summaryrefslogtreecommitdiffstats
path: root/0064-fix-ID_FS-attrs.patch
blob: cb59a854488c22fb5692548e82f3be4d0d780a78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
---
 libmultipath/defaults.h       |    3 -
 libmultipath/file.c           |   89 +++++++++++++++++++++++++++++++++++++++++-
 libmultipath/file.h           |    3 +
 libmultipath/wwids.c          |    7 ++-
 multipath/main.c              |   36 +++++++++++++++-
 multipath/multipath.rules     |   26 +++++++++---
 multipathd/main.c             |    4 +
 multipathd/multipathd.service |    2 
 multipathd/pidfile.c          |    3 +
 9 files changed, 160 insertions(+), 13 deletions(-)

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