]> err.no Git - util-linux/commitdiff
libblkid: DRBD support for blkid
authorBastian Friedrich <bastian.friedrich@collax.com>
Mon, 4 Jan 2010 13:13:13 +0000 (14:13 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 4 Jan 2010 13:17:31 +0000 (14:17 +0100)
DRBD is the Distributed Replicated Block Device, a replication service for low
level block devices.

The attached patch provides libblkid detection for v08 type drbd devices
(v08 is the current one).

[kzak@redhat.com: - port to libblkid 2.17
                  - use BLKID_USAGE_RAID flag
                  - remove BLKID_IDINFO_TOLERANT flag
                  - note that DRBD is supported since kernel v2.6.33-rc1]

Signed-off-by: Bastian Friedrich <bastian.friedrich@collax.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/superblocks/Makefile.am
shlibs/blkid/src/superblocks/drbd.c [new file with mode: 0644]
shlibs/blkid/src/superblocks/superblocks.c
shlibs/blkid/src/superblocks/superblocks.h

index 8cf3009b9f8aa2519f15a3a7d951bd1605717115..33e5d0c39a31a0ed6064d20cba65e8c61b5630d8 100644 (file)
@@ -44,4 +44,5 @@ libblkid_superblocks_la_SOURCES = \
                        zfs.c \
                        ubifs.c \
                        bfs.c \
+                       drbd.c \
                        vmfs.c
diff --git a/shlibs/blkid/src/superblocks/drbd.c b/shlibs/blkid/src/superblocks/drbd.c
new file mode 100644 (file)
index 0000000..e0bbb4d
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2009 by Bastian Friedrich <bastian.friedrich@collax.com>
+ *
+ * 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 "superblocks.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,
+               (unsigned char *) &md->device_uuid, sizeof(md->device_uuid),
+               "0x%" PRIx64, 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_RAID,
+       .probefunc      = probe_drbd,
+       .magics         = BLKID_NONE_MAGIC
+};
+
index f625f271bcb6b74b2c306ba9fc59cdf45d91b791..e77c511dde59855f1eda33b6b4aef859563bab7e 100644 (file)
@@ -94,6 +94,7 @@ static const struct blkid_idinfo *idinfos[] =
        &adraid_idinfo,
        &jmraid_idinfo,
 
+       &drbd_idinfo,
        &lvm2_idinfo,
        &lvm1_idinfo,
        &snapcow_idinfo,
index d1f55595697783c791483d02ea29f5df069ae56b..893ae72ae9f283a8b26e67a152067ebe8b38ce37 100644 (file)
@@ -63,6 +63,7 @@ extern const struct blkid_idinfo zfs_idinfo;
 extern const struct blkid_idinfo bfs_idinfo;
 extern const struct blkid_idinfo vmfs_volume_idinfo;
 extern const struct blkid_idinfo vmfs_fs_idinfo;
+extern const struct blkid_idinfo drbd_idinfo;
 
 /*
  * superblock functions