]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
e736b623 | 4 | * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de> |
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 | |
e736b623 | 22 | * Email: <neilb@suse.de> |
64c4757e NB |
23 | */ |
24 | ||
9a9dab36 | 25 | #include "mdadm.h" |
cd29a5c8 | 26 | #include "dlink.h" |
64c4757e | 27 | |
82b27616 NB |
28 | #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN) |
29 | #error no endian defined | |
30 | #endif | |
64c4757e NB |
31 | #include "md_u.h" |
32 | #include "md_p.h" | |
a655e550 | 33 | int Examine(struct mddev_dev *devlist, int brief, int export, int scan, |
a1cbd7d0 NB |
34 | int SparcAdjust, struct supertype *forcest, |
35 | char *homehost) | |
64c4757e NB |
36 | { |
37 | ||
38 | /* Read the raid superblock from a device and | |
39 | * display important content. | |
40 | * | |
41 | * If cannot be found, print reason: too small, bad magic | |
42 | * | |
43 | * Print: | |
44 | * version, ctime, level, size, raid+spare+ | |
45 | * prefered minor | |
46 | * uuid | |
47 | * | |
48 | * utime, state etc | |
49 | * | |
9a9dab36 | 50 | * If (brief) gather devices for same array and just print a mdadm.conf line including devices= |
8b0dabea | 51 | * if devlist==NULL, use conf_get_devs() |
64c4757e | 52 | */ |
aba69144 | 53 | int fd; |
cd29a5c8 | 54 | int rv = 0; |
6baf9a87 | 55 | int err = 0; |
64c4757e | 56 | |
cd29a5c8 | 57 | struct array { |
82d9eba6 | 58 | struct supertype *st; |
4b1ac34b | 59 | struct mdinfo info; |
cd29a5c8 NB |
60 | void *devs; |
61 | struct array *next; | |
4b1ac34b | 62 | int spares; |
cd29a5c8 NB |
63 | } *arrays = NULL; |
64 | ||
cd29a5c8 | 65 | for (; devlist ; devlist=devlist->next) { |
0ea2b5ef | 66 | struct supertype *st; |
1f49fb3a | 67 | int have_container = 0; |
f9ce90ba | 68 | |
8b0dabea | 69 | fd = dev_open(devlist->devname, O_RDONLY); |
cd29a5c8 | 70 | if (fd < 0) { |
751406f3 | 71 | if (!scan) { |
cd29a5c8 NB |
72 | fprintf(stderr,Name ": cannot open %s: %s\n", |
73 | devlist->devname, strerror(errno)); | |
e52f8e25 | 74 | rv = 1; |
751406f3 | 75 | } |
e52f8e25 | 76 | err = 1; |
cd29a5c8 NB |
77 | } |
78 | else { | |
1f49fb3a | 79 | int container = 0; |
0ea2b5ef N |
80 | if (forcest) |
81 | st = dup_super(forcest); | |
3a371610 | 82 | else if (must_be_container(fd)) { |
1f49fb3a N |
83 | /* might be a container */ |
84 | st = super_by_fd(fd, NULL); | |
85 | container = 1; | |
86 | } else | |
82d9eba6 | 87 | st = guess_super(fd); |
1f49fb3a N |
88 | if (st) { |
89 | err = 1; | |
df3346e6 | 90 | st->ignore_hw_compat = 1; |
1f49fb3a N |
91 | if (!container) |
92 | err = st->ss->load_super(st, fd, | |
93 | (brief||scan) ? NULL | |
94 | :devlist->devname); | |
95 | if (err && st->ss->load_container) { | |
96 | err = st->ss->load_container(st, fd, | |
97 | (brief||scan) ? NULL | |
98 | :devlist->devname); | |
99 | if (!err) | |
100 | have_container = 1; | |
101 | } | |
df3346e6 | 102 | st->ignore_hw_compat = 0; |
1f49fb3a | 103 | } else { |
e52f8e25 | 104 | if (!brief) { |
6baf9a87 | 105 | fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname); |
e52f8e25 NB |
106 | rv = 1; |
107 | } | |
f9ce90ba | 108 | err = 1; |
6baf9a87 | 109 | } |
cd29a5c8 NB |
110 | close(fd); |
111 | } | |
e52f8e25 | 112 | if (err) |
cd29a5c8 | 113 | continue; |
4b1ac34b NB |
114 | |
115 | if (SparcAdjust) | |
3da92f27 | 116 | st->ss->update_super(st, NULL, "sparc2.2", |
68c7d6d7 | 117 | devlist->devname, 0, 0, NULL); |
cd29a5c8 | 118 | /* Ok, its good enough to try, though the checksum could be wrong */ |
0d726f17 | 119 | |
0f22b998 N |
120 | if (brief && st->ss->brief_examine_super == NULL) { |
121 | if (!scan) | |
122 | fprintf(stderr, Name ": No brief listing for %s on %s\n", | |
123 | st->ss->name, devlist->devname); | |
124 | } else if (brief) { | |
cd29a5c8 NB |
125 | struct array *ap; |
126 | char *d; | |
127 | for (ap=arrays; ap; ap=ap->next) { | |
68c7d6d7 | 128 | if (st->ss == ap->st->ss && |
64557c33 | 129 | st->ss->compare_super(ap->st, st)==0) |
cd29a5c8 NB |
130 | break; |
131 | } | |
132 | if (!ap) { | |
133 | ap = malloc(sizeof(*ap)); | |
cd29a5c8 NB |
134 | ap->devs = dl_head(); |
135 | ap->next = arrays; | |
4b1ac34b | 136 | ap->spares = 0; |
82d9eba6 | 137 | ap->st = st; |
cd29a5c8 | 138 | arrays = ap; |
a5d85af7 | 139 | st->ss->getinfo_super(st, &ap->info, NULL); |
37424f13 | 140 | } else |
a5d85af7 | 141 | st->ss->getinfo_super(st, &ap->info, NULL); |
1f49fb3a | 142 | if (!have_container && |
ed57a7e8 | 143 | !(ap->info.disk.state & (1<<MD_DISK_SYNC))) |
4b1ac34b | 144 | ap->spares++; |
cd29a5c8 NB |
145 | d = dl_strdup(devlist->devname); |
146 | dl_add(ap->devs, d); | |
0d726f17 | 147 | } else if (export) { |
bceedeec N |
148 | if (st->ss->export_examine_super) |
149 | st->ss->export_examine_super(st); | |
1cc7f4fe | 150 | st->ss->free_super(st); |
cd29a5c8 NB |
151 | } else { |
152 | printf("%s:\n",devlist->devname); | |
3da92f27 NB |
153 | st->ss->examine_super(st, homehost); |
154 | st->ss->free_super(st); | |
bd526cee | 155 | } |
82b27616 | 156 | } |
cd29a5c8 NB |
157 | if (brief) { |
158 | struct array *ap; | |
159 | for (ap=arrays; ap; ap=ap->next) { | |
160 | char sep='='; | |
cd29a5c8 | 161 | char *d; |
ee836c39 DW |
162 | int newline = 0; |
163 | ||
061f2c6a | 164 | ap->st->ss->brief_examine_super(ap->st, brief > 1); |
ee836c39 DW |
165 | if (ap->spares) |
166 | newline += printf(" spares=%d", ap->spares); | |
22892d56 | 167 | if (brief > 1) { |
ee836c39 | 168 | newline += printf(" devices"); |
22892d56 NB |
169 | for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) { |
170 | printf("%c%s", sep, d); | |
171 | sep=','; | |
172 | } | |
cd29a5c8 | 173 | } |
ee836c39 DW |
174 | if (ap->st->ss->brief_examine_subarrays) { |
175 | if (newline) | |
176 | printf("\n"); | |
4737ae25 | 177 | ap->st->ss->brief_examine_subarrays(ap->st, brief > 1); |
ee836c39 | 178 | } |
3da92f27 | 179 | ap->st->ss->free_super(ap->st); |
4b1ac34b | 180 | /* FIXME free ap */ |
d9d4e469 NB |
181 | if (ap->spares || brief > 1) |
182 | printf("\n"); | |
cd29a5c8 | 183 | } |
64c4757e | 184 | } |
cd29a5c8 | 185 | return rv; |
64c4757e | 186 | } |