Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-release-src > by-pkgid > 105d736c57b2691635bd047efe146ef0 > files > 8

btrfs-progs-0.20-0.rc1.20130117.2.mga3.src.rpm

From ce814a93788c3289f50d383ea104fad1f66a16f8 Mon Sep 17 00:00:00 2001
From: Josef Bacik <jbacik@fusionio.com>
Date: Sat, 19 Jan 2013 13:06:20 -0500
Subject: [PATCH] Btrfs-progs: add btrfs device ready command

This command will be used by things like dracut that wish to know very
simply if all of the devices have been added to the kernel cache yet for the
device to be fully mounted.  This keeps initrd's from constantly having to
try to mount the file system until it succeeds every time a device is added
to the system.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
---
 cmds-device.c | 35 +++++++++++++++++++++++++++++++++++
 ioctl.h       |  2 ++
 2 files changed, 37 insertions(+)

diff --git a/cmds-device.c b/cmds-device.c
index 4787aca..75ee293 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -250,11 +250,46 @@ static int cmd_scan_dev(int argc, char **argv)
 	return 0;
 }
 
+static const char * const cmd_ready_dev_usage[] = {
+	"btrfs device ready <device>",
+	"Check device to see if it has all of it's devices in cache for mounting",
+	NULL
+};
+
+static int cmd_ready_dev(int argc, char **argv)
+{
+	struct	btrfs_ioctl_vol_args args;
+	int	fd;
+	int	ret;
+
+	if (check_argc_min(argc, 2))
+		usage(cmd_ready_dev_usage);
+
+	fd = open("/dev/btrfs-control", O_RDWR);
+	if (fd < 0) {
+		perror("failed to open /dev/btrfs-control");
+		return 10;
+	}
+
+	strncpy(args.name, argv[argc - 1], BTRFS_PATH_NAME_MAX);
+	ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: unable to determine if the device '%s'"
+			" is ready for mounting - %s\n", argv[argc - 1],
+			strerror(errno));
+		ret = 1;
+	}
+
+	close(fd);
+	return ret;
+}
+
 const struct cmd_group device_cmd_group = {
 	device_cmd_group_usage, NULL, {
 		{ "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 },
 		{ "delete", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 },
 		{ "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 },
+		{ "ready", cmd_ready_dev, cmd_ready_dev_usage, NULL, 0 },
 		{ 0, 0, 0, 0, 0 }
 	}
 };
diff --git a/ioctl.h b/ioctl.h
index 6fda3a1..d32e22c 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -419,6 +419,8 @@ struct btrfs_ioctl_clone_range_args {
 					struct btrfs_ioctl_ino_path_args)
 #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
 					struct btrfs_ioctl_ino_path_args)
+#define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
+				     struct btrfs_ioctl_vol_args)
 
 #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
 				struct btrfs_ioctl_received_subvol_args)
-- 
1.8.1.5