cifs: check the timestamp for the cached dirent when deciding on revalidate
Subsystems (2)
PATCH 3/9 cifs: rename the *_shroot* functions to *_cached_dir*
In reply to a message not in the archiveThese functions will eventually be used to cache any directory, not just the root so change the names.
--- fs/cifs/cifssmb.c | 2 +- fs/cifs/smb2inode.c | 4 ++-- fs/cifs/smb2ops.c | 19 ++++++++++--------- fs/cifs/smb2pdu.c | 2 +- fs/cifs/smb2proto.h | 14 +++++++------- 5 files changed, 21 insertions(+), 20 deletions(-)
fs/cifs/cifssmb.c +1 -1
@@ -114,7 +114,7 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon)mutex_lock (&tcon->crfid.fid_mutex); tcon->crfid.is_valid = false;/* cached handle is not valid, so SMB2_CLOSE won't be sent below */ -close_shroot_lease_locked (&tcon->crfid); +close_cached_dir_lease_locked (&tcon->crfid);memset (tcon->crfid.fid,0 ,sizeof (struct cifs_fid ));mutex_unlock (&tcon->crfid.fid_mutex);
fs/cifs/smb2inode.c +2 -2
@@ -523,7 +523,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ - rc =open_shroot (xid, tcon, full_path, cifs_sb, &cfid); + rc =open_cached_dir (xid, tcon, full_path, cifs_sb, &cfid);if (!rc) {if (tcon->crfid.file_all_info_is_valid) { move_smb2_info_to_cifs(data,
@@ -535,7 +535,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,if (!rc)move_smb2_info_to_cifs (data, smb2_data); } -close_shroot (cfid); +close_cached_dir (cfid); goto out; }
fs/cifs/smb2ops.c +10 -9
@@ -693,14 +693,14 @@ smb2_close_cached_fid(struct kref *ref) } } -void close_shroot (struct cached_fid *cfid) +void close_cached_dir (struct cached_fid *cfid) {mutex_lock (&cfid->fid_mutex);kref_put (&cfid->refcount, smb2_close_cached_fid);mutex_unlock (&cfid->fid_mutex); } -void close_shroot_lease_locked (struct cached_fid *cfid) +void close_cached_dir_lease_locked (struct cached_fid *cfid) {if (cfid->has_lease) { cfid->has_lease = false;
@@ -708,10 +708,10 @@ void close_shroot_lease_locked(struct cached_fid *cfid) } } -void close_shroot_lease (struct cached_fid *cfid) +void close_cached_dir_lease (struct cached_fid *cfid) {mutex_lock (&cfid->fid_mutex); -close_shroot_lease_locked (cfid); +close_cached_dir_lease_locked (cfid);mutex_unlock (&cfid->fid_mutex); }
@@ -721,13 +721,14 @@ smb2_cached_lease_break(struct work_struct *work)struct cached_fid *cfid =container_of (work, struct cached_fid, lease_break); -close_shroot_lease (cfid); +close_cached_dir_lease (cfid); }/* -* Open the directory at the root of a share +* Open the and cache a directory handle. +* Only supported for the root handle. */ -int open_shroot (unsigned int xid,struct cifs_tcon *tcon, +int open_cached_dir (unsigned int xid,struct cifs_tcon *tcon,const char *path,struct cifs_sb_info *cifs_sb,struct cached_fid **cfid)
@@ -930,7 +931,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =open_shroot (xid, tcon,"" , cifs_sb, &cfid); + rc =open_cached_dir (xid, tcon,"" , cifs_sb, &cfid);if (rc ==0 )memcpy (&fid, cfid->fid,sizeof (struct cifs_fid ));else
@@ -952,7 +953,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,if (cfid ==NULL )SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid);else -close_shroot (cfid); +close_cached_dir (cfid); } static void
fs/cifs/smb2pdu.c +1 -1
@@ -1857,7 +1857,7 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)if ((tcon->need_reconnect) || (tcon->ses->need_reconnect))return 0 ; -close_shroot_lease (&tcon->crfid); +close_cached_dir_lease (&tcon->crfid); rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, ses->server, (void **) &req,
fs/cifs/smb2proto.h +7 -7
@@ -69,13 +69,13 @@ extern struct cifs_ses *smb2_find_smb_ses(struct TCP_Server_Info *server,extern int smb3_handle_read_data (struct TCP_Server_Info *server,struct mid_q_entry *mid); -extern int open_shroot (unsigned int xid,struct cifs_tcon *tcon, -const char *path, -struct cifs_sb_info *cifs_sb, -struct cached_fid **cfid); -extern void close_shroot (struct cached_fid *cfid); -extern void close_shroot_lease (struct cached_fid *cfid); -extern void close_shroot_lease_locked (struct cached_fid *cfid); +extern int open_cached_dir (unsigned int xid,struct cifs_tcon *tcon, +const char *path, +struct cifs_sb_info *cifs_sb, +struct cached_fid **cfid); +extern void close_cached_dir (struct cached_fid *cfid); +extern void close_cached_dir_lease (struct cached_fid *cfid); +extern void close_cached_dir_lease_locked (struct cached_fid *cfid);extern void move_smb2_info_to_cifs (FILE_ALL_INFO *dst,struct smb2_file_all_info *src); extern int smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
Signature · 1 line
2.13.6
PATCH 6/9 cifs: add a function to get a cached dir based on its dentry
In reply to a message not in the archive--- fs/cifs/smb2ops.c | 16 ++++++++++++++++ fs/cifs/smb2proto.h | 3 +++ 2 files changed, 19 insertions(+)
fs/cifs/smb2ops.c +16 -0
@@ -925,6 +925,22 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,return rc; } +int open_cached_dir_by_dentry (struct cifs_tcon *tcon, +struct dentry *dentry, +struct cached_fid **cfid) +{ +mutex_lock (&tcon->crfid.fid_mutex); +if (tcon->crfid.dentry == dentry) { +cifs_dbg (FYI ,"found a cached root file handle by dentry\n" ); + *cfid = &tcon->crfid; +kref_get (&tcon->crfid.refcount); +mutex_unlock (&tcon->crfid.fid_mutex); +return 0 ; + } +mutex_unlock (&tcon->crfid.fid_mutex); +return -ENOENT ; +} +static void smb3_qfs_tcon (const unsigned int xid,struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb)
fs/cifs/smb2proto.h +3 -0
@@ -73,6 +73,9 @@ extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,const char *path, struct cifs_sb_info *cifs_sb, struct cached_fid **cfid); +extern int open_cached_dir_by_dentry (struct cifs_tcon *tcon, +struct dentry *dentry, +struct cached_fid **cfid);extern void close_cached_dir (struct cached_fid *cfid);extern void close_cached_dir_lease (struct cached_fid *cfid);extern void close_cached_dir_lease_locked (struct cached_fid *cfid);
Signature · 1 line
2.13.6
PATCH 9/9 cifs: check the timestamp for the cached dirent when deciding on revalidate
In reply to a message not in the archive--- fs/cifs/inode.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/cifs/inode.c +12 -0
@@ -2189,6 +2189,8 @@ cifs_dentry_needs_reval(struct dentry *dentry)struct inode *inode =d_inode (dentry);struct cifsInodeInfo *cifs_i =CIFS_I (inode);struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb); +struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb); +struct cached_fid *cfid =NULL ;if (cifs_i->time ==0 )return true;
@@ -2199,6 +2201,16 @@ cifs_dentry_needs_reval(struct dentry *dentry)if (!lookupCacheEnabled)return true; +if (!open_cached_dir_by_dentry (tcon, dentry->d_parent, &cfid)) { +mutex_lock (&cfid->fid_mutex); +if (cfid->time && cifs_i->time > cfid->time) { +mutex_unlock (&cfid->fid_mutex); +close_cached_dir (cfid); +return false; + } +mutex_unlock (&cfid->fid_mutex); +close_cached_dir (cfid); + }/* * depending on inode type, check if attribute caching disabled for * files or directories
Signature · 1 line
2.13.6
PATCH 7/9 cifs: add a timestamp to track when the lease of the cached dir was taken
In reply to a message not in the archiveand clear the timestamp when we receive a lease break.
--- fs/cifs/cifsglob.h | 1 + fs/cifs/smb2misc.c | 1 + fs/cifs/smb2ops.c | 2 ++ 3 files changed, 4 insertions(+)
fs/cifs/cifsglob.h +1 -0
@@ -988,6 +988,7 @@ struct cached_fid { bool is_valid:1; /* Do we have a useable root fid */ bool file_all_info_is_valid:1; bool has_lease:1; +unsigned long time;/* jiffies of when lease was taken */ struct kref refcount;struct cifs_fid *fid;struct mutex fid_mutex;
fs/cifs/smb2misc.c +1 -0
@@ -667,6 +667,7 @@ smb2_is_valid_lease_break(char *buffer) !memcmp (rsp->LeaseKey, tcon->crfid.fid->lease_key, SMB2_LEASE_KEY_SIZE)) { + tcon->crfid.time = 0;INIT_WORK (&tcon->crfid.lease_break, smb2_cached_lease_break); queue_work(cifsiod_wq,
fs/cifs/smb2ops.c +2 -0
@@ -912,6 +912,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, &rsp_iov[1], sizeof(struct smb2_file_all_info), (char *)&tcon->crfid.file_all_info)) tcon->crfid.file_all_info_is_valid = true; + tcon->crfid.time = jiffies; + oshr_exit:mutex_unlock (&tcon->crfid.fid_mutex);
Signature · 1 line
2.13.6
PATCH 2/9 cifs: pass a path to open_shroot and check if it is the root or not
In reply to a message not in the archiveMove the check for the directory path into the open_shroot() function but still fail for any non-root directories.
This is preparation for later when we will start using the cache also for other directories than the root.
--- fs/cifs/smb2inode.c | 22 ++++++++++------------ fs/cifs/smb2ops.c | 6 +++++- fs/cifs/smb2proto.h | 1 + 3 files changed, 16 insertions(+), 13 deletions(-)
fs/cifs/smb2inode.c +10 -12
@@ -523,22 +523,20 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ -if (!strlen (full_path)) { - rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (!rc) { -if (tcon->crfid.file_all_info_is_valid) { -move_smb2_info_to_cifs (data, + rc =open_shroot (xid, tcon, full_path, cifs_sb, &cfid); +if (!rc) { +if (tcon->crfid.file_all_info_is_valid) { +move_smb2_info_to_cifs (data, &tcon->crfid.file_all_info); - }else { - rc =SMB2_query_info (xid, tcon, + }else { + rc =SMB2_query_info (xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); -if (!rc) -move_smb2_info_to_cifs (data, smb2_data); - } -close_shroot (cfid); - goto out; +if (!rc) +move_smb2_info_to_cifs (data, smb2_data); } +close_shroot (cfid); + goto out; }cifs_get_readable_path (tcon, full_path, &cfile);
fs/cifs/smb2ops.c +5 -1
@@ -728,6 +728,7 @@ smb2_cached_lease_break(struct work_struct *work)* Open the directory at the root of a share */ int open_shroot (unsigned int xid,struct cifs_tcon *tcon, +const char *path,struct cifs_sb_info *cifs_sb,struct cached_fid **cfid) {
@@ -749,6 +750,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,if (tcon->nohandlecache)return -ENOTSUPP ; +if (strlen (path)) +return -ENOTSUPP ; +mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {cifs_dbg (FYI ,"found a cached root file handle\n" );
@@ -926,7 +930,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =open_shroot (xid, tcon, cifs_sb, &cfid); + rc =open_shroot (xid, tcon,"" , cifs_sb, &cfid);if (rc ==0 )memcpy (&fid, cfid->fid,sizeof (struct cifs_fid ));else
fs/cifs/smb2proto.h +1 -0
@@ -70,6 +70,7 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid);extern int open_shroot (unsigned int xid,struct cifs_tcon *tcon, +const char *path,struct cifs_sb_info *cifs_sb,struct cached_fid **cfid);extern void close_shroot (struct cached_fid *cfid);
Signature · 1 line
2.13.6
PATCH 4/9 cifs: store a pointer to the root dentry in cifs_sb_info once we have completed mounting the share
In reply to a message not in the archiveAnd use this to only allow to take out a shared handle once the mount has completed and the sb becomes available.
This will become important in follow up patches where we will start holding a reference to the directory dentry for the shared handle during the lifetime of the handle.
--- fs/cifs/cifs_fs_sb.h | 4 ++++ fs/cifs/cifsfs.c | 9 +++++++++ fs/cifs/smb2ops.c | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-)
fs/cifs/cifs_fs_sb.h +4 -0
@@ -81,5 +81,9 @@ struct cifs_sb_info {* (cifs_autodisable_serverino) in order to match new mounts. */ bool mnt_cifs_serverino_autodisabled; +/* +* Available once the mount has completed. +*/ + struct dentry *root; };#endif /* _CIFS_FS_SB_H */
fs/cifs/cifsfs.c +9 -0
@@ -257,6 +257,12 @@ cifs_read_super(struct super_block *sb)static void cifs_kill_sb (struct super_block *sb) {struct cifs_sb_info *cifs_sb =CIFS_SB (sb); + +if (cifs_sb->root) { +dput (cifs_sb->root); + cifs_sb->root =NULL ; + } +kill_anon_super (sb);cifs_umount (cifs_sb); }
@@ -886,6 +892,9 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,if (IS_ERR (root)) goto out_super; +if (cifs_sb) + cifs_sb->root =dget (root); +cifs_dbg (FYI ,"dentry root is: %p\n" , root);return root;
fs/cifs/smb2ops.c +4 -1
@@ -751,8 +751,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,if (tcon->nohandlecache)return -ENOTSUPP ; +if (cifs_sb->root ==NULL ) +return -ENOENT ; +if (strlen (path)) -return -ENOTSUPP ; +return -ENOENT ;mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {
Signature · 1 line
2.13.6
PATCH 8/9 cifs: pass the dentry instead of the inode down to the revalidation check functions
In reply to a message not in the archive--- fs/cifs/inode.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/cifs/inode.c +5 -4
@@ -2184,8 +2184,9 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, }static bool -cifs_inode_needs_reval (struct inode *inode) +cifs_dentry_needs_reval (struct dentry *dentry) { +struct inode *inode =d_inode (dentry);struct cifsInodeInfo *cifs_i =CIFS_I (inode);struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);
@@ -2296,10 +2297,10 @@ cifs_zap_mapping(struct inode *inode)int cifs_revalidate_file_attr (struct file *filp) {int rc =0 ; -struct inode *inode =file_inode (filp); +struct dentry *dentry =file_dentry (filp);struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data; -if (!cifs_inode_needs_reval (inode)) +if (!cifs_dentry_needs_reval (dentry))return rc;if (tlink_tcon (cfile->tlink)->unix_ext)
@@ -2322,7 +2323,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)if (inode ==NULL )return -ENOENT ; -if (!cifs_inode_needs_reval (inode)) +if (!cifs_dentry_needs_reval (dentry))return rc; xid =get_xid ();
Signature · 1 line
2.13.6
PATCH 1/9 cifs: move the check for nohandlecache into open_shroot
In reply to a message not in the archiveinstead of doing it in the callsites for open_shroot.
--- fs/cifs/smb2inode.c | 24 +++++++++++------------- fs/cifs/smb2ops.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 21 deletions(-)
fs/cifs/smb2inode.c +11 -13
@@ -511,7 +511,6 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,int rc;struct smb2_file_all_info *smb2_data;__u32 create_options =0 ; -bool no_cached_open = tcon->nohandlecache;struct cifsFileInfo *cfile;struct cached_fid *cfid =NULL ;
@@ -524,23 +523,22 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ -if (!strlen (full_path) && !no_cached_open) { +if (!strlen (full_path)) { rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (rc) - goto out; - -if (tcon->crfid.file_all_info_is_valid) { -move_smb2_info_to_cifs (data, +if (!rc) { +if (tcon->crfid.file_all_info_is_valid) { +move_smb2_info_to_cifs (data, &tcon->crfid.file_all_info); - }else { - rc =SMB2_query_info (xid, tcon, + }else { + rc =SMB2_query_info (xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); -if (!rc) -move_smb2_info_to_cifs (data, smb2_data); +if (!rc) +move_smb2_info_to_cifs (data, smb2_data); + } +close_shroot (cfid); + goto out; } -close_shroot (cfid); - goto out; }cifs_get_readable_path (tcon, full_path, &cfile);
fs/cifs/smb2ops.c +8 -8
@@ -746,6 +746,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_II ;struct cifs_fid *pfid; +if (tcon->nohandlecache) +return -ENOTSUPP ; +mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {cifs_dbg (FYI ,"found a cached root file handle\n" );
@@ -914,7 +917,6 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;struct cifs_open_parms oparms;struct cifs_fid fid; -bool no_cached_open = tcon->nohandlecache;struct cached_fid *cfid =NULL ; oparms.tcon = tcon;
@@ -924,14 +926,12 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; -if (no_cached_open) { + rc =open_shroot (xid, tcon, cifs_sb, &cfid); +if (rc ==0 ) +memcpy (&fid, cfid->fid,sizeof (struct cifs_fid )); +else rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ,NULL ,NULL ,NULL ); - }else { - rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (rc ==0 ) -memcpy (&fid, cfid->fid,sizeof (struct cifs_fid )); - }if (rc)return ;
@@ -945,7 +945,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, FS_VOLUME_INFORMATION);SMB2_QFS_attr (xid, tcon, fid.persistent_fid, fid.volatile_fid,FS_SECTOR_SIZE_INFORMATION );/* SMB3 specific */ -if (no_cached_open) +if (cfid ==NULL )SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid);else close_shroot (cfid);
Signature · 1 line
2.13.6
PATCH 5/9 cifs: Grab a reference for the dentry of the cached directory during the lifetime of the cache
In reply to a message not in the archiveWe need to hold both a reference for the root/superblock as well as the directory that we are caching. We need to drop these references before we call kill_anon_sb().
At this point, the root and the cached dentries are always the same but this will change once we start caching other directories as well.
--- fs/cifs/cifsfs.c | 17 +++++++++++++++++ fs/cifs/cifsglob.h | 1 + fs/cifs/smb2ops.c | 9 +++++++++ 3 files changed, 27 insertions(+)
fs/cifs/cifsfs.c +17 -0
@@ -257,11 +257,28 @@ cifs_read_super(struct super_block *sb)static void cifs_kill_sb (struct super_block *sb) {struct cifs_sb_info *cifs_sb =CIFS_SB (sb); +struct cifs_tcon *tcon; +struct cached_fid *cfid; +/* +* We ned to release all dentries for the cached directories +* before we kill the sb. +*/ if (cifs_sb->root) {dput (cifs_sb->root); cifs_sb->root =NULL ; } + tcon =cifs_sb_master_tcon (cifs_sb); +if (tcon) { + cfid = &tcon->crfid; +mutex_lock (&cfid->fid_mutex); +if (cfid->dentry) { + +dput (cfid->dentry); + cfid->dentry =NULL ; + } +mutex_unlock (&cfid->fid_mutex); + }kill_anon_super (sb);cifs_umount (cifs_sb);
fs/cifs/cifsglob.h +1 -0
@@ -992,6 +992,7 @@ struct cached_fid {struct cifs_fid *fid;struct mutex fid_mutex;struct cifs_tcon *tcon; +struct dentry *dentry;struct work_struct lease_break;struct smb2_file_all_info file_all_info; };
fs/cifs/smb2ops.c +9 -0
@@ -690,6 +690,10 @@ smb2_close_cached_fid(struct kref *ref) cfid->is_valid = false; cfid->file_all_info_is_valid = false; cfid->has_lease = false; +if (cfid->dentry) { +dput (cfid->dentry); + cfid->dentry =NULL ; + } } }
@@ -747,6 +751,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,__le16 utf16_path =0 ;/* Null - since an open of top of share */ u8 oplock =SMB2_OPLOCK_LEVEL_II ;struct cifs_fid *pfid; +struct dentry *dentry;if (tcon->nohandlecache)return -ENOTSUPP ;
@@ -757,6 +762,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,if (strlen (path))return -ENOENT ; + dentry = cifs_sb->root; +mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {cifs_dbg (FYI ,"found a cached root file handle\n" );
@@ -881,6 +888,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,memcpy (tcon->crfid.fid, pfid,sizeof (struct cifs_fid )); tcon->crfid.tcon = tcon; tcon->crfid.is_valid = true; + tcon->crfid.dentry = dentry; +dget (dentry);kref_init (&tcon->crfid.refcount);/* BB TBD check to see if oplock level check can be removed below */
Signature · 1 line
2.13.6
Re: [PATCH 1/9] cifs: move the check for nohandlecache into open_shroot
In reply to Ronnie SahlbergIs there an updated version of this 9 patch series or is this current?
Any additional review feedback on it?
Quoted 109 lines · Ronnie Sahlberg
instead of doing it in the callsites for
open_shroot.Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2inode.c | 24 +++++++++++------------- fs/cifs/smb2ops.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 21 deletions(-)fs/cifs/smb2inode.c +11
-13@@ -511,7 +511,6 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,int rc;struct smb2_file_all_info *smb2_data;__u32 create_options =0 ; -bool no_cached_open = tcon->nohandlecache;struct cifsFileInfo *cfile;struct cached_fid *cfid =NULL ;@@ -524,23 +523,22 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ -if (!strlen (full_path) && !no_cached_open) { +if (!strlen (full_path)) { rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (rc) - goto out; - -if (tcon->crfid.file_all_info_is_valid) { -move_smb2_info_to_cifs (data, +if (!rc) { +if (tcon->crfid.file_all_info_is_valid) { +move_smb2_info_to_cifs (data, &tcon->crfid.file_all_info); - }else { - rc =SMB2_query_info (xid, tcon, + }else { + rc =SMB2_query_info (xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); -if (!rc) -move_smb2_info_to_cifs (data, smb2_data); +if (!rc) +move_smb2_info_to_cifs (data, smb2_data); + } +close_shroot (cfid); + goto out; } -close_shroot (cfid); - goto out; }cifs_get_readable_path (tcon, full_path, &cfile);fs/cifs/smb2ops.c +8
-9@@ -746,6 +746,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_II ;struct cifs_fid *pfid; +if (tcon->nohandlecache) +return -ENOTSUPP ; +mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {cifs_dbg (FYI ,"found a cached root file handle\n" );@@ -914,7 +917,6 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;struct cifs_open_parms oparms;struct cifs_fid fid; -bool no_cached_open = tcon->nohandlecache;struct cached_fid *cfid =NULL ; oparms.tcon = tcon;@@ -924,14 +926,12 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; -if (no_cached_open) { + rc =open_shroot (xid, tcon, cifs_sb, &cfid); +if (rc ==0 ) +memcpy (&fid, cfid->fid,sizeof (struct cifs_fid )); +else rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ,NULL ,NULL ,NULL ); - }else { - rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (rc ==0 ) -memcpy (&fid, cfid->fid,sizeof (struct cifs_fid )); - }if (rc)return ;@@ -945,7 +945,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, FS_VOLUME_INFORMATION);SMB2_QFS_attr (xid, tcon, fid.persistent_fid, fid.volatile_fid,FS_SECTOR_SIZE_INFORMATION );/* SMB3 specific */ -if (no_cached_open) +if (cfid ==NULL )SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid);else close_shroot (cfid); --2.13.6
Signature · 3 lines
Thanks, Steve
Re: [PATCH 1/9] cifs: move the check for nohandlecache into open_shroot
In reply to Ronnie Sahlbergcheckpatch complains about
WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP #71: FILE: fs/cifs/smb2ops.c:750:
include/linux/errno.h indicates that these in range 512 through 530 should never be returned to userspace:
/*
* These should never be seen by user programs. To return one of ERESTART*
* codes, signal_pending() MUST be set. Note that ptrace can observe these
* at syscall exit tracing, but they will never be left for the debugged user
* process to see.
*/
... but since this is not returned to userspace, perhaps it is harmless. Thoughts?
Quoted 109 lines · Ronnie Sahlberg
instead of doing it in the callsites for
open_shroot.Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2inode.c | 24 +++++++++++------------- fs/cifs/smb2ops.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 21 deletions(-)fs/cifs/smb2inode.c +11
-13@@ -511,7 +511,6 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,int rc;struct smb2_file_all_info *smb2_data;__u32 create_options =0 ; -bool no_cached_open = tcon->nohandlecache;struct cifsFileInfo *cfile;struct cached_fid *cfid =NULL ;@@ -524,23 +523,22 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ -if (!strlen (full_path) && !no_cached_open) { +if (!strlen (full_path)) { rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (rc) - goto out; - -if (tcon->crfid.file_all_info_is_valid) { -move_smb2_info_to_cifs (data, +if (!rc) { +if (tcon->crfid.file_all_info_is_valid) { +move_smb2_info_to_cifs (data, &tcon->crfid.file_all_info); - }else { - rc =SMB2_query_info (xid, tcon, + }else { + rc =SMB2_query_info (xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); -if (!rc) -move_smb2_info_to_cifs (data, smb2_data); +if (!rc) +move_smb2_info_to_cifs (data, smb2_data); + } +close_shroot (cfid); + goto out; } -close_shroot (cfid); - goto out; }cifs_get_readable_path (tcon, full_path, &cfile);fs/cifs/smb2ops.c +8
-9@@ -746,6 +746,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_II ;struct cifs_fid *pfid; +if (tcon->nohandlecache) +return -ENOTSUPP ; +mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {cifs_dbg (FYI ,"found a cached root file handle\n" );@@ -914,7 +917,6 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;struct cifs_open_parms oparms;struct cifs_fid fid; -bool no_cached_open = tcon->nohandlecache;struct cached_fid *cfid =NULL ; oparms.tcon = tcon;@@ -924,14 +926,12 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; -if (no_cached_open) { + rc =open_shroot (xid, tcon, cifs_sb, &cfid); +if (rc ==0 ) +memcpy (&fid, cfid->fid,sizeof (struct cifs_fid )); +else rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ,NULL ,NULL ,NULL ); - }else { - rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (rc ==0 ) -memcpy (&fid, cfid->fid,sizeof (struct cifs_fid )); - }if (rc)return ;@@ -945,7 +945,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, FS_VOLUME_INFORMATION);SMB2_QFS_attr (xid, tcon, fid.persistent_fid, fid.volatile_fid,FS_SECTOR_SIZE_INFORMATION );/* SMB3 specific */ -if (no_cached_open) +if (cfid ==NULL )SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid);else close_shroot (cfid); --2.13.6
Signature · 3 lines
Thanks, Steve
Re: [PATCH 2/9] cifs: pass a path to open_shroot and check if it is the root or not
In reply to Ronnie SahlbergSimilar checkpatch complaint about ENOTSUPP (instead of EOPNOTSUPP)
WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP #74: FILE: fs/cifs/smb2ops.c:754:
+ return -ENOTSUPP;
the header which defines ENOTSUPP notes:
/*
* These should never be seen by user programs. To return one of ERESTART*
* codes, signal_pending() MUST be set. Note that ptrace can observe these
* at syscall exit tracing, but they will never be left for the debugged user
* process to see.
*/
Quoted 96 lines · Ronnie Sahlberg
Move the check for the directory path into the
open_shroot()function but still fail for any non-root directories.
This is preparation for later when we will start using the cache also for other directories than the root.Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2inode.c | 22 ++++++++++------------ fs/cifs/smb2ops.c | 6 +++++- fs/cifs/smb2proto.h | 1 + 3 files changed, 16 insertions(+), 13 deletions(-)fs/cifs/smb2inode.c +10
-12@@ -523,22 +523,20 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ -if (!strlen (full_path)) { - rc =open_shroot (xid, tcon, cifs_sb, &cfid); -if (!rc) { -if (tcon->crfid.file_all_info_is_valid) { -move_smb2_info_to_cifs (data, + rc =open_shroot (xid, tcon, full_path, cifs_sb, &cfid); +if (!rc) { +if (tcon->crfid.file_all_info_is_valid) { +move_smb2_info_to_cifs (data, &tcon->crfid.file_all_info); - }else { - rc =SMB2_query_info (xid, tcon, + }else { + rc =SMB2_query_info (xid, tcon, cfid->fid->persistent_fid, cfid->fid->volatile_fid, smb2_data); -if (!rc) -move_smb2_info_to_cifs (data, smb2_data); - } -close_shroot (cfid); - goto out; +if (!rc) +move_smb2_info_to_cifs (data, smb2_data); } +close_shroot (cfid); + goto out; }cifs_get_readable_path (tcon, full_path, &cfile);fs/cifs/smb2ops.c +5
-1@@ -728,6 +728,7 @@ smb2_cached_lease_break(struct work_struct *work)* Open the directory at the root of a share */ int open_shroot (unsigned int xid,struct cifs_tcon *tcon, +const char *path,struct cifs_sb_info *cifs_sb,struct cached_fid **cfid) {@@ -749,6 +750,9 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,if (tcon->nohandlecache)return -ENOTSUPP ; +if (strlen (path)) +return -ENOTSUPP ; +mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) {cifs_dbg (FYI ,"found a cached root file handle\n" );@@ -926,7 +930,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =open_shroot (xid, tcon, cifs_sb, &cfid); + rc =open_shroot (xid, tcon,"" , cifs_sb, &cfid);if (rc ==0 )memcpy (&fid, cfid->fid,sizeof (struct cifs_fid ));else fs/cifs/smb2proto.h +1
-1@@ -70,6 +70,7 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid);extern int open_shroot (unsigned int xid,struct cifs_tcon *tcon, +const char *path,struct cifs_sb_info *cifs_sb,struct cached_fid **cfid);extern void close_shroot (struct cached_fid *cfid); --2.13.6
Signature · 3 lines
Thanks, Steve
Re: [PATCH 3/9] cifs: rename the *_shroot* functions to *_cached_dir*
In reply to Ronnie Sahlbergthese renames look fine.
Quoted 159 lines · Ronnie Sahlberg
These functions will eventually be used to cache any directory, not just the root so change the names.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/cifssmb.c | 2 +- fs/cifs/smb2inode.c | 4 ++-- fs/cifs/smb2ops.c | 19 ++++++++++--------- fs/cifs/smb2pdu.c | 2 +- fs/cifs/smb2proto.h | 14 +++++++------- 5 files changed, 21 insertions(+), 20 deletions(-)fs/cifs/cifssmb.c +1
-1@@ -114,7 +114,7 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon)mutex_lock (&tcon->crfid.fid_mutex); tcon->crfid.is_valid = false;/* cached handle is not valid, so SMB2_CLOSE won't be sent below */ -close_shroot_lease_locked (&tcon->crfid); +close_cached_dir_lease_locked (&tcon->crfid);memset (tcon->crfid.fid,0 ,sizeof (struct cifs_fid ));mutex_unlock (&tcon->crfid.fid_mutex);fs/cifs/smb2inode.c +2
-2@@ -523,7 +523,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ;/* If it is a root and its handle is cached then use it */ - rc =open_shroot (xid, tcon, full_path, cifs_sb, &cfid); + rc =open_cached_dir (xid, tcon, full_path, cifs_sb, &cfid);if (!rc) {if (tcon->crfid.file_all_info_is_valid) { move_smb2_info_to_cifs(data,@@ -535,7 +535,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,if (!rc)move_smb2_info_to_cifs (data, smb2_data); } -close_shroot (cfid); +close_cached_dir (cfid); goto out; }fs/cifs/smb2ops.c +10
-9@@ -693,14 +693,14 @@ smb2_close_cached_fid(struct kref *ref) } } -void close_shroot (struct cached_fid *cfid) +void close_cached_dir (struct cached_fid *cfid) {mutex_lock (&cfid->fid_mutex);kref_put (&cfid->refcount, smb2_close_cached_fid);mutex_unlock (&cfid->fid_mutex); } -void close_shroot_lease_locked (struct cached_fid *cfid) +void close_cached_dir_lease_locked (struct cached_fid *cfid) {if (cfid->has_lease) { cfid->has_lease = false;@@ -708,10 +708,10 @@ void close_shroot_lease_locked(struct cached_fid *cfid) } } -void close_shroot_lease (struct cached_fid *cfid) +void close_cached_dir_lease (struct cached_fid *cfid) {mutex_lock (&cfid->fid_mutex); -close_shroot_lease_locked (cfid); +close_cached_dir_lease_locked (cfid);mutex_unlock (&cfid->fid_mutex); }@@ -721,13 +721,14 @@ smb2_cached_lease_break(struct work_struct *work)struct cached_fid *cfid =container_of (work, struct cached_fid, lease_break); -close_shroot_lease (cfid); +close_cached_dir_lease (cfid); }/* -* Open the directory at the root of a share +* Open the and cache a directory handle. +* Only supported for the root handle. */ -int open_shroot (unsigned int xid,struct cifs_tcon *tcon, +int open_cached_dir (unsigned int xid,struct cifs_tcon *tcon,const char *path,struct cifs_sb_info *cifs_sb,struct cached_fid **cfid)@@ -930,7 +931,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =open_shroot (xid, tcon,"" , cifs_sb, &cfid); + rc =open_cached_dir (xid, tcon,"" , cifs_sb, &cfid);if (rc ==0 )memcpy (&fid, cfid->fid,sizeof (struct cifs_fid ));else @@ -952,7 +953,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,if (cfid ==NULL )SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid);else -close_shroot (cfid); +close_cached_dir (cfid); } static voidfs/cifs/smb2pdu.c +1
-1@@ -1857,7 +1857,7 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)if ((tcon->need_reconnect) || (tcon->ses->need_reconnect))return 0 ; -close_shroot_lease (&tcon->crfid); +close_cached_dir_lease (&tcon->crfid); rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, ses->server, (void **) &req,fs/cifs/smb2proto.h +7
-8@@ -69,13 +69,13 @@ extern struct cifs_ses *smb2_find_smb_ses(struct TCP_Server_Info *server,extern int smb3_handle_read_data (struct TCP_Server_Info *server,struct mid_q_entry *mid); -extern int open_shroot (unsigned int xid,struct cifs_tcon *tcon, -const char *path, -struct cifs_sb_info *cifs_sb, -struct cached_fid **cfid); -extern void close_shroot (struct cached_fid *cfid); -extern void close_shroot_lease (struct cached_fid *cfid); -extern void close_shroot_lease_locked (struct cached_fid *cfid); +extern int open_cached_dir (unsigned int xid,struct cifs_tcon *tcon, +const char *path, +struct cifs_sb_info *cifs_sb, +struct cached_fid **cfid); +extern void close_cached_dir (struct cached_fid *cfid); +extern void close_cached_dir_lease (struct cached_fid *cfid); +extern void close_cached_dir_lease_locked (struct cached_fid *cfid);extern void move_smb2_info_to_cifs (FILE_ALL_INFO *dst,struct smb2_file_all_info *src); extern int smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon, --2.13.6
Signature · 3 lines
Thanks, Steve
Re: [PATCH 4/9] cifs: store a pointer to the root dentry in cifs_sb_info once we have completed mounting the share
In reply to Ronnie Sahlberglooks reasonable
Quoted 74 lines · Ronnie Sahlberg
And use this to only allow to take out a shared handle once the mount has completed and the sb becomes available.
This will become important in follow up patches where we will start holding a reference to the directory dentry for the shared handle during the lifetime of the handle.Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/cifs_fs_sb.h | 4 ++++ fs/cifs/cifsfs.c | 9 +++++++++ fs/cifs/smb2ops.c | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-)fs/cifs/cifs_fs_sb.h +4
-0@@ -81,5 +81,9 @@ struct cifs_sb_info {* (cifs_autodisable_serverino) in order to match new mounts. */ bool mnt_cifs_serverino_autodisabled; +/* +* Available once the mount has completed. +*/ + struct dentry *root; };#endif /* _CIFS_FS_SB_H */ fs/cifs/cifsfs.c +9
-0@@ -257,6 +257,12 @@ cifs_read_super(struct super_block *sb)static void cifs_kill_sb (struct super_block *sb) {struct cifs_sb_info *cifs_sb =CIFS_SB (sb); + +if (cifs_sb->root) { +dput (cifs_sb->root); + cifs_sb->root =NULL ; + } +kill_anon_super (sb);cifs_umount (cifs_sb); }@@ -886,6 +892,9 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,if (IS_ERR (root)) goto out_super; +if (cifs_sb) + cifs_sb->root =dget (root); +cifs_dbg (FYI ,"dentry root is: %p\n" , root);return root;fs/cifs/smb2ops.c +4
-2@@ -751,8 +751,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,if (tcon->nohandlecache)return -ENOTSUPP ; +if (cifs_sb->root ==NULL ) +return -ENOENT ; +if (strlen (path)) -return -ENOTSUPP ; +return -ENOENT ;mutex_lock (&tcon->crfid.fid_mutex);if (tcon->crfid.is_valid) { --2.13.6
Signature · 3 lines
Thanks, Steve