netfs: [WIP] Allow the use of MSG_SPLICE_PAGES and use netmem allocator
Subsystems (7)
David Howells
maintainercover netfs: [WIP] Allow the use of MSG_SPLICE_PAGES and use netmem allocator
Hi Steve et al,
[!] NOTE: These patches are NOT FULLY WRITTEN, won't necessarily compile
all the way through and haven't been fully tested and this is intended as a preview of what I'm working on. Basic SMB1 and SMB2+ work as far as "cifs: Rewrite base TCP transmission". Encrypted, signed and RDMA may work but haven't been tested; compressed is disabled. Assume that anything beyond the specified point won't work.
I'm trying to work towards the network filesystems being able to use zerocopy facilities such as MSG_SPLICE_PAGES and, in doing so, I think the cifs driver can be simplified quite a bit.
However, making it possible to use the zerocopy facilities is probably going to mean moving away from storing the data to be transmitted in slab pages as slab pages don't have refcounts and their lifetime rules are unsuitable for splicing.
So what I'd like to do is to allocate protocol bufferage from the netmem allocator. The netmem allocator, if I understand it correctly, manages DMA mapping and IOMMU wrangling in bulk, and works as a bump/page fragment allocator - which has the potential to improve performance a bit.
The aim is to build up a list of fragments for each request using a bvecq. These form a segmented list and can be spliced together when assembling a compound request. The segmented list can then be passed to sendmsg() with MSG_SPLICE_PAGES in a single call, thereby only having a single loop (in the TCP stack) to shovel data, not loops-over-loops. Possibly we can dispense with corking also, provided we can tell TCP to flush the record boundaries. (Note that this also simplifies smbd_send() for RDMA).
To make this easier, I want to introduce a "request descriptor", which I'm calling "struct smb_message" and allocate it at a higher level, notably the PDU encoding routines in cifssmb.c and smb2pdu.c and then hand that down into the transport. It will contain the list of fragments that form the message.
smb_message then replaces mid_q_struct, absorbing its contents. The transport then doesn't allocate these, but uses the ones that it is given and the I/O thread gets to simplify its refcounting and do less of it. The rule is that smb_message gets an extra ref when it is enqueued and whoever dequeues it gets this ref and either puts it or hands it on. The PDU encoding routines get a ref when allocating them and keep the refs until they complete.
smb_message is then given a next pointer to allow compounds to be trivially assembled, with the protocol wrangling being done in the transport. This next pointer also allows a bunch of fixed-size arrays to be got rid of (which were imposing weird restrictions like reducing the maximum component count of a compound if we stole a kvec[] slot for the transform header).
To this end, I make the following significant changes. Note that some of the changes are a way to transit to a later stage.
(1) Make SMB1 transport use the SMB2 transport rather than having parallel dispatch code.
(a) Get rid of the separation of the message buffer into two kvecs, one for the rfc1002 header and one for the rest. This seems to be only to simplify the signing code - but at the expense of making a bunch of other places more complex.
(b) Make SendReceive() wrap cifs_send_recv() as does SendReceive2().
(c) Get rid of SendReceiveBlockingLock() in favour of using SendReceive() and a couple of flags to request interruptible waiting and to indicate Windows-type unlock rather than lock cancellation.
(2) Replace mid_q_struct with smb_message and also include credits and smb_rqst therein.
(3) Rewrite the base TCP transmission to be able to use MSG_SPLICE_PAGES.
(a) Copy all the data involved in a message into a big buffer formed of a sequence of pages attached to a bvecq.
(b) If encrypting the message just encrypt this buffer. Converting this to a scatterlist is much simpler (and uses less memory) than encrypting from the protocol elements.
(c) As the pages in the bvecq are just that, they have refcounts and can be passed to MSG_SPLICE_PAGES - thereby avoiding the copy in TCP.
(d) Compression should be a matter of vmap()'ing these pages to form the source buffer, allocating a second buffer of pages to form a dest buffer, also in a bvecq, vmapping that and then doing the compression. The first buffer can then just be replaced by the second.
(e) __smb_send_rqst() can then do a single sendmsg() with MSG_SPLICE_PAGES() from an ITER_BVECQ-type iterator.
(f) smbd_send() can push the same buffer to smbd_post_send_iter() from the same iterator.
(4) Clean up mid->callback_data. Replace it with a waitqueue in smb_message (for most commands) and a cifs_io_subrequest pointer (for read and write). Make request completion wait on the smb_message waitqueue rather than on server->response_q to avoid thundering herd issues.
(Also, I note that under some circumstances, cifs just wakes up the first thing on server->response_q without any reference to *what* it is waking up).
(5) Add some more bits to smb_message to hold the buffers in a bvecq with the intent of killing of the smb_rqst struct.
(a) The PDU encoders will have to work out how much memory they need for the request protocol bits in advance and tell the smb_message allocator their requirements. This will get the requested amount from the netmem allocator, so it needs to be correctly sized. A pointer is then set in smb->request to the buffer.
(b) The smb_message is given a pointer (->next) to chain to another message to be compounded after it.
(c) smb_send_recv_messages() will be used to dispatch a synchronous request. If the head smb_message's ->next pointer is not NULL, it will set the appropriate compound chaining stuff and insert appropriate padding. Then it will link the bvecq structs of those messages together.
(6) Convert PDU encoders to allocate and use smb_message and pass it down.
(a) So far, SMB2 Negotiate Protocol, Session Setup, Logoff, Tree Connect and Tree Disconnect have been done - and though they build if SMB1 and compression are disabled, they won't work yet and so haven't been tested.
(b) SMB2 Posix Mkdir has been attempted and will compile, but is likely to need rejigging as it's a close associate of Create.
(c) SMB2 Create/Open is partially done and won't compile. This gets complicated because it's used in a lot of places and also gets compounded - so anything that gets compounded with it must also be converted.
The patches can be found here also:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=cifs-experimental
Thanks,
David
David Howells (31):
iov_iter: Move ITER_DISCARD and ITER_XARRAY iteration out-of-line
iov_iter: Add a segmented queue of bio_vec[]
netfs: Provide facility to alloc buffer in a bvecq
cifs, nls: Provide unicode size determination func
cifs: Introduce an ALIGN8() macro
cifs: Move the SMB1 transport code out of transport.c
cifs: Rename mid_q_entry to smb_message
cifs: Keep the CPU-endian command ID around
cifs: Rename SMB2_xxxx_HE to SMB2_xxxx
cifs: Make smb1's SendReceive() wrap cifs_send_recv()
cifs: Fix SMB1 to not require separate kvec for the rfc1002 header
cifs: Replace SendReceiveBlockingLock() with SendReceive() plus flags
cifs: Institute message managing struct
cifs: Split crypt_message() into encrypt and decrypt variants
cifs: Use netfs_alloc/free_folioq_buffer()
cifs: Rewrite base TCP transmission
cifs: Rework smb2 decryption
cifs: Pass smb_message structs down into the transport layer
cifs: Clean up mid->callback_data and kill off mid->creator
cifs: Don't need state locking in smb2_get_mid_entry()
cifs: [DEBUG] smb_message refcounting
cifs: Add netmem allocation functions
cifs: Add more pieces to smb_message
cifs: Convert SMB2 Negotiate Protocol request
cifs: Convert SMB2 Session Setup request
cifs: Convert SMB2 Logoff request
cifs: Convert SMB2 Tree Connect request
cifs: Convert SMB2 Tree Disconnect request
cifs: Rearrange Create request subfuncs
cifs: Convert SMB2 Posix Mkdir request
cifs: Convert SMB2 Open request
fs/netfs/Makefile | 1 + fs/netfs/buffer.c | 102 ++ fs/nls/nls_base.c | 33 + fs/smb/client/Makefile | 2 +- fs/smb/client/cached_dir.c | 41 +- fs/smb/client/cifs_debug.c | 15 +- fs/smb/client/cifs_unicode.c | 39 + fs/smb/client/cifs_unicode.h | 2 + fs/smb/client/cifsencrypt.c | 77 +- fs/smb/client/cifsfs.c | 31 +- fs/smb/client/cifsglob.h | 254 ++-- fs/smb/client/cifsproto.h | 91 +- fs/smb/client/cifssmb.c | 123 +- fs/smb/client/cifstransport.c | 251 ++++ fs/smb/client/compress.c | 4 +- fs/smb/client/compress.h | 6 +- fs/smb/client/connect.c | 158 +- fs/smb/client/netmisc.c | 15 +- fs/smb/client/ntlmssp.h | 20 +- fs/smb/client/reparse.c | 2 +- fs/smb/client/sess.c | 271 ++-- fs/smb/client/smb1ops.c | 101 +- fs/smb/client/smb2file.c | 2 +- fs/smb/client/smb2inode.c | 6 +- fs/smb/client/smb2misc.c | 80 +- fs/smb/client/smb2ops.c | 570 +++---- fs/smb/client/smb2pdu.c | 2616 +++++++++++++++++---------------- fs/smb/client/smb2proto.h | 65 +- fs/smb/client/smb2transport.c | 229 ++- fs/smb/client/smbdirect.c | 88 +- fs/smb/client/smbdirect.h | 5 +- fs/smb/client/trace.h | 61 + fs/smb/client/transport.c | 1372 +++++++---------- fs/smb/common/smb2pdu.h | 92 +- fs/smb/server/connection.c | 2 +- fs/smb/server/oplock.c | 4 +- fs/smb/server/smb2misc.c | 14 +- fs/smb/server/smb2ops.c | 38 +- fs/smb/server/smb2pdu.c | 66 +- fs/smb/server/smb_common.c | 2 +- include/linux/bvec.h | 13 + include/linux/iov_iter.h | 77 +- include/linux/netfs.h | 4 + include/linux/nls.h | 1 + include/linux/uio.h | 11 + lib/iov_iter.c | 406 ++++- lib/tests/kunit_iov_iter.c | 196 +++ 47 files changed, 4177 insertions(+), 3482 deletions(-) create mode 100644 fs/netfs/buffer.c create mode 100644 fs/smb/client/cifstransport.c
David Howells
maintainerRFC PATCH 1/31 iov_iter: Move ITER_DISCARD and ITER_XARRAY iteration out-of-line
Move ITER_DISCARD and ITER_XARRAY iteration out-of-line in preparation of adding other iteration types which will also be out-of-line.
--- include/linux/iov_iter.h | 77 +++----------------------------------- lib/iov_iter.c | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 72 deletions(-)
include/linux/iov_iter.h +5 -72
@@ -17,6 +17,9 @@ typedef size_t (*iov_step_f)(void *iter_base, size_t progress, size_t len,typedef size_t (*iov_ustep_f )(void __user *iter_base,size_t progress,size_t len,void *priv,void *priv2); +size_t __iterate_and_advance2 (struct iov_iter *iter,size_t len,void *priv, +void *priv2,iov_ustep_f ustep,iov_step_f step); +/* * Handle ITER_UBUF. */
@@ -195,72 +198,6 @@ size_t iterate_folioq(struct iov_iter *iter, size_t len, void *priv, void *priv2return progress; } -/* -* Handle ITER_XARRAY. -*/ -static __always_inline -size_t iterate_xarray(struct iov_iter *iter, size_t len, void *priv, void *priv2, -iov_step_f step) -{ -struct folio *folio; -size_t progress =0 ; -loff_t start = iter->xarray_start + iter->iov_offset; -pgoff_t index = start /PAGE_SIZE ; -XA_STATE (xas, iter->xarray, index); - -rcu_read_lock (); -xas_for_each (&xas, folio,ULONG_MAX ) { -size_t remain, consumed, offset, part, flen; - -if (xas_retry (&xas, folio)) -continue ; -if (WARN_ON (xa_is_value (folio))) -break ; -if (WARN_ON (folio_test_hugetlb (folio))) -break ; - - offset =offset_in_folio (folio, start + progress); - flen =min (folio_size (folio) - offset, len); - -while (flen) { -void *base =kmap_local_folio (folio, offset); - - part =min_t (size_t, flen, -PAGE_SIZE -offset_in_page (offset)); - remain =step (base, progress, part, priv, priv2); -kunmap_local (base); - - consumed = part - remain; - progress += consumed; - len -= consumed; - -if (remain || len ==0 ) - goto out; - flen -= consumed; - offset += consumed; - } - } - -out: -rcu_read_unlock (); - iter->iov_offset += progress; - iter->count -= progress; -return progress; -} - -/* -* Handle ITER_DISCARD. -*/ -static __always_inline -size_t iterate_discard(struct iov_iter *iter, size_t len, void *priv, void *priv2, -iov_step_f step) -{ -size_t progress = len; - - iter->count -= progress; -return progress; -} -/** * iterate_and_advance2 - Iterate over an iterator * @iter: The iterator to iterate over.
@@ -306,9 +243,7 @@ size_t iterate_and_advance2(struct iov_iter *iter, size_t len, void *priv,return iterate_kvec (iter, len, priv, priv2, step);if (iov_iter_is_folioq (iter))return iterate_folioq (iter, len, priv, priv2, step); -if (iov_iter_is_xarray (iter)) -return iterate_xarray (iter, len, priv, priv2, step); -return iterate_discard (iter, len, priv, priv2, step); +return __iterate_and_advance2 (iter, len, priv, priv2, ustep, step); }/**
@@ -370,9 +305,7 @@ size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv,return iterate_kvec (iter, len, priv, priv2, step);if (iov_iter_is_folioq (iter))return iterate_folioq (iter, len, priv, priv2, step); -if (iov_iter_is_xarray (iter)) -return iterate_xarray (iter, len, priv, priv2, step); - return iterate_discard(iter, len, priv, priv2, step); + return __iterate_and_advance2(iter, len, priv, priv2, NULL, step); }#endif /* _LINUX_IOV_ITER_H */
lib/iov_iter.c +81 -0
84 lines not on this page · raw message
David Howells
maintainerRFC PATCH 2/31 iov_iter: Add a segmented queue of bio_vec[]
In reply to David HowellsAdd a segmented queue of bio_vec[]. This allows an indefinite quantity of elements to be handled. A rolling buffer can also be implemented over them where new bio_vecs can be added to the leading edge and spent bio_vecs can be cleared from the trailing edge.
--- include/linux/bvec.h | 13 ++ include/linux/uio.h | 11 ++ lib/iov_iter.c | 325 ++++++++++++++++++++++++++++++++++++- lib/tests/kunit_iov_iter.c | 196 ++++++++++++++++++++++ 4 files changed, 543 insertions(+), 2 deletions(-)
include/linux/bvec.h +13 -0
@@ -298,4 +298,17 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec) return page_to_phys(bvec->bv_page) + bvec->bv_offset; } +/* +* Segmented bio_vec queue. These can be linked together to form messages of +* indefinite length and iterated over with an ITER_BVECQ iterator. +*/ +struct bvecq { +struct bvecq *next;/* Next bvec in the list or NULL */ +struct bvecq *prev;/* Prev bvec in the list or NULL */ +u16 max_segs;/* Number of elements allocated in bv[] */ +u16 nr_segs;/* Number of elements in bv[] used */ +u16 cleared;/* Number of elements used in bv[] cleared */ + struct bio_vec bv[] __counted_by(max_segs); +}; +#endif /* __LINUX_BVEC_H */
include/linux/uio.h +11 -0
@@ -27,6 +27,7 @@ enum iter_type {ITER_BVEC ,ITER_KVEC ,ITER_FOLIOQ , +ITER_BVECQ ,ITER_XARRAY , ITER_DISCARD, };
@@ -69,6 +70,7 @@ struct iov_iter {const struct kvec *kvec;const struct bio_vec *bvec;const struct folio_queue *folioq; +const struct bvecq *bvecq;struct xarray *xarray;void __user *ubuf; };
@@ -78,6 +80,7 @@ struct iov_iter {union {unsigned long nr_segs;u8 folioq_slot; +u16 bvecq_slot;loff_t xarray_start; }; };
@@ -150,6 +153,11 @@ static inline bool iov_iter_is_folioq(const struct iov_iter *i)return iov_iter_type (i) ==ITER_FOLIOQ ; } +static inline bool iov_iter_is_bvecq (const struct iov_iter *i) +{ +return iov_iter_type (i) ==ITER_BVECQ ; +} +static inline bool iov_iter_is_xarray (const struct iov_iter *i) {return iov_iter_type (i) ==ITER_XARRAY ;
@@ -300,6 +308,9 @@ void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count);void iov_iter_folio_queue (struct iov_iter *i,unsigned int direction,const struct folio_queue *folioq,unsigned int first_slot,unsigned int offset,size_t count); +void iov_iter_bvec_queue (struct iov_iter *i,unsigned int direction, +const struct bvecq *bvecq, +unsigned int first_slot,unsigned int offset,size_t count);void iov_iter_xarray (struct iov_iter *i,unsigned int direction,struct xarray *xarray,loff_t start,size_t count); ssize_t iov_iter_get_pages2(struct iov_iter *i, struct page **pages,
lib/iov_iter.c +323 -2
422 lines not on this page · raw message
lib/tests/kunit_iov_iter.c +196 -0
208 lines not on this page · raw message
David Howells
maintainerRFC PATCH 3/31 netfs: Provide facility to alloc buffer in a bvecq
In reply to David HowellsProvide facility to allocate a series of bvecq structs and to attach sufficient pages to that series to provide a buffer for the specified amount of space. This can be used to do things like creating an encryption buffer in cifs and it can then be attached to an ITER_BVECQ iterator and passed to a socket.
--- fs/netfs/Makefile | 1 + fs/netfs/buffer.c | 101 ++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 4 ++ 3 files changed, 106 insertions(+) create mode 100644 fs/netfs/buffer.c
fs/netfs/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 netfs-y := \ + buffer.o \ buffered_read.o \ buffered_write.o \ direct_read.o \
fs/netfs/buffer.c new file +101 -0
101 lines not on this page · raw message
include/linux/netfs.h +4 -0
@@ -23,6 +23,7 @@enum netfs_sreq_ref_trace ;typedef struct mempool_s mempool_t ;struct folio_queue ; +struct bvecq ;/** * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -462,6 +463,9 @@ int netfs_alloc_folioq_buffer(struct address_space *mapping,struct folio_queue **_buffer, size_t *_cur_size, ssize_t size, gfp_t gfp);void netfs_free_folioq_buffer (struct folio_queue *fq); +void dump_bvecq (const struct bvecq *bq); +struct bvecq *netfs_alloc_bvecq_buffer (size_t size,unsigned int pre_slots,gfp_t gfp); +void netfs_free_bvecq_buffer (struct bvecq *bq);/** * netfs_inode - Get the netfs inode context from the inode
David Howells
maintainerRFC PATCH 4/31 cifs, nls: Provide unicode size determination func
In reply to David Howells--- fs/nls/nls_base.c | 33 ++++++++++++++++++++++++++++++ fs/smb/client/cifs_unicode.c | 39 ++++++++++++++++++++++++++++++++++++ fs/smb/client/cifs_unicode.h | 2 ++ include/linux/nls.h | 1 + 4 files changed, 75 insertions(+)
fs/nls/nls_base.c +33 -0
@@ -171,6 +171,39 @@ int utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian, }EXPORT_SYMBOL (utf8s_to_utf16s); +/** +* utf8s_to_len_utf16s - Determine the length of a conversion of UTF8 to UTF16. +* @s: The source utf8 string +* @inlen: The length of the string +*/ +ssize_t utf8s_to_len_utf16s (const u8 *s,int inlen) +{ +unicode_t u; +size_t outcount =0 ; +int size; + +while (inlen >0 && *s) { +if (*s &0x80 ) { + size =utf8_to_utf32 (s, inlen, &u); +if (size <0 ) +return -EINVAL ; + s += size; + inlen -= size; + +if (u >=PLANE_SIZE ) + outcount +=2 ; +else + outcount++; + }else { + s++; + outcount++; + inlen--; + } + } +return outcount *sizeof (wchar_t); +} +EXPORT_SYMBOL (utf8s_to_len_utf16s); +static inline unsigned long get_utf16 (unsigned c,enum utf16_endian endian) {switch (endian) {
fs/smb/client/cifs_unicode.c +39 -0
@@ -290,6 +290,45 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len,return i; } +/* +* Work out how long a string will be once converted to UTF16 in bytes. This +* does not include a NUL terminator. +*/ +size_t cifs_size_strtoUTF16 (const char *from,int len, +const struct nls_table *codepage) +{ +wchar_t wchar_to;/* needed to quiet sparse */ +ssize_t out_len =0 ; +int charlen; + +/* special case for utf8 to handle no plane0 chars */ +if (strcmp (codepage->charset,"utf8" ) ==0 ) { + out_len =utf8s_to_len_utf16s (from, len); +if (out_len >=0 ) + goto success; +/* +* On failure, fall back to UCS encoding as this function +* should not return negative values currently can fail only if +* source contains invalid encoded characters +*/ + } + +for (; len && *from; len -= charlen) { + charlen = codepage->char2uni (from, len, &wchar_to); +if (charlen <1 ) { +cifs_dbg (VFS ,"strtoUTF16: char2uni of 0x%x returned %d\n" , + *from, charlen); +/* Replace with a question mark */ + charlen =1 ; + } + from += charlen; + out_len +=2 ; + } + +success: +return out_len; +} +/* * cifs_utf16_bytes - how long will a string be after conversion? * @utf16 - pointer to input string
fs/smb/client/cifs_unicode.h +2 -0
@@ -60,6 +60,8 @@ int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,int cifs_utf16_bytes (const __le16 *from,int maxbytes,const struct nls_table *codepage);int cifs_strtoUTF16 (__le16 *,const char *,int ,const struct nls_table *); +size_t cifs_size_strtoUTF16 (const char *from,int len, +const struct nls_table *codepage);char *cifs_strndup_from_utf16 (const char *src,const int maxlen,const bool is_unicode,const struct nls_table *codepage);
include/linux/nls.h +1 -0
@@ -56,6 +56,7 @@ extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu);extern int utf32_to_utf8 (unicode_t u,u8 *s,int maxlen);extern int utf8s_to_utf16s (const u8 *s,int len,enum utf16_endian endian,wchar_t *pwcs,int maxlen); +ssize_t utf8s_to_len_utf16s (const u8 *s,int inlen);extern int utf16s_to_utf8s (const wchar_t *pwcs,int len,enum utf16_endian endian,u8 *s,int maxlen);
David Howells
maintainerRFC PATCH 5/31 cifs: Introduce an ALIGN8() macro
In reply to David HowellsThe PDU generation seems to do ALIGN(x, 8) a lot, so make a macro for that.
--- fs/smb/client/cifsglob.h | 2 ++ fs/smb/client/reparse.c | 2 +- fs/smb/client/smb2file.c | 2 +- fs/smb/client/smb2misc.c | 2 +- fs/smb/client/smb2pdu.c | 28 ++++++++++++++-------------- 5 files changed, 19 insertions(+), 17 deletions(-)
fs/smb/client/cifsglob.h +2 -0
@@ -2375,4 +2375,6 @@ static inline bool cifs_netbios_name(const char *name, size_t namelen) return ret; } +#define ALIGN8 (x) ALIGN((x), 8) +#endif /* _CIFS_GLOB_H */
fs/smb/client/reparse.c +1 -1
@@ -571,7 +571,7 @@ static struct smb2_create_ea_ctx *ea_create_context(u32 dlen, size_t *cc_len) {struct smb2_create_ea_ctx *cc; - *cc_len =round_up (sizeof (*cc) + dlen,8 ); + *cc_len =ALIGN8 (sizeof (*cc) + dlen); cc =kzalloc (*cc_len,GFP_KERNEL );if (!cc)return ERR_PTR (-ENOMEM );
fs/smb/client/smb2file.c +1 -1
@@ -48,7 +48,7 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)cifs_dbg (FYI ,"%s: skipping unhandled error context: 0x%x\n" , __func__,le32_to_cpu (p->ErrorId)); - len =ALIGN (le32_to_cpu (p->ErrorDataLength),8 ); + len =ALIGN8 (le32_to_cpu (p->ErrorDataLength)); p = (struct smb2_error_context_rsp *)(p->ErrorContextData + len); }while (p < end); } else if (le32_to_cpu(err->ByteCount) >= sizeof(*sym) &&
fs/smb/client/smb2misc.c +1 -1
@@ -252,7 +252,7 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *server)* Some windows servers (win2016) will pad also the final * PDU in a compound to 8 bytes. */ -if (ALIGN (calc_len,8 ) == len) +if (ALIGN8 (calc_len) == len)return 0 ;/*
fs/smb/client/smb2pdu.c +14 -14
@@ -619,14 +619,14 @@ build_signing_ctxt(struct smb2_signing_capabilities *pneg_ctxt)/* * Context Data length must be rounded to multiple of 8 for some servers */ - pneg_ctxt->DataLength =cpu_to_le16 (ALIGN (sizeof (struct smb2_signing_capabilities ) - + pneg_ctxt->DataLength =cpu_to_le16 (ALIGN8 (sizeof (struct smb2_signing_capabilities ) -sizeof (struct smb2_neg_context ) + - (num_algs *sizeof (u16)),8 )); + (num_algs *sizeof (u16)))); pneg_ctxt->SigningAlgorithmCount =cpu_to_le16 (num_algs); pneg_ctxt->SigningAlgorithms[0 ] =cpu_to_le16 (SIGNING_ALG_AES_CMAC ); ctxt_len +=sizeof (__le16) * num_algs; - ctxt_len =ALIGN (ctxt_len,8 ); + ctxt_len =ALIGN8 (ctxt_len);return ctxt_len;/* TBD add SIGNING_ALG_AES_GMAC and/or SIGNING_ALG_HMAC_SHA256 */ }
@@ -663,7 +663,7 @@ build_netname_ctxt(struct smb2_netname_neg_context *pneg_ctxt, char *hostname)/* copy up to max of first 100 bytes of server name to NetName field */ pneg_ctxt->DataLength =cpu_to_le16 (2 *cifs_strtoUTF16 (pneg_ctxt->NetName, hostname,100 , cp));/* context size is DataLength + minimal smb2_neg_context */ -return ALIGN (le16_to_cpu (pneg_ctxt->DataLength) +sizeof (struct smb2_neg_context ),8 ); +return ALIGN8 (le16_to_cpu (pneg_ctxt->DataLength) +sizeof (struct smb2_neg_context )); } static void
@@ -709,18 +709,18 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,* round up total_len of fixed part of SMB3 negotiate request to 8 * byte boundary before adding negotiate contexts */ - *total_len =ALIGN (*total_len,8 ); + *total_len =ALIGN8 (*total_len); pneg_ctxt = (*total_len) + (char *)req; req->NegotiateContextOffset =cpu_to_le32 (*total_len);build_preauth_ctxt ((struct smb2_preauth_neg_context *)pneg_ctxt); - ctxt_len =ALIGN (sizeof (struct smb2_preauth_neg_context ),8 ); + ctxt_len =ALIGN8 (sizeof (struct smb2_preauth_neg_context )); *total_len += ctxt_len; pneg_ctxt += ctxt_len;build_encrypt_ctxt ((struct smb2_encryption_neg_context *)pneg_ctxt); - ctxt_len =ALIGN (sizeof (struct smb2_encryption_neg_context ),8 ); + ctxt_len =ALIGN8 (sizeof (struct smb2_encryption_neg_context )); *total_len += ctxt_len; pneg_ctxt += ctxt_len;
@@ -749,7 +749,7 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,if (server->compression.requested) {build_compression_ctxt ((struct smb2_compression_capabilities_context *) pneg_ctxt); - ctxt_len =ALIGN (sizeof (struct smb2_compression_capabilities_context ),8 ); + ctxt_len =ALIGN8 (sizeof (struct smb2_compression_capabilities_context )); *total_len += ctxt_len; pneg_ctxt += ctxt_len; neg_context_count++;
@@ -940,7 +940,7 @@ static int smb311_decode_neg_context(struct smb2_negotiate_rsp *rsp,* aligned offset following the previous negotiate context. */ if (i +1 != ctxt_cnt) - clen =ALIGN (clen,8 ); + clen =ALIGN8 (clen);if (clen > len_of_ctxts)break ;
@@ -2631,7 +2631,7 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)unsigned int group_offset =0 ;struct smb3_acl acl = {}; - *len =round_up (sizeof (struct crt_sd_ctxt ) + (sizeof (struct smb_ace ) *4 ),8 ); + *len =ALIGN8 (sizeof (struct crt_sd_ctxt ) + (sizeof (struct smb_ace ) *4 ));if (set_owner) {/* sizeof(struct owner_group_sids) is already multiple of 8 so no need to round */
@@ -2706,7 +2706,7 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)memcpy (aclptr, &acl,sizeof (struct smb3_acl )); buf->ccontext.DataLength =cpu_to_le32 (ptr - (__u8 *)&buf->sd); - *len =round_up ((unsigned int )(ptr - (__u8 *)buf),8 ); + *len =ALIGN8 ((unsigned int )(ptr - (__u8 *)buf));return buf; }
@@ -2799,7 +2799,7 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len,* final path needs to be 8-byte aligned as specified in * MS-SMB2 2.2.13 SMB2 CREATE Request. */ - *out_size =round_up (*out_len *sizeof (__le16),8 ); + *out_size =ALIGN8 (*out_len *sizeof (__le16)); *out_path =kzalloc (*out_size +sizeof (__le16)/* null */ ,GFP_KERNEL );if (!*out_path)return -ENOMEM ;
@@ -3064,7 +3064,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, uni_path_len = (2 *UniStrnlen ((wchar_t *)path,PATH_MAX )) +2 ;/* MUST set path len (NameLength) to 0 opening root of share */ req->NameLength =cpu_to_le16 (uni_path_len -2 ); - copy_size =round_up (uni_path_len,8 ); + copy_size =ALIGN8 (uni_path_len); copy_path =kzalloc (copy_size,GFP_KERNEL );if (!copy_path)return -ENOMEM ;
@@ -4490,7 +4490,7 @@ smb2_new_read_req(void **buf, unsigned int *total_len,if (request_type &CHAINED_REQUEST ) {if (!(request_type &END_OF_CHAIN )) {/* next 8-byte aligned request */ - *total_len =ALIGN (*total_len,8 ); + *total_len =ALIGN8 (*total_len); shdr->NextCommand =cpu_to_le32 (*total_len); }else /* END_OF_CHAIN */ shdr->NextCommand =0 ;
David Howells
maintainerRFC PATCH 6/31 cifs: Move the SMB1 transport code out of transport.c
In reply to David Howells--- fs/smb/client/Makefile | 2 +- fs/smb/client/cifsproto.h | 15 + fs/smb/client/cifstransport.c | 566 ++++++++++++++++++++++++++++++++++ fs/smb/client/transport.c | 559 +-------------------------------- 4 files changed, 588 insertions(+), 554 deletions(-) create mode 100644 fs/smb/client/cifstransport.c
fs/smb/client/Makefile +1 -1
@@ -32,6 +32,6 @@ cifs-$(CONFIG_CIFS_SMB_DIRECT) += smbdirect.o cifs-$(CONFIG_CIFS_ROOT) += cifsroot.o -cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o cifssmb.o +cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o cifssmb.o cifstransport.o cifs-$(CONFIG_CIFS_COMPRESSION) += compress.o compress/lz77.o
fs/smb/client/cifsproto.h +15 -0
@@ -116,16 +116,31 @@ 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 *,struct TCP_Server_Info *,struct smb_rqst *);extern struct mid_q_entry *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,struct TCP_Server_Info *server,bool log_error); +int wait_for_free_request (struct TCP_Server_Info *server,const int flags, +unsigned int *instance);extern int cifs_wait_mtu_credits (struct TCP_Server_Info *server,size_t size,size_t *num,struct cifs_credits *credits); + +static inline int +send_cancel (struct TCP_Server_Info *server,struct smb_rqst *rqst, +struct mid_q_entry *mid) +{ +return server->ops->send_cancel ? + server->ops->send_cancel (server, rqst, mid) :0 ; +} + +int wait_for_response (struct TCP_Server_Info *server,struct mid_q_entry *midQ); extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, struct kvec *, int /* nvec to send */, int * /* type of buf returned */, const int flags,
fs/smb/client/cifstransport.c new file +566 -0
566 lines not on this page · raw message
fs/smb/client/transport.c +6 -553
619 lines not on this page · raw message
David Howells
maintainerRFC PATCH 7/31 cifs: Rename mid_q_entry to smb_message
In reply to David Howells--- fs/smb/client/cifs_debug.c | 14 +- fs/smb/client/cifsfs.c | 31 +++-- fs/smb/client/cifsglob.h | 48 +++---- fs/smb/client/cifsproto.h | 34 ++--- fs/smb/client/cifssmb.c | 82 ++++++------ fs/smb/client/cifstransport.c | 156 +++++++++++----------- 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 | 60 ++++----- fs/smb/client/transport.c | 235 +++++++++++++++++----------------- 15 files changed, 529 insertions(+), 530 deletions(-)
fs/smb/client/cifs_debug.c +7 -7
@@ -300,7 +300,7 @@ static __always_inline const char *compression_alg_str(__le16 alg)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;
@@ -624,13 +624,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_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_lock); }
fs/smb/client/cifsfs.c +15 -16
@@ -380,13 +380,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;
@@ -1765,28 +1765,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 )
@@ -1946,7 +1945,7 @@ init_cifs(void)if (rc) goto out_destroy_inodecache; - rc =init_mids (); + rc =init_smb_message ();if (rc) goto out_destroy_netfs;
@@ -2003,7 +2002,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:
@@ -2045,7 +2044,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 +24 -24
134 lines not on this page · raw message
fs/smb/client/cifsproto.h +17 -17
@@ -83,11 +83,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);
@@ -97,8 +97,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,
@@ -116,15 +116,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);
@@ -134,13 +134,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,
@@ -186,7 +186,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 */ );
@@ -269,7 +269,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,
@@ -613,7 +613,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,
@@ -762,9 +762,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 +78 -78
378 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
@@ -839,14 +839,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);
@@ -50,7 +50,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);
@@ -257,7 +257,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 +30 -30
141 lines not on this page · raw message
fs/smb/client/transport.c +118 -117
511 lines not on this page · raw message
David Howells
maintainerRFC PATCH 8/31 cifs: Keep the CPU-endian command ID around
In reply to David HowellsBecause the command IDs are small integers in a sequence, the C compiler can generate better code if they're cpu-endian.
--- fs/smb/client/cifs_debug.c | 2 +- fs/smb/client/cifsglob.h | 4 +- fs/smb/client/cifstransport.c | 4 +- fs/smb/client/compress.c | 4 +- fs/smb/client/smb1ops.c | 3 +- fs/smb/client/smb2misc.c | 30 +++++----- fs/smb/client/smb2ops.c | 19 ++++--- fs/smb/client/smb2pdu.c | 103 ++++++++++++++++++---------------- fs/smb/client/smb2transport.c | 20 +++---- fs/smb/client/transport.c | 12 ++-- fs/smb/common/smb2pdu.h | 68 +++++++++------------- fs/smb/server/oplock.c | 4 +- fs/smb/server/smb2misc.c | 40 ++++++------- fs/smb/server/smb2ops.c | 8 +-- fs/smb/server/smb2pdu.c | 14 ++--- 15 files changed, 162 insertions(+), 173 deletions(-)
fs/smb/client/cifs_debug.c +1 -1
@@ -627,7 +627,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)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" , smb->mid_state, -le16_to_cpu (smb->command), + smb->command_id, smb->pid, smb->callback_data, smb->mid);
fs/smb/client/cifsglob.h +2 -2
@@ -647,7 +647,7 @@ struct smb_version_values {size_t header_size;size_t max_header_size;size_t read_rsp_size; -__le16 lock_cmd; +enum smb2_command lock_cmd;unsigned int cap_unix;unsigned int cap_nt_find;unsigned int cap_large_files;
@@ -1728,8 +1728,8 @@ struct smb_message {int mid_state;/* wish this were enum but can not pass to wait_event */ int mid_rc;/* rc for MID_RC */ unsigned int mid_flags; -__le16 command;/* smb command code */ unsigned int optype;/* operation type */ +enum smb2_command command_id;/* smb command code */ bool large_buf:1; /* if valid response, is pointer to large buf */ bool multiRsp:1; /* multiple trans2 responses for one request */ bool multiEnd:1; /* both received */
fs/smb/client/cifstransport.c +2 -2
@@ -48,8 +48,8 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)kref_init (&smb->refcount); smb->mid =get_mid (smb_buffer); smb->pid = current->pid; - smb->command =cpu_to_le16 (smb_buffer->Command); -cifs_dbg (FYI ,"For smb_command %d\n" , smb_buffer->Command); + smb->command_id =le16_to_cpu (smb_buffer->Command); +cifs_dbg (FYI ,"For smb_command %d\n" , smb->command_id);/* easier to use jiffies */ /* when mid allocated can be before when sent */ smb->when_alloc = jiffies;
fs/smb/client/compress.c +2 -2
@@ -303,7 +303,7 @@ bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq)if (!(tcon->share_flags &SMB2_SHAREFLAG_COMPRESS_DATA ))return false; -if (shdr->Command ==SMB2_WRITE ) { +if (le16_to_cpu (shdr->Command) ==SMB2_WRITE_HE ) {const struct smb2_write_req *wreq = rq->rq_iov->iov_base;if (le32_to_cpu (wreq->Length) <SMB_COMPRESS_MIN_LEN )
@@ -312,7 +312,7 @@ bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq)return is_compressible (&rq->rq_iter); } -return (shdr->Command ==SMB2_READ ); +return le16_to_cpu (shdr->Command) ==SMB2_READ_HE ; }int smb_compress (struct TCP_Server_Info *server,struct smb_rqst *rq,compress_send_fn send_fn)
fs/smb/client/smb1ops.c +2 -1
@@ -93,12 +93,13 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer) {struct smb_hdr *buf = (struct smb_hdr *)buffer;struct smb_message *smb; +enum smb2_command command =le16_to_cpu (buf->Command);spin_lock (&server->mid_lock);list_for_each_entry (smb, &server->pending_mid_q, qhead) {if (compare_mid (smb->mid, buf) && smb->mid_state ==MID_REQUEST_SUBMITTED && -le16_to_cpu (smb->command) == buf->Command) { + smb->command_id == command) {kref_get (&smb->refcount);spin_unlock (&server->mid_lock);return smb;
fs/smb/client/smb2misc.c +15 -15
@@ -33,7 +33,7 @@ check_smb2_hdr(struct smb2_hdr *shdr, __u64 mid)return 0 ; else {/* only one valid case where server sends us request */ -if (shdr->Command ==SMB2_OPLOCK_BREAK ) +if (le16_to_cpu (shdr->Command) ==SMB2_OPLOCK_BREAK_HE )return 0 ;else cifs_dbg (VFS ,"Received Request not response\n" );
@@ -138,9 +138,9 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *server)struct TCP_Server_Info *pserver;struct smb2_hdr *shdr = (struct smb2_hdr *)buf;struct smb2_pdu *pdu = (struct smb2_pdu *)shdr; +enum smb2_command command;int hdr_size =sizeof (struct smb2_hdr );int pdu_size =sizeof (struct smb2_pdu ); -int command;__u32 calc_len;/* calculated length */ __u64 mid;
@@ -330,49 +330,49 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr)* of the data buffer offset and data buffer length for the particular * command. */ -switch (shdr->Command) { -case SMB2_NEGOTIATE : +switch (le16_to_cpu (shdr->Command)) { +case SMB2_NEGOTIATE_HE : *off =le16_to_cpu ( ((struct smb2_negotiate_rsp *)shdr)->SecurityBufferOffset); *len =le16_to_cpu ( ((struct smb2_negotiate_rsp *)shdr)->SecurityBufferLength);break ; -case SMB2_SESSION_SETUP : +case SMB2_SESSION_SETUP_HE : *off =le16_to_cpu ( ((struct smb2_sess_setup_rsp *)shdr)->SecurityBufferOffset); *len =le16_to_cpu ( ((struct smb2_sess_setup_rsp *)shdr)->SecurityBufferLength);break ; -case SMB2_CREATE : +case SMB2_CREATE_HE : *off =le32_to_cpu ( ((struct smb2_create_rsp *)shdr)->CreateContextsOffset); *len =le32_to_cpu ( ((struct smb2_create_rsp *)shdr)->CreateContextsLength);break ; -case SMB2_QUERY_INFO : +case SMB2_QUERY_INFO_HE : *off =le16_to_cpu ( ((struct smb2_query_info_rsp *)shdr)->OutputBufferOffset); *len =le32_to_cpu ( ((struct smb2_query_info_rsp *)shdr)->OutputBufferLength);break ; -case SMB2_READ : +case SMB2_READ_HE :/* TODO: is this a bug ? */ *off = ((struct smb2_read_rsp *)shdr)->DataOffset; *len =le32_to_cpu (((struct smb2_read_rsp *)shdr)->DataLength);break ; -case SMB2_QUERY_DIRECTORY : +case SMB2_QUERY_DIRECTORY_HE : *off =le16_to_cpu ( ((struct smb2_query_directory_rsp *)shdr)->OutputBufferOffset); *len =le32_to_cpu ( ((struct smb2_query_directory_rsp *)shdr)->OutputBufferLength);break ; -case SMB2_IOCTL : +case SMB2_IOCTL_HE : *off =le32_to_cpu ( ((struct smb2_ioctl_rsp *)shdr)->OutputOffset); *len =le32_to_cpu ( ((struct smb2_ioctl_rsp *)shdr)->OutputCount);break ; -case SMB2_CHANGE_NOTIFY : +case SMB2_CHANGE_NOTIFY_HE : *off =le16_to_cpu ( ((struct smb2_change_notify_rsp *)shdr)->OutputBufferOffset); *len = le32_to_cpu(
@@ -680,7 +680,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)cifs_dbg (FYI ,"Checking for oplock break\n" ); -if (rsp->hdr.Command !=SMB2_OPLOCK_BREAK ) +if (rsp->hdr.Command !=cpu_to_le32 (SMB2_OPLOCK_BREAK_HE ))return false; if (rsp->StructureSize !=
@@ -846,7 +846,7 @@ smb2_handle_cancelled_mid(struct smb_message *smb, struct TCP_Server_Info *servestruct cifs_tcon *tcon;int rc; -if ((smb->optype &CIFS_CP_CREATE_CLOSE_OP ) || hdr->Command !=SMB2_CREATE || +if ((smb->optype &CIFS_CP_CREATE_CLOSE_OP ) || smb->command_id !=SMB2_CREATE_HE || hdr->Status !=STATUS_SUCCESS )return 0 ;
@@ -887,7 +887,7 @@ smb311_update_preauth_hash(struct cifs_ses *ses, struct TCP_Server_Info *server, hdr = (struct smb2_hdr *)iov[0 ].iov_base;/* neg prot are always taken */ -if (hdr->Command ==SMB2_NEGOTIATE ) +if (le16_to_cpu (hdr->Command) ==SMB2_NEGOTIATE_HE ) goto ok;/*
@@ -898,7 +898,7 @@ smb311_update_preauth_hash(struct cifs_ses *ses, struct TCP_Server_Info *server,if (server->dialect !=SMB311_PROT_ID )return 0 ; -if (hdr->Command !=SMB2_SESSION_SETUP ) +if (le16_to_cpu (hdr->Command) !=SMB2_SESSION_SETUP_HE )return 0 ;/* skip last sess setup response */
fs/smb/client/smb2ops.c +10 -9
@@ -394,6 +394,7 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue) {struct smb_message *smb;struct smb2_hdr *shdr = (struct smb2_hdr *)buf; +enum smb2_command command =le16_to_cpu (shdr->Command);__u64 wire_mid =le64_to_cpu (shdr->MessageId);if (shdr->ProtocolId ==SMB2_TRANSFORM_PROTO_NUM ) {
@@ -405,7 +406,7 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)list_for_each_entry (smb, &server->pending_mid_q, qhead) {if ((smb->mid == wire_mid) && (smb->mid_state ==MID_REQUEST_SUBMITTED ) && - (smb->command == shdr->Command)) { + (smb->command_id == command)) {kref_get (&smb->refcount);if (dequeue) {list_del_init (&smb->qhead);
@@ -4625,7 +4626,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,int length;bool use_rdma_mr = false; -if (shdr->Command !=SMB2_READ ) { +if (le16_to_cpu (shdr->Command) !=SMB2_READ_HE ) {cifs_server_dbg (VFS ,"only big read responses are supported\n" );return -EOPNOTSUPP ; }
@@ -5714,7 +5715,7 @@ struct smb_version_values smb20_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -5736,7 +5737,7 @@ struct smb_version_values smb21_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -5757,7 +5758,7 @@ struct smb_version_values smb3any_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -5778,7 +5779,7 @@ struct smb_version_values smbdefault_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -5799,7 +5800,7 @@ struct smb_version_values smb30_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -5820,7 +5821,7 @@ struct smb_version_values smb302_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -5841,7 +5842,7 @@ struct smb_version_values smb311_values = { .header_preamble_size = 0, .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
fs/smb/client/smb2pdu.c +54 -49
322 lines not on this page · raw message
fs/smb/client/smb2transport.c +10 -10
@@ -671,7 +671,7 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) shdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base; ssr = (struct smb2_sess_setup_req *)shdr; - is_binding = shdr->Command ==SMB2_SESSION_SETUP && + is_binding =le16_to_cpu (shdr->Command) ==SMB2_SESSION_SETUP_HE && (ssr->Flags &SMB2_SESSION_REQ_FLAG_BINDING ); is_signed = shdr->Flags &SMB2_FLAGS_SIGNED ;
@@ -702,9 +702,9 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)struct smb2_hdr *shdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base; -if ((shdr->Command ==SMB2_NEGOTIATE ) || - (shdr->Command ==SMB2_SESSION_SETUP ) || - (shdr->Command ==SMB2_OPLOCK_BREAK ) || +if (le16_to_cpu (shdr->Command) ==SMB2_NEGOTIATE_HE || +le16_to_cpu (shdr->Command) ==SMB2_SESSION_SETUP_HE || +le16_to_cpu (shdr->Command) ==SMB2_OPLOCK_BREAK_HE || server->ignore_signature || (!server->session_estab))return 0 ;
@@ -774,7 +774,7 @@ smb2_mid_entry_alloc(const struct smb2_hdr *shdr, smb->mid =le64_to_cpu (shdr->MessageId); smb->credits = credits >0 ? credits :1 ; smb->pid = current->pid; - smb->command = shdr->Command;/* Always LE */ + smb->command_id =le16_to_cpu (shdr->Command); smb->when_alloc = jiffies; smb->server = server;
@@ -812,7 +812,7 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, }if (server->tcpStatus == CifsNeedNegotiate && - shdr->Command !=SMB2_NEGOTIATE ) { +le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE_HE ) {spin_unlock (&server->srv_lock);return -EAGAIN ; }
@@ -820,8 +820,8 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,spin_lock (&ses->ses_lock);if (ses->ses_status ==SES_NEW ) { -if ((shdr->Command !=SMB2_SESSION_SETUP ) && - (shdr->Command !=SMB2_NEGOTIATE )) { +if (le16_to_cpu (shdr->Command) !=SMB2_SESSION_SETUP_HE && +le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE_HE ) {spin_unlock (&ses->ses_lock);return -EAGAIN ; }
@@ -829,7 +829,7 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, }if (ses->ses_status ==SES_EXITING ) { -if (shdr->Command !=SMB2_LOGOFF ) { +if (le16_to_cpu (shdr->Command) !=SMB2_LOGOFF_HE ) {spin_unlock (&ses->ses_lock);return -EAGAIN ; }
@@ -910,7 +910,7 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedNegotiate && - shdr->Command !=SMB2_NEGOTIATE ) { +le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE_HE ) {spin_unlock (&server->srv_lock);return ERR_PTR (-EAGAIN ); }
fs/smb/client/transport.c +6 -6
@@ -43,8 +43,8 @@ void __release_mid(struct kref *refcount)struct smb_message *smb = container_of(refcount, struct smb_message, refcount);#ifdef CONFIG_CIFS_STATS2 -__le16 command = smb->server->vals->lock_cmd; -__u16 smb_cmd =le16_to_cpu (smb->command); +enum smb2_command command = smb->server->vals->lock_cmd; +enum smb2_command smb_cmd = smb->command_id;unsigned long now;unsigned long roundtrip_time;#endif
@@ -93,7 +93,7 @@ void __release_mid(struct kref *refcount)*/ if ((slow_rsp_threshold !=0 ) &&time_after (now, smb->when_alloc + (slow_rsp_threshold *HZ )) && - (smb->command != command)) { + (smb->command_id != command)) {/* * smb2slowcmd[NUMBER_OF_SMB2_COMMANDS] counts by command * NB: le16_to_cpu returns unsigned so can not be negative below
@@ -105,7 +105,7 @@ void __release_mid(struct kref *refcount) smb->when_sent, smb->when_received);if (cifsFYI &CIFS_TIMER ) {pr_debug ("slow rsp: cmd %d mid %llu" , - smb->command, smb->mid); + smb->command_id, smb->mid); cifs_info("A: 0x%lx S: 0x%lx R: 0x%lx\n", now - smb->when_alloc, now - smb->when_sent,
@@ -733,7 +733,7 @@ int cifs_sync_mid_result(struct smb_message *smb, struct TCP_Server_Info *serverint rc =0 ;cifs_dbg (FYI ,"%s: cmd=%d mid=%llu state=%d\n" , - __func__,le16_to_cpu (smb->command), smb->mid, smb->mid_state); + __func__, smb->command_id, smb->mid, smb->mid_state);spin_lock (&server->mid_lock);switch (smb->mid_state) {
@@ -1004,7 +1004,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,if (rc !=0 ) {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)); + smb[i]->mid, smb[i]->command_id);send_cancel (server, &rqst[i], smb[i]);spin_lock (&server->mid_lock); smb[i]->mid_flags |=MID_WAIT_CANCELLED ;
fs/smb/common/smb2pdu.h +25 -43
80 lines not on this page · raw message
fs/smb/server/oplock.c +2 -2
@@ -642,7 +642,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 ); - rsp_hdr->Command =SMB2_OPLOCK_BREAK ; + rsp_hdr->Command =cpu_to_le16 (SMB2_OPLOCK_BREAK_HE ); rsp_hdr->Flags = (SMB2_FLAGS_SERVER_TO_REDIR ); rsp_hdr->NextCommand =0 ; rsp_hdr->MessageId =cpu_to_le64 (-1 );
@@ -749,7 +749,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 ); - rsp_hdr->Command =SMB2_OPLOCK_BREAK ; + rsp_hdr->Command =cpu_to_le16 (SMB2_OPLOCK_BREAK_HE ); rsp_hdr->Flags = (SMB2_FLAGS_SERVER_TO_REDIR ); rsp_hdr->NextCommand =0 ; rsp_hdr->MessageId =cpu_to_le64 (-1 );
fs/smb/server/smb2misc.c +20 -20
@@ -95,18 +95,18 @@ static int smb2_get_data_area_len(unsigned int *off, unsigned int *len,* of the data buffer offset and data buffer length for the particular * command. */ -switch (hdr->Command) { -case SMB2_SESSION_SETUP : +switch (le16_to_cpu (hdr->Command)) { +case SMB2_SESSION_SETUP_HE : *off =le16_to_cpu (((struct smb2_sess_setup_req *)hdr)->SecurityBufferOffset); *len =le16_to_cpu (((struct smb2_sess_setup_req *)hdr)->SecurityBufferLength);break ; -case SMB2_TREE_CONNECT : +case SMB2_TREE_CONNECT_HE : *off = max_t(unsigned short int,le16_to_cpu (((struct smb2_tree_connect_req *)hdr)->PathOffset), offsetof(struct smb2_tree_connect_req , Buffer)); *len =le16_to_cpu (((struct smb2_tree_connect_req *)hdr)->PathLength);break ; -case SMB2_CREATE : +case SMB2_CREATE_HE : {unsigned short int name_off = max_t(unsigned short int,
@@ -131,23 +131,23 @@ static int smb2_get_data_area_len(unsigned int *off, unsigned int *len, *len = name_len;break ; } -case SMB2_QUERY_INFO : +case SMB2_QUERY_INFO_HE : *off = max_t(unsigned int,le16_to_cpu (((struct smb2_query_info_req *)hdr)->InputBufferOffset), offsetof(struct smb2_query_info_req , Buffer)); *len =le32_to_cpu (((struct smb2_query_info_req *)hdr)->InputBufferLength);break ; -case SMB2_SET_INFO : +case SMB2_SET_INFO_HE : *off = max_t(unsigned int,le16_to_cpu (((struct smb2_set_info_req *)hdr)->BufferOffset), offsetof(struct smb2_set_info_req , Buffer)); *len =le32_to_cpu (((struct smb2_set_info_req *)hdr)->BufferLength);break ; -case SMB2_READ : +case SMB2_READ_HE : *off =le16_to_cpu (((struct smb2_read_req *)hdr)->ReadChannelInfoOffset); *len =le16_to_cpu (((struct smb2_read_req *)hdr)->ReadChannelInfoLength);break ; -case SMB2_WRITE : +case SMB2_WRITE_HE :if (((struct smb2_write_req *)hdr)->DataOffset || ((struct smb2_write_req *)hdr)->Length) { *off = max_t(unsigned short int,
@@ -160,13 +160,13 @@ static int smb2_get_data_area_len(unsigned int *off, unsigned int *len, *off =le16_to_cpu (((struct smb2_write_req *)hdr)->WriteChannelInfoOffset); *len =le16_to_cpu (((struct smb2_write_req *)hdr)->WriteChannelInfoLength);break ; -case SMB2_QUERY_DIRECTORY : +case SMB2_QUERY_DIRECTORY_HE : *off = max_t(unsigned short int,le16_to_cpu (((struct smb2_query_directory_req *)hdr)->FileNameOffset), offsetof(struct smb2_query_directory_req , Buffer)); *len =le16_to_cpu (((struct smb2_query_directory_req *)hdr)->FileNameLength);break ; -case SMB2_LOCK : +case SMB2_LOCK_HE : {unsigned short lock_count;
@@ -177,7 +177,7 @@ static int smb2_get_data_area_len(unsigned int *off, unsigned int *len, }break ; } -case SMB2_IOCTL : +case SMB2_IOCTL_HE : *off = max_t(unsigned int,le32_to_cpu (((struct smb2_ioctl_req *)hdr)->InputOffset), offsetof(struct smb2_ioctl_req , Buffer));
@@ -226,7 +226,7 @@ static int smb2_calc_size(void *buf, unsigned int *len)* regardless of number of locks. Subtract single * smb2_lock_element for correct buffer size check. */ -if (hdr->Command ==SMB2_LOCK ) +if (le16_to_cpu (hdr->Command) ==SMB2_LOCK_HE ) *len -=sizeof (struct smb2_lock_element );if (has_smb2_data_area[le16_to_cpu (hdr->Command)] == false)
@@ -306,27 +306,27 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,void *__hdr = hdr;int ret =0 ; -switch (hdr->Command) { -case SMB2_QUERY_INFO : +switch (le16_to_cpu (hdr->Command)) { +case SMB2_QUERY_INFO_HE : req_len =smb2_query_info_req_len (__hdr);break ; -case SMB2_SET_INFO : +case SMB2_SET_INFO_HE : req_len =smb2_set_info_req_len (__hdr);break ; -case SMB2_READ : +case SMB2_READ_HE : req_len =smb2_read_req_len (__hdr);break ; -case SMB2_WRITE : +case SMB2_WRITE_HE : req_len =smb2_write_req_len (__hdr);break ; -case SMB2_QUERY_DIRECTORY : +case SMB2_QUERY_DIRECTORY_HE : req_len =smb2_query_dir_req_len (__hdr);break ; -case SMB2_IOCTL : +case SMB2_IOCTL_HE : req_len =smb2_ioctl_req_len (__hdr); expect_resp_len =smb2_ioctl_resp_len (__hdr);break ; -case SMB2_CANCEL : +case SMB2_CANCEL_HE :return 0 ;default : req_len =1 ;
fs/smb/server/smb2ops.c +4 -4
@@ -27,7 +27,7 @@ static struct smb_version_values smb21_server_values = { .header_size = sizeof(struct smb2_hdr), .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -53,7 +53,7 @@ static struct smb_version_values smb30_server_values = { .header_size = sizeof(struct smb2_hdr), .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -80,7 +80,7 @@ static struct smb_version_values smb302_server_values = { .header_size = sizeof(struct smb2_hdr), .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
@@ -107,7 +107,7 @@ static struct smb_version_values smb311_server_values = { .header_size = sizeof(struct smb2_hdr), .max_header_size = MAX_SMB2_HDR_SIZE, .read_rsp_size = sizeof(struct smb2_read_rsp), - .lock_cmd = SMB2_LOCK, + .lock_cmd = SMB2_LOCK_HE, .cap_unix = 0, .cap_nt_find = SMB2_NT_FIND, .cap_large_files = SMB2_LARGE_FILES,
fs/smb/server/smb2pdu.c +7 -7
@@ -181,7 +181,7 @@ bool is_smb2_neg_cmd(struct ksmbd_work *work)if (hdr->Flags &SMB2_FLAGS_SERVER_TO_REDIR )return false; -if (hdr->Command !=SMB2_NEGOTIATE ) +if (le16_to_cpu (hdr->Command) !=SMB2_NEGOTIATE_HE )return false;return true;
@@ -262,7 +262,7 @@ int init_smb2_neg_rsp(struct ksmbd_work *work) rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (2 ); - rsp_hdr->Command =SMB2_NEGOTIATE ; + rsp_hdr->Command =cpu_to_le16 (SMB2_NEGOTIATE_HE ); rsp_hdr->Flags = (SMB2_FLAGS_SERVER_TO_REDIR ); rsp_hdr->NextCommand =0 ; rsp_hdr->MessageId =0 ;
@@ -349,7 +349,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)* TODO: Need to adjuct CreditRequest value according to * current cpu load */ -if (hdr->Command ==SMB2_NEGOTIATE ) +if (le16_to_cpu (hdr->Command) ==SMB2_NEGOTIATE_HE ) aux_max =1 ;else aux_max = conn->vals->max_credits - conn->total_credits;
@@ -389,7 +389,7 @@ static void init_chained_smb2_rsp(struct ksmbd_work *work)/* Storing the current local FID which may be needed by subsequent * command in the compound request */ -if (req->Command ==SMB2_CREATE && rsp->Status ==STATUS_SUCCESS ) { +if (req->Command ==cpu_to_le16 (SMB2_CREATE_HE ) && rsp->Status ==STATUS_SUCCESS ) { work->compound_fid = ((struct smb2_create_rsp *)rsp)->VolatileFileId; work->compound_pfid = ((struct smb2_create_rsp *)rsp)->PersistentFileId; work->compound_sid =le64_to_cpu (rsp->SessionId);
@@ -572,7 +572,7 @@ int smb2_check_user_session(struct ksmbd_work *work) {struct smb2_hdr *req_hdr =ksmbd_req_buf_next (work);struct ksmbd_conn *conn = work->conn; -unsigned int cmd =le16_to_cpu (req_hdr->Command); +enum smb2_command cmd =le16_to_cpu (req_hdr->Command);unsigned long long sess_id;/*
@@ -8887,7 +8887,7 @@ void smb2_set_sign_rsp(struct ksmbd_work *work) hdr->Flags |=SMB2_FLAGS_SIGNED ;memset (hdr->Signature,0 ,SMB2_SIGNATURE_SIZE ); -if (hdr->Command ==SMB2_READ ) { +if (hdr->Command ==cpu_to_le16 (SMB2_READ_HE )) { iov = &work->iov[work->iov_idx -1 ]; n_vec++; }else {
@@ -8993,7 +8993,7 @@ void smb3_set_sign_rsp(struct ksmbd_work *work) hdr->Flags |=SMB2_FLAGS_SIGNED ;memset (hdr->Signature,0 ,SMB2_SIGNATURE_SIZE ); -if (hdr->Command ==SMB2_READ ) { +if (hdr->Command ==cpu_to_le16 (SMB2_READ_HE )) { iov = &work->iov[work->iov_idx -1 ]; n_vec++; }else {
David Howells
maintainerRFC PATCH 9/31 cifs: Rename SMB2_xxxx_HE to SMB2_xxxx
In reply to David HowellsRename SMB2_xxxx_HE to SMB2_xxxx as the LE variants have been got rid of.
--- fs/smb/client/compress.c | 4 +- fs/smb/client/smb2misc.c | 43 ++++++----- fs/smb/client/smb2ops.c | 72 +++++++++--------- fs/smb/client/smb2pdu.c | 134 +++++++++++++++++----------------- fs/smb/client/smb2transport.c | 18 ++--- fs/smb/common/smb2pdu.h | 40 +++++----- fs/smb/server/connection.c | 2 +- fs/smb/server/oplock.c | 4 +- fs/smb/server/smb2misc.c | 44 +++++------ fs/smb/server/smb2ops.c | 46 ++++++------ fs/smb/server/smb2pdu.c | 42 +++++------ fs/smb/server/smb_common.c | 2 +- 12 files changed, 225 insertions(+), 226 deletions(-)
fs/smb/client/compress.c +2 -2
@@ -303,7 +303,7 @@ bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq)if (!(tcon->share_flags &SMB2_SHAREFLAG_COMPRESS_DATA ))return false; -if (le16_to_cpu (shdr->Command) ==SMB2_WRITE_HE ) { +if (le16_to_cpu (shdr->Command) ==SMB2_WRITE ) {const struct smb2_write_req *wreq = rq->rq_iov->iov_base;if (le32_to_cpu (wreq->Length) <SMB_COMPRESS_MIN_LEN )
@@ -312,7 +312,7 @@ bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq)return is_compressible (&rq->rq_iter); } -return le16_to_cpu (shdr->Command) ==SMB2_READ_HE ; +return le16_to_cpu (shdr->Command) ==SMB2_READ ; }int smb_compress (struct TCP_Server_Info *server,struct smb_rqst *rq,compress_send_fn send_fn)
fs/smb/client/smb2misc.c +21 -22
147 lines not on this page · raw message
fs/smb/client/smb2ops.c +36 -36
139 lines not on this page · raw message
fs/smb/client/smb2pdu.c +67 -67
456 lines not on this page · raw message
fs/smb/client/smb2transport.c +9 -9
@@ -671,7 +671,7 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) shdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base; ssr = (struct smb2_sess_setup_req *)shdr; - is_binding =le16_to_cpu (shdr->Command) ==SMB2_SESSION_SETUP_HE && + is_binding =le16_to_cpu (shdr->Command) ==SMB2_SESSION_SETUP && (ssr->Flags &SMB2_SESSION_REQ_FLAG_BINDING ); is_signed = shdr->Flags &SMB2_FLAGS_SIGNED ;
@@ -702,9 +702,9 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)struct smb2_hdr *shdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base; -if (le16_to_cpu (shdr->Command) ==SMB2_NEGOTIATE_HE || -le16_to_cpu (shdr->Command) ==SMB2_SESSION_SETUP_HE || -le16_to_cpu (shdr->Command) ==SMB2_OPLOCK_BREAK_HE || +if (le16_to_cpu (shdr->Command) ==SMB2_NEGOTIATE || +le16_to_cpu (shdr->Command) ==SMB2_SESSION_SETUP || +le16_to_cpu (shdr->Command) ==SMB2_OPLOCK_BREAK || server->ignore_signature || (!server->session_estab))return 0 ;
@@ -812,7 +812,7 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, }if (server->tcpStatus == CifsNeedNegotiate && -le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE_HE ) { +le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE ) {spin_unlock (&server->srv_lock);return -EAGAIN ; }
@@ -820,8 +820,8 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,spin_lock (&ses->ses_lock);if (ses->ses_status ==SES_NEW ) { -if (le16_to_cpu (shdr->Command) !=SMB2_SESSION_SETUP_HE && -le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE_HE ) { +if (le16_to_cpu (shdr->Command) !=SMB2_SESSION_SETUP && +le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE ) {spin_unlock (&ses->ses_lock);return -EAGAIN ; }
@@ -829,7 +829,7 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, }if (ses->ses_status ==SES_EXITING ) { -if (le16_to_cpu (shdr->Command) !=SMB2_LOGOFF_HE ) { +if (le16_to_cpu (shdr->Command) !=SMB2_LOGOFF ) {spin_unlock (&ses->ses_lock);return -EAGAIN ; }
@@ -910,7 +910,7 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedNegotiate && -le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE_HE ) { +le16_to_cpu (shdr->Command) !=SMB2_NEGOTIATE ) {spin_unlock (&server->srv_lock);return ERR_PTR (-EAGAIN ); }
fs/smb/common/smb2pdu.h +20 -20
@@ -16,29 +16,29 @@/* List of commands in host endian */ enum smb2_command { -SMB2_NEGOTIATE_HE =0x0000 , -SMB2_SESSION_SETUP_HE =0x0001 , -SMB2_LOGOFF_HE =0x0002 ,/* trivial request/resp */ -SMB2_TREE_CONNECT_HE =0x0003 , -SMB2_TREE_DISCONNECT_HE =0x0004 ,/* trivial req/resp */ -SMB2_CREATE_HE =0x0005 , -SMB2_CLOSE_HE =0x0006 , -SMB2_FLUSH_HE =0x0007 ,/* trivial resp */ -SMB2_READ_HE =0x0008 , -SMB2_WRITE_HE =0x0009 , -SMB2_LOCK_HE =0x000A , -SMB2_IOCTL_HE =0x000B , -SMB2_CANCEL_HE =0x000C , -SMB2_ECHO_HE =0x000D , -SMB2_QUERY_DIRECTORY_HE =0x000E , -SMB2_CHANGE_NOTIFY_HE =0x000F , -SMB2_QUERY_INFO_HE =0x0010 , -SMB2_SET_INFO_HE =0x0011 , -SMB2_OPLOCK_BREAK_HE =0x0012 , +SMB2_NEGOTIATE =0x0000 , +SMB2_SESSION_SETUP =0x0001 , +SMB2_LOGOFF =0x0002 ,/* trivial request/resp */ +SMB2_TREE_CONNECT =0x0003 , +SMB2_TREE_DISCONNECT =0x0004 ,/* trivial req/resp */ +SMB2_CREATE =0x0005 , +SMB2_CLOSE =0x0006 , +SMB2_FLUSH =0x0007 ,/* trivial resp */ +SMB2_READ =0x0008 , +SMB2_WRITE =0x0009 , +SMB2_LOCK =0x000A , +SMB2_IOCTL =0x000B , +SMB2_CANCEL =0x000C , +SMB2_ECHO =0x000D , +SMB2_QUERY_DIRECTORY =0x000E , +SMB2_CHANGE_NOTIFY =0x000F , +SMB2_QUERY_INFO =0x0010 , +SMB2_SET_INFO =0x0011 , +SMB2_OPLOCK_BREAK =0x0012 ,SMB2_SERVER_TO_CLIENT_NOTIFICATION =0x0013 }; -#define SMB2_INTERNAL_CMD_HE 0xFFFF +#define SMB2_INTERNAL_CMD 0xFFFF#define NUMBER_OF_SMB2_COMMANDS 0x0013
fs/smb/server/connection.c +1 -1
@@ -118,7 +118,7 @@ void ksmbd_conn_enqueue_request(struct ksmbd_work *work)struct ksmbd_conn *conn = work->conn;struct list_head *requests_queue =NULL ; -if (conn->ops->get_cmd_val (work) !=SMB2_CANCEL_HE ) +if (conn->ops->get_cmd_val (work) !=SMB2_CANCEL ) requests_queue = &conn->requests;atomic_inc (&conn->req_running);
fs/smb/server/oplock.c +2 -2
@@ -642,7 +642,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 ); - rsp_hdr->Command =cpu_to_le16 (SMB2_OPLOCK_BREAK_HE ); + rsp_hdr->Command =cpu_to_le16 (SMB2_OPLOCK_BREAK ); rsp_hdr->Flags = (SMB2_FLAGS_SERVER_TO_REDIR ); rsp_hdr->NextCommand =0 ; rsp_hdr->MessageId =cpu_to_le64 (-1 );
@@ -749,7 +749,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 ); - rsp_hdr->Command =cpu_to_le16 (SMB2_OPLOCK_BREAK_HE ); + rsp_hdr->Command =cpu_to_le16 (SMB2_OPLOCK_BREAK ); rsp_hdr->Flags = (SMB2_FLAGS_SERVER_TO_REDIR ); rsp_hdr->NextCommand =0 ; rsp_hdr->MessageId =cpu_to_le64 (-1 );
fs/smb/server/smb2misc.c +22 -22
141 lines not on this page · raw message
fs/smb/server/smb2ops.c +23 -23
76 lines not on this page · raw message
fs/smb/server/smb2pdu.c +21 -21
132 lines not on this page · raw message
fs/smb/server/smb_common.c +1 -1
@@ -596,7 +596,7 @@ int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command)ksmbd_negotiate_smb_dialect (work->request_buf);ksmbd_debug (SMB ,"conn->dialect 0x%x\n" , conn->dialect); -if (command ==SMB2_NEGOTIATE_HE ) { +if (command ==SMB2_NEGOTIATE ) { ret =smb2_handle_negotiate (work);return ret; }
David Howells
maintainerRFC PATCH 10/31 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
@@ -270,13 +270,13 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, struct smb_hdr *in_buf, struct smb_hdr *out_buf, int *pbytes_returned, const int flags) { - int rc = 0; -struct smb_message *smb; unsigned int len = be32_to_cpu(in_buf->smb_buf_length); +struct TCP_Server_Info *server; +struct kvec resp_iov = {};struct kvec iov = { .iov_base = in_buf, .iov_len = 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 (ses ==NULL ) {cifs_dbg (VFS ,"Null smb session\n" );
@@ -305,78 +305,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, server, &smb->sequence_number); -if (rc) { -cifs_server_unlock (server); - goto out; - } - - smb->mid_state =MID_REQUEST_SUBMITTED ; - - rc =smb_send (server, in_buf, 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 (&server->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 (&server->mid_lock); -add_credits (server, &credits,0 ); -return rc; - } -spin_unlock (&server->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 =get_rfc1002_length (smb->resp_buf); -memcpy (out_buf, smb->resp_buf, *pbytes_returned +4 ); - 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
maintainerRFC PATCH 11/31 cifs: Fix SMB1 to not require separate kvec for the rfc1002 header
In reply to David HowellsFix SMB1 to not require separate kvec for the rfc1002 header, which seems to be something intended to make the signing algorithm simpler, but at the expense of additional complexity everywhere else.
--- fs/smb/client/cifsencrypt.c | 77 +++++++-------------------------- fs/smb/client/cifsproto.h | 5 --- fs/smb/client/cifssmb.c | 28 ++++++------ fs/smb/client/cifstransport.c | 81 +++++++---------------------------- fs/smb/client/smb1ops.c | 11 +++-- fs/smb/client/transport.c | 27 ++++++------ 6 files changed, 65 insertions(+), 164 deletions(-)
fs/smb/client/cifsencrypt.c +16 -61
@@ -58,38 +58,25 @@ int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server, char *signature, struct shash_desc *shash) { - int i; + struct iov_iter iter;ssize_t rc; -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 */ - } +size_t size =0 ; -for (; 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 =crypto_shash_update (shash, - 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); + +/* Skip the rfc1002 length for SMB1 */ +if (is_smb1 (server)) +iov_iter_advance (&iter,4 ); + +if (iov_iter_count (&iter) <=4 ) +return -EIO ; + + rc =cifs_shash_iter (&iter,iov_iter_count (&iter), shash); +if (rc <0 ) +return rc; rc =cifs_shash_iter (&rqst->rq_iter,iov_iter_count (&rqst->rq_iter), shash);if (rc <0 )
@@ -145,10 +132,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 ;
@@ -181,30 +164,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,struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence_number) -{ -struct kvec iov[2 ]; - - 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, - pexpected_response_sequence_number); -} -int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number)
@@ -214,10 +173,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/cifsproto.h +0 -5
@@ -29,8 +29,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);
@@ -556,9 +554,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 *); -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);
fs/smb/client/cifssmb.c +12 -16
@@ -591,9 +591,11 @@ CIFSSMBEcho(struct TCP_Server_Info *server) {ECHO_REQ *smb;int rc =0 ; -struct kvec iov[2 ]; -struct smb_rqst rqst = { .rq_iov = iov, - .rq_nvec =2 }; +struct kvec iov[1 ]; +struct smb_rqst rqst = { + .rq_iov = iov, + .rq_nvec =ARRAY_SIZE (iov), + };cifs_dbg (FYI ,"In echo request\n" );
@@ -612,10 +614,8 @@ CIFSSMBEcho(struct TCP_Server_Info *server) smb->Data[0 ] ='a' ;inc_rfc1001_len (smb,3 ); - iov[0 ].iov_len =4 ; + iov[0 ].iov_len =4 +get_rfc1002_length (smb); iov[0 ].iov_base = smb; - iov[1 ].iov_len =get_rfc1002_length (smb); - iov[1 ].iov_base = (char *)smb +4 ; rc =cifs_call_async (server, &rqst,NULL , cifs_echo_callback,NULL , server,CIFS_NON_BLOCKING |CIFS_ECHO_OP ,NULL );
@@ -1392,7 +1392,7 @@ cifs_async_readv(struct cifs_io_subrequest *rdata)int wct;struct cifs_tcon *tcon =tlink_tcon (rdata->req->cfile->tlink);struct smb_rqst rqst = { .rq_iov = rdata->iov, - .rq_nvec =2 }; + .rq_nvec =1 };cifs_dbg (FYI ,"%s: offset=%llu bytes=%zu\n" , __func__, rdata->subreq.start, rdata->subreq.len);
@@ -1433,9 +1433,7 @@ cifs_async_readv(struct cifs_io_subrequest *rdata)/* 4 for RFC1001 length + 1 for BCC */ rdata->iov[0 ].iov_base = smb; - rdata->iov[0 ].iov_len =4 ; - rdata->iov[1 ].iov_base = (char *)smb +4 ; - rdata->iov[1 ].iov_len =get_rfc1002_length (smb); + rdata->iov[0 ].iov_len =4 +get_rfc1002_length (smb); rc =cifs_call_async (tcon->ses->server, &rqst, cifs_readv_receive, cifs_readv_callback,NULL , rdata,0 ,NULL );
@@ -1764,7 +1762,7 @@ cifs_async_writev(struct cifs_io_subrequest *wdata)WRITE_REQ *req =NULL ;int wct;struct cifs_tcon *tcon =tlink_tcon (wdata->req->cfile->tlink); -struct kvec iov[2 ]; +struct kvec iov[1 ];struct smb_rqst rqst = { };if (tcon->ses->capabilities &CAP_LARGE_FILES ) {
@@ -1798,13 +1796,11 @@ cifs_async_writev(struct cifs_io_subrequest *wdata)cpu_to_le16 (offsetof(struct smb_com_write_req , Data) -4 );/* 4 for RFC1001 length + 1 for BCC */ - iov[0 ].iov_len =4 ; iov[0 ].iov_base = req; - iov[1 ].iov_len =get_rfc1002_length (req) +1 ; - iov[1 ].iov_base = (char *)req +4 ; + iov[0 ].iov_len =4 +get_rfc1002_length (req) +1 ; rqst.rq_iov = iov; - rqst.rq_nvec =2 ; + rqst.rq_nvec =1 ; rqst.rq_iter = wdata->subreq.io_iter; cifs_dbg(FYI, "async write at %llu %zu bytes\n",
@@ -1822,7 +1818,7 @@ cifs_async_writev(struct cifs_io_subrequest *wdata) (struct smb_com_writex_req *)req;inc_rfc1001_len (&reqw->hdr, wdata->subreq.len +5 );put_bcc (wdata->subreq.len +5 , &reqw->hdr); - iov[1 ].iov_len +=4 ;/* pad bigger by four bytes */ + iov[0 ].iov_len +=4 ;/* pad bigger by four bytes */ } rc = cifs_call_async(tcon->ses->server, &rqst, NULL,
fs/smb/client/cifstransport.c +15 -66
151 lines not on this page · raw message
fs/smb/client/smb1ops.c +8 -3
@@ -31,8 +31,10 @@ 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; +struct kvec iov[1 ]; +struct smb_rqst crqst = { .rq_iov = iov, .rq_nvec =1 }; +int rc =0 ;/* -4 for RFC1001 length and +2 for BCC field */ in_buf->smb_buf_length =cpu_to_be32 (sizeof (struct smb_hdr ) -4 +2 );
@@ -40,8 +42,11 @@ send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst, 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, server, &smb->sequence_number); + rc =cifs_sign_rqst (&crqst, server, &smb->sequence_number);if (rc) {cifs_server_unlock (server);return rc;
@@ -53,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,be32_to_cpu (in_buf->smb_buf_length)); + rc =__smb_send_rqst (server,1 , &crqst);if (rc <0 ) server->sequence_number--;
fs/smb/client/transport.c +14 -13
@@ -1036,23 +1036,24 @@ 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 + -HEADER_PREAMBLE_SIZE (server); - -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 + +HEADER_PREAMBLE_SIZE (server); +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
maintainerRFC PATCH 12/31 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 | 12 +- fs/smb/client/cifssmb.c | 18 +-- fs/smb/client/cifstransport.c | 210 +--------------------------------- fs/smb/client/smb1ops.c | 45 +++++++- fs/smb/client/transport.c | 10 +- 6 files changed, 75 insertions(+), 228 deletions(-)
fs/smb/client/cifsglob.h +6 -2
@@ -312,8 +312,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 *,
@@ -1713,6 +1714,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 */
@@ -1922,6 +1924,8 @@ static inline bool is_replayable_error(int error)#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 -8
@@ -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,11 +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 */); -extern int SendReceiveBlockingLock (const unsigned int xid, -struct cifs_tcon *ptcon, -struct smb_hdr *in_buf, -struct smb_hdr *out_buf, -int *bytes_returned);void smb2_query_server_interfaces (struct work_struct *work);void
fs/smb/client/cifssmb.c +10 -8
@@ -1997,7 +1997,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,LOCK_REQ *pSMB =NULL ;/* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ int bytes_returned; -int flags =0 ; +int flags =CIFS_WINDOWS_LOCK |CIFS_INTERRUPTIBLE_WAIT ;__u16 count; cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n",
@@ -2041,8 +2041,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, - (struct smb_hdr *) pSMB, &bytes_returned); + rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, + (struct smb_hdr *) pSMB, &bytes_returned, + flags);else rc =SendReceiveNoRsp (xid, tcon->ses, (char *)pSMB, flags);cifs_small_buf_release (pSMB);
@@ -2066,7 +2067,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,struct smb_com_transaction2_sfi_rsp *pSMBr =NULL ;struct cifs_posix_lock *parm_data;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;
@@ -2111,7 +2112,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
@@ -2128,13 +2129,14 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,inc_rfc1001_len (pSMB, byte_count); pSMB->ByteCount =cpu_to_le16 (byte_count);if (waitFlag) { - rc =SendReceiveBlockingLock (xid, tcon, (struct smb_hdr *) pSMB, - (struct smb_hdr *) pSMBr, &bytes_returned); + rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, + (struct smb_hdr *) pSMBr, &bytes_returned, + sr_flags); }else { iov[0 ].iov_base = (char *)pSMB; iov[0 ].iov_len =be32_to_cpu (pSMB->hdr.smb_buf_length) +4 ; 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 -205
222 lines not on this page · raw message
fs/smb/client/smb1ops.c +42 -3
63 lines not on this page · raw message
fs/smb/client/transport.c +8 -2
@@ -636,12 +636,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 ;
@@ -695,6 +699,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;
@@ -939,6 +944,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;/*
@@ -1005,7 +1011,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, smb[i]->command_id); -send_cancel (server, &rqst[i], smb[i]); +send_cancel (ses, server, &rqst[i], smb[i], xid);spin_lock (&server->mid_lock); smb[i]->mid_flags |=MID_WAIT_CANCELLED ; if (smb[i]->mid_state == MID_REQUEST_SUBMITTED ||
David Howells
maintainerRFC PATCH 13/31 cifs: Institute message managing struct
In reply to David HowellsTurn the smb_message struct into a message handling struct to aid in building an SMB message, queuing them and holding the resources and buffers. It has absorbed the mid_q_struct and now other fields are added.
The idea is that the smb_message struct will be allocated and filled in much higher up (typically in the PDU encoding code) and passed down to the transport.
In particular, the following fields:
(*) ->next: This is used to link together messages into compounds and then
walk through the message list.
(*) ->credits: The credit requirements for the message.
(*) ->request: Pointer to the smb_hdr struct for the request.
(*) ->command_id: The ID of the command in CPU endian form (better for
if- and switch-statements).
(*) ->total_len: The total length of the request message, not including
rfc1002 or transform headers.
(*) ->response: Pointer to the smb_hdr struct for the response.
(*) ->rqst, ->resp_buf_type, ->resp_iov: The old request info stuff.
Functions are provided to get and put refs upon the struct and also to drop all the refs on a compound string of structs.
--- fs/smb/client/cifsglob.h | 101 ++++++++++++++++++++++++---------- fs/smb/client/cifsproto.h | 10 +++- fs/smb/client/cifstransport.c | 2 +- fs/smb/client/connect.c | 6 +- fs/smb/client/smb1ops.c | 2 +- fs/smb/client/smb2ops.c | 2 +- fs/smb/client/smb2transport.c | 4 +- fs/smb/client/transport.c | 46 ++++++++++++++-- 8 files changed, 130 insertions(+), 43 deletions(-)
fs/smb/client/cifsglob.h +72 -29
@@ -1704,38 +1704,81 @@ typedef void (*mid_callback_t)(struct smb_message *smb);typedef int (*mid_handle_t )(struct TCP_Server_Info *server,struct smb_message *smb); -/* one of these for every pending CIFS request to the server */ +/* +* Definition of an SMB request message to be transmitted. These may be +* chained together and will automatically be turned into compound messages if +* they are. +* +* +-----------------------+ +* | NetBIOS/padding | +* +-----------------------+ <--- smb->request + pre_offset +* | (Transform header) | +* +-----------------------+ <--- smb->request +* | SMB2 Header | } } +* +-----------------------+ } header_size } +* | Req/Rsp struct | } } +* +-----------------------+ <--- smb->request + ext_offset } protocol_size +* | | } +* | Extra protocol data | } +* | | } +* +-----------------------+ <--- smb->request + smb->data_offset +* | | +* | Data Payload | data_size +* | | +* +-----------------------+ +* +* +* If the data is to be RDMA'd, it will be kept separate from the protocol. +*/ 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 */ -__u64 mid;/* multiplex id */ -__u16 credits;/* number of credits consumed by this mid */ -__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 */ +struct smb_message *next;/* Next message in compound */ +struct cifs_credits credits;/* Credit requirements for this message */ +void *request;/* Pointer to request message body */ +refcount_t ref; +bool sensitive;/* Request contains sensitive data */ +bool cancelled;/* T if cancelled */ +unsigned int sr_flags;/* Flags passed to send_recv() */ + +/* Queue state */ +struct list_head qhead;/* mids waiting on reply from this server */ +struct TCP_Server_Info *server;/* server corresponding to this mid */ +__u64 mid;/* multiplex id */ +__u16 credits_consumed;/* number of credits consumed by this op */ +__u16 credits_received;/* number of credits from the response */ +__u32 pid;/* process id */ +__u32 sequence_number;/* for CIFS signing */ +unsigned long when_alloc;/* when mid was created */ #ifdef CONFIG_CIFS_STATS2 -unsigned long when_sent;/* time when smb send finished */ -unsigned long when_received;/* when demux complete (taken off wire) */ +unsigned long when_sent;/* time when smb send finished */ +unsigned long when_received;/* when demux complete (taken off wire) */ #endif -mid_receive_t receive;/* call receive callback */ -mid_callback_t callback;/* call completion callback */ -mid_handle_t handle;/* call handle mid callback */ -void *callback_data;/* general purpose pointer for callback */ -struct task_struct *creator; -void *resp_buf;/* pointer to received SMB header */ -unsigned int resp_buf_size; -int mid_state;/* wish this were enum but can not pass to wait_event */ -int mid_rc;/* rc for MID_RC */ -unsigned int mid_flags; -unsigned int optype;/* operation type */ -enum smb2_command command_id;/* smb command code */ -bool large_buf:1 ;/* if valid response, is pointer to large buf */ -bool multiRsp:1 ;/* multiple trans2 responses for one request */ -bool multiEnd:1 ;/* both received */ -bool decrypted:1 ;/* decrypted entry */ +mid_receive_t receive;/* call receive callback */ +mid_callback_t callback;/* call completion callback */ +mid_handle_t handle;/* call handle mid callback */ +void *callback_data;/* general purpose pointer for callback */ +struct task_struct *creator; +void *resp_buf;/* pointer to received SMB header */ +unsigned int resp_buf_size; +int mid_state;/* wish this were enum but can not pass to wait_event */ +int mid_rc;/* rc for MID_RC */ +unsigned int mid_flags; +unsigned int optype;/* operation type */ +bool large_buf:1 ;/* if valid response, is pointer to large buf */ +bool multiRsp:1 ;/* multiple trans2 responses for one request */ +bool multiEnd:1 ;/* both received */ +bool decrypted:1 ;/* decrypted entry */ + +/* Request details */ +enum smb2_command command_id;/* Command ID */ +s16 pre_offset;/* Offset of pre-headers from ->body (negative) */ +unsigned int total_len;/* Total length of from hdr_offset onwards */ +/* Response */ +void *response;/* Protocol part of response */ +u32 response_len;/* Size of response */ +/* Compat with old code */ +struct smb_rqst rqst; +int *resp_buf_type; +struct kvec *resp_iov; };struct close_cancelled_open {
fs/smb/client/cifsproto.h +8 -2
@@ -82,7 +82,7 @@ extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx,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); +void __release_mid (struct smb_message *smb);extern void cifs_wake_up_task (struct smb_message *smb);extern int cifs_handle_standard (struct TCP_Server_Info *server,struct smb_message *smb);
@@ -755,7 +755,8 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)static inline void release_mid (struct smb_message *smb) { -kref_put (&smb->refcount, __release_mid); +if (refcount_dec_and_test (&smb->ref)) +__release_mid (smb); }static inline void cifs_free_open_info (struct cifs_open_info_data *data)
@@ -765,4 +766,9 @@ static inline void cifs_free_open_info(struct cifs_open_info_data *data) memset(data, 0, sizeof(*data)); } +struct smb_message *smb_message_alloc (enum smb2_command cmd,gfp_t gfp); +void smb_get_message (struct smb_message *smb); +void smb_put_message (struct smb_message *smb); +void smb_put_messages (struct smb_message *smb); +#endif /* _CIFSPROTO_H */
fs/smb/client/cifstransport.c +1 -1
@@ -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->ref,1 ); smb->mid =get_mid (smb_buffer); smb->pid = current->pid; smb->command_id =le16_to_cpu (smb_buffer->Command);
fs/smb/client/connect.c +3 -3
@@ -323,7 +323,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: moving mids to private list\n" , __func__);spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -kref_get (&smb->refcount); +smb_get_message (smb);if (smb->mid_state ==MID_REQUEST_SUBMITTED ) smb->mid_state =MID_RETRY_NEEDED ;list_move (&smb->qhead, &retry_list);
@@ -886,7 +886,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)*/ spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -kref_get (&smb->refcount); +smb_get_message (smb);list_move (&smb->qhead, &dispose_list); smb->mid_flags |=MID_DELETED ; }
@@ -1105,7 +1105,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_message (smb); smb->mid_state =MID_SHUTDOWN ;list_move (&smb->qhead, &dispose_list); smb->mid_flags |=MID_DELETED ;
fs/smb/client/smb1ops.c +1 -1
@@ -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 && smb->command_id == command) { -kref_get (&smb->refcount); +smb_get_message (smb);spin_unlock (&server->mid_lock);return smb; }
fs/smb/client/smb2ops.c +1 -1
@@ -407,7 +407,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_id == command)) { -kref_get (&smb->refcount); +smb_get_message (smb);if (dequeue) {list_del_init (&smb->qhead); smb->mid_flags |=MID_DELETED ;
fs/smb/client/smb2transport.c +2 -2
@@ -770,9 +770,9 @@ 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->ref,1 ); smb->mid =le64_to_cpu (shdr->MessageId); - smb->credits = credits >0 ? credits :1 ; + smb->credits_consumed = credits >0 ? credits :1 ; smb->pid = current->pid; smb->command_id =le16_to_cpu (shdr->Command); smb->when_alloc = jiffies;
fs/smb/client/transport.c +42 -4
65 lines not on this page · raw message
David Howells
maintainerRFC PATCH 14/31 cifs: Split crypt_message() into encrypt and decrypt variants
In reply to David HowellsSplit crypt_message() into encrypt and decrypt variants so that the encrypt variant can be substantially changed.
--- fs/smb/client/smb2ops.c | 100 ++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 15 deletions(-)
fs/smb/client/smb2ops.c +85 -15
@@ -4297,16 +4297,17 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)return -EAGAIN ; } +/* -* Encrypt or decrypt @rqst message. @rqst[0] has the following format: +* Encrypt @rqst message. @rqst[0] has the following format: * iov[0] - transform header (associate data), * iov[1-N] - SMB2 header and pages - data to encrypt. * On success return encrypted data in iov[1-N] and pages, leave iov[0] * untouched. */ static int -crypt_message (struct TCP_Server_Info *server,int num_rqst, -struct smb_rqst *rqst,int enc,struct crypto_aead *tfm) +encrypt_message (struct TCP_Server_Info *server,int num_rqst, +struct smb_rqst *rqst,struct crypto_aead *tfm) {struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)rqst[0 ].rq_iov[0 ].iov_base;
@@ -4321,10 +4322,10 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,void *creq;size_t sensitive_size; - rc =smb2_get_enc_key (server,le64_to_cpu (tr_hdr->SessionId), enc, key); + rc =smb2_get_enc_key (server,le64_to_cpu (tr_hdr->SessionId),1 , key);if (rc) { -cifs_server_dbg (FYI ,"%s: Could not get %scryption key. sid: 0x%llx\n" , __func__, - enc ?"en" :"de" ,le64_to_cpu (tr_hdr->SessionId)); +cifs_server_dbg (FYI ,"%s: Could not get encryption key. sid: 0x%llx\n" , + __func__,le64_to_cpu (tr_hdr->SessionId));return rc; }
@@ -4350,11 +4351,6 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,if (IS_ERR (creq))return PTR_ERR (creq); -if (!enc) { -memcpy (sign, &tr_hdr->Signature,SMB2_SIGNATURE_SIZE ); - crypt_len +=SMB2_SIGNATURE_SIZE ; - } -if ((server->cipher_type ==SMB2_ENCRYPTION_AES128_GCM ) || (server->cipher_type ==SMB2_ENCRYPTION_AES256_GCM ))memcpy (iv, (char *)tr_hdr->Nonce,SMB3_AES_GCM_NONCE );
@@ -4367,15 +4363,89 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,aead_request_set_crypt (req, sg, sg, crypt_len, iv);aead_request_set_ad (req, assoc_data_len); - rc = enc ?crypto_aead_encrypt (req) :crypto_aead_decrypt (req); + rc =crypto_aead_encrypt (req); -if (!rc && enc) +if (!rc)memcpy (&tr_hdr->Signature, sign,SMB2_SIGNATURE_SIZE );kvfree_sensitive (creq, sensitive_size);return rc; } +/* +* Decrypt @rqst message. @rqst[0] has the following format: +* iov[0] - transform header (associate data), +* iov[1-N] - SMB2 header and pages - data to decrypt. +* On success return encrypted data in iov[1-N] and pages, leave iov[0] +* untouched. +*/ +static int +decrypt_message (struct TCP_Server_Info *server,int num_rqst, +struct smb_rqst *rqst,struct crypto_aead *tfm) +{ +struct smb2_transform_hdr *tr_hdr = + (struct smb2_transform_hdr *)rqst[0 ].rq_iov[0 ].iov_base; +unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -20 ; +int rc =0 ; +struct scatterlist *sg; +u8 sign[SMB2_SIGNATURE_SIZE ] = {}; +u8 key[SMB3_ENC_DEC_KEY_SIZE ]; +struct aead_request *req; +u8 *iv; +unsigned int crypt_len =le32_to_cpu (tr_hdr->OriginalMessageSize); +void *creq; +size_t sensitive_size; + + rc =smb2_get_enc_key (server,le64_to_cpu (tr_hdr->SessionId),0 , key); +if (rc) { +cifs_server_dbg (FYI ,"%s: Could not get decryption key. sid: 0x%llx\n" , + __func__,le64_to_cpu (tr_hdr->SessionId)); +return rc; + } + +if ((server->cipher_type ==SMB2_ENCRYPTION_AES256_CCM ) || + (server->cipher_type ==SMB2_ENCRYPTION_AES256_GCM )) + rc =crypto_aead_setkey (tfm, key,SMB3_GCM256_CRYPTKEY_SIZE ); +else + rc =crypto_aead_setkey (tfm, key,SMB3_GCM128_CRYPTKEY_SIZE ); + +if (rc) { +cifs_server_dbg (VFS ,"%s: Failed to set aead key %d\n" , __func__, rc); +return rc; + } + + rc =crypto_aead_setauthsize (tfm,SMB2_SIGNATURE_SIZE ); +if (rc) { +cifs_server_dbg (VFS ,"%s: Failed to set authsize %d\n" , __func__, rc); +return rc; + } + + creq =smb2_get_aead_req (tfm, rqst, num_rqst, sign, &iv, &req, &sg, + &sensitive_size); +if (IS_ERR (creq)) +return PTR_ERR (creq); + +memcpy (sign, &tr_hdr->Signature,SMB2_SIGNATURE_SIZE ); + crypt_len +=SMB2_SIGNATURE_SIZE ; + +if ((server->cipher_type ==SMB2_ENCRYPTION_AES128_GCM ) || + (server->cipher_type ==SMB2_ENCRYPTION_AES256_GCM )) +memcpy (iv, (char *)tr_hdr->Nonce,SMB3_AES_GCM_NONCE ); +else { + iv[0 ] =3 ; +memcpy (iv +1 , (char *)tr_hdr->Nonce,SMB3_AES_CCM_NONCE ); + } + +aead_request_set_tfm (req, tfm); +aead_request_set_crypt (req, sg, sg, crypt_len, iv); +aead_request_set_ad (req, assoc_data_len); + + rc =crypto_aead_decrypt (req); + +kvfree_sensitive (creq, sensitive_size); +return rc; +} +/* * Clear a read buffer, discarding the folios which have the 1st mark set. */
@@ -4509,7 +4579,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,/* fill the 1st iov with a transform header */ fill_transform_hdr (tr_hdr, orig_len, old_rq, server->cipher_type); - rc =crypt_message (server, num_rqst, new_rq,1 , server->secmech.enc); + rc =encrypt_message (server, num_rqst, new_rq, server->secmech.enc);cifs_dbg (FYI ,"Encrypt message returned %d\n" , rc);if (rc) goto err_free;
@@ -4571,7 +4641,7 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf, tfm = server->secmech.dec; } - rc =crypt_message (server,1 , &rqst,0 , tfm); + rc =decrypt_message (server,1 , &rqst, tfm);cifs_dbg (FYI ,"Decrypt message returned %d\n" , rc);if (is_offloaded)
David Howells
maintainerRFC PATCH 15/31 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
@@ -4446,61 +4446,6 @@ decrypt_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. */
@@ -4526,7 +4471,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); }/*
@@ -4561,8 +4506,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;
@@ -4894,7 +4841,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); }
@@ -4932,9 +4879,9 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb, 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);
@@ -4995,7 +4942,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb, } free_pages: -cifs_clear_folioq_buffer (dw->buffer); +netfs_free_folioq_buffer (dw->buffer); free_dw:kfree (dw);return rc;
David Howells
maintainerRFC PATCH 16/31 cifs: Rewrite base TCP transmission
In reply to David Howells[!] NOTE: This patch is not fully complete: RDMA is untested and compression is currently disabled
Rewrite the base TCP transmission in cifs to copy all the content in a (compound) message into a buffer of pages in a bvecq chain. In future, the pages in this bvecq chain will be allocated from the netmem allocator so that the advance DMA/IOMMU handling will be done.
This list of pages can then be attached to an ITER_BVEC_QUEUE-type iov_iter and passed in a single call to sendmsg() with MSG_SPLICE_PAGES, thereby avoiding the need to copy the data in the TCP stack.
The encryption code can also be simplified as it only needs to encrypt the data stored in those pages, with the bonus that the content in the pages is correctly aligned for the encryption in place such that it does not need to copy the data whilst encrypting it.
It could be arranged for the data to be held in contiguous pages if possible and if necessary such that crypto can be offloaded to devices that only permit a single contiguous buffer.
--- fs/netfs/buffer.c | 3 +- fs/smb/client/cifsglob.h | 7 +- fs/smb/client/cifsproto.h | 5 +- fs/smb/client/smb1ops.c | 5 +- fs/smb/client/smb2ops.c | 193 ++++++++++++------------- fs/smb/client/smbdirect.c | 88 ++---------- fs/smb/client/smbdirect.h | 5 +- fs/smb/client/transport.c | 291 +++++++++++++++++++++++++++----------- 8 files changed, 330 insertions(+), 267 deletions(-)
fs/netfs/buffer.c +2 -1
@@ -93,7 +93,8 @@ void netfs_free_bvecq_buffer(struct bvecq *bq)for (; bq; bq = next) {for (int seg =0 ; seg < bq->nr_segs; seg++) -__free_page (bq->bv[seg].bv_page); +if (bq->bv[seg].bv_page) +__free_page (bq->bv[seg].bv_page); next = bq->next;kfree (bq); }
fs/smb/client/cifsglob.h +4 -3
@@ -594,8 +594,10 @@ struct smb_version_operations {long (*fallocate)(struct file *,struct cifs_tcon *,int ,loff_t ,loff_t );/* init transform (compress/encrypt) request */ -int (*init_transform_rq)(struct TCP_Server_Info *,int num_rqst, -struct smb_rqst *,struct smb_rqst *); +int (*init_transform_rq)(struct TCP_Server_Info *server, +int num_rqst,const struct smb_rqst *rqst, +struct smb2_transform_hdr *tr_hdr, +struct iov_iter *iter);int (*is_transform_hdr)(void *buf);int (*receive_transform)(struct TCP_Server_Info *,struct smb_message **smb,char **,int *);
@@ -1356,7 +1358,6 @@ struct tcon_link { };extern struct tcon_link *cifs_sb_tlink (struct cifs_sb_info *cifs_sb); -extern void smb3_free_compound_rqst (int num_rqst,struct smb_rqst *rqst);static inline struct cifs_tcon *tlink_tcon (struct tcon_link *tlink)
fs/smb/client/cifsproto.h +3 -2
@@ -32,6 +32,8 @@ extern void free_rsp_buf(int, void *);extern int smb_send_kvec (struct TCP_Server_Info *server,struct msghdr *msg,size_t *sent); +int smb_sendmsg (struct TCP_Server_Info *server,struct msghdr *smb_msg, +size_t *sent);extern unsigned int _get_xid (void );extern void _free_xid (unsigned int );#define get_xid () \
@@ -120,8 +122,7 @@ extern struct smb_message *cifs_setup_request(struct cifs_ses *, struct smb_rqst *);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); +int __smb_send_rqst (struct TCP_Server_Info *server,struct iov_iter *iter);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,
fs/smb/client/smb1ops.c +4 -1
@@ -32,6 +32,7 @@ send_nt_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server, struct smb_rqst *rqst, struct smb_message *smb, unsigned int xid) { + struct iov_iter iter;struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base;struct kvec iov[1 ];struct smb_rqst crqst = { .rq_iov = iov, .rq_nvec =1 };
@@ -53,13 +54,15 @@ send_nt_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server,return rc; } +iov_iter_kvec (&iter,ITER_SOURCE , iov,1 , iov[0 ].iov_len); +/* * The response to this call was already factored into the sequence * number when the call went out, so we must adjust it back downward * after signing here. */ --server->sequence_number; - rc =__smb_send_rqst (server,1 , &crqst); + rc =__smb_send_rqst (server, &iter);if (rc <0 ) server->sequence_number--;
fs/smb/client/smb2ops.c +94 -99
241 lines not on this page · raw message
fs/smb/client/smbdirect.c +15 -73
117 lines not on this page · raw message
fs/smb/client/smbdirect.h +2 -3
@@ -214,8 +214,7 @@ void smbd_destroy(struct TCP_Server_Info *server);/* Interface for carrying upper layer I/O through send/recv */ int smbd_recv (struct smbd_connection *info,struct msghdr *msg); -int smbd_send (struct TCP_Server_Info *server, -int num_rqst,struct smb_rqst *rqst); +int smbd_send (struct TCP_Server_Info *server,struct iov_iter *iter);enum mr_state {MR_READY ,
@@ -254,7 +253,7 @@ static inline void *smbd_get_connection(static inline int smbd_reconnect (struct TCP_Server_Info *server) {return -1 ; }static inline void smbd_destroy (struct TCP_Server_Info *server) {}static inline int smbd_recv (struct smbd_connection *info,struct msghdr *msg) {return -1 ; } -static inline int smbd_send (struct TCP_Server_Info *server,int num_rqst,struct smb_rqst *rqst) {return -1 ; } +static inline int smbd_send (struct TCP_Server_Info *server,struct iov_iter *iter) {return -1 ; }#endif #endif
fs/smb/client/transport.c +206 -85
361 lines not on this page · raw message
Stefan Metzmacher
reviewerRe: [RFC PATCH 16/31] cifs: Rewrite base TCP transmission
Am 06.08.25 um 22:36 schrieb David Howells:
Quoted 5 lines
fs/smb/client/transport.c +5
-0+int smb_sendmsg (struct TCP_Server_Info *server,struct msghdr *smb_msg, +size_t *sent) +{ +int rc =0 ; +int retries =0 ;
fs/smb/client/transport.c smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, · line 272
Quoted 10 lines
fs/smb/client/transport.c +10
-0+struct socket *ssocket = server->ssocket; + + *sent =0 ; + +if (server->noblocksnd) + smb_msg->msg_flags =MSG_DONTWAIT +MSG_NOSIGNAL ; +else + smb_msg->msg_flags =MSG_NOSIGNAL ; + smb_msg->msg_flags =MSG_SPLICE_PAGES ; +
I guess you want '|=' instead of '=' in all 3 lines?
I also think msghdr should be setup in the caller completely or it should be a local variable in smb_sendmsg() and the caller only passes struct iov_iter.
metze
David Howells
maintainerRe: [RFC PATCH 16/31] cifs: Rewrite base TCP transmission
Quoted 8 lines · Stefan Metzmacher
Quoted 6 lines
+ if (
server->noblocksnd)
+smb_msg->msg_flags=MSG_DONTWAIT+MSG_NOSIGNAL;
+ else
+smb_msg->msg_flags=MSG_NOSIGNAL;
+smb_msg->msg_flags=MSG_SPLICE_PAGES;
+I guess you want '|=' instead of '=' in all 3 lines?
Well on the third line. msg_flags is 0 on entry to the function.
Quoted 3 lines
I also think msghdr should be setup in the caller completely or it should be a local variable in
smb_sendmsg()and the caller only passes structiov_iter.
Yeah, makes sense.
David
David Howells
maintainerRe: [RFC PATCH 16/31] cifs: Rewrite base TCP transmission
In reply to Stefan MetzmacherQuoted 1 line · Stefan Metzmacher
Quoted 1 line
+
smb_msg->msg_flags=MSG_DONTWAIT+MSG_NOSIGNAL;
And whilst I'm sure addition works, I would much rather that be bit-OR.
David
David Howells
maintainerRFC PATCH 17/31 cifs: Rework smb2 decryption
In reply to David Howells--- fs/smb/client/cifsglob.h | 60 ----------------- fs/smb/client/smb2ops.c | 138 +++++---------------------------------- 2 files changed, 15 insertions(+), 183 deletions(-)
fs/smb/client/cifsglob.h +0 -60
@@ -2280,66 +2280,6 @@ static inline void move_cifs_info_to_smb2(struct smb2_file_all_info *dst, const dst->FileNameLength = src->FileNameLength; } -static inline int cifs_get_num_sgs (const struct smb_rqst *rqst, -int num_rqst, -const u8 *sig) -{ -unsigned int len, skip; -unsigned int nents =0 ; -unsigned long addr; -size_t data_size; -int i, j; - -/* -* The first rqst has a transform header where the first 20 bytes are -* not part of the encrypted blob. -*/ - skip =20 ; - -/* Assumes the first rqst has a transform header as the first iov. -* I.e. -* rqst[0].rq_iov[0] is transform header -* rqst[0].rq_iov[1+] data to be encrypted/decrypted -* rqst[1+].rq_iov[0+] data to be encrypted/decrypted -*/ -for (i =0 ; i < num_rqst; i++) { - data_size =iov_iter_count (&rqst[i].rq_iter); - -/* We really don't want a mixture of pinned and unpinned pages -* in the sglist. It's hard to keep track of which is what. -* Instead, we convert to a BVEC-type iterator higher up. -*/ -if (data_size && -WARN_ON_ONCE (user_backed_iter (&rqst[i].rq_iter))) -return -EIO ; - -/* We also don't want to have any extra refs or pins to clean -* up in the sglist. -*/ -if (data_size && -WARN_ON_ONCE (iov_iter_extract_will_pin (&rqst[i].rq_iter))) -return -EIO ; - -for (j =0 ; j < rqst[i].rq_nvec; j++) { -struct kvec *iov = &rqst[i].rq_iov[j]; - - addr = (unsigned long )iov->iov_base + skip; -if (is_vmalloc_or_module_addr ((void *)addr)) { - len = iov->iov_len - skip; - nents +=DIV_ROUND_UP (offset_in_page (addr) + len, -PAGE_SIZE ); - }else { - nents++; - } - skip =0 ; - } -if (data_size) - nents +=iov_iter_npages (&rqst[i].rq_iter,INT_MAX ); - } - nents +=DIV_ROUND_UP (offset_in_page (sig) +SMB2_SIGNATURE_SIZE ,PAGE_SIZE ); -return nents; -} -/* We can not use the normal sg_set_buf() as we will sometimes pass a * stack object as buf. */
fs/smb/client/smb2ops.c +15 -123
198 lines not on this page · raw message
David Howells
maintainerRFC PATCH 18/31 cifs: Pass smb_message structs down into the transport layer
In reply to David HowellsInstitute the creation of smb_message structs at the layer above the transport layer and pass them down into the transport layer. This replaces the handling of mid_q_structs entirely within the transport layer.
This includes the following changes:
(1) The smb_rqst struct is partially absorbed into the smb_message struct. Because the latter is on a linked list, the fixed-size arrays of requests can be got rid of - along with the COMPOUND_MAX-1 limit that gets imposed by the encryption code because it needs to steal a slot for the transform header.
(2) Hand smb_message structs into the message sending code in the transport rather than allocating them (as it did for mid_q_structs) in the ->setup_request/->setup_async_request functions.
For the moment compound_send_rcv() does the generation of smb_message structs, stringing them together before passing them down.
--- fs/smb/client/cifsglob.h | 38 ++-- fs/smb/client/cifsproto.h | 39 ++-- fs/smb/client/cifssmb.c | 1 - fs/smb/client/cifstransport.c | 8 +- fs/smb/client/compress.h | 6 +- fs/smb/client/connect.c | 24 +-- fs/smb/client/netmisc.c | 5 +- fs/smb/client/smb1ops.c | 19 +- fs/smb/client/smb2misc.c | 45 ++--- fs/smb/client/smb2ops.c | 40 +++-- fs/smb/client/smb2pdu.c | 212 +++++++++++++--------- fs/smb/client/smb2proto.h | 31 ++-- fs/smb/client/smb2transport.c | 183 +++++++------------ fs/smb/client/transport.c | 325 +++++++++++++++++++--------------- 14 files changed, 501 insertions(+), 475 deletions(-)
fs/smb/client/cifsglob.h +17 -21
@@ -313,26 +313,24 @@ struct cifs_credits;struct smb_version_operations {int (*send_cancel)(struct cifs_ses *ses,struct TCP_Server_Info *server, -struct smb_rqst *rqst,struct smb_message *smb, -unsigned int xid); +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 *, -struct TCP_Server_Info *, -struct smb_rqst *); +/* setup request: set up mid, sign message */ +int (*setup_request)(struct cifs_ses *ses, +struct TCP_Server_Info *server, +struct smb_message *smb);/* setup async request: allocate mid, sign message */ -struct smb_message *(*setup_async_request)(struct TCP_Server_Info *, -struct smb_rqst *); +int (*setup_async_request)(struct TCP_Server_Info *server,struct smb_message *smb);/* check response: verify signature, map error */ -int (*check_receive)(struct smb_message *,struct TCP_Server_Info *, -bool ); +int (*check_receive)(struct smb_message *smb,struct TCP_Server_Info *server, +bool log_error);void (*add_credits)(struct TCP_Server_Info *server,struct cifs_credits *credits,const int optype);void (*set_credits)(struct TCP_Server_Info *,const int );int * (*get_credits_field)(struct TCP_Server_Info *,const int );unsigned int (*get_credits)(struct smb_message *smb); -__u64 (*get_next_mid)(struct TCP_Server_Info *); +__u64 (*get_next_mid)(struct TCP_Server_Info *server,unsigned int count);void (*revert_current_mid)(struct TCP_Server_Info *server,const unsigned int val);/* data offset from read response message */
@@ -537,8 +535,8 @@ struct smb_version_operations {void (*new_lease_key)(struct cifs_fid *);int (*generate_signingkey)(struct cifs_ses *ses,struct TCP_Server_Info *server); -int (*calc_signature)(struct smb_rqst *,struct TCP_Server_Info *, -bool allocate_crypto); +int (*calc_signature)(struct smb_message *smb,struct TCP_Server_Info *server, +bool allocate_crypto);int (*set_integrity)(const unsigned int ,struct cifs_tcon *tcon,struct cifsFileInfo *src_file); int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon,
@@ -594,10 +592,8 @@ struct smb_version_operations {long (*fallocate)(struct file *,struct cifs_tcon *,int ,loff_t ,loff_t );/* init transform (compress/encrypt) request */ -int (*init_transform_rq)(struct TCP_Server_Info *server, -int num_rqst,const struct smb_rqst *rqst, -struct smb2_transform_hdr *tr_hdr, -struct iov_iter *iter); +int (*init_transform_rq)(struct TCP_Server_Info *server,struct smb_message *head_smb, +struct smb2_transform_hdr *tr_hdr,struct iov_iter *iter);int (*is_transform_hdr)(void *buf);int (*receive_transform)(struct TCP_Server_Info *,struct smb_message **smb,char **,int *);
@@ -945,16 +941,16 @@ adjust_credits(struct TCP_Server_Info *server, struct cifs_io_subrequest *subreq server->ops->adjust_credits(server, subreq, trace) : 0; } -static inline __le64 -get_next_mid64 (struct TCP_Server_Info *server) +static inline __u64 +get_next_mid64 (struct TCP_Server_Info *server,unsigned int count) { -return cpu_to_le64 (server->ops->get_next_mid (server)); +return server->ops->get_next_mid (server, count); }static inline __le16 get_next_mid (struct TCP_Server_Info *server) { -__u16 mid = server->ops->get_next_mid (server); +__u16 mid = server->ops->get_next_mid (server,1 );/* * The value in the SMB header should be little endian for easy * on-the-wire decoding.
fs/smb/client/cifsproto.h +16 -23
@@ -83,8 +83,6 @@ 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 smb_message *smb);extern void cifs_wake_up_task (struct smb_message *smb);extern int cifs_handle_standard (struct TCP_Server_Info *server,struct smb_message *smb);
@@ -96,15 +94,16 @@ extern int cifs_ipaddr_cmp(struct sockaddr *srcaddr, struct sockaddr *rhs);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, -const struct cifs_credits *exist_credits); +struct smb_message *msg,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,struct TCP_Server_Info *server,struct smb_rqst *rqst,int *resp_buf_type,const int flags,struct kvec *resp_iov); +int smb_send_recv_messages (const unsigned int xid,struct cifs_ses *ses, +struct TCP_Server_Info *server, +struct smb_message *smb,const int flags); extern int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, struct TCP_Server_Info *server, const int flags, const int num_rqst,
@@ -117,14 +116,14 @@ extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,extern int SendReceiveNoRsp (const unsigned int xid,struct cifs_ses *ses,char *in_buf,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 *, -struct smb_rqst *); -extern struct smb_message *cifs_setup_async_request (struct TCP_Server_Info *, -struct smb_rqst *); +int cifs_setup_request (struct cifs_ses *ses, +struct TCP_Server_Info *server, +struct smb_message *smb); +int cifs_setup_async_request (struct TCP_Server_Info *server, +struct smb_message *smb);int __smb_send_rqst (struct TCP_Server_Info *server,struct iov_iter *iter); -extern int cifs_check_receive (struct smb_message *msg, -struct TCP_Server_Info *server,bool log_error); +int cifs_check_receive (struct smb_message *smb, +struct TCP_Server_Info *server,bool log_error);int wait_for_free_request (struct TCP_Server_Info *server,const int flags,unsigned int *instance); extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server,
@@ -133,11 +132,10 @@ extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server,static inline int send_cancel (struct cifs_ses *ses,struct TCP_Server_Info *server, -struct smb_rqst *rqst,struct smb_message *smb, -unsigned int xid) +struct smb_message *smb,unsigned int xid) {return server->ops->send_cancel ? - server->ops->send_cancel (ses, server, rqst, smb, xid) :0 ; + server->ops->send_cancel (ses, server, smb, xid) :0 ; }int wait_for_response (struct TCP_Server_Info *server,struct smb_message *smb);
@@ -181,7 +179,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);extern void header_assemble (struct smb_hdr *,char /* command */ ,const struct cifs_tcon *,int /* length of fixed section (word count) in two byte units */ );
@@ -754,12 +753,6 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)return true; } -static inline void release_mid (struct smb_message *smb) -{ -if (refcount_dec_and_test (&smb->ref)) -__release_mid (smb); -} -static inline void cifs_free_open_info (struct cifs_open_info_data *data) {kfree (data->symlink_target);
fs/smb/client/cifssmb.c +0 -1
@@ -582,7 +582,6 @@ cifs_echo_callback(struct smb_message *smb)struct TCP_Server_Info *server = smb->callback_data;struct cifs_credits credits = { .value =1 , .instance =0 }; -release_mid (smb);add_credits (server, &credits,CIFS_ECHO_OP ); }
fs/smb/client/cifstransport.c +4 -4
@@ -101,8 +101,8 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,return 0 ; } -struct smb_message * -cifs_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst) +int +cifs_setup_async_request (struct TCP_Server_Info *server,struct smb_message *smb) {int rc;struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base;
@@ -181,9 +181,9 @@ cifs_check_receive(struct smb_message *smb, struct TCP_Server_Info *server,return map_and_check_smb_error (smb, log_error); } -struct smb_message * +int cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *ignored, -struct smb_rqst *rqst) +struct smb_message *smb) {int rc;struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base;
fs/smb/client/compress.h +3 -3
@@ -35,7 +35,7 @@ int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq, compress_s* should_compress() - Determines if a request (write) or the response to a * request (read) should be compressed. * @tcon: tcon of the request is being sent to -* @rqst: request to evaluate +* @smb: request to evaluate * * Return: true iff: * - compression was successfully negotiated with server
@@ -46,7 +46,7 @@ int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq, compress_s* * Return false otherwise. */ -bool should_compress (const struct cifs_tcon *tcon,const struct smb_rqst *rq); +bool should_compress (const struct cifs_tcon *tcon,const struct smb_message *smb);/** * smb_compress_alg_valid() - Validate a compression algorithm.
@@ -77,7 +77,7 @@ static inline int smb_compress(void *unused1, void *unused2, void *unused3)return -EOPNOTSUPP ; } -static inline bool should_compress (void *unused1,void *unused2) +static inline bool should_compress (const struct cifs_tcon *tcon,const struct smb_message *smb) {return false; }
fs/smb/client/connect.c +9 -15
@@ -323,7 +323,6 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: moving mids to private list\n" , __func__);spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -smb_get_message (smb);if (smb->mid_state ==MID_REQUEST_SUBMITTED ) smb->mid_state =MID_RETRY_NEEDED ;list_move (&smb->qhead, &retry_list);
@@ -336,7 +335,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)list_for_each_entry_safe (smb, nsmb, &retry_list, qhead) {list_del_init (&smb->qhead); smb->callback (smb); -release_mid (smb); +smb_put_message (smb); }if (cifs_rdma_enabled (server)) {
@@ -871,9 +870,9 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) server->tcpStatus == CifsInNegotiate && !server->with_rfc1001 && server->rfc1001_sessinit != 0) { -int rc, mid_rc;struct smb_message *smb, *nsmb;LIST_HEAD (dispose_list); +int rc, mid_rc;cifs_dbg (FYI ,"RFC 1002 negative session response during SMB Negotiate, retrying with NetBIOS session\n" );
@@ -886,7 +885,6 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)*/ spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -smb_get_message (smb);list_move (&smb->qhead, &dispose_list); smb->mid_flags |=MID_DELETED ; }
@@ -920,7 +918,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) smb->mid_rc = mid_rc; smb->mid_state =MID_RC ; smb->callback (smb); -release_mid (smb); +smb_put_message (smb); }/*
@@ -1097,15 +1095,12 @@ clean_demultiplex_info(struct TCP_Server_Info *server) }if (!list_empty (&server->pending_mid_q)) { -struct smb_message *smb; -struct list_head *tmp, *tmp2; +struct smb_message *smb, *smb2;LIST_HEAD (dispose_list);spin_lock (&server->mid_lock); -list_for_each_safe (tmp, tmp2, &server->pending_mid_q) { - smb = list_entry(tmp, struct smb_message, qhead); +list_for_each_entry_safe (smb, smb2, &server->pending_mid_q, qhead) {cifs_dbg (FYI ,"Clearing mid %llu\n" , smb->mid); -smb_get_message (smb); smb->mid_state =MID_SHUTDOWN ;list_move (&smb->qhead, &dispose_list); smb->mid_flags |=MID_DELETED ;
@@ -1113,12 +1108,11 @@ clean_demultiplex_info(struct TCP_Server_Info *server)spin_unlock (&server->mid_lock);/* now walk dispose list and issue callbacks */ -list_for_each_safe (tmp, tmp2, &dispose_list) { - smb = list_entry(tmp, struct smb_message, qhead); +list_for_each_entry_safe (smb, smb2, &dispose_list, qhead) {cifs_dbg (FYI ,"Callback mid %llu\n" , smb->mid);list_del_init (&smb->qhead); smb->callback (smb); -release_mid (smb); +smb_put_message (smb); }/* 1/8th of sec is more than enough time for them to exit */ msleep (125 );
@@ -1361,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]); +smb_put_message (smbs[i]);continue ; }
@@ -1396,7 +1390,7 @@ cifs_demultiplex_thread(void *p)if (!smbs[i]->multiRsp || smbs[i]->multiEnd) smbs[i]->callback (smbs[i]); -release_mid (smbs[i]); +smb_put_message (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 +8 -11
@@ -29,11 +29,10 @@*/ static int send_nt_cancel (struct cifs_ses *ses,struct TCP_Server_Info *server, -struct smb_rqst *rqst,struct smb_message *smb, -unsigned int xid) +struct smb_message *smb,unsigned int xid) {struct iov_iter iter; -struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; +struct smb_hdr *in_buf = (struct smb_hdr *)smb->rqst.rq_iov[0 ].iov_base;struct kvec iov[1 ];struct smb_rqst crqst = { .rq_iov = iov, .rq_nvec =1 };int rc =0 ;
@@ -80,10 +79,9 @@ send_nt_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server,*/ static int send_lock_cancel (struct cifs_ses *ses,struct TCP_Server_Info *server, -struct smb_rqst *rqst,struct smb_message *smb, -unsigned int xid) +struct smb_message *smb,unsigned int xid) { -struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; +struct smb_hdr *in_buf = (struct smb_hdr *)smb->rqst.rq_iov[0 ].iov_base;LOCK_REQ *pSMB = (LOCK_REQ *)in_buf;int rc;
@@ -104,12 +102,11 @@ send_lock_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server, }static int cifs_send_cancel (struct cifs_ses *ses,struct TCP_Server_Info *server, -struct smb_rqst *rqst,struct smb_message *smb, -unsigned int xid) +struct smb_message *smb,unsigned int xid) {if (smb->sr_flags &CIFS_WINDOWS_LOCK ) -return send_lock_cancel (ses, server, rqst, smb, xid); -return send_nt_cancel (ses, server, rqst, smb, xid); +return send_lock_cancel (ses, server, smb, xid); +return send_nt_cancel (ses, server, smb, xid); } static bool
@@ -210,7 +207,7 @@ cifs_get_credits(struct smb_message *smb)* so many threads being in the vfs at one time. */ static __u64 -cifs_get_next_mid (struct TCP_Server_Info *server) +cifs_get_next_mid (struct TCP_Server_Info *server,unsigned int count) {__u64 mid =0 ;__u16 last_mid, cur_mid;
fs/smb/client/smb2misc.c +25 -20
75 lines not on this page · raw message
fs/smb/client/smb2ops.c +23 -17
@@ -370,12 +370,13 @@ smb2_adjust_credits(struct TCP_Server_Info *server, }static __u64 -smb2_get_next_mid (struct TCP_Server_Info *server) +smb2_get_next_mid (struct TCP_Server_Info *server,unsigned int count) {__u64 mid;/* for SMB2 we need the current value */ spin_lock (&server->mid_lock); - mid = server->CurrentMid++; + mid = server->CurrentMid; + server->CurrentMid = mid +umax (count,1 );spin_unlock (&server->mid_lock);return mid; }
@@ -407,7 +408,6 @@ __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_id == command)) { -smb_get_message (smb);if (dequeue) {list_del_init (&smb->qhead); smb->mid_flags |=MID_DELETED ;
@@ -4168,10 +4168,12 @@ smb2_dir_needs_close(struct cifsFileInfo *cfile) }static void -fill_transform_hdr (struct smb2_transform_hdr *tr_hdr,unsigned int orig_len, -const struct smb_rqst *old_rq,__le16 cipher_type) +fill_transform_hdr (struct smb2_transform_hdr *tr_hdr, +struct smb_message *head_smb, +unsigned int orig_len, +__le16 cipher_type) { -struct smb2_hdr *shdr = (struct smb2_hdr *)old_rq->rq_iov[0 ].iov_base; +struct smb2_hdr *shdr = head_smb->request; *tr_hdr = (struct smb2_transform_hdr ){ .ProtocolId =SMB2_TRANSFORM_PROTO_NUM ,
@@ -4422,7 +4424,6 @@ decrypt_message(struct TCP_Server_Info *server,aead_request_set_ad (req, assoc_data_len); rc =crypto_aead_decrypt (req); -kvfree_sensitive (creq, sensitive_size);return rc; }
@@ -4434,13 +4435,14 @@ decrypt_message(struct TCP_Server_Info *server,*/ static int smb3_init_transform_rq (struct TCP_Server_Info *server, -int num_rqst,const struct smb_rqst *rqst, +struct smb_message *head_smb,struct smb2_transform_hdr *tr_hdr,struct iov_iter *iter) + {int rc; -fill_transform_hdr (tr_hdr,iov_iter_count (iter), rqst, +fill_transform_hdr (tr_hdr, head_smb,iov_iter_count (iter), server->cipher_type); rc =encrypt_message (server, tr_hdr, iter, server->secmech.enc);
@@ -4689,9 +4691,9 @@ static void smb2_decrypt_offload(struct work_struct *work) dw->server->lstrp = jiffies; smb =smb2_find_dequeue_mid (dw->server, dw->buf); -if (smb ==NULL ) +if (smb ==NULL ) {cifs_dbg (FYI ,"mid not found\n" ); -else { + }else { smb->decrypted = true; rc = handle_read_data(dw->server, smb, dw->buf, dw->server->vals->read_rsp_size,
@@ -4724,7 +4726,7 @@ static void smb2_decrypt_offload(struct work_struct *work)spin_unlock (&dw->server->srv_lock); } } -release_mid (smb); +smb_put_message (smb); } free_pages:
@@ -4735,9 +4737,12 @@ static void smb2_decrypt_offload(struct work_struct *work)static int -receive_encrypted_read (struct TCP_Server_Info *server,struct smb_message **smb, +receive_encrypted_read (struct TCP_Server_Info *server,struct smb_message **mid,int *num_mids) { +WARN_ON_ONCE (1 ); +return -ENOANO ;// TODO +#if 0 char *buf = server->smallbuf;struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;struct iov_iter iter;
@@ -4753,8 +4758,8 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb, dw->server = server; *num_mids =1 ; - len = min_t(unsigned int, buflen, server->vals->read_rsp_size + -sizeof (struct smb2_transform_hdr )) -HEADER_SIZE (server) +1 ; + len =umin (buflen, server->vals->read_rsp_size + +sizeof (struct smb2_transform_hdr )) -HEADER_SIZE (server) +1 ; rc =cifs_read_from_socket (server, buf +HEADER_SIZE (server) -1 , len);if (rc <0 )
@@ -4836,6 +4841,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb, discard_data:cifs_discard_remaining_data (server); goto free_pages; +#endif } static int
@@ -4893,9 +4899,9 @@ receive_encrypted_standard(struct TCP_Server_Info *server, } smb =smb2_find_mid (server, buf); -if (smb ==NULL ) +if (smb ==NULL ) {cifs_dbg (FYI ,"mid not found\n" ); -else { + }else {cifs_dbg (FYI ,"mid found\n" ); smb->decrypted = true; smb->resp_buf_size = server->pdu_size;
fs/smb/client/smb2pdu.c +125 -87
372 lines not on this page · raw message
fs/smb/client/smb2proto.h +14 -17
@@ -29,22 +29,20 @@ extern char *smb2_get_data_area_len(int *off, int *len,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 smb_message *smb, -struct TCP_Server_Info *server,bool log_error); -extern struct smb_message *smb2_setup_request (struct cifs_ses *ses, -struct TCP_Server_Info *, -struct smb_rqst *rqst); -extern struct smb_message *smb2_setup_async_request ( -struct TCP_Server_Info *server,struct smb_rqst *rqst); +int smb2_verify_signature (struct smb_message *smb,struct TCP_Server_Info *server); +int smb2_check_receive (struct smb_message *smb,struct TCP_Server_Info *server, +bool log_error); +int smb2_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *server, +struct smb_message *smb); +int smb2_setup_async_request (struct TCP_Server_Info *server,struct smb_message *smb);extern struct cifs_tcon *smb2_find_smb_tcon (struct TCP_Server_Info *server,__u64 ses_id,__u32 tid); -extern int smb2_calc_signature (struct smb_rqst *rqst, -struct TCP_Server_Info *server, -bool allocate_crypto); -extern int smb3_calc_signature (struct smb_rqst *rqst, -struct TCP_Server_Info *server, -bool allocate_crypto); +int smb2_calc_signature (struct smb_message *smb, +struct TCP_Server_Info *server, +bool allocate_crypto); +int smb3_calc_signature (struct smb_message *smb, +struct TCP_Server_Info *server, +bool allocate_crypto);extern void smb2_echo_request (struct work_struct *work);extern __le32 smb2_get_lease_state (struct cifsInodeInfo *cinode); extern bool smb2_is_valid_oplock_break(char *buffer,
@@ -127,8 +125,7 @@ extern int smb2_unlock_range(struct cifsFileInfo *cfile,extern int smb2_push_mandatory_locks (struct cifsFileInfo *cfile);extern void smb2_reconnect_server (struct work_struct *work);extern int smb3_crypto_aead_allocate (struct TCP_Server_Info *server); -extern unsigned long smb_rqst_len (struct TCP_Server_Info *server, -struct smb_rqst *rqst); +extern unsigned long smb_rqst_len (struct TCP_Server_Info *server,struct smb_rqst *rqst);extern void smb2_set_next_command (struct cifs_tcon *tcon,struct smb_rqst *rqst);extern void smb2_set_related (struct smb_rqst *rqst);
@@ -298,7 +295,7 @@ extern void smb2_copy_fs_info_to_kstatfs(extern int smb311_crypto_shash_allocate (struct TCP_Server_Info *server);extern int smb311_update_preauth_hash (struct cifs_ses *ses,struct TCP_Server_Info *server, -struct kvec *iov,int nvec); +struct smb_message *smb,bool hash_resp); extern int smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, const char *path, u32 desired_access,
fs/smb/client/smb2transport.c +68 -115
354 lines not on this page · raw message
fs/smb/client/transport.c +186 -139
560 lines not on this page · raw message
Re: [RFC PATCH 18/31] cifs: Pass smb_message structs down into the transport layer
Hi David,
Quoted 26 lines · David Howells
...
static int
fs/smb/client/smb2ops.c +1
-1-receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb, +receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **mid,int
*num_mids)
{fs/smb/client/smb2ops.c +3
-0+WARN_ON_ONCE (1 ); +return -ENOANO ;// TODO +#if 0 char *buf = server->smallbuf; struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; struct iov_iter iter;fs/smb/client/smb2ops.c +2
-2@@ -4753,8 +4758,8 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb, dw->server = server; *num_mids =1 ; - len = min_t(unsigned int, buflen, server->vals->read_rsp_size + -sizeof (struct smb2_transform_hdr )) -HEADER_SIZE (server) +1 ; + len =umin (buflen, server->vals->read_rsp_size + +sizeof (struct smb2_transform_hdr )) -HEADER_SIZE (server) +1 ; rc =cifs_read_from_socket (server, buf +HEADER_SIZE (server) -1 , len);if (rc <0 )@@ -4836,6 +4841,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct smb_message **smb,
discard_data:
Quoted 4 lines
cifs_discard_remaining_data(server); goto free_pages;+#endif
}
I don't quite get why this was commented out (and also seems unrelated to patch subject).
What problems did you have here? Does it not work?
David Howells
maintainerRFC PATCH 19/31 cifs: Clean up mid->callback_data and kill off mid->creator
In reply to David HowellsWe shouldn't really be pinning a task_struct on the mid_q_struct. Better to provide a wait queue there and have the waiter wait on it. For synchronous operations, this allows them to remove themselves from it once this is absorbed into smb_message and smb_message is generated higher up the stack. This also gets rid of one of the uses of mid->callback_data.
We can also get rid of the need for callback_data for the Echo command callback by passing a server pointer down into ->callback() from the callers (all of which have it available). This can also be used in the Read and Write callbacks.
We then only need the callback_data for the Read and Write commands - and in both cases, it points to a cifs_io_subrequest struct. So replace callback_data with a specifically typed pointer in a union that other users can be added to as the need arises.
--- fs/smb/client/cifs_debug.c | 3 +-- fs/smb/client/cifsglob.h | 11 ++++++++--- fs/smb/client/cifsproto.h | 2 +- fs/smb/client/cifstransport.c | 1 - fs/smb/client/connect.c | 8 ++++---- fs/smb/client/smb2ops.c | 6 +++--- fs/smb/client/smb2pdu.c | 18 +++++++----------- fs/smb/client/smb2transport.c | 6 ------ fs/smb/client/transport.c | 27 +++++++++++++-------------- 9 files changed, 37 insertions(+), 45 deletions(-)
fs/smb/client/cifs_debug.c +1 -2
@@ -625,11 +625,10 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) chan_server->conn_id);spin_lock (&chan_server->mid_lock);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" , +seq_printf (m,"\n\t\tState: %d com: %d pid: %d mid %llu" , smb->mid_state, smb->command_id, smb->pid, - smb->callback_data, smb->mid); }spin_unlock (&chan_server->mid_lock);
fs/smb/client/cifsglob.h +8 -3
@@ -1692,7 +1692,8 @@ 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 *server, +struct smb_message *smb);/* * This is the protopyte for mid handle function. This is called once the mid
@@ -1731,11 +1732,17 @@ struct smb_message {struct smb_message *next;/* Next message in compound */ struct cifs_credits credits;/* Credit requirements for this message */ void *request;/* Pointer to request message body */ +wait_queue_head_t waitq;/* Wait queue for message events */ refcount_t ref;bool sensitive;/* Request contains sensitive data */ bool cancelled;/* T if cancelled */ unsigned int sr_flags;/* Flags passed to send_recv() */ +/* PDU-type specific data */ +union { +struct cifs_io_subrequest *subreq;/* Read/write subrequest */ + }; +/* Queue state */ struct list_head qhead;/* mids waiting on reply from this server */ struct TCP_Server_Info *server;/* server corresponding to this mid */
@@ -1752,8 +1759,6 @@ struct smb_message {mid_receive_t receive;/* call receive callback */ mid_callback_t callback;/* call completion callback */ mid_handle_t handle;/* call handle mid callback */ -void *callback_data;/* general purpose pointer for callback */ -struct task_struct *creator;void *resp_buf;/* pointer to received SMB header */ unsigned int resp_buf_size;int mid_state;/* wish this were enum but can not pass to wait_event */
fs/smb/client/cifsproto.h +1 -1
@@ -83,7 +83,7 @@ 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 cifs_wake_up_task (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,
fs/smb/client/cifstransport.c +0 -1
@@ -60,7 +60,6 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)* default callback just wakes up the current task. */ get_task_struct (current); - smb->creator = current; smb->callback = cifs_wake_up_task; smb->callback_data = current;
fs/smb/client/connect.c +4 -4
@@ -334,7 +334,7 @@ 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); - smb->callback (smb); + smb->callback (server, smb);smb_put_message (smb); }
@@ -917,7 +917,7 @@ 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 ; - smb->callback (smb); + smb->callback (server, smb);smb_put_message (smb); }
@@ -1111,7 +1111,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)list_for_each_entry_safe (smb, smb2, &dispose_list, qhead) {cifs_dbg (FYI ,"Callback mid %llu\n" , smb->mid);list_del_init (&smb->qhead); - smb->callback (smb); + smb->callback (server, smb);smb_put_message (smb); }/* 1/8th of sec is more than enough time for them to exit */
@@ -1388,7 +1388,7 @@ cifs_demultiplex_thread(void *p) }if (!smbs[i]->multiRsp || smbs[i]->multiEnd) - smbs[i]->callback (smbs[i]); + smbs[i]->callback (server, smbs[i]);smb_put_message (smbs[i]); } else if (server->ops->is_oplock_break &&
fs/smb/client/smb2ops.c +3 -3
@@ -4527,7 +4527,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,unsigned int cur_off;unsigned int cur_page_idx;unsigned int pad_len; -struct cifs_io_subrequest *rdata = smb->callback_data; +struct cifs_io_subrequest *rdata = smb->subreq;struct smb2_hdr *shdr = (struct smb2_hdr *)buf;int length;bool use_rdma_mr = false;
@@ -4707,7 +4707,7 @@ static void smb2_decrypt_offload(struct work_struct *work) dw->server->ops->is_network_name_deleted (dw->buf, dw->server); - smb->callback (smb); + smb->callback (dw->server, smb); }else {spin_lock (&dw->server->srv_lock);if (dw->server->tcpStatus == CifsNeedReconnect) {
@@ -4715,7 +4715,7 @@ static void smb2_decrypt_offload(struct work_struct *work) smb->mid_state =MID_RETRY_NEEDED ;spin_unlock (&dw->server->mid_lock);spin_unlock (&dw->server->srv_lock); - smb->callback (smb); + smb->callback (dw->server, smb); }else {spin_lock (&dw->server->mid_lock); smb->mid_state =MID_REQUEST_SUBMITTED ;
fs/smb/client/smb2pdu.c +7 -11
@@ -4094,9 +4094,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 };
@@ -4298,7 +4297,6 @@ SMB2_echo(struct TCP_Server_Info *server) smb->request = req; smb->total_len = total_len; smb->callback = smb2_echo_callback; - smb->callback_data = server; req->hdr.CreditRequest =cpu_to_le16 (1 );
@@ -4533,12 +4531,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 cifs_io_subrequest *rdata = smb->subreq;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 ,
@@ -4720,7 +4717,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) smb->receive = cifs_readv_receive; smb->handle = smb3_handle_read_data; smb->callback = smb2_readv_callback; - smb->callback_data = rdata; + smb->subreq = rdata; shdr = (struct smb2_hdr *)smb->request;
@@ -4847,11 +4844,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_io_subrequest *wdata = smb->subreq;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 ,
@@ -5016,7 +5012,7 @@ smb2_async_writev(struct cifs_io_subrequest *wdata) smb->request = req; smb->total_len = total_len; smb->callback = smb2_writev_callback; - smb->callback_data = wdata; + smb->subreq = wdata;if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ;
fs/smb/client/smb2transport.c +0 -6
@@ -759,12 +759,6 @@ static void smb2_init_mid(struct smb_message *smb, smb->credits_consumed = credits >0 ? credits :1 ; smb->server = server; -/* -* The default is for the mid to be synchronous, so the -* default callback just wakes up the current task. -*/ - smb->creator =get_task_struct (current); -atomic_inc (&mid_count); trace_smb3_cmd_enter(le32_to_cpu(shdr->Id.SyncId.TreeId), le64_to_cpu(shdr->SessionId),
fs/smb/client/transport.c +13 -14
@@ -49,8 +49,9 @@ struct smb_message *smb_message_alloc(enum smb2_command cmd, gfp_t gfp)* callback just wakes up the current task. */ smb->callback = cifs_wake_up_task; - smb->callback_data = current; smb->mid_state =MID_REQUEST_ALLOCATED ; + +init_waitqueue_head (&smb->waitq); }return smb; }
@@ -84,11 +85,11 @@ void smb_put_messages(struct smb_message *smb) }void -cifs_wake_up_task (struct smb_message *smb) +cifs_wake_up_task (struct TCP_Server_Info *server,struct smb_message *smb) {if (smb->mid_state ==MID_RESPONSE_RECEIVED ) smb->mid_state =MID_RESPONSE_READY ; -wake_up_process (smb->callback_data); +wake_up_all (&smb->waitq); }static void smb_clear_mid (struct smb_message *smb,struct TCP_Server_Info *server)
@@ -163,7 +164,6 @@ static void smb_clear_mid(struct smb_message *smb, struct TCP_Server_Info *serve } }#endif -put_task_struct (smb->creator); }static bool discard_message (struct TCP_Server_Info *server,struct smb_message *smb)
@@ -817,7 +817,7 @@ int wait_for_response(struct TCP_Server_Info *server, struct smb_message *smb)if (smb->sr_flags &CIFS_INTERRUPTIBLE_WAIT ) sleep_state =TASK_INTERRUPTIBLE ; - error =wait_event_state (server->response_q, + error =wait_event_state (smb->waitq, smb->mid_state !=MID_REQUEST_SUBMITTED && smb->mid_state !=MID_RESPONSE_RECEIVED , (sleep_state |TASK_FREEZABLE_UNSAFE ));
@@ -948,9 +948,8 @@ int cifs_sync_mid_result(struct smb_message *smb, struct TCP_Server_Info *server }static void -cifs_compound_callback (struct smb_message *smb) +cifs_compound_callback (struct TCP_Server_Info *server,struct smb_message *smb) { -struct TCP_Server_Info *server = smb->server;struct cifs_credits credits = { .value = server->ops->get_credits (smb), .instance = server->reconnect_instance,
@@ -963,16 +962,16 @@ cifs_compound_callback(struct smb_message *smb) }static void -cifs_compound_last_callback (struct smb_message *smb) +cifs_compound_last_callback (struct TCP_Server_Info *server,struct smb_message *smb) { -cifs_compound_callback (smb); -cifs_wake_up_task (smb); +cifs_compound_callback (server, smb); +cifs_wake_up_task (server, smb); }static void -cifs_cancelled_callback (struct smb_message *smb) +cifs_cancelled_callback (struct TCP_Server_Info *server,struct smb_message *smb) { -cifs_compound_callback (smb); +cifs_compound_callback (server, smb); }/*
@@ -1352,7 +1351,7 @@ __cifs_readv_discard(struct TCP_Server_Info *server, struct smb_message *smb,static int cifs_readv_discard (struct TCP_Server_Info *server,struct smb_message *smb) { -struct cifs_io_subrequest *rdata = smb->callback_data; +struct cifs_io_subrequest *rdata = smb->subreq;return __cifs_readv_discard (server, smb, rdata->result); }
@@ -1362,7 +1361,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct smb_message *smb) {int length, len;unsigned int data_offset, data_len; -struct cifs_io_subrequest *rdata = smb->callback_data; +struct cifs_io_subrequest *rdata = smb->subreq;char *buf = server->smallbuf;unsigned int buflen = server->pdu_size +HEADER_PREAMBLE_SIZE (server);bool use_rdma_mr = false;
David Howells
maintainerRFC PATCH 20/31 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 | 46 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 27 deletions(-)
fs/smb/client/smb2transport.c +19 -27
@@ -769,43 +769,35 @@ static int smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, 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 ; +case CifsNeedNegotiate: +if (smb->command_id !=SMB2_NEGOTIATE ) +return -EAGAIN ; +break ; +default : +break ; } -if (server->tcpStatus == CifsNeedNegotiate && - smb->command_id !=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 ) { +switch (READ_ONCE (ses->ses_status)) { +case SES_NEW :if (smb->command_id !=SMB2_SESSION_SETUP && - smb->command_id !=SMB2_NEGOTIATE ) { -spin_unlock (&ses->ses_lock); + smb->command_id !=SMB2_NEGOTIATE )return -EAGAIN ; - } -/* else ok - we are setting up session */ - } - -if (ses->ses_status ==SES_EXITING ) { -if (smb->command_id !=SMB2_LOGOFF ) { -spin_unlock (&ses->ses_lock); +/* else ok - we are setting up session */ +break ; +case SES_EXITING : +if (smb->command_id !=SMB2_LOGOFF )return -EAGAIN ; - }/* else ok - we are shutting down the session */ +break ; +default : +break ; } -spin_unlock (&ses->ses_lock);smb2_init_mid (smb, server);
David Howells
maintainerRFC PATCH 21/31 cifs: [DEBUG] smb_message refcounting
In reply to David Howells--- fs/smb/client/cifsglob.h | 1 + fs/smb/client/cifsproto.h | 5 +-- fs/smb/client/connect.c | 14 +++++--- fs/smb/client/smb2ops.c | 3 +- fs/smb/client/smb2pdu.c | 6 ++-- fs/smb/client/smb2transport.c | 2 +- fs/smb/client/trace.h | 61 +++++++++++++++++++++++++++++++++++ fs/smb/client/transport.c | 57 ++++++++++++++++++++++++++------ 8 files changed, 127 insertions(+), 22 deletions(-)
fs/smb/client/cifsglob.h +1 -0
@@ -1734,6 +1734,7 @@ struct smb_message {void *request;/* Pointer to request message body */ wait_queue_head_t waitq;/* Wait queue for message events */ refcount_t ref; +unsigned int debug_id;/* Debugging ID for tracing */ bool sensitive;/* Request contains sensitive data */ bool cancelled;/* T if cancelled */ unsigned int sr_flags;/* Flags passed to send_recv() */
fs/smb/client/cifsproto.h +3 -2
@@ -761,8 +761,9 @@ static inline void cifs_free_open_info(struct cifs_open_info_data *data) }struct smb_message *smb_message_alloc (enum smb2_command cmd,gfp_t gfp); -void smb_get_message (struct smb_message *smb); -void smb_put_message (struct smb_message *smb); +void smb_see_message (struct smb_message *smb,enum smb_message_trace trace); +void smb_get_message (struct smb_message *smb,enum smb_message_trace trace); +void smb_put_message (struct smb_message *smb,enum smb_message_trace trace);void smb_put_messages (struct smb_message *smb);#endif /* _CIFSPROTO_H */
fs/smb/client/connect.c +9 -5
@@ -323,6 +323,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: moving mids to private list\n" , __func__);spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { +smb_see_message (smb, smb_message_trace_see_abort_conn);if (smb->mid_state ==MID_REQUEST_SUBMITTED ) smb->mid_state =MID_RETRY_NEEDED ;list_move (&smb->qhead, &retry_list);
@@ -335,7 +336,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)list_for_each_entry_safe (smb, nsmb, &retry_list, qhead) {list_del_init (&smb->qhead); smb->callback (server, smb); -smb_put_message (smb); +smb_put_message (smb, smb_message_trace_put_abort_conn); }if (cifs_rdma_enabled (server)) {
@@ -885,6 +886,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)*/ spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { +smb_see_message (smb, smb_message_trace_see_is_smb_resp);list_move (&smb->qhead, &dispose_list); smb->mid_flags |=MID_DELETED ; }
@@ -918,7 +920,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) smb->mid_rc = mid_rc; smb->mid_state =MID_RC ; smb->callback (server, smb); -smb_put_message (smb); +smb_put_message (smb, smb_message_trace_put_is_smb_resp); }/*
@@ -968,6 +970,7 @@ dequeue_mid(struct smb_message *smb, bool malformed)spin_unlock (&smb->server->mid_lock);pr_warn_once ("trying to dequeue a deleted mid\n" ); }else { +smb_see_message (smb, smb_message_trace_see_dequeue_mid);list_del_init (&smb->qhead); smb->mid_flags |=MID_DELETED ;spin_unlock (&smb->server->mid_lock);
@@ -1101,6 +1104,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)spin_lock (&server->mid_lock);list_for_each_entry_safe (smb, smb2, &server->pending_mid_q, qhead) {cifs_dbg (FYI ,"Clearing mid %llu\n" , smb->mid); +smb_see_message (smb, smb_message_trace_see_clean_demux); smb->mid_state =MID_SHUTDOWN ;list_move (&smb->qhead, &dispose_list); smb->mid_flags |=MID_DELETED ;
@@ -1112,7 +1116,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)cifs_dbg (FYI ,"Callback mid %llu\n" , smb->mid);list_del_init (&smb->qhead); smb->callback (server, smb); -smb_put_message (smb); +smb_put_message (smb, smb_message_trace_put_clean_demux); }/* 1/8th of sec is more than enough time for them to exit */ msleep (125 );
@@ -1355,7 +1359,7 @@ cifs_demultiplex_thread(void *p)if (length <0 ) {for (i =0 ; i < num_smbs; i++)if (smbs[i]) -smb_put_message (smbs[i]); +smb_put_message (smbs[i], smb_message_trace_put_demux);continue ; }
@@ -1390,7 +1394,7 @@ cifs_demultiplex_thread(void *p)if (!smbs[i]->multiRsp || smbs[i]->multiEnd) smbs[i]->callback (server, smbs[i]); -smb_put_message (smbs[i]); +smb_put_message (smbs[i], smb_message_trace_put_demux_cb); }else if (server->ops->is_oplock_break && server->ops->is_oplock_break (bufs[i], server)) {
fs/smb/client/smb2ops.c +2 -1
@@ -408,6 +408,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_id == command)) { +smb_see_message (smb, smb_message_trace_see_find_mid);if (dequeue) {list_del_init (&smb->qhead); smb->mid_flags |=MID_DELETED ;
@@ -4726,7 +4727,7 @@ static void smb2_decrypt_offload(struct work_struct *work)spin_unlock (&dw->server->srv_lock); } } -smb_put_message (smb); +smb_put_message (smb, smb_message_trace_put_decrypt_offload); } free_pages:
fs/smb/client/smb2pdu.c +3 -3
@@ -4305,7 +4305,7 @@ SMB2_echo(struct TCP_Server_Info *server)cifs_dbg (FYI ,"Echo request failed: %d\n" , rc);cifs_small_buf_release (req); -smb_put_message (smb); +smb_put_messages (smb);return rc; }
@@ -4753,7 +4753,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) async_readv_out:cifs_small_buf_release (buf); -smb_put_message (smb); +smb_put_messages (smb);return rc; }
@@ -5127,7 +5127,7 @@ smb2_async_writev(struct cifs_io_subrequest *wdata) async_writev_out:cifs_small_buf_release (req); -smb_put_message (smb); +smb_put_messages (smb); out:if (rc) { trace_smb3_rw_credits(wdata->rreq->debug_id,
fs/smb/client/smb2transport.c +1 -1
@@ -801,7 +801,7 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,smb2_init_mid (smb, server); -smb_get_message (smb); +smb_get_message (smb, smb_message_trace_get_enqueue_sync);spin_lock (&server->mid_lock);list_add_tail (&smb->qhead, &server->pending_mid_q);spin_unlock (&server->mid_lock);
fs/smb/client/trace.h +61 -0
85 lines not on this page · raw message
fs/smb/client/transport.c +47 -10
123 lines not on this page · raw message
David Howells
maintainerRFC PATCH 22/31 cifs: Add netmem allocation functions
In reply to David HowellsAdd (stub) functions for doing netmem allocations. We want to allocate memory from the netmem buffering as that does bulk DMA and IOMMU management.
--- fs/smb/client/cifsproto.h | 3 +++ fs/smb/client/transport.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)
fs/smb/client/cifsproto.h +3 -0
@@ -766,4 +766,7 @@ void smb_get_message(struct smb_message *smb, enum smb_message_trace trace);void smb_put_message (struct smb_message *smb,enum smb_message_trace trace);void smb_put_messages (struct smb_message *smb); +void *cifs_allocate_tx_buf (struct TCP_Server_Info *server,size_t size); +void cifs_free_tx_buf (void *p); +#endif /* _CIFSPROTO_H */
fs/smb/client/transport.c +15 -0
@@ -32,6 +32,21 @@#include "smbdirect.h" #include "compress.h" +/* +* Allocate transmission buffers for a socket. This memory will be allocated +* from the netmem buffers. It comes with a page ref that we need to drop. +* The networking layer can pin it by getting its own ref. +*/ +void *cifs_allocate_tx_buf (struct TCP_Server_Info *server,size_t size) +{ +return NULL ;/* TODO */ +} + +void cifs_free_tx_buf (void *p) +{ +/* TODO */ +} +struct smb_message *smb_message_alloc (enum smb2_command cmd,gfp_t gfp) {static atomic_t debug_ids;
David Howells
maintainerRFC PATCH 23/31 cifs: Add more pieces to smb_message
In reply to David HowellsAdd more pieces to the smb_message struct to facilitate future changes.
Also move towards not needing the server pointer in smb_message.
--- fs/smb/client/cifsglob.h | 7 ++ fs/smb/client/cifsproto.h | 15 +++ fs/smb/client/cifstransport.c | 2 +- fs/smb/client/smb2ops.c | 10 ++ fs/smb/client/smb2pdu.c | 198 ++++++++++++++++++++++++++++++++++ fs/smb/client/smb2proto.h | 1 + fs/smb/client/transport.c | 28 ++++- 7 files changed, 259 insertions(+), 2 deletions(-)
fs/smb/client/cifsglob.h +7 -0
@@ -1774,7 +1774,12 @@ struct smb_message {/* Request details */ enum smb2_command command_id;/* Command ID */ s16 pre_offset;/* Offset of pre-headers from ->body (negative) */ +u16 ext_offset;/* Offset of extensions from ->body */ +u16 latest_record;/* Offset of latest context record (or 0) */ +u16 offset;/* Running offset during assembly */ +u16 data_offset;/* Offset of data in message (maybe in ->body) */ unsigned int total_len;/* Total length of from hdr_offset onwards */ +struct iov_iter iter;/* Data iterator */ /* Response */ void *response;/* Protocol part of response */ u32 response_len;/* Size of response */
@@ -1782,6 +1787,8 @@ struct smb_message {struct smb_rqst rqst;int *resp_buf_type;struct kvec *resp_iov; +/* Variable-length request fragment list - must be last! */ +struct bvecq bvecq;/* List of request frags (passed to socket) */ };struct close_cancelled_open {
fs/smb/client/cifsproto.h +15 -0
@@ -765,8 +765,23 @@ void smb_see_message(struct smb_message *smb, enum smb_message_trace trace);void smb_get_message (struct smb_message *smb,enum smb_message_trace trace);void smb_put_message (struct smb_message *smb,enum smb_message_trace trace);void smb_put_messages (struct smb_message *smb); +void smb_clear_request (struct smb_message *smb);void *cifs_allocate_tx_buf (struct TCP_Server_Info *server,size_t size);void cifs_free_tx_buf (void *p); +/* +* Add a segment to a message. This should be allocated with +* cifs_allocate_tx_buf() so that it can be used with MSG_SPLICE_PAGES. +*/ +static inline void smb_add_segment_to_tx_buf (struct smb_message *smb, +void *key_buf,size_t size) +{ +unsigned int nr = smb->bvecq.nr_segs; + +bvec_set_virt (&smb->bvecq.bv[nr], key_buf, size); + smb->bvecq.nr_segs = nr++; + smb->total_len += size; +} +#endif /* _CIFSPROTO_H */
fs/smb/client/cifstransport.c +1 -1
@@ -177,7 +177,7 @@ 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); }int
fs/smb/client/smb2ops.c +10 -0
@@ -2602,6 +2602,16 @@ smb2_set_replay(struct TCP_Server_Info *server, struct smb_rqst *rqst) shdr->Flags |=SMB2_FLAGS_REPLAY_OPERATION ; } +void smb2_set_replay_smb (struct TCP_Server_Info *server,struct smb_message *smb) +{ +struct smb2_hdr *shdr = smb->request; + +if (server->dialect <SMB30_PROT_ID ) +return ; + + shdr->Flags |=SMB2_FLAGS_REPLAY_OPERATION ; +} +void smb2_set_related (struct smb_rqst *rqst) {
fs/smb/client/smb2pdu.c +198 -0
204 lines not on this page · raw message
fs/smb/client/smb2proto.h +1 -0
@@ -131,6 +131,7 @@ extern void smb2_set_next_command(struct cifs_tcon *tcon,extern void smb2_set_related (struct smb_rqst *rqst);extern void smb2_set_replay (struct TCP_Server_Info *server,struct smb_rqst *rqst); +void smb2_set_replay_smb (struct TCP_Server_Info *server,struct smb_message *smb);extern bool smb2_should_replay (struct cifs_tcon *tcon,int *pretries,int *pcur_sleep);
fs/smb/client/transport.c +27 -1
@@ -93,9 +93,31 @@ static void smb_free_message(struct smb_message *smb) {trace_smb3_message (smb->debug_id,refcount_read (&smb->ref), smb_message_trace_free); +cifs_free_tx_buf (smb->request);mempool_free (smb, &smb_message_pool); } +/* +* Clear the request parts of a message. +*/ +void smb_clear_request (struct smb_message *smb) +{ +for (; smb; smb = smb->next) { +if (smb->request) { +if (smb->sensitive) { +iov_iter_bvec_queue (&smb->iter,ITER_SOURCE , + &smb->bvecq,3 , + -smb->pre_offset, + smb->ext_offset - -smb->pre_offset); +iov_iter_zero (smb->ext_offset - -smb->pre_offset, + &smb->iter); + } +cifs_free_tx_buf (smb->request); + smb->request =NULL ; + } + } +} +/* * Drop a ref on a message. This does not touch the chained messages. */
@@ -120,6 +142,8 @@ void smb_put_messages(struct smb_message *smb) {struct smb_message *next; +smb_clear_request (smb); +for (; smb; smb = next) {unsigned int debug_id = smb->debug_id;bool dead;
@@ -1099,9 +1123,11 @@ int smb_send_recv_messages(const unsigned int xid, struct cifs_ses *ses, optype = flags &CIFS_OP_MASK ;/* TODO: Stitch together the messages in a compound. */ +//u32 last_next = 0; nr_reqs =0 ; -for (struct smb_message *smb = head_smb; smb; smb = smb->next) +for (struct smb_message *smb = head_smb; smb; smb = smb->next) { nr_reqs++; + }spin_lock (&server->srv_lock);if (server->tcpStatus == CifsExiting) {
David Howells
maintainerRFC PATCH 24/31 cifs: Convert SMB2 Negotiate Protocol request
In reply to David Howells--- fs/smb/client/smb2pdu.c | 509 ++++++++++++++++++++++++---------------- fs/smb/common/smb2pdu.h | 24 +- fs/smb/server/smb2pdu.c | 22 +- 3 files changed, 319 insertions(+), 236 deletions(-)
fs/smb/client/smb2pdu.c +302 -207
@@ -788,144 +788,200 @@ static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon,/* For explanation of negotiate contexts see MS-SMB2 section 2.2.3.1 */ -static void -build_preauth_ctxt (struct smb2_preauth_neg_context *pneg_ctxt) +static void *cifs_begin_neg_context (struct smb_message *smb, +__le16 context_type) { - pneg_ctxt->ContextType =SMB2_PREAUTH_INTEGRITY_CAPABILITIES ; - pneg_ctxt->DataLength =cpu_to_le16 (38 ); - pneg_ctxt->HashAlgorithmCount =cpu_to_le16 (1 ); - pneg_ctxt->SaltLength =cpu_to_le16 (SMB311_SALT_SIZE ); -get_random_bytes (pneg_ctxt->Salt,SMB311_SALT_SIZE ); - pneg_ctxt->HashAlgorithms =SMB2_PREAUTH_INTEGRITY_SHA512 ; +struct smb2_neg_context *neg; + + neg =cifs_begin_extension (smb); + neg->ContextType = context_type; + neg->Reserved =0 ; +return (void *)neg; } -static void -build_compression_ctxt (struct smb2_compression_capabilities_context *pneg_ctxt) +static void cifs_end_neg_context (struct smb_message *smb,void *p,size_t size) +{ +struct smb2_neg_context *neg = p; + + neg->DataLength =cpu_to_le16 (size -sizeof (*neg)); +cifs_end_extension (smb, size); +} + +static void build_preauth_ctxt (struct smb_message *smb) { - pneg_ctxt->ContextType =SMB2_COMPRESSION_CAPABILITIES ; - pneg_ctxt->DataLength = -cpu_to_le16 (sizeof (struct smb2_compression_capabilities_context ) - -sizeof (struct smb2_neg_context )); - pneg_ctxt->CompressionAlgorithmCount =cpu_to_le16 (3 ); - pneg_ctxt->CompressionAlgorithms[0 ] =SMB3_COMPRESS_LZ77 ; - pneg_ctxt->CompressionAlgorithms[1 ] =SMB3_COMPRESS_LZ77_HUFF ; - pneg_ctxt->CompressionAlgorithms[2 ] =SMB3_COMPRESS_LZNT1 ; +struct smb2_preauth_neg_context *preauth; + + preauth =cifs_begin_neg_context (smb,SMB2_PREAUTH_INTEGRITY_CAPABILITIES ); + preauth->HashAlgorithmCount =cpu_to_le16 (1 ); + preauth->SaltLength =cpu_to_le16 (SMB311_SALT_SIZE ); + preauth->HashAlgorithms =SMB2_PREAUTH_INTEGRITY_SHA512 ; +get_random_bytes (preauth->Salt,SMB311_SALT_SIZE ); +cifs_end_neg_context (smb, preauth,sizeof (*preauth)); } -static unsigned int -build_signing_ctxt (struct smb2_signing_capabilities *pneg_ctxt) +static void build_compression_ctxt (struct smb_message *smb) +{ +struct smb2_compression_capabilities_context *compr; + + compr =cifs_begin_neg_context (smb,SMB2_COMPRESSION_CAPABILITIES ); + compr->CompressionAlgorithmCount =cpu_to_le16 (3 ); + compr->CompressionAlgorithms[0 ] =SMB3_COMPRESS_LZ77 ; + compr->CompressionAlgorithms[1 ] =SMB3_COMPRESS_LZ77_HUFF ; + compr->CompressionAlgorithms[2 ] =SMB3_COMPRESS_LZNT1 ; +cifs_end_neg_context (smb, compr,sizeof (*compr)); +} + +static size_t smb2_size_signing_ctxt (void ) +{ +size_t ctxt_len =sizeof (struct smb2_signing_capabilities ); +unsigned short num_algs =1 ;/* number of signing algorithms sent */ + + ctxt_len +=sizeof (__le16) * num_algs; +return ALIGN8 (ctxt_len); +} + +static void build_signing_ctxt (struct smb_message *smb) { -unsigned int ctxt_len =sizeof (struct smb2_signing_capabilities ); +struct smb2_signing_capabilities *scap;unsigned short num_algs =1 ;/* number of signing algorithms sent */ - pneg_ctxt->ContextType =SMB2_SIGNING_CAPABILITIES ; + scap =cifs_begin_neg_context (smb,SMB2_SIGNING_CAPABILITIES ); + scap->SigningAlgorithmCount =cpu_to_le16 (num_algs); + scap->SigningAlgorithms[0 ] =cpu_to_le16 (SIGNING_ALG_AES_CMAC ); +/* TBD add SIGNING_ALG_AES_GMAC and/or SIGNING_ALG_HMAC_SHA256 */ +/* * Context Data length must be rounded to multiple of 8 for some servers */ - pneg_ctxt->DataLength =cpu_to_le16 (ALIGN8 (sizeof (struct smb2_signing_capabilities ) - -sizeof (struct smb2_neg_context ) + - (num_algs *sizeof (u16)))); - pneg_ctxt->SigningAlgorithmCount =cpu_to_le16 (num_algs); - pneg_ctxt->SigningAlgorithms[0 ] =cpu_to_le16 (SIGNING_ALG_AES_CMAC ); - - ctxt_len +=sizeof (__le16) * num_algs; - ctxt_len =ALIGN8 (ctxt_len); -return ctxt_len; -/* TBD add SIGNING_ALG_AES_GMAC and/or SIGNING_ALG_HMAC_SHA256 */ +cifs_end_neg_context (smb, scap, +ALIGN8 (struct_size (scap, SigningAlgorithms, num_algs))); } -static void -build_encrypt_ctxt (struct smb2_encryption_neg_context *pneg_ctxt) +static void build_encrypt_ctxt (struct smb_message *smb) { - pneg_ctxt->ContextType =SMB2_ENCRYPTION_CAPABILITIES ; -if (require_gcm_256) { - pneg_ctxt->DataLength =cpu_to_le16 (4 );/* Cipher Count + 1 cipher */ - pneg_ctxt->CipherCount =cpu_to_le16 (1 ); - pneg_ctxt->Ciphers[0 ] =SMB2_ENCRYPTION_AES256_GCM ; - }else if (enable_gcm_256) { - pneg_ctxt->DataLength =cpu_to_le16 (8 );/* Cipher Count + 3 ciphers */ - pneg_ctxt->CipherCount =cpu_to_le16 (3 ); - pneg_ctxt->Ciphers[0 ] =SMB2_ENCRYPTION_AES128_GCM ; - pneg_ctxt->Ciphers[1 ] =SMB2_ENCRYPTION_AES256_GCM ; - pneg_ctxt->Ciphers[2 ] =SMB2_ENCRYPTION_AES128_CCM ; +struct smb2_encryption_neg_context *ecap; +size_t count; + + ecap =cifs_begin_neg_context (smb,SMB2_ENCRYPTION_CAPABILITIES ); + +if (READ_ONCE (require_gcm_256)) { + ecap->Ciphers[0 ] =SMB2_ENCRYPTION_AES256_GCM ; + count =1 ; + }else if (READ_ONCE (enable_gcm_256)) { + ecap->Ciphers[0 ] =SMB2_ENCRYPTION_AES128_GCM ; + ecap->Ciphers[1 ] =SMB2_ENCRYPTION_AES256_GCM ; + ecap->Ciphers[2 ] =SMB2_ENCRYPTION_AES128_CCM ; + count =3 ; }else { - pneg_ctxt->DataLength =cpu_to_le16 (6 );/* Cipher Count + 2 ciphers */ - pneg_ctxt->CipherCount =cpu_to_le16 (2 ); - pneg_ctxt->Ciphers[0 ] =SMB2_ENCRYPTION_AES128_GCM ; - pneg_ctxt->Ciphers[1 ] =SMB2_ENCRYPTION_AES128_CCM ; + ecap->Ciphers[0 ] =SMB2_ENCRYPTION_AES128_GCM ; + ecap->Ciphers[1 ] =SMB2_ENCRYPTION_AES128_CCM ; + count =2 ; } + ecap->CipherCount =cpu_to_le16 (count); +cifs_end_neg_context (smb, ecap,struct_size (ecap, Ciphers, count)); } -static unsigned int -build_netname_ctxt (struct smb2_netname_neg_context *pneg_ctxt,char *hostname) +static size_t smb2_size_netname_ctxt (struct TCP_Server_Info *server) { +size_t data_len; + +#if 0 struct nls_table *cp =load_nls_default (); +const char *hostname; - pneg_ctxt->ContextType =SMB2_NETNAME_NEGOTIATE_CONTEXT_ID ; +/* Only include up to first 100 bytes of server name in the NetName +* field. +*/ +cifs_server_lock (pserver); + hostname = pserver->hostname; +if (hostname && hostname[0 ]) + data_len =cifs_size_strtoUTF16 (hostname,100 , cp); +cifs_server_unlock (pserver); +#else +/* Now, we can't just measure the length of hostname as, unless we hold +* the lock, it may change under us, so allow maximum space for it. +*/ + data_len =400 ; +#endif +return ALIGN8 (sizeof (struct smb2_neg_context ) + data_len); +} + +static void build_netname_ctxt (struct smb_message *smb,const char *hostname) +{ +struct smb2_netname_neg_context *name; +struct nls_table *cp =load_nls_default (); +size_t count; + + name =cifs_begin_neg_context (smb,SMB2_NETNAME_NEGOTIATE_CONTEXT_ID );/* copy up to max of first 100 bytes of server name to NetName field */ - pneg_ctxt->DataLength =cpu_to_le16 (2 *cifs_strtoUTF16 (pneg_ctxt->NetName, hostname,100 , cp)); -/* context size is DataLength + minimal smb2_neg_context */ -return ALIGN8 (le16_to_cpu (pneg_ctxt->DataLength) +sizeof (struct smb2_neg_context )); + count =cifs_strtoUTF16 (name->NetName, hostname,100 , cp); +cifs_end_neg_context (smb, name,struct_size (name, NetName, count)); } -static void -build_posix_ctxt (struct smb2_posix_neg_context *pneg_ctxt) +static void build_posix_ctxt (struct smb_message *smb) { - pneg_ctxt->ContextType =SMB2_POSIX_EXTENSIONS_AVAILABLE ; - pneg_ctxt->DataLength =cpu_to_le16 (POSIX_CTXT_DATA_LEN ); +struct smb2_posix_neg_context *posix; + + posix =cifs_begin_neg_context (smb,SMB2_POSIX_EXTENSIONS_AVAILABLE );/* SMB2_CREATE_TAG_POSIX is "0x93AD25509CB411E7B42383DE968BCD7C" */ - pneg_ctxt->Name[0 ] =0x93 ; - pneg_ctxt->Name[1 ] =0xAD ; - pneg_ctxt->Name[2 ] =0x25 ; - pneg_ctxt->Name[3 ] =0x50 ; - pneg_ctxt->Name[4 ] =0x9C ; - pneg_ctxt->Name[5 ] =0xB4 ; - pneg_ctxt->Name[6 ] =0x11 ; - pneg_ctxt->Name[7 ] =0xE7 ; - pneg_ctxt->Name[8 ] =0xB4 ; - pneg_ctxt->Name[9 ] =0x23 ; - pneg_ctxt->Name[10 ] =0x83 ; - pneg_ctxt->Name[11 ] =0xDE ; - pneg_ctxt->Name[12 ] =0x96 ; - pneg_ctxt->Name[13 ] =0x8B ; - pneg_ctxt->Name[14 ] =0xCD ; - pneg_ctxt->Name[15 ] =0x7C ; + posix->Name[0 ] =0x93 ; + posix->Name[1 ] =0xAD ; + posix->Name[2 ] =0x25 ; + posix->Name[3 ] =0x50 ; + posix->Name[4 ] =0x9C ; + posix->Name[5 ] =0xB4 ; + posix->Name[6 ] =0x11 ; + posix->Name[7 ] =0xE7 ; + posix->Name[8 ] =0xB4 ; + posix->Name[9 ] =0x23 ; + posix->Name[10 ] =0x83 ; + posix->Name[11 ] =0xDE ; + posix->Name[12 ] =0x96 ; + posix->Name[13 ] =0x8B ; + posix->Name[14 ] =0xCD ; + posix->Name[15 ] =0x7C ; +cifs_end_neg_context (smb, posix,sizeof (posix)); } -static void -assemble_neg_contexts (struct smb2_negotiate_req *req, -struct TCP_Server_Info *server,unsigned int *total_len) +static size_t smb2_size_neg_contexts (struct TCP_Server_Info *server, +size_t offset) { -unsigned int ctxt_len, neg_context_count;struct TCP_Server_Info *pserver; -char *pneg_ctxt; -char *hostname; - -if (*total_len >200 ) { -/* In case length corrupted don't want to overrun smb buffer */ -cifs_server_dbg (VFS ,"Bad frame length assembling neg contexts\n" ); -return ; - }/* * round up total_len of fixed part of SMB3 negotiate request to 8 * byte boundary before adding negotiate contexts */ - *total_len =ALIGN8 (*total_len); + offset =ALIGN8 (offset); + offset +=ALIGN8 (sizeof (struct smb2_preauth_neg_context )); + offset +=ALIGN8 (sizeof (struct smb2_encryption_neg_context )); - pneg_ctxt = (*total_len) + (char *)req; - req->NegotiateContextOffset =cpu_to_le32 (*total_len); +/* +* secondary channels don't have the hostname field populated +* use the hostname field in the primary channel instead +*/ + pserver =SERVER_IS_CHAN (server) ? server->primary_server : server; + offset +=smb2_size_netname_ctxt (pserver); + + offset +=ALIGN8 (sizeof (struct smb2_posix_neg_context )); +if (server->compression.requested) + offset +=ALIGN8 (sizeof (struct smb2_compression_capabilities_context )); +if (enable_negotiate_signing) + offset +=smb2_size_signing_ctxt (); +return offset; +} -build_preauth_ctxt ((struct smb2_preauth_neg_context *)pneg_ctxt); - ctxt_len =ALIGN8 (sizeof (struct smb2_preauth_neg_context )); - *total_len += ctxt_len; - pneg_ctxt += ctxt_len; +static void +assemble_neg_contexts (struct smb_message *smb,struct TCP_Server_Info *server) +{ +struct smb2_negotiate_req *req; +struct TCP_Server_Info *pserver; +const char *hostname; +unsigned int neg_context_count =2 ; -build_encrypt_ctxt ((struct smb2_encryption_neg_context *)pneg_ctxt); - ctxt_len =ALIGN8 (sizeof (struct smb2_encryption_neg_context )); - *total_len += ctxt_len; - pneg_ctxt += ctxt_len; +build_preauth_ctxt (smb); +build_encrypt_ctxt (smb);/* * secondary channels don't have the hostname field populated
@@ -934,47 +990,36 @@ assemble_neg_contexts(struct smb2_negotiate_req *req, pserver =SERVER_IS_CHAN (server) ? server->primary_server : server;cifs_server_lock (pserver); hostname = pserver->hostname; -if (hostname && (hostname[0 ] !=0 )) { - ctxt_len =build_netname_ctxt ((struct smb2_netname_neg_context *)pneg_ctxt, - hostname); - *total_len += ctxt_len; - pneg_ctxt += ctxt_len; - neg_context_count =3 ; - }else - neg_context_count =2 ; +if (hostname && hostname[0 ]) { +build_netname_ctxt (smb, hostname); + neg_context_count++; + }cifs_server_unlock (pserver); -build_posix_ctxt ((struct smb2_posix_neg_context *)pneg_ctxt); - *total_len +=sizeof (struct smb2_posix_neg_context ); - pneg_ctxt +=sizeof (struct smb2_posix_neg_context ); +build_posix_ctxt (smb); neg_context_count++;if (server->compression.requested) { -build_compression_ctxt ((struct smb2_compression_capabilities_context *) - pneg_ctxt); - ctxt_len =ALIGN8 (sizeof (struct smb2_compression_capabilities_context )); - *total_len += ctxt_len; - pneg_ctxt += ctxt_len; +build_compression_ctxt (smb); neg_context_count++; }if (enable_negotiate_signing) { - ctxt_len =build_signing_ctxt ((struct smb2_signing_capabilities *) - pneg_ctxt); - *total_len += ctxt_len; - pneg_ctxt += ctxt_len; +build_signing_ctxt (smb); neg_context_count++; }/* check for and add transport_capabilities and signing capabilities */ + req = smb->request; req->NegotiateContextCount =cpu_to_le16 (neg_context_count); - }/* If invalid preauth context warn but use what we requested, SHA-512 */ -static void decode_preauth_context (struct smb2_preauth_neg_context *ctxt) +static void decode_preauth_context (struct smb2_neg_context *neg) { -unsigned int len =le16_to_cpu (ctxt->DataLength); +struct smb2_preauth_neg_context *ctxt = + container_of(neg, struct smb2_preauth_neg_context, neg); +unsigned int len =le16_to_cpu (ctxt->neg.DataLength);/* * Caller checked that DataLength remains within SMB boundary. We still
@@ -994,9 +1039,11 @@ static void decode_preauth_context(struct smb2_preauth_neg_context *ctxt) }static void decode_compress_ctx (struct TCP_Server_Info *server, -struct smb2_compression_capabilities_context *ctxt) +struct smb2_neg_context *neg) { -unsigned int len =le16_to_cpu (ctxt->DataLength); +struct smb2_compression_capabilities_context *ctxt = + container_of(neg, struct smb2_compression_capabilities_context, neg); +unsigned int len =le16_to_cpu (ctxt->neg.DataLength);__le16 alg; server->compression.enabled = false;
@@ -1029,9 +1076,11 @@ static void decode_compress_ctx(struct TCP_Server_Info *server, }static int decode_encrypt_ctx (struct TCP_Server_Info *server, -struct smb2_encryption_neg_context *ctxt) +struct smb2_neg_context *neg) { -unsigned int len =le16_to_cpu (ctxt->DataLength); +struct smb2_encryption_neg_context *ctxt = + container_of(neg, struct smb2_encryption_neg_context, neg); +unsigned int len =le16_to_cpu (ctxt->neg.DataLength);cifs_dbg (FYI ,"decode SMB3.11 encryption neg context of len %d\n" , len);/*
@@ -1081,9 +1130,11 @@ static int decode_encrypt_ctx(struct TCP_Server_Info *server, }static void decode_signing_ctx (struct TCP_Server_Info *server, -struct smb2_signing_capabilities *pctxt) +struct smb2_neg_context *neg) { -unsigned int len =le16_to_cpu (pctxt->DataLength); +struct smb2_signing_capabilities *pctxt = + container_of(neg, struct smb2_signing_capabilities, neg); +unsigned int len =le16_to_cpu (pctxt->neg.DataLength);/* * Caller checked that DataLength remains within SMB boundary. We still
@@ -1110,11 +1161,12 @@ static void decode_signing_ctx(struct TCP_Server_Info *server, } -static int smb311_decode_neg_context (struct smb2_negotiate_rsp *rsp, -struct TCP_Server_Info *server, -unsigned int len_of_smb) +static int smb311_decode_neg_context (struct smb_message *smb, +struct TCP_Server_Info *server) { +struct smb2_negotiate_rsp *rsp = smb->response;struct smb2_neg_context *pctx; +unsigned int len_of_smb = smb->response_len;unsigned int offset =le32_to_cpu (rsp->NegotiateContextOffset);unsigned int ctxt_cnt =le16_to_cpu (rsp->NegotiateContextCount);unsigned int len_of_ctxts, i;
@@ -1147,23 +1199,26 @@ static int smb311_decode_neg_context(struct smb2_negotiate_rsp *rsp,if (clen > len_of_ctxts)break ; -if (pctx->ContextType ==SMB2_PREAUTH_INTEGRITY_CAPABILITIES ) -decode_preauth_context ( - (struct smb2_preauth_neg_context *)pctx); -else if (pctx->ContextType ==SMB2_ENCRYPTION_CAPABILITIES ) - rc =decode_encrypt_ctx (server, - (struct smb2_encryption_neg_context *)pctx); -else if (pctx->ContextType ==SMB2_COMPRESSION_CAPABILITIES ) -decode_compress_ctx (server, - (struct smb2_compression_capabilities_context *)pctx); -else if (pctx->ContextType ==SMB2_POSIX_EXTENSIONS_AVAILABLE ) +switch (pctx->ContextType) { +case SMB2_PREAUTH_INTEGRITY_CAPABILITIES : +decode_preauth_context (pctx); +break ; +case SMB2_ENCRYPTION_CAPABILITIES : + rc =decode_encrypt_ctx (server, pctx); +break ; +case SMB2_COMPRESSION_CAPABILITIES : +decode_compress_ctx (server, pctx); +break ; +case SMB2_POSIX_EXTENSIONS_AVAILABLE : server->posix_ext_supported = true; -else if (pctx->ContextType ==SMB2_SIGNING_CAPABILITIES ) -decode_signing_ctx (server, - (struct smb2_signing_capabilities *)pctx); -else +break ; +case SMB2_SIGNING_CAPABILITIES : +decode_signing_ctx (server, pctx); +break ; +default :cifs_server_dbg (VFS ,"unknown negcontext of type %d ignored\n" ,le16_to_cpu (pctx->ContextType)); + }if (rc)break ;
@@ -1248,17 +1303,16 @@ SMB2_negotiate(const unsigned int xid,struct cifs_ses *ses, struct TCP_Server_Info *server) { - struct smb_rqst rqst; struct smb2_negotiate_req *req;struct smb2_negotiate_rsp *rsp; -struct kvec iov[1 ]; -struct kvec rsp_iov; +struct smb_message *smb; +const char *vs; +size_t offset, num_dialects;int rc; -int resp_buftype;int blob_offset, blob_length;char *security_blob;int flags =CIFS_NEG_OP ; -unsigned int total_len; +enum {DEF ,ANY3 ,SPEC } version;cifs_dbg (FYI ,"Negotiate protocol\n" );
@@ -1267,36 +1321,67 @@ SMB2_negotiate(const unsigned int xid,return -EIO ; } - rc =smb2_plain_req_init (SMB2_NEGOTIATE ,NULL , server, - (void **) &req, &total_len); + rc =smb2_reconnect (SMB2_SESSION_SETUP ,NULL , server, false);if (rc)return rc; +/* Calculate how much space we need for a Negotiate Request message. +* We can't do this exactly as the hostname might change, but we don't +* want to hold the lock across the allocation. +*/ + vs = server->vals->version_string; +if (strcmp (vs,SMB3ANY_VERSION_STRING ) ==0 ) { + version =ANY3 ; + num_dialects =3 ; + }else if (strcmp (vs,SMBDEFAULT_VERSION_STRING ) ==0 ) { + version =DEF ; + num_dialects =4 ; + }else { + version =SPEC ; + num_dialects =1 ; + } + + offset =sizeof (struct smb2_negotiate_req ); + offset +=sizeof (req->Dialects[0 ]) * num_dialects; + +if ((server->vals->protocol_id ==SMB311_PROT_ID ) || + (version ==ANY3 ) || + (version ==DEF )) + offset =smb2_size_neg_contexts (server, offset); + + smb =smb2_create_request (SMB2_NEGOTIATE , server,NULL , +sizeof (*req), offset,0 , +SMB2_REQ_HEAD ); +if (!smb) +return -ENOMEM ; + +/* Fill in the message. */ + req = smb->request; req->hdr.SessionId =0 ; + req->NegotiateContextOffset =cpu_to_be32 (smb->ext_offset);memset (server->preauth_sha_hash,0 ,SMB2_PREAUTH_HASH_SIZE );memset (ses->preauth_sha_hash,0 ,SMB2_PREAUTH_HASH_SIZE ); -if (strcmp (server->vals->version_string, -SMB3ANY_VERSION_STRING ) ==0 ) { +switch (version) { +case ANY3 : req->Dialects[0 ] =cpu_to_le16 (SMB30_PROT_ID ); req->Dialects[1 ] =cpu_to_le16 (SMB302_PROT_ID ); req->Dialects[2 ] =cpu_to_le16 (SMB311_PROT_ID ); req->DialectCount =cpu_to_le16 (3 ); - total_len +=6 ; - }else if (strcmp (server->vals->version_string, -SMBDEFAULT_VERSION_STRING ) ==0 ) { +break ; +case DEF : req->Dialects[0 ] =cpu_to_le16 (SMB21_PROT_ID ); req->Dialects[1 ] =cpu_to_le16 (SMB30_PROT_ID ); req->Dialects[2 ] =cpu_to_le16 (SMB302_PROT_ID ); req->Dialects[3 ] =cpu_to_le16 (SMB311_PROT_ID ); req->DialectCount =cpu_to_le16 (4 ); - total_len +=8 ; - }else { +break ; +case SPEC :/* otherwise send specific dialect */ req->Dialects[0 ] =cpu_to_le16 (server->vals->protocol_id); req->DialectCount =cpu_to_le16 (1 ); - total_len +=2 ; +break ; }/* only one of SMB2 signing flags may be set in SMB2 request */
@@ -1312,97 +1397,108 @@ SMB2_negotiate(const unsigned int xid, req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );/* ClientGUID must be zero for SMB2.02 dialect */ -if (server->vals->protocol_id ==SMB20_PROT_ID ) +if (server->vals->protocol_id ==SMB20_PROT_ID ) {memset (req->ClientGUID,0 ,SMB2_CLIENT_GUID_SIZE ); -else { + }else {memcpy (req->ClientGUID, server->client_guid,SMB2_CLIENT_GUID_SIZE );if ((server->vals->protocol_id ==SMB311_PROT_ID ) || - (strcmp (server->vals->version_string, -SMB3ANY_VERSION_STRING ) ==0 ) || - (strcmp (server->vals->version_string, -SMBDEFAULT_VERSION_STRING ) ==0 )) -assemble_neg_contexts (req, server, &total_len); + (version ==ANY3 ) || + (version ==DEF )) +assemble_neg_contexts (smb, server); } - iov[0 ].iov_base = (char *)req; - iov[0 ].iov_len = total_len; -memset (&rqst,0 ,sizeof (struct smb_rqst )); - rqst.rq_iov = iov; - rqst.rq_nvec =1 ; + rc =smb_send_recv_messages (xid, ses, server, smb, flags); +smb_clear_request (smb); - rc =cifs_send_recv (xid, ses, server, - &rqst, &resp_buftype, flags, &rsp_iov); -cifs_small_buf_release (req); - rsp = (struct smb2_negotiate_rsp *)rsp_iov.iov_base;/* * No tcon so can't do * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); */ -if (rc == -EOPNOTSUPP ) { -cifs_server_dbg (VFS ,"Dialect not supported by server. Consider specifying vers=1.0 or vers=2.0 on mount for accessing older servers\n" ); - goto neg_exit; - }else if (rc !=0 ) +if (rc !=0 ) { +if (rc == -EOPNOTSUPP ) +cifs_server_dbg (VFS ,"Dialect not supported by server. Consider specifying vers=1.0 or vers=2.0 on mount for accessing older servers\n" ); goto neg_exit; + } +/* ________________________________________ +* Decode the response. +*/ + rsp = (struct smb2_negotiate_rsp *)smb->response; + +int dialect_revision =le16_to_cpu (rsp->DialectRevision); rc = -EIO ; -if (strcmp (server->vals->version_string, -SMB3ANY_VERSION_STRING ) ==0 ) { -if (rsp->DialectRevision ==cpu_to_le16 (SMB20_PROT_ID )) { +switch (version) { +case ANY3 : +switch (dialect_revision) { +case SMB20_PROT_ID :cifs_server_dbg (VFS ,"SMB2 dialect returned but not requested\n" ); goto neg_exit; - }else if (rsp->DialectRevision ==cpu_to_le16 (SMB21_PROT_ID )) { +case SMB21_PROT_ID :cifs_server_dbg (VFS ,"SMB2.1 dialect returned but not requested\n" ); goto neg_exit; - }else if (rsp->DialectRevision ==cpu_to_le16 (SMB311_PROT_ID )) { +case SMB311_PROT_ID :/* ops set to 3.0 by default for default so update */ server->ops = &smb311_operations; server->vals = &smb311_values; +break ; } - }else if (strcmp (server->vals->version_string, -SMBDEFAULT_VERSION_STRING ) ==0 ) { -if (rsp->DialectRevision ==cpu_to_le16 (SMB20_PROT_ID )) { +break ; +case DEF : +switch (dialect_revision) { +case SMB20_PROT_ID :cifs_server_dbg (VFS ,"SMB2 dialect returned but not requested\n" ); goto neg_exit; - }else if (rsp->DialectRevision ==cpu_to_le16 (SMB21_PROT_ID )) { +case SMB21_PROT_ID :/* ops set to 3.0 by default for default so update */ server->ops = &smb21_operations; server->vals = &smb21_values; - }else if (rsp->DialectRevision ==cpu_to_le16 (SMB311_PROT_ID )) { +break ; +case SMB311_PROT_ID : server->ops = &smb311_operations; server->vals = &smb311_values; +break ; } - }else if (le16_to_cpu (rsp->DialectRevision) != - server->vals->protocol_id) { -/* if requested single dialect ensure returned dialect matched */ -cifs_server_dbg (VFS ,"Invalid 0x%x dialect returned: not requested\n" , -le16_to_cpu (rsp->DialectRevision)); - goto neg_exit; +break ; +default : +if (dialect_revision != server->vals->protocol_id) { +/* if requested single dialect ensure returned dialect matched */ +cifs_server_dbg (VFS ,"Invalid 0x%x dialect returned: not requested\n" , + dialect_revision); + goto neg_exit; + } +break ; }cifs_dbg (FYI ,"mode 0x%x\n" , rsp->SecurityMode); -if (rsp->DialectRevision ==cpu_to_le16 (SMB20_PROT_ID )) +switch (dialect_revision) { +case SMB20_PROT_ID :cifs_dbg (FYI ,"negotiated smb2.0 dialect\n" ); -else if (rsp->DialectRevision ==cpu_to_le16 (SMB21_PROT_ID )) +break ; +case SMB21_PROT_ID :cifs_dbg (FYI ,"negotiated smb2.1 dialect\n" ); -else if (rsp->DialectRevision ==cpu_to_le16 (SMB30_PROT_ID )) +break ; +case SMB30_PROT_ID :cifs_dbg (FYI ,"negotiated smb3.0 dialect\n" ); -else if (rsp->DialectRevision ==cpu_to_le16 (SMB302_PROT_ID )) +break ; +case SMB302_PROT_ID :cifs_dbg (FYI ,"negotiated smb3.02 dialect\n" ); -else if (rsp->DialectRevision ==cpu_to_le16 (SMB311_PROT_ID )) +break ; +case SMB311_PROT_ID :cifs_dbg (FYI ,"negotiated smb3.1.1 dialect\n" ); -else { +break ; +default :cifs_server_dbg (VFS ,"Invalid dialect returned by server 0x%x\n" , -le16_to_cpu (rsp->DialectRevision)); + dialect_revision); goto neg_exit; } rc =0 ; - server->dialect =le16_to_cpu (rsp->DialectRevision); + server->dialect = dialect_revision;/* * Keep a copy of the hash after negprot. This hash will be
@@ -1461,10 +1557,9 @@ SMB2_negotiate(const unsigned int xid, rc = -EIO ; } -if (rsp->DialectRevision ==cpu_to_le16 (SMB311_PROT_ID )) { +if (server->dialect ==SMB311_PROT_ID ) {if (rsp->NegotiateContextCount) - rc =smb311_decode_neg_context (rsp, server, - rsp_iov.iov_len); + rc =smb311_decode_neg_context (smb, server);else cifs_server_dbg (VFS ,"Missing expected negotiate contexts\n" ); }
@@ -1472,7 +1567,7 @@ SMB2_negotiate(const unsigned int xid,if (server->cipher_type && !rc) rc =smb3_crypto_aead_allocate (server); neg_exit: -free_rsp_buf (resp_buftype, rsp); +smb_put_messages (smb);return rc; }
fs/smb/common/smb2pdu.h +6 -18
@@ -455,9 +455,7 @@ struct smb2_neg_context {#define MIN_PREAUTH_CTXT_DATA_LEN 6struct smb2_preauth_neg_context { -__le16 ContextType;/* 1 */ -__le16 DataLength; -__le32 Reserved; +struct smb2_neg_context neg;__le16 HashAlgorithmCount;/* 1 */ __le16 SaltLength;__le16 HashAlgorithms;/* HashAlgorithms[0] since only one defined */
@@ -473,9 +471,7 @@ struct smb2_preauth_neg_context {/* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */ #define MIN_ENCRYPT_CTXT_DATA_LEN 4struct smb2_encryption_neg_context { -__le16 ContextType;/* 2 */ -__le16 DataLength; -__le32 Reserved; +struct smb2_neg_context neg;/* CipherCount usually 2, but can be 3 when AES256-GCM enabled */ __le16 CipherCount;/* AES128-GCM and AES128-CCM by default */ __le16 Ciphers[];
@@ -495,9 +491,7 @@ struct smb2_encryption_neg_context {#define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)struct smb2_compression_capabilities_context { -__le16 ContextType;/* 3 */ -__le16 DataLength; -__le32 Reserved; +struct smb2_neg_context neg;__le16 CompressionAlgorithmCount;__le16 Padding;__le32 Flags;
@@ -511,9 +505,7 @@ struct smb2_compression_capabilities_context {* Its struct simply contains NetName, an array of Unicode characters */ struct smb2_netname_neg_context { -__le16 ContextType;/* 5 */ -__le16 DataLength; -__le32 Reserved; +struct smb2_neg_context neg;__le16 NetName[];/* hostname of target converted to UCS-2 */ } __packed;
@@ -567,9 +559,7 @@ struct smb2_rdma_transform_capabilities_context {#define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2)struct smb2_signing_capabilities { -__le16 ContextType;/* 8 */ -__le16 DataLength; -__le32 Reserved; +struct smb2_neg_context neg;__le16 SigningAlgorithmCount;__le16 SigningAlgorithms[];/* Followed by padding to 8 byte boundary (required by some servers) */
@@ -577,9 +567,7 @@ struct smb2_signing_capabilities {#define POSIX_CTXT_DATA_LEN 16struct smb2_posix_neg_context { -__le16 ContextType;/* 0x100 */ -__le16 DataLength; -__le32 Reserved; +struct smb2_neg_context neg;__u8 Name[16 ];/* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */ } __packed;
fs/smb/server/smb2pdu.c +11 -11
@@ -774,10 +774,10 @@ static int smb2_get_dos_mode(struct kstat *stat, int attribute)static void build_preauth_ctxt (struct smb2_preauth_neg_context *pneg_ctxt,__le16 hash_id) { - pneg_ctxt->ContextType =SMB2_PREAUTH_INTEGRITY_CAPABILITIES ; - pneg_ctxt->DataLength =cpu_to_le16 (38 ); + pneg_ctxt->neg.ContextType =SMB2_PREAUTH_INTEGRITY_CAPABILITIES ; + pneg_ctxt->neg.DataLength =cpu_to_le16 (38 ); + pneg_ctxt->neg.Reserved =cpu_to_le32 (0 ); pneg_ctxt->HashAlgorithmCount =cpu_to_le16 (1 ); - pneg_ctxt->Reserved =cpu_to_le32 (0 ); pneg_ctxt->SaltLength =cpu_to_le16 (SMB311_SALT_SIZE );get_random_bytes (pneg_ctxt->Salt,SMB311_SALT_SIZE ); pneg_ctxt->HashAlgorithms = hash_id;
@@ -786,9 +786,9 @@ static void build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt,static void build_encrypt_ctxt (struct smb2_encryption_neg_context *pneg_ctxt,__le16 cipher_type) { - pneg_ctxt->ContextType =SMB2_ENCRYPTION_CAPABILITIES ; - pneg_ctxt->DataLength =cpu_to_le16 (4 ); - pneg_ctxt->Reserved =cpu_to_le32 (0 ); + pneg_ctxt->neg.ContextType =SMB2_ENCRYPTION_CAPABILITIES ; + pneg_ctxt->neg.DataLength =cpu_to_le16 (4 ); + pneg_ctxt->neg.Reserved =cpu_to_le32 (0 ); pneg_ctxt->CipherCount =cpu_to_le16 (1 ); pneg_ctxt->Ciphers[0 ] = cipher_type; }
@@ -796,19 +796,19 @@ static void build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt,static void build_sign_cap_ctxt (struct smb2_signing_capabilities *pneg_ctxt,__le16 sign_algo) { - pneg_ctxt->ContextType =SMB2_SIGNING_CAPABILITIES ; - pneg_ctxt->DataLength = + pneg_ctxt->neg.ContextType =SMB2_SIGNING_CAPABILITIES ; + pneg_ctxt->neg.DataLength =cpu_to_le16 ((sizeof (struct smb2_signing_capabilities ) +2 ) -sizeof (struct smb2_neg_context )); - pneg_ctxt->Reserved =cpu_to_le32 (0 ); + pneg_ctxt->neg.Reserved =cpu_to_le32 (0 ); pneg_ctxt->SigningAlgorithmCount =cpu_to_le16 (1 ); pneg_ctxt->SigningAlgorithms[0 ] = sign_algo; }static void build_posix_ctxt (struct smb2_posix_neg_context *pneg_ctxt) { - pneg_ctxt->ContextType =SMB2_POSIX_EXTENSIONS_AVAILABLE ; - pneg_ctxt->DataLength =cpu_to_le16 (POSIX_CTXT_DATA_LEN ); + pneg_ctxt->neg.ContextType =SMB2_POSIX_EXTENSIONS_AVAILABLE ; + pneg_ctxt->neg.DataLength =cpu_to_le16 (POSIX_CTXT_DATA_LEN );/* SMB2_CREATE_TAG_POSIX is "0x93AD25509CB411E7B42383DE968BCD7C" */ pneg_ctxt->Name[0 ] =0x93 ; pneg_ctxt->Name[1 ] =0xAD ;
Re: [RFC PATCH 24/31] cifs: Convert SMB2 Negotiate Protocol request
Quoted 19 lines · David Howells
...
fs/smb/client/smb2pdu.c +1
-2-static unsigned int -build_netname_ctxt (struct smb2_netname_neg_context *pneg_ctxt,char *hostname) +static size_t smb2_size_netname_ctxt (struct TCP_Server_Info *server){
fs/smb/client/smb2pdu.c +3
-0+size_t data_len; + +#if 0 struct nls_table *cp = load_nls_default();fs/smb/client/smb2pdu.c +7
-1+const char *hostname; - pneg_ctxt->ContextType =SMB2_NETNAME_NEGOTIATE_CONTEXT_ID ; +/* Only include up to first 100 bytes of server name in the NetName +* field. +*/ +cifs_server_lock (pserver); + hostname = pserver->hostname; +if (hostname && hostname[0 ])
fs/smb/client/smb2pdu.c static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon, · line 907
Quoted 10 lines
fs/smb/client/smb2pdu.c +10
-0+ data_len =cifs_size_strtoUTF16 (hostname,100 , cp); +cifs_server_unlock (pserver); +#else +/* Now, we can't just measure the length of hostname as, unless we hold +* the lock, it may change under us, so allow maximum space for it. +*/ + data_len =400 ; +#endif +return ALIGN8 (sizeof (struct smb2_neg_context ) + data_len); +}
Why was this commented out? Your comment implies that you can't hold the lock anymore there, but I couldn't find out why (with your patches applied).
Quoted 24 lines
fs/smb/client/smb2pdu.c +2
-3-static void -assemble_neg_contexts (struct smb2_negotiate_req *req, -struct TCP_Server_Info *server,unsigned int *total_len) +static size_t smb2_size_neg_contexts (struct TCP_Server_Info *server, +size_t offset){
fs/smb/client/smb2pdu.c +0
-1-unsigned int ctxt_len, neg_context_count;struct TCP_Server_Info *pserver;fs/smb/client/smb2pdu.c +0
-8-char *pneg_ctxt; -char *hostname; - -if (*total_len >200 ) { -/* In case length corrupted don't want to overrun smb buffer */ -cifs_server_dbg (VFS ,"Bad frame length assembling neg contexts\n" ); -return ; - }/* * round up total_len of fixed part of SMB3 negotiate request to 8 * byte boundary before adding negotiate contexts */fs/smb/client/smb2pdu.c +2
-1- *total_len =ALIGN8 (*total_len); + offset =ALIGN8 (offset); + offset +=ALIGN8 (sizeof (struct smb2_preauth_neg_context ));
fs/smb/client/smb2pdu.c static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon, · line 965
Quoted 10 lines
fs/smb/client/smb2pdu.c +7
-2+ offset +=ALIGN8 (sizeof (struct smb2_encryption_neg_context )); - pneg_ctxt = (*total_len) + (char *)req; - req->NegotiateContextOffset =cpu_to_le32 (*total_len); +/* +* secondary channels don't have the hostname field populated +* use the hostname field in the primary channel instead +*/ + pserver =SERVER_IS_CHAN (server) ? server->primary_server : server; + offset +=smb2_size_netname_ctxt (pserver);
If you're keeping data_len=400 above, you could just drop smb2_size_netname_ctxt() altogether and use "ALIGN8(sizeof(struct smb2_neg_context) + 400)" directly here.
David Howells
maintainerRe: [RFC PATCH 24/31] cifs: Convert SMB2 Negotiate Protocol request
Quoted 25 lines · Enzo Matsumiya
Quoted 24 lines · David Howells
...
fs/smb/client/smb2pdu.c +1
-2-static unsigned int -build_netname_ctxt (struct smb2_netname_neg_context *pneg_ctxt,char *hostname) +static size_t smb2_size_netname_ctxt (struct TCP_Server_Info *server){
fs/smb/client/smb2pdu.c +3
-0+size_t data_len; + +#if 0 struct nls_table *cp = load_nls_default();fs/smb/client/smb2pdu.c +13
-1+const char *hostname; - pneg_ctxt->ContextType =SMB2_NETNAME_NEGOTIATE_CONTEXT_ID ; +/* Only include up to first 100 bytes of server name in the NetName +* field. +*/ +cifs_server_lock (pserver); + hostname = pserver->hostname; +if (hostname && hostname[0 ]) + data_len =cifs_size_strtoUTF16 (hostname,100 , cp); +cifs_server_unlock (pserver); +#else +/* Now, we can't just measure the length of hostname as, unless we hold +* the lock, it may change under us, so allow maximum space for it. +*/
Quoted 8 lines
fs/smb/client/smb2pdu.c static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon, · line 907
Quoted 4 lines
fs/smb/client/smb2pdu.c +4
-0+ data_len =400 ; +#endif +return ALIGN8 (sizeof (struct smb2_neg_context ) + data_len); +}Why was this commented out? Your comment implies that you can't hold the lock anymore there, but I couldn't find out why (with your patches applied).
The problem is that the hostname may change - and there's a spinlock to protect it. However, now that I'm working out the message size before the allocation, I need to find the size of the host name, do the alloc and then copy the hostname in - but I can't hold the spinlock across the alloc, so the hostname may change whilst the lock is dropped.
The obvious solution is to just allocate the maximum size for it. It's not that big and this command isn't used all that often.
Remember that this is a work in progress, so you may find bits like this where I may need to reconsider what I've chosen.
Quoted 26 lines
Quoted 26 lines
fs/smb/client/smb2pdu.c +2
-3-static void -assemble_neg_contexts (struct smb2_negotiate_req *req, -struct TCP_Server_Info *server,unsigned int *total_len) +static size_t smb2_size_neg_contexts (struct TCP_Server_Info *server, +size_t offset){
fs/smb/client/smb2pdu.c +0
-1-unsigned int ctxt_len, neg_context_count;struct TCP_Server_Info *pserver;fs/smb/client/smb2pdu.c +0
-8-char *pneg_ctxt; -char *hostname; - -if (*total_len >200 ) { -/* In case length corrupted don't want to overrun smb buffer */ -cifs_server_dbg (VFS ,"Bad frame length assembling neg contexts\n" ); -return ; - }/* * round up total_len of fixed part of SMB3 negotiate request to 8 * byte boundary before adding negotiate contexts */fs/smb/client/smb2pdu.c +3
-1- *total_len =ALIGN8 (*total_len); + offset =ALIGN8 (offset); + offset +=ALIGN8 (sizeof (struct smb2_preauth_neg_context )); + offset +=ALIGN8 (sizeof (struct smb2_encryption_neg_context ));
Quoted 12 lines
fs/smb/client/smb2pdu.c static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon, · line 965
Quoted 8 lines
fs/smb/client/smb2pdu.c +6
-2- pneg_ctxt = (*total_len) + (char *)req; - req->NegotiateContextOffset =cpu_to_le32 (*total_len); +/* +* secondary channels don't have the hostname field populated +* use the hostname field in the primary channel instead +*/ + pserver =SERVER_IS_CHAN (server) ? server->primary_server : server; + offset +=smb2_size_netname_ctxt (pserver);If you're keeping data_len=400 above, you could just drop
smb2_size_netname_ctxt()altogether and use "ALIGN8(sizeof(struct smb2_neg_context) + 400)" directly here.
Yeah. Probably would make sense to do that with a comment saying why 400.
David
David Howells
maintainerRFC PATCH 25/31 cifs: Convert SMB2 Session Setup request
In reply to David Howells--- fs/smb/client/ntlmssp.h | 20 +-- fs/smb/client/sess.c | 271 ++++++++++++++++++++++------------------ fs/smb/client/smb2pdu.c | 172 ++++++++++--------------- 3 files changed, 226 insertions(+), 237 deletions(-)
fs/smb/client/ntlmssp.h +10 -10
@@ -123,7 +123,7 @@ typedef struct _CHALLENGE_MESSAGE {do not set the version is present flag */ } __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE; -typedef struct _AUTHENTICATE_MESSAGE { +struct ntlmssp_authenticate_message {__u8 Signature[sizeof (NTLMSSP_SIGNATURE )];__le32 MessageType;/* NtLmsAuthenticate = 3 */ SECURITY_BUFFER LmChallengeResponse;
@@ -136,7 +136,7 @@ typedef struct _AUTHENTICATE_MESSAGE {struct ntlmssp_version Version;/* SECURITY_BUFFER */ char UserString[]; -} __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE; +} __attribute__((packed));/* * Size of the session key (crypto key encrypted with the password
@@ -147,11 +147,11 @@ int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen,struct cifs_ses *ses, struct TCP_Server_Info *server, const struct nls_table *nls_cp); -int build_ntlmssp_smb3_negotiate_blob (unsigned char **pbuffer,u16 *buflen, -struct cifs_ses *ses, -struct TCP_Server_Info *server, -const struct nls_table *nls_cp); -int build_ntlmssp_auth_blob (unsigned char **pbuffer,u16 *buflen, -struct cifs_ses *ses, -struct TCP_Server_Info *server, -const struct nls_table *nls_cp); +int build_ntlmssp_smb3_negotiate_blob (struct smb_message *smb, +struct cifs_ses *ses, +struct TCP_Server_Info *server, +const struct nls_table *nls_cp); +int build_ntlmssp_auth_blob (struct smb_message *smb, +struct cifs_ses *ses, +struct TCP_Server_Info *server, +const struct nls_table *nls_cp);
fs/smb/client/sess.c +150 -121
362 lines not on this page · raw message
fs/smb/client/smb2pdu.c +66 -106
313 lines not on this page · raw message
David Howells
maintainerRFC PATCH 26/31 cifs: Convert SMB2 Logoff request
In reply to David Howells--- fs/smb/client/smb2pdu.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-)
fs/smb/client/smb2pdu.c +9 -22
@@ -2212,15 +2212,10 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,int SMB2_logoff (const unsigned int xid,struct cifs_ses *ses) { -struct smb_rqst rqst; -struct smb2_logoff_req *req;/* response is also trivial struct */ -int rc =0 ;struct TCP_Server_Info *server; -int flags =0 ; -unsigned int total_len; -struct kvec iov[1 ]; -struct kvec rsp_iov; -int resp_buf_type; +struct smb2_logoff_req *req;/* response is also trivial struct */ +struct smb_message *smb =NULL ; +int rc =0 , flags =0 ;cifs_dbg (FYI ,"disconnect session %p\n" , ses);
@@ -2237,10 +2232,10 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses) }spin_unlock (&ses->chan_lock); - rc =smb2_plain_req_init (SMB2_LOGOFF ,NULL , ses->server, - (void **) &req, &total_len); -if (rc) -return rc; + smb =smb2_create_request (SMB2_LOGOFF , server,NULL , +sizeof (*req),sizeof (*req),0 ,0 ); +if (!smb) +return -ENOMEM ;/* since no tcon, smb2_init can not do this, so do here */ req->hdr.SessionId =cpu_to_le64 (ses->Suid);
@@ -2252,21 +2247,13 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses) flags |=CIFS_NO_RSP_BUF ; - iov[0 ].iov_base = (char *)req; - iov[0 ].iov_len = total_len; - -memset (&rqst,0 ,sizeof (struct smb_rqst )); - rqst.rq_iov = iov; - rqst.rq_nvec =1 ; - - rc =cifs_send_recv (xid, ses, ses->server, - &rqst, &resp_buf_type, flags, &rsp_iov); -cifs_small_buf_release (req); + rc =smb_send_recv_messages (xid, ses, ses->server, smb, flags);/* * No tcon so can't do * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); */ +smb_put_messages (smb); smb2_session_already_dead:return rc; }
David Howells
maintainerRFC PATCH 27/31 cifs: Convert SMB2 Tree Connect request
In reply to David Howells--- fs/smb/client/smb2pdu.c | 71 +++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 46 deletions(-)
fs/smb/client/smb2pdu.c +25 -46
@@ -2277,57 +2277,43 @@ int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, struct cifs_tcon *tcon, const struct nls_table *cp) { - struct smb_rqst rqst; + struct TCP_Server_Info *server = cifs_pick_channel(ses);struct smb2_tree_connect_req *req;struct smb2_tree_connect_rsp *rsp =NULL ; -struct kvec iov[2 ]; -struct kvec rsp_iov = {NULL ,0 }; -int rc =0 ; -int resp_buftype; -int unc_path_len; -__le16 *unc_path =NULL ; +struct smb_message *smb =NULL ; +int unc_path_size;int flags =0 ; -unsigned int total_len; -struct TCP_Server_Info *server =cifs_pick_channel (ses); +int rc =0 ;cifs_dbg (FYI ,"TCON\n" );if (!server || !tree)return -EIO ; - unc_path =kmalloc (MAX_SHARENAME_LENGTH *2 ,GFP_KERNEL ); -if (unc_path ==NULL ) -return -ENOMEM ; - - unc_path_len =cifs_strtoUTF16 (unc_path, tree,strlen (tree), cp); -if (unc_path_len <=0 ) { -kfree (unc_path); -return -EINVAL ; - } - unc_path_len *=2 ; + unc_path_size =cifs_size_strtoUTF16 (tree,INT_MAX , cp);/* SMB2 TREE_CONNECT request must be called with TreeId == 0 */ tcon->tid =0 ;atomic_set (&tcon->num_remote_opens,0 ); - rc =smb2_plain_req_init (SMB2_TREE_CONNECT , tcon, server, - (void **) &req, &total_len); -if (rc) { -kfree (unc_path); -return rc; - } + + smb =smb2_create_request (SMB2_TREE_CONNECT , server, tcon, +sizeof (*req),sizeof (*req) + unc_path_size,0 , +SMB2_REQ_DYNAMIC ); +if (!smb) +return -ENOMEM ;if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ; - iov[0 ].iov_base = (char *)req; -/* 1 for pad */ - iov[0 ].iov_len = total_len -1 ; -/* Testing shows that buffer offset must be at location of Buffer[0] */ - req->PathOffset =cpu_to_le16 (sizeof (struct smb2_tree_connect_req )); - req->PathLength =cpu_to_le16 (unc_path_len); - iov[1 ].iov_base = unc_path; - iov[1 ].iov_len = unc_path_len; + req->PathOffset =cpu_to_le16 (smb->ext_offset); + req->PathLength =cpu_to_le16 (unc_path_size); + + rc =cifs_strtoUTF16 (smb->request + smb->ext_offset, tree,strlen (tree), cp); +if (rc <=0 ) { + rc = -EINVAL ; + goto tcon_exit; + }/* * 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1
@@ -2341,22 +2327,17 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, ((ses->user_name != NULL) || (ses->sectype == Kerberos))) req->hdr.Flags |= SMB2_FLAGS_SIGNED; -memset (&rqst,0 ,sizeof (struct smb_rqst )); - rqst.rq_iov = iov; - rqst.rq_nvec =2 ; -/* Need 64 for max size write so ask for more in case not there yet */ if (server->credits >= server->max_credits) req->hdr.CreditRequest =cpu_to_le16 (0 );else req->hdr.CreditRequest =cpu_to_le16 ( -min_t (int, server->max_credits - - server->credits,64 )); +min_t (int, server->max_credits - server->credits,64 )); - rc =cifs_send_recv (xid, ses, server, - &rqst, &resp_buftype, flags, &rsp_iov); -cifs_small_buf_release (req); - rsp = (struct smb2_tree_connect_rsp *)rsp_iov.iov_base; + rc =smb_send_recv_messages (xid, ses, server, smb, flags); +smb_clear_request (smb); + + rsp = (struct smb2_tree_connect_rsp *)smb->response;trace_smb3_tcon (xid, tcon->tid, ses->Suid, tree, rc);if ((rc !=0 ) || (rsp ==NULL )) {cifs_stats_fail_inc (tcon,SMB2_TREE_CONNECT );
@@ -2403,9 +2384,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,if (tcon->share_flags &SMB2_SHAREFLAG_ISOLATED_TRANSPORT ) server->nosharesock = true; tcon_exit: - -free_rsp_buf (resp_buftype, rsp); -kfree (unc_path); +smb_put_messages (smb);return rc; tcon_error_exit:
David Howells
maintainerRFC PATCH 28/31 cifs: Convert SMB2 Tree Disconnect request
In reply to David Howells--- fs/smb/client/smb2pdu.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-)
fs/smb/client/smb2pdu.c +10 -21
@@ -2396,16 +2396,12 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon) { -struct smb_rqst rqst;struct smb2_tree_disconnect_req *req;/* response is trivial */ -int rc =0 ; +struct smb_message *smb =NULL ;struct cifs_ses *ses = tcon->ses;struct TCP_Server_Info *server =cifs_pick_channel (ses);int flags =0 ; -unsigned int total_len; -struct kvec iov[1 ]; -struct kvec rsp_iov; -int resp_buf_type; +int rc =0 ;cifs_dbg (FYI ,"Tree Disconnect\n" );
@@ -2423,33 +2419,26 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)invalidate_all_cached_dirs (tcon); - rc =smb2_plain_req_init (SMB2_TREE_DISCONNECT , tcon, server, - (void **) &req, - &total_len); -if (rc) -return rc; + smb =smb2_create_request (SMB2_TREE_DISCONNECT , server, tcon, +sizeof (*req),sizeof (*req),0 , +SMB2_REQ_DYNAMIC ); +if (!smb) +return -ENOMEM ;if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ; flags |=CIFS_NO_RSP_BUF ; - iov[0 ].iov_base = (char *)req; - iov[0 ].iov_len = total_len; - -memset (&rqst,0 ,sizeof (struct smb_rqst )); - rqst.rq_iov = iov; - rqst.rq_nvec =1 ; - - rc =cifs_send_recv (xid, ses, server, - &rqst, &resp_buf_type, flags, &rsp_iov); -cifs_small_buf_release (req); + rc =smb_send_recv_messages (xid, ses, server, smb, flags); +smb_clear_request (smb);if (rc) {cifs_stats_fail_inc (tcon,SMB2_TREE_DISCONNECT );trace_smb3_tdis_err (xid, tcon->tid, ses->Suid, rc); }trace_smb3_tdis_done (xid, tcon->tid, ses->Suid); +smb_put_messages (smb);return rc; }
David Howells
maintainerRFC PATCH 29/31 cifs: Rearrange Create request subfuncs
In reply to David Howells--- fs/smb/client/smb2pdu.c | 357 ++++++++++++++++++++-------------------- 1 file changed, 178 insertions(+), 179 deletions(-)
fs/smb/client/smb2pdu.c +178 -179
@@ -1228,61 +1228,6 @@ static int smb311_decode_neg_context(struct smb_message *smb,return rc; } -static struct create_posix * -create_posix_buf (umode_t mode) -{ -struct create_posix *buf; - - buf =kzalloc (sizeof (struct create_posix ), -GFP_KERNEL ); -if (!buf) -return NULL ; - - buf->ccontext.DataOffset = -cpu_to_le16 (offsetof(struct create_posix , Mode)); - buf->ccontext.DataLength =cpu_to_le32 (4 ); - buf->ccontext.NameOffset = -cpu_to_le16 (offsetof(struct create_posix , Name)); - buf->ccontext.NameLength =cpu_to_le16 (16 ); - -/* SMB2_CREATE_TAG_POSIX is "0x93AD25509CB411E7B42383DE968BCD7C" */ - buf->Name[0 ] =0x93 ; - buf->Name[1 ] =0xAD ; - buf->Name[2 ] =0x25 ; - buf->Name[3 ] =0x50 ; - buf->Name[4 ] =0x9C ; - buf->Name[5 ] =0xB4 ; - buf->Name[6 ] =0x11 ; - buf->Name[7 ] =0xE7 ; - buf->Name[8 ] =0xB4 ; - buf->Name[9 ] =0x23 ; - buf->Name[10 ] =0x83 ; - buf->Name[11 ] =0xDE ; - buf->Name[12 ] =0x96 ; - buf->Name[13 ] =0x8B ; - buf->Name[14 ] =0xCD ; - buf->Name[15 ] =0x7C ; - buf->Mode =cpu_to_le32 (mode); -cifs_dbg (FYI ,"mode on posix create 0%o\n" , mode); -return buf; -} - -static int -add_posix_context (struct kvec *iov,unsigned int *num_iovec,umode_t mode) -{ -unsigned int num = *num_iovec; - - iov[num].iov_base =create_posix_buf (mode); -if (mode ==ACL_NO_MODE ) -cifs_dbg (FYI ,"%s: no mode\n" , __func__); -if (iov[num].iov_base ==NULL ) -return -ENOMEM ; - iov[num].iov_len =sizeof (struct create_posix ); - *num_iovec = num +1 ; -return 0 ; -} - -/* * * SMB2 Worker functions follow:
@@ -2443,6 +2388,60 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) } +static struct create_posix * +create_posix_buf (umode_t mode) +{ +struct create_posix *buf; + + buf =kzalloc (sizeof (struct create_posix ), +GFP_KERNEL ); +if (!buf) +return NULL ; + + buf->ccontext.DataOffset = +cpu_to_le16 (offsetof(struct create_posix , Mode)); + buf->ccontext.DataLength =cpu_to_le32 (4 ); + buf->ccontext.NameOffset = +cpu_to_le16 (offsetof(struct create_posix , Name)); + buf->ccontext.NameLength =cpu_to_le16 (16 ); + +/* SMB2_CREATE_TAG_POSIX is "0x93AD25509CB411E7B42383DE968BCD7C" */ + buf->Name[0 ] =0x93 ; + buf->Name[1 ] =0xAD ; + buf->Name[2 ] =0x25 ; + buf->Name[3 ] =0x50 ; + buf->Name[4 ] =0x9C ; + buf->Name[5 ] =0xB4 ; + buf->Name[6 ] =0x11 ; + buf->Name[7 ] =0xE7 ; + buf->Name[8 ] =0xB4 ; + buf->Name[9 ] =0x23 ; + buf->Name[10 ] =0x83 ; + buf->Name[11 ] =0xDE ; + buf->Name[12 ] =0x96 ; + buf->Name[13 ] =0x8B ; + buf->Name[14 ] =0xCD ; + buf->Name[15 ] =0x7C ; + buf->Mode =cpu_to_le32 (mode); +cifs_dbg (FYI ,"mode on posix create 0%o\n" , mode); +return buf; +} + +static int +add_posix_context (struct kvec *iov,unsigned int *num_iovec,umode_t mode) +{ +unsigned int num = *num_iovec; + + iov[num].iov_base =create_posix_buf (mode); +if (mode ==ACL_NO_MODE ) +cifs_dbg (FYI ,"%s: no mode\n" , __func__); +if (iov[num].iov_base ==NULL ) +return -ENOMEM ; + iov[num].iov_len =sizeof (struct create_posix ); + *num_iovec = num +1 ; +return 0 ; +} +static struct create_durable *create_durable_buf (void ) {
@@ -2491,130 +2490,6 @@ create_reconnect_durable_buf(struct cifs_fid *fid)return buf; } -static void -parse_query_id_ctxt (struct create_context *cc,struct smb2_file_all_info *buf) -{ -struct create_disk_id_rsp *pdisk_id = (struct create_disk_id_rsp *)cc; - -cifs_dbg (FYI ,"parse query id context 0x%llx 0x%llx\n" , - pdisk_id->DiskFileId, pdisk_id->VolumeId); - buf->IndexNumber = pdisk_id->DiskFileId; -} - -static void -parse_posix_ctxt (struct create_context *cc,struct smb2_file_all_info *info, -struct create_posix_rsp *posix) -{ -int sid_len; -u8 *beg = (u8 *)cc +le16_to_cpu (cc->DataOffset); -u8 *end = beg +le32_to_cpu (cc->DataLength); -u8 *sid; - -memset (posix,0 ,sizeof (*posix)); - - posix->nlink =le32_to_cpu (*(__le32 *)(beg +0 )); - posix->reparse_tag =le32_to_cpu (*(__le32 *)(beg +4 )); - posix->mode =le32_to_cpu (*(__le32 *)(beg +8 )); - - sid = beg +12 ; - sid_len =posix_info_sid_size (sid, end); -if (sid_len <0 ) { -cifs_dbg (VFS ,"bad owner sid in posix create response\n" ); -return ; - } -memcpy (&posix->owner, sid, sid_len); - - sid = sid + sid_len; - sid_len =posix_info_sid_size (sid, end); -if (sid_len <0 ) { -cifs_dbg (VFS ,"bad group sid in posix create response\n" ); -return ; - } -memcpy (&posix->group, sid, sid_len); - -cifs_dbg (FYI ,"nlink=%d mode=%o reparse_tag=%x\n" , - posix->nlink, posix->mode, posix->reparse_tag); -} - -int smb2_parse_contexts (struct TCP_Server_Info *server, -struct kvec *rsp_iov, -__u16 *epoch, -char *lease_key,__u8 *oplock, -struct smb2_file_all_info *buf, -struct create_posix_rsp *posix) -{ -struct smb2_create_rsp *rsp = rsp_iov->iov_base; -struct create_context *cc; -size_t rem, off, len; -size_t doff, dlen; -size_t noff, nlen; -char *name; -static const char smb3_create_tag_posix[] = { -0x93 ,0xAD ,0x25 ,0x50 ,0x9C , -0xB4 ,0x11 ,0xE7 ,0xB4 ,0x23 ,0x83 , -0xDE ,0x96 ,0x8B ,0xCD ,0x7C - }; - - *oplock =0 ; - - off =le32_to_cpu (rsp->CreateContextsOffset); - rem =le32_to_cpu (rsp->CreateContextsLength); -if (check_add_overflow (off, rem, &len) || len > rsp_iov->iov_len) -return -EINVAL ; - cc = (struct create_context *)((u8 *)rsp + off); - -/* Initialize inode number to 0 in case no valid data in qfid context */ -if (buf) - buf->IndexNumber =0 ; - -while (rem >=sizeof (*cc)) { - doff =le16_to_cpu (cc->DataOffset); - dlen =le32_to_cpu (cc->DataLength); -if (check_add_overflow (doff, dlen, &len) || len > rem) -return -EINVAL ; - - noff =le16_to_cpu (cc->NameOffset); - nlen =le16_to_cpu (cc->NameLength); -if (noff + nlen > doff) -return -EINVAL ; - - name = (char *)cc + noff; -switch (nlen) { -case 4 : -if (!strncmp (name,SMB2_CREATE_REQUEST_LEASE ,4 )) { - *oplock = server->ops->parse_lease_buf (cc, epoch, - lease_key); - }else if (buf && - !strncmp (name,SMB2_CREATE_QUERY_ON_DISK_ID ,4 )) { -parse_query_id_ctxt (cc, buf); - } -break ; -case 16 : -if (posix && !memcmp (name, smb3_create_tag_posix,16 )) -parse_posix_ctxt (cc, buf, posix); -break ; -default : -cifs_dbg (FYI ,"%s: unhandled context (nlen=%zu dlen=%zu)\n" , - __func__, nlen, dlen); -if (IS_ENABLED (CONFIG_CIFS_DEBUG2 )) -cifs_dump_mem ("context data: " , cc, dlen); -break ; - } - - off =le32_to_cpu (cc->Next); -if (!off) -break ; -if (check_sub_overflow (rem, off, &rem)) -return -EINVAL ; - cc = (struct create_context *)((u8 *)cc + off); - } - -if (rsp->OplockLevel !=SMB2_OPLOCK_LEVEL_LEASE ) - *oplock = rsp->OplockLevel; - -return 0 ; -} - static int add_lease_context(struct TCP_Server_Info *server, struct smb2_create_req *req,
@@ -3383,6 +3258,130 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,return 0 ; } +static void +parse_query_id_ctxt (struct create_context *cc,struct smb2_file_all_info *buf) +{ +struct create_disk_id_rsp *pdisk_id = (struct create_disk_id_rsp *)cc; + +cifs_dbg (FYI ,"parse query id context 0x%llx 0x%llx\n" , + pdisk_id->DiskFileId, pdisk_id->VolumeId); + buf->IndexNumber = pdisk_id->DiskFileId; +} + +static void +parse_posix_ctxt (struct create_context *cc,struct smb2_file_all_info *info, +struct create_posix_rsp *posix) +{ +int sid_len; +u8 *beg = (u8 *)cc +le16_to_cpu (cc->DataOffset); +u8 *end = beg +le32_to_cpu (cc->DataLength); +u8 *sid; + +memset (posix,0 ,sizeof (*posix)); + + posix->nlink =le32_to_cpu (*(__le32 *)(beg +0 )); + posix->reparse_tag =le32_to_cpu (*(__le32 *)(beg +4 )); + posix->mode =le32_to_cpu (*(__le32 *)(beg +8 )); + + sid = beg +12 ; + sid_len =posix_info_sid_size (sid, end); +if (sid_len <0 ) { +cifs_dbg (VFS ,"bad owner sid in posix create response\n" ); +return ; + } +memcpy (&posix->owner, sid, sid_len); + + sid = sid + sid_len; + sid_len =posix_info_sid_size (sid, end); +if (sid_len <0 ) { +cifs_dbg (VFS ,"bad group sid in posix create response\n" ); +return ; + } +memcpy (&posix->group, sid, sid_len); + +cifs_dbg (FYI ,"nlink=%d mode=%o reparse_tag=%x\n" , + posix->nlink, posix->mode, posix->reparse_tag); +} + +int smb2_parse_contexts (struct TCP_Server_Info *server, +struct kvec *rsp_iov, +__u16 *epoch, +char *lease_key,__u8 *oplock, +struct smb2_file_all_info *buf, +struct create_posix_rsp *posix) +{ +struct smb2_create_rsp *rsp = rsp_iov->iov_base; +struct create_context *cc; +size_t rem, off, len; +size_t doff, dlen; +size_t noff, nlen; +char *name; +static const char smb3_create_tag_posix[] = { +0x93 ,0xAD ,0x25 ,0x50 ,0x9C , +0xB4 ,0x11 ,0xE7 ,0xB4 ,0x23 ,0x83 , +0xDE ,0x96 ,0x8B ,0xCD ,0x7C + }; + + *oplock =0 ; + + off =le32_to_cpu (rsp->CreateContextsOffset); + rem =le32_to_cpu (rsp->CreateContextsLength); +if (check_add_overflow (off, rem, &len) || len > rsp_iov->iov_len) +return -EINVAL ; + cc = (struct create_context *)((u8 *)rsp + off); + +/* Initialize inode number to 0 in case no valid data in qfid context */ +if (buf) + buf->IndexNumber =0 ; + +while (rem >=sizeof (*cc)) { + doff =le16_to_cpu (cc->DataOffset); + dlen =le32_to_cpu (cc->DataLength); +if (check_add_overflow (doff, dlen, &len) || len > rem) +return -EINVAL ; + + noff =le16_to_cpu (cc->NameOffset); + nlen =le16_to_cpu (cc->NameLength); +if (noff + nlen > doff) +return -EINVAL ; + + name = (char *)cc + noff; +switch (nlen) { +case 4 : +if (!strncmp (name,SMB2_CREATE_REQUEST_LEASE ,4 )) { + *oplock = server->ops->parse_lease_buf (cc, epoch, + lease_key); + }else if (buf && + !strncmp (name,SMB2_CREATE_QUERY_ON_DISK_ID ,4 )) { +parse_query_id_ctxt (cc, buf); + } +break ; +case 16 : +if (posix && !memcmp (name, smb3_create_tag_posix,16 )) +parse_posix_ctxt (cc, buf, posix); +break ; +default : +cifs_dbg (FYI ,"%s: unhandled context (nlen=%zu dlen=%zu)\n" , + __func__, nlen, dlen); +if (IS_ENABLED (CONFIG_CIFS_DEBUG2 )) +cifs_dump_mem ("context data: " , cc, dlen); +break ; + } + + off =le32_to_cpu (cc->Next); +if (!off) +break ; +if (check_sub_overflow (rem, off, &rem)) +return -EINVAL ; + cc = (struct create_context *)((u8 *)cc + off); + } + +if (rsp->OplockLevel !=SMB2_OPLOCK_LEVEL_LEASE ) + *oplock = rsp->OplockLevel; + +return 0 ; +} +/* rq_iov[0] is the request and is released by cifs_small_buf_release(). * All other vectors are freed by kfree(). */
David Howells
maintainerRFC PATCH 30/31 cifs: Convert SMB2 Posix Mkdir request
In reply to David Howells--- fs/smb/client/smb2pdu.c | 244 ++++++++++++++++++++++------------------ 1 file changed, 137 insertions(+), 107 deletions(-)
fs/smb/client/smb2pdu.c +137 -107
@@ -2388,16 +2388,8 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) } -static struct create_posix * -create_posix_buf (umode_t mode) +static void fill_posix_buf (struct create_posix *buf,umode_t mode) { -struct create_posix *buf; - - buf =kzalloc (sizeof (struct create_posix ), -GFP_KERNEL ); -if (!buf) -return NULL ; - buf->ccontext.DataOffset =cpu_to_le16 (offsetof(struct create_posix , Mode)); buf->ccontext.DataLength =cpu_to_le32 (4 );
@@ -2424,20 +2416,25 @@ create_posix_buf(umode_t mode) buf->Name[15 ] =0x7C ; buf->Mode =cpu_to_le32 (mode);cifs_dbg (FYI ,"mode on posix create 0%o\n" , mode); -return buf; }static int add_posix_context (struct kvec *iov,unsigned int *num_iovec,umode_t mode) { +struct create_posix *buf;unsigned int num = *num_iovec; - iov[num].iov_base =create_posix_buf (mode);if (mode ==ACL_NO_MODE )cifs_dbg (FYI ,"%s: no mode\n" , __func__); -if (iov[num].iov_base ==NULL ) + + buf =kzalloc (sizeof (struct create_posix ),GFP_KERNEL ); +if (!buf)return -ENOMEM ; - iov[num].iov_len =sizeof (struct create_posix ); + +fill_posix_buf (buf, mode); + + iov[num].iov_base = buf; + iov[num].iov_len =sizeof (struct create_posix ); *num_iovec = num +1 ;return 0 ; }
@@ -2906,72 +2903,140 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len,return 0 ; } +struct smb2_create_layout { +const struct nls_table *cp; +u16 offset;/* Running offset for assembly */ +u16 path_len;/* Length of utf16 path (or 0) */ +u16 treename_len;/* Length of DFS prefix (or 0) */ +u16 name_len;/* Total name length */ +u16 name_offset;/* Offset in message of name */ +u16 contexts_offset;/* Offset in message contexts */ +u16 contexts_len;/* Length of contexts (or 0) */ +u16 posix_offset;/* Offset in message of posix context */ +u8 name_pad;/* Amount of name padding needed */ +}; + +static int smb311_posix_mkdir_layout (struct cifs_tcon *tcon, +struct smb2_create_layout *lay) +{ +size_t offset = lay->offset; +size_t tmp; +bool has_contexts = false; + +/* [MS-SMB2] 2.2.13 NameOffset: If SMB2_FLAGS_DFS_OPERATIONS +* is set in the Flags field of the SMB2 header, the file name +* includes a prefix that will be processed during DFS name +* normalization as specified in section 3.3.5.9. Otherwise, +* the file name is relative to the share that is identified +* by the TreeId in the SMB2 header. +*/ + lay->name_offset = offset; +if (tcon->share_flags &SHI1005_FLAGS_DFS ) { +const char *treename = tcon->tree_name; +int treename_len; + +/* skip leading "\\" */ +if (!(treename[0 ] =='\\' && treename[1 ] =='\\' )) +return -EINVAL ; + + treename_len =cifs_size_strtoUTF16 (treename +2 ,INT_MAX , lay->cp); + + lay->treename_len = treename_len; + lay->name_len = treename_len; +if (lay->path_len) + lay->name_len +=2 + lay->path_len; + }else { + lay->name_len = lay->path_len; + } + + offset += lay->name_len; + tmp = offset; + offset =ALIGN8 (offset); + lay->name_pad = offset - tmp; + lay->contexts_offset = offset; + +if (tcon->posix_extensions) { +/* resource #3: posix buf */ + offset +=sizeof (struct create_posix ); + has_contexts = true; + } + +if (has_contexts) + lay->contexts_len = offset - lay->contexts_offset; +else + lay->contexts_offset =0 ; + + lay->offset = offset; +return 0 ; +} +int smb311_posix_mkdir (const unsigned int xid,struct inode *inode,umode_t mode,struct cifs_tcon *tcon,const char *full_path,struct cifs_sb_info *cifs_sb) { -struct smb_rqst rqst; +struct TCP_Server_Info *server;struct smb2_create_req *req;struct smb2_create_rsp *rsp =NULL ; +struct smb_message *smb =NULL ;struct cifs_ses *ses = tcon->ses; -struct kvec iov[3 ];/* make sure at least one for each open context */ -struct kvec rsp_iov = {NULL ,0 }; -int resp_buftype; -int uni_path_len; -__le16 *copy_path =NULL ; -int copy_size; -int rc =0 ; -unsigned int n_iov =2 ; +__le16 *utf16_path =NULL ;__u32 file_attributes =0 ; -char *pc_buf =NULL ; +int retries =0 , cur_sleep =1 , path_len;int flags =0 ; -unsigned int total_len; -__le16 *utf16_path =NULL ; -struct TCP_Server_Info *server; -int retries =0 , cur_sleep =1 ; +int rc =0 ; + +/* resource #1: path allocation */ + utf16_path =cifs_convert_path_to_utf16 (full_path, cifs_sb); +if (!utf16_path) +return -ENOMEM ; + path_len =UniStrlen (utf16_path); replay_again:/* reinitialize for possible replay */ flags =0 ; - n_iov =2 ; server =cifs_pick_channel (ses);cifs_dbg (FYI ,"mkdir\n" ); -/* resource #1: path allocation */ - utf16_path =cifs_convert_path_to_utf16 (full_path, cifs_sb); -if (!utf16_path) -return -ENOMEM ; - -if (!ses || !server) { +if (!server) { rc = -EIO ; goto err_free_path; } +struct smb2_create_layout layout = { + .offset =sizeof (struct smb2_create_req ), + .path_len = path_len, + .cp = cifs_sb->local_nls, + }; + rc =smb311_posix_mkdir_layout (tcon, &layout); +if (rc <0 ) + goto err_free_path; +/* resource #2: request */ - rc =smb2_plain_req_init (SMB2_CREATE , tcon, server, - (void **) &req, &total_len); -if (rc) + rc = -ENOMEM ; + smb =smb2_create_request (SMB2_CREATE , server, tcon, +sizeof (*req), layout.offset,0 , +SMB2_REQ_DYNAMIC ); +if (!smb) goto err_free_path;if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ; - req->ImpersonationLevel =IL_IMPERSONATION ; - req->DesiredAccess =cpu_to_le32 (FILE_WRITE_ATTRIBUTES ); + req->ImpersonationLevel =IL_IMPERSONATION ; + req->DesiredAccess =cpu_to_le32 (FILE_WRITE_ATTRIBUTES );/* File attributes ignored on open (used in create though) */ - req->FileAttributes =cpu_to_le32 (file_attributes); - req->ShareAccess =FILE_SHARE_ALL_LE ; - req->CreateDisposition =cpu_to_le32 (FILE_CREATE ); - req->CreateOptions =cpu_to_le32 (CREATE_NOT_FILE ); - - iov[0 ].iov_base = (char *)req; -/* -1 since last byte is buf[0] which is sent below (path) */ - iov[0 ].iov_len = total_len -1 ; - - req->NameOffset =cpu_to_le16 (sizeof (struct smb2_create_req )); + req->FileAttributes =cpu_to_le32 (file_attributes); + req->ShareAccess =FILE_SHARE_ALL_LE ; + req->CreateDisposition =cpu_to_le32 (FILE_CREATE ); + req->CreateOptions =cpu_to_le32 (CREATE_NOT_FILE ); + req->NameOffset =cpu_to_le16 (layout.name_offset); + req->NameLength =cpu_to_le16 (layout.name_len); + req->RequestedOplockLevel =SMB2_OPLOCK_LEVEL_NONE ; + req->CreateContextsOffset =cpu_to_le32 (layout.contexts_offset); + req->CreateContextsLength =cpu_to_le32 (layout.contexts_len);/* [MS-SMB2] 2.2.13 NameOffset: * If SMB2_FLAGS_DFS_OPERATIONS is set in the Flags field of
@@ -2981,78 +3046,48 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,* the share that is identified by the TreeId in the SMB2 * header. */ +__le16 *name = smb->request + layout.name_offset; +if (tcon->share_flags &SHI1005_FLAGS_DFS ) { -int name_len; +int tmp; req->hdr.Flags |=SMB2_FLAGS_DFS_OPERATIONS ; - rc =alloc_path_with_tree_prefix (©_path, ©_size, - &name_len, - tcon->tree_name, utf16_path); -if (rc) - goto err_free_req; - req->NameLength =cpu_to_le16 (name_len *2 ); - uni_path_len = copy_size; -/* free before overwriting resource */ -kfree (utf16_path); - utf16_path = copy_path; - }else { - uni_path_len = (2 *UniStrnlen ((wchar_t *)utf16_path,PATH_MAX )) +2 ; -/* MUST set path len (NameLength) to 0 opening root of share */ - req->NameLength =cpu_to_le16 (uni_path_len -2 ); -if (uni_path_len %8 !=0 ) { - copy_size =roundup (uni_path_len,8 ); - copy_path =kzalloc (copy_size,GFP_KERNEL ); -if (!copy_path) { - rc = -ENOMEM ; - goto err_free_req; - } -memcpy ((char *)copy_path, (const char *)utf16_path, - uni_path_len); - uni_path_len = copy_size; -/* free before overwriting resource */ -kfree (utf16_path); - utf16_path = copy_path; + tmp =cifs_strtoUTF16 (name, tcon->tree_name +2 ,INT_MAX , + layout.cp); +WARN_ON (tmp != layout.treename_len); + name += tmp; +if (layout.path_len) { + *name++ =cpu_to_le16 ('\\' ); +memcpy (name, utf16_path, layout.path_len); } + }else { +memcpy (name, utf16_path, layout.path_len); } - iov[1 ].iov_len = uni_path_len; - iov[1 ].iov_base = utf16_path; - req->RequestedOplockLevel =SMB2_OPLOCK_LEVEL_NONE ; +if (layout.name_pad) +memset (smb->request + layout.name_offset + layout.name_len, +0 , layout.name_pad); -if (tcon->posix_extensions) { +if (tcon->posix_extensions)/* resource #3: posix buf */ - rc =add_posix_context (iov, &n_iov, mode); -if (rc) - goto err_free_req; - req->CreateContextsOffset =cpu_to_le32 ( -sizeof (struct smb2_create_req ) + - iov[1 ].iov_len); -le32_add_cpu (&req->CreateContextsLength, iov[n_iov-1 ].iov_len); - pc_buf = iov[n_iov-1 ].iov_base; - } - - -memset (&rqst,0 ,sizeof (struct smb_rqst )); - rqst.rq_iov = iov; - rqst.rq_nvec = n_iov; +fill_posix_buf (smb->request + layout.posix_offset, mode);/* no need to inc num_remote_opens because we close it just below */ trace_smb3_posix_mkdir_enter (xid, tcon->tid, ses->Suid, full_path,CREATE_NOT_FILE ,FILE_WRITE_ATTRIBUTES );if (retries) -smb2_set_replay (server, &rqst); +smb2_set_replay_smb (server, smb);/* resource #4: response buffer */ - rc =cifs_send_recv (xid, ses, server, - &rqst, &resp_buftype, flags, &rsp_iov); + rc =smb_send_recv_messages (xid, ses, server, smb, flags);if (rc) {cifs_stats_fail_inc (tcon,SMB2_CREATE );trace_smb3_posix_mkdir_err (xid, tcon->tid, ses->Suid,CREATE_NOT_FILE ,FILE_WRITE_ATTRIBUTES , rc); - goto err_free_rsp_buf; + goto err_free_req; }/*
@@ -3060,10 +3095,9 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,* adding check below is slightly safer long term (and quiets Coverity * warning) */ - rsp = (struct smb2_create_rsp *)rsp_iov.iov_base; + rsp = (struct smb2_create_rsp *)smb->response;if (rsp ==NULL ) { rc = -EIO ; -kfree (pc_buf); goto err_free_req; }
@@ -3074,18 +3108,14 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,/* Eventually save off posix specific response info and timestamps */ -err_free_rsp_buf: -free_rsp_buf (resp_buftype, rsp_iov.iov_base); -kfree (pc_buf); err_free_req: -cifs_small_buf_release (req); +smb_put_messages (smb); err_free_path: -kfree (utf16_path); -if (is_replayable_error (rc) &&smb2_should_replay (tcon, &retries, &cur_sleep)) goto replay_again; +kfree (utf16_path);return rc; }
David Howells
maintainerRFC PATCH 31/31 cifs: Convert SMB2 Open request
In reply to David Howells--- fs/smb/client/cached_dir.c | 41 +- fs/smb/client/cifsglob.h | 5 +- fs/smb/client/smb2inode.c | 6 +- fs/smb/client/smb2ops.c | 34 +- fs/smb/client/smb2pdu.c | 877 +++++++++++++++---------------------- fs/smb/client/smb2proto.h | 29 +- 6 files changed, 399 insertions(+), 593 deletions(-)
fs/smb/client/cached_dir.c +15 -26
@@ -141,9 +141,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,struct cifs_open_parms oparms;struct smb2_create_rsp *o_rsp =NULL ;struct smb2_query_info_rsp *qi_rsp =NULL ; -int resp_buftype[2 ]; -struct smb_rqst rqst[2 ]; -struct kvec rsp_iov[2 ]; +struct smb_message *smb;struct kvec open_iov[SMB2_CREATE_IOV_SIZE ];struct kvec qi_iov[1 ];int rc, flags =0 ;
@@ -260,29 +258,20 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, server->ops->new_lease_key (pfid); -memset (rqst,0 ,sizeof (rqst)); - resp_buftype[0 ] = resp_buftype[1 ] =CIFS_NO_BUFFER ; -memset (rsp_iov,0 ,sizeof (rsp_iov)); -/* Open */ -memset (&open_iov,0 ,sizeof (open_iov)); - rqst[0 ].rq_iov = open_iov; - rqst[0 ].rq_nvec =SMB2_CREATE_IOV_SIZE ; - oparms = (struct cifs_open_parms ) { - .tcon = tcon, - .path = path, - .create_options =cifs_create_options (cifs_sb,CREATE_NOT_FILE ), - .desired_access =FILE_READ_DATA |FILE_READ_ATTRIBUTES | -FILE_READ_EA , - .disposition =FILE_OPEN , - .fid = pfid, - .lease_flags = lease_flags, - .replay = !!(retries), + .tcon = tcon, + .path = path, + .create_options =cifs_create_options (cifs_sb,CREATE_NOT_FILE ), + .desired_access =FILE_READ_DATA |FILE_READ_ATTRIBUTES | +FILE_READ_EA , + .disposition =FILE_OPEN , + .fid = pfid, + .lease_flags = lease_flags, + .replay = !!(retries), }; - rc =SMB2_open_init (tcon, server, - &rqst[0 ], &oplock, &oparms, utf16_path); + smb =SMB2_open_init (tcon, server, &oplock, &oparms, utf16_path);if (rc) goto oshr_free;smb2_set_next_command (tcon, &rqst[0 ]);
@@ -336,10 +325,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, goto oshr_free; } - rc =smb2_parse_contexts (server, rsp_iov, - &oparms.fid->epoch, - oparms.fid->lease_key, - &oplock,NULL ,NULL ); + rc =smb2_parse_create_response (server, rsp_iov, + &oparms.fid->epoch, + oparms.fid->lease_key, + &oplock,NULL ,NULL );if (rc) {spin_unlock (&cfids->cfid_list_lock); goto oshr_free;
fs/smb/client/cifsglob.h +3 -2
@@ -554,8 +554,9 @@ struct smb_version_operations {/* set oplock level for the inode */ void (*set_oplock_level)(struct cifsInodeInfo *cinode,__u32 oplock,__u16 epoch,bool *purge_cache); -/* create lease context buffer for CREATE request */ -char * (*create_lease_buf)(u8 *lease_key,u8 oplock,u8 *parent_lease_key,__le32 le_flags); +/* Fill in a lease context buffer for CREATE request */ +void (*fill_lease_buf)(struct smb_message *smb,const u8 *lease_key,u8 oplock, +const u8 *parent_lease_key,__le32 le_flags);/* parse lease context buffer and return oplock/epoch info */ __u8 (*parse_lease_buf)(void *buf, __u16 *epoch, char *lkey); ssize_t (*copychunk_range)(const unsigned int,
fs/smb/client/smb2inode.c +3 -3
@@ -663,9 +663,9 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, idata->fi.DeletePending =0 ; idata->fi.Directory = !!(le32_to_cpu (create_rsp->FileAttributes) &ATTR_DIRECTORY ); -/* smb2_parse_contexts() fills idata->fi.IndexNumber */ - rc =smb2_parse_contexts (server, &rsp_iov[0 ], &oparms->fid->epoch, - oparms->fid->lease_key, &oplock, &idata->fi,NULL ); +/* smb2_parse_create_response() fills idata->fi.IndexNumber */ + rc =smb2_parse_create_response (server, &rsp_iov[0 ], &oparms->fid->epoch, + oparms->fid->lease_key, &oplock, &idata->fi,NULL );if (rc)cifs_dbg (VFS ,"rc: %d parsing context of compound op\n" , rc); }
fs/smb/client/smb2ops.c +14 -20
@@ -4086,14 +4086,11 @@ map_oplock_to_lease(u8 oplock)return 0 ; } -static char * -smb2_create_lease_buf (u8 *lease_key,u8 oplock,u8 *parent_lease_key,__le32 flags) +static void +smb2_fill_lease_buf (struct smb_message *smb,const u8 *lease_key,u8 oplock, +const u8 *parent_lease_key,__le32 flags) { -struct create_lease *buf; - - buf =kzalloc (sizeof (struct create_lease ),GFP_KERNEL ); -if (!buf) -return NULL ; +struct create_lease *buf =cifs_begin_extension (smb);memcpy (&buf->lcontext.LeaseKey, lease_key,SMB2_LEASE_KEY_SIZE ); buf->lcontext.LeaseState =map_oplock_to_lease (oplock);
@@ -4109,17 +4106,14 @@ smb2_create_lease_buf(u8 *lease_key, u8 oplock, u8 *parent_lease_key, __le32 fla buf->Name[1 ] ='q' ; buf->Name[2 ] ='L' ; buf->Name[3 ] ='s' ; -return (char *)buf; +cifs_end_extension (smb,sizeof (*buf)); } -static char * -smb3_create_lease_buf (u8 *lease_key,u8 oplock,u8 *parent_lease_key,__le32 flags) +static void +smb3_fill_lease_buf (struct smb_message *smb,const u8 *lease_key,u8 oplock, +const u8 *parent_lease_key,__le32 flags) { -struct create_lease_v2 *buf; - - buf =kzalloc (sizeof (struct create_lease_v2 ),GFP_KERNEL ); -if (!buf) -return NULL ; +struct create_lease_v2 *buf =cifs_begin_extension (smb);memcpy (&buf->lcontext.LeaseKey, lease_key,SMB2_LEASE_KEY_SIZE ); buf->lcontext.LeaseState =map_oplock_to_lease (oplock);
@@ -4138,7 +4132,7 @@ smb3_create_lease_buf(u8 *lease_key, u8 oplock, u8 *parent_lease_key, __le32 fla buf->Name[1 ] ='q' ; buf->Name[2 ] ='L' ; buf->Name[3 ] ='s' ; -return (char *)buf; +cifs_end_extension (smb,sizeof (*buf)); } static __u8
@@ -5263,7 +5257,7 @@ struct smb_version_operations smb20_operations = { .calc_signature = smb2_calc_signature, .is_read_op = smb2_is_read_op, .set_oplock_level = smb2_set_oplock_level, - .create_lease_buf = smb2_create_lease_buf, + .fill_lease_buf = smb2_fill_lease_buf, .parse_lease_buf = smb2_parse_lease_buf, .copychunk_range = smb2_copychunk_range, .wp_retry_size = smb2_wp_retry_size,
@@ -5366,7 +5360,7 @@ struct smb_version_operations smb21_operations = { .calc_signature = smb2_calc_signature, .is_read_op = smb21_is_read_op, .set_oplock_level = smb21_set_oplock_level, - .create_lease_buf = smb2_create_lease_buf, + .fill_lease_buf = smb2_fill_lease_buf, .parse_lease_buf = smb2_parse_lease_buf, .copychunk_range = smb2_copychunk_range, .wp_retry_size = smb2_wp_retry_size,
@@ -5476,7 +5470,7 @@ struct smb_version_operations smb30_operations = { .set_integrity = smb3_set_integrity, .is_read_op = smb21_is_read_op, .set_oplock_level = smb3_set_oplock_level, - .create_lease_buf = smb3_create_lease_buf, + .fill_lease_buf = smb3_fill_lease_buf, .parse_lease_buf = smb3_parse_lease_buf, .copychunk_range = smb2_copychunk_range, .duplicate_extents = smb2_duplicate_extents,
@@ -5592,7 +5586,7 @@ struct smb_version_operations smb311_operations = { .set_integrity = smb3_set_integrity, .is_read_op = smb21_is_read_op, .set_oplock_level = smb3_set_oplock_level, - .create_lease_buf = smb3_create_lease_buf, + .fill_lease_buf = smb3_fill_lease_buf, .parse_lease_buf = smb3_parse_lease_buf, .copychunk_range = smb2_copychunk_range, .duplicate_extents = smb2_duplicate_extents,
fs/smb/client/smb2pdu.c +352 -525
1,106 lines not on this page · raw message
fs/smb/client/smb2proto.h +12 -17
@@ -151,17 +151,12 @@ extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, struct cifs_tcon *tcon, const struct nls_table *);extern int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon); -extern int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms, -__le16 *path,__u8 *oplock, -struct smb2_file_all_info *buf, -struct create_posix_rsp *posix, -struct kvec *err_iov,int *resp_buftype); -extern int SMB2_open_init (struct cifs_tcon *tcon, -struct TCP_Server_Info *server, -struct smb_rqst *rqst, -__u8 *oplock,struct cifs_open_parms *oparms, -__le16 *path); -extern void SMB2_open_free (struct smb_rqst *rqst); +int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path, +__u8 *oplock,struct smb2_file_all_info *buf, +struct create_posix_rsp *posix,struct kvec *err_iov); +struct smb_message *SMB2_open_init (struct cifs_tcon *tcon, +struct TCP_Server_Info *server,__u8 *oplock, +struct cifs_open_parms *oparms,__le16 *path); extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, u32 opcode, char *in_data, u32 indatalen, u32 maxoutlen,
@@ -276,12 +271,12 @@ extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);extern enum securityEnum smb2_select_sectype (struct TCP_Server_Info *,enum securityEnum ); -int smb2_parse_contexts (struct TCP_Server_Info *server, -struct kvec *rsp_iov, -__u16 *epoch, -char *lease_key,__u8 *oplock, -struct smb2_file_all_info *buf, -struct create_posix_rsp *posix); +int smb2_parse_create_response (struct TCP_Server_Info *server, +struct smb_message *smb, +__u16 *epoch, +char *lease_key,__u8 *oplock, +struct smb2_file_all_info *buf, +struct create_posix_rsp *posix);extern int smb3_encryption_required (const struct cifs_tcon *tcon); extern int smb2_validate_iov(unsigned int offset, unsigned int buffer_length,
Stefan Metzmacher
reviewerHi David,
Quoted 7 lines
The aim is to build up a list of fragments for each request using a bvecq. These form a segmented list and can be spliced together when assembling a compound request. The segmented list can then be passed to
sendmsg()withMSG_SPLICE_PAGESin a single call, thereby only having a single loop (in the TCP stack) to shovel data, not loops-over-loops. Possibly we can dispense with corking also, provided we can tell TCP to flush the record boundaries. (Note that this also simplifiessmbd_send()for RDMA).
I didn't look at the patches in detail, but I like the simplifications for the transport layer and that hopefully allows me to move smbd_send() behind sendmsg() with MSG_SPLICE_PAGES in the end.
So the current situation is that we memcpy (at least) in sendmsg() and with your patches we do a memcpy higher in the stack, but then use MSG_SPLICE_PAGES in order to do it twice. Is that correct?
Thanks!
metze
David Howells
maintainerQuoted 3 lines · Stefan Metzmacher
So the current situation is that we memcpy (at least) in
sendmsg()and with your patches we do a memcpy higher in the stack, but then useMSG_SPLICE_PAGESin order to do it twice. Is that correct?
Not twice, no. MSG_SPLICE_PAGES allows sendmsg() to splice the supplied pages into the sk_buffs directly, thereby avoiding a copy in the TCP layer and cutting out the feeder loop in cifs.
However, this is meant to be an intermediate step. I actually want to assemble the fragment list in a bvecq in the smb_create_request() as called by the PDU encoders, with everything aligned for crypto so that the crypto layer doesn't copy it also. But cleaning up the transport first should hopefully reduce the size of the later patches.
David
Stefan Metzmacher
reviewerAm 07.08.25 um 08:24 schrieb David Howells:
Quoted 9 lines
Quoted 3 lines · Stefan Metzmacher
So the current situation is that we memcpy (at least) in
sendmsg()and with your patches we do a memcpy higher in the stack, but then useMSG_SPLICE_PAGESin order to do it twice. Is that correct?Not twice, no.
MSG_SPLICE_PAGESallowssendmsg()to splice the supplied pages into thesk_buffsdirectly, thereby avoiding a copy in the TCP layer and cutting out the feeder loop in cifs.
Yes, and we must be careful to not touch the pages after calling sendmsg(MSG_SPLICE_PAGES).
And unlike MSG_ZEROCOPY tcp_sendmsg_locked() has no no struct ubuf_info *uarg when MSG_SPLICE_PAGES is used and there's no way to know when the pages are no longer used by the tcp stack.
Can you explain how/where we allocate the memory and where we unreference it in the caller of sendmsg(MSG_SPLICE_PAGES).
Quoted 5 lines
However, this is meant to be an intermediate step. I actually want to assemble the fragment list in a bvecq in the
smb_create_request()as called by the PDU encoders, with everything aligned for crypto so that the crypto layer doesn't copy it also. But cleaning up the transport first should hopefully reduce the size of the later patches.
Sounds good :-)
metze
David Howells
maintainerQuoted 10 lines · Stefan Metzmacher
Quoted 7 lines
Quoted 3 lines
So the current situation is that we memcpy (at least) in
sendmsg()and with your patches we do a memcpy higher in the stack, but then useMSG_SPLICE_PAGESin order to do it twice. Is that correct?Not twice, no.
MSG_SPLICE_PAGESallowssendmsg()to splice the supplied pages
into thesk_buffsdirectly, thereby avoiding a copy in the TCP layer and cutting out the feeder loop in cifs.Yes, and we must be careful to not touch the pages after calling
sendmsg(MSG_SPLICE_PAGES).
Until we get a response from the server, yes, but for the protocol info that shouldn't be an issue. And if we're going to encrypt, we'll have to do a copy anyway for something like Write, but we can get the encryption algo to do that for us by giving it a separate destination buffer.
Quoted 4 lines
And unlike
MSG_ZEROCOPYtcp_sendmsg_locked()has no no structubuf_info*uarg whenMSG_SPLICE_PAGESis used and there's no way to know when the pages are no longer used by the tcp stack.
Correct (and this is something we'll need to address), but for the moment we can rely on page refcounts. MSG_SPLICE_PAGES takes a ref on each page - which is why you can't use it with slab memory. However, if we pass in netmem-allocated memory, that works by refcounting, so that should work.
Quoted 2 lines
Can you explain how/where we allocate the memory and where we unreference it in the caller of
sendmsg(MSG_SPLICE_PAGES).
Currently, we allocate the buffer in fs/netfs/buffer.c in netfs_alloc_bvecq_buffer(). That just bulk allocates a bunch of pages and adds them into a bvecq. As they're untyped pages, we can use the refcount. I want to allocate netmem instead, but I haven't done that yet.
We then call sendmsg(MSG_SPLICE_PAGES) and then drop our ref on the pages. TCP will have taken its own ref which it will drop in due course when the skbuffs are cleaned up.
David
Hi David,
Quoted 4 lines · David Howells
(3) Rewrite the base TCP transmission to be able to use
MSG_SPLICE_PAGES.(a) Copy all the data involved in a message into a big buffer formed of a sequence of pages attached to a bvecq.
Nice!
Quoted 3 lines
(b) If encrypting the message just encrypt this buffer. Converting this to a scatterlist is much simpler (and uses less memory) than encrypting from the protocol elements.
This could've been done a long ago, but since you're on it... crypto API supports in-place ops (src == dst), so you can save yet another allocation here.
This is also possible from SMB2 side because the spec says if encryption fails, the request should be failed as a whole.
Quoted 5 lines
(d) Compression should be a matter of vmap()'ing these pages to form the source buffer, allocating a second buffer of pages to form a dest buffer, also in a bvecq, vmapping that and then doing the compression. The first buffer can then just be replaced by the second.
OTOH, compression can't be in-place because SMB2 says that if compression fails, the original uncompressed request must be sent (i.e. src must be left untouched until smb_compress() finishes).
I don't know how relevant these comments are for you and your patches, but HTH.
Directly related to the patches: it would be great if you could handle commented out code, either by completely removing them, or by providing some in-code fallback mechanism (I'll reply to the patches).
Other than that, +1 for the cleanup/refactoring; I really like the new smb_message/transport infrastructure!
Cheers,
Enzo
David Howells
maintainerHi Enzo,
Quoted 9 lines
Quoted 5 lines
(d) Compression should be a matter of vmap()'ing these pages to form the source buffer, allocating a second buffer of pages to form a dest buffer, also in a bvecq, vmapping that and then doing the compression. The first buffer can then just be replaced by the second.
OTOH, compression can't be in-place because SMB2 says that if compression fails, the original uncompressed request must be sent (i.e. src must be left untouched until
smb_compress()finishes).
I've got a change which should achieve this, but it seems I can't test it. None of ksmbd, samba and azure seem to support it:-/
David
Quoted 8 lines · David Howells
Hi Enzo,
Quoted 6 lines
Quoted 5 lines
(d) Compression should be a matter of vmap()'ing these pages to form the source buffer, allocating a second buffer of pages to form a dest buffer, also in a bvecq, vmapping that and then doing the compression. The first buffer can then just be replaced by the second.
Quoted 6 lines
Quoted 3 lines
OTOH, compression can't be in-place because SMB2 says that if compression fails, the original uncompressed request must be sent (i.e. src must be left untouched until
smb_compress()finishes).I've got a change which should achieve this, but it seems I can't test it. None of ksmbd, samba and azure seem to support it:-/
Yes, Windows 11 or Windows Server 2022+ only.
Compression for ksmbd and samba have been on my TODO list for too long, I should get back to it :/
Anyway, if you want me to test, just send me the patches. I have your linux-fs remote as well, if that's easier.
Cheers,
Enzo
We should also retest compression with Linux client to current Windows
- IIRC there were still multiple things missing.
Patches / ideas welcome :)
Quoted 30 lines · Enzo Matsumiya
Quoted 8 lines · David Howells
Hi Enzo,
Quoted 6 lines
Quoted 5 lines
(d) Compression should be a matter of vmap()'ing these pages to form the source buffer, allocating a second buffer of pages to form a dest buffer, also in a bvecq, vmapping that and then doing the compression. The first buffer can then just be replaced by the second.
Quoted 6 lines
Quoted 3 lines
OTOH, compression can't be in-place because SMB2 says that if compression fails, the original uncompressed request must be sent (i.e. src must be left untouched until
smb_compress()finishes).I've got a change which should achieve this, but it seems I can't test it. None of ksmbd, samba and azure seem to support it:-/
Yes, Windows 11 or Windows Server 2022+ only.
Compression for ksmbd and samba have been on my TODO list for too long, I should get back to it :/
Anyway, if you want me to test, just send me the patches. I have your linux-fs remote as well, if that's easier.
Cheers,
Enzo
Signature · 3 lines
Thanks, Steve
David Howells
maintainerQuoted 2 lines · Enzo Matsumiya
Anyway, if you want me to test, just send me the patches. I have your linux-fs remote as well, if that's easier.
If you look at:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=cifs-experimental
You can see a patch with the subject "cifs: [!] FIX transport compression". Grab that and everything up to it.
I'm pretty certain it won't work, but I can't test it. Well, maybe I can force it on and look at the packet trace if wireshark can handle it.
Some things to note:
(1) In smb_compress(), netfs_alloc_bvecq_buffer() is used to allocate the destination buffer and attach it to a bvecq, which it also allocates. An iterator can be set on this to define part of the buffer to operate on.
(2) vmap_bvecq() is used to map the source and the destination buffers. It extracts the pages and then calls vmap() on them.
(3) Space for the compression header is allocated by smb_send_rqst() in the first bvecq slot along with the rfc1002 header and transform header (if sealing). A pointer is passed down to smb_compress().
(4) It attempts to adjust the values such that the compression header is included in the encrypted section if also sealing. However, it might be better to have smb_compress() place it in the output buffer.
(5) If compression is successful, smb_compress() switches the original bvecq and the output bvecq and moves the header segment from the original to the output.
(6) If the compression algo returns -EMSGSIZE, then the compression header is excluded from the header segment.
David
David Howells
maintainerHi Enzo,
I now have encryption, compression and encryption+compression all working :-)
I've pushed my patches here:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=cifs-experimental
It should work up to "cifs: Don't use corking".
Btw, is is_compressible() actually worth doing? It seems to copy a lot of data (up to 4M) to an extra buffer and then do various analyses on it, including doing a sort.
I need to extract a fix for collect_sample(), which I can do tomorrow, but it should look something like:
/*
* Collect some 2K samples with 2K gaps between.
*/
static int collect_sample(const struct iov_iter *source, ssize_t max, u8 *sample)
{
struct iov_iter iter = *source;
size_t s = 0;
while (iov_iter_count(&iter) >= SZ_2K) {
size_t part = umin(umin(iov_iter_count(&iter), SZ_2K), max);
size_t n;
n = copy_from_iter(sample + s, part, &iter);
if (n != part)
return -EFAULT;
s += n;
max -= n;
if (iov_iter_count(&iter) < PAGE_SIZE - SZ_2K)
break;
iov_iter_advance(&iter, SZ_2K);
}
return s;
}What's currently upstream won't work and may crash because it assumes that ITER_XARRAY is in use - which should now never be true.
Also, there's a bug in wireshark's LZ77 decoder. See attached patch.
David
epan/tvbuff_lz77.c +1 -1
@@ -68,7 +68,7 @@ static bool do_uncompress(tvbuff_t *tvb, int offset, int in_size, in_off +=2 ;if (match_len ==0 ) {/* This case isn't documented */ - match_len =tvb_get_letohs (tvb, offset+in_off); + match_len =tvb_get_letohl (tvb, offset+in_off); in_off +=4 ; }if (match_len <15 +7 )
Quoted 9 lines · David Howells
Hi Enzo,
I now have encryption, compression and encryption+compression all working :-)
I've pushed my patches here:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=cifs-experimental
It should work up to "cifs: Don't use corking".
Great! I'll try it out later.
Quoted 3 lines
Btw, is
is_compressible()actually worth doing? It seems to copy a lot of data (up to 4M) to an extra buffer and then do various analyses on it, including doing a sort.
Compression, as a whole, is actually only worth doing if one is paying more for network traffic than computing. is_compressible() tries to balance that to avoid a "compress/fail/send original" cycle, as it takes 0-4ms on a 4M payload (on my machine) whereas, without it, a failing cycle can take up to 40ms.
Quoted 31 lines
I need to extract a fix for
collect_sample(), which I can do tomorrow, but it should look something like:/*
* Collect some 2K samples with 2K gaps between.
*/
static intcollect_sample(const struct iov_iter *source, ssize_t max, u8 *sample){ struct iov_iter iter = *source; size_t s = 0; while (iov_iter_count(&iter) >= SZ_2K) { size_t part = umin(umin(iov_iter_count(&iter), SZ_2K), max); size_t n; n = copy_from_iter(sample + s, part, &iter); if (n != part) return -EFAULT; s += n; max -= n; if (iov_iter_count(&iter) < PAGE_SIZE - SZ_2K) break; iov_iter_advance(&iter, SZ_2K); } return s; }
Quoted 2 lines
What's currently upstream won't work and may crash because it assumes that
ITER_XARRAYis in use - which should now never be true.
Yes, compression was merged when that was the only case.
Quoted 1 line
Also, there's a bug in wireshark's LZ77 decoder. See attached patch.
Good catch :)
There are several, actually... if you vary the compression parameters defined (min len, min/max dist, hash log) within acceptable limits, you'll notice that, even though wireshark might show some as malformed packets, Windows is able to decode them just fine.
I really need to reserve some time to work on this again :(
Cheers,
Enzo