bool noblocksnd; /* use blocking sendmsg */
bool noautotune; /* do not autotune send buf sizes */
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 task_struct *tsk;
char server_GUID[16];
#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
* when CONFIG_NET_NS isn't set.
wake_up_all(&server->response_q);
/* Check if we have blocked requests that need to free. */
- spin_lock(&GlobalMid_Lock);
- if (atomic_read(&server->inFlight) >= server->maxReq)
- atomic_set(&server->inFlight, server->maxReq - 1);
+ spin_lock(&server->req_lock);
+ if (server->in_flight >= server->maxReq)
+ server->in_flight = server->maxReq - 1;
/*
* We do not want to set the max_pending too low or we could end up
* 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
* can not hurt to be paranoid and try to wake up requests that may
tcp_ses->noblocksnd = volume_info->noblocksnd;
tcp_ses->noautotune = volume_info->noautotune;
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 */
init_waitqueue_head(&tcp_ses->response_q);
init_waitqueue_head(&tcp_ses->request_q);
return smb_sendv(server, &iov, 1);
}
-static int wait_for_free_request(struct TCP_Server_Info *server,
- const int long_op)
+static int
+wait_for_free_request(struct TCP_Server_Info *server, const int long_op)
{
+ spin_lock(&server->req_lock);
+
if (long_op == CIFS_ASYNC_OP) {
/* oplock breaks must not be held up */
- atomic_inc(&server->inFlight);
+ server->in_flight++;
+ spin_unlock(&server->req_lock);
return 0;
}
- spin_lock(&GlobalMid_Lock);
while (1) {
- if (atomic_read(&server->inFlight) >= server->maxReq) {
- spin_unlock(&GlobalMid_Lock);
+ if (server->in_flight >= server->maxReq) {
+ spin_unlock(&server->req_lock);
cifs_num_waiters_inc(server);
wait_event(server->request_q,
- atomic_read(&server->inFlight)
- < server->maxReq);
+ in_flight(server) < server->maxReq);
cifs_num_waiters_dec(server);
- spin_lock(&GlobalMid_Lock);
+ spin_lock(&server->req_lock);
} else {
if (server->tcpStatus == CifsExiting) {
- spin_unlock(&GlobalMid_Lock);
+ spin_unlock(&server->req_lock);
return -ENOENT;
}
/* update # of requests on the wire to server */
if (long_op != CIFS_BLOCKING_OP)
- atomic_inc(&server->inFlight);
- spin_unlock(&GlobalMid_Lock);
+ server->in_flight++;
+ spin_unlock(&server->req_lock);
break;
}
}
mid = AllocMidQEntry(hdr, server);
if (mid == NULL) {
mutex_unlock(&server->srv_mutex);
- atomic_dec(&server->inFlight);
+ dec_in_flight(server);
wake_up(&server->request_q);
return -ENOMEM;
}
return rc;
out_err:
delete_mid(mid);
- atomic_dec(&server->inFlight);
+ dec_in_flight(server);
wake_up(&server->request_q);
return rc;
}
mutex_unlock(&ses->server->srv_mutex);
cifs_small_buf_release(in_buf);
/* Update # of requests on wire to server */
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
}
midQ->callback = DeleteMidQEntry;
spin_unlock(&GlobalMid_Lock);
cifs_small_buf_release(in_buf);
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
}
rc = cifs_sync_mid_result(midQ, ses->server);
if (rc != 0) {
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
}
midQ->resp_buf = NULL;
out:
delete_mid(midQ);
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
if (rc) {
mutex_unlock(&ses->server->srv_mutex);
/* Update # of requests on wire to server */
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
}
/* no longer considered to be "in-flight" */
midQ->callback = DeleteMidQEntry;
spin_unlock(&GlobalMid_Lock);
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
}
rc = cifs_sync_mid_result(midQ, ses->server);
if (rc != 0) {
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;
}
rc = cifs_check_receive(midQ, ses->server, 0);
out:
delete_mid(midQ);
- atomic_dec(&ses->server->inFlight);
+ dec_in_flight(ses->server);
wake_up(&ses->server->request_q);
return rc;