X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=dump%2Ftape.c;h=38dd80426f4a798dd3880c70f917e441834f07d6;hb=700b236e8f7d2d64fe86cb231f041f151a0fe02c;hp=7851719381ee78f3702acbbe2fc0bc70a2f5c2e7;hpb=a1b67fc50f87e9febfd56bd2a7089eb569b852f6;p=dump.git diff --git a/dump/tape.c b/dump/tape.c index 7851719..38dd804 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.36 2001/03/20 10:02:48 stelian Exp $"; + "$Id: tape.c,v 1.42 2001/04/12 13:14:15 stelian Exp $"; #endif /* not lint */ #include @@ -68,6 +68,7 @@ int write(), read(); #include #include #include +#include #ifdef __linux__ #include #include @@ -158,6 +159,9 @@ static int ready; /* have we reached the lock point without having */ /* received the SIGUSR2 signal from the prev slave? */ static sigjmp_buf jmpbuf; /* where to jump to if we are ready when the */ /* SIGUSR2 arrives from the previous slave */ +#ifdef USE_QFA +static int gtperr = 0; +#endif int alloctape(void) @@ -253,7 +257,8 @@ tperror(int errnum) quit("Cannot recover\n"); /* NOTREACHED */ } - msg("write error %d blocks into volume %d: %s\n", blocksthisvol, tapeno, strerror(errnum)); + msg("write error %d blocks into volume %d: %s\n", + blocksthisvol, tapeno, strerror(errnum)); broadcast("DUMP WRITE ERROR!\n"); if (query("Do you want to rewrite this volume?")) { msg("Closing this volume. Prepare to restart with new media;\n"); @@ -297,13 +302,13 @@ do_stats(void) long txfrate = volkb / ttaken; msg("Volume %d took %d:%02d:%02d\n", tapeno, ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60); - msg("Volume %d transfer rate: %ld KB/s\n", tapeno, + msg("Volume %d transfer rate: %ld kB/s\n", tapeno, txfrate); xferrate += txfrate; if (compressed) { double rate = .0005 + (double) blocks / (double) volkb; - msg("Volume %d %ldKB uncompressed, %ldKB compressed," - " compression ratio %1.3f\n", + msg("Volume %d %ldkB uncompressed, %ldkB compressed," + " %1.3f:1\n", tapeno, blocks, volkb, rate); } } @@ -326,7 +331,7 @@ mktimeest(time_t tnow) / blockswritten * tapesize; if (tnow > tstart_volume) (void)snprintf(msgbuf, sizeof(msgbuf), - "%3.2f%% done at %ld KB/s, finished in %d:%02d\n", + "%3.2f%% done at %ld kB/s, finished in %d:%02d\n", (blockswritten * 100.0) / tapesize, (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume), (int)(deltat / 3600), (int)((deltat % 3600) / 60)); @@ -859,7 +864,7 @@ restore_check_point: open(tape, O_WRONLY|O_CREAT, 0666))) < 0) #else while ((tapefd = (pipeout ? fileno(stdout) : - open(tape, O_WRONLY|O_CREAT, 0666))) < 0) + open(tape, O_RDWR|O_CREAT, 0666))) < 0) #endif { msg("Cannot open output \"%s\".\n", tape); @@ -989,6 +994,8 @@ enslave(void) doslave(cmd[0], i); Exit(X_FINOK); } + else + close(cmd[0]); } #ifdef LINUX_FORK_BUG @@ -1038,13 +1045,18 @@ doslave(int cmd, int slave_number) char *buffer; #ifdef HAVE_ZLIB struct tapebuf *comp_buf = NULL; - int compresult, complevel = 6, do_compress = 0; + int compresult, do_compress = 0; unsigned long worklen; #endif /* HAVE_ZLIB */ struct slave_results returns; #ifdef __linux__ errcode_t retval; #endif +#ifdef USE_QFA + long curtapepos; + union u_spcl *uspclptr; + struct s_spcl *spclptr; +#endif /* USA_QFA */ /* * Need our own seek pointer. @@ -1095,14 +1107,30 @@ doslave(int cmd, int slave_number) quit("master/slave protocol botched.\n"); } } - if (sigsetjmp(jmpbuf, 1) == 0) { - ready = 1; - if (!caught) - (void) pause(); - } - ready = 0; - caught = 0; +#ifdef USE_QFA + if (gTapeposfd >= 0) { + uspclptr = (union u_spcl *)&slp->tblock[0]; + spclptr = &uspclptr->s_spcl; + if ((spclptr->c_magic == NFS_MAGIC) && + (spclptr->c_type == TS_INODE)) { + /* if an error occured previously don't + * try again */ + if (gtperr == 0) { + if ((gtperr = GetTapePos(&curtapepos)) == 0) { +#ifdef DEBUG_QFA + msg("inode %ld at tapepos %ld\n", spclptr->c_inumber, curtapepos); +#endif + sprintf(gTps, "%ld\t%d\t%ld\n", (unsigned long)spclptr->c_inumber, tapeno, curtapepos); + if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) { + quit("error writing tapepos file.\n"); + } + } + } + } + } +#endif /* USE_QFA */ + /* Try to write the data... */ wrote = 0; eot_count = 0; @@ -1113,7 +1141,6 @@ doslave(int cmd, int slave_number) #ifdef HAVE_ZLIB /* - * The first NR_SLAVE blocks are not compressed. * When writing a compressed dump, each block is * written from struct tapebuf with an 4 byte prefix * followed by the data. This can be less than @@ -1121,6 +1148,7 @@ doslave(int cmd, int slave_number) * length read to the compressed length in the header * to verify that the read was good. Blocks which don't * compress well are written uncompressed. + * The first block written by each slave is not compressed. */ if (compressed) { @@ -1128,7 +1156,7 @@ doslave(int cmd, int slave_number) worklen = TP_BSIZE + writesize; if (do_compress) compresult = compress2(comp_buf->buf, &worklen, - (char *)slp->tblock[0], writesize, complevel); + (char *)slp->tblock[0], writesize, compressed); if (compresult == Z_OK && worklen <= writesize-32) { /* write the compressed buffer */ comp_buf->length = worklen; @@ -1150,6 +1178,14 @@ doslave(int cmd, int slave_number) do_compress = compressed; #endif /* HAVE_ZLIB */ + if (sigsetjmp(jmpbuf, 1) == 0) { + ready = 1; + if (!caught) + (void) pause(); + } + ready = 0; + caught = 0; + while (eot_count < 10 && size < bufsize) { #ifdef RDUMP if (host) @@ -1238,3 +1274,24 @@ atomic_write(int fd, const void *buf, size_t count) } while (got == -1 && errno == EINTR); return (got < 0 ? got : count - need); } + + +#ifdef USE_QFA +/* + * read the current tape position + */ +int +GetTapePos(long *pos) +{ + int err = 0; + + *pos = 0; + if (ioctl(tapefd, MTIOCPOS, pos) == -1) { + err = errno; + msg("[%ld] error: %d (getting tapepos: %ld)\n", getpid(), + err, *pos); + return err; + } + return err; +} +#endif /* USE_QFA */