]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: added drbdmanage control volume detection.
authorPhilipp Marek <philipp.marek@linbit.com>
Tue, 18 Aug 2015 12:07:49 +0000 (14:07 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 24 Aug 2015 09:01:34 +0000 (11:01 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/Makemodule.am
libblkid/src/superblocks/drbdmanage.c [new file with mode: 0644]
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h
tests/expected/blkid/low-probe-drbdmanage-control-volume [new file with mode: 0644]
tests/ts/blkid/images-fs/drbdmanage-control-volume.img.bz2 [new file with mode: 0644]

index 7682958fe57cbf6173ae411abc0ecf4c0218550e..52d0b0a7b75a446f1ad374c464abe05f90b336cb 100644 (file)
@@ -52,6 +52,7 @@ libblkid_la_SOURCES = \
        libblkid/src/superblocks/ddf_raid.c \
        libblkid/src/superblocks/drbd.c \
        libblkid/src/superblocks/drbdproxy_datalog.c \
+       libblkid/src/superblocks/drbdmanage.c \
        libblkid/src/superblocks/exfat.c \
        libblkid/src/superblocks/ext.c \
        libblkid/src/superblocks/f2fs.c \
diff --git a/libblkid/src/superblocks/drbdmanage.c b/libblkid/src/superblocks/drbdmanage.c
new file mode 100644 (file)
index 0000000..ee84142
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 by Philipp Marek <philipp.marek@linbit.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ *
+ * DRBD is a blocklevel replication solution in the Linux kernel,
+ * upstream since 2.6.33. (See http://drbd.linbit.com/)
+ * DRBDmanage is a configuration frontend that assists in
+ * creating/deleting/modifying DRBD resources across multiple machines
+ * (a DRBDmanage "cluster"); this file detects its control volume,
+ * which is replicated (via DRBD 9) on some of the nodes.
+ */
+#include <endian.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include <stddef.h>
+
+#include "superblocks.h"
+
+struct drbdmanage_hdr {
+       unsigned char magic[11];
+       unsigned char uuid[32];
+       unsigned char lf;
+} __attribute__ ((packed));
+
+struct drbdmanage_pers {
+       char magic[4];
+       uint32_t version_le;
+} __attribute__ ((packed));
+
+
+const char persistence_magic[4] = "\x1a\xdb\x98\xa2";
+
+
+static int probe_drbdmanage(blkid_probe pr,
+               const struct blkid_idmag *mag __attribute__((__unused__)))
+{
+       struct drbdmanage_hdr *hdr;
+       unsigned char *cp;
+       struct drbdmanage_pers *prs;
+       char persistence_version[10];
+       int l;
+
+
+       hdr = (struct drbdmanage_hdr*)
+               blkid_probe_get_buffer(pr, 0, sizeof(*hdr));
+       if (!hdr)
+               return errno ? -errno : 1;
+
+       for(cp=hdr->uuid; cp<&hdr->lf; cp++)
+               if (!isxdigit(*cp))
+                       return 1;
+       if (hdr->lf != '\n')
+               return 1;
+
+       if (blkid_probe_set_id_label(pr, "UUID",
+                               hdr->uuid, sizeof(hdr->uuid)))
+               return errno ? -errno : 1;
+
+       prs = (struct drbdmanage_pers*)
+               blkid_probe_get_buffer(pr, 0x1000, sizeof(*prs));
+       if (!prs)
+               return errno ? -errno : 1;
+
+       if (memcmp(prs->magic, persistence_magic, sizeof(prs->magic)) == 0) {
+               l = sprintf(persistence_version, "%d",
+                               be32toh(prs->version_le));
+               blkid_probe_set_value(pr, "PERSISTENCE_VERSION",
+                               persistence_version, l);
+       }
+
+       return 0;
+}
+
+
+const struct blkid_idinfo drbdmanage_idinfo =
+{
+       .name           = "drbdmanage_control_volume",
+       .usage          = BLKID_USAGE_OTHER,
+       .probefunc      = probe_drbdmanage,
+       .minsz      = 64 * 1024,
+       .magics         = {
+               { .magic = "$DRBDmgr=q", .len = 10, .sboff = 0 },
+       },
+};
+
index 334d67304823997d3f2e9ab8602f00444af801b7..0d970f1341f0013cce3e45f320d9510eb965712f 100644 (file)
@@ -103,6 +103,7 @@ static const struct blkid_idinfo *idinfos[] =
 
        &bcache_idinfo,
        &drbd_idinfo,
+       &drbdmanage_idinfo,
        &drbdproxy_datalog_idinfo,
        &lvm2_idinfo,
        &lvm1_idinfo,
index 238a9ff1b3f996c4faab660e819bd0f8b43827af..79dba1a3cf7b148274369fad258ec6eee18108f1 100644 (file)
@@ -68,6 +68,7 @@ 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;
+extern const struct blkid_idinfo drbdmanage_idinfo;
 extern const struct blkid_idinfo drbdproxy_datalog_idinfo;
 extern const struct blkid_idinfo befs_idinfo;
 extern const struct blkid_idinfo nilfs2_idinfo;
diff --git a/tests/expected/blkid/low-probe-drbdmanage-control-volume b/tests/expected/blkid/low-probe-drbdmanage-control-volume
new file mode 100644 (file)
index 0000000..9f23bfc
--- /dev/null
@@ -0,0 +1,5 @@
+ID_FS_PERSISTENCE_VERSION=1
+ID_FS_TYPE=drbdmanage_control_volume
+ID_FS_USAGE=other
+ID_FS_UUID=8765f402dcb246529acee269b0ba8f2e
+ID_FS_UUID_ENC=8765f402dcb246529acee269b0ba8f2e
diff --git a/tests/ts/blkid/images-fs/drbdmanage-control-volume.img.bz2 b/tests/ts/blkid/images-fs/drbdmanage-control-volume.img.bz2
new file mode 100644 (file)
index 0000000..6979055
Binary files /dev/null and b/tests/ts/blkid/images-fs/drbdmanage-control-volume.img.bz2 differ