xref: /titanic_41/usr/src/lib/lvm/libmeta/common/meta_metad.c (revision da83352438a4a62b87fcb6fd1583e3a70aa31bb8)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*da833524Sjeanm  * Common Development and Distribution License (the "License").
6*da833524Sjeanm  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da833524Sjeanm  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Just in case we're not in a build environment, make sure that
307c478bd9Sstevel@tonic-gate  * TEXT_DOMAIN gets set to something.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
337c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <meta.h>
377c478bd9Sstevel@tonic-gate #include <metad.h>
387c478bd9Sstevel@tonic-gate #include <devid.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate static md_setkey_t	*my_cl_sk = NULL;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	CL_DEF_TMO	30L
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Convert an old style mddrivename_t into a new style
467c478bd9Sstevel@tonic-gate  * mddrivename_t. Meant to be used *ONLY* by rpc.metad
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate void
meta_conv_drvname_old2new(o_mddrivename_t * v1_dp,mddrivename_t * v2_dp)497c478bd9Sstevel@tonic-gate meta_conv_drvname_old2new(
507c478bd9Sstevel@tonic-gate 	o_mddrivename_t		*v1_dp,
517c478bd9Sstevel@tonic-gate 	mddrivename_t		*v2_dp
527c478bd9Sstevel@tonic-gate )
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	int 		sliceno;
557c478bd9Sstevel@tonic-gate 	o_mdname_t	*v1_np;
567c478bd9Sstevel@tonic-gate 	mdname_t	*v2_np;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	/* fields that haven't changed */
597c478bd9Sstevel@tonic-gate 	v2_dp->cname   = v1_dp->cname;
607c478bd9Sstevel@tonic-gate 	v2_dp->rname   = v1_dp->rname;
617c478bd9Sstevel@tonic-gate 	v2_dp->type    = v1_dp->type;
627c478bd9Sstevel@tonic-gate 	v2_dp->errnum  = v1_dp->errnum;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	/* geometry information */
657c478bd9Sstevel@tonic-gate 	v2_dp->geom.ncyl  = v1_dp->geom.ncyl;
667c478bd9Sstevel@tonic-gate 	v2_dp->geom.nhead = v1_dp->geom.nhead;
677c478bd9Sstevel@tonic-gate 	v2_dp->geom.nsect = v1_dp->geom.nsect;
687c478bd9Sstevel@tonic-gate 	v2_dp->geom.rpm   = v1_dp->geom.rpm;
697c478bd9Sstevel@tonic-gate 	v2_dp->geom.write_reinstruct = v1_dp->geom.write_reinstruct;
707c478bd9Sstevel@tonic-gate 	v2_dp->geom.read_reinstruct  = v1_dp->geom.read_reinstruct;
717c478bd9Sstevel@tonic-gate 	v2_dp->geom.blk_sz = 0;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/* controller information */
747c478bd9Sstevel@tonic-gate 	v2_dp->cinfo = v1_dp->cinfo;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/* vtoc information */
777c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.nparts    = v1_dp->vtoc.nparts;
787c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.first_lba = 0;
797c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.last_lba  = 0;
807c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.lbasize   = 0;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	for (sliceno = 0; sliceno < (MD_MAX_PARTS - 1); sliceno++) {
837c478bd9Sstevel@tonic-gate 		v2_dp->vtoc.parts[sliceno].start =
847c478bd9Sstevel@tonic-gate 		    (diskaddr_t)v1_dp->vtoc.parts[sliceno].start;
857c478bd9Sstevel@tonic-gate 		v2_dp->vtoc.parts[sliceno].size =
867c478bd9Sstevel@tonic-gate 		    (diskaddr_t)v1_dp->vtoc.parts[sliceno].size;
877c478bd9Sstevel@tonic-gate 		v2_dp->vtoc.parts[sliceno].tag =
887c478bd9Sstevel@tonic-gate 		    v1_dp->vtoc.parts[sliceno].tag;
897c478bd9Sstevel@tonic-gate 		v2_dp->vtoc.parts[sliceno].flag =
907c478bd9Sstevel@tonic-gate 		    v1_dp->vtoc.parts[sliceno].flag;
917c478bd9Sstevel@tonic-gate 		v2_dp->vtoc.parts[sliceno].label =
927c478bd9Sstevel@tonic-gate 		    (diskaddr_t)v1_dp->vtoc.parts[sliceno].label;
937c478bd9Sstevel@tonic-gate 	}
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	/* The new style vtoc has 17 partitions */
967c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.parts[MD_MAX_PARTS - 1].start = 0;
977c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.parts[MD_MAX_PARTS - 1].size  = 0;
987c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.parts[MD_MAX_PARTS - 1].tag   = 0;
997c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.parts[MD_MAX_PARTS - 1].flag  = 0;
1007c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.parts[MD_MAX_PARTS - 1].label = 0;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	v2_dp->vtoc.typename = v1_dp->vtoc.typename;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	/* partition information */
1057c478bd9Sstevel@tonic-gate 	v2_dp->parts.parts_len = v1_dp->parts.parts_len;
1067c478bd9Sstevel@tonic-gate 	for (sliceno = 0; sliceno < v1_dp->parts.parts_len; sliceno++) {
1077c478bd9Sstevel@tonic-gate 		v1_np = &v1_dp->parts.parts_val[sliceno];
1087c478bd9Sstevel@tonic-gate 		v2_np = &v2_dp->parts.parts_val[sliceno];
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 		/*
1117c478bd9Sstevel@tonic-gate 		 * We speculate that if cname for a particular
1127c478bd9Sstevel@tonic-gate 		 * partition does not exist, the other fields
1137c478bd9Sstevel@tonic-gate 		 * don't exist either. In such a case, we don't
1147c478bd9Sstevel@tonic-gate 		 * need to do anything for that partition.
1157c478bd9Sstevel@tonic-gate 		 */
1167c478bd9Sstevel@tonic-gate 		if (v1_np->cname != NULL) {
1177c478bd9Sstevel@tonic-gate 			v2_np->cname = v1_np->cname;
1187c478bd9Sstevel@tonic-gate 			v2_np->bname = v1_np->bname;
1197c478bd9Sstevel@tonic-gate 			v2_np->rname = v1_np->rname;
1207c478bd9Sstevel@tonic-gate 			v2_np->devicesname = v1_np->devicesname;
1217c478bd9Sstevel@tonic-gate 			v2_np->dev = meta_expldev(v1_np->dev);
1227c478bd9Sstevel@tonic-gate 			v2_np->key = v1_np->key;
1237c478bd9Sstevel@tonic-gate 			v2_np->end_blk = (diskaddr_t)v1_np->end_blk;
1247c478bd9Sstevel@tonic-gate 			v2_np->start_blk = (diskaddr_t)v1_np->start_blk;
1257c478bd9Sstevel@tonic-gate 		}
1267c478bd9Sstevel@tonic-gate 		v2_np->drivenamep = v2_dp;
1277c478bd9Sstevel@tonic-gate 	}
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	/* We don't care about the rest of the fields */
1307c478bd9Sstevel@tonic-gate 	v2_dp->side_names = v1_dp->side_names;
1317c478bd9Sstevel@tonic-gate 	v2_dp->side_names_key = v1_dp->side_names_key;
1327c478bd9Sstevel@tonic-gate 	v2_dp->miscname = v1_dp->miscname;
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * Convert a new style mddrivename_t into an old style
1377c478bd9Sstevel@tonic-gate  * mddrivename_t. Meant to be used *ONLY* by rpc.metad
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate void
meta_conv_drvname_new2old(o_mddrivename_t * v1_dp,mddrivename_t * v2_dp)1407c478bd9Sstevel@tonic-gate meta_conv_drvname_new2old(
1417c478bd9Sstevel@tonic-gate 	o_mddrivename_t		*v1_dp,
1427c478bd9Sstevel@tonic-gate 	mddrivename_t		*v2_dp
1437c478bd9Sstevel@tonic-gate )
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	int 		sliceno;
1467c478bd9Sstevel@tonic-gate 	o_mdname_t	*v1_np;
1477c478bd9Sstevel@tonic-gate 	mdname_t	*v2_np;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	/* fields that haven't changed */
1507c478bd9Sstevel@tonic-gate 	v1_dp->cname   = v2_dp->cname;
1517c478bd9Sstevel@tonic-gate 	v1_dp->rname   = v2_dp->rname;
1527c478bd9Sstevel@tonic-gate 	v1_dp->type    = v2_dp->type;
1537c478bd9Sstevel@tonic-gate 	v1_dp->errnum  = v2_dp->errnum;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	/* geometry information */
1567c478bd9Sstevel@tonic-gate 	v1_dp->geom.ncyl  = v2_dp->geom.ncyl;
1577c478bd9Sstevel@tonic-gate 	v1_dp->geom.nhead = v2_dp->geom.nhead;
1587c478bd9Sstevel@tonic-gate 	v1_dp->geom.nsect = v2_dp->geom.nsect;
1597c478bd9Sstevel@tonic-gate 	v1_dp->geom.rpm   = v2_dp->geom.rpm;
1607c478bd9Sstevel@tonic-gate 	v1_dp->geom.write_reinstruct = v2_dp->geom.write_reinstruct;
1617c478bd9Sstevel@tonic-gate 	v1_dp->geom.read_reinstruct  = v2_dp->geom.read_reinstruct;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	/* controller information */
1647c478bd9Sstevel@tonic-gate 	v1_dp->cinfo = v2_dp->cinfo;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* vtoc information */
1677c478bd9Sstevel@tonic-gate 	v1_dp->vtoc.typename = v2_dp->vtoc.typename;
1687c478bd9Sstevel@tonic-gate 	v1_dp->vtoc.nparts   = v2_dp->vtoc.nparts;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	for (sliceno = 0; sliceno < (MD_MAX_PARTS - 1); sliceno++) {
1717c478bd9Sstevel@tonic-gate 		v1_dp->vtoc.parts[sliceno].start =
1727c478bd9Sstevel@tonic-gate 		    (daddr_t)v2_dp->vtoc.parts[sliceno].start;
1737c478bd9Sstevel@tonic-gate 		v1_dp->vtoc.parts[sliceno].size  =
1747c478bd9Sstevel@tonic-gate 		    (daddr_t)v2_dp->vtoc.parts[sliceno].size;
1757c478bd9Sstevel@tonic-gate 		v1_dp->vtoc.parts[sliceno].tag   =
1767c478bd9Sstevel@tonic-gate 		    v2_dp->vtoc.parts[sliceno].tag;
1777c478bd9Sstevel@tonic-gate 		v1_dp->vtoc.parts[sliceno].flag  =
1787c478bd9Sstevel@tonic-gate 		    v2_dp->vtoc.parts[sliceno].flag;
1797c478bd9Sstevel@tonic-gate 		v1_dp->vtoc.parts[sliceno].label =
1807c478bd9Sstevel@tonic-gate 		    (daddr_t)v2_dp->vtoc.parts[sliceno].label;
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	/* partition information */
1847c478bd9Sstevel@tonic-gate 	v1_dp->parts.parts_len = v2_dp->parts.parts_len;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	for (sliceno = 0; sliceno < v2_dp->parts.parts_len; sliceno++) {
1877c478bd9Sstevel@tonic-gate 		v1_np = &v1_dp->parts.parts_val[sliceno];
1887c478bd9Sstevel@tonic-gate 		v2_np = &v2_dp->parts.parts_val[sliceno];
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 		/*
1917c478bd9Sstevel@tonic-gate 		 * We speculate that if cname for a particular
1927c478bd9Sstevel@tonic-gate 		 * partition does not exist then the rest of
1937c478bd9Sstevel@tonic-gate 		 * the fields a partition don't exist either.
1947c478bd9Sstevel@tonic-gate 		 * In such a case, we don't need to do anything
1957c478bd9Sstevel@tonic-gate 		 * for that partition.
1967c478bd9Sstevel@tonic-gate 		 */
1977c478bd9Sstevel@tonic-gate 		if (v2_np->cname != NULL) {
1987c478bd9Sstevel@tonic-gate 			v1_np->cname = v2_np->cname;
1997c478bd9Sstevel@tonic-gate 			v1_np->bname = v2_np->bname;
2007c478bd9Sstevel@tonic-gate 			v1_np->rname = v2_np->rname;
2017c478bd9Sstevel@tonic-gate 			v1_np->devicesname = v2_np->devicesname;
2027c478bd9Sstevel@tonic-gate 			v1_np->dev = meta_cmpldev(v2_np->dev);
2037c478bd9Sstevel@tonic-gate 			v1_np->key = v2_np->key;
2047c478bd9Sstevel@tonic-gate 			v1_np->end_blk = (daddr_t)v2_np->end_blk;
2057c478bd9Sstevel@tonic-gate 			v1_np->start_blk = (daddr_t)v2_np->start_blk;
2067c478bd9Sstevel@tonic-gate 		}
2077c478bd9Sstevel@tonic-gate 		v1_np->drivenamep = v1_dp;
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	/* We don't care about the rest of the fields */
2117c478bd9Sstevel@tonic-gate 	v1_dp->side_names = v2_dp->side_names;
2127c478bd9Sstevel@tonic-gate 	v1_dp->side_names_key = v2_dp->side_names_key;
2137c478bd9Sstevel@tonic-gate 	v1_dp->miscname = v2_dp->miscname;
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate /*
2177c478bd9Sstevel@tonic-gate  * Convert an old style md_drive_desc_t into a new style
2187c478bd9Sstevel@tonic-gate  * md_drive_desc_t. Meant to be used *ONLY* by rpc.metad
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate void
meta_conv_drvdesc_old2new(o_md_drive_desc * v1_dd,md_drive_desc * v2_dd)2217c478bd9Sstevel@tonic-gate meta_conv_drvdesc_old2new(
2227c478bd9Sstevel@tonic-gate 	o_md_drive_desc		*v1_dd,
2237c478bd9Sstevel@tonic-gate 	md_drive_desc		*v2_dd
2247c478bd9Sstevel@tonic-gate )
2257c478bd9Sstevel@tonic-gate {
2267c478bd9Sstevel@tonic-gate 	md_drive_desc	*dd;
2277c478bd9Sstevel@tonic-gate 	o_md_drive_desc	*o_dd;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	dd = v2_dd;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	for (o_dd = v1_dd; o_dd != NULL; o_dd = o_dd->dd_next) {
2327c478bd9Sstevel@tonic-gate 		dd->dd_ctime = o_dd->dd_ctime;
2337c478bd9Sstevel@tonic-gate 		dd->dd_genid = o_dd->dd_genid;
2347c478bd9Sstevel@tonic-gate 		dd->dd_flags = o_dd->dd_flags;
2357c478bd9Sstevel@tonic-gate 		meta_conv_drvname_old2new(o_dd->dd_dnp, dd->dd_dnp);
2367c478bd9Sstevel@tonic-gate 		dd->dd_dbcnt = o_dd->dd_dbcnt;
2377c478bd9Sstevel@tonic-gate 		dd->dd_dbsize = o_dd->dd_dbsize;
2387c478bd9Sstevel@tonic-gate 		dd = dd->dd_next;
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate  * Convert an new style md_drive_desc_t into a old style
2447c478bd9Sstevel@tonic-gate  * md_drive_desc_t. Meant to be used *ONLY* by rpc.metad
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate void
meta_conv_drvdesc_new2old(o_md_drive_desc * v1_dd,md_drive_desc * v2_dd)2477c478bd9Sstevel@tonic-gate meta_conv_drvdesc_new2old(
2487c478bd9Sstevel@tonic-gate 	o_md_drive_desc		*v1_dd,
2497c478bd9Sstevel@tonic-gate 	md_drive_desc		*v2_dd
2507c478bd9Sstevel@tonic-gate )
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate 	md_drive_desc	*dd;
2537c478bd9Sstevel@tonic-gate 	o_md_drive_desc	*o_dd;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	o_dd = v1_dd;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	for (dd = v2_dd; dd != NULL; dd = dd->dd_next) {
2587c478bd9Sstevel@tonic-gate 		o_dd->dd_ctime = dd->dd_ctime;
2597c478bd9Sstevel@tonic-gate 		o_dd->dd_genid = dd->dd_genid;
2607c478bd9Sstevel@tonic-gate 		o_dd->dd_flags = dd->dd_flags;
2617c478bd9Sstevel@tonic-gate 		meta_conv_drvname_new2old(o_dd->dd_dnp, dd->dd_dnp);
2627c478bd9Sstevel@tonic-gate 		o_dd->dd_dbcnt = dd->dd_dbcnt;
2637c478bd9Sstevel@tonic-gate 		o_dd->dd_dbsize = dd->dd_dbsize;
2647c478bd9Sstevel@tonic-gate 		o_dd = o_dd->dd_next;
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate  * Allocate memory for v1 drive descriptor
2707c478bd9Sstevel@tonic-gate  * depending upon the number of drives in the
2717c478bd9Sstevel@tonic-gate  * v2 drive descriptor
2727c478bd9Sstevel@tonic-gate  */
2737c478bd9Sstevel@tonic-gate void
alloc_olddrvdesc(o_md_drive_desc ** v1_dd,md_drive_desc * v2_dd)2747c478bd9Sstevel@tonic-gate alloc_olddrvdesc(
2757c478bd9Sstevel@tonic-gate 	o_md_drive_desc		**v1_dd,
2767c478bd9Sstevel@tonic-gate 	md_drive_desc		*v2_dd
2777c478bd9Sstevel@tonic-gate )
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	md_drive_desc	*dd;
2807c478bd9Sstevel@tonic-gate 	o_md_drive_desc *new, *head;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	head = NULL;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	for (dd = v2_dd; dd != NULL; dd = dd->dd_next) {
2857c478bd9Sstevel@tonic-gate 		new = Zalloc(sizeof (o_md_drive_desc));
2867c478bd9Sstevel@tonic-gate 		new->dd_dnp = Zalloc(sizeof (o_mddrivename_t));
2877c478bd9Sstevel@tonic-gate 		new->dd_dnp->parts.parts_val = Zalloc(sizeof (o_mdname_t) *
2887c478bd9Sstevel@tonic-gate 		    dd->dd_dnp->parts.parts_len);
2897c478bd9Sstevel@tonic-gate 		new->dd_next = head;
2907c478bd9Sstevel@tonic-gate 		head = new;
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate 	*v1_dd = head;
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * Allocate memory for v2 drive descriptor
2977c478bd9Sstevel@tonic-gate  * depending upon the number of drives in the
2987c478bd9Sstevel@tonic-gate  * v1 drive descriptor
2997c478bd9Sstevel@tonic-gate  */
3007c478bd9Sstevel@tonic-gate void
alloc_newdrvdesc(o_md_drive_desc * v1_dd,md_drive_desc ** v2_dd)3017c478bd9Sstevel@tonic-gate alloc_newdrvdesc(
3027c478bd9Sstevel@tonic-gate 	o_md_drive_desc		*v1_dd,
3037c478bd9Sstevel@tonic-gate 	md_drive_desc		**v2_dd
3047c478bd9Sstevel@tonic-gate )
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate 	md_drive_desc	*new, *head;
3077c478bd9Sstevel@tonic-gate 	o_md_drive_desc	*o_dd;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	head = NULL;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	for (o_dd = v1_dd; o_dd != NULL; o_dd = o_dd->dd_next) {
3127c478bd9Sstevel@tonic-gate 		new = Zalloc(sizeof (md_drive_desc));
3137c478bd9Sstevel@tonic-gate 		new->dd_dnp = Zalloc(sizeof (mddrivename_t));
3147c478bd9Sstevel@tonic-gate 		new->dd_dnp->parts.parts_val = Zalloc(sizeof (mdname_t) *
3157c478bd9Sstevel@tonic-gate 		    o_dd->dd_dnp->parts.parts_len);
3167c478bd9Sstevel@tonic-gate 		new->dd_next = head;
3177c478bd9Sstevel@tonic-gate 		head = new;
3187c478bd9Sstevel@tonic-gate 	}
3197c478bd9Sstevel@tonic-gate 	*v2_dd = head;
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate void
free_olddrvdesc(o_md_drive_desc * v1_dd)3237c478bd9Sstevel@tonic-gate free_olddrvdesc(
3247c478bd9Sstevel@tonic-gate 	o_md_drive_desc		*v1_dd
3257c478bd9Sstevel@tonic-gate )
3267c478bd9Sstevel@tonic-gate {
3277c478bd9Sstevel@tonic-gate 	o_md_drive_desc	*o_dd, *head;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	head = v1_dd;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	while (head != NULL) {
3327c478bd9Sstevel@tonic-gate 		o_dd = head;
3337c478bd9Sstevel@tonic-gate 		head = head->dd_next;
3347c478bd9Sstevel@tonic-gate 		free(o_dd->dd_dnp->parts.parts_val);
3357c478bd9Sstevel@tonic-gate 		free(o_dd->dd_dnp);
3367c478bd9Sstevel@tonic-gate 		free(o_dd);
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate void
free_newdrvdesc(md_drive_desc * v2_dd)3417c478bd9Sstevel@tonic-gate free_newdrvdesc(
3427c478bd9Sstevel@tonic-gate 	md_drive_desc		*v2_dd
3437c478bd9Sstevel@tonic-gate )
3447c478bd9Sstevel@tonic-gate {
3457c478bd9Sstevel@tonic-gate 	md_drive_desc	*dd, *head;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	head = v2_dd;
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	while (head != NULL) {
3507c478bd9Sstevel@tonic-gate 		dd = head;
3517c478bd9Sstevel@tonic-gate 		head = head->dd_next;
3527c478bd9Sstevel@tonic-gate 		free(dd->dd_dnp->parts.parts_val);
3537c478bd9Sstevel@tonic-gate 		free(dd->dd_dnp);
3547c478bd9Sstevel@tonic-gate 		free(dd);
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate  * Return the device id for a given device
3607c478bd9Sstevel@tonic-gate  */
3617c478bd9Sstevel@tonic-gate char *
meta_get_devid(char * rname)3627c478bd9Sstevel@tonic-gate meta_get_devid(
3637c478bd9Sstevel@tonic-gate 	char	*rname
3647c478bd9Sstevel@tonic-gate )
3657c478bd9Sstevel@tonic-gate {
3667c478bd9Sstevel@tonic-gate 	ddi_devid_t	devid;
3677c478bd9Sstevel@tonic-gate 	int		fd;
3687c478bd9Sstevel@tonic-gate 	char		*enc_devid, *dup_enc_devid = NULL;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	if ((fd = open(rname, O_RDWR | O_NDELAY, 0)) < 0)
3717c478bd9Sstevel@tonic-gate 		return (NULL);
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	if (devid_get(fd, &devid) == -1) {
3747c478bd9Sstevel@tonic-gate 		(void) close(fd);
3757c478bd9Sstevel@tonic-gate 		return (NULL);
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate 	(void) close(fd);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	enc_devid = devid_str_encode(devid, NULL);
3807c478bd9Sstevel@tonic-gate 	devid_free(devid);
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	if (enc_devid != NULL) {
3837c478bd9Sstevel@tonic-gate 		dup_enc_devid = strdup(enc_devid);
3847c478bd9Sstevel@tonic-gate 		devid_str_free(enc_devid);
3857c478bd9Sstevel@tonic-gate 	}
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	return (dup_enc_devid);
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate /*
3917c478bd9Sstevel@tonic-gate  * Add side names for the diskset drive records
3927c478bd9Sstevel@tonic-gate  * NOTE: these go into the local set's namespace.
3937c478bd9Sstevel@tonic-gate  */
3947c478bd9Sstevel@tonic-gate int
clnt_add_drv_sidenms(char * hostname,char * this_host,mdsetname_t * sp,md_set_desc * sd,int node_c,char ** node_v,md_error_t * ep)3957c478bd9Sstevel@tonic-gate clnt_add_drv_sidenms(
3967c478bd9Sstevel@tonic-gate 	char			*hostname,
3977c478bd9Sstevel@tonic-gate 	char			*this_host,
3987c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
3997c478bd9Sstevel@tonic-gate 	md_set_desc		*sd,
4007c478bd9Sstevel@tonic-gate 	int			node_c,
4017c478bd9Sstevel@tonic-gate 	char			**node_v,
4027c478bd9Sstevel@tonic-gate 	md_error_t		*ep
4037c478bd9Sstevel@tonic-gate )
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate 	CLIENT				*clntp;
4067c478bd9Sstevel@tonic-gate 	mdrpc_drv_sidenm_args		v1_args;
4077c478bd9Sstevel@tonic-gate 	mdrpc_drv_sidenm_2_args		v2_args;
4087c478bd9Sstevel@tonic-gate 	mdrpc_drv_sidenm_2_args_r1	*v21_args;
4097c478bd9Sstevel@tonic-gate 	mdrpc_generic_res		res;
4107c478bd9Sstevel@tonic-gate 	int				rval;
4117c478bd9Sstevel@tonic-gate 	int				version;
4127c478bd9Sstevel@tonic-gate 	int				i, j;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	/* initialize */
4157c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
4167c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
4177c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
4187c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	/* build args */
4217c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
4227c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_drv_sidenm_2_args_u.rev1;
4237c478bd9Sstevel@tonic-gate 	v21_args->hostname = this_host;
4247c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
4257c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
4267c478bd9Sstevel@tonic-gate 	v21_args->sd = sd;
4277c478bd9Sstevel@tonic-gate 	v21_args->node_v.node_v_len = node_c;
4287c478bd9Sstevel@tonic-gate 	v21_args->node_v.node_v_val = node_v;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	/* do it */
4317c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
4327c478bd9Sstevel@tonic-gate 		int	bool;
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 		/*
4357c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
4367c478bd9Sstevel@tonic-gate 		 */
4377c478bd9Sstevel@tonic-gate 		bool = mdrpc_add_drv_sidenms_2_svc(&v2_args, &res, NULL);
4387c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
4397c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
4407c478bd9Sstevel@tonic-gate 	} else {
4417c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
4427c478bd9Sstevel@tonic-gate 			return (-1);
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 		/*
4457c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
4467c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
4477c478bd9Sstevel@tonic-gate 		 * remote procedure
4487c478bd9Sstevel@tonic-gate 		 */
4497c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 			v1_args.sd = Zalloc(sizeof (o_md_set_desc));
4547c478bd9Sstevel@tonic-gate 			alloc_olddrvdesc(&v1_args.sd->sd_drvs, sd->sd_drvs);
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 			/* build args */
4577c478bd9Sstevel@tonic-gate 			v1_args.hostname = this_host;
4587c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
4597c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
4607c478bd9Sstevel@tonic-gate 			/* set descriptor */
4617c478bd9Sstevel@tonic-gate 			v1_args.sd->sd_ctime = sd->sd_ctime;
4627c478bd9Sstevel@tonic-gate 			v1_args.sd->sd_genid = sd->sd_genid;
4637c478bd9Sstevel@tonic-gate 			v1_args.sd->sd_setno = sd->sd_setno;
4647c478bd9Sstevel@tonic-gate 			v1_args.sd->sd_flags = sd->sd_flags;
4657c478bd9Sstevel@tonic-gate 			for (i = 0; i < MD_MAXSIDES; i++) {
4667c478bd9Sstevel@tonic-gate 				v1_args.sd->sd_isown[i] = sd->sd_isown[i];
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 				for (j = 0; j < MD_MAX_NODENAME_PLUS_1; j ++)
4697c478bd9Sstevel@tonic-gate 					v1_args.sd->sd_nodes[i][j] =
4707c478bd9Sstevel@tonic-gate 					    sd->sd_nodes[i][j];
4717c478bd9Sstevel@tonic-gate 			}
4727c478bd9Sstevel@tonic-gate 			v1_args.sd->sd_med = sd->sd_med;
4737c478bd9Sstevel@tonic-gate 			meta_conv_drvdesc_new2old(v1_args.sd->sd_drvs,
4747c478bd9Sstevel@tonic-gate 			    sd->sd_drvs);
4757c478bd9Sstevel@tonic-gate 			v1_args.node_v.node_v_len = node_c;
4767c478bd9Sstevel@tonic-gate 			v1_args.node_v.node_v_val = node_v;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 			rval = mdrpc_add_drv_sidenms_1(&v1_args, &res, clntp);
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 			free_olddrvdesc(v1_args.sd->sd_drvs);
4817c478bd9Sstevel@tonic-gate 			free(v1_args.sd);
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
4847c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
4857c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
4867c478bd9Sstevel@tonic-gate 				    "metad add drive sidenames"));
4877c478bd9Sstevel@tonic-gate 			else
4887c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
4897c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
4907c478bd9Sstevel@tonic-gate 			rval = mdrpc_add_drv_sidenms_2(&v2_args, &res, clntp);
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
4937c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
4947c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
4957c478bd9Sstevel@tonic-gate 				    "metad add drive sidenames"));
4967c478bd9Sstevel@tonic-gate 			else
4977c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
4987c478bd9Sstevel@tonic-gate 		}
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
5067c478bd9Sstevel@tonic-gate 		return (-1);
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	return (0);
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate /*
512*da833524Sjeanm  * Adding drives via metaimport to disksets. Some of the drives may
513*da833524Sjeanm  * not be available so we need more information than the basic clnt_adddrvs
514*da833524Sjeanm  * offers us.
515*da833524Sjeanm  */
516*da833524Sjeanm int
clnt_imp_adddrvs(char * hostname,mdsetname_t * sp,md_drive_desc * dd,md_timeval32_t timestamp,ulong_t genid,md_error_t * ep)517*da833524Sjeanm clnt_imp_adddrvs(
518*da833524Sjeanm 	char			*hostname,
519*da833524Sjeanm 	mdsetname_t		*sp,
520*da833524Sjeanm 	md_drive_desc		*dd,
521*da833524Sjeanm 	md_timeval32_t		timestamp,
522*da833524Sjeanm 	ulong_t			genid,
523*da833524Sjeanm 	md_error_t		*ep
524*da833524Sjeanm )
525*da833524Sjeanm {
526*da833524Sjeanm 	CLIENT			*clntp;
527*da833524Sjeanm 	mdrpc_drives_2_args	v2_args;
528*da833524Sjeanm 	mdrpc_drives_2_args_r1	*v21_args;
529*da833524Sjeanm 	mdrpc_generic_res	res;
530*da833524Sjeanm 	int			rval;
531*da833524Sjeanm 	int			version;
532*da833524Sjeanm 
533*da833524Sjeanm 	/* initialize */
534*da833524Sjeanm 	mdclrerror(ep);
535*da833524Sjeanm 	(void) memset(&v2_args, 0, sizeof (v2_args));
536*da833524Sjeanm 	(void) memset(&res, 0, sizeof (res));
537*da833524Sjeanm 
538*da833524Sjeanm 	/* build args */
539*da833524Sjeanm 	v2_args.rev = MD_METAD_ARGS_REV_1;
540*da833524Sjeanm 	v21_args = &v2_args.mdrpc_drives_2_args_u.rev1;
541*da833524Sjeanm 	v21_args->sp = sp;
542*da833524Sjeanm 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
543*da833524Sjeanm 	v21_args->drivedescs = dd;
544*da833524Sjeanm 	v21_args->timestamp = timestamp;
545*da833524Sjeanm 	v21_args->genid = genid;
546*da833524Sjeanm 
547*da833524Sjeanm 	/* do it */
548*da833524Sjeanm 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
549*da833524Sjeanm 		int	bool;
550*da833524Sjeanm 
551*da833524Sjeanm 		/*
552*da833524Sjeanm 		 * If the server is local, we call the v1 procedure
553*da833524Sjeanm 		 */
554*da833524Sjeanm 		bool = mdrpc_imp_adddrvs_2(&v2_args, &res, NULL);
555*da833524Sjeanm 		assert(bool == TRUE);
556*da833524Sjeanm 		(void) mdstealerror(ep, &res.status);
557*da833524Sjeanm 	} else {
558*da833524Sjeanm 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
559*da833524Sjeanm 			return (-1);
560*da833524Sjeanm 
561*da833524Sjeanm 		/*
562*da833524Sjeanm 		 * Check the client handle for the version
563*da833524Sjeanm 		 * and invoke the appropriate version of the
564*da833524Sjeanm 		 * remote procedure
565*da833524Sjeanm 		 */
566*da833524Sjeanm 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
567*da833524Sjeanm 
568*da833524Sjeanm 		/*
569*da833524Sjeanm 		 * If the client is version 1, return error
570*da833524Sjeanm 		 * otherwise, make the remote procedure call.
571*da833524Sjeanm 		 */
572*da833524Sjeanm 		if (version == METAD_VERSION) { /* version 1 */
573*da833524Sjeanm 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
574*da833524Sjeanm 			    sp->setno, hostname, NULL, NULL);
575*da833524Sjeanm 			metarpcclose(clntp);
576*da833524Sjeanm 			return (-1);
577*da833524Sjeanm 		} else {
578*da833524Sjeanm 			rval = mdrpc_imp_adddrvs_2(&v2_args, &res, clntp);
579*da833524Sjeanm 			if (rval != RPC_SUCCESS)
580*da833524Sjeanm 				(void) mdrpcerror(ep, clntp, hostname,
581*da833524Sjeanm 				    dgettext(TEXT_DOMAIN,
582*da833524Sjeanm 				    "metad imp add drives"));
583*da833524Sjeanm 			else
584*da833524Sjeanm 				(void) mdstealerror(ep, &res.status);
585*da833524Sjeanm 		}
586*da833524Sjeanm 
587*da833524Sjeanm 		metarpcclose(clntp);
588*da833524Sjeanm 	}
589*da833524Sjeanm 
590*da833524Sjeanm 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
591*da833524Sjeanm 
592*da833524Sjeanm 	if (! mdisok(ep))
593*da833524Sjeanm 		return (-1);
594*da833524Sjeanm 
595*da833524Sjeanm 	return (0);
596*da833524Sjeanm }
597*da833524Sjeanm 
598*da833524Sjeanm 
599*da833524Sjeanm /*
6007c478bd9Sstevel@tonic-gate  * Add drives to disksets.
6017c478bd9Sstevel@tonic-gate  */
6027c478bd9Sstevel@tonic-gate int
clnt_adddrvs(char * hostname,mdsetname_t * sp,md_drive_desc * dd,md_timeval32_t timestamp,ulong_t genid,md_error_t * ep)6037c478bd9Sstevel@tonic-gate clnt_adddrvs(
6047c478bd9Sstevel@tonic-gate 	char			*hostname,
6057c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
6067c478bd9Sstevel@tonic-gate 	md_drive_desc		*dd,
6077c478bd9Sstevel@tonic-gate 	md_timeval32_t		timestamp,
6087c478bd9Sstevel@tonic-gate 	ulong_t			genid,
6097c478bd9Sstevel@tonic-gate 	md_error_t		*ep
6107c478bd9Sstevel@tonic-gate )
6117c478bd9Sstevel@tonic-gate {
6127c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
6137c478bd9Sstevel@tonic-gate 	mdrpc_drives_args	v1_args;
6147c478bd9Sstevel@tonic-gate 	mdrpc_drives_2_args	v2_args;
6157c478bd9Sstevel@tonic-gate 	mdrpc_drives_2_args_r1	*v21_args;
6167c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
6177c478bd9Sstevel@tonic-gate 	int			rval;
6187c478bd9Sstevel@tonic-gate 	int			version;
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 	/* initialize */
6217c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
6227c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
6237c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
6247c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	/* build args */
6277c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
6287c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_drives_2_args_u.rev1;
6297c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
6307c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
6317c478bd9Sstevel@tonic-gate 	v21_args->drivedescs = dd;
6327c478bd9Sstevel@tonic-gate 	v21_args->timestamp = timestamp;
6337c478bd9Sstevel@tonic-gate 	v21_args->genid = genid;
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	/* do it */
6367c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
6377c478bd9Sstevel@tonic-gate 		int	bool;
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 		/*
6407c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
6417c478bd9Sstevel@tonic-gate 		 */
6427c478bd9Sstevel@tonic-gate 		bool = mdrpc_adddrvs_2_svc(&v2_args, &res, NULL);
6437c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
6447c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
6457c478bd9Sstevel@tonic-gate 	} else {
6467c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
6477c478bd9Sstevel@tonic-gate 			return (-1);
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 		/*
6507c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
6517c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
6527c478bd9Sstevel@tonic-gate 		 * remote procedure
6537c478bd9Sstevel@tonic-gate 		 */
6547c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 			alloc_olddrvdesc(&v1_args.drivedescs, dd);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 			/* build args */
6617c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
6627c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
6637c478bd9Sstevel@tonic-gate 			meta_conv_drvdesc_new2old(v1_args.drivedescs, dd);
6647c478bd9Sstevel@tonic-gate 			v1_args.timestamp = timestamp;
6657c478bd9Sstevel@tonic-gate 			v1_args.genid = genid;
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 			rval = mdrpc_adddrvs_1(&v1_args, &res, clntp);
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 			free_olddrvdesc(v1_args.drivedescs);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
6727c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
6737c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad add drives"));
6747c478bd9Sstevel@tonic-gate 			else
6757c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
6767c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
6777c478bd9Sstevel@tonic-gate 			rval = mdrpc_adddrvs_2(&v2_args, &res, clntp);
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
6807c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
6817c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad add drives"));
6827c478bd9Sstevel@tonic-gate 			else
6837c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
6847c478bd9Sstevel@tonic-gate 		}
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
6877c478bd9Sstevel@tonic-gate 	}
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
6927c478bd9Sstevel@tonic-gate 		return (-1);
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 	return (0);
6957c478bd9Sstevel@tonic-gate }
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate /*
6987c478bd9Sstevel@tonic-gate  * Add hosts to disksets.
6997c478bd9Sstevel@tonic-gate  */
7007c478bd9Sstevel@tonic-gate int
clnt_addhosts(char * hostname,mdsetname_t * sp,int node_c,char ** node_v,md_error_t * ep)7017c478bd9Sstevel@tonic-gate clnt_addhosts(
7027c478bd9Sstevel@tonic-gate 	char			*hostname,
7037c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
7047c478bd9Sstevel@tonic-gate 	int			node_c,
7057c478bd9Sstevel@tonic-gate 	char			**node_v,
7067c478bd9Sstevel@tonic-gate 	md_error_t		*ep
7077c478bd9Sstevel@tonic-gate )
7087c478bd9Sstevel@tonic-gate {
7097c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
7107c478bd9Sstevel@tonic-gate 	mdrpc_host_args		*args;
7117c478bd9Sstevel@tonic-gate 	mdrpc_host_2_args	v2_args;
7127c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
7137c478bd9Sstevel@tonic-gate 	int			version;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 	/* initialize */
7167c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
7177c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
7187c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate 	/* build args */
7217c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
7227c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_host_2_args_u.rev1;
7237c478bd9Sstevel@tonic-gate 	args->sp = sp;
7247c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
7257c478bd9Sstevel@tonic-gate 	args->hosts.hosts_len = node_c;
7267c478bd9Sstevel@tonic-gate 	args->hosts.hosts_val = node_v;
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 	/* do it */
7297c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
7307c478bd9Sstevel@tonic-gate 		int bool;
7317c478bd9Sstevel@tonic-gate 		bool = mdrpc_addhosts_2_svc(&v2_args, &res, NULL);
7327c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
7337c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
7347c478bd9Sstevel@tonic-gate 	} else {
7357c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
7367c478bd9Sstevel@tonic-gate 			return (-1);
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 		/*
7397c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version and invoke
7407c478bd9Sstevel@tonic-gate 		 * the appropriate version of the remote procedure
7417c478bd9Sstevel@tonic-gate 		 */
7427c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
7457c478bd9Sstevel@tonic-gate 			if (mdrpc_addhosts_1(args, &res, clntp) != RPC_SUCCESS)
7467c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
7477c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad add hosts"));
7487c478bd9Sstevel@tonic-gate 			else
7497c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
7507c478bd9Sstevel@tonic-gate 		} else {
7517c478bd9Sstevel@tonic-gate 			if (mdrpc_addhosts_2(&v2_args, &res, clntp) !=
7527c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
7537c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
7547c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad add hosts"));
7557c478bd9Sstevel@tonic-gate 			else
7567c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
7577c478bd9Sstevel@tonic-gate 		}
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
7607c478bd9Sstevel@tonic-gate 	}
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
7657c478bd9Sstevel@tonic-gate 		return (-1);
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 	return (0);
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate /*
7717c478bd9Sstevel@tonic-gate  * Create disksets.
7727c478bd9Sstevel@tonic-gate  */
7737c478bd9Sstevel@tonic-gate int
clnt_createset(char * hostname,mdsetname_t * sp,md_node_nm_arr_t nodes,md_timeval32_t timestamp,ulong_t genid,md_error_t * ep)7747c478bd9Sstevel@tonic-gate clnt_createset(
7757c478bd9Sstevel@tonic-gate 	char			*hostname,
7767c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
7777c478bd9Sstevel@tonic-gate 	md_node_nm_arr_t	nodes,
7787c478bd9Sstevel@tonic-gate 	md_timeval32_t		timestamp,
7797c478bd9Sstevel@tonic-gate 	ulong_t			genid,
7807c478bd9Sstevel@tonic-gate 	md_error_t		*ep
7817c478bd9Sstevel@tonic-gate )
7827c478bd9Sstevel@tonic-gate {
7837c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
7847c478bd9Sstevel@tonic-gate 	mdrpc_createset_args	*args;
7857c478bd9Sstevel@tonic-gate 	mdrpc_createset_2_args	v2_args;
7867c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
7877c478bd9Sstevel@tonic-gate 	int			i;
7887c478bd9Sstevel@tonic-gate 	int			version;
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 	/* initialize */
7917c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
7927c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
7937c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 	/* build args */
7967c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
7977c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_createset_2_args_u.rev1;
7987c478bd9Sstevel@tonic-gate 	args->sp = sp;
7997c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
8007c478bd9Sstevel@tonic-gate 	args->timestamp = timestamp;
8017c478bd9Sstevel@tonic-gate 	args->genid = genid;
8027c478bd9Sstevel@tonic-gate 	for (i = 0; i < MD_MAXSIDES; i++)
8037c478bd9Sstevel@tonic-gate 		(void) strcpy(args->nodes[i], nodes[i]);
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate 	/* do it */
8067c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
8077c478bd9Sstevel@tonic-gate 		int	bool;
8087c478bd9Sstevel@tonic-gate 		bool = mdrpc_createset_2_svc(&v2_args, &res, NULL);
8097c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
8107c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
8117c478bd9Sstevel@tonic-gate 	} else {
8127c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
8137c478bd9Sstevel@tonic-gate 			return (-1);
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 		/*
8167c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version and invoke
8177c478bd9Sstevel@tonic-gate 		 * the appropriate version of the remote procedure
8187c478bd9Sstevel@tonic-gate 		 */
8197c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
8227c478bd9Sstevel@tonic-gate 			if (mdrpc_createset_1(args, &res, clntp) !=
8237c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
8247c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
8257c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad create set"));
8267c478bd9Sstevel@tonic-gate 			else
8277c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
8287c478bd9Sstevel@tonic-gate 		} else {
8297c478bd9Sstevel@tonic-gate 			if (mdrpc_createset_2(&v2_args, &res, clntp) !=
8307c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
8317c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
8327c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad create set"));
8337c478bd9Sstevel@tonic-gate 			else
8347c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
8357c478bd9Sstevel@tonic-gate 		}
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
8387c478bd9Sstevel@tonic-gate 	}
8397c478bd9Sstevel@tonic-gate 
8407c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
8437c478bd9Sstevel@tonic-gate 		return (-1);
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 	return (0);
8467c478bd9Sstevel@tonic-gate }
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate /*
8497c478bd9Sstevel@tonic-gate  * Create MN disksets.
8507c478bd9Sstevel@tonic-gate  */
8517c478bd9Sstevel@tonic-gate int
clnt_mncreateset(char * hostname,mdsetname_t * sp,md_mnnode_desc * nodelist,md_timeval32_t timestamp,ulong_t genid,md_node_nm_t master_nodenm,int master_nodeid,md_error_t * ep)8527c478bd9Sstevel@tonic-gate clnt_mncreateset(
8537c478bd9Sstevel@tonic-gate 	char			*hostname,
8547c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
8557c478bd9Sstevel@tonic-gate 	md_mnnode_desc		*nodelist,
8567c478bd9Sstevel@tonic-gate 	md_timeval32_t		timestamp,
8577c478bd9Sstevel@tonic-gate 	ulong_t			genid,
8587c478bd9Sstevel@tonic-gate 	md_node_nm_t		master_nodenm,
8597c478bd9Sstevel@tonic-gate 	int			master_nodeid,
8607c478bd9Sstevel@tonic-gate 	md_error_t		*ep
8617c478bd9Sstevel@tonic-gate )
8627c478bd9Sstevel@tonic-gate {
8637c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
8647c478bd9Sstevel@tonic-gate 	mdrpc_mncreateset_args	*args;
8657c478bd9Sstevel@tonic-gate 	mdrpc_mncreateset_2_args v2_args;
8667c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
8677c478bd9Sstevel@tonic-gate 	int			version;
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate 	/* initialize */
8707c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
8717c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
8727c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 	/* build args */
8757c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
8767c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_mncreateset_2_args_u.rev1;
8777c478bd9Sstevel@tonic-gate 	args->sp = sp;
8787c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
8797c478bd9Sstevel@tonic-gate 	args->timestamp = timestamp;
8807c478bd9Sstevel@tonic-gate 	args->genid = genid;
8817c478bd9Sstevel@tonic-gate 	(void) strlcpy(args->master_nodenm, master_nodenm, MD_MAX_NODENAME);
8827c478bd9Sstevel@tonic-gate 	args->master_nodeid = master_nodeid;
8837c478bd9Sstevel@tonic-gate 	args->nodelist = nodelist;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 	/* do it */
8867c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
8877c478bd9Sstevel@tonic-gate 		int	bool;
8887c478bd9Sstevel@tonic-gate 		bool = mdrpc_mncreateset_2_svc(&v2_args, &res, NULL);
8897c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
8907c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
8917c478bd9Sstevel@tonic-gate 	} else {
8927c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
8937c478bd9Sstevel@tonic-gate 			return (-1);
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 		/*
8967c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
8977c478bd9Sstevel@tonic-gate 		 */
8987c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate 		/*
9017c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
9027c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
9037c478bd9Sstevel@tonic-gate 		 */
9047c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
9057c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
9067c478bd9Sstevel@tonic-gate 			    sp->setno, hostname, NULL, sp->setname);
9077c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
9087c478bd9Sstevel@tonic-gate 			return (-1);
9097c478bd9Sstevel@tonic-gate 		} else {
9107c478bd9Sstevel@tonic-gate 			if (mdrpc_mncreateset_2(&v2_args, &res, clntp)
9117c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
9127c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
9137c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad mncreate set"));
9147c478bd9Sstevel@tonic-gate 			else
9157c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
9167c478bd9Sstevel@tonic-gate 		}
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
9197c478bd9Sstevel@tonic-gate 	}
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
9247c478bd9Sstevel@tonic-gate 		return (-1);
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 	return (0);
9277c478bd9Sstevel@tonic-gate }
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate /*
9307c478bd9Sstevel@tonic-gate  * Join MN set
9317c478bd9Sstevel@tonic-gate  */
9327c478bd9Sstevel@tonic-gate int
clnt_joinset(char * hostname,mdsetname_t * sp,int flags,md_error_t * ep)9337c478bd9Sstevel@tonic-gate clnt_joinset(
9347c478bd9Sstevel@tonic-gate 	char			*hostname,
9357c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
9367c478bd9Sstevel@tonic-gate 	int			flags,
9377c478bd9Sstevel@tonic-gate 	md_error_t		*ep
9387c478bd9Sstevel@tonic-gate )
9397c478bd9Sstevel@tonic-gate {
9407c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
9417c478bd9Sstevel@tonic-gate 	mdrpc_sp_flags_args	*args;
9427c478bd9Sstevel@tonic-gate 	mdrpc_sp_flags_2_args	v2_args;
9437c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
9447c478bd9Sstevel@tonic-gate 	int			version;
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate 	/* initialize */
9477c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
9487c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
9497c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	/* build args */
9527c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
9537c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_flags_2_args_u.rev1;
9547c478bd9Sstevel@tonic-gate 	args->sp = sp;
9557c478bd9Sstevel@tonic-gate 	args->flags = flags;
9567c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	/* do it */
9597c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
9607c478bd9Sstevel@tonic-gate 		int	bool;
9617c478bd9Sstevel@tonic-gate 		bool = mdrpc_joinset_2_svc(&v2_args, &res, NULL);
9627c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
9637c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
9647c478bd9Sstevel@tonic-gate 	} else {
9657c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
9667c478bd9Sstevel@tonic-gate 			return (-1);
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 		/*
9697c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
9707c478bd9Sstevel@tonic-gate 		 */
9717c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 		/*
9747c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
9757c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
9767c478bd9Sstevel@tonic-gate 		 */
9777c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
9787c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
9797c478bd9Sstevel@tonic-gate 			    sp->setno, hostname, NULL, sp->setname);
9807c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
9817c478bd9Sstevel@tonic-gate 			return (-1);
9827c478bd9Sstevel@tonic-gate 		} else {
9837c478bd9Sstevel@tonic-gate 			if (mdrpc_joinset_2(&v2_args, &res, clntp)
9847c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
9857c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
9867c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad join set"));
9877c478bd9Sstevel@tonic-gate 			else
9887c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
9897c478bd9Sstevel@tonic-gate 		}
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
9927c478bd9Sstevel@tonic-gate 	}
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
9977c478bd9Sstevel@tonic-gate 		return (-1);
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate 	return (0);
10007c478bd9Sstevel@tonic-gate }
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate /*
10037c478bd9Sstevel@tonic-gate  * Withdraw from MN set
10047c478bd9Sstevel@tonic-gate  */
10057c478bd9Sstevel@tonic-gate int
clnt_withdrawset(char * hostname,mdsetname_t * sp,md_error_t * ep)10067c478bd9Sstevel@tonic-gate clnt_withdrawset(
10077c478bd9Sstevel@tonic-gate 	char			*hostname,
10087c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
10097c478bd9Sstevel@tonic-gate 	md_error_t		*ep
10107c478bd9Sstevel@tonic-gate )
10117c478bd9Sstevel@tonic-gate {
10127c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
10137c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
10147c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
10157c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
10167c478bd9Sstevel@tonic-gate 	int			version;
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 	/* initialize */
10197c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
10207c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
10217c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	/* build args */
10247c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
10257c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
10267c478bd9Sstevel@tonic-gate 	args->sp = sp;
10277c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 	/* do it */
10307c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
10317c478bd9Sstevel@tonic-gate 		int	bool;
10327c478bd9Sstevel@tonic-gate 		bool = mdrpc_withdrawset_2_svc(&v2_args, &res, NULL);
10337c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
10347c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
10357c478bd9Sstevel@tonic-gate 	} else {
10367c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
10377c478bd9Sstevel@tonic-gate 			return (-1);
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate 		/*
10407c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
10417c478bd9Sstevel@tonic-gate 		 */
10427c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate 		/*
10457c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
10467c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
10477c478bd9Sstevel@tonic-gate 		 */
10487c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
10497c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
10507c478bd9Sstevel@tonic-gate 			    sp->setno, hostname, NULL, sp->setname);
10517c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
10527c478bd9Sstevel@tonic-gate 			return (-1);
10537c478bd9Sstevel@tonic-gate 		} else {
10547c478bd9Sstevel@tonic-gate 			if (mdrpc_withdrawset_2(&v2_args, &res, clntp)
10557c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
10567c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
10577c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
10587c478bd9Sstevel@tonic-gate 				    "metad withdraw set"));
10597c478bd9Sstevel@tonic-gate 			else
10607c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
10617c478bd9Sstevel@tonic-gate 		}
10627c478bd9Sstevel@tonic-gate 
10637c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
10647c478bd9Sstevel@tonic-gate 	}
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
10677c478bd9Sstevel@tonic-gate 
10687c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
10697c478bd9Sstevel@tonic-gate 		return (-1);
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 	return (0);
10727c478bd9Sstevel@tonic-gate }
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate /*
10757c478bd9Sstevel@tonic-gate  * Delete side names for the diskset drive records
10767c478bd9Sstevel@tonic-gate  * NOTE: these are removed from the local set's namespace.
10777c478bd9Sstevel@tonic-gate  */
10787c478bd9Sstevel@tonic-gate int
clnt_del_drv_sidenms(char * hostname,mdsetname_t * sp,md_error_t * ep)10797c478bd9Sstevel@tonic-gate clnt_del_drv_sidenms(
10807c478bd9Sstevel@tonic-gate 	char			*hostname,
10817c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
10827c478bd9Sstevel@tonic-gate 	md_error_t		*ep
10837c478bd9Sstevel@tonic-gate )
10847c478bd9Sstevel@tonic-gate {
10857c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
10867c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
10877c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
10887c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
10897c478bd9Sstevel@tonic-gate 	int			version;
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	/* initialize */
10927c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
10937c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
10947c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
10957c478bd9Sstevel@tonic-gate 
10967c478bd9Sstevel@tonic-gate 	/* build args */
10977c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
10987c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
10997c478bd9Sstevel@tonic-gate 	args->sp = sp;
11007c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate 	/* do it */
11037c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
11047c478bd9Sstevel@tonic-gate 		int	bool;
11057c478bd9Sstevel@tonic-gate 		bool = mdrpc_del_drv_sidenms_2_svc(&v2_args, &res, NULL);
11067c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
11077c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
11087c478bd9Sstevel@tonic-gate 	} else {
11097c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
11107c478bd9Sstevel@tonic-gate 			return (-1);
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 		if (metaget_setdesc(sp, ep) == NULL) {
11137c478bd9Sstevel@tonic-gate 			if (! mdisok(ep))
11147c478bd9Sstevel@tonic-gate 				return (-1);
11157c478bd9Sstevel@tonic-gate 			mdclrerror(ep);
11167c478bd9Sstevel@tonic-gate 		}
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 		/*
11197c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version and invoke
11207c478bd9Sstevel@tonic-gate 		 * the appropriate version of the remote procedure
11217c478bd9Sstevel@tonic-gate 		 */
11227c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
11237c478bd9Sstevel@tonic-gate 
11247c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
11257c478bd9Sstevel@tonic-gate 			if (mdrpc_del_drv_sidenms_1(args, &res, clntp) !=
11267c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
11277c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
11287c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
11297c478bd9Sstevel@tonic-gate 				    "metad delete drive sidenames"));
11307c478bd9Sstevel@tonic-gate 			else
11317c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
11327c478bd9Sstevel@tonic-gate 		} else {
11337c478bd9Sstevel@tonic-gate 			if (mdrpc_del_drv_sidenms_2(&v2_args, &res, clntp) !=
11347c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
11357c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
11367c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
11377c478bd9Sstevel@tonic-gate 				    "metad delete drive sidenames"));
11387c478bd9Sstevel@tonic-gate 			else
11397c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
11407c478bd9Sstevel@tonic-gate 		}
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
11437c478bd9Sstevel@tonic-gate 	}
11447c478bd9Sstevel@tonic-gate 
11457c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
11467c478bd9Sstevel@tonic-gate 
11477c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
11487c478bd9Sstevel@tonic-gate 		return (-1);
11497c478bd9Sstevel@tonic-gate 
11507c478bd9Sstevel@tonic-gate 	return (0);
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate /*
11547c478bd9Sstevel@tonic-gate  * delete drives from the set
11557c478bd9Sstevel@tonic-gate  */
11567c478bd9Sstevel@tonic-gate int
clnt_deldrvs(char * hostname,mdsetname_t * sp,md_drive_desc * dd,md_error_t * ep)11577c478bd9Sstevel@tonic-gate clnt_deldrvs(
11587c478bd9Sstevel@tonic-gate 	char			*hostname,
11597c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
11607c478bd9Sstevel@tonic-gate 	md_drive_desc		*dd,
11617c478bd9Sstevel@tonic-gate 	md_error_t		*ep
11627c478bd9Sstevel@tonic-gate )
11637c478bd9Sstevel@tonic-gate {
11647c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
11657c478bd9Sstevel@tonic-gate 	mdrpc_drives_args	v1_args;
11667c478bd9Sstevel@tonic-gate 	mdrpc_drives_2_args	v2_args;
11677c478bd9Sstevel@tonic-gate 	mdrpc_drives_2_args_r1	*v21_args;
11687c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
11697c478bd9Sstevel@tonic-gate 	int			rval;
11707c478bd9Sstevel@tonic-gate 	int			version;
11717c478bd9Sstevel@tonic-gate 
11727c478bd9Sstevel@tonic-gate 	/* initialize */
11737c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
11747c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
11757c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
11767c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate 	/* build args */
11797c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
11807c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_drives_2_args_u.rev1;
11817c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
11827c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
11837c478bd9Sstevel@tonic-gate 	v21_args->drivedescs = dd;
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 	/* do it */
11867c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
11877c478bd9Sstevel@tonic-gate 		int	bool;
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 		/*
11907c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
11917c478bd9Sstevel@tonic-gate 		 */
11927c478bd9Sstevel@tonic-gate 		bool = mdrpc_deldrvs_2_svc(&v2_args, &res, NULL);
11937c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
11947c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
11957c478bd9Sstevel@tonic-gate 	} else {
11967c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
11977c478bd9Sstevel@tonic-gate 			return (-1);
11987c478bd9Sstevel@tonic-gate 
11997c478bd9Sstevel@tonic-gate 		/*
12007c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
12017c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
12027c478bd9Sstevel@tonic-gate 		 * remote procedure
12037c478bd9Sstevel@tonic-gate 		 */
12047c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
12057c478bd9Sstevel@tonic-gate 
12067c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
12077c478bd9Sstevel@tonic-gate 
12087c478bd9Sstevel@tonic-gate 			alloc_olddrvdesc(&v1_args.drivedescs, dd);
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 			/* build args */
12117c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
12127c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
12137c478bd9Sstevel@tonic-gate 			meta_conv_drvdesc_new2old(v1_args.drivedescs, dd);
12147c478bd9Sstevel@tonic-gate 
12157c478bd9Sstevel@tonic-gate 			rval = mdrpc_deldrvs_1(&v1_args, &res, clntp);
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 			free_olddrvdesc(v1_args.drivedescs);
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
12207c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
12217c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
12227c478bd9Sstevel@tonic-gate 				    "metad delete drives"));
12237c478bd9Sstevel@tonic-gate 			else
12247c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
12257c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
12267c478bd9Sstevel@tonic-gate 			rval = mdrpc_deldrvs_2(&v2_args, &res, clntp);
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
12297c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
12307c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
12317c478bd9Sstevel@tonic-gate 				    "metad delete drives"));
12327c478bd9Sstevel@tonic-gate 			else
12337c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
12347c478bd9Sstevel@tonic-gate 		}
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
12377c478bd9Sstevel@tonic-gate 	}
12387c478bd9Sstevel@tonic-gate 
12397c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
12427c478bd9Sstevel@tonic-gate 		return (-1);
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate 	return (0);
12457c478bd9Sstevel@tonic-gate }
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate /*
12487c478bd9Sstevel@tonic-gate  * delete host(s) from a set.
12497c478bd9Sstevel@tonic-gate  */
12507c478bd9Sstevel@tonic-gate int
clnt_delhosts(char * hostname,mdsetname_t * sp,int node_c,char ** node_v,md_error_t * ep)12517c478bd9Sstevel@tonic-gate clnt_delhosts(
12527c478bd9Sstevel@tonic-gate 	char			*hostname,
12537c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
12547c478bd9Sstevel@tonic-gate 	int			node_c,
12557c478bd9Sstevel@tonic-gate 	char			**node_v,
12567c478bd9Sstevel@tonic-gate 	md_error_t		*ep
12577c478bd9Sstevel@tonic-gate )
12587c478bd9Sstevel@tonic-gate {
12597c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
12607c478bd9Sstevel@tonic-gate 	mdrpc_host_args		*args;
12617c478bd9Sstevel@tonic-gate 	mdrpc_host_2_args	v2_args;
12627c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
12637c478bd9Sstevel@tonic-gate 	int			version;
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 	/* initialize */
12667c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
12677c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
12687c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
12697c478bd9Sstevel@tonic-gate 
12707c478bd9Sstevel@tonic-gate 	/* build args */
12717c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
12727c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_host_2_args_u.rev1;
12737c478bd9Sstevel@tonic-gate 	args->sp = sp;
12747c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
12757c478bd9Sstevel@tonic-gate 	args->hosts.hosts_len = node_c;
12767c478bd9Sstevel@tonic-gate 	args->hosts.hosts_val = node_v;
12777c478bd9Sstevel@tonic-gate 
12787c478bd9Sstevel@tonic-gate 	/* do it */
12797c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
12807c478bd9Sstevel@tonic-gate 		int	bool;
12817c478bd9Sstevel@tonic-gate 		bool = mdrpc_delhosts_2_svc(&v2_args, &res, NULL);
12827c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
12837c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
12847c478bd9Sstevel@tonic-gate 	} else {
12857c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
12867c478bd9Sstevel@tonic-gate 			return (-1);
12877c478bd9Sstevel@tonic-gate 
12887c478bd9Sstevel@tonic-gate 		/*
12897c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
12907c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
12917c478bd9Sstevel@tonic-gate 		 * remote procedure
12927c478bd9Sstevel@tonic-gate 		 */
12937c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
12967c478bd9Sstevel@tonic-gate 			if (mdrpc_delhosts_1(args, &res, clntp) != RPC_SUCCESS)
12977c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
12987c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad delete hosts"));
12997c478bd9Sstevel@tonic-gate 			else
13007c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
13017c478bd9Sstevel@tonic-gate 		} else {
13027c478bd9Sstevel@tonic-gate 			if (mdrpc_delhosts_2(&v2_args, &res, clntp) !=
13037c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
13047c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
13057c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad delete hosts"));
13067c478bd9Sstevel@tonic-gate 			else
13077c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
13087c478bd9Sstevel@tonic-gate 		}
13097c478bd9Sstevel@tonic-gate 
13107c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
13117c478bd9Sstevel@tonic-gate 	}
13127c478bd9Sstevel@tonic-gate 
13137c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
13167c478bd9Sstevel@tonic-gate 		return (-1);
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate 	return (0);
13197c478bd9Sstevel@tonic-gate }
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate /*
13227c478bd9Sstevel@tonic-gate  * Delete diskset.
13237c478bd9Sstevel@tonic-gate  */
13247c478bd9Sstevel@tonic-gate int
clnt_delset(char * hostname,mdsetname_t * sp,md_error_t * ep)13257c478bd9Sstevel@tonic-gate clnt_delset(
13267c478bd9Sstevel@tonic-gate 	char			*hostname,
13277c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
13287c478bd9Sstevel@tonic-gate 	md_error_t		*ep
13297c478bd9Sstevel@tonic-gate )
13307c478bd9Sstevel@tonic-gate {
13317c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
13327c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
13337c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
13347c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
13357c478bd9Sstevel@tonic-gate 	int			version;
13367c478bd9Sstevel@tonic-gate 
13377c478bd9Sstevel@tonic-gate 	/* initialize */
13387c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
13397c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
13407c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 	/* build args */
13437c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
13447c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
13457c478bd9Sstevel@tonic-gate 	args->sp = sp;
13467c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
13477c478bd9Sstevel@tonic-gate 
13487c478bd9Sstevel@tonic-gate 	/* do it */
13497c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
13507c478bd9Sstevel@tonic-gate 		int	bool;
13517c478bd9Sstevel@tonic-gate 		bool = mdrpc_delset_2_svc(&v2_args, &res, NULL);
13527c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
13537c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
13547c478bd9Sstevel@tonic-gate 	} else {
13557c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
13567c478bd9Sstevel@tonic-gate 			return (-1);
13577c478bd9Sstevel@tonic-gate 
13587c478bd9Sstevel@tonic-gate 		/*
13597c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
13607c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
13617c478bd9Sstevel@tonic-gate 		 * remote procedure
13627c478bd9Sstevel@tonic-gate 		 */
13637c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
13647c478bd9Sstevel@tonic-gate 
13657c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
13667c478bd9Sstevel@tonic-gate 			if (mdrpc_delset_1(args, &res, clntp) != RPC_SUCCESS)
13677c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
13687c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad delete set"));
13697c478bd9Sstevel@tonic-gate 			else
13707c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
13717c478bd9Sstevel@tonic-gate 		} else {
13727c478bd9Sstevel@tonic-gate 			if (mdrpc_delset_2(&v2_args, &res, clntp) !=
13737c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
13747c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
13757c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad delete set"));
13767c478bd9Sstevel@tonic-gate 			else
13777c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
13787c478bd9Sstevel@tonic-gate 		}
13797c478bd9Sstevel@tonic-gate 
13807c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
13817c478bd9Sstevel@tonic-gate 	}
13827c478bd9Sstevel@tonic-gate 
13837c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
13847c478bd9Sstevel@tonic-gate 
13857c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
13867c478bd9Sstevel@tonic-gate 		return (-1);
13877c478bd9Sstevel@tonic-gate 
13887c478bd9Sstevel@tonic-gate 	return (0);
13897c478bd9Sstevel@tonic-gate }
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate /*
13927c478bd9Sstevel@tonic-gate  * return remote device info
13937c478bd9Sstevel@tonic-gate  */
13947c478bd9Sstevel@tonic-gate int
clnt_devinfo(char * hostname,mdsetname_t * sp,mddrivename_t * dp,md_dev64_t * ret_dev,time_t * ret_timestamp,md_error_t * ep)13957c478bd9Sstevel@tonic-gate clnt_devinfo(
13967c478bd9Sstevel@tonic-gate 	char			*hostname,
13977c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
13987c478bd9Sstevel@tonic-gate 	mddrivename_t		*dp,
13997c478bd9Sstevel@tonic-gate 	md_dev64_t		*ret_dev,
14007c478bd9Sstevel@tonic-gate 	time_t			*ret_timestamp,
14017c478bd9Sstevel@tonic-gate 	md_error_t		*ep
14027c478bd9Sstevel@tonic-gate )
14037c478bd9Sstevel@tonic-gate {
14047c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
14057c478bd9Sstevel@tonic-gate 	mdrpc_devinfo_args	v1_args;
14067c478bd9Sstevel@tonic-gate 	mdrpc_devinfo_2_args	v2_args;
14077c478bd9Sstevel@tonic-gate 	mdrpc_devinfo_2_args_r1	*v21_args;
14087c478bd9Sstevel@tonic-gate 	mdrpc_devinfo_res	v1_res;
14097c478bd9Sstevel@tonic-gate 	mdrpc_devinfo_2_res	v2_res;
14107c478bd9Sstevel@tonic-gate 	int			rval, version;
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate 	/* initialize */
14137c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
14147c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
14157c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
14167c478bd9Sstevel@tonic-gate 	(void) memset(&v1_res,  0, sizeof (v1_res));
14177c478bd9Sstevel@tonic-gate 	(void) memset(&v2_res, 	0, sizeof (v2_res));
14187c478bd9Sstevel@tonic-gate 
14197c478bd9Sstevel@tonic-gate 	/* build args */
14207c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
14217c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_devinfo_2_args_u.rev1;
14227c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
14237c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
14247c478bd9Sstevel@tonic-gate 	v21_args->drivenamep = dp;
14257c478bd9Sstevel@tonic-gate 
14267c478bd9Sstevel@tonic-gate 	/* do it */
14277c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
14287c478bd9Sstevel@tonic-gate 		int	bool;
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate 		/*
14317c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure.
14327c478bd9Sstevel@tonic-gate 		 */
14337c478bd9Sstevel@tonic-gate 		bool = mdrpc_devinfo_2_svc(&v2_args, &v2_res, NULL);
14347c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
14357c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &v1_res.status);
14367c478bd9Sstevel@tonic-gate 	} else {
14377c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
14387c478bd9Sstevel@tonic-gate 			return (-1);
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 		/*
14417c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
14427c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of
14437c478bd9Sstevel@tonic-gate 		 * the remote procedure.
14447c478bd9Sstevel@tonic-gate 		 */
14457c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
14467c478bd9Sstevel@tonic-gate 
14477c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
14487c478bd9Sstevel@tonic-gate 			v1_args.drivenamep =
14497c478bd9Sstevel@tonic-gate 			    Zalloc(sizeof (o_mddrivename_t));
14507c478bd9Sstevel@tonic-gate 			v1_args.drivenamep->parts.parts_val =
14517c478bd9Sstevel@tonic-gate 			    Zalloc((sizeof (o_mdname_t)) *
14527c478bd9Sstevel@tonic-gate 			    dp->parts.parts_len);
14537c478bd9Sstevel@tonic-gate 
14547c478bd9Sstevel@tonic-gate 			/* build args */
14557c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
14567c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno,
14577c478bd9Sstevel@tonic-gate 			    sp->setname);
14587c478bd9Sstevel@tonic-gate 
14597c478bd9Sstevel@tonic-gate 			/*
14607c478bd9Sstevel@tonic-gate 			 * Convert v2 arguments to v1 arguments
14617c478bd9Sstevel@tonic-gate 			 * before sending over the wire.
14627c478bd9Sstevel@tonic-gate 			 */
14637c478bd9Sstevel@tonic-gate 			meta_conv_drvname_new2old(v1_args.drivenamep,
14647c478bd9Sstevel@tonic-gate 			    v21_args->drivenamep);
14657c478bd9Sstevel@tonic-gate 
14667c478bd9Sstevel@tonic-gate 			rval = mdrpc_devinfo_1(&v1_args, &v1_res, clntp);
14677c478bd9Sstevel@tonic-gate 
14687c478bd9Sstevel@tonic-gate 			free(v1_args.drivenamep->parts.parts_val);
14697c478bd9Sstevel@tonic-gate 			free(v1_args.drivenamep);
14707c478bd9Sstevel@tonic-gate 
14717c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
14727c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
14737c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad device info"));
14747c478bd9Sstevel@tonic-gate 			else
14757c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &v1_res.status);
14767c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
14777c478bd9Sstevel@tonic-gate 			rval = mdrpc_devinfo_2(&v2_args, &v2_res, clntp);
14787c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
14797c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
14807c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad device info"));
14817c478bd9Sstevel@tonic-gate 			else
14827c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &v2_res.status);
14837c478bd9Sstevel@tonic-gate 		}
14847c478bd9Sstevel@tonic-gate 
14857c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
14867c478bd9Sstevel@tonic-gate 	}
14877c478bd9Sstevel@tonic-gate 
14887c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
14897c478bd9Sstevel@tonic-gate 		/* do something with the results */
14907c478bd9Sstevel@tonic-gate 		rval = 0;
14917c478bd9Sstevel@tonic-gate 
14927c478bd9Sstevel@tonic-gate 		if (ret_dev != NULL) {
14937c478bd9Sstevel@tonic-gate 			if (version == METAD_VERSION)
14947c478bd9Sstevel@tonic-gate 				*ret_dev = meta_expldev(v1_res.dev);
14957c478bd9Sstevel@tonic-gate 			else
14967c478bd9Sstevel@tonic-gate 				*ret_dev = v2_res.dev;
14977c478bd9Sstevel@tonic-gate 		}
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate 		if (ret_timestamp != NULL) {
15007c478bd9Sstevel@tonic-gate 			if (version == METAD_VERSION)
15017c478bd9Sstevel@tonic-gate 				*ret_timestamp = v1_res.vtime;
15027c478bd9Sstevel@tonic-gate 			else
15037c478bd9Sstevel@tonic-gate 				*ret_timestamp = v2_res.vtime;
15047c478bd9Sstevel@tonic-gate 		}
15057c478bd9Sstevel@tonic-gate 	}
15067c478bd9Sstevel@tonic-gate 
15077c478bd9Sstevel@tonic-gate 	if (version == METAD_VERSION)
15087c478bd9Sstevel@tonic-gate 		xdr_free(xdr_mdrpc_devinfo_res, (char *)&v1_res);
15097c478bd9Sstevel@tonic-gate 	else
15107c478bd9Sstevel@tonic-gate 		xdr_free(xdr_mdrpc_devinfo_2_res, (char *)&v2_res);
15117c478bd9Sstevel@tonic-gate 
15127c478bd9Sstevel@tonic-gate 	return (rval);
15137c478bd9Sstevel@tonic-gate }
15147c478bd9Sstevel@tonic-gate 
15157c478bd9Sstevel@tonic-gate /*
15167c478bd9Sstevel@tonic-gate  * return remote device info
15177c478bd9Sstevel@tonic-gate  */
15187c478bd9Sstevel@tonic-gate int
clnt_devid(char * hostname,mdsetname_t * sp,mddrivename_t * dp,char ** ret_encdevid,md_error_t * ep)15197c478bd9Sstevel@tonic-gate clnt_devid(
15207c478bd9Sstevel@tonic-gate 	char			*hostname,
15217c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
15227c478bd9Sstevel@tonic-gate 	mddrivename_t		*dp,
15237c478bd9Sstevel@tonic-gate 	char			**ret_encdevid,
15247c478bd9Sstevel@tonic-gate 	md_error_t		*ep
15257c478bd9Sstevel@tonic-gate )
15267c478bd9Sstevel@tonic-gate {
15277c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
15287c478bd9Sstevel@tonic-gate 	mdrpc_devid_args	*args;
15297c478bd9Sstevel@tonic-gate 	mdrpc_devid_2_args	v2_args;
15307c478bd9Sstevel@tonic-gate 	mdrpc_devid_res		res;
15317c478bd9Sstevel@tonic-gate 	int			rval;
15327c478bd9Sstevel@tonic-gate 	int			version;
15337c478bd9Sstevel@tonic-gate 
15347c478bd9Sstevel@tonic-gate 	/* initialize */
15357c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
15367c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
15377c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
15387c478bd9Sstevel@tonic-gate 
15397c478bd9Sstevel@tonic-gate 	/* build args */
15407c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
15417c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_devid_2_args_u.rev1;
15427c478bd9Sstevel@tonic-gate 	args->sp = sp;
15437c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
15447c478bd9Sstevel@tonic-gate 	args->drivenamep = dp;
15457c478bd9Sstevel@tonic-gate 
15467c478bd9Sstevel@tonic-gate 	/* do it */
15477c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
15487c478bd9Sstevel@tonic-gate 		int	bool;
15497c478bd9Sstevel@tonic-gate 
15507c478bd9Sstevel@tonic-gate 		/*
15517c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure.
15527c478bd9Sstevel@tonic-gate 		 */
15537c478bd9Sstevel@tonic-gate 		bool = mdrpc_devid_2_svc(&v2_args, &res, NULL);
15547c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
15557c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
15567c478bd9Sstevel@tonic-gate 	} else {
15577c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
15587c478bd9Sstevel@tonic-gate 			return (-1);
15597c478bd9Sstevel@tonic-gate 
15607c478bd9Sstevel@tonic-gate 		/*
15617c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
15627c478bd9Sstevel@tonic-gate 		 */
15637c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate 		/*
15667c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
15677c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
15687c478bd9Sstevel@tonic-gate 		 */
15697c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
15707c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_DRIVENOTONHOST, sp->setno,
15717c478bd9Sstevel@tonic-gate 			    hostname, dp->cname, sp->setname);
15727c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
15737c478bd9Sstevel@tonic-gate 			rval = mdrpc_devid_2(&v2_args, &res, clntp);
15747c478bd9Sstevel@tonic-gate 
15757c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
15767c478bd9Sstevel@tonic-gate 			    (void) mdrpcerror(ep, clntp, hostname,
15777c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad devid info"));
15787c478bd9Sstevel@tonic-gate 			else
15797c478bd9Sstevel@tonic-gate 			    (void) mdstealerror(ep, &res.status);
15807c478bd9Sstevel@tonic-gate 		}
15817c478bd9Sstevel@tonic-gate 
15827c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
15837c478bd9Sstevel@tonic-gate 	}
15847c478bd9Sstevel@tonic-gate 
15857c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
15867c478bd9Sstevel@tonic-gate 		/* do something with the results */
15877c478bd9Sstevel@tonic-gate 		rval = 0;
15887c478bd9Sstevel@tonic-gate 
15897c478bd9Sstevel@tonic-gate 		if (ret_encdevid != NULL)
15907c478bd9Sstevel@tonic-gate 			*ret_encdevid = strdup(res.enc_devid);
15917c478bd9Sstevel@tonic-gate 
15927c478bd9Sstevel@tonic-gate 	}
15937c478bd9Sstevel@tonic-gate 
15947c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_devid_res, (char *)&res);
15957c478bd9Sstevel@tonic-gate 
15967c478bd9Sstevel@tonic-gate 	return (rval);
15977c478bd9Sstevel@tonic-gate }
15987c478bd9Sstevel@tonic-gate 
15997c478bd9Sstevel@tonic-gate /*
16007c478bd9Sstevel@tonic-gate  * Get the device information of a disk on a remote host. The information
16017c478bd9Sstevel@tonic-gate  * retrieved is the device's name, the associated driver and the dev_t.
16027c478bd9Sstevel@tonic-gate  * The lookup is performed by using the devid of the disk as this is
16037c478bd9Sstevel@tonic-gate  * unique to the disk.  The device name on the originating node is passed
16047c478bd9Sstevel@tonic-gate  * in.  If that devname is found when doing the devid to namelist translation
16057c478bd9Sstevel@tonic-gate  * then that value is used to make the device names as consistent as possible
16067c478bd9Sstevel@tonic-gate  * across the nodes.
16077c478bd9Sstevel@tonic-gate  *
16087c478bd9Sstevel@tonic-gate  * An attempt is made to retrieve this information by calling
16097c478bd9Sstevel@tonic-gate  * mdrpc_devinfo_by_devid_name_2_svc.  Locally this call should always
16107c478bd9Sstevel@tonic-gate  * succeed.  In the case where a call is made through a CLIENT handle,
16117c478bd9Sstevel@tonic-gate  * it is possible that the function hasn't been implemented on the called
16127c478bd9Sstevel@tonic-gate  * node.  If this is the case fall back to mdrpc_devinfo_by_devidstr_2_svc.
16137c478bd9Sstevel@tonic-gate  *
16147c478bd9Sstevel@tonic-gate  * Returns:
16157c478bd9Sstevel@tonic-gate  * 	-1 	Error
16167c478bd9Sstevel@tonic-gate  * 	ENOTSUP Operation not supported i.e. procedure not supported on
16177c478bd9Sstevel@tonic-gate  * 		the remote node
16187c478bd9Sstevel@tonic-gate  * 	0	Success
16197c478bd9Sstevel@tonic-gate  */
16207c478bd9Sstevel@tonic-gate int
clnt_devinfo_by_devid(char * hostname,mdsetname_t * sp,char * devidstr,md_dev64_t * ret_dev,char * orig_devname,char ** ret_devname,char ** ret_driver,md_error_t * ep)16217c478bd9Sstevel@tonic-gate clnt_devinfo_by_devid(
16227c478bd9Sstevel@tonic-gate 	char		*hostname,
16237c478bd9Sstevel@tonic-gate 	mdsetname_t	*sp,
16247c478bd9Sstevel@tonic-gate 	char		*devidstr,
16257c478bd9Sstevel@tonic-gate 	md_dev64_t	*ret_dev,
16267c478bd9Sstevel@tonic-gate 	char		*orig_devname,
16277c478bd9Sstevel@tonic-gate 	char		**ret_devname,
16287c478bd9Sstevel@tonic-gate 	char		**ret_driver,
16297c478bd9Sstevel@tonic-gate 	md_error_t	*ep
16307c478bd9Sstevel@tonic-gate )
16317c478bd9Sstevel@tonic-gate {
16327c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
16337c478bd9Sstevel@tonic-gate 	mdrpc_devidstr_args	devid_args;
16347c478bd9Sstevel@tonic-gate 	mdrpc_devid_name_args	*args;
16357c478bd9Sstevel@tonic-gate 	mdrpc_devid_name_2_args	v2_args;
16367c478bd9Sstevel@tonic-gate 	mdrpc_devinfo_2_res	res;
16377c478bd9Sstevel@tonic-gate 	int			rval;
16387c478bd9Sstevel@tonic-gate 	int			version;
16397c478bd9Sstevel@tonic-gate 
16407c478bd9Sstevel@tonic-gate 	/* initialize */
16417c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
16427c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
16437c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
16447c478bd9Sstevel@tonic-gate 
16457c478bd9Sstevel@tonic-gate 	/* build args */
16467c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
16477c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_devid_name_2_args_u.rev1;
16487c478bd9Sstevel@tonic-gate 	args->enc_devid = devidstr;
16497c478bd9Sstevel@tonic-gate 	args->orig_devname = orig_devname;
16507c478bd9Sstevel@tonic-gate 	args->sp = sp;
16517c478bd9Sstevel@tonic-gate 
16527c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
16537c478bd9Sstevel@tonic-gate 		int	bool;
16547c478bd9Sstevel@tonic-gate 
16557c478bd9Sstevel@tonic-gate 		/*
16567c478bd9Sstevel@tonic-gate 		 * We are calling this locally so call the function
16577c478bd9Sstevel@tonic-gate 		 * directly.
16587c478bd9Sstevel@tonic-gate 		 */
16597c478bd9Sstevel@tonic-gate 		bool = mdrpc_devinfo_by_devid_name_2_svc(&v2_args, &res, NULL);
16607c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
16617c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
16627c478bd9Sstevel@tonic-gate 	} else {
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 		/* open connection */
16657c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL) {
16667c478bd9Sstevel@tonic-gate 			return (-1);
16677c478bd9Sstevel@tonic-gate 		}
16687c478bd9Sstevel@tonic-gate 
16697c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
16707c478bd9Sstevel@tonic-gate 
16717c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* Version 1 */
16727c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
16737c478bd9Sstevel@tonic-gate 			return (ENOTSUP);
16747c478bd9Sstevel@tonic-gate 		}
16757c478bd9Sstevel@tonic-gate 
16767c478bd9Sstevel@tonic-gate 		rval = mdrpc_devinfo_by_devid_name_2(&v2_args, &res, clntp);
16777c478bd9Sstevel@tonic-gate 
16787c478bd9Sstevel@tonic-gate 		if (rval != RPC_SUCCESS) {
16797c478bd9Sstevel@tonic-gate 			/* try falling back to devidstr_2_svc */
16807c478bd9Sstevel@tonic-gate 			(void) memset(&devid_args, 0, sizeof (devid_args));
16817c478bd9Sstevel@tonic-gate 			(void) memset(&res, 0, sizeof (res));
16827c478bd9Sstevel@tonic-gate 
16837c478bd9Sstevel@tonic-gate 			devid_args.enc_devid = devidstr;
16847c478bd9Sstevel@tonic-gate 			devid_args.sp = sp;
16857c478bd9Sstevel@tonic-gate 
16867c478bd9Sstevel@tonic-gate 			rval = mdrpc_devinfo_by_devid_2(
16877c478bd9Sstevel@tonic-gate 					&devid_args, &res, clntp);
16887c478bd9Sstevel@tonic-gate 
16897c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS) {
16907c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
16917c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
16927c478bd9Sstevel@tonic-gate 				    "metad devinfo by devid"));
16937c478bd9Sstevel@tonic-gate 			} else {
16947c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
16957c478bd9Sstevel@tonic-gate 			}
16967c478bd9Sstevel@tonic-gate 		} else {
16977c478bd9Sstevel@tonic-gate 			(void) mdstealerror(ep, &res.status);
16987c478bd9Sstevel@tonic-gate 		}
16997c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
17007c478bd9Sstevel@tonic-gate 	}
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
17037c478bd9Sstevel@tonic-gate 		rval = 0;
17047c478bd9Sstevel@tonic-gate 		if (ret_dev != NULL)
17057c478bd9Sstevel@tonic-gate 			*ret_dev = res.dev;
17067c478bd9Sstevel@tonic-gate 
17077c478bd9Sstevel@tonic-gate 		if (ret_devname != NULL && res.devname != NULL)
17087c478bd9Sstevel@tonic-gate 			*ret_devname = Strdup(res.devname);
17097c478bd9Sstevel@tonic-gate 
17107c478bd9Sstevel@tonic-gate 		if (ret_driver != NULL && res.drivername != NULL)
17117c478bd9Sstevel@tonic-gate 			*ret_driver = Strdup(res.drivername);
17127c478bd9Sstevel@tonic-gate 	}
17137c478bd9Sstevel@tonic-gate 
17147c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_devinfo_2_res, (char *)&res);
17157c478bd9Sstevel@tonic-gate 
17167c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
17177c478bd9Sstevel@tonic-gate 		return (-1);
17187c478bd9Sstevel@tonic-gate 
17197c478bd9Sstevel@tonic-gate 	return (0);
17207c478bd9Sstevel@tonic-gate 
17217c478bd9Sstevel@tonic-gate }
17227c478bd9Sstevel@tonic-gate 
17237c478bd9Sstevel@tonic-gate 
17247c478bd9Sstevel@tonic-gate /*
17257c478bd9Sstevel@tonic-gate  * return status of whether driver is used, mount
17267c478bd9Sstevel@tonic-gate  */
17277c478bd9Sstevel@tonic-gate int
clnt_drvused(char * hostname,mdsetname_t * sp,mddrivename_t * dp,md_error_t * ep)17287c478bd9Sstevel@tonic-gate clnt_drvused(
17297c478bd9Sstevel@tonic-gate 	char			*hostname,
17307c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
17317c478bd9Sstevel@tonic-gate 	mddrivename_t		*dp,
17327c478bd9Sstevel@tonic-gate 	md_error_t		*ep
17337c478bd9Sstevel@tonic-gate )
17347c478bd9Sstevel@tonic-gate {
17357c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
17367c478bd9Sstevel@tonic-gate 	mdrpc_drvused_args	v1_args;
17377c478bd9Sstevel@tonic-gate 	mdrpc_drvused_2_args	v2_args;
17387c478bd9Sstevel@tonic-gate 	mdrpc_drvused_2_args_r1	*v21_args;
17397c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
17407c478bd9Sstevel@tonic-gate 	int			rval;
17417c478bd9Sstevel@tonic-gate 	int			version;
17427c478bd9Sstevel@tonic-gate 
17437c478bd9Sstevel@tonic-gate 	/* initialize */
17447c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
17457c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
17467c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
17477c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
17487c478bd9Sstevel@tonic-gate 
17497c478bd9Sstevel@tonic-gate 	/* build args */
17507c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
17517c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_drvused_2_args_u.rev1;
17527c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
17537c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
17547c478bd9Sstevel@tonic-gate 	v21_args->drivenamep = dp;
17557c478bd9Sstevel@tonic-gate 
17567c478bd9Sstevel@tonic-gate 	/* do it */
17577c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
17587c478bd9Sstevel@tonic-gate 		int	bool;
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate 		/*
17617c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
17627c478bd9Sstevel@tonic-gate 		 */
17637c478bd9Sstevel@tonic-gate 		bool = mdrpc_drvused_2_svc(&v2_args, &res, NULL);
17647c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
17657c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
17667c478bd9Sstevel@tonic-gate 	} else {
17677c478bd9Sstevel@tonic-gate 		/* open connection */
17687c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
17697c478bd9Sstevel@tonic-gate 			return (-1);
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate 		/*
17727c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
17737c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
17747c478bd9Sstevel@tonic-gate 		 * remote procedure
17757c478bd9Sstevel@tonic-gate 		 */
17767c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
17777c478bd9Sstevel@tonic-gate 
17787c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
17797c478bd9Sstevel@tonic-gate 			v1_args.drivenamep =
17807c478bd9Sstevel@tonic-gate 			    Zalloc(sizeof (o_mddrivename_t));
17817c478bd9Sstevel@tonic-gate 			v1_args.drivenamep->parts.parts_val =
17827c478bd9Sstevel@tonic-gate 			    Zalloc((sizeof (o_mdname_t)) *
17837c478bd9Sstevel@tonic-gate 			    dp->parts.parts_len);
17847c478bd9Sstevel@tonic-gate 
17857c478bd9Sstevel@tonic-gate 			/* build args */
17867c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
17877c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
17887c478bd9Sstevel@tonic-gate 
17897c478bd9Sstevel@tonic-gate 			/* Convert v2 args to v1 args */
17907c478bd9Sstevel@tonic-gate 			meta_conv_drvname_new2old(v1_args.drivenamep,
17917c478bd9Sstevel@tonic-gate 			    v21_args->drivenamep);
17927c478bd9Sstevel@tonic-gate 
17937c478bd9Sstevel@tonic-gate 			rval = mdrpc_drvused_1(&v1_args, &res, clntp);
17947c478bd9Sstevel@tonic-gate 
17957c478bd9Sstevel@tonic-gate 			free(v1_args.drivenamep->parts.parts_val);
17967c478bd9Sstevel@tonic-gate 			free(v1_args.drivenamep);
17977c478bd9Sstevel@tonic-gate 
17987c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
17997c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
18007c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad drive used"));
18017c478bd9Sstevel@tonic-gate 			else
18027c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
18037c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
18047c478bd9Sstevel@tonic-gate 			rval = mdrpc_drvused_2(&v2_args, &res, clntp);
18057c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
18067c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
18077c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad drive used"));
18087c478bd9Sstevel@tonic-gate 			else
18097c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
18107c478bd9Sstevel@tonic-gate 		}
18117c478bd9Sstevel@tonic-gate 
18127c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
18137c478bd9Sstevel@tonic-gate 	}
18147c478bd9Sstevel@tonic-gate 
18157c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
18167c478bd9Sstevel@tonic-gate 
18177c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
18187c478bd9Sstevel@tonic-gate 		return (-1);
18197c478bd9Sstevel@tonic-gate 
18207c478bd9Sstevel@tonic-gate 	return (0);
18217c478bd9Sstevel@tonic-gate }
18227c478bd9Sstevel@tonic-gate 
18237c478bd9Sstevel@tonic-gate void
free_sr(md_set_record * sr)18247c478bd9Sstevel@tonic-gate free_sr(md_set_record *sr)
18257c478bd9Sstevel@tonic-gate {
18267c478bd9Sstevel@tonic-gate 	mdrpc_getset_res	res;
18277c478bd9Sstevel@tonic-gate 	mdrpc_mngetset_res	mnres;
18287c478bd9Sstevel@tonic-gate 
18297c478bd9Sstevel@tonic-gate 	if (md_in_daemon)
18307c478bd9Sstevel@tonic-gate 		return;
18317c478bd9Sstevel@tonic-gate 
18327c478bd9Sstevel@tonic-gate 	/*
18337c478bd9Sstevel@tonic-gate 	 * dummy up a result struct, to do a deep free of the (mn)sr.
18347c478bd9Sstevel@tonic-gate 	 * (A deep free means that the xdr_free code will free the
18357c478bd9Sstevel@tonic-gate 	 * linked list of drive records for the sr and will also free
18367c478bd9Sstevel@tonic-gate 	 * the linked list of node records for the mnsr.)
18377c478bd9Sstevel@tonic-gate 	 */
18387c478bd9Sstevel@tonic-gate 	if (MD_MNSET_REC(sr)) {
18397c478bd9Sstevel@tonic-gate 		(void) memset(&mnres, 0, sizeof (mnres));
18407c478bd9Sstevel@tonic-gate 		mnres.mnsr = (struct md_mnset_record *)sr;
18417c478bd9Sstevel@tonic-gate 		xdr_free(xdr_mdrpc_mngetset_res, (char *)&mnres);
18427c478bd9Sstevel@tonic-gate 	} else {
18437c478bd9Sstevel@tonic-gate 		(void) memset(&res, 0, sizeof (res));
18447c478bd9Sstevel@tonic-gate 		res.sr = sr;
18457c478bd9Sstevel@tonic-gate 		xdr_free(xdr_mdrpc_getset_res, (char *)&res);
18467c478bd9Sstevel@tonic-gate 	}
18477c478bd9Sstevel@tonic-gate }
18487c478bd9Sstevel@tonic-gate 
18497c478bd9Sstevel@tonic-gate void
short_circuit_getset(mdrpc_getset_args * args,mdrpc_getset_res * res)18507c478bd9Sstevel@tonic-gate short_circuit_getset(
18517c478bd9Sstevel@tonic-gate 	mdrpc_getset_args	*args,
18527c478bd9Sstevel@tonic-gate 	mdrpc_getset_res	*res
18537c478bd9Sstevel@tonic-gate )
18547c478bd9Sstevel@tonic-gate {
18557c478bd9Sstevel@tonic-gate 	if (args->setname != NULL)
18567c478bd9Sstevel@tonic-gate 		res->sr = metad_getsetbyname(args->setname, &res->status);
18577c478bd9Sstevel@tonic-gate 	else
18587c478bd9Sstevel@tonic-gate 		res->sr = metad_getsetbynum(args->setno, &res->status);
18597c478bd9Sstevel@tonic-gate }
18607c478bd9Sstevel@tonic-gate 
18617c478bd9Sstevel@tonic-gate void
short_circuit_mngetset(mdrpc_getset_args * args,mdrpc_mngetset_res * res)18627c478bd9Sstevel@tonic-gate short_circuit_mngetset(
18637c478bd9Sstevel@tonic-gate 	mdrpc_getset_args	*args,
18647c478bd9Sstevel@tonic-gate 	mdrpc_mngetset_res	*res
18657c478bd9Sstevel@tonic-gate )
18667c478bd9Sstevel@tonic-gate {
18677c478bd9Sstevel@tonic-gate 	md_set_record		*sr;
18687c478bd9Sstevel@tonic-gate 	if (args->setname != NULL)
18697c478bd9Sstevel@tonic-gate 		sr = metad_getsetbyname(args->setname, &res->status);
18707c478bd9Sstevel@tonic-gate 	else
18717c478bd9Sstevel@tonic-gate 		sr = metad_getsetbynum(args->setno, &res->status);
18727c478bd9Sstevel@tonic-gate 
18737c478bd9Sstevel@tonic-gate 	if (MD_MNSET_REC(sr)) {
18747c478bd9Sstevel@tonic-gate 		res->mnsr = (struct md_mnset_record *)sr;
18757c478bd9Sstevel@tonic-gate 	} else {
18767c478bd9Sstevel@tonic-gate 		res->mnsr = NULL;
18777c478bd9Sstevel@tonic-gate 	}
18787c478bd9Sstevel@tonic-gate }
18797c478bd9Sstevel@tonic-gate 
18807c478bd9Sstevel@tonic-gate static int
is_auto_take_set(char * setname,set_t setno)18817c478bd9Sstevel@tonic-gate is_auto_take_set(char *setname, set_t setno)
18827c478bd9Sstevel@tonic-gate {
18837c478bd9Sstevel@tonic-gate 	if (setname != NULL)
18847c478bd9Sstevel@tonic-gate 	    return (metad_isautotakebyname(setname));
18857c478bd9Sstevel@tonic-gate 	else
18867c478bd9Sstevel@tonic-gate 	    return (metad_isautotakebynum(setno));
18877c478bd9Sstevel@tonic-gate }
18887c478bd9Sstevel@tonic-gate 
18897c478bd9Sstevel@tonic-gate /*
18907c478bd9Sstevel@tonic-gate  * return the diskset record, and drive records.
18917c478bd9Sstevel@tonic-gate  * If record is a MNdiskset record, then only the first md_set_record
18927c478bd9Sstevel@tonic-gate  * bytes were copied from the daemon.
18937c478bd9Sstevel@tonic-gate  */
18947c478bd9Sstevel@tonic-gate int
clnt_getset(char * hostname,char * setname,set_t setno,md_set_record ** ret_sr,md_error_t * ep)18957c478bd9Sstevel@tonic-gate clnt_getset(
18967c478bd9Sstevel@tonic-gate 	char			*hostname,
18977c478bd9Sstevel@tonic-gate 	char			*setname,
18987c478bd9Sstevel@tonic-gate 	set_t			setno,
18997c478bd9Sstevel@tonic-gate 	md_set_record		**ret_sr,
19007c478bd9Sstevel@tonic-gate 	md_error_t		*ep
19017c478bd9Sstevel@tonic-gate )
19027c478bd9Sstevel@tonic-gate {
19037c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
19047c478bd9Sstevel@tonic-gate 	mdrpc_getset_args	*args;
19057c478bd9Sstevel@tonic-gate 	mdrpc_getset_2_args	v2_args;
19067c478bd9Sstevel@tonic-gate 	mdrpc_getset_res	res;
19077c478bd9Sstevel@tonic-gate 	int			rval = -1;
19087c478bd9Sstevel@tonic-gate 	int			version;
19097c478bd9Sstevel@tonic-gate 
19107c478bd9Sstevel@tonic-gate 	/* initialize */
19117c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
19127c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
19137c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
19147c478bd9Sstevel@tonic-gate 
19157c478bd9Sstevel@tonic-gate 	/* build args */
19167c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
19177c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_getset_2_args_u.rev1;
19187c478bd9Sstevel@tonic-gate 	args->setname = setname;
19197c478bd9Sstevel@tonic-gate 	args->setno   = setno;
19207c478bd9Sstevel@tonic-gate 
19217c478bd9Sstevel@tonic-gate 	/* do it */
19227c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
19237c478bd9Sstevel@tonic-gate 		short_circuit_getset(args, &res);
19247c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
19257c478bd9Sstevel@tonic-gate 	} else {
19267c478bd9Sstevel@tonic-gate 	    if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL) {
19277c478bd9Sstevel@tonic-gate 		/*
19287c478bd9Sstevel@tonic-gate 		 * This has to work during the boot up before the rpc.metad can
19297c478bd9Sstevel@tonic-gate 		 * run.  Check to see if we can handle this as a strictly local
19307c478bd9Sstevel@tonic-gate 		 * diskset.
19317c478bd9Sstevel@tonic-gate 		 */
19327c478bd9Sstevel@tonic-gate 		if (is_auto_take_set(setname, setno)) {
19337c478bd9Sstevel@tonic-gate 		    mdclrerror(ep);
19347c478bd9Sstevel@tonic-gate 		    short_circuit_getset(args, &res);
19357c478bd9Sstevel@tonic-gate 		    res.sr = setdup(res.sr);
19367c478bd9Sstevel@tonic-gate 		    (void) mdstealerror(ep, &res.status);
19377c478bd9Sstevel@tonic-gate 		} else {
19387c478bd9Sstevel@tonic-gate 		    return (-1);
19397c478bd9Sstevel@tonic-gate 		}
19407c478bd9Sstevel@tonic-gate 	    } else {
19417c478bd9Sstevel@tonic-gate 
19427c478bd9Sstevel@tonic-gate 		/*
19437c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
19447c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
19457c478bd9Sstevel@tonic-gate 		 * remote procedure
19467c478bd9Sstevel@tonic-gate 		 */
19477c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
19487c478bd9Sstevel@tonic-gate 
19497c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
19507c478bd9Sstevel@tonic-gate 			if (mdrpc_getset_1(args, &res, clntp) != RPC_SUCCESS)
19517c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
19527c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad get set"));
19537c478bd9Sstevel@tonic-gate 			else
19547c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
19557c478bd9Sstevel@tonic-gate 		} else {
19567c478bd9Sstevel@tonic-gate 			if (mdrpc_getset_2(&v2_args, &res, clntp) !=
19577c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
19587c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
19597c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad get set"));
19607c478bd9Sstevel@tonic-gate 			else
19617c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
19627c478bd9Sstevel@tonic-gate 		}
19637c478bd9Sstevel@tonic-gate 
19647c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
19657c478bd9Sstevel@tonic-gate 	    }
19667c478bd9Sstevel@tonic-gate 	}
19677c478bd9Sstevel@tonic-gate 
19687c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
19697c478bd9Sstevel@tonic-gate 		rval = 0;
19707c478bd9Sstevel@tonic-gate 		if (ret_sr != NULL)
19717c478bd9Sstevel@tonic-gate 			*ret_sr = res.sr;
19727c478bd9Sstevel@tonic-gate 		else
19737c478bd9Sstevel@tonic-gate 			if (! md_in_daemon)
19747c478bd9Sstevel@tonic-gate 				xdr_free(xdr_mdrpc_getset_res, (char *)&res);
19757c478bd9Sstevel@tonic-gate 	}
19767c478bd9Sstevel@tonic-gate 
19777c478bd9Sstevel@tonic-gate 	return (rval);
19787c478bd9Sstevel@tonic-gate }
19797c478bd9Sstevel@tonic-gate 
19807c478bd9Sstevel@tonic-gate /*
19817c478bd9Sstevel@tonic-gate  * return the multi-node diskset record, drive records and node records.
19827c478bd9Sstevel@tonic-gate  */
1983b6c8bd52Sjeanm int
clnt_mngetset(char * hostname,char * setname,set_t setno,md_mnset_record ** ret_mnsr,md_error_t * ep)19847c478bd9Sstevel@tonic-gate clnt_mngetset(
19857c478bd9Sstevel@tonic-gate 	char			*hostname,
19867c478bd9Sstevel@tonic-gate 	char			*setname,
19877c478bd9Sstevel@tonic-gate 	set_t			setno,
19887c478bd9Sstevel@tonic-gate 	md_mnset_record		**ret_mnsr,
19897c478bd9Sstevel@tonic-gate 	md_error_t		*ep
19907c478bd9Sstevel@tonic-gate )
19917c478bd9Sstevel@tonic-gate {
19927c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
19937c478bd9Sstevel@tonic-gate 	mdrpc_getset_args	*args;
19947c478bd9Sstevel@tonic-gate 	mdrpc_getset_2_args	v2_args;
19957c478bd9Sstevel@tonic-gate 	mdrpc_mngetset_res	res;
19967c478bd9Sstevel@tonic-gate 	int			rval = -1;
19977c478bd9Sstevel@tonic-gate 	int			version;
19987c478bd9Sstevel@tonic-gate 
19997c478bd9Sstevel@tonic-gate 	/* initialize */
20007c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
20017c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
20027c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
20037c478bd9Sstevel@tonic-gate 
20047c478bd9Sstevel@tonic-gate 	/* build args */
20057c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
20067c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_getset_2_args_u.rev1;
20077c478bd9Sstevel@tonic-gate 	args->setname = setname;
20087c478bd9Sstevel@tonic-gate 	args->setno   = setno;
20097c478bd9Sstevel@tonic-gate 
20107c478bd9Sstevel@tonic-gate 	/* do it */
20117c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
20127c478bd9Sstevel@tonic-gate 		short_circuit_mngetset(args, &res);
20137c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
20147c478bd9Sstevel@tonic-gate 	} else {
20157c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
20167c478bd9Sstevel@tonic-gate 			return (-1);
20177c478bd9Sstevel@tonic-gate 
20187c478bd9Sstevel@tonic-gate 		/*
20197c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
20207c478bd9Sstevel@tonic-gate 		 */
20217c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
20227c478bd9Sstevel@tonic-gate 
20237c478bd9Sstevel@tonic-gate 		/*
20247c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
20257c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
20267c478bd9Sstevel@tonic-gate 		 */
20277c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
20287c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
20297c478bd9Sstevel@tonic-gate 				setno, hostname, NULL, setname);
20307c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
20317c478bd9Sstevel@tonic-gate 			return (-1);
20327c478bd9Sstevel@tonic-gate 		} else {
20337c478bd9Sstevel@tonic-gate 			if (mdrpc_mngetset_2(&v2_args, &res, clntp)
20347c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
20357c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
20367c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad mn get set"));
20377c478bd9Sstevel@tonic-gate 			else
20387c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
20397c478bd9Sstevel@tonic-gate 		}
20407c478bd9Sstevel@tonic-gate 
20417c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
20427c478bd9Sstevel@tonic-gate 	}
20437c478bd9Sstevel@tonic-gate 
20447c478bd9Sstevel@tonic-gate 	/* If no ep error and no version mismatch - rpc call worked ok */
20457c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
20467c478bd9Sstevel@tonic-gate 		rval = 0;
20477c478bd9Sstevel@tonic-gate 		if (ret_mnsr != NULL)
20487c478bd9Sstevel@tonic-gate 			*ret_mnsr = res.mnsr;
20497c478bd9Sstevel@tonic-gate 		else
20507c478bd9Sstevel@tonic-gate 			if (! md_in_daemon)
20517c478bd9Sstevel@tonic-gate 				xdr_free(xdr_mdrpc_mngetset_res, (char *)&res);
20527c478bd9Sstevel@tonic-gate 	}
20537c478bd9Sstevel@tonic-gate 
20547c478bd9Sstevel@tonic-gate 	return (rval);
20557c478bd9Sstevel@tonic-gate }
20567c478bd9Sstevel@tonic-gate 
20577c478bd9Sstevel@tonic-gate /*
20587c478bd9Sstevel@tonic-gate  * Set master nodeid and nodename in multi-node set record.
20597c478bd9Sstevel@tonic-gate  */
2060b6c8bd52Sjeanm int
clnt_mnsetmaster(char * hostname,mdsetname_t * sp,md_node_nm_t master_nodenm,int master_nodeid,md_error_t * ep)20617c478bd9Sstevel@tonic-gate clnt_mnsetmaster(
20627c478bd9Sstevel@tonic-gate 	char			*hostname,
20637c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
20647c478bd9Sstevel@tonic-gate 	md_node_nm_t		master_nodenm,
20657c478bd9Sstevel@tonic-gate 	int			master_nodeid,
20667c478bd9Sstevel@tonic-gate 	md_error_t		*ep
20677c478bd9Sstevel@tonic-gate )
20687c478bd9Sstevel@tonic-gate {
20697c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
20707c478bd9Sstevel@tonic-gate 	mdrpc_mnsetmaster_args	*args;
20717c478bd9Sstevel@tonic-gate 	mdrpc_mnsetmaster_2_args	v2_args;
20727c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
20737c478bd9Sstevel@tonic-gate 	int			version;
20747c478bd9Sstevel@tonic-gate 
20757c478bd9Sstevel@tonic-gate 	/* initialize */
20767c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
20777c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
20787c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
20797c478bd9Sstevel@tonic-gate 
20807c478bd9Sstevel@tonic-gate 	/* build args */
20817c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
20827c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_mnsetmaster_2_args_u.rev1;
20837c478bd9Sstevel@tonic-gate 	args->sp = sp;
20847c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
20857c478bd9Sstevel@tonic-gate 	(void) strlcpy(args->master_nodenm, master_nodenm, MD_MAX_NODENAME);
20867c478bd9Sstevel@tonic-gate 	args->master_nodeid = master_nodeid;
20877c478bd9Sstevel@tonic-gate 
20887c478bd9Sstevel@tonic-gate 	/* do it */
20897c478bd9Sstevel@tonic-gate 	if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
20907c478bd9Sstevel@tonic-gate 		return (-1);
20917c478bd9Sstevel@tonic-gate 
20927c478bd9Sstevel@tonic-gate 	/*
20937c478bd9Sstevel@tonic-gate 	 * Check the client handle for the version
20947c478bd9Sstevel@tonic-gate 	 */
20957c478bd9Sstevel@tonic-gate 	CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
20967c478bd9Sstevel@tonic-gate 
20977c478bd9Sstevel@tonic-gate 	/*
20987c478bd9Sstevel@tonic-gate 	 * If the client is version 1, return error
20997c478bd9Sstevel@tonic-gate 	 * otherwise, make the remote procedure call.
21007c478bd9Sstevel@tonic-gate 	 */
21017c478bd9Sstevel@tonic-gate 	if (version == METAD_VERSION) { /* version 1 */
21027c478bd9Sstevel@tonic-gate 		(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
21037c478bd9Sstevel@tonic-gate 			sp->setno, hostname, NULL, sp->setname);
21047c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
21057c478bd9Sstevel@tonic-gate 		return (-1);
21067c478bd9Sstevel@tonic-gate 	} else {
21077c478bd9Sstevel@tonic-gate 		if (mdrpc_mnsetmaster_2(&v2_args, &res, clntp) != RPC_SUCCESS)
21087c478bd9Sstevel@tonic-gate 			(void) mdrpcerror(ep, clntp, hostname,
21097c478bd9Sstevel@tonic-gate 			dgettext(TEXT_DOMAIN, "metad multi-owner set master"));
21107c478bd9Sstevel@tonic-gate 		else
21117c478bd9Sstevel@tonic-gate 			(void) mdstealerror(ep, &res.status);
21127c478bd9Sstevel@tonic-gate 	}
21137c478bd9Sstevel@tonic-gate 
21147c478bd9Sstevel@tonic-gate 	metarpcclose(clntp);
21157c478bd9Sstevel@tonic-gate 
21167c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
21177c478bd9Sstevel@tonic-gate 
21187c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
21197c478bd9Sstevel@tonic-gate 		return (-1);
21207c478bd9Sstevel@tonic-gate 
21217c478bd9Sstevel@tonic-gate 	return (0);
21227c478bd9Sstevel@tonic-gate }
21237c478bd9Sstevel@tonic-gate 
21247c478bd9Sstevel@tonic-gate /*
21257c478bd9Sstevel@tonic-gate  * Get the MH timeout values.
21267c478bd9Sstevel@tonic-gate  */
21277c478bd9Sstevel@tonic-gate int
clnt_gtimeout(char * hostname,mdsetname_t * sp,mhd_mhiargs_t * ret_mhiargs,md_error_t * ep)21287c478bd9Sstevel@tonic-gate clnt_gtimeout(
21297c478bd9Sstevel@tonic-gate 	char			*hostname,
21307c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
21317c478bd9Sstevel@tonic-gate 	mhd_mhiargs_t		*ret_mhiargs,
21327c478bd9Sstevel@tonic-gate 	md_error_t		*ep
21337c478bd9Sstevel@tonic-gate )
21347c478bd9Sstevel@tonic-gate {
21357c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
21367c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
21377c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
21387c478bd9Sstevel@tonic-gate 	mdrpc_gtimeout_res	res;
21397c478bd9Sstevel@tonic-gate 	int			rval = -1;
21407c478bd9Sstevel@tonic-gate 	int			version;
21417c478bd9Sstevel@tonic-gate 
21427c478bd9Sstevel@tonic-gate 	/* initialize */
21437c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
21447c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
21457c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
21467c478bd9Sstevel@tonic-gate 
21477c478bd9Sstevel@tonic-gate 	/* build args */
21487c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
21497c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
21507c478bd9Sstevel@tonic-gate 	args->sp = sp;
21517c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
21527c478bd9Sstevel@tonic-gate 
21537c478bd9Sstevel@tonic-gate 	/* do it */
21547c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
21557c478bd9Sstevel@tonic-gate 		int	bool;
21567c478bd9Sstevel@tonic-gate 		bool = mdrpc_gtimeout_2_svc(&v2_args, &res, NULL);
21577c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
21587c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
21597c478bd9Sstevel@tonic-gate 	} else {
21607c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
21617c478bd9Sstevel@tonic-gate 			return (-1);
21627c478bd9Sstevel@tonic-gate 
21637c478bd9Sstevel@tonic-gate 		/*
21647c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
21657c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
21667c478bd9Sstevel@tonic-gate 		 * remote procedure
21677c478bd9Sstevel@tonic-gate 		 */
21687c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
21697c478bd9Sstevel@tonic-gate 
21707c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
21717c478bd9Sstevel@tonic-gate 			if (mdrpc_gtimeout_1(args, &res, clntp) != RPC_SUCCESS)
21727c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
21737c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad get timeout"));
21747c478bd9Sstevel@tonic-gate 			else
21757c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
21767c478bd9Sstevel@tonic-gate 		} else {
21777c478bd9Sstevel@tonic-gate 			if (mdrpc_gtimeout_2(&v2_args, &res, clntp) !=
21787c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
21797c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
21807c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad get timeout"));
21817c478bd9Sstevel@tonic-gate 			else
21827c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
21837c478bd9Sstevel@tonic-gate 		}
21847c478bd9Sstevel@tonic-gate 
21857c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
21867c478bd9Sstevel@tonic-gate 	}
21877c478bd9Sstevel@tonic-gate 
21887c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
21897c478bd9Sstevel@tonic-gate 
21907c478bd9Sstevel@tonic-gate 		/* do something with the results */
21917c478bd9Sstevel@tonic-gate 		rval = 0;
21927c478bd9Sstevel@tonic-gate 
21937c478bd9Sstevel@tonic-gate 		/* copy md_mhiargs_t */
21947c478bd9Sstevel@tonic-gate 		if (ret_mhiargs != NULL)
21957c478bd9Sstevel@tonic-gate 			*ret_mhiargs = *res.mhiargsp;
21967c478bd9Sstevel@tonic-gate 	}
21977c478bd9Sstevel@tonic-gate 
21987c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_gtimeout_res, (char *)&res);
21997c478bd9Sstevel@tonic-gate 
22007c478bd9Sstevel@tonic-gate 	return (rval);
22017c478bd9Sstevel@tonic-gate }
22027c478bd9Sstevel@tonic-gate 
22037c478bd9Sstevel@tonic-gate /*
22047c478bd9Sstevel@tonic-gate  * get real hostname from remote host
22057c478bd9Sstevel@tonic-gate  */
22067c478bd9Sstevel@tonic-gate int
clnt_hostname(char * hostname,char ** ret_hostname,md_error_t * ep)22077c478bd9Sstevel@tonic-gate clnt_hostname(
22087c478bd9Sstevel@tonic-gate 	char			*hostname,
22097c478bd9Sstevel@tonic-gate 	char			**ret_hostname,
22107c478bd9Sstevel@tonic-gate 	md_error_t		*ep
22117c478bd9Sstevel@tonic-gate )
22127c478bd9Sstevel@tonic-gate {
22137c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
22147c478bd9Sstevel@tonic-gate 	mdrpc_null_args		args;
22157c478bd9Sstevel@tonic-gate 	mdrpc_hostname_res	res;
22167c478bd9Sstevel@tonic-gate 	int			rval = -1;
22177c478bd9Sstevel@tonic-gate 
22187c478bd9Sstevel@tonic-gate 	/* initialize */
22197c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
22207c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
22217c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
22227c478bd9Sstevel@tonic-gate 
22237c478bd9Sstevel@tonic-gate 	/* build args */
22247c478bd9Sstevel@tonic-gate 	args.cl_sk = NULL;
22257c478bd9Sstevel@tonic-gate 
22267c478bd9Sstevel@tonic-gate 	/* do it */
22277c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
22287c478bd9Sstevel@tonic-gate 		int	bool;
22297c478bd9Sstevel@tonic-gate 		bool = mdrpc_hostname_1_svc(&args, &res, NULL);
22307c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
22317c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
22327c478bd9Sstevel@tonic-gate 	} else {
22337c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
22347c478bd9Sstevel@tonic-gate 			return (-1);
22357c478bd9Sstevel@tonic-gate 
22367c478bd9Sstevel@tonic-gate 		if (mdrpc_hostname_1(&args, &res, clntp) != RPC_SUCCESS)
22377c478bd9Sstevel@tonic-gate 			(void) mdrpcerror(ep, clntp, hostname,
22387c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad hostname"));
22397c478bd9Sstevel@tonic-gate 		else
22407c478bd9Sstevel@tonic-gate 			(void) mdstealerror(ep, &res.status);
22417c478bd9Sstevel@tonic-gate 
22427c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
22437c478bd9Sstevel@tonic-gate 	}
22447c478bd9Sstevel@tonic-gate 
22457c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
22467c478bd9Sstevel@tonic-gate 		/* do something with the results */
22477c478bd9Sstevel@tonic-gate 		rval = 0;
22487c478bd9Sstevel@tonic-gate 
22497c478bd9Sstevel@tonic-gate 		if (ret_hostname != NULL)
22507c478bd9Sstevel@tonic-gate 			*ret_hostname = Strdup(res.hostname);
22517c478bd9Sstevel@tonic-gate 	}
22527c478bd9Sstevel@tonic-gate 
22537c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_hostname_res, (char *)&res);
22547c478bd9Sstevel@tonic-gate 
22557c478bd9Sstevel@tonic-gate 	return (rval);
22567c478bd9Sstevel@tonic-gate }
22577c478bd9Sstevel@tonic-gate 
22587c478bd9Sstevel@tonic-gate /*
22597c478bd9Sstevel@tonic-gate  * NULLPROC - just returns a response
22607c478bd9Sstevel@tonic-gate  */
22617c478bd9Sstevel@tonic-gate int
clnt_nullproc(char * hostname,md_error_t * ep)22627c478bd9Sstevel@tonic-gate clnt_nullproc(
22637c478bd9Sstevel@tonic-gate 	char			*hostname,
22647c478bd9Sstevel@tonic-gate 	md_error_t		*ep
22657c478bd9Sstevel@tonic-gate )
22667c478bd9Sstevel@tonic-gate {
22677c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
22687c478bd9Sstevel@tonic-gate 
22697c478bd9Sstevel@tonic-gate 	/* initialize */
22707c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
22717c478bd9Sstevel@tonic-gate 
22727c478bd9Sstevel@tonic-gate 	/* do it */
22737c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
22747c478bd9Sstevel@tonic-gate 		int	bool;
22757c478bd9Sstevel@tonic-gate 		bool = mdrpc_nullproc_1_svc(NULL, ep, NULL);
22767c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
22777c478bd9Sstevel@tonic-gate 	} else {
22787c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_DEF_TMO, ep)) == NULL)
22797c478bd9Sstevel@tonic-gate 			return (-1);
22807c478bd9Sstevel@tonic-gate 
22817c478bd9Sstevel@tonic-gate 		if (mdrpc_nullproc_1(NULL, ep, clntp) != RPC_SUCCESS)
22827c478bd9Sstevel@tonic-gate 			(void) mdrpcerror(ep, clntp, hostname,
22837c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad nullproc"));
22847c478bd9Sstevel@tonic-gate 
22857c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
22867c478bd9Sstevel@tonic-gate 	}
22877c478bd9Sstevel@tonic-gate 
22887c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
22897c478bd9Sstevel@tonic-gate 		return (-1);
22907c478bd9Sstevel@tonic-gate 
22917c478bd9Sstevel@tonic-gate 	return (0);
22927c478bd9Sstevel@tonic-gate }
22937c478bd9Sstevel@tonic-gate 
22947c478bd9Sstevel@tonic-gate /*
22957c478bd9Sstevel@tonic-gate  * does host own the set?
22967c478bd9Sstevel@tonic-gate  */
22977c478bd9Sstevel@tonic-gate int
clnt_ownset(char * hostname,mdsetname_t * sp,int * ret_bool,md_error_t * ep)22987c478bd9Sstevel@tonic-gate clnt_ownset(
22997c478bd9Sstevel@tonic-gate 	char			*hostname,
23007c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
23017c478bd9Sstevel@tonic-gate 	int			*ret_bool,
23027c478bd9Sstevel@tonic-gate 	md_error_t		*ep
23037c478bd9Sstevel@tonic-gate )
23047c478bd9Sstevel@tonic-gate {
23057c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
23067c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
23077c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
23087c478bd9Sstevel@tonic-gate 	mdrpc_bool_res		res;
23097c478bd9Sstevel@tonic-gate 	int			rval = -1;
23107c478bd9Sstevel@tonic-gate 	int			version;
23117c478bd9Sstevel@tonic-gate 
23127c478bd9Sstevel@tonic-gate 	/* initialize */
23137c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
23147c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
23157c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
23167c478bd9Sstevel@tonic-gate 
23177c478bd9Sstevel@tonic-gate 	/* build args */
23187c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
23197c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
23207c478bd9Sstevel@tonic-gate 	args->sp = sp;
23217c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
23227c478bd9Sstevel@tonic-gate 
23237c478bd9Sstevel@tonic-gate 	/* do it */
23247c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
23257c478bd9Sstevel@tonic-gate 		int	bool;
23267c478bd9Sstevel@tonic-gate 		bool = mdrpc_ownset_2_svc(&v2_args, &res, NULL);
23277c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
23287c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
23297c478bd9Sstevel@tonic-gate 	} else {
23307c478bd9Sstevel@tonic-gate 	    if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL) {
23317c478bd9Sstevel@tonic-gate 		/*
23327c478bd9Sstevel@tonic-gate 		 * This has to work in the code path from libpreen which is
23337c478bd9Sstevel@tonic-gate 		 * running within fsck before the rpc.metad can run.  Check
23347c478bd9Sstevel@tonic-gate 		 * to see if we should handle this as an auto-take diskset.
23357c478bd9Sstevel@tonic-gate 		 */
23367c478bd9Sstevel@tonic-gate 		if (is_auto_take_set(sp->setname, sp->setno)) {
23377c478bd9Sstevel@tonic-gate 		    /* Can't call mdrpc_ownset_2_svc since not in daemon */
23387c478bd9Sstevel@tonic-gate 		    mdclrerror(ep);
23397c478bd9Sstevel@tonic-gate 		    if (s_ownset(sp->setno, ep))
23407c478bd9Sstevel@tonic-gate 			res.value = TRUE;
23417c478bd9Sstevel@tonic-gate 		    else
23427c478bd9Sstevel@tonic-gate 			res.value = FALSE;
23437c478bd9Sstevel@tonic-gate 		} else {
23447c478bd9Sstevel@tonic-gate 		    return (-1);
23457c478bd9Sstevel@tonic-gate 		}
23467c478bd9Sstevel@tonic-gate 
23477c478bd9Sstevel@tonic-gate 	    } else {
23487c478bd9Sstevel@tonic-gate 
23497c478bd9Sstevel@tonic-gate 		/*
23507c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
23517c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
23527c478bd9Sstevel@tonic-gate 		 * remote procedure
23537c478bd9Sstevel@tonic-gate 		 */
23547c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
23557c478bd9Sstevel@tonic-gate 
23567c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
23577c478bd9Sstevel@tonic-gate 			if (mdrpc_ownset_1(args, &res, clntp) != RPC_SUCCESS)
23587c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
23597c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad own set"));
23607c478bd9Sstevel@tonic-gate 			else
23617c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
23627c478bd9Sstevel@tonic-gate 		} else {
23637c478bd9Sstevel@tonic-gate 			if (mdrpc_ownset_2(&v2_args, &res, clntp) !=
23647c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
23657c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
23667c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad own set"));
23677c478bd9Sstevel@tonic-gate 			else
23687c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
23697c478bd9Sstevel@tonic-gate 		}
23707c478bd9Sstevel@tonic-gate 
23717c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
23727c478bd9Sstevel@tonic-gate 	    }
23737c478bd9Sstevel@tonic-gate 	}
23747c478bd9Sstevel@tonic-gate 
23757c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
23767c478bd9Sstevel@tonic-gate 		/* do something with the results */
23777c478bd9Sstevel@tonic-gate 		rval = 0;
23787c478bd9Sstevel@tonic-gate 
23797c478bd9Sstevel@tonic-gate 		if (ret_bool != NULL)
23807c478bd9Sstevel@tonic-gate 			*ret_bool = res.value;
23817c478bd9Sstevel@tonic-gate 	}
23827c478bd9Sstevel@tonic-gate 
23837c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_bool_res, (char *)&res);
23847c478bd9Sstevel@tonic-gate 
23857c478bd9Sstevel@tonic-gate 	return (rval);
23867c478bd9Sstevel@tonic-gate }
23877c478bd9Sstevel@tonic-gate 
23887c478bd9Sstevel@tonic-gate /*
23897c478bd9Sstevel@tonic-gate  * Valid set name.
23907c478bd9Sstevel@tonic-gate  */
23917c478bd9Sstevel@tonic-gate int
clnt_setnameok(char * hostname,mdsetname_t * sp,int * ret_bool,md_error_t * ep)23927c478bd9Sstevel@tonic-gate clnt_setnameok(
23937c478bd9Sstevel@tonic-gate 	char			*hostname,
23947c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
23957c478bd9Sstevel@tonic-gate 	int			*ret_bool,
23967c478bd9Sstevel@tonic-gate 	md_error_t		*ep
23977c478bd9Sstevel@tonic-gate )
23987c478bd9Sstevel@tonic-gate {
23997c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
24007c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
24017c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
24027c478bd9Sstevel@tonic-gate 	mdrpc_bool_res		res;
24037c478bd9Sstevel@tonic-gate 	int			rval = -1;
24047c478bd9Sstevel@tonic-gate 	int			version;
24057c478bd9Sstevel@tonic-gate 
24067c478bd9Sstevel@tonic-gate 	/* initialize */
24077c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
24087c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
24097c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
24107c478bd9Sstevel@tonic-gate 
24117c478bd9Sstevel@tonic-gate 	/* build args */
24127c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
24137c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
24147c478bd9Sstevel@tonic-gate 	args->sp = sp;
24157c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
24167c478bd9Sstevel@tonic-gate 
24177c478bd9Sstevel@tonic-gate 	/* do it */
24187c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
24197c478bd9Sstevel@tonic-gate 		int	bool;
24207c478bd9Sstevel@tonic-gate 		bool = mdrpc_setnameok_2_svc(&v2_args, &res, NULL);
24217c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
24227c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
24237c478bd9Sstevel@tonic-gate 	} else {
24247c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
24257c478bd9Sstevel@tonic-gate 			return (-1);
24267c478bd9Sstevel@tonic-gate 
24277c478bd9Sstevel@tonic-gate 		/*
24287c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
24297c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
24307c478bd9Sstevel@tonic-gate 		 * remote procedure
24317c478bd9Sstevel@tonic-gate 		 */
24327c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
24337c478bd9Sstevel@tonic-gate 
24347c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
24357c478bd9Sstevel@tonic-gate 			if (mdrpc_setnameok_1(args, &res, clntp) != RPC_SUCCESS)
24367c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
24377c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad setname ok"));
24387c478bd9Sstevel@tonic-gate 			else
24397c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
24407c478bd9Sstevel@tonic-gate 		} else {
24417c478bd9Sstevel@tonic-gate 			if (mdrpc_setnameok_2(&v2_args, &res, clntp) !=
24427c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
24437c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
24447c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad setname ok"));
24457c478bd9Sstevel@tonic-gate 			else
24467c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
24477c478bd9Sstevel@tonic-gate 		}
24487c478bd9Sstevel@tonic-gate 
24497c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
24507c478bd9Sstevel@tonic-gate 	}
24517c478bd9Sstevel@tonic-gate 
24527c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
24537c478bd9Sstevel@tonic-gate 		/* do something with the results */
24547c478bd9Sstevel@tonic-gate 		rval = 0;
24557c478bd9Sstevel@tonic-gate 
24567c478bd9Sstevel@tonic-gate 		if (ret_bool != NULL)
24577c478bd9Sstevel@tonic-gate 			*ret_bool = res.value;
24587c478bd9Sstevel@tonic-gate 	}
24597c478bd9Sstevel@tonic-gate 
24607c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_bool_res, (char *)&res);
24617c478bd9Sstevel@tonic-gate 
24627c478bd9Sstevel@tonic-gate 	return (rval);
24637c478bd9Sstevel@tonic-gate }
24647c478bd9Sstevel@tonic-gate 
24657c478bd9Sstevel@tonic-gate /*
24667c478bd9Sstevel@tonic-gate  * Is set number in-use?
24677c478bd9Sstevel@tonic-gate  */
24687c478bd9Sstevel@tonic-gate int
clnt_setnumbusy(char * hostname,set_t setno,int * ret_bool,md_error_t * ep)24697c478bd9Sstevel@tonic-gate clnt_setnumbusy(
24707c478bd9Sstevel@tonic-gate 	char			*hostname,
24717c478bd9Sstevel@tonic-gate 	set_t			setno,
24727c478bd9Sstevel@tonic-gate 	int			*ret_bool,
24737c478bd9Sstevel@tonic-gate 	md_error_t		*ep
24747c478bd9Sstevel@tonic-gate )
24757c478bd9Sstevel@tonic-gate {
24767c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
24777c478bd9Sstevel@tonic-gate 	mdrpc_setno_args	*args;
24787c478bd9Sstevel@tonic-gate 	mdrpc_setno_2_args	v2_args;
24797c478bd9Sstevel@tonic-gate 	mdrpc_bool_res		res;
24807c478bd9Sstevel@tonic-gate 	int			rval = -1;
24817c478bd9Sstevel@tonic-gate 	int			version;
24827c478bd9Sstevel@tonic-gate 
24837c478bd9Sstevel@tonic-gate 	/* initialize */
24847c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
24857c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
24867c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
24877c478bd9Sstevel@tonic-gate 
24887c478bd9Sstevel@tonic-gate 	/* build args */
24897c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
24907c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_setno_2_args_u.rev1;
24917c478bd9Sstevel@tonic-gate 	args->setno = setno;
24927c478bd9Sstevel@tonic-gate 	args->cl_sk = NULL;
24937c478bd9Sstevel@tonic-gate 
24947c478bd9Sstevel@tonic-gate 	/* do it */
24957c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
24967c478bd9Sstevel@tonic-gate 		int	bool;
24977c478bd9Sstevel@tonic-gate 		bool = mdrpc_setnumbusy_2_svc(&v2_args, &res, NULL);
24987c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
24997c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
25007c478bd9Sstevel@tonic-gate 	} else {
25017c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
25027c478bd9Sstevel@tonic-gate 			return (-1);
25037c478bd9Sstevel@tonic-gate 
25047c478bd9Sstevel@tonic-gate 		/*
25057c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
25067c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
25077c478bd9Sstevel@tonic-gate 		 * remote procedure
25087c478bd9Sstevel@tonic-gate 		 */
25097c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
25107c478bd9Sstevel@tonic-gate 
25117c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
25127c478bd9Sstevel@tonic-gate 			if (mdrpc_setnumbusy_1(args, &res, clntp) !=
25137c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
25147c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
25157c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad setnumber busy"));
25167c478bd9Sstevel@tonic-gate 			else
25177c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
25187c478bd9Sstevel@tonic-gate 		} else {
25197c478bd9Sstevel@tonic-gate 			if (mdrpc_setnumbusy_2(&v2_args, &res, clntp) !=
25207c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
25217c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
25227c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad setnumber busy"));
25237c478bd9Sstevel@tonic-gate 			else
25247c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
25257c478bd9Sstevel@tonic-gate 		}
25267c478bd9Sstevel@tonic-gate 
25277c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
25287c478bd9Sstevel@tonic-gate 	}
25297c478bd9Sstevel@tonic-gate 
25307c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
25317c478bd9Sstevel@tonic-gate 		/* do something with the results */
25327c478bd9Sstevel@tonic-gate 		rval = 0;
25337c478bd9Sstevel@tonic-gate 
25347c478bd9Sstevel@tonic-gate 		if (ret_bool != NULL)
25357c478bd9Sstevel@tonic-gate 			*ret_bool = res.value;
25367c478bd9Sstevel@tonic-gate 	}
25377c478bd9Sstevel@tonic-gate 
25387c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_bool_res, (char *)&res);
25397c478bd9Sstevel@tonic-gate 
25407c478bd9Sstevel@tonic-gate 	return (rval);
25417c478bd9Sstevel@tonic-gate }
25427c478bd9Sstevel@tonic-gate 
25437c478bd9Sstevel@tonic-gate /*
25447c478bd9Sstevel@tonic-gate  * Set the timeout values used into the drive records.
25457c478bd9Sstevel@tonic-gate  */
25467c478bd9Sstevel@tonic-gate int
clnt_stimeout(char * hostname,mdsetname_t * sp,mhd_mhiargs_t * mhiargsp,md_error_t * ep)25477c478bd9Sstevel@tonic-gate clnt_stimeout(
25487c478bd9Sstevel@tonic-gate 	char			*hostname,
25497c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
25507c478bd9Sstevel@tonic-gate 	mhd_mhiargs_t		*mhiargsp,
25517c478bd9Sstevel@tonic-gate 	md_error_t		*ep
25527c478bd9Sstevel@tonic-gate )
25537c478bd9Sstevel@tonic-gate {
25547c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
25557c478bd9Sstevel@tonic-gate 	mdrpc_stimeout_args	*args;
25567c478bd9Sstevel@tonic-gate 	mdrpc_stimeout_2_args	v2_args;
25577c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
25587c478bd9Sstevel@tonic-gate 	int			version;
25597c478bd9Sstevel@tonic-gate 
25607c478bd9Sstevel@tonic-gate 	/* initialize */
25617c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
25627c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
25637c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
25647c478bd9Sstevel@tonic-gate 
25657c478bd9Sstevel@tonic-gate 	/* build args */
25667c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
25677c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_stimeout_2_args_u.rev1;
25687c478bd9Sstevel@tonic-gate 	args->sp = sp;
25697c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
25707c478bd9Sstevel@tonic-gate 	args->mhiargsp = mhiargsp;
25717c478bd9Sstevel@tonic-gate 
25727c478bd9Sstevel@tonic-gate 	/* do it */
25737c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
25747c478bd9Sstevel@tonic-gate 		int	bool;
25757c478bd9Sstevel@tonic-gate 		bool = mdrpc_stimeout_2_svc(&v2_args, &res, NULL);
25767c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
25777c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
25787c478bd9Sstevel@tonic-gate 	} else {
25797c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
25807c478bd9Sstevel@tonic-gate 			return (-1);
25817c478bd9Sstevel@tonic-gate 
25827c478bd9Sstevel@tonic-gate 		/*
25837c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
25847c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
25857c478bd9Sstevel@tonic-gate 		 * remote procedure
25867c478bd9Sstevel@tonic-gate 		 */
25877c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
25887c478bd9Sstevel@tonic-gate 
25897c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
25907c478bd9Sstevel@tonic-gate 			if (mdrpc_stimeout_1(args, &res, clntp) != RPC_SUCCESS)
25917c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
25927c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad set timeout"));
25937c478bd9Sstevel@tonic-gate 			else
25947c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
25957c478bd9Sstevel@tonic-gate 		} else {
25967c478bd9Sstevel@tonic-gate 			if (mdrpc_stimeout_2(&v2_args, &res, clntp) !=
25977c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
25987c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
25997c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad set timeout"));
26007c478bd9Sstevel@tonic-gate 			else
26017c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
26027c478bd9Sstevel@tonic-gate 		}
26037c478bd9Sstevel@tonic-gate 
26047c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
26057c478bd9Sstevel@tonic-gate 	}
26067c478bd9Sstevel@tonic-gate 
26077c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
26087c478bd9Sstevel@tonic-gate 
26097c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
26107c478bd9Sstevel@tonic-gate 		return (-1);
26117c478bd9Sstevel@tonic-gate 
26127c478bd9Sstevel@tonic-gate 	return (0);
26137c478bd9Sstevel@tonic-gate }
26147c478bd9Sstevel@tonic-gate 
26157c478bd9Sstevel@tonic-gate /*
26167c478bd9Sstevel@tonic-gate  * update drive records
26177c478bd9Sstevel@tonic-gate  */
26187c478bd9Sstevel@tonic-gate int
clnt_upd_dr_dbinfo(char * hostname,mdsetname_t * sp,md_drive_desc * dd,md_error_t * ep)26197c478bd9Sstevel@tonic-gate clnt_upd_dr_dbinfo(
26207c478bd9Sstevel@tonic-gate 	char			*hostname,
26217c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
26227c478bd9Sstevel@tonic-gate 	md_drive_desc		*dd,
26237c478bd9Sstevel@tonic-gate 	md_error_t		*ep
26247c478bd9Sstevel@tonic-gate )
26257c478bd9Sstevel@tonic-gate {
26267c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
26277c478bd9Sstevel@tonic-gate 	mdrpc_drives_args	v1_args;
26287c478bd9Sstevel@tonic-gate 	mdrpc_drives_2_args	v2_args;
26297c478bd9Sstevel@tonic-gate 	mdrpc_drives_2_args_r1	*v21_args;
26307c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
26317c478bd9Sstevel@tonic-gate 	int			rval;
26327c478bd9Sstevel@tonic-gate 	int			version;
26337c478bd9Sstevel@tonic-gate 
26347c478bd9Sstevel@tonic-gate 	/* initialize */
26357c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
26367c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
26377c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
26387c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
26397c478bd9Sstevel@tonic-gate 
26407c478bd9Sstevel@tonic-gate 	/* build args */
26417c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
26427c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_drives_2_args_u.rev1;
26437c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
26447c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
26457c478bd9Sstevel@tonic-gate 	v21_args->drivedescs = dd;
26467c478bd9Sstevel@tonic-gate 
26477c478bd9Sstevel@tonic-gate 	/* do it */
26487c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
26497c478bd9Sstevel@tonic-gate 		int	bool;
26507c478bd9Sstevel@tonic-gate 
26517c478bd9Sstevel@tonic-gate 		/*
26527c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
26537c478bd9Sstevel@tonic-gate 		 */
26547c478bd9Sstevel@tonic-gate 		bool = mdrpc_upd_dr_dbinfo_2_svc(&v2_args, &res, NULL);
26557c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
26567c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
26577c478bd9Sstevel@tonic-gate 	} else {
26587c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
26597c478bd9Sstevel@tonic-gate 			return (-1);
26607c478bd9Sstevel@tonic-gate 
26617c478bd9Sstevel@tonic-gate 		/*
26627c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
26637c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
26647c478bd9Sstevel@tonic-gate 		 * remote procedure
26657c478bd9Sstevel@tonic-gate 		 */
26667c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
26677c478bd9Sstevel@tonic-gate 
26687c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
26697c478bd9Sstevel@tonic-gate 
26707c478bd9Sstevel@tonic-gate 			alloc_olddrvdesc(&v1_args.drivedescs, dd);
26717c478bd9Sstevel@tonic-gate 
26727c478bd9Sstevel@tonic-gate 			/* build args */
26737c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
26747c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
26757c478bd9Sstevel@tonic-gate 			meta_conv_drvdesc_new2old(v1_args.drivedescs, dd);
26767c478bd9Sstevel@tonic-gate 
26777c478bd9Sstevel@tonic-gate 			rval = mdrpc_upd_dr_dbinfo_1(&v1_args, &res, clntp);
26787c478bd9Sstevel@tonic-gate 
26797c478bd9Sstevel@tonic-gate 			free_olddrvdesc(v1_args.drivedescs);
26807c478bd9Sstevel@tonic-gate 
26817c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
26827c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
26837c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
26847c478bd9Sstevel@tonic-gate 				    "metad update drive dbinfo"));
26857c478bd9Sstevel@tonic-gate 			else
26867c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
26877c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
26887c478bd9Sstevel@tonic-gate 			rval = mdrpc_upd_dr_dbinfo_2(&v2_args, &res, clntp);
26897c478bd9Sstevel@tonic-gate 
26907c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
26917c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
26927c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
26937c478bd9Sstevel@tonic-gate 				    "metad update drive dbinfo"));
26947c478bd9Sstevel@tonic-gate 			else
26957c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
26967c478bd9Sstevel@tonic-gate 		}
26977c478bd9Sstevel@tonic-gate 
26987c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
26997c478bd9Sstevel@tonic-gate 	}
27007c478bd9Sstevel@tonic-gate 
27017c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
27027c478bd9Sstevel@tonic-gate 
27037c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
27047c478bd9Sstevel@tonic-gate 		return (-1);
27057c478bd9Sstevel@tonic-gate 
27067c478bd9Sstevel@tonic-gate 	return (0);
27077c478bd9Sstevel@tonic-gate }
27087c478bd9Sstevel@tonic-gate 
27097c478bd9Sstevel@tonic-gate /*
27107c478bd9Sstevel@tonic-gate  * update dr_flags field of drive record.
27117c478bd9Sstevel@tonic-gate  */
27127c478bd9Sstevel@tonic-gate int
clnt_upd_dr_flags(char * hostname,mdsetname_t * sp,md_drive_desc * dd,uint_t new_flags,md_error_t * ep)27137c478bd9Sstevel@tonic-gate clnt_upd_dr_flags(
27147c478bd9Sstevel@tonic-gate 	char			*hostname,
27157c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
27167c478bd9Sstevel@tonic-gate 	md_drive_desc		*dd,
27177c478bd9Sstevel@tonic-gate 	uint_t			new_flags,
27187c478bd9Sstevel@tonic-gate 	md_error_t		*ep
27197c478bd9Sstevel@tonic-gate )
27207c478bd9Sstevel@tonic-gate {
27217c478bd9Sstevel@tonic-gate 	CLIENT				*clntp;
27227c478bd9Sstevel@tonic-gate 	mdrpc_upd_dr_flags_args		v1_args;
27237c478bd9Sstevel@tonic-gate 	mdrpc_upd_dr_flags_2_args	v2_args;
27247c478bd9Sstevel@tonic-gate 	mdrpc_upd_dr_flags_2_args_r1	*v21_args;
27257c478bd9Sstevel@tonic-gate 	mdrpc_generic_res		res;
27267c478bd9Sstevel@tonic-gate 	int				rval;
27277c478bd9Sstevel@tonic-gate 	int				version;
27287c478bd9Sstevel@tonic-gate 
27297c478bd9Sstevel@tonic-gate 	/* initialize */
27307c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
27317c478bd9Sstevel@tonic-gate 	(void) memset(&v1_args, 0, sizeof (v1_args));
27327c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
27337c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
27347c478bd9Sstevel@tonic-gate 
27357c478bd9Sstevel@tonic-gate 	/* build args */
27367c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
27377c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_upd_dr_flags_2_args_u.rev1;
27387c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
27397c478bd9Sstevel@tonic-gate 	v21_args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
27407c478bd9Sstevel@tonic-gate 	v21_args->drivedescs = dd;
27417c478bd9Sstevel@tonic-gate 	v21_args->new_flags = new_flags;
27427c478bd9Sstevel@tonic-gate 
27437c478bd9Sstevel@tonic-gate 	/* do it */
27447c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
27457c478bd9Sstevel@tonic-gate 		int	bool;
27467c478bd9Sstevel@tonic-gate 
27477c478bd9Sstevel@tonic-gate 		/*
27487c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
27497c478bd9Sstevel@tonic-gate 		 */
27507c478bd9Sstevel@tonic-gate 		bool = mdrpc_upd_dr_flags_2_svc(&v2_args, &res, NULL);
27517c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
27527c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
27537c478bd9Sstevel@tonic-gate 	} else {
27547c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
27557c478bd9Sstevel@tonic-gate 			return (-1);
27567c478bd9Sstevel@tonic-gate 
27577c478bd9Sstevel@tonic-gate 		/*
27587c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
27597c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
27607c478bd9Sstevel@tonic-gate 		 * remote procedure
27617c478bd9Sstevel@tonic-gate 		 */
27627c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
27637c478bd9Sstevel@tonic-gate 
27647c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
27657c478bd9Sstevel@tonic-gate 
27667c478bd9Sstevel@tonic-gate 			alloc_olddrvdesc(&v1_args.drivedescs, dd);
27677c478bd9Sstevel@tonic-gate 
27687c478bd9Sstevel@tonic-gate 			/* build args */
27697c478bd9Sstevel@tonic-gate 			v1_args.sp = sp;
27707c478bd9Sstevel@tonic-gate 			v1_args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
27717c478bd9Sstevel@tonic-gate 			meta_conv_drvdesc_new2old(v1_args.drivedescs, dd);
27727c478bd9Sstevel@tonic-gate 			v1_args.new_flags = new_flags;
27737c478bd9Sstevel@tonic-gate 
27747c478bd9Sstevel@tonic-gate 			rval = mdrpc_upd_dr_flags_1(&v1_args, &res, clntp);
27757c478bd9Sstevel@tonic-gate 
27767c478bd9Sstevel@tonic-gate 			free_olddrvdesc(v1_args.drivedescs);
27777c478bd9Sstevel@tonic-gate 
27787c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
27797c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
27807c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
27817c478bd9Sstevel@tonic-gate 				    "metad update drive flags"));
27827c478bd9Sstevel@tonic-gate 			else
27837c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
27847c478bd9Sstevel@tonic-gate 		} else {			/* version 2 */
27857c478bd9Sstevel@tonic-gate 			rval = mdrpc_upd_dr_flags_2(&v2_args, &res, clntp);
27867c478bd9Sstevel@tonic-gate 
27877c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
27887c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
27897c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
27907c478bd9Sstevel@tonic-gate 				    "metad update drive flags"));
27917c478bd9Sstevel@tonic-gate 			else
27927c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
27937c478bd9Sstevel@tonic-gate 		}
27947c478bd9Sstevel@tonic-gate 
27957c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
27967c478bd9Sstevel@tonic-gate 	}
27977c478bd9Sstevel@tonic-gate 
27987c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
27997c478bd9Sstevel@tonic-gate 
28007c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
28017c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
28027c478bd9Sstevel@tonic-gate 			return (-1);
28037c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
28047c478bd9Sstevel@tonic-gate 			return (-1);
28057c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
28067c478bd9Sstevel@tonic-gate 	}
28077c478bd9Sstevel@tonic-gate 
28087c478bd9Sstevel@tonic-gate 	return (0);
28097c478bd9Sstevel@tonic-gate }
28107c478bd9Sstevel@tonic-gate 
28117c478bd9Sstevel@tonic-gate /*
28127c478bd9Sstevel@tonic-gate  * update set record flags
28137c478bd9Sstevel@tonic-gate  * This replaces all of the sr_flags with the new_flags.  It relies on the
28147c478bd9Sstevel@tonic-gate  * caller to "do the right thing" to preserve the existing flags that should
28157c478bd9Sstevel@tonic-gate  * not be reset.
28167c478bd9Sstevel@tonic-gate  */
28177c478bd9Sstevel@tonic-gate static int
upd_sr_flags_common(char * hostname,mdsetname_t * sp,uint_t new_flags,md_error_t * ep)28187c478bd9Sstevel@tonic-gate upd_sr_flags_common(
28197c478bd9Sstevel@tonic-gate 	char			*hostname,
28207c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
28217c478bd9Sstevel@tonic-gate 	uint_t			new_flags,
28227c478bd9Sstevel@tonic-gate 	md_error_t		*ep
28237c478bd9Sstevel@tonic-gate )
28247c478bd9Sstevel@tonic-gate {
28257c478bd9Sstevel@tonic-gate 	CLIENT				*clntp;
28267c478bd9Sstevel@tonic-gate 	mdrpc_upd_sr_flags_args		*args;
28277c478bd9Sstevel@tonic-gate 	mdrpc_upd_sr_flags_2_args	v2_args;
28287c478bd9Sstevel@tonic-gate 	mdrpc_generic_res		res;
28297c478bd9Sstevel@tonic-gate 	int				version;
28307c478bd9Sstevel@tonic-gate 
28317c478bd9Sstevel@tonic-gate 	/* initialize */
28327c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
28337c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
28347c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
28357c478bd9Sstevel@tonic-gate 
28367c478bd9Sstevel@tonic-gate 	/* build args */
28377c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
28387c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_upd_sr_flags_2_args_u.rev1;
28397c478bd9Sstevel@tonic-gate 	args->sp = sp;
28407c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
28417c478bd9Sstevel@tonic-gate 
28427c478bd9Sstevel@tonic-gate 	args->new_flags = new_flags;
28437c478bd9Sstevel@tonic-gate 
28447c478bd9Sstevel@tonic-gate 	/* do it */
28457c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
28467c478bd9Sstevel@tonic-gate 		int	bool;
28477c478bd9Sstevel@tonic-gate 		bool = mdrpc_upd_sr_flags_2_svc(&v2_args, &res, NULL);
28487c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
28497c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
28507c478bd9Sstevel@tonic-gate 	} else {
28517c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
28527c478bd9Sstevel@tonic-gate 			return (-1);
28537c478bd9Sstevel@tonic-gate 
28547c478bd9Sstevel@tonic-gate 		/*
28557c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
28567c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
28577c478bd9Sstevel@tonic-gate 		 * remote procedure
28587c478bd9Sstevel@tonic-gate 		 */
28597c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
28607c478bd9Sstevel@tonic-gate 
28617c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
28627c478bd9Sstevel@tonic-gate 			if (mdrpc_upd_sr_flags_1(args, &res, clntp) !=
28637c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
28647c478bd9Sstevel@tonic-gate 			    (void) mdrpcerror(ep, clntp, hostname,
28657c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad update set flags"));
28667c478bd9Sstevel@tonic-gate 			else
28677c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
28687c478bd9Sstevel@tonic-gate 		} else {
28697c478bd9Sstevel@tonic-gate 			if (mdrpc_upd_sr_flags_2(&v2_args, &res, clntp) !=
28707c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
28717c478bd9Sstevel@tonic-gate 			    (void) mdrpcerror(ep, clntp, hostname,
28727c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad update set flags"));
28737c478bd9Sstevel@tonic-gate 			else
28747c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
28757c478bd9Sstevel@tonic-gate 		}
28767c478bd9Sstevel@tonic-gate 
28777c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
28787c478bd9Sstevel@tonic-gate 	}
28797c478bd9Sstevel@tonic-gate 
28807c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
28817c478bd9Sstevel@tonic-gate 
28827c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
28837c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
28847c478bd9Sstevel@tonic-gate 			return (-1);
28857c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
28867c478bd9Sstevel@tonic-gate 			return (-1);
28877c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
28887c478bd9Sstevel@tonic-gate 	}
28897c478bd9Sstevel@tonic-gate 
28907c478bd9Sstevel@tonic-gate 	return (0);
28917c478bd9Sstevel@tonic-gate }
28927c478bd9Sstevel@tonic-gate 
28937c478bd9Sstevel@tonic-gate /*
28947c478bd9Sstevel@tonic-gate  * Enable bits in the set record flags field.  This just turns on the specified
28957c478bd9Sstevel@tonic-gate  * bits and leaves the other bits alone.
28967c478bd9Sstevel@tonic-gate  */
28977c478bd9Sstevel@tonic-gate int
clnt_enable_sr_flags(char * hostname,mdsetname_t * sp,uint_t flags,md_error_t * ep)28987c478bd9Sstevel@tonic-gate clnt_enable_sr_flags(
28997c478bd9Sstevel@tonic-gate 	char			*hostname,
29007c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
29017c478bd9Sstevel@tonic-gate 	uint_t			flags,
29027c478bd9Sstevel@tonic-gate 	md_error_t		*ep
29037c478bd9Sstevel@tonic-gate )
29047c478bd9Sstevel@tonic-gate {
29057c478bd9Sstevel@tonic-gate 	uint_t		new_flags;
29067c478bd9Sstevel@tonic-gate 	md_set_desc	*sd;
29077c478bd9Sstevel@tonic-gate 
29087c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
29097c478bd9Sstevel@tonic-gate 
29107c478bd9Sstevel@tonic-gate 	/* Get the flags from the current set */
29117c478bd9Sstevel@tonic-gate 	if ((sd = metaget_setdesc(sp, ep)) == NULL)
29127c478bd9Sstevel@tonic-gate 		return (-1);
29137c478bd9Sstevel@tonic-gate 
29147c478bd9Sstevel@tonic-gate 	/* Turn on the specified bits */
29157c478bd9Sstevel@tonic-gate 	new_flags = (sd->sd_flags | flags);
29167c478bd9Sstevel@tonic-gate 
29177c478bd9Sstevel@tonic-gate 	/* do it */
29187c478bd9Sstevel@tonic-gate 	return (upd_sr_flags_common(hostname, sp, new_flags, ep));
29197c478bd9Sstevel@tonic-gate }
29207c478bd9Sstevel@tonic-gate 
29217c478bd9Sstevel@tonic-gate /*
29227c478bd9Sstevel@tonic-gate  * Disable bits in the set record flags field.  This just turns off the
29237c478bd9Sstevel@tonic-gate  * specified bits and leaves the other bits alone.
29247c478bd9Sstevel@tonic-gate  */
29257c478bd9Sstevel@tonic-gate int
clnt_disable_sr_flags(char * hostname,mdsetname_t * sp,uint_t flags,md_error_t * ep)29267c478bd9Sstevel@tonic-gate clnt_disable_sr_flags(
29277c478bd9Sstevel@tonic-gate 	char			*hostname,
29287c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
29297c478bd9Sstevel@tonic-gate 	uint_t			flags,
29307c478bd9Sstevel@tonic-gate 	md_error_t		*ep
29317c478bd9Sstevel@tonic-gate )
29327c478bd9Sstevel@tonic-gate {
29337c478bd9Sstevel@tonic-gate 	uint_t		new_flags;
29347c478bd9Sstevel@tonic-gate 	md_set_desc	*sd;
29357c478bd9Sstevel@tonic-gate 
29367c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
29377c478bd9Sstevel@tonic-gate 
29387c478bd9Sstevel@tonic-gate 	/* Get the flags from the current set */
29397c478bd9Sstevel@tonic-gate 	if ((sd = metaget_setdesc(sp, ep)) == NULL)
29407c478bd9Sstevel@tonic-gate 		return (-1);
29417c478bd9Sstevel@tonic-gate 
29427c478bd9Sstevel@tonic-gate 	/* Turn off the specified bits */
29437c478bd9Sstevel@tonic-gate 	new_flags = (sd->sd_flags & ~flags);
29447c478bd9Sstevel@tonic-gate 
29457c478bd9Sstevel@tonic-gate 	/* do it */
29467c478bd9Sstevel@tonic-gate 	return (upd_sr_flags_common(hostname, sp, new_flags, ep));
29477c478bd9Sstevel@tonic-gate }
29487c478bd9Sstevel@tonic-gate 
29497c478bd9Sstevel@tonic-gate /*
29507c478bd9Sstevel@tonic-gate  * Assign the flags as the new value(s) for the MD_SR_STATE_FLAGS within the
29517c478bd9Sstevel@tonic-gate  * set record flags field.  This actually can set any bits but only clears
29527c478bd9Sstevel@tonic-gate  * the bits within the MD_SR_STATE_FLAGS subfield and leaves any other
29537c478bd9Sstevel@tonic-gate  * bits turned on.  It can be used to clear (state) and set bits all in one
29547c478bd9Sstevel@tonic-gate  * rpc call.
29557c478bd9Sstevel@tonic-gate  */
29567c478bd9Sstevel@tonic-gate int
clnt_upd_sr_flags(char * hostname,mdsetname_t * sp,uint_t flags,md_error_t * ep)29577c478bd9Sstevel@tonic-gate clnt_upd_sr_flags(
29587c478bd9Sstevel@tonic-gate 	char			*hostname,
29597c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
29607c478bd9Sstevel@tonic-gate 	uint_t			flags,
29617c478bd9Sstevel@tonic-gate 	md_error_t		*ep
29627c478bd9Sstevel@tonic-gate )
29637c478bd9Sstevel@tonic-gate {
29647c478bd9Sstevel@tonic-gate 	uint_t		new_flags;
29657c478bd9Sstevel@tonic-gate 	md_set_desc	*sd;
29667c478bd9Sstevel@tonic-gate 
29677c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
29687c478bd9Sstevel@tonic-gate 
29697c478bd9Sstevel@tonic-gate 	/* Get the flags from the current set */
29707c478bd9Sstevel@tonic-gate 	if ((sd = metaget_setdesc(sp, ep)) == NULL)
29717c478bd9Sstevel@tonic-gate 		return (-1);
29727c478bd9Sstevel@tonic-gate 
29737c478bd9Sstevel@tonic-gate 	/* clear the existing state flags */
29747c478bd9Sstevel@tonic-gate 	sd->sd_flags &= ~MD_SR_STATE_FLAGS;
29757c478bd9Sstevel@tonic-gate 
29767c478bd9Sstevel@tonic-gate 	/* Or in the new value */
29777c478bd9Sstevel@tonic-gate 	new_flags = (sd->sd_flags | flags);
29787c478bd9Sstevel@tonic-gate 
29797c478bd9Sstevel@tonic-gate 	/* do it */
29807c478bd9Sstevel@tonic-gate 	return (upd_sr_flags_common(hostname, sp, new_flags, ep));
29817c478bd9Sstevel@tonic-gate }
29827c478bd9Sstevel@tonic-gate 
29837c478bd9Sstevel@tonic-gate md_setkey_t *
cl_get_setkey(set_t setno,char * setname)29847c478bd9Sstevel@tonic-gate cl_get_setkey(set_t setno, char *setname)
29857c478bd9Sstevel@tonic-gate {
29867c478bd9Sstevel@tonic-gate 
29877c478bd9Sstevel@tonic-gate 	if (my_cl_sk == NULL) {
29887c478bd9Sstevel@tonic-gate 		my_cl_sk = Zalloc(sizeof (md_setkey_t));
29897c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_setno = setno;
29907c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_setname = Strdup(setname);
29917c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_host = Strdup(mynode());
29927c478bd9Sstevel@tonic-gate 	} else {
29937c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_setno = setno;
29947c478bd9Sstevel@tonic-gate 		if (my_cl_sk->sk_setname != NULL)
29957c478bd9Sstevel@tonic-gate 			Free(my_cl_sk->sk_setname);
29967c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_setname = Strdup(setname);
29977c478bd9Sstevel@tonic-gate 	}
29987c478bd9Sstevel@tonic-gate 
29997c478bd9Sstevel@tonic-gate 	return (my_cl_sk);
30007c478bd9Sstevel@tonic-gate }
30017c478bd9Sstevel@tonic-gate 
30027c478bd9Sstevel@tonic-gate void
cl_set_setkey(md_setkey_t * cl_sk)30037c478bd9Sstevel@tonic-gate cl_set_setkey(md_setkey_t *cl_sk)
30047c478bd9Sstevel@tonic-gate {
30057c478bd9Sstevel@tonic-gate 	if ((cl_sk != NULL) && (my_cl_sk != NULL)) {
30067c478bd9Sstevel@tonic-gate 		assert(my_cl_sk->sk_setno == cl_sk->sk_setno);
30077c478bd9Sstevel@tonic-gate 		assert(strcmp(my_cl_sk->sk_setname, cl_sk->sk_setname) == 0);
30087c478bd9Sstevel@tonic-gate 		assert(strcmp(my_cl_sk->sk_host, cl_sk->sk_host) == 0);
30097c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_key = cl_sk->sk_key;
30107c478bd9Sstevel@tonic-gate 		return;
30117c478bd9Sstevel@tonic-gate 	}
30127c478bd9Sstevel@tonic-gate 
30137c478bd9Sstevel@tonic-gate 	if (my_cl_sk != NULL) {
30147c478bd9Sstevel@tonic-gate 		if (my_cl_sk->sk_setname != NULL)
30157c478bd9Sstevel@tonic-gate 			Free(my_cl_sk->sk_setname);
30167c478bd9Sstevel@tonic-gate 		if (my_cl_sk->sk_host != NULL)
30177c478bd9Sstevel@tonic-gate 			Free(my_cl_sk->sk_host);
30187c478bd9Sstevel@tonic-gate 		Free(my_cl_sk);
30197c478bd9Sstevel@tonic-gate 	}
30207c478bd9Sstevel@tonic-gate 
30217c478bd9Sstevel@tonic-gate 	my_cl_sk = NULL;
30227c478bd9Sstevel@tonic-gate 
30237c478bd9Sstevel@tonic-gate 	/* get here, if set called before get */
30247c478bd9Sstevel@tonic-gate 	if (cl_sk != NULL) {
30257c478bd9Sstevel@tonic-gate 		my_cl_sk = Zalloc(sizeof (md_setkey_t));
30267c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_host = Strdup(cl_sk->sk_host);
30277c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_setno = cl_sk->sk_setno;
30287c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_setname = Strdup(cl_sk->sk_setname);
30297c478bd9Sstevel@tonic-gate 		my_cl_sk->sk_key = cl_sk->sk_key;
30307c478bd9Sstevel@tonic-gate 	}
30317c478bd9Sstevel@tonic-gate }
30327c478bd9Sstevel@tonic-gate 
30337c478bd9Sstevel@tonic-gate /*
30347c478bd9Sstevel@tonic-gate  * Unlock the set after operation is complete.
30357c478bd9Sstevel@tonic-gate  */
30367c478bd9Sstevel@tonic-gate int
clnt_unlock_set(char * hostname,md_setkey_t * cl_sk,md_error_t * ep)30377c478bd9Sstevel@tonic-gate clnt_unlock_set(
30387c478bd9Sstevel@tonic-gate 	char			*hostname,
30397c478bd9Sstevel@tonic-gate 	md_setkey_t		*cl_sk,
30407c478bd9Sstevel@tonic-gate 	md_error_t		*ep
30417c478bd9Sstevel@tonic-gate )
30427c478bd9Sstevel@tonic-gate {
30437c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
30447c478bd9Sstevel@tonic-gate 	mdrpc_null_args		args;
30457c478bd9Sstevel@tonic-gate 	mdrpc_setlock_res	res;
30467c478bd9Sstevel@tonic-gate 
30477c478bd9Sstevel@tonic-gate 	/* initialize */
30487c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
30497c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
30507c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
30517c478bd9Sstevel@tonic-gate 
30527c478bd9Sstevel@tonic-gate 	/* build args */
30537c478bd9Sstevel@tonic-gate 	args.cl_sk = cl_sk;
30547c478bd9Sstevel@tonic-gate 
30557c478bd9Sstevel@tonic-gate 	/* do it */
30567c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
30577c478bd9Sstevel@tonic-gate 		int	bool;
30587c478bd9Sstevel@tonic-gate 		bool = mdrpc_unlock_set_1_svc(&args, &res, NULL);
30597c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
30607c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
30617c478bd9Sstevel@tonic-gate 	} else {
30627c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
30637c478bd9Sstevel@tonic-gate 			return (-1);
30647c478bd9Sstevel@tonic-gate 
30657c478bd9Sstevel@tonic-gate 		if (mdrpc_unlock_set_1(&args, &res, clntp) != RPC_SUCCESS)
30667c478bd9Sstevel@tonic-gate 			(void) mdrpcerror(ep, clntp, hostname,
30677c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad unlock set"));
30687c478bd9Sstevel@tonic-gate 		else
30697c478bd9Sstevel@tonic-gate 			(void) mdstealerror(ep, &res.status);
30707c478bd9Sstevel@tonic-gate 
30717c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
30727c478bd9Sstevel@tonic-gate 	}
30737c478bd9Sstevel@tonic-gate 
30747c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_setlock_res, (char *)&res);
30757c478bd9Sstevel@tonic-gate 
30767c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
30777c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
30787c478bd9Sstevel@tonic-gate 			return (-1);
30797c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
30807c478bd9Sstevel@tonic-gate 			return (-1);
30817c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
30827c478bd9Sstevel@tonic-gate 	}
30837c478bd9Sstevel@tonic-gate 
30847c478bd9Sstevel@tonic-gate 	return (0);
30857c478bd9Sstevel@tonic-gate }
30867c478bd9Sstevel@tonic-gate 
30877c478bd9Sstevel@tonic-gate /*
30887c478bd9Sstevel@tonic-gate  * Lock set so that only operators with valid keys are allowed in the daemon.
30897c478bd9Sstevel@tonic-gate  */
30907c478bd9Sstevel@tonic-gate int
clnt_lock_set(char * hostname,mdsetname_t * sp,md_error_t * ep)30917c478bd9Sstevel@tonic-gate clnt_lock_set(
30927c478bd9Sstevel@tonic-gate 	char			*hostname,
30937c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
30947c478bd9Sstevel@tonic-gate 	md_error_t		*ep
30957c478bd9Sstevel@tonic-gate )
30967c478bd9Sstevel@tonic-gate {
30977c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
30987c478bd9Sstevel@tonic-gate 	mdrpc_null_args		args;
30997c478bd9Sstevel@tonic-gate 	mdrpc_setlock_res	res;
31007c478bd9Sstevel@tonic-gate 
31017c478bd9Sstevel@tonic-gate 	/* initialize */
31027c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
31037c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
31047c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
31057c478bd9Sstevel@tonic-gate 
31067c478bd9Sstevel@tonic-gate 	/* build args */
31077c478bd9Sstevel@tonic-gate 	args.cl_sk = cl_get_setkey(sp->setno, sp->setname);
31087c478bd9Sstevel@tonic-gate 
31097c478bd9Sstevel@tonic-gate 	/* do it */
31107c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
31117c478bd9Sstevel@tonic-gate 		int	bool;
31127c478bd9Sstevel@tonic-gate 		bool = mdrpc_lock_set_1_svc(&args, &res, NULL);
31137c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
31147c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
31157c478bd9Sstevel@tonic-gate 	} else {
31167c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
31177c478bd9Sstevel@tonic-gate 			return (-1);
31187c478bd9Sstevel@tonic-gate 
31197c478bd9Sstevel@tonic-gate 		if (mdrpc_lock_set_1(&args, &res, clntp) != RPC_SUCCESS)
31207c478bd9Sstevel@tonic-gate 			(void) mdrpcerror(ep, clntp, hostname,
31217c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad lock set"));
31227c478bd9Sstevel@tonic-gate 		else
31237c478bd9Sstevel@tonic-gate 			(void) mdstealerror(ep, &res.status);
31247c478bd9Sstevel@tonic-gate 
31257c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
31267c478bd9Sstevel@tonic-gate 	}
31277c478bd9Sstevel@tonic-gate 
31287c478bd9Sstevel@tonic-gate 	if (mdisok(ep))
31297c478bd9Sstevel@tonic-gate 		cl_set_setkey(res.cl_sk);
31307c478bd9Sstevel@tonic-gate 
31317c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_setlock_res, (char *)&res);
31327c478bd9Sstevel@tonic-gate 
31337c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
31347c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
31357c478bd9Sstevel@tonic-gate 			return (-1);
31367c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
31377c478bd9Sstevel@tonic-gate 			return (-1);
31387c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
31397c478bd9Sstevel@tonic-gate 	}
31407c478bd9Sstevel@tonic-gate 
31417c478bd9Sstevel@tonic-gate 	return (0);
31427c478bd9Sstevel@tonic-gate }
31437c478bd9Sstevel@tonic-gate 
31447c478bd9Sstevel@tonic-gate /*
31457c478bd9Sstevel@tonic-gate  * Add mediator hosts to disksets.
31467c478bd9Sstevel@tonic-gate  */
31477c478bd9Sstevel@tonic-gate int
clnt_updmeds(char * hostname,mdsetname_t * sp,md_h_arr_t * medp,md_error_t * ep)31487c478bd9Sstevel@tonic-gate clnt_updmeds(
31497c478bd9Sstevel@tonic-gate 	char			*hostname,
31507c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
31517c478bd9Sstevel@tonic-gate 	md_h_arr_t		*medp,
31527c478bd9Sstevel@tonic-gate 	md_error_t		*ep
31537c478bd9Sstevel@tonic-gate )
31547c478bd9Sstevel@tonic-gate {
31557c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
31567c478bd9Sstevel@tonic-gate 	mdrpc_updmeds_args	*args;
31577c478bd9Sstevel@tonic-gate 	mdrpc_updmeds_2_args	v2_args;
31587c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
31597c478bd9Sstevel@tonic-gate 	int			version;
31607c478bd9Sstevel@tonic-gate 
31617c478bd9Sstevel@tonic-gate 	/* initialize */
31627c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
31637c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
31647c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
31657c478bd9Sstevel@tonic-gate 
31667c478bd9Sstevel@tonic-gate 	/* build args */
31677c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
31687c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_updmeds_2_args_u.rev1;
31697c478bd9Sstevel@tonic-gate 	args->sp = sp;
31707c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
31717c478bd9Sstevel@tonic-gate 	args->meds = *medp;			/* structure assignment */
31727c478bd9Sstevel@tonic-gate 
31737c478bd9Sstevel@tonic-gate 	/* do it */
31747c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
31757c478bd9Sstevel@tonic-gate 		int bool;
31767c478bd9Sstevel@tonic-gate 		bool = mdrpc_updmeds_2_svc(&v2_args, &res, NULL);
31777c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
31787c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
31797c478bd9Sstevel@tonic-gate 	} else {
31807c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
31817c478bd9Sstevel@tonic-gate 			return (-1);
31827c478bd9Sstevel@tonic-gate 
31837c478bd9Sstevel@tonic-gate 		/*
31847c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
31857c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
31867c478bd9Sstevel@tonic-gate 		 * remote procedure
31877c478bd9Sstevel@tonic-gate 		 */
31887c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
31897c478bd9Sstevel@tonic-gate 
31907c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) {	/* version 1 */
31917c478bd9Sstevel@tonic-gate 			if (mdrpc_updmeds_1(args, &res, clntp) != RPC_SUCCESS)
31927c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
31937c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad add hosts"));
31947c478bd9Sstevel@tonic-gate 			else
31957c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
31967c478bd9Sstevel@tonic-gate 		} else {
31977c478bd9Sstevel@tonic-gate 			if (mdrpc_updmeds_2(&v2_args, &res, clntp) !=
31987c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
31997c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
32007c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad add hosts"));
32017c478bd9Sstevel@tonic-gate 			else
32027c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
32037c478bd9Sstevel@tonic-gate 		}
32047c478bd9Sstevel@tonic-gate 
32057c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
32067c478bd9Sstevel@tonic-gate 	}
32077c478bd9Sstevel@tonic-gate 
32087c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
32097c478bd9Sstevel@tonic-gate 
32107c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
32117c478bd9Sstevel@tonic-gate 		return (-1);
32127c478bd9Sstevel@tonic-gate 
32137c478bd9Sstevel@tonic-gate 	return (0);
32147c478bd9Sstevel@tonic-gate }
32157c478bd9Sstevel@tonic-gate 
32167c478bd9Sstevel@tonic-gate /*
32177c478bd9Sstevel@tonic-gate  * update nr_flags field of node records based
32187c478bd9Sstevel@tonic-gate  * on given action.
32197c478bd9Sstevel@tonic-gate  */
32207c478bd9Sstevel@tonic-gate int
clnt_upd_nr_flags(char * hostname,mdsetname_t * sp,md_mnnode_desc * nd,uint_t flag_action,uint_t flags,md_error_t * ep)32217c478bd9Sstevel@tonic-gate clnt_upd_nr_flags(
32227c478bd9Sstevel@tonic-gate 	char			*hostname,
32237c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
32247c478bd9Sstevel@tonic-gate 	md_mnnode_desc		*nd,
32257c478bd9Sstevel@tonic-gate 	uint_t			flag_action,
32267c478bd9Sstevel@tonic-gate 	uint_t			flags,
32277c478bd9Sstevel@tonic-gate 	md_error_t		*ep
32287c478bd9Sstevel@tonic-gate )
32297c478bd9Sstevel@tonic-gate {
32307c478bd9Sstevel@tonic-gate 	CLIENT				*clntp;
32317c478bd9Sstevel@tonic-gate 	mdrpc_upd_nr_flags_args		*args;
32327c478bd9Sstevel@tonic-gate 	mdrpc_upd_nr_flags_2_args	v2_args;
32337c478bd9Sstevel@tonic-gate 	mdrpc_generic_res		res;
32347c478bd9Sstevel@tonic-gate 	int				version;
32357c478bd9Sstevel@tonic-gate 
32367c478bd9Sstevel@tonic-gate 	/* initialize */
32377c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
32387c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
32397c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
32407c478bd9Sstevel@tonic-gate 
32417c478bd9Sstevel@tonic-gate 	/* build args */
32427c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
32437c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_upd_nr_flags_2_args_u.rev1;
32447c478bd9Sstevel@tonic-gate 	args->sp = sp;
32457c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
32467c478bd9Sstevel@tonic-gate 	args->nodedescs = nd;
32477c478bd9Sstevel@tonic-gate 	args->flag_action = flag_action;
32487c478bd9Sstevel@tonic-gate 	args->flags = flags;
32497c478bd9Sstevel@tonic-gate 
32507c478bd9Sstevel@tonic-gate 	/* do it */
32517c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
32527c478bd9Sstevel@tonic-gate 		int	bool;
32537c478bd9Sstevel@tonic-gate 		bool = mdrpc_upd_nr_flags_2_svc(&v2_args, &res, NULL);
32547c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
32557c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
32567c478bd9Sstevel@tonic-gate 	} else {
32577c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
32587c478bd9Sstevel@tonic-gate 			return (-1);
32597c478bd9Sstevel@tonic-gate 
32607c478bd9Sstevel@tonic-gate 		/*
32617c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
32627c478bd9Sstevel@tonic-gate 		 */
32637c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
32647c478bd9Sstevel@tonic-gate 
32657c478bd9Sstevel@tonic-gate 		/*
32667c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
32677c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
32687c478bd9Sstevel@tonic-gate 		 */
32697c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
32707c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
32717c478bd9Sstevel@tonic-gate 				sp->setno, hostname, NULL, sp->setname);
32727c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
32737c478bd9Sstevel@tonic-gate 			return (-1);
32747c478bd9Sstevel@tonic-gate 		} else {
32757c478bd9Sstevel@tonic-gate 			if (mdrpc_upd_nr_flags_2(&v2_args, &res, clntp)
32767c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
32777c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
32787c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
32797c478bd9Sstevel@tonic-gate 				    "metad set node flags"));
32807c478bd9Sstevel@tonic-gate 			else
32817c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
32827c478bd9Sstevel@tonic-gate 		}
32837c478bd9Sstevel@tonic-gate 
32847c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
32857c478bd9Sstevel@tonic-gate 	}
32867c478bd9Sstevel@tonic-gate 
32877c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
32887c478bd9Sstevel@tonic-gate 
32897c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
32907c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
32917c478bd9Sstevel@tonic-gate 			return (-1);
32927c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
32937c478bd9Sstevel@tonic-gate 			return (-1);
32947c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
32957c478bd9Sstevel@tonic-gate 	}
32967c478bd9Sstevel@tonic-gate 
32977c478bd9Sstevel@tonic-gate 	return (0);
32987c478bd9Sstevel@tonic-gate }
32997c478bd9Sstevel@tonic-gate 
33007c478bd9Sstevel@tonic-gate /*
33017c478bd9Sstevel@tonic-gate  * Clear set locks for all MN disksets.
33027c478bd9Sstevel@tonic-gate  * Used during reconfig cycle to recover from failed nodes.
33037c478bd9Sstevel@tonic-gate  */
33047c478bd9Sstevel@tonic-gate int
clnt_clr_mnsetlock(char * hostname,md_error_t * ep)33057c478bd9Sstevel@tonic-gate clnt_clr_mnsetlock(
33067c478bd9Sstevel@tonic-gate 	char			*hostname,
33077c478bd9Sstevel@tonic-gate 	md_error_t		*ep
33087c478bd9Sstevel@tonic-gate )
33097c478bd9Sstevel@tonic-gate {
33107c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
33117c478bd9Sstevel@tonic-gate 	mdrpc_null_args		args;
33127c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
33137c478bd9Sstevel@tonic-gate 	int			version;
33147c478bd9Sstevel@tonic-gate 
33157c478bd9Sstevel@tonic-gate 	/* initialize */
33167c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
33177c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
33187c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
33197c478bd9Sstevel@tonic-gate 
33207c478bd9Sstevel@tonic-gate 	/* do it */
33217c478bd9Sstevel@tonic-gate 	if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
33227c478bd9Sstevel@tonic-gate 		return (-1);
33237c478bd9Sstevel@tonic-gate 
33247c478bd9Sstevel@tonic-gate 	/*
33257c478bd9Sstevel@tonic-gate 	 * Check the client handle for the version
33267c478bd9Sstevel@tonic-gate 	 */
33277c478bd9Sstevel@tonic-gate 	CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
33287c478bd9Sstevel@tonic-gate 
33297c478bd9Sstevel@tonic-gate 	/*
33307c478bd9Sstevel@tonic-gate 	 * If the client is version 1, return error
33317c478bd9Sstevel@tonic-gate 	 * otherwise, make the remote procedure call.
33327c478bd9Sstevel@tonic-gate 	 */
33337c478bd9Sstevel@tonic-gate 	if (version == METAD_VERSION) { /* version 1 */
33347c478bd9Sstevel@tonic-gate 		(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
33357c478bd9Sstevel@tonic-gate 			NULL, hostname, NULL, NULL);
33367c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
33377c478bd9Sstevel@tonic-gate 		return (-1);
33387c478bd9Sstevel@tonic-gate 	} else {
33397c478bd9Sstevel@tonic-gate 		if (mdrpc_clr_mnsetlock_2(&args, &res, clntp) != RPC_SUCCESS)
33407c478bd9Sstevel@tonic-gate 			(void) mdrpcerror(ep, clntp, hostname,
33417c478bd9Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "metad clr mnsetlock"));
33427c478bd9Sstevel@tonic-gate 		else
33437c478bd9Sstevel@tonic-gate 			(void) mdstealerror(ep, &res.status);
33447c478bd9Sstevel@tonic-gate 	}
33457c478bd9Sstevel@tonic-gate 
33467c478bd9Sstevel@tonic-gate 	metarpcclose(clntp);
33477c478bd9Sstevel@tonic-gate 
33487c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
33497c478bd9Sstevel@tonic-gate 
33507c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
33517c478bd9Sstevel@tonic-gate 		return (-1);
33527c478bd9Sstevel@tonic-gate 
33537c478bd9Sstevel@tonic-gate 	return (0);
33547c478bd9Sstevel@tonic-gate }
33557c478bd9Sstevel@tonic-gate 
33567c478bd9Sstevel@tonic-gate /*
33577c478bd9Sstevel@tonic-gate  * Calls to suspend, resume or reinit the rpc.mdcommd daemon.
33587c478bd9Sstevel@tonic-gate  * This allows a node to remotely suspend, reinit and resume the
33597c478bd9Sstevel@tonic-gate  * rpc.mdcommd daemon on the given hostname node.  Used by libmeta
33607c478bd9Sstevel@tonic-gate  * to lock out class 1 messages (metainit, etc) on all nodes when running
33617c478bd9Sstevel@tonic-gate  * metaset and metadb commands on this node.
33627c478bd9Sstevel@tonic-gate  *
33637c478bd9Sstevel@tonic-gate  * When suspending the commd, the suspend request will fail until all
33647c478bd9Sstevel@tonic-gate  * messages have been drained from the rpc.mdcommd.  This routine will
33657c478bd9Sstevel@tonic-gate  * spin sending the suspend request until the rpc.mdcommd is drained
33667c478bd9Sstevel@tonic-gate  * or until rpc.mdcommd returns a failure other than MDMNE_SET_NOT_DRAINED.
33677c478bd9Sstevel@tonic-gate  *
33687c478bd9Sstevel@tonic-gate  * Also used to send the rpc.mdcommd daemon a new nodelist by draining all
33697c478bd9Sstevel@tonic-gate  * messages from the mdcommd and sending a reinit command to have mdcommd
33707c478bd9Sstevel@tonic-gate  * get the new nodelist from rpc.metad.  Used when nodelist is changed
33717c478bd9Sstevel@tonic-gate  * during:
33727c478bd9Sstevel@tonic-gate  *	- addition or deletion of host from diskset
33737c478bd9Sstevel@tonic-gate  *	- join or withdrawal of host from diskset
33747c478bd9Sstevel@tonic-gate  *	- addition of first disk to diskset (joins all nodes)
33757c478bd9Sstevel@tonic-gate  *	- removal of last disk from diskset (withdraws all nodes)
33767c478bd9Sstevel@tonic-gate  */
33777c478bd9Sstevel@tonic-gate int
clnt_mdcommdctl(char * hostname,int flag_action,mdsetname_t * sp,md_mn_msgclass_t class,uint_t flags,md_error_t * ep)33787c478bd9Sstevel@tonic-gate clnt_mdcommdctl(
33797c478bd9Sstevel@tonic-gate 	char			*hostname,
33807c478bd9Sstevel@tonic-gate 	int			flag_action,
33817c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
33827c478bd9Sstevel@tonic-gate 	md_mn_msgclass_t	class,
33837c478bd9Sstevel@tonic-gate 	uint_t			flags,
33847c478bd9Sstevel@tonic-gate 	md_error_t		*ep
33857c478bd9Sstevel@tonic-gate )
33867c478bd9Sstevel@tonic-gate {
33877c478bd9Sstevel@tonic-gate 	CLIENT				*clntp;
33887c478bd9Sstevel@tonic-gate 	mdrpc_mdcommdctl_args		*args;
33897c478bd9Sstevel@tonic-gate 	mdrpc_mdcommdctl_2_args		v2_args;
33907c478bd9Sstevel@tonic-gate 	mdrpc_generic_res		res;
33917c478bd9Sstevel@tonic-gate 	int				version;
33927c478bd9Sstevel@tonic-gate 	int				suspend_spin = 0;
33937c478bd9Sstevel@tonic-gate 
33947c478bd9Sstevel@tonic-gate 	/* initialize */
33957c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
33967c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
33977c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
33987c478bd9Sstevel@tonic-gate 
33997c478bd9Sstevel@tonic-gate 	/* build args */
34007c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
34017c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_mdcommdctl_2_args_u.rev1;
34027c478bd9Sstevel@tonic-gate 	args->flag_action = flag_action;
34037c478bd9Sstevel@tonic-gate 	args->setno = sp->setno;
34047c478bd9Sstevel@tonic-gate 	args->class = class;
34057c478bd9Sstevel@tonic-gate 	args->flags = flags;
34067c478bd9Sstevel@tonic-gate 
34077c478bd9Sstevel@tonic-gate 	/* do it */
34087c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
34097c478bd9Sstevel@tonic-gate 		int	bool;
34107c478bd9Sstevel@tonic-gate 		/*
34117c478bd9Sstevel@tonic-gate 		 * Call v2 procedure directly if rpc.metad on this node is
34127c478bd9Sstevel@tonic-gate 		 * sending message to itself.
34137c478bd9Sstevel@tonic-gate 		 */
34147c478bd9Sstevel@tonic-gate 		if (flag_action == COMMDCTL_SUSPEND) {
34157c478bd9Sstevel@tonic-gate 			suspend_spin = 1;
34167c478bd9Sstevel@tonic-gate 			while (suspend_spin) {
34177c478bd9Sstevel@tonic-gate 				suspend_spin = 0;
34187c478bd9Sstevel@tonic-gate 				bool = mdrpc_mdcommdctl_2_svc(&v2_args, &res,
34197c478bd9Sstevel@tonic-gate 					NULL);
34207c478bd9Sstevel@tonic-gate 				assert(bool == TRUE);
34217c478bd9Sstevel@tonic-gate 				/*
34227c478bd9Sstevel@tonic-gate 				 * If set not yet drained, wait a second
34237c478bd9Sstevel@tonic-gate 				 * and try again.
34247c478bd9Sstevel@tonic-gate 				 */
34257c478bd9Sstevel@tonic-gate 				if (mdisdserror(&(res.status),
34267c478bd9Sstevel@tonic-gate 				    MDE_DS_COMMDCTL_SUSPEND_NYD)) {
34277c478bd9Sstevel@tonic-gate 					/* Wait a second and try again */
34287c478bd9Sstevel@tonic-gate 					mdclrerror(&(res.status));
34297c478bd9Sstevel@tonic-gate 					(void) sleep(1);
34307c478bd9Sstevel@tonic-gate 					suspend_spin = 1;
34317c478bd9Sstevel@tonic-gate 				}
34327c478bd9Sstevel@tonic-gate 			}
34337c478bd9Sstevel@tonic-gate 		} else {
34347c478bd9Sstevel@tonic-gate 			bool = mdrpc_mdcommdctl_2_svc(&v2_args, &res, NULL);
34357c478bd9Sstevel@tonic-gate 			assert(bool == TRUE);
34367c478bd9Sstevel@tonic-gate 		}
34377c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
34387c478bd9Sstevel@tonic-gate 	} else {
34397c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
34407c478bd9Sstevel@tonic-gate 			return (-1);
34417c478bd9Sstevel@tonic-gate 
34427c478bd9Sstevel@tonic-gate 		/*
34437c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
34447c478bd9Sstevel@tonic-gate 		 */
34457c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
34467c478bd9Sstevel@tonic-gate 
34477c478bd9Sstevel@tonic-gate 		/*
34487c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
34497c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
34507c478bd9Sstevel@tonic-gate 		 */
34517c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
34527c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
34537c478bd9Sstevel@tonic-gate 				sp->setno, hostname, NULL, sp->setname);
34547c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
34557c478bd9Sstevel@tonic-gate 			return (-1);
34567c478bd9Sstevel@tonic-gate 		}
34577c478bd9Sstevel@tonic-gate 
34587c478bd9Sstevel@tonic-gate 		if (flag_action == COMMDCTL_SUSPEND) {
34597c478bd9Sstevel@tonic-gate 			suspend_spin = 1;
34607c478bd9Sstevel@tonic-gate 			while (suspend_spin) {
34617c478bd9Sstevel@tonic-gate 				suspend_spin = 0;
34627c478bd9Sstevel@tonic-gate 				if (mdrpc_mdcommdctl_2(&v2_args, &res,
34637c478bd9Sstevel@tonic-gate 				    clntp) != RPC_SUCCESS) {
34647c478bd9Sstevel@tonic-gate 					(void) mdrpcerror(ep, clntp,
34657c478bd9Sstevel@tonic-gate 					    hostname,
34667c478bd9Sstevel@tonic-gate 					    dgettext(TEXT_DOMAIN,
34677c478bd9Sstevel@tonic-gate 					    "metad commd control"));
34687c478bd9Sstevel@tonic-gate 				} else {
34697c478bd9Sstevel@tonic-gate 					/*
34707c478bd9Sstevel@tonic-gate 					 * If set not yet drained,
34717c478bd9Sstevel@tonic-gate 					 * wait a second and
34727c478bd9Sstevel@tonic-gate 					 * and try again.
34737c478bd9Sstevel@tonic-gate 					 */
34747c478bd9Sstevel@tonic-gate 					if (mdisdserror(&(res.status),
34757c478bd9Sstevel@tonic-gate 					    MDE_DS_COMMDCTL_SUSPEND_NYD)) {
34767c478bd9Sstevel@tonic-gate 						mdclrerror(&(res.status));
34777c478bd9Sstevel@tonic-gate 						(void) sleep(1);
34787c478bd9Sstevel@tonic-gate 						suspend_spin = 1;
34797c478bd9Sstevel@tonic-gate 					} else {
34807c478bd9Sstevel@tonic-gate 						(void) mdstealerror(ep,
34817c478bd9Sstevel@tonic-gate 						    &res.status);
34827c478bd9Sstevel@tonic-gate 					}
34837c478bd9Sstevel@tonic-gate 				}
34847c478bd9Sstevel@tonic-gate 			}
34857c478bd9Sstevel@tonic-gate 		} else {
34867c478bd9Sstevel@tonic-gate 			if (mdrpc_mdcommdctl_2(&v2_args, &res, clntp)
34877c478bd9Sstevel@tonic-gate 			    != RPC_SUCCESS)
34887c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
34897c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
34907c478bd9Sstevel@tonic-gate 				    "metad commd control"));
34917c478bd9Sstevel@tonic-gate 			else
34927c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
34937c478bd9Sstevel@tonic-gate 		}
34947c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
34957c478bd9Sstevel@tonic-gate 	}
34967c478bd9Sstevel@tonic-gate 
34977c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
34987c478bd9Sstevel@tonic-gate 
34997c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
35007c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
35017c478bd9Sstevel@tonic-gate 			return (-1);
35027c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
35037c478bd9Sstevel@tonic-gate 			return (-1);
35047c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
35057c478bd9Sstevel@tonic-gate 	}
35067c478bd9Sstevel@tonic-gate 
35077c478bd9Sstevel@tonic-gate 	return (0);
35087c478bd9Sstevel@tonic-gate }
35097c478bd9Sstevel@tonic-gate 
35107c478bd9Sstevel@tonic-gate /*
35117c478bd9Sstevel@tonic-gate  * Is owner node stale?
35127c478bd9Sstevel@tonic-gate  */
35137c478bd9Sstevel@tonic-gate int
clnt_mn_is_stale(char * hostname,mdsetname_t * sp,int * ret_bool,md_error_t * ep)35147c478bd9Sstevel@tonic-gate clnt_mn_is_stale(
35157c478bd9Sstevel@tonic-gate 	char			*hostname,
35167c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
35177c478bd9Sstevel@tonic-gate 	int			*ret_bool,
35187c478bd9Sstevel@tonic-gate 	md_error_t		*ep
35197c478bd9Sstevel@tonic-gate )
35207c478bd9Sstevel@tonic-gate {
35217c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
35227c478bd9Sstevel@tonic-gate 	mdrpc_setno_args	*args;
35237c478bd9Sstevel@tonic-gate 	mdrpc_setno_2_args	v2_args;
35247c478bd9Sstevel@tonic-gate 	mdrpc_bool_res		res;
35257c478bd9Sstevel@tonic-gate 	int			rval = -1;
35267c478bd9Sstevel@tonic-gate 	int			version;
35277c478bd9Sstevel@tonic-gate 
35287c478bd9Sstevel@tonic-gate 	/* initialize */
35297c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
35307c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
35317c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
35327c478bd9Sstevel@tonic-gate 
35337c478bd9Sstevel@tonic-gate 	/* build args */
35347c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
35357c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_setno_2_args_u.rev1;
35367c478bd9Sstevel@tonic-gate 	args->setno = sp->setno;
35377c478bd9Sstevel@tonic-gate 
35387c478bd9Sstevel@tonic-gate 	/* do it */
35397c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
35407c478bd9Sstevel@tonic-gate 		int	bool;
35417c478bd9Sstevel@tonic-gate 		/*
35427c478bd9Sstevel@tonic-gate 		 * Call v2 procedure directly if rpc.metad on this node is
35437c478bd9Sstevel@tonic-gate 		 * sending message to itself.
35447c478bd9Sstevel@tonic-gate 		 */
35457c478bd9Sstevel@tonic-gate 		bool = mdrpc_mn_is_stale_2_svc(&v2_args, &res, NULL);
35467c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
35477c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
35487c478bd9Sstevel@tonic-gate 	} else {
35497c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
35507c478bd9Sstevel@tonic-gate 			return (-1);
35517c478bd9Sstevel@tonic-gate 
35527c478bd9Sstevel@tonic-gate 		/*
35537c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
35547c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
35557c478bd9Sstevel@tonic-gate 		 * remote procedure
35567c478bd9Sstevel@tonic-gate 		 */
35577c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
35587c478bd9Sstevel@tonic-gate 
35597c478bd9Sstevel@tonic-gate 		/*
35607c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
35617c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
35627c478bd9Sstevel@tonic-gate 		 */
35637c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
35647c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
35657c478bd9Sstevel@tonic-gate 			    sp->setno, hostname, NULL, sp->setname);
35667c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
35677c478bd9Sstevel@tonic-gate 			return (-1);
35687c478bd9Sstevel@tonic-gate 		} else {
35697c478bd9Sstevel@tonic-gate 			if (mdrpc_mn_is_stale_2(&v2_args, &res, clntp) !=
35707c478bd9Sstevel@tonic-gate 			    RPC_SUCCESS)
35717c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
35727c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN, "metad mn is stale"));
35737c478bd9Sstevel@tonic-gate 			else
35747c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
35757c478bd9Sstevel@tonic-gate 		}
35767c478bd9Sstevel@tonic-gate 
35777c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
35787c478bd9Sstevel@tonic-gate 	}
35797c478bd9Sstevel@tonic-gate 
35807c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
35817c478bd9Sstevel@tonic-gate 		/* do something with the results */
35827c478bd9Sstevel@tonic-gate 		rval = 0;
35837c478bd9Sstevel@tonic-gate 
35847c478bd9Sstevel@tonic-gate 		if (ret_bool != NULL)
35857c478bd9Sstevel@tonic-gate 			*ret_bool = res.value;
35867c478bd9Sstevel@tonic-gate 	}
35877c478bd9Sstevel@tonic-gate 
35887c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_bool_res, (char *)&res);
35897c478bd9Sstevel@tonic-gate 
35907c478bd9Sstevel@tonic-gate 	return (rval);
35917c478bd9Sstevel@tonic-gate }
35927c478bd9Sstevel@tonic-gate 
35937c478bd9Sstevel@tonic-gate /*
35947c478bd9Sstevel@tonic-gate  * Free md_drive_desc linked list of drive descriptors that was alloc'd
35957c478bd9Sstevel@tonic-gate  * from a call to the RPC routine clnt_getdrivedesc.  Drive descriptors
35967c478bd9Sstevel@tonic-gate  * are from another node.
35977c478bd9Sstevel@tonic-gate  */
35987c478bd9Sstevel@tonic-gate void
free_rem_dd(md_drive_desc * dd)35997c478bd9Sstevel@tonic-gate free_rem_dd(md_drive_desc *dd)
36007c478bd9Sstevel@tonic-gate {
36017c478bd9Sstevel@tonic-gate 	mdrpc_getdrivedesc_res	res;
36027c478bd9Sstevel@tonic-gate 
36037c478bd9Sstevel@tonic-gate 	/*
36047c478bd9Sstevel@tonic-gate 	 * dummy up a result struct, to do a deep free of the dd.
36057c478bd9Sstevel@tonic-gate 	 * (A deep free means that the xdr_free code will free the
36067c478bd9Sstevel@tonic-gate 	 * linked list of drive descs.)
36077c478bd9Sstevel@tonic-gate 	 */
36087c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
36097c478bd9Sstevel@tonic-gate 	res.dd = (struct md_drive_desc *)dd;
36107c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_getdrivedesc_res, (char *)&res);
36117c478bd9Sstevel@tonic-gate }
36127c478bd9Sstevel@tonic-gate 
36137c478bd9Sstevel@tonic-gate /*
36147c478bd9Sstevel@tonic-gate  * Get a partially filled in drive desc from remote node.  Used in MN
36157c478bd9Sstevel@tonic-gate  * disksets during the reconfig cycle to get the diskset drive
36167c478bd9Sstevel@tonic-gate  * information from another host in order to sync up all nodes.
36177c478bd9Sstevel@tonic-gate  * Used when the drive record information isn't good enough
36187c478bd9Sstevel@tonic-gate  * since the drive record doesn't give the name of
36197c478bd9Sstevel@tonic-gate  * the drive, but just a key into that other node's nodespace.
36207c478bd9Sstevel@tonic-gate  * Returned drive desc has the drive name filled in but no other strings
36217c478bd9Sstevel@tonic-gate  * in the drivename structure.
36227c478bd9Sstevel@tonic-gate  *
36237c478bd9Sstevel@tonic-gate  * Returns a 0 if RPC was successful, 1 otherwise.
36247c478bd9Sstevel@tonic-gate  */
36257c478bd9Sstevel@tonic-gate int
clnt_getdrivedesc(char * hostname,mdsetname_t * sp,md_drive_desc ** ret_dd,md_error_t * ep)36267c478bd9Sstevel@tonic-gate clnt_getdrivedesc(
36277c478bd9Sstevel@tonic-gate 	char			*hostname,
36287c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
36297c478bd9Sstevel@tonic-gate 	md_drive_desc		**ret_dd,
36307c478bd9Sstevel@tonic-gate 	md_error_t		*ep
36317c478bd9Sstevel@tonic-gate )
36327c478bd9Sstevel@tonic-gate {
36337c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
36347c478bd9Sstevel@tonic-gate 	mdrpc_sp_args		*args;
36357c478bd9Sstevel@tonic-gate 	mdrpc_sp_2_args		v2_args;
36367c478bd9Sstevel@tonic-gate 	mdrpc_getdrivedesc_res	res;
36377c478bd9Sstevel@tonic-gate 	int			version;
36387c478bd9Sstevel@tonic-gate 	int			rval = -1;
36397c478bd9Sstevel@tonic-gate 
36407c478bd9Sstevel@tonic-gate 	/* initialize */
36417c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
36427c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
36437c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
36447c478bd9Sstevel@tonic-gate 
36457c478bd9Sstevel@tonic-gate 	/* build args */
36467c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
36477c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_sp_2_args_u.rev1;
36487c478bd9Sstevel@tonic-gate 	args->sp = sp;
36497c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
36507c478bd9Sstevel@tonic-gate 
36517c478bd9Sstevel@tonic-gate 	/* do it */
36527c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
36537c478bd9Sstevel@tonic-gate 		int	bool;
36547c478bd9Sstevel@tonic-gate 		bool = mdrpc_getdrivedesc_2_svc(&v2_args, &res, NULL);
36557c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
36567c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
36577c478bd9Sstevel@tonic-gate 	} else {
36587c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
36597c478bd9Sstevel@tonic-gate 			return (-1);
36607c478bd9Sstevel@tonic-gate 
36617c478bd9Sstevel@tonic-gate 		/*
36627c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
36637c478bd9Sstevel@tonic-gate 		 */
36647c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
36657c478bd9Sstevel@tonic-gate 
36667c478bd9Sstevel@tonic-gate 		/*
36677c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
36687c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
36697c478bd9Sstevel@tonic-gate 		 */
36707c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
36717c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
36727c478bd9Sstevel@tonic-gate 			    sp->setno, hostname, NULL, sp->setname);
36737c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
36747c478bd9Sstevel@tonic-gate 			return (-1);
36757c478bd9Sstevel@tonic-gate 		} else {
36767c478bd9Sstevel@tonic-gate 			if (mdrpc_getdrivedesc_2(&v2_args, &res, clntp)
36777c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
36787c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
36797c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
36807c478bd9Sstevel@tonic-gate 				    "metad get drive desc set"));
36817c478bd9Sstevel@tonic-gate 			else
36827c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
36837c478bd9Sstevel@tonic-gate 		}
36847c478bd9Sstevel@tonic-gate 
36857c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
36867c478bd9Sstevel@tonic-gate 	}
36877c478bd9Sstevel@tonic-gate 
36887c478bd9Sstevel@tonic-gate 	/* If no ep error and no version mismatch - rpc call worked ok */
36897c478bd9Sstevel@tonic-gate 	if (mdisok(ep)) {
36907c478bd9Sstevel@tonic-gate 		rval = 0;
36917c478bd9Sstevel@tonic-gate 		if (ret_dd != NULL)
36927c478bd9Sstevel@tonic-gate 			*ret_dd = res.dd;
36937c478bd9Sstevel@tonic-gate 		else
36947c478bd9Sstevel@tonic-gate 			xdr_free(xdr_mdrpc_getdrivedesc_res, (char *)&res);
36957c478bd9Sstevel@tonic-gate 	}
36967c478bd9Sstevel@tonic-gate 
36977c478bd9Sstevel@tonic-gate 	return (rval);
36987c478bd9Sstevel@tonic-gate }
36997c478bd9Sstevel@tonic-gate 
37007c478bd9Sstevel@tonic-gate /*
37017c478bd9Sstevel@tonic-gate  * update dr_flags field of drive record.
37027c478bd9Sstevel@tonic-gate  * Also sync up genid of drive descriptors and make set
37037c478bd9Sstevel@tonic-gate  * record and node records match the genid.
37047c478bd9Sstevel@tonic-gate  *
37057c478bd9Sstevel@tonic-gate  * Returns a 0 if RPC was successful, 1 otherwise.
37067c478bd9Sstevel@tonic-gate  */
37077c478bd9Sstevel@tonic-gate int
clnt_upd_dr_reconfig(char * hostname,mdsetname_t * sp,md_drive_desc * dd,md_error_t * ep)37087c478bd9Sstevel@tonic-gate clnt_upd_dr_reconfig(
37097c478bd9Sstevel@tonic-gate 	char			*hostname,
37107c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
37117c478bd9Sstevel@tonic-gate 	md_drive_desc		*dd,
37127c478bd9Sstevel@tonic-gate 	md_error_t		*ep
37137c478bd9Sstevel@tonic-gate )
37147c478bd9Sstevel@tonic-gate {
37157c478bd9Sstevel@tonic-gate 	CLIENT				*clntp;
37167c478bd9Sstevel@tonic-gate 	mdrpc_upd_dr_flags_2_args	v2_args;
37177c478bd9Sstevel@tonic-gate 	mdrpc_upd_dr_flags_2_args_r1	*v21_args;
37187c478bd9Sstevel@tonic-gate 	mdrpc_generic_res		res;
37197c478bd9Sstevel@tonic-gate 	int				rval;
37207c478bd9Sstevel@tonic-gate 	int				version;
37217c478bd9Sstevel@tonic-gate 
37227c478bd9Sstevel@tonic-gate 	/* initialize */
37237c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
37247c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
37257c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
37267c478bd9Sstevel@tonic-gate 
37277c478bd9Sstevel@tonic-gate 	/* build args */
37287c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
37297c478bd9Sstevel@tonic-gate 	v21_args = &v2_args.mdrpc_upd_dr_flags_2_args_u.rev1;
37307c478bd9Sstevel@tonic-gate 	v21_args->sp = sp;
37317c478bd9Sstevel@tonic-gate 	v21_args->drivedescs = dd;
37327c478bd9Sstevel@tonic-gate 
37337c478bd9Sstevel@tonic-gate 	/* do it */
37347c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
37357c478bd9Sstevel@tonic-gate 		int	bool;
37367c478bd9Sstevel@tonic-gate 
37377c478bd9Sstevel@tonic-gate 		/*
37387c478bd9Sstevel@tonic-gate 		 * If the server is local, we call the v2 procedure
37397c478bd9Sstevel@tonic-gate 		 */
37407c478bd9Sstevel@tonic-gate 		bool = mdrpc_upd_dr_reconfig_2_svc(&v2_args, &res, NULL);
37417c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
37427c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
37437c478bd9Sstevel@tonic-gate 	} else {
37447c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
37457c478bd9Sstevel@tonic-gate 			return (-1);
37467c478bd9Sstevel@tonic-gate 
37477c478bd9Sstevel@tonic-gate 		/*
37487c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
37497c478bd9Sstevel@tonic-gate 		 */
37507c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
37517c478bd9Sstevel@tonic-gate 		/*
37527c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
37537c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
37547c478bd9Sstevel@tonic-gate 		 */
37557c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
37567c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
37577c478bd9Sstevel@tonic-gate 				sp->setno, hostname, NULL, sp->setname);
37587c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
37597c478bd9Sstevel@tonic-gate 			return (-1);
37607c478bd9Sstevel@tonic-gate 		} else {
37617c478bd9Sstevel@tonic-gate 			rval = mdrpc_upd_dr_reconfig_2(&v2_args, &res, clntp);
37627c478bd9Sstevel@tonic-gate 
37637c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
37647c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
37657c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN,
37667c478bd9Sstevel@tonic-gate 				    "metad update drive reconfig"));
37677c478bd9Sstevel@tonic-gate 			else
37687c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
37697c478bd9Sstevel@tonic-gate 		}
37707c478bd9Sstevel@tonic-gate 
37717c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
37727c478bd9Sstevel@tonic-gate 	}
37737c478bd9Sstevel@tonic-gate 
37747c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
37757c478bd9Sstevel@tonic-gate 
37767c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
37777c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
37787c478bd9Sstevel@tonic-gate 			return (-1);
37797c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
37807c478bd9Sstevel@tonic-gate 			return (-1);
37817c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
37827c478bd9Sstevel@tonic-gate 	}
37837c478bd9Sstevel@tonic-gate 
37847c478bd9Sstevel@tonic-gate 	return (0);
37857c478bd9Sstevel@tonic-gate }
37867c478bd9Sstevel@tonic-gate 
37877c478bd9Sstevel@tonic-gate /*
37887c478bd9Sstevel@tonic-gate  * Reset mirror owner(s) if mirror owner(s) is in the list of
37897c478bd9Sstevel@tonic-gate  * node's specified in the array of nodeids.
37907c478bd9Sstevel@tonic-gate  * This is called when a node has been deleted or withdrawn
37917c478bd9Sstevel@tonic-gate  * from the diskset.
37927c478bd9Sstevel@tonic-gate  */
37937c478bd9Sstevel@tonic-gate int
clnt_reset_mirror_owner(char * hostname,mdsetname_t * sp,int node_c,int node_id[],md_error_t * ep)37947c478bd9Sstevel@tonic-gate clnt_reset_mirror_owner(
37957c478bd9Sstevel@tonic-gate 	char			*hostname,
37967c478bd9Sstevel@tonic-gate 	mdsetname_t		*sp,
37977c478bd9Sstevel@tonic-gate 	int			node_c,
37987c478bd9Sstevel@tonic-gate 	int			node_id[],
37997c478bd9Sstevel@tonic-gate 	md_error_t		*ep
38007c478bd9Sstevel@tonic-gate )
38017c478bd9Sstevel@tonic-gate {
38027c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
38037c478bd9Sstevel@tonic-gate 	mdrpc_nodeid_args	*args;
38047c478bd9Sstevel@tonic-gate 	mdrpc_nodeid_2_args	v2_args;
38057c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
38067c478bd9Sstevel@tonic-gate 	int			version;
38077c478bd9Sstevel@tonic-gate 
38087c478bd9Sstevel@tonic-gate 	/* initialize */
38097c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
38107c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
38117c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
38127c478bd9Sstevel@tonic-gate 
38137c478bd9Sstevel@tonic-gate 	/* build args */
38147c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
38157c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_nodeid_2_args_u.rev1;
38167c478bd9Sstevel@tonic-gate 	args->sp = sp;
38177c478bd9Sstevel@tonic-gate 	args->cl_sk = cl_get_setkey(sp->setno, sp->setname);
38187c478bd9Sstevel@tonic-gate 	args->nodeid.nodeid_len = node_c;
38197c478bd9Sstevel@tonic-gate 	args->nodeid.nodeid_val = &node_id[0];
38207c478bd9Sstevel@tonic-gate 
38217c478bd9Sstevel@tonic-gate 	/* do it */
38227c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
38237c478bd9Sstevel@tonic-gate 		int	bool;
38247c478bd9Sstevel@tonic-gate 		bool = mdrpc_reset_mirror_owner_2_svc(&v2_args, &res, NULL);
38257c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
38267c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
38277c478bd9Sstevel@tonic-gate 	} else {
38287c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
38297c478bd9Sstevel@tonic-gate 			return (-1);
38307c478bd9Sstevel@tonic-gate 
38317c478bd9Sstevel@tonic-gate 		/*
38327c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
38337c478bd9Sstevel@tonic-gate 		 * and invoke the appropriate version of the
38347c478bd9Sstevel@tonic-gate 		 * remote procedure
38357c478bd9Sstevel@tonic-gate 		 */
38367c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
38377c478bd9Sstevel@tonic-gate 
38387c478bd9Sstevel@tonic-gate 		/*
38397c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
38407c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
38417c478bd9Sstevel@tonic-gate 		 */
38427c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
38437c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
38447c478bd9Sstevel@tonic-gate 			    sp->setno, hostname, NULL, sp->setname);
38457c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
38467c478bd9Sstevel@tonic-gate 			return (-1);
38477c478bd9Sstevel@tonic-gate 		} else {
38487c478bd9Sstevel@tonic-gate 			if (mdrpc_reset_mirror_owner_2(&v2_args, &res, clntp)
38497c478bd9Sstevel@tonic-gate 			    != RPC_SUCCESS)
38507c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
38517c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
38527c478bd9Sstevel@tonic-gate 					"metad reset mirror owner"));
38537c478bd9Sstevel@tonic-gate 			else
38547c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
38557c478bd9Sstevel@tonic-gate 		}
38567c478bd9Sstevel@tonic-gate 
38577c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
38587c478bd9Sstevel@tonic-gate 	}
38597c478bd9Sstevel@tonic-gate 
38607c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
38617c478bd9Sstevel@tonic-gate 
38627c478bd9Sstevel@tonic-gate 	if (! mdisok(ep))
38637c478bd9Sstevel@tonic-gate 		return (-1);
38647c478bd9Sstevel@tonic-gate 
38657c478bd9Sstevel@tonic-gate 	return (0);
38667c478bd9Sstevel@tonic-gate }
38677c478bd9Sstevel@tonic-gate 
38687c478bd9Sstevel@tonic-gate /*
38697c478bd9Sstevel@tonic-gate  * Call to suspend and resume I/O for given diskset(s).
38707c478bd9Sstevel@tonic-gate  * This allows a node to remotely suspend and resume I/O on
38717c478bd9Sstevel@tonic-gate  * a MN diskset.  A diskset number of 0 represents all MN disksets.
38727c478bd9Sstevel@tonic-gate  */
38737c478bd9Sstevel@tonic-gate int
clnt_mn_susp_res_io(char * hostname,set_t setno,int cmd,md_error_t * ep)38747c478bd9Sstevel@tonic-gate clnt_mn_susp_res_io(
38757c478bd9Sstevel@tonic-gate 	char			*hostname,
38767c478bd9Sstevel@tonic-gate 	set_t			setno,
38777c478bd9Sstevel@tonic-gate 	int			cmd,
38787c478bd9Sstevel@tonic-gate 	md_error_t		*ep
38797c478bd9Sstevel@tonic-gate )
38807c478bd9Sstevel@tonic-gate {
38817c478bd9Sstevel@tonic-gate 	CLIENT					*clntp;
38827c478bd9Sstevel@tonic-gate 	mdrpc_mn_susp_res_io_args		*args;
38837c478bd9Sstevel@tonic-gate 	mdrpc_mn_susp_res_io_2_args		v2_args;
38847c478bd9Sstevel@tonic-gate 	mdrpc_generic_res			res;
38857c478bd9Sstevel@tonic-gate 	int					version;
38867c478bd9Sstevel@tonic-gate 
38877c478bd9Sstevel@tonic-gate 	/* initialize */
38887c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
38897c478bd9Sstevel@tonic-gate 	(void) memset(&v2_args, 0, sizeof (v2_args));
38907c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
38917c478bd9Sstevel@tonic-gate 
38927c478bd9Sstevel@tonic-gate 	/* build args */
38937c478bd9Sstevel@tonic-gate 	v2_args.rev = MD_METAD_ARGS_REV_1;
38947c478bd9Sstevel@tonic-gate 	args = &v2_args.mdrpc_mn_susp_res_io_2_args_u.rev1;
38957c478bd9Sstevel@tonic-gate 	args->susp_res_cmd = cmd;
38967c478bd9Sstevel@tonic-gate 	args->susp_res_setno = setno;
38977c478bd9Sstevel@tonic-gate 
38987c478bd9Sstevel@tonic-gate 	/* do it */
38997c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
39007c478bd9Sstevel@tonic-gate 		int	bool;
39017c478bd9Sstevel@tonic-gate 		/*
39027c478bd9Sstevel@tonic-gate 		 * Call v2 procedure directly if rpc.metad on this node is
39037c478bd9Sstevel@tonic-gate 		 * sending message to itself.
39047c478bd9Sstevel@tonic-gate 		 */
39057c478bd9Sstevel@tonic-gate 		bool = mdrpc_mn_susp_res_io_2_svc(&v2_args, &res, NULL);
39067c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
39077c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
39087c478bd9Sstevel@tonic-gate 	} else {
39097c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
39107c478bd9Sstevel@tonic-gate 			return (-1);
39117c478bd9Sstevel@tonic-gate 
39127c478bd9Sstevel@tonic-gate 		/*
39137c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
39147c478bd9Sstevel@tonic-gate 		 */
39157c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
39167c478bd9Sstevel@tonic-gate 
39177c478bd9Sstevel@tonic-gate 		/*
39187c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
39197c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
39207c478bd9Sstevel@tonic-gate 		 */
39217c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
39227c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
39237c478bd9Sstevel@tonic-gate 			    setno, hostname, NULL, NULL);
39247c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
39257c478bd9Sstevel@tonic-gate 			return (-1);
39267c478bd9Sstevel@tonic-gate 		} else {
39277c478bd9Sstevel@tonic-gate 			if (mdrpc_mn_susp_res_io_2(&v2_args, &res, clntp)
39287c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
39297c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
39307c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
39317c478bd9Sstevel@tonic-gate 				    "metad mn_susp_res_io control"));
39327c478bd9Sstevel@tonic-gate 			else
39337c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
39347c478bd9Sstevel@tonic-gate 		}
39357c478bd9Sstevel@tonic-gate 
39367c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
39377c478bd9Sstevel@tonic-gate 	}
39387c478bd9Sstevel@tonic-gate 
39397c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
39407c478bd9Sstevel@tonic-gate 
39417c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
39427c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
39437c478bd9Sstevel@tonic-gate 			return (-1);
39447c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
39457c478bd9Sstevel@tonic-gate 			return (-1);
39467c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
39477c478bd9Sstevel@tonic-gate 	}
39487c478bd9Sstevel@tonic-gate 
39497c478bd9Sstevel@tonic-gate 	return (0);
39507c478bd9Sstevel@tonic-gate }
39517c478bd9Sstevel@tonic-gate 
39527c478bd9Sstevel@tonic-gate /*
39537c478bd9Sstevel@tonic-gate  * Resnarf the set after the set has been imported
39547c478bd9Sstevel@tonic-gate  *
39557c478bd9Sstevel@tonic-gate  * We should never be making this procedure call
39567c478bd9Sstevel@tonic-gate  * over the wire, it's sole purpose is to snarf
39577c478bd9Sstevel@tonic-gate  * the imported set on the localhost.
39587c478bd9Sstevel@tonic-gate  */
39597c478bd9Sstevel@tonic-gate int
clnt_resnarf_set(char * hostname,set_t setno,md_error_t * ep)39607c478bd9Sstevel@tonic-gate clnt_resnarf_set(
39617c478bd9Sstevel@tonic-gate 	char		*hostname,
39627c478bd9Sstevel@tonic-gate 	set_t		setno,
39637c478bd9Sstevel@tonic-gate 	md_error_t	*ep
39647c478bd9Sstevel@tonic-gate )
39657c478bd9Sstevel@tonic-gate {
39667c478bd9Sstevel@tonic-gate 	CLIENT			*clntp;
39677c478bd9Sstevel@tonic-gate 	mdrpc_setno_2_args	args;
39687c478bd9Sstevel@tonic-gate 	mdrpc_generic_res	res;
39697c478bd9Sstevel@tonic-gate 	int			rval = -1;
39707c478bd9Sstevel@tonic-gate 	int			version;
39717c478bd9Sstevel@tonic-gate 
39727c478bd9Sstevel@tonic-gate 	/* initialize */
39737c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
39747c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
39757c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
39767c478bd9Sstevel@tonic-gate 
39777c478bd9Sstevel@tonic-gate 	/* build args */
39787c478bd9Sstevel@tonic-gate 	args.rev = MD_METAD_ARGS_REV_1;
39797c478bd9Sstevel@tonic-gate 	args.mdrpc_setno_2_args_u.rev1.setno = setno;
39807c478bd9Sstevel@tonic-gate 	args.mdrpc_setno_2_args_u.rev1.cl_sk = NULL;
39817c478bd9Sstevel@tonic-gate 
39827c478bd9Sstevel@tonic-gate 	/* do it */
39837c478bd9Sstevel@tonic-gate 	if (strcmp(mynode(), hostname) == 0) {
39847c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
39857c478bd9Sstevel@tonic-gate 			return (-1);
39867c478bd9Sstevel@tonic-gate 
39877c478bd9Sstevel@tonic-gate 		/* Check the client handle for the version */
39887c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
39897c478bd9Sstevel@tonic-gate 
39907c478bd9Sstevel@tonic-gate 		/* If the client is version 1, return error */
39917c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
39927c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_CANTRESNARF, MD_SET_BAD,
39937c478bd9Sstevel@tonic-gate 			    mynode(), NULL, NULL);
39947c478bd9Sstevel@tonic-gate 		} else {
39957c478bd9Sstevel@tonic-gate 			rval = mdrpc_resnarf_set_2(&args, &res, clntp);
39967c478bd9Sstevel@tonic-gate 
39977c478bd9Sstevel@tonic-gate 			if (rval != RPC_SUCCESS)
39987c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
39997c478bd9Sstevel@tonic-gate 				    dgettext(TEXT_DOMAIN, "metad resnarf set"));
40007c478bd9Sstevel@tonic-gate 			else
40017c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
40027c478bd9Sstevel@tonic-gate 		}
40037c478bd9Sstevel@tonic-gate 
40047c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
40057c478bd9Sstevel@tonic-gate 
40067c478bd9Sstevel@tonic-gate 	} else {
40077c478bd9Sstevel@tonic-gate 		(void) mddserror(ep, MDE_DS_CANTRESNARF, MD_SET_BAD,
40087c478bd9Sstevel@tonic-gate 		    mynode(), NULL, NULL);
40097c478bd9Sstevel@tonic-gate 	}
40107c478bd9Sstevel@tonic-gate 
40117c478bd9Sstevel@tonic-gate 	if (mdisok(ep))
40127c478bd9Sstevel@tonic-gate 		rval = 0;
40137c478bd9Sstevel@tonic-gate 
40147c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
40157c478bd9Sstevel@tonic-gate 
40167c478bd9Sstevel@tonic-gate 	return (rval);
40177c478bd9Sstevel@tonic-gate }
40187c478bd9Sstevel@tonic-gate 
40197c478bd9Sstevel@tonic-gate /*
40207c478bd9Sstevel@tonic-gate  * Call to start a resync for a given diskset.
40217c478bd9Sstevel@tonic-gate  * Used when a node has been added to a diskset.
40227c478bd9Sstevel@tonic-gate  * Should be called after rpc.mdcommd is resumed.
40237c478bd9Sstevel@tonic-gate  */
40247c478bd9Sstevel@tonic-gate int
clnt_mn_mirror_resync_all(char * hostname,set_t setno,md_error_t * ep)40257c478bd9Sstevel@tonic-gate clnt_mn_mirror_resync_all(
40267c478bd9Sstevel@tonic-gate 	char			*hostname,
40277c478bd9Sstevel@tonic-gate 	set_t			setno,
40287c478bd9Sstevel@tonic-gate 	md_error_t		*ep
40297c478bd9Sstevel@tonic-gate )
40307c478bd9Sstevel@tonic-gate {
40317c478bd9Sstevel@tonic-gate 	CLIENT					*clntp;
40327c478bd9Sstevel@tonic-gate 	mdrpc_setno_2_args			args;
40337c478bd9Sstevel@tonic-gate 	mdrpc_generic_res			res;
40347c478bd9Sstevel@tonic-gate 	int					version;
40357c478bd9Sstevel@tonic-gate 
40367c478bd9Sstevel@tonic-gate 	/* initialize */
40377c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
40387c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
40397c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
40407c478bd9Sstevel@tonic-gate 
40417c478bd9Sstevel@tonic-gate 	/* build args */
40427c478bd9Sstevel@tonic-gate 	args.rev = MD_METAD_ARGS_REV_1;
40437c478bd9Sstevel@tonic-gate 	args.mdrpc_setno_2_args_u.rev1.setno = setno;
40447c478bd9Sstevel@tonic-gate 	args.mdrpc_setno_2_args_u.rev1.cl_sk = NULL;
40457c478bd9Sstevel@tonic-gate 
40467c478bd9Sstevel@tonic-gate 	/* do it */
40477c478bd9Sstevel@tonic-gate 	if (md_in_daemon && strcmp(mynode(), hostname) == 0) {
40487c478bd9Sstevel@tonic-gate 		int	bool;
40497c478bd9Sstevel@tonic-gate 		/*
40507c478bd9Sstevel@tonic-gate 		 * Call v2 procedure directly if rpc.metad on this node is
40517c478bd9Sstevel@tonic-gate 		 * sending message to itself.
40527c478bd9Sstevel@tonic-gate 		 */
40537c478bd9Sstevel@tonic-gate 		bool = mdrpc_mn_mirror_resync_all_2_svc(&args, &res, NULL);
40547c478bd9Sstevel@tonic-gate 		assert(bool == TRUE);
40557c478bd9Sstevel@tonic-gate 		(void) mdstealerror(ep, &res.status);
40567c478bd9Sstevel@tonic-gate 	} else {
40577c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
40587c478bd9Sstevel@tonic-gate 			return (-1);
40597c478bd9Sstevel@tonic-gate 
40607c478bd9Sstevel@tonic-gate 		/*
40617c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
40627c478bd9Sstevel@tonic-gate 		 */
40637c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
40647c478bd9Sstevel@tonic-gate 
40657c478bd9Sstevel@tonic-gate 		/*
40667c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
40677c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
40687c478bd9Sstevel@tonic-gate 		 */
40697c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
40707c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
40717c478bd9Sstevel@tonic-gate 			    setno, hostname, NULL, NULL);
40727c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
40737c478bd9Sstevel@tonic-gate 			return (-1);
40747c478bd9Sstevel@tonic-gate 		} else {
40757c478bd9Sstevel@tonic-gate 			if (mdrpc_mn_mirror_resync_all_2(&args, &res, clntp)
40767c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
40777c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
40787c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
40797c478bd9Sstevel@tonic-gate 				    "metad mn_mirror_resync_all"));
40807c478bd9Sstevel@tonic-gate 			else
40817c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
40827c478bd9Sstevel@tonic-gate 		}
40837c478bd9Sstevel@tonic-gate 
40847c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
40857c478bd9Sstevel@tonic-gate 	}
40867c478bd9Sstevel@tonic-gate 
40877c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
40887c478bd9Sstevel@tonic-gate 
40897c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
40907c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
40917c478bd9Sstevel@tonic-gate 			return (-1);
40927c478bd9Sstevel@tonic-gate 		if (strcmp(mynode(), hostname) == 0)
40937c478bd9Sstevel@tonic-gate 			return (-1);
40947c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
40957c478bd9Sstevel@tonic-gate 	}
40967c478bd9Sstevel@tonic-gate 
40977c478bd9Sstevel@tonic-gate 	return (0);
40987c478bd9Sstevel@tonic-gate }
40997c478bd9Sstevel@tonic-gate 
41007c478bd9Sstevel@tonic-gate /*
41017c478bd9Sstevel@tonic-gate  * Call to update the ABR state for all soft partitions.
41027c478bd9Sstevel@tonic-gate  * Used when a node has been added to a diskset.
41037c478bd9Sstevel@tonic-gate  * Should be called after rpc.mdcommd is resumed.
41047c478bd9Sstevel@tonic-gate  */
41057c478bd9Sstevel@tonic-gate int
clnt_mn_sp_update_abr(char * hostname,set_t setno,md_error_t * ep)41067c478bd9Sstevel@tonic-gate clnt_mn_sp_update_abr(
41077c478bd9Sstevel@tonic-gate 	char			*hostname,
41087c478bd9Sstevel@tonic-gate 	set_t			setno,
41097c478bd9Sstevel@tonic-gate 	md_error_t		*ep
41107c478bd9Sstevel@tonic-gate )
41117c478bd9Sstevel@tonic-gate {
41127c478bd9Sstevel@tonic-gate 	CLIENT					*clntp;
41137c478bd9Sstevel@tonic-gate 	mdrpc_setno_2_args			args;
41147c478bd9Sstevel@tonic-gate 	mdrpc_generic_res			res;
41157c478bd9Sstevel@tonic-gate 	int					version;
41167c478bd9Sstevel@tonic-gate 
41177c478bd9Sstevel@tonic-gate 	/* initialize */
41187c478bd9Sstevel@tonic-gate 	mdclrerror(ep);
41197c478bd9Sstevel@tonic-gate 	(void) memset(&args, 0, sizeof (args));
41207c478bd9Sstevel@tonic-gate 	(void) memset(&res, 0, sizeof (res));
41217c478bd9Sstevel@tonic-gate 
41227c478bd9Sstevel@tonic-gate 	/* build args */
41237c478bd9Sstevel@tonic-gate 	args.rev = MD_METAD_ARGS_REV_1;
41247c478bd9Sstevel@tonic-gate 	args.mdrpc_setno_2_args_u.rev1.setno = setno;
41257c478bd9Sstevel@tonic-gate 	args.mdrpc_setno_2_args_u.rev1.cl_sk = NULL;
41267c478bd9Sstevel@tonic-gate 
41277c478bd9Sstevel@tonic-gate 	/*
41287c478bd9Sstevel@tonic-gate 	 * No need to call function if adding local node as ABR cannot
41297c478bd9Sstevel@tonic-gate 	 * be set.
41307c478bd9Sstevel@tonic-gate 	 */
41317c478bd9Sstevel@tonic-gate 	if (strcmp(mynode(), hostname) != 0) {
41327c478bd9Sstevel@tonic-gate 		if ((clntp = metarpcopen(hostname, CL_LONG_TMO, ep)) == NULL)
41337c478bd9Sstevel@tonic-gate 			return (-1);
41347c478bd9Sstevel@tonic-gate 
41357c478bd9Sstevel@tonic-gate 		/*
41367c478bd9Sstevel@tonic-gate 		 * Check the client handle for the version
41377c478bd9Sstevel@tonic-gate 		 */
41387c478bd9Sstevel@tonic-gate 		CLNT_CONTROL(clntp, CLGET_VERS, (char *)&version);
41397c478bd9Sstevel@tonic-gate 
41407c478bd9Sstevel@tonic-gate 		/*
41417c478bd9Sstevel@tonic-gate 		 * If the client is version 1, return error
41427c478bd9Sstevel@tonic-gate 		 * otherwise, make the remote procedure call.
41437c478bd9Sstevel@tonic-gate 		 */
41447c478bd9Sstevel@tonic-gate 		if (version == METAD_VERSION) { /* version 1 */
41457c478bd9Sstevel@tonic-gate 			(void) mddserror(ep, MDE_DS_RPCVERSMISMATCH,
41467c478bd9Sstevel@tonic-gate 			    setno, hostname, NULL, NULL);
41477c478bd9Sstevel@tonic-gate 			metarpcclose(clntp);
41487c478bd9Sstevel@tonic-gate 			return (-1);
41497c478bd9Sstevel@tonic-gate 		} else {
41507c478bd9Sstevel@tonic-gate 			if (mdrpc_mn_sp_update_abr_2(&args, &res, clntp)
41517c478bd9Sstevel@tonic-gate 							!= RPC_SUCCESS)
41527c478bd9Sstevel@tonic-gate 				(void) mdrpcerror(ep, clntp, hostname,
41537c478bd9Sstevel@tonic-gate 				dgettext(TEXT_DOMAIN,
41547c478bd9Sstevel@tonic-gate 				    "metad mn_sp_update_abr"));
41557c478bd9Sstevel@tonic-gate 			else
41567c478bd9Sstevel@tonic-gate 				(void) mdstealerror(ep, &res.status);
41577c478bd9Sstevel@tonic-gate 		}
41587c478bd9Sstevel@tonic-gate 
41597c478bd9Sstevel@tonic-gate 		metarpcclose(clntp);
41607c478bd9Sstevel@tonic-gate 	}
41617c478bd9Sstevel@tonic-gate 
41627c478bd9Sstevel@tonic-gate 	xdr_free(xdr_mdrpc_generic_res, (char *)&res);
41637c478bd9Sstevel@tonic-gate 
41647c478bd9Sstevel@tonic-gate 	if (! mdisok(ep)) {
41657c478bd9Sstevel@tonic-gate 		if (! mdanyrpcerror(ep))
41667c478bd9Sstevel@tonic-gate 			return (-1);
41677c478bd9Sstevel@tonic-gate 		mdclrerror(ep);
41687c478bd9Sstevel@tonic-gate 	}
41697c478bd9Sstevel@tonic-gate 
41707c478bd9Sstevel@tonic-gate 	return (0);
41717c478bd9Sstevel@tonic-gate }
4172