[master] 45cf215 Use VFIL_allocate in vsm_zerofile

Martin Blix Grydeland martin at varnish-software.com
Tue Oct 21 12:25:43 CEST 2014


commit 45cf21512b772c01b53696b35ac499eb79431fcd
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Oct 7 16:17:26 2014 +0200

    Use VFIL_allocate in vsm_zerofile
    
    Here we insist the file is completely allocated

diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c
index dc1fa5c..04634b8 100644
--- a/bin/varnishd/mgt/mgt_shmem.c
+++ b/bin/varnishd/mgt/mgt_shmem.c
@@ -47,6 +47,7 @@
 #include "flopen.h"
 #include "vapi/vsm_int.h"
 #include "vmb.h"
+#include "vfil.h"
 
 #ifndef MAP_HASSEMAPHORE
 #define MAP_HASSEMAPHORE 0 /* XXX Linux */
@@ -147,8 +148,6 @@ static int
 vsm_zerofile(const char *fn, ssize_t size)
 {
 	int fd;
-	ssize_t i, u;
-	char buf[64*1024];
 	int flags;
 
 	fd = flopen(fn, O_RDWR | O_CREAT | O_EXCL | O_NONBLOCK, 0644);
@@ -161,18 +160,11 @@ vsm_zerofile(const char *fn, ssize_t size)
 	assert(flags != -1);
 	flags &= ~O_NONBLOCK;
 	AZ(fcntl(fd, F_SETFL, flags));
-
-	memset(buf, 0, sizeof buf);
-	for (u = 0; u < size; ) {
-		i = write(fd, buf, sizeof buf);
-		if (i <= 0) {
-			fprintf(stderr, "Write error %s: %s\n",
-			    fn, strerror(errno));
-			return (-1);
-		}
-		u += i;
+	if (VFIL_allocate(fd, (off_t)size, 1)) {
+		fprintf(stderr, "File allocation error %s: %s\n",
+		    fn, strerror(errno));
+		return (-1);
 	}
-	AZ(ftruncate(fd, (off_t)size));
 	return (fd);
 }
 



More information about the varnish-commit mailing list