]> xenbits.xensource.com Git - libvirt.git/commitdiff
virt-aa-helper: Rework setting virDomainMemoryDef labels
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 26 Jul 2023 10:34:08 +0000 (12:34 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Aug 2023 10:38:56 +0000 (12:38 +0200)
Currently, inside of virt-aa-helper code the domain definition is
parsed and then all def->mems are iterated over and for NVDIMM
models corresponding nvdimmPath is set label on. Conceptually,
this code works (except the label should be set for VIRTIO_PMEM
model too, but that is addressed in the next commit), but it can
be written in more extensible way. Firstly, there's no need to
check whether def->mems[i] is not NULL because we're inside a
for() loop that's counting through def->nmems. Secondly, we can
have a helper variable ('mem') to make the code more readable
(just like we do in other loops). Then, we can use switch() to
allow compiler warn us on new memory model.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/security/virt-aa-helper.c

index da1e4fc3e41be8a9e8823519a0ca9f1626254b8f..a0c76d24a8661c62116c2f3169a2a8220d1f4b61 100644 (file)
@@ -1147,10 +1147,20 @@ get_files(vahControl * ctl)
     }
 
     for (i = 0; i < ctl->def->nmems; i++) {
-        if (ctl->def->mems[i] &&
-                ctl->def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) {
-            if (vah_add_file(&buf, ctl->def->mems[i]->nvdimmPath, "rw") != 0)
+        virDomainMemoryDef *mem = ctl->def->mems[i];
+
+        switch (mem->model) {
+        case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+            if (vah_add_file(&buf, mem->nvdimmPath, "rw") != 0)
                 goto cleanup;
+            break;
+        case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+        case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+        case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+        case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+        case VIR_DOMAIN_MEMORY_MODEL_NONE:
+        case VIR_DOMAIN_MEMORY_MODEL_LAST:
+            break;
         }
     }