]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - cmd_device.c
Fix build against musl libc.
[bcachefs-tools-debian] / cmd_device.c
index 1d91ecdd99f23d3e17f6b162aa182d70253f9f6b..e3c5d513bf3026111ca5c49d68a1744041326172 100644 (file)
@@ -49,11 +49,11 @@ static void device_add_usage(void)
             "  -S, --fs_size=size          Size of filesystem on device\n"
             "  -B, --bucket=size           Bucket size\n"
             "  -D, --discard               Enable discards\n"
-            "  -g, --group=group           Disk group\n"
+            "  -l, --label=label           Disk label\n"
             "  -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[])
@@ -62,7 +62,7 @@ int cmd_device_add(int argc, char *argv[])
                { "fs_size",            required_argument,      NULL, 'S' },
                { "bucket",             required_argument,      NULL, 'B' },
                { "discard",            no_argument,            NULL, 'D' },
-               { "group",              required_argument,      NULL, 'g' },
+               { "label",              required_argument,      NULL, 'l' },
                { "force",              no_argument,            NULL, 'f' },
                { "help",               no_argument,            NULL, 'h' },
                { NULL }
@@ -78,18 +78,16 @@ 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':
-                       dev_opts.group = strdup(optarg);
+               case 'l':
+                       dev_opts.label = strdup(optarg);
                        break;
                case 'f':
                        force = true;
@@ -104,8 +102,8 @@ int cmd_device_add(int argc, char *argv[])
        if (!fs_path)
                die("Please supply a filesystem");
 
-       char *dev_path = arg_pop();
-       if (!dev_path)
+       dev_opts.path = arg_pop();
+       if (!dev_opts.path)
                die("Please supply a device");
 
        if (argc)
@@ -113,7 +111,6 @@ int cmd_device_add(int argc, char *argv[])
 
        struct bchfs_handle fs = bcache_fs_open(fs_path);
 
-       dev_opts.path = dev_path;
        dev_opts.fd = open_for_format(dev_opts.path, force);
 
        struct bch_opt_strs fs_opt_strs;
@@ -122,9 +119,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, "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, "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,
@@ -150,7 +147,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);
 }
 
@@ -217,7 +214,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[])
@@ -254,7 +251,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[])
@@ -298,7 +295,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[])
@@ -353,7 +350,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);
 }
 
@@ -421,9 +418,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();
@@ -454,7 +454,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);
 }
 
@@ -562,7 +562,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);
 }