Commit ea7c38fe authored by Trond Myklebust's avatar Trond Myklebust

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: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
Reviewed-by: default avatarPeng Tao <tao.peng@primarydata.com>
parent 6ae37339
...@@ -391,7 +391,7 @@ extern struct rpc_stat nfs_rpcstat; ...@@ -391,7 +391,7 @@ extern struct rpc_stat nfs_rpcstat;
extern int __init register_nfs_fs(void); extern int __init register_nfs_fs(void);
extern void __exit unregister_nfs_fs(void); extern void __exit unregister_nfs_fs(void);
extern void nfs_sb_active(struct super_block *sb); extern bool nfs_sb_active(struct super_block *sb);
extern void nfs_sb_deactive(struct super_block *sb); extern void nfs_sb_deactive(struct super_block *sb);
/* namespace.c */ /* namespace.c */
...@@ -514,6 +514,26 @@ extern int nfs41_walk_client_list(struct nfs_client *clp, ...@@ -514,6 +514,26 @@ extern int nfs41_walk_client_list(struct nfs_client *clp,
struct nfs_client **result, struct nfs_client **result,
struct rpc_cred *cred); struct rpc_cred *cred);
static inline struct inode *nfs_igrab_and_active(struct inode *inode)
{
inode = igrab(inode);
if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
iput(inode);
inode = NULL;
}
return inode;
}
static inline void nfs_iput_and_deactive(struct inode *inode)
{
if (inode != NULL) {
struct super_block *sb = inode->i_sb;
iput(inode);
nfs_sb_deactive(sb);
}
}
/* /*
* Determine the device name as a string * Determine the device name as a string
*/ */
......
...@@ -5175,9 +5175,13 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) ...@@ -5175,9 +5175,13 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
static void nfs4_delegreturn_release(void *calldata) static void nfs4_delegreturn_release(void *calldata)
{ {
struct nfs4_delegreturndata *data = calldata; struct nfs4_delegreturndata *data = calldata;
struct inode *inode = data->inode;
if (data->roc) if (inode) {
pnfs_roc_release(data->inode); if (data->roc)
pnfs_roc_release(inode);
nfs_iput_and_deactive(inode);
}
kfree(calldata); kfree(calldata);
} }
...@@ -5234,9 +5238,9 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co ...@@ -5234,9 +5238,9 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
nfs_fattr_init(data->res.fattr); nfs_fattr_init(data->res.fattr);
data->timestamp = jiffies; data->timestamp = jiffies;
data->rpc_status = 0; data->rpc_status = 0;
data->inode = inode; data->inode = nfs_igrab_and_active(inode);
data->roc = list_empty(&NFS_I(inode)->open_files) ? if (data->inode)
pnfs_roc(inode) : false; data->roc = nfs4_roc(inode);
task_setup_data.callback_data = data; task_setup_data.callback_data = data;
msg.rpc_argp = &data->args; msg.rpc_argp = &data->args;
......
...@@ -405,12 +405,15 @@ void __exit unregister_nfs_fs(void) ...@@ -405,12 +405,15 @@ void __exit unregister_nfs_fs(void)
unregister_filesystem(&nfs_fs_type); unregister_filesystem(&nfs_fs_type);
} }
void nfs_sb_active(struct super_block *sb) bool nfs_sb_active(struct super_block *sb)
{ {
struct nfs_server *server = NFS_SB(sb); struct nfs_server *server = NFS_SB(sb);
if (atomic_inc_return(&server->active) == 1) if (!atomic_inc_not_zero(&sb->s_active))
atomic_inc(&sb->s_active); return false;
if (atomic_inc_return(&server->active) != 1)
atomic_dec(&sb->s_active);
return true;
} }
EXPORT_SYMBOL_GPL(nfs_sb_active); EXPORT_SYMBOL_GPL(nfs_sb_active);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment