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