]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
ca3b6696 | 4 | * Copyright (C) 2001-2012 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" | |
eec3f887 N |
33 | int Examine(struct mddev_dev *devlist, |
34 | struct context *c, | |
35 | struct supertype *forcest) | |
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 | * | |
ca3b6696 N |
50 | * If (brief) gather devices for same array and just print a mdadm.conf |
51 | * line including devices= | |
8b0dabea | 52 | * if devlist==NULL, use conf_get_devs() |
64c4757e | 53 | */ |
aba69144 | 54 | int fd; |
cd29a5c8 | 55 | int rv = 0; |
6baf9a87 | 56 | int err = 0; |
64c4757e | 57 | |
cd29a5c8 | 58 | struct array { |
82d9eba6 | 59 | struct supertype *st; |
4b1ac34b | 60 | struct mdinfo info; |
cd29a5c8 NB |
61 | void *devs; |
62 | struct array *next; | |
4b1ac34b | 63 | int spares; |
cd29a5c8 NB |
64 | } *arrays = NULL; |
65 | ||
ca3b6696 | 66 | for (; devlist ; devlist = devlist->next) { |
0ea2b5ef | 67 | struct supertype *st; |
1f49fb3a | 68 | int have_container = 0; |
f9ce90ba | 69 | |
8b0dabea | 70 | fd = dev_open(devlist->devname, O_RDONLY); |
cd29a5c8 | 71 | if (fd < 0) { |
eec3f887 | 72 | if (!c->scan) { |
e7b84f9d N |
73 | pr_err("cannot open %s: %s\n", |
74 | devlist->devname, strerror(errno)); | |
e52f8e25 | 75 | rv = 1; |
751406f3 | 76 | } |
e52f8e25 | 77 | err = 1; |
cd29a5c8 NB |
78 | } |
79 | else { | |
1f49fb3a | 80 | int container = 0; |
0ea2b5ef N |
81 | if (forcest) |
82 | st = dup_super(forcest); | |
3a371610 | 83 | else if (must_be_container(fd)) { |
1f49fb3a N |
84 | /* might be a container */ |
85 | st = super_by_fd(fd, NULL); | |
86 | container = 1; | |
87 | } else | |
82d9eba6 | 88 | st = guess_super(fd); |
1f49fb3a N |
89 | if (st) { |
90 | err = 1; | |
df3346e6 | 91 | st->ignore_hw_compat = 1; |
1f49fb3a N |
92 | if (!container) |
93 | err = st->ss->load_super(st, fd, | |
eec3f887 | 94 | (c->brief||c->scan) ? NULL |
1f49fb3a N |
95 | :devlist->devname); |
96 | if (err && st->ss->load_container) { | |
97 | err = st->ss->load_container(st, fd, | |
eec3f887 | 98 | (c->brief||c->scan) ? NULL |
1f49fb3a N |
99 | :devlist->devname); |
100 | if (!err) | |
101 | have_container = 1; | |
102 | } | |
df3346e6 | 103 | st->ignore_hw_compat = 0; |
1f49fb3a | 104 | } else { |
eec3f887 | 105 | if (!c->brief) { |
e7b84f9d | 106 | pr_err("No md superblock detected on %s.\n", devlist->devname); |
e52f8e25 NB |
107 | rv = 1; |
108 | } | |
f9ce90ba | 109 | err = 1; |
6baf9a87 | 110 | } |
cd29a5c8 NB |
111 | close(fd); |
112 | } | |
e52f8e25 | 113 | if (err) |
cd29a5c8 | 114 | continue; |
4b1ac34b | 115 | |
eec3f887 | 116 | if (c->SparcAdjust) |
3da92f27 | 117 | st->ss->update_super(st, NULL, "sparc2.2", |
68c7d6d7 | 118 | devlist->devname, 0, 0, NULL); |
cd29a5c8 | 119 | /* Ok, its good enough to try, though the checksum could be wrong */ |
0d726f17 | 120 | |
eec3f887 N |
121 | if (c->brief && st->ss->brief_examine_super == NULL) { |
122 | if (!c->scan) | |
e7b84f9d | 123 | pr_err("No brief listing for %s on %s\n", |
0f22b998 | 124 | st->ss->name, devlist->devname); |
eec3f887 | 125 | } else if (c->brief) { |
cd29a5c8 NB |
126 | struct array *ap; |
127 | char *d; | |
ca3b6696 | 128 | for (ap = arrays; ap; ap = ap->next) { |
68c7d6d7 | 129 | if (st->ss == ap->st->ss && |
ca3b6696 | 130 | st->ss->compare_super(ap->st, st) == 0) |
cd29a5c8 NB |
131 | break; |
132 | } | |
133 | if (!ap) { | |
503975b9 | 134 | ap = xmalloc(sizeof(*ap)); |
cd29a5c8 NB |
135 | ap->devs = dl_head(); |
136 | ap->next = arrays; | |
4b1ac34b | 137 | ap->spares = 0; |
82d9eba6 | 138 | ap->st = st; |
cd29a5c8 | 139 | arrays = ap; |
a5d85af7 | 140 | st->ss->getinfo_super(st, &ap->info, NULL); |
37424f13 | 141 | } else |
a5d85af7 | 142 | st->ss->getinfo_super(st, &ap->info, NULL); |
1f49fb3a | 143 | if (!have_container && |
ed57a7e8 | 144 | !(ap->info.disk.state & (1<<MD_DISK_SYNC))) |
4b1ac34b | 145 | ap->spares++; |
cd29a5c8 NB |
146 | d = dl_strdup(devlist->devname); |
147 | dl_add(ap->devs, d); | |
eec3f887 | 148 | } else if (c->export) { |
bceedeec N |
149 | if (st->ss->export_examine_super) |
150 | st->ss->export_examine_super(st); | |
1cc7f4fe | 151 | st->ss->free_super(st); |
cd29a5c8 NB |
152 | } else { |
153 | printf("%s:\n",devlist->devname); | |
eec3f887 | 154 | st->ss->examine_super(st, c->homehost); |
3da92f27 | 155 | st->ss->free_super(st); |
bd526cee | 156 | } |
82b27616 | 157 | } |
eec3f887 | 158 | if (c->brief) { |
cd29a5c8 | 159 | struct array *ap; |
ca3b6696 | 160 | for (ap = arrays; ap; ap = ap->next) { |
cd29a5c8 | 161 | char sep='='; |
cd29a5c8 | 162 | char *d; |
ee836c39 DW |
163 | int newline = 0; |
164 | ||
eec3f887 | 165 | ap->st->ss->brief_examine_super(ap->st, c->verbose > 0); |
ee836c39 DW |
166 | if (ap->spares) |
167 | newline += printf(" spares=%d", ap->spares); | |
eec3f887 | 168 | if (c->verbose > 0) { |
ee836c39 | 169 | newline += printf(" devices"); |
ca3b6696 N |
170 | for (d = dl_next(ap->devs); |
171 | d != ap->devs; | |
172 | d=dl_next(d)) { | |
22892d56 NB |
173 | printf("%c%s", sep, d); |
174 | sep=','; | |
175 | } | |
cd29a5c8 | 176 | } |
ee836c39 DW |
177 | if (ap->st->ss->brief_examine_subarrays) { |
178 | if (newline) | |
179 | printf("\n"); | |
eec3f887 | 180 | ap->st->ss->brief_examine_subarrays(ap->st, c->verbose); |
ee836c39 | 181 | } |
3da92f27 | 182 | ap->st->ss->free_super(ap->st); |
4b1ac34b | 183 | /* FIXME free ap */ |
eec3f887 | 184 | if (ap->spares || c->verbose > 0) |
d9d4e469 | 185 | printf("\n"); |
cd29a5c8 | 186 | } |
64c4757e | 187 | } |
cd29a5c8 | 188 | return rv; |
64c4757e | 189 | } |