From nobody Wed May 8 22:12:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1570568540; cv=none; d=zoho.com; s=zohoarc; b=eEDuHXR6jWpFpBn9/nQwmMjoFI7uxvElsw91lnvyxEM8fYfhDseoPUK/GP4IP0jNGeEs+QQd9EdEHR2yLPOTBPdbmr6BxCdLZvgAQhoOWCE2gQnS+I986xKkCB0hK8SZCwZthPkHkmWAnWE4MbJZRVQvgxGtkxCDXJlPQavC4W4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570568540; h=Content-Type:Content-Transfer-Encoding:Cc: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=I/C0Sb20e4wS/+R7pazaly3QIgqrJM3wkk2zMdD7ovE=; b=FFRsnu8vFkIRH1iEAtwbp361PVq+0Vuchp4RPL63goGoDEIAzfVRqfxLxiYwU8oMGZ/cwk91a5XsDiFVA9+qzfM0DlqEnzunfWHK9jtHwAatXnt9CZ17tQel4zj9+G1E08vqRh6DQZfJVcch42opAq+Fm7d2tiPPfz+vJ/2ldpw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570568540226581.6433823051013; Tue, 8 Oct 2019 14:02:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id F38CB10CC1EE; Tue, 8 Oct 2019 21:02:17 +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 AC98419C7F; Tue, 8 Oct 2019 21:02:17 +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 1B3F74EE96; Tue, 8 Oct 2019 21:02:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x98L2GaN024952 for ; Tue, 8 Oct 2019 17:02:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68E1D60C18; Tue, 8 Oct 2019 21:02:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1F9260BF4; Tue, 8 Oct 2019 21:02:13 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63A73C01FBD9; Tue, 8 Oct 2019 21:02:12 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id h126so168768qke.10; Tue, 08 Oct 2019 14:02:12 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:e8e7:3739:3e28:be31:8030]) by smtp.gmail.com with ESMTPSA id w14sm8907486qki.73.2019.10.08.14.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 14:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6UazZUIs5V4Arc5XB/w4q5VVuheXtF4XbVZquGKMPns=; b=chEyNXuKQ3P7ut4mRUCiNNTNnneLvnnLbO2/DrV3ZSM5iBV/WXDNRLQgwN3KJQcp1x pDASZFHS4n0AJtQkovQENzk+UyCZjuFfdsDdj/pCDAvSWOCDfyCvAOzhB/8BrvzF4mGo CJVi5Sy81O3wqxazsuM5MRWiLMFCEKhWfShjBMsKfMYQAXV4cKCCilBgSY0Qll2GAgp5 3ncHcB3ziazfpTWXBFu2yo+VLo7dYxaPu/iNUeokosWC+9EFKpczOuVypW1+q94e0qL4 gy9+mEsjlOdNCYAntJsSWCRp8pBIg8HaiMrDLJtyRgzMjLRBMzD4D0C6RVyEAK3S2mkN jnJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6UazZUIs5V4Arc5XB/w4q5VVuheXtF4XbVZquGKMPns=; b=A3hE5MhJc/gp+p4T0RdC2xsTz5sVvJzZG8873+RjM9z3/0zshKadKsujXVx1gqQCv1 mZ+bxdaWYO8aJr3GAfPp0rQkjMczIbkWToE/tCQhFviTxEl8dKruGqwHjoh3ogANdK3p dRfykCUoogpxlz8x/wurim3RFMYlxrvw5V9b2GXyL60bHiGOz3T12+tRGASZzS+npBVc 9D9EmKpD0R2IhyQ1XoWlzbOdcE22sB+/uW47/DgothnbZBFcXtxQMjrZHQgZxQAp2r/F PjBsGJsVbFUyihLsdxsunHt99MXDhsdVdxDaMhTeFdukkvzJmLZaM0gFUdkVV6TevNFQ R/Jg== X-Gm-Message-State: APjAAAU1LynUnjnDLRAYVbXcObihg/+d4IVEHQjYiI2sD9bBsqqcIKKV qCms6dtoC8zncLx6I9NsibKlqhZr X-Google-Smtp-Source: APXvYqx8hls9fv1frxQJ/HhOUT9/4UtBR5eRSIOXE01sNliu/DxHkd2yG4K1cKzTcnijARJFBeXj/A== X-Received: by 2002:a37:7d82:: with SMTP id y124mr166498qkc.264.1570568531447; Tue, 08 Oct 2019 14:02:11 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 8 Oct 2019 18:02:00 -0300 Message-Id: <20191008210200.29318-2-danielhb413@gmail.com> In-Reply-To: <20191008210200.29318-1-danielhb413@gmail.com> References: <20191008210200.29318-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 08 Oct 2019 21:02:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 08 Oct 2019 21:02:12 +0000 (UTC) for IP:'209.85.222.193' DOMAIN:'mail-qk1-f193.google.com' HELO:'mail-qk1-f193.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.15 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.222.193 mail-qk1-f193.google.com 209.85.222.193 mail-qk1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 1/1] src/driver.c: remove duplicated code in virGetConnect* functions 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Tue, 08 Oct 2019 21:02:18 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" All the 6 virGetConnect* functions in driver.c shares the same code base. This patch creates a new static function virGetConnectGeneric() that contains the common code to be used with all other virGetConnect*. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- src/driver.c | 99 +++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 75 deletions(-) diff --git a/src/driver.c b/src/driver.c index 305c4c624b..4b526a73ae 100644 --- a/src/driver.c +++ b/src/driver.c @@ -135,112 +135,61 @@ virConnectCacheOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(virConnectCache); =20 -virConnectPtr virGetConnectInterface(void) +static virConnectPtr +virGetConnectGeneric(virThreadLocalPtr threadPtr, const char *name) { virConnectPtr conn; =20 if (virConnectCacheInitialize() < 0) return NULL; =20 - conn =3D virThreadLocalGet(&connectInterface); + conn =3D virThreadLocalGet(threadPtr); + if (conn) { - VIR_DEBUG("Return cached interface connection %p", conn); + VIR_DEBUG("Return cached %s connection %p", name, conn); virObjectRef(conn); } else { - conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "interface:///system"= : "interface:///session"); - VIR_DEBUG("Opened new interface connection %p", conn); + VIR_AUTOFREE(char *) uri =3D NULL; + const char *uriPath =3D geteuid() =3D=3D 0 ? "/system" : "/session= "; + + if (virAsprintf(&uri, "%s://%s", name, uriPath) < 0) + return NULL; + + conn =3D virConnectOpen(uri); + VIR_DEBUG("Opened new %s connection %p", name, conn); } return conn; } =20 -virConnectPtr virGetConnectNetwork(void) -{ - virConnectPtr conn; =20 - if (virConnectCacheInitialize() < 0) - return NULL; +virConnectPtr virGetConnectInterface(void) +{ + return virGetConnectGeneric(&connectInterface, "interface"); +} =20 - conn =3D virThreadLocalGet(&connectNetwork); - if (conn) { - VIR_DEBUG("Return cached network connection %p", conn); - virObjectRef(conn); - } else { - conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "network:///system" := "network:///session"); - VIR_DEBUG("Opened new network connection %p", conn); - } - return conn; +virConnectPtr virGetConnectNetwork(void) +{ + return virGetConnectGeneric(&connectNetwork, "network"); } =20 virConnectPtr virGetConnectNWFilter(void) { - virConnectPtr conn; - - if (virConnectCacheInitialize() < 0) - return NULL; - - conn =3D virThreadLocalGet(&connectNWFilter); - if (conn) { - VIR_DEBUG("Return cached nwfilter connection %p", conn); - virObjectRef(conn); - } else { - conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "nwfilter:///system" = : "nwfilter:///session"); - VIR_DEBUG("Opened new nwfilter connection %p", conn); - } - return conn; + return virGetConnectGeneric(&connectNWFilter, "nwfilter"); } =20 virConnectPtr virGetConnectNodeDev(void) { - virConnectPtr conn; - - if (virConnectCacheInitialize() < 0) - return NULL; - - conn =3D virThreadLocalGet(&connectNodeDev); - if (conn) { - VIR_DEBUG("Return cached nodedev connection %p", conn); - virObjectRef(conn); - } else { - conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "nodedev:///system" := "nodedev:///session"); - VIR_DEBUG("Opened new nodedev connection %p", conn); - } - return conn; + return virGetConnectGeneric(&connectNodeDev, "nodedev"); } =20 virConnectPtr virGetConnectSecret(void) { - virConnectPtr conn; - - if (virConnectCacheInitialize() < 0) - return NULL; - - conn =3D virThreadLocalGet(&connectSecret); - if (conn) { - VIR_DEBUG("Return cached secret connection %p", conn); - virObjectRef(conn); - } else { - conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "secret:///system" : = "secret:///session"); - VIR_DEBUG("Opened new secret connection %p", conn); - } - return conn; + return virGetConnectGeneric(&connectSecret, "secret"); } =20 virConnectPtr virGetConnectStorage(void) { - virConnectPtr conn; - - if (virConnectCacheInitialize() < 0) - return NULL; - - conn =3D virThreadLocalGet(&connectStorage); - if (conn) { - VIR_DEBUG("Return cached storage connection %p", conn); - virObjectRef(conn); - } else { - conn =3D virConnectOpen(geteuid() =3D=3D 0 ? "storage:///system" := "storage:///session"); - VIR_DEBUG("Opened new storage connection %p", conn); - } - return conn; + return virGetConnectGeneric(&connectStorage, "storage"); } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list