aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2014-09-29 17:12:59 +0200
committerPeter Maydell <peter.maydell@linaro.org>2014-09-29 16:28:24 +0100
commited9114356b587b362f5ed10e75366a4f07ed32af (patch)
tree24a063327e9e7e424cb7ef04389df8dd64b0c4b9 /block
parent0ebcc564533454853e66cbe665a0d23bf7199834 (diff)
downloadqemu-ed9114356b587b362f5ed10e75366a4f07ed32af.zip
qemu-ed9114356b587b362f5ed10e75366a4f07ed32af.tar.gz
qemu-ed9114356b587b362f5ed10e75366a4f07ed32af.tar.bz2
raw-posix: Fix build without posix_fallocate()
Check for the presence of posix_fallocate() in configure and only compile in support for PREALLOC_MODE_FALLOC when it's there. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'block')
-rw-r--r--block/raw-posix.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/block/raw-posix.c b/block/raw-posix.c
index a253697..86ce4f2 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1416,16 +1416,21 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
goto out_close;
}
- if (prealloc == PREALLOC_MODE_FALLOC) {
+ switch (prealloc) {
+#ifdef CONFIG_POSIX_FALLOCATE
+ case PREALLOC_MODE_FALLOC:
/* posix_fallocate() doesn't set errno. */
result = -posix_fallocate(fd, 0, total_size);
if (result != 0) {
error_setg_errno(errp, -result,
"Could not preallocate data for the new file");
}
- } else if (prealloc == PREALLOC_MODE_FULL) {
- buf = g_malloc0(65536);
+ break;
+#endif
+ case PREALLOC_MODE_FULL:
+ {
int64_t num = 0, left = total_size;
+ buf = g_malloc0(65536);
while (left > 0) {
num = MIN(left, 65536);
@@ -1440,10 +1445,15 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
}
fsync(fd);
g_free(buf);
- } else if (prealloc != PREALLOC_MODE_OFF) {
+ break;
+ }
+ case PREALLOC_MODE_OFF:
+ break;
+ default:
result = -EINVAL;
error_setg(errp, "Unsupported preallocation mode: %s",
PreallocMode_lookup[prealloc]);
+ break;
}
out_close: