]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb/server: get compression file attribute on open
authorChenXiaoSong <chenxiaosong@kylinos.cn>
Mon, 15 Jun 2026 11:29:07 +0000 (20:29 +0900)
committerSteve French <stfrench@microsoft.com>
Tue, 16 Jun 2026 23:57:21 +0000 (18:57 -0500)
Example:

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

Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smb2pdu.c
fs/smb/server/vfs.c
fs/smb/server/vfs.h

index e3c53f22f5ec4aec5364b5b069153fd3897444e5..4b8e1a4f9e6bfc093f2e1f452b8529a764b30832 100644 (file)
@@ -3604,7 +3604,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);
index 18c0a7c6b41bd65416ef0b62a80c95e405809a4e..b2403db1355847303ec23da783659d2ca8d73e66 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/sched/xacct.h>
 #include <linux/crc32c.h>
 #include <linux/splice.h>
+#include <linux/fileattr.h>
 
 #include "glob.h"
 #include "oplock.h"
@@ -1881,3 +1882,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;
+}
index 16ca29ee16e5159547e4fc7907c59fec8ff3c9f4..ac6dda173b752f365984b4211f106f703ee67226 100644 (file)
@@ -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__ */