Skip to contentSkip to conversation

smb/server: implement compression fattr handler

PATCH Superseded [email protected] 3 participants 25 messages Jun 6 1 message not in the archive

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

cover smb/server: implement compression fattr handler

From: ChenXiaoSong <[email protected]>

ChenXiaoSong (5):
smb: move compression definitions into common/fscc.h smb/server: get compression file attribute on open smb/server: implement FSCTL_GET_COMPRESSION ioctl handler smb/server: implement FSCTL_SET_COMPRESSION ioctl handler
smb: remove duplicate server/smbfsctl.h

 fs/smb/client/smb1pdu.h  |   5 --
 fs/smb/client/smb2pdu.h  |   4 --
 fs/smb/common/fscc.h     |  18 ++++++
 fs/smb/common/smbfsctl.h |  10 +++-
 fs/smb/server/smb2pdu.c  |  73 +++++++++++++++++++++---
 fs/smb/server/smb2pdu.h  |   3 -
 fs/smb/server/smbfsctl.h |  91 ------------------------------
 fs/smb/server/vfs.c      | 116 +++++++++++++++++++++++++++++++++++++++
 fs/smb/server/vfs.h      |   3 +
 9 files changed, 211 insertions(+), 112 deletions(-)
 delete mode 100644 fs/smb/server/smbfsctl.h
Signature · 1 line
2.54.0
author reviewer
#1 lore raw

PATCH 1/5 smb: move compression definitions into common/fscc.h

From: ChenXiaoSong <[email protected]>

These definitions will also be used by ksmbd, move them into common header file.

---
 fs/smb/client/smb1pdu.h |  5 -----
 fs/smb/client/smb2pdu.h |  4 ----
 fs/smb/common/fscc.h    | 18 ++++++++++++++++++
 fs/smb/server/smb2pdu.h |  3 ---
 4 files changed, 18 insertions(+), 12 deletions(-)
fs/smb/client/smb1pdu.h +0 -5
index 7584e94d9b2b..0870949144ab 100644
@@ -1211,11 +1211,6 @@ typedef struct smb_com_transaction_compr_ioctl_req {
 	__le16 compression_state;  /* See below for valid flags */
 } __packed TRANSACT_COMPR_IOCTL_REQ;
 
