Commit 5ff10c0a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Convert acl.c to allocate_dropping_locks()

More work to avoid allocating memory with btree locks held.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent d95dd378
...@@ -35,12 +35,14 @@ static inline int acl_to_xattr_type(int type) ...@@ -35,12 +35,14 @@ static inline int acl_to_xattr_type(int type)
/* /*
* Convert from filesystem to in-memory representation. * Convert from filesystem to in-memory representation.
*/ */
static struct posix_acl *bch2_acl_from_disk(const void *value, size_t size) static struct posix_acl *bch2_acl_from_disk(struct btree_trans *trans,
const void *value, size_t size)
{ {
const void *p, *end = value + size; const void *p, *end = value + size;
struct posix_acl *acl; struct posix_acl *acl;
struct posix_acl_entry *out; struct posix_acl_entry *out;
unsigned count = 0; unsigned count = 0;
int ret;
if (!value) if (!value)
return NULL; return NULL;
...@@ -81,9 +83,14 @@ static struct posix_acl *bch2_acl_from_disk(const void *value, size_t size) ...@@ -81,9 +83,14 @@ static struct posix_acl *bch2_acl_from_disk(const void *value, size_t size)
if (!count) if (!count)
return NULL; return NULL;
acl = posix_acl_alloc(count, GFP_KERNEL); acl = allocate_dropping_locks(trans, ret,
posix_acl_alloc(count, _gfp));
if (!acl) if (!acl)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (ret) {
kfree(acl);
return ERR_PTR(ret);
}
out = acl->a_entries; out = acl->a_entries;
...@@ -234,8 +241,6 @@ struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap, ...@@ -234,8 +241,6 @@ struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap,
&X_SEARCH(acl_to_xattr_type(type), "", 0), &X_SEARCH(acl_to_xattr_type(type), "", 0),
0); 0);
if (ret) { if (ret) {
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;
if (!bch2_err_matches(ret, ENOENT)) if (!bch2_err_matches(ret, ENOENT))
acl = ERR_PTR(ret); acl = ERR_PTR(ret);
goto out; goto out;
...@@ -249,12 +254,15 @@ struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap, ...@@ -249,12 +254,15 @@ struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap,
} }
xattr = bkey_s_c_to_xattr(k); xattr = bkey_s_c_to_xattr(k);
acl = bch2_acl_from_disk(xattr_val(xattr.v), acl = bch2_acl_from_disk(&trans, xattr_val(xattr.v),
le16_to_cpu(xattr.v->x_val_len)); le16_to_cpu(xattr.v->x_val_len));
if (!IS_ERR(acl)) if (!IS_ERR(acl))
set_cached_acl(&inode->v, type, acl); set_cached_acl(&inode->v, type, acl);
out: out:
if (bch2_err_matches(PTR_ERR_OR_ZERO(acl), BCH_ERR_transaction_restart))
goto retry;
bch2_trans_iter_exit(&trans, &iter); bch2_trans_iter_exit(&trans, &iter);
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return acl; return acl;
...@@ -375,13 +383,14 @@ int bch2_acl_chmod(struct btree_trans *trans, subvol_inum inum, ...@@ -375,13 +383,14 @@ int bch2_acl_chmod(struct btree_trans *trans, subvol_inum inum,
if (ret) if (ret)
goto err; goto err;
acl = bch2_acl_from_disk(xattr_val(xattr.v), acl = bch2_acl_from_disk(trans, xattr_val(xattr.v),
le16_to_cpu(xattr.v->x_val_len)); le16_to_cpu(xattr.v->x_val_len));
ret = PTR_ERR_OR_ZERO(acl); ret = PTR_ERR_OR_ZERO(acl);
if (IS_ERR_OR_NULL(acl)) if (IS_ERR_OR_NULL(acl))
goto err; goto err;
ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode); ret = allocate_dropping_locks_errcode(trans,
__posix_acl_chmod(&acl, _gfp, mode));
if (ret) if (ret)
goto err; goto err;
......
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