1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* mdadm - manage Linux "md" devices aka RAID arrays.
*
* Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Neil Brown
* Email: <neilb@suse.de>
*/
#include "mdadm.h"
#include "dlink.h"
#if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
#error no endian defined
#endif
#include "md_u.h"
#include "md_p.h"
int Examine(struct mddev_dev *devlist, int brief, int export, int scan,
int SparcAdjust, struct supertype *forcest,
char *homehost)
{
/* Read the raid superblock from a device and
* display important content.
*
* If cannot be found, print reason: too small, bad magic
*
* Print:
* version, ctime, level, size, raid+spare+
* prefered minor
* uuid
*
* utime, state etc
*
* If (brief) gather devices for same array and just print a mdadm.conf line including devices=
* if devlist==NULL, use conf_get_devs()
*/
int fd;
int rv = 0;
int err = 0;
struct array {
struct supertype *st;
struct mdinfo info;
void *devs;
struct array *next;
int spares;
} *arrays = NULL;
for (; devlist ; devlist=devlist->next) {
struct supertype *st;
int have_container = 0;
fd = dev_open(devlist->devname, O_RDONLY);
if (fd < 0) {
if (!scan) {
fprintf(stderr,Name ": cannot open %s: %s\n",
devlist->devname, strerror(errno));
rv = 1;
}
err = 1;
}
else {
int container = 0;
if (forcest)
st = dup_super(forcest);
else if (must_be_container(fd)) {
/* might be a container */
st = super_by_fd(fd, NULL);
container = 1;
} else
st = guess_super(fd);
if (st) {
err = 1;
if (!container)
err = st->ss->load_super(st, fd,
(brief||scan) ? NULL
:devlist->devname);
if (err && st->ss->load_container) {
err = st->ss->load_container(st, fd,
(brief||scan) ? NULL
:devlist->devname);
if (!err)
have_container = 1;
}
} else {
if (!brief) {
fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
rv = 1;
}
err = 1;
}
close(fd);
}
if (err)
continue;
if (SparcAdjust)
st->ss->update_super(st, NULL, "sparc2.2",
devlist->devname, 0, 0, NULL);
/* Ok, its good enough to try, though the checksum could be wrong */
if (brief && st->ss->brief_examine_super == NULL) {
if (!scan)
fprintf(stderr, Name ": No brief listing for %s on %s\n",
st->ss->name, devlist->devname);
} else if (brief) {
struct array *ap;
char *d;
for (ap=arrays; ap; ap=ap->next) {
if (st->ss == ap->st->ss &&
st->ss->compare_super(ap->st, st)==0)
break;
}
if (!ap) {
ap = malloc(sizeof(*ap));
ap->devs = dl_head();
ap->next = arrays;
ap->spares = 0;
ap->st = st;
arrays = ap;
st->ss->getinfo_super(st, &ap->info, NULL);
} else
st->ss->getinfo_super(st, &ap->info, NULL);
if (!have_container &&
!(ap->info.disk.state & (1<<MD_DISK_SYNC)))
ap->spares++;
d = dl_strdup(devlist->devname);
dl_add(ap->devs, d);
} else if (export) {
if (st->ss->export_examine_super)
st->ss->export_examine_super(st);
} else {
printf("%s:\n",devlist->devname);
st->ss->examine_super(st, homehost);
st->ss->free_super(st);
}
}
if (brief) {
struct array *ap;
for (ap=arrays; ap; ap=ap->next) {
char sep='=';
char *d;
int newline = 0;
ap->st->ss->brief_examine_super(ap->st, brief > 1);
if (ap->spares)
newline += printf(" spares=%d", ap->spares);
if (brief > 1) {
newline += printf(" devices");
for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
printf("%c%s", sep, d);
sep=',';
}
}
if (ap->st->ss->brief_examine_subarrays) {
if (newline)
printf("\n");
ap->st->ss->brief_examine_subarrays(ap->st, brief > 1);
}
ap->st->ss->free_super(ap->st);
/* FIXME free ap */
if (ap->spares || brief > 1)
printf("\n");
}
}
return rv;
}
|