Blame SOURCES/0064-RHBZ-1010040-fix-ID_FS-attrs.patch

671555
---
671555
 libmultipath/defaults.h       |    3 -
671555
 libmultipath/file.c           |   89 +++++++++++++++++++++++++++++++++++++++++-
671555
 libmultipath/file.h           |    3 +
671555
 libmultipath/wwids.c          |    7 ++-
671555
 multipath/main.c              |   36 +++++++++++++++-
671555
 multipath/multipath.rules     |   26 +++++++++---
671555
 multipathd/main.c             |    4 +
671555
 multipathd/multipathd.service |    2 
671555
 multipathd/pidfile.c          |    3 +
671555
 9 files changed, 160 insertions(+), 13 deletions(-)
671555
671555
Index: multipath-tools-130222/libmultipath/defaults.h
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/defaults.h
671555
+++ multipath-tools-130222/libmultipath/defaults.h
671555
@@ -24,7 +24,8 @@
671555
 #define MAX_CHECKINT(a)		(a << 2)
671555
 
671555
 #define MAX_DEV_LOSS_TMO	0x7FFFFFFF
671555
-#define DEFAULT_PIDFILE		"/var/run/multipathd.pid"
671555
+#define DEFAULT_PIDFILE		"/var/run/multipathd/multipathd.pid"
671555
+#define DEFAULT_TIMESTAMP_FILE	"/var/run/multipathd/timestamp"
671555
 #define DEFAULT_SOCKET		"/org/kernel/linux/storage/multipathd"
671555
 #define DEFAULT_CONFIGFILE	"/etc/multipath.conf"
671555
 #define DEFAULT_BINDINGS_FILE	"/etc/multipath/bindings"
671555
Index: multipath-tools-130222/libmultipath/file.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/file.c
671555
+++ multipath-tools-130222/libmultipath/file.c
671555
@@ -12,10 +12,12 @@
671555
 #include <limits.h>
671555
 #include <stdio.h>
671555
 #include <signal.h>
671555
+#include <time.h>
671555
 
671555
 #include "file.h"
671555
 #include "debug.h"
671555
 #include "uxsock.h"
671555
+#include "defaults.h"
671555
 
671555
 
671555
 /*
671555
@@ -36,8 +38,8 @@
671555
  * See the file COPYING included with this distribution for more details.
671555
  */
671555
 
671555
-static int
671555
-ensure_directories_exist(char *str, mode_t dir_mode)
671555
+int
671555
+ensure_directories_exist(const char *str, mode_t dir_mode)
671555
 {
671555
 	char *pathname;
671555
 	char *end;
671555
@@ -178,3 +180,86 @@ fail:
671555
 	close(fd);
671555
 	return -1;
671555
 }
