Skip to content

Commit ec2e452

Browse files
committed
CIFS: Add capability to send SMB2 negotiate message
and add negotiate request type to let set_credits know that we are only on negotiate stage and no need to make a decision about disabling echos and oplocks. Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru> Signed-off-by: Steve French <smfrench@gmail.com>
1 parent 3792c17 commit ec2e452

8 files changed

Lines changed: 417 additions & 11 deletions

File tree

‎fs/cifs/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
1616

1717
cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
1818

19-
cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o smb2misc.o
19+
cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \
20+
smb2misc.o smb2pdu.o

‎fs/cifs/cifsglob.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ get_rfc1002_length(void *buf)
313313
return be32_to_cpu(*((__be32 *)buf));
314314
}
315315

316+
static inline void
317+
inc_rfc1001_len(void *buf, int count)
318+
{
319+
be32_add_cpu((__be32 *)buf, count);
320+
}
321+
316322
struct TCP_Server_Info {
317323
struct list_head tcp_ses_list;
318324
struct list_head smb_ses_list;
@@ -393,6 +399,10 @@ struct TCP_Server_Info {
393399
atomic_t in_send; /* requests trying to send */
394400
atomic_t num_waiters; /* blocked waiting to get in sendrecv */
395401
#endif
402+
#ifdef CONFIG_CIFS_SMB2
403+
unsigned int max_read;
404+
unsigned int max_write;
405+
#endif /* CONFIG_CIFS_SMB2 */
396406
};
397407

398408
static inline unsigned int
@@ -986,7 +996,8 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
986996
/* Type of request operation */
987997
#define CIFS_ECHO_OP 0x080 /* echo request */
988998
#define CIFS_OBREAK_OP 0x0100 /* oplock break request */
989-
#define CIFS_OP_MASK 0x0180 /* mask request type */
999+
#define CIFS_NEG_OP 0x0200 /* negotiate request */
1000+
#define CIFS_OP_MASK 0x0380 /* mask request type */
9901001

9911002
/* Security Flags: indicate type of session setup needed */
9921003
#define CIFSSEC_MAY_SIGN 0x00001

‎fs/cifs/cifssmb.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,6 @@ static int validate_t2(struct smb_t2_rsp *pSMB)
388388
return -EINVAL;
389389
}
390390

391-
static inline void inc_rfc1001_len(void *pSMB, int count)
392-
{
393-
struct smb_hdr *hdr = (struct smb_hdr *)pSMB;
394-
395-
be32_add_cpu(&hdr->smb_buf_length, count);
396-
}
397-
398391
int
399392
CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses)
400393
{

‎fs/cifs/smb2misc.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static const bool has_smb2_data_area[NUMBER_OF_SMB2_COMMANDS] = {
199199
* Returns the pointer to the beginning of the data area. Length of the data
200200
* area and the offset to it (from the beginning of the smb are also returned.
201201
*/
202-
static char *
202+
char *
203203
smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
204204
{
205205
*off = 0;
@@ -218,6 +218,11 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
218218
*/
219219
switch (hdr->Command) {
220220
case SMB2_NEGOTIATE:
221+
*off = le16_to_cpu(
222+
((struct smb2_negotiate_rsp *)hdr)->SecurityBufferOffset);
223+
*len = le16_to_cpu(
224+
((struct smb2_negotiate_rsp *)hdr)->SecurityBufferLength);
225+
break;
221226
case SMB2_SESSION_SETUP:
222227
case SMB2_CREATE:
223228
case SMB2_READ:

‎fs/cifs/smb2ops.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
6161
val = server->ops->get_credits_field(server, optype);
6262
*val += add;
6363
server->in_flight--;
64-
if (server->in_flight == 0)
64+
if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
6565
rc = change_conf(server);
6666
spin_unlock(&server->req_lock);
6767
wake_up(&server->request_q);
@@ -139,6 +139,24 @@ smb2_dump_detail(void *buf)
139139
#endif
140140
}
141141

142+
static bool
143+
smb2_need_neg(struct TCP_Server_Info *server)
144+
{
145+
return server->max_read == 0;
146+
}
147+
148+
static int
149+
smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
150+
{
151+
int rc;
152+
ses->server->CurrentMid = 0;
153+
rc = SMB2_negotiate(xid, ses);
154+
/* BB we probably don't need to retry with modern servers */
155+
if (rc == -EAGAIN)
156+
rc = -EHOSTDOWN;
157+
return rc;
158+
}
159+
142160
struct smb_version_operations smb21_operations = {
143161
.setup_request = smb2_setup_request,
144162
.check_receive = smb2_check_receive,
@@ -150,6 +168,8 @@ struct smb_version_operations smb21_operations = {
150168
.find_mid = smb2_find_mid,
151169
.check_message = smb2_check_message,
152170
.dump_detail = smb2_dump_detail,
171+
.need_neg = smb2_need_neg,
172+
.negotiate = smb2_negotiate,
153173
};
154174

155175
struct smb_version_values smb21_values = {

0 commit comments

Comments
 (0)