]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/fs-common.c
Update bcachefs sources to 5e392aed7a bcachefs: Kill bch2_alloc_write()
[bcachefs-tools-debian] / libbcachefs / fs-common.c
index 3e8e3c5bf87038db8252608b80a200116ec74080..d543480be111796702d9f5c5f2ced168f4815e16 100644 (file)
@@ -67,26 +67,14 @@ int bch2_create_trans(struct btree_trans *trans,
 
                if (!snapshot_src.inum) {
                        /* Inode wasn't specified, just snapshot: */
-                       struct btree_iter subvol_iter;
-                       struct bkey_s_c k;
-
-                       bch2_trans_iter_init(trans, &subvol_iter, BTREE_ID_subvolumes,
-                                            POS(0, snapshot_src.subvol), 0);
-                       k = bch2_btree_iter_peek_slot(&subvol_iter);
-
-                       ret = bkey_err(k);
-                       if (!ret && k.k->type != KEY_TYPE_subvolume) {
-                               bch_err(c, "subvolume %u not found",
-                                       snapshot_src.subvol);
-                               ret = -ENOENT;
-                       }
-
-                       if (!ret)
-                               snapshot_src.inum = le64_to_cpu(bkey_s_c_to_subvolume(k).v->inode);
-                       bch2_trans_iter_exit(trans, &subvol_iter);
+                       struct bch_subvolume s;
 
+                       ret = bch2_subvolume_get(trans, snapshot_src.subvol, true,
+                                                BTREE_ITER_CACHED, &s);
                        if (ret)
                                goto err;
+
+                       snapshot_src.inum = le64_to_cpu(s.inode);
                }
 
                ret = bch2_inode_peek(trans, &inode_iter, new_inode, snapshot_src,
@@ -251,7 +239,7 @@ int bch2_unlink_trans(struct btree_trans *trans,
                      struct bch_inode_unpacked *dir_u,
                      struct bch_inode_unpacked *inode_u,
                      const struct qstr *name,
-                     int deleting_snapshot)
+                     bool deleting_snapshot)
 {
        struct bch_fs *c = trans->c;
        struct btree_iter dir_iter = { NULL };
@@ -279,20 +267,19 @@ int bch2_unlink_trans(struct btree_trans *trans,
        if (ret)
                goto err;
 
-       if (deleting_snapshot == 1 && !inode_u->bi_subvol) {
-               ret = -ENOENT;
-               goto err;
-       }
-
-       if (deleting_snapshot <= 0 && S_ISDIR(inode_u->bi_mode)) {
+       if (!deleting_snapshot && S_ISDIR(inode_u->bi_mode)) {
                ret = bch2_empty_dir_trans(trans, inum);
                if (ret)
                        goto err;
        }
 
-       if (inode_u->bi_subvol) {
-               ret = bch2_subvolume_delete(trans, inode_u->bi_subvol,
-                                           deleting_snapshot);
+       if (deleting_snapshot && !inode_u->bi_subvol) {
+               ret = -ENOENT;
+               goto err;
+       }
+
+       if (deleting_snapshot || inode_u->bi_subvol) {
+               ret = bch2_subvolume_unlink(trans, inode_u->bi_subvol);
                if (ret)
                        goto err;
 
@@ -309,6 +296,8 @@ int bch2_unlink_trans(struct btree_trans *trans,
                ret = bch2_btree_iter_traverse(&dirent_iter);
                if (ret)
                        goto err;
+       } else {
+               bch2_inode_nlink_dec(inode_u);
        }
 
        if (inode_u->bi_dir             == dirent_iter.pos.inode &&
@@ -319,7 +308,6 @@ int bch2_unlink_trans(struct btree_trans *trans,
 
        dir_u->bi_mtime = dir_u->bi_ctime = inode_u->bi_ctime = now;
        dir_u->bi_nlink -= is_subdir_for_nlink(inode_u);
-       bch2_inode_nlink_dec(inode_u);
 
        ret =   bch2_hash_delete_at(trans, bch2_dirent_hash_desc,
                                    &dir_hash, &dirent_iter,
@@ -341,6 +329,7 @@ bool bch2_reinherit_attrs(struct bch_inode_unpacked *dst_u,
        bool ret = false;
 
        for (id = 0; id < Inode_opt_nr; id++) {
+               /* Skip attributes that were explicitly set on this inode */
                if (dst_u->bi_fields_set & (1 << id))
                        continue;