On soft mounts cifs_wait_for_server_reconnect() waited up to 10 seconds (per target) for the reconnect, even if the reconnect attempts failed right away, e.g. because the local address used for the connection was removed. This delays e.g. the statfs() umount(8) does before calling umount(2) by 10 seconds. Count the reconnect attempts that failed with an error indicating a local problem, -EADDRNOTAVAIL or -ENODEV if the local address or the network device used for the connection is gone, and -ENETUNREACH or -ENETDOWN if the local network is down or has no route to the server, in server->reconnect_local_failures and wake up server->response_q after each of them, so that requests on soft mounts give up once the next such reconnect attempt failed. Note that a short local outage, e.g. while the link is down for a few seconds during a cable replug or a Wi-Fi roam, now also makes requests on soft mounts fail after about 3 seconds instead of 10. That's what soft mounts are for, hard mounts hide it as before. For other errors the requests wait up to 10 seconds as before, e.g. while the server restarts the first attempt may fail with -ECONNREFUSED and the next one succeeds, so the 10 second wait still hides such a short outage from the applications. Hard mounts still keep waiting. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: aa24d1e96924 ("CIFS: Process reconnects for SMB2 shares") Cc: stable@vger.kernel.org Cc: Paulo Alcantara Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- fs/smb/client/cifsglob.h | 5 +++++ fs/smb/client/connect.c | 37 +++++++++++++++++++++++++++++++++++++ fs/smb/client/misc.c | 29 ++++++++++++++++++++++------- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 3bfa9b1bacf5..a59eb91a0ff3 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -742,6 +742,11 @@ struct TCP_Server_Info { char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; __u32 sequence_number; /* for signing, protected by srv_mutex */ __u32 reconnect_instance; /* incremented on each reconnect */ + /* + * incremented on each reconnect attempt that failed + * because of a local problem, protected by srv_lock + */ + unsigned int reconnect_local_failures; __le32 session_key_id; /* retrieved from negotiate response and send in session setup request */ struct session_key session_key; unsigned long lstrp; /* when we got last response from this server */ diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index d3e40dcbf049..7aef771c67b5 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -393,6 +393,41 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num return true; } +/* + * Errors that indicate a local problem, which is not expected to go + * away within a few seconds, e.g. the local address or the network + * device used for the connection is gone. Other errors, e.g. + * -ECONNREFUSED while the server restarts, may be transient. + */ +static bool cifs_reconnect_error_is_local(int rc) +{ + switch (rc) { + case -EADDRNOTAVAIL: + case -ENETUNREACH: + case -ENETDOWN: + case -ENODEV: + return true; + } + + return false; +} + +/* + * Let the requests waiting in cifs_wait_for_server_reconnect() + * on soft mounts know that a reconnect attempt failed because + * of a local problem. + */ +static void cifs_reconnect_failed(struct TCP_Server_Info *server, int rc) +{ + if (!cifs_reconnect_error_is_local(rc)) + return; + + spin_lock(&server->srv_lock); + server->reconnect_local_failures++; + spin_unlock(&server->srv_lock); + wake_up_all(&server->response_q); +} + /* * cifs tcp session reconnection * @@ -443,6 +478,7 @@ static int __cifs_reconnect(struct TCP_Server_Info *server, if (rc) { cifs_server_unlock(server); cifs_dbg(FYI, "%s: reconnect error %d\n", __func__, rc); + cifs_reconnect_failed(server, rc); /* If was asked to reconnect only once, do not try it more times */ if (once) break; @@ -583,6 +619,7 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server) /* Failed to reconnect socket */ cifs_server_unlock(server); cifs_dbg(FYI, "%s: reconnect error %d\n", __func__, rc); + cifs_reconnect_failed(server, rc); /* * Wait before the next try, but stop * waiting once the server is exiting. diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 6785a92b0924..3231bc1e1b4b 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -1096,17 +1096,27 @@ bool cifs_server_wait_exiting(struct TCP_Server_Info *server, } static bool reco_wait_done(struct TCP_Server_Info *server, - struct cifs_tcon *tcon, int aborts) + struct cifs_tcon *tcon, int aborts, + unsigned int failures) { - return server->tcpStatus != CifsNeedReconnect || - atomic_read(&tcon->umount_aborts) != aborts || - cifs_tcon_dying(tcon); + if (server->tcpStatus != CifsNeedReconnect || + atomic_read(&tcon->umount_aborts) != aborts || + cifs_tcon_dying(tcon)) + return true; + + /* + * soft mounts only wait until the next reconnect + * attempt failed because of a local problem + */ + return !tcon->retry && + READ_ONCE(server->reconnect_local_failures) != failures; } int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, struct cifs_tcon *tcon, int aborts, bool nowait) { + unsigned int failures; int timeout = 10; int rc; @@ -1120,6 +1130,7 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, return -EAGAIN; } timeout *= server->nr_targets; + failures = server->reconnect_local_failures; spin_unlock(&server->srv_lock); /* @@ -1127,14 +1138,18 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, * reconnect -- should be greater than cifs socket timeout which is 7 * seconds. * - * On "soft" mounts we wait once. Hard mounts keep retrying until - * process is killed or server comes back on-line. + * On "soft" mounts we wait once, but only until the next reconnect + * attempt failed because of a local problem, e.g. it can't succeed + * if the local address is gone. + * Hard mounts keep retrying until process is killed or server comes + * back on-line. */ do { rc = wait_event_interruptible_timeout(server->response_q, reco_wait_done(server, tcon, - aborts), + aborts, + failures), timeout * HZ); if (rc < 0) { cifs_dbg(FYI, "%s: aborting reconnect due to received signal\n", -- 2.43.0