Commit 69cba9d3 authored by Shyam Prasad N's avatar Shyam Prasad N Committed by Steve French

cifs: fix mid leak during reconnection after timeout threshold

When the number of responses with status of STATUS_IO_TIMEOUT
exceeds a specified threshold (NUM_STATUS_IO_TIMEOUT), we reconnect
the connection. But we do not return the mid, or the credits
returned for the mid, or reduce the number of in-flight requests.

This bug could result in the server->in_flight count to go bad,
and also cause a leak in the mids.

This change moves the check to a few lines below where the
response is decrypted, even of the response is read from the
transform header. This way, the code for returning the mids
can be reused.

Also, the cifs_reconnect was reconnecting just the transport
connection before. In case of multi-channel, this may not be
what we want to do after several timeouts. Changed that to
reconnect the session and the tree too.

Also renamed NUM_STATUS_IO_TIMEOUT to a more appropriate name
MAX_STATUS_IO_TIMEOUT.

Fixes: 8e670f77 ("Handle STATUS_IO_TIMEOUT gracefully")
Signed-off-by: default avatarShyam Prasad N <sprasad@microsoft.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent c071b34f
...@@ -60,7 +60,7 @@ extern bool disable_legacy_dialects; ...@@ -60,7 +60,7 @@ extern bool disable_legacy_dialects;
#define TLINK_IDLE_EXPIRE (600 * HZ) #define TLINK_IDLE_EXPIRE (600 * HZ)
/* Drop the connection to not overload the server */ /* Drop the connection to not overload the server */
#define NUM_STATUS_IO_TIMEOUT 5 #define MAX_STATUS_IO_TIMEOUT 5
static int ip_connect(struct TCP_Server_Info *server); static int ip_connect(struct TCP_Server_Info *server);
static int generic_ip_connect(struct TCP_Server_Info *server); static int generic_ip_connect(struct TCP_Server_Info *server);
...@@ -1117,6 +1117,7 @@ cifs_demultiplex_thread(void *p) ...@@ -1117,6 +1117,7 @@ cifs_demultiplex_thread(void *p)
struct mid_q_entry *mids[MAX_COMPOUND]; struct mid_q_entry *mids[MAX_COMPOUND];
char *bufs[MAX_COMPOUND]; char *bufs[MAX_COMPOUND];
unsigned int noreclaim_flag, num_io_timeout = 0; unsigned int noreclaim_flag, num_io_timeout = 0;
bool pending_reconnect = false;
noreclaim_flag = memalloc_noreclaim_save(); noreclaim_flag = memalloc_noreclaim_save();
cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current)); cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current));
...@@ -1156,6 +1157,8 @@ cifs_demultiplex_thread(void *p) ...@@ -1156,6 +1157,8 @@ cifs_demultiplex_thread(void *p)
cifs_dbg(FYI, "RFC1002 header 0x%x\n", pdu_length); cifs_dbg(FYI, "RFC1002 header 0x%x\n", pdu_length);
if (!is_smb_response(server, buf[0])) if (!is_smb_response(server, buf[0]))
continue; continue;
pending_reconnect = false;
next_pdu: next_pdu:
server->pdu_size = pdu_length; server->pdu_size = pdu_length;
...@@ -1213,10 +1216,13 @@ cifs_demultiplex_thread(void *p) ...@@ -1213,10 +1216,13 @@ cifs_demultiplex_thread(void *p)
if (server->ops->is_status_io_timeout && if (server->ops->is_status_io_timeout &&
server->ops->is_status_io_timeout(buf)) { server->ops->is_status_io_timeout(buf)) {
num_io_timeout++; num_io_timeout++;
if (num_io_timeout > NUM_STATUS_IO_TIMEOUT) { if (num_io_timeout > MAX_STATUS_IO_TIMEOUT) {
cifs_reconnect(server, false); cifs_server_dbg(VFS,
"Number of request timeouts exceeded %d. Reconnecting",
MAX_STATUS_IO_TIMEOUT);
pending_reconnect = true;
num_io_timeout = 0; num_io_timeout = 0;
continue;
} }
} }
...@@ -1268,6 +1274,11 @@ cifs_demultiplex_thread(void *p) ...@@ -1268,6 +1274,11 @@ cifs_demultiplex_thread(void *p)
buf = server->smallbuf; buf = server->smallbuf;
goto next_pdu; goto next_pdu;
} }
/* do this reconnect at the very end after processing all MIDs */
if (pending_reconnect)
cifs_reconnect(server, true);
} /* end while !EXITING */ } /* end while !EXITING */
/* buffer usually freed in free_mid - need to free it here on exit */ /* buffer usually freed in free_mid - need to free it here on exit */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment