netfs: Miscellaneous prep patches for rewrite of I/O layer
David Howells
maintainerv2 cover netfs: Miscellaneous prep patches for rewrite of I/O layer
Hi Steve,
Could you consider taking these patches extracted from my I/O layer rewrite for the upcoming merge window. The performance change should be neutral, but it cleans up the code a bit.
(1) Add the smb3_read_* tracepoints to SMB1 as well as SMB2/3.
(2) Use netfs_alloc/free_folioq_buffer() rather than cifs doing its own version.
(3) Rename struct mid_q_entry to smb_message. In my rewrite, smb_message will get allocated in the marshalling functions in smb2pdu.c and cifssmb.c rather than in transport.c and used to hand parameters down
- and so I think it could be better named for that.
(4) Remove the RFC1002 header from the smb_hdr struct so that it's consistent with SMB2/3. This allows I/O routines to be simplified and shared.
(5) Make SMB1's SendReceive() wrap cifs_send_recv() and thus share code
with SMB2/3.
(6) Clean up a bunch of extra kvec[] that were required for RFC1002 headers from SMB1's header struct.
(7) Replace SendReceiveBlockingLock() with SendReceive() plus flags.
(8) Remove the server pointer from smb_message. It can be passed down from the caller to all places that need it.
(9) Don't need state locking in smb2_get_mid_entry() as we're just doing a single read inside the lock. READ_ONCE() should suffice instead.
The patches can be found here also:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=cifs-next
Thanks,
David
Changes
=======
ver #2)
- Rebased on the ksmbd-for-next-next branch.
- Moved the patch to use netfs_alloc/free_folioq_buffer() down the stack.
David Howells (9):
cifs: Add the smb3_read_* tracepoints to SMB1
cifs: Use netfs_alloc/free_folioq_buffer()
cifs: Rename mid_q_entry to smb_message
cifs: Remove the RFC1002 header from smb_hdr
cifs: Make smb1's SendReceive() wrap cifs_send_recv()
cifs: Clean up some places where an extra kvec[] was required for
rfc1002
cifs: Replace SendReceiveBlockingLock() with SendReceive() plus flags
cifs: Remove the server pointer from smb_message
cifs: Don't need state locking in smb2_get_mid_entry()
fs/smb/client/cifs_debug.c | 47 +- fs/smb/client/cifs_debug.h | 2 +- fs/smb/client/cifsencrypt.c | 72 +-- fs/smb/client/cifsfs.c | 31 +- fs/smb/client/cifsglob.h | 92 ++-- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 76 ++-- fs/smb/client/cifssmb.c | 806 +++++++++++++++++++--------------- fs/smb/client/cifstransport.c | 432 +++--------------- fs/smb/client/connect.c | 188 ++++---- fs/smb/client/misc.c | 32 +- fs/smb/client/netmisc.c | 15 +- fs/smb/client/sess.c | 8 +- fs/smb/client/smb1ops.c | 113 +++-- fs/smb/client/smb2misc.c | 11 +- fs/smb/client/smb2ops.c | 206 +++------ fs/smb/client/smb2pdu.c | 48 +- fs/smb/client/smb2proto.h | 12 +- fs/smb/client/smb2transport.c | 111 +++-- fs/smb/client/transport.c | 281 ++++++------ fs/smb/common/smb2pdu.h | 3 - fs/smb/common/smbglob.h | 1 - 22 files changed, 1159 insertions(+), 1430 deletions(-)
David Howells
maintainerPATCH v2 1/9 cifs: Add the smb3_read_* tracepoints to SMB1
Add the smb3_read_* tracepoints to SMB1's cifs_async_readv() and cifs_readv_callback().
--- fs/smb/client/cifssmb.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
fs/smb/client/cifssmb.c +22 -0
@@ -1363,6 +1363,14 @@ cifs_readv_callback(struct mid_q_entry *mid)if (rdata->result == -ENODATA ) { rdata->result =0 ;__set_bit (NETFS_SREQ_HIT_EOF , &rdata->subreq.flags); +trace_smb3_read_err (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->xid, + rdata->req->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->subreq.len - rdata->subreq.transferred, + rdata->result); }else {size_t trans = rdata->subreq.transferred + rdata->got_bytes; if (trans < rdata->subreq.len &&
@@ -1374,6 +1382,13 @@ cifs_readv_callback(struct mid_q_entry *mid) }if (rdata->got_bytes)__set_bit (NETFS_SREQ_MADE_PROGRESS , &rdata->subreq.flags); +trace_smb3_read_done (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->xid, + rdata->req->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->got_bytes); } trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value,
@@ -1445,6 +1460,13 @@ cifs_async_readv(struct cifs_io_subrequest *rdata) rdata->iov[1 ].iov_base = (char *)smb +4 ; rdata->iov[1 ].iov_len =get_rfc1002_len (smb); +trace_smb3_read_enter (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->xid, + rdata->req->cfile->fid.netfid, + tcon->tid, tcon->ses->Suid, + rdata->subreq.start, rdata->subreq.len); + rc =cifs_call_async (tcon->ses->server, &rqst, cifs_readv_receive, cifs_readv_callback,NULL , rdata,0 ,NULL );
Re: [PATCH v2 1/9] cifs: Add the smb3_read_* tracepoints to SMB1
Quoted 8 lines · David Howells
Add the smb3_read_* tracepoints to SMB1's
cifs_async_readv()andcifs_readv_callback().Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Paulo Alcantara <[email protected]>
David Howells
maintainerPATCH v2 2/9 cifs: Use netfs_alloc/free_folioq_buffer()
In reply to David HowellsUse netfs_alloc/free_folioq_buffer() rather than doing its own version.
--- fs/smb/client/smb2ops.c | 73 ++++++----------------------------------- 1 file changed, 10 insertions(+), 63 deletions(-)
fs/smb/client/smb2ops.c +10 -63
@@ -4484,61 +4484,6 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,return rc; } -/* -* Clear a read buffer, discarding the folios which have the 1st mark set. -*/ -static void cifs_clear_folioq_buffer (struct folio_queue *buffer) -{ -struct folio_queue *folioq; - -while ((folioq = buffer)) { -for (int s =0 ; s <folioq_count (folioq); s++) -if (folioq_is_marked (folioq, s)) -folio_put (folioq_folio (folioq, s)); - buffer = folioq->next; -kfree (folioq); - } -} - -/* -* Allocate buffer space into a folio queue. -*/ -static struct folio_queue *cifs_alloc_folioq_buffer (ssize_t size) -{ -struct folio_queue *buffer =NULL , *tail =NULL , *p; -struct folio *folio; -unsigned int slot; - -do { -if (!tail ||folioq_full (tail)) { - p =kmalloc (sizeof (*p),GFP_NOFS ); -if (!p) - goto nomem; -folioq_init (p,0 ); -if (tail) { - tail->next = p; - p->prev = tail; - }else { - buffer = p; - } - tail = p; - } - - folio =folio_alloc (GFP_KERNEL |__GFP_HIGHMEM,0 ); -if (!folio) - goto nomem; - - slot =folioq_append_mark (tail, folio); - size -=folioq_folio_size (tail, slot); - }while (size >0 ); - -return buffer; - -nomem: -cifs_clear_folioq_buffer (buffer); -return NULL ; -} -/* * Copy data from an iterator to the folios in a folio queue buffer. */
@@ -4564,7 +4509,7 @@ void smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst) {for (int i =0 ; i < num_rqst; i++) -cifs_clear_folioq_buffer (rqst[i].rq_buffer); +netfs_free_folioq_buffer (rqst[i].rq_buffer); }/*
@@ -4599,8 +4544,10 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, new->rq_nvec = old->rq_nvec;if (size >0 ) { - buffer =cifs_alloc_folioq_buffer (size); -if (!buffer) +size_t cur_size =0 ; + rc =netfs_alloc_folioq_buffer (NULL , &buffer, &cur_size, + size,GFP_NOFS ); +if (rc <0 ) goto err_free; new->rq_buffer = buffer;
@@ -4932,7 +4879,7 @@ static void smb2_decrypt_offload(struct work_struct *work) } free_pages: -cifs_clear_folioq_buffer (dw->buffer); +netfs_free_folioq_buffer (dw->buffer);cifs_small_buf_release (dw->buf);kfree (dw); }
@@ -4970,9 +4917,9 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, dw->len = len; len =round_up (dw->len,PAGE_SIZE ); - rc = -ENOMEM ; - dw->buffer =cifs_alloc_folioq_buffer (len); -if (!dw->buffer) +size_t cur_size =0 ; + rc =netfs_alloc_folioq_buffer (NULL , &dw->buffer, &cur_size, len,GFP_NOFS ); +if (rc <0 ) goto discard_data;iov_iter_folio_queue (&iter,ITER_DEST , dw->buffer,0 ,0 , len);
@@ -5033,7 +4980,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, } free_pages: -cifs_clear_folioq_buffer (dw->buffer); +netfs_free_folioq_buffer (dw->buffer); free_dw:kfree (dw);return rc;
David Howells
maintainerPATCH v2 3/9 cifs: Rename mid_q_entry to smb_message
In reply to David Howells--- fs/smb/client/cifs_debug.c | 43 +++--- fs/smb/client/cifsfs.c | 31 +++-- fs/smb/client/cifsglob.h | 62 ++++----- fs/smb/client/cifsproto.h | 34 ++--- fs/smb/client/cifssmb.c | 82 ++++++------ fs/smb/client/cifstransport.c | 168 ++++++++++++------------ fs/smb/client/connect.c | 152 +++++++++++----------- fs/smb/client/netmisc.c | 14 +- fs/smb/client/smb1ops.c | 46 +++---- fs/smb/client/smb2misc.c | 8 +- fs/smb/client/smb2ops.c | 122 ++++++++--------- fs/smb/client/smb2pdu.c | 47 ++++--- fs/smb/client/smb2proto.h | 10 +- fs/smb/client/smb2transport.c | 62 ++++----- fs/smb/client/transport.c | 238 +++++++++++++++++----------------- 15 files changed, 560 insertions(+), 559 deletions(-)
fs/smb/client/cifs_debug.c +21 -22
@@ -55,33 +55,32 @@ void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)void cifs_dump_mids (struct TCP_Server_Info *server) {#ifdef CONFIG_CIFS_DEBUG2 -struct mid_q_entry *mid_entry; +struct smb_message *smb;if (server ==NULL )return ;cifs_dbg (VFS ,"Dump pending requests:\n" );spin_lock (&server->mid_queue_lock); -list_for_each_entry (mid_entry, &server->pending_mid_q, qhead) { +list_for_each_entry (smb, &server->pending_mid_q, qhead) {cifs_dbg (VFS ,"State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n" , - mid_entry->mid_state, -le16_to_cpu (mid_entry->command), - mid_entry->pid, - mid_entry->callback_data, - mid_entry->mid); + smb->mid_state, +le16_to_cpu (smb->command), + smb->pid, + smb->callback_data, + smb->mid);#ifdef CONFIG_CIFS_STATS2 cifs_dbg (VFS ,"IsLarge: %d buf: %p time rcv: %ld now: %ld\n" , - mid_entry->large_buf, - mid_entry->resp_buf, - mid_entry->when_received, + smb->large_buf, + smb->resp_buf, + smb->when_received, jiffies);#endif /* STATS2 */ cifs_dbg (VFS ,"IsMult: %d IsEnd: %d\n" , - mid_entry->multiRsp, mid_entry->multiEnd); -if (mid_entry->resp_buf) { -cifs_dump_detail (mid_entry->resp_buf, server); -cifs_dump_mem ("existing buf: " , - mid_entry->resp_buf,62 ); + smb->multiRsp, smb->multiEnd); +if (smb->resp_buf) { +cifs_dump_detail (smb->resp_buf, server); +cifs_dump_mem ("existing buf: " , smb->resp_buf,62 ); } }spin_unlock (&server->mid_queue_lock);
@@ -395,7 +394,7 @@ static __always_inline const char *cipher_alg_str(__le16 cipher)static int cifs_debug_data_proc_show (struct seq_file *m,void *v) { -struct mid_q_entry *mid_entry; +struct smb_message *smb;struct TCP_Server_Info *server;struct TCP_Server_Info *chan_server;struct cifs_ses *ses;
@@ -716,13 +715,13 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)seq_printf (m,"\n\tServer ConnectionId: 0x%llx" , chan_server->conn_id);spin_lock (&chan_server->mid_queue_lock); -list_for_each_entry (mid_entry, &chan_server->pending_mid_q, qhead) { +list_for_each_entry (smb, &chan_server->pending_mid_q, qhead) {seq_printf (m,"\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu" , - mid_entry->mid_state, -le16_to_cpu (mid_entry->command), - mid_entry->pid, - mid_entry->callback_data, - mid_entry->mid); + smb->mid_state, +le16_to_cpu (smb->command), + smb->pid, + smb->callback_data, + smb->mid); }spin_unlock (&chan_server->mid_queue_lock); }
fs/smb/client/cifsfs.c +15 -16
@@ -436,13 +436,13 @@ static int cifs_permission(struct mnt_idmap *idmap,static struct kmem_cache *cifs_inode_cachep;static struct kmem_cache *cifs_req_cachep; -static struct kmem_cache *cifs_mid_cachep; +static struct kmem_cache *smb_message_cachep;static struct kmem_cache *cifs_sm_req_cachep;static struct kmem_cache *cifs_io_request_cachep;static struct kmem_cache *cifs_io_subrequest_cachep;mempool_t *cifs_sm_req_poolp;mempool_t *cifs_req_poolp; -mempool_t *cifs_mid_poolp; +mempool_t smb_message_pool;mempool_t cifs_io_request_pool;mempool_t cifs_io_subrequest_pool;
@@ -1835,28 +1835,27 @@ cifs_destroy_request_bufs(void)kmem_cache_destroy (cifs_sm_req_cachep); } -static int init_mids (void ) +static int init_smb_message (void ) { - cifs_mid_cachep =kmem_cache_create ("cifs_mpx_ids" , -sizeof (struct mid_q_entry ),0 , -SLAB_HWCACHE_ALIGN ,NULL ); -if (cifs_mid_cachep ==NULL ) + smb_message_cachep =kmem_cache_create ("cifs_smb_message" , +sizeof (struct smb_message ),0 , +SLAB_HWCACHE_ALIGN ,NULL ); +if (smb_message_cachep ==NULL )return -ENOMEM ;/* 3 is a reasonable minimum number of simultaneous operations */ - cifs_mid_poolp =mempool_create_slab_pool (3 , cifs_mid_cachep); -if (cifs_mid_poolp ==NULL ) { -kmem_cache_destroy (cifs_mid_cachep); +if (mempool_init_slab_pool (&smb_message_pool,3 , smb_message_cachep) <0 ) { +kmem_cache_destroy (smb_message_cachep);return -ENOMEM ; }return 0 ; } -static void destroy_mids (void ) +static void destroy_smb_message (void ) { -mempool_destroy (cifs_mid_poolp); -kmem_cache_destroy (cifs_mid_cachep); +mempool_exit (&smb_message_pool); +kmem_cache_destroy (smb_message_cachep); }static int cifs_init_netfs (void )
@@ -2020,7 +2019,7 @@ init_cifs(void)if (rc) goto out_destroy_inodecache; - rc =init_mids (); + rc =init_smb_message ();if (rc) goto out_destroy_netfs;
@@ -2077,7 +2076,7 @@ init_cifs(void)#endif cifs_destroy_request_bufs (); out_destroy_mids: -destroy_mids (); +destroy_smb_message (); out_destroy_netfs:cifs_destroy_netfs (); out_destroy_inodecache:
@@ -2119,7 +2118,7 @@ exit_cifs(void)dfs_cache_destroy ();#endif cifs_destroy_request_bufs (); -destroy_mids (); +destroy_smb_message ();cifs_destroy_netfs ();cifs_destroy_inodecache ();destroy_workqueue (deferredclose_wq);
fs/smb/client/cifsglob.h +31 -31
158 lines not on this page · raw message
fs/smb/client/cifsproto.h +17 -17
@@ -84,11 +84,11 @@ extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx, int add_treename);extern char *build_wildcard_path_from_dentry (struct dentry *direntry);char *cifs_build_devname (char *nodename,const char *prepath); -extern void delete_mid (struct mid_q_entry *mid); +extern void delete_mid (struct smb_message *smb);void __release_mid (struct kref *refcount); -extern void cifs_wake_up_task (struct mid_q_entry *mid); +extern void cifs_wake_up_task (struct smb_message *smb);extern int cifs_handle_standard (struct TCP_Server_Info *server, -struct mid_q_entry *mid); +struct smb_message *smb);extern char *smb3_fs_context_fullpath (const struct smb3_fs_context *ctx,char dirsep);extern int smb3_parse_devname (const char *devname,struct smb3_fs_context *ctx);
@@ -98,8 +98,8 @@ extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs);extern int cifs_discard_remaining_data (struct TCP_Server_Info *server);extern int cifs_call_async (struct TCP_Server_Info *server,struct smb_rqst *rqst, -mid_receive_t *receive,mid_callback_t *callback, -mid_handle_t *handle,void *cbdata,const int flags, +mid_receive_t receive,mid_callback_t callback, +mid_handle_t handle,void *cbdata,const int flags,const struct cifs_credits *exist_credits);extern struct TCP_Server_Info *cifs_pick_channel (struct cifs_ses *ses); extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
@@ -117,15 +117,15 @@ extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, int * /* bytes returned */ , const int);extern int SendReceiveNoRsp (const unsigned int xid,struct cifs_ses *ses,char *in_buf,int flags); -int cifs_sync_mid_result (struct mid_q_entry *mid,struct TCP_Server_Info *server); -extern struct mid_q_entry *cifs_setup_request (struct cifs_ses *, +int cifs_sync_mid_result (struct smb_message *smb,struct TCP_Server_Info *server); +extern struct smb_message *cifs_setup_request (struct cifs_ses *,struct TCP_Server_Info *,struct smb_rqst *); -extern struct mid_q_entry *cifs_setup_async_request (struct TCP_Server_Info *, +extern struct smb_message *cifs_setup_async_request (struct TCP_Server_Info *,struct smb_rqst *);int __smb_send_rqst (struct TCP_Server_Info *server,int num_rqst,struct smb_rqst *rqst); -extern int cifs_check_receive (struct mid_q_entry *mid, +extern int cifs_check_receive (struct smb_message *msg,struct TCP_Server_Info *server,bool log_error);int wait_for_free_request (struct TCP_Server_Info *server,const int flags,unsigned int *instance);
@@ -135,13 +135,13 @@ extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server,static inline int send_cancel (struct TCP_Server_Info *server,struct smb_rqst *rqst, -struct mid_q_entry *mid) +struct smb_message *smb) {return server->ops->send_cancel ? - server->ops->send_cancel (server, rqst, mid) :0 ; + server->ops->send_cancel (server, rqst, smb) :0 ; } -int wait_for_response (struct TCP_Server_Info *server,struct mid_q_entry *midQ); +int wait_for_response (struct TCP_Server_Info *server,struct smb_message *smb); extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, struct kvec *, int /* nvec to send */, int * /* type of buf returned */, const int flags,
@@ -187,7 +187,7 @@ extern int decode_negTokenInit(unsigned char *security_blob, int length,extern int cifs_convert_address (struct sockaddr *dst,const char *src,int len);extern void cifs_set_port (struct sockaddr *addr,const unsigned short int port);extern int map_smb_to_linux_error (char *buf,bool logErr); -extern int map_and_check_smb_error (struct mid_q_entry *mid,bool logErr); +extern int map_and_check_smb_error (struct smb_message *smb,bool logErr);extern void header_assemble (struct smb_hdr *,char /* command */ ,const struct cifs_tcon *,int /* length of fixed section (word count) in two byte units */ );
@@ -270,7 +270,7 @@ extern unsigned int setup_special_mode_ACE(struct smb_ace *pace, __u64 nmode);extern unsigned int setup_special_user_owner_ACE (struct smb_ace *pace); -extern void dequeue_mid (struct mid_q_entry *mid,bool malformed); +extern void dequeue_mid (struct smb_message *smb,bool malformed);extern int cifs_read_from_socket (struct TCP_Server_Info *server,char *buf,unsigned int to_read); extern ssize_t cifs_discard_from_socket(struct TCP_Server_Info *server,
@@ -624,7 +624,7 @@ extern struct cifs_ses * cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx);int cifs_async_readv (struct cifs_io_subrequest *rdata); -int cifs_readv_receive (struct TCP_Server_Info *server,struct mid_q_entry *mid); +int cifs_readv_receive (struct TCP_Server_Info *server,struct smb_message *smb);void cifs_async_writev (struct cifs_io_subrequest *wdata); int cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
@@ -777,9 +777,9 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)return true; } -static inline void release_mid (struct mid_q_entry *mid) +static inline void release_mid (struct smb_message *smb) { -kref_put (&mid->refcount, __release_mid); +kref_put (&smb->refcount, __release_mid); }static inline void cifs_free_open_info (struct cifs_open_info_data *data)
fs/smb/client/cifssmb.c +41 -41
182 lines not on this page · raw message
fs/smb/client/cifstransport.c +85 -83
389 lines not on this page · raw message
fs/smb/client/connect.c +76 -76
304 lines not on this page · raw message
fs/smb/client/netmisc.c +7 -7
@@ -889,22 +889,22 @@ map_smb_to_linux_error(char *buf, bool logErr) }int -map_and_check_smb_error (struct mid_q_entry *mid,bool logErr) +map_and_check_smb_error (struct smb_message *smb,bool logErr) {int rc; -struct smb_hdr *smb = (struct smb_hdr *)mid->resp_buf; +struct smb_hdr *rhdr = (struct smb_hdr *)smb->resp_buf; - rc =map_smb_to_linux_error ((char *)smb, logErr); -if (rc == -EACCES && !(smb->Flags2 &SMBFLG2_ERR_STATUS )) { + rc =map_smb_to_linux_error ((char *)rhdr, logErr); +if (rc == -EACCES && !(rhdr->Flags2 &SMBFLG2_ERR_STATUS )) {/* possible ERRBaduid */ -__u8 class = smb->Status.DosError.ErrorClass; -__u16 code =le16_to_cpu (smb->Status.DosError.Error); +__u8 class = rhdr->Status.DosError.ErrorClass; +__u16 code =le16_to_cpu (rhdr->Status.DosError.Error);/* switch can be used to handle different errors */ if (class ==ERRSRV && code == ERRbaduid) {cifs_dbg (FYI ,"Server returned 0x%x, reconnecting session...\n" , code); -cifs_signal_cifsd_for_reconnect (mid->server, false); +cifs_signal_cifsd_for_reconnect (smb->server, false); } }
fs/smb/client/smb1ops.c +23 -23
111 lines not on this page · raw message
fs/smb/client/smb2misc.c +4 -4
@@ -851,14 +851,14 @@ smb2_handle_cancelled_close(struct cifs_tcon *tcon, __u64 persistent_fid, }int -smb2_handle_cancelled_mid (struct mid_q_entry *mid,struct TCP_Server_Info *server) +smb2_handle_cancelled_mid (struct smb_message *smb,struct TCP_Server_Info *server) { -struct smb2_hdr *hdr = mid->resp_buf; -struct smb2_create_rsp *rsp = mid->resp_buf; +struct smb2_hdr *hdr = smb->resp_buf; +struct smb2_create_rsp *rsp = smb->resp_buf;struct cifs_tcon *tcon;int rc; -if ((mid->optype &CIFS_CP_CREATE_CLOSE_OP ) || hdr->Command !=SMB2_CREATE || +if ((smb->optype &CIFS_CP_CREATE_CLOSE_OP ) || hdr->Command !=SMB2_CREATE || hdr->Status !=STATUS_SUCCESS )return 0 ;
fs/smb/client/smb2ops.c +61 -61
312 lines not on this page · raw message
fs/smb/client/smb2pdu.c +23 -24
118 lines not on this page · raw message
fs/smb/client/smb2proto.h +5 -5
@@ -30,12 +30,12 @@ extern __le16 *cifs_convert_path_to_utf16(const char *from, struct cifs_sb_info *cifs_sb);extern int smb2_verify_signature (struct smb_rqst *,struct TCP_Server_Info *); -extern int smb2_check_receive (struct mid_q_entry *mid, +extern int smb2_check_receive (struct smb_message *smb,struct TCP_Server_Info *server,bool log_error); -extern struct mid_q_entry *smb2_setup_request (struct cifs_ses *ses, +extern struct smb_message *smb2_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *,struct smb_rqst *rqst); -extern struct mid_q_entry *smb2_setup_async_request ( +extern struct smb_message *smb2_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst);extern struct cifs_tcon *smb2_find_smb_tcon (struct TCP_Server_Info *server,__u64 ses_id,__u32 tid);
@@ -44,7 +44,7 @@ extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);extern bool smb2_is_valid_oplock_break (char *buffer,struct TCP_Server_Info *srv);extern int smb3_handle_read_data (struct TCP_Server_Info *server, -struct mid_q_entry *mid); +struct smb_message *smb);extern int smb2_query_reparse_tag (const unsigned int xid,struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb,const char *path,__u32 *reparse_tag);
@@ -251,7 +251,7 @@ extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,extern int smb2_handle_cancelled_close (struct cifs_tcon *tcon,__u64 persistent_fid,__u64 volatile_fid); -extern int smb2_handle_cancelled_mid (struct mid_q_entry *mid,struct TCP_Server_Info *server); +extern int smb2_handle_cancelled_mid (struct smb_message *smb,struct TCP_Server_Info *server);void smb2_cancelled_close_fid (struct work_struct *work); extern int SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_file_id, u64 volatile_file_id,
fs/smb/client/smb2transport.c +31 -31
143 lines not on this page · raw message
fs/smb/client/transport.c +120 -118
516 lines not on this page · raw message
David Howells
maintainerPATCH v2 4/9 cifs: Remove the RFC1002 header from smb_hdr
In reply to David HowellsRemove the RFC1002 header from struct smb_hdr as used for SMB-1.0. This simplifies the SMB-1.0 code by simplifying a lot of places that have to add or subtract 4 to work around the fact that the RFC1002 header isn't really part of the message and the base for various offsets within the message is from the base of the smb_hdr, not the RFC1002 header.
Further, clean up a bunch of places that require an extra kvec struct specifically pointing to the RFC1002 header, such that kvec[0].iov_base must be exactly 4 bytes before kvec[1].iov_base.
This allows the header preamble size stuff to be removed too.
The size of the request and response message are then handed around either directly or by summing the size of all the iov_len members in the kvec array for which we have a count.
Also, this simplifies and cleans up the common transmission and receive paths for SMB1 and SMB2/3 as there no longer needs to be special handling casing for SMB1 messages as the RFC1002 header is now generated on the fly for SMB1 as it is for SMB2/3.
--- fs/smb/client/cifs_debug.c | 6 +- fs/smb/client/cifs_debug.h | 2 +- fs/smb/client/cifsencrypt.c | 36 +- fs/smb/client/cifsglob.h | 20 +- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 32 +- fs/smb/client/cifssmb.c | 695 +++++++++++++++++++--------------- fs/smb/client/cifstransport.c | 128 +++---- fs/smb/client/connect.c | 36 +- fs/smb/client/misc.c | 32 +- fs/smb/client/sess.c | 8 +- fs/smb/client/smb1ops.c | 21 +- fs/smb/client/smb2misc.c | 3 +- fs/smb/client/smb2ops.c | 11 +- fs/smb/client/smb2proto.h | 2 +- fs/smb/client/transport.c | 22 +- fs/smb/common/smb2pdu.h | 3 - fs/smb/common/smbglob.h | 1 - 18 files changed, 540 insertions(+), 520 deletions(-)
fs/smb/client/cifs_debug.c +3 -3
@@ -37,7 +37,7 @@ cifs_dump_mem(char *label, void *data, int length) data, length, true); } -void cifs_dump_detail (void *buf,struct TCP_Server_Info *server) +void cifs_dump_detail (void *buf,size_t buf_len,struct TCP_Server_Info *server) {#ifdef CONFIG_CIFS_DEBUG2 struct smb_hdr *smb = buf;
@@ -45,7 +45,7 @@ void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)cifs_dbg (VFS ,"Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n" , smb->Command, smb->Status.CifsError, smb->Flags, smb->Flags2, smb->Mid, smb->Pid, smb->WordCount); -if (!server->ops->check_message (buf, server->total_read, server)) { +if (!server->ops->check_message (buf, buf_len, server->total_read, server)) {cifs_dbg (VFS ,"smb buf %p len %u\n" , smb, server->ops->calc_smb_size (smb)); }
@@ -79,7 +79,7 @@ void cifs_dump_mids(struct TCP_Server_Info *server)cifs_dbg (VFS ,"IsMult: %d IsEnd: %d\n" , smb->multiRsp, smb->multiEnd);if (smb->resp_buf) { -cifs_dump_detail (smb->resp_buf, server); +cifs_dump_detail (smb->resp_buf, smb->response_pdu_len, server);cifs_dump_mem ("existing buf: " , smb->resp_buf,62 ); } }
fs/smb/client/cifs_debug.h +1 -1
@@ -15,7 +15,7 @@#define pr_fmt (fmt) "CIFS: " fmtvoid cifs_dump_mem (char *label,void *data,int length); -void cifs_dump_detail (void *buf,struct TCP_Server_Info *ptcp_info); +void cifs_dump_detail (void *buf,size_t buf_len,struct TCP_Server_Info *ptcp_info);void cifs_dump_mids (struct TCP_Server_Info *);extern bool traceSMB;/* flag which enables the function below */ void dump_smb (void *,int );
fs/smb/client/cifsencrypt.c +8 -28
@@ -91,18 +91,7 @@ int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,struct kvec *iov = rqst->rq_iov;int n_vec = rqst->rq_nvec; -/* iov[0] is actual data and not the rfc1002 length for SMB2+ */ -if (!is_smb1 (server)) { -if (iov[0 ].iov_len <=4 ) -return -EIO ; - i =0 ; - }else { -if (n_vec <2 || iov[0 ].iov_len !=4 ) -return -EIO ; - i =1 ;/* skip rfc1002 length */ - } - -for (; i < n_vec; i++) { +for (i =0 ; i < n_vec; i++) {if (iov[i].iov_len ==0 )continue ;if (iov[i].iov_base ==NULL ) {
@@ -165,10 +154,6 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,char smb_signature[20 ];struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; -if (rqst->rq_iov[0 ].iov_len !=4 || - rqst->rq_iov[0 ].iov_base +4 != rqst->rq_iov[1 ].iov_base) -return -EIO ; -if ((cifs_pdu ==NULL ) || (server ==NULL ))return -EINVAL ;
@@ -211,17 +196,16 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, }/* must be called with server->srv_mutex held */ -int cifs_sign_smb (struct smb_hdr *cifs_pdu,struct TCP_Server_Info *server, +int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, +struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number) { -struct kvec iov[2 ]; +struct kvec iov[1 ] = { + [0 ].iov_base = (char *)cifs_pdu, + [0 ].iov_len = pdu_len, + }; - iov[0 ].iov_base = cifs_pdu; - iov[0 ].iov_len =4 ; - iov[1 ].iov_base = (char *)cifs_pdu +4 ; - iov[1 ].iov_len =be32_to_cpu (cifs_pdu->smb_buf_length); - -return cifs_sign_smbv (iov,2 , server, +return cifs_sign_smbv (iov,ARRAY_SIZE (iov), server, pexpected_response_sequence_number); }
@@ -234,10 +218,6 @@ int cifs_verify_signature(struct smb_rqst *rqst,char what_we_think_sig_should_be[20 ];struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; -if (rqst->rq_iov[0 ].iov_len !=4 || - rqst->rq_iov[0 ].iov_base +4 != rqst->rq_iov[1 ].iov_base) -return -EIO ; -if (cifs_pdu ==NULL || server ==NULL )return -EINVAL ;
fs/smb/client/cifsglob.h +10 -10
@@ -347,12 +347,12 @@ struct smb_version_operations {int (*map_error)(char *,bool );/* find mid corresponding to the response message */ struct smb_message * (*find_mid)(struct TCP_Server_Info *,char *); -void (*dump_detail)(void *buf,struct TCP_Server_Info *ptcp_info); +void (*dump_detail)(void *buf,size_t buf_len,struct TCP_Server_Info *ptcp_info);void (*clear_stats)(struct cifs_tcon *);void (*print_stats)(struct seq_file *m,struct cifs_tcon *);void (*dump_share_caps)(struct seq_file *,struct cifs_tcon *);/* verify the message */ -int (*check_message)(char *,unsigned int ,struct TCP_Server_Info *); +int (*check_message)(char *,unsigned int ,unsigned int ,struct TCP_Server_Info *);bool (*is_oplock_break)(char *,struct TCP_Server_Info *);int (*handle_cancelled_mid)(struct smb_message *smb,struct TCP_Server_Info *server); void (*downgrade_oplock)(struct TCP_Server_Info *server,
@@ -636,8 +636,7 @@ struct smb_version_operations {#define HEADER_SIZE (server) (server->vals->header_size)#define MAX_HEADER_SIZE (server) (server->vals->max_header_size) -#define HEADER_PREAMBLE_SIZE (server) (server->vals->header_preamble_size) -#define MID_HEADER_SIZE (server) (HEADER_SIZE(server) - 1 - HEADER_PREAMBLE_SIZE(server)) +#define MID_HEADER_SIZE (server) (HEADER_SIZE(server) - 1)/** * CIFS superblock mount flags (mnt_cifs_flags) to consider when
@@ -832,9 +831,9 @@ struct TCP_Server_Info {char dns_dom[CIFS_MAX_DOMAINNAME_LEN +1 ]; }; -static inline bool is_smb1 (struct TCP_Server_Info *server) +static inline bool is_smb1 (const struct TCP_Server_Info *server) { -return HEADER_PREAMBLE_SIZE (server) !=0 ; +return server->vals->protocol_id ==SMB10_PROT_ID ; }static inline void cifs_server_lock (struct TCP_Server_Info *server)
@@ -973,16 +972,16 @@ compare_mid(__u16 mid, const struct smb_hdr *smb)* of kvecs to handle the receive, though that should only need to be done * once. */ -#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) -#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) +#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ)) +#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP))/* * When the server doesn't allow large posix writes, only allow a rsize/wsize * of 2^17-1 minus the size of the call header. That allows for a read or * write up to the maximum size described by RFC1002. */ -#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) -#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) +#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ)) +#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP))/* * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
@@ -1701,6 +1700,7 @@ struct smb_message {struct task_struct *creator;void *resp_buf;/* pointer to received SMB header */ unsigned int resp_buf_size; +u32 response_pdu_len;int mid_state;/* wish this were enum but can not pass to wait_event */ int mid_rc;/* rc for MID_RC */ __le16 command;/* smb command code */
fs/smb/client/cifspdu.h +1 -1
@@ -90,7 +90,7 @@/* future chained NTCreateXReadX bigger, but for time being NTCreateX biggest */ /* among the requests (NTCreateX response is bigger with wct of 34) */ -#define MAX_CIFS_HDR_SIZE 0x58/* 4 len + 32 hdr + (2*24 wct) + 2 bct + 2 pad */ +#define MAX_CIFS_HDR_SIZE 0x54/* 32 hdr + (2*24 wct) + 2 bct + 2 pad */ #define CIFS_SMALL_PATH 120/* allows for (448-88)/3 */ /* internal cifs vfs structures */
fs/smb/client/cifsproto.h +16 -16
@@ -111,12 +111,11 @@ extern int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, const int flags, const int num_rqst, struct smb_rqst *rqst, int *resp_buf_type, struct kvec *resp_iov); -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); +int SendReceive (const unsigned int xid,struct cifs_ses *ses, +struct smb_hdr *in_buf,unsigned int in_len, +struct smb_hdr *out_buf,int *pbytes_returned,const int flags); +int SendReceiveNoRsp (const unsigned int xid,struct cifs_ses *ses, +char *in_buf,unsigned int in_len,int flags);int cifs_sync_mid_result (struct smb_message *smb,struct TCP_Server_Info *server); extern struct smb_message *cifs_setup_request(struct cifs_ses *, struct TCP_Server_Info *,
@@ -146,11 +145,9 @@ extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, struct kvec *, int /* nvec to send */, int * /* type of buf returned */, const int flags, struct kvec * /* resp vec */); -extern int SendReceiveBlockingLock (const unsigned int xid, -struct cifs_tcon *ptcon, -struct smb_hdr *in_buf, -struct smb_hdr *out_buf, -int *bytes_returned); +int SendReceiveBlockingLock (const unsigned int xid,struct cifs_tcon *tcon, +struct smb_hdr *in_buf,unsigned int in_len, +struct smb_hdr *out_buf,int *pbytes_returned);void smb2_query_server_interfaces (struct work_struct *work);void
@@ -161,7 +158,8 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server, bool mark_smb_session);extern int cifs_reconnect (struct TCP_Server_Info *server,bool mark_smb_session); -extern int checkSMB (char *buf,unsigned int len,struct TCP_Server_Info *srvr); +int checkSMB (char *buf,unsigned int pdu_len,unsigned int len, +struct TCP_Server_Info *srvr);extern bool is_valid_oplock_break (char *,struct TCP_Server_Info *);extern bool backup_cred (struct cifs_sb_info *); extern bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 eof,
@@ -188,9 +186,9 @@ extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);extern void cifs_set_port (struct sockaddr *addr,const unsigned short int port);extern int map_smb_to_linux_error (char *buf,bool logErr);extern int map_and_check_smb_error (struct smb_message *smb,bool logErr); -extern void header_assemble (struct smb_hdr *,char /* command */ , -const struct cifs_tcon *,int /* length of -fixed section (word count) in two byte units */ ); +unsigned int header_assemble (struct smb_hdr *,char /* command */ , +const struct cifs_tcon *, +int /* length of fixed section (word count) in two byte units */ );extern int small_smb_init_no_tc (const int smb_cmd,const int wct,struct cifs_ses *ses,void **request_buf);
@@ -567,7 +565,9 @@ 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_sign_smb (struct smb_hdr *,struct TCP_Server_Info *,__u32 *); +int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, +struct TCP_Server_Info *server, +__u32 *pexpected_response_sequence_number);extern int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number);
fs/smb/client/cifssmb.c +394 -301
2,311 lines not on this page · raw message
fs/smb/client/cifstransport.c +47 -81
271 lines not on this page · raw message
fs/smb/client/connect.c +17 -19
@@ -1155,15 +1155,14 @@ standard_receive3(struct TCP_Server_Info *server, struct smb_message *smb)unsigned int pdu_length = server->pdu_size;/* make sure this will fit in a large buffer */ -if (pdu_length > CIFSMaxBufSize +MAX_HEADER_SIZE (server) - -HEADER_PREAMBLE_SIZE (server)) { +if (pdu_length > CIFSMaxBufSize +MAX_HEADER_SIZE (server)) {cifs_server_dbg (VFS ,"SMB response too long (%u bytes)\n" , pdu_length);cifs_reconnect (server, true);return -ECONNABORTED ; }/* switch to large buffer if too big for a small one */ -if (pdu_length >MAX_CIFS_SMALL_BUFFER_SIZE -4 ) { +if (pdu_length >MAX_CIFS_SMALL_BUFFER_SIZE ) { server->large_buf = true;memcpy (server->bigbuf, buf, server->total_read); buf = server->bigbuf;
@@ -1196,7 +1195,8 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct smb_message *smb)* 48 bytes is enough to display the header and a little bit * into the payload for debugging purposes. */ - rc = server->ops->check_message (buf, server->total_read, server); + rc = server->ops->check_message (buf, server->pdu_size, + server->total_read, server);if (rc)cifs_dump_mem ("Bad SMB: " , buf, min_t(unsigned int, server->total_read, 48));
@@ -1286,16 +1286,13 @@ cifs_demultiplex_thread(void *p)if (length <0 )continue ; -if (is_smb1 (server)) - server->total_read = length; -else - server->total_read =0 ; + server->total_read =0 ;/* * The right amount was read from socket - 4 bytes, * so we can now interpret the length field. */ - pdu_length =get_rfc1002_len (buf); + pdu_length =be32_to_cpup (((__be32 *)buf)) &0xffffff ;cifs_dbg (FYI ,"RFC1002 header 0x%x\n" , pdu_length);if (!is_smb_response (server, buf[0 ]))
@@ -1314,9 +1311,8 @@ cifs_demultiplex_thread(void *p) }/* read down to the MID */ - length =cifs_read_from_socket (server, - buf +HEADER_PREAMBLE_SIZE (server), -MID_HEADER_SIZE (server)); + length =cifs_read_from_socket (server, buf, +MID_HEADER_SIZE (server));if (length <0 )continue ; server->total_read += length;
@@ -1348,6 +1344,8 @@ cifs_demultiplex_thread(void *p) bufs[0 ] = buf; num_smbs =1 ; +if (smbs[0 ]) + smbs[0 ]->response_pdu_len = pdu_length;if (!smbs[0 ] || !smbs[0 ]->receive) length =standard_receive3 (server, smbs[0 ]);else
@@ -1406,7 +1404,7 @@ cifs_demultiplex_thread(void *p)smb2_add_credits_from_hdr (bufs[i], server);#ifdef CONFIG_CIFS_DEBUG2 if (server->ops->dump_detail) - server->ops->dump_detail (bufs[i], + server->ops->dump_detail (bufs[i], pdu_length, server);cifs_dump_mids (server);#endif /* CIFS_DEBUG2 */
@@ -3999,7 +3997,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,TCONX_RSP *pSMBr;unsigned char *bcc_ptr;int rc =0 ; -int length; +int length, in_len;__u16 bytes_left, count;if (ses ==NULL )
@@ -4011,8 +4009,8 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, smb_buffer_response = smb_buffer; -header_assemble (smb_buffer,SMB_COM_TREE_CONNECT_ANDX , -NULL /*no tid */ ,4 /*wct */ ); + in_len =header_assemble (smb_buffer,SMB_COM_TREE_CONNECT_ANDX , +NULL /*no tid */ ,4 /*wct */ ); smb_buffer->Mid =get_next_mid (ses->server); smb_buffer->Uid = ses->Suid;
@@ -4053,11 +4051,11 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, bcc_ptr +=strlen ("?????" ); bcc_ptr +=1 ; count = bcc_ptr - &pSMB->Password[0 ]; -be32_add_cpu (&pSMB->hdr.smb_buf_length, count); + in_len += count; pSMB->ByteCount =cpu_to_le16 (count); - rc =SendReceive (xid, ses, smb_buffer, smb_buffer_response, &length, -0 ); + rc =SendReceive (xid, ses, smb_buffer, in_len, smb_buffer_response, + &length,0 );/* above now done in SendReceive */ if (rc ==0 ) {
fs/smb/client/misc.c +16 -16
@@ -264,19 +264,18 @@ free_rsp_buf(int resp_buftype, void *rsp)/* NB: MID can not be set if treeCon not passed in, in that case it is responsibility of caller to set the mid */ -void +unsigned int header_assemble (struct smb_hdr *buffer,char smb_command/* command */ ,const struct cifs_tcon *treeCon,int word_count/* length of fixed section (word count) in two byte units */ ) { +unsigned int in_len;char *temp = (char *) buffer;memset (temp,0 ,256 );/* bigger than MAX_CIFS_HDR_SIZE */ - buffer->smb_buf_length =cpu_to_be32 ( - (2 * word_count) +sizeof (struct smb_hdr ) - -4 /* RFC 1001 length field does not count */ + -2 /* for bcc field itself */ ) ; + in_len = (2 * word_count) +sizeof (struct smb_hdr ) + +2 /* for bcc field itself */ ; buffer->Protocol[0 ] =0xFF ; buffer->Protocol[1 ] ='S' ;
@@ -311,7 +310,7 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,/* endian conversion of flags is now done just before sending */ buffer->WordCount = (char ) word_count; -return ; +return in_len; } static int
@@ -346,10 +345,11 @@ check_smb_hdr(struct smb_hdr *smb) }int -checkSMB (char *buf,unsigned int total_read,struct TCP_Server_Info *server) +checkSMB (char *buf,unsigned int pdu_len,unsigned int total_read, +struct TCP_Server_Info *server) {struct smb_hdr *smb = (struct smb_hdr *)buf; -__u32 rfclen =be32_to_cpu (smb->smb_buf_length); +__u32 rfclen = pdu_len;__u32 clc_len;/* calculated length */ cifs_dbg (FYI ,"checkSMB Length: 0x%x, smb_buf_length: 0x%x\n" , total_read, rfclen);
@@ -394,24 +394,24 @@ checkSMB(char *buf, unsigned int total_read, struct TCP_Server_Info *server)return -EIO ; clc_len =smbCalcSize (smb); -if (4 + rfclen != total_read) { -cifs_dbg (VFS ,"Length read does not match RFC1001 length %d\n" , - rfclen); +if (rfclen != total_read) { +cifs_dbg (VFS ,"Length read does not match RFC1001 length %d/%d\n" , + rfclen, total_read);return -EIO ; } -if (4 + rfclen != clc_len) { +if (rfclen != clc_len) {__u16 mid =get_mid (smb);/* check if bcc wrapped around for large read responses */ if ((rfclen >64 *1024 ) && (rfclen > clc_len)) {/* check if lengths match mod 64K */ -if (((4 + rfclen) &0xFFFF ) == (clc_len &0xFFFF )) +if (((rfclen) &0xFFFF ) == (clc_len &0xFFFF ))return 0 ;/* bcc wrapped */ }cifs_dbg (FYI ,"Calculated size %u vs length %u mismatch for mid=%u\n" , - clc_len,4 + rfclen, mid); + clc_len, rfclen, mid); -if (4 + rfclen < clc_len) { +if (rfclen < clc_len) {cifs_dbg (VFS ,"RFC1001 size %u smaller than SMB for mid=%u\n" , rfclen, mid);return -EIO ;
@@ -451,7 +451,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) (struct smb_com_transaction_change_notify_rsp *)buf;struct file_notify_information *pnotify;__u32 data_offset =0 ; -size_t len = srv->total_read -sizeof (pSMBr->hdr.smb_buf_length); +size_t len = srv->total_read - srv->pdu_size;if (get_bcc (buf) >sizeof (struct file_notify_information )) { data_offset =le32_to_cpu (pSMBr->DataOffset);
fs/smb/client/sess.c +5 -3
@@ -1313,6 +1313,7 @@ struct sess_data {struct nls_table *nls_cp;void (*func)(struct sess_data *);int result; +unsigned int in_len;/* we will send the SMB in three pieces:
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH v2 5/9 cifs: Make smb1's SendReceive() wrap cifs_send_recv()
In reply to David HowellsMake the smb1 transport's SendReceive() simply wrap cifs_send_recv() as does SendReceive2(). This will then allow that to pick up the transport changes there.
--- fs/smb/client/cifstransport.c | 85 +++++------------------------------ 1 file changed, 11 insertions(+), 74 deletions(-)
fs/smb/client/cifstransport.c +11 -74
@@ -236,12 +236,12 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, struct smb_hdr *in_buf, unsigned int in_len, struct smb_hdr *out_buf, int *pbytes_returned, const int flags) { - int rc = 0; -struct smb_message *smb; + struct TCP_Server_Info *server; +struct kvec resp_iov = {};struct kvec iov = { .iov_base = in_buf, .iov_len = in_len };struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec =1 }; -struct cifs_credits credits = { .value =1 , .instance =0 }; -struct TCP_Server_Info *server; +int resp_buf_type; +int rc =0 ;if (WARN_ON_ONCE (in_len >0xffffff ))return -EIO ;
@@ -272,78 +272,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,return -EIO ; } - rc =wait_for_free_request (server, flags, &credits.instance); -if (rc) -return rc; - -/* make sure that we sign in the same order that we send on this socket -and avoid races inside tcp sendmsg code that could cause corruption -of smb data */ - -cifs_server_lock (server); - - rc =allocate_mid (ses, in_buf, &smb); -if (rc) { -cifs_server_unlock (server); -/* Update # of requests on wire to server */ -add_credits (server, &credits,0 ); -return rc; - } - - rc =cifs_sign_smb (in_buf, in_len, server, &smb->sequence_number); -if (rc) { -cifs_server_unlock (server); - goto out; - } - - smb->mid_state =MID_REQUEST_SUBMITTED ; - - rc =smb_send (server, in_buf, in_len); -cifs_save_when_sent (smb); - -if (rc <0 ) - server->sequence_number -=2 ; - -cifs_server_unlock (server); - + rc =cifs_send_recv (xid, ses, ses->server, + &rqst, &resp_buf_type, flags, &resp_iov);if (rc <0 ) - goto out; - - rc =wait_for_response (server, smb); -if (rc !=0 ) { -send_cancel (server, &rqst, smb); -spin_lock (&smb->mid_lock); -if (smb->mid_state ==MID_REQUEST_SUBMITTED || - smb->mid_state ==MID_RESPONSE_RECEIVED ) { -/* no longer considered to be "in-flight" */ - smb->callback = release_mid; -spin_unlock (&smb->mid_lock); -add_credits (server, &credits,0 ); -return rc; - } -spin_unlock (&smb->mid_lock); - } - - rc =cifs_sync_mid_result (smb, server); -if (rc !=0 ) { -add_credits (server, &credits,0 );return rc; - } - -if (!smb->resp_buf || !out_buf || - smb->mid_state !=MID_RESPONSE_READY ) { - rc = -EIO ; -cifs_server_dbg (VFS ,"Bad MID state?\n" ); - goto out; - } - - *pbytes_returned = smb->response_pdu_len; -memcpy (out_buf, smb->resp_buf, *pbytes_returned); - rc =cifs_check_receive (smb, server,0 ); -out: -delete_mid (smb); -add_credits (server, &credits,0 ); - + + *pbytes_returned = resp_iov.iov_len; +if (resp_iov.iov_len) +memcpy (out_buf, resp_iov.iov_base, resp_iov.iov_len); +free_rsp_buf (resp_buf_type, resp_iov.iov_base);return rc; }
David Howells
maintainerPATCH v2 6/9 cifs: Clean up some places where an extra kvec[] was required for rfc1002
In reply to David HowellsClean up some places where previously an extra element in the kvec array was being used to hold an rfc1002 header for SMB1 (a previous patch removed this and generated it on the fly as for SMB2/3).
--- fs/smb/client/cifsencrypt.c | 52 ++++++++--------------------------- fs/smb/client/cifsproto.h | 7 ----- fs/smb/client/cifstransport.c | 22 ++------------- fs/smb/client/smb1ops.c | 12 +++++--- fs/smb/client/transport.c | 25 +++++++++-------- 5 files changed, 36 insertions(+), 82 deletions(-)
fs/smb/client/cifsencrypt.c +12 -40
@@ -86,26 +86,21 @@ static int cifs_sig_iter(const struct iov_iter *iter, size_t maxsize,int __cifs_calc_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,char *signature,struct cifs_calc_sig_ctx *ctx) { -int i; +struct iov_iter iter;ssize_t rc; -struct kvec *iov = rqst->rq_iov; -int n_vec = rqst->rq_nvec; +size_t size =0 ; -for (i =0 ; i < n_vec; i++) { -if (iov[i].iov_len ==0 ) -continue ; -if (iov[i].iov_base ==NULL ) { -cifs_dbg (VFS ,"null iovec entry\n" ); -return -EIO ; - } +for (int i =0 ; i < rqst->rq_nvec; i++) + size += rqst->rq_iov[i].iov_len; - rc =cifs_sig_update (ctx, iov[i].iov_base, iov[i].iov_len); -if (rc) { -cifs_dbg (VFS ,"%s: Could not update with payload\n" , - __func__); -return rc; - } - } +iov_iter_kvec (&iter,ITER_SOURCE , rqst->rq_iov, rqst->rq_nvec, size); + +if (iov_iter_count (&iter) <=4 ) +return -EIO ; + + rc =cifs_sig_iter (&iter,iov_iter_count (&iter), ctx); +if (rc <0 ) +return rc; rc =cifs_sig_iter (&rqst->rq_iter,iov_iter_count (&rqst->rq_iter), ctx);if (rc <0 )
@@ -186,29 +181,6 @@ int cifs_sign_rqst(struct smb_rqst *rqst, 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,unsigned int pdu_len, -struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence_number) -{ -struct kvec iov[1 ] = { - [0 ].iov_base = (char *)cifs_pdu, - [0 ].iov_len = pdu_len, - }; - -return cifs_sign_smbv (iov,ARRAY_SIZE (iov), server, - pexpected_response_sequence_number); -} -int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number)
fs/smb/client/cifsproto.h +0 -7
@@ -30,8 +30,6 @@ extern void cifs_buf_release(void *);extern struct smb_hdr *cifs_small_buf_get (void );extern void cifs_small_buf_release (void *);extern void free_rsp_buf (int ,void *); -extern int smb_send (struct TCP_Server_Info *,struct smb_hdr *, -unsigned int /* length */ );extern int smb_send_kvec (struct TCP_Server_Info *server,struct msghdr *msg,size_t *sent);
@@ -563,11 +561,6 @@ extern void tconInfoFree(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace)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 *); -int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, -struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence_number);extern int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number);
fs/smb/client/cifstransport.c +3 -19
@@ -70,22 +70,6 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)return smb; } -int -smb_send (struct TCP_Server_Info *server,struct smb_hdr *smb_buffer, -unsigned int smb_buf_length) -{ -struct kvec iov[1 ] = { - [0 ].iov_base = smb_buffer, - [0 ].iov_len = smb_buf_length, - }; -struct smb_rqst rqst = { - .rq_iov = iov, - .rq_nvec =ARRAY_SIZE (iov), - }; - -return __smb_send_rqst (server,1 , &rqst); -} -static int allocate_mid (struct cifs_ses *ses,struct smb_hdr *in_buf,struct smb_message **ppmidQ) {
@@ -276,7 +260,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, &rqst, &resp_buf_type, flags, &resp_iov);if (rc <0 )return rc; - + *pbytes_returned = resp_iov.iov_len;if (resp_iov.iov_len)memcpy (out_buf, resp_iov.iov_base, resp_iov.iov_len);
@@ -369,7 +353,7 @@ int SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,return rc; } - rc =cifs_sign_smb (in_buf, in_len, server, &smb->sequence_number); + rc =cifs_sign_rqst (&rqst, server, &smb->sequence_number);if (rc) {delete_mid (smb);cifs_server_unlock (server);
@@ -377,7 +361,7 @@ int SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, } smb->mid_state =MID_REQUEST_SUBMITTED ; - rc =smb_send (server, in_buf, in_len); + rc =__smb_send_rqst (server,1 , &rqst);cifs_save_when_sent (smb);if (rc <0 )
fs/smb/client/smb1ops.c +8 -4
@@ -32,17 +32,21 @@ static int send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst, struct smb_message *smb) { - int rc = 0; struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0].iov_base; -unsigned int in_len = rqst->rq_iov[0 ].iov_len; +struct kvec iov[1 ]; +struct smb_rqst crqst = { .rq_iov = iov, .rq_nvec =1 }; +int rc =0 ;/* +2 for BCC field */ in_buf->Command =SMB_COM_NT_CANCEL ; in_buf->WordCount =0 ;put_bcc (0 , in_buf); + iov[0 ].iov_base = in_buf; + iov[0 ].iov_len =sizeof (struct smb_hdr ) +2 ; +cifs_server_lock (server); - rc =cifs_sign_smb (in_buf, in_len, server, &smb->sequence_number); + rc =cifs_sign_rqst (&crqst, server, &smb->sequence_number);if (rc) {cifs_server_unlock (server);return rc;
@@ -54,7 +58,7 @@ send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst,* after signing here. */ --server->sequence_number; - rc =smb_send (server, in_buf, in_len); + rc =__smb_send_rqst (server,1 , &crqst);if (rc <0 ) server->sequence_number--;
fs/smb/client/transport.c +13 -12
@@ -1043,22 +1043,23 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, goto out; } - buf = (char *)smb[i]->resp_buf; - resp_iov[i].iov_base = buf; - resp_iov[i].iov_len = smb[i]->resp_buf_size; - -if (smb[i]->large_buf) - resp_buf_type[i] =CIFS_LARGE_BUFFER ; -else - resp_buf_type[i] =CIFS_SMALL_BUFFER ; - rc = server->ops->check_receive (smb[i], server, flags &CIFS_LOG_ERROR ); -/* mark it so buf will not be freed by delete_mid */ -if ((flags &CIFS_NO_RSP_BUF ) ==0 ) - smb[i]->resp_buf =NULL ; +if (resp_iov) { + buf = (char *)smb[i]->resp_buf; + resp_iov[i].iov_base = buf; + resp_iov[i].iov_len = smb[i]->resp_buf_size; +if (smb[i]->large_buf) + resp_buf_type[i] =CIFS_LARGE_BUFFER ; +else + resp_buf_type[i] =CIFS_SMALL_BUFFER ; + +/* mark it so buf will not be freed by delete_mid */ +if ((flags &CIFS_NO_RSP_BUF ) ==0 ) + smb[i]->resp_buf =NULL ; + } }/*
David Howells
maintainerPATCH v2 7/9 cifs: Replace SendReceiveBlockingLock() with SendReceive() plus flags
In reply to David HowellsReplace the smb1 transport's SendReceiveBlockingLock() with SendReceive() plus a couple of flags. This will then allow that to pick up the transport changes there.
The first flag, CIFS_INTERRUPTIBLE_WAIT, is added to indicate that the wait should be interruptible and the second, CIFS_WINDOWS_LOCK, indicates that we need to send a Lock command with unlock type rather than a Cancel.
send_lock_cancel() is then called from cifs_lock_cancel() which is called from the main transport loop in compound_send_recv().
[!] I *think* the error code handling is probably right.
--- fs/smb/client/cifsglob.h | 8 +- fs/smb/client/cifsproto.h | 10 +- fs/smb/client/cifssmb.c | 18 +-- fs/smb/client/cifstransport.c | 200 +--------------------------------- fs/smb/client/smb1ops.c | 46 +++++++- fs/smb/client/transport.c | 10 +- 6 files changed, 76 insertions(+), 216 deletions(-)
fs/smb/client/cifsglob.h +6 -2
@@ -311,8 +311,9 @@ struct cifs_open_parms;struct cifs_credits ;struct smb_version_operations { -int (*send_cancel)(struct TCP_Server_Info *,struct smb_rqst *, -struct smb_message *smb); +int (*send_cancel)(struct cifs_ses *ses,struct TCP_Server_Info *server, +struct smb_rqst *rqst,struct smb_message *smb, +unsigned int xid);bool (*compare_fids)(struct cifsFileInfo *,struct cifsFileInfo *);/* setup request: allocate mid, sign message */ struct smb_message *(*setup_request)(struct cifs_ses *,
@@ -1688,6 +1689,7 @@ struct smb_message {__u16 credits_received;/* number of credits from the response */ __u32 pid;/* process id */ __u32 sequence_number;/* for CIFS signing */ +unsigned int sr_flags;/* Flags passed to send_recv() */ unsigned long when_alloc;/* when mid was created */ #ifdef CONFIG_CIFS_STATS2 unsigned long when_sent;/* time when smb send finished */
@@ -1899,6 +1901,8 @@ enum cifs_writable_file_flags {#define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ #define CIFS_NO_SRV_RSP 0x1000/* there is no server response */ #define CIFS_COMPRESS_REQ 0x4000/* compress request before sending */ +#define CIFS_INTERRUPTIBLE_WAIT 0x8000/* Interruptible wait (e.g. lock request) */ +#define CIFS_WINDOWS_LOCK 0x10000/* We're trying to get a Windows lock */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001
fs/smb/client/cifsproto.h +4 -6
@@ -131,11 +131,12 @@ extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server, struct cifs_credits *credits);static inline int -send_cancel (struct TCP_Server_Info *server,struct smb_rqst *rqst, -struct smb_message *smb) +send_cancel (struct cifs_ses *ses,struct TCP_Server_Info *server, +struct smb_rqst *rqst,struct smb_message *smb, +unsigned int xid) {return server->ops->send_cancel ? - server->ops->send_cancel (server, rqst, smb) :0 ; + server->ops->send_cancel (ses, server, rqst, smb, xid) :0 ; }int wait_for_response (struct TCP_Server_Info *server,struct smb_message *smb);
@@ -143,9 +144,6 @@ extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, struct kvec *, int /* nvec to send */, int * /* type of buf returned */, const int flags, struct kvec * /* resp vec */); -int SendReceiveBlockingLock (const unsigned int xid,struct cifs_tcon *tcon, -struct smb_hdr *in_buf,unsigned int in_len, -struct smb_hdr *out_buf,int *pbytes_returned);void smb2_query_server_interfaces (struct work_struct *work);void
fs/smb/client/cifssmb.c +10 -8
@@ -2059,7 +2059,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,/* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ unsigned int in_len;int bytes_returned; -int flags =0 ; +int flags =CIFS_WINDOWS_LOCK |CIFS_INTERRUPTIBLE_WAIT ;__u16 count; cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n",
@@ -2104,8 +2104,9 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, pSMB->ByteCount =cpu_to_le16 (count);if (waitFlag) - rc =SendReceiveBlockingLock (xid, tcon, (struct smb_hdr *) pSMB, in_len, - (struct smb_hdr *) pSMB, &bytes_returned); + rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, in_len, + (struct smb_hdr *) pSMB, &bytes_returned, + flags);else rc =SendReceiveNoRsp (xid, tcon->ses, (char *)pSMB, in_len, flags);cifs_small_buf_release (pSMB);
@@ -2130,7 +2131,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,struct cifs_posix_lock *parm_data;unsigned int in_len;int rc =0 ; -int timeout =0 ; +int sr_flags =CIFS_INTERRUPTIBLE_WAIT ;int bytes_returned =0 ;int resp_buf_type =0 ;__u16 params, param_offset, offset, byte_count, count;
@@ -2173,7 +2174,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, parm_data->lock_type =cpu_to_le16 (lock_type);if (waitFlag) { - timeout =CIFS_BLOCKING_OP ;/* blocking operation, no timeout */ + sr_flags |=CIFS_BLOCKING_OP ;/* blocking operation, no timeout */ parm_data->lock_flags =cpu_to_le16 (1 ); pSMB->Timeout =cpu_to_le32 (-1 ); }else
@@ -2190,13 +2191,14 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, in_len += byte_count; pSMB->ByteCount =cpu_to_le16 (byte_count);if (waitFlag) { - rc =SendReceiveBlockingLock (xid, tcon, (struct smb_hdr *) pSMB, in_len, - (struct smb_hdr *) pSMBr, &bytes_returned); + rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, in_len, + (struct smb_hdr *) pSMBr, &bytes_returned, + sr_flags); }else { iov[0 ].iov_base = (char *)pSMB; iov[0 ].iov_len = in_len; rc =SendReceive2 (xid, tcon->ses, iov,1 /* num iovecs */ , - &resp_buf_type, timeout, &rsp_iov); + &resp_buf_type, sr_flags, &rsp_iov); pSMBr = (struct smb_com_transaction2_sfi_rsp *)rsp_iov.iov_base; }cifs_small_buf_release (pSMB);
fs/smb/client/cifstransport.c +5 -195
212 lines not on this page · raw message
fs/smb/client/smb1ops.c +43 -3
64 lines not on this page · raw message
fs/smb/client/transport.c +8 -2
@@ -643,12 +643,16 @@ cifs_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,int wait_for_response (struct TCP_Server_Info *server,struct smb_message *smb) { +unsigned int sleep_state =TASK_KILLABLE ;int error; +if (smb->sr_flags &CIFS_INTERRUPTIBLE_WAIT ) + sleep_state =TASK_INTERRUPTIBLE ; + error =wait_event_state (server->response_q, smb->mid_state !=MID_REQUEST_SUBMITTED && smb->mid_state !=MID_RESPONSE_RECEIVED , - (TASK_KILLABLE |TASK_FREEZABLE_UNSAFE )); + (sleep_state |TASK_FREEZABLE_UNSAFE ));if (error <0 )return -ERESTARTSYS ;
@@ -702,6 +706,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,return PTR_ERR (smb); } + smb->sr_flags = flags; smb->receive = receive; smb->callback = callback; smb->callback_data = cbdata;
@@ -946,6 +951,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,return PTR_ERR (smb[i]); } + smb[i]->sr_flags = flags; smb[i]->mid_state =MID_REQUEST_SUBMITTED ; smb[i]->optype = optype;/*
@@ -1012,7 +1018,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,for (; i < num_rqst; i++) {cifs_server_dbg (FYI ,"Cancelling wait for mid %llu cmd: %d\n" , smb[i]->mid,le16_to_cpu (smb[i]->command)); -send_cancel (server, &rqst[i], smb[i]); +send_cancel (ses, server, &rqst[i], smb[i], xid);spin_lock (&smb[i]->mid_lock); smb[i]->wait_cancelled = true; if (smb[i]->mid_state == MID_REQUEST_SUBMITTED ||
David Howells
maintainerPATCH v2 8/9 cifs: Remove the server pointer from smb_message
In reply to David HowellsRemove the server pointer from smb_message and instead pass it down to all the things that access it.
--- fs/smb/client/cifsglob.h | 10 ++++---- fs/smb/client/cifsproto.h | 21 +++++++++++------ fs/smb/client/cifssmb.c | 15 +++++------- fs/smb/client/cifstransport.c | 13 +++++------ fs/smb/client/connect.c | 34 +++++++++++++-------------- fs/smb/client/netmisc.c | 5 ++-- fs/smb/client/smb1ops.c | 4 ++-- fs/smb/client/smb2ops.c | 22 +++++++++--------- fs/smb/client/smb2pdu.c | 23 ++++++++---------- fs/smb/client/smb2transport.c | 7 +++--- fs/smb/client/transport.c | 44 ++++++++++++++++------------------- 11 files changed, 97 insertions(+), 101 deletions(-)
fs/smb/client/cifsglob.h +5 -5
@@ -1670,7 +1670,7 @@ typedef int (*mid_receive_t)(struct TCP_Server_Info *server,* - it will be called by cifsd, with no locks held * - the mid will be removed from any lists */ -typedef void (*mid_callback_t )(struct smb_message *smb); +typedef void (*mid_callback_t )(struct TCP_Server_Info *srv,struct smb_message *smb);/* * This is the protopyte for mid handle function. This is called once the mid
@@ -1682,8 +1682,7 @@ typedef int (*mid_handle_t)(struct TCP_Server_Info *server,/* one of these for every pending CIFS request to the server */ struct smb_message {struct list_head qhead;/* mids waiting on reply from this server */ -struct kref refcount; -struct TCP_Server_Info *server;/* server corresponding to this mid */ +refcount_t refcount;__u64 mid;/* multiplex id */ __u16 credits;/* number of credits consumed by this mid */ __u16 credits_received;/* number of credits from the response */
@@ -2355,7 +2354,8 @@ static inline bool cifs_netbios_name(const char *name, size_t namelen)* Execute mid callback atomically - ensures callback runs exactly once * and prevents sleeping in atomic context. */ -static inline void mid_execute_callback (struct smb_message *smb) +static inline void mid_execute_callback (struct TCP_Server_Info *server, +struct smb_message *smb) {mid_callback_t callback;
@@ -2365,7 +2365,7 @@ static inline void mid_execute_callback(struct smb_message *smb)spin_unlock (&smb->mid_lock);if (callback) -callback (smb); +callback (server, smb); }#define CIFS_REPARSE_SUPPORT (tcon) \
fs/smb/client/cifsproto.h +14 -7
@@ -82,9 +82,9 @@ extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx, int add_treename);extern char *build_wildcard_path_from_dentry (struct dentry *direntry);char *cifs_build_devname (char *nodename,const char *prepath); -extern void delete_mid (struct smb_message *smb); -void __release_mid (struct kref *refcount); -extern void cifs_wake_up_task (struct smb_message *smb); +extern void delete_mid (struct TCP_Server_Info *server,struct smb_message *smb); +void __release_mid (struct TCP_Server_Info *server,struct smb_message *smb); +extern void cifs_wake_up_task (struct TCP_Server_Info *server,struct smb_message *smb);extern int cifs_handle_standard (struct TCP_Server_Info *server,struct smb_message *smb); extern char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx,
@@ -181,7 +181,8 @@ extern int decode_negTokenInit(unsigned char *security_blob, int length,extern int cifs_convert_address (struct sockaddr *dst,const char *src,int len);extern void cifs_set_port (struct sockaddr *addr,const unsigned short int port);extern int map_smb_to_linux_error (char *buf,bool logErr); -extern int map_and_check_smb_error (struct smb_message *smb,bool logErr); +extern int map_and_check_smb_error (struct TCP_Server_Info *server, +struct smb_message *smb,bool logErr);unsigned int header_assemble (struct smb_hdr *,char /* command */ ,const struct cifs_tcon *,int /* length of fixed section (word count) in two byte units */ );
@@ -264,7 +265,7 @@ extern unsigned int setup_special_mode_ACE(struct smb_ace *pace, __u64 nmode);extern unsigned int setup_special_user_owner_ACE (struct smb_ace *pace); -extern void dequeue_mid (struct smb_message *smb,bool malformed); +void dequeue_mid (struct TCP_Server_Info *server,struct smb_message *smb,bool malformed);extern int cifs_read_from_socket (struct TCP_Server_Info *server,char *buf,unsigned int to_read); extern ssize_t cifs_discard_from_socket(struct TCP_Server_Info *server,
@@ -768,9 +769,15 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)return true; } -static inline void release_mid (struct smb_message *smb) +static inline void smb_get_mid (struct smb_message *smb) { -kref_put (&smb->refcount, __release_mid); +refcount_inc (&smb->refcount); +} + +static inline void release_mid (struct TCP_Server_Info *server,struct smb_message *smb) +{ +if (refcount_dec_and_test (&smb->refcount)) +__release_mid (server, smb); }static inline void cifs_free_open_info (struct cifs_open_info_data *data)
fs/smb/client/cifssmb.c +6 -9
@@ -584,12 +584,11 @@ CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon)* FIXME: maybe we should consider checking that the reply matches request? */ static void -cifs_echo_callback (struct smb_message *smb) +cifs_echo_callback (struct TCP_Server_Info *server,struct smb_message *smb) { -struct TCP_Server_Info *server = smb->callback_data;struct cifs_credits credits = { .value =1 , .instance =0 }; -release_mid (smb); +release_mid (server, smb);add_credits (server, &credits,CIFS_ECHO_OP ); }
@@ -1317,12 +1316,11 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, }static void -cifs_readv_callback (struct smb_message *smb) +cifs_readv_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *rdata = smb->callback_data;struct netfs_inode *ictx =netfs_inode (rdata->rreq->inode);struct cifs_tcon *tcon =tlink_tcon (rdata->req->cfile->tlink); -struct TCP_Server_Info *server = tcon->ses->server;struct smb_rqst rqst = { .rq_iov = rdata->iov, .rq_nvec =1 , .rq_iter = rdata->subreq.io_iter };
@@ -1420,7 +1418,7 @@ cifs_readv_callback(struct smb_message *smb) rdata->subreq.transferred += rdata->got_bytes;trace_netfs_sreq (&rdata->subreq, netfs_sreq_trace_io_progress);netfs_read_subreq_terminated (&rdata->subreq); -release_mid (smb); +release_mid (server, smb);add_credits (server, &credits,0 ); trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, 0, server->credits, server->in_flight,
@@ -1736,10 +1734,9 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,* workqueue completion task. */ static void -cifs_writev_callback (struct smb_message *smb) +cifs_writev_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *wdata = smb->callback_data; -struct TCP_Server_Info *server = wdata->server;struct cifs_tcon *tcon =tlink_tcon (wdata->req->cfile->tlink);WRITE_RSP *rsp = (WRITE_RSP *)smb->resp_buf;struct cifs_credits credits = {
@@ -1803,7 +1800,7 @@ cifs_writev_callback(struct smb_message *smb) 0, cifs_trace_rw_credits_write_response_clear); wdata->credits.value =0 ;cifs_write_subrequest_terminated (wdata, result); -release_mid (smb); +release_mid (server, smb);trace_smb3_rw_credits (credits.rreq_debug_id, credits.rreq_debug_index,0 , server->credits, server->in_flight, credits.value, cifs_trace_rw_credits_write_response_add);
fs/smb/client/cifstransport.c +6 -7
@@ -45,7 +45,7 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) smb =mempool_alloc (&smb_message_pool,GFP_NOFS );memset (smb,0 ,sizeof (struct smb_message )); -kref_init (&smb->refcount); +refcount_set (&smb->refcount,1 );spin_lock_init (&smb->mid_lock); smb->mid =get_mid (smb_buffer); smb->pid = current->pid;
@@ -54,7 +54,6 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)/* easier to use jiffies */ /* when mid allocated can be before when sent */ smb->when_alloc = jiffies; - smb->server = server;/* * The default is for the mid to be synchronous, so the
@@ -119,7 +118,7 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) rc =cifs_sign_rqst (rqst, server, &smb->sequence_number);if (rc) { -release_mid (smb); +release_mid (server, smb);return ERR_PTR (rc); }
@@ -179,11 +178,11 @@ cifs_check_receive(struct smb_message *smb, struct TCP_Server_Info *server, }/* BB special case reconnect tid and uid here? */ -return map_and_check_smb_error (smb, log_error); +return map_and_check_smb_error (server, smb, log_error); }struct smb_message * -cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *ignored, +cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *server,struct smb_rqst *rqst) {int rc;
@@ -193,9 +192,9 @@ cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored, rc =allocate_mid (ses, hdr, &smb);if (rc)return ERR_PTR (rc); - rc =cifs_sign_rqst (rqst, ses->server, &smb->sequence_number); + rc =cifs_sign_rqst (rqst, server, &smb->sequence_number);if (rc) { -delete_mid (smb); +delete_mid (server, smb);return ERR_PTR (rc); }return smb;
fs/smb/client/connect.c +17 -17
@@ -325,7 +325,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: moving mids to private list\n" , __func__);spin_lock (&server->mid_queue_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -kref_get (&smb->refcount); +smb_get_mid (smb);if (smb->mid_state ==MID_REQUEST_SUBMITTED ) smb->mid_state =MID_RETRY_NEEDED ;list_move (&smb->qhead, &retry_list);
@@ -337,8 +337,8 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: issuing mid callbacks\n" , __func__);list_for_each_entry_safe (smb, nsmb, &retry_list, qhead) {list_del_init (&smb->qhead); -mid_execute_callback (smb); -release_mid (smb); +mid_execute_callback (server, smb); +release_mid (server, smb); } }
@@ -882,7 +882,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)*/ spin_lock (&server->mid_queue_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -kref_get (&smb->refcount); +smb_get_mid (smb);list_move (&smb->qhead, &dispose_list); smb->deleted_from_q = true; }
@@ -915,8 +915,8 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)list_del_init (&smb->qhead); smb->mid_rc = mid_rc; smb->mid_state =MID_RC ; -mid_execute_callback (smb); -release_mid (smb); +mid_execute_callback (server, smb); +release_mid (server, smb); }/*
@@ -948,12 +948,12 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) }void -dequeue_mid (struct smb_message *smb,bool malformed) +dequeue_mid (struct TCP_Server_Info *server,struct smb_message *smb,bool malformed) {#ifdef CONFIG_CIFS_STATS2 smb->when_received = jiffies;#endif -spin_lock (&smb->server->mid_queue_lock); +spin_lock (&server->mid_queue_lock);if (!malformed) smb->mid_state =MID_RESPONSE_RECEIVED ;else
@@ -963,12 +963,12 @@ dequeue_mid(struct smb_message *smb, bool malformed)* function has finished processing it is a bug. */ if (smb->deleted_from_q) { -spin_unlock (&smb->server->mid_queue_lock); +spin_unlock (&server->mid_queue_lock);pr_warn_once ("trying to dequeue a deleted mid\n" ); }else {list_del_init (&smb->qhead); smb->deleted_from_q = true; -spin_unlock (&smb->server->mid_queue_lock); +spin_unlock (&server->mid_queue_lock); } }
@@ -1004,7 +1004,7 @@ handle_mid(struct smb_message *smb, struct TCP_Server_Info *server,else server->smallbuf =NULL ; } -dequeue_mid (smb, malformed); +dequeue_mid (server, smb, malformed); }int
@@ -1101,7 +1101,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)list_for_each_safe (tmp, tmp2, &server->pending_mid_q) { smb = list_entry(tmp, struct smb_message, qhead);cifs_dbg (FYI ,"Clearing mid %llu\n" , smb->mid); -kref_get (&smb->refcount); +smb_get_mid (smb); smb->mid_state =MID_SHUTDOWN ;list_move (&smb->qhead, &dispose_list); smb->deleted_from_q = true;
@@ -1113,8 +1113,8 @@ clean_demultiplex_info(struct TCP_Server_Info *server) smb = list_entry(tmp, struct smb_message, qhead);cifs_dbg (FYI ,"Callback mid %llu\n" , smb->mid);list_del_init (&smb->qhead); -mid_execute_callback (smb); -release_mid (smb); +mid_execute_callback (server, smb); +release_mid (server, smb); }/* 1/8th of sec is more than enough time for them to exit */ msleep (125 );
@@ -1355,7 +1355,7 @@ cifs_demultiplex_thread(void *p)if (length <0 ) {for (i =0 ; i < num_smbs; i++)if (smbs[i]) -release_mid (smbs[i]); +release_mid (server, smbs[i]);continue ; }
@@ -1388,9 +1388,9 @@ cifs_demultiplex_thread(void *p) }if (!smbs[i]->multiRsp || smbs[i]->multiEnd) -mid_execute_callback (smbs[i]); +mid_execute_callback (server, smbs[i]); -release_mid (smbs[i]); +release_mid (server, smbs[i]); }else if (server->ops->is_oplock_break && server->ops->is_oplock_break (bufs[i], server)) {
fs/smb/client/netmisc.c +3 -2
@@ -889,7 +889,8 @@ map_smb_to_linux_error(char *buf, bool logErr) }int -map_and_check_smb_error (struct smb_message *smb,bool logErr) +map_and_check_smb_error (struct TCP_Server_Info *server, +struct smb_message *smb,bool logErr) {int rc;struct smb_hdr *rhdr = (struct smb_hdr *)smb->resp_buf;
@@ -904,7 +905,7 @@ map_and_check_smb_error(struct smb_message *smb, bool logErr)if (class ==ERRSRV && code == ERRbaduid) {cifs_dbg (FYI ,"Server returned 0x%x, reconnecting session...\n" , code); -cifs_signal_cifsd_for_reconnect (smb->server, false); +cifs_signal_cifsd_for_reconnect (server, false); } }
fs/smb/client/smb1ops.c +2 -2
@@ -144,7 +144,7 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer)if (compare_mid (smb->mid, buf) && smb->mid_state ==MID_REQUEST_SUBMITTED &&le16_to_cpu (smb->command) == buf->Command) { -kref_get (&smb->refcount); +smb_get_mid (smb);spin_unlock (&server->mid_queue_lock);return smb; }
@@ -446,7 +446,7 @@ cifs_check_trans2(struct smb_message *smb, struct TCP_Server_Info *server,return true;/* All parts received or packet is malformed. */ smb->multiEnd = true; -dequeue_mid (smb, malformed); +dequeue_mid (server, smb, malformed);return true; }if (!server->large_buf) {
fs/smb/client/smb2ops.c +11 -11
@@ -406,7 +406,7 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)if ((smb->mid == wire_mid) && (smb->mid_state ==MID_REQUEST_SUBMITTED ) && (smb->command == shdr->Command)) { -kref_get (&smb->refcount); +smb_get_mid (smb);if (dequeue) {list_del_init (&smb->qhead); smb->deleted_from_q = true;
@@ -4716,7 +4716,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_RECEIVED ;else -dequeue_mid (smb, false); +dequeue_mid (server, smb, false);return 0 ; }
@@ -4743,7 +4743,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }
@@ -4762,7 +4762,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }
@@ -4772,7 +4772,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }
@@ -4783,7 +4783,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; } rdata->got_bytes = buffer_len;
@@ -4802,14 +4802,14 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }if (is_offloaded) smb->mid_state =MID_RESPONSE_RECEIVED ;else -dequeue_mid (smb, false); +dequeue_mid (server, smb, false);return 0 ; }
@@ -4856,7 +4856,7 @@ static void smb2_decrypt_offload(struct work_struct *work) dw->server->ops->is_network_name_deleted (dw->buf, dw->server); -mid_execute_callback (smb); +mid_execute_callback (dw->server, smb); }else {spin_lock (&dw->server->srv_lock);if (dw->server->tcpStatus == CifsNeedReconnect) {
@@ -4864,7 +4864,7 @@ static void smb2_decrypt_offload(struct work_struct *work) smb->mid_state =MID_RETRY_NEEDED ;spin_unlock (&dw->server->mid_queue_lock);spin_unlock (&dw->server->srv_lock); -mid_execute_callback (smb); +mid_execute_callback (dw->server, smb); }else {spin_lock (&dw->server->mid_queue_lock); smb->mid_state =MID_REQUEST_SUBMITTED ;
@@ -4875,7 +4875,7 @@ static void smb2_decrypt_offload(struct work_struct *work)spin_unlock (&dw->server->srv_lock); } } -release_mid (smb); +release_mid (dw->server, smb); } free_pages:
fs/smb/client/smb2pdu.c +10 -13
@@ -4091,9 +4091,8 @@ SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon,* FIXME: maybe we should consider checking that the reply matches request? */ static void -smb2_echo_callback (struct smb_message *smb) +smb2_echo_callback (struct TCP_Server_Info *server,struct smb_message *smb) { -struct TCP_Server_Info *server = smb->callback_data;struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)smb->resp_buf;struct cifs_credits credits = { .value =0 , .instance =0 };
@@ -4103,7 +4102,7 @@ smb2_echo_callback(struct smb_message *smb) credits.instance = server->reconnect_instance; } -release_mid (smb); +release_mid (server, smb);add_credits (server, &credits,CIFS_ECHO_OP ); }
@@ -4518,12 +4517,11 @@ smb2_new_read_req(void **buf, unsigned int *total_len, }static void -smb2_readv_callback (struct smb_message *smb) +smb2_readv_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *rdata = smb->callback_data;struct netfs_inode *ictx =netfs_inode (rdata->rreq->inode);struct cifs_tcon *tcon =tlink_tcon (rdata->req->cfile->tlink); -struct TCP_Server_Info *server = rdata->server;struct smb2_hdr *shdr = (struct smb2_hdr *)rdata->iov[0 ].iov_base;struct cifs_credits credits = { .value =0 ,
@@ -4539,9 +4537,9 @@ smb2_readv_callback(struct smb_message *smb) rqst.rq_iter = rdata->subreq.io_iter; } -WARN_ONCE (rdata->server != smb->server, +WARN_ONCE (rdata->server != server,"rdata server %p != mid server %p" , - rdata->server, smb->server); + rdata->server, server); cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%zu/%zu\n", __func__, smb->mid, smb->mid_state, rdata->result,
@@ -4642,7 +4640,7 @@ smb2_readv_callback(struct smb_message *smb) rdata->subreq.transferred += rdata->got_bytes;trace_netfs_sreq (&rdata->subreq, netfs_sreq_trace_io_progress);netfs_read_subreq_terminated (&rdata->subreq); -release_mid (smb); +release_mid (server, smb);trace_smb3_rw_credits (rreq_debug_id, subreq_debug_index,0 , server->credits, server->in_flight, credits.value, cifs_trace_rw_credits_read_response_add);
@@ -4819,11 +4817,10 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,* workqueue completion task. */ static void -smb2_writev_callback (struct smb_message *smb) +smb2_writev_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *wdata = smb->callback_data;struct cifs_tcon *tcon =tlink_tcon (wdata->req->cfile->tlink); -struct TCP_Server_Info *server = wdata->server;struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)smb->resp_buf;struct cifs_credits credits = { .value =0 ,
@@ -4836,9 +4833,9 @@ smb2_writev_callback(struct smb_message *smb)ssize_t result =0 ;size_t written; -WARN_ONCE (wdata->server != smb->server, +WARN_ONCE (wdata->server != server,"wdata server %p != mid server %p" , - wdata->server, smb->server); + wdata->server, server);switch (smb->mid_state) {case MID_RESPONSE_RECEIVED :
@@ -4928,7 +4925,7 @@ smb2_writev_callback(struct smb_message *smb) 0, cifs_trace_rw_credits_write_response_clear); wdata->credits.value =0 ;cifs_write_subrequest_terminated (wdata, result ?: written); -release_mid (smb); +release_mid (server, smb);trace_smb3_rw_credits (rreq_debug_id, subreq_debug_index,0 , server->credits, server->in_flight, credits.value, cifs_trace_rw_credits_write_response_add);
fs/smb/client/smb2transport.c +3 -4
@@ -655,14 +655,13 @@ smb2_mid_entry_alloc(const struct smb2_hdr *shdr, smb =mempool_alloc (&smb_message_pool,GFP_NOFS );memset (smb,0 ,sizeof (*smb)); -kref_init (&smb->refcount); +refcount_set (&smb->refcount,1 );spin_lock_init (&smb->mid_lock); smb->mid =le64_to_cpu (shdr->MessageId); smb->credits = credits >0 ? credits :1 ; smb->pid = current->pid; smb->command = shdr->Command;/* Always LE */ smb->when_alloc = jiffies; - smb->server = server;/* * The default is for the mid to be synchronous, so the
@@ -779,7 +778,7 @@ smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server, rc =smb2_sign_rqst (rqst, server);if (rc) {revert_current_mid_from_hdr (server, shdr); -delete_mid (mid); +delete_mid (server, mid);return ERR_PTR (rc); }
@@ -813,7 +812,7 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) rc =smb2_sign_rqst (rqst, server);if (rc) {revert_current_mid_from_hdr (server, shdr); -release_mid (smb); +release_mid (server, smb);return ERR_PTR (rc); }
fs/smb/client/transport.c +20 -24
127 lines not on this page · raw message
David Howells
maintainerPATCH v2 9/9 cifs: Don't need state locking in smb2_get_mid_entry()
In reply to David HowellsThere's no need to get ->srv_lock or ->ses_lock in smb2_get_mid_entry() as all that happens of relevance (to the lock) inside the locked sections is the reading of one status value in each.
Replace the locking with READ_ONCE() and use a switch instead of a chain of if-statements.
--- fs/smb/client/smb2transport.c | 48 +++++++++++++++-------------------- 1 file changed, 20 insertions(+), 28 deletions(-)
fs/smb/client/smb2transport.c +20 -28
@@ -684,43 +684,35 @@ static int smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, struct smb2_hdr *shdr, struct smb_message **smb) { - spin_lock(&server->srv_lock); -if (server->tcpStatus == CifsExiting) { -spin_unlock (&server->srv_lock); + switch (READ_ONCE(server->tcpStatus)) { + case CifsExiting: return -ENOENT; - } - -if (server->tcpStatus == CifsNeedReconnect) { -spin_unlock (&server->srv_lock); +case CifsNeedReconnect:cifs_dbg (FYI ,"tcp session dead - return to caller to retry\n" );return -EAGAIN ; - } - -if (server->tcpStatus == CifsNeedNegotiate && - shdr->Command !=SMB2_NEGOTIATE ) { -spin_unlock (&server->srv_lock); -return -EAGAIN ; - } -spin_unlock (&server->srv_lock); - -spin_lock (&ses->ses_lock); -if (ses->ses_status ==SES_NEW ) { -if ((shdr->Command !=SMB2_SESSION_SETUP ) && - (shdr->Command !=SMB2_NEGOTIATE )) { -spin_unlock (&ses->ses_lock); +case CifsNeedNegotiate: +if (shdr->Command !=SMB2_NEGOTIATE )return -EAGAIN ; - } -/* else ok - we are setting up session */ +break ; +default : +break ; } -if (ses->ses_status ==SES_EXITING ) { -if (shdr->Command !=SMB2_LOGOFF ) { -spin_unlock (&ses->ses_lock); +switch (READ_ONCE (ses->ses_status)) { +case SES_NEW : +if (shdr->Command !=SMB2_SESSION_SETUP && + shdr->Command !=SMB2_NEGOTIATE ) +return -EAGAIN ; +/* else ok - we are setting up session */ +break ; +case SES_EXITING : +if (shdr->Command !=SMB2_LOGOFF )return -EAGAIN ; - }/* else ok - we are shutting down the session */ +break ; +default : +break ; } -spin_unlock (&ses->ses_lock); *smb =smb2_mid_entry_alloc (shdr, server);if (*smb ==NULL )