linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jim Rees <rees@umich.edu>
To: Benny Halevy <bhalevy@panasas.com>
Cc: linux-nfs@vger.kernel.org, peter honeyman <honey@citi.umich.edu>
Subject: [PATCH 5/6] add "-d" option to just do discovery then exit
Date: Tue, 2 Nov 2010 16:10:42 -0400	[thread overview]
Message-ID: <162b681df7912e12c89948261775da5bf5b67a89.1288726186.git.rees@umich.edu> (raw)
In-Reply-To: <cover.1288726186.git.rees@umich.edu>

Signed-off-by: Jim Rees <rees@umich.edu>
---
 utils/blkmapd/device-discovery.c |   69 +++++++++++++++++++++----------------
 1 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c
index c8bd39c..6b1f942 100644
--- a/utils/blkmapd/device-discovery.c
+++ b/utils/blkmapd/device-discovery.c
@@ -398,54 +398,63 @@ int bl_run_disk_inquiry_process(int fd)
 /* Daemon */
 int main(int argc, char **argv)
 {
-	int fd, opt, fg = 0, ret = 1;
+	int fd = -1, opt, dflag = 0, fg = 0, ret = 1;
 	struct stat statbuf;
 	char pidbuf[64];
 
-	while ((opt = getopt(argc, argv, "f")) != -1) {
+	while ((opt = getopt(argc, argv, "df")) != -1) {
 		switch (opt) {
+		case 'd':
+			dflag = 1;
+			break;
 		case 'f':
 			fg = 1;
 			break;
 		}
 	}
 
-	if (!stat(PID_FILE, &statbuf)) {
-		fprintf(stderr, "Pid file already existed\n");
-		return -1;
-	}
+	if (fg) {
+		openlog("blkmapd", LOG_PERROR, 0);
+	} else {
+		if (!stat(PID_FILE, &statbuf)) {
+			fprintf(stderr, "Pid file already existed\n");
+			return -1;
+		}
 
-	if (!fg && daemon(0, 0) != 0) {
-		fprintf(stderr, "Daemonize failed\n");
-		return -1;
-	}
+		if (daemon(0, 0) != 0) {
+			fprintf(stderr, "Daemonize failed\n");
+			return -1;
+		}
 
-	openlog("blkmapd", LOG_PID, 0);
-	fd = open(PID_FILE, O_WRONLY | O_CREAT, 0644);
-	if (fd < 0) {
-		BL_LOG_ERR("Create pid file failed\n");
-		return -1;
-	}
+		openlog("blkmapd", LOG_PID, 0);
+		fd = open(PID_FILE, O_WRONLY | O_CREAT, 0644);
+		if (fd < 0) {
+			BL_LOG_ERR("Create pid file failed\n");
+			return -1;
+		}
 
-	if (lockf(fd, F_TLOCK, 0) < 0) {
-		BL_LOG_ERR("Lock pid file failed\n");
-		close(fd);
-		return -1;
-	}
-	ftruncate(fd, 0);
-	sprintf(pidbuf, "%d\n", getpid());
-	write(fd, pidbuf, strlen(pidbuf));
-
-	/* open pipe file */
-	fd = open(BL_PIPE_FILE, O_RDWR);
-	if (fd < 0) {
-		BL_LOG_ERR("open pipe file error\n");
-		return -1;
+		if (lockf(fd, F_TLOCK, 0) < 0) {
+			BL_LOG_ERR("Lock pid file failed\n");
+			close(fd);
+			return -1;
+		}
+		ftruncate(fd, 0);
+		sprintf(pidbuf, "%d\n", getpid());
+		write(fd, pidbuf, strlen(pidbuf));
+
+		/* open pipe file */
+		fd = open(BL_PIPE_FILE, O_RDWR);
+		if (fd < 0) {
+			BL_LOG_ERR("open pipe file error\n");
+			return -1;
+		}
 	}
 
 	while (1) {
 		/* discover device when needed */
 		bl_discover_devices();
+		if (dflag)
+			break;
 
 		ret = bl_run_disk_inquiry_process(fd);
 		if (ret < 0) {
-- 
1.7.1


  parent reply	other threads:[~2010-11-02 20:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-02 20:08 [PATCH 0/6] nfs-utils: Cumulative patches for blkmapd Jim Rees
2010-11-02 20:09 ` [PATCH 1/6] blkmapd: get rid of config file and instead examine all block devices Jim Rees
2010-11-02 20:09 ` [PATCH 2/6] blkmapd: don't rescan periodically Jim Rees
2010-11-02 20:10 ` [PATCH 3/6] blkmapd: don't use atomicio() where it's not needed Jim Rees
2010-11-02 20:10 ` [PATCH 4/6] ignore passive devices before checking serial numbers Jim Rees
2010-11-02 20:10 ` Jim Rees [this message]
2010-11-02 20:11 ` [PATCH 6/6] Various bug fixes and cleanups Jim Rees
2010-11-03  7:08 ` [PATCH 0/6] nfs-utils: Cumulative patches for blkmapd Benny Halevy

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=162b681df7912e12c89948261775da5bf5b67a89.1288726186.git.rees@umich.edu \
    --to=rees@umich.edu \
    --cc=bhalevy@panasas.com \
    --cc=honey@citi.umich.edu \
    --cc=linux-nfs@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).