virDomainRedirdevDef: Introduce find & remove routines

Basically, there are just two functions introduced here:
virDomainRedirdevDefFind which looks up given redirdev in domain
definition, and virDomainRedirdevDefRemove which removes the
device at given index in the array of devices.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2016-06-09 11:17:01 +02:00
parent 9f20b3b45e
commit e30dbb9f98
3 changed files with 48 additions and 0 deletions

View File

@ -14615,6 +14615,48 @@ virDomainMemoryRemove(virDomainDefPtr def,
} }
ssize_t
virDomainRedirdevDefFind(virDomainDefPtr def,
virDomainRedirdevDefPtr redirdev)
{
size_t i;
for (i = 0; i < def->nredirdevs; i++) {
virDomainRedirdevDefPtr tmp = def->redirdevs[i];
if (redirdev->bus != tmp->bus)
continue;
if (!virDomainChrSourceDefIsEqual(&redirdev->source.chr,
&tmp->source.chr))
continue;
if (redirdev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
!virDomainDeviceInfoAddressIsEqual(&redirdev->info, &tmp->info))
continue;
if (redirdev->info.alias &&
STRNEQ_NULLABLE(redirdev->info.alias, tmp->info.alias))
continue;
return i;
}
return -1;
}
virDomainRedirdevDefPtr
virDomainRedirdevDefRemove(virDomainDefPtr def, size_t idx)
{
virDomainRedirdevDefPtr ret = def->redirdevs[idx];
VIR_DELETE_ELEMENT(def->redirdevs, idx, def->nredirdevs);
return ret;
}
char * char *
virDomainDefGetDefaultEmulator(virDomainDefPtr def, virDomainDefGetDefaultEmulator(virDomainDefPtr def,
virCapsPtr caps) virCapsPtr caps)

View File

@ -2834,6 +2834,10 @@ virDomainChrRemove(virDomainDefPtr vmdef,
ssize_t virDomainRNGFind(virDomainDefPtr def, virDomainRNGDefPtr rng); ssize_t virDomainRNGFind(virDomainDefPtr def, virDomainRNGDefPtr rng);
virDomainRNGDefPtr virDomainRNGRemove(virDomainDefPtr def, size_t idx); virDomainRNGDefPtr virDomainRNGRemove(virDomainDefPtr def, size_t idx);
ssize_t virDomainRedirdevDefFind(virDomainDefPtr def,
virDomainRedirdevDefPtr redirdev);
virDomainRedirdevDefPtr virDomainRedirdevDefRemove(virDomainDefPtr def, size_t idx);
int virDomainSaveXML(const char *configDir, int virDomainSaveXML(const char *configDir,
virDomainDefPtr def, virDomainDefPtr def,
const char *xml); const char *xml);

View File

@ -425,7 +425,9 @@ virDomainPMSuspendedReasonTypeFromString;
virDomainPMSuspendedReasonTypeToString; virDomainPMSuspendedReasonTypeToString;
virDomainRedirdevBusTypeFromString; virDomainRedirdevBusTypeFromString;
virDomainRedirdevBusTypeToString; virDomainRedirdevBusTypeToString;
virDomainRedirdevDefFind;
virDomainRedirdevDefFree; virDomainRedirdevDefFree;
virDomainRedirdevDefRemove;
virDomainRNGBackendTypeToString; virDomainRNGBackendTypeToString;
virDomainRNGDefFree; virDomainRNGDefFree;
virDomainRNGFind; virDomainRNGFind;