Re: [PATCH 1/3] test_driver: Implement virDomainGetSecurityLabelList

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

 



On Thu, Sep 02, 2021 at 08:29:34PM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
src/test/test_driver.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 2f19b7c520..1b5914c890 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -137,6 +137,7 @@ VIR_ONCE_GLOBAL_INIT(testDriver);

#define TEST_MODEL "i686"
#define TEST_EMULATOR "/usr/bin/test-hv"
+#define TEST_SECURITY_LABEL_LIST_LENGTH 2

static const virNodeInfo defaultNodeInfo = {
    TEST_MODEL,
@@ -5261,6 +5262,46 @@ testDomainGetSecurityLabel(virDomainPtr dom,
    return ret;
}

+static int
+testDomainGetSecurityLabelList(virDomainPtr dom,
+                               virSecurityLabelPtr* seclabels)
+{
+    virDomainObj *vm;
+    size_t i;
+    int ret = -1;
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;
+
+    if (!virDomainObjIsActive(vm)) {
+        /* No seclabels */
+        *seclabels = NULL;
+        ret = 0;
+    } else {
+        int len = TEST_SECURITY_LABEL_LIST_LENGTH;
+
+        (*seclabels) = g_new0(virSecurityLabel, len);
+        memset(*seclabels, 0, sizeof(**seclabels) * len);
+
+        /* Fill the array */
+        for (i = 0; i < len; i++) {
+            if (virStrcpyStatic((*seclabels)[i].label, "libvirt-test") < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("security label exceeds maximum: %zu"),
+                               sizeof((*seclabels)[i].label) - 1);
+                g_clear_pointer(seclabels, g_free);
+                goto cleanup;
+            }
+            (*seclabels)[i].enforcing = 1;

There could be some variety here, like:

if (i == 0)
    (*seclabels)[i].enforcing = 1

But that's just a nitpick.

+        }
+        ret = len;
+    }
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
static int
testNodeGetSecurityModel(virConnectPtr conn,
                         virSecurityModelPtr secmodel)
@@ -9615,6 +9656,7 @@ static virHypervisorDriver testHypervisorDriver = {
    .domainGetVcpuPinInfo = testDomainGetVcpuPinInfo, /* 1.2.18 */
    .domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */
    .domainGetSecurityLabel = testDomainGetSecurityLabel, /* 7.5.0 */
+    .domainGetSecurityLabelList = testDomainGetSecurityLabelList, /* 7.8.0 */
    .nodeGetSecurityModel = testNodeGetSecurityModel, /* 7.5.0 */
    .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */
    .domainSetMemoryParameters = testDomainSetMemoryParameters, /* 5.6.0 */
--
2.33.0

Attachment: signature.asc
Description: PGP signature


[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