[libvirt PATCH v3 1/7] api: add virNodeDevice(Get|Set)Autostart()

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

 



This will allow persistent mediated devices to be configured to be
restarted automatically when the host reboots.

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 include/libvirt/libvirt-nodedev.h |  6 +++
 src/driver-nodedev.h              | 10 ++++
 src/libvirt-nodedev.c             | 76 +++++++++++++++++++++++++++++++
 src/libvirt_public.syms           |  2 +
 src/remote/remote_driver.c        |  4 +-
 src/remote/remote_protocol.x      | 29 +++++++++++-
 src/remote_protocol-structs       | 12 +++++
 7 files changed, 137 insertions(+), 2 deletions(-)

diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index 067d914d37..0e841ada8a 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -141,6 +141,12 @@ int virNodeDeviceUndefine(virNodeDevicePtr dev,
 int virNodeDeviceCreate(virNodeDevicePtr dev,
                         unsigned int flags);
 
+int virNodeDeviceSetAutostart(virNodeDevicePtr dev,
+                              int autostart);
+
+int virNodeDeviceGetAutostart(virNodeDevicePtr dev,
+                              int *autostart);
+
 /**
  * VIR_NODE_DEVICE_EVENT_CALLBACK:
  *
diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h
index dd56421a54..125f4cfd9e 100644
--- a/src/driver-nodedev.h
+++ b/src/driver-nodedev.h
@@ -87,6 +87,14 @@ typedef int
 (*virDrvNodeDeviceCreate)(virNodeDevicePtr dev,
                           unsigned int flags);
 
+typedef int
+(*virDrvNodeDeviceSetAutostart)(virNodeDevicePtr dev,
+                                int autostart);
+
+typedef int
+(*virDrvNodeDeviceGetAutostart)(virNodeDevicePtr dev,
+                                int *autostart);
+
 typedef int
 (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn,
                                            virNodeDevicePtr dev,
@@ -128,4 +136,6 @@ struct _virNodeDeviceDriver {
     virDrvNodeDeviceDefineXML nodeDeviceDefineXML;
     virDrvNodeDeviceUndefine nodeDeviceUndefine;
     virDrvNodeDeviceCreate nodeDeviceCreate;
+    virDrvNodeDeviceSetAutostart nodeDeviceSetAutostart;
+    virDrvNodeDeviceGetAutostart nodeDeviceGetAutostart;
 };
diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c
index e416c12534..68fc83203d 100644
--- a/src/libvirt-nodedev.c
+++ b/src/libvirt-nodedev.c
@@ -979,3 +979,79 @@ virConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
     virDispatchError(conn);
     return -1;
 }
+
+/**
+ * virNodeDeviceSetAutostart:
+ * @dev: the device object
+ * @autostart: whether the device should be automatically started
+ *
+ * Configure the node device to be automatically started when the host machine
+ * boots or the parent device becomes available.
+ *
+ * Returns -1 in case of error, 0 in case of success
+ */
+int
+virNodeDeviceSetAutostart(virNodeDevicePtr dev,
+                          int autostart)
+{
+    VIR_DEBUG("dev=%p", dev);
+
+    virResetLastError();
+
+    virCheckNodeDeviceReturn(dev, -1);
+    virCheckReadOnlyGoto(dev->conn->flags, error);
+
+    if (dev->conn->nodeDeviceDriver &&
+        dev->conn->nodeDeviceDriver->nodeDeviceSetAutostart) {
+        int retval = dev->conn->nodeDeviceDriver->nodeDeviceSetAutostart(dev, autostart);
+        if (retval < 0)
+            goto error;
+
+        return 0;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(dev->conn);
+    return -1;
+}
+
+
+/**
+ * virNodeDeviceGetAutostart:
+ * @dev: the device object
+ * @autostart: the value returned
+ *
+ * Provides a boolean value indicating whether the node device is configured to
+ * be automatically started when the host machine boots or the parent device
+ * becomes available.
+ *
+ * Returns -1 in case of error, 0 in case of success
+ */
+int
+virNodeDeviceGetAutostart(virNodeDevicePtr dev,
+                          int *autostart)
+{
+    VIR_DEBUG("dev=%p", dev);
+
+    virResetLastError();
+
+    virCheckNodeDeviceReturn(dev, -1);
+    virCheckReadOnlyGoto(dev->conn->flags, error);
+
+    if (dev->conn->nodeDeviceDriver &&
+        dev->conn->nodeDeviceDriver->nodeDeviceGetAutostart) {
+        int retval = dev->conn->nodeDeviceDriver->nodeDeviceGetAutostart(dev, autostart);
+        if (retval < 0)
+            goto error;
+
+        return 0;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(dev->conn);
+    return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 68f5e9c900..206b20f773 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -899,6 +899,8 @@ LIBVIRT_7.3.0 {
 LIBVIRT_7.7.0 {
     global:
         virNWFilterDefineXMLFlags;
+        virNodeDeviceSetAutostart;
+        virNodeDeviceGetAutostart;
 } LIBVIRT_7.3.0;
 
 # .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 9ee22e7e15..d8febcf46f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8672,7 +8672,9 @@ static virNodeDeviceDriver node_device_driver = {
     .nodeDeviceCreate = remoteNodeDeviceCreate, /* 7.3.0 */
     .nodeDeviceDefineXML = remoteNodeDeviceDefineXML, /* 7.3.0 */
     .nodeDeviceUndefine = remoteNodeDeviceUndefine, /* 7.3.0 */
-    .nodeDeviceDestroy = remoteNodeDeviceDestroy /* 0.6.3 */
+    .nodeDeviceDestroy = remoteNodeDeviceDestroy, /* 0.6.3 */
+    .nodeDeviceGetAutostart = remoteNodeDeviceGetAutostart, /* 7.7.0 */
+    .nodeDeviceSetAutostart = remoteNodeDeviceSetAutostart, /* 7.7.0 */
 };
 
 static virNWFilterDriver nwfilter_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 56f610839e..c4f26ecb4c 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2173,6 +2173,19 @@ struct remote_node_device_create_args {
     unsigned int flags;
 };
 
+struct remote_node_device_get_autostart_args {
+    remote_nonnull_string name;
+};
+
+struct remote_node_device_get_autostart_ret {
+    int autostart;
+};
+
+struct remote_node_device_set_autostart_args {
+    remote_nonnull_string name;
+    int autostart;
+};
+
 
 /*
  * Events Register/Deregister:
@@ -6801,5 +6814,19 @@ enum remote_procedure {
      * @acl: nwfilter:write
      * @acl: nwfilter:save
      */
-    REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS = 431
+    REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS = 431,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: node_device:read
+     */
+    REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 432,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: node_device:write
+     */
+    REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 433
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index d51f12f781..dad3a418cb 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1622,6 +1622,16 @@ struct remote_node_device_create_args {
         remote_nonnull_string      name;
         u_int                      flags;
 };
+struct remote_node_device_get_autostart_args {
+        remote_nonnull_string      name;
+};
+struct remote_node_device_get_autostart_ret {
+        int                        autostart;
+};
+struct remote_node_device_set_autostart_args {
+        remote_nonnull_string      name;
+        int                        autostart;
+};
 struct remote_connect_domain_event_register_ret {
         int                        cb_registered;
 };
@@ -3631,4 +3641,6 @@ enum remote_procedure {
         REMOTE_PROC_NODE_DEVICE_UNDEFINE = 429,
         REMOTE_PROC_NODE_DEVICE_CREATE = 430,
         REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS = 431,
+        REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 432,
+        REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 433,
 };
-- 
2.31.1




[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]

  Powered by Linux