Skip to content

Commit fdf59eb

Browse files
committed
smb3: cleanup and clarify status of tree connections
Currently the way the tid (tree connection) status is tracked is confusing. The same enum is used for structs cifs_tcon and cifs_ses and TCP_Server_info, but each of these three has different states that they transition among. The current code also unnecessarily uses camelCase. Convert from use of statusEnum to a new tid_status_enum for tree connections. The valid states for a tid are: TID_NEW = 0, TID_GOOD, TID_EXITING, TID_NEED_RECON, TID_NEED_TCON, TID_IN_TCON, TID_NEED_FILES_INVALIDATE, /* unused, considering removing in future */ TID_IN_FILES_INVALIDATE It also removes CifsNeedTcon, CifsInTcon, CifsNeedFilesInvalidate and CifsInFilesInvalidate from the statusEnum used for session and TCP_Server_Info since they are not relevant for those. A follow on patch will fix the places where we use the tcon->need_reconnect flag to be more consistent with the tid->status. Also fixes a bug that was: Reported-by: kernel test robot <lkp@intel.com> Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent be13500 commit fdf59eb

7 files changed

Lines changed: 40 additions & 33 deletions

File tree

fs/cifs/cifs_debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
9494
le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
9595
le32_to_cpu(tcon->fsAttrInfo.Attributes),
9696
le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
97-
tcon->tidStatus);
97+
tcon->status);
9898
if (dev_type == FILE_DEVICE_DISK)
9999
seq_puts(m, " type: DISK ");
100100
else if (dev_type == FILE_DEVICE_CD_ROM)

fs/cifs/cifsfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,14 +699,14 @@ static void cifs_umount_begin(struct super_block *sb)
699699
tcon = cifs_sb_master_tcon(cifs_sb);
700700

701701
spin_lock(&cifs_tcp_ses_lock);
702-
if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
702+
if ((tcon->tc_count > 1) || (tcon->status == TID_EXITING)) {
703703
/* we have other mounts to same share or we have
704704
already tried to force umount this and woken up
705705
all waiting network requests, nothing to do */
706706
spin_unlock(&cifs_tcp_ses_lock);
707707
return;
708708
} else if (tcon->tc_count == 1)
709-
tcon->tidStatus = CifsExiting;
709+
tcon->status = TID_EXITING;
710710
spin_unlock(&cifs_tcp_ses_lock);
711711

712712
/* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */

fs/cifs/cifsglob.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,18 @@ enum statusEnum {
115115
CifsInNegotiate,
116116
CifsNeedSessSetup,
117117
CifsInSessSetup,
118-
CifsNeedTcon,
119-
CifsInTcon,
120-
CifsNeedFilesInvalidate,
121-
CifsInFilesInvalidate
118+
};
119+
120+
/* associated with each tree connection to the server */
121+
enum tid_status_enum {
122+
TID_NEW = 0,
123+
TID_GOOD,
124+
TID_EXITING,
125+
TID_NEED_RECON,
126+
TID_NEED_TCON,
127+
TID_IN_TCON,
128+
TID_NEED_FILES_INVALIDATE, /* currently unused */
129+
TID_IN_FILES_INVALIDATE
122130
};
123131

