^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Device operations for the pnfs nfs4 file layout driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * The Regents of the University of Michigan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Dean Hildebrand <dhildebz@umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Garth Goodson <Garth.Goodson@netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Permission is granted to use, copy, create derivative works, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * redistribute this software and such derivative works for any purpose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * so long as the name of the University of Michigan is not used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * any advertising or publicity pertaining to the use or distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * of this software without specific, written prior authorization. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * the above copyright notice or any other identification of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * University of Michigan is included in any copy of any portion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * this software, then the disclaimer below must also be included.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * This software is provided as is, without representation or warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * of any kind either express or implied, including without limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * the implied warranties of merchantability, fitness for a particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * purpose, or noninfringement. The Regents of the University of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Michigan shall not be liable for any damages, including special,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * indirect, incidental, or consequential damages, with respect to any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * claim arising out of or in connection with the use of the software,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * even if it has been or is hereafter advised of the possibility of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * such damages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "../internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "../nfs4session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "filelayout.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define NFSDBG_FACILITY NFSDBG_PNFS_LD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct nfs4_pnfs_ds *ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) nfs4_print_deviceid(&dsaddr->id_node.deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) for (i = 0; i < dsaddr->ds_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ds = dsaddr->ds_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (ds != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) nfs4_pnfs_ds_put(ds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) kfree(dsaddr->stripe_indices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) kfree_rcu(dsaddr, id_node.rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Decode opaque device data and return the result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct nfs4_file_layout_dsaddr *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 cnt, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 *indexp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 *stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u8 max_stripe_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct nfs4_file_layout_dsaddr *dsaddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct xdr_stream stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct xdr_buf buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct page *scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct list_head dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct nfs4_pnfs_ds_addr *da;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* set up xdr stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) scratch = alloc_page(gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!scratch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* Get the stripe count (number of stripe index) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) p = xdr_inline_decode(&stream, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) goto out_err_free_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) cnt = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) dprintk("%s stripe count %d\n", __func__, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) printk(KERN_WARNING "NFS: %s: stripe count %d greater than "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) "supported maximum %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) cnt, NFS4_PNFS_MAX_STRIPE_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) goto out_err_free_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* read stripe indices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (!stripe_indices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) goto out_err_free_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) p = xdr_inline_decode(&stream, cnt << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) goto out_err_free_stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) indexp = &stripe_indices[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) max_stripe_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) for (i = 0; i < cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *indexp = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) max_stripe_index = max(max_stripe_index, *indexp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) indexp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* Check the multipath list count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) p = xdr_inline_decode(&stream, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) goto out_err_free_stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) num = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) dprintk("%s ds_num %u\n", __func__, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (num > NFS4_PNFS_MAX_MULTI_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) printk(KERN_WARNING "NFS: %s: multipath count %d greater than "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) "supported maximum %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) num, NFS4_PNFS_MAX_MULTI_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) goto out_err_free_stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* validate stripe indices are all < num */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (max_stripe_index >= num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) __func__, max_stripe_index, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) goto out_err_free_stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) dsaddr = kzalloc(sizeof(*dsaddr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) (sizeof(struct nfs4_pnfs_ds *) * (num - 1)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!dsaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) goto out_err_free_stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) dsaddr->stripe_count = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dsaddr->stripe_indices = stripe_indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) stripe_indices = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dsaddr->ds_num = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) nfs4_init_deviceid_node(&dsaddr->id_node, server, &pdev->dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) INIT_LIST_HEAD(&dsaddrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) for (i = 0; i < dsaddr->ds_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) u32 mp_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) p = xdr_inline_decode(&stream, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) goto out_err_free_deviceid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) mp_count = be32_to_cpup(p); /* multipath count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) for (j = 0; j < mp_count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) da = nfs4_decode_mp_ds_addr(server->nfs_client->cl_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) &stream, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (da)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) list_add_tail(&da->da_node, &dsaddrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (list_empty(&dsaddrs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dprintk("%s: no suitable DS addresses found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) goto out_err_free_deviceid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) dsaddr->ds_list[i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (!dsaddr->ds_list[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) goto out_err_drain_dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* If DS was already in cache, free ds addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) while (!list_empty(&dsaddrs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) da = list_first_entry(&dsaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct nfs4_pnfs_ds_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) list_del_init(&da->da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kfree(da->da_remotestr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) kfree(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) __free_page(scratch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return dsaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) out_err_drain_dsaddrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) while (!list_empty(&dsaddrs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) list_del_init(&da->da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) kfree(da->da_remotestr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) kfree(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) out_err_free_deviceid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) nfs4_fl_free_deviceid(dsaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* stripe_indicies was part of dsaddr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) goto out_err_free_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) out_err_free_stripe_indices:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) kfree(stripe_indices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) out_err_free_scratch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) __free_page(scratch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) dprintk("%s ERROR: returning NULL\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) nfs4_put_deviceid_node(&dsaddr->id_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * Then: ((res + fsi) % dsaddr->stripe_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) u64 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) tmp = offset - flseg->pattern_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) do_div(tmp, flseg->stripe_unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) tmp += flseg->first_stripe_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return do_div(tmp, flseg->dsaddr->stripe_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct nfs_fh *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (flseg->stripe_type == STRIPE_SPARSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (flseg->num_fh == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) else if (flseg->num_fh == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) i = nfs4_fl_calc_ds_index(lseg, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) i = j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return flseg->fh_array[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* Upon return, either ds is connected, or ds is NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct nfs4_pnfs_ds *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct nfs4_pnfs_ds *ret = ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (ds == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) printk(KERN_ERR "NFS: %s: No data server for offset index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) __func__, ds_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) pnfs_generic_mark_devid_invalid(devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (ds->ds_clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) goto out_test_devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) status = nfs4_pnfs_ds_connect(s, ds, devid, dataserver_timeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) dataserver_retrans, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) s->nfs_client->cl_minorversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) nfs4_mark_deviceid_unavailable(devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) out_test_devid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (ret->ds_clp == NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) filelayout_test_devid_unavailable(devid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) module_param(dataserver_retrans, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) "retries a request before it attempts further "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) " recovery action.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) module_param(dataserver_timeo, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) "NFSv4.1 client waits for a response from a "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) " data server before it retries an NFS request.");