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