124132
enum securityEnum {
@@ -1032,7 +1040,7 @@ struct cifs_tcon {
10321040
char *password; /* for share-level security */
10331041
__u32 tid; /* The 4 byte tree id */
10341042
__u16 Flags; /* optional support bits */
1035-
enum statusEnum tidStatus;
1043+
enum tid_status_enum status;
10361044
atomic_t num_smbs_sent;
10371045
union {
10381046
struct {

fs/cifs/cifssmb.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
7575

7676
/* only send once per connect */
7777
spin_lock(&cifs_tcp_ses_lock);
78-
if (tcon->ses->status != CifsGood ||
79-
tcon->tidStatus != CifsNeedReconnect) {
78+
if ((tcon->ses->status != CifsGood) || (tcon->status != TID_NEED_RECON)) {
8079
spin_unlock(&cifs_tcp_ses_lock);
8180
return;
8281
}
83-
tcon->tidStatus = CifsInFilesInvalidate;
82+
tcon->status = TID_IN_FILES_INVALIDATE;
8483
spin_unlock(&cifs_tcp_ses_lock);
8584

8685
/* list all files open on tree connection and mark them invalid */
@@ -100,8 +99,8 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
10099
mutex_unlock(&tcon->crfid.fid_mutex);
101100

102101
spin_lock(&cifs_tcp_ses_lock);
103-
if (tcon->tidStatus == CifsInFilesInvalidate)
104-
tcon->tidStatus = CifsNeedTcon;
102+
if (tcon->status == TID_IN_FILES_INVALIDATE)
103+
tcon->status = TID_NEED_TCON;
105104
spin_unlock(&cifs_tcp_ses_lock);
106105

107106
/*
@@ -136,7 +135,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
136135
* have tcon) are allowed as we start force umount
137136
*/
138137
spin_lock(&cifs_tcp_ses_lock);
139-
if (tcon->tidStatus == CifsExiting) {
138+
if (tcon->status == TID_EXITING) {
140139
if (smb_command != SMB_COM_WRITE_ANDX &&
141140
smb_command != SMB_COM_OPEN_ANDX &&
142141
smb_command != SMB_COM_TREE_DISCONNECT) {

fs/cifs/connect.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
245245

246246
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
247247
tcon->need_reconnect = true;
248-
tcon->tidStatus = CifsNeedReconnect;
248+
tcon->status = TID_NEED_RECON;
249249
}
250250
if (ses->tcon_ipc)
251251
ses->tcon_ipc->need_reconnect = true;
@@ -2207,7 +2207,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
22072207

22082208
static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
22092209
{
2210-
if (tcon->tidStatus == CifsExiting)
2210+
if (tcon->status == TID_EXITING)
22112211
return 0;
22122212
if (strncmp(tcon->treeName, ctx->UNC, MAX_TREE_SIZE))
22132213
return 0;
@@ -4486,12 +4486,12 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
44864486
/* only send once per connect */
44874487
spin_lock(&cifs_tcp_ses_lock);
44884488
if (tcon->ses->status != CifsGood ||
4489-
(tcon->tidStatus != CifsNew &&
4490-
tcon->tidStatus != CifsNeedTcon)) {
4489+
(tcon->status != TID_NEW &&
4490+
tcon->status != TID_NEED_TCON)) {
44914491
spin_unlock(&cifs_tcp_ses_lock);
44924492
return 0;
44934493
}
4494-
tcon->tidStatus = CifsInTcon;
4494+
tcon->status = TID_IN_TCON;
44954495
spin_unlock(&cifs_tcp_ses_lock);
44964496

44974497
tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL);
@@ -4532,13 +4532,13 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
45324532

45334533
if (rc) {
45344534
spin_lock(&cifs_tcp_ses_lock);
4535-
if (tcon->tidStatus == CifsInTcon)
4536-
tcon->tidStatus = CifsNeedTcon;
4535+
if (tcon->status == TID_IN_TCON)
4536+
tcon->status = TID_NEED_TCON;
45374537
spin_unlock(&cifs_tcp_ses_lock);
45384538
} else {
45394539
spin_lock(&cifs_tcp_ses_lock);
4540-
if (tcon->tidStatus == CifsInTcon)
4541-
tcon->tidStatus = CifsGood;
4540+
if (tcon->status == TID_IN_TCON)
4541+
tcon->status = TID_GOOD;
45424542
spin_unlock(&cifs_tcp_ses_lock);
45434543
tcon->need_reconnect = false;
45444544
}
@@ -4554,24 +4554,24 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
45544554
/* only send once per connect */
45554555
spin_lock(&cifs_tcp_ses_lock);
45564556
if (tcon->ses->status != CifsGood ||
4557-
(tcon->tidStatus != CifsNew &&
4558-
tcon->tidStatus != CifsNeedTcon)) {
4557+
(tcon->status != TID_NEW &&
4558+
tcon->status != TID_NEED_TCON)) {
45594559
spin_unlock(&cifs_tcp_ses_lock);
45604560
return 0;
45614561
}
4562-
tcon->tidStatus = CifsInTcon;
4562+
tcon->status = TID_IN_TCON;
45634563
spin_unlock(&cifs_tcp_ses_lock);
45644564

45654565
rc = ops->tree_connect(xid, tcon->ses, tcon->treeName, tcon, nlsc);
45664566
if (rc) {
45674567
spin_lock(&cifs_tcp_ses_lock);
4568-
if (tcon->tidStatus == CifsInTcon)
4569-
tcon->tidStatus = CifsNeedTcon;
4568+
if (tcon->status == TID_IN_TCON)
4569+
tcon->status = TID_NEED_TCON;
45704570
spin_unlock(&cifs_tcp_ses_lock);
45714571
} else {
45724572
spin_lock(&cifs_tcp_ses_lock);
4573-
if (tcon->tidStatus == CifsInTcon)
4574-
tcon->tidStatus = CifsGood;
4573+
if (tcon->status == TID_IN_TCON)
4574+
tcon->status = TID_GOOD;
45754575
spin_unlock(&cifs_tcp_ses_lock);
45764576
tcon->need_reconnect = false;
45774577
}

fs/cifs/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ tconInfoAlloc(void)
116116
}
117117

118118
atomic_inc(&tconInfoAllocCount);
119-
ret_buf->tidStatus = CifsNew;
119+
ret_buf->status = TID_NEW;
120120
++ret_buf->tc_count;
121121
INIT_LIST_HEAD(&ret_buf->openFileList);
122122
INIT_LIST_HEAD(&ret_buf->tcon_list);

fs/cifs/smb2pdu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
163163
return 0;
164164

165165
spin_lock(&cifs_tcp_ses_lock);
166-
if (tcon->tidStatus == CifsExiting) {
166+
if (tcon->status == TID_EXITING) {
167167
/*
168168
* only tree disconnect, open, and write,
169169
* (and ulogoff which does not have tcon)
@@ -3860,7 +3860,7 @@ void smb2_reconnect_server(struct work_struct *work)
38603860
goto done;
38613861
}
38623862

3863-
tcon->tidStatus = CifsGood;
3863+
tcon->status = TID_GOOD;
38643864
tcon->retry = false;
38653865
tcon->need_reconnect = false;
38663866

0 commit comments

Comments
 (0)