671555
+
671555
+/* If you can't get the timestamp, return equal to just keep using the
671555
+ * existing value.
671555
+ */
671555
+int timestamp_equal(long int chk_timestamp)
671555
+{
671555
+	char buf[4096];
671555
+	FILE *file;
671555
+	long int file_timestamp;
671555
+	int ret = 1;
671555
+
671555
+	if ((file = fopen(DEFAULT_TIMESTAMP_FILE, "r")) == NULL) {
671555
+		if (errno != ENOENT)
671555
+			condlog(2, "Cannot open timestamp file [%s]: %s",
671555
+				DEFAULT_TIMESTAMP_FILE, strerror(errno));
671555
+		goto out;
671555
+	}
671555
+	errno = 0;
671555
+	if (fgets(buf, sizeof(buf), file) == NULL) {
671555
+		if (errno)
671555
+			condlog(2, "Cannot read from timestamp file: %s",
671555
+				strerror(errno));
671555
+		goto out;
671555
+	}
671555
+	if (sscanf(buf, "DM_MULTIPATH_TIMESTAMP=%ld", &file_timestamp) != 1) {
671555
+		if (errno)
671555
+			condlog(0, "Cannot get timestamp: %s", strerror(errno));
671555
+		else
671555
+			condlog(0, "invalid timestamp file [%s]: %s",
671555
+				DEFAULT_TIMESTAMP_FILE, strerror(errno));
671555
+		goto out;
671555
+	}
671555
+	if (file_timestamp != chk_timestamp) {
671555
+		condlog(3, "timestamp has changed");
671555
+		ret = 0;
671555
+	}
671555
+	else
671555
+		condlog(3, "timestamp has not changed");
671555
+out:
671555
+	if (file)
671555
+		fclose(file);
671555
+	return ret;
671555
+}
671555
+
671555
+int update_timestamp(int create)
671555
+{
671555
+	char buf[44];
671555
+	time_t timestamp;
671555
+	int fd;
671555
+	int flags = O_WRONLY;
671555
+	if (create)
671555
+		flags |= O_CREAT;
671555
+	if((fd = open(DEFAULT_TIMESTAMP_FILE, flags,
671555
+		      (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
671555
+		if (errno == ENOENT)
671555
+			return 0;
671555
+		condlog(0, "Cannot open timestamp file [%s]: %s",
671555
+			DEFAULT_TIMESTAMP_FILE, strerror(errno));
671555
+		return 1;
671555
+	}
671555
+	if (ftruncate(fd, 0) < 0) {
671555
+		condlog(0, "Cannot truncate timestamp file [%s]: %s",
671555
+			DEFAULT_TIMESTAMP_FILE, strerror(errno));
671555
+		goto fail;
671555
+	}
671555
+	if (time(&timestamp) == -1) {
671555
+		condlog(0, "Cannot get current time: %s", strerror(errno));
671555
+		goto fail;
671555
+	}
671555
+	memset(buf, 0, sizeof(buf));
671555
+	snprintf(buf, sizeof(buf)-1, "DM_MULTIPATH_TIMESTAMP=%ld\n",
671555
+		 timestamp);
671555
+	if (write(fd, buf, strlen(buf)) != strlen(buf)) {
671555
+		condlog(0, "Cannot write out timestamp to %s: %s",
671555
+			DEFAULT_TIMESTAMP_FILE, strerror(errno));
671555
+		goto fail;
671555
+	}
671555
+	close(fd);
671555
+	return 0;
671555
+fail:
671555
+	close(fd);
671555
+	return 1;
671555
+}
671555
Index: multipath-tools-130222/libmultipath/file.h
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/file.h
671555
+++ multipath-tools-130222/libmultipath/file.h
671555
@@ -7,5 +7,8 @@
671555
 
671555
 #define FILE_TIMEOUT 30
671555
 int open_file(char *file, int *can_write, char *header);
671555
+int ensure_directories_exist(const char *str, mode_t dir_mode);
671555
+int update_timestamp(int create);
671555
+int timestamp_equal(long int chk_timestamp);
671555
 
671555
 #endif /* _FILE_H */
671555
Index: multipath-tools-130222/multipathd/pidfile.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipathd/pidfile.c
671555
+++ multipath-tools-130222/multipathd/pidfile.c
671555
@@ -9,6 +9,7 @@
671555
 #include <fcntl.h>     /* for fcntl() */
671555
 
671555
 #include <debug.h>
671555
+#include <file.h>
671555
 
671555
 #include "pidfile.h"
671555
 
671555
@@ -18,6 +19,8 @@ int pidfile_create(const char *pidFile,
671555
 	struct flock lock;
671555
 	int fd, value;
671555
 
671555
+	if (ensure_directories_exist(pidFile, 0700))
671555
+		return 1;
671555
 	if((fd = open(pidFile, O_WRONLY | O_CREAT,
671555
 		       (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
671555
 		condlog(0, "Cannot open pidfile [%s], error was [%s]",
671555
Index: multipath-tools-130222/libmultipath/wwids.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/wwids.c
671555
+++ multipath-tools-130222/libmultipath/wwids.c
671555
@@ -125,6 +125,7 @@ replace_wwids(vector mp)
671555
 			goto out_file;
671555
 	}
671555
 	ret = 0;
671555
+	update_timestamp(0);
671555
 out_file:
671555
 	close(fd);
671555
 out:
671555
@@ -209,6 +210,8 @@ remove_wwid(char *wwid) {
671555
 		goto out_file;
671555
 	}
671555
 	ret = do_remove_wwid(fd, str);
671555
+	if (!ret)
671555
+		update_timestamp(0);
671555
 
671555
 out_file:
671555
 	close(fd);
671555
@@ -294,8 +297,10 @@ remember_wwid(char *wwid)
671555
 		condlog(3, "failed writing wwid %s to wwids file", wwid);
671555
 		return -1;
671555
 	}
671555
-	if (ret == 1)
671555
+	if (ret == 1) {
671555
 		condlog(3, "wrote wwid %s to wwids file", wwid);
671555
+		update_timestamp(0);
671555
+	}
671555
 	else
671555
 		condlog(4, "wwid %s already in wwids file", wwid);
671555
 	return 0;
671555
Index: multipath-tools-130222/multipath/multipath.rules
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipath/multipath.rules
671555
+++ multipath-tools-130222/multipath/multipath.rules
671555
@@ -4,18 +4,34 @@ SUBSYSTEM!="block", GOTO="end_mpath"
671555
 
671555
 IMPORT{cmdline}="nompath"
671555
 ENV{nompath}=="?*", GOTO="end_mpath"
671555
+ENV{DEVTYPE}=="partition", GOTO="end_mpath"
671555
 ENV{MPATH_SBIN_PATH}="/sbin"
671555
 TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin"
671555
+TEST!="/etc/multipath.conf", GOTO="check_kpartx"
671555
 
671555
-ACTION=="add", ENV{DEVTYPE}!="partition", \
671555
-	ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
671555
-	TEST=="/etc/multipath.conf", \
671555
+ACTION=="add", ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
671555
 	PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -c $tempnode", \
671555
-	ENV{DM_MULTIPATH_DEVICE_PATH}="1" ENV{ID_FS_TYPE}="mpath_member"
671555
+	ENV{DM_MULTIPATH_DEVICE_PATH}="1", ENV{ID_FS_TYPE}="mpath_member"
671555
 
671555
-ENV{DM_MULTIPATH_DEVICE_PATH}=="1", ENV{DEVTYPE}!="partition", \
671555
+ENV{DM_MULTIPATH_DEVICE_PATH}=="1", \
671555
 	RUN+="/sbin/partx -d --nr 1-1024 $env{DEVNAME}"
671555
 
671555
+ACTION!="change", GOTO="update_timestamp"
671555
+IMPORT{db}="DM_MULTIPATH_TIMESTAMP"
671555
+IMPORT{db}="DM_MULTIPATH_DEVICE_PATH"
671555
+# Check if the device is part of a multipath device. the -T option just keeps
671555
+# the old result if the timestamp hasn't changed.
671555
+PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -T $env{DM_MULTIPATH_TIMESTAMP}:$env{DM_MULTIPATH_DEVICE_PATH} -c $env{DEVNAME}", \
671555
+	ENV{DM_MULTIPATH_DEVICE_PATH}="1", ENV{ID_FS_TYPE}="mpath_member", \
671555
+	GOTO="update_timestamp"
671555
+
671555
+# If the device isn't part of a multipath device, clear this
671555
+ENV{DM_MULTIPATH_DEVICE_PATH}=""
671555
+
671555
+LABEL="update_timestamp"
671555
+IMPORT{file}="/run/multipathd/timestamp"
671555
+
671555
+LABEL="check_kpartx"
671555
 KERNEL!="dm-*", GOTO="end_mpath"
671555
 ENV{DM_UUID}=="mpath-?*|part[0-9]*-mpath-?*", OPTIONS+="link_priority=10"
671555
 ACTION!="change", GOTO="end_mpath"
671555
Index: multipath-tools-130222/multipathd/main.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipathd/main.c
671555
+++ multipath-tools-130222/multipathd/main.c
671555
@@ -54,6 +54,7 @@
671555
 #include <pgpolicies.h>
671555
 #include <uevent.h>
671555
 #include <log.h>
671555
+#include <file.h>
671555
 
671555
 #include "main.h"
671555
 #include "pidfile.h"
671555
@@ -1417,6 +1418,7 @@ reconfigure (struct vectors * vecs)
671555
 		free_config(old);
671555
 		retval = 0;
671555
 	}
671555
+	update_timestamp(0);
671555
 
671555
 	return retval;
671555
 }
671555
@@ -1709,6 +1711,7 @@ child (void * param)
671555
 
671555
 	/* Startup complete, create logfile */
671555
 	pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
671555
+	update_timestamp(1);
671555
 	/* Ignore errors, we can live without */
671555
 
671555
 	running_state = DAEMON_RUNNING;
671555
@@ -1758,6 +1761,7 @@ child (void * param)
671555
 	if (!pid_rc) {
671555
 		condlog(3, "unlink pidfile");
671555
 		unlink(DEFAULT_PIDFILE);
671555
+		unlink(DEFAULT_TIMESTAMP_FILE);
671555
 	}
671555
 
671555
 	condlog(2, "--------shut down-------");
671555
Index: multipath-tools-130222/multipathd/multipathd.service
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipathd/multipathd.service
671555
+++ multipath-tools-130222/multipathd/multipathd.service
671555
@@ -9,7 +9,7 @@ Conflicts=shutdown.target
671555
 
671555
 [Service]
671555
 Type=forking
671555
-PIDFile=/var/run/multipathd.pid
671555
+PIDFile=/var/run/multipathd/multipathd.pid
671555
 ExecStartPre=/sbin/modprobe dm-multipath
671555
 ExecStart=/sbin/multipathd
671555
 ExecReload=/sbin/multipathd reconfigure
671555
Index: multipath-tools-130222/multipath/main.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/multipath/main.c
671555
+++ multipath-tools-130222/multipath/main.c
671555
@@ -55,6 +55,7 @@
671555
 #include <sys/time.h>
671555
 #include <sys/resource.h>
671555
 #include <wwids.h>
671555
+#include <file.h>
671555
 #include "dev_t.h"
671555
 
671555
 int logsink;
671555
@@ -84,7 +85,7 @@ usage (char * progname)
671555
 {
671555
 	fprintf (stderr, VERSION_STRING);
671555
 	fprintf (stderr, "Usage:\n");
671555
-	fprintf (stderr, "  %s [-c|-w|-W] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
671555
+	fprintf (stderr, "  %s [-c|-w|-W] [-d] [-T tm:val] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
671555
 	fprintf (stderr, "  %s -l|-ll|-f [-v lvl] [-b fil] [dev]\n", progname);
671555
 	fprintf (stderr, "  %s -F [-v lvl]\n", progname);
671555
 	fprintf (stderr, "  %s -t\n", progname);
671555
@@ -98,6 +99,9 @@ usage (char * progname)
671555
 		"  -f      flush a multipath device map\n" \
671555
 		"  -F      flush all multipath device maps\n" \
671555
 		"  -c      check if a device should be a path in a multipath device\n" \
671555
+		"  -T tm:val\n" \
671555
+		"          check if tm matches the multipathd timestamp. If so val is\n" \
671555
+		"          whether or not the device is a path in a multipath device\n" \
671555
 		"  -q      allow queue_if_no_path when multipathd is not running\n"\
671555
 		"  -d      dry run, do not create or update devmaps\n" \
671555
 		"  -t      dump internal hardware table\n" \
671555
@@ -441,7 +445,31 @@ main (int argc, char *argv[])
671555
 	extern char *optarg;
671555
 	extern int optind;
671555
 	int r = 1;
671555
-
671555
+	long int timestamp = -1;
671555
+	int valid = -1;
671555
+	while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtT:qwW")) != EOF ) {
671555
+		switch(arg) {
671555
+		case 'T':
671555
+			if (optarg[0] == ':')
671555
+				sscanf(optarg, ":%d", &valid);
671555
+			else
671555
+				sscanf(optarg, "%ld:%d", &timestamp, &valid);
671555
+			if (timestamp_equal(timestamp))
671555
+				return (valid != 1);
671555
+			break;
671555
+		case ':':
671555
+			fprintf(stderr, "Missing option argument\n");
671555
+			usage(argv[0]);
671555
+			exit(1);
671555
+		case '?':
671555
+			fprintf(stderr, "Unknown switch: %s\n", optarg);
671555
+			usage(argv[0]);
671555
+			exit(1);
671555
+		default:
671555
+			break;
671555
+		}
671555
+	}
671555
+	optind = 1;
671555
 	if (getuid() != 0) {
671555
 		fprintf(stderr, "need to be root\n");
671555
 		exit(1);
671555
@@ -455,7 +483,7 @@ main (int argc, char *argv[])
671555
 	if (dm_prereq())
671555
 		exit(1);
671555
 
671555
-	while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtqwW")) != EOF ) {
671555
+	while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtT:qwW")) != EOF ) {
671555
 		switch(arg) {
671555
 		case 1: printf("optarg : %s\n",optarg);
671555
 			break;
671555
@@ -517,6 +545,8 @@ main (int argc, char *argv[])
671555
 		case 't':
671555
 			r = dump_config();
671555
 			goto out;
671555
+		case 'T':
671555
+			break;
671555
 		case 'h':
671555
 			usage(argv[0]);
671555
 			exit(0);