]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
6f02172d | 4 | * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de> |
64c4757e NB |
5 | * |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * Author: Neil Brown | |
e736b623 | 22 | * Email: <neilb@suse.de> |
64c4757e NB |
23 | */ |
24 | ||
9a9dab36 | 25 | #include "mdadm.h" |
64c4757e NB |
26 | #include "md_p.h" |
27 | #include "md_u.h" | |
b9c9bd9b | 28 | #include <ctype.h> |
c69b251b | 29 | #include <dirent.h> |
64c4757e | 30 | |
41a663b2 | 31 | static int cmpstringp(const void *p1, const void *p2) |
32 | { | |
33 | return strcmp(* (char * const *) p1, * (char * const *) p2); | |
34 | } | |
35 | ||
b76dc299 MW |
36 | static int add_device(const char *dev, char ***p_devices, |
37 | int *p_max_devices, int n_devices) | |
38 | { | |
39 | if (n_devices + 1 >= *p_max_devices) { | |
40 | *p_max_devices += 16; | |
41 | *p_devices = xrealloc(*p_devices, *p_max_devices * | |
42 | sizeof(**p_devices)); | |
43 | if (!*p_devices) { | |
44 | *p_max_devices = 0; | |
45 | return 0; | |
46 | } | |
47 | }; | |
48 | (*p_devices)[n_devices] = xstrdup(dev); | |
49 | return n_devices + 1; | |
50 | } | |
51 | ||
ef898ce6 | 52 | int Detail(char *dev, struct context *c) |
64c4757e NB |
53 | { |
54 | /* | |
d97572f5 | 55 | * Print out details for an md array |
64c4757e | 56 | */ |
fb97b4d6 | 57 | int fd = open(dev, O_RDONLY); |
64c4757e | 58 | mdu_array_info_t array; |
b0c63f32 NB |
59 | mdu_disk_info_t *disks; |
60 | int next; | |
64c4757e NB |
61 | int d; |
62 | time_t atime; | |
4df01ff5 | 63 | char *str; |
41a663b2 | 64 | char **devices = NULL; |
65 | int max_devices = 0, n_devices = 0; | |
feb716e9 | 66 | int spares = 0; |
dd0781e5 | 67 | struct stat stb; |
e5329c37 | 68 | int failed = 0; |
9aaada05 | 69 | struct supertype *st; |
4725bc31 | 70 | char *subarray = NULL; |
e27d562b | 71 | int max_disks = MD_SB_DISKS; /* just a default */ |
a1f976a0 | 72 | struct mdinfo *info = NULL; |
142cb9e1 | 73 | struct mdinfo *sra; |
e6fc80a8 | 74 | struct mdinfo *subdev; |
c69b251b N |
75 | char *member = NULL; |
76 | char *container = NULL; | |
64c4757e | 77 | |
ef898ce6 | 78 | int rv = c->test ? 4 : 1; |
a77be586 | 79 | int avail_disks = 0; |
d0673517 | 80 | char *avail = NULL; |
e6fc80a8 N |
81 | int external; |
82 | int inactive; | |
82b27616 | 83 | |
64c4757e | 84 | if (fd < 0) { |
e7b84f9d | 85 | pr_err("cannot open %s: %s\n", |
64c4757e | 86 | dev, strerror(errno)); |
feb716e9 | 87 | return rv; |
64c4757e | 88 | } |
a4dcdb23 | 89 | sra = sysfs_read(fd, NULL, GET_VERSION | GET_DEVS | GET_ARRAY_STATE); |
901d5ee6 | 90 | if (!sra) { |
0885b942 JS |
91 | if (md_get_array_info(fd, &array)) { |
92 | pr_err("%s does not appear to be an md device\n", dev); | |
93 | close(fd); | |
94 | return rv; | |
95 | } | |
64c4757e | 96 | } |
901d5ee6 JS |
97 | external = (sra != NULL && sra->array.major_version == -1 && |
98 | sra->array.minor_version == -2); | |
a4dcdb23 JS |
99 | inactive = (sra->array_state == ARRAY_ACTIVE || |
100 | sra->array_state == ARRAY_CLEAR); | |
e6fc80a8 | 101 | st = super_by_fd(fd, &subarray); |
9b8fea91 TM |
102 | if (md_get_array_info(fd, &array)) { |
103 | if (errno == ENODEV) { | |
104 | if (sra->array.major_version == -1 && | |
105 | sra->array.minor_version == -1 && | |
106 | sra->devs == NULL) { | |
107 | pr_err("Array associated with md device %s does not exist.\n", | |
108 | dev); | |
109 | close(fd); | |
110 | sysfs_free(sra); | |
111 | return rv; | |
112 | } | |
113 | array = sra->array; | |
114 | } else { | |
115 | pr_err("cannot get array detail for %s: %s\n", | |
116 | dev, strerror(errno)); | |
b4decd51 | 117 | close(fd); |
b4decd51 N |
118 | return rv; |
119 | } | |
64c4757e | 120 | } |
f9ce90ba | 121 | |
dd0781e5 NB |
122 | if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode)) |
123 | stb.st_rdev = 0; | |
feb716e9 | 124 | rv = 0; |
e5329c37 | 125 | |
c69b251b N |
126 | if (st) |
127 | max_disks = st->max_devs; | |
128 | ||
5f7e44b2 | 129 | if (subarray) { |
c69b251b N |
130 | /* This is a subarray of some container. |
131 | * We want the name of the container, and the member | |
132 | */ | |
13db17bd | 133 | dev_t devid = devnm2devid(st->container_devnm); |
c1ea5a98 | 134 | int cfd, err; |
5f7e44b2 DW |
135 | |
136 | member = subarray; | |
4dd2df09 N |
137 | container = map_dev_preferred(major(devid), minor(devid), |
138 | 1, c->prefer); | |
c1ea5a98 | 139 | cfd = open_dev(st->container_devnm); |
140 | if (cfd >= 0) { | |
141 | err = st->ss->load_container(st, cfd, NULL); | |
142 | close(cfd); | |
143 | if (err == 0) | |
144 | info = st->ss->container_content(st, subarray); | |
145 | } | |
c69b251b | 146 | } |
ea329559 | 147 | |
e6fc80a8 | 148 | /* try to load a superblock. Try sra->devs first, then try ioctl */ |
776b199e JS |
149 | if (st && !info) |
150 | for (d = 0, subdev = sra ? sra->devs : NULL; | |
151 | d < max_disks || subdev; | |
152 | subdev ? (void)(subdev = subdev->next) : (void)(d++)){ | |
e5329c37 NB |
153 | mdu_disk_info_t disk; |
154 | char *dv; | |
9aaada05 N |
155 | int fd2; |
156 | int err; | |
776b199e | 157 | |
e6fc80a8 N |
158 | if (subdev) |
159 | disk = subdev->disk; | |
160 | else { | |
161 | disk.number = d; | |
d97572f5 | 162 | if (md_get_disk_info(fd, &disk) < 0) |
e6fc80a8 N |
163 | continue; |
164 | if (d >= array.raid_disks && | |
5737086e | 165 | disk.major == 0 && disk.minor == 0) |
e6fc80a8 N |
166 | continue; |
167 | } | |
9aaada05 N |
168 | |
169 | if (array.raid_disks > 0 && | |
170 | (disk.state & (1 << MD_DISK_ACTIVE)) == 0) | |
171 | continue; | |
172 | ||
173 | dv = map_dev(disk.major, disk.minor, 1); | |
174 | if (!dv) | |
175 | continue; | |
176 | ||
177 | fd2 = dev_open(dv, O_RDONLY); | |
178 | if (fd2 < 0) | |
179 | continue; | |
180 | ||
181 | if (st->sb) | |
182 | st->ss->free_super(st); | |
183 | ||
184 | err = st->ss->load_super(st, fd2, NULL); | |
185 | close(fd2); | |
186 | if (err) | |
187 | continue; | |
a1f976a0 N |
188 | if (info) |
189 | free(info); | |
190 | if (subarray) | |
191 | info = st->ss->container_content(st, subarray); | |
192 | else { | |
503975b9 | 193 | info = xmalloc(sizeof(*info)); |
a1f976a0 N |
194 | st->ss->getinfo_super(st, info, NULL); |
195 | } | |
196 | if (!info) | |
197 | continue; | |
9aaada05 N |
198 | |
199 | if (array.raid_disks != 0 && /* container */ | |
a1f976a0 N |
200 | (info->array.ctime != array.ctime || |
201 | info->array.level != array.level)) { | |
9aaada05 N |
202 | st->ss->free_super(st); |
203 | continue; | |
e5329c37 | 204 | } |
9aaada05 | 205 | /* some formats (imsm) have free-floating-spares |
22e263f6 | 206 | * with a uuid of uuid_zero, they don't |
9aaada05 N |
207 | * have very good info about the rest of the |
208 | * container, so keep searching when | |
209 | * encountering such a device. Otherwise, stop | |
210 | * after the first successful call to | |
211 | * ->load_super. | |
212 | */ | |
22e263f6 | 213 | if (memcmp(uuid_zero, |
a1f976a0 | 214 | info->uuid, |
22e263f6 | 215 | sizeof(uuid_zero)) == 0) { |
9aaada05 N |
216 | st->ss->free_super(st); |
217 | continue; | |
218 | } | |
219 | break; | |
e5329c37 NB |
220 | } |
221 | ||
64c4757e | 222 | /* Ok, we have some info to print... */ |
4df01ff5 | 223 | str = map_num(pers, array.level); |
54bad364 | 224 | |
ef898ce6 | 225 | if (c->export) { |
c69b251b | 226 | if (array.raid_disks) { |
4df01ff5 N |
227 | if (str) |
228 | printf("MD_LEVEL=%s\n", str); | |
c69b251b N |
229 | printf("MD_DEVICES=%d\n", array.raid_disks); |
230 | } else { | |
e6fc80a8 N |
231 | if (!inactive) |
232 | printf("MD_LEVEL=container\n"); | |
c69b251b N |
233 | printf("MD_DEVICES=%d\n", array.nr_disks); |
234 | } | |
235 | if (container) { | |
236 | printf("MD_CONTAINER=%s\n", container); | |
237 | printf("MD_MEMBER=%s\n", member); | |
238 | } else { | |
239 | if (sra && sra->array.major_version < 0) | |
240 | printf("MD_METADATA=%s\n", sra->text_version); | |
241 | else | |
6e48d593 | 242 | printf("MD_METADATA=%d.%d\n", |
5737086e JS |
243 | array.major_version, |
244 | array.minor_version); | |
c69b251b | 245 | } |
ca3b6696 | 246 | |
a1f976a0 | 247 | if (st && st->sb && info) { |
35ddc76d | 248 | char nbuf[64]; |
f069dd29 | 249 | struct map_ent *mp, *map = NULL; |
9aaada05 | 250 | |
a1f976a0 | 251 | fname_from_uuid(st, info, nbuf, ':'); |
5737086e | 252 | printf("MD_UUID=%s\n", nbuf + 5); |
a1f976a0 | 253 | mp = map_by_uuid(&map, info->uuid); |
f069dd29 | 254 | if (mp && mp->path && |
7103b9b8 N |
255 | strncmp(mp->path, "/dev/md/", 8) == 0) { |
256 | printf("MD_DEVNAME="); | |
5737086e | 257 | print_escape(mp->path + 8); |
7103b9b8 N |
258 | putchar('\n'); |
259 | } | |
142cb9e1 | 260 | |
35ddc76d N |
261 | if (st->ss->export_detail_super) |
262 | st->ss->export_detail_super(st); | |
7e6c6cb2 N |
263 | } else { |
264 | struct map_ent *mp, *map = NULL; | |
aae5a112 | 265 | char nbuf[64]; |
4dd2df09 | 266 | mp = map_by_devnm(&map, fd2devnm(fd)); |
aae5a112 DW |
267 | if (mp) { |
268 | __fname_from_uuid(mp->uuid, 0, nbuf, ':'); | |
269 | printf("MD_UUID=%s\n", nbuf+5); | |
270 | } | |
7e6c6cb2 | 271 | if (mp && mp->path && |
7103b9b8 N |
272 | strncmp(mp->path, "/dev/md/", 8) == 0) { |
273 | printf("MD_DEVNAME="); | |
274 | print_escape(mp->path+8); | |
275 | putchar('\n'); | |
276 | } | |
35ddc76d | 277 | } |
54def20f N |
278 | if (sra) { |
279 | struct mdinfo *mdi; | |
280 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
5737086e | 281 | char *path; |
b9c9bd9b N |
282 | char *sysdev = xstrdup(mdi->sys_name + 1); |
283 | char *cp; | |
5737086e JS |
284 | |
285 | path = map_dev(mdi->disk.major, | |
286 | mdi->disk.minor, 0); | |
b9c9bd9b N |
287 | for (cp = sysdev; *cp; cp++) |
288 | if (!isalnum(*cp)) | |
289 | *cp = '_'; | |
54def20f N |
290 | |
291 | if (mdi->disk.raid_disk >= 0) | |
292 | printf("MD_DEVICE_%s_ROLE=%d\n", | |
b9c9bd9b | 293 | sysdev, |
54def20f N |
294 | mdi->disk.raid_disk); |
295 | else | |
296 | printf("MD_DEVICE_%s_ROLE=spare\n", | |
b9c9bd9b | 297 | sysdev); |
54def20f N |
298 | if (path) |
299 | printf("MD_DEVICE_%s_DEV=%s\n", | |
b9c9bd9b | 300 | sysdev, path); |
54def20f N |
301 | } |
302 | } | |
54bad364 KS |
303 | goto out; |
304 | } | |
305 | ||
8057db46 N |
306 | disks = xmalloc(max_disks * 2 * sizeof(mdu_disk_info_t)); |
307 | for (d = 0; d < max_disks * 2; d++) { | |
5737086e | 308 | disks[d].state = (1 << MD_DISK_REMOVED); |
d998adc3 | 309 | disks[d].major = disks[d].minor = 0; |
78a5dc03 | 310 | disks[d].number = -1; |
5737086e | 311 | disks[d].raid_disk = d / 2; |
d998adc3 N |
312 | } |
313 | ||
5737086e | 314 | next = array.raid_disks * 2; |
e6fc80a8 N |
315 | if (inactive) { |
316 | struct mdinfo *mdi; | |
317 | if (sra != NULL) | |
318 | for (mdi = sra->devs; mdi; mdi = mdi->next) { | |
319 | disks[next++] = mdi->disk; | |
5737086e | 320 | disks[next - 1].number = -1; |
e6fc80a8 N |
321 | } |
322 | } else for (d = 0; d < max_disks; d++) { | |
d998adc3 N |
323 | mdu_disk_info_t disk; |
324 | disk.number = d; | |
d97572f5 | 325 | if (md_get_disk_info(fd, &disk) < 0) { |
d998adc3 | 326 | if (d < array.raid_disks) |
e7b84f9d | 327 | pr_err("cannot get device detail for device %d: %s\n", |
d998adc3 N |
328 | d, strerror(errno)); |
329 | continue; | |
330 | } | |
331 | if (disk.major == 0 && disk.minor == 0) | |
332 | continue; | |
5737086e JS |
333 | if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks && |
334 | disks[disk.raid_disk * 2].state == (1 << MD_DISK_REMOVED) && | |
335 | ((disk.state & (1 << MD_DISK_JOURNAL)) == 0)) | |
336 | disks[disk.raid_disk * 2] = disk; | |
337 | else if (disk.raid_disk >= 0 && | |
338 | disk.raid_disk < array.raid_disks && | |
339 | disks[disk.raid_disk * 2 + 1].state == | |
340 | (1 << MD_DISK_REMOVED) && | |
341 | !(disk.state & (1 << MD_DISK_JOURNAL))) | |
342 | disks[disk.raid_disk * 2 + 1] = disk; | |
343 | else if (next < max_disks * 2) | |
d998adc3 N |
344 | disks[next++] = disk; |
345 | } | |
346 | ||
503975b9 | 347 | avail = xcalloc(array.raid_disks, 1); |
d998adc3 | 348 | |
5737086e | 349 | for (d = 0; d < array.raid_disks; d++) { |
d998adc3 | 350 | |
24c7bc84 N |
351 | if ((disks[d*2].state & (1<<MD_DISK_SYNC)) || |
352 | (disks[d*2+1].state & (1<<MD_DISK_SYNC))) { | |
d998adc3 N |
353 | avail_disks ++; |
354 | avail[d] = 1; | |
cd04f562 CS |
355 | } else |
356 | rv |= !! c->test; | |
d998adc3 N |
357 | } |
358 | ||
ef898ce6 | 359 | if (c->brief) { |
e8eb8763 | 360 | mdu_bitmap_file_t bmf; |
e6fc80a8 | 361 | printf("%sARRAY %s", inactive ? "INACTIVE-":"", dev); |
b3908491 | 362 | if (c->verbose > 0) { |
061f2c6a | 363 | if (array.raid_disks) |
0e90271e | 364 | printf(" level=%s num-devices=%d", |
5737086e JS |
365 | str ? str : "-unknown-", |
366 | array.raid_disks); | |
e6fc80a8 | 367 | else if (!inactive) |
0e90271e | 368 | printf(" level=container num-devices=%d", |
061f2c6a | 369 | array.nr_disks); |
e6fc80a8 N |
370 | else |
371 | printf(" num-devices=%d", array.nr_disks); | |
061f2c6a | 372 | } |
c69b251b N |
373 | if (container) { |
374 | printf(" container=%s", container); | |
375 | printf(" member=%s", member); | |
376 | } else { | |
377 | if (sra && sra->array.major_version < 0) | |
378 | printf(" metadata=%s", sra->text_version); | |
379 | else | |
5737086e JS |
380 | printf(" metadata=%d.%d", array.major_version, |
381 | array.minor_version); | |
c69b251b | 382 | } |
e8eb8763 NB |
383 | |
384 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ | |
901d5ee6 | 385 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { |
e8eb8763 NB |
386 | printf(" bitmap=%s", bmf.pathname); |
387 | } | |
142cb9e1 | 388 | } else { |
8fac0577 | 389 | mdu_bitmap_file_t bmf; |
e0d19036 | 390 | unsigned long long larray_size; |
22a88995 | 391 | struct mdstat_ent *ms = mdstat_read(0, 0); |
dd0781e5 | 392 | struct mdstat_ent *e; |
4dd2df09 | 393 | char *devnm; |
dd0781e5 | 394 | |
4dd2df09 | 395 | devnm = stat2devnm(&stb); |
5737086e | 396 | for (e = ms; e; e = e->next) |
4dd2df09 | 397 | if (strcmp(e->devnm, devnm) == 0) |
dd0781e5 | 398 | break; |
beae1dfe NB |
399 | if (!get_dev_size(fd, NULL, &larray_size)) |
400 | larray_size = 0; | |
56eb10c0 | 401 | |
cd29a5c8 | 402 | printf("%s:\n", dev); |
142cb9e1 | 403 | |
c69b251b | 404 | if (container) |
5737086e JS |
405 | printf(" Container : %s, member %s\n", |
406 | container, member); | |
c69b251b | 407 | else { |
5737086e JS |
408 | if (sra && sra->array.major_version < 0) |
409 | printf(" Version : %s\n", | |
410 | sra->text_version); | |
411 | else | |
412 | printf(" Version : %d.%d\n", | |
413 | array.major_version, | |
414 | array.minor_version); | |
c69b251b | 415 | } |
142cb9e1 | 416 | |
cd29a5c8 | 417 | atime = array.ctime; |
c69b251b | 418 | if (atime) |
65884368 | 419 | printf(" Creation Time : %.24s\n", ctime(&atime)); |
e6fc80a8 | 420 | if (array.raid_disks == 0 && external) |
4df01ff5 | 421 | str = "container"; |
e6fc80a8 | 422 | if (str) |
65884368 | 423 | printf(" Raid Level : %s\n", str); |
56eb10c0 | 424 | if (larray_size) |
5737086e JS |
425 | printf(" Array Size : %llu%s\n", |
426 | (larray_size >> 10), | |
ca3b6696 | 427 | human_size(larray_size)); |
3d4064cc | 428 | if (array.level >= 1) { |
ec1b28fd N |
429 | if (sra) |
430 | array.major_version = sra->array.major_version; | |
3d4064cc | 431 | if (array.major_version != 0 && |
6ee5c05a | 432 | (larray_size >= 0xFFFFFFFFULL|| array.size == 0)) { |
5737086e JS |
433 | unsigned long long dsize; |
434 | ||
435 | dsize = get_component_size(fd); | |
6ee5c05a | 436 | if (dsize > 0) |
65884368 | 437 | printf(" Used Dev Size : %llu%s\n", |
a1236192 N |
438 | dsize/2, |
439 | human_size((long long)dsize<<9)); | |
6ee5c05a | 440 | else |
65884368 | 441 | printf(" Used Dev Size : unknown\n"); |
6ee5c05a | 442 | } else |
65884368 | 443 | printf(" Used Dev Size : %lu%s\n", |
9f7f28ee | 444 | (unsigned long)array.size, |
5737086e JS |
445 | human_size((unsigned long long) |
446 | array.size << 10)); | |
3d4064cc | 447 | } |
c69b251b | 448 | if (array.raid_disks) |
65884368 AP |
449 | printf(" Raid Devices : %d\n", array.raid_disks); |
450 | printf(" Total Devices : %d\n", array.nr_disks); | |
ca3b6696 | 451 | if (!container && |
c69b251b N |
452 | ((sra == NULL && array.major_version == 0) || |
453 | (sra && sra->array.major_version == 0))) | |
65884368 | 454 | printf(" Preferred Minor : %d\n", array.md_minor); |
142cb9e1 | 455 | if (sra == NULL || sra->array.major_version >= 0) |
65884368 | 456 | printf(" Persistence : Superblock is %spersistent\n", |
5737086e | 457 | array.not_persistent ? "not " : ""); |
cd29a5c8 | 458 | printf("\n"); |
4027ddca | 459 | /* Only try GET_BITMAP_FILE for 0.90.01 and later */ |
901d5ee6 | 460 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 && bmf.pathname[0]) { |
65884368 | 461 | printf(" Intent Bitmap : %s\n", bmf.pathname); |
8fac0577 NB |
462 | printf("\n"); |
463 | } else if (array.state & (1<<MD_SB_BITMAP_PRESENT)) | |
65884368 | 464 | printf(" Intent Bitmap : Internal\n\n"); |
cd29a5c8 | 465 | atime = array.utime; |
c69b251b | 466 | if (atime) |
65884368 | 467 | printf(" Update Time : %.24s\n", ctime(&atime)); |
d998adc3 | 468 | if (array.raid_disks) { |
ca3b6696 N |
469 | static char *sync_action[] = { |
470 | ", recovering", ", resyncing", | |
471 | ", reshaping", ", checking" }; | |
d998adc3 N |
472 | char *st; |
473 | if (avail_disks == array.raid_disks) | |
474 | st = ""; | |
475 | else if (!enough(array.level, array.raid_disks, | |
de5a472e | 476 | array.layout, 1, avail)) |
d998adc3 N |
477 | st = ", FAILED"; |
478 | else | |
479 | st = ", degraded"; | |
480 | ||
65884368 | 481 | printf(" State : %s%s%s%s%s%s \n", |
5737086e JS |
482 | (array.state & (1 << MD_SB_CLEAN)) ? |
483 | "clean" : "active", st, | |
484 | (!e || (e->percent < 0 && | |
485 | e->percent != RESYNC_PENDING && | |
486 | e->percent != RESYNC_DELAYED)) ? | |
487 | "" : sync_action[e->resync], | |
2d3603ba | 488 | larray_size ? "": ", Not Started", |
5737086e JS |
489 | (e && e->percent == RESYNC_DELAYED) ? |
490 | " (DELAYED)": "", | |
491 | (e && e->percent == RESYNC_PENDING) ? | |
492 | " (PENDING)": ""); | |
e6fc80a8 | 493 | } else if (inactive) { |
65884368 | 494 | printf(" State : inactive\n"); |
d998adc3 | 495 | } |
c69b251b | 496 | if (array.raid_disks) |
65884368 | 497 | printf(" Active Devices : %d\n", array.active_disks); |
e6fc80a8 | 498 | if (array.working_disks > 0) |
5737086e JS |
499 | printf(" Working Devices : %d\n", |
500 | array.working_disks); | |
c69b251b | 501 | if (array.raid_disks) { |
65884368 AP |
502 | printf(" Failed Devices : %d\n", array.failed_disks); |
503 | printf(" Spare Devices : %d\n", array.spare_disks); | |
c69b251b | 504 | } |
cd29a5c8 NB |
505 | printf("\n"); |
506 | if (array.level == 5) { | |
4df01ff5 | 507 | str = map_num(r5layout, array.layout); |
5737086e JS |
508 | printf(" Layout : %s\n", |
509 | str ? str : "-unknown-"); | |
cd29a5c8 | 510 | } |
fe77a154 | 511 | if (array.level == 6) { |
4df01ff5 | 512 | str = map_num(r6layout, array.layout); |
5737086e JS |
513 | printf(" Layout : %s\n", |
514 | str ? str : "-unknown-"); | |
fe77a154 | 515 | } |
e5329c37 | 516 | if (array.level == 10) { |
65884368 | 517 | printf(" Layout :"); |
e4965ef8 N |
518 | print_r10_layout(array.layout); |
519 | printf("\n"); | |
e5329c37 | 520 | } |
cd29a5c8 NB |
521 | switch (array.level) { |
522 | case 0: | |
523 | case 4: | |
524 | case 5: | |
e5329c37 NB |
525 | case 10: |
526 | case 6: | |
142cb9e1 | 527 | if (array.chunk_size) |
65884368 | 528 | printf(" Chunk Size : %dK\n\n", |
142cb9e1 | 529 | array.chunk_size/1024); |
cd29a5c8 NB |
530 | break; |
531 | case -1: | |
65884368 AP |
532 | printf(" Rounding : %dK\n\n", |
533 | array.chunk_size/1024); | |
cd29a5c8 | 534 | break; |
5737086e JS |
535 | default: |
536 | break; | |
cd29a5c8 | 537 | } |
aba69144 | 538 | |
65884368 | 539 | if (array.raid_disks) { |
5737086e JS |
540 | struct mdinfo *mdi; |
541 | ||
542 | mdi = sysfs_read(fd, NULL, GET_CONSISTENCY_POLICY); | |
65884368 AP |
543 | if (mdi) { |
544 | char *policy = map_num(consistency_policies, | |
545 | mdi->consistency_policy); | |
546 | sysfs_free(mdi); | |
547 | if (policy) | |
548 | printf("Consistency Policy : %s\n\n", | |
549 | policy); | |
550 | } | |
551 | } | |
552 | ||
e5329c37 | 553 | if (e && e->percent >= 0) { |
ca3b6696 | 554 | static char *sync_action[] = { |
5737086e | 555 | "Rebuild", "Resync", "Reshape", "Check"}; |
65884368 AP |
556 | printf(" %7s Status : %d%% complete\n", |
557 | sync_action[e->resync], e->percent); | |
e5329c37 | 558 | } |
dd0781e5 NB |
559 | free_mdstat(ms); |
560 | ||
db428d7a | 561 | if ((st && st->sb) && (info && info->reshape_active)) { |
bed256c2 NB |
562 | #if 0 |
563 | This is pretty boring | |
65884368 | 564 | printf(" Reshape pos'n : %llu%s\n", |
5737086e JS |
565 | (unsigned long long) info->reshape_progress << 9, |
566 | human_size((unsigned long long) | |
567 | info->reshape_progress << 9)); | |
bed256c2 | 568 | #endif |
c281a804 | 569 | if (info->delta_disks != 0) |
65884368 | 570 | printf(" Delta Devices : %d, (%d->%d)\n", |
ca3b6696 N |
571 | info->delta_disks, |
572 | array.raid_disks - info->delta_disks, | |
573 | array.raid_disks); | |
a1f976a0 | 574 | if (info->new_level != array.level) { |
4df01ff5 | 575 | str = map_num(pers, info->new_level); |
5737086e JS |
576 | printf(" New Level : %s\n", |
577 | str ? str : "-unknown-"); | |
bed256c2 | 578 | } |
a1f976a0 N |
579 | if (info->new_level != array.level || |
580 | info->new_layout != array.layout) { | |
581 | if (info->new_level == 5) { | |
5737086e JS |
582 | str = map_num(r5layout, |
583 | info->new_layout); | |
65884368 | 584 | printf(" New Layout : %s\n", |
5737086e | 585 | str ? str : "-unknown-"); |
bed256c2 | 586 | } |
a1f976a0 | 587 | if (info->new_level == 6) { |
5737086e JS |
588 | str = map_num(r6layout, |
589 | info->new_layout); | |
65884368 | 590 | printf(" New Layout : %s\n", |
5737086e | 591 | str ? str : "-unknown-"); |
dab54dcb | 592 | } |
a1f976a0 | 593 | if (info->new_level == 10) { |
65884368 | 594 | printf(" New Layout : near=%d, %s=%d\n", |
5737086e JS |
595 | info->new_layout & 255, |
596 | (info->new_layout & 0x10000) ? | |
597 | "offset" : "far", | |
598 | (info->new_layout >> 8) & 255); | |
bed256c2 NB |
599 | } |
600 | } | |
a1f976a0 | 601 | if (info->new_chunk != array.chunk_size) |
65884368 AP |
602 | printf(" New Chunksize : %dK\n", |
603 | info->new_chunk/1024); | |
bed256c2 NB |
604 | printf("\n"); |
605 | } else if (e && e->percent >= 0) | |
606 | printf("\n"); | |
3da92f27 | 607 | if (st && st->sb) |
ef898ce6 | 608 | st->ss->detail_super(st, c->homehost); |
e5329c37 | 609 | |
5737086e JS |
610 | if (array.raid_disks == 0 && sra && |
611 | sra->array.major_version == -1 && | |
612 | sra->array.minor_version == -2 && | |
613 | sra->text_version[0] != '/') { | |
c69b251b N |
614 | /* This looks like a container. Find any active arrays |
615 | * That claim to be a member. | |
616 | */ | |
617 | DIR *dir = opendir("/sys/block"); | |
618 | struct dirent *de; | |
619 | ||
65884368 | 620 | printf(" Member Arrays :"); |
c69b251b N |
621 | |
622 | while (dir && (de = readdir(dir)) != NULL) { | |
ff9239ee | 623 | char path[287]; |
c69b251b N |
624 | char vbuf[1024]; |
625 | int nlen = strlen(sra->sys_name); | |
13db17bd | 626 | dev_t devid; |
c69b251b N |
627 | if (de->d_name[0] == '.') |
628 | continue; | |
5737086e JS |
629 | sprintf(path, |
630 | "/sys/block/%s/md/metadata_version", | |
c69b251b | 631 | de->d_name); |
193b6c0b | 632 | if (load_sys(path, vbuf, sizeof(vbuf)) < 0) |
c69b251b | 633 | continue; |
5737086e JS |
634 | if (strncmp(vbuf, "external:", 9) || |
635 | !is_subarray(vbuf + 9) || | |
636 | strncmp(vbuf + 10, sra->sys_name, nlen) || | |
637 | vbuf[10 + nlen] != '/') | |
c69b251b | 638 | continue; |
4dd2df09 | 639 | devid = devnm2devid(de->d_name); |
5737086e JS |
640 | printf(" %s", |
641 | map_dev_preferred(major(devid), | |
642 | minor(devid), 1, | |
643 | c->prefer)); | |
c69b251b N |
644 | } |
645 | if (dir) | |
646 | closedir(dir); | |
647 | printf("\n\n"); | |
648 | } | |
649 | ||
650 | if (array.raid_disks) | |
651 | printf(" Number Major Minor RaidDevice State\n"); | |
652 | else | |
653 | printf(" Number Major Minor RaidDevice\n"); | |
cd29a5c8 | 654 | } |
a1f976a0 | 655 | free(info); |
b0c63f32 | 656 | |
5737086e | 657 | for (d = 0; d < max_disks * 2; d++) { |
b0c63f32 NB |
658 | char *dv; |
659 | mdu_disk_info_t disk = disks[d]; | |
660 | ||
5737086e JS |
661 | if (d >= array.raid_disks * 2 && |
662 | disk.major == 0 && disk.minor == 0) | |
24c7bc84 | 663 | continue; |
5737086e | 664 | if ((d & 1) && disk.major == 0 && disk.minor == 0) |
e0d19036 | 665 | continue; |
ef898ce6 | 666 | if (!c->brief) { |
5737086e JS |
667 | if (d == array.raid_disks*2) |
668 | printf("\n"); | |
e652d1aa | 669 | if (disk.number < 0 && disk.raid_disk < 0) |
e6fc80a8 N |
670 | printf(" - %5d %5d - ", |
671 | disk.major, disk.minor); | |
5737086e JS |
672 | else if (disk.raid_disk < 0 || |
673 | disk.state & (1 << MD_DISK_JOURNAL)) | |
aba69144 | 674 | printf(" %5d %5d %5d - ", |
e5329c37 | 675 | disk.number, disk.major, disk.minor); |
78a5dc03 N |
676 | else if (disk.number < 0) |
677 | printf(" - %5d %5d %5d ", | |
678 | disk.major, disk.minor, disk.raid_disk); | |
e5329c37 | 679 | else |
aba69144 | 680 | printf(" %5d %5d %5d %5d ", |
5737086e JS |
681 | disk.number, disk.major, disk.minor, |
682 | disk.raid_disk); | |
c69b251b | 683 | } |
ef898ce6 | 684 | if (!c->brief && array.raid_disks) { |
5737086e | 685 | if (disk.state & (1 << MD_DISK_FAULTY)) { |
aba69144 | 686 | printf(" faulty"); |
e5329c37 NB |
687 | if (disk.raid_disk < array.raid_disks && |
688 | disk.raid_disk >= 0) | |
689 | failed++; | |
690 | } | |
5737086e JS |
691 | if (disk.state & (1 << MD_DISK_ACTIVE)) |
692 | printf(" active"); | |
693 | if (disk.state & (1 << MD_DISK_SYNC)) { | |
2c096ebe | 694 | printf(" sync"); |
5737086e JS |
695 | if (array.level == 10 && |
696 | (array.layout & ~0x1FFFF) == 0) { | |
2c096ebe N |
697 | int nc = array.layout & 0xff; |
698 | int fc = (array.layout >> 8) & 0xff; | |
699 | int copies = nc*fc; | |
5737086e JS |
700 | if (fc == 1 && |
701 | array.raid_disks % copies == 0 && | |
702 | copies <= 26) { | |
703 | /* We can divide the devices | |
704 | into 'sets' */ | |
705 | int set; | |
706 | set = disk.raid_disk % copies; | |
2c096ebe N |
707 | printf(" set-%c", set + 'A'); |
708 | } | |
709 | } | |
710 | } | |
5737086e JS |
711 | if (disk.state & (1 << MD_DISK_REMOVED)) |
712 | printf(" removed"); | |
713 | if (disk.state & (1 << MD_DISK_WRITEMOSTLY)) | |
714 | printf(" writemostly"); | |
715 | if (disk.state & (1 << MD_DISK_FAILFAST)) | |
716 | printf(" failfast"); | |
717 | if (disk.state & (1 << MD_DISK_JOURNAL)) | |
718 | printf(" journal"); | |
b0c63f32 | 719 | if ((disk.state & |
b831b299 JS |
720 | ((1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC) | |
721 | (1 << MD_DISK_REMOVED) | (1 << MD_DISK_FAULTY) | | |
722 | (1 << MD_DISK_JOURNAL))) == 0) { | |
b0c63f32 | 723 | printf(" spare"); |
5e13ef71 JS |
724 | if (disk.raid_disk < array.raid_disks && |
725 | disk.raid_disk >= 0) | |
726 | printf(" rebuilding"); | |
e5329c37 | 727 | } |
feb716e9 | 728 | } |
5737086e JS |
729 | if (disk.state == 0) |
730 | spares++; | |
731 | dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer); | |
ca3b6696 | 732 | if (dv != NULL) { |
b76dc299 MW |
733 | if (c->brief) |
734 | n_devices = add_device(dv, &devices, | |
5737086e | 735 | &max_devices, n_devices); |
b76dc299 | 736 | else |
d013a55e | 737 | printf(" %s", dv); |
82b27616 | 738 | } |
5737086e JS |
739 | if (!c->brief) |
740 | printf("\n"); | |
64c4757e | 741 | } |
5737086e JS |
742 | if (spares && c->brief && array.raid_disks) |
743 | printf(" spares=%d", spares); | |
ef898ce6 | 744 | if (c->brief && st && st->sb) |
3da92f27 | 745 | st->ss->brief_detail_super(st); |
db428d7a LD |
746 | if (st) |
747 | st->ss->free_super(st); | |
4b1ac34b | 748 | |
41a663b2 | 749 | if (c->brief && c->verbose > 0 && devices) { |
750 | qsort(devices, n_devices, sizeof(*devices), cmpstringp); | |
751 | printf("\n devices=%s", devices[0]); | |
752 | for (d = 1; d < n_devices; d++) | |
753 | printf(",%s", devices[d]); | |
754 | } | |
ef898ce6 N |
755 | if (c->brief) |
756 | printf("\n"); | |
757 | if (c->test && | |
5737086e | 758 | !enough(array.level, array.raid_disks, array.layout, 1, avail)) |
a77be586 NB |
759 | rv = 2; |
760 | ||
0eb26465 | 761 | free(disks); |
a328c097 | 762 | out: |
e5329c37 | 763 | close(fd); |
4725bc31 | 764 | free(subarray); |
d0673517 | 765 | free(avail); |
41a663b2 | 766 | for (d = 0; d < n_devices; d++) |
767 | free(devices[d]); | |
768 | free(devices); | |
5454b6f3 | 769 | sysfs_free(sra); |
feb716e9 | 770 | return rv; |
64c4757e | 771 | } |
4cce4069 | 772 | |
9eafa1de | 773 | int Detail_Platform(struct superswitch *ss, int scan, int verbose, int export, char *controller_path) |
4cce4069 DW |
774 | { |
775 | /* display platform capabilities for the given metadata format | |
776 | * 'scan' in this context means iterate over all metadata types | |
777 | */ | |
778 | int i; | |
779 | int err = 1; | |
780 | ||
e50cf220 | 781 | if (ss && export && ss->export_detail_platform) |
9eafa1de | 782 | err = ss->export_detail_platform(verbose, controller_path); |
e50cf220 | 783 | else if (ss && ss->detail_platform) |
9eafa1de | 784 | err = ss->detail_platform(verbose, 0, controller_path); |
4cce4069 | 785 | else if (ss) { |
ba728be7 | 786 | if (verbose > 0) |
e7b84f9d | 787 | pr_err("%s metadata is platform independent\n", |
4cce4069 DW |
788 | ss->name ? : "[no name]"); |
789 | } else if (!scan) { | |
ba728be7 | 790 | if (verbose > 0) |
e7b84f9d | 791 | pr_err("specify a metadata type or --scan\n"); |
4cce4069 DW |
792 | } |
793 | ||
794 | if (!scan) | |
795 | return err; | |
796 | ||
9590cb42 | 797 | err = 0; |
4cce4069 DW |
798 | for (i = 0; superlist[i]; i++) { |
799 | struct superswitch *meta = superlist[i]; | |
800 | ||
801 | if (meta == ss) | |
802 | continue; | |
ba728be7 | 803 | if (verbose > 0) |
e7b84f9d | 804 | pr_err("checking metadata %s\n", |
4cce4069 DW |
805 | meta->name ? : "[no name]"); |
806 | if (!meta->detail_platform) { | |
ba728be7 | 807 | if (verbose > 0) |
e7b84f9d | 808 | pr_err("%s metadata is platform independent\n", |
4cce4069 | 809 | meta->name ? : "[no name]"); |
e50cf220 | 810 | } else if (export && meta->export_detail_platform) { |
9eafa1de | 811 | err |= meta->export_detail_platform(verbose, controller_path); |
4cce4069 | 812 | } else |
9eafa1de | 813 | err |= meta->detail_platform(verbose, 0, controller_path); |
4cce4069 DW |
814 | } |
815 | ||
816 | return err; | |
817 | } |