smb/server: implement compression fattr handler
Subsystems (2)
[email protected]
reviewerv2 cover smb/server: implement compression fattr handler
From: ChenXiaoSong <[email protected]>
v1->v2:
- Patch #02: remove unneeded return
- Patch #03: return LZNT1 if the is compressed
- Patch #04:
- Don't roll back fp->f_ci->m_fattr when ksmbd_vfs_set_dos_attrib_xattr() fails
- Remove unneeded goto
v1: https://lore.kernel.org/linux-cifs/[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 | 111 +++++++++++++++++++++++++++++++++++++++ fs/smb/server/vfs.h | 3 ++ 9 files changed, 206 insertions(+), 112 deletions(-) delete mode 100644 fs/smb/server/smbfsctl.h
Signature · 1 line
2.54.0
[email protected]
reviewerPATCH v2 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
[email protected]
reviewerPATCH v2 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 | 18 ++++++++++++++++++ fs/smb/server/vfs.h | 1 + 3 files changed, 23 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 +18 -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,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
@@ -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
[email protected]
reviewerPATCH v2 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: 2 (LZNT1)
--- 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
@@ -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
@@ -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
[email protected]
reviewerPATCH v2 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 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/server/smb2pdu.c | 28 +++++++++++++++++ fs/smb/server/vfs.c | 70 +++++++++++++++++++++++++++++++++++++++++ fs/smb/server/vfs.h | 1 + 3 files changed, 99 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 +70 -0
73 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
[email protected]
reviewerPATCH v2 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