btrfs: rename variable holding per-inode compression type
authorDavid Sterba <dsterba@suse.com>
Mon, 17 Jul 2017 17:17:20 +0000 (19:17 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 16 Aug 2017 14:12:05 +0000 (16:12 +0200)
This is preparatory for separating inode compression requested by defrag
and set via properties. This will fix a usability bug when defrag will
reset compression type to NONE. If the file has compression set via
property, it will not apply anymore (until next mount or reset through
command line).

We're going to fix that by adding another variable just for the defrag
call and won't touch the property. The defrag will have higher priority
when deciding whether to compress the data.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/btrfs_inode.h
fs/btrfs/inode.c
fs/btrfs/ioctl.c
fs/btrfs/props.c

index 31c259c8462db0971527474049dcc63cc54640d5..fa118036a84ee4efd1b08bf1e903e34c615ac483 100644 (file)
@@ -179,9 +179,9 @@ struct btrfs_inode {
        unsigned reserved_extents;
 
        /*
-        * always compress this one file
+        * Cached values of inode properties
         */
-       unsigned force_compress;
+       unsigned prop_compress;         /* per-file compression algorithm */
 
        struct btrfs_delayed_node *delayed_node;
 
index 0bd008b9e0d162325fea7434ceca51ec9893791d..c60a6d692bc1a37fd3709a1f40c12dced2936961 100644 (file)
@@ -404,7 +404,7 @@ static inline int inode_need_compress(struct inode *inode, u64 start, u64 end)
                return 0;
        if (btrfs_test_opt(fs_info, COMPRESS) ||
            BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
-           BTRFS_I(inode)->force_compress)
+           BTRFS_I(inode)->prop_compress)
                return btrfs_compress_heuristic(inode, start, end);
        return 0;
 }
@@ -511,8 +511,8 @@ again:
                        goto cont;
                }
 
-               if (BTRFS_I(inode)->force_compress)
-                       compress_type = BTRFS_I(inode)->force_compress;
+               if (BTRFS_I(inode)->prop_compress)
+                       compress_type = BTRFS_I(inode)->prop_compress;
 
                /*
                 * we need to call clear_page_dirty_for_io on each
@@ -645,7 +645,7 @@ cont:
 
                /* flag the file so we don't compress in the future */
                if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) &&
-                   !(BTRFS_I(inode)->force_compress)) {
+                   !(BTRFS_I(inode)->prop_compress)) {
                        BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
                }
        }
@@ -9433,7 +9433,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
        ei->reserved_extents = 0;
 
        ei->runtime_flags = 0;
-       ei->force_compress = BTRFS_COMPRESS_NONE;
+       ei->prop_compress = BTRFS_COMPRESS_NONE;
 
        ei->delayed_node = NULL;
 
index 8189cb328d4ad5f5d709861f2e1469c14460e0e7..e1c15a2ac785aa3ddc9ee8e260538908a9fbe96e 100644 (file)
@@ -1371,7 +1371,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 
                inode_lock(inode);
                if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)
-                       BTRFS_I(inode)->force_compress = compress_type;
+                       BTRFS_I(inode)->prop_compress = compress_type;
                ret = cluster_pages_for_defrag(inode, pages, i, cluster);
                if (ret < 0) {
                        inode_unlock(inode);
@@ -1442,7 +1442,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 out_ra:
        if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) {
                inode_lock(inode);
-               BTRFS_I(inode)->force_compress = BTRFS_COMPRESS_NONE;
+               BTRFS_I(inode)->prop_compress = BTRFS_COMPRESS_NONE;
                inode_unlock(inode);
        }
        if (!file)
index 4b23ae5d0e5c0330260ae96d2574b9422c16978d..916f5cf9b2929fc640d1555e206ab2804fc7cdce 100644 (file)
@@ -403,7 +403,7 @@ static int prop_compression_apply(struct inode *inode,
        if (len == 0) {
                BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
                BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
-               BTRFS_I(inode)->force_compress = BTRFS_COMPRESS_NONE;
+               BTRFS_I(inode)->prop_compress = BTRFS_COMPRESS_NONE;
 
                return 0;
        }
@@ -417,14 +417,14 @@ static int prop_compression_apply(struct inode *inode,
 
        BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
        BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
-       BTRFS_I(inode)->force_compress = type;
+       BTRFS_I(inode)->prop_compress = type;
 
        return 0;
 }
 
 static const char *prop_compression_extract(struct inode *inode)
 {
-       switch (BTRFS_I(inode)->force_compress) {
+       switch (BTRFS_I(inode)->prop_compress) {
        case BTRFS_COMPRESS_ZLIB:
                return "zlib";
        case BTRFS_COMPRESS_LZO: