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