]>
Commit | Line | Data |
---|---|---|
e0d19036 NB |
1 | /* |
2 | * mdadm - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
e736b623 | 4 | * Copyright (C) 2002-2009 Neil Brown <neilb@suse.de> |
e0d19036 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> |
e0d19036 NB |
23 | */ |
24 | ||
25 | #include "mdadm.h" | |
26 | #include "md_p.h" | |
27 | #include "md_u.h" | |
28 | ||
29 | int Query(char *dev) | |
30 | { | |
31 | /* Give a brief description of the device, | |
aba69144 | 32 | * whether it is an md device and whether it has |
e0d19036 NB |
33 | * a superblock |
34 | */ | |
8d0cd09d JS |
35 | int fd; |
36 | int ioctlerr, staterr; | |
3d9d1880 | 37 | int superror; |
f22d6cde | 38 | int level, raid_disks, spare_disks; |
4b1ac34b | 39 | struct mdinfo info; |
f22d6cde | 40 | struct mdinfo *sra; |
82d9eba6 | 41 | struct supertype *st = NULL; |
e0d19036 | 42 | unsigned long long larray_size; |
e0d19036 NB |
43 | struct stat stb; |
44 | char *mddev; | |
45 | mdu_disk_info_t disc; | |
46 | char *activity; | |
47 | ||
8d0cd09d | 48 | fd = open(dev, O_RDONLY); |
e0d19036 | 49 | if (fd < 0){ |
8d0cd09d | 50 | pr_err("cannot open %s: %s\n", dev, strerror(errno)); |
e0d19036 NB |
51 | return 1; |
52 | } | |
53 | ||
8d0cd09d JS |
54 | if (fstat(fd, &stb) < 0) |
55 | staterr = errno; | |
56 | else | |
57 | staterr = 0; | |
e0d19036 | 58 | |
f22d6cde JS |
59 | ioctlerr = 0; |
60 | ||
61 | sra = sysfs_read(fd, dev, GET_DISKS | GET_LEVEL | GET_DEVS | GET_STATE); | |
62 | if (sra) { | |
63 | level = sra->array.level; | |
64 | raid_disks = sra->array.raid_disks; | |
65 | spare_disks = sra->array.spare_disks; | |
66 | } else { | |
3ab8f4bf JS |
67 | mdu_array_info_t array; |
68 | ||
f22d6cde JS |
69 | if (md_get_array_info(fd, &array) < 0) { |
70 | ioctlerr = errno; | |
0dfff0f2 JS |
71 | level = -1; |
72 | raid_disks = -1; | |
73 | spare_disks = -1; | |
f22d6cde JS |
74 | } else { |
75 | level = array.level; | |
76 | raid_disks = array.raid_disks; | |
77 | spare_disks = array.spare_disks; | |
78 | } | |
79 | } | |
80 | ||
8d0cd09d | 81 | if (!ioctlerr && !staterr) { |
beae1dfe NB |
82 | if (!get_dev_size(fd, NULL, &larray_size)) |
83 | larray_size = 0; | |
e0d19036 | 84 | } |
e0d19036 | 85 | |
5cb85996 | 86 | if (ioctlerr == ENODEV) |
e0d19036 NB |
87 | printf("%s: is an md device which is not active\n", dev); |
88 | else if (ioctlerr) | |
89 | printf("%s: is an md device, but gives \"%s\" when queried\n", | |
90 | dev, strerror(ioctlerr)); | |
8d0cd09d JS |
91 | else if (staterr) |
92 | printf("%s: is not a valid md device, returning %s\n", | |
93 | dev, strerror(ioctlerr)); | |
e0d19036 NB |
94 | else { |
95 | printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n", | |
f22d6cde JS |
96 | dev, human_size_brief(larray_size,IEC), |
97 | map_num(pers, level), raid_disks, | |
98 | spare_disks, spare_disks == 1 ? "" : "s"); | |
e0d19036 | 99 | } |
82d9eba6 | 100 | st = guess_super(fd); |
61a30986 | 101 | if (st && st->ss->compare_super != NULL) |
3da92f27 | 102 | superror = st->ss->load_super(st, fd, dev); |
3d9d1880 | 103 | else |
f9ce90ba | 104 | superror = -1; |
4b1ac34b NB |
105 | close(fd); |
106 | if (superror == 0) { | |
e0d19036 | 107 | /* array might be active... */ |
4610608a N |
108 | int uuid[4]; |
109 | struct map_ent *me, *map = NULL; | |
a5d85af7 | 110 | st->ss->getinfo_super(st, &info, NULL); |
4610608a N |
111 | st->ss->uuid_from_super(st, uuid); |
112 | me = map_by_uuid(&map, uuid); | |
113 | if (me) { | |
114 | mddev = me->path; | |
fbf8a0b7 NB |
115 | disc.number = info.disk.number; |
116 | activity = "undetected"; | |
117 | if (mddev && (fd = open(mddev, O_RDONLY))>=0) { | |
3ab8f4bf | 118 | if (md_array_active(fd)) { |
d97572f5 | 119 | if (md_get_disk_info(fd, &disc) >= 0 && |
fbf8a0b7 NB |
120 | makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev) |
121 | activity = "active"; | |
122 | else | |
123 | activity = "mismatch"; | |
124 | } | |
125 | close(fd); | |
e0d19036 | 126 | } |
fbf8a0b7 | 127 | } else { |
4610608a | 128 | activity = "inactive"; |
fbf8a0b7 | 129 | mddev = "array"; |
e0d19036 | 130 | } |
fbf8a0b7 | 131 | printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n", |
aba69144 | 132 | dev, |
4b1ac34b | 133 | info.disk.number, info.array.raid_disks, |
e0d19036 | 134 | activity, |
4b1ac34b | 135 | map_num(pers, info.array.level), |
fbf8a0b7 | 136 | mddev); |
b8ac1967 | 137 | if (st->ss == &super0) |
e7bb5d23 | 138 | put_md_name(mddev); |
e0d19036 NB |
139 | } |
140 | return 0; | |
141 | } |