From patchwork Mon Apr 18 23:04:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 66064 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1542537qge; Mon, 18 Apr 2016 16:06:43 -0700 (PDT) X-Received: by 10.140.23.139 with SMTP id 11mr20099912qgp.62.1461020803398; Mon, 18 Apr 2016 16:06:43 -0700 (PDT) Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com. [209.132.183.39]) by mx.google.com with ESMTPS id x66si14649159qhx.63.2016.04.18.16.06.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Apr 2016 16:06:43 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3IN49NF040016; Mon, 18 Apr 2016 19:04:09 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3IN47kJ027421 for ; Mon, 18 Apr 2016 19:04:07 -0400 Received: from colepc.redhat.com (ovpn-113-99.phx2.redhat.com [10.3.113.99]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3IN47m8003428; Mon, 18 Apr 2016 19:04:07 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Mon, 18 Apr 2016 19:04:04 -0400 Message-Id: <4c80593d9666307ec7bf27ca7d12311435aedbc7.1461020644.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] Explicitly error on uri=qemu://system X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com It's a fairly common error that a user tries to connect to a URI like qemu://system or qemu://session (missing a slash). This errors like: $ virsh --connect qemu://session error: failed to connect to the hypervisor error: Unable to resolve address 'session' service '16514': No address associated with hostname If you already know that the standard qemu URI has 3 slashes, that error will make it obvious enough. But new user's may not get it. There's even a RHEL support page explicitly mentioning it!: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/sect-Troubleshooting-Common_libvirt_errors_and_troubleshooting.html Catch this error early in libvirt.c virConnectOpen for qemu (and vbox which has similar rules https://bugzilla.redhat.com/show_bug.cgi?id=1038304 --- src/libvirt.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) -- 2.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/libvirt.c b/src/libvirt.c index a21d00e..7607ae3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -928,6 +928,33 @@ virConnectGetDefaultURI(virConfPtr conf, } +/* + * Check to see if an invalid URI like qemu://system (missing /) was passed, + * offer the suggested fix. + */ +static int +check_uri_missing_slash(const char *uristr, virURIPtr uri) +{ + /* These drivers _only_ accepts URIs with a 'path' element */ + if (STRNEQ(uri->scheme, "qemu") && + STRNEQ(uri->scheme, "vbox")) + return 0; + + if (uri->path != NULL) + return 0; + + if (STREQ(uri->server, "session") || + STREQ(uri->server, "system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid URI %s (maybe you want %s:///%s)"), + uristr, uri->scheme, uri->server); + return -1; + } + + return 0; +} + + static virConnectPtr do_open(const char *name, virConnectAuthPtr auth, @@ -995,6 +1022,11 @@ do_open(const char *name, NULLSTR(ret->uri->user), ret->uri->port, NULLSTR(ret->uri->path)); + if (check_uri_missing_slash(alias ? alias : name, ret->uri) < 0) { + VIR_FREE(alias); + goto failed; + } + VIR_FREE(alias); } else { VIR_DEBUG("no name, allowing driver auto-select");