From 7022759b7e913340582a5b58fc5c07d2eceb1a83 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 8 May 2009 09:58:46 +0000 Subject: [PATCH] Add new VIR_ERR_OPERATION_INVALID error code & use it in Xen & QEMU drivers --- ChangeLog | 8 +++++++ include/libvirt/virterror.h | 1 + src/qemu_driver.c | 46 +++++++++++++++++++++++++------------ src/virterror.c | 6 +++++ src/xen_internal.c | 29 +++++++++++++++++------ src/xend_internal.c | 14 +++++------ 6 files changed, 75 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee6a3d86b3..048548ad72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri May 8 10:56:22 BST 2009 Daniel P. Berrange + + * include/libvirt/virterror.h, src/virterror.c: Add new error + code VIR_ERR_OPERATION_INVALID for operations that are not + applicable at this time (eg, pause on an inactive guest) + * src/qemu_driver.c, src/xen_internal.c, src/xend_internal.c: + Use new error code where relevant. + Thu May 7 09:31:22 CEST 2009 Daniel Veillard * qemud/libvirtd.init.in: improve the LSB init header for the diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index faf3f6158e..4677ebc1b2 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -157,6 +157,7 @@ typedef enum { VIR_ERR_INVALID_NODE_DEVICE,/* invalid node device object */ VIR_ERR_NO_NODE_DEVICE,/* node device not found */ VIR_ERR_NO_SECURITY_MODEL, /* security model not found */ + VIR_ERR_OPERATION_INVALID, /* operation is not applicable at this time */ } virErrorNumber; /** diff --git a/src/qemu_driver.c b/src/qemu_driver.c index acf08d49fb..404d773018 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -1325,7 +1325,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, FD_ZERO(&keepfd); if (virDomainIsActive(vm)) { - qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("VM is already active")); return -1; } @@ -2216,7 +2216,7 @@ static int qemudDomainSuspend(virDomainPtr dom) { goto cleanup; } if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } @@ -2269,7 +2269,7 @@ static int qemudDomainResume(virDomainPtr dom) { goto cleanup; } if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } @@ -2757,7 +2757,7 @@ static int qemudDomainSave(virDomainPtr dom, } if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } @@ -2892,7 +2892,7 @@ static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { } if (virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s", + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot change vcpu count of an active domain")); goto cleanup; } @@ -2944,8 +2944,16 @@ qemudDomainPinVcpu(virDomainPtr dom, vm = virDomainFindByUUID(&driver->domains, dom->uuid); qemuDriverUnlock(driver); + if (!vm) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(dom->uuid, uuidstr); + qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s'"), uuidstr); + goto cleanup; + } + if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s",_("cannot pin vcpus on an inactive domain")); goto cleanup; } @@ -3005,8 +3013,16 @@ qemudDomainGetVcpus(virDomainPtr dom, vm = virDomainFindByUUID(&driver->domains, dom->uuid); qemuDriverUnlock(driver); + if (!vm) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(dom->uuid, uuidstr); + qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s'"), uuidstr); + goto cleanup; + } + if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s",_("cannot pin vcpus on an inactive domain")); goto cleanup; } @@ -3260,7 +3276,7 @@ static int qemudDomainRestore(virConnectPtr conn, vm = virDomainFindByName(&driver->domains, def->name); if (vm) { if (virDomainIsActive(vm)) { - qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_INVALID, _("domain is already active as '%s'"), vm->def->name); goto cleanup; } else { @@ -3513,7 +3529,7 @@ static int qemudDomainUndefine(virDomainPtr dom) { } if (virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot delete active domain")); goto cleanup; } @@ -3910,7 +3926,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom, if (!virDomainIsActive(vm)) { qemuDriverUnlock(driver); - qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot attach device on inactive domain")); goto cleanup; } @@ -4062,7 +4078,7 @@ static int qemudDomainDetachDevice(virDomainPtr dom, if (!virDomainIsActive(vm)) { qemuDriverUnlock(driver); - qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot detach device on inactive domain")); goto cleanup; } @@ -4222,7 +4238,7 @@ qemudDomainBlockStats (virDomainPtr dom, goto cleanup; } if (!virDomainIsActive (vm)) { - qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } @@ -4361,7 +4377,7 @@ qemudDomainInterfaceStats (virDomainPtr dom, } if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } @@ -4507,7 +4523,7 @@ qemudDomainMemoryPeek (virDomainPtr dom, } if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } @@ -4832,7 +4848,7 @@ qemudDomainMigratePerform (virDomainPtr dom, } if (!virDomainIsActive(vm)) { - qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } diff --git a/src/virterror.c b/src/virterror.c index c9db91f3f0..e12608d4ee 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -1018,6 +1018,12 @@ virErrorMsg(virErrorNumber error, const char *info) else errmsg = _("Security model not found: %s"); break; + case VIR_ERR_OPERATION_INVALID: + if (info == NULL) + errmsg = _("Requested operation is not valid"); + else + errmsg = _("Requested operation is not valid: %s"); + break; } return (errmsg); } diff --git a/src/xen_internal.c b/src/xen_internal.c index 7a88ca2f7d..06b0cbac10 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -1068,9 +1068,14 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) } priv = (xenUnifiedPrivatePtr) domain->conn->privateData; - if (priv->handle < 0 || domain->id < 0) { + if (priv->handle < 0) { virXenErrorFunc(domain->conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__, - "priv->handle or domain->id invalid", 0); + "priv->handle invalid", 0); + return NULL; + } + if (domain->id < 0) { + virXenError(domain->conn, VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); return NULL; } @@ -1143,9 +1148,14 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain, } priv = (xenUnifiedPrivatePtr) domain->conn->privateData; - if (priv->handle < 0 || domain->id < 0) { + if (priv->handle < 0) { virXenErrorFunc(domain->conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__, - "priv->handle or domain->id invalid", 0); + "priv->handle invalid", 0); + return -1; + } + if (domain->id < 0) { + virXenError(domain->conn, VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); return -1; } @@ -1241,9 +1251,14 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain, } priv = (xenUnifiedPrivatePtr) domain->conn->privateData; - if (priv->handle < 0 || domain->id < 0) { - virXenErrorFunc (domain->conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__, - "priv->handle or domain->id invalid", 0); + if (priv->handle < 0) { + virXenErrorFunc(domain->conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__, + "priv->handle invalid", 0); + return -1; + } + if (domain->id < 0) { + virXenError(domain->conn, VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); return -1; } diff --git a/src/xend_internal.c b/src/xend_internal.c index ffc0d06162..c410726d2e 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -2982,7 +2982,7 @@ xenDaemonDomainSuspend(virDomainPtr domain) } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } @@ -3009,7 +3009,7 @@ xenDaemonDomainResume(virDomainPtr domain) } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } @@ -3037,7 +3037,7 @@ xenDaemonDomainShutdown(virDomainPtr domain) } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } @@ -3066,7 +3066,7 @@ xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } @@ -3097,7 +3097,7 @@ xenDaemonDomainDestroy(virDomainPtr domain) } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } @@ -3172,7 +3172,7 @@ xenDaemonDomainSave(virDomainPtr domain, const char *filename) } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } @@ -3209,7 +3209,7 @@ xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename, } if (domain->id < 0) { - virXendError(domain->conn, VIR_ERR_INVALID_ARG, + virXendError(domain->conn, VIR_ERR_OPERATION_INVALID, _("Domain %s isn't running."), domain->name); return(-1); } -- GitLab