static char *sccsid
= "@(#)tape.c 1.11 (Berkeley) %G%";
char (*tblock
)[TP_BSIZE
]; /* Pointer to malloc()ed buffer for tape */
int writesize
; /* Size of malloc()ed buffer for tape */
extern int ntrec
; /* blocking factor on tape */
* Streaming dump mods (Caltech) - disk block reading and tape writing
* are exported to several slave processes. While one slave writes the
* tape, the others read disk blocks; they pass control of the tape in
* a ring via pipes. The parent process traverses the filesystem and
* sends daddr's, inode records, etc, through pipes to each slave.
* Speed from Eagle to TU77 on VAX/780 is about 140 Kbytes/second.
* #ifdef RDUMP version is CPU-limited to about 40 Kbytes/second.
struct req
{ /* instruction packets sent to slaves */
#define SLAVES 3 /* 2 slaves read disk while 3rd writes tape */
#define LAG 2 /* Write behind by LAG tape blocks (rdump) */
int slavefd
[SLAVES
]; /* Pipes from master to each slave */
int rotor
; /* Current slave number */
int master
; /* Pid of master, for sending error signals */
int trace
= 0; /* Protocol trace; easily patchable with adb */
#define tmsg if (trace) msg
* Allocate tape buffer contiguous with the array of instruction packets,
* so they can be written with a single write call in flusht().
writesize
= ntrec
* TP_BSIZE
;
reqsiz
= ntrec
* sizeof(struct req
);
req
= (struct req
*)malloc(reqsiz
+writesize
); /* array of packets */
tblock
= (char (*)[TP_BSIZE
]) &req
[ntrec
]; /* Tape buffer */
* Send special record to be put on tape
tmsg("taprec %d\n", trecno
);
req
[trecno
].dblk
= (daddr_t
)0;
*(union u_spcl
*)(*tblock
++) = *(union u_spcl
*)dp
;
if (size
% TP_BSIZE
!= 0)
msg("bad size to dmpblk: %d\n", size
);
dblkno
= fsbtodb(sblock
, blkno
);
tpblks
= size
/ TP_BSIZE
;
while ((avail
= MIN(tpblks
, ntrec
- trecno
)) > 0) {
tmsg("dmpblk %d\n", avail
);
req
[trecno
].dblk
= dblkno
;
req
[trecno
].count
= avail
;
dblkno
+= avail
* (TP_BSIZE
/ DEV_BSIZE
);
msg("Tape write error on %s\n", tape
);
msg("Tape write error on tape %d\n", tapeno
);
broadcast("TAPE ERROR!\n");
if (!query("Do you want to restart?"))
msg("This tape will rewind. After it is rewound,\n");
msg("replace the faulty tape with a new one;\n");
msg("this dump volume will be rewritten.\n");
perror(" DUMP: pipe error in command to slave");
for (i
= 0; i
< ntrec
; i
++)
int sig
, siz
= (char *)tblock
- (char *)req
;
tmsg("flusht %d\n", siz
);
sig
= sigblock(1<<SIGINT
-1 | 1<<SIGIOT
-1); /* Don't interrupt write */
if (write(slavefd
[rotor
], req
, siz
) != siz
)
if (++rotor
>= SLAVES
) rotor
= 0;
tblock
= (char (*)[TP_BSIZE
]) &req
[ntrec
];
asize
+= writesize
/density
;
asize
+= 7; /* inter-record gap (why fixed?) */
if (!pipeout
&& asize
> tsize
) {
for (f
= 0; f
< SLAVES
; f
++)
while (wait(NULL
) >= 0) ; /* wait for any signals from slaves */
while (rmtopen(tape
, 0) < 0)
while ((f
= open(tape
, 0)) < 0)
msg("Change Tapes: Mount tape #%d\n", tapeno
+1);
broadcast("CHANGE TAPES!\7\7\n");
while (!query("Is the new tape mounted and ready to go?"))
if (query("Do you want to abort?"))
* We implement taking and restoring checkpoints on the tape level.
* When each tape is opened, a new process is created by forking; this
* saves all of the necessary context in the parent. The child
* continues the dump; the parent waits around, saving the context.
* If the child returns X_REWRITE, then it had problems writing that tape;
* this causes the parent to fork again, duplicating the context, and
* everything continues as if nothing had happened.
signal(SIGINT
, interrupt
);
* All signals are inherited...
msg("Context save fork fails in parent %d\n", parentpid
);
* save the context by waiting
* until the child doing all of the work returns.
* don't catch the interrupt
msg("Tape: %d; parent process: %d child process %d\n",
tapeno
+1, parentpid
, childpid
);
while ((waitpid
= wait(&status
)) != childpid
)
msg("Parent %d waiting for child %d has another child %d return\n",
parentpid
, childpid
, waitpid
);
msg("Child %d returns LOB status %o\n",
status
= (status
>> 8) & 0xFF;
msg("Child %d finishes X_FINOK\n", childpid
);
msg("Child %d finishes X_ABORT\n", childpid
);
msg("Child %d finishes X_REWRITE\n", childpid
);
msg("Child %d finishes unknown %d\n",
goto restore_check_point
;
msg("Bad return code from dump: %d\n", status
);
} else { /* we are the child; just continue */
sleep(4); /* allow time for parent's message to get out */
msg("Child on Tape %d has parent %d, my pid = %d\n",
tapeno
+1, parentpid
, getpid());
while ((to
= rmtopen(tape
, 2)) < 0)
while ((to
= pipeout
? 1 : creat(tape
, 0666)) < 0)
if (!query("Cannot open tape. Do you want to retry the open?"))
enslave(); /* Share open tape file descriptor with slaves */
tapeno
++; /* current tape sequence */
newtape
++; /* new tape signal */
msg("Tape %d begins with blocks from ino %d\n",
if (master
!= 0 && master
!= getpid())
msg("The ENTIRE dump is aborted.\n");
msg("pid = %d exits with status %d\n", getpid(), status
);
int prev
[2], next
[2], cmd
[2]; /* file descriptors for pipes */
signal(SIGPIPE
, dumpabort
);
signal(SIGIOT
, tperror
); /* SIGIOT asks for restart from checkpoint */
for (i
= rotor
= 0; i
< SLAVES
; ++i
) {
if ((i
< SLAVES
- 1 && pipe(next
) < 0) || pipe(cmd
) < 0
|| (slavepid
= fork()) < 0) {
perror(" DUMP: too many slaves");
next
[1] = prev
[1]; /* Last slave loops back */
if (slavepid
== 0) { /* Slave starts up here */
} else { /* Insert initial token */
if ((ret
= write(next
[1], &tok
, 1)) != 1)
ringerr(ret
, "cannot start token");
doslave(i
, cmd
[0], prev
[0], next
[1]);
j
= read(prev
[0], &tok
, 1); /* Eat the final token */
#ifdef RDUMP /* Read remaining acknowledges */
for (; j
> 0 && (tok
&~ OK
) > 0; tok
--) {
if (rmtwrite2() != writesize
&& (tok
& OK
)) {
* Somebody must have died, should never happen
ringerr(code
, msg
, a1
, a2
)
fprintf(stderr
, " DUMP: ");
sprintf(buf
, msg
, a1
, a2
);
fprintf(stderr
, "%s: unexpected EOF\n", buf
);
fprintf(stderr
, "%s: code %d\n", buf
, code
);
ringerr(childnum
, "SIGPIPE raised");
doslave(num
, cmd
, prev
, next
)
int num
, cmd
, prev
, next
;
signal(SIGINT
, SIG_IGN
); /* Master handles it */
signal(SIGTERM
, SIG_IGN
);
signal(SIGPIPE
, sigpipe
);
if ((fi
= open(disk
, 0)) < 0) { /* Need our own seek pointer */
perror(" DUMP: can't reopen disk");
while ((ret
= readpipe(cmd
, req
, reqsiz
)) == reqsiz
) {
register struct req
*p
= req
;
for (trecno
= 0; trecno
< ntrec
; trecno
+= p
->count
, p
+= p
->count
) {
tmsg("%d READS %d\n", num
, p
->count
);
bread(p
->dblk
, tblock
[trecno
],
tmsg("%d PIPEIN %d\n", num
, p
->count
);
ringerr(11, "%d PIPEIN %d", num
,
if (readpipe(cmd
, tblock
[trecno
], TP_BSIZE
) != TP_BSIZE
)
if ((ret
= read(prev
, &tok
, 1)) != 1)
ringerr(ret
, "read token"); /* Wait your turn */
rmtwrite1(tblock
[0], writesize
);
tok
++; /* Number of writes in progress */
if (tok
> (LAG
|OK
) && (--tok
, rmtwrite2() != writesize
)) {
write(to
, tblock
[0], writesize
) != writesize
) {
kill(master
, SIGIOT
); /* restart from checkpoint */
if ((ret
= write(next
, &tok
, 1)) != 1)
ringerr(ret
, "write token"); /* Next slave's turn */
ringerr(ret
, "partial record?");
* Since a read from a pipe may not return all we asked for
* we must loop until we get all we need
for (rd
= cnt
; rd
> 0; rd
-= got
) {