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 51320Srd117015 * Common Development and Distribution License (the "License"). 61320Srd117015 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*4932Spetede * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * Metadevice diskset utility. 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <meta.h> 330Sstevel@tonic-gate #include <sys/lvm/md_mddb.h> 340Sstevel@tonic-gate #include <sdssc.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate enum metaset_cmd { 370Sstevel@tonic-gate notspecified, 380Sstevel@tonic-gate add, 390Sstevel@tonic-gate balance, 400Sstevel@tonic-gate delete, 410Sstevel@tonic-gate cluster, 420Sstevel@tonic-gate isowner, 430Sstevel@tonic-gate purge, 440Sstevel@tonic-gate query, 450Sstevel@tonic-gate release, 460Sstevel@tonic-gate take, 470Sstevel@tonic-gate join, /* Join a multinode diskset */ 480Sstevel@tonic-gate withdraw /* Withdraw from a multinode diskset */ 490Sstevel@tonic-gate }; 500Sstevel@tonic-gate 510Sstevel@tonic-gate enum cluster_cmd { 520Sstevel@tonic-gate ccnotspecified, 530Sstevel@tonic-gate clusterversion, /* Return the version of the cluster I/F */ 540Sstevel@tonic-gate clusterdisksin, /* List disks in a given diskset */ 550Sstevel@tonic-gate clustertake, /* back door for Cluster take */ 560Sstevel@tonic-gate clusterrelease, /* ditto */ 570Sstevel@tonic-gate clusterpurge, /* back door for Cluster purge */ 580Sstevel@tonic-gate clusterproxy /* proxy the args after '--' to primary */ 590Sstevel@tonic-gate }; 600Sstevel@tonic-gate 610Sstevel@tonic-gate static void 620Sstevel@tonic-gate usage( 630Sstevel@tonic-gate mdsetname_t *sp, 640Sstevel@tonic-gate char *string) 650Sstevel@tonic-gate { 660Sstevel@tonic-gate if ((string != NULL) && (*string != '\0')) 670Sstevel@tonic-gate md_eprintf("%s\n", string); 680Sstevel@tonic-gate (void) fprintf(stderr, gettext( 69*4932Spetede "usage:\t%s -s setname -a [-A enable | disable] -h hostname ...\n" 70*4932Spetede " %s -s setname -a [-M] -h hostname ...\n" 71*4932Spetede " %s -s setname -a [-M] [-l length] [-L] drivename ...\n" 72*4932Spetede " %s -s setname -d [-M] -h hostname ...\n" 73*4932Spetede " %s -s setname -d [-M] -f -h all-hostnames\n" 74*4932Spetede " %s -s setname -d [-M] [-f] drivename ...\n" 75*4932Spetede " %s -s setname -d [-M] [-f] hostname ...\n" 76*4932Spetede " %s -s setname -A enable | disable\n" 77*4932Spetede " %s -s setname -t [-f]\n" 78*4932Spetede " %s -s setname -r\n" 79*4932Spetede " %s [-s setname] -j [-M]\n" 80*4932Spetede " %s [-s setname] -w [-M]\n" 81*4932Spetede " %s -s setname -P [-M]\n" 82*4932Spetede " %s -s setname -b [-M]\n" 83*4932Spetede " %s -s setname -o [-M] [-h hostname]\n" 84*4932Spetede " %s [-s setname]\n" 85*4932Spetede "\n" 86*4932Spetede " hostname = contents of /etc/nodename\n" 87*4932Spetede " drivename = cNtNdN no slice\n" 88*4932Spetede " [-M] for multi-owner set is optional except" 89*4932Spetede " on set creation\n"), 90*4932Spetede myname, myname, myname, myname, myname, myname, myname, myname, 91*4932Spetede myname, myname, myname, myname, myname, myname, myname, myname); 920Sstevel@tonic-gate md_exit(sp, (string == NULL) ? 0 : 1); 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * The svm.sync rc script relies heavily on the metaset output. 970Sstevel@tonic-gate * Any changes to the metaset output MUST verify that the rc script 980Sstevel@tonic-gate * does not break. Not doing so may potentially leave the system 990Sstevel@tonic-gate * unusable. You have been WARNED. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate static int 1020Sstevel@tonic-gate printset(mdsetname_t *sp, md_error_t *ep) 1030Sstevel@tonic-gate { 1040Sstevel@tonic-gate int i, j; 1050Sstevel@tonic-gate md_set_desc *sd; 1060Sstevel@tonic-gate md_drive_desc *dd, *p; 1070Sstevel@tonic-gate int max_meds; 1080Sstevel@tonic-gate md_mnnode_desc *nd; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) 1110Sstevel@tonic-gate return (-1); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* 1140Sstevel@tonic-gate * Only get set owner information for traditional diskset. 1150Sstevel@tonic-gate * This set owner information is stored in the node records 1160Sstevel@tonic-gate * for a MN diskset. 1170Sstevel@tonic-gate */ 1180Sstevel@tonic-gate if (!(MD_MNSET_DESC(sd))) { 1190Sstevel@tonic-gate if (metaget_setownership(sp, ep) == -1) 1200Sstevel@tonic-gate return (-1); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate if (((dd = metaget_drivedesc(sp, (MD_BASICNAME_OK | PRINT_FAST), 1240Sstevel@tonic-gate ep)) == NULL) && !mdisok(ep)) 1250Sstevel@tonic-gate return (-1); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 1280Sstevel@tonic-gate (void) printf(gettext( 1290Sstevel@tonic-gate "\nMulti-owner Set name = %s, Set number = %d, Master = %s\n"), 1300Sstevel@tonic-gate sp->setname, sp->setno, sd->sd_mn_master_nodenm); 1310Sstevel@tonic-gate if ((sd->sd_mn_master_nodeid == MD_MN_INVALID_NID) && 1320Sstevel@tonic-gate (dd != NULL)) { 1330Sstevel@tonic-gate (void) printf(gettext( 134*4932Spetede "Master and owner information unavailable " 135*4932Spetede "until joined (metaset -j)\n")); 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate } else { 1380Sstevel@tonic-gate (void) printf(gettext( 1390Sstevel@tonic-gate "\nSet name = %s, Set number = %d\n"), 1400Sstevel@tonic-gate sp->setname, sp->setno); 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 1440Sstevel@tonic-gate (void) printf(gettext("\n%-19.19s %-14.14s %-6.6s\n"), 145*4932Spetede gettext("Host"), gettext("Owner"), gettext("Member")); 1460Sstevel@tonic-gate nd = sd->sd_nodelist; 1470Sstevel@tonic-gate while (nd) { 1480Sstevel@tonic-gate /* 1490Sstevel@tonic-gate * Don't print nodes that aren't ok since they may be 1500Sstevel@tonic-gate * removed from config during a reconfig cycle. If a 1510Sstevel@tonic-gate * node was being added to a diskset and the entire 1520Sstevel@tonic-gate * cluster went down but the node being added was unable 1530Sstevel@tonic-gate * to reboot, there's no way to know if that node had 1540Sstevel@tonic-gate * its own node record set to OK or not. So, node 1550Sstevel@tonic-gate * record is left in ADD state during reconfig cycle. 1560Sstevel@tonic-gate * When that node reboots and returns to the cluster, 1570Sstevel@tonic-gate * the reconfig cycle will either remove the node 1580Sstevel@tonic-gate * record (if not marked OK on that node) or will mark 1590Sstevel@tonic-gate * it OK on all nodes. 1600Sstevel@tonic-gate * It is very important to only remove a node record 1610Sstevel@tonic-gate * from the other nodes when that node record is not 1620Sstevel@tonic-gate * marked OK on its own node - otherwise, different 1630Sstevel@tonic-gate * nodes would have different nodelists possibly 1640Sstevel@tonic-gate * causing different nodes to to choose different 1650Sstevel@tonic-gate * masters. 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate if (!(nd->nd_flags & MD_MN_NODE_OK)) { 1680Sstevel@tonic-gate nd = nd->nd_next; 1690Sstevel@tonic-gate continue; 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate if ((nd->nd_flags & MD_MN_NODE_ALIVE) && 1720Sstevel@tonic-gate (nd->nd_flags & MD_MN_NODE_OWN)) { 1730Sstevel@tonic-gate (void) printf( 1740Sstevel@tonic-gate gettext(" %-17.17s %-12.12s %-4.4s\n"), 1750Sstevel@tonic-gate nd->nd_nodename, gettext("multi-owner"), 1760Sstevel@tonic-gate gettext("Yes")); 177*4932Spetede } else if ((!(nd->nd_flags & MD_MN_NODE_ALIVE)) && 1780Sstevel@tonic-gate (nd->nd_flags & MD_MN_NODE_OWN)) { 179*4932Spetede /* Should never be able to happen */ 1800Sstevel@tonic-gate (void) printf( 1810Sstevel@tonic-gate gettext(" %-17.17s %-12.12s %-4.4s\n"), 1820Sstevel@tonic-gate nd->nd_nodename, gettext("multi-owner"), 1830Sstevel@tonic-gate gettext("No")); 1840Sstevel@tonic-gate } else if ((nd->nd_flags & MD_MN_NODE_ALIVE) && 1850Sstevel@tonic-gate (!(nd->nd_flags & MD_MN_NODE_OWN))) { 1860Sstevel@tonic-gate (void) printf( 1870Sstevel@tonic-gate gettext(" %-17.17s %-12.12s %-4.4s\n"), 1880Sstevel@tonic-gate nd->nd_nodename, gettext(""), 1890Sstevel@tonic-gate gettext("Yes")); 1900Sstevel@tonic-gate } else if ((!(nd->nd_flags & MD_MN_NODE_ALIVE)) && 1910Sstevel@tonic-gate (!(nd->nd_flags & MD_MN_NODE_OWN))) { 1920Sstevel@tonic-gate (void) printf( 1930Sstevel@tonic-gate gettext(" %-17.17s %-12.12s %-4.4s\n"), 1940Sstevel@tonic-gate nd->nd_nodename, gettext(""), 1950Sstevel@tonic-gate gettext("No")); 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate nd = nd->nd_next; 1980Sstevel@tonic-gate } 1990Sstevel@tonic-gate } else { 2000Sstevel@tonic-gate (void) printf("\n%-19.19s %-5.5s\n", 201*4932Spetede gettext("Host"), gettext("Owner")); 2020Sstevel@tonic-gate for (i = 0; i < MD_MAXSIDES; i++) { 2030Sstevel@tonic-gate /* Skip empty slots */ 2040Sstevel@tonic-gate if (sd->sd_nodes[i][0] == '\0') 2050Sstevel@tonic-gate continue; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * Standard hostname field is 17 bytes but metaset will 2090Sstevel@tonic-gate * display up to MD_MAX_NODENAME, def in meta_basic.h 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate (void) printf(" %-17.*s %s\n", MD_MAX_NODENAME, 2120Sstevel@tonic-gate sd->sd_nodes[i], (sd->sd_flags & MD_SR_AUTO_TAKE ? 213*4932Spetede (sd->sd_isown[i] ? gettext("Yes (auto)") : 214*4932Spetede gettext("No (auto)")) 215*4932Spetede : (sd->sd_isown[i] ? gettext("Yes") : ""))); 2160Sstevel@tonic-gate } 2170Sstevel@tonic-gate } 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate if (sd->sd_med.n_cnt > 0) 2200Sstevel@tonic-gate (void) printf("\n%-19.19s %-7.7s\n", 2210Sstevel@tonic-gate gettext("Mediator Host(s)"), gettext("Aliases")); 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate if ((max_meds = get_max_meds(ep)) == 0) 2240Sstevel@tonic-gate return (-1); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate for (i = 0; i < max_meds; i++) { 2270Sstevel@tonic-gate if (sd->sd_med.n_lst[i].a_cnt == 0) 2280Sstevel@tonic-gate continue; 2292063Shshaw /* 2302063Shshaw * Standard hostname field is 17 bytes but metaset will 2312063Shshaw * display up to MD_MAX_NODENAME, def in meta_basic.h 2322063Shshaw */ 2332063Shshaw (void) printf(" %-17.*s ", MD_MAX_NODENAME, 234*4932Spetede sd->sd_med.n_lst[i].a_nm[0]); 2350Sstevel@tonic-gate for (j = 1; j < sd->sd_med.n_lst[i].a_cnt; j++) { 2360Sstevel@tonic-gate (void) printf("%s", sd->sd_med.n_lst[i].a_nm[j]); 2370Sstevel@tonic-gate if (sd->sd_med.n_lst[i].a_cnt - j > 1) 2380Sstevel@tonic-gate (void) printf(gettext(", ")); 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate (void) printf("\n"); 2410Sstevel@tonic-gate } 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate if (dd) { 2440Sstevel@tonic-gate int len = 0; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate /* 2480Sstevel@tonic-gate * Building a format string on the fly that will 2490Sstevel@tonic-gate * be used in (f)printf. This allows the length 2500Sstevel@tonic-gate * of the ctd to vary from small to large without 2510Sstevel@tonic-gate * looking horrible. 2520Sstevel@tonic-gate */ 2530Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) 2540Sstevel@tonic-gate len = max(len, strlen(p->dd_dnp->cname)); 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate len += 2; 2570Sstevel@tonic-gate (void) printf("\n%-*.*s %-5.5s\n", len, len, 2580Sstevel@tonic-gate gettext("Drive"), 2590Sstevel@tonic-gate gettext("Dbase")); 2600Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) { 2610Sstevel@tonic-gate (void) printf("\n%-*.*s %-5.5s\n", len, len, 2620Sstevel@tonic-gate p->dd_dnp->cname, 2630Sstevel@tonic-gate (p->dd_dbcnt ? gettext("Yes") : 2640Sstevel@tonic-gate gettext("No"))); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate return (0); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate static int 2720Sstevel@tonic-gate printsets(mdsetname_t *sp, md_error_t *ep) 2730Sstevel@tonic-gate { 2740Sstevel@tonic-gate int i; 2750Sstevel@tonic-gate mdsetname_t *sp1; 2760Sstevel@tonic-gate set_t max_sets; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /* 2790Sstevel@tonic-gate * print setname given. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate if (! metaislocalset(sp)) { 2820Sstevel@tonic-gate if (printset(sp, ep)) 2830Sstevel@tonic-gate return (-1); 2840Sstevel@tonic-gate return (0); 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate if ((max_sets = get_max_sets(ep)) == 0) 2880Sstevel@tonic-gate return (-1); 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate /* 2910Sstevel@tonic-gate * Print all known sets 2920Sstevel@tonic-gate */ 2930Sstevel@tonic-gate for (i = 1; i < max_sets; i++) { 2940Sstevel@tonic-gate if ((sp1 = metasetnosetname(i, ep)) == NULL) { 2950Sstevel@tonic-gate if (! mdiserror(ep, MDE_NO_SET)) 2960Sstevel@tonic-gate break; 2970Sstevel@tonic-gate mdclrerror(ep); 2980Sstevel@tonic-gate continue; 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate if (printset(sp1, ep)) 3020Sstevel@tonic-gate break; 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate if (! mdisok(ep)) 3050Sstevel@tonic-gate return (-1); 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate return (0); 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate /* 3110Sstevel@tonic-gate * Print the current versionn of the cluster contract private interface. 3120Sstevel@tonic-gate */ 3130Sstevel@tonic-gate static void 3140Sstevel@tonic-gate printclusterversion() 3150Sstevel@tonic-gate { 3160Sstevel@tonic-gate printf("%s\n", METASETIFVERSION); 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* 3200Sstevel@tonic-gate * Print the disks that make up the given disk set. This is used 3210Sstevel@tonic-gate * exclusively by Sun Cluster and is contract private. 3220Sstevel@tonic-gate * Should never be called with sname of a Multinode diskset. 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate static int 3250Sstevel@tonic-gate printdisksin(char *sname, md_error_t *ep) 3260Sstevel@tonic-gate { 3270Sstevel@tonic-gate mdsetname_t *sp; 3280Sstevel@tonic-gate md_drive_desc *dd, *p; 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate /* 3330Sstevel@tonic-gate * During a deletion of a set the associated service is 3340Sstevel@tonic-gate * put offline. The SC3.0 reservation code calls disksuite 3350Sstevel@tonic-gate * to find a list of disks associated with the set so that 3360Sstevel@tonic-gate * it can release the reservation on those disks. In this 3370Sstevel@tonic-gate * case there won't be any disks or even a set left. So just 3380Sstevel@tonic-gate * return. 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate return (0); 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate if (metaget_setownership(sp, ep) == -1) 3440Sstevel@tonic-gate return (-1); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate if (((dd = metaget_drivedesc(sp, (MD_BASICNAME_OK | PRINT_FAST), 3470Sstevel@tonic-gate ep)) == NULL) && !mdisok(ep)) 3480Sstevel@tonic-gate return (-1); 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate for (p = dd; p != NULL; p = p->dd_next) 3510Sstevel@tonic-gate (void) printf("%s\n", p->dd_dnp->rname); 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate return (0); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate static void 3570Sstevel@tonic-gate parse_printset(int argc, char **argv) 3580Sstevel@tonic-gate { 3590Sstevel@tonic-gate int c; 3600Sstevel@tonic-gate mdsetname_t *sp = NULL; 3610Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 3620Sstevel@tonic-gate md_error_t status = mdnullerror; 3630Sstevel@tonic-gate md_error_t *ep = &status; 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate /* reset and parse args */ 3660Sstevel@tonic-gate optind = 1; 3670Sstevel@tonic-gate opterr = 1; 3680Sstevel@tonic-gate while ((c = getopt(argc, argv, "s:")) != -1) { 3690Sstevel@tonic-gate switch (c) { 3700Sstevel@tonic-gate case 's': 3710Sstevel@tonic-gate sname = optarg; 3720Sstevel@tonic-gate break; 3730Sstevel@tonic-gate default: 3740Sstevel@tonic-gate usage(sp, gettext("unknown options")); 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate argc -= optind; 3790Sstevel@tonic-gate argv += optind; 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate if (argc != 0) 3820Sstevel@tonic-gate usage(sp, gettext("too many args")); 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 3850Sstevel@tonic-gate mde_perror(ep, ""); 3860Sstevel@tonic-gate md_exit(sp, 1); 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate if (printsets(sp, ep) && !mdiserror(ep, MDE_SMF_NO_SERVICE)) { 3900Sstevel@tonic-gate mde_perror(ep, ""); 3910Sstevel@tonic-gate md_exit(sp, 1); 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate if (meta_smf_isonline(meta_smf_getmask(), ep) == 0) { 3950Sstevel@tonic-gate mde_perror(ep, ""); 3960Sstevel@tonic-gate md_exit(sp, 1); 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate md_exit(sp, 0); 4000Sstevel@tonic-gate } 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate static void 4030Sstevel@tonic-gate parse_add(int argc, char **argv) 4040Sstevel@tonic-gate { 405*4932Spetede int c, created_set; 406*4932Spetede int hosts = FALSE; 407*4932Spetede int meds = FALSE; 408*4932Spetede int auto_take = FALSE; 409*4932Spetede int force_label = FALSE; 410*4932Spetede int default_size = TRUE; 4110Sstevel@tonic-gate mdsetname_t *sp = NULL; 4120Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 413*4932Spetede md_error_t status = mdnullerror; 414*4932Spetede md_error_t *ep = &status; 4150Sstevel@tonic-gate mddrivenamelist_t *dnlp = NULL; 4160Sstevel@tonic-gate mddrivenamelist_t *p; 417*4932Spetede daddr_t dbsize, nblks; 4180Sstevel@tonic-gate mdsetname_t *local_sp = NULL; 4190Sstevel@tonic-gate int multi_node = 0; 4200Sstevel@tonic-gate md_set_desc *sd; 4210Sstevel@tonic-gate rval_e sdssc_rval; 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /* reset and parse args */ 4240Sstevel@tonic-gate optind = 1; 4250Sstevel@tonic-gate opterr = 1; 4260Sstevel@tonic-gate while ((c = getopt(argc, argv, "MaA:hl:Lms:")) != -1) { 4270Sstevel@tonic-gate switch (c) { 4280Sstevel@tonic-gate case 'M': 4290Sstevel@tonic-gate multi_node = 1; 4300Sstevel@tonic-gate break; 4310Sstevel@tonic-gate case 'A': 4320Sstevel@tonic-gate /* verified sub-option in main */ 4330Sstevel@tonic-gate if (strcmp(optarg, "enable") == 0) 4340Sstevel@tonic-gate auto_take = TRUE; 4350Sstevel@tonic-gate break; 4360Sstevel@tonic-gate case 'a': 4370Sstevel@tonic-gate break; 4380Sstevel@tonic-gate case 'h': 4390Sstevel@tonic-gate case 'm': 4400Sstevel@tonic-gate if (meds == TRUE || hosts == TRUE) 4410Sstevel@tonic-gate usage(sp, gettext( 4420Sstevel@tonic-gate "only one -m or -h option allowed")); 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate if (default_size == FALSE || force_label == TRUE) 4450Sstevel@tonic-gate usage(sp, gettext( 4460Sstevel@tonic-gate "conflicting options")); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate if (c == 'h') 4490Sstevel@tonic-gate hosts = TRUE; 4500Sstevel@tonic-gate else 4510Sstevel@tonic-gate meds = TRUE; 4520Sstevel@tonic-gate break; 4530Sstevel@tonic-gate case 'l': 4540Sstevel@tonic-gate if (hosts == TRUE || meds == TRUE) 4550Sstevel@tonic-gate usage(sp, gettext( 4560Sstevel@tonic-gate "conflicting options")); 4570Sstevel@tonic-gate if (sscanf(optarg, "%ld", &dbsize) != 1) { 4580Sstevel@tonic-gate md_eprintf(gettext( 4590Sstevel@tonic-gate "%s: bad format\n"), optarg); 4600Sstevel@tonic-gate usage(sp, ""); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate default_size = FALSE; 4640Sstevel@tonic-gate break; 4650Sstevel@tonic-gate case 'L': 4660Sstevel@tonic-gate /* Same criteria as -l */ 4670Sstevel@tonic-gate if (hosts == TRUE || meds == TRUE) 4680Sstevel@tonic-gate usage(sp, gettext( 4690Sstevel@tonic-gate "conflicting options")); 4700Sstevel@tonic-gate force_label = TRUE; 4710Sstevel@tonic-gate break; 4720Sstevel@tonic-gate case 's': 4730Sstevel@tonic-gate sname = optarg; 4740Sstevel@tonic-gate break; 4750Sstevel@tonic-gate default: 4760Sstevel@tonic-gate usage(sp, gettext( 4770Sstevel@tonic-gate "unknown options")); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* Can only use -A enable when creating the single-node set */ 4820Sstevel@tonic-gate if (auto_take && hosts != TRUE) 4830Sstevel@tonic-gate usage(sp, gettext("conflicting options")); 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate argc -= optind; 4860Sstevel@tonic-gate argv += optind; 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* 4890Sstevel@tonic-gate * Add hosts 4900Sstevel@tonic-gate */ 4910Sstevel@tonic-gate if (hosts == TRUE) { 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 4940Sstevel@tonic-gate mde_perror(ep, ""); 4950Sstevel@tonic-gate md_exit(local_sp, 1); 4960Sstevel@tonic-gate } 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 4990Sstevel@tonic-gate mde_perror(ep, ""); 5000Sstevel@tonic-gate md_exit(local_sp, 1); 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate /* 5040Sstevel@tonic-gate * Keep track of Cluster set creation. Need to complete 5050Sstevel@tonic-gate * the transaction no matter if the set was created or not. 5060Sstevel@tonic-gate */ 5070Sstevel@tonic-gate created_set = 0; 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate /* 5100Sstevel@tonic-gate * Have no set, cannot take the lock, so only take the 5110Sstevel@tonic-gate * local lock. 5120Sstevel@tonic-gate */ 5130Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 5140Sstevel@tonic-gate sdssc_rval = 0; 5150Sstevel@tonic-gate if (multi_node) { 5160Sstevel@tonic-gate /* 5170Sstevel@tonic-gate * When running on a cluster system that 5180Sstevel@tonic-gate * does not support MN disksets, the routine 5190Sstevel@tonic-gate * sdssc_mo_create_begin will be bound 5200Sstevel@tonic-gate * to the SVM routine not_bound_error 5210Sstevel@tonic-gate * which returns SDSSC_NOT_BOUND_ERROR. 5220Sstevel@tonic-gate * 5230Sstevel@tonic-gate * When running on a cluster system that 5240Sstevel@tonic-gate * does support MN disksets, the routine 5250Sstevel@tonic-gate * sdssc_mo_create_begin will be bound to 5260Sstevel@tonic-gate * the sdssc_mo_create_begin routine in 5270Sstevel@tonic-gate * library libsdssc_so. A call to 5280Sstevel@tonic-gate * sdssc_mo_create_begin will return with 5290Sstevel@tonic-gate * either SDSSC_ERROR or SDSSC_OKAY. If 5300Sstevel@tonic-gate * an SDSSC_OKAY is returned, then the 5310Sstevel@tonic-gate * cluster framework has allocated a 5320Sstevel@tonic-gate * set number for this new set that is unique 5330Sstevel@tonic-gate * across traditional and MN disksets. 5340Sstevel@tonic-gate * Libmeta will get this unique set number 5350Sstevel@tonic-gate * by calling sdssc_get_index. 5360Sstevel@tonic-gate * 5370Sstevel@tonic-gate * When running on a non-cluster system, 5380Sstevel@tonic-gate * the routine sdssc_mo_create_begin 5390Sstevel@tonic-gate * will be bound to the SVM routine 5400Sstevel@tonic-gate * not_bound which returns SDSSC_NOT_BOUND. 5410Sstevel@tonic-gate * In this case, all sdssc routines will 5420Sstevel@tonic-gate * return SDSSC_NOT_BOUND. No need to check 5430Sstevel@tonic-gate * for return value of SDSSC_NOT_BOUND since 5440Sstevel@tonic-gate * the libmeta call to get the set number 5450Sstevel@tonic-gate * (sdssc_get_index) will also fail with 5460Sstevel@tonic-gate * SDSSC_NOT_BOUND causing libmeta to 5470Sstevel@tonic-gate * determine its own set number. 5480Sstevel@tonic-gate */ 5490Sstevel@tonic-gate sdssc_rval = sdssc_mo_create_begin(sname, argc, 550*4932Spetede argv, SDSSC_PICK_SETNO); 5510Sstevel@tonic-gate if (sdssc_rval == SDSSC_NOT_BOUND_ERROR) { 5520Sstevel@tonic-gate mderror(ep, MDE_NOT_MN, NULL); 5530Sstevel@tonic-gate mde_perror(ep, 5540Sstevel@tonic-gate "Cluster node does not support " 5550Sstevel@tonic-gate "multi-owner diskset operations"); 5560Sstevel@tonic-gate md_exit(local_sp, 1); 5570Sstevel@tonic-gate } else if (sdssc_rval == SDSSC_ERROR) { 5580Sstevel@tonic-gate mde_perror(ep, ""); 5590Sstevel@tonic-gate md_exit(local_sp, 1); 5600Sstevel@tonic-gate } 5610Sstevel@tonic-gate } else { 5620Sstevel@tonic-gate sdssc_rval = sdssc_create_begin(sname, argc, 563*4932Spetede argv, SDSSC_PICK_SETNO); 5640Sstevel@tonic-gate if (sdssc_rval == SDSSC_ERROR) { 5650Sstevel@tonic-gate mde_perror(ep, ""); 5660Sstevel@tonic-gate md_exit(local_sp, 1); 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate } 5690Sstevel@tonic-gate /* 5700Sstevel@tonic-gate * Created diskset (as opposed to adding a 5710Sstevel@tonic-gate * host to an existing diskset). 5720Sstevel@tonic-gate */ 5730Sstevel@tonic-gate created_set = 1; 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate sp = Zalloc(sizeof (*sp)); 5760Sstevel@tonic-gate sp->setname = Strdup(sname); 5770Sstevel@tonic-gate sp->lockfd = MD_NO_LOCK; 5780Sstevel@tonic-gate mdclrerror(ep); 5790Sstevel@tonic-gate } else { 5800Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 5810Sstevel@tonic-gate mde_perror(ep, ""); 5820Sstevel@tonic-gate md_exit(local_sp, 1); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 5850Sstevel@tonic-gate multi_node = 1; 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * can't add hosts to an existing set & enable 5900Sstevel@tonic-gate * auto-take 5910Sstevel@tonic-gate */ 5920Sstevel@tonic-gate if (auto_take) 5930Sstevel@tonic-gate usage(sp, gettext("conflicting options")); 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate /* 5960Sstevel@tonic-gate * Have a valid set, take the set lock also. 5970Sstevel@tonic-gate * 5980Sstevel@tonic-gate * A MN diskset does not use the set meta_lock but 5990Sstevel@tonic-gate * instead uses the clnt_lock of rpc.metad and the 6000Sstevel@tonic-gate * suspend/resume feature of the rpc.mdcommd. Can't 6010Sstevel@tonic-gate * use set meta_lock since class 1 messages are 6020Sstevel@tonic-gate * grabbing this lock and if this thread is holding 6030Sstevel@tonic-gate * the set meta_lock then no rpc.mdcommd suspend 6040Sstevel@tonic-gate * can occur. 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate if (!multi_node) { 6070Sstevel@tonic-gate if (meta_lock(sp, TRUE, ep) != 0) { 6080Sstevel@tonic-gate mde_perror(ep, ""); 6090Sstevel@tonic-gate md_exit(local_sp, 1); 6100Sstevel@tonic-gate } 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate } 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate if (meta_set_addhosts(sp, multi_node, argc, argv, auto_take, 6150Sstevel@tonic-gate ep)) { 6160Sstevel@tonic-gate if (created_set) 6170Sstevel@tonic-gate sdssc_create_end(sname, SDSSC_CLEANUP); 6180Sstevel@tonic-gate mde_perror(&status, ""); 6190Sstevel@tonic-gate if (!multi_node) 6200Sstevel@tonic-gate (void) meta_unlock(sp, ep); 6210Sstevel@tonic-gate md_exit(local_sp, 1); 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate if (created_set) 6250Sstevel@tonic-gate sdssc_create_end(sname, SDSSC_COMMIT); 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate else { 6280Sstevel@tonic-gate /* 6290Sstevel@tonic-gate * If adding hosts to existing diskset, 6300Sstevel@tonic-gate * call DCS svcs 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate sdssc_add_hosts(sname, argc, argv); 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate if (!multi_node) 6350Sstevel@tonic-gate (void) meta_unlock(sp, ep); 6360Sstevel@tonic-gate md_exit(local_sp, 0); 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate /* 6400Sstevel@tonic-gate * Add mediators 6410Sstevel@tonic-gate */ 6420Sstevel@tonic-gate if (meds == TRUE) { 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 6450Sstevel@tonic-gate mde_perror(ep, ""); 6460Sstevel@tonic-gate md_exit(local_sp, 1); 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 6500Sstevel@tonic-gate mde_perror(ep, ""); 6510Sstevel@tonic-gate md_exit(local_sp, 1); 6520Sstevel@tonic-gate } 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 6550Sstevel@tonic-gate mde_perror(ep, ""); 6560Sstevel@tonic-gate md_exit(local_sp, 1); 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 6590Sstevel@tonic-gate multi_node = 1; 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 6630Sstevel@tonic-gate mde_perror(ep, ""); 6640Sstevel@tonic-gate md_exit(local_sp, 1); 6650Sstevel@tonic-gate } 6660Sstevel@tonic-gate /* 6670Sstevel@tonic-gate * A MN diskset does not use the set meta_lock but 6680Sstevel@tonic-gate * instead uses the clnt_lock of rpc.metad and the 6690Sstevel@tonic-gate * suspend/resume feature of the rpc.mdcommd. Can't 6700Sstevel@tonic-gate * use set meta_lock since class 1 messages are 6710Sstevel@tonic-gate * grabbing this lock and if this thread is holding 6720Sstevel@tonic-gate * the set meta_lock then no rpc.mdcommd suspend 6730Sstevel@tonic-gate * can occur. 6740Sstevel@tonic-gate */ 6750Sstevel@tonic-gate if (!multi_node) { 6760Sstevel@tonic-gate if (meta_lock(sp, TRUE, ep) != 0) { 6770Sstevel@tonic-gate mde_perror(ep, ""); 6780Sstevel@tonic-gate md_exit(local_sp, 1); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate } 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate if (meta_set_addmeds(sp, argc, argv, ep)) { 6830Sstevel@tonic-gate mde_perror(&status, ""); 6840Sstevel@tonic-gate if (!multi_node) 6850Sstevel@tonic-gate (void) meta_unlock(sp, ep); 6860Sstevel@tonic-gate md_exit(local_sp, 1); 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate if (!multi_node) 6900Sstevel@tonic-gate (void) meta_unlock(sp, ep); 6910Sstevel@tonic-gate md_exit(local_sp, 0); 6920Sstevel@tonic-gate } 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate /* 6950Sstevel@tonic-gate * Add drives 6960Sstevel@tonic-gate */ 6970Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 6980Sstevel@tonic-gate mde_perror(ep, ""); 6990Sstevel@tonic-gate md_exit(local_sp, 1); 7000Sstevel@tonic-gate } 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 7030Sstevel@tonic-gate mde_perror(ep, ""); 7040Sstevel@tonic-gate md_exit(local_sp, 1); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate /* Determine if diskset is a MN diskset or not */ 7080Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 7090Sstevel@tonic-gate mde_perror(ep, ""); 7100Sstevel@tonic-gate md_exit(local_sp, 1); 7110Sstevel@tonic-gate } 7120Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 7130Sstevel@tonic-gate multi_node = 1; 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 7170Sstevel@tonic-gate mde_perror(ep, ""); 7180Sstevel@tonic-gate md_exit(local_sp, 1); 7190Sstevel@tonic-gate } 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate /* Make sure database size is within limits */ 7220Sstevel@tonic-gate if (default_size == FALSE) { 7230Sstevel@tonic-gate if ((multi_node && dbsize < MDDB_MN_MINBLKS) || 7240Sstevel@tonic-gate (!multi_node && dbsize < MDDB_MINBLKS)) 7250Sstevel@tonic-gate usage(sp, gettext( 7260Sstevel@tonic-gate "size (-l) is too small")); 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate if ((multi_node && dbsize > MDDB_MN_MAXBLKS) || 7290Sstevel@tonic-gate (!multi_node && dbsize > MDDB_MAXBLKS)) 7300Sstevel@tonic-gate usage(sp, gettext( 7310Sstevel@tonic-gate "size (-l) is too big")); 7320Sstevel@tonic-gate } 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate /* 7350Sstevel@tonic-gate * Have a valid set, take the set lock also. 7360Sstevel@tonic-gate * 7370Sstevel@tonic-gate * A MN diskset does not use the set meta_lock but 7380Sstevel@tonic-gate * instead uses the clnt_lock of rpc.metad and the 7390Sstevel@tonic-gate * suspend/resume feature of the rpc.mdcommd. Can't 7400Sstevel@tonic-gate * use set meta_lock since class 1 messages are 7410Sstevel@tonic-gate * grabbing this lock and if this thread is holding 7420Sstevel@tonic-gate * the set meta_lock then no rpc.mdcommd suspend 7430Sstevel@tonic-gate * can occur. 7440Sstevel@tonic-gate */ 7450Sstevel@tonic-gate if (!multi_node) { 7460Sstevel@tonic-gate if (meta_lock(sp, TRUE, ep) != 0) { 7470Sstevel@tonic-gate mde_perror(ep, ""); 7480Sstevel@tonic-gate md_exit(local_sp, 1); 7490Sstevel@tonic-gate } 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate /* 7540Sstevel@tonic-gate * If using the default size, 7550Sstevel@tonic-gate * then let's adjust the default to the minimum 7560Sstevel@tonic-gate * size currently in use. 7570Sstevel@tonic-gate */ 7580Sstevel@tonic-gate if (default_size) { 7590Sstevel@tonic-gate dbsize = multi_node ? MD_MN_DBSIZE : MD_DBSIZE; 7600Sstevel@tonic-gate if ((nblks = meta_db_minreplica(sp, ep)) < 0) 7610Sstevel@tonic-gate mdclrerror(ep); 7620Sstevel@tonic-gate else 7630Sstevel@tonic-gate dbsize = nblks; /* adjust replica size */ 7640Sstevel@tonic-gate } 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate if ((c = metadrivenamelist(&sp, &dnlp, argc, argv, ep)) < 0) { 7670Sstevel@tonic-gate mde_perror(ep, ""); 7680Sstevel@tonic-gate if (!multi_node) 7690Sstevel@tonic-gate (void) meta_unlock(sp, ep); 7700Sstevel@tonic-gate md_exit(local_sp, 1); 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate if (c == 0) { 7740Sstevel@tonic-gate md_perror(gettext( 7750Sstevel@tonic-gate "No drives specified to add.\n")); 7760Sstevel@tonic-gate if (!multi_node) 7770Sstevel@tonic-gate (void) meta_unlock(sp, ep); 7780Sstevel@tonic-gate md_exit(local_sp, 1); 7790Sstevel@tonic-gate } 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate if (meta_set_adddrives(sp, dnlp, dbsize, force_label, ep)) { 7820Sstevel@tonic-gate metafreedrivenamelist(dnlp); 7830Sstevel@tonic-gate mde_perror(ep, ""); 7840Sstevel@tonic-gate if (!multi_node) 7850Sstevel@tonic-gate (void) meta_unlock(sp, ep); 7860Sstevel@tonic-gate md_exit(local_sp, 1); 7870Sstevel@tonic-gate } 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate /* 7900Sstevel@tonic-gate * MN disksets don't have a device id in the master block 7910Sstevel@tonic-gate * For traditional disksets, check for the drive device 7920Sstevel@tonic-gate * id not fitting in the master block 7930Sstevel@tonic-gate */ 7940Sstevel@tonic-gate if (!multi_node) { 7950Sstevel@tonic-gate for (p = dnlp; p != NULL; p = p->next) { 7960Sstevel@tonic-gate int fd; 7970Sstevel@tonic-gate ddi_devid_t devid; 7980Sstevel@tonic-gate mdname_t *np; 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate np = metaslicename(p->drivenamep, 0, ep); 8010Sstevel@tonic-gate if (np == NULL) 8020Sstevel@tonic-gate continue; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate if ((fd = open(np->rname, O_RDONLY | O_NDELAY)) < 0) 8050Sstevel@tonic-gate continue; 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate if (devid_get(fd, &devid) == 0) { 8080Sstevel@tonic-gate size_t len; 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate len = devid_sizeof(devid); 8110Sstevel@tonic-gate if (len > (DEV_BSIZE - sizeof (mddb_mb_t))) 8120Sstevel@tonic-gate (void) mddserror(ep, 8130Sstevel@tonic-gate MDE_DS_NOTSELFIDENTIFY, NULL, NULL, 8140Sstevel@tonic-gate np->rname, NULL); 8150Sstevel@tonic-gate devid_free(devid); 8160Sstevel@tonic-gate } else { 8170Sstevel@tonic-gate (void) mddserror(ep, MDE_DS_NOTSELFIDENTIFY, 8180Sstevel@tonic-gate NULL, NULL, np->rname, NULL); 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate (void) close(fd); 8210Sstevel@tonic-gate } 8220Sstevel@tonic-gate } 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate /* 8250Sstevel@tonic-gate * MN disksets don't use DCS clustering services. 8260Sstevel@tonic-gate * For traditional disksets: 8270Sstevel@tonic-gate * There's not really much we can do here if this call fails. 8280Sstevel@tonic-gate * The drives have been added to the set and DiskSuite believes 8290Sstevel@tonic-gate * it owns the drives. 8300Sstevel@tonic-gate * Relase the set and hope for the best. 8310Sstevel@tonic-gate */ 8320Sstevel@tonic-gate if ((!multi_node) && 8330Sstevel@tonic-gate (sdssc_notify_service(sname, Make_Primary) == SDSSC_ERROR)) { 8340Sstevel@tonic-gate meta_set_release(sp, ep); 8350Sstevel@tonic-gate printf(gettext( 8360Sstevel@tonic-gate "Sun Clustering failed to make set primary\n")); 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate 8390Sstevel@tonic-gate metafreedrivenamelist(dnlp); 8400Sstevel@tonic-gate if (!multi_node) 8410Sstevel@tonic-gate (void) meta_unlock(sp, ep); 8420Sstevel@tonic-gate md_exit(local_sp, 0); 8430Sstevel@tonic-gate } 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate static void 8460Sstevel@tonic-gate parse_balance(int argc, char **argv) 8470Sstevel@tonic-gate { 8480Sstevel@tonic-gate int c; 8490Sstevel@tonic-gate mdsetname_t *sp = NULL; 8500Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 8510Sstevel@tonic-gate md_error_t status = mdnullerror; 8520Sstevel@tonic-gate md_set_desc *sd; 8530Sstevel@tonic-gate int multi_node = 0; 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate /* reset and parse args */ 8560Sstevel@tonic-gate optind = 1; 8570Sstevel@tonic-gate opterr = 1; 8580Sstevel@tonic-gate while ((c = getopt(argc, argv, "Mbs:")) != -1) { 8590Sstevel@tonic-gate switch (c) { 8600Sstevel@tonic-gate case 'M': 8610Sstevel@tonic-gate break; 8620Sstevel@tonic-gate case 'b': 8630Sstevel@tonic-gate break; 8640Sstevel@tonic-gate case 's': 8650Sstevel@tonic-gate sname = optarg; 8660Sstevel@tonic-gate break; 8670Sstevel@tonic-gate default: 8680Sstevel@tonic-gate usage(sp, gettext("unknown options")); 8690Sstevel@tonic-gate } 8700Sstevel@tonic-gate } 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate argc -= optind; 8730Sstevel@tonic-gate argv += optind; 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate if (argc != 0) 8760Sstevel@tonic-gate usage(sp, gettext("too many args")); 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate if ((sp = metasetname(sname, &status)) == NULL) { 8790Sstevel@tonic-gate mde_perror(&status, ""); 8800Sstevel@tonic-gate md_exit(sp, 1); 8810Sstevel@tonic-gate } 8820Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, &status)) == NULL) { 8830Sstevel@tonic-gate mde_perror(&status, ""); 8840Sstevel@tonic-gate md_exit(sp, 1); 8850Sstevel@tonic-gate } 8860Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 8870Sstevel@tonic-gate multi_node = 1; 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate /* 8900Sstevel@tonic-gate * Have a valid set, take the set lock also. 8910Sstevel@tonic-gate * 8920Sstevel@tonic-gate * A MN diskset does not use the set meta_lock but 8930Sstevel@tonic-gate * instead uses the clnt_lock of rpc.metad and the 8940Sstevel@tonic-gate * suspend/resume feature of the rpc.mdcommd. Can't 8950Sstevel@tonic-gate * use set meta_lock since class 1 messages are 8960Sstevel@tonic-gate * grabbing this lock and if this thread is holding 8970Sstevel@tonic-gate * the set meta_lock then no rpc.mdcommd suspend 8980Sstevel@tonic-gate * can occur. 8990Sstevel@tonic-gate */ 9000Sstevel@tonic-gate if (!multi_node) { 9010Sstevel@tonic-gate if (meta_lock(sp, TRUE, &status) != 0) { 9020Sstevel@tonic-gate mde_perror(&status, ""); 9030Sstevel@tonic-gate md_exit(sp, 1); 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate } 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate if (meta_set_balance(sp, &status) != 0) { 9080Sstevel@tonic-gate mde_perror(&status, ""); 9090Sstevel@tonic-gate md_exit(sp, 1); 9100Sstevel@tonic-gate } 9110Sstevel@tonic-gate md_exit(sp, 0); 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate static void 9150Sstevel@tonic-gate parse_autotake(int argc, char **argv) 9160Sstevel@tonic-gate { 9170Sstevel@tonic-gate int c; 9180Sstevel@tonic-gate int enable = 0; 9190Sstevel@tonic-gate mdsetname_t *sp = NULL; 9200Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 9210Sstevel@tonic-gate md_error_t status = mdnullerror; 9220Sstevel@tonic-gate md_error_t *ep = &status; 9230Sstevel@tonic-gate 9240Sstevel@tonic-gate /* reset and parse args */ 9250Sstevel@tonic-gate optind = 1; 9260Sstevel@tonic-gate opterr = 1; 9270Sstevel@tonic-gate while ((c = getopt(argc, argv, "A:s:")) != -1) { 9280Sstevel@tonic-gate switch (c) { 9290Sstevel@tonic-gate case 'A': 9300Sstevel@tonic-gate /* verified sub-option in main */ 9310Sstevel@tonic-gate if (strcmp(optarg, "enable") == 0) 9320Sstevel@tonic-gate enable = 1; 9330Sstevel@tonic-gate break; 9340Sstevel@tonic-gate case 's': 9350Sstevel@tonic-gate /* verified presence of setname in main */ 9360Sstevel@tonic-gate sname = optarg; 9370Sstevel@tonic-gate break; 9380Sstevel@tonic-gate default: 9390Sstevel@tonic-gate usage(sp, gettext("unknown options")); 9400Sstevel@tonic-gate } 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 9440Sstevel@tonic-gate mde_perror(ep, ""); 9450Sstevel@tonic-gate md_exit(sp, 1); 9460Sstevel@tonic-gate } 9470Sstevel@tonic-gate 9480Sstevel@tonic-gate if (meta_lock(sp, TRUE, ep) != 0) { 9490Sstevel@tonic-gate mde_perror(ep, ""); 9500Sstevel@tonic-gate md_exit(sp, 1); 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate if (meta_check_ownership(sp, ep) != 0) { 9540Sstevel@tonic-gate mde_perror(ep, ""); 9550Sstevel@tonic-gate md_exit(sp, 1); 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate if (meta_set_auto_take(sp, enable, ep) != 0) { 9590Sstevel@tonic-gate mde_perror(ep, ""); 9600Sstevel@tonic-gate md_exit(sp, 1); 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate md_exit(sp, 0); 9640Sstevel@tonic-gate } 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate static void 9670Sstevel@tonic-gate parse_del(int argc, char **argv) 9680Sstevel@tonic-gate { 9690Sstevel@tonic-gate int c; 9700Sstevel@tonic-gate mdsetname_t *sp = NULL; 9710Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 9720Sstevel@tonic-gate int hosts = FALSE; 9730Sstevel@tonic-gate int meds = FALSE; 9740Sstevel@tonic-gate int forceflg = FALSE; 9750Sstevel@tonic-gate md_error_t status = mdnullerror; 9760Sstevel@tonic-gate md_error_t *ep = &status; 9770Sstevel@tonic-gate mddrivenamelist_t *dnlp = NULL; 9780Sstevel@tonic-gate mdsetname_t *local_sp = NULL; 9790Sstevel@tonic-gate md_set_desc *sd; 9800Sstevel@tonic-gate int multi_node = 0; 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate /* reset and parse args */ 9830Sstevel@tonic-gate optind = 1; 9840Sstevel@tonic-gate opterr = 1; 9850Sstevel@tonic-gate while ((c = getopt(argc, argv, "Mdfhms:")) != -1) { 9860Sstevel@tonic-gate switch (c) { 9870Sstevel@tonic-gate case 'M': 9880Sstevel@tonic-gate break; 9890Sstevel@tonic-gate case 'd': 9900Sstevel@tonic-gate break; 9910Sstevel@tonic-gate case 'f': 9920Sstevel@tonic-gate forceflg = TRUE; 9930Sstevel@tonic-gate break; 9940Sstevel@tonic-gate case 'h': 9950Sstevel@tonic-gate case 'm': 9960Sstevel@tonic-gate if (meds == TRUE || hosts == TRUE) 9970Sstevel@tonic-gate usage(sp, gettext( 9980Sstevel@tonic-gate "only one -m or -h option allowed")); 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate if (c == 'h') 10010Sstevel@tonic-gate hosts = TRUE; 10020Sstevel@tonic-gate else 10030Sstevel@tonic-gate meds = TRUE; 10040Sstevel@tonic-gate break; 10050Sstevel@tonic-gate case 's': 10060Sstevel@tonic-gate sname = optarg; 10070Sstevel@tonic-gate break; 10080Sstevel@tonic-gate default: 10090Sstevel@tonic-gate usage(sp, gettext("unknown options")); 10100Sstevel@tonic-gate } 10110Sstevel@tonic-gate } 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate argc -= optind; 10140Sstevel@tonic-gate argv += optind; 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 10170Sstevel@tonic-gate mde_perror(ep, ""); 10180Sstevel@tonic-gate md_exit(local_sp, 1); 10190Sstevel@tonic-gate } 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 10220Sstevel@tonic-gate mde_perror(ep, ""); 10230Sstevel@tonic-gate md_exit(local_sp, 1); 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 10270Sstevel@tonic-gate mde_perror(ep, ""); 10280Sstevel@tonic-gate md_exit(local_sp, 1); 10290Sstevel@tonic-gate } 10300Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) 10310Sstevel@tonic-gate multi_node = 1; 10320Sstevel@tonic-gate 10330Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 10340Sstevel@tonic-gate mde_perror(ep, ""); 10350Sstevel@tonic-gate md_exit(local_sp, 1); 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate /* 10390Sstevel@tonic-gate * Have a valid set, take the set lock also. 10400Sstevel@tonic-gate * 10410Sstevel@tonic-gate * A MN diskset does not use the set meta_lock but 10420Sstevel@tonic-gate * instead uses the clnt_lock of rpc.metad and the 10430Sstevel@tonic-gate * suspend/resume feature of the rpc.mdcommd. Can't 10440Sstevel@tonic-gate * use set meta_lock since class 1 messages are 10450Sstevel@tonic-gate * grabbing this lock and if this thread is holding 10460Sstevel@tonic-gate * the set meta_lock then no rpc.mdcommd suspend 10470Sstevel@tonic-gate * can occur. 10480Sstevel@tonic-gate */ 10490Sstevel@tonic-gate if (!multi_node) { 10500Sstevel@tonic-gate if (meta_lock(sp, TRUE, ep) != 0) { 10510Sstevel@tonic-gate mde_perror(ep, ""); 10520Sstevel@tonic-gate md_exit(local_sp, 1); 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate } 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate /* 10570Sstevel@tonic-gate * Delete hosts 10580Sstevel@tonic-gate */ 10590Sstevel@tonic-gate if (hosts == TRUE) { 10600Sstevel@tonic-gate if (meta_check_ownership(sp, ep) != 0) { 10610Sstevel@tonic-gate /* 10620Sstevel@tonic-gate * If we don't own the set bail out here otherwise 10630Sstevel@tonic-gate * we could delete the node from the DCS service 10640Sstevel@tonic-gate * yet not delete the host from the set. 10650Sstevel@tonic-gate */ 10660Sstevel@tonic-gate mde_perror(ep, ""); 10670Sstevel@tonic-gate if (!multi_node) 10680Sstevel@tonic-gate (void) meta_unlock(sp, ep); 10690Sstevel@tonic-gate md_exit(local_sp, 1); 10700Sstevel@tonic-gate } 10710Sstevel@tonic-gate if (sdssc_delete_hosts(sname, argc, argv) == SDSSC_ERROR) { 1072*4932Spetede if (!metad_isautotakebyname(sname)) { 1073*4932Spetede /* 1074*4932Spetede * SC could have been installed after the set 1075*4932Spetede * was created. We still want to be able to 1076*4932Spetede * delete these sets. 1077*4932Spetede */ 1078*4932Spetede md_perror(gettext( 1079*4932Spetede "Failed to delete hosts from DCS service")); 1080*4932Spetede if (!multi_node) 1081*4932Spetede (void) meta_unlock(sp, ep); 1082*4932Spetede md_exit(local_sp, 1); 1083*4932Spetede } 10840Sstevel@tonic-gate } 10850Sstevel@tonic-gate if (meta_set_deletehosts(sp, argc, argv, forceflg, ep)) { 10860Sstevel@tonic-gate if (sdssc_add_hosts(sname, argc, argv) == SDSSC_ERROR) { 10870Sstevel@tonic-gate (void) printf(gettext( 10880Sstevel@tonic-gate "Failed to restore host(s) in DCS " 10890Sstevel@tonic-gate "database\n")); 10900Sstevel@tonic-gate } 10910Sstevel@tonic-gate mde_perror(ep, ""); 10920Sstevel@tonic-gate if (!multi_node) 10930Sstevel@tonic-gate (void) meta_unlock(sp, ep); 10940Sstevel@tonic-gate md_exit(local_sp, 1); 10950Sstevel@tonic-gate } 10960Sstevel@tonic-gate if (!multi_node) 10970Sstevel@tonic-gate (void) meta_unlock(sp, ep); 10980Sstevel@tonic-gate md_exit(local_sp, 0); 10990Sstevel@tonic-gate } 11000Sstevel@tonic-gate 11010Sstevel@tonic-gate /* 11020Sstevel@tonic-gate * Delete mediators 11030Sstevel@tonic-gate */ 11040Sstevel@tonic-gate if (meds == TRUE) { 11050Sstevel@tonic-gate if (meta_set_deletemeds(sp, argc, argv, forceflg, ep)) { 11060Sstevel@tonic-gate mde_perror(ep, ""); 11070Sstevel@tonic-gate if (!multi_node) 11080Sstevel@tonic-gate (void) meta_unlock(sp, ep); 11090Sstevel@tonic-gate md_exit(local_sp, 1); 11100Sstevel@tonic-gate } 11110Sstevel@tonic-gate if (!multi_node) 11120Sstevel@tonic-gate (void) meta_unlock(sp, ep); 11130Sstevel@tonic-gate md_exit(local_sp, 0); 11140Sstevel@tonic-gate } 11150Sstevel@tonic-gate 11160Sstevel@tonic-gate /* 11170Sstevel@tonic-gate * Delete drives 11180Sstevel@tonic-gate */ 11190Sstevel@tonic-gate 11200Sstevel@tonic-gate if ((c = metadrivenamelist(&sp, &dnlp, argc, argv, ep)) < 0) { 11210Sstevel@tonic-gate mde_perror(ep, ""); 11220Sstevel@tonic-gate if (!multi_node) 11230Sstevel@tonic-gate (void) meta_unlock(sp, ep); 11240Sstevel@tonic-gate md_exit(local_sp, 1); 11250Sstevel@tonic-gate } 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate if (c == 0) { 11280Sstevel@tonic-gate md_perror(gettext( 11290Sstevel@tonic-gate "No drives specified to delete.\n")); 11300Sstevel@tonic-gate if (!multi_node) 11310Sstevel@tonic-gate (void) meta_unlock(sp, ep); 11320Sstevel@tonic-gate md_exit(local_sp, 1); 11330Sstevel@tonic-gate } 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate if (meta_set_deletedrives(sp, dnlp, forceflg, ep)) { 11360Sstevel@tonic-gate metafreedrivenamelist(dnlp); 11370Sstevel@tonic-gate mde_perror(ep, ""); 11380Sstevel@tonic-gate if (!multi_node) 11390Sstevel@tonic-gate (void) meta_unlock(sp, ep); 11400Sstevel@tonic-gate md_exit(local_sp, 1); 11410Sstevel@tonic-gate } 11420Sstevel@tonic-gate 11430Sstevel@tonic-gate metafreedrivenamelist(dnlp); 11440Sstevel@tonic-gate if (!multi_node) 11450Sstevel@tonic-gate (void) meta_unlock(sp, ep); 11460Sstevel@tonic-gate md_exit(local_sp, 0); 11470Sstevel@tonic-gate } 11480Sstevel@tonic-gate 11490Sstevel@tonic-gate static void 11500Sstevel@tonic-gate parse_isowner(int argc, char **argv) 11510Sstevel@tonic-gate { 11520Sstevel@tonic-gate int c; 11530Sstevel@tonic-gate mdsetname_t *sp = NULL; 11540Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 11550Sstevel@tonic-gate md_error_t status = mdnullerror; 11560Sstevel@tonic-gate md_error_t *ep = &status; 11570Sstevel@tonic-gate char *host = NULL; 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate /* reset and parse args */ 11600Sstevel@tonic-gate optind = 1; 11610Sstevel@tonic-gate opterr = 1; 11620Sstevel@tonic-gate while ((c = getopt(argc, argv, "Moh:s:")) != -1) { 11630Sstevel@tonic-gate switch (c) { 11640Sstevel@tonic-gate case 'M': 11650Sstevel@tonic-gate break; 11660Sstevel@tonic-gate case 'o': 11670Sstevel@tonic-gate break; 11680Sstevel@tonic-gate case 'h': 11690Sstevel@tonic-gate if (host != NULL) { 11700Sstevel@tonic-gate usage(sp, gettext( 11710Sstevel@tonic-gate "only one -h option allowed")); 11720Sstevel@tonic-gate } 11730Sstevel@tonic-gate host = optarg; 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate case 's': 11760Sstevel@tonic-gate sname = optarg; 11770Sstevel@tonic-gate break; 11780Sstevel@tonic-gate default: 11790Sstevel@tonic-gate usage(sp, gettext("unknown options")); 11800Sstevel@tonic-gate } 11810Sstevel@tonic-gate } 11820Sstevel@tonic-gate 11830Sstevel@tonic-gate argc -= optind; 11840Sstevel@tonic-gate argv += optind; 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate if (argc != 0) 11870Sstevel@tonic-gate usage(sp, gettext("too many args")); 11880Sstevel@tonic-gate 11890Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 11900Sstevel@tonic-gate mde_perror(ep, ""); 11910Sstevel@tonic-gate md_exit(sp, 1); 11920Sstevel@tonic-gate } 11930Sstevel@tonic-gate 11940Sstevel@tonic-gate if (host == NULL) { 11950Sstevel@tonic-gate if (meta_check_ownership(sp, ep) != 0) { 11960Sstevel@tonic-gate mde_perror(ep, ""); 11970Sstevel@tonic-gate md_exit(sp, 1); 11980Sstevel@tonic-gate } 11990Sstevel@tonic-gate } else { 12000Sstevel@tonic-gate if (meta_check_ownership_on_host(sp, host, ep) != 0) { 12010Sstevel@tonic-gate mde_perror(ep, ""); 12020Sstevel@tonic-gate md_exit(sp, 1); 12030Sstevel@tonic-gate } 12040Sstevel@tonic-gate } 12050Sstevel@tonic-gate md_exit(sp, 0); 12060Sstevel@tonic-gate } 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate static void 12090Sstevel@tonic-gate parse_purge(int argc, char **argv) 12100Sstevel@tonic-gate { 12110Sstevel@tonic-gate int c; 12120Sstevel@tonic-gate mdsetname_t *sp = NULL; 12130Sstevel@tonic-gate mdsetname_t *local_sp = NULL; 12140Sstevel@tonic-gate md_drive_desc *dd; 12150Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 12160Sstevel@tonic-gate char *thishost = mynode(); 12170Sstevel@tonic-gate md_error_t status = mdnullerror; 12180Sstevel@tonic-gate md_error_t *ep = &status; 12190Sstevel@tonic-gate int bypass_cluster_purge = 0; 12200Sstevel@tonic-gate int forceflg = FALSE; 12210Sstevel@tonic-gate int ret = 0; 12220Sstevel@tonic-gate int multi_node = 0; 12230Sstevel@tonic-gate md_set_desc *sd; 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate optind = 1; 12260Sstevel@tonic-gate opterr = 1; 12270Sstevel@tonic-gate while ((c = getopt(argc, argv, "C:fPs:")) != -1) { 12280Sstevel@tonic-gate switch (c) { 12290Sstevel@tonic-gate case 'M': 12300Sstevel@tonic-gate break; 12310Sstevel@tonic-gate case 'C': 12320Sstevel@tonic-gate bypass_cluster_purge = 1; 12330Sstevel@tonic-gate break; 12340Sstevel@tonic-gate case 'f': 12350Sstevel@tonic-gate forceflg = TRUE; 12360Sstevel@tonic-gate break; 12370Sstevel@tonic-gate case 'P': 12380Sstevel@tonic-gate break; 12390Sstevel@tonic-gate case 's': 12400Sstevel@tonic-gate sname = optarg; 12410Sstevel@tonic-gate break; 12420Sstevel@tonic-gate default: 12430Sstevel@tonic-gate usage(sp, gettext("unknown options")); 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate } 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate argc -= optind; 12480Sstevel@tonic-gate argv += optind; 12490Sstevel@tonic-gate 12500Sstevel@tonic-gate if (argc != 0) 12510Sstevel@tonic-gate usage(sp, gettext("too many arguments")); 12520Sstevel@tonic-gate 12530Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 12540Sstevel@tonic-gate mde_perror(ep, ""); 12550Sstevel@tonic-gate md_exit(local_sp, 1); 12560Sstevel@tonic-gate } 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 12590Sstevel@tonic-gate mde_perror(ep, ""); 12600Sstevel@tonic-gate md_exit(local_sp, 1); 12610Sstevel@tonic-gate } 12620Sstevel@tonic-gate 12630Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 12640Sstevel@tonic-gate mde_perror(ep, ""); 12650Sstevel@tonic-gate md_exit(sp, 1); 12660Sstevel@tonic-gate } 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 12690Sstevel@tonic-gate mde_perror(ep, ""); 12700Sstevel@tonic-gate md_exit(local_sp, 1); 12710Sstevel@tonic-gate } 12720Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) 12730Sstevel@tonic-gate multi_node = 1; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate if (!multi_node) { 12760Sstevel@tonic-gate if (meta_lock(sp, TRUE, ep) != 0) { 12770Sstevel@tonic-gate mde_perror(ep, ""); 12780Sstevel@tonic-gate md_exit(local_sp, 1); 12790Sstevel@tonic-gate } 12800Sstevel@tonic-gate } 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate /* Must not own the set if purging it from this host */ 12830Sstevel@tonic-gate if (meta_check_ownership(sp, ep) == 0) { 12840Sstevel@tonic-gate /* 12850Sstevel@tonic-gate * Need to see if there are disks in the set, if not then 12860Sstevel@tonic-gate * there is no ownership but meta_check_ownership returns 0 12870Sstevel@tonic-gate */ 12880Sstevel@tonic-gate dd = metaget_drivedesc(sp, (MD_BASICNAME_OK | PRINT_FAST), ep); 12890Sstevel@tonic-gate if (!mdisok(ep)) { 12900Sstevel@tonic-gate mde_perror(ep, ""); 12910Sstevel@tonic-gate if (!multi_node) 12920Sstevel@tonic-gate (void) meta_unlock(sp, ep); 12930Sstevel@tonic-gate md_exit(local_sp, 1); 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate if (dd != NULL) { 12960Sstevel@tonic-gate (void) printf(gettext 12970Sstevel@tonic-gate ("Must not be owner of the set when purging it\n")); 12980Sstevel@tonic-gate if (!multi_node) 12990Sstevel@tonic-gate (void) meta_unlock(sp, ep); 13000Sstevel@tonic-gate md_exit(local_sp, 1); 13010Sstevel@tonic-gate } 13020Sstevel@tonic-gate } 13030Sstevel@tonic-gate /* 13040Sstevel@tonic-gate * Remove the node from the DCS service 13050Sstevel@tonic-gate */ 13060Sstevel@tonic-gate if (!bypass_cluster_purge) { 13070Sstevel@tonic-gate if (sdssc_delete_hosts(sname, 1, &thishost) == SDSSC_ERROR) { 13080Sstevel@tonic-gate md_perror(gettext 13090Sstevel@tonic-gate ("Failed to purge hosts from DCS service")); 13100Sstevel@tonic-gate if (!multi_node) 13110Sstevel@tonic-gate (void) meta_unlock(sp, ep); 13120Sstevel@tonic-gate md_exit(local_sp, 1); 13130Sstevel@tonic-gate } 13140Sstevel@tonic-gate } 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate if ((ret = meta_set_purge(sp, bypass_cluster_purge, forceflg, 13170Sstevel@tonic-gate ep)) != 0) { 13180Sstevel@tonic-gate if (!bypass_cluster_purge) { 13190Sstevel@tonic-gate if (sdssc_add_hosts(sname, 1, &thishost) == 13200Sstevel@tonic-gate SDSSC_ERROR) { 13210Sstevel@tonic-gate (void) printf(gettext( 13220Sstevel@tonic-gate "Failed to restore host in DCS " 13230Sstevel@tonic-gate "database\n")); 13240Sstevel@tonic-gate } 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate mde_perror(ep, ""); 13270Sstevel@tonic-gate if (!multi_node) 13280Sstevel@tonic-gate (void) meta_unlock(sp, ep); 13290Sstevel@tonic-gate md_exit(local_sp, ret); 13300Sstevel@tonic-gate } 13310Sstevel@tonic-gate 13320Sstevel@tonic-gate if (!multi_node) 13330Sstevel@tonic-gate (void) meta_unlock(sp, ep); 13340Sstevel@tonic-gate md_exit(local_sp, 0); 13350Sstevel@tonic-gate } 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate static void 13380Sstevel@tonic-gate parse_query(int argc, char **argv) 13390Sstevel@tonic-gate { 13400Sstevel@tonic-gate int c; 13410Sstevel@tonic-gate mdsetname_t *sp = NULL; 13420Sstevel@tonic-gate mddb_dtag_lst_t *dtlp = NULL; 13430Sstevel@tonic-gate mddb_dtag_lst_t *tdtlp; 13440Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 13450Sstevel@tonic-gate md_error_t status = mdnullerror; 13460Sstevel@tonic-gate 13470Sstevel@tonic-gate /* reset and parse args */ 13480Sstevel@tonic-gate optind = 1; 13490Sstevel@tonic-gate opterr = 1; 13500Sstevel@tonic-gate while ((c = getopt(argc, argv, "Mqs:")) != -1) { 13510Sstevel@tonic-gate switch (c) { 13520Sstevel@tonic-gate case 'M': 13530Sstevel@tonic-gate break; 13540Sstevel@tonic-gate case 'q': 13550Sstevel@tonic-gate break; 13560Sstevel@tonic-gate case 's': 13570Sstevel@tonic-gate sname = optarg; 13580Sstevel@tonic-gate break; 13590Sstevel@tonic-gate default: 13600Sstevel@tonic-gate usage(sp, gettext("unknown options")); 13610Sstevel@tonic-gate } 13620Sstevel@tonic-gate } 13630Sstevel@tonic-gate 13640Sstevel@tonic-gate argc -= optind; 13650Sstevel@tonic-gate argv += optind; 13660Sstevel@tonic-gate 13670Sstevel@tonic-gate if (argc != 0) 13680Sstevel@tonic-gate usage(sp, gettext("too many args")); 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate if ((sp = metasetname(sname, &status)) == NULL) { 13710Sstevel@tonic-gate mde_perror(&status, ""); 13720Sstevel@tonic-gate md_exit(sp, 1); 13730Sstevel@tonic-gate } 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate if (meta_lock(sp, TRUE, &status) != 0) { 13760Sstevel@tonic-gate mde_perror(&status, ""); 13770Sstevel@tonic-gate md_exit(sp, 1); 13780Sstevel@tonic-gate } 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate if (meta_set_query(sp, &dtlp, &status) != 0) { 13810Sstevel@tonic-gate mde_perror(&status, ""); 13820Sstevel@tonic-gate md_exit(sp, 1); 13830Sstevel@tonic-gate } 13840Sstevel@tonic-gate 13850Sstevel@tonic-gate if (dtlp != NULL) 13860Sstevel@tonic-gate (void) printf("The following tag(s) were found:\n"); 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate for (tdtlp = dtlp; tdtlp != NULL; tdtlp = dtlp) { 13890Sstevel@tonic-gate dtlp = tdtlp->dtl_nx; 13900Sstevel@tonic-gate (void) printf("%2d - %s - %s", tdtlp->dtl_dt.dt_id, 13910Sstevel@tonic-gate tdtlp->dtl_dt.dt_hn, 13920Sstevel@tonic-gate ctime((long *)&tdtlp->dtl_dt.dt_tv.tv_sec)); 13930Sstevel@tonic-gate Free(tdtlp); 13940Sstevel@tonic-gate } 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate md_exit(sp, 0); 13970Sstevel@tonic-gate } 13980Sstevel@tonic-gate 13990Sstevel@tonic-gate /* Should never be called with sname of a Multinode diskset. */ 14000Sstevel@tonic-gate static void 14010Sstevel@tonic-gate parse_releaseset(int argc, char **argv) 14020Sstevel@tonic-gate { 14030Sstevel@tonic-gate int c; 14040Sstevel@tonic-gate mdsetname_t *sp = NULL; 14050Sstevel@tonic-gate md_error_t status = mdnullerror; 14060Sstevel@tonic-gate md_error_t *ep = &status; 14070Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 14080Sstevel@tonic-gate sdssc_boolean_e cluster_release = SDSSC_False; 14090Sstevel@tonic-gate sdssc_version_t vers; 14100Sstevel@tonic-gate rval_e rval; 14110Sstevel@tonic-gate md_set_desc *sd; 14120Sstevel@tonic-gate 14130Sstevel@tonic-gate /* reset and parse args */ 14140Sstevel@tonic-gate optind = 1; 14150Sstevel@tonic-gate opterr = 1; 14161320Srd117015 while ((c = getopt(argc, argv, "C:s:r")) != -1) { 14170Sstevel@tonic-gate switch (c) { 14180Sstevel@tonic-gate case 'C': 14190Sstevel@tonic-gate cluster_release = SDSSC_True; 14200Sstevel@tonic-gate break; 14210Sstevel@tonic-gate case 's': 14220Sstevel@tonic-gate sname = optarg; 14230Sstevel@tonic-gate break; 14240Sstevel@tonic-gate case 'r': 14250Sstevel@tonic-gate break; 14260Sstevel@tonic-gate default: 14270Sstevel@tonic-gate usage(sp, gettext("unknown options")); 14280Sstevel@tonic-gate } 14290Sstevel@tonic-gate } 14300Sstevel@tonic-gate 14310Sstevel@tonic-gate argc -= optind; 14320Sstevel@tonic-gate argv += optind; 14330Sstevel@tonic-gate 14340Sstevel@tonic-gate if (argc > 0) 14350Sstevel@tonic-gate usage(sp, gettext("too many args")); 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate memset(&vers, 0, sizeof (vers)); 14380Sstevel@tonic-gate 14390Sstevel@tonic-gate if ((sdssc_version(&vers) == SDSSC_OKAY) && 14400Sstevel@tonic-gate (vers.major == 3) && 14410Sstevel@tonic-gate (cluster_release == SDSSC_False)) { 14420Sstevel@tonic-gate 14430Sstevel@tonic-gate /* 14440Sstevel@tonic-gate * If the release is being done by the user via the CLI 14450Sstevel@tonic-gate * we need to notify the DCS to release this node as being 14460Sstevel@tonic-gate * the primary. The reason nothing else needs to be done 14470Sstevel@tonic-gate * is due to the fact that the reservation code will exec 14480Sstevel@tonic-gate * metaset -C release to complete the operation. 14490Sstevel@tonic-gate */ 14500Sstevel@tonic-gate rval = sdssc_notify_service(sname, Release_Primary); 14510Sstevel@tonic-gate if (rval == SDSSC_ERROR) { 14520Sstevel@tonic-gate printf(gettext( 14530Sstevel@tonic-gate "metaset: failed to notify DCS of release\n")); 14540Sstevel@tonic-gate } 14550Sstevel@tonic-gate md_exit(NULL, rval == SDSSC_ERROR); 14560Sstevel@tonic-gate } 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate /* 14610Sstevel@tonic-gate * It's entirely possible for the SC3.0 reservation code 14620Sstevel@tonic-gate * to call for DiskSet to release a diskset and have that 14630Sstevel@tonic-gate * diskset not exist. During a diskset removal DiskSuite 14640Sstevel@tonic-gate * maybe able to remove all traces of the diskset before 14650Sstevel@tonic-gate * the reservation code execs metaset -C release in which 14660Sstevel@tonic-gate * case the metasetname will fail, but the overall command 14670Sstevel@tonic-gate * shouldn't. 14680Sstevel@tonic-gate */ 14690Sstevel@tonic-gate if (vers.major == 3) 14700Sstevel@tonic-gate md_exit(sp, 0); 14710Sstevel@tonic-gate else { 14720Sstevel@tonic-gate mde_perror(ep, ""); 14730Sstevel@tonic-gate md_exit(sp, 1); 14740Sstevel@tonic-gate } 14750Sstevel@tonic-gate } 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 14780Sstevel@tonic-gate mde_perror(ep, ""); 14790Sstevel@tonic-gate md_exit(sp, 1); 14800Sstevel@tonic-gate } 14810Sstevel@tonic-gate 14820Sstevel@tonic-gate if (sd->sd_flags & MD_SR_AUTO_TAKE) { 14830Sstevel@tonic-gate md_eprintf(gettext("cannot release auto-take diskset\n")); 14840Sstevel@tonic-gate md_exit(sp, 1); 14850Sstevel@tonic-gate } 14860Sstevel@tonic-gate 14870Sstevel@tonic-gate if (meta_lock_nowait(sp, ep) != 0) { 14881320Srd117015 mde_perror(ep, ""); 14891320Srd117015 md_exit(sp, 10); /* special errcode */ 14900Sstevel@tonic-gate } 14910Sstevel@tonic-gate 14920Sstevel@tonic-gate if (meta_set_release(sp, ep)) { 14930Sstevel@tonic-gate mde_perror(ep, ""); 14940Sstevel@tonic-gate md_exit(sp, 1); 14950Sstevel@tonic-gate } 14960Sstevel@tonic-gate md_exit(sp, 0); 14970Sstevel@tonic-gate } 14980Sstevel@tonic-gate 14990Sstevel@tonic-gate /* Should never be called with sname of a Multinode diskset. */ 15000Sstevel@tonic-gate static void 15010Sstevel@tonic-gate parse_takeset(int argc, char **argv) 15020Sstevel@tonic-gate { 15030Sstevel@tonic-gate int c; 15040Sstevel@tonic-gate mdsetname_t *sp = NULL; 15050Sstevel@tonic-gate int flags = 0; 15060Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 15070Sstevel@tonic-gate mhd_mhiargs_t mhiargs; 15080Sstevel@tonic-gate char *cp = NULL; 15090Sstevel@tonic-gate int pos = -1; /* position of timeout value */ 15100Sstevel@tonic-gate int usetag = 0; 15110Sstevel@tonic-gate static char *nullopts[] = { NULL }; 15120Sstevel@tonic-gate md_error_t status = mdnullerror; 15130Sstevel@tonic-gate md_error_t *ep = &status; 15140Sstevel@tonic-gate sdssc_boolean_e cluster_take = SDSSC_False; 15150Sstevel@tonic-gate sdssc_version_t vers; 15160Sstevel@tonic-gate rval_e rval; 15171945Sjeanm int set_take_rval; 15180Sstevel@tonic-gate 15190Sstevel@tonic-gate /* reset and parse args */ 15200Sstevel@tonic-gate optind = 1; 15210Sstevel@tonic-gate opterr = 1; 15221320Srd117015 while ((c = getopt(argc, argv, "C:fs:tu:y")) != -1) { 15230Sstevel@tonic-gate switch (c) { 15240Sstevel@tonic-gate case 'C': 15250Sstevel@tonic-gate cluster_take = SDSSC_True; 15260Sstevel@tonic-gate break; 15270Sstevel@tonic-gate case 'f': 15280Sstevel@tonic-gate flags |= TAKE_FORCE; 15290Sstevel@tonic-gate break; 15300Sstevel@tonic-gate case 's': 15310Sstevel@tonic-gate sname = optarg; 15320Sstevel@tonic-gate break; 15330Sstevel@tonic-gate case 't': 15340Sstevel@tonic-gate break; 15350Sstevel@tonic-gate case 'u': 15360Sstevel@tonic-gate usetag = atoi(optarg); 15370Sstevel@tonic-gate flags |= TAKE_USETAG; 15380Sstevel@tonic-gate break; 15390Sstevel@tonic-gate case 'y': 15400Sstevel@tonic-gate flags |= TAKE_USEIT; 15410Sstevel@tonic-gate break; 15420Sstevel@tonic-gate default: 15430Sstevel@tonic-gate usage(sp, gettext("unknown options")); 15440Sstevel@tonic-gate } 15450Sstevel@tonic-gate } 15460Sstevel@tonic-gate 15470Sstevel@tonic-gate mhiargs = defmhiargs; 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate argc -= optind; 15500Sstevel@tonic-gate argv += optind; 15510Sstevel@tonic-gate 15520Sstevel@tonic-gate if (argc > 1) 15530Sstevel@tonic-gate usage(sp, gettext("too many args")); 15540Sstevel@tonic-gate 15550Sstevel@tonic-gate /* 15560Sstevel@tonic-gate * If we have a list of timeout value overrides, handle it here 15570Sstevel@tonic-gate */ 15580Sstevel@tonic-gate while (argv[0] != NULL && *argv[0] != '\0') { 15590Sstevel@tonic-gate /* 15600Sstevel@tonic-gate * The use of the nullopts[] "token list" here is to make 15610Sstevel@tonic-gate * getsubopts() simply parse a comma separated list 15620Sstevel@tonic-gate * returning either "" or the contents of the field, the 15630Sstevel@tonic-gate * end condition is exaustion of the initial string, which 15640Sstevel@tonic-gate * is modified in the process. 15650Sstevel@tonic-gate */ 15660Sstevel@tonic-gate (void) getsubopt(&argv[0], nullopts, &cp); 15670Sstevel@tonic-gate 15680Sstevel@tonic-gate c = 0; /* re-use c as temp value of timeout */ 15690Sstevel@tonic-gate 15700Sstevel@tonic-gate if (*cp != '-') /* '-' uses default */ 15710Sstevel@tonic-gate c = atoi(cp); 15720Sstevel@tonic-gate 15730Sstevel@tonic-gate if (c < 0) { 15740Sstevel@tonic-gate usage(sp, gettext( 15750Sstevel@tonic-gate "time out values must be > 0")); 15760Sstevel@tonic-gate } 15770Sstevel@tonic-gate 15780Sstevel@tonic-gate if (++pos > 3) { 15790Sstevel@tonic-gate usage(sp, gettext( 15800Sstevel@tonic-gate "too many timeout values specified.")); 15810Sstevel@tonic-gate } 15820Sstevel@tonic-gate 15830Sstevel@tonic-gate if (c == 0) /* 0 or "" field uses default */ 15840Sstevel@tonic-gate continue; 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate /* 15870Sstevel@tonic-gate * Assign temp value to appropriate structure member based on 15880Sstevel@tonic-gate * its position in the comma separated list. 15890Sstevel@tonic-gate */ 15900Sstevel@tonic-gate switch (pos) { 1591*4932Spetede case 0: 1592*4932Spetede mhiargs.mh_ff = c; 1593*4932Spetede break; 15940Sstevel@tonic-gate 1595*4932Spetede case 1: 1596*4932Spetede mhiargs.mh_tk.reinstate_resv_delay = c; 1597*4932Spetede break; 15980Sstevel@tonic-gate 1599*4932Spetede case 2: 1600*4932Spetede mhiargs.mh_tk.min_ownership_delay = c; 1601*4932Spetede break; 16020Sstevel@tonic-gate 1603*4932Spetede case 3: 1604*4932Spetede mhiargs.mh_tk.max_ownership_delay = c; 1605*4932Spetede break; 16060Sstevel@tonic-gate } 16070Sstevel@tonic-gate } 16080Sstevel@tonic-gate 16090Sstevel@tonic-gate memset(&vers, 0, sizeof (vers)); 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate if ((sdssc_version(&vers) == SDSSC_OKAY) && 16120Sstevel@tonic-gate (vers.major == 3) && 16130Sstevel@tonic-gate (cluster_take == SDSSC_False)) { 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate /* 16160Sstevel@tonic-gate * If the take is beging done by the user via the CLI we need 16170Sstevel@tonic-gate * to notify the DCS to make this current node the primary. 16180Sstevel@tonic-gate * The SC3.0 reservation code will in turn exec metaset with 16190Sstevel@tonic-gate * the -C take arg to complete this operation. 16200Sstevel@tonic-gate */ 16210Sstevel@tonic-gate if ((rval = sdssc_notify_service(sname, Make_Primary)) == 16220Sstevel@tonic-gate SDSSC_ERROR) { 16230Sstevel@tonic-gate printf(gettext( 16240Sstevel@tonic-gate "metaset: failed to notify DCS of take\n")); 16250Sstevel@tonic-gate } 16260Sstevel@tonic-gate md_exit(NULL, rval == SDSSC_ERROR); 16270Sstevel@tonic-gate } 16280Sstevel@tonic-gate 16290Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 16300Sstevel@tonic-gate mde_perror(ep, ""); 16310Sstevel@tonic-gate md_exit(sp, 1); 16320Sstevel@tonic-gate } 16330Sstevel@tonic-gate 16340Sstevel@tonic-gate if ((vers.major == 3) && (meta_check_ownership(sp, ep) == 0)) { 16350Sstevel@tonic-gate 16360Sstevel@tonic-gate /* 16370Sstevel@tonic-gate * If we're running in a cluster environment and this 16380Sstevel@tonic-gate * node already owns the set. Don't bother trying to 16390Sstevel@tonic-gate * take the set again. There's one case where an adminstrator 16400Sstevel@tonic-gate * is adding disks to a set for the first time. metaset 16410Sstevel@tonic-gate * will take the ownership of the set at that point. During 16420Sstevel@tonic-gate * that add operation SC3.0 notices activity on the device 16430Sstevel@tonic-gate * and also tries to perform a take operation. The SC3.0 take 16440Sstevel@tonic-gate * will fail because the adminstrative add has the set locked 16450Sstevel@tonic-gate */ 16460Sstevel@tonic-gate md_exit(sp, 0); 16470Sstevel@tonic-gate } 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate if (meta_lock_nowait(sp, ep) != 0) { 16501320Srd117015 mde_perror(ep, ""); 16511320Srd117015 md_exit(sp, 10); /* special errcode */ 16520Sstevel@tonic-gate } 16530Sstevel@tonic-gate 16541945Sjeanm /* 16551945Sjeanm * If a 2 is returned from meta_set_take, this take was able to resolve 16561945Sjeanm * an unresolved replicated disk (i.e. a disk is now available that 16571945Sjeanm * had been missing during the import of the replicated diskset). 16581945Sjeanm * Need to release the diskset and re-take in order to have 16591945Sjeanm * the subdrivers re-snarf using the newly resolved (or newly mapped) 16601945Sjeanm * devids. This also allows the namespace to be updated with the 16611945Sjeanm * correct major names in the case where the disk being replicated 16621945Sjeanm * was handled by a different driver than the replicated disk. 16631945Sjeanm */ 16641945Sjeanm set_take_rval = meta_set_take(sp, &mhiargs, flags, usetag, &status); 16651945Sjeanm if (set_take_rval == 2) { 16661945Sjeanm if (meta_set_release(sp, &status)) { 16671945Sjeanm mde_perror(&status, 16681945Sjeanm "Need to release and take set to resolve names."); 16691945Sjeanm md_exit(sp, 1); 16701945Sjeanm } 16711945Sjeanm metaflushdrivenames(); 16721945Sjeanm metaflushsetname(sp); 16731945Sjeanm set_take_rval = meta_set_take(sp, &mhiargs, 16741945Sjeanm (flags | TAKE_RETAKE), usetag, &status); 16751945Sjeanm } 16761945Sjeanm 16771945Sjeanm if (set_take_rval == -1) { 16780Sstevel@tonic-gate mde_perror(&status, ""); 16790Sstevel@tonic-gate if (mdismddberror(&status, MDE_DB_TAGDATA)) 16800Sstevel@tonic-gate md_exit(sp, 2); 16810Sstevel@tonic-gate if (mdismddberror(&status, MDE_DB_ACCOK)) 16820Sstevel@tonic-gate md_exit(sp, 3); 16830Sstevel@tonic-gate if (mdismddberror(&status, MDE_DB_STALE)) 16840Sstevel@tonic-gate md_exit(sp, 66); 16850Sstevel@tonic-gate md_exit(sp, 1); 16860Sstevel@tonic-gate } 16870Sstevel@tonic-gate md_exit(sp, 0); 16880Sstevel@tonic-gate } 16890Sstevel@tonic-gate 16900Sstevel@tonic-gate /* 16910Sstevel@tonic-gate * Joins a node to a specific set or to all multinode disksets known 16920Sstevel@tonic-gate * by this node. If set is specified then caller should have verified 16930Sstevel@tonic-gate * that the set is a multinode diskset. 16940Sstevel@tonic-gate * 16950Sstevel@tonic-gate * If an error occurs, metaset exits with a 1. 16960Sstevel@tonic-gate * If there is no error, metaset exits with a 0. 16970Sstevel@tonic-gate */ 16980Sstevel@tonic-gate static void 16990Sstevel@tonic-gate parse_joinset(int argc, char **argv) 17000Sstevel@tonic-gate { 17010Sstevel@tonic-gate int c; 17020Sstevel@tonic-gate mdsetname_t *sp = NULL, *local_sp = NULL; 17030Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 17040Sstevel@tonic-gate md_error_t status = mdnullerror; 17050Sstevel@tonic-gate md_error_t *ep = &status; 17060Sstevel@tonic-gate md_set_desc *sd; 17070Sstevel@tonic-gate char buf[BUFSIZ]; 17080Sstevel@tonic-gate char *p = buf; 17090Sstevel@tonic-gate set_t max_sets, setno; 17100Sstevel@tonic-gate int err, cumm_err = 0; 17110Sstevel@tonic-gate size_t bufsz; 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate bufsz = sizeof (buf); 17140Sstevel@tonic-gate /* reset and parse args */ 17150Sstevel@tonic-gate optind = 1; 17160Sstevel@tonic-gate opterr = 1; 17170Sstevel@tonic-gate while ((c = getopt(argc, argv, "Ms:j")) != -1) { 17180Sstevel@tonic-gate switch (c) { 17190Sstevel@tonic-gate case 'M': 17200Sstevel@tonic-gate break; 17210Sstevel@tonic-gate case 'j': 17220Sstevel@tonic-gate break; 17230Sstevel@tonic-gate case 's': 17240Sstevel@tonic-gate sname = optarg; 17250Sstevel@tonic-gate break; 17260Sstevel@tonic-gate default: 17270Sstevel@tonic-gate usage(sp, gettext("unknown options")); 17280Sstevel@tonic-gate } 17290Sstevel@tonic-gate } 17300Sstevel@tonic-gate 17310Sstevel@tonic-gate argc -= optind; 17320Sstevel@tonic-gate argv += optind; 17330Sstevel@tonic-gate 17340Sstevel@tonic-gate if (argc > 1) 17350Sstevel@tonic-gate usage(sp, gettext("too many args")); 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate /* 17380Sstevel@tonic-gate * If no setname option was used, then join all disksets 17390Sstevel@tonic-gate * that this node knows about. Attempt to join all 17400Sstevel@tonic-gate * disksets that this node knows about. 17410Sstevel@tonic-gate * 17420Sstevel@tonic-gate * Additional text is added to the error messages during 17430Sstevel@tonic-gate * this section of code in order to help the user understand 17440Sstevel@tonic-gate * why the 'join of all sets' failed and which set caused 17450Sstevel@tonic-gate * the failure. 17460Sstevel@tonic-gate */ 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate /* 17490Sstevel@tonic-gate * Hold local set lock throughout this call to keep 17500Sstevel@tonic-gate * other actions from interfering (such as creating a new 17510Sstevel@tonic-gate * set, etc.). 17520Sstevel@tonic-gate */ 17530Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 17540Sstevel@tonic-gate mde_perror(ep, ""); 17550Sstevel@tonic-gate md_exit(sp, 1); 17560Sstevel@tonic-gate } 17570Sstevel@tonic-gate 17580Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 17590Sstevel@tonic-gate mde_perror(ep, ""); 17600Sstevel@tonic-gate md_exit(local_sp, 1); 17610Sstevel@tonic-gate } 17620Sstevel@tonic-gate 17630Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME) == 0) { 17640Sstevel@tonic-gate /* 17650Sstevel@tonic-gate * If no set name is given, then walk through all sets 17660Sstevel@tonic-gate * on this node which could include: 17670Sstevel@tonic-gate * - MN disksets 17680Sstevel@tonic-gate * - traditional disksets 17690Sstevel@tonic-gate * - non-existent disksets 17700Sstevel@tonic-gate * Attempt to join the MN disksets. 17710Sstevel@tonic-gate * If the join of one set fails, print out an error message 17720Sstevel@tonic-gate * about that set and continue the walk. 17730Sstevel@tonic-gate */ 17740Sstevel@tonic-gate if ((max_sets = get_max_sets(ep)) == 0) { 17750Sstevel@tonic-gate mde_perror(ep, ""); 17760Sstevel@tonic-gate md_exit(local_sp, 1); 17770Sstevel@tonic-gate } 17780Sstevel@tonic-gate 17790Sstevel@tonic-gate /* Start walking through all possible disksets */ 17800Sstevel@tonic-gate for (setno = 1; setno < max_sets; setno++) { 17810Sstevel@tonic-gate if ((sp = metasetnosetname(setno, ep)) == NULL) { 17820Sstevel@tonic-gate if (mdiserror(ep, MDE_NO_SET)) { 17830Sstevel@tonic-gate /* No set for this setno - continue */ 17840Sstevel@tonic-gate mdclrerror(ep); 17850Sstevel@tonic-gate continue; 17860Sstevel@tonic-gate } else { 17870Sstevel@tonic-gate (void) sprintf(p, gettext( 17880Sstevel@tonic-gate "Unable to get set %d information"), 17890Sstevel@tonic-gate setno); 17900Sstevel@tonic-gate mde_perror(ep, p); 17910Sstevel@tonic-gate cumm_err = 1; 17920Sstevel@tonic-gate mdclrerror(ep); 17930Sstevel@tonic-gate continue; 17940Sstevel@tonic-gate } 17950Sstevel@tonic-gate } 17960Sstevel@tonic-gate 17970Sstevel@tonic-gate /* If setname is there, set desc should exist. */ 17980Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 17990Sstevel@tonic-gate (void) snprintf(p, bufsz, gettext( 18000Sstevel@tonic-gate "Unable to get set %s desc information"), 18010Sstevel@tonic-gate sp->setname); 18020Sstevel@tonic-gate mde_perror(ep, p); 18030Sstevel@tonic-gate cumm_err = 1; 18040Sstevel@tonic-gate mdclrerror(ep); 18050Sstevel@tonic-gate continue; 18060Sstevel@tonic-gate } 18070Sstevel@tonic-gate 18080Sstevel@tonic-gate /* Only check MN disksets */ 18090Sstevel@tonic-gate if (!MD_MNSET_DESC(sd)) { 18100Sstevel@tonic-gate continue; 18110Sstevel@tonic-gate } 18120Sstevel@tonic-gate 18130Sstevel@tonic-gate /* 18140Sstevel@tonic-gate * Return value of 0 is success. 18150Sstevel@tonic-gate * Return value of -1 means a failure. 18160Sstevel@tonic-gate * Return value of -2 means set could not be 18170Sstevel@tonic-gate * joined, but shouldn't cause an error. 18180Sstevel@tonic-gate * Reasons would be: 18190Sstevel@tonic-gate * - no drives in set 18200Sstevel@tonic-gate * - node already joined to set 18210Sstevel@tonic-gate * Return value of -3 means joined stale set. 18220Sstevel@tonic-gate * Can't check for all reasons here 18230Sstevel@tonic-gate * since set isn't locked yet across all 18240Sstevel@tonic-gate * nodes in the cluster. The call 18250Sstevel@tonic-gate * to libmeta routine, meta_set_join, will 18260Sstevel@tonic-gate * lock across the cluster and perform 18270Sstevel@tonic-gate * the checks. 18280Sstevel@tonic-gate */ 18290Sstevel@tonic-gate if ((err = meta_set_join(sp, ep)) == -1) { 18300Sstevel@tonic-gate /* Print error of diskset join failure */ 18310Sstevel@tonic-gate (void) snprintf(p, bufsz, 18320Sstevel@tonic-gate gettext("Join to diskset %s failed"), 18330Sstevel@tonic-gate sp->setname); 18340Sstevel@tonic-gate mde_perror(ep, p); 18350Sstevel@tonic-gate cumm_err = 1; 18360Sstevel@tonic-gate mdclrerror(ep); 18370Sstevel@tonic-gate continue; 18380Sstevel@tonic-gate } 18390Sstevel@tonic-gate 18400Sstevel@tonic-gate if (err == -3) { 18410Sstevel@tonic-gate /* Print error of diskset join failure */ 18420Sstevel@tonic-gate (void) snprintf(p, bufsz, 18430Sstevel@tonic-gate gettext("Joined to stale diskset %s"), 18440Sstevel@tonic-gate sp->setname); 18450Sstevel@tonic-gate mde_perror(ep, p); 18460Sstevel@tonic-gate mdclrerror(ep); 18470Sstevel@tonic-gate } 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate mdclrerror(ep); 18500Sstevel@tonic-gate } 18510Sstevel@tonic-gate 18520Sstevel@tonic-gate md_exit(local_sp, cumm_err); 18530Sstevel@tonic-gate } 18540Sstevel@tonic-gate 18550Sstevel@tonic-gate /* 18560Sstevel@tonic-gate * Code for a specific set is much simpler. 18570Sstevel@tonic-gate * Error messages don't need extra text since specific setname 18580Sstevel@tonic-gate * was used. 18590Sstevel@tonic-gate * Don't need to lock the local set, just the specific set given. 18600Sstevel@tonic-gate */ 18610Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 18620Sstevel@tonic-gate mde_perror(ep, ""); 18630Sstevel@tonic-gate md_exit(local_sp, 1); 18640Sstevel@tonic-gate } 18650Sstevel@tonic-gate 18660Sstevel@tonic-gate /* 18670Sstevel@tonic-gate * Fail command if meta_set_join returns -1. 18680Sstevel@tonic-gate * 18690Sstevel@tonic-gate * Return of 0 means that node joined set. 18700Sstevel@tonic-gate * 18710Sstevel@tonic-gate * Return of -2 means that node was unable to 18720Sstevel@tonic-gate * join a set since that set had no drives 18730Sstevel@tonic-gate * or that had already joined the set. No 18740Sstevel@tonic-gate * need to fail the command for these reasons. 18750Sstevel@tonic-gate * 18760Sstevel@tonic-gate * Return of -3 means that set is stale. 18770Sstevel@tonic-gate * Return a value of 66 to historically match traditional disksets. 18780Sstevel@tonic-gate */ 18790Sstevel@tonic-gate if ((err = meta_set_join(sp, ep)) == -1) { 18800Sstevel@tonic-gate mde_perror(&status, ""); 18810Sstevel@tonic-gate md_exit(local_sp, 1); 18820Sstevel@tonic-gate } 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate if (err == -3) { 18850Sstevel@tonic-gate /* Print error of diskset join failure */ 18860Sstevel@tonic-gate (void) snprintf(p, bufsz, 18870Sstevel@tonic-gate gettext("Joined to stale diskset %s"), 18880Sstevel@tonic-gate sp->setname); 18890Sstevel@tonic-gate mde_perror(&status, ""); 18900Sstevel@tonic-gate md_exit(local_sp, 66); 18910Sstevel@tonic-gate } 18920Sstevel@tonic-gate 18930Sstevel@tonic-gate md_exit(local_sp, 0); 18940Sstevel@tonic-gate } 18950Sstevel@tonic-gate 18960Sstevel@tonic-gate /* 18970Sstevel@tonic-gate * Withdraws a node from a specific set or from all multinode disksets known 18980Sstevel@tonic-gate * by this node. If set is specified then caller should have verified 18990Sstevel@tonic-gate * that the set is a multinode diskset. 19000Sstevel@tonic-gate * 19010Sstevel@tonic-gate * If an error occurs, metaset exits with a 1. 19020Sstevel@tonic-gate * If there is no error, metaset exits with a 0. 19030Sstevel@tonic-gate */ 19040Sstevel@tonic-gate static void 19050Sstevel@tonic-gate parse_withdrawset(int argc, char **argv) 19060Sstevel@tonic-gate { 19070Sstevel@tonic-gate int c; 19080Sstevel@tonic-gate mdsetname_t *sp = NULL, *local_sp = NULL; 19090Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 19100Sstevel@tonic-gate md_error_t status = mdnullerror; 19110Sstevel@tonic-gate md_error_t *ep = &status; 19120Sstevel@tonic-gate char buf[BUFSIZ]; 19130Sstevel@tonic-gate char *p = buf; 19140Sstevel@tonic-gate md_set_desc *sd; 19150Sstevel@tonic-gate set_t max_sets, setno; 19160Sstevel@tonic-gate int err, cumm_err = 0; 19170Sstevel@tonic-gate size_t bufsz; 19180Sstevel@tonic-gate 19190Sstevel@tonic-gate bufsz = sizeof (buf); 19200Sstevel@tonic-gate /* reset and parse args */ 19210Sstevel@tonic-gate optind = 1; 19220Sstevel@tonic-gate opterr = 1; 19230Sstevel@tonic-gate while ((c = getopt(argc, argv, "Ms:w")) != -1) { 19240Sstevel@tonic-gate switch (c) { 19250Sstevel@tonic-gate case 'M': 19260Sstevel@tonic-gate break; 19270Sstevel@tonic-gate case 'w': 19280Sstevel@tonic-gate break; 19290Sstevel@tonic-gate case 's': 19300Sstevel@tonic-gate sname = optarg; 19310Sstevel@tonic-gate break; 19320Sstevel@tonic-gate default: 19330Sstevel@tonic-gate usage(sp, gettext("unknown options")); 19340Sstevel@tonic-gate } 19350Sstevel@tonic-gate } 19360Sstevel@tonic-gate 19370Sstevel@tonic-gate argc -= optind; 19380Sstevel@tonic-gate argv += optind; 19390Sstevel@tonic-gate 19400Sstevel@tonic-gate if (argc > 1) 19410Sstevel@tonic-gate usage(sp, gettext("too many args")); 19420Sstevel@tonic-gate 19430Sstevel@tonic-gate /* 19440Sstevel@tonic-gate * If no setname option was used, then withdraw from all disksets 19450Sstevel@tonic-gate * that this node knows about. 19460Sstevel@tonic-gate * 19470Sstevel@tonic-gate * Additional text is added to the error messages during 19480Sstevel@tonic-gate * this section of code in order to help the user understand 19490Sstevel@tonic-gate * why the 'withdraw from all sets' failed and which set caused 19500Sstevel@tonic-gate * the failure. 19510Sstevel@tonic-gate */ 19520Sstevel@tonic-gate 19530Sstevel@tonic-gate /* 19540Sstevel@tonic-gate * Hold local set lock throughout this call to keep 19550Sstevel@tonic-gate * other actions from interfering (such as creating a new 19560Sstevel@tonic-gate * set, etc.). 19570Sstevel@tonic-gate */ 19580Sstevel@tonic-gate if ((local_sp = metasetname(MD_LOCAL_NAME, ep)) == NULL) { 19590Sstevel@tonic-gate mde_perror(ep, ""); 19600Sstevel@tonic-gate md_exit(sp, 1); 19610Sstevel@tonic-gate } 19620Sstevel@tonic-gate 19630Sstevel@tonic-gate if (meta_lock(local_sp, TRUE, ep) != 0) { 19640Sstevel@tonic-gate mde_perror(ep, ""); 19650Sstevel@tonic-gate md_exit(local_sp, 1); 19660Sstevel@tonic-gate } 19670Sstevel@tonic-gate 19680Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME) == 0) { 19690Sstevel@tonic-gate /* 19700Sstevel@tonic-gate * If no set name is given, then walk through all sets 19710Sstevel@tonic-gate * on this node which could include: 19720Sstevel@tonic-gate * - MN disksets 19730Sstevel@tonic-gate * - traditional disksets 19740Sstevel@tonic-gate * - non-existent disksets 19750Sstevel@tonic-gate * Attempt to withdraw from the MN disksets. 19760Sstevel@tonic-gate * If the withdraw of one set fails, print out an error 19770Sstevel@tonic-gate * message about that set and continue the walk. 19780Sstevel@tonic-gate */ 19790Sstevel@tonic-gate if ((max_sets = get_max_sets(ep)) == 0) { 19800Sstevel@tonic-gate mde_perror(ep, ""); 19810Sstevel@tonic-gate md_exit(local_sp, 1); 19820Sstevel@tonic-gate } 19830Sstevel@tonic-gate 19840Sstevel@tonic-gate /* Start walking through all possible disksets */ 19850Sstevel@tonic-gate for (setno = 1; setno < max_sets; setno++) { 19860Sstevel@tonic-gate if ((sp = metasetnosetname(setno, ep)) == NULL) { 19870Sstevel@tonic-gate if (mdiserror(ep, MDE_NO_SET)) { 19880Sstevel@tonic-gate /* No set for this setno - continue */ 19890Sstevel@tonic-gate mdclrerror(ep); 19900Sstevel@tonic-gate continue; 19910Sstevel@tonic-gate } else { 19920Sstevel@tonic-gate (void) sprintf(p, gettext( 19930Sstevel@tonic-gate "Unable to get set %d information"), 19940Sstevel@tonic-gate setno); 19950Sstevel@tonic-gate mde_perror(ep, p); 19960Sstevel@tonic-gate cumm_err = 1; 19970Sstevel@tonic-gate mdclrerror(ep); 19980Sstevel@tonic-gate continue; 19990Sstevel@tonic-gate } 20000Sstevel@tonic-gate } 20010Sstevel@tonic-gate 20020Sstevel@tonic-gate /* If setname is there, set desc should exist. */ 20030Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 20040Sstevel@tonic-gate (void) snprintf(p, bufsz, gettext( 20050Sstevel@tonic-gate "Unable to get set %s desc information"), 20060Sstevel@tonic-gate sp->setname); 20070Sstevel@tonic-gate mde_perror(ep, p); 20080Sstevel@tonic-gate cumm_err = 1; 20090Sstevel@tonic-gate mdclrerror(ep); 20100Sstevel@tonic-gate continue; 20110Sstevel@tonic-gate } 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate /* Only check MN disksets */ 20140Sstevel@tonic-gate if (!MD_MNSET_DESC(sd)) { 20150Sstevel@tonic-gate continue; 20160Sstevel@tonic-gate } 20170Sstevel@tonic-gate 20180Sstevel@tonic-gate /* 20190Sstevel@tonic-gate * Return value of 0 is success. 20200Sstevel@tonic-gate * Return value of -1 means a failure. 20210Sstevel@tonic-gate * Return value of -2 means set could not be 20220Sstevel@tonic-gate * withdrawn from, but this shouldn't cause 20230Sstevel@tonic-gate * an error. Reasons would be: 20240Sstevel@tonic-gate * - no drives in set 20250Sstevel@tonic-gate * - node already withdrawn from set 20260Sstevel@tonic-gate * Can't check for all reasons here 20270Sstevel@tonic-gate * since set isn't locked yet across all 20280Sstevel@tonic-gate * nodes in the cluster. The call 20290Sstevel@tonic-gate * to libmeta routine, meta_set_withdraw, will 20300Sstevel@tonic-gate * lock across the cluster and perform 20310Sstevel@tonic-gate * the checks. 20320Sstevel@tonic-gate */ 20330Sstevel@tonic-gate if ((err = meta_set_withdraw(sp, ep)) == -1) { 20340Sstevel@tonic-gate /* Print error of diskset withdraw failure */ 20350Sstevel@tonic-gate (void) snprintf(p, bufsz, 20360Sstevel@tonic-gate gettext("Withdraw from diskset %s failed"), 20370Sstevel@tonic-gate sp->setname); 20380Sstevel@tonic-gate mde_perror(ep, p); 20390Sstevel@tonic-gate mdclrerror(ep); 20400Sstevel@tonic-gate cumm_err = 1; 20410Sstevel@tonic-gate continue; 20420Sstevel@tonic-gate } 20430Sstevel@tonic-gate 20440Sstevel@tonic-gate if (err == -2) { 20450Sstevel@tonic-gate mdclrerror(ep); 20460Sstevel@tonic-gate continue; 20470Sstevel@tonic-gate } 20480Sstevel@tonic-gate 20490Sstevel@tonic-gate mdclrerror(ep); 20500Sstevel@tonic-gate } 20510Sstevel@tonic-gate md_exit(local_sp, cumm_err); 20520Sstevel@tonic-gate } 20530Sstevel@tonic-gate 20540Sstevel@tonic-gate 20550Sstevel@tonic-gate /* 20560Sstevel@tonic-gate * Code for a specific set is much simpler. 20570Sstevel@tonic-gate * Error messages don't need extra text since specific setname 20580Sstevel@tonic-gate * was used. 20590Sstevel@tonic-gate * Don't need to lock the local set, just the specific set given. 20600Sstevel@tonic-gate */ 20610Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 20620Sstevel@tonic-gate mde_perror(ep, ""); 20630Sstevel@tonic-gate md_exit(local_sp, 1); 20640Sstevel@tonic-gate } 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate /* 20670Sstevel@tonic-gate * Fail command if meta_set_withdraw returns -1. 20680Sstevel@tonic-gate * 20690Sstevel@tonic-gate * Return of 0 means that node withdrew from set. 20700Sstevel@tonic-gate * 20710Sstevel@tonic-gate * Return of -2 means that node was unable to 20720Sstevel@tonic-gate * withdraw from a set since that set had no drives 20730Sstevel@tonic-gate * or node was not joined to set. No 20740Sstevel@tonic-gate * need to fail the command for these reasons. 20750Sstevel@tonic-gate */ 20760Sstevel@tonic-gate if (meta_set_withdraw(sp, ep) == -1) { 20770Sstevel@tonic-gate mde_perror(&status, ""); 20780Sstevel@tonic-gate md_exit(local_sp, 1); 20790Sstevel@tonic-gate } 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate md_exit(local_sp, 0); 20820Sstevel@tonic-gate } 20830Sstevel@tonic-gate 20840Sstevel@tonic-gate static void 2085*4932Spetede parse_cluster(int argc, char **argv, int multi_node) 20860Sstevel@tonic-gate { 2087*4932Spetede int c, error, new_argc, x; 20880Sstevel@tonic-gate enum cluster_cmd cmd = ccnotspecified; 2089*4932Spetede char *hostname = SDSSC_PROXY_PRIMARY; 2090*4932Spetede char *argument = NULL; 2091*4932Spetede char *sname = MD_LOCAL_NAME; 2092*4932Spetede char primary_node[SDSSC_NODE_NAME_LEN]; 2093*4932Spetede char **new_argv = NULL; 2094*4932Spetede char **np = NULL; 20950Sstevel@tonic-gate mdsetname_t *sp = NULL; 20960Sstevel@tonic-gate md_error_t status = mdnullerror; 20970Sstevel@tonic-gate md_error_t *ep = &status; 20980Sstevel@tonic-gate 20990Sstevel@tonic-gate /* reset and parse args */ 21000Sstevel@tonic-gate optind = 1; 21010Sstevel@tonic-gate opterr = 1; 21021320Srd117015 while ((c = getopt(argc, argv, "C:s:h:ftu:yr")) != -1) { 21030Sstevel@tonic-gate switch (c) { 21040Sstevel@tonic-gate case 'C': 21050Sstevel@tonic-gate if (cmd != ccnotspecified) { 21060Sstevel@tonic-gate md_exit(sp, -1); 21070Sstevel@tonic-gate } 21080Sstevel@tonic-gate argument = optarg; 21090Sstevel@tonic-gate 21100Sstevel@tonic-gate if (strcmp(argument, "disksin") == 0) { 21110Sstevel@tonic-gate cmd = clusterdisksin; 21120Sstevel@tonic-gate } else if (strcmp(argument, "version") == 0) { 21130Sstevel@tonic-gate cmd = clusterversion; 21140Sstevel@tonic-gate } else if (strcmp(argument, "release") == 0) { 21150Sstevel@tonic-gate cmd = clusterrelease; 21160Sstevel@tonic-gate } else if (strcmp(argument, "take") == 0) { 21170Sstevel@tonic-gate cmd = clustertake; 21180Sstevel@tonic-gate } else if (strcmp(argument, "proxy") == 0) { 21190Sstevel@tonic-gate cmd = clusterproxy; 21200Sstevel@tonic-gate } else if (strcmp(argument, "purge") == 0) { 21210Sstevel@tonic-gate cmd = clusterpurge; 21220Sstevel@tonic-gate } else { 21230Sstevel@tonic-gate md_exit(sp, -1); 21240Sstevel@tonic-gate } 21250Sstevel@tonic-gate 21260Sstevel@tonic-gate break; 21270Sstevel@tonic-gate 21280Sstevel@tonic-gate case 'h': 21290Sstevel@tonic-gate hostname = optarg; 21300Sstevel@tonic-gate break; 21310Sstevel@tonic-gate 21320Sstevel@tonic-gate case 's': 21330Sstevel@tonic-gate sname = optarg; 21340Sstevel@tonic-gate break; 21350Sstevel@tonic-gate 21360Sstevel@tonic-gate case 'f': 21370Sstevel@tonic-gate case 't': 21380Sstevel@tonic-gate case 'u': 21390Sstevel@tonic-gate case 'y': 21400Sstevel@tonic-gate case 'r': 21410Sstevel@tonic-gate break; 21420Sstevel@tonic-gate 21430Sstevel@tonic-gate default: 21440Sstevel@tonic-gate md_exit(sp, -1); 21450Sstevel@tonic-gate } 21460Sstevel@tonic-gate } 21470Sstevel@tonic-gate 21480Sstevel@tonic-gate /* Now call the appropriate command function. */ 21490Sstevel@tonic-gate switch (cmd) { 21500Sstevel@tonic-gate case clusterversion: 2151*4932Spetede printclusterversion(); 2152*4932Spetede break; 21530Sstevel@tonic-gate 21540Sstevel@tonic-gate case clusterdisksin: 2155*4932Spetede if (printdisksin(sname, ep)) { 2156*4932Spetede md_exit(sp, -1); 2157*4932Spetede } 2158*4932Spetede break; 21590Sstevel@tonic-gate 21600Sstevel@tonic-gate case clusterrelease: 2161*4932Spetede if (multi_node) { 2162*4932Spetede usage(sp, gettext( 2163*4932Spetede "-C release is not allowed on multi-owner" 2164*4932Spetede " disksets")); 2165*4932Spetede } 2166*4932Spetede parse_releaseset(argc, argv); 2167*4932Spetede break; 21680Sstevel@tonic-gate 21690Sstevel@tonic-gate case clustertake: 2170*4932Spetede if (multi_node) { 2171*4932Spetede usage(sp, gettext( 2172*4932Spetede "-C take is not allowed on multi-owner disksets")); 2173*4932Spetede } 2174*4932Spetede parse_takeset(argc, argv); 2175*4932Spetede break; 21760Sstevel@tonic-gate 21770Sstevel@tonic-gate case clusterproxy: 2178*4932Spetede if (multi_node) { 2179*4932Spetede usage(sp, gettext( 2180*4932Spetede "-C proxy is not allowed on multi-owner disksets")); 2181*4932Spetede } 21820Sstevel@tonic-gate 21830Sstevel@tonic-gate if ((new_argv = calloc(argc, sizeof (char *))) == NULL) { 21840Sstevel@tonic-gate printf(gettext("Out of memory\n")); 21850Sstevel@tonic-gate md_exit(sp, 1); 21860Sstevel@tonic-gate } 21870Sstevel@tonic-gate 21880Sstevel@tonic-gate np = new_argv; 21890Sstevel@tonic-gate new_argc = 0; 21900Sstevel@tonic-gate memset(primary_node, '\0', SDSSC_NODE_NAME_LEN); 21910Sstevel@tonic-gate 21920Sstevel@tonic-gate for (x = 0; x < argc; x++) { 21930Sstevel@tonic-gate if (strcmp(argv[x], "-C") == 0) { 21940Sstevel@tonic-gate 21950Sstevel@tonic-gate /* 21960Sstevel@tonic-gate * Need to skip the '-C proxy' args so 21970Sstevel@tonic-gate * just increase x by one and the work is 21980Sstevel@tonic-gate * done. 21990Sstevel@tonic-gate */ 22000Sstevel@tonic-gate x++; 22010Sstevel@tonic-gate } else { 22020Sstevel@tonic-gate *np++ = strdup(argv[x]); 22030Sstevel@tonic-gate new_argc++; 22040Sstevel@tonic-gate } 22050Sstevel@tonic-gate } 22060Sstevel@tonic-gate 22070Sstevel@tonic-gate switch (sdssc_get_primary_host(sname, primary_node, 22080Sstevel@tonic-gate SDSSC_NODE_NAME_LEN)) { 22090Sstevel@tonic-gate case SDSSC_ERROR: 22100Sstevel@tonic-gate md_exit(sp, 1); 22110Sstevel@tonic-gate break; 22120Sstevel@tonic-gate 22130Sstevel@tonic-gate case SDSSC_NO_SERVICE: 22140Sstevel@tonic-gate if (hostname != SDSSC_PROXY_PRIMARY) { 22150Sstevel@tonic-gate (void) strlcpy(primary_node, hostname, 22160Sstevel@tonic-gate SDSSC_NODE_NAME_LEN); 22170Sstevel@tonic-gate } 22180Sstevel@tonic-gate break; 22190Sstevel@tonic-gate } 22200Sstevel@tonic-gate 22210Sstevel@tonic-gate if (sdssc_cmd_proxy(new_argc, new_argv, 22220Sstevel@tonic-gate primary_node[0] == '\0' ? SDSSC_PROXY_PRIMARY : 22230Sstevel@tonic-gate primary_node, &error) == SDSSC_PROXY_DONE) { 22240Sstevel@tonic-gate md_exit(sp, error); 22250Sstevel@tonic-gate } else { 22260Sstevel@tonic-gate printf(gettext( 22270Sstevel@tonic-gate "Couldn't proxy command\n")); 22280Sstevel@tonic-gate md_exit(sp, 1); 22290Sstevel@tonic-gate } 22300Sstevel@tonic-gate break; 22310Sstevel@tonic-gate 22320Sstevel@tonic-gate case clusterpurge: 22330Sstevel@tonic-gate parse_purge(argc, argv); 22340Sstevel@tonic-gate break; 22350Sstevel@tonic-gate 22360Sstevel@tonic-gate default: 2237*4932Spetede break; 22380Sstevel@tonic-gate } 22390Sstevel@tonic-gate 22400Sstevel@tonic-gate md_exit(sp, 0); 22410Sstevel@tonic-gate } 22420Sstevel@tonic-gate 22430Sstevel@tonic-gate /* 22440Sstevel@tonic-gate * parse args and do it 22450Sstevel@tonic-gate */ 22460Sstevel@tonic-gate int 22470Sstevel@tonic-gate main(int argc, char *argv[]) 22480Sstevel@tonic-gate { 22490Sstevel@tonic-gate enum metaset_cmd cmd = notspecified; 22500Sstevel@tonic-gate md_error_t status = mdnullerror; 22510Sstevel@tonic-gate md_error_t *ep = &status; 22520Sstevel@tonic-gate mdsetname_t *sp = NULL; 2253*4932Spetede char *hostname = SDSSC_PROXY_PRIMARY; 2254*4932Spetede char *sname = MD_LOCAL_NAME; 2255*4932Spetede char *auto_take_option = NULL; 2256*4932Spetede char primary_node[SDSSC_NODE_NAME_LEN]; 2257*4932Spetede int error, c, stat; 2258*4932Spetede int auto_take = FALSE; 22590Sstevel@tonic-gate md_set_desc *sd; 22600Sstevel@tonic-gate int mflag = 0; 22610Sstevel@tonic-gate int multi_node = 0; 22620Sstevel@tonic-gate rval_e sdssc_res; 22630Sstevel@tonic-gate 22640Sstevel@tonic-gate /* 22650Sstevel@tonic-gate * Get the locale set up before calling any other routines 22660Sstevel@tonic-gate * with messages to ouput. Just in case we're not in a build 22670Sstevel@tonic-gate * environment, make sure that TEXT_DOMAIN gets set to 22680Sstevel@tonic-gate * something. 22690Sstevel@tonic-gate */ 22700Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 22710Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 22720Sstevel@tonic-gate #endif 22730Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 22740Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 22750Sstevel@tonic-gate 22760Sstevel@tonic-gate sdssc_res = sdssc_bind_library(); 22770Sstevel@tonic-gate if (sdssc_res == SDSSC_ERROR) { 22780Sstevel@tonic-gate printf(gettext( 22790Sstevel@tonic-gate "%s: Interface error with libsds_sc.so\n"), argv[0]); 22800Sstevel@tonic-gate exit(1); 22810Sstevel@tonic-gate } 22820Sstevel@tonic-gate 22830Sstevel@tonic-gate /* initialize */ 22840Sstevel@tonic-gate if (md_init(argc, argv, 0, 1, ep) != 0) { 22850Sstevel@tonic-gate mde_perror(ep, ""); 22860Sstevel@tonic-gate md_exit(sp, 1); 22870Sstevel@tonic-gate } 22880Sstevel@tonic-gate 22890Sstevel@tonic-gate optind = 1; 22900Sstevel@tonic-gate opterr = 1; 22910Sstevel@tonic-gate 22920Sstevel@tonic-gate /* 22930Sstevel@tonic-gate * NOTE: The "C" option is strictly for cluster use. it is not 22940Sstevel@tonic-gate * and should not be documented for the customer. - JST 22950Sstevel@tonic-gate */ 22961320Srd117015 while ((c = getopt(argc, argv, "C:MaA:bdfh:jl:Lm:oPqrs:tu:wy?")) 22970Sstevel@tonic-gate != -1) { 22980Sstevel@tonic-gate switch (c) { 22990Sstevel@tonic-gate case 'M': 23000Sstevel@tonic-gate mflag = 1; 23010Sstevel@tonic-gate break; 23020Sstevel@tonic-gate case 'A': 23030Sstevel@tonic-gate auto_take = TRUE; 23040Sstevel@tonic-gate if (optarg == NULL || !(strcmp(optarg, "enable") == 0 || 23050Sstevel@tonic-gate strcmp(optarg, "disable") == 0)) 23060Sstevel@tonic-gate usage(sp, gettext( 23070Sstevel@tonic-gate "-A: enable or disable must be specified")); 23080Sstevel@tonic-gate auto_take_option = optarg; 23090Sstevel@tonic-gate break; 23100Sstevel@tonic-gate case 'a': 23110Sstevel@tonic-gate if (cmd != notspecified) { 23120Sstevel@tonic-gate usage(sp, gettext( 23130Sstevel@tonic-gate "conflicting options")); 23140Sstevel@tonic-gate } 23150Sstevel@tonic-gate cmd = add; 23160Sstevel@tonic-gate break; 23170Sstevel@tonic-gate case 'b': 23180Sstevel@tonic-gate if (cmd != notspecified) { 23190Sstevel@tonic-gate usage(sp, gettext( 23200Sstevel@tonic-gate "conflicting options")); 23210Sstevel@tonic-gate } 23220Sstevel@tonic-gate cmd = balance; 23230Sstevel@tonic-gate break; 23240Sstevel@tonic-gate case 'd': 23250Sstevel@tonic-gate if (cmd != notspecified) { 23260Sstevel@tonic-gate usage(sp, gettext( 23270Sstevel@tonic-gate "conflicting options")); 23280Sstevel@tonic-gate } 23290Sstevel@tonic-gate cmd = delete; 23300Sstevel@tonic-gate break; 23310Sstevel@tonic-gate case 'C': /* cluster commands */ 23320Sstevel@tonic-gate if (cmd != notspecified) { 23330Sstevel@tonic-gate md_exit(sp, -1); /* conflicting options */ 23340Sstevel@tonic-gate } 23350Sstevel@tonic-gate cmd = cluster; 23360Sstevel@tonic-gate break; 23370Sstevel@tonic-gate case 'f': 23380Sstevel@tonic-gate break; 23390Sstevel@tonic-gate case 'h': 23400Sstevel@tonic-gate hostname = optarg; 23410Sstevel@tonic-gate break; 23420Sstevel@tonic-gate case 'j': 23430Sstevel@tonic-gate if (cmd != notspecified) { 23440Sstevel@tonic-gate usage(sp, gettext( 23450Sstevel@tonic-gate "conflicting options")); 23460Sstevel@tonic-gate } 23470Sstevel@tonic-gate cmd = join; 23480Sstevel@tonic-gate break; 23490Sstevel@tonic-gate case 'l': 23500Sstevel@tonic-gate break; 23510Sstevel@tonic-gate case 'L': 23520Sstevel@tonic-gate break; 23530Sstevel@tonic-gate case 'm': 23540Sstevel@tonic-gate break; 23550Sstevel@tonic-gate case 'o': 23560Sstevel@tonic-gate if (cmd != notspecified) { 23570Sstevel@tonic-gate usage(sp, gettext( 23580Sstevel@tonic-gate "conflicting options")); 23590Sstevel@tonic-gate } 23600Sstevel@tonic-gate cmd = isowner; 23610Sstevel@tonic-gate break; 23620Sstevel@tonic-gate case 'P': 23630Sstevel@tonic-gate if (cmd != notspecified) { 23640Sstevel@tonic-gate usage(sp, gettext( 23650Sstevel@tonic-gate "conflicting options")); 23660Sstevel@tonic-gate } 23670Sstevel@tonic-gate cmd = purge; 23680Sstevel@tonic-gate break; 23690Sstevel@tonic-gate case 'q': 23700Sstevel@tonic-gate if (cmd != notspecified) { 23710Sstevel@tonic-gate usage(sp, gettext( 23720Sstevel@tonic-gate "conflicting options")); 23730Sstevel@tonic-gate } 23740Sstevel@tonic-gate cmd = query; 23750Sstevel@tonic-gate break; 23760Sstevel@tonic-gate case 'r': 23770Sstevel@tonic-gate if (cmd != notspecified) { 23780Sstevel@tonic-gate usage(sp, gettext( 23790Sstevel@tonic-gate "conflicting options")); 23800Sstevel@tonic-gate } 23810Sstevel@tonic-gate cmd = release; 23820Sstevel@tonic-gate break; 23830Sstevel@tonic-gate case 's': 23840Sstevel@tonic-gate sname = optarg; 23850Sstevel@tonic-gate break; 23860Sstevel@tonic-gate case 't': 23870Sstevel@tonic-gate if (cmd != notspecified) { 23880Sstevel@tonic-gate usage(sp, gettext( 23890Sstevel@tonic-gate "conflicting options")); 23900Sstevel@tonic-gate } 23910Sstevel@tonic-gate cmd = take; 23920Sstevel@tonic-gate break; 23930Sstevel@tonic-gate case 'u': 23940Sstevel@tonic-gate break; 23950Sstevel@tonic-gate case 'w': 23960Sstevel@tonic-gate if (cmd != notspecified) { 23970Sstevel@tonic-gate usage(sp, gettext( 23980Sstevel@tonic-gate "conflicting options")); 23990Sstevel@tonic-gate } 24000Sstevel@tonic-gate cmd = withdraw; 24010Sstevel@tonic-gate break; 24020Sstevel@tonic-gate case 'y': 24030Sstevel@tonic-gate break; 24040Sstevel@tonic-gate case '?': 24050Sstevel@tonic-gate if (optopt == '?') 24060Sstevel@tonic-gate usage(sp, NULL); 24070Sstevel@tonic-gate /*FALLTHROUGH*/ 24080Sstevel@tonic-gate default: 24090Sstevel@tonic-gate if (cmd == cluster) { /* cluster is silent */ 24100Sstevel@tonic-gate md_exit(sp, -1); 24110Sstevel@tonic-gate } else { 24120Sstevel@tonic-gate usage(sp, gettext( 24130Sstevel@tonic-gate "unknown command")); 24140Sstevel@tonic-gate } 24150Sstevel@tonic-gate } 24160Sstevel@tonic-gate } 24170Sstevel@tonic-gate 24180Sstevel@tonic-gate /* check if suncluster is installed and -A enable specified */ 24190Sstevel@tonic-gate if (auto_take && sdssc_res != SDSSC_NOT_BOUND && 24200Sstevel@tonic-gate strcmp(auto_take_option, "enable") == 0) { 2421*4932Spetede md_eprintf(gettext( 2422*4932Spetede "cannot enable auto-take when SunCluster is installed\n")); 2423*4932Spetede md_exit(sp, 1); 24240Sstevel@tonic-gate } 24250Sstevel@tonic-gate 24260Sstevel@tonic-gate /* 24270Sstevel@tonic-gate * At this point we know that if the -A enable option is specified 24280Sstevel@tonic-gate * for an auto-take diskset that SC is not installed on the machine, so 24290Sstevel@tonic-gate * all of the sdssc calls will just be no-ops. 24300Sstevel@tonic-gate */ 24310Sstevel@tonic-gate 24320Sstevel@tonic-gate /* list sets */ 24330Sstevel@tonic-gate if (cmd == notspecified && auto_take == FALSE) { 24340Sstevel@tonic-gate parse_printset(argc, argv); 24350Sstevel@tonic-gate /*NOTREACHED*/ 24360Sstevel@tonic-gate } 24370Sstevel@tonic-gate 24380Sstevel@tonic-gate if (meta_check_root(ep) != 0) { 24390Sstevel@tonic-gate mde_perror(ep, ""); 24400Sstevel@tonic-gate md_exit(sp, 1); 24410Sstevel@tonic-gate } 24420Sstevel@tonic-gate 24430Sstevel@tonic-gate /* snarf MDDB */ 24440Sstevel@tonic-gate if (meta_setup_db_locations(ep) != 0) { 24450Sstevel@tonic-gate mde_perror(ep, ""); 24460Sstevel@tonic-gate md_exit(sp, 1); 24470Sstevel@tonic-gate } 24480Sstevel@tonic-gate 24490Sstevel@tonic-gate /* 24500Sstevel@tonic-gate * If sname is a diskset - check for multi_node. 24510Sstevel@tonic-gate * It is possible for sname to not exist. 24520Sstevel@tonic-gate */ 24530Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME)) { 24540Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) != NULL) { 24550Sstevel@tonic-gate /* Set exists - check for MN diskset */ 24560Sstevel@tonic-gate if ((sd = metaget_setdesc(sp, ep)) == NULL) { 24570Sstevel@tonic-gate mde_perror(ep, ""); 24580Sstevel@tonic-gate md_exit(sp, 1); 24590Sstevel@tonic-gate } 24600Sstevel@tonic-gate if (MD_MNSET_DESC(sd)) { 24610Sstevel@tonic-gate /* 24620Sstevel@tonic-gate * If a MN diskset always set multi_node 24630Sstevel@tonic-gate * regardless of whether the -M option was 24640Sstevel@tonic-gate * used or not (mflag). 24650Sstevel@tonic-gate */ 24660Sstevel@tonic-gate multi_node = 1; 24670Sstevel@tonic-gate } else { 24680Sstevel@tonic-gate /* 24690Sstevel@tonic-gate * If a traditional diskset, mflag must 24700Sstevel@tonic-gate * not be set. 24710Sstevel@tonic-gate */ 24720Sstevel@tonic-gate if (mflag) { 24730Sstevel@tonic-gate usage(sp, gettext( 24740Sstevel@tonic-gate "-M option only allowed " 24750Sstevel@tonic-gate "on multi-owner diskset")); 24760Sstevel@tonic-gate } 24770Sstevel@tonic-gate } 24780Sstevel@tonic-gate } else { 24790Sstevel@tonic-gate /* 24800Sstevel@tonic-gate * Set name does not exist, set multi_node 24810Sstevel@tonic-gate * based on -M option. 24820Sstevel@tonic-gate */ 24830Sstevel@tonic-gate if (mflag) { 24840Sstevel@tonic-gate multi_node = 1; 24850Sstevel@tonic-gate } 24860Sstevel@tonic-gate } 24870Sstevel@tonic-gate } 24880Sstevel@tonic-gate 24890Sstevel@tonic-gate if (auto_take && multi_node) { 24900Sstevel@tonic-gate /* Can't mix multinode and auto-take on a diskset */ 24910Sstevel@tonic-gate usage(sp, 24920Sstevel@tonic-gate gettext("-A option not allowed on multi-owner diskset")); 24930Sstevel@tonic-gate } 24940Sstevel@tonic-gate 24950Sstevel@tonic-gate /* 24960Sstevel@tonic-gate * MN disksets don't use DCS clustering services, so 24970Sstevel@tonic-gate * do not get primary_node for MN diskset since no command 24980Sstevel@tonic-gate * proxying is done to Primary cluster node. Do not proxy 24990Sstevel@tonic-gate * MN diskset commands of join and withdraw when issued without 25000Sstevel@tonic-gate * a valid setname. 25010Sstevel@tonic-gate * For traditional disksets: proxy all commands except a take 25020Sstevel@tonic-gate * and release. Use first host listed as the host to send the 25030Sstevel@tonic-gate * command to if there isn't already a primary 25040Sstevel@tonic-gate */ 25050Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME) && (multi_node == 0) && 25060Sstevel@tonic-gate (cmd != take) && (cmd != release) && 25070Sstevel@tonic-gate (cmd != cluster) && (cmd != join) && 25080Sstevel@tonic-gate (cmd != withdraw) && (cmd != purge)) { 25090Sstevel@tonic-gate stat = sdssc_get_primary_host(sname, primary_node, 25100Sstevel@tonic-gate SDSSC_NODE_NAME_LEN); 25110Sstevel@tonic-gate switch (stat) { 25120Sstevel@tonic-gate case SDSSC_ERROR: 25130Sstevel@tonic-gate return (0); 25140Sstevel@tonic-gate 25150Sstevel@tonic-gate case SDSSC_NO_SERVICE: 25160Sstevel@tonic-gate if (hostname != SDSSC_PROXY_PRIMARY) { 25170Sstevel@tonic-gate (void) strlcpy(primary_node, hostname, 25180Sstevel@tonic-gate SDSSC_NODE_NAME_LEN); 25190Sstevel@tonic-gate } else { 25200Sstevel@tonic-gate memset(primary_node, '\0', 25210Sstevel@tonic-gate SDSSC_NODE_NAME_LEN); 25220Sstevel@tonic-gate } 25230Sstevel@tonic-gate break; 25240Sstevel@tonic-gate } 25250Sstevel@tonic-gate 25260Sstevel@tonic-gate /* 25270Sstevel@tonic-gate * We've got a complicated decision here regarding 25280Sstevel@tonic-gate * the hostname. If we didn't get a primary host 25290Sstevel@tonic-gate * and a host name wasn't supplied on the command line 25300Sstevel@tonic-gate * then we need to revert to SDSSC_PROXY_PRIMARY. Otherwise 25310Sstevel@tonic-gate * use what's been found. 25320Sstevel@tonic-gate */ 25330Sstevel@tonic-gate if (sdssc_cmd_proxy(argc, argv, 25340Sstevel@tonic-gate primary_node[0] == '\0' ? 2535*4932Spetede SDSSC_PROXY_PRIMARY : primary_node, 25360Sstevel@tonic-gate &error) == SDSSC_PROXY_DONE) { 25370Sstevel@tonic-gate exit(error); 25380Sstevel@tonic-gate } 25390Sstevel@tonic-gate } 25400Sstevel@tonic-gate 25410Sstevel@tonic-gate /* cluster-specific commands */ 25420Sstevel@tonic-gate if (cmd == cluster) { 2543*4932Spetede parse_cluster(argc, argv, multi_node); 2544*4932Spetede /*NOTREACHED*/ 25450Sstevel@tonic-gate } 25460Sstevel@tonic-gate 25470Sstevel@tonic-gate /* join MultiNode diskset */ 25480Sstevel@tonic-gate if (cmd == join) { 25490Sstevel@tonic-gate /* 25500Sstevel@tonic-gate * If diskset specified, verify that it exists 25510Sstevel@tonic-gate * and is a multinode diskset. 25520Sstevel@tonic-gate */ 25530Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME)) { 25540Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 25550Sstevel@tonic-gate mde_perror(ep, ""); 25560Sstevel@tonic-gate md_exit(sp, 1); 25570Sstevel@tonic-gate } 25580Sstevel@tonic-gate 25590Sstevel@tonic-gate if (!multi_node) { 25600Sstevel@tonic-gate usage(sp, gettext( 25610Sstevel@tonic-gate "-j option only allowed on " 25620Sstevel@tonic-gate "multi-owner diskset")); 25630Sstevel@tonic-gate } 25640Sstevel@tonic-gate } 25650Sstevel@tonic-gate /* 25660Sstevel@tonic-gate * Start mddoors daemon here. 25670Sstevel@tonic-gate * mddoors itself takes care there will be only one 25680Sstevel@tonic-gate * instance running, so starting it twice won't hurt 25690Sstevel@tonic-gate */ 25700Sstevel@tonic-gate pclose(popen("/usr/lib/lvm/mddoors", "w")); 25710Sstevel@tonic-gate parse_joinset(argc, argv); 25720Sstevel@tonic-gate /*NOTREACHED*/ 25730Sstevel@tonic-gate } 25740Sstevel@tonic-gate 25750Sstevel@tonic-gate /* withdraw from MultiNode diskset */ 25760Sstevel@tonic-gate if (cmd == withdraw) { 25770Sstevel@tonic-gate /* 25780Sstevel@tonic-gate * If diskset specified, verify that it exists 25790Sstevel@tonic-gate * and is a multinode diskset. 25800Sstevel@tonic-gate */ 25810Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME)) { 25820Sstevel@tonic-gate if ((sp = metasetname(sname, ep)) == NULL) { 25830Sstevel@tonic-gate mde_perror(ep, ""); 25840Sstevel@tonic-gate md_exit(sp, 1); 25850Sstevel@tonic-gate } 25860Sstevel@tonic-gate 25870Sstevel@tonic-gate if (!multi_node) { 25880Sstevel@tonic-gate usage(sp, gettext( 25890Sstevel@tonic-gate "-w option only allowed on " 25900Sstevel@tonic-gate "multi-owner diskset")); 25910Sstevel@tonic-gate } 25920Sstevel@tonic-gate } 25930Sstevel@tonic-gate parse_withdrawset(argc, argv); 25940Sstevel@tonic-gate /*NOTREACHED*/ 25950Sstevel@tonic-gate } 25960Sstevel@tonic-gate 25970Sstevel@tonic-gate /* must have set for everything else */ 25980Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME) == 0) 25990Sstevel@tonic-gate usage(sp, gettext("setname must be specified")); 26000Sstevel@tonic-gate 26010Sstevel@tonic-gate /* add hosts or drives */ 26020Sstevel@tonic-gate if (cmd == add) { 26030Sstevel@tonic-gate /* 26040Sstevel@tonic-gate * In the multi node case start mddoors daemon. 26050Sstevel@tonic-gate * mddoors itself takes care there will be 26060Sstevel@tonic-gate * only one instance running, so starting it twice won't hurt 26070Sstevel@tonic-gate */ 26080Sstevel@tonic-gate if (multi_node) { 26090Sstevel@tonic-gate pclose(popen("/usr/lib/lvm/mddoors", "w")); 26100Sstevel@tonic-gate } 26110Sstevel@tonic-gate 26120Sstevel@tonic-gate parse_add(argc, argv); 26130Sstevel@tonic-gate /*NOTREACHED*/ 26140Sstevel@tonic-gate } 26150Sstevel@tonic-gate 26160Sstevel@tonic-gate /* re-balance the replicas */ 26170Sstevel@tonic-gate if (cmd == balance) { 26180Sstevel@tonic-gate parse_balance(argc, argv); 26190Sstevel@tonic-gate /*NOTREACHED*/ 26200Sstevel@tonic-gate } 26210Sstevel@tonic-gate 26220Sstevel@tonic-gate /* delete hosts or drives */ 26230Sstevel@tonic-gate if (cmd == delete) { 26240Sstevel@tonic-gate parse_del(argc, argv); 26250Sstevel@tonic-gate /*NOTREACHED*/ 26260Sstevel@tonic-gate } 26270Sstevel@tonic-gate 26280Sstevel@tonic-gate /* check ownership */ 26290Sstevel@tonic-gate if (cmd == isowner) { 26300Sstevel@tonic-gate parse_isowner(argc, argv); 26310Sstevel@tonic-gate /*NOTREACHED*/ 26320Sstevel@tonic-gate } 26330Sstevel@tonic-gate 26340Sstevel@tonic-gate /* purge the diskset */ 26350Sstevel@tonic-gate if (cmd == purge) { 26360Sstevel@tonic-gate parse_purge(argc, argv); 26370Sstevel@tonic-gate /*NOTREACHED*/ 26380Sstevel@tonic-gate } 26390Sstevel@tonic-gate 26400Sstevel@tonic-gate /* query for data marks */ 26410Sstevel@tonic-gate if (cmd == query) { 26420Sstevel@tonic-gate parse_query(argc, argv); 26430Sstevel@tonic-gate /*NOTREACHED*/ 26440Sstevel@tonic-gate } 26450Sstevel@tonic-gate 26460Sstevel@tonic-gate /* release ownership */ 26470Sstevel@tonic-gate if (cmd == release) { 26480Sstevel@tonic-gate if (multi_node) { 26490Sstevel@tonic-gate /* Can't release multinode diskset */ 26500Sstevel@tonic-gate usage(sp, gettext( 26510Sstevel@tonic-gate "-r option not allowed on multi-owner diskset")); 26520Sstevel@tonic-gate } else { 26530Sstevel@tonic-gate parse_releaseset(argc, argv); 26540Sstevel@tonic-gate /*NOTREACHED*/ 26550Sstevel@tonic-gate } 26560Sstevel@tonic-gate } 26570Sstevel@tonic-gate 26580Sstevel@tonic-gate /* take ownership */ 26590Sstevel@tonic-gate if (cmd == take) { 26600Sstevel@tonic-gate if (multi_node) { 26610Sstevel@tonic-gate /* Can't take multinode diskset */ 26620Sstevel@tonic-gate usage(sp, gettext( 26630Sstevel@tonic-gate "-t option not allowed on multi-owner diskset")); 26640Sstevel@tonic-gate } else { 26650Sstevel@tonic-gate parse_takeset(argc, argv); 26660Sstevel@tonic-gate /*NOTREACHED*/ 26670Sstevel@tonic-gate } 26680Sstevel@tonic-gate } 26690Sstevel@tonic-gate 26700Sstevel@tonic-gate /* take ownership of auto-take sets */ 26710Sstevel@tonic-gate if (auto_take) { 26720Sstevel@tonic-gate parse_autotake(argc, argv); 26730Sstevel@tonic-gate /*NOTREACHED*/ 26740Sstevel@tonic-gate } 26750Sstevel@tonic-gate 26760Sstevel@tonic-gate /*NOTREACHED*/ 26770Sstevel@tonic-gate return (0); 26780Sstevel@tonic-gate } 2679