Skip to content

Commit ea7c38f

Browse files
committed
NFSv4: Ensure we reference the inode for return-on-close in delegreturn
If we have to do a return-on-close in the delegreturn code, then we must ensure that the inode and super block remain referenced. Cc: Peng Tao <tao.peng@primarydata.com> Cc: stable@vger.kernel.org # 3.17.x Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Reviewed-by: Peng Tao <tao.peng@primarydata.com>
1 parent 6ae3733 commit ea7c38f

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

fs/nfs/internal.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ extern struct rpc_stat nfs_rpcstat;
391391

392392
extern int __init register_nfs_fs(void);
393393
extern void __exit unregister_nfs_fs(void);
394-
extern void nfs_sb_active(struct super_block *sb);
394+
extern bool nfs_sb_active(struct super_block *sb);
395395
extern void nfs_sb_deactive(struct super_block *sb);
396396

397397
/* namespace.c */
@@ -514,6 +514,26 @@ extern int nfs41_walk_client_list(struct nfs_client *clp,
514514
struct nfs_client **result,
515515
struct rpc_cred *cred);
516516

517+
static inline struct inode *nfs_igrab_and_active(struct inode *inode)
518+
{
519+
inode = igrab(inode);
520+
if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
521+
iput(inode);
522+
inode = NULL;
523+
}
524+
return inode;
525+
}
526+
527+
static inline void nfs_iput_and_deactive(struct inode *inode)
528+
{
529+
if (inode != NULL) {
530+
struct super_block *sb = inode->i_sb;
531+
532+
iput(inode);
533+
nfs_sb_deactive(sb);
534+
}
535+
}
536+
517537
/*
518538
* Determine the device name as a string
519539
*/

fs/nfs/nfs4proc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,9 +5175,13 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
51755175
static void nfs4_delegreturn_release(void *calldata)
51765176
{
51775177
struct nfs4_delegreturndata *data = calldata;
5178+
struct inode *inode = data->inode;
51785179

5179-
if (data->roc)
5180-
pnfs_roc_release(data->inode);
5180+
if (inode) {
5181+
if (data->roc)
5182+
pnfs_roc_release(inode);
5183+
nfs_iput_and_deactive(inode);
5184+
}
51815185
kfree(calldata);
51825186
}
51835187

@@ -5234,9 +5238,9 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
52345238
nfs_fattr_init(data->res.fattr);
52355239
data->timestamp = jiffies;
52365240
data->rpc_status = 0;
5237-
data->inode = inode;
5238-
data->roc = list_empty(&NFS_I(inode)->open_files) ?
5239-
pnfs_roc(inode) : false;
5241+
data->inode = nfs_igrab_and_active(inode);
5242+
if (data->inode)
5243+
data->roc = nfs4_roc(inode);
52405244

52415245
task_setup_data.callback_data = data;
52425246
msg.rpc_argp = &data->args;

fs/nfs/super.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,15 @@ void __exit unregister_nfs_fs(void)
405405
unregister_filesystem(&nfs_fs_type);
406406
}
407407

408-
void nfs_sb_active(struct super_block *sb)
408+
bool nfs_sb_active(struct super_block *sb)
409409
{
410410
struct nfs_server *server = NFS_SB(sb);
411411

412-
if (atomic_inc_return(&server->active) == 1)
413-
atomic_inc(&sb->s_active);
412+
if (!atomic_inc_not_zero(&sb->s_active))
413+
return false;
414+
if (atomic_inc_return(&server->active) != 1)
415+
atomic_dec(&sb->s_active);
416+
return true;
414417
}
415418
EXPORT_SYMBOL_GPL(nfs_sb_active);
416419

0 commit comments

Comments
 (0)