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 * replace mirror component
45 (void) fprintf(stderr
, gettext("\
46 usage: %s [-s setname] mirror component-old component-new\n\
47 %s [-s setname] -e mirror component\n\
48 %s [-s setname] [-f] RAID component-old component-new\n\
49 %s [-s setname] [-f] -e RAID component\n"),
50 myname
, myname
, myname
, myname
);
55 * online replace a physical disk in a metamirror
64 mdsetname_t
*sp
= NULL
;
65 mdcmdopts_t options
= (MDCMD_PRINT
|MDCMD_DOIT
);
69 md_error_t status
= mdnullerror
;
70 md_error_t
*ep
= &status
;
73 bool_t called_thru_rpc
= FALSE
;
76 char **origargv
= argv
;
79 * Get the locale set up before calling any other routines
80 * with messages to ouput. Just in case we're not in a build
81 * environment, make sure that TEXT_DOMAIN gets set to
84 #if !defined(TEXT_DOMAIN)
85 #define TEXT_DOMAIN "SYS_TEST"
87 (void) setlocale(LC_ALL
, "");
88 (void) textdomain(TEXT_DOMAIN
);
91 if ((cp
= strstr(argv
[0], ".rpc_call")) == NULL
) {
92 if (sdssc_bind_library() == SDSSC_OKAY
)
93 if (sdssc_cmd_proxy(argc
, argv
, SDSSC_PROXY_PRIMARY
,
94 &error
) == SDSSC_PROXY_DONE
)
97 *cp
= '\0'; /* cut off ".rpc_call" */
98 called_thru_rpc
= TRUE
;
102 if (md_init(argc
, argv
, 0, 1, ep
) != 0 ||
103 meta_check_root(ep
) != 0) {
108 /* parse arguments */
111 while ((c
= getopt(argc
, argv
, "hs:efn?")) != -1) {
126 options
|= MDCMD_FORCE
;
130 if (called_thru_rpc
== TRUE
) {
131 options
&= ~MDCMD_DOIT
;
150 if ((sp
= metasetname(sname
, ep
)) == NULL
) {
162 if (((namep
= metaname(&sp
, uname
, META_DEVICE
, ep
)) == NULL
)) {
167 if (metachkmeta(namep
, ep
) != 0) {
173 if ((called_thru_rpc
== FALSE
) &&
174 meta_is_mn_name(&sp
, argv
[0], ep
)) {
176 * If we are dealing with a MN set and we were not
177 * called thru an rpc call, we are just to send this
178 * command string to the master of the set and let it
180 * Note that if sp is NULL, meta_is_mn_name() derives sp
181 * from argv[0] which is the metadevice arg
189 if ((miscname
= metagetmiscname(namep
, ep
)) == NULL
) {
194 newargv
= calloc(origargc
+1, sizeof (char *));
195 newargv
[0] = "metareplace";
196 newargv
[1] = "-n"; /* always do "-n" first */
198 for (i
= 1; i
< origargc
; i
++, newargc
++) {
199 newargv
[newargc
] = origargv
[i
];
202 result
= meta_mn_send_command(sp
, newargc
, newargv
,
203 MD_DISP_STDERR
| MD_DRYRUN
, NO_CONTEXT_STRING
, ep
);
205 /* If we've found a problem don't do it for real */
210 * Do it for real now. Remove "-n" from the arguments and
211 * MD_DRYRUN from the flags. If this fails, the master must
212 * panic as the mddbs may be inconsistent.
214 newargv
[1] = ""; /* this was "-n" before */
215 result
= meta_mn_send_command(sp
, newargc
, newargv
,
216 MD_DISP_STDERR
| MD_RETRY_BUSY
| MD_PANIC_WHEN_INCONSISTENT
,
217 NO_CONTEXT_STRING
, ep
);
222 * if the metareplace command succeeds for a mirror, send a
223 * resync starting message for the metadevice
225 if ((result
== 0) && (strcmp(miscname
, MD_MIRROR
) == 0)) {
226 if ((result
= meta_mn_send_resync_starting(namep
, ep
))
228 mde_perror(ep
, "Unable to start resync");
236 if (meta_lock(sp
, TRUE
, ep
)) {
241 /* check for ownership */
242 if (meta_check_ownership(sp
, ep
) != 0) {
247 if (eflag
) { /* enable component */
253 if ((compnp
= metaname(&sp
, argv
[0], UNKNOWN
, ep
)) == NULL
) {
257 if (meta_enable_byname(sp
, namep
, compnp
, options
, ep
)
262 } else { /* replace component */
269 if ((oldnp
= metaname(&sp
, argv
[0], UNKNOWN
, ep
)) == NULL
) {
273 if ((newnp
= metaname(&sp
, argv
[1], UNKNOWN
, ep
)) == NULL
) {
277 if (meta_replace_byname(sp
, namep
, oldnp
, newnp
,
285 if (meta_update_md_cf(sp
, ep
) != 0) {