smb/client: improve change notify support
Subsystems (2)
ChenXiaoSong
reviewercover smb/client: improve change notify support
From: ChenXiaoSong <[email protected]>
I still need to do more debugging on this patchset, for example to check whether there is any race between ioctl(CIFS_IOC_NOTIFY_INFO) and readdir(). Maybe I can send this patchset to the mailing list first to get more suggestions from others.
Before this patchset, when an operation on the server triggered multiple actions, the client received only one action notification.
After this patchset, the client can receive all action notifications.
Example:
smbinfo notify /mnt
# server: touch /export/file1
Notifications received, returned data_len is 24
Action: 0x00000001, FileName: file1
Notifications received, returned data_len is 24
Action: 0x00000003, FileName: file1
# server: mv /export/file1 /export/file2
Notifications received, returned data_len is 48
Action: 0x00000004, FileName: file1
Action: 0x00000005, FileName: file2
Notifications received, returned data_len is 24
Action: 0x00000003, FileName: file2
Notifications received, returned data_len is 24
Action: 0x00000002, FileName: file1
ChenXiaoSong (2):
smb/client: introduce smb3_notify_open() smb/client: do not call SMB2_close() in smb3_notify()
fs/smb/client/smb2ops.c | 120 ++++++++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 34 deletions(-)
Signature · 1 line
2.54.0
ChenXiaoSong
reviewerRFC PATCH 1/2 smb/client: introduce smb3_notify_open()
From: ChenXiaoSong <[email protected]>
Introduce this helper function to reduce the diff in the next patch and make the actual changes easier to review. No functional changes.
--- fs/smb/client/smb2ops.c | 71 ++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 26 deletions(-)
fs/smb/client/smb2ops.c +45 -26
@@ -2364,7 +2364,50 @@ smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,return rc; } +static int +smb3_notify_open (const unsigned int xid,struct dentry *dentry, +struct cifs_sb_info *cifs_sb,void *page, +struct cifs_fid *fid,const unsigned char **pathp, +__le16 **utf16_pathp,struct cifs_tcon **tconp) +{ +struct cifs_tcon *tcon; +const unsigned char *path; +__le16 *utf16_path =NULL ; +struct cifs_open_parms oparms; +u8 oplock =SMB2_OPLOCK_LEVEL_NONE ; +int rc; + + path =build_path_from_dentry (dentry, page); +if (IS_ERR (path)) { + rc =PTR_ERR (path); + goto out; + } + *pathp = path; + + utf16_path =cifs_convert_path_to_utf16 (path, cifs_sb); +if (utf16_path ==NULL ) { + rc = -ENOMEM ; + goto out; + } + *utf16_pathp = utf16_path; + + tcon =cifs_sb_master_tcon (cifs_sb); + *tconp = tcon; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .path = path, + .desired_access =FILE_READ_ATTRIBUTES |FILE_READ_DATA , + .disposition =FILE_OPEN , + .create_options =cifs_create_options (cifs_sb,0 ), + .fid = fid, + }; + + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL ,NULL , +NULL ); +out: +return rc; +} static int smb3_notify(const unsigned int xid, struct file *pfile,
@@ -2375,29 +2418,15 @@ smb3_notify(const unsigned int xid, struct file *pfile,struct dentry *dentry = pfile->f_path.dentry;struct inode *inode =file_inode (pfile);struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb); -struct cifs_open_parms oparms;struct cifs_fid fid;struct cifs_tcon *tcon;const unsigned char *path;char *returned_ioctl_info =NULL ;void *page =alloc_dentry_path ();__le16 *utf16_path =NULL ; -u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;int rc =0 ;__u32 ret_len =0 ; - path =build_path_from_dentry (dentry, page); -if (IS_ERR (path)) { - rc =PTR_ERR (path); - goto notify_exit; - } - - utf16_path =cifs_convert_path_to_utf16 (path, cifs_sb); -if (utf16_path ==NULL ) { - rc = -ENOMEM ; - goto notify_exit; - } -if (return_changes) {if (copy_from_user (¬ify, ioc_buf,sizeof (struct smb3_notify_info ))) { rc = -EFAULT ;
@@ -2411,18 +2440,8 @@ smb3_notify(const unsigned int xid, struct file *pfile, notify.data_len =0 ; } - tcon =cifs_sb_master_tcon (cifs_sb); - oparms = (struct cifs_open_parms ) { - .tcon = tcon, - .path = path, - .desired_access =FILE_READ_ATTRIBUTES |FILE_READ_DATA , - .disposition =FILE_OPEN , - .create_options =cifs_create_options (cifs_sb,0 ), - .fid = &fid, - }; - - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL ,NULL , -NULL ); + rc =smb3_notify_open (xid, dentry, cifs_sb, page, &fid, + &path, &utf16_path, &tcon);if (rc) goto notify_exit;
Signature · 1 line
2.54.0
ChenXiaoSong
reviewerRFC PATCH 2/2 smb/client: do not call SMB2_close() in smb3_notify()
In reply to ChenXiaoSongFrom: ChenXiaoSong <[email protected]>
Before this patch, when an operation on the server triggered multiple actions, the client received only one action notification.
After this patch, the client can receive all action notifications. After open(directory), only the first ioctl(CIFS_IOC_NOTIFY_INFO) triggers SMB2_open(), cifsFileInfo is stored in file->private_data, close(directory) will trigger SMB2_close().
Example:
smbinfo notify /mnt
# server: touch /export/file1
Notifications received, returned data_len is 24
Action: 0x00000001, FileName: file1
Notifications received, returned data_len is 24
Action: 0x00000003, FileName: file1
# server: mv /export/file1 /export/file2
Notifications received, returned data_len is 48
Action: 0x00000004, FileName: file1
Action: 0x00000005, FileName: file2
Notifications received, returned data_len is 24
Action: 0x00000003, FileName: file2
Notifications received, returned data_len is 24
Action: 0x00000002, FileName: file1
--- fs/smb/client/smb2ops.c | 83 ++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 25 deletions(-)
fs/smb/client/smb2ops.c +58 -25
@@ -2365,47 +2365,84 @@ smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, }static int -smb3_notify_open (const unsigned int xid,struct dentry *dentry, -struct cifs_sb_info *cifs_sb,void *page, -struct cifs_fid *fid,const unsigned char **pathp, -__le16 **utf16_pathp,struct cifs_tcon **tconp) +smb3_notify_open (const unsigned int xid,struct file *pfile) { +struct inode *inode =file_inode (pfile); +struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb); +struct cifsFileInfo *cfile, *existing_cfile;struct cifs_tcon *tcon;const unsigned char *path;__le16 *utf16_path =NULL ; +struct tcon_link *tlink =NULL ;struct cifs_open_parms oparms; +struct cifs_fid fid = {}; +void *page =NULL ;u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;int rc; - path =build_path_from_dentry (dentry, page); + existing_cfile = pfile->private_data; +if (existing_cfile && !existing_cfile->invalidHandle) { + rc =0 ; + goto out; + } +if (existing_cfile && existing_cfile->invalidHandle) { + rc = -EBADF ; + goto out; + } + + tlink =cifs_sb_tlink (cifs_sb); +if (IS_ERR (tlink)) { + rc =PTR_ERR (tlink); + goto out; + } + tcon =tlink_tcon (tlink); + + page =alloc_dentry_path (); + path =build_path_from_dentry (pfile->f_path.dentry, page);if (IS_ERR (path)) { rc =PTR_ERR (path); goto out; } - *pathp = path; utf16_path =cifs_convert_path_to_utf16 (path, cifs_sb);if (utf16_path ==NULL ) { rc = -ENOMEM ; goto out; } - *utf16_pathp = utf16_path; - tcon =cifs_sb_master_tcon (cifs_sb); - *tconp = tcon; + cfile = kzalloc_obj(struct cifsFileInfo); +if (!cfile) { + rc = -ENOMEM ; + goto out; + } +spin_lock_init (&cfile->file_info_lock); + cfile->tlink =cifs_get_tlink (tlink); + oparms = (struct cifs_open_parms ) { .tcon = tcon, .path = path, .desired_access =FILE_READ_ATTRIBUTES |FILE_READ_DATA , .disposition =FILE_OPEN , .create_options =cifs_create_options (cifs_sb,0 ), - .fid = fid, + .fid = &fid, }; rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL ,NULL ,NULL ); +if (rc) { +cifs_put_tlink (cfile->tlink); +kfree (cfile); + goto out; + } + + cfile->fid = fid; + cfile->invalidHandle = false; + pfile->private_data = cfile; out: +kfree (utf16_path); +free_dentry_path (page); +cifs_put_tlink (tlink);return rc; }
@@ -2415,17 +2452,12 @@ smb3_notify(const unsigned int xid, struct file *pfile, {struct smb3_notify_info notify;struct smb3_notify_info __user *pnotify_buf; -struct dentry *dentry = pfile->f_path.dentry; -struct inode *inode =file_inode (pfile); -struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);struct cifs_fid fid;struct cifs_tcon *tcon; -const unsigned char *path;char *returned_ioctl_info =NULL ; -void *page =alloc_dentry_path (); -__le16 *utf16_path =NULL ;int rc =0 ;__u32 ret_len =0 ; +struct cifsFileInfo *cfile = pfile->private_data;if (return_changes) {if (copy_from_user (¬ify, ioc_buf,sizeof (struct smb3_notify_info ))) {
@@ -2440,18 +2472,21 @@ smb3_notify(const unsigned int xid, struct file *pfile, notify.data_len =0 ; } - rc =smb3_notify_open (xid, dentry, cifs_sb, page, &fid, - &path, &utf16_path, &tcon); -if (rc) - goto notify_exit; +if (!cfile || cfile->invalidHandle) { + rc =smb3_notify_open (xid, pfile); +if (rc) + goto notify_exit; + cfile = pfile->private_data; + } + + tcon =tlink_tcon (cfile->tlink); + fid = cfile->fid; rc =SMB2_change_notify (xid, tcon, fid.persistent_fid, fid.volatile_fid, notify.watch_tree, notify.completion_filter, notify.data_len, &returned_ioctl_info, &ret_len); -SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid); - -cifs_dbg (FYI ,"change notify for path %s rc %d\n" , path, rc); +cifs_dbg (FYI ,"change notify rc %d\n" , rc);if (return_changes && (ret_len >0 ) && (notify.data_len >0 )) {if (ret_len > notify.data_len) ret_len = notify.data_len;
@@ -2463,8 +2498,6 @@ smb3_notify(const unsigned int xid, struct file *pfile, }kfree (returned_ioctl_info); notify_exit: -free_dentry_path (page); -kfree (utf16_path);return rc; }
Signature · 1 line
2.54.0