mirror of
https://github.com/torvalds/linux.git
synced 2024-12-13 14:43:03 +00:00
849dc3244c
I hit the following oops out of the blue while testing with flexfiles: BUG: unable to handle kernel NULL pointer dereference at 00000000000000e8 IP: [<ffffffffa048f6b8>] nfs4_ff_find_or_create_ds_client+0x48/0x50 [nfs_layout_flexfiles] PGD 44031067 PUD 5062d067 PMD 0 Oops: 0000 [#1] SMP Modules linked in: nfsv3 nfs_layout_flexfiles tun rpcsec_gss_krb5 nfsv4 dns_resolver nfs fscache dcdbas nfsd auth_rpcgss nfs_acl lockd grace sunrpc ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw bonding ipmi_devintf ipmi_msghandler snd_hda_codec_generic virtio_balloon ppdev snd_hda_intel snd_hda_controller snd_hda_codec iosf_mbi crct10dif_pclmul crc32_pclmul ghash_clmulni_intel snd_hda_core parport_pc snd_hwdep parport snd_seq snd_seq_device snd_pcm snd_timer acpi_cpufreq snd soundcore i2c_piix4 xfs libcrc32c joydev virtio_net virtio_console qxl drm_kms_helper ttm crc32c_intel drm virtio_pci serio_raw ata_generic virtio_ring virtio pata_acpi CPU: 0 PID: 19138 Comm: test5 Not tainted 4.1.9-100.pd.90.el7.x86_64 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014 task: ffff88007b70cf00 ti: ffff88004cc44000 task.ti: ffff88004cc44000 RIP: 0010:[<ffffffffa048f6b8>] [<ffffffffa048f6b8>] nfs4_ff_find_or_create_ds_client+0x48/0x50 [nfs_layout_flexfiles] RSP: 0018:ffff88004cc47890 EFLAGS: 00010246 RAX: 0000000000000003 RBX: ffff880050932300 RCX: ffff88006978f488 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88003e0e8540 RBP: ffff88004cc47908 R08: 0000000000000000 R09: 0000000000000000 R10: ffff88007ff8c758 R11: 0000000000000005 R12: ffff88003e0e8540 R13: 0000000000000000 R14: ffff88006978f488 R15: ffff88004431cc80 FS: 00007fea40c7c740(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000000000e8 CR3: 0000000044318000 CR4: 00000000000406f0 Stack: ffffffffa048c934 ffff880050932310 0000000100000001 ffff88006978f510 ffff88006978f3c8 ffff88003e56cd90 ffff88004cc479d0 00000020a052aff0 000000000004b000 ffff88004cc47908 ffff880050932300 ffff88004cc479d0 Call Trace: [<ffffffffa048c934>] ? ff_layout_write_pagelist+0x64/0x220 [nfs_layout_flexfiles] [<ffffffffa057a3bf>] pnfs_generic_pg_writepages+0xaf/0x1b0 [nfsv4] [<ffffffffa051ab57>] nfs_pageio_doio+0x27/0x60 [nfs] [<ffffffffa051bfe4>] nfs_pageio_complete_mirror+0x54/0xa0 [nfs] [<ffffffffa051c7ad>] nfs_pageio_complete+0x2d/0x90 [nfs] [<ffffffffa052032d>] nfs_writepage_locked+0x8d/0xe0 [nfs] [<ffffffff811e4630>] ? page_referenced_one+0x1a0/0x1a0 [<ffffffffa05210e7>] nfs_wb_single_page+0xf7/0x190 [nfs] [<ffffffffa05108d1>] nfs_launder_page+0x41/0x90 [nfs] [<ffffffff811b8930>] invalidate_inode_pages2_range+0x340/0x3a0 [<ffffffff811b89a7>] invalidate_inode_pages2+0x17/0x20 [<ffffffffa0513e1e>] nfs_release+0x9e/0xb0 [nfs] [<ffffffffa050fa1d>] nfs_file_release+0x3d/0x60 [nfs] [<ffffffff8122481c>] __fput+0xdc/0x1e0 [<ffffffff8122496e>] ____fput+0xe/0x10 [<ffffffff810bde67>] task_work_run+0xa7/0xe0 [<ffffffff810af735>] get_signal+0x565/0x600 [<ffffffff811a9815>] ? __filemap_fdatawrite_range+0x65/0x90 [<ffffffff810144a7>] do_signal+0x37/0x730 [<ffffffffa0569921>] ? nfs4_file_fsync+0x81/0x150 [nfsv4] [<ffffffff81254dbb>] ? vfs_fsync_range+0x3b/0xb0 [<ffffffff811446a6>] ? __audit_syscall_exit+0x1e6/0x280 [<ffffffff81014bff>] do_notify_resume+0x5f/0xa0 [<ffffffff8178ec3c>] int_signal+0x12/0x17 Code: 48 8b 40 70 8b 00 83 f8 03 74 20 83 f8 04 75 13 55 48 89 ce 48 89 d7 48 89 e5 e8 14 0f 0e 00 5d c3 66 90 0f 0b 66 0f 1f 44 00 00 <48> 8b 82 e8 00 00 00 c3 66 66 66 66 90 55 48 89 e5 41 57 41 56 RIP [<ffffffffa048f6b8>] nfs4_ff_find_or_create_ds_client+0x48/0x50 [nfs_layout_flexfiles] RSP <ffff88004cc47890> CR2: 00000000000000e8 When the DS connection attempt fails, nfs4_ff_layout_prepare_ds marks it for the error but then just returns the ds as if it were usable. The comments though say: /* Upon return, either ds is connected, or ds is NULL */ Ensure that we set the return pointer to NULL in the event that the connection attempt fails. Signed-off-by: Jeff Layton <jeff.layton@primarydata.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
573 lines
15 KiB
C
573 lines
15 KiB
C
/*
|
|
* Device operations for the pnfs nfs4 file layout driver.
|
|
*
|
|
* Copyright (c) 2014, Primary Data, Inc. All rights reserved.
|
|
*
|
|
* Tao Peng <bergwolf@primarydata.com>
|
|
*/
|
|
|
|
#include <linux/nfs_fs.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/module.h>
|
|
#include <linux/sunrpc/addr.h>
|
|
|
|
#include "../internal.h"
|
|
#include "../nfs4session.h"
|
|
#include "flexfilelayout.h"
|
|
|
|
#define NFSDBG_FACILITY NFSDBG_PNFS_LD
|
|
|
|
static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO;
|
|
static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS;
|
|
|
|
void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds)
|
|
{
|
|
if (mirror_ds)
|
|
nfs4_put_deviceid_node(&mirror_ds->id_node);
|
|
}
|
|
|
|
void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds)
|
|
{
|
|
nfs4_print_deviceid(&mirror_ds->id_node.deviceid);
|
|
nfs4_pnfs_ds_put(mirror_ds->ds);
|
|
kfree_rcu(mirror_ds, id_node.rcu);
|
|
}
|
|
|
|
/* Decode opaque device data and construct new_ds using it */
|
|
struct nfs4_ff_layout_ds *
|
|
nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
|
|
gfp_t gfp_flags)
|
|
{
|
|
struct xdr_stream stream;
|
|
struct xdr_buf buf;
|
|
struct page *scratch;
|
|
struct list_head dsaddrs;
|
|
struct nfs4_pnfs_ds_addr *da;
|
|
struct nfs4_ff_layout_ds *new_ds = NULL;
|
|
struct nfs4_ff_ds_version *ds_versions = NULL;
|
|
u32 mp_count;
|
|
u32 version_count;
|
|
__be32 *p;
|
|
int i, ret = -ENOMEM;
|
|
|
|
/* set up xdr stream */
|
|
scratch = alloc_page(gfp_flags);
|
|
if (!scratch)
|
|
goto out_err;
|
|
|
|
new_ds = kzalloc(sizeof(struct nfs4_ff_layout_ds), gfp_flags);
|
|
if (!new_ds)
|
|
goto out_scratch;
|
|
|
|
nfs4_init_deviceid_node(&new_ds->id_node,
|
|
server,
|
|
&pdev->dev_id);
|
|
INIT_LIST_HEAD(&dsaddrs);
|
|
|
|
xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
|
|
xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
|
|
|
|
/* multipath count */
|
|
p = xdr_inline_decode(&stream, 4);
|
|
if (unlikely(!p))
|
|
goto out_err_drain_dsaddrs;
|
|
mp_count = be32_to_cpup(p);
|
|
dprintk("%s: multipath ds count %d\n", __func__, mp_count);
|
|
|
|
for (i = 0; i < mp_count; i++) {
|
|
/* multipath ds */
|
|
da = nfs4_decode_mp_ds_addr(server->nfs_client->cl_net,
|
|
&stream, gfp_flags);
|
|
if (da)
|
|
list_add_tail(&da->da_node, &dsaddrs);
|
|
}
|
|
if (list_empty(&dsaddrs)) {
|
|
dprintk("%s: no suitable DS addresses found\n",
|
|
__func__);
|
|
ret = -ENOMEDIUM;
|
|
goto out_err_drain_dsaddrs;
|
|
}
|
|
|
|
/* version count */
|
|
p = xdr_inline_decode(&stream, 4);
|
|
if (unlikely(!p))
|
|
goto out_err_drain_dsaddrs;
|
|
version_count = be32_to_cpup(p);
|
|
dprintk("%s: version count %d\n", __func__, version_count);
|
|
|
|
ds_versions = kzalloc(version_count * sizeof(struct nfs4_ff_ds_version),
|
|
gfp_flags);
|
|
if (!ds_versions)
|
|
goto out_scratch;
|
|
|
|
for (i = 0; i < version_count; i++) {
|
|
/* 20 = version(4) + minor_version(4) + rsize(4) + wsize(4) +
|
|
* tightly_coupled(4) */
|
|
p = xdr_inline_decode(&stream, 20);
|
|
if (unlikely(!p))
|
|
goto out_err_drain_dsaddrs;
|
|
ds_versions[i].version = be32_to_cpup(p++);
|
|
ds_versions[i].minor_version = be32_to_cpup(p++);
|
|
ds_versions[i].rsize = nfs_block_size(be32_to_cpup(p++), NULL);
|
|
ds_versions[i].wsize = nfs_block_size(be32_to_cpup(p++), NULL);
|
|
ds_versions[i].tightly_coupled = be32_to_cpup(p);
|
|
|
|
if (ds_versions[i].rsize > NFS_MAX_FILE_IO_SIZE)
|
|
ds_versions[i].rsize = NFS_MAX_FILE_IO_SIZE;
|
|
if (ds_versions[i].wsize > NFS_MAX_FILE_IO_SIZE)
|
|
ds_versions[i].wsize = NFS_MAX_FILE_IO_SIZE;
|
|
|
|
if (ds_versions[i].version != 3 || ds_versions[i].minor_version != 0) {
|
|
dprintk("%s: [%d] unsupported ds version %d-%d\n", __func__,
|
|
i, ds_versions[i].version,
|
|
ds_versions[i].minor_version);
|
|
ret = -EPROTONOSUPPORT;
|
|
goto out_err_drain_dsaddrs;
|
|
}
|
|
|
|
dprintk("%s: [%d] vers %u minor_ver %u rsize %u wsize %u coupled %d\n",
|
|
__func__, i, ds_versions[i].version,
|
|
ds_versions[i].minor_version,
|
|
ds_versions[i].rsize,
|
|
ds_versions[i].wsize,
|
|
ds_versions[i].tightly_coupled);
|
|
}
|
|
|
|
new_ds->ds_versions = ds_versions;
|
|
new_ds->ds_versions_cnt = version_count;
|
|
|
|
new_ds->ds = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags);
|
|
if (!new_ds->ds)
|
|
goto out_err_drain_dsaddrs;
|
|
|
|
/* If DS was already in cache, free ds addrs */
|
|
while (!list_empty(&dsaddrs)) {
|
|
da = list_first_entry(&dsaddrs,
|
|
struct nfs4_pnfs_ds_addr,
|
|
da_node);
|
|
list_del_init(&da->da_node);
|
|
kfree(da->da_remotestr);
|
|
kfree(da);
|
|
}
|
|
|
|
__free_page(scratch);
|
|
return new_ds;
|
|
|
|
out_err_drain_dsaddrs:
|
|
while (!list_empty(&dsaddrs)) {
|
|
da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr,
|
|
da_node);
|
|
list_del_init(&da->da_node);
|
|
kfree(da->da_remotestr);
|
|
kfree(da);
|
|
}
|
|
|
|
kfree(ds_versions);
|
|
out_scratch:
|
|
__free_page(scratch);
|
|
out_err:
|
|
kfree(new_ds);
|
|
|
|
dprintk("%s ERROR: returning %d\n", __func__, ret);
|
|
return NULL;
|
|
}
|
|
|
|
static void ff_layout_mark_devid_invalid(struct pnfs_layout_segment *lseg,
|
|
struct nfs4_deviceid_node *devid)
|
|
{
|
|
nfs4_mark_deviceid_unavailable(devid);
|
|
if (!ff_layout_has_available_ds(lseg))
|
|
pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode,
|
|
lseg);
|
|
}
|
|
|
|
static bool ff_layout_mirror_valid(struct pnfs_layout_segment *lseg,
|
|
struct nfs4_ff_layout_mirror *mirror)
|
|
{
|
|
if (mirror == NULL || mirror->mirror_ds == NULL) {
|
|
pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode,
|
|
lseg);
|
|
return false;
|
|
}
|
|
if (mirror->mirror_ds->ds == NULL) {
|
|
struct nfs4_deviceid_node *devid;
|
|
devid = &mirror->mirror_ds->id_node;
|
|
ff_layout_mark_devid_invalid(lseg, devid);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static u64
|
|
end_offset(u64 start, u64 len)
|
|
{
|
|
u64 end;
|
|
|
|
end = start + len;
|
|
return end >= start ? end : NFS4_MAX_UINT64;
|
|
}
|
|
|
|
static void extend_ds_error(struct nfs4_ff_layout_ds_err *err,
|
|
u64 offset, u64 length)
|
|
{
|
|
u64 end;
|
|
|
|
end = max_t(u64, end_offset(err->offset, err->length),
|
|
end_offset(offset, length));
|
|
err->offset = min_t(u64, err->offset, offset);
|
|
err->length = end - err->offset;
|
|
}
|
|
|
|
static int
|
|
ff_ds_error_match(const struct nfs4_ff_layout_ds_err *e1,
|
|
const struct nfs4_ff_layout_ds_err *e2)
|
|
{
|
|
int ret;
|
|
|
|
if (e1->opnum != e2->opnum)
|
|
return e1->opnum < e2->opnum ? -1 : 1;
|
|
if (e1->status != e2->status)
|
|
return e1->status < e2->status ? -1 : 1;
|
|
ret = memcmp(&e1->stateid, &e2->stateid, sizeof(e1->stateid));
|
|
if (ret != 0)
|
|
return ret;
|
|
ret = memcmp(&e1->deviceid, &e2->deviceid, sizeof(e1->deviceid));
|
|
if (ret != 0)
|
|
return ret;
|
|
if (end_offset(e1->offset, e1->length) < e2->offset)
|
|
return -1;
|
|
if (e1->offset > end_offset(e2->offset, e2->length))
|
|
return 1;
|
|
/* If ranges overlap or are contiguous, they are the same */
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
ff_layout_add_ds_error_locked(struct nfs4_flexfile_layout *flo,
|
|
struct nfs4_ff_layout_ds_err *dserr)
|
|
{
|
|
struct nfs4_ff_layout_ds_err *err, *tmp;
|
|
struct list_head *head = &flo->error_list;
|
|
int match;
|
|
|
|
/* Do insertion sort w/ merges */
|
|
list_for_each_entry_safe(err, tmp, &flo->error_list, list) {
|
|
match = ff_ds_error_match(err, dserr);
|
|
if (match < 0)
|
|
continue;
|
|
if (match > 0) {
|
|
/* Add entry "dserr" _before_ entry "err" */
|
|
head = &err->list;
|
|
break;
|
|
}
|
|
/* Entries match, so merge "err" into "dserr" */
|
|
extend_ds_error(dserr, err->offset, err->length);
|
|
list_del(&err->list);
|
|
kfree(err);
|
|
}
|
|
|
|
list_add_tail(&dserr->list, head);
|
|
}
|
|
|
|
int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
|
|
struct nfs4_ff_layout_mirror *mirror, u64 offset,
|
|
u64 length, int status, enum nfs_opnum4 opnum,
|
|
gfp_t gfp_flags)
|
|
{
|
|
struct nfs4_ff_layout_ds_err *dserr;
|
|
|
|
if (status == 0)
|
|
return 0;
|
|
|
|
if (mirror->mirror_ds == NULL)
|
|
return -EINVAL;
|
|
|
|
dserr = kmalloc(sizeof(*dserr), gfp_flags);
|
|
if (!dserr)
|
|
return -ENOMEM;
|
|
|
|
INIT_LIST_HEAD(&dserr->list);
|
|
dserr->offset = offset;
|
|
dserr->length = length;
|
|
dserr->status = status;
|
|
dserr->opnum = opnum;
|
|
nfs4_stateid_copy(&dserr->stateid, &mirror->stateid);
|
|
memcpy(&dserr->deviceid, &mirror->mirror_ds->id_node.deviceid,
|
|
NFS4_DEVICEID4_SIZE);
|
|
|
|
spin_lock(&flo->generic_hdr.plh_inode->i_lock);
|
|
ff_layout_add_ds_error_locked(flo, dserr);
|
|
spin_unlock(&flo->generic_hdr.plh_inode->i_lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* currently we only support AUTH_NONE and AUTH_SYS */
|
|
static rpc_authflavor_t
|
|
nfs4_ff_layout_choose_authflavor(struct nfs4_ff_layout_mirror *mirror)
|
|
{
|
|
if (mirror->uid == (u32)-1)
|
|
return RPC_AUTH_NULL;
|
|
return RPC_AUTH_UNIX;
|
|
}
|
|
|
|
/* fetch cred for NFSv3 DS */
|
|
static int ff_layout_update_mirror_cred(struct nfs4_ff_layout_mirror *mirror,
|
|
struct nfs4_pnfs_ds *ds)
|
|
{
|
|
if (ds->ds_clp && !mirror->cred &&
|
|
mirror->mirror_ds->ds_versions[0].version == 3) {
|
|
struct rpc_auth *auth = ds->ds_clp->cl_rpcclient->cl_auth;
|
|
struct rpc_cred *cred;
|
|
struct auth_cred acred = {
|
|
.uid = make_kuid(&init_user_ns, mirror->uid),
|
|
.gid = make_kgid(&init_user_ns, mirror->gid),
|
|
};
|
|
|
|
/* AUTH_NULL ignores acred */
|
|
cred = auth->au_ops->lookup_cred(auth, &acred, 0);
|
|
if (IS_ERR(cred)) {
|
|
dprintk("%s: lookup_cred failed with %ld\n",
|
|
__func__, PTR_ERR(cred));
|
|
return PTR_ERR(cred);
|
|
} else {
|
|
if (cmpxchg(&mirror->cred, NULL, cred))
|
|
put_rpccred(cred);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct nfs_fh *
|
|
nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx)
|
|
{
|
|
struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, mirror_idx);
|
|
struct nfs_fh *fh = NULL;
|
|
|
|
if (!ff_layout_mirror_valid(lseg, mirror)) {
|
|
pr_err_ratelimited("NFS: %s: No data server for mirror offset index %d\n",
|
|
__func__, mirror_idx);
|
|
goto out;
|
|
}
|
|
|
|
/* FIXME: For now assume there is only 1 version available for the DS */
|
|
fh = &mirror->fh_versions[0];
|
|
out:
|
|
return fh;
|
|
}
|
|
|
|
/* Upon return, either ds is connected, or ds is NULL */
|
|
struct nfs4_pnfs_ds *
|
|
nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
|
|
bool fail_return)
|
|
{
|
|
struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
|
|
struct nfs4_pnfs_ds *ds = NULL;
|
|
struct nfs4_deviceid_node *devid;
|
|
struct inode *ino = lseg->pls_layout->plh_inode;
|
|
struct nfs_server *s = NFS_SERVER(ino);
|
|
unsigned int max_payload;
|
|
rpc_authflavor_t flavor;
|
|
|
|
if (!ff_layout_mirror_valid(lseg, mirror)) {
|
|
pr_err_ratelimited("NFS: %s: No data server for offset index %d\n",
|
|
__func__, ds_idx);
|
|
goto out;
|
|
}
|
|
|
|
devid = &mirror->mirror_ds->id_node;
|
|
if (ff_layout_test_devid_unavailable(devid))
|
|
goto out;
|
|
|
|
ds = mirror->mirror_ds->ds;
|
|
/* matching smp_wmb() in _nfs4_pnfs_v3/4_ds_connect */
|
|
smp_rmb();
|
|
if (ds->ds_clp)
|
|
goto out_update_creds;
|
|
|
|
flavor = nfs4_ff_layout_choose_authflavor(mirror);
|
|
|
|
/* FIXME: For now we assume the server sent only one version of NFS
|
|
* to use for the DS.
|
|
*/
|
|
nfs4_pnfs_ds_connect(s, ds, devid, dataserver_timeo,
|
|
dataserver_retrans,
|
|
mirror->mirror_ds->ds_versions[0].version,
|
|
mirror->mirror_ds->ds_versions[0].minor_version,
|
|
flavor);
|
|
|
|
/* connect success, check rsize/wsize limit */
|
|
if (ds->ds_clp) {
|
|
max_payload =
|
|
nfs_block_size(rpc_max_payload(ds->ds_clp->cl_rpcclient),
|
|
NULL);
|
|
if (mirror->mirror_ds->ds_versions[0].rsize > max_payload)
|
|
mirror->mirror_ds->ds_versions[0].rsize = max_payload;
|
|
if (mirror->mirror_ds->ds_versions[0].wsize > max_payload)
|
|
mirror->mirror_ds->ds_versions[0].wsize = max_payload;
|
|
} else {
|
|
ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout),
|
|
mirror, lseg->pls_range.offset,
|
|
lseg->pls_range.length, NFS4ERR_NXIO,
|
|
OP_ILLEGAL, GFP_NOIO);
|
|
if (!fail_return) {
|
|
if (ff_layout_has_available_ds(lseg))
|
|
set_bit(NFS_LAYOUT_RETURN_REQUESTED,
|
|
&lseg->pls_layout->plh_flags);
|
|
else
|
|
pnfs_error_mark_layout_for_return(ino, lseg);
|
|
} else
|
|
pnfs_error_mark_layout_for_return(ino, lseg);
|
|
ds = NULL;
|
|
goto out;
|
|
}
|
|
out_update_creds:
|
|
if (ff_layout_update_mirror_cred(mirror, ds))
|
|
ds = NULL;
|
|
out:
|
|
return ds;
|
|
}
|
|
|
|
struct rpc_cred *
|
|
ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, u32 ds_idx,
|
|
struct rpc_cred *mdscred)
|
|
{
|
|
struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
|
|
struct rpc_cred *cred = ERR_PTR(-EINVAL);
|
|
|
|
if (!nfs4_ff_layout_prepare_ds(lseg, ds_idx, true))
|
|
goto out;
|
|
|
|
if (mirror && mirror->cred)
|
|
cred = mirror->cred;
|
|
else
|
|
cred = mdscred;
|
|
out:
|
|
return cred;
|
|
}
|
|
|
|
/**
|
|
* Find or create a DS rpc client with th MDS server rpc client auth flavor
|
|
* in the nfs_client cl_ds_clients list.
|
|
*/
|
|
struct rpc_clnt *
|
|
nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg, u32 ds_idx,
|
|
struct nfs_client *ds_clp, struct inode *inode)
|
|
{
|
|
struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
|
|
|
|
switch (mirror->mirror_ds->ds_versions[0].version) {
|
|
case 3:
|
|
/* For NFSv3 DS, flavor is set when creating DS connections */
|
|
return ds_clp->cl_rpcclient;
|
|
case 4:
|
|
return nfs4_find_or_create_ds_client(ds_clp, inode);
|
|
default:
|
|
BUG();
|
|
}
|
|
}
|
|
|
|
static bool is_range_intersecting(u64 offset1, u64 length1,
|
|
u64 offset2, u64 length2)
|
|
{
|
|
u64 end1 = end_offset(offset1, length1);
|
|
u64 end2 = end_offset(offset2, length2);
|
|
|
|
return (end1 == NFS4_MAX_UINT64 || end1 > offset2) &&
|
|
(end2 == NFS4_MAX_UINT64 || end2 > offset1);
|
|
}
|
|
|
|
/* called with inode i_lock held */
|
|
int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo,
|
|
struct xdr_stream *xdr, int *count,
|
|
const struct pnfs_layout_range *range)
|
|
{
|
|
struct nfs4_ff_layout_ds_err *err, *n;
|
|
__be32 *p;
|
|
|
|
list_for_each_entry_safe(err, n, &flo->error_list, list) {
|
|
if (!is_range_intersecting(err->offset, err->length,
|
|
range->offset, range->length))
|
|
continue;
|
|
/* offset(8) + length(8) + stateid(NFS4_STATEID_SIZE)
|
|
* + array length + deviceid(NFS4_DEVICEID4_SIZE)
|
|
* + status(4) + opnum(4)
|
|
*/
|
|
p = xdr_reserve_space(xdr,
|
|
28 + NFS4_STATEID_SIZE + NFS4_DEVICEID4_SIZE);
|
|
if (unlikely(!p))
|
|
return -ENOBUFS;
|
|
p = xdr_encode_hyper(p, err->offset);
|
|
p = xdr_encode_hyper(p, err->length);
|
|
p = xdr_encode_opaque_fixed(p, &err->stateid,
|
|
NFS4_STATEID_SIZE);
|
|
/* Encode 1 error */
|
|
*p++ = cpu_to_be32(1);
|
|
p = xdr_encode_opaque_fixed(p, &err->deviceid,
|
|
NFS4_DEVICEID4_SIZE);
|
|
*p++ = cpu_to_be32(err->status);
|
|
*p++ = cpu_to_be32(err->opnum);
|
|
*count += 1;
|
|
list_del(&err->list);
|
|
dprintk("%s: offset %llu length %llu status %d op %d count %d\n",
|
|
__func__, err->offset, err->length, err->status,
|
|
err->opnum, *count);
|
|
kfree(err);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static bool ff_read_layout_has_available_ds(struct pnfs_layout_segment *lseg)
|
|
{
|
|
struct nfs4_ff_layout_mirror *mirror;
|
|
struct nfs4_deviceid_node *devid;
|
|
u32 idx;
|
|
|
|
for (idx = 0; idx < FF_LAYOUT_MIRROR_COUNT(lseg); idx++) {
|
|
mirror = FF_LAYOUT_COMP(lseg, idx);
|
|
if (mirror && mirror->mirror_ds) {
|
|
devid = &mirror->mirror_ds->id_node;
|
|
if (!ff_layout_test_devid_unavailable(devid))
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static bool ff_rw_layout_has_available_ds(struct pnfs_layout_segment *lseg)
|
|
{
|
|
struct nfs4_ff_layout_mirror *mirror;
|
|
struct nfs4_deviceid_node *devid;
|
|
u32 idx;
|
|
|
|
for (idx = 0; idx < FF_LAYOUT_MIRROR_COUNT(lseg); idx++) {
|
|
mirror = FF_LAYOUT_COMP(lseg, idx);
|
|
if (!mirror || !mirror->mirror_ds)
|
|
return false;
|
|
devid = &mirror->mirror_ds->id_node;
|
|
if (ff_layout_test_devid_unavailable(devid))
|
|
return false;
|
|
}
|
|
|
|
return FF_LAYOUT_MIRROR_COUNT(lseg) != 0;
|
|
}
|
|
|
|
bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg)
|
|
{
|
|
if (lseg->pls_range.iomode == IOMODE_READ)
|
|
return ff_read_layout_has_available_ds(lseg);
|
|
/* Note: RW layout needs all mirrors available */
|
|
return ff_rw_layout_has_available_ds(lseg);
|
|
}
|
|
|
|
module_param(dataserver_retrans, uint, 0644);
|
|
MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client "
|
|
"retries a request before it attempts further "
|
|
" recovery action.");
|
|
module_param(dataserver_timeo, uint, 0644);
|
|
MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the "
|
|
"NFSv4.1 client waits for a response from a "
|
|
" data server before it retries an NFS request.");
|