[PATCH 2/2] Remove the automatic file size reduction

Martin Blix Grydeland martin at varnish-software.com
Fri Oct 3 16:43:10 CEST 2014


This never worked as intented, as it didn't take the actual size into
account (sparse files). Also the calucation didn't take overflow into
account leading to strange behavior.

Replace it with an ARGV_ERR if the attempted file size exceeds the
size of the filesystem.

This is still not perfect as file system overhead can't be
anticipated, making it possible to end up with IO errors on
writes. posix_fallocate() could be run after the ftruncate call to
make sure we can allocate all the blocks, but posix_fallocate() isn't
available in FreeBSD (I believe).

Fixes: #1343
---
 bin/varnishd/storage/stevedore_utils.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c
index c865f6e..7ff5202 100644
--- a/bin/varnishd/storage/stevedore_utils.c
+++ b/bin/varnishd/storage/stevedore_utils.c
@@ -196,8 +196,9 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
 		 * use its existing size.
 		 */
 		l = st.st_size;
+	} else if (size == NULL || *size == '\0') {
+		ARGV_ERR("(%s) missing size argument\n", ctx);
 	} else {
-		AN(size);
 		q = VNUM_2bytes(size, &l, fssize);
 
 		if (q != NULL)
@@ -206,6 +207,10 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
 		if (l < 1024*1024)
 			ARGV_ERR("(%s) size \"%s\": too small, "
 			    "did you forget to specify M or G?\n", ctx, size);
+
+		if (l > fssize)
+			ARGV_ERR("(%s) size \"%s\": larger than file system",
+			    ctx, size);
 	}
 
 	/*
@@ -223,11 +228,6 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
 	if (i)
 		fprintf(stderr, "WARNING: (%s) file size reduced"
 		    " to %ju due to system \"off_t\" limitations\n", ctx, l);
-	else if (l - st.st_size > fssize) {
-		l = fssize * 80 / 100;
-		fprintf(stderr, "WARNING: (%s) file size reduced"
-		    " to %ju (80%% of available disk space)\n", ctx, l);
-	}
 
 	if (sizeof(void *) == 4 && l > INT32_MAX) { /*lint !e506 !e774 !e845 */
 		fprintf(stderr,
-- 
2.1.0




More information about the varnish-dev mailing list