linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Berra <bluca@comedia.it>
To: "Neil Brown (neilb@suse.de)" <neilb@suse.de>
Cc: "linux-raid@vger.kernel.org" <linux-raid@vger.kernel.org>
Subject: [mdadm PATCH 2/2] fix mdmon takeover
Date: Sat, 27 Feb 2010 16:07:51 +0100	[thread overview]
Message-ID: <2-2.1267282753.git.bluca@comedia.it> (raw)
In-Reply-To: <cover.1267282753.git.bluca@comedia.it>

there are two cases that would result in two mdmon processes for the
same array
takeover not detecting pid file in ALT_RUN
if running mdmon a second time without "--takeover"

Signed-off-by: Luca Berra <bluca@comedia.it>
---
  mdmon.c |   10 +++++++++-
  msg.c   |    2 +-
  util.c  |    4 ++--
  3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/mdmon.c b/mdmon.c
index d593ebc..a2b7946 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -441,7 +441,6 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
  	sigaction(SIGPIPE, &act, NULL);
  
  	if (takeover) {
-		pid_dir = VAR_RUN;
  		victim = mdmon_pid(container->devnum);
  		if (victim < 0) {
  			pid_dir = ALT_RUN;
@@ -453,6 +452,15 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
  
  	ignore = chdir("/");
  	if (victim < 0) {
+		pid_dir = ALT_RUN;
+		if (ping_monitor(container->devname) == 0) {
+			fprintf(stderr, "mdmon: %s already managed\n",
+				container->devname);
+			if (!takeover)
+				fprintf(stderr, "\trun mdmon --takeover instead\n");
+			exit(3);
+		}
+		pid_dir = VAR_RUN;
  		if (ping_monitor(container->devname) == 0) {
  			fprintf(stderr, "mdmon: %s already managed\n",
  				container->devname);
diff --git a/msg.c b/msg.c
index cc07b96..d2d8445 100644
--- a/msg.c
+++ b/msg.c
@@ -147,7 +147,7 @@ int connect_monitor(char *devname)
  	int pos;
  	char *c;
  
-	pos = sprintf(path, "%s/", VAR_RUN);
+	pos = sprintf(path, "%s/", pid_dir);
  	if (is_subarray(devname)) {
  		devname++;
  		c = strchr(devname, '/');
diff --git a/util.c b/util.c
index 1def2a0..2fe566d 100644
--- a/util.c
+++ b/util.c
@@ -1475,11 +1475,11 @@ int mdmon_pid(int devnum)
  	fd = open(path, O_RDONLY | O_NOATIME, 0);
  
  	if (fd < 0)
-		return 0;
+		return -1;
  	n = read(fd, pid, 9);
  	close(fd);
  	if (n <= 0)
-		return 0;
+		return -1;
  	return atoi(pid);
  }
  
-- 
1.7.0

-- 
Luca Berra -- bluca@comedia.it
         Communication Media & Services S.r.l.
  /"\
  \ /     ASCII RIBBON CAMPAIGN
   X        AGAINST HTML MAIL
  / \

  parent reply	other threads:[~2010-02-27 15:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-27 15:05 [mdadm PATCH 0/2] *** mdmon fixes *** Luca Berra
2010-02-27 15:07 ` [mdadm PATCH 1/2] fix mdmon option parsing Luca Berra
2010-02-27 15:21   ` Luca Berra
2010-03-02  5:40   ` Neil Brown
2010-03-02  7:42     ` Luca Berra
2010-02-27 15:07 ` Luca Berra [this message]
2010-03-03  0:52   ` [mdadm PATCH 2/2] fix mdmon takeover Neil Brown
2010-02-28 14:41 ` [mdadm PATCH 0/2] *** mdmon fixes *** Luca Berra
2010-02-28 14:42   ` [mdadm PATCH 3/9] add missing newline to mdmon usage message Luca Berra
2010-02-28 14:42   ` [mdadm PATCH 4/9] mdmon: check select a writable pid_dir Luca Berra
2010-03-03  1:07     ` Neil Brown
2010-02-28 14:43   ` [mdadm PATCH 5/9] mdmon: mdmon_pid should return pid from either dir Luca Berra
2010-03-03  1:50     ` Neil Brown
2010-03-03  6:44       ` Luca Berra
2010-03-03  6:55         ` Neil Brown
2010-03-03  7:09           ` Luca Berra
2010-02-28 14:44   ` [mdadm PATCH 6/9] mdmon: connect_monitor should use socket " Luca Berra
2010-03-03  1:51     ` Neil Brown
2010-02-28 14:45   ` [mdadm PATCH 7/9] mdmon: move pid_dir to mdmon.c Luca Berra
2010-02-28 14:45   ` [mdadm PATCH 8/9] mdmon: rework startup and takeover logic Luca Berra
2010-03-03  1:52     ` Neil Brown
2010-03-03  6:48       ` Luca Berra
2010-02-28 14:46   ` [mdadm PATCH 9/9] allow redefinition of VAR_RUN Luca Berra
2010-03-03  1:53     ` Neil Brown
2010-02-28 15:41   ` [mdadm PATCH 0/2] *** mdmon fixes *** Bill Davidsen
2010-02-28 17:37     ` Luca Berra

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=2-2.1267282753.git.bluca@comedia.it \
    --to=bluca@comedia.it \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    /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).