Skip to content

Commit 491eafc

Browse files
author
Steve French
committed
smb3: fix unusable share after force unmount failure
If user does forced unmount ("umount -f") while files are still open on the share (as was seen in a Kubernetes example running on SMB3.1.1 mount) then we were marking the share as "TID_EXITING" in umount_begin() which caused all subsequent operations (except write) to fail ... but unfortunately when umount_begin() is called we do not know yet that there are open files or active references on the share that would prevent unmount from succeeding. Kubernetes had example when they were doing umount -f when files were open which caused the share to become unusable until the files were closed (and the umount retried). Fix this so that TID_EXITING is not set until we are about to send the tree disconnect (not at the beginning of forced umounts in umount_begin) so that if "umount -f" fails (due to open files or references) the mount is still usable. Cc: stable@vger.kernel.org Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Reviewed-by: Paulo Alcantara (SUSE) <pc@manguebit.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent be4fde7 commit 491eafc

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

fs/cifs/cifsfs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,16 @@ static void cifs_umount_begin(struct super_block *sb)
731731
spin_lock(&tcon->tc_lock);
732732
if ((tcon->tc_count > 1) || (tcon->status == TID_EXITING)) {
733733
/* we have other mounts to same share or we have
734-
already tried to force umount this and woken up
734+
already tried to umount this and woken up
735735
all waiting network requests, nothing to do */
736736
spin_unlock(&tcon->tc_lock);
737737
spin_unlock(&cifs_tcp_ses_lock);
738738
return;
739-
} else if (tcon->tc_count == 1)
740-
tcon->status = TID_EXITING;
739+
}
740+
/*
741+
* can not set tcon->status to TID_EXITING yet since we don't know if umount -f will
742+
* fail later (e.g. due to open files). TID_EXITING will be set just before tdis req sent
743+
*/
741744
spin_unlock(&tcon->tc_lock);
742745
spin_unlock(&cifs_tcp_ses_lock);
743746

fs/cifs/cifssmb.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
8686

8787
/*
8888
* only tree disconnect, open, and write, (and ulogoff which does not
89-
* have tcon) are allowed as we start force umount
89+
* have tcon) are allowed as we start umount
9090
*/
9191
spin_lock(&tcon->tc_lock);
9292
if (tcon->status == TID_EXITING) {
93-
if (smb_command != SMB_COM_WRITE_ANDX &&
94-
smb_command != SMB_COM_OPEN_ANDX &&
95-
smb_command != SMB_COM_TREE_DISCONNECT) {
93+
if (smb_command != SMB_COM_TREE_DISCONNECT) {
9694
spin_unlock(&tcon->tc_lock);
9795
cifs_dbg(FYI, "can not send cmd %d while umounting\n",
9896
smb_command);

fs/cifs/connect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,7 @@ cifs_put_tcon(struct cifs_tcon *tcon)
23242324
WARN_ON(tcon->tc_count < 0);
23252325

23262326
list_del_init(&tcon->tcon_list);
2327+
tcon->status = TID_EXITING;
23272328
spin_unlock(&tcon->tc_lock);
23282329
spin_unlock(&cifs_tcp_ses_lock);
23292330

fs/cifs/smb2pdu.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,9 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
165165
spin_lock(&tcon->tc_lock);
166166
if (tcon->status == TID_EXITING) {
167167
/*
168-
* only tree disconnect, open, and write,
169-
* (and ulogoff which does not have tcon)
170-
* are allowed as we start force umount.
168+
* only tree disconnect allowed when disconnecting ...
171169
*/
172-
if ((smb2_command != SMB2_WRITE) &&
173-
(smb2_command != SMB2_CREATE) &&
174-
(smb2_command != SMB2_TREE_DISCONNECT)) {
170+
if (smb2_command != SMB2_TREE_DISCONNECT) {
175171
spin_unlock(&tcon->tc_lock);
176172
cifs_dbg(FYI, "can not send cmd %d while umounting\n",
177173
smb2_command);

0 commit comments

Comments
 (0)