Skip to content

Commit 9c6376e

Browse files
committed
pNFS: Prevent the layout header refcount going to zero in pnfs_roc()
Ensure that we hold a reference to the layout header when processing the pNFS return-on-close so that the refcount value does not inadvertently go to zero. Reported-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Cc: stable@vger.kernel.org # v4.10+ Tested-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
1 parent d9ee655 commit 9c6376e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

fs/nfs/pnfs.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,11 @@ pnfs_detach_layout_hdr(struct pnfs_layout_hdr *lo)
292292
void
293293
pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
294294
{
295-
struct inode *inode = lo->plh_inode;
295+
struct inode *inode;
296296

297+
if (!lo)
298+
return;
299+
inode = lo->plh_inode;
297300
pnfs_layoutreturn_before_put_layout_hdr(lo);
298301

299302
if (refcount_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
@@ -1241,10 +1244,12 @@ bool pnfs_roc(struct inode *ino,
12411244
spin_lock(&ino->i_lock);
12421245
lo = nfsi->layout;
12431246
if (!lo || !pnfs_layout_is_valid(lo) ||
1244-
test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags))
1247+
test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1248+
lo = NULL;
12451249
goto out_noroc;
1250+
}
1251+
pnfs_get_layout_hdr(lo);
12461252
if (test_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) {
1247-
pnfs_get_layout_hdr(lo);
12481253
spin_unlock(&ino->i_lock);
12491254
wait_on_bit(&lo->plh_flags, NFS_LAYOUT_RETURN,
12501255
TASK_UNINTERRUPTIBLE);
@@ -1312,10 +1317,12 @@ bool pnfs_roc(struct inode *ino,
13121317
struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld;
13131318
if (ld->prepare_layoutreturn)
13141319
ld->prepare_layoutreturn(args);
1320+
pnfs_put_layout_hdr(lo);
13151321
return true;
13161322
}
13171323
if (layoutreturn)
13181324
pnfs_send_layoutreturn(lo, &stateid, iomode, true);
1325+
pnfs_put_layout_hdr(lo);
13191326
return false;
13201327
}
13211328

0 commit comments

Comments
 (0)