Skip to contentSkip to conversation

mdadm: autodetect being run in an initramfs

PATCH In review Dave Reisner 4 participants 7 messages Sep 27, 2012 1 message not in the archive MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mdadm: autodetect being run in an initramfs

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +5 -0
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
 		exit(0);
 	}
 
+	/* auto-detect being on an initramfs
+	 * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */
+	if (access("/etc/initrd-release", F_OK) == 0)
+		__offroot = 1;
+
 	if (!mode && devs_found) {
 		mode = MISC;
 		devmode = 'Q';
Signature · 1 line
1.7.12.1
#1 lore raw
Quoted 6 lines · Dave Reisner

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

And what shall non-systemd systems do?

I don't have /etc/initrd-release in my initramfs-tools generated initrd, and so far didn't have a usecase for it. Should it be an empty file?

Quoted 28 lines
---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +5 -1
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
+       /* auto-detect being on an initramfs
+        * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */
+       if (access("/etc/initrd-release", F_OK) == 0)
+               __offroot = 1;
+
        if (!mode && devs_found) {
                mode = MISC;
                devmode = 'Q';
--

1.7.12.1

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CA+mSPTgDnq8Xi+xCZte1WtORZhnV8S0=FXsm=wM0N1LfLpgtfQ@mail.gmail.com

#3 lore raw
Quoted 17 lines · Dave Reisner
Quoted 10 lines · Dmitrijs Ledkovs
Quoted 6 lines · Dave Reisner

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

And what shall non-systemd systems do?

Add the file, of course!

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

I don't have /etc/initrd-release in my initramfs-tools generated initrd, and so far didn't have a usecase for it. Should it be an empty file?

Yep, just an empty file. It only serves to be a marker since there really isn't any other heuristic for detecting early userspace.

This is a bit backwards. As far as I understand the systemd & udev merge now means that udev rules cannot spawn long running processes and instead should have a proper systemd units instead. And since systemd is running all of the initramfs surely it can set up an environment without adding pointless files, e.g. an environment variable?

Please correct me, if I am wrong, cause I really don't understand either this patch or systemd or both.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +2 -0
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
+       /* auto-detect being on an initramfs
+        *

http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */

mdadm.c +3 -1
+       if (access("/etc/initrd-release", F_OK) == 0)
+               __offroot = 1;
+
        if (!mode && devs_found) {
                mode = MISC;
                devmode = 'Q';
--

1.7.12.1

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 23 lines · Dmitrijs Ledkovs
Quoted 22 lines · Dave Reisner
Quoted 10 lines · Dmitrijs Ledkovs
Quoted 6 lines · Dave Reisner

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

And what shall non-systemd systems do?

Add the file, of course!

Quoted 5 lines

I don't have /etc/initrd-release in my initramfs-tools generated initrd, and so far didn't have a usecase for it. Should it be an empty file?

Quoted 7 lines
Quoted 3 lines

Yep, just an empty file. It only serves to be a marker since there really isn't any other heuristic for detecting early userspace.

This is a bit backwards. As far as I understand the systemd & udev merge now means that udev rules cannot spawn long running processes and instead should have a proper systemd units instead.

udev rules were never allowed to spawn long running processes. The merger means nothing in this regard. The only point of this patch is to ensure that mdmon is spawned via mdadm with the correct --offroot flag so that it isn't mercilessly slaughtered later on. This auto-spawn behavior happens today, but without the --offroot flag.

Quoted 3 lines

And since systemd is running all of the initramfs surely it can set up an environment without adding pointless files, e.g. an environment variable?

How would such an environment variable be set?

Not everyone runs systemd in early userspace. To my knowledge, only Fedora does this currently. However, everyone can only benefit from this marker file in their initramfs. For those not running systemd at all, the presence of this file has no perceivable effect.

Quoted 34 lines

Please correct me, if I am wrong, cause I really don't understand either this patch or systemd or both.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +2 -0
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
                exit(0);
        }
 
+       /* auto-detect being on an initramfs
+        *

http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */

mdadm.c +3 -1
+       if (access("/etc/initrd-release", F_OK) == 0)
+               __offroot = 1;
+
        if (!mode && devs_found) {
                mode = MISC;
                devmode = 'Q';
--

1.7.12.1

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Dave Reisner
Quoted 17 lines · On Thu, 27 Sep 2012 10:41:03 -0400 Dave Reisner <[email protected]> wrote:

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +0 -0
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
 		exit(0);

mdadm.c int main(int argc, char *argv[]) · line 1116

Quoted 10 lines
mdadm.c +5 -0
 	}
 
+	/* auto-detect being on an initramfs
+	 * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */
+	if (access("/etc/initrd-release", F_OK) == 0)
+		__offroot = 1;
+
 	if (!mode && devs_found) {
 		mode = MISC;
 		devmode = 'Q';

What is the problem with adding the --offroot flag to every place in the initrd that starts mdadm?

(Actually I'm contemplating making --offroot the default so this might become a non-issue)

NeilBrown

#6 lore raw
Quoted 22 lines · NeilBrown
Quoted 19 lines · On Thu, 27 Sep 2012 10:41:03 -0400 Dave Reisner <[email protected]> wrote:

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +0 -0
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
 		exit(0);
 	}
 
Quoted 11 lines

mdadm.c int main(int argc, char *argv[]) · line 1116

Quoted 8 lines
mdadm.c +5 -0
+	/* auto-detect being on an initramfs
+	 * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */
+	if (access("/etc/initrd-release", F_OK) == 0)
+		__offroot = 1;
+
 	if (!mode && devs_found) {
 		mode = MISC;
 		devmode = 'Q';

What is the problem with adding the --offroot flag to every place in the initrd that starts mdadm?

The assumption is that mdadm is being called via udev for assembly, so we'd need to maintain a separate udev rule explicitly for the initramfs. I'd rather not do that.

Quoted 2 lines

(Actually I'm contemplating making --offroot the default so this might become a non-issue)

That'd be great!

#7 lore raw
Quoted 35 lines · On Thu, 27 Sep 2012 18:53:02 -0400 Dave Reisner <[email protected]> wrote:
Quoted 22 lines · NeilBrown
Quoted 19 lines · On Thu, 27 Sep 2012 10:41:03 -0400 Dave Reisner <[email protected]> wrote:

Key off of the existance of /etc/initrd-release as an indicator that mdadm is running in early userspace and set the __offroot flag. This allows the same udev-based assembly rules to be valid both off and on root and, moreover, will propagate to mdmon, should it need to be started.

---
 mdadm.c | 5 +++++
 1 file changed, 5 insertions(+)
mdadm.c +0 -0
index 4c7c5ea..557e00b 100644
@@ -1106,6 +1106,11 @@ int main(int argc, char *argv[])
 		exit(0);
 	}
 
Quoted 11 lines

mdadm.c int main(int argc, char *argv[]) · line 1116

Quoted 8 lines
mdadm.c +5 -0
+	/* auto-detect being on an initramfs
+	 * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */
+	if (access("/etc/initrd-release", F_OK) == 0)
+		__offroot = 1;
+
 	if (!mode && devs_found) {
 		mode = MISC;
 		devmode = 'Q';

What is the problem with adding the --offroot flag to every place in the initrd that starts mdadm?

Quoted 3 lines

The assumption is that mdadm is being called via udev for assembly, so we'd need to maintain a separate udev rule explicitly for the initramfs. I'd rather not do that.

Then use --offroot for the 'standard' udev rules too.

Quoted 5 lines
Quoted 3 lines

(Actually I'm contemplating making --offroot the default so this might become a non-issue)

That'd be great!

Your support is noted - thanks :-)

NeilBrown