]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
419c45cbdc6e1ec161742808e2c994452a9d6509
[thirdparty/mdadm.git] / Detail.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
5 *
6 *
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.
11 *
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.
16 *
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
20 *
21 * Author: Neil Brown
22 * Email: <neilb@cse.unsw.edu.au>
23 * Paper: Neil Brown
24 * School of Computer Science and Engineering
25 * The University of New South Wales
26 * Sydney, 2052
27 * Australia
28 */
29
30 #include "mdadm.h"
31 #include "md_p.h"
32 #include "md_u.h"
33
34 int Detail(char *dev, int brief, int test)
35 {
36 /*
37 * Print out details for an md array by using
38 * GET_ARRAY_INFO and GET_DISK_INFO ioctl calls
39 */
40
41 int fd = open(dev, O_RDONLY, 0);
42 int vers;
43 mdu_array_info_t array;
44 int d;
45 time_t atime;
46 char *c;
47 char *devices = NULL;
48 int spares = 0;
49
50 mdp_super_t super;
51 int have_super = 0;
52 int rv = test ? 4 : 1;
53
54 if (fd < 0) {
55 fprintf(stderr, Name ": cannot open %s: %s\n",
56 dev, strerror(errno));
57 return rv;
58 }
59 vers = md_get_version(fd);
60 if (vers < 0) {
61 fprintf(stderr, Name ": %s does not appear to be an md device\n",
62 dev);
63 close(fd);
64 return rv;
65 }
66 if (vers < 9000) {
67 fprintf(stderr, Name ": cannot get detail for md device %s: driver version too old.\n",
68 dev);
69 close(fd);
70 return rv;
71 }
72 if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
73 if (errno == ENODEV)
74 fprintf(stderr, Name ": md device %s does not appear to be active.\n",
75 dev);
76 else
77 fprintf(stderr, Name ": cannot get array detail for %s: %s\n",
78 dev, strerror(errno));
79 close(fd);
80 return rv;
81 }
82 rv = 0;
83 /* Ok, we have some info to print... */
84 c = map_num(pers, array.level);
85 if (brief)
86 printf("ARRAY %s level=%s num-devices=%d", dev, c?c:"-unknown-",array.raid_disks );
87 else {
88 unsigned long array_size;
89 unsigned long long larray_size;
90 #ifdef BLKGETSIZE64
91 if (ioctl(fd, BLKGETSIZE64, &larray_size)==0)
92 ;
93 else
94 #endif
95 if (ioctl(fd, BLKGETSIZE, &array_size)==0) {
96 larray_size = array_size;
97 larray_size <<= 9;
98 }
99
100 else larray_size = 0;
101
102 printf("%s:\n", dev);
103 printf(" Version : %02d.%02d.%02d\n",
104 array.major_version, array.minor_version, array.patch_version);
105 atime = array.ctime;
106 printf(" Creation Time : %.24s\n", ctime(&atime));
107 printf(" Raid Level : %s\n", c?c:"-unknown-");
108 if (larray_size)
109 printf(" Array Size : %llu%s\n", (larray_size>>10), human_size(larray_size));
110 if (array.level >= 1)
111 printf(" Device Size : %d%s\n", array.size, human_size((long long)array.size<<10));
112 printf(" Raid Devices : %d\n", array.raid_disks);
113 printf(" Total Devices : %d\n", array.nr_disks);
114 printf("Preferred Minor : %d\n", array.md_minor);
115 printf(" Persistence : Superblock is %spersistent\n",
116 array.not_persistent?"not ":"");
117 printf("\n");
118 atime = array.utime;
119 printf(" Update Time : %.24s\n", ctime(&atime));
120 printf(" State : %s, %serrors\n",
121 (array.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
122 (array.state&(1<<MD_SB_ERRORS))?"":"no-");
123 printf(" Active Devices : %d\n", array.active_disks);
124 printf("Working Devices : %d\n", array.working_disks);
125 printf(" Failed Devices : %d\n", array.failed_disks);
126 printf(" Spare Devices : %d\n", array.spare_disks);
127 printf("\n");
128 if (array.level == 5) {
129 c = map_num(r5layout, array.layout);
130 printf(" Layout : %s\n", c?c:"-unknown-");
131 }
132 switch (array.level) {
133 case 0:
134 case 4:
135 case 5:
136 printf(" Chunk Size : %dK\n", array.chunk_size/1024);
137 break;
138 case -1:
139 printf(" Rounding : %dK\n", array.chunk_size/1024);
140 break;
141 default: break;
142 }
143
144 printf("\n");
145 {
146 struct mdstat_ent *ms = mdstat_read();
147 struct mdstat_ent *e;
148 for (e=ms; e; e=e->next)
149 if (e->devnum == array.md_minor) {
150 if (e->percent >= 0)
151 printf(" Rebuild Status : %d%% complete\n\n", e->percent);
152 break;
153 }
154 free_mdstat(ms);
155 }
156 printf(" Number Major Minor RaidDevice State\n");
157 }
158 for (d= 0; d<MD_SB_DISKS; d++) {
159 mdu_disk_info_t disk;
160 char *dv;
161 disk.number = d;
162 if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
163 if (d < array.raid_disks)
164 fprintf(stderr, Name ": cannot get device detail for device %d: %s\n",
165 d, strerror(errno));
166 continue;
167 }
168 if (d >= array.raid_disks &&
169 disk.major == 0 &&
170 disk.minor == 0)
171 continue;
172 if (!brief) {
173 printf(" %5d %5d %5d %5d ",
174 disk.number, disk.major, disk.minor, disk.raid_disk);
175 if (disk.state & (1<<MD_DISK_FAULTY)) printf(" faulty");
176 if (disk.state & (1<<MD_DISK_ACTIVE)) printf(" active");
177 if (disk.state & (1<<MD_DISK_SYNC)) printf(" sync");
178 if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed");
179 if (disk.state == 0) { printf(" spare"); spares++; }
180 }
181 if (test && d < array.raid_disks && disk.state & (1<<MD_DISK_FAULTY)) {
182 if ((rv & 1) && (array.level ==4 || array.level == 5))
183 rv |= 2;
184 rv |= 1;
185 }
186 if ((dv=map_dev(disk.major, disk.minor))) {
187 if (brief) {
188 if (devices) {
189 devices = realloc(devices,
190 strlen(devices)+1+strlen(dv)+1);
191 strcat(strcat(devices,","),dv);
192 } else
193 devices = strdup(dv);
194 } else
195 printf(" %s", dv);
196 if (!have_super && (disk.state & (1<<MD_DISK_ACTIVE))) {
197 /* try to read the superblock from this device
198 * to get more info
199 */
200 int fd = open(dv, O_RDONLY);
201 if (fd >=0 &&
202 load_super(fd, &super) ==0 &&
203 (unsigned long)super.ctime == (unsigned long)array.ctime &&
204 (unsigned int)super.level == (unsigned int)array.level)
205 have_super = 1;
206 }
207 }
208 if (!brief) printf("\n");
209 }
210 if (spares && brief) printf(" spares=%d", spares);
211 if (have_super) {
212 if (brief) printf(" UUID=");
213 else printf(" UUID : ");
214 if (super.minor_version >= 90)
215 printf("%08x:%08x:%08x:%08x", super.set_uuid0, super.set_uuid1,
216 super.set_uuid2, super.set_uuid3);
217 else
218 printf("%08x", super.set_uuid0);
219 if (!brief)
220 printf("\n Events : %d.%d\n", super.events_hi, super.events_lo);
221 }
222 if (brief && devices) printf("\n devices=%s", devices);
223 if (brief) printf("\n");
224 if (test && (rv&2)) rv &= ~1;
225 return rv;
226 }