Skip to content

Commit

Permalink
CIFS: Extend credit mechanism to process request type
Browse files Browse the repository at this point in the history
Split all requests to echos, oplocks and others - each group uses
its own credit slot. This is indicated by new flags

CIFS_ECHO_OP and CIFS_OBREAK_OP

that are not used now for CIFS. This change is required to support
SMB2 protocol because of different processing of these commands.

Acked-by: Jeff Layton <[email protected]>
Signed-off-by: Pavel Shilovsky <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
piastry authored and smfrench committed Jul 24, 2012
1 parent 316cf94 commit a891f0f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 49 deletions.
16 changes: 12 additions & 4 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ struct smb_version_operations {
/* check response: verify signature, map error */
int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *,
bool);
void (*add_credits)(struct TCP_Server_Info *, const unsigned int);
void (*add_credits)(struct TCP_Server_Info *, const unsigned int,
const int);
void (*set_credits)(struct TCP_Server_Info *, const int);
int * (*get_credits_field)(struct TCP_Server_Info *);
int * (*get_credits_field)(struct TCP_Server_Info *, const int);
unsigned int (*get_credits)(struct mid_q_entry *);
__u64 (*get_next_mid)(struct TCP_Server_Info *);
/* data offset from read response message */
unsigned int (*read_data_offset)(char *);
Expand Down Expand Up @@ -392,9 +394,10 @@ has_credits(struct TCP_Server_Info *server, int *credits)
}

static inline void
add_credits(struct TCP_Server_Info *server, const unsigned int add)
add_credits(struct TCP_Server_Info *server, const unsigned int add,
const int optype)
{
server->ops->add_credits(server, add);
server->ops->add_credits(server, add, optype);
}

static inline void
Expand Down Expand Up @@ -957,6 +960,11 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */
#define CIFS_NO_RESP 0x040 /* no response buffer required */

/* Type of request operation */
#define CIFS_ECHO_OP 0x080 /* echo request */
#define CIFS_OBREAK_OP 0x0100 /* oplock break request */
#define CIFS_OP_MASK 0x0180 /* mask request type */

/* Security Flags: indicate type of session setup needed */
#define CIFSSEC_MAY_SIGN 0x00001
#define CIFSSEC_MAY_NTLM 0x00002
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/cifsproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ extern void DeleteMidQEntry(struct mid_q_entry *midEntry);
extern int cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
unsigned int nvec, mid_receive_t *receive,
mid_callback_t *callback, void *cbdata,
bool ignore_pend);
const int flags);
extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
struct smb_hdr * /* input */ ,
struct smb_hdr * /* out */ ,
int * /* bytes returned */ , const int long_op);
int * /* bytes returned */ , const int);
extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
char *in_buf, int flags);
extern int cifs_setup_request(struct cifs_ses *, struct kvec *, unsigned int,
Expand Down
21 changes: 11 additions & 10 deletions fs/cifs/cifssmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ cifs_echo_callback(struct mid_q_entry *mid)
struct TCP_Server_Info *server = mid->callback_data;

DeleteMidQEntry(mid);
add_credits(server, 1);
add_credits(server, 1, CIFS_ECHO_OP);
}

int
Expand All @@ -771,7 +771,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4;

rc = cifs_call_async(server, &iov, 1, NULL, cifs_echo_callback,
server, true);
server, CIFS_ASYNC_OP | CIFS_ECHO_OP);
if (rc)
cFYI(1, "Echo request failed: %d", rc);

Expand Down Expand Up @@ -1589,7 +1589,7 @@ cifs_readv_callback(struct mid_q_entry *mid)

queue_work(cifsiod_wq, &rdata->work);
DeleteMidQEntry(mid);
add_credits(server, 1);
add_credits(server, 1, 0);
}

/* cifs_async_readv - send an async write, and set up mid to handle result */
Expand Down Expand Up @@ -1645,7 +1645,7 @@ cifs_async_readv(struct cifs_readdata *rdata)
kref_get(&rdata->refcount);
rc = cifs_call_async(tcon->ses->server, rdata->iov, 1,
cifs_readv_receive, cifs_readv_callback,
rdata, false);
rdata, 0);

if (rc == 0)
cifs_stats_inc(&tcon->num_reads);
Expand Down Expand Up @@ -2036,7 +2036,7 @@ cifs_writev_callback(struct mid_q_entry *mid)

queue_work(cifsiod_wq, &wdata->work);
DeleteMidQEntry(mid);
add_credits(tcon->ses->server, 1);
add_credits(tcon->ses->server, 1, 0);
}

/* cifs_async_writev - send an async write, and set up mid to handle result */
Expand Down Expand Up @@ -2118,7 +2118,7 @@ cifs_async_writev(struct cifs_writedata *wdata)

kref_get(&wdata->refcount);
rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1,
NULL, cifs_writev_callback, wdata, false);
NULL, cifs_writev_callback, wdata, 0);

if (rc == 0)
cifs_stats_inc(&tcon->num_writes);
Expand Down Expand Up @@ -2296,7 +2296,7 @@ CIFSSMBLock(const int xid, struct cifs_tcon *tcon,
LOCK_REQ *pSMB = NULL;
/* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
int bytes_returned;
int timeout = 0;
int flags = 0;
__u16 count;

cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock);
Expand All @@ -2306,10 +2306,11 @@ CIFSSMBLock(const int xid, struct cifs_tcon *tcon,
return rc;

if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) {
timeout = CIFS_ASYNC_OP; /* no response expected */
/* no response expected */
flags = CIFS_ASYNC_OP | CIFS_OBREAK_OP;
pSMB->Timeout = 0;
} else if (waitFlag) {
timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */
flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */
pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */
} else {
pSMB->Timeout = 0;
Expand Down Expand Up @@ -2342,7 +2343,7 @@ CIFSSMBLock(const int xid, struct cifs_tcon *tcon,
(struct smb_hdr *) pSMB, &bytes_returned);
cifs_small_buf_release(pSMB);
} else {
rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, timeout);
rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags);
/* SMB buffer freed by function above */
}
cifs_stats_inc(&tcon->num_locks);
Expand Down
12 changes: 10 additions & 2 deletions fs/cifs/smb1ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer)
}

static void
cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add)
cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add,
const int optype)
{
spin_lock(&server->req_lock);
server->credits += add;
Expand All @@ -120,11 +121,17 @@ cifs_set_credits(struct TCP_Server_Info *server, const int val)
}

static int *
cifs_get_credits_field(struct TCP_Server_Info *server)
cifs_get_credits_field(struct TCP_Server_Info *server, const int optype)
{
return &server->credits;
}

static unsigned int
cifs_get_credits(struct mid_q_entry *mid)
{
return 1;
}

/*
* Find a free multiplex id (SMB mid). Otherwise there could be
* mid collisions which might cause problems, demultiplexing the
Expand Down Expand Up @@ -390,6 +397,7 @@ struct smb_version_operations smb1_operations = {
.add_credits = cifs_add_credits,
.set_credits = cifs_set_credits,
.get_credits_field = cifs_get_credits_field,
.get_credits = cifs_get_credits,
.get_next_mid = cifs_get_next_mid,
.read_data_offset = cifs_read_data_offset,
.read_data_length = cifs_read_data_length,
Expand Down
Loading

0 comments on commit a891f0f

Please sign in to comment.