qemu: cold-unplug of sound

With this patch users can cold unplug some sound devices.
use "virsh detach-device vm sound.xml --config" command.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jidong Xia <xiajidong@cmss.chinamobile.com>
This commit is contained in:
Jidong Xia 2019-11-29 17:40:46 +08:00 committed by Cole Robinson
parent fda14dd782
commit 863c0d8e8d
4 changed files with 64 additions and 1 deletions

View File

@ -2753,6 +2753,14 @@ void virDomainSoundDefFree(virDomainSoundDefPtr def)
VIR_FREE(def); VIR_FREE(def);
} }
virDomainSoundDefPtr
virDomainSoundDefRemove(virDomainDefPtr def, size_t idx)
{
virDomainSoundDefPtr ret = def->sounds[idx];
VIR_DELETE_ELEMENT(def->sounds, idx, def->nsounds);
return ret;
}
void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def) void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def)
{ {
if (!def) if (!def)
@ -14554,6 +14562,46 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xmlopt,
} }
static bool
virDomainSoundDefEquals(const virDomainSoundDef *a,
const virDomainSoundDef *b)
{
size_t i;
if (a->model != b->model)
return false;
if (a->ncodecs != b->ncodecs)
return false;
for (i = 0; i < a->ncodecs; i++) {
if (a->codecs[i]->type != b->codecs[i]->type)
return false;
}
if (a->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
!virDomainDeviceInfoAddressIsEqual(&a->info, &b->info))
return false;
return true;
}
ssize_t
virDomainSoundDefFind(const virDomainDef *def,
const virDomainSoundDef *sound)
{
size_t i;
for (i = 0; i < def->nsounds; i++) {
if (virDomainSoundDefEquals(sound, def->sounds[i]))
return i;
}
return -1;
}
static virDomainWatchdogDefPtr static virDomainWatchdogDefPtr
virDomainWatchdogDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainWatchdogDefParseXML(virDomainXMLOptionPtr xmlopt,
xmlNodePtr node, xmlNodePtr node,

View File

@ -2883,7 +2883,10 @@ void virDomainChrDefFree(virDomainChrDefPtr def);
int virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, int virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
virDomainChrSourceDefPtr src); virDomainChrSourceDefPtr src);
void virDomainSoundCodecDefFree(virDomainSoundCodecDefPtr def); void virDomainSoundCodecDefFree(virDomainSoundCodecDefPtr def);
ssize_t virDomainSoundDefFind(const virDomainDef *def,
const virDomainSoundDef *sound);
void virDomainSoundDefFree(virDomainSoundDefPtr def); void virDomainSoundDefFree(virDomainSoundDefPtr def);
virDomainSoundDefPtr virDomainSoundDefRemove(virDomainDefPtr def, size_t idx);
void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def); void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def); void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def);
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def); void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);

View File

@ -578,7 +578,9 @@ virDomainSmartcardTypeFromString;
virDomainSmartcardTypeToString; virDomainSmartcardTypeToString;
virDomainSmbiosModeTypeFromString; virDomainSmbiosModeTypeFromString;
virDomainSmbiosModeTypeToString; virDomainSmbiosModeTypeToString;
virDomainSoundDefFind;
virDomainSoundDefFree; virDomainSoundDefFree;
virDomainSoundDefRemove;
virDomainSoundModelTypeFromString; virDomainSoundModelTypeFromString;
virDomainSoundModelTypeToString; virDomainSoundModelTypeToString;
virDomainStartupPolicyTypeFromString; virDomainStartupPolicyTypeFromString;

View File

@ -8308,6 +8308,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
{ {
virDomainDiskDefPtr disk, det_disk; virDomainDiskDefPtr disk, det_disk;
virDomainNetDefPtr net; virDomainNetDefPtr net;
virDomainSoundDefPtr sound;
virDomainHostdevDefPtr hostdev, det_hostdev; virDomainHostdevDefPtr hostdev, det_hostdev;
virDomainLeaseDefPtr lease, det_lease; virDomainLeaseDefPtr lease, det_lease;
virDomainControllerDefPtr cont, det_cont; virDomainControllerDefPtr cont, det_cont;
@ -8336,6 +8337,16 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
virDomainNetDefFree(virDomainNetRemove(vmdef, idx)); virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
break; break;
case VIR_DOMAIN_DEVICE_SOUND:
sound = dev->data.sound;
if ((idx = virDomainSoundDefFind(vmdef, sound)) < 0) {
virReportError(VIR_ERR_DEVICE_MISSING, "%s",
_("device not present in domain configuration"));
return -1;
}
virDomainSoundDefFree(virDomainSoundDefRemove(vmdef, idx));
break;
case VIR_DOMAIN_DEVICE_HOSTDEV: { case VIR_DOMAIN_DEVICE_HOSTDEV: {
hostdev = dev->data.hostdev; hostdev = dev->data.hostdev;
if ((idx = virDomainHostdevFind(vmdef, hostdev, &det_hostdev)) < 0) { if ((idx = virDomainHostdevFind(vmdef, hostdev, &det_hostdev)) < 0) {
@ -8466,7 +8477,6 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
vmdef->vsock = NULL; vmdef->vsock = NULL;
break; break;
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_VIDEO: case VIR_DOMAIN_DEVICE_VIDEO:
case VIR_DOMAIN_DEVICE_GRAPHICS: case VIR_DOMAIN_DEVICE_GRAPHICS:
case VIR_DOMAIN_DEVICE_HUB: case VIR_DOMAIN_DEVICE_HUB: