summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/props.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2019-04-20 19:48:51 +0800
committerDavid Sterba <dsterba@suse.com>2019-04-29 19:02:52 +0200
commitf22125e5d8ae136adb99552d97078702e1ee68ab (patch)
tree091574a84bd201eff96baa3e9d20b3751c3f2f6c /fs/btrfs/props.c
parent7c15d41016dc886cc011e3854d855e219759ae68 (diff)
btrfs: refactor btrfs_set_props to validate externally
In preparation to merge multiple transactions when setting the compression flags, split btrfs_set_props() validation part outside of it. Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/props.c')
-rw-r--r--fs/btrfs/props.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 44b7bf647ab3..e356dd2a0f73 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -55,6 +55,23 @@ find_prop_handler(const char *name,
return NULL;
}
+int btrfs_validate_prop(const char *name, const char *value, size_t value_len)
+{
+ const struct prop_handler *handler;
+
+ if (strlen(name) <= XATTR_BTRFS_PREFIX_LEN)
+ return -EINVAL;
+
+ handler = find_prop_handler(name, NULL);
+ if (!handler)
+ return -EINVAL;
+
+ if (value_len == 0)
+ return 0;
+
+ return handler->validate(value, value_len);
+}
+
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)
@@ -62,9 +79,6 @@ static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
const struct prop_handler *handler;
int ret;
- if (strlen(name) <= XATTR_BTRFS_PREFIX_LEN)
- return -EINVAL;
-
handler = find_prop_handler(name, NULL);
if (!handler)
return -EINVAL;
@@ -85,9 +99,6 @@ static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
return ret;
}
- ret = handler->validate(value, value_len);
- if (ret)
- return ret;
if (trans)
ret = btrfs_setxattr(trans, inode, handler->xattr_name, value,
value_len, flags);