]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2013 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 static int cmpstringp(const void *p1
, const void *p2
)
32 return strcmp(* (char * const *) p1
, * (char * const *) p2
);
35 static int add_device(const char *dev
, char ***p_devices
,
36 int *p_max_devices
, int n_devices
)
38 if (n_devices
+ 1 >= *p_max_devices
) {
40 *p_devices
= xrealloc(*p_devices
, *p_max_devices
*
47 (*p_devices
)[n_devices
] = xstrdup(dev
);
51 int Detail(char *dev
, struct context
*c
)
54 * Print out details for an md array by using
55 * GET_ARRAY_INFO and GET_DISK_INFO ioctl calls
58 int fd
= open(dev
, O_RDONLY
);
60 mdu_array_info_t array
;
61 mdu_disk_info_t
*disks
;
66 char **devices
= NULL
;
67 int max_devices
= 0, n_devices
= 0;
70 int is_26
= get_linux_version() >= 2006000;
71 int is_rebuilding
= 0;
74 char *subarray
= NULL
;
75 int max_disks
= MD_SB_DISKS
; /* just a default */
76 struct mdinfo
*info
= NULL
;
78 struct mdinfo
*subdev
;
80 char *container
= NULL
;
82 int rv
= c
->test
? 4 : 1;
89 pr_err("cannot open %s: %s\n",
90 dev
, strerror(errno
));
93 vers
= md_get_version(fd
);
95 pr_err("%s does not appear to be an md device\n",
101 pr_err("cannot get detail for md device %s: driver version too old.\n",
106 sra
= sysfs_read(fd
, NULL
, GET_VERSION
|GET_DEVS
);
107 external
= (sra
!= NULL
&& sra
->array
.major_version
== -1
108 && sra
->array
.minor_version
== -2);
109 st
= super_by_fd(fd
, &subarray
);
110 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) == 0) {
112 } else if (errno
== ENODEV
&& sra
) {
113 if (sra
->array
.major_version
== -1 &&
114 sra
->array
.minor_version
== -1 &&
116 pr_err("Array associated with md device %s does not exist.\n", dev
);
124 pr_err("cannot get array detail for %s: %s\n",
125 dev
, strerror(errno
));
130 if (fstat(fd
, &stb
) != 0 && !S_ISBLK(stb
.st_mode
))
135 max_disks
= st
->max_devs
;
138 /* This is a subarray of some container.
139 * We want the name of the container, and the member
141 dev_t devid
= devnm2devid(st
->container_devnm
);
145 container
= map_dev_preferred(major(devid
), minor(devid
),
147 cfd
= open_dev(st
->container_devnm
);
149 err
= st
->ss
->load_container(st
, cfd
, NULL
);
152 info
= st
->ss
->container_content(st
, subarray
);
156 /* try to load a superblock. Try sra->devs first, then try ioctl */
157 if (st
&& !info
) for (d
= 0, subdev
= sra
? sra
->devs
: NULL
;
158 d
< max_disks
|| subdev
;
159 subdev
? (void)(subdev
= subdev
->next
) : (void)(d
++)){
160 mdu_disk_info_t disk
;
168 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
170 if (d
>= array
.raid_disks
&&
176 if (array
.raid_disks
> 0 &&
177 (disk
.state
& (1 << MD_DISK_ACTIVE
)) == 0)
180 dv
= map_dev(disk
.major
, disk
.minor
, 1);
184 fd2
= dev_open(dv
, O_RDONLY
);
189 st
->ss
->free_super(st
);
191 err
= st
->ss
->load_super(st
, fd2
, NULL
);
198 info
= st
->ss
->container_content(st
, subarray
);
200 info
= xmalloc(sizeof(*info
));
201 st
->ss
->getinfo_super(st
, info
, NULL
);
206 if (array
.raid_disks
!= 0 && /* container */
207 (info
->array
.ctime
!= array
.ctime
||
208 info
->array
.level
!= array
.level
)) {
209 st
->ss
->free_super(st
);
212 /* some formats (imsm) have free-floating-spares
213 * with a uuid of uuid_zero, they don't
214 * have very good info about the rest of the
215 * container, so keep searching when
216 * encountering such a device. Otherwise, stop
217 * after the first successful call to
220 if (memcmp(uuid_zero
,
222 sizeof(uuid_zero
)) == 0) {
223 st
->ss
->free_super(st
);
229 /* Ok, we have some info to print... */
230 str
= map_num(pers
, array
.level
);
233 if (array
.raid_disks
) {
235 printf("MD_LEVEL=%s\n", str
);
236 printf("MD_DEVICES=%d\n", array
.raid_disks
);
239 printf("MD_LEVEL=container\n");
240 printf("MD_DEVICES=%d\n", array
.nr_disks
);
243 printf("MD_CONTAINER=%s\n", container
);
244 printf("MD_MEMBER=%s\n", member
);
246 if (sra
&& sra
->array
.major_version
< 0)
247 printf("MD_METADATA=%s\n", sra
->text_version
);
249 printf("MD_METADATA=%d.%d\n",
250 array
.major_version
, array
.minor_version
);
253 if (st
&& st
->sb
&& info
) {
255 struct map_ent
*mp
, *map
= NULL
;
257 fname_from_uuid(st
, info
, nbuf
, ':');
258 printf("MD_UUID=%s\n", nbuf
+5);
259 mp
= map_by_uuid(&map
, info
->uuid
);
260 if (mp
&& mp
->path
&&
261 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
262 printf("MD_DEVNAME=");
263 print_escape(mp
->path
+8);
267 if (st
->ss
->export_detail_super
)
268 st
->ss
->export_detail_super(st
);
270 struct map_ent
*mp
, *map
= NULL
;
272 mp
= map_by_devnm(&map
, fd2devnm(fd
));
274 __fname_from_uuid(mp
->uuid
, 0, nbuf
, ':');
275 printf("MD_UUID=%s\n", nbuf
+5);
277 if (mp
&& mp
->path
&&
278 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
279 printf("MD_DEVNAME=");
280 print_escape(mp
->path
+8);
286 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
288 map_dev(mdi
->disk
.major
,
291 if (mdi
->disk
.raid_disk
>= 0)
292 printf("MD_DEVICE_%s_ROLE=%d\n",
294 mdi
->disk
.raid_disk
);
296 printf("MD_DEVICE_%s_ROLE=spare\n",
299 printf("MD_DEVICE_%s_DEV=%s\n",
300 mdi
->sys_name
+4, path
);
306 disks
= xmalloc(max_disks
* 2 * sizeof(mdu_disk_info_t
));
307 for (d
= 0; d
< max_disks
* 2; d
++) {
308 disks
[d
].state
= (1<<MD_DISK_REMOVED
);
309 disks
[d
].major
= disks
[d
].minor
= 0;
310 disks
[d
].number
= -1;
311 disks
[d
].raid_disk
= d
/2;
314 next
= array
.raid_disks
*2;
318 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
319 disks
[next
++] = mdi
->disk
;
320 disks
[next
-1].number
= -1;
322 } else for (d
= 0; d
< max_disks
; d
++) {
323 mdu_disk_info_t disk
;
325 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
326 if (d
< array
.raid_disks
)
327 pr_err("cannot get device detail for device %d: %s\n",
331 if (disk
.major
== 0 && disk
.minor
== 0)
333 if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
334 && disks
[disk
.raid_disk
*2].state
== (1<<MD_DISK_REMOVED
)
335 && ((disk
.state
& (1<<MD_DISK_JOURNAL
)) == 0))
336 disks
[disk
.raid_disk
*2] = disk
;
337 else if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
338 && disks
[disk
.raid_disk
*2+1].state
== (1<<MD_DISK_REMOVED
)
339 && !(disk
.state
& (1<<MD_DISK_JOURNAL
)))
340 disks
[disk
.raid_disk
*2+1] = disk
;
341 else if (next
< max_disks
*2)
342 disks
[next
++] = disk
;
345 avail
= xcalloc(array
.raid_disks
, 1);
347 for (d
= 0; d
< array
.raid_disks
; d
++) {
349 if ((disks
[d
*2].state
& (1<<MD_DISK_SYNC
)) ||
350 (disks
[d
*2+1].state
& (1<<MD_DISK_SYNC
))) {
358 mdu_bitmap_file_t bmf
;
359 printf("%sARRAY %s", inactive
? "INACTIVE-":"", dev
);
360 if (c
->verbose
> 0) {
361 if (array
.raid_disks
)
362 printf(" level=%s num-devices=%d",
366 printf(" level=container num-devices=%d",
369 printf(" num-devices=%d", array
.nr_disks
);
372 printf(" container=%s", container
);
373 printf(" member=%s", member
);
375 if (sra
&& sra
->array
.major_version
< 0)
376 printf(" metadata=%s", sra
->text_version
);
378 printf(" metadata=%d.%d",
379 array
.major_version
, array
.minor_version
);
382 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
384 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
386 printf(" bitmap=%s", bmf
.pathname
);
389 mdu_bitmap_file_t bmf
;
390 unsigned long long larray_size
;
391 struct mdstat_ent
*ms
= mdstat_read(0, 0);
392 struct mdstat_ent
*e
;
395 devnm
= stat2devnm(&stb
);
396 for (e
=ms
; e
; e
=e
->next
)
397 if (strcmp(e
->devnm
, devnm
) == 0)
399 if (!get_dev_size(fd
, NULL
, &larray_size
))
402 printf("%s:\n", dev
);
405 printf(" Container : %s, member %s\n", container
,
408 if (sra
&& sra
->array
.major_version
< 0)
409 printf(" Version : %s\n", sra
->text_version
);
411 printf(" Version : %d.%d\n",
412 array
.major_version
, array
.minor_version
);
417 printf(" Creation Time : %.24s\n", ctime(&atime
));
418 if (array
.raid_disks
== 0 && external
)
421 printf(" Raid Level : %s\n", str
);
423 printf(" Array Size : %llu%s\n", (larray_size
>>10),
424 human_size(larray_size
));
425 if (array
.level
>= 1) {
427 array
.major_version
= sra
->array
.major_version
;
428 if (array
.major_version
!= 0 &&
429 (larray_size
>= 0xFFFFFFFFULL
|| array
.size
== 0)) {
430 unsigned long long dsize
= get_component_size(fd
);
432 printf(" Used Dev Size : %llu%s\n",
434 human_size((long long)dsize
<<9));
436 printf(" Used Dev Size : unknown\n");
438 printf(" Used Dev Size : %lu%s\n",
439 (unsigned long)array
.size
,
440 human_size((unsigned long long)array
.size
<<10));
442 if (array
.raid_disks
)
443 printf(" Raid Devices : %d\n", array
.raid_disks
);
444 printf(" Total Devices : %d\n", array
.nr_disks
);
446 ((sra
== NULL
&& array
.major_version
== 0) ||
447 (sra
&& sra
->array
.major_version
== 0)))
448 printf(" Preferred Minor : %d\n", array
.md_minor
);
449 if (sra
== NULL
|| sra
->array
.major_version
>= 0)
450 printf(" Persistence : Superblock is %spersistent\n",
451 array
.not_persistent
?"not ":"");
453 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
455 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
457 printf(" Intent Bitmap : %s\n", bmf
.pathname
);
459 } else if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
))
460 printf(" Intent Bitmap : Internal\n\n");
463 printf(" Update Time : %.24s\n", ctime(&atime
));
464 if (array
.raid_disks
) {
465 static char *sync_action
[] = {
466 ", recovering", ", resyncing",
467 ", reshaping", ", checking" };
469 if (avail_disks
== array
.raid_disks
)
471 else if (!enough(array
.level
, array
.raid_disks
,
472 array
.layout
, 1, avail
))
477 printf(" State : %s%s%s%s%s%s \n",
478 (array
.state
&(1<<MD_SB_CLEAN
))?"clean":"active", st
,
479 (!e
|| (e
->percent
< 0 && e
->percent
!= RESYNC_PENDING
&&
480 e
->percent
!= RESYNC_DELAYED
)) ? "" : sync_action
[e
->resync
],
481 larray_size
? "": ", Not Started",
482 (e
&& e
->percent
== RESYNC_DELAYED
) ? " (DELAYED)": "",
483 (e
&& e
->percent
== RESYNC_PENDING
) ? " (PENDING)": "");
484 } else if (inactive
) {
485 printf(" State : inactive\n");
487 if (array
.raid_disks
)
488 printf(" Active Devices : %d\n", array
.active_disks
);
489 if (array
.working_disks
> 0)
490 printf(" Working Devices : %d\n", array
.working_disks
);
491 if (array
.raid_disks
) {
492 printf(" Failed Devices : %d\n", array
.failed_disks
);
493 printf(" Spare Devices : %d\n", array
.spare_disks
);
496 if (array
.level
== 5) {
497 str
= map_num(r5layout
, array
.layout
);
498 printf(" Layout : %s\n", str
?str
:"-unknown-");
500 if (array
.level
== 6) {
501 str
= map_num(r6layout
, array
.layout
);
502 printf(" Layout : %s\n", str
?str
:"-unknown-");
504 if (array
.level
== 10) {
506 print_r10_layout(array
.layout
);
509 switch (array
.level
) {
515 if (array
.chunk_size
)
516 printf(" Chunk Size : %dK\n\n",
517 array
.chunk_size
/1024);
520 printf(" Rounding : %dK\n\n",
521 array
.chunk_size
/1024);
526 if (array
.raid_disks
) {
527 struct mdinfo
*mdi
= sysfs_read(fd
, NULL
,
528 GET_CONSISTENCY_POLICY
);
530 char *policy
= map_num(consistency_policies
,
531 mdi
->consistency_policy
);
534 printf("Consistency Policy : %s\n\n",
539 if (e
&& e
->percent
>= 0) {
540 static char *sync_action
[] = {
543 printf(" %7s Status : %d%% complete\n",
544 sync_action
[e
->resync
], e
->percent
);
549 if ((st
&& st
->sb
) && (info
&& info
->reshape_active
)) {
551 This is pretty boring
552 printf(" Reshape pos'n : %llu%s\n",
553 (unsigned long long) info
->reshape_progress
<<9,
554 human_size((unsigned long long)info
->reshape_progress
<<9));
556 if (info
->delta_disks
!= 0)
557 printf(" Delta Devices : %d, (%d->%d)\n",
559 array
.raid_disks
- info
->delta_disks
,
561 if (info
->new_level
!= array
.level
) {
562 str
= map_num(pers
, info
->new_level
);
563 printf(" New Level : %s\n", str
?str
:"-unknown-");
565 if (info
->new_level
!= array
.level
||
566 info
->new_layout
!= array
.layout
) {
567 if (info
->new_level
== 5) {
568 str
= map_num(r5layout
, info
->new_layout
);
569 printf(" New Layout : %s\n",
570 str
?str
:"-unknown-");
572 if (info
->new_level
== 6) {
573 str
= map_num(r6layout
, info
->new_layout
);
574 printf(" New Layout : %s\n",
575 str
?str
:"-unknown-");
577 if (info
->new_level
== 10) {
578 printf(" New Layout : near=%d, %s=%d\n",
579 info
->new_layout
&255,
580 (info
->new_layout
&0x10000)?"offset":"far",
581 (info
->new_layout
>>8)&255);
584 if (info
->new_chunk
!= array
.chunk_size
)
585 printf(" New Chunksize : %dK\n",
586 info
->new_chunk
/1024);
588 } else if (e
&& e
->percent
>= 0)
591 st
->ss
->detail_super(st
, c
->homehost
);
593 if (array
.raid_disks
== 0 && sra
&& sra
->array
.major_version
== -1
594 && sra
->array
.minor_version
== -2 && sra
->text_version
[0] != '/') {
595 /* This looks like a container. Find any active arrays
596 * That claim to be a member.
598 DIR *dir
= opendir("/sys/block");
601 printf(" Member Arrays :");
603 while (dir
&& (de
= readdir(dir
)) != NULL
) {
606 int nlen
= strlen(sra
->sys_name
);
608 if (de
->d_name
[0] == '.')
610 sprintf(path
, "/sys/block/%s/md/metadata_version",
612 if (load_sys(path
, vbuf
, sizeof(vbuf
)) < 0)
614 if (strncmp(vbuf
, "external:", 9) != 0 ||
615 !is_subarray(vbuf
+9) ||
616 strncmp(vbuf
+10, sra
->sys_name
, nlen
) != 0 ||
617 vbuf
[10+nlen
] != '/')
619 devid
= devnm2devid(de
->d_name
);
620 printf(" %s", map_dev_preferred(
622 minor(devid
), 1, c
->prefer
));
629 if (array
.raid_disks
)
630 printf(" Number Major Minor RaidDevice State\n");
632 printf(" Number Major Minor RaidDevice\n");
636 for (d
= 0; d
< max_disks
* 2; d
++) {
638 mdu_disk_info_t disk
= disks
[d
];
640 if (d
>= array
.raid_disks
*2 &&
649 if (d
== array
.raid_disks
*2) printf("\n");
650 if (disk
.number
< 0 && disk
.raid_disk
< 0)
651 printf(" - %5d %5d - ",
652 disk
.major
, disk
.minor
);
653 else if (disk
.raid_disk
< 0 || disk
.state
& (1<<MD_DISK_JOURNAL
))
654 printf(" %5d %5d %5d - ",
655 disk
.number
, disk
.major
, disk
.minor
);
656 else if (disk
.number
< 0)
657 printf(" - %5d %5d %5d ",
658 disk
.major
, disk
.minor
, disk
.raid_disk
);
660 printf(" %5d %5d %5d %5d ",
661 disk
.number
, disk
.major
, disk
.minor
, disk
.raid_disk
);
663 if (!c
->brief
&& array
.raid_disks
) {
665 if (disk
.state
& (1<<MD_DISK_FAULTY
)) {
667 if (disk
.raid_disk
< array
.raid_disks
&&
671 if (disk
.state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
672 if (disk
.state
& (1<<MD_DISK_SYNC
)) {
674 if (array
.level
== 10 && (array
.layout
& ~0x1FFFF) == 0) {
675 int nc
= array
.layout
& 0xff;
676 int fc
= (array
.layout
>> 8) & 0xff;
678 if (fc
== 1 && array
.raid_disks
% copies
== 0 && copies
<= 26) {
679 /* We can divide the devices into 'sets' */
680 int set
= disk
.raid_disk
% copies
;
681 printf(" set-%c", set
+ 'A');
685 if (disk
.state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
686 if (disk
.state
& (1<<MD_DISK_WRITEMOSTLY
)) printf(" writemostly");
687 if (disk
.state
& (1<<MD_DISK_FAILFAST
)) printf(" failfast");
688 if (disk
.state
& (1<<MD_DISK_JOURNAL
)) printf(" journal");
690 ((1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
)
691 |(1<<MD_DISK_REMOVED
)|(1<<MD_DISK_FAULTY
)|(1<<MD_DISK_JOURNAL
)))
695 if (disk
.raid_disk
< array
.raid_disks
&& disk
.raid_disk
>= 0)
696 printf(" rebuilding");
697 } else if (is_rebuilding
&& failed
) {
698 /* Taking a bit of a risk here, we remove the
699 * device from the array, and then put it back.
700 * If this fails, we are rebuilding
702 int err
= ioctl(fd
, HOT_REMOVE_DISK
, makedev(disk
.major
, disk
.minor
));
703 if (err
== 0) ioctl(fd
, HOT_ADD_DISK
, makedev(disk
.major
, disk
.minor
));
704 if (err
&& errno
== EBUSY
)
705 printf(" rebuilding");
709 if (disk
.state
== 0) spares
++;
710 dv
=map_dev_preferred(disk
.major
, disk
.minor
, 0, c
->prefer
);
713 n_devices
= add_device(dv
, &devices
,
719 if (!c
->brief
) printf("\n");
721 if (spares
&& c
->brief
&& array
.raid_disks
) printf(" spares=%d", spares
);
722 if (c
->brief
&& st
&& st
->sb
)
723 st
->ss
->brief_detail_super(st
);
725 st
->ss
->free_super(st
);
727 if (c
->brief
&& c
->verbose
> 0 && devices
) {
728 qsort(devices
, n_devices
, sizeof(*devices
), cmpstringp
);
729 printf("\n devices=%s", devices
[0]);
730 for (d
= 1; d
< n_devices
; d
++)
731 printf(",%s", devices
[d
]);
736 !enough(array
.level
, array
.raid_disks
, array
.layout
,
745 for (d
= 0; d
< n_devices
; d
++)
752 int Detail_Platform(struct superswitch
*ss
, int scan
, int verbose
, int export
, char *controller_path
)
754 /* display platform capabilities for the given metadata format
755 * 'scan' in this context means iterate over all metadata types
760 if (ss
&& export
&& ss
->export_detail_platform
)
761 err
= ss
->export_detail_platform(verbose
, controller_path
);
762 else if (ss
&& ss
->detail_platform
)
763 err
= ss
->detail_platform(verbose
, 0, controller_path
);
766 pr_err("%s metadata is platform independent\n",
767 ss
->name
? : "[no name]");
770 pr_err("specify a metadata type or --scan\n");
777 for (i
= 0; superlist
[i
]; i
++) {
778 struct superswitch
*meta
= superlist
[i
];
783 pr_err("checking metadata %s\n",
784 meta
->name
? : "[no name]");
785 if (!meta
->detail_platform
) {
787 pr_err("%s metadata is platform independent\n",
788 meta
->name
? : "[no name]");
789 } else if (export
&& meta
->export_detail_platform
) {
790 err
|= meta
->export_detail_platform(verbose
, controller_path
);
792 err
|= meta
->detail_platform(verbose
, 0, controller_path
);