From c11874ae81ac93a5a60316a138f55bb1eae153eb Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Thu, 29 Oct 2020 16:17:36 -0700 Subject: [PATCH] btrfs-progs: rescue: add create-control-device subcommand Add a new subcommand 'btrfs rescue create-control-device' that creates /dev/btrfs-control. This is helpful on systems that may not have `mknod` installed and the device node is missing for some reason. Issue: #223 Reviewed-by: Josef Bacik Signed-off-by: Daniel Xu [ update docs ] Signed-off-by: David Sterba --- Documentation/btrfs-man5.asciidoc | 18 +++++++++++++++--- btrfs-completion | 2 +- cmds/rescue.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Documentation/btrfs-man5.asciidoc b/Documentation/btrfs-man5.asciidoc index e5edbe53..80d323f6 100644 --- a/Documentation/btrfs-man5.asciidoc +++ b/Documentation/btrfs-man5.asciidoc @@ -920,16 +920,28 @@ filesystem module: for a given filesystem * get the supported features (can be also found under '/sys/fs/btrfs/features') -The device is usually created by a system device node manager (eg. udev), but -can be created manually: +The device is created when btrfs is initialized, either as a module or a +built-in functionality and makes sense only in connection with that. Running +eg. mkfs without the module loaded will not register the device and will +probably warn about that. + +In rare cases when the module is loaded but the device is not present (most +likely accidentally deleted), it's possible to recreate it by -------------------- # mknod --mode=600 /dev/btrfs-control c 10 234 -------------------- +or (since 5.11) by a convenience command + +-------------------- +# btrfs rescue create-control-device +-------------------- + The control device is not strictly required but the device scanning will not work and a workaround would need to be used to mount a multi-device filesystem. -The mount option 'device' can trigger the device scanning during mount. +The mount option 'device' can trigger the device scanning during mount, see +also *btrfs device scan*. FILESYSTEM WITH MULTIPLE PROFILES diff --git a/btrfs-completion b/btrfs-completion index 6ae57d1b..5bbd5378 100644 --- a/btrfs-completion +++ b/btrfs-completion @@ -28,7 +28,7 @@ _btrfs() commands_balance='start pause cancel resume status' commands_device='scan add delete remove ready stats usage' commands_scrub='start cancel resume status' - commands_rescue='chunk-recover super-recover zero-log' + commands_rescue='chunk-recover super-recover zero-log create-control-device' commands_inspect_internal='inode-resolve logical-resolve subvolid-resolve rootid min-dev-size dump-tree dump-super tree-stats' commands_property='get set list' commands_quota='enable disable rescan' diff --git a/cmds/rescue.c b/cmds/rescue.c index 100d25f3..5094d8a9 100644 --- a/cmds/rescue.c +++ b/cmds/rescue.c @@ -18,6 +18,7 @@ #include "kerncompat.h" +#include #include #include "kernel-shared/ctree.h" #include "kernel-shared/volumes.h" @@ -264,6 +265,34 @@ out: } static DEFINE_SIMPLE_COMMAND(rescue_fix_device_size, "fix-device-size"); +static const char * const cmd_rescue_create_control_device_usage[] = { + "btrfs rescue create-control-device", + "Create /dev/btrfs-control (see 'CONTROL DEVICE' in btrfs(5))", + NULL +}; + +static int cmd_rescue_create_control_device(const struct cmd_struct *cmd, + int argc, char **argv) +{ + dev_t device; + int ret; + + if (check_argc_exact(argc, 1)) + return 1; + + device = makedev(10, 234); + + ret = mknod("/dev/btrfs-control", S_IFCHR | S_IRUSR | S_IWUSR, device); + if (ret) { + error("could not create /dev/btrfs-control: %m"); + return 1; + } + + return 0; + +} +static DEFINE_SIMPLE_COMMAND(rescue_create_control_device, "create-control-device"); + static const char rescue_cmd_group_info[] = "toolbox for specific rescue operations"; @@ -273,6 +302,7 @@ static const struct cmd_group rescue_cmd_group = { &cmd_struct_rescue_super_recover, &cmd_struct_rescue_zero_log, &cmd_struct_rescue_fix_device_size, + &cmd_struct_rescue_create_control_device, NULL } };