Skip to content

Commit 193e3aa

Browse files
Peng TaoTom Haynes
authored andcommitted
nfs41: introduce NFS_LAYOUT_RETURN_BEFORE_CLOSE
When it is set, generic pnfs would try to send layoutreturn right before last close/delegation_return regard less NFS_LAYOUT_ROC is set or not. LD can then make sure layoutreturn is always sent rather than being omitted. The difference against NFS_LAYOUT_RETURN is that NFS_LAYOUT_RETURN_BEFORE_CLOSE does not block usage of the layout so LD can set it and expect generic layer to try pnfs path at the same time. Signed-off-by: Peng Tao <tao.peng@primarydata.com> Signed-off-by: Tom Haynes <loghyr@primarydata.com>
1 parent 6c16605 commit 193e3aa

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

fs/nfs/nfs4proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,6 +7797,8 @@ static void nfs4_layoutreturn_release(void *calldata)
77977797
if (lrp->res.lrs_present)
77987798
pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
77997799
clear_bit(NFS_LAYOUT_RETURN, &lo->plh_flags);
7800+
clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags);
7801+
rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq);
78007802
lo->plh_block_lgets--;
78017803
spin_unlock(&lo->plh_inode->i_lock);
78027804
pnfs_put_layout_hdr(lrp->args.layout);

fs/nfs/pnfs.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid,
909909
status = -ENOMEM;
910910
spin_lock(&ino->i_lock);
911911
lo->plh_block_lgets--;
912+
rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq);
912913
spin_unlock(&ino->i_lock);
913914
pnfs_put_layout_hdr(lo);
914915
goto out;
@@ -926,11 +927,6 @@ pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid,
926927

927928
status = nfs4_proc_layoutreturn(lrp, sync);
928929
out:
929-
if (status) {
930-
spin_lock(&ino->i_lock);
931-
clear_bit(NFS_LAYOUT_RETURN, &lo->plh_flags);
932-
spin_unlock(&ino->i_lock);
933-
}
934930
dprintk("<-- %s status: %d\n", __func__, status);
935931
return status;
936932
}
@@ -1028,8 +1024,9 @@ bool pnfs_roc(struct inode *ino)
10281024
{
10291025
struct pnfs_layout_hdr *lo;
10301026
struct pnfs_layout_segment *lseg, *tmp;
1027+
nfs4_stateid stateid;
10311028
LIST_HEAD(tmp_list);
1032-
bool found = false;
1029+
bool found = false, layoutreturn = false;
10331030

10341031
spin_lock(&ino->i_lock);
10351032
lo = NFS_I(ino)->layout;
@@ -1050,7 +1047,20 @@ bool pnfs_roc(struct inode *ino)
10501047
return true;
10511048

10521049
out_nolayout:
1050+
if (lo) {
1051+
stateid = lo->plh_stateid;
1052+
layoutreturn =
1053+
test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE,
1054+
&lo->plh_flags);
1055+
if (layoutreturn) {
1056+
lo->plh_block_lgets++;
1057+
pnfs_get_layout_hdr(lo);
1058+
}
1059+
}
10531060
spin_unlock(&ino->i_lock);
1061+
if (layoutreturn)
1062+
pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, 0,
1063+
NFS4_MAX_UINT64, true);
10541064
return false;
10551065
}
10561066

@@ -1085,8 +1095,9 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task)
10851095
struct nfs_inode *nfsi = NFS_I(ino);
10861096
struct pnfs_layout_hdr *lo;
10871097
struct pnfs_layout_segment *lseg;
1098+
nfs4_stateid stateid;
10881099
u32 current_seqid;
1089-
bool found = false;
1100+
bool found = false, layoutreturn = false;
10901101

10911102
spin_lock(&ino->i_lock);
10921103
list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list)
@@ -1103,7 +1114,22 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task)
11031114
*/
11041115
*barrier = current_seqid + atomic_read(&lo->plh_outstanding);
11051116
out:
1117+
if (!found) {
1118+
stateid = lo->plh_stateid;
1119+
layoutreturn =
1120+
test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE,
1121+
&lo->plh_flags);
1122+
if (layoutreturn) {
1123+
lo->plh_block_lgets++;
1124+
pnfs_get_layout_hdr(lo);
1125+
}
1126+
}
11061127
spin_unlock(&ino->i_lock);
1128+
if (layoutreturn) {
1129+
rpc_sleep_on(&NFS_SERVER(ino)->roc_rpcwaitq, task, NULL);
1130+
pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, 0,
1131+
NFS4_MAX_UINT64, false);
1132+
}
11071133
return found;
11081134
}
11091135

fs/nfs/pnfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ enum {
9696
NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */
9797
NFS_LAYOUT_ROC, /* some lseg had roc bit set */
9898
NFS_LAYOUT_RETURN, /* Return this layout ASAP */
99+
NFS_LAYOUT_RETURN_BEFORE_CLOSE, /* Return this layout before close */
99100
NFS_LAYOUT_INVALID_STID, /* layout stateid id is invalid */
100101
NFS_LAYOUT_FIRST_LAYOUTGET, /* Serialize first layoutget */
101102
};

0 commit comments

Comments
 (0)