Skip to contentSkip to conversation

cifs: Cleanup of duplicated structures

PATCH In review Pali Rohár 2 participants 5 messages Dec 22, 2024 – Dec 24, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover cifs: Cleanup of duplicated structures

This patch series contains only code cleanup of few duplicates structures and enums between smb/common and smb/client subdirs. No function change.

Can be useful also for ksmbd server part.

Pali Rohár (3):
cifs: Remove struct reparse_posix_data from struct cifs_open_info_data
cifs: Remove duplicate struct reparse_symlink_data and
SYMLINK_FLAG_RELATIVE
cifs: Rename struct reparse_posix_data to reparse_nfs_data_buffer and
move to common/smb2pdu.h

 fs/smb/client/cifsglob.h |  5 +----
 fs/smb/client/cifspdu.h  | 30 ------------------------------
 fs/smb/client/reparse.c  | 15 +++++++--------
 fs/smb/common/smb2pdu.h  | 14 +++++++++++++-
 4 files changed, 21 insertions(+), 43 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 cifs: Remove struct reparse_posix_data from struct cifs_open_info_data

Linux SMB client already supports more reparse point types but only the reparse_posix_data is defined in union of struct cifs_open_info_data. This union is currently used as implicit casting between point types.

With this code style, it hides information that union is used for pointer casting, and just in mknod_nfs() and posix_reparse_to_fattr() functions.

Other reparse point buffers do not use this kind of casting. So remove reparse_posix_data from reparse part of struct cifs_open_info_data and for all cases of reparse buffer use just struct reparse_data_buffer *buf.

---
 fs/smb/client/cifsglob.h | 5 +----
 fs/smb/client/reparse.c  | 5 ++---
 2 files changed, 3 insertions(+), 7 deletions(-)
fs/smb/client/cifsglob.h +1 -4
index b56fca6dd195..5045ead02c43 100644
@@ -262,10 +262,7 @@ struct cifs_open_info_data {
 			struct kvec iov;
 		} io;
 		__u32 tag;
