]>
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
56 int fd
= open(dev
, O_RDONLY
);
57 mdu_array_info_t array
;
58 mdu_disk_info_t
*disks
;
63 char **devices
= NULL
;
64 int max_devices
= 0, n_devices
= 0;
69 char *subarray
= NULL
;
70 int max_disks
= MD_SB_DISKS
; /* just a default */
71 struct mdinfo
*info
= NULL
;
73 struct mdinfo
*subdev
;
75 char *container
= NULL
;
77 int rv
= c
->test
? 4 : 1;
84 pr_err("cannot open %s: %s\n",
85 dev
, strerror(errno
));
88 sra
= sysfs_read(fd
, NULL
, GET_VERSION
|GET_DEVS
);
90 pr_err("%s does not appear to be an md device\n", dev
);
94 external
= (sra
!= NULL
&& sra
->array
.major_version
== -1 &&
95 sra
->array
.minor_version
== -2);
96 st
= super_by_fd(fd
, &subarray
);
97 if (md_get_array_info(fd
, &array
) == 0) {
99 } else if (errno
== ENODEV
&& sra
) {
100 if (sra
->array
.major_version
== -1 &&
101 sra
->array
.minor_version
== -1 &&
103 pr_err("Array associated with md device %s does not exist.\n", dev
);
111 pr_err("cannot get array detail for %s: %s\n",
112 dev
, strerror(errno
));
117 if (fstat(fd
, &stb
) != 0 && !S_ISBLK(stb
.st_mode
))
122 max_disks
= st
->max_devs
;
125 /* This is a subarray of some container.
126 * We want the name of the container, and the member
128 dev_t devid
= devnm2devid(st
->container_devnm
);
132 container
= map_dev_preferred(major(devid
), minor(devid
),
134 cfd
= open_dev(st
->container_devnm
);
136 err
= st
->ss
->load_container(st
, cfd
, NULL
);
139 info
= st
->ss
->container_content(st
, subarray
);
143 /* try to load a superblock. Try sra->devs first, then try ioctl */
144 if (st
&& !info
) for (d
= 0, subdev
= sra
? sra
->devs
: NULL
;
145 d
< max_disks
|| subdev
;
146 subdev
? (void)(subdev
= subdev
->next
) : (void)(d
++)){
147 mdu_disk_info_t disk
;
155 if (md_get_disk_info(fd
, &disk
) < 0)
157 if (d
>= array
.raid_disks
&&
163 if (array
.raid_disks
> 0 &&
164 (disk
.state
& (1 << MD_DISK_ACTIVE
)) == 0)
167 dv
= map_dev(disk
.major
, disk
.minor
, 1);
171 fd2
= dev_open(dv
, O_RDONLY
);
176 st
->ss
->free_super(st
);
178 err
= st
->ss
->load_super(st
, fd2
, NULL
);
185 info
= st
->ss
->container_content(st
, subarray
);
187 info
= xmalloc(sizeof(*info
));
188 st
->ss
->getinfo_super(st
, info
, NULL
);
193 if (array
.raid_disks
!= 0 && /* container */
194 (info
->array
.ctime
!= array
.ctime
||
195 info
->array
.level
!= array
.level
)) {
196 st
->ss
->free_super(st
);
199 /* some formats (imsm) have free-floating-spares
200 * with a uuid of uuid_zero, they don't
201 * have very good info about the rest of the
202 * container, so keep searching when
203 * encountering such a device. Otherwise, stop
204 * after the first successful call to
207 if (memcmp(uuid_zero
,
209 sizeof(uuid_zero
)) == 0) {
210 st
->ss
->free_super(st
);
216 /* Ok, we have some info to print... */
217 str
= map_num(pers
, array
.level
);
220 if (array
.raid_disks
) {
222 printf("MD_LEVEL=%s\n", str
);
223 printf("MD_DEVICES=%d\n", array
.raid_disks
);
226 printf("MD_LEVEL=container\n");
227 printf("MD_DEVICES=%d\n", array
.nr_disks
);
230 printf("MD_CONTAINER=%s\n", container
);
231 printf("MD_MEMBER=%s\n", member
);
233 if (sra
&& sra
->array
.major_version
< 0)
234 printf("MD_METADATA=%s\n", sra
->text_version
);
236 printf("MD_METADATA=%d.%d\n",
237 array
.major_version
, array
.minor_version
);
240 if (st
&& st
->sb
&& info
) {
242 struct map_ent
*mp
, *map
= NULL
;
244 fname_from_uuid(st
, info
, nbuf
, ':');
245 printf("MD_UUID=%s\n", nbuf
+5);
246 mp
= map_by_uuid(&map
, info
->uuid
);
247 if (mp
&& mp
->path
&&
248 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
249 printf("MD_DEVNAME=");
250 print_escape(mp
->path
+8);
254 if (st
->ss
->export_detail_super
)
255 st
->ss
->export_detail_super(st
);
257 struct map_ent
*mp
, *map
= NULL
;
259 mp
= map_by_devnm(&map
, fd2devnm(fd
));
261 __fname_from_uuid(mp
->uuid
, 0, nbuf
, ':');
262 printf("MD_UUID=%s\n", nbuf
+5);
264 if (mp
&& mp
->path
&&
265 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
266 printf("MD_DEVNAME=");
267 print_escape(mp
->path
+8);
273 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
275 map_dev(mdi
->disk
.major
,
278 if (mdi
->disk
.raid_disk
>= 0)
279 printf("MD_DEVICE_%s_ROLE=%d\n",
281 mdi
->disk
.raid_disk
);
283 printf("MD_DEVICE_%s_ROLE=spare\n",
286 printf("MD_DEVICE_%s_DEV=%s\n",
287 mdi
->sys_name
+4, path
);
293 disks
= xmalloc(max_disks
* 2 * sizeof(mdu_disk_info_t
));
294 for (d
= 0; d
< max_disks
* 2; d
++) {
295 disks
[d
].state
= (1<<MD_DISK_REMOVED
);
296 disks
[d
].major
= disks
[d
].minor
= 0;
297 disks
[d
].number
= -1;
298 disks
[d
].raid_disk
= d
/2;
301 next
= array
.raid_disks
*2;
305 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
306 disks
[next
++] = mdi
->disk
;
307 disks
[next
-1].number
= -1;
309 } else for (d
= 0; d
< max_disks
; d
++) {
310 mdu_disk_info_t disk
;
312 if (md_get_disk_info(fd
, &disk
) < 0) {
313 if (d
< array
.raid_disks
)
314 pr_err("cannot get device detail for device %d: %s\n",
318 if (disk
.major
== 0 && disk
.minor
== 0)
320 if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
321 && disks
[disk
.raid_disk
*2].state
== (1<<MD_DISK_REMOVED
)
322 && ((disk
.state
& (1<<MD_DISK_JOURNAL
)) == 0))
323 disks
[disk
.raid_disk
*2] = disk
;
324 else if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
325 && disks
[disk
.raid_disk
*2+1].state
== (1<<MD_DISK_REMOVED
)
326 && !(disk
.state
& (1<<MD_DISK_JOURNAL
)))
327 disks
[disk
.raid_disk
*2+1] = disk
;
328 else if (next
< max_disks
*2)
329 disks
[next
++] = disk
;
332 avail
= xcalloc(array
.raid_disks
, 1);
334 for (d
= 0; d
< array
.raid_disks
; d
++) {
336 if ((disks
[d
*2].state
& (1<<MD_DISK_SYNC
)) ||
337 (disks
[d
*2+1].state
& (1<<MD_DISK_SYNC
))) {
345 mdu_bitmap_file_t bmf
;
346 printf("%sARRAY %s", inactive
? "INACTIVE-":"", dev
);
347 if (c
->verbose
> 0) {
348 if (array
.raid_disks
)
349 printf(" level=%s num-devices=%d",
353 printf(" level=container num-devices=%d",
356 printf(" num-devices=%d", array
.nr_disks
);
359 printf(" container=%s", container
);
360 printf(" member=%s", member
);
362 if (sra
&& sra
->array
.major_version
< 0)
363 printf(" metadata=%s", sra
->text_version
);
365 printf(" metadata=%d.%d",
366 array
.major_version
, array
.minor_version
);
369 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
370 if (ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 && bmf
.pathname
[0]) {
371 printf(" bitmap=%s", bmf
.pathname
);
374 mdu_bitmap_file_t bmf
;
375 unsigned long long larray_size
;
376 struct mdstat_ent
*ms
= mdstat_read(0, 0);
377 struct mdstat_ent
*e
;
380 devnm
= stat2devnm(&stb
);
381 for (e
=ms
; e
; e
=e
->next
)
382 if (strcmp(e
->devnm
, devnm
) == 0)
384 if (!get_dev_size(fd
, NULL
, &larray_size
))
387 printf("%s:\n", dev
);
390 printf(" Container : %s, member %s\n", container
,
393 if (sra
&& sra
->array
.major_version
< 0)
394 printf(" Version : %s\n", sra
->text_version
);
396 printf(" Version : %d.%d\n",
397 array
.major_version
, array
.minor_version
);
402 printf(" Creation Time : %.24s\n", ctime(&atime
));
403 if (array
.raid_disks
== 0 && external
)
406 printf(" Raid Level : %s\n", str
);
408 printf(" Array Size : %llu%s\n", (larray_size
>>10),
409 human_size(larray_size
));
410 if (array
.level
>= 1) {
412 array
.major_version
= sra
->array
.major_version
;
413 if (array
.major_version
!= 0 &&
414 (larray_size
>= 0xFFFFFFFFULL
|| array
.size
== 0)) {
415 unsigned long long dsize
= get_component_size(fd
);
417 printf(" Used Dev Size : %llu%s\n",
419 human_size((long long)dsize
<<9));
421 printf(" Used Dev Size : unknown\n");
423 printf(" Used Dev Size : %lu%s\n",
424 (unsigned long)array
.size
,
425 human_size((unsigned long long)array
.size
<<10));
427 if (array
.raid_disks
)
428 printf(" Raid Devices : %d\n", array
.raid_disks
);
429 printf(" Total Devices : %d\n", array
.nr_disks
);
431 ((sra
== NULL
&& array
.major_version
== 0) ||
432 (sra
&& sra
->array
.major_version
== 0)))
433 printf(" Preferred Minor : %d\n", array
.md_minor
);
434 if (sra
== NULL
|| sra
->array
.major_version
>= 0)
435 printf(" Persistence : Superblock is %spersistent\n",
436 array
.not_persistent
?"not ":"");
438 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
439 if (ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 && bmf
.pathname
[0]) {
440 printf(" Intent Bitmap : %s\n", bmf
.pathname
);
442 } else if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
))
443 printf(" Intent Bitmap : Internal\n\n");
446 printf(" Update Time : %.24s\n", ctime(&atime
));
447 if (array
.raid_disks
) {
448 static char *sync_action
[] = {
449 ", recovering", ", resyncing",
450 ", reshaping", ", checking" };
452 if (avail_disks
== array
.raid_disks
)
454 else if (!enough(array
.level
, array
.raid_disks
,
455 array
.layout
, 1, avail
))
460 printf(" State : %s%s%s%s%s%s \n",
461 (array
.state
&(1<<MD_SB_CLEAN
))?"clean":"active", st
,
462 (!e
|| (e
->percent
< 0 && e
->percent
!= RESYNC_PENDING
&&
463 e
->percent
!= RESYNC_DELAYED
)) ? "" : sync_action
[e
->resync
],
464 larray_size
? "": ", Not Started",
465 (e
&& e
->percent
== RESYNC_DELAYED
) ? " (DELAYED)": "",
466 (e
&& e
->percent
== RESYNC_PENDING
) ? " (PENDING)": "");
467 } else if (inactive
) {
468 printf(" State : inactive\n");
470 if (array
.raid_disks
)
471 printf(" Active Devices : %d\n", array
.active_disks
);
472 if (array
.working_disks
> 0)
473 printf(" Working Devices : %d\n", array
.working_disks
);
474 if (array
.raid_disks
) {
475 printf(" Failed Devices : %d\n", array
.failed_disks
);
476 printf(" Spare Devices : %d\n", array
.spare_disks
);
479 if (array
.level
== 5) {
480 str
= map_num(r5layout
, array
.layout
);
481 printf(" Layout : %s\n", str
?str
:"-unknown-");
483 if (array
.level
== 6) {
484 str
= map_num(r6layout
, array
.layout
);
485 printf(" Layout : %s\n", str
?str
:"-unknown-");
487 if (array
.level
== 10) {
489 print_r10_layout(array
.layout
);
492 switch (array
.level
) {
498 if (array
.chunk_size
)
499 printf(" Chunk Size : %dK\n\n",
500 array
.chunk_size
/1024);
503 printf(" Rounding : %dK\n\n",
504 array
.chunk_size
/1024);
509 if (array
.raid_disks
) {
510 struct mdinfo
*mdi
= sysfs_read(fd
, NULL
,
511 GET_CONSISTENCY_POLICY
);
513 char *policy
= map_num(consistency_policies
,
514 mdi
->consistency_policy
);
517 printf("Consistency Policy : %s\n\n",
522 if (e
&& e
->percent
>= 0) {
523 static char *sync_action
[] = {
526 printf(" %7s Status : %d%% complete\n",
527 sync_action
[e
->resync
], e
->percent
);
531 if ((st
&& st
->sb
) && (info
&& info
->reshape_active
)) {
533 This is pretty boring
534 printf(" Reshape pos'n : %llu%s\n",
535 (unsigned long long) info
->reshape_progress
<<9,
536 human_size((unsigned long long)info
->reshape_progress
<<9));
538 if (info
->delta_disks
!= 0)
539 printf(" Delta Devices : %d, (%d->%d)\n",
541 array
.raid_disks
- info
->delta_disks
,
543 if (info
->new_level
!= array
.level
) {
544 str
= map_num(pers
, info
->new_level
);
545 printf(" New Level : %s\n", str
?str
:"-unknown-");
547 if (info
->new_level
!= array
.level
||
548 info
->new_layout
!= array
.layout
) {
549 if (info
->new_level
== 5) {
550 str
= map_num(r5layout
, info
->new_layout
);
551 printf(" New Layout : %s\n",
552 str
?str
:"-unknown-");
554 if (info
->new_level
== 6) {
555 str
= map_num(r6layout
, info
->new_layout
);
556 printf(" New Layout : %s\n",
557 str
?str
:"-unknown-");
559 if (info
->new_level
== 10) {
560 printf(" New Layout : near=%d, %s=%d\n",
561 info
->new_layout
&255,
562 (info
->new_layout
&0x10000)?"offset":"far",
563 (info
->new_layout
>>8)&255);
566 if (info
->new_chunk
!= array
.chunk_size
)
567 printf(" New Chunksize : %dK\n",
568 info
->new_chunk
/1024);
570 } else if (e
&& e
->percent
>= 0)
573 st
->ss
->detail_super(st
, c
->homehost
);
575 if (array
.raid_disks
== 0 && sra
&& sra
->array
.major_version
== -1
576 && sra
->array
.minor_version
== -2 && sra
->text_version
[0] != '/') {
577 /* This looks like a container. Find any active arrays
578 * That claim to be a member.
580 DIR *dir
= opendir("/sys/block");
583 printf(" Member Arrays :");
585 while (dir
&& (de
= readdir(dir
)) != NULL
) {
588 int nlen
= strlen(sra
->sys_name
);
590 if (de
->d_name
[0] == '.')
592 sprintf(path
, "/sys/block/%s/md/metadata_version",
594 if (load_sys(path
, vbuf
, sizeof(vbuf
)) < 0)
596 if (strncmp(vbuf
, "external:", 9) != 0 ||
597 !is_subarray(vbuf
+9) ||
598 strncmp(vbuf
+10, sra
->sys_name
, nlen
) != 0 ||
599 vbuf
[10+nlen
] != '/')
601 devid
= devnm2devid(de
->d_name
);
602 printf(" %s", map_dev_preferred(
604 minor(devid
), 1, c
->prefer
));
611 if (array
.raid_disks
)
612 printf(" Number Major Minor RaidDevice State\n");
614 printf(" Number Major Minor RaidDevice\n");
618 for (d
= 0; d
< max_disks
* 2; d
++) {
620 mdu_disk_info_t disk
= disks
[d
];
622 if (d
>= array
.raid_disks
*2 &&
631 if (d
== array
.raid_disks
*2) printf("\n");
632 if (disk
.number
< 0 && disk
.raid_disk
< 0)
633 printf(" - %5d %5d - ",
634 disk
.major
, disk
.minor
);
635 else if (disk
.raid_disk
< 0 || disk
.state
& (1<<MD_DISK_JOURNAL
))
636 printf(" %5d %5d %5d - ",
637 disk
.number
, disk
.major
, disk
.minor
);
638 else if (disk
.number
< 0)
639 printf(" - %5d %5d %5d ",
640 disk
.major
, disk
.minor
, disk
.raid_disk
);
642 printf(" %5d %5d %5d %5d ",
643 disk
.number
, disk
.major
, disk
.minor
, disk
.raid_disk
);
645 if (!c
->brief
&& array
.raid_disks
) {
647 if (disk
.state
& (1<<MD_DISK_FAULTY
)) {
649 if (disk
.raid_disk
< array
.raid_disks
&&
653 if (disk
.state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
654 if (disk
.state
& (1<<MD_DISK_SYNC
)) {
656 if (array
.level
== 10 && (array
.layout
& ~0x1FFFF) == 0) {
657 int nc
= array
.layout
& 0xff;
658 int fc
= (array
.layout
>> 8) & 0xff;
660 if (fc
== 1 && array
.raid_disks
% copies
== 0 && copies
<= 26) {
661 /* We can divide the devices into 'sets' */
662 int set
= disk
.raid_disk
% copies
;
663 printf(" set-%c", set
+ 'A');
667 if (disk
.state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
668 if (disk
.state
& (1<<MD_DISK_WRITEMOSTLY
)) printf(" writemostly");
669 if (disk
.state
& (1<<MD_DISK_FAILFAST
)) printf(" failfast");
670 if (disk
.state
& (1<<MD_DISK_JOURNAL
)) printf(" journal");
672 ((1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
)
673 |(1<<MD_DISK_REMOVED
)|(1<<MD_DISK_FAULTY
)|(1<<MD_DISK_JOURNAL
)))
676 if (disk
.raid_disk
< array
.raid_disks
&&
678 printf(" rebuilding");
681 if (disk
.state
== 0) spares
++;
682 dv
=map_dev_preferred(disk
.major
, disk
.minor
, 0, c
->prefer
);
685 n_devices
= add_device(dv
, &devices
,
691 if (!c
->brief
) printf("\n");
693 if (spares
&& c
->brief
&& array
.raid_disks
) printf(" spares=%d", spares
);
694 if (c
->brief
&& st
&& st
->sb
)
695 st
->ss
->brief_detail_super(st
);
697 st
->ss
->free_super(st
);
699 if (c
->brief
&& c
->verbose
> 0 && devices
) {
700 qsort(devices
, n_devices
, sizeof(*devices
), cmpstringp
);
701 printf("\n devices=%s", devices
[0]);
702 for (d
= 1; d
< n_devices
; d
++)
703 printf(",%s", devices
[d
]);
708 !enough(array
.level
, array
.raid_disks
, array
.layout
,
717 for (d
= 0; d
< n_devices
; d
++)
724 int Detail_Platform(struct superswitch
*ss
, int scan
, int verbose
, int export
, char *controller_path
)
726 /* display platform capabilities for the given metadata format
727 * 'scan' in this context means iterate over all metadata types
732 if (ss
&& export
&& ss
->export_detail_platform
)
733 err
= ss
->export_detail_platform(verbose
, controller_path
);
734 else if (ss
&& ss
->detail_platform
)
735 err
= ss
->detail_platform(verbose
, 0, controller_path
);
738 pr_err("%s metadata is platform independent\n",
739 ss
->name
? : "[no name]");
742 pr_err("specify a metadata type or --scan\n");
749 for (i
= 0; superlist
[i
]; i
++) {
750 struct superswitch
*meta
= superlist
[i
];
755 pr_err("checking metadata %s\n",
756 meta
->name
? : "[no name]");
757 if (!meta
->detail_platform
) {
759 pr_err("%s metadata is platform independent\n",
760 meta
->name
? : "[no name]");
761 } else if (export
&& meta
->export_detail_platform
) {
762 err
|= meta
->export_detail_platform(verbose
, controller_path
);
764 err
|= meta
->detail_platform(verbose
, 0, controller_path
);