]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * mdadm - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4 | * Copyright (C) 2002-2009 Neil Brown <neilb@suse.de> | |
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@suse.de> | |
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, | |
32 | * whether it is an md device and whether it has | |
33 | * a superblock | |
34 | */ | |
35 | int fd; | |
36 | int ioctlerr, staterr; | |
37 | int superror; | |
38 | int level, raid_disks, spare_disks; | |
39 | struct mdinfo info; | |
40 | struct mdinfo *sra; | |
41 | struct supertype *st = NULL; | |
42 | unsigned long long larray_size; | |
43 | struct stat stb; | |
44 | char *mddev; | |
45 | mdu_disk_info_t disc; | |
46 | char *activity; | |
47 | ||
48 | fd = open(dev, O_RDONLY); | |
49 | if (fd < 0){ | |
50 | pr_err("cannot open %s: %s\n", dev, strerror(errno)); | |
51 | return 1; | |
52 | } | |
53 | ||
54 | if (fstat(fd, &stb) < 0) | |
55 | staterr = errno; | |
56 | else | |
57 | staterr = 0; | |
58 | ||
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 { | |
67 | mdu_array_info_t array; | |
68 | ||
69 | if (md_get_array_info(fd, &array) < 0) { | |
70 | ioctlerr = errno; | |
71 | level = -1; | |
72 | raid_disks = -1; | |
73 | spare_disks = -1; | |
74 | } else { | |
75 | level = array.level; | |
76 | raid_disks = array.raid_disks; | |
77 | spare_disks = array.spare_disks; | |
78 | } | |
79 | } | |
80 | ||
81 | if (!ioctlerr && !staterr) { | |
82 | if (!get_dev_size(fd, NULL, &larray_size)) | |
83 | larray_size = 0; | |
84 | } | |
85 | ||
86 | if (ioctlerr == ENODEV) | |
87 | printf("%s: is an md device which is not active\n", dev); | |
88 | else if (ioctlerr && major(stb.st_rdev) != MD_MAJOR) | |
89 | printf("%s: is not an md array\n", dev); | |
90 | else if (ioctlerr) | |
91 | printf("%s: is an md device, but gives \"%s\" when queried\n", | |
92 | dev, strerror(ioctlerr)); | |
93 | else { | |
94 | printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n", | |
95 | dev, human_size_brief(larray_size,IEC), | |
96 | map_num_s(pers, level), raid_disks, | |
97 | spare_disks, spare_disks == 1 ? "" : "s"); | |
98 | } | |
99 | st = guess_super(fd); | |
100 | if (st && st->ss->compare_super != NULL) | |
101 | superror = st->ss->load_super(st, fd, dev); | |
102 | else | |
103 | superror = -1; | |
104 | close(fd); | |
105 | if (superror == 0) { | |
106 | /* array might be active... */ | |
107 | int uuid[4]; | |
108 | struct map_ent *me, *map = NULL; | |
109 | st->ss->getinfo_super(st, &info, NULL); | |
110 | st->ss->uuid_from_super(st, uuid); | |
111 | me = map_by_uuid(&map, uuid); | |
112 | if (me) { | |
113 | mddev = me->path; | |
114 | disc.number = info.disk.number; | |
115 | activity = "undetected"; | |
116 | if (mddev && (fd = open(mddev, O_RDONLY))>=0) { | |
117 | if (md_array_active(fd)) { | |
118 | if (md_get_disk_info(fd, &disc) >= 0 && | |
119 | makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev) | |
120 | activity = "active"; | |
121 | else | |
122 | activity = "mismatch"; | |
123 | } | |
124 | close(fd); | |
125 | } | |
126 | } else { | |
127 | activity = "inactive"; | |
128 | mddev = "array"; | |
129 | } | |
130 | printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n", | |
131 | dev, | |
132 | info.disk.number, info.array.raid_disks, | |
133 | activity, | |
134 | map_num_s(pers, info.array.level), | |
135 | mddev); | |
136 | if (st->ss == &super0) | |
137 | put_md_name(mddev); | |
138 | } | |
139 | return 0; | |
140 | } |