|
Josef Bacik |
b5e03c |
From 01077c81987011d8a50999824f96032c10b2733b Mon Sep 17 00:00:00 2001
|
|
Josef Bacik |
b5e03c |
From: Josef Bacik <jbacik@fusionio.com>
|
|
Josef Bacik |
b5e03c |
Date: Thu, 21 Jun 2012 16:02:10 -0400
|
|
Josef Bacik |
b5e03c |
Subject: [PATCH 1/3] Btrfs-progs: add btrfs device ready command
|
|
Josef Bacik |
b5e03c |
|
|
Josef Bacik |
b5e03c |
This command will be used by things like dracut that wish to know very
|
|
Josef Bacik |
b5e03c |
simply if all of the devices have been added to the kernel cache yet for the
|
|
Josef Bacik |
b5e03c |
device to be fully mounted. This keeps initrd's from constantly having to
|
|
Josef Bacik |
b5e03c |
try to mount the file system until it succeeds every time a device is added
|
|
Josef Bacik |
b5e03c |
to the system. Thanks,
|
|
Josef Bacik |
b5e03c |
|
|
Josef Bacik |
b5e03c |
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
|
|
Josef Bacik |
b5e03c |
---
|
|
Josef Bacik |
b5e03c |
cmds-device.c | 35 +++++++++++++++++++++++++++++++++++
|
|
Josef Bacik |
b5e03c |
ioctl.h | 2 ++
|
|
Josef Bacik |
b5e03c |
2 files changed, 37 insertions(+), 0 deletions(-)
|
|
Josef Bacik |
b5e03c |
|
|
Josef Bacik |
b5e03c |
diff --git a/cmds-device.c b/cmds-device.c
|
|
Josef Bacik |
b5e03c |
index 771856b..b24e2a3 100644
|
|
Josef Bacik |
b5e03c |
--- a/cmds-device.c
|
|
Josef Bacik |
b5e03c |
+++ b/cmds-device.c
|
|
Josef Bacik |
b5e03c |
@@ -249,11 +249,46 @@ static int cmd_scan_dev(int argc, char **argv)
|
|
Josef Bacik |
b5e03c |
return 0;
|
|
Josef Bacik |
b5e03c |
}
|
|
Josef Bacik |
b5e03c |
|
|
Josef Bacik |
b5e03c |
+static const char * const cmd_ready_dev_usage[] = {
|
|
Josef Bacik |
b5e03c |
+ "btrfs device ready <device>",
|
|
Josef Bacik |
b5e03c |
+ "Check device to see if it has all of it's devices in cache for mounting",
|
|
Josef Bacik |
b5e03c |
+ NULL
|
|
Josef Bacik |
b5e03c |
+};
|
|
Josef Bacik |
b5e03c |
+
|
|
Josef Bacik |
b5e03c |
+static int cmd_ready_dev(int argc, char **argv)
|
|
Josef Bacik |
b5e03c |
+{
|
|
Josef Bacik |
b5e03c |
+ struct btrfs_ioctl_vol_args args;
|
|
Josef Bacik |
b5e03c |
+ int fd;
|
|
Josef Bacik |
b5e03c |
+ int ret;
|
|
Josef Bacik |
b5e03c |
+
|
|
Josef Bacik |
b5e03c |
+ if (check_argc_min(argc, 2))
|
|
Josef Bacik |
b5e03c |
+ usage(cmd_ready_dev_usage);
|
|
Josef Bacik |
b5e03c |
+
|
|
Josef Bacik |
b5e03c |
+ fd = open("/dev/btrfs-control", O_RDWR);
|
|
Josef Bacik |
b5e03c |
+ if (fd < 0) {
|
|
Josef Bacik |
b5e03c |
+ perror("failed to open /dev/btrfs-control");
|
|
Josef Bacik |
b5e03c |
+ return 10;
|
|
Josef Bacik |
b5e03c |
+ }
|
|
Josef Bacik |
b5e03c |
+
|
|
Josef Bacik |
b5e03c |
+ strncpy(args.name, argv[argc - 1], BTRFS_PATH_NAME_MAX);
|
|
Josef Bacik |
b5e03c |
+ ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
|
|
Josef Bacik |
b5e03c |
+ if (ret < 0) {
|
|
Josef Bacik |
b5e03c |
+ fprintf(stderr, "ERROR: unable to determine if the device '%s'"
|
|
Josef Bacik |
b5e03c |
+ " is ready for mounting - %s\n", argv[argc - 1],
|
|
Josef Bacik |
b5e03c |
+ strerror(errno));
|
|
Josef Bacik |
b5e03c |
+ ret = 1;
|
|
Josef Bacik |
b5e03c |
+ }
|
|
Josef Bacik |
b5e03c |
+
|
|
Josef Bacik |
b5e03c |
+ close(fd);
|
|
Josef Bacik |
b5e03c |
+ return ret;
|
|
Josef Bacik |
b5e03c |
+}
|
|
Josef Bacik |
b5e03c |
+
|
|
Josef Bacik |
b5e03c |
const struct cmd_group device_cmd_group = {
|
|
Josef Bacik |
b5e03c |
device_cmd_group_usage, NULL, {
|
|
Josef Bacik |
b5e03c |
{ "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 },
|
|
Josef Bacik |
b5e03c |
{ "delete", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 },
|
|
Josef Bacik |
b5e03c |
{ "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 },
|
|
Josef Bacik |
b5e03c |
+ { "ready", cmd_ready_dev, cmd_ready_dev_usage, NULL, 0 },
|
|
Josef Bacik |
b5e03c |
{ 0, 0, 0, 0, 0 }
|
|
Josef Bacik |
b5e03c |
}
|
|
Josef Bacik |
b5e03c |
};
|
|
Josef Bacik |
b5e03c |
diff --git a/ioctl.h b/ioctl.h
|
|
Josef Bacik |
b5e03c |
index d6f3d07..30220ad 100644
|
|
Josef Bacik |
b5e03c |
--- a/ioctl.h
|
|
Josef Bacik |
b5e03c |
+++ b/ioctl.h
|
|
Josef Bacik |
b5e03c |
@@ -365,6 +365,8 @@ struct btrfs_ioctl_clone_range_args {
|
|
Josef Bacik |
b5e03c |
struct btrfs_ioctl_ino_path_args)
|
|
Josef Bacik |
b5e03c |
#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
|
|
Josef Bacik |
b5e03c |
struct btrfs_ioctl_ino_path_args)
|
|
Josef Bacik |
b5e03c |
+#define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
|
|
Josef Bacik |
b5e03c |
+ struct btrfs_ioctl_vol_args)
|
|
Josef Bacik |
b5e03c |
|
|
Josef Bacik |
b5e03c |
#define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
|
|
Josef Bacik |
b5e03c |
struct btrfs_ioctl_received_subvol_args)
|
|
Josef Bacik |
b5e03c |
--
|
|
Josef Bacik |
b5e03c |
1.7.7.6
|
|
Josef Bacik |
b5e03c |
|