]>
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()
65 for (; devlist
; devlist
= devlist
->next
) {
67 int have_container
= 0;
71 fd
= dev_open(devlist
->devname
, O_RDONLY
);
74 pr_err("cannot open %s: %s\n",
75 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
);
115 st
->ss
->free_super(st
);
120 st
->ss
->update_super(st
, NULL
, "sparc2.2",
121 devlist
->devname
, 0, 0, NULL
);
122 /* Ok, its good enough to try, though the checksum could be wrong */
124 if (c
->brief
&& st
->ss
->brief_examine_super
== NULL
) {
126 pr_err("No brief listing for %s on %s\n",
127 st
->ss
->name
, devlist
->devname
);
128 } else if (c
->brief
) {
131 for (ap
= arrays
; ap
; ap
= ap
->next
) {
132 if (st
->ss
== ap
->st
->ss
&&
133 st
->ss
->compare_super(ap
->st
, st
) == 0)
137 ap
= xmalloc(sizeof(*ap
));
138 ap
->devs
= dl_head();
143 st
->ss
->getinfo_super(st
, &ap
->info
, NULL
);
145 st
->ss
->getinfo_super(st
, &ap
->info
, NULL
);
146 if (!have_container
&&
147 !(ap
->info
.disk
.state
& (1<<MD_DISK_SYNC
)))
149 d
= dl_strdup(devlist
->devname
);
151 } else if (c
->export
) {
152 if (st
->ss
->export_examine_super
)
153 st
->ss
->export_examine_super(st
);
154 st
->ss
->free_super(st
);
156 printf("%s:\n",devlist
->devname
);
157 st
->ss
->examine_super(st
, c
->homehost
);
158 st
->ss
->free_super(st
);
163 for (ap
= arrays
; ap
; ap
= ap
->next
) {
168 ap
->st
->ss
->brief_examine_super(ap
->st
, c
->verbose
> 0);
170 newline
+= printf(" spares=%d", ap
->spares
);
171 if (c
->verbose
> 0) {
172 newline
+= printf(" devices");
173 for (d
= dl_next(ap
->devs
);
176 printf("%c%s", sep
, d
);
180 if (ap
->st
->ss
->brief_examine_subarrays
) {
183 ap
->st
->ss
->brief_examine_subarrays(ap
->st
, c
->verbose
);
185 ap
->st
->ss
->free_super(ap
->st
);
187 if (ap
->spares
|| c
->verbose
> 0)
194 int ExamineBadblocks(char *devname
, int brief
, struct supertype
*forcest
)
196 int fd
= dev_open(devname
, O_RDONLY
);
197 struct supertype
*st
= forcest
;
201 pr_err("cannot open %s: %s\n", devname
, strerror(errno
));
205 st
= guess_super(fd
);
208 pr_err("No md superblock detected on %s\n", devname
);
211 if (!st
->ss
->examine_badblocks
) {
212 pr_err("%s metadata does not support badblocks\n", st
->ss
->name
);
215 err
= st
->ss
->load_super(st
, fd
, brief
? NULL
: devname
);
218 err
= st
->ss
->examine_badblocks(st
, fd
, devname
);
224 st
->ss
->free_super(st
);