From nobody Sun May 19 01:43:19 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724710; cv=none; d=zohomail.com; s=zohoarc; b=mWYxFBkWfxzHOBHwr/0QsWoEXcowaCD1aVoAtIZHez71xA6yGMHf/O0nl6jjeGo38w89G+T4o7Oh3oBZvru0OjBfuUTFMlVXYrjgkAiyaYQ6QxtKpNVVBV4QS+o2kN6B5Jbd+H3aOPym6R2SM/JB7BK8fhC66cnOyyorl97z+Zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724710; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J7+8yuL85XVuhF+/8KsHf+t50gvCNXtae5OfScvdryg=; b=COiEpORdqwAiy0xLcJhOz71lJu274QpBznLFh2PVivwW72UhGrhz4cosKYV2wiNeniUcfkic5rrZdHbPVWcXWHR0rUKBj5xpAiD8F8sNO47Pv3FVMnXtmuQWhNiT2/ijYQ5hcyTmQxBuPjoc53CoK8qmY0UM0/2Sm9NnhgstusY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1662724710331235.9214063131892; Fri, 9 Sep 2022 04:58:30 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-602-VcsYTIMvMUqX8tB50V3jiw-1; Fri, 09 Sep 2022 07:58:26 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ACD9883DE3C; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F396D1410F3C; Fri, 9 Sep 2022 11:58:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5E1761946A44; Fri, 9 Sep 2022 11:58:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EDFD41946A41 for ; Fri, 9 Sep 2022 11:58:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E096F2166B29; Fri, 9 Sep 2022 11:58:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31EE82166B26 for ; Fri, 9 Sep 2022 11:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724709; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J7+8yuL85XVuhF+/8KsHf+t50gvCNXtae5OfScvdryg=; b=ZqdlfD+vfgnYeNmMUxV0uRuNL7d07Ic5u1jo5ucgFyaOG1LN/ydIBtwkIPipcOBhsdPuwT pwhCyu1PAF/k396tBV/Mbg583W17TeQ6DMNhl951LaykpcQzxMqpp1QC9Pap1DryedeRh0 v4b4U/1GYeLxx/AoLZ2bP7TGJmXzjvI= X-MC-Unique: VcsYTIMvMUqX8tB50V3jiw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 1/9] virConnectOpenInternal: Avoid double free() when alias is an invalid URI Date: Fri, 9 Sep 2022 13:58:11 +0200 Message-Id: <4f08a463d82ed91be33767bcb3e17d01cbc23ebb.1662723003.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724711926100001 Content-Type: text/plain; charset="utf-8" Configuring an URI alias such as uri_aliases =3D [ "blah=3Dqemu://invaliduri@@@", ] Results in a double free when the alias is used: $ virsh -c blah free(): double free detected in tcache 2 Aborted (core dumped) This happens as the 'alias' variable is first assigned to 'uristr' which is cleared in the 'failed' label and then is explicitly freed again. Fix this by switching to 'g_autofree' for alias and stealing it into 'uristr'. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index b78b49a632..7e7c0fc8e3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -933,21 +933,19 @@ virConnectOpenInternal(const char *name, } if (uristr) { - char *alias =3D NULL; + g_autofree char *alias =3D NULL; if (!(flags & VIR_CONNECT_NO_ALIASES) && virURIResolveAlias(conf, uristr, &alias) < 0) goto failed; if (alias) { - VIR_FREE(uristr); - uristr =3D alias; + g_free(uristr); + uristr =3D g_steal_pointer(&alias); } - if (!(ret->uri =3D virURIParse(uristr))) { - VIR_FREE(alias); + if (!(ret->uri =3D virURIParse(uristr))) goto failed; - } /* Avoid need for drivers to worry about NULLs, as * no one needs to distinguish "" vs NULL */ --=20 2.37.1 From nobody Sun May 19 01:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724752; cv=none; d=zohomail.com; s=zohoarc; b=VPrFFSHS9tHUfGixYW0xQmT+PvfWnPJ6cyUfQKwK+EAYNRz0KxnNd6iTvXehICBQGKae77BGGwvIVGjDZpzbR2Mogl4L+NYtNGXUAFi8up2DIcUw0iWqHhdhNuPknwbPYjJakxx2csdgy8GiI0bk3SmMLyBbu3UPGwm+pnI25NE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724752; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gZARYz9DSHWg8WqXvHu7xSs+4m/eFmpX6yfkBbNysg0=; b=BYevuu62iUqZnSXHcl82Ro4upF6EBpUMcaolkFI9mFn4An3gAdGG4Dax3tNhn3IT4jDxTYx4Sqn/gi4mDBgA0UZXYuIxhtc/Wq98D3f9Te4UpLRQM1s8U6kygDsz3sW3U8hDhBeoSJ+Jm7xAbqBTBPTcI3cVwciwDt6Q61XQHA0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662724752214889.9988045171928; Fri, 9 Sep 2022 04:59:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-lrwfcPIkOTGcnzIF2t5lCg-1; Fri, 09 Sep 2022 07:58:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B9E791C0759B; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7210112131E; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9CC3F1946A49; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D519F1946A5E for ; Fri, 9 Sep 2022 11:58:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C57282166B26; Fri, 9 Sep 2022 11:58:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 420FB2166B29 for ; Fri, 9 Sep 2022 11:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724751; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=gZARYz9DSHWg8WqXvHu7xSs+4m/eFmpX6yfkBbNysg0=; b=JCTcmw8XmKr7eiKZ1PPG7ErOx0RTVSHGg5jvz8aTXeqK9/CMN9kzbRUq4EGMORRbcDOUju CpOuM7edFWHV9x8cLQ7Rayty47s3VwMm9oEY3/PR2C24vNNVZGmePb9DWJF8OYJ11IKygi Z5pfX8psgqK2A+5vH4VF4nZegBCH2yE= X-MC-Unique: lrwfcPIkOTGcnzIF2t5lCg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 2/9] virConnectOpenInternal: Switch to automatic memory cleanup Date: Fri, 9 Sep 2022 13:58:12 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724754058100001 Content-Type: text/plain; charset="utf-8" Use automatic cleanup for 'ret' and 'uristr'. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 7e7c0fc8e3..fca38dba40 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -882,9 +882,9 @@ virConnectOpenInternal(const char *name, { size_t i; int res; - virConnectPtr ret; + g_autoptr(virConnect) ret =3D NULL; g_autoptr(virConf) conf =3D NULL; - char *uristr =3D NULL; + g_autofree char *uristr =3D NULL; bool embed =3D false; ret =3D virGetConnect(); @@ -1151,14 +1151,9 @@ virConnectOpenInternal(const char *name, goto failed; } - VIR_FREE(uristr); - - return ret; + return g_steal_pointer(&ret); failed: - VIR_FREE(uristr); - virObjectUnref(ret); - return NULL; } --=20 2.37.1 From nobody Sun May 19 01:43:19 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724716; cv=none; d=zohomail.com; s=zohoarc; b=SwNnRvPv1VXYycWpo2Jz1Jj5V4vxFu1u+fIWvOEljJsIVUkLWmRlCnl8B42QE4JbDmO4z29bwaqw52BauM8b6SdMbGWXXBMrimkr9EWAzHBCGOhbsQjLCscOL2mdSlgiVZgUCJe2NRGMyWA8c0UNujVNwshyjuRV9WvIhwbDy7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724716; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mrsQ4eS2jY78cYIGymLe2Gw6emgKI/8cWyT7we9Q4no=; b=Kuene5VO8CNuvVz81JkX7V+hf3/T8lJ/TvQSzjfGhXQ9CeITEmF7gJLFF7l5xL6JvpNMSLvbQ04+V0wIKIczdHdkCa13wOrH5lIqJvukKsIF8h9eUWMMHUO4S2icI65gSnv5GAFcyDTZqw01a/I1PQz+Pr43gYaBOZg/xqggKPQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1662724716099537.6604798377639; Fri, 9 Sep 2022 04:58:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-604-buV9UMfpOry9RG6PP6KZ4w-1; Fri, 09 Sep 2022 07:58:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F4681C0758D; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CD771121315; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E68B01946A42; Fri, 9 Sep 2022 11:58:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D0D6A1946A49 for ; Fri, 9 Sep 2022 11:58:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B5F132166B29; Fri, 9 Sep 2022 11:58:23 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EFA92166B26 for ; Fri, 9 Sep 2022 11:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724714; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mrsQ4eS2jY78cYIGymLe2Gw6emgKI/8cWyT7we9Q4no=; b=WnTHVnI67C2n7gwkXXeq9TBkAOmLGw4BB+/3o6m9WKl21a6e0nBCKch+0IPi3vTYI9QsZj YP3BzitJ2H3sPbBW0y5wGBFL7N+gDtA0oTE6Ln8o6MGC7sVcql9NTLwjWdbGAfGaB3Dv4e fxLD6os9dq87xPQIuWFVq9aeNxEOeE8= X-MC-Unique: buV9UMfpOry9RG6PP6KZ4w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 3/9] virConnectOpenInternal: Remove 'failed' label Date: Fri, 9 Sep 2022 13:58:13 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724717971100002 Content-Type: text/plain; charset="utf-8" Jumping to the label would just return NULL. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index fca38dba40..d5ae68d16f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -892,7 +892,7 @@ virConnectOpenInternal(const char *name, return NULL; if (virConfLoadConfig(&conf, "libvirt.conf") < 0) - goto failed; + return NULL; if (name && name[0] =3D=3D '\0') name =3D NULL; @@ -916,14 +916,14 @@ virConnectOpenInternal(const char *name, uristr =3D g_strdup(name); } else { if (virConnectGetDefaultURI(conf, &uristr) < 0) - goto failed; + return NULL; if (uristr =3D=3D NULL) { VIR_DEBUG("Trying to probe for default URI"); for (i =3D 0; i < virConnectDriverTabCount && uristr =3D=3D NU= LL; i++) { if (virConnectDriverTab[i]->hypervisorDriver->connectURIPr= obe) { if (virConnectDriverTab[i]->hypervisorDriver->connectU= RIProbe(&uristr) < 0) - goto failed; + return NULL; VIR_DEBUG("%s driver URI probe returned '%s'", virConnectDriverTab[i]->hypervisorDriver->na= me, NULLSTR(uristr)); @@ -937,7 +937,7 @@ virConnectOpenInternal(const char *name, if (!(flags & VIR_CONNECT_NO_ALIASES) && virURIResolveAlias(conf, uristr, &alias) < 0) - goto failed; + return NULL; if (alias) { g_free(uristr); @@ -945,7 +945,7 @@ virConnectOpenInternal(const char *name, } if (!(ret->uri =3D virURIParse(uristr))) - goto failed; + return NULL; /* Avoid need for drivers to worry about NULLs, as * no one needs to distinguish "" vs NULL */ @@ -967,12 +967,12 @@ virConnectOpenInternal(const char *name, virReportError(VIR_ERR_NO_CONNECT, _("URI '%s' does not include a driver name"), name); - goto failed; + return NULL; } if (virConnectCheckURIMissingSlash(uristr, ret->uri) < 0) { - goto failed; + return NULL; } if (STREQ(ret->uri->path, "/embed")) { @@ -985,26 +985,26 @@ virConnectOpenInternal(const char *name, virReportError(VIR_ERR_NO_CONNECT, _("URI scheme '%s' for embedded driver is n= ot valid"), ret->uri->scheme); - goto failed; + return NULL; } root =3D virURIGetParam(ret->uri, "root"); if (!root) - goto failed; + return NULL; if (!g_path_is_absolute(root)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("root path must be absolute")); - goto failed; + return NULL; } if (virEventRequireImpl() < 0) - goto failed; + return NULL; regMethod =3D g_strdup_printf("%sRegister", ret->uri->scheme); if (virDriverLoadModule(ret->uri->scheme, regMethod, false) < = 0) - goto failed; + return NULL; if (virAccessManagerGetDefault() =3D=3D NULL) { virAccessManager *acl; @@ -1012,12 +1012,12 @@ virConnectOpenInternal(const char *name, virResetLastError(); if (!(acl =3D virAccessManagerNew("none"))) - goto failed; + return NULL; virAccessManagerSetDefault(acl); } if (virStateInitialize(geteuid() =3D=3D 0, true, root, NULL, N= ULL) < 0) - goto failed; + return NULL; embed =3D true; } @@ -1055,7 +1055,7 @@ virConnectOpenInternal(const char *name, __FILE__, __FUNCTION__, __LINE__, _("libvirt was built without the '%s' dri= ver"), ret->uri->scheme); - goto failed; + return NULL; } VIR_DEBUG("trying driver %zu (%s) ...", @@ -1105,13 +1105,13 @@ virConnectOpenInternal(const char *name, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Driver %s cannot be used in embedded mode"), virConnectDriverTab[i]->hypervisorDriver->name); - goto failed; + return NULL; } /* 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; + return NULL; } ret->driver =3D virConnectDriverTab[i]->hypervisorDriver; @@ -1141,20 +1141,17 @@ virConnectOpenInternal(const char *name, ret->storageDriver =3D NULL; if (res =3D=3D VIR_DRV_OPEN_ERROR) - goto failed; + return NULL; } } if (!ret->driver) { /* If we reach here, then all drivers declined the connection. */ virReportError(VIR_ERR_NO_CONNECT, "%s", NULLSTR(name)); - goto failed; + return NULL; } return g_steal_pointer(&ret); - - failed: - return NULL; } --=20 2.37.1 From nobody Sun May 19 01:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724754; cv=none; d=zohomail.com; s=zohoarc; b=NguBxhWQUJEA4ZrtKeNKAb8vgz1sdJW59unJp+jYtzYAlJTbWVCd1GFmPtfXVglDwH7Q0522CVvTeNsQS2QtlegPpDSatZwJOpK7hi/9XLrJh+US5Oj5AEviLvD4mnkzVatVMadaOvmo+MgkjjLLGLM+ry3yu5/DyeNCdn+60Zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724754; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=02AwTtRYuY8iieRmb+bsVRYpJzRFt+pRcD4FHguLyUU=; b=E42Amsl20jR2ls4/3ajYFQ1coCukM7mf70PsPQe3uKUcu+myojCfKXu1cjbatHsYPAo8iQ/bM7ZsCoVJHeCy41g6A6Dykn30lF0qcfSbb/ZHWkGJNO4g8RDJ25uYOJtjgnik8h7Vc0WB/yTS+yIIEZDxGxZqtwOUIjrzA3u6LnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662724754913737.1181596769114; Fri, 9 Sep 2022 04:59:14 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-RveGjlE9PjOzq_w7Liw1YQ-1; Fri, 09 Sep 2022 07:58:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 597B5823F18; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47A6AC15BB3; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 320BD1946A42; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AC3A81946A41 for ; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9E4622166B29; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 190B62166B26 for ; Fri, 9 Sep 2022 11:58:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724753; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=02AwTtRYuY8iieRmb+bsVRYpJzRFt+pRcD4FHguLyUU=; b=Z4XzOWgMugKpo3llXmEvknOsejAdoQ8qmAPyUf9EyrgrJrkCmWOlBhEUww81D+CvaxWBl/ RrfXF1ph8B8jxsWysDySBfFyYmRlPMXRWJaL0sgg0eoJLEtxYYtnPLXkjZjRQWZceQc+zF aGD7uQ416iGxk/Xq0D2hSgZOx12uT+E= X-MC-Unique: RveGjlE9PjOzq_w7Liw1YQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 4/9] remote: remoteOpenConn: Use virConnectOpenAuth instead of virConnectOpen(ReadOnly) Date: Fri, 9 Sep 2022 13:58:14 +0200 Message-Id: <0d756470786c4a9a4f0da185d5a8b83f08c4bf3f.1662723003.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724756059100003 Content-Type: text/plain; charset="utf-8" virConnectOpenAuth provides an unified interface with using 'flags' to select the proper mode. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/remote/remote_daemon_dispatch.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index dc5790f077..061e0f7811 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1790,6 +1790,7 @@ remoteOpenConn(const char *uri, { g_autoptr(virTypedParamList) identparams =3D NULL; g_autoptr(virConnect) newconn =3D NULL; + unsigned int connectFlags =3D 0; VIR_DEBUG("Getting secondary uri=3D%s readonly=3D%d preserveIdent=3D%d= conn=3D%p", NULLSTR(uri), readonly, preserveIdentity, conn); @@ -1814,11 +1815,9 @@ remoteOpenConn(const char *uri, VIR_DEBUG("Opening driver %s", uri); if (readonly) - newconn =3D virConnectOpenReadOnly(uri); - else - newconn =3D virConnectOpen(uri); + connectFlags |=3D VIR_CONNECT_RO; - if (!newconn) + if (!(newconn =3D virConnectOpenAuth(uri, NULL, connectFlags))) return -1; VIR_DEBUG("Opened driver %p", newconn); --=20 2.37.1 From nobody Sun May 19 01:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724716; cv=none; d=zohomail.com; s=zohoarc; b=Reiq5XOMZJYXuP5LJFfNxvTtP/ExxgejORlN4jlpQfZvmavDVGs3BmEvjKP6fdSNxmgG/6WpegLwY4Q7EbypBsowHL/7rCjncpoD3hmIQR0fWUDQTLfWvF3TTEYwJCncNJpp+b3Rz3cl/oT8qmeHwjJfhAKnevAchlz1ZNWYhBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724716; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2ugZcJ8AkCziRe+l2GboKPDA4NRB55jkhzrhyPyVSbM=; b=Lf4UxeTjP+KAs3ly3Q9liHqTdORSp8hg5KAyZYl8aYjdpvZ2+gH+SF6AFKpAMivzWjJ17nLra91ur4jy1zghDB97Z+GgovE6gKgmIu2ibR6xdNXU0jPDj3bOnvHSClVv3m22WE/HTGcfLst/95OBRCQ8LTRE6rGxRmyi4gTyljM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662724716982933.7075374686864; Fri, 9 Sep 2022 04:58:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-9-FYz2cnjeMVCJo6kb3UfVEA-1; Fri, 09 Sep 2022 07:58:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB24C8039A0; Fri, 9 Sep 2022 11:58:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7CF140C141D; Fri, 9 Sep 2022 11:58:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C776E1946A48; Fri, 9 Sep 2022 11:58:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B081F1946A41 for ; Fri, 9 Sep 2022 11:58:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 941302166B26; Fri, 9 Sep 2022 11:58:25 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EA2A2166B29 for ; Fri, 9 Sep 2022 11:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724715; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2ugZcJ8AkCziRe+l2GboKPDA4NRB55jkhzrhyPyVSbM=; b=PrcJ8whQ5Y3Qlw2TuBGzzL/8xkHaGzP5wmove/B8SOg9YhigPVKvk+a13MxdmyWR6ylmId MvqqoZHWlRBsOmEehpdwoSIOij2KtA/C2xd0tb8Zhwx7RHZwlTt7BRUub+FsWXQneoKbhS 5rzALeJ4um1OULRGxzfUILzx0Cj/GhY= X-MC-Unique: FYz2cnjeMVCJo6kb3UfVEA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 5/9] remoteConnectOpen: Refactor cleanup Date: Fri, 9 Sep 2022 13:58:15 +0200 Message-Id: <7c897db7658fd15fef2e8273cbc3458c18af6b5b.1662723003.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724717961100001 Content-Type: text/plain; charset="utf-8" Use automatic memory freeing for 'driver' and return error right away to avoid the 'cleanup' label. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/remote/remote_driver.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 0ca365c4cc..b670284211 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1228,23 +1228,20 @@ remoteConnectOpen(virConnectPtr conn, struct private_data *priv; int ret =3D VIR_DRV_OPEN_ERROR; unsigned int rflags =3D 0; - char *driver =3D NULL; + g_autofree char *driver =3D NULL; remoteDriverTransport transport; if (conn->uri) { if (remoteSplitURIScheme(conn->uri, &driver, &transport) < 0) - goto cleanup; + return VIR_DRV_OPEN_ERROR; } else { /* No URI, then must be probing so use UNIX socket */ transport =3D REMOTE_DRIVER_TRANSPORT_UNIX; } - if (inside_daemon) { - if (!conn->uri) { - ret =3D VIR_DRV_OPEN_DECLINED; - goto cleanup; - } + if (!conn->uri) + return VIR_DRV_OPEN_DECLINED; /* If there's a driver registered we must defer to that. * If there isn't a driver, we must connect in "direct" @@ -1254,15 +1251,12 @@ remoteConnectOpen(virConnectPtr conn, * host */ if (!conn->uri->server && virHasDriverForURIScheme(driver) && - !virURICheckUnixSocket(conn->uri)) { - ret =3D VIR_DRV_OPEN_DECLINED; - goto cleanup; - } + !virURICheckUnixSocket(conn->uri)) + return VIR_DRV_OPEN_DECLINED; } if (!(priv =3D remoteAllocPrivateData())) - goto cleanup; - + return VIR_DRV_OPEN_ERROR; remoteGetURIDaemonInfo(conn->uri, transport, &rflags); if (flags & VIR_CONNECT_RO) @@ -1278,8 +1272,6 @@ remoteConnectOpen(virConnectPtr conn, remoteDriverUnlock(priv); } - cleanup: - VIR_FREE(driver); return ret; } --=20 2.37.1 From nobody Sun May 19 01:43:19 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724718; cv=none; d=zohomail.com; s=zohoarc; b=AZSEgdvqjKijprvymd/toIpFdhRn9MIi3uwfUnlh5G7rdyrjGQkqGTIknEj6/fB7tIZAHCi1cyRgbm8IPAg5EVckbIacfN3d5kw2WQSFCxCzT7shn6iKB4NC6XsT/X+01LhULPYIOa89COeQCFDIy7HfkIugPyE+ThPsWyPedyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724718; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cCs+Lnq8gMJNoYl1xo0J8DJKLk9NDncgGaH4ks6lp/E=; b=N7mzG8fwmowENVmi+5EgIDO6qqhvVnuWuy4y4LpYv/3RmIrKPZCl25ZZDS4RGcvIdcfgk83TAXtjhc+75gkat/Xb97dVHWSRkUFm5Sq7xWrC5VaruVbKec8a3aClnlPJhkwUhsvoD3d+Ji2bvSwyd2+PVBZcShVONYKpmWeV5t4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1662724718751505.91238969462324; Fri, 9 Sep 2022 04:58:38 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-HtC9Qo1bOvuTTRUlfsjmhw-1; Fri, 09 Sep 2022 07:58:30 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD4338039A1; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8B8314152E0; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7D4D41946A65; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9B01E1946A41 for ; Fri, 9 Sep 2022 11:58:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 807FE2166B29; Fri, 9 Sep 2022 11:58:26 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E92282166B26 for ; Fri, 9 Sep 2022 11:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724717; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cCs+Lnq8gMJNoYl1xo0J8DJKLk9NDncgGaH4ks6lp/E=; b=TGhUFOKe5sRebmuvYT2qk4o6VhIkwY/d1COVtg+oC47dm6wrTWjFFCnPuwwmOS2G1LdOJI U1CZgB8rIrp9Z4Prpbc5nKJFz9AMm5N+vRim+5UAQ9u8JkQCSqGrBOXnJvtPUK7Cx9VeyB 4uBu0dDiMg83xwtmU5wHyq/tTH7JuSg= X-MC-Unique: HtC9Qo1bOvuTTRUlfsjmhw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 6/9] remote: doRemoteOpen: Automatically clean up 'priv' Date: Fri, 9 Sep 2022 13:58:16 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724719962100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/remote/remote_driver.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index b670284211..25c80a09c7 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1225,7 +1225,7 @@ remoteConnectOpen(virConnectPtr conn, virConf *conf, unsigned int flags) { - struct private_data *priv; + g_autofree struct private_data *priv =3D NULL; int ret =3D VIR_DRV_OPEN_ERROR; unsigned int rflags =3D 0; g_autofree char *driver =3D NULL; @@ -1263,14 +1263,12 @@ remoteConnectOpen(virConnectPtr conn, rflags |=3D REMOTE_DRIVER_OPEN_RO; ret =3D doRemoteOpen(conn, priv, driver, transport, auth, conf, rflags= ); - if (ret !=3D VIR_DRV_OPEN_SUCCESS) { + remoteDriverUnlock(priv); + + if (ret !=3D VIR_DRV_OPEN_SUCCESS) conn->privateData =3D NULL; - remoteDriverUnlock(priv); - VIR_FREE(priv); - } else { - conn->privateData =3D priv; - remoteDriverUnlock(priv); - } + else + conn->privateData =3D g_steal_pointer(&priv); return ret; } --=20 2.37.1 From nobody Sun May 19 01:43:19 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724721; cv=none; d=zohomail.com; s=zohoarc; b=GQY3mgG7Py1xcZ0VHa+gVc8xewhuO3mWPwX2+u//xLu2KY+Oy0R/cPYTMQGQAeF+MslhvVeeA39hji4fkl27taBrJqLI7AychGu2n+BagPSYmYstP5axs40a2pOdVEMNBkf0rIc1a52c7fCfU+qDl0eJRNxgm13oy/ce8PtpKGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724721; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pKQ+AVDCDTfFpERfEst/xBs+zTnQwzRjjNJeiyKoHh4=; b=f+UQOAOeVUsdGI7pdhrnqpKXi3KXTCVuOd391KvQ4mBTNAt/59/LYnZfSqn1uDpun8LTUa6ziWJC5POTU6GbTDKpfno7WI3XKVLzblmuHvE3j9lRyvSbUjEROtBukuQHaqdb0l9IW8TppunG0g68iHRxcjEftUJXnpUsY5+m4YQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1662724720990784.8170364176361; Fri, 9 Sep 2022 04:58:40 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-kxccC15nMyu0KQTOhE6how-1; Fri, 09 Sep 2022 07:58:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C5BA8582A8; Fri, 9 Sep 2022 11:58:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3475C40E7F32; Fri, 9 Sep 2022 11:58:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 221241946A58; Fri, 9 Sep 2022 11:58:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 975511946A5A for ; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 752E42166B2D; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2D892166B26 for ; Fri, 9 Sep 2022 11:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724720; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=pKQ+AVDCDTfFpERfEst/xBs+zTnQwzRjjNJeiyKoHh4=; b=MjGLHfML4sxf3dUIEQpYAIFnlszh7J/2ae7kfWwXxV1Vqxy8045dkhPut2pwsBC6ZZ8Cz9 of1syZHWRHvaS8mk22Bbd3qsO35FaMujY2/+FVrqKkfkdhvVIc+BXP9uwDKv026OZiY/Vu L0YDc5ZNte/5P5Q0zakMvlPCXm76oQ4= X-MC-Unique: kxccC15nMyu0KQTOhE6how-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 7/9] lxc: Remove unneeded forward declaration of 'lxcStateInitialize' Date: Fri, 9 Sep 2022 13:58:17 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724721960100007 Content-Type: text/plain; charset="utf-8" The function is used only after the definition. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_driver.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e7c6c4fbc4..f2a358805a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -79,10 +79,6 @@ VIR_LOG_INIT("lxc.lxc_driver"); #define LXC_NB_DOMAIN_BLOCK_STAT_PARAM 4 -static int lxcStateInitialize(bool privileged, - const char *root, - virStateInhibitCallback callback, - void *opaque); static int lxcStateCleanup(void); virLXCDriver *lxc_driver =3D NULL; --=20 2.37.1 From nobody Sun May 19 01:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724724; cv=none; d=zohomail.com; s=zohoarc; b=F6H9lI3+R+hr9YWCbqD7NrAfq/wY6xWDhOMLm/WG6hVkPEJJT4N43hroXpZUlu9H96/J45YDvwJXcLFUBsUAVeHOHAhYEZHd6l6HY4jWSbxNiLImdp5Pb+RDCxRkGr2pESKP9IzoSTbcbpj6QV8A3iXtWm7EfjiTCBv182XuSPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724724; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tih0XZNrCvTdpxbggdOfj/rcK3qufDVKcHYJHADITMI=; b=TNGcoO6y5Q7IXdVpY3AXoLpvDtHSzgUOYSSQBFaPPqP1SLUkBybBxsjmYDbLCk6FfyqCc8exfjd0gsstY5ICyCc3XqiY4AtZJEyp/iLlCEGMl1zt9TPIn0Of9sZ/Obt0WP1EdMlBZ3HPsDTgBUtrHEI+yaSDTvs6LKF9EcOC74A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662724724000440.82166132105954; Fri, 9 Sep 2022 04:58:44 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-CVHWQ7YPMGGzt4TbK6xB9w-1; Fri, 09 Sep 2022 07:58:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24A6B1066566; Fri, 9 Sep 2022 11:58:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EAEA2166B26; Fri, 9 Sep 2022 11:58:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E8A291946A42; Fri, 9 Sep 2022 11:58:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 756C41946A4A for ; Fri, 9 Sep 2022 11:58:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 677862166B29; Fri, 9 Sep 2022 11:58:28 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC4FA2166B26 for ; Fri, 9 Sep 2022 11:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724721; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Tih0XZNrCvTdpxbggdOfj/rcK3qufDVKcHYJHADITMI=; b=fJFFamciZvEMzGltEVBA5Xc6wqilXnxJhFZsYRZI9Z2JFu/9oIjZc+JF4FppylzZLPi5LT CjUmaszkk0MY+mGgW1ekAwExEgIC4K8NrcEI4WlYt+RxxakIK3lVvkqoxSt88F5+wm4R3v 4aZEhZyXyK8r54SnTrOvYC0T0bcQg8A= X-MC-Unique: CVHWQ7YPMGGzt4TbK6xB9w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 8/9] virStateInitialize: Propagate whether running in monolithic daemon mode to stateful driver init Date: Fri, 9 Sep 2022 13:58:18 +0200 Message-Id: <7f4752fddbe79330e86f7c65c6ff461a6b0e4c98.1662723003.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724726002100001 Content-Type: text/plain; charset="utf-8" Upcoming patch which is fixing the opening of drivers in monolithic mode needs to know whether we are inside 'libvirtd' but the code where the decision needs to happen is not re-compiled per daemon. Thus we need to pass this information to the stateful driver init function so that it can be remebered. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/bhyve/bhyve_driver.c | 1 + src/ch/ch_driver.c | 1 + src/driver-state.h | 1 + src/interface/interface_backend_netcf.c | 1 + src/interface/interface_backend_udev.c | 1 + src/libvirt.c | 5 ++++- src/libvirt_internal.h | 1 + src/libxl/libxl_driver.c | 1 + src/lxc/lxc_driver.c | 1 + src/network/bridge_driver.c | 1 + src/node_device/node_device_udev.c | 1 + src/nwfilter/nwfilter_driver.c | 1 + src/qemu/qemu_driver.c | 1 + src/remote/remote_daemon.c | 6 ++++++ src/remote/remote_driver.c | 1 + src/secret/secret_driver.c | 1 + src/storage/storage_driver.c | 1 + src/vz/vz_driver.c | 1 + 18 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 09ba52483a..e0bf2a19a6 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1178,6 +1178,7 @@ bhyveStateCleanup(void) static int bhyveStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index c6e92efb2c..db2a66d131 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -861,6 +861,7 @@ static int chStateCleanup(void) static int chStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSE= D, void *opaque G_GNUC_UNUSED) { diff --git a/src/driver-state.h b/src/driver-state.h index f3a0638e90..7f8b61fa1c 100644 --- a/src/driver-state.h +++ b/src/driver-state.h @@ -33,6 +33,7 @@ typedef enum { typedef virDrvStateInitResult (*virDrvStateInitialize)(bool privileged, const char *root, + bool monolithic, virStateInhibitCallback callback, void *opaque); diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interf= ace_backend_netcf.c index 90514692e2..5964720e0f 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -89,6 +89,7 @@ virNetcfDriverStateDispose(void *obj) static int netcfStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 32318d8d50..979f187d87 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -1110,6 +1110,7 @@ udevStateCleanup(void); static int udevStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/libvirt.c b/src/libvirt.c index d5ae68d16f..1b4c90e110 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -604,6 +604,7 @@ virRegisterStateDriver(virStateDriver *driver) * @privileged: set to true if running with root privilege, false otherwise * @mandatory: set to true if all drivers must report success, not skipped * @root: directory to use for embedded mode + * @monolithic: set to true if running in monolithic mode (daemon is libvi= rtd) * @callback: callback to invoke to inhibit shutdown of the daemon * @opaque: data to pass to @callback * @@ -633,6 +634,7 @@ int virStateInitialize(bool privileged, bool mandatory, const char *root, + bool monolithic, virStateInhibitCallback callback, void *opaque) { @@ -650,6 +652,7 @@ virStateInitialize(bool privileged, virStateDriverTab[i]->initialized =3D true; ret =3D virStateDriverTab[i]->stateInitialize(privileged, root, + monolithic, callback, opaque); VIR_DEBUG("State init result %d (mandatory=3D%d)", ret, mandat= ory); @@ -1016,7 +1019,7 @@ virConnectOpenInternal(const char *name, virAccessManagerSetDefault(acl); } - if (virStateInitialize(geteuid() =3D=3D 0, true, root, NULL, N= ULL) < 0) + if (virStateInitialize(geteuid() =3D=3D 0, true, root, false, = NULL, NULL) < 0) return NULL; embed =3D true; diff --git a/src/libvirt_internal.h b/src/libvirt_internal.h index f4e592922d..1ae3e2b2e0 100644 --- a/src/libvirt_internal.h +++ b/src/libvirt_internal.h @@ -32,6 +32,7 @@ typedef void (*virStateInhibitCallback)(bool inhibit, int virStateInitialize(bool privileged, bool mandatory, const char *root, + bool monolithic, virStateInhibitCallback inhibit, void *opaque); int virStateShutdownPrepare(void); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 79af2f4441..1b8b40e9e0 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -648,6 +648,7 @@ libxlAddDom0(libxlDriverPrivate *driver) static int libxlStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback, void *opaque) { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f2a358805a..d66c26221c 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1430,6 +1430,7 @@ lxcSecurityInit(virLXCDriverConfig *cfg) static int lxcStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUS= ED, void *opaque G_GNUC_UNUSED) { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 7c7812e276..7c6430b4e3 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -575,6 +575,7 @@ firewalld_dbus_signal_callback(GDBusConnection *connect= ion G_GNUC_UNUSED, static int networkStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index a06eaade5d..07c10f0d88 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2226,6 +2226,7 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_GN= UC_UNUSED, static int nodeStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index d1bdd806fc..9cb306909c 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -211,6 +211,7 @@ nwfilterStateCleanup(void) static int nwfilterStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6931f0670d..94b70872d4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -549,6 +549,7 @@ qemuDomainFindMaxID(virDomainObj *vm, static int qemuStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback, void *opaque) { diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 36d95de83d..f369d09d35 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -591,6 +591,11 @@ static void daemonRunStateInit(void *opaque) #else /* ! MODULE_NAME */ bool mandatory =3D false; #endif /* ! MODULE_NAME */ +#ifdef LIBVIRTD + bool monolithic =3D true; +#else /* ! LIBVIRTD */ + bool monolithic =3D false; +#endif /* ! LIBVIRTD */ virIdentitySetCurrent(sysident); @@ -605,6 +610,7 @@ static void daemonRunStateInit(void *opaque) if (virStateInitialize(virNetDaemonIsPrivileged(dmn), mandatory, NULL, + monolithic, daemonInhibitCallback, dmn) < 0) { VIR_ERROR(_("Driver state initialization failed")); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 25c80a09c7..33cc6b1fce 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -168,6 +168,7 @@ static void make_nonnull_domain_snapshot(remote_nonnull= _domain_snapshot *snapsho static int remoteStateInitialize(bool privileged G_GNUC_UNUSED, const char *root G_GNUC_UNUSED, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 080ed962a9..6328589fa4 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -462,6 +462,7 @@ secretStateCleanup(void) static int secretStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 8dc2cfa7c9..fccf0fcf52 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -242,6 +242,7 @@ storageDriverAutostart(void) static int storageStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 571d895167..4f5e340d53 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -4077,6 +4077,7 @@ vzStateCleanup(void) static int vzStateInitialize(bool privileged, const char *root, + bool monolithic G_GNUC_UNUSED, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { --=20 2.37.1 From nobody Sun May 19 01:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662724743; cv=none; d=zohomail.com; s=zohoarc; b=WNaaWOirg4tp0pXmEWZfxWlVj6O2bMCk3UM/grmpCuhrCoHa/Vtk5GxdUrLal1EgpR/Bqb1Y/U1YHnFCuddo4aNh7YaomHKVvjIU0LsB3pe+wGuevpWxqhJl7X8WvsJQh20oTkt7PWohAE7mN0iDmSDI79AZxyFprZaP91eKe28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662724743; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MR3i9OOFOK1z/VhiqTNXnFbOl0lP4VzrVHggeyEo4PQ=; b=PDqJKZchOEZUIT8b4WT1p0EW12/j2ido+QQJS7trCRvlUMnf5kdbNfsE3D1EfLdLE+B4dpw8gPt14OWo71IHjO8txyyhXnu3f8/Lh4V8TE8E8Dj32psljH8P35hOHrHwrh14G1/sqKWVPX56JPhGq5alPZqP2g8j1tBjMsIIecc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662724743175348.2025419175832; Fri, 9 Sep 2022 04:59:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-_urjLh8ENwqOIyIbUe_44Q-1; Fri, 09 Sep 2022 07:58:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8BAFD85A58E; Fri, 9 Sep 2022 11:58:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7751A4C819; Fri, 9 Sep 2022 11:58:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5A6491946A44; Fri, 9 Sep 2022 11:58:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5BCE01946A48 for ; Fri, 9 Sep 2022 11:58:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5006F2166B2A; Fri, 9 Sep 2022 11:58:29 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0B472166B26 for ; Fri, 9 Sep 2022 11:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662724742; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=MR3i9OOFOK1z/VhiqTNXnFbOl0lP4VzrVHggeyEo4PQ=; b=WUGeNHGCbJktMzGrodAZZEBPCtTh7liVV3oOhZqILinW8lR7gRWDNfpqlSCSdalR7g/dNg 66Urtak4/9DMzjVqwmhFS7alnBO0xUVZnNvJ4OFtaL1X6gHyT1SBPbh4W/ZalTtXHFhSh+ xF5n6v1W5Xji0m05wK7xsdbhq4VkyCs= X-MC-Unique: _urjLh8ENwqOIyIbUe_44Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 9/9] remote: Don't attempt remote connection from libvirtd Date: Fri, 9 Sep 2022 13:58:19 +0200 Message-Id: <912e09484a9e27fb5c4f58af8fbefd6631bf2557.1662723003.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662724744053100001 Content-Type: text/plain; charset="utf-8" When a hypervisor driver is not compiled in and a user enables the monolithic libvirtd, they get the following misleading error: $ virsh -c qemu:///system error: failed to connect to the hypervisor error: Failed to connect socket to '/var/run/libvirt/virtqemud-sock': No = such file or directory The issue is that the daemon side of the remote driver can't find the appropriate driver, but the remote driver always accepts everything and thus attempts to delegate further, which in case of libvirtd makes no sense. Refuse opening a connection for local URIS even when the requested driver is not registered in case when we are inside 'libvirtd' as libvirtd doesn't have anything to delegate to. $ virsh -c qemu:///system error: failed to connect to the hypervisor error: no connection driver available for qemu:///system Discovered when investigating https://gitlab.com/libvirt/libvirt/-/issues/3= 70 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/remote/remote_driver.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 33cc6b1fce..a4efe101a3 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -73,6 +73,7 @@ VIR_LOG_INIT("remote.remote_driver"); #endif static bool inside_daemon; +static bool monolithic_daemon; struct private_data { virMutex lock; @@ -168,7 +169,7 @@ static void make_nonnull_domain_snapshot(remote_nonnull= _domain_snapshot *snapsho static int remoteStateInitialize(bool privileged G_GNUC_UNUSED, const char *root G_GNUC_UNUSED, - bool monolithic G_GNUC_UNUSED, + bool monolithic, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { @@ -176,6 +177,7 @@ remoteStateInitialize(bool privileged G_GNUC_UNUSED, * re-entering ourselves */ inside_daemon =3D true; + monolithic_daemon =3D monolithic; return VIR_DRV_STATE_INIT_COMPLETE; } @@ -1244,16 +1246,22 @@ remoteConnectOpen(virConnectPtr conn, if (!conn->uri) return VIR_DRV_OPEN_DECLINED; - /* If there's a driver registered we must defer to that. - * If there isn't a driver, we must connect in "direct" - * mode - see doRemoteOpen. - * One exception is if we are trying to connect to an - * unknown socket path as that might be proxied to remote - * host */ - if (!conn->uri->server && - virHasDriverForURIScheme(driver) && - !virURICheckUnixSocket(conn->uri)) - return VIR_DRV_OPEN_DECLINED; + /* Handle deferring to local drivers if we are dealing with a defa= ult + * local URI. (Unknown local socket paths may be proxied to a remo= te + * host so they are treated as remote too). + * + * Deferring to a local driver is needed if: + * - the driver is registered in the current daemon + * - if we are running monolithic libvirtd, in which case we consi= der + * even un-registered drivers as local + */ + if (!conn->uri->server && !virURICheckUnixSocket(conn->uri)) { + if (virHasDriverForURIScheme(driver)) + return VIR_DRV_OPEN_DECLINED; + + if (monolithic_daemon) + return VIR_DRV_OPEN_DECLINED; + } } if (!(priv =3D remoteAllocPrivateData())) --=20 2.37.1