]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Query.c
Query: Remove all references to md_get_version()
[thirdparty/mdadm.git] / Query.c
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 = open(dev, O_RDONLY);
36 int ioctlerr;
37 int superror;
38 struct mdinfo info;
39 mdu_array_info_t array;
40 struct supertype *st = NULL;
41
42 unsigned long long larray_size;
43 struct stat stb;
44 char *mddev;
45 mdu_disk_info_t disc;
46 char *activity;
47
48 if (fd < 0){
49 pr_err("cannot open %s: %s\n",
50 dev, strerror(errno));
51 return 1;
52 }
53
54 if (md_get_array_info(fd, &array) < 0)
55 ioctlerr = errno;
56 else
57 ioctlerr = 0;
58
59 fstat(fd, &stb);
60
61 if (!ioctlerr) {
62 if (!get_dev_size(fd, NULL, &larray_size))
63 larray_size = 0;
64 }
65
66 if (ioctlerr == ENODEV)
67 printf("%s: is an md device which is not active\n", dev);
68 else if (ioctlerr)
69 printf("%s: is an md device, but gives \"%s\" when queried\n",
70 dev, strerror(ioctlerr));
71 else {
72 printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
73 dev,
74 human_size_brief(larray_size,IEC),
75 map_num(pers, array.level),
76 array.raid_disks,
77 array.spare_disks, array.spare_disks==1?"":"s");
78 }
79 st = guess_super(fd);
80 if (st && st->ss->compare_super != NULL)
81 superror = st->ss->load_super(st, fd, dev);
82 else
83 superror = -1;
84 close(fd);
85 if (superror == 0) {
86 /* array might be active... */
87 int uuid[4];
88 struct map_ent *me, *map = NULL;
89 st->ss->getinfo_super(st, &info, NULL);
90 st->ss->uuid_from_super(st, uuid);
91 me = map_by_uuid(&map, uuid);
92 if (me) {
93 mddev = me->path;
94 disc.number = info.disk.number;
95 activity = "undetected";
96 if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
97 if (md_get_array_info(fd, &array) >= 0) {
98 if (md_get_disk_info(fd, &disc) >= 0 &&
99 makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
100 activity = "active";
101 else
102 activity = "mismatch";
103 }
104 close(fd);
105 }
106 } else {
107 activity = "inactive";
108 mddev = "array";
109 }
110 printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n",
111 dev,
112 info.disk.number, info.array.raid_disks,
113 activity,
114 map_num(pers, info.array.level),
115 mddev);
116 if (st->ss == &super0)
117 put_md_name(mddev);
118 }
119 return 0;
120 }