On 08/14/2012 11:38 PM, Alasdair G Kergon wrote:
On Mon, Aug 13, 2012 at 12:25:04PM +0200, Miquel van Smoorenburg wrote:
This patch makes sure that disks with signatures of one of these
metadata formats are also filtered out. To minimize the chance of
regressions, it only does this if md is actually running (i.e.
/proc/mdstat is present).
Why is /proc/mdstat relevant?
Do the signatures not appear without it?
Otherwise that check shouldn't be added.
I was just being cautious. In theory, it could be that someone has
re-used a disk that had a ddf or imsm signature, and if nothing has
overwritten that signature in the mean time such a setup might now break
with lvm. Unless ofcourse md raid was activated, in which case mdadm in
initrd would have triggered on it (in debian, mdadm is started before
lvm) and would have broken the system in a different way..
OTOH, mdadm had the same theoretical issue when it started to support
imsm/ddf and apparently that worked out ok, so probably that check
should be dropped.
And I'm not sure that it's exclusively 'md' (dmraid?) so the code might
need to go in a function with a different name.
I guess. What about the attached patch? The only thing is that I did not
bother to create seperate ddf_component_detection and
imsm_component_detection settings in lvm.conf, for now that's all lumped
under the md_component_detection setting.
Thanks,
Mike.
Description: Also automatically filter DDF and IMSM formatted disks
Author: Miquel van Smoorenburg <miqu...@debian.org>
Index: lvm2-2.02.95/lib/device/dev-ddf.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ lvm2-2.02.95/lib/device/dev-ddf.c 2012-08-15 16:18:08.019582071 +0000
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 Miquel van Smoorenburg
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "metadata.h"
+#include "xlate.h"
+#include "crc.h"
+
+#define DDF_MAGIC 0xDE11DE11
+struct ddf_header {
+ uint32_t magic;
+ uint32_t crc;
+ char guid[24];
+ char revision[8];
+ char padding[472];
+};
+
+/*
+ * Returns -1 on error
+ */
+int dev_is_ddf(struct device *dev, uint64_t *sb)
+{
+ struct ddf_header hdr;
+ uint32_t crc;
+ int ret = 0;
+ uint64_t size, sb_offset;
+
+ if (!dev_get_size(dev, &size)) {
+ stack;
+ return -1;
+ }
+
+ if (!dev_open_readonly(dev)) {
+ stack;
+ return -1;
+ }
+
+ /* Also calculate CRC so we have at least 8 bytes to check */
+ sb_offset = size - 512;
+ if (dev_read(dev, sb_offset, 512, &hdr) &&
+ (hdr.magic == xlate32(DDF_MAGIC))) {
+ crc = hdr.crc;
+ hdr.crc = 0xffffffff;
+ if (xlate32(calc_crc(0, (const uint8_t *)&hdr, 512)) == crc)
+ ret = 1;
+ }
+
+ if (!dev_close(dev))
+ stack;
+
+ if (ret && sb)
+ *sb = sb_offset;
+
+ return ret;
+}
+
Index: lvm2-2.02.95/lib/device/dev-imsm.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ lvm2-2.02.95/lib/device/dev-imsm.c 2012-08-15 16:18:16.955745514 +0000
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 Miquel van Smoorenburg
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "metadata.h"
+
+#define IMSM_SIGNATURE "Intel Raid ISM Cfg Sig. "
+#define IMSM_SIG_LEN (strlen(IMSM_SIGNATURE))
+
+/*
+ * Returns -1 on error
+ */
+int dev_is_imsm(struct device *dev, uint64_t *sb)
+{
+ char imsm_signature[IMSM_SIG_LEN];
+ int ret = 0;
+ uint64_t size, sb_offset;
+
+ if (!dev_get_size(dev, &size)) {
+ stack;
+ return -1;
+ }
+
+ if (!dev_open_readonly(dev)) {
+ stack;
+ return -1;
+ }
+
+ sb_offset = size - 1024;
+ if (dev_read(dev, sb_offset, IMSM_SIG_LEN, imsm_signature) &&
+ memcmp(imsm_signature, IMSM_SIGNATURE, IMSM_SIG_LEN) == 0)
+ ret = 1;
+
+ if (!dev_close(dev))
+ stack;
+
+ if (ret && sb)
+ *sb = sb_offset;
+
+ return ret;
+}
+
Index: lvm2-2.02.95/lib/device/device.h
===================================================================
--- lvm2-2.02.95.orig/lib/device/device.h 2012-08-15 15:04:03.757865705 +0000
+++ lvm2-2.02.95/lib/device/device.h 2012-08-15 15:04:19.042146729 +0000
@@ -101,6 +101,8 @@
/* Does device contain md superblock? If so, where? */
int dev_is_md(struct device *dev, uint64_t *sb);
+int dev_is_ddf(struct device *dev, uint64_t *sb);
+int dev_is_imsm(struct device *dev, uint64_t *sb);
int dev_is_swap(struct device *dev, uint64_t *signature);
int dev_is_luks(struct device *dev, uint64_t *signature);
unsigned long dev_md_stripe_width(const char *sysfs_dir, struct device *dev);
Index: lvm2-2.02.95/lib/filters/filter-md.c
===================================================================
--- lvm2-2.02.95.orig/lib/filters/filter-md.c 2012-08-15 15:12:31.163191518 +0000
+++ lvm2-2.02.95/lib/filters/filter-md.c 2012-08-15 15:10:58.325485708 +0000
@@ -28,6 +28,10 @@
return 1;
ret = dev_is_md(dev, NULL);
+ if (ret == 0)
+ ret = dev_is_ddf(dev, NULL);
+ if (ret == 0)
+ ret = dev_is_imsm(dev, NULL);
if (ret == 1) {
log_debug("%s: Skipping md component device", dev_name(dev));
Index: lvm2-2.02.95/lib/metadata/metadata.c
===================================================================
--- lvm2-2.02.95.orig/lib/metadata/metadata.c 2012-08-15 15:06:38.908718045 +0000
+++ lvm2-2.02.95/lib/metadata/metadata.c 2012-08-15 15:06:49.264908409 +0000
@@ -1392,6 +1392,12 @@
if (!_wipe_sb(dev, "software RAID md superblock", name, 4, pp, dev_is_md))
goto_bad;
+ if (!_wipe_sb(dev, "software RAID imsm superblock", name, 1024, pp, dev_is_imsm))
+ goto_bad;
+
+ if (!_wipe_sb(dev, "RAID ddf superblock", name, 512, pp, dev_is_ddf))
+ goto_bad;
+
if (!_wipe_sb(dev, "swap signature", name, 10, pp, dev_is_swap))
goto_bad;
Index: lvm2-2.02.95/lib/Makefile.in
===================================================================
--- lvm2-2.02.95.orig/lib/Makefile.in 2012-08-15 16:09:56.970605576 +0000
+++ lvm2-2.02.95/lib/Makefile.in 2012-08-15 16:10:12.906896731 +0000
@@ -54,6 +54,8 @@
device/dev-cache.c \
device/dev-io.c \
device/dev-md.c \
+ device/dev-ddf.c \
+ device/dev-imsm.c \
device/dev-swap.c \
device/dev-luks.c \
device/device.c \