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 * rename or exchange metadevice identity
45 (void) fprintf(stderr
, gettext("\
46 usage: %s [-s setname] [-f] [-x] metadevice1 metadevice2\n\
49 -s operations are done on the set setname, rather than the local set\n\
50 -f force exchange or rename\n\
51 -x exchange the identities of metadevice1 and metadevice2\n\
52 -h help: print this message\n"), myname
, myname
);
57 * mainline. crack command line arguments.
66 mdsetname_t
*sp
= NULL
;
68 mdcmdopts_t options
= (MDCMD_PRINT
| MDCMD_DOIT
);
69 md_error_t status
= mdnullerror
;
70 md_error_t
*ep
= &status
;
75 bool_t called_thru_rpc
= FALSE
;
78 char **origargv
= argv
;
82 * Get the locale set up before calling any other routines
83 * with messages to ouput. Just in case we're not in a build
84 * environment, make sure that TEXT_DOMAIN gets set to
87 #if !defined(TEXT_DOMAIN)
88 #define TEXT_DOMAIN "SYS_TEST"
90 (void) setlocale(LC_ALL
, "");
91 (void) textdomain(TEXT_DOMAIN
);
94 if ((cp
= strstr(argv
[0], ".rpc_call")) == NULL
) {
95 if (sdssc_bind_library() == SDSSC_OKAY
)
96 if (sdssc_cmd_proxy(argc
, argv
, SDSSC_PROXY_PRIMARY
,
97 &error
) == SDSSC_PROXY_DONE
)
100 *cp
= '\0'; /* cut off ".rpc_call" */
101 called_thru_rpc
= TRUE
;
105 if (md_init(argc
, argv
, 0, 1, ep
) != 0 ||
106 meta_check_root(ep
) != 0) {
114 while ((c
= getopt(argc
, argv
, "fns:xh?")) != -1) {
129 options
|= MDCMD_FORCE
;
133 if (called_thru_rpc
== TRUE
) {
134 options
&= ~MDCMD_DOIT
;
153 if ((sp
= metasetname(sname
, ep
)) == NULL
) {
163 if ((called_thru_rpc
== FALSE
) &&
164 meta_is_mn_name(&sp
, argv
[0], ep
)) {
166 * If we are dealing with a MN set and we were not
167 * called thru an rpc call, we are just to send this
168 * command string to the master of the set and let it
170 * Note that if sp is NULL, meta_is_mn_name() derives sp
171 * from argv[0] which is the metadevice arg
179 * For MN sets we start a dryrun version of this command
180 * before sending out the real version.
181 * Thus we need a new array for the arguments as the first
182 * one will be -n to indicate the dryrun
184 newargv
= calloc(origargc
+1, sizeof (char *));
185 newargv
[0] = "metarename";
186 newargv
[1] = "-n"; /* always do "-n" first */
188 for (i
= 1; i
< origargc
; i
++, newargc
++)
189 newargv
[newargc
] = origargv
[i
];
191 result
= meta_mn_send_command(sp
, newargc
, newargv
,
192 MD_DISP_STDERR
| MD_DRYRUN
, NO_CONTEXT_STRING
, ep
);
194 /* If we found a problem don't do it for real */
200 * Do it for real now. Remove "-n" from the arguments and
201 * MD_DRYRUN from the flags. If this fails, the master must
202 * panic as the mddb may be inconsistent.
204 newargv
[1] = ""; /* this was "-n" before */
205 result
= meta_mn_send_command(sp
, newargc
, newargv
,
206 MD_DISP_STDERR
| MD_RETRY_BUSY
| MD_PANIC_WHEN_INCONSISTENT
,
207 NO_CONTEXT_STRING
, ep
);
213 for (i
= 0; i
< 2; i
++) {
214 if (!is_metaname(argv
[i
])) {
216 * one of the input devices is not a valid
221 if (i
== 1 && !xflag
) {
222 /* rename, create dest metadevice name */
223 if (meta_init_make_device(&sp
, argv
[i
], ep
) <= 0) {
224 mde_perror(ep
, argv
[i
]);
229 if ((mdnms
[i
] = metaname(&sp
, argv
[i
],
230 META_DEVICE
, ep
)) == NULL
) {
231 mde_perror(ep
, argv
[i
]);
237 * The FORCE option is only valid for a trans metadevice, clear it if
240 if ((miscname
= metagetmiscname(mdnms
[0], ep
)) == NULL
) {
245 if (strcmp(miscname
, MD_TRANS
) != 0) {
246 options
&= ~MDCMD_FORCE
;
249 if (meta_lock(sp
, TRUE
, ep
)) {
254 if (meta_check_ownership(sp
, ep
) != 0) {
260 rc
= meta_exchange(sp
, mdnms
[0], mdnms
[1], options
, ep
);
262 rc
= meta_rename(sp
, mdnms
[0], mdnms
[1], options
, ep
);
265 if (rc
!= 0 || !mdisok(ep
)) {