]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Examine.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
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.
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.
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
22 * Email: <neilb@suse.de>
28 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
29 #error no endian defined
33 int Examine(struct mddev_dev
*devlist
,
35 struct supertype
*forcest
)
38 /* Read the raid superblock from a device and
39 * display important content.
41 * If cannot be found, print reason: too small, bad magic
44 * version, ctime, level, size, raid+spare+
50 * If (brief) gather devices for same array and just print a mdadm.conf
51 * line including devices=
52 * if devlist==NULL, use conf_get_devs()
66 for (; devlist
; devlist
= devlist
->next
) {
68 int have_container
= 0;
70 fd
= dev_open(devlist
->devname
, O_RDONLY
);
73 pr_err("cannot open %s: %s\n",
74 devlist
->devname
, strerror(errno
));
82 st
= dup_super(forcest
);
83 else if (must_be_container(fd
)) {
84 /* might be a container */
85 st
= super_by_fd(fd
, NULL
);
91 st
->ignore_hw_compat
= 1;
93 err
= st
->ss
->load_super(st
, fd
,
94 (c
->brief
||c
->scan
) ? NULL
96 if (err
&& st
->ss
->load_container
) {
97 err
= st
->ss
->load_container(st
, fd
,
98 (c
->brief
||c
->scan
) ? NULL
103 st
->ignore_hw_compat
= 0;
106 pr_err("No md superblock detected on %s.\n", devlist
->devname
);
117 st
->ss
->update_super(st
, NULL
, "sparc2.2",
118 devlist
->devname
, 0, 0, NULL
);
119 /* Ok, its good enough to try, though the checksum could be wrong */
121 if (c
->brief
&& st
->ss
->brief_examine_super
== NULL
) {
123 pr_err("No brief listing for %s on %s\n",
124 st
->ss
->name
, devlist
->devname
);
125 } else if (c
->brief
) {
128 for (ap
= arrays
; ap
; ap
= ap
->next
) {
129 if (st
->ss
== ap
->st
->ss
&&
130 st
->ss
->compare_super(ap
->st
, st
) == 0)
134 ap
= xmalloc(sizeof(*ap
));
135 ap
->devs
= dl_head();
140 st
->ss
->getinfo_super(st
, &ap
->info
, NULL
);
142 st
->ss
->getinfo_super(st
, &ap
->info
, NULL
);
143 if (!have_container
&&
144 !(ap
->info
.disk
.state
& (1<<MD_DISK_SYNC
)))
146 d
= dl_strdup(devlist
->devname
);
148 } else if (c
->export
) {
149 if (st
->ss
->export_examine_super
)
150 st
->ss
->export_examine_super(st
);
151 st
->ss
->free_super(st
);
153 printf("%s:\n",devlist
->devname
);
154 st
->ss
->examine_super(st
, c
->homehost
);
155 st
->ss
->free_super(st
);
160 for (ap
= arrays
; ap
; ap
= ap
->next
) {
165 ap
->st
->ss
->brief_examine_super(ap
->st
, c
->verbose
> 0);
167 newline
+= printf(" spares=%d", ap
->spares
);
168 if (c
->verbose
> 0) {
169 newline
+= printf(" devices");
170 for (d
= dl_next(ap
->devs
);
173 printf("%c%s", sep
, d
);
177 if (ap
->st
->ss
->brief_examine_subarrays
) {
180 ap
->st
->ss
->brief_examine_subarrays(ap
->st
, c
->verbose
);
182 ap
->st
->ss
->free_super(ap
->st
);
184 if (ap
->spares
|| c
->verbose
> 0)
191 int ExamineBadblocks(char *devname
, int brief
, struct supertype
*forcest
)
193 int fd
= dev_open(devname
, O_RDONLY
);
194 struct supertype
*st
= forcest
;
198 pr_err("cannot open %s: %s\n", devname
, strerror(errno
));
202 st
= guess_super(fd
);
205 pr_err("No md superblock detected on %s\n", devname
);
208 if (!st
->ss
->examine_badblocks
) {
209 pr_err("%s metadata does not support badblocks\n", st
->ss
->name
);
212 err
= st
->ss
->load_super(st
, fd
, brief
? NULL
: devname
);
215 err
= st
->ss
->examine_badblocks(st
, fd
, devname
);
221 st
->ss
->free_super(st
);