]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/acl.c
Update bcachefs sources to 6a3927a96b fixup! bcachefs: Don't use write side of mark_l...
[bcachefs-tools-debian] / libbcachefs / acl.c
index 5dd666ec42d271ef23e4852bd63730139f251d6f..0f2d7437c740344e3191ee83041e3bc62d6c2be1 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 #ifdef CONFIG_BCACHEFS_POSIX_ACL
 
 #include "bcachefs.h"
@@ -23,9 +24,9 @@ static inline int acl_to_xattr_type(int type)
 {
        switch (type) {
        case ACL_TYPE_ACCESS:
-               return BCH_XATTR_INDEX_POSIX_ACL_ACCESS;
+               return KEY_TYPE_XATTR_INDEX_POSIX_ACL_ACCESS;
        case ACL_TYPE_DEFAULT:
-               return BCH_XATTR_INDEX_POSIX_ACL_DEFAULT;
+               return KEY_TYPE_XATTR_INDEX_POSIX_ACL_DEFAULT;
        default:
                BUG();
        }
@@ -215,17 +216,18 @@ struct posix_acl *bch2_get_acl(struct inode *vinode, int type)
 {
        struct bch_inode_info *inode = to_bch_ei(vinode);
        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;
        struct btree_iter *iter;
        struct bkey_s_c_xattr xattr;
        struct posix_acl *acl = NULL;
 
-       bch2_trans_init(&trans, c);
+       bch2_trans_init(&trans, c, 0, 0);
 retry:
        bch2_trans_begin(&trans);
 
        iter = bch2_hash_lookup(&trans, bch2_xattr_hash_desc,
-                       &inode->ei_str_hash, inode->v.i_ino,
+                       &hash, inode->v.i_ino,
                        &X_SEARCH(acl_to_xattr_type(type), "", 0),
                        0);
        if (IS_ERR(iter)) {
@@ -238,12 +240,12 @@ retry:
        }
 
        xattr = bkey_s_c_to_xattr(bch2_btree_iter_peek_slot(iter));
-
        acl = bch2_acl_from_disk(xattr_val(xattr.v),
                        le16_to_cpu(xattr.v->x_val_len));
 
        if (!IS_ERR(acl))
                set_cached_acl(&inode->v, type, acl);
+       bch2_trans_iter_put(&trans, iter);
 out:
        bch2_trans_exit(&trans);
        return acl;
@@ -266,8 +268,8 @@ int bch2_set_acl_trans(struct btree_trans *trans,
                if (IS_ERR(xattr))
                        return PTR_ERR(xattr);
 
-               ret = __bch2_hash_set(trans, bch2_xattr_hash_desc, hash_info,
-                                     inode_u->bi_inum, &xattr->k_i, 0);
+               ret = bch2_hash_set(trans, bch2_xattr_hash_desc, hash_info,
+                                   inode_u->bi_inum, &xattr->k_i, 0);
        } else {
                struct xattr_search_key search =
                        X_SEARCH(acl_to_xattr_type(type), "", 0);
@@ -279,49 +281,54 @@ int bch2_set_acl_trans(struct btree_trans *trans,
        return ret == -ENOENT ? 0 : ret;
 }
 
-static int inode_update_for_set_acl_fn(struct bch_inode_info *inode,
-                                      struct bch_inode_unpacked *bi,
-                                      void *p)
-{
-       struct bch_fs *c = inode->v.i_sb->s_fs_info;
-       umode_t mode = (unsigned long) p;
-
-       bi->bi_ctime    = bch2_current_time(c);
-       bi->bi_mode     = mode;
-       return 0;
-}
-
-int bch2_set_acl(struct inode *vinode, struct posix_acl *acl, int type)
+int bch2_set_acl(struct inode *vinode, struct posix_acl *_acl, int type)
 {
        struct bch_inode_info *inode = to_bch_ei(vinode);
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
        struct btree_trans trans;
+       struct btree_iter *inode_iter;
        struct bch_inode_unpacked inode_u;
-       umode_t mode = inode->v.i_mode;
+       struct bch_hash_info hash_info;
+       struct posix_acl *acl;
+       umode_t mode;
        int ret;
 
        mutex_lock(&inode->ei_update_lock);
-       bch2_trans_init(&trans, c);
+       bch2_trans_init(&trans, c, 0, 0);
+retry:
+       bch2_trans_begin(&trans);
+       acl = _acl;
+
+       inode_iter = bch2_inode_peek(&trans, &inode_u, inode->v.i_ino,
+                                    BTREE_ITER_INTENT);
+       ret = PTR_ERR_OR_ZERO(inode_iter);
+       if (ret)
+               goto btree_err;
+
+       mode = inode_u.bi_mode;
 
-       if (type == ACL_TYPE_ACCESS && acl) {
+       if (type == ACL_TYPE_ACCESS) {
                ret = posix_acl_update_mode(&inode->v, &mode, &acl);
                if (ret)
-                       goto err;
+                       goto btree_err;
        }
-retry:
-       bch2_trans_begin(&trans);
 
-       ret   = bch2_set_acl_trans(&trans,
-                                  &inode->ei_inode,
-                                  &inode->ei_str_hash,
-                                  acl, type) ?:
-               bch2_write_inode_trans(&trans, inode, &inode_u,
-                                      inode_update_for_set_acl_fn,
-                                      (void *)(unsigned long) mode) ?:
+       hash_info = bch2_hash_info_init(c, &inode_u);
+
+       ret = bch2_set_acl_trans(&trans, &inode_u, &hash_info, acl, type);
+       if (ret)
+               goto btree_err;
+
+       inode_u.bi_ctime        = bch2_current_time(c);
+       inode_u.bi_mode         = mode;
+
+       ret =   bch2_inode_write(&trans, inode_iter, &inode_u) ?:
                bch2_trans_commit(&trans, NULL,
                                  &inode->ei_journal_seq,
-                                 BTREE_INSERT_ATOMIC|
                                  BTREE_INSERT_NOUNLOCK);
+btree_err:
+       bch2_trans_iter_put(&trans, inode_iter);
+
        if (ret == -EINTR)
                goto retry;
        if (unlikely(ret))
@@ -339,29 +346,31 @@ err:
 }
 
 int bch2_acl_chmod(struct btree_trans *trans,
-                  struct bch_inode_info *inode,
+                  struct bch_inode_unpacked *inode,
                   umode_t mode,
                   struct posix_acl **new_acl)
 {
+       struct bch_hash_info hash_info = bch2_hash_info_init(trans->c, inode);
        struct btree_iter *iter;
        struct bkey_s_c_xattr xattr;
        struct bkey_i_xattr *new;
        struct posix_acl *acl;
-       int ret = 0;
+       int ret;
 
        iter = bch2_hash_lookup(trans, bch2_xattr_hash_desc,
-                       &inode->ei_str_hash, inode->v.i_ino,
-                       &X_SEARCH(BCH_XATTR_INDEX_POSIX_ACL_ACCESS, "", 0),
+                       &hash_info, inode->bi_inum,
+                       &X_SEARCH(KEY_TYPE_XATTR_INDEX_POSIX_ACL_ACCESS, "", 0),
                        BTREE_ITER_INTENT);
-       if (IS_ERR(iter))
-               return PTR_ERR(iter) != -ENOENT ? PTR_ERR(iter) : 0;
+       ret = PTR_ERR_OR_ZERO(iter);
+       if (ret)
+               return ret == -ENOENT ? 0 : ret;
 
        xattr = bkey_s_c_to_xattr(bch2_btree_iter_peek_slot(iter));
-
        acl = bch2_acl_from_disk(xattr_val(xattr.v),
                        le16_to_cpu(xattr.v->x_val_len));
-       if (IS_ERR_OR_NULL(acl))
-               return PTR_ERR(acl);
+       ret = PTR_ERR_OR_ZERO(acl);
+       if (ret || !acl)
+               goto err;
 
        ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
        if (ret)
@@ -373,10 +382,12 @@ int bch2_acl_chmod(struct btree_trans *trans,
                goto err;
        }
 
-       bch2_trans_update(trans, BTREE_INSERT_ENTRY(iter, &new->k_i));
+       new->k.p = iter->pos;
+       bch2_trans_update(trans, iter, &new->k_i, 0);
        *new_acl = acl;
        acl = NULL;
 err:
+       bch2_trans_iter_put(trans, iter);
        kfree(acl);
        return ret;
 }