xref: /onnv-gate/usr/src/cmd/lvm/util/metaonline.c (revision 1623:7bac4a816ebe)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1623Stw21770  * Common Development and Distribution License (the "License").
6*1623Stw21770  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1623Stw21770  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * online sub-mirrors
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <meta.h>
330Sstevel@tonic-gate #include <sdssc.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * print usage message
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate static void
usage(mdsetname_t * sp,int eval)390Sstevel@tonic-gate usage(
400Sstevel@tonic-gate 	mdsetname_t	*sp,
410Sstevel@tonic-gate 	int		eval
420Sstevel@tonic-gate )
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\
450Sstevel@tonic-gate usage:	%s [-s setname] mirror submirror\n"),
460Sstevel@tonic-gate 	    myname);
470Sstevel@tonic-gate 	md_exit(sp, eval);
480Sstevel@tonic-gate }
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * Metaonline: to online a metadevice
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate int
main(int argc,char * argv[])540Sstevel@tonic-gate main(
550Sstevel@tonic-gate 	int		argc,
560Sstevel@tonic-gate 	char		*argv[]
570Sstevel@tonic-gate )
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	char		*sname = NULL;
600Sstevel@tonic-gate 	mdsetname_t	*sp = NULL;
610Sstevel@tonic-gate 	mdcmdopts_t	options = (MDCMD_PRINT);
620Sstevel@tonic-gate 	mdname_t	*mirnp;
630Sstevel@tonic-gate 	mdname_t	*submirnp;
640Sstevel@tonic-gate 	int		c;
650Sstevel@tonic-gate 	md_error_t	status = mdnullerror;
660Sstevel@tonic-gate 	md_error_t	*ep = &status;
670Sstevel@tonic-gate 	int		error;
680Sstevel@tonic-gate 	bool_t		called_thru_rpc = FALSE;
690Sstevel@tonic-gate 	char		*cp;
700Sstevel@tonic-gate 	int		origargc = argc;
710Sstevel@tonic-gate 	char		**origargv = argv;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	/*
740Sstevel@tonic-gate 	 * Get the locale set up before calling any other routines
750Sstevel@tonic-gate 	 * with messages to ouput.  Just in case we're not in a build
760Sstevel@tonic-gate 	 * environment, make sure that TEXT_DOMAIN gets set to
770Sstevel@tonic-gate 	 * something.
780Sstevel@tonic-gate 	 */
790Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
800Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
830Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	if ((cp = strstr(argv[0], ".rpc_call")) == NULL) {
860Sstevel@tonic-gate 		if (sdssc_bind_library() == SDSSC_OKAY)
870Sstevel@tonic-gate 			if (sdssc_cmd_proxy(argc, argv, SDSSC_PROXY_PRIMARY,
880Sstevel@tonic-gate 						&error) == SDSSC_PROXY_DONE)
890Sstevel@tonic-gate 				exit(error);
900Sstevel@tonic-gate 	} else {
910Sstevel@tonic-gate 		*cp = '\0'; /* cut off ".rpc_call" */
920Sstevel@tonic-gate 		called_thru_rpc = TRUE;
930Sstevel@tonic-gate 	}
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	/* initialize */
960Sstevel@tonic-gate 	if (md_init(argc, argv, 0, 1, ep) != 0 ||
970Sstevel@tonic-gate 			meta_check_root(ep) != 0) {
980Sstevel@tonic-gate 		mde_perror(ep, "");
990Sstevel@tonic-gate 		md_exit(sp, 1);
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	/* parse args */
1030Sstevel@tonic-gate 	optind = 1;
1040Sstevel@tonic-gate 	opterr = 1;
1050Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "hs:?")) != -1) {
1060Sstevel@tonic-gate 		switch (c) {
1070Sstevel@tonic-gate 		case 'h':
1080Sstevel@tonic-gate 			usage(sp, 0);
1090Sstevel@tonic-gate 			break;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 		case 's':
1120Sstevel@tonic-gate 			sname = optarg;
1130Sstevel@tonic-gate 			break;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 		case '?':
1160Sstevel@tonic-gate 			if (optopt == '?')
1170Sstevel@tonic-gate 				usage(sp, 0);
1180Sstevel@tonic-gate 			/*FALLTHROUGH*/
1190Sstevel@tonic-gate 		default:
1200Sstevel@tonic-gate 			usage(sp, 1);
1210Sstevel@tonic-gate 			break;
1220Sstevel@tonic-gate 		}
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate 	argc -= optind;
1250Sstevel@tonic-gate 	argv += optind;
1260Sstevel@tonic-gate 	if (argc != 2)
1270Sstevel@tonic-gate 		usage(sp, 1);
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	if (sname != NULL) {
1300Sstevel@tonic-gate 		if ((sp = metasetname(sname, ep)) == NULL) {
1310Sstevel@tonic-gate 			mde_perror(ep, "");
1320Sstevel@tonic-gate 			md_exit(sp, 1);
1330Sstevel@tonic-gate 		}
1340Sstevel@tonic-gate 	}
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	/* get names */
137*1623Stw21770 	if (((mirnp = metaname(&sp, argv[0], META_DEVICE, ep)) == NULL) ||
138*1623Stw21770 	    ((submirnp = metaname(&sp, argv[1], META_DEVICE, ep)) == NULL)) {
1390Sstevel@tonic-gate 		mde_perror(ep, "");
1400Sstevel@tonic-gate 		md_exit(sp, 1);
1410Sstevel@tonic-gate 	}
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	assert(sp != NULL);
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	if ((called_thru_rpc == FALSE) &&
1460Sstevel@tonic-gate 	    meta_is_mn_name(&sp, argv[0], ep)) {
1470Sstevel@tonic-gate 		/*
1480Sstevel@tonic-gate 		 * If we are dealing with a MN set and we were not
1490Sstevel@tonic-gate 		 * called thru an rpc call, we are just to send this
1500Sstevel@tonic-gate 		 * command string to the master of the set and let it
1510Sstevel@tonic-gate 		 * deal with it.
1520Sstevel@tonic-gate 		 * Note that if sp is NULL, meta_is_mn_name() derives sp
1530Sstevel@tonic-gate 		 * from argv[0] which is the metadevice arg
1540Sstevel@tonic-gate 		 * If this fails, the master must panic as the mddb may be
1550Sstevel@tonic-gate 		 * inconsistent.
1560Sstevel@tonic-gate 		 */
1570Sstevel@tonic-gate 		int  result;
1580Sstevel@tonic-gate 		result = meta_mn_send_command(sp, origargc, origargv,
1590Sstevel@tonic-gate 		    MD_DISP_STDERR | MD_PANIC_WHEN_INCONSISTENT,
1600Sstevel@tonic-gate 		    NO_CONTEXT_STRING, ep);
1610Sstevel@tonic-gate 		/*
1620Sstevel@tonic-gate 		 * Unlike non-MN sets, the metaonline command does not actually
1630Sstevel@tonic-gate 		 * start a resync, it simply updates the state on all of the
1640Sstevel@tonic-gate 		 * nodes. Therefore, to start a resync we send a resync starting
1650Sstevel@tonic-gate 		 * message for the metadevice
1660Sstevel@tonic-gate 		 */
1670Sstevel@tonic-gate 		if (result == 0) {
1680Sstevel@tonic-gate 			if ((result = meta_mn_send_resync_starting(mirnp, ep))
1690Sstevel@tonic-gate 			    != 0)
1700Sstevel@tonic-gate 				mde_perror(ep, "Unable to start resync");
1710Sstevel@tonic-gate 		}
1720Sstevel@tonic-gate 		md_exit(sp, result);
1730Sstevel@tonic-gate 	}
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	/* grab set lock */
1760Sstevel@tonic-gate 	if (meta_lock(sp, TRUE, ep)) {
1770Sstevel@tonic-gate 		mde_perror(ep, "");
1780Sstevel@tonic-gate 		md_exit(sp, 1);
1790Sstevel@tonic-gate 	}
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	/* check for ownership */
1820Sstevel@tonic-gate 	if (meta_check_ownership(sp, ep) != 0) {
1830Sstevel@tonic-gate 		mde_perror(ep, "");
1840Sstevel@tonic-gate 		md_exit(sp, 1);
1850Sstevel@tonic-gate 	}
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	/* online submirror */
1880Sstevel@tonic-gate 	if (meta_mirror_online(sp, mirnp, submirnp, options, ep) != 0) {
1890Sstevel@tonic-gate 		mde_perror(ep, "");
1900Sstevel@tonic-gate 		md_exit(sp, 1);
1910Sstevel@tonic-gate 	}
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	/* return success */
1940Sstevel@tonic-gate 	md_exit(sp, 0);
1950Sstevel@tonic-gate 	/*NOTREACHED*/
1960Sstevel@tonic-gate 	return (0);
1970Sstevel@tonic-gate }
198