Use fsync() at the end of file allocation instead of O_DSYNC

Instead of opening storage file with O_DSYNC, make sure data are written
to a disk only before we claim allocation has finished.
This commit is contained in:
Jiri Denemark 2010-03-16 16:03:59 +01:00
parent c78c9f5a9b
commit e3c36a2575

View File

@ -331,6 +331,13 @@ static int createRawFileOpHook(int fd, void *data) {
goto cleanup; goto cleanup;
} }
} }
if (fsync(fd) < 0) {
ret = errno;
virReportSystemError(errno, _("cannot sync data to file '%s'"),
hdata->vol->target.path);
goto cleanup;
}
} }
cleanup: cleanup:
@ -359,7 +366,7 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
gid_t gid = (vol->target.perms.gid == -1) ? getgid() : vol->target.perms.gid; gid_t gid = (vol->target.perms.gid == -1) ? getgid() : vol->target.perms.gid;
if ((createstat = virFileOperation(vol->target.path, if ((createstat = virFileOperation(vol->target.path,
O_RDWR | O_CREAT | O_EXCL | O_DSYNC, O_RDWR | O_CREAT | O_EXCL,
vol->target.perms.mode, uid, gid, vol->target.perms.mode, uid, gid,
createRawFileOpHook, &hdata, createRawFileOpHook, &hdata,
VIR_FILE_OP_FORCE_PERMS | VIR_FILE_OP_FORCE_PERMS |