mirror of https://gitee.com/openkylin/libvirt.git
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse and virURIFormat, to get consistency. * include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI * src/util/viruri.c, src/util/viruri.h: Add error reporting * src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c, src/lxc/lxc_driver.c, src/openvz/openvz_driver.c, src/qemu/qemu_driver.c, src/qemu/qemu_migration.c, src/remote/remote_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c, src/xen/xend_internal.c, tests/viruritest.c: Remove error reporting Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
94410848e1
commit
1f66c18f79
|
@ -85,6 +85,7 @@ typedef enum {
|
|||
VIR_FROM_LOCKING = 42, /* Error from lock manager */
|
||||
VIR_FROM_HYPERV = 43, /* Error from Hyper-V driver */
|
||||
VIR_FROM_CAPABILITIES = 44, /* Error from capabilities */
|
||||
VIR_FROM_URI = 45, /* Error from URI handling */
|
||||
} virErrorDomain;
|
||||
|
||||
|
||||
|
|
|
@ -3977,12 +3977,8 @@ esxDomainMigratePerform(virDomainPtr domain,
|
|||
}
|
||||
|
||||
/* Parse migration URI */
|
||||
parsedUri = virURIParse(uri);
|
||||
|
||||
if (parsedUri == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(parsedUri = virURIParse(uri)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parsedUri->scheme == NULL || STRCASENEQ(parsedUri->scheme, "vpxmigr")) {
|
||||
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
||||
|
|
|
@ -1165,11 +1165,7 @@ do_open (const char *name,
|
|||
virConnectOpenResolveURIAlias(conf, name, &alias) < 0)
|
||||
goto failed;
|
||||
|
||||
ret->uri = virURIParse (alias ? alias : name);
|
||||
if (!ret->uri) {
|
||||
virLibConnError(VIR_ERR_INVALID_ARG,
|
||||
_("could not parse connection URI %s"),
|
||||
alias ? alias : name);
|
||||
if (!(ret->uri = virURIParse (alias ? alias : name))) {
|
||||
VIR_FREE(alias);
|
||||
goto failed;
|
||||
}
|
||||
|
@ -1770,11 +1766,9 @@ virConnectGetURI (virConnectPtr conn)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
name = virURIFormat(conn->uri);
|
||||
if (!name) {
|
||||
virReportOOMError();
|
||||
if (!(name = virURIFormat(conn->uri)))
|
||||
goto error;
|
||||
}
|
||||
|
||||
return name;
|
||||
|
||||
error:
|
||||
|
@ -5061,9 +5055,7 @@ virDomainMigratePeer2Peer (virDomainPtr domain,
|
|||
return -1;
|
||||
}
|
||||
|
||||
tempuri = virURIParse(dconnuri);
|
||||
if (!tempuri) {
|
||||
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
if (!(tempuri = virURIParse(dconnuri))) {
|
||||
virDispatchError(domain->conn);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1044,11 +1044,8 @@ libxlOpen(virConnectPtr conn,
|
|||
if (libxl_driver == NULL)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
conn->uri = virURIParse("xen:///");
|
||||
if (!conn->uri) {
|
||||
virReportOOMError();
|
||||
if (!(conn->uri = virURIParse("xen:///")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
} else {
|
||||
/* Only xen scheme */
|
||||
if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "xen"))
|
||||
|
|
|
@ -140,11 +140,8 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn,
|
|||
if (lxc_driver == NULL)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
conn->uri = virURIParse("lxc:///");
|
||||
if (!conn->uri) {
|
||||
virReportOOMError();
|
||||
if (!(conn->uri = virURIParse("lxc:///")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (conn->uri->scheme == NULL ||
|
||||
STRNEQ(conn->uri->scheme, "lxc"))
|
||||
|
|
|
@ -1336,11 +1336,8 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn,
|
|||
if (access("/proc/vz", W_OK) < 0)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
conn->uri = virURIParse("openvz:///system");
|
||||
if (conn->uri == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(conn->uri = virURIParse("openvz:///system")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
} else {
|
||||
/* If scheme isn't 'openvz', then its for another driver */
|
||||
if (conn->uri->scheme == NULL ||
|
||||
|
|
|
@ -860,13 +860,10 @@ static virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
|||
if (qemu_driver == NULL)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
conn->uri = virURIParse(qemu_driver->privileged ?
|
||||
"qemu:///system" :
|
||||
"qemu:///session");
|
||||
if (!conn->uri) {
|
||||
virReportOOMError();
|
||||
if (!(conn->uri = virURIParse(qemu_driver->privileged ?
|
||||
"qemu:///system" :
|
||||
"qemu:///session")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
} else {
|
||||
/* If URI isn't 'qemu' its definitely not for us */
|
||||
if (conn->uri->scheme == NULL ||
|
||||
|
|
|
@ -1936,11 +1936,8 @@ static int doNativeMigrate(struct qemud_driver *driver,
|
|||
} else {
|
||||
uribits = virURIParse(uri);
|
||||
}
|
||||
if (!uribits) {
|
||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot parse URI %s"), uri);
|
||||
if (!uribits)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATE_QEMU_FD))
|
||||
spec.destType = MIGRATION_DEST_CONNECT_HOST;
|
||||
|
|
|
@ -485,7 +485,8 @@ doRemoteOpen (virConnectPtr conn,
|
|||
(STREQ(conn->uri->scheme, "remote") ||
|
||||
STRPREFIX(conn->uri->scheme, "remote+"))) {
|
||||
/* Allow remote serve to probe */
|
||||
name = strdup("");
|
||||
if (!(name = strdup("")))
|
||||
goto out_of_memory;
|
||||
} else {
|
||||
virURI tmpuri = {
|
||||
.scheme = conn->uri->scheme,
|
||||
|
@ -515,6 +516,9 @@ doRemoteOpen (virConnectPtr conn,
|
|||
/* Restore transport scheme */
|
||||
if (transport_str)
|
||||
transport_str[-1] = '+';
|
||||
|
||||
if (!name)
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -522,12 +526,8 @@ doRemoteOpen (virConnectPtr conn,
|
|||
vars = NULL;
|
||||
} else {
|
||||
/* Probe URI server side */
|
||||
name = strdup("");
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
virReportOOMError();
|
||||
goto failed;
|
||||
if (!(name = strdup("")))
|
||||
goto out_of_memory;
|
||||
}
|
||||
|
||||
VIR_DEBUG("proceeding with name = %s", name);
|
||||
|
@ -720,10 +720,8 @@ doRemoteOpen (virConnectPtr conn,
|
|||
VIR_DEBUG("Auto-probed URI is %s", uriret.uri);
|
||||
conn->uri = virURIParse(uriret.uri);
|
||||
VIR_FREE(uriret.uri);
|
||||
if (!conn->uri) {
|
||||
virReportOOMError();
|
||||
if (!conn->uri)
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(priv->domainEventState = virDomainEventStateNew()))
|
||||
|
|
|
@ -1139,13 +1139,10 @@ static virDrvOpenStatus umlOpen(virConnectPtr conn,
|
|||
if (uml_driver == NULL)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
conn->uri = virURIParse(uml_driver->privileged ?
|
||||
"uml:///system" :
|
||||
"uml:///session");
|
||||
if (!conn->uri) {
|
||||
virReportOOMError();
|
||||
if (!(conn->uri = virURIParse(uml_driver->privileged ?
|
||||
"uml:///system" :
|
||||
"uml:///session")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (conn->uri->scheme == NULL ||
|
||||
STRNEQ (conn->uri->scheme, "uml"))
|
||||
|
|
|
@ -178,6 +178,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
|
|||
case VIR_FROM_CAPABILITIES:
|
||||
dom = "Capabilities ";
|
||||
break;
|
||||
case VIR_FROM_URI:
|
||||
dom = "URI ";
|
||||
break;
|
||||
}
|
||||
return(dom);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,14 @@
|
|||
|
||||
#include "memory.h"
|
||||
#include "util.h"
|
||||
#include "virterror_internal.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_URI
|
||||
|
||||
#define virURIReportError(code, ...) \
|
||||
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
||||
|
||||
/**
|
||||
* virURIParse:
|
||||
|
@ -30,9 +38,15 @@ virURIParse(const char *uri)
|
|||
{
|
||||
virURIPtr ret = xmlParseURI(uri);
|
||||
|
||||
if (!ret) {
|
||||
/* libxml2 does not tell us what failed. Grr :-( */
|
||||
virURIReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Unable to parse URI %s", uri);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* First check: does it even make sense to jump inside */
|
||||
if (ret != NULL &&
|
||||
ret->server != NULL &&
|
||||
if (ret->server != NULL &&
|
||||
ret->server[0] == '[') {
|
||||
size_t length = strlen(ret->server);
|
||||
|
||||
|
@ -70,8 +84,7 @@ virURIFormat(virURIPtr uri)
|
|||
char *ret;
|
||||
|
||||
/* First check: does it make sense to do anything */
|
||||
if (uri != NULL &&
|
||||
uri->server != NULL &&
|
||||
if (uri->server != NULL &&
|
||||
strchr(uri->server, ':') != NULL) {
|
||||
|
||||
backupserver = uri->server;
|
||||
|
@ -82,7 +95,12 @@ virURIFormat(virURIPtr uri)
|
|||
}
|
||||
|
||||
ret = (char *) xmlSaveUri(uri);
|
||||
if (!ret) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
/* Put the fixed version back */
|
||||
if (tmpserver) {
|
||||
uri->server = backupserver;
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
typedef xmlURI virURI;
|
||||
typedef xmlURIPtr virURIPtr;
|
||||
|
||||
virURIPtr virURIParse(const char *uri);
|
||||
char *virURIFormat(virURIPtr uri);
|
||||
virURIPtr virURIParse(const char *uri)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
char *virURIFormat(virURIPtr uri)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
void virURIFree(virURIPtr uri);
|
||||
|
||||
|
|
|
@ -980,13 +980,9 @@ static virDrvOpenStatus vboxOpen(virConnectPtr conn,
|
|||
|
||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
if (conn->uri == NULL) {
|
||||
conn->uri = virURIParse(uid ? "vbox:///session" : "vbox:///system");
|
||||
if (conn->uri == NULL) {
|
||||
virReportOOMError();
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
}
|
||||
if (conn->uri == NULL &&
|
||||
!(conn->uri = virURIParse(uid ? "vbox:///session" : "vbox:///system")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
|
||||
if (conn->uri->scheme == NULL ||
|
||||
STRNEQ (conn->uri->scheme, "vbox"))
|
||||
|
|
|
@ -2617,12 +2617,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
|
|||
(*def)->target.port = port;
|
||||
(*def)->source.type = VIR_DOMAIN_CHR_TYPE_TCP;
|
||||
|
||||
parsedUri = virURIParse(fileName);
|
||||
|
||||
if (parsedUri == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(parsedUri = virURIParse(fileName)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (parsedUri->port == 0) {
|
||||
VMX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
||||
|
|
|
@ -270,11 +270,8 @@ xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
|
|||
if (!xenUnifiedProbe())
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
|
||||
conn->uri = virURIParse("xen:///");
|
||||
if (!conn->uri) {
|
||||
virReportOOMError();
|
||||
if (!(conn->uri = virURIParse("xen:///")))
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (conn->uri->scheme) {
|
||||
/* Decline any scheme which isn't "xen://" or "http://". */
|
||||
|
|
|
@ -3224,12 +3224,10 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
|
|||
* "hostname", "hostname:port" or "xenmigr://hostname[:port]/".
|
||||
*/
|
||||
if (strstr (uri, "//")) { /* Full URI. */
|
||||
virURIPtr uriptr = virURIParse (uri);
|
||||
if (!uriptr) {
|
||||
virXendError(VIR_ERR_INVALID_ARG,
|
||||
"%s", _("xenDaemonDomainMigrate: invalid URI"));
|
||||
virURIPtr uriptr;
|
||||
if (!(uriptr = virURIParse (uri)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uriptr->scheme && STRCASENEQ (uriptr->scheme, "xenmigr")) {
|
||||
virXendError(VIR_ERR_INVALID_ARG,
|
||||
"%s", _("xenDaemonDomainMigrate: only xenmigr://"
|
||||
|
|
|
@ -50,15 +50,11 @@ static int testURIParse(const void *args)
|
|||
const struct URIParseData *data = args;
|
||||
char *uristr;
|
||||
|
||||
if (!(uri = virURIParse(data->uri))) {
|
||||
virReportOOMError();
|
||||
if (!(uri = virURIParse(data->uri)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(uristr = virURIFormat(uri))) {
|
||||
virReportOOMError();
|
||||
if (!(uristr = virURIFormat(uri)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!STREQ(uristr, data->uri)) {
|
||||
VIR_DEBUG("URI did not roundtrip, expect '%s', actual '%s'",
|
||||
|
|
Loading…
Reference in New Issue