]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
cd29a5c8 | 4 | * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au> |
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 | |
22 | * Email: <neilb@cse.unsw.edu.au> | |
23 | * Paper: Neil Brown | |
24 | * School of Computer Science and Engineering | |
25 | * The University of New South Wales | |
26 | * Sydney, 2052 | |
27 | * Australia | |
28 | */ | |
29 | ||
9a9dab36 | 30 | #include "mdadm.h" |
cd29a5c8 | 31 | #include "dlink.h" |
64c4757e | 32 | |
82b27616 NB |
33 | #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN) |
34 | #error no endian defined | |
35 | #endif | |
64c4757e NB |
36 | #include "md_u.h" |
37 | #include "md_p.h" | |
bd526cee | 38 | int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust) |
64c4757e NB |
39 | { |
40 | ||
41 | /* Read the raid superblock from a device and | |
42 | * display important content. | |
43 | * | |
44 | * If cannot be found, print reason: too small, bad magic | |
45 | * | |
46 | * Print: | |
47 | * version, ctime, level, size, raid+spare+ | |
48 | * prefered minor | |
49 | * uuid | |
50 | * | |
51 | * utime, state etc | |
52 | * | |
9a9dab36 | 53 | * If (brief) gather devices for same array and just print a mdadm.conf line including devices= |
cd29a5c8 | 54 | * if devlist==NULL, use conf_get_devs( |
64c4757e | 55 | */ |
cd29a5c8 | 56 | int fd; |
4b1ac34b | 57 | void *super = NULL; |
cd29a5c8 NB |
58 | int rv = 0; |
59 | int err; | |
64c4757e | 60 | |
cd29a5c8 | 61 | struct array { |
4b1ac34b | 62 | void *super; |
f9ce90ba | 63 | struct superswitch *ss; |
4b1ac34b | 64 | struct mdinfo info; |
cd29a5c8 NB |
65 | void *devs; |
66 | struct array *next; | |
4b1ac34b | 67 | int spares; |
cd29a5c8 NB |
68 | } *arrays = NULL; |
69 | ||
cd29a5c8 | 70 | for (; devlist ; devlist=devlist->next) { |
f9ce90ba NB |
71 | struct superswitch *ss; |
72 | ||
cd29a5c8 NB |
73 | fd = open(devlist->devname, O_RDONLY); |
74 | if (fd < 0) { | |
75 | if (!scan) | |
76 | fprintf(stderr,Name ": cannot open %s: %s\n", | |
77 | devlist->devname, strerror(errno)); | |
78 | err = 1; | |
79 | } | |
80 | else { | |
f9ce90ba NB |
81 | ss = guess_super(fd, devlist->devname); |
82 | if (ss) | |
83 | err = ss->load_super(fd, &super, (brief||scan)?NULL:devlist->devname); | |
84 | else | |
85 | err = 1; | |
cd29a5c8 NB |
86 | close(fd); |
87 | } | |
4b1ac34b | 88 | if (err) |
cd29a5c8 NB |
89 | continue; |
90 | if (err) rv =1; | |
4b1ac34b NB |
91 | |
92 | if (SparcAdjust) | |
f9ce90ba | 93 | ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0); |
cd29a5c8 NB |
94 | /* Ok, its good enough to try, though the checksum could be wrong */ |
95 | if (brief) { | |
96 | struct array *ap; | |
97 | char *d; | |
98 | for (ap=arrays; ap; ap=ap->next) { | |
f9ce90ba | 99 | if (ss == ap->ss && ss->compare_super(&ap->super, super)==0) |
cd29a5c8 NB |
100 | break; |
101 | } | |
102 | if (!ap) { | |
103 | ap = malloc(sizeof(*ap)); | |
104 | ap->super = super; | |
105 | ap->devs = dl_head(); | |
106 | ap->next = arrays; | |
4b1ac34b | 107 | ap->spares = 0; |
f9ce90ba | 108 | ap->ss = ss; |
cd29a5c8 | 109 | arrays = ap; |
f9ce90ba | 110 | ss->getinfo_super(&ap->info, super); |
4b1ac34b | 111 | } else { |
f9ce90ba | 112 | ss->getinfo_super(&ap->info, super); |
4b1ac34b | 113 | free(super); |
cd29a5c8 | 114 | } |
4b1ac34b NB |
115 | if (!(ap->info.disk.state & MD_DISK_SYNC)) |
116 | ap->spares++; | |
cd29a5c8 NB |
117 | d = dl_strdup(devlist->devname); |
118 | dl_add(ap->devs, d); | |
119 | } else { | |
120 | printf("%s:\n",devlist->devname); | |
f9ce90ba | 121 | ss->examine_super(super); |
4b1ac34b | 122 | free(super); |
bd526cee | 123 | } |
82b27616 | 124 | } |
cd29a5c8 NB |
125 | if (brief) { |
126 | struct array *ap; | |
127 | for (ap=arrays; ap; ap=ap->next) { | |
128 | char sep='='; | |
cd29a5c8 | 129 | char *d; |
f9ce90ba | 130 | ap->ss->brief_examine_super(ap->super); |
4b1ac34b NB |
131 | if (ap->spares) printf(" spares=%d", ap->spares); |
132 | printf(" devices"); | |
cd29a5c8 NB |
133 | for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) { |
134 | printf("%c%s", sep, d); | |
135 | sep=','; | |
136 | } | |
4b1ac34b NB |
137 | free(ap->super); |
138 | /* FIXME free ap */ | |
cd29a5c8 NB |
139 | printf("\n"); |
140 | } | |
64c4757e | 141 | } |
cd29a5c8 | 142 | return rv; |
64c4757e | 143 | } |