Merge lp:~xnox/ubuntu/quantal/mdadm/merge into lp:~xnox/ubuntu/quantal/mdadm/quantal
- Quantal (12.10)
- merge
- Merge into quantal
Proposed by
Dimitri John Ledkov
Status: | Merged | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Merge reported by: | Dimitri John Ledkov | ||||||||||||||||||||||||||||
Merged at revision: | not available | ||||||||||||||||||||||||||||
Proposed branch: | lp:~xnox/ubuntu/quantal/mdadm/merge | ||||||||||||||||||||||||||||
Merge into: | lp:~xnox/ubuntu/quantal/mdadm/quantal | ||||||||||||||||||||||||||||
Diff against target: |
24674 lines (+7902/-9243) 110 files modified
.pc/applied-patches (+0/-3) .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c (+0/-1650) .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c (+0/-602) .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/config.c (+0/-1131) .pc/debian-conffile-location.diff/Makefile (+287/-0) .pc/debian-conffile-location.diff/ReadMe.c (+608/-0) .pc/debian-conffile-location.diff/mdadm.8.in (+2899/-0) .pc/debian-conffile-location.diff/mdadm.conf.5 (+581/-0) .pc/debian-conffile-location.diff/mdassemble.8 (+65/-0) .pc/debian-no-Werror.diff/Makefile (+287/-0) .pc/debian/conffile-location.diff/Makefile (+0/-286) .pc/debian/conffile-location.diff/ReadMe.c (+0/-602) .pc/debian/conffile-location.diff/mdadm.8.in (+0/-2880) .pc/debian/conffile-location.diff/mdadm.conf.5 (+0/-581) .pc/debian/conffile-location.diff/mdassemble.8 (+0/-65) .pc/debian/no-Werror.diff/Makefile (+0/-286) .pc/sha1-includes.diff/sha1.h (+141/-0) ANNOUNCE-3.2.4 (+144/-0) ANNOUNCE-3.2.5 (+31/-0) Assemble.c (+72/-23) Create.c (+14/-4) Detail.c (+8/-7) Grow.c (+288/-84) Incremental.c (+6/-8) Makefile (+7/-6) Manage.c (+94/-51) Monitor.c (+19/-12) ReadMe.c (+7/-1) check.d/_numbers (+0/-1) check.d/root_on_raid (+0/-35) config.c (+6/-6) debian/README.source (+0/-18) debian/changelog (+102/-0) debian/checkarray (+15/-0) debian/control (+1/-1) debian/initramfs/local-premount (+1/-0) debian/mdadm.logcheck.ignore.server (+1/-1) debian/patches/debian-conffile-location.diff (+126/-0) debian/patches/debian-disable-udev-incr-assembly.diff (+27/-0) debian/patches/debian-no-Werror.diff (+26/-0) debian/patches/debian/conffile-location.diff (+0/-128) debian/patches/debian/disable-udev-incr-assembly.diff (+0/-29) debian/patches/debian/no-Werror.diff (+0/-28) debian/patches/series (+4/-3) debian/patches/sha1-includes.diff (+45/-0) debian/po/ca.po (+7/-7) debian/po/cs.po (+7/-7) debian/po/da.po (+7/-7) debian/po/de.po (+7/-7) debian/po/es.po (+7/-7) debian/po/eu.po (+7/-7) debian/po/fi.po (+6/-6) debian/po/fr.po (+7/-7) debian/po/gl.po (+7/-7) debian/po/it.po (+7/-7) debian/po/ja.po (+7/-7) debian/po/nl.po (+7/-7) debian/po/pt.po (+7/-7) debian/po/pt_BR.po (+39/-7) debian/po/ru.po (+7/-7) debian/po/sk.po (+7/-7) debian/po/sv.po (+7/-7) debian/po/templates.pot (+2/-2) debian/po/vi.po (+7/-7) debian/rules (+7/-17) debian/source_mdadm.py (+5/-7) inventory (+28/-26) lib.c (+7/-2) makedist (+4/-2) managemon.c (+6/-0) mapfile.c (+6/-11) mdadm.8.in (+42/-23) mdadm.c (+24/-6) mdadm.conf-example (+1/-1) mdadm.conf.5 (+1/-1) mdadm.h (+38/-14) mdadm.spec (+2/-2) mdassemble.8 (+1/-1) mdmon.8 (+13/-3) mdmon.c (+48/-11) mdopen.c (+1/-1) monitor.c (+20/-16) msg.c (+10/-0) msg.h (+1/-0) platform-intel.h (+1/-0) sha1.c (+42/-49) sha1.h (+64/-12) super-ddf.c (+25/-16) super-intel.c (+1159/-189) super0.c (+18/-12) super1.c (+169/-102) sysfs.c (+13/-4) test (+6/-5) tests/00raid1 (+2/-2) tests/05r1-bitmapfile (+3/-3) tests/05r1-grow-external (+2/-2) tests/05r1-grow-internal (+2/-2) tests/05r1-grow-internal-1 (+2/-2) tests/05r1-internalbitmap (+3/-3) tests/05r1-internalbitmap-v1a (+3/-3) tests/05r1-internalbitmap-v1b (+3/-3) tests/05r1-internalbitmap-v1c (+3/-3) tests/05r1-n3-bitmapfile (+3/-3) tests/05r1-re-add (+2/-2) tests/06wrmostly (+2/-2) tests/07autoassemble (+4/-4) tests/09imsm-assemble (+3/-3) tests/09imsm-create-fail-rebuild (+1/-1) tests/10ddf-create (+1/-1) util.c (+30/-12) |
||||||||||||||||||||||||||||
To merge this branch: | bzr merge lp:~xnox/ubuntu/quantal/mdadm/merge | ||||||||||||||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dimitri John Ledkov | Pending | ||
Review via email: mp+110746@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 1970-01-01 00:00:00 +0000 | |||
3 | +++ .pc/applied-patches 2012-06-18 08:55:05 +0000 | |||
4 | @@ -0,0 +1,4 @@ | |||
5 | 1 | debian-conffile-location.diff | ||
6 | 2 | debian-no-Werror.diff | ||
7 | 3 | debian-changes-3.1.4-1+8efb9d1ubuntu4 | ||
8 | 4 | sha1-includes.diff | ||
9 | 0 | 5 | ||
10 | === removed file '.pc/applied-patches' | |||
11 | --- .pc/applied-patches 2012-05-22 16:40:37 +0000 | |||
12 | +++ .pc/applied-patches 1970-01-01 00:00:00 +0000 | |||
13 | @@ -1,3 +0,0 @@ | |||
14 | 1 | debian/conffile-location.diff | ||
15 | 2 | debian/no-Werror.diff | ||
16 | 3 | debian-changes-3.1.4-1+8efb9d1ubuntu4 | ||
17 | 4 | 0 | ||
18 | === removed directory '.pc/debian' | |||
19 | === added directory '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4' | |||
20 | === removed directory '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4' | |||
21 | === added file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c' | |||
22 | --- .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c 1970-01-01 00:00:00 +0000 | |||
23 | +++ .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c 2012-06-18 08:55:05 +0000 | |||
24 | @@ -0,0 +1,1699 @@ | |||
25 | 1 | /* | ||
26 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. | ||
27 | 3 | * | ||
28 | 4 | * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de> | ||
29 | 5 | * | ||
30 | 6 | * | ||
31 | 7 | * This program is free software; you can redistribute it and/or modify | ||
32 | 8 | * it under the terms of the GNU General Public License as published by | ||
33 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
34 | 10 | * (at your option) any later version. | ||
35 | 11 | * | ||
36 | 12 | * This program is distributed in the hope that it will be useful, | ||
37 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
38 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
39 | 15 | * GNU General Public License for more details. | ||
40 | 16 | * | ||
41 | 17 | * You should have received a copy of the GNU General Public License | ||
42 | 18 | * along with this program; if not, write to the Free Software | ||
43 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
44 | 20 | * | ||
45 | 21 | * Author: Neil Brown | ||
46 | 22 | * Email: <neilb@suse.de> | ||
47 | 23 | */ | ||
48 | 24 | |||
49 | 25 | #include "mdadm.h" | ||
50 | 26 | #include <ctype.h> | ||
51 | 27 | |||
52 | 28 | static int name_matches(char *found, char *required, char *homehost) | ||
53 | 29 | { | ||
54 | 30 | /* See if the name found matches the required name, possibly | ||
55 | 31 | * prefixed with 'homehost' | ||
56 | 32 | */ | ||
57 | 33 | char fnd[33]; | ||
58 | 34 | |||
59 | 35 | strncpy(fnd, found, 32); | ||
60 | 36 | fnd[32] = 0; | ||
61 | 37 | if (strcmp(found, required)==0) | ||
62 | 38 | return 1; | ||
63 | 39 | if (homehost) { | ||
64 | 40 | int l = strlen(homehost); | ||
65 | 41 | if (l < 32 && fnd[l] == ':' && | ||
66 | 42 | strcmp(fnd+l+1, required)==0) | ||
67 | 43 | return 1; | ||
68 | 44 | } | ||
69 | 45 | return 0; | ||
70 | 46 | } | ||
71 | 47 | |||
72 | 48 | static int is_member_busy(char *metadata_version) | ||
73 | 49 | { | ||
74 | 50 | /* check if the given member array is active */ | ||
75 | 51 | struct mdstat_ent *mdstat = mdstat_read(1, 0); | ||
76 | 52 | struct mdstat_ent *ent; | ||
77 | 53 | int busy = 0; | ||
78 | 54 | |||
79 | 55 | for (ent = mdstat; ent; ent = ent->next) { | ||
80 | 56 | if (ent->metadata_version == NULL) | ||
81 | 57 | continue; | ||
82 | 58 | if (strncmp(ent->metadata_version, "external:", 9) != 0) | ||
83 | 59 | continue; | ||
84 | 60 | if (!is_subarray(&ent->metadata_version[9])) | ||
85 | 61 | continue; | ||
86 | 62 | /* Skip first char - it can be '/' or '-' */ | ||
87 | 63 | if (strcmp(&ent->metadata_version[10], metadata_version+1) == 0) { | ||
88 | 64 | busy = 1; | ||
89 | 65 | break; | ||
90 | 66 | } | ||
91 | 67 | } | ||
92 | 68 | free_mdstat(mdstat); | ||
93 | 69 | |||
94 | 70 | return busy; | ||
95 | 71 | } | ||
96 | 72 | |||
97 | 73 | static int ident_matches(struct mddev_ident *ident, | ||
98 | 74 | struct mdinfo *content, | ||
99 | 75 | struct supertype *tst, | ||
100 | 76 | char *homehost, | ||
101 | 77 | char *update, char *devname) | ||
102 | 78 | { | ||
103 | 79 | |||
104 | 80 | if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) && | ||
105 | 81 | same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0 && | ||
106 | 82 | memcmp(content->uuid, uuid_zero, sizeof(int[4])) != 0) { | ||
107 | 83 | if (devname) | ||
108 | 84 | fprintf(stderr, Name ": %s has wrong uuid.\n", | ||
109 | 85 | devname); | ||
110 | 86 | return 0; | ||
111 | 87 | } | ||
112 | 88 | if (ident->name[0] && (!update || strcmp(update, "name")!= 0) && | ||
113 | 89 | name_matches(content->name, ident->name, homehost)==0) { | ||
114 | 90 | if (devname) | ||
115 | 91 | fprintf(stderr, Name ": %s has wrong name.\n", | ||
116 | 92 | devname); | ||
117 | 93 | return 0; | ||
118 | 94 | } | ||
119 | 95 | if (ident->super_minor != UnSet && | ||
120 | 96 | ident->super_minor != content->array.md_minor) { | ||
121 | 97 | if (devname) | ||
122 | 98 | fprintf(stderr, Name ": %s has wrong super-minor.\n", | ||
123 | 99 | devname); | ||
124 | 100 | return 0; | ||
125 | 101 | } | ||
126 | 102 | if (ident->level != UnSet && | ||
127 | 103 | ident->level != content->array.level) { | ||
128 | 104 | if (devname) | ||
129 | 105 | fprintf(stderr, Name ": %s has wrong raid level.\n", | ||
130 | 106 | devname); | ||
131 | 107 | return 0; | ||
132 | 108 | } | ||
133 | 109 | if (ident->raid_disks != UnSet && | ||
134 | 110 | ident->raid_disks!= content->array.raid_disks) { | ||
135 | 111 | if (devname) | ||
136 | 112 | fprintf(stderr, Name ": %s requires wrong number of drives.\n", | ||
137 | 113 | devname); | ||
138 | 114 | return 0; | ||
139 | 115 | } | ||
140 | 116 | if (ident->member && ident->member[0]) { | ||
141 | 117 | /* content->text_version must match */ | ||
142 | 118 | char *s = strchr(content->text_version+1, '/'); | ||
143 | 119 | if (s == NULL) { | ||
144 | 120 | if (devname) | ||
145 | 121 | fprintf(stderr, Name ": %s is not a container and one is required.\n", | ||
146 | 122 | devname); | ||
147 | 123 | return 0; | ||
148 | 124 | } else if (strcmp(ident->member, s+1) != 0) { | ||
149 | 125 | if (devname) | ||
150 | 126 | fprintf(stderr, Name ": skipping wrong member %s is %s\n", | ||
151 | 127 | content->text_version, devname); | ||
152 | 128 | return 0; | ||
153 | 129 | } | ||
154 | 130 | } | ||
155 | 131 | return 1; | ||
156 | 132 | } | ||
157 | 133 | |||
158 | 134 | |||
159 | 135 | int Assemble(struct supertype *st, char *mddev, | ||
160 | 136 | struct mddev_ident *ident, | ||
161 | 137 | struct mddev_dev *devlist, | ||
162 | 138 | char *backup_file, int invalid_backup, | ||
163 | 139 | int readonly, int runstop, | ||
164 | 140 | char *update, char *homehost, int require_homehost, | ||
165 | 141 | int verbose, int force, int freeze_reshape) | ||
166 | 142 | { | ||
167 | 143 | /* | ||
168 | 144 | * The task of Assemble is to find a collection of | ||
169 | 145 | * devices that should (according to their superblocks) | ||
170 | 146 | * form an array, and to give this collection to the MD driver. | ||
171 | 147 | * In Linux-2.4 and later, this involves submitting a | ||
172 | 148 | * SET_ARRAY_INFO ioctl with no arg - to prepare | ||
173 | 149 | * the array - and then submit a number of | ||
174 | 150 | * ADD_NEW_DISK ioctls to add disks into | ||
175 | 151 | * the array. Finally RUN_ARRAY might | ||
176 | 152 | * be submitted to start the array. | ||
177 | 153 | * | ||
178 | 154 | * Much of the work of Assemble is in finding and/or | ||
179 | 155 | * checking the disks to make sure they look right. | ||
180 | 156 | * | ||
181 | 157 | * If mddev is not set, then scan must be set and we | ||
182 | 158 | * read through the config file for dev+uuid mapping | ||
183 | 159 | * We recurse, setting mddev, for each device that | ||
184 | 160 | * - isn't running | ||
185 | 161 | * - has a valid uuid (or any uuid if !uuidset) | ||
186 | 162 | * | ||
187 | 163 | * If mddev is set, we try to determine state of md. | ||
188 | 164 | * check version - must be at least 0.90.0 | ||
189 | 165 | * check kernel version. must be at least 2.4. | ||
190 | 166 | * If not, we can possibly fall back on START_ARRAY | ||
191 | 167 | * Try to GET_ARRAY_INFO. | ||
192 | 168 | * If possible, give up | ||
193 | 169 | * If not, try to STOP_ARRAY just to make sure | ||
194 | 170 | * | ||
195 | 171 | * If !uuidset and scan, look in conf-file for uuid | ||
196 | 172 | * If not found, give up | ||
197 | 173 | * If !devlist and scan and uuidset, get list of devs from conf-file | ||
198 | 174 | * | ||
199 | 175 | * For each device: | ||
200 | 176 | * Check superblock - discard if bad | ||
201 | 177 | * Check uuid (set if we don't have one) - discard if no match | ||
202 | 178 | * Check superblock similarity if we have a superblock - discard if different | ||
203 | 179 | * Record events, devicenum | ||
204 | 180 | * This should give us a list of devices for the array | ||
205 | 181 | * We should collect the most recent event number | ||
206 | 182 | * | ||
207 | 183 | * Count disks with recent enough event count | ||
208 | 184 | * While force && !enough disks | ||
209 | 185 | * Choose newest rejected disks, update event count | ||
210 | 186 | * mark clean and rewrite superblock | ||
211 | 187 | * If recent kernel: | ||
212 | 188 | * SET_ARRAY_INFO | ||
213 | 189 | * foreach device with recent events : ADD_NEW_DISK | ||
214 | 190 | * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY | ||
215 | 191 | * If old kernel: | ||
216 | 192 | * Check the device numbers in superblock are right | ||
217 | 193 | * update superblock if any changes | ||
218 | 194 | * START_ARRAY | ||
219 | 195 | * | ||
220 | 196 | */ | ||
221 | 197 | int mdfd; | ||
222 | 198 | int clean; | ||
223 | 199 | int auto_assem = (mddev == NULL && !ident->uuid_set && | ||
224 | 200 | ident->super_minor == UnSet && ident->name[0] == 0 | ||
225 | 201 | && (ident->container == NULL || ident->member == NULL)); | ||
226 | 202 | int old_linux = 0; | ||
227 | 203 | int vers = vers; /* Keep gcc quite - it really is initialised */ | ||
228 | 204 | struct { | ||
229 | 205 | char *devname; | ||
230 | 206 | int uptodate; /* set once we decide that this device is as | ||
231 | 207 | * recent as everything else in the array. | ||
232 | 208 | */ | ||
233 | 209 | struct mdinfo i; | ||
234 | 210 | } *devices; | ||
235 | 211 | char *devmap; | ||
236 | 212 | int *best = NULL; /* indexed by raid_disk */ | ||
237 | 213 | int bestcnt = 0; | ||
238 | 214 | int devcnt = 0; | ||
239 | 215 | unsigned int okcnt, sparecnt, rebuilding_cnt; | ||
240 | 216 | unsigned int req_cnt; | ||
241 | 217 | int i; | ||
242 | 218 | int most_recent = 0; | ||
243 | 219 | int chosen_drive; | ||
244 | 220 | int change = 0; | ||
245 | 221 | int inargv = 0; | ||
246 | 222 | int report_missmatch; | ||
247 | 223 | #ifndef MDASSEMBLE | ||
248 | 224 | int bitmap_done; | ||
249 | 225 | #endif | ||
250 | 226 | int start_partial_ok = (runstop >= 0) && | ||
251 | 227 | (force || devlist==NULL || auto_assem); | ||
252 | 228 | unsigned int num_devs; | ||
253 | 229 | struct mddev_dev *tmpdev; | ||
254 | 230 | struct mdinfo info; | ||
255 | 231 | struct mdinfo *content = NULL; | ||
256 | 232 | char *avail; | ||
257 | 233 | int nextspare = 0; | ||
258 | 234 | char *name = NULL; | ||
259 | 235 | int trustworthy; | ||
260 | 236 | char chosen_name[1024]; | ||
261 | 237 | struct domainlist *domains = NULL; | ||
262 | 238 | |||
263 | 239 | if (get_linux_version() < 2004000) | ||
264 | 240 | old_linux = 1; | ||
265 | 241 | |||
266 | 242 | /* | ||
267 | 243 | * If any subdevs are listed, then any that don't | ||
268 | 244 | * match ident are discarded. Remainder must all match and | ||
269 | 245 | * become the array. | ||
270 | 246 | * If no subdevs, then we scan all devices in the config file, but | ||
271 | 247 | * there must be something in the identity | ||
272 | 248 | */ | ||
273 | 249 | |||
274 | 250 | if (!devlist && | ||
275 | 251 | ident->uuid_set == 0 && | ||
276 | 252 | (ident->super_minor < 0 || ident->super_minor == UnSet) && | ||
277 | 253 | ident->name[0] == 0 && | ||
278 | 254 | (ident->container == NULL || ident->member == NULL) && | ||
279 | 255 | ident->devices == NULL) { | ||
280 | 256 | fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n", | ||
281 | 257 | mddev ? mddev : "further assembly"); | ||
282 | 258 | return 1; | ||
283 | 259 | } | ||
284 | 260 | |||
285 | 261 | if (devlist == NULL) | ||
286 | 262 | devlist = conf_get_devs(); | ||
287 | 263 | else if (mddev) | ||
288 | 264 | inargv = 1; | ||
289 | 265 | |||
290 | 266 | report_missmatch = ((inargv && verbose >= 0) || verbose > 0); | ||
291 | 267 | try_again: | ||
292 | 268 | /* We come back here when doing auto-assembly and attempting some | ||
293 | 269 | * set of devices failed. Those are now marked as ->used==2 and | ||
294 | 270 | * we ignore them and try again | ||
295 | 271 | */ | ||
296 | 272 | |||
297 | 273 | tmpdev = devlist; num_devs = 0; | ||
298 | 274 | while (tmpdev) { | ||
299 | 275 | if (tmpdev->used) | ||
300 | 276 | tmpdev->used = 2; | ||
301 | 277 | else | ||
302 | 278 | num_devs++; | ||
303 | 279 | tmpdev = tmpdev->next; | ||
304 | 280 | } | ||
305 | 281 | |||
306 | 282 | if (!st && ident->st) st = ident->st; | ||
307 | 283 | |||
308 | 284 | if (verbose>0) | ||
309 | 285 | fprintf(stderr, Name ": looking for devices for %s\n", | ||
310 | 286 | mddev ? mddev : "further assembly"); | ||
311 | 287 | |||
312 | 288 | /* first walk the list of devices to find a consistent set | ||
313 | 289 | * that match the criterea, if that is possible. | ||
314 | 290 | * We flag the ones we like with 'used'. | ||
315 | 291 | */ | ||
316 | 292 | for (tmpdev = devlist; | ||
317 | 293 | tmpdev; | ||
318 | 294 | tmpdev = tmpdev ? tmpdev->next : NULL) { | ||
319 | 295 | char *devname = tmpdev->devname; | ||
320 | 296 | int dfd; | ||
321 | 297 | struct stat stb; | ||
322 | 298 | struct supertype *tst; | ||
323 | 299 | struct dev_policy *pol = NULL; | ||
324 | 300 | int found_container = 0; | ||
325 | 301 | |||
326 | 302 | if (tmpdev->used > 1) continue; | ||
327 | 303 | |||
328 | 304 | if (ident->devices && | ||
329 | 305 | !match_oneof(ident->devices, devname)) { | ||
330 | 306 | if (report_missmatch) | ||
331 | 307 | fprintf(stderr, Name ": %s is not one of %s\n", devname, ident->devices); | ||
332 | 308 | continue; | ||
333 | 309 | } | ||
334 | 310 | |||
335 | 311 | tst = dup_super(st); | ||
336 | 312 | |||
337 | 313 | dfd = dev_open(devname, O_RDONLY); | ||
338 | 314 | if (dfd < 0) { | ||
339 | 315 | if (report_missmatch) | ||
340 | 316 | fprintf(stderr, Name ": cannot open device %s: %s\n", | ||
341 | 317 | devname, strerror(errno)); | ||
342 | 318 | tmpdev->used = 2; | ||
343 | 319 | } else if (fstat(dfd, &stb)< 0) { | ||
344 | 320 | /* Impossible! */ | ||
345 | 321 | fprintf(stderr, Name ": fstat failed for %s: %s\n", | ||
346 | 322 | devname, strerror(errno)); | ||
347 | 323 | tmpdev->used = 2; | ||
348 | 324 | } else if ((stb.st_mode & S_IFMT) != S_IFBLK) { | ||
349 | 325 | fprintf(stderr, Name ": %s is not a block device.\n", | ||
350 | 326 | devname); | ||
351 | 327 | tmpdev->used = 2; | ||
352 | 328 | } else if (must_be_container(dfd)) { | ||
353 | 329 | if (st) { | ||
354 | 330 | /* already found some components, this cannot | ||
355 | 331 | * be another one. | ||
356 | 332 | */ | ||
357 | 333 | if (report_missmatch) | ||
358 | 334 | fprintf(stderr, Name ": %s is a container, but we are looking for components\n", | ||
359 | 335 | devname); | ||
360 | 336 | tmpdev->used = 2; | ||
361 | 337 | #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) | ||
362 | 338 | } if (!tst && (tst = super_by_fd(dfd, NULL)) == NULL) { | ||
363 | 339 | if (report_missmatch) | ||
364 | 340 | fprintf(stderr, Name ": not a recognisable container: %s\n", | ||
365 | 341 | devname); | ||
366 | 342 | tmpdev->used = 2; | ||
367 | 343 | #endif | ||
368 | 344 | } else if (!tst->ss->load_container | ||
369 | 345 | || tst->ss->load_container(tst, dfd, NULL)) { | ||
370 | 346 | if (report_missmatch) | ||
371 | 347 | fprintf(stderr, Name ": no correct container type: %s\n", | ||
372 | 348 | devname); | ||
373 | 349 | tmpdev->used = 2; | ||
374 | 350 | } else if (auto_assem && | ||
375 | 351 | !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)), | ||
376 | 352 | tst->ss->match_home(tst, homehost) == 1)) { | ||
377 | 353 | if (report_missmatch) | ||
378 | 354 | fprintf(stderr, Name ": %s has metadata type %s for which " | ||
379 | 355 | "auto-assembly is disabled\n", | ||
380 | 356 | devname, tst->ss->name); | ||
381 | 357 | tmpdev->used = 2; | ||
382 | 358 | } else | ||
383 | 359 | found_container = 1; | ||
384 | 360 | } else { | ||
385 | 361 | if (!tst && (tst = guess_super(dfd)) == NULL) { | ||
386 | 362 | if (report_missmatch) | ||
387 | 363 | fprintf(stderr, Name ": no recogniseable superblock on %s\n", | ||
388 | 364 | devname); | ||
389 | 365 | tmpdev->used = 2; | ||
390 | 366 | } else if (tst->ss->load_super(tst,dfd, NULL)) { | ||
391 | 367 | if (report_missmatch) | ||
392 | 368 | fprintf(stderr, Name ": no RAID superblock on %s\n", | ||
393 | 369 | devname); | ||
394 | 370 | tmpdev->used = 2; | ||
395 | 371 | } else if (tst->ss->compare_super == NULL) { | ||
396 | 372 | if (report_missmatch) | ||
397 | 373 | fprintf(stderr, Name ": Cannot assemble %s metadata on %s\n", | ||
398 | 374 | tst->ss->name, devname); | ||
399 | 375 | tmpdev->used = 2; | ||
400 | 376 | } else if (auto_assem && st == NULL && | ||
401 | 377 | !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)), | ||
402 | 378 | tst->ss->match_home(tst, homehost) == 1)) { | ||
403 | 379 | if (report_missmatch) | ||
404 | 380 | fprintf(stderr, Name ": %s has metadata type %s for which " | ||
405 | 381 | "auto-assembly is disabled\n", | ||
406 | 382 | devname, tst->ss->name); | ||
407 | 383 | tmpdev->used = 2; | ||
408 | 384 | } | ||
409 | 385 | } | ||
410 | 386 | if (dfd >= 0) close(dfd); | ||
411 | 387 | if (tmpdev->used == 2) { | ||
412 | 388 | if (auto_assem || !inargv) | ||
413 | 389 | /* Ignore unrecognised devices during auto-assembly */ | ||
414 | 390 | goto loop; | ||
415 | 391 | if (ident->uuid_set || ident->name[0] || | ||
416 | 392 | ident->super_minor != UnSet) | ||
417 | 393 | /* Ignore unrecognised device if looking for | ||
418 | 394 | * specific array */ | ||
419 | 395 | goto loop; | ||
420 | 396 | |||
421 | 397 | |||
422 | 398 | fprintf(stderr, Name ": %s has no superblock - assembly aborted\n", | ||
423 | 399 | devname); | ||
424 | 400 | if (st) | ||
425 | 401 | st->ss->free_super(st); | ||
426 | 402 | dev_policy_free(pol); | ||
427 | 403 | domain_free(domains); | ||
428 | 404 | return 1; | ||
429 | 405 | } | ||
430 | 406 | |||
431 | 407 | if (found_container) { | ||
432 | 408 | /* tmpdev is a container. We need to be either | ||
433 | 409 | * looking for a member, or auto-assembling | ||
434 | 410 | */ | ||
435 | 411 | /* should be safe to try an exclusive open now, we | ||
436 | 412 | * have rejected anything that some other mdadm might | ||
437 | 413 | * be looking at | ||
438 | 414 | */ | ||
439 | 415 | dfd = dev_open(devname, O_RDONLY | O_EXCL); | ||
440 | 416 | if (dfd < 0) { | ||
441 | 417 | if (report_missmatch) | ||
442 | 418 | fprintf(stderr, Name ": %s is busy - skipping\n", devname); | ||
443 | 419 | goto loop; | ||
444 | 420 | } | ||
445 | 421 | close(dfd); | ||
446 | 422 | |||
447 | 423 | if (ident->container) { | ||
448 | 424 | if (ident->container[0] == '/' && | ||
449 | 425 | !same_dev(ident->container, devname)) { | ||
450 | 426 | if (report_missmatch) | ||
451 | 427 | fprintf(stderr, Name ": %s is not the container required (%s)\n", | ||
452 | 428 | devname, ident->container); | ||
453 | 429 | goto loop; | ||
454 | 430 | } | ||
455 | 431 | if (ident->container[0] != '/') { | ||
456 | 432 | /* we have a uuid */ | ||
457 | 433 | int uuid[4]; | ||
458 | 434 | |||
459 | 435 | content = &info; | ||
460 | 436 | tst->ss->getinfo_super(tst, content, NULL); | ||
461 | 437 | |||
462 | 438 | if (!parse_uuid(ident->container, uuid) || | ||
463 | 439 | !same_uuid(content->uuid, uuid, tst->ss->swapuuid)) { | ||
464 | 440 | if (report_missmatch) | ||
465 | 441 | fprintf(stderr, Name ": %s has wrong UUID to be required container\n", | ||
466 | 442 | devname); | ||
467 | 443 | goto loop; | ||
468 | 444 | } | ||
469 | 445 | } | ||
470 | 446 | } | ||
471 | 447 | /* It is worth looking inside this container. | ||
472 | 448 | */ | ||
473 | 449 | if (verbose > 0) | ||
474 | 450 | fprintf(stderr, Name ": looking in container %s\n", | ||
475 | 451 | devname); | ||
476 | 452 | |||
477 | 453 | for (content = tst->ss->container_content(tst, NULL); | ||
478 | 454 | content; | ||
479 | 455 | content = content->next) { | ||
480 | 456 | |||
481 | 457 | if (!ident_matches(ident, content, tst, | ||
482 | 458 | homehost, update, | ||
483 | 459 | report_missmatch ? devname : NULL)) | ||
484 | 460 | /* message already printed */; | ||
485 | 461 | else if (is_member_busy(content->text_version)) { | ||
486 | 462 | if (report_missmatch) | ||
487 | 463 | fprintf(stderr, Name ": member %s in %s is already assembled\n", | ||
488 | 464 | content->text_version, | ||
489 | 465 | devname); | ||
490 | 466 | } else if (content->array.state & (1<<MD_SB_BLOCK_VOLUME)) { | ||
491 | 467 | /* do not assemble arrays with unsupported configurations */ | ||
492 | 468 | fprintf(stderr, Name ": Cannot activate member %s in %s.\n", | ||
493 | 469 | content->text_version, | ||
494 | 470 | devname); | ||
495 | 471 | } else | ||
496 | 472 | break; | ||
497 | 473 | } | ||
498 | 474 | if (!content) { | ||
499 | 475 | tmpdev->used = 2; | ||
500 | 476 | goto loop; /* empty container */ | ||
501 | 477 | } | ||
502 | 478 | |||
503 | 479 | st = tst; tst = NULL; | ||
504 | 480 | if (!auto_assem && inargv && tmpdev->next != NULL) { | ||
505 | 481 | fprintf(stderr, Name ": %s is a container, but is not " | ||
506 | 482 | "only device given: confused and aborting\n", | ||
507 | 483 | devname); | ||
508 | 484 | st->ss->free_super(st); | ||
509 | 485 | dev_policy_free(pol); | ||
510 | 486 | domain_free(domains); | ||
511 | 487 | return 1; | ||
512 | 488 | } | ||
513 | 489 | if (verbose > 0) | ||
514 | 490 | fprintf(stderr, Name ": found match on member %s in %s\n", | ||
515 | 491 | content->text_version, devname); | ||
516 | 492 | |||
517 | 493 | /* make sure we finished the loop */ | ||
518 | 494 | tmpdev = NULL; | ||
519 | 495 | goto loop; | ||
520 | 496 | } else { | ||
521 | 497 | |||
522 | 498 | content = &info; | ||
523 | 499 | tst->ss->getinfo_super(tst, content, NULL); | ||
524 | 500 | |||
525 | 501 | if (!ident_matches(ident, content, tst, | ||
526 | 502 | homehost, update, | ||
527 | 503 | report_missmatch ? devname : NULL)) | ||
528 | 504 | goto loop; | ||
529 | 505 | |||
530 | 506 | /* should be safe to try an exclusive open now, we | ||
531 | 507 | * have rejected anything that some other mdadm might | ||
532 | 508 | * be looking at | ||
533 | 509 | */ | ||
534 | 510 | dfd = dev_open(devname, O_RDONLY | O_EXCL); | ||
535 | 511 | if (dfd < 0) { | ||
536 | 512 | if (report_missmatch) | ||
537 | 513 | fprintf(stderr, Name ": %s is busy - skipping\n", devname); | ||
538 | 514 | goto loop; | ||
539 | 515 | } | ||
540 | 516 | close(dfd); | ||
541 | 517 | |||
542 | 518 | if (st == NULL) | ||
543 | 519 | st = dup_super(tst); | ||
544 | 520 | if (st->minor_version == -1) | ||
545 | 521 | st->minor_version = tst->minor_version; | ||
546 | 522 | |||
547 | 523 | if (memcmp(content->uuid, uuid_zero, | ||
548 | 524 | sizeof(int[4])) == 0) { | ||
549 | 525 | /* this is a floating spare. It cannot define | ||
550 | 526 | * an array unless there are no more arrays of | ||
551 | 527 | * this type to be found. It can be included | ||
552 | 528 | * in an array of this type though. | ||
553 | 529 | */ | ||
554 | 530 | tmpdev->used = 3; | ||
555 | 531 | goto loop; | ||
556 | 532 | } | ||
557 | 533 | |||
558 | 534 | if (st->ss != tst->ss || | ||
559 | 535 | st->minor_version != tst->minor_version || | ||
560 | 536 | st->ss->compare_super(st, tst) != 0) { | ||
561 | 537 | /* Some mismatch. If exactly one array matches this host, | ||
562 | 538 | * we can resolve on that one. | ||
563 | 539 | * Or, if we are auto assembling, we just ignore the second | ||
564 | 540 | * for now. | ||
565 | 541 | */ | ||
566 | 542 | if (auto_assem) | ||
567 | 543 | goto loop; | ||
568 | 544 | if (homehost) { | ||
569 | 545 | int first = st->ss->match_home(st, homehost); | ||
570 | 546 | int last = tst->ss->match_home(tst, homehost); | ||
571 | 547 | if (first != last && | ||
572 | 548 | (first == 1 || last == 1)) { | ||
573 | 549 | /* We can do something */ | ||
574 | 550 | if (first) {/* just ignore this one */ | ||
575 | 551 | if (report_missmatch) | ||
576 | 552 | fprintf(stderr, Name ": %s misses out due to wrong homehost\n", | ||
577 | 553 | devname); | ||
578 | 554 | goto loop; | ||
579 | 555 | } else { /* reject all those sofar */ | ||
580 | 556 | struct mddev_dev *td; | ||
581 | 557 | if (report_missmatch) | ||
582 | 558 | fprintf(stderr, Name ": %s overrides previous devices due to good homehost\n", | ||
583 | 559 | devname); | ||
584 | 560 | for (td=devlist; td != tmpdev; td=td->next) | ||
585 | 561 | if (td->used == 1) | ||
586 | 562 | td->used = 0; | ||
587 | 563 | tmpdev->used = 1; | ||
588 | 564 | goto loop; | ||
589 | 565 | } | ||
590 | 566 | } | ||
591 | 567 | } | ||
592 | 568 | fprintf(stderr, Name ": superblock on %s doesn't match others - assembly aborted\n", | ||
593 | 569 | devname); | ||
594 | 570 | tst->ss->free_super(tst); | ||
595 | 571 | st->ss->free_super(st); | ||
596 | 572 | dev_policy_free(pol); | ||
597 | 573 | domain_free(domains); | ||
598 | 574 | return 1; | ||
599 | 575 | } | ||
600 | 576 | tmpdev->used = 1; | ||
601 | 577 | } | ||
602 | 578 | loop: | ||
603 | 579 | /* Collect domain information from members only */ | ||
604 | 580 | if (tmpdev && tmpdev->used == 1) { | ||
605 | 581 | if (!pol) | ||
606 | 582 | pol = devnum_policy(stb.st_rdev); | ||
607 | 583 | domain_merge(&domains, pol, tst?tst->ss->name:NULL); | ||
608 | 584 | } | ||
609 | 585 | dev_policy_free(pol); | ||
610 | 586 | pol = NULL; | ||
611 | 587 | if (tst) | ||
612 | 588 | tst->ss->free_super(tst); | ||
613 | 589 | } | ||
614 | 590 | |||
615 | 591 | /* Check if we found some imsm spares but no members */ | ||
616 | 592 | if ((auto_assem || | ||
617 | 593 | (ident->uuid_set && | ||
618 | 594 | memcmp(uuid_zero, ident->uuid,sizeof(uuid_zero)) == 0)) && | ||
619 | 595 | (!st || !st->sb)) | ||
620 | 596 | for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) { | ||
621 | 597 | if (tmpdev->used != 3) | ||
622 | 598 | continue; | ||
623 | 599 | tmpdev->used = 1; | ||
624 | 600 | content = &info; | ||
625 | 601 | |||
626 | 602 | if (!st->sb) { | ||
627 | 603 | /* we need sb from one of the spares */ | ||
628 | 604 | int dfd = dev_open(tmpdev->devname, O_RDONLY); | ||
629 | 605 | if (dfd < 0 || | ||
630 | 606 | st->ss->load_super(st, dfd, NULL)) | ||
631 | 607 | tmpdev->used = 2; | ||
632 | 608 | if (dfd > 0) | ||
633 | 609 | close(dfd); | ||
634 | 610 | } | ||
635 | 611 | } | ||
636 | 612 | |||
637 | 613 | /* Now reject spares that don't match domains of identified members */ | ||
638 | 614 | for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) { | ||
639 | 615 | struct stat stb; | ||
640 | 616 | if (tmpdev->used != 3) | ||
641 | 617 | continue; | ||
642 | 618 | if (stat(tmpdev->devname, &stb)< 0) { | ||
643 | 619 | fprintf(stderr, Name ": fstat failed for %s: %s\n", | ||
644 | 620 | tmpdev->devname, strerror(errno)); | ||
645 | 621 | tmpdev->used = 2; | ||
646 | 622 | } else { | ||
647 | 623 | struct dev_policy *pol = devnum_policy(stb.st_rdev); | ||
648 | 624 | int dt = domain_test(domains, pol, NULL); | ||
649 | 625 | if (inargv && dt != 0) | ||
650 | 626 | /* take this spare as domains match | ||
651 | 627 | * if there are any */ | ||
652 | 628 | tmpdev->used = 1; | ||
653 | 629 | else if (!inargv && dt == 1) | ||
654 | 630 | /* device wasn't explicitly listed, so need | ||
655 | 631 | * explicit domain match - which we have */ | ||
656 | 632 | tmpdev->used = 1; | ||
657 | 633 | else | ||
658 | 634 | /* if domains don't match mark as unused */ | ||
659 | 635 | tmpdev->used = 0; | ||
660 | 636 | dev_policy_free(pol); | ||
661 | 637 | } | ||
662 | 638 | } | ||
663 | 639 | domain_free(domains); | ||
664 | 640 | |||
665 | 641 | if (!st || !st->sb || !content) | ||
666 | 642 | return 2; | ||
667 | 643 | |||
668 | 644 | /* Now need to open the array device. Use create_mddev */ | ||
669 | 645 | if (content == &info) | ||
670 | 646 | st->ss->getinfo_super(st, content, NULL); | ||
671 | 647 | |||
672 | 648 | trustworthy = FOREIGN; | ||
673 | 649 | name = content->name; | ||
674 | 650 | switch (st->ss->match_home(st, homehost) | ||
675 | 651 | ?: st->ss->match_home(st, "any")) { | ||
676 | 652 | case 1: | ||
677 | 653 | trustworthy = LOCAL; | ||
678 | 654 | name = strchr(content->name, ':'); | ||
679 | 655 | if (name) | ||
680 | 656 | name++; | ||
681 | 657 | else | ||
682 | 658 | name = content->name; | ||
683 | 659 | break; | ||
684 | 660 | } | ||
685 | 661 | if (!auto_assem) | ||
686 | 662 | /* If the array is listed in mdadm.conf or on | ||
687 | 663 | * command line, then we trust the name | ||
688 | 664 | * even if the array doesn't look local | ||
689 | 665 | */ | ||
690 | 666 | trustworthy = LOCAL; | ||
691 | 667 | |||
692 | 668 | if (name[0] == 0 && | ||
693 | 669 | content->array.level == LEVEL_CONTAINER) { | ||
694 | 670 | name = content->text_version; | ||
695 | 671 | trustworthy = METADATA; | ||
696 | 672 | } | ||
697 | 673 | |||
698 | 674 | if (name[0] && trustworthy != LOCAL && | ||
699 | 675 | ! require_homehost && | ||
700 | 676 | conf_name_is_free(name)) | ||
701 | 677 | trustworthy = LOCAL; | ||
702 | 678 | |||
703 | 679 | if (trustworthy == LOCAL && | ||
704 | 680 | strchr(name, ':')) | ||
705 | 681 | /* Ignore 'host:' prefix of name */ | ||
706 | 682 | name = strchr(name, ':')+1; | ||
707 | 683 | |||
708 | 684 | mdfd = create_mddev(mddev, name, ident->autof, trustworthy, | ||
709 | 685 | chosen_name); | ||
710 | 686 | if (mdfd < 0) { | ||
711 | 687 | st->ss->free_super(st); | ||
712 | 688 | if (auto_assem) | ||
713 | 689 | goto try_again; | ||
714 | 690 | return 1; | ||
715 | 691 | } | ||
716 | 692 | mddev = chosen_name; | ||
717 | 693 | vers = md_get_version(mdfd); | ||
718 | 694 | if (vers < 9000) { | ||
719 | 695 | fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n" | ||
720 | 696 | " Upgrade your kernel or try --build\n"); | ||
721 | 697 | close(mdfd); | ||
722 | 698 | return 1; | ||
723 | 699 | } | ||
724 | 700 | if (mddev_busy(fd2devnum(mdfd))) { | ||
725 | 701 | fprintf(stderr, Name ": %s already active, cannot restart it!\n", | ||
726 | 702 | mddev); | ||
727 | 703 | for (tmpdev = devlist ; | ||
728 | 704 | tmpdev && tmpdev->used != 1; | ||
729 | 705 | tmpdev = tmpdev->next) | ||
730 | 706 | ; | ||
731 | 707 | if (tmpdev && auto_assem) | ||
732 | 708 | fprintf(stderr, Name ": %s needed for %s...\n", | ||
733 | 709 | mddev, tmpdev->devname); | ||
734 | 710 | close(mdfd); | ||
735 | 711 | mdfd = -3; | ||
736 | 712 | st->ss->free_super(st); | ||
737 | 713 | if (auto_assem) | ||
738 | 714 | goto try_again; | ||
739 | 715 | return 1; | ||
740 | 716 | } | ||
741 | 717 | ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */ | ||
742 | 718 | |||
743 | 719 | #ifndef MDASSEMBLE | ||
744 | 720 | if (content != &info) { | ||
745 | 721 | /* This is a member of a container. Try starting the array. */ | ||
746 | 722 | int err; | ||
747 | 723 | err = assemble_container_content(st, mdfd, content, runstop, | ||
748 | 724 | chosen_name, verbose, | ||
749 | 725 | backup_file, freeze_reshape); | ||
750 | 726 | close(mdfd); | ||
751 | 727 | return err; | ||
752 | 728 | } | ||
753 | 729 | bitmap_done = 0; | ||
754 | 730 | #endif | ||
755 | 731 | /* Ok, no bad inconsistancy, we can try updating etc */ | ||
756 | 732 | devices = malloc(num_devs * sizeof(*devices)); | ||
757 | 733 | devmap = calloc(num_devs * content->array.raid_disks, 1); | ||
758 | 734 | for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used == 1) { | ||
759 | 735 | char *devname = tmpdev->devname; | ||
760 | 736 | struct stat stb; | ||
761 | 737 | /* looks like a good enough match to update the super block if needed */ | ||
762 | 738 | #ifndef MDASSEMBLE | ||
763 | 739 | if (update) { | ||
764 | 740 | int dfd; | ||
765 | 741 | /* prepare useful information in info structures */ | ||
766 | 742 | struct stat stb2; | ||
767 | 743 | struct supertype *tst; | ||
768 | 744 | int err; | ||
769 | 745 | fstat(mdfd, &stb2); | ||
770 | 746 | |||
771 | 747 | if (strcmp(update, "uuid")==0 && | ||
772 | 748 | !ident->uuid_set) { | ||
773 | 749 | int rfd; | ||
774 | 750 | if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || | ||
775 | 751 | read(rfd, ident->uuid, 16) != 16) { | ||
776 | 752 | *(__u32*)(ident->uuid) = random(); | ||
777 | 753 | *(__u32*)(ident->uuid+1) = random(); | ||
778 | 754 | *(__u32*)(ident->uuid+2) = random(); | ||
779 | 755 | *(__u32*)(ident->uuid+3) = random(); | ||
780 | 756 | } | ||
781 | 757 | if (rfd >= 0) close(rfd); | ||
782 | 758 | } | ||
783 | 759 | dfd = dev_open(devname, O_RDWR|O_EXCL); | ||
784 | 760 | |||
785 | 761 | tst = dup_super(st); | ||
786 | 762 | if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { | ||
787 | 763 | fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n", | ||
788 | 764 | devname); | ||
789 | 765 | if (dfd >= 0) | ||
790 | 766 | close(dfd); | ||
791 | 767 | close(mdfd); | ||
792 | 768 | free(devices); | ||
793 | 769 | free(devmap); | ||
794 | 770 | return 1; | ||
795 | 771 | } | ||
796 | 772 | tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks); | ||
797 | 773 | |||
798 | 774 | memcpy(content->uuid, ident->uuid, 16); | ||
799 | 775 | strcpy(content->name, ident->name); | ||
800 | 776 | content->array.md_minor = minor(stb2.st_rdev); | ||
801 | 777 | |||
802 | 778 | if (strcmp(update, "byteorder") == 0) | ||
803 | 779 | err = 0; | ||
804 | 780 | else | ||
805 | 781 | err = tst->ss->update_super(tst, content, update, | ||
806 | 782 | devname, verbose, | ||
807 | 783 | ident->uuid_set, | ||
808 | 784 | homehost); | ||
809 | 785 | if (err < 0) { | ||
810 | 786 | fprintf(stderr, | ||
811 | 787 | Name ": --update=%s not understood" | ||
812 | 788 | " for %s metadata\n", | ||
813 | 789 | update, tst->ss->name); | ||
814 | 790 | tst->ss->free_super(tst); | ||
815 | 791 | free(tst); | ||
816 | 792 | close(mdfd); | ||
817 | 793 | close(dfd); | ||
818 | 794 | free(devices); | ||
819 | 795 | free(devmap); | ||
820 | 796 | return 1; | ||
821 | 797 | } | ||
822 | 798 | if (strcmp(update, "uuid")==0 && | ||
823 | 799 | !ident->uuid_set) { | ||
824 | 800 | ident->uuid_set = 1; | ||
825 | 801 | memcpy(ident->uuid, content->uuid, 16); | ||
826 | 802 | } | ||
827 | 803 | if (tst->ss->store_super(tst, dfd)) | ||
828 | 804 | fprintf(stderr, Name ": Could not re-write superblock on %s.\n", | ||
829 | 805 | devname); | ||
830 | 806 | close(dfd); | ||
831 | 807 | |||
832 | 808 | if (strcmp(update, "uuid")==0 && | ||
833 | 809 | ident->bitmap_fd >= 0 && !bitmap_done) { | ||
834 | 810 | if (bitmap_update_uuid(ident->bitmap_fd, | ||
835 | 811 | content->uuid, | ||
836 | 812 | tst->ss->swapuuid) != 0) | ||
837 | 813 | fprintf(stderr, Name ": Could not update uuid on external bitmap.\n"); | ||
838 | 814 | else | ||
839 | 815 | bitmap_done = 1; | ||
840 | 816 | } | ||
841 | 817 | tst->ss->free_super(tst); | ||
842 | 818 | } else | ||
843 | 819 | #endif | ||
844 | 820 | { | ||
845 | 821 | struct supertype *tst = dup_super(st); | ||
846 | 822 | int dfd; | ||
847 | 823 | dfd = dev_open(devname, O_RDWR|O_EXCL); | ||
848 | 824 | |||
849 | 825 | if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { | ||
850 | 826 | fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n", | ||
851 | 827 | devname); | ||
852 | 828 | if (dfd >= 0) | ||
853 | 829 | close(dfd); | ||
854 | 830 | close(mdfd); | ||
855 | 831 | free(devices); | ||
856 | 832 | free(devmap); | ||
857 | 833 | return 1; | ||
858 | 834 | } | ||
859 | 835 | tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks); | ||
860 | 836 | tst->ss->free_super(tst); | ||
861 | 837 | close(dfd); | ||
862 | 838 | } | ||
863 | 839 | |||
864 | 840 | stat(devname, &stb); | ||
865 | 841 | |||
866 | 842 | if (verbose > 0) | ||
867 | 843 | fprintf(stderr, Name ": %s is identified as a member of %s, slot %d.\n", | ||
868 | 844 | devname, mddev, content->disk.raid_disk); | ||
869 | 845 | devices[devcnt].devname = devname; | ||
870 | 846 | devices[devcnt].uptodate = 0; | ||
871 | 847 | devices[devcnt].i = *content; | ||
872 | 848 | devices[devcnt].i.disk.major = major(stb.st_rdev); | ||
873 | 849 | devices[devcnt].i.disk.minor = minor(stb.st_rdev); | ||
874 | 850 | if (most_recent < devcnt) { | ||
875 | 851 | if (devices[devcnt].i.events | ||
876 | 852 | > devices[most_recent].i.events) | ||
877 | 853 | most_recent = devcnt; | ||
878 | 854 | } | ||
879 | 855 | if (content->array.level == LEVEL_MULTIPATH) | ||
880 | 856 | /* with multipath, the raid_disk from the superblock is meaningless */ | ||
881 | 857 | i = devcnt; | ||
882 | 858 | else | ||
883 | 859 | i = devices[devcnt].i.disk.raid_disk; | ||
884 | 860 | if (i+1 == 0) { | ||
885 | 861 | if (nextspare < content->array.raid_disks) | ||
886 | 862 | nextspare = content->array.raid_disks; | ||
887 | 863 | i = nextspare++; | ||
888 | 864 | } else { | ||
889 | 865 | if (i >= content->array.raid_disks && | ||
890 | 866 | i >= nextspare) | ||
891 | 867 | nextspare = i+1; | ||
892 | 868 | } | ||
893 | 869 | if (i < 10000) { | ||
894 | 870 | if (i >= bestcnt) { | ||
895 | 871 | int newbestcnt = i+10; | ||
896 | 872 | int *newbest = malloc(sizeof(int)*newbestcnt); | ||
897 | 873 | int c; | ||
898 | 874 | for (c=0; c < newbestcnt; c++) | ||
899 | 875 | if (c < bestcnt) | ||
900 | 876 | newbest[c] = best[c]; | ||
901 | 877 | else | ||
902 | 878 | newbest[c] = -1; | ||
903 | 879 | if (best)free(best); | ||
904 | 880 | best = newbest; | ||
905 | 881 | bestcnt = newbestcnt; | ||
906 | 882 | } | ||
907 | 883 | if (best[i] >=0 && | ||
908 | 884 | devices[best[i]].i.events | ||
909 | 885 | == devices[devcnt].i.events | ||
910 | 886 | && (devices[best[i]].i.disk.minor | ||
911 | 887 | != devices[devcnt].i.disk.minor) | ||
912 | 888 | && st->ss == &super0 | ||
913 | 889 | && content->array.level != LEVEL_MULTIPATH) { | ||
914 | 890 | /* two different devices with identical superblock. | ||
915 | 891 | * Could be a mis-detection caused by overlapping | ||
916 | 892 | * partitions. fail-safe. | ||
917 | 893 | */ | ||
918 | 894 | fprintf(stderr, Name ": WARNING %s and %s appear" | ||
919 | 895 | " to have very similar superblocks.\n" | ||
920 | 896 | " If they are really different, " | ||
921 | 897 | "please --zero the superblock on one\n" | ||
922 | 898 | " If they are the same or overlap," | ||
923 | 899 | " please remove one from %s.\n", | ||
924 | 900 | devices[best[i]].devname, devname, | ||
925 | 901 | inargv ? "the list" : | ||
926 | 902 | "the\n DEVICE list in mdadm.conf" | ||
927 | 903 | ); | ||
928 | 904 | close(mdfd); | ||
929 | 905 | free(devices); | ||
930 | 906 | free(devmap); | ||
931 | 907 | return 1; | ||
932 | 908 | } | ||
933 | 909 | if (best[i] == -1 | ||
934 | 910 | || (devices[best[i]].i.events | ||
935 | 911 | < devices[devcnt].i.events)) | ||
936 | 912 | best[i] = devcnt; | ||
937 | 913 | } | ||
938 | 914 | devcnt++; | ||
939 | 915 | } | ||
940 | 916 | |||
941 | 917 | if (devcnt == 0) { | ||
942 | 918 | fprintf(stderr, Name ": no devices found for %s\n", | ||
943 | 919 | mddev); | ||
944 | 920 | if (st) | ||
945 | 921 | st->ss->free_super(st); | ||
946 | 922 | close(mdfd); | ||
947 | 923 | free(devices); | ||
948 | 924 | free(devmap); | ||
949 | 925 | return 1; | ||
950 | 926 | } | ||
951 | 927 | |||
952 | 928 | if (update && strcmp(update, "byteorder")==0) | ||
953 | 929 | st->minor_version = 90; | ||
954 | 930 | |||
955 | 931 | st->ss->getinfo_super(st, content, NULL); | ||
956 | 932 | clean = content->array.state & 1; | ||
957 | 933 | |||
958 | 934 | /* now we have some devices that might be suitable. | ||
959 | 935 | * I wonder how many | ||
960 | 936 | */ | ||
961 | 937 | avail = malloc(content->array.raid_disks); | ||
962 | 938 | memset(avail, 0, content->array.raid_disks); | ||
963 | 939 | okcnt = 0; | ||
964 | 940 | sparecnt=0; | ||
965 | 941 | rebuilding_cnt=0; | ||
966 | 942 | for (i=0; i< bestcnt; i++) { | ||
967 | 943 | int j = best[i]; | ||
968 | 944 | int event_margin = 1; /* always allow a difference of '1' | ||
969 | 945 | * like the kernel does | ||
970 | 946 | */ | ||
971 | 947 | if (j < 0) continue; | ||
972 | 948 | /* note: we ignore error flags in multipath arrays | ||
973 | 949 | * as they don't make sense | ||
974 | 950 | */ | ||
975 | 951 | if (content->array.level != LEVEL_MULTIPATH) | ||
976 | 952 | if (!(devices[j].i.disk.state & (1<<MD_DISK_ACTIVE))) { | ||
977 | 953 | if (!(devices[j].i.disk.state | ||
978 | 954 | & (1<<MD_DISK_FAULTY))) { | ||
979 | 955 | devices[j].uptodate = 1; | ||
980 | 956 | sparecnt++; | ||
981 | 957 | } | ||
982 | 958 | continue; | ||
983 | 959 | } | ||
984 | 960 | /* If this device thinks that 'most_recent' has failed, then | ||
985 | 961 | * we must reject this device. | ||
986 | 962 | */ | ||
987 | 963 | if (j != most_recent && | ||
988 | 964 | content->array.raid_disks > 0 && | ||
989 | 965 | devices[most_recent].i.disk.raid_disk >= 0 && | ||
990 | 966 | devmap[j * content->array.raid_disks + devices[most_recent].i.disk.raid_disk] == 0) { | ||
991 | 967 | if (verbose > -1) | ||
992 | 968 | fprintf(stderr, Name ": ignoring %s as it reports %s as failed\n", | ||
993 | 969 | devices[j].devname, devices[most_recent].devname); | ||
994 | 970 | best[i] = -1; | ||
995 | 971 | continue; | ||
996 | 972 | } | ||
997 | 973 | if (devices[j].i.events+event_margin >= | ||
998 | 974 | devices[most_recent].i.events) { | ||
999 | 975 | devices[j].uptodate = 1; | ||
1000 | 976 | if (i < content->array.raid_disks) { | ||
1001 | 977 | if (devices[j].i.recovery_start == MaxSector || | ||
1002 | 978 | (content->reshape_active && | ||
1003 | 979 | ((i >= content->array.raid_disks - content->delta_disks) || | ||
1004 | 980 | (i >= content->array.raid_disks - content->delta_disks - 1 | ||
1005 | 981 | && content->array.level == 4)))) { | ||
1006 | 982 | okcnt++; | ||
1007 | 983 | avail[i]=1; | ||
1008 | 984 | } else | ||
1009 | 985 | rebuilding_cnt++; | ||
1010 | 986 | } else | ||
1011 | 987 | sparecnt++; | ||
1012 | 988 | } | ||
1013 | 989 | } | ||
1014 | 990 | free(devmap); | ||
1015 | 991 | while (force && | ||
1016 | 992 | (!enough(content->array.level, content->array.raid_disks, | ||
1017 | 993 | content->array.layout, 1, | ||
1018 | 994 | avail) | ||
1019 | 995 | || | ||
1020 | 996 | (content->reshape_active && content->delta_disks > 0 && | ||
1021 | 997 | !enough(content->array.level, (content->array.raid_disks | ||
1022 | 998 | - content->delta_disks), | ||
1023 | 999 | content->new_layout, 1, | ||
1024 | 1000 | avail) | ||
1025 | 1001 | ))) { | ||
1026 | 1002 | /* Choose the newest best drive which is | ||
1027 | 1003 | * not up-to-date, update the superblock | ||
1028 | 1004 | * and add it. | ||
1029 | 1005 | */ | ||
1030 | 1006 | int fd; | ||
1031 | 1007 | struct supertype *tst; | ||
1032 | 1008 | unsigned long long current_events; | ||
1033 | 1009 | chosen_drive = -1; | ||
1034 | 1010 | for (i = 0; i < content->array.raid_disks && i < bestcnt; i++) { | ||
1035 | 1011 | int j = best[i]; | ||
1036 | 1012 | if (j>=0 && | ||
1037 | 1013 | !devices[j].uptodate && | ||
1038 | 1014 | devices[j].i.recovery_start == MaxSector && | ||
1039 | 1015 | (chosen_drive < 0 || | ||
1040 | 1016 | devices[j].i.events | ||
1041 | 1017 | > devices[chosen_drive].i.events)) | ||
1042 | 1018 | chosen_drive = j; | ||
1043 | 1019 | } | ||
1044 | 1020 | if (chosen_drive < 0) | ||
1045 | 1021 | break; | ||
1046 | 1022 | current_events = devices[chosen_drive].i.events; | ||
1047 | 1023 | add_another: | ||
1048 | 1024 | if (verbose >= 0) | ||
1049 | 1025 | fprintf(stderr, Name ": forcing event count in %s(%d) from %d upto %d\n", | ||
1050 | 1026 | devices[chosen_drive].devname, | ||
1051 | 1027 | devices[chosen_drive].i.disk.raid_disk, | ||
1052 | 1028 | (int)(devices[chosen_drive].i.events), | ||
1053 | 1029 | (int)(devices[most_recent].i.events)); | ||
1054 | 1030 | fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL); | ||
1055 | 1031 | if (fd < 0) { | ||
1056 | 1032 | fprintf(stderr, Name ": Couldn't open %s for write - not updating\n", | ||
1057 | 1033 | devices[chosen_drive].devname); | ||
1058 | 1034 | devices[chosen_drive].i.events = 0; | ||
1059 | 1035 | continue; | ||
1060 | 1036 | } | ||
1061 | 1037 | tst = dup_super(st); | ||
1062 | 1038 | if (tst->ss->load_super(tst,fd, NULL)) { | ||
1063 | 1039 | close(fd); | ||
1064 | 1040 | fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n", | ||
1065 | 1041 | devices[chosen_drive].devname); | ||
1066 | 1042 | devices[chosen_drive].i.events = 0; | ||
1067 | 1043 | continue; | ||
1068 | 1044 | } | ||
1069 | 1045 | content->events = devices[most_recent].i.events; | ||
1070 | 1046 | tst->ss->update_super(tst, content, "force-one", | ||
1071 | 1047 | devices[chosen_drive].devname, verbose, | ||
1072 | 1048 | 0, NULL); | ||
1073 | 1049 | |||
1074 | 1050 | if (tst->ss->store_super(tst, fd)) { | ||
1075 | 1051 | close(fd); | ||
1076 | 1052 | fprintf(stderr, Name ": Could not re-write superblock on %s\n", | ||
1077 | 1053 | devices[chosen_drive].devname); | ||
1078 | 1054 | devices[chosen_drive].i.events = 0; | ||
1079 | 1055 | tst->ss->free_super(tst); | ||
1080 | 1056 | continue; | ||
1081 | 1057 | } | ||
1082 | 1058 | close(fd); | ||
1083 | 1059 | devices[chosen_drive].i.events = devices[most_recent].i.events; | ||
1084 | 1060 | devices[chosen_drive].uptodate = 1; | ||
1085 | 1061 | avail[chosen_drive] = 1; | ||
1086 | 1062 | okcnt++; | ||
1087 | 1063 | tst->ss->free_super(tst); | ||
1088 | 1064 | |||
1089 | 1065 | /* If there are any other drives of the same vintage, | ||
1090 | 1066 | * add them in as well. We can't lose and we might gain | ||
1091 | 1067 | */ | ||
1092 | 1068 | for (i = 0; i < content->array.raid_disks && i < bestcnt ; i++) { | ||
1093 | 1069 | int j = best[i]; | ||
1094 | 1070 | if (j >= 0 && | ||
1095 | 1071 | !devices[j].uptodate && | ||
1096 | 1072 | devices[j].i.recovery_start == MaxSector && | ||
1097 | 1073 | devices[j].i.events == current_events) { | ||
1098 | 1074 | chosen_drive = j; | ||
1099 | 1075 | goto add_another; | ||
1100 | 1076 | } | ||
1101 | 1077 | } | ||
1102 | 1078 | } | ||
1103 | 1079 | |||
1104 | 1080 | /* Now we want to look at the superblock which the kernel will base things on | ||
1105 | 1081 | * and compare the devices that we think are working with the devices that the | ||
1106 | 1082 | * superblock thinks are working. | ||
1107 | 1083 | * If there are differences and --force is given, then update this chosen | ||
1108 | 1084 | * superblock. | ||
1109 | 1085 | */ | ||
1110 | 1086 | chosen_drive = -1; | ||
1111 | 1087 | st->ss->free_super(st); | ||
1112 | 1088 | for (i=0; chosen_drive < 0 && i<bestcnt; i++) { | ||
1113 | 1089 | int j = best[i]; | ||
1114 | 1090 | int fd; | ||
1115 | 1091 | |||
1116 | 1092 | if (j<0) | ||
1117 | 1093 | continue; | ||
1118 | 1094 | if (!devices[j].uptodate) | ||
1119 | 1095 | continue; | ||
1120 | 1096 | if (devices[j].i.events < devices[most_recent].i.events) | ||
1121 | 1097 | continue; | ||
1122 | 1098 | chosen_drive = j; | ||
1123 | 1099 | if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) { | ||
1124 | 1100 | fprintf(stderr, Name ": Cannot open %s: %s\n", | ||
1125 | 1101 | devices[j].devname, strerror(errno)); | ||
1126 | 1102 | close(mdfd); | ||
1127 | 1103 | free(devices); | ||
1128 | 1104 | return 1; | ||
1129 | 1105 | } | ||
1130 | 1106 | if (st->ss->load_super(st,fd, NULL)) { | ||
1131 | 1107 | close(fd); | ||
1132 | 1108 | fprintf(stderr, Name ": RAID superblock has disappeared from %s\n", | ||
1133 | 1109 | devices[j].devname); | ||
1134 | 1110 | close(mdfd); | ||
1135 | 1111 | free(devices); | ||
1136 | 1112 | return 1; | ||
1137 | 1113 | } | ||
1138 | 1114 | close(fd); | ||
1139 | 1115 | } | ||
1140 | 1116 | if (st->sb == NULL) { | ||
1141 | 1117 | fprintf(stderr, Name ": No suitable drives found for %s\n", mddev); | ||
1142 | 1118 | close(mdfd); | ||
1143 | 1119 | free(devices); | ||
1144 | 1120 | return 1; | ||
1145 | 1121 | } | ||
1146 | 1122 | st->ss->getinfo_super(st, content, NULL); | ||
1147 | 1123 | #ifndef MDASSEMBLE | ||
1148 | 1124 | sysfs_init(content, mdfd, 0); | ||
1149 | 1125 | #endif | ||
1150 | 1126 | for (i=0; i<bestcnt; i++) { | ||
1151 | 1127 | int j = best[i]; | ||
1152 | 1128 | unsigned int desired_state; | ||
1153 | 1129 | |||
1154 | 1130 | if (i < content->array.raid_disks) | ||
1155 | 1131 | desired_state = (1<<MD_DISK_ACTIVE) | (1<<MD_DISK_SYNC); | ||
1156 | 1132 | else | ||
1157 | 1133 | desired_state = 0; | ||
1158 | 1134 | |||
1159 | 1135 | if (j<0) | ||
1160 | 1136 | continue; | ||
1161 | 1137 | if (!devices[j].uptodate) | ||
1162 | 1138 | continue; | ||
1163 | 1139 | |||
1164 | 1140 | devices[j].i.disk.state = desired_state; | ||
1165 | 1141 | if (!(devices[j].i.array.state & 1)) | ||
1166 | 1142 | clean = 0; | ||
1167 | 1143 | |||
1168 | 1144 | if (st->ss->update_super(st, &devices[j].i, "assemble", NULL, | ||
1169 | 1145 | verbose, 0, NULL)) { | ||
1170 | 1146 | if (force) { | ||
1171 | 1147 | if (verbose >= 0) | ||
1172 | 1148 | fprintf(stderr, Name ": " | ||
1173 | 1149 | "clearing FAULTY flag for device %d in %s for %s\n", | ||
1174 | 1150 | j, mddev, devices[j].devname); | ||
1175 | 1151 | change = 1; | ||
1176 | 1152 | } else { | ||
1177 | 1153 | if (verbose >= -1) | ||
1178 | 1154 | fprintf(stderr, Name ": " | ||
1179 | 1155 | "device %d in %s has wrong state in superblock, but %s seems ok\n", | ||
1180 | 1156 | i, mddev, devices[j].devname); | ||
1181 | 1157 | } | ||
1182 | 1158 | } | ||
1183 | 1159 | #if 0 | ||
1184 | 1160 | if (!(super.disks[i].i.disk.state & (1 << MD_DISK_FAULTY))) { | ||
1185 | 1161 | fprintf(stderr, Name ": devices %d of %s is not marked FAULTY in superblock, but cannot be found\n", | ||
1186 | 1162 | i, mddev); | ||
1187 | 1163 | } | ||
1188 | 1164 | #endif | ||
1189 | 1165 | } | ||
1190 | 1166 | if (force && !clean && | ||
1191 | 1167 | !enough(content->array.level, content->array.raid_disks, | ||
1192 | 1168 | content->array.layout, clean, | ||
1193 | 1169 | avail)) { | ||
1194 | 1170 | change += st->ss->update_super(st, content, "force-array", | ||
1195 | 1171 | devices[chosen_drive].devname, verbose, | ||
1196 | 1172 | 0, NULL); | ||
1197 | 1173 | clean = 1; | ||
1198 | 1174 | } | ||
1199 | 1175 | |||
1200 | 1176 | if (change) { | ||
1201 | 1177 | int fd; | ||
1202 | 1178 | fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL); | ||
1203 | 1179 | if (fd < 0) { | ||
1204 | 1180 | fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n", | ||
1205 | 1181 | devices[chosen_drive].devname); | ||
1206 | 1182 | close(mdfd); | ||
1207 | 1183 | free(devices); | ||
1208 | 1184 | return 1; | ||
1209 | 1185 | } | ||
1210 | 1186 | if (st->ss->store_super(st, fd)) { | ||
1211 | 1187 | close(fd); | ||
1212 | 1188 | fprintf(stderr, Name ": Could not re-write superblock on %s\n", | ||
1213 | 1189 | devices[chosen_drive].devname); | ||
1214 | 1190 | close(mdfd); | ||
1215 | 1191 | free(devices); | ||
1216 | 1192 | return 1; | ||
1217 | 1193 | } | ||
1218 | 1194 | if (verbose >= 0) | ||
1219 | 1195 | fprintf(stderr, Name ": Marking array %s as 'clean'\n", | ||
1220 | 1196 | mddev); | ||
1221 | 1197 | close(fd); | ||
1222 | 1198 | } | ||
1223 | 1199 | |||
1224 | 1200 | /* If we are in the middle of a reshape we may need to restore saved data | ||
1225 | 1201 | * that was moved aside due to the reshape overwriting live data | ||
1226 | 1202 | * The code of doing this lives in Grow.c | ||
1227 | 1203 | */ | ||
1228 | 1204 | #ifndef MDASSEMBLE | ||
1229 | 1205 | if (content->reshape_active) { | ||
1230 | 1206 | int err = 0; | ||
1231 | 1207 | int *fdlist = malloc(sizeof(int)* bestcnt); | ||
1232 | 1208 | if (verbose > 0) | ||
1233 | 1209 | fprintf(stderr, Name ":%s has an active reshape - checking " | ||
1234 | 1210 | "if critical section needs to be restored\n", | ||
1235 | 1211 | chosen_name); | ||
1236 | 1212 | for (i=0; i<bestcnt; i++) { | ||
1237 | 1213 | int j = best[i]; | ||
1238 | 1214 | if (j >= 0) { | ||
1239 | 1215 | fdlist[i] = dev_open(devices[j].devname, O_RDWR|O_EXCL); | ||
1240 | 1216 | if (fdlist[i] < 0) { | ||
1241 | 1217 | fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n", | ||
1242 | 1218 | devices[j].devname); | ||
1243 | 1219 | err = 1; | ||
1244 | 1220 | break; | ||
1245 | 1221 | } | ||
1246 | 1222 | } else | ||
1247 | 1223 | fdlist[i] = -1; | ||
1248 | 1224 | } | ||
1249 | 1225 | if (!err) { | ||
1250 | 1226 | if (st->ss->external && st->ss->recover_backup) | ||
1251 | 1227 | err = st->ss->recover_backup(st, content); | ||
1252 | 1228 | else | ||
1253 | 1229 | err = Grow_restart(st, content, fdlist, bestcnt, | ||
1254 | 1230 | backup_file, verbose > 0); | ||
1255 | 1231 | if (err && invalid_backup) { | ||
1256 | 1232 | if (verbose > 0) | ||
1257 | 1233 | fprintf(stderr, Name ": continuing" | ||
1258 | 1234 | " without restoring backup\n"); | ||
1259 | 1235 | err = 0; | ||
1260 | 1236 | } | ||
1261 | 1237 | } | ||
1262 | 1238 | while (i>0) { | ||
1263 | 1239 | i--; | ||
1264 | 1240 | if (fdlist[i]>=0) close(fdlist[i]); | ||
1265 | 1241 | } | ||
1266 | 1242 | if (err) { | ||
1267 | 1243 | fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n"); | ||
1268 | 1244 | if (backup_file == NULL) | ||
1269 | 1245 | fprintf(stderr," Possibly you needed to specify the --backup-file\n"); | ||
1270 | 1246 | close(mdfd); | ||
1271 | 1247 | free(devices); | ||
1272 | 1248 | return err; | ||
1273 | 1249 | } | ||
1274 | 1250 | } | ||
1275 | 1251 | #endif | ||
1276 | 1252 | /* count number of in-sync devices according to the superblock. | ||
1277 | 1253 | * We must have this number to start the array without -s or -R | ||
1278 | 1254 | */ | ||
1279 | 1255 | req_cnt = content->array.working_disks; | ||
1280 | 1256 | |||
1281 | 1257 | /* Almost ready to actually *do* something */ | ||
1282 | 1258 | if (!old_linux) { | ||
1283 | 1259 | int rv; | ||
1284 | 1260 | |||
1285 | 1261 | /* First, fill in the map, so that udev can find our name | ||
1286 | 1262 | * as soon as we become active. | ||
1287 | 1263 | */ | ||
1288 | 1264 | map_update(NULL, fd2devnum(mdfd), content->text_version, | ||
1289 | 1265 | content->uuid, chosen_name); | ||
1290 | 1266 | |||
1291 | 1267 | rv = set_array_info(mdfd, st, content); | ||
1292 | 1268 | if (rv) { | ||
1293 | 1269 | fprintf(stderr, Name ": failed to set array info for %s: %s\n", | ||
1294 | 1270 | mddev, strerror(errno)); | ||
1295 | 1271 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
1296 | 1272 | close(mdfd); | ||
1297 | 1273 | free(devices); | ||
1298 | 1274 | return 1; | ||
1299 | 1275 | } | ||
1300 | 1276 | if (ident->bitmap_fd >= 0) { | ||
1301 | 1277 | if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) { | ||
1302 | 1278 | fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n"); | ||
1303 | 1279 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
1304 | 1280 | close(mdfd); | ||
1305 | 1281 | free(devices); | ||
1306 | 1282 | return 1; | ||
1307 | 1283 | } | ||
1308 | 1284 | } else if (ident->bitmap_file) { | ||
1309 | 1285 | /* From config file */ | ||
1310 | 1286 | int bmfd = open(ident->bitmap_file, O_RDWR); | ||
1311 | 1287 | if (bmfd < 0) { | ||
1312 | 1288 | fprintf(stderr, Name ": Could not open bitmap file %s\n", | ||
1313 | 1289 | ident->bitmap_file); | ||
1314 | 1290 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
1315 | 1291 | close(mdfd); | ||
1316 | 1292 | free(devices); | ||
1317 | 1293 | return 1; | ||
1318 | 1294 | } | ||
1319 | 1295 | if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) { | ||
1320 | 1296 | fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev); | ||
1321 | 1297 | close(bmfd); | ||
1322 | 1298 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
1323 | 1299 | close(mdfd); | ||
1324 | 1300 | free(devices); | ||
1325 | 1301 | return 1; | ||
1326 | 1302 | } | ||
1327 | 1303 | close(bmfd); | ||
1328 | 1304 | } | ||
1329 | 1305 | |||
1330 | 1306 | /* First, add the raid disks, but add the chosen one last */ | ||
1331 | 1307 | for (i=0; i<= bestcnt; i++) { | ||
1332 | 1308 | int j; | ||
1333 | 1309 | if (i < bestcnt) { | ||
1334 | 1310 | j = best[i]; | ||
1335 | 1311 | if (j == chosen_drive) | ||
1336 | 1312 | continue; | ||
1337 | 1313 | } else | ||
1338 | 1314 | j = chosen_drive; | ||
1339 | 1315 | |||
1340 | 1316 | if (j >= 0 /* && devices[j].uptodate */) { | ||
1341 | 1317 | int dfd = dev_open(devices[j].devname, | ||
1342 | 1318 | O_RDWR|O_EXCL); | ||
1343 | 1319 | if (dfd >= 0) { | ||
1344 | 1320 | remove_partitions(dfd); | ||
1345 | 1321 | close(dfd); | ||
1346 | 1322 | } | ||
1347 | 1323 | rv = add_disk(mdfd, st, content, &devices[j].i); | ||
1348 | 1324 | |||
1349 | 1325 | if (rv) { | ||
1350 | 1326 | fprintf(stderr, Name ": failed to add " | ||
1351 | 1327 | "%s to %s: %s\n", | ||
1352 | 1328 | devices[j].devname, | ||
1353 | 1329 | mddev, | ||
1354 | 1330 | strerror(errno)); | ||
1355 | 1331 | if (i < content->array.raid_disks | ||
1356 | 1332 | || i == bestcnt) | ||
1357 | 1333 | okcnt--; | ||
1358 | 1334 | else | ||
1359 | 1335 | sparecnt--; | ||
1360 | 1336 | } else if (verbose > 0) | ||
1361 | 1337 | fprintf(stderr, Name ": added %s " | ||
1362 | 1338 | "to %s as %d%s\n", | ||
1363 | 1339 | devices[j].devname, mddev, | ||
1364 | 1340 | devices[j].i.disk.raid_disk, | ||
1365 | 1341 | devices[j].uptodate?"": | ||
1366 | 1342 | " (possibly out of date)"); | ||
1367 | 1343 | } else if (verbose > 0 && i < content->array.raid_disks) | ||
1368 | 1344 | fprintf(stderr, Name ": no uptodate device for " | ||
1369 | 1345 | "slot %d of %s\n", | ||
1370 | 1346 | i, mddev); | ||
1371 | 1347 | } | ||
1372 | 1348 | |||
1373 | 1349 | if (content->array.level == LEVEL_CONTAINER) { | ||
1374 | 1350 | if (verbose >= 0) { | ||
1375 | 1351 | fprintf(stderr, Name ": Container %s has been " | ||
1376 | 1352 | "assembled with %d drive%s", | ||
1377 | 1353 | mddev, okcnt+sparecnt, okcnt+sparecnt==1?"":"s"); | ||
1378 | 1354 | if (okcnt < (unsigned)content->array.raid_disks) | ||
1379 | 1355 | fprintf(stderr, " (out of %d)", | ||
1380 | 1356 | content->array.raid_disks); | ||
1381 | 1357 | fprintf(stderr, "\n"); | ||
1382 | 1358 | } | ||
1383 | 1359 | st->ss->free_super(st); | ||
1384 | 1360 | sysfs_uevent(content, "change"); | ||
1385 | 1361 | wait_for(chosen_name, mdfd); | ||
1386 | 1362 | close(mdfd); | ||
1387 | 1363 | free(devices); | ||
1388 | 1364 | return 0; | ||
1389 | 1365 | } | ||
1390 | 1366 | |||
1391 | 1367 | if (runstop == 1 || | ||
1392 | 1368 | (runstop <= 0 && | ||
1393 | 1369 | ( enough(content->array.level, content->array.raid_disks, | ||
1394 | 1370 | content->array.layout, clean, avail) && | ||
1395 | 1371 | (okcnt + rebuilding_cnt >= req_cnt || start_partial_ok) | ||
1396 | 1372 | ))) { | ||
1397 | 1373 | /* This array is good-to-go. | ||
1398 | 1374 | * If a reshape is in progress then we might need to | ||
1399 | 1375 | * continue monitoring it. In that case we start | ||
1400 | 1376 | * it read-only and let the grow code make it writable. | ||
1401 | 1377 | */ | ||
1402 | 1378 | int rv; | ||
1403 | 1379 | #ifndef MDASSEMBLE | ||
1404 | 1380 | if (content->reshape_active && | ||
1405 | 1381 | content->delta_disks <= 0) { | ||
1406 | 1382 | rv = sysfs_set_str(content, NULL, | ||
1407 | 1383 | "array_state", "readonly"); | ||
1408 | 1384 | if (rv == 0) | ||
1409 | 1385 | rv = Grow_continue(mdfd, st, content, | ||
1410 | 1386 | backup_file, | ||
1411 | 1387 | freeze_reshape); | ||
1412 | 1388 | } else | ||
1413 | 1389 | #endif | ||
1414 | 1390 | rv = ioctl(mdfd, RUN_ARRAY, NULL); | ||
1415 | 1391 | if (rv == 0) { | ||
1416 | 1392 | if (verbose >= 0) { | ||
1417 | 1393 | fprintf(stderr, Name ": %s has been started with %d drive%s", | ||
1418 | 1394 | mddev, okcnt, okcnt==1?"":"s"); | ||
1419 | 1395 | if (okcnt < (unsigned)content->array.raid_disks) | ||
1420 | 1396 | fprintf(stderr, " (out of %d)", content->array.raid_disks); | ||
1421 | 1397 | if (rebuilding_cnt) | ||
1422 | 1398 | fprintf(stderr, "%s %d rebuilding", sparecnt?",":" and", rebuilding_cnt); | ||
1423 | 1399 | if (sparecnt) | ||
1424 | 1400 | fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s"); | ||
1425 | 1401 | fprintf(stderr, ".\n"); | ||
1426 | 1402 | } | ||
1427 | 1403 | if (content->reshape_active && | ||
1428 | 1404 | content->array.level >= 4 && | ||
1429 | 1405 | content->array.level <= 6) { | ||
1430 | 1406 | /* might need to increase the size | ||
1431 | 1407 | * of the stripe cache - default is 256 | ||
1432 | 1408 | */ | ||
1433 | 1409 | if (256 < 4 * (content->array.chunk_size/4096)) { | ||
1434 | 1410 | struct mdinfo *sra = sysfs_read(mdfd, 0, 0); | ||
1435 | 1411 | if (sra) | ||
1436 | 1412 | sysfs_set_num(sra, NULL, | ||
1437 | 1413 | "stripe_cache_size", | ||
1438 | 1414 | (4 * content->array.chunk_size / 4096) + 1); | ||
1439 | 1415 | sysfs_free(sra); | ||
1440 | 1416 | } | ||
1441 | 1417 | } | ||
1442 | 1418 | if (okcnt < (unsigned)content->array.raid_disks) { | ||
1443 | 1419 | /* If any devices did not get added | ||
1444 | 1420 | * because the kernel rejected them based | ||
1445 | 1421 | * on event count, try adding them | ||
1446 | 1422 | * again providing the action policy is | ||
1447 | 1423 | * 're-add' or greater. The bitmap | ||
1448 | 1424 | * might allow them to be included, or | ||
1449 | 1425 | * they will become spares. | ||
1450 | 1426 | */ | ||
1451 | 1427 | for (i = 0; i < bestcnt; i++) { | ||
1452 | 1428 | int j = best[i]; | ||
1453 | 1429 | if (j >= 0 && !devices[j].uptodate) { | ||
1454 | 1430 | if (!disk_action_allows(&devices[j].i, st->ss->name, act_re_add)) | ||
1455 | 1431 | continue; | ||
1456 | 1432 | rv = add_disk(mdfd, st, content, | ||
1457 | 1433 | &devices[j].i); | ||
1458 | 1434 | if (rv == 0 && verbose >= 0) | ||
1459 | 1435 | fprintf(stderr, | ||
1460 | 1436 | Name ": %s has been re-added.\n", | ||
1461 | 1437 | devices[j].devname); | ||
1462 | 1438 | } | ||
1463 | 1439 | } | ||
1464 | 1440 | } | ||
1465 | 1441 | wait_for(mddev, mdfd); | ||
1466 | 1442 | close(mdfd); | ||
1467 | 1443 | if (auto_assem) { | ||
1468 | 1444 | int usecs = 1; | ||
1469 | 1445 | /* There is a nasty race with 'mdadm --monitor'. | ||
1470 | 1446 | * If it opens this device before we close it, | ||
1471 | 1447 | * it gets an incomplete open on which IO | ||
1472 | 1448 | * doesn't work and the capacity is | ||
1473 | 1449 | * wrong. | ||
1474 | 1450 | * If we reopen (to check for layered devices) | ||
1475 | 1451 | * before --monitor closes, we loose. | ||
1476 | 1452 | * | ||
1477 | 1453 | * So: wait upto 1 second for there to be | ||
1478 | 1454 | * a non-zero capacity. | ||
1479 | 1455 | */ | ||
1480 | 1456 | while (usecs < 1000) { | ||
1481 | 1457 | mdfd = open(mddev, O_RDONLY); | ||
1482 | 1458 | if (mdfd >= 0) { | ||
1483 | 1459 | unsigned long long size; | ||
1484 | 1460 | if (get_dev_size(mdfd, NULL, &size) && | ||
1485 | 1461 | size > 0) | ||
1486 | 1462 | break; | ||
1487 | 1463 | close(mdfd); | ||
1488 | 1464 | } | ||
1489 | 1465 | usleep(usecs); | ||
1490 | 1466 | usecs <<= 1; | ||
1491 | 1467 | } | ||
1492 | 1468 | } | ||
1493 | 1469 | free(devices); | ||
1494 | 1470 | return 0; | ||
1495 | 1471 | } | ||
1496 | 1472 | fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n", | ||
1497 | 1473 | mddev, strerror(errno)); | ||
1498 | 1474 | |||
1499 | 1475 | if (!enough(content->array.level, content->array.raid_disks, | ||
1500 | 1476 | content->array.layout, 1, avail)) | ||
1501 | 1477 | fprintf(stderr, Name ": Not enough devices to " | ||
1502 | 1478 | "start the array.\n"); | ||
1503 | 1479 | else if (!enough(content->array.level, | ||
1504 | 1480 | content->array.raid_disks, | ||
1505 | 1481 | content->array.layout, clean, | ||
1506 | 1482 | avail)) | ||
1507 | 1483 | fprintf(stderr, Name ": Not enough devices to " | ||
1508 | 1484 | "start the array while not clean " | ||
1509 | 1485 | "- consider --force.\n"); | ||
1510 | 1486 | |||
1511 | 1487 | if (auto_assem) | ||
1512 | 1488 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
1513 | 1489 | close(mdfd); | ||
1514 | 1490 | free(devices); | ||
1515 | 1491 | return 1; | ||
1516 | 1492 | } | ||
1517 | 1493 | if (runstop == -1) { | ||
1518 | 1494 | fprintf(stderr, Name ": %s assembled from %d drive%s", | ||
1519 | 1495 | mddev, okcnt, okcnt==1?"":"s"); | ||
1520 | 1496 | if (okcnt != (unsigned)content->array.raid_disks) | ||
1521 | 1497 | fprintf(stderr, " (out of %d)", content->array.raid_disks); | ||
1522 | 1498 | fprintf(stderr, ", but not started.\n"); | ||
1523 | 1499 | close(mdfd); | ||
1524 | 1500 | free(devices); | ||
1525 | 1501 | return 0; | ||
1526 | 1502 | } | ||
1527 | 1503 | if (verbose >= -1) { | ||
1528 | 1504 | fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s"); | ||
1529 | 1505 | if (rebuilding_cnt) | ||
1530 | 1506 | fprintf(stderr, "%s %d rebuilding", sparecnt?", ":" and ", rebuilding_cnt); | ||
1531 | 1507 | if (sparecnt) | ||
1532 | 1508 | fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s"); | ||
1533 | 1509 | if (!enough(content->array.level, content->array.raid_disks, | ||
1534 | 1510 | content->array.layout, 1, avail)) | ||
1535 | 1511 | fprintf(stderr, " - not enough to start the array.\n"); | ||
1536 | 1512 | else if (!enough(content->array.level, | ||
1537 | 1513 | content->array.raid_disks, | ||
1538 | 1514 | content->array.layout, clean, | ||
1539 | 1515 | avail)) | ||
1540 | 1516 | fprintf(stderr, " - not enough to start the " | ||
1541 | 1517 | "array while not clean - consider " | ||
1542 | 1518 | "--force.\n"); | ||
1543 | 1519 | else { | ||
1544 | 1520 | if (req_cnt == (unsigned)content->array.raid_disks) | ||
1545 | 1521 | fprintf(stderr, " - need all %d to start it", req_cnt); | ||
1546 | 1522 | else | ||
1547 | 1523 | fprintf(stderr, " - need %d of %d to start", req_cnt, content->array.raid_disks); | ||
1548 | 1524 | fprintf(stderr, " (use --run to insist).\n"); | ||
1549 | 1525 | } | ||
1550 | 1526 | } | ||
1551 | 1527 | if (auto_assem) | ||
1552 | 1528 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
1553 | 1529 | close(mdfd); | ||
1554 | 1530 | free(devices); | ||
1555 | 1531 | return 1; | ||
1556 | 1532 | } else { | ||
1557 | 1533 | /* The "chosen_drive" is a good choice, and if necessary, the superblock has | ||
1558 | 1534 | * been updated to point to the current locations of devices. | ||
1559 | 1535 | * so we can just start the array | ||
1560 | 1536 | */ | ||
1561 | 1537 | unsigned long dev; | ||
1562 | 1538 | dev = makedev(devices[chosen_drive].i.disk.major, | ||
1563 | 1539 | devices[chosen_drive].i.disk.minor); | ||
1564 | 1540 | if (ioctl(mdfd, START_ARRAY, dev)) { | ||
1565 | 1541 | fprintf(stderr, Name ": Cannot start array: %s\n", | ||
1566 | 1542 | strerror(errno)); | ||
1567 | 1543 | } | ||
1568 | 1544 | |||
1569 | 1545 | } | ||
1570 | 1546 | close(mdfd); | ||
1571 | 1547 | free(devices); | ||
1572 | 1548 | return 0; | ||
1573 | 1549 | } | ||
1574 | 1550 | |||
1575 | 1551 | #ifndef MDASSEMBLE | ||
1576 | 1552 | int assemble_container_content(struct supertype *st, int mdfd, | ||
1577 | 1553 | struct mdinfo *content, int runstop, | ||
1578 | 1554 | char *chosen_name, int verbose, | ||
1579 | 1555 | char *backup_file, int freeze_reshape) | ||
1580 | 1556 | { | ||
1581 | 1557 | struct mdinfo *dev, *sra; | ||
1582 | 1558 | int working = 0, preexist = 0; | ||
1583 | 1559 | int expansion = 0; | ||
1584 | 1560 | struct map_ent *map = NULL; | ||
1585 | 1561 | int old_raid_disks; | ||
1586 | 1562 | int start_reshape; | ||
1587 | 1563 | |||
1588 | 1564 | sysfs_init(content, mdfd, 0); | ||
1589 | 1565 | |||
1590 | 1566 | sra = sysfs_read(mdfd, 0, GET_VERSION); | ||
1591 | 1567 | if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) | ||
1592 | 1568 | if (sysfs_set_array(content, md_get_version(mdfd)) != 0) { | ||
1593 | 1569 | if (sra) | ||
1594 | 1570 | sysfs_free(sra); | ||
1595 | 1571 | return 1; | ||
1596 | 1572 | } | ||
1597 | 1573 | |||
1598 | 1574 | /* There are two types of reshape: container wide or sub-array specific | ||
1599 | 1575 | * Check if metadata requests blocking container wide reshapes | ||
1600 | 1576 | */ | ||
1601 | 1577 | start_reshape = (content->reshape_active && | ||
1602 | 1578 | !((content->reshape_active == CONTAINER_RESHAPE) && | ||
1603 | 1579 | (content->array.state & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE)))); | ||
1604 | 1580 | |||
1605 | 1581 | /* Block subarray here if it is under reshape now | ||
1606 | 1582 | * Do not allow for any changes in this array | ||
1607 | 1583 | */ | ||
1608 | 1584 | if (st->ss->external && content->recovery_blocked && start_reshape) | ||
1609 | 1585 | block_subarray(content); | ||
1610 | 1586 | |||
1611 | 1587 | if (sra) | ||
1612 | 1588 | sysfs_free(sra); | ||
1613 | 1589 | old_raid_disks = content->array.raid_disks - content->delta_disks; | ||
1614 | 1590 | for (dev = content->devs; dev; dev = dev->next) | ||
1615 | 1591 | if (sysfs_add_disk(content, dev, 1) == 0) { | ||
1616 | 1592 | if (dev->disk.raid_disk >= old_raid_disks && | ||
1617 | 1593 | content->reshape_active) | ||
1618 | 1594 | expansion++; | ||
1619 | 1595 | else | ||
1620 | 1596 | working++; | ||
1621 | 1597 | } else if (errno == EEXIST) | ||
1622 | 1598 | preexist++; | ||
1623 | 1599 | if (working + expansion == 0) | ||
1624 | 1600 | return 1;/* Nothing new, don't try to start */ | ||
1625 | 1601 | |||
1626 | 1602 | map_update(&map, fd2devnum(mdfd), | ||
1627 | 1603 | content->text_version, | ||
1628 | 1604 | content->uuid, chosen_name); | ||
1629 | 1605 | |||
1630 | 1606 | if (runstop > 0 || | ||
1631 | 1607 | (working + preexist + expansion) >= | ||
1632 | 1608 | content->array.working_disks) { | ||
1633 | 1609 | int err; | ||
1634 | 1610 | |||
1635 | 1611 | if (start_reshape) { | ||
1636 | 1612 | int spare = content->array.raid_disks + expansion; | ||
1637 | 1613 | if (restore_backup(st, content, | ||
1638 | 1614 | working, | ||
1639 | 1615 | spare, backup_file, verbose) == 1) | ||
1640 | 1616 | return 1; | ||
1641 | 1617 | |||
1642 | 1618 | err = sysfs_set_str(content, NULL, | ||
1643 | 1619 | "array_state", "readonly"); | ||
1644 | 1620 | if (err) | ||
1645 | 1621 | return 1; | ||
1646 | 1622 | |||
1647 | 1623 | if (st->ss->external) { | ||
1648 | 1624 | if (!mdmon_running(st->container_dev)) | ||
1649 | 1625 | start_mdmon(st->container_dev); | ||
1650 | 1626 | ping_monitor_by_id(st->container_dev); | ||
1651 | 1627 | if (mdmon_running(st->container_dev) && | ||
1652 | 1628 | st->update_tail == NULL) | ||
1653 | 1629 | st->update_tail = &st->updates; | ||
1654 | 1630 | } | ||
1655 | 1631 | |||
1656 | 1632 | err = Grow_continue(mdfd, st, content, backup_file, | ||
1657 | 1633 | freeze_reshape); | ||
1658 | 1634 | } else switch(content->array.level) { | ||
1659 | 1635 | case LEVEL_LINEAR: | ||
1660 | 1636 | case LEVEL_MULTIPATH: | ||
1661 | 1637 | case 0: | ||
1662 | 1638 | err = sysfs_set_str(content, NULL, "array_state", | ||
1663 | 1639 | "active"); | ||
1664 | 1640 | break; | ||
1665 | 1641 | default: | ||
1666 | 1642 | err = sysfs_set_str(content, NULL, "array_state", | ||
1667 | 1643 | "readonly"); | ||
1668 | 1644 | /* start mdmon if needed. */ | ||
1669 | 1645 | if (!err) { | ||
1670 | 1646 | if (!mdmon_running(st->container_dev)) | ||
1671 | 1647 | start_mdmon(st->container_dev); | ||
1672 | 1648 | ping_monitor_by_id(st->container_dev); | ||
1673 | 1649 | } | ||
1674 | 1650 | break; | ||
1675 | 1651 | } | ||
1676 | 1652 | if (!err) | ||
1677 | 1653 | sysfs_set_safemode(content, content->safe_mode_delay); | ||
1678 | 1654 | |||
1679 | 1655 | /* Block subarray here if it is not reshaped now | ||
1680 | 1656 | * It has be blocked a little later to allow mdmon to switch in | ||
1681 | 1657 | * in to R/W state | ||
1682 | 1658 | */ | ||
1683 | 1659 | if (st->ss->external && content->recovery_blocked && | ||
1684 | 1660 | !start_reshape) | ||
1685 | 1661 | block_subarray(content); | ||
1686 | 1662 | |||
1687 | 1663 | if (verbose >= 0) { | ||
1688 | 1664 | if (err) | ||
1689 | 1665 | fprintf(stderr, Name | ||
1690 | 1666 | ": array %s now has %d device%s", | ||
1691 | 1667 | chosen_name, working + preexist, | ||
1692 | 1668 | working + preexist == 1 ? "":"s"); | ||
1693 | 1669 | else | ||
1694 | 1670 | fprintf(stderr, Name | ||
1695 | 1671 | ": Started %s with %d device%s", | ||
1696 | 1672 | chosen_name, working + preexist, | ||
1697 | 1673 | working + preexist == 1 ? "":"s"); | ||
1698 | 1674 | if (preexist) | ||
1699 | 1675 | fprintf(stderr, " (%d new)", working); | ||
1700 | 1676 | if (expansion) | ||
1701 | 1677 | fprintf(stderr, " ( + %d for expansion)", | ||
1702 | 1678 | expansion); | ||
1703 | 1679 | fprintf(stderr, "\n"); | ||
1704 | 1680 | } | ||
1705 | 1681 | if (!err) | ||
1706 | 1682 | wait_for(chosen_name, mdfd); | ||
1707 | 1683 | return err; | ||
1708 | 1684 | /* FIXME should have an O_EXCL and wait for read-auto */ | ||
1709 | 1685 | } else { | ||
1710 | 1686 | if (verbose >= 0) { | ||
1711 | 1687 | fprintf(stderr, Name | ||
1712 | 1688 | ": %s assembled with %d device%s", | ||
1713 | 1689 | chosen_name, preexist + working, | ||
1714 | 1690 | preexist + working == 1 ? "":"s"); | ||
1715 | 1691 | if (preexist) | ||
1716 | 1692 | fprintf(stderr, " (%d new)", working); | ||
1717 | 1693 | fprintf(stderr, " but not started\n"); | ||
1718 | 1694 | } | ||
1719 | 1695 | return 1; | ||
1720 | 1696 | } | ||
1721 | 1697 | } | ||
1722 | 1698 | #endif | ||
1723 | 1699 | |||
1724 | 0 | 1700 | ||
1725 | === removed file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c' | |||
1726 | --- .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c 2012-02-09 16:53:02 +0000 | |||
1727 | +++ .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/Assemble.c 1970-01-01 00:00:00 +0000 | |||
1728 | @@ -1,1650 +0,0 @@ | |||
1729 | 1 | /* | ||
1730 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. | ||
1731 | 3 | * | ||
1732 | 4 | * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de> | ||
1733 | 5 | * | ||
1734 | 6 | * | ||
1735 | 7 | * This program is free software; you can redistribute it and/or modify | ||
1736 | 8 | * it under the terms of the GNU General Public License as published by | ||
1737 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
1738 | 10 | * (at your option) any later version. | ||
1739 | 11 | * | ||
1740 | 12 | * This program is distributed in the hope that it will be useful, | ||
1741 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1742 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1743 | 15 | * GNU General Public License for more details. | ||
1744 | 16 | * | ||
1745 | 17 | * You should have received a copy of the GNU General Public License | ||
1746 | 18 | * along with this program; if not, write to the Free Software | ||
1747 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
1748 | 20 | * | ||
1749 | 21 | * Author: Neil Brown | ||
1750 | 22 | * Email: <neilb@suse.de> | ||
1751 | 23 | */ | ||
1752 | 24 | |||
1753 | 25 | #include "mdadm.h" | ||
1754 | 26 | #include <ctype.h> | ||
1755 | 27 | |||
1756 | 28 | static int name_matches(char *found, char *required, char *homehost) | ||
1757 | 29 | { | ||
1758 | 30 | /* See if the name found matches the required name, possibly | ||
1759 | 31 | * prefixed with 'homehost' | ||
1760 | 32 | */ | ||
1761 | 33 | char fnd[33]; | ||
1762 | 34 | |||
1763 | 35 | strncpy(fnd, found, 32); | ||
1764 | 36 | fnd[32] = 0; | ||
1765 | 37 | if (strcmp(found, required)==0) | ||
1766 | 38 | return 1; | ||
1767 | 39 | if (homehost) { | ||
1768 | 40 | int l = strlen(homehost); | ||
1769 | 41 | if (l < 32 && fnd[l] == ':' && | ||
1770 | 42 | strcmp(fnd+l+1, required)==0) | ||
1771 | 43 | return 1; | ||
1772 | 44 | } | ||
1773 | 45 | return 0; | ||
1774 | 46 | } | ||
1775 | 47 | |||
1776 | 48 | static int is_member_busy(char *metadata_version) | ||
1777 | 49 | { | ||
1778 | 50 | /* check if the given member array is active */ | ||
1779 | 51 | struct mdstat_ent *mdstat = mdstat_read(1, 0); | ||
1780 | 52 | struct mdstat_ent *ent; | ||
1781 | 53 | int busy = 0; | ||
1782 | 54 | |||
1783 | 55 | for (ent = mdstat; ent; ent = ent->next) { | ||
1784 | 56 | if (ent->metadata_version == NULL) | ||
1785 | 57 | continue; | ||
1786 | 58 | if (strncmp(ent->metadata_version, "external:", 9) != 0) | ||
1787 | 59 | continue; | ||
1788 | 60 | if (!is_subarray(&ent->metadata_version[9])) | ||
1789 | 61 | continue; | ||
1790 | 62 | /* Skip first char - it can be '/' or '-' */ | ||
1791 | 63 | if (strcmp(&ent->metadata_version[10], metadata_version+1) == 0) { | ||
1792 | 64 | busy = 1; | ||
1793 | 65 | break; | ||
1794 | 66 | } | ||
1795 | 67 | } | ||
1796 | 68 | free_mdstat(mdstat); | ||
1797 | 69 | |||
1798 | 70 | return busy; | ||
1799 | 71 | } | ||
1800 | 72 | |||
1801 | 73 | static int ident_matches(struct mddev_ident *ident, | ||
1802 | 74 | struct mdinfo *content, | ||
1803 | 75 | struct supertype *tst, | ||
1804 | 76 | char *homehost, | ||
1805 | 77 | char *update, char *devname) | ||
1806 | 78 | { | ||
1807 | 79 | |||
1808 | 80 | if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) && | ||
1809 | 81 | same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0 && | ||
1810 | 82 | memcmp(content->uuid, uuid_zero, sizeof(int[4])) != 0) { | ||
1811 | 83 | if (devname) | ||
1812 | 84 | fprintf(stderr, Name ": %s has wrong uuid.\n", | ||
1813 | 85 | devname); | ||
1814 | 86 | return 0; | ||
1815 | 87 | } | ||
1816 | 88 | if (ident->name[0] && (!update || strcmp(update, "name")!= 0) && | ||
1817 | 89 | name_matches(content->name, ident->name, homehost)==0) { | ||
1818 | 90 | if (devname) | ||
1819 | 91 | fprintf(stderr, Name ": %s has wrong name.\n", | ||
1820 | 92 | devname); | ||
1821 | 93 | return 0; | ||
1822 | 94 | } | ||
1823 | 95 | if (ident->super_minor != UnSet && | ||
1824 | 96 | ident->super_minor != content->array.md_minor) { | ||
1825 | 97 | if (devname) | ||
1826 | 98 | fprintf(stderr, Name ": %s has wrong super-minor.\n", | ||
1827 | 99 | devname); | ||
1828 | 100 | return 0; | ||
1829 | 101 | } | ||
1830 | 102 | if (ident->level != UnSet && | ||
1831 | 103 | ident->level != content->array.level) { | ||
1832 | 104 | if (devname) | ||
1833 | 105 | fprintf(stderr, Name ": %s has wrong raid level.\n", | ||
1834 | 106 | devname); | ||
1835 | 107 | return 0; | ||
1836 | 108 | } | ||
1837 | 109 | if (ident->raid_disks != UnSet && | ||
1838 | 110 | ident->raid_disks!= content->array.raid_disks) { | ||
1839 | 111 | if (devname) | ||
1840 | 112 | fprintf(stderr, Name ": %s requires wrong number of drives.\n", | ||
1841 | 113 | devname); | ||
1842 | 114 | return 0; | ||
1843 | 115 | } | ||
1844 | 116 | if (ident->member && ident->member[0]) { | ||
1845 | 117 | /* content->text_version must match */ | ||
1846 | 118 | char *s = strchr(content->text_version+1, '/'); | ||
1847 | 119 | if (s == NULL) { | ||
1848 | 120 | if (devname) | ||
1849 | 121 | fprintf(stderr, Name ": %s is not a container and one is required.\n", | ||
1850 | 122 | devname); | ||
1851 | 123 | return 0; | ||
1852 | 124 | } else if (strcmp(ident->member, s+1) != 0) { | ||
1853 | 125 | if (devname) | ||
1854 | 126 | fprintf(stderr, Name ": skipping wrong member %s is %s\n", | ||
1855 | 127 | content->text_version, devname); | ||
1856 | 128 | return 0; | ||
1857 | 129 | } | ||
1858 | 130 | } | ||
1859 | 131 | return 1; | ||
1860 | 132 | } | ||
1861 | 133 | |||
1862 | 134 | |||
1863 | 135 | int Assemble(struct supertype *st, char *mddev, | ||
1864 | 136 | struct mddev_ident *ident, | ||
1865 | 137 | struct mddev_dev *devlist, | ||
1866 | 138 | char *backup_file, int invalid_backup, | ||
1867 | 139 | int readonly, int runstop, | ||
1868 | 140 | char *update, char *homehost, int require_homehost, | ||
1869 | 141 | int verbose, int force, int freeze_reshape) | ||
1870 | 142 | { | ||
1871 | 143 | /* | ||
1872 | 144 | * The task of Assemble is to find a collection of | ||
1873 | 145 | * devices that should (according to their superblocks) | ||
1874 | 146 | * form an array, and to give this collection to the MD driver. | ||
1875 | 147 | * In Linux-2.4 and later, this involves submitting a | ||
1876 | 148 | * SET_ARRAY_INFO ioctl with no arg - to prepare | ||
1877 | 149 | * the array - and then submit a number of | ||
1878 | 150 | * ADD_NEW_DISK ioctls to add disks into | ||
1879 | 151 | * the array. Finally RUN_ARRAY might | ||
1880 | 152 | * be submitted to start the array. | ||
1881 | 153 | * | ||
1882 | 154 | * Much of the work of Assemble is in finding and/or | ||
1883 | 155 | * checking the disks to make sure they look right. | ||
1884 | 156 | * | ||
1885 | 157 | * If mddev is not set, then scan must be set and we | ||
1886 | 158 | * read through the config file for dev+uuid mapping | ||
1887 | 159 | * We recurse, setting mddev, for each device that | ||
1888 | 160 | * - isn't running | ||
1889 | 161 | * - has a valid uuid (or any uuid if !uuidset) | ||
1890 | 162 | * | ||
1891 | 163 | * If mddev is set, we try to determine state of md. | ||
1892 | 164 | * check version - must be at least 0.90.0 | ||
1893 | 165 | * check kernel version. must be at least 2.4. | ||
1894 | 166 | * If not, we can possibly fall back on START_ARRAY | ||
1895 | 167 | * Try to GET_ARRAY_INFO. | ||
1896 | 168 | * If possible, give up | ||
1897 | 169 | * If not, try to STOP_ARRAY just to make sure | ||
1898 | 170 | * | ||
1899 | 171 | * If !uuidset and scan, look in conf-file for uuid | ||
1900 | 172 | * If not found, give up | ||
1901 | 173 | * If !devlist and scan and uuidset, get list of devs from conf-file | ||
1902 | 174 | * | ||
1903 | 175 | * For each device: | ||
1904 | 176 | * Check superblock - discard if bad | ||
1905 | 177 | * Check uuid (set if we don't have one) - discard if no match | ||
1906 | 178 | * Check superblock similarity if we have a superblock - discard if different | ||
1907 | 179 | * Record events, devicenum | ||
1908 | 180 | * This should give us a list of devices for the array | ||
1909 | 181 | * We should collect the most recent event number | ||
1910 | 182 | * | ||
1911 | 183 | * Count disks with recent enough event count | ||
1912 | 184 | * While force && !enough disks | ||
1913 | 185 | * Choose newest rejected disks, update event count | ||
1914 | 186 | * mark clean and rewrite superblock | ||
1915 | 187 | * If recent kernel: | ||
1916 | 188 | * SET_ARRAY_INFO | ||
1917 | 189 | * foreach device with recent events : ADD_NEW_DISK | ||
1918 | 190 | * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY | ||
1919 | 191 | * If old kernel: | ||
1920 | 192 | * Check the device numbers in superblock are right | ||
1921 | 193 | * update superblock if any changes | ||
1922 | 194 | * START_ARRAY | ||
1923 | 195 | * | ||
1924 | 196 | */ | ||
1925 | 197 | int mdfd; | ||
1926 | 198 | int clean; | ||
1927 | 199 | int auto_assem = (mddev == NULL && !ident->uuid_set && | ||
1928 | 200 | ident->super_minor == UnSet && ident->name[0] == 0 | ||
1929 | 201 | && (ident->container == NULL || ident->member == NULL)); | ||
1930 | 202 | int old_linux = 0; | ||
1931 | 203 | int vers = vers; /* Keep gcc quite - it really is initialised */ | ||
1932 | 204 | struct { | ||
1933 | 205 | char *devname; | ||
1934 | 206 | int uptodate; /* set once we decide that this device is as | ||
1935 | 207 | * recent as everything else in the array. | ||
1936 | 208 | */ | ||
1937 | 209 | struct mdinfo i; | ||
1938 | 210 | } *devices; | ||
1939 | 211 | char *devmap; | ||
1940 | 212 | int *best = NULL; /* indexed by raid_disk */ | ||
1941 | 213 | int bestcnt = 0; | ||
1942 | 214 | int devcnt = 0; | ||
1943 | 215 | unsigned int okcnt, sparecnt, rebuilding_cnt; | ||
1944 | 216 | unsigned int req_cnt; | ||
1945 | 217 | int i; | ||
1946 | 218 | int most_recent = 0; | ||
1947 | 219 | int chosen_drive; | ||
1948 | 220 | int change = 0; | ||
1949 | 221 | int inargv = 0; | ||
1950 | 222 | int report_missmatch; | ||
1951 | 223 | #ifndef MDASSEMBLE | ||
1952 | 224 | int bitmap_done; | ||
1953 | 225 | #endif | ||
1954 | 226 | int start_partial_ok = (runstop >= 0) && | ||
1955 | 227 | (force || devlist==NULL || auto_assem); | ||
1956 | 228 | unsigned int num_devs; | ||
1957 | 229 | struct mddev_dev *tmpdev; | ||
1958 | 230 | struct mdinfo info; | ||
1959 | 231 | struct mdinfo *content = NULL; | ||
1960 | 232 | char *avail; | ||
1961 | 233 | int nextspare = 0; | ||
1962 | 234 | char *name = NULL; | ||
1963 | 235 | int trustworthy; | ||
1964 | 236 | char chosen_name[1024]; | ||
1965 | 237 | struct domainlist *domains = NULL; | ||
1966 | 238 | |||
1967 | 239 | if (get_linux_version() < 2004000) | ||
1968 | 240 | old_linux = 1; | ||
1969 | 241 | |||
1970 | 242 | /* | ||
1971 | 243 | * If any subdevs are listed, then any that don't | ||
1972 | 244 | * match ident are discarded. Remainder must all match and | ||
1973 | 245 | * become the array. | ||
1974 | 246 | * If no subdevs, then we scan all devices in the config file, but | ||
1975 | 247 | * there must be something in the identity | ||
1976 | 248 | */ | ||
1977 | 249 | |||
1978 | 250 | if (!devlist && | ||
1979 | 251 | ident->uuid_set == 0 && | ||
1980 | 252 | (ident->super_minor < 0 || ident->super_minor == UnSet) && | ||
1981 | 253 | ident->name[0] == 0 && | ||
1982 | 254 | (ident->container == NULL || ident->member == NULL) && | ||
1983 | 255 | ident->devices == NULL) { | ||
1984 | 256 | fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n", | ||
1985 | 257 | mddev ? mddev : "further assembly"); | ||
1986 | 258 | return 1; | ||
1987 | 259 | } | ||
1988 | 260 | |||
1989 | 261 | if (devlist == NULL) | ||
1990 | 262 | devlist = conf_get_devs(); | ||
1991 | 263 | else if (mddev) | ||
1992 | 264 | inargv = 1; | ||
1993 | 265 | |||
1994 | 266 | report_missmatch = ((inargv && verbose >= 0) || verbose > 0); | ||
1995 | 267 | try_again: | ||
1996 | 268 | /* We come back here when doing auto-assembly and attempting some | ||
1997 | 269 | * set of devices failed. Those are now marked as ->used==2 and | ||
1998 | 270 | * we ignore them and try again | ||
1999 | 271 | */ | ||
2000 | 272 | |||
2001 | 273 | tmpdev = devlist; num_devs = 0; | ||
2002 | 274 | while (tmpdev) { | ||
2003 | 275 | if (tmpdev->used) | ||
2004 | 276 | tmpdev->used = 2; | ||
2005 | 277 | else | ||
2006 | 278 | num_devs++; | ||
2007 | 279 | tmpdev = tmpdev->next; | ||
2008 | 280 | } | ||
2009 | 281 | |||
2010 | 282 | if (!st && ident->st) st = ident->st; | ||
2011 | 283 | |||
2012 | 284 | if (verbose>0) | ||
2013 | 285 | fprintf(stderr, Name ": looking for devices for %s\n", | ||
2014 | 286 | mddev ? mddev : "further assembly"); | ||
2015 | 287 | |||
2016 | 288 | /* first walk the list of devices to find a consistent set | ||
2017 | 289 | * that match the criterea, if that is possible. | ||
2018 | 290 | * We flag the ones we like with 'used'. | ||
2019 | 291 | */ | ||
2020 | 292 | for (tmpdev = devlist; | ||
2021 | 293 | tmpdev; | ||
2022 | 294 | tmpdev = tmpdev ? tmpdev->next : NULL) { | ||
2023 | 295 | char *devname = tmpdev->devname; | ||
2024 | 296 | int dfd; | ||
2025 | 297 | struct stat stb; | ||
2026 | 298 | struct supertype *tst; | ||
2027 | 299 | struct dev_policy *pol = NULL; | ||
2028 | 300 | int found_container = 0; | ||
2029 | 301 | |||
2030 | 302 | if (tmpdev->used > 1) continue; | ||
2031 | 303 | |||
2032 | 304 | if (ident->devices && | ||
2033 | 305 | !match_oneof(ident->devices, devname)) { | ||
2034 | 306 | if (report_missmatch) | ||
2035 | 307 | fprintf(stderr, Name ": %s is not one of %s\n", devname, ident->devices); | ||
2036 | 308 | continue; | ||
2037 | 309 | } | ||
2038 | 310 | |||
2039 | 311 | tst = dup_super(st); | ||
2040 | 312 | |||
2041 | 313 | dfd = dev_open(devname, O_RDONLY|O_EXCL); | ||
2042 | 314 | if (dfd < 0) { | ||
2043 | 315 | if (report_missmatch) | ||
2044 | 316 | fprintf(stderr, Name ": cannot open device %s: %s\n", | ||
2045 | 317 | devname, strerror(errno)); | ||
2046 | 318 | tmpdev->used = 2; | ||
2047 | 319 | } else if (fstat(dfd, &stb)< 0) { | ||
2048 | 320 | /* Impossible! */ | ||
2049 | 321 | fprintf(stderr, Name ": fstat failed for %s: %s\n", | ||
2050 | 322 | devname, strerror(errno)); | ||
2051 | 323 | tmpdev->used = 2; | ||
2052 | 324 | } else if ((stb.st_mode & S_IFMT) != S_IFBLK) { | ||
2053 | 325 | fprintf(stderr, Name ": %s is not a block device.\n", | ||
2054 | 326 | devname); | ||
2055 | 327 | tmpdev->used = 2; | ||
2056 | 328 | } else if (must_be_container(dfd)) { | ||
2057 | 329 | if (st) { | ||
2058 | 330 | /* already found some components, this cannot | ||
2059 | 331 | * be another one. | ||
2060 | 332 | */ | ||
2061 | 333 | if (report_missmatch) | ||
2062 | 334 | fprintf(stderr, Name ": %s is a container, but we are looking for components\n", | ||
2063 | 335 | devname); | ||
2064 | 336 | tmpdev->used = 2; | ||
2065 | 337 | #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) | ||
2066 | 338 | } if (!tst && (tst = super_by_fd(dfd, NULL)) == NULL) { | ||
2067 | 339 | if (report_missmatch) | ||
2068 | 340 | fprintf(stderr, Name ": not a recognisable container: %s\n", | ||
2069 | 341 | devname); | ||
2070 | 342 | tmpdev->used = 2; | ||
2071 | 343 | #endif | ||
2072 | 344 | } else if (!tst->ss->load_container | ||
2073 | 345 | || tst->ss->load_container(tst, dfd, NULL)) { | ||
2074 | 346 | if (report_missmatch) | ||
2075 | 347 | fprintf(stderr, Name ": no correct container type: %s\n", | ||
2076 | 348 | devname); | ||
2077 | 349 | tmpdev->used = 2; | ||
2078 | 350 | } else if (auto_assem && | ||
2079 | 351 | !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)), | ||
2080 | 352 | tst->ss->match_home(tst, homehost) == 1)) { | ||
2081 | 353 | if (report_missmatch) | ||
2082 | 354 | fprintf(stderr, Name ": %s has metadata type %s for which " | ||
2083 | 355 | "auto-assembly is disabled\n", | ||
2084 | 356 | devname, tst->ss->name); | ||
2085 | 357 | tmpdev->used = 2; | ||
2086 | 358 | } else | ||
2087 | 359 | found_container = 1; | ||
2088 | 360 | } else { | ||
2089 | 361 | if (!tst && (tst = guess_super(dfd)) == NULL) { | ||
2090 | 362 | if (report_missmatch) | ||
2091 | 363 | fprintf(stderr, Name ": no recogniseable superblock on %s\n", | ||
2092 | 364 | devname); | ||
2093 | 365 | tmpdev->used = 2; | ||
2094 | 366 | } else if (tst->ss->load_super(tst,dfd, NULL)) { | ||
2095 | 367 | if (report_missmatch) | ||
2096 | 368 | fprintf(stderr, Name ": no RAID superblock on %s\n", | ||
2097 | 369 | devname); | ||
2098 | 370 | tmpdev->used = 2; | ||
2099 | 371 | } else if (tst->ss->compare_super == NULL) { | ||
2100 | 372 | if (report_missmatch) | ||
2101 | 373 | fprintf(stderr, Name ": Cannot assemble %s metadata on %s\n", | ||
2102 | 374 | tst->ss->name, devname); | ||
2103 | 375 | tmpdev->used = 2; | ||
2104 | 376 | } else if (auto_assem && st == NULL && | ||
2105 | 377 | !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)), | ||
2106 | 378 | tst->ss->match_home(tst, homehost) == 1)) { | ||
2107 | 379 | if (report_missmatch) | ||
2108 | 380 | fprintf(stderr, Name ": %s has metadata type %s for which " | ||
2109 | 381 | "auto-assembly is disabled\n", | ||
2110 | 382 | devname, tst->ss->name); | ||
2111 | 383 | tmpdev->used = 2; | ||
2112 | 384 | } | ||
2113 | 385 | } | ||
2114 | 386 | if (dfd >= 0) close(dfd); | ||
2115 | 387 | if (tmpdev->used == 2) { | ||
2116 | 388 | if (auto_assem || !inargv) | ||
2117 | 389 | /* Ignore unrecognised devices during auto-assembly */ | ||
2118 | 390 | goto loop; | ||
2119 | 391 | if (ident->uuid_set || ident->name[0] || | ||
2120 | 392 | ident->super_minor != UnSet) | ||
2121 | 393 | /* Ignore unrecognised device if looking for | ||
2122 | 394 | * specific array */ | ||
2123 | 395 | goto loop; | ||
2124 | 396 | |||
2125 | 397 | |||
2126 | 398 | fprintf(stderr, Name ": %s has no superblock - assembly aborted\n", | ||
2127 | 399 | devname); | ||
2128 | 400 | if (st) | ||
2129 | 401 | st->ss->free_super(st); | ||
2130 | 402 | dev_policy_free(pol); | ||
2131 | 403 | domain_free(domains); | ||
2132 | 404 | return 1; | ||
2133 | 405 | } | ||
2134 | 406 | |||
2135 | 407 | if (found_container) { | ||
2136 | 408 | /* tmpdev is a container. We need to be either | ||
2137 | 409 | * looking for a member, or auto-assembling | ||
2138 | 410 | */ | ||
2139 | 411 | |||
2140 | 412 | if (ident->container) { | ||
2141 | 413 | if (ident->container[0] == '/' && | ||
2142 | 414 | !same_dev(ident->container, devname)) { | ||
2143 | 415 | if (report_missmatch) | ||
2144 | 416 | fprintf(stderr, Name ": %s is not the container required (%s)\n", | ||
2145 | 417 | devname, ident->container); | ||
2146 | 418 | goto loop; | ||
2147 | 419 | } | ||
2148 | 420 | if (ident->container[0] != '/') { | ||
2149 | 421 | /* we have a uuid */ | ||
2150 | 422 | int uuid[4]; | ||
2151 | 423 | |||
2152 | 424 | content = &info; | ||
2153 | 425 | tst->ss->getinfo_super(tst, content, NULL); | ||
2154 | 426 | |||
2155 | 427 | if (!parse_uuid(ident->container, uuid) || | ||
2156 | 428 | !same_uuid(content->uuid, uuid, tst->ss->swapuuid)) { | ||
2157 | 429 | if (report_missmatch) | ||
2158 | 430 | fprintf(stderr, Name ": %s has wrong UUID to be required container\n", | ||
2159 | 431 | devname); | ||
2160 | 432 | goto loop; | ||
2161 | 433 | } | ||
2162 | 434 | } | ||
2163 | 435 | } | ||
2164 | 436 | /* It is worth looking inside this container. | ||
2165 | 437 | */ | ||
2166 | 438 | if (verbose > 0) | ||
2167 | 439 | fprintf(stderr, Name ": looking in container %s\n", | ||
2168 | 440 | devname); | ||
2169 | 441 | |||
2170 | 442 | for (content = tst->ss->container_content(tst, NULL); | ||
2171 | 443 | content; | ||
2172 | 444 | content = content->next) { | ||
2173 | 445 | |||
2174 | 446 | if (!ident_matches(ident, content, tst, | ||
2175 | 447 | homehost, update, | ||
2176 | 448 | report_missmatch ? devname : NULL)) | ||
2177 | 449 | /* message already printed */; | ||
2178 | 450 | else if (is_member_busy(content->text_version)) { | ||
2179 | 451 | if (report_missmatch) | ||
2180 | 452 | fprintf(stderr, Name ": member %s in %s is already assembled\n", | ||
2181 | 453 | content->text_version, | ||
2182 | 454 | devname); | ||
2183 | 455 | } else if (content->array.state & (1<<MD_SB_BLOCK_VOLUME)) { | ||
2184 | 456 | /* do not assemble arrays with unsupported configurations */ | ||
2185 | 457 | fprintf(stderr, Name ": Cannot activate member %s in %s.\n", | ||
2186 | 458 | content->text_version, | ||
2187 | 459 | devname); | ||
2188 | 460 | } else | ||
2189 | 461 | break; | ||
2190 | 462 | } | ||
2191 | 463 | if (!content) { | ||
2192 | 464 | tmpdev->used = 2; | ||
2193 | 465 | goto loop; /* empty container */ | ||
2194 | 466 | } | ||
2195 | 467 | |||
2196 | 468 | st = tst; tst = NULL; | ||
2197 | 469 | if (!auto_assem && inargv && tmpdev->next != NULL) { | ||
2198 | 470 | fprintf(stderr, Name ": %s is a container, but is not " | ||
2199 | 471 | "only device given: confused and aborting\n", | ||
2200 | 472 | devname); | ||
2201 | 473 | st->ss->free_super(st); | ||
2202 | 474 | dev_policy_free(pol); | ||
2203 | 475 | domain_free(domains); | ||
2204 | 476 | return 1; | ||
2205 | 477 | } | ||
2206 | 478 | if (verbose > 0) | ||
2207 | 479 | fprintf(stderr, Name ": found match on member %s in %s\n", | ||
2208 | 480 | content->text_version, devname); | ||
2209 | 481 | |||
2210 | 482 | /* make sure we finished the loop */ | ||
2211 | 483 | tmpdev = NULL; | ||
2212 | 484 | goto loop; | ||
2213 | 485 | } else { | ||
2214 | 486 | |||
2215 | 487 | content = &info; | ||
2216 | 488 | tst->ss->getinfo_super(tst, content, NULL); | ||
2217 | 489 | |||
2218 | 490 | if (!ident_matches(ident, content, tst, | ||
2219 | 491 | homehost, update, | ||
2220 | 492 | report_missmatch ? devname : NULL)) | ||
2221 | 493 | goto loop; | ||
2222 | 494 | |||
2223 | 495 | if (st == NULL) | ||
2224 | 496 | st = dup_super(tst); | ||
2225 | 497 | if (st->minor_version == -1) | ||
2226 | 498 | st->minor_version = tst->minor_version; | ||
2227 | 499 | |||
2228 | 500 | if (memcmp(content->uuid, uuid_zero, | ||
2229 | 501 | sizeof(int[4])) == 0) { | ||
2230 | 502 | /* this is a floating spare. It cannot define | ||
2231 | 503 | * an array unless there are no more arrays of | ||
2232 | 504 | * this type to be found. It can be included | ||
2233 | 505 | * in an array of this type though. | ||
2234 | 506 | */ | ||
2235 | 507 | tmpdev->used = 3; | ||
2236 | 508 | goto loop; | ||
2237 | 509 | } | ||
2238 | 510 | |||
2239 | 511 | if (st->ss != tst->ss || | ||
2240 | 512 | st->minor_version != tst->minor_version || | ||
2241 | 513 | st->ss->compare_super(st, tst) != 0) { | ||
2242 | 514 | /* Some mismatch. If exactly one array matches this host, | ||
2243 | 515 | * we can resolve on that one. | ||
2244 | 516 | * Or, if we are auto assembling, we just ignore the second | ||
2245 | 517 | * for now. | ||
2246 | 518 | */ | ||
2247 | 519 | if (auto_assem) | ||
2248 | 520 | goto loop; | ||
2249 | 521 | if (homehost) { | ||
2250 | 522 | int first = st->ss->match_home(st, homehost); | ||
2251 | 523 | int last = tst->ss->match_home(tst, homehost); | ||
2252 | 524 | if (first != last && | ||
2253 | 525 | (first == 1 || last == 1)) { | ||
2254 | 526 | /* We can do something */ | ||
2255 | 527 | if (first) {/* just ignore this one */ | ||
2256 | 528 | if (report_missmatch) | ||
2257 | 529 | fprintf(stderr, Name ": %s misses out due to wrong homehost\n", | ||
2258 | 530 | devname); | ||
2259 | 531 | goto loop; | ||
2260 | 532 | } else { /* reject all those sofar */ | ||
2261 | 533 | struct mddev_dev *td; | ||
2262 | 534 | if (report_missmatch) | ||
2263 | 535 | fprintf(stderr, Name ": %s overrides previous devices due to good homehost\n", | ||
2264 | 536 | devname); | ||
2265 | 537 | for (td=devlist; td != tmpdev; td=td->next) | ||
2266 | 538 | if (td->used == 1) | ||
2267 | 539 | td->used = 0; | ||
2268 | 540 | tmpdev->used = 1; | ||
2269 | 541 | goto loop; | ||
2270 | 542 | } | ||
2271 | 543 | } | ||
2272 | 544 | } | ||
2273 | 545 | fprintf(stderr, Name ": superblock on %s doesn't match others - assembly aborted\n", | ||
2274 | 546 | devname); | ||
2275 | 547 | tst->ss->free_super(tst); | ||
2276 | 548 | st->ss->free_super(st); | ||
2277 | 549 | dev_policy_free(pol); | ||
2278 | 550 | domain_free(domains); | ||
2279 | 551 | return 1; | ||
2280 | 552 | } | ||
2281 | 553 | tmpdev->used = 1; | ||
2282 | 554 | } | ||
2283 | 555 | loop: | ||
2284 | 556 | /* Collect domain information from members only */ | ||
2285 | 557 | if (tmpdev && tmpdev->used == 1) { | ||
2286 | 558 | if (!pol) | ||
2287 | 559 | pol = devnum_policy(stb.st_rdev); | ||
2288 | 560 | domain_merge(&domains, pol, tst?tst->ss->name:NULL); | ||
2289 | 561 | } | ||
2290 | 562 | dev_policy_free(pol); | ||
2291 | 563 | pol = NULL; | ||
2292 | 564 | if (tst) | ||
2293 | 565 | tst->ss->free_super(tst); | ||
2294 | 566 | } | ||
2295 | 567 | |||
2296 | 568 | /* Check if we found some imsm spares but no members */ | ||
2297 | 569 | if ((auto_assem || | ||
2298 | 570 | (ident->uuid_set && | ||
2299 | 571 | memcmp(uuid_zero, ident->uuid,sizeof(uuid_zero)) == 0)) && | ||
2300 | 572 | (!st || !st->sb)) | ||
2301 | 573 | for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) { | ||
2302 | 574 | if (tmpdev->used != 3) | ||
2303 | 575 | continue; | ||
2304 | 576 | tmpdev->used = 1; | ||
2305 | 577 | content = &info; | ||
2306 | 578 | |||
2307 | 579 | if (!st->sb) { | ||
2308 | 580 | /* we need sb from one of the spares */ | ||
2309 | 581 | int dfd = dev_open(tmpdev->devname, O_RDONLY); | ||
2310 | 582 | if (dfd < 0 || | ||
2311 | 583 | st->ss->load_super(st, dfd, NULL)) | ||
2312 | 584 | tmpdev->used = 2; | ||
2313 | 585 | if (dfd > 0) | ||
2314 | 586 | close(dfd); | ||
2315 | 587 | } | ||
2316 | 588 | } | ||
2317 | 589 | |||
2318 | 590 | /* Now reject spares that don't match domains of identified members */ | ||
2319 | 591 | for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) { | ||
2320 | 592 | struct stat stb; | ||
2321 | 593 | if (tmpdev->used != 3) | ||
2322 | 594 | continue; | ||
2323 | 595 | if (stat(tmpdev->devname, &stb)< 0) { | ||
2324 | 596 | fprintf(stderr, Name ": fstat failed for %s: %s\n", | ||
2325 | 597 | tmpdev->devname, strerror(errno)); | ||
2326 | 598 | tmpdev->used = 2; | ||
2327 | 599 | } else { | ||
2328 | 600 | struct dev_policy *pol = devnum_policy(stb.st_rdev); | ||
2329 | 601 | int dt = domain_test(domains, pol, NULL); | ||
2330 | 602 | if (inargv && dt != 0) | ||
2331 | 603 | /* take this spare as domains match | ||
2332 | 604 | * if there are any */ | ||
2333 | 605 | tmpdev->used = 1; | ||
2334 | 606 | else if (!inargv && dt == 1) | ||
2335 | 607 | /* device wasn't explicitly listed, so need | ||
2336 | 608 | * explicit domain match - which we have */ | ||
2337 | 609 | tmpdev->used = 1; | ||
2338 | 610 | else | ||
2339 | 611 | /* if domains don't match mark as unused */ | ||
2340 | 612 | tmpdev->used = 0; | ||
2341 | 613 | dev_policy_free(pol); | ||
2342 | 614 | } | ||
2343 | 615 | } | ||
2344 | 616 | domain_free(domains); | ||
2345 | 617 | |||
2346 | 618 | if (!st || !st->sb || !content) | ||
2347 | 619 | return 2; | ||
2348 | 620 | |||
2349 | 621 | /* Now need to open the array device. Use create_mddev */ | ||
2350 | 622 | if (content == &info) | ||
2351 | 623 | st->ss->getinfo_super(st, content, NULL); | ||
2352 | 624 | |||
2353 | 625 | trustworthy = FOREIGN; | ||
2354 | 626 | name = content->name; | ||
2355 | 627 | switch (st->ss->match_home(st, homehost) | ||
2356 | 628 | ?: st->ss->match_home(st, "any")) { | ||
2357 | 629 | case 1: | ||
2358 | 630 | trustworthy = LOCAL; | ||
2359 | 631 | name = strchr(content->name, ':'); | ||
2360 | 632 | if (name) | ||
2361 | 633 | name++; | ||
2362 | 634 | else | ||
2363 | 635 | name = content->name; | ||
2364 | 636 | break; | ||
2365 | 637 | } | ||
2366 | 638 | if (!auto_assem) | ||
2367 | 639 | /* If the array is listed in mdadm.conf or on | ||
2368 | 640 | * command line, then we trust the name | ||
2369 | 641 | * even if the array doesn't look local | ||
2370 | 642 | */ | ||
2371 | 643 | trustworthy = LOCAL; | ||
2372 | 644 | |||
2373 | 645 | if (name[0] == 0 && | ||
2374 | 646 | content->array.level == LEVEL_CONTAINER) { | ||
2375 | 647 | name = content->text_version; | ||
2376 | 648 | trustworthy = METADATA; | ||
2377 | 649 | } | ||
2378 | 650 | |||
2379 | 651 | if (name[0] && trustworthy != LOCAL && | ||
2380 | 652 | ! require_homehost && | ||
2381 | 653 | conf_name_is_free(name)) | ||
2382 | 654 | trustworthy = LOCAL; | ||
2383 | 655 | |||
2384 | 656 | if (trustworthy == LOCAL && | ||
2385 | 657 | strchr(name, ':')) | ||
2386 | 658 | /* Ignore 'host:' prefix of name */ | ||
2387 | 659 | name = strchr(name, ':')+1; | ||
2388 | 660 | |||
2389 | 661 | mdfd = create_mddev(mddev, name, ident->autof, trustworthy, | ||
2390 | 662 | chosen_name); | ||
2391 | 663 | if (mdfd < 0) { | ||
2392 | 664 | st->ss->free_super(st); | ||
2393 | 665 | if (auto_assem) | ||
2394 | 666 | goto try_again; | ||
2395 | 667 | return 1; | ||
2396 | 668 | } | ||
2397 | 669 | mddev = chosen_name; | ||
2398 | 670 | vers = md_get_version(mdfd); | ||
2399 | 671 | if (vers < 9000) { | ||
2400 | 672 | fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n" | ||
2401 | 673 | " Upgrade your kernel or try --build\n"); | ||
2402 | 674 | close(mdfd); | ||
2403 | 675 | return 1; | ||
2404 | 676 | } | ||
2405 | 677 | if (mddev_busy(fd2devnum(mdfd))) { | ||
2406 | 678 | fprintf(stderr, Name ": %s already active, cannot restart it!\n", | ||
2407 | 679 | mddev); | ||
2408 | 680 | for (tmpdev = devlist ; | ||
2409 | 681 | tmpdev && tmpdev->used != 1; | ||
2410 | 682 | tmpdev = tmpdev->next) | ||
2411 | 683 | ; | ||
2412 | 684 | if (tmpdev && auto_assem) | ||
2413 | 685 | fprintf(stderr, Name ": %s needed for %s...\n", | ||
2414 | 686 | mddev, tmpdev->devname); | ||
2415 | 687 | close(mdfd); | ||
2416 | 688 | mdfd = -3; | ||
2417 | 689 | st->ss->free_super(st); | ||
2418 | 690 | if (auto_assem) | ||
2419 | 691 | goto try_again; | ||
2420 | 692 | return 1; | ||
2421 | 693 | } | ||
2422 | 694 | ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */ | ||
2423 | 695 | |||
2424 | 696 | #ifndef MDASSEMBLE | ||
2425 | 697 | if (content != &info) { | ||
2426 | 698 | /* This is a member of a container. Try starting the array. */ | ||
2427 | 699 | int err; | ||
2428 | 700 | err = assemble_container_content(st, mdfd, content, runstop, | ||
2429 | 701 | chosen_name, verbose, | ||
2430 | 702 | backup_file, freeze_reshape); | ||
2431 | 703 | close(mdfd); | ||
2432 | 704 | return err; | ||
2433 | 705 | } | ||
2434 | 706 | bitmap_done = 0; | ||
2435 | 707 | #endif | ||
2436 | 708 | /* Ok, no bad inconsistancy, we can try updating etc */ | ||
2437 | 709 | devices = malloc(num_devs * sizeof(*devices)); | ||
2438 | 710 | devmap = calloc(num_devs * content->array.raid_disks, 1); | ||
2439 | 711 | for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used == 1) { | ||
2440 | 712 | char *devname = tmpdev->devname; | ||
2441 | 713 | struct stat stb; | ||
2442 | 714 | /* looks like a good enough match to update the super block if needed */ | ||
2443 | 715 | #ifndef MDASSEMBLE | ||
2444 | 716 | if (update) { | ||
2445 | 717 | int dfd; | ||
2446 | 718 | /* prepare useful information in info structures */ | ||
2447 | 719 | struct stat stb2; | ||
2448 | 720 | struct supertype *tst; | ||
2449 | 721 | int err; | ||
2450 | 722 | fstat(mdfd, &stb2); | ||
2451 | 723 | |||
2452 | 724 | if (strcmp(update, "uuid")==0 && | ||
2453 | 725 | !ident->uuid_set) { | ||
2454 | 726 | int rfd; | ||
2455 | 727 | if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || | ||
2456 | 728 | read(rfd, ident->uuid, 16) != 16) { | ||
2457 | 729 | *(__u32*)(ident->uuid) = random(); | ||
2458 | 730 | *(__u32*)(ident->uuid+1) = random(); | ||
2459 | 731 | *(__u32*)(ident->uuid+2) = random(); | ||
2460 | 732 | *(__u32*)(ident->uuid+3) = random(); | ||
2461 | 733 | } | ||
2462 | 734 | if (rfd >= 0) close(rfd); | ||
2463 | 735 | } | ||
2464 | 736 | dfd = dev_open(devname, O_RDWR|O_EXCL); | ||
2465 | 737 | |||
2466 | 738 | tst = dup_super(st); | ||
2467 | 739 | if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { | ||
2468 | 740 | fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n", | ||
2469 | 741 | devname); | ||
2470 | 742 | if (dfd >= 0) | ||
2471 | 743 | close(dfd); | ||
2472 | 744 | close(mdfd); | ||
2473 | 745 | free(devices); | ||
2474 | 746 | free(devmap); | ||
2475 | 747 | return 1; | ||
2476 | 748 | } | ||
2477 | 749 | tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks); | ||
2478 | 750 | |||
2479 | 751 | memcpy(content->uuid, ident->uuid, 16); | ||
2480 | 752 | strcpy(content->name, ident->name); | ||
2481 | 753 | content->array.md_minor = minor(stb2.st_rdev); | ||
2482 | 754 | |||
2483 | 755 | if (strcmp(update, "byteorder") == 0) | ||
2484 | 756 | err = 0; | ||
2485 | 757 | else | ||
2486 | 758 | err = tst->ss->update_super(tst, content, update, | ||
2487 | 759 | devname, verbose, | ||
2488 | 760 | ident->uuid_set, | ||
2489 | 761 | homehost); | ||
2490 | 762 | if (err < 0) { | ||
2491 | 763 | fprintf(stderr, | ||
2492 | 764 | Name ": --update=%s not understood" | ||
2493 | 765 | " for %s metadata\n", | ||
2494 | 766 | update, tst->ss->name); | ||
2495 | 767 | tst->ss->free_super(tst); | ||
2496 | 768 | free(tst); | ||
2497 | 769 | close(mdfd); | ||
2498 | 770 | close(dfd); | ||
2499 | 771 | free(devices); | ||
2500 | 772 | free(devmap); | ||
2501 | 773 | return 1; | ||
2502 | 774 | } | ||
2503 | 775 | if (strcmp(update, "uuid")==0 && | ||
2504 | 776 | !ident->uuid_set) { | ||
2505 | 777 | ident->uuid_set = 1; | ||
2506 | 778 | memcpy(ident->uuid, content->uuid, 16); | ||
2507 | 779 | } | ||
2508 | 780 | if (tst->ss->store_super(tst, dfd)) | ||
2509 | 781 | fprintf(stderr, Name ": Could not re-write superblock on %s.\n", | ||
2510 | 782 | devname); | ||
2511 | 783 | close(dfd); | ||
2512 | 784 | |||
2513 | 785 | if (strcmp(update, "uuid")==0 && | ||
2514 | 786 | ident->bitmap_fd >= 0 && !bitmap_done) { | ||
2515 | 787 | if (bitmap_update_uuid(ident->bitmap_fd, | ||
2516 | 788 | content->uuid, | ||
2517 | 789 | tst->ss->swapuuid) != 0) | ||
2518 | 790 | fprintf(stderr, Name ": Could not update uuid on external bitmap.\n"); | ||
2519 | 791 | else | ||
2520 | 792 | bitmap_done = 1; | ||
2521 | 793 | } | ||
2522 | 794 | tst->ss->free_super(tst); | ||
2523 | 795 | } else | ||
2524 | 796 | #endif | ||
2525 | 797 | { | ||
2526 | 798 | struct supertype *tst = dup_super(st); | ||
2527 | 799 | int dfd; | ||
2528 | 800 | dfd = dev_open(devname, O_RDWR|O_EXCL); | ||
2529 | 801 | |||
2530 | 802 | if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { | ||
2531 | 803 | fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n", | ||
2532 | 804 | devname); | ||
2533 | 805 | if (dfd >= 0) | ||
2534 | 806 | close(dfd); | ||
2535 | 807 | close(mdfd); | ||
2536 | 808 | free(devices); | ||
2537 | 809 | free(devmap); | ||
2538 | 810 | return 1; | ||
2539 | 811 | } | ||
2540 | 812 | tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks); | ||
2541 | 813 | tst->ss->free_super(tst); | ||
2542 | 814 | close(dfd); | ||
2543 | 815 | } | ||
2544 | 816 | |||
2545 | 817 | stat(devname, &stb); | ||
2546 | 818 | |||
2547 | 819 | if (verbose > 0) | ||
2548 | 820 | fprintf(stderr, Name ": %s is identified as a member of %s, slot %d.\n", | ||
2549 | 821 | devname, mddev, content->disk.raid_disk); | ||
2550 | 822 | devices[devcnt].devname = devname; | ||
2551 | 823 | devices[devcnt].uptodate = 0; | ||
2552 | 824 | devices[devcnt].i = *content; | ||
2553 | 825 | devices[devcnt].i.disk.major = major(stb.st_rdev); | ||
2554 | 826 | devices[devcnt].i.disk.minor = minor(stb.st_rdev); | ||
2555 | 827 | if (most_recent < devcnt) { | ||
2556 | 828 | if (devices[devcnt].i.events | ||
2557 | 829 | > devices[most_recent].i.events) | ||
2558 | 830 | most_recent = devcnt; | ||
2559 | 831 | } | ||
2560 | 832 | if (content->array.level == LEVEL_MULTIPATH) | ||
2561 | 833 | /* with multipath, the raid_disk from the superblock is meaningless */ | ||
2562 | 834 | i = devcnt; | ||
2563 | 835 | else | ||
2564 | 836 | i = devices[devcnt].i.disk.raid_disk; | ||
2565 | 837 | if (i+1 == 0) { | ||
2566 | 838 | if (nextspare < content->array.raid_disks) | ||
2567 | 839 | nextspare = content->array.raid_disks; | ||
2568 | 840 | i = nextspare++; | ||
2569 | 841 | } else { | ||
2570 | 842 | if (i >= content->array.raid_disks && | ||
2571 | 843 | i >= nextspare) | ||
2572 | 844 | nextspare = i+1; | ||
2573 | 845 | } | ||
2574 | 846 | if (i < 10000) { | ||
2575 | 847 | if (i >= bestcnt) { | ||
2576 | 848 | int newbestcnt = i+10; | ||
2577 | 849 | int *newbest = malloc(sizeof(int)*newbestcnt); | ||
2578 | 850 | int c; | ||
2579 | 851 | for (c=0; c < newbestcnt; c++) | ||
2580 | 852 | if (c < bestcnt) | ||
2581 | 853 | newbest[c] = best[c]; | ||
2582 | 854 | else | ||
2583 | 855 | newbest[c] = -1; | ||
2584 | 856 | if (best)free(best); | ||
2585 | 857 | best = newbest; | ||
2586 | 858 | bestcnt = newbestcnt; | ||
2587 | 859 | } | ||
2588 | 860 | if (best[i] >=0 && | ||
2589 | 861 | devices[best[i]].i.events | ||
2590 | 862 | == devices[devcnt].i.events | ||
2591 | 863 | && (devices[best[i]].i.disk.minor | ||
2592 | 864 | != devices[devcnt].i.disk.minor) | ||
2593 | 865 | && st->ss == &super0 | ||
2594 | 866 | && content->array.level != LEVEL_MULTIPATH) { | ||
2595 | 867 | /* two different devices with identical superblock. | ||
2596 | 868 | * Could be a mis-detection caused by overlapping | ||
2597 | 869 | * partitions. fail-safe. | ||
2598 | 870 | */ | ||
2599 | 871 | fprintf(stderr, Name ": WARNING %s and %s appear" | ||
2600 | 872 | " to have very similar superblocks.\n" | ||
2601 | 873 | " If they are really different, " | ||
2602 | 874 | "please --zero the superblock on one\n" | ||
2603 | 875 | " If they are the same or overlap," | ||
2604 | 876 | " please remove one from %s.\n", | ||
2605 | 877 | devices[best[i]].devname, devname, | ||
2606 | 878 | inargv ? "the list" : | ||
2607 | 879 | "the\n DEVICE list in mdadm.conf" | ||
2608 | 880 | ); | ||
2609 | 881 | close(mdfd); | ||
2610 | 882 | free(devices); | ||
2611 | 883 | free(devmap); | ||
2612 | 884 | return 1; | ||
2613 | 885 | } | ||
2614 | 886 | if (best[i] == -1 | ||
2615 | 887 | || (devices[best[i]].i.events | ||
2616 | 888 | < devices[devcnt].i.events)) | ||
2617 | 889 | best[i] = devcnt; | ||
2618 | 890 | } | ||
2619 | 891 | devcnt++; | ||
2620 | 892 | } | ||
2621 | 893 | |||
2622 | 894 | if (devcnt == 0) { | ||
2623 | 895 | fprintf(stderr, Name ": no devices found for %s\n", | ||
2624 | 896 | mddev); | ||
2625 | 897 | if (st) | ||
2626 | 898 | st->ss->free_super(st); | ||
2627 | 899 | close(mdfd); | ||
2628 | 900 | free(devices); | ||
2629 | 901 | free(devmap); | ||
2630 | 902 | return 1; | ||
2631 | 903 | } | ||
2632 | 904 | |||
2633 | 905 | if (update && strcmp(update, "byteorder")==0) | ||
2634 | 906 | st->minor_version = 90; | ||
2635 | 907 | |||
2636 | 908 | st->ss->getinfo_super(st, content, NULL); | ||
2637 | 909 | clean = content->array.state & 1; | ||
2638 | 910 | |||
2639 | 911 | /* now we have some devices that might be suitable. | ||
2640 | 912 | * I wonder how many | ||
2641 | 913 | */ | ||
2642 | 914 | avail = malloc(content->array.raid_disks); | ||
2643 | 915 | memset(avail, 0, content->array.raid_disks); | ||
2644 | 916 | okcnt = 0; | ||
2645 | 917 | sparecnt=0; | ||
2646 | 918 | rebuilding_cnt=0; | ||
2647 | 919 | for (i=0; i< bestcnt; i++) { | ||
2648 | 920 | int j = best[i]; | ||
2649 | 921 | int event_margin = 1; /* always allow a difference of '1' | ||
2650 | 922 | * like the kernel does | ||
2651 | 923 | */ | ||
2652 | 924 | if (j < 0) continue; | ||
2653 | 925 | /* note: we ignore error flags in multipath arrays | ||
2654 | 926 | * as they don't make sense | ||
2655 | 927 | */ | ||
2656 | 928 | if (content->array.level != LEVEL_MULTIPATH) | ||
2657 | 929 | if (!(devices[j].i.disk.state & (1<<MD_DISK_ACTIVE))) { | ||
2658 | 930 | if (!(devices[j].i.disk.state | ||
2659 | 931 | & (1<<MD_DISK_FAULTY))) { | ||
2660 | 932 | devices[j].uptodate = 1; | ||
2661 | 933 | sparecnt++; | ||
2662 | 934 | } | ||
2663 | 935 | continue; | ||
2664 | 936 | } | ||
2665 | 937 | /* If this devices thinks that 'most_recent' has failed, then | ||
2666 | 938 | * we must reject this device. | ||
2667 | 939 | */ | ||
2668 | 940 | if (j != most_recent && | ||
2669 | 941 | content->array.raid_disks > 0 && | ||
2670 | 942 | devices[most_recent].i.disk.raid_disk >= 0 && | ||
2671 | 943 | devmap[j * content->array.raid_disks + devices[most_recent].i.disk.raid_disk] == 0) { | ||
2672 | 944 | if (verbose > -1) | ||
2673 | 945 | fprintf(stderr, Name ": ignoring %s as it reports %s as failed\n", | ||
2674 | 946 | devices[j].devname, devices[most_recent].devname); | ||
2675 | 947 | best[i] = -1; | ||
2676 | 948 | continue; | ||
2677 | 949 | } | ||
2678 | 950 | if (devices[j].i.events+event_margin >= | ||
2679 | 951 | devices[most_recent].i.events) { | ||
2680 | 952 | devices[j].uptodate = 1; | ||
2681 | 953 | if (i < content->array.raid_disks) { | ||
2682 | 954 | if (devices[j].i.recovery_start == MaxSector || | ||
2683 | 955 | (content->reshape_active && | ||
2684 | 956 | j >= content->array.raid_disks - content->delta_disks)) { | ||
2685 | 957 | okcnt++; | ||
2686 | 958 | avail[i]=1; | ||
2687 | 959 | } else | ||
2688 | 960 | rebuilding_cnt++; | ||
2689 | 961 | } else | ||
2690 | 962 | sparecnt++; | ||
2691 | 963 | } | ||
2692 | 964 | } | ||
2693 | 965 | free(devmap); | ||
2694 | 966 | while (force && !enough(content->array.level, content->array.raid_disks, | ||
2695 | 967 | content->array.layout, 1, | ||
2696 | 968 | avail, okcnt)) { | ||
2697 | 969 | /* Choose the newest best drive which is | ||
2698 | 970 | * not up-to-date, update the superblock | ||
2699 | 971 | * and add it. | ||
2700 | 972 | */ | ||
2701 | 973 | int fd; | ||
2702 | 974 | struct supertype *tst; | ||
2703 | 975 | unsigned long long current_events; | ||
2704 | 976 | chosen_drive = -1; | ||
2705 | 977 | for (i = 0; i < content->array.raid_disks && i < bestcnt; i++) { | ||
2706 | 978 | int j = best[i]; | ||
2707 | 979 | if (j>=0 && | ||
2708 | 980 | !devices[j].uptodate && | ||
2709 | 981 | devices[j].i.recovery_start == MaxSector && | ||
2710 | 982 | (chosen_drive < 0 || | ||
2711 | 983 | devices[j].i.events | ||
2712 | 984 | > devices[chosen_drive].i.events)) | ||
2713 | 985 | chosen_drive = j; | ||
2714 | 986 | } | ||
2715 | 987 | if (chosen_drive < 0) | ||
2716 | 988 | break; | ||
2717 | 989 | current_events = devices[chosen_drive].i.events; | ||
2718 | 990 | add_another: | ||
2719 | 991 | if (verbose >= 0) | ||
2720 | 992 | fprintf(stderr, Name ": forcing event count in %s(%d) from %d upto %d\n", | ||
2721 | 993 | devices[chosen_drive].devname, | ||
2722 | 994 | devices[chosen_drive].i.disk.raid_disk, | ||
2723 | 995 | (int)(devices[chosen_drive].i.events), | ||
2724 | 996 | (int)(devices[most_recent].i.events)); | ||
2725 | 997 | fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL); | ||
2726 | 998 | if (fd < 0) { | ||
2727 | 999 | fprintf(stderr, Name ": Couldn't open %s for write - not updating\n", | ||
2728 | 1000 | devices[chosen_drive].devname); | ||
2729 | 1001 | devices[chosen_drive].i.events = 0; | ||
2730 | 1002 | continue; | ||
2731 | 1003 | } | ||
2732 | 1004 | tst = dup_super(st); | ||
2733 | 1005 | if (tst->ss->load_super(tst,fd, NULL)) { | ||
2734 | 1006 | close(fd); | ||
2735 | 1007 | fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n", | ||
2736 | 1008 | devices[chosen_drive].devname); | ||
2737 | 1009 | devices[chosen_drive].i.events = 0; | ||
2738 | 1010 | continue; | ||
2739 | 1011 | } | ||
2740 | 1012 | content->events = devices[most_recent].i.events; | ||
2741 | 1013 | tst->ss->update_super(tst, content, "force-one", | ||
2742 | 1014 | devices[chosen_drive].devname, verbose, | ||
2743 | 1015 | 0, NULL); | ||
2744 | 1016 | |||
2745 | 1017 | if (tst->ss->store_super(tst, fd)) { | ||
2746 | 1018 | close(fd); | ||
2747 | 1019 | fprintf(stderr, Name ": Could not re-write superblock on %s\n", | ||
2748 | 1020 | devices[chosen_drive].devname); | ||
2749 | 1021 | devices[chosen_drive].i.events = 0; | ||
2750 | 1022 | tst->ss->free_super(tst); | ||
2751 | 1023 | continue; | ||
2752 | 1024 | } | ||
2753 | 1025 | close(fd); | ||
2754 | 1026 | devices[chosen_drive].i.events = devices[most_recent].i.events; | ||
2755 | 1027 | devices[chosen_drive].uptodate = 1; | ||
2756 | 1028 | avail[chosen_drive] = 1; | ||
2757 | 1029 | okcnt++; | ||
2758 | 1030 | tst->ss->free_super(tst); | ||
2759 | 1031 | |||
2760 | 1032 | /* If there are any other drives of the same vintage, | ||
2761 | 1033 | * add them in as well. We can't lose and we might gain | ||
2762 | 1034 | */ | ||
2763 | 1035 | for (i = 0; i < content->array.raid_disks && i < bestcnt ; i++) { | ||
2764 | 1036 | int j = best[i]; | ||
2765 | 1037 | if (j >= 0 && | ||
2766 | 1038 | !devices[j].uptodate && | ||
2767 | 1039 | devices[j].i.events == current_events) { | ||
2768 | 1040 | chosen_drive = j; | ||
2769 | 1041 | goto add_another; | ||
2770 | 1042 | } | ||
2771 | 1043 | } | ||
2772 | 1044 | } | ||
2773 | 1045 | |||
2774 | 1046 | /* Now we want to look at the superblock which the kernel will base things on | ||
2775 | 1047 | * and compare the devices that we think are working with the devices that the | ||
2776 | 1048 | * superblock thinks are working. | ||
2777 | 1049 | * If there are differences and --force is given, then update this chosen | ||
2778 | 1050 | * superblock. | ||
2779 | 1051 | */ | ||
2780 | 1052 | chosen_drive = -1; | ||
2781 | 1053 | st->ss->free_super(st); | ||
2782 | 1054 | for (i=0; chosen_drive < 0 && i<bestcnt; i++) { | ||
2783 | 1055 | int j = best[i]; | ||
2784 | 1056 | int fd; | ||
2785 | 1057 | |||
2786 | 1058 | if (j<0) | ||
2787 | 1059 | continue; | ||
2788 | 1060 | if (!devices[j].uptodate) | ||
2789 | 1061 | continue; | ||
2790 | 1062 | if (devices[j].i.events < devices[most_recent].i.events) | ||
2791 | 1063 | continue; | ||
2792 | 1064 | chosen_drive = j; | ||
2793 | 1065 | if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) { | ||
2794 | 1066 | fprintf(stderr, Name ": Cannot open %s: %s\n", | ||
2795 | 1067 | devices[j].devname, strerror(errno)); | ||
2796 | 1068 | close(mdfd); | ||
2797 | 1069 | free(devices); | ||
2798 | 1070 | return 1; | ||
2799 | 1071 | } | ||
2800 | 1072 | if (st->ss->load_super(st,fd, NULL)) { | ||
2801 | 1073 | close(fd); | ||
2802 | 1074 | fprintf(stderr, Name ": RAID superblock has disappeared from %s\n", | ||
2803 | 1075 | devices[j].devname); | ||
2804 | 1076 | close(mdfd); | ||
2805 | 1077 | free(devices); | ||
2806 | 1078 | return 1; | ||
2807 | 1079 | } | ||
2808 | 1080 | close(fd); | ||
2809 | 1081 | } | ||
2810 | 1082 | if (st->sb == NULL) { | ||
2811 | 1083 | fprintf(stderr, Name ": No suitable drives found for %s\n", mddev); | ||
2812 | 1084 | close(mdfd); | ||
2813 | 1085 | free(devices); | ||
2814 | 1086 | return 1; | ||
2815 | 1087 | } | ||
2816 | 1088 | st->ss->getinfo_super(st, content, NULL); | ||
2817 | 1089 | #ifndef MDASSEMBLE | ||
2818 | 1090 | sysfs_init(content, mdfd, 0); | ||
2819 | 1091 | #endif | ||
2820 | 1092 | for (i=0; i<bestcnt; i++) { | ||
2821 | 1093 | int j = best[i]; | ||
2822 | 1094 | unsigned int desired_state; | ||
2823 | 1095 | |||
2824 | 1096 | if (i < content->array.raid_disks) | ||
2825 | 1097 | desired_state = (1<<MD_DISK_ACTIVE) | (1<<MD_DISK_SYNC); | ||
2826 | 1098 | else | ||
2827 | 1099 | desired_state = 0; | ||
2828 | 1100 | |||
2829 | 1101 | if (j<0) | ||
2830 | 1102 | continue; | ||
2831 | 1103 | if (!devices[j].uptodate) | ||
2832 | 1104 | continue; | ||
2833 | 1105 | |||
2834 | 1106 | devices[j].i.disk.state = desired_state; | ||
2835 | 1107 | if (!(devices[j].i.array.state & 1)) | ||
2836 | 1108 | clean = 0; | ||
2837 | 1109 | |||
2838 | 1110 | if (st->ss->update_super(st, &devices[j].i, "assemble", NULL, | ||
2839 | 1111 | verbose, 0, NULL)) { | ||
2840 | 1112 | if (force) { | ||
2841 | 1113 | if (verbose >= 0) | ||
2842 | 1114 | fprintf(stderr, Name ": " | ||
2843 | 1115 | "clearing FAULTY flag for device %d in %s for %s\n", | ||
2844 | 1116 | j, mddev, devices[j].devname); | ||
2845 | 1117 | change = 1; | ||
2846 | 1118 | } else { | ||
2847 | 1119 | if (verbose >= -1) | ||
2848 | 1120 | fprintf(stderr, Name ": " | ||
2849 | 1121 | "device %d in %s has wrong state in superblock, but %s seems ok\n", | ||
2850 | 1122 | i, mddev, devices[j].devname); | ||
2851 | 1123 | } | ||
2852 | 1124 | } | ||
2853 | 1125 | #if 0 | ||
2854 | 1126 | if (!(super.disks[i].i.disk.state & (1 << MD_DISK_FAULTY))) { | ||
2855 | 1127 | fprintf(stderr, Name ": devices %d of %s is not marked FAULTY in superblock, but cannot be found\n", | ||
2856 | 1128 | i, mddev); | ||
2857 | 1129 | } | ||
2858 | 1130 | #endif | ||
2859 | 1131 | } | ||
2860 | 1132 | if (force && !clean && | ||
2861 | 1133 | !enough(content->array.level, content->array.raid_disks, | ||
2862 | 1134 | content->array.layout, clean, | ||
2863 | 1135 | avail, okcnt)) { | ||
2864 | 1136 | change += st->ss->update_super(st, content, "force-array", | ||
2865 | 1137 | devices[chosen_drive].devname, verbose, | ||
2866 | 1138 | 0, NULL); | ||
2867 | 1139 | clean = 1; | ||
2868 | 1140 | } | ||
2869 | 1141 | |||
2870 | 1142 | if (change) { | ||
2871 | 1143 | int fd; | ||
2872 | 1144 | fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL); | ||
2873 | 1145 | if (fd < 0) { | ||
2874 | 1146 | fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n", | ||
2875 | 1147 | devices[chosen_drive].devname); | ||
2876 | 1148 | close(mdfd); | ||
2877 | 1149 | free(devices); | ||
2878 | 1150 | return 1; | ||
2879 | 1151 | } | ||
2880 | 1152 | if (st->ss->store_super(st, fd)) { | ||
2881 | 1153 | close(fd); | ||
2882 | 1154 | fprintf(stderr, Name ": Could not re-write superblock on %s\n", | ||
2883 | 1155 | devices[chosen_drive].devname); | ||
2884 | 1156 | close(mdfd); | ||
2885 | 1157 | free(devices); | ||
2886 | 1158 | return 1; | ||
2887 | 1159 | } | ||
2888 | 1160 | if (verbose >= 0) | ||
2889 | 1161 | fprintf(stderr, Name ": Marking array %s as 'clean'\n", | ||
2890 | 1162 | mddev); | ||
2891 | 1163 | close(fd); | ||
2892 | 1164 | } | ||
2893 | 1165 | |||
2894 | 1166 | /* If we are in the middle of a reshape we may need to restore saved data | ||
2895 | 1167 | * that was moved aside due to the reshape overwriting live data | ||
2896 | 1168 | * The code of doing this lives in Grow.c | ||
2897 | 1169 | */ | ||
2898 | 1170 | #ifndef MDASSEMBLE | ||
2899 | 1171 | if (content->reshape_active) { | ||
2900 | 1172 | int err = 0; | ||
2901 | 1173 | int *fdlist = malloc(sizeof(int)* bestcnt); | ||
2902 | 1174 | if (verbose > 0) | ||
2903 | 1175 | fprintf(stderr, Name ":%s has an active reshape - checking " | ||
2904 | 1176 | "if critical section needs to be restored\n", | ||
2905 | 1177 | chosen_name); | ||
2906 | 1178 | for (i=0; i<bestcnt; i++) { | ||
2907 | 1179 | int j = best[i]; | ||
2908 | 1180 | if (j >= 0) { | ||
2909 | 1181 | fdlist[i] = dev_open(devices[j].devname, O_RDWR|O_EXCL); | ||
2910 | 1182 | if (fdlist[i] < 0) { | ||
2911 | 1183 | fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n", | ||
2912 | 1184 | devices[j].devname); | ||
2913 | 1185 | err = 1; | ||
2914 | 1186 | break; | ||
2915 | 1187 | } | ||
2916 | 1188 | } else | ||
2917 | 1189 | fdlist[i] = -1; | ||
2918 | 1190 | } | ||
2919 | 1191 | if (!err) { | ||
2920 | 1192 | if (st->ss->external && st->ss->recover_backup) | ||
2921 | 1193 | err = st->ss->recover_backup(st, content); | ||
2922 | 1194 | else | ||
2923 | 1195 | err = Grow_restart(st, content, fdlist, bestcnt, | ||
2924 | 1196 | backup_file, verbose > 0); | ||
2925 | 1197 | if (err && invalid_backup) { | ||
2926 | 1198 | if (verbose > 0) | ||
2927 | 1199 | fprintf(stderr, Name ": continuing" | ||
2928 | 1200 | " without restoring backup\n"); | ||
2929 | 1201 | err = 0; | ||
2930 | 1202 | } | ||
2931 | 1203 | } | ||
2932 | 1204 | while (i>0) { | ||
2933 | 1205 | i--; | ||
2934 | 1206 | if (fdlist[i]>=0) close(fdlist[i]); | ||
2935 | 1207 | } | ||
2936 | 1208 | if (err) { | ||
2937 | 1209 | fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n"); | ||
2938 | 1210 | if (backup_file == NULL) | ||
2939 | 1211 | fprintf(stderr," Possibly you needed to specify the --backup-file\n"); | ||
2940 | 1212 | close(mdfd); | ||
2941 | 1213 | free(devices); | ||
2942 | 1214 | return err; | ||
2943 | 1215 | } | ||
2944 | 1216 | } | ||
2945 | 1217 | #endif | ||
2946 | 1218 | /* count number of in-sync devices according to the superblock. | ||
2947 | 1219 | * We must have this number to start the array without -s or -R | ||
2948 | 1220 | */ | ||
2949 | 1221 | req_cnt = content->array.working_disks; | ||
2950 | 1222 | |||
2951 | 1223 | /* Almost ready to actually *do* something */ | ||
2952 | 1224 | if (!old_linux) { | ||
2953 | 1225 | int rv; | ||
2954 | 1226 | |||
2955 | 1227 | /* First, fill in the map, so that udev can find our name | ||
2956 | 1228 | * as soon as we become active. | ||
2957 | 1229 | */ | ||
2958 | 1230 | map_update(NULL, fd2devnum(mdfd), content->text_version, | ||
2959 | 1231 | content->uuid, chosen_name); | ||
2960 | 1232 | |||
2961 | 1233 | rv = set_array_info(mdfd, st, content); | ||
2962 | 1234 | if (rv) { | ||
2963 | 1235 | fprintf(stderr, Name ": failed to set array info for %s: %s\n", | ||
2964 | 1236 | mddev, strerror(errno)); | ||
2965 | 1237 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
2966 | 1238 | close(mdfd); | ||
2967 | 1239 | free(devices); | ||
2968 | 1240 | return 1; | ||
2969 | 1241 | } | ||
2970 | 1242 | if (ident->bitmap_fd >= 0) { | ||
2971 | 1243 | if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) { | ||
2972 | 1244 | fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n"); | ||
2973 | 1245 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
2974 | 1246 | close(mdfd); | ||
2975 | 1247 | free(devices); | ||
2976 | 1248 | return 1; | ||
2977 | 1249 | } | ||
2978 | 1250 | } else if (ident->bitmap_file) { | ||
2979 | 1251 | /* From config file */ | ||
2980 | 1252 | int bmfd = open(ident->bitmap_file, O_RDWR); | ||
2981 | 1253 | if (bmfd < 0) { | ||
2982 | 1254 | fprintf(stderr, Name ": Could not open bitmap file %s\n", | ||
2983 | 1255 | ident->bitmap_file); | ||
2984 | 1256 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
2985 | 1257 | close(mdfd); | ||
2986 | 1258 | free(devices); | ||
2987 | 1259 | return 1; | ||
2988 | 1260 | } | ||
2989 | 1261 | if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) { | ||
2990 | 1262 | fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev); | ||
2991 | 1263 | close(bmfd); | ||
2992 | 1264 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
2993 | 1265 | close(mdfd); | ||
2994 | 1266 | free(devices); | ||
2995 | 1267 | return 1; | ||
2996 | 1268 | } | ||
2997 | 1269 | close(bmfd); | ||
2998 | 1270 | } | ||
2999 | 1271 | |||
3000 | 1272 | /* First, add the raid disks, but add the chosen one last */ | ||
3001 | 1273 | for (i=0; i<= bestcnt; i++) { | ||
3002 | 1274 | int j; | ||
3003 | 1275 | if (i < bestcnt) { | ||
3004 | 1276 | j = best[i]; | ||
3005 | 1277 | if (j == chosen_drive) | ||
3006 | 1278 | continue; | ||
3007 | 1279 | } else | ||
3008 | 1280 | j = chosen_drive; | ||
3009 | 1281 | |||
3010 | 1282 | if (j >= 0 /* && devices[j].uptodate */) { | ||
3011 | 1283 | int dfd = dev_open(devices[j].devname, | ||
3012 | 1284 | O_RDWR|O_EXCL); | ||
3013 | 1285 | if (dfd >= 0) { | ||
3014 | 1286 | remove_partitions(dfd); | ||
3015 | 1287 | close(dfd); | ||
3016 | 1288 | } | ||
3017 | 1289 | rv = add_disk(mdfd, st, content, &devices[j].i); | ||
3018 | 1290 | |||
3019 | 1291 | if (rv) { | ||
3020 | 1292 | fprintf(stderr, Name ": failed to add " | ||
3021 | 1293 | "%s to %s: %s\n", | ||
3022 | 1294 | devices[j].devname, | ||
3023 | 1295 | mddev, | ||
3024 | 1296 | strerror(errno)); | ||
3025 | 1297 | if (i < content->array.raid_disks | ||
3026 | 1298 | || i == bestcnt) | ||
3027 | 1299 | okcnt--; | ||
3028 | 1300 | else | ||
3029 | 1301 | sparecnt--; | ||
3030 | 1302 | } else if (verbose > 0) | ||
3031 | 1303 | fprintf(stderr, Name ": added %s " | ||
3032 | 1304 | "to %s as %d\n", | ||
3033 | 1305 | devices[j].devname, mddev, | ||
3034 | 1306 | devices[j].i.disk.raid_disk); | ||
3035 | 1307 | } else if (verbose > 0 && i < content->array.raid_disks) | ||
3036 | 1308 | fprintf(stderr, Name ": no uptodate device for " | ||
3037 | 1309 | "slot %d of %s\n", | ||
3038 | 1310 | i, mddev); | ||
3039 | 1311 | } | ||
3040 | 1312 | |||
3041 | 1313 | if (content->array.level == LEVEL_CONTAINER) { | ||
3042 | 1314 | if (verbose >= 0) { | ||
3043 | 1315 | fprintf(stderr, Name ": Container %s has been " | ||
3044 | 1316 | "assembled with %d drive%s", | ||
3045 | 1317 | mddev, okcnt+sparecnt, okcnt+sparecnt==1?"":"s"); | ||
3046 | 1318 | if (okcnt < (unsigned)content->array.raid_disks) | ||
3047 | 1319 | fprintf(stderr, " (out of %d)", | ||
3048 | 1320 | content->array.raid_disks); | ||
3049 | 1321 | fprintf(stderr, "\n"); | ||
3050 | 1322 | } | ||
3051 | 1323 | st->ss->free_super(st); | ||
3052 | 1324 | sysfs_uevent(content, "change"); | ||
3053 | 1325 | wait_for(chosen_name, mdfd); | ||
3054 | 1326 | close(mdfd); | ||
3055 | 1327 | free(devices); | ||
3056 | 1328 | return 0; | ||
3057 | 1329 | } | ||
3058 | 1330 | |||
3059 | 1331 | if (runstop == 1 || | ||
3060 | 1332 | (runstop <= 0 && | ||
3061 | 1333 | ( enough(content->array.level, content->array.raid_disks, | ||
3062 | 1334 | content->array.layout, clean, avail, okcnt) && | ||
3063 | 1335 | (okcnt + rebuilding_cnt >= req_cnt || start_partial_ok) | ||
3064 | 1336 | ))) { | ||
3065 | 1337 | /* This array is good-to-go. | ||
3066 | 1338 | * If a reshape is in progress then we might need to | ||
3067 | 1339 | * continue monitoring it. In that case we start | ||
3068 | 1340 | * it read-only and let the grow code make it writable. | ||
3069 | 1341 | */ | ||
3070 | 1342 | int rv; | ||
3071 | 1343 | #ifndef MDASSEMBLE | ||
3072 | 1344 | if (content->reshape_active && | ||
3073 | 1345 | content->delta_disks <= 0) { | ||
3074 | 1346 | rv = sysfs_set_str(content, NULL, | ||
3075 | 1347 | "array_state", "readonly"); | ||
3076 | 1348 | if (rv == 0) | ||
3077 | 1349 | rv = Grow_continue(mdfd, st, content, | ||
3078 | 1350 | backup_file, | ||
3079 | 1351 | freeze_reshape); | ||
3080 | 1352 | } else | ||
3081 | 1353 | #endif | ||
3082 | 1354 | rv = ioctl(mdfd, RUN_ARRAY, NULL); | ||
3083 | 1355 | if (rv == 0) { | ||
3084 | 1356 | if (verbose >= 0) { | ||
3085 | 1357 | fprintf(stderr, Name ": %s has been started with %d drive%s", | ||
3086 | 1358 | mddev, okcnt, okcnt==1?"":"s"); | ||
3087 | 1359 | if (okcnt < (unsigned)content->array.raid_disks) | ||
3088 | 1360 | fprintf(stderr, " (out of %d)", content->array.raid_disks); | ||
3089 | 1361 | if (rebuilding_cnt) | ||
3090 | 1362 | fprintf(stderr, "%s %d rebuilding", sparecnt?",":" and", rebuilding_cnt); | ||
3091 | 1363 | if (sparecnt) | ||
3092 | 1364 | fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s"); | ||
3093 | 1365 | fprintf(stderr, ".\n"); | ||
3094 | 1366 | } | ||
3095 | 1367 | if (content->reshape_active && | ||
3096 | 1368 | content->array.level >= 4 && | ||
3097 | 1369 | content->array.level <= 6) { | ||
3098 | 1370 | /* might need to increase the size | ||
3099 | 1371 | * of the stripe cache - default is 256 | ||
3100 | 1372 | */ | ||
3101 | 1373 | if (256 < 4 * (content->array.chunk_size/4096)) { | ||
3102 | 1374 | struct mdinfo *sra = sysfs_read(mdfd, 0, 0); | ||
3103 | 1375 | if (sra) | ||
3104 | 1376 | sysfs_set_num(sra, NULL, | ||
3105 | 1377 | "stripe_cache_size", | ||
3106 | 1378 | (4 * content->array.chunk_size / 4096) + 1); | ||
3107 | 1379 | sysfs_free(sra); | ||
3108 | 1380 | } | ||
3109 | 1381 | } | ||
3110 | 1382 | if (okcnt < (unsigned)content->array.raid_disks) { | ||
3111 | 1383 | /* If any devices did not get added | ||
3112 | 1384 | * because the kernel rejected them based | ||
3113 | 1385 | * on event count, try adding them | ||
3114 | 1386 | * again providing the action policy is | ||
3115 | 1387 | * 're-add' or greater. The bitmap | ||
3116 | 1388 | * might allow them to be included, or | ||
3117 | 1389 | * they will become spares. | ||
3118 | 1390 | */ | ||
3119 | 1391 | for (i = 0; i < bestcnt; i++) { | ||
3120 | 1392 | int j = best[i]; | ||
3121 | 1393 | if (j >= 0 && !devices[j].uptodate) { | ||
3122 | 1394 | if (!disk_action_allows(&devices[j].i, st->ss->name, act_re_add)) | ||
3123 | 1395 | continue; | ||
3124 | 1396 | rv = add_disk(mdfd, st, content, | ||
3125 | 1397 | &devices[j].i); | ||
3126 | 1398 | if (rv == 0 && verbose >= 0) | ||
3127 | 1399 | fprintf(stderr, | ||
3128 | 1400 | Name ": %s has been re-added.\n", | ||
3129 | 1401 | devices[j].devname); | ||
3130 | 1402 | } | ||
3131 | 1403 | } | ||
3132 | 1404 | } | ||
3133 | 1405 | wait_for(mddev, mdfd); | ||
3134 | 1406 | close(mdfd); | ||
3135 | 1407 | if (auto_assem) { | ||
3136 | 1408 | int usecs = 1; | ||
3137 | 1409 | /* There is a nasty race with 'mdadm --monitor'. | ||
3138 | 1410 | * If it opens this device before we close it, | ||
3139 | 1411 | * it gets an incomplete open on which IO | ||
3140 | 1412 | * doesn't work and the capacity is | ||
3141 | 1413 | * wrong. | ||
3142 | 1414 | * If we reopen (to check for layered devices) | ||
3143 | 1415 | * before --monitor closes, we loose. | ||
3144 | 1416 | * | ||
3145 | 1417 | * So: wait upto 1 second for there to be | ||
3146 | 1418 | * a non-zero capacity. | ||
3147 | 1419 | */ | ||
3148 | 1420 | while (usecs < 1000) { | ||
3149 | 1421 | mdfd = open(mddev, O_RDONLY); | ||
3150 | 1422 | if (mdfd >= 0) { | ||
3151 | 1423 | unsigned long long size; | ||
3152 | 1424 | if (get_dev_size(mdfd, NULL, &size) && | ||
3153 | 1425 | size > 0) | ||
3154 | 1426 | break; | ||
3155 | 1427 | close(mdfd); | ||
3156 | 1428 | } | ||
3157 | 1429 | usleep(usecs); | ||
3158 | 1430 | usecs <<= 1; | ||
3159 | 1431 | } | ||
3160 | 1432 | } | ||
3161 | 1433 | free(devices); | ||
3162 | 1434 | return 0; | ||
3163 | 1435 | } | ||
3164 | 1436 | fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n", | ||
3165 | 1437 | mddev, strerror(errno)); | ||
3166 | 1438 | |||
3167 | 1439 | if (!enough(content->array.level, content->array.raid_disks, | ||
3168 | 1440 | content->array.layout, 1, avail, okcnt)) | ||
3169 | 1441 | fprintf(stderr, Name ": Not enough devices to " | ||
3170 | 1442 | "start the array.\n"); | ||
3171 | 1443 | else if (!enough(content->array.level, | ||
3172 | 1444 | content->array.raid_disks, | ||
3173 | 1445 | content->array.layout, clean, | ||
3174 | 1446 | avail, okcnt)) | ||
3175 | 1447 | fprintf(stderr, Name ": Not enough devices to " | ||
3176 | 1448 | "start the array while not clean " | ||
3177 | 1449 | "- consider --force.\n"); | ||
3178 | 1450 | |||
3179 | 1451 | if (auto_assem) | ||
3180 | 1452 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
3181 | 1453 | close(mdfd); | ||
3182 | 1454 | free(devices); | ||
3183 | 1455 | return 1; | ||
3184 | 1456 | } | ||
3185 | 1457 | if (runstop == -1) { | ||
3186 | 1458 | fprintf(stderr, Name ": %s assembled from %d drive%s", | ||
3187 | 1459 | mddev, okcnt, okcnt==1?"":"s"); | ||
3188 | 1460 | if (okcnt != (unsigned)content->array.raid_disks) | ||
3189 | 1461 | fprintf(stderr, " (out of %d)", content->array.raid_disks); | ||
3190 | 1462 | fprintf(stderr, ", but not started.\n"); | ||
3191 | 1463 | close(mdfd); | ||
3192 | 1464 | free(devices); | ||
3193 | 1465 | return 0; | ||
3194 | 1466 | } | ||
3195 | 1467 | if (verbose >= -1) { | ||
3196 | 1468 | fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s"); | ||
3197 | 1469 | if (rebuilding_cnt) | ||
3198 | 1470 | fprintf(stderr, "%s %d rebuilding", sparecnt?", ":" and ", rebuilding_cnt); | ||
3199 | 1471 | if (sparecnt) | ||
3200 | 1472 | fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s"); | ||
3201 | 1473 | if (!enough(content->array.level, content->array.raid_disks, | ||
3202 | 1474 | content->array.layout, 1, avail, okcnt)) | ||
3203 | 1475 | fprintf(stderr, " - not enough to start the array.\n"); | ||
3204 | 1476 | else if (!enough(content->array.level, | ||
3205 | 1477 | content->array.raid_disks, | ||
3206 | 1478 | content->array.layout, clean, | ||
3207 | 1479 | avail, okcnt)) | ||
3208 | 1480 | fprintf(stderr, " - not enough to start the " | ||
3209 | 1481 | "array while not clean - consider " | ||
3210 | 1482 | "--force.\n"); | ||
3211 | 1483 | else { | ||
3212 | 1484 | if (req_cnt == (unsigned)content->array.raid_disks) | ||
3213 | 1485 | fprintf(stderr, " - need all %d to start it", req_cnt); | ||
3214 | 1486 | else | ||
3215 | 1487 | fprintf(stderr, " - need %d of %d to start", req_cnt, content->array.raid_disks); | ||
3216 | 1488 | fprintf(stderr, " (use --run to insist).\n"); | ||
3217 | 1489 | } | ||
3218 | 1490 | } | ||
3219 | 1491 | if (auto_assem) | ||
3220 | 1492 | ioctl(mdfd, STOP_ARRAY, NULL); | ||
3221 | 1493 | close(mdfd); | ||
3222 | 1494 | free(devices); | ||
3223 | 1495 | return 1; | ||
3224 | 1496 | } else { | ||
3225 | 1497 | /* The "chosen_drive" is a good choice, and if necessary, the superblock has | ||
3226 | 1498 | * been updated to point to the current locations of devices. | ||
3227 | 1499 | * so we can just start the array | ||
3228 | 1500 | */ | ||
3229 | 1501 | unsigned long dev; | ||
3230 | 1502 | dev = makedev(devices[chosen_drive].i.disk.major, | ||
3231 | 1503 | devices[chosen_drive].i.disk.minor); | ||
3232 | 1504 | if (ioctl(mdfd, START_ARRAY, dev)) { | ||
3233 | 1505 | fprintf(stderr, Name ": Cannot start array: %s\n", | ||
3234 | 1506 | strerror(errno)); | ||
3235 | 1507 | } | ||
3236 | 1508 | |||
3237 | 1509 | } | ||
3238 | 1510 | close(mdfd); | ||
3239 | 1511 | free(devices); | ||
3240 | 1512 | return 0; | ||
3241 | 1513 | } | ||
3242 | 1514 | |||
3243 | 1515 | #ifndef MDASSEMBLE | ||
3244 | 1516 | int assemble_container_content(struct supertype *st, int mdfd, | ||
3245 | 1517 | struct mdinfo *content, int runstop, | ||
3246 | 1518 | char *chosen_name, int verbose, | ||
3247 | 1519 | char *backup_file, int freeze_reshape) | ||
3248 | 1520 | { | ||
3249 | 1521 | struct mdinfo *dev, *sra; | ||
3250 | 1522 | int working = 0, preexist = 0; | ||
3251 | 1523 | int expansion = 0; | ||
3252 | 1524 | struct map_ent *map = NULL; | ||
3253 | 1525 | int old_raid_disks; | ||
3254 | 1526 | |||
3255 | 1527 | sysfs_init(content, mdfd, 0); | ||
3256 | 1528 | |||
3257 | 1529 | sra = sysfs_read(mdfd, 0, GET_VERSION); | ||
3258 | 1530 | if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) | ||
3259 | 1531 | if (sysfs_set_array(content, md_get_version(mdfd)) != 0) { | ||
3260 | 1532 | if (sra) | ||
3261 | 1533 | sysfs_free(sra); | ||
3262 | 1534 | return 1; | ||
3263 | 1535 | } | ||
3264 | 1536 | |||
3265 | 1537 | if (st->ss->external && content->recovery_blocked) | ||
3266 | 1538 | block_subarray(content); | ||
3267 | 1539 | |||
3268 | 1540 | if (sra) | ||
3269 | 1541 | sysfs_free(sra); | ||
3270 | 1542 | old_raid_disks = content->array.raid_disks - content->delta_disks; | ||
3271 | 1543 | for (dev = content->devs; dev; dev = dev->next) | ||
3272 | 1544 | if (sysfs_add_disk(content, dev, 1) == 0) { | ||
3273 | 1545 | if (dev->disk.raid_disk >= old_raid_disks && | ||
3274 | 1546 | content->reshape_active) | ||
3275 | 1547 | expansion++; | ||
3276 | 1548 | else | ||
3277 | 1549 | working++; | ||
3278 | 1550 | } else if (errno == EEXIST) | ||
3279 | 1551 | preexist++; | ||
3280 | 1552 | if (working == 0) | ||
3281 | 1553 | return 1;/* Nothing new, don't try to start */ | ||
3282 | 1554 | |||
3283 | 1555 | map_update(&map, fd2devnum(mdfd), | ||
3284 | 1556 | content->text_version, | ||
3285 | 1557 | content->uuid, chosen_name); | ||
3286 | 1558 | |||
3287 | 1559 | if (runstop > 0 || | ||
3288 | 1560 | (working + preexist + expansion) >= | ||
3289 | 1561 | content->array.working_disks) { | ||
3290 | 1562 | int err; | ||
3291 | 1563 | int start_reshape; | ||
3292 | 1564 | |||
3293 | 1565 | /* There are two types of reshape: container wide or sub-array specific | ||
3294 | 1566 | * Check if metadata requests blocking container wide reshapes | ||
3295 | 1567 | */ | ||
3296 | 1568 | start_reshape = (content->reshape_active && | ||
3297 | 1569 | !((content->reshape_active == CONTAINER_RESHAPE) && | ||
3298 | 1570 | (content->array.state & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE)))); | ||
3299 | 1571 | if (start_reshape) { | ||
3300 | 1572 | int spare = content->array.raid_disks + expansion; | ||
3301 | 1573 | if (restore_backup(st, content, | ||
3302 | 1574 | working, | ||
3303 | 1575 | spare, backup_file, verbose) == 1) | ||
3304 | 1576 | return 1; | ||
3305 | 1577 | |||
3306 | 1578 | err = sysfs_set_str(content, NULL, | ||
3307 | 1579 | "array_state", "readonly"); | ||
3308 | 1580 | if (err) | ||
3309 | 1581 | return 1; | ||
3310 | 1582 | |||
3311 | 1583 | if (st->ss->external) { | ||
3312 | 1584 | if (!mdmon_running(st->container_dev)) | ||
3313 | 1585 | start_mdmon(st->container_dev); | ||
3314 | 1586 | ping_monitor_by_id(st->container_dev); | ||
3315 | 1587 | if (mdmon_running(st->container_dev) && | ||
3316 | 1588 | st->update_tail == NULL) | ||
3317 | 1589 | st->update_tail = &st->updates; | ||
3318 | 1590 | } | ||
3319 | 1591 | |||
3320 | 1592 | err = Grow_continue(mdfd, st, content, backup_file, | ||
3321 | 1593 | freeze_reshape); | ||
3322 | 1594 | } else switch(content->array.level) { | ||
3323 | 1595 | case LEVEL_LINEAR: | ||
3324 | 1596 | case LEVEL_MULTIPATH: | ||
3325 | 1597 | case 0: | ||
3326 | 1598 | err = sysfs_set_str(content, NULL, "array_state", | ||
3327 | 1599 | "active"); | ||
3328 | 1600 | break; | ||
3329 | 1601 | default: | ||
3330 | 1602 | err = sysfs_set_str(content, NULL, "array_state", | ||
3331 | 1603 | "readonly"); | ||
3332 | 1604 | /* start mdmon if needed. */ | ||
3333 | 1605 | if (!err) { | ||
3334 | 1606 | if (!mdmon_running(st->container_dev)) | ||
3335 | 1607 | start_mdmon(st->container_dev); | ||
3336 | 1608 | ping_monitor_by_id(st->container_dev); | ||
3337 | 1609 | } | ||
3338 | 1610 | break; | ||
3339 | 1611 | } | ||
3340 | 1612 | if (!err) | ||
3341 | 1613 | sysfs_set_safemode(content, content->safe_mode_delay); | ||
3342 | 1614 | if (verbose >= 0) { | ||
3343 | 1615 | if (err) | ||
3344 | 1616 | fprintf(stderr, Name | ||
3345 | 1617 | ": array %s now has %d device%s", | ||
3346 | 1618 | chosen_name, working + preexist, | ||
3347 | 1619 | working + preexist == 1 ? "":"s"); | ||
3348 | 1620 | else | ||
3349 | 1621 | fprintf(stderr, Name | ||
3350 | 1622 | ": Started %s with %d device%s", | ||
3351 | 1623 | chosen_name, working + preexist, | ||
3352 | 1624 | working + preexist == 1 ? "":"s"); | ||
3353 | 1625 | if (preexist) | ||
3354 | 1626 | fprintf(stderr, " (%d new)", working); | ||
3355 | 1627 | if (expansion) | ||
3356 | 1628 | fprintf(stderr, " ( + %d for expansion)", | ||
3357 | 1629 | expansion); | ||
3358 | 1630 | fprintf(stderr, "\n"); | ||
3359 | 1631 | } | ||
3360 | 1632 | if (!err) | ||
3361 | 1633 | wait_for(chosen_name, mdfd); | ||
3362 | 1634 | return err; | ||
3363 | 1635 | /* FIXME should have an O_EXCL and wait for read-auto */ | ||
3364 | 1636 | } else { | ||
3365 | 1637 | if (verbose >= 0) { | ||
3366 | 1638 | fprintf(stderr, Name | ||
3367 | 1639 | ": %s assembled with %d device%s", | ||
3368 | 1640 | chosen_name, preexist + working, | ||
3369 | 1641 | preexist + working == 1 ? "":"s"); | ||
3370 | 1642 | if (preexist) | ||
3371 | 1643 | fprintf(stderr, " (%d new)", working); | ||
3372 | 1644 | fprintf(stderr, " but not started\n"); | ||
3373 | 1645 | } | ||
3374 | 1646 | return 1; | ||
3375 | 1647 | } | ||
3376 | 1648 | } | ||
3377 | 1649 | #endif | ||
3378 | 1650 | |||
3379 | 1651 | 0 | ||
3380 | === added file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c' | |||
3381 | --- .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c 1970-01-01 00:00:00 +0000 | |||
3382 | +++ .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c 2012-06-18 08:55:05 +0000 | |||
3383 | @@ -0,0 +1,608 @@ | |||
3384 | 1 | /* | ||
3385 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. | ||
3386 | 3 | * | ||
3387 | 4 | * Copyright (C) 2001-2010 Neil Brown <neilb@suse.de> | ||
3388 | 5 | * | ||
3389 | 6 | * | ||
3390 | 7 | * This program is free software; you can redistribute it and/or modify | ||
3391 | 8 | * it under the terms of the GNU General Public License as published by | ||
3392 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
3393 | 10 | * (at your option) any later version. | ||
3394 | 11 | * | ||
3395 | 12 | * This program is distributed in the hope that it will be useful, | ||
3396 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3397 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3398 | 15 | * GNU General Public License for more details. | ||
3399 | 16 | * | ||
3400 | 17 | * You should have received a copy of the GNU General Public License | ||
3401 | 18 | * along with this program; if not, write to the Free Software | ||
3402 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
3403 | 20 | * | ||
3404 | 21 | * Author: Neil Brown | ||
3405 | 22 | * Email: <neilb@suse.de> | ||
3406 | 23 | */ | ||
3407 | 24 | |||
3408 | 25 | #include "mdadm.h" | ||
3409 | 26 | |||
3410 | 27 | char Version[] = Name " - v3.2.5 - 18th May 2012\n"; | ||
3411 | 28 | |||
3412 | 29 | /* | ||
3413 | 30 | * File: ReadMe.c | ||
3414 | 31 | * | ||
3415 | 32 | * This file contains general comments about the implementation | ||
3416 | 33 | * and the various usage messages that can be displayed by mdadm | ||
3417 | 34 | * | ||
3418 | 35 | * mdadm is a single program that can be used to control Linux md devices. | ||
3419 | 36 | * It is intended to provide all the functionality of the mdtools and | ||
3420 | 37 | * raidtools but with a very different interface. | ||
3421 | 38 | * mdadm can perform all functions without a configuration file. | ||
3422 | 39 | * There is the option of using a configuration file, but not in the same | ||
3423 | 40 | * way that raidtools uses one | ||
3424 | 41 | * raidtools uses a configuration file to describe how to create a RAID | ||
3425 | 42 | * array, and also uses this file partially to start a previously | ||
3426 | 43 | * created RAID array. Further, raidtools requires the configuration | ||
3427 | 44 | * file for such things as stopping a raid array which needs to know | ||
3428 | 45 | * nothing about the array. | ||
3429 | 46 | * | ||
3430 | 47 | * The configuration file that can be used by mdadm lists two | ||
3431 | 48 | * different things: | ||
3432 | 49 | * 1/ a mapping from uuid to md device to identify which arrays are | ||
3433 | 50 | * expect and what names (numbers) they should be given | ||
3434 | 51 | * 2/ a list of devices that should be scanned for md sub-devices | ||
3435 | 52 | * | ||
3436 | 53 | * | ||
3437 | 54 | */ | ||
3438 | 55 | |||
3439 | 56 | /* | ||
3440 | 57 | * mdadm has 7 major modes of operation: | ||
3441 | 58 | * 1/ Create | ||
3442 | 59 | * This mode is used to create a new array with a superblock | ||
3443 | 60 | * It can progress in several step create-add-add-run | ||
3444 | 61 | * or it can all happen with one command | ||
3445 | 62 | * 2/ Assemble | ||
3446 | 63 | * This mode is used to assemble the parts of a previously created | ||
3447 | 64 | * array into an active array. Components can be explicitly given | ||
3448 | 65 | * or can be searched for. mdadm (optionally) check that the components | ||
3449 | 66 | * do form a bona-fide array, and can, on request, fiddle superblock | ||
3450 | 67 | * version numbers so as to assemble a faulty array. | ||
3451 | 68 | * 3/ Build | ||
3452 | 69 | * This is for building legacy arrays without superblocks | ||
3453 | 70 | * 4/ Manage | ||
3454 | 71 | * This is for doing something to one or more devices | ||
3455 | 72 | * in an array, such as add,remove,fail. | ||
3456 | 73 | * run/stop/readonly/readwrite are also available | ||
3457 | 74 | * 5/ Misc | ||
3458 | 75 | * This is for doing things to individual devices. | ||
3459 | 76 | * They might be parts of an array so | ||
3460 | 77 | * zero-superblock, examine might be appropriate | ||
3461 | 78 | * They might be md arrays so | ||
3462 | 79 | * run,stop,rw,ro,detail might be appropriate | ||
3463 | 80 | * Also query will treat it as either | ||
3464 | 81 | * 6/ Monitor | ||
3465 | 82 | * This mode never exits but just monitors arrays and reports changes. | ||
3466 | 83 | * 7/ Grow | ||
3467 | 84 | * This mode allows for changing of key attributes of a raid array, such | ||
3468 | 85 | * as size, number of devices, and possibly even layout. | ||
3469 | 86 | * At the time if writing, there is only minimal support. | ||
3470 | 87 | */ | ||
3471 | 88 | |||
3472 | 89 | char short_options[]="-ABCDEFGIQhVXYWZ:vqbc:i:l:p:m:n:x:u:c:d:z:U:N:sarfRSow1tye:"; | ||
3473 | 90 | char short_bitmap_options[]= | ||
3474 | 91 | "-ABCDEFGIQhVXYWZ:vqb:c:i:l:p:m:n:x:u:c:d:z:U:N:sarfRSow1tye:"; | ||
3475 | 92 | char short_bitmap_auto_options[]= | ||
3476 | 93 | "-ABCDEFGIQhVXYWZ:vqb:c:i:l:p:m:n:x:u:c:d:z:U:N:sa:rfRSow1tye:"; | ||
3477 | 94 | |||
3478 | 95 | struct option long_options[] = { | ||
3479 | 96 | {"manage", 0, 0, ManageOpt}, | ||
3480 | 97 | {"misc", 0, 0, MiscOpt}, | ||
3481 | 98 | {"assemble", 0, 0, 'A'}, | ||
3482 | 99 | {"build", 0, 0, 'B'}, | ||
3483 | 100 | {"create", 0, 0, 'C'}, | ||
3484 | 101 | {"detail", 0, 0, 'D'}, | ||
3485 | 102 | {"examine", 0, 0, 'E'}, | ||
3486 | 103 | {"follow", 0, 0, 'F'}, | ||
3487 | 104 | {"grow", 0, 0, 'G'}, | ||
3488 | 105 | {"incremental",0,0, 'I'}, | ||
3489 | 106 | {"zero-superblock", 0, 0, 'K'}, /* deliberately no a short_option */ | ||
3490 | 107 | {"query", 0, 0, 'Q'}, | ||
3491 | 108 | {"examine-bitmap", 0, 0, 'X'}, | ||
3492 | 109 | {"auto-detect", 0, 0, AutoDetect}, | ||
3493 | 110 | {"detail-platform", 0, 0, DetailPlatform}, | ||
3494 | 111 | {"kill-subarray", 1, 0, KillSubarray}, | ||
3495 | 112 | {"update-subarray", 1, 0, UpdateSubarray}, | ||
3496 | 113 | {"udev-rules", 2, 0, UdevRules}, | ||
3497 | 114 | {"offroot", 0, 0, OffRootOpt}, | ||
3498 | 115 | |||
3499 | 116 | /* synonyms */ | ||
3500 | 117 | {"monitor", 0, 0, 'F'}, | ||
3501 | 118 | |||
3502 | 119 | /* after those will normally come the name of the md device */ | ||
3503 | 120 | {"help", 0, 0, 'h'}, | ||
3504 | 121 | {"help-options",0,0, HelpOptions}, | ||
3505 | 122 | {"version", 0, 0, 'V'}, | ||
3506 | 123 | {"verbose", 0, 0, 'v'}, | ||
3507 | 124 | {"quiet", 0, 0, 'q'}, | ||
3508 | 125 | |||
3509 | 126 | /* For create or build: */ | ||
3510 | 127 | {"chunk", 1, 0, ChunkSize}, | ||
3511 | 128 | {"rounding", 1, 0, ChunkSize}, /* for linear, chunk is really a | ||
3512 | 129 | * rounding number */ | ||
3513 | 130 | {"level", 1, 0, 'l'}, /* 0,1,4,5,6,linear */ | ||
3514 | 131 | {"parity", 1, 0, Layout}, /* {left,right}-{a,}symmetric */ | ||
3515 | 132 | {"layout", 1, 0, Layout}, | ||
3516 | 133 | {"raid-disks",1, 0, 'n'}, | ||
3517 | 134 | {"raid-devices",1, 0, 'n'}, | ||
3518 | 135 | {"spare-disks",1,0, 'x'}, | ||
3519 | 136 | {"spare-devices",1,0, 'x'}, | ||
3520 | 137 | {"size", 1, 0, 'z'}, | ||
3521 | 138 | {"auto", 1, 0, Auto}, /* also for --assemble */ | ||
3522 | 139 | {"assume-clean",0,0, AssumeClean }, | ||
3523 | 140 | {"metadata", 1, 0, 'e'}, /* superblock format */ | ||
3524 | 141 | {"bitmap", 1, 0, Bitmap}, | ||
3525 | 142 | {"bitmap-chunk", 1, 0, BitmapChunk}, | ||
3526 | 143 | {"write-behind", 2, 0, WriteBehind}, | ||
3527 | 144 | {"write-mostly",0, 0, WriteMostly}, | ||
3528 | 145 | {"re-add", 0, 0, ReAdd}, | ||
3529 | 146 | {"homehost", 1, 0, HomeHost}, | ||
3530 | 147 | {"symlinks", 1, 0, Symlinks}, | ||
3531 | 148 | |||
3532 | 149 | /* For assemble */ | ||
3533 | 150 | {"uuid", 1, 0, 'u'}, | ||
3534 | 151 | {"super-minor",1,0, SuperMinor}, | ||
3535 | 152 | {"name", 1, 0, 'N'}, | ||
3536 | 153 | {"config", 1, 0, ConfigFile}, | ||
3537 | 154 | {"scan", 0, 0, 's'}, | ||
3538 | 155 | {"force", 0, 0, Force}, | ||
3539 | 156 | {"update", 1, 0, 'U'}, | ||
3540 | 157 | {"freeze-reshape", 0, 0, FreezeReshape}, | ||
3541 | 158 | |||
3542 | 159 | /* Management */ | ||
3543 | 160 | {"add", 0, 0, Add}, | ||
3544 | 161 | {"remove", 0, 0, Remove}, | ||
3545 | 162 | {"fail", 0, 0, Fail}, | ||
3546 | 163 | {"set-faulty",0, 0, Fail}, | ||
3547 | 164 | {"run", 0, 0, 'R'}, | ||
3548 | 165 | {"stop", 0, 0, 'S'}, | ||
3549 | 166 | {"readonly", 0, 0, 'o'}, | ||
3550 | 167 | {"readwrite", 0, 0, 'w'}, | ||
3551 | 168 | {"no-degraded",0,0, NoDegraded }, | ||
3552 | 169 | {"wait", 0, 0, WaitOpt}, | ||
3553 | 170 | {"wait-clean", 0, 0, Waitclean }, | ||
3554 | 171 | |||
3555 | 172 | /* For Detail/Examine */ | ||
3556 | 173 | {"brief", 0, 0, Brief}, | ||
3557 | 174 | {"export", 0, 0, 'Y'}, | ||
3558 | 175 | {"sparc2.2", 0, 0, Sparc22}, | ||
3559 | 176 | {"test", 0, 0, 't'}, | ||
3560 | 177 | {"prefer", 1, 0, Prefer}, | ||
3561 | 178 | |||
3562 | 179 | /* For Follow/monitor */ | ||
3563 | 180 | {"mail", 1, 0, EMail}, | ||
3564 | 181 | {"program", 1, 0, ProgramOpt}, | ||
3565 | 182 | {"alert", 1, 0, ProgramOpt}, | ||
3566 | 183 | {"increment", 1, 0, Increment}, | ||
3567 | 184 | {"delay", 1, 0, 'd'}, | ||
3568 | 185 | {"daemonise", 0, 0, Fork}, | ||
3569 | 186 | {"daemonize", 0, 0, Fork}, | ||
3570 | 187 | {"oneshot", 0, 0, '1'}, | ||
3571 | 188 | {"pid-file", 1, 0, 'i'}, | ||
3572 | 189 | {"syslog", 0, 0, 'y'}, | ||
3573 | 190 | {"no-sharing", 0, 0, NoSharing}, | ||
3574 | 191 | |||
3575 | 192 | /* For Grow */ | ||
3576 | 193 | {"backup-file", 1,0, BackupFile}, | ||
3577 | 194 | {"invalid-backup",0,0,InvalidBackup}, | ||
3578 | 195 | {"array-size", 1, 0, 'Z'}, | ||
3579 | 196 | {"continue", 0, 0, Continue}, | ||
3580 | 197 | |||
3581 | 198 | /* For Incremental */ | ||
3582 | 199 | {"rebuild-map", 0, 0, RebuildMapOpt}, | ||
3583 | 200 | {"path", 1, 0, IncrementalPath}, | ||
3584 | 201 | |||
3585 | 202 | {0, 0, 0, 0} | ||
3586 | 203 | }; | ||
3587 | 204 | |||
3588 | 205 | char Usage[] = | ||
3589 | 206 | "Usage: mdadm --help\n" | ||
3590 | 207 | " for help\n" | ||
3591 | 208 | ; | ||
3592 | 209 | |||
3593 | 210 | char Help[] = | ||
3594 | 211 | "mdadm is used for building, managing, and monitoring\n" | ||
3595 | 212 | "Linux md devices (aka RAID arrays)\n" | ||
3596 | 213 | "Usage: mdadm --create device options...\n" | ||
3597 | 214 | " Create a new array from unused devices.\n" | ||
3598 | 215 | " mdadm --assemble device options...\n" | ||
3599 | 216 | " Assemble a previously created array.\n" | ||
3600 | 217 | " mdadm --build device options...\n" | ||
3601 | 218 | " Create or assemble an array without metadata.\n" | ||
3602 | 219 | " mdadm --manage device options...\n" | ||
3603 | 220 | " make changes to an existing array.\n" | ||
3604 | 221 | " mdadm --misc options... devices\n" | ||
3605 | 222 | " report on or modify various md related devices.\n" | ||
3606 | 223 | " mdadm --grow options device\n" | ||
3607 | 224 | " resize/reshape an active array\n" | ||
3608 | 225 | " mdadm --incremental device\n" | ||
3609 | 226 | " add/remove a device to/from an array as appropriate\n" | ||
3610 | 227 | " mdadm --monitor options...\n" | ||
3611 | 228 | " Monitor one or more array for significant changes.\n" | ||
3612 | 229 | " mdadm device options...\n" | ||
3613 | 230 | " Shorthand for --manage.\n" | ||
3614 | 231 | "Any parameter that does not start with '-' is treated as a device name\n" | ||
3615 | 232 | "or, for --examine-bitmap, a file name.\n" | ||
3616 | 233 | "The first such name is often the name of an md device. Subsequent\n" | ||
3617 | 234 | "names are often names of component devices.\n" | ||
3618 | 235 | "\n" | ||
3619 | 236 | " For detailed help on the above major modes use --help after the mode\n" | ||
3620 | 237 | " e.g.\n" | ||
3621 | 238 | " mdadm --assemble --help\n" | ||
3622 | 239 | " For general help on options use\n" | ||
3623 | 240 | " mdadm --help-options\n" | ||
3624 | 241 | ; | ||
3625 | 242 | |||
3626 | 243 | char OptionHelp[] = | ||
3627 | 244 | "Any parameter that does not start with '-' is treated as a device name\n" | ||
3628 | 245 | "or, for --examine-bitmap, a file name.\n" | ||
3629 | 246 | "The first such name is often the name of an md device. Subsequent\n" | ||
3630 | 247 | "names are often names of component devices.\n" | ||
3631 | 248 | "\n" | ||
3632 | 249 | "Some common options are:\n" | ||
3633 | 250 | " --help -h : General help message or, after above option,\n" | ||
3634 | 251 | " mode specific help message\n" | ||
3635 | 252 | " --help-options : This help message\n" | ||
3636 | 253 | " --version -V : Print version information for mdadm\n" | ||
3637 | 254 | " --verbose -v : Be more verbose about what is happening\n" | ||
3638 | 255 | " --quiet -q : Don't print un-necessary messages\n" | ||
3639 | 256 | " --brief -b : Be less verbose, more brief\n" | ||
3640 | 257 | " --export -Y : With --detail, use key=value format for easy\n" | ||
3641 | 258 | " import into environment\n" | ||
3642 | 259 | " --force -f : Override normal checks and be more forceful\n" | ||
3643 | 260 | "\n" | ||
3644 | 261 | " --assemble -A : Assemble an array\n" | ||
3645 | 262 | " --build -B : Build an array without metadata\n" | ||
3646 | 263 | " --create -C : Create a new array\n" | ||
3647 | 264 | " --detail -D : Display details of an array\n" | ||
3648 | 265 | " --examine -E : Examine superblock on an array component\n" | ||
3649 | 266 | " --examine-bitmap -X: Display the detail of a bitmap file\n" | ||
3650 | 267 | " --monitor -F : monitor (follow) some arrays\n" | ||
3651 | 268 | " --grow -G : resize/ reshape and array\n" | ||
3652 | 269 | " --incremental -I : add/remove a single device to/from an array as appropriate\n" | ||
3653 | 270 | " --query -Q : Display general information about how a\n" | ||
3654 | 271 | " device relates to the md driver\n" | ||
3655 | 272 | " --auto-detect : Start arrays auto-detected by the kernel\n" | ||
3656 | 273 | " --offroot : Set first character of argv[0] to @ to indicate the\n" | ||
3657 | 274 | " application was launched from initrd/initramfs and\n" | ||
3658 | 275 | " should not be shutdown by systemd as part of the\n" | ||
3659 | 276 | " regular shutdown process.\n" | ||
3660 | 277 | ; | ||
3661 | 278 | /* | ||
3662 | 279 | "\n" | ||
3663 | 280 | " For create or build:\n" | ||
3664 | 281 | " --bitmap= -b : File to store bitmap in - may pre-exist for --build\n" | ||
3665 | 282 | " --chunk= -c : chunk size of kibibytes\n" | ||
3666 | 283 | " --rounding= : rounding factor for linear array (==chunk size)\n" | ||
3667 | 284 | " --level= -l : raid level: 0,1,4,5,6,linear,mp. 0 or linear for build\n" | ||
3668 | 285 | " --parity= -p : raid5/6 parity algorithm: {left,right}-{,a}symmetric\n" | ||
3669 | 286 | " --layout= : same as --parity\n" | ||
3670 | 287 | " --raid-devices= -n : number of active devices in array\n" | ||
3671 | 288 | " --spare-devices= -x: number of spares (eXtras) devices in initial array\n" | ||
3672 | 289 | " --size= -z : Size (in K) of each drive in RAID1/4/5/6/10 - optional\n" | ||
3673 | 290 | " --force -f : Honour devices as listed on command line. Don't\n" | ||
3674 | 291 | " : insert a missing drive for RAID5.\n" | ||
3675 | 292 | " --assume-clean : Assume the array is already in-sync. This is dangerous.\n" | ||
3676 | 293 | " --bitmap-chunk= : chunksize of bitmap in bitmap file (Kilobytes)\n" | ||
3677 | 294 | " --delay= -d : seconds between bitmap updates\n" | ||
3678 | 295 | " --write-behind= : number of simultaneous write-behind requests to allow (requires bitmap)\n" | ||
3679 | 296 | " --name= -N : Textual name for array - max 32 characters\n" | ||
3680 | 297 | "\n" | ||
3681 | 298 | " For assemble:\n" | ||
3682 | 299 | " --bitmap= -b : File to find bitmap information in\n" | ||
3683 | 300 | " --uuid= -u : uuid of array to assemble. Devices which don't\n" | ||
3684 | 301 | " have this uuid are excluded\n" | ||
3685 | 302 | " --super-minor= -m : minor number to look for in super-block when\n" | ||
3686 | 303 | " choosing devices to use.\n" | ||
3687 | 304 | " --name= -N : Array name to look for in super-block.\n" | ||
3688 | 305 | " --config= -c : config file\n" | ||
3689 | 306 | " --scan -s : scan config file for missing information\n" | ||
3690 | 307 | " --force -f : Assemble the array even if some superblocks appear out-of-date\n" | ||
3691 | 308 | " --update= -U : Update superblock: try '-A --update=?' for list of options.\n" | ||
3692 | 309 | " --no-degraded : Do not start any degraded arrays - default unless --scan.\n" | ||
3693 | 310 | "\n" | ||
3694 | 311 | " For detail or examine:\n" | ||
3695 | 312 | " --brief -b : Just print device name and UUID\n" | ||
3696 | 313 | "\n" | ||
3697 | 314 | " For follow/monitor:\n" | ||
3698 | 315 | " --mail= -m : Address to mail alerts of failure to\n" | ||
3699 | 316 | " --program= -p : Program to run when an event is detected\n" | ||
3700 | 317 | " --alert= : same as --program\n" | ||
3701 | 318 | " --delay= -d : seconds of delay between polling state. default=60\n" | ||
3702 | 319 | "\n" | ||
3703 | 320 | " General management:\n" | ||
3704 | 321 | " --add -a : add, or hotadd subsequent devices\n" | ||
3705 | 322 | " --remove -r : remove subsequent devices\n" | ||
3706 | 323 | " --fail -f : mark subsequent devices a faulty\n" | ||
3707 | 324 | " --set-faulty : same as --fail\n" | ||
3708 | 325 | " --run -R : start a partially built array\n" | ||
3709 | 326 | " --stop -S : deactivate array, releasing all resources\n" | ||
3710 | 327 | " --readonly -o : mark array as readonly\n" | ||
3711 | 328 | " --readwrite -w : mark array as readwrite\n" | ||
3712 | 329 | " --zero-superblock : erase the MD superblock from a device.\n" | ||
3713 | 330 | " --wait -W : wait for recovery/resync/reshape to finish.\n" | ||
3714 | 331 | ; | ||
3715 | 332 | */ | ||
3716 | 333 | |||
3717 | 334 | char Help_create[] = | ||
3718 | 335 | "Usage: mdadm --create device -chunk=X --level=Y --raid-devices=Z devices\n" | ||
3719 | 336 | "\n" | ||
3720 | 337 | " This usage will initialise a new md array, associate some\n" | ||
3721 | 338 | " devices with it, and activate the array. In order to create an\n" | ||
3722 | 339 | " array with some devices missing, use the special word 'missing' in\n" | ||
3723 | 340 | " place of the relevant device name.\n" | ||
3724 | 341 | "\n" | ||
3725 | 342 | " Before devices are added, they are checked to see if they already contain\n" | ||
3726 | 343 | " raid superblocks or filesystems. They are also checked to see if\n" | ||
3727 | 344 | " the variance in device size exceeds 1%.\n" | ||
3728 | 345 | " If any discrepancy is found, the user will be prompted for confirmation\n" | ||
3729 | 346 | " before the array is created. The presence of a '--run' can override this\n" | ||
3730 | 347 | " caution.\n" | ||
3731 | 348 | "\n" | ||
3732 | 349 | " If the --size option is given then only that many kilobytes of each\n" | ||
3733 | 350 | " device is used, no matter how big each device is.\n" | ||
3734 | 351 | " If no --size is given, the apparent size of the smallest drive given\n" | ||
3735 | 352 | " is used for raid level 1 and greater, and the full device is used for\n" | ||
3736 | 353 | " other levels.\n" | ||
3737 | 354 | "\n" | ||
3738 | 355 | " Options that are valid with --create (-C) are:\n" | ||
3739 | 356 | " --bitmap= : Create a bitmap for the array with the given filename\n" | ||
3740 | 357 | " --chunk= -c : chunk size of kibibytes\n" | ||
3741 | 358 | " --rounding= : rounding factor for linear array (==chunk size)\n" | ||
3742 | 359 | " --level= -l : raid level: 0,1,4,5,6,linear,multipath and synonyms\n" | ||
3743 | 360 | " --parity= -p : raid5/6 parity algorithm: {left,right}-{,a}symmetric\n" | ||
3744 | 361 | " --layout= : same as --parity\n" | ||
3745 | 362 | " --raid-devices= -n : number of active devices in array\n" | ||
3746 | 363 | " --spare-devices= -x: number of spares (eXtras) devices in initial array\n" | ||
3747 | 364 | " --size= -z : Size (in K) of each drive in RAID1/4/5/6/10 - optional\n" | ||
3748 | 365 | " --force -f : Honour devices as listed on command line. Don't\n" | ||
3749 | 366 | " : insert a missing drive for RAID5.\n" | ||
3750 | 367 | " --run -R : insist of running the array even if not all\n" | ||
3751 | 368 | " : devices are present or some look odd.\n" | ||
3752 | 369 | " --readonly -o : start the array readonly - not supported yet.\n" | ||
3753 | 370 | " --name= -N : Textual name for array - max 32 characters\n" | ||
3754 | 371 | " --bitmap-chunk= : bitmap chunksize in Kilobytes.\n" | ||
3755 | 372 | " --delay= -d : bitmap update delay in seconds.\n" | ||
3756 | 373 | "\n" | ||
3757 | 374 | ; | ||
3758 | 375 | |||
3759 | 376 | char Help_build[] = | ||
3760 | 377 | "Usage: mdadm --build device -chunk=X --level=Y --raid-devices=Z devices\n" | ||
3761 | 378 | "\n" | ||
3762 | 379 | " This usage is similar to --create. The difference is that it creates\n" | ||
3763 | 380 | " a legacy array without a superblock. With these arrays there is no\n" | ||
3764 | 381 | " different between initially creating the array and subsequently\n" | ||
3765 | 382 | " assembling the array, except that hopefully there is useful data\n" | ||
3766 | 383 | " there in the second case.\n" | ||
3767 | 384 | "\n" | ||
3768 | 385 | " The level may only be 0, raid0, or linear.\n" | ||
3769 | 386 | " All devices must be listed and the array will be started once complete.\n" | ||
3770 | 387 | " Options that are valid with --build (-B) are:\n" | ||
3771 | 388 | " --bitmap= : file to store/find bitmap information in.\n" | ||
3772 | 389 | " --chunk= -c : chunk size of kibibytes\n" | ||
3773 | 390 | " --rounding= : rounding factor for linear array (==chunk size)\n" | ||
3774 | 391 | " --level= -l : 0, raid0, or linear\n" | ||
3775 | 392 | " --raid-devices= -n : number of active devices in array\n" | ||
3776 | 393 | " --bitmap-chunk= : bitmap chunksize in Kilobytes.\n" | ||
3777 | 394 | " --delay= -d : bitmap update delay in seconds.\n" | ||
3778 | 395 | ; | ||
3779 | 396 | |||
3780 | 397 | char Help_assemble[] = | ||
3781 | 398 | "Usage: mdadm --assemble device options...\n" | ||
3782 | 399 | " mdadm --assemble --scan options...\n" | ||
3783 | 400 | "\n" | ||
3784 | 401 | "This usage assembles one or more raid arrays from pre-existing\n" | ||
3785 | 402 | "components.\n" | ||
3786 | 403 | "For each array, mdadm needs to know the md device, the identity of\n" | ||
3787 | 404 | "the array, and a number of sub devices. These can be found in a number\n" | ||
3788 | 405 | "of ways.\n" | ||
3789 | 406 | "\n" | ||
3790 | 407 | "The md device is either given on the command line or is found listed\n" | ||
3791 | 408 | "in the config file. The array identity is determined either from the\n" | ||
3792 | 409 | "--uuid or --super-minor commandline arguments, from the config file,\n" | ||
3793 | 410 | "or from the first component device on the command line.\n" | ||
3794 | 411 | "\n" | ||
3795 | 412 | "The different combinations of these are as follows:\n" | ||
3796 | 413 | " If the --scan option is not given, then only devices and identities\n" | ||
3797 | 414 | " listed on the command line are considered.\n" | ||
3798 | 415 | " The first device will be the array device, and the remainder will be\n" | ||
3799 | 416 | " examined when looking for components.\n" | ||
3800 | 417 | " If an explicit identity is given with --uuid or --super-minor, then\n" | ||
3801 | 418 | " only devices with a superblock which matches that identity is considered,\n" | ||
3802 | 419 | " otherwise every device listed is considered.\n" | ||
3803 | 420 | "\n" | ||
3804 | 421 | " If the --scan option is given, and no devices are listed, then\n" | ||
3805 | 422 | " every array listed in the config file is considered for assembly.\n" | ||
3806 | 423 | " The identity of candidate devices are determined from the config file.\n" | ||
3807 | 424 | "\n" | ||
3808 | 425 | " If the --scan option is given as well as one or more devices, then\n" | ||
3809 | 426 | " Those devices are md devices that are to be assembled. Their identity\n" | ||
3810 | 427 | " and components are determined from the config file.\n" | ||
3811 | 428 | "\n" | ||
3812 | 429 | " If mdadm can not find all of the components for an array, it will assemble\n" | ||
3813 | 430 | " it but not activate it unless --run or --scan is given. To preserve this\n" | ||
3814 | 431 | " behaviour even with --scan, add --no-degraded. Note that \"all of the\n" | ||
3815 | 432 | " components\" means as many as were present the last time the array was running\n" | ||
3816 | 433 | " as recorded in the superblock. If the array was already degraded, and\n" | ||
3817 | 434 | " the missing device is not a new problem, it will still be assembled. It\n" | ||
3818 | 435 | " is only newly missing devices that cause the array not to be started.\n" | ||
3819 | 436 | "\n" | ||
3820 | 437 | "Options that are valid with --assemble (-A) are:\n" | ||
3821 | 438 | " --bitmap= : bitmap file to use wit the array\n" | ||
3822 | 439 | " --uuid= -u : uuid of array to assemble. Devices which don't\n" | ||
3823 | 440 | " have this uuid are excluded\n" | ||
3824 | 441 | " --super-minor= -m : minor number to look for in super-block when\n" | ||
3825 | 442 | " choosing devices to use.\n" | ||
3826 | 443 | " --name= -N : Array name to look for in super-block.\n" | ||
3827 | 444 | " --config= -c : config file\n" | ||
3828 | 445 | " --scan -s : scan config file for missing information\n" | ||
3829 | 446 | " --run -R : Try to start the array even if not enough devices\n" | ||
3830 | 447 | " for a full array are present\n" | ||
3831 | 448 | " --force -f : Assemble the array even if some superblocks appear\n" | ||
3832 | 449 | " : out-of-date. This involves modifying the superblocks.\n" | ||
3833 | 450 | " --update= -U : Update superblock: try '-A --update=?' for option list.\n" | ||
3834 | 451 | " --no-degraded : Assemble but do not start degraded arrays.\n" | ||
3835 | 452 | ; | ||
3836 | 453 | |||
3837 | 454 | char Help_manage[] = | ||
3838 | 455 | "Usage: mdadm arraydevice options component devices...\n" | ||
3839 | 456 | "\n" | ||
3840 | 457 | "This usage is for managing the component devices within an array.\n" | ||
3841 | 458 | "The --manage option is not needed and is assumed if the first argument\n" | ||
3842 | 459 | "is a device name or a management option.\n" | ||
3843 | 460 | "The first device listed will be taken to be an md array device, and\n" | ||
3844 | 461 | "subsequent devices are (potential) components of that array.\n" | ||
3845 | 462 | "\n" | ||
3846 | 463 | "Options that are valid with management mode are:\n" | ||
3847 | 464 | " --add -a : hotadd subsequent devices to the array\n" | ||
3848 | 465 | " --remove -r : remove subsequent devices, which must not be active\n" | ||
3849 | 466 | " --fail -f : mark subsequent devices a faulty\n" | ||
3850 | 467 | " --set-faulty : same as --fail\n" | ||
3851 | 468 | " --run -R : start a partially built array\n" | ||
3852 | 469 | " --stop -S : deactivate array, releasing all resources\n" | ||
3853 | 470 | " --readonly -o : mark array as readonly\n" | ||
3854 | 471 | " --readwrite -w : mark array as readwrite\n" | ||
3855 | 472 | ; | ||
3856 | 473 | |||
3857 | 474 | char Help_misc[] = | ||
3858 | 475 | "Usage: mdadm misc_option devices...\n" | ||
3859 | 476 | "\n" | ||
3860 | 477 | "This usage is for performing some task on one or more devices, which\n" | ||
3861 | 478 | "may be arrays or components, depending on the task.\n" | ||
3862 | 479 | "The --misc option is not needed (though it is allowed) and is assumed\n" | ||
3863 | 480 | "if the first argument in a misc option.\n" | ||
3864 | 481 | "\n" | ||
3865 | 482 | "Options that are valid with the miscellaneous mode are:\n" | ||
3866 | 483 | " --query -Q : Display general information about how a\n" | ||
3867 | 484 | " device relates to the md driver\n" | ||
3868 | 485 | " --detail -D : Display details of an array\n" | ||
3869 | 486 | " --detail-platform : Display hardware/firmware details\n" | ||
3870 | 487 | " --examine -E : Examine superblock on an array component\n" | ||
3871 | 488 | " --examine-bitmap -X: Display contents of a bitmap file\n" | ||
3872 | 489 | " --zero-superblock : erase the MD superblock from a device.\n" | ||
3873 | 490 | " --run -R : start a partially built array\n" | ||
3874 | 491 | " --stop -S : deactivate array, releasing all resources\n" | ||
3875 | 492 | " --readonly -o : mark array as readonly\n" | ||
3876 | 493 | " --readwrite -w : mark array as readwrite\n" | ||
3877 | 494 | " --test -t : exit status 0 if ok, 1 if degrade, 2 if dead, 4 if missing\n" | ||
3878 | 495 | " --wait -W : wait for resync/rebuild/recovery to finish\n" | ||
3879 | 496 | ; | ||
3880 | 497 | |||
3881 | 498 | char Help_monitor[] = | ||
3882 | 499 | "Usage: mdadm --monitor options devices\n" | ||
3883 | 500 | "\n" | ||
3884 | 501 | "This usage causes mdadm to monitor a number of md arrays by periodically\n" | ||
3885 | 502 | "polling their status and acting on any changes.\n" | ||
3886 | 503 | "If any devices are listed then those devices are monitored, otherwise\n" | ||
3887 | 504 | "all devices listed in the config file are monitored.\n" | ||
3888 | 505 | "The address for mailing advisories to, and the program to handle\n" | ||
3889 | 506 | "each change can be specified in the config file or on the command line.\n" | ||
3890 | 507 | "If no mail address or program are specified, then mdadm reports all\n" | ||
3891 | 508 | "state changes to stdout.\n" | ||
3892 | 509 | "\n" | ||
3893 | 510 | "Options that are valid with the monitor (-F --follow) mode are:\n" | ||
3894 | 511 | " --mail= -m : Address to mail alerts of failure to\n" | ||
3895 | 512 | " --program= -p : Program to run when an event is detected\n" | ||
3896 | 513 | " --alert= : same as --program\n" | ||
3897 | 514 | " --syslog -y : Report alerts via syslog\n" | ||
3898 | 515 | " --increment= -r : Report RebuildNN events in the given increment. default=20\n" | ||
3899 | 516 | " --delay= -d : seconds of delay between polling state. default=60\n" | ||
3900 | 517 | " --config= -c : specify a different config file\n" | ||
3901 | 518 | " --scan -s : find mail-address/program in config file\n" | ||
3902 | 519 | " --daemonise -f : Fork and continue in child, parent exits\n" | ||
3903 | 520 | " --pid-file= -i : In daemon mode write pid to specified file instead of stdout\n" | ||
3904 | 521 | " --oneshot -1 : Check for degraded arrays, then exit\n" | ||
3905 | 522 | " --test -t : Generate a TestMessage event against each array at startup\n" | ||
3906 | 523 | ; | ||
3907 | 524 | |||
3908 | 525 | char Help_grow[] = | ||
3909 | 526 | "Usage: mdadm --grow device options\n" | ||
3910 | 527 | "\n" | ||
3911 | 528 | "This usage causes mdadm to attempt to reconfigure a running array.\n" | ||
3912 | 529 | "This is only possibly if the kernel being used supports a particular\n" | ||
3913 | 530 | "reconfiguration. This version supports changing the number of\n" | ||
3914 | 531 | "devices in a RAID1/5/6, changing the active size of all devices in\n" | ||
3915 | 532 | "a RAID1/4/5/6, adding or removing a write-intent bitmap, and changing\n" | ||
3916 | 533 | "the error mode for a 'FAULTY' array.\n" | ||
3917 | 534 | "\n" | ||
3918 | 535 | "Options that are valid with the grow (-G --grow) mode are:\n" | ||
3919 | 536 | " --level= -l : Tell mdadm what level the array is so that it can\n" | ||
3920 | 537 | " : interpret '--layout' properly.\n" | ||
3921 | 538 | " --layout= -p : For a FAULTY array, set/change the error mode.\n" | ||
3922 | 539 | " --size= -z : Change the active size of devices in an array.\n" | ||
3923 | 540 | " : This is useful if all devices have been replaced\n" | ||
3924 | 541 | " : with larger devices. Value is in Kilobytes, or\n" | ||
3925 | 542 | " : the special word 'max' meaning 'as large as possible'.\n" | ||
3926 | 543 | " --raid-devices= -n : Change the number of active devices in an array.\n" | ||
3927 | 544 | " --bitmap= -b : Add or remove a write-intent bitmap.\n" | ||
3928 | 545 | " --backup-file= file : A file on a differt device to store data for a\n" | ||
3929 | 546 | " : short time while increasing raid-devices on a\n" | ||
3930 | 547 | " : RAID4/5/6 array. Not needed when a spare is present.\n" | ||
3931 | 548 | " --array-size= -Z : Change visible size of array. This does not change\n" | ||
3932 | 549 | " : any data on the device, and is not stable across restarts.\n" | ||
3933 | 550 | ; | ||
3934 | 551 | |||
3935 | 552 | char Help_incr[] = | ||
3936 | 553 | "Usage: mdadm --incremental [-Rqrsf] device\n" | ||
3937 | 554 | "\n" | ||
3938 | 555 | "This usage allows for incremental assembly of md arrays. Devices can be\n" | ||
3939 | 556 | "added one at a time as they are discovered. Once an array has all expected\n" | ||
3940 | 557 | "devices, it will be started.\n" | ||
3941 | 558 | "\n" | ||
3942 | 559 | "Optionally, the process can be reversed by using the fail option.\n" | ||
3943 | 560 | "When fail mode is invoked, mdadm will see if the device belongs to an array\n" | ||
3944 | 561 | "and then both fail (if needed) and remove the device from that array.\n" | ||
3945 | 562 | "\n" | ||
3946 | 563 | "Options that are valid with incremental assembly (-I --incremental) are:\n" | ||
3947 | 564 | " --run -R : Run arrays as soon as a minimal number of devices are\n" | ||
3948 | 565 | " : present rather than waiting for all expected.\n" | ||
3949 | 566 | " --quiet -q : Don't print any information messages, just errors.\n" | ||
3950 | 567 | " --rebuild-map -r : Rebuild the 'map' file that mdadm uses for tracking\n" | ||
3951 | 568 | " : partial arrays.\n" | ||
3952 | 569 | " --scan -s : Use with -R to start any arrays that have the minimal\n" | ||
3953 | 570 | " : required number of devices, but are not yet started.\n" | ||
3954 | 571 | " --fail -f : First fail (if needed) and then remove device from\n" | ||
3955 | 572 | " : any array that it is a member of.\n" | ||
3956 | 573 | ; | ||
3957 | 574 | |||
3958 | 575 | char Help_config[] = | ||
3959 | 576 | "The /etc/mdadm/mdadm.conf config file:\n\n" | ||
3960 | 577 | " The config file contains, apart from blank lines and comment lines that\n" | ||
3961 | 578 | " start with a hash(#), four sorts of configuration lines: array lines, \n" | ||
3962 | 579 | " device lines, mailaddr lines and program lines.\n" | ||
3963 | 580 | " Each configuration line is constructed of a number of space separated\n" | ||
3964 | 581 | " words, and can be continued on subsequent physical lines by indenting\n" | ||
3965 | 582 | " those lines.\n" | ||
3966 | 583 | "\n" | ||
3967 | 584 | " A device line starts with the word 'device' and then has a number of words\n" | ||
3968 | 585 | " which identify devices. These words should be names of devices in the\n" | ||
3969 | 586 | " filesystem, and can contain wildcards. There can be multiple words or each\n" | ||
3970 | 587 | " device line, and multiple device lines. All devices so listed are checked\n" | ||
3971 | 588 | " for relevant super blocks when assembling arrays.\n" | ||
3972 | 589 | "\n" | ||
3973 | 590 | " An array line start with the word 'array'. This is followed by the name of\n" | ||
3974 | 591 | " the array device in the filesystem, e.g. '/dev/md2'. Subsequent words\n" | ||
3975 | 592 | " describe the identity of the array, used to recognise devices to include in the\n" | ||
3976 | 593 | " array. The identity can be given as a UUID with a word starting 'uuid=', or\n" | ||
3977 | 594 | " as a minor-number stored in the superblock using 'super-minor=', or as a list\n" | ||
3978 | 595 | " of devices. This is given as a comma separated list of names, possibly\n" | ||
3979 | 596 | " containing wildcards, preceded by 'devices='. If multiple critea are given,\n" | ||
3980 | 597 | " than a device must match all of them to be considered.\n" | ||
3981 | 598 | "\n" | ||
3982 | 599 | " A mailaddr line starts with the word 'mailaddr' and should contain exactly\n" | ||
3983 | 600 | " one Email address. 'mdadm --monitor --scan' will send alerts of failed drives\n" | ||
3984 | 601 | " to this Email address." | ||
3985 | 602 | "\n" | ||
3986 | 603 | " A program line starts with the word 'program' and should contain exactly\n" | ||
3987 | 604 | " one program name. 'mdadm --monitor --scan' will run this program when any\n" | ||
3988 | 605 | " event is detected.\n" | ||
3989 | 606 | "\n" | ||
3990 | 607 | ; | ||
3991 | 608 | |||
3992 | 0 | 609 | ||
3993 | === removed file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c' | |||
3994 | --- .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c 2012-02-09 16:53:02 +0000 | |||
3995 | +++ .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/ReadMe.c 1970-01-01 00:00:00 +0000 | |||
3996 | @@ -1,602 +0,0 @@ | |||
3997 | 1 | /* | ||
3998 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. | ||
3999 | 3 | * | ||
4000 | 4 | * Copyright (C) 2001-2010 Neil Brown <neilb@suse.de> | ||
4001 | 5 | * | ||
4002 | 6 | * | ||
4003 | 7 | * This program is free software; you can redistribute it and/or modify | ||
4004 | 8 | * it under the terms of the GNU General Public License as published by | ||
4005 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
4006 | 10 | * (at your option) any later version. | ||
4007 | 11 | * | ||
4008 | 12 | * This program is distributed in the hope that it will be useful, | ||
4009 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4010 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4011 | 15 | * GNU General Public License for more details. | ||
4012 | 16 | * | ||
4013 | 17 | * You should have received a copy of the GNU General Public License | ||
4014 | 18 | * along with this program; if not, write to the Free Software | ||
4015 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
4016 | 20 | * | ||
4017 | 21 | * Author: Neil Brown | ||
4018 | 22 | * Email: <neilb@suse.de> | ||
4019 | 23 | */ | ||
4020 | 24 | |||
4021 | 25 | #include "mdadm.h" | ||
4022 | 26 | |||
4023 | 27 | char Version[] = Name " - v3.2.3 - 23rd December 2011\n"; | ||
4024 | 28 | |||
4025 | 29 | /* | ||
4026 | 30 | * File: ReadMe.c | ||
4027 | 31 | * | ||
4028 | 32 | * This file contains general comments about the implementation | ||
4029 | 33 | * and the various usage messages that can be displayed by mdadm | ||
4030 | 34 | * | ||
4031 | 35 | * mdadm is a single program that can be used to control Linux md devices. | ||
4032 | 36 | * It is intended to provide all the functionality of the mdtools and | ||
4033 | 37 | * raidtools but with a very different interface. | ||
4034 | 38 | * mdadm can perform all functions without a configuration file. | ||
4035 | 39 | * There is the option of using a configuration file, but not in the same | ||
4036 | 40 | * way that raidtools uses one | ||
4037 | 41 | * raidtools uses a configuration file to describe how to create a RAID | ||
4038 | 42 | * array, and also uses this file partially to start a previously | ||
4039 | 43 | * created RAID array. Further, raidtools requires the configuration | ||
4040 | 44 | * file for such things as stopping a raid array which needs to know | ||
4041 | 45 | * nothing about the array. | ||
4042 | 46 | * | ||
4043 | 47 | * The configuration file that can be used by mdadm lists two | ||
4044 | 48 | * different things: | ||
4045 | 49 | * 1/ a mapping from uuid to md device to identify which arrays are | ||
4046 | 50 | * expect and what names (numbers) they should be given | ||
4047 | 51 | * 2/ a list of devices that should be scanned for md sub-devices | ||
4048 | 52 | * | ||
4049 | 53 | * | ||
4050 | 54 | */ | ||
4051 | 55 | |||
4052 | 56 | /* | ||
4053 | 57 | * mdadm has 7 major modes of operation: | ||
4054 | 58 | * 1/ Create | ||
4055 | 59 | * This mode is used to create a new array with a superblock | ||
4056 | 60 | * It can progress in several step create-add-add-run | ||
4057 | 61 | * or it can all happen with one command | ||
4058 | 62 | * 2/ Assemble | ||
4059 | 63 | * This mode is used to assemble the parts of a previously created | ||
4060 | 64 | * array into an active array. Components can be explicitly given | ||
4061 | 65 | * or can be searched for. mdadm (optionally) check that the components | ||
4062 | 66 | * do form a bona-fide array, and can, on request, fiddle superblock | ||
4063 | 67 | * version numbers so as to assemble a faulty array. | ||
4064 | 68 | * 3/ Build | ||
4065 | 69 | * This is for building legacy arrays without superblocks | ||
4066 | 70 | * 4/ Manage | ||
4067 | 71 | * This is for doing something to one or more devices | ||
4068 | 72 | * in an array, such as add,remove,fail. | ||
4069 | 73 | * run/stop/readonly/readwrite are also available | ||
4070 | 74 | * 5/ Misc | ||
4071 | 75 | * This is for doing things to individual devices. | ||
4072 | 76 | * They might be parts of an array so | ||
4073 | 77 | * zero-superblock, examine might be appropriate | ||
4074 | 78 | * They might be md arrays so | ||
4075 | 79 | * run,stop,rw,ro,detail might be appropriate | ||
4076 | 80 | * Also query will treat it as either | ||
4077 | 81 | * 6/ Monitor | ||
4078 | 82 | * This mode never exits but just monitors arrays and reports changes. | ||
4079 | 83 | * 7/ Grow | ||
4080 | 84 | * This mode allows for changing of key attributes of a raid array, such | ||
4081 | 85 | * as size, number of devices, and possibly even layout. | ||
4082 | 86 | * At the time if writing, there is only minimal support. | ||
4083 | 87 | */ | ||
4084 | 88 | |||
4085 | 89 | char short_options[]="-ABCDEFGIQhVXYWZ:vqbc:i:l:p:m:n:x:u:c:d:z:U:N:sarfRSow1tye:"; | ||
4086 | 90 | char short_bitmap_options[]= | ||
4087 | 91 | "-ABCDEFGIQhVXYWZ:vqb:c:i:l:p:m:n:x:u:c:d:z:U:N:sarfRSow1tye:"; | ||
4088 | 92 | char short_bitmap_auto_options[]= | ||
4089 | 93 | "-ABCDEFGIQhVXYWZ:vqb:c:i:l:p:m:n:x:u:c:d:z:U:N:sa:rfRSow1tye:"; | ||
4090 | 94 | |||
4091 | 95 | struct option long_options[] = { | ||
4092 | 96 | {"manage", 0, 0, ManageOpt}, | ||
4093 | 97 | {"misc", 0, 0, MiscOpt}, | ||
4094 | 98 | {"assemble", 0, 0, 'A'}, | ||
4095 | 99 | {"build", 0, 0, 'B'}, | ||
4096 | 100 | {"create", 0, 0, 'C'}, | ||
4097 | 101 | {"detail", 0, 0, 'D'}, | ||
4098 | 102 | {"examine", 0, 0, 'E'}, | ||
4099 | 103 | {"follow", 0, 0, 'F'}, | ||
4100 | 104 | {"grow", 0, 0, 'G'}, | ||
4101 | 105 | {"incremental",0,0, 'I'}, | ||
4102 | 106 | {"zero-superblock", 0, 0, 'K'}, /* deliberately no a short_option */ | ||
4103 | 107 | {"query", 0, 0, 'Q'}, | ||
4104 | 108 | {"examine-bitmap", 0, 0, 'X'}, | ||
4105 | 109 | {"auto-detect", 0, 0, AutoDetect}, | ||
4106 | 110 | {"detail-platform", 0, 0, DetailPlatform}, | ||
4107 | 111 | {"kill-subarray", 1, 0, KillSubarray}, | ||
4108 | 112 | {"update-subarray", 1, 0, UpdateSubarray}, | ||
4109 | 113 | {"udev-rules", 2, 0, UdevRules}, | ||
4110 | 114 | |||
4111 | 115 | /* synonyms */ | ||
4112 | 116 | {"monitor", 0, 0, 'F'}, | ||
4113 | 117 | |||
4114 | 118 | /* after those will normally come the name of the md device */ | ||
4115 | 119 | {"help", 0, 0, 'h'}, | ||
4116 | 120 | {"help-options",0,0, HelpOptions}, | ||
4117 | 121 | {"version", 0, 0, 'V'}, | ||
4118 | 122 | {"verbose", 0, 0, 'v'}, | ||
4119 | 123 | {"quiet", 0, 0, 'q'}, | ||
4120 | 124 | |||
4121 | 125 | /* For create or build: */ | ||
4122 | 126 | {"chunk", 1, 0, ChunkSize}, | ||
4123 | 127 | {"rounding", 1, 0, ChunkSize}, /* for linear, chunk is really a | ||
4124 | 128 | * rounding number */ | ||
4125 | 129 | {"level", 1, 0, 'l'}, /* 0,1,4,5,6,linear */ | ||
4126 | 130 | {"parity", 1, 0, Layout}, /* {left,right}-{a,}symmetric */ | ||
4127 | 131 | {"layout", 1, 0, Layout}, | ||
4128 | 132 | {"raid-disks",1, 0, 'n'}, | ||
4129 | 133 | {"raid-devices",1, 0, 'n'}, | ||
4130 | 134 | {"spare-disks",1,0, 'x'}, | ||
4131 | 135 | {"spare-devices",1,0, 'x'}, | ||
4132 | 136 | {"size", 1, 0, 'z'}, | ||
4133 | 137 | {"auto", 1, 0, Auto}, /* also for --assemble */ | ||
4134 | 138 | {"assume-clean",0,0, AssumeClean }, | ||
4135 | 139 | {"metadata", 1, 0, 'e'}, /* superblock format */ | ||
4136 | 140 | {"bitmap", 1, 0, Bitmap}, | ||
4137 | 141 | {"bitmap-chunk", 1, 0, BitmapChunk}, | ||
4138 | 142 | {"write-behind", 2, 0, WriteBehind}, | ||
4139 | 143 | {"write-mostly",0, 0, WriteMostly}, | ||
4140 | 144 | {"re-add", 0, 0, ReAdd}, | ||
4141 | 145 | {"homehost", 1, 0, HomeHost}, | ||
4142 | 146 | {"symlinks", 1, 0, Symlinks}, | ||
4143 | 147 | |||
4144 | 148 | /* For assemble */ | ||
4145 | 149 | {"uuid", 1, 0, 'u'}, | ||
4146 | 150 | {"super-minor",1,0, SuperMinor}, | ||
4147 | 151 | {"name", 1, 0, 'N'}, | ||
4148 | 152 | {"config", 1, 0, ConfigFile}, | ||
4149 | 153 | {"scan", 0, 0, 's'}, | ||
4150 | 154 | {"force", 0, 0, Force}, | ||
4151 | 155 | {"update", 1, 0, 'U'}, | ||
4152 | 156 | {"freeze-reshape", 0, 0, FreezeReshape}, | ||
4153 | 157 | |||
4154 | 158 | /* Management */ | ||
4155 | 159 | {"add", 0, 0, Add}, | ||
4156 | 160 | {"remove", 0, 0, Remove}, | ||
4157 | 161 | {"fail", 0, 0, Fail}, | ||
4158 | 162 | {"set-faulty",0, 0, Fail}, | ||
4159 | 163 | {"run", 0, 0, 'R'}, | ||
4160 | 164 | {"stop", 0, 0, 'S'}, | ||
4161 | 165 | {"readonly", 0, 0, 'o'}, | ||
4162 | 166 | {"readwrite", 0, 0, 'w'}, | ||
4163 | 167 | {"no-degraded",0,0, NoDegraded }, | ||
4164 | 168 | {"wait", 0, 0, WaitOpt}, | ||
4165 | 169 | {"wait-clean", 0, 0, Waitclean }, | ||
4166 | 170 | |||
4167 | 171 | /* For Detail/Examine */ | ||
4168 | 172 | {"brief", 0, 0, Brief}, | ||
4169 | 173 | {"export", 0, 0, 'Y'}, | ||
4170 | 174 | {"sparc2.2", 0, 0, Sparc22}, | ||
4171 | 175 | {"test", 0, 0, 't'}, | ||
4172 | 176 | |||
4173 | 177 | /* For Follow/monitor */ | ||
4174 | 178 | {"mail", 1, 0, EMail}, | ||
4175 | 179 | {"program", 1, 0, ProgramOpt}, | ||
4176 | 180 | {"alert", 1, 0, ProgramOpt}, | ||
4177 | 181 | {"increment", 1, 0, Increment}, | ||
4178 | 182 | {"delay", 1, 0, 'd'}, | ||
4179 | 183 | {"daemonise", 0, 0, Fork}, | ||
4180 | 184 | {"daemonize", 0, 0, Fork}, | ||
4181 | 185 | {"oneshot", 0, 0, '1'}, | ||
4182 | 186 | {"pid-file", 1, 0, 'i'}, | ||
4183 | 187 | {"syslog", 0, 0, 'y'}, | ||
4184 | 188 | {"no-sharing", 0, 0, NoSharing}, | ||
4185 | 189 | |||
4186 | 190 | /* For Grow */ | ||
4187 | 191 | {"backup-file", 1,0, BackupFile}, | ||
4188 | 192 | {"invalid-backup",0,0,InvalidBackup}, | ||
4189 | 193 | {"array-size", 1, 0, 'Z'}, | ||
4190 | 194 | {"continue", 0, 0, Continue}, | ||
4191 | 195 | |||
4192 | 196 | /* For Incremental */ | ||
4193 | 197 | {"rebuild-map", 0, 0, RebuildMapOpt}, | ||
4194 | 198 | {"path", 1, 0, IncrementalPath}, | ||
4195 | 199 | |||
4196 | 200 | {0, 0, 0, 0} | ||
4197 | 201 | }; | ||
4198 | 202 | |||
4199 | 203 | char Usage[] = | ||
4200 | 204 | "Usage: mdadm --help\n" | ||
4201 | 205 | " for help\n" | ||
4202 | 206 | ; | ||
4203 | 207 | |||
4204 | 208 | char Help[] = | ||
4205 | 209 | "mdadm is used for building, managing, and monitoring\n" | ||
4206 | 210 | "Linux md devices (aka RAID arrays)\n" | ||
4207 | 211 | "Usage: mdadm --create device options...\n" | ||
4208 | 212 | " Create a new array from unused devices.\n" | ||
4209 | 213 | " mdadm --assemble device options...\n" | ||
4210 | 214 | " Assemble a previously created array.\n" | ||
4211 | 215 | " mdadm --build device options...\n" | ||
4212 | 216 | " Create or assemble an array without metadata.\n" | ||
4213 | 217 | " mdadm --manage device options...\n" | ||
4214 | 218 | " make changes to an existing array.\n" | ||
4215 | 219 | " mdadm --misc options... devices\n" | ||
4216 | 220 | " report on or modify various md related devices.\n" | ||
4217 | 221 | " mdadm --grow options device\n" | ||
4218 | 222 | " resize/reshape an active array\n" | ||
4219 | 223 | " mdadm --incremental device\n" | ||
4220 | 224 | " add/remove a device to/from an array as appropriate\n" | ||
4221 | 225 | " mdadm --monitor options...\n" | ||
4222 | 226 | " Monitor one or more array for significant changes.\n" | ||
4223 | 227 | " mdadm device options...\n" | ||
4224 | 228 | " Shorthand for --manage.\n" | ||
4225 | 229 | "Any parameter that does not start with '-' is treated as a device name\n" | ||
4226 | 230 | "or, for --examine-bitmap, a file name.\n" | ||
4227 | 231 | "The first such name is often the name of an md device. Subsequent\n" | ||
4228 | 232 | "names are often names of component devices.\n" | ||
4229 | 233 | "\n" | ||
4230 | 234 | " For detailed help on the above major modes use --help after the mode\n" | ||
4231 | 235 | " e.g.\n" | ||
4232 | 236 | " mdadm --assemble --help\n" | ||
4233 | 237 | " For general help on options use\n" | ||
4234 | 238 | " mdadm --help-options\n" | ||
4235 | 239 | ; | ||
4236 | 240 | |||
4237 | 241 | char OptionHelp[] = | ||
4238 | 242 | "Any parameter that does not start with '-' is treated as a device name\n" | ||
4239 | 243 | "or, for --examine-bitmap, a file name.\n" | ||
4240 | 244 | "The first such name is often the name of an md device. Subsequent\n" | ||
4241 | 245 | "names are often names of component devices.\n" | ||
4242 | 246 | "\n" | ||
4243 | 247 | "Some common options are:\n" | ||
4244 | 248 | " --help -h : General help message or, after above option,\n" | ||
4245 | 249 | " mode specific help message\n" | ||
4246 | 250 | " --help-options : This help message\n" | ||
4247 | 251 | " --version -V : Print version information for mdadm\n" | ||
4248 | 252 | " --verbose -v : Be more verbose about what is happening\n" | ||
4249 | 253 | " --quiet -q : Don't print un-necessary messages\n" | ||
4250 | 254 | " --brief -b : Be less verbose, more brief\n" | ||
4251 | 255 | " --export -Y : With --detail, use key=value format for easy\n" | ||
4252 | 256 | " import into environment\n" | ||
4253 | 257 | " --force -f : Override normal checks and be more forceful\n" | ||
4254 | 258 | "\n" | ||
4255 | 259 | " --assemble -A : Assemble an array\n" | ||
4256 | 260 | " --build -B : Build an array without metadata\n" | ||
4257 | 261 | " --create -C : Create a new array\n" | ||
4258 | 262 | " --detail -D : Display details of an array\n" | ||
4259 | 263 | " --examine -E : Examine superblock on an array component\n" | ||
4260 | 264 | " --examine-bitmap -X: Display the detail of a bitmap file\n" | ||
4261 | 265 | " --monitor -F : monitor (follow) some arrays\n" | ||
4262 | 266 | " --grow -G : resize/ reshape and array\n" | ||
4263 | 267 | " --incremental -I : add/remove a single device to/from an array as appropriate\n" | ||
4264 | 268 | " --query -Q : Display general information about how a\n" | ||
4265 | 269 | " device relates to the md driver\n" | ||
4266 | 270 | " --auto-detect : Start arrays auto-detected by the kernel\n" | ||
4267 | 271 | ; | ||
4268 | 272 | /* | ||
4269 | 273 | "\n" | ||
4270 | 274 | " For create or build:\n" | ||
4271 | 275 | " --bitmap= -b : File to store bitmap in - may pre-exist for --build\n" | ||
4272 | 276 | " --chunk= -c : chunk size of kibibytes\n" | ||
4273 | 277 | " --rounding= : rounding factor for linear array (==chunk size)\n" | ||
4274 | 278 | " --level= -l : raid level: 0,1,4,5,6,linear,mp. 0 or linear for build\n" | ||
4275 | 279 | " --parity= -p : raid5/6 parity algorithm: {left,right}-{,a}symmetric\n" | ||
4276 | 280 | " --layout= : same as --parity\n" | ||
4277 | 281 | " --raid-devices= -n : number of active devices in array\n" | ||
4278 | 282 | " --spare-devices= -x: number of spares (eXtras) devices in initial array\n" | ||
4279 | 283 | " --size= -z : Size (in K) of each drive in RAID1/4/5/6/10 - optional\n" | ||
4280 | 284 | " --force -f : Honour devices as listed on command line. Don't\n" | ||
4281 | 285 | " : insert a missing drive for RAID5.\n" | ||
4282 | 286 | " --assume-clean : Assume the array is already in-sync. This is dangerous.\n" | ||
4283 | 287 | " --bitmap-chunk= : chunksize of bitmap in bitmap file (Kilobytes)\n" | ||
4284 | 288 | " --delay= -d : seconds between bitmap updates\n" | ||
4285 | 289 | " --write-behind= : number of simultaneous write-behind requests to allow (requires bitmap)\n" | ||
4286 | 290 | " --name= -N : Textual name for array - max 32 characters\n" | ||
4287 | 291 | "\n" | ||
4288 | 292 | " For assemble:\n" | ||
4289 | 293 | " --bitmap= -b : File to find bitmap information in\n" | ||
4290 | 294 | " --uuid= -u : uuid of array to assemble. Devices which don't\n" | ||
4291 | 295 | " have this uuid are excluded\n" | ||
4292 | 296 | " --super-minor= -m : minor number to look for in super-block when\n" | ||
4293 | 297 | " choosing devices to use.\n" | ||
4294 | 298 | " --name= -N : Array name to look for in super-block.\n" | ||
4295 | 299 | " --config= -c : config file\n" | ||
4296 | 300 | " --scan -s : scan config file for missing information\n" | ||
4297 | 301 | " --force -f : Assemble the array even if some superblocks appear out-of-date\n" | ||
4298 | 302 | " --update= -U : Update superblock: try '-A --update=?' for list of options.\n" | ||
4299 | 303 | " --no-degraded : Do not start any degraded arrays - default unless --scan.\n" | ||
4300 | 304 | "\n" | ||
4301 | 305 | " For detail or examine:\n" | ||
4302 | 306 | " --brief -b : Just print device name and UUID\n" | ||
4303 | 307 | "\n" | ||
4304 | 308 | " For follow/monitor:\n" | ||
4305 | 309 | " --mail= -m : Address to mail alerts of failure to\n" | ||
4306 | 310 | " --program= -p : Program to run when an event is detected\n" | ||
4307 | 311 | " --alert= : same as --program\n" | ||
4308 | 312 | " --delay= -d : seconds of delay between polling state. default=60\n" | ||
4309 | 313 | "\n" | ||
4310 | 314 | " General management:\n" | ||
4311 | 315 | " --add -a : add, or hotadd subsequent devices\n" | ||
4312 | 316 | " --remove -r : remove subsequent devices\n" | ||
4313 | 317 | " --fail -f : mark subsequent devices a faulty\n" | ||
4314 | 318 | " --set-faulty : same as --fail\n" | ||
4315 | 319 | " --run -R : start a partially built array\n" | ||
4316 | 320 | " --stop -S : deactivate array, releasing all resources\n" | ||
4317 | 321 | " --readonly -o : mark array as readonly\n" | ||
4318 | 322 | " --readwrite -w : mark array as readwrite\n" | ||
4319 | 323 | " --zero-superblock : erase the MD superblock from a device.\n" | ||
4320 | 324 | " --wait -W : wait for recovery/resync/reshape to finish.\n" | ||
4321 | 325 | ; | ||
4322 | 326 | */ | ||
4323 | 327 | |||
4324 | 328 | char Help_create[] = | ||
4325 | 329 | "Usage: mdadm --create device -chunk=X --level=Y --raid-devices=Z devices\n" | ||
4326 | 330 | "\n" | ||
4327 | 331 | " This usage will initialise a new md array, associate some\n" | ||
4328 | 332 | " devices with it, and activate the array. In order to create an\n" | ||
4329 | 333 | " array with some devices missing, use the special word 'missing' in\n" | ||
4330 | 334 | " place of the relevant device name.\n" | ||
4331 | 335 | "\n" | ||
4332 | 336 | " Before devices are added, they are checked to see if they already contain\n" | ||
4333 | 337 | " raid superblocks or filesystems. They are also checked to see if\n" | ||
4334 | 338 | " the variance in device size exceeds 1%.\n" | ||
4335 | 339 | " If any discrepancy is found, the user will be prompted for confirmation\n" | ||
4336 | 340 | " before the array is created. The presence of a '--run' can override this\n" | ||
4337 | 341 | " caution.\n" | ||
4338 | 342 | "\n" | ||
4339 | 343 | " If the --size option is given then only that many kilobytes of each\n" | ||
4340 | 344 | " device is used, no matter how big each device is.\n" | ||
4341 | 345 | " If no --size is given, the apparent size of the smallest drive given\n" | ||
4342 | 346 | " is used for raid level 1 and greater, and the full device is used for\n" | ||
4343 | 347 | " other levels.\n" | ||
4344 | 348 | "\n" | ||
4345 | 349 | " Options that are valid with --create (-C) are:\n" | ||
4346 | 350 | " --bitmap= : Create a bitmap for the array with the given filename\n" | ||
4347 | 351 | " --chunk= -c : chunk size of kibibytes\n" | ||
4348 | 352 | " --rounding= : rounding factor for linear array (==chunk size)\n" | ||
4349 | 353 | " --level= -l : raid level: 0,1,4,5,6,linear,multipath and synonyms\n" | ||
4350 | 354 | " --parity= -p : raid5/6 parity algorithm: {left,right}-{,a}symmetric\n" | ||
4351 | 355 | " --layout= : same as --parity\n" | ||
4352 | 356 | " --raid-devices= -n : number of active devices in array\n" | ||
4353 | 357 | " --spare-devices= -x: number of spares (eXtras) devices in initial array\n" | ||
4354 | 358 | " --size= -z : Size (in K) of each drive in RAID1/4/5/6/10 - optional\n" | ||
4355 | 359 | " --force -f : Honour devices as listed on command line. Don't\n" | ||
4356 | 360 | " : insert a missing drive for RAID5.\n" | ||
4357 | 361 | " --run -R : insist of running the array even if not all\n" | ||
4358 | 362 | " : devices are present or some look odd.\n" | ||
4359 | 363 | " --readonly -o : start the array readonly - not supported yet.\n" | ||
4360 | 364 | " --name= -N : Textual name for array - max 32 characters\n" | ||
4361 | 365 | " --bitmap-chunk= : bitmap chunksize in Kilobytes.\n" | ||
4362 | 366 | " --delay= -d : bitmap update delay in seconds.\n" | ||
4363 | 367 | "\n" | ||
4364 | 368 | ; | ||
4365 | 369 | |||
4366 | 370 | char Help_build[] = | ||
4367 | 371 | "Usage: mdadm --build device -chunk=X --level=Y --raid-devices=Z devices\n" | ||
4368 | 372 | "\n" | ||
4369 | 373 | " This usage is similar to --create. The difference is that it creates\n" | ||
4370 | 374 | " a legacy array without a superblock. With these arrays there is no\n" | ||
4371 | 375 | " different between initially creating the array and subsequently\n" | ||
4372 | 376 | " assembling the array, except that hopefully there is useful data\n" | ||
4373 | 377 | " there in the second case.\n" | ||
4374 | 378 | "\n" | ||
4375 | 379 | " The level may only be 0, raid0, or linear.\n" | ||
4376 | 380 | " All devices must be listed and the array will be started once complete.\n" | ||
4377 | 381 | " Options that are valid with --build (-B) are:\n" | ||
4378 | 382 | " --bitmap= : file to store/find bitmap information in.\n" | ||
4379 | 383 | " --chunk= -c : chunk size of kibibytes\n" | ||
4380 | 384 | " --rounding= : rounding factor for linear array (==chunk size)\n" | ||
4381 | 385 | " --level= -l : 0, raid0, or linear\n" | ||
4382 | 386 | " --raid-devices= -n : number of active devices in array\n" | ||
4383 | 387 | " --bitmap-chunk= : bitmap chunksize in Kilobytes.\n" | ||
4384 | 388 | " --delay= -d : bitmap update delay in seconds.\n" | ||
4385 | 389 | ; | ||
4386 | 390 | |||
4387 | 391 | char Help_assemble[] = | ||
4388 | 392 | "Usage: mdadm --assemble device options...\n" | ||
4389 | 393 | " mdadm --assemble --scan options...\n" | ||
4390 | 394 | "\n" | ||
4391 | 395 | "This usage assembles one or more raid arrays from pre-existing\n" | ||
4392 | 396 | "components.\n" | ||
4393 | 397 | "For each array, mdadm needs to know the md device, the identity of\n" | ||
4394 | 398 | "the array, and a number of sub devices. These can be found in a number\n" | ||
4395 | 399 | "of ways.\n" | ||
4396 | 400 | "\n" | ||
4397 | 401 | "The md device is either given on the command line or is found listed\n" | ||
4398 | 402 | "in the config file. The array identity is determined either from the\n" | ||
4399 | 403 | "--uuid or --super-minor commandline arguments, from the config file,\n" | ||
4400 | 404 | "or from the first component device on the command line.\n" | ||
4401 | 405 | "\n" | ||
4402 | 406 | "The different combinations of these are as follows:\n" | ||
4403 | 407 | " If the --scan option is not given, then only devices and identities\n" | ||
4404 | 408 | " listed on the command line are considered.\n" | ||
4405 | 409 | " The first device will be the array device, and the remainder will be\n" | ||
4406 | 410 | " examined when looking for components.\n" | ||
4407 | 411 | " If an explicit identity is given with --uuid or --super-minor, then\n" | ||
4408 | 412 | " only devices with a superblock which matches that identity is considered,\n" | ||
4409 | 413 | " otherwise every device listed is considered.\n" | ||
4410 | 414 | "\n" | ||
4411 | 415 | " If the --scan option is given, and no devices are listed, then\n" | ||
4412 | 416 | " every array listed in the config file is considered for assembly.\n" | ||
4413 | 417 | " The identity of candidate devices are determined from the config file.\n" | ||
4414 | 418 | "\n" | ||
4415 | 419 | " If the --scan option is given as well as one or more devices, then\n" | ||
4416 | 420 | " Those devices are md devices that are to be assembled. Their identity\n" | ||
4417 | 421 | " and components are determined from the config file.\n" | ||
4418 | 422 | "\n" | ||
4419 | 423 | " If mdadm can not find all of the components for an array, it will assemble\n" | ||
4420 | 424 | " it but not activate it unless --run or --scan is given. To preserve this\n" | ||
4421 | 425 | " behaviour even with --scan, add --no-degraded. Note that \"all of the\n" | ||
4422 | 426 | " components\" means as many as were present the last time the array was running\n" | ||
4423 | 427 | " as recorded in the superblock. If the array was already degraded, and\n" | ||
4424 | 428 | " the missing device is not a new problem, it will still be assembled. It\n" | ||
4425 | 429 | " is only newly missing devices that cause the array not to be started.\n" | ||
4426 | 430 | "\n" | ||
4427 | 431 | "Options that are valid with --assemble (-A) are:\n" | ||
4428 | 432 | " --bitmap= : bitmap file to use wit the array\n" | ||
4429 | 433 | " --uuid= -u : uuid of array to assemble. Devices which don't\n" | ||
4430 | 434 | " have this uuid are excluded\n" | ||
4431 | 435 | " --super-minor= -m : minor number to look for in super-block when\n" | ||
4432 | 436 | " choosing devices to use.\n" | ||
4433 | 437 | " --name= -N : Array name to look for in super-block.\n" | ||
4434 | 438 | " --config= -c : config file\n" | ||
4435 | 439 | " --scan -s : scan config file for missing information\n" | ||
4436 | 440 | " --run -R : Try to start the array even if not enough devices\n" | ||
4437 | 441 | " for a full array are present\n" | ||
4438 | 442 | " --force -f : Assemble the array even if some superblocks appear\n" | ||
4439 | 443 | " : out-of-date. This involves modifying the superblocks.\n" | ||
4440 | 444 | " --update= -U : Update superblock: try '-A --update=?' for option list.\n" | ||
4441 | 445 | " --no-degraded : Assemble but do not start degraded arrays.\n" | ||
4442 | 446 | ; | ||
4443 | 447 | |||
4444 | 448 | char Help_manage[] = | ||
4445 | 449 | "Usage: mdadm arraydevice options component devices...\n" | ||
4446 | 450 | "\n" | ||
4447 | 451 | "This usage is for managing the component devices within an array.\n" | ||
4448 | 452 | "The --manage option is not needed and is assumed if the first argument\n" | ||
4449 | 453 | "is a device name or a management option.\n" | ||
4450 | 454 | "The first device listed will be taken to be an md array device, and\n" | ||
4451 | 455 | "subsequent devices are (potential) components of that array.\n" | ||
4452 | 456 | "\n" | ||
4453 | 457 | "Options that are valid with management mode are:\n" | ||
4454 | 458 | " --add -a : hotadd subsequent devices to the array\n" | ||
4455 | 459 | " --remove -r : remove subsequent devices, which must not be active\n" | ||
4456 | 460 | " --fail -f : mark subsequent devices a faulty\n" | ||
4457 | 461 | " --set-faulty : same as --fail\n" | ||
4458 | 462 | " --run -R : start a partially built array\n" | ||
4459 | 463 | " --stop -S : deactivate array, releasing all resources\n" | ||
4460 | 464 | " --readonly -o : mark array as readonly\n" | ||
4461 | 465 | " --readwrite -w : mark array as readwrite\n" | ||
4462 | 466 | ; | ||
4463 | 467 | |||
4464 | 468 | char Help_misc[] = | ||
4465 | 469 | "Usage: mdadm misc_option devices...\n" | ||
4466 | 470 | "\n" | ||
4467 | 471 | "This usage is for performing some task on one or more devices, which\n" | ||
4468 | 472 | "may be arrays or components, depending on the task.\n" | ||
4469 | 473 | "The --misc option is not needed (though it is allowed) and is assumed\n" | ||
4470 | 474 | "if the first argument in a misc option.\n" | ||
4471 | 475 | "\n" | ||
4472 | 476 | "Options that are valid with the miscellaneous mode are:\n" | ||
4473 | 477 | " --query -Q : Display general information about how a\n" | ||
4474 | 478 | " device relates to the md driver\n" | ||
4475 | 479 | " --detail -D : Display details of an array\n" | ||
4476 | 480 | " --detail-platform : Display hardware/firmware details\n" | ||
4477 | 481 | " --examine -E : Examine superblock on an array component\n" | ||
4478 | 482 | " --examine-bitmap -X: Display contents of a bitmap file\n" | ||
4479 | 483 | " --zero-superblock : erase the MD superblock from a device.\n" | ||
4480 | 484 | " --run -R : start a partially built array\n" | ||
4481 | 485 | " --stop -S : deactivate array, releasing all resources\n" | ||
4482 | 486 | " --readonly -o : mark array as readonly\n" | ||
4483 | 487 | " --readwrite -w : mark array as readwrite\n" | ||
4484 | 488 | " --test -t : exit status 0 if ok, 1 if degrade, 2 if dead, 4 if missing\n" | ||
4485 | 489 | " --wait -W : wait for resync/rebuild/recovery to finish\n" | ||
4486 | 490 | ; | ||
4487 | 491 | |||
4488 | 492 | char Help_monitor[] = | ||
4489 | 493 | "Usage: mdadm --monitor options devices\n" | ||
4490 | 494 | "\n" | ||
4491 | 495 | "This usage causes mdadm to monitor a number of md arrays by periodically\n" | ||
4492 | 496 | "polling their status and acting on any changes.\n" | ||
4493 | 497 | "If any devices are listed then those devices are monitored, otherwise\n" | ||
4494 | 498 | "all devices listed in the config file are monitored.\n" | ||
4495 | 499 | "The address for mailing advisories to, and the program to handle\n" | ||
4496 | 500 | "each change can be specified in the config file or on the command line.\n" | ||
4497 | 501 | "If no mail address or program are specified, then mdadm reports all\n" | ||
4498 | 502 | "state changes to stdout.\n" | ||
4499 | 503 | "\n" | ||
4500 | 504 | "Options that are valid with the monitor (-F --follow) mode are:\n" | ||
4501 | 505 | " --mail= -m : Address to mail alerts of failure to\n" | ||
4502 | 506 | " --program= -p : Program to run when an event is detected\n" | ||
4503 | 507 | " --alert= : same as --program\n" | ||
4504 | 508 | " --syslog -y : Report alerts via syslog\n" | ||
4505 | 509 | " --increment= -r : Report RebuildNN events in the given increment. default=20\n" | ||
4506 | 510 | " --delay= -d : seconds of delay between polling state. default=60\n" | ||
4507 | 511 | " --config= -c : specify a different config file\n" | ||
4508 | 512 | " --scan -s : find mail-address/program in config file\n" | ||
4509 | 513 | " --daemonise -f : Fork and continue in child, parent exits\n" | ||
4510 | 514 | " --pid-file= -i : In daemon mode write pid to specified file instead of stdout\n" | ||
4511 | 515 | " --oneshot -1 : Check for degraded arrays, then exit\n" | ||
4512 | 516 | " --test -t : Generate a TestMessage event against each array at startup\n" | ||
4513 | 517 | ; | ||
4514 | 518 | |||
4515 | 519 | char Help_grow[] = | ||
4516 | 520 | "Usage: mdadm --grow device options\n" | ||
4517 | 521 | "\n" | ||
4518 | 522 | "This usage causes mdadm to attempt to reconfigure a running array.\n" | ||
4519 | 523 | "This is only possibly if the kernel being used supports a particular\n" | ||
4520 | 524 | "reconfiguration. This version supports changing the number of\n" | ||
4521 | 525 | "devices in a RAID1/5/6, changing the active size of all devices in\n" | ||
4522 | 526 | "a RAID1/4/5/6, adding or removing a write-intent bitmap, and changing\n" | ||
4523 | 527 | "the error mode for a 'FAULTY' array.\n" | ||
4524 | 528 | "\n" | ||
4525 | 529 | "Options that are valid with the grow (-G --grow) mode are:\n" | ||
4526 | 530 | " --level= -l : Tell mdadm what level the array is so that it can\n" | ||
4527 | 531 | " : interpret '--layout' properly.\n" | ||
4528 | 532 | " --layout= -p : For a FAULTY array, set/change the error mode.\n" | ||
4529 | 533 | " --size= -z : Change the active size of devices in an array.\n" | ||
4530 | 534 | " : This is useful if all devices have been replaced\n" | ||
4531 | 535 | " : with larger devices. Value is in Kilobytes, or\n" | ||
4532 | 536 | " : the special word 'max' meaning 'as large as possible'.\n" | ||
4533 | 537 | " --raid-devices= -n : Change the number of active devices in an array.\n" | ||
4534 | 538 | " --bitmap= -b : Add or remove a write-intent bitmap.\n" | ||
4535 | 539 | " --backup-file= file : A file on a differt device to store data for a\n" | ||
4536 | 540 | " : short time while increasing raid-devices on a\n" | ||
4537 | 541 | " : RAID4/5/6 array. Not needed when a spare is present.\n" | ||
4538 | 542 | " --array-size= -Z : Change visible size of array. This does not change\n" | ||
4539 | 543 | " : any data on the device, and is not stable across restarts.\n" | ||
4540 | 544 | ; | ||
4541 | 545 | |||
4542 | 546 | char Help_incr[] = | ||
4543 | 547 | "Usage: mdadm --incremental [-Rqrsf] device\n" | ||
4544 | 548 | "\n" | ||
4545 | 549 | "This usage allows for incremental assembly of md arrays. Devices can be\n" | ||
4546 | 550 | "added one at a time as they are discovered. Once an array has all expected\n" | ||
4547 | 551 | "devices, it will be started.\n" | ||
4548 | 552 | "\n" | ||
4549 | 553 | "Optionally, the process can be reversed by using the fail option.\n" | ||
4550 | 554 | "When fail mode is invoked, mdadm will see if the device belongs to an array\n" | ||
4551 | 555 | "and then both fail (if needed) and remove the device from that array.\n" | ||
4552 | 556 | "\n" | ||
4553 | 557 | "Options that are valid with incremental assembly (-I --incremental) are:\n" | ||
4554 | 558 | " --run -R : Run arrays as soon as a minimal number of devices are\n" | ||
4555 | 559 | " : present rather than waiting for all expected.\n" | ||
4556 | 560 | " --quiet -q : Don't print any information messages, just errors.\n" | ||
4557 | 561 | " --rebuild-map -r : Rebuild the 'map' file that mdadm uses for tracking\n" | ||
4558 | 562 | " : partial arrays.\n" | ||
4559 | 563 | " --scan -s : Use with -R to start any arrays that have the minimal\n" | ||
4560 | 564 | " : required number of devices, but are not yet started.\n" | ||
4561 | 565 | " --fail -f : First fail (if needed) and then remove device from\n" | ||
4562 | 566 | " : any array that it is a member of.\n" | ||
4563 | 567 | ; | ||
4564 | 568 | |||
4565 | 569 | char Help_config[] = | ||
4566 | 570 | "The /etc/mdadm/mdadm.conf config file:\n\n" | ||
4567 | 571 | " The config file contains, apart from blank lines and comment lines that\n" | ||
4568 | 572 | " start with a hash(#), four sorts of configuration lines: array lines, \n" | ||
4569 | 573 | " device lines, mailaddr lines and program lines.\n" | ||
4570 | 574 | " Each configuration line is constructed of a number of space separated\n" | ||
4571 | 575 | " words, and can be continued on subsequent physical lines by indenting\n" | ||
4572 | 576 | " those lines.\n" | ||
4573 | 577 | "\n" | ||
4574 | 578 | " A device line starts with the word 'device' and then has a number of words\n" | ||
4575 | 579 | " which identify devices. These words should be names of devices in the\n" | ||
4576 | 580 | " filesystem, and can contain wildcards. There can be multiple words or each\n" | ||
4577 | 581 | " device line, and multiple device lines. All devices so listed are checked\n" | ||
4578 | 582 | " for relevant super blocks when assembling arrays.\n" | ||
4579 | 583 | "\n" | ||
4580 | 584 | " An array line start with the word 'array'. This is followed by the name of\n" | ||
4581 | 585 | " the array device in the filesystem, e.g. '/dev/md2'. Subsequent words\n" | ||
4582 | 586 | " describe the identity of the array, used to recognise devices to include in the\n" | ||
4583 | 587 | " array. The identity can be given as a UUID with a word starting 'uuid=', or\n" | ||
4584 | 588 | " as a minor-number stored in the superblock using 'super-minor=', or as a list\n" | ||
4585 | 589 | " of devices. This is given as a comma separated list of names, possibly\n" | ||
4586 | 590 | " containing wildcards, preceded by 'devices='. If multiple critea are given,\n" | ||
4587 | 591 | " than a device must match all of them to be considered.\n" | ||
4588 | 592 | "\n" | ||
4589 | 593 | " A mailaddr line starts with the word 'mailaddr' and should contain exactly\n" | ||
4590 | 594 | " one Email address. 'mdadm --monitor --scan' will send alerts of failed drives\n" | ||
4591 | 595 | " to this Email address." | ||
4592 | 596 | "\n" | ||
4593 | 597 | " A program line starts with the word 'program' and should contain exactly\n" | ||
4594 | 598 | " one program name. 'mdadm --monitor --scan' will run this program when any\n" | ||
4595 | 599 | " event is detected.\n" | ||
4596 | 600 | "\n" | ||
4597 | 601 | ; | ||
4598 | 602 | |||
4599 | 603 | 0 | ||
4600 | === added directory '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/check.d' | |||
4601 | === removed directory '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/check.d' | |||
4602 | === added file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/check.d/_numbers' | |||
4603 | === removed file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/check.d/_numbers' | |||
4604 | === added file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/check.d/root_on_raid' | |||
4605 | === removed file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/check.d/root_on_raid' | |||
4606 | === added file '.pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/config.c' | |||
4607 | --- .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/config.c 1970-01-01 00:00:00 +0000 | |||
4608 | +++ .pc/debian-changes-3.1.4-1+8efb9d1ubuntu4/config.c 2012-06-18 08:55:05 +0000 | |||
4609 | @@ -0,0 +1,1131 @@ | |||
4610 | 1 | /* | ||
4611 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. | ||
4612 | 3 | * | ||
4613 | 4 | * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de> | ||
4614 | 5 | * | ||
4615 | 6 | * | ||
4616 | 7 | * This program is free software; you can redistribute it and/or modify | ||
4617 | 8 | * it under the terms of the GNU General Public License as published by | ||
4618 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
4619 | 10 | * (at your option) any later version. | ||
4620 | 11 | * | ||
4621 | 12 | * This program is distributed in the hope that it will be useful, | ||
4622 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4623 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4624 | 15 | * GNU General Public License for more details. | ||
4625 | 16 | * | ||
4626 | 17 | * You should have received a copy of the GNU General Public License | ||
4627 | 18 | * along with this program; if not, write to the Free Software | ||
4628 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
4629 | 20 | * | ||
4630 | 21 | * Author: Neil Brown | ||
4631 | 22 | * Email: <neilb@suse.de> | ||
4632 | 23 | */ | ||
4633 | 24 | |||
4634 | 25 | #include "mdadm.h" | ||
4635 | 26 | #include "dlink.h" | ||
4636 | 27 | #include <dirent.h> | ||
4637 | 28 | #include <glob.h> | ||
4638 | 29 | #include <fnmatch.h> | ||
4639 | 30 | #include <ctype.h> | ||
4640 | 31 | #include <pwd.h> | ||
4641 | 32 | #include <grp.h> | ||
4642 | 33 | |||
4643 | 34 | /* | ||
4644 | 35 | * Read the config file | ||
4645 | 36 | * | ||
4646 | 37 | * conf_get_uuids gets a list of devicename+uuid pairs | ||
4647 | 38 | * conf_get_devs gets device names after expanding wildcards | ||
4648 | 39 | * | ||
4649 | 40 | * Each keeps the returned list and frees it when asked to make | ||
4650 | 41 | * a new list. | ||
4651 | 42 | * | ||
4652 | 43 | * The format of the config file needs to be fairly extensible. | ||
4653 | 44 | * Now, arrays only have names and uuids and devices merely are. | ||
4654 | 45 | * But later arrays might want names, and devices might want superblock | ||
4655 | 46 | * versions, and who knows what else. | ||
4656 | 47 | * I like free format, abhore backslash line continuation, adore | ||
4657 | 48 | * indentation for structure and am ok about # comments. | ||
4658 | 49 | * | ||
4659 | 50 | * So, each line that isn't blank or a #comment must either start | ||
4660 | 51 | * with a key word, and not be indented, or must start with a | ||
4661 | 52 | * non-key-word and must be indented. | ||
4662 | 53 | * | ||
4663 | 54 | * Keywords are DEVICE and ARRAY ... and several others. | ||
4664 | 55 | * DEV{ICE} introduces some devices that might contain raid components. | ||
4665 | 56 | * e.g. | ||
4666 | 57 | * DEV style=0 /dev/sda* /dev/hd* | ||
4667 | 58 | * DEV style=1 /dev/sd[b-f]* | ||
4668 | 59 | * ARR{AY} describes an array giving md device and attributes like uuid=whatever | ||
4669 | 60 | * e.g. | ||
4670 | 61 | * ARRAY /dev/md0 uuid=whatever name=something | ||
4671 | 62 | * Spaces separate words on each line. Quoting, with "" or '' protects them, | ||
4672 | 63 | * but may not wrap over lines | ||
4673 | 64 | * | ||
4674 | 65 | */ | ||
4675 | 66 | |||
4676 | 67 | #ifndef CONFFILE | ||
4677 | 68 | #define CONFFILE "/etc/mdadm.conf" | ||
4678 | 69 | #endif | ||
4679 | 70 | #ifndef CONFFILE2 | ||
4680 | 71 | /* for Debian compatibility .... */ | ||
4681 | 72 | #define CONFFILE2 "/etc/mdadm/mdadm.conf" | ||
4682 | 73 | #endif | ||
4683 | 74 | char DefaultConfFile[] = CONFFILE; | ||
4684 | 75 | char DefaultAltConfFile[] = CONFFILE2; | ||
4685 | 76 | |||
4686 | 77 | enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev, | ||
4687 | 78 | Homehost, AutoMode, Policy, PartPolicy, LTEnd }; | ||
4688 | 79 | char *keywords[] = { | ||
4689 | 80 | [Devices] = "devices", | ||
4690 | 81 | [Array] = "array", | ||
4691 | 82 | [Mailaddr] = "mailaddr", | ||
4692 | 83 | [Mailfrom] = "mailfrom", | ||
4693 | 84 | [Program] = "program", | ||
4694 | 85 | [CreateDev]= "create", | ||
4695 | 86 | [Homehost] = "homehost", | ||
4696 | 87 | [AutoMode] = "auto", | ||
4697 | 88 | [Policy] = "policy", | ||
4698 | 89 | [PartPolicy]="part-policy", | ||
4699 | 90 | [LTEnd] = NULL | ||
4700 | 91 | }; | ||
4701 | 92 | |||
4702 | 93 | /* | ||
4703 | 94 | * match_keyword returns an index into the keywords array, or -1 for no match | ||
4704 | 95 | * case is ignored, and at least three characters must be given | ||
4705 | 96 | */ | ||
4706 | 97 | |||
4707 | 98 | int match_keyword(char *word) | ||
4708 | 99 | { | ||
4709 | 100 | int len = strlen(word); | ||
4710 | 101 | int n; | ||
4711 | 102 | |||
4712 | 103 | if (len < 3) return -1; | ||
4713 | 104 | for (n=0; keywords[n]; n++) { | ||
4714 | 105 | if (strncasecmp(word, keywords[n], len)==0) | ||
4715 | 106 | return n; | ||
4716 | 107 | } | ||
4717 | 108 | return -1; | ||
4718 | 109 | } | ||
4719 | 110 | |||
4720 | 111 | /* | ||
4721 | 112 | * conf_line reads one logical line from the conffile. | ||
4722 | 113 | * It skips comments and continues until it finds a line that starts | ||
4723 | 114 | * with a non blank/comment. This character is pushed back for the next call | ||
4724 | 115 | * A doubly linked list of words is returned. | ||
4725 | 116 | * the first word will be a keyword. Other words will have had quotes removed. | ||
4726 | 117 | */ | ||
4727 | 118 | |||
4728 | 119 | char *conf_line(FILE *file) | ||
4729 | 120 | { | ||
4730 | 121 | char *w; | ||
4731 | 122 | char *list; | ||
4732 | 123 | |||
4733 | 124 | w = conf_word(file, 1); | ||
4734 | 125 | if (w == NULL) return NULL; | ||
4735 | 126 | |||
4736 | 127 | list = dl_strdup(w); | ||
4737 | 128 | free(w); | ||
4738 | 129 | dl_init(list); | ||
4739 | 130 | |||
4740 | 131 | while ((w = conf_word(file,0))){ | ||
4741 | 132 | char *w2 = dl_strdup(w); | ||
4742 | 133 | free(w); | ||
4743 | 134 | dl_add(list, w2); | ||
4744 | 135 | } | ||
4745 | 136 | /* printf("got a line\n");*/ | ||
4746 | 137 | return list; | ||
4747 | 138 | } | ||
4748 | 139 | |||
4749 | 140 | void free_line(char *line) | ||
4750 | 141 | { | ||
4751 | 142 | char *w; | ||
4752 | 143 | for (w=dl_next(line); w != line; w=dl_next(line)) { | ||
4753 | 144 | dl_del(w); | ||
4754 | 145 | dl_free(w); | ||
4755 | 146 | } | ||
4756 | 147 | dl_free(line); | ||
4757 | 148 | } | ||
4758 | 149 | |||
4759 | 150 | |||
4760 | 151 | struct conf_dev { | ||
4761 | 152 | struct conf_dev *next; | ||
4762 | 153 | char *name; | ||
4763 | 154 | } *cdevlist = NULL; | ||
4764 | 155 | |||
4765 | 156 | struct mddev_dev *load_partitions(void) | ||
4766 | 157 | { | ||
4767 | 158 | FILE *f = fopen("/proc/partitions", "r"); | ||
4768 | 159 | char buf[1024]; | ||
4769 | 160 | struct mddev_dev *rv = NULL; | ||
4770 | 161 | if (f == NULL) { | ||
4771 | 162 | fprintf(stderr, Name ": cannot open /proc/partitions\n"); | ||
4772 | 163 | return NULL; | ||
4773 | 164 | } | ||
4774 | 165 | while (fgets(buf, 1024, f)) { | ||
4775 | 166 | int major, minor; | ||
4776 | 167 | char *name, *mp; | ||
4777 | 168 | struct mddev_dev *d; | ||
4778 | 169 | |||
4779 | 170 | buf[1023] = '\0'; | ||
4780 | 171 | if (buf[0] != ' ') | ||
4781 | 172 | continue; | ||
4782 | 173 | major = strtoul(buf, &mp, 10); | ||
4783 | 174 | if (mp == buf || *mp != ' ') | ||
4784 | 175 | continue; | ||
4785 | 176 | minor = strtoul(mp, NULL, 10); | ||
4786 | 177 | |||
4787 | 178 | name = map_dev(major, minor, 1); | ||
4788 | 179 | if (!name) | ||
4789 | 180 | continue; | ||
4790 | 181 | d = malloc(sizeof(*d)); | ||
4791 | 182 | d->devname = strdup(name); | ||
4792 | 183 | d->next = rv; | ||
4793 | 184 | d->used = 0; | ||
4794 | 185 | rv = d; | ||
4795 | 186 | } | ||
4796 | 187 | fclose(f); | ||
4797 | 188 | return rv; | ||
4798 | 189 | } | ||
4799 | 190 | |||
4800 | 191 | struct mddev_dev *load_containers(void) | ||
4801 | 192 | { | ||
4802 | 193 | struct mdstat_ent *mdstat = mdstat_read(1, 0); | ||
4803 | 194 | struct mdstat_ent *ent; | ||
4804 | 195 | struct mddev_dev *d; | ||
4805 | 196 | struct mddev_dev *rv = NULL; | ||
4806 | 197 | |||
4807 | 198 | if (!mdstat) | ||
4808 | 199 | return NULL; | ||
4809 | 200 | |||
4810 | 201 | for (ent = mdstat; ent; ent = ent->next) | ||
4811 | 202 | if (ent->metadata_version && | ||
4812 | 203 | strncmp(ent->metadata_version, "external:", 9) == 0 && | ||
4813 | 204 | !is_subarray(&ent->metadata_version[9])) { | ||
4814 | 205 | d = malloc(sizeof(*d)); | ||
4815 | 206 | if (!d) | ||
4816 | 207 | continue; | ||
4817 | 208 | if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) { | ||
4818 | 209 | free(d); | ||
4819 | 210 | continue; | ||
4820 | 211 | } | ||
4821 | 212 | d->next = rv; | ||
4822 | 213 | d->used = 0; | ||
4823 | 214 | rv = d; | ||
4824 | 215 | } | ||
4825 | 216 | free_mdstat(mdstat); | ||
4826 | 217 | |||
4827 | 218 | return rv; | ||
4828 | 219 | } | ||
4829 | 220 | |||
4830 | 221 | struct createinfo createinfo = { | ||
4831 | 222 | .autof = 2, /* by default, create devices with standard names */ | ||
4832 | 223 | .symlinks = 1, | ||
4833 | 224 | #ifdef DEBIAN | ||
4834 | 225 | .gid = 6, /* disk */ | ||
4835 | 226 | .mode = 0660, | ||
4836 | 227 | #else | ||
4837 | 228 | .mode = 0600, | ||
4838 | 229 | #endif | ||
4839 | 230 | }; | ||
4840 | 231 | |||
4841 | 232 | int parse_auto(char *str, char *msg, int config) | ||
4842 | 233 | { | ||
4843 | 234 | int autof; | ||
4844 | 235 | if (str == NULL || *str == 0) | ||
4845 | 236 | autof = 2; | ||
4846 | 237 | else if (strcasecmp(str,"no")==0) | ||
4847 | 238 | autof = 1; | ||
4848 | 239 | else if (strcasecmp(str,"yes")==0) | ||
4849 | 240 | autof = 2; | ||
4850 | 241 | else if (strcasecmp(str,"md")==0) | ||
4851 | 242 | autof = config?5:3; | ||
4852 | 243 | else { | ||
4853 | 244 | /* There might be digits, and maybe a hypen, at the end */ | ||
4854 | 245 | char *e = str + strlen(str); | ||
4855 | 246 | int num = 4; | ||
4856 | 247 | int len; | ||
4857 | 248 | while (e > str && isdigit(e[-1])) | ||
4858 | 249 | e--; | ||
4859 | 250 | if (*e) { | ||
4860 | 251 | num = atoi(e); | ||
4861 | 252 | if (num <= 0) num = 1; | ||
4862 | 253 | } | ||
4863 | 254 | if (e > str && e[-1] == '-') | ||
4864 | 255 | e--; | ||
4865 | 256 | len = e - str; | ||
4866 | 257 | if ((len == 2 && strncasecmp(str,"md",2)==0)) { | ||
4867 | 258 | autof = config ? 5 : 3; | ||
4868 | 259 | } else if ((len == 3 && strncasecmp(str,"yes",3)==0)) { | ||
4869 | 260 | autof = 2; | ||
4870 | 261 | } else if ((len == 3 && strncasecmp(str,"mdp",3)==0)) { | ||
4871 | 262 | autof = config ? 6 : 4; | ||
4872 | 263 | } else if ((len == 1 && strncasecmp(str,"p",1)==0) || | ||
4873 | 264 | (len >= 4 && strncasecmp(str,"part",4)==0)) { | ||
4874 | 265 | autof = 6; | ||
4875 | 266 | } else { | ||
4876 | 267 | fprintf(stderr, Name ": %s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n" | ||
4877 | 268 | " optionally followed by a number.\n", | ||
4878 | 269 | msg, str); | ||
4879 | 270 | exit(2); | ||
4880 | 271 | } | ||
4881 | 272 | autof |= num << 3; | ||
4882 | 273 | } | ||
4883 | 274 | return autof; | ||
4884 | 275 | } | ||
4885 | 276 | |||
4886 | 277 | static void createline(char *line) | ||
4887 | 278 | { | ||
4888 | 279 | char *w; | ||
4889 | 280 | char *ep; | ||
4890 | 281 | |||
4891 | 282 | for (w=dl_next(line); w!=line; w=dl_next(w)) { | ||
4892 | 283 | if (strncasecmp(w, "auto=", 5) == 0) | ||
4893 | 284 | createinfo.autof = parse_auto(w+5, "auto=", 1); | ||
4894 | 285 | else if (strncasecmp(w, "owner=", 6) == 0) { | ||
4895 | 286 | if (w[6] == 0) { | ||
4896 | 287 | fprintf(stderr, Name ": missing owner name\n"); | ||
4897 | 288 | continue; | ||
4898 | 289 | } | ||
4899 | 290 | createinfo.uid = strtoul(w+6, &ep, 10); | ||
4900 | 291 | if (*ep != 0) { | ||
4901 | 292 | struct passwd *pw; | ||
4902 | 293 | /* must be a name */ | ||
4903 | 294 | pw = getpwnam(w+6); | ||
4904 | 295 | if (pw) | ||
4905 | 296 | createinfo.uid = pw->pw_uid; | ||
4906 | 297 | else | ||
4907 | 298 | fprintf(stderr, Name ": CREATE user %s not found\n", w+6); | ||
4908 | 299 | } | ||
4909 | 300 | } else if (strncasecmp(w, "group=", 6) == 0) { | ||
4910 | 301 | if (w[6] == 0) { | ||
4911 | 302 | fprintf(stderr, Name ": missing group name\n"); | ||
4912 | 303 | continue; | ||
4913 | 304 | } | ||
4914 | 305 | createinfo.gid = strtoul(w+6, &ep, 10); | ||
4915 | 306 | if (*ep != 0) { | ||
4916 | 307 | struct group *gr; | ||
4917 | 308 | /* must be a name */ | ||
4918 | 309 | gr = getgrnam(w+6); | ||
4919 | 310 | if (gr) | ||
4920 | 311 | createinfo.gid = gr->gr_gid; | ||
4921 | 312 | else | ||
4922 | 313 | fprintf(stderr, Name ": CREATE group %s not found\n", w+6); | ||
4923 | 314 | } | ||
4924 | 315 | } else if (strncasecmp(w, "mode=", 5) == 0) { | ||
4925 | 316 | if (w[5] == 0) { | ||
4926 | 317 | fprintf(stderr, Name ": missing CREATE mode\n"); | ||
4927 | 318 | continue; | ||
4928 | 319 | } | ||
4929 | 320 | createinfo.mode = strtoul(w+5, &ep, 8); | ||
4930 | 321 | if (*ep != 0) { | ||
4931 | 322 | createinfo.mode = 0600; | ||
4932 | 323 | fprintf(stderr, Name ": unrecognised CREATE mode %s\n", | ||
4933 | 324 | w+5); | ||
4934 | 325 | } | ||
4935 | 326 | } else if (strncasecmp(w, "metadata=", 9) == 0) { | ||
4936 | 327 | /* style of metadata to use by default */ | ||
4937 | 328 | int i; | ||
4938 | 329 | for (i=0; superlist[i] && !createinfo.supertype; i++) | ||
4939 | 330 | createinfo.supertype = | ||
4940 | 331 | superlist[i]->match_metadata_desc(w+9); | ||
4941 | 332 | if (!createinfo.supertype) | ||
4942 | 333 | fprintf(stderr, Name ": metadata format %s unknown, ignoring\n", | ||
4943 | 334 | w+9); | ||
4944 | 335 | } else if (strncasecmp(w, "symlinks=yes", 12) == 0) | ||
4945 | 336 | createinfo.symlinks = 1; | ||
4946 | 337 | else if (strncasecmp(w, "symlinks=no", 11) == 0) | ||
4947 | 338 | createinfo.symlinks = 0; | ||
4948 | 339 | else { | ||
4949 | 340 | fprintf(stderr, Name ": unrecognised word on CREATE line: %s\n", | ||
4950 | 341 | w); | ||
4951 | 342 | } | ||
4952 | 343 | } | ||
4953 | 344 | } | ||
4954 | 345 | |||
4955 | 346 | void devline(char *line) | ||
4956 | 347 | { | ||
4957 | 348 | char *w; | ||
4958 | 349 | struct conf_dev *cd; | ||
4959 | 350 | |||
4960 | 351 | for (w=dl_next(line); w != line; w=dl_next(w)) { | ||
4961 | 352 | if (w[0] == '/' || strcasecmp(w, "partitions") == 0 || | ||
4962 | 353 | strcasecmp(w, "containers") == 0) { | ||
4963 | 354 | cd = malloc(sizeof(*cd)); | ||
4964 | 355 | cd->name = strdup(w); | ||
4965 | 356 | cd->next = cdevlist; | ||
4966 | 357 | cdevlist = cd; | ||
4967 | 358 | } else { | ||
4968 | 359 | fprintf(stderr, Name ": unreconised word on DEVICE line: %s\n", | ||
4969 | 360 | w); | ||
4970 | 361 | } | ||
4971 | 362 | } | ||
4972 | 363 | } | ||
4973 | 364 | |||
4974 | 365 | struct mddev_ident *mddevlist = NULL; | ||
4975 | 366 | struct mddev_ident **mddevlp = &mddevlist; | ||
4976 | 367 | |||
4977 | 368 | static int is_number(char *w) | ||
4978 | 369 | { | ||
4979 | 370 | /* check if there are 1 or more digits and nothing else */ | ||
4980 | 371 | int digits = 0; | ||
4981 | 372 | while (*w && isdigit(*w)) { | ||
4982 | 373 | digits++; | ||
4983 | 374 | w++; | ||
4984 | 375 | } | ||
4985 | 376 | return (digits && ! *w); | ||
4986 | 377 | } | ||
4987 | 378 | |||
4988 | 379 | void arrayline(char *line) | ||
4989 | 380 | { | ||
4990 | 381 | char *w; | ||
4991 | 382 | |||
4992 | 383 | struct mddev_ident mis; | ||
4993 | 384 | struct mddev_ident *mi; | ||
4994 | 385 | |||
4995 | 386 | mis.uuid_set = 0; | ||
4996 | 387 | mis.super_minor = UnSet; | ||
4997 | 388 | mis.level = UnSet; | ||
4998 | 389 | mis.raid_disks = UnSet; | ||
4999 | 390 | mis.spare_disks = 0; | ||
5000 | 391 | mis.devices = NULL; |
The diff has been truncated for viewing.