smb/server: implement compression fattr handler
Subsystems (2)
[email protected]
reviewercover 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
[email protected]
reviewerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
Namjae Jeon
maintainerRe: [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_LZNT10x0002
ChenXiaoSong
reviewerRe: [PATCH 1/5] smb: move compression definitions into common/fscc.h
Please see MS-FSCC 2.3.67: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/77f650a3-e3a2-4a25-baac-4bf9b36bcc46
Quoted 3 lines · Namjae Jeon
Quoted 1 line
-#define
COMPRESSION_FORMAT_DEFAULT0x0001Where is
COMPRESSION_FORMAT_DEFAULTdefined in the specifications? I looked through MS-FSCC but couldn't find it...
Namjae Jeon
maintainerRe: [PATCH 1/5] smb: move compression definitions into common/fscc.h
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?
ChenXiaoSong
reviewerRe: [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-4bf9b36bcc46What does
COMPRESSION_FORMAT_DEFAULTmean? default?
Tom Talpey
reviewerRe: [PATCH 1/5] smb: move compression definitions into common/fscc.h
In reply to Namjae JeonQuoted 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-4bf9b36bcc46What does
COMPRESSION_FORMAT_DEFAULTmean? 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.
ChenXiaoSong
reviewerRe: [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.
[email protected]
reviewerPATCH 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
@@ -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
@@ -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
@@ -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
Namjae Jeon
maintainerRe: [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 ; +}
ChenXiaoSong
reviewerRe: [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.
[email protected]
reviewerPATCH 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
@@ -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
@@ -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
@@ -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
Namjae Jeon
maintainerRe: [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; +}
ChenXiaoSong
reviewerRe: [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_DEFAULTdoesn't seem to exist in the spec. How do other smb clients behave when they receive this response?
Namjae Jeon
maintainerRe: [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-4bf9b36bcc46There'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.
ChenXiaoSong
reviewerRe: [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_DEFAULTis not defined inFSCTL_GET_COMPRESSION. Isn't that why it showed up as UNKNOWN in your test results?2. client: smbinfo getcompression
/mnt/fileCompression: 1 (UNKNOWN)My thought is that if the file is compressed, it might be better to return
COMPRESSION_FORMAT_LZNT1even though it is not actually compressed with LZNT1. Of course, we need to test this with a Windows client. This is because I thinkFSCTL_GET_COMPRESSIONis simply a request to check whether the file is in a compressed state or not.
Tom Talpey
reviewerRe: [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_DEFAULTis not defined inFSCTL_GET_COMPRESSION. Isn't that why it showed up as UNKNOWN in your test results?2. client: smbinfo getcompression
/mnt/fileCompression: 1 (UNKNOWN)My thought is that if the file is compressed, it might be better to return
COMPRESSION_FORMAT_LZNT1even though it is not actually compressed with LZNT1. Of course, we need to test this with a Windows client. This is because I thinkFSCTL_GET_COMPRESSIONis simply a request to check whether the file is in a compressed state or not.
ChenXiaoSong
reviewerRe: [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
Namjae Jeon
maintainerRe: [PATCH 3/5] smb/server: implement FSCTL_GET_COMPRESSION ioctl handler
Quoted 2 lines · Steve French
It is defined in current ms-fscc
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_DEFAULTdoesn'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; +}
ChenXiaoSong
reviewerRe: [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-9de52f1180f1It is defined in the
FSCTL_SET_COMPRESSIONrequest but not in theFSCTL_GET_COMPRESSIONresponse. This patch is forFSCTL_GET_COMPRESSION. I'm not sure if it's a specification error or if it's intentional.
Tom Talpey
reviewerRe: [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-9de52f1180f1It is defined in the
FSCTL_SET_COMPRESSIONrequest but not in theFSCTL_GET_COMPRESSIONresponse. This patch is forFSCTL_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.
[email protected]
reviewerPATCH 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
@@ -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
@@ -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
Namjae Jeon
maintainerRe: [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; +}
ChenXiaoSong
reviewerRe: [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 backfp->f_ci->m_fattr. I prefer the latter.
[email protected]
reviewerPATCH 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
@@ -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
@@ -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