Commit fc40f9cf authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Steve French

CIFS: Simplify inFlight logic

by making it as unsigned integer and surround access with req_lock
from server structure.
Reviewed-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarPavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent 1daaae8f
...@@ -171,8 +171,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) ...@@ -171,8 +171,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
seq_printf(m, "TCP status: %d\n\tLocal Users To " seq_printf(m, "TCP status: %d\n\tLocal Users To "
"Server: %d SecMode: 0x%x Req On Wire: %d", "Server: %d SecMode: 0x%x Req On Wire: %d",
server->tcpStatus, server->srv_count, server->tcpStatus, server->srv_count,
server->sec_mode, server->sec_mode, in_flight(server));
atomic_read(&server->inFlight));
#ifdef CONFIG_CIFS_STATS2 #ifdef CONFIG_CIFS_STATS2
seq_printf(m, " In Send: %d In MaxReq Wait: %d", seq_printf(m, " In Send: %d In MaxReq Wait: %d",
......
...@@ -250,7 +250,8 @@ struct TCP_Server_Info { ...@@ -250,7 +250,8 @@ struct TCP_Server_Info {
bool noblocksnd; /* use blocking sendmsg */ bool noblocksnd; /* use blocking sendmsg */
bool noautotune; /* do not autotune send buf sizes */ bool noautotune; /* do not autotune send buf sizes */
bool tcp_nodelay; bool tcp_nodelay;
atomic_t inFlight; /* number of requests on the wire to server */ unsigned int in_flight; /* number of requests on the wire to server */
spinlock_t req_lock; /* protect the value above */
struct mutex srv_mutex; struct mutex srv_mutex;
struct task_struct *tsk; struct task_struct *tsk;
char server_GUID[16]; char server_GUID[16];
...@@ -303,6 +304,24 @@ struct TCP_Server_Info { ...@@ -303,6 +304,24 @@ struct TCP_Server_Info {
#endif #endif
}; };
static inline unsigned int
in_flight(struct TCP_Server_Info *server)
{
unsigned int num;
spin_lock(&server->req_lock);
num = server->in_flight;
spin_unlock(&server->req_lock);
return num;
}
static inline void
dec_in_flight(struct TCP_Server_Info *server)
{
spin_lock(&server->req_lock);
server->in_flight--;
spin_unlock(&server->req_lock);
}
/* /*
* Macros to allow the TCP_Server_Info->net field and related code to drop out * Macros to allow the TCP_Server_Info->net field and related code to drop out
* when CONFIG_NET_NS isn't set. * when CONFIG_NET_NS isn't set.
......
...@@ -721,7 +721,7 @@ cifs_echo_callback(struct mid_q_entry *mid) ...@@ -721,7 +721,7 @@ cifs_echo_callback(struct mid_q_entry *mid)
struct TCP_Server_Info *server = mid->callback_data; struct TCP_Server_Info *server = mid->callback_data;
DeleteMidQEntry(mid); DeleteMidQEntry(mid);
atomic_dec(&server->inFlight); dec_in_flight(server);
wake_up(&server->request_q); wake_up(&server->request_q);
} }
...@@ -1674,7 +1674,7 @@ cifs_readv_callback(struct mid_q_entry *mid) ...@@ -1674,7 +1674,7 @@ cifs_readv_callback(struct mid_q_entry *mid)
queue_work(system_nrt_wq, &rdata->work); queue_work(system_nrt_wq, &rdata->work);
DeleteMidQEntry(mid); DeleteMidQEntry(mid);
atomic_dec(&server->inFlight); dec_in_flight(server);
wake_up(&server->request_q); wake_up(&server->request_q);
} }
...@@ -2115,7 +2115,7 @@ cifs_writev_callback(struct mid_q_entry *mid) ...@@ -2115,7 +2115,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
queue_work(system_nrt_wq, &wdata->work); queue_work(system_nrt_wq, &wdata->work);
DeleteMidQEntry(mid); DeleteMidQEntry(mid);
atomic_dec(&tcon->ses->server->inFlight); dec_in_flight(tcon->ses->server);
wake_up(&tcon->ses->server->request_q); wake_up(&tcon->ses->server->request_q);
} }
......
...@@ -643,14 +643,14 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) ...@@ -643,14 +643,14 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
wake_up_all(&server->response_q); wake_up_all(&server->response_q);
/* Check if we have blocked requests that need to free. */ /* Check if we have blocked requests that need to free. */
spin_lock(&GlobalMid_Lock); spin_lock(&server->req_lock);
if (atomic_read(&server->inFlight) >= server->maxReq) if (server->in_flight >= server->maxReq)
atomic_set(&server->inFlight, server->maxReq - 1); server->in_flight = server->maxReq - 1;
/* /*
* We do not want to set the max_pending too low or we could end up * We do not want to set the max_pending too low or we could end up
* with the counter going negative. * with the counter going negative.
*/ */
spin_unlock(&GlobalMid_Lock); spin_unlock(&server->req_lock);
/* /*
* Although there should not be any requests blocked on this queue it * Although there should not be any requests blocked on this queue it
* can not hurt to be paranoid and try to wake up requests that may * can not hurt to be paranoid and try to wake up requests that may
...@@ -1905,7 +1905,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) ...@@ -1905,7 +1905,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
tcp_ses->noblocksnd = volume_info->noblocksnd; tcp_ses->noblocksnd = volume_info->noblocksnd;
tcp_ses->noautotune = volume_info->noautotune; tcp_ses->noautotune = volume_info->noautotune;
tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay; tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay;
atomic_set(&tcp_ses->inFlight, 0); tcp_ses->in_flight = 0;
tcp_ses->maxReq = 1; /* enough to send negotiate request */ tcp_ses->maxReq = 1; /* enough to send negotiate request */
init_waitqueue_head(&tcp_ses->response_q); init_waitqueue_head(&tcp_ses->response_q);
init_waitqueue_head(&tcp_ses->request_q); init_waitqueue_head(&tcp_ses->request_q);
......
...@@ -254,28 +254,29 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, ...@@ -254,28 +254,29 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
return smb_sendv(server, &iov, 1); return smb_sendv(server, &iov, 1);
} }
static int wait_for_free_request(struct TCP_Server_Info *server, static int
const int long_op) wait_for_free_request(struct TCP_Server_Info *server, const int long_op)
{ {
spin_lock(&server->req_lock);
if (long_op == CIFS_ASYNC_OP) { if (long_op == CIFS_ASYNC_OP) {
/* oplock breaks must not be held up */ /* oplock breaks must not be held up */
atomic_inc(&server->inFlight); server->in_flight++;
spin_unlock(&server->req_lock);
return 0; return 0;
} }
spin_lock(&GlobalMid_Lock);
while (1) { while (1) {
if (atomic_read(&server->inFlight) >= server->maxReq) { if (server->in_flight >= server->maxReq) {
spin_unlock(&GlobalMid_Lock); spin_unlock(&server->req_lock);
cifs_num_waiters_inc(server); cifs_num_waiters_inc(server);
wait_event(server->request_q, wait_event(server->request_q,
atomic_read(&server->inFlight) in_flight(server) < server->maxReq);
< server->maxReq);
cifs_num_waiters_dec(server); cifs_num_waiters_dec(server);
spin_lock(&GlobalMid_Lock); spin_lock(&server->req_lock);
} else { } else {
if (server->tcpStatus == CifsExiting) { if (server->tcpStatus == CifsExiting) {
spin_unlock(&GlobalMid_Lock); spin_unlock(&server->req_lock);
return -ENOENT; return -ENOENT;
} }
...@@ -284,8 +285,8 @@ static int wait_for_free_request(struct TCP_Server_Info *server, ...@@ -284,8 +285,8 @@ static int wait_for_free_request(struct TCP_Server_Info *server,
/* update # of requests on the wire to server */ /* update # of requests on the wire to server */
if (long_op != CIFS_BLOCKING_OP) if (long_op != CIFS_BLOCKING_OP)
atomic_inc(&server->inFlight); server->in_flight++;
spin_unlock(&GlobalMid_Lock); spin_unlock(&server->req_lock);
break; break;
} }
} }
...@@ -359,7 +360,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, ...@@ -359,7 +360,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
mid = AllocMidQEntry(hdr, server); mid = AllocMidQEntry(hdr, server);
if (mid == NULL) { if (mid == NULL) {
mutex_unlock(&server->srv_mutex); mutex_unlock(&server->srv_mutex);
atomic_dec(&server->inFlight); dec_in_flight(server);
wake_up(&server->request_q); wake_up(&server->request_q);
return -ENOMEM; return -ENOMEM;
} }
...@@ -392,7 +393,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, ...@@ -392,7 +393,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
return rc; return rc;
out_err: out_err:
delete_mid(mid); delete_mid(mid);
atomic_dec(&server->inFlight); dec_in_flight(server);
wake_up(&server->request_q); wake_up(&server->request_q);
return rc; return rc;
} }
...@@ -564,7 +565,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, ...@@ -564,7 +565,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
mutex_unlock(&ses->server->srv_mutex); mutex_unlock(&ses->server->srv_mutex);
cifs_small_buf_release(in_buf); cifs_small_buf_release(in_buf);
/* Update # of requests on wire to server */ /* Update # of requests on wire to server */
atomic_dec(&ses->server->inFlight); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
} }
...@@ -601,7 +602,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, ...@@ -601,7 +602,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
midQ->callback = DeleteMidQEntry; midQ->callback = DeleteMidQEntry;
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
cifs_small_buf_release(in_buf); cifs_small_buf_release(in_buf);
atomic_dec(&ses->server->inFlight); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
} }
...@@ -612,7 +613,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, ...@@ -612,7 +613,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
rc = cifs_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); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
} }
...@@ -637,7 +638,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, ...@@ -637,7 +638,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
midQ->resp_buf = NULL; midQ->resp_buf = NULL;
out: out:
delete_mid(midQ); delete_mid(midQ);
atomic_dec(&ses->server->inFlight); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
...@@ -688,7 +689,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, ...@@ -688,7 +689,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
if (rc) { if (rc) {
mutex_unlock(&ses->server->srv_mutex); mutex_unlock(&ses->server->srv_mutex);
/* Update # of requests on wire to server */ /* Update # of requests on wire to server */
atomic_dec(&ses->server->inFlight); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
} }
...@@ -721,7 +722,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, ...@@ -721,7 +722,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
/* no longer considered to be "in-flight" */ /* no longer considered to be "in-flight" */
midQ->callback = DeleteMidQEntry; midQ->callback = DeleteMidQEntry;
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
atomic_dec(&ses->server->inFlight); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
} }
...@@ -730,7 +731,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, ...@@ -730,7 +731,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
rc = cifs_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); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
return rc; return rc;
} }
...@@ -747,7 +748,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, ...@@ -747,7 +748,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
rc = cifs_check_receive(midQ, ses->server, 0); rc = cifs_check_receive(midQ, ses->server, 0);
out: out:
delete_mid(midQ); delete_mid(midQ);
atomic_dec(&ses->server->inFlight); dec_in_flight(ses->server);
wake_up(&ses->server->request_q); wake_up(&ses->server->request_q);
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