]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: use better definition of number of compression type
authorChengguang Xu <cgxu519@mykernel.net>
Thu, 10 Oct 2019 07:59:57 +0000 (15:59 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 18 Nov 2019 11:46:55 +0000 (12:46 +0100)
The compression type upper limit constant is the same as the last value
and this is confusing.  In order to keep coding style consistent, use
BTRFS_NR_COMPRESS_TYPES as the total number that follows the idom of
'NR' being one more than the last value.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/ioctl.c
fs/btrfs/tree-checker.c

index d70c464074209e42cc4db862385c048c1fea4c01..93deaf0cc2b84d164f9e9797f67c3f028e4f25e6 100644 (file)
@@ -39,6 +39,8 @@ const char* btrfs_compress_type2str(enum btrfs_compression_type type)
        case BTRFS_COMPRESS_ZSTD:
        case BTRFS_COMPRESS_NONE:
                return btrfs_compress_types[type];
+       default:
+               break;
        }
 
        return NULL;
index dd392278ab3f2324f0099f2afb03480b03323af3..52dce1176f897333a161880df0a60f788762764d 100644 (file)
@@ -105,7 +105,7 @@ enum btrfs_compression_type {
        BTRFS_COMPRESS_ZLIB  = 1,
        BTRFS_COMPRESS_LZO   = 2,
        BTRFS_COMPRESS_ZSTD  = 3,
-       BTRFS_COMPRESS_TYPES = 3,
+       BTRFS_NR_COMPRESS_TYPES = 4,
 };
 
 struct workspace_manager {
@@ -163,7 +163,7 @@ struct btrfs_compress_op {
 };
 
 /* The heuristic workspaces are managed via the 0th workspace manager */
-#define BTRFS_NR_WORKSPACE_MANAGERS    (BTRFS_COMPRESS_TYPES + 1)
+#define BTRFS_NR_WORKSPACE_MANAGERS    BTRFS_NR_COMPRESS_TYPES
 
 extern const struct btrfs_compress_op btrfs_heuristic_compress;
 extern const struct btrfs_compress_op btrfs_zlib_compress;
index d7a1bd74bb71c4cf252250e317c6af3ccb5a529e..5892fa9398c36857373e93c3b835224aaa13659d 100644 (file)
@@ -1409,7 +1409,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                return -EINVAL;
 
        if (do_compress) {
-               if (range->compress_type > BTRFS_COMPRESS_TYPES)
+               if (range->compress_type >= BTRFS_NR_COMPRESS_TYPES)
                        return -EINVAL;
                if (range->compress_type)
                        compress_type = range->compress_type;
index 9699c91c958eabf64d7b34e405d2038729e546e4..f4751615a189d5755fa8d3f91321830686dd446d 100644 (file)
@@ -233,11 +233,11 @@ static int check_extent_data_item(struct extent_buffer *leaf,
         * Support for new compression/encryption must introduce incompat flag,
         * and must be caught in open_ctree().
         */
-       if (btrfs_file_extent_compression(leaf, fi) > BTRFS_COMPRESS_TYPES) {
+       if (btrfs_file_extent_compression(leaf, fi) >= BTRFS_NR_COMPRESS_TYPES) {
                file_extent_err(leaf, slot,
        "invalid compression for file extent, have %u expect range [0, %u]",
                        btrfs_file_extent_compression(leaf, fi),
-                       BTRFS_COMPRESS_TYPES);
+                       BTRFS_NR_COMPRESS_TYPES - 1);
                return -EUCLEAN;
        }
        if (btrfs_file_extent_encryption(leaf, fi)) {