[Devel] [PATCH] ploop: try to use fallocate to allocate raw images

Andrew Vagin avagin at parallels.com
Tue May 28 02:59:24 PDT 2013


It's much faster than writing zeros
---
 lib/ploop.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/lib/ploop.c b/lib/ploop.c
index 1af227c..9a371dd 100644
--- a/lib/ploop.c
+++ b/lib/ploop.c
@@ -397,7 +397,7 @@ out_close:
 
 static int create_raw_delta(const char * path, off_t bdsize)
 {
-	int fd;
+	int fd, err;
 	void * buf = NULL;
 	off_t pos;
 
@@ -414,6 +414,18 @@ static int create_raw_delta(const char * path, off_t bdsize)
 		return -1;
 	}
 
+	err = sys_fallocate(fd, 0, 0, S2B(bdsize));
+	if (err == 0)
+		goto out;
+	else {
+		if (errno != ENOTSUP) {
+			ploop_err(errno, "Failed to create %s", path);
+			goto out_close;
+		}
+
+		ploop_log(0, "Warning: fallocate is not supported");
+	}
+
 	memset(buf, 0, DEF_CLUSTER);
 
 	pos = 0;
@@ -428,6 +440,7 @@ static int create_raw_delta(const char * path, off_t bdsize)
 		pos += copy;
 	}
 
+out:
 	if (fsync(fd)) {
 		ploop_err(errno, "fsync");
 		goto out_close;
-- 
1.7.1




More information about the Devel mailing list