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