]>
Commit | Line | Data |
---|---|---|
e0d19036 NB |
1 | /* |
2 | * mdadm - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4 | * Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au> | |
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 | ||
30 | #include "mdadm.h" | |
31 | #include "md_p.h" | |
32 | #include "md_u.h" | |
33 | ||
34 | int Query(char *dev) | |
35 | { | |
36 | /* Give a brief description of the device, | |
37 | * whether it is an md device and whether it has | |
38 | * a superblock | |
39 | */ | |
40 | int fd = open(dev, O_RDONLY, 0); | |
41 | int vers; | |
42 | int ioctlerr; | |
43 | int superror, superrno; | |
4b1ac34b | 44 | struct mdinfo info; |
947fd4dd | 45 | struct mddev_ident_s ident; |
e0d19036 | 46 | mdu_array_info_t array; |
4b1ac34b | 47 | void *super; |
82d9eba6 | 48 | struct supertype *st = NULL; |
4b1ac34b | 49 | |
e0d19036 NB |
50 | unsigned long long larray_size; |
51 | unsigned long array_size; | |
52 | struct stat stb; | |
53 | char *mddev; | |
54 | mdu_disk_info_t disc; | |
55 | char *activity; | |
56 | ||
57 | if (fd < 0){ | |
58 | fprintf(stderr, Name ": cannot open %s: %s\n", | |
59 | dev, strerror(errno)); | |
60 | return 1; | |
61 | } | |
62 | ||
63 | vers = md_get_version(fd); | |
64 | if (ioctl(fd, GET_ARRAY_INFO, &array)<0) | |
65 | ioctlerr = errno; | |
66 | else ioctlerr = 0; | |
e0d19036 NB |
67 | |
68 | fstat(fd, &stb); | |
69 | ||
70 | if (vers>=9000 && !ioctlerr) { | |
71 | #ifdef BLKGETSIZE64 | |
72 | if (ioctl(fd, BLKGETSIZE64, &larray_size)==0) | |
73 | ; | |
74 | else | |
75 | #endif | |
b83d95f3 NB |
76 | if (ioctl(fd, BLKGETSIZE, &array_size)==0) { |
77 | larray_size = array_size; | |
78 | larray_size <<= 9; | |
79 | } else larray_size = 0; | |
e0d19036 | 80 | } |
e0d19036 NB |
81 | |
82 | if (vers < 0) | |
83 | printf("%s: is not an md array\n", dev); | |
84 | else if (vers < 9000) | |
85 | printf("%s: is an md device, but kernel cannot provide details\n", dev); | |
86 | else if (ioctlerr == ENODEV) | |
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)); | |
91 | else { | |
92 | printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n", | |
93 | dev, | |
94 | human_size_brief(larray_size), | |
95 | map_num(pers, array.level), | |
96 | array.raid_disks, | |
97 | array.spare_disks, array.spare_disks==1?"":"s"); | |
98 | } | |
82d9eba6 NB |
99 | st = guess_super(fd); |
100 | if (st) { | |
101 | superror = st->ss->load_super(st, fd, &super, dev); | |
f9ce90ba NB |
102 | superrno = errno; |
103 | } else | |
104 | superror = -1; | |
4b1ac34b NB |
105 | close(fd); |
106 | if (superror == 0) { | |
e0d19036 | 107 | /* array might be active... */ |
947fd4dd | 108 | st->ss->getinfo_super(&info, &ident, super); |
fbf8a0b7 NB |
109 | if (st->ss->major == 0) { |
110 | mddev = get_md_name(info.array.md_minor); | |
111 | disc.number = info.disk.number; | |
112 | activity = "undetected"; | |
113 | if (mddev && (fd = open(mddev, O_RDONLY))>=0) { | |
114 | if (md_get_version(fd) >= 9000 && | |
115 | ioctl(fd, GET_ARRAY_INFO, &array)>= 0) { | |
116 | if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 && | |
117 | makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev) | |
118 | activity = "active"; | |
119 | else | |
120 | activity = "mismatch"; | |
121 | } | |
122 | close(fd); | |
e0d19036 | 123 | } |
fbf8a0b7 NB |
124 | } else { |
125 | activity = "unknown"; | |
126 | mddev = "array"; | |
e0d19036 | 127 | } |
fbf8a0b7 | 128 | printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n", |
e0d19036 | 129 | dev, |
4b1ac34b | 130 | info.disk.number, info.array.raid_disks, |
e0d19036 | 131 | activity, |
4b1ac34b | 132 | map_num(pers, info.array.level), |
fbf8a0b7 | 133 | mddev); |
e0d19036 NB |
134 | } |
135 | return 0; | |
136 | } | |
137 | ||
138 |