Skip to content

Commit 84afc29

Browse files
author
Steve French
committed
[CIFS] Readpages and readir performance improvements - eliminate extra
memcpy. Part 1 Signed-off-by: Steve French <[email protected]>
1 parent bf82067 commit 84afc29

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

fs/cifs/CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Version 1.40
22
------------
3-
Use fsuid (fsgid) more consistently instead of uid (gid).
3+
Use fsuid (fsgid) more consistently instead of uid (gid). Improve performance
4+
of readpages by eliminating one extra memcpy.
45

56
Version 1.39
67
------------

fs/cifs/cifsencrypt.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* fs/cifs/cifsencrypt.c
33
*
4-
* Copyright (C) International Business Machines Corp., 2003
4+
* Copyright (C) International Business Machines Corp., 2005
55
* Author(s): Steve French ([email protected])
66
*
77
* This library is free software; you can redistribute it and/or modify
@@ -82,6 +82,59 @@ int cifs_sign_smb(struct smb_hdr * cifs_pdu, struct TCP_Server_Info * server,
8282
return rc;
8383
}
8484

85+
static int cifs_calc_signature2(const struct kvec * iov, int n_vec,
86+
const char * key, char * signature)
87+
{
88+
struct MD5Context context;
89+
90+
if((iov == NULL) || (signature == NULL))
91+
return -EINVAL;
92+
93+
MD5Init(&context);
94+
MD5Update(&context,key,CIFS_SESSION_KEY_SIZE+16);
95+
96+
/* MD5Update(&context,cifs_pdu->Protocol,cifs_pdu->smb_buf_length); */ /* BB FIXME BB */
97+
98+
MD5Final(signature,&context);
99+
100+
return -EOPNOTSUPP;
101+
/* return 0; */
102+
}
103+
104+
105+
int cifs_sign_smb2(struct kvec * iov, int n_vec, struct TCP_Server_Info *server,
106+
__u32 * pexpected_response_sequence_number)
107+
{
108+
int rc = 0;
109+
char smb_signature[20];
110+
struct smb_hdr * cifs_pdu = iov[0].iov_base;
111+
112+
if((cifs_pdu == NULL) || (server == NULL))
113+
return -EINVAL;
114+
115+
if((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
116+
return rc;
117+
118+
spin_lock(&GlobalMid_Lock);
119+
cifs_pdu->Signature.Sequence.SequenceNumber =
120+
cpu_to_le32(server->sequence_number);
121+
cifs_pdu->Signature.Sequence.Reserved = 0;
122+
123+
*pexpected_response_sequence_number = server->sequence_number++;
124+
server->sequence_number++;
125+
spin_unlock(&GlobalMid_Lock);
126+
127+
rc = cifs_calc_signature2(iov, n_vec, server->mac_signing_key,
128+
smb_signature);
129+
if(rc)
130+
memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
131+
else
132+
memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);
133+
134+
return rc;
135+
136+
}
137+
85138
int cifs_verify_signature(struct smb_hdr * cifs_pdu, const char * mac_key,
86139
__u32 expected_sequence_number)
87140
{

fs/cifs/cifsproto.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *,
4848
struct smb_hdr * /* out */ ,
4949
int * /* bytes returned */ , const int long_op);
5050
extern int SendReceive2(const unsigned int /* xid */ , struct cifsSesInfo *,
51-
struct kvec *, int /* nvec */,
51+
struct kvec *, int /* nvec to send */,
5252
int * /* bytes returned */ , const int long_op);
5353
extern int checkSMBhdr(struct smb_hdr *smb, __u16 mid);
5454
extern int checkSMB(struct smb_hdr *smb, __u16 mid, int length);
@@ -237,12 +237,10 @@ extern int CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
237237
const __u64 lseek, unsigned int *nbytes,
238238
const char *buf, const char __user *ubuf,
239239
const int long_op);
240-
#ifdef CONFIG_CIFS_EXPERIMENTAL
241240
extern int CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
242241
const int netfid, const unsigned int count,
243242
const __u64 offset, unsigned int *nbytes,
244243
struct kvec *iov, const int nvec, const int long_op);
245-
#endif /* CONFIG_CIFS_EXPERIMENTAL */
246244
extern int CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon,
247245
const unsigned char *searchName, __u64 * inode_number,
248246
const struct nls_table *nls_codepage,
@@ -269,6 +267,8 @@ extern void tconInfoFree(struct cifsTconInfo *);
269267
extern int cifs_reconnect(struct TCP_Server_Info *server);
270268

