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