All of lore.kernel.org
 help / color / mirror / Atom feed
* mdadm named array (metadata 1.2) and udev when assembling an array in initramfs
@ 2014-11-01 18:53 Stephen Kent
  2014-11-04  9:06 ` Michael Tokarev
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Kent @ 2014-11-01 18:53 UTC (permalink / raw)
  To: linux-raid

I have set up a machine to use an md array as the root device. I have
created the array with metadata type 1.2, name "root," on host
"optimus" (so the full metadata name is "optimus:root").

I'm using Gentoo Linux (kernel 3.16.5-gentoo), and previously I had no
initramfs so I wrote a short one to assemble the array. My initramfs
sets the hostname and runs "mdadm -As," which correctly auto-assembles
the root device array on /dev/md/root (even without an
/etc/mdadm.conf).

Once the initramfs script is finished, init starts which then starts
udev. Now, at this point the array is already assembled, but the
/dev/md/* name is lost (and so is /run/mdadm/map) since those files
were on the initramfs' tempfs root. udev creates a /dev/mdXXX node
(ex. /dev/md127) and then runs a rule to try to figure out the
/dev/md/* name, which should be /dev/md/root. The default udev rule
calls mdadm --detail --export /dev/md127, which should print
MD_DEVNAME=root for udev, but instead it prints
MD_DEVNAME=optimus:root, and the symlink in /dev/md gets created as
/dev/md/optimus:root.

I think this is a bug in mdadm, but I'm not sure how to dig into it. I
have made sure that my main OS init sets the hostname before starting
udev, and I have tried with and without "HOMEHOST optimus" in
/etc/mdadm.conf.

The workaround I am using right now is to define the array name
manually in /etc/mdadm.conf like this:

ARRAY /dev/md/root UUID=782a671c:e646f2d5:848baad0:5668ee84

This works by avoiding automatic name detection and using the defined
name (/dev/md/root), but it really seems that mdadm should know how to
determine MD_DEVNAME correctly for an already-started array if the
hostname (or homehost) is correctly set. Is this a bug in mdadm? If
so, is this the correct place to report it or is there a bug tracking
system I should use? I am using mdadm v3.3.1.

(Please cc me on replies as I am not currently subscribed to the
linux-raid list.)

Thanks,

Stephen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mdadm named array (metadata 1.2) and udev when assembling an array in initramfs
  2014-11-01 18:53 mdadm named array (metadata 1.2) and udev when assembling an array in initramfs Stephen Kent
@ 2014-11-04  9:06 ` Michael Tokarev
  2014-11-04 18:17   ` Stephen Kent
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2014-11-04  9:06 UTC (permalink / raw)
  To: Stephen Kent, linux-raid

01.11.2014 21:53, Stephen Kent wrote:
> I have set up a machine to use an md array as the root device. I have
> created the array with metadata type 1.2, name "root," on host
> "optimus" (so the full metadata name is "optimus:root").
> 
> I'm using Gentoo Linux (kernel 3.16.5-gentoo), and previously I had no
> initramfs so I wrote a short one to assemble the array. My initramfs
> sets the hostname and runs "mdadm -As," which correctly auto-assembles
> the root device array on /dev/md/root (even without an
> /etc/mdadm.conf).
> 
> Once the initramfs script is finished, init starts which then starts
> udev. Now, at this point the array is already assembled, but the
> /dev/md/* name is lost (and so is /run/mdadm/map) since those files
> were on the initramfs' tempfs root.

This is your problem.  You should not lose neither /dev nor /run
when switching root.  Usual thing to do is to mount tmpfs /dev and
tmpfs /run in initramfs and do mount --move /dev /root/dev (and
the same for /run) before switching root.

Thanks,

/mjt

>   udev creates a /dev/mdXXX node
> (ex. /dev/md127) and then runs a rule to try to figure out the
> /dev/md/* name, which should be /dev/md/root. The default udev rule
> calls mdadm --detail --export /dev/md127, which should print
> MD_DEVNAME=root for udev, but instead it prints
> MD_DEVNAME=optimus:root, and the symlink in /dev/md gets created as
> /dev/md/optimus:root.
> 
> I think this is a bug in mdadm, but I'm not sure how to dig into it. I
> have made sure that my main OS init sets the hostname before starting
> udev, and I have tried with and without "HOMEHOST optimus" in
> /etc/mdadm.conf.
> 
> The workaround I am using right now is to define the array name
> manually in /etc/mdadm.conf like this:
> 
> ARRAY /dev/md/root UUID=782a671c:e646f2d5:848baad0:5668ee84
> 
> This works by avoiding automatic name detection and using the defined
> name (/dev/md/root), but it really seems that mdadm should know how to
> determine MD_DEVNAME correctly for an already-started array if the
> hostname (or homehost) is correctly set. Is this a bug in mdadm? If
> so, is this the correct place to report it or is there a bug tracking
> system I should use? I am using mdadm v3.3.1.
> 
> (Please cc me on replies as I am not currently subscribed to the
> linux-raid list.)
> 
> Thanks,
> 
> Stephen
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mdadm named array (metadata 1.2) and udev when assembling an array in initramfs
  2014-11-04  9:06 ` Michael Tokarev
