]>
Commit | Line | Data |
---|---|---|
64c4757e NB |
1 | /* |
2 | * mdctl - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4 | * Copyright (C) 2001 Neil Brown <neilb@cse.unsw.edu.au> | |
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 "mdctl.h" | |
31 | #include "md_p.h" | |
32 | #include "md_u.h" | |
33 | ||
34 | int Detail(char *dev) | |
35 | { | |
36 | /* | |
37 | * Print out details for an md array by using | |
38 | * GET_ARRAY_INFO and GET_DISK_INFO ioctl calls | |
39 | */ | |
40 | ||
41 | int fd = open(dev, O_RDONLY, 0); | |
42 | int vers; | |
43 | mdu_array_info_t array; | |
44 | int d; | |
45 | time_t atime; | |
46 | ||
47 | if (fd < 0) { | |
48 | fprintf(stderr, "mdctl: cannot open %s: %s\n", | |
49 | dev, strerror(errno)); | |
50 | return 1; | |
51 | } | |
52 | vers = md_get_version(fd); | |
53 | if (vers < 0) { | |
54 | fprintf(stderr, "mdctl: %s does not appear to be an md device\n", | |
55 | dev); | |
56 | close(fd); | |
57 | return 1; | |
58 | } | |
59 | if (vers < (90<<8)) { | |
60 | fprintf(stderr, "mdctl: cannot get detail for md device %s: driver version too old.\n", | |
61 | dev); | |
62 | close(fd); | |
63 | return 1; | |
64 | } | |
65 | if (ioctl(fd, GET_ARRAY_INFO, &array)<0) { | |
66 | if (errno == ENODEV) | |
67 | fprintf(stderr, "mdctl: md device %s does not appear to be active.\n", | |
68 | dev); | |
69 | else | |
70 | fprintf(stderr, "mdctl: cannot get array detail for %s: %s\n", | |
71 | dev, strerror(errno)); | |
72 | close(fd); | |
73 | return 1; | |
74 | } | |
75 | /* Ok, we have some info to print... */ | |
76 | printf("%s:\n", dev); | |
77 | printf(" Version : %02d.%02d.%02d\n", | |
78 | array.major_version, array.minor_version, array.patch_version); | |
79 | atime = array.ctime; | |
80 | printf(" Creation Time : %.24s\n", ctime(&atime)); | |
81 | printf(" Raid Level : %d\n", array.level); | |
82 | printf(" Size : %d\n", array.size); | |
83 | printf(" Raid Disks : %d\n", array.raid_disks); | |
84 | printf(" Total Disks : %d\n", array.nr_disks); | |
85 | printf("Preferred Minor : %d\n", array.md_minor); | |
86 | printf(" Persistance : Superblock is %spersistant\n", | |
87 | array.not_persistent?"not ":""); | |
88 | printf("\n"); | |
89 | atime = array.utime; | |
90 | printf(" Update Time : %.24s\n", ctime(&atime)); | |
91 | printf(" State : %s, %serrors\n", | |
92 | (array.state&(1<<MD_SB_CLEAN))?"clean":"dirty", | |
93 | (array.state&(1<<MD_SB_ERRORS))?"":"no-"); | |
94 | printf(" Active Drives : %d\n", array.active_disks); | |
95 | printf(" Working Drives : %d\n", array.working_disks); | |
96 | printf(" Failed Drives : %d\n", array.failed_disks); | |
97 | printf(" Spare Drives : %d\n", array.spare_disks); | |
98 | printf("\n"); | |
99 | printf(" Layout : %d\n", array.layout); | |
100 | printf(" Chunk Size : %dK\n", array.chunk_size/1024); | |
101 | printf("\n"); | |
102 | printf(" Number Major Minor RaidDisk State\n"); | |
103 | for (d= 0; d<array.nr_disks; d++) { | |
104 | mdu_disk_info_t disk; | |
105 | disk.number = d; | |
106 | if (ioctl(fd, GET_DISK_INFO, &disk) < 0) { | |
107 | fprintf(stderr, "mdctl: cannot get disk detail for disk %d: %s\n", | |
108 | d, strerror(errno)); | |
109 | continue; | |
110 | } | |
111 | printf(" %5d %5d %5d %5d ", | |
112 | disk.number, disk.major, disk.minor, disk.raid_disk); | |
113 | if (disk.state & (1<<MD_DISK_FAULTY)) printf(" faulty"); | |
114 | if (disk.state & (1<<MD_DISK_ACTIVE)) printf(" active"); | |
115 | if (disk.state & (1<<MD_DISK_SYNC)) printf(" sync"); | |
116 | if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed"); | |
117 | printf("\n"); | |
118 | } | |
119 | return 0; | |
120 | } |