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