int unused[15];
};
-struct fileOpHookData {
- virDomainPtr dom;
- const char *path;
- char *xml;
- struct qemud_save_header *header;
-};
-
/* return -errno on failure, or 0 on success */
-static int qemudDomainSaveFileOpHook(int fd, void *data) {
- struct fileOpHookData *hdata = data;
+static int
+qemuDomainSaveHeader(int fd, const char *path, char *xml,
+ struct qemud_save_header *header)
+{
int ret = 0;
- if (safewrite(fd, hdata->header, sizeof(*hdata->header)) != sizeof(*hdata->header)) {
+ if (safewrite(fd, header, sizeof(*header)) != sizeof(*header)) {
ret = -errno;
qemuReportError(VIR_ERR_OPERATION_FAILED,
_("failed to write header to domain save file '%s'"),
- hdata->path);
+ path);
goto endjob;
}
- if (safewrite(fd, hdata->xml, hdata->header->xml_len) != hdata->header->xml_len) {
+ if (safewrite(fd, xml, header->xml_len) != header->xml_len) {
ret = -errno;
qemuReportError(VIR_ERR_OPERATION_FAILED,
- _("failed to write xml to '%s'"), hdata->path);
+ _("failed to write xml to '%s'"), path);
goto endjob;
}
endjob:
{
char *xml = NULL;
struct qemud_save_header header;
- struct fileOpHookData hdata;
int bypassSecurityDriver = 0;
int ret = -1;
int rc;
}
/* Write header to file, followed by XML */
- hdata.dom = dom;
- hdata.path = path;
- hdata.xml = xml;
- hdata.header = &header;
-
- if (qemudDomainSaveFileOpHook(fd, &hdata) < 0) {
+ if (qemuDomainSaveHeader(fd, path, xml, &header) < 0) {
VIR_FORCE_CLOSE(fd);
goto endjob;
}
return ret;
}
-struct createRawFileOpHookData {
- virStorageVolDefPtr vol;
- virStorageVolDefPtr inputvol;
-};
-
-static int createRawFileOpHook(int fd, void *data) {
- struct createRawFileOpHookData *hdata = data;
+static int
+createRawFile(int fd, virStorageVolDefPtr vol,
+ virStorageVolDefPtr inputvol)
+{
int ret = 0;
unsigned long long remain;
/* Seek to the final size, so the capacity is available upfront
* for progress reporting */
- if (ftruncate(fd, hdata->vol->capacity) < 0) {
+ if (ftruncate(fd, vol->capacity) < 0) {
ret = -errno;
virReportSystemError(errno,
_("cannot extend file '%s'"),
- hdata->vol->target.path);
+ vol->target.path);
goto cleanup;
}
- remain = hdata->vol->allocation;
+ remain = vol->allocation;
- if (hdata->inputvol) {
- ret = virStorageBackendCopyToFD(hdata->vol, hdata->inputvol,
- fd, &remain, 1);
+ if (inputvol) {
+ ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, 1);
if (ret < 0) {
goto cleanup;
}
if (bytes > remain)
bytes = remain;
- if (safezero(fd, 0, hdata->vol->allocation - remain,
- bytes) != 0) {
+ if (safezero(fd, 0, vol->allocation - remain, bytes) != 0) {
ret = -errno;
virReportSystemError(errno, _("cannot fill file '%s'"),
- hdata->vol->target.path);
+ vol->target.path);
goto cleanup;
}
remain -= bytes;
if (safezero(fd, 0, 0, remain) != 0) {
ret = -errno;
virReportSystemError(errno, _("cannot fill file '%s'"),
- hdata->vol->target.path);
+ vol->target.path);
goto cleanup;
}
}
if (fsync(fd) < 0) {
ret = -errno;
virReportSystemError(errno, _("cannot sync data to file '%s'"),
- hdata->vol->target.path);
+ vol->target.path);
goto cleanup;
}
{
int ret = -1;
int fd = -1;
- struct createRawFileOpHookData hdata = { vol, inputvol };
uid_t uid;
gid_t gid;
int operation_flags;
goto cleanup;
}
- if ((ret = createRawFileOpHook(fd, &hdata)) < 0) {
+ if ((ret = createRawFile(fd, vol, inputvol)) < 0) {
virReportSystemError(-fd,
_("cannot create path '%s'"),
vol->target.path);