]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
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
)
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
;
50 int is_26
= get_linux_version() >= 2006000;
51 int is_rebuilding
= 0;
53 struct supertype
*st
= NULL
;
54 int max_disks
= MD_SB_DISKS
;
57 int rv
= test
? 4 : 1;
60 fprintf(stderr
, Name
": cannot open %s: %s\n",
61 dev
, strerror(errno
));
64 vers
= md_get_version(fd
);
66 fprintf(stderr
, Name
": %s does not appear to be an md device\n",
72 fprintf(stderr
, Name
": cannot get detail for md device %s: driver version too old.\n",
77 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)<0) {
79 fprintf(stderr
, Name
": md device %s does not appear to be active.\n",
82 fprintf(stderr
, Name
": cannot get array detail for %s: %s\n",
83 dev
, strerror(errno
));
87 st
= super_by_version(array
.major_version
, array
.minor_version
);
89 if (fstat(fd
, &stb
) != 0 && !S_ISBLK(stb
.st_mode
))
93 if (st
) max_disks
= st
->max_devs
;
95 /* try to load a superblock */
96 for (d
= 0; d
<max_disks
; d
++) {
100 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
102 if (d
>= array
.raid_disks
&&
106 if ((dv
=map_dev(disk
.major
, disk
.minor
))) {
107 if (!super
&& (disk
.state
& (1<<MD_DISK_ACTIVE
))) {
108 /* try to read the superblock from this device
111 int fd2
= open(dv
, O_RDONLY
);
113 st
->ss
->load_super(st
, fd2
, &super
, NULL
) == 0) {
115 st
->ss
->getinfo_super(&info
, super
);
116 if (info
.array
.ctime
!= array
.ctime
||
117 info
.array
.level
!= array
.level
) {
122 if (fd2
>= 0) close(fd2
);
127 /* Ok, we have some info to print... */
128 c
= map_num(pers
, array
.level
);
130 printf("ARRAY %s level=%s num-devices=%d", dev
, c
?c
:"-unknown-",array
.raid_disks
);
132 unsigned long array_size
;
133 unsigned long long larray_size
;
134 struct mdstat_ent
*ms
= mdstat_read(0);
135 struct mdstat_ent
*e
;
136 int devnum
= array
.md_minor
;
137 if (major(stb
.st_rdev
) != MD_MAJOR
)
138 devnum
= -1 - devnum
;
140 for (e
=ms
; e
; e
=e
->next
)
141 if (e
->devnum
== devnum
)
144 if (ioctl(fd
, BLKGETSIZE64
, &larray_size
)==0)
148 if (ioctl(fd
, BLKGETSIZE
, &array_size
)==0) {
149 larray_size
= array_size
;
153 else larray_size
= 0;
155 printf("%s:\n", dev
);
156 printf(" Version : %02d.%02d.%02d\n",
157 array
.major_version
, array
.minor_version
, array
.patch_version
);
159 printf(" Creation Time : %.24s\n", ctime(&atime
));
160 printf(" Raid Level : %s\n", c
?c
:"-unknown-");
162 printf(" Array Size : %llu%s\n", (larray_size
>>10), human_size(larray_size
));
163 if (array
.level
>= 1)
164 printf(" Device Size : %d%s\n", array
.size
, human_size((long long)array
.size
<<10));
165 printf(" Raid Devices : %d\n", array
.raid_disks
);
166 printf(" Total Devices : %d\n", array
.nr_disks
);
167 printf("Preferred Minor : %d\n", array
.md_minor
);
168 printf(" Persistence : Superblock is %spersistent\n",
169 array
.not_persistent
?"not ":"");
172 printf(" Update Time : %.24s\n", ctime(&atime
));
173 printf(" State : %s%s%s\n",
174 (array
.state
&(1<<MD_SB_CLEAN
))?"clean":"active",
175 array
.active_disks
< array
.raid_disks
? ", degraded":"",
176 (!e
|| e
->percent
< 0) ? "" :
177 (e
->resync
) ? ", resyncing": ", recovering");
178 printf(" Active Devices : %d\n", array
.active_disks
);
179 printf("Working Devices : %d\n", array
.working_disks
);
180 printf(" Failed Devices : %d\n", array
.failed_disks
);
181 printf(" Spare Devices : %d\n", array
.spare_disks
);
183 if (array
.level
== 5) {
184 c
= map_num(r5layout
, array
.layout
);
185 printf(" Layout : %s\n", c
?c
:"-unknown-");
187 if (array
.level
== 10) {
188 printf(" Layout : near=%d, far=%d\n",
189 array
.layout
&255, (array
.layout
>>8)&255);
191 switch (array
.level
) {
197 printf(" Chunk Size : %dK\n\n", array
.chunk_size
/1024);
200 printf(" Rounding : %dK\n\n", array
.chunk_size
/1024);
205 if (e
&& e
->percent
>= 0) {
206 printf(" Rebuild Status : %d%% complete\n\n", e
->percent
);
212 st
->ss
->detail_super(super
);
214 printf(" Number Major Minor RaidDevice State\n");
216 for (d
= 0; d
< max_disks
; d
++) {
217 mdu_disk_info_t disk
;
220 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
221 if (d
< array
.raid_disks
)
222 fprintf(stderr
, Name
": cannot get device detail for device %d: %s\n",
226 if (d
>= array
.raid_disks
&&
231 if (disk
.number
== array
.raid_disks
) printf("\n");
232 if (disk
.raid_disk
< 0)
233 printf(" %5d %5d %5d - ",
234 disk
.number
, disk
.major
, disk
.minor
);
236 printf(" %5d %5d %5d %5d ",
237 disk
.number
, disk
.major
, disk
.minor
, disk
.raid_disk
);
238 if (disk
.state
& (1<<MD_DISK_FAULTY
)) {
240 if (disk
.raid_disk
< array
.raid_disks
&&
244 if (disk
.state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
245 if (disk
.state
& (1<<MD_DISK_SYNC
)) printf(" sync");
246 if (disk
.state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
247 if (disk
.state
== 0) printf(" spare");
248 if (disk
.state
== 0) {
250 if (disk
.raid_disk
< array
.raid_disks
&& disk
.raid_disk
>= 0)
251 printf(" rebuilding");
252 } else if (is_rebuilding
&& failed
) {
253 /* Taking a bit of a risk here, we remove the
254 * device from the array, and then put it back.
255 * If this fails, we are rebuilding
257 int err
= ioctl(fd
, HOT_REMOVE_DISK
, makedev(disk
.major
, disk
.minor
));
258 if (err
== 0) ioctl(fd
, HOT_ADD_DISK
, makedev(disk
.major
, disk
.minor
));
259 if (err
&& errno
== EBUSY
)
260 printf(" rebuilding");
264 if (disk
.state
== 0) spares
++;
265 if (test
&& d
< array
.raid_disks
&& disk
.state
& (1<<MD_DISK_FAULTY
)) {
266 if ((rv
& 1) && (array
.level
==4 || array
.level
== 5))
270 if ((dv
=map_dev(disk
.major
, disk
.minor
))) {
273 devices
= realloc(devices
,
274 strlen(devices
)+1+strlen(dv
)+1);
275 strcat(strcat(devices
,","),dv
);
277 devices
= strdup(dv
);
281 if (!brief
) printf("\n");
283 if (spares
&& brief
) printf(" spares=%d", spares
);
284 if (super
&& brief
&& st
)
285 st
->ss
->brief_detail_super(super
);
287 if (brief
> 1 && devices
) printf("\n devices=%s", devices
);
288 if (brief
) printf("\n");
289 if (test
&& (rv
&2)) rv
&= ~1;