cifs: convert async write and read code to use less kmapping
Subsystems (2)
v3 cover cifs: convert async write and read code to use less kmapping
This is the third version of this series. The main differences are:
1) fix up merge conflicts with Steve's for-next tree, mostly due to the merge of more SMB2 patches.
2) the async read code has been converted not to do as much kmapping
We currently have a problem with the async write code on CONFIG_HIGHMEM architectures. It uses *way* too much kmap space. Not only does this limit throughput by adding an artificial bottleneck, but can lead to deadlocks.
This patchset fixes this by making the code not kmap an entire array of pages before attempting to send and receive it. Instead, pages are dealt with one at a time so we only generally will have a single kmap in play at a time.
I've tested this numerous ways and it seems to work as expected. Pavel reviewed an earlier series. Some of these patches have seen some changes but I've left his Reviewed-by's in place. Let me know if you want to withdraw them.
It's probably too late now for the 3.6 merge window, but I'd like to see this go into linux-next very soon so that it's ready for merge in 3.7.
Jeff Layton (15):
cifs: change signing routines to deal with smb_rqst structs
cifs: change smb2 signing routines to use smb_rqst structs
cifs: convert send code to use smb_rqst structs
cifs: cork the socket before a send and uncork it afterward
cifs: teach smb_send_rqst how to handle arrays of pages
cifs: teach signing routines how to deal with arrays of pages in a
smb_rqst
cifs: change cifs_call_async to use smb_rqst structs
cifs: convert async write code to pass in data via rq_pages array
cifs: remove the kmap size limit from wsize
cifs: add deprecation warning to sockopt=TCP_NODELAY option
cifs: allocate kvec array for cifs_readdata as a separate allocation
cifs: turn the pages list in cifs_readdata into an array
cifs: convert async read code to use pages array without kmapping
cifs: replace kvec array in readdata with a single kvec
cifs: remove kmap lock and rsize limit
fs/cifs/cifsencrypt.c | 37 +++++-- fs/cifs/cifsfs.c | 4 - fs/cifs/cifsglob.h | 78 ++++++--------- fs/cifs/cifsproto.h | 25 +++-- fs/cifs/cifssmb.c | 106 +++++++++----------- fs/cifs/connect.c | 7 +- fs/cifs/file.c | 253 ++++++++++++++++++++++------------------------- fs/cifs/smb1ops.c | 6 -- fs/cifs/smb2ops.c | 6 -- fs/cifs/smb2pdu.c | 65 ++++++------ fs/cifs/smb2proto.h | 13 ++- fs/cifs/smb2transport.c | 83 ++++++++-------- fs/cifs/transport.c | 255 ++++++++++++++++++++++++++++++++++-------------- 13 files changed, 503 insertions(+), 435 deletions(-)
Signature · 1 line
1.7.11.2
PATCH v3 1/15 cifs: change signing routines to deal with smb_rqst structs
In reply to a message not in the archiveWe need a way to represent a call to be sent on the wire that does not require having all of the page data kmapped. Behold the smb_rqst struct. This new struct represents an array of kvecs immediately followed by an array of pages.
Convert the signing routines to use these structs under the hood and turn the existing functions for this into wrappers around that. For now, we're just changing these functions to take different args. Later, we'll teach them how to deal with arrays of pages.
--- fs/cifs/cifsencrypt.c | 26 ++++++++++++++++++-------- fs/cifs/cifsglob.h | 14 ++++++++++++++ fs/cifs/cifsproto.h | 7 +++++-- fs/cifs/cifssmb.c | 7 ++++--- fs/cifs/transport.c | 4 +++- 5 files changed, 44 insertions(+), 14 deletions(-)
fs/cifs/cifsencrypt.c +18 -8
@@ -37,11 +37,13 @@* the sequence number before this function is called. Also, this function * should be called with the server->srv_mutex held. */ -static int cifs_calc_signature (const struct kvec *iov,int n_vec, +static int cifs_calc_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,char *signature) {int i;int rc; +struct kvec *iov = rqst->rq_iov; +int n_vec = rqst->rq_nvec;if (iov ==NULL || signature ==NULL || server ==NULL )return -EINVAL ;
@@ -99,12 +101,12 @@ static int cifs_calc_signature(const struct kvec *iov, int n_vec, }/* must be called with server->srv_mutex held */ -int cifs_sign_smbv (struct kvec *iov,int n_vec,struct TCP_Server_Info *server, +int cifs_sign_rqst (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number) {int rc =0 ;char smb_signature[20 ]; -struct smb_hdr *cifs_pdu = (struct smb_hdr *)iov[0 ].iov_base; +struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base;if ((cifs_pdu ==NULL ) || (server ==NULL ))return -EINVAL ;
@@ -125,7 +127,7 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, *pexpected_response_sequence_number = server->sequence_number++; server->sequence_number++; - rc =cifs_calc_signature (iov, n_vec, server, smb_signature); + rc =cifs_calc_signature (rqst, server, smb_signature);if (rc)memset (cifs_pdu->Signature.SecuritySignature,0 ,8 );else
@@ -134,6 +136,15 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,return rc; } +int cifs_sign_smbv (struct kvec *iov,int n_vec,struct TCP_Server_Info *server, +__u32 *pexpected_response_sequence) +{ +struct smb_rqst rqst = { .rq_iov = iov, + .rq_nvec = n_vec }; + +return cifs_sign_rqst (&rqst, server, pexpected_response_sequence); +} +/* must be called with server->srv_mutex held */ int cifs_sign_smb (struct smb_hdr *cifs_pdu,struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number)
@@ -147,14 +158,14 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, pexpected_response_sequence_number); } -int cifs_verify_signature (struct kvec *iov,unsigned int nr_iov, +int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number) {unsigned int rc;char server_response_sig[8 ];char what_we_think_sig_should_be[20 ]; -struct smb_hdr *cifs_pdu = (struct smb_hdr *)iov[0 ].iov_base; +struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base;if (cifs_pdu ==NULL || server ==NULL )return -EINVAL ;
@@ -186,8 +197,7 @@ int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, cifs_pdu->Signature.Sequence.Reserved =0 ;mutex_lock (&server->srv_mutex); - rc =cifs_calc_signature (iov, nr_iov, server, - what_we_think_sig_should_be); + rc =cifs_calc_signature (rqst, server, what_we_think_sig_should_be);mutex_unlock (&server->srv_mutex);if (rc)
fs/cifs/cifsglob.h +14 -0
@@ -162,6 +162,20 @@ struct cifs_cred {***************************************************************** */ +/* +* A smb_rqst represents a complete request to be issued to a server. It's +* formed by a kvec array, followed by an array of pages. Page data is assumed +* to start at the beginning of the first page. +*/ +struct smb_rqst { +struct kvec *rq_iov;/* array of kvecs */ +unsigned int rq_nvec;/* number of kvecs in array */ +struct page **rq_pages;/* pointer to array of page ptrs */ +unsigned int rq_npages;/* number pages in array */ +unsigned int rq_pagesz;/* page size to use */ +unsigned int rq_tailsz;/* length of last page */ +}; +enum smb_version { Smb_1 =1 , Smb_21,
fs/cifs/cifsproto.h +5 -2
@@ -24,6 +24,7 @@struct statfs ;struct smb_vol ; +struct smb_rqst ;/* *****************************************************************
@@ -394,10 +395,12 @@ extern void sesInfoFree(struct cifs_ses *);extern struct cifs_tcon *tconInfoAlloc (void );extern void tconInfoFree (struct cifs_tcon *); -extern int cifs_sign_smb (struct smb_hdr *,struct TCP_Server_Info *,__u32 *); +extern int cifs_sign_rqst (struct smb_rqst *rqst,struct TCP_Server_Info *server, +__u32 *pexpected_response_sequence_number);extern int cifs_sign_smbv (struct kvec *iov,int n_vec,struct TCP_Server_Info *,__u32 *); -extern int cifs_verify_signature (struct kvec *iov,unsigned int nr_iov, +extern int cifs_sign_smb (struct smb_hdr *,struct TCP_Server_Info *,__u32 *); +extern int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number); extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *,
fs/cifs/cifssmb.c +4 -3
@@ -1541,6 +1541,8 @@ cifs_readv_callback(struct mid_q_entry *mid)struct cifs_readdata *rdata = mid->callback_data;struct cifs_tcon *tcon =tlink_tcon (rdata->cfile->tlink);struct TCP_Server_Info *server = tcon->ses->server; +struct smb_rqst rqst = { .rq_iov = rdata->iov, + .rq_nvec = rdata->nr_iov };cFYI (1 ,"%s: mid=%llu state=%d result=%d bytes=%u" , __func__, mid->mid, mid->mid_state, rdata->result, rdata->bytes);
@@ -1552,9 +1554,8 @@ cifs_readv_callback(struct mid_q_entry *mid) (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {int rc =0 ; - rc =cifs_verify_signature (rdata->iov, rdata->nr_iov, - server, - mid->sequence_number +1 ); + rc =cifs_verify_signature (&rqst, server, + mid->sequence_number +1 );if (rc)cERROR (1 ,"SMB signature verification returned " "error = %d" , rc);
fs/cifs/transport.c +3 -1
@@ -504,11 +504,13 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,if (server->sec_mode & (SECMODE_SIGN_REQUIRED |SECMODE_SIGN_ENABLED )) {struct kvec iov;int rc =0 ; +struct smb_rqst rqst = { .rq_iov = &iov, + .rq_nvec =1 }; iov.iov_base = mid->resp_buf; iov.iov_len = len;/* FIXME: add code to kill session */ - rc =cifs_verify_signature (&iov,1 , server, + rc =cifs_verify_signature (&rqst, server, mid->sequence_number +1 );if (rc) cERROR(1, "SMB signature verification returned error = "
Signature · 1 line
1.7.11.2
PATCH v3 2/15 cifs: change smb2 signing routines to use smb_rqst structs
In reply to a message not in the archive--- fs/cifs/smb2pdu.c | 5 +++-- fs/cifs/smb2proto.h | 4 ++-- fs/cifs/smb2transport.c | 44 ++++++++++++++++++++++---------------------- 3 files changed, 27 insertions(+), 26 deletions(-)
fs/cifs/smb2pdu.c +3 -2
@@ -1297,6 +1297,8 @@ smb2_readv_callback(struct mid_q_entry *mid)struct TCP_Server_Info *server = tcon->ses->server;struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov[0 ].iov_base;unsigned int credits_received =1 ; +struct smb_rqst rqst = { .rq_iov = rdata->iov, + .rq_nvec = rdata->nr_iov };cFYI (1 ,"%s: mid=%llu state=%d result=%d bytes=%u" , __func__, mid->mid, mid->mid_state, rdata->result, rdata->bytes);
@@ -1307,8 +1309,7 @@ smb2_readv_callback(struct mid_q_entry *mid)/* result already set, check signature */ if (server->sec_mode & (SECMODE_SIGN_REQUIRED |SECMODE_SIGN_ENABLED )) { -if (smb2_verify_signature2 (rdata->iov, rdata->nr_iov, - server)) +if (smb2_verify_signature (&rqst, server))cERROR (1 ,"Unexpected SMB signature" ); }/* FIXME: should this be counted toward the initiating task? */
fs/cifs/smb2proto.h +2 -2
@@ -26,6 +26,7 @@#include <linux/key-type.h> struct statfs ; +struct smb_rqst ;/* *****************************************************************
@@ -39,8 +40,7 @@ extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr);extern __le16 *cifs_convert_path_to_utf16 (const char *from,struct cifs_sb_info *cifs_sb); -extern int smb2_verify_signature2 (struct kvec *,unsigned int , -struct TCP_Server_Info *); +extern int smb2_verify_signature (struct smb_rqst *,struct TCP_Server_Info *);extern int smb2_check_receive (struct mid_q_entry *mid,struct TCP_Server_Info *server,bool log_error); extern int smb2_setup_request(struct cifs_ses *ses, struct kvec *iov,
fs/cifs/smb2transport.c +22 -22
123 lines not on this page · raw message
Signature · 1 line
1.7.11.2
PATCH v3 3/15 cifs: convert send code to use smb_rqst structs
In reply to a message not in the archiveAgain, just a change in the arguments and some function renaming here. In later patches, we'll change this code to deal with page arrays.
In this patch, we add a new smb_send_rqst wrapper and have smb_sendv call that. Then we move most of the existing smb_sendv code into a new function -- smb_send_kvec. This seems a little redundant, but later we'll flesh this out to deal with arrays of pages.
--- fs/cifs/transport.c | 135 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 45 deletions(-)
fs/cifs/transport.c +90 -45
@@ -119,18 +119,29 @@ cifs_delete_mid(struct mid_q_entry *mid)DeleteMidQEntry (mid); } +/* +* smb_send_kvec - send an array of kvecs to the server +* @server: Server to send the data to +* @iov: Pointer to array of kvecs +* @n_vec: length of kvec array +* @sent: amount of data sent on socket is stored here +* +* Our basic "send data to server" function. Should be called with srv_mutex +* held. The caller is responsible for handling the results. +*/ static int -smb_sendv (struct TCP_Server_Info *server,struct kvec *iov,int n_vec) +smb_send_kvec (struct TCP_Server_Info *server,struct kvec *iov,size_t n_vec, +size_t *sent) {int rc =0 ;int i =0 ;struct msghdr smb_msg; -unsigned int len = iov[0 ].iov_len; -unsigned int total_len; -int first_vec =0 ; -unsigned int smb_buf_length =get_rfc1002_length (iov[0 ].iov_base); +unsigned int remaining; +size_t first_vec =0 ;struct socket *ssocket = server->ssocket; + *sent =0 ; +if (ssocket ==NULL )return -ENOTSOCK ;/* BB eventually add reconnect code here */
@@ -143,56 +154,60 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)else smb_msg.msg_flags =MSG_NOSIGNAL ; - total_len =0 ; + remaining =0 ;for (i =0 ; i < n_vec; i++) - total_len += iov[i].iov_len; - -cFYI (1 ,"Sending smb: total_len %d" , total_len); -dump_smb (iov[0 ].iov_base, len); + remaining += iov[i].iov_len; i =0 ; -while (total_len) { +while (remaining) { +/* +* If blocking send, we try 3 times, since each can block +* for 5 seconds. For nonblocking we have to try more +* but wait increasing amounts of time allowing time for +* socket to clear. The overall time we wait in either +* case to send on the socket is about 15 seconds. +* Similarly we wait for 15 seconds for a response from +* the server in SendReceive[2] for the server to send +* a response back for most types of requests (except +* SMB Write past end of file which can be slow, and +* blocking lock operations). NFS waits slightly longer +* than CIFS, but this can make it take longer for +* nonresponsive servers to be detected and 15 seconds +* is more than enough time for modern networks to +* send a packet. In most cases if we fail to send +* after the retries we will kill the socket and +* reconnect which may clear the network problem. +*/ rc =kernel_sendmsg (ssocket, &smb_msg, &iov[first_vec], - n_vec - first_vec, total_len); -if ((rc == -ENOSPC ) || (rc == -EAGAIN )) { + n_vec - first_vec, remaining); +if (rc == -ENOSPC || rc == -EAGAIN ) { i++; -/* -* If blocking send we try 3 times, since each can block -* for 5 seconds. For nonblocking we have to try more -* but wait increasing amounts of time allowing time for -* socket to clear. The overall time we wait in either -* case to send on the socket is about 15 seconds. -* Similarly we wait for 15 seconds for a response from -* the server in SendReceive[2] for the server to send -* a response back for most types of requests (except -* SMB Write past end of file which can be slow, and -* blocking lock operations). NFS waits slightly longer -* than CIFS, but this can make it take longer for -* nonresponsive servers to be detected and 15 seconds -* is more than enough time for modern networks to -* send a packet. In most cases if we fail to send -* after the retries we will kill the socket and -* reconnect which may clear the network problem. -*/ -if ((i >=14 ) || (!server->noblocksnd && (i >2 ))) { -cERROR (1 ,"sends on sock %p stuck for 15 seconds" , - ssocket); +if (i >=14 || (!server->noblocksnd && (i >2 ))) { +cERROR (1 ,"sends on sock %p stuck for 15 " +"seconds" , ssocket); rc = -EAGAIN ;break ; }msleep (1 << i);continue ; } +if (rc <0 )break ; -if (rc == total_len) { - total_len =0 ; +/* send was at least partially successful */ + *sent += rc; + +if (rc == remaining) { + remaining =0 ;break ; - }else if (rc > total_len) { -cERROR (1 ,"sent %d requested %d" , rc, total_len); + } + +if (rc > remaining) { +cERROR (1 ,"sent %d requested %d" , rc, remaining);break ; } +if (rc ==0 ) {/* should never happen, letting socket clear before retrying is our only obvious option here */
@@ -200,7 +215,9 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)msleep (500 );continue ; } - total_len -= rc; + + remaining -= rc; +/* the line below resets i */ for (i = first_vec; i < n_vec; i++) {if (iov[i].iov_len) {
@@ -215,16 +232,35 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) } } } + i =0 ;/* in case we get ENOSPC on the next send */ + rc =0 ; } +return rc; +} + +static int +smb_send_rqst (struct TCP_Server_Info *server,struct smb_rqst *rqst) +{ +int rc; +struct kvec *iov = rqst->rq_iov; +int n_vec = rqst->rq_nvec; +unsigned int smb_buf_length =get_rfc1002_length (iov[0 ].iov_base); +size_t total_len; + +cFYI (1 ,"Sending smb: smb_len=%u" , smb_buf_length); +dump_smb (iov[0 ].iov_base, iov[0 ].iov_len); + + rc =smb_send_kvec (server, iov, n_vec, &total_len);if ((total_len >0 ) && (total_len != smb_buf_length +4 )) { -cFYI (1 ,"partial send (%d remaining), terminating session" , - total_len); -/* If we have only sent part of an SMB then the next SMB -could be taken as the remainder of this one. We need -to kill the socket so the server throws away the partial -SMB */ +cFYI (1 ,"partial send (wanted=%u sent=%zu): terminating " +"session" , smb_buf_length +4 , total_len); +/* +* If we have only sent part of an SMB then the next SMB could +* be taken as the remainder of this one. We need to kill the +* socket so the server throws away the partial SMB +*/ server->tcpStatus = CifsNeedReconnect; }
@@ -236,6 +272,15 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)return rc; } +static int +smb_sendv (struct TCP_Server_Info *server,struct kvec *iov,int n_vec) +{ +struct smb_rqst rqst = { .rq_iov = iov, + .rq_nvec = n_vec }; + +return smb_send_rqst (server, &rqst); +} +int smb_send (struct TCP_Server_Info *server,struct smb_hdr *smb_buffer,unsigned int smb_buf_length)
Signature · 1 line
1.7.11.2
PATCH v3 4/15 cifs: cork the socket before a send and uncork it afterward
In reply to a message not in the archiveWe want to send SMBs as "atomically" as possible. Prior to sending any data on the socket, cork it to make sure that no non-full frames go out. Afterward, uncork it to make sure all of the data gets pushed out to the wire.
Note that this more or less renders the socket=TCP_NODELAY mount option obsolete. When TCP_CORK and TCP_NODELAY are used on the same socket, TCP_NODELAY is essentially ignored.
--- fs/cifs/connect.c | 4 ++++ fs/cifs/transport.c | 12 ++++++++++++ 2 files changed, 16 insertions(+)
fs/cifs/connect.c +4 -0
@@ -1680,6 +1680,10 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,if (string ==NULL ) goto out_nomem; +/* +* FIXME: since we now cork/uncork the socket while +* sending, should we deprecate this option? +*/ if (strnicmp (string,"TCP_NODELAY" ,11 ) ==0 ) vol->sockopt_tcp_nodelay =1 ;break ;
fs/cifs/transport.c +12 -0
@@ -27,6 +27,7 @@#include <linux/net.h> #include <linux/delay.h> #include <linux/freezer.h> +#include <linux/tcp.h> #include <asm/uaccess.h> #include <asm/processor.h> #include <linux/mempool.h>
@@ -247,12 +248,23 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)int n_vec = rqst->rq_nvec;unsigned int smb_buf_length =get_rfc1002_length (iov[0 ].iov_base);size_t total_len; +struct socket *ssocket = server->ssocket; +int val =1 ;cFYI (1 ,"Sending smb: smb_len=%u" , smb_buf_length);dump_smb (iov[0 ].iov_base, iov[0 ].iov_len); +/* cork the socket */ +kernel_setsockopt (ssocket,SOL_TCP ,TCP_CORK , + (char *)&val,sizeof (val)); + rc =smb_send_kvec (server, iov, n_vec, &total_len); +/* uncork it */ + val =0 ; +kernel_setsockopt (ssocket,SOL_TCP ,TCP_CORK , + (char *)&val,sizeof (val)); +if ((total_len >0 ) && (total_len != smb_buf_length +4 )) {cFYI (1 ,"partial send (wanted=%u sent=%zu): terminating " "session" , smb_buf_length +4 , total_len);
Signature · 1 line
1.7.11.2
PATCH v3 5/15 cifs: teach smb_send_rqst how to handle arrays of pages
In reply to a message not in the archiveAdd code that allows smb_send_rqst to send an array of pages after the initial kvec array has been sent. For now, we simply kmap the page array and send it using the standard smb_send_kvec function. Eventually, we may want to convert this code to use kernel_sendpage under the hood and avoid the kmap altogether for the page data.
--- fs/cifs/transport.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-)
fs/cifs/transport.c +54 -2
@@ -28,6 +28,7 @@#include <linux/delay.h> #include <linux/freezer.h> #include <linux/tcp.h> +#include <linux/highmem.h> #include <asm/uaccess.h> #include <asm/processor.h> #include <linux/mempool.h>
@@ -240,6 +241,38 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,return rc; } +/** +* rqst_page_to_kvec - Turn a slot in the smb_rqst page array into a kvec +* @rqst: pointer to smb_rqst +* @idx: index into the array of the page +* @iov: pointer to struct kvec that will hold the result +* +* Helper function to convert a slot in the rqst->rq_pages array into a kvec. +* The page will be kmapped and the address placed into iov_base. The length +* will then be adjusted according to the ptailoff. +*/ +static void +cifs_rqst_page_to_kvec (struct smb_rqst *rqst,unsigned int idx, +struct kvec *iov) +{ +/* +* FIXME: We could avoid this kmap altogether if we used +* kernel_sendpage instead of kernel_sendmsg. That will only +* work if signing is disabled though as sendpage inlines the +* page directly into the fraglist. If userspace modifies the +* page after we calculate the signature, then the server will +* reject it and may break the connection. kernel_sendmsg does +* an extra copy of the data and avoids that issue. +*/ + iov->iov_base =kmap (rqst->rq_pages[idx]); + +/* if last page, don't send beyond this offset into page */ +if (idx == (rqst->rq_npages -1 )) + iov->iov_len = rqst->rq_tailsz; +else + iov->iov_len = rqst->rq_pagesz; +} +static int smb_send_rqst (struct TCP_Server_Info *server,struct smb_rqst *rqst) {
@@ -247,7 +280,8 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)struct kvec *iov = rqst->rq_iov;int n_vec = rqst->rq_nvec;unsigned int smb_buf_length =get_rfc1002_length (iov[0 ].iov_base); -size_t total_len; +unsigned int i; +size_t total_len =0 , sent;struct socket *ssocket = server->ssocket;int val =1 ;
@@ -258,8 +292,26 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)kernel_setsockopt (ssocket,SOL_TCP ,TCP_CORK , (char *)&val,sizeof (val)); - rc =smb_send_kvec (server, iov, n_vec, &total_len); + rc =smb_send_kvec (server, iov, n_vec, &sent); +if (rc <0 ) + goto uncork; + + total_len += sent; + +/* now walk the page array and send each page in it */ +for (i =0 ; i < rqst->rq_npages; i++) { +struct kvec p_iov; + +cifs_rqst_page_to_kvec (rqst, i, &p_iov); + rc =smb_send_kvec (server, &p_iov,1 , &sent); +kunmap (rqst->rq_pages[i]); +if (rc <0 ) +break ; + + total_len += sent; + } +uncork:/* uncork it */ val =0 ; kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
Signature · 1 line
1.7.11.2
PATCH v3 6/15 cifs: teach signing routines how to deal with arrays of pages in a smb_rqst
In reply to a message not in the archiveUse the smb_send_rqst helper function to kmap each page in the array and update the hash for that chunk.
--- fs/cifs/cifsencrypt.c | 11 +++++++++++ fs/cifs/cifsproto.h | 2 ++ fs/cifs/smb2transport.c | 11 +++++++++++ fs/cifs/transport.c | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-)
fs/cifs/cifsencrypt.c +11 -0
@@ -29,6 +29,7 @@#include "ntlmssp.h" #include <linux/ctype.h> #include <linux/random.h> +#include <linux/highmem.h> /* * Calculate and return the CIFS signature based on the mac key and SMB PDU.
@@ -93,6 +94,16 @@ static int cifs_calc_signature(struct smb_rqst *rqst, } } +/* now hash over the rq_pages array */ +for (i =0 ; i < rqst->rq_npages; i++) { +struct kvec p_iov; + +cifs_rqst_page_to_kvec (rqst, i, &p_iov); +crypto_shash_update (&server->secmech.sdescmd5->shash, + p_iov.iov_base, p_iov.iov_len); +kunmap (rqst->rq_pages[i]); + } + rc =crypto_shash_final (&server->secmech.sdescmd5->shash, signature);if (rc)cERROR (1 ,"%s: Could not generate md5 hash" , __func__);
fs/cifs/cifsproto.h +2 -0
@@ -36,6 +36,8 @@ extern struct smb_hdr *cifs_buf_get(void);extern void cifs_buf_release (void *);extern struct smb_hdr *cifs_small_buf_get (void );extern void cifs_small_buf_release (void *); +extern void cifs_rqst_page_to_kvec (struct smb_rqst *rqst,unsigned int idx, +struct kvec *iov);extern int smb_send (struct TCP_Server_Info *,struct smb_hdr *,unsigned int /* length */ );extern unsigned int _get_xid (void );
fs/cifs/smb2transport.c +11 -0
@@ -30,6 +30,7 @@#include <linux/uaccess.h> #include <asm/processor.h> #include <linux/mempool.h> +#include <linux/highmem.h> #include "smb2pdu.h" #include "cifsglob.h" #include "cifsproto.h"
@@ -95,6 +96,16 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) } } +/* now hash over the rq_pages array */ +for (i =0 ; i < rqst->rq_npages; i++) { +struct kvec p_iov; + +cifs_rqst_page_to_kvec (rqst, i, &p_iov); +crypto_shash_update (&server->secmech.sdeschmacsha256->shash, + p_iov.iov_base, p_iov.iov_len); +kunmap (rqst->rq_pages[i]); + } + rc =crypto_shash_final (&server->secmech.sdeschmacsha256->shash, sigptr);if (rc)
fs/cifs/transport.c +1 -1
@@ -251,7 +251,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,* The page will be kmapped and the address placed into iov_base. The length * will then be adjusted according to the ptailoff. */ -static void +void cifs_rqst_page_to_kvec (struct smb_rqst *rqst,unsigned int idx,struct kvec *iov) {
Signature · 1 line
1.7.11.2
PATCH v3 7/15 cifs: change cifs_call_async to use smb_rqst structs
In reply to a message not in the archiveFor now, none of the callers populate rq_pages. That will be done for writes in a later patch. While we're at it, change the prototype of setup_async_request not to need a return pointer argument. Just return the pointer to the mid_q_entry or an ERR_PTR.
--- fs/cifs/cifsglob.h | 8 ++++---- fs/cifs/cifsproto.h | 16 +++++++-------- fs/cifs/cifssmb.c | 20 ++++++++++++------- fs/cifs/smb2pdu.c | 15 ++++++++++---- fs/cifs/smb2proto.h | 9 ++++----- fs/cifs/smb2transport.c | 40 ++++++++++++++++--------------------- fs/cifs/transport.c | 52 ++++++++++++++++++++++++------------------------- 7 files changed, 83 insertions(+), 77 deletions(-)
fs/cifs/cifsglob.h +4 -4
@@ -201,11 +201,11 @@ struct smb_version_operations { struct mid_q_entry *);bool (*compare_fids)(struct cifsFileInfo *,struct cifsFileInfo *);/* setup request: allocate mid, sign message */ -int (*setup_request)(struct cifs_ses *,struct kvec *,unsigned int , -struct mid_q_entry **); +struct mid_q_entry *(*setup_request)(struct cifs_ses *, +struct smb_rqst *);/* setup async request: allocate mid, sign message */ -int (*setup_async_request)(struct TCP_Server_Info *,struct kvec *, -unsigned int ,struct mid_q_entry **); +struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *, +struct smb_rqst *);/* check response: verify signature, map error */ int (*check_receive)(struct mid_q_entry *,struct TCP_Server_Info *,bool );
fs/cifs/cifsproto.h +8 -8
@@ -70,20 +70,20 @@ extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer,extern void DeleteMidQEntry (struct mid_q_entry *midEntry);extern void cifs_delete_mid (struct mid_q_entry *mid);extern void cifs_wake_up_task (struct mid_q_entry *mid); -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, -const int flags); +extern int cifs_call_async (struct TCP_Server_Info *server, +struct smb_rqst *rqst, +mid_receive_t *receive,mid_callback_t *callback, +void *cbdata,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 );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 , -struct mid_q_entry **); -extern int cifs_setup_async_request (struct TCP_Server_Info *,struct kvec *, -unsigned int ,struct mid_q_entry **); +extern struct mid_q_entry *cifs_setup_request (struct cifs_ses *, +struct smb_rqst *); +extern struct mid_q_entry *cifs_setup_async_request (struct TCP_Server_Info *, +struct smb_rqst *);extern int cifs_check_receive (struct mid_q_entry *mid,struct TCP_Server_Info *server,bool log_error); extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *,
fs/cifs/cifssmb.c +13 -7
@@ -725,6 +725,8 @@ CIFSSMBEcho(struct TCP_Server_Info *server)ECHO_REQ *smb;int rc =0 ;struct kvec iov; +struct smb_rqst rqst = { .rq_iov = &iov, + .rq_nvec =1 };cFYI (1 ,"In echo request" );
@@ -742,7 +744,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) iov.iov_base = smb; iov.iov_len =be32_to_cpu (smb->hdr.smb_buf_length) +4 ; - rc =cifs_call_async (server, &iov,1 ,NULL , cifs_echo_callback, + rc =cifs_call_async (server, &rqst,NULL , cifs_echo_callback, server,CIFS_ASYNC_OP |CIFS_ECHO_OP );if (rc)cFYI (1 ,"Echo request failed: %d" , rc);
@@ -1585,6 +1587,8 @@ cifs_async_readv(struct cifs_readdata *rdata)READ_REQ *smb =NULL ;int wct;struct cifs_tcon *tcon =tlink_tcon (rdata->cfile->tlink); +struct smb_rqst rqst = { .rq_iov = rdata->iov, + .rq_nvec =1 };cFYI (1 ,"%s: offset=%llu bytes=%u" , __func__, rdata->offset, rdata->bytes);
@@ -1628,9 +1632,8 @@ cifs_async_readv(struct cifs_readdata *rdata) rdata->iov[0 ].iov_len =be32_to_cpu (smb->hdr.smb_buf_length) +4 ;kref_get (&rdata->refcount); - rc =cifs_call_async (tcon->ses->server, rdata->iov,1 , - cifs_readv_receive, cifs_readv_callback, - rdata,0 ); + rc =cifs_call_async (tcon->ses->server, &rqst, cifs_readv_receive, + cifs_readv_callback, rdata,0 );if (rc ==0 )cifs_stats_inc (&tcon->stats.cifs_stats.num_reads);
@@ -2035,6 +2038,7 @@ cifs_async_writev(struct cifs_writedata *wdata)int wct;struct cifs_tcon *tcon =tlink_tcon (wdata->cfile->tlink);struct kvec *iov =NULL ; +struct smb_rqst rqst = { };if (tcon->ses->capabilities &CAP_LARGE_FILES ) { wct =14 ;
@@ -2051,11 +2055,13 @@ cifs_async_writev(struct cifs_writedata *wdata) goto async_writev_out;/* 1 iov per page + 1 for header */ - iov =kzalloc ((wdata->nr_pages +1 ) *sizeof (*iov),GFP_NOFS ); + rqst.rq_nvec = wdata->nr_pages +1 ; + iov =kzalloc ((rqst.rq_nvec) *sizeof (*iov),GFP_NOFS );if (iov ==NULL ) { rc = -ENOMEM ; goto async_writev_out; } + rqst.rq_iov = iov; smb->hdr.Pid =cpu_to_le16 ((__u16 )wdata->pid); smb->hdr.PidHigh =cpu_to_le16 ((__u16)(wdata->pid >>16 ));
@@ -2104,8 +2110,8 @@ 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,0 ); + rc =cifs_call_async (tcon->ses->server, &rqst,NULL , + cifs_writev_callback, wdata,0 );if (rc ==0 )cifs_stats_inc (&tcon->stats.cifs_stats.num_writes);
fs/cifs/smb2pdu.c +11 -4
@@ -1171,6 +1171,8 @@ SMB2_echo(struct TCP_Server_Info *server)struct smb2_echo_req *req;int rc =0 ;struct kvec iov; +struct smb_rqst rqst = { .rq_iov = &iov, + .rq_nvec =1 };cFYI (1 ,"In echo request" );
@@ -1184,7 +1186,7 @@ SMB2_echo(struct TCP_Server_Info *server)/* 4 for rfc1002 length field */ iov.iov_len =get_rfc1002_length (req) +4 ; - rc =cifs_call_async (server, &iov,1 ,NULL , smb2_echo_callback, server, + rc =cifs_call_async (server, &rqst,NULL , smb2_echo_callback, server,CIFS_ECHO_OP );if (rc)cFYI (1 ,"Echo request failed: %d" , rc);
@@ -1340,6 +1342,8 @@ smb2_async_readv(struct cifs_readdata *rdata)int rc;struct smb2_hdr *buf;struct cifs_io_parms io_parms; +struct smb_rqst rqst = { .rq_iov = rdata->iov, + .rq_nvec =1 };cFYI (1 ,"%s: offset=%llu bytes=%u" , __func__, rdata->offset, rdata->bytes);
@@ -1359,7 +1363,7 @@ smb2_async_readv(struct cifs_readdata *rdata) rdata->iov[0 ].iov_len =get_rfc1002_length (rdata->iov[0 ].iov_base) +4 ;kref_get (&rdata->refcount); - rc =cifs_call_async (io_parms.tcon->ses->server, rdata->iov,1 , + rc =cifs_call_async (io_parms.tcon->ses->server, &rqst, cifs_readv_receive, smb2_readv_callback, rdata,0 );if (rc)
@@ -1480,6 +1484,7 @@ smb2_async_writev(struct cifs_writedata *wdata)struct smb2_write_req *req =NULL ;struct cifs_tcon *tcon =tlink_tcon (wdata->cfile->tlink);struct kvec *iov =NULL ; +struct smb_rqst rqst; rc =small_smb2_init (SMB2_WRITE , tcon, (void **) &req);if (rc)
@@ -1491,6 +1496,8 @@ smb2_async_writev(struct cifs_writedata *wdata) rc = -ENOMEM ; goto async_writev_out; } + rqst.rq_iov = iov; + rqst.rq_nvec = wdata->nr_pages +1 ; req->hdr.ProcessId =cpu_to_le32 (wdata->cfile->pid);
@@ -1526,8 +1533,8 @@ smb2_async_writev(struct cifs_writedata *wdata)inc_rfc1001_len (&req->hdr, wdata->bytes -1 /* Buffer */ );kref_get (&wdata->refcount); - rc =cifs_call_async (tcon->ses->server, iov, wdata->nr_pages +1 , -NULL , smb2_writev_callback, wdata,0 ); + rc =cifs_call_async (tcon->ses->server, &rqst,NULL , + smb2_writev_callback, wdata,0 );if (rc)kref_put (&wdata->refcount, cifs_writedata_release);
fs/cifs/smb2proto.h +4 -5
@@ -43,11 +43,10 @@ extern __le16 *cifs_convert_path_to_utf16(const char *from,extern int smb2_verify_signature (struct smb_rqst *,struct TCP_Server_Info *);extern int smb2_check_receive (struct mid_q_entry *mid,struct TCP_Server_Info *server,bool log_error); -extern int smb2_setup_request (struct cifs_ses *ses,struct kvec *iov, -unsigned int nvec,struct mid_q_entry **ret_mid); -extern int smb2_setup_async_request (struct TCP_Server_Info *server, -struct kvec *iov,unsigned int nvec, -struct mid_q_entry **ret_mid); +extern struct mid_q_entry *smb2_setup_request (struct cifs_ses *ses, +struct smb_rqst *rqst); +extern struct mid_q_entry *smb2_setup_async_request ( +struct TCP_Server_Info *server,struct smb_rqst *rqst);extern void smb2_echo_request (struct work_struct *work);extern bool smb2_is_valid_oplock_break (char *buffer,struct TCP_Server_Info *srv);
fs/cifs/smb2transport.c +17 -23
@@ -277,50 +277,44 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,return map_smb2_to_linux_error (mid->resp_buf, log_error); } -int -smb2_setup_request (struct cifs_ses *ses,struct kvec *iov, -unsigned int nvec,struct mid_q_entry **ret_mid) +struct mid_q_entry * +smb2_setup_request (struct cifs_ses *ses,struct smb_rqst *rqst) {int rc; -struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0 ].iov_base; +struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base;struct mid_q_entry *mid; -struct smb_rqst rqst = { .rq_iov = iov, - .rq_nvec = nvec };smb2_seq_num_into_buf (ses->server, hdr); rc =smb2_get_mid_entry (ses, hdr, &mid);if (rc) -return rc; - rc =smb2_sign_rqst (&rqst, ses->server); -if (rc) +return ERR_PTR (rc); + rc =smb2_sign_rqst (rqst, ses->server); +if (rc) {cifs_delete_mid (mid); - *ret_mid = mid; -return rc; +return ERR_PTR (rc); + } +return mid; } -int -smb2_setup_async_request (struct TCP_Server_Info *server,struct kvec *iov, -unsigned int nvec,struct mid_q_entry **ret_mid) +struct mid_q_entry * +smb2_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst) { -int rc =0 ; -struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0 ].iov_base; +int rc; +struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base;struct mid_q_entry *mid; -struct smb_rqst rqst = { .rq_iov = iov, - .rq_nvec = nvec };smb2_seq_num_into_buf (server, hdr); mid =smb2_mid_entry_alloc (hdr, server);if (mid ==NULL ) -return -ENOMEM ; +return ERR_PTR (-ENOMEM ); - rc =smb2_sign_rqst (&rqst, server); + rc =smb2_sign_rqst (rqst, server);if (rc) {DeleteMidQEntry (mid); -return rc; +return ERR_PTR (rc); } - *ret_mid = mid; -return rc; +return mid; }
fs/cifs/transport.c +26 -26
117 lines not on this page · raw message
Signature · 1 line
1.7.11.2
PATCH v3 8/15 cifs: convert async write code to pass in data via rq_pages array
In reply to a message not in the archive--- fs/cifs/cifsglob.h | 4 ++-- fs/cifs/cifssmb.c | 39 +++++++++++---------------------------- fs/cifs/file.c | 48 ++++++++++-------------------------------------- fs/cifs/smb2pdu.c | 37 ++++++++++--------------------------- 4 files changed, 33 insertions(+), 95 deletions(-)
fs/cifs/cifsglob.h +2 -2
@@ -998,8 +998,8 @@ struct cifs_writedata {pid_t pid;unsigned int bytes;int result; -void (*marshal_iov) (struct kvec *iov, -struct cifs_writedata *wdata); +unsigned int pagesz; +unsigned int tailsz;unsigned int nr_pages;struct page *pages[1 ]; };
fs/cifs/cifssmb.c +11 -28
@@ -2033,11 +2033,11 @@ cifs_writev_callback(struct mid_q_entry *mid)int cifs_async_writev (struct cifs_writedata *wdata) { -int i, rc = -EACCES ; +int rc = -EACCES ;WRITE_REQ *smb =NULL ;int wct;struct cifs_tcon *tcon =tlink_tcon (wdata->cfile->tlink); -struct kvec *iov =NULL ; +struct kvec iov;struct smb_rqst rqst = { };if (tcon->ses->capabilities &CAP_LARGE_FILES ) {
@@ -2054,15 +2054,6 @@ cifs_async_writev(struct cifs_writedata *wdata)if (rc) goto async_writev_out; -/* 1 iov per page + 1 for header */ - rqst.rq_nvec = wdata->nr_pages +1 ; - iov =kzalloc ((rqst.rq_nvec) *sizeof (*iov),GFP_NOFS ); -if (iov ==NULL ) { - rc = -ENOMEM ; - goto async_writev_out; - } - rqst.rq_iov = iov; - smb->hdr.Pid =cpu_to_le16 ((__u16 )wdata->pid); smb->hdr.PidHigh =cpu_to_le16 ((__u16)(wdata->pid >>16 ));
@@ -2079,18 +2070,15 @@ cifs_async_writev(struct cifs_writedata *wdata)cpu_to_le16 (offsetof(struct smb_com_write_req , Data) -4 );/* 4 for RFC1001 length + 1 for BCC */ - iov[0 ].iov_len =be32_to_cpu (smb->hdr.smb_buf_length) +4 +1 ; - iov[0 ].iov_base = smb; + iov.iov_len =be32_to_cpu (smb->hdr.smb_buf_length) +4 +1 ; + iov.iov_base = smb; -/* -* This function should marshal up the page array into the kvec -* array, reserving [0] for the header. It should kmap the pages -* and set the iov_len properly for each one. It may also set -* wdata->bytes too. -*/ -cifs_kmap_lock (); - wdata->marshal_iov (iov, wdata); -cifs_kmap_unlock (); + rqst.rq_iov = &iov; + rqst.rq_nvec =1 ; + rqst.rq_pages = wdata->pages; + rqst.rq_npages = wdata->nr_pages; + rqst.rq_pagesz = wdata->pagesz; + rqst.rq_tailsz = wdata->tailsz;cFYI (1 ,"async write at %llu %u bytes" , wdata->offset, wdata->bytes);
@@ -2106,7 +2094,7 @@ cifs_async_writev(struct cifs_writedata *wdata) (struct smb_com_writex_req *)smb;inc_rfc1001_len (&smbw->hdr, wdata->bytes +5 );put_bcc (wdata->bytes +5 , &smbw->hdr); - iov[0 ].iov_len +=4 ;/* pad bigger by four bytes */ + iov.iov_len +=4 ;/* pad bigger by four bytes */ }kref_get (&wdata->refcount);
@@ -2118,13 +2106,8 @@ cifs_async_writev(struct cifs_writedata *wdata)else kref_put (&wdata->refcount, cifs_writedata_release); -/* send is done, unmap pages */ -for (i =0 ; i < wdata->nr_pages; i++) -kunmap (wdata->pages[i]); - async_writev_out:cifs_small_buf_release (smb); -kfree (iov);return rc; }
fs/cifs/file.c +10 -38
84 lines not on this page · raw message
fs/cifs/smb2pdu.c +10 -27
@@ -1480,25 +1480,16 @@ smb2_writev_callback(struct mid_q_entry *mid)int smb2_async_writev (struct cifs_writedata *wdata) { -int i, rc = -EACCES ; +int rc = -EACCES ;struct smb2_write_req *req =NULL ;struct cifs_tcon *tcon =tlink_tcon (wdata->cfile->tlink); -struct kvec *iov =NULL ; +struct kvec iov;struct smb_rqst rqst; rc =small_smb2_init (SMB2_WRITE , tcon, (void **) &req);if (rc) goto async_writev_out; -/* 1 iov per page + 1 for header */ - iov =kzalloc ((wdata->nr_pages +1 ) *sizeof (*iov),GFP_NOFS ); -if (iov ==NULL ) { - rc = -ENOMEM ; - goto async_writev_out; - } - rqst.rq_iov = iov; - rqst.rq_nvec = wdata->nr_pages +1 ; - req->hdr.ProcessId =cpu_to_le32 (wdata->cfile->pid); req->PersistentFileId = wdata->cfile->fid.persistent_fid;
@@ -1513,18 +1504,15 @@ smb2_async_writev(struct cifs_writedata *wdata) req->RemainingBytes =0 ;/* 4 for rfc1002 length field and 1 for Buffer */ - iov[0 ].iov_len =get_rfc1002_length (req) +4 -1 ; - iov[0 ].iov_base = (char *)req; + iov.iov_len =get_rfc1002_length (req) +4 -1 ; + iov.iov_base = req; -/* -* This function should marshal up the page array into the kvec -* array, reserving [0] for the header. It should kmap the pages -* and set the iov_len properly for each one. It may also set -* wdata->bytes too. -*/ -cifs_kmap_lock (); - wdata->marshal_iov (iov, wdata); -cifs_kmap_unlock (); + rqst.rq_iov = &iov; + rqst.rq_nvec =1 ; + rqst.rq_pages = wdata->pages; + rqst.rq_npages = wdata->nr_pages; + rqst.rq_pagesz = wdata->pagesz; + rqst.rq_tailsz = wdata->tailsz;cFYI (1 ,"async write at %llu %u bytes" , wdata->offset, wdata->bytes);
@@ -1539,13 +1527,8 @@ smb2_async_writev(struct cifs_writedata *wdata)if (rc)kref_put (&wdata->refcount, cifs_writedata_release); -/* send is done, unmap pages */ -for (i =0 ; i < wdata->nr_pages; i++) -kunmap (wdata->pages[i]); - async_writev_out:cifs_small_buf_release (req); -kfree (iov);return rc; }
Signature · 1 line
1.7.11.2
PATCH v3 9/15 cifs: remove the kmap size limit from wsize
In reply to a message not in the archiveNow that we're not kmapping so much at once, there's no need to cap the wsize at the amount that can be simultaneously kmapped.
--- fs/cifs/smb1ops.c | 3 --- fs/cifs/smb2ops.c | 3 --- 2 files changed, 6 deletions(-)
fs/cifs/smb1ops.c +0 -3
@@ -442,9 +442,6 @@ cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) wsize = min_t(unsigned int, wsize, server->maxBuf -sizeof (WRITE_REQ ) +4 ); -/* limit to the amount that we can kmap at once */ - wsize = min_t(unsigned int, wsize, CIFS_KMAP_SIZE_LIMIT); -/* hard limit of CIFS_MAX_WSIZE */ wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
fs/cifs/smb2ops.c +0 -3
@@ -187,9 +187,6 @@ smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)*/ wsize = min_t(unsigned int, wsize, 2 << 15); -/* limit to the amount that we can kmap at once */ - wsize = min_t(unsigned int, wsize, CIFS_KMAP_SIZE_LIMIT); -return wsize; }
Signature · 1 line
1.7.11.2
PATCH v3 10/15 cifs: add deprecation warning to sockopt=TCP_NODELAY option
In reply to a message not in the archiveNow that we're using TCP_CORK on the socket, there's no value in continuting to support this option. Schedule it for removal in 3.8.
--- fs/cifs/connect.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
fs/cifs/connect.c +6 -5
@@ -1680,12 +1680,13 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,if (string ==NULL ) goto out_nomem; -/* -* FIXME: since we now cork/uncork the socket while -* sending, should we deprecate this option? -*/ -if (strnicmp (string,"TCP_NODELAY" ,11 ) ==0 ) +if (strnicmp (string,"TCP_NODELAY" ,11 ) ==0 ) { +printk (KERN_WARNING "CIFS: the " +"sockopt=TCP_NODELAY option has been " +"deprecated and will be removed " +"in 3.8\n" ); vol->sockopt_tcp_nodelay =1 ; + }break ;case Opt_netbiosname: string =match_strdup (args);
Signature · 1 line
1.7.11.2
PATCH v3 11/15 cifs: allocate kvec array for cifs_readdata as a separate allocation
In reply to a message not in the archiveEventually, we're going to want to append a list of pages to cifs_readdata instead of a list of kvecs. To prepare for that, turn the kvec array allocation into a separate one and just keep a pointer to it in the readdata.
--- fs/cifs/cifsglob.h | 2 +- fs/cifs/file.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-)
fs/cifs/cifsglob.h +1 -1
@@ -981,7 +981,7 @@ struct cifs_readdata {int (*marshal_iov) (struct cifs_readdata *rdata,unsigned int remaining);unsigned int nr_iov; -struct kvec iov[1 ]; +struct kvec *iov; };struct cifs_writedata ;
fs/cifs/file.c +12 -3
@@ -2410,19 +2410,27 @@ ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, }static struct cifs_readdata * -cifs_readdata_alloc (unsigned int nr_vecs,work_func_t complete) +cifs_readdata_alloc (unsigned int nr_pages,work_func_t complete) {struct cifs_readdata *rdata; +struct kvec *iov; - rdata =kzalloc (sizeof (*rdata) + -sizeof (struct kvec ) * nr_vecs,GFP_KERNEL ); + iov =kzalloc (sizeof (*iov) * (nr_pages +1 ),GFP_KERNEL ); +if (!iov) +return (struct cifs_readdata *)iov; + + rdata =kzalloc (sizeof (*rdata),GFP_KERNEL );if (rdata !=NULL ) {kref_init (&rdata->refcount);INIT_LIST_HEAD (&rdata->list);init_completion (&rdata->done);INIT_WORK (&rdata->work, complete);INIT_LIST_HEAD (&rdata->pages); + rdata->iov = iov; + }else { +kfree (iov); } +return rdata; }
@@ -2435,6 +2443,7 @@ cifs_readdata_release(struct kref *refcount)if (rdata->cfile)cifsFileInfo_put (rdata->cfile); +kfree (rdata->iov);kfree (rdata); }
Signature · 1 line
1.7.11.2
PATCH v3 12/15 cifs: turn the pages list in cifs_readdata into an array
In reply to a message not in the archiveWe'll need an array to put into a smb_rqst, so convert this into an array instead of (ab)using the lru list_head.
--- fs/cifs/cifsglob.h | 3 +- fs/cifs/file.c | 82 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 35 deletions(-)
fs/cifs/cifsglob.h +2 -1
@@ -976,12 +976,13 @@ struct cifs_readdata {unsigned int bytes;pid_t pid;int result; -struct list_head pages;struct work_struct work;int (*marshal_iov) (struct cifs_readdata *rdata,unsigned int remaining);unsigned int nr_iov;struct kvec *iov; +unsigned int nr_pages; +struct page *pages[]; };struct cifs_writedata ;
fs/cifs/file.c +48 -34
236 lines not on this page · raw message
Signature · 1 line
1.7.11.2
PATCH v3 13/15 cifs: convert async read code to use pages array without kmapping
In reply to a message not in the archiveReplace the "marshal_iov" function with a "read_into_pages" function. That function will copy the read data off the socket and into the pages array, kmapping and reading pages one at a time.
--- fs/cifs/cifsglob.h | 7 ++- fs/cifs/cifssmb.c | 27 +++++------- fs/cifs/file.c | 123 ++++++++++++++++++++++++++--------------------------- fs/cifs/smb2pdu.c | 6 ++- 4 files changed, 80 insertions(+), 83 deletions(-)
fs/cifs/cifsglob.h +5 -2
@@ -977,8 +977,11 @@ struct cifs_readdata {pid_t pid;int result;struct work_struct work; -int (*marshal_iov) (struct cifs_readdata *rdata, -unsigned int remaining); +int (*read_into_pages)(struct TCP_Server_Info *server, +struct cifs_readdata *rdata, +unsigned int len); +unsigned int pagesz; +unsigned int tailsz;unsigned int nr_iov;struct kvec *iov;unsigned int nr_pages;
fs/cifs/cifssmb.c +10 -17
@@ -1496,6 +1496,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)/* set up first iov for signature check */ rdata->iov[0 ].iov_base = buf; rdata->iov[0 ].iov_len = server->total_read; + rdata->nr_iov =1 ;cFYI (1 ,"0: iov_base=%p iov_len=%zu" , rdata->iov[0 ].iov_base, rdata->iov[0 ].iov_len);
@@ -1507,23 +1508,11 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)return cifs_readv_discard (server, mid); } -/* marshal up the page array */ -cifs_kmap_lock (); - len = rdata->marshal_iov (rdata, data_len); -cifs_kmap_unlock (); - data_len -= len; - -/* issue the read if we have any iovecs left to fill */ -if (rdata->nr_iov >1 ) { - length =cifs_readv_from_socket (server, &rdata->iov[1 ], - rdata->nr_iov -1 , len); -if (length <0 ) -return length; - server->total_read += length; - }else { - length =0 ; - } + length = rdata->read_into_pages (server, rdata, data_len); +if (length <0 ) +return length; + server->total_read += length; rdata->bytes = length; cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read,
@@ -1544,7 +1533,11 @@ cifs_readv_callback(struct mid_q_entry *mid)struct cifs_tcon *tcon =tlink_tcon (rdata->cfile->tlink);struct TCP_Server_Info *server = tcon->ses->server;struct smb_rqst rqst = { .rq_iov = rdata->iov, - .rq_nvec = rdata->nr_iov }; + .rq_nvec = rdata->nr_iov, + .rq_pages = rdata->pages, + .rq_npages = rdata->nr_pages, + .rq_pagesz = rdata->pagesz, + .rq_tailsz = rdata->tailsz };cFYI (1 ,"%s: mid=%llu state=%d result=%d bytes=%u" , __func__, mid->mid, mid->mid_state, rdata->result, rdata->bytes);
fs/cifs/file.c +60 -63
209 lines not on this page · raw message
fs/cifs/smb2pdu.c +5 -1
@@ -1300,7 +1300,11 @@ smb2_readv_callback(struct mid_q_entry *mid)struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov[0 ].iov_base;unsigned int credits_received =1 ;struct smb_rqst rqst = { .rq_iov = rdata->iov, - .rq_nvec = rdata->nr_iov }; + .rq_nvec =1 , + .rq_pages = rdata->pages, + .rq_npages = rdata->nr_pages, + .rq_pagesz = rdata->pagesz, + .rq_tailsz = rdata->tailsz };cFYI (1 ,"%s: mid=%llu state=%d result=%d bytes=%u" , __func__, mid->mid, mid->mid_state, rdata->result, rdata->bytes);
Signature · 1 line
1.7.11.2
PATCH v3 14/15 cifs: replace kvec array in readdata with a single kvec
In reply to a message not in the archiveThe array is no longer needed. We just need a single kvec to hold the header for signature checking.
--- fs/cifs/cifsglob.h | 3 +-- fs/cifs/cifssmb.c | 29 ++++++++++++++--------------- fs/cifs/file.c | 9 --------- fs/cifs/smb2pdu.c | 12 ++++++------ 4 files changed, 21 insertions(+), 32 deletions(-)
fs/cifs/cifsglob.h +1 -2
@@ -980,10 +980,9 @@ struct cifs_readdata {int (*read_into_pages)(struct TCP_Server_Info *server,struct cifs_readdata *rdata,unsigned int len); +struct kvec iov;unsigned int pagesz;unsigned int tailsz; -unsigned int nr_iov; -struct kvec *iov;unsigned int nr_pages;struct page *pages[]; };
fs/cifs/cifssmb.c +14 -15
@@ -1436,10 +1436,10 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -HEADER_SIZE (server) +1 ; - rdata->iov[0 ].iov_base = buf +HEADER_SIZE (server) -1 ; - rdata->iov[0 ].iov_len = len; + rdata->iov.iov_base = buf +HEADER_SIZE (server) -1 ; + rdata->iov.iov_len = len; - length =cifs_readv_from_socket (server, rdata->iov,1 , len); + length =cifs_readv_from_socket (server, &rdata->iov,1 , len);if (length <0 )return length; server->total_read += length;
@@ -1485,20 +1485,19 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) len = data_offset - server->total_read;if (len >0 ) {/* read any junk before data into the rest of smallbuf */ - rdata->iov[0 ].iov_base = buf + server->total_read; - rdata->iov[0 ].iov_len = len; - length =cifs_readv_from_socket (server, rdata->iov,1 , len); + rdata->iov.iov_base = buf + server->total_read; + rdata->iov.iov_len = len; + length =cifs_readv_from_socket (server, &rdata->iov,1 , len);if (length <0 )return length; server->total_read += length; }/* set up first iov for signature check */ - rdata->iov[0 ].iov_base = buf; - rdata->iov[0 ].iov_len = server->total_read; - rdata->nr_iov =1 ; + rdata->iov.iov_base = buf; + rdata->iov.iov_len = server->total_read;cFYI (1 ,"0: iov_base=%p iov_len=%zu" , - rdata->iov[0 ].iov_base, rdata->iov[0 ].iov_len); + rdata->iov.iov_base, rdata->iov.iov_len);/* how much data is in the response? */ data_len = server->ops->read_data_length (buf);
@@ -1532,8 +1531,8 @@ cifs_readv_callback(struct mid_q_entry *mid)struct cifs_readdata *rdata = mid->callback_data;struct cifs_tcon *tcon =tlink_tcon (rdata->cfile->tlink);struct TCP_Server_Info *server = tcon->ses->server; -struct smb_rqst rqst = { .rq_iov = rdata->iov, - .rq_nvec = rdata->nr_iov, +struct smb_rqst rqst = { .rq_iov = &rdata->iov, + .rq_nvec =1 , .rq_pages = rdata->pages, .rq_npages = rdata->nr_pages, .rq_pagesz = rdata->pagesz,
@@ -1580,7 +1579,7 @@ cifs_async_readv(struct cifs_readdata *rdata)READ_REQ *smb =NULL ;int wct;struct cifs_tcon *tcon =tlink_tcon (rdata->cfile->tlink); -struct smb_rqst rqst = { .rq_iov = rdata->iov, +struct smb_rqst rqst = { .rq_iov = &rdata->iov, .rq_nvec =1 }; cFYI(1, "%s: offset=%llu bytes=%u", __func__,
@@ -1621,8 +1620,8 @@ cifs_async_readv(struct cifs_readdata *rdata) }/* 4 for RFC1001 length + 1 for BCC */ - rdata->iov[0 ].iov_base = smb; - rdata->iov[0 ].iov_len =be32_to_cpu (smb->hdr.smb_buf_length) +4 ; + rdata->iov.iov_base = smb; + rdata->iov.iov_len =be32_to_cpu (smb->hdr.smb_buf_length) +4 ;kref_get (&rdata->refcount); rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive,
fs/cifs/file.c +0 -9
@@ -2413,11 +2413,6 @@ static struct cifs_readdata * cifs_readdata_alloc(unsigned int nr_pages, work_func_t complete) {struct cifs_readdata *rdata; -struct kvec *iov; - - iov =kzalloc (sizeof (*iov) * (nr_pages +1 ),GFP_KERNEL ); -if (!iov) -return (struct cifs_readdata *)iov; rdata =kzalloc (sizeof (*rdata) + (sizeof (struct page *) * nr_pages),GFP_KERNEL );
@@ -2426,9 +2421,6 @@ cifs_readdata_alloc(unsigned int nr_pages, work_func_t complete)INIT_LIST_HEAD (&rdata->list);init_completion (&rdata->done);INIT_WORK (&rdata->work, complete); - rdata->iov = iov; - }else { -kfree (iov); }return rdata;
@@ -2443,7 +2435,6 @@ cifs_readdata_release(struct kref *refcount)if (rdata->cfile)cifsFileInfo_put (rdata->cfile); -kfree (rdata->iov);kfree (rdata); }
fs/cifs/smb2pdu.c +6 -6
@@ -1297,9 +1297,9 @@ smb2_readv_callback(struct mid_q_entry *mid)struct cifs_readdata *rdata = mid->callback_data;struct cifs_tcon *tcon =tlink_tcon (rdata->cfile->tlink);struct TCP_Server_Info *server = tcon->ses->server; -struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov[0 ].iov_base; +struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base;unsigned int credits_received =1 ; -struct smb_rqst rqst = { .rq_iov = rdata->iov, +struct smb_rqst rqst = { .rq_iov = &rdata->iov, .rq_nvec =1 , .rq_pages = rdata->pages, .rq_npages = rdata->nr_pages,
@@ -1346,7 +1346,7 @@ smb2_async_readv(struct cifs_readdata *rdata)int rc;struct smb2_hdr *buf;struct cifs_io_parms io_parms; -struct smb_rqst rqst = { .rq_iov = rdata->iov, +struct smb_rqst rqst = { .rq_iov = &rdata->iov, .rq_nvec =1 }; cFYI(1, "%s: offset=%llu bytes=%u", __func__,
@@ -1358,13 +1358,13 @@ smb2_async_readv(struct cifs_readdata *rdata) io_parms.persistent_fid = rdata->cfile->fid.persistent_fid; io_parms.volatile_fid = rdata->cfile->fid.volatile_fid; io_parms.pid = rdata->pid; - rc =smb2_new_read_req (&rdata->iov[0 ], &io_parms,0 ,0 ); + rc =smb2_new_read_req (&rdata->iov, &io_parms,0 ,0 );if (rc)return rc; - buf = (struct smb2_hdr *)rdata->iov[0 ].iov_base; + buf = (struct smb2_hdr *)rdata->iov.iov_base;/* 4 for rfc1002 length field */ - rdata->iov[0 ].iov_len =get_rfc1002_length (rdata->iov[0 ].iov_base) +4 ; + rdata->iov.iov_len =get_rfc1002_length (rdata->iov.iov_base) +4 ;kref_get (&rdata->refcount); rc = cifs_call_async(io_parms.tcon->ses->server, &rqst,
Signature · 1 line
1.7.11.2
PATCH v3 15/15 cifs: remove kmap lock and rsize limit
In reply to a message not in the archiveNow that we aren't abusing the kmap address space, there's no need for this lock or to impose a limit on the rsize.
--- fs/cifs/cifsfs.c | 4 ---- fs/cifs/cifsglob.h | 39 --------------------------------------- fs/cifs/smb1ops.c | 3 --- fs/cifs/smb2ops.c | 3 --- 4 files changed, 49 deletions(-)
fs/cifs/cifsfs.c +0 -4
@@ -88,10 +88,6 @@ extern mempool_t *cifs_mid_poolp;struct workqueue_struct *cifsiod_wq; -#ifdef CONFIG_HIGHMEM -DEFINE_MUTEX (cifs_kmap_mutex); -#endif -static int cifs_read_super (struct super_block *sb) {
fs/cifs/cifsglob.h +0 -39
@@ -637,45 +637,6 @@ get_next_mid(struct TCP_Server_Info *server)#define CIFS_DEFAULT_NON_POSIX_WSIZE (65536)/* -* On hosts with high memory, we can't currently support wsize/rsize that are -* larger than we can kmap at once. Cap the rsize/wsize at -* LAST_PKMAP * PAGE_SIZE. We'll never be able to fill a read or write request -* larger than that anyway. -*/ -#ifdef CONFIG_HIGHMEM -#define CIFS_KMAP_SIZE_LIMIT (LAST_PKMAP * PAGE_CACHE_SIZE) -#else /* CONFIG_HIGHMEM */ -#define CIFS_KMAP_SIZE_LIMIT (1<<24) -#endif /* CONFIG_HIGHMEM */ - -#ifdef CONFIG_HIGHMEM -/* -* On arches that have high memory, kmap address space is limited. By -* serializing the kmap operations on those arches, we ensure that we don't -* end up with a bunch of threads in writeback with partially mapped page -* arrays, stuck waiting for kmap to come back. That situation prevents -* progress and can deadlock. -*/ - -extern struct mutex cifs_kmap_mutex; - -static inline void -cifs_kmap_lock (void ) -{ -mutex_lock (&cifs_kmap_mutex); -} - -static inline void -cifs_kmap_unlock (void ) -{ -mutex_unlock (&cifs_kmap_mutex); -} -#else /* !CONFIG_HIGHMEM */ -#define cifs_kmap_lock () do { ; } while (0) -#define cifs_kmap_unlock () do { ; } while (0) -#endif /* CONFIG_HIGHMEM */ - -/* * Macros to allow the TCP_Server_Info->net field and related code to drop out * when CONFIG_NET_NS isn't set. */
fs/cifs/smb1ops.c +0 -3
@@ -483,9 +483,6 @@ cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)if (!(server->capabilities &CAP_LARGE_READ_X )) rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); -/* limit to the amount that we can kmap at once */ - rsize = min_t(unsigned int, rsize, CIFS_KMAP_SIZE_LIMIT); -/* hard limit of CIFS_MAX_RSIZE */ rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE);
fs/cifs/smb2ops.c +0 -3
@@ -205,9 +205,6 @@ smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)*/ rsize = min_t(unsigned int, rsize, 2 << 15); -/* limit to the amount that we can kmap at once */ - rsize = min_t(unsigned int, rsize, CIFS_KMAP_SIZE_LIMIT); -return rsize; }
Signature · 1 line
1.7.11.2
Pavel Shilovsky
Reviewed-byRe: [PATCH v3 11/15] cifs: allocate kvec array for cifs_readdata as a separate allocation
In reply to a message not in the archive2012/8/6 Jeff Layton <[email protected]>:
Quoted 68 lines
Eventually, we're going to want to append a list of pages to
cifs_readdatainstead of a list of kvecs. To prepare for that, turn the kvec array allocation into a separate one and just keep a pointer to it in the readdata.Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsglob.h | 2 +- fs/cifs/file.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-)fs/cifs/cifsglob.h +1
-1@@ -981,7 +981,7 @@ struct cifs_readdata {int (*marshal_iov) (struct cifs_readdata *rdata,unsigned int remaining);unsigned int nr_iov; -struct kvec iov[1 ]; +struct kvec *iov; };struct cifs_writedata ;fs/cifs/file.c +12
-4@@ -2410,19 +2410,27 @@ ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, }static struct cifs_readdata * -cifs_readdata_alloc (unsigned int nr_vecs,work_func_t complete) +cifs_readdata_alloc (unsigned int nr_pages,work_func_t complete) {struct cifs_readdata *rdata; +struct kvec *iov; - rdata =kzalloc (sizeof (*rdata) + -sizeof (struct kvec ) * nr_vecs,GFP_KERNEL ); + iov =kzalloc (sizeof (*iov) * (nr_pages +1 ),GFP_KERNEL ); +if (!iov) +return (struct cifs_readdata *)iov; + + rdata =kzalloc (sizeof (*rdata),GFP_KERNEL );if (rdata !=NULL ) {kref_init (&rdata->refcount);INIT_LIST_HEAD (&rdata->list);init_completion (&rdata->done);INIT_WORK (&rdata->work, complete);INIT_LIST_HEAD (&rdata->pages); + rdata->iov = iov; + }else { +kfree (iov); } +return rdata; }@@ -2435,6 +2443,7 @@ cifs_readdata_release(struct kref *refcount)if (rdata->cfile)cifsFileInfo_put (rdata->cfile); +kfree (rdata->iov);kfree (rdata); } --
Quoted 2 lines
1.7.11.2
Looks correct.
Signature · 2 lines
Best regards, Pavel Shilovsky.