cifs: clean up cifs_unlink and fix silly-renames (try #2)
cover cifs: clean up cifs_unlink and fix silly-renames (try #2)
This is try #2 of the patchset to clean up cifs_unlink and fix up the silly-rename scheme. The main difference between this one and the original patchset is the renaming of some variables in cifs_unlink to more closely match generic VFS code and kernel coding style. It also fixes a bug -- misspelled flag name in the open flags in the third patch.
This patchset is a cleanup of the cifs_unlink() code. It moves most of the "silly-rename" logic into a helper function and has cifs_unlink call it. It also fixes the silly-rename logic, which didn't work quite right in some cases and also adds a new function to properly set the DELETE_ON_CLOSE bit on files that already exist. With this patchset, CIFS VFS can now pass the op_chmod test in the Connectathon test suite when tested against a win2k3 server.
The patchset is a little larger than the resulting code. I attempted to preserve bisectability with it, so I suggest applying them in order. If everything looks OK, this patchset is probably appropriate for 2.6.28.
Jeff Layton (4):
cifs: clean up variables in cifs_unlink
cifs: use common code for turning off ATTR_READONLY in cifs_unlink
cifs: move silly-rename logic into helper function
cifs: add function to set file disposition
fs/cifs/cifsfs.h | 2 +- fs/cifs/cifsproto.h | 2 + fs/cifs/cifssmb.c | 55 ++++++++++++ fs/cifs/inode.c | 235 ++++++++++++++++++++++++-------------------------- 4 files changed, 171 insertions(+), 123 deletions(-)
PATCH 1/4 cifs: clean up variables in cifs_unlink
Change parameters to cifs_unlink to match the ones used in the generic VFS. Add some local variables to cut down on the amount of struct dereferencing that needs to be done, and eliminate some unneeded NULL pointer checks on the parent directory inode. Finally, rename pTcon to "tcon" to more closely match standard kernel coding style.
--- fs/cifs/cifsfs.h | 2 +- fs/cifs/inode.c | 90 ++++++++++++++++++++++++----------------------------- 2 files changed, 42 insertions(+), 50 deletions(-)
fs/cifs/cifsfs.h +1 -1
@@ -41,7 +41,7 @@ extern int cifs_create(struct inode *, struct dentry *, int, struct nameidata *);extern struct dentry *cifs_lookup (struct inode *,struct dentry *,struct nameidata *); -extern int cifs_unlink (struct inode *,struct dentry *); +extern int cifs_unlink (struct inode *dir,struct dentry *dentry);extern int cifs_hardlink (struct dentry *,struct inode *,struct dentry *);extern int cifs_mknod (struct inode *,struct dentry *,int ,dev_t );extern int cifs_mkdir (struct inode *,struct dentry *,int );
fs/cifs/inode.c +41 -49
192 lines not on this page · raw message
Signature · 1 line
1.5.5.1
PATCH 2/4 cifs: use common code for turning off ATTR_READONLY in cifs_unlink
In reply to Jeff LaytonWe already have a cifs_set_file_info function that can flip DOS attribute bits. Have cifs_unlink call it to handle turning ATTR_HIDDEN on and ATTR_READONLY off when an unlink attempt returns -EACCES.
This also removes a level of indentation from cifs_unlink.
--- fs/cifs/inode.c | 118 +++++++++++++++++++++--------------------------------- 1 files changed, 46 insertions(+), 72 deletions(-)
fs/cifs/inode.c +46 -72
@@ -29,6 +29,8 @@#include "cifs_debug.h" #include "cifs_fs_sb.h" +static int cifs_set_file_info (struct inode *inode,struct iattr *attrs, +int xid,char *full_path,__u32 dosattr);static void cifs_set_ops (struct inode *inode,const bool is_dfs_referral) {
@@ -675,7 +677,8 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)struct super_block *sb = dir->i_sb;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifsTconInfo *tcon = cifs_sb->tcon; -FILE_BASIC_INFO *pinfo_buf; +struct iattr *attrs; +__u32 dosattr;cFYI (1 , ("cifs_unlink, dir=0x%p, dentry=0x%p" , dir, dentry));
@@ -728,84 +731,55 @@ psx_del_no_retry: } }else if (rc == -EACCES ) {/* try only if r/o attribute set in local lookup data? */ - pinfo_buf =kzalloc (sizeof (FILE_BASIC_INFO ),GFP_KERNEL ); -if (pinfo_buf) { -/* ATTRS set to normal clears r/o bit */ - pinfo_buf->Attributes =cpu_to_le32 (ATTR_NORMAL ); -if (!(tcon->ses->flags &CIFS_SES_NT4 )) - rc =CIFSSMBSetPathInfo (xid, tcon, full_path, - pinfo_buf, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -else - rc = -EOPNOTSUPP ; - -if (rc == -EOPNOTSUPP ) { -int oplock =0 ; -__u16 netfid; -/* rc = CIFSSMBSetAttrLegacy(xid, tcon, -full_path, -(__u16)ATTR_NORMAL, -cifs_sb->local_nls); -For some strange reason it seems that NT4 eats the -old setattr call without actually setting the -attributes so on to the third attempted workaround -*/ - -/* BB could scan to see if we already have it open -and pass in pid of opener to function */ - rc =CIFSSMBOpen (xid, tcon, full_path, -FILE_OPEN ,SYNCHRONIZE | -FILE_WRITE_ATTRIBUTES ,0 , - &netfid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (rc ==0 ) { - rc =CIFSSMBSetFileInfo (xid, tcon, - pinfo_buf, - netfid, - current->tgid); -CIFSSMBClose (xid, tcon, netfid); - } - } -kfree (pinfo_buf); + attrs =kzalloc (sizeof (*attrs),GFP_KERNEL ); +if (attrs ==NULL ) { + rc = -ENOMEM ; + goto out_reval; } + +/* try to reset dos attributes */ + cifsInode =CIFS_I (inode); + dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY ; +if (dosattr ==0 ) + dosattr |=ATTR_NORMAL ; + dosattr |=ATTR_HIDDEN ; + + rc =cifs_set_file_info (inode, attrs, xid, full_path, dosattr); +kfree (attrs); +if (rc !=0 ) + goto out_reval; + rc =CIFSSMBDelFile (xid, tcon, full_path, cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR );if (rc ==0 ) { - rc =CIFSSMBDelFile (xid, tcon, full_path, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (!rc) { +if (inode) +drop_nlink (inode); + }else if (rc == -ETXTBSY ) { +int oplock =0 ; +__u16 netfid; + + rc =CIFSSMBOpen (xid, tcon, full_path, +FILE_OPEN ,DELETE , +CREATE_NOT_DIR | +CREATE_DELETE_ON_CLOSE , + &netfid, &oplock,NULL , + cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc ==0 ) { +CIFSSMBRenameOpenFile (xid, tcon, + netfid,NULL , + cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +CIFSSMBClose (xid, tcon, netfid);if (inode)drop_nlink (inode); - }else if (rc == -ETXTBSY ) { -int oplock =0 ; -__u16 netfid; - - rc =CIFSSMBOpen (xid, tcon, full_path, -FILE_OPEN ,DELETE , -CREATE_NOT_DIR | -CREATE_DELETE_ON_CLOSE , - &netfid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (rc ==0 ) { -CIFSSMBRenameOpenFile (xid, tcon, - netfid,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -CIFSSMBClose (xid, tcon, netfid); -if (inode) -drop_nlink (inode); - } -/* BB if rc = -ETXTBUSY goto the rename logic BB */ } +/* BB if rc = -ETXTBUSY goto the rename logic BB */ } } +out_reval:if (inode) { cifsInode =CIFS_I (inode); cifsInode->time =0 ;/* will force revalidate to get info
Signature · 1 line
1.5.5.1
Re: [PATCH 2/4] cifs: use common code for turning off ATTR_READONLY in cifs_unlink
I will commit the patch to the cifs git development tree but wanted to consider things:
1) your patch changes from open with FILE_WRITE_ATTRIBUTES to open with GENERIC_WRITE by calling cifs_set_file_info
2) we should probably do the Open then RenameOpenFile whether or not the cifs_set_file_info fails
3) to remove the extern for a static in the c file, the function cifs_set_file_info should be moved forward in the file
Quoted 181 lines · Jeff Layton
We already have a
cifs_set_file_infofunction that can flip DOS attribute bits. Havecifs_unlinkcall it to handle turningATTR_HIDDENon andATTR_READONLYoff when an unlink attempt returns-EACCES.This also removes a level of indentation from
cifs_unlink.Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/inode.c | 118 +++++++++++++++++++++--------------------------------- 1 files changed, 46 insertions(+), 72 deletions(-)fs/cifs/inode.c +4
-22@@ -29,6 +29,8 @@#include "cifs_debug.h" #include "cifs_fs_sb.h" +static int cifs_set_file_info (struct inode *inode,struct iattr *attrs, +int xid,char *full_path,__u32 dosattr);static void cifs_set_ops (struct inode *inode,const bool is_dfs_referral) {@@ -675,7 +677,8 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)struct super_block *sb = dir->i_sb;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifsTconInfo *tcon = cifs_sb->tcon; -FILE_BASIC_INFO *pinfo_buf; +struct iattr *attrs; +__u32 dosattr;cFYI (1 , ("cifs_unlink, dir=0x%p, dentry=0x%p" , dir, dentry));@@ -728,84 +731,55 @@ psx_del_no_retry: } }else if (rc == -EACCES ) {/* try only if r/o attribute set in local lookup data? */ - pinfo_buf =kzalloc (sizeof (FILE_BASIC_INFO ),GFP_KERNEL ); -if (pinfo_buf) { -/* ATTRS set to normal clears r/o bit */ - pinfo_buf->Attributes =cpu_to_le32 (ATTR_NORMAL ); -if (!(tcon->ses->flags &CIFS_SES_NT4 )) - rc =CIFSSMBSetPathInfo (xid, tcon, full_path, - pinfo_buf, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); -else - rc = -EOPNOTSUPP ; - -if (rc == -EOPNOTSUPP ) { -int oplock =0 ; -__u16 netfid; -/* rc = CIFSSMBSetAttrLegacy(xid, tcon, -full_path, - (__u16 )ATTR_NORMAL , - cifs_sb->local_nls); -For some strange reason it seems that NT4 eats the
fs/cifs/inode.c +0
-2- old setattr call without actually setting the - attributes so on to the third attemptedworkaround
fs/cifs/inode.c +0
-11-*/ - -/* BB could scan to see if we already have it open -and pass in pid of opener to function */ - rc = CIFSSMBOpen(xid, tcon, full_path, - FILE_OPEN, SYNCHRONIZE | - FILE_WRITE_ATTRIBUTES, 0, - &netfid, &oplock, NULL, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -
CIFS_MOUNT_MAP_SPECIAL_CHR);fs/cifs/inode.c +0
-5-if (rc ==0 ) { - rc = CIFSSMBSetFileInfo(xid, tcon, - pinfo_buf, - netfid, -
current->tgid);fs/cifs/inode.c +13
-4-CIFSSMBClose (xid, tcon, netfid); - } - } -kfree (pinfo_buf); + attrs =kzalloc (sizeof (*attrs),GFP_KERNEL ); +if (attrs ==NULL ) { + rc = -ENOMEM ; + goto out_reval; } + +/* try to reset dos attributes */ + cifsInode =CIFS_I (inode); + dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY ; +if (dosattr ==0 ) + dosattr |=ATTR_NORMAL ; + dosattr |=ATTR_HIDDEN ; + + rc = cifs_set_file_info(inode, attrs, xid, full_path,dosattr);
fs/cifs/inode.c +4
-0+kfree (attrs); +if (rc !=0 ) + goto out_reval; + rc = CIFSSMBDelFile(xid, tcon, full_path,
cifs_sb->local_nls,fs/cifs/inode.c +2
-4+ cifs_sb->mnt_cifs_flags & + CIFS_MOUNT_MAP_SPECIAL_CHR);if (rc ==0 ) { - rc = CIFSSMBDelFile(xid, tcon, full_path, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -
CIFS_MOUNT_MAP_SPECIAL_CHR);fs/cifs/inode.c +21
-13-if (!rc) { +if (inode) +drop_nlink (inode); + }else if (rc == -ETXTBSY ) { +int oplock =0 ; +__u16 netfid; + + rc =CIFSSMBOpen (xid, tcon, full_path, +FILE_OPEN ,DELETE , +CREATE_NOT_DIR | +CREATE_DELETE_ON_CLOSE , + &netfid, &oplock,NULL , + cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc ==0 ) { +CIFSSMBRenameOpenFile (xid, tcon, + netfid,NULL , + cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +CIFSSMBClose (xid, tcon, netfid);if (inode)drop_nlink (inode); - }else if (rc == -ETXTBSY ) { -int oplock =0 ; -__u16 netfid; - - rc = CIFSSMBOpen(xid, tcon, full_path, - FILE_OPEN, DELETE, - CREATE_NOT_DIR | - CREATE_DELETE_ON_CLOSE, - &netfid, &oplock, NULL, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -
CIFS_MOUNT_MAP_SPECIAL_CHR);fs/cifs/inode.c +0
-6-if (rc ==0 ) { - CIFSSMBRenameOpenFile(xid, tcon, - netfid, NULL, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -
CIFS_MOUNT_MAP_SPECIAL_CHR);fs/cifs/inode.c +2
-6-CIFSSMBClose (xid, tcon, netfid); -if (inode) -drop_nlink (inode); - } -/* BB if rc = -ETXTBUSY goto the rename logic BB */ } +/* BB if rc = -ETXTBUSY goto the rename logic BB */ } } +out_reval:if (inode) { cifsInode =CIFS_I (inode); cifsInode->time =0 ;/* will force revalidate to get info -- 1.5.5.1
Signature · 3 lines
Thanks, Steve
_______________________________________________
linux-cifs-client mailing list
[email protected]
https://lists.samba.org/mailman/listinfo/linux-cifs-client
Re: [PATCH 2/4] cifs: use common code for turning off ATTR_READONLY in cifs_unlink
I will commit the patch to the cifs git development tree but wanted to consider things:
1) your patch changes from open with FILE_WRITE_ATTRIBUTES to open with GENERIC_WRITE by calling cifs_set_file_info
2) we should probably do the Open then RenameOpenFile whether or not the cifs_set_file_info fails
3) to remove the extern for a static in the c file, the function cifs_set_file_info should be moved forward in the file
Quoted 179 lines · Steve French
I will commit the patch to the cifs git development tree but wanted to consider things:
1) your patch changes from open with
FILE_WRITE_ATTRIBUTESto open withGENERIC_WRITEby callingcifs_set_file_info
2) we should probably do the Open then RenameOpenFile whether or not thecifs_set_file_infofails
3) to remove the extern for a static in the c file, the functioncifs_set_file_infoshould be moved forward in the fileQuoted 163 lines · Jeff Layton
We already have a
cifs_set_file_infofunction that can flip DOS attribute bits. Havecifs_unlinkcall it to handle turningATTR_HIDDENon andATTR_READONLYoff when an unlink attempt returns-EACCES.This also removes a level of indentation from
cifs_unlink.Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/inode.c | 118 +++++++++++++++++++++--------------------------------- 1 files changed, 46 insertions(+), 72 deletions(-)fs/cifs/inode.c +46
-73@@ -29,6 +29,8 @@#include "cifs_debug.h" #include "cifs_fs_sb.h" +static int cifs_set_file_info (struct inode *inode,struct iattr *attrs, +int xid,char *full_path,__u32 dosattr);static void cifs_set_ops (struct inode *inode,const bool is_dfs_referral) {@@ -675,7 +677,8 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)struct super_block *sb = dir->i_sb;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifsTconInfo *tcon = cifs_sb->tcon; -FILE_BASIC_INFO *pinfo_buf; +struct iattr *attrs; +__u32 dosattr;cFYI (1 , ("cifs_unlink, dir=0x%p, dentry=0x%p" , dir, dentry));@@ -728,84 +731,55 @@ psx_del_no_retry: } }else if (rc == -EACCES ) {/* try only if r/o attribute set in local lookup data? */ - pinfo_buf =kzalloc (sizeof (FILE_BASIC_INFO ),GFP_KERNEL ); -if (pinfo_buf) { -/* ATTRS set to normal clears r/o bit */ - pinfo_buf->Attributes =cpu_to_le32 (ATTR_NORMAL ); -if (!(tcon->ses->flags &CIFS_SES_NT4 )) - rc =CIFSSMBSetPathInfo (xid, tcon, full_path, - pinfo_buf, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -else - rc = -EOPNOTSUPP ; - -if (rc == -EOPNOTSUPP ) { -int oplock =0 ; -__u16 netfid; -/* rc = CIFSSMBSetAttrLegacy(xid, tcon, -full_path, -(__u16)ATTR_NORMAL, -cifs_sb->local_nls); -For some strange reason it seems that NT4 eats the -old setattr call without actually setting the -attributes so on to the third attempted workaround -*/ - -/* BB could scan to see if we already have it open -and pass in pid of opener to function */ - rc =CIFSSMBOpen (xid, tcon, full_path, -FILE_OPEN ,SYNCHRONIZE | -FILE_WRITE_ATTRIBUTES ,0 , - &netfid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (rc ==0 ) { - rc =CIFSSMBSetFileInfo (xid, tcon, - pinfo_buf, - netfid, - current->tgid); -CIFSSMBClose (xid, tcon, netfid); - } - } -kfree (pinfo_buf); + attrs =kzalloc (sizeof (*attrs),GFP_KERNEL ); +if (attrs ==NULL ) { + rc = -ENOMEM ; + goto out_reval; } + +/* try to reset dos attributes */ + cifsInode =CIFS_I (inode); + dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY ; +if (dosattr ==0 ) + dosattr |=ATTR_NORMAL ; + dosattr |=ATTR_HIDDEN ; + + rc =cifs_set_file_info (inode, attrs, xid, full_path, dosattr); +kfree (attrs); +if (rc !=0 ) + goto out_reval; + rc =CIFSSMBDelFile (xid, tcon, full_path, cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR );if (rc ==0 ) { - rc =CIFSSMBDelFile (xid, tcon, full_path, - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (!rc) { +if (inode) +drop_nlink (inode); + }else if (rc == -ETXTBSY ) { +int oplock =0 ; +__u16 netfid; + + rc =CIFSSMBOpen (xid, tcon, full_path, +FILE_OPEN ,DELETE , +CREATE_NOT_DIR | +CREATE_DELETE_ON_CLOSE , + &netfid, &oplock,NULL , + cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc ==0 ) { +CIFSSMBRenameOpenFile (xid, tcon, + netfid,NULL , + cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +CIFSSMBClose (xid, tcon, netfid);if (inode)drop_nlink (inode); - }else if (rc == -ETXTBSY ) { -int oplock =0 ; -__u16 netfid; - - rc =CIFSSMBOpen (xid, tcon, full_path, -FILE_OPEN ,DELETE , -CREATE_NOT_DIR | -CREATE_DELETE_ON_CLOSE , - &netfid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (rc ==0 ) { -CIFSSMBRenameOpenFile (xid, tcon, - netfid,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -CIFSSMBClose (xid, tcon, netfid); -if (inode) -drop_nlink (inode); - } -/* BB if rc = -ETXTBUSY goto the rename logic BB */ } +/* BB if rc = -ETXTBUSY goto the rename logic BB */ } } +out_reval:if (inode) { cifsInode =CIFS_I (inode); cifsInode->time =0 ;/* will force revalidate to get info -- Quoted 2 lines
1.5.5.1
--
Thanks,
Quoted 1 line
Steve
--
Thanks,
Steve
Re: [PATCH 2/4] cifs: use common code for turning off ATTR_READONLY in cifs_unlink
In reply to Steve FrenchQuoted 5 lines · On Tue, 16 Sep 2008 18:35:58 -0500 "Steve French" <[email protected]> wrote:
I will commit the patch to the cifs git development tree but wanted to consider things:
1) your patch changes from open with
FILE_WRITE_ATTRIBUTESto open withGENERIC_WRITEby callingcifs_set_file_info
Ahh ok. Just got the other mail. Yes, we could end up using a superset of FILE_WRITE_ATTRIBUTES if we already have an open fh we can use. I'm assuming that's OK (and preferred), but we could change it if we think it would be a problem.
Quoted 2 lines
2) we should probably do the Open then RenameOpenFile whether or not the
cifs_set_file_infofails
You mean that we should go ahead and do the silly_rename logic if the first CIFSSMBDelOpenFile call returns -ETXTBSY or -EACCES? That's probably reasonable and more efficient overall. It'll also mean less complex logic too. I like this idea.
Quoted 3 lines
3) to remove the extern for a static in the c file, the function
cifs_set_file_infoshould be moved forward in the file
No objection here. I'll look at doing that.
Good observations all around. There's no huge hurry here, so let me code up a respun set with some of these changes before you commit the last 3. We might as well get it right the first time...
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 2/4] cifs: use common code for turning off ATTR_READONLY in cifs_unlink
Quoted 5 lines · Jeff Layton
Quoted 3 lines
3) to remove the extern for a static in the c file, the function
cifs_set_file_infoshould be moved forward in the fileNo objection here. I'll look at doing that.
I changed that and merged it.into the cifs tree.
Quoted 7 lines
Good observations all around. There's no huge hurry here, so let me code up a respun set with some of these changes before you commit the last 3. We might as well get it right the first time...
--
Jeff Layton <[email protected]>
Signature · 3 lines
Thanks, Steve
PATCH 3/4 cifs: move silly-rename logic into helper function
In reply to Jeff LaytonWhen a file is still open on the server, we attempt to set the DELETE_ON_CLOSE bit and rename it to a new filename. When the last opener closes the file, the server should delete it.
This patch moves this mechanism into a helper function and has the two places in cifs_unlink that do silly-renames call it. It also fixes the open flags to be correct.
--- fs/cifs/inode.c | 98 +++++++++++++++++++++++++++++++++---------------------- 1 files changed, 59 insertions(+), 39 deletions(-)
fs/cifs/inode.c +59 -39
@@ -667,6 +667,59 @@ struct inode *cifs_iget(struct super_block *sb, unsigned long ino)return inode; } +/* +* open the given file (if it isn't already), set the DELETE_ON_CLOSE bit +* and rename it to a random name that hopefully won't conflict with +* anything else. +*/ +static int +cifs_silly_rename (char *full_path,struct inode *inode,int xid) +{ +int oplock =0 ; +int rc; +__u16 netfid; +struct cifsInodeInfo *cifsInode =CIFS_I (inode); +struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb); +struct cifsTconInfo *tcon = cifs_sb->tcon; +__u32 dosattr; +FILE_BASIC_INFO *info_buf; + + rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , +DELETE |FILE_WRITE_ATTRIBUTES , +CREATE_NOT_DIR |CREATE_DELETE_ON_CLOSE , + &netfid, &oplock,NULL , cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc !=0 ) + goto out; + +/* set ATTR_HIDDEN and clear ATTR_READONLY */ + cifsInode =CIFS_I (inode); + dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY ; +if (dosattr ==0 ) + dosattr |=ATTR_NORMAL ; + dosattr |=ATTR_HIDDEN ; + + info_buf =kzalloc (sizeof (*info_buf),GFP_KERNEL ); +if (info_buf ==NULL ) { + rc = -ENOMEM ; + goto out_close; + } + info_buf->Attributes =cpu_to_le32 (dosattr); + rc =CIFSSMBSetFileInfo (xid, tcon, info_buf, netfid, current->tgid); +kfree (info_buf); +if (rc !=0 ) + goto out_close; + +/* silly-rename the file */ + rc =CIFSSMBRenameOpenFile (xid, tcon, netfid,NULL , cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & +CIFS_MOUNT_MAP_SPECIAL_CHR ); +out_close: +CIFSSMBClose (xid, tcon, netfid); +out: +return rc; +} +int cifs_unlink (struct inode *dir,struct dentry *dentry) {int rc =0 ;
@@ -712,23 +765,9 @@ psx_del_no_retry: }else if (rc == -ENOENT ) {d_drop (dentry); }else if (rc == -ETXTBSY ) { -int oplock =0 ; -__u16 netfid; - - rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN ,DELETE , -CREATE_NOT_DIR |CREATE_DELETE_ON_CLOSE , - &netfid, &oplock,NULL , cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (rc ==0 ) { -CIFSSMBRenameOpenFile (xid, tcon, netfid,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -CIFSSMBClose (xid, tcon, netfid); -if (inode) -drop_nlink (inode); - } + rc =cifs_silly_rename (full_path, inode, xid); +if (rc ==0 ) +drop_nlink (inode); }else if (rc == -EACCES ) {/* try only if r/o attribute set in local lookup data? */ attrs =kzalloc (sizeof (*attrs),GFP_KERNEL );
@@ -755,28 +794,9 @@ psx_del_no_retry:if (inode)drop_nlink (inode); }else if (rc == -ETXTBSY ) { -int oplock =0 ; -__u16 netfid; - - rc =CIFSSMBOpen (xid, tcon, full_path, -FILE_OPEN ,DELETE , -CREATE_NOT_DIR | -CREATE_DELETE_ON_CLOSE , - &netfid, &oplock,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -if (rc ==0 ) { -CIFSSMBRenameOpenFile (xid, tcon, - netfid,NULL , - cifs_sb->local_nls, - cifs_sb->mnt_cifs_flags & -CIFS_MOUNT_MAP_SPECIAL_CHR ); -CIFSSMBClose (xid, tcon, netfid); -if (inode) -drop_nlink (inode); - } -/* BB if rc = -ETXTBUSY goto the rename logic BB */ + rc =cifs_silly_rename (full_path, inode, xid); +if (rc ==0 ) +drop_nlink (inode); } } out_reval:
Signature · 1 line
1.5.5.1
PATCH 4/4 cifs: add function to set file disposition
In reply to Jeff LaytonThe proper way to set the delete on close bit on an already existing file is to use SET_FILE_INFO with an infolevel of SMB_FILE_DISPOSITION_INFO. Add a function to do that and have the silly-rename code use it.
--- fs/cifs/cifsproto.h | 2 + fs/cifs/cifssmb.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/inode.c | 9 ++++++- 3 files changed, 64 insertions(+), 2 deletions(-)
fs/cifs/cifsproto.h +2 -0
@@ -179,6 +179,8 @@ extern int CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon,extern int CIFSSMBSetFileInfo (const int xid,struct cifsTconInfo *tcon,const FILE_BASIC_INFO *data,__u16 fid,__u32 pid_of_opener); +extern int CIFSSMBSetFileDisposition (const int xid,struct cifsTconInfo *tcon, +bool delete_file,__u16 fid,__u32 pid_of_opener);#if 0 extern int CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, __u16 dos_attributes,
fs/cifs/cifssmb.c +55 -0
61 lines not on this page · raw message
fs/cifs/inode.c +7 -2
@@ -685,8 +685,7 @@ cifs_silly_rename(char *full_path, struct inode *inode, int xid)FILE_BASIC_INFO *info_buf; rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , -DELETE |FILE_WRITE_ATTRIBUTES , -CREATE_NOT_DIR |CREATE_DELETE_ON_CLOSE , +DELETE |FILE_WRITE_ATTRIBUTES ,CREATE_NOT_DIR , &netfid, &oplock,NULL , cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR );if (rc !=0 )
@@ -714,6 +713,12 @@ cifs_silly_rename(char *full_path, struct inode *inode, int xid) rc =CIFSSMBRenameOpenFile (xid, tcon, netfid,NULL , cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc !=0 ) + goto out_close; + +/* set DELETE_ON_CLOSE */ + rc =CIFSSMBSetFileDisposition (xid, tcon, true, netfid, current->tgid); + out_close:CIFSSMBClose (xid, tcon, netfid); out:
Signature · 1 line
1.5.5.1
Re: [PATCH 4/4] cifs: add function to set file disposition
Does this work with NT4?
Quoted 122 lines · Jeff Layton
The proper way to set the delete on close bit on an already existing file is to use
SET_FILE_INFOwith an infolevel ofSMB_FILE_DISPOSITION_INFO. Add a function to do that and have the silly-rename code use it.Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsproto.h | 2 + fs/cifs/cifssmb.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/inode.c | 9 ++++++- 3 files changed, 64 insertions(+), 2 deletions(-)fs/cifs/cifsproto.h +2
-0@@ -179,6 +179,8 @@ extern int CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon,extern int CIFSSMBSetFileInfo (const int xid,struct cifsTconInfo *tcon,const FILE_BASIC_INFO *data,__u16 fid,__u32 pid_of_opener); +extern int CIFSSMBSetFileDisposition (const int xid,struct cifsTconInfo *tcon, +bool delete_file,__u16 fid,__u32 pid_of_opener);#if 0 extern int CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, __u16 dos_attributes,fs/cifs/cifssmb.c +55
-0@@ -4876,6 +4876,61 @@ CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon,return rc; } +int +CIFSSMBSetFileDisposition (const int xid,struct cifsTconInfo *tcon, +bool delete_file,__u16 fid,__u32 pid_of_opener) +{ +struct smb_com_transaction2_sfi_req *pSMB =NULL ; +char *data_offset; +int rc =0 ; +__u16 params, param_offset, offset, byte_count, count; + +cFYI (1 , ("Set File Disposition (via SetFileInfo)" )); + rc =small_smb_init (SMB_COM_TRANSACTION2 ,15 , tcon, (void **) &pSMB); + +if (rc) +return rc; + + pSMB->hdr.Pid =cpu_to_le16 ((__u16 )pid_of_opener); + pSMB->hdr.PidHigh =cpu_to_le16 ((__u16)(pid_of_opener >>16 )); + + params =6 ; + pSMB->MaxSetupCount =0 ; + pSMB->Reserved =0 ; + pSMB->Flags =0 ; + pSMB->Timeout =0 ; + pSMB->Reserved2 =0 ; + param_offset = offsetof(struct smb_com_transaction2_sfi_req , Fid) -4 ; + offset = param_offset + params; + + data_offset = (char *) (&pSMB->hdr.Protocol) + offset; + + count =1 ; + pSMB->MaxParameterCount =cpu_to_le16 (2 ); +/* BB find max SMB PDU from sess */ + pSMB->MaxDataCount =cpu_to_le16 (1000 ); + pSMB->SetupCount =1 ; + pSMB->Reserved3 =0 ; + pSMB->SubCommand =cpu_to_le16 (TRANS2_SET_FILE_INFORMATION ); + byte_count =3 /* pad */ + params + count; + pSMB->DataCount =cpu_to_le16 (count); + pSMB->ParameterCount =cpu_to_le16 (params); + pSMB->TotalDataCount = pSMB->DataCount; + pSMB->TotalParameterCount = pSMB->ParameterCount; + pSMB->ParameterOffset =cpu_to_le16 (param_offset); + pSMB->DataOffset =cpu_to_le16 (offset); + pSMB->Fid = fid; + pSMB->InformationLevel =cpu_to_le16 (SMB_SET_FILE_DISPOSITION_INFO ); + pSMB->Reserved4 =0 ; + pSMB->hdr.smb_buf_length += byte_count; + pSMB->ByteCount =cpu_to_le16 (byte_count); + *data_offset = delete_file ?1 :0 ; + rc =SendReceiveNoRsp (xid, tcon->ses, (struct smb_hdr *) pSMB,0 ); +if (rc) +cFYI (1 , ("Send error in SetFileDisposition = %d" , rc)); + +return rc; +} int CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon,fs/cifs/inode.c +7
-3@@ -685,8 +685,7 @@ cifs_silly_rename(char *full_path, struct inode *inode, int xid)FILE_BASIC_INFO *info_buf; rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , -DELETE |FILE_WRITE_ATTRIBUTES , -CREATE_NOT_DIR |CREATE_DELETE_ON_CLOSE , +DELETE |FILE_WRITE_ATTRIBUTES ,CREATE_NOT_DIR , &netfid, &oplock,NULL , cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR );if (rc !=0 )@@ -714,6 +713,12 @@ cifs_silly_rename(char *full_path, struct inode *inode, int xid) rc =CIFSSMBRenameOpenFile (xid, tcon, netfid,NULL , cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc !=0 ) + goto out_close; + +/* set DELETE_ON_CLOSE */ + rc =CIFSSMBSetFileDisposition (xid, tcon, true, netfid, current->tgid); + out_close:CIFSSMBClose (xid, tcon, netfid); out: --1.5.5.1
Signature · 3 lines
Thanks, Steve
Re: [linux-cifs-client] Re: [PATCH 4/4] cifs: add function to set file disposition
Quoted 2 lines · On Tue, 16 Sep 2008 20:33:49 -0500 "Steve French" <[email protected]> wrote:
Does this work with NT4?
Good question. I haven't tested it against NT4. Guess this gives me a good reason to get a NT4 host set up. :)
Quoted 135 lines · Jeff Layton
Quoted 122 lines
The proper way to set the delete on close bit on an already existing file is to use
SET_FILE_INFOwith an infolevel ofSMB_FILE_DISPOSITION_INFO. Add a function to do that and have the silly-rename code use it.Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsproto.h | 2 + fs/cifs/cifssmb.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/inode.c | 9 ++++++- 3 files changed, 64 insertions(+), 2 deletions(-)fs/cifs/cifsproto.h +2
-0@@ -179,6 +179,8 @@ extern int CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon,extern int CIFSSMBSetFileInfo (const int xid,struct cifsTconInfo *tcon,const FILE_BASIC_INFO *data,__u16 fid,__u32 pid_of_opener); +extern int CIFSSMBSetFileDisposition (const int xid,struct cifsTconInfo *tcon, +bool delete_file,__u16 fid,__u32 pid_of_opener);#if 0 extern int CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, __u16 dos_attributes,fs/cifs/cifssmb.c +55
-0@@ -4876,6 +4876,61 @@ CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon,return rc; } +int +CIFSSMBSetFileDisposition (const int xid,struct cifsTconInfo *tcon, +bool delete_file,__u16 fid,__u32 pid_of_opener) +{ +struct smb_com_transaction2_sfi_req *pSMB =NULL ; +char *data_offset; +int rc =0 ; +__u16 params, param_offset, offset, byte_count, count; + +cFYI (1 , ("Set File Disposition (via SetFileInfo)" )); + rc =small_smb_init (SMB_COM_TRANSACTION2 ,15 , tcon, (void **) &pSMB); + +if (rc) +return rc; + + pSMB->hdr.Pid =cpu_to_le16 ((__u16 )pid_of_opener); + pSMB->hdr.PidHigh =cpu_to_le16 ((__u16)(pid_of_opener >>16 )); + + params =6 ; + pSMB->MaxSetupCount =0 ; + pSMB->Reserved =0 ; + pSMB->Flags =0 ; + pSMB->Timeout =0 ; + pSMB->Reserved2 =0 ; + param_offset = offsetof(struct smb_com_transaction2_sfi_req , Fid) -4 ; + offset = param_offset + params; + + data_offset = (char *) (&pSMB->hdr.Protocol) + offset; + + count =1 ; + pSMB->MaxParameterCount =cpu_to_le16 (2 ); +/* BB find max SMB PDU from sess */ + pSMB->MaxDataCount =cpu_to_le16 (1000 ); + pSMB->SetupCount =1 ; + pSMB->Reserved3 =0 ; + pSMB->SubCommand =cpu_to_le16 (TRANS2_SET_FILE_INFORMATION ); + byte_count =3 /* pad */ + params + count; + pSMB->DataCount =cpu_to_le16 (count); + pSMB->ParameterCount =cpu_to_le16 (params); + pSMB->TotalDataCount = pSMB->DataCount; + pSMB->TotalParameterCount = pSMB->ParameterCount; + pSMB->ParameterOffset =cpu_to_le16 (param_offset); + pSMB->DataOffset =cpu_to_le16 (offset); + pSMB->Fid = fid; + pSMB->InformationLevel =cpu_to_le16 (SMB_SET_FILE_DISPOSITION_INFO ); + pSMB->Reserved4 =0 ; + pSMB->hdr.smb_buf_length += byte_count; + pSMB->ByteCount =cpu_to_le16 (byte_count); + *data_offset = delete_file ?1 :0 ; + rc =SendReceiveNoRsp (xid, tcon->ses, (struct smb_hdr *) pSMB,0 ); +if (rc) +cFYI (1 , ("Send error in SetFileDisposition = %d" , rc)); + +return rc; +} int CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon,fs/cifs/inode.c +7
-3@@ -685,8 +685,7 @@ cifs_silly_rename(char *full_path, struct inode *inode, int xid)FILE_BASIC_INFO *info_buf; rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , -DELETE |FILE_WRITE_ATTRIBUTES , -CREATE_NOT_DIR |CREATE_DELETE_ON_CLOSE , +DELETE |FILE_WRITE_ATTRIBUTES ,CREATE_NOT_DIR , &netfid, &oplock,NULL , cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR );if (rc !=0 )@@ -714,6 +713,12 @@ cifs_silly_rename(char *full_path, struct inode *inode, int xid) rc =CIFSSMBRenameOpenFile (xid, tcon, netfid,NULL , cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc !=0 ) + goto out_close; + +/* set DELETE_ON_CLOSE */ + rc =CIFSSMBSetFileDisposition (xid, tcon, true, netfid, current->tgid); + out_close:CIFSSMBClose (xid, tcon, netfid); out: --1.5.5.1
Signature · 7 lines
Thanks, Steve _______________________________________________ linux-cifs-client mailing list [email protected] https://lists.samba.org/mailman/listinfo/linux-cifs-client
Signature · 1 line
Jeff Layton <[email protected]>