btrfs: split btrfs_setxattr calls regarding transaction

When the caller has already created the transaction handle,
btrfs_setxattr() will use it. Also adds assert in btrfs_setxattr().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Anand Jain 2019-04-12 16:02:58 +08:00 committed by David Sterba
parent 353c2ea735
commit 04e6863b19
3 changed files with 33 additions and 13 deletions

View File

@ -93,7 +93,11 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
goto out;
}
ret = btrfs_setxattr_trans(trans, inode, name, value, size, 0);
if (trans)
ret = btrfs_setxattr(trans, inode, name, value, size, 0);
else
ret = btrfs_setxattr_trans(NULL, inode, name, value, size, 0);
out:
kfree(value);

View File

@ -70,8 +70,13 @@ static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
return -EINVAL;
if (value_len == 0) {
ret = btrfs_setxattr_trans(trans, inode, handler->xattr_name,
NULL, 0, flags);
if (trans)
ret = btrfs_setxattr(trans, inode, handler->xattr_name,
NULL, 0, flags);
else
ret = btrfs_setxattr_trans(NULL, inode,
handler->xattr_name, NULL, 0,
flags);
if (ret)
return ret;
@ -84,14 +89,23 @@ static int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode,
ret = handler->validate(value, value_len);
if (ret)
return ret;
ret = btrfs_setxattr_trans(trans, inode, handler->xattr_name,
value, value_len, flags);
if (trans)
ret = btrfs_setxattr(trans, inode, handler->xattr_name, value,
value_len, flags);
else
ret = btrfs_setxattr_trans(NULL, inode, handler->xattr_name,
value, value_len, flags);
if (ret)
return ret;
ret = handler->apply(inode, value, value_len);
if (ret) {
btrfs_setxattr_trans(trans, inode, handler->xattr_name,
NULL, 0, flags);
if (trans)
btrfs_setxattr(trans, inode, handler->xattr_name, NULL,
0, flags);
else
btrfs_setxattr_trans(NULL, inode, handler->xattr_name,
NULL, 0, flags);
return ret;
}
@ -358,13 +372,13 @@ static int inherit_props(struct btrfs_trans_handle *trans,
if (ret)
return ret;
ret = btrfs_setxattr_trans(trans, inode, h->xattr_name, value,
strlen(value), 0);
ret = btrfs_setxattr(trans, inode, h->xattr_name, value,
strlen(value), 0);
if (!ret) {
ret = h->apply(inode, value, strlen(value));
if (ret)
btrfs_setxattr_trans(trans, inode, h->xattr_name,
NULL, 0, 0);
btrfs_setxattr(trans, inode, h->xattr_name,
NULL, 0, 0);
else
set_bit(BTRFS_INODE_HAS_PROPS,
&BTRFS_I(inode)->runtime_flags);

View File

@ -86,6 +86,8 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,
size_t name_len = strlen(name);
int ret = 0;
ASSERT(trans);
if (name_len + size > BTRFS_MAX_XATTR_SIZE(root->fs_info))
return -ENOSPC;
@ -437,8 +439,8 @@ static int btrfs_initxattrs(struct inode *inode,
}
strcpy(name, XATTR_SECURITY_PREFIX);
strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name);
err = btrfs_setxattr_trans(trans, inode, name, xattr->value,
xattr->value_len, 0);
err = btrfs_setxattr(trans, inode, name, xattr->value,
xattr->value_len, 0);
kfree(name);
if (err < 0)
break;