btrfs: property: Set incompat flag if lzo/zstd compression is set
[sfrench/cifs-2.6.git] / fs / btrfs / props.c
index b30a056963ab91a5f110d0a034bd5bd81adeb9f1..dc6140013ae8194739a8aa6a387f12c35794bdf9 100644 (file)
@@ -1,26 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License v2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
  */
 
 #include <linux/hashtable.h>
 #include "props.h"
 #include "btrfs_inode.h"
-#include "hash.h"
 #include "transaction.h"
+#include "ctree.h"
 #include "xattr.h"
 #include "compression.h"
 
@@ -116,7 +103,7 @@ static int __btrfs_set_prop(struct btrfs_trans_handle *trans,
                return -EINVAL;
 
        if (value_len == 0) {
-               ret = __btrfs_setxattr(trans, inode, handler->xattr_name,
+               ret = btrfs_setxattr(trans, inode, handler->xattr_name,
                                       NULL, 0, flags);
                if (ret)
                        return ret;
@@ -130,13 +117,13 @@ static int __btrfs_set_prop(struct btrfs_trans_handle *trans,
        ret = handler->validate(value, value_len);
        if (ret)
                return ret;
-       ret = __btrfs_setxattr(trans, inode, handler->xattr_name,
+       ret = btrfs_setxattr(trans, inode, handler->xattr_name,
                               value, value_len, flags);
        if (ret)
                return ret;
        ret = handler->apply(inode, value, value_len);
        if (ret) {
-               __btrfs_setxattr(trans, inode, handler->xattr_name,
+               btrfs_setxattr(trans, inode, handler->xattr_name,
                                 NULL, 0, flags);
                return ret;
        }
@@ -393,6 +380,7 @@ 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) {
@@ -403,14 +391,17 @@ static int prop_compression_apply(struct inode *inode,
                return 0;
        }
 
-       if (!strncmp("lzo", value, 3))
+       if (!strncmp("lzo", value, 3)) {
                type = BTRFS_COMPRESS_LZO;
-       else if (!strncmp("zlib", value, 4))
+               btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
+       } else if (!strncmp("zlib", value, 4)) {
                type = BTRFS_COMPRESS_ZLIB;
-       else if (!strncmp("zstd", value, len))
+       } else if (!strncmp("zstd", value, len)) {
                type = BTRFS_COMPRESS_ZSTD;
-       else
+               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;