pnfs: layout pipelining
Subsystems (2)
v2 cover pnfs: layout pipelining
v2:
- rework of LAYOUTGET retry handling.
This is v2 of the layout pipelining work. I've done some testing with it, driving read and write I/Os against a file while forcing recalls to occur. With this set, the client can successfully issue new LAYOUTGET calls to handle new page I/Os while the still draining I/Os to the old layout.
The main change from the last set is a rework of how we handle retryable errors in LAYOUTGET. With the current code, once it has made a decision to issue a LAYOUTGET, it will drive that RPC until completion. That's not really ideal though. A usable layout could have shown up in the list while the RPC was still in flight.
What we really want to do when we get back a retryable error is to re-search for the layout from scratch. Thus, the last patch lifts the code to retry the LAYOUTGET into pnfs_update_layout, so it can make an intelligent decision about whether it's even necessary to reissue the RPC at all.
Original cover letter from the RFC patchset follows:
--------------------------[snip]----------------------------
At Primary Data, one of the things we're most interested in is data mobility. IOW, we want to be able to change the layout for an inode seamlessly, with little interruption to I/O patterns.
The problem we have now is that CB_LAYOUTRECALLs interrupt I/O. When one comes in, most pNFS servers refuse to hand out new layouts until the recalled ones have been returned (or the client indicates that it no longer knows about them). It doesn't have to be this way though. RFC5661 allows for concurrent LAYOUTGET and LAYOUTRETURN calls.
Furthermore, servers are expected to deal with old stateids in LAYOUTRETURN. From RFC5661, section 18.44.3:
If the client returns the layout in response to a CB_LAYOUTRECALL where the lor_recalltype field of the clora_recall field was LAYOUTRECALL4_FILE, the client should use the lor_stateid value from CB_LAYOUTRECALL as the value for lrf_stateid. Otherwise, it should use logr_stateid (from a previous LAYOUTGET result) or lorr_stateid (from a previous LAYRETURN result). This is done to indicate the point in time (in terms of layout stateid transitions) when the recall was sent.
The way I'm interpreting this is that we can treat a LAYOUTRETURN with an old stateid as returning all layouts that matched the given iomode, at the time that that seqid was current.
With that, we can allow a LAYOUTGET on the same fh to proceed even when there are still recalled layouts outstanding. This should allow the client to pivot to a new layout while it's still draining I/Os that are pinning the ones to be returned.
This patchset is a first draft of the client side piece that allows this. Basically whenever we get a new layout segment, we'll tag it with the seqid that was in the LAYOUTGET stateid that grants it.
When a CB_LAYOUTRECALL comes in, we tag the return seqid in the layout header with the one that was in the request. When we do a LAYOUTRETURN in response to a CB_LAYOUTRECALL, we craft the seqid such that we're only returning the layouts that were recalled. Nothing that has been granted since then will be returned.
I think I've done this in a way that the existing behavior is preserved in the case where the server enforces the serialization of these operations, but please do have a look and let me know if you see any potential problems here. Testing this is still a WIP...
Jeff Layton (9):
pnfs: don't merge new ff lsegs with ones that have LAYOUTRETURN bit
set
pnfs: record sequence in pnfs_layout_segment when it's created
pnfs: keep track of the return sequence number in pnfs_layout_hdr
pnfs: only tear down lsegs that precede seqid in LAYOUTRETURN args
flexfiles: remove pointless setting of NFS_LAYOUT_RETURN_REQUESTED
flexfiles: add kerneldoc header to nfs4_ff_layout_prepare_ds
pnfs: fix bad error handling in send_layoutget
pnfs: lift retry logic from send_layoutget to pnfs_update_layout
pnfs: rework LAYOUTGET retry handling
fs/nfs/callback_proc.c | 3 +- fs/nfs/flexfilelayout/flexfilelayout.c | 6 +- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 26 +++- fs/nfs/nfs42proc.c | 2 +- fs/nfs/nfs4proc.c | 68 +++------ fs/nfs/pnfs.c | 243 +++++++++++++++++------------- fs/nfs/pnfs.h | 12 +- include/linux/nfs_xdr.h | 3 +- 8 files changed, 184 insertions(+), 179 deletions(-)
Signature · 1 line
2.5.5
PATCH v2 1/9 pnfs: don't merge new ff lsegs with ones that have LAYOUTRETURN bit set
Otherwise, we'll end up returning layouts that we've just received if the client issues a new LAYOUTGET prior to the LAYOUTRETURN.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +2 -2
@@ -298,6 +298,8 @@ ff_lseg_merge(struct pnfs_layout_segment *new, {u64 new_end, old_end; +if (test_bit (NFS_LSEG_LAYOUTRETURN , &old->pls_flags)) +return false;if (new->pls_range.iomode != old->pls_range.iomode)return false; old_end = pnfs_calc_offset_end(old->pls_range.offset,
@@ -318,8 +320,6 @@ ff_lseg_merge(struct pnfs_layout_segment *new, new_end);if (test_bit (NFS_LSEG_ROC , &old->pls_flags))set_bit (NFS_LSEG_ROC , &new->pls_flags); -if (test_bit (NFS_LSEG_LAYOUTRETURN , &old->pls_flags)) -set_bit (NFS_LSEG_LAYOUTRETURN , &new->pls_flags);return true; }
Signature · 1 line
2.5.5
PATCH v2 2/9 pnfs: record sequence in pnfs_layout_segment when it's created
In reply to Jeff LaytonIn later patches, we're going to teach the client to be more selective about how it returns layouts. This means keeping a record of what the stateid's seqid was at the time that the server handed out a layout segment.
--- fs/nfs/pnfs.c | 1 + fs/nfs/pnfs.h | 1 + 2 files changed, 2 insertions(+)
fs/nfs/pnfs.c +1 -0
@@ -1697,6 +1697,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)init_lseg (lo, lseg); lseg->pls_range = res->range; + lseg->pls_seq =be32_to_cpu (res->stateid.seqid);spin_lock (&ino->i_lock);if (pnfs_layoutgets_blocked (lo)) {
fs/nfs/pnfs.h +1 -0
@@ -64,6 +64,7 @@ struct pnfs_layout_segment {struct list_head pls_lc_list;struct pnfs_layout_range pls_range;atomic_t pls_refcount; +u32 pls_seq;unsigned long pls_flags;struct pnfs_layout_hdr *pls_layout;struct work_struct pls_work;
Signature · 1 line
2.5.5
PATCH v2 3/9 pnfs: keep track of the return sequence number in pnfs_layout_hdr
In reply to Jeff LaytonWhen we want to selectively do a LAYOUTRETURN, we need to specify a stateid that represents most recent layout acquisition that is to be returned.
When we mark a layout stateid to be returned, we update the return sequence number in the layout header with that value, if it's newer than the existing one. Then, when we go to do a LAYOUTRETURN on layout header put, we overwrite the seqid in the stateid with the saved one, and then zero it out.
--- fs/nfs/pnfs.c | 11 ++++++++--- fs/nfs/pnfs.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
fs/nfs/pnfs.c +8 -3
@@ -899,6 +899,7 @@ pnfs_prepare_layoutreturn(struct pnfs_layout_hdr *lo)if (test_and_set_bit (NFS_LAYOUT_RETURN , &lo->plh_flags))return false; lo->plh_return_iomode =0 ; + lo->plh_return_seq =0 ;pnfs_get_layout_hdr (lo);clear_bit (NFS_LAYOUT_RETURN_REQUESTED , &lo->plh_flags);return true;
@@ -969,6 +970,7 @@ static void pnfs_layoutreturn_before_put_layout_hdr(struct pnfs_layout_hdr *lo)bool send;nfs4_stateid_copy (&stateid, &lo->plh_stateid); + stateid.seqid =cpu_to_be32 (lo->plh_return_seq); iomode = lo->plh_return_iomode; send =pnfs_prepare_layoutreturn (lo);spin_unlock (&inode->i_lock);
@@ -1747,7 +1749,8 @@ out_forget_reply: }static void -pnfs_set_plh_return_iomode (struct pnfs_layout_hdr *lo,enum pnfs_iomode iomode) +pnfs_set_plh_return_info (struct pnfs_layout_hdr *lo,enum pnfs_iomode iomode, +u32 seq) {if (lo->plh_return_iomode == iomode)return ;
@@ -1755,6 +1758,8 @@ pnfs_set_plh_return_iomode(struct pnfs_layout_hdr *lo, enum pnfs_iomode iomode) iomode =IOMODE_ANY ; lo->plh_return_iomode = iomode;set_bit (NFS_LAYOUT_RETURN_REQUESTED , &lo->plh_flags); +if (!lo->plh_return_seq ||pnfs_seqid_is_newer (seq, lo->plh_return_seq)) + lo->plh_return_seq = seq; }/**
@@ -1793,7 +1798,7 @@ pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo,continue ; remaining++;set_bit (NFS_LSEG_LAYOUTRETURN , &lseg->pls_flags); -pnfs_set_plh_return_iomode (lo, return_range->iomode); +pnfs_set_plh_return_info (lo, return_range->iomode, lseg->pls_seq); }return remaining; }
@@ -1811,7 +1816,7 @@ void pnfs_error_mark_layout_for_return(struct inode *inode,bool return_now = false;spin_lock (&inode->i_lock); -pnfs_set_plh_return_iomode (lo, range.iomode); +pnfs_set_plh_return_info (lo, range.iomode, lseg->pls_seq);/* * mark all matching lsegs so that we are sure to have no live * segments at hand when sending layoutreturn. See pnfs_put_lseg()
fs/nfs/pnfs.h +1 -0
@@ -195,6 +195,7 @@ struct pnfs_layout_hdr {unsigned long plh_flags;nfs4_stateid plh_stateid;u32 plh_barrier;/* ignore lower seqids */ +u32 plh_return_seq;enum pnfs_iomode plh_return_iomode;loff_t plh_lwb;/* last write byte for layoutcommit */ struct rpc_cred *plh_lc_cred;/* layoutcommit cred */
Signature · 1 line
2.5.5
PATCH v2 4/9 pnfs: only tear down lsegs that precede seqid in LAYOUTRETURN args
In reply to Jeff LaytonLAYOUTRETURN is "special" in that servers and clients are expected to work with old stateids. When the client sends a LAYOUTRETURN with an old stateid in it then the server is expected to only tear down layout segments that were present when that seqid was current. Ensure that the client handles its accounting accordingly.
--- fs/nfs/callback_proc.c | 3 ++- fs/nfs/nfs42proc.c | 2 +- fs/nfs/nfs4proc.c | 5 ++-- fs/nfs/pnfs.c | 64 +++++++++++++++++++++++++++++++++----------------- fs/nfs/pnfs.h | 6 +++-- 5 files changed, 52 insertions(+), 28 deletions(-)
fs/nfs/callback_proc.c +2 -1
@@ -217,7 +217,8 @@ static u32 initiate_file_draining(struct nfs_client *clp, }if (pnfs_mark_matching_lsegs_return (lo, &free_me_list, - &args->cbl_range)) { + &args->cbl_range, +be32_to_cpu (args->cbl_stateid.seqid))) { rv =NFS4_OK ; goto unlock; }
fs/nfs/nfs42proc.c +1 -1
@@ -232,7 +232,7 @@ nfs42_layoutstat_done(struct rpc_task *task, void *calldata)* with the current stateid. */ set_bit (NFS_LAYOUT_INVALID_STID , &lo->plh_flags); -pnfs_mark_matching_lsegs_invalid (lo, &head,NULL ); +pnfs_mark_matching_lsegs_invalid (lo, &head,NULL ,0 );spin_unlock (&inode->i_lock);pnfs_free_lseg_list (&head); }else
fs/nfs/nfs4proc.c +3 -2
@@ -7930,7 +7930,7 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)* with the current stateid. */ set_bit (NFS_LAYOUT_INVALID_STID , &lo->plh_flags); -pnfs_mark_matching_lsegs_invalid (lo, &head,NULL ); +pnfs_mark_matching_lsegs_invalid (lo, &head,NULL ,0 );spin_unlock (&inode->i_lock);pnfs_free_lseg_list (&head); }else
@@ -8122,7 +8122,8 @@ static void nfs4_layoutreturn_release(void *calldata)dprintk ("--> %s\n" , __func__);spin_lock (&lo->plh_inode->i_lock); -pnfs_mark_matching_lsegs_invalid (lo, &freeme, &lrp->args.range); +pnfs_mark_matching_lsegs_invalid (lo, &freeme, &lrp->args.range, +be32_to_cpu (lrp->args.stateid.seqid));pnfs_mark_layout_returned_if_empty (lo);if (lrp->res.lrs_present)pnfs_set_layout_stateid (lo, &lrp->res.stateid, true);
fs/nfs/pnfs.c +42 -22
130 lines not on this page · raw message
fs/nfs/pnfs.h +4 -2
@@ -266,10 +266,12 @@ int pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct nfs4_state *open_state);int pnfs_mark_matching_lsegs_invalid (struct pnfs_layout_hdr *lo,struct list_head *tmp_list, -const struct pnfs_layout_range *recall_range); +const struct pnfs_layout_range *recall_range, +u32 seq);int pnfs_mark_matching_lsegs_return (struct pnfs_layout_hdr *lo,struct list_head *tmp_list, -const struct pnfs_layout_range *recall_range); +const struct pnfs_layout_range *recall_range, +u32 seq);bool pnfs_roc (struct inode *ino);void pnfs_roc_release (struct inode *ino);void pnfs_roc_set_barrier (struct inode *ino,u32 barrier);
Signature · 1 line
2.5.5
PATCH v2 5/9 flexfiles: remove pointless setting of NFS_LAYOUT_RETURN_REQUESTED
In reply to Jeff LaytonSetting just the NFS_LAYOUT_RETURN_REQUESTED flag doesn't do anything, unless there are lsegs that are also being marked for return. At the point where that happens this flag is also set, so these set_bit calls don't do anything useful.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 2 -- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 8 +------- 2 files changed, 1 insertion(+), 9 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +0 -2
@@ -1249,8 +1249,6 @@ static int ff_layout_read_done_cb(struct rpc_task *task, hdr->pgio_mirror_idx + 1, &hdr->pgio_mirror_idx)) goto out_eagain; -set_bit (NFS_LAYOUT_RETURN_REQUESTED , - &hdr->lseg->pls_layout->plh_flags);pnfs_read_resend_pnfs (hdr);return task->tk_status;case -NFS4ERR_RESET_TO_MDS :
fs/nfs/flexfilelayout/flexfilelayoutdev.c +1 -7
@@ -393,13 +393,7 @@ nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx, 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 +if (fail_return || !ff_layout_has_available_ds (lseg))pnfs_error_mark_layout_for_return (ino, lseg); ds =NULL ; }
Signature · 1 line
2.5.5
PATCH v2 6/9 flexfiles: add kerneldoc header to nfs4_ff_layout_prepare_ds
In reply to Jeff Layton--- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
fs/nfs/flexfilelayout/flexfilelayoutdev.c +17 -1
@@ -342,7 +342,23 @@ out:return fh; } -/* Upon return, either ds is connected, or ds is NULL */ +/** +* nfs4_ff_layout_prepare_ds - prepare a DS connection for an RPC call +* @lseg: the layout segment we're operating on +* @ds_idx: index of the DS to use +* @fail_return: return layout on connect failure? +* +* Try to prepare a DS connection to accept an RPC call. This involves +* selecting a mirror to use and connecting the client to it if it's not +* already connected. +* +* Since we only need single functioning mirror to satisfy a read, we don't +* want to return the layout if there is one. For writes though, any down +* mirror should result in a LAYOUTRETURN. @fail_return is how we distinguish +* between the two cases. +* +* Returns a pointer to a connected DS object on success or NULL on failure. +*/ struct nfs4_pnfs_ds *nfs4_ff_layout_prepare_ds (struct pnfs_layout_segment *lseg,u32 ds_idx,bool fail_return)
Signature · 1 line
2.5.5
PATCH v2 7/9 pnfs: fix bad error handling in send_layoutget
In reply to Jeff LaytonCurrently, the code will clear the fail bit if we get back a fatal error. I don't think that's correct -- we only want to clear that bit if the layoutget succeeds.
--- fs/nfs/pnfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/nfs/pnfs.c +5 -3
@@ -876,11 +876,13 @@ send_layoutget(struct pnfs_layout_hdr *lo, lseg =nfs4_proc_layoutget (lgp, gfp_flags); }while (lseg ==ERR_PTR (-EAGAIN )); -if (IS_ERR (lseg) && !nfs_error_is_fatal (PTR_ERR (lseg))) - lseg =NULL ; -else +if (IS_ERR (lseg)) { +if (!nfs_error_is_fatal (PTR_ERR (lseg))) + lseg =NULL ; + }else {pnfs_layout_clear_fail_bit (lo,pnfs_iomode_to_fail_bit (range->iomode)); + }return lseg; }
Signature · 1 line
2.5.5
PATCH v2 8/9 pnfs: lift retry logic from send_layoutget to pnfs_update_layout
In reply to Jeff LaytonIf we get back something like NFS4ERR_OLD_STATEID, that will be translated into -EAGAIN, and the do/while loop in send_layoutget will drive the call again.
This is not quite what we want, I think. An error like that is a sign that something has changed. That something could have been a concurrent LAYOUTGET that would give us a usable lseg.
Lift the retry logic into pnfs_update_layout instead. That allows us to redo the layout search, and may spare us from having to issue an RPC.
--- fs/nfs/pnfs.c | 67 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 33 deletions(-)
fs/nfs/pnfs.c +34 -33
@@ -839,7 +839,6 @@ send_layoutget(struct pnfs_layout_hdr *lo,struct inode *ino = lo->plh_inode;struct nfs_server *server =NFS_SERVER (ino);struct nfs4_layoutget *lgp; -struct pnfs_layout_segment *lseg;loff_t i_size;dprintk ("--> %s\n" , __func__);
@@ -849,42 +848,30 @@ send_layoutget(struct pnfs_layout_hdr *lo,* store in lseg. If we race with a concurrent seqid morphing * op, then re-send the LAYOUTGET. */ -do { - lgp =kzalloc (sizeof (*lgp), gfp_flags); -if (lgp ==NULL ) -return NULL ; - - 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; - } - lgp->args.maxcount =PNFS_LAYOUT_MAXSIZE ; -pnfs_copy_range (&lgp->args.range, range); - lgp->args.type = server->pnfs_curr_ld->id; - lgp->args.inode = ino; - lgp->args.ctx =get_nfs_open_context (ctx); - lgp->gfp_flags = gfp_flags; - lgp->cred = lo->plh_lc_cred; + lgp =kzalloc (sizeof (*lgp), gfp_flags); +if (lgp ==NULL ) +return NULL ; - lseg =nfs4_proc_layoutget (lgp, gfp_flags); - }while (lseg ==ERR_PTR (-EAGAIN )); + i_size =i_size_read (ino); -if (IS_ERR (lseg)) { -if (!nfs_error_is_fatal (PTR_ERR (lseg))) - lseg =NULL ; - }else { -pnfs_layout_clear_fail_bit (lo, -pnfs_iomode_to_fail_bit (range->iomode)); + 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; } + lgp->args.maxcount =PNFS_LAYOUT_MAXSIZE ; +pnfs_copy_range (&lgp->args.range, range); + lgp->args.type = server->pnfs_curr_ld->id; + lgp->args.inode = ino; + lgp->args.ctx =get_nfs_open_context (ctx); + lgp->gfp_flags = gfp_flags; + lgp->cred = lo->plh_lc_cred; -return lseg; +return nfs4_proc_layoutget (lgp, gfp_flags); } static void pnfs_clear_layoutcommit(struct inode *inode,
@@ -1646,6 +1633,20 @@ lookup_again: arg.length =PAGE_ALIGN (arg.length); lseg =send_layoutget (lo, ctx, &arg, gfp_flags); +if (IS_ERR (lseg)) { +if (lseg ==ERR_PTR (-EAGAIN )) { +if (first) +pnfs_clear_first_layoutget (lo); +pnfs_put_layout_hdr (lo); + goto lookup_again; + } + +if (!nfs_error_is_fatal (PTR_ERR (lseg))) + lseg =NULL ; + }else { +pnfs_layout_clear_fail_bit (lo,pnfs_iomode_to_fail_bit (iomode)); + } +atomic_dec (&lo->plh_outstanding);trace_pnfs_update_layout (ino, pos, count, iomode, lo,PNFS_UPDATE_LAYOUT_SEND_LAYOUTGET );
Signature · 1 line
2.5.5
Re: [PATCH v2 8/9] pnfs: lift retry logic from send_layoutget to pnfs_update_layout
Quoted 30 lines · Jeff Layton
If we get back something like
NFS4ERR_OLD_STATEID, that will be translated into-EAGAIN, and the do/while loop insend_layoutgetwill drive the call again.This is not quite what we want, I think. An error like that is a sign that something has changed. That something could have been a concurrent LAYOUTGET that would give us a usable lseg.
Lift the retry logic into
pnfs_update_layoutinstead. That allows us to redo the layout search, and may spare us from having to issue an RPC.Signed-off-by Jeff Layton <[email protected]>---
fs/nfs/pnfs.c | 67 ++++++++++++++++++++++++++++++-----------------------------1 file changed, 34 insertions(+), 33 deletions(-)fs/nfs/pnfs.c +0
-1@@ -839,7 +839,6 @@ send_layoutget(struct pnfs_layout_hdr *lo, struct inode *ino = lo->plh_inode; struct nfs_server *server = NFS_SERVER(ino); struct nfs4_layoutget *lgp; -struct pnfs_layout_segment *lseg; loff_t i_size;
dprintk("--> %s\n", __func__);
fs/nfs/pnfs.c send_layoutget(struct pnfs_layout_hdr *lo, · line 856
Quoted 8 lines
fs/nfs/pnfs.c +0
-5@@ -849,42 +848,30 @@ send_layoutget(struct pnfs_layout_hdr *lo,* store in lseg. If we race with a concurrent seqid morphing * op, then re-send the LAYOUTGET. */ - do { - lgp = kzalloc(sizeof(*lgp), gfp_flags); - if (lgp == NULL) - return NULL; -
Just spotted this bug. The above should return ERR_PTR(-ENOMEM). Fixed in my nfs-4.7 branch.
Quoted 75 lines
fs/nfs/pnfs.c +3
-18- 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; - } - lgp->args.maxcount =PNFS_LAYOUT_MAXSIZE ; -pnfs_copy_range (&lgp->args.range, range); - lgp->args.type = server->pnfs_curr_ld->id; - lgp->args.inode = ino; - lgp->args.ctx =get_nfs_open_context (ctx); - lgp->gfp_flags = gfp_flags; - lgp->cred = lo->plh_lc_cred; + lgp =kzalloc (sizeof (*lgp), gfp_flags); +if (lgp ==NULL ) +return NULL ;fs/nfs/pnfs.c +1
-2- lseg =nfs4_proc_layoutget (lgp, gfp_flags); - }while (lseg ==ERR_PTR (-EAGAIN )); + i_size =i_size_read (ino);fs/nfs/pnfs.c +8
-6-if (IS_ERR (lseg)) { -if (!nfs_error_is_fatal (PTR_ERR (lseg))) - lseg =NULL ; - }else { -pnfs_layout_clear_fail_bit (lo, -pnfs_iomode_to_fail_bit (range->iomode)); + 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;}
fs/nfs/pnfs.c +7
-0+ lgp->args.maxcount =PNFS_LAYOUT_MAXSIZE ; +pnfs_copy_range (&lgp->args.range, range); + lgp->args.type = server->pnfs_curr_ld->id; + lgp->args.inode = ino; + lgp->args.ctx =get_nfs_open_context (ctx); + lgp->gfp_flags = gfp_flags; + lgp->cred = lo->plh_lc_cred;fs/nfs/pnfs.c +1
-1-return lseg; +return nfs4_proc_layoutget (lgp, gfp_flags);}
static void pnfs_clear_layoutcommit(struct inode *inode,fs/nfs/pnfs.c +0
-0@@ -1646,6 +1633,20 @@ lookup_again: arg.length = PAGE_ALIGN(arg.length);
lseg =send_layoutget(lo, ctx, &arg, gfp_flags);fs/nfs/pnfs.c +14
-0+if (IS_ERR (lseg)) { +if (lseg ==ERR_PTR (-EAGAIN )) { +if (first) +pnfs_clear_first_layoutget (lo); +pnfs_put_layout_hdr (lo); + goto lookup_again; + } + +if (!nfs_error_is_fatal (PTR_ERR (lseg))) + lseg =NULL ; + }else { +pnfs_layout_clear_fail_bit (lo,pnfs_iomode_to_fail_bit (iomode)); + } +
atomic_dec(&lo->plh_outstanding);trace_pnfs_update_layout(ino, pos, count, iomode, lo, PNFS_UPDATE_LAYOUT_SEND_LAYOUTGET);
Signature · 1 line
Jeff Layton <[email protected]>
PATCH v2 9/9 pnfs: rework LAYOUTGET retry handling
In reply to Jeff LaytonThere are several problems in the way a stateid is selected for a LAYOUTGET operation:
First, the list_empty test in pnfs_update_layout is not reliable. We may have lsegs on the list that are in the process of being returned.
Also, we pick a stateid to use in the rpc_prepare op, but that makes it difficult to serialize LAYOUTGETs that use the open stateid. That serialization is done in pnfs_update_layout, which occurs well before rpc_prepare.
Between those two events, the i_lock is dropped and reacquired. pnfs_update_layout can find that the list has lsegs in it and not do any serialization, but then later pnfs_choose_layoutget_stateid ends up choosing the open stateid.
Fix this by selecting the stateid to use in the LAYOUTGET earlier, when we're searching for a usable layout segment. This way we can do it all while holding the i_lock the first time, and ensure that we serialize any LAYOUTGET call that uses a non-layout stateid.
This also means a rework of how retryable errors are handled as we must update the stateid if we need to retransmit.
Currently, when we need to retry a LAYOUTGET because of an error, we drive that retry via the rpc state machine. That's not really ideal though. Most of those errors boil down to the fact that the layout state has changed in some fashion. Thus, what we really want to do is to re-search for a layout and take it from there.
Fix nfs4_layoutget_done not to requeue the rpc_task on a retryable error, but rather to just set the tk_status to -EAGAIN. This tells the upper layers to retry the whole thing from scratch, searching for an lseg, and then re-driving the LAYOUTGET.
In order to handle errors like NFS4ERR_DELAY properly, we must also pass a pointer to the timeout field, that is now moved to the stack in pnfs_update_layout.
The complicating factor is -NFS4ERR_RECALLCONFLICT, as that involves a timeout after which we give up and return NULL back to the caller. So, take special care not to clobber that error with -EAGAIN, so the upper layers can distinguish between the two.
Finally, when send_layoutget gets back an -EAGAIN, and the timeout is set, have it just sleep that long via schedule_timeout.
--- fs/nfs/nfs4proc.c | 63 +++++++----------------------- fs/nfs/pnfs.c | 102 ++++++++++++++++++++++++------------------------ fs/nfs/pnfs.h | 4 -- include/linux/nfs_xdr.h | 3 +- 4 files changed, 67 insertions(+), 105 deletions(-)
fs/nfs/nfs4proc.c +15 -48
@@ -416,6 +416,7 @@ static int nfs4_do_handle_exception(struct nfs_server *server,case -NFS4ERR_DELAY :nfs_inc_server_stats (server,NFSIOS_DELAY );case -NFS4ERR_GRACE : +case -NFS4ERR_RECALLCONFLICT : exception->delay =1 ;return 0 ;
@@ -7824,23 +7825,11 @@ nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)struct nfs4_layoutget *lgp = calldata;struct nfs_server *server =NFS_SERVER (lgp->args.inode);struct nfs4_session *session =nfs4_get_session (server); -int ret;dprintk ("--> %s\n" , __func__); -/* Note the is a race here, where a CB_LAYOUTRECALL can come in -* right now covering the LAYOUTGET we are about to send. -* However, that is not so catastrophic, and there seems -* to be no way to prevent it completely. -*/ -if (nfs41_setup_sequence (session, &lgp->args.seq_args, - &lgp->res.seq_res, task)) -return ; - ret =pnfs_choose_layoutget_stateid (&lgp->args.stateid, -NFS_I (lgp->args.inode)->layout, - &lgp->args.range, - lgp->args.ctx->state); -if (ret <0 ) -rpc_exit (task, ret); +nfs41_setup_sequence (session, &lgp->args.seq_args, + &lgp->res.seq_res, task); +dprintk ("<-- %s\n" , __func__); }static void nfs4_layoutget_done (struct rpc_task *task,void *calldata)
@@ -7850,7 +7839,6 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)struct nfs_server *server =NFS_SERVER (inode);struct pnfs_layout_hdr *lo;struct nfs4_state *state =NULL ; -unsigned long timeo, now, giveup;dprintk ("--> %s tk_status => %d\n" , __func__, -task->tk_status);
@@ -7883,35 +7871,9 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)case -NFS4ERR_LAYOUTTRYLATER :if (lgp->args.minlength ==0 ) goto out_overflow; -/* -* NFS4ERR_RECALLCONFLICT is when conflict with self (must recall -* existing layout before getting a new one). -*/ -case -NFS4ERR_RECALLCONFLICT : - timeo =rpc_get_timeout (task->tk_client); - giveup = lgp->args.timestamp + timeo; - now = jiffies; -if (time_after (giveup, now)) { -unsigned long delay; - -/* Delay for: -* - Not less then NFS4_POLL_RETRY_MIN. -* - One last time a jiffie before we give up -* - exponential backoff (time_now minus start_attempt) -*/ - delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, -min ((giveup - now -1 ), - now - lgp->args.timestamp)); - -dprintk ("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n" , - __func__, delay); -rpc_delay (task, delay); -/* Do not call nfs4_async_handle_error() */ - goto out_restart; - } -break ;case -NFS4ERR_EXPIRED :case -NFS4ERR_BAD_STATEID : + *lgp->timeout =0 ;spin_lock (&inode->i_lock);if (nfs4_stateid_match (&lgp->args.stateid, &lgp->args.ctx->state->stateid)) {
@@ -7937,15 +7899,21 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)spin_unlock (&inode->i_lock); goto out_restart; } -if (nfs4_async_handle_error (task, server, state, &lgp->timeout) == -EAGAIN ) + +/* +* Don't clobber -NFS4ERR_RECALLCONFLICT, as we want the upper layers +* to be able to distinguish between that and -EAGAIN so that we can +* properly give up in the RECALLCONFLICT case. +*/ +if (nfs4_async_handle_error (task, server, state, lgp->timeout) == -EAGAIN && + task->tk_status != -NFS4ERR_RECALLCONFLICT ) goto out_restart; out:dprintk ("<-- %s\n" , __func__);return ; out_restart: - task->tk_status =0 ; -rpc_restart_call_prepare (task); -return ; + task->tk_status = -EAGAIN ; + goto out; out_overflow: task->tk_status = -EOVERFLOW ; goto out;
@@ -8050,7 +8018,6 @@ nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags)return ERR_PTR (-ENOMEM ); } lgp->args.layout.pglen = max_pages *PAGE_SIZE ; - lgp->args.timestamp = jiffies; lgp->res.layoutp = &lgp->args.layout; lgp->res.seq_res.sr_slot =NULL ;
fs/nfs/pnfs.c +51 -51
153 lines not on this page · raw message
fs/nfs/pnfs.h +0 -4
@@ -260,10 +260,6 @@ void pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo);void pnfs_set_layout_stateid (struct pnfs_layout_hdr *lo,const nfs4_stateid *new,bool update_barrier); -int pnfs_choose_layoutget_stateid (nfs4_stateid *dst, -struct pnfs_layout_hdr *lo, -const struct pnfs_layout_range *range, -struct nfs4_state *open_state); int pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, struct list_head *tmp_list, const struct pnfs_layout_range *recall_range,
include/linux/nfs_xdr.h +1 -2
@@ -233,7 +233,6 @@ struct nfs4_layoutget_args {struct inode *inode;struct nfs_open_context *ctx;nfs4_stateid stateid; -unsigned long timestamp;struct nfs4_layoutdriver_data layout; };
@@ -251,7 +250,7 @@ struct nfs4_layoutget {struct nfs4_layoutget_res res;struct rpc_cred *cred;gfp_t gfp_flags; -long timeout; +long *timeout; };struct nfs4_getdeviceinfo_args {
Signature · 1 line
2.5.5