31 #include <linux/nfs_fs.h>
33 #include <linux/module.h>
38 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
60 printk(
"%s NULL device\n", __func__);
66 " cl_exchange_flags %x\n",
107 dprintk(
"%s: unhandled address family: %u\n",
116 _same_data_server_addrs_locked(
const struct list_head *dsaddrs1,
141 _data_server_lookup_locked(
const struct list_head *dsaddrs)
146 if (_same_data_server_addrs_locked(&ds->
ds_addrs, dsaddrs))
162 dprintk(
"--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr,
163 mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor);
165 BUG_ON(list_empty(&ds->ds_addrs));
168 dprintk(
"%s: DS %s: trying address %s\n",
174 dataserver_timeo, dataserver_retrans);
180 status = PTR_ERR(clp);
189 dprintk(
"%s [new] addr: %s\n", __func__, ds->ds_remotestr);
209 while (!list_empty(&ds->ds_addrs)) {
228 nfs4_print_deviceid(&dsaddr->
id_node.deviceid);
230 for (i = 0; i < dsaddr->
ds_num; i++) {
234 &nfs4_ds_cache_lock)) {
236 spin_unlock(&nfs4_ds_cache_lock);
262 remotestr = kzalloc(len, gfp_flags);
300 if (list_empty(dsaddrs)) {
301 dprintk(
"%s: no addresses defined\n", __func__);
305 ds = kzalloc(
sizeof(*ds), gfp_flags);
310 remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags);
312 spin_lock(&nfs4_ds_cache_lock);
313 tmp_ds = _data_server_lookup_locked(dsaddrs);
314 if (tmp_ds == NULL) {
316 list_splice_init(dsaddrs, &ds->
ds_addrs);
321 list_add(&ds->
ds_node, &nfs4_data_server_cache);
322 dprintk(
"%s add new data server %s\n", __func__,
328 dprintk(
"%s data server %s found, inc'ed ds_count to %d\n",
333 spin_unlock(&nfs4_ds_cache_lock);
342 decode_ds_addr(
struct net *
net,
struct xdr_stream *streamp,
gfp_t gfp_flags)
350 char *netid, *match_netid;
351 size_t len, match_netid_len;
366 netid =
kmalloc(nlen+1, gfp_flags);
385 dprintk(
"%s: Invalid address, length %d\n", __func__,
389 buf =
kmalloc(rlen + 1, gfp_flags);
391 dprintk(
"%s: Not enough memory\n", __func__);
400 dprintk(
"%s: Failed finding expected dot in port\n",
409 dprintk(
"%s: Failed finding expected dot between address and "
415 da = kzalloc(
sizeof(*da), gfp_flags);
423 dprintk(
"%s: error parsing address %s\n", __func__, buf);
428 sscanf(portstr,
"%d-%d", &tmp[0], &tmp[1]);
429 port =
htons((tmp[0] << 8) | (tmp[1]));
431 switch (da->
da_addr.ss_family) {
442 match_netid =
"tcp6";
449 dprintk(
"%s: unsupported address family: %u\n",
450 __func__, da->
da_addr.ss_family);
454 if (nlen != match_netid_len ||
strncmp(netid, match_netid, nlen)) {
455 dprintk(
"%s: ERROR: r_netid \"%s\" != \"%s\"\n",
456 __func__, netid, match_netid);
467 buf, endsep,
ntohs(port));
477 dprintk(
"%s: Error parsing DS addr: %s\n", __func__, buf);
487 decode_device(
struct inode *
ino,
struct pnfs_device *pdev,
gfp_t gfp_flags)
513 goto out_err_free_scratch;
516 dprintk(
"%s stripe count %d\n", __func__, cnt);
519 "supported maximum %d\n", __func__,
521 goto out_err_free_scratch;
525 stripe_indices = kcalloc(cnt,
sizeof(
u8), gfp_flags);
527 goto out_err_free_scratch;
531 goto out_err_free_stripe_indices;
533 indexp = &stripe_indices[0];
534 max_stripe_index = 0;
535 for (i = 0; i <
cnt; i++) {
537 max_stripe_index =
max(max_stripe_index, *indexp);
544 goto out_err_free_stripe_indices;
547 dprintk(
"%s ds_num %u\n", __func__, num);
550 "supported maximum %d\n", __func__,
552 goto out_err_free_stripe_indices;
556 if (max_stripe_index >= num) {
558 __func__, max_stripe_index, num);
559 goto out_err_free_stripe_indices;
562 dsaddr = kzalloc(
sizeof(*dsaddr) +
566 goto out_err_free_stripe_indices;
570 stripe_indices =
NULL;
573 NFS_SERVER(ino)->pnfs_curr_ld,
577 INIT_LIST_HEAD(&dsaddrs);
579 for (i = 0; i < dsaddr->
ds_num; i++) {
585 goto out_err_free_deviceid;
588 for (j = 0; j < mp_count; j++) {
594 if (list_empty(&dsaddrs)) {
595 dprintk(
"%s: no suitable DS addresses found\n",
597 goto out_err_free_deviceid;
600 dsaddr->
ds_list[
i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags);
602 goto out_err_drain_dsaddrs;
605 while (!list_empty(&dsaddrs)) {
618 out_err_drain_dsaddrs:
619 while (!list_empty(&dsaddrs)) {
626 out_err_free_deviceid:
629 goto out_err_free_scratch;
630 out_err_free_stripe_indices:
631 kfree(stripe_indices);
632 out_err_free_scratch:
635 dprintk(
"%s ERROR: returning NULL\n", __func__);
646 struct nfs4_deviceid_node *
d;
649 new = decode_device(inode, dev, gfp_flags);
673 struct pnfs_device *pdev =
NULL;
679 struct nfs_server *server = NFS_SERVER(inode);
685 max_resp_sz = server->
nfs_client->cl_session->fc_attrs.max_resp_sz;
686 max_pages = nfs_page_array_len(0, max_resp_sz);
687 dprintk(
"%s inode %p max_resp_sz %u max_pages %d\n",
688 __func__, inode, max_resp_sz, max_pages);
690 pdev = kzalloc(
sizeof(
struct pnfs_device), gfp_flags);
694 pages = kzalloc(max_pages *
sizeof(
struct page *), gfp_flags);
699 for (i = 0; i < max_pages; i++) {
705 memcpy(&pdev->dev_id, dev_id,
sizeof(*dev_id));
709 pdev->pglen = max_resp_sz;
712 rc = nfs4_proc_getdeviceinfo(server, pdev);
713 dprintk(
"%s getdevice info returns %d\n", __func__, rc);
721 dsaddr = decode_and_add_device(inode, pdev, gfp_flags);
723 for (i = 0; i < max_pages; i++)
727 dprintk(
"<-- %s dsaddr %p\n", __func__, dsaddr);
756 return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[
j];
768 else if (flseg->
num_fh == 0)
783 struct nfs4_deviceid_node *
devid = FILELAYOUT_DEVID_NODE(lseg);
791 filelayout_mark_devid_invalid(devid);
799 err = nfs4_ds_connect(s, ds);
809 MODULE_PARM_DESC(dataserver_retrans,
"The number of times the NFSv4.1 client "
810 "retries a request before it attempts further "
811 " recovery action.");
814 "NFSv4.1 client waits for a response from a "
815 " data server before it retries an NFS request.");