17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*fe0e7ec4Smaheshvs * Common Development and Distribution License (the "License"). 6*fe0e7ec4Smaheshvs * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*fe0e7ec4Smaheshvs * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include "dump.h" 377c478bd9Sstevel@tonic-gate #include <rmt.h> 387c478bd9Sstevel@tonic-gate #include <setjmp.h> 397c478bd9Sstevel@tonic-gate #include <sys/fdio.h> 407c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 417c478bd9Sstevel@tonic-gate #include <assert.h> 427c478bd9Sstevel@tonic-gate #include <limits.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define SLEEPMS 50 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate static uint_t writesize; /* size of malloc()ed buffer for tape */ 477c478bd9Sstevel@tonic-gate static ino_t inos[TP_NINOS]; /* starting inodes on each tape */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * The req structure is used to pass commands from the parent 517c478bd9Sstevel@tonic-gate * process through the pipes to the slave processes. It comes 527c478bd9Sstevel@tonic-gate * in two flavors, depending on which mode dump is operating under: 537c478bd9Sstevel@tonic-gate * an inode request (on-line mode) and a disk block request ("old" mode). 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * The inode request structure is used during on-line mode. 577c478bd9Sstevel@tonic-gate * The master passes inode numbers and starting offsets to 587c478bd9Sstevel@tonic-gate * the slaves. The tape writer passes out the current inode, 597c478bd9Sstevel@tonic-gate * offset, and number of tape records written after completing a volume. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate struct ireq { 627c478bd9Sstevel@tonic-gate ino_t inumber; /* inode number to open/dump */ 637c478bd9Sstevel@tonic-gate long igen; /* inode generation number */ 647c478bd9Sstevel@tonic-gate off_t offset; /* starting offset in inode */ 657c478bd9Sstevel@tonic-gate int count; /* count for 1st spclrec */ 667c478bd9Sstevel@tonic-gate }; 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * The block request structure is used in off-line mode to pass 697c478bd9Sstevel@tonic-gate * commands to dump disk blocks from the parent process through 707c478bd9Sstevel@tonic-gate * the pipes to the slave processes. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate struct breq { 737c478bd9Sstevel@tonic-gate diskaddr_t dblk; /* disk address to read */ 747c478bd9Sstevel@tonic-gate size_t size; /* number of bytes to read from disk */ 757c478bd9Sstevel@tonic-gate ulong_t spclrec[1]; /* actually longer */ 767c478bd9Sstevel@tonic-gate }; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate struct req { 797c478bd9Sstevel@tonic-gate short aflag; /* write data to archive process as well */ 807c478bd9Sstevel@tonic-gate short tflag; /* begin new tape */ 817c478bd9Sstevel@tonic-gate union reqdata { 827c478bd9Sstevel@tonic-gate struct ireq ino; /* used for on-line mode */ 837c478bd9Sstevel@tonic-gate struct breq blks; /* used for off-line mode */ 847c478bd9Sstevel@tonic-gate } data; 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #define ir_inumber data.ino.inumber 887c478bd9Sstevel@tonic-gate #define ir_igen data.ino.igen 897c478bd9Sstevel@tonic-gate #define ir_offset data.ino.offset 907c478bd9Sstevel@tonic-gate #define ir_count data.ino.count 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define br_dblk data.blks.dblk 937c478bd9Sstevel@tonic-gate #define br_size data.blks.size 947c478bd9Sstevel@tonic-gate #define br_spcl data.blks.spclrec 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate static int reqsiz = 0; /* alloctape will initialize */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define SLAVES 3 997c478bd9Sstevel@tonic-gate struct slaves { 1007c478bd9Sstevel@tonic-gate int sl_slavefd; /* pipe from master to slave */ 1017c478bd9Sstevel@tonic-gate pid_t sl_slavepid; /* slave pid; used by killall() */ 1027c478bd9Sstevel@tonic-gate ino_t sl_inos; /* inos, if this record starts tape */ 1037c478bd9Sstevel@tonic-gate int sl_offset; /* logical blocks written for object */ 1047c478bd9Sstevel@tonic-gate int sl_count; /* logical blocks left in spclrec */ 1057c478bd9Sstevel@tonic-gate int sl_tapea; /* header number, if starting tape */ 1067c478bd9Sstevel@tonic-gate int sl_firstrec; /* number of first block on tape */ 1077c478bd9Sstevel@tonic-gate int sl_state; /* dump output state */ 1087c478bd9Sstevel@tonic-gate struct req *sl_req; /* instruction packet to slave */ 1097c478bd9Sstevel@tonic-gate }; 1107c478bd9Sstevel@tonic-gate static struct slaves slaves[SLAVES]; /* one per slave */ 1117c478bd9Sstevel@tonic-gate static struct slaves *slp; /* pointer to current slave */ 1127c478bd9Sstevel@tonic-gate static struct slaves chkpt; /* checkpointed data */ 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate struct bdesc { 1157c478bd9Sstevel@tonic-gate char *b_data; /* pointer to buffer data */ 1167c478bd9Sstevel@tonic-gate int b_flags; /* flags (see below) */ 1177c478bd9Sstevel@tonic-gate }; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * The following variables are in shared memory, and must be 1217c478bd9Sstevel@tonic-gate * explicitly checkpointed and/or reset. 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate static caddr_t shared; /* pointer to block of shared memory */ 1247c478bd9Sstevel@tonic-gate static struct bdesc *bufp; /* buffer descriptors */ 1257c478bd9Sstevel@tonic-gate static struct bdesc **current; /* output buffer to fill */ 1267c478bd9Sstevel@tonic-gate static int *tapea; /* logical record count */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate #ifdef INSTRUMENT 1297c478bd9Sstevel@tonic-gate static int *readmissp; /* number of times writer was idle */ 1307c478bd9Sstevel@tonic-gate static int *idle; /* number of times slaves were idle */ 1317c478bd9Sstevel@tonic-gate #endif /* INSTRUMENT */ 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Buffer flags 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate #define BUF_EMPTY 0x0 /* nothing in buffer */ 1377c478bd9Sstevel@tonic-gate #define BUF_FULL 0x1 /* data in buffer */ 1387c478bd9Sstevel@tonic-gate #define BUF_SPCLREC 0x2 /* contains special record */ 1397c478bd9Sstevel@tonic-gate #define BUF_ARCHIVE 0x4 /* dump to archive */ 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate static int recsout; /* number of req's sent to slaves */ 1427c478bd9Sstevel@tonic-gate static int totalrecsout; /* total number of req's sent to slaves */ 1437c478bd9Sstevel@tonic-gate static int rotor; /* next slave to be instructed */ 1447c478bd9Sstevel@tonic-gate static pid_t master; /* pid of master, for sending error signals */ 1457c478bd9Sstevel@tonic-gate static int writer = -1; /* fd of tape writer */ 1467c478bd9Sstevel@tonic-gate static pid_t writepid; /* pid of tape writer */ 1477c478bd9Sstevel@tonic-gate static int arch; /* fd of output archiver */ 1487c478bd9Sstevel@tonic-gate static pid_t archivepid; /* pid of output archiver */ 1497c478bd9Sstevel@tonic-gate static int archivefd; /* fd of archive file (proper) */ 1507c478bd9Sstevel@tonic-gate static offset_t lf_archoffset; /* checkpointed offset into archive file */ 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate int caught; /* caught signal -- imported by mapfile() */ 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #ifdef DEBUG 1557c478bd9Sstevel@tonic-gate extern int xflag; 1567c478bd9Sstevel@tonic-gate #endif 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #ifdef __STDC__ 1597c478bd9Sstevel@tonic-gate static void cmdwrterr(void); 1607c478bd9Sstevel@tonic-gate static void cmdrderr(void); 1617c478bd9Sstevel@tonic-gate static void freetape(void); 1627c478bd9Sstevel@tonic-gate static void bufclear(void); 1637c478bd9Sstevel@tonic-gate static pid_t setuparchive(void); 1647c478bd9Sstevel@tonic-gate static pid_t setupwriter(void); 1657c478bd9Sstevel@tonic-gate static void nextslave(void); 1667c478bd9Sstevel@tonic-gate static void tperror(int); 1677c478bd9Sstevel@tonic-gate static void rollforward(int); 1687c478bd9Sstevel@tonic-gate static void nap(int); 1697c478bd9Sstevel@tonic-gate static void alrm(int); 1707c478bd9Sstevel@tonic-gate static void just_rewind(void); 1717c478bd9Sstevel@tonic-gate static void killall(void); 1727c478bd9Sstevel@tonic-gate static void proceed(int); 1737c478bd9Sstevel@tonic-gate static void die(int); 1747c478bd9Sstevel@tonic-gate static void enslave(void); 1757c478bd9Sstevel@tonic-gate static void wait_our_turn(void); 1767c478bd9Sstevel@tonic-gate static void dumpoffline(int, pid_t, int); 1777c478bd9Sstevel@tonic-gate static void onxfsz(int); 1787c478bd9Sstevel@tonic-gate static void dowrite(int); 1797c478bd9Sstevel@tonic-gate static void checkpoint(struct bdesc *, int); 1807c478bd9Sstevel@tonic-gate static ssize_t atomic(int (*)(), int, char *, int); 1817c478bd9Sstevel@tonic-gate #else 1827c478bd9Sstevel@tonic-gate static void cmdwrterr(); 1837c478bd9Sstevel@tonic-gate static void cmdrderr(); 1847c478bd9Sstevel@tonic-gate static void freetape(); 1857c478bd9Sstevel@tonic-gate static void bufclear(); 1867c478bd9Sstevel@tonic-gate static pid_t setuparchive(); 1877c478bd9Sstevel@tonic-gate static pid_t setupwriter(); 1887c478bd9Sstevel@tonic-gate static void nextslave(); 1897c478bd9Sstevel@tonic-gate static void tperror(); 1907c478bd9Sstevel@tonic-gate static void rollforward(); 1917c478bd9Sstevel@tonic-gate static void nap(); 1927c478bd9Sstevel@tonic-gate static void alrm(); 1937c478bd9Sstevel@tonic-gate static void just_rewind(); 1947c478bd9Sstevel@tonic-gate static void killall(); 1957c478bd9Sstevel@tonic-gate static void proceed(); 1967c478bd9Sstevel@tonic-gate static void die(); 1977c478bd9Sstevel@tonic-gate static void enslave(); 1987c478bd9Sstevel@tonic-gate static void wait_our_turn(); 1997c478bd9Sstevel@tonic-gate static void dumpoffline(); 2007c478bd9Sstevel@tonic-gate static void onxfsz(); 2017c478bd9Sstevel@tonic-gate static void dowrite(); 2027c478bd9Sstevel@tonic-gate static void checkpoint(); 2037c478bd9Sstevel@tonic-gate static ssize_t atomic(); 2047c478bd9Sstevel@tonic-gate #endif 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate static size_t tapesize; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * Allocate buffers and shared memory variables. Tape buffers are 2107c478bd9Sstevel@tonic-gate * allocated on page boundaries for tape write() efficiency. 2117c478bd9Sstevel@tonic-gate */ 2127c478bd9Sstevel@tonic-gate void 2137c478bd9Sstevel@tonic-gate #ifdef __STDC__ 2147c478bd9Sstevel@tonic-gate #else 2157c478bd9Sstevel@tonic-gate #endif 2167c478bd9Sstevel@tonic-gate alloctape(void) 2177c478bd9Sstevel@tonic-gate { 2187c478bd9Sstevel@tonic-gate struct slaves *slavep; 2197c478bd9Sstevel@tonic-gate ulong_t pgoff = (unsigned)(getpagesize() - 1); /* 2**n - 1 */ 2207c478bd9Sstevel@tonic-gate int mapfd; 2217c478bd9Sstevel@tonic-gate char *obuf; 2227c478bd9Sstevel@tonic-gate int saverr; 2237c478bd9Sstevel@tonic-gate int i, j; 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate writesize = ntrec * tp_bsize; 2267c478bd9Sstevel@tonic-gate if (!printsize) 2277c478bd9Sstevel@tonic-gate msg(gettext("Writing %d Kilobyte records\n"), 2287c478bd9Sstevel@tonic-gate writesize / TP_BSIZE_MIN); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * set up shared memory seg for here and child 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate mapfd = open("/dev/zero", O_RDWR); 2347c478bd9Sstevel@tonic-gate if (mapfd == -1) { 2357c478bd9Sstevel@tonic-gate saverr = errno; 2367c478bd9Sstevel@tonic-gate msg(gettext("Cannot open `%s': %s\n"), 2377c478bd9Sstevel@tonic-gate "/dev/zero", strerror(saverr)); 2387c478bd9Sstevel@tonic-gate dumpabort(); 2397c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * Allocate space such that buffers are page-aligned and 2437c478bd9Sstevel@tonic-gate * pointers are aligned on 4-byte boundaries (for SPARC). 2447c478bd9Sstevel@tonic-gate * This code assumes that (NBUF * writesize) is a multiple 2457c478bd9Sstevel@tonic-gate * of the page size and that pages are aligned on 4-byte 2467c478bd9Sstevel@tonic-gate * boundaries. Space is allocated as follows: 2477c478bd9Sstevel@tonic-gate * 2487c478bd9Sstevel@tonic-gate * (NBUF * writesize) for the actual buffers 2497c478bd9Sstevel@tonic-gate * (pagesize - 1) for padding so the buffers are page-aligned 2507c478bd9Sstevel@tonic-gate * (NBUF * ntrec * sizeof (struct bdesc)) for each buffer 2517c478bd9Sstevel@tonic-gate * (n * sizeof (int)) for [n] debugging variables/pointers 2527c478bd9Sstevel@tonic-gate * (n * sizeof (int)) for [n] miscellaneous variables/pointers 2537c478bd9Sstevel@tonic-gate */ 2547c478bd9Sstevel@tonic-gate tapesize = 2557c478bd9Sstevel@tonic-gate (NBUF * writesize) /* output buffers */ 2567c478bd9Sstevel@tonic-gate /* LINTED: pgoff fits into a size_t */ 2577c478bd9Sstevel@tonic-gate + (size_t)pgoff /* page alignment */ 2587c478bd9Sstevel@tonic-gate /* buffer descriptors */ 2597c478bd9Sstevel@tonic-gate + (((size_t)sizeof (struct bdesc)) * NBUF * ntrec) 2607c478bd9Sstevel@tonic-gate #ifdef INSTRUMENT 2617c478bd9Sstevel@tonic-gate + (2 * (size_t)sizeof (int *)) /* instrumentation */ 2627c478bd9Sstevel@tonic-gate #endif 2637c478bd9Sstevel@tonic-gate /* shared variables */ 2647c478bd9Sstevel@tonic-gate + (size_t)sizeof (struct bdesc **) 2657c478bd9Sstevel@tonic-gate + (size_t)sizeof (int *) 2667c478bd9Sstevel@tonic-gate + (3 * (size_t)sizeof (time_t)); 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate shared = mmap((char *)0, tapesize, PROT_READ|PROT_WRITE, 2697c478bd9Sstevel@tonic-gate MAP_SHARED, mapfd, (off_t)0); 2707c478bd9Sstevel@tonic-gate if (shared == (caddr_t)-1) { 2717c478bd9Sstevel@tonic-gate saverr = errno; 2727c478bd9Sstevel@tonic-gate msg(gettext("Cannot memory map output buffers: %s\n"), 2737c478bd9Sstevel@tonic-gate strerror(saverr)); 2747c478bd9Sstevel@tonic-gate dumpabort(); 2757c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate (void) close(mapfd); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate /* 2807c478bd9Sstevel@tonic-gate * Buffers and buffer headers 2817c478bd9Sstevel@tonic-gate */ 2827c478bd9Sstevel@tonic-gate obuf = (char *)(((ulong_t)shared + pgoff) & ~pgoff); 2837c478bd9Sstevel@tonic-gate /* LINTED obuf and writesize are aligned */ 2847c478bd9Sstevel@tonic-gate bufp = (struct bdesc *)(obuf + NBUF*writesize); 2857c478bd9Sstevel@tonic-gate /* 2867c478bd9Sstevel@tonic-gate * Shared memory variables 2877c478bd9Sstevel@tonic-gate */ 2887c478bd9Sstevel@tonic-gate current = (struct bdesc **)&bufp[NBUF*ntrec]; 2897c478bd9Sstevel@tonic-gate tapea = (int *)(current + 1); 2907c478bd9Sstevel@tonic-gate /* LINTED pointer alignment ok */ 2917c478bd9Sstevel@tonic-gate telapsed = (time_t *)(tapea + 1); 2927c478bd9Sstevel@tonic-gate tstart_writing = telapsed + 1; 2937c478bd9Sstevel@tonic-gate tschedule = tstart_writing + 1; 2947c478bd9Sstevel@tonic-gate #ifdef INSTRUMENT 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * Debugging and instrumentation variables 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate readmissp = (int *)(tschedule + 1); 2997c478bd9Sstevel@tonic-gate idle = readmissp + 1; 3007c478bd9Sstevel@tonic-gate #endif 3017c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < NBUF * ntrec; i++, j += tp_bsize) { 3027c478bd9Sstevel@tonic-gate bufp[i].b_data = &obuf[j]; 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate reqsiz = sizeof (struct req) + tp_bsize - sizeof (long); 3067c478bd9Sstevel@tonic-gate for (slavep = slaves; slavep < &slaves[SLAVES]; slavep++) 3077c478bd9Sstevel@tonic-gate slavep->sl_req = (struct req *)xmalloc(reqsiz); 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate chkpt.sl_offset = 0; /* start at offset 0 */ 3107c478bd9Sstevel@tonic-gate chkpt.sl_count = 0; 3117c478bd9Sstevel@tonic-gate chkpt.sl_inos = UFSROOTINO; /* in root inode */ 3127c478bd9Sstevel@tonic-gate chkpt.sl_firstrec = 1; 3137c478bd9Sstevel@tonic-gate chkpt.sl_tapea = 0; 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate static void 3177c478bd9Sstevel@tonic-gate #ifdef __STDC__ 3187c478bd9Sstevel@tonic-gate freetape(void) 3197c478bd9Sstevel@tonic-gate #else 3207c478bd9Sstevel@tonic-gate freetape() 3217c478bd9Sstevel@tonic-gate #endif 3227c478bd9Sstevel@tonic-gate { 3237c478bd9Sstevel@tonic-gate if (shared == NULL) 3247c478bd9Sstevel@tonic-gate return; 3257c478bd9Sstevel@tonic-gate (void) timeclock((time_t)0); 3267c478bd9Sstevel@tonic-gate (void) munmap(shared, tapesize); 3277c478bd9Sstevel@tonic-gate shared = NULL; 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /* 3317c478bd9Sstevel@tonic-gate * Reset tape state variables -- called 3327c478bd9Sstevel@tonic-gate * before a pass to dump active files. 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate void 3357c478bd9Sstevel@tonic-gate #ifdef __STDC__ 3367c478bd9Sstevel@tonic-gate reset(void) 3377c478bd9Sstevel@tonic-gate #else 3387c478bd9Sstevel@tonic-gate reset() 3397c478bd9Sstevel@tonic-gate #endif 3407c478bd9Sstevel@tonic-gate { 3417c478bd9Sstevel@tonic-gate bufclear(); 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate #ifdef INSTRUMENT 3447c478bd9Sstevel@tonic-gate (*readmissp) = 0; 3457c478bd9Sstevel@tonic-gate (*idle) = 0; 3467c478bd9Sstevel@tonic-gate #endif 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate spcl.c_flags = 0; 3497c478bd9Sstevel@tonic-gate spcl.c_volume = 0; 3507c478bd9Sstevel@tonic-gate tapeno = 0; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate chkpt.sl_offset = 0; /* start at offset 0 */ 3537c478bd9Sstevel@tonic-gate chkpt.sl_count = 0; 3547c478bd9Sstevel@tonic-gate chkpt.sl_inos = UFSROOTINO; /* in root inode */ 3557c478bd9Sstevel@tonic-gate chkpt.sl_firstrec = 1; 3567c478bd9Sstevel@tonic-gate chkpt.sl_tapea = 0; 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate static void 3607c478bd9Sstevel@tonic-gate #ifdef __STDC__ 3617c478bd9Sstevel@tonic-gate bufclear(void) 3627c478bd9Sstevel@tonic-gate #else 3637c478bd9Sstevel@tonic-gate bufclear() 3647c478bd9Sstevel@tonic-gate #endif 3657c478bd9Sstevel@tonic-gate { 3667c478bd9Sstevel@tonic-gate struct bdesc *bp; 3677c478bd9Sstevel@tonic-gate int i; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate for (i = 0, bp = bufp; i < NBUF * ntrec; i++, bp++) 3707c478bd9Sstevel@tonic-gate bp->b_flags = BUF_EMPTY; 3717c478bd9Sstevel@tonic-gate if ((caddr_t)current < shared || 3727c478bd9Sstevel@tonic-gate (caddr_t)current > (shared + tapesize)) { 3737c478bd9Sstevel@tonic-gate msg(gettext( 3747c478bd9Sstevel@tonic-gate "bufclear: current pointer out of range of shared memory\n")); 3757c478bd9Sstevel@tonic-gate dumpabort(); 3767c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate if ((*current != NULL) && 3797c478bd9Sstevel@tonic-gate (*current < &bufp[0] || *current > &bufp[NBUF*ntrec])) { 3807c478bd9Sstevel@tonic-gate /* ANSI string catenation, to shut cstyle up */ 3817c478bd9Sstevel@tonic-gate msg(gettext("bufclear: current buffer pointer (0x%x) " 3827c478bd9Sstevel@tonic-gate "out of range of buffer\naddresses (0x%x - 0x%x)\n"), 3837c478bd9Sstevel@tonic-gate *current, &bufp[0], &bufp[NBUF*ntrec]); 3847c478bd9Sstevel@tonic-gate dumpabort(); 3857c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate *current = bufp; 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate /* 3917c478bd9Sstevel@tonic-gate * Start a process to collect information describing the dump. 3927c478bd9Sstevel@tonic-gate * This data takes two forms: 3937c478bd9Sstevel@tonic-gate * the bitmap and directory information being written to 3947c478bd9Sstevel@tonic-gate * the front of the tape (the "archive" file) 3957c478bd9Sstevel@tonic-gate * information describing each directory and inode (to 3967c478bd9Sstevel@tonic-gate * be included in the database tmp file) 3977c478bd9Sstevel@tonic-gate * Write the data to the files as it is received so huge file 3987c478bd9Sstevel@tonic-gate * systems don't cause dump to consume large amounts of memory. 3997c478bd9Sstevel@tonic-gate */ 4007c478bd9Sstevel@tonic-gate static pid_t 4017c478bd9Sstevel@tonic-gate setuparchive(void) 4027c478bd9Sstevel@tonic-gate { 4037c478bd9Sstevel@tonic-gate struct slaves *slavep; 4047c478bd9Sstevel@tonic-gate int cmd[2]; 4057c478bd9Sstevel@tonic-gate pid_t pid; 4067c478bd9Sstevel@tonic-gate ssize_t size; 4077c478bd9Sstevel@tonic-gate char *data; 4087c478bd9Sstevel@tonic-gate char *errmsg; 4097c478bd9Sstevel@tonic-gate int flags, saverr; 4107c478bd9Sstevel@tonic-gate int punt = 0; 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate /* 4137c478bd9Sstevel@tonic-gate * Both the archive and database tmp files are 4147c478bd9Sstevel@tonic-gate * checkpointed by taking their current offsets 4157c478bd9Sstevel@tonic-gate * (sizes) after completing each volume. Restoring 4167c478bd9Sstevel@tonic-gate * from a checkpoint involves truncating to the 4177c478bd9Sstevel@tonic-gate * checkpointed size. 4187c478bd9Sstevel@tonic-gate */ 4197c478bd9Sstevel@tonic-gate if (archive && !doingactive) { 4207c478bd9Sstevel@tonic-gate /* It's allowed/expected to exist, so can't use O_EXCL */ 4217c478bd9Sstevel@tonic-gate archivefd = safe_file_open(archivefile, O_WRONLY, 0600); 4227c478bd9Sstevel@tonic-gate if (archivefd < 0) { 4237c478bd9Sstevel@tonic-gate saverr = errno; 4247c478bd9Sstevel@tonic-gate msg(gettext("Cannot open archive file `%s': %s\n"), 4257c478bd9Sstevel@tonic-gate archivefile, strerror(saverr)); 4267c478bd9Sstevel@tonic-gate dumpabort(); 4277c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate if (lseek64(archivefd, lf_archoffset, 0) < 0) { 4317c478bd9Sstevel@tonic-gate saverr = errno; 4327c478bd9Sstevel@tonic-gate msg(gettext( 4337c478bd9Sstevel@tonic-gate "Cannot position archive file `%s' : %s\n"), 4347c478bd9Sstevel@tonic-gate archivefile, strerror(saverr)); 4357c478bd9Sstevel@tonic-gate dumpabort(); 4367c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate if (ftruncate64(archivefd, lf_archoffset) < 0) { 4397c478bd9Sstevel@tonic-gate saverr = errno; 4407c478bd9Sstevel@tonic-gate msg(gettext( 4417c478bd9Sstevel@tonic-gate "Cannot truncate archive file `%s' : %s\n"), 4427c478bd9Sstevel@tonic-gate archivefile, strerror(saverr)); 4437c478bd9Sstevel@tonic-gate dumpabort(); 4447c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate if (pipe(cmd) < 0) { 4497c478bd9Sstevel@tonic-gate saverr = errno; 4507c478bd9Sstevel@tonic-gate msg(gettext("%s: %s error: %s\n"), 4517c478bd9Sstevel@tonic-gate "setuparchive", "pipe", strerror(saverr)); 4527c478bd9Sstevel@tonic-gate return (0); 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate sighold(SIGINT); 4557c478bd9Sstevel@tonic-gate if ((pid = fork()) < 0) { 4567c478bd9Sstevel@tonic-gate saverr = errno; 4577c478bd9Sstevel@tonic-gate msg(gettext("%s: %s error: %s\n"), 4587c478bd9Sstevel@tonic-gate "setuparchive", "fork", strerror(saverr)); 4597c478bd9Sstevel@tonic-gate return (0); 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate if (pid > 0) { 4627c478bd9Sstevel@tonic-gate sigrelse(SIGINT); 4637c478bd9Sstevel@tonic-gate /* parent process */ 4647c478bd9Sstevel@tonic-gate (void) close(cmd[0]); 4657c478bd9Sstevel@tonic-gate arch = cmd[1]; 4667c478bd9Sstevel@tonic-gate return (pid); 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate /* 4697c478bd9Sstevel@tonic-gate * child process 4707c478bd9Sstevel@tonic-gate */ 4717c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); /* master handles this */ 4727c478bd9Sstevel@tonic-gate #ifdef TDEBUG 4737c478bd9Sstevel@tonic-gate (void) sleep(4); /* allow time for parent's message to get out */ 4747c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 4757c478bd9Sstevel@tonic-gate msg(gettext("Archiver has pid = %ld\n"), (long)getpid()); 4767c478bd9Sstevel@tonic-gate #endif 4777c478bd9Sstevel@tonic-gate freeino(); /* release unneeded resources */ 4787c478bd9Sstevel@tonic-gate freetape(); 4797c478bd9Sstevel@tonic-gate for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) { 4807c478bd9Sstevel@tonic-gate if (slavep->sl_slavefd != -1) { 4817c478bd9Sstevel@tonic-gate (void) close(slavep->sl_slavefd); 4827c478bd9Sstevel@tonic-gate slavep->sl_slavefd = -1; 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate (void) close(to); 4867c478bd9Sstevel@tonic-gate (void) close(fi); 4877c478bd9Sstevel@tonic-gate to = fi = -1; 4887c478bd9Sstevel@tonic-gate (void) close(cmd[1]); 4897c478bd9Sstevel@tonic-gate data = xmalloc(tp_bsize); 4907c478bd9Sstevel@tonic-gate for (;;) { 4917c478bd9Sstevel@tonic-gate size = atomic((int(*)())read, cmd[0], (char *)&flags, 4927c478bd9Sstevel@tonic-gate sizeof (flags)); 4937c478bd9Sstevel@tonic-gate if ((unsigned)size != sizeof (flags)) 4947c478bd9Sstevel@tonic-gate break; 4957c478bd9Sstevel@tonic-gate size = atomic((int(*)())read, cmd[0], data, tp_bsize); 4967c478bd9Sstevel@tonic-gate if (size == tp_bsize) { 4977c478bd9Sstevel@tonic-gate if (archive && flags & BUF_ARCHIVE && !punt && 4987c478bd9Sstevel@tonic-gate (size = write(archivefd, data, tp_bsize)) 4997c478bd9Sstevel@tonic-gate != tp_bsize) { 5007c478bd9Sstevel@tonic-gate struct stat64 stats; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate if (size != -1) { 5037c478bd9Sstevel@tonic-gate errmsg = strdup(gettext( 5047c478bd9Sstevel@tonic-gate "Output truncated")); 5057c478bd9Sstevel@tonic-gate if (errmsg == NULL) 5067c478bd9Sstevel@tonic-gate errmsg = ""; 5077c478bd9Sstevel@tonic-gate } else { 5087c478bd9Sstevel@tonic-gate errmsg = strerror(errno); 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate if (fstat64(archivefd, &stats) < 0) 5127c478bd9Sstevel@tonic-gate stats.st_size = -1; 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate /* cast to keep lint&printf happy */ 5157c478bd9Sstevel@tonic-gate msg(gettext( 5167c478bd9Sstevel@tonic-gate "Cannot write archive file `%s' at offset %lld: %s\n"), 5177c478bd9Sstevel@tonic-gate archivefile, (longlong_t)stats.st_size, 5187c478bd9Sstevel@tonic-gate errmsg); 5197c478bd9Sstevel@tonic-gate msg(gettext( 5207c478bd9Sstevel@tonic-gate "Archive file will be deleted, dump will continue\n")); 5217c478bd9Sstevel@tonic-gate punt++; 5227c478bd9Sstevel@tonic-gate if ((size != -1) && (*errmsg != '\0')) { 5237c478bd9Sstevel@tonic-gate free(errmsg); 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate } else { 5277c478bd9Sstevel@tonic-gate break; 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate (void) close(cmd[0]); 5317c478bd9Sstevel@tonic-gate if (archive) { 5327c478bd9Sstevel@tonic-gate (void) close(archivefd); 5337c478bd9Sstevel@tonic-gate archivefd = -1; 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate if (punt) { 5367c478bd9Sstevel@tonic-gate (void) unlink(archivefile); 5377c478bd9Sstevel@tonic-gate Exit(X_ABORT); 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate Exit(X_FINOK); 5407c478bd9Sstevel@tonic-gate /* NOTREACHED */ 541*fe0e7ec4Smaheshvs return (0); 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate /* 5457c478bd9Sstevel@tonic-gate * Start a process to read the output buffers and write the data 5467c478bd9Sstevel@tonic-gate * to the output device. 5477c478bd9Sstevel@tonic-gate */ 5487c478bd9Sstevel@tonic-gate static pid_t 5497c478bd9Sstevel@tonic-gate setupwriter(void) 5507c478bd9Sstevel@tonic-gate { 5517c478bd9Sstevel@tonic-gate struct slaves *slavep; 5527c478bd9Sstevel@tonic-gate int cmd[2]; 5537c478bd9Sstevel@tonic-gate pid_t pid; 5547c478bd9Sstevel@tonic-gate int saverr; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate caught = 0; 5577c478bd9Sstevel@tonic-gate if (pipe(cmd) < 0) { 5587c478bd9Sstevel@tonic-gate saverr = errno; 5597c478bd9Sstevel@tonic-gate msg(gettext("%s: %s error: %s\n"), 5607c478bd9Sstevel@tonic-gate "setupwriter", "pipe", strerror(saverr)); 5617c478bd9Sstevel@tonic-gate return (0); 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate sighold(SIGINT); 5647c478bd9Sstevel@tonic-gate if ((pid = fork()) < 0) { 5657c478bd9Sstevel@tonic-gate saverr = errno; 5667c478bd9Sstevel@tonic-gate msg(gettext("%s: %s error: %s\n"), 5677c478bd9Sstevel@tonic-gate "setupwriter", "fork", strerror(saverr)); 5687c478bd9Sstevel@tonic-gate return (0); 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate if (pid > 0) { 5717c478bd9Sstevel@tonic-gate /* 5727c478bd9Sstevel@tonic-gate * Parent process 5737c478bd9Sstevel@tonic-gate */ 5747c478bd9Sstevel@tonic-gate sigrelse(SIGINT); 5757c478bd9Sstevel@tonic-gate (void) close(cmd[0]); 5767c478bd9Sstevel@tonic-gate writer = cmd[1]; 5777c478bd9Sstevel@tonic-gate return (pid); 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate /* 5807c478bd9Sstevel@tonic-gate * Child (writer) process 5817c478bd9Sstevel@tonic-gate */ 5827c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); /* master handles this */ 5837c478bd9Sstevel@tonic-gate #ifdef TDEBUG 5847c478bd9Sstevel@tonic-gate (void) sleep(4); /* allow time for parent's message to get out */ 5857c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 5867c478bd9Sstevel@tonic-gate msg(gettext("Writer has pid = %ld\n"), (long)getpid()); 5877c478bd9Sstevel@tonic-gate #endif 5887c478bd9Sstevel@tonic-gate child_chdir(); 5897c478bd9Sstevel@tonic-gate freeino(); /* release unneeded resources */ 5907c478bd9Sstevel@tonic-gate for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) { 5917c478bd9Sstevel@tonic-gate if (slavep->sl_slavefd != -1) { 5927c478bd9Sstevel@tonic-gate (void) close(slavep->sl_slavefd); 5937c478bd9Sstevel@tonic-gate slavep->sl_slavefd = -1; 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate (void) close(fi); 5977c478bd9Sstevel@tonic-gate fi = -1; 5987c478bd9Sstevel@tonic-gate (void) close(cmd[1]); 5997c478bd9Sstevel@tonic-gate dowrite(cmd[0]); 6007c478bd9Sstevel@tonic-gate if (arch >= 0) { 6017c478bd9Sstevel@tonic-gate (void) close(arch); 6027c478bd9Sstevel@tonic-gate arch = -1; 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate (void) close(cmd[0]); 6057c478bd9Sstevel@tonic-gate Exit(X_FINOK); 6067c478bd9Sstevel@tonic-gate /* NOTREACHED */ 607*fe0e7ec4Smaheshvs return (0); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate void 6117c478bd9Sstevel@tonic-gate #ifdef __STDC__ 6127c478bd9Sstevel@tonic-gate spclrec(void) 6137c478bd9Sstevel@tonic-gate #else 6147c478bd9Sstevel@tonic-gate spclrec() 6157c478bd9Sstevel@tonic-gate #endif 6167c478bd9Sstevel@tonic-gate { 6177c478bd9Sstevel@tonic-gate int s, i; 6187c478bd9Sstevel@tonic-gate int32_t *ip; 6197c478bd9Sstevel@tonic-gate int flags = BUF_SPCLREC; 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate if ((BIT(ino, shamap)) && (spcl.c_type == TS_INODE)) { 6227c478bd9Sstevel@tonic-gate spcl.c_type = TS_ADDR; 6237c478bd9Sstevel@tonic-gate /* LINTED: result fits in a short */ 6247c478bd9Sstevel@tonic-gate spcl.c_dinode.di_mode &= ~S_IFMT; 6257c478bd9Sstevel@tonic-gate /* LINTED: result fits in a short */ 6267c478bd9Sstevel@tonic-gate spcl.c_dinode.di_mode |= IFSHAD; 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate /* 6307c478bd9Sstevel@tonic-gate * Only TS_INODEs should have short metadata, if this 6317c478bd9Sstevel@tonic-gate * isn't such a spclrec, clear the metadata flag and 6327c478bd9Sstevel@tonic-gate * the c_shadow contents. 6337c478bd9Sstevel@tonic-gate */ 6347c478bd9Sstevel@tonic-gate if (!(spcl.c_type == TS_INODE && (spcl.c_flags & DR_HASMETA))) { 6357c478bd9Sstevel@tonic-gate spcl.c_flags &= ~DR_HASMETA; 6367c478bd9Sstevel@tonic-gate bcopy(c_shadow_save, &(spcl.c_shadow), 6377c478bd9Sstevel@tonic-gate sizeof (spcl.c_shadow)); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate if (spcl.c_type == TS_END) { 6417c478bd9Sstevel@tonic-gate spcl.c_count = 1; 6427c478bd9Sstevel@tonic-gate spcl.c_flags |= DR_INODEINFO; 6437c478bd9Sstevel@tonic-gate bcopy((char *)inos, (char *)spcl.c_inos, sizeof (inos)); 6447c478bd9Sstevel@tonic-gate } else if (spcl.c_type == TS_TAPE) { 6457c478bd9Sstevel@tonic-gate spcl.c_flags |= DR_NEWHEADER; 6467c478bd9Sstevel@tonic-gate if (doingactive) 6477c478bd9Sstevel@tonic-gate spcl.c_flags |= DR_REDUMP; 6487c478bd9Sstevel@tonic-gate } else if (spcl.c_type != TS_INODE) 6497c478bd9Sstevel@tonic-gate flags = BUF_SPCLREC; 6507c478bd9Sstevel@tonic-gate spcl.c_tapea = *tapea; 6517c478bd9Sstevel@tonic-gate /* LINTED for now, max inode # is 2**31 (ufs max size is 4TB) */ 6527c478bd9Sstevel@tonic-gate spcl.c_inumber = (ino32_t)ino; 6537c478bd9Sstevel@tonic-gate spcl.c_magic = (tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC; 6547c478bd9Sstevel@tonic-gate spcl.c_checksum = 0; 6557c478bd9Sstevel@tonic-gate ip = (int32_t *)&spcl; 6567c478bd9Sstevel@tonic-gate s = CHECKSUM; 6577c478bd9Sstevel@tonic-gate assert((tp_bsize % sizeof (*ip)) == 0); 6587c478bd9Sstevel@tonic-gate i = tp_bsize / sizeof (*ip); 6597c478bd9Sstevel@tonic-gate assert((i%8) == 0); 6607c478bd9Sstevel@tonic-gate i /= 8; 6617c478bd9Sstevel@tonic-gate do { 6627c478bd9Sstevel@tonic-gate s -= *ip++; s -= *ip++; s -= *ip++; s -= *ip++; 6637c478bd9Sstevel@tonic-gate s -= *ip++; s -= *ip++; s -= *ip++; s -= *ip++; 6647c478bd9Sstevel@tonic-gate } while (--i > 0); 6657c478bd9Sstevel@tonic-gate spcl.c_checksum = s; 6667c478bd9Sstevel@tonic-gate taprec((uchar_t *)&spcl, flags, sizeof (spcl)); 6677c478bd9Sstevel@tonic-gate if (spcl.c_type == TS_END) 6687c478bd9Sstevel@tonic-gate spcl.c_flags &= ~DR_INODEINFO; 6697c478bd9Sstevel@tonic-gate else if (spcl.c_type == TS_TAPE) 6707c478bd9Sstevel@tonic-gate spcl.c_flags &= ~(DR_NEWHEADER|DR_REDUMP|DR_TRUEINC); 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate /* 6747c478bd9Sstevel@tonic-gate * Fill appropriate buffer 6757c478bd9Sstevel@tonic-gate */ 6767c478bd9Sstevel@tonic-gate void 677*fe0e7ec4Smaheshvs taprec(uchar_t *dp, int flags, int size) 6787c478bd9Sstevel@tonic-gate { 6797c478bd9Sstevel@tonic-gate if (size > tp_bsize) { 6807c478bd9Sstevel@tonic-gate msg(gettext( 6817c478bd9Sstevel@tonic-gate "taprec: Unexpected buffer size, expected %d, got %d.\n"), 6827c478bd9Sstevel@tonic-gate tp_bsize, size); 6837c478bd9Sstevel@tonic-gate dumpabort(); 6847c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate while ((*current)->b_flags & BUF_FULL) 6887c478bd9Sstevel@tonic-gate nap(10); 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate bcopy(dp, (*current)->b_data, (size_t)size); 6917c478bd9Sstevel@tonic-gate if (size < tp_bsize) { 6927c478bd9Sstevel@tonic-gate bzero((*current)->b_data + size, tp_bsize - size); 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate if (dumptoarchive) 6967c478bd9Sstevel@tonic-gate flags |= BUF_ARCHIVE; 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate /* no locking as we assume only one reader and one writer active */ 6997c478bd9Sstevel@tonic-gate (*current)->b_flags = (flags | BUF_FULL); 7007c478bd9Sstevel@tonic-gate if (++*current >= &bufp[NBUF*ntrec]) 7017c478bd9Sstevel@tonic-gate (*current) = &bufp[0]; 7027c478bd9Sstevel@tonic-gate (*tapea)++; 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate void 706*fe0e7ec4Smaheshvs dmpblk(daddr32_t blkno, size_t size, off_t offset) 7077c478bd9Sstevel@tonic-gate { 7087c478bd9Sstevel@tonic-gate diskaddr_t dblkno; 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate assert((offset >> DEV_BSHIFT) <= INT32_MAX); 7117c478bd9Sstevel@tonic-gate dblkno = fsbtodb(sblock, blkno) + (offset >> DEV_BSHIFT); 7127c478bd9Sstevel@tonic-gate size = (size + DEV_BSIZE-1) & ~(DEV_BSIZE-1); 7137c478bd9Sstevel@tonic-gate slp->sl_req->br_dblk = dblkno; 7147c478bd9Sstevel@tonic-gate slp->sl_req->br_size = size; 7157c478bd9Sstevel@tonic-gate if (dumptoarchive) { 7167c478bd9Sstevel@tonic-gate /* LINTED: result fits in a short */ 7177c478bd9Sstevel@tonic-gate slp->sl_req->aflag |= BUF_ARCHIVE; 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate toslave((void(*)())0, ino); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7237c478bd9Sstevel@tonic-gate static void 724*fe0e7ec4Smaheshvs tperror(int sig) 7257c478bd9Sstevel@tonic-gate { 7267c478bd9Sstevel@tonic-gate char buf[3000]; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if (pipeout) { 7297c478bd9Sstevel@tonic-gate msg(gettext("Write error on %s\n"), tape); 7307c478bd9Sstevel@tonic-gate msg(gettext("Cannot recover\n")); 7317c478bd9Sstevel@tonic-gate dumpabort(); 7327c478bd9Sstevel@tonic-gate /* NOTREACHED */ 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate if (!doingverify) { 7357c478bd9Sstevel@tonic-gate broadcast(gettext("WRITE ERROR!\n")); 7367c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 7377c478bd9Sstevel@tonic-gate gettext("Do you want to restart?: (\"yes\" or \"no\") ")); 7387c478bd9Sstevel@tonic-gate if (!query(buf)) { 7397c478bd9Sstevel@tonic-gate dumpabort(); 7407c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate if (tapeout && (isrewind(to) || offline)) { 7437c478bd9Sstevel@tonic-gate /* ANSI string catenation, to shut cstyle up */ 7447c478bd9Sstevel@tonic-gate msg(gettext("This tape will rewind. After " 7457c478bd9Sstevel@tonic-gate "it is rewound,\nreplace the faulty tape " 7467c478bd9Sstevel@tonic-gate "with a new one;\nthis dump volume will " 7477c478bd9Sstevel@tonic-gate "be rewritten.\n")); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate } else { 7507c478bd9Sstevel@tonic-gate broadcast(gettext("TAPE VERIFICATION ERROR!\n")); 7517c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), gettext( 7527c478bd9Sstevel@tonic-gate "Do you want to rewrite?: (\"yes\" or \"no\") ")); 7537c478bd9Sstevel@tonic-gate if (!query(buf)) { 7547c478bd9Sstevel@tonic-gate dumpabort(); 7557c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate msg(gettext( 7587c478bd9Sstevel@tonic-gate "This tape will be rewritten and then verified\n")); 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate killall(); 7617c478bd9Sstevel@tonic-gate trewind(); 7627c478bd9Sstevel@tonic-gate Exit(X_REWRITE); 7637c478bd9Sstevel@tonic-gate } 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate /* 7667c478bd9Sstevel@tonic-gate * Called by master from pass() to send a request to dump files/blocks 7677c478bd9Sstevel@tonic-gate * to one of the slaves. Slaves return whether the file was active 7687c478bd9Sstevel@tonic-gate * when it was being dumped. The tape writer process sends checkpoint 7697c478bd9Sstevel@tonic-gate * info when it completes a volume. 7707c478bd9Sstevel@tonic-gate */ 7717c478bd9Sstevel@tonic-gate void 772*fe0e7ec4Smaheshvs toslave(void (*fn)(), ino_t inumber) 7737c478bd9Sstevel@tonic-gate { 7747c478bd9Sstevel@tonic-gate int wasactive; 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate if (recsout >= SLAVES) { 7777c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())read, slp->sl_slavefd, 7787c478bd9Sstevel@tonic-gate (char *)&wasactive, sizeof (wasactive)) != 7797c478bd9Sstevel@tonic-gate sizeof (wasactive)) { 7807c478bd9Sstevel@tonic-gate cmdrderr(); 7817c478bd9Sstevel@tonic-gate dumpabort(); 7827c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate if (wasactive) { 7857c478bd9Sstevel@tonic-gate active++; 7867c478bd9Sstevel@tonic-gate msg(gettext( 7877c478bd9Sstevel@tonic-gate "The file at inode `%lu' was active and will be recopied\n"), 7887c478bd9Sstevel@tonic-gate slp->sl_req->ir_inumber); 7897c478bd9Sstevel@tonic-gate /* LINTED: 32-bit to 8-bit assignment ok */ 7907c478bd9Sstevel@tonic-gate BIS(slp->sl_req->ir_inumber, activemap); 7917c478bd9Sstevel@tonic-gate } 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate slp->sl_req->aflag = 0; 7947c478bd9Sstevel@tonic-gate if (dumptoarchive) { 7957c478bd9Sstevel@tonic-gate /* LINTED: result fits in a short */ 7967c478bd9Sstevel@tonic-gate slp->sl_req->aflag |= BUF_ARCHIVE; 7977c478bd9Sstevel@tonic-gate } 7987c478bd9Sstevel@tonic-gate if (fn) 7997c478bd9Sstevel@tonic-gate (*fn)(inumber); 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate if (atomic((int(*)())write, slp->sl_slavefd, (char *)slp->sl_req, 8027c478bd9Sstevel@tonic-gate reqsiz) != reqsiz) { 8037c478bd9Sstevel@tonic-gate cmdwrterr(); 8047c478bd9Sstevel@tonic-gate dumpabort(); 8057c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate ++recsout; 8087c478bd9Sstevel@tonic-gate nextslave(); 8097c478bd9Sstevel@tonic-gate } 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate void 812*fe0e7ec4Smaheshvs dospcl(ino_t inumber) 8137c478bd9Sstevel@tonic-gate { 8147c478bd9Sstevel@tonic-gate /* LINTED for now, max inode # is 2**31 (ufs max size is 1TB) */ 8157c478bd9Sstevel@tonic-gate spcl.c_inumber = (ino32_t)inumber; 8167c478bd9Sstevel@tonic-gate slp->sl_req->br_dblk = 0; 8177c478bd9Sstevel@tonic-gate bcopy((char *)&spcl, (char *)slp->sl_req->br_spcl, tp_bsize); 8187c478bd9Sstevel@tonic-gate } 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate static void 8217c478bd9Sstevel@tonic-gate #ifdef __STDC__ 8227c478bd9Sstevel@tonic-gate nextslave(void) 8237c478bd9Sstevel@tonic-gate #else 8247c478bd9Sstevel@tonic-gate nextslave() 8257c478bd9Sstevel@tonic-gate #endif 8267c478bd9Sstevel@tonic-gate { 8277c478bd9Sstevel@tonic-gate if (++rotor >= SLAVES) { 8287c478bd9Sstevel@tonic-gate rotor = 0; 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate slp = &slaves[rotor]; 8317c478bd9Sstevel@tonic-gate } 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate void 8347c478bd9Sstevel@tonic-gate #ifdef __STDC__ 8357c478bd9Sstevel@tonic-gate flushcmds(void) 8367c478bd9Sstevel@tonic-gate #else 8377c478bd9Sstevel@tonic-gate flushcmds() 8387c478bd9Sstevel@tonic-gate #endif 8397c478bd9Sstevel@tonic-gate { 8407c478bd9Sstevel@tonic-gate int i; 8417c478bd9Sstevel@tonic-gate int wasactive; 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * Retrieve all slave status 8457c478bd9Sstevel@tonic-gate */ 8467c478bd9Sstevel@tonic-gate if (recsout < SLAVES) { 8477c478bd9Sstevel@tonic-gate slp = slaves; 8487c478bd9Sstevel@tonic-gate rotor = 0; 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate for (i = 0; i < (recsout < SLAVES ? recsout : SLAVES); i++) { 8517c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())read, slp->sl_slavefd, 8527c478bd9Sstevel@tonic-gate (char *)&wasactive, sizeof (wasactive)) != 8537c478bd9Sstevel@tonic-gate sizeof (wasactive)) { 8547c478bd9Sstevel@tonic-gate cmdrderr(); 8557c478bd9Sstevel@tonic-gate dumpabort(); 8567c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate if (wasactive) { 8597c478bd9Sstevel@tonic-gate active++; 8607c478bd9Sstevel@tonic-gate msg(gettext( 8617c478bd9Sstevel@tonic-gate "inode %d was active and will be recopied\n"), 8627c478bd9Sstevel@tonic-gate slp->sl_req->ir_inumber); 8637c478bd9Sstevel@tonic-gate /* LINTED: 32-bit to 8-bit assignment ok */ 8647c478bd9Sstevel@tonic-gate BIS(slp->sl_req->ir_inumber, activemap); 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate nextslave(); 8677c478bd9Sstevel@tonic-gate } 8687c478bd9Sstevel@tonic-gate } 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate void 8717c478bd9Sstevel@tonic-gate #ifdef __STDC__ 8727c478bd9Sstevel@tonic-gate flusht(void) 8737c478bd9Sstevel@tonic-gate #else 8747c478bd9Sstevel@tonic-gate flusht() 8757c478bd9Sstevel@tonic-gate #endif 8767c478bd9Sstevel@tonic-gate { 8777c478bd9Sstevel@tonic-gate sigset_t block_set, oset; /* hold SIGUSR1 and atomically sleep */ 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate (void) sigemptyset(&block_set); 8807c478bd9Sstevel@tonic-gate (void) sigaddset(&block_set, SIGUSR1); 8817c478bd9Sstevel@tonic-gate (void) sigprocmask(SIG_BLOCK, &block_set, &oset); 8827c478bd9Sstevel@tonic-gate (void) kill(writepid, SIGUSR1); /* tell writer to flush */ 8837c478bd9Sstevel@tonic-gate (void) sigpause(SIGUSR1); /* wait for SIGUSR1 from writer */ 8847c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 8857c478bd9Sstevel@tonic-gate } 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate jmp_buf checkpoint_buf; 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate /* 8907c478bd9Sstevel@tonic-gate * Roll forward to the next volume after receiving 8917c478bd9Sstevel@tonic-gate * an EOT signal from writer. Get checkpoint data 8927c478bd9Sstevel@tonic-gate * from writer and return if done, otherwise fork 8937c478bd9Sstevel@tonic-gate * a new process and jump back to main state loop 8947c478bd9Sstevel@tonic-gate * to begin the next volume. Installed as the master's 8957c478bd9Sstevel@tonic-gate * signal handler for SIGUSR1. 8967c478bd9Sstevel@tonic-gate */ 8977c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8987c478bd9Sstevel@tonic-gate static void 899*fe0e7ec4Smaheshvs rollforward(int sig) 9007c478bd9Sstevel@tonic-gate { 9017c478bd9Sstevel@tonic-gate int status; 9027c478bd9Sstevel@tonic-gate (void) sighold(SIGUSR1); 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate /* 9057c478bd9Sstevel@tonic-gate * Writer sends us checkpoint information after 9067c478bd9Sstevel@tonic-gate * each volume. A returned state of DS_DONE with no 9077c478bd9Sstevel@tonic-gate * unwritten (left-over) records differentiates a 9087c478bd9Sstevel@tonic-gate * clean flush from one in which EOT was encountered. 9097c478bd9Sstevel@tonic-gate */ 9107c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())read, writer, (char *)&chkpt, 9117c478bd9Sstevel@tonic-gate sizeof (struct slaves)) != sizeof (struct slaves)) { 9127c478bd9Sstevel@tonic-gate cmdrderr(); 9137c478bd9Sstevel@tonic-gate dumpabort(); 9147c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate if (atomic((int(*)())read, writer, (char *)&spcl, 9177c478bd9Sstevel@tonic-gate TP_BSIZE_MIN) != TP_BSIZE_MIN) { 9187c478bd9Sstevel@tonic-gate cmdrderr(); 9197c478bd9Sstevel@tonic-gate dumpabort(); 9207c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 9217c478bd9Sstevel@tonic-gate } 9227c478bd9Sstevel@tonic-gate ino = chkpt.sl_inos - 1; 9237c478bd9Sstevel@tonic-gate pos = chkpt.sl_offset; 9247c478bd9Sstevel@tonic-gate leftover = chkpt.sl_count; 9257c478bd9Sstevel@tonic-gate dumpstate = chkpt.sl_state; 9267c478bd9Sstevel@tonic-gate blockswritten = ++chkpt.sl_tapea; 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate if (dumpstate == DS_DONE) { 9297c478bd9Sstevel@tonic-gate if (archivepid) { 9307c478bd9Sstevel@tonic-gate /* 9317c478bd9Sstevel@tonic-gate * If archiving (either archive or 9327c478bd9Sstevel@tonic-gate * database), signal the archiver 9337c478bd9Sstevel@tonic-gate * to finish up. This must happen 9347c478bd9Sstevel@tonic-gate * before the writer exits in order 9357c478bd9Sstevel@tonic-gate * to avoid a race. 9367c478bd9Sstevel@tonic-gate */ 9377c478bd9Sstevel@tonic-gate (void) kill(archivepid, SIGUSR1); 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate (void) signal(SIGUSR1, SIG_IGN); 9407c478bd9Sstevel@tonic-gate (void) sigrelse(SIGUSR1); 9417c478bd9Sstevel@tonic-gate (void) kill(writepid, SIGUSR1); /* tell writer to exit */ 9427c478bd9Sstevel@tonic-gate 9437c478bd9Sstevel@tonic-gate lf_archoffset = 0LL; 9447c478bd9Sstevel@tonic-gate longjmp(checkpoint_buf, 1); 9457c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate if (leftover) { 9497c478bd9Sstevel@tonic-gate (void) memmove(spcl.c_addr, 9507c478bd9Sstevel@tonic-gate &spcl.c_addr[spcl.c_count-leftover], leftover); 9517c478bd9Sstevel@tonic-gate bzero(&spcl.c_addr[leftover], TP_NINDIR-leftover); 9527c478bd9Sstevel@tonic-gate } 9537c478bd9Sstevel@tonic-gate if (writepid) { 9547c478bd9Sstevel@tonic-gate (void) kill(writepid, SIGUSR1); /* tell writer to exit */ 9557c478bd9Sstevel@tonic-gate (void) close(writer); 9567c478bd9Sstevel@tonic-gate writer = -1; 9577c478bd9Sstevel@tonic-gate } 9587c478bd9Sstevel@tonic-gate if (archivepid) { 9597c478bd9Sstevel@tonic-gate (void) waitpid(archivepid, &status, 0); /* wait for archiver */ 9607c478bd9Sstevel@tonic-gate #ifdef TDEBUG 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 9637c478bd9Sstevel@tonic-gate msg(gettext("Archiver %ld returns with status %d\n"), 9647c478bd9Sstevel@tonic-gate (long)archivepid, status); 9657c478bd9Sstevel@tonic-gate #endif 9667c478bd9Sstevel@tonic-gate archivepid = 0; 9677c478bd9Sstevel@tonic-gate } 9687c478bd9Sstevel@tonic-gate /* 9697c478bd9Sstevel@tonic-gate * Checkpoint archive file 9707c478bd9Sstevel@tonic-gate */ 9717c478bd9Sstevel@tonic-gate if (!doingverify && archive) { 9727c478bd9Sstevel@tonic-gate lf_archoffset = lseek64(archivefd, (off64_t)0, 2); 9737c478bd9Sstevel@tonic-gate if (lf_archoffset < 0) { 9747c478bd9Sstevel@tonic-gate int saverr = errno; 9757c478bd9Sstevel@tonic-gate msg(gettext("Cannot position archive file `%s': %s\n"), 9767c478bd9Sstevel@tonic-gate archivefile, strerror(saverr)); 9777c478bd9Sstevel@tonic-gate dumpabort(); 9787c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 9797c478bd9Sstevel@tonic-gate } 9807c478bd9Sstevel@tonic-gate (void) close(archivefd); 9817c478bd9Sstevel@tonic-gate archivefd = -1; 9827c478bd9Sstevel@tonic-gate } 9837c478bd9Sstevel@tonic-gate resetino(ino); 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate if (dumpstate == DS_START) { 9867c478bd9Sstevel@tonic-gate msg(gettext( 9877c478bd9Sstevel@tonic-gate "Tape too short: changing volumes and restarting\n")); 9887c478bd9Sstevel@tonic-gate reset(); 9897c478bd9Sstevel@tonic-gate } 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate if (!pipeout) { 9927c478bd9Sstevel@tonic-gate if (verify && !doingverify) 9937c478bd9Sstevel@tonic-gate trewind(); 9947c478bd9Sstevel@tonic-gate else { 9957c478bd9Sstevel@tonic-gate close_rewind(); 9967c478bd9Sstevel@tonic-gate changevol(); 9977c478bd9Sstevel@tonic-gate } 9987c478bd9Sstevel@tonic-gate } 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate (void) sigrelse(SIGUSR1); 10017c478bd9Sstevel@tonic-gate otape(0); 10027c478bd9Sstevel@tonic-gate longjmp(checkpoint_buf, 1); 10037c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate static void 1007*fe0e7ec4Smaheshvs nap(int ms) 10087c478bd9Sstevel@tonic-gate { 10097c478bd9Sstevel@tonic-gate struct timeval tv; 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate tv.tv_sec = ms / 1000; 10127c478bd9Sstevel@tonic-gate tv.tv_usec = (ms - tv.tv_sec * 1000) * 1000; 10137c478bd9Sstevel@tonic-gate (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv); 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate static jmp_buf alrm_buf; 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10197c478bd9Sstevel@tonic-gate static void 1020*fe0e7ec4Smaheshvs alrm(int sig) 10217c478bd9Sstevel@tonic-gate { 10227c478bd9Sstevel@tonic-gate longjmp(alrm_buf, 1); 10237c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 10247c478bd9Sstevel@tonic-gate } 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate void 10277c478bd9Sstevel@tonic-gate #ifdef __STDC__ 10287c478bd9Sstevel@tonic-gate nextdevice(void) 10297c478bd9Sstevel@tonic-gate #else 10307c478bd9Sstevel@tonic-gate nextdevice() 10317c478bd9Sstevel@tonic-gate #endif 10327c478bd9Sstevel@tonic-gate { 10337c478bd9Sstevel@tonic-gate char *cp; 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate if (host != NULL) /* we set the host only once in ufsdump */ 10367c478bd9Sstevel@tonic-gate return; 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate host = NULL; 10397c478bd9Sstevel@tonic-gate if (strchr(tape, ':')) { 10407c478bd9Sstevel@tonic-gate if (diskette) { 10417c478bd9Sstevel@tonic-gate msg(gettext("Cannot do remote dump to diskette\n")); 10427c478bd9Sstevel@tonic-gate Exit(X_ABORT); 10437c478bd9Sstevel@tonic-gate } 10447c478bd9Sstevel@tonic-gate host = tape; 10457c478bd9Sstevel@tonic-gate tape = strchr(host, ':'); 10467c478bd9Sstevel@tonic-gate *tape++ = 0; 10477c478bd9Sstevel@tonic-gate cp = strchr(host, '@'); /* user@host? */ 10487c478bd9Sstevel@tonic-gate if (cp != (char *)0) 10497c478bd9Sstevel@tonic-gate cp++; 10507c478bd9Sstevel@tonic-gate else 10517c478bd9Sstevel@tonic-gate cp = host; 10527c478bd9Sstevel@tonic-gate } else 10537c478bd9Sstevel@tonic-gate cp = spcl.c_host; 10547c478bd9Sstevel@tonic-gate /* 10557c478bd9Sstevel@tonic-gate * dumpdev is provided for use in prompts and is of 10567c478bd9Sstevel@tonic-gate * the form: 10577c478bd9Sstevel@tonic-gate * hostname:device 10587c478bd9Sstevel@tonic-gate * sdumpdev is of the form: 10597c478bd9Sstevel@tonic-gate * hostname:device 10607c478bd9Sstevel@tonic-gate * for remote devices, and simply: 10617c478bd9Sstevel@tonic-gate * device 10627c478bd9Sstevel@tonic-gate * for local devices. 10637c478bd9Sstevel@tonic-gate */ 10647c478bd9Sstevel@tonic-gate if (dumpdev != (char *)NULL) { 10657c478bd9Sstevel@tonic-gate /* LINTED: dumpdev is not NULL */ 10667c478bd9Sstevel@tonic-gate free(dumpdev); 10677c478bd9Sstevel@tonic-gate } 10687c478bd9Sstevel@tonic-gate /*LINTED [cast to smaller integer]*/ 10697c478bd9Sstevel@tonic-gate dumpdev = xmalloc((size_t)((sizeof (spcl.c_host) + strlen(tape) + 2))); 10707c478bd9Sstevel@tonic-gate /* LINTED unsigned -> signed cast ok */ 10717c478bd9Sstevel@tonic-gate (void) sprintf(dumpdev, "%.*s:%s", (int)sizeof (spcl.c_host), cp, tape); 10727c478bd9Sstevel@tonic-gate if (cp == spcl.c_host) 10737c478bd9Sstevel@tonic-gate sdumpdev = strchr(dumpdev, ':') + 1; 10747c478bd9Sstevel@tonic-gate else 10757c478bd9Sstevel@tonic-gate sdumpdev = dumpdev; 10767c478bd9Sstevel@tonic-gate } 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate /* 10797c478bd9Sstevel@tonic-gate * Gross hack due to misfeature of mt tape driver that causes 10807c478bd9Sstevel@tonic-gate * the device to rewind if we generate any signals. Guess 10817c478bd9Sstevel@tonic-gate * whether tape is rewind device or not -- for local devices 10827c478bd9Sstevel@tonic-gate * we can just look at the minor number. For rmt devices, 10837c478bd9Sstevel@tonic-gate * make an educated guess. 10847c478bd9Sstevel@tonic-gate */ 10857c478bd9Sstevel@tonic-gate int 1086*fe0e7ec4Smaheshvs isrewind(int f) 10877c478bd9Sstevel@tonic-gate { 10887c478bd9Sstevel@tonic-gate struct stat64 sbuf; 10897c478bd9Sstevel@tonic-gate char *c; 10907c478bd9Sstevel@tonic-gate int unit; 10917c478bd9Sstevel@tonic-gate int rewind; 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate if (host) { 10947c478bd9Sstevel@tonic-gate c = strrchr(tape, '/'); 10957c478bd9Sstevel@tonic-gate if (c == NULL) 10967c478bd9Sstevel@tonic-gate c = tape; 10977c478bd9Sstevel@tonic-gate else 10987c478bd9Sstevel@tonic-gate c++; 10997c478bd9Sstevel@tonic-gate /* 11007c478bd9Sstevel@tonic-gate * If the last component begins or ends with an 'n', it is 11017c478bd9Sstevel@tonic-gate * assumed to be a non-rewind device. 11027c478bd9Sstevel@tonic-gate */ 11037c478bd9Sstevel@tonic-gate if (c[0] == 'n' || c[strlen(c)-1] == 'n') 11047c478bd9Sstevel@tonic-gate rewind = 0; 11057c478bd9Sstevel@tonic-gate else if ((strstr(tape, "mt") || strstr(tape, "st")) && 11067c478bd9Sstevel@tonic-gate sscanf(tape, "%*[a-zA-Z/]%d", &unit) == 1 && 11077c478bd9Sstevel@tonic-gate (unit & MT_NOREWIND)) 11087c478bd9Sstevel@tonic-gate rewind = 0; 11097c478bd9Sstevel@tonic-gate else 11107c478bd9Sstevel@tonic-gate rewind = 1; 11117c478bd9Sstevel@tonic-gate } else { 11127c478bd9Sstevel@tonic-gate if (fstat64(f, &sbuf) < 0) { 11137c478bd9Sstevel@tonic-gate msg(gettext( 11147c478bd9Sstevel@tonic-gate "Cannot obtain status of output device `%s'\n"), 11157c478bd9Sstevel@tonic-gate tape); 11167c478bd9Sstevel@tonic-gate dumpabort(); 11177c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 11187c478bd9Sstevel@tonic-gate } 11197c478bd9Sstevel@tonic-gate rewind = minor(sbuf.st_rdev) & MT_NOREWIND ? 0 : 1; 11207c478bd9Sstevel@tonic-gate } 11217c478bd9Sstevel@tonic-gate return (rewind); 11227c478bd9Sstevel@tonic-gate } 11237c478bd9Sstevel@tonic-gate 11247c478bd9Sstevel@tonic-gate static void 11257c478bd9Sstevel@tonic-gate #ifdef __STDC__ 11267c478bd9Sstevel@tonic-gate just_rewind(void) 11277c478bd9Sstevel@tonic-gate #else 11287c478bd9Sstevel@tonic-gate just_rewind() 11297c478bd9Sstevel@tonic-gate #endif 11307c478bd9Sstevel@tonic-gate { 11317c478bd9Sstevel@tonic-gate struct slaves *slavep; 11327c478bd9Sstevel@tonic-gate char *rewinding = gettext("Tape rewinding\n"); 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) { 11357c478bd9Sstevel@tonic-gate if (slavep->sl_slavepid > 0) /* signal normal exit */ 11367c478bd9Sstevel@tonic-gate (void) kill(slavep->sl_slavepid, SIGTERM); 11377c478bd9Sstevel@tonic-gate if (slavep->sl_slavefd >= 0) { 11387c478bd9Sstevel@tonic-gate (void) close(slavep->sl_slavefd); 11397c478bd9Sstevel@tonic-gate slavep->sl_slavefd = -1; 11407c478bd9Sstevel@tonic-gate } 11417c478bd9Sstevel@tonic-gate } 11427c478bd9Sstevel@tonic-gate 11437c478bd9Sstevel@tonic-gate /* wait for any signals from slaves */ 11447c478bd9Sstevel@tonic-gate while (waitpid(0, (int *)0, 0) >= 0) 11457c478bd9Sstevel@tonic-gate /*LINTED [empty body]*/ 11467c478bd9Sstevel@tonic-gate continue; 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate if (pipeout) 11497c478bd9Sstevel@tonic-gate return; 11507c478bd9Sstevel@tonic-gate 11517c478bd9Sstevel@tonic-gate if (doingverify) { 11527c478bd9Sstevel@tonic-gate /* 11537c478bd9Sstevel@tonic-gate * Space to the end of the tape. 11547c478bd9Sstevel@tonic-gate * Backup first in case we already read the EOF. 11557c478bd9Sstevel@tonic-gate */ 11567c478bd9Sstevel@tonic-gate if (host) { 11577c478bd9Sstevel@tonic-gate (void) rmtioctl(MTBSR, 1); 11587c478bd9Sstevel@tonic-gate if (rmtioctl(MTEOM, 1) < 0) 11597c478bd9Sstevel@tonic-gate (void) rmtioctl(MTFSF, 1); 11607c478bd9Sstevel@tonic-gate } else { 11617c478bd9Sstevel@tonic-gate static struct mtop bsr = { MTBSR, 1 }; 11627c478bd9Sstevel@tonic-gate static struct mtop eom = { MTEOM, 1 }; 11637c478bd9Sstevel@tonic-gate static struct mtop fsf = { MTFSF, 1 }; 11647c478bd9Sstevel@tonic-gate 11657c478bd9Sstevel@tonic-gate (void) ioctl(to, MTIOCTOP, &bsr); 11667c478bd9Sstevel@tonic-gate if (ioctl(to, MTIOCTOP, &eom) < 0) 11677c478bd9Sstevel@tonic-gate (void) ioctl(to, MTIOCTOP, &fsf); 11687c478bd9Sstevel@tonic-gate } 11697c478bd9Sstevel@tonic-gate } 11707c478bd9Sstevel@tonic-gate 11717c478bd9Sstevel@tonic-gate /* 11727c478bd9Sstevel@tonic-gate * Guess whether the tape is rewinding so we can tell 11737c478bd9Sstevel@tonic-gate * the operator if it's going to take a long time. 11747c478bd9Sstevel@tonic-gate */ 11757c478bd9Sstevel@tonic-gate if (tapeout && isrewind(to)) { 11767c478bd9Sstevel@tonic-gate /* tape is probably rewinding */ 11777c478bd9Sstevel@tonic-gate msg(rewinding); 11787c478bd9Sstevel@tonic-gate } 11797c478bd9Sstevel@tonic-gate } 11807c478bd9Sstevel@tonic-gate 11817c478bd9Sstevel@tonic-gate void 11827c478bd9Sstevel@tonic-gate #ifdef __STDC__ 11837c478bd9Sstevel@tonic-gate trewind(void) 11847c478bd9Sstevel@tonic-gate #else 11857c478bd9Sstevel@tonic-gate trewind() 11867c478bd9Sstevel@tonic-gate #endif 11877c478bd9Sstevel@tonic-gate { 11887c478bd9Sstevel@tonic-gate (void) timeclock((time_t)0); 11897c478bd9Sstevel@tonic-gate if (offline && (!verify || doingverify)) { 11907c478bd9Sstevel@tonic-gate close_rewind(); 11917c478bd9Sstevel@tonic-gate } else { 11927c478bd9Sstevel@tonic-gate just_rewind(); 11937c478bd9Sstevel@tonic-gate if (host) 11947c478bd9Sstevel@tonic-gate rmtclose(); 11957c478bd9Sstevel@tonic-gate else { 11967c478bd9Sstevel@tonic-gate (void) close(to); 11977c478bd9Sstevel@tonic-gate to = -1; 11987c478bd9Sstevel@tonic-gate } 11997c478bd9Sstevel@tonic-gate } 12007c478bd9Sstevel@tonic-gate } 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate void 12037c478bd9Sstevel@tonic-gate #ifdef __STDC__ 12047c478bd9Sstevel@tonic-gate close_rewind(void) 12057c478bd9Sstevel@tonic-gate #else 12067c478bd9Sstevel@tonic-gate close_rewind() 12077c478bd9Sstevel@tonic-gate #endif 12087c478bd9Sstevel@tonic-gate { 12097c478bd9Sstevel@tonic-gate char *rewinding = gettext("Tape rewinding\n"); 12107c478bd9Sstevel@tonic-gate 12117c478bd9Sstevel@tonic-gate (void) timeclock((time_t)0); 12127c478bd9Sstevel@tonic-gate just_rewind(); 12137c478bd9Sstevel@tonic-gate /* 12147c478bd9Sstevel@tonic-gate * The check in just_rewind won't catch the case in 12157c478bd9Sstevel@tonic-gate * which the current volume is being taken off-line 12167c478bd9Sstevel@tonic-gate * and is not mounted on a no-rewind device (and is 12177c478bd9Sstevel@tonic-gate * not the last volume, which is not taken off-line). 12187c478bd9Sstevel@tonic-gate */ 12197c478bd9Sstevel@tonic-gate if (tapeout && !isrewind(to) && offline) { 12207c478bd9Sstevel@tonic-gate /* tape is probably rewinding */ 12217c478bd9Sstevel@tonic-gate msg(rewinding); 12227c478bd9Sstevel@tonic-gate } 12237c478bd9Sstevel@tonic-gate if (host) { 12247c478bd9Sstevel@tonic-gate if (offline || autoload) 12257c478bd9Sstevel@tonic-gate (void) rmtioctl(MTOFFL, 0); 12267c478bd9Sstevel@tonic-gate rmtclose(); 12277c478bd9Sstevel@tonic-gate } else { 12287c478bd9Sstevel@tonic-gate if (offline || autoload) { 12297c478bd9Sstevel@tonic-gate static struct mtop offl = { MTOFFL, 0 }; 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate (void) ioctl(to, MTIOCTOP, &offl); 12327c478bd9Sstevel@tonic-gate if (diskette) 12337c478bd9Sstevel@tonic-gate (void) ioctl(to, FDEJECT, 0); 12347c478bd9Sstevel@tonic-gate } 12357c478bd9Sstevel@tonic-gate (void) close(to); 12367c478bd9Sstevel@tonic-gate to = -1; 12377c478bd9Sstevel@tonic-gate } 12387c478bd9Sstevel@tonic-gate } 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate void 12417c478bd9Sstevel@tonic-gate #ifdef __STDC__ 12427c478bd9Sstevel@tonic-gate changevol(void) 12437c478bd9Sstevel@tonic-gate #else 12447c478bd9Sstevel@tonic-gate changevol() 12457c478bd9Sstevel@tonic-gate #endif 12467c478bd9Sstevel@tonic-gate { 12477c478bd9Sstevel@tonic-gate char buf1[3000], buf2[3000]; 12487c478bd9Sstevel@tonic-gate char volname[LBLSIZE+1]; 12497c478bd9Sstevel@tonic-gate 12507c478bd9Sstevel@tonic-gate /*CONSTANTCONDITION*/ 12517c478bd9Sstevel@tonic-gate assert(sizeof (spcl.c_label) < sizeof (volname)); 12527c478bd9Sstevel@tonic-gate 12537c478bd9Sstevel@tonic-gate filenum = 1; 12547c478bd9Sstevel@tonic-gate nextdevice(); 12557c478bd9Sstevel@tonic-gate (void) strcpy(spcl.c_label, tlabel); 12567c478bd9Sstevel@tonic-gate if (host) { 12577c478bd9Sstevel@tonic-gate char *rhost = host; 12587c478bd9Sstevel@tonic-gate char *cp = strchr(host, '@'); 12597c478bd9Sstevel@tonic-gate if (cp == (char *)0) 12607c478bd9Sstevel@tonic-gate cp = host; 12617c478bd9Sstevel@tonic-gate else 12627c478bd9Sstevel@tonic-gate cp++; 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate if (rmthost(rhost, ntrec) == 0) { 12657c478bd9Sstevel@tonic-gate msg(gettext("Cannot connect to tape host `%s'\n"), cp); 12667c478bd9Sstevel@tonic-gate dumpabort(); 12677c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate if (rhost != host) 12707c478bd9Sstevel@tonic-gate free(rhost); 12717c478bd9Sstevel@tonic-gate } 12727c478bd9Sstevel@tonic-gate 12737c478bd9Sstevel@tonic-gate /* 12747c478bd9Sstevel@tonic-gate * Make volume switching as automatic as possible 12757c478bd9Sstevel@tonic-gate * while avoiding overwriting volumes. We will 12767c478bd9Sstevel@tonic-gate * switch automatically under the following condition: 12777c478bd9Sstevel@tonic-gate * 1) The user specified autoloading from the 12787c478bd9Sstevel@tonic-gate * command line. 12797c478bd9Sstevel@tonic-gate * At one time, we (in the guise of hsmdump) had the 12807c478bd9Sstevel@tonic-gate * concept of a sequence of devices to rotate through, 12817c478bd9Sstevel@tonic-gate * but that's never been a ufsdump feature. 12827c478bd9Sstevel@tonic-gate */ 12837c478bd9Sstevel@tonic-gate if (autoload) { 12847c478bd9Sstevel@tonic-gate int tries; 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate /* 12877c478bd9Sstevel@tonic-gate * Stop the clock for throughput calculations. 12887c478bd9Sstevel@tonic-gate */ 12897c478bd9Sstevel@tonic-gate if ((telapsed != NULL) && (tstart_writing != NULL)) { 12907c478bd9Sstevel@tonic-gate *telapsed += time((time_t *)NULL) - *tstart_writing; 12917c478bd9Sstevel@tonic-gate } 12927c478bd9Sstevel@tonic-gate 12937c478bd9Sstevel@tonic-gate (void) snprintf(volname, sizeof (volname), "#%d", tapeno+1); 12947c478bd9Sstevel@tonic-gate (void) snprintf(buf1, sizeof (buf1), gettext( 12957c478bd9Sstevel@tonic-gate "Mounting volume %s on %s\n"), volname, dumpdev); 12967c478bd9Sstevel@tonic-gate msg(buf1); 12977c478bd9Sstevel@tonic-gate broadcast(buf1); 12987c478bd9Sstevel@tonic-gate 12997c478bd9Sstevel@tonic-gate /* 13007c478bd9Sstevel@tonic-gate * Wait for the tape to autoload. Note that the delay 13017c478bd9Sstevel@tonic-gate * period doesn't take into account however long it takes 13027c478bd9Sstevel@tonic-gate * for the open to fail (measured at 21 seconds for an 13037c478bd9Sstevel@tonic-gate * Exabyte 8200 under 2.7 on an Ultra 2). 13047c478bd9Sstevel@tonic-gate */ 13057c478bd9Sstevel@tonic-gate for (tries = 0; tries < autoload_tries; tries++) { 13067c478bd9Sstevel@tonic-gate if (host) { 13077c478bd9Sstevel@tonic-gate if (rmtopen(tape, O_RDONLY) >= 0) { 13087c478bd9Sstevel@tonic-gate rmtclose(); 13097c478bd9Sstevel@tonic-gate return; 13107c478bd9Sstevel@tonic-gate } 13117c478bd9Sstevel@tonic-gate } else { 13127c478bd9Sstevel@tonic-gate int f, m; 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate m = (access(tape, F_OK) == 0) ? 0 : O_CREAT; 13157c478bd9Sstevel@tonic-gate if ((f = doingverify ? 13167c478bd9Sstevel@tonic-gate safe_device_open(tape, O_RDONLY, 0600) : 13177c478bd9Sstevel@tonic-gate safe_device_open(tape, O_RDONLY|m, 0600)) 13187c478bd9Sstevel@tonic-gate >= 0) { 13197c478bd9Sstevel@tonic-gate (void) close(f); 13207c478bd9Sstevel@tonic-gate return; 13217c478bd9Sstevel@tonic-gate } 13227c478bd9Sstevel@tonic-gate } 13237c478bd9Sstevel@tonic-gate (void) sleep(autoload_period); 13247c478bd9Sstevel@tonic-gate } 13257c478bd9Sstevel@tonic-gate /* 13267c478bd9Sstevel@tonic-gate * Autoload timed out, ask the operator to do it. 13277c478bd9Sstevel@tonic-gate * Note that query() will update *telapsed, and we 13287c478bd9Sstevel@tonic-gate * shouldn't charge for the autoload time. So, since 13297c478bd9Sstevel@tonic-gate * we updated *telapsed ourselves above, we just set 13307c478bd9Sstevel@tonic-gate * tstart_writing to the current time, and query() 13317c478bd9Sstevel@tonic-gate * will end up making a null-effect change. This, 13327c478bd9Sstevel@tonic-gate * of course, assumes that our caller will be resetting 13337c478bd9Sstevel@tonic-gate * *tstart_writing. This is currently the case. 13347c478bd9Sstevel@tonic-gate * If tstart_writing is NULL (should never happen), 13357c478bd9Sstevel@tonic-gate * we're ok, since time(2) will accept a NULL pointer. 13367c478bd9Sstevel@tonic-gate */ 13377c478bd9Sstevel@tonic-gate (void) time(tstart_writing); 13387c478bd9Sstevel@tonic-gate } 13397c478bd9Sstevel@tonic-gate 13407c478bd9Sstevel@tonic-gate if (strncmp(spcl.c_label, "none", 5)) { 13417c478bd9Sstevel@tonic-gate (void) strncpy(volname, spcl.c_label, sizeof (spcl.c_label)); 13427c478bd9Sstevel@tonic-gate volname[sizeof (spcl.c_label)] = '\0'; 13437c478bd9Sstevel@tonic-gate } else 13447c478bd9Sstevel@tonic-gate (void) snprintf(volname, sizeof (volname), "#%d", tapeno+1); 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate timeest(1, spcl.c_tapea); 13477c478bd9Sstevel@tonic-gate (void) snprintf(buf1, sizeof (buf1), gettext( 13487c478bd9Sstevel@tonic-gate "Change Volumes: Mount volume `%s' on `%s'\n"), volname, dumpdev); 13497c478bd9Sstevel@tonic-gate msg(buf1); 13507c478bd9Sstevel@tonic-gate broadcast(gettext("CHANGE VOLUMES!\7\7\n")); 13517c478bd9Sstevel@tonic-gate (void) snprintf(buf1, sizeof (buf1), gettext( 13527c478bd9Sstevel@tonic-gate "Is the new volume (%s) mounted on `%s' and ready to go?: %s"), 13537c478bd9Sstevel@tonic-gate volname, dumpdev, gettext("(\"yes\" or \"no\") ")); 13547c478bd9Sstevel@tonic-gate while (!query(buf1)) { 13557c478bd9Sstevel@tonic-gate (void) snprintf(buf2, sizeof (buf2), gettext( 13567c478bd9Sstevel@tonic-gate "Do you want to abort dump?: (\"yes\" or \"no\") ")); 13577c478bd9Sstevel@tonic-gate if (query(buf2)) { 13587c478bd9Sstevel@tonic-gate dumpabort(); 13597c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 13607c478bd9Sstevel@tonic-gate } 13617c478bd9Sstevel@tonic-gate } 13627c478bd9Sstevel@tonic-gate } 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate /* 13657c478bd9Sstevel@tonic-gate * We implement taking and restoring checkpoints on the tape level. 13667c478bd9Sstevel@tonic-gate * When each tape is opened, a new process is created by forking; this 13677c478bd9Sstevel@tonic-gate * saves all of the necessary context in the parent. The child 13687c478bd9Sstevel@tonic-gate * continues the dump; the parent waits around, saving the context. 13697c478bd9Sstevel@tonic-gate * If the child returns X_REWRITE, then it had problems writing that tape; 13707c478bd9Sstevel@tonic-gate * this causes the parent to fork again, duplicating the context, and 13717c478bd9Sstevel@tonic-gate * everything continues as if nothing had happened. 13727c478bd9Sstevel@tonic-gate */ 13737c478bd9Sstevel@tonic-gate 13747c478bd9Sstevel@tonic-gate void 1375*fe0e7ec4Smaheshvs otape(int top) 13767c478bd9Sstevel@tonic-gate { 13777c478bd9Sstevel@tonic-gate static struct mtget mt; 13787c478bd9Sstevel@tonic-gate char buf[3000]; 13797c478bd9Sstevel@tonic-gate pid_t parentpid; 13807c478bd9Sstevel@tonic-gate pid_t childpid; 13817c478bd9Sstevel@tonic-gate pid_t waitproc; 13827c478bd9Sstevel@tonic-gate int status; 13837c478bd9Sstevel@tonic-gate struct sigvec sv, osv; 13847c478bd9Sstevel@tonic-gate 13857c478bd9Sstevel@tonic-gate sv.sv_flags = SA_RESTART; 13867c478bd9Sstevel@tonic-gate (void) sigemptyset(&sv.sa_mask); 13877c478bd9Sstevel@tonic-gate sv.sv_handler = SIG_IGN; 13887c478bd9Sstevel@tonic-gate (void) sigvec(SIGINT, &sv, (struct sigvec *)0); 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate parentpid = getpid(); 13917c478bd9Sstevel@tonic-gate 13927c478bd9Sstevel@tonic-gate if (verify) { 13937c478bd9Sstevel@tonic-gate if (doingverify) 13947c478bd9Sstevel@tonic-gate doingverify = 0; 13957c478bd9Sstevel@tonic-gate else 13967c478bd9Sstevel@tonic-gate Exit(X_VERIFY); 13977c478bd9Sstevel@tonic-gate } 13987c478bd9Sstevel@tonic-gate restore_check_point: 13997c478bd9Sstevel@tonic-gate 14007c478bd9Sstevel@tonic-gate sv.sv_handler = interrupt; 14017c478bd9Sstevel@tonic-gate (void) sigvec(SIGINT, &sv, (struct sigvec *)0); 14027c478bd9Sstevel@tonic-gate (void) fflush(stderr); 14037c478bd9Sstevel@tonic-gate /* 14047c478bd9Sstevel@tonic-gate * All signals are inherited... 14057c478bd9Sstevel@tonic-gate */ 14067c478bd9Sstevel@tonic-gate sighold(SIGINT); 14077c478bd9Sstevel@tonic-gate childpid = fork(); 14087c478bd9Sstevel@tonic-gate if (childpid < 0) { 14097c478bd9Sstevel@tonic-gate msg(gettext( 14107c478bd9Sstevel@tonic-gate "Context-saving fork failed in parent %ld\n"), 14117c478bd9Sstevel@tonic-gate (long)parentpid); 14127c478bd9Sstevel@tonic-gate Exit(X_ABORT); 14137c478bd9Sstevel@tonic-gate } 14147c478bd9Sstevel@tonic-gate if (childpid != 0) { 14157c478bd9Sstevel@tonic-gate /* 14167c478bd9Sstevel@tonic-gate * PARENT: 14177c478bd9Sstevel@tonic-gate * save the context by waiting 14187c478bd9Sstevel@tonic-gate * until the child doing all of the work returns. 14197c478bd9Sstevel@tonic-gate * let the child catch user interrupts 14207c478bd9Sstevel@tonic-gate */ 14217c478bd9Sstevel@tonic-gate sv.sv_handler = SIG_IGN; 14227c478bd9Sstevel@tonic-gate (void) sigvec(SIGINT, &sv, (struct sigvec *)0); 14237c478bd9Sstevel@tonic-gate sigrelse(SIGINT); 14247c478bd9Sstevel@tonic-gate #ifdef TDEBUG 14257c478bd9Sstevel@tonic-gate 14267c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14277c478bd9Sstevel@tonic-gate msg(gettext( 14287c478bd9Sstevel@tonic-gate "Volume: %d; parent process: %ld child process %ld\n"), 14297c478bd9Sstevel@tonic-gate tapeno+1, (long)parentpid, (long)childpid); 14307c478bd9Sstevel@tonic-gate #endif /* TDEBUG */ 14317c478bd9Sstevel@tonic-gate for (;;) { 14327c478bd9Sstevel@tonic-gate waitproc = waitpid(0, &status, 0); 14337c478bd9Sstevel@tonic-gate if (waitproc == childpid) 14347c478bd9Sstevel@tonic-gate break; 14357c478bd9Sstevel@tonic-gate msg(gettext( 14367c478bd9Sstevel@tonic-gate "Parent %ld waiting for child %ld had another child %ld return\n"), 14377c478bd9Sstevel@tonic-gate (long)parentpid, (long)childpid, (long)waitproc); 14387c478bd9Sstevel@tonic-gate } 14397c478bd9Sstevel@tonic-gate if (WIFSIGNALED(status)) { 14407c478bd9Sstevel@tonic-gate msg(gettext("Process %ld killed by signal %d: %s\n"), 14417c478bd9Sstevel@tonic-gate (long)childpid, WTERMSIG(status), 14427c478bd9Sstevel@tonic-gate strsignal(WTERMSIG(status))); 14437c478bd9Sstevel@tonic-gate status = X_ABORT; 14447c478bd9Sstevel@tonic-gate } else 14457c478bd9Sstevel@tonic-gate status = WEXITSTATUS(status); 14467c478bd9Sstevel@tonic-gate #ifdef TDEBUG 14477c478bd9Sstevel@tonic-gate switch (status) { 14487c478bd9Sstevel@tonic-gate case X_FINOK: 14497c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14507c478bd9Sstevel@tonic-gate msg(gettext( 14517c478bd9Sstevel@tonic-gate "Child %ld finishes X_FINOK\n"), (long)childpid); 14527c478bd9Sstevel@tonic-gate break; 14537c478bd9Sstevel@tonic-gate case X_ABORT: 14547c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14557c478bd9Sstevel@tonic-gate msg(gettext( 14567c478bd9Sstevel@tonic-gate "Child %ld finishes X_ABORT\n"), (long)childpid); 14577c478bd9Sstevel@tonic-gate break; 14587c478bd9Sstevel@tonic-gate case X_REWRITE: 14597c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14607c478bd9Sstevel@tonic-gate msg(gettext( 14617c478bd9Sstevel@tonic-gate "Child %ld finishes X_REWRITE\n"), (long)childpid); 14627c478bd9Sstevel@tonic-gate break; 14637c478bd9Sstevel@tonic-gate case X_RESTART: 14647c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14657c478bd9Sstevel@tonic-gate msg(gettext( 14667c478bd9Sstevel@tonic-gate "Child %ld finishes X_RESTART\n"), (long)childpid); 14677c478bd9Sstevel@tonic-gate break; 14687c478bd9Sstevel@tonic-gate case X_VERIFY: 14697c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14707c478bd9Sstevel@tonic-gate msg(gettext( 14717c478bd9Sstevel@tonic-gate "Child %ld finishes X_VERIFY\n"), (long)childpid); 14727c478bd9Sstevel@tonic-gate break; 14737c478bd9Sstevel@tonic-gate default: 14747c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 14757c478bd9Sstevel@tonic-gate msg(gettext("Child %ld finishes unknown %d\n"), 14767c478bd9Sstevel@tonic-gate (long)childpid, status); 14777c478bd9Sstevel@tonic-gate break; 14787c478bd9Sstevel@tonic-gate } 14797c478bd9Sstevel@tonic-gate #endif /* TDEBUG */ 14807c478bd9Sstevel@tonic-gate switch (status) { 14817c478bd9Sstevel@tonic-gate case X_FINOK: 14827c478bd9Sstevel@tonic-gate /* wait for children */ 14837c478bd9Sstevel@tonic-gate while (waitpid(0, (int *)0, 0) >= 0) 14847c478bd9Sstevel@tonic-gate /*LINTED [empty body]*/ 14857c478bd9Sstevel@tonic-gate continue; 14867c478bd9Sstevel@tonic-gate Exit(X_FINOK); 14877c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 14887c478bd9Sstevel@tonic-gate case X_ABORT: 14897c478bd9Sstevel@tonic-gate Exit(X_ABORT); 14907c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 14917c478bd9Sstevel@tonic-gate case X_VERIFY: 14927c478bd9Sstevel@tonic-gate doingverify++; 14937c478bd9Sstevel@tonic-gate goto restore_check_point; 14947c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 14957c478bd9Sstevel@tonic-gate case X_REWRITE: 14967c478bd9Sstevel@tonic-gate doingverify = 0; 14977c478bd9Sstevel@tonic-gate changevol(); 14987c478bd9Sstevel@tonic-gate goto restore_check_point; 14997c478bd9Sstevel@tonic-gate /* NOTREACHED */ 15007c478bd9Sstevel@tonic-gate case X_RESTART: 15017c478bd9Sstevel@tonic-gate doingverify = 0; 15027c478bd9Sstevel@tonic-gate if (!top) { 15037c478bd9Sstevel@tonic-gate Exit(X_RESTART); 15047c478bd9Sstevel@tonic-gate } 15057c478bd9Sstevel@tonic-gate if (!offline) 15067c478bd9Sstevel@tonic-gate autoload = 0; 15077c478bd9Sstevel@tonic-gate changevol(); 15087c478bd9Sstevel@tonic-gate sv.sv_handler = interrupt; 15097c478bd9Sstevel@tonic-gate (void) sigvec(SIGINT, &sv, (struct sigvec *)0); 15107c478bd9Sstevel@tonic-gate return; 15117c478bd9Sstevel@tonic-gate /* NOTREACHED */ 15127c478bd9Sstevel@tonic-gate default: 15137c478bd9Sstevel@tonic-gate msg(gettext("Bad return code from dump: %d\n"), status); 15147c478bd9Sstevel@tonic-gate Exit(X_ABORT); 15157c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 15187c478bd9Sstevel@tonic-gate } else { /* we are the child; just continue */ 15197c478bd9Sstevel@tonic-gate child_chdir(); 15207c478bd9Sstevel@tonic-gate sigrelse(SIGINT); 15217c478bd9Sstevel@tonic-gate #ifdef TDEBUG 15227c478bd9Sstevel@tonic-gate (void) sleep(4); /* time for parent's message to get out */ 15237c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 15247c478bd9Sstevel@tonic-gate msg(gettext( 15257c478bd9Sstevel@tonic-gate "Child on Volume %d has parent %ld, my pid = %ld\n"), 15267c478bd9Sstevel@tonic-gate tapeno+1, (long)parentpid, (long)getpid()); 15277c478bd9Sstevel@tonic-gate #endif 15287c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), gettext( 15297c478bd9Sstevel@tonic-gate "Cannot open `%s'. Do you want to retry the open?: (\"yes\" or \"no\") "), 15307c478bd9Sstevel@tonic-gate dumpdev); 15317c478bd9Sstevel@tonic-gate if (doingverify) { 15327c478bd9Sstevel@tonic-gate /* 1 for stdout */ 15337c478bd9Sstevel@tonic-gate while ((to = host ? rmtopen(tape, O_RDONLY) : 15347c478bd9Sstevel@tonic-gate pipeout ? 1 : 15357c478bd9Sstevel@tonic-gate safe_device_open(tape, O_RDONLY, 0600)) < 0) { 15367c478bd9Sstevel@tonic-gate perror(tape); 15377c478bd9Sstevel@tonic-gate if (autoload) { 15387c478bd9Sstevel@tonic-gate if (!query_once(buf, 1)) { 15397c478bd9Sstevel@tonic-gate dumpabort(); 15407c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 15417c478bd9Sstevel@tonic-gate } 15427c478bd9Sstevel@tonic-gate } else { 15437c478bd9Sstevel@tonic-gate if (!query(buf)) { 15447c478bd9Sstevel@tonic-gate dumpabort(); 15457c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 15467c478bd9Sstevel@tonic-gate } 15477c478bd9Sstevel@tonic-gate } 15487c478bd9Sstevel@tonic-gate } 15497c478bd9Sstevel@tonic-gate 15507c478bd9Sstevel@tonic-gate /* 15517c478bd9Sstevel@tonic-gate * If we're using the non-rewinding tape device, 15527c478bd9Sstevel@tonic-gate * the tape will be left positioned after the 15537c478bd9Sstevel@tonic-gate * EOF mark. We need to back up to the beginning 15547c478bd9Sstevel@tonic-gate * of this tape file (cross two tape marks in the 15557c478bd9Sstevel@tonic-gate * reverse direction and one in the forward 15567c478bd9Sstevel@tonic-gate * direction) before the verify pass. 15577c478bd9Sstevel@tonic-gate */ 15587c478bd9Sstevel@tonic-gate if (host) { 15597c478bd9Sstevel@tonic-gate if (rmtioctl(MTBSF, 2) >= 0) 15607c478bd9Sstevel@tonic-gate (void) rmtioctl(MTFSF, 1); 15617c478bd9Sstevel@tonic-gate else 15627c478bd9Sstevel@tonic-gate (void) rmtioctl(MTNBSF, 1); 15637c478bd9Sstevel@tonic-gate } else { 15647c478bd9Sstevel@tonic-gate static struct mtop bsf = { MTBSF, 2 }; 15657c478bd9Sstevel@tonic-gate static struct mtop fsf = { MTFSF, 1 }; 15667c478bd9Sstevel@tonic-gate static struct mtop nbsf = { MTNBSF, 1 }; 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate if (ioctl(to, MTIOCTOP, &bsf) >= 0) 15697c478bd9Sstevel@tonic-gate (void) ioctl(to, MTIOCTOP, &fsf); 15707c478bd9Sstevel@tonic-gate else 15717c478bd9Sstevel@tonic-gate (void) ioctl(to, MTIOCTOP, &nbsf); 15727c478bd9Sstevel@tonic-gate } 15737c478bd9Sstevel@tonic-gate } else { 15747c478bd9Sstevel@tonic-gate /* 15757c478bd9Sstevel@tonic-gate * XXX Add logic to test for "tape" being a 15767c478bd9Sstevel@tonic-gate * XXX device or a non-existent file. 15777c478bd9Sstevel@tonic-gate * Current behaviour is that it must exist, 15787c478bd9Sstevel@tonic-gate * and we over-write whatever's there. 15797c478bd9Sstevel@tonic-gate * This can be bad if tape == "/etc/passwd". 15807c478bd9Sstevel@tonic-gate */ 15817c478bd9Sstevel@tonic-gate if (!pipeout && doposition && (tapeno == 0)) { 15827c478bd9Sstevel@tonic-gate positiontape(buf); 15837c478bd9Sstevel@tonic-gate if (setjmp(alrm_buf)) { 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * The tape is rewinding; 15867c478bd9Sstevel@tonic-gate * we're screwed. 15877c478bd9Sstevel@tonic-gate */ 15887c478bd9Sstevel@tonic-gate msg(gettext( 15897c478bd9Sstevel@tonic-gate "Cannot position tape using rewind device!\n")); 15907c478bd9Sstevel@tonic-gate dumpabort(); 15917c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 15927c478bd9Sstevel@tonic-gate } else { 15937c478bd9Sstevel@tonic-gate sv.sv_handler = alrm; 15947c478bd9Sstevel@tonic-gate (void) sigvec(SIGALRM, &sv, &osv); 15957c478bd9Sstevel@tonic-gate (void) alarm(15); 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate while ((to = host ? rmtopen(tape, O_WRONLY) : 15987c478bd9Sstevel@tonic-gate safe_device_open(tape, O_WRONLY, 0600)) < 0) 15997c478bd9Sstevel@tonic-gate (void) sleep(10); 16007c478bd9Sstevel@tonic-gate (void) alarm(0); 16017c478bd9Sstevel@tonic-gate (void) sigvec(SIGALRM, &osv, 16027c478bd9Sstevel@tonic-gate (struct sigvec *)0); 16037c478bd9Sstevel@tonic-gate } else { 16047c478bd9Sstevel@tonic-gate int m; 16057c478bd9Sstevel@tonic-gate m = (access(tape, F_OK) == 0) ? 0 : O_CREAT; 16067c478bd9Sstevel@tonic-gate /* 16077c478bd9Sstevel@tonic-gate * Only verify the tape label if label 16087c478bd9Sstevel@tonic-gate * verification is on and we are at BOT 16097c478bd9Sstevel@tonic-gate */ 16107c478bd9Sstevel@tonic-gate if (pipeout) 16117c478bd9Sstevel@tonic-gate to = 1; 16127c478bd9Sstevel@tonic-gate else while ((to = host ? 16137c478bd9Sstevel@tonic-gate rmtopen(tape, O_WRONLY) : 16147c478bd9Sstevel@tonic-gate safe_device_open(tape, O_WRONLY|m, 0600)) 16157c478bd9Sstevel@tonic-gate < 0) 16167c478bd9Sstevel@tonic-gate if (!query_once(buf, 1)) { 16177c478bd9Sstevel@tonic-gate dumpabort(); 16187c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 16197c478bd9Sstevel@tonic-gate } 16207c478bd9Sstevel@tonic-gate } 16217c478bd9Sstevel@tonic-gate } 16227c478bd9Sstevel@tonic-gate if (!pipeout) { 16237c478bd9Sstevel@tonic-gate tapeout = host ? rmtstatus(&mt) >= 0 : 16247c478bd9Sstevel@tonic-gate ioctl(to, MTIOCGET, &mt) >= 0; /* set state */ 16257c478bd9Sstevel@tonic-gate /* 16267c478bd9Sstevel@tonic-gate * Make sure the tape is positioned 16277c478bd9Sstevel@tonic-gate * where it is supposed to be 16287c478bd9Sstevel@tonic-gate */ 16297c478bd9Sstevel@tonic-gate if (tapeout && (tapeno > 0) && 16307c478bd9Sstevel@tonic-gate (mt.mt_fileno != (filenum-1))) { 16317c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), gettext( 16327c478bd9Sstevel@tonic-gate "Warning - tape positioning error!\n\ 16337c478bd9Sstevel@tonic-gate \t%s current file %ld, should be %ld\n"), 16347c478bd9Sstevel@tonic-gate tape, mt.mt_fileno+1, filenum); 16357c478bd9Sstevel@tonic-gate msg(buf); 16367c478bd9Sstevel@tonic-gate dumpailing(); 16377c478bd9Sstevel@tonic-gate } 16387c478bd9Sstevel@tonic-gate } 16397c478bd9Sstevel@tonic-gate tapeno++; /* current tape sequence */ 16407c478bd9Sstevel@tonic-gate if (tapeno < TP_NINOS) 16417c478bd9Sstevel@tonic-gate inos[tapeno] = chkpt.sl_inos; 16427c478bd9Sstevel@tonic-gate spcl.c_firstrec = chkpt.sl_firstrec; 16437c478bd9Sstevel@tonic-gate spcl.c_tapea = (*tapea) = chkpt.sl_tapea; 16447c478bd9Sstevel@tonic-gate spcl.c_volume++; 16457c478bd9Sstevel@tonic-gate 16467c478bd9Sstevel@tonic-gate enslave(); /* Share tape buffers with slaves */ 16477c478bd9Sstevel@tonic-gate 16487c478bd9Sstevel@tonic-gate #ifdef DEBUG 16497c478bd9Sstevel@tonic-gate if (xflag) { 16507c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef DEBUG only */ 16517c478bd9Sstevel@tonic-gate msg(gettext("Checkpoint state:\n")); 16527c478bd9Sstevel@tonic-gate msg(" blockswritten %u\n", blockswritten); 16537c478bd9Sstevel@tonic-gate msg(" ino %u\n", ino); 16547c478bd9Sstevel@tonic-gate msg(" pos %u\n", pos); 16557c478bd9Sstevel@tonic-gate msg(" left %u\n", leftover); 16567c478bd9Sstevel@tonic-gate msg(" tapea %u\n", (*tapea)); 16577c478bd9Sstevel@tonic-gate msg(" state %d\n", dumpstate); 16587c478bd9Sstevel@tonic-gate } 16597c478bd9Sstevel@tonic-gate #endif 16607c478bd9Sstevel@tonic-gate spcl.c_type = TS_TAPE; 16617c478bd9Sstevel@tonic-gate spcl.c_tpbsize = tp_bsize; 16627c478bd9Sstevel@tonic-gate if (leftover == 0) { 16637c478bd9Sstevel@tonic-gate spcl.c_count = 0; 16647c478bd9Sstevel@tonic-gate spclrec(); 16657c478bd9Sstevel@tonic-gate newtape = 0; 16667c478bd9Sstevel@tonic-gate } else 16677c478bd9Sstevel@tonic-gate newtape++; /* new volume indication */ 16687c478bd9Sstevel@tonic-gate if (doingverify) { 16697c478bd9Sstevel@tonic-gate msg(gettext("Starting verify pass\n")); 16707c478bd9Sstevel@tonic-gate } else if (tapeno > 1) { 16717c478bd9Sstevel@tonic-gate msg(gettext( 16727c478bd9Sstevel@tonic-gate "Volume %d begins with blocks from inode %lu\n"), 16737c478bd9Sstevel@tonic-gate tapeno, chkpt.sl_inos); 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate (void) timeclock((time_t)1); 16767c478bd9Sstevel@tonic-gate (void) time(tstart_writing); 16777c478bd9Sstevel@tonic-gate timeest(0, spcl.c_tapea); 16787c478bd9Sstevel@tonic-gate } 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate void 16827c478bd9Sstevel@tonic-gate #ifdef __STDC__ 16837c478bd9Sstevel@tonic-gate dumpabort(void) 16847c478bd9Sstevel@tonic-gate #else 16857c478bd9Sstevel@tonic-gate dumpabort() 16867c478bd9Sstevel@tonic-gate #endif 16877c478bd9Sstevel@tonic-gate { 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate if (master && master != getpid()) 16907c478bd9Sstevel@tonic-gate /* 16917c478bd9Sstevel@tonic-gate * signal master to call dumpabort 16927c478bd9Sstevel@tonic-gate */ 16937c478bd9Sstevel@tonic-gate (void) kill(master, SIGTERM); 16947c478bd9Sstevel@tonic-gate else { 16957c478bd9Sstevel@tonic-gate killall(); 16967c478bd9Sstevel@tonic-gate 16977c478bd9Sstevel@tonic-gate if (archivefile) 16987c478bd9Sstevel@tonic-gate (void) unlink(archivefile); 16997c478bd9Sstevel@tonic-gate msg(gettext("The ENTIRE dump is aborted.\n")); 17007c478bd9Sstevel@tonic-gate } 17017c478bd9Sstevel@tonic-gate Exit(X_ABORT); 17027c478bd9Sstevel@tonic-gate } 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate void 17057c478bd9Sstevel@tonic-gate dumpailing(void) 17067c478bd9Sstevel@tonic-gate { 17077c478bd9Sstevel@tonic-gate 17087c478bd9Sstevel@tonic-gate broadcast(gettext("DUMP IS AILING!\n")); 17097c478bd9Sstevel@tonic-gate if (!query(gettext( 17107c478bd9Sstevel@tonic-gate "Do you want to attempt to continue? (\"yes\" or \"no\") "))) { 17117c478bd9Sstevel@tonic-gate dumpabort(); 17127c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 17137c478bd9Sstevel@tonic-gate } 17147c478bd9Sstevel@tonic-gate } 17157c478bd9Sstevel@tonic-gate 17167c478bd9Sstevel@tonic-gate void 17177c478bd9Sstevel@tonic-gate Exit(status) 17187c478bd9Sstevel@tonic-gate { 17197c478bd9Sstevel@tonic-gate /* 17207c478bd9Sstevel@tonic-gate * Clean up message system 17217c478bd9Sstevel@tonic-gate */ 17227c478bd9Sstevel@tonic-gate #ifdef TDEBUG 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 17257c478bd9Sstevel@tonic-gate msg(gettext("pid = %ld exits with status %d\n"), 17267c478bd9Sstevel@tonic-gate (long)getpid(), status); 17277c478bd9Sstevel@tonic-gate #endif /* TDEBUG */ 17287c478bd9Sstevel@tonic-gate exit(status); 17297c478bd9Sstevel@tonic-gate } 17307c478bd9Sstevel@tonic-gate 17317c478bd9Sstevel@tonic-gate static void 17327c478bd9Sstevel@tonic-gate #ifdef __STDC__ 17337c478bd9Sstevel@tonic-gate killall(void) 17347c478bd9Sstevel@tonic-gate #else 17357c478bd9Sstevel@tonic-gate killall() 17367c478bd9Sstevel@tonic-gate #endif 17377c478bd9Sstevel@tonic-gate { 17387c478bd9Sstevel@tonic-gate struct slaves *slavep; 17397c478bd9Sstevel@tonic-gate 17407c478bd9Sstevel@tonic-gate for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) 17417c478bd9Sstevel@tonic-gate if (slavep->sl_slavepid > 0) { 17427c478bd9Sstevel@tonic-gate (void) kill(slavep->sl_slavepid, SIGKILL); 17437c478bd9Sstevel@tonic-gate #ifdef TDEBUG 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 17467c478bd9Sstevel@tonic-gate msg(gettext("Slave child %ld killed\n"), 17477c478bd9Sstevel@tonic-gate (long)slavep->sl_slavepid); 17487c478bd9Sstevel@tonic-gate #endif 17497c478bd9Sstevel@tonic-gate } 17507c478bd9Sstevel@tonic-gate if (writepid) { 17517c478bd9Sstevel@tonic-gate (void) kill(writepid, SIGKILL); 17527c478bd9Sstevel@tonic-gate #ifdef TDEBUG 17537c478bd9Sstevel@tonic-gate 17547c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 17557c478bd9Sstevel@tonic-gate msg(gettext("Writer child %ld killed\n"), (long)writepid); 17567c478bd9Sstevel@tonic-gate #endif 17577c478bd9Sstevel@tonic-gate } 17587c478bd9Sstevel@tonic-gate if (archivepid) { 17597c478bd9Sstevel@tonic-gate (void) kill(archivepid, SIGKILL); 17607c478bd9Sstevel@tonic-gate #ifdef TDEBUG 17617c478bd9Sstevel@tonic-gate 17627c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 17637c478bd9Sstevel@tonic-gate msg(gettext("Archiver child %ld killed\n"), (long)archivepid); 17647c478bd9Sstevel@tonic-gate #endif 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate } 17677c478bd9Sstevel@tonic-gate 17687c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17697c478bd9Sstevel@tonic-gate static void 1770*fe0e7ec4Smaheshvs proceed(int sig) 17717c478bd9Sstevel@tonic-gate { 17727c478bd9Sstevel@tonic-gate caught++; 17737c478bd9Sstevel@tonic-gate } 17747c478bd9Sstevel@tonic-gate 17757c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17767c478bd9Sstevel@tonic-gate static void 1777*fe0e7ec4Smaheshvs die(int sig) 17787c478bd9Sstevel@tonic-gate { 17797c478bd9Sstevel@tonic-gate Exit(X_FINOK); 17807c478bd9Sstevel@tonic-gate } 17817c478bd9Sstevel@tonic-gate 17827c478bd9Sstevel@tonic-gate static void 17837c478bd9Sstevel@tonic-gate #ifdef __STDC__ 17847c478bd9Sstevel@tonic-gate enslave(void) 17857c478bd9Sstevel@tonic-gate #else 17867c478bd9Sstevel@tonic-gate enslave() 17877c478bd9Sstevel@tonic-gate #endif 17887c478bd9Sstevel@tonic-gate { 17897c478bd9Sstevel@tonic-gate int cmd[2]; /* file descriptors */ 17907c478bd9Sstevel@tonic-gate int i; 17917c478bd9Sstevel@tonic-gate struct sigvec sv; 17927c478bd9Sstevel@tonic-gate struct slaves *slavep; 17937c478bd9Sstevel@tonic-gate int saverr; 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate sv.sv_flags = SA_RESTART; 17967c478bd9Sstevel@tonic-gate (void) sigemptyset(&sv.sa_mask); 17977c478bd9Sstevel@tonic-gate master = getpid(); 17987c478bd9Sstevel@tonic-gate /* 17997c478bd9Sstevel@tonic-gate * slave sends SIGTERM on dumpabort 18007c478bd9Sstevel@tonic-gate */ 18017c478bd9Sstevel@tonic-gate sv.sv_handler = (void(*)(int))dumpabort; 18027c478bd9Sstevel@tonic-gate (void) sigvec(SIGTERM, &sv, (struct sigvec *)0); 18037c478bd9Sstevel@tonic-gate sv.sv_handler = tperror; 18047c478bd9Sstevel@tonic-gate (void) sigvec(SIGUSR2, &sv, (struct sigvec *)0); 18057c478bd9Sstevel@tonic-gate sv.sv_handler = proceed; 18067c478bd9Sstevel@tonic-gate (void) sigvec(SIGUSR1, &sv, (struct sigvec *)0); 18077c478bd9Sstevel@tonic-gate totalrecsout += recsout; 18087c478bd9Sstevel@tonic-gate caught = 0; 18097c478bd9Sstevel@tonic-gate recsout = 0; 18107c478bd9Sstevel@tonic-gate rotor = 0; 18117c478bd9Sstevel@tonic-gate bufclear(); 18127c478bd9Sstevel@tonic-gate for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) 18137c478bd9Sstevel@tonic-gate slavep->sl_slavefd = -1; 18147c478bd9Sstevel@tonic-gate archivefd = arch = writer = -1; 18157c478bd9Sstevel@tonic-gate for (i = 0; i < SLAVES; i++) { 18167c478bd9Sstevel@tonic-gate if (pipe(cmd) < 0) { 18177c478bd9Sstevel@tonic-gate saverr = errno; 18187c478bd9Sstevel@tonic-gate msg(gettext( 18197c478bd9Sstevel@tonic-gate "Cannot create pipe for slave process: %s\n"), 18207c478bd9Sstevel@tonic-gate strerror(saverr)); 18217c478bd9Sstevel@tonic-gate dumpabort(); 18227c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 18237c478bd9Sstevel@tonic-gate } 18247c478bd9Sstevel@tonic-gate sighold(SIGUSR2); 18257c478bd9Sstevel@tonic-gate sighold(SIGINT); 18267c478bd9Sstevel@tonic-gate sighold(SIGTERM); 18277c478bd9Sstevel@tonic-gate if ((slaves[i].sl_slavepid = fork()) < 0) { 18287c478bd9Sstevel@tonic-gate saverr = errno; 18297c478bd9Sstevel@tonic-gate msg(gettext("Cannot create slave process: %s\n"), 18307c478bd9Sstevel@tonic-gate strerror(saverr)); 18317c478bd9Sstevel@tonic-gate dumpabort(); 18327c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 18337c478bd9Sstevel@tonic-gate } 18347c478bd9Sstevel@tonic-gate slaves[i].sl_slavefd = cmd[1]; 18357c478bd9Sstevel@tonic-gate if (slaves[i].sl_slavepid == 0) { /* Slave starts up here */ 18367c478bd9Sstevel@tonic-gate pid_t next; /* pid of neighbor */ 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate sv.sv_handler = SIG_DFL; 18397c478bd9Sstevel@tonic-gate (void) sigvec(SIGUSR2, &sv, (struct sigvec *)0); 18407c478bd9Sstevel@tonic-gate sv.sv_handler = SIG_IGN; /* master handler INT */ 18417c478bd9Sstevel@tonic-gate (void) sigvec(SIGINT, &sv, (struct sigvec *)0); 18427c478bd9Sstevel@tonic-gate sv.sv_handler = die; /* normal slave exit */ 18437c478bd9Sstevel@tonic-gate (void) sigvec(SIGTERM, &sv, (struct sigvec *)0); 18447c478bd9Sstevel@tonic-gate 18457c478bd9Sstevel@tonic-gate child_chdir(); 18467c478bd9Sstevel@tonic-gate sigrelse(SIGUSR2); 18477c478bd9Sstevel@tonic-gate sigrelse(SIGINT); 18487c478bd9Sstevel@tonic-gate sigrelse(SIGTERM); 18497c478bd9Sstevel@tonic-gate 18507c478bd9Sstevel@tonic-gate freeino(); /* release unneeded resources */ 18517c478bd9Sstevel@tonic-gate #ifdef TDEBUG 18527c478bd9Sstevel@tonic-gate (void) sleep(4); /* time for parent's message to get out */ 18537c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 18547c478bd9Sstevel@tonic-gate msg(gettext("Neighbor has pid = %ld\n"), (long)getpid()); 18557c478bd9Sstevel@tonic-gate #endif 18567c478bd9Sstevel@tonic-gate /* Closes cmd[1] as a side-effect */ 18577c478bd9Sstevel@tonic-gate for (slavep = &slaves[0]; 18587c478bd9Sstevel@tonic-gate slavep < &slaves[SLAVES]; 18597c478bd9Sstevel@tonic-gate slavep++) 18607c478bd9Sstevel@tonic-gate if (slavep->sl_slavefd >= 0) { 18617c478bd9Sstevel@tonic-gate (void) close(slavep->sl_slavefd); 18627c478bd9Sstevel@tonic-gate slavep->sl_slavefd = -1; 18637c478bd9Sstevel@tonic-gate } 18647c478bd9Sstevel@tonic-gate (void) close(to); 18657c478bd9Sstevel@tonic-gate (void) close(fi); /* Need our own seek ptr */ 18667c478bd9Sstevel@tonic-gate to = -1; 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate fi = open(disk, O_RDONLY); 18697c478bd9Sstevel@tonic-gate 18707c478bd9Sstevel@tonic-gate if (fi < 0) { 18717c478bd9Sstevel@tonic-gate saverr = errno; 18727c478bd9Sstevel@tonic-gate msg(gettext( 18737c478bd9Sstevel@tonic-gate "Cannot open dump device `%s': %s\n"), 18747c478bd9Sstevel@tonic-gate disk, strerror(saverr)); 18757c478bd9Sstevel@tonic-gate dumpabort(); 18767c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 18777c478bd9Sstevel@tonic-gate } 18787c478bd9Sstevel@tonic-gate 18797c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())read, cmd[0], 18807c478bd9Sstevel@tonic-gate (char *)&next, sizeof (next)) != sizeof (next)) { 18817c478bd9Sstevel@tonic-gate cmdrderr(); 18827c478bd9Sstevel@tonic-gate dumpabort(); 18837c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 18847c478bd9Sstevel@tonic-gate } 18857c478bd9Sstevel@tonic-gate dumpoffline(cmd[0], next, i); 18867c478bd9Sstevel@tonic-gate Exit(X_FINOK); 18877c478bd9Sstevel@tonic-gate } 18887c478bd9Sstevel@tonic-gate /* Parent continues here */ 18897c478bd9Sstevel@tonic-gate sigrelse(SIGUSR2); 18907c478bd9Sstevel@tonic-gate sigrelse(SIGINT); 18917c478bd9Sstevel@tonic-gate sigrelse(SIGTERM); 18927c478bd9Sstevel@tonic-gate (void) close(cmd[0]); 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate if (archive) { 18967c478bd9Sstevel@tonic-gate archivepid = setuparchive(); 18977c478bd9Sstevel@tonic-gate if (!archivepid) { 18987c478bd9Sstevel@tonic-gate dumpabort(); 18997c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 19007c478bd9Sstevel@tonic-gate } 19017c478bd9Sstevel@tonic-gate } 19027c478bd9Sstevel@tonic-gate 19037c478bd9Sstevel@tonic-gate writepid = setupwriter(); 19047c478bd9Sstevel@tonic-gate if (!writepid) { 19057c478bd9Sstevel@tonic-gate dumpabort(); 19067c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 19077c478bd9Sstevel@tonic-gate } 19087c478bd9Sstevel@tonic-gate 19097c478bd9Sstevel@tonic-gate if (arch >= 0) { 19107c478bd9Sstevel@tonic-gate (void) close(arch); /* only writer has this open */ 19117c478bd9Sstevel@tonic-gate arch = -1; 19127c478bd9Sstevel@tonic-gate } 19137c478bd9Sstevel@tonic-gate 19147c478bd9Sstevel@tonic-gate /* Tell each slave who follows it */ 19157c478bd9Sstevel@tonic-gate for (i = 0; i < SLAVES; i++) { 19167c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())write, slaves[i].sl_slavefd, 19177c478bd9Sstevel@tonic-gate (char *)&(slaves[(i + 1) % SLAVES].sl_slavepid), 19187c478bd9Sstevel@tonic-gate sizeof (int)) != sizeof (int)) { 19197c478bd9Sstevel@tonic-gate cmdwrterr(); 19207c478bd9Sstevel@tonic-gate dumpabort(); 19217c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 19227c478bd9Sstevel@tonic-gate } 19237c478bd9Sstevel@tonic-gate } 19247c478bd9Sstevel@tonic-gate sv.sv_handler = rollforward; /* rcvd from writer on EOT */ 19257c478bd9Sstevel@tonic-gate (void) sigvec(SIGUSR1, &sv, (struct sigvec *)0); 19267c478bd9Sstevel@tonic-gate slp = slaves; 19277c478bd9Sstevel@tonic-gate (void) kill(slp->sl_slavepid, SIGUSR1); 19287c478bd9Sstevel@tonic-gate master = 0; 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate static void 19327c478bd9Sstevel@tonic-gate #ifdef __STDC__ 19337c478bd9Sstevel@tonic-gate wait_our_turn(void) 19347c478bd9Sstevel@tonic-gate #else 19357c478bd9Sstevel@tonic-gate wait_our_turn() 19367c478bd9Sstevel@tonic-gate #endif 19377c478bd9Sstevel@tonic-gate { 19387c478bd9Sstevel@tonic-gate (void) sighold(SIGUSR1); 19397c478bd9Sstevel@tonic-gate 19407c478bd9Sstevel@tonic-gate if (!caught) { 19417c478bd9Sstevel@tonic-gate #ifdef INSTRUMENT 19427c478bd9Sstevel@tonic-gate (*idle)++; 19437c478bd9Sstevel@tonic-gate #endif 19447c478bd9Sstevel@tonic-gate (void) sigpause(SIGUSR1); 19457c478bd9Sstevel@tonic-gate } 19467c478bd9Sstevel@tonic-gate caught = 0; 19477c478bd9Sstevel@tonic-gate (void) sigrelse(SIGUSR1); 19487c478bd9Sstevel@tonic-gate } 19497c478bd9Sstevel@tonic-gate 19507c478bd9Sstevel@tonic-gate static void 1951*fe0e7ec4Smaheshvs dumpoffline(int cmd, pid_t next, int mynum) 19527c478bd9Sstevel@tonic-gate { 19537c478bd9Sstevel@tonic-gate struct req *p = slaves[mynum].sl_req; 19547c478bd9Sstevel@tonic-gate ulong_t i; 19557c478bd9Sstevel@tonic-gate uchar_t *cp; 19567c478bd9Sstevel@tonic-gate uchar_t *blkbuf; 19577c478bd9Sstevel@tonic-gate int notactive = 0; 19587c478bd9Sstevel@tonic-gate 19597c478bd9Sstevel@tonic-gate blkbuf = xmalloc(sblock->fs_bsize); 19607c478bd9Sstevel@tonic-gate 19617c478bd9Sstevel@tonic-gate /*CONSTANTCONDITION*/ 19627c478bd9Sstevel@tonic-gate assert(sizeof (spcl) == TP_BSIZE_MIN); 19637c478bd9Sstevel@tonic-gate 19647c478bd9Sstevel@tonic-gate while (atomic((int(*)())read, cmd, (char *)p, reqsiz) == reqsiz) { 19657c478bd9Sstevel@tonic-gate if (p->br_dblk) { 19667c478bd9Sstevel@tonic-gate bread(p->br_dblk, (uchar_t *)blkbuf, p->br_size); 19677c478bd9Sstevel@tonic-gate } else { 19687c478bd9Sstevel@tonic-gate bcopy((char *)p->br_spcl, (char *)&spcl, 19697c478bd9Sstevel@tonic-gate sizeof (spcl)); 19707c478bd9Sstevel@tonic-gate ino = spcl.c_inumber; 19717c478bd9Sstevel@tonic-gate } 19727c478bd9Sstevel@tonic-gate dumptoarchive = p->aflag & BUF_ARCHIVE; 19737c478bd9Sstevel@tonic-gate wait_our_turn(); 19747c478bd9Sstevel@tonic-gate if (p->br_dblk) { 19757c478bd9Sstevel@tonic-gate for (i = p->br_size, cp = blkbuf; 19767c478bd9Sstevel@tonic-gate i > 0; 19777c478bd9Sstevel@tonic-gate /* LINTED character pointers aren't signed */ 19787c478bd9Sstevel@tonic-gate cp += i > tp_bsize ? tp_bsize : i, 19797c478bd9Sstevel@tonic-gate i -= i > tp_bsize ? tp_bsize : i) { 19807c478bd9Sstevel@tonic-gate /* LINTED unsigned to signed conversion ok */ 19817c478bd9Sstevel@tonic-gate taprec(cp, 0, i > tp_bsize ? tp_bsize : (int)i); 19827c478bd9Sstevel@tonic-gate } 19837c478bd9Sstevel@tonic-gate } else 19847c478bd9Sstevel@tonic-gate spclrec(); 19857c478bd9Sstevel@tonic-gate (void) kill(next, SIGUSR1); /* Next slave's turn */ 19867c478bd9Sstevel@tonic-gate /* 19877c478bd9Sstevel@tonic-gate * Note that we lie about file activity since we don't 19887c478bd9Sstevel@tonic-gate * check for it. 19897c478bd9Sstevel@tonic-gate */ 19907c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())write, cmd, (char *)¬active, 19917c478bd9Sstevel@tonic-gate sizeof (notactive)) != sizeof (notactive)) { 19927c478bd9Sstevel@tonic-gate cmdwrterr(); 19937c478bd9Sstevel@tonic-gate dumpabort(); 19947c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 19957c478bd9Sstevel@tonic-gate } 19967c478bd9Sstevel@tonic-gate } 19977c478bd9Sstevel@tonic-gate 19987c478bd9Sstevel@tonic-gate free(blkbuf); 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate static int count; /* tape blocks written since last spclrec */ 20027c478bd9Sstevel@tonic-gate 20037c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 20047c478bd9Sstevel@tonic-gate static void 2005*fe0e7ec4Smaheshvs onxfsz(int sig) 20067c478bd9Sstevel@tonic-gate { 20077c478bd9Sstevel@tonic-gate msg(gettext("File size limit exceeded writing output volume %d\n"), 20087c478bd9Sstevel@tonic-gate tapeno); 20097c478bd9Sstevel@tonic-gate (void) kill(master, SIGUSR2); 20107c478bd9Sstevel@tonic-gate Exit(X_REWRITE); 20117c478bd9Sstevel@tonic-gate } 20127c478bd9Sstevel@tonic-gate 20137c478bd9Sstevel@tonic-gate static long lastnonaddr; /* last DS_{INODE,CLRI,BITS} written */ 20147c478bd9Sstevel@tonic-gate static long lastnonaddrm; /* and the mode thereof */ 20157c478bd9Sstevel@tonic-gate /* 20167c478bd9Sstevel@tonic-gate * dowrite -- the main body of the output writer process 20177c478bd9Sstevel@tonic-gate */ 20187c478bd9Sstevel@tonic-gate static void 2019*fe0e7ec4Smaheshvs dowrite(int cmd) 20207c478bd9Sstevel@tonic-gate { 20217c478bd9Sstevel@tonic-gate struct bdesc *last = 20227c478bd9Sstevel@tonic-gate &bufp[(NBUF*ntrec)-1]; /* last buffer in pool */ 20237c478bd9Sstevel@tonic-gate struct bdesc *bp = bufp; /* current buf in tape block */ 20247c478bd9Sstevel@tonic-gate struct bdesc *begin = bufp; /* first buf of tape block */ 20257c478bd9Sstevel@tonic-gate struct bdesc *end = bufp + (ntrec-1); /* last buf of tape block */ 20267c478bd9Sstevel@tonic-gate int siz; /* bytes written (block) */ 20277c478bd9Sstevel@tonic-gate int trecs; /* records written (block) */ 20287c478bd9Sstevel@tonic-gate long asize = 0; /* number of 0.1" units... */ 20297c478bd9Sstevel@tonic-gate /* ...written on current tape */ 20307c478bd9Sstevel@tonic-gate char *tp, *rbuf = NULL; 20317c478bd9Sstevel@tonic-gate char *recmap = spcl.c_addr; /* current tape record map */ 20327c478bd9Sstevel@tonic-gate char *endmp; /* end of valid map data */ 20337c478bd9Sstevel@tonic-gate char *mp; /* current map entry */ 20347c478bd9Sstevel@tonic-gate union u_spcl *sp; 20357c478bd9Sstevel@tonic-gate 20367c478bd9Sstevel@tonic-gate (void) signal(SIGXFSZ, onxfsz); 20377c478bd9Sstevel@tonic-gate 20387c478bd9Sstevel@tonic-gate bzero((char *)&spcl, sizeof (spcl)); 20397c478bd9Sstevel@tonic-gate count = 0; 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate if (doingverify) { 20427c478bd9Sstevel@tonic-gate rbuf = (char *)malloc((uint_t)writesize); 20437c478bd9Sstevel@tonic-gate if (rbuf == 0) { 20447c478bd9Sstevel@tonic-gate /* Restart from checkpoint */ 20457c478bd9Sstevel@tonic-gate (void) kill(master, SIGUSR2); 20467c478bd9Sstevel@tonic-gate Exit(X_REWRITE); 20477c478bd9Sstevel@tonic-gate } 20487c478bd9Sstevel@tonic-gate } 20497c478bd9Sstevel@tonic-gate 20507c478bd9Sstevel@tonic-gate for (;;) { 20517c478bd9Sstevel@tonic-gate /* START: wait until all buffers in tape block are full */ 20527c478bd9Sstevel@tonic-gate if ((bp->b_flags & BUF_FULL) == 0) { 20537c478bd9Sstevel@tonic-gate if (caught) { /* master signalled flush */ 20547c478bd9Sstevel@tonic-gate (void) sighold(SIGUSR1); 20557c478bd9Sstevel@tonic-gate caught = 0; 20567c478bd9Sstevel@tonic-gate /* signal ready */ 20577c478bd9Sstevel@tonic-gate (void) kill(master, SIGUSR1); 20587c478bd9Sstevel@tonic-gate chkpt.sl_count = 0; /* signal not at EOT */ 20597c478bd9Sstevel@tonic-gate checkpoint(bp-1, cmd); /* send data */ 20607c478bd9Sstevel@tonic-gate (void) sigpause(SIGUSR1); 20617c478bd9Sstevel@tonic-gate break; 20627c478bd9Sstevel@tonic-gate } 20637c478bd9Sstevel@tonic-gate #ifdef INSTRUMENT 20647c478bd9Sstevel@tonic-gate (*readmissp)++; 20657c478bd9Sstevel@tonic-gate #endif 20667c478bd9Sstevel@tonic-gate nap(50); 20677c478bd9Sstevel@tonic-gate continue; 20687c478bd9Sstevel@tonic-gate } 20697c478bd9Sstevel@tonic-gate if (bp < end) { 20707c478bd9Sstevel@tonic-gate bp++; 20717c478bd9Sstevel@tonic-gate continue; 20727c478bd9Sstevel@tonic-gate } 20737c478bd9Sstevel@tonic-gate /* END: wait until all buffers in tape block are full */ 20747c478bd9Sstevel@tonic-gate 20757c478bd9Sstevel@tonic-gate tp = begin->b_data; 20767c478bd9Sstevel@tonic-gate (void) sighold(SIGUSR1); 20777c478bd9Sstevel@tonic-gate if (host) { 20787c478bd9Sstevel@tonic-gate if (!doingverify) 20797c478bd9Sstevel@tonic-gate siz = rmtwrite(tp, writesize); 20807c478bd9Sstevel@tonic-gate else if ((siz = rmtread(rbuf, writesize)) == 20817c478bd9Sstevel@tonic-gate writesize && bcmp(rbuf, tp, writesize)) 20827c478bd9Sstevel@tonic-gate siz = -1; 20837c478bd9Sstevel@tonic-gate } else { 20847c478bd9Sstevel@tonic-gate if (!doingverify) 20857c478bd9Sstevel@tonic-gate siz = write(to, tp, writesize); 20867c478bd9Sstevel@tonic-gate else if ((siz = read(to, rbuf, writesize)) == 20877c478bd9Sstevel@tonic-gate writesize && bcmp(rbuf, tp, writesize)) 20887c478bd9Sstevel@tonic-gate siz = -1; 20897c478bd9Sstevel@tonic-gate if (siz < 0 && diskette && errno == ENOSPC) 20907c478bd9Sstevel@tonic-gate siz = 0; /* really EOF */ 20917c478bd9Sstevel@tonic-gate } 20927c478bd9Sstevel@tonic-gate (void) sigrelse(SIGUSR1); 20937c478bd9Sstevel@tonic-gate if (siz < 0 || 20947c478bd9Sstevel@tonic-gate (pipeout && siz != writesize)) { 20957c478bd9Sstevel@tonic-gate char buf[3000]; 20967c478bd9Sstevel@tonic-gate 20977c478bd9Sstevel@tonic-gate /* 20987c478bd9Sstevel@tonic-gate * Isn't i18n wonderful? 20997c478bd9Sstevel@tonic-gate */ 21007c478bd9Sstevel@tonic-gate if (doingverify) { 21017c478bd9Sstevel@tonic-gate if (diskette) 21027c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 21037c478bd9Sstevel@tonic-gate gettext( 21047c478bd9Sstevel@tonic-gate "Verification error %ld blocks into diskette %d\n"), 21057c478bd9Sstevel@tonic-gate asize * 2, tapeno); 21067c478bd9Sstevel@tonic-gate else if (tapeout) 21077c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 21087c478bd9Sstevel@tonic-gate gettext( 21097c478bd9Sstevel@tonic-gate "Verification error %ld feet into tape %d\n"), 21107c478bd9Sstevel@tonic-gate (cartridge ? asize/tracks : 21117c478bd9Sstevel@tonic-gate asize)/120L, 21127c478bd9Sstevel@tonic-gate tapeno); 21137c478bd9Sstevel@tonic-gate else 21147c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 21157c478bd9Sstevel@tonic-gate gettext( 21167c478bd9Sstevel@tonic-gate "Verification error %ld blocks into volume %d\n"), 21177c478bd9Sstevel@tonic-gate asize * 2, tapeno); 21187c478bd9Sstevel@tonic-gate 21197c478bd9Sstevel@tonic-gate } else { 21207c478bd9Sstevel@tonic-gate if (diskette) 21217c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 21227c478bd9Sstevel@tonic-gate gettext( 21237c478bd9Sstevel@tonic-gate "Write error %ld blocks into diskette %d\n"), 21247c478bd9Sstevel@tonic-gate asize * 2, tapeno); 21257c478bd9Sstevel@tonic-gate else if (tapeout) 21267c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 21277c478bd9Sstevel@tonic-gate gettext( 21287c478bd9Sstevel@tonic-gate "Write error %ld feet into tape %d\n"), 21297c478bd9Sstevel@tonic-gate (cartridge ? asize/tracks : 21307c478bd9Sstevel@tonic-gate asize)/120L, tapeno); 21317c478bd9Sstevel@tonic-gate else 21327c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 21337c478bd9Sstevel@tonic-gate gettext( 21347c478bd9Sstevel@tonic-gate "Write error %ld blocks into volume %d\n"), 21357c478bd9Sstevel@tonic-gate asize * 2, tapeno); 21367c478bd9Sstevel@tonic-gate } 21377c478bd9Sstevel@tonic-gate 21387c478bd9Sstevel@tonic-gate msg(buf); 21397c478bd9Sstevel@tonic-gate /* Restart from checkpoint */ 21407c478bd9Sstevel@tonic-gate #ifdef TDEBUG 21417c478bd9Sstevel@tonic-gate 21427c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef TDEBUG only */ 21437c478bd9Sstevel@tonic-gate msg(gettext("sending SIGUSR2 to pid %ld\n"), master); 21447c478bd9Sstevel@tonic-gate #endif 21457c478bd9Sstevel@tonic-gate (void) kill(master, SIGUSR2); 21467c478bd9Sstevel@tonic-gate Exit(X_REWRITE); 21477c478bd9Sstevel@tonic-gate } 21487c478bd9Sstevel@tonic-gate trecs = siz / tp_bsize; 21497c478bd9Sstevel@tonic-gate if (diskette) 21507c478bd9Sstevel@tonic-gate asize += trecs; /* asize == blocks written */ 21517c478bd9Sstevel@tonic-gate else 21527c478bd9Sstevel@tonic-gate asize += (siz/density + tenthsperirg); 21537c478bd9Sstevel@tonic-gate if (trecs) 21547c478bd9Sstevel@tonic-gate chkpt.sl_firstrec++; 21557c478bd9Sstevel@tonic-gate for (bp = begin; bp < begin + trecs; bp++) { 21567c478bd9Sstevel@tonic-gate if ((arch >= 0) && (bp->b_flags & BUF_ARCHIVE)) { 21577c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())write, arch, 21587c478bd9Sstevel@tonic-gate (char *)&bp->b_flags, sizeof (bp->b_flags)) 21597c478bd9Sstevel@tonic-gate != sizeof (bp->b_flags)) { 21607c478bd9Sstevel@tonic-gate cmdwrterr(); 21617c478bd9Sstevel@tonic-gate dumpabort(); 21627c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 21637c478bd9Sstevel@tonic-gate } 21647c478bd9Sstevel@tonic-gate if (atomic((int(*)())write, arch, bp->b_data, 21657c478bd9Sstevel@tonic-gate tp_bsize) != tp_bsize) { 21667c478bd9Sstevel@tonic-gate cmdwrterr(); 21677c478bd9Sstevel@tonic-gate dumpabort(); 21687c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 21697c478bd9Sstevel@tonic-gate } 21707c478bd9Sstevel@tonic-gate } 21717c478bd9Sstevel@tonic-gate if (bp->b_flags & BUF_SPCLREC) { 21727c478bd9Sstevel@tonic-gate /*LINTED [bp->b_data is aligned]*/ 21737c478bd9Sstevel@tonic-gate sp = (union u_spcl *)bp->b_data; 21747c478bd9Sstevel@tonic-gate if (sp->s_spcl.c_type != TS_ADDR) { 21757c478bd9Sstevel@tonic-gate lastnonaddr = sp->s_spcl.c_type; 21767c478bd9Sstevel@tonic-gate lastnonaddrm = 21777c478bd9Sstevel@tonic-gate sp->s_spcl.c_dinode.di_mode; 21787c478bd9Sstevel@tonic-gate if (sp->s_spcl.c_type != TS_TAPE) 21797c478bd9Sstevel@tonic-gate chkpt.sl_offset = 0; 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate chkpt.sl_count = sp->s_spcl.c_count; 21827c478bd9Sstevel@tonic-gate bcopy((char *)sp, 21837c478bd9Sstevel@tonic-gate (char *)&spcl, sizeof (spcl)); 21847c478bd9Sstevel@tonic-gate mp = recmap; 21857c478bd9Sstevel@tonic-gate endmp = &recmap[spcl.c_count]; 21867c478bd9Sstevel@tonic-gate count = 0; 21877c478bd9Sstevel@tonic-gate } else { 21887c478bd9Sstevel@tonic-gate chkpt.sl_offset++; 21897c478bd9Sstevel@tonic-gate chkpt.sl_count--; 21907c478bd9Sstevel@tonic-gate count++; 21917c478bd9Sstevel@tonic-gate mp++; 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate /* 21947c478bd9Sstevel@tonic-gate * Adjust for contiguous hole 21957c478bd9Sstevel@tonic-gate */ 21967c478bd9Sstevel@tonic-gate for (; mp < endmp; mp++) { 21977c478bd9Sstevel@tonic-gate if (*mp) 21987c478bd9Sstevel@tonic-gate break; 21997c478bd9Sstevel@tonic-gate chkpt.sl_offset++; 22007c478bd9Sstevel@tonic-gate chkpt.sl_count--; 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate } 22037c478bd9Sstevel@tonic-gate /* 22047c478bd9Sstevel@tonic-gate * Check for end of tape 22057c478bd9Sstevel@tonic-gate */ 22067c478bd9Sstevel@tonic-gate if (trecs < ntrec || 22077c478bd9Sstevel@tonic-gate (!pipeout && tsize > 0 && asize > tsize)) { 22087c478bd9Sstevel@tonic-gate if (tapeout) 22097c478bd9Sstevel@tonic-gate msg(gettext("End-of-tape detected\n")); 22107c478bd9Sstevel@tonic-gate else 22117c478bd9Sstevel@tonic-gate msg(gettext("End-of-file detected\n")); 22127c478bd9Sstevel@tonic-gate (void) sighold(SIGUSR1); 22137c478bd9Sstevel@tonic-gate caught = 0; 22147c478bd9Sstevel@tonic-gate (void) kill(master, SIGUSR1); /* signal EOT */ 22157c478bd9Sstevel@tonic-gate checkpoint(--bp, cmd); /* send checkpoint data */ 22167c478bd9Sstevel@tonic-gate (void) sigpause(SIGUSR1); 22177c478bd9Sstevel@tonic-gate break; 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate for (bp = begin; bp <= end; bp++) 22207c478bd9Sstevel@tonic-gate bp->b_flags = BUF_EMPTY; 22217c478bd9Sstevel@tonic-gate if (end + ntrec > last) { 22227c478bd9Sstevel@tonic-gate bp = begin = bufp; 22237c478bd9Sstevel@tonic-gate timeest(0, spcl.c_tapea); 22247c478bd9Sstevel@tonic-gate } else 22257c478bd9Sstevel@tonic-gate bp = begin = end+1; 22267c478bd9Sstevel@tonic-gate end = begin + (ntrec-1); 22277c478bd9Sstevel@tonic-gate } 22287c478bd9Sstevel@tonic-gate 22297c478bd9Sstevel@tonic-gate if (rbuf != NULL) 22307c478bd9Sstevel@tonic-gate free(rbuf); 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate 22337c478bd9Sstevel@tonic-gate /* 22347c478bd9Sstevel@tonic-gate * Send checkpoint info back to master. This information 22357c478bd9Sstevel@tonic-gate * consists of the current inode number, number of logical 22367c478bd9Sstevel@tonic-gate * blocks written for that inode (or bitmap), the last logical 22377c478bd9Sstevel@tonic-gate * block number written, the number of logical blocks written 22387c478bd9Sstevel@tonic-gate * to this volume, the current dump state, and the current 22397c478bd9Sstevel@tonic-gate * special record map. 22407c478bd9Sstevel@tonic-gate */ 22417c478bd9Sstevel@tonic-gate static void 2242*fe0e7ec4Smaheshvs checkpoint(struct bdesc *bp, int cmd) 22437c478bd9Sstevel@tonic-gate { 22447c478bd9Sstevel@tonic-gate int state, type; 22457c478bd9Sstevel@tonic-gate ino_t ino; 22467c478bd9Sstevel@tonic-gate 22477c478bd9Sstevel@tonic-gate if (++bp >= &bufp[NBUF*ntrec]) 22487c478bd9Sstevel@tonic-gate bp = bufp; 22497c478bd9Sstevel@tonic-gate 22507c478bd9Sstevel@tonic-gate /* 22517c478bd9Sstevel@tonic-gate * If we are dumping files and the record following 22527c478bd9Sstevel@tonic-gate * the last written to tape is a special record, use 22537c478bd9Sstevel@tonic-gate * it to get an accurate indication of current state. 22547c478bd9Sstevel@tonic-gate */ 22557c478bd9Sstevel@tonic-gate if ((bp->b_flags & BUF_SPCLREC) && (bp->b_flags & BUF_FULL) && 22567c478bd9Sstevel@tonic-gate lastnonaddr == TS_INODE) { 22577c478bd9Sstevel@tonic-gate /*LINTED [bp->b_data is aligned]*/ 22587c478bd9Sstevel@tonic-gate union u_spcl *nextspcl = (union u_spcl *)bp->b_data; 22597c478bd9Sstevel@tonic-gate 22607c478bd9Sstevel@tonic-gate if (nextspcl->s_spcl.c_type == TS_INODE) { 22617c478bd9Sstevel@tonic-gate chkpt.sl_offset = 0; 22627c478bd9Sstevel@tonic-gate chkpt.sl_count = 0; 22637c478bd9Sstevel@tonic-gate } else if (nextspcl->s_spcl.c_type == TS_END) { 22647c478bd9Sstevel@tonic-gate chkpt.sl_offset = 0; 22657c478bd9Sstevel@tonic-gate chkpt.sl_count = 1; /* EOT indicator */ 22667c478bd9Sstevel@tonic-gate } 22677c478bd9Sstevel@tonic-gate ino = nextspcl->s_spcl.c_inumber; 22687c478bd9Sstevel@tonic-gate type = nextspcl->s_spcl.c_type; 22697c478bd9Sstevel@tonic-gate } else { 22707c478bd9Sstevel@tonic-gate /* 22717c478bd9Sstevel@tonic-gate * If not, use what we have. 22727c478bd9Sstevel@tonic-gate */ 22737c478bd9Sstevel@tonic-gate ino = spcl.c_inumber; 22747c478bd9Sstevel@tonic-gate type = spcl.c_type; 22757c478bd9Sstevel@tonic-gate } 22767c478bd9Sstevel@tonic-gate 22777c478bd9Sstevel@tonic-gate switch (type) { /* set output state */ 22787c478bd9Sstevel@tonic-gate case TS_ADDR: 22797c478bd9Sstevel@tonic-gate switch (lastnonaddr) { 22807c478bd9Sstevel@tonic-gate case TS_INODE: 22817c478bd9Sstevel@tonic-gate case TS_TAPE: 22827c478bd9Sstevel@tonic-gate if ((lastnonaddrm & IFMT) == IFDIR || 22837c478bd9Sstevel@tonic-gate (lastnonaddrm & IFMT) == IFATTRDIR) 22847c478bd9Sstevel@tonic-gate state = DS_DIRS; 22857c478bd9Sstevel@tonic-gate else 22867c478bd9Sstevel@tonic-gate state = DS_FILES; 22877c478bd9Sstevel@tonic-gate break; 22887c478bd9Sstevel@tonic-gate case TS_CLRI: 22897c478bd9Sstevel@tonic-gate state = DS_CLRI; 22907c478bd9Sstevel@tonic-gate break; 22917c478bd9Sstevel@tonic-gate case TS_BITS: 22927c478bd9Sstevel@tonic-gate state = DS_BITS; 22937c478bd9Sstevel@tonic-gate break; 22947c478bd9Sstevel@tonic-gate } 22957c478bd9Sstevel@tonic-gate break; 22967c478bd9Sstevel@tonic-gate case TS_INODE: 22977c478bd9Sstevel@tonic-gate if ((spcl.c_dinode.di_mode & IFMT) == IFDIR || 22987c478bd9Sstevel@tonic-gate (spcl.c_dinode.di_mode & IFMT) == IFATTRDIR) 22997c478bd9Sstevel@tonic-gate state = DS_DIRS; 23007c478bd9Sstevel@tonic-gate else 23017c478bd9Sstevel@tonic-gate state = DS_FILES; 23027c478bd9Sstevel@tonic-gate break; 23037c478bd9Sstevel@tonic-gate case 0: /* EOT on 1st record */ 23047c478bd9Sstevel@tonic-gate case TS_TAPE: 23057c478bd9Sstevel@tonic-gate state = DS_START; 23067c478bd9Sstevel@tonic-gate ino = UFSROOTINO; 23077c478bd9Sstevel@tonic-gate break; 23087c478bd9Sstevel@tonic-gate case TS_CLRI: 23097c478bd9Sstevel@tonic-gate state = DS_CLRI; 23107c478bd9Sstevel@tonic-gate break; 23117c478bd9Sstevel@tonic-gate case TS_BITS: 23127c478bd9Sstevel@tonic-gate state = DS_BITS; 23137c478bd9Sstevel@tonic-gate break; 23147c478bd9Sstevel@tonic-gate case TS_END: 23157c478bd9Sstevel@tonic-gate if (spcl.c_type == TS_END) 23167c478bd9Sstevel@tonic-gate state = DS_DONE; 23177c478bd9Sstevel@tonic-gate else 23187c478bd9Sstevel@tonic-gate state = DS_END; 23197c478bd9Sstevel@tonic-gate break; 23207c478bd9Sstevel@tonic-gate } 23217c478bd9Sstevel@tonic-gate 23227c478bd9Sstevel@tonic-gate /* 23237c478bd9Sstevel@tonic-gate * Checkpoint info to be processed by rollforward(): 23247c478bd9Sstevel@tonic-gate * The inode with which the next volume should begin 23257c478bd9Sstevel@tonic-gate * The last inode number on this volume 23267c478bd9Sstevel@tonic-gate * The last logical block number on this volume 23277c478bd9Sstevel@tonic-gate * The current output state 23287c478bd9Sstevel@tonic-gate * The offset within the current inode (already in sl_offset) 23297c478bd9Sstevel@tonic-gate * The number of records left from last spclrec (in sl_count) 23307c478bd9Sstevel@tonic-gate * The physical block the next vol begins with (in sl_firstrec) 23317c478bd9Sstevel@tonic-gate */ 23327c478bd9Sstevel@tonic-gate chkpt.sl_inos = ino; 23337c478bd9Sstevel@tonic-gate chkpt.sl_tapea = spcl.c_tapea + count; 23347c478bd9Sstevel@tonic-gate chkpt.sl_state = state; 23357c478bd9Sstevel@tonic-gate 23367c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())write, cmd, (char *)&chkpt, 23377c478bd9Sstevel@tonic-gate sizeof (chkpt)) != sizeof (chkpt)) { 23387c478bd9Sstevel@tonic-gate cmdwrterr(); 23397c478bd9Sstevel@tonic-gate dumpabort(); 23407c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 23417c478bd9Sstevel@tonic-gate } 23427c478bd9Sstevel@tonic-gate if ((unsigned)atomic((int(*)())write, cmd, (char *)&spcl, 23437c478bd9Sstevel@tonic-gate sizeof (spcl)) != sizeof (spcl)) { 23447c478bd9Sstevel@tonic-gate cmdwrterr(); 23457c478bd9Sstevel@tonic-gate dumpabort(); 23467c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 23477c478bd9Sstevel@tonic-gate } 23487c478bd9Sstevel@tonic-gate #ifdef DEBUG 23497c478bd9Sstevel@tonic-gate if (xflag) { 23507c478bd9Sstevel@tonic-gate /* XGETTEXT: #ifdef DEBUG only */ 23517c478bd9Sstevel@tonic-gate msg(gettext("sent chkpt to master:\n")); 23527c478bd9Sstevel@tonic-gate msg(" ino %u\n", chkpt.sl_inos); 23537c478bd9Sstevel@tonic-gate msg(" 1strec %u\n", chkpt.sl_firstrec); 23547c478bd9Sstevel@tonic-gate msg(" lastrec %u\n", chkpt.sl_tapea); 23557c478bd9Sstevel@tonic-gate msg(" written %u\n", chkpt.sl_offset); 23567c478bd9Sstevel@tonic-gate msg(" left %u\n", chkpt.sl_count); 23577c478bd9Sstevel@tonic-gate msg(" state %d\n", chkpt.sl_state); 23587c478bd9Sstevel@tonic-gate } 23597c478bd9Sstevel@tonic-gate #endif 23607c478bd9Sstevel@tonic-gate } 23617c478bd9Sstevel@tonic-gate 23627c478bd9Sstevel@tonic-gate /* 23637c478bd9Sstevel@tonic-gate * Since a read from a pipe may not return all we asked for, 23647c478bd9Sstevel@tonic-gate * or a write may not write all we ask if we get a signal, 23657c478bd9Sstevel@tonic-gate * loop until the count is satisfied (or error). 23667c478bd9Sstevel@tonic-gate */ 23677c478bd9Sstevel@tonic-gate static ssize_t 2368*fe0e7ec4Smaheshvs atomic(int (*func)(), int fd, char *buf, int count) 23697c478bd9Sstevel@tonic-gate { 23707c478bd9Sstevel@tonic-gate ssize_t got = 0, need = count; 23717c478bd9Sstevel@tonic-gate 23727c478bd9Sstevel@tonic-gate /* don't inherit random value if immediately get zero back from func */ 23737c478bd9Sstevel@tonic-gate errno = 0; 23747c478bd9Sstevel@tonic-gate while (need > 0) { 23757c478bd9Sstevel@tonic-gate got = (*func)(fd, buf, MIN(need, 4096)); 23767c478bd9Sstevel@tonic-gate if (got < 0 && errno == EINTR) 23777c478bd9Sstevel@tonic-gate continue; 23787c478bd9Sstevel@tonic-gate if (got <= 0) 23797c478bd9Sstevel@tonic-gate break; 23807c478bd9Sstevel@tonic-gate buf += got; 23817c478bd9Sstevel@tonic-gate need -= got; 23827c478bd9Sstevel@tonic-gate } 23837c478bd9Sstevel@tonic-gate /* if we got what was asked for, return count, else failure (got) */ 23847c478bd9Sstevel@tonic-gate return ((need != 0) ? got : count); 23857c478bd9Sstevel@tonic-gate } 23867c478bd9Sstevel@tonic-gate 23877c478bd9Sstevel@tonic-gate void 23887c478bd9Sstevel@tonic-gate #ifdef __STDC__ 23897c478bd9Sstevel@tonic-gate positiontape(char *msgbuf) 23907c478bd9Sstevel@tonic-gate #else 2391*fe0e7ec4Smaheshvs positiontape(char *msgbuf) 23927c478bd9Sstevel@tonic-gate #endif 23937c478bd9Sstevel@tonic-gate { 23947c478bd9Sstevel@tonic-gate /* Static as never change, no need to waste stack space */ 23957c478bd9Sstevel@tonic-gate static struct mtget mt; 23967c478bd9Sstevel@tonic-gate static struct mtop rew = { MTREW, 1 }; 23977c478bd9Sstevel@tonic-gate static struct mtop fsf = { MTFSF, 1 }; 23987c478bd9Sstevel@tonic-gate char *info = strdup(gettext("Positioning `%s' to file %ld\n")); 23997c478bd9Sstevel@tonic-gate char *fail = strdup(gettext("Cannot position tape to file %d\n")); 24007c478bd9Sstevel@tonic-gate int m; 24017c478bd9Sstevel@tonic-gate 24027c478bd9Sstevel@tonic-gate /* gettext()'s return value is volatile, hence the strdup()s */ 24037c478bd9Sstevel@tonic-gate 24047c478bd9Sstevel@tonic-gate m = (access(tape, F_OK) == 0) ? 0 : O_CREAT; 24057c478bd9Sstevel@tonic-gate 24067c478bd9Sstevel@tonic-gate /* 24077c478bd9Sstevel@tonic-gate * To avoid writing tape marks at inappropriate places, we open the 24087c478bd9Sstevel@tonic-gate * device read-only, position it, close it, and reopen it for writing. 24097c478bd9Sstevel@tonic-gate */ 24107c478bd9Sstevel@tonic-gate while ((to = host ? rmtopen(tape, O_RDONLY) : 24117c478bd9Sstevel@tonic-gate safe_device_open(tape, O_RDONLY|m, 0600)) < 0) { 24127c478bd9Sstevel@tonic-gate if (autoload) { 24137c478bd9Sstevel@tonic-gate if (!query_once(msgbuf, 1)) { 24147c478bd9Sstevel@tonic-gate dumpabort(); 24157c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24167c478bd9Sstevel@tonic-gate } 24177c478bd9Sstevel@tonic-gate } else { 24187c478bd9Sstevel@tonic-gate if (!query(msgbuf)) { 24197c478bd9Sstevel@tonic-gate dumpabort(); 24207c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24217c478bd9Sstevel@tonic-gate } 24227c478bd9Sstevel@tonic-gate } 24237c478bd9Sstevel@tonic-gate } 24247c478bd9Sstevel@tonic-gate 24257c478bd9Sstevel@tonic-gate if (host) { 24267c478bd9Sstevel@tonic-gate if (rmtstatus(&mt) >= 0 && 24277c478bd9Sstevel@tonic-gate rmtioctl(MTREW, 1) >= 0 && 24287c478bd9Sstevel@tonic-gate filenum > 1) { 24297c478bd9Sstevel@tonic-gate msg(info, dumpdev, filenum); 24307c478bd9Sstevel@tonic-gate if (rmtioctl(MTFSF, filenum-1) < 0) { 24317c478bd9Sstevel@tonic-gate msg(fail, filenum); 24327c478bd9Sstevel@tonic-gate dumpabort(); 24337c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24347c478bd9Sstevel@tonic-gate } 24357c478bd9Sstevel@tonic-gate } 24367c478bd9Sstevel@tonic-gate rmtclose(); 24377c478bd9Sstevel@tonic-gate } else { 24387c478bd9Sstevel@tonic-gate if (ioctl(to, MTIOCGET, &mt) >= 0 && 24397c478bd9Sstevel@tonic-gate ioctl(to, MTIOCTOP, &rew) >= 0 && 24407c478bd9Sstevel@tonic-gate filenum > 1) { 24417c478bd9Sstevel@tonic-gate msg(info, dumpdev, filenum); 24427c478bd9Sstevel@tonic-gate fsf.mt_count = filenum - 1; 24437c478bd9Sstevel@tonic-gate if (ioctl(to, MTIOCTOP, &fsf) < 0) { 24447c478bd9Sstevel@tonic-gate msg(fail, filenum); 24457c478bd9Sstevel@tonic-gate dumpabort(); 24467c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24477c478bd9Sstevel@tonic-gate } 24487c478bd9Sstevel@tonic-gate } 24497c478bd9Sstevel@tonic-gate (void) close(to); 24507c478bd9Sstevel@tonic-gate to = -1; 24517c478bd9Sstevel@tonic-gate } 24527c478bd9Sstevel@tonic-gate 24537c478bd9Sstevel@tonic-gate free(info); 24547c478bd9Sstevel@tonic-gate free(fail); 24557c478bd9Sstevel@tonic-gate } 24567c478bd9Sstevel@tonic-gate 24577c478bd9Sstevel@tonic-gate static void 24587c478bd9Sstevel@tonic-gate #ifdef __STDC__ 24597c478bd9Sstevel@tonic-gate cmdwrterr(void) 24607c478bd9Sstevel@tonic-gate #else 24617c478bd9Sstevel@tonic-gate cmdwrterr() 24627c478bd9Sstevel@tonic-gate #endif 24637c478bd9Sstevel@tonic-gate { 24647c478bd9Sstevel@tonic-gate int saverr = errno; 24657c478bd9Sstevel@tonic-gate msg(gettext("Error writing command pipe: %s\n"), strerror(saverr)); 24667c478bd9Sstevel@tonic-gate } 24677c478bd9Sstevel@tonic-gate 24687c478bd9Sstevel@tonic-gate static void 24697c478bd9Sstevel@tonic-gate #ifdef __STDC__ 24707c478bd9Sstevel@tonic-gate cmdrderr(void) 24717c478bd9Sstevel@tonic-gate #else 24727c478bd9Sstevel@tonic-gate cmdrderr() 24737c478bd9Sstevel@tonic-gate #endif 24747c478bd9Sstevel@tonic-gate { 24757c478bd9Sstevel@tonic-gate int saverr = errno; 24767c478bd9Sstevel@tonic-gate msg(gettext("Error reading command pipe: %s\n"), strerror(saverr)); 24777c478bd9Sstevel@tonic-gate } 2478