dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0108-blkid-make-zfs-detection-more-robust.patch

531551
From a0e00751052b06508f6cfe4a434ebf2e1a04bf07 Mon Sep 17 00:00:00 2001
531551
From: Michal Humpula <michal.humpula@hudrydum.cz>
531551
Date: Wed, 25 Feb 2015 20:25:05 +0100
531551
Subject: [PATCH 108/116] blkid: make zfs detection more robust
531551
531551
Try to use all the possible uberblock locations.
531551
531551
Upstream: https://github.com/karelzak/util-linux/commit/5dd705ba65dc80cf8630b3b1b4f3a1ba153e7eec
531551
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1392661
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 libblkid/src/superblocks/zfs.c | 42 +++++++++++++++++++++++++++---------------
531551
 1 file changed, 27 insertions(+), 15 deletions(-)
531551
531551
diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c
531551
index 86da59d..4a64a03 100644
531551
--- a/libblkid/src/superblocks/zfs.c
531551
+++ b/libblkid/src/superblocks/zfs.c
531551
@@ -19,6 +19,7 @@
531551
 #define VDEV_LABEL_UBERBLOCK	(128 * 1024ULL)
531551
 #define VDEV_LABEL_NVPAIR	( 16 * 1024ULL)
531551
 #define VDEV_LABEL_SIZE		(256 * 1024ULL)
531551
+#define UBERBLOCK_SIZE		1024ULL
531551
 
531551
 /* #include <sys/uberblock_impl.h> */
531551
 #define UBERBLOCK_MAGIC         0x00bab10c              /* oo-ba-bloc!  */
531551
@@ -31,7 +32,7 @@ struct zfs_uberblock {
531551
 	char		ub_rootbp;	/* MOS objset_phys_t		*/
531551
 } __attribute__((packed));
531551
 
531551
-#define ZFS_TRIES	64
531551
+#define ZFS_TRIES	512
531551
 #define ZFS_WANT	 4
531551
 
531551
 #define DATA_TYPE_UINT64 8
531551
@@ -162,11 +163,10 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
531551
 #define zdebug(fmt, ...)	do {} while(0)
531551
 /*#define zdebug(fmt, a...)	fprintf(stderr, fmt, ##a)*/
531551
 
531551
-/* ZFS has 128x1kB host-endian root blocks, stored in 2 areas at the start
531551
- * of the disk, and 2 areas at the end of the disk.  Check only some of them...
531551
- * #4 (@ 132kB) is the first one written on a new filesystem. */
531551
-static int probe_zfs(blkid_probe pr,
531551
-		const struct blkid_idmag *mag __attribute__((__unused__)))
531551
+/* ZFS has 128x1kB host-endian root blocks, stored in 2 areas (labels)
531551
+ * at the start of the disk, and 2 areas at the end of the disk.
531551
+ */
531551
+static int probe_zfs(blkid_probe pr, const struct blkid_idmag *mag)
531551
 {
531551
 	uint64_t swab_magic = swab64(UBERBLOCK_MAGIC);
531551
 	struct zfs_uberblock *ub;
531551
@@ -174,15 +174,29 @@ static int probe_zfs(blkid_probe pr,
531551
 	loff_t offset, ub_offset = 0;
531551
 	int tried;
531551
 	int found;
531551
+	loff_t blk_align = (pr->size % (256 * 1024ULL));
531551
 
531551
 	zdebug("probe_zfs\n");
531551
-	/* Look for at least 4 uberblocks to ensure a positive match */
531551
+	/* Look for at least 4 uberblocks to ensure a positive match.
531551
+	   Begin with Label 0 (L0) at the start of the block device. */
531551
 	for (tried = found = 0, offset = VDEV_LABEL_UBERBLOCK;
531551
-	     tried < ZFS_TRIES && found < ZFS_WANT;
531551
-	     tried++, offset += 4096) {
531551
-		/* also try the second uberblock copy */
531551
-		if (tried == (ZFS_TRIES / 2))
531551
+	     found < ZFS_WANT && tried < ZFS_TRIES;
531551
+	     tried++, offset += UBERBLOCK_SIZE)
531551
+	{
531551
+		/* Leave L0 to try other labels */
531551
+		switch(tried) {
531551
+		case 128: // jump to L1, just after L0
531551
 			offset = VDEV_LABEL_SIZE + VDEV_LABEL_UBERBLOCK;
531551
+			break;
531551
+		case 256: // jump to L2 near the far end of the block device
531551
+			offset = pr->size - 2 * VDEV_LABEL_SIZE + VDEV_LABEL_UBERBLOCK - blk_align;
531551
+			zdebug("probe_zfs: l2 offset %llu\n", offset >> 10);
531551
+			break;
531551
+		case 384: // jump to L3 at the furthest end of the block device
531551
+			offset = pr->size - VDEV_LABEL_SIZE + VDEV_LABEL_UBERBLOCK - blk_align;
531551
+			zdebug("probe_zfs: l3 offset %llu\n", offset >> 10);
531551
+			break;
531551
+		}
531551
 
531551
 		ub = (struct zfs_uberblock *)
531551
 			blkid_probe_get_buffer(pr, offset,
531551
@@ -193,15 +207,14 @@ static int probe_zfs(blkid_probe pr,
531551
 		if (ub->ub_magic == UBERBLOCK_MAGIC) {
531551
 			ub_offset = offset;
531551
 			found++;
531551
+			zdebug("probe_zfs: found little-endian uberblock at %llu\n", offset >> 10);
531551
 		}
531551
 
531551
 		if ((swab_endian = (ub->ub_magic == swab_magic))) {
531551
 			ub_offset = offset;
531551
 			found++;
531551
+			zdebug("probe_zfs: found big-endian uberblock at %llu\n", offset >> 10);
531551
 		}
531551
-
531551
-		zdebug("probe_zfs: found %s-endian uberblock at %llu\n",
531551
-		       swab_endian ? "big" : "little", offset >> 10);
531551
 	}
531551
 
531551
 	if (found < 4)
531551
@@ -230,4 +243,3 @@ const struct blkid_idinfo zfs_idinfo =
531551
 	.minsz		= 64 * 1024 * 1024,
531551
 	.magics		= BLKID_NONE_MAGIC
531551
 };
531551
-
531551
-- 
531551
2.9.3
531551