Skip to contentSkip to conversation

smb/server: implement compression fattr handler

PATCH Applied [email protected] 2 participants 12 messages Jun 8 – Jun 9

Subsystems (2)

v3 of 4 Applied Latest is v4 →

lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

v3 cover smb/server: implement compression fattr handler

From: ChenXiaoSong <[email protected]>

v2->v3:
- Add patch #06 #07: get correct compression format and file size in get_file_compression_info()

v2: https://lore.kernel.org/linux-cifs/[email protected]/

ChenXiaoSong (7):
smb: remove duplicate server/smbfsctl.h
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/server: get compression format in get_file_compression_info() smb/server: fix incorrect file size in get_file_compression_info()

 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  |  82 +++++++++++++++++++++++++----
 fs/smb/server/smb2pdu.h  |   3 --
 fs/smb/server/smbfsctl.h |  91 --------------------------------
 fs/smb/server/vfs.c      | 111 +++++++++++++++++++++++++++++++++++++++
 fs/smb/server/vfs.h      |   3 ++
 9 files changed, 213 insertions(+), 114 deletions(-)
 delete mode 100644 fs/smb/server/smbfsctl.h
Signature · 1 line
2.54.0
author reviewer
#1 lore raw

PATCH v3 1/7 smb: remove duplicate server/smbfsctl.h

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 |  6 +++
 fs/smb/server/smb2pdu.c  | 12 +++---
 fs/smb/server/smbfsctl.h | 91 ----------------------------------------
 3 files changed, 12 insertions(+), 97 deletions(-)
 delete mode 100644 fs/smb/server/smbfsctl.h
fs/smb/common/smbfsctl.h +6 -0
index 3253a18ecb5c..74e78bcb4618 100644
@@ -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 a97fc9b7e44c..8bf418e2da1c 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"
 
@@ -7914,9 +7914,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;
@@ -8390,7 +8390,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;
@@ -8404,8 +8404,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
author reviewer
#2 lore raw

PATCH v3 2/7 smb: move compression definitions into common/fscc.h

In reply to [email protected]

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
author reviewer
#3 lore raw

PATCH v3 3/7 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     | 18 ++++++++++++++++++
 fs/smb/server/vfs.h     |  1 +
 3 files changed, 23 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +4 -1
index 8bf418e2da1c..30c67f1c5109 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 +18 -0
index e020e59d1d5d..6dee609e9749 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,20 @@ 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;
+	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
author reviewer
#4 lore raw

PATCH v3 4/7 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: 2 (LZNT1)

---
 fs/smb/common/smbfsctl.h |  2 +-
 fs/smb/server/smb2pdu.c  | 28 ++++++++++++++++++++++++++++
 fs/smb/server/vfs.c      | 23 +++++++++++++++++++++++
 fs/smb/server/vfs.h      |  1 +
 4 files changed, 53 insertions(+), 1 deletion(-)
fs/smb/common/smbfsctl.h +1 -1
index 74e78bcb4618..9debdd709d1c 100644
@@ -61,7 +61,7 @@
 #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_GET_COMPRESSION        0x0009003C
 #define FSCTL_SET_COMPRESSION        0x0009C040 /* BB add struct */
 #define FSCTL_QUERY_FAT_BPB          0x00090058 /* BB add struct */
 /* Verify the next FSCTL number, we had it as 0x00090090 before */
fs/smb/server/smb2pdu.c +28 -0
index 30c67f1c5109..7cc63678e2e0 100644
@@ -8336,6 +8336,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 6dee609e9749..b8c3ba43452a 100644
@@ -1908,3 +1908,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_LZNT1;
+	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
author reviewer
#5 lore raw

PATCH v3 5/7 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 lznt1 /mnt/file
4. client: smbinfo getcompression /mnt/file
Compression: 2 (LZNT1)
5. client: smbinfo setcompression default /mnt/file
6. client: smbinfo getcompression /mnt/file
Compression: 2 (LZNT1)

---
 fs/smb/common/smbfsctl.h |  2 +-
 fs/smb/server/smb2pdu.c  | 28 ++++++++++++++++
 fs/smb/server/vfs.c      | 70 ++++++++++++++++++++++++++++++++++++++++
 fs/smb/server/vfs.h      |  1 +
 4 files changed, 100 insertions(+), 1 deletion(-)
