]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Fix error code when attaching existing device
authorJiri Denemark <jdenemar@redhat.com>
Tue, 4 Dec 2012 09:20:30 +0000 (10:20 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 5 Dec 2012 12:45:34 +0000 (13:45 +0100)
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

index 64221cf99d75008272f3d2872dad8332b322dad5..e099c5cb434828eb0de50f8b5b3a733977ae7d80 100644 (file)
@@ -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;
         }