Only disable the usage of posix_fadvise for that one file if a call fails and don't abort mkvmerge itself.

This commit is contained in:
Moritz Bunkus 2005-02-28 19:26:04 +00:00
parent afd8960844
commit 9139ced877
3 changed files with 34 additions and 16 deletions

View File

@ -1,5 +1,9 @@
2005-02-28 Moritz Bunkus <moritz@bunkus.org> 2005-02-28 Moritz Bunkus <moritz@bunkus.org>
* mkvmerge: bug fix: A failing call to posix_fadvise will only
turn its usage off for that one file and not abort mkvmerge
completely.
* mmg: bug fix: When "appending" a file all tracks where added to * mmg: bug fix: When "appending" a file all tracks where added to
the end of the track list making it unnecessarily difficult to the end of the track list making it unnecessarily difficult to
concatenate similar structured files. Now the tracks from the concatenate similar structured files. Now the tracks from the

View File

@ -45,6 +45,11 @@ static const unsigned long write_before_dontneed = 8 * 1024 * 1024;
bool mm_file_io_c::use_posix_fadvise = false; bool mm_file_io_c::use_posix_fadvise = false;
# endif # endif
#define FADVISE_WARNING "mm_file_io_c: Could not posix_fadvise() file '%s' " \
"(errno = %d, %s). " \
"This only means that access to this file might be slower than it could " \
"be. Data integrity is not in danger."
mm_file_io_c::mm_file_io_c(const string &path, mm_file_io_c::mm_file_io_c(const string &path,
const open_mode mode): const open_mode mode):
file_name(path) { file_name(path) {
@ -57,6 +62,7 @@ mm_file_io_c::mm_file_io_c(const string &path,
advise = 0; advise = 0;
read_count = 0; read_count = 0;
write_count = 0; write_count = 0;
use_posix_fadvise_here = use_posix_fadvise;
# endif # endif
switch (mode) { switch (mode) {
@ -95,11 +101,12 @@ mm_file_io_c::mm_file_io_c(const string &path,
throw error_c(mxsprintf("Error opening file %s", path.c_str())); throw error_c(mxsprintf("Error opening file %s", path.c_str()));
# if HAVE_POSIX_FADVISE # if HAVE_POSIX_FADVISE
if (use_posix_fadvise && if (use_posix_fadvise && use_posix_fadvise_here &&
(0 != posix_fadvise(fileno((FILE *)file), 0, read_using_willneed, (0 != posix_fadvise(fileno((FILE *)file), 0, read_using_willneed,
advise))) advise))) {
mxerror("mm_file_io_c: Could not fadvise file '%s' (errno = %d, %s)\n", mxwarn(FADVISE_WARNING, path.c_str(), errno, strerror(errno));
path.c_str(), errno, strerror(errno)); use_posix_fadvise_here = false;
}
# endif # endif
} }
@ -136,12 +143,15 @@ mm_file_io_c::write(const void *buffer,
# if HAVE_POSIX_FADVISE # if HAVE_POSIX_FADVISE
write_count += bwritten; write_count += bwritten;
if (use_posix_fadvise && (write_count > write_before_dontneed)) { if (use_posix_fadvise && use_posix_fadvise_here &&
(write_count > write_before_dontneed)) {
uint64 pos = getFilePointer(); uint64 pos = getFilePointer();
write_count = 0; write_count = 0;
if (0 != posix_fadvise(fileno((FILE *)file), 0, pos, POSIX_FADV_DONTNEED)) if (0 != posix_fadvise(fileno((FILE *)file), 0, pos,
mxerror("mm_file_io_c: Could not fadvise file '%s' (errno = %d, %s)\n", POSIX_FADV_DONTNEED)) {
file_name.c_str(), errno, strerror(errno)); mxwarn(FADVISE_WARNING, file_name.c_str(), errno, strerror(errno));
use_posix_fadvise_here = false;
}
} }
# endif # endif
@ -156,19 +166,22 @@ mm_file_io_c::read(void *buffer,
bread = fread(buffer, 1, size, (FILE *)file); bread = fread(buffer, 1, size, (FILE *)file);
# if HAVE_POSIX_FADVISE # if HAVE_POSIX_FADVISE
if (use_posix_fadvise && (0 <= bread)) { if (use_posix_fadvise && use_posix_fadvise_here && (0 <= bread)) {
read_count += bread; read_count += bread;
if (read_count > read_using_willneed) { if (read_count > read_using_willneed) {
uint64 pos = getFilePointer(); uint64 pos = getFilePointer();
int fd = fileno((FILE *)file); int fd = fileno((FILE *)file);
read_count = 0; read_count = 0;
if (0 != posix_fadvise(fd, 0, pos, POSIX_FADV_DONTNEED)) if (0 != posix_fadvise(fd, 0, pos, POSIX_FADV_DONTNEED)) {
mxerror("mm_file_io_c: Could not fadvise file '%s' (errno = %d, %s)\n", mxwarn(FADVISE_WARNING, file_name.c_str(), errno, strerror(errno));
file_name.c_str(), errno, strerror(errno)); use_posix_fadvise_here = false;
if (0 != posix_fadvise(fd, pos, pos + read_using_willneed, }
POSIX_FADV_WILLNEED)) if (use_posix_fadvise_here &&
mxerror("mm_file_io_c: Could not fadvise file '%s' (errno = %d, %s)\n", (0 != posix_fadvise(fd, pos, pos + read_using_willneed,
file_name.c_str(), errno, strerror(errno)); POSIX_FADV_WILLNEED))) {
mxwarn(FADVISE_WARNING, file_name.c_str(), errno, strerror(errno));
use_posix_fadvise_here = false;
}
} }
} }
# endif # endif

View File

@ -92,6 +92,7 @@ protected:
#if HAVE_POSIX_FADVISE #if HAVE_POSIX_FADVISE
unsigned long read_count, write_count; unsigned long read_count, write_count;
static bool use_posix_fadvise; static bool use_posix_fadvise;
bool use_posix_fadvise_here;
#endif #endif
string file_name; string file_name;
void *file; void *file;