]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Examine.c
mdadm-0.7
[thirdparty/mdadm.git] / Examine.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 "dlink.h"
32
33 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
34 #error no endian defined
35 #endif
36 #include "md_u.h"
37 #include "md_p.h"
38 int Examine(mddev_dev_t devlist, int brief, char *conffile)
39 {
40
41 /* Read the raid superblock from a device and
42 * display important content.
43 *
44 * If cannot be found, print reason: too small, bad magic
45 *
46 * Print:
47 * version, ctime, level, size, raid+spare+
48 * prefered minor
49 * uuid
50 *
51 * utime, state etc
52 *
53 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
54 * if devlist==NULL, use conf_get_devs(
55 */
56 int fd;
57 time_t atime;
58 mdp_super_t super;
59 int d;
60 char *c;
61 int rv = 0;
62 int err;
63 int scan= 0;
64
65 struct array {
66 mdp_super_t super;
67 void *devs;
68 struct array *next;
69 } *arrays = NULL;
70
71 if (devlist == NULL) {
72 devlist = conf_get_devs(conffile);
73 scan=1;
74 }
75 if (devlist == NULL) {
76 fprintf(stderr, Name ": No devices listed in %s\n", conffile);
77 return 1;
78 }
79
80 for (; devlist ; devlist=devlist->next) {
81 fd = open(devlist->devname, O_RDONLY);
82 if (fd < 0) {
83 if (!scan)
84 fprintf(stderr,Name ": cannot open %s: %s\n",
85 devlist->devname, strerror(errno));
86 err = 1;
87 }
88 else {
89 err = load_super(fd, &super);
90 close(fd);
91 }
92 if (err && (brief||scan))
93 continue;
94 if (err) rv =1;
95 switch(err) {
96 case 1:
97 fprintf(stderr, Name ": cannot find device size for %s: %s\n",
98 devlist->devname, strerror(errno));
99 continue;
100 case 2:
101 /* fprintf(stderr, Name ": %s is too small for md: size is %ld sectors\n",
102 devlist->devname, size);
103 */
104 fprintf(stderr, Name ": %s is too small for md\n",
105 devlist->devname);
106 continue;
107 case 3:
108 fprintf(stderr, Name ": Cannot seek to superblock on %s: %s\n",
109 devlist->devname, strerror(errno));
110 continue;
111 case 4:
112 fprintf(stderr, Name ": Cannot read superblock on %s\n",
113 devlist->devname);
114 continue;
115 case 5:
116 fprintf(stderr, Name ": No super block found on %s (Expected magic %08x, got %08x)\n",
117 devlist->devname, MD_SB_MAGIC, super.md_magic);
118 continue;
119 case 6:
120 fprintf(stderr, Name ": Cannot interpret superblock on %s - version is %d\n",
121 devlist->devname, super.major_version);
122 continue;
123 }
124
125 /* Ok, its good enough to try, though the checksum could be wrong */
126 if (brief) {
127 struct array *ap;
128 char *d;
129 for (ap=arrays; ap; ap=ap->next) {
130 if (compare_super(&ap->super, &super)==0)
131 break;
132 }
133 if (!ap) {
134 ap = malloc(sizeof(*ap));
135 ap->super = super;
136 ap->devs = dl_head();
137 ap->next = arrays;
138 arrays = ap;
139 }
140 d = dl_strdup(devlist->devname);
141 dl_add(ap->devs, d);
142 } else {
143 printf("%s:\n",devlist->devname);
144 printf(" Magic : %08x\n", super.md_magic);
145 printf(" Version : %02d.%02d.%02d\n", super.major_version, super.minor_version,
146 super.patch_version);
147 if (super.minor_version >= 90)
148 printf(" UUID : %08x:%08x:%08x:%08x\n", super.set_uuid0, super.set_uuid1,
149 super.set_uuid2, super.set_uuid3);
150 else
151 printf(" UUID : %08x\n", super.set_uuid0);
152
153 atime = super.ctime;
154 printf(" Creation Time : %.24s\n", ctime(&atime));
155 c=map_num(pers, super.level);
156 printf(" Raid Level : %s\n", c?c:"-unknown-");
157 printf(" Device Size : %d%s\n", super.size, human_size(super.size));
158 printf(" Raid Disks : %d\n", super.raid_disks);
159 printf(" Total Disks : %d\n", super.nr_disks);
160 printf("Preferred Minor : %d\n", super.md_minor);
161 printf("\n");
162 atime = super.utime;
163 printf(" Update Time : %.24s\n", ctime(&atime));
164 printf(" State : %s, %serrors\n",
165 (super.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
166 (super.state&(1<<MD_SB_ERRORS))?"":"no-");
167 printf(" Active Drives : %d\n", super.active_disks);
168 printf(" Working Drives : %d\n", super.working_disks);
169 printf(" Failed Drives : %d\n", super.failed_disks);
170 printf(" Spare Drives : %d\n", super.spare_disks);
171 if (calc_sb_csum(&super) == super.sb_csum)
172 printf(" Checksum : %x - correct\n", super.sb_csum);
173 else
174 printf(" Checksum : %x - expected %x\n", super.sb_csum, calc_sb_csum(&super));
175 printf(" Events : %d.%d\n", super.events_hi, super.events_lo);
176 printf("\n");
177 if (super.level == 5) {
178 c = map_num(r5layout, super.layout);
179 printf(" Layout : %s\n", c?c:"-unknown-");
180 }
181 switch(super.level) {
182 case 0:
183 case 4:
184 case 5:
185 printf(" Chunk Size : %dK\n", super.chunk_size/1024);
186 break;
187 case -1:
188 printf(" Rounding : %dK\n", super.chunk_size/1024);
189 break;
190 default: break;
191 }
192 printf("\n");
193 printf(" Number Major Minor RaidDisk State\n");
194 for (d= -1; d<(signed int)(super.raid_disks+super.spare_disks); d++) {
195 mdp_disk_t *dp;
196 char *dv;
197 char nb[5];
198 if (d>=0) dp = &super.disks[d];
199 else dp = &super.this_disk;
200 sprintf(nb, "%4d", d);
201 printf("%4s %5d %5d %5d %5d ", d < 0 ? "this" : nb,
202 dp->number, dp->major, dp->minor, dp->raid_disk);
203 if (dp->state & (1<<MD_DISK_FAULTY)) printf(" faulty");
204 if (dp->state & (1<<MD_DISK_ACTIVE)) printf(" active");
205 if (dp->state & (1<<MD_DISK_SYNC)) printf(" sync");
206 if (dp->state & (1<<MD_DISK_REMOVED)) printf(" removed");
207 if ((dv=map_dev(dp->major, dp->minor)))
208 printf(" %s", dv);
209 printf("\n");
210 }
211 }
212 }
213 if (brief) {
214 struct array *ap;
215 for (ap=arrays; ap; ap=ap->next) {
216 char sep='=';
217 char *c=map_num(pers, ap->super.level);
218 char *d;
219 printf("ARRAY /dev/md%d level=%s disks=%d UUID=",
220 ap->super.md_minor, c?c:"-unknown-", ap->super.raid_disks);
221 if (ap->super.minor_version >= 90)
222 printf("%08x:%08x:%08x:%08x", ap->super.set_uuid0, ap->super.set_uuid1,
223 ap->super.set_uuid2, ap->super.set_uuid3);
224 else
225 printf("%08x", ap->super.set_uuid0);
226 printf("\n devices");
227 for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
228 printf("%c%s", sep, d);
229 sep=',';
230 }
231 printf("\n");
232 }
233 }
234 return rv;
235 }