diff mbox series

[6/9] cifs: cifs: handlecache, only track the dentry for the root handle

Message ID 20220809021156.3086869-7-lsahlber@redhat.com (mailing list archive)
State New, archived
Headers show
Series [1/9] cifs: Move cached-dir functions into a separate file | expand

Commit Message

Ronnie Sahlberg Aug. 9, 2022, 2:11 a.m. UTC
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/cached_dir.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Paulo Alcantara Aug. 11, 2022, 1:34 p.m. UTC | #1
Ronnie Sahlberg <lsahlber@redhat.com> writes:

> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/cached_dir.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/fs/cifs/cached_dir.c b/fs/cifs/cached_dir.c
> index 1fb80b23bbeb..9423fee378f4 100644
> --- a/fs/cifs/cached_dir.c
> +++ b/fs/cifs/cached_dir.c
> @@ -47,11 +47,12 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
>  	if (cifs_sb->root == NULL)
>  		return -ENOENT;
>  
> +	if (!strlen(path))
> +		dentry = cifs_sb->root;
> +

Why are you calling strlen() twice?  If below check is false, that means
path is empty and then you can set dentry to cifs_sb->root, as the
original code did.

>  	if (strlen(path))
>  		return -ENOENT;
>  
> -	dentry = cifs_sb->root;
> -

>  	cfid = &tcon->cfids->cfid;
>  	mutex_lock(&cfid->fid_mutex);
>  	if (cfid->is_valid) {
> @@ -177,7 +178,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
>  	cfid->tcon = tcon;
>  	cfid->is_valid = true;
>  	cfid->dentry = dentry;
> -	dget(dentry);
> +	if (dentry)

No need for NULL check.  dget() already does that.

> +		dget(dentry);
>  	kref_init(&cfid->refcount);
>  
>  	/* BB TBD check to see if oplock level check can be removed below */

Otherwise, look good to me.
diff mbox series

Patch

diff --git a/fs/cifs/cached_dir.c b/fs/cifs/cached_dir.c
index 1fb80b23bbeb..9423fee378f4 100644
--- a/fs/cifs/cached_dir.c
+++ b/fs/cifs/cached_dir.c
@@ -47,11 +47,12 @@  int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	if (cifs_sb->root == NULL)
 		return -ENOENT;
 
+	if (!strlen(path))
+		dentry = cifs_sb->root;
+
 	if (strlen(path))
 		return -ENOENT;
 
-	dentry = cifs_sb->root;
-
 	cfid = &tcon->cfids->cfid;
 	mutex_lock(&cfid->fid_mutex);
 	if (cfid->is_valid) {
@@ -177,7 +178,8 @@  int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	cfid->tcon = tcon;
 	cfid->is_valid = true;
 	cfid->dentry = dentry;
-	dget(dentry);
+	if (dentry)
+		dget(dentry);
 	kref_init(&cfid->refcount);
 
 	/* BB TBD check to see if oplock level check can be removed below */