]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/acl.c
New upstream release
[bcachefs-tools-debian] / libbcachefs / acl.c
index 0f2d7437c740344e3191ee83041e3bc62d6c2be1..eb907e5d33d3fcf364f0f977d390d916336d391d 100644 (file)
@@ -221,6 +221,8 @@ struct posix_acl *bch2_get_acl(struct inode *vinode, int type)
        struct btree_iter *iter;
        struct bkey_s_c_xattr xattr;
        struct posix_acl *acl = NULL;
+       struct bkey_s_c k;
+       int ret;
 
        bch2_trans_init(&trans, c, 0, 0);
 retry:
@@ -239,7 +241,14 @@ retry:
                goto out;
        }
 
-       xattr = bkey_s_c_to_xattr(bch2_btree_iter_peek_slot(iter));
+       k = bch2_btree_iter_peek_slot(iter);
+       ret = bkey_err(k);
+       if (ret) {
+               acl = ERR_PTR(ret);
+               goto out;
+       }
+
+       xattr = bkey_s_c_to_xattr(k);
        acl = bch2_acl_from_disk(xattr_val(xattr.v),
                        le16_to_cpu(xattr.v->x_val_len));
 
@@ -281,7 +290,8 @@ int bch2_set_acl_trans(struct btree_trans *trans,
        return ret == -ENOENT ? 0 : ret;
 }
 
-int bch2_set_acl(struct inode *vinode, struct posix_acl *_acl, int type)
+int bch2_set_acl(struct user_namespace *mnt_userns,
+                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;
@@ -308,7 +318,7 @@ retry:
        mode = inode_u.bi_mode;
 
        if (type == ACL_TYPE_ACCESS) {
-               ret = posix_acl_update_mode(&inode->v, &mode, &acl);
+               ret = posix_acl_update_mode(mnt_userns, &inode->v, &mode, &acl);
                if (ret)
                        goto btree_err;
        }
@@ -324,8 +334,7 @@ retry:
 
        ret =   bch2_inode_write(&trans, inode_iter, &inode_u) ?:
                bch2_trans_commit(&trans, NULL,
-                                 &inode->ei_journal_seq,
-                                 BTREE_INSERT_NOUNLOCK);
+                                 &inode->ei_journal_seq, 0);
 btree_err:
        bch2_trans_iter_put(&trans, inode_iter);
 
@@ -355,6 +364,7 @@ int bch2_acl_chmod(struct btree_trans *trans,
        struct bkey_s_c_xattr xattr;
        struct bkey_i_xattr *new;
        struct posix_acl *acl;
+       struct bkey_s_c k;
        int ret;
 
        iter = bch2_hash_lookup(trans, bch2_xattr_hash_desc,
@@ -365,11 +375,15 @@ int bch2_acl_chmod(struct btree_trans *trans,
        if (ret)
                return ret == -ENOENT ? 0 : ret;
 
-       xattr = bkey_s_c_to_xattr(bch2_btree_iter_peek_slot(iter));
+       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),
                        le16_to_cpu(xattr.v->x_val_len));
        ret = PTR_ERR_OR_ZERO(acl);
-       if (ret || !acl)
+       if (IS_ERR_OR_NULL(acl))
                goto err;
 
        ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
@@ -383,12 +397,13 @@ int bch2_acl_chmod(struct btree_trans *trans,
        }
 
        new->k.p = iter->pos;
-       bch2_trans_update(trans, iter, &new->k_i, 0);
+       ret = bch2_trans_update(trans, iter, &new->k_i, 0);
        *new_acl = acl;
        acl = NULL;
 err:
        bch2_trans_iter_put(trans, iter);
-       kfree(acl);
+       if (!IS_ERR_OR_NULL(acl))
+               kfree(acl);
        return ret;
 }