On 2012/12/01 04:26, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange(a)redhat.com>
>
> Wire up the attach/detach/update device APIs to support changing
> of network interfaces in the persistent config file
>
> Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
> ---
> src/lxc/lxc_driver.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 66 insertions(+), 3 deletions(-)
>
> diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
> index 38d5d87..ecd7cb8 100644
> --- a/src/lxc/lxc_driver.c
> +++ b/src/lxc/lxc_driver.c
> @@ -2770,52 +2770,115 @@ lxcListAllDomains(virConnectPtr conn,
>
>
> static int
> -lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef ATTRIBUTE_UNUSED,
> +lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
> virDomainDeviceDefPtr dev)
> {
> int ret = -1;
> + virDomainNetDefPtr net;
>
> switch (dev->type) {
> + case VIR_DOMAIN_DEVICE_NET:
> + net =
dev->data.net;
> + if (virDomainNetInsert(vmdef, net) < 0) {
> + virReportOOMError();
> + goto cleanup;
> + }
> +
dev->data.net = NULL;
> + ret = 0;
> + break;
> +
> default:
> virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> _("persistent attach of device is not
supported"));
> break;
> }
>
> +cleanup:
> return ret;
> }
>
>
> static int
> -lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef ATTRIBUTE_UNUSED,
> +lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
> virDomainDeviceDefPtr dev)
> {
> int ret = -1;
> + virDomainNetDefPtr net;
> + int pos;
> + char mac[VIR_MAC_STRING_BUFLEN];
>
> switch (dev->type) {
> + case VIR_DOMAIN_DEVICE_NET:
> + net =
dev->data.net;
> + pos = virDomainNetFindIdx(vmdef, net);
> + if (pos == -2) {
> + virMacAddrFormat(&net->mac, mac);
> + virReportError(VIR_ERR_OPERATION_FAILED,
> + _("couldn't find matching device "
> + "with mac address %s"), mac);
> + goto cleanup;
> + } else if (pos < 0) {
> + virMacAddrFormat(&net->mac, mac);
> + virReportError(VIR_ERR_OPERATION_FAILED,
> + _("couldn't find matching device "
> + "with mac address %s"), mac);
> + goto cleanup;
> + }
Need some proper err msg,just as the err msg in lxcDomainDetachDeviceConfig