fs/smb/common/smbfsctl.h +1 -1
index 9debdd709d1c..d1fcb46a7cde 100644
@@ -62,7 +62,7 @@
 #define FSCTL_UNLOCK_VOLUME          0x0009001C
 #define FSCTL_IS_PATHNAME_VALID      0x0009002C /* BB add struct */
 #define FSCTL_GET_COMPRESSION        0x0009003C
-#define FSCTL_SET_COMPRESSION        0x0009C040 /* BB add struct */
+#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 */
fs/smb/server/smb2pdu.c +28 -0
index 7cc63678e2e0..2b67c5926c67 100644
@@ -8364,6 +8364,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 +70 -0

73 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
author reviewer
#6 lore raw

PATCH v3 6/7 smb/server: get compression format in get_file_compression_info()

In reply to [email protected]

From: ChenXiaoSong <[email protected]>

I have added filecompressioninfo subcommand to smbinfo in cifs-utils.git.

Example:

1. client: smbinfo setcompression lznt1 /mnt/file
2. client: smbinfo filecompressioninfo /mnt/file Compressed File Size: 104857600 Compression Format: 2 (LZNT1) Compression Unit Shift: 0 Chunk Shift: 0
Cluster Shift: 0

---
 fs/smb/server/smb2pdu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +6 -1
