]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/fs-common.c
Update bcachefs sources to 95ff72a6c1 fixup! mm: Centralize & improve oom reporting...
[bcachefs-tools-debian] / libbcachefs / fs-common.c
index c49de741e1e3b156bf603b33a8d74eafdb879262..53ffc684223cf30486693f615b6de27054de347b 100644 (file)
@@ -204,7 +204,9 @@ int bch2_link_trans(struct btree_trans *trans,
                goto err;
 
        inode_u->bi_ctime = now;
-       bch2_inode_nlink_inc(inode_u);
+       ret = bch2_inode_nlink_inc(inode_u);
+       if (ret)
+               return ret;
 
        ret = bch2_inode_peek(trans, &dir_iter, dir_u, dir, BTREE_ITER_INTENT);
        if (ret)
@@ -239,7 +241,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 };
@@ -267,35 +269,19 @@ int bch2_unlink_trans(struct btree_trans *trans,
        if (ret)
                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 (deleting_snapshot < 0 &&
-           inode_u->bi_subvol) {
-               struct bch_subvolume s;
-
-               ret = bch2_subvolume_get(trans, inode_u->bi_subvol, true,
-                                        BTREE_ITER_CACHED|
-                                        BTREE_ITER_WITH_UPDATES,
-                                        &s);
-               if (ret)
-                       goto err;
-
-               if (BCH_SUBVOLUME_SNAP(&s))
-                       deleting_snapshot = 1;
+       if (deleting_snapshot && !inode_u->bi_subvol) {
+               ret = -ENOENT;
+               goto err;
        }
 
-       if (deleting_snapshot == 1) {
-               if (!inode_u->bi_subvol) {
-                       ret = -ENOENT;
-                       goto err;
-               }
-
-               ret = bch2_subvolume_delete(trans, inode_u->bi_subvol,
-                                           deleting_snapshot);
+       if (deleting_snapshot || inode_u->bi_subvol) {
+               ret = bch2_subvolume_unlink(trans, inode_u->bi_subvol);
                if (ret)
                        goto err;
 
@@ -313,7 +299,7 @@ int bch2_unlink_trans(struct btree_trans *trans,
                if (ret)
                        goto err;
        } else {
-               bch2_inode_nlink_dec(inode_u);
+               bch2_inode_nlink_dec(trans, inode_u);
        }
 
        if (inode_u->bi_dir             == dirent_iter.pos.inode &&
@@ -345,6 +331,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;
 
@@ -477,7 +464,7 @@ int bch2_rename_trans(struct btree_trans *trans,
        }
 
        if (mode == BCH_RENAME_OVERWRITE)
-               bch2_inode_nlink_dec(dst_inode_u);
+               bch2_inode_nlink_dec(trans, dst_inode_u);
 
        src_dir_u->bi_mtime             = now;
        src_dir_u->bi_ctime             = now;