[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv4 11/15] qemu, storage: improve type safety



* src/storage/storage_backend.c (createRawFileOpHook): Change
signature.
(struct createRawFileOpHookData): Delete unused struct.
(virStorageBackendCreateRaw): Adjust caller.
* src/qemu/qemu_driver.c (struct fileOpHookData): Delete unused
struct.
(qemudDomainSaveFileOpHook): Rename...
(qemuDomainSaveFileOpHook): ...and change signature.
(qemudDomainSaveFlag): Adjust caller.
---

Phooey - Just noticed that my ISP griped that git send-email sent too
many mails in one session (is there a setting to tweak to force multiple
sessions?)  Hopefully I rethreaded this correctly.

 src/qemu/qemu_driver.c        |   29 +++++++++--------------------
 src/storage/storage_backend.c |   34 ++++++++++++++--------------------
 2 files changed, 23 insertions(+), 40 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 06bc969..11ba910 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1741,30 +1741,25 @@ struct qemud_save_header {
     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:
@@ -1780,7 +1775,6 @@ static int qemudDomainSaveFlag(struct qemud_driver *driver, virDomainPtr dom,
 {
     char *xml = NULL;
     struct qemud_save_header header;
-    struct fileOpHookData hdata;
     int bypassSecurityDriver = 0;
     int ret = -1;
     int rc;
@@ -1946,12 +1940,7 @@ static int qemudDomainSaveFlag(struct qemud_driver *driver, virDomainPtr dom,
     }

     /* 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;
     }
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 7a3a2b8..be980b0 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -266,31 +266,27 @@ cleanup:
     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;
         }
@@ -308,11 +304,10 @@ static int createRawFileOpHook(int fd, void *data) {

                 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;
@@ -321,7 +316,7 @@ static int createRawFileOpHook(int fd, void *data) {
             if (safezero(fd, 0, 0, remain) != 0) {
                 ret = -errno;
                 virReportSystemError(errno, _("cannot fill file '%s'"),
-                                     hdata->vol->target.path);
+                                     vol->target.path);
                 goto cleanup;
             }
         }
@@ -331,7 +326,7 @@ static int createRawFileOpHook(int fd, void *data) {
     if (fsync(fd) < 0) {
         ret = -errno;
         virReportSystemError(errno, _("cannot sync data to file '%s'"),
-                             hdata->vol->target.path);
+                             vol->target.path);
         goto cleanup;
     }

@@ -348,7 +343,6 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
 {
     int ret = -1;
     int fd = -1;
-    struct createRawFileOpHookData hdata = { vol, inputvol };
     uid_t uid;
     gid_t gid;
     int operation_flags;
@@ -378,7 +372,7 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
         goto cleanup;
     }

-    if ((ret = createRawFileOpHook(fd, &hdata)) < 0) {
+    if ((ret = createRawFile(fd, vol, inputvol)) < 0) {
         virReportSystemError(-fd,
                              _("cannot create path '%s'"),
                              vol->target.path);
-- 
1.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]