From: Chen Hanxiao <chenhanxiao(a)gmail.com>
We used VIR_ERR_OPERATION_FAILED when target detaching device
is not found.
That error code VIR_ERR_OPERATION_FAILED is widely used,
so the tools powered by libvirt, such as nova,
can't catch the exact errors from libvirt.
This patch introduce VIR_ERR_DEVICE_MISSING for this
kind of scenario.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)gmail.com>
---
include/libvirt/virterror.h | 1 +
src/qemu/qemu_hotplug.c | 26 +++++++++++++-------------
src/util/virerror.c | 6 ++++++
3 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 91ba29784..3e7c7a02c 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -320,6 +320,7 @@ typedef enum {
VIR_ERR_AGENT_UNSYNCED = 97, /* guest agent replies with wrong id
to guest-sync command (DEPRECATED)*/
VIR_ERR_LIBSSH = 98, /* error in libssh transport driver */
+ VIR_ERR_DEVICE_MISSING = 99, /* fail to find the desired device */
} virErrorNumber;
/**
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 6472a13a8..9e4424e35 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3513,7 +3513,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver,
int ret = -1;
if (!olddev) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("cannot find existing graphics device to modify of"
" type '%s'"), type);
goto cleanup;
@@ -4758,7 +4758,7 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
if ((idx = virDomainControllerFind(vm->def,
dev->data.controller->type,
dev->data.controller->idx)) < 0) {
- virReportError(VIR_ERR_OPERATION_FAILED,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("controller %s:%d not found"),
virDomainControllerTypeToString(dev->data.controller->type),
dev->data.controller->idx);
@@ -4987,18 +4987,18 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
if (idx < 0) {
switch (subsys->type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
- virReportError(VIR_ERR_OPERATION_FAILED,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("host pci device %.4x:%.2x:%.2x.%.1x not found"),
pcisrc->addr.domain, pcisrc->addr.bus,
pcisrc->addr.slot, pcisrc->addr.function);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
if (usbsrc->bus && usbsrc->device) {
- virReportError(VIR_ERR_OPERATION_FAILED,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("host usb device %03d.%03d not found"),
usbsrc->bus, usbsrc->device);
} else {
- virReportError(VIR_ERR_OPERATION_FAILED,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("host usb device vendor=0x%.4x product=0x%.4x not
found"),
usbsrc->vendor, usbsrc->product);
}
@@ -5007,13 +5007,13 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
if (scsisrc->protocol ==
VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
- virReportError(VIR_ERR_OPERATION_FAILED,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("host scsi iSCSI path %s not found"),
iscsisrc->src->path);
} else {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc =
&scsisrc->u.host;
- virReportError(VIR_ERR_OPERATION_FAILED,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("host scsi device %s:%u:%u.%llu not found"),
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit);
@@ -5051,7 +5051,7 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
if ((idx = virDomainShmemDefFind(vm->def, dev)) < 0) {
- virReportError(VIR_ERR_OPERATION_INVALID,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("shmem device of model '%s' not found "
"in domain configuration"),
virDomainShmemModelTypeToString(dev->model));
@@ -5110,7 +5110,7 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver,
watchdog->model == dev->model &&
watchdog->action == dev->action &&
virDomainDeviceInfoAddressIsEqual(&dev->info, &watchdog->info)))
{
- virReportError(VIR_ERR_OPERATION_INVALID,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("watchdog device of model '%s' is not "
"found in domain configuration"),
virDomainWatchdogModelTypeToString(watchdog->model));
@@ -5155,7 +5155,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0) {
char mac[VIR_MAC_STRING_BUFLEN];
- virReportError(VIR_ERR_INTERNAL_ERROR,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("netdev '%s' not found in domain
configuration"),
virMacAddrFormat(&dev->data.net->mac, mac));
goto cleanup;
@@ -5345,7 +5345,7 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
char *devstr = NULL;
if (!(tmpChr = virDomainChrFind(vmdef, chr))) {
- virReportError(VIR_ERR_OPERATION_INVALID,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("chr device of type '%s' not found "
"in domain configuration"),
virDomainChrDeviceTypeToString(chr->deviceType));
@@ -5394,7 +5394,7 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
int ret = -1;
if ((idx = virDomainRNGFind(vm->def, rng)) < 0) {
- virReportError(VIR_ERR_OPERATION_INVALID,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("RNG device of model '%s' not found "
"in domain configuration"),
virDomainRNGBackendTypeToString(rng->model));
@@ -5439,7 +5439,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
qemuDomainMemoryDeviceAlignSize(vm->def, memdef);
if ((idx = virDomainMemoryFindByDef(vm->def, memdef)) < 0) {
- virReportError(VIR_ERR_OPERATION_INVALID,
+ virReportError(VIR_ERR_DEVICE_MISSING,
_("memory device of model '%s' not found "
"in domain configuration"),
virDomainMemoryModelTypeToString(memdef->model));
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 562c3bc61..c000b0043 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -1453,6 +1453,12 @@ virErrorMsg(virErrorNumber error, const char *info)
else
errmsg = _("libssh transport error: %s");
break;
+ case VIR_ERR_DEVICE_MISSING:
+ if (info == NULL)
+ errmsg = _("device not found");
+ else
+ errmsg = _("device not found: %s");
+ break;
}
return errmsg;
}
--
2.14.3