]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Implement virNodeDeviceIsPersistent()/IsActive()
authorJonathon Jongsma <jjongsma@redhat.com>
Thu, 3 Jun 2021 18:28:39 +0000 (13:28 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 14 Sep 2021 19:25:55 +0000 (14:25 -0500)
Implement these new API functions in the nodedev driver.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/node_device/node_device_driver.c
src/node_device/node_device_driver.h
src/node_device/node_device_udev.c

index bb18b24e53e065fcd6d76a3302c3eefc2006ace3..3bc6eb1c11f8d201fbdc865a517d154f5cba6234 100644 (file)
@@ -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;
+}
index 17c7473d85fe84ef19de3e063f70248423c0e26d..7311b603ac16a853e53621bc931d5bf2d5cb4557 100644 (file)
@@ -186,6 +186,12 @@ int
 nodeDeviceGetAutostart(virNodeDevice *dev,
                        int *autostart);
 
+int
+nodeDeviceIsPersistent(virNodeDevice *dev);
+
+int
+nodeDeviceIsActive(virNodeDevice *dev);
+
 virCommand*
 nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def,
                                         bool autostart,
index 2bb34a6a0f94a634615509be705090f4d8dbe5e0..71f0bef827c1f06a2a9b526654e25533f2b7cf28 100644 (file)
@@ -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.8.0 */
     .nodeDeviceGetAutostart = nodeDeviceGetAutostart, /* 7.8.0 */
+    .nodeDeviceIsPersistent = nodeDeviceIsPersistent, /* 7.8.0 */
+    .nodeDeviceIsActive = nodeDeviceIsActive, /* 7.8.0 */
 };