-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New wrapper for gzclose; added err_fflush calls and made it call fsyn…
…c too. Added a new utils.c wrapper err_gzclose and changed gzclose calls to use it. Put in some more err_fflush calls before files being written are closed. Made err_fflush call fsync. This is useful for remote filesystems where errors may not be reported on fflush or fclose as problems at the server end may only be detected after they have returned. If bwa is being used only to write to local filesystems, calling fsync is not really necessary. To disable it, comment out #define FSYNC_ON_FLUSH in utils.c.
- Loading branch information
Rob Davies
committed
Jan 3, 2013
1 parent
b081ac9
commit 55f1b36
Showing
12 changed files
with
64 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,19 @@ | |
*/ | ||
|
||
/* Contact: Heng Li <[email protected]> */ | ||
#define FSYNC_ON_FLUSH | ||
|
||
#include <stdio.h> | ||
#include <stdarg.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <zlib.h> | ||
#include <errno.h> | ||
#ifdef FSYNC_ON_FLUSH | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
#endif | ||
#include <sys/resource.h> | ||
#include <sys/time.h> | ||
#include "utils.h" | ||
|
@@ -196,6 +202,28 @@ int err_fflush(FILE *stream) | |
{ | ||
_err_fatal_simple("fflush", strerror(errno)); | ||
} | ||
#ifdef FSYNC_ON_FLUSH | ||
/* Calling fflush() ensures that all the data has made it to the | ||
kernel buffers, but this may not be sufficient for remote filesystems | ||
(e.g. NFS, lustre) as an error may still occur while the kernel | ||
is copying the buffered data to the file server. To be sure of | ||
catching these errors, we need to call fsync() on the file | ||
descriptor, but only if it is a regular file. */ | ||
{ | ||
struct stat sbuf; | ||
if (0 != fstat(fileno(stream), &sbuf)) | ||
{ | ||
_err_fatal_simple("fstat", strerror(errno)); | ||
} | ||
if (S_ISREG(sbuf.st_mode)) | ||
{ | ||
if (0 != fsync(fileno(stream))) | ||
{ | ||
_err_fatal_simple("fsync", strerror(errno)); | ||
} | ||
} | ||
} | ||
#endif | ||
return ret; | ||
} | ||
|
||
|
@@ -209,6 +237,17 @@ int err_fclose(FILE *stream) | |
return ret; | ||
} | ||
|
||
int err_gzclose(gzFile file) | ||
{ | ||
int ret = gzclose(file); | ||
if (Z_OK != ret) | ||
{ | ||
_err_fatal_simple("gzclose", Z_ERRNO == ret ? strerror(errno) : zError(ret)); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
void *err_calloc(size_t nmemb, size_t size, const char *file, unsigned int line, const char *func) | ||
{ | ||
void *p = calloc(nmemb, size); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters