/*
* Pre allocate enough data for 1 block of leases at preferred alignment
*/
- if (safezero(fd, 0, rv, false) < 0) {
+ if (safezero(fd, 0, rv) < 0) {
virReportSystemError(errno,
_("Unable to allocate lockspace %s"),
path);
/*
* Pre allocate enough data for 1 block of leases at preferred alignment
*/
- if (safezero(fd, 0, rv, false) < 0) {
+ if (safezero(fd, 0, rv) < 0) {
virReportSystemError(errno,
_("Unable to allocate lease %s"),
res->disks[0].path);
off_t offset ATTRIBUTE_UNUSED,
off_t len ATTRIBUTE_UNUSED)
{
- return -1;
+ return -2;
}
#endif /* !HAVE_POSIX_FALLOCATE */
off_t offset,
off_t len)
{
- int rc = -1;
- rc = syscall(SYS_fallocate, fd, 0, offset, len);
- return rc;
+ return syscall(SYS_fallocate, fd, 0, offset, len);
}
#else /* !HAVE_SYS_SYSCALL_H || !defined(SYS_fallocate) */
static int
off_t offset ATTRIBUTE_UNUSED,
off_t len ATTRIBUTE_UNUSED)
{
- int rc = -1;
- errno = ENOSYS;
- return rc;
+ return -2;
}
#endif /* !HAVE_SYS_SYSCALL_H || !defined(SYS_fallocate) */
/* fall back to writing zeroes using safewrite if mmap fails (for
* example because of virtual memory limits) */
- return -1;
+ return -2;
}
#else /* !HAVE_MMAP */
static int
off_t offset ATTRIBUTE_UNUSED,
off_t len ATTRIBUTE_UNUSED)
{
- return -1;
+ return -2;
}
#endif /* !HAVE_MMAP */
return 0;
}
-int safezero(int fd, off_t offset, off_t len, bool resize)
+int safezero(int fd, off_t offset, off_t len)
{
int ret;
- /* posix_fallocate returns 0 on success or error number on failure,
- * but errno is not set so use that to our advantage since we set
- * errno to the returned value if we make the call. If we don't make
- * the call because it doesn't exist, then errno won't change and
- * we can try other methods.
- */
- errno = 0;
ret = safezero_posix_fallocate(fd, offset, len);
- if (ret == 0 || errno != 0)
+ if (ret != -2)
return ret;
- if (resize)
- return safezero_sys_fallocate(fd, offset, len);
-
- if (safezero_mmap(fd, offset, len) == 0)
+ if (safezero_sys_fallocate(fd, offset, len) == 0)
return 0;
+
+ ret = safezero_mmap(fd, offset, len);
+ if (ret != -2)
+ return ret;
return safezero_slow(fd, offset, len);
}
ssize_t saferead(int fd, void *buf, size_t count) ATTRIBUTE_RETURN_CHECK;
ssize_t safewrite(int fd, const void *buf, size_t count)
ATTRIBUTE_RETURN_CHECK;
-int safezero(int fd, off_t offset, off_t len, bool resize)
+int safezero(int fd, off_t offset, off_t len)
ATTRIBUTE_RETURN_CHECK;
/* Don't call these directly - use the macros below */
}
if (pre_allocate) {
- if (safezero(fd, offset, len, true) != 0) {
- if (errno == ENOSYS)
- virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
- _("preallocate is not supported on this "
- "platform"));
- else
- virReportSystemError(errno,
- _("Failed to pre-allocate space for "
- "file '%s'"), path);
+ if (safezero(fd, offset, len) != 0) {
+ virReportSystemError(errno,
+ _("Failed to pre-allocate space for "
+ "file '%s'"), path);
goto cleanup;
}
} else {