Changeset: aa92d4ce3345 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=aa92d4ce3345 Modified Files: configure.ag gdk/gdk_posix.c gdk/gdk_private.h gdk/gdk_storage.c Branch: default Log Message:
Merge with Jan2014 branch. diffs (136 lines): diff --git a/configure.ag b/configure.ag --- a/configure.ag +++ b/configure.ag @@ -2835,6 +2835,7 @@ AC_CHECK_FUNCS([\ pipe \ popen \ posix_fadvise \ + posix_fallocate \ posix_madvise \ putenv \ round \ diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c --- a/gdk/gdk_posix.c +++ b/gdk/gdk_posix.c @@ -423,7 +423,7 @@ MT_mremap(const char *path, int mode, vo fprintf(stderr, "= %s:%d: MT_mremap(%s,"PTRFMT","SZFMT","SZFMT"): open() failed\n", __FILE__, __LINE__, path?path:"NULL", PTRFMTCAST old_address, old_size, *new_size); return NULL; } - if (GDKextendf(fd, *new_size) < 0) { + if (GDKextendf(fd, *new_size, path) < 0) { close(fd); fprintf(stderr, "= %s:%d: MT_mremap(%s,"PTRFMT","SZFMT","SZFMT"): GDKextendf() failed\n", __FILE__, __LINE__, path?path:"NULL", PTRFMTCAST old_address, old_size, *new_size); return NULL; @@ -522,6 +522,9 @@ MT_mremap(const char *path, int mode, vo /* if it failed, try alternative */ } if (p == MAP_FAILED && path != NULL) { +#ifdef HAVE_POSIX_FALLOCATE + int rt; +#endif /* write data to disk, then * mmap it to new address */ if (fd >= 0) @@ -537,9 +540,30 @@ MT_mremap(const char *path, int mode, vo } if (write(fd, old_address, old_size) < 0 || - ftruncate(fd, *new_size) < 0) { +#ifdef HAVE_POSIX_FALLOCATE + /* posix_fallocate returns + * error number on + * failure, not -1, and if + * it returns EINVAL, the + * underlying file system + * may not support the + * operation, so we then + * need to try + * ftruncate */ + ((rt = posix_fallocate(fd, 0, (off_t) *new_size)) == EINVAL ? ftruncate(fd, (off_t) *new_size) < 0 : rt != 0) +#else + ftruncate(fd, (off_t) *new_size) < 0 +#endif + ) { close(fd); - fprintf(stderr, "= %s:%d: MT_mremap(%s,"PTRFMT","SZFMT","SZFMT"): write() or ftruncate() failed\n", __FILE__, __LINE__, path?path:"NULL", PTRFMTCAST old_address, old_size, *new_size); + fprintf(stderr, + "= %s:%d: MT_mremap(%s,"PTRFMT","SZFMT","SZFMT"): write() or " +#ifdef HAVE_POSIX_FALLOCATE + "posix_fallocate()" +#else + "ftruncate()" +#endif + " failed\n", __FILE__, __LINE__, path?path:"NULL", PTRFMTCAST old_address, old_size, *new_size); return NULL; } p = mmap(NULL, *new_size, prot, flags, diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -100,7 +100,7 @@ void GDKclrerr(void) __attribute__((__visibility__("hidden"))); int GDKextend(const char *fn, size_t size) __attribute__((__visibility__("hidden"))); -int GDKextendf(int fd, size_t size) +int GDKextendf(int fd, size_t size, const char *fn) __attribute__((__visibility__("hidden"))); int GDKfdlocate(const char *nme, const char *mode, const char *ext) __attribute__((__visibility__("hidden"))); diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c --- a/gdk/gdk_storage.c +++ b/gdk/gdk_storage.c @@ -229,35 +229,46 @@ GDKmove(const char *dir1, const char *nm } int -GDKextendf(int fd, size_t size) +GDKextendf(int fd, size_t size, const char *fn) { struct stat stb; + int rt = 0; + int t0 = 0; if (fstat(fd, &stb) < 0) { /* shouldn't happen */ return -1; } /* if necessary, extend the underlying file */ + IODEBUG t0 = GDKms(); if (stb.st_size < (off_t) size) { - return ftruncate(fd, (off_t) size); +#ifdef HAVE_POSIX_FALLOCATE + /* posix_fallocate returns error number on failure, + * not -1 :-( */ + if ((rt = posix_fallocate(fd, 0, (off_t) size)) == EINVAL) + /* on Solaris/OpenIndiana, this may mean that + * the underlying file system doesn't support + * the operation, so just resize the file */ +#endif + rt = ftruncate(fd, (off_t) size); } - return 0; + IODEBUG fprintf(stderr, "#GDKextend %s " SZFMT " -> " SZFMT " %dms%s\n", + fn, stb.st_size, size, + GDKms() - t0, rt < 0 ? " (failed)" : ""); + /* return 0 or -1 (posix_fallocate returns != 0 on failure) */ + return -(rt != 0); } int GDKextend(const char *fn, size_t size) { - int t0 = 0; int rt = -1, fd; - IODEBUG t0 = GDKms(); rt = -1; if ((fd = open(fn, O_RDWR)) >= 0) { - rt = GDKextendf(fd, size); + rt = GDKextendf(fd, size, fn); close(fd); } - IODEBUG fprintf(stderr, "#GDKextend %s " SZFMT " %dms%s\n", fn, size, - GDKms() - t0, rt < 0 ? " (failed)" : ""); return rt; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list