reparse points work
Subsystems (2)
v2 cover reparse points work
Hi Steve,
This series contains reparse point fixes and improvements for SMB2+:
- Add support for creating character/block devices, sockets and fifos via NFS reparse points by default.
- Add support for creating SMB symlinks via IO_REPARSE_TAG_SYMLINK reparse points.
- smb2_compound_op()
* allow up to MAX_COMPOUND(5) commands in a single compound request
* introduce SMB2_OP_{GET,SET}_REPARSE commands
- Optimisations for dentry revalidation and read/write of reparse points by reducing number of roundtrips.
- Fix renaming and hardlinking of reparse points
For people who pass 'mfsymlinks' and 'sfu' mount options, the implementation is expected to avoid creating reparse points at all.
Volker Lendecke had suggested trying to create both SMB symlink and mfsymlink in a single compound request but this series doesn't have it. It could be implemented later.
---
Changes in v2:
- Fix missing mode bits for SMB symlinks (reported by Steve)
- Fix uninitialised var warnings (reported by kernel test robot)
- Add dentry reval optimisation for SMB3 POSIX query info as well
---
Paulo Alcantara (9):
smb: client: extend smb2_compound_op() to accept more commands
smb: client: allow creating special files via reparse points
smb: client: allow creating symlinks via reparse points
smb: client: optimise reparse point querying
smb: client: fix renaming of reparse points
smb: client: fix hardlinking of reparse points
smb: client: cleanup smb2_query_reparse_point()
smb: client: optimise dentry revalidation for reparse points
smb: client: fix missing mode bits for SMB symlinks
fs/smb/client/cifsglob.h | 47 +- fs/smb/client/cifsproto.h | 30 +- fs/smb/client/cifssmb.c | 17 +- fs/smb/client/dir.c | 7 +- fs/smb/client/file.c | 10 +- fs/smb/client/inode.c | 98 ++-- fs/smb/client/link.c | 29 +- fs/smb/client/smb2glob.h | 26 +- fs/smb/client/smb2inode.c | 1054 ++++++++++++++++++++++--------------- fs/smb/client/smb2ops.c | 297 ++++++----- fs/smb/client/smb2proto.h | 29 +- fs/smb/client/trace.h | 7 +- 12 files changed, 997 insertions(+), 654 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/9 smb: client: extend smb2_compound_op() to accept more commands
Make smb2_compound_op() accept up to MAX_COMPOUND(5) commands to be sent over a single compounded request.
This will allow next commits to read and write reparse files through a single roundtrip to the server.
--- fs/smb/client/cifsglob.h | 4 +- fs/smb/client/smb2inode.c | 790 +++++++++++++++++++------------------- 2 files changed, 406 insertions(+), 388 deletions(-)
fs/smb/client/cifsglob.h +2 -2
@@ -2238,8 +2238,8 @@ 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 rsp_iov[MAX_COMPOUND ]; +struct smb_rqst rqst[MAX_COMPOUND ];struct kvec open_iov[SMB2_CREATE_IOV_SIZE ];struct kvec qi_iov;struct kvec io_iov[SMB2_IOCTL_IOV_SIZE ];
fs/smb/client/smb2inode.c +404 -386
975 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/9 smb: client: allow creating special files via reparse points
In reply to Paulo AlcantaraAdd support for creating special files (e.g. char/block devices, sockets, fifos) via NFS reparse points on SMB2+, which are fully supported by most SMB servers and documented in MS-FSCC.
smb2_get_reparse_inode() creates the file with a corresponding reparse point buffer set in @iov through a single roundtrip to the server.
--- fs/smb/client/cifsproto.h | 8 +++- fs/smb/client/dir.c | 7 +-- fs/smb/client/file.c | 10 +++-- fs/smb/client/inode.c | 76 ++++++++++++++++++++----------- fs/smb/client/link.c | 10 +++-- fs/smb/client/smb2glob.h | 25 ++++++----- fs/smb/client/smb2inode.c | 75 +++++++++++++++++++++++++++++++ fs/smb/client/smb2ops.c | 94 +++++++++++++++++++++++++++++++++++---- fs/smb/client/smb2proto.h | 7 +++ fs/smb/client/trace.h | 4 +- 10 files changed, 256 insertions(+), 60 deletions(-)
fs/smb/client/cifsproto.h +6 -2
@@ -211,8 +211,12 @@ int cifs_get_inode_info(struct inode **inode, const char *full_path,bool cifs_reparse_point_to_fattr (struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr,struct cifs_open_info_data *data); -extern int smb311_posix_get_inode_info (struct inode **pinode,const char *search_path, -struct super_block *sb,unsigned int xid); + +extern int smb311_posix_get_inode_info (struct inode **inode, +const char *full_path, +struct cifs_open_info_data *data, +struct super_block *sb, +const unsigned int xid);extern int cifs_get_inode_info_unix (struct inode **pinode,const unsigned char *search_path,struct super_block *sb,unsigned int xid);
fs/smb/client/dir.c +4 -3
@@ -680,9 +680,10 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, full_path, d_inode(direntry)); again: -if (pTcon->posix_extensions) - rc =smb311_posix_get_inode_info (&newInode, full_path, parent_dir_inode->i_sb, xid); -else if (pTcon->unix_ext) { +if (pTcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&newInode, full_path,NULL , + parent_dir_inode->i_sb, xid); + }else if (pTcon->unix_ext) { rc =cifs_get_inode_info_unix (&newInode, full_path, parent_dir_inode->i_sb, xid); }else {
fs/smb/client/file.c +6 -4
@@ -1020,14 +1020,16 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)if (!is_interrupt_error (rc))mapping_set_error (inode->i_mapping, rc); -if (tcon->posix_extensions) - rc =smb311_posix_get_inode_info (&inode, full_path, inode->i_sb, xid); -else if (tcon->unix_ext) +if (tcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&inode, full_path, +NULL , inode->i_sb, xid); + }else if (tcon->unix_ext) { rc =cifs_get_inode_info_unix (&inode, full_path, inode->i_sb, xid); -else + }else { rc =cifs_get_inode_info (&inode, full_path,NULL , inode->i_sb, xid,NULL ); + } }/* * Else we are writing out data to server already and could deadlock if
fs/smb/client/inode.c +50 -26
170 lines not on this page · raw message
fs/smb/client/link.c +6 -4
@@ -614,14 +614,16 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,cifs_sb_target->local_nls); */ if (rc ==0 ) { -if (pTcon->posix_extensions) - rc =smb311_posix_get_inode_info (&newinode, full_path, inode->i_sb, xid); -else if (pTcon->unix_ext) +if (pTcon->posix_extensions) { + rc =smb311_posix_get_inode_info (&newinode, full_path, +NULL , inode->i_sb, xid); + }else if (pTcon->unix_ext) { rc =cifs_get_inode_info_unix (&newinode, full_path, inode->i_sb, xid); -else + }else { rc =cifs_get_inode_info (&newinode, full_path,NULL , inode->i_sb, xid,NULL ); + }if (rc !=0 ) { cifs_dbg(FYI, "Create symlink ok, getinodeinfo fail rc = %d\n",
fs/smb/client/smb2glob.h +14 -11
@@ -23,17 +23,20 @@* Identifiers for functions that use the open, operation, close pattern * in smb2inode.c:smb2_compound_op() */ -#define SMB2_OP_SET_DELETE 1 -#define SMB2_OP_SET_INFO 2 -#define SMB2_OP_QUERY_INFO 3 -#define SMB2_OP_QUERY_DIR 4 -#define SMB2_OP_MKDIR 5 -#define SMB2_OP_RENAME 6 -#define SMB2_OP_DELETE 7 -#define SMB2_OP_HARDLINK 8 -#define SMB2_OP_SET_EOF 9 -#define SMB2_OP_RMDIR 10 -#define SMB2_OP_POSIX_QUERY_INFO 11 +enum smb2_compound_ops { +SMB2_OP_SET_DELETE =1 , +SMB2_OP_SET_INFO , +SMB2_OP_QUERY_INFO , +SMB2_OP_QUERY_DIR , +SMB2_OP_MKDIR , +SMB2_OP_RENAME , +SMB2_OP_DELETE , +SMB2_OP_HARDLINK , +SMB2_OP_SET_EOF , +SMB2_OP_RMDIR , +SMB2_OP_POSIX_QUERY_INFO , +SMB2_OP_SET_REPARSE +};/* Used when constructing chained read requests. */ #define CHAINED_REQUEST 1
fs/smb/client/smb2inode.c +75 -0
90 lines not on this page · raw message
fs/smb/client/smb2ops.c +85 -9
111 lines not on this page · raw message
fs/smb/client/smb2proto.h +7 -0
@@ -56,6 +56,12 @@ 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); +struct inode *smb2_get_reparse_inode (struct cifs_open_info_data *data, +struct super_block *sb, +const unsigned int xid, +struct cifs_tcon *tcon, +const char *full_path, +struct kvec *iov); int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb,
@@ -287,4 +293,5 @@ int smb311_posix_query_path_info(const unsigned int xid,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); +#endif /* _SMB2PROTO_H */
fs/smb/client/trace.h +3 -1
@@ -370,11 +370,11 @@ DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(rename_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (rmdir_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (set_eof_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (set_info_compound_enter); +DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (set_reparse_compound_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (delete_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (mkdir_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (tdis_enter); - DECLARE_EVENT_CLASS(smb3_inf_compound_done_class, TP_PROTO(unsigned int xid, __u32 tid,
@@ -408,6 +408,7 @@ DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(rename_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (rmdir_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (set_eof_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (set_info_compound_done); +DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (set_reparse_compound_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (delete_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (mkdir_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (tdis_done);
@@ -451,6 +452,7 @@ DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(rename_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (rmdir_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (set_eof_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (set_info_compound_err); +DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (set_reparse_compound_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (mkdir_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (delete_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (tdis_err);
Signature · 1 line
2.43.0
PATCH v2 3/9 smb: client: allow creating symlinks via reparse points
In reply to Paulo AlcantaraAdd support for creating symlinks via IO_REPARSE_TAG_SYMLINK reparse points in SMB2+.
These are fully supported by most SMB servers and documented in MS-FSCC. Also have the advantage of requiring fewer roundtrips as their symlink targets can be parsed directly from CREATE responses on STATUS_STOPPED_ON_SYMLINK errors.
--- fs/smb/client/cifsglob.h | 6 ++++ fs/smb/client/link.c | 15 ++++++--- fs/smb/client/smb2ops.c | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-)
fs/smb/client/cifsglob.h +6 -0
@@ -559,6 +559,12 @@ struct smb_version_operations {int (*parse_reparse_point)(struct cifs_sb_info *cifs_sb,struct kvec *rsp_iov,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); };struct smb_version_values {
fs/smb/client/link.c +10 -5
@@ -569,6 +569,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,int rc = -EOPNOTSUPP ;unsigned int xid;struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb); +struct TCP_Server_Info *server;struct tcon_link *tlink;struct cifs_tcon *pTcon;const char *full_path;
@@ -590,6 +591,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode, goto symlink_exit; } pTcon =tlink_tcon (tlink); + server =cifs_pick_channel (pTcon->ses); full_path =build_path_from_dentry (direntry, page);if (IS_ERR (full_path)) {
@@ -601,17 +603,20 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,cifs_dbg (FYI ,"symname is %s\n" , symname);/* BB what if DFS and this volume is on different share? BB */ -if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) +if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) { rc =create_mf_symlink (xid, pTcon, cifs_sb, full_path, symname); #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY - else if (pTcon->unix_ext) + }else if (pTcon->unix_ext) { rc =CIFSUnixCreateSymLink (xid, pTcon, full_path, symname, cifs_sb->local_nls,cifs_remap (cifs_sb));#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ -/* else -rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName, -cifs_sb_target->local_nls); */ + }else if (server->ops->create_reparse_symlink) { + rc = server->ops->create_reparse_symlink (xid, inode, direntry, + pTcon, full_path, + symname); + goto symlink_exit; + }if (rc ==0 ) {if (pTcon->posix_extensions) {
fs/smb/client/smb2ops.c +70 -0
100 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 4/9 smb: client: optimise reparse point querying
In reply to Paulo AlcantaraReduce number of roundtrips made to server when querying reparse points in ->query_path_info() by sending a single compound request of create+get_reparse+get_info+close.
--- fs/smb/client/cifsglob.h | 10 ++-- fs/smb/client/cifsproto.h | 7 +++ fs/smb/client/inode.c | 5 +- fs/smb/client/smb2glob.h | 3 +- fs/smb/client/smb2inode.c | 121 ++++++++++++++++++++++++++++++-------- fs/smb/client/trace.h | 3 + 6 files changed, 118 insertions(+), 31 deletions(-)
fs/smb/client/cifsglob.h +5 -5
@@ -192,6 +192,11 @@ struct cifs_open_info_data {bool symlink; };struct { +/* ioctl response buffer */ +struct { +int buftype; +struct kvec iov; + } io;__u32 tag;union {struct reparse_data_buffer *buf;
@@ -209,11 +214,6 @@ struct cifs_open_info_data { ((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); -} -/* ***************************************************************** * Except the CIFS PDUs themselves all the
fs/smb/client/cifsproto.h +7 -0
@@ -764,4 +764,11 @@ static inline void release_mid(struct mid_q_entry *mid) kref_put(&mid->refcount, __release_mid); } +static inline void cifs_free_open_info (struct cifs_open_info_data *data) +{ +kfree (data->symlink_target); +free_rsp_buf (data->reparse.io.buftype, data->reparse.io.iov.iov_base); +memset (data,0 ,sizeof (*data)); +} +#endif /* _CIFSPROTO_H */
fs/smb/client/inode.c +4 -1
@@ -1076,6 +1076,9 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data, &rsp_iov, &rsp_buftype);if (!rc) iov = &rsp_iov; + }else if (data->reparse.io.buftype !=CIFS_NO_BUFFER && + data->reparse.io.iov.iov_base) { + iov = &data->reparse.io.iov; } rc = -EOPNOTSUPP ;
@@ -1095,7 +1098,7 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data,/* Check for cached reparse point data */ if (data->symlink_target || data->reparse.buf) { rc =0 ; - }else if (server->ops->parse_reparse_point) { + }else if (iov && server->ops->parse_reparse_point) { rc = server->ops->parse_reparse_point (cifs_sb, iov, data); }
fs/smb/client/smb2glob.h +2 -1
@@ -35,7 +35,8 @@ enum smb2_compound_ops {SMB2_OP_SET_EOF ,SMB2_OP_RMDIR ,SMB2_OP_POSIX_QUERY_INFO , - SMB2_OP_SET_REPARSE +SMB2_OP_SET_REPARSE , + SMB2_OP_GET_REPARSE };/* Used when constructing chained read requests. */
fs/smb/client/smb2inode.c +97 -24
217 lines not on this page · raw message
fs/smb/client/trace.h +3 -0
@@ -371,6 +371,7 @@ DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(rmdir_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (set_eof_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (set_info_compound_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (set_reparse_compound_enter); +DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (get_reparse_compound_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (delete_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (mkdir_enter);DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT (tdis_enter);
@@ -409,6 +410,7 @@ DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(rmdir_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (set_eof_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (set_info_compound_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (set_reparse_compound_done); +DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (get_reparse_compound_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (delete_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (mkdir_done);DEFINE_SMB3_INF_COMPOUND_DONE_EVENT (tdis_done);
@@ -453,6 +455,7 @@ DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(rmdir_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (set_eof_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (set_info_compound_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (set_reparse_compound_err); +DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (get_reparse_compound_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (mkdir_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (delete_err);DEFINE_SMB3_INF_COMPOUND_ERR_EVENT (tdis_err);
Signature · 1 line
2.43.0
PATCH v2 5/9 smb: client: fix renaming of reparse points
In reply to Paulo AlcantaraThe client was sending an SMB2_CREATE request without setting OPEN_REPARSE_POINT flag thus failing the entire rename operation.
Fix this by setting OPEN_REPARSE_POINT in create options for SMB2_CREATE request when the source inode is a repase point.
--- fs/smb/client/cifsglob.h | 23 ++++++++++++++---- fs/smb/client/cifsproto.h | 7 +++--- fs/smb/client/cifssmb.c | 8 +++---- fs/smb/client/inode.c | 4 +++- fs/smb/client/smb2inode.c | 50 +++++++++++++++++++++++---------------- fs/smb/client/smb2proto.h | 8 ++++--- 6 files changed, 63 insertions(+), 37 deletions(-)
fs/smb/client/cifsglob.h +18 -5
@@ -210,9 +210,18 @@ struct cifs_open_info_data { }; }; -#define cifs_open_data_reparse (d) \ - ((d)->reparse_point || \ - (le32_to_cpu((d)->fi.Attributes) & ATTR_REPARSE)) +static inline bool cifs_open_data_reparse (struct cifs_open_info_data *data) +{ +struct smb2_file_all_info *fi = &data->fi; +u32 attrs =le32_to_cpu (fi->Attributes); +bool ret; + + ret = data->reparse_point || (attrs &ATTR_REPARSE ); +if (ret) + attrs |=ATTR_REPARSE ; + fi->Attributes =cpu_to_le32 (attrs); +return ret; +}/* *****************************************************************
@@ -390,8 +399,11 @@ struct smb_version_operations {int (*rename_pending_delete)(const char *,struct dentry *,const unsigned int );/* send rename request */ -int (*rename)(const unsigned int ,struct cifs_tcon *,const char *, -const char *,struct cifs_sb_info *); +int (*rename)(const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb);/* send create hardlink request */ int (*create_hardlink)(const unsigned int, struct cifs_tcon *, const char *, const char *,
@@ -1551,6 +1563,7 @@ struct cifsInodeInfo {spinlock_t deferred_lock;/* protection on deferred list */ bool lease_granted;/* Flag to indicate whether lease or oplock is granted. */ char *symlink_target; + bool reparse:1; }; static inline struct cifsInodeInfo *
fs/smb/client/cifsproto.h +4 -3
@@ -439,9 +439,10 @@ extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, int remap_special_chars);extern int CIFSSMBDelFile (const unsigned int xid,struct cifs_tcon *tcon,const char *name,struct cifs_sb_info *cifs_sb); -extern int CIFSSMBRename (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb); +int CIFSSMBRename (const unsigned int xid,struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb); extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, int netfid, const char *target_name, const struct nls_table *nls_codepage,
fs/smb/client/cifssmb.c +4 -4
@@ -2147,10 +2147,10 @@ CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id)return rc; } -int -CIFSSMBRename (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb) +int CIFSSMBRename (const unsigned int xid,struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb) {int rc =0 ;RENAME_REQ *pSMB =NULL ;
fs/smb/client/inode.c +3 -1
@@ -214,6 +214,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) cifs_i->symlink_target = fattr->cf_symlink_target; fattr->cf_symlink_target =NULL ; } + cifs_i->reparse = !!(fattr->cf_cifsattrs &ATTR_REPARSE );spin_unlock (&inode->i_lock);if (fattr->cf_flags &CIFS_FATTR_JUNCTION )
@@ -2242,7 +2243,8 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,return -ENOSYS ;/* try path-based rename first */ - rc = server->ops->rename (xid, tcon, from_path, to_path, cifs_sb); + rc = server->ops->rename (xid, tcon, from_dentry, + from_path, to_path, cifs_sb);/* * Don't bother with rename by filehandle unless file is busy and
fs/smb/client/smb2inode.c +29 -21
75 lines not on this page · raw message
fs/smb/client/smb2proto.h +5 -3
@@ -86,9 +86,11 @@ extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb);extern int smb2_unlink (const unsigned int xid,struct cifs_tcon *tcon,const char *name,struct cifs_sb_info *cifs_sb); -extern int smb2_rename_path (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb); +int smb2_rename_path (const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb);extern int smb2_create_hardlink (const unsigned int xid,struct cifs_tcon *tcon,const char *from_name,const char *to_name,struct cifs_sb_info *cifs_sb);
Signature · 1 line
2.43.0
PATCH v2 6/9 smb: client: fix hardlinking of reparse points
In reply to Paulo AlcantaraThe client was sending an SMB2_CREATE request without setting OPEN_REPARSE_POINT flag thus failing the entire hardlink operation.
Fix this by setting OPEN_REPARSE_POINT in create options for SMB2_CREATE request when the source inode is a repase point.
--- fs/smb/client/cifsglob.h | 8 +++++--- fs/smb/client/cifsproto.h | 8 +++++--- fs/smb/client/cifssmb.c | 9 +++++---- fs/smb/client/link.c | 4 ++-- fs/smb/client/smb2inode.c | 34 ++++++++++++++++++++++------------ fs/smb/client/smb2proto.h | 8 +++++--- 6 files changed, 44 insertions(+), 27 deletions(-)
fs/smb/client/cifsglob.h +5 -3
@@ -405,9 +405,11 @@ struct smb_version_operations { const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb);/* send create hardlink request */ -int (*create_hardlink)(const unsigned int ,struct cifs_tcon *, -const char *,const char *, -struct cifs_sb_info *); +int (*create_hardlink)(const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb);/* query symlink target */ int (*query_symlink)(const unsigned int xid, struct cifs_tcon *tcon,
fs/smb/client/cifsproto.h +5 -3
@@ -447,9 +447,11 @@ extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, int netfid, const char *target_name, const struct nls_table *nls_codepage, int remap_special_chars); -extern int CIFSCreateHardLink (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb); +int CIFSCreateHardLink (const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb); extern int CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, const char *fromName, const char *toName,
fs/smb/client/cifssmb.c +5 -4
@@ -2528,10 +2528,11 @@ CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon,return rc; } -int -CIFSCreateHardLink (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb) +int CIFSCreateHardLink (const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb) {int rc =0 ;NT_RENAME_REQ *pSMB =NULL ;
fs/smb/client/link.c +2 -2
@@ -510,8 +510,8 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode, rc = -ENOSYS ; goto cifs_hl_exit; } - rc = server->ops->create_hardlink (xid, tcon, from_name, to_name, - cifs_sb); + rc = server->ops->create_hardlink (xid, tcon, old_file, + from_name, to_name, cifs_sb);if ((rc == -EIO ) || (rc == -EINVAL )) rc = -EOPNOTSUPP ; }
fs/smb/client/smb2inode.c +22 -12
@@ -43,6 +43,18 @@ static struct reparse_data_buffer *reparse_buf_ptr(struct kvec *iov)return buf; } +static inline __u32 file_create_options (struct dentry *dentry) +{ +struct cifsInodeInfo *ci; + +if (dentry) { + ci =CIFS_I (d_inode (dentry)); +if (ci->reparse) +return OPEN_REPARSE_POINT ; + } +return 0 ; +} +/* * 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.
@@ -919,15 +931,10 @@ int smb2_rename_path(const unsigned int xid, const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb) { - struct cifsInodeInfo *ci; + struct cifsFileInfo *cfile; -__u32 co =0 ; +__u32 co =file_create_options (source_dentry); -if (source_dentry) { - ci =CIFS_I (d_inode (source_dentry)); -if (ci->reparse) - co |=OPEN_REPARSE_POINT ; - }drop_cached_dir_by_name (xid, tcon, from_name, cifs_sb);cifs_get_writable_path (tcon, from_name,FIND_WR_WITH_DELETE , &cfile);
@@ -935,13 +942,16 @@ int smb2_rename_path(const unsigned int xid, co, DELETE, SMB2_OP_RENAME, cfile); } -int -smb2_create_hardlink (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb) +int smb2_create_hardlink (const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb) { +__u32 co =file_create_options (source_dentry); +return smb2_set_path_attr (xid, tcon, from_name, to_name, - cifs_sb,0 ,FILE_READ_ATTRIBUTES , + cifs_sb, co,FILE_READ_ATTRIBUTES ,SMB2_OP_HARDLINK ,NULL ); }
fs/smb/client/smb2proto.h +5 -3
@@ -91,9 +91,11 @@ int smb2_rename_path(const unsigned int xid,struct dentry *source_dentry, const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb); -extern int smb2_create_hardlink (const unsigned int xid,struct cifs_tcon *tcon, -const char *from_name,const char *to_name, -struct cifs_sb_info *cifs_sb); +int smb2_create_hardlink (const unsigned int xid, +struct cifs_tcon *tcon, +struct dentry *source_dentry, +const char *from_name,const char *to_name, +struct cifs_sb_info *cifs_sb);extern int smb3_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);
Signature · 1 line
2.43.0
PATCH v2 7/9 smb: client: cleanup smb2_query_reparse_point()
In reply to Paulo AlcantaraUse smb2_compound_op() with SMB2_OP_GET_REPARSE to get reparse point.
--- fs/smb/client/smb2inode.c | 33 ++++++++++ fs/smb/client/smb2ops.c | 133 -------------------------------------- fs/smb/client/smb2proto.h | 6 ++ 3 files changed, 39 insertions(+), 133 deletions(-)
fs/smb/client/smb2inode.c +33 -0
@@ -1053,3 +1053,36 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data, }return rc ?ERR_PTR (rc) : new; } + +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) +{ +struct cifs_open_info_data data = {}; +struct cifsFileInfo *cfile; +struct kvec in_iov = { .iov_base = &data, .iov_len =sizeof (data), }; +int rc; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + +cifs_get_readable_path (tcon, full_path, &cfile); + rc =smb2_compound_op (xid, tcon, cifs_sb, full_path, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT ,ACL_NO_MODE , &in_iov, + &(int ){SMB2_OP_GET_REPARSE },1 , cfile, +NULL ,NULL ,NULL ,NULL ); +if (rc) + goto out; + + *tag = data.reparse.tag; + *rsp = data.reparse.io.iov; + *rsp_buftype = data.reparse.io.buftype; +memset (&data.reparse.io.iov,0 ,sizeof (data.reparse.io.iov)); + data.reparse.io.buftype =CIFS_NO_BUFFER ; +out: +cifs_free_open_info (&data); +return rc; +}
fs/smb/client/smb2ops.c +0 -133
139 lines not on this page · raw message
fs/smb/client/smb2proto.h +6 -0
@@ -62,6 +62,12 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data,struct cifs_tcon *tcon, const char *full_path, struct kvec *iov); +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 smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb,
Signature · 1 line
2.43.0
PATCH v2 8/9 smb: client: optimise dentry revalidation for reparse points
In reply to Paulo AlcantaraIf the positive dentry is known to be a reparse point already, save a roundtrip in smb2_query_path_info() and smb311_posix_query_path_info() by sending compound request with OPEN_REPARSE_POINT.
--- fs/smb/client/inode.c | 15 +++++++++++---- fs/smb/client/smb2inode.c | 11 ++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-)
fs/smb/client/inode.c +11 -4
@@ -1142,6 +1142,8 @@ static int cifs_get_fattr(struct cifs_open_info_data *data,*/ if (!data) { +if (*inode &&CIFS_I (*inode)->reparse) + tmp_data.reparse_point = true; rc = server->ops->query_path_info (xid, tcon, cifs_sb, full_path, &tmp_data); data = &tmp_data;
@@ -1301,6 +1303,7 @@ int cifs_get_inode_info(struct inode **inode,static int smb311_posix_get_fattr (struct cifs_open_info_data *data,struct cifs_fattr *fattr, +struct inode **inode,const char *full_path,struct super_block *sb,const unsigned int xid)
@@ -1322,6 +1325,8 @@ static int smb311_posix_get_fattr(struct cifs_open_info_data *data,* 1. Fetch file metadata if not provided (data) */ if (!data) { +if (*inode &&CIFS_I (*inode)->reparse) + tmp_data.reparse_point = true; rc =smb311_posix_query_path_info (xid, tcon, cifs_sb, full_path, &tmp_data, &owner, &group);
@@ -1390,7 +1395,7 @@ int smb311_posix_get_inode_info(struct inode **inode,return 0 ; } - rc =smb311_posix_get_fattr (data, &fattr, full_path, sb, xid); + rc =smb311_posix_get_fattr (data, &fattr, inode, full_path, sb, xid);if (rc) goto out;
@@ -1537,10 +1542,12 @@ struct inode *cifs_root_iget(struct super_block *sb) }convert_delimiter (path,CIFS_DIR_SEP (cifs_sb)); -if (tcon->posix_extensions) - rc =smb311_posix_get_fattr (NULL , &fattr, path, sb, xid); -else +if (tcon->posix_extensions) { + rc =smb311_posix_get_fattr (NULL , &fattr, &inode, + path, sb, xid); + }else { rc =cifs_get_fattr (NULL , sb, xid,NULL , &fattr, &inode, path); + } iget_root:if (!rc) {
fs/smb/client/smb2inode.c +8 -3
@@ -667,7 +667,6 @@ int smb2_query_path_info(const unsigned int xid,int rc, rc2; data->adjust_tz = false; - data->reparse_point = false;if (strcmp (full_path,"" )) rc = -ENOENT ;
@@ -689,6 +688,9 @@ int smb2_query_path_info(const unsigned int xid, in_iov[0 ].iov_len =sizeof (*data); in_iov[1 ] = in_iov[0 ]; +if (data->reparse_point) + goto open_reparse; +cifs_get_readable_path (tcon, full_path, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
@@ -714,6 +716,7 @@ int smb2_query_path_info(const unsigned int xid,/* symlink already parsed in create response */ num_cmds =1 ; }else { +open_reparse: cmds[1 ] =SMB2_OP_GET_REPARSE ; num_cmds =2 ; }
@@ -766,8 +769,6 @@ int smb311_posix_query_path_info(const unsigned int xid,int i, num_cmds; data->adjust_tz = false; - data->reparse_point = false; -/* * BB TODO: Add support for using the cached root handle. * Create SMB2_query_posix_info worker function to do non-compounded query
@@ -778,6 +779,9 @@ int smb311_posix_query_path_info(const unsigned int xid, in_iov[0 ].iov_len =sizeof (*data); in_iov[1 ] = in_iov[0 ]; +if (data->reparse_point) + goto open_reparse; +cifs_get_readable_path (tcon, full_path, &cfile); rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
@@ -802,6 +806,7 @@ int smb311_posix_query_path_info(const unsigned int xid,/* symlink already parsed in create response */ num_cmds =1 ; }else { +open_reparse: cmds[1 ] =SMB2_OP_GET_REPARSE ; num_cmds =2 ; }
Signature · 1 line
2.43.0
PATCH v2 9/9 smb: client: fix missing mode bits for SMB symlinks
In reply to Paulo AlcantaraWhen instantiating inodes for SMB symlinks, add the mode bits from @cifs_sb->ctx->file_mode as we already do for the other special files.
--- fs/smb/client/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/inode.c +1 -1
@@ -791,7 +791,7 @@ bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb,case 0 :/* SMB1 symlink */ case IO_REPARSE_TAG_SYMLINK :case IO_REPARSE_TAG_NFS : - fattr->cf_mode =S_IFLNK ; + fattr->cf_mode =S_IFLNK | cifs_sb->ctx->file_mode; fattr->cf_dtype =DT_LNK ;break ;default :
Signature · 1 line
2.43.0
tentatively merged to cifs-2.6.git for-next pending more testing and review
rearranged order slightly to move patch 9 up (and added Cc: stable to that one)
Quoted 64 lines · Paulo Alcantara
Hi Steve,
This series contains reparse point fixes and improvements for SMB2+:
- Add support for creating character/block devices, sockets and fifos via NFS reparse points by default.
- Add support for creating SMB symlinks via
IO_REPARSE_TAG_SYMLINKreparse points.-
smb2_compound_op()* allow up to
MAX_COMPOUND(5)commands in a single compound request
* introduce SMB2_OP_{GET,SET}_REPARSE commands- Optimisations for dentry revalidation and read/write of reparse points by reducing number of roundtrips.
- Fix renaming and hardlinking of reparse points
For people who pass 'mfsymlinks' and 'sfu' mount options, the implementation is expected to avoid creating reparse points at all.
Volker Lendecke had suggested trying to create both SMB symlink and mfsymlink in a single compound request but this series doesn't have it. It could be implemented later.
Signed-off-by Paulo Alcantara (SUSE) <[email protected]>---
Changes in v2:
- Fix missing mode bits for SMB symlinks (reported by Steve)
- Fix uninitialised var warnings (reported by kernel test robot)
- Add dentry reval optimisation for SMB3 POSIX query info as well---
Paulo Alcantara (9):
smb: client: extendsmb2_compound_op()to accept more commands
smb: client: allow creating special files via reparse points
smb: client: allow creating symlinks via reparse points
smb: client: optimise reparse point querying
smb: client: fix renaming of reparse points
smb: client: fix hardlinking of reparse points
smb: client: cleanupsmb2_query_reparse_point()
smb: client: optimise dentry revalidation for reparse points
smb: client: fix missing mode bits for SMB symlinksfs/smb/client/cifsglob.h | 47 +- fs/smb/client/cifsproto.h | 30 +- fs/smb/client/cifssmb.c | 17 +- fs/smb/client/dir.c | 7 +- fs/smb/client/file.c | 10 +- fs/smb/client/inode.c | 98 ++-- fs/smb/client/link.c | 29 +- fs/smb/client/smb2glob.h | 26 +- fs/smb/client/smb2inode.c | 1054 ++++++++++++++++++++++--------------- fs/smb/client/smb2ops.c | 297 ++++++----- fs/smb/client/smb2proto.h | 29 +- fs/smb/client/trace.h | 7 +- 12 files changed, 997 insertions(+), 654 deletions(-)--
2.43.0
Signature · 3 lines
Thanks, Steve
Quoted 2 lines · Steve French
tentatively merged to cifs-2.6.git for-next pending more testing and review
Please drop patch 8/9 as it is wrong. We can't really do that as the file could have been changed on server side to a regular file and therefore the client would keep trying to open it as a reparse point. That can be easily reproduced.
Yeah, that is the price we get when we don't have such information directly from query dir responses. Looking forward to having it with the SMB3 POSIX spec :-)