1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* clear metadevices
*/
#include <meta.h>
#include <sdssc.h>
/*
* clear metadevice or hotspare pool
*/
static int
clear_name(
mdsetname_t **spp,
char *uname,
mdcmdopts_t options,
md_error_t *ep
)
{
/* clear hotspare pool */
if (is_existing_hsp(*spp, uname)) {
mdhspname_t *hspnp;
/* get hotspare pool name */
if ((hspnp = metahspname(spp, uname, ep)) == NULL)
return (-1);
assert(*spp != NULL);
/* grab set lock */
if (meta_lock(*spp, TRUE, ep))
return (-1);
/* check for ownership */
if (meta_check_ownership(*spp, ep) != 0)
return (-1);
/* clear hotspare pool */
return (meta_hsp_reset(*spp, hspnp, options, ep));
}
/* clear metadevice */
else {
mdname_t *np;
/* check for ownership */
if (meta_check_ownership(*spp, ep) != 0)
return (-1);
/* get metadevice name */
if (((np = metaname(spp, uname, META_DEVICE, ep)) == NULL) ||
(metachkmeta(np, ep) != 0)) {
return (-1);
}
assert(*spp != NULL);
/* grab set lock */
if (meta_lock(*spp, TRUE, ep))
return (-1);
/* clear metadevice */
return (meta_reset_by_name(*spp, np, options, ep));
}
}
/*
* print usage message
*/
static void
usage(
mdsetname_t *sp,
int eval
)
{
(void) fprintf(stderr, gettext("\
usage: %s [-s setname] -a\n\
%s [-s setname] [options] metadevice...\n\
options:\n\
-f force clear\n\
-r recursive clear\n\
-p clear all soft partitions on metadevice/component\n"), myname, myname);
md_exit(sp, eval);
}
/*
* mainline. crack command line arguments.
*/
int
main(
int argc,
char *argv[]
)
{
char *sname = MD_LOCAL_NAME;
mdsetname_t *sp = NULL;
int aflag = 0;
int pflag = 0;
int set_flag = 0;
mdcmdopts_t options = (MDCMD_PRINT|MDCMD_DOIT);
int c;
md_error_t status = mdnullerror;
md_error_t *ep = &status;
int eval = 1;
int error;
bool_t called_thru_rpc = FALSE;
char *cp;
int mnset = FALSE;
/*
* Get the locale set up before calling any other routines
* with messages to ouput. Just in case we're not in a build
* environment, make sure that TEXT_DOMAIN gets set to
* something.
*/
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) setlocale(LC_ALL, "");
(void) textdomain(TEXT_DOMAIN);
if ((cp = strstr(argv[0], ".rpc_call")) == NULL) {
if (sdssc_bind_library() == SDSSC_OKAY)
if (sdssc_cmd_proxy(argc, argv, SDSSC_PROXY_PRIMARY,
&error) == SDSSC_PROXY_DONE)
exit(error);
} else {
*cp = '\0'; /* cut off ".rpc_call" */
called_thru_rpc = TRUE;
}
/* initialize */
if (md_init(argc, argv, 0, 1, ep) != 0 ||
meta_check_root(ep) != 0)
goto errout;
/* parse args */
optind = 1;
opterr = 1;
while ((c = getopt(argc, argv, "hs:afrp?")) != -1) {
switch (c) {
case 'h':
usage(sp, 0);
break;
case 's':
sname = optarg;
set_flag++;
break;
case 'a':
++aflag;
options |= MDCMD_FORCE;
break;
case 'f':
options |= MDCMD_FORCE;
break;
case 'r':
options |= MDCMD_RECURSE | MDCMD_FORCE;
break;
case 'p':
++pflag;
break;
case '?':
if (optopt == '?')
usage(sp, 0);
/*FALLTHROUGH*/
default:
usage(sp, 1);
break;
}
}
argc -= optind;
argv += optind;
/* with mn sets if -a, set name must have been specified by -s */
if (called_thru_rpc && aflag && !set_flag) {
md_eprintf(gettext(
"-a parameter requires the use of -s in multi-node sets"));
md_exit(sp, 1);
}
/* get set context */
if ((sp = metasetname(sname, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
if (called_thru_rpc) {
/* Check if the device is open on all nodes */
options |= MDCMD_MN_OPEN_CHECK;
}
if (aflag) { /* clear all devices */
if (argc != 0)
usage(sp, 1);
/*
* If a MN set, we will generate a series of individual
* metaclear commands which will each grab the set lock.
* Therefore do not grab the set lock now.
*/
if (!meta_is_mn_set(sp, ep)) {
/* grab set lock */
if (meta_lock(sp, TRUE, ep))
goto errout;
/* check for ownership */
if (meta_check_ownership(sp, ep) != 0)
goto errout;
} else {
mnset = TRUE;
}
/* reset all devices in set */
if (meta_reset_all(sp, options, ep) != 0) {
if (!mnset)
mde_perror(ep, "");
} else
eval = 0;
} else {
/*
* We are dealing with either a single or multiple names.
* The set for the command is either denoted by the -s option
* or the set of the first name.
*/
if (argc <= 0)
usage(sp, 1);
if (meta_is_mn_name(&sp, argv[0], ep))
mnset = TRUE;
eval = 0;
for (; (argc > 0); --argc, ++argv) {
char *cname;
/*
* If we are dealing with a MN set and we were not
* called thru an rpc call, we are just to send this
* command string to the master of the set and let it
* deal with it.
*/
if (!called_thru_rpc && mnset) {
/* get the canonical name */
if (pflag) {
/*
* If -p, set cname to the device
* argument.
*/
cname = Strdup(argv[0]);
} else {
/*
* For hotspares and metadevices, set
* cname to the full name,
* setname/hspxxx or setname/dxxx
*/
cname = meta_name_getname(&sp,
argv[0], META_DEVICE, ep);
if (cname == NULL) {
mde_perror(ep, "");
eval = 1;
continue;
}
}
if (meta_mn_send_metaclear_command(sp,
cname, options, pflag, ep) != 0) {
eval = 1;
}
Free(cname);
} else {
if (pflag) {
/*
* clear all soft partitions on named
* devices
*/
if (meta_sp_reset_component(sp, argv[0],
options, ep) != 0) {
mde_perror(ep, "");
eval = 1;
continue;
}
} else {
/*
* get the canonical name and
* setup sp if it has been
* specified as part of the
* metadevice/hsp name param
*/
cname = meta_name_getname(&sp,
argv[0], META_DEVICE, ep);
if (cname == NULL) {
mde_perror(ep, "");
eval = 1;
continue;
}
/* clear named devices */
if (clear_name(&sp, cname,
options, ep) != 0) {
mde_perror(ep, "");
eval = 1;
Free(cname);
continue;
}
Free(cname);
}
}
}
}
/* update md.cf */
if (meta_update_md_cf(sp, ep) != 0) {
mde_perror(ep, "");
eval = 1;
}
md_exit(sp, eval);
errout:
mde_perror(ep, "");
md_exit(sp, eval);
/*NOTREACHED*/
return (eval);
}
|