]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - cmd_migrate.c
add overlay
[bcachefs-tools-debian] / cmd_migrate.c
index 40d72671d46a686a49575201129f5d2fb67ff37d..41cfe5d9ab4d9d9567bfe098ac56cd4a93030c23 100644 (file)
@@ -123,7 +123,7 @@ static void update_inode(struct bch_fs *c,
        int ret;
 
        bch2_inode_pack(c, &packed, inode);
-       ret = bch2_btree_insert(c, BTREE_ID_INODES, &packed.inode.k_i,
+       ret = bch2_btree_insert(c, BTREE_ID_inodes, &packed.inode.k_i,
                                NULL, NULL, 0);
        if (ret)
                die("error updating inode: %s", strerror(-ret));
@@ -138,8 +138,9 @@ static void create_link(struct bch_fs *c,
        struct bch_inode_unpacked inode;
 
        int ret = bch2_trans_do(c, NULL, NULL, 0,
-               bch2_link_trans(&trans, parent->bi_inum, inum,
-                               &parent_u, &inode, &qstr));
+               bch2_link_trans(&trans,
+                               (subvol_inum) { 1, parent->bi_inum }, &parent_u,
+                               (subvol_inum) { 1, inum }, &inode, &qstr));
        if (ret)
                die("error creating hardlink: %s", strerror(-ret));
 }
@@ -155,9 +156,10 @@ static struct bch_inode_unpacked create_file(struct bch_fs *c,
 
        int ret = bch2_trans_do(c, NULL, NULL, 0,
                bch2_create_trans(&trans,
-                                 parent->bi_inum, parent,
+                                 (subvol_inum) { 1, parent->bi_inum }, parent,
                                  &new_inode, &qstr,
-                                 uid, gid, mode, rdev, NULL, NULL));
+                                 uid, gid, mode, rdev, NULL, NULL,
+                                 (subvol_inum) {}, 0));
        if (ret)
                die("error creating file: %s", strerror(-ret));
 
@@ -225,7 +227,9 @@ static void copy_xattrs(struct bch_fs *c, struct bch_inode_unpacked *dst,
                const struct xattr_handler *h = xattr_resolve_name(&attr);
 
                int ret = bch2_trans_do(c, NULL, NULL, 0,
-                               bch2_xattr_set(&trans, dst->bi_inum, &hash_info, attr,
+                               bch2_xattr_set(&trans,
+                                              (subvol_inum) { 1, dst->bi_inum },
+                                              &hash_info, attr,
                                               val, val_size, h->flags, 0));
                if (ret < 0)
                        die("error creating xattr: %s", strerror(-ret));
@@ -329,7 +333,7 @@ static void link_data(struct bch_fs *c, struct bch_inode_unpacked *dst,
 
                bch2_mark_bkey_replicas(c, extent_i_to_s_c(e).s_c);
 
-               ret = bch2_btree_insert(c, BTREE_ID_EXTENTS, &e->k_i,
+               ret = bch2_btree_insert(c, BTREE_ID_extents, &e->k_i,
                                        &res, NULL, 0);
                if (ret)
                        die("btree insert error %s", strerror(-ret));
@@ -569,7 +573,8 @@ static void copy_fs(struct bch_fs *c, int src_fd, const char *src_path,
        syncfs(src_fd);
 
        struct bch_inode_unpacked root_inode;
-       int ret = bch2_inode_find_by_inum(c, BCACHEFS_ROOT_INO, &root_inode);
+       int ret = bch2_inode_find_by_inum(c, (subvol_inum) { 1, BCACHEFS_ROOT_INO },
+                                         &root_inode);
        if (ret)
                die("error looking up root directory: %s", strerror(-ret));
 
@@ -599,7 +604,9 @@ static void copy_fs(struct bch_fs *c, int src_fd, const char *src_path,
        bch2_alloc_write(c, false);
 }
 
-static void find_superblock_space(ranges extents, struct dev_opts *dev)
+static void find_superblock_space(ranges extents,
+                                 struct format_opts opts,
+                                 struct dev_opts *dev)
 {
        struct range *i;
 
@@ -609,9 +616,10 @@ static void find_superblock_space(ranges extents, struct dev_opts *dev)
                u64 end = round_down(i->end,
                                     dev->bucket_size << 9);
 
-               if (start + (128 << 10) <= end) {
+               /* Need space for two superblocks: */
+               if (start + (opts.superblock_size << 9) * 2 <= end) {
                        dev->sb_offset  = start >> 9;
-                       dev->sb_end     = dev->sb_offset + 256;
+                       dev->sb_end     = dev->sb_offset + opts.superblock_size * 2;
                        return;
                }
        }
@@ -673,7 +681,7 @@ static int migrate_fs(const char            *fs_path,
                                get_size(dev.path, dev.fd) / 5,
                                &bcachefs_inum, stat.st_dev, force);
 
-       find_superblock_space(extents, &dev);
+       find_superblock_space(extents, format_opts, &dev);
 
        struct bch_sb *sb = bch2_format(fs_opt_strs,
                                        fs_opts,format_opts, &dev, 1);
@@ -770,10 +778,12 @@ int cmd_migrate(int argc, char *argv[])
        if (format_opts.encrypted && !no_passphrase)
                format_opts.passphrase = read_passphrase_twice("Enter passphrase: ");
 
-       return migrate_fs(fs_path,
-                         fs_opt_strs,
-                         fs_opts,
-                         format_opts, force);
+       int ret = migrate_fs(fs_path,
+                            fs_opt_strs,
+                            fs_opts,
+                            format_opts, force);
+       bch2_opt_strs_free(&fs_opt_strs);
+       return ret;
 }
 
 static void migrate_superblock_usage(void)