X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cmd_migrate.c;h=8cf7c9840e461997c253250485b414e70712c8d5;hb=b0c9ad15f4e5cee60973a8f5f6dc49acfeec9755;hp=bde7288b9cb830621f2fa794c1ec3f92b268484f;hpb=ad031731727d4239351afeebf675f069a289beb3;p=bcachefs-tools-debian diff --git a/cmd_migrate.c b/cmd_migrate.c index bde7288..8cf7c98 100644 --- a/cmd_migrate.c +++ b/cmd_migrate.c @@ -30,6 +30,7 @@ #include "libbcachefs/btree_update.h" #include "libbcachefs/buckets.h" #include "libbcachefs/dirent.h" +#include "libbcachefs/errcode.h" #include "libbcachefs/fs-common.h" #include "libbcachefs/inode.h" #include "libbcachefs/io.h" @@ -122,12 +123,12 @@ static void update_inode(struct bch_fs *c, struct bkey_inode_buf packed; int ret; - bch2_inode_pack(c, &packed, inode); + bch2_inode_pack(&packed, inode); packed.inode.k.p.snapshot = U32_MAX; ret = bch2_btree_insert(c, BTREE_ID_inodes, &packed.inode.k_i, NULL, NULL, 0); if (ret) - die("error updating inode: %s", strerror(-ret)); + die("error updating inode: %s", bch2_err_str(ret)); } static void create_link(struct bch_fs *c, @@ -143,7 +144,7 @@ static void create_link(struct bch_fs *c, (subvol_inum) { 1, parent->bi_inum }, &parent_u, (subvol_inum) { 1, inum }, &inode, &qstr)); if (ret) - die("error creating hardlink: %s", strerror(-ret)); + die("error creating hardlink: %s", bch2_err_str(ret)); } static struct bch_inode_unpacked create_file(struct bch_fs *c, @@ -164,7 +165,7 @@ static struct bch_inode_unpacked create_file(struct bch_fs *c, uid, gid, mode, rdev, NULL, NULL, (subvol_inum) {}, 0)); if (ret) - die("error creating %s: %s", name, strerror(-ret)); + die("error creating %s: %s", name, bch2_err_str(ret)); return new_inode; } @@ -235,7 +236,7 @@ static void copy_xattrs(struct bch_fs *c, struct bch_inode_unpacked *dst, &hash_info, attr, val, val_size, h->flags, 0)); if (ret < 0) - die("error creating xattr: %s", strerror(-ret)); + die("error creating xattr: %s", bch2_err_str(ret)); } } @@ -257,7 +258,7 @@ static void write_data(struct bch_fs *c, closure_init_stack(&cl); - bio_init(&op.wbio.bio, bv, ARRAY_SIZE(bv)); + bio_init(&op.wbio.bio, NULL, bv, ARRAY_SIZE(bv), 0); bch2_bio_map(&op.wbio.bio, buf, len); bch2_write_op_init(&op, c, bch2_opts_to_inode_opts(c->opts)); @@ -265,14 +266,14 @@ static void write_data(struct bch_fs *c, op.nr_replicas = 1; op.subvol = 1; op.pos = SPOS(dst_inode->bi_inum, dst_offset >> 9, U32_MAX); + op.flags |= BCH_WRITE_SYNC; int ret = bch2_disk_reservation_get(c, &op.res, len >> 9, c->opts.data_replicas, 0); if (ret) - die("error reserving space in new filesystem: %s", strerror(-ret)); + die("error reserving space in new filesystem: %s", bch2_err_str(ret)); closure_call(&op.cl, bch2_write, NULL, &cl); - closure_sync(&cl); dst_inode->bi_sectors += len >> 9; } @@ -310,7 +311,7 @@ static void link_data(struct bch_fs *c, struct bch_inode_unpacked *dst, while (length) { struct bkey_i_extent *e; - __BKEY_PADDED(k, BKEY_EXTENT_VAL_U64s_MAX) k; + BKEY_PADDED_ONSTACK(k, BKEY_EXTENT_VAL_U64s_MAX) k; u64 b = sector_to_bucket(ca, physical); struct disk_reservation res; unsigned sectors; @@ -328,19 +329,19 @@ static void link_data(struct bch_fs *c, struct bch_inode_unpacked *dst, bch2_bkey_append_ptr(&e->k_i, (struct bch_extent_ptr) { .offset = physical, .dev = 0, - .gen = bucket(ca, b)->mark.gen, + .gen = *bucket_gen(ca, b), }); ret = bch2_disk_reservation_get(c, &res, sectors, 1, BCH_DISK_RESERVATION_NOFAIL); if (ret) die("error reserving space in new filesystem: %s", - strerror(-ret)); + bch2_err_str(ret)); ret = bch2_btree_insert(c, BTREE_ID_extents, &e->k_i, &res, NULL, 0); if (ret) - die("btree insert error %s", strerror(-ret)); + die("btree insert error %s", bch2_err_str(ret)); bch2_disk_reservation_put(c, &res); @@ -530,7 +531,7 @@ static ranges reserve_new_fs_space(const char *file_path, unsigned block_size, struct fiemap_iter iter; struct fiemap_extent e; - ranges extents = { NULL }; + ranges extents = { 0 }; fiemap_for_each(fd, iter, e) { if (e.fe_flags & (FIEMAP_EXTENT_UNKNOWN| @@ -581,7 +582,7 @@ static void copy_fs(struct bch_fs *c, int src_fd, const char *src_path, 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)); + die("error looking up root directory: %s", bch2_err_str(ret)); if (fchdir(src_fd)) die("chdir error: %m"); @@ -603,10 +604,8 @@ static void copy_fs(struct bch_fs *c, int src_fd, const char *src_path, update_inode(c, &root_inode); - darray_free(s.extents); + darray_exit(&s.extents); genradix_free(&s.hardlinks); - - bch2_alloc_write_all(c, false); } static void find_superblock_space(ranges extents, @@ -615,7 +614,7 @@ static void find_superblock_space(ranges extents, { struct range *i; - darray_foreach(i, extents) { + darray_for_each(extents, i) { u64 start = round_up(max(256ULL << 10, i->start), dev->bucket_size << 9); u64 end = round_down(i->end, @@ -643,7 +642,7 @@ static void migrate_usage(void) " --no_passphrase Don't encrypt master encryption key\n" " -F Force, even if metadata file already exists\n" " -h Display this help and exit\n" - "Report bugs to "); + "Report bugs to "); } static const struct option migrate_opts[] = { @@ -693,7 +692,7 @@ static int migrate_fs(const char *fs_path, u64 sb_offset = le64_to_cpu(sb->layout.sb_offset[0]); if (format_opts.passphrase) - bch2_add_key(sb, format_opts.passphrase); + bch2_add_key(sb, "user", "user", format_opts.passphrase); free(sb); @@ -704,16 +703,17 @@ static int migrate_fs(const char *fs_path, opt_set(opts, sb, sb_offset); opt_set(opts, nostart, true); opt_set(opts, noexcl, true); + opt_set(opts, buckets_nouse, true); c = bch2_fs_open(path, 1, opts); if (IS_ERR(c)) - die("Error opening new filesystem: %s", strerror(-PTR_ERR(c))); + die("Error opening new filesystem: %s", bch2_err_str(PTR_ERR(c))); mark_unreserved_space(c, extents); int ret = bch2_fs_start(c); if (ret) - die("Error starting new filesystem: %s", strerror(-ret)); + die("Error starting new filesystem: %s", bch2_err_str(ret)); copy_fs(c, fs_fd, fs_path, bcachefs_inum, &extents); @@ -725,7 +725,7 @@ static int migrate_fs(const char *fs_path, c = bch2_fs_open(path, 1, opts); if (IS_ERR(c)) - die("Error opening new filesystem: %s", strerror(-PTR_ERR(c))); + die("Error opening new filesystem: %s", bch2_err_str(PTR_ERR(c))); bch2_fs_stop(c); printf("fsck complete\n"); @@ -800,7 +800,7 @@ static void migrate_superblock_usage(void) " -d device Device to create superblock for\n" " -o offset Offset of existing superblock\n" " -h Display this help and exit\n" - "Report bugs to "); + "Report bugs to "); } int cmd_migrate_superblock(int argc, char *argv[])