fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/utsname.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mdb_modapi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netdb.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libintl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stream.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socket.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/in.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <arpa/inet.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <pthread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_u.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_impl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_io.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_prot.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/librdc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdcerr.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_dtrinkets.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_etrinkets.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socket.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mnttab.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/in.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <arpa/inet.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/tcp.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/rpc_com.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/rpc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RDC_LOCAL_TAG "local"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bitmap_in_use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 1 if in use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if not in use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return -1 on error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebitmap_in_use(int cmd, char *hostp, char *bmp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CFGFILE *cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char host[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char shost[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char pri[CFG_MAX_BUF]; /* rdc primary vol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char sec[CFG_MAX_BUF]; /* rdc secondary vol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char sbm[CFG_MAX_BUF]; /* rdc secondary bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char bit[CFG_MAX_BUF]; /* a bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char mas[CFG_MAX_BUF]; /* II master */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char sha[CFG_MAX_BUF]; /* II shadow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char mod[CFG_MAX_BUF]; /* II mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char ovr[CFG_MAX_BUF]; /* II overflow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(NULL)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_DSCFG, 0, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_RDLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_DSCFG, 0, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look into II config to see if this is being used elsewhere
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CSTYLED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; ; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setnumber = i + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(key, sizeof (key), "ii.set%d", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = sscanf(buf, "%s %s %s %s %s", mas, sha, bit, mod, ovr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_OS, 0, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * got master shadow bitmap, now compare
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(bmp, mas) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, sha) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, bit) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, ovr) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "bitmap %s is in use by"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Point-in-Time Copy", bmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and last but not least, make sure sndr is not using vol for anything
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CSTYLED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; ; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setnumber = i + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(key, sizeof (key), "sndr.set%d", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I think this is quicker than
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * having to double dip into the config
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sscanf(buf, "%s %s %s %s %s %s", host, pri, bit,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shost, sec, sbm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == RDC_CMD_ENABLE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (self_check(host)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(bmp, pri) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, bit) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_NONFATAL, dgettext("librdc",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "bitmap %s is in use by %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp, RDC_NAME_DU_JOUR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(bmp, sec) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, sbm) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_NONFATAL, dgettext("librdc",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "bitmap %s is in use by %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp, RDC_NAME_DU_JOUR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cmd == RDC_CMD_RECONFIG) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * read this logic 1000 times and consider
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multi homed, one to many, many to one (marketing)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * etc, etc, before changing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (self_check(hostp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (self_check(host)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(bmp, pri) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, bit) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "bitmap"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " %s is in use by %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp, RDC_NAME_DU_JOUR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(hostp, shost) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, sec) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, sbm) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "bitmap"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " %s is in use by %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp, RDC_NAME_DU_JOUR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* self_check(hostp) failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (self_check(host)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(shost, hostp) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, sec) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, sbm) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "bitmap"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " %s is in use by %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp, RDC_NAME_DU_JOUR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(host, hostp) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, pri) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(bmp, bit) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "bitmap"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " %s is in use by %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp, RDC_NAME_DU_JOUR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecheck_dgislocal(char *dgname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *othernode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check where this disk service is mastered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_dgname_islocal(dgname, &othernode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to find "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disk service, %s: %s"), dgname, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("disk service, %s, is "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "active on node \"%s\"\nPlease re-issue "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "the command on that node"), dgname, othernode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DCMD_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortectag_check(rdcconfig_t *rdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *file_dgname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *bmp_dgname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *fromhost, *tohost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *fromfile, *tofile;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *frombitmap, *tobitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *localfile;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *ctag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char file_buf[MAX_RDC_HOST_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char bmp_buf[MAX_RDC_HOST_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int is_primary;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int islocal = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct hostent *hp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char fromname[MAXHOSTNAMELEN], toname[MAXHOSTNAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fromhost = rdc->phost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fromfile = rdc->pfile;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte frombitmap = rdc->pbmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tohost = rdc->shost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tofile = rdc->sfile;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tobitmap = rdc->sbmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctag = rdc->ctag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check for the special (local) cluster tag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_iscluster())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctag != NULL && strcmp(rdc->ctag, RDC_LOCAL_TAG) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(rdc->ctag, "-");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte islocal = TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte islocal = FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = gethost_byname(fromhost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(fromname, hp->h_name, MAXHOSTNAMELEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = gethost_byname(tohost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(toname, hp->h_name, MAXHOSTNAMELEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!self_check(fromname) && !self_check(toname)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we could get a list of logical hosts on this cluster
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then we could print something intelligent about where
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the volume is mastered. For now, just print some babble
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * about the fact that we have no idea.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("either %s:%s or %s:%s is not local"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fromhost, fromfile, tohost, tofile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_primary = self_check(fromname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If implicit disk group name and no ctag specified by user,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we set the ctag to it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If implicit disk group name, it must match any supplied ctag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_primary)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte localfile = fromfile;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte localfile = tofile;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_dgname = cfg_dgname(localfile, file_buf, sizeof (file_buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (file_dgname != NULL && file_dgname[0] != '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (check_dgislocal(file_dgname) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* errors already set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(ctag) == 0 && file_dgname && strlen(file_dgname))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(ctag, file_dgname, MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * making an exception here for users giving the "local"tag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this overrides this error message. (rdc_islocal ! = 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(ctag) != 0 && file_dgname && islocal != 1 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(file_dgname) != 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(ctag, file_dgname, MAX_RDC_HOST_SIZE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("ctag \"%s\" does not "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "match disk group name \"%s\" of volume %s"), ctag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte file_dgname, localfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((file_dgname == NULL) || ((strlen(ctag) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strlen(file_dgname) == 0))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we must have a non-volume managed disk here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so ask for a tag and get out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("volume \"%s\" is not part"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " of a disk group,\nplease specify resource ctag\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte localfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Local bitmap must also have same ctag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_primary)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte localfile = frombitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte localfile = tobitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp_dgname = cfg_dgname(localfile, bmp_buf, sizeof (bmp_buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bmp_dgname != NULL && bmp_dgname[0] != '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (check_dgislocal(bmp_dgname) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* error already set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (file_dgname && strlen(file_dgname) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* File is in a real disk group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bmp_dgname == NULL) || (strlen(bmp_dgname) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Bitmap is not in a real disk group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("bitmap %s is not in disk group \"%s\""),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte localfile, islocal < 1?file_dgname:ctag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(ctag) != 0 && bmp_dgname && islocal != 1 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(bmp_dgname) != 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(ctag, bmp_dgname, MAX_RDC_HOST_SIZE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("ctag \"%s\" does not "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "match disk group name \"%s\" of bitmap %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctag, bmp_dgname, localfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemounted(char *device)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char target[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct mnttab mntref;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct mnttab mntent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *mntfp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rdsk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdsk = i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (s = target; i < NSC_MAXPATH && (*s = *device++); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*s == 'r' && rdsk == 0 && strncmp(device, "dsk/", 4) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdsk = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *s = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_special = target;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_mountp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_fstype = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_mntopts = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_time = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntfp = fopen(MNTTAB, "r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mntfp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Assume the worst, that it is mounted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = getmntany(mntfp, &mntent, &mntref)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* found something before EOF */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fclose(mntfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fclose(mntfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecan_enable(rdcconfig_t *rdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(rdc->pfile, rdc->pbmp) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(rdc->sfile, rdc->sbmp) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "volumes and bitmaps must not match"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctag_check(rdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* rdc_error should already be set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (self_check(rdc->phost)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(rdc->pfile, &stb) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_OS, RDC_FATAL, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!S_ISCHR(stb.st_mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "%s is not a character device"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc->pfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc->persist ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !bitmap_in_use(RDC_CMD_ENABLE, rdc->phost, rdc->pbmp) : 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* on the secondary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(rdc->sfile, &stb) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_OS, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc", "unable to access %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc->sfile, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!S_ISCHR(stb.st_mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgettext("librdc",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s is not a character device"), rdc->sfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc->persist ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !bitmap_in_use(RDC_CMD_ENABLE, rdc->shost, rdc->sbmp) : 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecan_reconfig_pbmp(rdcconfig_t *rdc, char *bmp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc->persist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (!bitmap_in_use(RDC_CMD_RECONFIG, rdc->phost, bmp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecan_reconfig_sbmp(rdcconfig_t *rdc, char *bmp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc->persist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (!bitmap_in_use(RDC_CMD_RECONFIG, rdc->shost, bmp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_rc_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecant_rsync(rdcconfig_t *rdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_rc_t *rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mounted(rdc->pfile)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = new_rc();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->set.phost, rdc->phost, MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->set.pfile, rdc->pfile, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->set.pbmp, rdc->pbmp, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->set.shost, rdc->shost, MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->set.sfile, rdc->sfile, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->set.sbmp, rdc->sbmp, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc->rc = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_error(NULL, RDC_INTERNAL, 0, "unable to sync %s volume"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " is currently mounted", rdc->pfile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(rc->msg, rdc_error(NULL), RDC_ERR_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}