~xnox/ubuntu/natty/mdadm/natty-updates

1 by Fabio M. Di Nitto
Import upstream version 1.5.0
1
/*
2
 * mdadm - manage Linux "md" devices aka RAID arrays.
3
 *
1.2.9 by martin f. krafft
Import upstream version 3.0
4
 * Copyright (C) 2002-2009 Neil Brown <neilb@suse.de>
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
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
1.2.9 by martin f. krafft
Import upstream version 3.0
22
 *    Email: <neilb@suse.de>
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
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,
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
32
	 * whether it is an md device and whether it has
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
33
	 * a superblock
34
	 */
1.2.7 by martin f. krafft
Import upstream version 2.6.8-12-gb47dff6
35
	int fd = open(dev, O_RDONLY);
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
36
	int vers;
37
	int ioctlerr;
38
	int superror, superrno;
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
39
	struct mdinfo info;
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
40
	mdu_array_info_t array;
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
41
	struct supertype *st = NULL;
42
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
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
		fprintf(stderr, Name ": cannot open %s: %s\n",
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;
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
59
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
60
	fstat(fd, &stb);
61
62
	if (vers>=9000 && !ioctlerr) {
1.2.1 by Scott James Remnant
Import upstream version 2.6.2
63
		if (!get_dev_size(fd, NULL, &larray_size))
64
			larray_size = 0;
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
65
	}
66
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
67
	if (vers < 0)
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
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,
79
		       human_size_brief(larray_size),
80
		       map_num(pers, array.level),
81
		       array.raid_disks,
82
		       array.spare_disks, array.spare_disks==1?"":"s");
83
	}
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
84
	st = guess_super(fd);
85
	if (st) {
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
86
		superror = st->ss->load_super(st, fd, dev);
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
87
		superrno = errno;
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
88
	} else
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
89
		superror = -1;
90
	close(fd);
91
	if (superror == 0) {
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
92
		/* array might be active... */
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
93
		st->ss->getinfo_super(st, &info);
1.2.9 by martin f. krafft
Import upstream version 3.0
94
		if (st->ss == &super0) {
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
95
			mddev = get_md_name(info.array.md_minor);
96
			disc.number = info.disk.number;
97
			activity = "undetected";
98
			if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
99
				if (md_get_version(fd) >= 9000 &&
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
100
				    ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
101
					if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
102
					    makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
103
						activity = "active";
104
					else
105
						activity = "mismatch";
106
				}
107
				close(fd);
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
108
			}
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
109
		} else {
110
			activity = "unknown";
111
			mddev = "array";
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
112
		}
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
113
		printf("%s: device %d in %d device %s %s %s.  Use mdadm --examine for more detail.\n",
1.2.4 by Luke Yelavich
Import upstream version 2.6.7
114
		       dev,
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
115
		       info.disk.number, info.array.raid_disks,
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
116
		       activity,
1.1.4 by Scott James Remnant
Import upstream version 2.4.1
117
		       map_num(pers, info.array.level),
118
		       mddev);
1.2.9 by martin f. krafft
Import upstream version 3.0
119
		if (st->ss == &super0)
1.1.5 by Fabio M. Di Nitto
Import upstream version 2.5.5
120
			put_md_name(mddev);
1 by Fabio M. Di Nitto
Import upstream version 1.5.0
121
	}
122
	return 0;
123
}
124