Commit 3c1105df authored by Jeff Layton's avatar Jeff Layton Committed by Steve French

cifs: don't call mid_q_entry->callback under the Global_MidLock (try #5)

Minor revision to the last version of this patch -- the only difference
is the fix to the cFYI statement in cifs_reconnect.

Holding the spinlock while we call this function means that it can't
sleep, which really limits what it can do. Taking it out from under
the spinlock also means less contention for this global lock.

Change the semantics such that the Global_MidLock is not held when
the callback is called. To do this requires that we take extra care
not to have sync_mid_result remove the mid from the list when the
mid is in a state where that has already happened. This prevents
list corruption when the mid is sitting on a private list for
reconnect or when cifsd is coming down.
Reviewed-by: default avatarShirish Pargaonkar <shirishpargaonkar@gmail.com>
Reviewed-by: default avatarPavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent 724d9f1c
...@@ -543,9 +543,8 @@ struct mid_q_entry; ...@@ -543,9 +543,8 @@ struct mid_q_entry;
* This is the prototype for the mid callback function. When creating one, * This is the prototype for the mid callback function. When creating one,
* take special care to avoid deadlocks. Things to bear in mind: * take special care to avoid deadlocks. Things to bear in mind:
* *
* - it will be called by cifsd * - it will be called by cifsd, with no locks held
* - the GlobalMid_Lock will be held * - the mid will be removed from any lists
* - the mid will be removed from the pending_mid_q list
*/ */
typedef void (mid_callback_t)(struct mid_q_entry *mid); typedef void (mid_callback_t)(struct mid_q_entry *mid);
...@@ -656,6 +655,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param, ...@@ -656,6 +655,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
#define MID_RESPONSE_RECEIVED 4 #define MID_RESPONSE_RECEIVED 4
#define MID_RETRY_NEEDED 8 /* session closed while this request out */ #define MID_RETRY_NEEDED 8 /* session closed while this request out */
#define MID_RESPONSE_MALFORMED 0x10 #define MID_RESPONSE_MALFORMED 0x10
#define MID_SHUTDOWN 0x20
/* Types of response buffer returned from SendReceive2 */ /* Types of response buffer returned from SendReceive2 */
#define CIFS_NO_BUFFER 0 /* Response buffer not returned */ #define CIFS_NO_BUFFER 0 /* Response buffer not returned */
......
...@@ -137,6 +137,7 @@ cifs_reconnect(struct TCP_Server_Info *server) ...@@ -137,6 +137,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
struct cifsSesInfo *ses; struct cifsSesInfo *ses;
struct cifsTconInfo *tcon; struct cifsTconInfo *tcon;
struct mid_q_entry *mid_entry; struct mid_q_entry *mid_entry;
struct list_head retry_list;
spin_lock(&GlobalMid_Lock); spin_lock(&GlobalMid_Lock);
if (server->tcpStatus == CifsExiting) { if (server->tcpStatus == CifsExiting) {
...@@ -188,16 +189,23 @@ cifs_reconnect(struct TCP_Server_Info *server) ...@@ -188,16 +189,23 @@ cifs_reconnect(struct TCP_Server_Info *server)
mutex_unlock(&server->srv_mutex); mutex_unlock(&server->srv_mutex);
/* mark submitted MIDs for retry and issue callback */ /* mark submitted MIDs for retry and issue callback */
cFYI(1, "%s: issuing mid callbacks", __func__); INIT_LIST_HEAD(&retry_list);
cFYI(1, "%s: moving mids to private list", __func__);
spin_lock(&GlobalMid_Lock); spin_lock(&GlobalMid_Lock);
list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
mid_entry = list_entry(tmp, struct mid_q_entry, qhead); mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
if (mid_entry->midState == MID_REQUEST_SUBMITTED) if (mid_entry->midState == MID_REQUEST_SUBMITTED)
mid_entry->midState = MID_RETRY_NEEDED; mid_entry->midState = MID_RETRY_NEEDED;
list_move(&mid_entry->qhead, &retry_list);
}
spin_unlock(&GlobalMid_Lock);
cFYI(1, "%s: issuing mid callbacks", __func__);
list_for_each_safe(tmp, tmp2, &retry_list) {
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
list_del_init(&mid_entry->qhead); list_del_init(&mid_entry->qhead);
mid_entry->callback(mid_entry); mid_entry->callback(mid_entry);
} }
spin_unlock(&GlobalMid_Lock);
while (server->tcpStatus == CifsNeedReconnect) { while (server->tcpStatus == CifsNeedReconnect) {
try_to_freeze(); try_to_freeze();
...@@ -671,12 +679,12 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) ...@@ -671,12 +679,12 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
mid_entry->when_received = jiffies; mid_entry->when_received = jiffies;
#endif #endif
list_del_init(&mid_entry->qhead); list_del_init(&mid_entry->qhead);
mid_entry->callback(mid_entry);
break; break;
} }
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
if (mid_entry != NULL) { if (mid_entry != NULL) {
mid_entry->callback(mid_entry);
/* Was previous buf put in mpx struct for multi-rsp? */ /* Was previous buf put in mpx struct for multi-rsp? */
if (!isMultiRsp) { if (!isMultiRsp) {
/* smb buffer will be freed by user thread */ /* smb buffer will be freed by user thread */
...@@ -740,15 +748,25 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) ...@@ -740,15 +748,25 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
cifs_small_buf_release(smallbuf); cifs_small_buf_release(smallbuf);
if (!list_empty(&server->pending_mid_q)) { if (!list_empty(&server->pending_mid_q)) {
struct list_head dispose_list;
INIT_LIST_HEAD(&dispose_list);
spin_lock(&GlobalMid_Lock); spin_lock(&GlobalMid_Lock);
list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
mid_entry = list_entry(tmp, struct mid_q_entry, qhead); mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
cFYI(1, "Clearing Mid 0x%x - issuing callback", cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
mid_entry->mid); mid_entry->midState = MID_SHUTDOWN;
list_move(&mid_entry->qhead, &dispose_list);
}
spin_unlock(&GlobalMid_Lock);
/* now walk dispose list and issue callbacks */
list_for_each_safe(tmp, tmp2, &dispose_list) {
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
cFYI(1, "Callback mid 0x%x", mid_entry->mid);
list_del_init(&mid_entry->qhead); list_del_init(&mid_entry->qhead);
mid_entry->callback(mid_entry); mid_entry->callback(mid_entry);
} }
spin_unlock(&GlobalMid_Lock);
/* 1/8th of sec is more than enough time for them to exit */ /* 1/8th of sec is more than enough time for them to exit */
msleep(125); msleep(125);
} }
......
...@@ -426,7 +426,7 @@ SendReceiveNoRsp(const unsigned int xid, struct cifsSesInfo *ses, ...@@ -426,7 +426,7 @@ SendReceiveNoRsp(const unsigned int xid, struct cifsSesInfo *ses,
} }
static int static int
sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
{ {
int rc = 0; int rc = 0;
...@@ -434,28 +434,21 @@ sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) ...@@ -434,28 +434,21 @@ sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
mid->mid, mid->midState); mid->mid, mid->midState);
spin_lock(&GlobalMid_Lock); spin_lock(&GlobalMid_Lock);
/* ensure that it's no longer on the pending_mid_q */
list_del_init(&mid->qhead);
switch (mid->midState) { switch (mid->midState) {
case MID_RESPONSE_RECEIVED: case MID_RESPONSE_RECEIVED:
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
return rc; return rc;
case MID_REQUEST_SUBMITTED:
/* socket is going down, reject all calls */
if (server->tcpStatus == CifsExiting) {
cERROR(1, "%s: canceling mid=%d cmd=0x%x state=%d",
__func__, mid->mid, mid->command, mid->midState);
rc = -EHOSTDOWN;
break;
}
case MID_RETRY_NEEDED: case MID_RETRY_NEEDED:
rc = -EAGAIN; rc = -EAGAIN;
break; break;
case MID_RESPONSE_MALFORMED: case MID_RESPONSE_MALFORMED:
rc = -EIO; rc = -EIO;
break; break;
case MID_SHUTDOWN:
rc = -EHOSTDOWN;
break;
default: default:
list_del_init(&mid->qhead);
cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__, cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__,
mid->mid, mid->midState); mid->mid, mid->midState);
rc = -EIO; rc = -EIO;
...@@ -618,7 +611,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, ...@@ -618,7 +611,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
cifs_small_buf_release(in_buf); cifs_small_buf_release(in_buf);
rc = sync_mid_result(midQ, ses->server); rc = cifs_sync_mid_result(midQ, ses->server);
if (rc != 0) { if (rc != 0) {
atomic_dec(&ses->server->inFlight); atomic_dec(&ses->server->inFlight);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
...@@ -739,7 +732,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, ...@@ -739,7 +732,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
} }
rc = sync_mid_result(midQ, ses->server); rc = cifs_sync_mid_result(midQ, ses->server);
if (rc != 0) { if (rc != 0) {
atomic_dec(&ses->server->inFlight); atomic_dec(&ses->server->inFlight);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
...@@ -914,7 +907,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, ...@@ -914,7 +907,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
rstart = 1; rstart = 1;
} }
rc = sync_mid_result(midQ, ses->server); rc = cifs_sync_mid_result(midQ, ses->server);
if (rc != 0) if (rc != 0)
return rc; return rc;
......
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