From nobody Sun Apr 28 10:56:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1487851035158336.8370061808139; Thu, 23 Feb 2017 03:57:15 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBs5MP040822; Thu, 23 Feb 2017 06:54:05 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrCB0031824 for ; Thu, 23 Feb 2017 06:53:12 -0500 Received: from dnr.brq.redhat.com (dhcp129-180.brq.redhat.com [10.34.129.180]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBrBWX009079 for ; Thu, 23 Feb 2017 06:53:12 -0500 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 12:53:06 +0100 Message-Id: <089f28d134187af4883000f9bf803dd0dc92aa24.1487850710.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] Unify checking for machine1 systemd service 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Both virSystemdTerminateMachine and virSystemdCreateMachine propagate the error to tell between a non-systemd system and a hard error. In virSystemdGetMachineNameByPID both are treated the same, but an error is ignored by the callers. Split out the checks into a separate function. --- src/util/virsystemd.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 7ec3eee..d7a4e78 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -182,6 +182,20 @@ virSystemdMakeMachineName(const char *drivername, return machinename; } =20 +/* -2 =3D machine1 is not supported on this machine + * -1 =3D error + * 0 =3D machine1 is available + */ +static int +virSystemdHasCreateMachine(void) +{ + int ret; + if ((ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0) + return ret; + + return virDBusIsServiceRegistered("org.freedesktop.systemd1"); +} + =20 char * virSystemdGetMachineNameByPID(pid_t pid) @@ -190,10 +204,7 @@ virSystemdGetMachineNameByPID(pid_t pid) DBusMessage *reply =3D NULL; char *name =3D NULL, *object =3D NULL; =20 - if (virDBusIsServiceEnabled("org.freedesktop.machine1") < 0) - goto cleanup; - - if (virDBusIsServiceRegistered("org.freedesktop.systemd1") < 0) + if (virSystemdHasCreateMachine() < 0) goto cleanup; =20 if (!(conn =3D virDBusGetSystemBus())) @@ -268,11 +279,7 @@ int virSystemdCreateMachine(const char *name, char *slicename =3D NULL; static int hasCreateWithNetwork =3D 1; =20 - ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1"); - if (ret < 0) - return ret; - - if ((ret =3D virDBusIsServiceRegistered("org.freedesktop.systemd1")) <= 0) + if ((ret =3D virSystemdHasCreateMachine()) < 0) return ret; =20 if (!(conn =3D virDBusGetSystemBus())) @@ -434,11 +441,7 @@ int virSystemdTerminateMachine(const char *name) =20 memset(&error, 0, sizeof(error)); =20 - ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1"); - if (ret < 0) - goto cleanup; - - if ((ret =3D virDBusIsServiceRegistered("org.freedesktop.systemd1")) <= 0) + if ((ret =3D virSystemdHasCreateMachine()) < 0) goto cleanup; =20 ret =3D -1; --=20 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 10:56:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1487850992911990.3608854279356; Thu, 23 Feb 2017 03:56:32 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrFrc013363; Thu, 23 Feb 2017 06:53:15 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrDFw031829 for ; Thu, 23 Feb 2017 06:53:13 -0500 Received: from dnr.brq.redhat.com (dhcp129-180.brq.redhat.com [10.34.129.180]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBrBWY009079 for ; Thu, 23 Feb 2017 06:53:13 -0500 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 12:53:07 +0100 Message-Id: <922618d74c28696cc7eb0fa1647a63a1c3ab3c37.1487850710.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] Use macros for testing virSystemd APIs 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This hides the unused third parameter from every line and prepares for resetting the environment after each test case in the future. --- tests/virsystemdtest.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index f0cfabf..177cccc 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -518,25 +518,21 @@ mymain(void) if (virUUIDParse("c7a5fdbd-edaf-9455-926a-d65c16db1809", uuid) < 0) return EXIT_FAILURE; =20 - if (virTestRun("Test create container ", testCreateContainer, NULL) < = 0) - ret =3D -1; - if (virTestRun("Test terminate container ", testTerminateContainer, NU= LL) < 0) - ret =3D -1; - if (virTestRun("Test create machine ", testCreateMachine, NULL) < 0) - ret =3D -1; - if (virTestRun("Test terminate machine ", testTerminateMachine, NULL) = < 0) - ret =3D -1; - if (virTestRun("Test create no systemd ", testCreateNoSystemd, NULL) <= 0) - ret =3D -1; - if (virTestRun("Test create systemd not running ", - testCreateSystemdNotRunning, NULL) < 0) - ret =3D -1; - if (virTestRun("Test create bad systemd ", testCreateBadSystemd, NULL)= < 0) - ret =3D -1; - if (virTestRun("Test create with network ", testCreateNetwork, NULL) <= 0) - ret =3D -1; - if (virTestRun("Test getting machine name ", testGetMachineName, NULL)= < 0) - ret =3D -1; +# define DO_TEST(_name, func) \ + do { \ + if (virTestRun(_name, func, NULL) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST("Test create container ", testCreateContainer); + DO_TEST("Test terminate container ", testTerminateContainer); + DO_TEST("Test create machine ", testCreateMachine); + DO_TEST("Test terminate machine ", testTerminateMachine); + DO_TEST("Test create no systemd ", testCreateNoSystemd); + DO_TEST("Test create systemd not running ", testCreateSystemdNotRunnin= g); + DO_TEST("Test create bad systemd ", testCreateBadSystemd); + DO_TEST("Test create with network ", testCreateNetwork); + DO_TEST("Test getting machine name ", testGetMachineName); =20 # define TEST_SCOPE(_name, unitname, _legacy) \ do { \ --=20 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 10:56:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1487850994246399.9808843812582; Thu, 23 Feb 2017 03:56:34 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrFbs013366; Thu, 23 Feb 2017 06:53:15 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrEIM031836 for ; Thu, 23 Feb 2017 06:53:14 -0500 Received: from dnr.brq.redhat.com (dhcp129-180.brq.redhat.com [10.34.129.180]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBrBWZ009079 for ; Thu, 23 Feb 2017 06:53:13 -0500 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 12:53:08 +0100 Message-Id: <515a52de65e5cdbd8139b1e6f690b5d2e37472a2.1487850710.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] Cache the presence of machine1 service 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" After the system has been booted, it should not change. Cache the return value of virSystemdHasCreateMachine. Allow starting and terminating machines with just one DBus call, instead of three, reducing the chance of the call timing out. Also introduce a small function for resetting the cache to be used in tests. --- src/libvirt_private.syms | 1 + src/util/virsystemd.c | 28 ++++++++++++++++++++++++++-- src/util/virsystemdpriv.h | 33 +++++++++++++++++++++++++++++++++ tests/virsystemdtest.c | 4 ++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/util/virsystemdpriv.h diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 07a3533..738c3c8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2557,6 +2557,7 @@ virSystemdCanHibernate; virSystemdCanHybridSleep; virSystemdCanSuspend; virSystemdCreateMachine; +virSystemdCreateMachineResetCachedValue; virSystemdGetMachineNameByPID; virSystemdMakeMachineName; virSystemdMakeScopeName; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index d7a4e78..5982bc4 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -26,6 +26,9 @@ # include #endif =20 +#define __VIR_SYSTEMD_PRIV_H_ALLOW__ 1 +#include "virsystemdpriv.h" + #include "virsystemd.h" #include "viratomic.h" #include "virbuffer.h" @@ -182,6 +185,15 @@ virSystemdMakeMachineName(const char *drivername, return machinename; } =20 +static int virSystemdCreateMachineCachedValue =3D -1; + +/* Reset the cache from tests for testing the underlying dbus calls + * as well */ +void virSystemdCreateMachineResetCachedValue(void) +{ + virSystemdCreateMachineCachedValue =3D -1; +} + /* -2 =3D machine1 is not supported on this machine * -1 =3D error * 0 =3D machine1 is available @@ -190,10 +202,22 @@ static int virSystemdHasCreateMachine(void) { int ret; - if ((ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0) + int val; + + val =3D virAtomicIntGet(&virSystemdCreateMachineCachedValue); + if (val !=3D -1) + return val; + + if ((ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0)= { + if (ret =3D=3D -2) + virAtomicIntSet(&virSystemdCreateMachineCachedValue, -2); return ret; + } =20 - return virDBusIsServiceRegistered("org.freedesktop.systemd1"); + if ((ret =3D virDBusIsServiceRegistered("org.freedesktop.systemd1")) = =3D=3D -1) + return ret; + virAtomicIntSet(&virSystemdCreateMachineCachedValue, ret); + return ret; } =20 =20 diff --git a/src/util/virsystemdpriv.h b/src/util/virsystemdpriv.h new file mode 100644 index 0000000..413bc8b --- /dev/null +++ b/src/util/virsystemdpriv.h @@ -0,0 +1,33 @@ +/* + * virsystemdpriv.h: Functions for testing virSystemd APIs + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#ifndef __VIR_SYSTEMD_PRIV_H_ALLOW__ +# error "virsystemdpriv.h may only be included by virsystemd.c or test sui= tes" +#endif + +#ifndef __VIR_SYSTEMD_PRIV_H__ +# define __VIR_SYSTEMD_PRIV_H__ + +# include "virsystemd.h" + +void virSystemdCreateMachineResetCachedValue(void); + +#endif /* __VIR_SYSTEMD_PRIV_H__ */ diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 177cccc..eca6e84 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -27,6 +27,9 @@ # include # include =20 +# define __VIR_SYSTEMD_PRIV_H_ALLOW__ 1 +# include "virsystemdpriv.h" + # include "virsystemd.h" # include "virdbus.h" # include "virlog.h" @@ -522,6 +525,7 @@ mymain(void) do { \ if (virTestRun(_name, func, NULL) < 0) \ ret =3D -1; \ + virSystemdCreateMachineResetCachedValue(); \ } while (0) =20 DO_TEST("Test create container ", testCreateContainer); --=20 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 10:56:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 148785103284968.74350238246302; Thu, 23 Feb 2017 03:57:12 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBs58F040823; Thu, 23 Feb 2017 06:54:05 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrF0r031841 for ; Thu, 23 Feb 2017 06:53:15 -0500 Received: from dnr.brq.redhat.com (dhcp129-180.brq.redhat.com [10.34.129.180]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBrBWa009079 for ; Thu, 23 Feb 2017 06:53:14 -0500 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 12:53:09 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] Test virSystemd APIs twice to check the cache effects 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Test virSystemd APIs twice to check the cache effects. --- tests/virsystemdtest.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index eca6e84..6ba532d 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -525,6 +525,8 @@ mymain(void) do { \ if (virTestRun(_name, func, NULL) < 0) \ ret =3D -1; \ + if (virTestRun(_name "again ", func, NULL) < 0) \ + ret =3D -1; \ virSystemdCreateMachineResetCachedValue(); \ } while (0) =20 --=20 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list