4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * change metadevice parameters
45 (void) fprintf(stderr
, gettext("\
46 usage: %s [-s setname] [options] concat/stripe | RAID\n\
47 %s [-s setname] [options] mirror\n\
49 Concat/Stripe or RAID options:\n\
50 -h hotspare_pool | \"none\"\n\
53 -r roundrobin | geometric | first\n\
54 -w parallel | serial\n\
55 -p 0-%d\n"), myname
, myname
, MD_PASS_MAX
);
61 * do mirror parameters
76 /* we must have a set */
78 assert(sp
->setno
== MD_MIN2SET(meta_getminor(mirnp
->dev
)));
81 (void) memset(&mmp
, '\0', sizeof (mmp
));
83 /* reset and parse args */
86 while ((c
= getopt(argc
, argv
, "s:r:w:p:")) != -1) {
92 if (name_to_rd_opt(mirnp
->cname
, optarg
,
93 &mmp
.read_option
, ep
) != 0) {
96 mmp
.change_read_option
= 1;
101 if (name_to_wr_opt(mirnp
->cname
, optarg
,
102 &mmp
.write_option
, ep
) != 0) {
105 mmp
.change_write_option
= 1;
110 if (name_to_pass_num(mirnp
->cname
, optarg
,
111 &mmp
.pass_num
, ep
) != 0) {
114 mmp
.change_pass_num
= 1;
130 /* if just printing */
132 if (meta_mirror_get_params(sp
, mirnp
, &mmp
, ep
) != 0)
136 "%s: Mirror current parameters are:\n"),
138 if (meta_print_mirror_options(mmp
.read_option
,
139 mmp
.write_option
, mmp
.pass_num
, 0, NULL
,
140 sp
, stdout
, ep
) != 0) {
145 /* otherwise, change parameters */
147 if (meta_mirror_set_params(sp
, mirnp
, &mmp
, ep
) != 0)
151 if (meta_update_md_cf(sp
, ep
) != 0)
160 * do stripe parameters
176 /* we must have a set */
178 assert(sp
->setno
== MD_MIN2SET(meta_getminor(stripenp
->dev
)));
181 (void) memset(&msp
, '\0', sizeof (msp
));
183 /* reset and parse args */
186 while ((c
= getopt(argc
, argv
, "s:h:")) != -1) {
192 if (meta_is_none(optarg
)) {
193 msp
.hsp_id
= MD_HSP_NONE
;
194 } else if ((hspnp
= metahspname(&sp
, optarg
,
197 } else if (metachkhsp(sp
, hspnp
, ep
) != 0) {
200 msp
.hsp_id
= hspnp
->hsp
;
202 msp
.change_hsp_id
= 1;
217 /* if just printing */
219 if (meta_stripe_get_params(sp
, stripenp
, &msp
, ep
) != 0)
221 if (msp
.hsp_id
== MD_HSP_NONE
)
223 else if ((hspnp
= metahsphspname(&sp
, msp
.hsp_id
, ep
)) == NULL
)
225 (void) printf(gettext(
226 "%s: Concat/Stripe current parameters are:\n"),
228 if (meta_print_stripe_options(hspnp
, NULL
, stdout
, ep
) != 0)
232 /* otherwise, change parameters */
234 if (meta_stripe_set_params(sp
, stripenp
, &msp
, ep
) != 0)
238 if (meta_update_md_cf(sp
, ep
) != 0)
263 /* we must have a set */
265 assert(sp
->setno
== MD_MIN2SET(meta_getminor(raidnp
->dev
)));
268 (void) memset(&msp
, '\0', sizeof (msp
));
270 /* reset and parse args */
273 while ((c
= getopt(argc
, argv
, "s:h:")) != -1) {
279 if (meta_is_none(optarg
)) {
280 msp
.hsp_id
= MD_HSP_NONE
;
281 } else if ((hspnp
= metahspname(&sp
, optarg
,
284 } else if (metachkhsp(sp
, hspnp
, ep
) != 0) {
287 msp
.hsp_id
= hspnp
->hsp
;
289 msp
.change_hsp_id
= 1;
304 /* if just printing */
306 if (meta_raid_get_params(sp
, raidnp
, &msp
, ep
) != 0)
308 if (msp
.hsp_id
== MD_HSP_NONE
)
310 else if ((hspnp
= metahsphspname(&sp
, msp
.hsp_id
, ep
)) == NULL
)
312 (void) printf(gettext(
313 "%s: RAID current parameters are:\n"),
315 if (meta_print_raid_options(hspnp
, NULL
, stdout
, ep
) != 0)
319 /* otherwise, change parameters */
321 if (meta_raid_set_params(sp
, raidnp
, &msp
, ep
) != 0)
325 if (meta_update_md_cf(sp
, ep
) != 0)
334 * parse args and doit
343 mdsetname_t
*sp
= NULL
;
347 md_error_t status
= mdnullerror
;
348 md_error_t
*ep
= &status
;
350 bool_t called_thru_rpc
= FALSE
;
352 char *firstarg
= NULL
;
356 * Get the locale set up before calling any other routines
357 * with messages to ouput. Just in case we're not in a build
358 * environment, make sure that TEXT_DOMAIN gets set to
361 #if !defined(TEXT_DOMAIN)
362 #define TEXT_DOMAIN "SYS_TEST"
364 (void) setlocale(LC_ALL
, "");
365 (void) textdomain(TEXT_DOMAIN
);
367 if ((cp
= strstr(argv
[0], ".rpc_call")) == NULL
) {
368 if (sdssc_bind_library() == SDSSC_OKAY
)
369 if (sdssc_cmd_proxy(argc
, argv
, SDSSC_PROXY_PRIMARY
,
370 &error
) == SDSSC_PROXY_DONE
)
373 *cp
= '\0'; /* cut off ".rpc_call" */
374 called_thru_rpc
= TRUE
;
379 if (md_init(argc
, argv
, 0, 1, ep
) != 0 ||
380 meta_check_root(ep
) != 0) {
385 /* find set and metadevice first */
388 while ((c
= getopt(argc
, argv
, "s:h:p:r:w:o:?")) != -1) {
402 if ((argc
- optind
) <= 0)
406 if ((sp
= metasetname(sname
, ep
)) == NULL
) {
411 if (firstarg
== NULL
)
412 firstarg
= argv
[optind
];
413 if ((called_thru_rpc
== FALSE
) &&
414 meta_is_mn_name(&sp
, firstarg
, ep
)) {
416 * If we are dealing with a MN set and we were not
417 * called thru an rpc call, we are just to send this
418 * command string to the master of the set and let it
420 * Note that if sp is NULL, meta_is_mn_name() derives sp
421 * from firstarg which is the metadevice arg
422 * If this fails, the master must panic as the mddb may be
426 result
= meta_mn_send_command(sp
, argc
, argv
, MD_DISP_STDERR
|
427 MD_PANIC_WHEN_INCONSISTENT
, NO_CONTEXT_STRING
, ep
);
428 /* No further action required */
432 if ((np
= metaname(&sp
, argv
[optind
], META_DEVICE
, ep
)) == NULL
) {
438 if (meta_lock(sp
, TRUE
, ep
)) {
443 if (meta_check_ownership(sp
, ep
) != 0) {
447 if ((miscname
= metagetmiscname(np
, ep
)) == NULL
) {
452 /* dispatch based on device type */
453 if (strcmp(miscname
, MD_STRIPE
) == 0) {
454 if (stripe_params(sp
, np
, argc
, argv
, ep
) != 0) {
458 } else if (strcmp(miscname
, MD_MIRROR
) == 0) {
459 if (mirror_params(sp
, np
, argc
, argv
, ep
) != 0) {
463 } else if (strcmp(miscname
, MD_RAID
) == 0) {
464 if (raid_params(sp
, np
, argc
, argv
, ep
) != 0) {
470 "%s: invalid metadevice type %s\n"),
471 np
->cname
, miscname
);