Commit 4909fe50 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Handle lock restarts in bch2_xattr_get()

Snapshots add another btree lookup, thus we need to handle lock
restarts.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 5f87f3c1
......@@ -118,18 +118,15 @@ void bch2_xattr_to_text(struct printbuf *out, struct bch_fs *c,
le16_to_cpu(xattr.v->x_val_len));
}
int bch2_xattr_get(struct bch_fs *c, struct bch_inode_info *inode,
const char *name, void *buffer, size_t size, int type)
static int bch2_xattr_get_trans(struct btree_trans *trans, struct bch_inode_info *inode,
const char *name, void *buffer, size_t size, int type)
{
struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode);
struct btree_trans trans;
struct bch_hash_info hash = bch2_hash_info_init(trans->c, &inode->ei_inode);
struct btree_iter *iter;
struct bkey_s_c_xattr xattr;
int ret;
bch2_trans_init(&trans, c, 0, 0);
iter = bch2_hash_lookup(&trans, bch2_xattr_hash_desc, &hash,
iter = bch2_hash_lookup(trans, bch2_xattr_hash_desc, &hash,
inode->v.i_ino,
&X_SEARCH(type, name, strlen(name)),
0);
......@@ -145,14 +142,18 @@ int bch2_xattr_get(struct bch_fs *c, struct bch_inode_info *inode,
else
memcpy(buffer, xattr_val(xattr.v), ret);
}
bch2_trans_iter_put(&trans, iter);
bch2_trans_iter_put(trans, iter);
err:
bch2_trans_exit(&trans);
BUG_ON(ret == -EINTR);
return ret == -ENOENT ? -ENODATA : ret;
}
int bch2_xattr_get(struct bch_fs *c, struct bch_inode_info *inode,
const char *name, void *buffer, size_t size, int type)
{
return bch2_trans_do(c, NULL, NULL, 0,
bch2_xattr_get_trans(&trans, inode, name, buffer, size, type));
}
int bch2_xattr_set(struct btree_trans *trans, u64 inum,
const struct bch_hash_info *hash_info,
const char *name, const void *value, size_t size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment