[PATCH 07/10] util: Don't require full disk definition when getting imagelabels

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

 



The image labels are stored in the virStorageSource struct. Convert the
virDomainDiskDefGetSecurityLabelDef helper not to use the full disk def
and move it appropriately.
---
 src/conf/domain_conf.c          | 14 --------------
 src/conf/domain_conf.h          |  3 ---
 src/libvirt_private.syms        |  2 +-
 src/qemu/qemu_domain.c          |  2 +-
 src/security/security_dac.c     |  4 ++--
 src/security/security_selinux.c |  4 ++--
 src/util/virstoragefile.c       | 15 +++++++++++++++
 src/util/virstoragefile.h       |  4 ++++
 8 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4114289..02c394f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19489,20 +19489,6 @@ virDomainDefGetSecurityLabelDef(virDomainDefPtr def, const char *model)
     return seclabel;
 }

-virSecurityDeviceLabelDefPtr
-virDomainDiskDefGetSecurityLabelDef(virDomainDiskDefPtr def, const char *model)
-{
-    size_t i;
-
-    if (def == NULL)
-        return NULL;
-
-    for (i = 0; i < def->src->nseclabels; i++) {
-        if (STREQ_NULLABLE(def->src->seclabels[i]->model, model))
-            return def->src->seclabels[i];
-    }
-    return NULL;
-}

 virSecurityDeviceLabelDefPtr
 virDomainChrDefGetSecurityLabelDef(virDomainChrDefPtr def, const char *model)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a6ac95a..6779a41 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2519,9 +2519,6 @@ virSecurityLabelDefPtr
 virDomainDefGetSecurityLabelDef(virDomainDefPtr def, const char *model);

 virSecurityDeviceLabelDefPtr
-virDomainDiskDefGetSecurityLabelDef(virDomainDiskDefPtr def, const char *model);
-
-virSecurityDeviceLabelDefPtr
 virDomainChrDefGetSecurityLabelDef(virDomainChrDefPtr def, const char *model);

 typedef const char* (*virEventActionToStringFunc)(int type);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1c84777..4f075e5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -210,7 +210,6 @@ virDomainDiskCopyOnReadTypeToString;
 virDomainDiskDefAssignAddress;
 virDomainDiskDefForeachPath;
 virDomainDiskDefFree;
-virDomainDiskDefGetSecurityLabelDef;
 virDomainDiskDefNew;
 virDomainDiskDeviceTypeToString;
 virDomainDiskDiscardTypeToString;
@@ -1902,6 +1901,7 @@ virStorageSourceCopy;
 virStorageSourceCopySeclabels;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetSecurityLabelDef;
 virStorageSourceNewFromBacking;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e40c5ec..7c4fc67 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2413,7 +2413,7 @@ qemuDomainGetImageIds(virQEMUDriverConfigPtr cfg,
         vmlabel->label)
         virParseOwnershipIds(vmlabel->label, uid, gid);

-    if ((disklabel = virDomainDiskDefGetSecurityLabelDef(disk, "dac")) &&
+    if ((disklabel = virStorageSourceGetSecurityLabelDef(disk->src, "dac")) &&
         disklabel->label)
         virParseOwnershipIds(disklabel->label, uid, gid);
 }
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 9d5c25b..28f033d 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -302,7 +302,7 @@ virSecurityDACSetSecurityFileLabel(virDomainDiskDefPtr disk,
     uid_t user;
     gid_t group;

-    disk_seclabel = virDomainDiskDefGetSecurityLabelDef(disk,
+    disk_seclabel = virStorageSourceGetSecurityLabelDef(disk->src,
                                                         SECURITY_DAC_NAME);

     if (disk_seclabel && disk_seclabel->norelabel)
@@ -369,7 +369,7 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
     if (secdef && secdef->norelabel)
         return 0;

-    disk_seclabel = virDomainDiskDefGetSecurityLabelDef(disk,
+    disk_seclabel = virStorageSourceGetSecurityLabelDef(disk->src,
                                                         SECURITY_DAC_NAME);

     if (disk_seclabel && disk_seclabel->norelabel)
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 228e5cb..0c34af8 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1134,7 +1134,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
     if (seclabel == NULL)
         return 0;

-    disk_seclabel = virDomainDiskDefGetSecurityLabelDef(disk,
+    disk_seclabel = virStorageSourceGetSecurityLabelDef(disk->src,
                                                         SECURITY_SELINUX_NAME);
     if (seclabel->norelabel || (disk_seclabel && disk_seclabel->norelabel))
         return 0;
@@ -1202,7 +1202,7 @@ virSecuritySELinuxSetSecurityFileLabel(virDomainDiskDefPtr disk,
     virSecurityLabelDefPtr secdef = cbdata->secdef;
     virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(cbdata->manager);

-    disk_seclabel = virDomainDiskDefGetSecurityLabelDef(disk,
+    disk_seclabel = virStorageSourceGetSecurityLabelDef(disk->src,
                                                         SECURITY_SELINUX_NAME);

     if (disk_seclabel && disk_seclabel->norelabel)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 394c9e2..433ddc1 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1519,6 +1519,21 @@ virStorageSourceCopySeclabels(virStorageSourcePtr to,
 }


+virSecurityDeviceLabelDefPtr
+virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src,
+                                    const char *model)
+{
+    size_t i;
+
+    for (i = 0; i < src->nseclabels; i++) {
+        if (STREQ_NULLABLE(src->seclabels[i]->model, model))
+            return src->seclabels[i];
+    }
+
+    return NULL;
+}
+
+
 static virStorageTimestampsPtr
 virStorageTimestampsCopy(const virStorageTimestamps *src)
 {
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index fec1b00..ccacdb2 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -312,6 +312,10 @@ int virStorageFileGetLVMKey(const char *path,
 int virStorageFileGetSCSIKey(const char *path,
                              char **key);

+virSecurityDeviceLabelDefPtr
+virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src,
+                                    const char *model);
+
 void virStorageNetHostDefClear(virStorageNetHostDefPtr def);
 void virStorageNetHostDefFree(size_t nhosts, virStorageNetHostDefPtr hosts);
 virStorageNetHostDefPtr virStorageNetHostDefCopy(size_t nhosts,
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]