-/* compression state flags */
-#define COMPRESSION_FORMAT_NONE		0x0000
-#define COMPRESSION_FORMAT_DEFAULT	0x0001
-#define COMPRESSION_FORMAT_LZNT1	0x0002
-
 typedef struct smb_com_transaction_ioctl_rsp {
 	struct smb_hdr hdr;	/* wct = 19 */
 	__u8 Reserved[3];
fs/smb/client/smb2pdu.h +0 -4
index 30d70097fe2f..b9bf2fa989d5 100644
@@ -195,10 +195,6 @@ struct network_resiliency_req {
 
 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
 
-struct compress_ioctl {
-	__le16 CompressionState; /* See cifspdu.h for possible flag values */
-} __packed;
-
 /*
  * Maximum number of iovs we need for an ioctl request.
  * [0] : struct smb2_ioctl_req
fs/smb/common/fscc.h +18 -0
index bc3012cc295d..7e68de834e8b 100644
@@ -100,6 +100,24 @@ struct duplicate_extents_to_file_ex {
 	__le32 Reserved;
 } __packed;
 
+/*
+ * compression state flags
+ * See MS-FSCC 2.3.18
+ *     MS-FSCC 2.3.67
+ *     MS-FSCC 2.4.9
+ */
+#define COMPRESSION_FORMAT_NONE		0x0000
+#define COMPRESSION_FORMAT_DEFAULT	0x0001
+#define COMPRESSION_FORMAT_LZNT1	0x0002
+
+/*
+ * See MS-FSCC 2.3.18
+ *     MS-FSCC 2.3.67
+ */
+struct compress_ioctl {
+	__le16 CompressionState;
+} __packed;
+
 /* See MS-FSCC 2.3.20 */
 struct fsctl_get_integrity_information_rsp {
 	__le16	ChecksumAlgorithm;
fs/smb/server/smb2pdu.h +0 -3
index e7cf573e59f0..3bed676bb5ad 100644
@@ -230,9 +230,6 @@ struct smb2_file_mode_info {
 	__le32 Mode;
 } __packed;
 
-#define COMPRESSION_FORMAT_NONE 0x0000
-#define COMPRESSION_FORMAT_LZNT1 0x0002
-
 struct smb2_file_comp_info {
 	__le64 CompressedFileSize;
 	__le16 CompressionFormat;
Signature · 1 line
2.54.0
maintainer
#2 lore raw

Re: [PATCH 1/5] smb: move compression definitions into common/fscc.h

Hi ChenXiaoSong,

fs/smb/client/smb1pdu.h typedef struct smb_com_transaction_compr_ioctl_req { · line 1216

Quoted 4 lines
fs/smb/client/smb1pdu.h +0 -3
-/* compression state flags */
-#define COMPRESSION_FORMAT_NONE                0x0000
-#define COMPRESSION_FORMAT_DEFAULT     0x0001

Where is COMPRESSION_FORMAT_DEFAULT defined in the specifications? I looked through MS-FSCC but couldn't find it...

Quoted 1 line

-#define COMPRESSION_FORMAT_LZNT1 0x0002

author reviewer
#5 lore raw

Re: [PATCH 1/5] smb: move compression definitions into common/fscc.h

According to MS-FSCC 2.3.67: The actual file or directory compression performed when a server receives a request for COMPRESSION_FORMAT_DEFAULT and COMPRESSION_FORMAT_LZNT1 is implementation-dependent.

So my understanding is that DEFAULT and LZNT1 are equivalent. If so, we only need to use one of the two values, right?

Quoted 6 lines · Namjae Jeon
Quoted 3 lines · ChenXiaoSong

Please see MS-FSCC 2.3.67:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/77f650a3-e3a2-4a25-baac-4bf9b36bcc46

What does COMPRESSION_FORMAT_DEFAULT mean? default?

reviewer
#6 lore raw

Re: [PATCH 1/5] smb: move compression definitions into common/fscc.h

In reply to Namjae Jeon
Quoted 7 lines · Namjae Jeon
Quoted 3 lines · ChenXiaoSong

Please see MS-FSCC 2.3.67:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/77f650a3-e3a2-4a25-baac-4bf9b36bcc46

What does COMPRESSION_FORMAT_DEFAULT mean? default?

It's a behavior (choice), and the Windows Behavior note states what Windows implements. Per the WBN link in the quoted fragment:

<62> Section 2.3.67: Equivalent to COMPRESSION_FORMAT_LZNT1.

Tom.

author reviewer
#7 lore raw

Re: [PATCH 1/5] smb: move compression definitions into common/fscc.h

Hi Tom,

I'm only using DEFAULT for now,it seems reasonable,right?

Quoted 4 lines · Tom Talpey

It's a behavior (choice), and the Windows Behavior note states what Windows implements. Per the WBN link in the quoted fragment:

  <62> Section 2.3.67: Equivalent to COMPRESSION_FORMAT_LZNT1.

author reviewer
#8 lore raw

PATCH 2/5 smb/server: get compression file attribute on open

In reply to [email protected]

From: ChenXiaoSong <[email protected]>

Example:

1. server: chattr +c /export/file
2. client: lsattr /mnt/file

             --------c------------- /mnt/file
---
 fs/smb/server/smb2pdu.c |  5 ++++-
 fs/smb/server/vfs.c     | 20 ++++++++++++++++++++
 fs/smb/server/vfs.h     |  1 +
 3 files changed, 25 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +4 -1
index 3eb3b1711acb..707ad8d17b62 100644
@@ -3603,7 +3603,10 @@ int smb2_open(struct ksmbd_work *work)
 
 	if (!created)
 		smb2_update_xattrs(tcon, &path, fp);
-	else
+
+	ksmbd_vfs_update_compressed_fattr(path.dentry, &fp->f_ci->m_fattr);
+
+	if (created)
 		smb2_new_xattrs(tcon, &path, fp);
 
 	memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
fs/smb/server/vfs.c +20 -0
index d08973b288e5..08490a7fb396 100644
@@ -21,6 +21,7 @@
 #include <linux/crc32c.h>
 #include <linux/namei.h>
 #include <linux/splice.h>
+#include <linux/fileattr.h>
 
 #include "glob.h"
 #include "oplock.h"
@@ -1890,3 +1891,22 @@ int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap,
 	posix_acl_release(acls);
 	return rc;
 }
+
+void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr)
+{
+	int rc;
+	struct file_kattr fa = { .flags_valid = true };
+
+	rc = vfs_fileattr_get(dentry, &fa);
+	if (rc == -ENOIOCTLCMD) {
+		*fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
+		return;
+	}
+	if (rc)
+		return;
+
+	if (fa.flags & FS_COMPR_FL)
+		*fattr |= FILE_ATTRIBUTE_COMPRESSED_LE;
+	else
+		*fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
+}
fs/smb/server/vfs.h +1 -0
index 16ca29ee16e5..ac6dda173b75 100644
@@ -168,4 +168,5 @@ int ksmbd_vfs_set_init_posix_acl(struct mnt_idmap *idmap,
 int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap,
 				const struct path *path,
 				struct inode *parent_inode);
+void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr);
 #endif /* __KSMBD_VFS_H__ */
Signature · 1 line
2.54.0
maintainer
#9 lore raw

Re: [PATCH 2/5] smb/server: get compression file attribute on open

fs/smb/server/vfs.c int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap, · line 1903

Quoted 9 lines
fs/smb/server/vfs.c +9 -0
+void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr)
+{
+       int rc;
+       struct file_kattr fa = { .flags_valid = true };
+
+       rc = vfs_fileattr_get(dentry, &fa);
+       if (rc == -ENOIOCTLCMD) {
+               *fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
+               return;

Please remove unneeded return here.

Quoted 9 lines
fs/smb/server/vfs.c +9 -0
+       }
+       if (rc)
+               return;
+
+       if (fa.flags & FS_COMPR_FL)
+               *fattr |= FILE_ATTRIBUTE_COMPRESSED_LE;
+       else
+               *fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
+}
author reviewer
#10 lore raw

Re: [PATCH 2/5] smb/server: get compression file attribute on open

Yes, I will remove it in next version.

Quoted 4 lines · Namjae Jeon

fs/smb/server/vfs.c int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap, · line 1903

Quoted 3 lines
fs/smb/server/vfs.c +3 -0
+       if (rc == -ENOIOCTLCMD) {
+               *fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
+               return;

Please remove unneeded return here.

author reviewer
#11 lore raw

PATCH 3/5 smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

In reply to [email protected]

From: ChenXiaoSong <[email protected]>

Example:

1. server: chattr +c /export/file
2. client: smbinfo getcompression /mnt/file
Compression: 1 (UNKNOWN)

---
 fs/smb/server/smb2pdu.c | 28 ++++++++++++++++++++++++++++
 fs/smb/server/vfs.c     | 23 +++++++++++++++++++++++
 fs/smb/server/vfs.h     |  1 +
 3 files changed, 52 insertions(+)
fs/smb/server/smb2pdu.c +28 -0
index 707ad8d17b62..aeede3f11e06 100644
@@ -8338,6 +8338,34 @@ int smb2_ioctl(struct ksmbd_work *work)
 		ret = -EOPNOTSUPP;
 		rsp->hdr.Status = STATUS_FS_DRIVER_REQUIRED;
 		goto out2;
+	case FSCTL_GET_COMPRESSION: {
+		struct compress_ioctl *cmpr_rsp;
+		struct ksmbd_file *fp;
+		u16 fmt;
+
+		if (out_buf_len < sizeof(struct compress_ioctl)) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		fp = ksmbd_lookup_fd_fast(work, id);
+		if (!fp) {
+			ret = -ENOENT;
+			goto out;
+		}
+
+		ret = ksmbd_vfs_get_compression(fp, &fmt);
+		ksmbd_fd_put(work, fp);
+		if (ret < 0)
+			goto out;
+
+		cmpr_rsp = (struct compress_ioctl *)&rsp->Buffer[0];
+		cmpr_rsp->CompressionState = cpu_to_le16(fmt);
+		nbytes = sizeof(struct compress_ioctl);
+		rsp->PersistentFileId = req->PersistentFileId;
+		rsp->VolatileFileId = req->VolatileFileId;
+		break;
+	}
 	case FSCTL_CREATE_OR_GET_OBJECT_ID:
 	{
 		struct file_object_buf_type1_ioctl_rsp *obj_buf;
fs/smb/server/vfs.c +23 -0
index 08490a7fb396..fc29df32330b 100644
@@ -1910,3 +1910,26 @@ void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr)
 	else
 		*fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
 }
+
+int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt)
+{
+	struct file_kattr fa = { .flags_valid = true };
+	int rc;
+
+	rc = vfs_fileattr_get(fp->filp->f_path.dentry, &fa);
+	if (rc == -ENOIOCTLCMD) {
+		*fmt = COMPRESSION_FORMAT_NONE;
+		rc = 0;
+		goto out;
+	}
+	if (rc)
+		goto out;
+
+	if (fa.flags & FS_COMPR_FL)
+		*fmt = COMPRESSION_FORMAT_DEFAULT;
+	else
+		*fmt = COMPRESSION_FORMAT_NONE;
+
+out:
+	return rc;
+}
fs/smb/server/vfs.h +1 -0
index ac6dda173b75..f6121207dbda 100644
@@ -169,4 +169,5 @@ int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap,
 				const struct path *path,
 				struct inode *parent_inode);
 void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr);
