cifs.ko fixes
Subsystems (2)
cover cifs.ko fixes
Hi Steve,
Follow patchset with DFS, reparse point and -Wframe-larger-than fixes for v6.6.
Please review & test.
Paulo Alcantara (17):
smb: client: introduce DFS_CACHE_TGT_LIST()
smb: client: ensure to try all targets when finding nested links
smb: client: move some params to cifs_open_info_data
smb: client: make smb2_compound_op() return resp buffer on success
smb: client: rename cifs_dfs_ref.c to namespace.c
smb: client: get rid of dfs naming in automount code
smb: client: get rid of dfs code dep in namespace.c
smb: client: parse reparse point flag in create response
smb: client: do not query reparse points twice on symlinks
smb: client: query reparse points in older dialects
smb: cilent: set reparse mount points as automounts
smb: client: reduce stack usage in cifs_try_adding_channels()
smb: client: reduce stack usage in cifs_demultiplex_thread()
smb: client: reduce stack usage in smb_send_rqst()
smb: client: reduce stack usage in smb2_set_ea()
smb: client: reduce stack usage in smb2_query_info_compound()
smb: client: reduce stack usage in smb2_query_reparse_point()
fs/smb/client/Makefile | 5 +-
fs/smb/client/cifsfs.c | 2 +-
fs/smb/client/cifsfs.h | 11 +-
fs/smb/client/cifsglob.h | 69 ++-
fs/smb/client/cifsproto.h | 9 +-
fs/smb/client/connect.c | 8 +-
fs/smb/client/dfs.c | 291 +++++-----
fs/smb/client/dfs.h | 141 +++--
fs/smb/client/dfs_cache.c | 10 +-
fs/smb/client/dfs_cache.h | 12 +-
fs/smb/client/dir.c | 4 +-
fs/smb/client/inode.c | 530 ++++++++++--------
fs/smb/client/{cifs_dfs_ref.c => namespace.c} | 113 ++--
fs/smb/client/readdir.c | 23 +-
fs/smb/client/sess.c | 68 ++-
fs/smb/client/smb1ops.c | 26 +-
fs/smb/client/smb2inode.c | 199 ++++---
fs/smb/client/smb2ops.c | 283 +++-------
fs/smb/client/smb2proto.h | 17 +-
fs/smb/client/transport.c | 29 +-
20 files changed, 993 insertions(+), 857 deletions(-)
rename fs/smb/client/{cifs_dfs_ref.c => namespace.c} (62%)Signature · 1 line
2.41.0
PATCH 1/17 smb: client: introduce DFS_CACHE_TGT_LIST()
Add new helper which declares and initialises target list of a DFS referral rather having to do both separately.
No functional changes.
--- fs/smb/client/connect.c | 4 ++-- fs/smb/client/dfs.c | 6 +++--- fs/smb/client/dfs_cache.c | 4 ++-- fs/smb/client/dfs_cache.h | 6 +++++- 4 files changed, 12 insertions(+), 8 deletions(-)
fs/smb/client/connect.c +2 -2
@@ -453,10 +453,10 @@ static int reconnect_target_unlocked(struct TCP_Server_Info *server, struct dfs_static int reconnect_dfs_server (struct TCP_Server_Info *server) { -int rc =0 ; -struct dfs_cache_tgt_list tl =DFS_CACHE_TGT_LIST_INIT (tl);struct dfs_cache_tgt_iterator *target_hint =NULL ; +DFS_CACHE_TGT_LIST (tl);int num_targets =0 ; +int rc =0 ;/* * Determine the number of dfs targets the referral path in @cifs_sb resolves to.
fs/smb/client/dfs.c +3 -3
@@ -174,7 +174,7 @@ static int __dfs_mount_share(struct cifs_mount_ctx *mnt_ctx) } do { - struct dfs_cache_tgt_list tl = DFS_CACHE_TGT_LIST_INIT(tl); + DFS_CACHE_TGT_LIST(tl); rc = dfs_get_referral(mnt_ctx, ref_path + 1, NULL, &tl); if (rc) {
@@ -426,7 +426,7 @@ static int __tree_connect_dfs_target(const unsigned int xid, struct cifs_tcon *t/* Try to tree connect to all dfs targets */ for (; tit; tit =dfs_cache_get_next_tgt (tl, tit)) {const char *target =dfs_cache_get_tgt_name (tit); -struct dfs_cache_tgt_list ntl =DFS_CACHE_TGT_LIST_INIT (ntl); +DFS_CACHE_TGT_LIST (ntl);kfree (share);kfree (prefix);
@@ -520,7 +520,7 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const struint rc;struct TCP_Server_Info *server = tcon->ses->server;const struct smb_version_operations *ops = server->ops; -struct dfs_cache_tgt_list tl =DFS_CACHE_TGT_LIST_INIT (tl); +DFS_CACHE_TGT_LIST (tl);struct cifs_sb_info *cifs_sb =NULL ;struct super_block *sb =NULL ;struct dfs_info3_param ref = {0 };
fs/smb/client/dfs_cache.c +2 -2
@@ -1177,9 +1177,9 @@ static bool is_ses_good(struct cifs_ses *ses)/* Refresh dfs referral of tcon and mark it for reconnect if needed */ static int __refresh_tcon (const char *path,struct cifs_ses *ses,bool force_refresh) { -struct dfs_cache_tgt_list old_tl =DFS_CACHE_TGT_LIST_INIT (old_tl); -struct dfs_cache_tgt_list new_tl =DFS_CACHE_TGT_LIST_INIT (new_tl);struct TCP_Server_Info *server = ses->server; +DFS_CACHE_TGT_LIST (old_tl); +DFS_CACHE_TGT_LIST (new_tl);bool needs_refresh = false;struct cache_entry *ce;unsigned int xid;
fs/smb/client/dfs_cache.h +5 -1
@@ -16,7 +16,11 @@extern struct workqueue_struct *dfscache_wq;extern atomic_t dfs_cache_ttl; -#define DFS_CACHE_TGT_LIST_INIT (var) { .tl_numtgts = 0, .tl_list = LIST_HEAD_INIT((var).tl_list), } +#define DFS_CACHE_TGT_LIST_INIT (var) \ + { .tl_numtgts = 0, .tl_list = LIST_HEAD_INIT((var).tl_list), } + +#define DFS_CACHE_TGT_LIST (var) \ + struct dfs_cache_tgt_list var = DFS_CACHE_TGT_LIST_INIT(var)struct dfs_cache_tgt_list {int tl_numtgts;
Signature · 1 line
2.41.0
PATCH 2/17 smb: client: ensure to try all targets when finding nested links
In reply to Paulo AlcantaraWith current implementation, when a nested DFS link is found during mount(2), the client follows the referral and then try to connect to all of its targets. If all targets failed, the client bails out rather than retrying remaining targets from previous referral.
Fix this by stacking all referrals and targets so the client can retry remaining targets from previous referrals in case all targets of current referral have failed.
Thanks to samba, this can be easily tested like below
* Run the following under dfs folder in samba server
$ ln -s "msdfs:srv\\bad-share" link1 $ ln -s "msdfs:srv\\dfs\\link1,srv\\good-share" link0
* Before patch
$ mount.cifs //srv/dfs/link0 /mnt -o ... mount error(2): No such file or directory Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)...
* After patch
$ mount.cifs //srv/dfs/link0 /mnt -o ... # ls /mnt bar fileshare1 sub
--- fs/smb/client/cifsglob.h | 16 ++- fs/smb/client/dfs.c | 271 ++++++++++++++++++++------------------ fs/smb/client/dfs.h | 104 +++++++++++++++ fs/smb/client/dfs_cache.c | 6 +- fs/smb/client/dfs_cache.h | 6 +- 5 files changed, 265 insertions(+), 138 deletions(-)
fs/smb/client/cifsglob.h +14 -2
@@ -1721,11 +1721,23 @@ struct cifs_mount_ctx {struct list_head dfs_ses_list; }; +static inline void __free_dfs_info_param (struct dfs_info3_param *param) +{ +kfree (param->path_name); +kfree (param->node_name); +} +static inline void free_dfs_info_param (struct dfs_info3_param *param) +{ +if (param) +__free_dfs_info_param (param); +} + +static inline void zfree_dfs_info_param (struct dfs_info3_param *param) {if (param) { -kfree (param->path_name); -kfree (param->node_name); +__free_dfs_info_param (param); +memset (param,0 ,sizeof (*param)); } }
fs/smb/client/dfs.c +142 -129
305 lines not on this page · raw message
fs/smb/client/dfs.h +104 -0
110 lines not on this page · raw message
fs/smb/client/dfs_cache.c +2 -4
@@ -29,8 +29,6 @@#define CACHE_MIN_TTL 120/* 2 minutes */ #define CACHE_DEFAULT_TTL 300/* 5 minutes */ -#define IS_DFS_INTERLINK (v) (((v) & DFSREF_REFERRAL_SERVER) && !((v) & DFSREF_STORAGE_SERVER)) -struct cache_dfs_tgt {char *name;int path_consumed;
@@ -174,7 +172,7 @@ static int dfscache_proc_show(struct seq_file *m, void *v)"cache entry: path=%s,type=%s,ttl=%d,etime=%ld,hdr_flags=0x%x,ref_flags=0x%x,interlink=%s,path_consumed=%d,expired=%s\n" , ce->path, ce->srvtype ==DFS_TYPE_ROOT ?"root" :"link" , ce->ttl, ce->etime.tv_nsec, ce->hdr_flags, ce->ref_flags, -IS_DFS_INTERLINK (ce->hdr_flags) ?"yes" :"no" , +DFS_INTERLINK (ce->hdr_flags) ?"yes" :"no" , ce->path_consumed, cache_entry_expired(ce) ? "yes" : "no");list_for_each_entry (t, &ce->tlist, list) {
@@ -243,7 +241,7 @@ static inline void dump_ce(const struct cache_entry *ce) ce->srvtype ==DFS_TYPE_ROOT ?"root" :"link" , ce->ttl, ce->etime.tv_nsec, ce->hdr_flags, ce->ref_flags, -IS_DFS_INTERLINK (ce->hdr_flags) ?"yes" :"no" , +DFS_INTERLINK (ce->hdr_flags) ?"yes" :"no" , ce->path_consumed, cache_entry_expired(ce) ? "yes" : "no");dump_tgts (ce);
fs/smb/client/dfs_cache.h +3 -3
@@ -55,8 +55,8 @@ static inline struct dfs_cache_tgt_iterator * dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl, struct dfs_cache_tgt_iterator *it) { -if (!tl ||list_empty (&tl->tl_list) || !it || -list_is_last (&it->it_list, &tl->tl_list)) +if (!tl || !tl->tl_numtgts ||list_empty (&tl->tl_list) || + !it ||list_is_last (&it->it_list, &tl->tl_list))return NULL ;return list_next_entry (it, it_list); }
@@ -75,7 +75,7 @@ static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl) {struct dfs_cache_tgt_iterator *it, *nit; -if (!tl ||list_empty (&tl->tl_list)) +if (!tl || !tl->tl_numtgts ||list_empty (&tl->tl_list))return ;list_for_each_entry_safe (it, nit, &tl->tl_list, it_list) {list_del (&it->it_list);
Signature · 1 line
2.41.0
PATCH 3/17 smb: client: move some params to cifs_open_info_data
In reply to Paulo AlcantaraInstead of passing @adjust_tz and some reparse point related fields as parameters in ->query_path_info() and {smb311_posix,cifs}_info_to_fattr() calls, move them to cifs_open_info_data structure as they can be easily accessed through @data.
No functional changes.
--- fs/smb/client/cifsglob.h | 14 ++++++-- fs/smb/client/inode.c | 68 ++++++++++++++++++--------------------- fs/smb/client/smb1ops.c | 15 +++++---- fs/smb/client/smb2inode.c | 29 +++++++++-------- fs/smb/client/smb2proto.h | 17 ++++++---- 5 files changed, 77 insertions(+), 66 deletions(-)
fs/smb/client/cifsglob.h +11 -3
@@ -186,6 +186,12 @@ struct cifs_cred { };struct cifs_open_info_data { +bool adjust_tz; +union { +bool reparse_point; +bool symlink; + }; +__u32 reparse_tag;char *symlink_target;union {struct smb2_file_all_info fi;
@@ -318,9 +324,11 @@ struct smb_version_operations {int (*is_path_accessible)(const unsigned int ,struct cifs_tcon *,struct cifs_sb_info *,const char *);/* query path data from the server */ -int (*query_path_info)(const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, -struct cifs_open_info_data *data,bool *adjust_tz,bool *reparse); +int (*query_path_info)(const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +struct cifs_open_info_data *data);/* query file data from the server */ int (*query_file_info)(const unsigned int xid,struct cifs_tcon *tcon,struct cifsFileInfo *cfile,struct cifs_open_info_data *data);
fs/smb/client/inode.c +31 -37
173 lines not on this page · raw message
fs/smb/client/smb1ops.c +9 -6
@@ -542,14 +542,17 @@ cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,return rc; } -static int cifs_query_path_info (const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, -struct cifs_open_info_data *data,bool *adjustTZ,bool *symlink) +static int cifs_query_path_info (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +struct cifs_open_info_data *data) {int rc;FILE_ALL_INFO fi = {}; - *symlink = false; + data->symlink = false; + data->adjust_tz = false;/* could do find first instead but this returns more info */ rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, cifs_sb->local_nls,
@@ -562,7 +565,7 @@ static int cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,if ((rc == -EOPNOTSUPP ) || (rc == -EINVAL )) { rc =SMBQueryInformation (xid, tcon, full_path, &fi, cifs_sb->local_nls,cifs_remap (cifs_sb)); - *adjustTZ = true; + data->adjust_tz = true; }if (!rc) {
@@ -589,7 +592,7 @@ static int cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,/* Need to check if this is a symbolic link or not */ tmprc =CIFS_open (xid, &oparms, &oplock,NULL );if (tmprc == -EOPNOTSUPP ) - *symlink = true; + data->symlink = true;else if (tmprc ==0 )CIFSSMBClose (xid, tcon, fid.netfid); }
fs/smb/client/smb2inode.c +16 -13
@@ -541,9 +541,11 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,return rc; } -int smb2_query_path_info (const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, -struct cifs_open_info_data *data,bool *adjust_tz,bool *reparse) +int smb2_query_path_info (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +struct cifs_open_info_data *data) {__u32 create_options =0 ;struct cifsFileInfo *cfile;
@@ -553,8 +555,8 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,bool islink;int rc, rc2; - *adjust_tz = false; - *reparse = false; + data->adjust_tz = false; + data->reparse_point = false;if (strcmp (full_path,"" )) rc = -ENOENT ;
@@ -588,7 +590,7 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,if (rc) goto out; - *reparse = true; + data->reparse_point = true; create_options |=OPEN_REPARSE_POINT ;/* Failed on a symbolic link - query a reparse point info */
@@ -619,12 +621,13 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, } -int smb311_posix_query_path_info (const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, +int smb311_posix_query_path_info (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path,struct cifs_open_info_data *data,struct cifs_sid *owner, -struct cifs_sid *group, -bool *adjust_tz,bool *reparse) +struct cifs_sid *group) {int rc;__u32 create_options =0 ;
@@ -636,8 +639,8 @@ int smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,size_t sidsbuflen =0 ;size_t owner_len, group_len; - *adjust_tz = false; - *reparse = false; + data->adjust_tz = false; + data->reparse_point = false;/* * BB TODO: Add support for using the cached root handle.
@@ -659,7 +662,7 @@ int smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,if (rc) goto out; } - *reparse = true; + data->reparse_point = true; create_options |=OPEN_REPARSE_POINT ;/* Failed on a symbolic link - query a reparse point info */
fs/smb/client/smb2proto.h +10 -7
@@ -56,9 +56,11 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server,extern int smb2_query_reparse_tag (const unsigned int xid,struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb,const char *path,__u32 *reparse_tag); -int smb2_query_path_info (const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, -struct cifs_open_info_data *data,bool *adjust_tz,bool *reparse); +int smb2_query_path_info (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +struct cifs_open_info_data *data);extern int smb2_set_path_size (const unsigned int xid,struct cifs_tcon *tcon,const char *full_path,__u64 size,struct cifs_sb_info *cifs_sb,bool set_alloc);
@@ -275,12 +277,13 @@ extern int smb2_query_info_compound(const unsigned int xid, struct kvec *rsp, int *buftype, struct cifs_sb_info *cifs_sb);/* query path info from the server using SMB311 POSIX extensions*/ -int smb311_posix_query_path_info (const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, +int smb311_posix_query_path_info (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path,struct cifs_open_info_data *data,struct cifs_sid *owner, -struct cifs_sid *group, -bool *adjust_tz,bool *reparse); +struct cifs_sid *group);int posix_info_parse (const void *beg,const void *end,struct smb2_posix_info_parsed *out);int posix_info_sid_size (const void *beg,const void *end);
Signature · 1 line
2.41.0
PATCH 4/17 smb: client: make smb2_compound_op() return resp buffer on success
In reply to Paulo AlcantaraIf @out_iov and @out_buftype are passed, then return compounded responses regardless whether the request failed or not. This will be useful for detecting reparse points on SMB2_CREATE responses as specified in MS-SMB2 2.2.14.
No functional changes.
--- fs/smb/client/smb2inode.c | 52 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
fs/smb/client/smb2inode.c +26 -26
@@ -52,15 +52,16 @@ struct cop_vars {* note: If cfile is passed, the reference to it is dropped here. * So make sure that you do not reuse cfile after return from this func. * -* If passing @err_iov and @err_buftype, ensure to make them both large enough (>= 3) to hold all -* error responses. Caller is also responsible for freeing them up. +* If passing @out_iov and @out_buftype, ensure to make them both large enough +* (>= 3) to hold all compounded responses. Caller is also responsible for +* freeing them up with free_rsp_buf(). */ static int smb2_compound_op (const unsigned int xid,struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb,const char *full_path,__u32 desired_access,__u32 create_disposition,__u32 create_options,umode_t mode,void *ptr,int command,struct cifsFileInfo *cfile,__u8 **extbuf,size_t *extbuflen, -struct kvec *err_iov,int *err_buftype) +struct kvec *out_iov,int *out_buftype) {struct cop_vars *vars =NULL ;struct kvec *rsp_iov;
@@ -529,9 +530,9 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,if (cfile)cifsFileInfo_put (cfile); -if (rc && err_iov && err_buftype) { -memcpy (err_iov, rsp_iov,3 *sizeof (*err_iov)); -memcpy (err_buftype, resp_buftype,3 *sizeof (*err_buftype)); +if (out_iov && out_buftype) { +memcpy (out_iov, rsp_iov,3 *sizeof (*out_iov)); +memcpy (out_buftype, resp_buftype,3 *sizeof (*out_buftype)); }else {free_rsp_buf (resp_buftype[0 ], rsp_iov[0 ].iov_base);free_rsp_buf (resp_buftype[1 ], rsp_iov[1 ].iov_base);
@@ -550,8 +551,8 @@ int smb2_query_path_info(const unsigned int xid,__u32 create_options =0 ;struct cifsFileInfo *cfile;struct cached_fid *cfid =NULL ; -struct kvec err_iov[3 ] = {}; -int err_buftype[3 ] = {}; +struct kvec out_iov[3 ] = {}; +int out_buftype[3 ] = {};bool islink;int rc, rc2;
@@ -577,15 +578,15 @@ int smb2_query_path_info(const unsigned int xid,cifs_get_readable_path (tcon, full_path, &cfile); rc =smb2_compound_op (xid, tcon, cifs_sb, full_path,FILE_READ_ATTRIBUTES ,FILE_OPEN , create_options,ACL_NO_MODE , data,SMB2_OP_QUERY_INFO , cfile, -NULL ,NULL , err_iov, err_buftype); +NULL ,NULL , out_iov, out_buftype);if (rc) { -struct smb2_hdr *hdr = err_iov[0 ].iov_base; +struct smb2_hdr *hdr = out_iov[0 ].iov_base; -if (unlikely (!hdr || err_buftype[0 ] ==CIFS_NO_BUFFER )) +if (unlikely (!hdr || out_buftype[0 ] ==CIFS_NO_BUFFER )) goto out;if (rc == -EOPNOTSUPP && hdr->Command ==SMB2_CREATE && hdr->Status ==STATUS_STOPPED_ON_SYMLINK ) { - rc =smb2_parse_symlink_response (cifs_sb, err_iov, + rc =smb2_parse_symlink_response (cifs_sb, out_iov, &data->symlink_target);if (rc) goto out;
@@ -614,13 +615,12 @@ int smb2_query_path_info(const unsigned int xid, } out: -free_rsp_buf (err_buftype[0 ], err_iov[0 ].iov_base); -free_rsp_buf (err_buftype[1 ], err_iov[1 ].iov_base); -free_rsp_buf (err_buftype[2 ], err_iov[2 ].iov_base); +free_rsp_buf (out_buftype[0 ], out_iov[0 ].iov_base); +free_rsp_buf (out_buftype[1 ], out_iov[1 ].iov_base); +free_rsp_buf (out_buftype[2 ], out_iov[2 ].iov_base);return rc; } - int smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb,
@@ -632,8 +632,8 @@ int smb311_posix_query_path_info(const unsigned int xid,int rc;__u32 create_options =0 ;struct cifsFileInfo *cfile; -struct kvec err_iov[3 ] = {}; -int err_buftype[3 ] = {}; +struct kvec out_iov[3 ] = {}; +int out_buftype[3 ] = {};__u8 *sidsbuf =NULL ;__u8 *sidsbuf_end =NULL ;size_t sidsbuflen =0 ;
@@ -652,13 +652,13 @@ int smb311_posix_query_path_info(const unsigned int xid,cifs_get_readable_path (tcon, full_path, &cfile); rc =smb2_compound_op (xid, tcon, cifs_sb, full_path,FILE_READ_ATTRIBUTES ,FILE_OPEN , create_options,ACL_NO_MODE , data,SMB2_OP_POSIX_QUERY_INFO , cfile, - &sidsbuf, &sidsbuflen, err_iov, err_buftype); + &sidsbuf, &sidsbuflen, out_iov, out_buftype);if (rc == -EOPNOTSUPP ) {/* BB TODO: When support for special files added to Samba re-verify this path */ -if (err_iov[0 ].iov_base && err_buftype[0 ] !=CIFS_NO_BUFFER && - ((struct smb2_hdr *)err_iov[0 ].iov_base)->Command ==SMB2_CREATE && - ((struct smb2_hdr *)err_iov[0 ].iov_base)->Status ==STATUS_STOPPED_ON_SYMLINK ) { - rc =smb2_parse_symlink_response (cifs_sb, err_iov, &data->symlink_target); +if (out_iov[0 ].iov_base && out_buftype[0 ] !=CIFS_NO_BUFFER && + ((struct smb2_hdr *)out_iov[0 ].iov_base)->Command ==SMB2_CREATE && + ((struct smb2_hdr *)out_iov[0 ].iov_base)->Status ==STATUS_STOPPED_ON_SYMLINK ) { + rc =smb2_parse_symlink_response (cifs_sb, out_iov, &data->symlink_target);if (rc) goto out; }
@@ -694,9 +694,9 @@ int smb311_posix_query_path_info(const unsigned int xid, out:kfree (sidsbuf); -free_rsp_buf (err_buftype[0 ], err_iov[0 ].iov_base); -free_rsp_buf (err_buftype[1 ], err_iov[1 ].iov_base); -free_rsp_buf (err_buftype[2 ], err_iov[2 ].iov_base); +free_rsp_buf (out_buftype[0 ], out_iov[0 ].iov_base); +free_rsp_buf (out_buftype[1 ], out_iov[1 ].iov_base); +free_rsp_buf (out_buftype[2 ], out_iov[2 ].iov_base);return rc; }
Signature · 1 line
2.41.0
PATCH 5/17 smb: client: rename cifs_dfs_ref.c to namespace.c
In reply to Paulo AlcantaraThe automount code will handle both DFS links and reparse files that are mount points.
---
fs/smb/client/Makefile | 2 +-
fs/smb/client/{cifs_dfs_ref.c => namespace.c} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename fs/smb/client/{cifs_dfs_ref.c => namespace.c} (100%)fs/smb/client/Makefile +1 -1
@@ -21,7 +21,7 @@ cifs-$(CONFIG_CIFS_XATTR) += xattr.o cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o -cifs-$(CONFIG_CIFS_DFS_UPCALL) += cifs_dfs_ref.o dfs_cache.o dfs.o +cifs-$(CONFIG_CIFS_DFS_UPCALL) += namespace.o dfs_cache.o dfs.o cifs-$(CONFIG_CIFS_SWN_UPCALL) += netlink.o cifs_swn.o
fs/smb/client/namespace.c renamed from fs/smb/client/cifs_dfs_ref.c +0 -0
Signature · 1 line
2.41.0
PATCH 6/17 smb: client: get rid of dfs naming in automount code
In reply to Paulo AlcantaraAutomount code will handle both DFS links and reparse mount points.
Also, get rid of BUG_ON() in cifs_release_automount_timer() while we're at it.
--- fs/smb/client/cifsfs.c | 2 +- fs/smb/client/cifsfs.h | 6 +++--- fs/smb/client/cifsproto.h | 4 ++-- fs/smb/client/dir.c | 4 ++-- fs/smb/client/inode.c | 2 +- fs/smb/client/namespace.c | 42 +++++++++++++++++++-------------------- 6 files changed, 30 insertions(+), 30 deletions(-)
fs/smb/client/cifsfs.c +1 -1
@@ -1805,7 +1805,7 @@ exit_cifs(void)cifs_dbg (NOISY ,"exit_smb3\n" );unregister_filesystem (&cifs_fs_type);unregister_filesystem (&smb3_fs_type); -cifs_dfs_release_automount_timer (); +cifs_release_automount_timer ();exit_cifs_idmap ();#ifdef CONFIG_CIFS_SWN_UPCALL cifs_genl_exit ();
fs/smb/client/cifsfs.h +3 -3
@@ -81,7 +81,7 @@ extern int cifs_fiemap(struct inode *, struct fiemap_extent_info *, u64 start,extern const struct inode_operations cifs_file_inode_ops;extern const struct inode_operations cifs_symlink_inode_ops; -extern const struct inode_operations cifs_dfs_referral_inode_operations; +extern const struct inode_operations cifs_namespace_inode_operations;/* Functions related to files and directories */
@@ -119,9 +119,9 @@ extern const struct dentry_operations cifs_dentry_ops;extern const struct dentry_operations cifs_ci_dentry_ops;#ifdef CONFIG_CIFS_DFS_UPCALL -extern struct vfsmount *cifs_dfs_d_automount (struct path *path); +extern struct vfsmount *cifs_d_automount (struct path *path);#else -static inline struct vfsmount *cifs_dfs_d_automount (struct path *path) +static inline struct vfsmount *cifs_d_automount (struct path *path) {return ERR_PTR (-EREMOTE ); }
fs/smb/client/cifsproto.h +2 -2
@@ -296,9 +296,9 @@ extern void cifs_put_tcp_session(struct TCP_Server_Info *server,extern void cifs_put_tcon (struct cifs_tcon *tcon);#if IS_ENABLED (CONFIG_CIFS_DFS_UPCALL ) -extern void cifs_dfs_release_automount_timer (void ); +extern void cifs_release_automount_timer (void );#else /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */ -#define cifs_dfs_release_automount_timer () do { } while (0) +#define cifs_release_automount_timer () do { } while (0)#endif /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */ void cifs_proc_init (void );
fs/smb/client/dir.c +2 -2
@@ -797,7 +797,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)const struct dentry_operations cifs_dentry_ops = { .d_revalidate = cifs_d_revalidate, - .d_automount = cifs_dfs_d_automount, + .d_automount = cifs_d_automount,/* d_delete: cifs_d_delete, */ /* not needed except for debugging */ };
@@ -872,5 +872,5 @@ const struct dentry_operations cifs_ci_dentry_ops = { .d_revalidate = cifs_d_revalidate, .d_hash = cifs_ci_hash, .d_compare = cifs_ci_compare, - .d_automount = cifs_dfs_d_automount, + .d_automount = cifs_d_automount, };
fs/smb/client/inode.c +1 -1
@@ -60,7 +60,7 @@ static void cifs_set_ops(struct inode *inode)case S_IFDIR :#ifdef CONFIG_CIFS_DFS_UPCALL if (IS_AUTOMOUNT (inode)) { - inode->i_op = &cifs_dfs_referral_inode_operations; + inode->i_op = &cifs_namespace_inode_operations; }else {#else /* NO DFS support, treat as a directory */ {
fs/smb/client/namespace.c +21 -21
87 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 7/17 smb: client: get rid of dfs code dep in namespace.c
In reply to Paulo AlcantaraMake namespace.c being built without requiring CONFIG_CIFS_DFS_UPCALL=y by moving set_dest_addr() to dfs.c and call it at the beginning of dfs_mount_share() so it can chase the DFS link starting from the correct server in @ctx->dstaddr.
--- fs/smb/client/Makefile | 5 ++-- fs/smb/client/cifsfs.h | 7 ----- fs/smb/client/cifsproto.h | 4 --- fs/smb/client/dfs.c | 16 +++++++++++ fs/smb/client/dfs.h | 37 -------------------------- fs/smb/client/inode.c | 4 --- fs/smb/client/namespace.c | 56 ++++++++++++++++++++++++++------------- 7 files changed, 57 insertions(+), 72 deletions(-)
fs/smb/client/Makefile +3 -2
@@ -11,7 +11,8 @@ cifs-y := trace.o cifsfs.o cifs_debug.o connect.o dir.o file.o \ readdir.o ioctl.o sess.o export.o unc.o winucase.o \ smb2ops.o smb2maperror.o smb2transport.o \ smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o \ - dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o + dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o \ + namespace.o $(obj)/asn1.o: $(obj)/cifs_spnego_negtokeninit.asn1.h
@@ -21,7 +22,7 @@ cifs-$(CONFIG_CIFS_XATTR) += xattr.o cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o -cifs-$(CONFIG_CIFS_DFS_UPCALL) += namespace.o dfs_cache.o dfs.o +cifs-$(CONFIG_CIFS_DFS_UPCALL) += dfs_cache.o dfs.o cifs-$(CONFIG_CIFS_SWN_UPCALL) += netlink.o cifs_swn.o
fs/smb/client/cifsfs.h +0 -7
@@ -118,14 +118,7 @@ extern void cifs_pages_write_redirty(struct inode *inode, loff_t start, unsignedextern const struct dentry_operations cifs_dentry_ops;extern const struct dentry_operations cifs_ci_dentry_ops; -#ifdef CONFIG_CIFS_DFS_UPCALL extern struct vfsmount *cifs_d_automount (struct path *path); -#else -static inline struct vfsmount *cifs_d_automount (struct path *path) -{ -return ERR_PTR (-EREMOTE ); -} -#endif /* Functions related to symlinks */ extern const char *cifs_get_link(struct dentry *, struct inode *,
fs/smb/client/cifsproto.h +0 -4
@@ -295,11 +295,7 @@ extern void cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect);extern void cifs_put_tcon (struct cifs_tcon *tcon); -#if IS_ENABLED (CONFIG_CIFS_DFS_UPCALL )extern void cifs_release_automount_timer (void ); -#else /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */ -#define cifs_release_automount_timer () do { } while (0) -#endif /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */ void cifs_proc_init (void );void cifs_proc_clean (void );
fs/smb/client/dfs.c +16 -0
@@ -263,12 +263,28 @@ static int __dfs_mount_share(struct cifs_mount_ctx *mnt_ctx)return rc; } +/* Resolve UNC hostname in @ctx->source and set ip addr in @ctx->dstaddr */ +static int update_fs_context_dstaddr (struct smb3_fs_context *ctx) +{ +struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr; +int rc; + + rc =dns_resolve_server_name_to_ip (ctx->source, addr,NULL ); +if (!rc) +cifs_set_port (addr, ctx->port); +return rc; +} +int dfs_mount_share (struct cifs_mount_ctx *mnt_ctx,bool *isdfs) {struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;bool nodfs = ctx->nodfs;int rc; + rc =update_fs_context_dstaddr (ctx); +if (rc) +return rc; + *isdfs = false; rc =get_session (mnt_ctx,NULL );if (rc)
fs/smb/client/dfs.h +0 -37
@@ -138,43 +138,6 @@ static inline int dfs_get_referral(struct cifs_mount_ctx *mnt_ctx, const char *p cifs_remap(cifs_sb), path, ref, tl); } -/* Return DFS full path out of a dentry set for automount */ -static inline char *dfs_get_automount_devname (struct dentry *dentry,void *page) -{ -struct cifs_sb_info *cifs_sb =CIFS_SB (dentry->d_sb); -struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb); -size_t len; -char *s; - -spin_lock (&tcon->tc_lock); -if (unlikely (!tcon->origin_fullpath)) { -spin_unlock (&tcon->tc_lock); -return ERR_PTR (-EREMOTE ); - } -spin_unlock (&tcon->tc_lock); - - s =dentry_path_raw (dentry, page,PATH_MAX ); -if (IS_ERR (s)) -return s; -/* for root, we want "" */ -if (!s[1 ]) - s++; - -spin_lock (&tcon->tc_lock); - len =strlen (tcon->origin_fullpath); -if (s < (char *)page + len) { -spin_unlock (&tcon->tc_lock); -return ERR_PTR (-ENAMETOOLONG ); - } - - s -= len; -memcpy (s, tcon->origin_fullpath, len); -spin_unlock (&tcon->tc_lock); -convert_delimiter (s,'/' ); - -return s; -} -static inline void dfs_put_root_smb_sessions (struct list_head *head) {struct dfs_root_ses *root, *tmp;
fs/smb/client/inode.c +0 -4
@@ -58,13 +58,9 @@ static void cifs_set_ops(struct inode *inode) inode->i_data.a_ops = &cifs_addr_ops;break ;case S_IFDIR : -#ifdef CONFIG_CIFS_DFS_UPCALL if (IS_AUTOMOUNT (inode)) { inode->i_op = &cifs_namespace_inode_operations; }else { -#else /* NO DFS support, treat as a directory */ - { -#endif inode->i_op = &cifs_dir_inode_ops; inode->i_fop = &cifs_dir_ops; }
fs/smb/client/namespace.c +38 -18
90 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 8/17 smb: client: parse reparse point flag in create response
In reply to Paulo AlcantaraCheck for reparse point flag on query info calls as specified in MS-SMB2 2.2.14.
--- fs/smb/client/cifsglob.h | 4 ++ fs/smb/client/cifsproto.h | 3 + fs/smb/client/inode.c | 121 ++++++++++++++++++++++++++------------ fs/smb/client/readdir.c | 22 ++----- fs/smb/client/smb2inode.c | 115 ++++++++++++++++++++++++------------ 5 files changed, 172 insertions(+), 93 deletions(-)
fs/smb/client/cifsglob.h +4 -0
@@ -199,6 +199,10 @@ struct cifs_open_info_data { }; }; +#define cifs_open_data_reparse (d) \ + ((d)->reparse_point || \ + (le32_to_cpu((d)->fi.Attributes) & ATTR_REPARSE)) +static inline void cifs_free_open_info (struct cifs_open_info_data *data) {kfree (data->symlink_target);
fs/smb/client/cifsproto.h +3 -0
@@ -207,6 +207,9 @@ extern struct inode *cifs_iget(struct super_block *sb,int cifs_get_inode_info (struct inode **inode,const char *full_path,struct cifs_open_info_data *data,struct super_block *sb,int xid,const struct cifs_fid *fid); +bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb, +struct cifs_fattr *fattr, +u32 tag);extern int smb311_posix_get_inode_info (struct inode **pinode,const char *search_path,struct super_block *sb,unsigned int xid); extern int cifs_get_inode_info_unix(struct inode **pinode,
fs/smb/client/inode.c +83 -38
159 lines not on this page · raw message
fs/smb/client/readdir.c +6 -16
@@ -163,29 +163,19 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)* TODO: go through all documented reparse tags to see if we can * reasonably map some of them to directories vs. files vs. symlinks */ +if ((fattr->cf_cifsattrs &ATTR_REPARSE ) && +cifs_reparse_point_to_fattr (cifs_sb, fattr, fattr->cf_cifstag)) + goto out_reparse; +if (fattr->cf_cifsattrs &ATTR_DIRECTORY ) { fattr->cf_mode =S_IFDIR | cifs_sb->ctx->dir_mode; fattr->cf_dtype =DT_DIR ; - }else if (fattr->cf_cifstag ==IO_REPARSE_TAG_LX_SYMLINK ) { - fattr->cf_mode |=S_IFLNK | cifs_sb->ctx->file_mode; - fattr->cf_dtype =DT_LNK ; - }else if (fattr->cf_cifstag ==IO_REPARSE_TAG_LX_FIFO ) { - fattr->cf_mode |=S_IFIFO | cifs_sb->ctx->file_mode; - fattr->cf_dtype =DT_FIFO ; - }else if (fattr->cf_cifstag ==IO_REPARSE_TAG_AF_UNIX ) { - fattr->cf_mode |=S_IFSOCK | cifs_sb->ctx->file_mode; - fattr->cf_dtype =DT_SOCK ; - }else if (fattr->cf_cifstag ==IO_REPARSE_TAG_LX_CHR ) { - fattr->cf_mode |=S_IFCHR | cifs_sb->ctx->file_mode; - fattr->cf_dtype =DT_CHR ; - }else if (fattr->cf_cifstag ==IO_REPARSE_TAG_LX_BLK ) { - fattr->cf_mode |=S_IFBLK | cifs_sb->ctx->file_mode; - fattr->cf_dtype =DT_BLK ; - }else {/* TODO: should we mark some other reparse points (like DFSR) as directories? */ + }else { fattr->cf_mode =S_IFREG | cifs_sb->ctx->file_mode; fattr->cf_dtype =DT_REG ; } +out_reparse:/* * We need to revalidate it further to make a decision about whether it * is a symbolic link, DFS referral or a reparse point with a direct
fs/smb/client/smb2inode.c +76 -39
160 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 9/17 smb: client: do not query reparse points twice on symlinks
In reply to Paulo AlcantaraSave a roundtrip by getting the reparse point tag and buffer at once in ->query_reparse_point() and then pass the buffer down to ->query_symlink().
--- fs/smb/client/cifsglob.h | 20 +++-- fs/smb/client/inode.c | 19 +++-- fs/smb/client/smb1ops.c | 11 ++- fs/smb/client/smb2ops.c | 166 ++++++--------------------------------- 4 files changed, 55 insertions(+), 161 deletions(-)
fs/smb/client/cifsglob.h +13 -7
@@ -336,10 +336,13 @@ struct smb_version_operations {/* query file data from the server */ int (*query_file_info)(const unsigned int xid,struct cifs_tcon *tcon,struct cifsFileInfo *cfile,struct cifs_open_info_data *data); -/* query reparse tag from srv to determine which type of special file */ -int (*query_reparse_tag)(const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *path, -__u32 *reparse_tag); +/* query reparse point to determine which type of special file */ +int (*query_reparse_point)(const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +u32 *tag,struct kvec *rsp, +int *rsp_buftype);/* get server index number */ int (*get_srv_inum)(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path, u64 *uniqueid,
@@ -388,9 +391,12 @@ struct smb_version_operations { const char *, const char *, struct cifs_sb_info *);/* query symlink target */ -int (*query_symlink)(const unsigned int ,struct cifs_tcon *, -struct cifs_sb_info *,const char *, -char **,bool ); +int (*query_symlink)(const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +char **target_path, +struct kvec *rsp_iov);/* open a file for non-posix mounts */ int (*open)(const unsigned int xid,struct cifs_open_parms *oparms,__u32 *oplock,void *buf);
fs/smb/client/inode.c +12 -7
@@ -428,7 +428,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,if (!server->ops->query_symlink)return -EOPNOTSUPP ; rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, - &fattr.cf_symlink_target, false); + &fattr.cf_symlink_target,NULL );if (rc) {cifs_dbg (FYI ,"%s: query_symlink: %d\n" , __func__, rc); goto cgiiu_exit;
@@ -988,17 +988,21 @@ static int query_reparse(struct cifs_open_info_data *data, {struct TCP_Server_Info *server = tcon->ses->server;struct cifs_sb_info *cifs_sb =CIFS_SB (sb); -bool reparse_point = data->reparse_point; +struct kvec rsp_iov, *iov =NULL ; +int rsp_buftype =CIFS_NO_BUFFER ;u32 tag = data->reparse_tag;int rc =0 ; -if (!tag && server->ops->query_reparse_tag) { - server->ops->query_reparse_tag (xid, tcon, cifs_sb, - full_path, &tag); +if (!tag && server->ops->query_reparse_point) { + rc = server->ops->query_reparse_point (xid, tcon, cifs_sb, + full_path, &tag, + &rsp_iov, &rsp_buftype); +if (!rc) + iov = &rsp_iov; }switch ((data->reparse_tag = tag)) {case 0 :/* SMB1 symlink */ - reparse_point = false; + iov =NULL ; fallthrough;case IO_REPARSE_TAG_NFS :case IO_REPARSE_TAG_SYMLINK :
@@ -1006,10 +1010,11 @@ static int query_reparse(struct cifs_open_info_data *data, rc = server->ops->query_symlink (xid, tcon, cifs_sb, full_path, &data->symlink_target, - reparse_point); + iov); }break ; } +free_rsp_buf (rsp_buftype, rsp_iov.iov_base);return rc; }
fs/smb/client/smb1ops.c +7 -4
@@ -972,13 +972,16 @@ cifs_unix_dfs_readlink(const unsigned int xid, struct cifs_tcon *tcon,#endif } -static int -cifs_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, -struct cifs_sb_info *cifs_sb,const char *full_path, -char **target_path,bool is_reparse_point) +static int cifs_query_symlink (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifs_sb_info *cifs_sb, +const char *full_path, +char **target_path, +struct kvec *rsp_iov) {int rc;int oplock =0 ; +bool is_reparse_point = !!rsp_iov;struct cifs_fid fid;struct cifs_open_parms oparms;
fs/smb/client/smb2ops.c +23 -143
196 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 9/17 smb: client: do not query reparse points twice on symlinks
Am also curious about the problem where we do an extra query on mfsymlinks with ls -l
---------- Forwarded message ---------
From: Paulo Alcantara <[email protected]>
Date: Thu, Aug 17, 2023 at 10:35 AM
Subject: [PATCH 09/17] smb: client: do not query reparse points twice on symlinks
To: <[email protected]>
Cc: <[email protected]>, Paulo Alcantara <[email protected]>
Save a roundtrip by getting the reparse point tag and buffer at once in ->query_reparse_point() and then pass the buffer down to ->query_symlink().
--- fs/smb/client/cifsglob.h | 20 +++-- fs/smb/client/inode.c | 19 +++-- fs/smb/client/smb1ops.c | 11 ++- fs/smb/client/smb2ops.c | 166 ++++++--------------------------------- 4 files changed, 55 insertions(+), 161 deletions(-)
fs/smb/client/cifsglob.h +0 -0
@@ -336,10 +336,13 @@ struct smb_version_operations {/* query file data from the server */ int (*query_file_info)(const unsigned int xid, struct cifs_tcon *tcon, struct cifsFileInfo *cfile, struct
cifs_open_info_data *data);
- /* query reparse tag from srv to determine which type of special file */
- int (*query_reparse_tag)(const unsigned int xid, struct cifs_tcon *tcon,
- struct cifs_sb_info *cifs_sb, const char *path,
- __u32 *reparse_tag);
+ /* query reparse point to determine which type of special file */
+ int (*query_reparse_point)(const unsigned int xid,
+ struct cifs_tcon *tcon, + struct cifs_sb_info *cifs_sb, + const char *full_path, + u32 *tag, struct kvec *rsp, + int *rsp_buftype);
/* get server index number */
int (*get_srv_inum)(const unsigned int xid, struct cifs_tcon *tcon,
struct cifs_sb_info *cifs_sb, const char*full_path, u64 *uniqueid,
@@ -388,9 +391,12 @@ struct smb_version_operations {
const char *, const char *,
struct cifs_sb_info *);
/* query symlink target */- int (*query_symlink)(const unsigned int, struct cifs_tcon *,
- struct cifs_sb_info *, const char *,
- char **, bool);
+ int (*query_symlink)(const unsigned int xid,
+ struct cifs_tcon *tcon,
+ struct cifs_sb_info *cifs_sb,
+ const char *full_path,
+ char **target_path,
+ struct kvec *rsp_iov);
/* open a file for non-posix mounts */
int (*open)(const unsigned int xid, struct cifs_open_parms
*oparms, __u32 *oplock,
void *buf);fs/smb/client/inode.c +0 -1
@@ -428,7 +428,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,if (!server->ops->query_symlink)return -EOPNOTSUPP ; rc = server->ops->query_symlink(xid, tcon, cifs_sb, full_path, -
&fattr.cf_symlink_target, false);
+ &fattr.cf_symlink_target, NULL);
if (rc) {
cifs_dbg(FYI, "%s: query_symlink: %d\n", __func__, rc);
goto cgiiu_exit;
@@ -988,17 +988,21 @@ static int query_reparse(struct cifs_open_info_data *data,
{
struct TCP_Server_Info *server = tcon->ses->server;
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
- bool reparse_point = data->reparse_point;
+ struct kvec rsp_iov, *iov = NULL;
+ int rsp_buftype = CIFS_NO_BUFFER;
u32 tag = data->reparse_tag;
int rc = 0;- if (!tag && server->ops->query_reparse_tag) {
- server->ops->query_reparse_tag(xid, tcon, cifs_sb,
- full_path, &tag);
+ if (!tag && server->ops->query_reparse_point) {
+ rc = server->ops->query_reparse_point(xid, tcon, cifs_sb,
+ full_path, &tag,
+ &rsp_iov, &rsp_buftype);
+ if (!rc)
+ iov = &rsp_iov;
}
switch ((data->reparse_tag = tag)) {
case 0: /* SMB1 symlink */
- reparse_point = false;
+ iov = NULL;
fallthrough;
case IO_REPARSE_TAG_NFS:
case IO_REPARSE_TAG_SYMLINK:
@@ -1006,10 +1010,11 @@ static int query_reparse(struct
cifs_open_info_data *data,
rc = server->ops->query_symlink(xid, tcon,
cifs_sb, full_path,
&data->symlink_target,
- reparse_point);
+ iov);
}
break;
}
+ free_rsp_buf(rsp_buftype, rsp_iov.iov_base);
return rc;}
fs/smb/client/smb1ops.c +0 -0
@@ -972,13 +972,16 @@ cifs_unix_dfs_readlink(const unsigned int xid,
struct cifs_tcon *tcon,
#endif
}
-static int
-cifs_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
- struct cifs_sb_info *cifs_sb, const char *full_path,
- char **target_path, bool is_reparse_point)
+static int cifs_query_symlink(const unsigned int xid,
+ struct cifs_tcon *tcon,
+ struct cifs_sb_info *cifs_sb,
+ const char *full_path,
+ char **target_path,
+ struct kvec *rsp_iov)
{
int rc;
int oplock = 0;
+ bool is_reparse_point = !!rsp_iov;
struct cifs_fid fid;
struct cifs_open_parms oparms;fs/smb/client/smb2ops.c +9 -110
126 lines not on this page · raw message
len: %d\n",
- plen);
- rc = -EIO;
- goto querty_exit;
- }
-
- rc = parse_reparse_point(reparse_buf, plen, target_path,
- cifs_sb);
- goto querty_exit;
- }
-
- if (!rc || !err_iov.iov_base) {
- rc = -ENOENT;
- goto querty_exit;- }
-
- rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
-
- querty_exit:
- cifs_dbg(FYI, "query symlink rc %d\n", rc); - kfree(utf16_path); - SMB2_open_free(&rqst[0]); - SMB2_ioctl_free(&rqst[1]); - SMB2_close_free(&rqst[2]); - free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); - free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); - free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); - return rc; + buf = (struct reparse_data_buffer *)((u8 *)io +
+ le32_to_cpu(io->OutputOffset));
+ return parse_reparse_point(buf, plen, target_path, cifs_sb);
}
-int
-smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
- struct cifs_sb_info *cifs_sb, const char *full_path,
- __u32 *tag)
+static int smb2_query_reparse_point(const unsigned int xid,
+ struct cifs_tcon *tcon,
+ struct cifs_sb_info *cifs_sb,
+ const char *full_path,
+ u32 *tag, struct kvec *rsp,
+ int *rsp_buftype)
{
int rc;
__le16 *utf16_path = NULL;
@@ -3205,6 +3082,9 @@ smb2_query_reparse_tag(const unsigned int xid,
struct cifs_tcon *tcon,
goto query_rp_exit;
}
*tag = le32_to_cpu(reparse_buf->ReparseTag);
+ *rsp = rsp_iov[1];
+ *rsp_buftype = resp_buftype[1];
+ resp_buftype[1] = CIFS_NO_BUFFER;
} query_rp_exit:
@@ -5503,7 +5383,7 @@ struct smb_version_operations smb30_operations = {
.echo = SMB2_echo,
.query_path_info = smb2_query_path_info,
/* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */- .query_reparse_tag = smb2_query_reparse_tag,
+ .query_reparse_point = smb2_query_reparse_point,
.get_srv_inum = smb2_get_srv_inum,
.query_file_info = smb2_query_file_info,
.set_path_size = smb2_set_path_size,
@@ -5616,7 +5496,7 @@ struct smb_version_operations smb311_operations = {
.can_echo = smb2_can_echo,
.echo = SMB2_echo,
.query_path_info = smb2_query_path_info,- .query_reparse_tag = smb2_query_reparse_tag,
+ .query_reparse_point = smb2_query_reparse_point,
.get_srv_inum = smb2_get_srv_inum,
.query_file_info = smb2_query_file_info,
.set_path_size = smb2_set_path_size,
--
2.41.0
Signature · 3 lines
Thanks, Steve
Re: Fwd: [PATCH 09/17] smb: client: do not query reparse points twice on symlinks
Quoted 2 lines · Steve French
Am also curious about the problem where we do an extra query on mfsymlinks with ls -l
When we find regular files in QUERY_DIRECTORY response that could be a potential mfsymlink, we always mark those dentries for revalidation so we can read its target when it is an actual mfsymlink.
PATCH 10/17 smb: client: query reparse points in older dialects
In reply to Paulo AlcantaraEnable the client to query reparse points in SMB2+.
--- fs/smb/client/smb2ops.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/smb2ops.c +2 -0
@@ -5178,6 +5178,7 @@ struct smb_version_operations smb20_operations = { .can_echo = smb2_can_echo, .echo = SMB2_echo, .query_path_info = smb2_query_path_info, + .query_reparse_point = smb2_query_reparse_point, .get_srv_inum = smb2_get_srv_inum, .query_file_info = smb2_query_file_info, .set_path_size = smb2_set_path_size,
@@ -5279,6 +5280,7 @@ struct smb_version_operations smb21_operations = { .can_echo = smb2_can_echo, .echo = SMB2_echo, .query_path_info = smb2_query_path_info, + .query_reparse_point = smb2_query_reparse_point, .get_srv_inum = smb2_get_srv_inum, .query_file_info = smb2_query_file_info, .set_path_size = smb2_set_path_size,
Signature · 1 line
2.41.0
PATCH 11/17 smb: cilent: set reparse mount points as automounts
In reply to Paulo AlcantaraBy doing so we can selectively mark those submounts as 'noserverino' rather than whole mount and thus avoiding inode collisions in them.
Consider a "test" SMB share that has two mounted NTFS volumes (vol0 & vol1) inside it.
* Before patch
$ mount.cifs //srv/test /mnt/1 -o ...,serverino $ ls -li /mnt/1/vol0 total 1 281474976710693 drwxr-xr-x 2 root root 0 Jul 15 00:23 $RECYCLE.BIN 281474976710696 drwxr-xr-x 2 root root 0 Jul 18 18:23 System Volume... 281474976710699 -rwxr-xr-x 1 root root 0 Aug 14 21:53 f0 281474976710700 -rwxr-xr-x 1 root root 0 Aug 15 18:52 f2 281474976710698 drwxr-xr-x 2 root root 0 Aug 12 19:39 foo 281474976710692 -rwxr-xr-x 1 root root 5 Aug 4 21:18 vol0_f0.txt $ ls -li /mnt/1/vol1 total 0 281474976710693 drwxr-xr-x 2 root root 0 Jul 15 00:23 $RECYCLE.BIN 281474976710696 drwxr-xr-x 2 root root 0 Jul 18 18:23 System Volume... 281474976710698 drwxr-xr-x 2 root root 0 Aug 12 19:39 bar 281474976710699 -rwxr-xr-x 1 root root 0 Aug 14 22:03 f0 281474976710700 -rwxr-xr-x 1 root root 0 Aug 14 22:52 f1 281474976710692 -rwxr-xr-x 1 root root 0 Jul 15 00:23 vol1_f0.txt
* After patch
$ mount.cifs //srv/test /mnt/1 -o ...,serverino $ ls -li /mnt/1/vol0 total 1 590 drwxr-xr-x 2 root root 0 Jul 15 00:23 $RECYCLE.BIN 594 drwxr-xr-x 2 root root 0 Jul 18 18:23 System Volume Information 591 -rwxr-xr-x 1 root root 0 Aug 14 21:53 f0 592 -rwxr-xr-x 1 root root 0 Aug 15 18:52 f2 593 drwxr-xr-x 2 root root 0 Aug 12 19:39 foo 595 -rwxr-xr-x 1 root root 5 Aug 4 21:18 vol0_f0.txt $ ls -li /mnt/1/vol1 total 0 596 drwxr-xr-x 2 root root 0 Jul 15 00:23 $RECYCLE.BIN 600 drwxr-xr-x 2 root root 0 Jul 18 18:23 System Volume Information 597 drwxr-xr-x 2 root root 0 Aug 12 19:39 bar 598 -rwxr-xr-x 1 root root 0 Aug 14 22:03 f0 599 -rwxr-xr-x 1 root root 0 Aug 14 22:52 f1 601 -rwxr-xr-x 1 root root 0 Jul 15 00:23 vol1_f0.txt
--- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/inode.c | 352 +++++++++++++++++++++----------------- fs/smb/client/namespace.c | 19 +- fs/smb/client/readdir.c | 1 + 4 files changed, 198 insertions(+), 176 deletions(-)
fs/smb/client/cifsglob.h +1 -1
@@ -1094,7 +1094,7 @@ cap_unix(struct cifs_ses *ses)* inode with new info */ -#define CIFS_FATTR_DFS_REFERRAL 0x1 +#define CIFS_FATTR_JUNCTION 0x1#define CIFS_FATTR_DELETE_PENDING 0x2#define CIFS_FATTR_NEED_REVAL 0x4#define CIFS_FATTR_INO_COLLISION 0x8
fs/smb/client/inode.c +191 -161
579 lines not on this page · raw message
fs/smb/client/namespace.c +5 -14
@@ -126,9 +126,11 @@ static char *automount_fullpath(struct dentry *dentry, void *page)char *s;spin_lock (&tcon->tc_lock); -if (unlikely (!tcon->origin_fullpath)) { +if (!tcon->origin_fullpath) {spin_unlock (&tcon->tc_lock); -return ERR_PTR (-EREMOTE ); +return build_path_from_dentry_optional_prefix (dentry, + page, + true); }spin_unlock (&tcon->tc_lock);
@@ -162,7 +164,6 @@ static struct vfsmount *cifs_do_automount(struct path *path)int rc;struct dentry *mntpt = path->dentry;struct fs_context *fc; -struct cifs_sb_info *cifs_sb;void *page =NULL ;struct smb3_fs_context *ctx, *cur_ctx;struct smb3_fs_context tmp;
@@ -172,17 +173,7 @@ static struct vfsmount *cifs_do_automount(struct path *path)if (IS_ROOT (mntpt))return ERR_PTR (-ESTALE ); -/* -* The MSDFS spec states that paths in DFS referral requests and -* responses must be prefixed by a single '\' character instead of -* the double backslashes usually used in the UNC. This function -* gives us the latter, so we must adjust the result. -*/ - cifs_sb =CIFS_SB (mntpt->d_sb); -if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NO_DFS ) -return ERR_PTR (-EREMOTE ); - - cur_ctx = cifs_sb->ctx; + cur_ctx =CIFS_SB (mntpt->d_sb)->ctx; fc =fs_context_for_submount (path->mnt->mnt_sb->s_type, mntpt);if (IS_ERR (fc))
fs/smb/client/readdir.c +1 -0
@@ -143,6 +143,7 @@ static bool reparse_file_needs_reval(const struct cifs_fattr *fattr)case IO_REPARSE_TAG_DFSR :case IO_REPARSE_TAG_SYMLINK :case IO_REPARSE_TAG_NFS : +case IO_REPARSE_TAG_MOUNT_POINT :case 0 :return true; }
Signature · 1 line
2.41.0
PATCH 12/17 smb: client: reduce stack usage in cifs_try_adding_channels()
In reply to Paulo AlcantaraClang warns about exceeded stack frame size
fs/smb/client/sess.c:160:5: warning: stack frame size (1368) exceeds limit (1024) in 'cifs_try_adding_channels' [-Wframe-larger-than]
It turns out that cifs_ses_add_channel() got inlined into cifs_try_adding_channels() which had a stack-allocated variable @ctx of 624 bytes in size. Fix this by making it heap-allocated.
--- fs/smb/client/sess.c | 68 ++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 27 deletions(-)
fs/smb/client/sess.c +41 -27
@@ -360,11 +360,11 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses, {struct TCP_Server_Info *chan_server;struct cifs_chan *chan; -struct smb3_fs_context ctx = {NULL }; +struct smb3_fs_context *ctx;static const char unc_fmt[] ="\\%s\\foo" ; -char unc[sizeof (unc_fmt)+SERVER_NAME_LEN_WITH_NULL ] = {0 };struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr; +size_t len;int rc;unsigned int xid =get_xid ();
@@ -388,54 +388,64 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,* the session and server without caring about memory * management. */ + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) { + rc = -ENOMEM ; + goto out_free_xid; + }/* Always make new connection for now (TODO?) */ - ctx.nosharesock = true; + ctx->nosharesock = true;/* Auth */ - ctx.domainauto = ses->domainAuto; - ctx.domainname = ses->domainName; + ctx->domainauto = ses->domainAuto; + ctx->domainname = ses->domainName;/* no hostname for extra channels */ - ctx.server_hostname ="" ; + ctx->server_hostname ="" ; - ctx.username = ses->user_name; - ctx.password = ses->password; - ctx.sectype = ses->sectype; - ctx.sign = ses->sign; + ctx->username = ses->user_name; + ctx->password = ses->password; + ctx->sectype = ses->sectype; + ctx->sign = ses->sign;/* UNC and paths */ /* XXX: Use ses->server->hostname? */ -sprintf (unc, unc_fmt, ses->ip_addr); - ctx.UNC = unc; - ctx.prepath ="" ; + len =sizeof (unc_fmt) +SERVER_NAME_LEN_WITH_NULL ; + ctx->UNC =kzalloc (len,GFP_KERNEL ); +if (!ctx->UNC) { + rc = -ENOMEM ; + goto out_free_ctx; + } +scnprintf (ctx->UNC, len, unc_fmt, ses->ip_addr); + ctx->prepath ="" ;/* Reuse same version as master connection */ - ctx.vals = ses->server->vals; - ctx.ops = ses->server->ops; + ctx->vals = ses->server->vals; + ctx->ops = ses->server->ops; - ctx.noblocksnd = ses->server->noblocksnd; - ctx.noautotune = ses->server->noautotune; - ctx.sockopt_tcp_nodelay = ses->server->tcp_nodelay; - ctx.echo_interval = ses->server->echo_interval /HZ ; - ctx.max_credits = ses->server->max_credits; + ctx->noblocksnd = ses->server->noblocksnd; + ctx->noautotune = ses->server->noautotune; + ctx->sockopt_tcp_nodelay = ses->server->tcp_nodelay; + ctx->echo_interval = ses->server->echo_interval /HZ ; + ctx->max_credits = ses->server->max_credits;/* * This will be used for encoding/decoding user/domain/pw * during sess setup auth. */ - ctx.local_nls = cifs_sb->local_nls; + ctx->local_nls = cifs_sb->local_nls;/* Use RDMA if possible */ - ctx.rdma = iface->rdma_capable; -memcpy (&ctx.dstaddr, &iface->sockaddr,sizeof (struct sockaddr_storage )); + ctx->rdma = iface->rdma_capable; +memcpy (&ctx->dstaddr, &iface->sockaddr,sizeof (ctx->dstaddr));/* reuse master con client guid */ -memcpy (&ctx.client_guid, ses->server->client_guid, -SMB2_CLIENT_GUID_SIZE ); - ctx.use_client_guid = true; +memcpy (&ctx->client_guid, ses->server->client_guid, +sizeof (ctx->client_guid)); + ctx->use_client_guid = true; - chan_server =cifs_get_tcp_session (&ctx, ses->server); + chan_server =cifs_get_tcp_session (ctx, ses->server);spin_lock (&ses->chan_lock); chan = &ses->chans[ses->chan_count];
@@ -497,6 +507,10 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,cifs_put_tcp_session (chan->server,0 ); } +kfree (ctx->UNC); +out_free_ctx: +kfree (ctx); +out_free_xid:free_xid (xid);return rc; }
Signature · 1 line
2.41.0
PATCH 13/17 smb: client: reduce stack usage in cifs_demultiplex_thread()
In reply to Paulo AlcantaraClang warns about exceeded stack frame size
fs/smb/client/connect.c:1109:1: warning: stack frame size (1048) exceeds limit (1024) in 'cifs_demultiplex_thread' [-Wframe-larger-than]
It turns out that clean_demultiplex_info() got inlined into cifs_demultiplex_thread(), so mark it as noinline_for_stack to save some stack space.
--- fs/smb/client/connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/connect.c +2 -2
@@ -911,8 +911,8 @@ cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required)return 0 ; } - -static void clean_demultiplex_info (struct TCP_Server_Info *server) +static noinline_for_stack void +clean_demultiplex_info (struct TCP_Server_Info *server) {int length;
Signature · 1 line
2.41.0
PATCH 14/17 smb: client: reduce stack usage in smb_send_rqst()
In reply to Paulo AlcantaraClang warns about exceeded stack frame size
fs/smb/client/transport.c:420:1: warning: stack frame size (1048) exceeds limit (1024) in 'smb_send_rqst' [-Wframe-larger-than]
Fix this by allocating a structure that will hold transform header and compound requests.
--- fs/smb/client/transport.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
fs/smb/client/transport.c +17 -12
@@ -416,13 +416,19 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,return rc; } +struct send_req_vars { +struct smb2_transform_hdr tr_hdr; +struct smb_rqst rqst[MAX_COMPOUND ]; +struct kvec iov; +}; +static int smb_send_rqst (struct TCP_Server_Info *server,int num_rqst,struct smb_rqst *rqst,int flags) { -struct kvec iov; -struct smb2_transform_hdr *tr_hdr; -struct smb_rqst cur_rqst[MAX_COMPOUND ]; +struct send_req_vars *vars; +struct smb_rqst *cur_rqst; +struct kvec *iov;int rc;if (!(flags &CIFS_TRANSFORM_REQ ))
@@ -436,16 +442,15 @@ smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,return -EIO ; } - tr_hdr =kzalloc (sizeof (*tr_hdr),GFP_NOFS ); -if (!tr_hdr) + vars =kzalloc (sizeof (*vars),GFP_NOFS ); +if (!vars)return -ENOMEM ; + cur_rqst = vars->rqst; + iov = &vars->iov; -memset (&cur_rqst[0 ],0 ,sizeof (cur_rqst)); -memset (&iov,0 ,sizeof (iov)); - - iov.iov_base = tr_hdr; - iov.iov_len =sizeof (*tr_hdr); - cur_rqst[0 ].rq_iov = &iov; + iov->iov_base = &vars->tr_hdr; + iov->iov_len =sizeof (vars->tr_hdr); + cur_rqst[0 ].rq_iov = iov; cur_rqst[0 ].rq_nvec =1 ; rc = server->ops->init_transform_rq(server, num_rqst + 1,
@@ -456,7 +461,7 @@ smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, rc =__smb_send_rqst (server, num_rqst +1 , &cur_rqst[0 ]);smb3_free_compound_rqst (num_rqst, &cur_rqst[1 ]); out: -kfree (tr_hdr); +kfree (vars);return rc; }
Signature · 1 line
2.41.0
PATCH 15/17 smb: client: reduce stack usage in smb2_set_ea()
In reply to Paulo AlcantaraClang warns about exceeded stack frame size
fs/smb/client/smb2ops.c:1080:1: warning: stack frame size (1432) exceeds limit (1024) in 'smb2_set_ea' [-Wframe-larger-than]
Fix this by allocating a structure that will hold most of the large variables.
--- fs/smb/client/cifsglob.h | 13 ++++++++++ fs/smb/client/smb2inode.c | 21 ++++------------ fs/smb/client/smb2ops.c | 50 ++++++++++++++++----------------------- 3 files changed, 37 insertions(+), 47 deletions(-)
fs/smb/client/cifsglob.h +13 -0
@@ -2214,4 +2214,17 @@ static inline void cifs_sg_set_buf(struct sg_table *sgtable, } } +struct smb2_compound_vars { +struct cifs_open_parms oparms; +struct kvec rsp_iov[3 ]; +struct smb_rqst rqst[3 ]; +struct kvec open_iov[SMB2_CREATE_IOV_SIZE ]; +struct kvec qi_iov; +struct kvec io_iov[SMB2_IOCTL_IOV_SIZE ]; +struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE ]; +struct kvec close_iov; +struct smb2_file_rename_info rename_info; +struct smb2_file_link_info link_info; +}; +#endif /* _CIFS_GLOB_H */
fs/smb/client/smb2inode.c +4 -17
@@ -35,19 +35,6 @@ free_set_inf_compound(struct smb_rqst *rqst)SMB2_close_free (&rqst[2 ]); } - -struct cop_vars { -struct cifs_open_parms oparms; -struct kvec rsp_iov[3 ]; -struct smb_rqst rqst[3 ]; -struct kvec open_iov[SMB2_CREATE_IOV_SIZE ]; -struct kvec qi_iov[1 ]; -struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE ]; -struct kvec close_iov[1 ]; -struct smb2_file_rename_info rename_info; -struct smb2_file_link_info link_info; -}; -/* * note: If cfile is passed, the reference to it is dropped here. * So make sure that you do not reuse cfile after return from this func.
@@ -63,7 +50,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, __u8 **extbuf, size_t *extbuflen, struct kvec *out_iov, int *out_buftype) { -struct cop_vars *vars =NULL ; +struct smb2_compound_vars *vars =NULL ;struct kvec *rsp_iov;struct smb_rqst *rqst;int rc;
@@ -134,7 +121,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,/* Operation */ switch (command) {case SMB2_OP_QUERY_INFO : - rqst[num_rqst].rq_iov = &vars->qi_iov[0 ]; + rqst[num_rqst].rq_iov = &vars->qi_iov; rqst[num_rqst].rq_nvec =1 ;if (cfile)
@@ -168,7 +155,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, full_path);break ;case SMB2_OP_POSIX_QUERY_INFO : - rqst[num_rqst].rq_iov = &vars->qi_iov[0 ]; + rqst[num_rqst].rq_iov = &vars->qi_iov; rqst[num_rqst].rq_nvec =1 ;if (cfile)
@@ -376,7 +363,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, goto after_close;/* Close */ flags |=CIFS_CP_CREATE_CLOSE_OP ; - rqst[num_rqst].rq_iov = &vars->close_iov[0 ]; + rqst[num_rqst].rq_iov = &vars->close_iov; rqst[num_rqst].rq_nvec =1 ; rc = SMB2_close_init(tcon, server, &rqst[num_rqst], COMPOUND_FID,
fs/smb/client/smb2ops.c +20 -30
143 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 16/17 smb: client: reduce stack usage in smb2_query_info_compound()
In reply to Paulo AlcantaraClang warns about exceeded stack frame size
fs/smb/client/smb2ops.c:2521:1: warning: stack frame size (1336) exceeds limit (1024) in 'smb2_query_info_compound' [-Wframe-larger-than]
Fix this by allocating a structure that will hold most of the large variables.
--- fs/smb/client/smb2ops.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
fs/smb/client/smb2ops.c +16 -14
@@ -2513,15 +2513,13 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, struct kvec *rsp, int *buftype, struct cifs_sb_info *cifs_sb) { + struct smb2_compound_vars *vars;struct cifs_ses *ses = tcon->ses;struct TCP_Server_Info *server =cifs_pick_channel (ses);int flags =CIFS_CP_CREATE_CLOSE_OP ; -struct smb_rqst rqst[3 ]; +struct smb_rqst *rqst;int resp_buftype[3 ]; -struct kvec rsp_iov[3 ]; -struct kvec open_iov[SMB2_CREATE_IOV_SIZE ]; -struct kvec qi_iov[1 ]; -struct kvec close_iov[1 ]; +struct kvec *rsp_iov;u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;struct cifs_open_parms oparms;struct cifs_fid fid;
@@ -2538,9 +2536,14 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ; -memset (rqst,0 ,sizeof (rqst)); resp_buftype[0 ] = resp_buftype[1 ] = resp_buftype[2 ] =CIFS_NO_BUFFER ; -memset (rsp_iov,0 ,sizeof (rsp_iov)); + vars =kzalloc (sizeof (*vars),GFP_KERNEL ); +if (!vars) { + rc = -ENOMEM ; + goto out_free_path; + } + rqst = vars->rqst; + rsp_iov = vars->rsp_iov;/* * We can only call this for things we know are directories.
@@ -2549,8 +2552,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,open_cached_dir (xid, tcon, path, cifs_sb, false, &cfid);/* cfid null if open dir failed */ -memset (&open_iov,0 ,sizeof (open_iov)); - rqst[0 ].rq_iov = open_iov; + rqst[0 ].rq_iov = vars->open_iov; rqst[0 ].rq_nvec =SMB2_CREATE_IOV_SIZE ; oparms = (struct cifs_open_parms ) {
@@ -2568,8 +2570,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, goto qic_exit;smb2_set_next_command (tcon, &rqst[0 ]); -memset (&qi_iov,0 ,sizeof (qi_iov)); - rqst[1 ].rq_iov = qi_iov; + rqst[1 ].rq_iov = &vars->qi_iov; rqst[1 ].rq_nvec =1 ;if (cfid) {
@@ -2596,8 +2597,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,smb2_set_related (&rqst[1 ]); } -memset (&close_iov,0 ,sizeof (close_iov)); - rqst[2 ].rq_iov = close_iov; + rqst[2 ].rq_iov = &vars->close_iov; rqst[2 ].rq_nvec =1 ; rc = SMB2_close_init(tcon, server,
@@ -2628,7 +2628,6 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, *buftype = resp_buftype[1 ]; qic_exit: -kfree (utf16_path);SMB2_open_free (&rqst[0 ]);SMB2_query_info_free (&rqst[1 ]);SMB2_close_free (&rqst[2 ]);
@@ -2636,6 +2635,9 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,free_rsp_buf (resp_buftype[2 ], rsp_iov[2 ].iov_base);if (cfid)close_cached_dir (cfid); +kfree (vars); +out_free_path: +kfree (utf16_path);return rc; }
Signature · 1 line
2.41.0
PATCH 17/17 smb: client: reduce stack usage in smb2_query_reparse_point()
In reply to Paulo AlcantaraClang warns about exceeded stack frame size
fs/smb/client/smb2ops.c:2973:12: warning: stack frame size (1336) exceeds limit (1024) in 'smb2_query_reparse_point' [-Wframe-larger-than]
Fix this by allocating a structure that will hold most of the large variables.
--- fs/smb/client/smb2ops.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
fs/smb/client/smb2ops.c +18 -17
@@ -2965,6 +2965,7 @@ static int smb2_query_reparse_point(const unsigned int xid, u32 *tag, struct kvec *rsp, int *rsp_buftype) { + struct smb2_compound_vars *vars;int rc;__le16 *utf16_path =NULL ;__u8 oplock =SMB2_OPLOCK_LEVEL_NONE ;
@@ -2972,12 +2973,9 @@ static int smb2_query_reparse_point(const unsigned int xid,struct cifs_fid fid;struct TCP_Server_Info *server =cifs_pick_channel (tcon->ses);int flags =CIFS_CP_CREATE_CLOSE_OP ; -struct smb_rqst rqst[3 ]; +struct smb_rqst *rqst;int resp_buftype[3 ]; -struct kvec rsp_iov[3 ]; -struct kvec open_iov[SMB2_CREATE_IOV_SIZE ]; -struct kvec io_iov[SMB2_IOCTL_IOV_SIZE ]; -struct kvec close_iov[1 ]; +struct kvec *rsp_iov;struct smb2_ioctl_rsp *ioctl_rsp;struct reparse_data_buffer *reparse_buf;u32 plen;
@@ -2987,20 +2985,24 @@ static int smb2_query_reparse_point(const unsigned int xid,if (smb3_encryption_required (tcon)) flags |=CIFS_TRANSFORM_REQ ; -memset (rqst,0 ,sizeof (rqst)); - resp_buftype[0 ] = resp_buftype[1 ] = resp_buftype[2 ] =CIFS_NO_BUFFER ; -memset (rsp_iov,0 ,sizeof (rsp_iov)); - utf16_path =cifs_convert_path_to_utf16 (full_path, cifs_sb);if (!utf16_path)return -ENOMEM ; + resp_buftype[0 ] = resp_buftype[1 ] = resp_buftype[2 ] =CIFS_NO_BUFFER ; + vars =kzalloc (sizeof (*vars),GFP_KERNEL ); +if (!vars) { + rc = -ENOMEM ; + goto out_free_path; + } + rqst = vars->rqst; + rsp_iov = vars->rsp_iov; +/* * setup smb2open - TODO add optimization to call cifs_get_readable_path * to see if there is a handle already open that we can use */ -memset (&open_iov,0 ,sizeof (open_iov)); - rqst[0 ].rq_iov = open_iov; + rqst[0 ].rq_iov = vars->open_iov; rqst[0 ].rq_nvec =SMB2_CREATE_IOV_SIZE ; oparms = (struct cifs_open_parms ) {
@@ -3020,8 +3022,7 @@ static int smb2_query_reparse_point(const unsigned int xid,/* IOCTL */ -memset (&io_iov,0 ,sizeof (io_iov)); - rqst[1 ].rq_iov = io_iov; + rqst[1 ].rq_iov = vars->io_iov; rqst[1 ].rq_nvec =SMB2_IOCTL_IOV_SIZE ; rc = SMB2_ioctl_init(tcon, server,
@@ -3036,10 +3037,8 @@ static int smb2_query_reparse_point(const unsigned int xid,smb2_set_next_command (tcon, &rqst[1 ]);smb2_set_related (&rqst[1 ]); -/* Close */ -memset (&close_iov,0 ,sizeof (close_iov)); - rqst[2 ].rq_iov = close_iov; + rqst[2 ].rq_iov = &vars->close_iov; rqst[2 ].rq_nvec =1 ; rc = SMB2_close_init(tcon, server,
@@ -3080,13 +3079,15 @@ static int smb2_query_reparse_point(const unsigned int xid, } query_rp_exit: -kfree (utf16_path);SMB2_open_free (&rqst[0 ]);SMB2_ioctl_free (&rqst[1 ]);SMB2_close_free (&rqst[2 ]);free_rsp_buf (resp_buftype[0 ], rsp_iov[0 ].iov_base);free_rsp_buf (resp_buftype[1 ], rsp_iov[1 ].iov_base);free_rsp_buf (resp_buftype[2 ], rsp_iov[2 ].iov_base); +kfree (vars); +out_free_path: +kfree (utf16_path);return rc; }
Signature · 1 line
2.41.0
Tentatively added to cifs-2.6.git for-next pending testing.
Opinions on whether any should be cc:stable?
Also let me know if anyone wants to add RB or Acked-by
Quoted 53 lines · Paulo Alcantara
Hi Steve,
Follow patchset with DFS, reparse point and -Wframe-larger-than fixes for v6.6.
Please review & test.
Paulo Alcantara (17):
smb: client: introduceDFS_CACHE_TGT_LIST()
smb: client: ensure to try all targets when finding nested links
smb: client: move some params tocifs_open_info_data
smb: client: makesmb2_compound_op()return resp buffer on success
smb: client: renamecifs_dfs_ref.ctonamespace.c
smb: client: get rid of dfs naming in automount code
smb: client: get rid of dfs code dep innamespace.c
smb: client: parse reparse point flag in create response
smb: client: do not query reparse points twice on symlinks
smb: client: query reparse points in older dialects
smb: cilent: set reparse mount points as automounts
smb: client: reduce stack usage incifs_try_adding_channels()
smb: client: reduce stack usage incifs_demultiplex_thread()
smb: client: reduce stack usage insmb_send_rqst()
smb: client: reduce stack usage insmb2_set_ea()
smb: client: reduce stack usage insmb2_query_info_compound()
smb: client: reduce stack usage insmb2_query_reparse_point()fs/smb/client/Makefile | 5 +- fs/smb/client/cifsfs.c | 2 +- fs/smb/client/cifsfs.h | 11 +- fs/smb/client/cifsglob.h | 69 ++- fs/smb/client/cifsproto.h | 9 +- fs/smb/client/connect.c | 8 +- fs/smb/client/dfs.c | 291 +++++----- fs/smb/client/dfs.h | 141 +++-- fs/smb/client/dfs_cache.c | 10 +- fs/smb/client/dfs_cache.h | 12 +- fs/smb/client/dir.c | 4 +- fs/smb/client/inode.c | 530 ++++++++++-------- fs/smb/client/{cifs_dfs_ref.c => namespace.c} | 113 ++-- fs/smb/client/readdir.c | 23 +- fs/smb/client/sess.c | 68 ++- fs/smb/client/smb1ops.c | 26 +- fs/smb/client/smb2inode.c | 199 ++++--- fs/smb/client/smb2ops.c | 283 +++------- fs/smb/client/smb2proto.h | 17 +- fs/smb/client/transport.c | 29 +- 20 files changed, 993 insertions(+), 857 deletions(-) rename fs/smb/client/{cifs_dfs_ref.c => namespace.c} (62%)--
2.41.0
Signature · 3 lines
Thanks, Steve