Skip to contentSkip to conversation

blkmapd: allow blocklayoutdriver module to load/unload

PATCH New Peng Tao 1 participant 2 messages Aug 13, 2012

Subsystems (2)
lore
Share & tools
lore

Peng Tao

author
#0 lore raw

PATCH 1/2 blkmapd: allow blocklayoutdriver module to load/unload

User may load/unload blocklayoutdriver module dynanmically. So we handle it by watching the pipe file creation/deletion.

---
 configure.ac                     |    1 +
 utils/blkmapd/device-discovery.c |  104 ++++++++++++++++++++++++++++++-------
 2 files changed, 85 insertions(+), 20 deletions(-)
configure.ac +1 -0
index 18ee11a..a174bf4 100644
@@ -288,6 +288,7 @@ fi
 if test "$enable_nfsv41" = yes; then
   AC_CHECK_LIB([devmapper], [dm_task_create], [LIBDEVMAPPER="-ldevmapper"], AC_MSG_ERROR([libdevmapper needed]))
   AC_CHECK_HEADER(libdevmapper.h, , AC_MSG_ERROR([Cannot find devmapper header file libdevmapper.h]))
+  AC_CHECK_HEADER(sys/inotify.h, , AC_MSG_ERROR([Cannot find header file sys/inotify.h]))
 fi
 
 dnl enable nfsidmap when its support by libnfsidmap
utils/blkmapd/device-discovery.c +84 -20

163 lines not on this page · raw message

Signature · 1 line
1.7.1.262.g5ef3d
author
#1 lore raw

PATCH 2/2 blkmapd: proper signal handling

---
 utils/blkmapd/device-discovery.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
utils/blkmapd/device-discovery.c +17 -1
index 8eddf50..df4627e 100644
@@ -36,6 +36,7 @@
 #include <scsi/scsi.h>
 #include <scsi/scsi_ioctl.h>
 #include <scsi/sg.h>
+#include <signal.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -61,6 +62,7 @@
 
 struct bl_disk *visible_disk_list;
 int    bl_watch_fd, bl_pipe_fd, nfs_pipedir_wfd, rpc_pipedir_wfd;
+int    pidfd = -1;
 
 struct bl_disk_path *bl_get_path(const char *filepath,
 				 struct bl_disk_path *paths)
@@ -431,10 +433,20 @@ static int bl_event_helper(void)
 	return ret;
 }
 
+void sig_die(int signal)
+{
+	if (pidfd >= 0) {
+		close(pidfd);
+		unlink(PID_FILE);
+	}
+	BL_LOG_ERR("exit on signal(%d)\n", signal);
+	exit(1);
+}
+
 /* Daemon */
 int main(int argc, char **argv)
 {
-	int pidfd = -1, opt, dflag = 0, fg = 0, ret = 1;
+	int opt, dflag = 0, fg = 0, ret = 1;
 	struct stat statbuf;
 	char pidbuf[64];
 
@@ -479,6 +491,10 @@ int main(int argc, char **argv)
 		write(pidfd, pidbuf, strlen(pidbuf));
 	}
 
+	signal(SIGINT, sig_die);
+	signal(SIGTERM, sig_die);
+	signal(SIGHUP, SIG_IGN);
+
 	if (dflag) {
 		bl_discover_devices();
 		exit(0);
Signature · 1 line
1.7.1.262.g5ef3d