From: Luca Berra <bluca@comedia.it>
To: "linux-raid@vger.kernel.org" <linux-raid@vger.kernel.org>
Cc: "Neil Brown (neilb@suse.de)" <neilb@suse.de>
Subject: [mdadm PATCH 5/9] mdmon: mdmon_pid should return pid from either dir
Date: Sun, 28 Feb 2010 15:43:40 +0100 [thread overview]
Message-ID: <20100228144340.GD24781@maude.comedia.it> (raw)
In-Reply-To: <cover.1267282753.git.bluca@comedia.it>
mdmon_pid is called by mdmon_running to check if mdmon is running, so
the pid file should be checked in either VAR_RUN or ALT_RUN
Signed-off-by: Luca Berra <bluca@comedia.it>
---
mdadm.h | 2 +-
mdmon.c | 6 +++---
util.c | 14 ++++++++++++--
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/mdadm.h b/mdadm.h
index df3a056..7efa8bf 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -897,7 +897,7 @@ extern int open_container(int fd);
extern char *pid_dir;
extern int mdmon_running(int devnum);
-extern int mdmon_pid(int devnum);
+extern int mdmon_pid(int devnum, const char *pid_dir);
extern int check_env(char *name);
extern __u32 random32(void);
extern int start_mdmon(int devnum);
diff --git a/mdmon.c b/mdmon.c
index 57fd492..3410e84 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -441,10 +441,10 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
sigaction(SIGPIPE, &act, NULL);
if (takeover) {
- victim = mdmon_pid(container->devnum);
+ victim = mdmon_pid(container->devnum, pid_dir);
if (victim < 0) {
pid_dir = ALT_RUN;
- victim = mdmon_pid(container->devnum);
+ victim = mdmon_pid(container->devnum, pid_dir);
}
if (victim >= 0)
victim_sock = connect_monitor(container->devname);
@@ -467,7 +467,7 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
exit(3);
}
/* if there is a pid file, kill whoever is there just in case */
- victim = mdmon_pid(container->devnum);
+ victim = mdmon_pid(container->devnum, NULL);
}
if (container->ss->load_super(container, mdfd, devname)) {
fprintf(stderr, "mdmon: Cannot load metadata for %s\n",
diff --git a/util.c b/util.c
index 2fe566d..50e04bf 100644
--- a/util.c
+++ b/util.c
@@ -1465,12 +1465,22 @@ int fd2devnum(int fd)
char *pid_dir = VAR_RUN;
-int mdmon_pid(int devnum)
+int mdmon_pid(int devnum, const char *pid_dir)
{
char path[100];
char pid[10];
int fd;
int n;
+
+ /* if pid_dir is null try to detect it */
+ if (!pid_dir) {
+ n = mdmon_pid(devnum, VAR_RUN);
+ if (n >= 0)
+ return n;
+ else
+ return mdmon_pid(devnum, ALT_RUN);
+ }
+
sprintf(path, "%s/%s.pid", pid_dir, devnum2devname(devnum));
fd = open(path, O_RDONLY | O_NOATIME, 0);
@@ -1485,7 +1495,7 @@ int mdmon_pid(int devnum)
int mdmon_running(int devnum)
{
- int pid = mdmon_pid(devnum);
+ int pid = mdmon_pid(devnum, NULL);
if (pid <= 0)
return 0;
if (kill(pid, 0) == 0)
--
1.7.0
--
Luca Berra -- bluca@comedia.it
Communication Media & Services S.r.l.
/"\
\ / ASCII RIBBON CAMPAIGN
X AGAINST HTML MAIL
/ \
next prev parent reply other threads:[~2010-02-28 14:43 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 ` [mdadm PATCH 2/2] fix mdmon takeover Luca Berra
2010-03-03 0:52 ` Neil Brown
2010-02-28 14:41 ` [mdadm PATCH 0/2] *** mdmon fixes *** Luca Berra
2010-02-28 15:41 ` Bill Davidsen
2010-02-28 17:37 ` 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 ` Luca Berra [this message]
2010-03-03 1:50 ` [mdadm PATCH 5/9] mdmon: mdmon_pid should return pid from either dir 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
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=20100228144340.GD24781@maude.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 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.