From 587f03deb69bdbf2c8f5f06c5cdcebb42196faff Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Wed, 21 Sep 2016 05:14:28 -0400 Subject: pnfs: refactor send_layoutget Pull out the alloc/init part for eventual reuse by OPEN. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index ee723aa..2c955c3 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -915,18 +915,12 @@ pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo) test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); } -/* - * Get layout from server. - * for now, assume that whole file layouts are requested. - * arg->offset: 0 - * arg->length: all ones - */ -static struct pnfs_layout_segment * -send_layoutget(struct pnfs_layout_hdr *lo, +static struct nfs4_layoutget * +pnfs_alloc_init_layoutget_args(struct pnfs_layout_hdr *lo, struct nfs_open_context *ctx, nfs4_stateid *stateid, const struct pnfs_layout_range *range, - long *timeout, gfp_t gfp_flags) + gfp_t gfp_flags) { struct inode *ino = lo->plh_inode; struct nfs_server *server = NFS_SERVER(ino); @@ -935,14 +929,9 @@ send_layoutget(struct pnfs_layout_hdr *lo, dprintk("--> %s\n", __func__); - /* - * Synchronously retrieve layout information from server and - * store in lseg. If we race with a concurrent seqid morphing - * op, then re-send the LAYOUTGET. - */ lgp = kzalloc(sizeof(*lgp), gfp_flags); if (lgp == NULL) - return ERR_PTR(-ENOMEM); + return NULL; i_size = i_size_read(ino); @@ -963,8 +952,7 @@ send_layoutget(struct pnfs_layout_hdr *lo, nfs4_stateid_copy(&lgp->args.stateid, stateid); lgp->gfp_flags = gfp_flags; lgp->cred = lo->plh_lc_cred; - - return nfs4_proc_layoutget(lgp, timeout, gfp_flags); + return lgp; } static void pnfs_clear_layoutcommit(struct inode *inode, @@ -1694,6 +1682,7 @@ pnfs_update_layout(struct inode *ino, struct nfs_client *clp = server->nfs_client; struct pnfs_layout_hdr *lo = NULL; struct pnfs_layout_segment *lseg = NULL; + struct nfs4_layoutget *lgp; nfs4_stateid stateid; long timeout = 0; unsigned long giveup = jiffies + (clp->cl_lease_time << 1); @@ -1838,7 +1827,15 @@ lookup_again: if (arg.length != NFS4_MAX_UINT64) arg.length = PAGE_ALIGN(arg.length); - lseg = send_layoutget(lo, ctx, &stateid, &arg, &timeout, gfp_flags); + lgp = pnfs_alloc_init_layoutget_args(lo, ctx, &stateid, &arg, gfp_flags); + if (!lgp) { + trace_pnfs_update_layout(ino, pos, count, iomode, lo, NULL, + PNFS_UPDATE_LAYOUT_NOMEM); + atomic_dec(&lo->plh_outstanding); + goto out_put_layout_hdr; + } + + lseg = nfs4_proc_layoutget(lgp, &timeout, gfp_flags); trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, PNFS_UPDATE_LAYOUT_SEND_LAYOUTGET); atomic_dec(&lo->plh_outstanding); -- cgit v1.1 From dacb452db8733474c0317d499244c3c1ac769ef5 Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Mon, 19 Sep 2016 17:47:09 -0400 Subject: pnfs: move allocations out of nfs4_proc_layoutget They work better in the new alloc_init function. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 2c955c3..363420d 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -924,6 +924,7 @@ pnfs_alloc_init_layoutget_args(struct pnfs_layout_hdr *lo, { struct inode *ino = lo->plh_inode; struct nfs_server *server = NFS_SERVER(ino); + size_t max_pages = max_response_pages(server); struct nfs4_layoutget *lgp; loff_t i_size; @@ -933,6 +934,15 @@ pnfs_alloc_init_layoutget_args(struct pnfs_layout_hdr *lo, if (lgp == NULL) return NULL; + lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); + if (!lgp->args.layout.pages) { + kfree(lgp); + return NULL; + } + lgp->args.layout.pglen = max_pages * PAGE_SIZE; + lgp->res.layoutp = &lgp->args.layout; + + i_size = i_size_read(ino); lgp->args.minlength = PAGE_SIZE; @@ -1835,7 +1845,7 @@ lookup_again: goto out_put_layout_hdr; } - lseg = nfs4_proc_layoutget(lgp, &timeout, gfp_flags); + lseg = nfs4_proc_layoutget(lgp, &timeout); trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, PNFS_UPDATE_LAYOUT_SEND_LAYOUTGET); atomic_dec(&lo->plh_outstanding); -- cgit v1.1 From 1b146fcff7301c578d6e4a4bff48f1988cc12b4b Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Wed, 21 Sep 2016 15:24:26 -0400 Subject: pnfs: Move nfs4_opendata into nfs4_fs.h It will be needed now by the pnfs code. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 363420d..1114841 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -37,6 +37,7 @@ #include "nfs4trace.h" #include "delegation.h" #include "nfs42.h" +#include "nfs4_fs.h" #define NFSDBG_FACILITY NFSDBG_PNFS #define PNFS_LAYOUTGET_RETRY_TIMEOUT (120*HZ) -- cgit v1.1 From 5e36e2a9411210b1f81982af02504cd20f5c91d5 Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Thu, 6 Oct 2016 12:08:51 -0400 Subject: pnfs: Change pnfs_alloc_init_layoutget_args call signature Don't send in a layout, instead use the (possibly NULL) inode. This is needed for LAYOUTGET attached to an OPEN where the inode is not yet set. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 1114841..07f1bbd 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -916,18 +916,31 @@ pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo) test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); } +static struct nfs_server * +pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx) +{ + struct nfs_server *server; + + if (inode) + server = NFS_SERVER(inode); + else { + struct dentry *parent_dir = dget_parent(ctx->dentry); + server = NFS_SERVER(parent_dir->d_inode); + dput(parent_dir); + } + return server; +} + static struct nfs4_layoutget * -pnfs_alloc_init_layoutget_args(struct pnfs_layout_hdr *lo, +pnfs_alloc_init_layoutget_args(struct inode *ino, struct nfs_open_context *ctx, nfs4_stateid *stateid, const struct pnfs_layout_range *range, gfp_t gfp_flags) { - struct inode *ino = lo->plh_inode; - struct nfs_server *server = NFS_SERVER(ino); + struct nfs_server *server = pnfs_find_server(ino, ctx); size_t max_pages = max_response_pages(server); struct nfs4_layoutget *lgp; - loff_t i_size; dprintk("--> %s\n", __func__); @@ -944,16 +957,19 @@ pnfs_alloc_init_layoutget_args(struct pnfs_layout_hdr *lo, lgp->res.layoutp = &lgp->args.layout; - i_size = i_size_read(ino); lgp->args.minlength = PAGE_SIZE; if (lgp->args.minlength > range->length) lgp->args.minlength = range->length; - if (range->iomode == IOMODE_READ) { - if (range->offset >= i_size) - lgp->args.minlength = 0; - else if (i_size - range->offset < lgp->args.minlength) - lgp->args.minlength = i_size - range->offset; + if (ino) { + loff_t i_size = i_size_read(ino); + + if (range->iomode == IOMODE_READ) { + if (range->offset >= i_size) + lgp->args.minlength = 0; + else if (i_size - range->offset < lgp->args.minlength) + lgp->args.minlength = i_size - range->offset; + } } lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE; pnfs_copy_range(&lgp->args.range, range); @@ -962,7 +978,7 @@ pnfs_alloc_init_layoutget_args(struct pnfs_layout_hdr *lo, lgp->args.ctx = get_nfs_open_context(ctx); nfs4_stateid_copy(&lgp->args.stateid, stateid); lgp->gfp_flags = gfp_flags; - lgp->cred = lo->plh_lc_cred; + lgp->cred = ctx->cred; return lgp; } @@ -1838,7 +1854,7 @@ lookup_again: if (arg.length != NFS4_MAX_UINT64) arg.length = PAGE_ALIGN(arg.length); - lgp = pnfs_alloc_init_layoutget_args(lo, ctx, &stateid, &arg, gfp_flags); + lgp = pnfs_alloc_init_layoutget_args(ino, ctx, &stateid, &arg, gfp_flags); if (!lgp) { trace_pnfs_update_layout(ino, pos, count, iomode, lo, NULL, PNFS_UPDATE_LAYOUT_NOMEM); -- cgit v1.1 From 2409a976a2990ee1712c0945a75d75eeb3c60c08 Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Thu, 6 Oct 2016 12:11:21 -0400 Subject: pnfs: Add LAYOUTGET to OPEN of a new file This triggers when have no pre-existing inode to attach to. The preexisting case is saved for later. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 07f1bbd..a0a2484 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -934,7 +934,7 @@ pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx) static struct nfs4_layoutget * pnfs_alloc_init_layoutget_args(struct inode *ino, struct nfs_open_context *ctx, - nfs4_stateid *stateid, + const nfs4_stateid *stateid, const struct pnfs_layout_range *range, gfp_t gfp_flags) { @@ -978,7 +978,7 @@ pnfs_alloc_init_layoutget_args(struct inode *ino, lgp->args.ctx = get_nfs_open_context(ctx); nfs4_stateid_copy(&lgp->args.stateid, stateid); lgp->gfp_flags = gfp_flags; - lgp->cred = ctx->cred; + lgp->cred = get_rpccred(ctx->cred); return lgp; } @@ -1943,6 +1943,83 @@ pnfs_sanity_check_layout_range(struct pnfs_layout_range *range) return true; } +extern const nfs4_stateid current_stateid; + +static void _lgopen_prepare_attached(struct nfs4_opendata *data, + struct nfs_open_context *ctx) +{ + /* STUB */ +} + +static void _lgopen_prepare_floating(struct nfs4_opendata *data, + struct nfs_open_context *ctx) +{ + struct pnfs_layout_range rng = { + .iomode = (data->o_arg.fmode & FMODE_WRITE) ? + IOMODE_RW: IOMODE_READ, + .offset = 0, + .length = NFS4_MAX_UINT64, + }; + struct nfs4_layoutget *lgp; + + lgp = pnfs_alloc_init_layoutget_args(NULL, ctx, ¤t_stateid, + &rng, GFP_KERNEL); + if (!lgp) + return; + data->lgp = lgp; + data->o_arg.lg_args = &lgp->args; + data->o_res.lg_res = &lgp->res; +} + +void pnfs_lgopen_prepare(struct nfs4_opendata *data, + struct nfs_open_context *ctx) +{ + struct nfs_server *server = NFS_SERVER(data->dir->d_inode); + + if (!(pnfs_enabled_sb(server) && + server->pnfs_curr_ld->flags & PNFS_LAYOUTGET_ON_OPEN)) + return; + /* Could check on max_ops, but currently hardcoded high enough */ + if (data->state) + _lgopen_prepare_attached(data, ctx); + else + _lgopen_prepare_floating(data, ctx); +} + +void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, + struct nfs_open_context *ctx) +{ + struct pnfs_layout_hdr *lo; + struct pnfs_layout_segment *lseg; + u32 iomode; + + if (!lgp || lgp->res.layoutp->len == 0) + return; + if (!lgp->args.inode) { + /* Need to grab lo */ + spin_lock(&ino->i_lock); + lo = pnfs_find_alloc_layout(ino, ctx, GFP_KERNEL); + atomic_inc(&lo->plh_outstanding); + spin_unlock(&ino->i_lock); + lgp->args.inode = ino; + } else + lo = NFS_I(lgp->args.inode)->layout; + pnfs_get_layout_hdr(lo); + + lseg = pnfs_layout_process(lgp); + atomic_dec(&lo->plh_outstanding); + if (IS_ERR(lseg)) { + /* ignore lseg, but would like to mark not to try lgopen */ + /* clear some lo flags - first and fail ???? */ + } else { + iomode = lgp->args.range.iomode; + pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); + pnfs_put_lseg(lseg); + } + pnfs_clear_first_layoutget(lo); + pnfs_put_layout_hdr(lo); +} + struct pnfs_layout_segment * pnfs_layout_process(struct nfs4_layoutget *lgp) { -- cgit v1.1 From 29a8bfe52d1c38bde482971250af0ba9637ddaf2 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Wed, 30 May 2018 17:16:20 -0400 Subject: pNFS: Refactor nfs4_layoutget_release() Move the actual freeing of the struct nfs4_layoutget into fs/nfs/pnfs.c where it can be reused by the layoutget on open code. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index a0a2484..f568a1d 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -931,6 +931,44 @@ pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx) return server; } +static void nfs4_free_pages(struct page **pages, size_t size) +{ + int i; + + if (!pages) + return; + + for (i = 0; i < size; i++) { + if (!pages[i]) + break; + __free_page(pages[i]); + } + kfree(pages); +} + +static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) +{ + struct page **pages; + int i; + + pages = kcalloc(size, sizeof(struct page *), gfp_flags); + if (!pages) { + dprintk("%s: can't alloc array of %zu pages\n", __func__, size); + return NULL; + } + + for (i = 0; i < size; i++) { + pages[i] = alloc_page(gfp_flags); + if (!pages[i]) { + dprintk("%s: failed to allocate page\n", __func__); + nfs4_free_pages(pages, size); + return NULL; + } + } + + return pages; +} + static struct nfs4_layoutget * pnfs_alloc_init_layoutget_args(struct inode *ino, struct nfs_open_context *ctx, @@ -982,6 +1020,18 @@ pnfs_alloc_init_layoutget_args(struct inode *ino, return lgp; } +void pnfs_layoutget_free(struct nfs4_layoutget *lgp) +{ + size_t max_pages = lgp->args.layout.pglen / PAGE_SIZE; + + nfs4_free_pages(lgp->args.layout.pages, max_pages); + if (lgp->args.inode) + pnfs_put_layout_hdr(NFS_I(lgp->args.inode)->layout); + put_rpccred(lgp->cred); + put_nfs_open_context(lgp->args.ctx); + kfree(lgp); +} + static void pnfs_clear_layoutcommit(struct inode *inode, struct list_head *head) { -- cgit v1.1 From 78746a384c88c6405594cd07cae11b3b3caffb9b Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Thu, 22 Sep 2016 12:30:20 -0400 Subject: pnfs: Add LAYOUTGET to OPEN of an existing file Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 17 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index f568a1d..a6fe813 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -921,9 +921,9 @@ pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx) { struct nfs_server *server; - if (inode) + if (inode) { server = NFS_SERVER(inode); - else { + } else { struct dentry *parent_dir = dget_parent(ctx->dentry); server = NFS_SERVER(parent_dir->d_inode); dput(parent_dir); @@ -1736,6 +1736,22 @@ static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo) wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET); } +static void _add_to_server_list(struct pnfs_layout_hdr *lo, + struct nfs_server *server) +{ + if (list_empty(&lo->plh_layouts)) { + struct nfs_client *clp = server->nfs_client; + + /* The lo must be on the clp list if there is any + * chance of a CB_LAYOUTRECALL(FILE) coming in. + */ + spin_lock(&clp->cl_lock); + if (list_empty(&lo->plh_layouts)) + list_add_tail(&lo->plh_layouts, &server->layouts); + spin_unlock(&clp->cl_lock); + } +} + /* * Layout segment is retreived from the server if not cached. * The appropriate layout segment is referenced and returned to the caller. @@ -1886,15 +1902,7 @@ lookup_again: atomic_inc(&lo->plh_outstanding); spin_unlock(&ino->i_lock); - if (list_empty(&lo->plh_layouts)) { - /* The lo must be on the clp list if there is any - * chance of a CB_LAYOUTRECALL(FILE) coming in. - */ - spin_lock(&clp->cl_lock); - if (list_empty(&lo->plh_layouts)) - list_add_tail(&lo->plh_layouts, &server->layouts); - spin_unlock(&clp->cl_lock); - } + _add_to_server_list(lo, server); pg_offset = arg.offset & ~PAGE_MASK; if (pg_offset) { @@ -1993,12 +2001,62 @@ pnfs_sanity_check_layout_range(struct pnfs_layout_range *range) return true; } +static struct pnfs_layout_hdr * +_pnfs_grab_empty_layout(struct inode *ino, struct nfs_open_context *ctx) +{ + struct pnfs_layout_hdr *lo; + + spin_lock(&ino->i_lock); + lo = pnfs_find_alloc_layout(ino, ctx, GFP_KERNEL); + if (!lo) + goto out_unlock; + if (!test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) + goto out_unlock; + if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) + goto out_unlock; + if (pnfs_layoutgets_blocked(lo)) + goto out_unlock; + if (test_and_set_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags)) + goto out_unlock; + atomic_inc(&lo->plh_outstanding); + spin_unlock(&ino->i_lock); + _add_to_server_list(lo, NFS_SERVER(ino)); + return lo; + +out_unlock: + spin_unlock(&ino->i_lock); + pnfs_put_layout_hdr(lo); + return NULL; +} + extern const nfs4_stateid current_stateid; static void _lgopen_prepare_attached(struct nfs4_opendata *data, struct nfs_open_context *ctx) { - /* STUB */ + struct inode *ino = data->dentry->d_inode; + struct pnfs_layout_range rng = { + .iomode = (data->o_arg.fmode & FMODE_WRITE) ? + IOMODE_RW: IOMODE_READ, + .offset = 0, + .length = NFS4_MAX_UINT64, + }; + struct nfs4_layoutget *lgp; + struct pnfs_layout_hdr *lo; + + lo = _pnfs_grab_empty_layout(ino, ctx); + if (!lo) + return; + lgp = pnfs_alloc_init_layoutget_args(ino, ctx, ¤t_stateid, + &rng, GFP_KERNEL); + if (!lgp) { + pnfs_clear_first_layoutget(lo); + pnfs_put_layout_hdr(lo); + return; + } + data->lgp = lgp; + data->o_arg.lg_args = &lgp->args; + data->o_res.lg_res = &lgp->res; } static void _lgopen_prepare_floating(struct nfs4_opendata *data, @@ -2046,11 +2104,9 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, if (!lgp || lgp->res.layoutp->len == 0) return; if (!lgp->args.inode) { - /* Need to grab lo */ - spin_lock(&ino->i_lock); - lo = pnfs_find_alloc_layout(ino, ctx, GFP_KERNEL); - atomic_inc(&lo->plh_outstanding); - spin_unlock(&ino->i_lock); + lo = _pnfs_grab_empty_layout(ino, ctx); + if (!lo) + return; lgp->args.inode = ino; } else lo = NFS_I(lgp->args.inode)->layout; -- cgit v1.1 From 6e01260ceeca299b82d466660935534c5c909d54 Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Tue, 4 Oct 2016 15:26:41 -0400 Subject: pnfs: Stop attempting LAYOUTGET on OPEN on failure Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index a6fe813..3dfe9fa 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2088,6 +2088,8 @@ void pnfs_lgopen_prepare(struct nfs4_opendata *data, server->pnfs_curr_ld->flags & PNFS_LAYOUTGET_ON_OPEN)) return; /* Could check on max_ops, but currently hardcoded high enough */ + if (!nfs_server_capable(data->dir->d_inode, NFS_CAP_LGOPEN)) + return; if (data->state) _lgopen_prepare_attached(data, ctx); else @@ -2101,8 +2103,23 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, struct pnfs_layout_segment *lseg; u32 iomode; - if (!lgp || lgp->res.layoutp->len == 0) + if (!lgp) return; + dprintk("%s: entered with status %i\n", __func__, lgp->res.status); + if (lgp->res.status) { + switch (lgp->res.status) { + case -NFS4ERR_DELAY: + case -NFS4ERR_GRACE: + case -NFS4ERR_LAYOUTTRYLATER: + break; + default: + /* FIXME - Any error not listed above permanently + * halts lgopen attempts. + */ + NFS_SERVER(ino)->caps &= ~NFS_CAP_LGOPEN; + } + return; + } if (!lgp->args.inode) { lo = _pnfs_grab_empty_layout(ino, ctx); if (!lo) -- cgit v1.1 From c49b5209f99abe082d3d4cd94f0ad924baea34ed Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Wed, 5 Oct 2016 09:37:12 -0400 Subject: pnfs: Add barrier to prevent lgopen using LAYOUTGET during recall Since the LAYOUTGET on OPEN can be sent without prior inode information, existing methods to prevent LAYOUTGET from being sent while processing CB_LAYOUTRECALL don't work. Track if a recall occurred while LAYOUTGET was being sent, and if so ignore the results. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 3dfe9fa..a29fdea 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1017,6 +1017,7 @@ pnfs_alloc_init_layoutget_args(struct inode *ino, nfs4_stateid_copy(&lgp->args.stateid, stateid); lgp->gfp_flags = gfp_flags; lgp->cred = get_rpccred(ctx->cred); + lgp->callback_count = raw_seqcount_begin(&server->nfs_client->cl_callback_count); return lgp; } @@ -2101,6 +2102,7 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, { struct pnfs_layout_hdr *lo; struct pnfs_layout_segment *lseg; + struct nfs_server *srv = NFS_SERVER(ino); u32 iomode; if (!lgp) @@ -2116,7 +2118,7 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, /* FIXME - Any error not listed above permanently * halts lgopen attempts. */ - NFS_SERVER(ino)->caps &= ~NFS_CAP_LGOPEN; + srv->caps &= ~NFS_CAP_LGOPEN; } return; } @@ -2129,6 +2131,9 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, lo = NFS_I(lgp->args.inode)->layout; pnfs_get_layout_hdr(lo); + if (read_seqcount_retry(&srv->nfs_client->cl_callback_count, + lgp->callback_count)) + goto out; lseg = pnfs_layout_process(lgp); atomic_dec(&lo->plh_outstanding); if (IS_ERR(lseg)) { @@ -2139,6 +2144,7 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); pnfs_put_lseg(lseg); } +out: pnfs_clear_first_layoutget(lo); pnfs_put_layout_hdr(lo); } -- cgit v1.1 From 30ae2412e90f0ae177da631e36537392d89a2ccd Mon Sep 17 00:00:00 2001 From: Fred Isaman Date: Tue, 18 Oct 2016 13:39:51 -0400 Subject: pnfs: Fix manipulation of NFS_LAYOUT_FIRST_LAYOUTGET The flag was not always being cleared after LAYOUTGET on OPEN. Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index a29fdea..b0e42fd 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2129,13 +2129,11 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, lgp->args.inode = ino; } else lo = NFS_I(lgp->args.inode)->layout; - pnfs_get_layout_hdr(lo); if (read_seqcount_retry(&srv->nfs_client->cl_callback_count, lgp->callback_count)) - goto out; + return; lseg = pnfs_layout_process(lgp); - atomic_dec(&lo->plh_outstanding); if (IS_ERR(lseg)) { /* ignore lseg, but would like to mark not to try lgopen */ /* clear some lo flags - first and fail ???? */ @@ -2144,9 +2142,19 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); pnfs_put_lseg(lseg); } -out: - pnfs_clear_first_layoutget(lo); - pnfs_put_layout_hdr(lo); +} + +void nfs4_lgopen_release(struct nfs4_layoutget *lgp) +{ + if (lgp != NULL) { + struct inode *inode = lgp->args.inode; + if (inode) { + struct pnfs_layout_hdr *lo = NFS_I(inode)->layout; + atomic_dec(&lo->plh_outstanding); + pnfs_clear_first_layoutget(lo); + } + pnfs_layoutget_free(lgp); + } } struct pnfs_layout_segment * -- cgit v1.1 From d49e0d5b999621412ffb177f08a1c1746dfb6071 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Wed, 1 Feb 2017 20:42:44 -0500 Subject: NFSv4/pnfs: Ensure pnfs_parse_lgopen() won't try to parse uninitialised data We need to ensure that pnfs_parse_lgopen() doesn't try to parse a struct nfs4_layoutget_res that was not filled by a successful call to decode_layoutget(). This can happen if we performed a cached open, or if either the OP_ACCESS or OP_GETATTR operations preceding the OP_LAYOUTGET in the compound returned an error. By initialising the 'status' field to NFS4ERR_DELAY, we ensure that pnfs_parse_lgopen() won't try to interpret the structure. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index b0e42fd..4d3f04d 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -994,7 +994,8 @@ pnfs_alloc_init_layoutget_args(struct inode *ino, lgp->args.layout.pglen = max_pages * PAGE_SIZE; lgp->res.layoutp = &lgp->args.layout; - + /* Don't confuse uninitialised result and success */ + lgp->res.status = -NFS4ERR_DELAY; lgp->args.minlength = PAGE_SIZE; if (lgp->args.minlength > range->length) -- cgit v1.1 From 8dc96566c0c34b8c2632bc6071dad208d69dd5b0 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Wed, 1 Feb 2017 21:02:07 -0500 Subject: NFSv4/pnfs: Don't switch off layoutget-on-open for transient errors Ensure that we only switch off the LAYOUTGET operation in the OPEN compound when the server is truly broken, and/or it is complaining that the compound is too large. Currently, we end up turning off the functionality permanently, even for transient errors such as EACCES or ENOSPC. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 4d3f04d..d5dc97f 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2111,14 +2111,22 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, dprintk("%s: entered with status %i\n", __func__, lgp->res.status); if (lgp->res.status) { switch (lgp->res.status) { - case -NFS4ERR_DELAY: - case -NFS4ERR_GRACE: - case -NFS4ERR_LAYOUTTRYLATER: - break; default: - /* FIXME - Any error not listed above permanently - * halts lgopen attempts. - */ + break; + /* + * Halt lgopen attempts if the server doesn't recognise + * the "current stateid" value, the layout type, or the + * layoutget operation as being valid. + * Also if it complains about too many ops in the compound + * or of the request/reply being too big. + */ + case -NFS4ERR_BAD_STATEID: + case -NFS4ERR_NOTSUPP: + case -NFS4ERR_REP_TOO_BIG: + case -NFS4ERR_REP_TOO_BIG_TO_CACHE: + case -NFS4ERR_REQ_TOO_BIG: + case -NFS4ERR_TOO_MANY_OPS: + case -NFS4ERR_UNKNOWN_LAYOUTTYPE: srv->caps &= ~NFS_CAP_LGOPEN; } return; -- cgit v1.1 From 64294b08f9d27f83cbb0975250614864fa733bda Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Thu, 2 Feb 2017 12:26:38 -0500 Subject: pNFS: Don't send LAYOUTGET on OPEN for read, if we already have cached data If we're only opening the file for reading, and the file is empty and/or we already have cached data, then heuristically optimise away the LAYOUTGET. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index d5dc97f..717cd95 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2046,6 +2046,11 @@ static void _lgopen_prepare_attached(struct nfs4_opendata *data, struct nfs4_layoutget *lgp; struct pnfs_layout_hdr *lo; + /* Heuristic: don't send layoutget if we have cached data */ + if (rng.iomode == IOMODE_READ && + (i_size_read(ino) == 0 || ino->i_mapping->nrpages != 0)) + return; + lo = _pnfs_grab_empty_layout(ino, ctx); if (!lo) return; -- cgit v1.1 From 32f1c28f3d453f4652948ab9298078874d1a56b6 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Tue, 22 May 2018 11:15:32 -0400 Subject: pnfs: Don't call commit on failed layoutget-on-open If the layoutget on open call failed, we can't really commit the inode, so don't bother calling it. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 717cd95..d93942f 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2148,10 +2148,7 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, lgp->callback_count)) return; lseg = pnfs_layout_process(lgp); - if (IS_ERR(lseg)) { - /* ignore lseg, but would like to mark not to try lgopen */ - /* clear some lo flags - first and fail ???? */ - } else { + if (!IS_ERR(lseg)) { iomode = lgp->args.range.iomode; pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); pnfs_put_lseg(lseg); @@ -2236,8 +2233,6 @@ out_forget: spin_unlock(&ino->i_lock); lseg->pls_layout = lo; NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); - if (!pnfs_layout_is_valid(lo)) - nfs_commit_inode(ino, 0); return ERR_PTR(-EAGAIN); } -- cgit v1.1 From 93b7f7ad2018d2037559b1d0892417864c78b371 Mon Sep 17 00:00:00 2001 From: Olga Kornievskaia Date: Mon, 11 Jun 2018 15:32:06 -0400 Subject: skip LAYOUTRETURN if layout is invalid Currently, when IO to DS fails, client returns the layout and retries against the MDS. However, then on umounting (inode eviction) it returns the layout again. This is because pnfs_return_layout() was changed in commit d78471d32bb6 ("pnfs/blocklayout: set PNFS_LAYOUTRETURN_ON_ERROR") to always set NFS_LAYOUT_RETURN_REQUESTED so even if we returned the layout, it will be returned again. Instead, let's also check if we have already marked the layout invalid. Signed-off-by: Olga Kornievskaia Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'fs/nfs/pnfs.c') diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index d93942f..bcc3add 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1211,7 +1211,7 @@ _pnfs_return_layout(struct inode *ino) LIST_HEAD(tmp_list); nfs4_stateid stateid; int status = 0; - bool send; + bool send, valid_layout; dprintk("NFS: %s for inode %lu\n", __func__, ino->i_ino); @@ -1232,6 +1232,7 @@ _pnfs_return_layout(struct inode *ino) goto out_put_layout_hdr; spin_lock(&ino->i_lock); } + valid_layout = pnfs_layout_is_valid(lo); pnfs_clear_layoutcommit(ino, &tmp_list); pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL, 0); @@ -1245,7 +1246,8 @@ _pnfs_return_layout(struct inode *ino) } /* Don't send a LAYOUTRETURN if list was initially empty */ - if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) { + if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags) || + !valid_layout) { spin_unlock(&ino->i_lock); dprintk("NFS: %s no layout segments to return\n", __func__); goto out_put_layout_hdr; -- cgit v1.1