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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <sys/lvm/md_mirror.h>
49 (void) fprintf(stderr
, gettext("\
50 usage: %s [-s setname] -r [buffer_size]\n\
51 %s [-s setname] [buffer_size] metadevices...\n\
52 %s [-s setname] -c metadevices...\n"),
53 myname
, myname
, myname
);
58 * crack command line arguments.
67 mdsetname_t
*sp
= NULL
;
72 md_error_t status
= mdnullerror
;
73 md_error_t
*ep
= &status
;
76 md_resync_cmd_t resync_cmd
= MD_RESYNC_START
;
77 bool_t called_thru_rpc
= FALSE
;
83 * Get the locale set up before calling any other routines
84 * with messages to ouput. Just in case we're not in a build
85 * environment, make sure that TEXT_DOMAIN gets set to
88 #if !defined(TEXT_DOMAIN)
89 #define TEXT_DOMAIN "SYS_TEST"
91 (void) setlocale(LC_ALL
, "");
92 (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
;
106 if (md_init(argc
, argv
, 0, 1, ep
) != 0 ||
107 meta_check_root(ep
) != 0) {
115 while ((c
= getopt(argc
, argv
, "phs:rc?")) != -1) {
135 resync_cmd
= MD_RESYNC_KILL
;
147 if ((pflag
+ rflag
) > 1) {
156 if ((sp
= metasetname(sname
, ep
)) == NULL
) {
163 * look for buffer size. If one is not specified we pass '0' to
164 * the meta_resync_all() call. This uses whatever size has been
165 * configured via md_mirror:md_resync_bufsz
166 * The default value (if not overridden in /etc/system) is
167 * MD_DEF_RESYNC_BUF_SIZE
169 if ((argc
> 0) && (isdigit(argv
[0][0]))) {
170 if ((size
= atoi(argv
[0])) < 0) {
172 "illegal buffer size %s\n"),
180 /* sync all devices in set */
186 ((sp
= metasetname(MD_LOCAL_NAME
, ep
)) == NULL
) &&
187 (metaget_setdesc(sp
, ep
) == NULL
)) {
194 * For a MN set "metasync -r" can only be called by the
195 * initiator. We must not take the set lock for a MN set as
196 * it will only generate individual metasync commands which
197 * will individually take the lock when executing the
198 * individual metasync commands.
199 * Therefore only take the set lock for non MN sets.
201 if (meta_is_mn_set(sp
, ep
) == 0) {
203 if (meta_lock(sp
, TRUE
, ep
)) {
208 /* check for ownership */
209 if (meta_check_ownership(sp
, ep
) != 0) {
214 /* resync all metadevices in set */
215 if (meta_resync_all(sp
, size
, ep
) != 0) {
222 /* sync specified metadevices */
227 * Note that if sp is NULL, meta_is_mn_name() derives sp
228 * from argv[0] which is the metadevice arg
230 if (meta_is_mn_name(&sp
, argv
[0], ep
))
233 for (; (argc
> 0); --argc
, ++argv
) {
238 if ((np
= metaname(&sp
, argv
[0], META_DEVICE
, ep
)) == NULL
) {
246 * If we are not called through an rpc call and the
247 * set associated with the command is an MN set, send
248 * a setsync message to the master of the set and let it
251 if (!called_thru_rpc
&& mn_set
) {
252 if ((result
= meta_mn_send_setsync(sp
, np
, size
,
254 mde_perror(ep
, "Unable to start resync");
261 if (meta_lock(sp
, TRUE
, ep
)) {
266 /* check for ownership */
267 if (meta_check_ownership(sp
, ep
) != 0) {
269 md_exit(sp
, 1); /* no point in continuing */
272 /* resync or regen (raid only) metadevice */
275 if (meta_raid_regen_byname(sp
, np
, size
, ep
) != 0) {
281 if (meta_resync_byname(sp
, np
, size
, ep
, resync_cmd
)