10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include "metad_local.h" 300Sstevel@tonic-gate #include <metad.h> 310Sstevel@tonic-gate #include <sys/lvm/md_mddb.h> 320Sstevel@tonic-gate #include <sdssc.h> 330Sstevel@tonic-gate #include <sys/lvm/md_mirror.h> 340Sstevel@tonic-gate #include <syslog.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 370Sstevel@tonic-gate #include <sys/sysevent/svm.h> 380Sstevel@tonic-gate #include <thread.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #define MDDOORS "/usr/lib/lvm/mddoors" 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * rpc.metad daemon 440Sstevel@tonic-gate * 450Sstevel@tonic-gate * The rpc.metad deamon supports two versions of the svm rpc calls - version 1 460Sstevel@tonic-gate * and version 2. The over-the-wire structures sent as part of these rpc calls 470Sstevel@tonic-gate * are also versioned - version 1 and version 2 exist. It must be noted that 480Sstevel@tonic-gate * the version 2 structures have sub-versions or revisions as well. The 490Sstevel@tonic-gate * revisions in the version 2 structures allow for flexiblility in changing 500Sstevel@tonic-gate * over the wire structures without creating a new version of the svm rpc 510Sstevel@tonic-gate * calls. No changes may be made to the version 1 routines or structures used 520Sstevel@tonic-gate * by these routines. 530Sstevel@tonic-gate * 540Sstevel@tonic-gate * If, for example, the version 2 mdrpc_devinfo_args over the wire structure 550Sstevel@tonic-gate * (mdrpc_devinfo_2_args*) is changed then the structure change must be 560Sstevel@tonic-gate * accompanied by the following: 570Sstevel@tonic-gate * 580Sstevel@tonic-gate * Header file changes: 590Sstevel@tonic-gate * . May need to introduce a new structure revision MD_METAD_ARGS_REV_X, where 600Sstevel@tonic-gate * X is the revision number. 610Sstevel@tonic-gate * . Create mdrpc_devinfo_2_args_rX, where X is the new revision of the 620Sstevel@tonic-gate * structure. 630Sstevel@tonic-gate * . Add a switch statement in mdrpc_devinfo_2_args. 640Sstevel@tonic-gate * 650Sstevel@tonic-gate * rpc.metad changes: 660Sstevel@tonic-gate * . Check for the structure revision in the appropriate mdrpc_devinfo_svc 670Sstevel@tonic-gate * routine (mdrpc_devinfo_2_svc). 680Sstevel@tonic-gate * 690Sstevel@tonic-gate * libmeta changes: 700Sstevel@tonic-gate * . In the libmeta code that makes the mdrpc_devinfo rpc call, the arguments 710Sstevel@tonic-gate * being passed as part of this call (namely mdrpc_devinfo_Y_args) must have 720Sstevel@tonic-gate * the revision field and associated structure populated correctly. 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate 750Sstevel@tonic-gate static md_setkey_t *my_svc_sk = NULL; 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Add namespace entry to local mddb for using given sideno, key 790Sstevel@tonic-gate * and names. 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate static int 820Sstevel@tonic-gate add_sideno_sidenm( 830Sstevel@tonic-gate mdsidenames_t *sidenms, 840Sstevel@tonic-gate mdkey_t local_key, 850Sstevel@tonic-gate side_t sideno, 860Sstevel@tonic-gate md_set_desc *sd, /* Only used with Version 2 */ 870Sstevel@tonic-gate md_error_t *ep 880Sstevel@tonic-gate ) 890Sstevel@tonic-gate { 900Sstevel@tonic-gate mdsidenames_t *sn; 910Sstevel@tonic-gate mdsetname_t *local_sp; 920Sstevel@tonic-gate char *nm; 930Sstevel@tonic-gate 940Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) 950Sstevel@tonic-gate return (-1); 960Sstevel@tonic-gate 970Sstevel@tonic-gate for (sn = sidenms; sn != NULL; sn = sn->next) 980Sstevel@tonic-gate if (sn->sideno == sideno) 990Sstevel@tonic-gate break; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate assert(sn != NULL); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate /* 1050Sstevel@tonic-gate * SKEW will be used on the traditional diskset despite of the 1060Sstevel@tonic-gate * rpc version. SKEW is not used on the multinode diskset 1070Sstevel@tonic-gate */ 1080Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 1090Sstevel@tonic-gate nm = meta_getnmbykey(MD_LOCAL_SET, sideno, local_key, ep); 1100Sstevel@tonic-gate } else { 1110Sstevel@tonic-gate nm = meta_getnmbykey(MD_LOCAL_SET, sideno+SKEW, local_key, ep); 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate if (nm == NULL) { 1150Sstevel@tonic-gate if (! mdisok(ep)) { 1160Sstevel@tonic-gate if (! mdissyserror(ep, ENOENT)) 1170Sstevel@tonic-gate return (-1); 1180Sstevel@tonic-gate mdclrerror(ep); 1190Sstevel@tonic-gate } 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * Ignore returned key from add_name, only care about errs 1230Sstevel@tonic-gate * 1240Sstevel@tonic-gate * SKEW is used for a regular diskset since sideno could 1250Sstevel@tonic-gate * have a value of 0 in that diskset type. add_name is 1260Sstevel@tonic-gate * writing to the local mddb and a sideno of 0 in the 1270Sstevel@tonic-gate * local mddb is reserved for non-diskset names. 1280Sstevel@tonic-gate * SKEW is added to the sideno in the local mddb so that 1290Sstevel@tonic-gate * the sideno for the diskset will never be 0. 1300Sstevel@tonic-gate * 1310Sstevel@tonic-gate * In a MNdiskset, the sideno will never be 0 (by design). 1320Sstevel@tonic-gate * So, no SKEW is needed when writing to the local mddb. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 1350Sstevel@tonic-gate if (add_name(local_sp, sideno, local_key, 1360Sstevel@tonic-gate sn->dname, sn->mnum, sn->cname, ep) == -1) 1370Sstevel@tonic-gate return (-1); 1380Sstevel@tonic-gate } else { 1390Sstevel@tonic-gate if (add_name(local_sp, sideno+SKEW, local_key, 1400Sstevel@tonic-gate sn->dname, sn->mnum, sn->cname, ep) == -1) 1410Sstevel@tonic-gate return (-1); 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate } else 1440Sstevel@tonic-gate Free(nm); 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate return (0); 1470Sstevel@tonic-gate } 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* 1500Sstevel@tonic-gate * Delete sidename entry from local set using key and sideno. 1510Sstevel@tonic-gate */ 1520Sstevel@tonic-gate static int 1530Sstevel@tonic-gate del_sideno_sidenm( 1540Sstevel@tonic-gate mdkey_t sidekey, 1550Sstevel@tonic-gate side_t sideno, 1560Sstevel@tonic-gate md_error_t *ep 1570Sstevel@tonic-gate ) 1580Sstevel@tonic-gate { 1590Sstevel@tonic-gate mdsetname_t *local_sp; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) 1620Sstevel@tonic-gate return (-1); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (del_name(local_sp, sideno, sidekey, ep) == -1) 1650Sstevel@tonic-gate mdclrerror(ep); /* ignore errs */ 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate return (0); 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Add namespace entries to local mddb for drives in drive list in 1730Sstevel@tonic-gate * set descriptor. 1740Sstevel@tonic-gate * 1750Sstevel@tonic-gate * If a MNset and if this host is being added to the set (this host 1760Sstevel@tonic-gate * is in the node_v list), add a namespace entry for the name of 1770Sstevel@tonic-gate * each drive using this host's sideno. 1780Sstevel@tonic-gate * 1790Sstevel@tonic-gate * If not a MNset, add namespace entries for all the new hosts being 1800Sstevel@tonic-gate * added to this set (list in node_v). 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate static void 1830Sstevel@tonic-gate add_drv_sidenms( 1840Sstevel@tonic-gate char *hostname, 1850Sstevel@tonic-gate mdsetname_t *sp, 1860Sstevel@tonic-gate md_set_desc *sd, 1870Sstevel@tonic-gate int node_c, 1880Sstevel@tonic-gate char **node_v, 1890Sstevel@tonic-gate md_error_t *ep 1900Sstevel@tonic-gate ) 1910Sstevel@tonic-gate { 1920Sstevel@tonic-gate mdsetname_t *my_sp; 1930Sstevel@tonic-gate md_drive_desc *dd, *my_dd, *p, *q; 1940Sstevel@tonic-gate mddrivename_t *dn, *my_dn; 1950Sstevel@tonic-gate int i; 1960Sstevel@tonic-gate side_t sideno = 0, mysideno = 0; 1970Sstevel@tonic-gate ddi_devid_t devid_remote = NULL; 1980Sstevel@tonic-gate ddi_devid_t devid_local = NULL; 1990Sstevel@tonic-gate int devid_same = -1; 2000Sstevel@tonic-gate int using_devid = 0; 2010Sstevel@tonic-gate md_mnnode_desc *nd; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate assert(sd->sd_drvs != NULL); 2040Sstevel@tonic-gate dd = sd->sd_drvs; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate if (dd->dd_dnp == NULL) 2070Sstevel@tonic-gate return; 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate if ((my_sp = metasetname(sp->setname, ep)) == NULL) 2100Sstevel@tonic-gate return; 2110Sstevel@tonic-gate metaflushsetname(my_sp); 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* If a MN diskset */ 2140Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 2150Sstevel@tonic-gate /* Find sideno associated with RPC client. */ 2160Sstevel@tonic-gate nd = sd->sd_nodelist; 2170Sstevel@tonic-gate while (nd) { 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate if (strcmp(nd->nd_nodename, hostname) == 0) { 2200Sstevel@tonic-gate sideno = nd->nd_nodeid; 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate /* While looping, find my side num as well */ 2240Sstevel@tonic-gate if (strcmp(nd->nd_nodename, mynode()) == 0) { 2250Sstevel@tonic-gate mysideno = nd->nd_nodeid; 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate if ((sideno) && (mysideno)) { 2290Sstevel@tonic-gate break; 2300Sstevel@tonic-gate } 2310Sstevel@tonic-gate nd = nd->nd_next; 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate if (!sideno) { 2350Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_HOSTNOSIDE, 2360Sstevel@tonic-gate sp->setno, hostname, NULL, sp->setname); 2370Sstevel@tonic-gate return; 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate } else { 2400Sstevel@tonic-gate /* 2410Sstevel@tonic-gate * if not a MN diskset 2420Sstevel@tonic-gate * do action for traditional diskset. 2430Sstevel@tonic-gate * despite of the rpc version 2440Sstevel@tonic-gate */ 2450Sstevel@tonic-gate for (sideno = 0; sideno < MD_MAXSIDES; sideno++) { 2460Sstevel@tonic-gate /* Skip empty slots */ 2470Sstevel@tonic-gate if (sd->sd_nodes[sideno][0] == '\0') 2480Sstevel@tonic-gate continue; 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate if (strcmp(hostname, sd->sd_nodes[sideno]) == 0) 2510Sstevel@tonic-gate break; 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate if (sideno == MD_MAXSIDES) { 2550Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_HOSTNOSIDE, sp->setno, 2560Sstevel@tonic-gate hostname, NULL, sp->setname); 2570Sstevel@tonic-gate return; 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate if ((my_dd = metaget_drivedesc_sideno(my_sp, sideno, MD_BASICNAME_OK, 2610Sstevel@tonic-gate ep)) == NULL) { 2620Sstevel@tonic-gate if (! mdisok(ep)) 2630Sstevel@tonic-gate return; 2640Sstevel@tonic-gate /* we are supposed to have drives!!!! */ 2650Sstevel@tonic-gate assert(0); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate /* 2690Sstevel@tonic-gate * The system is either all devid or all 2700Sstevel@tonic-gate * non-devid so we look at the first item 2710Sstevel@tonic-gate * in the list to determine if we're using devids or not. 2720Sstevel@tonic-gate * We also check to make sure it's not a multi-node diskset. 2730Sstevel@tonic-gate * If it is, we don't use devid's. 2740Sstevel@tonic-gate * 2750Sstevel@tonic-gate * For did disks, the dd_dnp->devid is a valid pointer which 2760Sstevel@tonic-gate * points to a '' string of devid. We need to check this 2770Sstevel@tonic-gate * before set the using_devid. 2780Sstevel@tonic-gate */ 2790Sstevel@tonic-gate if ((dd->dd_dnp->devid != NULL) && (dd->dd_dnp->devid[0] != '\0') && 2800Sstevel@tonic-gate (!(MD_MNSET_DESC(sd)))) 2810Sstevel@tonic-gate using_devid = 1; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate /* 2840Sstevel@tonic-gate * We have to match-up the dd that were passed 2850Sstevel@tonic-gate * across the wire to the dd we have in this daemon. 2860Sstevel@tonic-gate * That way we can pick up the new sidenames that were 2870Sstevel@tonic-gate * passed to us and match them up with the local namespace key. 2880Sstevel@tonic-gate * Only we have the key, this cannot be passed in. 2890Sstevel@tonic-gate */ 2900Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 2910Sstevel@tonic-gate dn = p->dd_dnp; 2920Sstevel@tonic-gate devid_remote = NULL; 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate if (dn->devid != NULL && (strlen(dn->devid) != 0) && 2950Sstevel@tonic-gate using_devid) { 2960Sstevel@tonic-gate /* 2970Sstevel@tonic-gate * We have a devid so use it 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate (void) devid_str_decode(dn->devid, &devid_remote, NULL); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* check to make sure using_devid agrees with reality... */ 3030Sstevel@tonic-gate if ((using_devid == 1) && (devid_remote == NULL)) { 3040Sstevel@tonic-gate /* something went really wrong. Can't process */ 3050Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_INVALIDDEVID, sp->setno, 3060Sstevel@tonic-gate hostname, dn->cname, sp->setname); 3070Sstevel@tonic-gate return; 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate for (q = my_dd; q != NULL; q = q->dd_next) { 3110Sstevel@tonic-gate my_dn = q->dd_dnp; 3120Sstevel@tonic-gate devid_same = -1; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate if (my_dn->devid != NULL && using_devid) { 3150Sstevel@tonic-gate if (devid_str_decode(my_dn->devid, 3160Sstevel@tonic-gate &devid_local, NULL) == 0) { 3170Sstevel@tonic-gate devid_same = devid_compare(devid_remote, 3180Sstevel@tonic-gate devid_local); 3190Sstevel@tonic-gate devid_free(devid_local); 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate } 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate if (using_devid && devid_same == 0) { 3240Sstevel@tonic-gate break; 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate if (!using_devid && 3280Sstevel@tonic-gate strcmp(my_dn->cname, dn->cname) == 0) 3290Sstevel@tonic-gate break; 3300Sstevel@tonic-gate } 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate if (devid_remote) { 3330Sstevel@tonic-gate devid_free(devid_remote); 3340Sstevel@tonic-gate } 3350Sstevel@tonic-gate assert(q != NULL); 3360Sstevel@tonic-gate assert(my_dn->side_names_key != MD_KEYWILD); 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 3390Sstevel@tonic-gate /* 3400Sstevel@tonic-gate * Add the side names to the local db 3410Sstevel@tonic-gate * for this node only. 3420Sstevel@tonic-gate */ 3430Sstevel@tonic-gate if (add_sideno_sidenm(dn->side_names, 3440Sstevel@tonic-gate my_dn->side_names_key, mysideno, sd, ep)) 3450Sstevel@tonic-gate return; 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * Sidenames for this drive were added 3480Sstevel@tonic-gate * to this host during the routine adddrvs. 3490Sstevel@tonic-gate * The sidenames that were added are the 3500Sstevel@tonic-gate * names associated with this drive on 3510Sstevel@tonic-gate * each of the hosts that were previously 3520Sstevel@tonic-gate * in the set. 3530Sstevel@tonic-gate * When the sidename for this drive on 3540Sstevel@tonic-gate * this host is added, the sidename 3550Sstevel@tonic-gate * from the host executing the command 3560Sstevel@tonic-gate * (not this host) is sent to this host. 3570Sstevel@tonic-gate * This host finds the originating host's 3580Sstevel@tonic-gate * sidename and can then determine this 3590Sstevel@tonic-gate * host's sidename. 3600Sstevel@tonic-gate * The sidenames from the other hosts serve 3610Sstevel@tonic-gate * only as temporary sidenames until this 3620Sstevel@tonic-gate * host's sidename can be added. 3630Sstevel@tonic-gate * In order to conserve space in the 3640Sstevel@tonic-gate * local mddb, the code now deletes the 3650Sstevel@tonic-gate * temporary sidenames added during adddrvs. 3660Sstevel@tonic-gate * When finished, only the sidename for this 3670Sstevel@tonic-gate * node should be left. 3680Sstevel@tonic-gate * Ignore any errors during this process since 3690Sstevel@tonic-gate * a failure to delete the extraneous 3700Sstevel@tonic-gate * sidenames shouldn't cause this routine 3710Sstevel@tonic-gate * to fail (in case that sidename didn't exist). 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate nd = sd->sd_nodelist; 3740Sstevel@tonic-gate while (nd) { 3750Sstevel@tonic-gate if (nd->nd_nodeid != mysideno) { 3760Sstevel@tonic-gate if (del_sideno_sidenm( 3770Sstevel@tonic-gate dn->side_names_key, 3780Sstevel@tonic-gate nd->nd_nodeid, ep) == -1) 3790Sstevel@tonic-gate mdclrerror(ep); 3800Sstevel@tonic-gate } 3810Sstevel@tonic-gate nd = nd->nd_next; 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate } else { 3840Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 3850Sstevel@tonic-gate /* Skip empty slots */ 3860Sstevel@tonic-gate if (sd->sd_nodes[i][0] == '\0') 3870Sstevel@tonic-gate continue; 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate /* Skip nodes not being added */ 3900Sstevel@tonic-gate if (! strinlst(sd->sd_nodes[i], 3910Sstevel@tonic-gate node_c, node_v)) 3920Sstevel@tonic-gate continue; 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /* Add the per side names to local db */ 3950Sstevel@tonic-gate if (add_sideno_sidenm(dn->side_names, 3960Sstevel@tonic-gate my_dn->side_names_key, i, sd, ep)) 3970Sstevel@tonic-gate return; 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate } 4010Sstevel@tonic-gate } 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate /* ARGSUSED */ 4040Sstevel@tonic-gate bool_t 4050Sstevel@tonic-gate mdrpc_flush_internal_common(mdrpc_null_args *args, mdrpc_generic_res *res, 4060Sstevel@tonic-gate struct svc_req *rqstp) 4070Sstevel@tonic-gate { 4080Sstevel@tonic-gate md_error_t *ep = &res->status; 4090Sstevel@tonic-gate int err, 4100Sstevel@tonic-gate op_mode = W_OK; 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate memset(res, 0, sizeof (*res)); 4130Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 4140Sstevel@tonic-gate return (FALSE); 4150Sstevel@tonic-gate else if (err != 0) 4160Sstevel@tonic-gate return (TRUE); 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate metaflushnames(1); 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate err = svc_fini(ep); 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate return (TRUE); 4230Sstevel@tonic-gate } 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate bool_t 4260Sstevel@tonic-gate mdrpc_flush_internal_1_svc(mdrpc_null_args *args, mdrpc_generic_res *res, 4270Sstevel@tonic-gate struct svc_req *rqstp) 4280Sstevel@tonic-gate { 4290Sstevel@tonic-gate return (mdrpc_flush_internal_common(args, res, rqstp)); 4300Sstevel@tonic-gate } 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate bool_t 4330Sstevel@tonic-gate mdrpc_flush_internal_2_svc(mdrpc_null_args *args, mdrpc_generic_res *res, 4340Sstevel@tonic-gate struct svc_req *rqstp) 4350Sstevel@tonic-gate { 4360Sstevel@tonic-gate return (mdrpc_flush_internal_common(args, res, rqstp)); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate /* 4400Sstevel@tonic-gate * add 1 or more namespace entries per drive record. 4410Sstevel@tonic-gate * (into the local namespace) 4420Sstevel@tonic-gate */ 4430Sstevel@tonic-gate bool_t 4440Sstevel@tonic-gate mdrpc_add_drv_sidenms_common( 4450Sstevel@tonic-gate mdrpc_drv_sidenm_2_args_r1 *args, 4460Sstevel@tonic-gate mdrpc_generic_res *res, 4470Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 4480Sstevel@tonic-gate ) 4490Sstevel@tonic-gate { 4500Sstevel@tonic-gate md_error_t *ep = &res->status; 4510Sstevel@tonic-gate int err; 4520Sstevel@tonic-gate int op_mode = W_OK; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* setup, check permissions */ 4550Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 4560Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 4570Sstevel@tonic-gate return (FALSE); 4580Sstevel@tonic-gate else if (err != 0) 4590Sstevel@tonic-gate return (TRUE); 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 4620Sstevel@tonic-gate return (TRUE); 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* doit */ 4650Sstevel@tonic-gate add_drv_sidenms(args->hostname, args->sp, args->sd, 4660Sstevel@tonic-gate args->node_v.node_v_len, args->node_v.node_v_val, ep); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate err = svc_fini(ep); 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate return (TRUE); 4710Sstevel@tonic-gate } 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate /* 4740Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 4750Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 4760Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 4770Sstevel@tonic-gate */ 4780Sstevel@tonic-gate bool_t 4790Sstevel@tonic-gate mdrpc_add_drv_sidenms_1_svc( 4800Sstevel@tonic-gate mdrpc_drv_sidenm_args *args, 4810Sstevel@tonic-gate mdrpc_generic_res *res, 4820Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 4830Sstevel@tonic-gate ) 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate bool_t retval; 4860Sstevel@tonic-gate mdrpc_drv_sidenm_2_args_r1 v2_args; 4870Sstevel@tonic-gate int i, j; 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate /* allocate memory */ 4900Sstevel@tonic-gate v2_args.sd = Zalloc(sizeof (md_set_desc)); 4910Sstevel@tonic-gate alloc_newdrvdesc(args->sd->sd_drvs, &v2_args.sd->sd_drvs); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate /* build args */ 4940Sstevel@tonic-gate v2_args.hostname = args->hostname; 4950Sstevel@tonic-gate v2_args.cl_sk = args->cl_sk; 4960Sstevel@tonic-gate v2_args.sp = args->sp; 4970Sstevel@tonic-gate /* set descriptor */ 4980Sstevel@tonic-gate v2_args.sd->sd_ctime = args->sd->sd_ctime; 4990Sstevel@tonic-gate v2_args.sd->sd_genid = args->sd->sd_genid; 5000Sstevel@tonic-gate v2_args.sd->sd_setno = args->sd->sd_setno; 5010Sstevel@tonic-gate v2_args.sd->sd_flags = args->sd->sd_flags; 5020Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 5030Sstevel@tonic-gate v2_args.sd->sd_isown[i] = args->sd->sd_isown[i]; 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate for (j = 0; j < MD_MAX_NODENAME_PLUS_1; j++) 5060Sstevel@tonic-gate v2_args.sd->sd_nodes[i][j] = 5070Sstevel@tonic-gate args->sd->sd_nodes[i][j]; 5080Sstevel@tonic-gate } 5090Sstevel@tonic-gate v2_args.sd->sd_med = args->sd->sd_med; 5100Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 5110Sstevel@tonic-gate meta_conv_drvdesc_old2new(args->sd->sd_drvs, v2_args.sd->sd_drvs); 5120Sstevel@tonic-gate v2_args.node_v.node_v_len = args->node_v.node_v_len; 5130Sstevel@tonic-gate v2_args.node_v.node_v_val = args->node_v.node_v_val; 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate retval = mdrpc_add_drv_sidenms_common(&v2_args, res, rqstp); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate free(v2_args.sd); 5180Sstevel@tonic-gate free_newdrvdesc(v2_args.sd->sd_drvs); 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate return (retval); 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate bool_t 5240Sstevel@tonic-gate mdrpc_add_drv_sidenms_2_svc( 5250Sstevel@tonic-gate mdrpc_drv_sidenm_2_args *args, 5260Sstevel@tonic-gate mdrpc_generic_res *res, 5270Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 5280Sstevel@tonic-gate ) 5290Sstevel@tonic-gate { 5300Sstevel@tonic-gate switch (args->rev) { 5310Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 5320Sstevel@tonic-gate return (mdrpc_add_drv_sidenms_common( 5330Sstevel@tonic-gate &args->mdrpc_drv_sidenm_2_args_u.rev1, res, rqstp)); 5340Sstevel@tonic-gate default: 5350Sstevel@tonic-gate return (FALSE); 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate static int 5400Sstevel@tonic-gate add_sidenamelist( 5410Sstevel@tonic-gate mddrivename_t *dn, 5420Sstevel@tonic-gate side_t thisside, 5430Sstevel@tonic-gate md_set_record *sr, /* used by RPC version 2 */ 5440Sstevel@tonic-gate md_error_t *ep 5450Sstevel@tonic-gate ) 5460Sstevel@tonic-gate { 5470Sstevel@tonic-gate mdsidenames_t *sn; 5480Sstevel@tonic-gate mdkey_t key; 5490Sstevel@tonic-gate int err; 5500Sstevel@tonic-gate mdsetname_t *local_sp; 5510Sstevel@tonic-gate md_mnset_record *mnsr; 5520Sstevel@tonic-gate md_mnnode_record *nr; 5530Sstevel@tonic-gate uint_t nodeid = 0; 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) 5560Sstevel@tonic-gate return (-1); 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate key = MD_KEYWILD; 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate /* 5610Sstevel@tonic-gate * If a multi-node diskset, find nodeid associated with this node. 5620Sstevel@tonic-gate */ 5630Sstevel@tonic-gate if (MD_MNSET_REC(sr)) { 5640Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 5650Sstevel@tonic-gate nr = mnsr->sr_nodechain; 5660Sstevel@tonic-gate while (nr) { 5670Sstevel@tonic-gate if (strcmp(nr->nr_nodename, mynode()) == 0) { 5680Sstevel@tonic-gate break; 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate nr = nr->nr_next; 5710Sstevel@tonic-gate } 5720Sstevel@tonic-gate /* 5730Sstevel@tonic-gate * If node is found, then a new drive is being added to 5740Sstevel@tonic-gate * a MN set of which this node is a member. 5750Sstevel@tonic-gate * If node is not found, then this host is being added to 5760Sstevel@tonic-gate * a MN set that has drives associated with it. 5770Sstevel@tonic-gate */ 5780Sstevel@tonic-gate if (nr) 5790Sstevel@tonic-gate nodeid = nr->nr_nodeid; 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate for (sn = dn->side_names; sn != NULL; sn = sn->next) { 5820Sstevel@tonic-gate if (MD_MNSET_REC(sr)) { 5830Sstevel@tonic-gate /* 5840Sstevel@tonic-gate * In multi-node disksets, only add side information 5850Sstevel@tonic-gate * to the local mddb about this node. 5860Sstevel@tonic-gate * If the sideno for this node is found, then 5870Sstevel@tonic-gate * a new drive is being added to a MN set of 5880Sstevel@tonic-gate * which this node is a member. 5890Sstevel@tonic-gate * If the sideno for this node is not found, then 5900Sstevel@tonic-gate * this host is being added to a MNset that 5910Sstevel@tonic-gate * has drives associated with it. In this case, 5920Sstevel@tonic-gate * need to add the sidename associated with the 5930Sstevel@tonic-gate * rpc client, but since we don't know which node 5940Sstevel@tonic-gate * is the client, then add temp entries for all sides. 5950Sstevel@tonic-gate * Later, the sidename for this node will be set 5960Sstevel@tonic-gate * via add_drv_sidenms and then the temp 5970Sstevel@tonic-gate * sidenames can be removed. 5980Sstevel@tonic-gate */ 5990Sstevel@tonic-gate if (nodeid == sn->sideno) { 6000Sstevel@tonic-gate if ((err = add_name(local_sp, sn->sideno, key, 6010Sstevel@tonic-gate sn->dname, sn->mnum, sn->cname, ep)) == -1) 6020Sstevel@tonic-gate return (-1); 6030Sstevel@tonic-gate key = (mdkey_t)err; 6040Sstevel@tonic-gate break; 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate } else { 6070Sstevel@tonic-gate /* 6080Sstevel@tonic-gate * When a sidename is added into the namespace the local 6090Sstevel@tonic-gate * side information for the name is added first of all. 6100Sstevel@tonic-gate * When the first sidename is created this causes the 6110Sstevel@tonic-gate * devid of the disk to be recorded in the namespace, if 6120Sstevel@tonic-gate * the non-local side information is added first then 6130Sstevel@tonic-gate * there is the possibility of getting the wrong devid 6140Sstevel@tonic-gate * because there is no guarantee that the dev_t (mnum in 6150Sstevel@tonic-gate * this instance) is the same across all the nodes in 6160Sstevel@tonic-gate * the set. So the only way to make sure that the 6170Sstevel@tonic-gate * correct dev_t is used is to force the adding in of 6180Sstevel@tonic-gate * the local sidename record first of all. This same 6190Sstevel@tonic-gate * issue affects add_key_name(). 6200Sstevel@tonic-gate */ 6210Sstevel@tonic-gate if (sn->sideno != thisside) 6220Sstevel@tonic-gate continue; 6230Sstevel@tonic-gate if ((err = add_name(local_sp, sn->sideno+SKEW, key, 6240Sstevel@tonic-gate sn->dname, sn->mnum, sn->cname, ep)) == -1) 6250Sstevel@tonic-gate return (-1); 6260Sstevel@tonic-gate key = (mdkey_t)err; 6270Sstevel@tonic-gate break; 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate } 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate /* 6320Sstevel@tonic-gate * Now the other sides for non-MN set 6330Sstevel@tonic-gate */ 6340Sstevel@tonic-gate if (!MD_MNSET_REC(sr)) { 6350Sstevel@tonic-gate for (sn = dn->side_names; sn != NULL; sn = sn->next) { 6360Sstevel@tonic-gate if (sn->sideno == thisside) 6370Sstevel@tonic-gate continue; 6380Sstevel@tonic-gate if ((err = add_name(local_sp, sn->sideno+SKEW, key, 6390Sstevel@tonic-gate sn->dname, sn->mnum, sn->cname, ep)) == -1) 6400Sstevel@tonic-gate return (-1); 6410Sstevel@tonic-gate key = (mdkey_t)err; 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate /* Temporarily add all sides. */ 6460Sstevel@tonic-gate if ((key == MD_KEYWILD) && (MD_MNSET_REC(sr))) { 6470Sstevel@tonic-gate for (sn = dn->side_names; sn != NULL; sn = sn->next) { 6480Sstevel@tonic-gate sn = dn->side_names; 6490Sstevel@tonic-gate if (sn) { 6500Sstevel@tonic-gate if ((err = add_name(local_sp, sn->sideno, key, 6510Sstevel@tonic-gate sn->dname, sn->mnum, sn->cname, ep)) == -1) 6520Sstevel@tonic-gate return (-1); 6530Sstevel@tonic-gate key = (mdkey_t)err; 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate } 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate dn->side_names_key = key; 6590Sstevel@tonic-gate return (0); 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate static void 6630Sstevel@tonic-gate adddrvs( 6640Sstevel@tonic-gate char *setname, 6650Sstevel@tonic-gate md_drive_desc *dd, 6660Sstevel@tonic-gate md_timeval32_t timestamp, 6670Sstevel@tonic-gate ulong_t genid, 6680Sstevel@tonic-gate md_error_t *ep 6690Sstevel@tonic-gate ) 6700Sstevel@tonic-gate { 6710Sstevel@tonic-gate mddb_userreq_t req; 6720Sstevel@tonic-gate md_drive_record *dr; 6730Sstevel@tonic-gate md_set_record *sr; 6740Sstevel@tonic-gate md_drive_desc *p; 6750Sstevel@tonic-gate mddrivename_t *dn; 6760Sstevel@tonic-gate mdname_t *np; 6770Sstevel@tonic-gate md_dev64_t dev; 6780Sstevel@tonic-gate md_error_t xep = mdnullerror; 6790Sstevel@tonic-gate int i; 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate if ((sr = getsetbyname(setname, ep)) == NULL) 6820Sstevel@tonic-gate return; 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate if (MD_MNSET_REC(sr)) 6850Sstevel@tonic-gate i = 0; 6860Sstevel@tonic-gate else { 6870Sstevel@tonic-gate /* get thisside */ 6880Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 6890Sstevel@tonic-gate if (sr->sr_nodes[i][0] == '\0') 6900Sstevel@tonic-gate continue; 6910Sstevel@tonic-gate if (strcmp(mynode(), sr->sr_nodes[i]) == 0) 6920Sstevel@tonic-gate break; 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate if (i == MD_MAXSIDES) { 6960Sstevel@tonic-gate /* so find the first free slot! */ 6970Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 6980Sstevel@tonic-gate if (sr->sr_nodes[i][0] == '\0') 6990Sstevel@tonic-gate break; 7000Sstevel@tonic-gate } 7010Sstevel@tonic-gate } 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 7050Sstevel@tonic-gate uint_t rep_slice; 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate dn = p->dd_dnp; 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate /* Add the per side names to the local db */ 7100Sstevel@tonic-gate if (add_sidenamelist(dn, (side_t)i, sr, ep)) { 7110Sstevel@tonic-gate free_sr(sr); 7120Sstevel@tonic-gate return; 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate /* Create the drive record */ 7160Sstevel@tonic-gate (void) memset(&req, 0, sizeof (req)); 7170Sstevel@tonic-gate METAD_SETUP_DR(MD_DB_CREATE, 0); 7180Sstevel@tonic-gate req.ur_size = sizeof (*dr); 7190Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 7200Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 7210Sstevel@tonic-gate free_sr(sr); 7220Sstevel@tonic-gate return; 7230Sstevel@tonic-gate } 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate /* Fill in the drive record values */ 7260Sstevel@tonic-gate dr = Zalloc(sizeof (*dr)); 7270Sstevel@tonic-gate dr->dr_selfid = req.ur_recid; 7280Sstevel@tonic-gate dr->dr_dbcnt = p->dd_dbcnt; 7290Sstevel@tonic-gate dr->dr_dbsize = p->dd_dbsize; 7300Sstevel@tonic-gate dr->dr_key = dn->side_names_key; 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate dr->dr_ctime = timestamp; 7330Sstevel@tonic-gate dr->dr_genid = genid; 7340Sstevel@tonic-gate dr->dr_revision = MD_DRIVE_RECORD_REVISION; 7350Sstevel@tonic-gate dr->dr_flags = MD_DR_ADD; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate /* Link the drive records and fill in in-core data */ 7380Sstevel@tonic-gate dr_cache_add(sr, dr); 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate dev = NODEV64; 7410Sstevel@tonic-gate if ((meta_replicaslice(dn, &rep_slice, &xep) == 0) && 7420Sstevel@tonic-gate ((np = metaslicename(dn, rep_slice, &xep)) != NULL)) 7430Sstevel@tonic-gate dev = np->dev; 7440Sstevel@tonic-gate else 7450Sstevel@tonic-gate mdclrerror(&xep); 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_REMOVE, SVM_TAG_DRIVE, 7480Sstevel@tonic-gate MD_LOCAL_SET, dev); 7490Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_ADD, SVM_TAG_DRIVE, 7500Sstevel@tonic-gate sr->sr_setno, dev); 7510Sstevel@tonic-gate } 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate /* Commit all the records atomically */ 7540Sstevel@tonic-gate commitset(sr, TRUE, ep); 7550Sstevel@tonic-gate free_sr(sr); 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate /* 7590Sstevel@tonic-gate * add 1 or more drive records to a set. 7600Sstevel@tonic-gate */ 7610Sstevel@tonic-gate bool_t 7620Sstevel@tonic-gate mdrpc_adddrvs_common( 7630Sstevel@tonic-gate mdrpc_drives_2_args_r1 *args, 7640Sstevel@tonic-gate mdrpc_generic_res *res, 7650Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 7660Sstevel@tonic-gate ) 7670Sstevel@tonic-gate { 7680Sstevel@tonic-gate md_error_t *ep = &res->status; 7690Sstevel@tonic-gate int err; 7700Sstevel@tonic-gate int op_mode = W_OK; 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate /* setup, check permissions */ 7730Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 7740Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 7750Sstevel@tonic-gate return (FALSE); 7760Sstevel@tonic-gate else if (err != 0) 7770Sstevel@tonic-gate return (TRUE); 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 7800Sstevel@tonic-gate return (TRUE); 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate /* doit */ 7830Sstevel@tonic-gate adddrvs(args->sp->setname, args->drivedescs, args->timestamp, 7840Sstevel@tonic-gate args->genid, ep); 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate err = svc_fini(ep); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate return (TRUE); 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate /* 7920Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 7930Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 7940Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 7950Sstevel@tonic-gate */ 7960Sstevel@tonic-gate bool_t 7970Sstevel@tonic-gate mdrpc_adddrvs_1_svc( 7980Sstevel@tonic-gate mdrpc_drives_args *args, 7990Sstevel@tonic-gate mdrpc_generic_res *res, 8000Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 8010Sstevel@tonic-gate ) 8020Sstevel@tonic-gate { 8030Sstevel@tonic-gate bool_t retval; 8040Sstevel@tonic-gate mdrpc_drives_2_args_r1 v2_args; 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate /* allocate memory */ 8070Sstevel@tonic-gate alloc_newdrvdesc(args->drivedescs, &v2_args.drivedescs); 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate /* build args */ 8100Sstevel@tonic-gate v2_args.cl_sk = args->cl_sk; 8110Sstevel@tonic-gate v2_args.sp = args->sp; 8120Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 8130Sstevel@tonic-gate meta_conv_drvdesc_old2new(args->drivedescs, v2_args.drivedescs); 8140Sstevel@tonic-gate v2_args.timestamp = args->timestamp; 8150Sstevel@tonic-gate v2_args.genid = args->genid; 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate retval = mdrpc_adddrvs_common(&v2_args, res, rqstp); 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate free_newdrvdesc(v2_args.drivedescs); 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate return (retval); 8220Sstevel@tonic-gate } 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate bool_t 8250Sstevel@tonic-gate mdrpc_adddrvs_2_svc( 8260Sstevel@tonic-gate mdrpc_drives_2_args *args, 8270Sstevel@tonic-gate mdrpc_generic_res *res, 8280Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 8290Sstevel@tonic-gate ) 8300Sstevel@tonic-gate { 8310Sstevel@tonic-gate switch (args->rev) { 8320Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 8330Sstevel@tonic-gate return (mdrpc_adddrvs_common( 8340Sstevel@tonic-gate &args->mdrpc_drives_2_args_u.rev1, res, rqstp)); 8350Sstevel@tonic-gate default: 8360Sstevel@tonic-gate return (FALSE); 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate } 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate static void 8410Sstevel@tonic-gate addhosts( 8420Sstevel@tonic-gate char *setname, 8430Sstevel@tonic-gate int node_c, 8440Sstevel@tonic-gate char **node_v, 8450Sstevel@tonic-gate int version, /* RPC version of calling routine */ 8460Sstevel@tonic-gate md_error_t *ep 8470Sstevel@tonic-gate ) 8480Sstevel@tonic-gate { 8490Sstevel@tonic-gate mddb_userreq_t req; 8500Sstevel@tonic-gate md_set_record *sr; 8510Sstevel@tonic-gate int i, j; 8520Sstevel@tonic-gate md_mnset_record *mnsr; 8530Sstevel@tonic-gate md_mnnode_record *nr; 8540Sstevel@tonic-gate mddb_set_node_params_t snp; 8550Sstevel@tonic-gate int nodecnt; 8560Sstevel@tonic-gate mndiskset_membershiplist_t *nl, *nl2; 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate if ((sr = getsetbyname(setname, ep)) == NULL) 8590Sstevel@tonic-gate return; 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 8620Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 8630Sstevel@tonic-gate mnsr = (md_mnset_record *)sr; 8640Sstevel@tonic-gate /* 8650Sstevel@tonic-gate * Verify nodes are in membership list on THIS node. 8660Sstevel@tonic-gate * Initiating node has verified that nodes are in membership 8670Sstevel@tonic-gate * list on the initiating node. 8680Sstevel@tonic-gate * Get membershiplist from API routine. If there's 8690Sstevel@tonic-gate * an error, fail to add hosts and pass back error. 8700Sstevel@tonic-gate */ 8710Sstevel@tonic-gate if (meta_read_nodelist(&nodecnt, &nl, ep) == -1) { 8720Sstevel@tonic-gate free_sr(sr); 8730Sstevel@tonic-gate return; 8740Sstevel@tonic-gate } 8750Sstevel@tonic-gate /* Verify that all nodes are in member list */ 8760Sstevel@tonic-gate for (i = 0; i < node_c; i++) { 8770Sstevel@tonic-gate /* 8780Sstevel@tonic-gate * If node in list isn't a member of the membership, 8790Sstevel@tonic-gate * just return error. 8800Sstevel@tonic-gate */ 8810Sstevel@tonic-gate if (meta_is_member(node_v[i], NULL, nl) == 0) { 8820Sstevel@tonic-gate meta_free_nodelist(nl); 8830Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_NOTINMEMBERLIST, 8840Sstevel@tonic-gate sr->sr_setno, node_v[i], NULL, setname); 8850Sstevel@tonic-gate free_sr(sr); 8860Sstevel@tonic-gate return; 8870Sstevel@tonic-gate } 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate for (i = 0; i < node_c; i++) { 8920Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 8930Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 8940Sstevel@tonic-gate mnsr = (md_mnset_record *)sr; 8950Sstevel@tonic-gate /* Create the node record */ 8960Sstevel@tonic-gate (void) memset(&req, 0, sizeof (req)); 8970Sstevel@tonic-gate METAD_SETUP_NR(MD_DB_CREATE, 0); 8980Sstevel@tonic-gate req.ur_size = sizeof (*nr); 8990Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) 9000Sstevel@tonic-gate != 0) { 9010Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 9020Sstevel@tonic-gate meta_free_nodelist(nl); 9030Sstevel@tonic-gate free_sr(sr); 9040Sstevel@tonic-gate return; 9050Sstevel@tonic-gate } 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate nr = Zalloc(sizeof (*nr)); 9080Sstevel@tonic-gate nr->nr_revision = MD_MNNODE_RECORD_REVISION; 9090Sstevel@tonic-gate nr->nr_selfid = req.ur_recid; 9100Sstevel@tonic-gate nr->nr_ctime = sr->sr_ctime; 9110Sstevel@tonic-gate nr->nr_genid = sr->sr_genid; 9120Sstevel@tonic-gate nr->nr_flags = MD_MN_NODE_ADD; 9130Sstevel@tonic-gate nl2 = nl; 9140Sstevel@tonic-gate while (nl2) { 9150Sstevel@tonic-gate if (strcmp(nl2->msl_node_name, node_v[i]) 9160Sstevel@tonic-gate == 0) { 9170Sstevel@tonic-gate nr->nr_nodeid = nl2->msl_node_id; 9180Sstevel@tonic-gate break; 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate nl2 = nl2->next; 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate (void) strcpy(nr->nr_nodename, node_v[i]); 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate /* 9260Sstevel@tonic-gate * When a node is added to a MN diskset, set the 9270Sstevel@tonic-gate * nodeid of this node in the md_set structure 9280Sstevel@tonic-gate * in the kernel. 9290Sstevel@tonic-gate */ 9300Sstevel@tonic-gate if (strcmp(nr->nr_nodename, mynode()) == 0) { 9310Sstevel@tonic-gate (void) memset(&snp, 0, sizeof (snp)); 9320Sstevel@tonic-gate snp.sn_nodeid = nr->nr_nodeid; 9330Sstevel@tonic-gate snp.sn_setno = mnsr->sr_setno; 9340Sstevel@tonic-gate if (metaioctl(MD_MN_SET_NODEID, &snp, 9350Sstevel@tonic-gate &snp.sn_mde, NULL) != 0) { 9360Sstevel@tonic-gate (void) mdstealerror(ep, &snp.sn_mde); 9370Sstevel@tonic-gate meta_free_nodelist(nl); 9380Sstevel@tonic-gate free_sr(sr); 9390Sstevel@tonic-gate return; 9400Sstevel@tonic-gate } 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate /* Link the node records and fill in in-core data */ 9440Sstevel@tonic-gate mnnr_cache_add(mnsr, nr); 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_ADD, SVM_TAG_HOST, 9470Sstevel@tonic-gate mnsr->sr_setno, nr->nr_nodeid); 9480Sstevel@tonic-gate } else { 9490Sstevel@tonic-gate for (j = 0; j < MD_MAXSIDES; j++) { 9500Sstevel@tonic-gate if (sr->sr_nodes[j][0] != '\0') 9510Sstevel@tonic-gate continue; 9520Sstevel@tonic-gate (void) strcpy(sr->sr_nodes[j], node_v[i]); 9530Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_ADD, 9540Sstevel@tonic-gate SVM_TAG_HOST, sr->sr_setno, j); 9550Sstevel@tonic-gate break; 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate } 9590Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 9600Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 9610Sstevel@tonic-gate meta_free_nodelist(nl); 9620Sstevel@tonic-gate } 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate (void) memset(&req, '\0', sizeof (req)); 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_SETDATA, sr->sr_selfid) 9670Sstevel@tonic-gate 9680Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 9690Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 9700Sstevel@tonic-gate req.ur_size = sizeof (*mnsr); 9710Sstevel@tonic-gate } else { 9720Sstevel@tonic-gate req.ur_size = sizeof (*sr); 9730Sstevel@tonic-gate } 9740Sstevel@tonic-gate req.ur_data = (uintptr_t)sr; 9750Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 9760Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 9770Sstevel@tonic-gate free_sr(sr); 9780Sstevel@tonic-gate return; 9790Sstevel@tonic-gate } 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate commitset(sr, TRUE, ep); 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate free_sr(sr); 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate /* 9870Sstevel@tonic-gate * add 1 or more hosts to a set. 9880Sstevel@tonic-gate */ 9890Sstevel@tonic-gate bool_t 9900Sstevel@tonic-gate mdrpc_addhosts_common( 9910Sstevel@tonic-gate mdrpc_host_args *args, 9920Sstevel@tonic-gate mdrpc_generic_res *res, 9930Sstevel@tonic-gate struct svc_req *rqstp, /* RPC stuff */ 9940Sstevel@tonic-gate int version /* RPC version */ 9950Sstevel@tonic-gate ) 9960Sstevel@tonic-gate { 9970Sstevel@tonic-gate md_error_t *ep = &res->status; 9980Sstevel@tonic-gate int err; 9990Sstevel@tonic-gate int op_mode = W_OK; 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate /* setup, check permissions */ 10020Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 10030Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 10040Sstevel@tonic-gate return (FALSE); 10050Sstevel@tonic-gate else if (err != 0) 10060Sstevel@tonic-gate return (TRUE); 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 10090Sstevel@tonic-gate return (TRUE); 10100Sstevel@tonic-gate 10110Sstevel@tonic-gate /* doit */ 10120Sstevel@tonic-gate addhosts(args->sp->setname, args->hosts.hosts_len, 10130Sstevel@tonic-gate args->hosts.hosts_val, version, ep); 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate err = svc_fini(ep); 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate return (TRUE); 10180Sstevel@tonic-gate } 10190Sstevel@tonic-gate 10200Sstevel@tonic-gate bool_t 10210Sstevel@tonic-gate mdrpc_addhosts_1_svc( 10220Sstevel@tonic-gate mdrpc_host_args *args, 10230Sstevel@tonic-gate mdrpc_generic_res *res, 10240Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 10250Sstevel@tonic-gate ) 10260Sstevel@tonic-gate { 10270Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION) to common routine */ 10280Sstevel@tonic-gate return (mdrpc_addhosts_common(args, res, rqstp, METAD_VERSION)); 10290Sstevel@tonic-gate } 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate bool_t 10320Sstevel@tonic-gate mdrpc_addhosts_2_svc( 10330Sstevel@tonic-gate mdrpc_host_2_args *args, 10340Sstevel@tonic-gate mdrpc_generic_res *res, 10350Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 10360Sstevel@tonic-gate ) 10370Sstevel@tonic-gate { 10380Sstevel@tonic-gate switch (args->rev) { 10390Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 10400Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION_DEVID) to common routine */ 10410Sstevel@tonic-gate return (mdrpc_addhosts_common( 10420Sstevel@tonic-gate &args->mdrpc_host_2_args_u.rev1, res, 10430Sstevel@tonic-gate rqstp, METAD_VERSION_DEVID)); 10440Sstevel@tonic-gate default: 10450Sstevel@tonic-gate return (FALSE); 10460Sstevel@tonic-gate } 10470Sstevel@tonic-gate } 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate static void 10500Sstevel@tonic-gate createset( 10510Sstevel@tonic-gate mdsetname_t *sp, 10520Sstevel@tonic-gate md_node_nm_arr_t nodes, 10530Sstevel@tonic-gate md_timeval32_t timestamp, 10540Sstevel@tonic-gate ulong_t genid, 10550Sstevel@tonic-gate md_error_t *ep 10560Sstevel@tonic-gate ) 10570Sstevel@tonic-gate { 10580Sstevel@tonic-gate mddb_userreq_t req; 10590Sstevel@tonic-gate md_set_record *sr; 10600Sstevel@tonic-gate int i; 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate (void) memset(&req, 0, sizeof (req)); 10630Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_CREATE, 0); 10640Sstevel@tonic-gate req.ur_size = sizeof (*sr); 10650Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 10660Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 10670Sstevel@tonic-gate return; 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate sr = Zalloc(sizeof (*sr)); 10710Sstevel@tonic-gate 10720Sstevel@tonic-gate sr->sr_selfid = req.ur_recid; 10730Sstevel@tonic-gate sr->sr_setno = sp->setno; 10740Sstevel@tonic-gate (void) strcpy(sr->sr_setname, sp->setname); 10750Sstevel@tonic-gate 10760Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_CREATE, SVM_TAG_SET, sp->setno, 10770Sstevel@tonic-gate NODEV64); 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate (void) meta_smf_enable(META_SMF_DISKSET, NULL); 10800Sstevel@tonic-gate 10810Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 10820Sstevel@tonic-gate (void) strcpy(sr->sr_nodes[i], nodes[i]); 10830Sstevel@tonic-gate /* Skip empty slots */ 10840Sstevel@tonic-gate if (sr->sr_nodes[i][0] == '\0') 10850Sstevel@tonic-gate continue; 10860Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_ADD, SVM_TAG_HOST, sp->setno, 10870Sstevel@tonic-gate i); 10880Sstevel@tonic-gate } 10890Sstevel@tonic-gate 10900Sstevel@tonic-gate sr->sr_ctime = timestamp; 10910Sstevel@tonic-gate sr->sr_genid = genid; 10920Sstevel@tonic-gate sr->sr_revision = MD_SET_RECORD_REVISION; 10930Sstevel@tonic-gate sr->sr_flags |= MD_SR_ADD; 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate sr->sr_mhiargs = defmhiargs; 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate sr_cache_add(sr); 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate commitset(sr, TRUE, ep); 11000Sstevel@tonic-gate } 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate static void 11030Sstevel@tonic-gate mncreateset( 11040Sstevel@tonic-gate mdsetname_t *sp, 11050Sstevel@tonic-gate md_mnnode_desc *nodelist, 11060Sstevel@tonic-gate md_timeval32_t timestamp, 11070Sstevel@tonic-gate ulong_t genid, 11080Sstevel@tonic-gate md_node_nm_t master_nodenm, 11090Sstevel@tonic-gate int master_nodeid, 11100Sstevel@tonic-gate md_error_t *ep 11110Sstevel@tonic-gate ) 11120Sstevel@tonic-gate { 11130Sstevel@tonic-gate mddb_userreq_t req; 11140Sstevel@tonic-gate md_mnset_record *mnsr; 11150Sstevel@tonic-gate md_mnnode_record *nr; 11160Sstevel@tonic-gate md_mnnode_desc *nd; 11170Sstevel@tonic-gate mddb_set_node_params_t snp; 11180Sstevel@tonic-gate int nodecnt; 11190Sstevel@tonic-gate mndiskset_membershiplist_t *nl; 11200Sstevel@tonic-gate 11210Sstevel@tonic-gate /* 11220Sstevel@tonic-gate * Validate that nodes in set being created are in the 11230Sstevel@tonic-gate * membership list on THIS node. 11240Sstevel@tonic-gate * Initiating node has verified that nodes are in membership 11250Sstevel@tonic-gate * list on the initiating node. 11260Sstevel@tonic-gate * Get membershiplist from API routine. If there's 11270Sstevel@tonic-gate * an error, fail to add set and pass back error. 11280Sstevel@tonic-gate */ 11290Sstevel@tonic-gate if (meta_read_nodelist(&nodecnt, &nl, ep) == -1) { 11300Sstevel@tonic-gate return; 11310Sstevel@tonic-gate } 11320Sstevel@tonic-gate /* Verify that all nodes are in member list */ 11330Sstevel@tonic-gate nd = nodelist; 11340Sstevel@tonic-gate while (nd) { 11350Sstevel@tonic-gate /* 11360Sstevel@tonic-gate * If node in list isn't a member of the membership, 11370Sstevel@tonic-gate * just return error. 11380Sstevel@tonic-gate */ 11390Sstevel@tonic-gate if (meta_is_member(nd->nd_nodename, 0, nl) == 0) { 11400Sstevel@tonic-gate meta_free_nodelist(nl); 11410Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_NOTINMEMBERLIST, 11420Sstevel@tonic-gate sp->setno, nd->nd_nodename, NULL, sp->setname); 11430Sstevel@tonic-gate return; 11440Sstevel@tonic-gate } 11450Sstevel@tonic-gate nd = nd->nd_next; 11460Sstevel@tonic-gate } 11470Sstevel@tonic-gate meta_free_nodelist(nl); 11480Sstevel@tonic-gate 11490Sstevel@tonic-gate (void) memset(&req, 0, sizeof (req)); 11500Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_CREATE, 0); 11510Sstevel@tonic-gate req.ur_size = sizeof (*mnsr); 11520Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 11530Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 11540Sstevel@tonic-gate return; 11550Sstevel@tonic-gate } 11560Sstevel@tonic-gate 11570Sstevel@tonic-gate mnsr = Zalloc(sizeof (*mnsr)); 11580Sstevel@tonic-gate mnsr->sr_selfid = req.ur_recid; 11590Sstevel@tonic-gate mnsr->sr_setno = sp->setno; 11600Sstevel@tonic-gate (void) strlcpy(mnsr->sr_setname, sp->setname, MD_MAX_SETNAME); 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_CREATE, SVM_TAG_SET, sp->setno, 11630Sstevel@tonic-gate NODEV64); 11640Sstevel@tonic-gate 11650Sstevel@tonic-gate (void) meta_smf_enable(META_SMF_DISKSET | META_SMF_MN_DISKSET, NULL); 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate nd = nodelist; 11680Sstevel@tonic-gate while (nd) { 11690Sstevel@tonic-gate /* Create the node record */ 11700Sstevel@tonic-gate (void) memset(&req, 0, sizeof (req)); 11710Sstevel@tonic-gate METAD_SETUP_NR(MD_DB_CREATE, 0); 11720Sstevel@tonic-gate req.ur_size = sizeof (*nr); 11730Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 11740Sstevel@tonic-gate /* Frees mnsr and any alloc'd node records */ 11750Sstevel@tonic-gate free_sr((struct md_set_record *)mnsr); 11760Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 11770Sstevel@tonic-gate return; 11780Sstevel@tonic-gate } 11790Sstevel@tonic-gate 11800Sstevel@tonic-gate nr = Zalloc(sizeof (*nr)); 11810Sstevel@tonic-gate nr->nr_revision = MD_MNNODE_RECORD_REVISION; 11820Sstevel@tonic-gate nr->nr_selfid = req.ur_recid; 11830Sstevel@tonic-gate nr->nr_ctime = timestamp; 11840Sstevel@tonic-gate nr->nr_genid = genid; 11850Sstevel@tonic-gate nr->nr_nodeid = nd->nd_nodeid; 11860Sstevel@tonic-gate nr->nr_flags = nd->nd_flags; 11870Sstevel@tonic-gate (void) strlcpy(nr->nr_nodename, nd->nd_nodename, 11880Sstevel@tonic-gate MD_MAX_NODENAME); 11890Sstevel@tonic-gate 11900Sstevel@tonic-gate /* Link the node records and fill in in-core data */ 11910Sstevel@tonic-gate mnnr_cache_add(mnsr, nr); 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_ADD, SVM_TAG_HOST, sp->setno, 11940Sstevel@tonic-gate nr->nr_nodeid); 11950Sstevel@tonic-gate 11960Sstevel@tonic-gate nd = nd->nd_next; 11970Sstevel@tonic-gate } 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate /* 12000Sstevel@tonic-gate * For backward compatibility, fill in mynode name 12010Sstevel@tonic-gate * as the only name in the sr_nodes array. This 12020Sstevel@tonic-gate * allows the pre-MNdiskset code to see that there 12030Sstevel@tonic-gate * is a node in this diskset. This will keep the 12040Sstevel@tonic-gate * pre-MNdiskset code from removing this set. 12050Sstevel@tonic-gate */ 12060Sstevel@tonic-gate (void) strlcpy(mnsr->sr_nodes_bw_compat[0], mynode(), MD_MAX_NODENAME); 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate mnsr->sr_ctime = timestamp; 12090Sstevel@tonic-gate mnsr->sr_genid = genid; 12100Sstevel@tonic-gate mnsr->sr_revision = MD_SET_RECORD_REVISION; 12110Sstevel@tonic-gate mnsr->sr_flags |= MD_SR_ADD; 12120Sstevel@tonic-gate 12130Sstevel@tonic-gate mnsr->sr_flags |= MD_SR_MN; 12140Sstevel@tonic-gate strcpy(mnsr->sr_master_nodenm, master_nodenm); 12150Sstevel@tonic-gate mnsr->sr_master_nodeid = master_nodeid; 12160Sstevel@tonic-gate 12170Sstevel@tonic-gate mnsr->sr_mhiargs = defmhiargs; 12180Sstevel@tonic-gate 12190Sstevel@tonic-gate sr_cache_add((struct md_set_record *)mnsr); 12200Sstevel@tonic-gate 12210Sstevel@tonic-gate commitset((struct md_set_record *)mnsr, TRUE, ep); 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate /* 12240Sstevel@tonic-gate * When a set is created for the first time, the nodelist 12250Sstevel@tonic-gate * will contain this node. 12260Sstevel@tonic-gate * When a node is just being added to a set, the nodelist 12270Sstevel@tonic-gate * will not contain this node. This node is added to the 12280Sstevel@tonic-gate * set structure with a later call to addhosts. 12290Sstevel@tonic-gate * 12300Sstevel@tonic-gate * So, if the nodelist contains an entry for this node 12310Sstevel@tonic-gate * then set the nodeid of this node in the md_set kernel 12320Sstevel@tonic-gate * data structure. 12330Sstevel@tonic-gate */ 12340Sstevel@tonic-gate nd = nodelist; 12350Sstevel@tonic-gate while (nd) { 12360Sstevel@tonic-gate if (strcmp(nd->nd_nodename, mynode()) == 0) { 12370Sstevel@tonic-gate break; 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate nd = nd->nd_next; 12400Sstevel@tonic-gate } 12410Sstevel@tonic-gate if (nd) { 12420Sstevel@tonic-gate (void) memset(&snp, 0, sizeof (snp)); 12430Sstevel@tonic-gate snp.sn_nodeid = nd->nd_nodeid; 12440Sstevel@tonic-gate snp.sn_setno = sp->setno; 12450Sstevel@tonic-gate if (metaioctl(MD_MN_SET_NODEID, &snp, &snp.sn_mde, NULL) != 0) { 12460Sstevel@tonic-gate (void) mdstealerror(ep, &snp.sn_mde); 12470Sstevel@tonic-gate return; 12480Sstevel@tonic-gate } 12490Sstevel@tonic-gate } 12500Sstevel@tonic-gate } 12510Sstevel@tonic-gate 12520Sstevel@tonic-gate /* 12530Sstevel@tonic-gate * create a set on a host 12540Sstevel@tonic-gate */ 12550Sstevel@tonic-gate bool_t 12560Sstevel@tonic-gate mdrpc_createset_common( 12570Sstevel@tonic-gate mdrpc_createset_args *args, 12580Sstevel@tonic-gate mdrpc_generic_res *res, 12590Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 12600Sstevel@tonic-gate ) 12610Sstevel@tonic-gate { 12620Sstevel@tonic-gate md_error_t *ep = &res->status; 12630Sstevel@tonic-gate char stringbuf1[MAXPATHLEN]; 12640Sstevel@tonic-gate char stringbuf2[MAXPATHLEN]; 12650Sstevel@tonic-gate int err; 12660Sstevel@tonic-gate int op_mode = W_OK; 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate /* setup, check permissions */ 12690Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 12700Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 12710Sstevel@tonic-gate return (FALSE); 12720Sstevel@tonic-gate else if (err != 0) 12730Sstevel@tonic-gate return (TRUE); 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 12760Sstevel@tonic-gate return (TRUE); 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate /* create the arguments for the symlink() and unlink() calls */ 12790Sstevel@tonic-gate (void) snprintf(stringbuf2, sizeof (stringbuf2), "/dev/md/%s", 12800Sstevel@tonic-gate args->sp->setname); 12810Sstevel@tonic-gate (void) snprintf(stringbuf1, sizeof (stringbuf1), "shared/%d", 12820Sstevel@tonic-gate args->sp->setno); 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate /* 12850Sstevel@tonic-gate * Since we already verified that the setname was OK, make sure to 12860Sstevel@tonic-gate * cleanup before proceeding. 12870Sstevel@tonic-gate */ 12880Sstevel@tonic-gate if (unlink(stringbuf2) == -1) { 12890Sstevel@tonic-gate if (errno != ENOENT) { 12900Sstevel@tonic-gate (void) mdsyserror(ep, errno, stringbuf2); 12910Sstevel@tonic-gate return (TRUE); 12920Sstevel@tonic-gate } 12930Sstevel@tonic-gate } 12940Sstevel@tonic-gate 12950Sstevel@tonic-gate /* create the set */ 12960Sstevel@tonic-gate createset(args->sp, args->nodes, args->timestamp, args->genid, ep); 12970Sstevel@tonic-gate 12980Sstevel@tonic-gate if (! mdisok(ep)) 12990Sstevel@tonic-gate return (TRUE); 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate /* create the symlink */ 13020Sstevel@tonic-gate if (symlink(stringbuf1, stringbuf2) == -1) 13030Sstevel@tonic-gate (void) mdsyserror(ep, errno, stringbuf2); 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate err = svc_fini(ep); 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate return (TRUE); 13080Sstevel@tonic-gate } 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate bool_t 13110Sstevel@tonic-gate mdrpc_createset_1_svc( 13120Sstevel@tonic-gate mdrpc_createset_args *args, 13130Sstevel@tonic-gate mdrpc_generic_res *res, 13140Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 13150Sstevel@tonic-gate ) 13160Sstevel@tonic-gate { 13170Sstevel@tonic-gate return (mdrpc_createset_common(args, res, rqstp)); 13180Sstevel@tonic-gate } 13190Sstevel@tonic-gate 13200Sstevel@tonic-gate bool_t 13210Sstevel@tonic-gate mdrpc_createset_2_svc( 13220Sstevel@tonic-gate mdrpc_createset_2_args *args, 13230Sstevel@tonic-gate mdrpc_generic_res *res, 13240Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 13250Sstevel@tonic-gate ) 13260Sstevel@tonic-gate { 13270Sstevel@tonic-gate switch (args->rev) { 13280Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 13290Sstevel@tonic-gate return (mdrpc_createset_common( 13300Sstevel@tonic-gate &args->mdrpc_createset_2_args_u.rev1, res, rqstp)); 13310Sstevel@tonic-gate default: 13320Sstevel@tonic-gate return (FALSE); 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate } 13350Sstevel@tonic-gate 13360Sstevel@tonic-gate bool_t 13370Sstevel@tonic-gate mdrpc_mncreateset_common( 13380Sstevel@tonic-gate mdrpc_mncreateset_args *args, 13390Sstevel@tonic-gate mdrpc_generic_res *res, 13400Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 13410Sstevel@tonic-gate ) 13420Sstevel@tonic-gate { 13430Sstevel@tonic-gate md_error_t *ep = &res->status; 13440Sstevel@tonic-gate char stringbuf1[MAXPATHLEN]; 13450Sstevel@tonic-gate char stringbuf2[MAXPATHLEN]; 13460Sstevel@tonic-gate int err; 13470Sstevel@tonic-gate int op_mode = W_OK; 13480Sstevel@tonic-gate 13490Sstevel@tonic-gate /* setup, check permissions */ 13500Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 13510Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 13520Sstevel@tonic-gate return (FALSE); 13530Sstevel@tonic-gate else if (err != 0) 13540Sstevel@tonic-gate return (TRUE); 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 13570Sstevel@tonic-gate return (TRUE); 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate /* create the arguments for the symlink() and unlink() calls */ 13600Sstevel@tonic-gate (void) snprintf(stringbuf2, sizeof (stringbuf2), "/dev/md/%s", 13610Sstevel@tonic-gate args->sp->setname); 13620Sstevel@tonic-gate (void) snprintf(stringbuf1, sizeof (stringbuf1), "shared/%d", 13630Sstevel@tonic-gate args->sp->setno); 13640Sstevel@tonic-gate 13650Sstevel@tonic-gate /* 13660Sstevel@tonic-gate * Since we already verified that the setname was OK, make sure to 13670Sstevel@tonic-gate * cleanup before proceeding. 13680Sstevel@tonic-gate */ 13690Sstevel@tonic-gate if (unlink(stringbuf2) == -1) { 13700Sstevel@tonic-gate if (errno != ENOENT) { 13710Sstevel@tonic-gate (void) mdsyserror(ep, errno, stringbuf2); 13720Sstevel@tonic-gate return (TRUE); 13730Sstevel@tonic-gate } 13740Sstevel@tonic-gate } 13750Sstevel@tonic-gate 13760Sstevel@tonic-gate /* create the set */ 13770Sstevel@tonic-gate mncreateset(args->sp, args->nodelist, args->timestamp, args->genid, 13780Sstevel@tonic-gate args->master_nodenm, args->master_nodeid, ep); 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate if (! mdisok(ep)) { 13810Sstevel@tonic-gate return (TRUE); 13820Sstevel@tonic-gate } 13830Sstevel@tonic-gate 13840Sstevel@tonic-gate /* create the symlink */ 13850Sstevel@tonic-gate if (symlink(stringbuf1, stringbuf2) == -1) 13860Sstevel@tonic-gate (void) mdsyserror(ep, errno, stringbuf2); 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate err = svc_fini(ep); 13890Sstevel@tonic-gate 13900Sstevel@tonic-gate return (TRUE); 13910Sstevel@tonic-gate } 13920Sstevel@tonic-gate 13930Sstevel@tonic-gate bool_t 13940Sstevel@tonic-gate mdrpc_mncreateset_2_svc( 13950Sstevel@tonic-gate mdrpc_mncreateset_2_args *args, 13960Sstevel@tonic-gate mdrpc_generic_res *res, 13970Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 13980Sstevel@tonic-gate ) 13990Sstevel@tonic-gate { 14000Sstevel@tonic-gate switch (args->rev) { 14010Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 14020Sstevel@tonic-gate return (mdrpc_mncreateset_common( 14030Sstevel@tonic-gate &args->mdrpc_mncreateset_2_args_u.rev1, res, rqstp)); 14040Sstevel@tonic-gate default: 14050Sstevel@tonic-gate return (FALSE); 14060Sstevel@tonic-gate } 14070Sstevel@tonic-gate } 14080Sstevel@tonic-gate 14090Sstevel@tonic-gate static void 14100Sstevel@tonic-gate del_drv_sidenms( 14110Sstevel@tonic-gate mdsetname_t *sp, 14120Sstevel@tonic-gate int version, /* RPC version of calling routine */ 14130Sstevel@tonic-gate md_error_t *ep 14140Sstevel@tonic-gate ) 14150Sstevel@tonic-gate { 14160Sstevel@tonic-gate md_set_record *sr; 14170Sstevel@tonic-gate md_drive_desc *dd, *p; 14180Sstevel@tonic-gate mddrivename_t *dn; 14190Sstevel@tonic-gate mdsetname_t *local_sp; 14200Sstevel@tonic-gate int i; 14210Sstevel@tonic-gate int rb_mode = 0; 14220Sstevel@tonic-gate 14230Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) 14240Sstevel@tonic-gate return; 14250Sstevel@tonic-gate 14260Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 14270Sstevel@tonic-gate return; 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 14300Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 14310Sstevel@tonic-gate /* 14320Sstevel@tonic-gate * In the multi-node diskset, there are no diskset 14330Sstevel@tonic-gate * entries in the local set for other nodes, so there's 14340Sstevel@tonic-gate * nothing to do. 14350Sstevel@tonic-gate */ 14360Sstevel@tonic-gate free_sr(sr); 14370Sstevel@tonic-gate return; 14380Sstevel@tonic-gate } 14390Sstevel@tonic-gate 14400Sstevel@tonic-gate if ((dd = metaget_drivedesc(sp, (MD_BASICNAME_OK | PRINT_FAST), 14410Sstevel@tonic-gate ep)) == NULL) { 14420Sstevel@tonic-gate if (! mdisdserror(ep, MDE_DS_HOSTNOSIDE)) { 14430Sstevel@tonic-gate metaflushsetname(sp); 14440Sstevel@tonic-gate if (! mdisok(ep)) { 14450Sstevel@tonic-gate free_sr(sr); 14460Sstevel@tonic-gate return; 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate /* we are supposed to have drives!!!! */ 14490Sstevel@tonic-gate assert(0); 14500Sstevel@tonic-gate } 14510Sstevel@tonic-gate rb_mode = 1; 14520Sstevel@tonic-gate mdclrerror(ep); 14530Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 14540Sstevel@tonic-gate /* Skip empty sides of the diskset */ 14550Sstevel@tonic-gate if (sr->sr_nodes[i][0] == '\0') 14560Sstevel@tonic-gate continue; 14570Sstevel@tonic-gate dd = metaget_drivedesc_sideno(sp, i, 14580Sstevel@tonic-gate (MD_BASICNAME_OK | PRINT_FAST), ep); 14590Sstevel@tonic-gate /* Got dd, get out of loop */ 14600Sstevel@tonic-gate if (dd != NULL) 14610Sstevel@tonic-gate break; 14620Sstevel@tonic-gate 14630Sstevel@tonic-gate /* some error occurred, get out of loop */ 14640Sstevel@tonic-gate if (! mdisok(ep)) 14650Sstevel@tonic-gate break; 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate /* 14680Sstevel@tonic-gate * At this point, we have one of three possibilities: 14690Sstevel@tonic-gate * 1) dd != NULL (we have found drives using an alternate 14700Sstevel@tonic-gate * side.) 14710Sstevel@tonic-gate * 2) dd == NULL (no drives) && mdisok(ep) : assert(0) 14720Sstevel@tonic-gate * 3) dd == NULL (no drives) && ! mdisok(ep) : return 14730Sstevel@tonic-gate * error information to caller. 14740Sstevel@tonic-gate */ 14750Sstevel@tonic-gate if (dd == NULL) { 14760Sstevel@tonic-gate metaflushsetname(sp); 14770Sstevel@tonic-gate if (! mdisok(ep)) { 14780Sstevel@tonic-gate free_sr(sr); 14790Sstevel@tonic-gate return; 14800Sstevel@tonic-gate } 14810Sstevel@tonic-gate /* we are supposed to have drives!!!! */ 14820Sstevel@tonic-gate assert(0); 14830Sstevel@tonic-gate } 14840Sstevel@tonic-gate } 14850Sstevel@tonic-gate 14860Sstevel@tonic-gate /* 14870Sstevel@tonic-gate * Let's run through each drive descriptor, and delete the 14880Sstevel@tonic-gate * sidename for all sides that are not in the sr_nodes array. 14890Sstevel@tonic-gate * We will ignore errors, cause the empty side may not 14900Sstevel@tonic-gate * have had any names to begin with. 14910Sstevel@tonic-gate */ 14920Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 14930Sstevel@tonic-gate dn = p->dd_dnp; 14940Sstevel@tonic-gate 14950Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 14960Sstevel@tonic-gate /* Skip existing sides of the diskset */ 14970Sstevel@tonic-gate if (!rb_mode && sr->sr_nodes[i][0] != '\0') 14980Sstevel@tonic-gate continue; 14990Sstevel@tonic-gate /* An empty side, delete the sidename */ 15000Sstevel@tonic-gate if (del_name(local_sp, i+SKEW, 15010Sstevel@tonic-gate dn->side_names_key, ep)) { 15020Sstevel@tonic-gate if (!mdissyserror(ep, ENOENT)) { 15030Sstevel@tonic-gate free_sr(sr); 15040Sstevel@tonic-gate return; 15050Sstevel@tonic-gate } 15060Sstevel@tonic-gate mdclrerror(ep); 15070Sstevel@tonic-gate } 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate } 15100Sstevel@tonic-gate free_sr(sr); 15110Sstevel@tonic-gate metaflushsetname(sp); 15120Sstevel@tonic-gate } 15130Sstevel@tonic-gate 15140Sstevel@tonic-gate /* 15150Sstevel@tonic-gate * delete 1 or more sidenames per drive desc, from the local namespace 15160Sstevel@tonic-gate */ 15170Sstevel@tonic-gate bool_t 15180Sstevel@tonic-gate mdrpc_del_drv_sidenms_common( 15190Sstevel@tonic-gate mdrpc_sp_args *args, 15200Sstevel@tonic-gate mdrpc_generic_res *res, 15210Sstevel@tonic-gate struct svc_req *rqstp, /* RPC stuff */ 15220Sstevel@tonic-gate int version /* RPC version */ 15230Sstevel@tonic-gate ) 15240Sstevel@tonic-gate { 15250Sstevel@tonic-gate md_error_t *ep = &res->status; 15260Sstevel@tonic-gate int err; 15270Sstevel@tonic-gate int op_mode = W_OK; 15280Sstevel@tonic-gate 15290Sstevel@tonic-gate /* setup, check permissions */ 15300Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 15310Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 15320Sstevel@tonic-gate return (FALSE); 15330Sstevel@tonic-gate else if (err != 0) 15340Sstevel@tonic-gate return (TRUE); 15350Sstevel@tonic-gate 15360Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 15370Sstevel@tonic-gate return (TRUE); 15380Sstevel@tonic-gate 15390Sstevel@tonic-gate /* doit */ 15400Sstevel@tonic-gate del_drv_sidenms(args->sp, version, ep); 15410Sstevel@tonic-gate 15420Sstevel@tonic-gate err = svc_fini(ep); 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate return (TRUE); 15450Sstevel@tonic-gate } 15460Sstevel@tonic-gate 15470Sstevel@tonic-gate bool_t 15480Sstevel@tonic-gate mdrpc_del_drv_sidenms_1_svc( 15490Sstevel@tonic-gate mdrpc_sp_args *args, 15500Sstevel@tonic-gate mdrpc_generic_res *res, 15510Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 15520Sstevel@tonic-gate ) 15530Sstevel@tonic-gate { 15540Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION) to common routine */ 15550Sstevel@tonic-gate return (mdrpc_del_drv_sidenms_common(args, res, rqstp, METAD_VERSION)); 15560Sstevel@tonic-gate } 15570Sstevel@tonic-gate 15580Sstevel@tonic-gate bool_t 15590Sstevel@tonic-gate mdrpc_del_drv_sidenms_2_svc( 15600Sstevel@tonic-gate mdrpc_sp_2_args *args, 15610Sstevel@tonic-gate mdrpc_generic_res *res, 15620Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 15630Sstevel@tonic-gate ) 15640Sstevel@tonic-gate { 15650Sstevel@tonic-gate switch (args->rev) { 15660Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 15670Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION_DEVID) to common routine */ 15680Sstevel@tonic-gate return (mdrpc_del_drv_sidenms_common( 15690Sstevel@tonic-gate &args->mdrpc_sp_2_args_u.rev1, res, 15700Sstevel@tonic-gate rqstp, METAD_VERSION_DEVID)); 15710Sstevel@tonic-gate default: 15720Sstevel@tonic-gate return (FALSE); 15730Sstevel@tonic-gate } 15740Sstevel@tonic-gate } 15750Sstevel@tonic-gate 15760Sstevel@tonic-gate static int 15770Sstevel@tonic-gate del_sidenamelist( 15780Sstevel@tonic-gate md_set_record *sr, 15790Sstevel@tonic-gate mddrivename_t *dn, 15800Sstevel@tonic-gate md_error_t *ep 15810Sstevel@tonic-gate ) 15820Sstevel@tonic-gate { 15830Sstevel@tonic-gate mdsidenames_t *sn; 15840Sstevel@tonic-gate mdsetname_t *local_sp; 15850Sstevel@tonic-gate md_mnset_record *mnsr; 15860Sstevel@tonic-gate md_mnnode_record *nr; 15870Sstevel@tonic-gate 15880Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) 15890Sstevel@tonic-gate return (-1); 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate for (sn = dn->side_names; sn != NULL; sn = sn->next) 15920Sstevel@tonic-gate if (MD_MNSET_REC(sr)) { 15930Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 15940Sstevel@tonic-gate /* 15950Sstevel@tonic-gate * Only delete side name entries for this node 15960Sstevel@tonic-gate * on a multi-node diskset. 15970Sstevel@tonic-gate */ 15980Sstevel@tonic-gate nr = mnsr->sr_nodechain; 15990Sstevel@tonic-gate while (nr) { 16000Sstevel@tonic-gate if (nr->nr_nodeid == sn->sideno) { 16010Sstevel@tonic-gate if (del_name(local_sp, sn->sideno, 16020Sstevel@tonic-gate dn->side_names_key, ep) == -1) 16030Sstevel@tonic-gate mdclrerror(ep); /* ignore err */ 16040Sstevel@tonic-gate break; 16050Sstevel@tonic-gate } 16060Sstevel@tonic-gate nr = nr->nr_next; 16070Sstevel@tonic-gate } 16080Sstevel@tonic-gate } else { 16090Sstevel@tonic-gate if (del_name(local_sp, sn->sideno+SKEW, 16100Sstevel@tonic-gate dn->side_names_key, ep) == -1) 16110Sstevel@tonic-gate mdclrerror(ep); /* ignore errors */ 16120Sstevel@tonic-gate } 16130Sstevel@tonic-gate 16140Sstevel@tonic-gate dn->side_names_key = MD_KEYBAD; 16150Sstevel@tonic-gate return (0); 16160Sstevel@tonic-gate } 16170Sstevel@tonic-gate 16180Sstevel@tonic-gate static void 16190Sstevel@tonic-gate deldrvs( 16200Sstevel@tonic-gate char *setname, 16210Sstevel@tonic-gate md_drive_desc *dd, 16220Sstevel@tonic-gate md_error_t *ep 16230Sstevel@tonic-gate ) 16240Sstevel@tonic-gate { 16250Sstevel@tonic-gate mdsetname_t *sp; 16260Sstevel@tonic-gate md_set_record *sr; 16270Sstevel@tonic-gate md_drive_record *dr; 16280Sstevel@tonic-gate mddb_userreq_t req; 16290Sstevel@tonic-gate md_drive_desc *p; 16300Sstevel@tonic-gate mddrivename_t *dn, *dn1; 16310Sstevel@tonic-gate side_t sideno; 16320Sstevel@tonic-gate int i; 16330Sstevel@tonic-gate int rb_mode = 0; 16340Sstevel@tonic-gate mdname_t *np; 16350Sstevel@tonic-gate md_dev64_t dev; 16360Sstevel@tonic-gate md_error_t xep = mdnullerror; 16370Sstevel@tonic-gate ddi_devid_t devid_remote = NULL; 16380Sstevel@tonic-gate ddi_devid_t devid_local = NULL; 16390Sstevel@tonic-gate int devid_same = -1; 16400Sstevel@tonic-gate int using_devid = 0; 16410Sstevel@tonic-gate md_mnnode_record *nr; 16420Sstevel@tonic-gate md_mnset_record *mnsr; 16430Sstevel@tonic-gate 16440Sstevel@tonic-gate if ((sp = metasetname(setname, ep)) == NULL) 16450Sstevel@tonic-gate return; 16460Sstevel@tonic-gate 16470Sstevel@tonic-gate metaflushsetname(sp); 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate if ((sideno = getmyside(sp, ep)) == MD_SIDEWILD) { 16500Sstevel@tonic-gate if (! mdisdserror(ep, MDE_DS_HOSTNOSIDE)) 16510Sstevel@tonic-gate return; 16520Sstevel@tonic-gate mdclrerror(ep); 16530Sstevel@tonic-gate /* 16540Sstevel@tonic-gate * The set record is incomplete, so we need to make note 16550Sstevel@tonic-gate * here so that we can do some special handling later. 16560Sstevel@tonic-gate */ 16570Sstevel@tonic-gate rb_mode = 1; 16580Sstevel@tonic-gate } 16590Sstevel@tonic-gate 16600Sstevel@tonic-gate if ((sr = getsetbyname(setname, ep)) == NULL) 16610Sstevel@tonic-gate return; 16620Sstevel@tonic-gate 16630Sstevel@tonic-gate if (dd->dd_dnp == NULL) 16640Sstevel@tonic-gate return; 16650Sstevel@tonic-gate 16660Sstevel@tonic-gate /* 16670Sstevel@tonic-gate * The system is either all devid or all 16680Sstevel@tonic-gate * non-devid so we determine this by looking 16690Sstevel@tonic-gate * at the first item in the list. 16700Sstevel@tonic-gate * 16710Sstevel@tonic-gate * For did disks, the dd_dnp->devid is a valid pointer which 16720Sstevel@tonic-gate * points to a '' string of devid. We need to check this 16730Sstevel@tonic-gate * before set the using_devid. 16740Sstevel@tonic-gate */ 16750Sstevel@tonic-gate if ((dd->dd_dnp->devid != NULL) && (dd->dd_dnp->devid[0] != '\0') && 16760Sstevel@tonic-gate (!(MD_MNSET_REC(sr)))) 16770Sstevel@tonic-gate using_devid = 1; 16780Sstevel@tonic-gate 16790Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 16800Sstevel@tonic-gate dn = p->dd_dnp; 16810Sstevel@tonic-gate devid_remote = NULL; 16820Sstevel@tonic-gate 16830Sstevel@tonic-gate if (dn->devid != NULL && (strlen(dn->devid) != 0) && 16840Sstevel@tonic-gate using_devid) { 16850Sstevel@tonic-gate /* 16860Sstevel@tonic-gate * We have a devid so use it 16870Sstevel@tonic-gate */ 16880Sstevel@tonic-gate (void) devid_str_decode(dn->devid, &devid_remote, NULL); 16890Sstevel@tonic-gate } 16900Sstevel@tonic-gate 16910Sstevel@tonic-gate /* check to make sure using_devid agrees with reality... */ 16920Sstevel@tonic-gate if ((using_devid == 1) && (devid_remote == NULL)) { 16930Sstevel@tonic-gate /* something went really wrong. Can't process */ 16940Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_INVALIDDEVID, sp->setno, 16950Sstevel@tonic-gate mynode(), dn->cname, sp->setname); 16960Sstevel@tonic-gate return; 16970Sstevel@tonic-gate } 16980Sstevel@tonic-gate 16990Sstevel@tonic-gate for (dr = sr->sr_drivechain; dr; dr = dr->dr_next) { 17000Sstevel@tonic-gate devid_same = -1; 17010Sstevel@tonic-gate 17020Sstevel@tonic-gate if (! rb_mode) { 17030Sstevel@tonic-gate dn1 = metadrivename_withdrkey(sp, sideno, 17040Sstevel@tonic-gate dr->dr_key, MD_BASICNAME_OK, ep); 17050Sstevel@tonic-gate if (dn1 == NULL) { 17060Sstevel@tonic-gate free_sr(sr); 17070Sstevel@tonic-gate if (devid_remote) 17080Sstevel@tonic-gate devid_free(devid_remote); 17090Sstevel@tonic-gate return; 17100Sstevel@tonic-gate } 17110Sstevel@tonic-gate } else { 17120Sstevel@tonic-gate /* 17130Sstevel@tonic-gate * Handle special case here where sidenames 17140Sstevel@tonic-gate * from other hosts for this drive may be 17150Sstevel@tonic-gate * in the local mddb, but there is no 17160Sstevel@tonic-gate * sidename entry for this host for this drive. 17170Sstevel@tonic-gate * This could have happened if the node 17180Sstevel@tonic-gate * panic'd between the 2 operations when 17190Sstevel@tonic-gate * adding this node to the set. 17200Sstevel@tonic-gate * So, delete all sidename entries for this 17210Sstevel@tonic-gate * drive. 17220Sstevel@tonic-gate */ 17230Sstevel@tonic-gate if (MD_MNSET_REC(sr)) { 17240Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 17250Sstevel@tonic-gate nr = mnsr->sr_nodechain; 17260Sstevel@tonic-gate while (nr) { 17270Sstevel@tonic-gate /* We delete all dr sides */ 17280Sstevel@tonic-gate dn1 = metadrivename_withdrkey( 17290Sstevel@tonic-gate sp, nr->nr_nodeid, 17300Sstevel@tonic-gate dr->dr_key, 17310Sstevel@tonic-gate MD_BASICNAME_OK, ep); 17320Sstevel@tonic-gate 17330Sstevel@tonic-gate /* if we do, get out of loop */ 17340Sstevel@tonic-gate if (dn1 != NULL) 17350Sstevel@tonic-gate break; 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate /* save error for later */ 17380Sstevel@tonic-gate (void) mdstealerror(&xep, ep); 17390Sstevel@tonic-gate 17400Sstevel@tonic-gate mdclrerror(ep); 17410Sstevel@tonic-gate 17420Sstevel@tonic-gate nr = nr->nr_next; 17430Sstevel@tonic-gate } 17440Sstevel@tonic-gate } else { 17450Sstevel@tonic-gate /* 17460Sstevel@tonic-gate * Handle special case here 17470Sstevel@tonic-gate * for traditional diskset 17480Sstevel@tonic-gate */ 17490Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 17500Sstevel@tonic-gate /* We delete all dr sides */ 17510Sstevel@tonic-gate dn1 = metadrivename_withdrkey( 17520Sstevel@tonic-gate sp, i, dr->dr_key, 17530Sstevel@tonic-gate MD_BASICNAME_OK, ep); 17540Sstevel@tonic-gate 17550Sstevel@tonic-gate /* if we do, get out of loop */ 17560Sstevel@tonic-gate if (dn1 != NULL) 17570Sstevel@tonic-gate break; 17580Sstevel@tonic-gate 17590Sstevel@tonic-gate /* save error for later */ 17600Sstevel@tonic-gate (void) mdstealerror(&xep, ep); 17610Sstevel@tonic-gate 17620Sstevel@tonic-gate mdclrerror(ep); 17630Sstevel@tonic-gate } 17640Sstevel@tonic-gate } 17650Sstevel@tonic-gate 17660Sstevel@tonic-gate if (dn1 == NULL) { 17670Sstevel@tonic-gate (void) mdstealerror(ep, &xep); 17680Sstevel@tonic-gate free_sr(sr); 17690Sstevel@tonic-gate if (devid_remote) 17700Sstevel@tonic-gate devid_free(devid_remote); 17710Sstevel@tonic-gate return; 17720Sstevel@tonic-gate } 17730Sstevel@tonic-gate 17740Sstevel@tonic-gate if (!using_devid) 17750Sstevel@tonic-gate mdclrerror(ep); 17760Sstevel@tonic-gate } 17770Sstevel@tonic-gate 17780Sstevel@tonic-gate if (dn1->devid != NULL && using_devid) { 17790Sstevel@tonic-gate if (devid_str_decode(dn1->devid, &devid_local, 17800Sstevel@tonic-gate NULL) == 0) { 17810Sstevel@tonic-gate devid_same = devid_compare(devid_remote, 17820Sstevel@tonic-gate devid_local); 17830Sstevel@tonic-gate devid_free(devid_local); 17840Sstevel@tonic-gate } 17850Sstevel@tonic-gate } 17860Sstevel@tonic-gate 17870Sstevel@tonic-gate /* 17880Sstevel@tonic-gate * Has the required disk been found - either the devids 17890Sstevel@tonic-gate * match if devid are being used or the actual name of 17900Sstevel@tonic-gate * the disk matches. 17910Sstevel@tonic-gate */ 17920Sstevel@tonic-gate if ((using_devid && devid_same == 0) || 17930Sstevel@tonic-gate (!using_devid && 17940Sstevel@tonic-gate strcmp(dn->cname, dn1->cname) == 0)) { 17950Sstevel@tonic-gate uint_t rep_slice; 17960Sstevel@tonic-gate 17970Sstevel@tonic-gate dev = NODEV64; 17980Sstevel@tonic-gate np = NULL; 17990Sstevel@tonic-gate if (meta_replicaslice(dn1, 18000Sstevel@tonic-gate &rep_slice, &xep) == 0) { 18010Sstevel@tonic-gate np = metaslicename(dn1, 18020Sstevel@tonic-gate rep_slice, &xep); 18030Sstevel@tonic-gate } 18040Sstevel@tonic-gate 18050Sstevel@tonic-gate if (np != NULL) 18060Sstevel@tonic-gate dev = np->dev; 18070Sstevel@tonic-gate else 18080Sstevel@tonic-gate mdclrerror(&xep); 18090Sstevel@tonic-gate break; 18100Sstevel@tonic-gate } 18110Sstevel@tonic-gate } 18120Sstevel@tonic-gate 18130Sstevel@tonic-gate if (dr) { 18140Sstevel@tonic-gate (void) memset(&req, 0, sizeof (req)); 18150Sstevel@tonic-gate METAD_SETUP_DR(MD_DB_DELETE, dr->dr_selfid) 18160Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) 18170Sstevel@tonic-gate != 0) { 18180Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 18190Sstevel@tonic-gate if (devid_remote) 18200Sstevel@tonic-gate devid_free(devid_remote); 18210Sstevel@tonic-gate free_sr(sr); 18220Sstevel@tonic-gate return; 18230Sstevel@tonic-gate } 18240Sstevel@tonic-gate 18250Sstevel@tonic-gate dr_cache_del(sr, dr->dr_selfid); 18260Sstevel@tonic-gate 18270Sstevel@tonic-gate if (del_sidenamelist(sr, dn1, ep) == -1) { 18280Sstevel@tonic-gate goto out; 18290Sstevel@tonic-gate } 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_REMOVE, SVM_TAG_DRIVE, 18320Sstevel@tonic-gate sr->sr_setno, dev); 18330Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_ADD, SVM_TAG_DRIVE, 18340Sstevel@tonic-gate MD_LOCAL_SET, dev); 18350Sstevel@tonic-gate 18360Sstevel@tonic-gate continue; 18370Sstevel@tonic-gate } 18380Sstevel@tonic-gate 18390Sstevel@tonic-gate if (devid_remote) 18400Sstevel@tonic-gate devid_free(devid_remote); 18410Sstevel@tonic-gate } 18420Sstevel@tonic-gate 18430Sstevel@tonic-gate out: 18440Sstevel@tonic-gate commitset(sr, TRUE, ep); 18450Sstevel@tonic-gate 18460Sstevel@tonic-gate free_sr(sr); 18470Sstevel@tonic-gate } 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate /* 18500Sstevel@tonic-gate * delete 1 or more drive records from a host. 18510Sstevel@tonic-gate */ 18520Sstevel@tonic-gate bool_t 18530Sstevel@tonic-gate mdrpc_deldrvs_common( 18540Sstevel@tonic-gate mdrpc_drives_2_args_r1 *args, 18550Sstevel@tonic-gate mdrpc_generic_res *res, 18560Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 18570Sstevel@tonic-gate ) 18580Sstevel@tonic-gate { 18590Sstevel@tonic-gate md_error_t *ep = &res->status; 18600Sstevel@tonic-gate int err; 18610Sstevel@tonic-gate int op_mode = W_OK; 18620Sstevel@tonic-gate 18630Sstevel@tonic-gate /* setup, check permissions */ 18640Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 18650Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 18660Sstevel@tonic-gate return (FALSE); 18670Sstevel@tonic-gate else if (err != 0) 18680Sstevel@tonic-gate return (TRUE); 18690Sstevel@tonic-gate 18700Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 18710Sstevel@tonic-gate return (TRUE); 18720Sstevel@tonic-gate 18730Sstevel@tonic-gate /* doit */ 18740Sstevel@tonic-gate deldrvs(args->sp->setname, args->drivedescs, ep); 18750Sstevel@tonic-gate 18760Sstevel@tonic-gate err = svc_fini(ep); 18770Sstevel@tonic-gate 18780Sstevel@tonic-gate return (TRUE); 18790Sstevel@tonic-gate } 18800Sstevel@tonic-gate 18810Sstevel@tonic-gate /* 18820Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 18830Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 18840Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 18850Sstevel@tonic-gate */ 18860Sstevel@tonic-gate bool_t 18870Sstevel@tonic-gate mdrpc_deldrvs_1_svc( 18880Sstevel@tonic-gate mdrpc_drives_args *args, 18890Sstevel@tonic-gate mdrpc_generic_res *res, 18900Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 18910Sstevel@tonic-gate ) 18920Sstevel@tonic-gate { 18930Sstevel@tonic-gate bool_t retval; 18940Sstevel@tonic-gate mdrpc_drives_2_args_r1 v2_args; 18950Sstevel@tonic-gate 18960Sstevel@tonic-gate /* allocate memory */ 18970Sstevel@tonic-gate alloc_newdrvdesc(args->drivedescs, &v2_args.drivedescs); 18980Sstevel@tonic-gate 18990Sstevel@tonic-gate /* build args */ 19000Sstevel@tonic-gate v2_args.cl_sk = args->cl_sk; 19010Sstevel@tonic-gate v2_args.sp = args->sp; 19020Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 19030Sstevel@tonic-gate meta_conv_drvdesc_old2new(args->drivedescs, v2_args.drivedescs); 19040Sstevel@tonic-gate v2_args.timestamp = args->timestamp; 19050Sstevel@tonic-gate v2_args.genid = args->genid; 19060Sstevel@tonic-gate 19070Sstevel@tonic-gate retval = mdrpc_deldrvs_common(&v2_args, res, rqstp); 19080Sstevel@tonic-gate 19090Sstevel@tonic-gate free_newdrvdesc(v2_args.drivedescs); 19100Sstevel@tonic-gate 19110Sstevel@tonic-gate return (retval); 19120Sstevel@tonic-gate } 19130Sstevel@tonic-gate 19140Sstevel@tonic-gate bool_t 19150Sstevel@tonic-gate mdrpc_deldrvs_2_svc( 19160Sstevel@tonic-gate mdrpc_drives_2_args *args, 19170Sstevel@tonic-gate mdrpc_generic_res *res, 19180Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 19190Sstevel@tonic-gate ) 19200Sstevel@tonic-gate { 19210Sstevel@tonic-gate switch (args->rev) { 19220Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 19230Sstevel@tonic-gate return (mdrpc_deldrvs_common( 19240Sstevel@tonic-gate &args->mdrpc_drives_2_args_u.rev1, res, rqstp)); 19250Sstevel@tonic-gate default: 19260Sstevel@tonic-gate return (FALSE); 19270Sstevel@tonic-gate } 19280Sstevel@tonic-gate } 19290Sstevel@tonic-gate 19300Sstevel@tonic-gate static void 19310Sstevel@tonic-gate delhosts( 19320Sstevel@tonic-gate char *setname, 19330Sstevel@tonic-gate int node_c, 19340Sstevel@tonic-gate char **node_v, 19350Sstevel@tonic-gate int version, /* RPC version of calling routine */ 19360Sstevel@tonic-gate md_error_t *ep 19370Sstevel@tonic-gate ) 19380Sstevel@tonic-gate { 19390Sstevel@tonic-gate mddb_userreq_t req; 19400Sstevel@tonic-gate md_set_record *sr; 19410Sstevel@tonic-gate int i, j; 19420Sstevel@tonic-gate md_mnset_record *mnsr; 19430Sstevel@tonic-gate md_mnnode_record *nr; 19440Sstevel@tonic-gate 19450Sstevel@tonic-gate if ((sr = getsetbyname(setname, ep)) == NULL) 19460Sstevel@tonic-gate return; 19470Sstevel@tonic-gate 19480Sstevel@tonic-gate for (i = 0; i < node_c; i++) { 19490Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 19500Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 19510Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 19520Sstevel@tonic-gate nr = mnsr->sr_nodechain; 19530Sstevel@tonic-gate while (nr) { 19540Sstevel@tonic-gate if (strcmp(nr->nr_nodename, node_v[i]) == 0) { 19550Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, 19560Sstevel@tonic-gate ESC_SVM_REMOVE, SVM_TAG_HOST, 19570Sstevel@tonic-gate sr->sr_setno, nr->nr_nodeid); 19580Sstevel@tonic-gate (void) memset(&req, '\0', sizeof (req)); 19590Sstevel@tonic-gate METAD_SETUP_NR(MD_DB_DELETE, 19600Sstevel@tonic-gate nr->nr_selfid); 19610Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, 19620Sstevel@tonic-gate &req.ur_mde, NULL) != 0) { 19630Sstevel@tonic-gate (void) mdstealerror(ep, 19640Sstevel@tonic-gate &req.ur_mde); 19650Sstevel@tonic-gate free_sr(sr); 19660Sstevel@tonic-gate return; 19670Sstevel@tonic-gate } 19680Sstevel@tonic-gate mnnr_cache_del(mnsr, nr->nr_selfid); 19690Sstevel@tonic-gate break; 19700Sstevel@tonic-gate } 19710Sstevel@tonic-gate nr = nr->nr_next; 19720Sstevel@tonic-gate } 19730Sstevel@tonic-gate } else { 19740Sstevel@tonic-gate for (j = 0; j < MD_MAXSIDES; j++) { 19750Sstevel@tonic-gate if (sr->sr_nodes[j][0] == '\0') 19760Sstevel@tonic-gate continue; 19770Sstevel@tonic-gate if (strcmp(sr->sr_nodes[j], node_v[i]) != 0) 19780Sstevel@tonic-gate continue; 19790Sstevel@tonic-gate (void) memset(sr->sr_nodes[j], '\0', 19800Sstevel@tonic-gate sizeof (sr->sr_nodes[j])); 19810Sstevel@tonic-gate SE_NOTIFY(EC_SVM_CONFIG, ESC_SVM_REMOVE, 19820Sstevel@tonic-gate SVM_TAG_HOST, sr->sr_setno, j); 19830Sstevel@tonic-gate break; 19840Sstevel@tonic-gate } 19850Sstevel@tonic-gate } 19860Sstevel@tonic-gate } 19870Sstevel@tonic-gate 19880Sstevel@tonic-gate (void) memset(&req, '\0', sizeof (req)); 19890Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_SETDATA, sr->sr_selfid) 19900Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 19910Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 19920Sstevel@tonic-gate req.ur_size = sizeof (*mnsr); 19930Sstevel@tonic-gate } else { 19940Sstevel@tonic-gate req.ur_size = sizeof (*sr); 19950Sstevel@tonic-gate } 19960Sstevel@tonic-gate req.ur_data = (uintptr_t)sr; 19970Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 19980Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 19990Sstevel@tonic-gate free_sr(sr); 20000Sstevel@tonic-gate return; 20010Sstevel@tonic-gate } 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate commitset(sr, TRUE, ep); 20040Sstevel@tonic-gate free_sr(sr); 20050Sstevel@tonic-gate } 20060Sstevel@tonic-gate 20070Sstevel@tonic-gate /* 20080Sstevel@tonic-gate * delete 1 or more a hosts from a set. 20090Sstevel@tonic-gate */ 20100Sstevel@tonic-gate bool_t 20110Sstevel@tonic-gate mdrpc_delhosts_common( 20120Sstevel@tonic-gate mdrpc_host_args *args, 20130Sstevel@tonic-gate mdrpc_generic_res *res, 20140Sstevel@tonic-gate struct svc_req *rqstp, /* RPC stuff */ 20150Sstevel@tonic-gate int version /* RPC version */ 20160Sstevel@tonic-gate ) 20170Sstevel@tonic-gate { 20180Sstevel@tonic-gate md_error_t *ep = &res->status; 20190Sstevel@tonic-gate int err; 20200Sstevel@tonic-gate int op_mode = W_OK; 20210Sstevel@tonic-gate 20220Sstevel@tonic-gate /* setup, check permissions */ 20230Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 20240Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 20250Sstevel@tonic-gate return (FALSE); 20260Sstevel@tonic-gate else if (err != 0) 20270Sstevel@tonic-gate return (TRUE); 20280Sstevel@tonic-gate 20290Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 20300Sstevel@tonic-gate return (TRUE); 20310Sstevel@tonic-gate 20320Sstevel@tonic-gate /* doit */ 20330Sstevel@tonic-gate delhosts(args->sp->setname, args->hosts.hosts_len, 20340Sstevel@tonic-gate args->hosts.hosts_val, version, ep); 20350Sstevel@tonic-gate 20360Sstevel@tonic-gate err = svc_fini(ep); 20370Sstevel@tonic-gate 20380Sstevel@tonic-gate return (TRUE); 20390Sstevel@tonic-gate } 20400Sstevel@tonic-gate 20410Sstevel@tonic-gate bool_t 20420Sstevel@tonic-gate mdrpc_delhosts_1_svc( 20430Sstevel@tonic-gate mdrpc_host_args *args, 20440Sstevel@tonic-gate mdrpc_generic_res *res, 20450Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 20460Sstevel@tonic-gate ) 20470Sstevel@tonic-gate { 20480Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION) to common routine */ 20490Sstevel@tonic-gate return (mdrpc_delhosts_common(args, res, rqstp, METAD_VERSION)); 20500Sstevel@tonic-gate } 20510Sstevel@tonic-gate 20520Sstevel@tonic-gate bool_t 20530Sstevel@tonic-gate mdrpc_delhosts_2_svc( 20540Sstevel@tonic-gate mdrpc_host_2_args *args, 20550Sstevel@tonic-gate mdrpc_generic_res *res, 20560Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 20570Sstevel@tonic-gate ) 20580Sstevel@tonic-gate { 20590Sstevel@tonic-gate switch (args->rev) { 20600Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 20610Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION_DEVID) to common routine */ 20620Sstevel@tonic-gate return (mdrpc_delhosts_common( 20630Sstevel@tonic-gate &args->mdrpc_host_2_args_u.rev1, res, 20640Sstevel@tonic-gate rqstp, METAD_VERSION_DEVID)); 20650Sstevel@tonic-gate default: 20660Sstevel@tonic-gate return (FALSE); 20670Sstevel@tonic-gate } 20680Sstevel@tonic-gate } 20690Sstevel@tonic-gate 20700Sstevel@tonic-gate /* 20710Sstevel@tonic-gate * delete a set. 20720Sstevel@tonic-gate */ 20730Sstevel@tonic-gate bool_t 20740Sstevel@tonic-gate mdrpc_delset_common( 20750Sstevel@tonic-gate mdrpc_sp_args *args, 20760Sstevel@tonic-gate mdrpc_generic_res *res, 20770Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 20780Sstevel@tonic-gate ) 20790Sstevel@tonic-gate { 20800Sstevel@tonic-gate md_error_t *ep = &res->status; 20810Sstevel@tonic-gate int err; 20820Sstevel@tonic-gate int op_mode = W_OK; 20830Sstevel@tonic-gate 20840Sstevel@tonic-gate /* setup, check permissions */ 20850Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 20860Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 20870Sstevel@tonic-gate return (FALSE); 20880Sstevel@tonic-gate else if (err != 0) 20890Sstevel@tonic-gate return (TRUE); 20900Sstevel@tonic-gate 20910Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 20920Sstevel@tonic-gate return (TRUE); 20930Sstevel@tonic-gate 20940Sstevel@tonic-gate /* doit */ 20950Sstevel@tonic-gate s_delset(args->sp->setname, ep); 20960Sstevel@tonic-gate 20970Sstevel@tonic-gate err = svc_fini(ep); 20980Sstevel@tonic-gate 20990Sstevel@tonic-gate return (TRUE); 21000Sstevel@tonic-gate } 21010Sstevel@tonic-gate 21020Sstevel@tonic-gate bool_t 21030Sstevel@tonic-gate mdrpc_delset_1_svc( 21040Sstevel@tonic-gate mdrpc_sp_args *args, 21050Sstevel@tonic-gate mdrpc_generic_res *res, 21060Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 21070Sstevel@tonic-gate ) 21080Sstevel@tonic-gate { 21090Sstevel@tonic-gate return (mdrpc_delset_common(args, res, rqstp)); 21100Sstevel@tonic-gate } 21110Sstevel@tonic-gate 21120Sstevel@tonic-gate bool_t 21130Sstevel@tonic-gate mdrpc_delset_2_svc( 21140Sstevel@tonic-gate mdrpc_sp_2_args *args, 21150Sstevel@tonic-gate mdrpc_generic_res *res, 21160Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 21170Sstevel@tonic-gate ) 21180Sstevel@tonic-gate { 21190Sstevel@tonic-gate switch (args->rev) { 21200Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 21210Sstevel@tonic-gate return (mdrpc_delset_common( 21220Sstevel@tonic-gate &args->mdrpc_sp_2_args_u.rev1, res, rqstp)); 21230Sstevel@tonic-gate default: 21240Sstevel@tonic-gate return (FALSE); 21250Sstevel@tonic-gate } 21260Sstevel@tonic-gate } 21270Sstevel@tonic-gate 21280Sstevel@tonic-gate /* 21290Sstevel@tonic-gate * return device info 21300Sstevel@tonic-gate */ 21310Sstevel@tonic-gate static void 21320Sstevel@tonic-gate devinfo( 21330Sstevel@tonic-gate mdsetname_t *sp, 21340Sstevel@tonic-gate mddrivename_t *dp, 21350Sstevel@tonic-gate mdrpc_devinfo_2_res *res, 21360Sstevel@tonic-gate md_error_t *ep 21370Sstevel@tonic-gate ) 21380Sstevel@tonic-gate { 21390Sstevel@tonic-gate mdname_t *np, *real_np; 21400Sstevel@tonic-gate 21410Sstevel@tonic-gate if ((np = metaslicename(dp, MD_SLICE0, ep)) == NULL) 21420Sstevel@tonic-gate return; 21430Sstevel@tonic-gate 21440Sstevel@tonic-gate if ((real_np = metaname(&sp, np->bname, ep)) == NULL) 21450Sstevel@tonic-gate return; 21460Sstevel@tonic-gate 21470Sstevel@tonic-gate res->dev = real_np->dev; 21480Sstevel@tonic-gate (void) getdevstamp(dp, (long *)&res->vtime, ep); 21490Sstevel@tonic-gate res->enc_devid = meta_get_devid(np->rname); 21500Sstevel@tonic-gate } 21510Sstevel@tonic-gate 21520Sstevel@tonic-gate bool_t 21530Sstevel@tonic-gate mdrpc_devinfo_common( 21540Sstevel@tonic-gate mdrpc_devinfo_2_args_r1 *args, 21550Sstevel@tonic-gate mdrpc_devinfo_2_res *res, 21560Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 21570Sstevel@tonic-gate ) 21580Sstevel@tonic-gate { 21590Sstevel@tonic-gate int slice; 21600Sstevel@tonic-gate mdname_t *np; 21610Sstevel@tonic-gate mddrivename_t *dnp = args->drivenamep; 21620Sstevel@tonic-gate md_error_t *ep = &res->status; 21630Sstevel@tonic-gate int err; 21640Sstevel@tonic-gate int op_mode = R_OK; 21650Sstevel@tonic-gate 21660Sstevel@tonic-gate /* setup, check permissions */ 21670Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 21680Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 21690Sstevel@tonic-gate return (FALSE); 21700Sstevel@tonic-gate else if (err != 0) 21710Sstevel@tonic-gate return (TRUE); 21720Sstevel@tonic-gate 21730Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 21740Sstevel@tonic-gate return (TRUE); 21750Sstevel@tonic-gate 21760Sstevel@tonic-gate /* 21770Sstevel@tonic-gate * fix all the drivenamep's in the mdname_t's to 21780Sstevel@tonic-gate * point to the right place. 21790Sstevel@tonic-gate */ 21800Sstevel@tonic-gate for (slice = 0; (slice < dnp->parts.parts_len); ++slice) { 21810Sstevel@tonic-gate if ((np = metaslicename(dnp, slice, ep)) == NULL) 21820Sstevel@tonic-gate return (TRUE); 21830Sstevel@tonic-gate np->drivenamep = dnp; 21840Sstevel@tonic-gate } 21850Sstevel@tonic-gate 21860Sstevel@tonic-gate /* doit */ 21870Sstevel@tonic-gate devinfo(args->sp, dnp, res, ep); 21880Sstevel@tonic-gate 21890Sstevel@tonic-gate err = svc_fini(ep); 21900Sstevel@tonic-gate 21910Sstevel@tonic-gate return (TRUE); 21920Sstevel@tonic-gate } 21930Sstevel@tonic-gate 21940Sstevel@tonic-gate /* 21950Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 21960Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 21970Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 21980Sstevel@tonic-gate */ 21990Sstevel@tonic-gate bool_t 22000Sstevel@tonic-gate mdrpc_devinfo_1_svc( 22010Sstevel@tonic-gate mdrpc_devinfo_args *args, 22020Sstevel@tonic-gate mdrpc_devinfo_res *res, 22030Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 22040Sstevel@tonic-gate ) 22050Sstevel@tonic-gate { 22060Sstevel@tonic-gate bool_t retval; 22070Sstevel@tonic-gate mdrpc_devinfo_2_args_r1 v2_args; 22080Sstevel@tonic-gate mdrpc_devinfo_2_res v2_res; 22090Sstevel@tonic-gate 22100Sstevel@tonic-gate /* allocate memory */ 22110Sstevel@tonic-gate v2_args.drivenamep = Zalloc(sizeof (mddrivename_t)); 22120Sstevel@tonic-gate v2_args.drivenamep->parts.parts_val = 22130Sstevel@tonic-gate Zalloc(sizeof (mdname_t) * args->drivenamep->parts.parts_len); 22140Sstevel@tonic-gate 22150Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 22160Sstevel@tonic-gate meta_conv_drvname_old2new(args->drivenamep, v2_args.drivenamep); 22170Sstevel@tonic-gate retval = mdrpc_devinfo_common(&v2_args, &v2_res, rqstp); 22180Sstevel@tonic-gate 22190Sstevel@tonic-gate /* 22200Sstevel@tonic-gate * Fill in the result appropriately. 22210Sstevel@tonic-gate * Since dev_t's for version 2 are 64-bit, 22220Sstevel@tonic-gate * we need to convert them to 32-bit for version 1. 22230Sstevel@tonic-gate */ 22240Sstevel@tonic-gate res->dev = meta_cmpldev(v2_res.dev); 22250Sstevel@tonic-gate res->vtime = v2_res.vtime; 22260Sstevel@tonic-gate res->status = v2_res.status; 22270Sstevel@tonic-gate 22280Sstevel@tonic-gate free(v2_args.drivenamep); 22290Sstevel@tonic-gate free(v2_args.drivenamep->parts.parts_val); 22300Sstevel@tonic-gate 22310Sstevel@tonic-gate return (retval); 22320Sstevel@tonic-gate } 22330Sstevel@tonic-gate 22340Sstevel@tonic-gate bool_t 22350Sstevel@tonic-gate mdrpc_devinfo_2_svc( 22360Sstevel@tonic-gate mdrpc_devinfo_2_args *args, 22370Sstevel@tonic-gate mdrpc_devinfo_2_res *res, 22380Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 22390Sstevel@tonic-gate ) 22400Sstevel@tonic-gate { 22410Sstevel@tonic-gate switch (args->rev) { 22420Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 22430Sstevel@tonic-gate return (mdrpc_devinfo_common( 22440Sstevel@tonic-gate &args->mdrpc_devinfo_2_args_u.rev1, res, rqstp)); 22450Sstevel@tonic-gate default: 22460Sstevel@tonic-gate return (FALSE); 22470Sstevel@tonic-gate } 22480Sstevel@tonic-gate } 22490Sstevel@tonic-gate 22500Sstevel@tonic-gate /* 22510Sstevel@tonic-gate * return device id 22520Sstevel@tonic-gate */ 22530Sstevel@tonic-gate static void 22540Sstevel@tonic-gate mdrpc_get_devid( 22550Sstevel@tonic-gate mdsetname_t *sp, 22560Sstevel@tonic-gate mddrivename_t *dp, 22570Sstevel@tonic-gate mdrpc_devid_res *res, 22580Sstevel@tonic-gate md_error_t *ep 22590Sstevel@tonic-gate ) 22600Sstevel@tonic-gate { 22610Sstevel@tonic-gate mdname_t *np; 22620Sstevel@tonic-gate 22630Sstevel@tonic-gate if ((np = metaslicename(dp, MD_SLICE0, ep)) == NULL) 22640Sstevel@tonic-gate return; 22650Sstevel@tonic-gate 22660Sstevel@tonic-gate if (metaname(&sp, np->bname, ep) == NULL) 22670Sstevel@tonic-gate return; 22680Sstevel@tonic-gate 22690Sstevel@tonic-gate res->enc_devid = meta_get_devid(np->rname); 22700Sstevel@tonic-gate } 22710Sstevel@tonic-gate 22720Sstevel@tonic-gate bool_t 22730Sstevel@tonic-gate mdrpc_devid_2_svc( 22740Sstevel@tonic-gate mdrpc_devid_2_args *args, 22750Sstevel@tonic-gate mdrpc_devid_res *res, 22760Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 22770Sstevel@tonic-gate ) 22780Sstevel@tonic-gate { 22790Sstevel@tonic-gate int slice; 22800Sstevel@tonic-gate mdname_t *np; 22810Sstevel@tonic-gate mddrivename_t *dnp; 22820Sstevel@tonic-gate md_error_t *ep = &res->status; 22830Sstevel@tonic-gate int err; 22840Sstevel@tonic-gate int op_mode = R_OK; 22850Sstevel@tonic-gate 22860Sstevel@tonic-gate switch (args->rev) { 22870Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 22880Sstevel@tonic-gate dnp = (&(args->mdrpc_devid_2_args_u.rev1))->drivenamep; 22890Sstevel@tonic-gate break; 22900Sstevel@tonic-gate default: 22910Sstevel@tonic-gate return (FALSE); 22920Sstevel@tonic-gate } 22930Sstevel@tonic-gate 22940Sstevel@tonic-gate /* setup, check permissions */ 22950Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 22960Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 22970Sstevel@tonic-gate return (FALSE); 22980Sstevel@tonic-gate else if (err != 0) 22990Sstevel@tonic-gate return (TRUE); 23000Sstevel@tonic-gate 23010Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 23020Sstevel@tonic-gate return (TRUE); 23030Sstevel@tonic-gate 23040Sstevel@tonic-gate /* 23050Sstevel@tonic-gate * fix all the drivenamep's in the mdname_t's to 23060Sstevel@tonic-gate * point to the right place. 23070Sstevel@tonic-gate */ 23080Sstevel@tonic-gate for (slice = 0; (slice < dnp->parts.parts_len); ++slice) { 23090Sstevel@tonic-gate if ((np = metaslicename(dnp, slice, ep)) == NULL) 23100Sstevel@tonic-gate return (TRUE); 23110Sstevel@tonic-gate np->drivenamep = dnp; 23120Sstevel@tonic-gate } 23130Sstevel@tonic-gate 23140Sstevel@tonic-gate /* doit */ 23150Sstevel@tonic-gate mdrpc_get_devid((&(args->mdrpc_devid_2_args_u.rev1))->sp, dnp, res, ep); 23160Sstevel@tonic-gate 23170Sstevel@tonic-gate err = svc_fini(ep); 23180Sstevel@tonic-gate 23190Sstevel@tonic-gate return (TRUE); 23200Sstevel@tonic-gate } 23210Sstevel@tonic-gate 23220Sstevel@tonic-gate /* 23230Sstevel@tonic-gate * This routine should not be called for a multi-node diskset. 23240Sstevel@tonic-gate * 23250Sstevel@tonic-gate * The devid support is disabled for MN diskset so this routine 23260Sstevel@tonic-gate * will not be called if the set is MN diskset. The check has 23270Sstevel@tonic-gate * been done early in meta_getnextside_devinfo. However this 23280Sstevel@tonic-gate * routine will be called when the devid support for MN set is 23290Sstevel@tonic-gate * enabled and check is removed. 23300Sstevel@tonic-gate */ 23310Sstevel@tonic-gate bool_t 23320Sstevel@tonic-gate mdrpc_devinfo_by_devid_2_svc( 23330Sstevel@tonic-gate mdrpc_devidstr_args *args, 23340Sstevel@tonic-gate mdrpc_devinfo_2_res *res, 23350Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 23360Sstevel@tonic-gate ) 23370Sstevel@tonic-gate { 23380Sstevel@tonic-gate 23390Sstevel@tonic-gate char *devidstr = args->enc_devid; 23400Sstevel@tonic-gate md_error_t *ep = &res->status; 23410Sstevel@tonic-gate ddi_devid_t devid; 23420Sstevel@tonic-gate char *minor_name = NULL; 23430Sstevel@tonic-gate int ret = 0; 23440Sstevel@tonic-gate int err; 23450Sstevel@tonic-gate devid_nmlist_t *disklist = NULL; 23460Sstevel@tonic-gate int op_mode = R_OK; 23470Sstevel@tonic-gate mdname_t *np; 23480Sstevel@tonic-gate mdsetname_t *sp = args->sp; 23490Sstevel@tonic-gate 23500Sstevel@tonic-gate /* setup, check permissions */ 23510Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 23520Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 23530Sstevel@tonic-gate return (FALSE); 23540Sstevel@tonic-gate else if (err != 0) 23550Sstevel@tonic-gate return (TRUE); 23560Sstevel@tonic-gate 23570Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 23580Sstevel@tonic-gate return (TRUE); 23590Sstevel@tonic-gate 23600Sstevel@tonic-gate if (devid_str_decode(devidstr, &devid, &minor_name) != 0) 23610Sstevel@tonic-gate return (TRUE); 23620Sstevel@tonic-gate 23630Sstevel@tonic-gate /* 23640Sstevel@tonic-gate * if we do not have a minor name then look for a character device. 23650Sstevel@tonic-gate * This is because the caller (checkdrive_onnode) expects a character 23660Sstevel@tonic-gate * device to be returned. The other client of this interface is 23670Sstevel@tonic-gate * meta_getnextside_devinfo and this supplies a minor name. 23680Sstevel@tonic-gate */ 23690Sstevel@tonic-gate if (minor_name == NULL) { 23700Sstevel@tonic-gate ret = meta_deviceid_to_nmlist("/dev", devid, 23710Sstevel@tonic-gate DEVID_MINOR_NAME_ALL_CHR, &disklist); 23720Sstevel@tonic-gate } else { 23730Sstevel@tonic-gate ret = meta_deviceid_to_nmlist("/dev", devid, minor_name, 23740Sstevel@tonic-gate &disklist); 23750Sstevel@tonic-gate devid_str_free(minor_name); 23760Sstevel@tonic-gate } 23770Sstevel@tonic-gate 23780Sstevel@tonic-gate devid_free(devid); 23790Sstevel@tonic-gate if (ret != 0) { 23800Sstevel@tonic-gate res->dev = NODEV64; 23810Sstevel@tonic-gate devid_free_nmlist(disklist); 23820Sstevel@tonic-gate return (TRUE); 23830Sstevel@tonic-gate } 23840Sstevel@tonic-gate 23850Sstevel@tonic-gate np = metaname(&sp, disklist[0].devname, ep); 23860Sstevel@tonic-gate if (np != NULL) { 23870Sstevel@tonic-gate mdcinfo_t *cinfo; 23880Sstevel@tonic-gate if ((cinfo = metagetcinfo(np, ep)) != NULL) { 23890Sstevel@tonic-gate res->drivername = Strdup(cinfo->dname); 23900Sstevel@tonic-gate } 23910Sstevel@tonic-gate } 23920Sstevel@tonic-gate 23930Sstevel@tonic-gate res->dev = meta_expldev(disklist[0].dev); 23940Sstevel@tonic-gate res->devname = strdup(disklist[0].devname); 23950Sstevel@tonic-gate 23960Sstevel@tonic-gate devid_free_nmlist(disklist); 23970Sstevel@tonic-gate 23980Sstevel@tonic-gate err = svc_fini(ep); 23990Sstevel@tonic-gate 24000Sstevel@tonic-gate return (TRUE); 24010Sstevel@tonic-gate } 24020Sstevel@tonic-gate 24030Sstevel@tonic-gate /* 24040Sstevel@tonic-gate * This routine should not be called for a multi-node diskset. 24050Sstevel@tonic-gate * 24060Sstevel@tonic-gate * The devid support is disabled for MN diskset so this routine 24070Sstevel@tonic-gate * will not be called if the set is MN diskset. The check has 24080Sstevel@tonic-gate * been done early in meta_getnextside_devinfo. However this 24090Sstevel@tonic-gate * routine will be called when the devid support for MN set is 24100Sstevel@tonic-gate * enabled and check is removed. 24110Sstevel@tonic-gate * 24120Sstevel@tonic-gate * This function will return the device info attempting to use 24130Sstevel@tonic-gate * both the passed in devid and device name. This is to deal 24140Sstevel@tonic-gate * with systems that use multi-path disks but not running mpxio. 24150Sstevel@tonic-gate * In this situation meta_deviceid_to_nmlist will return multiple 24160Sstevel@tonic-gate * devices. The orig_devname is used to disambiguate. 24170Sstevel@tonic-gate * 24180Sstevel@tonic-gate */ 24190Sstevel@tonic-gate bool_t 24200Sstevel@tonic-gate mdrpc_devinfo_by_devid_name_2_svc( 24210Sstevel@tonic-gate mdrpc_devid_name_2_args *args, 24220Sstevel@tonic-gate mdrpc_devinfo_2_res *res, 24230Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 24240Sstevel@tonic-gate ) 24250Sstevel@tonic-gate { 24260Sstevel@tonic-gate 24270Sstevel@tonic-gate char *devidstr; 24280Sstevel@tonic-gate char *orig_devname; 24290Sstevel@tonic-gate md_error_t *ep = &res->status; 24300Sstevel@tonic-gate ddi_devid_t devid; 24310Sstevel@tonic-gate char *minor_name = NULL; 24320Sstevel@tonic-gate int ret = 0; 24330Sstevel@tonic-gate int err; 24340Sstevel@tonic-gate int i; 24350Sstevel@tonic-gate devid_nmlist_t *disklist = NULL; 24360Sstevel@tonic-gate int op_mode = R_OK; 24370Sstevel@tonic-gate mdname_t *np; 24380Sstevel@tonic-gate mdsetname_t *sp; 24390Sstevel@tonic-gate 24400Sstevel@tonic-gate switch (args->rev) { 24410Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 24420Sstevel@tonic-gate sp = (&(args->mdrpc_devid_name_2_args_u.rev1))->sp; 24430Sstevel@tonic-gate devidstr = (&(args->mdrpc_devid_name_2_args_u.rev1))->enc_devid; 24440Sstevel@tonic-gate orig_devname = 24450Sstevel@tonic-gate (&(args->mdrpc_devid_name_2_args_u.rev1))->orig_devname; 24460Sstevel@tonic-gate break; 24470Sstevel@tonic-gate default: 24480Sstevel@tonic-gate return (FALSE); 24490Sstevel@tonic-gate } 24500Sstevel@tonic-gate 24510Sstevel@tonic-gate /* setup, check permissions */ 24520Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 24530Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 24540Sstevel@tonic-gate return (FALSE); 24550Sstevel@tonic-gate else if (err != 0) 24560Sstevel@tonic-gate return (TRUE); 24570Sstevel@tonic-gate 24580Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 24590Sstevel@tonic-gate return (TRUE); 24600Sstevel@tonic-gate 24610Sstevel@tonic-gate if (devid_str_decode(devidstr, &devid, &minor_name) != 0) 24620Sstevel@tonic-gate return (TRUE); 24630Sstevel@tonic-gate 24640Sstevel@tonic-gate /* 24650Sstevel@tonic-gate * if we do not have a minor name then look for a character device. 24660Sstevel@tonic-gate * This is because the caller (checkdrive_onnode) expects a character 24670Sstevel@tonic-gate * device to be returned. The other client of this interface is 24680Sstevel@tonic-gate * meta_getnextside_devinfo and this supplies a minor name. 24690Sstevel@tonic-gate */ 24700Sstevel@tonic-gate if (minor_name == NULL) { 24710Sstevel@tonic-gate ret = meta_deviceid_to_nmlist("/dev", devid, 24720Sstevel@tonic-gate DEVID_MINOR_NAME_ALL_CHR, &disklist); 24730Sstevel@tonic-gate } else { 24740Sstevel@tonic-gate ret = meta_deviceid_to_nmlist("/dev", devid, minor_name, 24750Sstevel@tonic-gate &disklist); 24760Sstevel@tonic-gate devid_str_free(minor_name); 24770Sstevel@tonic-gate } 24780Sstevel@tonic-gate 24790Sstevel@tonic-gate devid_free(devid); 24800Sstevel@tonic-gate if (ret != 0) { 24810Sstevel@tonic-gate res->dev = NODEV64; 24820Sstevel@tonic-gate devid_free_nmlist(disklist); 24830Sstevel@tonic-gate return (TRUE); 24840Sstevel@tonic-gate } 24850Sstevel@tonic-gate 24860Sstevel@tonic-gate /* attempt to match to the device name on the originating node */ 24870Sstevel@tonic-gate for (i = 0; disklist[i].dev != NODEV; i++) { 24880Sstevel@tonic-gate if (strncmp(orig_devname, disklist[i].devname, 24890Sstevel@tonic-gate strlen(disklist[i].devname)) == 0) 24900Sstevel@tonic-gate break; 24910Sstevel@tonic-gate } 24920Sstevel@tonic-gate 24930Sstevel@tonic-gate /* if it's not found then use the first disk in the list */ 24940Sstevel@tonic-gate if (disklist[i].dev == NODEV) 24950Sstevel@tonic-gate i = 0; 24960Sstevel@tonic-gate 24970Sstevel@tonic-gate np = metaname(&sp, disklist[i].devname, ep); 24980Sstevel@tonic-gate if (np != NULL) { 24990Sstevel@tonic-gate mdcinfo_t *cinfo; 25000Sstevel@tonic-gate if ((cinfo = metagetcinfo(np, ep)) != NULL) { 25010Sstevel@tonic-gate res->drivername = Strdup(cinfo->dname); 25020Sstevel@tonic-gate } 25030Sstevel@tonic-gate } 25040Sstevel@tonic-gate 25050Sstevel@tonic-gate res->dev = meta_expldev(disklist[i].dev); 25060Sstevel@tonic-gate res->devname = strdup(disklist[i].devname); 25070Sstevel@tonic-gate 25080Sstevel@tonic-gate devid_free_nmlist(disklist); 25090Sstevel@tonic-gate 25100Sstevel@tonic-gate err = svc_fini(ep); 25110Sstevel@tonic-gate 25120Sstevel@tonic-gate return (TRUE); 25130Sstevel@tonic-gate } 25140Sstevel@tonic-gate 25150Sstevel@tonic-gate static void 25160Sstevel@tonic-gate drvused(mdsetname_t *sp, mddrivename_t *dnp, md_error_t *ep) 25170Sstevel@tonic-gate { 25180Sstevel@tonic-gate if (meta_check_drivemounted(sp, dnp, ep)) 25190Sstevel@tonic-gate return; 25200Sstevel@tonic-gate 25210Sstevel@tonic-gate if (meta_check_driveswapped(sp, dnp, ep)) 25220Sstevel@tonic-gate return; 25230Sstevel@tonic-gate 25240Sstevel@tonic-gate if (meta_check_drive_inuse(metasetname(MD_LOCAL_NAME, ep), dnp, 25250Sstevel@tonic-gate TRUE, ep)) 25260Sstevel@tonic-gate return; 25270Sstevel@tonic-gate 25280Sstevel@tonic-gate (void) meta_check_driveinset(sp, dnp, ep); 25290Sstevel@tonic-gate } 25300Sstevel@tonic-gate 25310Sstevel@tonic-gate /* 25320Sstevel@tonic-gate * determine if a device is in use. 25330Sstevel@tonic-gate */ 25340Sstevel@tonic-gate bool_t 25350Sstevel@tonic-gate mdrpc_drvused_common( 25360Sstevel@tonic-gate mdrpc_drvused_2_args_r1 *args, 25370Sstevel@tonic-gate mdrpc_generic_res *res, 25380Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 25390Sstevel@tonic-gate ) 25400Sstevel@tonic-gate { 25410Sstevel@tonic-gate md_error_t *ep = &res->status; 25420Sstevel@tonic-gate int slice; 25430Sstevel@tonic-gate mdname_t *np; 25440Sstevel@tonic-gate mddrivename_t *dnp = args->drivenamep; 25450Sstevel@tonic-gate int err; 25460Sstevel@tonic-gate int op_mode = R_OK; 25470Sstevel@tonic-gate 25480Sstevel@tonic-gate /* setup, check permissions */ 25490Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 25500Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 25510Sstevel@tonic-gate return (FALSE); 25520Sstevel@tonic-gate else if (err != 0) 25530Sstevel@tonic-gate return (TRUE); 25540Sstevel@tonic-gate 25550Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 25560Sstevel@tonic-gate return (TRUE); 25570Sstevel@tonic-gate 25580Sstevel@tonic-gate if (dnp == NULL) { 25590Sstevel@tonic-gate /* no drive pointer specified */ 25600Sstevel@tonic-gate return (TRUE); 25610Sstevel@tonic-gate } 25620Sstevel@tonic-gate /* 25630Sstevel@tonic-gate * fix all the drivenamep's in the mdname_t's to 25640Sstevel@tonic-gate * point to the right place. 25650Sstevel@tonic-gate */ 25660Sstevel@tonic-gate for (slice = 0; (slice < dnp->parts.parts_len); ++slice) { 25670Sstevel@tonic-gate if ((np = metaslicename(dnp, slice, ep)) == NULL) 25680Sstevel@tonic-gate return (TRUE); 25690Sstevel@tonic-gate np->drivenamep = dnp; 25700Sstevel@tonic-gate } 25710Sstevel@tonic-gate 25720Sstevel@tonic-gate /* doit */ 25730Sstevel@tonic-gate drvused(args->sp, dnp, ep); 25740Sstevel@tonic-gate 25750Sstevel@tonic-gate err = svc_fini(ep); 25760Sstevel@tonic-gate 25770Sstevel@tonic-gate return (TRUE); 25780Sstevel@tonic-gate } 25790Sstevel@tonic-gate 25800Sstevel@tonic-gate /* 25810Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 25820Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 25830Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 25840Sstevel@tonic-gate */ 25850Sstevel@tonic-gate bool_t 25860Sstevel@tonic-gate mdrpc_drvused_1_svc( 25870Sstevel@tonic-gate mdrpc_drvused_args *args, 25880Sstevel@tonic-gate mdrpc_generic_res *res, 25890Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 25900Sstevel@tonic-gate ) 25910Sstevel@tonic-gate { 25920Sstevel@tonic-gate bool_t retval; 25930Sstevel@tonic-gate mdrpc_drvused_2_args_r1 v2_args; 25940Sstevel@tonic-gate 25950Sstevel@tonic-gate /* allocate memory */ 25960Sstevel@tonic-gate v2_args.drivenamep = Zalloc(sizeof (mddrivename_t)); 25970Sstevel@tonic-gate v2_args.drivenamep->parts.parts_val = 25980Sstevel@tonic-gate Zalloc(sizeof (mdname_t) * args->drivenamep->parts.parts_len); 25990Sstevel@tonic-gate 26000Sstevel@tonic-gate /* build args */ 26010Sstevel@tonic-gate v2_args.sp = args->sp; 26020Sstevel@tonic-gate v2_args.cl_sk = args->cl_sk; 26030Sstevel@tonic-gate 26040Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 26050Sstevel@tonic-gate meta_conv_drvname_old2new(args->drivenamep, v2_args.drivenamep); 26060Sstevel@tonic-gate retval = mdrpc_drvused_common(&v2_args, res, rqstp); 26070Sstevel@tonic-gate 26080Sstevel@tonic-gate free(v2_args.drivenamep); 26090Sstevel@tonic-gate free(v2_args.drivenamep->parts.parts_val); 26100Sstevel@tonic-gate 26110Sstevel@tonic-gate return (retval); 26120Sstevel@tonic-gate } 26130Sstevel@tonic-gate 26140Sstevel@tonic-gate bool_t 26150Sstevel@tonic-gate mdrpc_drvused_2_svc( 26160Sstevel@tonic-gate mdrpc_drvused_2_args *args, 26170Sstevel@tonic-gate mdrpc_generic_res *res, 26180Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 26190Sstevel@tonic-gate ) 26200Sstevel@tonic-gate { 26210Sstevel@tonic-gate switch (args->rev) { 26220Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 26230Sstevel@tonic-gate return (mdrpc_drvused_common( 26240Sstevel@tonic-gate &args->mdrpc_drvused_2_args_u.rev1, res, rqstp)); 26250Sstevel@tonic-gate default: 26260Sstevel@tonic-gate return (FALSE); 26270Sstevel@tonic-gate } 26280Sstevel@tonic-gate } 26290Sstevel@tonic-gate 26300Sstevel@tonic-gate /* 26310Sstevel@tonic-gate * return a set records selected by name or number. 26320Sstevel@tonic-gate */ 26330Sstevel@tonic-gate bool_t 26340Sstevel@tonic-gate mdrpc_getset_common( 26350Sstevel@tonic-gate mdrpc_getset_args *args, 26360Sstevel@tonic-gate mdrpc_getset_res *res, 26370Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 26380Sstevel@tonic-gate ) 26390Sstevel@tonic-gate { 26400Sstevel@tonic-gate md_error_t *ep = &res->status; 26410Sstevel@tonic-gate int err; 26420Sstevel@tonic-gate int op_mode = R_OK; 26430Sstevel@tonic-gate 26440Sstevel@tonic-gate /* setup, check permissions */ 26450Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 26460Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 26470Sstevel@tonic-gate return (FALSE); 26480Sstevel@tonic-gate else if (err != 0) 26490Sstevel@tonic-gate return (TRUE); 26500Sstevel@tonic-gate 26510Sstevel@tonic-gate /* Don't have a setno, so we don't check the lock */ 26520Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 26530Sstevel@tonic-gate return (TRUE); 26540Sstevel@tonic-gate 26550Sstevel@tonic-gate /* doit */ 26560Sstevel@tonic-gate if (args->setname && *args->setname) 26570Sstevel@tonic-gate res->sr = setdup(getsetbyname(args->setname, ep)); 26580Sstevel@tonic-gate else if (args->setno > 0) 26590Sstevel@tonic-gate res->sr = setdup(getsetbynum(args->setno, ep)); 26600Sstevel@tonic-gate else 26610Sstevel@tonic-gate res->sr = NULL; 26620Sstevel@tonic-gate 26630Sstevel@tonic-gate err = svc_fini(ep); 26640Sstevel@tonic-gate 26650Sstevel@tonic-gate return (TRUE); 26660Sstevel@tonic-gate } 26670Sstevel@tonic-gate 26680Sstevel@tonic-gate bool_t 26690Sstevel@tonic-gate mdrpc_getset_1_svc( 26700Sstevel@tonic-gate mdrpc_getset_args *args, 26710Sstevel@tonic-gate mdrpc_getset_res *res, 26720Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 26730Sstevel@tonic-gate ) 26740Sstevel@tonic-gate { 26750Sstevel@tonic-gate return (mdrpc_getset_common(args, res, rqstp)); 26760Sstevel@tonic-gate } 26770Sstevel@tonic-gate 26780Sstevel@tonic-gate bool_t 26790Sstevel@tonic-gate mdrpc_getset_2_svc( 26800Sstevel@tonic-gate mdrpc_getset_2_args *args, 26810Sstevel@tonic-gate mdrpc_getset_res *res, 26820Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 26830Sstevel@tonic-gate ) 26840Sstevel@tonic-gate { 26850Sstevel@tonic-gate switch (args->rev) { 26860Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 26870Sstevel@tonic-gate return (mdrpc_getset_common( 26880Sstevel@tonic-gate &args->mdrpc_getset_2_args_u.rev1, res, rqstp)); 26890Sstevel@tonic-gate default: 26900Sstevel@tonic-gate return (FALSE); 26910Sstevel@tonic-gate } 26920Sstevel@tonic-gate } 26930Sstevel@tonic-gate 26940Sstevel@tonic-gate /* 26950Sstevel@tonic-gate * return a MN set record selected by name or number. 26960Sstevel@tonic-gate */ 26970Sstevel@tonic-gate bool_t 26980Sstevel@tonic-gate mdrpc_mngetset_common( 26990Sstevel@tonic-gate mdrpc_getset_args *args, 27000Sstevel@tonic-gate mdrpc_mngetset_res *res, 27010Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 27020Sstevel@tonic-gate ) 27030Sstevel@tonic-gate { 27040Sstevel@tonic-gate md_error_t *ep = &res->status; 27050Sstevel@tonic-gate int err; 27060Sstevel@tonic-gate int op_mode = R_OK; 27070Sstevel@tonic-gate md_set_record *sr = NULL; 27080Sstevel@tonic-gate md_mnset_record *mnsr = NULL; 27090Sstevel@tonic-gate 27100Sstevel@tonic-gate /* setup, check permissions */ 27110Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 27120Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 27130Sstevel@tonic-gate return (FALSE); 27140Sstevel@tonic-gate else if (err != 0) 27150Sstevel@tonic-gate return (TRUE); 27160Sstevel@tonic-gate 27170Sstevel@tonic-gate /* Don't have a setno, so we don't check the lock */ 27180Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 27190Sstevel@tonic-gate return (TRUE); 27200Sstevel@tonic-gate 27210Sstevel@tonic-gate /* doit */ 27220Sstevel@tonic-gate res->mnsr = NULL; 27230Sstevel@tonic-gate if (args->setname && *args->setname) 27240Sstevel@tonic-gate sr = getsetbyname(args->setname, ep); 27250Sstevel@tonic-gate else if (args->setno > 0) 27260Sstevel@tonic-gate sr = getsetbynum(args->setno, ep); 27270Sstevel@tonic-gate 27280Sstevel@tonic-gate if ((sr) && (MD_MNSET_REC(sr))) { 27290Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 27300Sstevel@tonic-gate res->mnsr = mnsetdup(mnsr); 27310Sstevel@tonic-gate } 27320Sstevel@tonic-gate 27330Sstevel@tonic-gate err = svc_fini(ep); 27340Sstevel@tonic-gate 27350Sstevel@tonic-gate return (TRUE); 27360Sstevel@tonic-gate } 27370Sstevel@tonic-gate 27380Sstevel@tonic-gate bool_t 27390Sstevel@tonic-gate mdrpc_mngetset_2_svc( 27400Sstevel@tonic-gate mdrpc_getset_2_args *args, 27410Sstevel@tonic-gate mdrpc_mngetset_res *res, 27420Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 27430Sstevel@tonic-gate ) 27440Sstevel@tonic-gate { 27450Sstevel@tonic-gate switch (args->rev) { 27460Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 27470Sstevel@tonic-gate return (mdrpc_mngetset_common( 27480Sstevel@tonic-gate &args->mdrpc_getset_2_args_u.rev1, res, rqstp)); 27490Sstevel@tonic-gate default: 27500Sstevel@tonic-gate return (FALSE); 27510Sstevel@tonic-gate } 27520Sstevel@tonic-gate } 27530Sstevel@tonic-gate 27540Sstevel@tonic-gate static void 27550Sstevel@tonic-gate upd_setmaster( 27560Sstevel@tonic-gate mdsetname_t *sp, 27570Sstevel@tonic-gate md_node_nm_t master_nodenm, 27580Sstevel@tonic-gate int master_nodeid, 27590Sstevel@tonic-gate md_error_t *ep 27600Sstevel@tonic-gate ) 27610Sstevel@tonic-gate { 27620Sstevel@tonic-gate mdsetname_t *local_sp; 27630Sstevel@tonic-gate md_set_record *sr; 27640Sstevel@tonic-gate md_mnset_record *mnsr; 27650Sstevel@tonic-gate mddb_setmaster_config_t sm; 27660Sstevel@tonic-gate 27670Sstevel@tonic-gate if ((local_sp = metasetname(sp->setname, ep)) == NULL) 27680Sstevel@tonic-gate return; 27690Sstevel@tonic-gate 27700Sstevel@tonic-gate metaflushsetname(local_sp); 27710Sstevel@tonic-gate 27720Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 27730Sstevel@tonic-gate return; 27740Sstevel@tonic-gate 27750Sstevel@tonic-gate if (MD_MNSET_REC(sr)) { 27760Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 27770Sstevel@tonic-gate strlcpy(mnsr->sr_master_nodenm, master_nodenm, 27780Sstevel@tonic-gate MD_MAX_NODENAME); 27790Sstevel@tonic-gate mnsr->sr_master_nodeid = master_nodeid; 27800Sstevel@tonic-gate if (master_nodeid != 0) { 27810Sstevel@tonic-gate (void) memset(&sm, 0, sizeof (sm)); 27820Sstevel@tonic-gate sm.c_setno = sp->setno; 27830Sstevel@tonic-gate /* Use magic to help protect ioctl against attack. */ 27840Sstevel@tonic-gate sm.c_magic = MDDB_SETMASTER_MAGIC; 27850Sstevel@tonic-gate if (strcmp(master_nodenm, mynode()) == 0) { 27860Sstevel@tonic-gate sm.c_current_host_master = 1; 27870Sstevel@tonic-gate } else { 27880Sstevel@tonic-gate sm.c_current_host_master = 0; 27890Sstevel@tonic-gate } 27900Sstevel@tonic-gate (void) metaioctl(MD_SETMASTER, &sm, &sm.c_mde, NULL); 27910Sstevel@tonic-gate mdclrerror(&sm.c_mde); 27920Sstevel@tonic-gate } 27930Sstevel@tonic-gate } 27940Sstevel@tonic-gate 27950Sstevel@tonic-gate out: 27960Sstevel@tonic-gate commitset(sr, FALSE, ep); 27970Sstevel@tonic-gate free_sr(sr); 27980Sstevel@tonic-gate } 27990Sstevel@tonic-gate 28000Sstevel@tonic-gate /* 28010Sstevel@tonic-gate * set the master and nodeid in node record 28020Sstevel@tonic-gate */ 28030Sstevel@tonic-gate bool_t 28040Sstevel@tonic-gate mdrpc_mnsetmaster_common( 28050Sstevel@tonic-gate mdrpc_mnsetmaster_args *args, 28060Sstevel@tonic-gate mdrpc_generic_res *res, 28070Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 28080Sstevel@tonic-gate ) 28090Sstevel@tonic-gate { 28100Sstevel@tonic-gate md_error_t *ep = &res->status; 28110Sstevel@tonic-gate int err; 28120Sstevel@tonic-gate int op_mode = W_OK; 28130Sstevel@tonic-gate 28140Sstevel@tonic-gate /* setup, check permissions */ 28150Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 28160Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 28170Sstevel@tonic-gate return (FALSE); 28180Sstevel@tonic-gate else if (err != 0) 28190Sstevel@tonic-gate return (TRUE); 28200Sstevel@tonic-gate 28210Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 28220Sstevel@tonic-gate return (TRUE); 28230Sstevel@tonic-gate 28240Sstevel@tonic-gate /* doit */ 28250Sstevel@tonic-gate upd_setmaster(args->sp, args->master_nodenm, args->master_nodeid, ep); 28260Sstevel@tonic-gate 28270Sstevel@tonic-gate err = svc_fini(ep); 28280Sstevel@tonic-gate 28290Sstevel@tonic-gate return (TRUE); 28300Sstevel@tonic-gate } 28310Sstevel@tonic-gate 28320Sstevel@tonic-gate bool_t 28330Sstevel@tonic-gate mdrpc_mnsetmaster_2_svc( 28340Sstevel@tonic-gate mdrpc_mnsetmaster_2_args *args, 28350Sstevel@tonic-gate mdrpc_generic_res *res, 28360Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 28370Sstevel@tonic-gate ) 28380Sstevel@tonic-gate { 28390Sstevel@tonic-gate switch (args->rev) { 28400Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 28410Sstevel@tonic-gate return (mdrpc_mnsetmaster_common( 28420Sstevel@tonic-gate &args->mdrpc_mnsetmaster_2_args_u.rev1, res, rqstp)); 28430Sstevel@tonic-gate default: 28440Sstevel@tonic-gate return (FALSE); 28450Sstevel@tonic-gate } 28460Sstevel@tonic-gate } 28470Sstevel@tonic-gate 28480Sstevel@tonic-gate /* 28490Sstevel@tonic-gate * Join this node to the diskset. 28500Sstevel@tonic-gate * Pass stale_flag information to snarf_set so that snarf code 28510Sstevel@tonic-gate * can choose a STALE or non-STALE state when starting the set. 28520Sstevel@tonic-gate * If master is STALE, any joining node will join a stale set regardless 28530Sstevel@tonic-gate * of the number of accessible mddbs. Also, if master is at 50% 28540Sstevel@tonic-gate * accessible replicas and is in the TOOFEW state, don't mark newly 28550Sstevel@tonic-gate * joining node as STALE; mark it TOOFEW instead. 28560Sstevel@tonic-gate */ 28570Sstevel@tonic-gate static void 28580Sstevel@tonic-gate joinset( 28590Sstevel@tonic-gate mdsetname_t *sp, 28600Sstevel@tonic-gate int flags, 28610Sstevel@tonic-gate md_error_t *ep 28620Sstevel@tonic-gate ) 28630Sstevel@tonic-gate { 28640Sstevel@tonic-gate mdsetname_t *local_sp; 28650Sstevel@tonic-gate md_drive_desc *mydd; 28660Sstevel@tonic-gate bool_t stale_bool; 28670Sstevel@tonic-gate mddb_block_parm_t mbp; 28680Sstevel@tonic-gate md_error_t xep = mdnullerror; 28690Sstevel@tonic-gate 28700Sstevel@tonic-gate if ((local_sp = metasetname(sp->setname, ep)) == NULL) 28710Sstevel@tonic-gate return; 28720Sstevel@tonic-gate 28730Sstevel@tonic-gate /* 28740Sstevel@tonic-gate * Start mddoors daemon here. 28750Sstevel@tonic-gate * mddoors itself takes care there will be 28760Sstevel@tonic-gate * only one instance running, so starting it twice won't hurt 28770Sstevel@tonic-gate */ 28780Sstevel@tonic-gate pclose(popen(MDDOORS, "w")); 28790Sstevel@tonic-gate 28800Sstevel@tonic-gate /* 28810Sstevel@tonic-gate * Get latest copy of data. If a drive was just added causing 28820Sstevel@tonic-gate * nodes to get joined - this drive won't be in the local 28830Sstevel@tonic-gate * name caches drive list yet. 28840Sstevel@tonic-gate */ 28850Sstevel@tonic-gate metaflushsetname(local_sp); 28860Sstevel@tonic-gate 28870Sstevel@tonic-gate mydd = metaget_drivedesc(local_sp, (MD_BASICNAME_OK | PRINT_FAST), ep); 28880Sstevel@tonic-gate if (mydd) { 2889*650Sskamm /* 2890*650Sskamm * Causes mddbs to be loaded into the kernel. 2891*650Sskamm * Set the force flag so that replica locations can be loaded 2892*650Sskamm * into the kernel even if a mediator node was unavailable. 2893*650Sskamm * This allows a node to join an MO diskset when there are 2894*650Sskamm * sufficient replicas available, but a mediator node 2895*650Sskamm * in unavailable. 2896*650Sskamm */ 2897*650Sskamm if (setup_db_bydd(local_sp, mydd, TRUE, ep) == -1) { 28980Sstevel@tonic-gate /* If ep isn't set for some reason, set it */ 2899*650Sskamm if (mdisok(ep)) { 290062Sjeanm (void) mdmddberror(ep, MDE_DB_NOTNOW, 290162Sjeanm (minor_t)NODEV64, sp->setno, 0, NULL); 29020Sstevel@tonic-gate } 29030Sstevel@tonic-gate return; 29040Sstevel@tonic-gate } 29050Sstevel@tonic-gate 29060Sstevel@tonic-gate if (flags & MNSET_IS_STALE) 29070Sstevel@tonic-gate stale_bool = TRUE; 29080Sstevel@tonic-gate else 29090Sstevel@tonic-gate stale_bool = FALSE; 29100Sstevel@tonic-gate 29110Sstevel@tonic-gate /* 29120Sstevel@tonic-gate * Snarf the set. No failure has occurred if STALE or 29130Sstevel@tonic-gate * ACCOK error was set. Otherwise, fail the call setting 29140Sstevel@tonic-gate * a generic error if no error was already set. 29150Sstevel@tonic-gate * 29160Sstevel@tonic-gate * STALE means that set has < 50% mddbs. 29170Sstevel@tonic-gate * ACCOK means that the mediator provided an extra vote. 29180Sstevel@tonic-gate */ 29190Sstevel@tonic-gate if (snarf_set(local_sp, stale_bool, ep) != 0) { 29200Sstevel@tonic-gate if (!(mdismddberror(ep, MDE_DB_STALE)) && 29210Sstevel@tonic-gate !(mdismddberror(ep, MDE_DB_ACCOK))) { 29220Sstevel@tonic-gate return; 29230Sstevel@tonic-gate } else if (mdisok(ep)) { 29240Sstevel@tonic-gate /* If snarf failed, but no error set - set it */ 292562Sjeanm (void) mdmddberror(ep, MDE_DB_NOTNOW, 292662Sjeanm (minor_t)NODEV64, sp->setno, 0, NULL); 29270Sstevel@tonic-gate return; 29280Sstevel@tonic-gate } 29290Sstevel@tonic-gate } 29300Sstevel@tonic-gate 29310Sstevel@tonic-gate /* 29320Sstevel@tonic-gate * If node is joining during reconfig cycle, then 29330Sstevel@tonic-gate * set mddb_parse to be in blocked state so that 29340Sstevel@tonic-gate * mddb reparse messages are not generated until 29350Sstevel@tonic-gate * the commd has been resumed later in the reconfig 29360Sstevel@tonic-gate * cycle. 29370Sstevel@tonic-gate */ 29380Sstevel@tonic-gate if (flags & MNSET_IN_RECONFIG) { 29390Sstevel@tonic-gate (void) memset(&mbp, 0, sizeof (mbp)); 29400Sstevel@tonic-gate if (s_ownset(sp->setno, &xep) == MD_SETOWNER_YES) { 29410Sstevel@tonic-gate (void) memset(&mbp, 0, sizeof (mbp)); 29420Sstevel@tonic-gate mbp.c_setno = local_sp->setno; 29430Sstevel@tonic-gate mbp.c_blk_flags = MDDB_BLOCK_PARSE; 29440Sstevel@tonic-gate if (metaioctl(MD_MN_MDDB_BLOCK, &mbp, 29450Sstevel@tonic-gate &mbp.c_mde, NULL)) { 29460Sstevel@tonic-gate mdstealerror(&xep, &mbp.c_mde); 29470Sstevel@tonic-gate mde_perror(ep, gettext( 29480Sstevel@tonic-gate "Could not block set %s"), 29490Sstevel@tonic-gate sp->setname); 29500Sstevel@tonic-gate return; 29510Sstevel@tonic-gate } 29520Sstevel@tonic-gate } 29530Sstevel@tonic-gate /* 29540Sstevel@tonic-gate * If s_ownset fails and snarf_set succeeded, 29550Sstevel@tonic-gate * then can steal the ownset failure information 29560Sstevel@tonic-gate * and store it into ep. If snarf_set failed, 29570Sstevel@tonic-gate * don't overwrite critical ep information even 29580Sstevel@tonic-gate * if s_ownset failed. 29590Sstevel@tonic-gate */ 29600Sstevel@tonic-gate if (!mdisok(&xep)) { 29610Sstevel@tonic-gate /* 29620Sstevel@tonic-gate * If snarf_set succeeded or snarf_set failed 29630Sstevel@tonic-gate * with MDE_DB_ACCOK (which is set if the 29640Sstevel@tonic-gate * mediator provided the extra vote) then 29650Sstevel@tonic-gate * steal the xep failure information and put 29660Sstevel@tonic-gate * into ep. 29670Sstevel@tonic-gate */ 29680Sstevel@tonic-gate if (mdisok(ep) || 29690Sstevel@tonic-gate mdismddberror(ep, MDE_DB_ACCOK)) { 29700Sstevel@tonic-gate mdstealerror(ep, &xep); 29710Sstevel@tonic-gate } 29720Sstevel@tonic-gate } 29730Sstevel@tonic-gate } 29740Sstevel@tonic-gate } 29750Sstevel@tonic-gate } 29760Sstevel@tonic-gate 29770Sstevel@tonic-gate /* 29780Sstevel@tonic-gate * Have this node join the set. 29790Sstevel@tonic-gate * This is called when a node has been 29800Sstevel@tonic-gate * added to a MN diskset that has drives. 29810Sstevel@tonic-gate * Also, called when a node is an alive 29820Sstevel@tonic-gate * member of a MN diskset and the first 29830Sstevel@tonic-gate * drive has been added. 29840Sstevel@tonic-gate */ 29850Sstevel@tonic-gate bool_t 29860Sstevel@tonic-gate mdrpc_joinset_common( 29870Sstevel@tonic-gate mdrpc_sp_flags_args *args, 29880Sstevel@tonic-gate mdrpc_generic_res *res, 29890Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 29900Sstevel@tonic-gate ) 29910Sstevel@tonic-gate { 29920Sstevel@tonic-gate md_error_t *ep = &res->status; 29930Sstevel@tonic-gate int err; 29940Sstevel@tonic-gate int op_mode = W_OK; 29950Sstevel@tonic-gate 29960Sstevel@tonic-gate /* setup, check permissions */ 29970Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 29980Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 29990Sstevel@tonic-gate return (FALSE); 30000Sstevel@tonic-gate else if (err != 0) 30010Sstevel@tonic-gate return (TRUE); 30020Sstevel@tonic-gate 30030Sstevel@tonic-gate /* 30040Sstevel@tonic-gate * During reconfig, joinset can happen without 30050Sstevel@tonic-gate * locking first. Turn off reconfig flag before calling 30060Sstevel@tonic-gate * joinset. 30070Sstevel@tonic-gate */ 30080Sstevel@tonic-gate if (!(args->flags & MNSET_IN_RECONFIG)) { 30090Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 30100Sstevel@tonic-gate return (TRUE); 30110Sstevel@tonic-gate } 30120Sstevel@tonic-gate 30130Sstevel@tonic-gate /* doit */ 30140Sstevel@tonic-gate joinset(args->sp, args->flags, ep); 30150Sstevel@tonic-gate 30160Sstevel@tonic-gate err = svc_fini(ep); 30170Sstevel@tonic-gate 30180Sstevel@tonic-gate return (TRUE); 30190Sstevel@tonic-gate } 30200Sstevel@tonic-gate 30210Sstevel@tonic-gate bool_t 30220Sstevel@tonic-gate mdrpc_joinset_2_svc( 30230Sstevel@tonic-gate mdrpc_sp_flags_2_args *args, 30240Sstevel@tonic-gate mdrpc_generic_res *res, 30250Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 30260Sstevel@tonic-gate ) 30270Sstevel@tonic-gate { 30280Sstevel@tonic-gate switch (args->rev) { 30290Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 30300Sstevel@tonic-gate return (mdrpc_joinset_common( 30310Sstevel@tonic-gate &args->mdrpc_sp_flags_2_args_u.rev1, res, rqstp)); 30320Sstevel@tonic-gate default: 30330Sstevel@tonic-gate return (FALSE); 30340Sstevel@tonic-gate } 30350Sstevel@tonic-gate } 30360Sstevel@tonic-gate 30370Sstevel@tonic-gate static void 30380Sstevel@tonic-gate withdrawset( 30390Sstevel@tonic-gate mdsetname_t *sp, 30400Sstevel@tonic-gate md_error_t *ep 30410Sstevel@tonic-gate ) 30420Sstevel@tonic-gate { 30430Sstevel@tonic-gate mdsetname_t *my_sp; 30440Sstevel@tonic-gate 30450Sstevel@tonic-gate if ((my_sp = metasetname(sp->setname, ep)) == NULL) 30460Sstevel@tonic-gate return; 30470Sstevel@tonic-gate 30480Sstevel@tonic-gate (void) halt_set(my_sp, ep); 30490Sstevel@tonic-gate } 30500Sstevel@tonic-gate 30510Sstevel@tonic-gate /* 30520Sstevel@tonic-gate * Have this node withdraw from set. 30530Sstevel@tonic-gate * In response to a failure that occurred 30540Sstevel@tonic-gate * on the client after a joinset. 30550Sstevel@tonic-gate */ 30560Sstevel@tonic-gate bool_t 30570Sstevel@tonic-gate mdrpc_withdrawset_common( 30580Sstevel@tonic-gate mdrpc_sp_args *args, 30590Sstevel@tonic-gate mdrpc_generic_res *res, 30600Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 30610Sstevel@tonic-gate ) 30620Sstevel@tonic-gate { 30630Sstevel@tonic-gate md_error_t *ep = &res->status; 30640Sstevel@tonic-gate int err; 30650Sstevel@tonic-gate int op_mode = W_OK; 30660Sstevel@tonic-gate 30670Sstevel@tonic-gate /* setup, check permissions */ 30680Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 30690Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 30700Sstevel@tonic-gate return (FALSE); 30710Sstevel@tonic-gate else if (err != 0) 30720Sstevel@tonic-gate return (TRUE); 30730Sstevel@tonic-gate 30740Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 30750Sstevel@tonic-gate return (TRUE); 30760Sstevel@tonic-gate 30770Sstevel@tonic-gate /* doit */ 30780Sstevel@tonic-gate withdrawset(args->sp, ep); 30790Sstevel@tonic-gate 30800Sstevel@tonic-gate err = svc_fini(ep); 30810Sstevel@tonic-gate 30820Sstevel@tonic-gate return (TRUE); 30830Sstevel@tonic-gate } 30840Sstevel@tonic-gate 30850Sstevel@tonic-gate bool_t 30860Sstevel@tonic-gate mdrpc_withdrawset_2_svc( 30870Sstevel@tonic-gate mdrpc_sp_2_args *args, 30880Sstevel@tonic-gate mdrpc_generic_res *res, 30890Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 30900Sstevel@tonic-gate ) 30910Sstevel@tonic-gate { 30920Sstevel@tonic-gate switch (args->rev) { 30930Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 30940Sstevel@tonic-gate return (mdrpc_withdrawset_common( 30950Sstevel@tonic-gate &args->mdrpc_sp_2_args_u.rev1, res, rqstp)); 30960Sstevel@tonic-gate default: 30970Sstevel@tonic-gate return (FALSE); 30980Sstevel@tonic-gate } 30990Sstevel@tonic-gate } 31000Sstevel@tonic-gate 31010Sstevel@tonic-gate static mhd_mhiargs_t * 31020Sstevel@tonic-gate gtimeout(mdsetname_t *sp, md_error_t *ep) 31030Sstevel@tonic-gate { 31040Sstevel@tonic-gate md_set_record *sr; 31050Sstevel@tonic-gate mhd_mhiargs_t *mhiargs; 31060Sstevel@tonic-gate 31070Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 31080Sstevel@tonic-gate return (NULL); 31090Sstevel@tonic-gate 31100Sstevel@tonic-gate mhiargs = Zalloc(sizeof (*mhiargs)); 31110Sstevel@tonic-gate *mhiargs = sr->sr_mhiargs; 31120Sstevel@tonic-gate 31130Sstevel@tonic-gate free_sr(sr); 31140Sstevel@tonic-gate return (mhiargs); 31150Sstevel@tonic-gate } 31160Sstevel@tonic-gate 31170Sstevel@tonic-gate /* 31180Sstevel@tonic-gate * Get the MH timeout values for this set. 31190Sstevel@tonic-gate */ 31200Sstevel@tonic-gate bool_t 31210Sstevel@tonic-gate mdrpc_gtimeout_common( 31220Sstevel@tonic-gate mdrpc_sp_args *args, 31230Sstevel@tonic-gate mdrpc_gtimeout_res *res, 31240Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 31250Sstevel@tonic-gate ) 31260Sstevel@tonic-gate { 31270Sstevel@tonic-gate md_error_t *ep = &res->status; 31280Sstevel@tonic-gate int err; 31290Sstevel@tonic-gate int op_mode = R_OK; 31300Sstevel@tonic-gate 31310Sstevel@tonic-gate /* setup, check permissions */ 31320Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 31330Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 31340Sstevel@tonic-gate return (FALSE); 31350Sstevel@tonic-gate else if (err != 0) 31360Sstevel@tonic-gate return (TRUE); 31370Sstevel@tonic-gate 31380Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 31390Sstevel@tonic-gate return (TRUE); 31400Sstevel@tonic-gate 31410Sstevel@tonic-gate /* doit */ 31420Sstevel@tonic-gate res->mhiargsp = gtimeout(args->sp, ep); 31430Sstevel@tonic-gate 31440Sstevel@tonic-gate err = svc_fini(ep); 31450Sstevel@tonic-gate 31460Sstevel@tonic-gate return (TRUE); 31470Sstevel@tonic-gate } 31480Sstevel@tonic-gate 31490Sstevel@tonic-gate bool_t 31500Sstevel@tonic-gate mdrpc_gtimeout_1_svc( 31510Sstevel@tonic-gate mdrpc_sp_args *args, 31520Sstevel@tonic-gate mdrpc_gtimeout_res *res, 31530Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 31540Sstevel@tonic-gate ) 31550Sstevel@tonic-gate { 31560Sstevel@tonic-gate return (mdrpc_gtimeout_common(args, res, rqstp)); 31570Sstevel@tonic-gate } 31580Sstevel@tonic-gate 31590Sstevel@tonic-gate bool_t 31600Sstevel@tonic-gate mdrpc_gtimeout_2_svc( 31610Sstevel@tonic-gate mdrpc_sp_2_args *args, 31620Sstevel@tonic-gate mdrpc_gtimeout_res *res, 31630Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 31640Sstevel@tonic-gate ) 31650Sstevel@tonic-gate { 31660Sstevel@tonic-gate switch (args->rev) { 31670Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 31680Sstevel@tonic-gate return (mdrpc_gtimeout_common( 31690Sstevel@tonic-gate &args->mdrpc_sp_2_args_u.rev1, res, rqstp)); 31700Sstevel@tonic-gate default: 31710Sstevel@tonic-gate return (FALSE); 31720Sstevel@tonic-gate } 31730Sstevel@tonic-gate } 31740Sstevel@tonic-gate 31750Sstevel@tonic-gate /* 31760Sstevel@tonic-gate * return the official host name for the callee 31770Sstevel@tonic-gate */ 31780Sstevel@tonic-gate /*ARGSUSED*/ 31790Sstevel@tonic-gate bool_t 31800Sstevel@tonic-gate mdrpc_hostname_common( 31810Sstevel@tonic-gate mdrpc_null_args *args, 31820Sstevel@tonic-gate mdrpc_hostname_res *res, 31830Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 31840Sstevel@tonic-gate ) 31850Sstevel@tonic-gate { 31860Sstevel@tonic-gate md_error_t *ep = &res->status; 31870Sstevel@tonic-gate int err; 31880Sstevel@tonic-gate int op_mode = R_OK; 31890Sstevel@tonic-gate 31900Sstevel@tonic-gate /* setup, check permissions */ 31910Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 31920Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 31930Sstevel@tonic-gate return (FALSE); 31940Sstevel@tonic-gate else if (err != 0) 31950Sstevel@tonic-gate return (TRUE); 31960Sstevel@tonic-gate 31970Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 31980Sstevel@tonic-gate return (TRUE); 31990Sstevel@tonic-gate 32000Sstevel@tonic-gate /* doit */ 32010Sstevel@tonic-gate res->hostname = Strdup(mynode()); 32020Sstevel@tonic-gate 32030Sstevel@tonic-gate err = svc_fini(ep); 32040Sstevel@tonic-gate 32050Sstevel@tonic-gate return (TRUE); 32060Sstevel@tonic-gate } 32070Sstevel@tonic-gate 32080Sstevel@tonic-gate bool_t 32090Sstevel@tonic-gate mdrpc_hostname_1_svc( 32100Sstevel@tonic-gate mdrpc_null_args *args, 32110Sstevel@tonic-gate mdrpc_hostname_res *res, 32120Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 32130Sstevel@tonic-gate ) 32140Sstevel@tonic-gate { 32150Sstevel@tonic-gate return (mdrpc_hostname_common(args, res, rqstp)); 32160Sstevel@tonic-gate } 32170Sstevel@tonic-gate 32180Sstevel@tonic-gate bool_t 32190Sstevel@tonic-gate mdrpc_hostname_2_svc( 32200Sstevel@tonic-gate mdrpc_null_args *args, 32210Sstevel@tonic-gate mdrpc_hostname_res *res, 32220Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 32230Sstevel@tonic-gate ) 32240Sstevel@tonic-gate { 32250Sstevel@tonic-gate return (mdrpc_hostname_common(args, res, rqstp)); 32260Sstevel@tonic-gate } 32270Sstevel@tonic-gate 32280Sstevel@tonic-gate /* 32290Sstevel@tonic-gate * return a response 32300Sstevel@tonic-gate */ 32310Sstevel@tonic-gate /*ARGSUSED*/ 32320Sstevel@tonic-gate bool_t 32330Sstevel@tonic-gate mdrpc_nullproc_common( 32340Sstevel@tonic-gate void *args, 32350Sstevel@tonic-gate md_error_t *ep, 32360Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 32370Sstevel@tonic-gate ) 32380Sstevel@tonic-gate { 32390Sstevel@tonic-gate *ep = mdnullerror; 32400Sstevel@tonic-gate /* do nothing */ 32410Sstevel@tonic-gate return (TRUE); 32420Sstevel@tonic-gate } 32430Sstevel@tonic-gate 32440Sstevel@tonic-gate bool_t 32450Sstevel@tonic-gate mdrpc_nullproc_1_svc( 32460Sstevel@tonic-gate void *args, 32470Sstevel@tonic-gate md_error_t *ep, 32480Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 32490Sstevel@tonic-gate ) 32500Sstevel@tonic-gate { 32510Sstevel@tonic-gate return (mdrpc_nullproc_common(args, ep, rqstp)); 32520Sstevel@tonic-gate } 32530Sstevel@tonic-gate 32540Sstevel@tonic-gate bool_t 32550Sstevel@tonic-gate mdrpc_nullproc_2_svc( 32560Sstevel@tonic-gate void *args, 32570Sstevel@tonic-gate md_error_t *ep, 32580Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 32590Sstevel@tonic-gate ) 32600Sstevel@tonic-gate { 32610Sstevel@tonic-gate return (mdrpc_nullproc_common(args, ep, rqstp)); 32620Sstevel@tonic-gate } 32630Sstevel@tonic-gate 32640Sstevel@tonic-gate /* 32650Sstevel@tonic-gate * determine if the caller owns the set. 32660Sstevel@tonic-gate */ 32670Sstevel@tonic-gate bool_t 32680Sstevel@tonic-gate mdrpc_ownset_common( 32690Sstevel@tonic-gate mdrpc_sp_args *args, 32700Sstevel@tonic-gate mdrpc_bool_res *res, 32710Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 32720Sstevel@tonic-gate ) 32730Sstevel@tonic-gate { 32740Sstevel@tonic-gate md_error_t *ep = &res->status; 32750Sstevel@tonic-gate int err; 32760Sstevel@tonic-gate int op_mode = R_OK; 32770Sstevel@tonic-gate 32780Sstevel@tonic-gate /* setup, check permissions */ 32790Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 32800Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 32810Sstevel@tonic-gate return (FALSE); 32820Sstevel@tonic-gate else if (err != 0) 32830Sstevel@tonic-gate return (TRUE); 32840Sstevel@tonic-gate 32850Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 32860Sstevel@tonic-gate return (TRUE); 32870Sstevel@tonic-gate 32880Sstevel@tonic-gate /* doit */ 32890Sstevel@tonic-gate if (s_ownset(args->sp->setno, ep)) 32900Sstevel@tonic-gate res->value = TRUE; 32910Sstevel@tonic-gate else 32920Sstevel@tonic-gate res->value = FALSE; 32930Sstevel@tonic-gate 32940Sstevel@tonic-gate err = svc_fini(ep); 32950Sstevel@tonic-gate 32960Sstevel@tonic-gate return (TRUE); 32970Sstevel@tonic-gate } 32980Sstevel@tonic-gate 32990Sstevel@tonic-gate bool_t 33000Sstevel@tonic-gate mdrpc_ownset_1_svc( 33010Sstevel@tonic-gate mdrpc_sp_args *args, 33020Sstevel@tonic-gate mdrpc_bool_res *res, 33030Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 33040Sstevel@tonic-gate ) 33050Sstevel@tonic-gate { 33060Sstevel@tonic-gate return (mdrpc_ownset_common(args, res, rqstp)); 33070Sstevel@tonic-gate } 33080Sstevel@tonic-gate 33090Sstevel@tonic-gate bool_t 33100Sstevel@tonic-gate mdrpc_ownset_2_svc( 33110Sstevel@tonic-gate mdrpc_sp_2_args *args, 33120Sstevel@tonic-gate mdrpc_bool_res *res, 33130Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 33140Sstevel@tonic-gate ) 33150Sstevel@tonic-gate { 33160Sstevel@tonic-gate switch (args->rev) { 33170Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 33180Sstevel@tonic-gate return (mdrpc_ownset_common( 33190Sstevel@tonic-gate &args->mdrpc_sp_2_args_u.rev1, res, rqstp)); 33200Sstevel@tonic-gate default: 33210Sstevel@tonic-gate return (FALSE); 33220Sstevel@tonic-gate } 33230Sstevel@tonic-gate } 33240Sstevel@tonic-gate 33250Sstevel@tonic-gate static int 33260Sstevel@tonic-gate setnameok(char *setname, md_error_t *ep) 33270Sstevel@tonic-gate { 33280Sstevel@tonic-gate int rval = 0; 33290Sstevel@tonic-gate struct stat statb; 33300Sstevel@tonic-gate md_set_record *sr = NULL; 33310Sstevel@tonic-gate char *setlink = NULL; 33320Sstevel@tonic-gate 33330Sstevel@tonic-gate setlink = Strdup("/dev/md/"); 33340Sstevel@tonic-gate setlink = Realloc(setlink, strlen(setlink) + strlen(setname) + 1); 33350Sstevel@tonic-gate (void) strcat(setlink, setname); 33360Sstevel@tonic-gate 33370Sstevel@tonic-gate if (lstat(setlink, &statb) == -1) { 33380Sstevel@tonic-gate /* 33390Sstevel@tonic-gate * If lstat() fails with ENOENT, setname is OK, if it 33400Sstevel@tonic-gate * fails for other than that, we fail the RPC 33410Sstevel@tonic-gate */ 33420Sstevel@tonic-gate if (errno == ENOENT) { 33430Sstevel@tonic-gate rval = 1; 33440Sstevel@tonic-gate goto out; 33450Sstevel@tonic-gate } 33460Sstevel@tonic-gate 33470Sstevel@tonic-gate (void) mdsyserror(ep, errno, setlink); 33480Sstevel@tonic-gate goto out; 33490Sstevel@tonic-gate } 33500Sstevel@tonic-gate 33510Sstevel@tonic-gate /* 33520Sstevel@tonic-gate * If the lstat() succeeded, then we see what type of object 33530Sstevel@tonic-gate * we are dealing with, if it is a symlink, we do some further 33540Sstevel@tonic-gate * checking, if it is not a symlink, then we return an 33550Sstevel@tonic-gate * indication that the set name is NOT acceptable. 33560Sstevel@tonic-gate */ 33570Sstevel@tonic-gate if (! S_ISLNK(statb.st_mode)) 33580Sstevel@tonic-gate goto out; 33590Sstevel@tonic-gate 33600Sstevel@tonic-gate /* 33610Sstevel@tonic-gate * We look up the setname to see if there is a set 33620Sstevel@tonic-gate * with that name, if there is, then we return 33630Sstevel@tonic-gate * an indication that the set name is NOT acceptable. 33640Sstevel@tonic-gate */ 33650Sstevel@tonic-gate if ((sr = getsetbyname(setname, ep)) != NULL) 33660Sstevel@tonic-gate goto out; 33670Sstevel@tonic-gate 33680Sstevel@tonic-gate if (! mdiserror(ep, MDE_NO_SET)) 33690Sstevel@tonic-gate goto out; 33700Sstevel@tonic-gate 33710Sstevel@tonic-gate mdclrerror(ep); 33720Sstevel@tonic-gate 33730Sstevel@tonic-gate rval = 1; 33740Sstevel@tonic-gate out: 33750Sstevel@tonic-gate if (sr != NULL) 33760Sstevel@tonic-gate free_sr(sr); 33770Sstevel@tonic-gate Free(setlink); 33780Sstevel@tonic-gate return (rval); 33790Sstevel@tonic-gate } 33800Sstevel@tonic-gate 33810Sstevel@tonic-gate /* 33820Sstevel@tonic-gate * Make sure the name of the set is OK. 33830Sstevel@tonic-gate */ 33840Sstevel@tonic-gate bool_t 33850Sstevel@tonic-gate mdrpc_setnameok_common( 33860Sstevel@tonic-gate mdrpc_sp_args *args, /* device name */ 33870Sstevel@tonic-gate mdrpc_bool_res *res, 33880Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 33890Sstevel@tonic-gate ) 33900Sstevel@tonic-gate { 33910Sstevel@tonic-gate md_error_t *ep = &res->status; 33920Sstevel@tonic-gate int err; 33930Sstevel@tonic-gate int op_mode = R_OK; 33940Sstevel@tonic-gate 33950Sstevel@tonic-gate /* setup, check permissions */ 33960Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 33970Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 33980Sstevel@tonic-gate return (FALSE); 33990Sstevel@tonic-gate else if (err != 0) 34000Sstevel@tonic-gate return (TRUE); 34010Sstevel@tonic-gate 34020Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 34030Sstevel@tonic-gate return (TRUE); 34040Sstevel@tonic-gate 34050Sstevel@tonic-gate /* doit */ 34060Sstevel@tonic-gate res->value = setnameok(args->sp->setname, ep); 34070Sstevel@tonic-gate 34080Sstevel@tonic-gate err = svc_fini(ep); 34090Sstevel@tonic-gate 34100Sstevel@tonic-gate return (TRUE); 34110Sstevel@tonic-gate } 34120Sstevel@tonic-gate 34130Sstevel@tonic-gate bool_t 34140Sstevel@tonic-gate mdrpc_setnameok_1_svc( 34150Sstevel@tonic-gate mdrpc_sp_args *args, /* device name */ 34160Sstevel@tonic-gate mdrpc_bool_res *res, 34170Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 34180Sstevel@tonic-gate ) 34190Sstevel@tonic-gate { 34200Sstevel@tonic-gate return (mdrpc_setnameok_common(args, res, rqstp)); 34210Sstevel@tonic-gate } 34220Sstevel@tonic-gate 34230Sstevel@tonic-gate bool_t 34240Sstevel@tonic-gate mdrpc_setnameok_2_svc( 34250Sstevel@tonic-gate mdrpc_sp_2_args *args, /* device name */ 34260Sstevel@tonic-gate mdrpc_bool_res *res, 34270Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 34280Sstevel@tonic-gate ) 34290Sstevel@tonic-gate { 34300Sstevel@tonic-gate switch (args->rev) { 34310Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 34320Sstevel@tonic-gate return (mdrpc_setnameok_common( 34330Sstevel@tonic-gate &args->mdrpc_sp_2_args_u.rev1, res, rqstp)); 34340Sstevel@tonic-gate default: 34350Sstevel@tonic-gate return (FALSE); 34360Sstevel@tonic-gate } 34370Sstevel@tonic-gate } 34380Sstevel@tonic-gate 34390Sstevel@tonic-gate /* 34400Sstevel@tonic-gate * determine if the setnumber we want to share is in use. 34410Sstevel@tonic-gate */ 34420Sstevel@tonic-gate bool_t 34430Sstevel@tonic-gate mdrpc_setnumbusy_common( 34440Sstevel@tonic-gate mdrpc_setno_args *args, 34450Sstevel@tonic-gate mdrpc_bool_res *res, 34460Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 34470Sstevel@tonic-gate ) 34480Sstevel@tonic-gate { 34490Sstevel@tonic-gate md_error_t *ep = &res->status; 34500Sstevel@tonic-gate md_set_record *sr = NULL; 34510Sstevel@tonic-gate int err; 34520Sstevel@tonic-gate int op_mode = R_OK; 34530Sstevel@tonic-gate 34540Sstevel@tonic-gate /* setup, check permissions */ 34550Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 34560Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 34570Sstevel@tonic-gate return (FALSE); 34580Sstevel@tonic-gate else if (err != 0) 34590Sstevel@tonic-gate return (TRUE); 34600Sstevel@tonic-gate 34610Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 34620Sstevel@tonic-gate return (TRUE); 34630Sstevel@tonic-gate 34640Sstevel@tonic-gate /* doit */ 34650Sstevel@tonic-gate if ((sr = getsetbynum(args->setno, ep)) != NULL) { 34660Sstevel@tonic-gate res->value = TRUE; 34670Sstevel@tonic-gate free_sr(sr); 34680Sstevel@tonic-gate return (TRUE); 34690Sstevel@tonic-gate } 34700Sstevel@tonic-gate res->value = FALSE; 34710Sstevel@tonic-gate if (mdiserror(ep, MDE_NO_SET)) 34720Sstevel@tonic-gate mdclrerror(ep); 34730Sstevel@tonic-gate 34740Sstevel@tonic-gate err = svc_fini(ep); 34750Sstevel@tonic-gate 34760Sstevel@tonic-gate return (TRUE); 34770Sstevel@tonic-gate } 34780Sstevel@tonic-gate 34790Sstevel@tonic-gate bool_t 34800Sstevel@tonic-gate mdrpc_setnumbusy_1_svc( 34810Sstevel@tonic-gate mdrpc_setno_args *args, 34820Sstevel@tonic-gate mdrpc_bool_res *res, 34830Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 34840Sstevel@tonic-gate ) 34850Sstevel@tonic-gate { 34860Sstevel@tonic-gate return (mdrpc_setnumbusy_common(args, res, rqstp)); 34870Sstevel@tonic-gate } 34880Sstevel@tonic-gate 34890Sstevel@tonic-gate bool_t 34900Sstevel@tonic-gate mdrpc_setnumbusy_2_svc( 34910Sstevel@tonic-gate mdrpc_setno_2_args *args, 34920Sstevel@tonic-gate mdrpc_bool_res *res, 34930Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 34940Sstevel@tonic-gate ) 34950Sstevel@tonic-gate { 34960Sstevel@tonic-gate switch (args->rev) { 34970Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 34980Sstevel@tonic-gate return (mdrpc_setnumbusy_common( 34990Sstevel@tonic-gate &args->mdrpc_setno_2_args_u.rev1, res, rqstp)); 35000Sstevel@tonic-gate default: 35010Sstevel@tonic-gate return (FALSE); 35020Sstevel@tonic-gate } 35030Sstevel@tonic-gate } 35040Sstevel@tonic-gate 35050Sstevel@tonic-gate static void 35060Sstevel@tonic-gate stimeout( 35070Sstevel@tonic-gate mdsetname_t *sp, 35080Sstevel@tonic-gate mhd_mhiargs_t *mhiargsp, 35090Sstevel@tonic-gate int version, /* RPC version of calling routine */ 35100Sstevel@tonic-gate md_error_t *ep 35110Sstevel@tonic-gate ) 35120Sstevel@tonic-gate { 35130Sstevel@tonic-gate mddb_userreq_t req; 35140Sstevel@tonic-gate md_set_record *sr; 35150Sstevel@tonic-gate 35160Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 35170Sstevel@tonic-gate return; 35180Sstevel@tonic-gate 35190Sstevel@tonic-gate sr->sr_mhiargs = *mhiargsp; 35200Sstevel@tonic-gate 35210Sstevel@tonic-gate (void) memset(&req, '\0', sizeof (req)); 35220Sstevel@tonic-gate 35230Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_SETDATA, sr->sr_selfid) 35240Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 35250Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 35260Sstevel@tonic-gate req.ur_size = sizeof (struct md_mnset_record); 35270Sstevel@tonic-gate } else { 35280Sstevel@tonic-gate req.ur_size = sizeof (*sr); 35290Sstevel@tonic-gate } 35300Sstevel@tonic-gate req.ur_data = (uintptr_t)sr; 35310Sstevel@tonic-gate 35320Sstevel@tonic-gate /* 35330Sstevel@tonic-gate * Cluster nodename support 35340Sstevel@tonic-gate * Convert nodename -> nodeid 35350Sstevel@tonic-gate * Don't do this for MN disksets since we've already stored 35360Sstevel@tonic-gate * both the nodeid and name. 35370Sstevel@tonic-gate */ 35380Sstevel@tonic-gate if ((version == METAD_VERSION) || 35390Sstevel@tonic-gate ((version == METAD_VERSION_DEVID) && (!(MD_MNSET_REC(sr))))) 35400Sstevel@tonic-gate sdssc_cm_sr_nm2nid(sr); 35410Sstevel@tonic-gate 35420Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 35430Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 35440Sstevel@tonic-gate return; 35450Sstevel@tonic-gate } 35460Sstevel@tonic-gate 35470Sstevel@tonic-gate (void) memset(&req, '\0', sizeof (req)); 35480Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_COMMIT_ONE, sr->sr_selfid) 35490Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) 35500Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 35510Sstevel@tonic-gate 35520Sstevel@tonic-gate /* 35530Sstevel@tonic-gate * Cluster nodename support 35540Sstevel@tonic-gate * Convert nodeid -> nodename 35550Sstevel@tonic-gate * Don't do this for MN disksets since we've already stored 35560Sstevel@tonic-gate * both the nodeid and name. 35570Sstevel@tonic-gate */ 35580Sstevel@tonic-gate if ((version == METAD_VERSION) || 35590Sstevel@tonic-gate ((version == METAD_VERSION_DEVID) && (!(MD_MNSET_REC(sr))))) 35600Sstevel@tonic-gate sdssc_cm_sr_nid2nm(sr); 35610Sstevel@tonic-gate 35620Sstevel@tonic-gate free_sr(sr); 35630Sstevel@tonic-gate } 35640Sstevel@tonic-gate 35650Sstevel@tonic-gate /* 35660Sstevel@tonic-gate * Set MH ioctl timeout values. 35670Sstevel@tonic-gate */ 35680Sstevel@tonic-gate bool_t 35690Sstevel@tonic-gate mdrpc_stimeout_common( 35700Sstevel@tonic-gate mdrpc_stimeout_args *args, 35710Sstevel@tonic-gate mdrpc_generic_res *res, 35720Sstevel@tonic-gate struct svc_req *rqstp, /* RPC stuff */ 35730Sstevel@tonic-gate int version /* RPC version */ 35740Sstevel@tonic-gate ) 35750Sstevel@tonic-gate { 35760Sstevel@tonic-gate md_error_t *ep = &res->status; 35770Sstevel@tonic-gate int err; 35780Sstevel@tonic-gate int op_mode = W_OK; 35790Sstevel@tonic-gate 35800Sstevel@tonic-gate /* setup, check permissions */ 35810Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 35820Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 35830Sstevel@tonic-gate return (FALSE); 35840Sstevel@tonic-gate else if (err != 0) 35850Sstevel@tonic-gate return (TRUE); 35860Sstevel@tonic-gate 35870Sstevel@tonic-gate if (check_set_lock(op_mode, NULL, ep)) 35880Sstevel@tonic-gate return (TRUE); 35890Sstevel@tonic-gate 35900Sstevel@tonic-gate /* doit */ 35910Sstevel@tonic-gate stimeout(args->sp, args->mhiargsp, version, ep); 35920Sstevel@tonic-gate 35930Sstevel@tonic-gate err = svc_fini(ep); 35940Sstevel@tonic-gate 35950Sstevel@tonic-gate return (TRUE); 35960Sstevel@tonic-gate } 35970Sstevel@tonic-gate 35980Sstevel@tonic-gate bool_t 35990Sstevel@tonic-gate mdrpc_stimeout_1_svc( 36000Sstevel@tonic-gate mdrpc_stimeout_args *args, 36010Sstevel@tonic-gate mdrpc_generic_res *res, 36020Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 36030Sstevel@tonic-gate ) 36040Sstevel@tonic-gate { 36050Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION) to common routine */ 36060Sstevel@tonic-gate return (mdrpc_stimeout_common(args, res, rqstp, METAD_VERSION)); 36070Sstevel@tonic-gate } 36080Sstevel@tonic-gate 36090Sstevel@tonic-gate bool_t 36100Sstevel@tonic-gate mdrpc_stimeout_2_svc( 36110Sstevel@tonic-gate mdrpc_stimeout_2_args *args, 36120Sstevel@tonic-gate mdrpc_generic_res *res, 36130Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 36140Sstevel@tonic-gate ) 36150Sstevel@tonic-gate { 36160Sstevel@tonic-gate switch (args->rev) { 36170Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 36180Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION_DEVID) to common routine */ 36190Sstevel@tonic-gate return (mdrpc_stimeout_common( 36200Sstevel@tonic-gate &args->mdrpc_stimeout_2_args_u.rev1, res, 36210Sstevel@tonic-gate rqstp, METAD_VERSION_DEVID)); 36220Sstevel@tonic-gate default: 36230Sstevel@tonic-gate return (FALSE); 36240Sstevel@tonic-gate } 36250Sstevel@tonic-gate } 36260Sstevel@tonic-gate 36270Sstevel@tonic-gate static void 36280Sstevel@tonic-gate upd_dr_dbinfo( 36290Sstevel@tonic-gate mdsetname_t *sp, 36300Sstevel@tonic-gate md_drive_desc *dd, 36310Sstevel@tonic-gate md_error_t *ep 36320Sstevel@tonic-gate ) 36330Sstevel@tonic-gate { 36340Sstevel@tonic-gate mdsetname_t *local_sp; 36350Sstevel@tonic-gate md_set_record *sr; 36360Sstevel@tonic-gate md_drive_record *dr; 36370Sstevel@tonic-gate md_drive_desc *p; 36380Sstevel@tonic-gate mddrivename_t *dn, *dn1; 36390Sstevel@tonic-gate ddi_devid_t devid_remote = NULL; 36400Sstevel@tonic-gate ddi_devid_t devid_local = NULL; 36410Sstevel@tonic-gate int devid_same = -1; 36420Sstevel@tonic-gate side_t sideno; 36430Sstevel@tonic-gate int using_devid = 0; 36440Sstevel@tonic-gate 36450Sstevel@tonic-gate if ((local_sp = metasetname(sp->setname, ep)) == NULL) 36460Sstevel@tonic-gate return; 36470Sstevel@tonic-gate 36480Sstevel@tonic-gate metaflushsetname(local_sp); 36490Sstevel@tonic-gate 36500Sstevel@tonic-gate if ((sideno = getmyside(local_sp, ep)) == MD_SIDEWILD) 36510Sstevel@tonic-gate return; 36520Sstevel@tonic-gate 36530Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 36540Sstevel@tonic-gate return; 36550Sstevel@tonic-gate 36560Sstevel@tonic-gate if (dd->dd_dnp == NULL) 36570Sstevel@tonic-gate return; 36580Sstevel@tonic-gate 36590Sstevel@tonic-gate /* 36600Sstevel@tonic-gate * The system is either all devid or all 36610Sstevel@tonic-gate * non-devid so we determine this by looking 36620Sstevel@tonic-gate * at the first item in the list. 36630Sstevel@tonic-gate * 36640Sstevel@tonic-gate * For did disks, the dd_dnp->devid is a valid pointer which 36650Sstevel@tonic-gate * points to a '' string of devid. We need to check this 36660Sstevel@tonic-gate * before set the using_devid. 36670Sstevel@tonic-gate */ 36680Sstevel@tonic-gate if ((dd->dd_dnp->devid != NULL) && (dd->dd_dnp->devid[0] != '\0') && 36690Sstevel@tonic-gate (!(MD_MNSET_REC(sr)))) 36700Sstevel@tonic-gate using_devid = 1; 36710Sstevel@tonic-gate 36720Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 36730Sstevel@tonic-gate dn = p->dd_dnp; 36740Sstevel@tonic-gate devid_remote = NULL; 36750Sstevel@tonic-gate 36760Sstevel@tonic-gate if (dn->devid != NULL && (strlen(dn->devid) != 0) && 36770Sstevel@tonic-gate using_devid) { 36780Sstevel@tonic-gate /* 36790Sstevel@tonic-gate * We have a devid so use it. 36800Sstevel@tonic-gate */ 36810Sstevel@tonic-gate (void) devid_str_decode(dn->devid, &devid_remote, NULL); 36820Sstevel@tonic-gate } 36830Sstevel@tonic-gate 36840Sstevel@tonic-gate /* check to make sure using_devid agrees with reality... */ 36850Sstevel@tonic-gate if ((using_devid == 1) && (devid_remote == NULL)) { 36860Sstevel@tonic-gate /* something went really wrong. Can't process */ 36870Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_INVALIDDEVID, sp->setno, 36880Sstevel@tonic-gate mynode(), dn->cname, sp->setname); 36890Sstevel@tonic-gate return; 36900Sstevel@tonic-gate } 36910Sstevel@tonic-gate 36920Sstevel@tonic-gate for (dr = sr->sr_drivechain; dr; dr = dr->dr_next) { 36930Sstevel@tonic-gate devid_same = -1; 36940Sstevel@tonic-gate 36950Sstevel@tonic-gate dn1 = metadrivename_withdrkey(local_sp, sideno, 36960Sstevel@tonic-gate dr->dr_key, MD_BASICNAME_OK, ep); 36970Sstevel@tonic-gate 36980Sstevel@tonic-gate if (dn1 == NULL) { 36990Sstevel@tonic-gate if (devid_remote) 37000Sstevel@tonic-gate devid_free(devid_remote); 37010Sstevel@tonic-gate goto out; 37020Sstevel@tonic-gate } 37030Sstevel@tonic-gate 37040Sstevel@tonic-gate if (dn1->devid != NULL && using_devid) { 37050Sstevel@tonic-gate if (devid_str_decode(dn1->devid, &devid_local, 37060Sstevel@tonic-gate NULL) == 0) { 37070Sstevel@tonic-gate devid_same = devid_compare(devid_remote, 37080Sstevel@tonic-gate devid_local); 37090Sstevel@tonic-gate devid_free(devid_local); 37100Sstevel@tonic-gate } 37110Sstevel@tonic-gate } 37120Sstevel@tonic-gate 37130Sstevel@tonic-gate if (using_devid && devid_same == 0) 37140Sstevel@tonic-gate break; 37150Sstevel@tonic-gate 37160Sstevel@tonic-gate if (!using_devid && 37170Sstevel@tonic-gate strcmp(dn->cname, dn1->cname) == 0) 37180Sstevel@tonic-gate break; 37190Sstevel@tonic-gate } 37200Sstevel@tonic-gate 37210Sstevel@tonic-gate if (dr) { 37220Sstevel@tonic-gate /* Adjust the fields in the copy */ 37230Sstevel@tonic-gate dr->dr_dbcnt = p->dd_dbcnt; 37240Sstevel@tonic-gate dr->dr_dbsize = p->dd_dbsize; 37250Sstevel@tonic-gate } 37260Sstevel@tonic-gate if (devid_remote) 37270Sstevel@tonic-gate devid_free(devid_remote); 37280Sstevel@tonic-gate } 37290Sstevel@tonic-gate 37300Sstevel@tonic-gate 37310Sstevel@tonic-gate out: 37320Sstevel@tonic-gate commitset(sr, FALSE, ep); 37330Sstevel@tonic-gate free_sr(sr); 37340Sstevel@tonic-gate } 37350Sstevel@tonic-gate 37360Sstevel@tonic-gate /* 37370Sstevel@tonic-gate * update the database count and size field of drive records. 37380Sstevel@tonic-gate */ 37390Sstevel@tonic-gate bool_t 37400Sstevel@tonic-gate mdrpc_upd_dr_dbinfo_common( 37410Sstevel@tonic-gate mdrpc_drives_2_args_r1 *args, 37420Sstevel@tonic-gate mdrpc_generic_res *res, 37430Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 37440Sstevel@tonic-gate ) 37450Sstevel@tonic-gate { 37460Sstevel@tonic-gate md_error_t *ep = &res->status; 37470Sstevel@tonic-gate int err; 37480Sstevel@tonic-gate int op_mode = W_OK; 37490Sstevel@tonic-gate 37500Sstevel@tonic-gate /* setup, check permissions */ 37510Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 37520Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 37530Sstevel@tonic-gate return (FALSE); 37540Sstevel@tonic-gate else if (err != 0) 37550Sstevel@tonic-gate return (TRUE); 37560Sstevel@tonic-gate 37570Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 37580Sstevel@tonic-gate return (TRUE); 37590Sstevel@tonic-gate 37600Sstevel@tonic-gate /* doit */ 37610Sstevel@tonic-gate upd_dr_dbinfo(args->sp, args->drivedescs, ep); 37620Sstevel@tonic-gate 37630Sstevel@tonic-gate err = svc_fini(ep); 37640Sstevel@tonic-gate 37650Sstevel@tonic-gate return (TRUE); 37660Sstevel@tonic-gate } 37670Sstevel@tonic-gate 37680Sstevel@tonic-gate /* 37690Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 37700Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 37710Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 37720Sstevel@tonic-gate */ 37730Sstevel@tonic-gate bool_t 37740Sstevel@tonic-gate mdrpc_upd_dr_dbinfo_1_svc( 37750Sstevel@tonic-gate mdrpc_drives_args *args, 37760Sstevel@tonic-gate mdrpc_generic_res *res, 37770Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 37780Sstevel@tonic-gate ) 37790Sstevel@tonic-gate { 37800Sstevel@tonic-gate bool_t retval; 37810Sstevel@tonic-gate mdrpc_drives_2_args_r1 v2_args; 37820Sstevel@tonic-gate 37830Sstevel@tonic-gate /* allocate memory */ 37840Sstevel@tonic-gate alloc_newdrvdesc(args->drivedescs, &v2_args.drivedescs); 37850Sstevel@tonic-gate 37860Sstevel@tonic-gate /* build args */ 37870Sstevel@tonic-gate v2_args.cl_sk = args->cl_sk; 37880Sstevel@tonic-gate v2_args.sp = args->sp; 37890Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 37900Sstevel@tonic-gate meta_conv_drvdesc_old2new(args->drivedescs, v2_args.drivedescs); 37910Sstevel@tonic-gate v2_args.timestamp = args->timestamp; 37920Sstevel@tonic-gate v2_args.genid = args->genid; 37930Sstevel@tonic-gate 37940Sstevel@tonic-gate retval = mdrpc_upd_dr_dbinfo_common(&v2_args, res, rqstp); 37950Sstevel@tonic-gate 37960Sstevel@tonic-gate free_newdrvdesc(v2_args.drivedescs); 37970Sstevel@tonic-gate 37980Sstevel@tonic-gate return (retval); 37990Sstevel@tonic-gate } 38000Sstevel@tonic-gate 38010Sstevel@tonic-gate bool_t 38020Sstevel@tonic-gate mdrpc_upd_dr_dbinfo_2_svc( 38030Sstevel@tonic-gate mdrpc_drives_2_args *args, 38040Sstevel@tonic-gate mdrpc_generic_res *res, 38050Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 38060Sstevel@tonic-gate ) 38070Sstevel@tonic-gate { 38080Sstevel@tonic-gate switch (args->rev) { 38090Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 38100Sstevel@tonic-gate return (mdrpc_upd_dr_dbinfo_common( 38110Sstevel@tonic-gate &args->mdrpc_drives_2_args_u.rev1, res, rqstp)); 38120Sstevel@tonic-gate default: 38130Sstevel@tonic-gate return (FALSE); 38140Sstevel@tonic-gate } 38150Sstevel@tonic-gate } 38160Sstevel@tonic-gate 38170Sstevel@tonic-gate static void 38180Sstevel@tonic-gate upd_dr_flags( 38190Sstevel@tonic-gate mdsetname_t *sp, 38200Sstevel@tonic-gate md_drive_desc *dd, 38210Sstevel@tonic-gate uint_t new_flags, 38220Sstevel@tonic-gate md_error_t *ep 38230Sstevel@tonic-gate ) 38240Sstevel@tonic-gate { 38250Sstevel@tonic-gate mdsetname_t *local_sp; 38260Sstevel@tonic-gate md_set_record *sr; 38270Sstevel@tonic-gate md_drive_record *dr; 38280Sstevel@tonic-gate md_drive_desc *p; 38290Sstevel@tonic-gate mddrivename_t *dn, *dn1; 38300Sstevel@tonic-gate ddi_devid_t devid_remote = NULL; 38310Sstevel@tonic-gate ddi_devid_t devid_local = NULL; 38320Sstevel@tonic-gate int devid_same = -1; 38330Sstevel@tonic-gate side_t sideno; 38340Sstevel@tonic-gate int using_devid = 0; 38350Sstevel@tonic-gate 38360Sstevel@tonic-gate if ((local_sp = metasetname(sp->setname, ep)) == NULL) 38370Sstevel@tonic-gate return; 38380Sstevel@tonic-gate 38390Sstevel@tonic-gate metaflushsetname(local_sp); 38400Sstevel@tonic-gate 38410Sstevel@tonic-gate if ((sideno = getmyside(local_sp, ep)) == MD_SIDEWILD) 38420Sstevel@tonic-gate return; 38430Sstevel@tonic-gate 38440Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 38450Sstevel@tonic-gate return; 38460Sstevel@tonic-gate 38470Sstevel@tonic-gate if (dd->dd_dnp == NULL) 38480Sstevel@tonic-gate return; 38490Sstevel@tonic-gate 38500Sstevel@tonic-gate /* 38510Sstevel@tonic-gate * The system is either all devid or all 38520Sstevel@tonic-gate * non-devid so we determine this by looking 38530Sstevel@tonic-gate * at the first item in the list. 38540Sstevel@tonic-gate * 38550Sstevel@tonic-gate * For did disks, the dd_dnp->devid is a valid pointer which 38560Sstevel@tonic-gate * points to a '' string of devid. We need to check this 38570Sstevel@tonic-gate * before set the using_devid. 38580Sstevel@tonic-gate */ 38590Sstevel@tonic-gate if ((dd->dd_dnp->devid != NULL) && (dd->dd_dnp->devid[0] != '\0') && 38600Sstevel@tonic-gate (!(MD_MNSET_REC(sr)))) 38610Sstevel@tonic-gate using_devid = 1; 38620Sstevel@tonic-gate 38630Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 38640Sstevel@tonic-gate dn = p->dd_dnp; 38650Sstevel@tonic-gate devid_remote = NULL; 38660Sstevel@tonic-gate 38670Sstevel@tonic-gate if (dn->devid != NULL && (strlen(dn->devid) != 0) && 38680Sstevel@tonic-gate using_devid) { 38690Sstevel@tonic-gate /* 38700Sstevel@tonic-gate * We have a devid so use it. 38710Sstevel@tonic-gate */ 38720Sstevel@tonic-gate (void) devid_str_decode(dn->devid, &devid_remote, NULL); 38730Sstevel@tonic-gate } 38740Sstevel@tonic-gate 38750Sstevel@tonic-gate /* check to make sure using_devid agrees with reality... */ 38760Sstevel@tonic-gate if ((using_devid == 1) && (devid_remote == NULL)) { 38770Sstevel@tonic-gate /* something went really wrong. Can't process */ 38780Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_INVALIDDEVID, sp->setno, 38790Sstevel@tonic-gate mynode(), dn->cname, sp->setname); 38800Sstevel@tonic-gate return; 38810Sstevel@tonic-gate } 38820Sstevel@tonic-gate 38830Sstevel@tonic-gate for (dr = sr->sr_drivechain; dr; dr = dr->dr_next) { 38840Sstevel@tonic-gate devid_same = -1; 38850Sstevel@tonic-gate 38860Sstevel@tonic-gate dn1 = metadrivename_withdrkey(local_sp, sideno, 38870Sstevel@tonic-gate dr->dr_key, MD_BASICNAME_OK, ep); 38880Sstevel@tonic-gate 38890Sstevel@tonic-gate if (dn1 == NULL) { 38900Sstevel@tonic-gate if (devid_remote) 38910Sstevel@tonic-gate devid_free(devid_remote); 38920Sstevel@tonic-gate goto out; 38930Sstevel@tonic-gate } 38940Sstevel@tonic-gate 38950Sstevel@tonic-gate if (dn1->devid != NULL && using_devid) { 38960Sstevel@tonic-gate if (devid_str_decode(dn1->devid, 38970Sstevel@tonic-gate &devid_local, NULL) == 0) { 38980Sstevel@tonic-gate devid_same = devid_compare(devid_remote, 38990Sstevel@tonic-gate devid_local); 39000Sstevel@tonic-gate devid_free(devid_local); 39010Sstevel@tonic-gate } 39020Sstevel@tonic-gate } 39030Sstevel@tonic-gate 39040Sstevel@tonic-gate if (using_devid && devid_same == 0) 39050Sstevel@tonic-gate break; 39060Sstevel@tonic-gate 39070Sstevel@tonic-gate if (!using_devid && 39080Sstevel@tonic-gate strcmp(dn->cname, dn1->cname) == 0) 39090Sstevel@tonic-gate break; 39100Sstevel@tonic-gate } 39110Sstevel@tonic-gate 39120Sstevel@tonic-gate if (dr) 39130Sstevel@tonic-gate dr->dr_flags = new_flags; 39140Sstevel@tonic-gate if (devid_remote) 39150Sstevel@tonic-gate devid_free(devid_remote); 39160Sstevel@tonic-gate } 39170Sstevel@tonic-gate out: 39180Sstevel@tonic-gate commitset(sr, TRUE, ep); 39190Sstevel@tonic-gate free_sr(sr); 39200Sstevel@tonic-gate } 39210Sstevel@tonic-gate 39220Sstevel@tonic-gate /* 39230Sstevel@tonic-gate * update the database count and size field of drive records. 39240Sstevel@tonic-gate */ 39250Sstevel@tonic-gate bool_t 39260Sstevel@tonic-gate mdrpc_upd_dr_flags_common( 39270Sstevel@tonic-gate mdrpc_upd_dr_flags_2_args_r1 *args, 39280Sstevel@tonic-gate mdrpc_generic_res *res, 39290Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 39300Sstevel@tonic-gate ) 39310Sstevel@tonic-gate { 39320Sstevel@tonic-gate md_error_t *ep = &res->status; 39330Sstevel@tonic-gate int err; 39340Sstevel@tonic-gate int op_mode = W_OK; 39350Sstevel@tonic-gate 39360Sstevel@tonic-gate /* setup, check permissions */ 39370Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 39380Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 39390Sstevel@tonic-gate return (FALSE); 39400Sstevel@tonic-gate else if (err != 0) 39410Sstevel@tonic-gate return (TRUE); 39420Sstevel@tonic-gate 39430Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 39440Sstevel@tonic-gate return (TRUE); 39450Sstevel@tonic-gate 39460Sstevel@tonic-gate /* doit */ 39470Sstevel@tonic-gate upd_dr_flags(args->sp, args->drivedescs, args->new_flags, ep); 39480Sstevel@tonic-gate 39490Sstevel@tonic-gate err = svc_fini(ep); 39500Sstevel@tonic-gate 39510Sstevel@tonic-gate return (TRUE); 39520Sstevel@tonic-gate } 39530Sstevel@tonic-gate 39540Sstevel@tonic-gate /* 39550Sstevel@tonic-gate * version 1 of the remote procedure. This procedure is called if the 39560Sstevel@tonic-gate * client is running in version 1. We first convert version 1 arguments 39570Sstevel@tonic-gate * into version 2 arguments and then call the common remote procedure. 39580Sstevel@tonic-gate */ 39590Sstevel@tonic-gate bool_t 39600Sstevel@tonic-gate mdrpc_upd_dr_flags_1_svc( 39610Sstevel@tonic-gate mdrpc_upd_dr_flags_args *args, 39620Sstevel@tonic-gate mdrpc_generic_res *res, 39630Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 39640Sstevel@tonic-gate ) 39650Sstevel@tonic-gate { 39660Sstevel@tonic-gate bool_t retval; 39670Sstevel@tonic-gate mdrpc_upd_dr_flags_2_args_r1 v2_args; 39680Sstevel@tonic-gate 39690Sstevel@tonic-gate /* allocate memory */ 39700Sstevel@tonic-gate alloc_newdrvdesc(args->drivedescs, &v2_args.drivedescs); 39710Sstevel@tonic-gate 39720Sstevel@tonic-gate /* build args */ 39730Sstevel@tonic-gate v2_args.cl_sk = args->cl_sk; 39740Sstevel@tonic-gate v2_args.sp = args->sp; 39750Sstevel@tonic-gate /* convert v1 args to v2 (revision 1) args */ 39760Sstevel@tonic-gate meta_conv_drvdesc_old2new(args->drivedescs, v2_args.drivedescs); 39770Sstevel@tonic-gate v2_args.new_flags = args->new_flags; 39780Sstevel@tonic-gate 39790Sstevel@tonic-gate retval = mdrpc_upd_dr_flags_common(&v2_args, res, rqstp); 39800Sstevel@tonic-gate 39810Sstevel@tonic-gate free_newdrvdesc(v2_args.drivedescs); 39820Sstevel@tonic-gate 39830Sstevel@tonic-gate return (retval); 39840Sstevel@tonic-gate } 39850Sstevel@tonic-gate 39860Sstevel@tonic-gate bool_t 39870Sstevel@tonic-gate mdrpc_upd_dr_flags_2_svc( 39880Sstevel@tonic-gate mdrpc_upd_dr_flags_2_args *args, 39890Sstevel@tonic-gate mdrpc_generic_res *res, 39900Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 39910Sstevel@tonic-gate ) 39920Sstevel@tonic-gate { 39930Sstevel@tonic-gate switch (args->rev) { 39940Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 39950Sstevel@tonic-gate return (mdrpc_upd_dr_flags_common( 39960Sstevel@tonic-gate &args->mdrpc_upd_dr_flags_2_args_u.rev1, res, rqstp)); 39970Sstevel@tonic-gate default: 39980Sstevel@tonic-gate return (FALSE); 39990Sstevel@tonic-gate } 40000Sstevel@tonic-gate } 40010Sstevel@tonic-gate 40020Sstevel@tonic-gate static void 40030Sstevel@tonic-gate upd_sr_flags( 40040Sstevel@tonic-gate mdsetname_t *sp, 40050Sstevel@tonic-gate uint_t new_flags, 40060Sstevel@tonic-gate md_error_t *ep 40070Sstevel@tonic-gate ) 40080Sstevel@tonic-gate { 40090Sstevel@tonic-gate md_set_record *sr; 40100Sstevel@tonic-gate 40110Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 40120Sstevel@tonic-gate return; 40130Sstevel@tonic-gate 40140Sstevel@tonic-gate sr->sr_flags = new_flags; 40150Sstevel@tonic-gate commitset(sr, TRUE, ep); 40160Sstevel@tonic-gate free_sr(sr); 40170Sstevel@tonic-gate } 40180Sstevel@tonic-gate 40190Sstevel@tonic-gate /* 40200Sstevel@tonic-gate * update the set record flags 40210Sstevel@tonic-gate */ 40220Sstevel@tonic-gate bool_t 40230Sstevel@tonic-gate mdrpc_upd_sr_flags_common( 40240Sstevel@tonic-gate mdrpc_upd_sr_flags_args *args, 40250Sstevel@tonic-gate mdrpc_generic_res *res, 40260Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 40270Sstevel@tonic-gate ) 40280Sstevel@tonic-gate { 40290Sstevel@tonic-gate md_error_t *ep = &res->status; 40300Sstevel@tonic-gate int err; 40310Sstevel@tonic-gate int op_mode = W_OK; 40320Sstevel@tonic-gate 40330Sstevel@tonic-gate /* setup, check permissions */ 40340Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 40350Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 40360Sstevel@tonic-gate return (FALSE); 40370Sstevel@tonic-gate else if (err != 0) 40380Sstevel@tonic-gate return (TRUE); 40390Sstevel@tonic-gate 40400Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 40410Sstevel@tonic-gate return (TRUE); 40420Sstevel@tonic-gate 40430Sstevel@tonic-gate /* doit */ 40440Sstevel@tonic-gate upd_sr_flags(args->sp, args->new_flags, ep); 40450Sstevel@tonic-gate 40460Sstevel@tonic-gate err = svc_fini(ep); 40470Sstevel@tonic-gate 40480Sstevel@tonic-gate return (TRUE); 40490Sstevel@tonic-gate } 40500Sstevel@tonic-gate 40510Sstevel@tonic-gate bool_t 40520Sstevel@tonic-gate mdrpc_upd_sr_flags_1_svc( 40530Sstevel@tonic-gate mdrpc_upd_sr_flags_args *args, 40540Sstevel@tonic-gate mdrpc_generic_res *res, 40550Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 40560Sstevel@tonic-gate ) 40570Sstevel@tonic-gate { 40580Sstevel@tonic-gate return (mdrpc_upd_sr_flags_common(args, res, rqstp)); 40590Sstevel@tonic-gate } 40600Sstevel@tonic-gate 40610Sstevel@tonic-gate bool_t 40620Sstevel@tonic-gate mdrpc_upd_sr_flags_2_svc( 40630Sstevel@tonic-gate mdrpc_upd_sr_flags_2_args *args, 40640Sstevel@tonic-gate mdrpc_generic_res *res, 40650Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 40660Sstevel@tonic-gate ) 40670Sstevel@tonic-gate { 40680Sstevel@tonic-gate switch (args->rev) { 40690Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 40700Sstevel@tonic-gate return (mdrpc_upd_sr_flags_common( 40710Sstevel@tonic-gate &args->mdrpc_upd_sr_flags_2_args_u.rev1, res, rqstp)); 40720Sstevel@tonic-gate default: 40730Sstevel@tonic-gate return (FALSE); 40740Sstevel@tonic-gate } 40750Sstevel@tonic-gate } 40760Sstevel@tonic-gate 40770Sstevel@tonic-gate /* 40780Sstevel@tonic-gate * upd_nr_flags updates the node records stored in this node's local mddb 40790Sstevel@tonic-gate * given a node desciptor list and an action. upd_nr_flags then commits 40800Sstevel@tonic-gate * the node records to the local mddb. 40810Sstevel@tonic-gate * 40820Sstevel@tonic-gate * nd - A linked list of node descriptors that describes the node records 40830Sstevel@tonic-gate * in this diskset on which the action applies. 40840Sstevel@tonic-gate * flag_action: action to be taken on node records that match the nd list. 40850Sstevel@tonic-gate * flag_action can be: 40860Sstevel@tonic-gate * MD_NR_JOIN: set OWN flag in node records 40870Sstevel@tonic-gate * MD_NR_WITHDRAW: reset OWN flag in node records 40880Sstevel@tonic-gate * MD_NR_OK: reset ADD flags and set OK flag in node records 40890Sstevel@tonic-gate * MD_NR_SET: set node record flags based on flags stored in nd 40900Sstevel@tonic-gate * 40910Sstevel@tonic-gate * Typically, the JOIN, WITHDRAW and OK flag_actions are used when setting 40920Sstevel@tonic-gate * all nodes in a diskset to JOIN (add first disk to set), WITHDRAW 40930Sstevel@tonic-gate * (remove last disk from set) or OK (after addition of host to set). 40940Sstevel@tonic-gate * 40950Sstevel@tonic-gate * The SET flag_action is typically used when nodelist contains all nodes 40960Sstevel@tonic-gate * in the diskset, but specific nodes have had flag changes. An example of 40970Sstevel@tonic-gate * this would be the join/withdraw of a specific node to/from the set. 40980Sstevel@tonic-gate * 40990Sstevel@tonic-gate * Ignore the MD_MN_NODE_RB_JOIN flag if set in node record flag. This 41000Sstevel@tonic-gate * flag is used by the client to recover in case of failure and should not 41010Sstevel@tonic-gate * be set in the node record flags. 41020Sstevel@tonic-gate */ 41030Sstevel@tonic-gate static void 41040Sstevel@tonic-gate upd_nr_flags( 41050Sstevel@tonic-gate mdsetname_t *sp, 41060Sstevel@tonic-gate md_mnnode_desc *nd, 41070Sstevel@tonic-gate uint_t flag_action, 41080Sstevel@tonic-gate md_error_t *ep 41090Sstevel@tonic-gate ) 41100Sstevel@tonic-gate { 41110Sstevel@tonic-gate mdsetname_t *local_sp; 41120Sstevel@tonic-gate md_set_record *sr; 41130Sstevel@tonic-gate md_mnset_record *mnsr; 41140Sstevel@tonic-gate md_mnnode_desc *ndp; 41150Sstevel@tonic-gate md_mnnode_record *nrp; 41160Sstevel@tonic-gate 41170Sstevel@tonic-gate if ((local_sp = metasetname(sp->setname, ep)) == NULL) 41180Sstevel@tonic-gate return; 41190Sstevel@tonic-gate 41200Sstevel@tonic-gate metaflushsetname(local_sp); 41210Sstevel@tonic-gate 41220Sstevel@tonic-gate if ((sr = getsetbyname(sp->setname, ep)) == NULL) 41230Sstevel@tonic-gate return; 41240Sstevel@tonic-gate 41250Sstevel@tonic-gate if (!(MD_MNSET_REC(sr))) { 41260Sstevel@tonic-gate return; 41270Sstevel@tonic-gate } 41280Sstevel@tonic-gate mnsr = (struct md_mnset_record *)sr; 41290Sstevel@tonic-gate 41300Sstevel@tonic-gate switch (flag_action) { 41310Sstevel@tonic-gate case MD_NR_JOIN: 41320Sstevel@tonic-gate case MD_NR_WITHDRAW: 41330Sstevel@tonic-gate case MD_NR_SET: 41340Sstevel@tonic-gate case MD_NR_OK: 41350Sstevel@tonic-gate case MD_NR_DEL: 41360Sstevel@tonic-gate break; 41370Sstevel@tonic-gate default: 41380Sstevel@tonic-gate return; 41390Sstevel@tonic-gate } 41400Sstevel@tonic-gate 41410Sstevel@tonic-gate for (ndp = nd; ndp != NULL; ndp = ndp->nd_next) { 41420Sstevel@tonic-gate /* Find matching node record for given node descriptor */ 41430Sstevel@tonic-gate for (nrp = mnsr->sr_nodechain; nrp != NULL; 41440Sstevel@tonic-gate nrp = nrp->nr_next) { 41450Sstevel@tonic-gate if (ndp->nd_nodeid == nrp->nr_nodeid) { 41460Sstevel@tonic-gate switch (flag_action) { 41470Sstevel@tonic-gate case MD_NR_JOIN: 41480Sstevel@tonic-gate nrp->nr_flags |= MD_MN_NODE_OWN; 41490Sstevel@tonic-gate break; 41500Sstevel@tonic-gate case MD_NR_WITHDRAW: 41510Sstevel@tonic-gate nrp->nr_flags &= ~MD_MN_NODE_OWN; 41520Sstevel@tonic-gate break; 41530Sstevel@tonic-gate case MD_NR_OK: 41540Sstevel@tonic-gate nrp->nr_flags &= 41550Sstevel@tonic-gate ~(MD_MN_NODE_ADD | MD_MN_NODE_DEL); 41560Sstevel@tonic-gate nrp->nr_flags |= MD_MN_NODE_OK; 41570Sstevel@tonic-gate break; 41580Sstevel@tonic-gate case MD_NR_DEL: 41590Sstevel@tonic-gate nrp->nr_flags &= 41600Sstevel@tonic-gate ~(MD_MN_NODE_OK | MD_MN_NODE_ADD); 41610Sstevel@tonic-gate nrp->nr_flags |= MD_MN_NODE_DEL; 41620Sstevel@tonic-gate break; 41630Sstevel@tonic-gate case MD_NR_SET: 41640Sstevel@tonic-gate /* Do not set RB_JOIN flag */ 41650Sstevel@tonic-gate nrp->nr_flags = 41660Sstevel@tonic-gate ndp->nd_flags & ~MD_MN_NODE_RB_JOIN; 41670Sstevel@tonic-gate break; 41680Sstevel@tonic-gate } 41690Sstevel@tonic-gate break; 41700Sstevel@tonic-gate } 41710Sstevel@tonic-gate } 41720Sstevel@tonic-gate } 41730Sstevel@tonic-gate out: 41740Sstevel@tonic-gate /* Don't increment set genid for node record flag update */ 41750Sstevel@tonic-gate commitset(sr, FALSE, ep); 41760Sstevel@tonic-gate free_sr(sr); 41770Sstevel@tonic-gate } 41780Sstevel@tonic-gate 41790Sstevel@tonic-gate /* 41800Sstevel@tonic-gate * init/fini wrapper around upd_nr_flags 41810Sstevel@tonic-gate */ 41820Sstevel@tonic-gate bool_t 41830Sstevel@tonic-gate mdrpc_upd_nr_flags_common( 41840Sstevel@tonic-gate mdrpc_upd_nr_flags_args *args, 41850Sstevel@tonic-gate mdrpc_generic_res *res, 41860Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 41870Sstevel@tonic-gate ) 41880Sstevel@tonic-gate { 41890Sstevel@tonic-gate md_error_t *ep = &res->status; 41900Sstevel@tonic-gate int err; 41910Sstevel@tonic-gate int op_mode = W_OK; 41920Sstevel@tonic-gate 41930Sstevel@tonic-gate /* setup, check permissions */ 41940Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 41950Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 41960Sstevel@tonic-gate return (FALSE); 41970Sstevel@tonic-gate else if (err != 0) 41980Sstevel@tonic-gate return (TRUE); 41990Sstevel@tonic-gate 42000Sstevel@tonic-gate /* 42010Sstevel@tonic-gate * During reconfig, node record flags can be updated without 42020Sstevel@tonic-gate * locking first. 42030Sstevel@tonic-gate */ 42040Sstevel@tonic-gate if (!(args->flags & MNSET_IN_RECONFIG)) { 42050Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 42060Sstevel@tonic-gate return (TRUE); 42070Sstevel@tonic-gate } 42080Sstevel@tonic-gate 42090Sstevel@tonic-gate /* doit */ 42100Sstevel@tonic-gate upd_nr_flags(args->sp, args->nodedescs, args->flag_action, ep); 42110Sstevel@tonic-gate 42120Sstevel@tonic-gate err = svc_fini(ep); 42130Sstevel@tonic-gate 42140Sstevel@tonic-gate return (TRUE); 42150Sstevel@tonic-gate } 42160Sstevel@tonic-gate 42170Sstevel@tonic-gate /* 42180Sstevel@tonic-gate * update the node records using given flag action. 42190Sstevel@tonic-gate */ 42200Sstevel@tonic-gate bool_t 42210Sstevel@tonic-gate mdrpc_upd_nr_flags_2_svc( 42220Sstevel@tonic-gate mdrpc_upd_nr_flags_2_args *args, 42230Sstevel@tonic-gate mdrpc_generic_res *res, 42240Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 42250Sstevel@tonic-gate ) 42260Sstevel@tonic-gate { 42270Sstevel@tonic-gate switch (args->rev) { 42280Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 42290Sstevel@tonic-gate return (mdrpc_upd_nr_flags_common( 42300Sstevel@tonic-gate &args->mdrpc_upd_nr_flags_2_args_u.rev1, res, rqstp)); 42310Sstevel@tonic-gate default: 42320Sstevel@tonic-gate return (FALSE); 42330Sstevel@tonic-gate } 42340Sstevel@tonic-gate } 42350Sstevel@tonic-gate 42360Sstevel@tonic-gate void 42370Sstevel@tonic-gate free_sk(md_setkey_t *skp) 42380Sstevel@tonic-gate { 42390Sstevel@tonic-gate Free(skp->sk_setname); 42400Sstevel@tonic-gate Free(skp->sk_host); 42410Sstevel@tonic-gate Free(skp); 42420Sstevel@tonic-gate } 42430Sstevel@tonic-gate 42440Sstevel@tonic-gate void 42450Sstevel@tonic-gate del_sk(set_t setno) 42460Sstevel@tonic-gate { 42470Sstevel@tonic-gate md_setkey_t *skp; 42480Sstevel@tonic-gate md_setkey_t *tskp; 42490Sstevel@tonic-gate 42500Sstevel@tonic-gate for (skp = tskp = my_svc_sk; skp; tskp = skp, skp = skp->sk_next) { 42510Sstevel@tonic-gate if (setno == skp->sk_setno) { 42520Sstevel@tonic-gate if (skp == my_svc_sk) 42530Sstevel@tonic-gate my_svc_sk = skp->sk_next; 42540Sstevel@tonic-gate else 42550Sstevel@tonic-gate tskp->sk_next = skp->sk_next; 42560Sstevel@tonic-gate 42570Sstevel@tonic-gate Free(skp->sk_setname); 42580Sstevel@tonic-gate Free(skp->sk_host); 42590Sstevel@tonic-gate Free(skp); 42600Sstevel@tonic-gate break; 42610Sstevel@tonic-gate } 42620Sstevel@tonic-gate } 42630Sstevel@tonic-gate } 42640Sstevel@tonic-gate 42650Sstevel@tonic-gate md_setkey_t * 42660Sstevel@tonic-gate dupsk(md_setkey_t *skp) 42670Sstevel@tonic-gate { 42680Sstevel@tonic-gate md_setkey_t *tskp; 42690Sstevel@tonic-gate 42700Sstevel@tonic-gate tskp = Zalloc(sizeof (md_setkey_t)); 42710Sstevel@tonic-gate 42720Sstevel@tonic-gate *tskp = *skp; 42730Sstevel@tonic-gate tskp->sk_host = Strdup(skp->sk_host); 42740Sstevel@tonic-gate tskp->sk_setname = Strdup(skp->sk_setname); 42750Sstevel@tonic-gate 42760Sstevel@tonic-gate return (tskp); 42770Sstevel@tonic-gate } 42780Sstevel@tonic-gate 42790Sstevel@tonic-gate md_setkey_t * 42800Sstevel@tonic-gate svc_get_setkey(set_t setno) 42810Sstevel@tonic-gate { 42820Sstevel@tonic-gate md_setkey_t *skp; 42830Sstevel@tonic-gate 42840Sstevel@tonic-gate for (skp = my_svc_sk; skp != NULL; skp = skp->sk_next) 42850Sstevel@tonic-gate if (setno == skp->sk_setno) 42860Sstevel@tonic-gate return (dupsk(skp)); 42870Sstevel@tonic-gate return (NULL); 42880Sstevel@tonic-gate } 42890Sstevel@tonic-gate 42900Sstevel@tonic-gate void 42910Sstevel@tonic-gate svc_set_setkey(md_setkey_t *svc_sk) 42920Sstevel@tonic-gate { 42930Sstevel@tonic-gate md_setkey_t *skp; 42940Sstevel@tonic-gate 42950Sstevel@tonic-gate if (my_svc_sk == NULL) { 42960Sstevel@tonic-gate my_svc_sk = dupsk(svc_sk); 42970Sstevel@tonic-gate return; 42980Sstevel@tonic-gate } 42990Sstevel@tonic-gate 43000Sstevel@tonic-gate for (skp = my_svc_sk; skp->sk_next != NULL; skp = skp->sk_next) 43010Sstevel@tonic-gate assert(svc_sk->sk_setno != skp->sk_setno); 43020Sstevel@tonic-gate 43030Sstevel@tonic-gate skp->sk_next = dupsk(svc_sk); 43040Sstevel@tonic-gate } 43050Sstevel@tonic-gate 43060Sstevel@tonic-gate /* 43070Sstevel@tonic-gate * Unlock the set 43080Sstevel@tonic-gate * 43090Sstevel@tonic-gate * To unlock the set, the user must have the correct key, once this is verified 43100Sstevel@tonic-gate * the set is unlocked and the cached information for the set is flushed. 43110Sstevel@tonic-gate */ 43120Sstevel@tonic-gate bool_t 43130Sstevel@tonic-gate mdrpc_unlock_set_common( 43140Sstevel@tonic-gate mdrpc_null_args *args, 43150Sstevel@tonic-gate mdrpc_setlock_res *res, 43160Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 43170Sstevel@tonic-gate ) 43180Sstevel@tonic-gate { 43190Sstevel@tonic-gate md_error_t *ep = &res->status; 43200Sstevel@tonic-gate int err; 43210Sstevel@tonic-gate int op_mode = W_OK; 43220Sstevel@tonic-gate md_setkey_t *svc_skp; 43230Sstevel@tonic-gate md_set_desc *sd; 43240Sstevel@tonic-gate mdsetname_t *sp; 43250Sstevel@tonic-gate int multi_node = 0; 43260Sstevel@tonic-gate md_error_t xep = mdnullerror; 43270Sstevel@tonic-gate 43280Sstevel@tonic-gate /* setup, check permissions */ 43290Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 43300Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 43310Sstevel@tonic-gate return (FALSE); 43320Sstevel@tonic-gate else if (err != 0) 43330Sstevel@tonic-gate return (TRUE); 43340Sstevel@tonic-gate 43350Sstevel@tonic-gate /* 43360Sstevel@tonic-gate * Is diskset a MN diskset? 43370Sstevel@tonic-gate * Don't set error from this check since unlock set can be 43380Sstevel@tonic-gate * called after a set has been deleted. 43390Sstevel@tonic-gate */ 43400Sstevel@tonic-gate if (((sp = metasetnosetname(args->cl_sk->sk_setno, &xep)) != NULL) && 43410Sstevel@tonic-gate ((sd = metaget_setdesc(sp, &xep)) != NULL)) { 43420Sstevel@tonic-gate if ((MD_MNSET_DESC(sd))) { 43430Sstevel@tonic-gate multi_node = 1; 43440Sstevel@tonic-gate } 43450Sstevel@tonic-gate } 43460Sstevel@tonic-gate 43470Sstevel@tonic-gate /* Get the set key, if any */ 43480Sstevel@tonic-gate svc_skp = svc_get_setkey(args->cl_sk->sk_setno); 43490Sstevel@tonic-gate 43500Sstevel@tonic-gate /* The set is locked */ 43510Sstevel@tonic-gate if (svc_skp != NULL) { 43520Sstevel@tonic-gate 43530Sstevel@tonic-gate /* Make sure the opener has the right key. */ 43540Sstevel@tonic-gate if (args->cl_sk->sk_key.tv_sec != svc_skp->sk_key.tv_sec || 43550Sstevel@tonic-gate args->cl_sk->sk_key.tv_usec != svc_skp->sk_key.tv_usec) { 43560Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_ULKSBADKEY, 43570Sstevel@tonic-gate svc_skp->sk_setno, mynode(), svc_skp->sk_host, 43580Sstevel@tonic-gate svc_skp->sk_setname); 43590Sstevel@tonic-gate free_sk(svc_skp); 43600Sstevel@tonic-gate return (TRUE); 43610Sstevel@tonic-gate } 43620Sstevel@tonic-gate 43630Sstevel@tonic-gate /* Unlock the set */ 43640Sstevel@tonic-gate del_sk(args->cl_sk->sk_setno); 43650Sstevel@tonic-gate 43660Sstevel@tonic-gate /* Cleanup */ 43670Sstevel@tonic-gate free_sk(svc_skp); 43680Sstevel@tonic-gate 43690Sstevel@tonic-gate goto out; 43700Sstevel@tonic-gate } 43710Sstevel@tonic-gate 43720Sstevel@tonic-gate 43730Sstevel@tonic-gate /* 43740Sstevel@tonic-gate * It is possible on a MN diskset to attempt to unlock a set that 43750Sstevel@tonic-gate * is unlocked. This could occur when the metaset or metadb command 43760Sstevel@tonic-gate * is failing due to another metaset or metadb command running. 43770Sstevel@tonic-gate * So, print no warning for MN disksets. 43780Sstevel@tonic-gate */ 43790Sstevel@tonic-gate if (multi_node == 0) { 43800Sstevel@tonic-gate md_eprintf("Warning: set unlocked when unlock_set called!\n"); 43810Sstevel@tonic-gate } 43820Sstevel@tonic-gate 43830Sstevel@tonic-gate out: 43840Sstevel@tonic-gate res->cl_sk = svc_get_setkey(args->cl_sk->sk_setno); 43850Sstevel@tonic-gate 43860Sstevel@tonic-gate /* Flush the set cache */ 43870Sstevel@tonic-gate sr_cache_flush_setno(args->cl_sk->sk_setno); 43880Sstevel@tonic-gate 43890Sstevel@tonic-gate return (TRUE); 43900Sstevel@tonic-gate } 43910Sstevel@tonic-gate 43920Sstevel@tonic-gate bool_t 43930Sstevel@tonic-gate mdrpc_unlock_set_1_svc( 43940Sstevel@tonic-gate mdrpc_null_args *args, 43950Sstevel@tonic-gate mdrpc_setlock_res *res, 43960Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 43970Sstevel@tonic-gate ) 43980Sstevel@tonic-gate { 43990Sstevel@tonic-gate return (mdrpc_unlock_set_common(args, res, rqstp)); 44000Sstevel@tonic-gate } 44010Sstevel@tonic-gate 44020Sstevel@tonic-gate bool_t 44030Sstevel@tonic-gate mdrpc_unlock_set_2_svc( 44040Sstevel@tonic-gate mdrpc_null_args *args, 44050Sstevel@tonic-gate mdrpc_setlock_res *res, 44060Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 44070Sstevel@tonic-gate ) 44080Sstevel@tonic-gate { 44090Sstevel@tonic-gate return (mdrpc_unlock_set_common(args, res, rqstp)); 44100Sstevel@tonic-gate } 44110Sstevel@tonic-gate 44120Sstevel@tonic-gate /* 44130Sstevel@tonic-gate * Lock the set 44140Sstevel@tonic-gate * 44150Sstevel@tonic-gate * If the user does not hand us a key, then we generate a new key and lock the 44160Sstevel@tonic-gate * set using this new key that was generated, if the user hands us a key then 44170Sstevel@tonic-gate * we use the key to lock the set. 44180Sstevel@tonic-gate */ 44190Sstevel@tonic-gate bool_t 44200Sstevel@tonic-gate mdrpc_lock_set_common( 44210Sstevel@tonic-gate mdrpc_null_args *args, 44220Sstevel@tonic-gate mdrpc_setlock_res *res, 44230Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 44240Sstevel@tonic-gate ) 44250Sstevel@tonic-gate { 44260Sstevel@tonic-gate md_error_t *ep = &res->status; 44270Sstevel@tonic-gate int err; 44280Sstevel@tonic-gate md_error_t xep = mdnullerror; 44290Sstevel@tonic-gate int op_mode = W_OK; 44300Sstevel@tonic-gate md_setkey_t *svc_skp; 44310Sstevel@tonic-gate md_setkey_t new_sk; 44320Sstevel@tonic-gate md_set_desc *sd; 44330Sstevel@tonic-gate mdsetname_t *sp; 44340Sstevel@tonic-gate 44350Sstevel@tonic-gate /* setup, check permissions */ 44360Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 44370Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 44380Sstevel@tonic-gate return (FALSE); 44390Sstevel@tonic-gate else if (err != 0) 44400Sstevel@tonic-gate return (TRUE); 44410Sstevel@tonic-gate 44420Sstevel@tonic-gate svc_skp = svc_get_setkey(args->cl_sk->sk_setno); 44430Sstevel@tonic-gate 44440Sstevel@tonic-gate /* The set is unlocked */ 44450Sstevel@tonic-gate if (svc_skp == NULL) { 44460Sstevel@tonic-gate /* If we have been given a key, use it. */ 44470Sstevel@tonic-gate if (args->cl_sk->sk_key.tv_sec || args->cl_sk->sk_key.tv_usec) { 44480Sstevel@tonic-gate svc_set_setkey(args->cl_sk); 44490Sstevel@tonic-gate res->cl_sk = svc_get_setkey(args->cl_sk->sk_setno); 44500Sstevel@tonic-gate goto out; 44510Sstevel@tonic-gate } 44520Sstevel@tonic-gate 44530Sstevel@tonic-gate /* We need to lock it, with a new key */ 44540Sstevel@tonic-gate new_sk = *args->cl_sk; 44550Sstevel@tonic-gate if (meta_gettimeofday(&new_sk.sk_key) == -1) { 44560Sstevel@tonic-gate (void) mdsyserror(ep, errno, "meta_gettimeofday()"); 44570Sstevel@tonic-gate mde_perror(&xep, ""); 44580Sstevel@tonic-gate md_exit(NULL, 1); 44590Sstevel@tonic-gate } 44600Sstevel@tonic-gate svc_set_setkey(&new_sk); 44610Sstevel@tonic-gate 44620Sstevel@tonic-gate res->cl_sk = svc_get_setkey(args->cl_sk->sk_setno); 44630Sstevel@tonic-gate goto out; 44640Sstevel@tonic-gate } 44650Sstevel@tonic-gate 44660Sstevel@tonic-gate /* 44670Sstevel@tonic-gate * If a MN diskset, the lock_set routine is used as a locking 44680Sstevel@tonic-gate * mechanism to keep multiple metaset and/or metadb commads 44690Sstevel@tonic-gate * from interfering with each other. If two metaset/metadb 44700Sstevel@tonic-gate * commands are issued at the same time - one will complete 44710Sstevel@tonic-gate * and the other command will fail with MDE_DS_NOTNOW_CMD. 44720Sstevel@tonic-gate */ 44730Sstevel@tonic-gate if (((sp = metasetnosetname(args->cl_sk->sk_setno, ep)) != NULL) && 44740Sstevel@tonic-gate ((sd = metaget_setdesc(sp, ep)) != NULL) && 44750Sstevel@tonic-gate (MD_MNSET_DESC(sd))) { 44760Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_NOTNOW_CMD, 44770Sstevel@tonic-gate svc_skp->sk_setno, mynode(), 44780Sstevel@tonic-gate svc_skp->sk_host, svc_skp->sk_setname); 44790Sstevel@tonic-gate goto out; 44800Sstevel@tonic-gate } 44810Sstevel@tonic-gate 44820Sstevel@tonic-gate md_eprintf("Warning: set locked when lock_set called!\n"); 44830Sstevel@tonic-gate 44840Sstevel@tonic-gate md_eprintf("Lock info:\n"); 44850Sstevel@tonic-gate 44860Sstevel@tonic-gate md_eprintf("\tLock(svc):\n"); 44870Sstevel@tonic-gate md_eprintf("\t\tSetname: %s\n", svc_skp->sk_setname); 44880Sstevel@tonic-gate md_eprintf("\t\tSetno: %d\n", svc_skp->sk_setno); 44890Sstevel@tonic-gate md_eprintf("\t\tHost: %s\n", svc_skp->sk_host); 44900Sstevel@tonic-gate md_eprintf("\t\tKey: %d/%d %s", 44910Sstevel@tonic-gate svc_skp->sk_key.tv_sec, svc_skp->sk_key.tv_usec, 44920Sstevel@tonic-gate ctime((const time_t *)&svc_skp->sk_key.tv_sec)); 44930Sstevel@tonic-gate 44940Sstevel@tonic-gate md_eprintf("\tLock(cl):\n"); 44950Sstevel@tonic-gate md_eprintf("\t\tSetname: %s\n", args->cl_sk->sk_setname); 44960Sstevel@tonic-gate md_eprintf("\t\tSetno: %d\n", args->cl_sk->sk_setno); 44970Sstevel@tonic-gate md_eprintf("\t\tHost: %s\n", args->cl_sk->sk_host); 44980Sstevel@tonic-gate md_eprintf("\t\tKey: %d/%d %s", 44990Sstevel@tonic-gate args->cl_sk->sk_key.tv_sec, args->cl_sk->sk_key.tv_usec, 45000Sstevel@tonic-gate ctime((const time_t *)&args->cl_sk->sk_key.tv_sec)); 45010Sstevel@tonic-gate 45020Sstevel@tonic-gate /* The set is locked, do we have the key? */ 45030Sstevel@tonic-gate if (args->cl_sk->sk_key.tv_sec == svc_skp->sk_key.tv_sec && 45040Sstevel@tonic-gate args->cl_sk->sk_key.tv_usec == svc_skp->sk_key.tv_usec) { 45050Sstevel@tonic-gate res->cl_sk = svc_get_setkey(args->cl_sk->sk_setno); 45060Sstevel@tonic-gate goto out; 45070Sstevel@tonic-gate } 45080Sstevel@tonic-gate 45090Sstevel@tonic-gate /* 45100Sstevel@tonic-gate * The set is locked and we do not have the key, so we set up an error. 45110Sstevel@tonic-gate */ 45120Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_LKSBADKEY, svc_skp->sk_setno, mynode(), 45130Sstevel@tonic-gate svc_skp->sk_host, args->cl_sk->sk_setname); 45140Sstevel@tonic-gate 45150Sstevel@tonic-gate out: 45160Sstevel@tonic-gate if (svc_skp != NULL) 45170Sstevel@tonic-gate free_sk(svc_skp); 45180Sstevel@tonic-gate 45190Sstevel@tonic-gate /* Flush the set cache */ 45200Sstevel@tonic-gate sr_cache_flush_setno(args->cl_sk->sk_setno); 45210Sstevel@tonic-gate 45220Sstevel@tonic-gate return (TRUE); 45230Sstevel@tonic-gate } 45240Sstevel@tonic-gate 45250Sstevel@tonic-gate bool_t 45260Sstevel@tonic-gate mdrpc_lock_set_1_svc( 45270Sstevel@tonic-gate mdrpc_null_args *args, 45280Sstevel@tonic-gate mdrpc_setlock_res *res, 45290Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 45300Sstevel@tonic-gate ) 45310Sstevel@tonic-gate { 45320Sstevel@tonic-gate return (mdrpc_lock_set_common(args, res, rqstp)); 45330Sstevel@tonic-gate } 45340Sstevel@tonic-gate 45350Sstevel@tonic-gate bool_t 45360Sstevel@tonic-gate mdrpc_lock_set_2_svc( 45370Sstevel@tonic-gate mdrpc_null_args *args, 45380Sstevel@tonic-gate mdrpc_setlock_res *res, 45390Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 45400Sstevel@tonic-gate ) 45410Sstevel@tonic-gate { 45420Sstevel@tonic-gate return (mdrpc_lock_set_common(args, res, rqstp)); 45430Sstevel@tonic-gate } 45440Sstevel@tonic-gate 45450Sstevel@tonic-gate static void 45460Sstevel@tonic-gate updmeds( 45470Sstevel@tonic-gate char *setname, 45480Sstevel@tonic-gate md_h_arr_t *medp, 45490Sstevel@tonic-gate int version, /* RPC version of calling routine */ 45500Sstevel@tonic-gate md_error_t *ep 45510Sstevel@tonic-gate ) 45520Sstevel@tonic-gate { 45530Sstevel@tonic-gate mddb_userreq_t req; 45540Sstevel@tonic-gate md_set_record *sr; 45550Sstevel@tonic-gate mddb_med_parm_t mp; 45560Sstevel@tonic-gate 45570Sstevel@tonic-gate if ((sr = getsetbyname(setname, ep)) == NULL) 45580Sstevel@tonic-gate return; 45590Sstevel@tonic-gate 45600Sstevel@tonic-gate sr->sr_med = *medp; /* structure assignment */ 45610Sstevel@tonic-gate 45620Sstevel@tonic-gate (void) memset(&req, '\0', sizeof (req)); 45630Sstevel@tonic-gate 45640Sstevel@tonic-gate METAD_SETUP_SR(MD_DB_SETDATA, sr->sr_selfid) 45650Sstevel@tonic-gate /* Do MN operation if rpc version supports it and if a MN set */ 45660Sstevel@tonic-gate if ((version != METAD_VERSION) && (MD_MNSET_REC(sr))) { 45670Sstevel@tonic-gate req.ur_size = sizeof (struct md_mnset_record); 45680Sstevel@tonic-gate } else { 45690Sstevel@tonic-gate req.ur_size = sizeof (*sr); 45700Sstevel@tonic-gate } 45710Sstevel@tonic-gate req.ur_data = (uintptr_t)sr; 45720Sstevel@tonic-gate if (metaioctl(MD_DB_USERREQ, &req, &req.ur_mde, NULL) != 0) { 45730Sstevel@tonic-gate (void) mdstealerror(ep, &req.ur_mde); 45740Sstevel@tonic-gate free_sr(sr); 45750Sstevel@tonic-gate return; 45760Sstevel@tonic-gate } 45770Sstevel@tonic-gate 45780Sstevel@tonic-gate commitset(sr, TRUE, ep); 45790Sstevel@tonic-gate 45800Sstevel@tonic-gate /* 45810Sstevel@tonic-gate * If a MN disket, send the mediator list to the kernel. 45820Sstevel@tonic-gate */ 45830Sstevel@tonic-gate if (MD_MNSET_REC(sr)) { 45840Sstevel@tonic-gate (void) memset(&mp, '\0', sizeof (mddb_med_parm_t)); 45850Sstevel@tonic-gate mp.med_setno = sr->sr_setno; 45860Sstevel@tonic-gate if (meta_h2hi(medp, &mp.med, ep)) { 45870Sstevel@tonic-gate free_sr(sr); 45880Sstevel@tonic-gate return; 45890Sstevel@tonic-gate } 45900Sstevel@tonic-gate 45910Sstevel@tonic-gate /* Resolve the IP addresses for the host list */ 45920Sstevel@tonic-gate if (meta_med_hnm2ip(&mp.med, ep)) { 45930Sstevel@tonic-gate free_sr(sr); 45940Sstevel@tonic-gate return; 45950Sstevel@tonic-gate } 45960Sstevel@tonic-gate 45970Sstevel@tonic-gate /* If node not yet joined to set, failure is ok. */ 45980Sstevel@tonic-gate if (metaioctl(MD_MED_SET_LST, &mp, &mp.med_mde, NULL) != 0) { 45990Sstevel@tonic-gate if (!mdismddberror(&mp.med_mde, MDE_DB_NOTOWNER)) { 46000Sstevel@tonic-gate (void) mdstealerror(ep, &mp.med_mde); 46010Sstevel@tonic-gate } 46020Sstevel@tonic-gate } 46030Sstevel@tonic-gate } 46040Sstevel@tonic-gate free_sr(sr); 46050Sstevel@tonic-gate } 46060Sstevel@tonic-gate 46070Sstevel@tonic-gate /* 46080Sstevel@tonic-gate * Update the mediator data in the set record 46090Sstevel@tonic-gate */ 46100Sstevel@tonic-gate bool_t 46110Sstevel@tonic-gate mdrpc_updmeds_common( 46120Sstevel@tonic-gate mdrpc_updmeds_args *args, 46130Sstevel@tonic-gate mdrpc_generic_res *res, 46140Sstevel@tonic-gate struct svc_req *rqstp, /* RPC stuff */ 46150Sstevel@tonic-gate int version /* RPC version */ 46160Sstevel@tonic-gate ) 46170Sstevel@tonic-gate { 46180Sstevel@tonic-gate md_error_t *ep = &res->status; 46190Sstevel@tonic-gate int err; 46200Sstevel@tonic-gate int op_mode = W_OK; 46210Sstevel@tonic-gate 46220Sstevel@tonic-gate /* setup, check permissions */ 46230Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 46240Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 46250Sstevel@tonic-gate return (FALSE); 46260Sstevel@tonic-gate else if (err != 0) 46270Sstevel@tonic-gate return (TRUE); 46280Sstevel@tonic-gate 46290Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 46300Sstevel@tonic-gate return (TRUE); 46310Sstevel@tonic-gate 46320Sstevel@tonic-gate /* doit */ 46330Sstevel@tonic-gate updmeds(args->sp->setname, &args->meds, version, ep); 46340Sstevel@tonic-gate 46350Sstevel@tonic-gate err = svc_fini(ep); 46360Sstevel@tonic-gate 46370Sstevel@tonic-gate return (TRUE); 46380Sstevel@tonic-gate } 46390Sstevel@tonic-gate 46400Sstevel@tonic-gate bool_t 46410Sstevel@tonic-gate mdrpc_updmeds_1_svc( 46420Sstevel@tonic-gate mdrpc_updmeds_args *args, 46430Sstevel@tonic-gate mdrpc_generic_res *res, 46440Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 46450Sstevel@tonic-gate ) 46460Sstevel@tonic-gate { 46470Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION) to common routine */ 46480Sstevel@tonic-gate return (mdrpc_updmeds_common(args, res, rqstp, METAD_VERSION)); 46490Sstevel@tonic-gate } 46500Sstevel@tonic-gate 46510Sstevel@tonic-gate bool_t 46520Sstevel@tonic-gate mdrpc_updmeds_2_svc( 46530Sstevel@tonic-gate mdrpc_updmeds_2_args *args, 46540Sstevel@tonic-gate mdrpc_generic_res *res, 46550Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 46560Sstevel@tonic-gate ) 46570Sstevel@tonic-gate { 46580Sstevel@tonic-gate switch (args->rev) { 46590Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 46600Sstevel@tonic-gate /* Pass RPC version (METAD_VERSION_DEVID) to common routine */ 46610Sstevel@tonic-gate return (mdrpc_updmeds_common( 46620Sstevel@tonic-gate &args->mdrpc_updmeds_2_args_u.rev1, res, 46630Sstevel@tonic-gate rqstp, METAD_VERSION_DEVID)); 46640Sstevel@tonic-gate default: 46650Sstevel@tonic-gate return (FALSE); 46660Sstevel@tonic-gate } 46670Sstevel@tonic-gate } 46680Sstevel@tonic-gate 46690Sstevel@tonic-gate /* 46700Sstevel@tonic-gate * Call routines to suspend, reinit and resume mdcommd. 46710Sstevel@tonic-gate * Called during metaset and metadb command. 46720Sstevel@tonic-gate * NOT called during reconfig cycle. 46730Sstevel@tonic-gate */ 46740Sstevel@tonic-gate bool_t 46750Sstevel@tonic-gate mdrpc_mdcommdctl_2_svc( 46760Sstevel@tonic-gate mdrpc_mdcommdctl_2_args *args, 46770Sstevel@tonic-gate mdrpc_generic_res *res, 46780Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 46790Sstevel@tonic-gate ) 46800Sstevel@tonic-gate { 46810Sstevel@tonic-gate mdrpc_mdcommdctl_args *args_cc; 46820Sstevel@tonic-gate md_error_t *ep = &res->status; 46830Sstevel@tonic-gate int err; 46840Sstevel@tonic-gate int op_mode = R_OK; 46850Sstevel@tonic-gate int suspend_ret; 46860Sstevel@tonic-gate 46870Sstevel@tonic-gate switch (args->rev) { 46880Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 46890Sstevel@tonic-gate /* setup, check permissions */ 46900Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 46910Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 46920Sstevel@tonic-gate return (FALSE); 46930Sstevel@tonic-gate else if (err != 0) 46940Sstevel@tonic-gate return (TRUE); 46950Sstevel@tonic-gate 46960Sstevel@tonic-gate args_cc = &(args->mdrpc_mdcommdctl_2_args_u.rev1); 46970Sstevel@tonic-gate switch (args_cc->flag_action) { 46980Sstevel@tonic-gate case COMMDCTL_SUSPEND: 46990Sstevel@tonic-gate suspend_ret = mdmn_suspend(args_cc->setno, 47000Sstevel@tonic-gate args_cc->class); 47010Sstevel@tonic-gate if (suspend_ret != 0) { 47020Sstevel@tonic-gate (void) mddserror(ep, suspend_ret, 47030Sstevel@tonic-gate args_cc->setno, mynode(), 47040Sstevel@tonic-gate NULL, mynode()); 47050Sstevel@tonic-gate } 47060Sstevel@tonic-gate break; 47070Sstevel@tonic-gate case COMMDCTL_RESUME: 47080Sstevel@tonic-gate if (mdmn_resume(args_cc->setno, 47090Sstevel@tonic-gate args_cc->class, args_cc->flags)) { 47100Sstevel@tonic-gate (void) mddserror(ep, 47110Sstevel@tonic-gate MDE_DS_COMMDCTL_RESUME_FAIL, 47120Sstevel@tonic-gate args_cc->setno, mynode(), 47130Sstevel@tonic-gate NULL, mynode()); 47140Sstevel@tonic-gate } 47150Sstevel@tonic-gate break; 47160Sstevel@tonic-gate case COMMDCTL_REINIT: 47170Sstevel@tonic-gate if (mdmn_reinit_set(args_cc->setno)) { 47180Sstevel@tonic-gate (void) mddserror(ep, 47190Sstevel@tonic-gate MDE_DS_COMMDCTL_REINIT_FAIL, 47200Sstevel@tonic-gate args_cc->setno, mynode(), 47210Sstevel@tonic-gate NULL, mynode()); 47220Sstevel@tonic-gate } 47230Sstevel@tonic-gate break; 47240Sstevel@tonic-gate } 47250Sstevel@tonic-gate err = svc_fini(ep); 47260Sstevel@tonic-gate return (TRUE); 47270Sstevel@tonic-gate 47280Sstevel@tonic-gate default: 47290Sstevel@tonic-gate return (FALSE); 47300Sstevel@tonic-gate } 47310Sstevel@tonic-gate } 47320Sstevel@tonic-gate 47330Sstevel@tonic-gate /* 47340Sstevel@tonic-gate * Return TRUE if set is stale. 47350Sstevel@tonic-gate */ 47360Sstevel@tonic-gate bool_t 47370Sstevel@tonic-gate mdrpc_mn_is_stale_2_svc( 47380Sstevel@tonic-gate mdrpc_setno_2_args *args, 47390Sstevel@tonic-gate mdrpc_bool_res *res, 47400Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 47410Sstevel@tonic-gate ) 47420Sstevel@tonic-gate { 47430Sstevel@tonic-gate md_error_t *ep = &res->status; 47440Sstevel@tonic-gate mddb_config_t c; 47450Sstevel@tonic-gate int err; 47460Sstevel@tonic-gate int op_mode = R_OK; 47470Sstevel@tonic-gate 47480Sstevel@tonic-gate (void) memset(&c, 0, sizeof (c)); 47490Sstevel@tonic-gate switch (args->rev) { 47500Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 47510Sstevel@tonic-gate c.c_id = 0; 47520Sstevel@tonic-gate c.c_setno = args->mdrpc_setno_2_args_u.rev1.setno; 47530Sstevel@tonic-gate 47540Sstevel@tonic-gate /* setup, check permissions */ 47550Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 47560Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 47570Sstevel@tonic-gate return (FALSE); 47580Sstevel@tonic-gate else if (err != 0) 47590Sstevel@tonic-gate return (TRUE); 47600Sstevel@tonic-gate 47610Sstevel@tonic-gate if (metaioctl(MD_DB_GETDEV, &c, &c.c_mde, NULL) != 0) { 47620Sstevel@tonic-gate mdstealerror(ep, &c.c_mde); 47630Sstevel@tonic-gate return (TRUE); 47640Sstevel@tonic-gate } 47650Sstevel@tonic-gate 47660Sstevel@tonic-gate if (c.c_flags & MDDB_C_STALE) { 47670Sstevel@tonic-gate res->value = TRUE; 47680Sstevel@tonic-gate } else { 47690Sstevel@tonic-gate res->value = FALSE; 47700Sstevel@tonic-gate } 47710Sstevel@tonic-gate 47720Sstevel@tonic-gate err = svc_fini(ep); 47730Sstevel@tonic-gate return (TRUE); 47740Sstevel@tonic-gate 47750Sstevel@tonic-gate default: 47760Sstevel@tonic-gate return (FALSE); 47770Sstevel@tonic-gate } 47780Sstevel@tonic-gate } 47790Sstevel@tonic-gate 47800Sstevel@tonic-gate /* 47810Sstevel@tonic-gate * Clear out all clnt_locks held by all MN disksets. 47820Sstevel@tonic-gate * This is only used during a reconfig cycle. 47830Sstevel@tonic-gate */ 47840Sstevel@tonic-gate /* ARGSUSED */ 478562Sjeanm int 47860Sstevel@tonic-gate mdrpc_clr_mnsetlock_2_svc( 47870Sstevel@tonic-gate mdrpc_null_args *args, 47880Sstevel@tonic-gate mdrpc_generic_res *res, 47890Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 47900Sstevel@tonic-gate ) 47910Sstevel@tonic-gate { 47920Sstevel@tonic-gate set_t max_sets, setno; 47930Sstevel@tonic-gate md_error_t *ep = &res->status; 47940Sstevel@tonic-gate int err; 47950Sstevel@tonic-gate int op_mode = W_OK; 47960Sstevel@tonic-gate mdsetname_t *sp; 47970Sstevel@tonic-gate 47980Sstevel@tonic-gate /* setup, check permissions */ 47990Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 48000Sstevel@tonic-gate 48010Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 48020Sstevel@tonic-gate return (FALSE); 48030Sstevel@tonic-gate else if (err != 0) 48040Sstevel@tonic-gate return (TRUE); 48050Sstevel@tonic-gate 48060Sstevel@tonic-gate /* 48070Sstevel@tonic-gate * Walk through all possible disksets. 48080Sstevel@tonic-gate * For each MN set, delete all keys associated with that set. 48090Sstevel@tonic-gate */ 48100Sstevel@tonic-gate if ((max_sets = get_max_sets(ep)) == 0) { 48110Sstevel@tonic-gate return (TRUE); 48120Sstevel@tonic-gate } 48130Sstevel@tonic-gate 48140Sstevel@tonic-gate /* start walking through all possible disksets */ 48150Sstevel@tonic-gate for (setno = 1; setno < max_sets; setno++) { 48160Sstevel@tonic-gate if ((sp = metasetnosetname(setno, ep)) == NULL) { 48170Sstevel@tonic-gate if (mdiserror(ep, MDE_NO_SET)) { 48180Sstevel@tonic-gate /* No set for this setno - continue */ 48190Sstevel@tonic-gate mdclrerror(ep); 48200Sstevel@tonic-gate continue; 48210Sstevel@tonic-gate } else { 48220Sstevel@tonic-gate mde_perror(ep, gettext( 48230Sstevel@tonic-gate "Unable to get set %s information"), 48240Sstevel@tonic-gate sp->setname); 48250Sstevel@tonic-gate mdclrerror(ep); 48260Sstevel@tonic-gate continue; 48270Sstevel@tonic-gate } 48280Sstevel@tonic-gate } 48290Sstevel@tonic-gate 48300Sstevel@tonic-gate /* only check multi-node disksets */ 48310Sstevel@tonic-gate if (!meta_is_mn_set(sp, ep)) { 48320Sstevel@tonic-gate mdclrerror(ep); 48330Sstevel@tonic-gate continue; 48340Sstevel@tonic-gate } 48350Sstevel@tonic-gate 48360Sstevel@tonic-gate /* Delete keys associated with rpc.metad clnt_lock */ 48370Sstevel@tonic-gate del_sk(setno); 48380Sstevel@tonic-gate } 48390Sstevel@tonic-gate 48400Sstevel@tonic-gate *ep = mdnullerror; 48410Sstevel@tonic-gate 48420Sstevel@tonic-gate err = svc_fini(ep); 48430Sstevel@tonic-gate 48440Sstevel@tonic-gate return (TRUE); 48450Sstevel@tonic-gate } 48460Sstevel@tonic-gate 48470Sstevel@tonic-gate /* 48480Sstevel@tonic-gate * Get drive desc on this host for given setno. 48490Sstevel@tonic-gate * This is only used during a reconfig cycle. 48500Sstevel@tonic-gate * Returns a drive desc structure for the given mdsetname 48510Sstevel@tonic-gate * from this host. 48520Sstevel@tonic-gate * 48530Sstevel@tonic-gate * Returned drive desc structure is partially filled in with 48540Sstevel@tonic-gate * the drive name but is not filled in with any other strings 48550Sstevel@tonic-gate * in the drivename structure. 48560Sstevel@tonic-gate */ 48570Sstevel@tonic-gate bool_t 48580Sstevel@tonic-gate mdrpc_getdrivedesc_2_svc( 48590Sstevel@tonic-gate mdrpc_sp_2_args *args, 48600Sstevel@tonic-gate mdrpc_getdrivedesc_res *res, 48610Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 48620Sstevel@tonic-gate ) 48630Sstevel@tonic-gate { 48640Sstevel@tonic-gate md_drive_desc *dd; 48650Sstevel@tonic-gate md_error_t *ep = &res->status; 48660Sstevel@tonic-gate int err; 48670Sstevel@tonic-gate int op_mode = R_OK; 48680Sstevel@tonic-gate mdsetname_t *my_sp; 48690Sstevel@tonic-gate mdrpc_sp_args *args_r1; 48700Sstevel@tonic-gate 48710Sstevel@tonic-gate switch (args->rev) { 48720Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 48730Sstevel@tonic-gate /* setup, check permissions */ 48740Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 48750Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 48760Sstevel@tonic-gate return (FALSE); 48770Sstevel@tonic-gate else if (err != 0) 48780Sstevel@tonic-gate return (TRUE); 48790Sstevel@tonic-gate 48800Sstevel@tonic-gate /* doit */ 48810Sstevel@tonic-gate args_r1 = &args->mdrpc_sp_2_args_u.rev1; 48820Sstevel@tonic-gate if ((my_sp = metasetname(args_r1->sp->setname, ep)) == NULL) 48830Sstevel@tonic-gate return (TRUE); 48840Sstevel@tonic-gate 48850Sstevel@tonic-gate dd = metaget_drivedesc(my_sp, 48860Sstevel@tonic-gate (MD_BASICNAME_OK | PRINT_FAST), ep); 48870Sstevel@tonic-gate 48880Sstevel@tonic-gate res->dd = dd_list_dup(dd); 48890Sstevel@tonic-gate 48900Sstevel@tonic-gate err = svc_fini(ep); 48910Sstevel@tonic-gate 48920Sstevel@tonic-gate return (TRUE); 48930Sstevel@tonic-gate default: 48940Sstevel@tonic-gate return (FALSE); 48950Sstevel@tonic-gate } 48960Sstevel@tonic-gate } 48970Sstevel@tonic-gate 48980Sstevel@tonic-gate /* 48990Sstevel@tonic-gate * Update drive records given list from master during reconfig. 49000Sstevel@tonic-gate * Make this node's list match the master's list which may include 49010Sstevel@tonic-gate * deleting a drive record that is known by this node and not known 49020Sstevel@tonic-gate * by the master node. 49030Sstevel@tonic-gate * 49040Sstevel@tonic-gate * Sync up the set/node/drive record genids to match the genid 49050Sstevel@tonic-gate * passed in the dd structure (all genids in this structure 49060Sstevel@tonic-gate * are the same). 49070Sstevel@tonic-gate */ 49080Sstevel@tonic-gate bool_t 49090Sstevel@tonic-gate mdrpc_upd_dr_reconfig_common( 49100Sstevel@tonic-gate mdrpc_upd_dr_flags_2_args_r1 *args, 49110Sstevel@tonic-gate mdrpc_generic_res *res, 49120Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 49130Sstevel@tonic-gate ) 49140Sstevel@tonic-gate { 49150Sstevel@tonic-gate md_error_t *ep = &res->status; 49160Sstevel@tonic-gate int err; 49170Sstevel@tonic-gate mdsetname_t *local_sp; 49180Sstevel@tonic-gate md_set_record *sr; 49190Sstevel@tonic-gate md_mnset_record *mnsr; 49200Sstevel@tonic-gate md_drive_record *dr, *dr_placeholder = NULL; 49210Sstevel@tonic-gate md_drive_desc *dd; 49220Sstevel@tonic-gate mddrivename_t *dn, *dn1; 49230Sstevel@tonic-gate side_t sideno; 49240Sstevel@tonic-gate md_mnnode_record *nrp; 49250Sstevel@tonic-gate int op_mode = W_OK; 49260Sstevel@tonic-gate int change = 0; 49270Sstevel@tonic-gate 49280Sstevel@tonic-gate /* setup, check permissions */ 49290Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 49300Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 49310Sstevel@tonic-gate return (FALSE); 49320Sstevel@tonic-gate else if (err != 0) 49330Sstevel@tonic-gate return (TRUE); 49340Sstevel@tonic-gate 49350Sstevel@tonic-gate if ((local_sp = metasetname(args->sp->setname, ep)) == NULL) 49360Sstevel@tonic-gate return (TRUE); 49370Sstevel@tonic-gate 49380Sstevel@tonic-gate metaflushsetname(local_sp); 49390Sstevel@tonic-gate 49400Sstevel@tonic-gate if ((sideno = getmyside(local_sp, ep)) == MD_SIDEWILD) 49410Sstevel@tonic-gate return (TRUE); 49420Sstevel@tonic-gate 49430Sstevel@tonic-gate if ((sr = getsetbyname(args->sp->setname, ep)) == NULL) 49440Sstevel@tonic-gate return (TRUE); 49450Sstevel@tonic-gate 49460Sstevel@tonic-gate if (!(MD_MNSET_REC(sr))) { 49470Sstevel@tonic-gate free_sr(sr); 49480Sstevel@tonic-gate return (TRUE); 49490Sstevel@tonic-gate } 49500Sstevel@tonic-gate 49510Sstevel@tonic-gate mnsr = (md_mnset_record *)sr; 49520Sstevel@tonic-gate /* Setup genid on set and node records */ 49530Sstevel@tonic-gate if (args->drivedescs) { 49540Sstevel@tonic-gate if (mnsr->sr_genid != args->drivedescs->dd_genid) { 49550Sstevel@tonic-gate change = 1; 49560Sstevel@tonic-gate mnsr->sr_genid = args->drivedescs->dd_genid; 49570Sstevel@tonic-gate } 49580Sstevel@tonic-gate nrp = mnsr->sr_nodechain; 49590Sstevel@tonic-gate while (nrp) { 49600Sstevel@tonic-gate if (nrp->nr_genid != args->drivedescs->dd_genid) { 49610Sstevel@tonic-gate change = 1; 49620Sstevel@tonic-gate nrp->nr_genid = args->drivedescs->dd_genid; 49630Sstevel@tonic-gate } 49640Sstevel@tonic-gate nrp = nrp->nr_next; 49650Sstevel@tonic-gate } 49660Sstevel@tonic-gate } 49670Sstevel@tonic-gate for (dr = mnsr->sr_drivechain; dr; dr = dr->dr_next) { 49680Sstevel@tonic-gate dn1 = metadrivename_withdrkey(local_sp, sideno, 49690Sstevel@tonic-gate dr->dr_key, (MD_BASICNAME_OK | PRINT_FAST), ep); 49700Sstevel@tonic-gate if (dn1 == NULL) 49710Sstevel@tonic-gate goto out; 49720Sstevel@tonic-gate for (dd = args->drivedescs; dd != NULL; dd = dd->dd_next) { 49730Sstevel@tonic-gate dn = dd->dd_dnp; 49740Sstevel@tonic-gate /* Found this node's drive rec to match dd */ 49750Sstevel@tonic-gate if (strcmp(dn->cname, dn1->cname) == 0) 49760Sstevel@tonic-gate break; 49770Sstevel@tonic-gate } 49780Sstevel@tonic-gate 49790Sstevel@tonic-gate /* 49800Sstevel@tonic-gate * If drive found in master's list, make slave match master. 49810Sstevel@tonic-gate * If drive not found in master's list, remove drive. 49820Sstevel@tonic-gate */ 49830Sstevel@tonic-gate if (dd) { 49840Sstevel@tonic-gate if ((dr->dr_flags != dd->dd_flags) || 49850Sstevel@tonic-gate (dr->dr_genid != dd->dd_genid)) { 49860Sstevel@tonic-gate change = 1; 49870Sstevel@tonic-gate dr->dr_flags = dd->dd_flags; 49880Sstevel@tonic-gate dr->dr_genid = dd->dd_genid; 49890Sstevel@tonic-gate } 49900Sstevel@tonic-gate } else { 49910Sstevel@tonic-gate /* 49920Sstevel@tonic-gate * Delete entry from linked list. Need to use 49930Sstevel@tonic-gate * dr_placeholder so that dr->dr_next points to 49940Sstevel@tonic-gate * the next drive record in the list. 49950Sstevel@tonic-gate */ 49960Sstevel@tonic-gate if (dr_placeholder == NULL) { 49970Sstevel@tonic-gate dr_placeholder = 49980Sstevel@tonic-gate Zalloc(sizeof (md_drive_record)); 49990Sstevel@tonic-gate } 50000Sstevel@tonic-gate dr_placeholder->dr_next = dr->dr_next; 50010Sstevel@tonic-gate dr_placeholder->dr_key = dr->dr_key; 50020Sstevel@tonic-gate sr_del_drv(sr, dr->dr_selfid); 50030Sstevel@tonic-gate (void) del_sideno_sidenm(dr_placeholder->dr_key, 50040Sstevel@tonic-gate sideno, ep); 50050Sstevel@tonic-gate change = 1; 50060Sstevel@tonic-gate dr = dr_placeholder; 50070Sstevel@tonic-gate } 50080Sstevel@tonic-gate } 50090Sstevel@tonic-gate out: 50100Sstevel@tonic-gate /* If incore records are correct, don't need to write to disk */ 50110Sstevel@tonic-gate if (change) { 50120Sstevel@tonic-gate /* Don't increment the genid in commitset */ 50130Sstevel@tonic-gate commitset(sr, FALSE, ep); 50140Sstevel@tonic-gate } 50150Sstevel@tonic-gate free_sr(sr); 50160Sstevel@tonic-gate 50170Sstevel@tonic-gate err = svc_fini(ep); 50180Sstevel@tonic-gate 50190Sstevel@tonic-gate if (dr_placeholder != NULL) 50200Sstevel@tonic-gate Free(dr_placeholder); 50210Sstevel@tonic-gate 50220Sstevel@tonic-gate return (TRUE); 50230Sstevel@tonic-gate } 50240Sstevel@tonic-gate 50250Sstevel@tonic-gate /* 50260Sstevel@tonic-gate * Version 2 routine to update this node's drive records based on 50270Sstevel@tonic-gate * list passed in from master node. 50280Sstevel@tonic-gate */ 50290Sstevel@tonic-gate bool_t 50300Sstevel@tonic-gate mdrpc_upd_dr_reconfig_2_svc( 50310Sstevel@tonic-gate mdrpc_upd_dr_flags_2_args *args, 50320Sstevel@tonic-gate mdrpc_generic_res *res, 50330Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 50340Sstevel@tonic-gate ) 50350Sstevel@tonic-gate { 50360Sstevel@tonic-gate switch (args->rev) { 50370Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 50380Sstevel@tonic-gate return (mdrpc_upd_dr_reconfig_common( 50390Sstevel@tonic-gate &args->mdrpc_upd_dr_flags_2_args_u.rev1, res, rqstp)); 50400Sstevel@tonic-gate default: 50410Sstevel@tonic-gate return (FALSE); 50420Sstevel@tonic-gate } 50430Sstevel@tonic-gate } 50440Sstevel@tonic-gate 50450Sstevel@tonic-gate /* 50460Sstevel@tonic-gate * reset mirror owner for mirrors owned by deleted 50470Sstevel@tonic-gate * or withdrawn host(s). Hosts being deleted or 50480Sstevel@tonic-gate * withdrawn are designated by nodeid since host is 50490Sstevel@tonic-gate * already deleted or withdrawn from set and may not 50500Sstevel@tonic-gate * be able to translate between a nodename and a nodeid. 50510Sstevel@tonic-gate * If an error occurs, ep will be set to that error information. 50520Sstevel@tonic-gate */ 50530Sstevel@tonic-gate static void 50540Sstevel@tonic-gate reset_mirror_owner( 50550Sstevel@tonic-gate char *setname, 50560Sstevel@tonic-gate int node_c, 50570Sstevel@tonic-gate int *node_id, /* Array of node ids */ 50580Sstevel@tonic-gate md_error_t *ep 50590Sstevel@tonic-gate ) 50600Sstevel@tonic-gate { 50610Sstevel@tonic-gate mdsetname_t *local_sp; 50620Sstevel@tonic-gate int i; 50630Sstevel@tonic-gate mdnamelist_t *devnlp = NULL; 50640Sstevel@tonic-gate mdnamelist_t *p; 50650Sstevel@tonic-gate mdname_t *devnp = NULL; 50660Sstevel@tonic-gate md_set_mmown_params_t ownpar_p; 50670Sstevel@tonic-gate md_set_mmown_params_t *ownpar = &ownpar_p; 50680Sstevel@tonic-gate char *miscname; 50690Sstevel@tonic-gate 50700Sstevel@tonic-gate if ((local_sp = metasetname(setname, ep)) == NULL) 50710Sstevel@tonic-gate return; 50720Sstevel@tonic-gate 50730Sstevel@tonic-gate /* get a list of all the mirrors for current set */ 50740Sstevel@tonic-gate if (meta_get_mirror_names(local_sp, &devnlp, 0, ep) < 0) 50750Sstevel@tonic-gate return; 50760Sstevel@tonic-gate 50770Sstevel@tonic-gate /* for each mirror */ 50780Sstevel@tonic-gate for (p = devnlp; (p != NULL); p = p->next) { 50790Sstevel@tonic-gate devnp = p->namep; 50800Sstevel@tonic-gate 50810Sstevel@tonic-gate /* 50820Sstevel@tonic-gate * we can only do these for mirrors so make sure we 50830Sstevel@tonic-gate * really have a mirror device and not a softpartition 50840Sstevel@tonic-gate * imitating one. meta_get_mirror_names seems to think 50850Sstevel@tonic-gate * softparts on top of a mirror are mirrors! 50860Sstevel@tonic-gate */ 50870Sstevel@tonic-gate if ((miscname = metagetmiscname(devnp, ep)) == NULL) 50880Sstevel@tonic-gate goto out; 50890Sstevel@tonic-gate if (strcmp(miscname, MD_MIRROR) != 0) 50900Sstevel@tonic-gate continue; 50910Sstevel@tonic-gate 50920Sstevel@tonic-gate (void) memset(ownpar, 0, sizeof (*ownpar)); 50930Sstevel@tonic-gate ownpar->d.mnum = meta_getminor(devnp->dev); 50940Sstevel@tonic-gate MD_SETDRIVERNAME(ownpar, MD_MIRROR, local_sp->setno); 50950Sstevel@tonic-gate 50960Sstevel@tonic-gate /* get the current owner id */ 50970Sstevel@tonic-gate if (metaioctl(MD_MN_GET_MM_OWNER, ownpar, ep, 50980Sstevel@tonic-gate "MD_MN_GET_MM_OWNER") != 0) { 50990Sstevel@tonic-gate mde_perror(ep, gettext( 51000Sstevel@tonic-gate "Unable to get mirror owner for %s/d%u"), 51010Sstevel@tonic-gate local_sp->setname, 51020Sstevel@tonic-gate (unsigned)MD_MIN2UNIT(ownpar->d.mnum)); 51030Sstevel@tonic-gate goto out; 51040Sstevel@tonic-gate } 51050Sstevel@tonic-gate 51060Sstevel@tonic-gate if (ownpar->d.owner == MD_MN_MIRROR_UNOWNED) { 51070Sstevel@tonic-gate mdclrerror(ep); 51080Sstevel@tonic-gate continue; 51090Sstevel@tonic-gate } 51100Sstevel@tonic-gate /* 51110Sstevel@tonic-gate * reset owner only if the current owner is 51120Sstevel@tonic-gate * in the list of nodes being deleted. 51130Sstevel@tonic-gate */ 51140Sstevel@tonic-gate for (i = 0; i < node_c; i++) { 51150Sstevel@tonic-gate if (ownpar->d.owner == node_id[i]) { 51160Sstevel@tonic-gate if (meta_mn_change_owner(&ownpar, 51170Sstevel@tonic-gate local_sp->setno, ownpar->d.mnum, 51180Sstevel@tonic-gate MD_MN_MIRROR_UNOWNED, 51190Sstevel@tonic-gate MD_MN_MM_ALLOW_CHANGE) == -1) { 51200Sstevel@tonic-gate mde_perror(ep, gettext( 51210Sstevel@tonic-gate "Unable to reset mirror owner for" 51220Sstevel@tonic-gate " %s/d%u"), local_sp->setname, 51230Sstevel@tonic-gate (unsigned)MD_MIN2UNIT( 51240Sstevel@tonic-gate ownpar->d.mnum)); 51250Sstevel@tonic-gate goto out; 51260Sstevel@tonic-gate } 51270Sstevel@tonic-gate break; 51280Sstevel@tonic-gate } 51290Sstevel@tonic-gate } 51300Sstevel@tonic-gate } 51310Sstevel@tonic-gate 51320Sstevel@tonic-gate out: 51330Sstevel@tonic-gate /* cleanup */ 51340Sstevel@tonic-gate metafreenamelist(devnlp); 51350Sstevel@tonic-gate } 51360Sstevel@tonic-gate 51370Sstevel@tonic-gate /* 51380Sstevel@tonic-gate * Wrapper routine for reset_mirror_owner. 51390Sstevel@tonic-gate * Called when hosts are deleted or withdrawn 51400Sstevel@tonic-gate * in order to reset any mirror owners that are needed. 51410Sstevel@tonic-gate */ 51420Sstevel@tonic-gate bool_t 51430Sstevel@tonic-gate mdrpc_reset_mirror_owner_common( 51440Sstevel@tonic-gate mdrpc_nodeid_args *args, 51450Sstevel@tonic-gate mdrpc_generic_res *res, 51460Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 51470Sstevel@tonic-gate ) 51480Sstevel@tonic-gate { 51490Sstevel@tonic-gate md_error_t *ep = &res->status; 51500Sstevel@tonic-gate int err; 51510Sstevel@tonic-gate int op_mode = W_OK; 51520Sstevel@tonic-gate 51530Sstevel@tonic-gate /* setup, check permissions */ 51540Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 51550Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 51560Sstevel@tonic-gate return (FALSE); 51570Sstevel@tonic-gate else if (err != 0) 51580Sstevel@tonic-gate return (TRUE); 51590Sstevel@tonic-gate 51600Sstevel@tonic-gate if (check_set_lock(op_mode, args->cl_sk, ep)) 51610Sstevel@tonic-gate return (TRUE); 51620Sstevel@tonic-gate 51630Sstevel@tonic-gate /* doit */ 51640Sstevel@tonic-gate reset_mirror_owner(args->sp->setname, args->nodeid.nodeid_len, 51650Sstevel@tonic-gate args->nodeid.nodeid_val, ep); 51660Sstevel@tonic-gate 51670Sstevel@tonic-gate err = svc_fini(ep); 51680Sstevel@tonic-gate 51690Sstevel@tonic-gate return (TRUE); 51700Sstevel@tonic-gate } 51710Sstevel@tonic-gate 51720Sstevel@tonic-gate /* 51730Sstevel@tonic-gate * RPC service routine to reset the mirror owner for mirrors owned 51740Sstevel@tonic-gate * by the given hosts. Typically, the list of given hosts is a list 51750Sstevel@tonic-gate * of nodes being deleted or withdrawn from a diskset. 51760Sstevel@tonic-gate * The given hosts are designated by nodeid since host may 51770Sstevel@tonic-gate * already be deleted or withdrawn from set and may not 51780Sstevel@tonic-gate * be able to translate between a nodename and a nodeid. 51790Sstevel@tonic-gate */ 51800Sstevel@tonic-gate bool_t 51810Sstevel@tonic-gate mdrpc_reset_mirror_owner_2_svc( 51820Sstevel@tonic-gate mdrpc_nodeid_2_args *args, 51830Sstevel@tonic-gate mdrpc_generic_res *res, 51840Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 51850Sstevel@tonic-gate ) 51860Sstevel@tonic-gate { 51870Sstevel@tonic-gate switch (args->rev) { 51880Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 51890Sstevel@tonic-gate return (mdrpc_reset_mirror_owner_common( 51900Sstevel@tonic-gate &args->mdrpc_nodeid_2_args_u.rev1, res, 51910Sstevel@tonic-gate rqstp)); 51920Sstevel@tonic-gate default: 51930Sstevel@tonic-gate return (FALSE); 51940Sstevel@tonic-gate } 51950Sstevel@tonic-gate } 51960Sstevel@tonic-gate 51970Sstevel@tonic-gate /* 51980Sstevel@tonic-gate * Call routines to suspend and resume I/O for the given diskset(s). 51990Sstevel@tonic-gate * Called during reconfig cycle. 52000Sstevel@tonic-gate * Diskset of 0 represents all MN disksets. 52010Sstevel@tonic-gate */ 52020Sstevel@tonic-gate bool_t 52030Sstevel@tonic-gate mdrpc_mn_susp_res_io_2_svc( 52040Sstevel@tonic-gate mdrpc_mn_susp_res_io_2_args *args, 52050Sstevel@tonic-gate mdrpc_generic_res *res, 52060Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 52070Sstevel@tonic-gate ) 52080Sstevel@tonic-gate { 52090Sstevel@tonic-gate mdrpc_mn_susp_res_io_args *args_sr; 52100Sstevel@tonic-gate md_error_t *ep = &res->status; 52110Sstevel@tonic-gate int err; 52120Sstevel@tonic-gate int op_mode = R_OK; 52130Sstevel@tonic-gate 52140Sstevel@tonic-gate switch (args->rev) { 52150Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 52160Sstevel@tonic-gate /* setup, check permissions */ 52170Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 52180Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 52190Sstevel@tonic-gate return (FALSE); 52200Sstevel@tonic-gate else if (err != 0) 52210Sstevel@tonic-gate return (TRUE); 52220Sstevel@tonic-gate 52230Sstevel@tonic-gate args_sr = &(args->mdrpc_mn_susp_res_io_2_args_u.rev1); 52240Sstevel@tonic-gate switch (args_sr->susp_res_cmd) { 52250Sstevel@tonic-gate case MN_SUSP_IO: 52260Sstevel@tonic-gate (void) (metaioctl(MD_MN_SUSPEND_SET, 52270Sstevel@tonic-gate &args_sr->susp_res_setno, ep, NULL)); 52280Sstevel@tonic-gate break; 52290Sstevel@tonic-gate case MN_RES_IO: 52300Sstevel@tonic-gate (void) (metaioctl(MD_MN_RESUME_SET, 52310Sstevel@tonic-gate &args_sr->susp_res_setno, ep, NULL)); 52320Sstevel@tonic-gate break; 52330Sstevel@tonic-gate } 52340Sstevel@tonic-gate err = svc_fini(ep); 52350Sstevel@tonic-gate return (TRUE); 52360Sstevel@tonic-gate 52370Sstevel@tonic-gate default: 52380Sstevel@tonic-gate return (FALSE); 52390Sstevel@tonic-gate } 52400Sstevel@tonic-gate } 52410Sstevel@tonic-gate 52420Sstevel@tonic-gate /* 52430Sstevel@tonic-gate * Resnarf a set after it has been imported 52440Sstevel@tonic-gate */ 52450Sstevel@tonic-gate bool_t 52460Sstevel@tonic-gate mdrpc_resnarf_set_2_svc( 52470Sstevel@tonic-gate mdrpc_setno_2_args *args, 52480Sstevel@tonic-gate mdrpc_generic_res *res, 52490Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 52500Sstevel@tonic-gate ) 52510Sstevel@tonic-gate { 52520Sstevel@tonic-gate mdrpc_setno_args *setno_args; 52530Sstevel@tonic-gate md_error_t *ep = &res->status; 52540Sstevel@tonic-gate int err; 52550Sstevel@tonic-gate int op_mode = R_OK; 52560Sstevel@tonic-gate 52570Sstevel@tonic-gate switch (args->rev) { 52580Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 52590Sstevel@tonic-gate setno_args = &args->mdrpc_setno_2_args_u.rev1; 52600Sstevel@tonic-gate break; 52610Sstevel@tonic-gate default: 52620Sstevel@tonic-gate return (FALSE); 52630Sstevel@tonic-gate } 52640Sstevel@tonic-gate 52650Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 52660Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 52670Sstevel@tonic-gate return (FALSE); 52680Sstevel@tonic-gate else if (err != 0) 52690Sstevel@tonic-gate return (TRUE); 52700Sstevel@tonic-gate 52710Sstevel@tonic-gate /* do it */ 52720Sstevel@tonic-gate if (resnarf_set(setno_args->setno, ep) < 0) 52730Sstevel@tonic-gate return (FALSE); 52740Sstevel@tonic-gate 52750Sstevel@tonic-gate err = svc_fini(ep); 52760Sstevel@tonic-gate return (TRUE); 52770Sstevel@tonic-gate } 52780Sstevel@tonic-gate 52790Sstevel@tonic-gate /* 52800Sstevel@tonic-gate * Creates a resync thread. 52810Sstevel@tonic-gate * Always returns true. 52820Sstevel@tonic-gate */ 52830Sstevel@tonic-gate bool_t 52840Sstevel@tonic-gate mdrpc_mn_mirror_resync_all_2_svc( 52850Sstevel@tonic-gate mdrpc_setno_2_args *args, 52860Sstevel@tonic-gate mdrpc_generic_res *res, 52870Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 52880Sstevel@tonic-gate ) 52890Sstevel@tonic-gate { 52900Sstevel@tonic-gate md_error_t *ep = &res->status; 52910Sstevel@tonic-gate mdrpc_setno_args *setno_args; 52920Sstevel@tonic-gate int err; 52930Sstevel@tonic-gate int op_mode = R_OK; 52940Sstevel@tonic-gate 52950Sstevel@tonic-gate switch (args->rev) { 52960Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 52970Sstevel@tonic-gate /* setup, check permissions */ 52980Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 52990Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 53000Sstevel@tonic-gate return (FALSE); 53010Sstevel@tonic-gate else if (err != 0) 53020Sstevel@tonic-gate return (TRUE); 53030Sstevel@tonic-gate setno_args = &args->mdrpc_setno_2_args_u.rev1; 53040Sstevel@tonic-gate 53050Sstevel@tonic-gate /* 53060Sstevel@tonic-gate * Need to invoke a metasync on a node newly added to a set. 53070Sstevel@tonic-gate */ 53080Sstevel@tonic-gate meta_mn_mirror_resync_all(&(setno_args->setno)); 53090Sstevel@tonic-gate 53100Sstevel@tonic-gate err = svc_fini(ep); 53110Sstevel@tonic-gate return (TRUE); 53120Sstevel@tonic-gate 53130Sstevel@tonic-gate default: 53140Sstevel@tonic-gate return (FALSE); 53150Sstevel@tonic-gate } 53160Sstevel@tonic-gate } 53170Sstevel@tonic-gate 53180Sstevel@tonic-gate /* 53190Sstevel@tonic-gate * Updates ABR state for all softpartitions. Calls meta_mn_sp_update_abr(), 53200Sstevel@tonic-gate * which forks a daemon process to perform this action. 53210Sstevel@tonic-gate * Always returns true. 53220Sstevel@tonic-gate */ 53230Sstevel@tonic-gate bool_t 53240Sstevel@tonic-gate mdrpc_mn_sp_update_abr_2_svc( 53250Sstevel@tonic-gate mdrpc_setno_2_args *args, 53260Sstevel@tonic-gate mdrpc_generic_res *res, 53270Sstevel@tonic-gate struct svc_req *rqstp /* RPC stuff */ 53280Sstevel@tonic-gate ) 53290Sstevel@tonic-gate { 53300Sstevel@tonic-gate md_error_t *ep = &res->status; 53310Sstevel@tonic-gate mdrpc_setno_args *setno_args; 53320Sstevel@tonic-gate int err; 53330Sstevel@tonic-gate int op_mode = R_OK; 53340Sstevel@tonic-gate 53350Sstevel@tonic-gate switch (args->rev) { 53360Sstevel@tonic-gate case MD_METAD_ARGS_REV_1: 53370Sstevel@tonic-gate /* setup, check permissions */ 53380Sstevel@tonic-gate (void) memset(res, 0, sizeof (*res)); 53390Sstevel@tonic-gate if ((err = svc_init(rqstp, op_mode, ep)) < 0) 53400Sstevel@tonic-gate return (FALSE); 53410Sstevel@tonic-gate else if (err != 0) 53420Sstevel@tonic-gate return (TRUE); 53430Sstevel@tonic-gate setno_args = &args->mdrpc_setno_2_args_u.rev1; 53440Sstevel@tonic-gate 53450Sstevel@tonic-gate meta_mn_sp_update_abr(&(setno_args->setno)); 53460Sstevel@tonic-gate 53470Sstevel@tonic-gate err = svc_fini(ep); 53480Sstevel@tonic-gate return (TRUE); 53490Sstevel@tonic-gate 53500Sstevel@tonic-gate default: 53510Sstevel@tonic-gate return (FALSE); 53520Sstevel@tonic-gate } 53530Sstevel@tonic-gate } 5354