mirror of https://github.com/xemu-project/xemu.git
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>
This commit is contained in:
parent
0ebcc56453
commit
ed9114356b
|
@ -1416,16 +1416,21 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prealloc == PREALLOC_MODE_FALLOC) {
|
switch (prealloc) {
|
||||||
|
#ifdef CONFIG_POSIX_FALLOCATE
|
||||||
|
case PREALLOC_MODE_FALLOC:
|
||||||
/* posix_fallocate() doesn't set errno. */
|
/* posix_fallocate() doesn't set errno. */
|
||||||
result = -posix_fallocate(fd, 0, total_size);
|
result = -posix_fallocate(fd, 0, total_size);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
error_setg_errno(errp, -result,
|
error_setg_errno(errp, -result,
|
||||||
"Could not preallocate data for the new file");
|
"Could not preallocate data for the new file");
|
||||||
}
|
}
|
||||||
} else if (prealloc == PREALLOC_MODE_FULL) {
|
break;
|
||||||
buf = g_malloc0(65536);
|
#endif
|
||||||
|
case PREALLOC_MODE_FULL:
|
||||||
|
{
|
||||||
int64_t num = 0, left = total_size;
|
int64_t num = 0, left = total_size;
|
||||||
|
buf = g_malloc0(65536);
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
num = MIN(left, 65536);
|
num = MIN(left, 65536);
|
||||||
|
@ -1440,10 +1445,15 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||||
}
|
}
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
} else if (prealloc != PREALLOC_MODE_OFF) {
|
break;
|
||||||
|
}
|
||||||
|
case PREALLOC_MODE_OFF:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
result = -EINVAL;
|
result = -EINVAL;
|
||||||
error_setg(errp, "Unsupported preallocation mode: %s",
|
error_setg(errp, "Unsupported preallocation mode: %s",
|
||||||
PreallocMode_lookup[prealloc]);
|
PreallocMode_lookup[prealloc]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_close:
|
out_close:
|
||||||
|
|
|
@ -3308,6 +3308,21 @@ if compile_prog "" "" ; then
|
||||||
fallocate_punch_hole=yes
|
fallocate_punch_hole=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check for posix_fallocate
|
||||||
|
posix_fallocate=no
|
||||||
|
cat > $TMPC << EOF
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
posix_fallocate(0, 0, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
if compile_prog "" "" ; then
|
||||||
|
posix_fallocate=yes
|
||||||
|
fi
|
||||||
|
|
||||||
# check for sync_file_range
|
# check for sync_file_range
|
||||||
sync_file_range=no
|
sync_file_range=no
|
||||||
cat > $TMPC << EOF
|
cat > $TMPC << EOF
|
||||||
|
@ -4522,6 +4537,9 @@ fi
|
||||||
if test "$fallocate_punch_hole" = "yes" ; then
|
if test "$fallocate_punch_hole" = "yes" ; then
|
||||||
echo "CONFIG_FALLOCATE_PUNCH_HOLE=y" >> $config_host_mak
|
echo "CONFIG_FALLOCATE_PUNCH_HOLE=y" >> $config_host_mak
|
||||||
fi
|
fi
|
||||||
|
if test "$posix_fallocate" = "yes" ; then
|
||||||
|
echo "CONFIG_POSIX_FALLOCATE=y" >> $config_host_mak
|
||||||
|
fi
|
||||||
if test "$sync_file_range" = "yes" ; then
|
if test "$sync_file_range" = "yes" ; then
|
||||||
echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak
|
echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue