[PATCH 1/4] New APIs to manage saved-state & core-dump files.

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

 



New APIS:
. virConnectNumOfSavedImages
. virConnectListSavedImages
. virSavedImageRemove
. virSavedImageDownload
. virConnectNumOfCoreDumps
. virConnectListCoreDumps
. virCoreDumpRemove
. virCoreDumpDownload

* include/libvirt/libvirt.h.in: declarations
* src/driver.h: driver extension for new APIs
* src/libvirt.c, src/libvirt_public.syms: entry points for new APIs
* python/generator.py,
  python/libvirt-override-api.xml,
  python/libvirt-override.c: overridden python binding

Signed-off-by: Hong Xiang <hxiang@xxxxxxxxxxxxxxxxxx>
---
 include/libvirt/libvirt.h.in    |   18 +++
 python/generator.py             |    2 +
 python/libvirt-override-api.xml |   10 ++
 python/libvirt-override.c       |   92 ++++++++++++
 src/driver.h                    |   34 +++++
 src/libvirt.c                   |  314 +++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms         |   12 ++
 7 files changed, 482 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 361881a..6a2c4e4 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1084,6 +1084,15 @@ int             virDomainSaveImageDefineXML     (virConnectPtr conn,
                                                  const char *file,
                                                  const char *dxml,
                                                  unsigned int flags);
