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