]> git.ipfire.org Git - thirdparty/mdadm.git/blame - Query.c
tests/06name: adjust for homehost
[thirdparty/mdadm.git] / Query.c
CommitLineData
e0d19036
NB
1/*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4f589ad0 4 * Copyright (C) 2002-2006 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
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
34int Query(char *dev)
35{
36 /* Give a brief description of the device,
aba69144 37 * whether it is an md device and whether it has
e0d19036
NB
38 * a superblock
39 */
fb97b4d6 40 int fd = open(dev, O_RDONLY);
e0d19036
NB
41 int vers;
42 int ioctlerr;
43 int superror, superrno;
4b1ac34b 44 struct mdinfo info;
e0d19036 45 mdu_array_info_t array;
82d9eba6 46 struct supertype *st = NULL;
4b1ac34b 47
e0d19036 48 unsigned long long larray_size;
e0d19036
NB
49 struct stat stb;
50 char *mddev;
51 mdu_disk_info_t disc;
52 char *activity;
53
54 if (fd < 0){
55 fprintf(stderr, Name ": cannot open %s: %s\n",
56 dev, strerror(errno));
57 return 1;
58 }
59
60 vers = md_get_version(fd);
61 if (ioctl(fd, GET_ARRAY_INFO, &array)<0)
62 ioctlerr = errno;
63 else ioctlerr = 0;
aba69144 64
e0d19036
NB
65 fstat(fd, &stb);
66
67 if (vers>=9000 && !ioctlerr) {
beae1dfe
NB
68 if (!get_dev_size(fd, NULL, &larray_size))
69 larray_size = 0;
e0d19036 70 }
e0d19036 71
aba69144 72 if (vers < 0)
e0d19036
NB
73 printf("%s: is not an md array\n", dev);
74 else if (vers < 9000)
75 printf("%s: is an md device, but kernel cannot provide details\n", dev);
76 else if (ioctlerr == ENODEV)
77 printf("%s: is an md device which is not active\n", dev);
78 else if (ioctlerr)
79 printf("%s: is an md device, but gives \"%s\" when queried\n",
80 dev, strerror(ioctlerr));
81 else {
82 printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
83 dev,
84 human_size_brief(larray_size),
85 map_num(pers, array.level),
86 array.raid_disks,
87 array.spare_disks, array.spare_disks==1?"":"s");
88 }
82d9eba6
NB
89 st = guess_super(fd);
90 if (st) {
3da92f27 91 superror = st->ss->load_super(st, fd, dev);
f9ce90ba 92 superrno = errno;
aba69144 93 } else
f9ce90ba 94 superror = -1;
4b1ac34b
NB
95 close(fd);
96 if (superror == 0) {
e0d19036 97 /* array might be active... */
3da92f27 98 st->ss->getinfo_super(st, &info);
b8ac1967 99 if (st->ss == &super0) {
fbf8a0b7
NB
100 mddev = get_md_name(info.array.md_minor);
101 disc.number = info.disk.number;
102 activity = "undetected";
103 if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
aba69144 104 if (md_get_version(fd) >= 9000 &&
fbf8a0b7
NB
105 ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
106 if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
107 makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
108 activity = "active";
109 else
110 activity = "mismatch";
111 }
112 close(fd);
e0d19036 113 }
fbf8a0b7
NB
114 } else {
115 activity = "unknown";
116 mddev = "array";
e0d19036 117 }
fbf8a0b7 118 printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n",
aba69144 119 dev,
4b1ac34b 120 info.disk.number, info.array.raid_disks,
e0d19036 121 activity,
4b1ac34b 122 map_num(pers, info.array.level),
fbf8a0b7 123 mddev);
b8ac1967 124 if (st->ss == &super0)
e7bb5d23 125 put_md_name(mddev);
e0d19036
NB
126 }
127 return 0;
128}
129