Skip to content

Commit 731347a

Browse files
author
Ronnie Sahlberg
committed
cifs: drop the lease for cached directories on rmdir or rename
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2151418 commit 8e77860 When we delete or rename a directory we must also drop any cached lease we have on the directory. Fixes: a350d6e73f5e ("cifs: enable caching of directories for which a lease is held") Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com> (cherry picked from commit 8e77860) Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
1 parent e66a8f6 commit 731347a

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

fs/cifs/cached_dir.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,27 @@ smb2_close_cached_fid(struct kref *ref)
338338
free_cached_dir(cfid);
339339
}
340340

341+
void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
342+
const char *name, struct cifs_sb_info *cifs_sb)
343+
{
344+
struct cached_fid *cfid = NULL;
345+
int rc;
346+
347+
rc = open_cached_dir(xid, tcon, name, cifs_sb, true, &cfid);
348+
if (rc) {
349+
cifs_dbg(FYI, "no cached dir found for rmdir(%s)\n", name);
350+
return;
351+
}
352+
spin_lock(&cfid->cfids->cfid_list_lock);
353+
if (cfid->has_lease) {
354+
cfid->has_lease = false;
355+
kref_put(&cfid->refcount, smb2_close_cached_fid);
356+
}
357+
spin_unlock(&cfid->cfids->cfid_list_lock);
358+
close_cached_dir(cfid);
359+
}
360+
361+
341362
void close_cached_dir(struct cached_fid *cfid)
342363
{
343364
kref_put(&cfid->refcount, smb2_close_cached_fid);

fs/cifs/cached_dir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
6969
struct dentry *dentry,
7070
struct cached_fid **cfid);
7171
extern void close_cached_dir(struct cached_fid *cfid);
72+
extern void drop_cached_dir_by_name(const unsigned int xid,
73+
struct cifs_tcon *tcon,
74+
const char *name,
75+
struct cifs_sb_info *cifs_sb);
7276
extern void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);
7377
extern void invalidate_all_cached_dirs(struct cifs_tcon *tcon);
7478
extern int cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]);

fs/cifs/smb2inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ int
650650
smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
651651
struct cifs_sb_info *cifs_sb)
652652
{
653+
drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
653654
return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
654655
CREATE_NOT_FILE, ACL_NO_MODE,
655656
NULL, SMB2_OP_RMDIR, NULL);
@@ -693,6 +694,7 @@ smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
693694
{
694695
struct cifsFileInfo *cfile;
695696

697+
drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb);
696698
cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile);
697699

698700
return smb2_set_path_attr(xid, tcon, from_name, to_name,

0 commit comments

Comments
 (0)