+int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt);
 #endif /* __KSMBD_VFS_H__ */
Signature · 1 line
2.54.0
maintainer
#12 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

Quoted 6 lines
fs/smb/server/vfs.c +6 -0
+int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt)
+{
+       struct file_kattr fa = { .flags_valid = true };
+       int rc;
+
+       rc = vfs_fileattr_get(fp->filp->f_path.dentry, &fa);

fs/smb/server/vfs.c void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr) · line 1929

Quoted 10 lines
fs/smb/server/vfs.c +10 -0
+       if (rc == -ENOIOCTLCMD) {
+               *fmt = COMPRESSION_FORMAT_NONE;
+               rc = 0;
+               goto out;
+       }
+       if (rc)
+               goto out;
+
+       if (fa.flags & FS_COMPR_FL)
+               *fmt = COMPRESSION_FORMAT_DEFAULT;

Again.. The definition of COMPRESSION_FORMAT_DEFAULT doesn't seem to exist in the spec. How do other smb clients behave when they receive this response?

Quoted 6 lines
fs/smb/server/vfs.c +6 -0
+       else
+               *fmt = COMPRESSION_FORMAT_NONE;
+
+out:
+       return rc;
+}
author reviewer
#13 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

It is defined in MS-FSCC 2.3.67: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/77f650a3-e3a2-4a25-baac-4bf9b36bcc46

