btrfs: tree-checker: get fs_info from eb in check_extent_data_item
[sfrench/cifs-2.6.git] / fs / btrfs / props.c
index 61d22a56c0ba4e7d43f0552854f4ac4e82443218..722ccf6bdd2b1fbe5cc786d84c6e804bc7a04eb9 100644 (file)
@@ -23,36 +23,6 @@ struct prop_handler {
        int inheritable;
 };
 
-static int prop_compression_validate(const char *value, size_t len);
-static int prop_compression_apply(struct inode *inode,
-                                 const char *value,
-                                 size_t len);
-static const char *prop_compression_extract(struct inode *inode);
-
-static struct prop_handler prop_handlers[] = {
-       {
-               .xattr_name = XATTR_BTRFS_PREFIX "compression",
-               .validate = prop_compression_validate,
-               .apply = prop_compression_apply,
-               .extract = prop_compression_extract,
-               .inheritable = 1
-       },
-};
-
-void __init btrfs_props_init(void)
-{
-       int i;
-
-       hash_init(prop_handlers_ht);
-
-       for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) {
-               struct prop_handler *p = &prop_handlers[i];
-               u64 h = btrfs_name_hash(p->xattr_name, strlen(p->xattr_name));
-
-               hash_add(prop_handlers_ht, &p->node, h);
-       }
-}
-
 static const struct hlist_head *find_prop_handlers_by_hash(const u64 hash)
 {
        struct hlist_head *h;
@@ -85,12 +55,9 @@ find_prop_handler(const char *name,
        return NULL;
 }
 
-static int __btrfs_set_prop(struct btrfs_trans_handle *trans,
-                           struct inode *inode,
-                           const char *name,
-                           const char *value,
-                           size_t value_len,
-                           int flags)
+static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
+                         const char *name, const char *value, size_t value_len,
+                         int flags)
 {
        const struct prop_handler *handler;
        int ret;
@@ -133,13 +100,10 @@ static int __btrfs_set_prop(struct btrfs_trans_handle *trans,
        return 0;
 }
 
-int btrfs_set_prop(struct inode *inode,
-                  const char *name,
-                  const char *value,
-                  size_t value_len,
-                  int flags)
+int btrfs_set_prop_trans(struct inode *inode, const char *name,
+                        const char *value, size_t value_len, int flags)
 {
-       return __btrfs_set_prop(NULL, inode, name, value, value_len, flags);
+       return btrfs_set_prop(NULL, inode, name, value, value_len, flags);
 }
 
 static int iterate_object_props(struct btrfs_root *root,
@@ -283,6 +247,78 @@ int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path)
        return ret;
 }
 
+static int prop_compression_validate(const char *value, size_t len)
+{
+       if (!value)
+               return 0;
+
+       if (!strncmp("lzo", value, 3))
+               return 0;
+       else if (!strncmp("zlib", value, 4))
+               return 0;
+       else if (!strncmp("zstd", value, 4))
+               return 0;
+
+       return -EINVAL;
+}
+
+static int prop_compression_apply(struct inode *inode, const char *value,
+                                 size_t len)
+{
+       struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+       int type;
+
+       if (len == 0) {
+               BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
+               BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
+               BTRFS_I(inode)->prop_compress = BTRFS_COMPRESS_NONE;
+
+               return 0;
+       }
+
+       if (!strncmp("lzo", value, 3)) {
+               type = BTRFS_COMPRESS_LZO;
+               btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
+       } else if (!strncmp("zlib", value, 4)) {
+               type = BTRFS_COMPRESS_ZLIB;
+       } else if (!strncmp("zstd", value, 4)) {
+               type = BTRFS_COMPRESS_ZSTD;
+               btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
+       } else {
+               return -EINVAL;
+       }
+
+       BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
+       BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
+       BTRFS_I(inode)->prop_compress = type;
+
+       return 0;
+}
+
+static const char *prop_compression_extract(struct inode *inode)
+{
+       switch (BTRFS_I(inode)->prop_compress) {
+       case BTRFS_COMPRESS_ZLIB:
+       case BTRFS_COMPRESS_LZO:
+       case BTRFS_COMPRESS_ZSTD:
+               return btrfs_compress_type2str(BTRFS_I(inode)->prop_compress);
+       default:
+               break;
+       }
+
+       return NULL;
+}
+
+static struct prop_handler prop_handlers[] = {
+       {
+               .xattr_name = XATTR_BTRFS_PREFIX "compression",
+               .validate = prop_compression_validate,
+               .apply = prop_compression_apply,
+               .extract = prop_compression_extract,
+               .inheritable = 1
+       },
+};
+
 static int inherit_props(struct btrfs_trans_handle *trans,
                         struct inode *inode,
                         struct inode *parent)
@@ -313,8 +349,8 @@ static int inherit_props(struct btrfs_trans_handle *trans,
                                          num_bytes, BTRFS_RESERVE_NO_FLUSH);
                if (ret)
                        goto out;
-               ret = __btrfs_set_prop(trans, inode, h->xattr_name,
-                                      value, strlen(value), 0);
+               ret = btrfs_set_prop(trans, inode, h->xattr_name, value,
+                                    strlen(value), 0);
                btrfs_block_rsv_release(fs_info, trans->block_rsv, num_bytes);
                if (ret)
                        goto out;
@@ -364,64 +400,17 @@ int btrfs_subvol_inherit_props(struct btrfs_trans_handle *trans,
        return ret;
 }
 
-static int prop_compression_validate(const char *value, size_t len)
-{
-       if (!strncmp("lzo", value, 3))
-               return 0;
-       else if (!strncmp("zlib", value, 4))
-               return 0;
-       else if (!strncmp("zstd", value, 4))
-               return 0;
-
-       return -EINVAL;
-}
-
-static int prop_compression_apply(struct inode *inode,
-                                 const char *value,
-                                 size_t len)
+void __init btrfs_props_init(void)
 {
-       struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
-       int type;
-
-       if (len == 0) {
-               BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
-               BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
-               BTRFS_I(inode)->prop_compress = BTRFS_COMPRESS_NONE;
-
-               return 0;
-       }
-
-       if (!strncmp("lzo", value, 3)) {
-               type = BTRFS_COMPRESS_LZO;
-               btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
-       } else if (!strncmp("zlib", value, 4)) {
-               type = BTRFS_COMPRESS_ZLIB;
-       } else if (!strncmp("zstd", value, 4)) {
-               type = BTRFS_COMPRESS_ZSTD;
-               btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
-       } else {
-               return -EINVAL;
-       }
+       int i;
 
-       BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
-       BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
-       BTRFS_I(inode)->prop_compress = type;
+       hash_init(prop_handlers_ht);
 
-       return 0;
-}
+       for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) {
+               struct prop_handler *p = &prop_handlers[i];
+               u64 h = btrfs_name_hash(p->xattr_name, strlen(p->xattr_name));
 
-static const char *prop_compression_extract(struct inode *inode)
-{
-       switch (BTRFS_I(inode)->prop_compress) {
-       case BTRFS_COMPRESS_ZLIB:
-       case BTRFS_COMPRESS_LZO:
-       case BTRFS_COMPRESS_ZSTD:
-               return btrfs_compress_type2str(BTRFS_I(inode)->prop_compress);
-       default:
-               break;
+               hash_add(prop_handlers_ht, &p->node, h);
        }
-
-       return NULL;
 }
 
-