[libvirt PATCH v3 6/7] nodedev: Implement virNodeDeviceIsPersistent()/IsActive()

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

 



Implement these new API functions in the nodedev driver.

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/node_device/node_device_driver.c | 50 ++++++++++++++++++++++++++++
 src/node_device/node_device_driver.h |  6 ++++
 src/node_device/node_device_udev.c   | 10 ++++--
 3 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index bb18b24e53..3bc6eb1c11 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1989,3 +1989,53 @@ int nodeDeviceDefValidate(virNodeDeviceDef *def,
     }
     return 0;
 }
+
+
+int
+nodeDeviceIsPersistent(virNodeDevice *device)
+{
+    virNodeDeviceObj *obj = NULL;
+    virNodeDeviceDef *def = NULL;
+    int ret = -1;
+
+    if (nodeDeviceInitWait() < 0)
+        return -1;
+
+    if (!(obj = nodeDeviceObjFindByName(device->name)))
+        return -1;
+    def = virNodeDeviceObjGetDef(obj);
+
+    if (virNodeDeviceIsPersistentEnsureACL(device->conn, def) < 0)
+        goto cleanup;
+
+    ret = virNodeDeviceObjIsPersistent(obj);
+
+ cleanup:
+    virNodeDeviceObjEndAPI(&obj);
+    return ret;
+}
+
+
+int
+nodeDeviceIsActive(virNodeDevice *device)
+{
+    virNodeDeviceObj *obj = NULL;
+    virNodeDeviceDef *def = NULL;
+    int ret = -1;
+
+    if (nodeDeviceInitWait() < 0)
+        return -1;
+
+    if (!(obj = nodeDeviceObjFindByName(device->name)))
+        return -1;
+    def = virNodeDeviceObjGetDef(obj);
+
+    if (virNodeDeviceIsActiveEnsureACL(device->conn, def) < 0)
+        goto cleanup;
+
+    ret = virNodeDeviceObjIsActive(obj);
+
+ cleanup:
+    virNodeDeviceObjEndAPI(&obj);
+    return ret;
+}
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 17c7473d85..7311b603ac 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -186,6 +186,12 @@ int
 nodeDeviceGetAutostart(virNodeDevice *dev,
                        int *autostart);
 
+int
+nodeDeviceIsPersistent(virNodeDevice *dev);
+
+int
+nodeDeviceIsActive(virNodeDevice *dev);
+
 virCommand*
 nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def,
                                         bool autostart,
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 73334c1cc7..0f1770f771 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1503,7 +1503,7 @@ udevAddOneDevice(struct udev_device *device)
     virObjectEvent *event = NULL;
     bool new_device = true;
     int ret = -1;
-    bool was_persistent = false;
+    bool persistent = false;
     bool autostart = false;
     bool is_mdev;
 
@@ -1534,7 +1534,8 @@ udevAddOneDevice(struct udev_device *device)
 
         if (is_mdev)
             nodeDeviceDefCopyFromMdevctl(def, objdef);
-        was_persistent = virNodeDeviceObjIsPersistent(obj);
+
+        persistent = virNodeDeviceObjIsPersistent(obj);
         autostart = virNodeDeviceObjIsAutostart(obj);
 
         /* If the device was defined by mdevctl and was never instantiated, it
@@ -1548,7 +1549,7 @@ udevAddOneDevice(struct udev_device *device)
      * and the current definition will take its place. */
     if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
         goto cleanup;
-    virNodeDeviceObjSetPersistent(obj, was_persistent);
+    virNodeDeviceObjSetPersistent(obj, persistent);
     virNodeDeviceObjSetAutostart(obj, autostart);
     objdef = virNodeDeviceObjGetDef(obj);
 
@@ -1954,6 +1955,7 @@ udevSetupSystemDev(void)
 
     virNodeDeviceObjSetActive(obj, true);
     virNodeDeviceObjSetAutostart(obj, true);
+    virNodeDeviceObjSetPersistent(obj, true);
 
     virNodeDeviceObjEndAPI(&obj);
 
@@ -2360,6 +2362,8 @@ static virNodeDeviceDriver udevNodeDeviceDriver = {
     .nodeDeviceCreate = nodeDeviceCreate, /* 7.3.0 */
     .nodeDeviceSetAutostart = nodeDeviceSetAutostart, /* 7.7.0 */
     .nodeDeviceGetAutostart = nodeDeviceGetAutostart, /* 7.7.0 */
+    .nodeDeviceIsPersistent = nodeDeviceIsPersistent, /* 7.7.0 */
+    .nodeDeviceIsActive = nodeDeviceIsActive, /* 7.7.0 */
 };
 
 
-- 
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