[PATCH] DRBD support for blkid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

DRBD is the Distributed Replicated Block Device, a replication service for low 
level block devices. The kernel dependent code will probably[tm] be taken 
upstream shortly, see discussions on kernel mailing list.

The attached patch provides (lib)blkid detection for v08 type drbd devices 
(v08 is the current one). Two people at linbit are CC'ed.

drbd may be used in "stacked" environments, such as LVM-on-DRBD-on-LVM. Due to 
that, flag BLKID_IDINFO_TOLERANT is required; also, the position of the info 
struct in idinfos seems to be critical.

Thx, best regards
   Bastian

-- 
Collax GmbH . Basler Str. 115a . 79115 Freiburg . Germany
p: +49 (0) 89-990 157-28	www.collax.com

Geschäftsführer: Boris Nalbach
AG München HRB 158898 . Ust.-IdNr: DE 814464942
\ To define recursion, we must first define recursion.
diff -uNr util-linux-ng-2.16.ori/shlibs/blkid/src/probe.c util-linux-ng-2.16/shlibs/blkid/src/probe.c
--- util-linux-ng-2.16.ori/shlibs/blkid/src/probe.c	2009-07-04 01:20:03.000000000 +0200
+++ util-linux-ng-2.16/shlibs/blkid/src/probe.c	2009-09-02 15:05:46.000000000 +0200
@@ -40,6 +40,9 @@
 
 static const struct blkid_idinfo *idinfos[] =
 {
+	/* Others */
+	&drbd_idinfo,
+
 	/* RAIDs */
 	&linuxraid_idinfo,
 	&ddfraid_idinfo,
--- util-linux-ng-2.16.ori/shlibs/blkid/src/probers/Makefile.am	2009-07-04 01:20:02.000000000 +0200
+++ util-linux-ng-2.16/shlibs/blkid/src/probers/Makefile.am	2009-09-02 11:32:07.000000000 +0200
@@ -40,4 +40,5 @@
 			sysv.c \
 			btrfs.c \
 			lvm.c \
-			zfs.c
+			zfs.c \
+			drbd.c
diff -uNr util-linux-ng-2.16.ori/shlibs/blkid/src/probers/drbd.c util-linux-ng-2.16/shlibs/blkid/src/probers/drbd.c
--- util-linux-ng-2.16.ori/shlibs/blkid/src/probers/drbd.c	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-ng-2.16/shlibs/blkid/src/probers/drbd.c	2009-09-09 15:02:03.000000000 +0200
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2009 by Bastian Friedrich <bastian.friedrich@xxxxxxxxxx>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ *
+ * defines, structs taken from drbd source; file names represent drbd source
+ * files.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include "blkidP.h"
+
+/*
+ * drbd/linux/drbd.h
+ */
+#define DRBD_MAGIC 0x83740267
+
+/*
+ * user/drbdmeta.c
+ * We only support v08 for now
+ */
+#define DRBD_MD_MAGIC_08 (DRBD_MAGIC+4)
+
+/*
+ * drbd/linux/drbd.h
+ */
+enum drbd_uuid_index {
+	UI_CURRENT,
+	UI_BITMAP,
+	UI_HISTORY_START,
+	UI_HISTORY_END,
+	UI_SIZE,		/* nl-packet: number of dirty bits */
+	UI_FLAGS,		/* nl-packet: flags */
+	UI_EXTENDED_SIZE	/* Everything. */
+};
+
+
+/*
+ * user/drbdmeta.c
+ * Minor modifications wrt. types
+ */
+struct md_on_disk_08 {
+	uint64_t la_sect;         /* last agreed size. */
+	uint64_t uuid[UI_SIZE];   // UUIDs.
+	uint64_t device_uuid;
+	uint64_t reserved_u64_1;
+	uint32_t flags;
+	uint32_t magic;
+	uint32_t md_size_sect;
+	int32_t  al_offset;       /* signed sector offset to this block */
+	uint32_t al_nr_extents;   /* important for restoring the AL */
+	int32_t  bm_offset;       /* signed sector offset to the bitmap, from here */
+	uint32_t bm_bytes_per_bit;
+	uint32_t reserved_u32[4];
+
+	char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
+};
+
+
+static int probe_drbd(blkid_probe pr, const struct blkid_idmag *mag)
+{
+	struct md_on_disk_08 *md;
+	off_t off;
+
+	off = pr->size - sizeof(*md);
+
+	/* Small devices cannot be drbd (?) */
+        if (pr->size < 0x10000)
+		return -1;
+
+	md = (struct md_on_disk_08 *)
+		blkid_probe_get_buffer(pr,
+		off,
+		sizeof(struct md_on_disk_08));
+
+
+	if (be32_to_cpu(md->magic) != DRBD_MD_MAGIC_08) {
+		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, &md->device_uuid, 8, "0x%"__PRI64_PREFIX"x",
+		be64_to_cpu(md->device_uuid));
+
+	blkid_probe_set_version(pr, "v08");
+
+	return 0;
+}
+
+const struct blkid_idinfo drbd_idinfo =
+{
+	.name		= "drbd",
+	.usage		= BLKID_USAGE_OTHER,
+	.flags		= BLKID_IDINFO_TOLERANT,
+	.probefunc	= probe_drbd,
+	.magics		= BLKID_NONE_MAGIC
+};
+
diff -uNr util-linux-ng-2.16.ori/shlibs/blkid/src/probers/probers.h util-linux-ng-2.16/shlibs/blkid/src/probers/probers.h
--- util-linux-ng-2.16.ori/shlibs/blkid/src/probers/probers.h	2009-07-04 01:20:02.000000000 +0200
+++ util-linux-ng-2.16/shlibs/blkid/src/probers/probers.h	2009-09-02 11:31:43.000000000 +0200
@@ -57,5 +57,6 @@
 extern const struct blkid_idinfo xenix_idinfo;
 extern const struct blkid_idinfo btrfs_idinfo;
 extern const struct blkid_idinfo zfs_idinfo;
+extern const struct blkid_idinfo drbd_idinfo;
 
 #endif /* _BLKID_PROBE_H */

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux