From 935550c6d35518371a97f94a1cf57081e02403e1 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 4 Dec 2012 10:20:30 +0100 Subject: [PATCH] qemu: Fix error code when attaching existing device An attempt to attach device that is already attached to a domain results in the following error: virsh # attach-device rhel6 pci2 --persistent error: Failed to attach device from pci2 error: invalid argument: device is already in the domain configuration The "invalid argument" error code looks wrong, we usually use "operation invalid" when the action cannot be done in current state. --- src/qemu/qemu_driver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 64221cf99d..e099c5cb43 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6299,8 +6299,8 @@ qemuDomainAttachDeviceConfig(qemuCapsPtr caps, case VIR_DOMAIN_DEVICE_DISK: disk = dev->data.disk; if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("target %s already exists."), disk->dst); + virReportError(VIR_ERR_OPERATION_INVALID, + _("target %s already exists"), disk->dst); return -1; } if (virDomainDiskInsert(vmdef, disk)) { @@ -6330,7 +6330,7 @@ qemuDomainAttachDeviceConfig(qemuCapsPtr caps, case VIR_DOMAIN_DEVICE_HOSTDEV: hostdev = dev->data.hostdev; if (virDomainHostdevFind(vmdef, hostdev, NULL) >= 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", + virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("device is already in the domain configuration")); return -1; } @@ -6346,7 +6346,7 @@ qemuDomainAttachDeviceConfig(qemuCapsPtr caps, case VIR_DOMAIN_DEVICE_LEASE: lease = dev->data.lease; if (virDomainLeaseIndex(vmdef, lease) >= 0) { - virReportError(VIR_ERR_INVALID_ARG, + virReportError(VIR_ERR_OPERATION_INVALID, _("Lease %s in lockspace %s already exists"), lease->key, NULLSTR(lease->lockspace)); return -1; @@ -6362,7 +6362,7 @@ qemuDomainAttachDeviceConfig(qemuCapsPtr caps, controller = dev->data.controller; if (virDomainControllerFind(vmdef, controller->type, controller->idx) > 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", + virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Target already exists")); return -1; }