10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*8979SRameshkumar.Ramasamy@Sun.COM * Common Development and Distribution License (the "License"). 6*8979SRameshkumar.Ramasamy@Sun.COM * 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*8979SRameshkumar.Ramasamy@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * mediator status utility. 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <meta.h> 310Sstevel@tonic-gate #include <sdssc.h> 320Sstevel@tonic-gate 330Sstevel@tonic-gate static void 340Sstevel@tonic-gate usage( 350Sstevel@tonic-gate mdsetname_t *sp, 360Sstevel@tonic-gate char *string) 370Sstevel@tonic-gate { 380Sstevel@tonic-gate if ((string != NULL) && (*string != '\0')) 390Sstevel@tonic-gate md_eprintf("%s\n", string); 400Sstevel@tonic-gate (void) fprintf(stderr, gettext( 410Sstevel@tonic-gate "usage: %s [-q] -s setname\n"), 42*8979SRameshkumar.Ramasamy@Sun.COM myname); 430Sstevel@tonic-gate md_exit(sp, (string == NULL) ? 0 : 1); 440Sstevel@tonic-gate } 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * parse args and do it 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate int 500Sstevel@tonic-gate main( 510Sstevel@tonic-gate int argc, 520Sstevel@tonic-gate char *argv[] 530Sstevel@tonic-gate ) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate int c; 560Sstevel@tonic-gate char *sname = MD_LOCAL_NAME; 570Sstevel@tonic-gate md_error_t status = mdnullerror; 580Sstevel@tonic-gate md_error_t *ep = &status; 590Sstevel@tonic-gate mdsetname_t *sp = NULL; 60*8979SRameshkumar.Ramasamy@Sun.COM md_set_desc *sd; 61*8979SRameshkumar.Ramasamy@Sun.COM int i; 62*8979SRameshkumar.Ramasamy@Sun.COM md_h_t mdh; 63*8979SRameshkumar.Ramasamy@Sun.COM med_data_t medd; 64*8979SRameshkumar.Ramasamy@Sun.COM int medok = 0; 65*8979SRameshkumar.Ramasamy@Sun.COM int golden = 0; 660Sstevel@tonic-gate int verbose = 1; 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * Get the locale set up before calling any other routines 700Sstevel@tonic-gate * with messages to ouput. Just in case we're not in a build 710Sstevel@tonic-gate * environment, make sure that TEXT_DOMAIN gets set to 720Sstevel@tonic-gate * something. 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 750Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 760Sstevel@tonic-gate #endif 770Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 780Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 790Sstevel@tonic-gate 807044Smk117520 /* 817044Smk117520 * There is no need to proxy the command to owner of the set 827044Smk117520 * to get the mediator information as the /etc/lvm/meddb file 837044Smk117520 * contains the required information and so it can be used. 847044Smk117520 */ 857044Smk117520 if ((sdssc_bind_library() == SDSSC_ERROR)) { 867044Smk117520 (void) fprintf(stderr, 877044Smk117520 "Failed to initialised libscsds.so.1\n"); 887044Smk117520 exit(1); 897044Smk117520 } 907044Smk117520 910Sstevel@tonic-gate /* initialize */ 920Sstevel@tonic-gate if (md_init(argc, argv, 0, 1, ep) != 0) { 930Sstevel@tonic-gate mde_perror(ep, ""); 940Sstevel@tonic-gate md_exit(sp, 1); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate optind = 1; 980Sstevel@tonic-gate opterr = 1; 990Sstevel@tonic-gate while ((c = getopt(argc, argv, "qs:?")) != -1) { 1000Sstevel@tonic-gate switch (c) { 101*8979SRameshkumar.Ramasamy@Sun.COM case 'q': 102*8979SRameshkumar.Ramasamy@Sun.COM verbose = 0; 103*8979SRameshkumar.Ramasamy@Sun.COM break; 104*8979SRameshkumar.Ramasamy@Sun.COM case 's': 105*8979SRameshkumar.Ramasamy@Sun.COM sname = optarg; 106*8979SRameshkumar.Ramasamy@Sun.COM break; 107*8979SRameshkumar.Ramasamy@Sun.COM case '?': 108*8979SRameshkumar.Ramasamy@Sun.COM if (optopt == '?') 109*8979SRameshkumar.Ramasamy@Sun.COM usage(sp, NULL); 110*8979SRameshkumar.Ramasamy@Sun.COM /*FALLTHROUGH*/ 111*8979SRameshkumar.Ramasamy@Sun.COM default: 1120Sstevel@tonic-gate usage(sp, gettext("unknown command")); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate } 115*8979SRameshkumar.Ramasamy@Sun.COM 1160Sstevel@tonic-gate /* must have set for everything else */ 1170Sstevel@tonic-gate if (strcmp(sname, MD_LOCAL_NAME) == 0) 1180Sstevel@tonic-gate usage(sp, gettext("setname must be specified")); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* snarf MDDB */ 1210Sstevel@tonic-gate if (meta_setup_db_locations(ep) != 0) { 1220Sstevel@tonic-gate mde_perror(ep, ""); 1230Sstevel@tonic-gate md_exit(sp, 1); 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate 126*8979SRameshkumar.Ramasamy@Sun.COM if ((sp = metasetname(sname, ep)) != NULL) { 127*8979SRameshkumar.Ramasamy@Sun.COM 128*8979SRameshkumar.Ramasamy@Sun.COM if ((sd = metaget_setdesc(sp, ep)) == NULL) { 129*8979SRameshkumar.Ramasamy@Sun.COM mde_perror(ep, ""); 130*8979SRameshkumar.Ramasamy@Sun.COM md_exit(sp, 1); 131*8979SRameshkumar.Ramasamy@Sun.COM } 132*8979SRameshkumar.Ramasamy@Sun.COM 133*8979SRameshkumar.Ramasamy@Sun.COM if (sd->sd_med.n_cnt == 0) { 134*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 135*8979SRameshkumar.Ramasamy@Sun.COM (void) printf(gettext("No mediator hosts" 136*8979SRameshkumar.Ramasamy@Sun.COM "configured for set \"%s\".\n"), sname); 137*8979SRameshkumar.Ramasamy@Sun.COM md_exit(sp, 2); 138*8979SRameshkumar.Ramasamy@Sun.COM } 139*8979SRameshkumar.Ramasamy@Sun.COM 140*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 141*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("%8.8s\t\t%6.6s\t" 142*8979SRameshkumar.Ramasamy@Sun.COM "%6.6s\n", gettext("Mediator"), 143*8979SRameshkumar.Ramasamy@Sun.COM gettext("Status"), gettext("Golden")); 144*8979SRameshkumar.Ramasamy@Sun.COM 145*8979SRameshkumar.Ramasamy@Sun.COM for (i = 0; i < MED_MAX_HOSTS; i++) { 146*8979SRameshkumar.Ramasamy@Sun.COM 147*8979SRameshkumar.Ramasamy@Sun.COM if (sd->sd_med.n_lst[i].a_cnt == 0) 148*8979SRameshkumar.Ramasamy@Sun.COM continue; 149*8979SRameshkumar.Ramasamy@Sun.COM 150*8979SRameshkumar.Ramasamy@Sun.COM (void) memset(&medd, '\0', sizeof (medd)); 151*8979SRameshkumar.Ramasamy@Sun.COM (void) memset(&mdh, '\0', sizeof (mdh)); 152*8979SRameshkumar.Ramasamy@Sun.COM mdh = sd->sd_med.n_lst[i]; 153*8979SRameshkumar.Ramasamy@Sun.COM 154*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 155*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("%-17.17s\t", 156*8979SRameshkumar.Ramasamy@Sun.COM sd->sd_med.n_lst[i].a_nm[0]); 157*8979SRameshkumar.Ramasamy@Sun.COM 158*8979SRameshkumar.Ramasamy@Sun.COM if (clnt_med_get_data(&mdh, sp, &medd, ep) == -1) { 159*8979SRameshkumar.Ramasamy@Sun.COM if (mdanyrpcerror(ep)) { 160*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 161*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("%s\n", 162*8979SRameshkumar.Ramasamy@Sun.COM gettext("Unreachable")); 163*8979SRameshkumar.Ramasamy@Sun.COM continue; 164*8979SRameshkumar.Ramasamy@Sun.COM } else if (mdiserror(ep, MDE_MED_ERROR)) { 165*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 166*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("%s\n", 167*8979SRameshkumar.Ramasamy@Sun.COM gettext("Bad")); 168*8979SRameshkumar.Ramasamy@Sun.COM } else { 169*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 170*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("%s\n", 171*8979SRameshkumar.Ramasamy@Sun.COM gettext("Fatal")); 172*8979SRameshkumar.Ramasamy@Sun.COM } 173*8979SRameshkumar.Ramasamy@Sun.COM mde_perror(ep, ""); 174*8979SRameshkumar.Ramasamy@Sun.COM if (mdiserror(ep, MDE_MED_ERROR)) 175*8979SRameshkumar.Ramasamy@Sun.COM continue; 176*8979SRameshkumar.Ramasamy@Sun.COM md_exit(sp, 1); 177*8979SRameshkumar.Ramasamy@Sun.COM } 178*8979SRameshkumar.Ramasamy@Sun.COM 179*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 180*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("%s", gettext("Ok")); 181*8979SRameshkumar.Ramasamy@Sun.COM 182*8979SRameshkumar.Ramasamy@Sun.COM if (medd.med_dat_fl & MED_DFL_GOLDEN) { 183*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 184*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("\t%s", 185*8979SRameshkumar.Ramasamy@Sun.COM gettext("Yes")); 186*8979SRameshkumar.Ramasamy@Sun.COM golden++; 187*8979SRameshkumar.Ramasamy@Sun.COM } else { 188*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 189*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("\t%s", gettext("No")); 190*8979SRameshkumar.Ramasamy@Sun.COM } 191*8979SRameshkumar.Ramasamy@Sun.COM 192*8979SRameshkumar.Ramasamy@Sun.COM if (verbose) 193*8979SRameshkumar.Ramasamy@Sun.COM (void) printf("\n"); 194*8979SRameshkumar.Ramasamy@Sun.COM 195*8979SRameshkumar.Ramasamy@Sun.COM medok++; 196*8979SRameshkumar.Ramasamy@Sun.COM } 197*8979SRameshkumar.Ramasamy@Sun.COM 198*8979SRameshkumar.Ramasamy@Sun.COM if (golden) 199*8979SRameshkumar.Ramasamy@Sun.COM md_exit(sp, 0); 200*8979SRameshkumar.Ramasamy@Sun.COM 201*8979SRameshkumar.Ramasamy@Sun.COM if (medok < ((sd->sd_med.n_cnt / 2) + 1)) 202*8979SRameshkumar.Ramasamy@Sun.COM md_exit(sp, 1); 203*8979SRameshkumar.Ramasamy@Sun.COM 204*8979SRameshkumar.Ramasamy@Sun.COM md_exit(sp, 0); 205*8979SRameshkumar.Ramasamy@Sun.COM } 206*8979SRameshkumar.Ramasamy@Sun.COM 2077044Smk117520 /* 208*8979SRameshkumar.Ramasamy@Sun.COM * Print the mediator status using /etc/lvm/meddb if host is not 209*8979SRameshkumar.Ramasamy@Sun.COM * part of metaset but part of mediators. 2107044Smk117520 */ 2110Sstevel@tonic-gate 2127044Smk117520 if (meta_mediator_info_from_file(sname, verbose, ep)) { 2130Sstevel@tonic-gate md_exit(sp, 1); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate md_exit(sp, 0); 2177044Smk117520 /* NOTREACHED */ 2180Sstevel@tonic-gate return (0); 2190Sstevel@tonic-gate } 220