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