271269
extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *,__u32 *);
270+
extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
271+
__u32 *);
272272
extern int cifs_verify_signature(struct smb_hdr *, const char * mac_key,
273273
__u32 expected_sequence_number);
274274
extern int cifs_calculate_mac_key(char * key,const char * rn,const char * pass);

fs/cifs/cifssmb.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,6 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
11551155
return rc;
11561156
}
11571157

1158-
#ifdef CONFIG_CIFS_EXPERIMENTAL
11591158
int
11601159
CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
11611160
const int netfid, const unsigned int count,
@@ -1223,7 +1222,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
12231222
*nbytes = le16_to_cpu(pSMBr->CountHigh);
12241223
*nbytes = (*nbytes) << 16;
12251224
*nbytes += le16_to_cpu(pSMBr->Count);
1226-
}
1225+
}
12271226

12281227
cifs_small_buf_release(pSMB);
12291228

@@ -1234,8 +1233,6 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
12341233
}
12351234

12361235

1237-
#endif /* CIFS_EXPERIMENTAL */
1238-
12391236
int
12401237
CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
12411238
const __u16 smb_file_id, const __u64 len,

fs/cifs/file.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
870870
if (rc != 0)
871871
break;
872872
}
873-
#ifdef CONFIG_CIFS_EXPERIMENTAL
874873
/* BB FIXME We can not sign across two buffers yet */
875874
if((experimEnabled) && ((pTcon->ses->server->secMode &
876875
(SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) == 0)) {
@@ -889,7 +888,6 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
889888
iov, 1, long_op);
890889
} else
891890
/* BB FIXME fixup indentation of line below */
892-
#endif
893891
rc = CIFSSMBWrite(xid, pTcon,
894892
open_file->netfid,
895893
min_t(const int, cifs_sb->wsize,
@@ -1026,7 +1024,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
10261024
return rc;
10271025
}
10281026

1029-
#ifdef CONFIG_CIFS_EXPERIMENTAL
10301027
static int cifs_writepages(struct address_space *mapping,
10311028
struct writeback_control *wbc)
10321029
{
@@ -1229,7 +1226,6 @@ static int cifs_writepages(struct address_space *mapping,
12291226

12301227
return rc;
12311228
}
1232-
#endif
12331229

12341230
static int cifs_writepage(struct page* page, struct writeback_control *wbc)
12351231
{
@@ -1875,9 +1871,7 @@ struct address_space_operations cifs_addr_ops = {
18751871
.readpage = cifs_readpage,
18761872
.readpages = cifs_readpages,
18771873
.writepage = cifs_writepage,
1878-
#ifdef CONFIG_CIFS_EXPERIMENTAL
18791874
.writepages = cifs_writepages,
1880-
#endif
18811875
.prepare_write = cifs_prepare_write,
18821876
.commit_write = cifs_commit_write,
18831877
.set_page_dirty = __set_page_dirty_nobuffers,

fs/cifs/transport.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer,
206206
return rc;
207207
}
208208

209-
#ifdef CONFIG_CIFS_EXPERIMENTAL
210209
static int
211210
smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
212211
struct sockaddr *sin)
@@ -392,8 +391,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
392391
return -ENOMEM;
393392
}
394393

395-
/* BB FIXME */
396-
/* rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number); */
394+
rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number);
397395

398396
midQ->midState = MID_REQUEST_SUBMITTED;
399397
#ifdef CONFIG_CIFS_STATS2
@@ -492,11 +490,17 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
492490

493491
if (midQ->resp_buf &&
494492
(midQ->midState == MID_RESPONSE_RECEIVED)) {
493+
495494
in_buf->smb_buf_length = receive_len;
496-
/* BB verify that length would not overrun small buf */
497-
memcpy((char *)in_buf + 4,
498-
(char *)midQ->resp_buf + 4,
499-
receive_len);
495+
if(receive_len > 500) {
496+
/* use multiple buffers on way out */
497+
} else {
498+
memcpy((char *)in_buf + 4,
499+
(char *)midQ->resp_buf + 4,
500+
receive_len);
501+
iov[0].iov_len = receive_len + 4;
502+
iov[1].iov_len = 0;
503+
}
500504

501505
dump_smb(in_buf, 80);
502506
/* convert the length into a more usable form */
@@ -549,7 +553,6 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
549553

550554
return rc;
551555
}
552-
#endif /* CIFS_EXPERIMENTAL */
553556

554557
int
555558
SendReceive(const unsigned int xid, struct cifsSesInfo *ses,

0 commit comments

Comments
 (0)