mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
Add new VIR_ERR_OPERATION_INVALID error code & use it in Xen & QEMU drivers
This commit is contained in:
parent
2a1c7b57ff
commit
7022759b7e
@ -1,3 +1,11 @@
|
||||
Fri May 8 10:56:22 BST 2009 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* 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 <veillard@redhat.com>
|
||||
|
||||
* qemud/libvirtd.init.in: improve the LSB init header for the
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user