[PATCH v2 2/3] test_driver: Introduce testDomainObjCheckTaint

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

 



In order to test the virDomainGetMessages for test driver, we need to
check some taints or deprecations, so introduce testDomainObjCheckTaint
for checking taints.

Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 src/test/test_driver.c | 57 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index dff96bceb6..88ae11c448 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -9331,6 +9331,61 @@ testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint,
     return ret;
 }
 
+static void
+testDomainObjCheckDiskTaint(virDomainObj *obj,
+                            virDomainDiskDef *disk)
+{
+    if (disk->rawio == VIR_TRISTATE_BOOL_YES)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES);
+
+    if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
+        virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_BLOCK &&
+        disk->src->path && virFileIsCDROM(disk->src->path) == 1)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH);
+}
+
+static void
+testDomainObjCheckHostdevTaint(virDomainObj *obj,
+                               virDomainHostdevDef *hostdev)
+{
+    if (!virHostdevIsSCSIDevice(hostdev))
+        return;
+
+    if (hostdev->source.subsys.u.scsi.rawio == VIR_TRISTATE_BOOL_YES)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES);
+}
+
+static void
+testDomainObjCheckNetTaint(virDomainObj *obj,
+                           virDomainNetDef *net)
+{
+    /* script is only useful for NET_TYPE_ETHERNET (qemu) and
+     * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for
+     * any interface type. In any case, it's adding user sauce into
+     * the soup, so it should taint the domain.
+     */
+    if (net->script != NULL)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_SHELL_SCRIPTS);
+}
+
+static void
+testDomainObjCheckTaint(virDomainObj *obj)
+{
+    size_t i;
+
+    for (i = 0; i < obj->def->ndisks; i++)
+        testDomainObjCheckDiskTaint(obj, obj->def->disks[i]);
+
+    for (i = 0; i < obj->def->nhostdevs; i++)
+        testDomainObjCheckHostdevTaint(obj, obj->def->hostdevs[i]);
+
+    for (i = 0; i < obj->def->nnets; i++)
+        testDomainObjCheckNetTaint(obj, obj->def->nets[i]);
+
+    if (obj->def->os.dtb)
+        virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CUSTOM_DTB);
+}
+
 static int
 testDomainGetMessages(virDomainPtr dom,
                       char ***msgs,
@@ -9351,6 +9406,8 @@ testDomainGetMessages(virDomainPtr dom,
     nmsgs = 0;
     n = 0;
 
+    testDomainObjCheckTaint(vm);
+
     if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) {
         nmsgs += __builtin_popcount(vm->taint);
         *msgs = g_renew(char *, *msgs, nmsgs+1);
-- 
2.32.0




[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