From c61e14d3a8412cd50d98aab604e607692c844c8a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:33:30 +0200 Subject: Adding upstream version 2.40. Signed-off-by: Daniel Baumann --- libblkid/src/superblocks/drbd.c | 147 ++++++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 67 deletions(-) (limited to 'libblkid/src/superblocks/drbd.c') diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c index f360186..96a2168 100644 --- a/libblkid/src/superblocks/drbd.c +++ b/libblkid/src/superblocks/drbd.c @@ -18,18 +18,24 @@ #include "superblocks.h" +enum { + DRBD_VERSION_08, + DRBD_VERSION_09, +}; + /* - * drbd/linux/drbd.h + * drbd/drbd_int.h */ -#define DRBD_MAGIC 0x83740267 +#define BM_BLOCK_SHIFT 12 /* 4k per bit */ +#define BM_BLOCK_SIZE (1<size - DRBD_MD_OFFSET; + for (; padding_start < padding_end; padding_start++) { + if (*padding_start != 0) + return 0; + } + return 1; +} - /* Small devices cannot be drbd (?) */ - if (pr->size < 0x10000) - return 1; +static int probe_drbd_84(blkid_probe pr, const struct blkid_idmag *mag) +{ + const struct md_on_disk_08 *md; - md = (struct md_on_disk_08 *) - blkid_probe_get_buffer(pr, - off, - sizeof(struct md_on_disk_08)); + md = blkid_probe_get_sb(pr, mag, struct md_on_disk_08); if (!md) return errno ? -errno : 1; - if (be32_to_cpu(md->magic) != DRBD_MD_MAGIC_08 && - be32_to_cpu(md->magic) != DRBD_MD_MAGIC_84_UNCLEAN) + if (be32_to_cpu(read_unaligned_member(md, bm_bytes_per_bit)) != BM_BLOCK_SIZE) + return 1; + + if (!is_zero_padded(member_ptr(md, padding_start), + member_ptr(md, padding_end))) return 1; /* @@ -151,43 +158,27 @@ static int probe_drbd_84(blkid_probe pr) * 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)); + member_ptr(md, device_uuid), sizeof(md->device_uuid), + "%" PRIx64, be64_to_cpu(read_unaligned_member(md, device_uuid))); blkid_probe_set_version(pr, "v08"); - if (blkid_probe_set_magic(pr, - off + offsetof(struct md_on_disk_08, magic), - sizeof(md->magic), - (unsigned char *) &md->magic)) - return 1; - return 0; } -static int probe_drbd_90(blkid_probe pr) +static int probe_drbd_90(blkid_probe pr, const struct blkid_idmag *mag) { - struct meta_data_on_disk_9 *md; - off_t off; - - off = pr->size - DRBD_MD_OFFSET; - - /* - * 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; + const struct meta_data_on_disk_9 *md; - md = (struct meta_data_on_disk_9 *) - blkid_probe_get_buffer(pr, - off, - sizeof(struct meta_data_on_disk_9)); + md = blkid_probe_get_sb(pr, mag, struct meta_data_on_disk_9); if (!md) return errno ? -errno : 1; - if (be32_to_cpu(md->magic) != DRBD_MD_MAGIC_09) + if (be32_to_cpu(read_unaligned_member(md, bm_bytes_per_bit)) != BM_BLOCK_SIZE) + return 1; + + if (!is_zero_padded(member_ptr(md, padding_start), + member_ptr(md, padding_end))) return 1; /* @@ -195,30 +186,23 @@ static int probe_drbd_90(blkid_probe pr) * 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)); + member_ptr(md, device_uuid), sizeof(md->device_uuid), + "%" PRIx64, be64_to_cpu(read_unaligned_member(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__))) +static int probe_drbd(blkid_probe pr, const struct blkid_idmag *mag) { - int ret; + if (mag->hint == DRBD_VERSION_08) + return probe_drbd_84(pr, mag); - ret = probe_drbd_84(pr); - if (ret <= 0) /* success or fatal (-errno) */ - return ret; + if (mag->hint == DRBD_VERSION_09) + return probe_drbd_90(pr, mag); - return probe_drbd_90(pr); + return 1; } const struct blkid_idinfo drbd_idinfo = @@ -226,6 +210,35 @@ const struct blkid_idinfo drbd_idinfo = .name = "drbd", .usage = BLKID_USAGE_RAID, .probefunc = probe_drbd, - .magics = BLKID_NONE_MAGIC + /* + * Smaller ones are certainly not DRBD9 devices. + * Recent utils even refuse to generate larger ones, + * keep this as a sufficient lower bound. + */ + .minsz = 0x10000, + .magics = { + { + .magic = DRBD_MD_MAGIC_08, + .len = sizeof(DRBD_MD_MAGIC_08) - 1, + .hint = DRBD_VERSION_08, + .kboff = -(DRBD_MD_OFFSET >> 10), + .sboff = offsetof(struct md_on_disk_08, magic), + }, + { + .magic = DRBD_MD_MAGIC_84_UNCLEAN, + .len = sizeof(DRBD_MD_MAGIC_84_UNCLEAN) - 1, + .hint = DRBD_VERSION_08, + .kboff = -(DRBD_MD_OFFSET >> 10), + .sboff = offsetof(struct md_on_disk_08, magic), + }, + { + .magic = DRBD_MD_MAGIC_09, + .len = sizeof(DRBD_MD_MAGIC_09) - 1, + .hint = DRBD_VERSION_09, + .kboff = -(DRBD_MD_OFFSET >> 10), + .sboff = offsetof(struct meta_data_on_disk_9, magic), + }, + { NULL } + } }; -- cgit v1.2.3