There's one thing I'm not sure about, vfs_fileattr_get() seems to only tell us whether the file is compressed or not, but it doesn't provide the detailed CompressionState. Namjae, do you have a better idea for how to get detailed CompressionState?

Quoted 5 lines · Namjae Jeon

fs/smb/server/vfs.c void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr) · line 1929

Quoted 2 lines
fs/smb/server/vfs.c +2 -0
+       if (fa.flags & FS_COMPR_FL)
+               *fmt = COMPRESSION_FORMAT_DEFAULT;

Again.. The definition of COMPRESSION_FORMAT_DEFAULT doesn't seem to exist in the spec. How do other smb clients behave when they receive this response?

maintainer
#14 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

Quoted 8 lines · ChenXiaoSong

It is defined in MS-FSCC 2.3.67:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/77f650a3-e3a2-4a25-baac-4bf9b36bcc46

There's one thing I'm not sure about, vfs_fileattr_get() seems to only tell us whether the file is compressed or not, but it doesn't provide the detailed CompressionState. Namjae, do you have a better idea for how to get detailed CompressionState?

It seems possible to get the file's compression algorithm format or information via ioctl in f2fs and other filesystems. However, COMPRESSION_FORMAT_DEFAULT is not defined in FSCTL_GET_COMPRESSION. Isn't that why it showed up as UNKNOWN in your test results?

2. client: smbinfo getcompression /mnt/file Compression: 1 (UNKNOWN)

My thought is that if the file is compressed, it might be better to return COMPRESSION_FORMAT_LZNT1 even though it is not actually compressed with LZNT1. Of course, we need to test this with a Windows client. This is because I think FSCTL_GET_COMPRESSION is simply a request to check whether the file is in a compressed state or not.

author reviewer
#15 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

I will update it to use LZNT1. Thanks for your suggestion.

