util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] libblkid: add check for DRBD9
@ 2018-11-20 16:10 Roland Kammerer
  2018-11-21  9:56 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Roland Kammerer @ 2018-11-20 16:10 UTC (permalink / raw)
  To: util-linux; +Cc: Roland Kammerer

This adds the according meta-data structs + defines and an additional
function to detect DRBD9 magics.

Signed-off-by: Roland Kammerer <roland.kammerer@linbit.com>
---
 libblkid/src/superblocks/drbd.c | 111 ++++++++++++++++++++++++++++++--
 1 file changed, 107 insertions(+), 4 deletions(-)

diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c
index e88e9f353..4ebaf1739 100644
--- a/libblkid/src/superblocks/drbd.c
+++ b/libblkid/src/superblocks/drbd.c
@@ -25,10 +25,12 @@
 
 /*
  * user/drbdmeta.c
- * We only support v08 for now
+ * We support v08 and v09
  */
 #define DRBD_MD_MAGIC_08         (DRBD_MAGIC+4)
 #define DRBD_MD_MAGIC_84_UNCLEAN (DRBD_MAGIC+5)
+#define DRBD_MD_MAGIC_09         (DRBD_MAGIC+6)
+/* there is no DRBD_MD_MAGIC_09_UNCLEAN */
 
 /*
  * drbd/linux/drbd.h
@@ -44,7 +46,7 @@ enum drbd_uuid_index {
 };
 
 /*
- * user/drbdmeta.c
+ * user/shared/drbdmeta.c
  * Minor modifications wrt. types
  */
 struct md_on_disk_08 {
@@ -64,9 +66,54 @@ struct md_on_disk_08 {
 	char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
 };
 
+/*
+ * linux/drbd.h, v9 only
+ */
+#define DRBD_PEERS_MAX 32
+#define HISTORY_UUIDS DRBD_PEERS_MAX
 
-static int probe_drbd(blkid_probe pr,
-		const struct blkid_idmag *mag __attribute__((__unused__)))
+/*
+ * drbd-headers/drbd_meta_data.h
+ * Minor modifications wrt. types
+ */
+struct peer_dev_md_on_disk_9 {
+	uint64_t bitmap_uuid;
+	uint64_t bitmap_dagtag;
+	uint32_t flags;
+	int32_t bitmap_index;
+	uint32_t reserved_u32[2];
+} __attribute__((packed));
+
+struct meta_data_on_disk_9 {
+	uint64_t effective_size;    /* last agreed size */
+	uint64_t current_uuid;
+	uint64_t reserved_u64[4];   /* to have the magic at the same position as in v07, and v08 */
+	uint64_t device_uuid;
+	uint32_t flags;             /* MDF */
+	uint32_t magic;
+	uint32_t md_size_sect;
+	uint32_t al_offset;         /* offset to this block */
+	uint32_t al_nr_extents;     /* important for restoring the AL */
+	uint32_t bm_offset;         /* offset to the bitmap, from here */
+	uint32_t bm_bytes_per_bit;  /* BM_BLOCK_SIZE */
+	uint32_t la_peer_max_bio_size;   /* last peer max_bio_size */
+	uint32_t bm_max_peers;
+	int32_t node_id;
+
+	/* see al_tr_number_to_on_disk_sector() */
+	uint32_t al_stripes;
+	uint32_t al_stripe_size_4k;
+
+	uint32_t reserved_u32[2];
+
+	struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX];
+	uint64_t history_uuids[HISTORY_UUIDS];
+
+	char padding[0] __attribute__((aligned(4096)));
+} __attribute__((packed));
+
+
+static int probe_drbd_84(blkid_probe pr)
 {
 	struct md_on_disk_08 *md;
 	off_t off;
@@ -107,6 +154,62 @@ static int probe_drbd(blkid_probe pr,
 	return 0;
 }
 
+static int probe_drbd_90(blkid_probe pr)
+{
+	struct meta_data_on_disk_9 *md;
+	off_t off;
+
+	off = pr->size - sizeof(*md);
+
+	/*
+	 * Smaller ones are certainly not DRBD9 devices.
+	 * Recent utils even refuse to generate larger ones,
+	 * keep this as a sufficient lower bound.
+	 */
+	if (pr->size < 0x10000)
+		return 1;
+
+	md = (struct meta_data_on_disk_9 *)
+			blkid_probe_get_buffer(pr,
+					off,
+					sizeof(struct meta_data_on_disk_9));
+	if (!md)
+		return errno ? -errno : 1;
+
+	if (be32_to_cpu(md->magic) != DRBD_MD_MAGIC_09)
+		return 1;
+
+	/*
+	 * DRBD does not have "real" uuids; the following resembles DRBD's
+	 * notion of uuids (64 bit, see struct above)
+	 */
+	blkid_probe_sprintf_uuid(pr,
+		(unsigned char *) &md->device_uuid, sizeof(md->device_uuid),
+		"%" PRIx64, be64_to_cpu(md->device_uuid));
+
+	blkid_probe_set_version(pr, "v09");
+
+	if (blkid_probe_set_magic(pr,
+				off + offsetof(struct meta_data_on_disk_9, magic),
+				sizeof(md->magic),
+				(unsigned char *) &md->magic))
+		return 1;
+
+	return 0;
+}
+
+static int probe_drbd(blkid_probe pr,
+		const struct blkid_idmag *mag __attribute__((__unused__)))
+{
+	int ret;
+
+	ret = probe_drbd_84(pr);
+	if (ret <= 0) /* success or fatal (-errno) */
+		return ret;
+
+	return probe_drbd_90(pr);
+}
+
 const struct blkid_idinfo drbd_idinfo =
 {
 	.name		= "drbd",
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] libblkid: add check for DRBD9
  2018-11-20 16:10 [PATCH 1/1] libblkid: add check for DRBD9 Roland Kammerer
@ 2018-11-21  9:56 ` Karel Zak
  2018-11-21 10:48   ` Roland Kammerer
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2018-11-21  9:56 UTC (permalink / raw)
  To: Roland Kammerer; +Cc: util-linux

On Tue, Nov 20, 2018 at 05:10:49PM +0100, Roland Kammerer wrote:
>  libblkid/src/superblocks/drbd.c | 111 ++++++++++++++++++++++++++++++--
>  1 file changed, 107 insertions(+), 4 deletions(-)

Applied, thanks!

It would be nice to have DRBD test images in tests/ts/blkid/images-fs/, 
so on 

    ./tests/run.sh blkid

we will see if DRBD probing code works as expected :-)

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] libblkid: add check for DRBD9
  2018-11-21  9:56 ` Karel Zak
@ 2018-11-21 10:48   ` Roland Kammerer
  0 siblings, 0 replies; 3+ messages in thread
From: Roland Kammerer @ 2018-11-21 10:48 UTC (permalink / raw)
  To: util-linux

On Wed, Nov 21, 2018 at 10:56:30AM +0100, Karel Zak wrote:
> On Tue, Nov 20, 2018 at 05:10:49PM +0100, Roland Kammerer wrote:
> >  libblkid/src/superblocks/drbd.c | 111 ++++++++++++++++++++++++++++++--
> >  1 file changed, 107 insertions(+), 4 deletions(-)
> 
> Applied, thanks!
> 
> It would be nice to have DRBD test images in tests/ts/blkid/images-fs/, 
> so on 
> 
>     ./tests/run.sh blkid
> 
> we will see if DRBD probing code works as expected :-)

Sure thing, I will prepare one for "v08" and one for "v09". Expect them
early next week.

Regards, rck

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-21 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 16:10 [PATCH 1/1] libblkid: add check for DRBD9 Roland Kammerer
2018-11-21  9:56 ` Karel Zak
2018-11-21 10:48   ` Roland Kammerer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).