]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - cmd_device.c
Update bcachefs sources to 7c0fe6f104 bcachefs: Fix bch2_fsck_ask_yn()
[bcachefs-tools-debian] / cmd_device.c
index c5d516bf0cb6113419901bbdd52e545eb2a41197..c59d37094761dccb5d83b9905d34cce451714c75 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "libbcachefs/bcachefs.h"
 #include "libbcachefs/bcachefs_ioctl.h"
+#include "libbcachefs/errcode.h"
 #include "libbcachefs/journal.h"
 #include "libbcachefs/super-io.h"
 #include "cmds.h"
@@ -53,7 +54,7 @@ static void device_add_usage(void)
             "  -f, --force                 Use device even if it appears to already be formatted\n"
             "  -h, --help                  Display this help and exit\n"
             "\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
 }
 
 int cmd_device_add(int argc, char *argv[])
@@ -78,17 +79,15 @@ int cmd_device_add(int argc, char *argv[])
                case 'S':
                        if (bch2_strtoull_h(optarg, &dev_opts.size))
                                die("invalid filesystem size");
-
-                       dev_opts.size >>= 9;
                        break;
                case 'B':
-                       dev_opts.bucket_size =
-                               hatoi_validate(optarg, "bucket size");
+                       if (bch2_strtoull_h(optarg, &dev_opts.bucket_size))
+                               die("bad bucket_size %s", optarg);
                        break;
                case 'D':
                        dev_opts.discard = true;
                        break;
-               case 'g':
+               case 'l':
                        dev_opts.label = strdup(optarg);
                        break;
                case 'f':
@@ -121,9 +120,9 @@ int cmd_device_add(int argc, char *argv[])
        struct bch_opts fs_opts = bch2_parse_opts(fs_opt_strs);
 
        opt_set(fs_opts, block_size,
-               read_file_u64(fs.sysfs_fd, "options/block_size") >> 9);
+               read_file_u64(fs.sysfs_fd, "options/block_size"));
        opt_set(fs_opts, btree_node_size,
-               read_file_u64(fs.sysfs_fd, "options/btree_node_size") >> 9);
+               read_file_u64(fs.sysfs_fd, "options/btree_node_size"));
 
        struct bch_sb *sb = bch2_format(fs_opt_strs,
                                        fs_opts,
@@ -149,7 +148,7 @@ static void device_remove_usage(void)
             "  -F, --force-metadata        Force removal, even if some metadata\n"
             "                              couldn't be migrated\n"
             "  -h, --help                  display this help and exit\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
        exit(EXIT_SUCCESS);
 }
 
@@ -216,7 +215,7 @@ static void device_online_usage(void)
             "Options:\n"
             "  -h, --help                  Display this help and exit\n"
             "\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
 }
 
 int cmd_device_online(int argc, char *argv[])
@@ -253,7 +252,7 @@ static void device_offline_usage(void)
             "  -f, --force                 Force, if data redundancy will be degraded\n"
             "  -h, --help                  Display this help and exit\n"
             "\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
 }
 
 int cmd_device_offline(int argc, char *argv[])
@@ -297,7 +296,7 @@ static void device_evacuate_usage(void)
             "Options:\n"
             "  -h, --help                  Display this help and exit\n"
             "\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
 }
 
 int cmd_device_evacuate(int argc, char *argv[])
@@ -352,7 +351,7 @@ static void device_set_state_usage(void)
             "      --force-if-data-lost    Force, if data will be lost\n"
             "  -o, --offline               Set state of an offline device\n"
             "  -h, --help                  display this help and exit\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
        exit(EXIT_SUCCESS);
 }
 
@@ -412,7 +411,7 @@ int cmd_device_set_state(int argc, char *argv[])
 
                int ret = bch2_read_super(dev_str, &opts, &sb);
                if (ret)
-                       die("error opening %s: %s", dev_str, strerror(-ret));
+                       die("error opening %s: %s", dev_str, bch2_err_str(ret));
 
                struct bch_member *m = bch2_sb_get_members(sb.sb)->members + sb.sb->dev_idx;
 
@@ -420,9 +419,12 @@ int cmd_device_set_state(int argc, char *argv[])
 
                le64_add_cpu(&sb.sb->seq, 1);
 
-               bch2_super_write(sb.bdev->bd_fd, sb.sb);
+               bch2_super_write(sb.bdev->bd_buffered_fd, sb.sb);
+               ret = fsync(sb.bdev->bd_buffered_fd);
+               if (ret)
+                       fprintf(stderr, "error writing superblock: fsync error (%m)");
                bch2_free_super(&sb);
-               return 0;
+               return ret;
        }
 
        char *fs_path = arg_pop();
@@ -453,7 +455,7 @@ static void device_resize_usage(void)
             "\n"
             "Options:\n"
             "  -h, --help                  display this help and exit\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
        exit(EXIT_SUCCESS);
 }
 
@@ -526,7 +528,7 @@ int cmd_device_resize(int argc, char *argv[])
 
                struct bch_fs *c = bch2_fs_open(&dev, 1, bch2_opts_empty());
                if (IS_ERR(c))
-                       die("error opening %s: %s", dev, strerror(-PTR_ERR(c)));
+                       die("error opening %s: %s", dev, bch2_err_str(PTR_ERR(c)));
 
                struct bch_dev *ca, *resize = NULL;
                unsigned i;
@@ -546,7 +548,7 @@ int cmd_device_resize(int argc, char *argv[])
                printf("resizing %s to %llu buckets\n", dev, nbuckets);
                int ret = bch2_dev_resize(c, resize, nbuckets);
                if (ret)
-                       fprintf(stderr, "resize error: %s\n", strerror(-ret));
+                       fprintf(stderr, "resize error: %s\n", bch2_err_str(ret));
 
                percpu_ref_put(&resize->io_ref);
                bch2_fs_stop(c);
@@ -561,7 +563,7 @@ static void device_resize_journal_usage(void)
             "\n"
             "Options:\n"
             "  -h, --help                  display this help and exit\n"
-            "Report bugs to <linux-bcache@vger.kernel.org>");
+            "Report bugs to <linux-bcachefs@vger.kernel.org>");
        exit(EXIT_SUCCESS);
 }
 
@@ -629,7 +631,7 @@ int cmd_device_resize_journal(int argc, char *argv[])
 
                struct bch_fs *c = bch2_fs_open(&dev, 1, bch2_opts_empty());
                if (IS_ERR(c))
-                       die("error opening %s: %s", dev, strerror(-PTR_ERR(c)));
+                       die("error opening %s: %s", dev, bch2_err_str(PTR_ERR(c)));
 
                struct bch_dev *ca, *resize = NULL;
                unsigned i;
@@ -646,7 +648,7 @@ int cmd_device_resize_journal(int argc, char *argv[])
                printf("resizing journal on %s to %llu buckets\n", dev, nbuckets);
                int ret = bch2_set_nr_journal_buckets(c, resize, nbuckets);
                if (ret)
-                       fprintf(stderr, "resize error: %s\n", strerror(-ret));
+                       fprintf(stderr, "resize error: %s\n", bch2_err_str(ret));
 
                percpu_ref_put(&resize->io_ref);
                bch2_fs_stop(c);