Quoted 12 lines · Namjae Jeon

It seems possible to get the file's compression algorithm format or information via ioctl in f2fs and other filesystems. However, COMPRESSION_FORMAT_DEFAULT is not defined in FSCTL_GET_COMPRESSION. Isn't that why it showed up as UNKNOWN in your test results?

2. client: smbinfo getcompression /mnt/file Compression: 1 (UNKNOWN)

My thought is that if the file is compressed, it might be better to return COMPRESSION_FORMAT_LZNT1 even though it is not actually compressed with LZNT1. Of course, we need to test this with a Windows client. This is because I think FSCTL_GET_COMPRESSION is simply a request to check whether the file is in a compressed state or not.

reviewer
#16 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

Quoted 1 line · ChenXiaoSong

I will update it to use LZNT1. Thanks for your suggestion.

This thread has forked badly. See my other reply.

Bottom line - servers must never send DEFAULT. Clients may choose to.

Tom.

Quoted 16 lines · Namjae Jeon
Quoted 12 lines

It seems possible to get the file's compression algorithm format or information via ioctl in f2fs and other filesystems. However, COMPRESSION_FORMAT_DEFAULT is not defined in FSCTL_GET_COMPRESSION. Isn't that why it showed up as UNKNOWN in your test results?

2. client: smbinfo getcompression /mnt/file Compression: 1 (UNKNOWN)

My thought is that if the file is compressed, it might be better to return COMPRESSION_FORMAT_LZNT1 even though it is not actually compressed with LZNT1. Of course, we need to test this with a Windows client. This is because I think FSCTL_GET_COMPRESSION is simply a request to check whether the file is in a compressed state or not.

author reviewer
#17 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

I understand now. Thank you very much for your detailed explanation.

Quoted 4 lines · Tom Talpey

This thread has forked badly. See my other reply.

Bottom line - servers must never send DEFAULT. Clients may choose to.

A message that is not in the archive (sent off-list or not yet received): CAH2r5mtmggcLnkBrFOX-ob4KC=v8LmfOGfmzH0X-WR5nxNTceQ@mail.gmail.com

maintainer
#19 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

Quoted 2 lines · Steve French

It is defined in current ms-fscc

See:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/62de177d-ed90-4884-ae04-9de52f1180f1

It is defined in the FSCTL_SET_COMPRESSION request but not in the FSCTL_GET_COMPRESSION response. This patch is for FSCTL_GET_COMPRESSION. I'm not sure if it's a specification error or if it's intentional.

Quoted 32 lines

Thanks,

Steve

Quoted 26 lines · Namjae Jeon
Quoted 7 lines
fs/smb/server/vfs.c +6 -0
+int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt)
+{
+       struct file_kattr fa = { .flags_valid = true };
+       int rc;
+
+       rc = vfs_fileattr_get(fp->filp->f_path.dentry, &fa);

fs/smb/server/vfs.c void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr) · line 1929

Quoted 10 lines
fs/smb/server/vfs.c +10 -0
+       if (rc == -ENOIOCTLCMD) {
+               *fmt = COMPRESSION_FORMAT_NONE;
+               rc = 0;
+               goto out;
+       }
+       if (rc)
+               goto out;
+
+       if (fa.flags & FS_COMPR_FL)
+               *fmt = COMPRESSION_FORMAT_DEFAULT;

Again.. The definition of COMPRESSION_FORMAT_DEFAULT doesn't seem to exist in the spec. How do other smb clients behave when they receive this response?

Quoted 6 lines
fs/smb/server/vfs.c +6 -0
+       else
+               *fmt = COMPRESSION_FORMAT_NONE;
+
+out:
+       return rc;
+}
author reviewer
#20 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

It's more likely a specification error (an omission).

Quoted 7 lines · Namjae Jeon

See:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms- fscc/62de177d-ed90-4884-ae04-9de52f1180f1

It is defined in the FSCTL_SET_COMPRESSION request but not in the FSCTL_GET_COMPRESSION response. This patch is for FSCTL_GET_COMPRESSION. I'm not sure if it's a specification error or if it's intentional.

reviewer
#21 lore raw

Re: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler

Quoted 10 lines · ChenXiaoSong

It's more likely a specification error (an omission).

