From b26376750ef63141737f39a07b98034b72d88d0f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 6 Jul 2007 14:56:15 +0000 Subject: [PATCH] Fri Jul 6 15:54:00 BST 2007 Richard W.M. Jones * include/libvirt/virterror.h, src/virterror.c, src/libvirt.c: Add VIR_ERR_NO_DOMAIN and VIR_ERR_NO_NETWORK errors, which indicate that there is no domain/network from vir*Lookup* functions. * src/qemu_driver.c: Use VIR_ERR_NO_DOMAIN in lookup functions. * src/test.c: Use VIR_ERR_NO_DOMAIN in lookup functions. --- ChangeLog | 8 ++++++ include/libvirt/virterror.h | 2 ++ src/libvirt.c | 12 ++++++--- src/qemu_driver.c | 6 ++--- src/test.c | 49 +++++++++++++++++++++++-------------- src/virterror.c | 12 +++++++++ 6 files changed, 64 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f2581c9a2..d83b5d45a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Jul 6 15:54:00 BST 2007 Richard W.M. Jones + + * include/libvirt/virterror.h, src/virterror.c, src/libvirt.c: + Add VIR_ERR_NO_DOMAIN and VIR_ERR_NO_NETWORK errors, which + indicate that there is no domain/network from vir*Lookup* functions. + * src/qemu_driver.c: Use VIR_ERR_NO_DOMAIN in lookup functions. + * src/test.c: Use VIR_ERR_NO_DOMAIN in lookup functions. + Thu Jul 5 18:02:28 CEST 2007 Daniel Veillard * src/xend_internal.c: fix typo in function comment diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 26331268f1..817a4ec201 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -125,6 +125,8 @@ typedef enum { VIR_ERR_RPC, /* some sort of RPC error */ VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */ VIR_WAR_NO_NETWORK, /* failed to start network */ + VIR_ERR_NO_DOMAIN, /* domain not found or unexpectedly disappeared */ + VIR_ERR_NO_NETWORK, /* network not found */ } virErrorNumber; /** diff --git a/src/libvirt.c b/src/libvirt.c index 0ffbf0ad95..163ed82026 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -752,7 +752,8 @@ virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc, * * Try to find a domain based on the hypervisor ID number * - * Returns a new domain object or NULL in case of failure + * Returns a new domain object or NULL in case of failure. If the + * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. */ virDomainPtr virDomainLookupByID(virConnectPtr conn, int id) @@ -780,7 +781,8 @@ virDomainLookupByID(virConnectPtr conn, int id) * * Try to lookup a domain on the given hypervisor based on its UUID. * - * Returns a new domain object or NULL in case of failure + * Returns a new domain object or NULL in case of failure. If the + * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. */ virDomainPtr virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) @@ -808,7 +810,8 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) * * Try to lookup a domain on the given hypervisor based on its UUID. * - * Returns a new domain object or NULL in case of failure + * Returns a new domain object or NULL in case of failure. If the + * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. */ virDomainPtr virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr) @@ -857,7 +860,8 @@ virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr) * * Try to lookup a domain on the given hypervisor based on its name. * - * Returns a new domain object or NULL in case of failure + * Returns a new domain object or NULL in case of failure. If the + * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. */ virDomainPtr virDomainLookupByName(virConnectPtr conn, const char *name) diff --git a/src/qemu_driver.c b/src/qemu_driver.c index e93cd3a9a2..6b0bcd23f7 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -1749,7 +1749,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn, virDomainPtr dom; if (!vm) { - qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no domain with matching id"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -1769,7 +1769,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn, virDomainPtr dom; if (!vm) { - qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no domain with matching uuid"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -1789,7 +1789,7 @@ static virDomainPtr qemudDomainLookupByName(virConnectPtr conn, virDomainPtr dom; if (!vm) { - qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "no domain with matching name"); + qemudReportError(conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); return NULL; } diff --git a/src/test.c b/src/test.c index 6e5723b7b3..be6d2f1b81 100644 --- a/src/test.c +++ b/src/test.c @@ -983,6 +983,7 @@ virDomainPtr testLookupDomainByID(virConnectPtr conn, } if (idx < 0) { + testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL); return(NULL); } @@ -1000,8 +1001,9 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn, { testPrivatePtr priv = (testPrivatePtr) conn->privateData; testCon *con = &node->connections[priv->handle]; - virDomainPtr dom = NULL; + virDomainPtr dom; int i, idx = -1; + for (i = 0 ; i < MAX_DOMAINS ; i++) { if (con->domains[i].active && memcmp(uuid, con->domains[i].uuid, VIR_UUID_BUFLEN) == 0) { @@ -1009,15 +1011,20 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn, break; } } - if (idx >= 0) { - dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid); - if (dom == NULL) { - testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain")); - return(NULL); - } - dom->id = con->domains[idx].id; + + if (idx < 0) { + testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL); + return NULL; } - return (dom); + + dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid); + if (dom == NULL) { + testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain")); + return NULL; + } + dom->id = con->domains[idx].id; + + return dom; } virDomainPtr testLookupDomainByName(virConnectPtr conn, @@ -1025,8 +1032,9 @@ virDomainPtr testLookupDomainByName(virConnectPtr conn, { testPrivatePtr priv = (testPrivatePtr) conn->privateData; testCon *con = &node->connections[priv->handle]; - virDomainPtr dom = NULL; + virDomainPtr dom; int i, idx = -1; + for (i = 0 ; i < MAX_DOMAINS ; i++) { if (con->domains[i].active && strcmp(name, con->domains[i].name) == 0) { @@ -1034,15 +1042,20 @@ virDomainPtr testLookupDomainByName(virConnectPtr conn, break; } } - if (idx >= 0) { - dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid); - if (dom == NULL) { - testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain")); - return(NULL); - } - dom->id = con->domains[idx].id; + + if (idx < 0) { + testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL); + return NULL; } - return (dom); + + dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid); + if (dom == NULL) { + testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain")); + return NULL; + } + dom->id = con->domains[idx].id; + + return dom; } int testListDomains (virConnectPtr conn, diff --git a/src/virterror.c b/src/virterror.c index d22b2d7844..8a0ef792a9 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -634,6 +634,18 @@ __virErrorMsg(virErrorNumber error, const char *info) else errmsg = _("Failed to find the network: %s"); break; + case VIR_ERR_NO_DOMAIN: + if (info == NULL) + errmsg = _("Domain not found"); + else + errmsg = _("Domain not found: %s"); + break; + case VIR_ERR_NO_NETWORK: + if (info == NULL) + errmsg = _("Network not found"); + else + errmsg = _("Network not found: %s"); + break; } return (errmsg); }