]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/acl.c
Update bcachefs sources to 7c0fe6f104 bcachefs: Fix bch2_fsck_ask_yn()
[bcachefs-tools-debian] / libbcachefs / acl.c
index 0cde2638d0178e8c6d523e67f83f2e1163b12d01..ce7a460fb308b3463e921dfbfb10e9891469b5ed 100644 (file)
@@ -35,12 +35,14 @@ static inline int acl_to_xattr_type(int type)
 /*
  * 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;
        struct posix_acl *acl;
        struct posix_acl_entry *out;
        unsigned count = 0;
+       int ret;
 
        if (!value)
                return NULL;
@@ -81,9 +83,14 @@ static struct posix_acl *bch2_acl_from_disk(const void *value, size_t size)
        if (!count)
                return NULL;
 
-       acl = posix_acl_alloc(count, GFP_KERNEL);
+       acl = allocate_dropping_locks(trans, ret,
+                       posix_acl_alloc(count, _gfp));
        if (!acl)
                return ERR_PTR(-ENOMEM);
+       if (ret) {
+               kfree(acl);
+               return ERR_PTR(ret);
+       }
 
        out = acl->a_entries;
 
@@ -173,7 +180,7 @@ bch2_acl_to_xattr(struct btree_trans *trans,
        bkey_xattr_init(&xattr->k_i);
        xattr->k.u64s           = u64s;
        xattr->v.x_type         = acl_to_xattr_type(type);
-       xattr->v.x_name_len     = 0,
+       xattr->v.x_name_len     = 0;
        xattr->v.x_val_len      = cpu_to_le16(acl_len);
 
        acl_header = xattr_val(&xattr->v);
@@ -212,9 +219,10 @@ bch2_acl_to_xattr(struct btree_trans *trans,
        return xattr;
 }
 
-struct posix_acl *bch2_get_acl(struct inode *vinode, int type, bool rcu)
+struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap,
+                              struct dentry *dentry, int type)
 {
-       struct bch_inode_info *inode = to_bch_ei(vinode);
+       struct bch_inode_info *inode = to_bch_ei(dentry->d_inode);
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
        struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode);
        struct btree_trans trans;
@@ -224,9 +232,6 @@ struct posix_acl *bch2_get_acl(struct inode *vinode, int type, bool rcu)
        struct bkey_s_c k;
        int ret;
 
-       if (rcu)
-               return ERR_PTR(-ECHILD);
-
        bch2_trans_init(&trans, c, 0, 0);
 retry:
        bch2_trans_begin(&trans);
@@ -236,9 +241,7 @@ retry:
                        &X_SEARCH(acl_to_xattr_type(type), "", 0),
                        0);
        if (ret) {
-               if (ret == -EINTR)
-                       goto retry;
-               if (ret != -ENOENT)
+               if (!bch2_err_matches(ret, ENOENT))
                        acl = ERR_PTR(ret);
                goto out;
        }
@@ -251,12 +254,15 @@ retry:
        }
 
        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));
 
        if (!IS_ERR(acl))
                set_cached_acl(&inode->v, type, acl);
 out:
+       if (bch2_err_matches(PTR_ERR_OR_ZERO(acl), BCH_ERR_transaction_restart))
+               goto retry;
+
        bch2_trans_iter_exit(&trans, &iter);
        bch2_trans_exit(&trans);
        return acl;
@@ -289,13 +295,14 @@ int bch2_set_acl_trans(struct btree_trans *trans, subvol_inum inum,
                                       inum, &search);
        }
 
-       return ret == -ENOENT ? 0 : ret;
+       return bch2_err_matches(ret, ENOENT) ? 0 : ret;
 }
 
-int bch2_set_acl(struct user_namespace *mnt_userns,
-                struct inode *vinode, struct posix_acl *_acl, int type)
+int bch2_set_acl(struct mnt_idmap *idmap,
+                struct dentry *dentry,
+                struct posix_acl *_acl, int type)
 {
-       struct bch_inode_info *inode = to_bch_ei(vinode);
+       struct bch_inode_info *inode = to_bch_ei(dentry->d_inode);
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
        struct btree_trans trans;
        struct btree_iter inode_iter = { NULL };
@@ -318,7 +325,7 @@ retry:
        mode = inode_u.bi_mode;
 
        if (type == ACL_TYPE_ACCESS) {
-               ret = posix_acl_update_mode(mnt_userns, &inode->v, &mode, &acl);
+               ret = posix_acl_update_mode(idmap, &inode->v, &mode, &acl);
                if (ret)
                        goto btree_err;
        }
@@ -335,12 +342,12 @@ retry:
 btree_err:
        bch2_trans_iter_exit(&trans, &inode_iter);
 
-       if (ret == -EINTR)
+       if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
                goto retry;
        if (unlikely(ret))
                goto err;
 
-       bch2_inode_update_after_write(c, inode, &inode_u,
+       bch2_inode_update_after_write(&trans, inode, &inode_u,
                                      ATTR_CTIME|ATTR_MODE);
 
        set_cached_acl(&inode->v, type, acl);
@@ -369,20 +376,21 @@ int bch2_acl_chmod(struct btree_trans *trans, subvol_inum inum,
                        &X_SEARCH(KEY_TYPE_XATTR_INDEX_POSIX_ACL_ACCESS, "", 0),
                        BTREE_ITER_INTENT);
        if (ret)
-               return ret == -ENOENT ? 0 : ret;
+               return bch2_err_matches(ret, ENOENT) ? 0 : ret;
 
        k = bch2_btree_iter_peek_slot(&iter);
        xattr = bkey_s_c_to_xattr(k);
        if (ret)
                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));
        ret = PTR_ERR_OR_ZERO(acl);
        if (IS_ERR_OR_NULL(acl))
                goto err;
 
-       ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
+       ret = allocate_dropping_locks_errcode(trans,
+                               __posix_acl_chmod(&acl, _gfp, mode));
        if (ret)
                goto err;