linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Jes.Sorensen@redhat.com
Cc: linux-raid@vger.kernel.org, dledford@redhat.com, harald@redhat.com
Subject: Re: [PATCH 1/3] Add support for launching mdmon via systemctl instead of fork/exec
Date: Tue, 22 Jan 2013 16:46:23 +1100	[thread overview]
Message-ID: <20130122164623.1962171b@notabene.brown> (raw)
In-Reply-To: <1358774578-2183-2-git-send-email-Jes.Sorensen@redhat.com>

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

On Mon, 21 Jan 2013 14:22:56 +0100 Jes.Sorensen@redhat.com wrote:

> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> To launch mdmon via systemctl, a new command line argument is added to
> mdadm '--systemctl'. Alternatively it is possible to set the
> environment variable MDMON_SYSTEMCTL.
> 
> This allows for having mdmon launched via systemctl which avoids
> problems with it getting killed by systemd due to it ending up in the
> parent's cgroup (udev).
> 
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>

Thanks Jes.  This is certainly something that we want in some form.
Some issues:

 - I have come to the conclusion that --offroot is a bad idea.  We should
   just make that the default.  No matter whether the array is providing the
   root filesystem or not, I never want systemd (or anything else) to kill
   mdmon.  I want it to remain in control.  So the systemctl handling should
   assume offroot. e.g. there should only be one .service file.

 - on my machine (openSUSE), systemctl is in /bin, not /usr/bin.
   Would I be correct in thinking that on your machine, /bin is a symlink
   to /usr/bin?  If so, maybe we can just use "/bin/systemctl"?  If not,
   we might need to try a few different options.
   Similarly I have mdmon in /sbin, not /usr/sbin.  We we cannot all
   use /sbin, we might need to 'sed' the .service file on installation to
   match the current system.
   (I note that you didn't get Makefile to install the .services files.  I
   think we want it to - at least optionally)

 - I want the default behaviour to "do the right thing" in most case, but it
   should be possible  to over-rid (by command line option or env var or
   both).
   So I think I would like it to try systemctl and if that fails for some
   reason (either because the binary doesn't exist, or because it finds that
   the .services file doesn't exist), then it should try to exec mdmon
   directly.
   This default could be over-ridden to always run mdmon directly.

Thanks!
NeilBrown



> +++ b/mdmon.c
> @@ -188,7 +188,9 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
>  	 * might be "@dmon"
>  	 */
>  	if (n < 0 || !(strstr(buf, "mdmon") ||
> -		       strstr(buf, "@dmon")))
> +		       strstr(buf, "@dmon") ||
> +		       strstr(buf, "/usr/sbin/mdmon") ||
> +		       strstr(buf, "@usr/sbin/mdmon")))
>  		return;

As we are using "strstr", here, the second two cases will be matched by the
first case, so this change is unnecessary.


>  
>  	kill(pid, SIGTERM);
> diff --git a/util.c b/util.c
> index 6c10365..500b2bd 100644
> --- a/util.c
> +++ b/util.c
> @@ -33,6 +33,7 @@
>  #include	<signal.h>
>  
>  int __offroot;
> +int __mdmon_systemctl;
>  
>  /*
>   * following taken from linux/blkpg.h because they aren't
> @@ -1651,6 +1652,9 @@ int start_mdmon(int devnum)
>  	if (check_env("MDADM_NO_MDMON"))
>  		return 0;
>  
> +	if (check_env("MDMON_SYSTEMCTL"))
> +		__mdmon_systemctl = 1;
> +
>  	len = readlink("/proc/self/exe", pathbuf, sizeof(pathbuf)-1);
>  	if (len > 0) {
>  		char *sl;
> @@ -1674,18 +1678,33 @@ int start_mdmon(int devnum)
>  			else
>  				skipped = 0;
>  
> -		for (i = 0; paths[i]; i++)
> -			if (paths[i][0]) {
> -				if (__offroot) {
> -					execl(paths[i], "mdmon", "--offroot",
> -					      devnum2devname(devnum),
> -					      NULL);
> -				} else {
> -					execl(paths[i], "mdmon",
> -					      devnum2devname(devnum),
> -					      NULL);
> -				}
> +		if (__mdmon_systemctl) {
> +			if (__offroot) {
> +				snprintf(pathbuf, 40, "mdmon-offroot@%s.service",
> +					 devnum2devname(devnum));
> +				execl("/usr/bin/systemctl", "systemctl",
> +				      "start", pathbuf, NULL);
> +			} else {
> +				snprintf(pathbuf, 30, "mdmon@%s.service",
> +					 devnum2devname(devnum));
> +				execl("/usr/bin/systemctl", "systemctl",
> +				      "start", pathbuf, NULL);
>  			}
> +		} else {
> +			for (i = 0; paths[i]; i++)
> +				if (paths[i][0]) {
> +					if (__offroot) {
> +						execl(paths[i], "mdmon",
> +						      "--offroot",
> +						      devnum2devname(devnum),
> +						      NULL);
> +					} else {
> +						execl(paths[i], "mdmon",
> +						      devnum2devname(devnum),
> +						      NULL);
> +					}
> +				}
> +		}
>  		exit(1);
>  	case -1: pr_err("cannot run mdmon. "
>  			 "Array remains readonly\n");


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

  reply	other threads:[~2013-01-22  5:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21 13:22 [PATCH v2 0/3] support launching mdmon via systemctl Jes.Sorensen
2013-01-21 13:22 ` [PATCH 1/3] Add support for launching mdmon via systemctl instead of fork/exec Jes.Sorensen
2013-01-22  5:46   ` NeilBrown [this message]
2013-01-22  7:33     ` Jes Sorensen
2013-01-25 11:13       ` Jes Sorensen
2013-01-25 15:05         ` Jes Sorensen
2013-01-21 13:22 ` [PATCH 2/3] systemd .service files for launching mdmon via systemctl Jes.Sorensen
2013-01-21 13:22 ` [PATCH 3/3] execl() only returns in case of error Jes.Sorensen
2013-01-22  5:48   ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130122164623.1962171b@notabene.brown \
    --to=neilb@suse.de \
    --cc=Jes.Sorensen@redhat.com \
    --cc=dledford@redhat.com \
    --cc=harald@redhat.com \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).