Skip to content

Commit 2da338f

Browse files
author
Steve French
committed
smb3: do not start laundromat thread when dir leases
disabled When no directory lease support, or for IPC shares where directories can not be opened, do not start an unneeded laundromat thread for that mount (it wastes resources). Fixes: d14de80 ("cifs: Add a laundromat thread for cached directories") Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Acked-by: Tom Talpey <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent e3603cc commit 2da338f

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

fs/smb/client/cached_dir.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ void invalidate_all_cached_dirs(struct cifs_tcon *tcon)
452452
struct cached_fid *cfid, *q;
453453
LIST_HEAD(entry);
454454

455+
if (cfids == NULL)
456+
return;
457+
455458
spin_lock(&cfids->cfid_list_lock);
456459
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
457460
list_move(&cfid->entry, &entry);
@@ -651,6 +654,9 @@ void free_cached_dirs(struct cached_fids *cfids)
651654
struct cached_fid *cfid, *q;
652655
LIST_HEAD(entry);
653656

657+
if (cfids == NULL)
658+
return;
659+
654660
if (cfids->laundromat) {
655661
kthread_stop(cfids->laundromat);
656662
cfids->laundromat = NULL;

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ require use of the stronger protocol */
19431943
* cifsInodeInfo->lock_sem cifsInodeInfo->llist cifs_init_once
19441944
* ->can_cache_brlcks
19451945
* cifsInodeInfo->deferred_lock cifsInodeInfo->deferred_closes cifsInodeInfo_alloc
1946-
* cached_fid->fid_mutex cifs_tcon->crfid tconInfoAlloc
1946+
* cached_fid->fid_mutex cifs_tcon->crfid tcon_info_alloc
19471947
* cifsFileInfo->fh_mutex cifsFileInfo cifs_new_fileinfo
19481948
* cifsFileInfo->file_info_lock cifsFileInfo->count cifs_new_fileinfo
19491949
* ->invalidHandle initiate_cifs_search

fs/smb/client/cifsproto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ extern int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses);
512512

513513
extern struct cifs_ses *sesInfoAlloc(void);
514514
extern void sesInfoFree(struct cifs_ses *);
515-
extern struct cifs_tcon *tconInfoAlloc(void);
515+
extern struct cifs_tcon *tcon_info_alloc(bool dir_leases_enabled);
516516
extern void tconInfoFree(struct cifs_tcon *);
517517

518518
extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,

fs/smb/client/connect.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,8 @@ cifs_setup_ipc(struct cifs_ses *ses, struct smb3_fs_context *ctx)
18821882
}
18831883
}
18841884

1885-
tcon = tconInfoAlloc();
1885+
/* no need to setup directory caching on IPC share, so pass in false */
1886+
tcon = tcon_info_alloc(false);
18861887
if (tcon == NULL)
18871888
return -ENOMEM;
18881889

@@ -2492,7 +2493,10 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
24922493
goto out_fail;
24932494
}
24942495

2495-
tcon = tconInfoAlloc();
2496+
if (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)
2497+
tcon = tcon_info_alloc(true);
2498+
else
2499+
tcon = tcon_info_alloc(false);
24962500
if (tcon == NULL) {
24972501
rc = -ENOMEM;
24982502
goto out_fail;

fs/smb/client/misc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,22 @@ sesInfoFree(struct cifs_ses *buf_to_free)
113113
}
114114

115115
struct cifs_tcon *
116-
tconInfoAlloc(void)
116+
tcon_info_alloc(bool dir_leases_enabled)
117117
{
118118
struct cifs_tcon *ret_buf;
119119

120120
ret_buf = kzalloc(sizeof(*ret_buf), GFP_KERNEL);
121121
if (!ret_buf)
122122
return NULL;
123-
ret_buf->cfids = init_cached_dirs();
124-
if (!ret_buf->cfids) {
125-
kfree(ret_buf);
126-
return NULL;
123+
124+
if (dir_leases_enabled == true) {
125+
ret_buf->cfids = init_cached_dirs();
126+
if (!ret_buf->cfids) {
127+
kfree(ret_buf);
128+
return NULL;
129+
}
127130
}
131+
/* else ret_buf->cfids is already set to NULL above */
128132

129133
atomic_inc(&tconInfoAllocCount);
130134
ret_buf->status = TID_NEW;

fs/smb/client/smb2pdu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,7 @@ void smb2_reconnect_server(struct work_struct *work)
38783878
goto done;
38793879

38803880
/* allocate a dummy tcon struct used for reconnect */
3881-
tcon = tconInfoAlloc();
3881+
tcon = tcon_info_alloc(false);
38823882
if (!tcon) {
38833883
resched = true;
38843884
list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {

0 commit comments

Comments
 (0)