Commit 88d37443 authored by Mike Hibler's avatar Mike Hibler

fsync/close the output device before we reports stats and exit.

Since Linux device writes go through the buffer cache, it was "finishing"
before all the data made it to disk. This led us to exit with success when
there might still be disk errors. It also led to reporting really great
performance numbers!
parent 4fc6775b
......@@ -87,7 +87,7 @@ extern void ImageUnzipSetChunkCount(unsigned long chunkcount);
extern void ImageUnzipSetMemory(unsigned long writebufmem);
extern int ImageWriteChunk(int chunkno, char *chunkdata, int chunksize);
extern int ImageUnzipChunk(char *chunkdata, int chunksize);
extern void ImageUnzipFlush(void);
extern int ImageUnzipFlush(void);
extern int ImageUnzipQuit(void);
/*
......@@ -1073,7 +1073,9 @@ ChunkerStartup(void)
* Make sure any asynchronous writes are done
* and collect stats from the unzipper.
*/
ImageUnzipFlush();
if (ImageUnzipFlush())
pfatal("ImageUnzipFlush failed");
#ifdef STATS
{
Stats.u.v1.decompblocks = decompblocks;
......
......@@ -901,6 +901,15 @@ main(int argc, char *argv[])
if (slice && dostype >= 0)
fixmbr(slice, dostype);
/* Flush any cached data and close the output device */
if (outfd >= 0) {
if (fsync(outfd) < 0) {
perror("flushing output data");
exit(1);
}
close(outfd);
}
dump_stats(0);
if (docrconly)
fprintf(stderr, "%s: CRC=%u\n", argv[0], ~crc);
......@@ -1048,13 +1057,25 @@ ImageUnzipChunk(char *chunkdata, int chunksize)
return inflate_subblock(chunkdata);
}
void
int
ImageUnzipFlush(void)
{
int rv = 0;
/* When zeroing, may need to zero the rest of the disk */
zero_remainder();
threadwait();
if (outfd >= 0) {
if (fsync(outfd) < 0) {
perror("fsync");
rv = -1;
}
close(outfd);
}
return(rv);
}
int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment