mirror of https://gitee.com/openkylin/libvirt.git
driver: ensure URI path is non-NULL to simplify drivers
Avoid the need for the drivers to explicitly check for a NULL path by making sure it is at least the empty string. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
91dd1b0f02
commit
65a372d6e0
|
@ -199,7 +199,7 @@ bhyveConnectOpen(virConnectPtr conn,
|
|||
{
|
||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
|
||||
if (STRNEQ(conn->uri->path, "/system")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unexpected bhyve URI path '%s', try bhyve:///system"),
|
||||
conn->uri->path);
|
||||
|
|
|
@ -852,7 +852,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
|||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
if (STRCASENEQ(conn->uri->scheme, "vpx") &&
|
||||
conn->uri->path && STRNEQ(conn->uri->path, "/")) {
|
||||
STRNEQ(conn->uri->path, "/")) {
|
||||
VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'",
|
||||
conn->uri->path, conn->uri->scheme);
|
||||
}
|
||||
|
|
|
@ -1007,6 +1007,12 @@ virConnectOpenInternal(const char *name,
|
|||
goto failed;
|
||||
}
|
||||
|
||||
/* Avoid need for drivers to worry about NULLs, as
|
||||
* no one needs to distinguish "" vs NULL */
|
||||
if (ret->uri->path == NULL &&
|
||||
VIR_STRDUP(ret->uri->path, "") < 0)
|
||||
goto failed;
|
||||
|
||||
VIR_DEBUG("Split \"%s\" to URI components:\n"
|
||||
" scheme %s\n"
|
||||
" server %s\n"
|
||||
|
@ -1016,7 +1022,7 @@ virConnectOpenInternal(const char *name,
|
|||
uristr,
|
||||
NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->server),
|
||||
NULLSTR(ret->uri->user), ret->uri->port,
|
||||
NULLSTR(ret->uri->path));
|
||||
ret->uri->path);
|
||||
|
||||
if (ret->uri->scheme == NULL) {
|
||||
virReportError(VIR_ERR_NO_CONNECT,
|
||||
|
|
|
@ -853,13 +853,12 @@ libxlConnectOpen(virConnectPtr conn,
|
|||
}
|
||||
|
||||
/* /session isn't supported in libxenlight */
|
||||
if (conn->uri->path &&
|
||||
STRNEQ(conn->uri->path, "") &&
|
||||
if (STRNEQ(conn->uri->path, "") &&
|
||||
STRNEQ(conn->uri->path, "/") &&
|
||||
STRNEQ(conn->uri->path, "/system")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unexpected Xen URI path '%s', try xen:///system"),
|
||||
NULLSTR(conn->uri->path));
|
||||
conn->uri->path);
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,8 +170,7 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn,
|
|||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
/* If path isn't '/' then they typoed, tell them correct path */
|
||||
if (conn->uri->path != NULL &&
|
||||
STRNEQ(conn->uri->path, "/") &&
|
||||
if (STRNEQ(conn->uri->path, "/") &&
|
||||
STRNEQ(conn->uri->path, "/system")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unexpected LXC URI path '%s', try lxc:///system"),
|
||||
|
|
|
@ -1355,8 +1355,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
|
|||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
/* If path isn't /system, then they typoed, so tell them correct path */
|
||||
if (conn->uri->path == NULL ||
|
||||
STRNEQ(conn->uri->path, "/system")) {
|
||||
if (STRNEQ(conn->uri->path, "/system")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unexpected OpenVZ URI path '%s', try openvz:///system"),
|
||||
conn->uri->path);
|
||||
|
|
|
@ -1155,7 +1155,7 @@ phypConnectOpen(virConnectPtr conn,
|
|||
if (VIR_ALLOC(uuid_table) < 0)
|
||||
goto failure;
|
||||
|
||||
if (conn->uri->path) {
|
||||
if (conn->uri->path[0] != '\0') {
|
||||
/* need to shift one byte in order to remove the first "/" of URI component */
|
||||
if (VIR_STRDUP(managed_system,
|
||||
conn->uri->path + (conn->uri->path[0] == '/')) < 0)
|
||||
|
|
|
@ -1150,12 +1150,6 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn,
|
|||
}
|
||||
|
||||
cfg = virQEMUDriverGetConfig(qemu_driver);
|
||||
if (conn->uri->path == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("no QEMU URI path given, try %s"),
|
||||
cfg->uri);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virQEMUDriverIsPrivileged(qemu_driver)) {
|
||||
if (STRNEQ(conn->uri->path, "/system") &&
|
||||
|
|
|
@ -1454,9 +1454,8 @@ testConnectOpen(virConnectPtr conn,
|
|||
|
||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
if (!conn->uri->path
|
||||
|| conn->uri->path[0] == '\0'
|
||||
|| (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) {
|
||||
if (conn->uri->path[0] == '\0' ||
|
||||
(conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
"%s", _("testOpen: supply a path or use test:///default"));
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
|
|
|
@ -517,12 +517,6 @@ vboxConnectOpen(virConnectPtr conn,
|
|||
|
||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("no VirtualBox driver path specified (try vbox:///session)"));
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
|
||||
if (uid != 0) {
|
||||
if (STRNEQ(conn->uri->path, "/session")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
|
|
@ -58,12 +58,6 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn,
|
|||
|
||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("no VirtualBox driver path specified (try vbox:///session)"));
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
|
||||
if (uid != 0) {
|
||||
if (STRNEQ(conn->uri->path, "/session")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
|
|
@ -131,7 +131,7 @@ vmwareConnectOpen(virConnectPtr conn,
|
|||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
/* If path isn't /session, then they typoed, so tell them correct path */
|
||||
if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) {
|
||||
if (STRNEQ(conn->uri->path, "/session")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unexpected VMware URI path '%s', try vmwareplayer:///session, vmwarews:///session or vmwarefusion:///session"),
|
||||
NULLSTR(conn->uri->path));
|
||||
|
|
|
@ -359,7 +359,7 @@ vzConnectOpen(virConnectPtr conn,
|
|||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
/* From this point on, the connection is for us. */
|
||||
if (STRNEQ_NULLABLE(conn->uri->path, "/system")) {
|
||||
if (STRNEQ(conn->uri->path, "/system")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unexpected Virtuozzo URI path '%s', try vz:///system"),
|
||||
conn->uri->path);
|
||||
|
|
Loading…
Reference in New Issue