From nobody Sun May 5 16:05:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1641481529638467.1261715735461; Thu, 6 Jan 2022 07:05:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-150-uU-4hBSGOLOt8OMTnVjFBg-1; Thu, 06 Jan 2022 10:05:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DB7F801AAB; Thu, 6 Jan 2022 15:05:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3868C2B4B1; Thu, 6 Jan 2022 15:05:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 064B64A705; Thu, 6 Jan 2022 15:05:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 206F5Ktv029498 for ; Thu, 6 Jan 2022 10:05:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id B3C2946D1F5; Thu, 6 Jan 2022 15:05:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFFF146D1F4 for ; Thu, 6 Jan 2022 15:05:20 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 962CC802E5E for ; Thu, 6 Jan 2022 15:05:20 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-orSAptJNNpCI1Sc6FPvKUQ-1; Thu, 06 Jan 2022 10:05:19 -0500 Received: by mail-pg1-f180.google.com with SMTP id i30so2819382pgl.0 for ; Thu, 06 Jan 2022 07:05:18 -0800 (PST) Received: from anisinha-lenovo.ba.nuagenetworks.net ([115.96.144.212]) by smtp.googlemail.com with ESMTPSA id 4sm2876838pfy.191.2022.01.06.07.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 07:05:17 -0800 (PST) X-MC-Unique: uU-4hBSGOLOt8OMTnVjFBg-1 X-MC-Unique: orSAptJNNpCI1Sc6FPvKUQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Fa6BDSfCJQZNPLhU7kV8GPixTxDJ8J7JrIq6POTnDOQ=; b=dUz2Z7Js7cF/4FQJBRq7wb59BNtJesvNNInW77yOugaq3rjiGxovrkfVAEZz2pEkbO kHY8GIyRyK4dbi5sVLnx68cD6kyJGHER1ZMo26az7UNkDJ+x0Pk5AXsvVuHQ7rQqZDES 90Bdn7VfWrZYSkeZmenB4S0aFPsaoCocY77NNUZoZM1iq8WhqttCDCOnrUGRt+01wchf 0zkqVCy5DPM4mdCEmosuN7LPF70F0rGqqpuFZX3hzmG/qeOZoHwCZ35JpTVtXhMyguqN V5HsCgGcTYFUs2odXALJGlPfGpw+AcWhS5HXKBb3gPMWkvmUTEQljQUt7TSLyn5GRmRt 4DvQ== X-Gm-Message-State: AOAM533vBGomu1XA8ZBXC/BrdAHJnzjzgF5kS4hh5EdGxj0w4UFMcZwl /+z/DQg5VVrCAcUiCVZZR5Cf61JMZkUyzgme X-Google-Smtp-Source: ABdhPJyA3UYVWeNPdGSjCmdsRLYRwel6FR/dpXmYsp34uqhKmxRJA/zhpgCHnrc7XOVo3Gi7lEG8yg== X-Received: by 2002:a63:4d8:: with SMTP id 207mr53796510pge.206.1641481517360; Thu, 06 Jan 2022 07:05:17 -0800 (PST) From: Ani Sinha To: libvir-list@redhat.com Subject: [PATCH] Make virConnectOpenInternal() report error in all cases Date: Thu, 6 Jan 2022 20:34:26 +0530 Message-Id: <20220106150426.175538-1-ani@anisinha.ca> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-loop: libvir-list@redhat.com Cc: Ani Sinha 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1641481531426100001 Content-Type: text/plain; charset="utf-8" virConnectOpenInternal() does not report error in all failure scenarios, ex= cept in some specific cases. This inconsistent behavior forces the caller of this function report a generic error for all failure modes which then hides spec= ific error scenarios. This change makes virConnectOpenInternal() report failure = in all cases so that it can generate specific errors based on the type of fail= ure encountered. The reporiting of the errors can be made more fine grained in subsequent changes. Signed-off-by: Ani Sinha --- src/libvirt.c | 24 ++++++++++++++++-------- src/libxl/libxl_migration.c | 3 --- src/qemu/qemu_migration.c | 3 --- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 45315f484c..53ceee1359 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -893,8 +893,12 @@ virConnectOpenInternal(const char *name, bool embed =3D false; =20 ret =3D virGetConnect(); - if (ret =3D=3D NULL) + if (ret =3D=3D NULL) { + virReportError(VIR_ERR_INVALID_CONN, + _("Failed to create connection object for URI %s"), + NULLSTR(name)); return NULL; + } =20 if (virConfLoadConfig(&conf, "libvirt.conf") < 0) goto failed; @@ -974,7 +978,7 @@ virConnectOpenInternal(const char *name, virReportError(VIR_ERR_NO_CONNECT, _("URI '%s' does not include a driver name"), name); - goto failed; + goto failed_no_report; } =20 if (virConnectCheckURIMissingSlash(uristr, @@ -992,7 +996,7 @@ virConnectOpenInternal(const char *name, virReportError(VIR_ERR_NO_CONNECT, _("URI scheme '%s' for embedded driver is n= ot valid"), ret->uri->scheme); - goto failed; + goto failed_no_report; } =20 root =3D virURIGetParam(ret->uri, "root"); @@ -1002,7 +1006,7 @@ virConnectOpenInternal(const char *name, if (!g_path_is_absolute(root)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("root path must be absolute")); - goto failed; + goto failed_no_report; } =20 if (virEventRequireImpl() < 0) @@ -1062,7 +1066,7 @@ virConnectOpenInternal(const char *name, __FILE__, __FUNCTION__, __LINE__, _("libvirt was built without the '%s' dri= ver"), ret->uri->scheme); - goto failed; + goto failed_no_report; } =20 VIR_DEBUG("trying driver %zu (%s) ...", @@ -1112,13 +1116,13 @@ virConnectOpenInternal(const char *name, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Driver %s cannot be used in embedded mode"), virConnectDriverTab[i]->hypervisorDriver->name); - goto failed; + goto failed_no_report; } /* before starting the new connection, check if the driver only wo= rks * with a server, and so return an error if the server is missing = */ if (virConnectDriverTab[i]->remoteOnly && ret->uri && !ret->uri->s= erver) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("URI is missing th= e server part")); - goto failed; + goto failed_no_report; } =20 ret->driver =3D virConnectDriverTab[i]->hypervisorDriver; @@ -1155,7 +1159,7 @@ virConnectOpenInternal(const char *name, if (!ret->driver) { /* If we reach here, then all drivers declined the connection. */ virReportError(VIR_ERR_NO_CONNECT, "%s", NULLSTR(name)); - goto failed; + goto failed_no_report; } =20 VIR_FREE(uristr); @@ -1163,6 +1167,10 @@ virConnectOpenInternal(const char *name, return ret; =20 failed: + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to connect to remote libvirt URI %s"), + NULLSTR(uristr)); + failed_no_report: VIR_FREE(uristr); virObjectUnref(ret); =20 diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 6d0ab4ee28..bc2b5401da 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -1134,9 +1134,6 @@ libxlDomainMigrationSrcPerformP2P(libxlDriverPrivate = *driver, virObjectLock(vm); =20 if (dconn =3D=3D NULL) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("Failed to connect to remote libvirt URI %s: %s"), - dconnuri, virGetLastErrorMessage()); return ret; } =20 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index b9d7d582f5..2635ef1162 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -5145,9 +5145,6 @@ qemuMigrationSrcPerformPeer2Peer(virQEMUDriver *drive= r, goto cleanup; =20 if (dconn =3D=3D NULL) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("Failed to connect to remote libvirt URI %s: %s"), - dconnuri, virGetLastErrorMessage()); return -1; } =20 --=20 2.25.1