]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2012 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
, struct context
*c
)
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
= c
->test
? 4 : 1;
64 pr_err("cannot open %s: %s\n",
65 dev
, strerror(errno
));
68 vers
= md_get_version(fd
);
70 pr_err("%s does not appear to be an md device\n",
76 pr_err("cannot get detail for md device %s: driver version too old.\n",
81 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)<0) {
83 pr_err("md device %s does not appear to be active.\n",
86 pr_err("cannot get array detail for %s: %s\n",
87 dev
, strerror(errno
));
91 sra
= sysfs_read(fd
, NULL
, 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 devid
= devnm2devid(st
->container_devnm
);
109 container
= map_dev_preferred(major(devid
), minor(devid
),
111 cfd
= open_dev(st
->container_devnm
);
113 err
= st
->ss
->load_container(st
, cfd
, NULL
);
116 info
= st
->ss
->container_content(st
, subarray
);
120 /* try to load a superblock */
121 if (st
&& !info
) for (d
= 0; d
< max_disks
; d
++) {
122 mdu_disk_info_t disk
;
127 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
129 if (d
>= array
.raid_disks
&&
134 if (array
.raid_disks
> 0 &&
135 (disk
.state
& (1 << MD_DISK_ACTIVE
)) == 0)
138 dv
= map_dev(disk
.major
, disk
.minor
, 1);
142 fd2
= dev_open(dv
, O_RDONLY
);
147 st
->ss
->free_super(st
);
149 err
= st
->ss
->load_super(st
, fd2
, NULL
);
156 info
= st
->ss
->container_content(st
, subarray
);
158 info
= xmalloc(sizeof(*info
));
159 st
->ss
->getinfo_super(st
, info
, NULL
);
164 if (array
.raid_disks
!= 0 && /* container */
165 (info
->array
.ctime
!= array
.ctime
||
166 info
->array
.level
!= array
.level
)) {
167 st
->ss
->free_super(st
);
170 /* some formats (imsm) have free-floating-spares
171 * with a uuid of uuid_zero, they don't
172 * have very good info about the rest of the
173 * container, so keep searching when
174 * encountering such a device. Otherwise, stop
175 * after the first successful call to
178 if (memcmp(uuid_zero
,
180 sizeof(uuid_zero
)) == 0) {
181 st
->ss
->free_super(st
);
187 /* Ok, we have some info to print... */
188 str
= map_num(pers
, array
.level
);
191 if (array
.raid_disks
) {
193 printf("MD_LEVEL=%s\n", str
);
194 printf("MD_DEVICES=%d\n", array
.raid_disks
);
196 printf("MD_LEVEL=container\n");
197 printf("MD_DEVICES=%d\n", array
.nr_disks
);
200 printf("MD_CONTAINER=%s\n", container
);
201 printf("MD_MEMBER=%s\n", member
);
203 if (sra
&& sra
->array
.major_version
< 0)
204 printf("MD_METADATA=%s\n", sra
->text_version
);
206 printf("MD_METADATA=%d.%d\n",
207 array
.major_version
, array
.minor_version
);
210 if (st
&& st
->sb
&& info
) {
212 struct map_ent
*mp
, *map
= NULL
;
214 fname_from_uuid(st
, info
, nbuf
, ':');
215 printf("MD_UUID=%s\n", nbuf
+5);
216 mp
= map_by_uuid(&map
, info
->uuid
);
217 if (mp
&& mp
->path
&&
218 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
219 printf("MD_DEVNAME=");
220 print_escape(mp
->path
+8);
224 if (st
->ss
->export_detail_super
)
225 st
->ss
->export_detail_super(st
);
227 struct map_ent
*mp
, *map
= NULL
;
229 mp
= map_by_devnm(&map
, fd2devnm(fd
));
231 __fname_from_uuid(mp
->uuid
, 0, nbuf
, ':');
232 printf("MD_UUID=%s\n", nbuf
+5);
234 if (mp
&& mp
->path
&&
235 strncmp(mp
->path
, "/dev/md/", 8) == 0) {
236 printf("MD_DEVNAME=");
237 print_escape(mp
->path
+8);
244 disks
= xmalloc(max_disks
* sizeof(mdu_disk_info_t
));
245 for (d
= 0; d
< max_disks
; d
++) {
246 disks
[d
].state
= (1<<MD_DISK_REMOVED
);
247 disks
[d
].major
= disks
[d
].minor
= 0;
248 disks
[d
].number
= disks
[d
].raid_disk
= d
;
251 next
= array
.raid_disks
*2;
252 for (d
= 0; d
< max_disks
; d
++) {
253 mdu_disk_info_t disk
;
255 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
256 if (d
< array
.raid_disks
)
257 pr_err("cannot get device detail for device %d: %s\n",
261 if (disk
.major
== 0 && disk
.minor
== 0)
263 if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
264 && disks
[disk
.raid_disk
*2].state
== (1<<MD_DISK_REMOVED
))
265 disks
[disk
.raid_disk
*2] = disk
;
266 else if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
267 && disks
[disk
.raid_disk
*2+1].state
== (1<<MD_DISK_REMOVED
))
268 disks
[disk
.raid_disk
*2+1] = disk
;
269 else if (next
< max_disks
)
270 disks
[next
++] = disk
;
273 avail
= xcalloc(array
.raid_disks
, 1);
275 for (d
= 0; d
< array
.raid_disks
; d
++) {
277 if ((disks
[d
*2].state
& (1<<MD_DISK_SYNC
)) ||
278 (disks
[d
*2+1].state
& (1<<MD_DISK_SYNC
))) {
285 mdu_bitmap_file_t bmf
;
286 printf("ARRAY %s", dev
);
288 if (array
.raid_disks
)
289 printf(" level=%s num-devices=%d",
293 printf(" level=container num-devices=%d",
297 printf(" container=%s", container
);
298 printf(" member=%s", member
);
300 if (sra
&& sra
->array
.major_version
< 0)
301 printf(" metadata=%s", sra
->text_version
);
303 printf(" metadata=%d.%d",
304 array
.major_version
, array
.minor_version
);
307 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
309 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
311 printf(" bitmap=%s", bmf
.pathname
);
314 mdu_bitmap_file_t bmf
;
315 unsigned long long larray_size
;
316 struct mdstat_ent
*ms
= mdstat_read(0, 0);
317 struct mdstat_ent
*e
;
320 devnm
= stat2devnm(&stb
);
321 for (e
=ms
; e
; e
=e
->next
)
322 if (strcmp(e
->devnm
, devnm
) == 0)
324 if (!get_dev_size(fd
, NULL
, &larray_size
))
327 printf("%s:\n", dev
);
330 printf(" Container : %s, member %s\n", container
, member
);
332 if (sra
&& sra
->array
.major_version
< 0)
333 printf(" Version : %s\n", sra
->text_version
);
335 printf(" Version : %d.%d\n",
336 array
.major_version
, array
.minor_version
);
341 printf(" Creation Time : %.24s\n", ctime(&atime
));
342 if (array
.raid_disks
== 0)
344 printf(" Raid Level : %s\n", str
?str
:"-unknown-");
346 printf(" Array Size : %llu%s\n", (larray_size
>>10),
347 human_size(larray_size
));
348 if (array
.level
>= 1) {
350 array
.major_version
= sra
->array
.major_version
;
351 if (array
.major_version
!= 0 &&
352 (larray_size
>= 0xFFFFFFFFULL
|| array
.size
== 0)) {
353 unsigned long long dsize
= get_component_size(fd
);
355 printf(" Used Dev Size : %llu%s\n",
357 human_size((long long)dsize
<<9));
359 printf(" Used Dev Size : unknown\n");
361 printf(" Used Dev Size : %d%s\n", array
.size
,
362 human_size((long long)array
.size
<<10));
364 if (array
.raid_disks
)
365 printf(" Raid Devices : %d\n", array
.raid_disks
);
366 printf(" Total Devices : %d\n", array
.nr_disks
);
368 ((sra
== NULL
&& array
.major_version
== 0) ||
369 (sra
&& sra
->array
.major_version
== 0)))
370 printf("Preferred Minor : %d\n", array
.md_minor
);
371 if (sra
== NULL
|| sra
->array
.major_version
>= 0)
372 printf(" Persistence : Superblock is %spersistent\n",
373 array
.not_persistent
?"not ":"");
375 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
377 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
379 printf(" Intent Bitmap : %s\n", bmf
.pathname
);
381 } else if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
))
382 printf(" Intent Bitmap : Internal\n\n");
385 printf(" Update Time : %.24s\n", ctime(&atime
));
386 if (array
.raid_disks
) {
387 static char *sync_action
[] = {
388 ", recovering", ", resyncing",
389 ", reshaping", ", checking" };
391 if (avail_disks
== array
.raid_disks
)
393 else if (!enough(array
.level
, array
.raid_disks
,
394 array
.layout
, 1, avail
))
399 printf(" State : %s%s%s%s%s%s \n",
400 (array
.state
&(1<<MD_SB_CLEAN
))?"clean":"active", st
,
401 (!e
|| (e
->percent
< 0 && e
->percent
!= RESYNC_PENDING
&&
402 e
->percent
!= RESYNC_DELAYED
)) ? "" : sync_action
[e
->resync
],
403 larray_size
? "": ", Not Started",
404 e
->percent
== RESYNC_DELAYED
? " (DELAYED)": "",
405 e
->percent
== RESYNC_PENDING
? " (PENDING)": "");
407 if (array
.raid_disks
)
408 printf(" Active Devices : %d\n", array
.active_disks
);
409 printf("Working Devices : %d\n", array
.working_disks
);
410 if (array
.raid_disks
) {
411 printf(" Failed Devices : %d\n", array
.failed_disks
);
412 printf(" Spare Devices : %d\n", array
.spare_disks
);
415 if (array
.level
== 5) {
416 str
= map_num(r5layout
, array
.layout
);
417 printf(" Layout : %s\n", str
?str
:"-unknown-");
419 if (array
.level
== 6) {
420 str
= map_num(r6layout
, array
.layout
);
421 printf(" Layout : %s\n", str
?str
:"-unknown-");
423 if (array
.level
== 10) {
425 print_r10_layout(array
.layout
);
428 switch (array
.level
) {
434 if (array
.chunk_size
)
435 printf(" Chunk Size : %dK\n\n",
436 array
.chunk_size
/1024);
439 printf(" Rounding : %dK\n\n", array
.chunk_size
/1024);
444 if (e
&& e
->percent
>= 0) {
445 static char *sync_action
[] = {
448 printf(" %7s Status : %d%% complete\n", sync_action
[e
->resync
], e
->percent
);
453 if ((st
&& st
->sb
) && (info
&& info
->reshape_active
)) {
455 This is pretty boring
456 printf(" Reshape pos'n : %llu%s\n", (unsigned long long) info
->reshape_progress
<<9,
457 human_size((unsigned long long)info
->reshape_progress
<<9));
459 if (info
->delta_disks
!= 0)
460 printf(" Delta Devices : %d, (%d->%d)\n",
462 array
.raid_disks
- info
->delta_disks
,
464 if (info
->new_level
!= array
.level
) {
465 str
= map_num(pers
, info
->new_level
);
466 printf(" New Level : %s\n", str
?str
:"-unknown-");
468 if (info
->new_level
!= array
.level
||
469 info
->new_layout
!= array
.layout
) {
470 if (info
->new_level
== 5) {
471 str
= map_num(r5layout
, info
->new_layout
);
472 printf(" New Layout : %s\n",
473 str
?str
:"-unknown-");
475 if (info
->new_level
== 6) {
476 str
= map_num(r6layout
, info
->new_layout
);
477 printf(" New Layout : %s\n",
478 str
?str
:"-unknown-");
480 if (info
->new_level
== 10) {
481 printf(" New Layout : near=%d, %s=%d\n",
482 info
->new_layout
&255,
483 (info
->new_layout
&0x10000)?"offset":"far",
484 (info
->new_layout
>>8)&255);
487 if (info
->new_chunk
!= array
.chunk_size
)
488 printf(" New Chunksize : %dK\n", info
->new_chunk
/1024);
490 } else if (e
&& e
->percent
>= 0)
493 st
->ss
->detail_super(st
, c
->homehost
);
495 if (array
.raid_disks
== 0 && sra
&& sra
->array
.major_version
== -1
496 && sra
->array
.minor_version
== -2 && sra
->text_version
[0] != '/') {
497 /* This looks like a container. Find any active arrays
498 * That claim to be a member.
500 DIR *dir
= opendir("/sys/block");
503 printf(" Member Arrays :");
505 while (dir
&& (de
= readdir(dir
)) != NULL
) {
508 int nlen
= strlen(sra
->sys_name
);
510 if (de
->d_name
[0] == '.')
512 sprintf(path
, "/sys/block/%s/md/metadata_version",
514 if (load_sys(path
, vbuf
) < 0)
516 if (strncmp(vbuf
, "external:", 9) != 0 ||
517 !is_subarray(vbuf
+9) ||
518 strncmp(vbuf
+10, sra
->sys_name
, nlen
) != 0 ||
519 vbuf
[10+nlen
] != '/')
521 devid
= devnm2devid(de
->d_name
);
522 printf(" %s", map_dev_preferred(
524 minor(devid
), 1, c
->prefer
));
531 if (array
.raid_disks
)
532 printf(" Number Major Minor RaidDevice State\n");
534 printf(" Number Major Minor RaidDevice\n");
538 for (d
= 0; d
< max_disks
; d
++) {
540 mdu_disk_info_t disk
= disks
[d
];
542 if (d
>= array
.raid_disks
*2 &&
551 if (d
== array
.raid_disks
*2) printf("\n");
552 if (disk
.raid_disk
< 0)
553 printf(" %5d %5d %5d - ",
554 disk
.number
, disk
.major
, disk
.minor
);
556 printf(" %5d %5d %5d %5d ",
557 disk
.number
, disk
.major
, disk
.minor
, disk
.raid_disk
);
559 if (!c
->brief
&& array
.raid_disks
) {
561 if (disk
.state
& (1<<MD_DISK_FAULTY
)) {
563 if (disk
.raid_disk
< array
.raid_disks
&&
567 if (disk
.state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
568 if (disk
.state
& (1<<MD_DISK_SYNC
)) {
570 if (array
.level
== 10 && (array
.layout
& ~0x1FFFF) == 0) {
571 int nc
= array
.layout
& 0xff;
572 int fc
= (array
.layout
>> 8) & 0xff;
574 if (fc
== 1 && array
.raid_disks
% copies
== 0 && copies
<= 26) {
575 /* We can divide the devices into 'sets' */
576 int set
= disk
.raid_disk
% copies
;
577 printf(" set-%c", set
+ 'A');
581 if (disk
.state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
582 if (disk
.state
& (1<<MD_DISK_WRITEMOSTLY
)) printf(" writemostly");
584 ((1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
)
585 |(1<<MD_DISK_REMOVED
)|(1<<MD_DISK_FAULTY
)))
589 if (disk
.raid_disk
< array
.raid_disks
&& disk
.raid_disk
>= 0)
590 printf(" rebuilding");
591 } else if (is_rebuilding
&& failed
) {
592 /* Taking a bit of a risk here, we remove the
593 * device from the array, and then put it back.
594 * If this fails, we are rebuilding
596 int err
= ioctl(fd
, HOT_REMOVE_DISK
, makedev(disk
.major
, disk
.minor
));
597 if (err
== 0) ioctl(fd
, HOT_ADD_DISK
, makedev(disk
.major
, disk
.minor
));
598 if (err
&& errno
== EBUSY
)
599 printf(" rebuilding");
603 if (disk
.state
== 0) spares
++;
604 if (c
->test
&& d
< array
.raid_disks
605 && !(disk
.state
& (1<<MD_DISK_SYNC
)))
607 dv
=map_dev_preferred(disk
.major
, disk
.minor
, 0, c
->prefer
);
611 devices
= xrealloc(devices
,
612 strlen(devices
)+1+strlen(dv
)+1);
613 strcat(strcat(devices
,","),dv
);
615 devices
= xstrdup(dv
);
619 if (!c
->brief
) printf("\n");
621 if (spares
&& c
->brief
&& array
.raid_disks
) printf(" spares=%d", spares
);
622 if (c
->brief
&& st
&& st
->sb
)
623 st
->ss
->brief_detail_super(st
);
625 st
->ss
->free_super(st
);
627 if (c
->brief
> 1 && devices
) printf("\n devices=%s", devices
);
631 !enough(array
.level
, array
.raid_disks
, array
.layout
,
644 int Detail_Platform(struct superswitch
*ss
, int scan
, int verbose
, int export
, char *controller_path
)
646 /* display platform capabilities for the given metadata format
647 * 'scan' in this context means iterate over all metadata types
652 if (ss
&& export
&& ss
->export_detail_platform
)
653 err
= ss
->export_detail_platform(verbose
, controller_path
);
654 else if (ss
&& ss
->detail_platform
)
655 err
= ss
->detail_platform(verbose
, 0, controller_path
);
658 pr_err("%s metadata is platform independent\n",
659 ss
->name
? : "[no name]");
662 pr_err("specify a metadata type or --scan\n");
669 for (i
= 0; superlist
[i
]; i
++) {
670 struct superswitch
*meta
= superlist
[i
];
675 pr_err("checking metadata %s\n",
676 meta
->name
? : "[no name]");
677 if (!meta
->detail_platform
) {
679 pr_err("%s metadata is platform independent\n",
680 meta
->name
? : "[no name]");
681 } else if (export
&& meta
->export_detail_platform
) {
682 err
|= meta
->export_detail_platform(verbose
, controller_path
);
684 err
|= meta
->detail_platform(verbose
, 0, controller_path
);