2 libmultipath/defaults.h | 3 -
3 libmultipath/file.c | 89 +++++++++++++++++++++++++++++++++++++++++-
4 libmultipath/file.h | 3 +
5 libmultipath/wwids.c | 7 ++-
6 multipath/main.c | 36 +++++++++++++++-
7 multipath/multipath.rules | 26 +++++++++---
8 multipathd/main.c | 4 +
9 multipathd/multipathd.service | 2
10 multipathd/pidfile.c | 3 +
11 9 files changed, 160 insertions(+), 13 deletions(-)
13 Index: multipath-tools-130222/libmultipath/defaults.h
14 ===================================================================
15 --- multipath-tools-130222.orig/libmultipath/defaults.h
16 +++ multipath-tools-130222/libmultipath/defaults.h
18 #define MAX_CHECKINT(a) (a << 2)
20 #define MAX_DEV_LOSS_TMO 0x7FFFFFFF
21 -#define DEFAULT_PIDFILE "/var/run/multipathd.pid"
22 +#define DEFAULT_PIDFILE "/var/run/multipathd/multipathd.pid"
23 +#define DEFAULT_TIMESTAMP_FILE "/var/run/multipathd/timestamp"
24 #define DEFAULT_SOCKET "/org/kernel/linux/storage/multipathd"
25 #define DEFAULT_CONFIGFILE "/etc/multipath.conf"
26 #define DEFAULT_BINDINGS_FILE "/etc/multipath/bindings"
27 Index: multipath-tools-130222/libmultipath/file.c
28 ===================================================================
29 --- multipath-tools-130222.orig/libmultipath/file.c
30 +++ multipath-tools-130222/libmultipath/file.c
40 +#include "defaults.h"
45 * See the file COPYING included with this distribution for more details.
49 -ensure_directories_exist(char *str, mode_t dir_mode)
51 +ensure_directories_exist(const char *str, mode_t dir_mode)
55 @@ -178,3 +180,86 @@ fail:
60 +/* If you can't get the timestamp, return equal to just keep using the
63 +int timestamp_equal(long int chk_timestamp)
67 + long int file_timestamp;
70 + if ((file = fopen(DEFAULT_TIMESTAMP_FILE, "r")) == NULL) {
71 + if (errno != ENOENT)
72 + condlog(2, "Cannot open timestamp file [%s]: %s",
73 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
77 + if (fgets(buf, sizeof(buf), file) == NULL) {
79 + condlog(2, "Cannot read from timestamp file: %s",
83 + if (sscanf(buf, "DM_MULTIPATH_TIMESTAMP=%ld", &file_timestamp) != 1) {
85 + condlog(0, "Cannot get timestamp: %s", strerror(errno));
87 + condlog(0, "invalid timestamp file [%s]: %s",
88 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
91 + if (file_timestamp != chk_timestamp) {
92 + condlog(3, "timestamp has changed");
96 + condlog(3, "timestamp has not changed");
103 +int update_timestamp(int create)
108 + int flags = O_WRONLY;
111 + if((fd = open(DEFAULT_TIMESTAMP_FILE, flags,
112 + (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
113 + if (errno == ENOENT)
115 + condlog(0, "Cannot open timestamp file [%s]: %s",
116 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
119 + if (ftruncate(fd, 0) < 0) {
120 + condlog(0, "Cannot truncate timestamp file [%s]: %s",
121 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
124 + if (time(×tamp) == -1) {
125 + condlog(0, "Cannot get current time: %s", strerror(errno));
128 + memset(buf, 0, sizeof(buf));
129 + snprintf(buf, sizeof(buf)-1, "DM_MULTIPATH_TIMESTAMP=%ld\n",
131 + if (write(fd, buf, strlen(buf)) != strlen(buf)) {
132 + condlog(0, "Cannot write out timestamp to %s: %s",
133 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
142 Index: multipath-tools-130222/libmultipath/file.h
143 ===================================================================
144 --- multipath-tools-130222.orig/libmultipath/file.h
145 +++ multipath-tools-130222/libmultipath/file.h
148 #define FILE_TIMEOUT 30
149 int open_file(char *file, int *can_write, char *header);
150 +int ensure_directories_exist(const char *str, mode_t dir_mode);
151 +int update_timestamp(int create);
152 +int timestamp_equal(long int chk_timestamp);
155 Index: multipath-tools-130222/multipathd/pidfile.c
156 ===================================================================
157 --- multipath-tools-130222.orig/multipathd/pidfile.c
158 +++ multipath-tools-130222/multipathd/pidfile.c
160 #include <fcntl.h> /* for fcntl() */
167 @@ -18,6 +19,8 @@ int pidfile_create(const char *pidFile,
171 + if (ensure_directories_exist(pidFile, 0700))
173 if((fd = open(pidFile, O_WRONLY | O_CREAT,
174 (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
175 condlog(0, "Cannot open pidfile [%s], error was [%s]",
176 Index: multipath-tools-130222/libmultipath/wwids.c
177 ===================================================================
178 --- multipath-tools-130222.orig/libmultipath/wwids.c
179 +++ multipath-tools-130222/libmultipath/wwids.c
180 @@ -125,6 +125,7 @@ replace_wwids(vector mp)
184 + update_timestamp(0);
188 @@ -209,6 +210,8 @@ remove_wwid(char *wwid) {
191 ret = do_remove_wwid(fd, str);
193 + update_timestamp(0);
197 @@ -294,8 +297,10 @@ remember_wwid(char *wwid)
198 condlog(3, "failed writing wwid %s to wwids file", wwid);
203 condlog(3, "wrote wwid %s to wwids file", wwid);
204 + update_timestamp(0);
207 condlog(4, "wwid %s already in wwids file", wwid);
209 Index: multipath-tools-130222/multipath/multipath.rules
210 ===================================================================
211 --- multipath-tools-130222.orig/multipath/multipath.rules
212 +++ multipath-tools-130222/multipath/multipath.rules
213 @@ -4,18 +4,34 @@ SUBSYSTEM!="block", GOTO="end_mpath"
215 IMPORT{cmdline}="nompath"
216 ENV{nompath}=="?*", GOTO="end_mpath"
217 +ENV{DEVTYPE}=="partition", GOTO="end_mpath"
218 ENV{MPATH_SBIN_PATH}="/sbin"
219 TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin"
220 +TEST!="/etc/multipath.conf", GOTO="check_kpartx"
222 -ACTION=="add", ENV{DEVTYPE}!="partition", \
223 - ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
224 - TEST=="/etc/multipath.conf", \
225 +ACTION=="add", ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \
226 PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -c $tempnode", \
227 - ENV{DM_MULTIPATH_DEVICE_PATH}="1" ENV{ID_FS_TYPE}="mpath_member"
228 + ENV{DM_MULTIPATH_DEVICE_PATH}="1", ENV{ID_FS_TYPE}="mpath_member"
230 -ENV{DM_MULTIPATH_DEVICE_PATH}=="1", ENV{DEVTYPE}!="partition", \
231 +ENV{DM_MULTIPATH_DEVICE_PATH}=="1", \
232 RUN+="/sbin/partx -d --nr 1-1024 $env{DEVNAME}"
234 +ACTION!="change", GOTO="update_timestamp"
235 +IMPORT{db}="DM_MULTIPATH_TIMESTAMP"
236 +IMPORT{db}="DM_MULTIPATH_DEVICE_PATH"
237 +# Check if the device is part of a multipath device. the -T option just keeps
238 +# the old result if the timestamp hasn't changed.
239 +PROGRAM=="$env{MPATH_SBIN_PATH}/multipath -T $env{DM_MULTIPATH_TIMESTAMP}:$env{DM_MULTIPATH_DEVICE_PATH} -c $env{DEVNAME}", \
240 + ENV{DM_MULTIPATH_DEVICE_PATH}="1", ENV{ID_FS_TYPE}="mpath_member", \
241 + GOTO="update_timestamp"
243 +# If the device isn't part of a multipath device, clear this
244 +ENV{DM_MULTIPATH_DEVICE_PATH}=""
246 +LABEL="update_timestamp"
247 +IMPORT{file}="/run/multipathd/timestamp"
249 +LABEL="check_kpartx"
250 KERNEL!="dm-*", GOTO="end_mpath"
251 ENV{DM_UUID}=="mpath-?*|part[0-9]*-mpath-?*", OPTIONS+="link_priority=10"
252 ACTION!="change", GOTO="end_mpath"
253 Index: multipath-tools-130222/multipathd/main.c
254 ===================================================================
255 --- multipath-tools-130222.orig/multipathd/main.c
256 +++ multipath-tools-130222/multipathd/main.c
258 #include <pgpolicies.h>
265 @@ -1417,6 +1418,7 @@ reconfigure (struct vectors * vecs)
269 + update_timestamp(0);
273 @@ -1709,6 +1711,7 @@ child (void * param)
275 /* Startup complete, create logfile */
276 pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
277 + update_timestamp(1);
278 /* Ignore errors, we can live without */
280 running_state = DAEMON_RUNNING;
281 @@ -1758,6 +1761,7 @@ child (void * param)
283 condlog(3, "unlink pidfile");
284 unlink(DEFAULT_PIDFILE);
285 + unlink(DEFAULT_TIMESTAMP_FILE);
288 condlog(2, "--------shut down-------");
289 Index: multipath-tools-130222/multipathd/multipathd.service
290 ===================================================================
291 --- multipath-tools-130222.orig/multipathd/multipathd.service
292 +++ multipath-tools-130222/multipathd/multipathd.service
293 @@ -9,7 +9,7 @@ Conflicts=shutdown.target
297 -PIDFile=/var/run/multipathd.pid
298 +PIDFile=/var/run/multipathd/multipathd.pid
299 ExecStartPre=/sbin/modprobe dm-multipath
300 ExecStart=/sbin/multipathd
301 ExecReload=/sbin/multipathd reconfigure
302 Index: multipath-tools-130222/multipath/main.c
303 ===================================================================
304 --- multipath-tools-130222.orig/multipath/main.c
305 +++ multipath-tools-130222/multipath/main.c
307 #include <sys/time.h>
308 #include <sys/resource.h>
314 @@ -84,7 +85,7 @@ usage (char * progname)
316 fprintf (stderr, VERSION_STRING);
317 fprintf (stderr, "Usage:\n");
318 - fprintf (stderr, " %s [-c|-w|-W] [-d] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
319 + fprintf (stderr, " %s [-c|-w|-W] [-d] [-T tm:val] [-r] [-v lvl] [-p pol] [-b fil] [-q] [dev]\n", progname);
320 fprintf (stderr, " %s -l|-ll|-f [-v lvl] [-b fil] [dev]\n", progname);
321 fprintf (stderr, " %s -F [-v lvl]\n", progname);
322 fprintf (stderr, " %s -t\n", progname);
323 @@ -98,6 +99,9 @@ usage (char * progname)
324 " -f flush a multipath device map\n" \
325 " -F flush all multipath device maps\n" \
326 " -c check if a device should be a path in a multipath device\n" \
328 + " check if tm matches the multipathd timestamp. If so val is\n" \
329 + " whether or not the device is a path in a multipath device\n" \
330 " -q allow queue_if_no_path when multipathd is not running\n"\
331 " -d dry run, do not create or update devmaps\n" \
332 " -t dump internal hardware table\n" \
333 @@ -441,7 +445,31 @@ main (int argc, char *argv[])
338 + long int timestamp = -1;
340 + while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtT:qwW")) != EOF ) {
343 + if (optarg[0] == ':')
344 + sscanf(optarg, ":%d", &valid);
346 + sscanf(optarg, "%ld:%d", ×tamp, &valid);
347 + if (timestamp_equal(timestamp))
348 + return (valid != 1);
351 + fprintf(stderr, "Missing option argument\n");
355 + fprintf(stderr, "Unknown switch: %s\n", optarg);
364 fprintf(stderr, "need to be root\n");
366 @@ -455,7 +483,7 @@ main (int argc, char *argv[])
370 - while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtqwW")) != EOF ) {
371 + while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtT:qwW")) != EOF ) {
373 case 1: printf("optarg : %s\n",optarg);
375 @@ -517,6 +545,8 @@ main (int argc, char *argv[])