]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blob - multipath-tools/patches/0064-fix-ID_FS-attrs.patch
multipath-tools: Update to snapshot from 2013-02-22
[people/amarx/ipfire-3.x.git] / multipath-tools / patches / 0064-fix-ID_FS-attrs.patch
1 ---
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(-)
12
13 Index: multipath-tools-130222/libmultipath/defaults.h
14 ===================================================================
15 --- multipath-tools-130222.orig/libmultipath/defaults.h
16 +++ multipath-tools-130222/libmultipath/defaults.h
17 @@ -24,7 +24,8 @@
18 #define MAX_CHECKINT(a) (a << 2)
19
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
31 @@ -12,10 +12,12 @@
32 #include <limits.h>
33 #include <stdio.h>
34 #include <signal.h>
35 +#include <time.h>
36
37 #include "file.h"
38 #include "debug.h"
39 #include "uxsock.h"
40 +#include "defaults.h"
41
42
43 /*
44 @@ -36,8 +38,8 @@
45 * See the file COPYING included with this distribution for more details.
46 */
47
48 -static int
49 -ensure_directories_exist(char *str, mode_t dir_mode)
50 +int
51 +ensure_directories_exist(const char *str, mode_t dir_mode)
52 {
53 char *pathname;
54 char *end;
55 @@ -178,3 +180,86 @@ fail:
56 close(fd);
57 return -1;
58 }
59 +
60 +/* If you can't get the timestamp, return equal to just keep using the
61 + * existing value.
62 + */
63 +int timestamp_equal(long int chk_timestamp)
64 +{
65 + char buf[4096];
66 + FILE *file;
67 + long int file_timestamp;
68 + int ret = 1;
69 +
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));
74 + goto out;
75 + }
76 + errno = 0;
77 + if (fgets(buf, sizeof(buf), file) == NULL) {
78 + if (errno)
79 + condlog(2, "Cannot read from timestamp file: %s",
80 + strerror(errno));
81 + goto out;
82 + }
83 + if (sscanf(buf, "DM_MULTIPATH_TIMESTAMP=%ld", &file_timestamp) != 1) {
84 + if (errno)
85 + condlog(0, "Cannot get timestamp: %s", strerror(errno));
86 + else
87 + condlog(0, "invalid timestamp file [%s]: %s",
88 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
89 + goto out;
90 + }
91 + if (file_timestamp != chk_timestamp) {
92 + condlog(3, "timestamp has changed");
93 + ret = 0;
94 + }
95 + else
96 + condlog(3, "timestamp has not changed");
97 +out:
98 + if (file)
99 + fclose(file);
100 + return ret;
101 +}
102 +
103 +int update_timestamp(int create)
104 +{
105 + char buf[44];
106 + time_t timestamp;
107 + int fd;
108 + int flags = O_WRONLY;
109 + if (create)
110 + flags |= O_CREAT;
111 + if((fd = open(DEFAULT_TIMESTAMP_FILE, flags,
112 + (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
113 + if (errno == ENOENT)
114 + return 0;
115 + condlog(0, "Cannot open timestamp file [%s]: %s",
116 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
117 + return 1;
118 + }
119 + if (ftruncate(fd, 0) < 0) {
120 + condlog(0, "Cannot truncate timestamp file [%s]: %s",
121 + DEFAULT_TIMESTAMP_FILE, strerror(errno));
122 + goto fail;
123 + }
124 + if (time(&timestamp) == -1) {
125 + condlog(0, "Cannot get current time: %s", strerror(errno));
126 + goto fail;
127 + }
128 + memset(buf, 0, sizeof(buf));
129 + snprintf(buf, sizeof(buf)-1, "DM_MULTIPATH_TIMESTAMP=%ld\n",
130 + timestamp);
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));
134 + goto fail;
135 + }
136 + close(fd);
137 + return 0;
138 +fail:
139 + close(fd);
140 + return 1;
141 +}
142 Index: multipath-tools-130222/libmultipath/file.h
143 ===================================================================
144 --- multipath-tools-130222.orig/libmultipath/file.h
145 +++ multipath-tools-130222/libmultipath/file.h
146 @@ -7,5 +7,8 @@
147
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);
153
154 #endif /* _FILE_H */
155 Index: multipath-tools-130222/multipathd/pidfile.c
156 ===================================================================
157 --- multipath-tools-130222.orig/multipathd/pidfile.c
158 +++ multipath-tools-130222/multipathd/pidfile.c
159 @@ -9,6 +9,7 @@
160 #include <fcntl.h> /* for fcntl() */
161
162 #include <debug.h>
163 +#include <file.h>
164
165 #include "pidfile.h"
166
167 @@ -18,6 +19,8 @@ int pidfile_create(const char *pidFile,
168 struct flock lock;
169 int fd, value;
170
171 + if (ensure_directories_exist(pidFile, 0700))
172 + return 1;
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)
181 goto out_file;
182 }
183 ret = 0;
184 + update_timestamp(0);
185 out_file:
186 close(fd);
187 out:
188 @@ -209,6 +210,8 @@ remove_wwid(char *wwid) {
189 goto out_file;
190 }
191 ret = do_remove_wwid(fd, str);
192 + if (!ret)
193 + update_timestamp(0);
194
195 out_file:
196 close(fd);
197 @@ -294,8 +297,10 @@ remember_wwid(char *wwid)
198 condlog(3, "failed writing wwid %s to wwids file", wwid);
199 return -1;
200 }
201 - if (ret == 1)
202 + if (ret == 1) {
203 condlog(3, "wrote wwid %s to wwids file", wwid);
204 + update_timestamp(0);
205 + }
206 else
207 condlog(4, "wwid %s already in wwids file", wwid);
208 return 0;
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"
214
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"
221
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"
229
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}"
233
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"
242 +
243 +# If the device isn't part of a multipath device, clear this
244 +ENV{DM_MULTIPATH_DEVICE_PATH}=""
245 +
246 +LABEL="update_timestamp"
247 +IMPORT{file}="/run/multipathd/timestamp"
248 +
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
257 @@ -54,6 +54,7 @@
258 #include <pgpolicies.h>
259 #include <uevent.h>
260 #include <log.h>
261 +#include <file.h>
262
263 #include "main.h"
264 #include "pidfile.h"
265 @@ -1417,6 +1418,7 @@ reconfigure (struct vectors * vecs)
266 free_config(old);
267 retval = 0;
268 }
269 + update_timestamp(0);
270
271 return retval;
272 }
273 @@ -1709,6 +1711,7 @@ child (void * param)
274
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 */
279
280 running_state = DAEMON_RUNNING;
281 @@ -1758,6 +1761,7 @@ child (void * param)
282 if (!pid_rc) {
283 condlog(3, "unlink pidfile");
284 unlink(DEFAULT_PIDFILE);
285 + unlink(DEFAULT_TIMESTAMP_FILE);
286 }
287
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
294
295 [Service]
296 Type=forking
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
306 @@ -55,6 +55,7 @@
307 #include <sys/time.h>
308 #include <sys/resource.h>
309 #include <wwids.h>
310 +#include <file.h>
311 #include "dev_t.h"
312
313 int logsink;
314 @@ -84,7 +85,7 @@ usage (char * progname)
315 {
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" \
327 + " -T tm:val\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[])
334 extern char *optarg;
335 extern int optind;
336 int r = 1;
337 -
338 + long int timestamp = -1;
339 + int valid = -1;
340 + while ((arg = getopt(argc, argv, ":dchl::FfM:v:p:b:BrtT:qwW")) != EOF ) {
341 + switch(arg) {
342 + case 'T':
343 + if (optarg[0] == ':')
344 + sscanf(optarg, ":%d", &valid);
345 + else
346 + sscanf(optarg, "%ld:%d", &timestamp, &valid);
347 + if (timestamp_equal(timestamp))
348 + return (valid != 1);
349 + break;
350 + case ':':
351 + fprintf(stderr, "Missing option argument\n");
352 + usage(argv[0]);
353 + exit(1);
354 + case '?':
355 + fprintf(stderr, "Unknown switch: %s\n", optarg);
356 + usage(argv[0]);
357 + exit(1);
358 + default:
359 + break;
360 + }
361 + }
362 + optind = 1;
363 if (getuid() != 0) {
364 fprintf(stderr, "need to be root\n");
365 exit(1);
366 @@ -455,7 +483,7 @@ main (int argc, char *argv[])
367 if (dm_prereq())
368 exit(1);
369
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 ) {
372 switch(arg) {
373 case 1: printf("optarg : %s\n",optarg);
374 break;
375 @@ -517,6 +545,8 @@ main (int argc, char *argv[])
376 case 't':
377 r = dump_config();
378 goto out;
379 + case 'T':
380 + break;
381 case 'h':
382 usage(argv[0]);
383 exit(0);