unsigned int fsflags, old_fsflags;
int ret;
const char *comp = NULL;
+ char comp_buf[BTRFS_COMPRESS_PROP_MAX_LEN];
u32 inode_flags;
bool prop_set = false;
inode_flags &= ~BTRFS_INODE_COMPRESS;
inode_flags |= BTRFS_INODE_NOCOMPRESS;
} else if (fsflags & FS_COMPR_FL) {
- enum btrfs_compression_type comp_type;
if (IS_SWAPFILE(&inode->vfs_inode))
return -ETXTBSY;
inode_flags &= ~BTRFS_INODE_NOCOMPRESS;
/*
- * Keep the algorithm recorded in the compression property,
- * otherwise changing an unrelated attribute would reset it to
- * the mount default, since FS_IOC_SETFLAGS callers write back
- * the whole flag set they got from FS_IOC_GETFLAGS and that
- * includes FS_COMPR_FL for any inode carrying the property.
+ * If compression is already enabled, we must reconstruct the
+ * full "algo:level" property string and write it back.
+ * Otherwise changing an unrelated attribute would reset it to
+ * the mount default and drop the level, since FS_IOC_SETFLAGS
+ * callers write back the whole flag set they got from
+ * FS_IOC_GETFLAGS, and that includes FS_COMPR_FL.
*
* Inodes with the compress flag set but no property keep using
* the mount default, so they behave as before.
*/
- if (inode->prop_compress)
- comp_type = inode->prop_compress;
- else if (fs_info->compress_type)
- comp_type = fs_info->compress_type;
- else
- comp_type = BTRFS_COMPRESS_ZLIB;
- comp = btrfs_compress_type2str(comp_type);
+ comp = btrfs_compress_typelevel2str(inode->prop_compress,
+ inode->prop_compress_level,
+ comp_buf, sizeof(comp_buf));
+ if (!comp || comp[0] == 0)
+ comp = btrfs_compress_type2str(fs_info->compress_type);
+ if (!comp || comp[0] == 0)
+ comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB);
} else {
inode_flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
}
#include "super.h"
#include "dir-item.h"
-/*
- * Max length of compression algorithm:level string.
- *
- * For now the longest possible string is "zstd:-15", which is
- * 8 characters + 1 terminating null byte.
- * Rounding it up to the closest power of 2 gives 16.
- */
-#define BTRFS_COMPRESS_PROP_MAX_LEN 16
-
#define BTRFS_PROP_HANDLERS_HT_BITS 8
static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS);
#include <linux/types.h>
#include <linux/compiler_types.h>
+/*
+ * Max length of compression algorithm:level string.
+ *
+ * For now the longest possible string is "zstd:-15", which is
+ * 8 characters + 1 terminating null byte.
+ * Rounding it up to the closest power of 2 gives 16.
+ */
+#define BTRFS_COMPRESS_PROP_MAX_LEN 16
+
struct btrfs_inode;
struct btrfs_path;
struct btrfs_trans_handle;