Fri Jul 6 15:54:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>

* 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.
This commit is contained in:
Richard W.M. Jones 2007-07-06 14:56:15 +00:00
parent 44b20d1056
commit b26376750e
6 changed files with 64 additions and 25 deletions

View File

@ -1,3 +1,11 @@
Fri Jul 6 15:54:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* 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 <veillard@redhat.com> Thu Jul 5 18:02:28 CEST 2007 Daniel Veillard <veillard@redhat.com>
* src/xend_internal.c: fix typo in function comment * src/xend_internal.c: fix typo in function comment

View File

@ -125,6 +125,8 @@ typedef enum {
VIR_ERR_RPC, /* some sort of RPC error */ VIR_ERR_RPC, /* some sort of RPC error */
VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */ VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */
VIR_WAR_NO_NETWORK, /* failed to start network */ 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; } virErrorNumber;
/** /**

View File

@ -752,7 +752,8 @@ virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
* *
* Try to find a domain based on the hypervisor ID number * 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 virDomainPtr
virDomainLookupByID(virConnectPtr conn, int id) 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. * 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 virDomainPtr
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) 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. * 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 virDomainPtr
virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr) 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. * 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 virDomainPtr
virDomainLookupByName(virConnectPtr conn, const char *name) virDomainLookupByName(virConnectPtr conn, const char *name)

View File

@ -1749,7 +1749,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
virDomainPtr dom; virDomainPtr dom;
if (!vm) { 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; return NULL;
} }
@ -1769,7 +1769,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
virDomainPtr dom; virDomainPtr dom;
if (!vm) { 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; return NULL;
} }
@ -1789,7 +1789,7 @@ static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
virDomainPtr dom; virDomainPtr dom;
if (!vm) { 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; return NULL;
} }

View File

@ -983,6 +983,7 @@ virDomainPtr testLookupDomainByID(virConnectPtr conn,
} }
if (idx < 0) { if (idx < 0) {
testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
return(NULL); return(NULL);
} }
@ -1000,8 +1001,9 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
{ {
testPrivatePtr priv = (testPrivatePtr) conn->privateData; testPrivatePtr priv = (testPrivatePtr) conn->privateData;
testCon *con = &node->connections[priv->handle]; testCon *con = &node->connections[priv->handle];
virDomainPtr dom = NULL; virDomainPtr dom;
int i, idx = -1; int i, idx = -1;
for (i = 0 ; i < MAX_DOMAINS ; i++) { for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (con->domains[i].active && if (con->domains[i].active &&
memcmp(uuid, con->domains[i].uuid, VIR_UUID_BUFLEN) == 0) { memcmp(uuid, con->domains[i].uuid, VIR_UUID_BUFLEN) == 0) {
@ -1009,15 +1011,20 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
break; break;
} }
} }
if (idx >= 0) {
dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid); if (idx < 0) {
if (dom == NULL) { testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain")); return NULL;
return(NULL);
}
dom->id = con->domains[idx].id;
} }
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, virDomainPtr testLookupDomainByName(virConnectPtr conn,
@ -1025,8 +1032,9 @@ virDomainPtr testLookupDomainByName(virConnectPtr conn,
{ {
testPrivatePtr priv = (testPrivatePtr) conn->privateData; testPrivatePtr priv = (testPrivatePtr) conn->privateData;
testCon *con = &node->connections[priv->handle]; testCon *con = &node->connections[priv->handle];
virDomainPtr dom = NULL; virDomainPtr dom;
int i, idx = -1; int i, idx = -1;
for (i = 0 ; i < MAX_DOMAINS ; i++) { for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (con->domains[i].active && if (con->domains[i].active &&
strcmp(name, con->domains[i].name) == 0) { strcmp(name, con->domains[i].name) == 0) {
@ -1034,15 +1042,20 @@ virDomainPtr testLookupDomainByName(virConnectPtr conn,
break; break;
} }
} }
if (idx >= 0) {
dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid); if (idx < 0) {
if (dom == NULL) { testError (conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain")); return NULL;
return(NULL);
}
dom->id = con->domains[idx].id;
} }
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, int testListDomains (virConnectPtr conn,

View File

@ -634,6 +634,18 @@ __virErrorMsg(virErrorNumber error, const char *info)
else else
errmsg = _("Failed to find the network: %s"); errmsg = _("Failed to find the network: %s");
break; 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); return (errmsg);
} }