Quoted 7 lines · Namjae Jeon

See:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms- fscc/62de177d-ed90-4884-ae04-9de52f1180f1

It is defined in the FSCTL_SET_COMPRESSION request but not in the FSCTL_GET_COMPRESSION response. This patch is for FSCTL_GET_COMPRESSION. I'm not sure if it's a specification error or if it's intentional.

Not at all - it's intentional on both counts. In a request, it signals that the client doesn't request any specific algorithm and will decompress whatever the server chooses. Remember, the possible algorithms are already known.

In a response, it can't be unspecified (default). So it's never returned. The server basically translates DEFAULT to what it actually used.

Ok, pedantic specification language aside, there is only one compression algorithm defined. But the server needs to inspect a request for DEFAULT so the code in ksmbd needs the token in the common header file to perform this check.

Tom.

author reviewer
#22 lore raw

PATCH 4/5 smb/server: implement FSCTL_SET_COMPRESSION ioctl handler

In reply to [email protected]

From: ChenXiaoSong <[email protected]>

Example:
1. client: smbinfo setcompression no /mnt/file
2. client: smbinfo getcompression /mnt/file
Compression: 0 (NONE)
3. client: smbinfo setcompression default /mnt/file
4. client: smbinfo getcompression /mnt/file
Compression: 1 (UNKNOWN)

---
 fs/smb/server/smb2pdu.c | 28 ++++++++++++++++
 fs/smb/server/vfs.c     | 73 +++++++++++++++++++++++++++++++++++++++++
 fs/smb/server/vfs.h     |  1 +
 3 files changed, 102 insertions(+)
fs/smb/server/smb2pdu.c +28 -0
index aeede3f11e06..8c40631ce64a 100644
@@ -8366,6 +8366,34 @@ int smb2_ioctl(struct ksmbd_work *work)
 		rsp->VolatileFileId = req->VolatileFileId;
 		break;
 	}
+	case FSCTL_SET_COMPRESSION: {
+		struct compress_ioctl *cmpr_req;
+		struct ksmbd_file *fp;
+
+		if (in_buf_len < sizeof(struct compress_ioctl)) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
+			ksmbd_debug(SMB, "User does not have write permission\n");
+			ret = -EACCES;
+			goto out;
+		}
+
+		cmpr_req = (struct compress_ioctl *)buffer;
+		fp = ksmbd_lookup_fd_fast(work, id);
+		if (!fp) {
+			ret = -ENOENT;
+			goto out;
+		}
+
+		ret = ksmbd_vfs_set_compression(work, fp, le16_to_cpu(cmpr_req->CompressionState));
+		ksmbd_fd_put(work, fp);
+		if (ret)
+			goto out;
+		break;
+	}
 	case FSCTL_CREATE_OR_GET_OBJECT_ID:
 	{
 		struct file_object_buf_type1_ioctl_rsp *obj_buf;
fs/smb/server/vfs.c +73 -0

76 lines not on this page · raw message

fs/smb/server/vfs.h +1 -0
index f6121207dbda..7b3d2f4fd985 100644
@@ -170,4 +170,5 @@ int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap,
 				struct inode *parent_inode);
 void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr);
 int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt);
+int ksmbd_vfs_set_compression(struct ksmbd_work *work, struct ksmbd_file *fp, u16 fmt);
 #endif /* __KSMBD_VFS_H__ */
Signature · 1 line
2.54.0
maintainer
#23 lore raw

Re: [PATCH 4/5] smb/server: implement FSCTL_SET_COMPRESSION ioctl handler

