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

CIFS: Prepare credits code for a slot reservation

that is essential for CIFS/SMB/SMB2 oplock breaks and SMB2 echos.
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 5bc59498
...@@ -315,12 +315,22 @@ in_flight(struct TCP_Server_Info *server) ...@@ -315,12 +315,22 @@ in_flight(struct TCP_Server_Info *server)
return num; return num;
} }
static inline int*
get_credits_field(struct TCP_Server_Info *server)
{
/*
* This will change to switch statement when we reserve slots for echos
* and oplock breaks.
*/
return &server->credits;
}
static inline bool static inline bool
has_credits(struct TCP_Server_Info *server) has_credits(struct TCP_Server_Info *server, int *credits)
{ {
int num; int num;
spin_lock(&server->req_lock); spin_lock(&server->req_lock);
num = server->credits; num = *credits;
spin_unlock(&server->req_lock); spin_unlock(&server->req_lock);
return num > 0; return num > 0;
} }
......
...@@ -255,26 +255,26 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, ...@@ -255,26 +255,26 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
} }
static int static int
wait_for_free_request(struct TCP_Server_Info *server, const int long_op) wait_for_free_credits(struct TCP_Server_Info *server, const int optype,
int *credits)
{ {
int rc; int rc;
spin_lock(&server->req_lock); spin_lock(&server->req_lock);
if (optype == CIFS_ASYNC_OP) {
if (long_op == CIFS_ASYNC_OP) {
/* oplock breaks must not be held up */ /* oplock breaks must not be held up */
server->in_flight++; server->in_flight++;
server->credits--; *credits -= 1;
spin_unlock(&server->req_lock); spin_unlock(&server->req_lock);
return 0; return 0;
} }
while (1) { while (1) {
if (server->credits <= 0) { if (*credits <= 0) {
spin_unlock(&server->req_lock); spin_unlock(&server->req_lock);
cifs_num_waiters_inc(server); cifs_num_waiters_inc(server);
rc = wait_event_killable(server->request_q, rc = wait_event_killable(server->request_q,
has_credits(server)); has_credits(server, credits));
cifs_num_waiters_dec(server); cifs_num_waiters_dec(server);
if (rc) if (rc)
return rc; return rc;
...@@ -291,8 +291,8 @@ wait_for_free_request(struct TCP_Server_Info *server, const int long_op) ...@@ -291,8 +291,8 @@ wait_for_free_request(struct TCP_Server_Info *server, const int long_op)
*/ */
/* update # of requests on the wire to server */ /* update # of requests on the wire to server */
if (long_op != CIFS_BLOCKING_OP) { if (optype != CIFS_BLOCKING_OP) {
server->credits--; *credits -= 1;
server->in_flight++; server->in_flight++;
} }
spin_unlock(&server->req_lock); spin_unlock(&server->req_lock);
...@@ -302,6 +302,12 @@ wait_for_free_request(struct TCP_Server_Info *server, const int long_op) ...@@ -302,6 +302,12 @@ wait_for_free_request(struct TCP_Server_Info *server, const int long_op)
return 0; return 0;
} }
static int
wait_for_free_request(struct TCP_Server_Info *server, const int optype)
{
return wait_for_free_credits(server, optype, get_credits_field(server));
}
static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf, static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
struct mid_q_entry **ppmidQ) struct mid_q_entry **ppmidQ)
{ {
......
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