From: Daniel P. Berrange Date: Tue, 27 Nov 2012 13:58:56 +0000 (+0000) Subject: Add support for attach/detach/update hostdev devices in config for LXC X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=986c270dac70a38108de32842b8e7085a4fb725c;p=libvirt.git Add support for attach/detach/update hostdev devices in config for LXC Wire up the attach/detach/update device APIs to support changing of hostdevs in the persistent config file Signed-off-by: Daniel P. Berrange --- diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 017d987079..87e9544af7 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2928,6 +2928,7 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, int ret = -1; virDomainDiskDefPtr disk; virDomainNetDefPtr net; + virDomainHostdevDefPtr hostdev; switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: @@ -2956,6 +2957,21 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, ret = 0; break; + case VIR_DOMAIN_DEVICE_HOSTDEV: + hostdev = dev->data.hostdev; + if (virDomainHostdevFind(vmdef, hostdev, NULL) >= 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("device is already in the domain configuration")); + return -1; + } + if (virDomainHostdevInsert(vmdef, hostdev) < 0) { + virReportOOMError(); + return -1; + } + dev->data.hostdev = NULL; + ret = 0; + break; + default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("persistent attach of device is not supported")); @@ -3017,6 +3033,7 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef, int ret = -1; virDomainDiskDefPtr disk, det_disk; virDomainNetDefPtr net; + virDomainHostdevDefPtr hostdev, det_hostdev; int idx; char mac[VIR_MAC_STRING_BUFLEN]; @@ -3050,6 +3067,19 @@ lxcDomainDetachDeviceConfig(virDomainDefPtr vmdef, ret = 0; break; + case VIR_DOMAIN_DEVICE_HOSTDEV: { + hostdev = dev->data.hostdev; + if ((idx = virDomainHostdevFind(vmdef, hostdev, &det_hostdev)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("device not present in domain configuration")); + return -1; + } + virDomainHostdevRemove(vmdef, idx); + virDomainHostdevDefFree(det_hostdev); + ret = 0; + break; + } + default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("persistent detach of device is not supported"));