[PATCH 2/4] qemu driver for new APIs to manage saved-state & core-dump files

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

 



qemu driver implementation of new APIs.

* src/qemu/qemu_driver.c: qemu driver implementation

Signed-off-by: Hong Xiang <hxiang@xxxxxxxxxxxxxxxxxx>
---
 src/qemu/qemu_driver.c |  253 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 253 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 36d6284..0dc0530 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3113,6 +3113,128 @@ cleanup:
     return ret;
 }
 
+static int
+qemuNumOfCoreDumps(virConnectPtr conn)
+{
+    struct qemud_driver *driver = conn->privateData;
+    DIR * dir = NULL;
+    struct dirent * ent;
+    int num = 0;
+
+    qemuDriverLock(driver);
+    if (NULL == (dir = opendir(driver->coreDumpDir))) {
+        qemuReportError(VIR_ERR_OPEN_FAILED, _("cannot open directory '%s'"),
+                        driver->coreDumpDir);
+        goto cleanup;
+    }
+    while (NULL != (ent = readdir(dir))) {
+        if('.' == ent->d_name[0])
+            continue;
+        num ++;
+    }
+    closedir(dir);
+    qemuDriverUnlock(driver);
+    return num;
+
+cleanup:
+    if (NULL != dir)
+        closedir(dir);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
+static int
+qemuListCoreDumps(virConnectPtr conn,
+                         char **const files,
+                         int maxfiles)
+{
+    struct qemud_driver *driver = conn->privateData;
+    DIR * dir = NULL;
+    struct dirent * ent;
+    int num = 0;
+
+    qemuDriverLock(driver);
+    if (NULL == (dir = opendir(driver->coreDumpDir))) {
+        qemuReportError(VIR_ERR_SYSTEM_ERROR, _("cannot open directory '%s'"),
+                        driver->coreDumpDir);
+        goto cleanup;
+    }
+    while (NULL != (ent = readdir(dir))) {
+        int res;
+        if ('.' == ent->d_name[0])
+            continue;
+        if (num >= maxfiles)
+            break;
+        res = virBase64DecodePathname(ent->d_name, &(files[num]));
+        if (-2 == res) {
+            VIR_WARN("Invalid coredump name '%s'", ent->d_name);
+            continue;
+        } else if (0 > res) {
+            goto cleanup;
+        }
+        num ++;
+    }
+    closedir(dir);
+    qemuDriverUnlock(driver);
+    return num;
+
+cleanup:
+    for ( ; num > 0; num --) {
+        VIR_FREE(files[num - 1]);
+    }
+    if (NULL != dir)
+        closedir(dir);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
+static int
+qemuCoreDumpRemove(virConnectPtr conn,
+                          const char *file)
+{
+    struct qemud_driver *driver = conn->privateData;
+    char *path = NULL;
+
+    qemuDriverLock(driver);
+    if (NULL == (path = qemuCoreDumpPath(driver, file)))
+        goto cleanup;
+    if (unlink(path)) {
+        qemuReportError(VIR_ERR_SYSTEM_ERROR, _("cannot remove '%s'"), path);
+        goto cleanup;
+    }
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return 0;
+
+cleanup:
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
+static int
+qemuCoreDumpDownload(virConnectPtr conn,
+                            virStreamPtr stream,
+                            const char *file)
+{
+    struct qemud_driver *driver = conn->privateData;
+    char *path = NULL;
+
+    qemuDriverLock(driver);
+    if (NULL == (path = qemuCoreDumpPath(driver, file)))
+        goto cleanup;
+    if (virFDStreamOpenFile(stream, path, 0, 0, O_RDONLY))
+        goto cleanup;
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return 0;
+
+cleanup:
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
 static char *
 qemuDomainScreenshot(virDomainPtr dom,
                      virStreamPtr st,
@@ -4439,6 +4561,129 @@ cleanup:
     return ret;
 }
 
+static int
+qemuNumOfSavedImages(virConnectPtr conn)
+{
+    struct qemud_driver *driver = conn->privateData;
+    DIR * dir = NULL;
+    struct dirent * ent;
+    int num = 0;
+
+    qemuDriverLock(driver);
+    if (NULL == (dir = opendir(driver->savedImageDir))) {
+        qemuReportError(VIR_ERR_OPEN_FAILED, _("cannot open directory '%s'"),
+                        driver->savedImageDir);
+        goto cleanup;
+    }
+    while (NULL != (ent = readdir(dir))) {
+        if ('.' == ent->d_name[0])
+            continue;
+        num ++;
+    }
+    closedir(dir);
+    qemuDriverUnlock(driver);
+    return num;
+
+cleanup:
+    if (NULL != dir)
+        closedir(dir);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
+static int
+qemuListSavedImages(virConnectPtr conn,
+                         char **const files,
+                         int maxfiles)
+{
+    struct qemud_driver *driver = conn->privateData;
+    DIR * dir = NULL;
+    struct dirent * ent;
+    int num = 0;
+
+    qemuDriverLock(driver);
+    if (NULL == (dir = opendir(driver->savedImageDir))) {
+        qemuReportError(VIR_ERR_SYSTEM_ERROR, _("cannot open directory '%s'"),
+                        driver->savedImageDir);
+        goto cleanup;
+    }
+    while (NULL != (ent = readdir(dir))) {
+        int res;
+
+        if ('.' == ent->d_name[0])
+            continue;
+        if (num >= maxfiles)
+            break;
+        res = virBase64DecodePathname(ent->d_name, &(files[num]));
+        if (-2 == res) {
+            VIR_WARN("Invalid saved image name '%s'", ent->d_name);
+            continue;
+        } else if (0 > res) {
+            goto cleanup;
+        }
+        num ++;
+    }
+    closedir(dir);
+    qemuDriverUnlock(driver);
+    return num;
+
+cleanup:
+    for ( ; num > 0; num --) {
+        VIR_FREE(files[num - 1]);
+    }
+    if (NULL != dir)
+        closedir(dir);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
+static int
+qemuSavedImageRemove(virConnectPtr conn,
+                          const char *file)
+{
+    struct qemud_driver *driver = conn->privateData;
+    char *path = NULL;
+
+    qemuDriverLock(driver);
+    if (NULL == (path = qemuSavedImagePath(driver, file)))
+        goto cleanup;
+    if (unlink(path)) {
+        qemuReportError(VIR_ERR_SYSTEM_ERROR, _("cannot remove '%s'"), path);
+        goto cleanup;
+    }
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return 0;
+
+cleanup:
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
+static int
+qemuSavedImageDownload(virConnectPtr conn,
+                            virStreamPtr stream,
+                            const char *file)
+{
+    struct qemud_driver *driver = conn->privateData;
+    char *path = NULL;
+
+    qemuDriverLock(driver);
+    if (NULL == (path = qemuSavedImagePath(driver, file)))
+        goto cleanup;
+    if (virFDStreamOpenFile(stream, path, 0, 0, O_RDONLY))
+        goto cleanup;
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return 0;
+
+cleanup:
+    VIR_FREE(path);
+    qemuDriverUnlock(driver);
+    return -1;
+}
+
 /* Return 0 on success, 1 if incomplete saved image was silently unlinked,
  * and -1 on failure with error raised.  */
 static int
@@ -10893,6 +11138,14 @@ static virDriver qemuDriver = {
     .domainGetBlockJobInfo = qemuDomainGetBlockJobInfo, /* 0.9.4 */
     .domainBlockJobSetSpeed = qemuDomainBlockJobSetSpeed, /* 0.9.4 */
     .domainBlockPull = qemuDomainBlockPull, /* 0.9.4 */
+    .numOfSavedImages = qemuNumOfSavedImages, /* 0.9.8 */
+    .listSavedImages = qemuListSavedImages, /* 0.9.8 */
+    .savedImageRemove = qemuSavedImageRemove, /* 0.9.8 */
+    .savedImageDownload = qemuSavedImageDownload, /* 0.9.8 */
+    .numOfCoreDumps = qemuNumOfCoreDumps, /* 0.9.8 */
+    .listCoreDumps = qemuListCoreDumps, /* 0.9.8 */
+    .coreDumpRemove = qemuCoreDumpRemove, /* 0.9.8 */
+    .coreDumpDownload = qemuCoreDumpDownload, /* 0.9.8 */
 };
 
 
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]