]>
Commit | Line | Data |
---|---|---|
32367cb5 N |
1 | /* |
2 | * mdadm - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4 | * Copyright (C) 2011 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 | ||
32367cb5 N |
27 | /* name/number mappings */ |
28 | ||
29 | mapping_t r5layout[] = { | |
30 | { "left-asymmetric", ALGORITHM_LEFT_ASYMMETRIC}, | |
31 | { "right-asymmetric", ALGORITHM_RIGHT_ASYMMETRIC}, | |
32 | { "left-symmetric", ALGORITHM_LEFT_SYMMETRIC}, | |
33 | { "right-symmetric", ALGORITHM_RIGHT_SYMMETRIC}, | |
34 | ||
35 | { "default", ALGORITHM_LEFT_SYMMETRIC}, | |
36 | { "la", ALGORITHM_LEFT_ASYMMETRIC}, | |
37 | { "ra", ALGORITHM_RIGHT_ASYMMETRIC}, | |
38 | { "ls", ALGORITHM_LEFT_SYMMETRIC}, | |
39 | { "rs", ALGORITHM_RIGHT_SYMMETRIC}, | |
40 | ||
41 | { "parity-first", ALGORITHM_PARITY_0}, | |
42 | { "parity-last", ALGORITHM_PARITY_N}, | |
43 | { "ddf-zero-restart", ALGORITHM_RIGHT_ASYMMETRIC}, | |
44 | { "ddf-N-restart", ALGORITHM_LEFT_ASYMMETRIC}, | |
45 | { "ddf-N-continue", ALGORITHM_LEFT_SYMMETRIC}, | |
46 | ||
5e8e35fb | 47 | { NULL, UnSet } |
32367cb5 N |
48 | }; |
49 | mapping_t r6layout[] = { | |
50 | { "left-asymmetric", ALGORITHM_LEFT_ASYMMETRIC}, | |
51 | { "right-asymmetric", ALGORITHM_RIGHT_ASYMMETRIC}, | |
52 | { "left-symmetric", ALGORITHM_LEFT_SYMMETRIC}, | |
53 | { "right-symmetric", ALGORITHM_RIGHT_SYMMETRIC}, | |
54 | ||
55 | { "default", ALGORITHM_LEFT_SYMMETRIC}, | |
56 | { "la", ALGORITHM_LEFT_ASYMMETRIC}, | |
57 | { "ra", ALGORITHM_RIGHT_ASYMMETRIC}, | |
58 | { "ls", ALGORITHM_LEFT_SYMMETRIC}, | |
59 | { "rs", ALGORITHM_RIGHT_SYMMETRIC}, | |
60 | ||
61 | { "parity-first", ALGORITHM_PARITY_0}, | |
62 | { "parity-last", ALGORITHM_PARITY_N}, | |
63 | { "ddf-zero-restart", ALGORITHM_ROTATING_ZERO_RESTART}, | |
64 | { "ddf-N-restart", ALGORITHM_ROTATING_N_RESTART}, | |
65 | { "ddf-N-continue", ALGORITHM_ROTATING_N_CONTINUE}, | |
66 | ||
67 | { "left-asymmetric-6", ALGORITHM_LEFT_ASYMMETRIC_6}, | |
68 | { "right-asymmetric-6", ALGORITHM_RIGHT_ASYMMETRIC_6}, | |
69 | { "left-symmetric-6", ALGORITHM_LEFT_SYMMETRIC_6}, | |
70 | { "right-symmetric-6", ALGORITHM_RIGHT_SYMMETRIC_6}, | |
71 | { "parity-first-6", ALGORITHM_PARITY_0_6}, | |
72 | ||
5e8e35fb | 73 | { NULL, UnSet } |
32367cb5 N |
74 | }; |
75 | ||
329dfc28 N |
76 | /* raid0 layout is only needed because of a bug in 3.14 which changed |
77 | * the effective layout of raid0 arrays with varying device sizes. | |
78 | */ | |
79 | mapping_t r0layout[] = { | |
80 | { "original", RAID0_ORIG_LAYOUT}, | |
81 | { "alternate", RAID0_ALT_MULTIZONE_LAYOUT}, | |
82 | { "1", 1}, /* aka ORIG */ | |
83 | { "2", 2}, /* aka ALT */ | |
84 | { "dangerous", 0}, | |
85 | { NULL, UnSet}, | |
86 | }; | |
87 | ||
32367cb5 N |
88 | mapping_t pers[] = { |
89 | { "linear", LEVEL_LINEAR}, | |
90 | { "raid0", 0}, | |
91 | { "0", 0}, | |
92 | { "stripe", 0}, | |
93 | { "raid1", 1}, | |
94 | { "1", 1}, | |
95 | { "mirror", 1}, | |
96 | { "raid4", 4}, | |
97 | { "4", 4}, | |
98 | { "raid5", 5}, | |
99 | { "5", 5}, | |
100 | { "multipath", LEVEL_MULTIPATH}, | |
101 | { "mp", LEVEL_MULTIPATH}, | |
102 | { "raid6", 6}, | |
103 | { "6", 6}, | |
104 | { "raid10", 10}, | |
105 | { "10", 10}, | |
106 | { "faulty", LEVEL_FAULTY}, | |
107 | { "container", LEVEL_CONTAINER}, | |
5e8e35fb | 108 | { NULL, UnSet } |
32367cb5 N |
109 | }; |
110 | ||
32367cb5 N |
111 | mapping_t modes[] = { |
112 | { "assemble", ASSEMBLE}, | |
113 | { "build", BUILD}, | |
114 | { "create", CREATE}, | |
115 | { "manage", MANAGE}, | |
116 | { "misc", MISC}, | |
117 | { "monitor", MONITOR}, | |
118 | { "grow", GROW}, | |
119 | { "incremental", INCREMENTAL}, | |
120 | { "auto-detect", AUTODETECT}, | |
5e8e35fb | 121 | { NULL, UnSet } |
32367cb5 N |
122 | }; |
123 | ||
124 | mapping_t faultylayout[] = { | |
125 | { "write-transient", WriteTransient }, | |
126 | { "wt", WriteTransient }, | |
127 | { "read-transient", ReadTransient }, | |
128 | { "rt", ReadTransient }, | |
129 | { "write-persistent", WritePersistent }, | |
130 | { "wp", WritePersistent }, | |
131 | { "read-persistent", ReadPersistent }, | |
132 | { "rp", ReadPersistent }, | |
133 | { "write-all", WriteAll }, | |
134 | { "wa", WriteAll }, | |
135 | { "read-fixable", ReadFixable }, | |
136 | { "rf", ReadFixable }, | |
137 | ||
138 | { "clear", ClearErrors}, | |
139 | { "flush", ClearFaults}, | |
140 | { "none", ClearErrors}, | |
141 | { "default", ClearErrors}, | |
5e8e35fb | 142 | { NULL, UnSet } |
32367cb5 N |
143 | }; |
144 | ||
5308f117 AP |
145 | mapping_t consistency_policies[] = { |
146 | { "unknown", CONSISTENCY_POLICY_UNKNOWN}, | |
147 | { "none", CONSISTENCY_POLICY_NONE}, | |
148 | { "resync", CONSISTENCY_POLICY_RESYNC}, | |
149 | { "bitmap", CONSISTENCY_POLICY_BITMAP}, | |
150 | { "journal", CONSISTENCY_POLICY_JOURNAL}, | |
151 | { "ppl", CONSISTENCY_POLICY_PPL}, | |
b7580566 | 152 | { NULL, CONSISTENCY_POLICY_UNKNOWN } |
5308f117 AP |
153 | }; |
154 | ||
5e4ca8bb | 155 | mapping_t sysfs_array_states[] = { |
5e4ca8bb JS |
156 | { "active-idle", ARRAY_ACTIVE_IDLE }, |
157 | { "active", ARRAY_ACTIVE }, | |
158 | { "clear", ARRAY_CLEAR }, | |
159 | { "inactive", ARRAY_INACTIVE }, | |
160 | { "suspended", ARRAY_SUSPENDED }, | |
161 | { "readonly", ARRAY_READONLY }, | |
162 | { "read-auto", ARRAY_READ_AUTO }, | |
163 | { "clean", ARRAY_CLEAN }, | |
164 | { "write-pending", ARRAY_WRITE_PENDING }, | |
43ebc910 | 165 | { "broken", ARRAY_BROKEN }, |
5e8e35fb | 166 | { NULL, ARRAY_UNKNOWN_STATE } |
5e4ca8bb JS |
167 | }; |
168 | ||
5f21d674 MT |
169 | /** |
170 | * map_num_s() - Safer alternative of map_num() function. | |
171 | * @map: map to search. | |
172 | * @num: key to match. | |
173 | * | |
174 | * Shall be used only if key existence is quaranted. | |
175 | * | |
176 | * Return: Pointer to name of the element. | |
177 | */ | |
178 | char *map_num_s(mapping_t *map, int num) | |
179 | { | |
180 | char *ret = map_num(map, num); | |
181 | ||
182 | assert(ret); | |
183 | return ret; | |
184 | } | |
185 | ||
186 | /** | |
187 | * map_num() - get element name by key. | |
188 | * @map: map to search. | |
189 | * @num: key to match. | |
190 | * | |
191 | * Return: Pointer to name of the element or NULL. | |
192 | */ | |
32367cb5 N |
193 | char *map_num(mapping_t *map, int num) |
194 | { | |
195 | while (map->name) { | |
196 | if (map->num == num) | |
197 | return map->name; | |
198 | map++; | |
199 | } | |
200 | return NULL; | |
201 | } | |
202 | ||
203 | int map_name(mapping_t *map, char *name) | |
204 | { | |
4a4379b0 | 205 | while (map->name && strcmp(map->name, name) != 0) |
32367cb5 | 206 | map++; |
5e8e35fb JS |
207 | |
208 | return map->num; | |
32367cb5 | 209 | } |