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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
/*
* 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"
/*
* change metadevice parameters
*/
#include <meta.h>
#include <sdssc.h>
/*
* print usage message
*/
static void
usage(
mdsetname_t *sp,
int eval
)
{
(void) fprintf(stderr, gettext("\
usage: %s [-s setname] [options] concat/stripe | RAID\n\
%s [-s setname] [options] mirror\n\
\n\
Concat/Stripe or RAID options:\n\
-h hotspare_pool | \"none\"\n\
\n\
Mirror options:\n\
-r roundrobin | geometric | first\n\
-w parallel | serial\n\
-p 0-%d\n"), myname, myname, MD_PASS_MAX);
md_exit(sp, eval);
}
/*
* do mirror parameters
*/
static int
mirror_params(
mdsetname_t *sp,
mdname_t *mirnp,
int argc,
char *argv[],
md_error_t *ep
)
{
mm_params_t mmp;
int modified = 0;
int c;
/* we must have a set */
assert(sp != NULL);
assert(sp->setno == MD_MIN2SET(meta_getminor(mirnp->dev)));
/* initialize */
(void) memset(&mmp, '\0', sizeof (mmp));
/* reset and parse args */
optind = 1;
opterr = 1;
while ((c = getopt(argc, argv, "s:r:w:p:")) != -1) {
switch (c) {
case 's':
break;
case 'r':
if (name_to_rd_opt(mirnp->cname, optarg,
&mmp.read_option, ep) != 0) {
return (-1);
}
mmp.change_read_option = 1;
modified = 1;
break;
case 'w':
if (name_to_wr_opt(mirnp->cname, optarg,
&mmp.write_option, ep) != 0) {
return (-1);
}
mmp.change_write_option = 1;
modified = 1;
break;
case 'p':
if (name_to_pass_num(mirnp->cname, optarg,
&mmp.pass_num, ep) != 0) {
return (-1);
}
mmp.change_pass_num = 1;
modified = 1;
break;
default:
usage(sp, 1);
/*NOTREACHED*/
break;
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage(sp, 1);
/* if just printing */
if (! modified) {
if (meta_mirror_get_params(sp, mirnp, &mmp, ep) != 0)
return (-1);
(void) printf(
gettext(
"%s: Mirror current parameters are:\n"),
mirnp->cname);
if (meta_print_mirror_options(mmp.read_option,
mmp.write_option, mmp.pass_num, 0, NULL,
sp, stdout, ep) != 0) {
return (-1);
}
}
/* otherwise, change parameters */
else {
if (meta_mirror_set_params(sp, mirnp, &mmp, ep) != 0)
return (-1);
/* update md.cf */
if (meta_update_md_cf(sp, ep) != 0)
return (-1);
}
/* return success */
return (0);
}
/*
* do stripe parameters
*/
static int
stripe_params(
mdsetname_t *sp,
mdname_t *stripenp,
int argc,
char *argv[],
md_error_t *ep
)
{
ms_params_t msp;
int modified = 0;
mdhspname_t *hspnp;
int c;
/* we must have a set */
assert(sp != NULL);
assert(sp->setno == MD_MIN2SET(meta_getminor(stripenp->dev)));
/* initialize */
(void) memset(&msp, '\0', sizeof (msp));
/* reset and parse args */
optind = 1;
opterr = 1;
while ((c = getopt(argc, argv, "s:h:")) != -1) {
switch (c) {
case 's':
break;
case 'h':
if (meta_is_none(optarg)) {
msp.hsp_id = MD_HSP_NONE;
} else if ((hspnp = metahspname(&sp, optarg,
ep)) == NULL) {
return (-1);
} else if (metachkhsp(sp, hspnp, ep) != 0) {
return (-1);
} else {
msp.hsp_id = hspnp->hsp;
}
msp.change_hsp_id = 1;
modified = 1;
break;
default:
usage(sp, 1);
/*NOTREACHED*/
break;
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage(sp, 1);
/* if just printing */
if (! modified) {
if (meta_stripe_get_params(sp, stripenp, &msp, ep) != 0)
return (-1);
if (msp.hsp_id == MD_HSP_NONE)
hspnp = NULL;
else if ((hspnp = metahsphspname(&sp, msp.hsp_id, ep)) == NULL)
return (-1);
(void) printf(gettext(
"%s: Concat/Stripe current parameters are:\n"),
stripenp->cname);
if (meta_print_stripe_options(hspnp, NULL, stdout, ep) != 0)
return (-1);
}
/* otherwise, change parameters */
else {
if (meta_stripe_set_params(sp, stripenp, &msp, ep) != 0)
return (-1);
/* update md.cf */
if (meta_update_md_cf(sp, ep) != 0)
return (-1);
}
/* return success */
return (0);
}
/*
* do raid parameters
*/
static int
raid_params(
mdsetname_t *sp,
mdname_t *raidnp,
int argc,
char *argv[],
md_error_t *ep
)
{
mr_params_t msp;
int modified = 0;
mdhspname_t *hspnp;
int c;
/* we must have a set */
assert(sp != NULL);
assert(sp->setno == MD_MIN2SET(meta_getminor(raidnp->dev)));
/* initialize */
(void) memset(&msp, '\0', sizeof (msp));
/* reset and parse args */
optind = 1;
opterr = 1;
while ((c = getopt(argc, argv, "s:h:")) != -1) {
switch (c) {
case 's':
break;
case 'h':
if (meta_is_none(optarg)) {
msp.hsp_id = MD_HSP_NONE;
} else if ((hspnp = metahspname(&sp, optarg,
ep)) == NULL) {
return (-1);
} else if (metachkhsp(sp, hspnp, ep) != 0) {
return (-1);
} else {
msp.hsp_id = hspnp->hsp;
}
msp.change_hsp_id = 1;
modified = 1;
break;
default:
usage(sp, 1);
/*NOTREACHED*/
break;
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage(sp, 1);
/* if just printing */
if (! modified) {
if (meta_raid_get_params(sp, raidnp, &msp, ep) != 0)
return (-1);
if (msp.hsp_id == MD_HSP_NONE)
hspnp = NULL;
else if ((hspnp = metahsphspname(&sp, msp.hsp_id, ep)) == NULL)
return (-1);
(void) printf(gettext(
"%s: RAID current parameters are:\n"),
raidnp->cname);
if (meta_print_raid_options(hspnp, NULL, stdout, ep) != 0)
return (-1);
}
/* otherwise, change parameters */
else {
if (meta_raid_set_params(sp, raidnp, &msp, ep) != 0)
return (-1);
/* update md.cf */
if (meta_update_md_cf(sp, ep) != 0)
return (-1);
}
/* return success */
return (0);
}
/*
* parse args and doit
*/
int
main(
int argc,
char **argv
)
{
char *sname = NULL;
mdsetname_t *sp = NULL;
mdname_t *np;
char *miscname;
int c;
md_error_t status = mdnullerror;
md_error_t *ep = &status;
int error;
bool_t called_thru_rpc = FALSE;
char *cp;
char *firstarg = NULL;
/*
* 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) {
mde_perror(ep, "");
md_exit(sp, 1);
}
/* find set and metadevice first */
optind = 1;
opterr = 1;
while ((c = getopt(argc, argv, "s:h:p:r:w:o:?")) != -1) {
switch (c) {
case 's':
sname = optarg;
break;
case 'h':
firstarg = optarg;
break;
case '?':
if (optopt == '?')
usage(sp, 0);
break;
}
}
if ((argc - optind) <= 0)
usage(sp, 1);
if (sname != NULL) {
if ((sp = metasetname(sname, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
}
if (firstarg == NULL)
firstarg = argv[optind];
if ((called_thru_rpc == FALSE) &&
meta_is_mn_name(&sp, firstarg, ep)) {
/*
* 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.
* Note that if sp is NULL, meta_is_mn_name() derives sp
* from firstarg which is the metadevice arg
* If this fails, the master must panic as the mddb may be
* inconsistent
*/
int result;
result = meta_mn_send_command(sp, argc, argv, MD_DISP_STDERR |
MD_PANIC_WHEN_INCONSISTENT, NO_CONTEXT_STRING, ep);
/* No further action required */
md_exit(sp, result);
}
if ((np = metaname(&sp, argv[optind], META_DEVICE, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
assert(sp != NULL);
/* grab set lock */
if (meta_lock(sp, TRUE, ep)) {
mde_perror(ep, "");
md_exit(sp, 1);
}
if (meta_check_ownership(sp, ep) != 0) {
mde_perror(ep, "");
md_exit(sp, 1);
}
if ((miscname = metagetmiscname(np, ep)) == NULL) {
mde_perror(ep, "");
md_exit(sp, 1);
}
/* dispatch based on device type */
if (strcmp(miscname, MD_STRIPE) == 0) {
if (stripe_params(sp, np, argc, argv, ep) != 0) {
mde_perror(ep, "");
md_exit(sp, 1);
}
} else if (strcmp(miscname, MD_MIRROR) == 0) {
if (mirror_params(sp, np, argc, argv, ep) != 0) {
mde_perror(ep, "");
md_exit(sp, 1);
}
} else if (strcmp(miscname, MD_RAID) == 0) {
if (raid_params(sp, np, argc, argv, ep) != 0) {
mde_perror(ep, "");
md_exit(sp, 1);
}
} else {
md_eprintf(gettext(
"%s: invalid metadevice type %s\n"),
np->cname, miscname);
md_exit(sp, 1);
}
/* return success */
md_exit(sp, 0);
/*NOTREACHED*/
return (0);
}
|