[master] 9f38e1a fallocate will for some filesystems (e.g. xfs) not take the already allocated blocks of the file into account. This will cause fallocate to report ENOSPC when called on an existing fully allocated file unless the filesystem has enough free space to accomodate the complete new file size. Because of this we enable fallocate only on filesystems that are known to work as we expect.

Martin Blix Grydeland martin at varnish-software.com
Tue Sep 15 15:37:50 CEST 2015


commit 9f38e1a8909baeb55f6d4e570948d3f904146303
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Sep 15 15:09:26 2015 +0200

    fallocate will for some filesystems (e.g. xfs) not take the already
    allocated blocks of the file into account. This will cause fallocate
    to report ENOSPC when called on an existing fully allocated file
    unless the filesystem has enough free space to accomodate the complete
    new file size. Because of this we enable fallocate only on filesystems
    that are known to work as we expect.
    
    Fixes: #1792

diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c
index 1a48231..19928ff 100644
--- a/lib/libvarnish/vfil.c
+++ b/lib/libvarnish/vfil.c
@@ -51,6 +51,9 @@
 #ifdef HAVE_SYS_VFS_H
 #  include <sys/vfs.h>
 #endif
+#if defined(__linux__) && defined(HAVE_FALLOCATE)
+#  include <linux/magic.h>
+#endif
 
 #include "vas.h"
 #include "vdef.h"
@@ -182,11 +185,24 @@ VFIL_allocate(int fd, off_t size, int insist)
 		errno = ENOSPC;
 		return (-1);
 	}
-#ifdef HAVE_FALLOCATE
-	if (!fallocate(fd, 0, 0, size))
-		return (0);
-	if (errno == ENOSPC)
-		return (-1);
+#if defined(__linux__) && defined(HAVE_FALLOCATE)
+	{
+		/* fallocate will for some filesystems (e.g. xfs) not take
+		   the already allocated blocks of the file into
+		   account. This will cause fallocate to report ENOSPC
+		   when called on an existing fully allocated file unless
+		   the filesystem has enough free space to accomodate the
+		   complete new file size. Because of this we enable
+		   fallocate only on filesystems that are known to work as
+		   we expect. */
+		struct statfs stfs;
+		if (!fstatfs(fd, &stfs) && stfs.f_type == EXT4_SUPER_MAGIC) {
+			if (!fallocate(fd, 0, 0, size))
+				return (0);
+			if (errno == ENOSPC)
+				return (-1);
+		}
+	}
 #endif
 	if (!insist)
 		return (0);



More information about the varnish-commit mailing list