[libvirt PATCH 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>
---
 include/libvirt/libvirt-nodedev.h |  6 +++
 src/driver-nodedev.h              | 10 ++++
 src/libvirt-nodedev.c             | 76 +++++++++++++++++++++++++++++++
 src/libvirt_public.syms           |  4 ++
 src/remote/remote_driver.c        |  4 +-
 src/remote/remote_protocol.x      | 29 +++++++++++-
 src/remote_protocol-structs       | 12 +++++
 7 files changed, 139 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 5678a13cda..a21bd6ac7d 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -896,4 +896,8 @@ LIBVIRT_7.3.0 {
         virNodeDeviceCreate;
 } LIBVIRT_7.2.0;
 
+LIBVIRT_7.5.0 {
+        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 48423f3619..9070f648e2 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8717,7 +8717,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.5.0 */
+    .nodeDeviceSetAutostart = remoteNodeDeviceSetAutostart, /* 7.5.0 */
 };
 
 static virNWFilterDriver nwfilter_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index de69704b68..a98ab49f2e 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2164,6 +2164,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:
@@ -6784,6 +6797,20 @@ enum remote_procedure {
      * @priority: high
      * @acl: node_device:start
      */
-    REMOTE_PROC_NODE_DEVICE_CREATE = 430
+    REMOTE_PROC_NODE_DEVICE_CREATE = 430,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: node_device:read
+     */
+    REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 431,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: node_device:write
+     */
+    REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 432
 
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 6b46328adc..b17372537b 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1615,6 +1615,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;
 };
@@ -3623,4 +3633,6 @@ enum remote_procedure {
         REMOTE_PROC_NODE_DEVICE_DEFINE_XML = 428,
         REMOTE_PROC_NODE_DEVICE_UNDEFINE = 429,
         REMOTE_PROC_NODE_DEVICE_CREATE = 430,
+        REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 431,
+        REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 432,
 };
-- 
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