^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Device operations for the pnfs nfs4 file layout driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Tao Peng <bergwolf@primarydata.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "../internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "../nfs4session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "flexfilelayout.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define NFSDBG_FACILITY NFSDBG_PNFS_LD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static unsigned int dataserver_timeo = NFS_DEF_TCP_TIMEO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static unsigned int dataserver_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (!IS_ERR_OR_NULL(mirror_ds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) nfs4_put_deviceid_node(&mirror_ds->id_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) nfs4_print_deviceid(&mirror_ds->id_node.deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) nfs4_pnfs_ds_put(mirror_ds->ds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) kfree(mirror_ds->ds_versions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) kfree_rcu(mirror_ds, id_node.rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Decode opaque device data and construct new_ds using it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct nfs4_ff_layout_ds *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct xdr_stream stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct xdr_buf buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct page *scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct list_head dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct nfs4_pnfs_ds_addr *da;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct nfs4_ff_layout_ds *new_ds = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct nfs4_ff_ds_version *ds_versions = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 mp_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u32 version_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int i, ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* set up xdr stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) scratch = alloc_page(gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (!scratch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) new_ds = kzalloc(sizeof(struct nfs4_ff_layout_ds), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!new_ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto out_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) nfs4_init_deviceid_node(&new_ds->id_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) &pdev->dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) INIT_LIST_HEAD(&dsaddrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* multipath count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) p = xdr_inline_decode(&stream, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) goto out_err_drain_dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) mp_count = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dprintk("%s: multipath ds count %d\n", __func__, mp_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) for (i = 0; i < mp_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* multipath ds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) da = nfs4_decode_mp_ds_addr(server->nfs_client->cl_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) &stream, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (da)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) list_add_tail(&da->da_node, &dsaddrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (list_empty(&dsaddrs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dprintk("%s: no suitable DS addresses found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ret = -ENOMEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) goto out_err_drain_dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* version count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) p = xdr_inline_decode(&stream, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) goto out_err_drain_dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) version_count = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) dprintk("%s: version count %d\n", __func__, version_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ds_versions = kcalloc(version_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sizeof(struct nfs4_ff_ds_version),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!ds_versions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto out_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) for (i = 0; i < version_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* 20 = version(4) + minor_version(4) + rsize(4) + wsize(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * tightly_coupled(4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) p = xdr_inline_decode(&stream, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) goto out_err_drain_dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ds_versions[i].version = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ds_versions[i].minor_version = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ds_versions[i].rsize = nfs_block_size(be32_to_cpup(p++), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ds_versions[i].wsize = nfs_block_size(be32_to_cpup(p++), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ds_versions[i].tightly_coupled = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (ds_versions[i].rsize > NFS_MAX_FILE_IO_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ds_versions[i].rsize = NFS_MAX_FILE_IO_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (ds_versions[i].wsize > NFS_MAX_FILE_IO_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ds_versions[i].wsize = NFS_MAX_FILE_IO_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * check for valid major/minor combination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * currently we support dataserver which talk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * v3, v4.0, v4.1, v4.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!((ds_versions[i].version == 3 && ds_versions[i].minor_version == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) (ds_versions[i].version == 4 && ds_versions[i].minor_version < 3))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) dprintk("%s: [%d] unsupported ds version %d-%d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) i, ds_versions[i].version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ds_versions[i].minor_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ret = -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) goto out_err_drain_dsaddrs;
^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) dprintk("%s: [%d] vers %u minor_ver %u rsize %u wsize %u coupled %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) __func__, i, ds_versions[i].version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ds_versions[i].minor_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ds_versions[i].rsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ds_versions[i].wsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ds_versions[i].tightly_coupled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) new_ds->ds_versions = ds_versions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) new_ds->ds_versions_cnt = version_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) new_ds->ds = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!new_ds->ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto out_err_drain_dsaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* If DS was already in cache, free ds addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) while (!list_empty(&dsaddrs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) da = list_first_entry(&dsaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct nfs4_pnfs_ds_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) list_del_init(&da->da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) kfree(da->da_remotestr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) kfree(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) __free_page(scratch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return new_ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) out_err_drain_dsaddrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) while (!list_empty(&dsaddrs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) list_del_init(&da->da_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) kfree(da->da_remotestr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) kfree(da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) kfree(ds_versions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) out_scratch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) __free_page(scratch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) kfree(new_ds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dprintk("%s ERROR: returning %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static void extend_ds_error(struct nfs4_ff_layout_ds_err *err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) u64 offset, u64 length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) u64 end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) end = max_t(u64, pnfs_end_offset(err->offset, err->length),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) pnfs_end_offset(offset, length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) err->offset = min_t(u64, err->offset, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) err->length = end - err->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ff_ds_error_match(const struct nfs4_ff_layout_ds_err *e1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) const struct nfs4_ff_layout_ds_err *e2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (e1->opnum != e2->opnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return e1->opnum < e2->opnum ? -1 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (e1->status != e2->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return e1->status < e2->status ? -1 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ret = memcmp(e1->stateid.data, e2->stateid.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) sizeof(e1->stateid.data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ret = memcmp(&e1->deviceid, &e2->deviceid, sizeof(e1->deviceid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (pnfs_end_offset(e1->offset, e1->length) < e2->offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (e1->offset > pnfs_end_offset(e2->offset, e2->length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* If ranges overlap or are contiguous, they are the same */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ff_layout_add_ds_error_locked(struct nfs4_flexfile_layout *flo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct nfs4_ff_layout_ds_err *dserr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct nfs4_ff_layout_ds_err *err, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct list_head *head = &flo->error_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Do insertion sort w/ merges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) list_for_each_entry_safe(err, tmp, &flo->error_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) match = ff_ds_error_match(err, dserr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (match < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (match > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Add entry "dserr" _before_ entry "err" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) head = &err->list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Entries match, so merge "err" into "dserr" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) extend_ds_error(dserr, err->offset, err->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) list_replace(&err->list, &dserr->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) kfree(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) list_add_tail(&dserr->list, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct nfs4_ff_layout_mirror *mirror, u64 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) u64 length, int status, enum nfs_opnum4 opnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct nfs4_ff_layout_ds_err *dserr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (status == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (IS_ERR_OR_NULL(mirror->mirror_ds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dserr = kmalloc(sizeof(*dserr), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!dserr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) INIT_LIST_HEAD(&dserr->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dserr->offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) dserr->length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) dserr->status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) dserr->opnum = opnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) nfs4_stateid_copy(&dserr->stateid, &mirror->stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) memcpy(&dserr->deviceid, &mirror->mirror_ds->id_node.deviceid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) NFS4_DEVICEID4_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) spin_lock(&flo->generic_hdr.plh_inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ff_layout_add_ds_error_locked(flo, dserr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) spin_unlock(&flo->generic_hdr.plh_inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static const struct cred *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ff_layout_get_mirror_cred(struct nfs4_ff_layout_mirror *mirror, u32 iomode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) const struct cred *cred, __rcu **pcred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (iomode == IOMODE_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) pcred = &mirror->ro_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) pcred = &mirror->rw_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) cred = rcu_dereference(*pcred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (!cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) cred = get_cred_rcu(cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) } while(!cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct nfs_fh *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) nfs4_ff_layout_select_ds_fh(struct nfs4_ff_layout_mirror *mirror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* FIXME: For now assume there is only 1 version available for the DS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return &mirror->fh_versions[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) nfs4_ff_layout_select_ds_stateid(const struct nfs4_ff_layout_mirror *mirror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) nfs4_stateid *stateid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (nfs4_ff_layout_ds_version(mirror) == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) nfs4_stateid_copy(stateid, &mirror->stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ff_layout_init_mirror_ds(struct pnfs_layout_hdr *lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct nfs4_ff_layout_mirror *mirror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (mirror == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) goto outerr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (mirror->mirror_ds == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct nfs4_deviceid_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct nfs4_ff_layout_ds *mirror_ds = ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) node = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) &mirror->devid, lo->plh_lc_cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) mirror_ds = FF_LAYOUT_MIRROR_DS(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* check for race with another call to this function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (cmpxchg(&mirror->mirror_ds, NULL, mirror_ds) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mirror_ds != ERR_PTR(-ENODEV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) nfs4_put_deviceid_node(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (IS_ERR(mirror->mirror_ds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) goto outerr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) outerr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * nfs4_ff_layout_prepare_ds - prepare a DS connection for an RPC call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * @lseg: the layout segment we're operating on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * @mirror: layout mirror describing the DS to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * @fail_return: return layout on connect failure?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * Try to prepare a DS connection to accept an RPC call. This involves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * selecting a mirror to use and connecting the client to it if it's not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * already connected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * Since we only need a single functioning mirror to satisfy a read, we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * want to return the layout if there is one. For writes though, any down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * mirror should result in a LAYOUTRETURN. @fail_return is how we distinguish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * between the two cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * Returns a pointer to a connected DS object on success or NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct nfs4_pnfs_ds *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct nfs4_ff_layout_mirror *mirror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) bool fail_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct nfs4_pnfs_ds *ds = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct inode *ino = lseg->pls_layout->plh_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct nfs_server *s = NFS_SERVER(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) unsigned int max_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (!ff_layout_init_mirror_ds(lseg->pls_layout, mirror))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) goto noconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ds = mirror->mirror_ds->ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (READ_ONCE(ds->ds_clp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* matching smp_wmb() in _nfs4_pnfs_v3/4_ds_connect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* FIXME: For now we assume the server sent only one version of NFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * to use for the DS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) status = nfs4_pnfs_ds_connect(s, ds, &mirror->mirror_ds->id_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) dataserver_timeo, dataserver_retrans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) mirror->mirror_ds->ds_versions[0].version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) mirror->mirror_ds->ds_versions[0].minor_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* connect success, check rsize/wsize limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) max_payload =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) nfs_block_size(rpc_max_payload(ds->ds_clp->cl_rpcclient),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (mirror->mirror_ds->ds_versions[0].rsize > max_payload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) mirror->mirror_ds->ds_versions[0].rsize = max_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (mirror->mirror_ds->ds_versions[0].wsize > max_payload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) mirror->mirror_ds->ds_versions[0].wsize = max_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) noconnect:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) mirror, lseg->pls_range.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) lseg->pls_range.length, NFS4ERR_NXIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) OP_ILLEGAL, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ff_layout_send_layouterror(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (fail_return || !ff_layout_has_available_ds(lseg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) pnfs_error_mark_layout_for_return(ino, lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ds = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) const struct cred *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ff_layout_get_ds_cred(struct nfs4_ff_layout_mirror *mirror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) const struct pnfs_layout_range *range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) const struct cred *mdscred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) const struct cred *cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (mirror && !mirror->mirror_ds->ds_versions[0].tightly_coupled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) cred = ff_layout_get_mirror_cred(mirror, range->iomode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (!cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) cred = get_cred(mdscred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) cred = get_cred(mdscred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * nfs4_ff_find_or_create_ds_client - Find or create a DS rpc client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * @mirror: pointer to the mirror
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * @ds_clp: nfs_client for the DS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * Find or create a DS rpc client with th MDS server rpc client auth flavor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * in the nfs_client cl_ds_clients list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct rpc_clnt *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) nfs4_ff_find_or_create_ds_client(struct nfs4_ff_layout_mirror *mirror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct nfs_client *ds_clp, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) switch (mirror->mirror_ds->ds_versions[0].version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* For NFSv3 DS, flavor is set when creating DS connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return ds_clp->cl_rpcclient;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return nfs4_find_or_create_ds_client(ds_clp, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) void ff_layout_free_ds_ioerr(struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct nfs4_ff_layout_ds_err *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) while (!list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) err = list_first_entry(head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct nfs4_ff_layout_ds_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) list_del(&err->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) kfree(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* called with inode i_lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) int ff_layout_encode_ds_ioerr(struct xdr_stream *xdr, const struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct nfs4_ff_layout_ds_err *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) list_for_each_entry(err, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* offset(8) + length(8) + stateid(NFS4_STATEID_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * + array length + deviceid(NFS4_DEVICEID4_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * + status(4) + opnum(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) p = xdr_reserve_space(xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 28 + NFS4_STATEID_SIZE + NFS4_DEVICEID4_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (unlikely(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) p = xdr_encode_hyper(p, err->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) p = xdr_encode_hyper(p, err->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) p = xdr_encode_opaque_fixed(p, &err->stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) NFS4_STATEID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* Encode 1 error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) *p++ = cpu_to_be32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) p = xdr_encode_opaque_fixed(p, &err->deviceid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) NFS4_DEVICEID4_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) *p++ = cpu_to_be32(err->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) *p++ = cpu_to_be32(err->opnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) dprintk("%s: offset %llu length %llu status %d op %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) __func__, err->offset, err->length, err->status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) err->opnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) unsigned int do_layout_fetch_ds_ioerr(struct pnfs_layout_hdr *lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) const struct pnfs_layout_range *range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) unsigned int maxnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct inode *inode = lo->plh_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct nfs4_ff_layout_ds_err *err, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) unsigned int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) list_for_each_entry_safe(err, n, &flo->error_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (!pnfs_is_range_intersecting(err->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) pnfs_end_offset(err->offset, err->length),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) range->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) pnfs_end_offset(range->offset, range->length)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (!maxnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) list_move(&err->list, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) maxnum--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) unsigned int ff_layout_fetch_ds_ioerr(struct pnfs_layout_hdr *lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) const struct pnfs_layout_range *range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) unsigned int maxnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) unsigned int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ret = do_layout_fetch_ds_ioerr(lo, range, head, maxnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* If we're over the max, discard all remaining entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (ret == maxnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) LIST_HEAD(discard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) do_layout_fetch_ds_ioerr(lo, range, &discard, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) ff_layout_free_ds_ioerr(&discard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static bool ff_read_layout_has_available_ds(struct pnfs_layout_segment *lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct nfs4_ff_layout_mirror *mirror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct nfs4_deviceid_node *devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) u32 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) for (idx = 0; idx < FF_LAYOUT_MIRROR_COUNT(lseg); idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) mirror = FF_LAYOUT_COMP(lseg, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (mirror) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!mirror->mirror_ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (IS_ERR(mirror->mirror_ds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) devid = &mirror->mirror_ds->id_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!nfs4_test_deviceid_unavailable(devid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static bool ff_rw_layout_has_available_ds(struct pnfs_layout_segment *lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct nfs4_ff_layout_mirror *mirror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) struct nfs4_deviceid_node *devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) u32 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) for (idx = 0; idx < FF_LAYOUT_MIRROR_COUNT(lseg); idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) mirror = FF_LAYOUT_COMP(lseg, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!mirror || IS_ERR(mirror->mirror_ds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!mirror->mirror_ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) devid = &mirror->mirror_ds->id_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (nfs4_test_deviceid_unavailable(devid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return FF_LAYOUT_MIRROR_COUNT(lseg) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (lseg->pls_range.iomode == IOMODE_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return ff_read_layout_has_available_ds(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* Note: RW layout needs all mirrors available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return ff_rw_layout_has_available_ds(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return ff_layout_no_fallback_to_mds(lseg) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) ff_layout_has_available_ds(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return lseg->pls_range.iomode == IOMODE_RW &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) ff_layout_no_read_on_rw(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) module_param(dataserver_retrans, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) "retries a request before it attempts further "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) " recovery action.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) module_param(dataserver_timeo, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) "NFSv4.1 client waits for a response from a "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) " data server before it retries an NFS request.");