mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
qemu : support persistent add/delete network interface
This patch allows to modify interfaces of domain(qemu) * src/conf/domain_conf.c src/conf/domain_conf.h src/libvirt_private.syms: (virDomainNetInsert) : Insert a network device to domain definition. (virDomainNetIndexByMac) : Returns an index of net device in array. (virDomainNetRemoveByMac): Remove a NIC of passed MAC address. * src/qemu/qemu_driver.c (qemuDomainAttachDeviceConfig): add codes for NIC. (qemuDomainDetachDeviceConfig): add codes for NIC.
This commit is contained in:
parent
8357d91b65
commit
9c26d6f09e
@ -5204,6 +5204,51 @@ int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net)
|
||||||
|
{
|
||||||
|
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
|
||||||
|
return -1;
|
||||||
|
def->nets[def->nnets] = net;
|
||||||
|
def->nnets++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < def->nnets; i++)
|
||||||
|
if (!memcmp(def->nets[i]->mac, mac, VIR_MAC_BUFLEN))
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void virDomainNetRemove(virDomainDefPtr def, size_t i)
|
||||||
|
{
|
||||||
|
if (def->nnets > 1) {
|
||||||
|
memmove(def->nets + i,
|
||||||
|
def->nets + i + 1,
|
||||||
|
sizeof(*def->nets) * (def->nnets - (i + 1)));
|
||||||
|
def->nnets--;
|
||||||
|
if (VIR_REALLOC_N(def->nets, def->nnets) < 0) {
|
||||||
|
/* ignore harmless */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
VIR_FREE(def->nets);
|
||||||
|
def->nnets = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac)
|
||||||
|
{
|
||||||
|
int i = virDomainNetIndexByMac(def, mac);
|
||||||
|
|
||||||
|
if (i < 0)
|
||||||
|
return -1;
|
||||||
|
virDomainNetRemove(def, i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int virDomainControllerInsert(virDomainDefPtr def,
|
int virDomainControllerInsert(virDomainDefPtr def,
|
||||||
virDomainControllerDefPtr controller)
|
virDomainControllerDefPtr controller)
|
||||||
|
@ -1370,6 +1370,10 @@ int virDomainDiskDefAssignAddress(virCapsPtr caps, virDomainDiskDefPtr def);
|
|||||||
void virDomainDiskRemove(virDomainDefPtr def, size_t i);
|
void virDomainDiskRemove(virDomainDefPtr def, size_t i);
|
||||||
int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);
|
int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);
|
||||||
|
|
||||||
|
int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac);
|
||||||
|
int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net);
|
||||||
|
int virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac);
|
||||||
|
|
||||||
int virDomainControllerInsert(virDomainDefPtr def,
|
int virDomainControllerInsert(virDomainDefPtr def,
|
||||||
virDomainControllerDefPtr controller);
|
virDomainControllerDefPtr controller);
|
||||||
void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
|
void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
|
||||||
|
@ -292,6 +292,9 @@ virDomainLoadAllConfigs;
|
|||||||
virDomainMemballoonModelTypeFromString;
|
virDomainMemballoonModelTypeFromString;
|
||||||
virDomainMemballoonModelTypeToString;
|
virDomainMemballoonModelTypeToString;
|
||||||
virDomainNetDefFree;
|
virDomainNetDefFree;
|
||||||
|
virDomainNetIndexByMac;
|
||||||
|
virDomainNetInsert;
|
||||||
|
virDomainNetRemoveByMac;
|
||||||
virDomainNetTypeToString;
|
virDomainNetTypeToString;
|
||||||
virDomainObjAssignDef;
|
virDomainObjAssignDef;
|
||||||
virDomainObjCopyPersistentDef;
|
virDomainObjCopyPersistentDef;
|
||||||
|
@ -4255,6 +4255,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev)
|
||||||
{
|
{
|
||||||
virDomainDiskDefPtr disk;
|
virDomainDiskDefPtr disk;
|
||||||
|
virDomainNetDefPtr net;
|
||||||
|
|
||||||
switch (dev->type) {
|
switch (dev->type) {
|
||||||
case VIR_DOMAIN_DEVICE_DISK:
|
case VIR_DOMAIN_DEVICE_DISK:
|
||||||
@ -4277,6 +4278,23 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
|
net = dev->data.net;
|
||||||
|
if (virDomainNetIndexByMac(vmdef, net->mac) >= 0) {
|
||||||
|
char macbuf[VIR_MAC_STRING_BUFLEN];
|
||||||
|
virFormatMacAddr(net->mac, macbuf);
|
||||||
|
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("mac %s already exists"), macbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (virDomainNetInsert(vmdef, net)) {
|
||||||
|
virReportOOMError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
dev->data.net = NULL;
|
||||||
|
if (qemuDomainAssignPCIAddresses(vmdef) < 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("persistent attach of device is not supported"));
|
_("persistent attach of device is not supported"));
|
||||||
@ -4291,6 +4309,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev)
|
||||||
{
|
{
|
||||||
virDomainDiskDefPtr disk;
|
virDomainDiskDefPtr disk;
|
||||||
|
virDomainNetDefPtr net;
|
||||||
|
|
||||||
switch (dev->type) {
|
switch (dev->type) {
|
||||||
case VIR_DOMAIN_DEVICE_DISK:
|
case VIR_DOMAIN_DEVICE_DISK:
|
||||||
@ -4301,6 +4320,17 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
|
net = dev->data.net;
|
||||||
|
if (virDomainNetRemoveByMac(vmdef, net->mac)) {
|
||||||
|
char macbuf[VIR_MAC_STRING_BUFLEN];
|
||||||
|
|
||||||
|
virFormatMacAddr(net->mac, macbuf);
|
||||||
|
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("no nic of mac %s"), macbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("persistent detach of device is not supported"));
|
_("persistent detach of device is not supported"));
|
||||||
|
Loading…
Reference in New Issue
Block a user