]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
9b04efdaa02d56f9efb48f3f21b861731629dc8f
[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)
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
49 mdp_super_t super;
50 int have_super = 0;
51
52 if (fd < 0) {
53 fprintf(stderr, Name ": cannot open %s: %s\n",
54 dev, strerror(errno));
55 return 1;
56 }
57 vers = md_get_version(fd);
58 if (vers < 0) {
59 fprintf(stderr, Name ": %s does not appear to be an md device\n",
60 dev);
61 close(fd);
62 return 1;
63 }
64 if (vers < 9000) {
65 fprintf(stderr, Name ": cannot get detail for md device %s: driver version too old.\n",
66 dev);
67 close(fd);
68 return 1;
69 }
70 if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
71 if (errno == ENODEV)
72 fprintf(stderr, Name ": md device %s does not appear to be active.\n",
73 dev);
74 else
75 fprintf(stderr, Name ": cannot get array detail for %s: %s\n",
76 dev, strerror(errno));
77 close(fd);
78 return 1;
79 }
80 /* Ok, we have some info to print... */
81 c = map_num(pers, array.level);
82 if (brief)
83 printf("ARRAY %s level=%s num-devices=%d", dev, c?c:"-unknown-",array.raid_disks );
84 else {
85 unsigned long array_size;
86 unsigned long long larray_size;
87 #ifdef BLKGETSIZE64
88 if (ioctl(fd, BLKGETSIZE64, &larray_size)==0)
89 ;
90 else
91 #endif
92 if (ioctl(fd, BLKGETSIZE, &array_size)==0) {
93 larray_size = array_size;
94 larray_size <<= 9;
95 }
96
97 else larray_size = 0;
98
99 printf("%s:\n", dev);
100 printf(" Version : %02d.%02d.%02d\n",
101 array.major_version, array.minor_version, array.patch_version);
102 atime = array.ctime;
103 printf(" Creation Time : %.24s\n", ctime(&atime));
104 printf(" Raid Level : %s\n", c?c:"-unknown-");
105 if (larray_size)
106 printf(" Array Size : %llu%s\n", (larray_size>>10), human_size(larray_size));
107 if (array.level >= 1)
108 printf(" Device Size : %d%s\n", array.size, human_size((long long)array.size<<10));
109 printf(" Raid Devices : %d\n", array.raid_disks);
110 printf(" Total Devices : %d\n", array.nr_disks);
111 printf("Preferred Minor : %d\n", array.md_minor);
112 printf(" Persistence : Superblock is %spersistent\n",
113 array.not_persistent?"not ":"");
114 printf("\n");
115 atime = array.utime;
116 printf(" Update Time : %.24s\n", ctime(&atime));
117 printf(" State : %s, %serrors\n",
118 (array.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
119 (array.state&(1<<MD_SB_ERRORS))?"":"no-");
120 printf(" Active Devices : %d\n", array.active_disks);
121 printf("Working Devices : %d\n", array.working_disks);
122 printf(" Failed Devices : %d\n", array.failed_disks);
123 printf(" Spare Devices : %d\n", array.spare_disks);
124 printf("\n");
125 if (array.level == 5) {
126 c = map_num(r5layout, array.layout);
127 printf(" Layout : %s\n", c?c:"-unknown-");
128 }
129 switch (array.level) {
130 case 0:
131 case 4:
132 case 5:
133 printf(" Chunk Size : %dK\n", array.chunk_size/1024);
134 break;
135 case -1:
136 printf(" Rounding : %dK\n", array.chunk_size/1024);
137 break;
138 default: break;
139 }
140
141 printf("\n");
142 printf(" Number Major Minor RaidDevice State\n");
143 }
144 for (d= 0; d<MD_SB_DISKS; d++) {
145 mdu_disk_info_t disk;
146 char *dv;
147 disk.number = d;
148 if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
149 if (d < array.raid_disks)
150 fprintf(stderr, Name ": cannot get device detail for device %d: %s\n",
151 d, strerror(errno));
152 continue;
153 }
154 if (d >= array.raid_disks &&
155 disk.major == 0 &&
156 disk.minor == 0)
157 continue;
158 if (!brief) {
159 printf(" %5d %5d %5d %5d ",
160 disk.number, disk.major, disk.minor, disk.raid_disk);
161 if (disk.state & (1<<MD_DISK_FAULTY)) printf(" faulty");
162 if (disk.state & (1<<MD_DISK_ACTIVE)) printf(" active");
163 if (disk.state & (1<<MD_DISK_SYNC)) printf(" sync");
164 if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed");
165 if (disk.state == 0) printf(" spare");
166 }
167 if ((dv=map_dev(disk.major, disk.minor))) {
168 if (brief) {
169 if (devices) {
170 devices = realloc(devices,
171 strlen(devices)+1+strlen(dv)+1);
172 strcat(strcat(devices,","),dv);
173 } else
174 devices = strdup(dv);
175 } else
176 printf(" %s", dv);
177 if (!have_super && (disk.state & (1<<MD_DISK_ACTIVE))) {
178 /* try to read the superblock from this device
179 * to get more info
180 */
181 int fd = open(dv, O_RDONLY);
182 if (fd >=0 &&
183 load_super(fd, &super) ==0 &&
184 super.ctime == array.ctime &&
185 super.level == array.level)
186 have_super = 1;
187 }
188 }
189 if (!brief) printf("\n");
190 }
191 if (have_super) {
192 if (brief) printf(" UUID=");
193 else printf(" UUID : ");
194 if (super.minor_version >= 90)
195 printf("%08x:%08x:%08x:%08x", super.set_uuid0, super.set_uuid1,
196 super.set_uuid2, super.set_uuid3);
197 else
198 printf("%08x", super.set_uuid0);
199 if (!brief)
200 printf("\n Events : %d.%d\n", super.events_hi, super.events_lo);
201 }
202 if (brief && devices) printf("\n devices=%s", devices);
203 if (brief) printf("\n");
204 return 0;
205 }