Skip to contentSkip to conversation

btrfs-progs: rescue: Add create-control-device subcommand

PATCH In review Daniel Xu 3 participants 7 messages Oct 29, 2020 – Feb 19, 2021

Subsystems (2)
lore
Share & tools
lore

Daniel Xu

author
#0 lore raw

cover btrfs-progs: rescue: Add create-control-device subcommand

This patchset adds a new btrfs rescue create-control-device subcommand that acts as a convenient way to invoke:

	# mknod --mode=600 c 10 234 /dev/btrfs-control

on systems that don't have mknod installed or when you're lazy.

Daniel Xu (3):
btrfs-progs: rescue: Add create-control-device subcommand
btrfs-progs: bash: Update completion script with create-control-device
btrfs-progs: rescue: Update docs with create-control-device

 Documentation/btrfs-man5.asciidoc   |  8 ++++++-
 Documentation/btrfs-rescue.asciidoc |  5 +++++
 btrfs-completion                    |  2 +-
 cmds/rescue.c                       | 35 +++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 2 deletions(-)

--
2.26.2

author
#1 lore raw

PATCH 1/3 btrfs-progs: rescue: Add create-control-device subcommand

This commit adds a new btrfs rescue create-control-device subcommand that creats /dev/btrfs-control. This is helpful on systems that may not have mknod installed.

---
 cmds/rescue.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
cmds/rescue.c +35 -0
index 100d25f3..e6972fb7 100644
@@ -18,6 +18,12 @@
 
 #include "kerncompat.h"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #include <getopt.h>
 #include "kernel-shared/ctree.h"
 #include "kernel-shared/volumes.h"
@@ -264,6 +270,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 +307,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
 	}
 };
Signature · 1 line
2.26.2
author
#4 lore raw

PATCH 3/3 btrfs-progs: rescue: Update docs with create-control-device

In reply to Daniel Xu

This commit updates the documentation for the new btrfs rescue create-control-device subcommand.

---
 Documentation/btrfs-man5.asciidoc   | 8 +++++++-
 Documentation/btrfs-rescue.asciidoc | 5 +++++
 2 files changed, 12 insertions(+), 1 deletion(-)
Documentation/btrfs-man5.asciidoc +7 -1
index 65352009..082599c1 100644
@@ -898,12 +898,18 @@ filesystem module:
 * 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:
+can be created manually with:
 
 --------------------
 # mknod --mode=600 c 10 234 /dev/btrfs-control
 --------------------
 
+or with:
+
+--------------------
+# 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.
Documentation/btrfs-rescue.asciidoc +5 -0
index af544372..db40ce64 100644
@@ -93,6 +93,11 @@ the log and the filesystem may be mounted normally again. The keywords to look
 for are 'open_ctree' which says that it's during mount and function names
 that contain 'replay', 'recover' or 'log_tree'.
 
+*create-control-device* ::
+Creates /dev/btrfs-control control device
++
+This command is for convenience when *mknod* is not installed on a system.
+
 EXIT STATUS
 -----------
 *btrfs rescue* returns a zero exit status if it succeeds. Non zero is
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH 2/3 btrfs-progs: bash: Update completion script with create-control-device

In reply to Daniel Xu

The previous commit added a new subcommand so in this commit we update the bash completion script.

---
 btrfs-completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
btrfs-completion +1 -1
index 6ae57d1b..5bbd5378 100644
@@ -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'
Signature · 1 line
2.26.2
#6 lore raw
In reply to Daniel Xu
Quoted 6 lines · Daniel Xu

This patchset adds a new btrfs rescue create-control-device subcommand that acts as a convenient way to invoke:

	# mknod --mode=600 c 10 234 /dev/btrfs-control

on systems that don't have mknod installed or when you're lazy.

Well, I don't think the part 'lazy' applies.

The whole thing with the control device is simpler that I originally thought. On a system without loaded btrfs module there's no /dev/btrfs-control. This is correct because the device node is created at load time or when btrfs_interface_init is called.

Creating just the device node makes no sense because there's nothing handling it. Once module is loaded it appears and works as expected.

The only case where the rescue command makes sense is when the module is loaded, device node creatd and then manually deleted. This is possible but highly unlikely. For that reason the rescue command still has some sense but the reasoning needs to reflect how it's related to the module status.

As this is docs update only, I'll fix that myself, no need to resend.