index 2b67c5926c67..7150e77ff113 100644
@@ -5278,6 +5278,7 @@ static int get_file_compression_info(struct smb2_query_info_rsp *rsp,
 {
 	struct smb2_file_comp_info *file_info;
 	struct kstat stat;
+	u16 fmt;
 	int ret;
 
 	ret = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS,
@@ -5285,9 +5286,13 @@ static int get_file_compression_info(struct smb2_query_info_rsp *rsp,
 	if (ret)
 		return ret;
 
+	ret = ksmbd_vfs_get_compression(fp, &fmt);
+	if (ret)
+		return ret;
+
 	file_info = (struct smb2_file_comp_info *)rsp->Buffer;
 	file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9);
-	file_info->CompressionFormat = COMPRESSION_FORMAT_NONE;
+	file_info->CompressionFormat = cpu_to_le16(fmt);
 	file_info->CompressionUnitShift = 0;
 	file_info->ChunkShift = 0;
 	file_info->ClusterShift = 0;
Signature · 1 line
2.54.0
author reviewer
#7 lore raw

PATCH v3 7/7 smb/server: fix incorrect file size in get_file_compression_info()

In reply to [email protected]

From: ChenXiaoSong <[email protected]>

Before this patch, we got the wrong file size:

- client: touch /mnt/file
- client: smbinfo setcompression default /mnt/file
- client: dd if=/dev/zero of=/mnt/file bs=1 count=1000
- client: smbinfo filecompressioninfo /mnt/file Compressed File Size: 4096 Compression Format: 2 (LZNT1)

After this patch, we get the correct file size:

- client: smbinfo filecompressioninfo /mnt/file
Compressed File Size: 1000
Compression Format: 2 (LZNT1)

Note that the actual compressed file size must be got by other methods. For Btrfs, use the following command to get actual compressed file size:

- server: compsize /export/file
Processed 1 file, 0 regular extents (0 refs), 1 inline.
Type Perc Disk Usage Uncompressed Referenced
TOTAL 4% 47B 1000B 1000B
zlib 4% 47B 1000B 1000B

---
 fs/smb/server/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +1 -1
index 7150e77ff113..5781695d1094 100644
@@ -5291,7 +5291,7 @@ static int get_file_compression_info(struct smb2_query_info_rsp *rsp,
 		return ret;
 
 	file_info = (struct smb2_file_comp_info *)rsp->Buffer;
-	file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9);
+	file_info->CompressedFileSize = cpu_to_le64(stat.size);
 	file_info->CompressionFormat = cpu_to_le16(fmt);
 	file_info->CompressionUnitShift = 0;
 	file_info->ChunkShift = 0;
Signature · 1 line
2.54.0
maintainer
#8 lore raw

Re: [PATCH v3 7/7] smb/server: fix incorrect file size in get_file_compression_info()

Quoted 37 lines · On Mon, Jun 8, 2026 at 11:03 PM <[email protected]> wrote:

From: ChenXiaoSong <[email protected]>

Before this patch, we got the wrong file size:

- client: touch /mnt/file
- client: smbinfo setcompression default /mnt/file
- client: dd if=/dev/zero of=/mnt/file bs=1 count=1000
- client: smbinfo filecompressioninfo /mnt/file Compressed File Size: 4096 Compression Format: 2 (LZNT1)

After this patch, we get the correct file size:

- client: smbinfo filecompressioninfo /mnt/file
Compressed File Size: 1000
Compression Format: 2 (LZNT1)

Note that the actual compressed file size must be got by other methods. For Btrfs, use the following command to get actual compressed file size:

- server: compsize /export/file
Processed 1 file, 0 regular extents (0 refs), 1 inline.
Type Perc Disk Usage Uncompressed Referenced
TOTAL 4% 47B 1000B 1000B
zlib 4% 47B 1000B 1000B

---
 fs/smb/server/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +0 -0
index 7150e77ff113..5781695d1094 100644

fs/smb/server/smb2pdu.c static int get_file_compression_info(struct smb2_query_info_rsp *rsp, · line 5294

Quoted 5 lines
fs/smb/server/smb2pdu.c +1 -1
@@ -5291,7 +5291,7 @@ static int get_file_compression_info(struct smb2_query_info_rsp *rsp,
                return ret;
 
        file_info = (struct smb2_file_comp_info *)rsp->Buffer;
-       file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9);
+       file_info->CompressedFileSize = cpu_to_le64(stat.size);

We should return the number of bytes allocated to the actual disk after compression. Is stat.size the actual compressed size?

author reviewer
#9 lore raw

Re: [PATCH v3 7/7] smb/server: fix incorrect file size in get_file_compression_info()

It seems that the actual compressed size is filesystem-specific. I haven't found any generic kernel interface that can get the actual compressed size. Namjae, do you have any better ideas or suggestions?

However, stat.blocks << 9 is definitely not the actual compressed size.

Quoted 4 lines · Namjae Jeon

fs/smb/server/smb2pdu.c static int get_file_compression_info(struct smb2_query_info_rsp *rsp, · line 5294

Quoted 2 lines
fs/smb/server/smb2pdu.c +1 -1
-       file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9);
+       file_info->CompressedFileSize = cpu_to_le64(stat.size);

We should return the number of bytes allocated to the actual disk after compression. Is stat.size the actual compressed size?

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: chenxiaosong.com
English Homepage: chenxiaosong.com/en
maintainer
#10 lore raw

Re: [PATCH v3 7/7] smb/server: fix incorrect file size in get_file_compression_info()

Quoted 6 lines · ChenXiaoSong

It seems that the actual compressed size is filesystem-specific. I haven't found any generic kernel interface that can get the actual compressed size. Namjae, do you have any better ideas or suggestions?

However, stat.blocks << 9 is definitely not the actual compressed size.

I don't have any good ideas either. At least,
Shouldn't we set the smaller of the two values as the compressed size? min(stat.size, stat.blocks << 9).

Quoted 12 lines · Namjae Jeon
Quoted 4 lines

fs/smb/server/smb2pdu.c static int get_file_compression_info(struct smb2_query_info_rsp *rsp, · line 5294

Quoted 2 lines
fs/smb/server/smb2pdu.c +1 -1
-       file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9);
+       file_info->CompressedFileSize = cpu_to_le64(stat.size);

We should return the number of bytes allocated to the actual disk after compression. Is stat.size the actual compressed size?

--
ChenXiaoSong <[email protected]>
Chinese Homepage: chenxiaosong.com
English Homepage: chenxiaosong.com/en

maintainer Applied
#11 lore raw
In reply to [email protected]
Quoted 8 lines · On Mon, Jun 8, 2026 at 11:02 PM <[email protected]> wrote:

From: ChenXiaoSong <[email protected]>

v2->v3:
- Add patch #06 #07: get correct compression format and file size in get_file_compression_info()

v2: https://lore.kernel.org/linux-cifs/[email protected]/

Quoted 8 lines

ChenXiaoSong (7):
smb: remove duplicate server/smbfsctl.h
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/server: get compression format in get_file_compression_info() smb/server: fix incorrect file size in get_file_compression_info()

Applied them to #ksmbd-for-next-next except 0007 patch. Thanks!