* [PATCH] lvm2 support for detecting v1.x MD superblocks
@ 2007-10-23 15:32 Mike Snitzer
2007-10-24 0:44 ` [lvm-devel] " Alasdair G Kergon
0 siblings, 1 reply; 3+ messages in thread
From: Mike Snitzer @ 2007-10-23 15:32 UTC (permalink / raw)
To: lvm-devel; +Cc: linux-raid
[-- Attachment #1: Type: text/plain, Size: 220 bytes --]
lvm2's MD v1.0 superblock detection doesn't work at all (because it
doesn't use v1 sb offsets).
I've tested the attached patch to work on MDs with v0.90.0, v1.0,
v1.1, and v1.2 superblocks.
please advise, thanks.
Mike
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: lvm2_md_v1_sb_fix.patch --]
[-- Type: text/x-patch; name=lvm2_md_v1_sb_fix.patch, Size: 2059 bytes --]
Index: lib/device/dev-md.c
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/device/dev-md.c,v
retrieving revision 1.5
diff -u -r1.5 dev-md.c
--- lib/device/dev-md.c 20 Aug 2007 20:55:25 -0000 1.5
+++ lib/device/dev-md.c 23 Oct 2007 15:17:57 -0000
@@ -25,6 +25,40 @@
#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) \
- MD_RESERVED_SECTORS)
+int dev_has_md_sb(struct device *dev, uint64_t sb_offset, uint64_t *sb)
+{
+ int ret = 0;
+ uint32_t md_magic;
+ /* Version 1 is little endian; version 0.90.0 is machine endian */
+ if (dev_read(dev, sb_offset, sizeof(uint32_t), &md_magic) &&
+ ((md_magic == xlate32(MD_SB_MAGIC)) ||
+ (md_magic == MD_SB_MAGIC))) {
+ if (sb)
+ *sb = sb_offset;
+ ret = 1;
+ }
+ return ret;
+}
+
+uint64_t v1_sb_offset(uint64_t size, int minor_version) {
+ uint64_t sb_offset;
+ switch(minor_version) {
+ case 0:
+ sb_offset = size;
+ sb_offset -= 8*2;
+ sb_offset &= ~(4*2-1);
+ break;
+ case 1:
+ sb_offset = 0;
+ break;
+ case 2:
+ sb_offset = 4*2;
+ break;
+ }
+ sb_offset <<= SECTOR_SHIFT;
+ return sb_offset;
+}
+
/*
* Returns -1 on error
*/
@@ -35,7 +69,6 @@
#ifdef linux
uint64_t size, sb_offset;
- uint32_t md_magic;
if (!dev_get_size(dev, &size)) {
stack;
@@ -50,16 +83,20 @@
return -1;
}
- sb_offset = MD_NEW_SIZE_SECTORS(size) << SECTOR_SHIFT;
-
/* Check if it is an md component device. */
- /* Version 1 is little endian; version 0.90.0 is machine endian */
- if (dev_read(dev, sb_offset, sizeof(uint32_t), &md_magic) &&
- ((md_magic == xlate32(MD_SB_MAGIC)) ||
- (md_magic == MD_SB_MAGIC))) {
- if (sb)
- *sb = sb_offset;
+ /* Version 0.90.0 */
+ sb_offset = MD_NEW_SIZE_SECTORS(size) << SECTOR_SHIFT;
+ if (dev_has_md_sb(dev, sb_offset, sb)) {
ret = 1;
+ } else {
+ /* Version 1, try v1.0 -> v1.2 */
+ int minor;
+ for (minor = 0; minor <= 2; minor++) {
+ if (dev_has_md_sb(dev, v1_sb_offset(size, minor), sb)) {
+ ret = 1;
+ break;
+ }
+ }
}
if (!dev_close(dev))
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [lvm-devel] [PATCH] lvm2 support for detecting v1.x MD superblocks
2007-10-23 15:32 [PATCH] lvm2 support for detecting v1.x MD superblocks Mike Snitzer
@ 2007-10-24 0:44 ` Alasdair G Kergon
2007-10-24 2:34 ` Mike Snitzer
0 siblings, 1 reply; 3+ messages in thread
From: Alasdair G Kergon @ 2007-10-24 0:44 UTC (permalink / raw)
To: LVM2 development; +Cc: linux-raid
On Tue, Oct 23, 2007 at 11:32:56AM -0400, Mike Snitzer wrote:
> I've tested the attached patch to work on MDs with v0.90.0, v1.0,
> v1.1, and v1.2 superblocks.
I'll apply this, thanks, but need to add comments (or reference) to explain
what the hard-coded numbers are:
sb_offset = (size - 8 * 2) & ~(4 * 2 - 1);
etc.
Alasdair
--
agk@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [lvm-devel] [PATCH] lvm2 support for detecting v1.x MD superblocks
2007-10-24 0:44 ` [lvm-devel] " Alasdair G Kergon
@ 2007-10-24 2:34 ` Mike Snitzer
0 siblings, 0 replies; 3+ messages in thread
From: Mike Snitzer @ 2007-10-24 2:34 UTC (permalink / raw)
To: LVM2 development, linux-raid
On 10/23/07, Alasdair G Kergon <agk@redhat.com> wrote:
> On Tue, Oct 23, 2007 at 11:32:56AM -0400, Mike Snitzer wrote:
> > I've tested the attached patch to work on MDs with v0.90.0, v1.0,
> > v1.1, and v1.2 superblocks.
>
> I'll apply this, thanks, but need to add comments (or reference) to explain
> what the hard-coded numbers are:
>
> sb_offset = (size - 8 * 2) & ~(4 * 2 - 1);
> etc.
All values are in terms of sectors; so that is where the * 2 is coming
from. The v1.0 case follows the same model as the MD_NEW_SIZE_SECTORS
which is used for v0.90.0. The difference is that the v1.0 superblock
is found "at least 8K, but less than 12K, from the end of the device".
The same switch statement is used in mdadm and is accompanied with the
following comment:
/*
* Calculate the position of the superblock.
* It is always aligned to a 4K boundary and
* depending on minor_version, it can be:
* 0: At least 8K, but less than 12K, from end of device
* 1: At start of device
* 2: 4K from start of device.
*/
Would it be sufficient to add that comment block above
v1_sb_offset()'s switch statement?
thanks,
Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-10-24 2:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-23 15:32 [PATCH] lvm2 support for detecting v1.x MD superblocks Mike Snitzer
2007-10-24 0:44 ` [lvm-devel] " Alasdair G Kergon
2007-10-24 2:34 ` Mike Snitzer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).