fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/dsw_dev.h> /* for bitmap format */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid copyshd(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint find_cfg_info(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint copy_shadow_vol(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern char *optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't copy shadow, only update dscfg and ii header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc == 1 || (argc%2) == 0) /* must have pairs of filenames */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open dscfg anyway */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Error opening config\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* close dscfg */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("\tiicpshd [-s] old_shadow new_shadow\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*LINTED pointer alignment*/
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Both old and new shadow "
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "file names must begin with a /.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check old shadow is in dscfg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check ii set status, suspend if need */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strncpy(args.shadow_vol, old_vol, DSW_NAMELEN);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Suspend the Point-in-Time Copy "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "set first\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("%s is not a character device\n"), real_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* use block device /dsk/ to update bitmap header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open bitmap by using update mode */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't open bitmap file\n"));
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 if (hp->ii_magic != DSW_CLEAN && hp->ii_magic != DSW_DIRTY) {
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);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strncpy(hp->shadow_vol, new_vol, DSW_NAMELEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reset the pointer position */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fwrite(&header, DSW_CBLK_FBA, FBA_SIZE(1), ifp) != FBA_SIZE(1)) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Failed to update dscfg.\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "iicpshd copy shadow from %s to %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find_cfg_info()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get read lock */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Error locking config\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; ; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, DSW_NAMELEN) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release read lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecopy_shadow_vol(char *old_shadow, char *new_shadow) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't open old shadow file\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Can't open new shadow file\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy the shadow vol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((i = fread(cp_buffer, sizeof (char), sizeof (cp_buffer), ishdfp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fwrite(cp_buffer, sizeof (char), i, oshdfp) != i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get write lock */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("Error locking config\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, new_shadow, len) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, new_shadow, len) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sprintf(key, DSVOL_TOKEN, dsvol_number);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, new_shadow, len) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i = 0, j = 0;