diff options
author | Philipp Marek | 2015-08-18 14:07:49 +0200 |
---|---|---|
committer | Karel Zak | 2015-08-24 11:01:34 +0200 |
commit | 2dc8cfb9a8082c040305b2a73763a451c28cf44d (patch) | |
tree | 10ca8a4fcca3ba1df5119a5c6024200e771cfd58 /libblkid | |
parent | hwclock: fix iopl implicit declaration warning on alpha (diff) | |
download | kernel-qcow2-util-linux-2dc8cfb9a8082c040305b2a73763a451c28cf44d.tar.gz kernel-qcow2-util-linux-2dc8cfb9a8082c040305b2a73763a451c28cf44d.tar.xz kernel-qcow2-util-linux-2dc8cfb9a8082c040305b2a73763a451c28cf44d.zip |
libblkid: added drbdmanage control volume detection.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libblkid')
-rw-r--r-- | libblkid/src/Makemodule.am | 1 | ||||
-rw-r--r-- | libblkid/src/superblocks/drbdmanage.c | 92 | ||||
-rw-r--r-- | libblkid/src/superblocks/superblocks.c | 1 | ||||
-rw-r--r-- | libblkid/src/superblocks/superblocks.h | 1 |
4 files changed, 95 insertions, 0 deletions
diff --git a/libblkid/src/Makemodule.am b/libblkid/src/Makemodule.am index 7682958fe..52d0b0a7b 100644 --- a/libblkid/src/Makemodule.am +++ b/libblkid/src/Makemodule.am @@ -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 index 000000000..ee841423f --- /dev/null +++ b/libblkid/src/superblocks/drbdmanage.c @@ -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 }, + }, +}; + diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index 334d67304..0d970f134 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -103,6 +103,7 @@ static const struct blkid_idinfo *idinfos[] = &bcache_idinfo, &drbd_idinfo, + &drbdmanage_idinfo, &drbdproxy_datalog_idinfo, &lvm2_idinfo, &lvm1_idinfo, diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h index 238a9ff1b..79dba1a3c 100644 --- a/libblkid/src/superblocks/superblocks.h +++ b/libblkid/src/superblocks/superblocks.h @@ -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; |