cifs: Miscellaneous prep patches for rewrite of I/O layer
Subsystems (5)
David Howells
maintainerv3 cover cifs: Miscellaneous prep patches for rewrite of I/O layer
Hi Steve,
Could you take these patches extracted from my I/O layer rewrite for the upcoming merge window. The performance change should be neutral, but it cleans up the code a bit.
(1) Do some minor cleanups so that patch 2 can be generated wholly by a script.
(2) Organise the declarations in the cifs client header files, naming the arguments the same as for the implementations, inserting divider comments, ordering them the same as they're found in the files and dividing them better between general, smb1 and smb2/3 categories.
The organisation is entirely scripted with the script in the second patch's commit message. The first patch does a bit of preparation to make sure that the second patch's output will build.
By filling in the argument names, this stops checkpatch moaning about unnamed arguments from search-and-replace changes in later patches. (Note that it doesn't fix func pointer declarations).
smbdirect is left untouched as requested by Stefan Metzmacher.
(3) Add the smb3_read_* tracepoints to SMB1 as well as SMB2/3.
(4) Use netfs_alloc/free_folioq_buffer() rather than cifs doing its own version.
(5) Rename struct mid_q_entry to smb_message. In my rewrite, smb_message will get allocated in the marshalling functions in smb2pdu.c and cifssmb.c rather than in transport.c and used to hand parameters down
- and so I think it could be better named for that.
(6) Remove the RFC1002 header from the smb_hdr struct so that it's consistent with SMB2/3. This allows I/O routines to be simplified and shared.
(7) Make SMB1's SendReceive() wrap cifs_send_recv() and thus share code
with SMB2/3.
(8) Clean up a bunch of extra kvec[] that were required for RFC1002 headers from SMB1's header struct.
(9) Replace SendReceiveBlockingLock() with SendReceive() plus flags.
(10) Remove the server pointer from smb_message. It can be passed down from the caller to all places that need it.
(11) Don't need state locking in smb2_get_mid_entry() as we're just doing a single read inside the lock. READ_ONCE() should suffice instead.
(12) Add a tracepoint to log EIO errors and up to a couple of bits of info for each to make it easier to find out why an EIO error happened when the system is very busy without introducing printk delays.
The patches can be found here also:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=cifs-cleanup
Thanks,
David
Changes
=======
ver #3)
- Rebased on the ksmbd-for-next branch.
- Add the patches to clean up the function prototypes in the headers.
- Don't touch smbdirect.
- Put prototypes into netlink.h and cached_dir.h rather than centralising them.
- Indent the arguments in the prototypes to the opening bracket + 1.
- Cleaned up most other checkpatch complaints.
- Added the EIO tracepoint patch to the end.
ver #2)
- Rebased on the ksmbd-for-next-next branch.
- Moved the patch to use netfs_alloc/free_folioq_buffer() down the stack.
David Howells (12):
cifs: Do some preparation prior to organising the function
declarations
cifs: Clean up declarations
cifs: Add the smb3_read_* tracepoints to SMB1
cifs: Use netfs_alloc/free_folioq_buffer()
cifs: Rename mid_q_entry to smb_message
cifs: Remove the RFC1002 header from smb_hdr
cifs: Make smb1's SendReceive() wrap cifs_send_recv()
cifs: Clean up some places where an extra kvec[] was required for
rfc1002
cifs: Replace SendReceiveBlockingLock() with SendReceive() plus flags
cifs: Remove the server pointer from smb_message
cifs: Don't need state locking in smb2_get_mid_entry()
cifs: Add a tracepoint to log EIO errors
fs/smb/client/cached_dir.c | 2 +- fs/smb/client/cached_dir.h | 37 +- fs/smb/client/cifs_debug.c | 51 +- fs/smb/client/cifs_debug.h | 15 +- fs/smb/client/cifs_spnego.h | 2 - fs/smb/client/cifs_swn.h | 15 +- fs/smb/client/cifs_unicode.c | 1 + fs/smb/client/cifs_unicode.h | 16 - fs/smb/client/cifsacl.c | 11 +- fs/smb/client/cifsencrypt.c | 83 +- fs/smb/client/cifsfs.c | 36 +- fs/smb/client/cifsfs.h | 64 -- fs/smb/client/cifsglob.h | 219 ++---- fs/smb/client/cifspdu.h | 13 +- fs/smb/client/cifsproto.h | 1340 +++++++++++++++++---------------- fs/smb/client/cifssmb.c | 954 +++++++++++++---------- fs/smb/client/cifstransport.c | 439 ++--------- fs/smb/client/compress.c | 23 +- fs/smb/client/compress.h | 20 +- fs/smb/client/connect.c | 200 ++--- fs/smb/client/dfs.h | 4 - fs/smb/client/dfs_cache.h | 16 - fs/smb/client/dir.c | 9 +- fs/smb/client/dns_resolve.h | 3 - fs/smb/client/file.c | 7 +- fs/smb/client/fs_context.c | 2 +- fs/smb/client/fs_context.h | 9 - fs/smb/client/fscache.h | 13 +- fs/smb/client/inode.c | 15 +- fs/smb/client/ioctl.c | 1 + fs/smb/client/link.c | 11 +- fs/smb/client/misc.c | 53 +- fs/smb/client/netlink.h | 8 +- fs/smb/client/netmisc.c | 21 +- fs/smb/client/nterr.h | 2 - fs/smb/client/ntlmssp.h | 13 - fs/smb/client/readdir.c | 2 +- fs/smb/client/reparse.c | 53 +- fs/smb/client/reparse.h | 11 - fs/smb/client/sess.c | 17 +- fs/smb/client/smb1ops.c | 116 ++- fs/smb/client/smb1proto.h | 227 ++++++ fs/smb/client/smb2file.c | 9 +- fs/smb/client/smb2inode.c | 12 +- fs/smb/client/smb2maperror.c | 3 + fs/smb/client/smb2misc.c | 11 +- fs/smb/client/smb2ops.c | 249 +++--- fs/smb/client/smb2pdu.c | 228 +++--- fs/smb/client/smb2proto.h | 516 ++++++------- fs/smb/client/smb2transport.c | 113 ++- fs/smb/client/smbdirect.c | 18 +- fs/smb/client/smbdirect.h | 1 + fs/smb/client/trace.h | 153 ++++ fs/smb/client/transport.c | 302 ++++---- fs/smb/client/xattr.c | 2 +- fs/smb/common/smb2pdu.h | 3 - fs/smb/common/smbglob.h | 1 - 57 files changed, 2913 insertions(+), 2862 deletions(-) create mode 100644 fs/smb/client/smb1proto.h
David Howells
maintainerPATCH v3 1/12 cifs: Do some preparation prior to organising the function declarations
Make some preparatory changes prior to running a script to organise the function declarations within the fs/smb/client/ headers. These include:
(1) Creating an smb1proto.h file and #including it in places that will need it. It will be populated by a script in a follow on patch.
(2) Insert a line saying "/* PROTOTYPES */" in the target headers to set the point at which prototypes should be inserted in that file.
(3) Remove "inline" from the dummy cifs_proc_init/clean() functions as they are in a .c file.
(4) Move should_compress()'s kdoc comment to the .c file and remove kdoc markers from the comments.
(5) Rename CIFS_ALLOW_INSECURE_LEGACY in #endif comments to have CONFIG_ on the front to allow the script to recognise it.
(6) Don't let comments have bare words at the left margin as that confused the simplistic function detection code in the script.
(7) Adjust some argument lists so that when the cleanup script is run they don't end up over 100 chars.
(8) Fix a few comments to have missing '*' added or the "*/" moved to their own lines so that checkpatch doesn't moan over the cleanup script patch.
--- fs/smb/client/cached_dir.h | 1 + fs/smb/client/cifs_debug.c | 4 ++-- fs/smb/client/cifs_debug.h | 2 ++ fs/smb/client/cifs_swn.h | 2 ++ fs/smb/client/cifs_unicode.c | 1 + fs/smb/client/cifsacl.c | 1 + fs/smb/client/cifsfs.c | 5 +++-- fs/smb/client/cifsglob.h | 8 +++++++- fs/smb/client/cifsproto.h | 14 ++------------ fs/smb/client/cifssmb.c | 1 + fs/smb/client/cifstransport.c | 1 + fs/smb/client/compress.c | 21 ++++++++++++++++++--- fs/smb/client/compress.h | 20 +++----------------- fs/smb/client/connect.c | 1 + fs/smb/client/dir.c | 3 ++- fs/smb/client/file.c | 1 + fs/smb/client/fs_context.c | 2 +- fs/smb/client/fscache.h | 4 +--- fs/smb/client/inode.c | 1 + fs/smb/client/ioctl.c | 1 + fs/smb/client/link.c | 1 + fs/smb/client/misc.c | 3 ++- fs/smb/client/netlink.h | 1 + fs/smb/client/netmisc.c | 2 +- fs/smb/client/sess.c | 1 + fs/smb/client/smb1ops.c | 2 ++ fs/smb/client/smb1proto.h | 20 ++++++++++++++++++++ fs/smb/client/smb2file.c | 3 ++- fs/smb/client/smb2pdu.c | 3 ++- fs/smb/client/smb2proto.h | 9 ++++----- fs/smb/client/smbdirect.h | 2 ++ 31 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 fs/smb/client/smb1proto.h
fs/smb/client/cached_dir.h +1 -0
@@ -77,6 +77,7 @@ is_valid_cached_dir(struct cached_fid *cfid)return cfid->time && cfid->has_lease; } +/* PROTOTYPES */ extern struct cached_fids *init_cached_dirs (void );extern void free_cached_dirs (struct cached_fids *cfids); extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
fs/smb/client/cifs_debug.c +2 -2
@@ -1307,11 +1307,11 @@ static const struct proc_ops cifs_mount_params_proc_ops = { };#else -inline void cifs_proc_init (void ) +void cifs_proc_init (void ) { } -inline void cifs_proc_clean (void ) +void cifs_proc_clean (void ) { }#endif /* PROC_FS */
fs/smb/client/cifs_debug.h +2 -0
@@ -14,6 +14,8 @@#define pr_fmt (fmt) "CIFS: " fmt +/* PROTOTYPES */ +void cifs_dump_mem (char *label,void *data,int length);void cifs_dump_detail (void *buf,struct TCP_Server_Info *ptcp_info);void cifs_dump_mids (struct TCP_Server_Info *);
fs/smb/client/cifs_swn.h +2 -0
@@ -14,6 +14,8 @@ struct sk_buff;struct genl_info ;#ifdef CONFIG_CIFS_SWN_UPCALL + +/* PROTOTYPES */ extern int cifs_swn_register (struct cifs_tcon *tcon);extern int cifs_swn_unregister (struct cifs_tcon *tcon);
fs/smb/client/cifs_unicode.c +1 -0
@@ -9,6 +9,7 @@#include "cifs_fs_sb.h" #include "cifs_unicode.h" #include "cifspdu.h" +#include "cifsproto.h" #include "cifsglob.h" #include "cifs_debug.h"
fs/smb/client/cifsacl.c +1 -0
@@ -21,6 +21,7 @@#include "cifsglob.h" #include "cifsacl.h" #include "cifsproto.h" +#include "smb1proto.h" #include "cifs_debug.h" #include "fs_context.h" #include "cifs_fs_sb.h"
fs/smb/client/cifsfs.c +3 -2
@@ -28,6 +28,8 @@#include <linux/splice.h> #include <linux/uuid.h> #include <linux/xattr.h> +#include <linux/mm.h> +#include <linux/key-type.h> #include <uapi/linux/magic.h> #include <net/ipv6.h> #include "cifsfs.h"
@@ -35,10 +37,9 @@#define DECLARE_GLOBALS_HERE #include "cifsglob.h" #include "cifsproto.h" +#include "smb2proto.h" #include "cifs_debug.h" #include "cifs_fs_sb.h" -#include <linux/mm.h> -#include <linux/key-type.h> #include "cifs_spnego.h" #include "fscache.h" #ifdef CONFIG_CIFS_DFS_UPCALL
fs/smb/client/cifsglob.h +7 -1
@@ -2114,7 +2114,7 @@ extern struct smb_version_operations smb1_operations;extern struct smb_version_values smb1_values;extern struct smb_version_operations smb20_operations;extern struct smb_version_values smb20_values; -#endif /* CIFS_ALLOW_INSECURE_LEGACY */ +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ extern struct smb_version_operations smb21_operations;extern struct smb_version_values smb21_values;extern struct smb_version_values smbdefault_values;
@@ -2369,4 +2369,10 @@ static inline void mid_execute_callback(struct mid_q_entry *mid) (le32_to_cpu((tcon)->fsAttrInfo.Attributes) & \ FILE_SUPPORTS_REPARSE_POINTS)) +struct cifs_calc_sig_ctx { +struct md5_ctx *md5; +struct hmac_sha256_ctx *hmac; +struct shash_desc *shash; +}; +#endif /* _CIFS_GLOB_H */
fs/smb/client/cifsproto.h +2 -12
@@ -9,7 +9,6 @@#define _CIFSPROTO_H#include <linux/nls.h> #include <linux/ctype.h> -#include "cifsglob.h" #include "trace.h" #ifdef CONFIG_CIFS_DFS_UPCALL #include "dfs_cache.h"
@@ -19,11 +18,7 @@ struct statfs;struct smb_rqst ;struct smb3_fs_context ; -/* -***************************************************************** -* All Prototypes -***************************************************************** -*/ +/* PROTOTYPES */ extern struct smb_hdr *cifs_buf_get (void );extern void cifs_buf_release (void *);
@@ -603,7 +598,7 @@ extern int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nls_codepage, int remap);extern int CIFSGetExtAttr (const unsigned int xid,struct cifs_tcon *tcon,const int netfid,__u64 *pExtAttrBits,__u64 *pMask); -#endif /* CIFS_ALLOW_INSECURE_LEGACY */ +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ extern void cifs_autodisable_serverino (struct cifs_sb_info *cifs_sb);extern bool couldbe_mf_symlink (const struct cifs_fattr *fattr); extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
@@ -635,11 +630,6 @@ int cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb, const unsigned char *path, char *pbuf, unsigned int *pbytes_written); -struct cifs_calc_sig_ctx { -struct md5_ctx *md5; -struct hmac_sha256_ctx *hmac; -struct shash_desc *shash; -};int __cifs_calc_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,char *signature,struct cifs_calc_sig_ctx *ctx); enum securityEnum cifs_select_sectype(struct TCP_Server_Info *,
fs/smb/client/cifssmb.c +1 -0
@@ -31,6 +31,7 @@#include "cifsglob.h" #include "cifsacl.h" #include "cifsproto.h" +#include "smb1proto.h" #include "cifs_unicode.h" #include "cifs_debug.h" #include "fscache.h"
fs/smb/client/cifstransport.c +1 -0
@@ -26,6 +26,7 @@#include "cifsglob.h" #include "cifsproto.h" #include "cifs_debug.h" +#include "smb1proto.h" #include "smb2proto.h" #include "smbdirect.h" #include "compress.h"
fs/smb/client/compress.c +18 -3
@@ -44,7 +44,7 @@ struct bucket {unsigned int count; }; -/** +/* * has_low_entropy() - Compute Shannon entropy of the sampled data. * @bkt: Bytes counts of the sample. * @slen: Size of the sample.
@@ -82,7 +82,7 @@ static bool has_low_entropy(struct bucket *bkt, size_t slen)#define BYTE_DIST_BAD 0#define BYTE_DIST_GOOD 1#define BYTE_DIST_MAYBE 2 -/** +/* * calc_byte_distribution() - Compute byte distribution on the sampled data. * @bkt: Byte counts of the sample. * @slen: Size of the sample.
@@ -182,7 +182,7 @@ static int collect_sample(const struct iov_iter *source, ssize_t max, u8 *samplereturn s; } -/** +/* * is_compressible() - Determines if a chunk of data is compressible. * @data: Iterator containing uncompressed data. *
@@ -261,6 +261,21 @@ static bool is_compressible(const struct iov_iter *data)return ret; } +/* +* 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 +* +* Return: true iff: +* - compression was successfully negotiated with server +* - server has enabled compression for the share +* - it's a read or write request +* - (write only) request length is >= SMB_COMPRESS_MIN_LEN +* - (write only) is_compressible() returns 1 +* +* Return false otherwise. +*/ bool should_compress (const struct cifs_tcon *tcon,const struct smb_rqst *rq) {const struct smb2_hdr *shdr = rq->rq_iov->iov_base;
fs/smb/client/compress.h +3 -17
@@ -29,26 +29,12 @@#ifdef CONFIG_CIFS_COMPRESSION typedef int (*compress_send_fn )(struct TCP_Server_Info *,int ,struct smb_rqst *); -int smb_compress (struct TCP_Server_Info *server,struct smb_rqst *rq,compress_send_fn send_fn); +/* PROTOTYPES */ -/** -* 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 -* -* Return: true iff: -* - compression was successfully negotiated with server -* - server has enabled compression for the share -* - it's a read or write request -* - (write only) request length is >= SMB_COMPRESS_MIN_LEN -* - (write only) is_compressible() returns 1 -* -* Return false otherwise. -*/ +int smb_compress (struct TCP_Server_Info *server,struct smb_rqst *rq,compress_send_fn send_fn);bool should_compress (const struct cifs_tcon *tcon,const struct smb_rqst *rq); -/** +/* * smb_compress_alg_valid() - Validate a compression algorithm. * @alg: Compression algorithm to check. * @valid_none: Conditional check whether NONE algorithm should be
fs/smb/client/connect.c +1 -0
@@ -42,6 +42,7 @@#include "nterr.h" #include "rfc1002pdu.h" #include "fscache.h" +#include "smb1proto.h" #include "smb2proto.h" #include "smbdirect.h" #include "dns_resolve.h"
fs/smb/client/dir.c +2 -1
@@ -17,6 +17,7 @@#include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h" +#include "smb1proto.h" #include "cifs_debug.h" #include "cifs_fs_sb.h" #include "cifs_unicode.h"
@@ -457,7 +458,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsignedint cifs_atomic_open (struct inode *inode,struct dentry *direntry, -struct file *file,unsigned oflags,umode_t mode) +struct file *file,unsigned int oflags,umode_t mode) {int rc;unsigned int xid;
fs/smb/client/file.c +1 -0
@@ -27,6 +27,7 @@#include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h" +#include "smb1proto.h" #include "smb2proto.h" #include "cifs_unicode.h" #include "cifs_debug.h"
fs/smb/client/fs_context.c +1 -1
@@ -505,7 +505,7 @@ cifs_parse_smb_version(struct fs_context *fc, char *value, struct smb3_fs_contexcase Smb_20:cifs_errorf (fc,"vers=2.0 mount not permitted when legacy dialects disabled\n" );return 1 ; -#endif /* CIFS_ALLOW_INSECURE_LEGACY */ +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ case Smb_21: ctx->ops = &smb21_operations; ctx->vals = &smb21_values;
fs/smb/client/fscache.h +1 -3
@@ -35,9 +35,7 @@ struct cifs_fscache_inode_coherency_data {#ifdef CONFIG_CIFS_FSCACHE -/* -* fscache.c -*/ +/* PROTOTYPES */ extern int cifs_fscache_get_super_cookie (struct cifs_tcon *);extern void cifs_fscache_release_super_cookie (struct cifs_tcon *);
fs/smb/client/inode.c +1 -0
@@ -18,6 +18,7 @@#include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h" +#include "smb1proto.h" #include "smb2proto.h" #include "cifs_debug.h" #include "cifs_fs_sb.h"
fs/smb/client/ioctl.c +1 -0
@@ -19,6 +19,7 @@#include "cifs_debug.h" #include "cifsfs.h" #include "cifs_ioctl.h" +#include "smb1proto.h" #include "smb2proto.h" #include "smb2glob.h" #include <linux/btrfs.h>
fs/smb/client/link.c +1 -0
@@ -17,6 +17,7 @@#include "cifs_debug.h" #include "cifs_fs_sb.h" #include "cifs_unicode.h" +#include "smb1proto.h" #include "smb2proto.h" #include "cifs_ioctl.h" #include "fs_context.h"
fs/smb/client/misc.c +2 -1
@@ -18,6 +18,7 @@#include "nterr.h" #include "cifs_unicode.h" #include "smb2pdu.h" +#include "smb2proto.h" #include "cifsfs.h" #ifdef CONFIG_CIFS_DFS_UPCALL #include "dns_resolve.h"
@@ -265,7 +266,7 @@ free_rsp_buf(int resp_buftype, void *rsp)/* NB: MID can not be set if treeCon not passed in, in that case it is responsibility of caller to set the mid */ void -header_assemble (struct smb_hdr *buffer,char smb_command/* command */ , +header_assemble (struct smb_hdr *buffer,char smb_command,const struct cifs_tcon *treeCon,int word_count/* length of fixed section (word count) in two byte units */ ) {
fs/smb/client/netlink.h +1 -0
@@ -10,6 +10,7 @@extern struct genl_family cifs_genl_family; +/* PROTOTYPES */ extern int cifs_genl_init (void );extern void cifs_genl_exit (void );
fs/smb/client/netmisc.c +1 -1
@@ -200,7 +200,7 @@ cifs_set_port(struct sockaddr *addr, const unsigned short int port) }/***************************************************************************** -convert a NT status code to a dos class/code +*convert a NT status code to a dos class/code *****************************************************************************/ /* NT status -> dos error map */ static const struct {
fs/smb/client/sess.c +1 -0
@@ -20,6 +20,7 @@#include <linux/version.h> #include "cifsfs.h" #include "cifs_spnego.h" +#include "smb1proto.h" #include "smb2proto.h" #include "fs_context.h"
fs/smb/client/smb1ops.c +2 -0
@@ -10,6 +10,8 @@#include <uapi/linux/magic.h> #include "cifsglob.h" #include "cifsproto.h" +#include "smb1proto.h" +#include "smb2proto.h" #include "cifs_debug.h" #include "cifspdu.h" #include "cifs_unicode.h"
fs/smb/client/smb1proto.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ +/* +* +* Copyright (c) International Business Machines Corp., 2002,2008 +* Author(s): Steve French ([email protected]) +* +*/ +#ifndef _SMB1PROTO_H +#define _SMB1PROTO_H + +#include <linux/nls.h> +#include <linux/ctype.h> +#include "trace.h" +#ifdef CONFIG_CIFS_DFS_UPCALL +#include "dfs_cache.h" +#endif + +/* PROTOTYPES */ + +#endif /* _SMB1PROTO_H */
fs/smb/client/smb2file.c +2 -1
@@ -140,7 +140,8 @@ int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb, const struct kvec cifs_sb); } -int smb2_open_file (const unsigned int xid,struct cifs_open_parms *oparms,__u32 *oplock,void *buf) +int smb2_open_file (const unsigned int xid,struct cifs_open_parms *oparms, +__u32 *oplock,void *buf) {int rc;__le16 *smb2_path;
fs/smb/client/smb2pdu.c +2 -1
@@ -3913,7 +3913,8 @@ int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,/* currently unused, as now we are doing compounding instead (see smb311_posix_query_path_info) */ int SMB311_posix_query_info (const unsigned int xid,struct cifs_tcon *tcon, -u64 persistent_fid,u64 volatile_fid,struct smb311_posix_qinfo *data,u32 *plen) +u64 persistent_fid,u64 volatile_fid, +struct smb311_posix_qinfo *data,u32 *plen) {size_t output_len =sizeof (struct smb311_posix_qinfo *) + (sizeof (struct smb_sid ) *2 ) + (PATH_MAX *2 );
fs/smb/client/smb2proto.h +4 -5
@@ -9,17 +9,16 @@*/ #ifndef _SMB2PROTO_H#define _SMB2PROTO_H +#include <linux/nls.h> #include <linux/key-type.h> +#include "cached_dir.h" struct statfs ;struct smb_rqst ; -/* -***************************************************************** -* All Prototypes -***************************************************************** -*/ +/* PROTOTYPES */ +extern int map_smb2_to_linux_error (char *buf,bool log_err);extern int smb2_check_message (char *buf,unsigned int length,struct TCP_Server_Info *server);
fs/smb/client/smbdirect.h +2 -0
@@ -62,6 +62,8 @@ struct smbdirect_mr_io *smbd_register_mr( bool writing, bool need_invalidate);void smbd_deregister_mr (struct smbdirect_mr_io *mr); +/* PROTOTYPES */ +#else #define cifs_rdma_enabled (server) 0struct smbd_connection {};
David Howells
maintainerPATCH v3 2/12 cifs: Clean up declarations
In reply to David HowellsUse this script, run as "cifs_proto.pl fs/smb/client/*.[ch]" to organise the function declarations. Most of the declarations will be split between cifsproto.h, smb1proto.h and smb2proto.h but with exceptions for compress.h, fscache.h and cifs_swn.h.
The declarations are inserted into each target proto file in place of line containing a comment of the form "/* PROTOTYPES */". The old header declarations are removed. Note that this script, as it stands, cannot be used again on its output as it inserts dividing comments to categorise the prototypes list by source filename.
The declarations are copied from the .c file, so that the argument names will match and ordered by appearance in the .c file.
Note that this must be applied on top of the preparatory patch otherwise it won't work.
use strict;
unless (@ARGV) {
die "Usage: $0 <c_file1> [<c_file2> ...]\n";
}my $filename = "-";
my $lineno = 0;
my @proto = "";
my @smb1proto = "";
my @smb2proto = "";
my @smbdirect = "";
my @netlink = "";
my @cached_dir = "";
my @cifs_debug = "";
my @compress = "";
my @fscache = "";
my @swn = "";
my %funcs = ();
sub error(@) {
print STDERR $filename, ":", $lineno, ": ", @_, "\n";
exit(1);
}
sub pad($) {
my ($line) = @_;
my @lines = split(/[\n]/, $line);
return $line if ($#lines <= 0);
for (my $i = 0; $i <= $#lines; $i++) {
$lines[$i] =~ s/^[ \t]+//;
}
my $b = index($lines[0], "(");
return $line if ($b < 0);
my $indent = "";
$b++;
$indent .= "\t" x ($b / 8);
$indent .= " " x ($b % 8);
for (my $i = 1; $i <= $#lines; $i++) {
$lines[$i] = $indent . $lines[$i];
}
my $rev = join("\n", @lines);
return $rev;
}
foreach my $file (@ARGV) {
# Open the file for reading.
next if $file =~ /trace[.]h$/;
next if $file =~ /smbdirect[.][ch]$/;
open my $fh, "<$file"
or die "Could not open file '$file'";
$filename = $file;
$lineno = 0;
my $state = 0;
my $qual = "";
my $type = "";
my $func = "";
my $funcdef = "";
my $bracket = 0;
my $comment = 0;
my $filemarker = 0;
my $insecure = 0;
my $header = 0;
my $inline = 0;
my $f_content = "";
my $copy = "";
my $config = "";
$header = 1 if ($file =~ m!.h$!);
$insecure = 1 if ($file =~ m!/smb1ops.c|/cifssmb.c|/cifstransport.c!);
foreach my $line (<$fh>) {
$lineno++;
$copy .= $line;
unless ($line) {
$f_content .= $copy;
$copy = "";
next;
}
if ($comment) {
$comment = 0 if ($line =~ m![*]/!);
$f_content .= $copy;
$copy = "";
next;
}
if ($line =~ /^[#]/) {
# if ($line =~ /ifdef.*CONFIG_CIFS_ALLOW_INSECURE_LEGACY/) {
# $insecure++;
# } elsif ($line =~ /endif.*CONFIG_CIFS_ALLOW_INSECURE_LEGACY/) {
# $insecure--;
# }
if ($header) {
if ($line =~ /ifdef.*(CONFIG_[A-Z0-9_])/) {
error("multiconfig") if $config;
$config = $1;
$insecure++ if ($config eq "CONFIG_CIFS_ALLOW_INSECURE_LEGACY");
} elsif ($line =~ /endif/) {
$insecure-- if ($config eq "CONFIG_CIFS_ALLOW_INSECURE_LEGACY");
$config = "";
}
}
$f_content .= $copy;
$copy = "";
next;
}
if ($line =~ /^[{]/ ||
$line =~ /##/ ||
$line =~ /^[_a-z0-9A-Z]+:$/ || # goto label
$line =~ /^do [{]/ ||
$line =~ m!^//!) {
$f_content .= $copy;
$copy = "";
next;
}
if ($line =~ m!^/[*]!) {
$comment = 1 unless ($line =~ m![*]/!);
$f_content .= $copy;
$copy = "";
next;
}
if ($line =~ /^[}]/) {
$type = "";
$qual = "";
$func = "";
$funcdef = "";
$f_content .= $copy;
$copy = "";
next;
}
if ($line =~ /^typedef/) {
$type = "";
$qual = "";
$func = "";
$funcdef = "";
$f_content .= $copy;
$copy = "";
next;
}
if ($line =~ /^(static|extern|inline|noinline|noinline_for_stack|__always_inline)\W/) {
error("Unexpected qualifier '$1'") if ($state != 0);
while ($line =~ /^(static|extern|inline|noinline|noinline_for_stack|__always_inline)\W/) {
$qual .= $1 . " ";
$inline = 1 if ($1 eq "inline");
$inline = 1 if ($1 eq "__always_inline");
$line = substr($line, length($1));
$line =~ s/^\s+//;
}
}
if ($state == 0) {
if ($line =~ /^\s/) {
$f_content .= $copy;
$copy = "";
next;
}
while ($line =~ /^(unsigned|signed|bool|char|short|int|long|void|const|volatile|(struct|union|enum)\s+[_a-zA-Z][_a-zA-Z0-9]*|[*]|__init|__exit|__le16|__le32|__le64|__be16|__be32|__be64)/) {
$type .= " " if $type;
$type .= $1;
$line = substr($line, length($1));
$line =~ s/^\s+//;
}
if ($line =~ /^struct [{]/) {
$type = "";
$qual = "";
$func = "";
$funcdef = "";
$f_content .= $copy;
$copy = "";
next;
}
if (index($line, "=") >= 0) {
$type = "";
$qual = "";
$func = "";
$funcdef = "";
$f_content .= $copy;
$copy = "";
next;
}
while ($line =~ /(^[_a-zA-Z][_a-zA-Z0-9]*)/) {
my $name = $1;
$line = substr($line, length($name));
next if ($line =~ /^[{]/);
$line =~ s/^\s+//;
if (substr($line, 0, 1) eq "(") {
$state = 1;
$line = substr($line, 1);
$func = $name;
$funcdef = $qual . $type . " " . $func . "(";
$funcdef =~ s/[*] /*/;
$bracket = 1;
last;
} elsif (substr($line, 0, 1) eq "[") {
last;
} elsif (substr($line, 0, 1) eq ";") {
last;
} else {
if ($type) {
if (index($line, ";") >= 0 && index($line, "(") == -1) {
last;
}
error("Unexpected name '$name' after '$type'");
}
$type .= " " if $type;
$type .= $name;
if ($line =~ /^(\s*[*]+)/) {
my $ptr = $1;
$type .= $ptr;
$line = substr($line, length($ptr));
}
}
}
}
if ($state == 1) {
my $o;
my $c;
while ($o = index($line, "("),
$c = index($line, ")"), 1) {
my $b;
if ($o == -1) {
if ($c == -1) {
$funcdef .= $line;
last;
} else {
$b = $c;
$bracket--;
unless ($bracket) {
$funcdef .= substr($line, 0, $b + 1);
$line = substr($line, $b + 1);
$state = 2;
last;
}
}
} else {
$b = $o;
if ($c == -1) {
$bracket++;
} elsif ($c < $o) {
$b = $c;
$bracket--;
unless ($bracket) {
$funcdef .= substr($line, 0, $b + 1);
$line = substr($line, $b + 1);
$state = 2;
last;
}
} else {
$bracket++;
}
}
$funcdef .= substr($line, 0, $b);
$line = substr($line, $b + 1);
}
}
if ($state == 2) {
$inline = 1 if ($qual =~ /inline/);
if (!$header &&
$qual !~ /static/ &&
$func ne "__acquires" &&
$func ne "__releases" &&
$func ne "module_init" &&
$func ne "module_exit" &&
$func ne "module_param" &&
$func ne "module_param_call" &&
$func ne "PROC_FILE_DEFINE" &&
$func !~ /MODULE_/ &&
$func !~ /DEFINE_/) {
my $p;
if ($insecure) {
$p = \@smb1proto;
} elsif ($file =~ m!/smb2!) {
$p = \@smb2proto;
} elsif ($file =~ m!/smbdirect.c!) {
$p = \@smbdirect;
} elsif ($file =~ m!/netlink.c!) {
$p = \@netlink;
} elsif ($file =~ m!/compress.c!) {
$p = \@compress;
} elsif ($file =~ m!/cached_dir.c!) {
$p = \@cached_dir;
} elsif ($file =~ m!/cifs_debug.c!) {
$p = \@cifs_debug;
} elsif ($file =~ m!/fscache.c!) {
$p = \@fscache;
} elsif ($file =~ m!/cifs_swn.c!) {
$p = \@swn;
} else {
$p = \@proto;
}
unless ($filemarker) {
my $n = $file;
$n =~ s!.*/!!;
push @{$p}, "\n/*\n * $n\n */\n";
$filemarker = 1;
}
push @{$p}, pad($funcdef) . ";\n";
} elsif (!$header || $inline) {
$f_content .= $copy;
}
$funcdef = "";
$type = "";
$qual = "";
$func = "";
$inline = 0;
$state = 0;
$copy = "";
}
if ($line =~ /;/) {
$type = "";
$qual = "";
$func = "";
$funcdef = "";
$state = 0;
$f_content .= $copy;
$copy = "";
}
}
close($fh);
if ($header) {
$f_content =~ s/[\n]{3,}/\n\n/g;
open my $fh, ">$file"
or die "Could not open file '$file' for writing";
print($fh $f_content) or die $file;
close($fh) or die $file;
}
}
sub insert_protos($$)
{
my ($file, $protos) = @_;
open my $fh, "<$file"
or die "Could not open file '$file'";
my @lines = <$fh>;
close($fh);
open $fh, ">$file"
or die "Could not open file '$file' for writing";
foreach my $line (@lines) {
if ($line eq "/* PROTOTYPES */\n") {
print($fh @{$protos}) or die $file;
} else {
print($fh $line) or die $file;
}
}
close($fh) or die $file;
}insert_protos("fs/smb/client/cifsproto.h", \@proto); insert_protos("fs/smb/client/smb1proto.h", \@smb1proto); insert_protos("fs/smb/client/smb2proto.h", \@smb2proto); insert_protos("fs/smb/client/smbdirect.h", \@smbdirect); insert_protos("fs/smb/client/netlink.h", \@netlink); insert_protos("fs/smb/client/compress.h", \@compress); insert_protos("fs/smb/client/cached_dir.h", \@cached_dir); insert_protos("fs/smb/client/cifs_debug.h", \@cifs_debug); insert_protos("fs/smb/client/fscache.h", \@fscache); insert_protos("fs/smb/client/cifs_swn.h", \@swn);
--- fs/smb/client/cached_dir.h | 38 +- fs/smb/client/cifs_debug.h | 15 +- fs/smb/client/cifs_spnego.h | 2 - fs/smb/client/cifs_swn.h | 17 +- fs/smb/client/cifs_unicode.h | 16 - fs/smb/client/cifsfs.h | 64 -- fs/smb/client/cifsglob.h | 22 - fs/smb/client/cifspdu.h | 11 - fs/smb/client/cifsproto.h | 1213 ++++++++++++++++------------------ fs/smb/client/compress.h | 6 +- fs/smb/client/dfs.h | 4 - fs/smb/client/dfs_cache.h | 16 - fs/smb/client/dns_resolve.h | 3 - fs/smb/client/fs_context.h | 9 - fs/smb/client/fscache.h | 15 +- fs/smb/client/netlink.h | 9 +- fs/smb/client/nterr.h | 2 - fs/smb/client/ntlmssp.h | 13 - fs/smb/client/reparse.h | 11 - fs/smb/client/smb1proto.h | 212 +++++- fs/smb/client/smb2proto.h | 512 +++++++------- fs/smb/client/smbdirect.h | 1 - 22 files changed, 1092 insertions(+), 1119 deletions(-)
fs/smb/client/cached_dir.h +19 -19
@@ -8,7 +8,6 @@ #ifndef _CACHED_DIR_H #define _CACHED_DIR_H - struct cached_dirent { struct list_head entry; char *name;
@@ -77,23 +76,24 @@ is_valid_cached_dir(struct cached_fid *cfid) return cfid->time && cfid->has_lease; } -/* PROTOTYPES */ -extern struct cached_fids *init_cached_dirs (void ); -extern void free_cached_dirs (struct cached_fids *cfids); -extern int open_cached_dir (unsigned int xid,struct cifs_tcon *tcon, -const char *path, -struct cifs_sb_info *cifs_sb, -bool lookup_only,struct cached_fid **cfid); -extern int open_cached_dir_by_dentry (struct cifs_tcon *tcon, -struct dentry *dentry, -struct cached_fid **cfid); -extern void close_cached_dir (struct cached_fid *cfid); -extern void drop_cached_dir_by_name (const unsigned int xid, -struct cifs_tcon *tcon, -const char *name, -struct cifs_sb_info *cifs_sb); -extern void close_all_cached_dirs (struct cifs_sb_info *cifs_sb); -extern void invalidate_all_cached_dirs (struct cifs_tcon *tcon); -extern bool cached_dir_lease_break (struct cifs_tcon *tcon,__u8 lease_key[16 ]); + +/* +* cached_dir.c +*/ +int open_cached_dir (unsigned int xid,struct cifs_tcon *tcon, +const char *path, +struct cifs_sb_info *cifs_sb, +bool lookup_only,struct cached_fid **ret_cfid); +int open_cached_dir_by_dentry (struct cifs_tcon *tcon, +struct dentry *dentry, +struct cached_fid **ret_cfid); +void drop_cached_dir_by_name (const unsigned int xid,struct cifs_tcon *tcon, +const char *name,struct cifs_sb_info *cifs_sb); +void close_cached_dir (struct cached_fid *cfid); +void close_all_cached_dirs (struct cifs_sb_info *cifs_sb); +void invalidate_all_cached_dirs (struct cifs_tcon *tcon); +bool cached_dir_lease_break (struct cifs_tcon *tcon,__u8 lease_key[16 ]); +struct cached_fids *init_cached_dirs (void ); +void free_cached_dirs (struct cached_fids *cfids);#endif /* _CACHED_DIR_H */
fs/smb/client/cifs_debug.h +10 -5
@@ -14,13 +14,19 @@#define pr_fmt (fmt) "CIFS: " fmt -/* PROTOTYPES */ +/* +* cifs_debug.c +*/ void cifs_dump_mem (char *label,void *data,int length); -void cifs_dump_detail (void *buf,struct TCP_Server_Info *ptcp_info); -void cifs_dump_mids (struct TCP_Server_Info *); +void cifs_dump_detail (void *buf,struct TCP_Server_Info *server); +void cifs_dump_mids (struct TCP_Server_Info *server); +void cifs_proc_init (void ); +void cifs_proc_clean (void ); +void cifs_proc_init (void ); +void cifs_proc_clean (void ); +extern bool traceSMB;/* flag which enables the function below */ -void dump_smb (void *,int );#define CIFS_INFO 0x01#define CIFS_RC 0x02#define CIFS_TIMER 0x04
@@ -41,7 +47,6 @@ extern int cifsFYI;*/ #ifdef CONFIG_CIFS_DEBUG -/* * When adding tracepoints and debug messages we have various choices. * Some considerations:
fs/smb/client/cifs_spnego.h +0 -2
@@ -29,8 +29,6 @@ struct cifs_spnego_msg {#ifdef __KERNEL__extern struct key_type cifs_spnego_key_type; -extern struct key *cifs_get_spnego_key (struct cifs_ses *sesInfo, -struct TCP_Server_Info *server);#endif /* KERNEL */ #endif /* _CIFS_SPNEGO_H */
fs/smb/client/cifs_swn.h +8 -9
@@ -15,16 +15,15 @@ struct genl_info;#ifdef CONFIG_CIFS_SWN_UPCALL -/* PROTOTYPES */ -extern int cifs_swn_register (struct cifs_tcon *tcon); -extern int cifs_swn_unregister (struct cifs_tcon *tcon); - -extern int cifs_swn_notify (struct sk_buff *skb,struct genl_info *info); - -extern void cifs_swn_dump (struct seq_file *m); - -extern void cifs_swn_check (void ); +/* +* cifs_swn.c +*/ +int cifs_swn_notify (struct sk_buff *skb,struct genl_info *info); +int cifs_swn_register (struct cifs_tcon *tcon); +int cifs_swn_unregister (struct cifs_tcon *tcon); +void cifs_swn_dump (struct seq_file *m); +void cifs_swn_check (void );static inline bool cifs_swn_set_server_dstaddr (struct TCP_Server_Info *server) {
fs/smb/client/cifs_unicode.h +0 -16
@@ -55,22 +55,6 @@#define SFU_MAP_UNI_RSVD 2#ifdef __KERNEL__ -int cifs_from_utf16 (char *to,const __le16 *from,int tolen,int fromlen, -const struct nls_table *cp,int map_type); -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 *); -char *cifs_strndup_from_utf16 (const char *src,const int maxlen, -const bool is_unicode, -const struct nls_table *codepage); -extern int cifsConvertToUTF16 (__le16 *target,const char *source,int maxlen, -const struct nls_table *cp,int mapChars); -extern int cifs_remap (struct cifs_sb_info *cifs_sb); -extern __le16 *cifs_strndup_to_utf16 (const char *src,const int maxlen, -int *utf16_len,const struct nls_table *cp, -int remap);#endif -wchar_t cifs_toupper (wchar_t in); -#endif /* _CIFS_UNICODE_H */
fs/smb/client/cifsfs.h +0 -64
100 lines not on this page · raw message
fs/smb/client/cifsglob.h +0 -22
@@ -1325,9 +1325,6 @@ struct tcon_link {struct cifs_tcon *tl_tcon; }; -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) {
@@ -1340,8 +1337,6 @@ cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)return cifs_sb->master_tlink; } -extern void cifs_put_tlink (struct tcon_link *tlink); -static inline struct tcon_link *cifs_get_tlink (struct tcon_link *tlink) {
@@ -1351,7 +1346,6 @@ cifs_get_tlink(struct tcon_link *tlink) }/* This function is always expected to succeed */ -extern struct cifs_tcon *cifs_sb_master_tcon (struct cifs_sb_info *cifs_sb);#define CIFS_OPLOCK_NO_CHANGE 0xfe
@@ -1523,16 +1517,6 @@ cifsFileInfo_get_locked(struct cifsFileInfo *cifs_file) ++cifs_file->count; } -struct cifsFileInfo *cifsFileInfo_get (struct cifsFileInfo *cifs_file); -void _cifsFileInfo_put (struct cifsFileInfo *cifs_file,bool wait_oplock_hdlr, -bool offload); -void cifsFileInfo_put (struct cifsFileInfo *cifs_file); -int cifs_file_flush (const unsigned int xid,struct inode *inode, -struct cifsFileInfo *cfile); -int cifs_file_set_size (const unsigned int xid,struct dentry *dentry, -const char *full_path,struct cifsFileInfo *open_file, -loff_t size); -#define CIFS_CACHE_READ_FLG 1#define CIFS_CACHE_HANDLE_FLG 2#define CIFS_CACHE_RH_FLG (CIFS_CACHE_READ_FLG | CIFS_CACHE_HANDLE_FLG)
@@ -1646,7 +1630,6 @@ static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,spin_unlock (&tcon->stat_lock); } -/* * This is the prototype for the mid receive function. This function is for * receiving the rest of the SMB frame, starting with the WordCount (which is
@@ -1853,7 +1836,6 @@ static inline bool is_replayable_error(int error)return false; } -/* cifs_get_writable_file() flags */ enum cifs_writable_file_flags {FIND_WR_ANY =0U ,
@@ -2088,10 +2070,6 @@ extern unsigned int dir_cache_timeout; /* max time for directory lease caching oextern bool disable_legacy_dialects;/* forbid vers=1.0 and vers=2.0 mounts */ extern atomic_t mid_count; -void cifs_oplock_break (struct work_struct *work); -void cifs_queue_oplock_break (struct cifsFileInfo *cfile); -void smb2_deferred_work_close (struct work_struct *work); -extern const struct slow_work_ops cifs_oplock_break_ops;extern struct workqueue_struct *cifsiod_wq;extern struct workqueue_struct *decrypt_wq;
fs/smb/client/cifspdu.h +0 -11
@@ -577,10 +577,8 @@ struct ntlmv2_resp {/* array of name entries could follow ending in minimum 4 byte struct */ } __packed; -#define CIFS_NETWORK_OPSYS "CIFS VFS Client for Linux" -/* * Capabilities bits (for NTLM SessSetup request) * See MS-CIFS 2.2.4.52.2
@@ -636,7 +634,6 @@ typedef struct smb_com_tconx_rsp_ext {/* STRING NativeFileSystem */ }__packed TCONX_RSP_EXT ; -/* tree connect Flags */ #define DISCONNECT_TID 0x0001#define TCON_EXTENDED_SIGNATURES 0x0004
@@ -836,7 +833,6 @@ typedef struct smb_com_open_rsp_ext {__u16 ByteCount;/* bct = 0 */ }__packed OPEN_RSP_EXT ; -/* format of legacy open request */ typedef struct smb_com_openx_req { struct smb_hdr hdr; /* wct = 15 */
@@ -1293,7 +1289,6 @@ typedef struct smb_com_transaction_qsec_req {__le32 AclFlags; }__packed QUERY_SEC_DESC_REQ ; - typedef struct smb_com_transaction_ssec_req { struct smb_hdr hdr; /* wct = 19 */ __u8 MaxSetupCount;
@@ -1488,7 +1483,6 @@ struct smb_t2_rsp {#define SMB_QUERY_FILE_MODE_INFO 0x3f8#define SMB_QUERY_FILE_ALGN_INFO 0x3f9 -#define SMB_SET_FILE_BASIC_INFO 0x101#define SMB_SET_FILE_DISPOSITION_INFO 0x102#define SMB_SET_FILE_ALLOCATION_INFO 0x103
@@ -2031,7 +2025,6 @@ typedef struct {#define CIFS_UNIX_CAP_MASK 0x00000013#endif /* CONFIG_CIFS_POSIX */ -#define CIFS_POSIX_EXTENSIONS 0x00000010/* support for new QFSInfo */ /* DeviceType Flags */
@@ -2103,7 +2096,6 @@ typedef struct {__u16 Pad; }__packed FILE_STANDARD_INFO ;/* level 0x102 QPathInfo */ -/* defines for enumerating possible values of the Unix type field below */ #define UNIX_FILE 0#define UNIX_DIR 1
@@ -2278,7 +2270,6 @@ struct file_attrib_tag {__le32 ReparseTag; } __packed;/* level 0x40b */ -/********************************************************/ /* FindFirst/FindNext transact2 data buffer formats */ /********************************************************/
@@ -2308,7 +2299,6 @@ typedef struct {char FileName[]; }__packed FIND_FILE_STANDARD_INFO ;/* level 0x1 FF resp data */ -struct fea {unsigned char EA_flags;__u8 name_len;
@@ -2331,7 +2321,6 @@ struct data_blob {void (*free) (struct data_blob *data_blob); } __packed; -#ifdef CONFIG_CIFS_POSIX /* For better POSIX semantics from Linux client, (even better
fs/smb/client/cifsproto.h +579 -634
1,257 lines not on this page · raw message
fs/smb/client/compress.h +4 -2
@@ -29,10 +29,12 @@#ifdef CONFIG_CIFS_COMPRESSION typedef int (*compress_send_fn )(struct TCP_Server_Info *,int ,struct smb_rqst *); -/* PROTOTYPES */ -int smb_compress (struct TCP_Server_Info *server,struct smb_rqst *rq,compress_send_fn send_fn); +/* +* compress.c +*/ bool should_compress (const struct cifs_tcon *tcon,const struct smb_rqst *rq); +int smb_compress (struct TCP_Server_Info *server,struct smb_rqst *rq,compress_send_fn send_fn);/* * smb_compress_alg_valid() - Validate a compression algorithm.
fs/smb/client/dfs.h +0 -4
@@ -151,10 +151,6 @@ static inline void ref_walk_mark_end(struct dfs_ref_walk *rw) ref->tit =ERR_PTR (-ENOENT );/* end marker */ } -int dfs_parse_target_referral (const char *full_path,const struct dfs_info3_param *ref, -struct smb3_fs_context *ctx); -int dfs_mount_share (struct cifs_mount_ctx *mnt_ctx); -static inline char *dfs_get_path (struct cifs_sb_info *cifs_sb,const char *path) {return dfs_cache_canonical_path (path, cifs_sb->local_nls,cifs_remap (cifs_sb));
fs/smb/client/dfs_cache.h +0 -16
@@ -33,24 +33,8 @@ struct dfs_cache_tgt_iterator {struct list_head it_list; }; -int dfs_cache_init (void ); -void dfs_cache_destroy (void );extern const struct proc_ops dfscache_proc_ops; -int dfs_cache_find (const unsigned int xid,struct cifs_ses *ses,const struct nls_table *cp, -int remap,const char *path,struct dfs_info3_param *ref, -struct dfs_cache_tgt_list *tgt_list); -int dfs_cache_noreq_find (const char *path,struct dfs_info3_param *ref, -struct dfs_cache_tgt_list *tgt_list); -void dfs_cache_noreq_update_tgthint (const char *path,const struct dfs_cache_tgt_iterator *it); -int dfs_cache_get_tgt_referral (const char *path,const struct dfs_cache_tgt_iterator *it, -struct dfs_info3_param *ref); -int dfs_cache_get_tgt_share (char *path,const struct dfs_cache_tgt_iterator *it,char **share, -char **prefix); -char *dfs_cache_canonical_path (const char *path,const struct nls_table *cp,int remap); -int dfs_cache_remount_fs (struct cifs_sb_info *cifs_sb); -void dfs_cache_refresh (struct work_struct *work); -static inline struct dfs_cache_tgt_iterator *dfs_cache_get_next_tgt (struct dfs_cache_tgt_list *tl,struct dfs_cache_tgt_iterator *it)
fs/smb/client/dns_resolve.h +0 -3
@@ -17,9 +17,6 @@#ifdef __KERNEL__ -int dns_resolve_name (const char *dom,const char *name, -size_t namelen,struct sockaddr *ip_addr); -static inline int dns_resolve_unc (const char *dom,const char *unc,struct sockaddr *ip_addr) {
fs/smb/client/fs_context.h +0 -9
@@ -359,26 +359,17 @@ static inline enum cifs_symlink_type cifs_symlink_type(struct cifs_sb_info *cifsreturn CIFS_SYMLINK_TYPE_NONE ; } -extern int smb3_init_fs_context (struct fs_context *fc); -extern void smb3_cleanup_fs_context_contents (struct smb3_fs_context *ctx); -extern void smb3_cleanup_fs_context (struct smb3_fs_context *ctx); -static inline struct smb3_fs_context *smb3_fc2context (const struct fs_context *fc) {return fc->fs_private; } -extern int smb3_fs_context_dup (struct smb3_fs_context *new_ctx,struct smb3_fs_context *ctx); -extern int smb3_sync_session_ctx_passwords (struct cifs_sb_info *cifs_sb,struct cifs_ses *ses); -extern void smb3_update_mnt_flags (struct cifs_sb_info *cifs_sb); -/* * max deferred close timeout (jiffies) - 2^30 */ #define SMB3_MAX_DCLOSETIMEO (1 << 30)#define SMB3_DEF_DCLOSETIMEO (1 * HZ)/* even 1 sec enough to help eg open/write/close/open/read */ #define MAX_CACHED_FIDS 16 -extern char *cifs_sanitize_prepath (char *prepath,gfp_t gfp);extern struct mutex cifs_mount_mutex;
fs/smb/client/fscache.h +8 -7
@@ -35,13 +35,15 @@ struct cifs_fscache_inode_coherency_data {#ifdef CONFIG_CIFS_FSCACHE -/* PROTOTYPES */ -extern int cifs_fscache_get_super_cookie (struct cifs_tcon *); -extern void cifs_fscache_release_super_cookie (struct cifs_tcon *); -extern void cifs_fscache_get_inode_cookie (struct inode *inode); -extern void cifs_fscache_release_inode_cookie (struct inode *); -extern void cifs_fscache_unuse_inode_cookie (struct inode *inode,bool update); +/* +* fscache.c +*/ +int cifs_fscache_get_super_cookie (struct cifs_tcon *tcon); +void cifs_fscache_release_super_cookie (struct cifs_tcon *tcon); +void cifs_fscache_get_inode_cookie (struct inode *inode); +void cifs_fscache_unuse_inode_cookie (struct inode *inode,bool update); +void cifs_fscache_release_inode_cookie (struct inode *inode); static inline void cifs_fscache_fill_coherency(struct inode *inode,
@@ -57,7 +59,6 @@ void cifs_fscache_fill_coherency(struct inode *inode, cd->last_change_time_nsec =cpu_to_le32 (ctime.tv_nsec); } -static inline struct fscache_cookie *cifs_inode_cookie (struct inode *inode) {return netfs_i_cookie (&CIFS_I (inode)->netfs);
fs/smb/client/netlink.h +6 -3
@@ -10,8 +10,11 @@extern struct genl_family cifs_genl_family; -/* PROTOTYPES */ -extern int cifs_genl_init (void ); -extern void cifs_genl_exit (void ); + +/* +* netlink.c +*/ +int cifs_genl_init (void ); +void cifs_genl_exit (void );#endif /* _CIFS_NETLINK_H */
fs/smb/client/nterr.h +0 -2
@@ -10,8 +10,6 @@*/ - -#ifndef _NTERR_H#define _NTERR_H
fs/smb/client/ntlmssp.h +0 -13
@@ -142,16 +142,3 @@ typedef struct _AUTHENTICATE_MESSAGE {* Size of the session key (crypto key encrypted with the password */ -int decode_ntlmssp_challenge (char *bcc_ptr,int blob_len,struct cifs_ses *ses); -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);
fs/smb/client/reparse.h +0 -11
@@ -126,15 +126,4 @@ static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data) return ret; } -bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb, -struct cifs_fattr *fattr, -struct cifs_open_info_data *data); -int create_reparse_symlink (const unsigned int xid,struct inode *inode, -struct dentry *dentry,struct cifs_tcon *tcon, -const char *full_path,const char *symname); -int mknod_reparse (unsigned int xid,struct inode *inode, -struct dentry *dentry,struct cifs_tcon *tcon, -const char *full_path,umode_t mode,dev_t dev); -struct reparse_data_buffer *smb2_get_reparse_point_buffer (const struct kvec *rsp_iov,u32 *len); -#endif /* _CIFS_REPARSE_H */
fs/smb/client/smb1proto.h +211 -1
217 lines not on this page · raw message
fs/smb/client/smb2proto.h +247 -265
544 lines not on this page · raw message
fs/smb/client/smbdirect.h +0 -1
@@ -62,7 +62,6 @@ struct smbdirect_mr_io *smbd_register_mr( bool writing, bool need_invalidate);void smbd_deregister_mr (struct smbdirect_mr_io *mr); -/* PROTOTYPES */ #else #define cifs_rdma_enabled (server) 0
David Howells
maintainerPATCH v3 3/12 cifs: Add the smb3_read_* tracepoints to SMB1
In reply to David HowellsAdd the smb3_read_* tracepoints to SMB1's cifs_async_readv() and cifs_readv_callback().
--- fs/smb/client/cifssmb.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
fs/smb/client/cifssmb.c +22 -0
@@ -1364,6 +1364,14 @@ cifs_readv_callback(struct mid_q_entry *mid)if (rdata->result == -ENODATA ) { rdata->result =0 ;__set_bit (NETFS_SREQ_HIT_EOF , &rdata->subreq.flags); +trace_smb3_read_err (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->xid, + rdata->req->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->subreq.len - rdata->subreq.transferred, + rdata->result); }else {size_t trans = rdata->subreq.transferred + rdata->got_bytes; if (trans < rdata->subreq.len &&
@@ -1375,6 +1383,13 @@ cifs_readv_callback(struct mid_q_entry *mid) }if (rdata->got_bytes)__set_bit (NETFS_SREQ_MADE_PROGRESS , &rdata->subreq.flags); +trace_smb3_read_done (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->xid, + rdata->req->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->got_bytes); } trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value,
@@ -1446,6 +1461,13 @@ cifs_async_readv(struct cifs_io_subrequest *rdata) rdata->iov[1 ].iov_base = (char *)smb +4 ; rdata->iov[1 ].iov_len =get_rfc1002_len (smb); +trace_smb3_read_enter (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->xid, + rdata->req->cfile->fid.netfid, + tcon->tid, tcon->ses->Suid, + rdata->subreq.start, rdata->subreq.len); + rc =cifs_call_async (tcon->ses->server, &rqst, cifs_readv_receive, cifs_readv_callback,NULL , rdata,0 ,NULL );
David Howells
maintainerPATCH v3 4/12 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 | 75 +++++++---------------------------------- 1 file changed, 12 insertions(+), 63 deletions(-)
fs/smb/client/smb2ops.c +12 -63
@@ -4484,61 +4484,6 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,return rc; } -/* -* Clear a read buffer, discarding the folios which have the 1st mark set. -*/ -static void cifs_clear_folioq_buffer (struct folio_queue *buffer) -{ -struct folio_queue *folioq; - -while ((folioq = buffer)) { -for (int s =0 ; s <folioq_count (folioq); s++) -if (folioq_is_marked (folioq, s)) -folio_put (folioq_folio (folioq, s)); - buffer = folioq->next; -kfree (folioq); - } -} - -/* -* Allocate buffer space into a folio queue. -*/ -static struct folio_queue *cifs_alloc_folioq_buffer (ssize_t size) -{ -struct folio_queue *buffer =NULL , *tail =NULL , *p; -struct folio *folio; -unsigned int slot; - -do { -if (!tail ||folioq_full (tail)) { - p =kmalloc (sizeof (*p),GFP_NOFS ); -if (!p) - goto nomem; -folioq_init (p,0 ); -if (tail) { - tail->next = p; - p->prev = tail; - }else { - buffer = p; - } - tail = p; - } - - folio =folio_alloc (GFP_KERNEL |__GFP_HIGHMEM,0 ); -if (!folio) - goto nomem; - - slot =folioq_append_mark (tail, folio); - size -=folioq_folio_size (tail, slot); - }while (size >0 ); - -return buffer; - -nomem: -cifs_clear_folioq_buffer (buffer); -return NULL ; -} -/* * Copy data from an iterator to the folios in a folio queue buffer. */
@@ -4564,7 +4509,7 @@ void smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst) {for (int i =0 ; i < num_rqst; i++) -cifs_clear_folioq_buffer (rqst[i].rq_buffer); +netfs_free_folioq_buffer (rqst[i].rq_buffer); }/*
@@ -4599,8 +4544,11 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, new->rq_nvec = old->rq_nvec;if (size >0 ) { - buffer =cifs_alloc_folioq_buffer (size); -if (!buffer) +size_t cur_size =0 ; + + rc =netfs_alloc_folioq_buffer (NULL , &buffer, &cur_size, + size,GFP_NOFS ); +if (rc <0 ) goto err_free; new->rq_buffer = buffer;
@@ -4932,7 +4880,7 @@ static void smb2_decrypt_offload(struct work_struct *work) } free_pages: -cifs_clear_folioq_buffer (dw->buffer); +netfs_free_folioq_buffer (dw->buffer);cifs_small_buf_release (dw->buf);kfree (dw); }
@@ -4970,9 +4918,10 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, dw->len = len; len =round_up (dw->len,PAGE_SIZE ); - rc = -ENOMEM ; - dw->buffer =cifs_alloc_folioq_buffer (len); -if (!dw->buffer) +size_t cur_size =0 ; + + rc =netfs_alloc_folioq_buffer (NULL , &dw->buffer, &cur_size, len,GFP_NOFS ); +if (rc <0 ) goto discard_data;iov_iter_folio_queue (&iter,ITER_DEST , dw->buffer,0 ,0 , len);
@@ -5033,7 +4982,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, } free_pages: -cifs_clear_folioq_buffer (dw->buffer); +netfs_free_folioq_buffer (dw->buffer); free_dw:kfree (dw);return rc;
David Howells
maintainerPATCH v3 5/12 cifs: Rename mid_q_entry to smb_message
In reply to David HowellsRename mid_q_entry to smb_message as future development that will allocate it at a higher level in the marshalling code and then hand it down into the transport layer. It will also be used to pass parameters such as the send and receive data buffers, credits and other things.
--- fs/smb/client/cifs_debug.c | 43 +++--- fs/smb/client/cifsfs.c | 31 +++-- fs/smb/client/cifsglob.h | 70 +++++----- fs/smb/client/cifsproto.h | 28 ++-- fs/smb/client/cifssmb.c | 82 ++++++------ fs/smb/client/cifstransport.c | 168 ++++++++++++------------ fs/smb/client/connect.c | 152 +++++++++++----------- fs/smb/client/netmisc.c | 14 +- fs/smb/client/smb1ops.c | 46 +++---- fs/smb/client/smb1proto.h | 6 +- fs/smb/client/smb2misc.c | 8 +- fs/smb/client/smb2ops.c | 122 ++++++++--------- fs/smb/client/smb2pdu.c | 47 ++++--- fs/smb/client/smb2proto.h | 10 +- fs/smb/client/smb2transport.c | 62 ++++----- fs/smb/client/transport.c | 238 +++++++++++++++++----------------- 16 files changed, 564 insertions(+), 563 deletions(-)
fs/smb/client/cifs_debug.c +21 -22
@@ -55,33 +55,32 @@ void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)void cifs_dump_mids (struct TCP_Server_Info *server) {#ifdef CONFIG_CIFS_DEBUG2 -struct mid_q_entry *mid_entry; +struct smb_message *smb;if (server ==NULL )return ;cifs_dbg (VFS ,"Dump pending requests:\n" );spin_lock (&server->mid_queue_lock); -list_for_each_entry (mid_entry, &server->pending_mid_q, qhead) { +list_for_each_entry (smb, &server->pending_mid_q, qhead) {cifs_dbg (VFS ,"State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n" , - mid_entry->mid_state, -le16_to_cpu (mid_entry->command), - mid_entry->pid, - mid_entry->callback_data, - mid_entry->mid); + smb->mid_state, +le16_to_cpu (smb->command), + smb->pid, + smb->callback_data, + smb->mid);#ifdef CONFIG_CIFS_STATS2 cifs_dbg (VFS ,"IsLarge: %d buf: %p time rcv: %ld now: %ld\n" , - mid_entry->large_buf, - mid_entry->resp_buf, - mid_entry->when_received, + smb->large_buf, + smb->resp_buf, + smb->when_received, jiffies);#endif /* STATS2 */ cifs_dbg (VFS ,"IsMult: %d IsEnd: %d\n" , - mid_entry->multiRsp, mid_entry->multiEnd); -if (mid_entry->resp_buf) { -cifs_dump_detail (mid_entry->resp_buf, server); -cifs_dump_mem ("existing buf: " , - mid_entry->resp_buf,62 ); + smb->multiRsp, smb->multiEnd); +if (smb->resp_buf) { +cifs_dump_detail (smb->resp_buf, server); +cifs_dump_mem ("existing buf: " , smb->resp_buf,62 ); } }spin_unlock (&server->mid_queue_lock);
@@ -395,7 +394,7 @@ static __always_inline const char *cipher_alg_str(__le16 cipher)static int cifs_debug_data_proc_show (struct seq_file *m,void *v) { -struct mid_q_entry *mid_entry; +struct smb_message *smb;struct TCP_Server_Info *server;struct TCP_Server_Info *chan_server;struct cifs_ses *ses;
@@ -716,13 +715,13 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)seq_printf (m,"\n\tServer ConnectionId: 0x%llx" , chan_server->conn_id);spin_lock (&chan_server->mid_queue_lock); -list_for_each_entry (mid_entry, &chan_server->pending_mid_q, qhead) { +list_for_each_entry (smb, &chan_server->pending_mid_q, qhead) {seq_printf (m,"\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu" , - mid_entry->mid_state, -le16_to_cpu (mid_entry->command), - mid_entry->pid, - mid_entry->callback_data, - mid_entry->mid); + smb->mid_state, +le16_to_cpu (smb->command), + smb->pid, + smb->callback_data, + smb->mid); }spin_unlock (&chan_server->mid_queue_lock); }
fs/smb/client/cifsfs.c +15 -16
@@ -437,13 +437,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;
@@ -1836,28 +1836,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 )
@@ -2021,7 +2020,7 @@ init_cifs(void)if (rc) goto out_destroy_inodecache; - rc =init_mids (); + rc =init_smb_message ();if (rc) goto out_destroy_netfs;
@@ -2078,7 +2077,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:
@@ -2120,7 +2119,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 +35 -35
163 lines not on this page · raw message
fs/smb/client/cifsproto.h +14 -14
@@ -136,9 +136,9 @@ int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,ssize_t cifs_discard_from_socket (struct TCP_Server_Info *server,size_t to_read);int cifs_read_iter_from_socket (struct TCP_Server_Info *server,struct iov_iter *iter,unsigned int to_read); -void dequeue_mid (struct mid_q_entry *mid,bool malformed); +void dequeue_mid (struct smb_message *mid,bool malformed);int cifs_enable_signing (struct TCP_Server_Info *server,bool mnt_sign_required); -int cifs_handle_standard (struct TCP_Server_Info *server,struct mid_q_entry *mid); +int cifs_handle_standard (struct TCP_Server_Info *server,struct smb_message *mid);int cifs_ipaddr_cmp (struct sockaddr *srcaddr,struct sockaddr *rhs);bool cifs_match_ipaddr (struct sockaddr *srcaddr,struct sockaddr *rhs);struct TCP_Server_Info *cifs_find_tcp_session (struct smb3_fs_context *ctx);
@@ -462,7 +462,7 @@ struct vfsmount *cifs_d_automount(struct path *path);int cifs_convert_address (struct sockaddr *dst,const char *src,int len);void cifs_set_port (struct sockaddr *addr,const unsigned short int port);int map_smb_to_linux_error (char *buf,bool logErr); -int map_and_check_smb_error (struct mid_q_entry *mid,bool logErr); +int map_and_check_smb_error (struct smb_message *mid,bool logErr);unsigned int smbCalcSize (void *buf);struct timespec64 cifs_NTtimeToUnix (__le64 ntutc);u64 cifs_UnixTimeToNT (struct timespec64 t);
@@ -550,9 +550,9 @@ int E_md4hash(const unsigned char *passwd, unsigned char *p16,/* * transport.c */ -void cifs_wake_up_task (struct mid_q_entry *mid); +void cifs_wake_up_task (struct smb_message *mid);void __release_mid (struct kref *refcount); -void delete_mid (struct mid_q_entry *mid); +void delete_mid (struct smb_message *mid);int smb_send_kvec (struct TCP_Server_Info *server,struct msghdr *smb_msg,size_t *sent);unsigned long smb_rqst_len (struct TCP_Server_Info *server,struct smb_rqst *rqst);
@@ -562,12 +562,12 @@ int wait_for_free_request(struct TCP_Server_Info *server, const int flags, unsigned int *instance);int cifs_wait_mtu_credits (struct TCP_Server_Info *server,size_t size,size_t *num,struct cifs_credits *credits); -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 *midQ);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); -int cifs_sync_mid_result (struct mid_q_entry *mid,struct TCP_Server_Info *server); +int cifs_sync_mid_result (struct smb_message *mid,struct TCP_Server_Info *server);struct TCP_Server_Info *cifs_pick_channel (struct cifs_ses *ses); int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, struct TCP_Server_Info *server,
@@ -578,7 +578,7 @@ int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, struct smb_rqst *rqst, int *resp_buf_type, const int flags, struct kvec *resp_iov);int cifs_discard_remaining_data (struct TCP_Server_Info *server); -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 *mid);/* * unc.c
@@ -630,10 +630,10 @@ static inline void free_dentry_path(void *page)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 ; }struct cifs_unix_set_info_args {
@@ -712,9 +712,9 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)return true; } -static inline void release_mid (struct mid_q_entry *mid) +static inline void release_mid (struct smb_message *smb) { -kref_put (&mid->refcount, __release_mid); +kref_put (&smb->refcount, __release_mid); }static inline void cifs_free_open_info (struct cifs_open_info_data *data)
fs/smb/client/cifssmb.c +41 -41
182 lines not on this page · raw message
fs/smb/client/cifstransport.c +85 -83
389 lines not on this page · raw message
fs/smb/client/connect.c +76 -76
304 lines not on this page · raw message
fs/smb/client/netmisc.c +7 -7
@@ -889,22 +889,22 @@ map_smb_to_linux_error(char *buf, bool logErr) }int -map_and_check_smb_error (struct mid_q_entry *mid,bool logErr) +map_and_check_smb_error (struct smb_message *smb,bool logErr) {int rc; -struct smb_hdr *smb = (struct smb_hdr *)mid->resp_buf; +struct smb_hdr *rhdr = (struct smb_hdr *)smb->resp_buf; - rc =map_smb_to_linux_error ((char *)smb, logErr); -if (rc == -EACCES && !(smb->Flags2 &SMBFLG2_ERR_STATUS )) { + rc =map_smb_to_linux_error ((char *)rhdr, logErr); +if (rc == -EACCES && !(rhdr->Flags2 &SMBFLG2_ERR_STATUS )) {/* possible ERRBaduid */ -__u8 class = smb->Status.DosError.ErrorClass; -__u16 code =le16_to_cpu (smb->Status.DosError.Error); +__u8 class = rhdr->Status.DosError.ErrorClass; +__u16 code =le16_to_cpu (rhdr->Status.DosError.Error);/* switch can be used to handle different errors */ if (class ==ERRSRV && code == ERRbaduid) {cifs_dbg (FYI ,"Server returned 0x%x, reconnecting session...\n" , code); -cifs_signal_cifsd_for_reconnect (mid->server, false); +cifs_signal_cifsd_for_reconnect (smb->server, false); } }
fs/smb/client/smb1ops.c +23 -23
111 lines not on this page · raw message
fs/smb/client/smb1proto.h +3 -3
@@ -210,12 +210,12 @@ int CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,*/ int smb_send (struct TCP_Server_Info *server,struct smb_hdr *smb_buffer,unsigned int smb_buf_length); -struct mid_q_entry *cifs_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst); +struct smb_message *cifs_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst);int SendReceiveNoRsp (const unsigned int xid,struct cifs_ses *ses,char *in_buf,int flags); -int cifs_check_receive (struct mid_q_entry *mid,struct TCP_Server_Info *server, +int cifs_check_receive (struct smb_message *mid,struct TCP_Server_Info *server,bool log_error); -struct mid_q_entry *cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *ignored, +struct smb_message *cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *ignored,struct smb_rqst *rqst); int SendReceive2(const unsigned int xid, struct cifs_ses *ses, struct kvec *iov, int n_vec, int *resp_buf_type /* ret */,
fs/smb/client/smb2misc.c +4 -4
@@ -851,14 +851,14 @@ smb2_handle_cancelled_close(struct cifs_tcon *tcon, __u64 persistent_fid, }int -smb2_handle_cancelled_mid (struct mid_q_entry *mid,struct TCP_Server_Info *server) +smb2_handle_cancelled_mid (struct smb_message *smb,struct TCP_Server_Info *server) { -struct smb2_hdr *hdr = mid->resp_buf; -struct smb2_create_rsp *rsp = mid->resp_buf; +struct smb2_hdr *hdr = smb->resp_buf; +struct smb2_create_rsp *rsp = smb->resp_buf;struct cifs_tcon *tcon;int rc; -if ((mid->optype &CIFS_CP_CREATE_CLOSE_OP ) || hdr->Command !=SMB2_CREATE || +if ((smb->optype &CIFS_CP_CREATE_CLOSE_OP ) || hdr->Command !=SMB2_CREATE || hdr->Status !=STATUS_SUCCESS )return 0 ;
fs/smb/client/smb2ops.c +61 -61
312 lines not on this page · raw message
fs/smb/client/smb2pdu.c +23 -24
118 lines not on this page · raw message
fs/smb/client/smb2proto.h +5 -5
@@ -99,7 +99,7 @@ bool smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server);void smb2_cancelled_close_fid (struct work_struct *work);int smb2_handle_cancelled_close (struct cifs_tcon *tcon,__u64 persistent_fid,__u64 volatile_fid); -int smb2_handle_cancelled_mid (struct mid_q_entry *mid,struct TCP_Server_Info *server); +int smb2_handle_cancelled_mid (struct smb_message *mid,struct TCP_Server_Info *server);void smb311_update_preauth_hash (struct cifs_ses *ses,struct TCP_Server_Info *server,struct kvec *iov,int nvec);
@@ -119,7 +119,7 @@ int smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, struct kvec *rsp, int *buftype, struct cifs_sb_info *cifs_sb);void smb3_free_compound_rqst (int num_rqst,struct smb_rqst *rqst); -int smb3_handle_read_data (struct TCP_Server_Info *server,struct mid_q_entry *mid); +int smb3_handle_read_data (struct TCP_Server_Info *server,struct smb_message *mid); int __cifs_sfu_make_node(unsigned int xid, struct inode *inode, struct dentry *dentry, struct cifs_tcon *tcon, const char *full_path, umode_t mode, dev_t dev,
@@ -282,11 +282,11 @@ int generate_smb30signingkey(struct cifs_ses *ses,int generate_smb311signingkey (struct cifs_ses *ses,struct TCP_Server_Info *server);int smb2_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server); -int smb2_check_receive (struct mid_q_entry *mid,struct TCP_Server_Info *server, +int smb2_check_receive (struct smb_message *mid,struct TCP_Server_Info *server,bool log_error); -struct mid_q_entry *smb2_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *server, +struct smb_message *smb2_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *server,struct smb_rqst *rqst); -struct mid_q_entry *smb2_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst); +struct smb_message *smb2_setup_async_request (struct TCP_Server_Info *server,struct smb_rqst *rqst);int smb3_crypto_aead_allocate (struct TCP_Server_Info *server);/*
fs/smb/client/smb2transport.c +31 -31
143 lines not on this page · raw message
fs/smb/client/transport.c +120 -118
516 lines not on this page · raw message
David Howells
maintainerPATCH v3 6/12 cifs: Remove the RFC1002 header from smb_hdr
In reply to David HowellsRemove the RFC1002 header from struct smb_hdr as used for SMB-1.0. This simplifies the SMB-1.0 code by simplifying a lot of places that have to add or subtract 4 to work around the fact that the RFC1002 header isn't really part of the message and the base for various offsets within the message is from the base of the smb_hdr, not the RFC1002 header.
Further, clean up a bunch of places that require an extra kvec struct specifically pointing to the RFC1002 header, such that kvec[0].iov_base must be exactly 4 bytes before kvec[1].iov_base.
This allows the header preamble size stuff to be removed too.
The size of the request and response message are then handed around either directly or by summing the size of all the iov_len members in the kvec array for which we have a count.
Also, this simplifies and cleans up the common transmission and receive paths for SMB1 and SMB2/3 as there no longer needs to be special handling casing for SMB1 messages as the RFC1002 header is now generated on the fly for SMB1 as it is for SMB2/3.
--- fs/smb/client/cifs_debug.c | 6 +- fs/smb/client/cifs_debug.h | 2 +- fs/smb/client/cifsencrypt.c | 36 +- fs/smb/client/cifsglob.h | 21 +- fs/smb/client/cifspdu.h | 2 +- fs/smb/client/cifsproto.h | 12 +- fs/smb/client/cifssmb.c | 695 +++++++++++++++++++--------------- fs/smb/client/cifstransport.c | 128 +++---- fs/smb/client/connect.c | 36 +- fs/smb/client/misc.c | 32 +- fs/smb/client/sess.c | 8 +- fs/smb/client/smb1ops.c | 21 +- fs/smb/client/smb1proto.h | 10 +- fs/smb/client/smb2misc.c | 3 +- fs/smb/client/smb2ops.c | 11 +- fs/smb/client/smb2proto.h | 3 +- fs/smb/client/transport.c | 22 +- fs/smb/common/smb2pdu.h | 3 - fs/smb/common/smbglob.h | 1 - 19 files changed, 538 insertions(+), 514 deletions(-)
fs/smb/client/cifs_debug.c +3 -3
@@ -37,7 +37,7 @@ cifs_dump_mem(char *label, void *data, int length) data, length, true); } -void cifs_dump_detail (void *buf,struct TCP_Server_Info *server) +void cifs_dump_detail (void *buf,size_t buf_len,struct TCP_Server_Info *server) {#ifdef CONFIG_CIFS_DEBUG2 struct smb_hdr *smb = buf;
@@ -45,7 +45,7 @@ void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)cifs_dbg (VFS ,"Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n" , smb->Command, smb->Status.CifsError, smb->Flags, smb->Flags2, smb->Mid, smb->Pid, smb->WordCount); -if (!server->ops->check_message (buf, server->total_read, server)) { +if (!server->ops->check_message (buf, buf_len, server->total_read, server)) {cifs_dbg (VFS ,"smb buf %p len %u\n" , smb, server->ops->calc_smb_size (smb)); }
@@ -79,7 +79,7 @@ void cifs_dump_mids(struct TCP_Server_Info *server)cifs_dbg (VFS ,"IsMult: %d IsEnd: %d\n" , smb->multiRsp, smb->multiEnd);if (smb->resp_buf) { -cifs_dump_detail (smb->resp_buf, server); +cifs_dump_detail (smb->resp_buf, smb->response_pdu_len, server);cifs_dump_mem ("existing buf: " , smb->resp_buf,62 ); } }
fs/smb/client/cifs_debug.h +1 -1
@@ -19,7 +19,7 @@* cifs_debug.c */ void cifs_dump_mem (char *label,void *data,int length); -void cifs_dump_detail (void *buf,struct TCP_Server_Info *server); +void cifs_dump_detail (void *buf,size_t buf_len,struct TCP_Server_Info *server);void cifs_dump_mids (struct TCP_Server_Info *server);void cifs_proc_init (void );void cifs_proc_clean (void );
fs/smb/client/cifsencrypt.c +8 -28
@@ -91,18 +91,7 @@ int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,struct kvec *iov = rqst->rq_iov;int n_vec = rqst->rq_nvec; -/* iov[0] is actual data and not the rfc1002 length for SMB2+ */ -if (!is_smb1 (server)) { -if (iov[0 ].iov_len <=4 ) -return -EIO ; - i =0 ; - }else { -if (n_vec <2 || iov[0 ].iov_len !=4 ) -return -EIO ; - i =1 ;/* skip rfc1002 length */ - } - -for (; i < n_vec; i++) { +for (i =0 ; i < n_vec; i++) {if (iov[i].iov_len ==0 )continue ;if (iov[i].iov_base ==NULL ) {
@@ -165,10 +154,6 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,char smb_signature[20 ];struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; -if (rqst->rq_iov[0 ].iov_len !=4 || - rqst->rq_iov[0 ].iov_base +4 != rqst->rq_iov[1 ].iov_base) -return -EIO ; -if ((cifs_pdu ==NULL ) || (server ==NULL ))return -EINVAL ;
@@ -211,17 +196,16 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, }/* must be called with server->srv_mutex held */ -int cifs_sign_smb (struct smb_hdr *cifs_pdu,struct TCP_Server_Info *server, +int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, +struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number) { -struct kvec iov[2 ]; +struct kvec iov[1 ] = { + [0 ].iov_base = (char *)cifs_pdu, + [0 ].iov_len = pdu_len, + }; - iov[0 ].iov_base = cifs_pdu; - iov[0 ].iov_len =4 ; - iov[1 ].iov_base = (char *)cifs_pdu +4 ; - iov[1 ].iov_len =be32_to_cpu (cifs_pdu->smb_buf_length); - -return cifs_sign_smbv (iov,2 , server, +return cifs_sign_smbv (iov,ARRAY_SIZE (iov), server, pexpected_response_sequence_number); }
@@ -234,10 +218,6 @@ int cifs_verify_signature(struct smb_rqst *rqst,char what_we_think_sig_should_be[20 ];struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; -if (rqst->rq_iov[0 ].iov_len !=4 || - rqst->rq_iov[0 ].iov_base +4 != rqst->rq_iov[1 ].iov_base) -return -EIO ; -if (cifs_pdu ==NULL || server ==NULL )return -EINVAL ;
fs/smb/client/cifsglob.h +11 -10
@@ -347,12 +347,13 @@ struct smb_version_operations {int (*map_error)(char *,bool );/* find mid corresponding to the response message */ struct smb_message * (*find_mid)(struct TCP_Server_Info *server,char *buf); -void (*dump_detail)(void *buf,struct TCP_Server_Info *ptcp_info); +void (*dump_detail)(void *buf,size_t buf_len,struct TCP_Server_Info *ptcp_info);void (*clear_stats)(struct cifs_tcon *);void (*print_stats)(struct seq_file *m,struct cifs_tcon *);void (*dump_share_caps)(struct seq_file *,struct cifs_tcon *);/* verify the message */ -int (*check_message)(char *,unsigned int ,struct TCP_Server_Info *); +int (*check_message)(char *buf,unsigned int pdu_len,unsigned int len, +struct TCP_Server_Info *server);bool (*is_oplock_break)(char *,struct TCP_Server_Info *);int (*handle_cancelled_mid)(struct smb_message *smb,struct TCP_Server_Info *server); void (*downgrade_oplock)(struct TCP_Server_Info *server,
@@ -636,8 +637,7 @@ struct smb_version_operations {#define HEADER_SIZE (server) (server->vals->header_size)#define MAX_HEADER_SIZE (server) (server->vals->max_header_size) -#define HEADER_PREAMBLE_SIZE (server) (server->vals->header_preamble_size) -#define MID_HEADER_SIZE (server) (HEADER_SIZE(server) - 1 - HEADER_PREAMBLE_SIZE(server)) +#define MID_HEADER_SIZE (server) (HEADER_SIZE(server) - 1)/** * CIFS superblock mount flags (mnt_cifs_flags) to consider when
@@ -832,9 +832,9 @@ struct TCP_Server_Info {char dns_dom[CIFS_MAX_DOMAINNAME_LEN +1 ]; }; -static inline bool is_smb1 (struct TCP_Server_Info *server) +static inline bool is_smb1 (const struct TCP_Server_Info *server) { -return HEADER_PREAMBLE_SIZE (server) !=0 ; +return server->vals->protocol_id ==SMB10_PROT_ID ; }static inline void cifs_server_lock (struct TCP_Server_Info *server)
@@ -973,16 +973,16 @@ compare_mid(__u16 mid, const struct smb_hdr *smb)* of kvecs to handle the receive, though that should only need to be done * once. */ -#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) -#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) +#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ)) +#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP))/* * When the server doesn't allow large posix writes, only allow a rsize/wsize * of 2^17-1 minus the size of the call header. That allows for a read or * write up to the maximum size described by RFC1002. */ -#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) -#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) +#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ)) +#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP))/* * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
@@ -1684,6 +1684,7 @@ struct smb_message {struct task_struct *creator;void *resp_buf;/* pointer to received SMB header */ unsigned int resp_buf_size; +u32 response_pdu_len;int mid_state;/* wish this were enum but can not pass to wait_event */ int mid_rc;/* rc for MID_RC */ __le16 command;/* smb command code */
fs/smb/client/cifspdu.h +1 -1
@@ -90,7 +90,7 @@/* future chained NTCreateXReadX bigger, but for time being NTCreateX biggest */ /* among the requests (NTCreateX response is bigger with wct of 34) */ -#define MAX_CIFS_HDR_SIZE 0x58/* 4 len + 32 hdr + (2*24 wct) + 2 bct + 2 pad */ +#define MAX_CIFS_HDR_SIZE 0x54/* 32 hdr + (2*24 wct) + 2 bct + 2 pad */ #define CIFS_SMALL_PATH 120/* allows for (448-88)/3 */ /* internal cifs vfs structures */
fs/smb/client/cifsproto.h +7 -5
@@ -69,7 +69,8 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, __u32 *pexpected_response_sequence_number);int cifs_sign_smbv (struct kvec *iov,int n_vec,struct TCP_Server_Info *server,__u32 *pexpected_response_sequence); -int cifs_sign_smb (struct smb_hdr *cifs_pdu,struct TCP_Server_Info *server, +int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, +struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number); int cifs_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
@@ -400,10 +401,11 @@ void cifs_buf_release(void *buf_to_free);struct smb_hdr *cifs_small_buf_get (void );void cifs_small_buf_release (void *buf_to_free);void free_rsp_buf (int resp_buftype,void *rsp); -void header_assemble (struct smb_hdr *buffer,char smb_command, -const struct cifs_tcon *treeCon,int word_count -/* length of fixed section word count in two byte units */ ); -int checkSMB (char *buf,unsigned int total_read,struct TCP_Server_Info *server); +unsigned int header_assemble (struct smb_hdr *buffer,char smb_command, +const struct cifs_tcon *treeCon,int word_count +/* length of fixed section word count in two byte units */ ); +int checkSMB (char *buf,unsigned int pdu_len,unsigned int total_read, +struct TCP_Server_Info *server);bool is_valid_oplock_break (char *buffer,struct TCP_Server_Info *srv);void dump_smb (void *buf,int smb_buf_length);void cifs_autodisable_serverino (struct cifs_sb_info *cifs_sb);
fs/smb/client/cifssmb.c +394 -301
2,311 lines not on this page · raw message
fs/smb/client/cifstransport.c +47 -81
271 lines not on this page · raw message
fs/smb/client/connect.c +17 -19
@@ -1156,15 +1156,14 @@ standard_receive3(struct TCP_Server_Info *server, struct smb_message *smb)unsigned int pdu_length = server->pdu_size;/* make sure this will fit in a large buffer */ -if (pdu_length > CIFSMaxBufSize +MAX_HEADER_SIZE (server) - -HEADER_PREAMBLE_SIZE (server)) { +if (pdu_length > CIFSMaxBufSize +MAX_HEADER_SIZE (server)) {cifs_server_dbg (VFS ,"SMB response too long (%u bytes)\n" , pdu_length);cifs_reconnect (server, true);return -ECONNABORTED ; }/* switch to large buffer if too big for a small one */ -if (pdu_length >MAX_CIFS_SMALL_BUFFER_SIZE -4 ) { +if (pdu_length >MAX_CIFS_SMALL_BUFFER_SIZE ) { server->large_buf = true;memcpy (server->bigbuf, buf, server->total_read); buf = server->bigbuf;
@@ -1197,7 +1196,8 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct smb_message *smb)* 48 bytes is enough to display the header and a little bit * into the payload for debugging purposes. */ - rc = server->ops->check_message (buf, server->total_read, server); + rc = server->ops->check_message (buf, server->pdu_size, + server->total_read, server);if (rc)cifs_dump_mem ("Bad SMB: " , buf, min_t(unsigned int, server->total_read, 48));
@@ -1287,16 +1287,13 @@ cifs_demultiplex_thread(void *p)if (length <0 )continue ; -if (is_smb1 (server)) - server->total_read = length; -else - server->total_read =0 ; + server->total_read =0 ;/* * The right amount was read from socket - 4 bytes, * so we can now interpret the length field. */ - pdu_length =get_rfc1002_len (buf); + pdu_length =be32_to_cpup (((__be32 *)buf)) &0xffffff ;cifs_dbg (FYI ,"RFC1002 header 0x%x\n" , pdu_length);if (!is_smb_response (server, buf[0 ]))
@@ -1315,9 +1312,8 @@ cifs_demultiplex_thread(void *p) }/* read down to the MID */ - length =cifs_read_from_socket (server, - buf +HEADER_PREAMBLE_SIZE (server), -MID_HEADER_SIZE (server)); + length =cifs_read_from_socket (server, buf, +MID_HEADER_SIZE (server));if (length <0 )continue ; server->total_read += length;
@@ -1349,6 +1345,8 @@ cifs_demultiplex_thread(void *p) bufs[0 ] = buf; num_smbs =1 ; +if (smbs[0 ]) + smbs[0 ]->response_pdu_len = pdu_length;if (!smbs[0 ] || !smbs[0 ]->receive) length =standard_receive3 (server, smbs[0 ]);else
@@ -1407,7 +1405,7 @@ cifs_demultiplex_thread(void *p)smb2_add_credits_from_hdr (bufs[i], server);#ifdef CONFIG_CIFS_DEBUG2 if (server->ops->dump_detail) - server->ops->dump_detail (bufs[i], + server->ops->dump_detail (bufs[i], pdu_length, server);cifs_dump_mids (server);#endif /* CIFS_DEBUG2 */
@@ -4000,7 +3998,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,TCONX_RSP *pSMBr;unsigned char *bcc_ptr;int rc =0 ; -int length; +int length, in_len;__u16 bytes_left, count;if (ses ==NULL )
@@ -4012,8 +4010,8 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, smb_buffer_response = smb_buffer; -header_assemble (smb_buffer,SMB_COM_TREE_CONNECT_ANDX , -NULL /*no tid */ ,4 /*wct */ ); + in_len =header_assemble (smb_buffer,SMB_COM_TREE_CONNECT_ANDX , +NULL /*no tid */ ,4 /*wct */ ); smb_buffer->Mid =get_next_mid (ses->server); smb_buffer->Uid = ses->Suid;
@@ -4054,11 +4052,11 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, bcc_ptr +=strlen ("?????" ); bcc_ptr +=1 ; count = bcc_ptr - &pSMB->Password[0 ]; -be32_add_cpu (&pSMB->hdr.smb_buf_length, count); + in_len += count; pSMB->ByteCount =cpu_to_le16 (count); - rc =SendReceive (xid, ses, smb_buffer, smb_buffer_response, &length, -0 ); + rc =SendReceive (xid, ses, smb_buffer, in_len, smb_buffer_response, + &length,0 );/* above now done in SendReceive */ if (rc ==0 ) {
fs/smb/client/misc.c +16 -16
@@ -265,19 +265,18 @@ free_rsp_buf(int resp_buftype, void *rsp)/* NB: MID can not be set if treeCon not passed in, in that case it is responsibility of caller to set the mid */ -void +unsigned int header_assemble (struct smb_hdr *buffer,char smb_command,const struct cifs_tcon *treeCon,int word_count/* length of fixed section (word count) in two byte units */ ) { +unsigned int in_len;char *temp = (char *) buffer;memset (temp,0 ,256 );/* bigger than MAX_CIFS_HDR_SIZE */ - buffer->smb_buf_length =cpu_to_be32 ( - (2 * word_count) +sizeof (struct smb_hdr ) - -4 /* RFC 1001 length field does not count */ + -2 /* for bcc field itself */ ) ; + in_len = (2 * word_count) +sizeof (struct smb_hdr ) + +2 /* for bcc field itself */ ; buffer->Protocol[0 ] =0xFF ; buffer->Protocol[1 ] ='S' ;
@@ -312,7 +311,7 @@ header_assemble(struct smb_hdr *buffer, char smb_command,/* endian conversion of flags is now done just before sending */ buffer->WordCount = (char ) word_count; -return ; +return in_len; } static int
@@ -347,10 +346,11 @@ check_smb_hdr(struct smb_hdr *smb) }int -checkSMB (char *buf,unsigned int total_read,struct TCP_Server_Info *server) +checkSMB (char *buf,unsigned int pdu_len,unsigned int total_read, +struct TCP_Server_Info *server) {struct smb_hdr *smb = (struct smb_hdr *)buf; -__u32 rfclen =be32_to_cpu (smb->smb_buf_length); +__u32 rfclen = pdu_len;__u32 clc_len;/* calculated length */ cifs_dbg (FYI ,"checkSMB Length: 0x%x, smb_buf_length: 0x%x\n" , total_read, rfclen);
@@ -395,24 +395,24 @@ checkSMB(char *buf, unsigned int total_read, struct TCP_Server_Info *server)return -EIO ; clc_len =smbCalcSize (smb); -if (4 + rfclen != total_read) { -cifs_dbg (VFS ,"Length read does not match RFC1001 length %d\n" , - rfclen); +if (rfclen != total_read) { +cifs_dbg (VFS ,"Length read does not match RFC1001 length %d/%d\n" , + rfclen, total_read);return -EIO ; } -if (4 + rfclen != clc_len) { +if (rfclen != clc_len) {__u16 mid =get_mid (smb);/* check if bcc wrapped around for large read responses */ if ((rfclen >64 *1024 ) && (rfclen > clc_len)) {/* check if lengths match mod 64K */ -if (((4 + rfclen) &0xFFFF ) == (clc_len &0xFFFF )) +if (((rfclen) &0xFFFF ) == (clc_len &0xFFFF ))return 0 ;/* bcc wrapped */ }cifs_dbg (FYI ,"Calculated size %u vs length %u mismatch for mid=%u\n" , - clc_len,4 + rfclen, mid); + clc_len, rfclen, mid); -if (4 + rfclen < clc_len) { +if (rfclen < clc_len) {cifs_dbg (VFS ,"RFC1001 size %u smaller than SMB for mid=%u\n" , rfclen, mid);return -EIO ;
@@ -452,7 +452,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) (struct smb_com_transaction_change_notify_rsp *)buf;struct file_notify_information *pnotify;__u32 data_offset =0 ; -size_t len = srv->total_read -sizeof (pSMBr->hdr.smb_buf_length); +size_t len = srv->total_read - srv->pdu_size;if (get_bcc (buf) >sizeof (struct file_notify_information )) { data_offset =le32_to_cpu (pSMBr->DataOffset);
fs/smb/client/sess.c +5 -3
@@ -1314,6 +1314,7 @@ struct sess_data {struct nls_table *nls_cp;void (*func)(struct sess_data *);int result; +unsigned int in_len;/* we will send the SMB in three pieces: * a fixed length beginning part, an optional
@@ -1337,11 +1338,12 @@ sess_alloc_buffer(struct sess_data *sess_data, int wct) rc =small_smb_init_no_tc (SMB_COM_SESSION_SETUP_ANDX , wct, ses, (void **)&smb_buf); -if (rc) +if (rc <0 )return rc; + sess_data->in_len = rc; sess_data->iov[0 ].iov_base = (char *)smb_buf; - sess_data->iov[0 ].iov_len =be32_to_cpu (smb_buf->smb_buf_length) +4 ; + sess_data->iov[0 ].iov_len = sess_data->in_len;/* * This variable will be used to clear the buffer * allocated above in case of any error in the calling function.
@@ -1419,7 +1421,7 @@ sess_sendreceive(struct sess_data *sess_data)struct kvec rsp_iov = {NULL ,0 }; count = sess_data->iov[1 ].iov_len + sess_data->iov[2 ].iov_len; -be32_add_cpu (&smb_buf->smb_buf_length, count); + sess_data->in_len += count;put_bcc (count, smb_buf); rc = SendReceive2(sess_data->xid, sess_data->ses,
fs/smb/client/smb1ops.c +10 -11
@@ -36,15 +36,15 @@ send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst, {int rc =0 ;struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; +unsigned int in_len = rqst->rq_iov[0 ].iov_len; -/* -4 for RFC1001 length and +2 for BCC field */ - in_buf->smb_buf_length =cpu_to_be32 (sizeof (struct smb_hdr ) -4 +2 ); +/* +2 for BCC field */ in_buf->Command =SMB_COM_NT_CANCEL ; in_buf->WordCount =0 ;put_bcc (0 , in_buf);cifs_server_lock (server); - rc =cifs_sign_smb (in_buf, server, &smb->sequence_number);
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH v3 7/12 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 | 83 +++++------------------------------ 1 file changed, 10 insertions(+), 73 deletions(-)
fs/smb/client/cifstransport.c +10 -73
@@ -237,12 +237,12 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, struct smb_hdr *in_buf, unsigned int in_len, struct smb_hdr *out_buf, int *pbytes_returned, const int flags) { - int rc = 0; -struct smb_message *smb; + struct TCP_Server_Info *server; +struct kvec resp_iov = {};struct kvec iov = { .iov_base = in_buf, .iov_len = in_len };struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec =1 }; -struct cifs_credits credits = { .value =1 , .instance =0 }; -struct TCP_Server_Info *server; +int resp_buf_type; +int rc =0 ;if (WARN_ON_ONCE (in_len >0xffffff ))return -EIO ;
@@ -273,78 +273,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,return -EIO ; } - rc =wait_for_free_request (server, flags, &credits.instance); -if (rc) -return rc; - -/* make sure that we sign in the same order that we send on this socket -and avoid races inside tcp sendmsg code that could cause corruption -of smb data */ - -cifs_server_lock (server); - - rc =allocate_mid (ses, in_buf, &smb); -if (rc) { -cifs_server_unlock (server); -/* Update # of requests on wire to server */ -add_credits (server, &credits,0 ); -return rc; - } - - rc =cifs_sign_smb (in_buf, in_len, server, &smb->sequence_number); -if (rc) { -cifs_server_unlock (server); - goto out; - } - - smb->mid_state =MID_REQUEST_SUBMITTED ; - - rc =smb_send (server, in_buf, in_len); -cifs_save_when_sent (smb); - -if (rc <0 ) - server->sequence_number -=2 ; - -cifs_server_unlock (server); - + rc =cifs_send_recv (xid, ses, ses->server, + &rqst, &resp_buf_type, flags, &resp_iov);if (rc <0 ) - goto out; - - rc =wait_for_response (server, smb); -if (rc !=0 ) { -send_cancel (server, &rqst, smb); -spin_lock (&smb->mid_lock); -if (smb->mid_state ==MID_REQUEST_SUBMITTED || - smb->mid_state ==MID_RESPONSE_RECEIVED ) { -/* no longer considered to be "in-flight" */ - smb->callback = release_mid; -spin_unlock (&smb->mid_lock); -add_credits (server, &credits,0 ); -return rc; - } -spin_unlock (&smb->mid_lock); - } - - rc =cifs_sync_mid_result (smb, server); -if (rc !=0 ) { -add_credits (server, &credits,0 );return rc; - } - -if (!smb->resp_buf || !out_buf || - smb->mid_state !=MID_RESPONSE_READY ) { - rc = -EIO ; -cifs_server_dbg (VFS ,"Bad MID state?\n" ); - goto out; - } - - *pbytes_returned = smb->response_pdu_len; -memcpy (out_buf, smb->resp_buf, *pbytes_returned); - rc =cifs_check_receive (smb, server,0 ); -out: -delete_mid (smb); -add_credits (server, &credits,0 ); + *pbytes_returned = resp_iov.iov_len; +if (resp_iov.iov_len) +memcpy (out_buf, resp_iov.iov_base, resp_iov.iov_len); +free_rsp_buf (resp_buf_type, resp_iov.iov_base);return rc; }
David Howells
maintainerPATCH v3 8/12 cifs: Clean up some places where an extra kvec[] was required for rfc1002
In reply to David HowellsClean up some places where previously an extra element in the kvec array was being used to hold an rfc1002 header for SMB1 (a previous patch removed this and generated it on the fly as for SMB2/3).
--- fs/smb/client/cifsencrypt.c | 52 ++++++++--------------------------- fs/smb/client/cifsproto.h | 5 ---- fs/smb/client/cifstransport.c | 20 ++------------ fs/smb/client/smb1ops.c | 12 +++++--- fs/smb/client/transport.c | 25 +++++++++-------- 5 files changed, 35 insertions(+), 79 deletions(-)
fs/smb/client/cifsencrypt.c +12 -40
@@ -86,26 +86,21 @@ static int cifs_sig_iter(const struct iov_iter *iter, size_t maxsize,int __cifs_calc_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,char *signature,struct cifs_calc_sig_ctx *ctx) { -int i; +struct iov_iter iter;ssize_t rc; -struct kvec *iov = rqst->rq_iov; -int n_vec = rqst->rq_nvec; +size_t size =0 ; -for (i =0 ; i < n_vec; i++) { -if (iov[i].iov_len ==0 ) -continue ; -if (iov[i].iov_base ==NULL ) { -cifs_dbg (VFS ,"null iovec entry\n" ); -return -EIO ; - } +for (int i =0 ; i < rqst->rq_nvec; i++) + size += rqst->rq_iov[i].iov_len; - rc =cifs_sig_update (ctx, iov[i].iov_base, iov[i].iov_len); -if (rc) { -cifs_dbg (VFS ,"%s: Could not update with payload\n" , - __func__); -return rc; - } - } +iov_iter_kvec (&iter,ITER_SOURCE , rqst->rq_iov, rqst->rq_nvec, size); + +if (iov_iter_count (&iter) <=4 ) +return -EIO ; + + rc =cifs_sig_iter (&iter,iov_iter_count (&iter), ctx); +if (rc <0 ) +return rc; rc =cifs_sig_iter (&rqst->rq_iter,iov_iter_count (&rqst->rq_iter), ctx);if (rc <0 )
@@ -186,29 +181,6 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,return rc; } -int cifs_sign_smbv (struct kvec *iov,int n_vec,struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence) -{ -struct smb_rqst rqst = { .rq_iov = iov, - .rq_nvec = n_vec }; - -return cifs_sign_rqst (&rqst, server, pexpected_response_sequence); -} - -/* must be called with server->srv_mutex held */ -int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, -struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence_number) -{ -struct kvec iov[1 ] = { - [0 ].iov_base = (char *)cifs_pdu, - [0 ].iov_len = pdu_len, - }; - -return cifs_sign_smbv (iov,ARRAY_SIZE (iov), server, - pexpected_response_sequence_number); -} -int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number)
fs/smb/client/cifsproto.h +0 -5
@@ -67,11 +67,6 @@ int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server, char *signature, struct cifs_calc_sig_ctx *ctx);int cifs_sign_rqst (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number); -int cifs_sign_smbv (struct kvec *iov,int n_vec,struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence); -int cifs_sign_smb (struct smb_hdr *cifs_pdu,unsigned int pdu_len, -struct TCP_Server_Info *server, -__u32 *pexpected_response_sequence_number);int cifs_verify_signature (struct smb_rqst *rqst,struct TCP_Server_Info *server,__u32 expected_sequence_number);
fs/smb/client/cifstransport.c +2 -18
@@ -71,22 +71,6 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)return smb; } -int -smb_send (struct TCP_Server_Info *server,struct smb_hdr *smb_buffer, -unsigned int smb_buf_length) -{ -struct kvec iov[1 ] = { - [0 ].iov_base = smb_buffer, - [0 ].iov_len = smb_buf_length, - }; -struct smb_rqst rqst = { - .rq_iov = iov, - .rq_nvec =ARRAY_SIZE (iov), - }; - -return __smb_send_rqst (server,1 , &rqst); -} -static int allocate_mid (struct cifs_ses *ses,struct smb_hdr *in_buf,struct smb_message **ppmidQ) {
@@ -370,7 +354,7 @@ int SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,return rc; } - rc =cifs_sign_smb (in_buf, in_len, server, &smb->sequence_number); + rc =cifs_sign_rqst (&rqst, server, &smb->sequence_number);if (rc) {delete_mid (smb);cifs_server_unlock (server);
@@ -378,7 +362,7 @@ int SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, } smb->mid_state =MID_REQUEST_SUBMITTED ; - rc =smb_send (server, in_buf, in_len); + rc =__smb_send_rqst (server,1 , &rqst);cifs_save_when_sent (smb);if (rc <0 )
fs/smb/client/smb1ops.c +8 -4
@@ -34,17 +34,21 @@ static int send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst, struct smb_message *smb) { - int rc = 0; struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0].iov_base; -unsigned int in_len = rqst->rq_iov[0 ].iov_len; +struct kvec iov[1 ]; +struct smb_rqst crqst = { .rq_iov = iov, .rq_nvec =1 }; +int rc =0 ;/* +2 for BCC field */ in_buf->Command =SMB_COM_NT_CANCEL ; in_buf->WordCount =0 ;put_bcc (0 , in_buf); + iov[0 ].iov_base = in_buf; + iov[0 ].iov_len =sizeof (struct smb_hdr ) +2 ; +cifs_server_lock (server); - rc =cifs_sign_smb (in_buf, in_len, server, &smb->sequence_number); + rc =cifs_sign_rqst (&crqst, server, &smb->sequence_number);if (rc) {cifs_server_unlock (server);return rc;
@@ -56,7 +60,7 @@ send_nt_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst,* after signing here. */ --server->sequence_number; - rc =smb_send (server, in_buf, in_len); + rc =__smb_send_rqst (server,1 , &crqst);if (rc <0 ) server->sequence_number--;
fs/smb/client/transport.c +13 -12
@@ -1043,22 +1043,23 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, goto out; } - buf = (char *)smb[i]->resp_buf; - resp_iov[i].iov_base = buf; - resp_iov[i].iov_len = smb[i]->resp_buf_size; - -if (smb[i]->large_buf) - resp_buf_type[i] =CIFS_LARGE_BUFFER ; -else - resp_buf_type[i] =CIFS_SMALL_BUFFER ; - rc = server->ops->check_receive (smb[i], server, flags &CIFS_LOG_ERROR ); -/* mark it so buf will not be freed by delete_mid */ -if ((flags &CIFS_NO_RSP_BUF ) ==0 ) - smb[i]->resp_buf =NULL ; +if (resp_iov) { + buf = (char *)smb[i]->resp_buf; + resp_iov[i].iov_base = buf; + resp_iov[i].iov_len = smb[i]->resp_buf_size; +if (smb[i]->large_buf) + resp_buf_type[i] =CIFS_LARGE_BUFFER ; +else + resp_buf_type[i] =CIFS_SMALL_BUFFER ; + +/* mark it so buf will not be freed by delete_mid */ +if ((flags &CIFS_NO_RSP_BUF ) ==0 ) + smb[i]->resp_buf =NULL ; + } }/*
David Howells
maintainerPATCH v3 9/12 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 | 7 +- fs/smb/client/cifssmb.c | 18 +-- fs/smb/client/cifstransport.c | 200 +--------------------------------- fs/smb/client/smb1ops.c | 47 +++++++- fs/smb/client/smb1proto.h | 3 - fs/smb/client/transport.c | 10 +- 7 files changed, 77 insertions(+), 216 deletions(-)
fs/smb/client/cifsglob.h +6 -2
@@ -311,8 +311,9 @@ struct cifs_open_parms;struct cifs_credits ;struct smb_version_operations { -int (*send_cancel)(struct TCP_Server_Info *,struct smb_rqst *, -struct smb_message *smb); +int (*send_cancel)(struct cifs_ses *ses,struct TCP_Server_Info *server, +struct smb_rqst *rqst,struct smb_message *smb, +unsigned int xid);bool (*compare_fids)(struct cifsFileInfo *,struct cifsFileInfo *);/* setup request: allocate mid, sign message */ struct smb_message *(*setup_request)(struct cifs_ses *ses,
@@ -1672,6 +1673,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 */
@@ -1882,6 +1884,8 @@ enum cifs_writable_file_flags {#define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ #define CIFS_NO_SRV_RSP 0x1000/* there is no server response */ #define CIFS_COMPRESS_REQ 0x4000/* compress request before sending */ +#define CIFS_INTERRUPTIBLE_WAIT 0x8000/* Interruptible wait (e.g. lock request) */ +#define CIFS_WINDOWS_LOCK 0x10000/* We're trying to get a Windows lock */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001
fs/smb/client/cifsproto.h +4 -3
@@ -626,11 +626,12 @@ static inline void free_dentry_path(void *page) }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 ; }struct cifs_unix_set_info_args {
fs/smb/client/cifssmb.c +10 -8
@@ -2060,7 +2060,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,/* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ unsigned int in_len;int bytes_returned; -int flags =0 ; +int flags =CIFS_WINDOWS_LOCK |CIFS_INTERRUPTIBLE_WAIT ;__u16 count; cifs_dbg(FYI, "CIFSSMBLock timeout %d numLock %d\n",
@@ -2105,8 +2105,9 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, pSMB->ByteCount =cpu_to_le16 (count);if (waitFlag) - rc =SendReceiveBlockingLock (xid, tcon, (struct smb_hdr *) pSMB, in_len, - (struct smb_hdr *) pSMB, &bytes_returned); + rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, in_len, + (struct smb_hdr *) pSMB, &bytes_returned, + flags);else rc =SendReceiveNoRsp (xid, tcon->ses, (char *)pSMB, in_len, flags);cifs_small_buf_release (pSMB);
@@ -2131,7 +2132,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,struct cifs_posix_lock *parm_data;unsigned int in_len;int rc =0 ; -int timeout =0 ; +int sr_flags =CIFS_INTERRUPTIBLE_WAIT ;int bytes_returned =0 ;int resp_buf_type =0 ;__u16 params, param_offset, offset, byte_count, count;
@@ -2174,7 +2175,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
@@ -2191,13 +2192,14 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, in_len += byte_count; pSMB->ByteCount =cpu_to_le16 (byte_count);if (waitFlag) { - rc =SendReceiveBlockingLock (xid, tcon, (struct smb_hdr *) pSMB, in_len, - (struct smb_hdr *) pSMBr, &bytes_returned); + rc =SendReceive (xid, tcon->ses, (struct smb_hdr *) pSMB, in_len, + (struct smb_hdr *) pSMBr, &bytes_returned, + sr_flags); }else { iov[0 ].iov_base = (char *)pSMB; iov[0 ].iov_len = in_len; rc =SendReceive2 (xid, tcon->ses, iov,1 /* num iovecs */ , - &resp_buf_type, timeout, &rsp_iov); + &resp_buf_type, sr_flags, &rsp_iov); pSMBr = (struct smb_com_transaction2_sfi_rsp *)rsp_iov.iov_base; }cifs_small_buf_release (pSMB);
fs/smb/client/cifstransport.c +5 -195
212 lines not on this page · raw message
fs/smb/client/smb1ops.c +44 -3
65 lines not on this page · raw message
fs/smb/client/smb1proto.h +0 -3
@@ -223,8 +223,5 @@ int SendReceive2(const unsigned int xid, struct cifs_ses *ses,int SendReceive (const unsigned int xid,struct cifs_ses *ses,struct smb_hdr *in_buf,unsigned int in_len,struct smb_hdr *out_buf,int *pbytes_returned,const int flags); -int SendReceiveBlockingLock (const unsigned int xid,struct cifs_tcon *tcon, -struct smb_hdr *in_buf,unsigned int in_len, -struct smb_hdr *out_buf,int *pbytes_returned);#endif /* _SMB1PROTO_H */
fs/smb/client/transport.c +8 -2
@@ -643,12 +643,16 @@ cifs_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,int wait_for_response (struct TCP_Server_Info *server,struct smb_message *smb) { +unsigned int sleep_state =TASK_KILLABLE ;int error; +if (smb->sr_flags &CIFS_INTERRUPTIBLE_WAIT ) + sleep_state =TASK_INTERRUPTIBLE ; + error =wait_event_state (server->response_q, smb->mid_state !=MID_REQUEST_SUBMITTED && smb->mid_state !=MID_RESPONSE_RECEIVED , - (TASK_KILLABLE |TASK_FREEZABLE_UNSAFE )); + (sleep_state |TASK_FREEZABLE_UNSAFE ));if (error <0 )return -ERESTARTSYS ;
@@ -702,6 +706,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,return PTR_ERR (smb); } + smb->sr_flags = flags; smb->receive = receive; smb->callback = callback; smb->callback_data = cbdata;
@@ -946,6 +951,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,return PTR_ERR (smb[i]); } + smb[i]->sr_flags = flags; smb[i]->mid_state =MID_REQUEST_SUBMITTED ; smb[i]->optype = optype;/*
@@ -1012,7 +1018,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,for (; i < num_rqst; i++) {cifs_server_dbg (FYI ,"Cancelling wait for mid %llu cmd: %d\n" , smb[i]->mid,le16_to_cpu (smb[i]->command)); -send_cancel (server, &rqst[i], smb[i]); +send_cancel (ses, server, &rqst[i], smb[i], xid);spin_lock (&smb[i]->mid_lock); smb[i]->wait_cancelled = true; if (smb[i]->mid_state == MID_REQUEST_SUBMITTED ||
David Howells
maintainerPATCH v3 10/12 cifs: Remove the server pointer from smb_message
In reply to David HowellsRemove the server pointer from smb_message and instead pass it down to all the things that access it.
--- fs/smb/client/cifsglob.h | 10 ++++---- fs/smb/client/cifsproto.h | 21 +++++++++++------ fs/smb/client/cifssmb.c | 15 +++++------- fs/smb/client/cifstransport.c | 13 +++++------ fs/smb/client/connect.c | 34 +++++++++++++-------------- fs/smb/client/netmisc.c | 5 ++-- fs/smb/client/smb1ops.c | 4 ++-- fs/smb/client/smb2ops.c | 22 +++++++++--------- fs/smb/client/smb2pdu.c | 23 ++++++++---------- fs/smb/client/smb2transport.c | 7 +++--- fs/smb/client/transport.c | 44 ++++++++++++++++------------------- 11 files changed, 97 insertions(+), 101 deletions(-)
fs/smb/client/cifsglob.h +5 -5
@@ -1654,7 +1654,7 @@ typedef int (*mid_receive_t)(struct TCP_Server_Info *server,* - it will be called by cifsd, with no locks held * - the mid will be removed from any lists */ -typedef void (*mid_callback_t )(struct smb_message *smb); +typedef void (*mid_callback_t )(struct TCP_Server_Info *srv,struct smb_message *smb);/* * This is the protopyte for mid handle function. This is called once the mid
@@ -1666,8 +1666,7 @@ typedef int (*mid_handle_t)(struct TCP_Server_Info *server,/* one of these for every pending CIFS request to the server */ struct smb_message {struct list_head qhead;/* mids waiting on reply from this server */ -struct kref refcount; -struct TCP_Server_Info *server;/* server corresponding to this mid */ +refcount_t refcount;__u64 mid;/* multiplex id */ __u16 credits;/* number of credits consumed by this mid */ __u16 credits_received;/* number of credits from the response */
@@ -2334,7 +2333,8 @@ static inline bool cifs_netbios_name(const char *name, size_t namelen)* Execute mid callback atomically - ensures callback runs exactly once * and prevents sleeping in atomic context. */ -static inline void mid_execute_callback (struct smb_message *smb) +static inline void mid_execute_callback (struct TCP_Server_Info *server, +struct smb_message *smb) {mid_callback_t callback;
@@ -2344,7 +2344,7 @@ static inline void mid_execute_callback(struct smb_message *smb)spin_unlock (&smb->mid_lock);if (callback) -callback (smb); +callback (server, smb); }#define CIFS_REPARSE_SUPPORT (tcon) \
fs/smb/client/cifsproto.h +14 -7
@@ -132,7 +132,7 @@ int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,ssize_t cifs_discard_from_socket (struct TCP_Server_Info *server,size_t to_read);int cifs_read_iter_from_socket (struct TCP_Server_Info *server,struct iov_iter *iter,unsigned int to_read); -void dequeue_mid (struct smb_message *mid,bool malformed); +void dequeue_mid (struct TCP_Server_Info *server,struct smb_message *mid,bool malformed);int cifs_enable_signing (struct TCP_Server_Info *server,bool mnt_sign_required);int cifs_handle_standard (struct TCP_Server_Info *server,struct smb_message *mid);int cifs_ipaddr_cmp (struct sockaddr *srcaddr,struct sockaddr *rhs);
@@ -459,7 +459,8 @@ struct vfsmount *cifs_d_automount(struct path *path);int cifs_convert_address (struct sockaddr *dst,const char *src,int len);void cifs_set_port (struct sockaddr *addr,const unsigned short int port);int map_smb_to_linux_error (char *buf,bool logErr); -int map_and_check_smb_error (struct smb_message *mid,bool logErr); +int map_and_check_smb_error (struct TCP_Server_Info *server, +struct smb_message *mid,bool logErr);unsigned int smbCalcSize (void *buf);struct timespec64 cifs_NTtimeToUnix (__le64 ntutc);u64 cifs_UnixTimeToNT (struct timespec64 t);
@@ -547,9 +548,9 @@ int E_md4hash(const unsigned char *passwd, unsigned char *p16,/* * transport.c */ -void cifs_wake_up_task (struct smb_message *mid); -void __release_mid (struct kref *refcount); -void delete_mid (struct smb_message *mid); +void cifs_wake_up_task (struct TCP_Server_Info *server,struct smb_message *mid); +void __release_mid (struct TCP_Server_Info *server,struct smb_message *smb); +void delete_mid (struct TCP_Server_Info *server,struct smb_message *mid);int smb_send_kvec (struct TCP_Server_Info *server,struct msghdr *smb_msg,size_t *sent);unsigned long smb_rqst_len (struct TCP_Server_Info *server,struct smb_rqst *rqst);
@@ -710,9 +711,15 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)return true; } -static inline void release_mid (struct smb_message *smb) +static inline void smb_get_mid (struct smb_message *smb) { -kref_put (&smb->refcount, __release_mid); +refcount_inc (&smb->refcount); +} + +static inline void release_mid (struct TCP_Server_Info *server,struct smb_message *smb) +{ +if (refcount_dec_and_test (&smb->refcount)) +__release_mid (server, smb); }static inline void cifs_free_open_info (struct cifs_open_info_data *data)
fs/smb/client/cifssmb.c +6 -9
@@ -585,12 +585,11 @@ CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon)* FIXME: maybe we should consider checking that the reply matches request? */ static void -cifs_echo_callback (struct smb_message *smb) +cifs_echo_callback (struct TCP_Server_Info *server,struct smb_message *smb) { -struct TCP_Server_Info *server = smb->callback_data;struct cifs_credits credits = { .value =1 , .instance =0 }; -release_mid (smb); +release_mid (server, smb);add_credits (server, &credits,CIFS_ECHO_OP ); }
@@ -1318,12 +1317,11 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, }static void -cifs_readv_callback (struct smb_message *smb) +cifs_readv_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *rdata = smb->callback_data;struct netfs_inode *ictx =netfs_inode (rdata->rreq->inode);struct cifs_tcon *tcon =tlink_tcon (rdata->req->cfile->tlink); -struct TCP_Server_Info *server = tcon->ses->server;struct smb_rqst rqst = { .rq_iov = rdata->iov, .rq_nvec =1 , .rq_iter = rdata->subreq.io_iter };
@@ -1421,7 +1419,7 @@ cifs_readv_callback(struct smb_message *smb) rdata->subreq.transferred += rdata->got_bytes;trace_netfs_sreq (&rdata->subreq, netfs_sreq_trace_io_progress);netfs_read_subreq_terminated (&rdata->subreq); -release_mid (smb); +release_mid (server, smb);add_credits (server, &credits,0 ); trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, 0, server->credits, server->in_flight,
@@ -1737,10 +1735,9 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,* workqueue completion task. */ static void -cifs_writev_callback (struct smb_message *smb) +cifs_writev_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *wdata = smb->callback_data; -struct TCP_Server_Info *server = wdata->server;struct cifs_tcon *tcon =tlink_tcon (wdata->req->cfile->tlink);WRITE_RSP *rsp = (WRITE_RSP *)smb->resp_buf;struct cifs_credits credits = {
@@ -1804,7 +1801,7 @@ cifs_writev_callback(struct smb_message *smb) 0, cifs_trace_rw_credits_write_response_clear); wdata->credits.value =0 ;cifs_write_subrequest_terminated (wdata, result); -release_mid (smb); +release_mid (server, smb);trace_smb3_rw_credits (credits.rreq_debug_id, credits.rreq_debug_index,0 , server->credits, server->in_flight, credits.value, cifs_trace_rw_credits_write_response_add);
fs/smb/client/cifstransport.c +6 -7
@@ -46,7 +46,7 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) smb =mempool_alloc (&smb_message_pool,GFP_NOFS );memset (smb,0 ,sizeof (struct smb_message )); -kref_init (&smb->refcount); +refcount_set (&smb->refcount,1 );spin_lock_init (&smb->mid_lock); smb->mid =get_mid (smb_buffer); smb->pid = current->pid;
@@ -55,7 +55,6 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)/* easier to use jiffies */ /* when mid allocated can be before when sent */ smb->when_alloc = jiffies; - smb->server = server;/* * The default is for the mid to be synchronous, so the
@@ -120,7 +119,7 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) rc =cifs_sign_rqst (rqst, server, &smb->sequence_number);if (rc) { -release_mid (smb); +release_mid (server, smb);return ERR_PTR (rc); }
@@ -180,11 +179,11 @@ cifs_check_receive(struct smb_message *smb, struct TCP_Server_Info *server, }/* BB special case reconnect tid and uid here? */ -return map_and_check_smb_error (smb, log_error); +return map_and_check_smb_error (server, smb, log_error); }struct smb_message * -cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *ignored, +cifs_setup_request (struct cifs_ses *ses,struct TCP_Server_Info *server,struct smb_rqst *rqst) {int rc;
@@ -194,9 +193,9 @@ cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored, rc =allocate_mid (ses, hdr, &smb);if (rc)return ERR_PTR (rc); - rc =cifs_sign_rqst (rqst, ses->server, &smb->sequence_number); + rc =cifs_sign_rqst (rqst, server, &smb->sequence_number);if (rc) { -delete_mid (smb); +delete_mid (server, smb);return ERR_PTR (rc); }return smb;
fs/smb/client/connect.c +17 -17
@@ -326,7 +326,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: moving mids to private list\n" , __func__);spin_lock (&server->mid_queue_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -kref_get (&smb->refcount); +smb_get_mid (smb);if (smb->mid_state ==MID_REQUEST_SUBMITTED ) smb->mid_state =MID_RETRY_NEEDED ;list_move (&smb->qhead, &retry_list);
@@ -338,8 +338,8 @@ cifs_abort_connection(struct TCP_Server_Info *server)cifs_dbg (FYI ,"%s: issuing mid callbacks\n" , __func__);list_for_each_entry_safe (smb, nsmb, &retry_list, qhead) {list_del_init (&smb->qhead); -mid_execute_callback (smb); -release_mid (smb); +mid_execute_callback (server, smb); +release_mid (server, smb); } }
@@ -883,7 +883,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)*/ spin_lock (&server->mid_queue_lock);list_for_each_entry_safe (smb, nsmb, &server->pending_mid_q, qhead) { -kref_get (&smb->refcount); +smb_get_mid (smb);list_move (&smb->qhead, &dispose_list); smb->deleted_from_q = true; }
@@ -916,8 +916,8 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)list_del_init (&smb->qhead); smb->mid_rc = mid_rc; smb->mid_state =MID_RC ; -mid_execute_callback (smb); -release_mid (smb); +mid_execute_callback (server, smb); +release_mid (server, smb); }/*
@@ -949,12 +949,12 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) }void -dequeue_mid (struct smb_message *smb,bool malformed) +dequeue_mid (struct TCP_Server_Info *server,struct smb_message *smb,bool malformed) {#ifdef CONFIG_CIFS_STATS2 smb->when_received = jiffies;#endif -spin_lock (&smb->server->mid_queue_lock); +spin_lock (&server->mid_queue_lock);if (!malformed) smb->mid_state =MID_RESPONSE_RECEIVED ;else
@@ -964,12 +964,12 @@ dequeue_mid(struct smb_message *smb, bool malformed)* function has finished processing it is a bug. */ if (smb->deleted_from_q) { -spin_unlock (&smb->server->mid_queue_lock); +spin_unlock (&server->mid_queue_lock);pr_warn_once ("trying to dequeue a deleted mid\n" ); }else {list_del_init (&smb->qhead); smb->deleted_from_q = true; -spin_unlock (&smb->server->mid_queue_lock); +spin_unlock (&server->mid_queue_lock); } }
@@ -1005,7 +1005,7 @@ handle_mid(struct smb_message *smb, struct TCP_Server_Info *server,else server->smallbuf =NULL ; } -dequeue_mid (smb, malformed); +dequeue_mid (server, smb, malformed); }int
@@ -1102,7 +1102,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)list_for_each_safe (tmp, tmp2, &server->pending_mid_q) { smb = list_entry(tmp, struct smb_message, qhead);cifs_dbg (FYI ,"Clearing mid %llu\n" , smb->mid); -kref_get (&smb->refcount); +smb_get_mid (smb); smb->mid_state =MID_SHUTDOWN ;list_move (&smb->qhead, &dispose_list); smb->deleted_from_q = true;
@@ -1114,8 +1114,8 @@ clean_demultiplex_info(struct TCP_Server_Info *server) smb = list_entry(tmp, struct smb_message, qhead);cifs_dbg (FYI ,"Callback mid %llu\n" , smb->mid);list_del_init (&smb->qhead); -mid_execute_callback (smb); -release_mid (smb); +mid_execute_callback (server, smb); +release_mid (server, smb); }/* 1/8th of sec is more than enough time for them to exit */ msleep (125 );
@@ -1356,7 +1356,7 @@ cifs_demultiplex_thread(void *p)if (length <0 ) {for (i =0 ; i < num_smbs; i++)if (smbs[i]) -release_mid (smbs[i]); +release_mid (server, smbs[i]);continue ; }
@@ -1389,9 +1389,9 @@ cifs_demultiplex_thread(void *p) }if (!smbs[i]->multiRsp || smbs[i]->multiEnd) -mid_execute_callback (smbs[i]); +mid_execute_callback (server, smbs[i]); -release_mid (smbs[i]); +release_mid (server, smbs[i]); }else if (server->ops->is_oplock_break && server->ops->is_oplock_break (bufs[i], server)) {
fs/smb/client/netmisc.c +3 -2
@@ -889,7 +889,8 @@ map_smb_to_linux_error(char *buf, bool logErr) }int -map_and_check_smb_error (struct smb_message *smb,bool logErr) +map_and_check_smb_error (struct TCP_Server_Info *server, +struct smb_message *smb,bool logErr) {int rc;struct smb_hdr *rhdr = (struct smb_hdr *)smb->resp_buf;
@@ -904,7 +905,7 @@ map_and_check_smb_error(struct smb_message *smb, bool logErr)if (class ==ERRSRV && code == ERRbaduid) {cifs_dbg (FYI ,"Server returned 0x%x, reconnecting session...\n" , code); -cifs_signal_cifsd_for_reconnect (smb->server, false); +cifs_signal_cifsd_for_reconnect (server, false); } }
fs/smb/client/smb1ops.c +2 -2
@@ -147,7 +147,7 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer)if (compare_mid (smb->mid, buf) && smb->mid_state ==MID_REQUEST_SUBMITTED &&le16_to_cpu (smb->command) == buf->Command) { -kref_get (&smb->refcount); +smb_get_mid (smb);spin_unlock (&server->mid_queue_lock);return smb; }
@@ -449,7 +449,7 @@ cifs_check_trans2(struct smb_message *smb, struct TCP_Server_Info *server,return true;/* All parts received or packet is malformed. */ smb->multiEnd = true; -dequeue_mid (smb, malformed); +dequeue_mid (server, smb, malformed);return true; }if (!server->large_buf) {
fs/smb/client/smb2ops.c +11 -11
@@ -406,7 +406,7 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)if ((smb->mid == wire_mid) && (smb->mid_state ==MID_REQUEST_SUBMITTED ) && (smb->command == shdr->Command)) { -kref_get (&smb->refcount); +smb_get_mid (smb);if (dequeue) {list_del_init (&smb->qhead); smb->deleted_from_q = true;
@@ -4717,7 +4717,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_RECEIVED ;else -dequeue_mid (smb, false); +dequeue_mid (server, smb, false);return 0 ; }
@@ -4744,7 +4744,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }
@@ -4763,7 +4763,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }
@@ -4773,7 +4773,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }
@@ -4784,7 +4784,7 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; } rdata->got_bytes = buffer_len;
@@ -4803,14 +4803,14 @@ handle_read_data(struct TCP_Server_Info *server, struct smb_message *smb,if (is_offloaded) smb->mid_state =MID_RESPONSE_MALFORMED ;else -dequeue_mid (smb, rdata->result); +dequeue_mid (server, smb, rdata->result);return 0 ; }if (is_offloaded) smb->mid_state =MID_RESPONSE_RECEIVED ;else -dequeue_mid (smb, false); +dequeue_mid (server, smb, false);return 0 ; }
@@ -4857,7 +4857,7 @@ static void smb2_decrypt_offload(struct work_struct *work) dw->server->ops->is_network_name_deleted (dw->buf, dw->server); -mid_execute_callback (smb); +mid_execute_callback (dw->server, smb); }else {spin_lock (&dw->server->srv_lock);if (dw->server->tcpStatus == CifsNeedReconnect) {
@@ -4865,7 +4865,7 @@ static void smb2_decrypt_offload(struct work_struct *work) smb->mid_state =MID_RETRY_NEEDED ;spin_unlock (&dw->server->mid_queue_lock);spin_unlock (&dw->server->srv_lock); -mid_execute_callback (smb); +mid_execute_callback (dw->server, smb); }else {spin_lock (&dw->server->mid_queue_lock); smb->mid_state =MID_REQUEST_SUBMITTED ;
@@ -4876,7 +4876,7 @@ static void smb2_decrypt_offload(struct work_struct *work)spin_unlock (&dw->server->srv_lock); } } -release_mid (smb); +release_mid (dw->server, smb); } free_pages:
fs/smb/client/smb2pdu.c +10 -13
@@ -4092,9 +4092,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 };
@@ -4104,7 +4103,7 @@ smb2_echo_callback(struct smb_message *smb) credits.instance = server->reconnect_instance; } -release_mid (smb); +release_mid (server, smb);add_credits (server, &credits,CIFS_ECHO_OP ); }
@@ -4519,12 +4518,11 @@ smb2_new_read_req(void **buf, unsigned int *total_len, }static void -smb2_readv_callback (struct smb_message *smb) +smb2_readv_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *rdata = smb->callback_data;struct netfs_inode *ictx =netfs_inode (rdata->rreq->inode);struct cifs_tcon *tcon =tlink_tcon (rdata->req->cfile->tlink); -struct TCP_Server_Info *server = rdata->server;struct smb2_hdr *shdr = (struct smb2_hdr *)rdata->iov[0 ].iov_base;struct cifs_credits credits = { .value =0 ,
@@ -4540,9 +4538,9 @@ smb2_readv_callback(struct smb_message *smb) rqst.rq_iter = rdata->subreq.io_iter; } -WARN_ONCE (rdata->server != smb->server, +WARN_ONCE (rdata->server != server,"rdata server %p != mid server %p" , - rdata->server, smb->server); + rdata->server, server); cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%zu/%zu\n", __func__, smb->mid, smb->mid_state, rdata->result,
@@ -4643,7 +4641,7 @@ smb2_readv_callback(struct smb_message *smb) rdata->subreq.transferred += rdata->got_bytes;trace_netfs_sreq (&rdata->subreq, netfs_sreq_trace_io_progress);netfs_read_subreq_terminated (&rdata->subreq); -release_mid (smb); +release_mid (server, smb);trace_smb3_rw_credits (rreq_debug_id, subreq_debug_index,0 , server->credits, server->in_flight, credits.value, cifs_trace_rw_credits_read_response_add);
@@ -4820,11 +4818,10 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,* workqueue completion task. */ static void -smb2_writev_callback (struct smb_message *smb) +smb2_writev_callback (struct TCP_Server_Info *server,struct smb_message *smb) {struct cifs_io_subrequest *wdata = smb->callback_data;struct cifs_tcon *tcon =tlink_tcon (wdata->req->cfile->tlink); -struct TCP_Server_Info *server = wdata->server;struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)smb->resp_buf;struct cifs_credits credits = { .value =0 ,
@@ -4837,9 +4834,9 @@ smb2_writev_callback(struct smb_message *smb)ssize_t result =0 ;size_t written; -WARN_ONCE (wdata->server != smb->server, +WARN_ONCE (wdata->server != server,"wdata server %p != mid server %p" , - wdata->server, smb->server); + wdata->server, server);switch (smb->mid_state) {case MID_RESPONSE_RECEIVED :
@@ -4929,7 +4926,7 @@ smb2_writev_callback(struct smb_message *smb) 0, cifs_trace_rw_credits_write_response_clear); wdata->credits.value =0 ;cifs_write_subrequest_terminated (wdata, result ?: written); -release_mid (smb); +release_mid (server, smb);trace_smb3_rw_credits (rreq_debug_id, subreq_debug_index,0 , server->credits, server->in_flight, credits.value, cifs_trace_rw_credits_write_response_add);
fs/smb/client/smb2transport.c +3 -4
@@ -655,14 +655,13 @@ smb2_mid_entry_alloc(const struct smb2_hdr *shdr, smb =mempool_alloc (&smb_message_pool,GFP_NOFS );memset (smb,0 ,sizeof (*smb)); -kref_init (&smb->refcount); +refcount_set (&smb->refcount,1 );spin_lock_init (&smb->mid_lock); smb->mid =le64_to_cpu (shdr->MessageId); smb->credits = credits >0 ? credits :1 ; smb->pid = current->pid; smb->command = shdr->Command;/* Always LE */ smb->when_alloc = jiffies; - smb->server = server;/* * The default is for the mid to be synchronous, so the
@@ -779,7 +778,7 @@ smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server, rc =smb2_sign_rqst (rqst, server);if (rc) {revert_current_mid_from_hdr (server, shdr); -delete_mid (mid); +delete_mid (server, mid);return ERR_PTR (rc); }
@@ -813,7 +812,7 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) rc =smb2_sign_rqst (rqst, server);if (rc) {revert_current_mid_from_hdr (server, shdr); -release_mid (smb); +release_mid (server, smb);return ERR_PTR (rc); }
fs/smb/client/transport.c +20 -24
127 lines not on this page · raw message
David Howells
maintainerPATCH v3 11/12 cifs: Don't need state locking in smb2_get_mid_entry()
In reply to David HowellsThere's no need to get ->srv_lock or ->ses_lock in smb2_get_mid_entry() as all that happens of relevance (to the lock) inside the locked sections is the reading of one status value in each.
Replace the locking with READ_ONCE() and use a switch instead of a chain of if-statements.
--- fs/smb/client/smb2transport.c | 48 +++++++++++++++-------------------- 1 file changed, 20 insertions(+), 28 deletions(-)
fs/smb/client/smb2transport.c +20 -28
@@ -684,43 +684,35 @@ static int smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, struct smb2_hdr *shdr, struct smb_message **smb) { - spin_lock(&server->srv_lock); -if (server->tcpStatus == CifsExiting) { -spin_unlock (&server->srv_lock); + switch (READ_ONCE(server->tcpStatus)) { + case CifsExiting: return -ENOENT; - } - -if (server->tcpStatus == CifsNeedReconnect) { -spin_unlock (&server->srv_lock); +case CifsNeedReconnect:cifs_dbg (FYI ,"tcp session dead - return to caller to retry\n" );return -EAGAIN ; - } - -if (server->tcpStatus == CifsNeedNegotiate && - shdr->Command !=SMB2_NEGOTIATE ) { -spin_unlock (&server->srv_lock); -return -EAGAIN ; - } -spin_unlock (&server->srv_lock); - -spin_lock (&ses->ses_lock); -if (ses->ses_status ==SES_NEW ) { -if ((shdr->Command !=SMB2_SESSION_SETUP ) && - (shdr->Command !=SMB2_NEGOTIATE )) { -spin_unlock (&ses->ses_lock); +case CifsNeedNegotiate: +if (shdr->Command !=SMB2_NEGOTIATE )return -EAGAIN ; - } -/* else ok - we are setting up session */ +break ; +default : +break ; } -if (ses->ses_status ==SES_EXITING ) { -if (shdr->Command !=SMB2_LOGOFF ) { -spin_unlock (&ses->ses_lock); +switch (READ_ONCE (ses->ses_status)) { +case SES_NEW : +if (shdr->Command !=SMB2_SESSION_SETUP && + shdr->Command !=SMB2_NEGOTIATE ) +return -EAGAIN ; +/* else ok - we are setting up session */ +break ; +case SES_EXITING : +if (shdr->Command !=SMB2_LOGOFF )return -EAGAIN ; - }/* else ok - we are shutting down the session */ +break ; +default : +break ; } -spin_unlock (&ses->ses_lock); *smb =smb2_mid_entry_alloc (shdr, server);if (*smb ==NULL )
David Howells
maintainerPATCH v3 12/12 cifs: Add a tracepoint to log EIO errors
In reply to David HowellsAdd a tracepoint to log EIO errors and give it the capacity to convey up to two integers of information. This is then wrapped with three functions:
int smb_EIO(enum smb_eio_trace trace)
int smb_EIO1(enum smb_eio_trace trace, unsigned long info) int smb_EIO2(enum smb_eio_trace trace, unsigned long info,
unsigned long info2)
depending on how many bits of info are desired to be logged with any particular trace. The functions all return -EIO and can be used in place of -EIO.
The trace argument is an enum value that gets translated to a string when the trace is printed.
This makes is easier to log EIO instances when the client is under high load than turning on a printk wrapper such as cifs_dbg(). Granted, EIO could have its own separate EIO printing since EIO shouldn't happen.
--- fs/smb/client/cached_dir.c | 2 +- fs/smb/client/cifsacl.c | 10 +- fs/smb/client/cifsencrypt.c | 13 ++- fs/smb/client/cifsglob.h | 88 ----------------- fs/smb/client/cifsproto.h | 106 ++++++++++++++++++++ fs/smb/client/cifssmb.c | 147 ++++++++++++++++++---------- fs/smb/client/cifstransport.c | 8 +- fs/smb/client/compress.c | 2 +- fs/smb/client/connect.c | 11 ++- fs/smb/client/dir.c | 6 +- fs/smb/client/file.c | 6 +- fs/smb/client/inode.c | 14 +-- fs/smb/client/link.c | 10 +- fs/smb/client/misc.c | 18 ++-- fs/smb/client/netmisc.c | 4 + fs/smb/client/readdir.c | 2 +- fs/smb/client/reparse.c | 53 ++++++---- fs/smb/client/sess.c | 8 +- fs/smb/client/smb2file.c | 6 +- fs/smb/client/smb2inode.c | 12 ++- fs/smb/client/smb2maperror.c | 3 + fs/smb/client/smb2ops.c | 41 +++++--- fs/smb/client/smb2pdu.c | 177 +++++++++++++++++++++------------- fs/smb/client/smb2transport.c | 2 +- fs/smb/client/smbdirect.c | 18 ++-- fs/smb/client/trace.h | 153 +++++++++++++++++++++++++++++ fs/smb/client/transport.c | 21 ++-- fs/smb/client/xattr.c | 2 +- 28 files changed, 622 insertions(+), 321 deletions(-)
fs/smb/client/cached_dir.c +1 -1
@@ -175,7 +175,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, server =cifs_pick_channel (ses);if (!server->ops->new_lease_key) -return -EIO ; +return smb_EIO (smb_eio_trace_no_lease_key); utf16_path =cifs_convert_path_to_utf16 (path, cifs_sb);if (!utf16_path)
fs/smb/client/cifsacl.c +6 -4
@@ -301,7 +301,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) __func__, sidtype == SIDOWNER ? 'u' : 'g', cid); goto out_revert_creds; }else if (sidkey->datalen <CIFS_SID_BASE_SIZE ) { - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_malformed_sid_key, sidkey->datalen);cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%hu)\n" , __func__, sidkey->datalen); goto invalidate_key;
@@ -318,7 +318,8 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) ksid_size =CIFS_SID_BASE_SIZE + (ksid->num_subauth *sizeof (__le32));if (ksid_size > sidkey->datalen) { - rc = -EIO ; + rc =smb_EIO2 (smb_eio_trace_malformed_ksid_key, + ksid_size, sidkey->datalen);cifs_dbg (FYI ,"%s: Downcall contained malformed key (datalen=%hu, ksid_size=%u)\n" , __func__, sidkey->datalen, ksid_size); goto invalidate_key;
@@ -353,7 +354,8 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid,if (unlikely (psid->num_subauth >SID_MAX_SUB_AUTHORITIES )) {cifs_dbg (FYI ,"%s: %u subauthorities is too many!\n" , __func__, psid->num_subauth); -return -EIO ; +return smb_EIO2 (smb_eio_trace_sid_too_many_auth, + psid->num_subauth,SID_MAX_SUB_AUTHORITIES ); } if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) ||
@@ -1228,7 +1230,7 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,__u32 dacloffset;if (pntsd ==NULL ) -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); owner_sid_ptr = (struct smb_sid *)((char *)pntsd +le32_to_cpu (pntsd->osidoffset));
fs/smb/client/cifsencrypt.c +8 -5
@@ -75,11 +75,13 @@ static int cifs_sig_iter(const struct iov_iter *iter, size_t maxsize, struct cifs_calc_sig_ctx *ctx) {struct iov_iter tmp_iter = *iter; -int err = -EIO ; +size_t did; +int err; -if (iterate_and_advance_kernel (&tmp_iter, maxsize, ctx, &err, - cifs_sig_step) != maxsize) -return err; + did =iterate_and_advance_kernel (&tmp_iter, maxsize, ctx, &err, + cifs_sig_step); +if (did != maxsize) +return smb_EIO2 (smb_eio_trace_sig_iter, did, maxsize);return 0 ; }
@@ -96,7 +98,8 @@ int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,iov_iter_kvec (&iter,ITER_SOURCE , rqst->rq_iov, rqst->rq_nvec, size);if (iov_iter_count (&iter) <=4 ) -return -EIO ; +return smb_EIO2 (smb_eio_trace_sig_data_too_small, +iov_iter_count (&iter),4 ); rc =cifs_sig_iter (&iter,iov_iter_count (&iter), ctx);if (rc <0 )
fs/smb/client/cifsglob.h +0 -88
94 lines not on this page · raw message
fs/smb/client/cifsproto.h +106 -0
110 lines not on this page · raw message
fs/smb/client/cifssmb.c +94 -53
430 lines not on this page · raw message
fs/smb/client/cifstransport.c +4 -4
@@ -228,15 +228,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,int rc =0 ;if (WARN_ON_ONCE (in_len >0xffffff )) -return -EIO ; +return smb_EIO1 (smb_eio_trace_tx_too_long, in_len);if (ses ==NULL ) {cifs_dbg (VFS ,"Null smb session\n" ); -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); } server = ses->server;if (server ==NULL ) {cifs_dbg (VFS ,"Null tcp session\n" ); -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); }/* Ensure that we do not send more than 50 overlapping requests
@@ -246,7 +246,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,if (in_len > CIFSMaxBufSize +MAX_CIFS_HDR_SIZE ) {cifs_server_dbg (VFS ,"Invalid length, greater than maximum frame, %d\n" , in_len); -return -EIO ; +return smb_EIO1 (smb_eio_trace_tx_too_long, in_len); } rc = cifs_send_recv(xid, ses, ses->server,
fs/smb/client/compress.c +1 -1
@@ -325,7 +325,7 @@ int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq, compress_s iter = rq->rq_iter;if (!copy_from_iter_full (src, slen, &iter)) { - ret = -EIO ; + ret =smb_EIO (smb_eio_trace_compress_copy); goto err_free; }
fs/smb/client/connect.c +6 -5
@@ -3241,7 +3241,7 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)if (be16_to_cpu (resp.length) !=0 ) {cifs_dbg (VFS ,"RFC 1002 positive session response but with invalid non-zero length %u\n" ,be16_to_cpu (resp.length)); -return -EIO ; +return smb_EIO (smb_eio_trace_rx_pos_sess_resp); }cifs_dbg (FYI ,"RFC 1002 positive session response" );break ;
@@ -3280,17 +3280,18 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)break ;case RFC1002_INSUFFICIENT_RESOURCE :/* remote server resource error */ +smb_EIO (smb_eio_trace_rx_insuff_res); rc = -EREMOTEIO ;break ;case RFC1002_UNSPECIFIED_ERROR :default :/* other/unknown error */ - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_rx_unspec_error);break ; } }else {cifs_dbg (VFS ,"RFC 1002 negative session response\n" ); - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_rx_neg_sess_resp); }return rc;case RFC1002_RETARGET_SESSION_RESPONSE :
@@ -3312,7 +3313,7 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)return -EMULTIHOP ;default :cifs_dbg (VFS ,"RFC 1002 unknown response type 0x%x\n" , resp.type); -return -EIO ; +return smb_EIO1 (smb_eio_trace_rx_unknown_resp, resp.type); } server->with_rfc1001 = true;
@@ -4002,7 +4003,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,__u16 bytes_left, count;if (ses ==NULL ) -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); smb_buffer =cifs_buf_get ();if (smb_buffer ==NULL )
fs/smb/client/dir.c +3 -3
@@ -472,7 +472,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,struct cifs_open_info_data buf = {};if (unlikely (cifs_forced_shutdown (CIFS_SB (inode->i_sb)))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);/* * Posix open is only called (at lookup time) for file create now. For
@@ -590,7 +590,7 @@ int cifs_create(struct mnt_idmap *idmap, struct inode *inode, inode, direntry, direntry);if (unlikely (cifs_forced_shutdown (CIFS_SB (inode->i_sb)))) { - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_forced_shutdown); goto out_free_xid; }
@@ -632,7 +632,7 @@ int cifs_mknod(struct mnt_idmap *idmap, struct inode *inode, cifs_sb =CIFS_SB (inode->i_sb);if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown); tlink =cifs_sb_tlink (cifs_sb);if (IS_ERR (tlink))
fs/smb/client/file.c +3 -3
@@ -118,7 +118,7 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq)int rc;if (cifs_forced_shutdown (sbi)) { - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_forced_shutdown); goto fail; }
@@ -286,7 +286,7 @@ static int cifs_init_request(struct netfs_io_request *rreq, struct file *file) req->pid = req->cfile->pid; }else if (rreq->origin !=NETFS_WRITEBACK ) {WARN_ON_ONCE (1 ); -return -EIO ; +return smb_EIO1 (smb_eio_trace_not_netfs_writeback, rreq->origin); }return 0 ;
@@ -1036,7 +1036,7 @@ int cifs_open(struct inode *inode, struct file *file) cifs_sb =CIFS_SB (inode->i_sb);if (unlikely (cifs_forced_shutdown (cifs_sb))) {free_xid (xid); -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown); } tlink =cifs_sb_tlink (cifs_sb);
fs/smb/client/inode.c +7 -7
@@ -1952,7 +1952,7 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyrencifs_dbg (FYI ,"cifs_unlink, dir=0x%p, dentry=0x%p\n" , dir, dentry);if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);/* Unhash dentry in advance to prevent any concurrent opens */ spin_lock (&dentry->d_lock);
@@ -2268,7 +2268,7 @@ struct dentry *cifs_mkdir(struct mnt_idmap *idmap, struct inode *inode, cifs_sb =CIFS_SB (inode->i_sb);if (unlikely (cifs_forced_shutdown (cifs_sb))) -return ERR_PTR (-EIO ); +return ERR_PTR (smb_EIO (smb_eio_trace_forced_shutdown)); tlink =cifs_sb_tlink (cifs_sb);if (IS_ERR (tlink))return ERR_CAST (tlink);
@@ -2354,7 +2354,7 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry) cifs_sb =CIFS_SB (inode->i_sb);if (unlikely (cifs_forced_shutdown (cifs_sb))) { - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_forced_shutdown); goto rmdir_exit; }
@@ -2516,7 +2516,7 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir, cifs_sb =CIFS_SB (source_dir->i_sb);if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);/* * Prevent any concurrent opens on the target by unhashing the dentry.
@@ -2901,7 +2901,7 @@ int cifs_getattr(struct mnt_idmap *idmap, const struct path *path,int rc;if (unlikely (cifs_forced_shutdown (CIFS_SB (inode->i_sb)))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);/* * We need to be sure that all dirty pages are written and the server
@@ -2976,7 +2976,7 @@ int cifs_fiemap(struct inode *inode, struct fiemap_extent_info *fei, u64 start,int rc;if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);/* * We need to be sure that all dirty pages are written as they
@@ -3468,7 +3468,7 @@ cifs_setattr(struct mnt_idmap *idmap, struct dentry *direntry,#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);/* * Avoid setting [cm]time with O_TRUNC to prevent the server from * disabling automatic timestamp updates as specified in
fs/smb/client/link.c +6 -4
@@ -161,7 +161,8 @@ create_mf_symlink(const unsigned int xid, struct cifs_tcon *tcon, goto out;if (bytes_written !=CIFS_MF_SYMLINK_FILE_SIZE ) - rc = -EIO ; + rc =smb_EIO2 (smb_eio_trace_symlink_file_size, + bytes_written,CIFS_MF_SYMLINK_FILE_SIZE ); out:kfree (buf);return rc;
@@ -425,7 +426,8 @@ smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,/* Make sure we wrote all of the symlink data */ if ((rc ==0 ) && (*pbytes_written !=CIFS_MF_SYMLINK_FILE_SIZE )) - rc = -EIO ; + rc =smb_EIO2 (smb_eio_trace_short_symlink_write, + *pbytes_written,CIFS_MF_SYMLINK_FILE_SIZE );SMB2_close (xid, tcon, fid.persistent_fid, fid.volatile_fid);
@@ -452,7 +454,7 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,struct cifsInodeInfo *cifsInode;if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown); tlink =cifs_sb_tlink (cifs_sb);if (IS_ERR (tlink))
@@ -554,7 +556,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,struct inode *newinode =NULL ;if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown); page =alloc_dentry_path ();if (!page)
fs/smb/client/misc.c +12 -6
@@ -380,25 +380,29 @@ checkSMB(char *buf, unsigned int pdu_len, unsigned int total_read,return 0 ; }cifs_dbg (VFS ,"rcvd invalid byte count (bcc)\n" ); +return smb_EIO1 (smb_eio_trace_rx_inv_bcc, tmp[sizeof (struct smb_hdr )]); }else {cifs_dbg (VFS ,"Length less than smb header size\n" ); +return smb_EIO2 (smb_eio_trace_rx_too_short, + total_read, smb->WordCount); } -return -EIO ; }else if (total_read <sizeof (*smb) +2 * smb->WordCount) {cifs_dbg (VFS ,"%s: can't read BCC due to invalid WordCount(%u)\n" , __func__, smb->WordCount); -return -EIO ; +return smb_EIO2 (smb_eio_trace_rx_check_rsp, + total_read,2 +sizeof (struct smb_hdr )); }/* otherwise, there is enough to get to the BCC */ if (check_smb_hdr (smb)) -return -EIO ; +return smb_EIO1 (smb_eio_trace_rx_rfc1002_magic, *(u32 *)smb->Protocol); clc_len =smbCalcSize (smb);if (rfclen != total_read) {cifs_dbg (VFS ,"Length read does not match RFC1001 length %d/%d\n" , rfclen, total_read); -return -EIO ; +return smb_EIO2 (smb_eio_trace_rx_check_rsp, + total_read, rfclen); }if (rfclen != clc_len) {
@@ -415,7 +419,8 @@ checkSMB(char *buf, unsigned int pdu_len, unsigned int total_read,if (rfclen < clc_len) {cifs_dbg (VFS ,"RFC1001 size %u smaller than SMB for mid=%u\n" , rfclen, mid); -return -EIO ; +return smb_EIO2 (smb_eio_trace_rx_calc_len_too_big, + rfclen, clc_len); }else if (rfclen > clc_len +512 ) {/* * Some servers (Windows XP in particular) send more
@@ -428,7 +433,8 @@ checkSMB(char *buf, unsigned int pdu_len, unsigned int total_read,*/ cifs_dbg (VFS ,"RFC1001 size %u more than 512 bytes larger than SMB for mid=%u\n" , rfclen, mid); -return -EIO ; +return smb_EIO2 (smb_eio_trace_rx_overlong, + rfclen, clc_len +512 ); } }return 0 ;
fs/smb/client/netmisc.c +4 -0
@@ -885,6 +885,10 @@ map_smb_to_linux_error(char *buf, bool logErr)/* generic corrective action e.g. reconnect SMB session on * ERRbaduid could be added */ +if (rc == -EIO ) +smb_EIO2 (smb_eio_trace_smb1_received_error, +le32_to_cpu (smb->Status.CifsError), +le16_to_cpu (smb->Flags2));return rc; }
fs/smb/client/readdir.c +1 -1
@@ -775,7 +775,7 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,if (cfile->srch_inf.ntwrk_buf_start ==NULL ) {cifs_dbg (VFS ,"ntwrk_buf_start is NULL during readdir\n" ); -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); } end_of_smb = cfile->srch_inf.ntwrk_buf_start +
fs/smb/client/reparse.c +33 -20
132 lines not on this page · raw message
fs/smb/client/sess.c +4 -4
@@ -1504,7 +1504,7 @@ sess_auth_ntlmv2(struct sess_data *sess_data) smb_buf = (struct smb_hdr *)sess_data->iov[0 ].iov_base;if (smb_buf->WordCount !=3 ) { - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_sess_nl2_wcc, smb_buf->WordCount);cifs_dbg (VFS ,"bad word count %d\n" , smb_buf->WordCount); goto out; }
@@ -1630,7 +1630,7 @@ sess_auth_kerberos(struct sess_data *sess_data) smb_buf = (struct smb_hdr *)sess_data->iov[0 ].iov_base;if (smb_buf->WordCount !=4 ) { - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_sess_krb_wcc, smb_buf->WordCount);cifs_dbg (VFS ,"bad word count %d\n" , smb_buf->WordCount); goto out_put_spnego_key; }
@@ -1791,7 +1791,7 @@ sess_auth_rawntlmssp_negotiate(struct sess_data *sess_data)cifs_dbg (FYI ,"rawntlmssp session setup challenge phase\n" );if (smb_buf->WordCount !=4 ) { - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_sess_rawnl_neg_wcc, smb_buf->WordCount);cifs_dbg (VFS ,"bad word count %d\n" , smb_buf->WordCount); goto out_free_ntlmsspblob; }
@@ -1881,7 +1881,7 @@ sess_auth_rawntlmssp_authenticate(struct sess_data *sess_data) pSMB = (SESSION_SETUP_ANDX *)sess_data->iov[0 ].iov_base; smb_buf = (struct smb_hdr *)sess_data->iov[0 ].iov_base;if (smb_buf->WordCount !=4 ) { - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_sess_rawnl_auth_wcc, smb_buf->WordCount);cifs_dbg (VFS ,"bad word count %d\n" , smb_buf->WordCount); goto out_free_ntlmsspblob; }
fs/smb/client/smb2file.c +3 -3
@@ -76,11 +76,11 @@ int smb2_fix_symlink_target_type(char **target, bool directory, struct cifs_sb_ireturn 0 ;if (!*target) -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); len =strlen (*target);if (!len) -return -EIO ; +return smb_EIO1 (smb_eio_trace_sym_target_len, len);/* * If this is directory symlink and it does not have trailing slash then
@@ -104,7 +104,7 @@ int smb2_fix_symlink_target_type(char **target, bool directory, struct cifs_sb_i* both Windows and Linux systems. So return an error for such symlink. */ if (!directory && (*target)[len-1 ] =='/' ) -return -EIO ; +return smb_EIO (smb_eio_trace_sym_slash);return 0 ; }
fs/smb/client/smb2inode.c +8 -4
@@ -31,16 +31,20 @@ static struct reparse_data_buffer *reparse_buf_ptr(struct kvec *iov)struct reparse_data_buffer *buf;struct smb2_ioctl_rsp *io = iov->iov_base;u32 off, count, len; +u16 rdlen; count =le32_to_cpu (io->OutputCount); off =le32_to_cpu (io->OutputOffset);if (check_add_overflow (off, count, &len) || len > iov->iov_len) -return ERR_PTR (-EIO ); +return ERR_PTR (smb_EIO2 (smb_eio_trace_reparse_overlong, + off, count)); buf = (struct reparse_data_buffer *)((u8 *)io + off); len =sizeof (*buf); -if (count < len || count <le16_to_cpu (buf->ReparseDataLength) + len) -return ERR_PTR (-EIO ); + rdlen =le16_to_cpu (buf->ReparseDataLength); + +if (count < len || count < rdlen + len) +return ERR_PTR (smb_EIO2 (smb_eio_trace_reparse_rdlen, count, rdlen));return buf; }
@@ -1635,7 +1639,7 @@ int smb2_rename_pending_delete(const char *full_path, }else {cifs_tcon_dbg (FYI ,"%s: failed to rename '%s' to '%s': %d\n" , __func__, full_path, to_name, rc); - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_pend_del_fail, rc); } out:cifs_put_tlink (tlink);
fs/smb/client/smb2maperror.c +3 -0
@@ -9,6 +9,7 @@*/ #include <linux/errno.h> #include "cifsglob.h" +#include "cifsproto.h" #include "cifs_debug.h" #include "smb2pdu.h" #include "smb2proto.h"
@@ -2477,5 +2478,7 @@ map_smb2_to_linux_error(char *buf, bool log_err)le16_to_cpu (shdr->Command),le64_to_cpu (shdr->MessageId), le32_to_cpu(smb2err), rc); +if (rc == -EIO ) +smb_EIO1 (smb_eio_trace_smb2_received_error,le32_to_cpu (smb2err));return rc; }
fs/smb/client/smb2ops.c +25 -16
111 lines not on this page · raw message
fs/smb/client/smb2pdu.c +108 -69
425 lines not on this page · raw message
fs/smb/client/smb2transport.c +1 -1
@@ -153,7 +153,7 @@ static int smb2_get_sign_key(struct TCP_Server_Info *server,memcpy (key, ses->auth_key.response,SMB2_NTLMV2_SESSKEY_SIZE ); }else { - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_no_auth_key); }break ;default :
fs/smb/client/smbdirect.c +9 -9
@@ -979,7 +979,7 @@ static int smbd_post_send_negotiate_req(struct smbdirect_socket *sc) sc->ib.dev, (void *)packet, sizeof(*packet), DMA_TO_DEVICE);if (ib_dma_mapping_error (sc->ib.dev, request->sge[0 ].addr)) { - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_rdma_dma_map); goto dma_mapping_failed; }
@@ -1179,7 +1179,7 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc, header_length, DMA_TO_DEVICE);if (ib_dma_mapping_error (sc->ib.dev, request->sge[0 ].addr)) { - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_rdma_dma_map); goto err_dma; }
@@ -1321,13 +1321,13 @@ static int smbd_post_recv( {struct smbdirect_socket_parameters *sp = &sc->parameters;struct ib_recv_wr recv_wr; -int rc = -EIO ; +int rc; response->sge.addr =ib_dma_map_single ( sc->ib.dev, response->packet, sp->max_recv_size,DMA_FROM_DEVICE );if (ib_dma_mapping_error (sc->ib.dev, response->sge.addr)) -return rc; +return smb_EIO (smb_eio_trace_rdma_dma_map); response->sge.length = sp->max_recv_size; response->sge.lkey = sc->ib.pd->local_dma_lkey;
@@ -2855,7 +2855,7 @@ static ssize_t smb_extract_bvec_to_rdma(struct iov_iter *iter, off = bv[i].bv_offset + start;if (!smb_set_sge (rdma, bv[i].bv_page, off, len)) -return -EIO ; +return smb_EIO (smb_eio_trace_rdma_set_sge); ret += len; maxsize -= len;
@@ -2909,7 +2909,7 @@ static ssize_t smb_extract_kvec_to_rdma(struct iov_iter *iter, page =virt_to_page ((void *)kaddr);if (!smb_set_sge (rdma, page, off, seg)) -return -EIO ; +return smb_EIO (smb_eio_trace_rdma_set_sge); ret += seg; len -= seg;
@@ -2945,7 +2945,7 @@ static ssize_t smb_extract_folioq_to_rdma(struct iov_iter *iter,if (slot >=folioq_nr_slots (folioq)) { folioq = folioq->next;if (WARN_ON_ONCE (!folioq)) -return -EIO ; +return smb_EIO (smb_eio_trace_rdma_fq_overrun); slot =0 ; }
@@ -2957,7 +2957,7 @@ static ssize_t smb_extract_folioq_to_rdma(struct iov_iter *iter,size_t part =umin (maxsize, fsize - offset);if (!smb_set_sge (rdma,folio_page (folio,0 ), offset, part)) -return -EIO ; +return smb_EIO (smb_eio_trace_rdma_set_sge); offset += part; ret += part;
@@ -3014,7 +3014,7 @@ static ssize_t smb_extract_iter_to_rdma(struct iov_iter *iter, size_t len,break ;default :WARN_ON_ONCE (1 ); -return -EIO ; +return smb_EIO (smb_eio_trace_rdma_iter_type); }if (ret <0 ) {
fs/smb/client/trace.h +153 -0
177 lines not on this page · raw message
fs/smb/client/transport.c +12 -9
@@ -402,11 +402,11 @@ smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,return __smb_send_rqst (server, num_rqst, rqst);if (WARN_ON_ONCE (num_rqst >MAX_COMPOUND -1 )) -return -EIO ; +return smb_EIO1 (smb_eio_trace_tx_max_compound, num_rqst);if (!server->ops->init_transform_rq) {cifs_server_dbg (VFS ,"Encryption requested but transform callback is missing\n" ); -return -EIO ; +return smb_EIO (smb_eio_trace_tx_need_transform); } new_rqst[0 ].rq_iov = &iov;
@@ -753,7 +753,7 @@ int cifs_sync_mid_result(struct smb_message *smb, struct TCP_Server_Info *server rc = -EAGAIN ;break ;case MID_RESPONSE_MALFORMED : - rc = -EIO ; + rc =smb_EIO (smb_eio_trace_rx_sync_mid_malformed);break ;case MID_SHUTDOWN : rc = -EHOSTDOWN ;
@@ -769,7 +769,7 @@ int cifs_sync_mid_result(struct smb_message *smb, struct TCP_Server_Info *serverspin_unlock (&server->mid_queue_lock);cifs_server_dbg (VFS ,"%s: invalid mid state mid=%llu state=%d\n" , __func__, smb->mid, smb->mid_state); - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_rx_sync_mid_invalid, smb->mid_state); goto sync_mid_done; }spin_unlock (&server->mid_queue_lock);
@@ -883,7 +883,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,if (!ses || !ses->server || !server) {cifs_dbg (VFS ,"Null session\n" ); -return -EIO ; +return smb_EIO (smb_eio_trace_null_pointers); }spin_lock (&server->srv_lock);
@@ -1040,7 +1040,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,if (!smb[i]->resp_buf || smb[i]->mid_state !=MID_RESPONSE_READY ) { - rc = -EIO ; + rc =smb_EIO1 (smb_eio_trace_rx_mid_unready, smb[i]->mid_state);cifs_dbg (FYI ,"Bad MID state?\n" ); goto out; }
@@ -1212,7 +1212,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct smb_message *smb)cifs_dbg (FYI ,"%s: server returned short header. got=%u expected=%zu\n" , __func__, server->total_read, server->vals->read_rsp_size); - rdata->result = -EIO ; + rdata->result =smb_EIO2 (smb_eio_trace_read_rsp_short, + server->total_read, server->vals->read_rsp_size);return cifs_readv_discard (server, smb); }
@@ -1230,7 +1231,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct smb_message *smb)/* data_offset is beyond the end of smallbuf */ cifs_dbg (FYI ,"%s: data offset (%u) beyond end of smallbuf\n" , __func__, data_offset); - rdata->result = -EIO ; + rdata->result =smb_EIO1 (smb_eio_trace_read_overlarge, + data_offset);return cifs_readv_discard (server, smb); }
@@ -1254,7 +1256,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct smb_message *smb) data_len = server->ops->read_data_length (buf, use_rdma_mr);if (!use_rdma_mr && (data_offset + data_len > buflen)) {/* data_len is corrupt -- discard frame */ - rdata->result = -EIO ; + rdata->result =smb_EIO2 (smb_eio_trace_read_rsp_malformed, + data_offset + data_len, buflen);return cifs_readv_discard (server, smb); }
fs/smb/client/xattr.c +1 -1
@@ -397,7 +397,7 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)void *page;if (unlikely (cifs_forced_shutdown (cifs_sb))) -return -EIO ; +return smb_EIO (smb_eio_trace_forced_shutdown);if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NO_XATTR )return -EOPNOTSUPP ;