Quoted 55 lines
fs/smb/server/vfs.c +55 -0
+int ksmbd_vfs_set_compression(struct ksmbd_work *work, struct ksmbd_file *fp, u16 fmt)
+{
+       struct file_kattr fa;
+       struct dentry *dentry = fp->filp->f_path.dentry;
+       struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
+       u32 flags;
+       __le32 old_fattr;
+       int rc;
+
+       if (!(fp->daccess & FILE_WRITE_DATA_LE)) {
+               rc = -EACCES;
+               goto out;
+       }
+
+       rc = vfs_fileattr_get(dentry, &fa);
+       if (rc)
+               goto out;
+
+       flags = fa.flags;
+       if (fmt == COMPRESSION_FORMAT_NONE) {
+               flags &= ~FS_COMPR_FL;
+       } else if (fmt == COMPRESSION_FORMAT_DEFAULT ||
+                  fmt == COMPRESSION_FORMAT_LZNT1) {
+               flags |= FS_COMPR_FL;
+       } else {
+               rc = -EINVAL;
+               goto out;
+       }
+
+       if (flags != fa.flags) {
+               fileattr_fill_flags(&fa, flags);
+               rc = mnt_want_write_file(fp->filp);
+               if (rc)
+                       goto out;
+
+               rc = vfs_fileattr_set(idmap, dentry, &fa);
+               mnt_drop_write_file(fp->filp);
+               if (rc)
+                       goto out;
+       }
+
+       old_fattr = fp->f_ci->m_fattr;
+       if (fmt == COMPRESSION_FORMAT_NONE)
+               fp->f_ci->m_fattr &= ~FILE_ATTRIBUTE_COMPRESSED_LE;
+       else
+               fp->f_ci->m_fattr |= FILE_ATTRIBUTE_COMPRESSED_LE;
+
+       if (fp->f_ci->m_fattr != old_fattr &&
+           test_share_config_flag(work->tcon->share_conf,
+                                  KSMBD_SHARE_FLAG_STORE_DOS_ATTRS)) {
+               struct xattr_dos_attrib da;
+
+               rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, dentry, &da);
+               if (rc <= 0) {
+                       rc = 0;

fs/smb/server/vfs.c int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt) · line 2001

Quoted 10 lines
fs/smb/server/vfs.c +10 -0
+                       goto out;
+               }
+
+               da.attr = le32_to_cpu(fp->f_ci->m_fattr);
+               rc = ksmbd_vfs_set_dos_attrib_xattr(idmap,
+                                                   &fp->filp->f_path,
+                                                   &da, true);
+               if (rc) {
+                       rc = 0;
+                       fp->f_ci->m_fattr = old_fattr;

If ksmbd_vfs_set_dos_attrib_xattr() fails after vfs_fileattr_set() succeeds, you only roll back fp->f_ci->m_fattr and return 0. This leaves the actual filesystem with the FS_COMPR_FL flag enabled, while ksmbd's attribute treats it as uncompressed. If the xattr update fails, we should either properly roll back the filesystem flag as well or don't roll back fp->f_ci->m_fattr. I prefer the latter.

Quoted 1 line

+ goto out;

And no need goto here.

Quoted 6 lines
fs/smb/server/vfs.c +6 -0
+               }
+       }
+
+out:
+       return rc;
+}
author reviewer
#24 lore raw

Re: [PATCH 4/5] smb/server: implement FSCTL_SET_COMPRESSION ioctl handler

Yes, thanks for your suggestion. We shouldn't roll back fp->f_ci->m_fattr here.

Quoted 3 lines · Namjae Jeon

If the xattr update
fails, we should either properly roll back the filesystem flag as well or don't roll back fp->f_ci->m_fattr. I prefer the latter.

author reviewer
#25 lore raw

PATCH 5/5 smb: remove duplicate server/smbfsctl.h

In reply to [email protected]

From: ChenXiaoSong <[email protected]>

Rename the following places:

- FSCTL_COPYCHUNK -> FSCTL_SRV_COPYCHUNK
- FSCTL_COPYCHUNK_WRITE -> FSCTL_SRV_COPYCHUNK_WRITE
- FSCTL_REQUEST_RESUME_KEY -> FSCTL_SRV_REQUEST_RESUME_KEY

server/smbfsctl.h contains the following additional definitions compared to common/smbfsctl.h:

- IO_REPARSE_TAG_LX_SYMLINK_LE
- IO_REPARSE_TAG_AF_UNIX_LE
- IO_REPARSE_TAG_LX_FIFO_LE
- IO_REPARSE_TAG_LX_CHR_LE
- IO_REPARSE_TAG_LX_BLK_LE

---
 fs/smb/common/smbfsctl.h | 10 ++++-
 fs/smb/server/smb2pdu.c  | 12 +++---
 fs/smb/server/smbfsctl.h | 91 ----------------------------------------
 3 files changed, 14 insertions(+), 99 deletions(-)
 delete mode 100644 fs/smb/server/smbfsctl.h
