util: Don't require full disk definition when getting imagelabels

The image labels are stored in the virStorageSource struct. Convert the
virDomainDiskDefGetSecurityLabelDef helper not to use the full disk def
and move it appropriately.
This commit is contained in:
Peter Krempa 2014-06-18 18:39:47 +02:00
parent 5aadf43750
commit 83c896c859
8 changed files with 25 additions and 23 deletions

View File

@ -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)

View File

@ -2518,9 +2518,6 @@ virDomainObjGetState(virDomainObjPtr obj, int *reason)
virSecurityLabelDefPtr
virDomainDefGetSecurityLabelDef(virDomainDefPtr def, const char *model);
virSecurityDeviceLabelDefPtr
virDomainDiskDefGetSecurityLabelDef(virDomainDiskDefPtr def, const char *model);
virSecurityDeviceLabelDefPtr
virDomainChrDefGetSecurityLabelDef(virDomainChrDefPtr def, const char *model);

View File

@ -210,7 +210,6 @@ virDomainDiskCopyOnReadTypeToString;
virDomainDiskDefAssignAddress;
virDomainDiskDefForeachPath;
virDomainDiskDefFree;
virDomainDiskDefGetSecurityLabelDef;
virDomainDiskDefNew;
virDomainDiskDeviceTypeToString;
virDomainDiskDiscardTypeToString;
@ -1900,6 +1899,7 @@ virStorageSourceClear;
virStorageSourceClearBackingStore;
virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;
virStorageSourceNewFromBacking;
virStorageSourcePoolDefFree;
virStorageSourcePoolModeTypeFromString;

View File

@ -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);
}

View File

@ -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)

View File

@ -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)

View File

@ -1496,6 +1496,21 @@ virStorageNetHostDefCopy(size_t nhosts,
}
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;
}
void
virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def)
{

View File

@ -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,