2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2006 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@cse.unsw.edu.au>
24 * School of Computer Science and Engineering
25 * The University of New South Wales
34 int Detail(char *dev
, int brief
, int test
, char *homehost
)
37 * Print out details for an md array by using
38 * GET_ARRAY_INFO and GET_DISK_INFO ioctl calls
41 int fd
= open(dev
, O_RDONLY
, 0);
43 mdu_array_info_t array
;
44 mdu_disk_info_t
*disks
;
52 int is_26
= get_linux_version() >= 2006000;
53 int is_rebuilding
= 0;
55 struct supertype
*st
= NULL
;
56 int max_disks
= MD_SB_DISKS
; /* just a default */
60 int rv
= test
? 4 : 1;
63 fprintf(stderr
, Name
": cannot open %s: %s\n",
64 dev
, strerror(errno
));
67 vers
= md_get_version(fd
);
69 fprintf(stderr
, Name
": %s does not appear to be an md device\n",
75 fprintf(stderr
, Name
": cannot get detail for md device %s: driver version too old.\n",
80 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)<0) {
82 fprintf(stderr
, Name
": md device %s does not appear to be active.\n",
85 fprintf(stderr
, Name
": cannot get array detail for %s: %s\n",
86 dev
, strerror(errno
));
90 st
= super_by_version(array
.major_version
, array
.minor_version
);
92 if (fstat(fd
, &stb
) != 0 && !S_ISBLK(stb
.st_mode
))
96 if (st
) max_disks
= st
->max_devs
;
98 /* try to load a superblock */
99 for (d
= 0; d
<max_disks
; d
++) {
100 mdu_disk_info_t disk
;
103 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
105 if (d
>= array
.raid_disks
&&
109 if ((dv
=map_dev(disk
.major
, disk
.minor
, 1))) {
110 if (!super
&& (disk
.state
& (1<<MD_DISK_ACTIVE
))) {
111 /* try to read the superblock from this device
114 int fd2
= dev_open(dv
, O_RDONLY
);
116 st
->ss
->load_super(st
, fd2
, &super
, NULL
) == 0) {
117 st
->ss
->getinfo_super(&info
, super
);
118 if (info
.array
.ctime
!= array
.ctime
||
119 info
.array
.level
!= array
.level
) {
124 if (fd2
>= 0) close(fd2
);
129 /* Ok, we have some info to print... */
130 c
= map_num(pers
, array
.level
);
132 printf("ARRAY %s level=%s num-devices=%d", dev
, c
?c
:"-unknown-",array
.raid_disks
);
134 mdu_bitmap_file_t bmf
;
135 unsigned long long larray_size
;
136 struct mdstat_ent
*ms
= mdstat_read(0, 0);
137 struct mdstat_ent
*e
;
138 int devnum
= array
.md_minor
;
139 if (major(stb
.st_rdev
) != MD_MAJOR
)
140 devnum
= -1 - devnum
;
142 for (e
=ms
; e
; e
=e
->next
)
143 if (e
->devnum
== devnum
)
145 if (!get_dev_size(fd
, NULL
, &larray_size
))
148 printf("%s:\n", dev
);
149 printf(" Version : %02d.%02d.%02d\n",
150 array
.major_version
, array
.minor_version
, array
.patch_version
);
152 printf(" Creation Time : %.24s\n", ctime(&atime
));
153 printf(" Raid Level : %s\n", c
?c
:"-unknown-");
155 printf(" Array Size : %llu%s\n", (larray_size
>>10), human_size(larray_size
));
156 if (array
.level
>= 1) {
157 if (array
.major_version
!= 0 &&
158 (larray_size
>= 0xFFFFFFFFULL
|| array
.size
== 0)) {
159 unsigned long long dsize
= get_component_size(fd
);
161 printf(" Used Dev Size : %llu%s\n",
163 human_size((long long)array
.size
<<10));
165 printf(" Used Dev Size : unknown\n");
167 printf(" Used Dev Size : %d%s\n", array
.size
,
168 human_size((long long)array
.size
<<10));
170 printf(" Raid Devices : %d\n", array
.raid_disks
);
171 printf(" Total Devices : %d\n", array
.nr_disks
);
172 printf("Preferred Minor : %d\n", array
.md_minor
);
173 printf(" Persistence : Superblock is %spersistent\n",
174 array
.not_persistent
?"not ":"");
176 /* Only try GET_BITMAP_FILE for 0.90.01 and later */
178 ioctl(fd
, GET_BITMAP_FILE
, &bmf
) == 0 &&
180 printf(" Intent Bitmap : %s\n", bmf
.pathname
);
182 } else if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
))
183 printf(" Intent Bitmap : Internal\n\n");
185 printf(" Update Time : %.24s\n", ctime(&atime
));
186 printf(" State : %s%s%s%s\n",
187 (array
.state
&(1<<MD_SB_CLEAN
))?"clean":"active",
188 array
.active_disks
< array
.raid_disks
? ", degraded":"",
189 (!e
|| e
->percent
< 0) ? "" :
190 (e
->resync
) ? ", resyncing": ", recovering",
191 larray_size
? "": ", Not Started");
192 printf(" Active Devices : %d\n", array
.active_disks
);
193 printf("Working Devices : %d\n", array
.working_disks
);
194 printf(" Failed Devices : %d\n", array
.failed_disks
);
195 printf(" Spare Devices : %d\n", array
.spare_disks
);
197 if (array
.level
== 5) {
198 c
= map_num(r5layout
, array
.layout
);
199 printf(" Layout : %s\n", c
?c
:"-unknown-");
201 if (array
.level
== 10) {
202 printf(" Layout : near=%d, %s=%d\n",
203 array
.layout
&255, (array
.layout
&0x10000)?"offset":"far",
204 (array
.layout
>>8)&255);
206 switch (array
.level
) {
212 printf(" Chunk Size : %dK\n\n", array
.chunk_size
/1024);
215 printf(" Rounding : %dK\n\n", array
.chunk_size
/1024);
220 if (e
&& e
->percent
>= 0) {
221 printf(" Re%s Status : %d%% complete\n",
222 (super
&& info
.reshape_active
)? "shape":"build",
228 if (super
&& info
.reshape_active
) {
230 This is pretty boring
231 printf(" Reshape pos'n : %llu%s\n", (unsigned long long) info
.reshape_progress
<<9,
232 human_size(info
.reshape_progress
<<9));
234 if (info
.delta_disks
> 0)
235 printf(" Delta Devices : %d, (%d->%d)\n",
236 info
.delta_disks
, array
.raid_disks
- info
.delta_disks
, array
.raid_disks
);
237 if (info
.delta_disks
< 0)
238 printf(" Delta Devices : %d, (%d->%d)\n",
239 info
.delta_disks
, array
.raid_disks
, array
.raid_disks
+ info
.delta_disks
);
240 if (info
.new_level
!= array
.level
) {
241 char *c
= map_num(pers
, info
.new_level
);
242 printf(" New Level : %s\n", c
?c
:"-unknown-");
244 if (info
.new_level
!= array
.level
||
245 info
.new_layout
!= array
.layout
) {
246 if (info
.new_level
== 5) {
247 char *c
= map_num(r5layout
, info
.new_layout
);
248 printf(" New Layout : %s\n",
251 if (info
.new_level
== 10) {
252 printf(" New Layout : near=%d, %s=%d\n",
254 (info
.new_layout
&0x10000)?"offset":"far",
255 (info
.new_layout
>>8)&255);
258 if (info
.new_chunk
!= array
.chunk_size
)
259 printf(" New Chunksize : %dK\n", info
.new_chunk
/1024);
261 } else if (e
&& e
->percent
>= 0)
264 st
->ss
->detail_super(super
, homehost
);
266 printf(" Number Major Minor RaidDevice State\n");
268 disks
= malloc(max_disks
* sizeof(mdu_disk_info_t
));
269 for (d
=0; d
<max_disks
; d
++) {
270 disks
[d
].state
= (1<<MD_DISK_REMOVED
);
271 disks
[d
].major
= disks
[d
].minor
= 0;
272 disks
[d
].number
= disks
[d
].raid_disk
= d
;
275 next
= array
.raid_disks
;
276 for (d
=0; d
< max_disks
; d
++) {
277 mdu_disk_info_t disk
;
279 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
280 if (d
< array
.raid_disks
)
281 fprintf(stderr
, Name
": cannot get device detail for device %d: %s\n",
285 if (disk
.major
== 0 && disk
.minor
== 0)
287 if (disk
.raid_disk
>= 0 && disk
.raid_disk
< array
.raid_disks
)
288 disks
[disk
.raid_disk
] = disk
;
289 else if (next
< max_disks
)
290 disks
[next
++] = disk
;
293 for (d
= 0; d
< max_disks
; d
++) {
295 mdu_disk_info_t disk
= disks
[d
];
297 if (d
>= array
.raid_disks
&&
302 if (d
== array
.raid_disks
) printf("\n");
303 if (disk
.raid_disk
< 0)
304 printf(" %5d %5d %5d - ",
305 disk
.number
, disk
.major
, disk
.minor
);
307 printf(" %5d %5d %5d %5d ",
308 disk
.number
, disk
.major
, disk
.minor
, disk
.raid_disk
);
309 if (disk
.state
& (1<<MD_DISK_FAULTY
)) {
311 if (disk
.raid_disk
< array
.raid_disks
&&
315 if (disk
.state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
316 if (disk
.state
& (1<<MD_DISK_SYNC
)) printf(" sync");
317 if (disk
.state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
318 if (disk
.state
& (1<<MD_DISK_WRITEMOSTLY
)) printf(" writemostly");
320 ((1<<MD_DISK_ACTIVE
)|(1<<MD_DISK_SYNC
)|(1<<MD_DISK_REMOVED
)))
324 if (disk
.raid_disk
< array
.raid_disks
&& disk
.raid_disk
>= 0)
325 printf(" rebuilding");
326 } else if (is_rebuilding
&& failed
) {
327 /* Taking a bit of a risk here, we remove the
328 * device from the array, and then put it back.
329 * If this fails, we are rebuilding
331 int err
= ioctl(fd
, HOT_REMOVE_DISK
, makedev(disk
.major
, disk
.minor
));
332 if (err
== 0) ioctl(fd
, HOT_ADD_DISK
, makedev(disk
.major
, disk
.minor
));
333 if (err
&& errno
== EBUSY
)
334 printf(" rebuilding");
338 if (disk
.state
== 0) spares
++;
339 if (test
&& d
< array
.raid_disks
&& disk
.state
& (1<<MD_DISK_FAULTY
)) {
340 if ((rv
& 1) && (array
.level
==4 || array
.level
== 5))
344 if ((dv
=map_dev(disk
.major
, disk
.minor
, 0))) {
347 devices
= realloc(devices
,
348 strlen(devices
)+1+strlen(dv
)+1);
349 strcat(strcat(devices
,","),dv
);
351 devices
= strdup(dv
);
355 if (!brief
) printf("\n");
357 if (spares
&& brief
) printf(" spares=%d", spares
);
358 if (super
&& brief
&& st
)
359 st
->ss
->brief_detail_super(super
);
361 if (brief
> 1 && devices
) printf("\n devices=%s", devices
);
362 if (brief
) printf("\n");
363 if (test
&& (rv
&2)) rv
&= ~1;