fs/smb/common/smbfsctl.h +8 -2
index 3253a18ecb5c..d1fcb46a7cde 100644
@@ -61,8 +61,8 @@
 #define FSCTL_LOCK_VOLUME            0x00090018
 #define FSCTL_UNLOCK_VOLUME          0x0009001C
 #define FSCTL_IS_PATHNAME_VALID      0x0009002C /* BB add struct */
-#define FSCTL_GET_COMPRESSION        0x0009003C /* BB add struct */
-#define FSCTL_SET_COMPRESSION        0x0009C040 /* BB add struct */
+#define FSCTL_GET_COMPRESSION        0x0009003C
+#define FSCTL_SET_COMPRESSION        0x0009C040
 #define FSCTL_QUERY_FAT_BPB          0x00090058 /* BB add struct */
 /* Verify the next FSCTL number, we had it as 0x00090090 before */
 #define FSCTL_FILESYSTEM_GET_STATS   0x00090060 /* BB add struct */
@@ -159,6 +159,12 @@
 #define IO_REPARSE_TAG_LX_CHR	     0x80000025
 #define IO_REPARSE_TAG_LX_BLK	     0x80000026
 
+#define IO_REPARSE_TAG_LX_SYMLINK_LE   cpu_to_le32(IO_REPARSE_TAG_LX_SYMLINK)
+#define IO_REPARSE_TAG_AF_UNIX_LE      cpu_to_le32(IO_REPARSE_TAG_AF_UNIX)
+#define IO_REPARSE_TAG_LX_FIFO_LE      cpu_to_le32(IO_REPARSE_TAG_LX_FIFO)
+#define IO_REPARSE_TAG_LX_CHR_LE       cpu_to_le32(IO_REPARSE_TAG_LX_CHR)
+#define IO_REPARSE_TAG_LX_BLK_LE       cpu_to_le32(IO_REPARSE_TAG_LX_BLK)
+
 /* If Name Surrogate Bit is set, the file or directory represents another named entity in the system. */
 #define IS_REPARSE_TAG_NAME_SURROGATE(tag) (!!((tag) & 0x20000000))
 
fs/smb/server/smb2pdu.c +6 -6
index 8c40631ce64a..140b3a878673 100644
@@ -16,7 +16,7 @@
 #include <linux/filelock.h>
 
 #include "glob.h"
-#include "smbfsctl.h"
+#include "../common/smbfsctl.h"
 #include "oplock.h"
 #include "smbacl.h"
 
@@ -7919,9 +7919,9 @@ static int fsctl_copychunk(struct ksmbd_work *work,
 
 	/*
 	 * FILE_READ_DATA should only be included in
-	 * the FSCTL_COPYCHUNK case
+	 * the FSCTL_SRV_COPYCHUNK case
 	 */
-	if (cnt_code == FSCTL_COPYCHUNK &&
+	if (cnt_code == FSCTL_SRV_COPYCHUNK &&
 	    !(dst_fp->daccess & (FILE_READ_DATA_LE | FILE_GENERIC_READ_LE))) {
 		rsp->hdr.Status = STATUS_ACCESS_DENIED;
 		goto out;
@@ -8451,7 +8451,7 @@ int smb2_ioctl(struct ksmbd_work *work)
 			goto out;
 		nbytes = ret;
 		break;
-	case FSCTL_REQUEST_RESUME_KEY:
+	case FSCTL_SRV_REQUEST_RESUME_KEY:
 		if (out_buf_len < sizeof(struct resume_key_ioctl_rsp)) {
 			ret = -EINVAL;
 			goto out;
@@ -8465,8 +8465,8 @@ int smb2_ioctl(struct ksmbd_work *work)
 		rsp->VolatileFileId = req->VolatileFileId;
 		nbytes = sizeof(struct resume_key_ioctl_rsp);
 		break;
-	case FSCTL_COPYCHUNK:
-	case FSCTL_COPYCHUNK_WRITE:
+	case FSCTL_SRV_COPYCHUNK:
+	case FSCTL_SRV_COPYCHUNK_WRITE:
 		if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
 			ksmbd_debug(SMB,
 				    "User does not have write permission\n");
fs/smb/server/smbfsctl.h deleted +0 -91

91 lines not on this page · raw message

Signature · 1 line
2.54.0