+int             virConnectNumOfSavedImages      (virConnectPtr conn);
+int             virConnectListSavedImages       (virConnectPtr conn,
+                                                 char **const files,
+                                                 int maxfiles);
+int             virSavedImageRemove             (virConnectPtr conn,
+                                                 const char *file);
+int             virSavedImageDownload           (virConnectPtr conn,
+                                                 virStreamPtr stream,
+                                                 const char *file);
 
 /*
  * Managed domain save
@@ -1101,6 +1110,15 @@ int                    virDomainManagedSaveRemove(virDomainPtr dom,
 int                     virDomainCoreDump       (virDomainPtr domain,
                                                  const char *to,
                                                  unsigned int flags);
+int                     virConnectNumOfCoreDumps(virConnectPtr conn);
+int                     virConnectListCoreDumps (virConnectPtr conn,
+                                                 char **const files,
+                                                 int maxfiles);
+int                     virCoreDumpRemove       (virConnectPtr conn,
+                                                 const char *file);
+int                     virCoreDumpDownload     (virConnectPtr conn,
+                                                 virStreamPtr stream,
+                                                 const char *file);
 
 /*
  * Screenshot of current domain console
diff --git a/python/generator.py b/python/generator.py
index 71afdb7..6ce5add 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -414,6 +414,8 @@ skip_impl = (
     'virDomainGetBlockJobInfo',
     'virDomainMigrateGetMaxSpeed',
     'virDomainBlockStatsFlags',
+    'virConnectListSavedImages',
+    'virConnectListCoreDumps',
 )
 
 qemu_skip_impl = (
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index ef02f34..4a71afb 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -375,5 +375,15 @@
       <arg name='flags' type='unsigned int' info='flags, currently unused, pass 0.'/>
       <return type='unsigned long' info='current max migration speed, or None in case of error'/>
     </function>
+    <function name='virConnectListSavedImages' file='python'>
+      <info>Lists saved state files.</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <return type='str *' info='the list of Names of None in case of error'/>
+    </function>
+    <function name='virConnectListCoreDumps' file='python'>
+      <info>Lists core dump files.</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <return type='str *' info='the list of Names of None in case of error'/>
+    </function>
   </symbols>
 </api>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 523c03b..caee110 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -4695,6 +4695,96 @@ libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *a
     return(py_retval);
 }
 
+static PyObject *
+libvirt_virConnectListSavedImages(PyObject *self ATTRIBUTE_UNUSED,
+                                     PyObject *args) {
+    PyObject *py_retval;
+    char **names = NULL;
+    int c_retval, i;
+    virConnectPtr conn;
+    PyObject *pyobj_conn;
+
+
+    if (!PyArg_ParseTuple(args, (char *)"O:virConnectListSavedImages", &pyobj_conn))
+        return(NULL);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virConnectNumOfSavedImages(conn);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (c_retval < 0)
+        return VIR_PY_NONE;
+
+    if (c_retval) {
+        names = malloc(sizeof(*names) * c_retval);
+        if (!names)
+            return VIR_PY_NONE;
+        LIBVIRT_BEGIN_ALLOW_THREADS;
+        c_retval = virConnectListSavedImages(conn, names, c_retval);
+        LIBVIRT_END_ALLOW_THREADS;
+        if (c_retval < 0) {
+            free(names);
+            return VIR_PY_NONE;
+        }
+    }
+    py_retval = PyList_New(c_retval);
+
+    if (names) {
+        for (i = 0;i < c_retval;i++) {
+            PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+            free(names[i]);
+        }
+        free(names);
+    }
+
+    return(py_retval);
+}
+
+static PyObject *
+libvirt_virConnectListCoreDumps(PyObject *self ATTRIBUTE_UNUSED,
+                                     PyObject *args) {
+    PyObject *py_retval;
+    char **names = NULL;
+    int c_retval, i;
+    virConnectPtr conn;
+    PyObject *pyobj_conn;
+
+
+    if (!PyArg_ParseTuple(args, (char *)"O:virConnectListCoreDumps", &pyobj_conn))
+        return(NULL);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virConnectNumOfCoreDumps(conn);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (c_retval < 0)
+        return VIR_PY_NONE;
+
+    if (c_retval) {
+        names = malloc(sizeof(*names) * c_retval);
+        if (!names)
+            return VIR_PY_NONE;
+        LIBVIRT_BEGIN_ALLOW_THREADS;
+        c_retval = virConnectListCoreDumps(conn, names, c_retval);
+        LIBVIRT_END_ALLOW_THREADS;
+        if (c_retval < 0) {
+            free(names);
+            return VIR_PY_NONE;
+        }
+    }
+    py_retval = PyList_New(c_retval);
+
+    if (names) {
+        for (i = 0;i < c_retval;i++) {
+            PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+            free(names[i]);
+        }
+        free(names);
+    }
+
+    return(py_retval);
+}
+
 /************************************************************************
  *									*
  *			The registration stuff				*
@@ -4786,6 +4876,8 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL},
     {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
     {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
+    {(char *) "virConnectListSavedImages", libvirt_virConnectListSavedImages, METH_VARARGS, NULL},
+    {(char *) "virConnectListCoreDumps", libvirt_virConnectListCoreDumps, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
diff --git a/src/driver.h b/src/driver.h
index b899d0e..f83db6f 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -734,6 +734,32 @@ typedef int
 typedef int
     (*virDrvDomainBlockPull)(virDomainPtr dom, const char *path,
                              unsigned long bandwidth, unsigned int flags);
+typedef int
+        (*virDrvNumOfSavedImages)       (virConnectPtr conn);
+typedef int
+        (*virDrvListSavedImages)        (virConnectPtr conn,
+                                         char **const files,
+                                         int maxfiles);
+typedef int
+        (*virDrvSavedImageRemove)       (virConnectPtr conn,
+                                         const char *file);
+typedef int
+        (*virDrvSavedImageDownload)     (virConnectPtr conn,
+                                         virStreamPtr stream,
+                                         const char *file);
+typedef int
+        (*virDrvNumOfCoreDumps)         (virConnectPtr conn);
+typedef int
+        (*virDrvListCoreDumps)          (virConnectPtr conn,
+                                         char **const files,
+                                         int maxfiles);
+typedef int
+        (*virDrvCoreDumpRemove)         (virConnectPtr conn,
+                                         const char *file);
+typedef int
+        (*virDrvCoreDumpDownload)       (virConnectPtr conn,
+                                         virStreamPtr stream,
+                                         const char *file);
 
 
 /**
@@ -893,6 +919,14 @@ struct _virDriver {
     virDrvDomainGetBlockJobInfo domainGetBlockJobInfo;
     virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed;
     virDrvDomainBlockPull domainBlockPull;
+    virDrvNumOfSavedImages      numOfSavedImages;
+    virDrvListSavedImages       listSavedImages;
+    virDrvSavedImageRemove      savedImageRemove;
+    virDrvSavedImageDownload    savedImageDownload;
+    virDrvNumOfCoreDumps        numOfCoreDumps;
+    virDrvListCoreDumps         listCoreDumps;
+    virDrvCoreDumpRemove        coreDumpRemove;
+    virDrvCoreDumpDownload      coreDumpDownload;
 };
 
 typedef int
diff --git a/src/libvirt.c b/src/libvirt.c
index 5de60c7..b715f0b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2829,6 +2829,163 @@ error:
 }
 
 /**
+ * virConnectNumOfSavedImages:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Provides the number of saved state files.
+ *
+ * Returns number of saved state files on success and -1 on failure.
+ */
+int
+virConnectNumOfSavedImages(virConnectPtr conn)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->driver->numOfSavedImages) {
+        int ret;
+
+        ret = conn->driver->numOfSavedImages(conn);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
+ * virConnectListSavedImages:
+ * @conn: pointer to the hypervisor connection
+ * @files: pointer to array to store save state filenames
+ * @maxfiles: size of the array
+ *
+ * Lists saved state files.
+ *
+ * Returns number of saved state files on success and -1 on failure.
+ */
+int
+virConnectListSavedImages(virConnectPtr conn,
+                          char **const files,
+                          int maxfiles)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->driver->listSavedImages) {
+        int ret;
+
+        ret = conn->driver->listSavedImages(conn, files, maxfiles);
+        if (ret < 0)
+            goto error;
+
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
+ * virSavedImageRemove:
+ * @conn: pointer to the hypervisor connection
+ * @file: path to saved state file
+ *
+ * Removes specified saved state file.
+ *
+ * Returns 0 on success and -1 on failure.
+ */
+int
+virSavedImageRemove(virConnectPtr conn, const char *file)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->savedImageRemove) {
+        int ret;
+
+        ret = conn->driver->savedImageRemove(conn, file);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
+ * virSavedImageDownload:
+ * @conn: pointer to the hypervisor connection
+ * @stream: stream to use as output
+ * @file: path to saved state file
+ *
+ * Downloads specified saved state file.
+ *
+ * Returns 0 on success and -1 on failure.
+ */
+int
+virSavedImageDownload(virConnectPtr conn,
+                             virStreamPtr stream,
+                             const char *file)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->driver->savedImageDownload) {
+        int ret;
+
+        ret = conn->driver->savedImageDownload(conn, stream, file);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
  * virDomainCoreDump:
  * @domain: a domain object
  * @to: path for the core file
@@ -2913,6 +3070,163 @@ error:
 }
 
 /**
+ * virConnectNumOfCoreDumps:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Provides number of core files.
+ *
+ * Returns number of core files on success and -1 on failure.
+ */
+int
+virConnectNumOfCoreDumps(virConnectPtr conn)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->driver->numOfCoreDumps) {
+        int ret;
+
+        ret = conn->driver->numOfCoreDumps(conn);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
+ * virConnectListCoreDumps:
+ * @conn: pointer to the hypervisor connection
+ * @files: pointer to array to store core filenames
+ * @maxfiles: size of the array
+ *
+ * Lists core files.
+ *
+ * Returns number of core files on success and -1 on failure.
+ */
+int
+virConnectListCoreDumps(virConnectPtr conn,
+                        char **const files,
+                        int maxfiles)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->driver->listCoreDumps) {
+        int ret;
+
+        ret = conn->driver->listCoreDumps(conn, files, maxfiles);
+        if (ret < 0)
+            goto error;
+
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
+ * virCoreDumpRemove:
+ * @conn: pointer to the hypervisor connection
+ * @file: path to core file
+ *
+ * Removes specified core file.
+ *
+ * Returns 0 on success and -1 on failure.
+ */
+int
+virCoreDumpRemove(virConnectPtr conn, const char *file)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->coreDumpRemove) {
+        int ret;
+
+        ret = conn->driver->coreDumpRemove(conn, file);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
+ * virCoreDumpDownload:
+ * @conn: pointer to the hypervisor connection
+ * @stream: stream to use as output
+ * @file: path to core file
+ *
+ * Downloads specified core file.
+ *
+ * Returns 0 on success and -1 on failure.
+ */
+int
+virCoreDumpDownload(virConnectPtr conn,
+                           virStreamPtr stream,
+                           const char *file)
+{
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->driver->coreDumpDownload) {
+        int ret;
+
+        ret = conn->driver->coreDumpDownload(conn, stream, file);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
  * virDomainScreenshot:
  * @domain: a domain object
  * @stream: stream to use as output
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 9762fc4..b97b24f 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -498,3 +498,15 @@ LIBVIRT_0.9.7 {
 } LIBVIRT_0.9.5;
 
 # .... define new API here using predicted next version number ....
+
+LIBVIRT_0.9.8 {
+    global:
+        virConnectNumOfSavedImages;
+        virConnectListSavedImages;
+        virSavedImageRemove;
+        virSavedImageDownload;
+        virConnectNumOfCoreDumps;
+        virConnectListCoreDumps;
+        virCoreDumpRemove;
+        virCoreDumpDownload;
+} LIBVIRT_0.9.7;
-- 
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]