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/*
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 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/time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <values.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdarg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_u.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/dsw.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/dsw_dev.h> /* for bitmap format */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DSW_TEXT_DOMAIN "II"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define BITMAP_TOKEN "ii.set%d.bitmap"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SHADOW_TOKEN "ii.set%d.shadow"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SV_TOKEN "sv.set%d.vol"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DSVOL_TOKEN "dsvol.set%d.path"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid iicpshd_usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid copyshd(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint find_cfg_info(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint copy_shadow_vol(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid convert_to_blockdevice();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint update_dscfg(char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int optind;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern char *optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int optind, opterr, optopt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint copy_shadow = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteCFGFILE *cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar real_bitmap[DSW_NAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint set_number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sv_number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint dsvol_number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiicpshd_lintmain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(argv[1], "-s") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't copy shadow, only update dscfg and ii header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copy_shadow = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte argc--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte argv++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc == 1 || (argc%2) == 0) /* must have pairs of filenames */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iicpshd_usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open dscfg anyway */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(NULL)) == NULL) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Error opening config\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (argv++; *argv != NULL; argv += 2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copyshd(argv[0], argv[1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* close dscfg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiicpshd_usage()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Usage:\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("\tiicpshd [-s] old_shadow new_shadow\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecopyshd(char *old_vol, char *new_vol)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int dsw_fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *ifp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char header[FBA_SIZE(1) * DSW_CBLK_FBA];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ii_header_t *hp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsw_stat_t args;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED pointer alignment*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = (ii_header_t *)&header;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsw_fd = open(DSWDEV, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dsw_fd < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(DSWDEV);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*old_vol != '/' || *new_vol != '/') {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Both old and new shadow "
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "file names must begin with a /.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(new_vol) > DSW_NAMELEN) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("New shadow name is to long.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check old shadow is in dscfg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (find_cfg_info(old_vol, SHADOW_TOKEN) == 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("Old shadow not in existing cfg\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check ii set status, suspend if need */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strncpy(args.shadow_vol, old_vol, DSW_NAMELEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte args.shadow_vol[DSW_NAMELEN-1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte args.status = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(dsw_fd, DSWIOC_STAT, &args) != -1) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Suspend the Point-in-Time Copy "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "set first\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) close(dsw_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copy_shadow) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (copy_shadow_vol(old_vol, new_vol) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("Write new shadow failed"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) close(dsw_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (find_cfg_info(old_vol, SV_TOKEN) == 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("Old shadow not in existing cfg\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (find_cfg_info(old_vol, DSVOL_TOKEN) == 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("Old shadow not in existing cfg\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(real_bitmap, "/rdsk/") == NULL) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("%s is not a character device\n"), real_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* use block device /dsk/ to update bitmap header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte convert_to_blockdevice();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open bitmap by using update mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ifp = fopen(real_bitmap, "r+")) == NULL) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't open bitmap file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check old header looks like an II bitmap header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fread(&header, DSW_CBLK_FBA, FBA_SIZE(1), ifp) != FBA_SIZE(1)) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't read bitmap file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp->ii_magic != DSW_CLEAN && hp->ii_magic != DSW_DIRTY) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("%s is not a Point-in-Time Copy "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "shadow.\n"), old_vol);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(hp->shadow_vol, old_vol, DSW_NAMELEN) != 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("%s has Point-in-Time Copy "
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "shadow magic number,\n"
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "but does not contain correct data.\n"), old_vol);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) memset(hp->shadow_vol, 0, DSW_NAMELEN);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strncpy(hp->shadow_vol, new_vol, DSW_NAMELEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reset the pointer position */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rewind(ifp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fwrite(&header, DSW_CBLK_FBA, FBA_SIZE(1), ifp) != FBA_SIZE(1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(new_vol);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("Can't write new bitmap header\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fclose(ifp);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) close(dsw_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (update_dscfg(new_vol) == 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Failed to update dscfg.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("ii", NULL,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "iicpshd copy shadow from %s to %s",
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki old_vol, new_vol);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find_cfg_info()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefind_cfg_info(char *volume, char *token)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get read lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_RDLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("ii", NULL,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "iicpbmp CFG_RDLOCK failed, errno %d", errno);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Error locking config\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; ; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buf, CFG_MAX_BUF);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) snprintf(key, sizeof (key), token, i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, DSW_NAMELEN) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_unlock(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(buf, volume) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(token, SHADOW_TOKEN) == 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) snprintf(key, sizeof (key),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki BITMAP_TOKEN, i);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) cfg_get_cstring(cfg, key,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki real_bitmap, DSW_NAMELEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_number = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcmp(token, SV_TOKEN) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_number = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcmp(token, DSVOL_TOKEN) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsvol_number = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release read lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_unlock(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecopy_shadow_vol(char *old_shadow, char *new_shadow) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char cp_buffer[256];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *ishdfp, *oshdfp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ishdfp = fopen(old_shadow, "r")) == NULL) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't open old shadow file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((oshdfp = fopen(new_shadow, "w")) == NULL) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't open new shadow file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy the shadow vol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((i = fread(cp_buffer, sizeof (char), sizeof (cp_buffer), ishdfp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fwrite(cp_buffer, sizeof (char), i, oshdfp) != i) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fclose(ishdfp);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fclose(oshdfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fclose(ishdfp);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fclose(oshdfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteupdate_dscfg(char *new_shadow) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len = strlen(new_shadow);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get write lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_WRLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("ii", NULL,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "iicpbmp CFG_WRLOCK failed, errno %d", errno);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Error locking config\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sprintf(key, SHADOW_TOKEN, set_number);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, new_shadow, len) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("cfg_put_cstring");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sprintf(key, SV_TOKEN, sv_number);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, new_shadow, len) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("cfg_put_cstring");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sprintf(key, DSVOL_TOKEN, dsvol_number);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, new_shadow, len) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("cfg_put_cstring");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) cfg_commit(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_unlock(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconvert_to_blockdevice() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len = strlen(real_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i = 0, j = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *temp_string = malloc(len-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (i < len + 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (real_bitmap[i] != 'r') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte temp_string[j] = real_bitmap[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte j++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(real_bitmap, temp_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(temp_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}