@ 2014-11-04 18:17   ` Stephen Kent
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Kent @ 2014-11-04 18:17 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: linux-raid

On Tue, Nov 4, 2014 at 1:06 AM, Michael Tokarev <mjt@tls.msk.ru> wrote:
>
> 01.11.2014 21:53, Stephen Kent wrote:
> > I have set up a machine to use an md array as the root device. I have
> > created the array with metadata type 1.2, name "root," on host
> > "optimus" (so the full metadata name is "optimus:root").
> >
> > I'm using Gentoo Linux (kernel 3.16.5-gentoo), and previously I had no
> > initramfs so I wrote a short one to assemble the array. My initramfs
> > sets the hostname and runs "mdadm -As," which correctly auto-assembles
> > the root device array on /dev/md/root (even without an
> > /etc/mdadm.conf).
> >
> > Once the initramfs script is finished, init starts which then starts
> > udev. Now, at this point the array is already assembled, but the
> > /dev/md/* name is lost (and so is /run/mdadm/map) since those files
> > were on the initramfs' tempfs root.
>
> This is your problem.  You should not lose neither /dev nor /run
> when switching root.  Usual thing to do is to mount tmpfs /dev and
> tmpfs /run in initramfs and do mount --move /dev /root/dev (and
> the same for /run) before switching root.
>
> Thanks,
>
> /mjt

Hm, interesting. I didn't realize a mount point could be moved, that's
good to know.

My initramfs is a short custom shell script that I wrote, basically
all it does is assemble the array and mount the root filesystem. I'm
not mounting a tmpfs and/or udev on /run and /dev, so unfortunately
there aren't any mount points to move to the target root mountpoint at
the end of init. /run and /dev are only mounted on my machine after
leaving the initramfs.

Fortunately, NeilBrown's patch works for me which solves the problem
and allows mdadm to work correctly with a minimal initramfs.

Stephen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mdadm named array (metadata 1.2) and udev when assembling an array in initramfs
  2014-11-03  4:16 ` Stephen Kent
