bcachefs: Handle lock restarts in bch2_xattr_get()
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 21 Jul 2021 01:07:21 +0000 (21:07 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:09 +0000 (17:09 -0400)
Snapshots add another btree lookup, thus we need to handle lock
restarts.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/xattr.c

index 1993bfcee788b80b6221b22ec964a9f1a2649ba0..d7160e8cdc070e2ad382371fb424b467721dbf51 100644 (file)
@@ -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,