nfs: make sure sillyrenames run to completion (try #1)
Subsystems (2)
cover nfs: make sure sillyrenames run to completion (try #1)
We had a bug report recently where someone was complaining about silly-renamed files being left around:
https://bugzilla.redhat.com/show_bug.cgi?id=511901
...they attached a reproducer to the bug which involves a pthreads-based program killing a child thread that's unlinking and closing a file.
The unlink triggers a sillyrename (since the file is still open). The parent kills the child thread and if timed just right, the child thread will be killed after the RENAME call is issued but before the reply is processed. The file will end up renamed on the server, but the client won't be aware of it and won't unlink it during dentry_iput.
This patchset is intended to prevent this from happening by having nfs_sillyrename use an asynchronous rename call and simply wait for the call to complete in TASK_KILLABLE sleep before proceeding. If the task is killed while the rename RPC is on the wire, it'll still run to completion even though the thread that initiated it was killed off.
To facilitate this, the set first changes all of the existing rename calls to use standardized argument and response containers. The nfs_sillyrename call is then moved to unlink.c (where the rest of the sillyrename code lives), and then is converted to use an asynchronous RPC call to handle the rename.
I've tested this by running the reproducer in the above bug report in a loop for several hours and never ended up with a leftover .nfs* file.
Jeff Layton (9):
nfs: eliminate nfs3_renameargs
nfs: convert nfs_renameargs to use qstr structs
nfs: eliminate nfs4_rename_arg
nfs: standardize the rename response container
nfs: move nfs_sillyrename to unlink.c
nfs: eliminate qsilly var from nfs_sillyrename
nfs: add a rename_setup nfs_rpc_op for async renames
nfs: add rename_done nfs_rpc_op
nfs: make sillyrename an async operation
fs/nfs/dir.c | 70 ------------- fs/nfs/nfs2xdr.c | 8 +- fs/nfs/nfs3proc.c | 62 +++++++++--- fs/nfs/nfs3xdr.c | 16 ++-- fs/nfs/nfs4proc.c | 43 ++++++++- fs/nfs/nfs4xdr.c | 4 +- fs/nfs/proc.c | 30 +++++- fs/nfs/unlink.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++- include/linux/nfs_fs.h | 2 +- include/linux/nfs_xdr.h | 64 ++++-------- 10 files changed, 405 insertions(+), 150 deletions(-)
PATCH 1/9 nfs: eliminate nfs3_renameargs
It's exactly the same as nfs_renameargs, so move it to the area of the header where protocol-neutral defintions live and eliminate the v3 specific variant.
--- fs/nfs/nfs3proc.c | 2 +- fs/nfs/nfs3xdr.c | 2 +- include/linux/nfs_xdr.h | 30 ++++++++++++------------------ 3 files changed, 14 insertions(+), 20 deletions(-)
fs/nfs/nfs3proc.c +1 -1
@@ -442,7 +442,7 @@ static int nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, struct inode *new_dir, struct qstr *new_name) { - struct nfs3_renameargs arg = { + struct nfs_renameargs arg = { .fromfh = NFS_FH(old_dir), .fromname = old_name->name, .fromlen = old_name->len,
fs/nfs/nfs3xdr.c +1 -1
@@ -442,7 +442,7 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req, __be32 *p, struct nfs3_mknodargs *args)* Encode RENAME arguments */ static int -nfs3_xdr_renameargs (struct rpc_rqst *req,__be32 *p,struct nfs3_renameargs *args) +nfs3_xdr_renameargs (struct rpc_rqst *req,__be32 *p,struct nfs_renameargs *args) { p =xdr_encode_fhandle (p, args->fromfh); p =xdr_encode_array (p, args->fromname, args->fromlen);
include/linux/nfs_xdr.h +12 -18
@@ -400,6 +400,18 @@ struct nfs_removeres { };/* +* Common arguments to the rename call +*/ +struct nfs_renameargs { +struct nfs_fh * fromfh; +const char * fromname; +unsigned int fromlen; +struct nfs_fh * tofh; +const char * toname; +unsigned int tolen; +}; + +/* * Argument struct for decode_entry function */ struct nfs_entry {
@@ -434,15 +446,6 @@ struct nfs_createargs {struct iattr * sattr; }; -struct nfs_renameargs { -struct nfs_fh * fromfh; -const char * fromname; -unsigned int fromlen; -struct nfs_fh * tofh; -const char * toname; -unsigned int tolen; -}; -struct nfs_setattrargs {struct nfs_fh * fh;nfs4_stateid stateid;
@@ -586,15 +589,6 @@ struct nfs3_mknodargs {dev_t rdev; }; -struct nfs3_renameargs { -struct nfs_fh * fromfh; -const char * fromname; -unsigned int fromlen; -struct nfs_fh * tofh; -const char * toname; -unsigned int tolen; -}; -struct nfs3_linkargs {struct nfs_fh * fromfh;struct nfs_fh * tofh;
Signature · 1 line
1.7.1
PATCH 2/9 nfs: convert nfs_renameargs to use qstr structs
In reply to Jeff LaytonThe v4 version already does this.
--- fs/nfs/nfs2xdr.c | 8 ++++---- fs/nfs/nfs3proc.c | 10 ++++------ fs/nfs/nfs3xdr.c | 8 ++++---- fs/nfs/proc.c | 10 ++++------ include/linux/nfs_xdr.h | 10 ++++------ 5 files changed, 20 insertions(+), 26 deletions(-)
fs/nfs/nfs2xdr.c +4 -4
@@ -337,10 +337,10 @@ nfs_xdr_createargs(struct rpc_rqst *req, __be32 *p, struct nfs_createargs *args)static int nfs_xdr_renameargs (struct rpc_rqst *req,__be32 *p,struct nfs_renameargs *args) { - p =xdr_encode_fhandle (p, args->fromfh); - p =xdr_encode_array (p, args->fromname, args->fromlen); - p =xdr_encode_fhandle (p, args->tofh); - p =xdr_encode_array (p, args->toname, args->tolen); + p =xdr_encode_fhandle (p, args->old_dir); + p =xdr_encode_array (p, args->old_name->name, args->old_name->len); + p =xdr_encode_fhandle (p, args->new_dir); + p =xdr_encode_array (p, args->new_name->name, args->new_name->len); req->rq_slen =xdr_adjust_iovec (req->rq_svec, p);return 0 ; }
fs/nfs/nfs3proc.c +4 -6
@@ -443,12 +443,10 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, struct inode *new_dir, struct qstr *new_name) { struct nfs_renameargs arg = { - .fromfh =NFS_FH (old_dir), - .fromname = old_name->name, - .fromlen = old_name->len, - .tofh =NFS_FH (new_dir), - .toname = new_name->name, - .tolen = new_name->len + .old_dir =NFS_FH (old_dir), + .old_name = old_name, + .new_dir =NFS_FH (new_dir), + .new_name = new_name, };struct nfs3_renameres res; struct rpc_message msg = {
fs/nfs/nfs3xdr.c +4 -4
@@ -444,10 +444,10 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req, __be32 *p, struct nfs3_mknodargs *args)static int nfs3_xdr_renameargs (struct rpc_rqst *req,__be32 *p,struct nfs_renameargs *args) { - p =xdr_encode_fhandle (p, args->fromfh); - p =xdr_encode_array (p, args->fromname, args->fromlen); - p =xdr_encode_fhandle (p, args->tofh); - p =xdr_encode_array (p, args->toname, args->tolen); + p =xdr_encode_fhandle (p, args->old_dir); + p =xdr_encode_array (p, args->old_name->name, args->old_name->len); + p =xdr_encode_fhandle (p, args->new_dir); + p =xdr_encode_array (p, args->new_name->name, args->new_name->len); req->rq_slen =xdr_adjust_iovec (req->rq_svec, p);return 0 ; }
fs/nfs/proc.c +4 -6
@@ -370,12 +370,10 @@ nfs_proc_rename(struct inode *old_dir, struct qstr *old_name, struct inode *new_dir, struct qstr *new_name) { struct nfs_renameargs arg = { - .fromfh =NFS_FH (old_dir), - .fromname = old_name->name, - .fromlen = old_name->len, - .tofh =NFS_FH (new_dir), - .toname = new_name->name, - .tolen = new_name->len + .old_dir =NFS_FH (old_dir), + .old_name = old_name, + .new_dir =NFS_FH (new_dir), + .new_name = new_name, }; struct rpc_message msg = { .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
include/linux/nfs_xdr.h +4 -6
@@ -403,12 +403,10 @@ struct nfs_removeres {* Common arguments to the rename call */ struct nfs_renameargs { -struct nfs_fh * fromfh; -const char * fromname; -unsigned int fromlen; -struct nfs_fh * tofh; -const char * toname; -unsigned int tolen; +const struct nfs_fh * old_dir; +const struct nfs_fh * new_dir; +const struct qstr * old_name; +const struct qstr * new_name; };/*
Signature · 1 line
1.7.1
PATCH 3/9 nfs: eliminate nfs4_rename_arg
In reply to Jeff LaytonAdd the missing fields to nfs_renameargs and drop nfs4_rename_arg
--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 2 +- include/linux/nfs_xdr.h | 19 ++++++------------- 3 files changed, 8 insertions(+), 15 deletions(-)
fs/nfs/nfs4proc.c +1 -1
@@ -2675,7 +2675,7 @@ static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, struct inode *new_dir, struct qstr *new_name) { struct nfs_server *server = NFS_SERVER(old_dir); - struct nfs4_rename_arg arg = { + struct nfs_renameargs arg = { .old_dir = NFS_FH(old_dir), .new_dir = NFS_FH(new_dir), .old_name = old_name,
fs/nfs/nfs4xdr.c +1 -1
@@ -1823,7 +1823,7 @@ static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs/* * Encode RENAME request */ -static int nfs4_xdr_enc_rename (struct rpc_rqst *req,__be32 *p,const struct nfs4_rename_arg *args) +static int nfs4_xdr_enc_rename (struct rpc_rqst *req,__be32 *p,const struct nfs_renameargs *args) {struct xdr_stream xdr;struct compound_hdr hdr = {
include/linux/nfs_xdr.h +6 -13
@@ -403,10 +403,12 @@ struct nfs_removeres {* Common arguments to the rename call */ struct nfs_renameargs { -const struct nfs_fh * old_dir; -const struct nfs_fh * new_dir; -const struct qstr * old_name; -const struct qstr * new_name; +const struct nfs_fh * old_dir; +const struct nfs_fh * new_dir; +const struct qstr * old_name; +const struct qstr * new_name; +const u32 * bitmask; +struct nfs4_sequence_args seq_args; };/*
@@ -793,15 +795,6 @@ struct nfs4_readlink_res {struct nfs4_sequence_res seq_res; }; -struct nfs4_rename_arg { -const struct nfs_fh * old_dir; -const struct nfs_fh * new_dir; -const struct qstr * old_name; -const struct qstr * new_name; -const u32 * bitmask; -struct nfs4_sequence_args seq_args; -}; -struct nfs4_rename_res {const struct nfs_server * server;struct nfs4_change_info old_cinfo;
Signature · 1 line
1.7.1
PATCH 4/9 nfs: standardize the rename response container
In reply to Jeff LaytonRight now, v3 and v4 have their own variants and v2 doesn't have one at all. Create a standard struct that will work for v3 and v4.
--- fs/nfs/nfs3proc.c | 16 ++++++++-------- fs/nfs/nfs3xdr.c | 6 +++--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4xdr.c | 2 +- include/linux/nfs_xdr.h | 23 +++++++++-------------- 5 files changed, 22 insertions(+), 27 deletions(-)
fs/nfs/nfs3proc.c +8 -8
@@ -448,7 +448,7 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, .new_dir = NFS_FH(new_dir), .new_name = new_name, }; -struct nfs3_renameres res; +struct nfs_renameres res;struct rpc_message msg = { .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME ], .rpc_argp = &arg,
@@ -458,17 +458,17 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,dprintk ("NFS call rename %s -> %s\n" , old_name->name, new_name->name); - res.fromattr =nfs_alloc_fattr (); - res.toattr =nfs_alloc_fattr (); -if (res.fromattr ==NULL || res.toattr ==NULL ) + res.old_fattr =nfs_alloc_fattr (); + res.new_fattr =nfs_alloc_fattr (); +if (res.old_fattr ==NULL || res.new_fattr ==NULL ) goto out; status =rpc_call_sync (NFS_CLIENT (old_dir), &msg,0 ); -nfs_post_op_update_inode (old_dir, res.fromattr); -nfs_post_op_update_inode (new_dir, res.toattr); +nfs_post_op_update_inode (old_dir, res.old_fattr); +nfs_post_op_update_inode (new_dir, res.new_fattr); out: -nfs_free_fattr (res.toattr); -nfs_free_fattr (res.fromattr); +nfs_free_fattr (res.old_fattr); +nfs_free_fattr (res.new_fattr);dprintk ("NFS reply rename: %d\n" , status);return status; }
fs/nfs/nfs3xdr.c +3 -3
@@ -970,14 +970,14 @@ nfs3_xdr_createres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res)* Decode RENAME reply */ static int -nfs3_xdr_renameres (struct rpc_rqst *req,__be32 *p,struct nfs3_renameres *res) +nfs3_xdr_renameres (struct rpc_rqst *req,__be32 *p,struct nfs_renameres *res) {int status;if ((status =ntohl (*p++)) !=0 ) status =nfs_stat_to_errno (status); - p =xdr_decode_wcc_data (p, res->fromattr); - p =xdr_decode_wcc_data (p, res->toattr); + p =xdr_decode_wcc_data (p, res->old_fattr); + p =xdr_decode_wcc_data (p, res->new_fattr);return status; }
fs/nfs/nfs4proc.c +1 -1
@@ -2682,7 +2682,7 @@ static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, .new_name = new_name, .bitmask = server->attr_bitmask, }; -struct nfs4_rename_res res = { +struct nfs_renameres res = { .server = server, };struct rpc_message msg = {
fs/nfs/nfs4xdr.c +1 -1
@@ -4873,7 +4873,7 @@ out:/* * Decode RENAME response */ -static int nfs4_xdr_dec_rename (struct rpc_rqst *rqstp,__be32 *p,struct nfs4_rename_res *res) +static int nfs4_xdr_dec_rename (struct rpc_rqst *rqstp,__be32 *p,struct nfs_renameres *res) {struct xdr_stream xdr;struct compound_hdr hdr;
include/linux/nfs_xdr.h +9 -14
@@ -411,6 +411,15 @@ struct nfs_renameargs {struct nfs4_sequence_args seq_args; }; +struct nfs_renameres { +const struct nfs_server * server; +struct nfs4_change_info old_cinfo; +struct nfs_fattr * old_fattr; +struct nfs4_change_info new_cinfo; +struct nfs_fattr * new_fattr; +struct nfs4_sequence_res seq_res; +}; +/* * Argument struct for decode_entry function */
@@ -623,11 +632,6 @@ struct nfs3_readlinkargs {struct page ** pages; }; -struct nfs3_renameres { -struct nfs_fattr * fromattr; -struct nfs_fattr * toattr; -}; -struct nfs3_linkres {struct nfs_fattr * dir_attr;struct nfs_fattr * fattr;
@@ -795,15 +799,6 @@ struct nfs4_readlink_res {struct nfs4_sequence_res seq_res; }; -struct nfs4_rename_res { -const struct nfs_server * server; -struct nfs4_change_info old_cinfo; -struct nfs_fattr * old_fattr; -struct nfs4_change_info new_cinfo; -struct nfs_fattr * new_fattr; -struct nfs4_sequence_res seq_res; -}; -#define NFS4_SETCLIENTID_NAMELEN (127)struct nfs4_setclientid {const nfs4_verifier * sc_verifier;
Signature · 1 line
1.7.1
PATCH 5/9 nfs: move nfs_sillyrename to unlink.c
In reply to Jeff Layton...since that's where most of the sillyrenaming code lives. Also, make nfs_async_unlink static as nfs_sillyrename is the only caller.
--- fs/nfs/dir.c | 70 --------------------------------------- fs/nfs/unlink.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++- include/linux/nfs_fs.h | 2 +- 3 files changed, 85 insertions(+), 72 deletions(-)
fs/nfs/dir.c +0 -70
@@ -1351,76 +1351,6 @@ static int nfs_rmdir(struct inode *dir, struct dentry *dentry)return error; } -static int nfs_sillyrename (struct inode *dir,struct dentry *dentry) -{ -static unsigned int sillycounter; -const int fileidsize =sizeof (NFS_FILEID (dentry->d_inode))*2 ; -const int countersize =sizeof (sillycounter)*2 ; -const int slen =sizeof (".nfs" )+fileidsize+countersize-1 ; -char silly[slen+1 ]; -struct qstr qsilly; -struct dentry *sdentry; -int error = -EIO ; - -dfprintk (VFS ,"NFS: silly-rename(%s/%s, ct=%d)\n" , - dentry->d_parent->d_name.name, dentry->d_name.name, -atomic_read (&dentry->d_count)); -nfs_inc_stats (dir,NFSIOS_SILLYRENAME ); - -/* -* We don't allow a dentry to be silly-renamed twice. -*/ - error = -EBUSY ; -if (dentry->d_flags &DCACHE_NFSFS_RENAMED ) - goto out; - -sprintf (silly,".nfs%*.*Lx" , - fileidsize, fileidsize, - (unsigned long long )NFS_FILEID (dentry->d_inode)); - -/* Return delegation in anticipation of the rename */ -nfs_inode_return_delegation (dentry->d_inode); - - sdentry =NULL ; -do { -char *suffix = silly + slen - countersize; - -dput (sdentry); - sillycounter++; -sprintf (suffix,"%*.*x" , countersize, countersize, sillycounter); - -dfprintk (VFS ,"NFS: trying to rename %s to %s\n" , - dentry->d_name.name, silly); - - sdentry =lookup_one_len (silly, dentry->d_parent, slen); -/* -* N.B. Better to return EBUSY here ... it could be -* dangerous to delete the file while it's in use. -*/ -if (IS_ERR (sdentry)) - goto out; - }while (sdentry->d_inode !=NULL );/* need negative lookup */ - - qsilly.name = silly; - qsilly.len =strlen (silly); -if (dentry->d_inode) { - error =NFS_PROTO (dir)->rename (dir, &dentry->d_name, - dir, &qsilly); -nfs_mark_for_revalidate (dentry->d_inode); - }else - error =NFS_PROTO (dir)->rename (dir, &dentry->d_name, - dir, &qsilly); -if (!error) { -nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); -d_move (dentry, sdentry); - error =nfs_async_unlink (dir, dentry); -/* If we return 0 we don't unlink */ - } -dput (sdentry); -out: -return error; -} -/* * Remove a file after making sure there are no pending writes, * and after checking that the file has only one user.
fs/nfs/unlink.c +84 -1
103 lines not on this page · raw message
include/linux/nfs_fs.h +1 -1
@@ -479,10 +479,10 @@ extern void nfs_release_automount_timer(void);/* * linux/fs/nfs/unlink.c */ -extern int nfs_async_unlink (struct inode *dir,struct dentry *dentry);extern void nfs_complete_unlink (struct dentry *dentry,struct inode *);extern void nfs_block_sillyrename (struct dentry *dentry);extern void nfs_unblock_sillyrename (struct dentry *dentry); +extern int nfs_sillyrename (struct inode *dir,struct dentry *dentry);/* * linux/fs/nfs/write.c
Signature · 1 line
1.7.1
PATCH 6/9 nfs: eliminate qsilly var from nfs_sillyrename
In reply to Jeff LaytonThe sdentry should already have the same info in d_name.
--- fs/nfs/unlink.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
fs/nfs/unlink.c +2 -4
@@ -328,7 +328,6 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)const int countersize =sizeof (sillycounter)*2 ;const int slen =sizeof (".nfs" )+fileidsize+countersize-1 ;char silly[slen+1 ]; -struct qstr qsilly;struct dentry *sdentry;int error = -EIO ;
@@ -371,9 +370,8 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry) goto out; }while (sdentry->d_inode !=NULL );/* need negative lookup */ - qsilly.name = silly; - qsilly.len =strlen (silly); - error =NFS_PROTO (dir)->rename (dir, &dentry->d_name, dir, &qsilly); + error =NFS_PROTO (dir)->rename (dir, &dentry->d_name, dir, + &sdentry->d_name);if (dentry->d_inode)nfs_mark_for_revalidate (dentry->d_inode);if (!error) {
Signature · 1 line
1.7.1
PATCH 7/9 nfs: add a rename_setup nfs_rpc_op for async renames
In reply to Jeff LaytonAdd a call that can set up the arguments and the response container for an asynchronous rename call.
--- fs/nfs/nfs3proc.c | 18 ++++++++++++++++++ fs/nfs/nfs4proc.c | 21 +++++++++++++++++++++ fs/nfs/proc.c | 8 ++++++++ include/linux/nfs_xdr.h | 1 + 4 files changed, 48 insertions(+), 0 deletions(-)
fs/nfs/nfs3proc.c +18 -0
@@ -439,6 +439,23 @@ nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir) }static int +nfs3_proc_rename_setup (struct rpc_message *msg,struct inode *dir) +{ +struct nfs_renameres *res = msg->rpc_resp; + + msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME ]; + + res->old_fattr =nfs_alloc_fattr (); + res->new_fattr =nfs_alloc_fattr (); +if (res->old_fattr !=NULL && res->new_fattr !=NULL ) +return 0 ; + +nfs_free_fattr (res->old_fattr); +nfs_free_fattr (res->new_fattr); +return -ENOMEM ; +} + +static int nfs3_proc_rename (struct inode *old_dir,struct qstr *old_name,struct inode *new_dir,struct qstr *new_name) {
@@ -842,6 +859,7 @@ const struct nfs_rpc_ops nfs_v3_clientops = { .unlink_setup = nfs3_proc_unlink_setup, .unlink_done = nfs3_proc_unlink_done, .rename = nfs3_proc_rename, + .rename_setup = nfs3_proc_rename_setup, .link = nfs3_proc_link, .symlink = nfs3_proc_symlink, .mkdir = nfs3_proc_mkdir,
fs/nfs/nfs4proc.c +21 -0
@@ -2671,6 +2671,26 @@ static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)return 1 ; } +static int nfs4_proc_rename_setup (struct rpc_message *msg,struct inode *dir) +{ +struct nfs_server *server =NFS_SERVER (dir); +struct nfs_renameargs *arg = msg->rpc_argp; +struct nfs_renameres *res = msg->rpc_resp; + + msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME ]; + arg->bitmask = server->attr_bitmask; + res->server = server; + + res->old_fattr =nfs_alloc_fattr (); + res->new_fattr =nfs_alloc_fattr (); +if (res->old_fattr !=NULL && res->new_fattr !=NULL ) +return 0 ; + +nfs_free_fattr (res->old_fattr); +nfs_free_fattr (res->new_fattr); +return -ENOMEM ; +} +static int _nfs4_proc_rename (struct inode *old_dir,struct qstr *old_name,struct inode *new_dir,struct qstr *new_name) {
@@ -5443,6 +5463,7 @@ const struct nfs_rpc_ops nfs_v4_clientops = { .unlink_setup = nfs4_proc_unlink_setup, .unlink_done = nfs4_proc_unlink_done, .rename = nfs4_proc_rename, + .rename_setup = nfs4_proc_rename_setup, .link = nfs4_proc_link, .symlink = nfs4_proc_symlink, .mkdir = nfs4_proc_mkdir,
fs/nfs/proc.c +8 -0
@@ -366,6 +366,13 @@ static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) }static int +nfs_proc_rename_setup (struct rpc_message *msg,struct inode *dir) +{ + msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME ]; +return 0 ; +} + +static int nfs_proc_rename (struct inode *old_dir,struct qstr *old_name,struct inode *new_dir,struct qstr *new_name) {
@@ -703,6 +710,7 @@ const struct nfs_rpc_ops nfs_v2_clientops = { .unlink_setup = nfs_proc_unlink_setup, .unlink_done = nfs_proc_unlink_done, .rename = nfs_proc_rename, + .rename_setup = nfs_proc_rename_setup, .link = nfs_proc_link, .symlink = nfs_proc_symlink, .mkdir = nfs_proc_mkdir,
include/linux/nfs_xdr.h +1 -0
@@ -1018,6 +1018,7 @@ struct nfs_rpc_ops {int (*unlink_done) (struct rpc_task *,struct inode *);int (*rename) (struct inode *,struct qstr *,struct inode *,struct qstr *); +int (*rename_setup) (struct rpc_message *msg,struct inode *dir);int (*link) (struct inode *,struct inode *,struct qstr *);int (*symlink) (struct inode *,struct dentry *,struct page *,unsigned int ,struct iattr *);
Signature · 1 line
1.7.1
PATCH 8/9 nfs: add rename_done nfs_rpc_op
In reply to Jeff Layton...for processing the rename reply.
--- fs/nfs/nfs3proc.c | 16 ++++++++++++++++ fs/nfs/nfs4proc.c | 18 ++++++++++++++++++ fs/nfs/proc.c | 12 ++++++++++++ include/linux/nfs_xdr.h | 1 + 4 files changed, 47 insertions(+), 0 deletions(-)
fs/nfs/nfs3proc.c +16 -0
@@ -456,6 +456,21 @@ nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir) }static int +nfs3_proc_rename_done (struct rpc_task *task,struct inode *old_dir, +struct inode *new_dir) +{ +struct nfs_renameres *res; + +if (nfs3_async_handle_jukebox (task, old_dir)) +return 0 ; + res = task->tk_msg.rpc_resp; + +nfs_post_op_update_inode (old_dir, res->old_fattr); +nfs_post_op_update_inode (new_dir, res->new_fattr); +return 1 ; +} + +static int nfs3_proc_rename (struct inode *old_dir,struct qstr *old_name,struct inode *new_dir,struct qstr *new_name) {
@@ -860,6 +875,7 @@ const struct nfs_rpc_ops nfs_v3_clientops = { .unlink_done = nfs3_proc_unlink_done, .rename = nfs3_proc_rename, .rename_setup = nfs3_proc_rename_setup, + .rename_done = nfs3_proc_rename_done, .link = nfs3_proc_link, .symlink = nfs3_proc_symlink, .mkdir = nfs3_proc_mkdir,
fs/nfs/nfs4proc.c +18 -0
@@ -2691,6 +2691,23 @@ static int nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)return -ENOMEM ; } +static int nfs4_proc_rename_done (struct rpc_task *task,struct inode *old_dir, +struct inode *new_dir) +{ +struct nfs_renameres *res = task->tk_msg.rpc_resp; + +if (!nfs4_sequence_done (task, &res->seq_res)) +return 0 ; +if (nfs4_async_handle_error (task, res->server,NULL ) == -EAGAIN ) +return 0 ; + +update_changeattr (old_dir, &res->old_cinfo); +nfs_post_op_update_inode (old_dir, res->old_fattr); +update_changeattr (new_dir, &res->new_cinfo); +nfs_post_op_update_inode (new_dir, res->new_fattr); +return 1 ; +} +static int _nfs4_proc_rename (struct inode *old_dir,struct qstr *old_name,struct inode *new_dir,struct qstr *new_name) {
@@ -5464,6 +5481,7 @@ const struct nfs_rpc_ops nfs_v4_clientops = { .unlink_done = nfs4_proc_unlink_done, .rename = nfs4_proc_rename, .rename_setup = nfs4_proc_rename_setup, + .rename_done = nfs4_proc_rename_done, .link = nfs4_proc_link, .symlink = nfs4_proc_symlink, .mkdir = nfs4_proc_mkdir,
fs/nfs/proc.c +12 -0
@@ -373,6 +373,17 @@ nfs_proc_rename_setup(struct rpc_message *msg, struct inode *dir) }static int +nfs_proc_rename_done (struct rpc_task *task,struct inode *old_dir, +struct inode *new_dir) +{ +if (nfs_async_handle_expired_key (task)) +return 0 ; +nfs_mark_for_revalidate (old_dir); +nfs_mark_for_revalidate (new_dir); +return 1 ; +} + +static int nfs_proc_rename (struct inode *old_dir,struct qstr *old_name,struct inode *new_dir,struct qstr *new_name) {
@@ -711,6 +722,7 @@ const struct nfs_rpc_ops nfs_v2_clientops = { .unlink_done = nfs_proc_unlink_done, .rename = nfs_proc_rename, .rename_setup = nfs_proc_rename_setup, + .rename_done = nfs_proc_rename_done, .link = nfs_proc_link, .symlink = nfs_proc_symlink, .mkdir = nfs_proc_mkdir,
include/linux/nfs_xdr.h +1 -0
@@ -1019,6 +1019,7 @@ struct nfs_rpc_ops {int (*rename) (struct inode *,struct qstr *,struct inode *,struct qstr *);int (*rename_setup) (struct rpc_message *msg,struct inode *dir); +int (*rename_done) (struct rpc_task *task,struct inode *old_dir,struct inode *new_dir);int (*link) (struct inode *,struct inode *,struct qstr *);int (*symlink) (struct inode *,struct dentry *,struct page *,unsigned int ,struct iattr *);
Signature · 1 line
1.7.1
PATCH 9/9 nfs: make sillyrename an async operation
In reply to Jeff LaytonA synchronous rename can be interrupted by a SIGKILL. If that happens during a sillyrename operation, it's possible for the rename call to be sent to the server, but the task exits before processing the reply. If this happens, the sillyrenamed file won't get cleaned up during nfs_dentry_iput and the server is left with a dangling .nfs* file hanging around.
Fix this problem by turning sillyrename into an asynchronous operation and have the task doing the sillyrename just wait on the reply. If the task is killed before the sillyrename completes, it'll still proceed to completion.
--- fs/nfs/unlink.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 182 insertions(+), 9 deletions(-)
fs/nfs/unlink.c +182 -9
@@ -307,6 +307,167 @@ nfs_complete_unlink(struct dentry *dentry, struct inode *inode)nfs_free_unlinkdata (data); } +/* Cancel a queued async unlink. Called when a sillyrename run fails. */ +static void +nfs_cancel_async_unlink (struct dentry *dentry) +{ +spin_lock (&dentry->d_lock); +if (dentry->d_flags &DCACHE_NFSFS_RENAMED ) { + dentry->d_flags &= ~DCACHE_NFSFS_RENAMED ; +nfs_free_unlinkdata (dentry->d_fsdata); + } +spin_unlock (&dentry->d_lock); +} + +struct nfs_renamedata { +struct nfs_renameargs args; +struct nfs_renameres res; +struct rpc_cred * cred; +struct inode * old_dir; +struct inode * new_dir; +struct dentry * old_dentry; +struct dentry * new_dentry; +}; + +/** +* nfs_async_rename_done - Sillyrename post-processing +* @task: rpc_task of the sillyrename +* @calldata: nfs_renamedata for the sillyrename +* +* Do the directory attribute updates and the d_move +*/ +static void nfs_async_rename_done (struct rpc_task *task,void *calldata) +{ +struct nfs_renamedata *data = calldata; +struct inode *old_dir = data->old_dir; +struct inode *new_dir = data->new_dir; + +if (!NFS_PROTO (old_dir)->rename_done (task, old_dir, new_dir)) { +nfs_restart_rpc (task,NFS_SERVER (old_dir)->nfs_client); +return ; + } + +if (task->tk_status !=0 ) +return ; + +nfs_set_verifier (data->old_dentry,nfs_save_change_attribute (old_dir)); +d_move (data->old_dentry, data->new_dentry); +} + +/** +* nfs_async_rename_release - Release the sillyrename data. +* @calldata: the struct nfs_renamedata to be released +* +* We need to call nfs_put_renamedata as a 'tk_release' task since the +* rpc_task would be freed too. +*/ +static void nfs_async_rename_release (void *calldata) +{ +struct nfs_renamedata *data = calldata; +struct super_block *sb = data->old_dir->i_sb; + +/* FIXME: is this OK here? Note that call_done will be done first... */ +if (data->old_dentry->d_inode) +nfs_mark_for_revalidate (data->old_dentry->d_inode); + +kfree (data->res.old_fattr); +kfree (data->res.new_fattr); +dput (data->old_dentry); +dput (data->new_dentry); +iput (data->old_dir); +iput (data->new_dir); +nfs_sb_deactive (sb); +put_rpccred (data->cred); +kfree (data); +} + +#if defined(CONFIG_NFS_V4_1 ) +static void nfs_rename_prepare (struct rpc_task *task,void *calldata) +{ +struct nfs_renamedata *data = calldata; +struct nfs_server *server =NFS_SERVER (data->old_dir); + +if (nfs4_setup_sequence (server, &data->args.seq_args, + &data->res.seq_res,1 , task)) +return ; +rpc_call_start (task); +} +#endif /* CONFIG_NFS_V4_1 */ + +static const struct rpc_call_ops nfs_rename_ops = { + .rpc_call_done = nfs_async_rename_done, + .rpc_release = nfs_async_rename_release, +#if defined(CONFIG_NFS_V4_1) + .rpc_call_prepare = nfs_rename_prepare, +#endif /* CONFIG_NFS_V4_1 */ +}; + +/** +* nfs_async_rename - perform an asynchronous rename operation +* @old_dir: directory that currently holds the dentry to be renamed +* @new_dir: target directory for the rename +* @old_dentry: original dentry to be renamed +* @new_dentry: dentry to which the old_dentry should be renamed +*/ +static struct rpc_task * +nfs_async_rename (struct inode *old_dir,struct inode *new_dir, +struct dentry *old_dentry,struct dentry *new_dentry) +{ +int error; +struct nfs_renamedata *data; +struct rpc_message msg = { }; +struct rpc_task_setup task_setup_data = { + .rpc_message = &msg, + .callback_ops = &nfs_rename_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +struct rpc_task *task; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (data ==NULL ) +return ERR_PTR (-ENOMEM ); + task_setup_data.callback_data = data, + + data->cred =rpc_lookup_cred (); +if (IS_ERR (data->cred)) { +kfree (data); +return (struct rpc_task *)data->cred; + } + msg.rpc_argp = &data->args, + msg.rpc_resp = &data->res, + msg.rpc_cred = data->cred; + +/* set up nfs_renamedata */ + data->old_dir = old_dir; +atomic_inc (&old_dir->i_count); + data->new_dir = new_dir; +atomic_inc (&new_dir->i_count); + data->old_dentry =dget (old_dentry); + data->new_dentry =dget (new_dentry); + +/* set up nfs_renameargs */ + data->args.old_dir =NFS_FH (old_dir); + data->args.old_name = &old_dentry->d_name; + data->args.new_dir =NFS_FH (new_dir); + data->args.new_name = &new_dentry->d_name; + +nfs_sb_active (old_dir->i_sb); + + error =NFS_PROTO (data->old_dir)->rename_setup (&msg, old_dir); +if (error) { +nfs_async_rename_release (data); +return ERR_PTR (error); + } + + task_setup_data.rpc_client =NFS_CLIENT (old_dir); + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) +nfs_async_rename_release (data); + +return task; +} +/** * nfs_sillyrename - Perform a silly-rename of a dentry * @dir: inode of directory that contains dentry
@@ -329,6 +490,7 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)const int slen =sizeof (".nfs" )+fileidsize+countersize-1 ;char silly[slen+1 ];struct dentry *sdentry; +struct rpc_task *task;int error = -EIO ; dfprintk(VFS, "NFS: silly-rename(%s/%s, ct=%d)\n",
@@ -370,16 +532,27 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry) goto out; }while (sdentry->d_inode !=NULL );/* need negative lookup */ - error =NFS_PROTO (dir)->rename (dir, &dentry->d_name, dir, - &sdentry->d_name); -if (dentry->d_inode) -nfs_mark_for_revalidate (dentry->d_inode); -if (!error) { -nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); -d_move (dentry, sdentry); - error =nfs_async_unlink (dir, dentry); -/* If we return 0 we don't unlink */ +/* queue unlink first. Can't do this from rpc_release as it +* has to allocate memory +*/ + error =nfs_async_unlink (dir, dentry); +if (error) + goto out_dput; + +/* run the rename task, undo unlink if it fails */ + task =nfs_async_rename (dir, dir, dentry, sdentry); +if (IS_ERR (task)) { + error = -EBUSY ; +nfs_cancel_async_unlink (dentry); + goto out_dput; } + +/* wait for the RPC task to complete, unless a SIGKILL intervenes */ + error =rpc_wait_for_completion_task (task); +if (error ==0 ) + error = task->tk_status; +rpc_put_task (task); +out_dput:dput (sdentry); out:return error;
Signature · 1 line
1.7.1