author | Alberto Bertogli
<albertito@blitiri.com.ar> 2009-03-29 04:09:14 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2009-03-29 04:14:26 UTC |
parent | 70ee2209c331e69bda9a6a7d02a138aac56d0797 |
libjio/Makefile | +1 | -1 |
libjio/compat.h | +19 | -0 |
libjio/trans.c | +5 | -0 |
diff --git a/libjio/Makefile b/libjio/Makefile index be29891..c3ab13e 100644 --- a/libjio/Makefile +++ b/libjio/Makefile @@ -3,7 +3,7 @@ CFLAGS = -std=c99 -pedantic -Wall -O3 MANDATORY_CFLAGS := \ -D_LARGEFILE_SOURCE=1 $(shell getconf LFS_CFLAGS 2>/dev/null) \ - -D_XOPEN_SOURCE=500 + -D_XOPEN_SOURCE=600 MANDATORY_LDFLAGS := $(shell getconf LFS_LIBS 2>/dev/null) diff --git a/libjio/compat.h b/libjio/compat.h new file mode 100644 index 0000000..ecc742a --- /dev/null +++ b/libjio/compat.h @@ -0,0 +1,19 @@ + +/* Header to provide fallbacks for compatibility purposes. */ + +#ifndef _COMPAT_H +#define _COMPAT_H + +/* posix_fadvise() was introduced in SUSv3. Because it's the only SUSv3 + * function we rely on so far (everything else is SUSv2), we define a void + * fallback for systems that do not implement it. + * + * The check is based on POSIX_FADV_WILLNEED being defined, which is not very + * nice, but it's simple, it works and should be reliable. */ +#include <fcntl.h> +#ifndef POSIX_FADV_WILLNEED +#define posix_fadvise(fd, offset, len, advise) +#endif + +#endif + diff --git a/libjio/trans.c b/libjio/trans.c index dc38814..6fb6885 100644 --- a/libjio/trans.c +++ b/libjio/trans.c @@ -21,6 +21,7 @@ #include "libjio.h" #include "common.h" +#include "compat.h" /* @@ -203,6 +204,10 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset) jop->pdata = NULL; jop->locked = 0; + /* it's highly likely that jtrans_commit() will want to read the + * current data, so we tell the kernel about that */ + posix_fadvise(ts->fs->fd, offset, count, POSIX_FADV_WILLNEED); + return 1; }