@ 2014-11-03  5:43   ` NeilBrown
  0 siblings, 0 replies; 6+ messages in thread
From: NeilBrown @ 2014-11-03  5:43 UTC (permalink / raw)
  To: Stephen Kent; +Cc: linux RAID

[-- Attachment #1: Type: text/plain, Size: 2681 bytes --]

On Sun, 2 Nov 2014 20:16:34 -0800 Stephen Kent <smkent@smkent.net> wrote:

> On Sun, Nov 2, 2014 at 5:50 PM, NeilBrown <neilb@suse.de> wrote:
> >
> > Hi Stephen,
> >  thanks for the bug report.
> > This patch should fix it.
> >
> > NeilBrown
> >
> > From 628cdf19ea35daad22e409e51c0abc7ffb19d6aa Mon Sep 17 00:00:00 2001
> > From: NeilBrown <neilb@suse.de>
> > Date: Mon, 3 Nov 2014 12:49:05 +1100
> > Subject: [PATCH] Rebuildmap: strip local host name from device name.
> >
> > When /run/mdadm/map is being rebuilt, e.g. by "mdadm -Ir",
> > if the device doesn't exist in /dev, we have to choose
> > a name.
> > Currently we don't strip the hostname which is wrong if
> > it is the local host.
> >
> > Reported-by: Stephen Kent <smkent@smkent.net>
> > Signed-off-by: NeilBrown <neilb@suse.de>
> >
> > diff --git a/mapfile.c b/mapfile.c
> > index 4e7f24214b8a..41599df05f97 100644
> > --- a/mapfile.c
> > +++ b/mapfile.c
> > @@ -455,12 +455,19 @@ void RebuildMap(void)
> >                                                         sep = "";
> >                                                 }
> >                                         }
> > -                                       if (strchr(name, ':'))
> > -                                               /* probably a uniquifying
> > +                                       if (strchr(name, ':')) {
> > +                                               /* Probably a uniquifying
> >                                                  * hostname prefix.  Allow
> > -                                                * without a suffix
> > +                                                * without a suffix, and strip
> > +                                                * hostname if it is us.
> >                                                  */
> > +                                               if (homehost && unum == -1 &&
> > +                                                   strncmp(name, homehost,
> > +                                                           strlen(homehost)) == 0 &&
> > +                                                   name[strlen(homehost)] == ':')
> > +                                                       name += strlen(homehost)+1;
> >                                                 unum = -1;
> > +                                       }
> >
> >                                         while (conflict) {
> >                                                 if (unum >= 0)
> 
> 
> Your patch works for me! Thanks so much for taking a look.
> 


Great - thanks for the confirmation.  It will be in the next release.

NeilBrown

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mdadm named array (metadata 1.2) and udev when assembling an array in initramfs
  2014-11-03  1:50 NeilBrown
@ 2014-11-03  4:16 ` Stephen Kent
  2014-11-03  5:43   ` NeilBrown
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Kent @ 2014-11-03  4:16 UTC (permalink / raw)
  To: NeilBrown; +Cc: linux RAID

On Sun, Nov 2, 2014 at 5:50 PM, NeilBrown <neilb@suse.de> wrote:
>
> Hi Stephen,
>  thanks for the bug report.
> This patch should fix it.
>
> NeilBrown
>
> From 628cdf19ea35daad22e409e51c0abc7ffb19d6aa Mon Sep 17 00:00:00 2001
> From: NeilBrown <neilb@suse.de>
> Date: Mon, 3 Nov 2014 12:49:05 +1100
> Subject: [PATCH] Rebuildmap: strip local host name from device name.
>
> When /run/mdadm/map is being rebuilt, e.g. by "mdadm -Ir",
> if the device doesn't exist in /dev, we have to choose
> a name.
> Currently we don't strip the hostname which is wrong if
> it is the local host.
>
> Reported-by: Stephen Kent <smkent@smkent.net>
> Signed-off-by: NeilBrown <neilb@suse.de>
>
> diff --git a/mapfile.c b/mapfile.c
> index 4e7f24214b8a..41599df05f97 100644
> --- a/mapfile.c
> +++ b/mapfile.c
> @@ -455,12 +455,19 @@ void RebuildMap(void)
>                                                         sep = "";
>                                                 }
>                                         }
> -                                       if (strchr(name, ':'))
> -                                               /* probably a uniquifying
> +                                       if (strchr(name, ':')) {
> +                                               /* Probably a uniquifying
>                                                  * hostname prefix.  Allow
> -                                                * without a suffix
> +                                                * without a suffix, and strip
> +                                                * hostname if it is us.
>                                                  */
> +                                               if (homehost && unum == -1 &&
> +                                                   strncmp(name, homehost,
> +                                                           strlen(homehost)) == 0 &&
> +                                                   name[strlen(homehost)] == ':')
> +                                                       name += strlen(homehost)+1;
>                                                 unum = -1;
> +                                       }
>
>                                         while (conflict) {
>                                                 if (unum >= 0)


Your patch works for me! Thanks so much for taking a look.

Stephen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mdadm named array (metadata 1.2) and udev when assembling an array in initramfs
@ 2014-11-03  1:50 NeilBrown
  2014-11-03  4:16 ` Stephen Kent
  0 siblings, 1 reply; 6+ messages in thread
From: NeilBrown @ 2014-11-03  1:50 UTC (permalink / raw)
  To: Stephen Kent; +Cc: linux RAID

[-- Attachment #1: Type: text/plain, Size: 1343 bytes --]


Hi Stephen,
 thanks for the bug report.
This patch should fix it.

NeilBrown

From 628cdf19ea35daad22e409e51c0abc7ffb19d6aa Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Mon, 3 Nov 2014 12:49:05 +1100
Subject: [PATCH] Rebuildmap: strip local host name from device name.

When /run/mdadm/map is being rebuilt, e.g. by "mdadm -Ir",
if the device doesn't exist in /dev, we have to choose
a name.
Currently we don't strip the hostname which is wrong if
it is the local host.

Reported-by: Stephen Kent <smkent@smkent.net>
Signed-off-by: NeilBrown <neilb@suse.de>

diff --git a/mapfile.c b/mapfile.c
index 4e7f24214b8a..41599df05f97 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -455,12 +455,19 @@ void RebuildMap(void)
 							sep = "";
 						}
 					}
-					if (strchr(name, ':'))
-						/* probably a uniquifying
+					if (strchr(name, ':')) {
+						/* Probably a uniquifying
 						 * hostname prefix.  Allow
-						 * without a suffix
+						 * without a suffix, and strip
+						 * hostname if it is us.
 						 */
+						if (homehost && unum == -1 &&
+						    strncmp(name, homehost,
+							    strlen(homehost)) == 0 &&
+						    name[strlen(homehost)] == ':')
+							name += strlen(homehost)+1;
 						unum = -1;
+					}
 
 					while (conflict) {
 						if (unum >= 0)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-04 18:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-01 18:53 mdadm named array (metadata 1.2) and udev when assembling an array in initramfs Stephen Kent
2014-11-04  9:06 ` Michael Tokarev
2014-11-04 18:17   ` Stephen Kent
2014-11-03  1:50 NeilBrown
2014-11-03  4:16 ` Stephen Kent
2014-11-03  5:43   ` NeilBrown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.