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