rdcpersist.c revision 2
1df6105803c4c56c020a56301c7c9c4890fd4158mathog/*
6a55cc6751be1162fa737fa656ffae0729c2e2a0Krzysztof Kosiński * CDDL HEADER START
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog *
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * The contents of this file are subject to the terms of the
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * Common Development and Distribution License (the "License").
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * You may not use this file except in compliance with the License.
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog *
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * or http://www.opensolaris.org/os/licensing.
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * See the License for the specific language governing permissions
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * and limitations under the License.
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog *
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * When distributing Covered Code, include this CDDL HEADER in each
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * If applicable, add the following below this CDDL HEADER, with the
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * fields enclosed by brackets "[]" replaced with your own identifying
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * information: Portions Copyright [yyyy] [name of copyright owner]
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog *
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * CDDL HEADER END
1df6105803c4c56c020a56301c7c9c4890fd4158mathog */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog/*
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * Use is subject to license terms.
1df6105803c4c56c020a56301c7c9c4890fd4158mathog */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/types.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/stat.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/mkdev.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <fcntl.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <unistd.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <stropts.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <stdio.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <errno.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <libintl.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <locale.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <stdlib.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/nsctl/rdcerr.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/nsctl/rdc_ioctl.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/nsctl/librdc.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/nsctl/cfg.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/nsctl/nsc_hash.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/nsctl/sv.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/unistat/spcs_dtrinkets.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/unistat/spcs_etrinkets.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/unistat/spcs_s.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/unistat/spcs_s_u.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/unistat/spcs_s_impl.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog#include <sys/unistat/spcs_errors.h>
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogtypedef struct volcount_s {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog int count;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog} volcount_t;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathoghash_node_t **volhash = NULL;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogchar *
1df6105803c4c56c020a56301c7c9c4890fd4158mathogconfig2buf(char *buf, rdcconfig_t *rdc)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog snprintf(buf, CFG_MAX_BUF, "%s %s %s %s %s %s %s %s %s %s %s",
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc->phost, rdc->pfile, rdc->pbmp, rdc->shost, rdc->sfile,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc->sbmp, rdc->direct, rdc->mode, rdc->group ? rdc->group : "",
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc->ctag ? rdc->ctag : "", rdc->options ? rdc->options : "");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (buf);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog/*
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * SV type functions.
1df6105803c4c56c020a56301c7c9c4890fd4158mathog */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogstatic void
1df6105803c4c56c020a56301c7c9c4890fd4158mathogload_rdc_vols(CFGFILE *cfg)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog int set;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char key[ CFG_MAX_KEY ];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char buf[ CFG_MAX_BUF ];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char *vol, *bmp, *host1, *host2;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount_t *volcount;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (volhash) {
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog return;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog }
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog cfg_rewind(cfg, CFG_SEC_CONF);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog volhash = nsc_create_hash();
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog for (set = 1; /*CSTYLED*/; set++) {
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog snprintf(key, CFG_MAX_KEY, "sndr.set%d", set);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog break;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog host1 = strtok(buf, " ");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog vol = strtok(NULL, " ");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bmp = strtok(NULL, " ");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (!self_check(host1)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog /* next one had better be ours */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog host2 = strtok(NULL, " ");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog vol = strtok(NULL, " ");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bmp = strtok(NULL, " ");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (!self_check(host2)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog continue;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog /* primary vol may be used more than once */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount = (volcount_t *)nsc_lookup(volhash, vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (volcount) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount->count++;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount = (volcount_t *)malloc(sizeof (volcount_t));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount->count = 1;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog nsc_insert_node(volhash, volcount, vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog /* bitmap ought to be only used once */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount = (volcount_t *)nsc_lookup(volhash, bmp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (volcount) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog /* argh */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount->count++;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount = (volcount_t *)malloc(sizeof (volcount_t));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount->count = 1;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog nsc_insert_node(volhash, volcount, bmp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogsv_enable_one_nocfg(char *vol)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog struct stat sb;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog sv_conf_t svc;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog int fd;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bzero(&svc, sizeof (svc));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (stat(vol, &sb) != 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_OS, 0, "unable to stat %s", vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (!S_ISCHR(sb.st_mode)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL, "%s is not"
1df6105803c4c56c020a56301c7c9c4890fd4158mathog " a character device", vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svc.svc_major = major(sb.st_rdev);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svc.svc_minor = minor(sb.st_rdev);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(svc.svc_path, vol, sizeof (svc.svc_path));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog fd = open(SV_DEVICE, O_RDONLY);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (fd < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_OS, 0, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svc.svc_flag = (NSC_DEVICE | NSC_CACHE);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svc.svc_error = spcs_s_ucreate();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (ioctl(fd, SVIOC_ENABLE, &svc) < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (errno != SV_EENABLED) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(&svc.svc_error, RDC_INTERNAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog RDC_NONFATAL, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_log("sv", NULL, gettext("enabled %s"), svc.svc_path);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog close(fd);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogsv_enable_nocfg(rdcconfig_t *rdc)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog struct stat stbv;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog struct stat stbb;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog sv_conf_t svcv;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog sv_conf_t svcb;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char vol[NSC_MAXPATH];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char bmp[NSC_MAXPATH];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog int fd = -1;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (self_check(rdc->phost)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(vol, rdc->pfile, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(bmp, rdc->pbmp, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(vol, rdc->sfile, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(bmp, rdc->sbmp, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bzero(&svcv, sizeof (svcv));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bzero(&svcb, sizeof (svcb));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if ((stat(vol, &stbv) != 0) || (stat(bmp, &stbb) != 0))
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if ((!S_ISCHR(stbv.st_mode)) || (!S_ISCHR(stbb.st_mode)))
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcv.svc_major = major(stbv.st_rdev);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcb.svc_minor = minor(stbb.st_rdev);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(svcv.svc_path, vol, sizeof (svcv.svc_path));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(svcb.svc_path, bmp, sizeof (svcb.svc_path));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog fd = open(SV_DEVICE, O_RDONLY);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (fd < 0)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog /* SV enable the volume */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcv.svc_flag = (NSC_DEVICE | NSC_CACHE);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcv.svc_error = spcs_s_ucreate();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (ioctl(fd, SVIOC_ENABLE, &svcv) < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (errno != SV_EENABLED) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_log("sv", &svcv.svc_error,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog gettext("unable to enable %s"),
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcv.svc_path);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_s_ufree(&svcv.svc_error);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog /* SV enable the bitmap disable the vol on error */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcb.svc_flag = (NSC_DEVICE | NSC_CACHE);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcb.svc_error = spcs_s_ucreate();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (ioctl(fd, SVIOC_ENABLE, &svcb) < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (errno != SV_EENABLED) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_log("sv", &svcb.svc_error,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog gettext("unable to enable %s"),
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcb.svc_path);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (ioctl(fd, SVIOC_DISABLE, &svcv) < 0)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_log("sv", &svcv.svc_error,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog gettext("unable to disable %s"),
1df6105803c4c56c020a56301c7c9c4890fd4158mathog svcv.svc_path);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_s_ufree(&svcv.svc_error);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_s_ufree(&svcb.svc_error);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_log("sv", NULL, gettext("enabled %s"), svcv.svc_path);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_log("sv", NULL, gettext("enabled %s"), svcb.svc_path);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_s_ufree(&svcv.svc_error);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog spcs_s_ufree(&svcb.svc_error);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (fd >= 0)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog (void) close(fd);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogdo_autosv_enable(CFGFILE *cfg, rdcconfig_t *rdc)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char vol[NSC_MAXPATH];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char bmp[NSC_MAXPATH];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_load_svols(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_load_dsvols(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_load_shadows(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog load_rdc_vols(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (self_check(rdc->phost)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(vol, rdc->pfile, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(bmp, rdc->pbmp, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(vol, rdc->sfile, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(bmp, rdc->sbmp, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (nsc_lookup(volhash, vol) == NULL) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_vol_enable(cfg, vol, rdc->ctag, "sndr") < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog "auto sv enable failed for %s", vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (nsc_lookup(volhash, bmp) == NULL) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_vol_enable(cfg, bmp, rdc->ctag, "sndr") < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog "auto sv enable failed for %s", vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog nsc_remove_all(volhash, free);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volhash = NULL;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_unload_shadows();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_unload_dsvols();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_unload_svols();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogdo_autosv_disable(CFGFILE *cfg, rdcconfig_t *rdc)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char vol[NSC_MAXPATH];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char bmp[NSC_MAXPATH];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog volcount_t *vc;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_load_svols(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_load_dsvols(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_load_shadows(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog load_rdc_vols(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (self_check(rdc->phost)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(vol, rdc->pfile, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(bmp, rdc->pbmp, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(vol, rdc->sfile, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog strncpy(bmp, rdc->sbmp, NSC_MAXPATH);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog vc = nsc_lookup(volhash, vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (vc && (vc->count == 1)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_vol_disable(cfg, vol, rdc->ctag, "sndr") < 0)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog "auto sv disable failed for %s", vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else if (!vc) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog "Unable to find %s in config", vol);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog vc = nsc_lookup(volhash, bmp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (vc && (vc->count == 1)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_vol_disable(cfg, bmp, rdc->ctag, "sndr") < 0)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog "auto sv disable failed for %s", bmp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else if (!vc) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog "Unable to find %s in config", bmp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog/*
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * do sv enables for the appropriate vol
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * and bitmap. If called without persistance
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * it will follow a chain and sv enable all
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * otherwise, it will enable only the one
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * set.
1df6105803c4c56c020a56301c7c9c4890fd4158mathog */
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogsv_enable(CFGFILE *cfg, rdcconfig_t *rdcs)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcconfig_t *rdcp = NULL;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcp = rdcs;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (!rdcp->persist) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (sv_enable_nocfg(rdcp));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog } else if (cfg == NULL) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog do_autosv_enable(cfg, rdcp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
06517eb74772b7c18a8ab8d703405646d9ec05d3mathogsv_disable(CFGFILE *cfg, rdcconfig_t *rdcs)
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog{
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog rdcconfig_t *rdcp;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog rdcp = rdcs;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (!rdcp->persist) { /* don't disable */
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog return (1);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog } else if (cfg == NULL) {
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog return (-1);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog }
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog do_autosv_disable(cfg, rdcp);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog return (1);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog}
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog/*
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * disable the appropriate bitmap in rdc
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog * and replace it with bitmap
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog */
06517eb74772b7c18a8ab8d703405646d9ec05d3mathogint
06517eb74772b7c18a8ab8d703405646d9ec05d3mathogsv_reconfig(CFGFILE *cfg, rdcconfig_t *rdc, char *oldbmp, char *newbmp)
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog{
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog rdcconfig_t *rdcp;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog int fail = 0;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog rdcp = rdc;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (!rdcp->persist) { /* just enable, don't disable */
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog sv_enable_one_nocfg(newbmp);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog } else if (rdcp->persist) { /* do sv disable and enable */
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog volcount_t *vc;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog cfg_load_svols(cfg);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog cfg_load_dsvols(cfg);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog cfg_load_shadows(cfg);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog load_rdc_vols(cfg);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog vc = (volcount_t *)nsc_lookup(volhash, oldbmp);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (vc && (vc->count == 1)) {
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (cfg_vol_disable(cfg, oldbmp, rdc->ctag, "sndr") < 0)
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog "auto sv disable failed for %s", oldbmp);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog }
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (nsc_lookup(volhash, newbmp) == NULL) {
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog if (cfg_vol_enable(cfg,
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog newbmp, rdc->ctag, "sndr") < 0) {
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog "auto sv enable failed for %s", newbmp);
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog fail++;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog }
5da08901f6f284dfb64e741ed2f6287d9cfc087amathog }
5da08901f6f284dfb64e741ed2f6287d9cfc087amathog nsc_remove_all(volhash, free);
5da08901f6f284dfb64e741ed2f6287d9cfc087amathog volhash = NULL;
06517eb74772b7c18a8ab8d703405646d9ec05d3mathog
5da08901f6f284dfb64e741ed2f6287d9cfc087amathog cfg_unload_shadows();
5da08901f6f284dfb64e741ed2f6287d9cfc087amathog cfg_unload_dsvols();
5da08901f6f284dfb64e741ed2f6287d9cfc087amathog cfg_unload_svols();
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (fail)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog/*
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * SNDR functions
1df6105803c4c56c020a56301c7c9c4890fd4158mathog */
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog/*
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * add_to_rdc_cfg
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * this adds the successfully created rdc sets to libdscfg,
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * also, as auto_sv stuff is part of libdscfg, it does the
1df6105803c4c56c020a56301c7c9c4890fd4158mathog * auto_sv stuff and enables the correct volumes
1df6105803c4c56c020a56301c7c9c4890fd4158mathog */
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogadd_to_rdc_cfg(rdcconfig_t *rdcs)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog CFGFILE *cfg;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcconfig_t *rdcp;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char *buf;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog buf = calloc(CFG_MAX_BUF, sizeof (char));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (!buf) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_OS, RDC_FATAL, NULL);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (NULL);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if ((cfg = cfg_open(NULL)) == NULL) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_DSCFG, 0, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if ((cfg_lock(cfg, CFG_WRLOCK)) < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_DSCFG, 0, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcp = rdcs;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog while (rdcp) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog buf = config2buf(buf, rdcp);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if ((sv_enable(cfg, rdcp) < 0) ||
1df6105803c4c56c020a56301c7c9c4890fd4158mathog (cfg_put_cstring(cfg, "sndr", buf, CFG_MAX_BUF) < 0)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_DSCFG, 0, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog free(buf);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcp = rdcp->next;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (!cfg_commit(cfg)) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_DSCFG, 0, NULL);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_close(cfg);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogint
1df6105803c4c56c020a56301c7c9c4890fd4158mathogcfg_lookup(CFGFILE *cfg, char *shost, char *sfile)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char buf[CFG_MAX_BUF];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char key[CFG_MAX_KEY];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog int setnum;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog int numsets = 0;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog numsets = cfg_get_num_entries(cfg, "sndr");
1df6105803c4c56c020a56301c7c9c4890fd4158mathog for (setnum = 1; setnum <= numsets; setnum++) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bzero(key, CFG_MAX_KEY);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog snprintf(key, CFG_MAX_KEY, "sndr.set%d.shost", setnum);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_DSCFG, 0, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (strncmp(buf, shost, strlen(shost)))
1df6105803c4c56c020a56301c7c9c4890fd4158mathog continue;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog bzero(key, CFG_MAX_KEY);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog snprintf(key, CFG_MAX_KEY, "sndr.set%d.secondary", setnum);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdc_set_error(NULL, RDC_DSCFG, 0, 0);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (-1);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if (strncmp(buf, sfile, strlen(sfile)))
1df6105803c4c56c020a56301c7c9c4890fd4158mathog continue;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog break;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog }
1df6105803c4c56c020a56301c7c9c4890fd4158mathog return (setnum);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog}
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathogvoid
1df6105803c4c56c020a56301c7c9c4890fd4158mathogremove_from_rdc_cfg(rdcconfig_t *rdcs)
1df6105803c4c56c020a56301c7c9c4890fd4158mathog{
1df6105803c4c56c020a56301c7c9c4890fd4158mathog CFGFILE *cfg;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcconfig_t *rdcp;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog char key[CFG_MAX_KEY];
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog rdcp = rdcs;
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg = cfg_open(NULL);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_lock(cfg, CFG_WRLOCK);
1df6105803c4c56c020a56301c7c9c4890fd4158mathog
1df6105803c4c56c020a56301c7c9c4890fd4158mathog while (rdcp) {
1df6105803c4c56c020a56301c7c9c4890fd4158mathog snprintf(key, CFG_MAX_KEY, "sndr.set%d",
1df6105803c4c56c020a56301c7c9c4890fd4158mathog cfg_lookup(cfg, rdcp->shost, rdcp->sfile));
1df6105803c4c56c020a56301c7c9c4890fd4158mathog if ((sv_disable(cfg, rdcp) < 0) ||
(cfg_put_cstring(cfg, key, NULL, 0)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
}
rdcp = rdcp->next;
}
cfg_commit(cfg);
cfg_close(cfg);
}
/*ARGSUSED*/
int
replace_entry(int offset, char *entry)
{
return (1);
}
/*
* this will set the value at "field" in dscfg to the
* value contained in entry.
* for things like bitmap reconfigs, only pass one rdc
* not a chain
*/
int
replace_cfgfield(rdcconfig_t *rdc, char *field, char *entry)
{
CFGFILE *cfg;
rdcconfig_t *rdcp;
char key[CFG_MAX_KEY];
char newentry[CFG_MAX_BUF];
char oldbmp[CFG_MAX_BUF];
int setnum;
int ispbmp = 0;
int issbmp = 0;
if (strncmp(field, "pbitmap", NSC_MAXPATH) == 0)
ispbmp++;
if (strncmp(field, "sbitmap", NSC_MAXPATH) == 0)
issbmp++;
bzero(newentry, sizeof (newentry));
if (!entry || strlen(entry) == 0)
*newentry = '-';
else
strncpy(newentry, entry, CFG_MAX_BUF);
if ((cfg = cfg_open(NULL)) == NULL) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
return (-1);
}
if ((cfg_lock(cfg, CFG_WRLOCK)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
return (-1);
}
rdcp = rdc;
while (rdcp) {
if ((setnum = cfg_lookup(cfg, rdcp->shost, rdcp->sfile)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
return (-1);
}
snprintf(key, CFG_MAX_KEY, "sndr.set%d.%s", setnum, field);
if (!((ispbmp || issbmp) &&
(cfg_get_cstring(cfg, key, oldbmp, CFG_MAX_BUF)) == 0)) {
rdc_set_error(NULL, RDC_DSCFG, 0, "unable to get %s",
key);
}
if (((ispbmp && self_check(rdcp->phost)) ||
(issbmp && self_check(rdcp->shost))) &&
(sv_reconfig(cfg, rdcp, oldbmp, newentry) < 0)) {
rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
"unable to sv reconfig %s to %s", oldbmp, newentry);
return (-1);
}
if ((cfg_put_cstring(cfg, key, newentry, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
return (-1);
}
rdcp = rdcp->next;
}
cfg_commit(cfg);
cfg_close(cfg);
return (1);
}
/*
* reverse_in_cfg
* used by RDC_OPT_REVERSE_ROLE
* swaps primary info and secondary info
*/
int
reverse_in_cfg(rdcconfig_t *rdc)
{
CFGFILE *cfg;
rdcconfig_t *rdcp = NULL;
char key[CFG_MAX_KEY];
int setnum;
if ((cfg = cfg_open(NULL)) == NULL) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
return (-1);
}
if ((cfg_lock(cfg, CFG_WRLOCK)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
return (-1);
}
rdcp = rdc;
while (rdcp) {
if ((setnum = cfg_lookup(cfg, rdcp->shost, rdcp->sfile)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
bzero(key, CFG_MAX_KEY);
snprintf(key, CFG_MAX_KEY, "sndr.set%d.phost", setnum);
if ((cfg_put_cstring(cfg, key, rdcp->shost, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
bzero(key, CFG_MAX_KEY);
snprintf(key, CFG_MAX_KEY, "sndr.set%d.primary", setnum);
if ((cfg_put_cstring(cfg, key, rdcp->sfile, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
bzero(key, CFG_MAX_KEY);
snprintf(key, CFG_MAX_KEY, "sndr.set%d.pbitmap", setnum);
if ((cfg_put_cstring(cfg, key, rdcp->sbmp, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
bzero(key, CFG_MAX_KEY);
snprintf(key, CFG_MAX_KEY, "sndr.set%d.shost", setnum);
if ((cfg_put_cstring(cfg, key, rdcp->phost, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
bzero(key, CFG_MAX_KEY);
snprintf(key, CFG_MAX_KEY, "sndr.set%d.secondary", setnum);
if ((cfg_put_cstring(cfg, key, rdcp->pfile, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
bzero(key, CFG_MAX_KEY);
snprintf(key, CFG_MAX_KEY, "sndr.set%d.sbitmap", setnum);
if ((cfg_put_cstring(cfg, key, rdcp->pbmp, CFG_MAX_BUF)) < 0) {
rdc_set_error(NULL, RDC_DSCFG, 0, 0);
goto badconfig;
}
rdcp = rdcp->next;
}
if (!cfg_commit(cfg)) {
cfg_close(cfg);
return (-1);
}
cfg_close(cfg);
return (0);
badconfig:
cfg_close(cfg);
return (-1);
}