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