-		union {
-			struct reparse_data_buffer *buf;
-			struct reparse_posix_data *posix;
-		};
+		struct reparse_data_buffer *buf;
 	} reparse;
 	struct {
 		__u8		eas[SMB2_WSL_MAX_QUERY_EA_RESP_SIZE];
fs/smb/client/reparse.c +2 -3
index f01214d6c5d4..40070e99fc8a 100644
@@ -486,7 +486,7 @@ static int mknod_nfs(unsigned int xid, struct inode *inode,
 
 	data = (struct cifs_open_info_data) {
 		.reparse_point = true,
-		.reparse = { .tag = IO_REPARSE_TAG_NFS, .posix = p, },
+		.reparse = { .tag = IO_REPARSE_TAG_NFS, .buf = (struct reparse_data_buffer *)p, },
 		.symlink_target = kstrdup(symname, GFP_KERNEL),
 	};
 
@@ -1165,8 +1165,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,
 				   struct cifs_fattr *fattr,
 				   struct cifs_open_info_data *data)
 {
-	struct reparse_posix_data *buf = data->reparse.posix;
-
+	struct reparse_posix_data *buf = (struct reparse_posix_data *)data->reparse.buf;
 
 	if (buf == NULL)
 		return true;
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/3 cifs: Remove duplicate struct reparse_symlink_data and SYMLINK_FLAG_RELATIVE

In reply to Pali Rohár

In file common/smb2pdu.h is defined struct reparse_symlink_data_buffer which is same as struct reparse_symlink_data and is used in the whole code. So remove duplicate struct reparse_symlink_data from client/cifspdu.h.

In file common/smb2pdu.h is defined also SYMLINK_FLAG_RELATIVE constant, so remove duplication from client/cifspdu.h.

---
 fs/smb/client/cifspdu.h | 16 ----------------
 1 file changed, 16 deletions(-)
fs/smb/client/cifspdu.h +0 -16
index d0e7fbc5cacd..2a29fa31c927 100644
@@ -1485,22 +1485,6 @@ struct file_notify_information {
 	__u8  FileName[];
 } __attribute__((packed));
 
-/* For IO_REPARSE_TAG_SYMLINK */
-struct reparse_symlink_data {
-	__le32	ReparseTag;
-	__le16	ReparseDataLength;
-	__u16	Reserved;
-	__le16	SubstituteNameOffset;
-	__le16	SubstituteNameLength;
-	__le16	PrintNameOffset;
-	__le16	PrintNameLength;
-	__le32	Flags;
-	char	PathBuffer[];
-} __attribute__((packed));
-
-/* Flag above */
-#define SYMLINK_FLAG_RELATIVE 0x00000001
-
 /* For IO_REPARSE_TAG_NFS */
 #define NFS_SPECFILE_LNK	0x00000000014B4E4C
 #define NFS_SPECFILE_CHR	0x0000000000524843
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/3 cifs: Rename struct reparse_posix_data to reparse_nfs_data_buffer and move to common/smb2pdu.h

In reply to Pali Rohár

Function parse_reparse_posix() parses NFS-style reparse points, which are used only by Windows NFS server since Windows Server 2012 version. This style is not understood by Microsoft POSIX/Interix/SFU/SUA subsystems.

So make it clear that parse_reparse_posix() function and reparse_posix_data structure are not POSIX general, but rather NFS specific.

All reparse buffer structures are defined in common/smb2pdu.h and have _buffer suffix. So move struct reparse_posix_data from client/cifspdu.h to common/smb2pdu.h and rename it to reparse_nfs_data_buffer for consistency. Note that also SMB specification in [MS-FSCC] document, section 2.1.2.6 defines it under name "Network File System (NFS) Reparse Data Buffer". So use this name for consistency.

Having this structure in common/smb2pdu.h can be useful for ksmbd server code as NFS-style reparse points is the preferred way for implementing support for special files.

---
 fs/smb/client/cifspdu.h | 14 --------------
 fs/smb/client/reparse.c | 12 ++++++------
 fs/smb/common/smb2pdu.h | 14 +++++++++++++-
 3 files changed, 19 insertions(+), 21 deletions(-)
fs/smb/client/cifspdu.h +0 -14
index 2a29fa31c927..f4c348b5c4f1 100644
@@ -1485,20 +1485,6 @@ struct file_notify_information {
 	__u8  FileName[];
 } __attribute__((packed));
 
-/* For IO_REPARSE_TAG_NFS */
-#define NFS_SPECFILE_LNK	0x00000000014B4E4C
-#define NFS_SPECFILE_CHR	0x0000000000524843
-#define NFS_SPECFILE_BLK	0x00000000004B4C42
-#define NFS_SPECFILE_FIFO	0x000000004F464946
-#define NFS_SPECFILE_SOCK	0x000000004B434F53
-struct reparse_posix_data {
-	__le32	ReparseTag;
-	__le16	ReparseDataLength;
-	__u16	Reserved;
-	__le64	InodeType; /* LNK, FIFO, CHR etc. */
-	__u8	DataBuffer[];
-} __attribute__((packed));
-
 struct cifs_quota_data {
 	__u32	rsrvd1;  /* 0 */
 	__u32	sid_size;
fs/smb/client/reparse.c +6 -6
index 40070e99fc8a..9fe9dd71a6fa 100644
@@ -407,7 +407,7 @@ static int create_native_socket(const unsigned int xid, struct inode *inode,
 	return rc;
 }
 
-static int nfs_set_reparse_buf(struct reparse_posix_data *buf,
+static int nfs_set_reparse_buf(struct reparse_nfs_data_buffer *buf,
 			       mode_t mode, dev_t dev,
 			       __le16 *symname_utf16,
 			       int symname_utf16_len,
@@ -454,7 +454,7 @@ static int mknod_nfs(unsigned int xid, struct inode *inode,
 {
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifs_open_info_data data;
-	struct reparse_posix_data *p = NULL;
+	struct reparse_nfs_data_buffer *p = NULL;
 	__le16 *symname_utf16 = NULL;
 	int symname_utf16_len = 0;
 	struct inode *new;
@@ -478,7 +478,7 @@ static int mknod_nfs(unsigned int xid, struct inode *inode,
 			goto out;
 		}
 	} else {
-		p = (struct reparse_posix_data *)buf;
+		p = (struct reparse_nfs_data_buffer *)buf;
 	}
 	rc = nfs_set_reparse_buf(p, mode, dev, symname_utf16, symname_utf16_len, &iov);
 	if (rc)
@@ -716,7 +716,7 @@ int smb2_mknod_reparse(unsigned int xid, struct inode *inode,
 }
 
 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
-static int parse_reparse_posix(struct reparse_posix_data *buf,
+static int parse_reparse_nfs(struct reparse_nfs_data_buffer *buf,
 			       struct cifs_sb_info *cifs_sb,
 			       struct cifs_open_info_data *data)
 {
@@ -1069,7 +1069,7 @@ int parse_reparse_point(struct reparse_data_buffer *buf,
 	/* See MS-FSCC 2.1.2 */
 	switch (le32_to_cpu(buf->ReparseTag)) {
 	case IO_REPARSE_TAG_NFS:
-		return parse_reparse_posix((struct reparse_posix_data *)buf,
+		return parse_reparse_nfs((struct reparse_nfs_data_buffer *)buf,
 					   cifs_sb, data);
 	case IO_REPARSE_TAG_SYMLINK:
 		return parse_reparse_native_symlink(
@@ -1165,7 +1165,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,
 				   struct cifs_fattr *fattr,
 				   struct cifs_open_info_data *data)
 {
-	struct reparse_posix_data *buf = (struct reparse_posix_data *)data->reparse.buf;
+	struct reparse_nfs_data_buffer *buf = (struct reparse_nfs_data_buffer *)data->reparse.buf;
 
 	if (buf == NULL)
 		return true;
fs/smb/common/smb2pdu.h +13 -1
index 3c7c706c797d..3336df2ea5d4 100644
@@ -1550,7 +1550,19 @@ struct reparse_symlink_data_buffer {
 	__u8	PathBuffer[]; /* Variable Length */
 } __packed;
 
-/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
+/* For IO_REPARSE_TAG_NFS - see MS-FSCC 2.1.2.6 */
+#define NFS_SPECFILE_LNK	0x00000000014B4E4C
+#define NFS_SPECFILE_CHR	0x0000000000524843
+#define NFS_SPECFILE_BLK	0x00000000004B4C42
+#define NFS_SPECFILE_FIFO	0x000000004F464946
+#define NFS_SPECFILE_SOCK	0x000000004B434F53
+struct reparse_nfs_data_buffer {
+	__le32	ReparseTag;
+	__le16	ReparseDataLength;
+	__u16	Reserved;
+	__le64	InodeType; /* NFS_SPECFILE_* */
+	__u8	DataBuffer[];
+} __packed;
 
 /* For IO_REPARSE_TAG_LX_SYMLINK */
 struct reparse_wsl_symlink_data_buffer {
Signature · 1 line
2.20.1
maintainer Reviewed-by on the v1 series
#4 lore raw
In reply to Pali Rohár
Quoted 4 lines · Pali Rohár

This patch series contains only code cleanup of few duplicates structures and enums between smb/common and smb/client subdirs. No function change.

Quoted 8 lines

Can be useful also for ksmbd server part.

Pali Rohár (3):
cifs: Remove struct reparse_posix_data from struct cifs_open_info_data
cifs: Remove duplicate struct reparse_symlink_data and
SYMLINK_FLAG_RELATIVE
cifs: Rename struct reparse_posix_data to reparse_nfs_data_buffer and
move to common/smb2pdu.h

Looks good to me:)

Thanks!

Quoted 10 lines
 fs/smb/client/cifsglob.h |  5 +----
 fs/smb/client/cifspdu.h  | 30 ------------------------------
 fs/smb/client/reparse.c  | 15 +++++++--------
 fs/smb/common/smb2pdu.h  | 14 +++++++++++++-
 4 files changed, 21 insertions(+), 43 deletions(-)

--
2.20.1