]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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.
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.
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
22 * Email: <neilb@suse.de>
30 int Detail(char *dev
, int brief
, int export
, int test
, char *homehost
, char *prefer
)
33 * Print out details for an md array by using
34 * GET_ARRAY_INFO and GET_DISK_INFO ioctl calls
37 int fd
= open(dev
, O_RDONLY
);
39 mdu_array_info_t array
;
40 mdu_disk_info_t
*disks
;
48 int is_26
= get_linux_version() >= 2006000;
49 int is_rebuilding
= 0;
52 char *subarray
= NULL
;
53 int max_disks
= MD_SB_DISKS
; /* just a default */
54 struct mdinfo
*info
= NULL
;
57 char *container
= NULL
;
59 int rv
= test
? 4 : 1;
64 fprintf(stderr
, Name
": cannot open %s: %s\n",
65 dev
, strerror(errno
));
68 vers
= md_get_version(fd
);
70 fprintf(stderr
, Name
": %s does not appear to be an md device\n",
76 fprintf(stderr
, Name
": cannot get detail for md device %s: driver version too old.\n",
81 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)<0) {
83 fprintf(stderr
, Name
": md device %s does not appear to be active.\n",
86 fprintf(stderr
, Name
": cannot get array detail for %s: %s\n",
87 dev
, strerror(errno
));
91 sra
= sysfs_read(fd
, 0, GET_VERSION
);
92 st
= super_by_fd(fd
, &subarray
);
94 if (fstat(fd
, &stb
) != 0 && !S_ISBLK(stb
.st_mode
))
99 max_disks
= st
->max_devs
;
102 /* This is a subarray of some container.
103 * We want the name of the container, and the member
105 int dn
= st
->container_dev
;
108 container
= map_dev_preferred(dev2major(dn
), dev2minor(dn
), 1, prefer
);
111 /* try to load a superblock */
112 if (st
) for (d
= 0; d
< max_disks
; d
++) {
113 mdu_disk_info_t disk
;
118 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
120 if (d
>= array
.raid_disks
&&
125 if (array
.raid_disks
> 0 &&
126 (disk
.state
& (1 << MD_DISK_ACTIVE
)) == 0)
129 dv
= map_dev(disk
.major
, disk
.minor
, 1);
133 fd2
= dev_open(dv
, O_RDONLY
);
138 st
->ss
->free_super(st
);
140 err
= st
->ss
->load_super(st
, fd2
, NULL
);
147 info
= st
->ss
->container_content(st
, subarray
);
149 info
= malloc(sizeof(*info
));
150 st
->ss
->getinfo_super(st
, info
, NULL
);
155 if (array
.raid_disks
!= 0 && /* container */
156 (info
->array
.ctime
!= array
.ctime
||
157 info
->array
.level
!= array
.level
)) {
158 st
->ss
->free_super(st
);
161 /* some formats (imsm) have free-floating-spares
162 * with a uuid of uuid_zero, they don't
163 * have very good info about the rest of the
164 * container, so keep searching when
165 * encountering such a device. Otherwise, stop
166 * after the first successful call to
169 if (memcmp(uuid_zero
,
171 sizeof(uuid_zero
)) == 0) {
172 st
->ss
->free_super(st
);
178 /* Ok, we have some info to print... */
179 c
= map_num(pers
, array
.level
);
182 if (array
.raid_disks
) {
184 printf("MD_LEVEL=%s\n", c
);
185 printf("MD_DEVICES=%d\n", array
.raid_disks
);
187 printf("MD_LEVEL=container\n");
188 printf("MD_DEVICES=%d\n", array
.nr_disks
);
191 printf("MD_CONTAINER=%s\n", container
);
192 printf("MD_MEMBER=%s\n", member
);
194 if (sra
&& sra
->array
.major_version
< 0)
195 printf("MD_METADATA=%s\n", sra
->text_version
);
197 printf("MD_METADATA=%d.%d\n",
198 array
.major_version
, array
.minor_version
);
201 if (st
&& st
->sb
&& info
) {
203 struct map_ent
*mp
, *map
= NULL
;
205 fname_from_uuid(st
, info
, nbuf
, ':');
206 printf("MD_UUID=%s\n", nbuf
+5);
207 mp
= map_by_uuid(&map
, info
->uuid
);
208 if (mp
&& mp
->path
&&
209 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
210 printf("MD_DEVNAME=");
211 print_escape(mp
->path
+8);
215 if (st
->ss
->export_detail_super
)
216 st
->ss
->export_detail_super(st
);
218 struct map_ent
*mp
, *map
= NULL
;
220 mp
= map_by_devnum(&map
, fd2devnum(fd
));
222 __fname_from_uuid(mp
->uuid
, 0, nbuf
, ':');
223 printf("MD_UUID=%s\n", nbuf
+5);
225 if (mp
&& mp
->path
&&
226 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
227 printf("MD_DEVNAME=");
228 print_escape(mp
->path
+8);
235 disks
= malloc(max_disks
* sizeof(mdu_disk_info_t
));
236 for (d
=0; d
<max_disks
; d
++) {
237 disks
[d
].state
= (1<<MD_DISK_REMOVED
);
238 disks
[d
].major
= disks
[d
].minor
= 0;
239 disks
[d
].number
= disks
[d
].raid_disk
= d
;
242 next
= array
.raid_disks
;
243 for (d
=0; d
< max_disks
; d
++) {
244 mdu_disk_info_t disk
;
246 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
247 if (d
< array
.raid_disks
)
248 fprintf(stderr
, Name
": cannot get device detail for device %d: %s\n",
252 if (disk
.major
== 0 && disk
.minor
== 0)
254 if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
)
255 disks
[disk
.raid_disk
] = disk
;
256 else if (next
< max_disks
)
257 disks
[next
++] = disk
;
260 avail
= calloc(array
.raid_disks
, 1);
262 for (d
= 0; d
< array
.raid_disks
; d
++) {
263 mdu_disk_info_t disk
= disks
[d
];
265 if ((disk
.state
& (1<<MD_DISK_SYNC
))) {
272 mdu_bitmap_file_t bmf
;
273 printf("ARRAY %s", dev
);
275 if (array
.raid_disks
)
276 printf(" level=%s num-devices=%d",
280 printf(" level=container num-devices=%d",
284 printf(" container=%s", container
);
285 printf(" member=%s", member
);
287 if (sra
&& sra
->array
.major_version
< 0)
288 printf(" metadata=%s", sra
->text_version
);
290 printf(" metadata=%d.%d",
291 array
.major_version
, array
.minor_version
);
294 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
296 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
298 printf(" bitmap=%s", bmf
.pathname
);
301 mdu_bitmap_file_t bmf
;
302 unsigned long long larray_size
;
303 struct mdstat_ent
*ms
= mdstat_read(0, 0);
304 struct mdstat_ent
*e
;
305 int devnum
= array
.md_minor
;
306 if (major(stb
.st_rdev
) == (unsigned)get_mdp_major())
307 devnum
= -1 - devnum
;
309 for (e
=ms
; e
; e
=e
->next
)
310 if (e
->devnum
== devnum
)
312 if (!get_dev_size(fd
, NULL
, &larray_size
))
315 printf("%s:\n", dev
);
318 printf(" Container : %s, member %s\n", container
, member
);
320 if (sra
&& sra
->array
.major_version
< 0)
321 printf(" Version : %s\n", sra
->text_version
);
323 printf(" Version : %d.%d\n",
324 array
.major_version
, array
.minor_version
);
329 printf(" Creation Time : %.24s\n", ctime(&atime
));
330 if (array
.raid_disks
== 0) c
= "container";
331 printf(" Raid Level : %s\n", c
?c
:"-unknown-");
333 printf(" Array Size : %llu%s\n", (larray_size
>>10), human_size(larray_size
));
334 if (array
.level
>= 1) {
335 if (array
.major_version
!= 0 &&
336 (larray_size
>= 0xFFFFFFFFULL
|| array
.size
== 0)) {
337 unsigned long long dsize
= get_component_size(fd
);
339 printf(" Used Dev Size : %llu%s\n",
341 human_size((long long)dsize
<<9));
343 printf(" Used Dev Size : unknown\n");
345 printf(" Used Dev Size : %d%s\n", array
.size
,
346 human_size((long long)array
.size
<<10));
348 if (array
.raid_disks
)
349 printf(" Raid Devices : %d\n", array
.raid_disks
);
350 printf(" Total Devices : %d\n", array
.nr_disks
);
352 ((sra
== NULL
&& array
.major_version
== 0) ||
353 (sra
&& sra
->array
.major_version
== 0)))
354 printf("Preferred Minor : %d\n", array
.md_minor
);
355 if (sra
== NULL
|| sra
->array
.major_version
>= 0)
356 printf(" Persistence : Superblock is %spersistent\n",
357 array
.not_persistent
?"not ":"");
359 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
361 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
363 printf(" Intent Bitmap : %s\n", bmf
.pathname
);
365 } else if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
))
366 printf(" Intent Bitmap : Internal\n\n");
369 printf(" Update Time : %.24s\n", ctime(&atime
));
370 if (array
.raid_disks
) {
371 static char *sync_action
[] = {", recovering",", resyncing",", reshaping",", checking"};
373 if (avail_disks
== array
.raid_disks
)
375 else if (!enough(array
.level
, array
.raid_disks
,
376 array
.layout
, 1, avail
))
381 printf(" State : %s%s%s%s%s%s \n",
382 (array
.state
&(1<<MD_SB_CLEAN
))?"clean":"active", st
,
383 (!e
|| (e
->percent
< 0 && e
->percent
!= RESYNC_PENDING
&&
384 e
->percent
!= RESYNC_DELAYED
)) ? "" : sync_action
[e
->resync
],
385 larray_size
? "": ", Not Started",
386 e
->percent
== RESYNC_DELAYED
? " (DELAYED)": "",
387 e
->percent
== RESYNC_PENDING
? " (PENDING)": "");
389 if (array
.raid_disks
)
390 printf(" Active Devices : %d\n", array
.active_disks
);
391 printf("Working Devices : %d\n", array
.working_disks
);
392 if (array
.raid_disks
) {
393 printf(" Failed Devices : %d\n", array
.failed_disks
);
394 printf(" Spare Devices : %d\n", array
.spare_disks
);
397 if (array
.level
== 5) {
398 c
= map_num(r5layout
, array
.layout
);
399 printf(" Layout : %s\n", c
?c
:"-unknown-");
401 if (array
.level
== 6) {
402 c
= map_num(r6layout
, array
.layout
);
403 printf(" Layout : %s\n", c
?c
:"-unknown-");
405 if (array
.level
== 10) {
407 print_r10_layout(array
.layout
);
410 switch (array
.level
) {
416 if (array
.chunk_size
)
417 printf(" Chunk Size : %dK\n\n",
418 array
.chunk_size
/1024);
421 printf(" Rounding : %dK\n\n", array
.chunk_size
/1024);
426 if (e
&& e
->percent
>= 0) {
427 static char *sync_action
[] = {"Rebuild", "Resync", "Reshape", "Check"};
428 printf(" %7s Status : %d%% complete\n", sync_action
[e
->resync
], e
->percent
);
433 if ((st
&& st
->sb
) && (info
&& info
->reshape_active
)) {
435 This is pretty boring
436 printf(" Reshape pos'n : %llu%s\n", (unsigned long long) info
->reshape_progress
<<9,
437 human_size((unsigned long long)info
->reshape_progress
<<9));
439 if (info
->delta_disks
!= 0)
440 printf(" Delta Devices : %d, (%d->%d)\n",
441 info
->delta_disks
, array
.raid_disks
- info
->delta_disks
, array
.raid_disks
);
442 if (info
->new_level
!= array
.level
) {
443 char *c
= map_num(pers
, info
->new_level
);
444 printf(" New Level : %s\n", c
?c
:"-unknown-");
446 if (info
->new_level
!= array
.level
||
447 info
->new_layout
!= array
.layout
) {
448 if (info
->new_level
== 5) {
449 char *c
= map_num(r5layout
, info
->new_layout
);
450 printf(" New Layout : %s\n",
453 if (info
->new_level
== 6) {
454 char *c
= map_num(r6layout
, info
->new_layout
);
455 printf(" New Layout : %s\n",
458 if (info
->new_level
== 10) {
459 printf(" New Layout : near=%d, %s=%d\n",
460 info
->new_layout
&255,
461 (info
->new_layout
&0x10000)?"offset":"far",
462 (info
->new_layout
>>8)&255);
465 if (info
->new_chunk
!= array
.chunk_size
)
466 printf(" New Chunksize : %dK\n", info
->new_chunk
/1024);
468 } else if (e
&& e
->percent
>= 0)
471 st
->ss
->detail_super(st
, homehost
);
473 if (array
.raid_disks
== 0 && sra
&& sra
->array
.major_version
== -1
474 && sra
->array
.minor_version
== -2 && sra
->text_version
[0] != '/') {
475 /* This looks like a container. Find any active arrays
476 * That claim to be a member.
478 DIR *dir
= opendir("/sys/block");
481 printf(" Member Arrays :");
483 while (dir
&& (de
= readdir(dir
)) != NULL
) {
486 int nlen
= strlen(sra
->sys_name
);
488 if (de
->d_name
[0] == '.')
490 sprintf(path
, "/sys/block/%s/md/metadata_version",
492 if (load_sys(path
, vbuf
) < 0)
494 if (strncmp(vbuf
, "external:", 9) != 0 ||
495 !is_subarray(vbuf
+9) ||
496 strncmp(vbuf
+10, sra
->sys_name
, nlen
) != 0 ||
497 vbuf
[10+nlen
] != '/')
499 dn
= devname2devnum(de
->d_name
);
500 printf(" %s", map_dev_preferred(
502 dev2minor(dn
), 1, prefer
));
509 if (array
.raid_disks
)
510 printf(" Number Major Minor RaidDevice State\n");
512 printf(" Number Major Minor RaidDevice\n");
516 for (d
= 0; d
< max_disks
; d
++) {
518 mdu_disk_info_t disk
= disks
[d
];
520 if (d
>= array
.raid_disks
&&
525 if (d
== array
.raid_disks
) printf("\n");
526 if (disk
.raid_disk
< 0)
527 printf(" %5d %5d %5d - ",
528 disk
.number
, disk
.major
, disk
.minor
);
530 printf(" %5d %5d %5d %5d ",
531 disk
.number
, disk
.major
, disk
.minor
, disk
.raid_disk
);
533 if (!brief
&& array
.raid_disks
) {
535 if (disk
.state
& (1<<MD_DISK_FAULTY
)) {
537 if (disk
.raid_disk
< array
.raid_disks
&&
541 if (disk
.state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
542 if (disk
.state
& (1<<MD_DISK_SYNC
)) printf(" sync");
543 if (disk
.state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
544 if (disk
.state
& (1<<MD_DISK_WRITEMOSTLY
)) printf(" writemostly");
546 ((1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
)
547 |(1<<MD_DISK_REMOVED
)|(1<<MD_DISK_FAULTY
)))
551 if (disk
.raid_disk
< array
.raid_disks
&& disk
.raid_disk
>= 0)
552 printf(" rebuilding");
553 } else if (is_rebuilding
&& failed
) {
554 /* Taking a bit of a risk here, we remove the
555 * device from the array, and then put it back.
556 * If this fails, we are rebuilding
558 int err
= ioctl(fd
, HOT_REMOVE_DISK
, makedev(disk
.major
, disk
.minor
));
559 if (err
== 0) ioctl(fd
, HOT_ADD_DISK
, makedev(disk
.major
, disk
.minor
));
560 if (err
&& errno
== EBUSY
)
561 printf(" rebuilding");
565 if (disk
.state
== 0) spares
++;
566 if (test
&& d
< array
.raid_disks
567 && !(disk
.state
& (1<<MD_DISK_SYNC
)))
569 if ((dv
=map_dev_preferred(disk
.major
, disk
.minor
, 0, prefer
))) {
572 devices
= realloc(devices
,
573 strlen(devices
)+1+strlen(dv
)+1);
574 strcat(strcat(devices
,","),dv
);
576 devices
= strdup(dv
);
580 if (!brief
) printf("\n");
582 if (spares
&& brief
&& array
.raid_disks
) printf(" spares=%d", spares
);
583 if (brief
&& st
&& st
->sb
)
584 st
->ss
->brief_detail_super(st
);
586 st
->ss
->free_super(st
);
588 if (brief
> 1 && devices
) printf("\n devices=%s", devices
);
589 if (brief
) printf("\n");
591 !enough(array
.level
, array
.raid_disks
, array
.layout
,
604 int Detail_Platform(struct superswitch
*ss
, int scan
, int verbose
)
606 /* display platform capabilities for the given metadata format
607 * 'scan' in this context means iterate over all metadata types
612 if (ss
&& ss
->detail_platform
)
613 err
= ss
->detail_platform(verbose
, 0);
616 fprintf(stderr
, Name
": %s metadata is platform independent\n",
617 ss
->name
? : "[no name]");
620 fprintf(stderr
, Name
": specify a metadata type or --scan\n");
626 for (i
= 0; superlist
[i
]; i
++) {
627 struct superswitch
*meta
= superlist
[i
];
632 fprintf(stderr
, Name
": checking metadata %s\n",
633 meta
->name
? : "[no name]");
634 if (!meta
->detail_platform
) {
636 fprintf(stderr
, Name
": %s metadata is platform independent\n",
637 meta
->name
? : "[no name]");
639 err
|= meta
->detail_platform(verbose
, 0);