From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154220048997097.34886844599998; Wed, 14 Nov 2018 05:01:29 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A09189AFC; Wed, 14 Nov 2018 13:01:27 +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 804881001F41; Wed, 14 Nov 2018 13:01:26 +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 E26854CAA8; Wed, 14 Nov 2018 13:01:25 +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 wAECio4F026151 for ; Wed, 14 Nov 2018 07:44:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id EBDD85C31F; Wed, 14 Nov 2018 12:44:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 731BB53B33 for ; Wed, 14 Nov 2018 12:44:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:29 +0100 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 01/15] virprocess: Introduce virProcessRunInFork 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 14 Nov 2018 13:01:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This new helper can be used to spawn a child process and run passed callback from it. This will come handy esp. if the callback is not thread safe. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virprocess.c | 86 ++++++++++++++++++++++++++++++++++++++++ src/util/virprocess.h | 16 ++++++++ 3 files changed, 103 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2343a757c1..7906d90f24 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2626,6 +2626,7 @@ virProcessKill; virProcessKillPainfully; virProcessKillPainfullyDelay; virProcessNamespaceAvailable; +virProcessRunInFork; virProcessRunInMountNamespace; virProcessSchedPolicyTypeFromString; virProcessSchedPolicyTypeToString; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 3883c708fc..17e7cfa4ee 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1165,6 +1165,92 @@ virProcessRunInMountNamespace(pid_t pid, } =20 =20 +static int +virProcessRunInForkHelper(int errfd, + pid_t ppid, + virProcessForkCallback cb, + void *opaque) +{ + if (cb(ppid, opaque) < 0) { + virErrorPtr err =3D virGetLastError(); + if (err) { + size_t len =3D strlen(err->message) + 1; + ignore_value(safewrite(errfd, err->message, len)); + } + + return -1; + } + + return 0; +} + + +/** + * virProcessRunInFork: + * @cb: callback to run + * @opaque: opaque data to @cb + * + * Do the fork and run @cb in the child. This can be used when + * @cb does something thread unsafe, for instance. All signals + * will be reset to have their platform default handlers and + * unmasked. @cb must only use async signal safe functions. In + * particular no mutexes should be used in @cb, unless steps were + * taken before forking to guarantee a predictable state. @cb + * must not exec any external binaries, instead + * virCommand/virExec should be used for that purpose. + * + * On return, the returned value is either -1 with error message + * reported if something went bad in the parent, if child has + * died from a signal or if the child returned EXIT_CANCELED. + * Otherwise the returned value is the exit status of the child. + */ +int +virProcessRunInFork(virProcessForkCallback cb, + void *opaque) +{ + int ret =3D -1; + pid_t child =3D -1; + pid_t parent =3D getpid(); + int errfd[2] =3D { -1, -1 }; + + if (pipe2(errfd, O_CLOEXEC) < 0) { + virReportSystemError(errno, "%s", + _("Cannot create pipe for child")); + return -1; + } + + if ((child =3D virFork()) < 0) + goto cleanup; + + if (child =3D=3D 0) { + VIR_FORCE_CLOSE(errfd[0]); + ret =3D virProcessRunInForkHelper(errfd[1], parent, cb, opaque); + VIR_FORCE_CLOSE(errfd[1]); + _exit(ret < 0 ? EXIT_CANCELED : ret); + } else { + int status; + VIR_AUTOFREE(char *) buf =3D NULL; + + VIR_FORCE_CLOSE(errfd[1]); + ignore_value(virFileReadHeaderFD(errfd[0], 1024, &buf)); + ret =3D virProcessWait(child, &status, false); + if (ret =3D=3D 0) { + ret =3D status =3D=3D EXIT_CANCELED ? -1 : status; + if (ret) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("child reported (status=3D%d): %s"), + status, NULLSTR(buf)); + } + } + } + + cleanup: + VIR_FORCE_CLOSE(errfd[0]); + VIR_FORCE_CLOSE(errfd[1]); + return ret; +} + + #if defined(HAVE_SYS_MOUNT_H) && defined(HAVE_UNSHARE) int virProcessSetupPrivateMountNS(void) diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 5faa0892fe..b1166902f0 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -93,6 +93,22 @@ int virProcessRunInMountNamespace(pid_t pid, virProcessNamespaceCallback cb, void *opaque); =20 +/** + * virProcessForkCallback: + * @ppid: parent's pid + * @opaque: opaque data + * + * Callback to run in fork()-ed process. + * + * Returns: 0 on success, + * -1 on error (treated as EXIT_CANCELED) + */ +typedef int (*virProcessForkCallback)(pid_t ppid, + void *opaque); + +int virProcessRunInFork(virProcessForkCallback cb, + void *opaque); + int virProcessSetupPrivateMountNS(void); =20 int virProcessSetScheduler(pid_t pid, --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200504553556.4986801157659; Wed, 14 Nov 2018 05:01:44 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DC8F7AEA6; Wed, 14 Nov 2018 13:01:42 +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 F387E5DD7F; Wed, 14 Nov 2018 13:01:41 +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 877254CAA8; Wed, 14 Nov 2018 13:01:41 +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 wAECipq0026156 for ; Wed, 14 Nov 2018 07:44:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id C0C5A53B33; Wed, 14 Nov 2018 12:44:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 469836B466 for ; Wed, 14 Nov 2018 12:44:51 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:30 +0100 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 02/15] virprocess: Make virProcessRunInMountNamespace use virProcessRunInFork 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 14 Nov 2018 13:01:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Both virProcessRunInMountNamespace() and virProcessRunInFork() look very similar. De-duplicate the code and make virProcessRunInMountNamespace() call virProcessRunInFork(). Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/util/virprocess.c | 64 +++++++++---------------------------------- 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 17e7cfa4ee..87f32464db 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1073,16 +1073,22 @@ int virProcessGetStartTime(pid_t pid, #endif =20 =20 -static int virProcessNamespaceHelper(int errfd, - pid_t pid, - virProcessNamespaceCallback cb, +typedef struct _virProcessNamespaceHelperData virProcessNamespaceHelperDat= a; +struct _virProcessNamespaceHelperData { + pid_t pid; + virProcessNamespaceCallback cb; + void *opaque; +}; + +static int virProcessNamespaceHelper(pid_t pid ATTRIBUTE_UNUSED, void *opaque) { + virProcessNamespaceHelperData *data =3D opaque; int fd =3D -1; int ret =3D -1; VIR_AUTOFREE(char *) path =3D NULL; =20 - if (virAsprintf(&path, "/proc/%lld/ns/mnt", (long long) pid) < 0) + if (virAsprintf(&path, "/proc/%lld/ns/mnt", (long long) data->pid) < 0) goto cleanup; =20 if ((fd =3D open(path, O_RDONLY)) < 0) { @@ -1097,16 +1103,9 @@ static int virProcessNamespaceHelper(int errfd, goto cleanup; } =20 - ret =3D cb(pid, opaque); + ret =3D data->cb(data->pid, data->opaque); =20 cleanup: - if (ret < 0) { - virErrorPtr err =3D virGetLastError(); - if (err) { - size_t len =3D strlen(err->message) + 1; - ignore_value(safewrite(errfd, err->message, len)); - } - } VIR_FORCE_CLOSE(fd); return ret; } @@ -1122,46 +1121,9 @@ virProcessRunInMountNamespace(pid_t pid, virProcessNamespaceCallback cb, void *opaque) { - int ret =3D -1; - pid_t child =3D -1; - int errfd[2] =3D { -1, -1 }; + virProcessNamespaceHelperData data =3D {.pid =3D pid, .cb =3D cb, .opa= que =3D opaque}; =20 - if (pipe2(errfd, O_CLOEXEC) < 0) { - virReportSystemError(errno, "%s", - _("Cannot create pipe for child")); - return -1; - } - - if ((child =3D virFork()) < 0) - goto cleanup; - - if (child =3D=3D 0) { - VIR_FORCE_CLOSE(errfd[0]); - ret =3D virProcessNamespaceHelper(errfd[1], pid, - cb, opaque); - VIR_FORCE_CLOSE(errfd[1]); - _exit(ret < 0 ? EXIT_CANCELED : ret); - } else { - int status; - VIR_AUTOFREE(char *) buf =3D NULL; - - VIR_FORCE_CLOSE(errfd[1]); - ignore_value(virFileReadHeaderFD(errfd[0], 1024, &buf)); - ret =3D virProcessWait(child, &status, false); - if (!ret) { - ret =3D status =3D=3D EXIT_CANCELED ? -1 : status; - if (ret) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("child reported: %s"), - NULLSTR(buf)); - } - } - } - - cleanup: - VIR_FORCE_CLOSE(errfd[0]); - VIR_FORCE_CLOSE(errfd[1]); - return ret; + return virProcessRunInFork(virProcessNamespaceHelper, &data); } =20 =20 --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200519180539.3430604258059; Wed, 14 Nov 2018 05:01:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87CBB30CF69B; Wed, 14 Nov 2018 13:01:54 +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 26F785E1BF; Wed, 14 Nov 2018 13:01:54 +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 C65974CAAE; Wed, 14 Nov 2018 13:01:53 +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 wAECiqQ4026169 for ; Wed, 14 Nov 2018 07:44:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9546153B33; Wed, 14 Nov 2018 12:44:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A6086B47C for ; Wed, 14 Nov 2018 12:44:51 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:31 +0100 Message-Id: <78982b6eacd1c912f175315a92e0e8fabe7aac44.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 03/15] qemu_tpm: Pass virDomainObjPtr instead of virDomainDefPtr 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 14 Nov 2018 13:01:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The TPM code currently accepts pointer to a domain definition. This is okay for now, but in near future the security driver APIs it calls will require domain object. Therefore, change the TPM code to accept the domain object pointer. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_extdevice.c | 16 ++++++++-------- src/qemu/qemu_extdevice.h | 4 ++-- src/qemu/qemu_process.c | 6 +++--- src/qemu/qemu_security.c | 14 +++++++------- src/qemu/qemu_security.h | 4 ++-- src/qemu/qemu_tpm.c | 24 ++++++++++++------------ src/qemu/qemu_tpm.h | 4 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index d982922470..27cf118c14 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -129,16 +129,16 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, =20 int qemuExtDevicesStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) { int ret =3D 0; =20 - if (qemuExtDevicesInitPaths(driver, def) < 0) + if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return -1; =20 - if (def->tpm) - ret =3D qemuExtTPMStart(driver, def, logCtxt); + if (vm->def->tpm) + ret =3D qemuExtTPMStart(driver, vm, logCtxt); =20 return ret; } @@ -146,13 +146,13 @@ qemuExtDevicesStart(virQEMUDriverPtr driver, =20 void qemuExtDevicesStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) { - if (qemuExtDevicesInitPaths(driver, def) < 0) + if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return; =20 - if (def->tpm) - qemuExtTPMStop(driver, def); + if (vm->def->tpm) + qemuExtTPMStop(driver, vm); } =20 =20 diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h index c557778ddb..c26cdd50b2 100644 --- a/src/qemu/qemu_extdevice.h +++ b/src/qemu/qemu_extdevice.h @@ -41,13 +41,13 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 int qemuExtDevicesStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; =20 void qemuExtDevicesStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 bool qemuExtDevicesHasDevice(virDomainDefPtr def); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1850923914..2c9e605047 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6392,7 +6392,7 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessGenID(vm, flags) < 0) goto cleanup; =20 - if (qemuExtDevicesStart(driver, vm->def, logCtxt) < 0) + if (qemuExtDevicesStart(driver, vm, logCtxt) < 0) goto cleanup; =20 VIR_DEBUG("Building emulator command line"); @@ -6648,7 +6648,7 @@ qemuProcessLaunch(virConnectPtr conn, =20 cleanup: if (ret < 0) - qemuExtDevicesStop(driver, vm->def); + qemuExtDevicesStop(driver, vm); qemuDomainSecretDestroy(vm); virCommandFree(cmd); virObjectUnref(logCtxt); @@ -7079,7 +7079,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, =20 qemuDomainCleanupRun(driver, vm); =20 - qemuExtDevicesStop(driver, vm->def); + qemuExtDevicesStop(driver, vm); =20 /* Stop autodestroy in case guest is restarted */ qemuProcessAutoDestroyRemove(driver, vm); diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index 34921b4046..bf45abf93a 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -453,7 +453,7 @@ qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, * qemuSecurityStartTPMEmulator: * * @driver: the QEMU driver - * @def: the domain definition + * @vm: the domain object * @cmd: the command to run * @uid: the uid to run the emulator * @gid: the gid to run the emulator @@ -469,7 +469,7 @@ qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, */ int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, virCommandPtr cmd, uid_t uid, gid_t gid, @@ -484,7 +484,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, transactionStarted =3D true; =20 if (virSecurityManagerSetTPMLabels(driver->securityManager, - def) < 0) { + vm->def) < 0) { virSecurityManagerTransactionAbort(driver->securityManager); return -1; } @@ -494,7 +494,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, transactionStarted =3D false; =20 if (virSecurityManagerSetChildProcessLabel(driver->securityManager, - def, cmd) < 0) + vm->def, cmd) < 0) goto cleanup; =20 if (virSecurityManagerPreFork(driver->securityManager) < 0) @@ -519,7 +519,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, virSecurityManagerTransactionStart(driver->securityManager) >=3D 0) transactionStarted =3D true; =20 - virSecurityManagerRestoreTPMLabels(driver->securityManager, def); + virSecurityManagerRestoreTPMLabels(driver->securityManager, vm->def); =20 if (transactionStarted && virSecurityManagerTransactionCommit(driver->securityManager, -1) <= 0) @@ -532,14 +532,14 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, =20 void qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) { bool transactionStarted =3D false; =20 if (virSecurityManagerTransactionStart(driver->securityManager) >=3D 0) transactionStarted =3D true; =20 - virSecurityManagerRestoreTPMLabels(driver->securityManager, def); + virSecurityManagerRestoreTPMLabels(driver->securityManager, vm->def); =20 if (transactionStarted && virSecurityManagerTransactionCommit(driver->securityManager, -1) <= 0) diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index 13fc05152c..45d26a0dbf 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -84,7 +84,7 @@ int qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driv= er, virDomainChrDefPtr chr); =20 int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, virCommandPtr cmd, uid_t uid, gid_t gid, @@ -92,7 +92,7 @@ int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, int *cmdret); =20 void qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def); + virDomainObjPtr vm); =20 int qemuSecurityDomainSetPathLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index c64114feac..af85f7b25f 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -756,7 +756,7 @@ qemuExtTPMCleanupHost(virDomainDefPtr def) */ static int qemuExtTPMStartEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) { int ret =3D -1; @@ -764,8 +764,8 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, int exitstatus =3D 0; char *errbuf =3D NULL; virQEMUDriverConfigPtr cfg; - virDomainTPMDefPtr tpm =3D def->tpm; - char *shortName =3D virDomainDefGetShortName(def); + virDomainTPMDefPtr tpm =3D vm->def->tpm; + char *shortName =3D virDomainDefGetShortName(vm->def); int cmdret =3D 0, timeout, rc; pid_t pid; =20 @@ -777,7 +777,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, /* stop any left-over TPM emulator for this VM */ qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName); =20 - if (!(cmd =3D qemuTPMEmulatorBuildCommand(tpm, def->name, def->uuid, + if (!(cmd =3D qemuTPMEmulatorBuildCommand(tpm, vm->def->name, vm->def-= >uuid, driver->privileged, cfg->swtpm_user, cfg->swtpm_group, @@ -789,7 +789,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, =20 virCommandSetErrorBuffer(cmd, &errbuf); =20 - if (qemuSecurityStartTPMEmulator(driver, def, cmd, + if (qemuSecurityStartTPMEmulator(driver, vm, cmd, cfg->swtpm_user, cfg->swtpm_group, &exitstatus, &cmdret) < 0) goto cleanup; @@ -837,15 +837,15 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, =20 int qemuExtTPMStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) { int ret =3D 0; - virDomainTPMDefPtr tpm =3D def->tpm; + virDomainTPMDefPtr tpm =3D vm->def->tpm; =20 switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: - ret =3D qemuExtTPMStartEmulator(driver, def, logCtxt); + ret =3D qemuExtTPMStartEmulator(driver, vm, logCtxt); break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_LAST: @@ -858,19 +858,19 @@ qemuExtTPMStart(virQEMUDriverPtr driver, =20 void qemuExtTPMStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); char *shortName =3D NULL; =20 - switch (def->tpm->type) { + switch (vm->def->tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: - shortName =3D virDomainDefGetShortName(def); + shortName =3D virDomainDefGetShortName(vm->def); if (!shortName) goto cleanup; =20 qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName); - qemuSecurityCleanupTPMEmulator(driver, def); + qemuSecurityCleanupTPMEmulator(driver, vm); break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_LAST: diff --git a/src/qemu/qemu_tpm.h b/src/qemu/qemu_tpm.h index 6eb1294da0..c7eeaafeb9 100644 --- a/src/qemu/qemu_tpm.h +++ b/src/qemu/qemu_tpm.h @@ -38,13 +38,13 @@ void qemuExtTPMCleanupHost(virDomainDefPtr def) ATTRIBUTE_NONNULL(1); =20 int qemuExtTPMStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; =20 void qemuExtTPMStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 int qemuExtTPMSetupCgroup(virQEMUDriverPtr driver, --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200044704603.8495850601051; Wed, 14 Nov 2018 04:54:04 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 631BD19CBE9; Wed, 14 Nov 2018 12:54:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99E345FCA0; Wed, 14 Nov 2018 12:53:59 +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 53168181A86C; Wed, 14 Nov 2018 12:53:58 +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 wAECirdt026176 for ; Wed, 14 Nov 2018 07:44:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6710D53B33; Wed, 14 Nov 2018 12:44:53 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1593610FC for ; Wed, 14 Nov 2018 12:44:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:32 +0100 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 04/15] qemu_domain: Track if domain remembers original owner 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 14 Nov 2018 12:54:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" For metadata locking we might need an extra fork() which given latest attempts to do fewer fork()-s is suboptimal. Therefore, there will be a qemu.conf knob to enable or this feature. But since the feature is actually not metadata locking itself rather than remembering of the original owner of the file this is named as 'rememberOwner'. But patches for that feature are not even posted yet so there is actually no qemu.conf entry in this patch nor a way to enable this feature. Even though this is effectively a dead code for now it is still desired. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_conf.h | 1 + src/qemu/qemu_domain.c | 7 +++++++ src/qemu/qemu_domain.h | 3 +++ src/qemu/qemu_process.c | 3 +++ 4 files changed, 14 insertions(+) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index f876f9117c..0b5b5a314f 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -92,6 +92,7 @@ struct _virQEMUDriverConfig { bool dynamicOwnership; =20 virBitmapPtr namespaces; + bool rememberOwner; =20 int cgroupControllers; char **cgroupDeviceACL; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 37926850b2..558c97ad36 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1963,6 +1963,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) virBitmapFree(priv->namespaces); priv->namespaces =3D NULL; =20 + priv->rememberOwner =3D false; + priv->reconnectBlockjobs =3D VIR_TRISTATE_BOOL_ABSENT; priv->allowReboot =3D VIR_TRISTATE_BOOL_ABSENT; =20 @@ -2480,6 +2482,9 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, if (priv->chardevStdioLogd) virBufferAddLit(buf, "\n"); =20 + if (priv->rememberOwner) + virBufferAddLit(buf, "\n"); + qemuDomainObjPrivateXMLFormatAllowReboot(buf, priv->allowReboot); =20 qemuDomainObjPrivateXMLFormatPR(buf, priv); @@ -2891,6 +2896,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, priv->namespaces =3D NULL; } =20 + priv->rememberOwner =3D virXPathBoolean("count(./rememberOwner) > 0", = ctxt); + if ((n =3D virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0) goto error; =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 87de433b22..53b5ea1678 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -369,6 +369,9 @@ struct _qemuDomainObjPrivate { /* qemuProcessStartCPUs stores the reason for starting vCPUs here for = the * RESUME event handler to use it */ virDomainRunningReason runningReason; + + /* true if libvirt remembers the original owner for files */ + bool rememberOwner; }; =20 # define QEMU_DOMAIN_PRIVATE(vm) \ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2c9e605047..44bf55bfb2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5916,6 +5916,9 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, priv->chardevStdioLogd =3D true; } =20 + /* Track if this domain remembers original owner */ + priv->rememberOwner =3D cfg->rememberOwner; + qemuProcessPrepareAllowReboot(vm); =20 /* clear the 'blockdev' capability for VMs which have disks that need --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542201419721841.2763956706226; Wed, 14 Nov 2018 05:16:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A14A3001957; Wed, 14 Nov 2018 13:16:57 +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 49D1760BF7; Wed, 14 Nov 2018 13:16:56 +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 B4C4D4BB79; Wed, 14 Nov 2018 13:16:54 +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 wAECisUf026181 for ; Wed, 14 Nov 2018 07:44:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 60FFC5C31F; Wed, 14 Nov 2018 12:44:54 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id B483A53B33 for ; Wed, 14 Nov 2018 12:44:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:33 +0100 Message-Id: <2d95a9ce06ee2510a4d8959311e937a4954b5e7b.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 05/15] virSecurityManagerTransactionCommit: Do metadata locking iff enabled in config 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 14 Nov 2018 13:16:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_security.c | 73 ++++++++++++++++++++++++--------- src/security/security_dac.c | 56 ++++++++++++++++--------- src/security/security_driver.h | 3 +- src/security/security_manager.c | 9 +++- src/security/security_manager.h | 3 +- src/security/security_selinux.c | 54 ++++++++++++++++-------- src/security/security_stack.c | 5 ++- 7 files changed, 140 insertions(+), 63 deletions(-) diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index bf45abf93a..372bc53396 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -53,7 +53,8 @@ qemuSecuritySetAllLabel(virQEMUDriverPtr driver, priv->chardevStdioLogd) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -86,7 +87,8 @@ qemuSecurityRestoreAllLabel(virQEMUDriverPtr driver, priv->chardevStdioLogd); =20 if (transactionStarted && - virSecurityManagerTransactionCommit(driver->securityManager, -1) <= 0) + virSecurityManagerTransactionCommit(driver->securityManager, + -1, priv->rememberOwner) < 0) VIR_WARN("Unable to run security manager transaction"); =20 virSecurityManagerTransactionAbort(driver->securityManager); @@ -98,6 +100,7 @@ qemuSecuritySetDiskLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDiskDefPtr disk) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -112,7 +115,8 @@ qemuSecuritySetDiskLabel(virQEMUDriverPtr driver, disk) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -127,6 +131,7 @@ qemuSecurityRestoreDiskLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDiskDefPtr disk) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -141,7 +146,8 @@ qemuSecurityRestoreDiskLabel(virQEMUDriverPtr driver, disk) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -156,6 +162,7 @@ qemuSecuritySetImageLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virStorageSourcePtr src) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -170,7 +177,8 @@ qemuSecuritySetImageLabel(virQEMUDriverPtr driver, src) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -185,6 +193,7 @@ qemuSecurityRestoreImageLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virStorageSourcePtr src) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -199,7 +208,8 @@ qemuSecurityRestoreImageLabel(virQEMUDriverPtr driver, src) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -214,6 +224,7 @@ qemuSecuritySetHostdevLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -229,7 +240,8 @@ qemuSecuritySetHostdevLabel(virQEMUDriverPtr driver, NULL) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -244,6 +256,7 @@ qemuSecurityRestoreHostdevLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -259,7 +272,8 @@ qemuSecurityRestoreHostdevLabel(virQEMUDriverPtr driver, NULL) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -274,6 +288,7 @@ qemuSecuritySetMemoryLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainMemoryDefPtr mem) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -288,7 +303,8 @@ qemuSecuritySetMemoryLabel(virQEMUDriverPtr driver, mem) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -303,6 +319,7 @@ qemuSecurityRestoreMemoryLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainMemoryDefPtr mem) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -317,7 +334,8 @@ qemuSecurityRestoreMemoryLabel(virQEMUDriverPtr driver, mem) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -347,7 +365,8 @@ qemuSecuritySetInputLabel(virDomainObjPtr vm, input) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -377,7 +396,8 @@ qemuSecurityRestoreInputLabel(virDomainObjPtr vm, input) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -408,7 +428,8 @@ qemuSecuritySetChardevLabel(virQEMUDriverPtr driver, priv->chardevStdioLogd) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -439,7 +460,8 @@ qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, priv->chardevStdioLogd) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -476,6 +498,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, int *exitstatus, int *cmdret) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; int ret =3D -1; bool transactionStarted =3D false; =20 @@ -489,7 +512,8 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, return -1; } =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, -1) <= 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + -1, priv->rememberOwner) < 0) goto cleanup; transactionStarted =3D false; =20 @@ -522,7 +546,8 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, virSecurityManagerRestoreTPMLabels(driver->securityManager, vm->def); =20 if (transactionStarted && - virSecurityManagerTransactionCommit(driver->securityManager, -1) <= 0) + virSecurityManagerTransactionCommit(driver->securityManager, + -1, priv->rememberOwner) < 0) VIR_WARN("Unable to run security manager transaction"); =20 virSecurityManagerTransactionAbort(driver->securityManager); @@ -534,6 +559,7 @@ void qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver, virDomainObjPtr vm) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; bool transactionStarted =3D false; =20 if (virSecurityManagerTransactionStart(driver->securityManager) >=3D 0) @@ -542,7 +568,8 @@ qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver, virSecurityManagerRestoreTPMLabels(driver->securityManager, vm->def); =20 if (transactionStarted && - virSecurityManagerTransactionCommit(driver->securityManager, -1) <= 0) + virSecurityManagerTransactionCommit(driver->securityManager, + -1, priv->rememberOwner) < 0) VIR_WARN("Unable to run security manager transaction"); =20 virSecurityManagerTransactionAbort(driver->securityManager); @@ -555,6 +582,7 @@ qemuSecurityDomainSetPathLabel(virQEMUDriverPtr driver, const char *path, bool allowSubtree) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -570,7 +598,8 @@ qemuSecurityDomainSetPathLabel(virQEMUDriverPtr driver, allowSubtree) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -585,6 +614,7 @@ qemuSecuritySetSavedStateLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, const char *savefile) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -599,7 +629,8 @@ qemuSecuritySetSavedStateLabel(virQEMUDriverPtr driver, savefile) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; @@ -614,6 +645,7 @@ qemuSecurityRestoreSavedStateLabel(virQEMUDriverPtr dri= ver, virDomainObjPtr vm, const char *savefile) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; pid_t pid =3D -1; int ret =3D -1; =20 @@ -628,7 +660,8 @@ qemuSecurityRestoreSavedStateLabel(virQEMUDriverPtr dri= ver, savefile) < 0) goto cleanup; =20 - if (virSecurityManagerTransactionCommit(driver->securityManager, pid) = < 0) + if (virSecurityManagerTransactionCommit(driver->securityManager, + pid, priv->rememberOwner) < 0) goto cleanup; =20 ret =3D 0; diff --git a/src/security/security_dac.c b/src/security/security_dac.c index da4a6c72fe..0e100f7895 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -86,6 +86,7 @@ struct _virSecurityDACChownList { virSecurityManagerPtr manager; virSecurityDACChownItemPtr *items; size_t nItems; + bool lock; }; =20 =20 @@ -210,22 +211,24 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUS= ED, int rv =3D 0; int ret =3D -1; =20 - if (VIR_ALLOC_N(paths, list->nItems) < 0) - return -1; + if (list->lock) { + if (VIR_ALLOC_N(paths, list->nItems) < 0) + return -1; =20 - for (i =3D 0; i < list->nItems; i++) { - const char *p =3D list->items[i]->path; + for (i =3D 0; i < list->nItems; i++) { + const char *p =3D list->items[i]->path; =20 - if (!p || - virFileIsDir(p)) - continue; + if (!p || + virFileIsDir(p)) + continue; =20 - VIR_APPEND_ELEMENT_COPY_INPLACE(paths, npaths, p); + VIR_APPEND_ELEMENT_COPY_INPLACE(paths, npaths, p); + } + + if (virSecurityManagerMetadataLock(list->manager, paths, npaths) <= 0) + goto cleanup; } =20 - if (virSecurityManagerMetadataLock(list->manager, paths, npaths) < 0) - goto cleanup; - for (i =3D 0; i < list->nItems; i++) { virSecurityDACChownItemPtr item =3D list->items[i]; =20 @@ -246,7 +249,8 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUSED, break; } =20 - if (virSecurityManagerMetadataUnlock(list->manager, paths, npaths) < 0) + if (list->lock && + virSecurityManagerMetadataUnlock(list->manager, paths, npaths) < 0) goto cleanup; =20 if (rv < 0) @@ -529,11 +533,15 @@ virSecurityDACTransactionStart(virSecurityManagerPtr = mgr) * virSecurityDACTransactionCommit: * @mgr: security manager * @pid: domain's PID + * @lock: lock and unlock paths that are relabeled * * If @pid is not -1 then enter the @pid namespace (usually @pid refers * to a domain) and perform all the chown()-s on the list. If @pid is -1 * then the transaction is performed in the namespace of the caller. * + * If @lock is true then all the paths that transaction would + * touch are locked before and unlocked after it is done so. + * * Note that the transaction is also freed, therefore new one has to be * started after successful return from this function. Also it is * considered as error if there's no transaction set and this function @@ -544,9 +552,11 @@ virSecurityDACTransactionStart(virSecurityManagerPtr m= gr) */ static int virSecurityDACTransactionCommit(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, - pid_t pid) + pid_t pid, + bool lock) { virSecurityDACChownListPtr list; + int rc; int ret =3D -1; =20 list =3D virThreadLocalGet(&chownList); @@ -562,12 +572,20 @@ virSecurityDACTransactionCommit(virSecurityManagerPtr= mgr ATTRIBUTE_UNUSED, goto cleanup; } =20 - if ((pid =3D=3D -1 && - virSecurityDACTransactionRun(pid, list) < 0) || - (pid !=3D -1 && - virProcessRunInMountNamespace(pid, - virSecurityDACTransactionRun, - list) < 0)) + list->lock =3D lock; + + if (pid =3D=3D -1) { + if (lock) + rc =3D virProcessRunInFork(virSecurityDACTransactionRun, list); + else + rc =3D virSecurityDACTransactionRun(pid, list); + } else { + rc =3D virProcessRunInMountNamespace(pid, + virSecurityDACTransactionRun, + list); + } + + if (rc < 0) goto cleanup; =20 ret =3D 0; diff --git a/src/security/security_driver.h b/src/security/security_driver.h index cbf0ecff6e..cd221f1c78 100644 --- a/src/security/security_driver.h +++ b/src/security/security_driver.h @@ -53,7 +53,8 @@ typedef int (*virSecurityDriverPreFork) (virSecurityManag= erPtr mgr); =20 typedef int (*virSecurityDriverTransactionStart) (virSecurityManagerPtr mg= r); typedef int (*virSecurityDriverTransactionCommit) (virSecurityManagerPtr m= gr, - pid_t pid); + pid_t pid, + bool lock); typedef void (*virSecurityDriverTransactionAbort) (virSecurityManagerPtr m= gr); =20 typedef int (*virSecurityDomainRestoreDiskLabel) (virSecurityManagerPtr mg= r, diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index c6c80e6165..712b785ae9 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -299,12 +299,16 @@ virSecurityManagerTransactionStart(virSecurityManager= Ptr mgr) * virSecurityManagerTransactionCommit: * @mgr: security manager * @pid: domain's PID + * @lock: lock and unlock paths that are relabeled * * If @pid is not -1 then enter the @pid namespace (usually @pid refers * to a domain) and perform all the operations on the transaction list. * If @pid is -1 then the transaction is performed in the namespace of * the caller. * + * If @lock is true then all the paths that transaction would + * touch are locked before and unlocked after it is done so. + * * Note that the transaction is also freed, therefore new one has to be * started after successful return from this function. Also it is * considered as error if there's no transaction set and this function @@ -315,13 +319,14 @@ virSecurityManagerTransactionStart(virSecurityManager= Ptr mgr) */ int virSecurityManagerTransactionCommit(virSecurityManagerPtr mgr, - pid_t pid) + pid_t pid, + bool lock) { int ret =3D 0; =20 virObjectLock(mgr); if (mgr->drv->transactionCommit) - ret =3D mgr->drv->transactionCommit(mgr, pid); + ret =3D mgr->drv->transactionCommit(mgr, pid, lock); virObjectUnlock(mgr); return ret; } diff --git a/src/security/security_manager.h b/src/security/security_manage= r.h index 10ebe5cc29..04bb54f61e 100644 --- a/src/security/security_manager.h +++ b/src/security/security_manager.h @@ -79,7 +79,8 @@ void virSecurityManagerPostFork(virSecurityManagerPtr mgr= ); =20 int virSecurityManagerTransactionStart(virSecurityManagerPtr mgr); int virSecurityManagerTransactionCommit(virSecurityManagerPtr mgr, - pid_t pid); + pid_t pid, + bool lock); void virSecurityManagerTransactionAbort(virSecurityManagerPtr mgr); =20 void *virSecurityManagerGetPrivateData(virSecurityManagerPtr mgr); diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 780d650c69..5e72a3589a 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -93,6 +93,7 @@ struct _virSecuritySELinuxContextList { virSecurityManagerPtr manager; virSecuritySELinuxContextItemPtr *items; size_t nItems; + bool lock; }; =20 #define SECURITY_SELINUX_VOID_DOI "0" @@ -221,21 +222,23 @@ virSecuritySELinuxTransactionRun(pid_t pid ATTRIBUTE_= UNUSED, int rv; int ret =3D -1; =20 - if (VIR_ALLOC_N(paths, list->nItems) < 0) - return -1; + if (list->lock) { + if (VIR_ALLOC_N(paths, list->nItems) < 0) + return -1; =20 - for (i =3D 0; i < list->nItems; i++) { - const char *p =3D list->items[i]->path; + for (i =3D 0; i < list->nItems; i++) { + const char *p =3D list->items[i]->path; =20 - if (virFileIsDir(p)) - continue; + if (virFileIsDir(p)) + continue; =20 - VIR_APPEND_ELEMENT_COPY_INPLACE(paths, npaths, p); + VIR_APPEND_ELEMENT_COPY_INPLACE(paths, npaths, p); + } + + if (virSecurityManagerMetadataLock(list->manager, paths, npaths) <= 0) + goto cleanup; } =20 - if (virSecurityManagerMetadataLock(list->manager, paths, npaths) < 0) - goto cleanup; - rv =3D 0; for (i =3D 0; i < list->nItems; i++) { virSecuritySELinuxContextItemPtr item =3D list->items[i]; @@ -250,7 +253,8 @@ virSecuritySELinuxTransactionRun(pid_t pid ATTRIBUTE_UN= USED, } } =20 - if (virSecurityManagerMetadataUnlock(list->manager, paths, npaths) < 0) + if (list->lock && + virSecurityManagerMetadataUnlock(list->manager, paths, npaths) < 0) goto cleanup; =20 if (rv < 0) @@ -1072,12 +1076,16 @@ virSecuritySELinuxTransactionStart(virSecurityManag= erPtr mgr) * virSecuritySELinuxTransactionCommit: * @mgr: security manager * @pid: domain's PID + * @lock: lock and unlock paths that are relabeled * * If @pis is not -1 then enter the @pid namespace (usually @pid refers * to a domain) and perform all the sefilecon()-s on the list. If @pid * is -1 then the transaction is performed in the namespace of the * caller. * + * If @lock is true then all the paths that transaction would + * touch are locked before and unlocked after it is done so. + * * Note that the transaction is also freed, therefore new one has to be * started after successful return from this function. Also it is * considered as error if there's no transaction set and this function @@ -1088,9 +1096,11 @@ virSecuritySELinuxTransactionStart(virSecurityManage= rPtr mgr) */ static int virSecuritySELinuxTransactionCommit(virSecurityManagerPtr mgr ATTRIBUTE_UN= USED, - pid_t pid) + pid_t pid, + bool lock) { virSecuritySELinuxContextListPtr list; + int rc; int ret =3D -1; =20 list =3D virThreadLocalGet(&contextList); @@ -1106,12 +1116,20 @@ virSecuritySELinuxTransactionCommit(virSecurityMana= gerPtr mgr ATTRIBUTE_UNUSED, goto cleanup; } =20 - if ((pid =3D=3D -1 && - virSecuritySELinuxTransactionRun(pid, list) < 0) || - (pid !=3D -1 && - virProcessRunInMountNamespace(pid, - virSecuritySELinuxTransactionRun, - list) < 0)) + list->lock =3D lock; + + if (pid =3D=3D -1) { + if (lock) + rc =3D virProcessRunInFork(virSecuritySELinuxTransactionRun, l= ist); + else + rc =3D virSecuritySELinuxTransactionRun(pid, list); + } else { + rc =3D virProcessRunInMountNamespace(pid, + virSecuritySELinuxTransactionRu= n, + list); + } + + if (rc < 0) goto cleanup; =20 ret =3D 0; diff --git a/src/security/security_stack.c b/src/security/security_stack.c index e37a681293..3e60d5d2b7 100644 --- a/src/security/security_stack.c +++ b/src/security/security_stack.c @@ -156,14 +156,15 @@ virSecurityStackTransactionStart(virSecurityManagerPt= r mgr) =20 static int virSecurityStackTransactionCommit(virSecurityManagerPtr mgr, - pid_t pid) + pid_t pid, + bool lock) { virSecurityStackDataPtr priv =3D virSecurityManagerGetPrivateData(mgr); virSecurityStackItemPtr item =3D priv->itemsHead; int rc =3D 0; =20 for (; item; item =3D item->next) { - if (virSecurityManagerTransactionCommit(item->securityManager, pid= ) < 0) + if (virSecurityManagerTransactionCommit(item->securityManager, pid= , lock) < 0) rc =3D -1; } =20 --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542201439591462.17214492786104; Wed, 14 Nov 2018 05:17:19 -0800 (PST) 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 C14F2C04B2EF; Wed, 14 Nov 2018 13:17:16 +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 5E9151779E; Wed, 14 Nov 2018 13:17:16 +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 EA0BA3D382; Wed, 14 Nov 2018 13:17:15 +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 wAECitC7026189 for ; Wed, 14 Nov 2018 07:44:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 34A806B468; Wed, 14 Nov 2018 12:44:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF4356E715 for ; Wed, 14 Nov 2018 12:44:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:34 +0100 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 06/15] security_manager: Rework metadata locking 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 14 Nov 2018 13:17:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Trying to use virlockd to lock metadata turns out to be too big gun. Since we will always spawn a separate process for relabeling we are safe to use thread unsafe POSIX locks and take out virtlockd completely out of the picture. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/security/security_dac.c | 12 +- src/security/security_manager.c | 225 +++++++++++++++++--------------- src/security/security_manager.h | 17 ++- src/security/security_selinux.c | 11 +- 4 files changed, 141 insertions(+), 124 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 0e100f7895..6b64d2c07a 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -205,6 +205,7 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUSED, void *opaque) { virSecurityDACChownListPtr list =3D opaque; + virSecurityManagerMetadataLockStatePtr state; const char **paths =3D NULL; size_t npaths =3D 0; size_t i; @@ -218,14 +219,10 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUS= ED, for (i =3D 0; i < list->nItems; i++) { const char *p =3D list->items[i]->path; =20 - if (!p || - virFileIsDir(p)) - continue; - VIR_APPEND_ELEMENT_COPY_INPLACE(paths, npaths, p); } =20 - if (virSecurityManagerMetadataLock(list->manager, paths, npaths) <= 0) + if (!(state =3D virSecurityManagerMetadataLock(list->manager, path= s, npaths))) goto cleanup; } =20 @@ -249,9 +246,8 @@ virSecurityDACTransactionRun(pid_t pid ATTRIBUTE_UNUSED, break; } =20 - if (list->lock && - virSecurityManagerMetadataUnlock(list->manager, paths, npaths) < 0) - goto cleanup; + if (list->lock) + virSecurityManagerMetadataUnlock(list->manager, &state); =20 if (rv < 0) goto cleanup; diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index 712b785ae9..f527e6b5b3 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -21,6 +21,10 @@ */ #include =20 +#include +#include +#include + #include "security_driver.h" #include "security_stack.h" #include "security_dac.h" @@ -30,14 +34,11 @@ #include "virlog.h" #include "locking/lock_manager.h" #include "virfile.h" -#include "virtime.h" =20 #define VIR_FROM_THIS VIR_FROM_SECURITY =20 VIR_LOG_INIT("security.security_manager"); =20 -virMutex lockManagerMutex =3D VIR_MUTEX_INITIALIZER; - struct _virSecurityManager { virObjectLockable parent; =20 @@ -47,10 +48,6 @@ struct _virSecurityManager { void *privateData; =20 virLockManagerPluginPtr lockPlugin; - /* This is a FD that represents a connection to virtlockd so - * that connection is kept open in between MetdataLock() and - * MetadataUnlock() calls. */ - int clientfd; }; =20 static virClassPtr virSecurityManagerClass; @@ -66,7 +63,6 @@ void virSecurityManagerDispose(void *obj) mgr->drv->close(mgr); =20 virObjectUnref(mgr->lockPlugin); - VIR_FORCE_CLOSE(mgr->clientfd); =20 VIR_FREE(mgr->privateData); } @@ -119,7 +115,6 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv, mgr->flags =3D flags; mgr->virtDriver =3D virtDriver; VIR_STEAL_PTR(mgr->privateData, privateData); - mgr->clientfd =3D -1; =20 if (drv->open(mgr) < 0) goto error; @@ -1281,129 +1276,153 @@ virSecurityManagerRestoreTPMLabels(virSecurityMan= agerPtr mgr, } =20 =20 -static virLockManagerPtr -virSecurityManagerNewLockManager(virSecurityManagerPtr mgr, - const char * const *paths, - size_t npaths) +struct _virSecurityManagerMetadataLockState { + size_t nfds; + int *fds; +}; + + +static int +cmpstringp(const void *p1, const void *p2) { - virLockManagerPtr lock; - virLockManagerParam params[] =3D { - { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_UUID, - .key =3D "uuid", - }, - { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_STRING, - .key =3D "name", - .value =3D { .cstr =3D "libvirtd-sec" }, - }, - { .type =3D VIR_LOCK_MANAGER_PARAM_TYPE_UINT, - .key =3D "pid", - .value =3D { .iv =3D getpid() }, - }, - }; - const unsigned int flags =3D 0; - size_t i; + const char *s1 =3D *(char * const *) p1; + const char *s2 =3D *(char * const *) p2; =20 - if (virGetHostUUID(params[0].value.uuid) < 0) - return NULL; + if (!s1 && !s2) + return 0; =20 - if (!(lock =3D virLockManagerNew(virLockManagerPluginGetDriver(mgr->lo= ckPlugin), - VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON, - ARRAY_CARDINALITY(params), - params, - flags))) - return NULL; + if (!s1 || !s2) + return s2 ? -1 : 1; =20 - for (i =3D 0; i < npaths; i++) { - if (virLockManagerAddResource(lock, - VIR_LOCK_MANAGER_RESOURCE_TYPE_METAD= ATA, - paths[i], 0, NULL, 0) < 0) - goto error; - } - - return lock; - error: - virLockManagerFree(lock); - return NULL; + /* from man 3 qsort */ + return strcmp(s1, s2); } =20 +#define METADATA_OFFSET 1 +#define METADATA_LEN 1 =20 -/* How many seconds should we try to acquire the lock before - * giving up. */ -#define LOCK_ACQUIRE_TIMEOUT 60 - -int -virSecurityManagerMetadataLock(virSecurityManagerPtr mgr, - const char * const *paths, +/** + * virSecurityManagerMetadataLock: + * @mgr: security manager object + * @paths: paths to lock + * @npaths: number of items in @paths array + * + * Lock passed @paths for metadata change. The returned state + * should be passed to virSecurityManagerMetadataUnlock. + * + * NOTE: this function is not thread safe (because of usage of + * POSIX locks). + * + * Returns: state on success, + * NULL on failure. + */ +virSecurityManagerMetadataLockStatePtr +virSecurityManagerMetadataLock(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, + const char **paths, size_t npaths) { - virLockManagerPtr lock; - virTimeBackOffVar timebackoff; - int fd =3D -1; - int rv =3D -1; - int ret =3D -1; + size_t i =3D 0; + size_t nfds =3D 0; + int *fds =3D NULL; + virSecurityManagerMetadataLockStatePtr ret =3D NULL; =20 - virMutexLock(&lockManagerMutex); + if (VIR_ALLOC_N(fds, npaths) < 0) + return NULL; =20 - if (!(lock =3D virSecurityManagerNewLockManager(mgr, paths, npaths))) - goto cleanup; + /* Sort paths to lock in order to avoid deadlocks. */ + qsort(paths, npaths, sizeof(*paths), cmpstringp); =20 - if (virTimeBackOffStart(&timebackoff, 1, LOCK_ACQUIRE_TIMEOUT * 1000) = < 0) - goto cleanup; - while (virTimeBackOffWait(&timebackoff)) { - rv =3D virLockManagerAcquire(lock, NULL, - VIR_LOCK_MANAGER_ACQUIRE_ROLLBACK, - VIR_DOMAIN_LOCK_FAILURE_DEFAULT, &fd); + for (i =3D 0; i < npaths; i++) { + const char *p =3D paths[i]; + struct stat sb; + int retries =3D 10 * 1000; + int fd; + + if (!p || stat(p, &sb) < 0) + continue; + + if (S_ISDIR(sb.st_mode)) { + /* Directories can't be locked */ + continue; + } + + if ((fd =3D open(p, O_RDWR)) < 0) { + if (S_ISSOCK(sb.st_mode)) { + /* Sockets can be opened only if there exists the + * other side that listens. */ + continue; + } + + virReportSystemError(errno, + _("unable to open %s"), + p); + goto cleanup; + } + + do { + if (virFileLock(fd, false, + METADATA_OFFSET, METADATA_LEN, false) < 0) { + if (retries && (errno =3D=3D EACCES || errno =3D=3D EAGAIN= )) { + /* File is locked. Try again. */ + retries--; + usleep(1000); + continue; + } else { + virReportSystemError(errno, + _("unable to lock %s for metadata= change"), + p); + VIR_FORCE_CLOSE(fd); + goto cleanup; + } + } =20 - if (rv >=3D 0) break; + } while (1); =20 - if (virGetLastErrorCode() =3D=3D VIR_ERR_RESOURCE_BUSY) - continue; - - goto cleanup; + VIR_APPEND_ELEMENT_COPY_INPLACE(fds, nfds, fd); } =20 - if (rv < 0) + if (VIR_ALLOC(ret) < 0) goto cleanup; =20 - mgr->clientfd =3D fd; - fd =3D -1; + VIR_STEAL_PTR(ret->fds, fds); + ret->nfds =3D nfds; + nfds =3D 0; =20 - ret =3D 0; cleanup: - virLockManagerFree(lock); - VIR_FORCE_CLOSE(fd); - if (ret < 0) - virMutexUnlock(&lockManagerMutex); + for (i =3D nfds; i > 0; i--) + VIR_FORCE_CLOSE(fds[i - 1]); + VIR_FREE(fds); return ret; } =20 =20 -int -virSecurityManagerMetadataUnlock(virSecurityManagerPtr mgr, - const char * const *paths, - size_t npaths) +void +virSecurityManagerMetadataUnlock(virSecurityManagerPtr mgr ATTRIBUTE_UNUSE= D, + virSecurityManagerMetadataLockStatePtr *s= tate) { - virLockManagerPtr lock; - int fd; - int ret =3D -1; + size_t i; =20 - /* lockManagerMutex acquired from previous - * virSecurityManagerMetadataLock() call. */ + if (!state) + return; =20 - fd =3D mgr->clientfd; - mgr->clientfd =3D -1; + for (i =3D 0; i < (*state)->nfds; i++) { + char ebuf[1024]; + int fd =3D (*state)->fds[i]; =20 - if (!(lock =3D virSecurityManagerNewLockManager(mgr, paths, npaths))) - goto cleanup; + /* Technically, unlock is not needed because it will + * happen on VIR_CLOSE() anyway. But let's play it nice. */ + if (virFileUnlock(fd, METADATA_OFFSET, METADATA_LEN) < 0) { + VIR_WARN("Unable to unlock fd %d: %s", + fd, virStrerror(errno, ebuf, sizeof(ebuf))); + } =20 - if (virLockManagerRelease(lock, NULL, 0) < 0) - goto cleanup; + if (VIR_CLOSE(fd) < 0) { + VIR_WARN("Unable to close fd %d: %s", + fd, virStrerror(errno, ebuf, sizeof(ebuf))); + } + } =20 - ret =3D 0; - cleanup: - virLockManagerFree(lock); - VIR_FORCE_CLOSE(fd); - virMutexUnlock(&lockManagerMutex); - return ret; + VIR_FREE((*state)->fds); + VIR_FREE(*state); } diff --git a/src/security/security_manager.h b/src/security/security_manage= r.h index 04bb54f61e..cacb17174f 100644 --- a/src/security/security_manager.h +++ b/src/security/security_manager.h @@ -200,11 +200,16 @@ int virSecurityManagerSetTPMLabels(virSecurityManager= Ptr mgr, int virSecurityManagerRestoreTPMLabels(virSecurityManagerPtr mgr, virDomainDefPtr vm); =20 -int virSecurityManagerMetadataLock(virSecurityManagerPtr mgr, - const char * const *paths, - size_t npaths); -int virSecurityManagerMetadataUnlock(virSecurityManagerPtr mgr, - const char * const *paths, - size_t npaths); +typedef struct _virSecurityManagerMetadataLockState virSecurityManagerMeta= dataLockState; +typedef virSecurityManagerMetadataLockState *virSecurityManagerMetadataLoc= kStatePtr; + +virSecurityManagerMetadataLockStatePtr +virSecurityManagerMetadataLock(virSecurityManagerPtr mgr, + const char **paths, + size_t npaths); + +void +virSecurityManagerMetadataUnlock(virSecurityManagerPtr mgr, + virSecurityManagerMetadataLockStatePtr *s= tate); =20 #endif /* VIR_SECURITY_MANAGER_H__ */ diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 5e72a3589a..95e9a1b0c7 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -215,6 +215,7 @@ virSecuritySELinuxTransactionRun(pid_t pid ATTRIBUTE_UN= USED, void *opaque) { virSecuritySELinuxContextListPtr list =3D opaque; + virSecurityManagerMetadataLockStatePtr state; bool privileged =3D virSecurityManagerGetPrivileged(list->manager); const char **paths =3D NULL; size_t npaths =3D 0; @@ -229,13 +230,10 @@ virSecuritySELinuxTransactionRun(pid_t pid ATTRIBUTE_= UNUSED, for (i =3D 0; i < list->nItems; i++) { const char *p =3D list->items[i]->path; =20 - if (virFileIsDir(p)) - continue; - VIR_APPEND_ELEMENT_COPY_INPLACE(paths, npaths, p); } =20 - if (virSecurityManagerMetadataLock(list->manager, paths, npaths) <= 0) + if (!(state =3D virSecurityManagerMetadataLock(list->manager, path= s, npaths))) goto cleanup; } =20 @@ -253,9 +251,8 @@ virSecuritySELinuxTransactionRun(pid_t pid ATTRIBUTE_UN= USED, } } =20 - if (list->lock && - virSecurityManagerMetadataUnlock(list->manager, paths, npaths) < 0) - goto cleanup; + if (list->lock) + virSecurityManagerMetadataUnlock(list->manager, &state); =20 if (rv < 0) goto cleanup; --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154220145227298.97813023397339; Wed, 14 Nov 2018 05:17:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBA9BC013C2D; Wed, 14 Nov 2018 13:17:29 +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 8F5B360FA6; Wed, 14 Nov 2018 13:17:29 +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 4C4893D3AA; Wed, 14 Nov 2018 13:17:29 +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 wAECiuLC026205 for ; Wed, 14 Nov 2018 07:44:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 093A46B481; Wed, 14 Nov 2018 12:44:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82C3C6B468 for ; Wed, 14 Nov 2018 12:44:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:35 +0100 Message-Id: <4beb190cb92ebcbe49c53def8b19a3fc80e9d4eb.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 07/15] Revert "security_manager: Load lock plugin on init" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 14 Nov 2018 13:17:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 3e26b476b5f322353bf0dcd8e3f037ca672b8c62. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- cfg.mk | 4 +--- src/lxc/lxc_controller.c | 3 +-- src/lxc/lxc_driver.c | 2 +- src/qemu/qemu_driver.c | 3 --- src/security/security_manager.c | 25 +------------------------ src/security/security_manager.h | 2 -- tests/seclabeltest.c | 2 +- tests/securityselinuxlabeltest.c | 2 +- tests/securityselinuxtest.c | 2 +- tests/testutilsqemu.c | 2 +- 10 files changed, 8 insertions(+), 39 deletions(-) diff --git a/cfg.mk b/cfg.mk index d0183c02ff..c83b152fda 100644 --- a/cfg.mk +++ b/cfg.mk @@ -787,10 +787,8 @@ sc_prohibit_cross_inclusion: case $$dir in \ util/) safe=3D"util";; \ access/ | conf/) safe=3D"($$dir|conf|util)";; \ - cpu/| network/| node_device/| rpc/| storage/) \ + cpu/| network/| node_device/| rpc/| security/| storage/) \ safe=3D"($$dir|util|conf|storage)";; \ - security/) \ - safe=3D"($$dir|util|conf|storage|locking)";; \ xenapi/ | xenconfig/ ) safe=3D"($$dir|util|conf|xen|cpu)";; \ *) safe=3D"($$dir|$(mid_dirs)|util)";; \ esac; \ diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 62dfd09473..e853d02d65 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -2624,8 +2624,7 @@ int main(int argc, char *argv[]) ctrl->handshakeFd =3D handshakeFd; =20 if (!(ctrl->securityManager =3D virSecurityManagerNew(securityDriver, - LXC_DRIVER_NAME, - NULL, 0))) + LXC_DRIVER_NAME, 0= ))) goto cleanup; =20 if (ctrl->def->seclabels) { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f732305649..990871d9b3 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1531,7 +1531,7 @@ lxcSecurityInit(virLXCDriverConfigPtr cfg) flags |=3D VIR_SECURITY_MANAGER_REQUIRE_CONFINED; =20 virSecurityManagerPtr mgr =3D virSecurityManagerNew(cfg->securityDrive= rName, - LXC_DRIVER_NAME, NUL= L, flags); + LXC_DRIVER_NAME, fla= gs); if (!mgr) goto error; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 09e04b8544..e387c831d4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -350,7 +350,6 @@ qemuSecurityInit(virQEMUDriverPtr driver) while (names && *names) { if (!(mgr =3D qemuSecurityNew(*names, QEMU_DRIVER_NAME, - cfg->metadataLockManagerName, flags))) goto error; if (!stack) { @@ -366,7 +365,6 @@ qemuSecurityInit(virQEMUDriverPtr driver) } else { if (!(mgr =3D qemuSecurityNew(NULL, QEMU_DRIVER_NAME, - cfg->metadataLockManagerName, flags))) goto error; if (!(stack =3D qemuSecurityNewStack(mgr))) @@ -383,7 +381,6 @@ qemuSecurityInit(virQEMUDriverPtr driver) cfg->user, cfg->group, flags, - cfg->metadataLockManagerName, qemuSecurityChownCallback))) goto error; if (!stack) { diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index f527e6b5b3..a049382c7b 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -32,7 +32,6 @@ #include "viralloc.h" #include "virobject.h" #include "virlog.h" -#include "locking/lock_manager.h" #include "virfile.h" =20 #define VIR_FROM_THIS VIR_FROM_SECURITY @@ -46,8 +45,6 @@ struct _virSecurityManager { unsigned int flags; const char *virtDriver; void *privateData; - - virLockManagerPluginPtr lockPlugin; }; =20 static virClassPtr virSecurityManagerClass; @@ -58,12 +55,8 @@ void virSecurityManagerDispose(void *obj) { virSecurityManagerPtr mgr =3D obj; =20 - if (mgr->drv && - mgr->drv->close) + if (mgr->drv->close) mgr->drv->close(mgr); - - virObjectUnref(mgr->lockPlugin); - VIR_FREE(mgr->privateData); } =20 @@ -83,7 +76,6 @@ VIR_ONCE_GLOBAL_INIT(virSecurityManager); static virSecurityManagerPtr virSecurityManagerNewDriver(virSecurityDriverPtr drv, const char *virtDriver, - const char *lockManagerPluginName, unsigned int flags) { virSecurityManagerPtr mgr =3D NULL; @@ -103,14 +95,6 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv, if (!(mgr =3D virObjectLockableNew(virSecurityManagerClass))) goto error; =20 - if (!lockManagerPluginName) - lockManagerPluginName =3D "nop"; - - if (!(mgr->lockPlugin =3D virLockManagerPluginNew(lockManagerPluginNam= e, - NULL, NULL, 0))) { - goto error; - } - mgr->drv =3D drv; mgr->flags =3D flags; mgr->virtDriver =3D virtDriver; @@ -133,7 +117,6 @@ virSecurityManagerNewStack(virSecurityManagerPtr primar= y) virSecurityManagerPtr mgr =3D virSecurityManagerNewDriver(&virSecurityDriverStack, virSecurityManagerGetDriver(primary), - NULL, primary->flags); =20 if (!mgr) @@ -142,8 +125,6 @@ virSecurityManagerNewStack(virSecurityManagerPtr primar= y) if (virSecurityStackAddNested(mgr, primary) < 0) goto error; =20 - mgr->lockPlugin =3D virObjectRef(mgr->lockPlugin); - return mgr; error: virObjectUnref(mgr); @@ -166,7 +147,6 @@ virSecurityManagerNewDAC(const char *virtDriver, uid_t user, gid_t group, unsigned int flags, - const char *lockManagerPluginName, virSecurityManagerDACChownCallback chownCallback) { virSecurityManagerPtr mgr; @@ -177,7 +157,6 @@ virSecurityManagerNewDAC(const char *virtDriver, =20 mgr =3D virSecurityManagerNewDriver(&virSecurityDriverDAC, virtDriver, - lockManagerPluginName, flags & VIR_SECURITY_MANAGER_NEW_MAS= K); =20 if (!mgr) @@ -199,7 +178,6 @@ virSecurityManagerNewDAC(const char *virtDriver, virSecurityManagerPtr virSecurityManagerNew(const char *name, const char *virtDriver, - const char *lockManagerPluginName, unsigned int flags) { virSecurityDriverPtr drv =3D virSecurityDriverLookup(name, virtDriver); @@ -228,7 +206,6 @@ virSecurityManagerNew(const char *name, =20 return virSecurityManagerNewDriver(drv, virtDriver, - lockManagerPluginName, flags); } =20 diff --git a/src/security/security_manager.h b/src/security/security_manage= r.h index cacb17174f..7e82304689 100644 --- a/src/security/security_manager.h +++ b/src/security/security_manager.h @@ -45,7 +45,6 @@ typedef enum { =20 virSecurityManagerPtr virSecurityManagerNew(const char *name, const char *virtDriver, - const char *lockManagerPluginN= ame, unsigned int flags); =20 virSecurityManagerPtr virSecurityManagerNewStack(virSecurityManagerPtr pri= mary); @@ -71,7 +70,6 @@ virSecurityManagerPtr virSecurityManagerNewDAC(const char= *virtDriver, uid_t user, gid_t group, unsigned int flags, - const char *lockManagerPlug= inName, virSecurityManagerDACChownC= allback chownCallback); =20 int virSecurityManagerPreFork(virSecurityManagerPtr mgr); diff --git a/tests/seclabeltest.c b/tests/seclabeltest.c index 7cddf96e82..a0296c787e 100644 --- a/tests/seclabeltest.c +++ b/tests/seclabeltest.c @@ -14,7 +14,7 @@ mymain(void) if (virThreadInitialize() < 0) return EXIT_FAILURE; =20 - mgr =3D virSecurityManagerNew(NULL, "QEMU", NULL, VIR_SECURITY_MANAGER= _DEFAULT_CONFINED); + mgr =3D virSecurityManagerNew(NULL, "QEMU", VIR_SECURITY_MANAGER_DEFAU= LT_CONFINED); if (mgr =3D=3D NULL) { fprintf(stderr, "Failed to start security driver"); return EXIT_FAILURE; diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabelt= est.c index aa9fae7d32..39f4eb7b6a 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -346,7 +346,7 @@ mymain(void) if (!rc) return EXIT_AM_SKIP; =20 - if (!(mgr =3D virSecurityManagerNew("selinux", "QEMU", NULL, + if (!(mgr =3D virSecurityManagerNew("selinux", "QEMU", VIR_SECURITY_MANAGER_DEFAULT_CONFINE= D | VIR_SECURITY_MANAGER_PRIVILEGED))) { VIR_TEST_VERBOSE("Unable to initialize security driver: %s\n", diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index f1ea51b1ac..a2864cf57c 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -272,7 +272,7 @@ mymain(void) int ret =3D 0; virSecurityManagerPtr mgr; =20 - if (!(mgr =3D virSecurityManagerNew("selinux", "QEMU", NULL, + if (!(mgr =3D virSecurityManagerNew("selinux", "QEMU", VIR_SECURITY_MANAGER_DEFAULT_CONFINE= D | VIR_SECURITY_MANAGER_PRIVILEGED))) { fprintf(stderr, "Unable to initialize security driver: %s\n", diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 332885eb77..0d3e9fc7e6 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -716,7 +716,7 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (qemuTestCapsCacheInsert(driver->qemuCapsCache, NULL) < 0) goto error; =20 - if (!(mgr =3D virSecurityManagerNew("none", "qemu", NULL, + if (!(mgr =3D virSecurityManagerNew("none", "qemu", VIR_SECURITY_MANAGER_PRIVILEGED))) goto error; if (!(driver->securityManager =3D virSecurityManagerNewStack(mgr))) --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200537152478.201876292479; Wed, 14 Nov 2018 05:02:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 327A930C5381; Wed, 14 Nov 2018 13:02:14 +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 E230C61481; Wed, 14 Nov 2018 13:02:13 +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 7A4B14CAB0; Wed, 14 Nov 2018 13:02:13 +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 wAECiul9026212 for ; Wed, 14 Nov 2018 07:44:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id D060B6B481; Wed, 14 Nov 2018 12:44:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5616C6B468 for ; Wed, 14 Nov 2018 12:44:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:36 +0100 Message-Id: <19817deb25ef1da1d9d91de0e7bf2291a8239225.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 08/15] Revert "qemu_conf: Introduce metadata_lock_manager" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 14 Nov 2018 13:02:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 8b8aefb3d6ae2139ea3d4ef6d7dd2c06f57f6075. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_conf.c | 1 - src/qemu/qemu_conf.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 17b7e11e02..32da9a7351 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -426,7 +426,6 @@ static void virQEMUDriverConfigDispose(void *obj) virStringListFree(cfg->securityDriverNames); =20 VIR_FREE(cfg->lockManagerName); - VIR_FREE(cfg->metadataLockManagerName); =20 virFirmwareFreeList(cfg->firmwares, cfg->nfirmwares); =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 0b5b5a314f..8986350fad 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -187,7 +187,6 @@ struct _virQEMUDriverConfig { bool autoStartBypassCache; =20 char *lockManagerName; - char *metadataLockManagerName; =20 int keepAliveInterval; unsigned int keepAliveCount; --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15422014667921003.8399096907052; Wed, 14 Nov 2018 05:17:46 -0800 (PST) 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 0DD46307EA97; Wed, 14 Nov 2018 13:17:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3D9A177BB; Wed, 14 Nov 2018 13:17:41 +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 3F38718E3061; Wed, 14 Nov 2018 13:17:41 +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 wAECivTj026223 for ; Wed, 14 Nov 2018 07:44:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id A204B6B468; Wed, 14 Nov 2018 12:44:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28C256E718 for ; Wed, 14 Nov 2018 12:44:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:37 +0100 Message-Id: <3e3990bbce5df1376d285281fd31ae882e758d36.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 09/15] Revert "lock_manager: Allow disabling configFile for virLockManagerPluginNew" 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 14 Nov 2018 13:17:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 35b5b244da825fb41e35e4dc62e740d716214ec9. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_driver.h | 4 ---- src/locking/lock_driver_lockd.c | 4 +--- src/locking/lock_driver_sanlock.c | 4 +--- src/locking/lock_manager.c | 10 +++------- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/locking/lock_driver.h b/src/locking/lock_driver.h index ae30abda7d..7c8f744be3 100644 --- a/src/locking/lock_driver.h +++ b/src/locking/lock_driver.h @@ -124,7 +124,6 @@ struct _virLockManagerParam { /** * virLockDriverInit: * @version: the libvirt requested plugin ABI version - * @configFile: path to config file * @flags: the libvirt requested plugin optional extras * * Allow the plugin to validate the libvirt requested @@ -132,9 +131,6 @@ struct _virLockManagerParam { * to block its use in versions of libvirtd which are * too old to support key features. * - * The @configFile variable points to config file that the driver - * should load. If NULL, no config file should be loaded. - * * NB: A plugin may be loaded multiple times, for different * libvirt drivers (eg QEMU, LXC, UML) * diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index 0c672b05b1..85cdcf97be 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -371,10 +371,8 @@ static int virLockManagerLockDaemonInit(unsigned int v= ersion, driver->requireLeaseForDisks =3D true; driver->autoDiskLease =3D true; =20 - if (configFile && - virLockManagerLockDaemonLoadConfig(configFile) < 0) { + if (virLockManagerLockDaemonLoadConfig(configFile) < 0) goto error; - } =20 if (driver->autoDiskLease) { if (driver->fileLockSpaceDir && diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 3ad0dc9bed..b10d8197c5 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -446,10 +446,8 @@ static int virLockManagerSanlockInit(unsigned int vers= ion, goto error; } =20 - if (configFile && - virLockManagerSanlockLoadConfig(driver, configFile) < 0) { + if (virLockManagerSanlockLoadConfig(driver, configFile) < 0) goto error; - } =20 if (driver->autoDiskLease && !driver->hostID) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index 9067f5a01a..d421b6acfc 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -104,8 +104,6 @@ static void virLockManagerLogParams(size_t nparams, /** * virLockManagerPluginNew: * @name: the name of the plugin - * @driverName: the hypervisor driver that loads the plugin - * @configDir: path to dir where config files are stored * @flag: optional plugin flags * * Attempt to load the plugin $(libdir)/libvirt/lock-driver/@name.so @@ -131,13 +129,11 @@ virLockManagerPluginPtr virLockManagerPluginNew(const= char *name, char *configFile =3D NULL; =20 VIR_DEBUG("name=3D%s driverName=3D%s configDir=3D%s flags=3D0x%x", - name, NULLSTR(driverName), NULLSTR(configDir), flags); + name, driverName, configDir, flags); =20 - if (driverName && configDir && - virAsprintf(&configFile, "%s/%s-%s.conf", - configDir, driverName, name) < 0) { + if (virAsprintf(&configFile, "%s/%s-%s.conf", + configDir, driverName, name) < 0) return NULL; - } =20 if (STREQ(name, "nop")) { driver =3D &virLockDriverNop; --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200550025768.7382540980534; Wed, 14 Nov 2018 05:02:30 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41D393078AB6; Wed, 14 Nov 2018 13:02:28 +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 03BDB100190B; Wed, 14 Nov 2018 13:02:28 +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 9A4704CAA0; Wed, 14 Nov 2018 13:02:27 +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 wAECiw0r026244 for ; Wed, 14 Nov 2018 07:44:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7551A6E71E; Wed, 14 Nov 2018 12:44:58 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF58B6E716 for ; Wed, 14 Nov 2018 12:44:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:38 +0100 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 10/15] Revert "lock_driver: Introduce VIR_LOCK_MANAGER_ACQUIRE_ROLLBACK" 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 14 Nov 2018 13:02:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 385eb8399bdb1610447c2857abfe99cee4a9fb9e. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_driver.h | 4 -- src/locking/lock_driver_lockd.c | 82 ++++++++++----------------------- 2 files changed, 24 insertions(+), 62 deletions(-) diff --git a/src/locking/lock_driver.h b/src/locking/lock_driver.h index 7c8f744be3..9be0abcfba 100644 --- a/src/locking/lock_driver.h +++ b/src/locking/lock_driver.h @@ -67,10 +67,6 @@ typedef enum { VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY =3D (1 << 0), /* Prevent further lock/unlock calls from this process */ VIR_LOCK_MANAGER_ACQUIRE_RESTRICT =3D (1 << 1), - /* Used when acquiring more resources in which one of them - * can't be acquired, perform a rollback and release all - * resources acquired so far. */ - VIR_LOCK_MANAGER_ACQUIRE_ROLLBACK =3D (1 << 2), } virLockManagerAcquireFlags; =20 typedef enum { diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index 85cdcf97be..d6551e125c 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -735,34 +735,6 @@ static int virLockManagerLockDaemonAddResource(virLock= ManagerPtr lock, } =20 =20 -static int virLockManagerLockDaemonReleaseImpl(virNetClientPtr client, - virNetClientProgramPtr prog= ram, - int counter, - virLockManagerLockDaemonRes= ourcePtr res) -{ - virLockSpaceProtocolReleaseResourceArgs args; - - memset(&args, 0, sizeof(args)); - - args.path =3D res->lockspace; - args.name =3D res->name; - args.flags =3D res->flags; - - args.flags &=3D - ~(VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED | - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE | - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA); - - return virNetClientProgramCall(program, - client, - counter, - VIR_LOCK_SPACE_PROTOCOL_PROC_RELEASE_RE= SOURCE, - 0, NULL, NULL, NULL, - (xdrproc_t)xdr_virLockSpaceProtocolRele= aseResourceArgs, &args, - (xdrproc_t)xdr_void, NULL); -} - - static int virLockManagerLockDaemonAcquire(virLockManagerPtr lock, const char *state ATTRIBUTE_UNU= SED, unsigned int flags, @@ -773,13 +745,10 @@ static int virLockManagerLockDaemonAcquire(virLockMan= agerPtr lock, virNetClientProgramPtr program =3D NULL; int counter =3D 0; int rv =3D -1; - ssize_t i; - ssize_t lastGood =3D -1; virLockManagerLockDaemonPrivatePtr priv =3D lock->privateData; =20 virCheckFlags(VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY | - VIR_LOCK_MANAGER_ACQUIRE_RESTRICT | - VIR_LOCK_MANAGER_ACQUIRE_ROLLBACK, -1); + VIR_LOCK_MANAGER_ACQUIRE_RESTRICT, -1); =20 if (priv->type =3D=3D VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN && priv->nresources =3D=3D 0 && @@ -798,6 +767,7 @@ static int virLockManagerLockDaemonAcquire(virLockManag= erPtr lock, goto cleanup; =20 if (!(flags & VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY)) { + size_t i; for (i =3D 0; i < priv->nresources; i++) { virLockSpaceProtocolAcquireResourceArgs args; =20 @@ -815,7 +785,6 @@ static int virLockManagerLockDaemonAcquire(virLockManag= erPtr lock, (xdrproc_t)xdr_virLockSpaceProtoco= lAcquireResourceArgs, &args, (xdrproc_t)xdr_void, NULL) < 0) goto cleanup; - lastGood =3D i; } } =20 @@ -826,28 +795,8 @@ static int virLockManagerLockDaemonAcquire(virLockMana= gerPtr lock, rv =3D 0; =20 cleanup: - if (rv < 0) { - int saved_errno =3D errno; - virErrorPtr origerr; - - virErrorPreserveLast(&origerr); - if (fd) - VIR_FORCE_CLOSE(*fd); - - if (flags & VIR_LOCK_MANAGER_ACQUIRE_ROLLBACK) { - for (i =3D lastGood; i >=3D 0; i--) { - virLockManagerLockDaemonResourcePtr res =3D &priv->resourc= es[i]; - - if (virLockManagerLockDaemonReleaseImpl(client, program, - counter++, res) < = 0) - VIR_WARN("Unable to release resource lockspace=3D%s na= me=3D%s", - res->lockspace, res->name); - } - } - - virErrorRestore(&origerr); - errno =3D saved_errno; - } + if (rv !=3D 0 && fd) + VIR_FORCE_CLOSE(*fd); virNetClientClose(client); virObjectUnref(client); virObjectUnref(program); @@ -875,10 +824,27 @@ static int virLockManagerLockDaemonRelease(virLockMan= agerPtr lock, goto cleanup; =20 for (i =3D 0; i < priv->nresources; i++) { - virLockManagerLockDaemonResourcePtr res =3D &priv->resources[i]; + virLockSpaceProtocolReleaseResourceArgs args; =20 - if (virLockManagerLockDaemonReleaseImpl(client, program, - counter++, res) < 0) + memset(&args, 0, sizeof(args)); + + if (priv->resources[i].lockspace) + args.path =3D priv->resources[i].lockspace; + args.name =3D priv->resources[i].name; + args.flags =3D priv->resources[i].flags; + + args.flags &=3D + ~(VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED | + VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE | + VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA); + + if (virNetClientProgramCall(program, + client, + counter++, + VIR_LOCK_SPACE_PROTOCOL_PROC_RELEASE_R= ESOURCE, + 0, NULL, NULL, NULL, + (xdrproc_t)xdr_virLockSpaceProtocolRel= easeResourceArgs, &args, + (xdrproc_t)xdr_void, NULL) < 0) goto cleanup; } =20 --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200566904191.77714433456958; Wed, 14 Nov 2018 05:02:46 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99F9430B9E1F; Wed, 14 Nov 2018 13:02:41 +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 E7190608F0; Wed, 14 Nov 2018 13:02:40 +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 882DD4CAA7; Wed, 14 Nov 2018 13:02:40 +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 wAECj2iY026282 for ; Wed, 14 Nov 2018 07:45:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 14D7C6E717; Wed, 14 Nov 2018 12:45:02 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E5546E721 for ; Wed, 14 Nov 2018 12:44:58 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:39 +0100 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 11/15] Revert "lock_driver: Introduce VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 14 Nov 2018 13:02:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 997283b54b0e1f599aed3085ceba027eb8110acb. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_driver.h | 2 -- src/locking/lock_driver_lockd.c | 47 +++++++++---------------------- src/locking/lock_driver_sanlock.c | 3 +- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/locking/lock_driver.h b/src/locking/lock_driver.h index 9be0abcfba..a9d2041c30 100644 --- a/src/locking/lock_driver.h +++ b/src/locking/lock_driver.h @@ -51,8 +51,6 @@ typedef enum { VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK =3D 0, /* A lease against an arbitrary resource */ VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE =3D 1, - /* The resource to be locked is a metadata */ - VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA =3D 2, } virLockManagerResourceType; =20 typedef enum { diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index d6551e125c..268676c407 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -563,7 +563,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, virLockManagerLockDaemonPrivatePtr priv =3D lock->privateData; char *newName =3D NULL; char *newLockspace =3D NULL; - int newFlags =3D 0; + bool autoCreate =3D false; int ret =3D -1; =20 virCheckFlags(VIR_LOCK_MANAGER_RESOURCE_READONLY | @@ -575,7 +575,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, switch (priv->type) { case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: =20 - switch ((virLockManagerResourceType) type) { + switch (type) { case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK: if (params || nparams) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -602,7 +602,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, VIR_DEBUG("Got an LVM UUID %s for %s", newName, name); if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) = < 0) goto cleanup; - newFlags |=3D VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE= _AUTOCREATE; + autoCreate =3D true; break; } virResetLastError(); @@ -619,7 +619,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, VIR_DEBUG("Got an SCSI ID %s for %s", newName, name); if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir)= < 0) goto cleanup; - newFlags |=3D VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE= _AUTOCREATE; + autoCreate =3D true; break; } virResetLastError(); @@ -631,7 +631,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, goto cleanup; if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &new= Name) < 0) goto cleanup; - newFlags |=3D VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUT= OCREATE; + autoCreate =3D true; VIR_DEBUG("Using indirect lease %s for %s", newName, name); } else { if (VIR_STRDUP(newLockspace, "") < 0) @@ -676,8 +676,6 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, goto cleanup; =20 } break; - - case VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown lock manager object type %d for doma= in lock object"), @@ -687,29 +685,6 @@ static int virLockManagerLockDaemonAddResource(virLock= ManagerPtr lock, break; =20 case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON: - switch ((virLockManagerResourceType) type) { - case VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA: - if (params || nparams) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unexpected parameters for metadata resou= rce")); - goto cleanup; - } - if (VIR_STRDUP(newLockspace, "") < 0 || - VIR_STRDUP(newName, name) < 0) - goto cleanup; - newFlags |=3D VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADAT= A; - break; - - case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK: - case VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE: - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown lock manager object type %d for daem= on lock object"), - type); - goto cleanup; - } - break; - default: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown lock manager object type %d"), @@ -717,15 +692,19 @@ static int virLockManagerLockDaemonAddResource(virLoc= kManagerPtr lock, goto cleanup; } =20 - if (flags & VIR_LOCK_MANAGER_RESOURCE_SHARED) - newFlags |=3D VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED; - if (VIR_EXPAND_N(priv->resources, priv->nresources, 1) < 0) goto cleanup; =20 VIR_STEAL_PTR(priv->resources[priv->nresources-1].lockspace, newLocksp= ace); VIR_STEAL_PTR(priv->resources[priv->nresources-1].name, newName); - priv->resources[priv->nresources-1].flags =3D newFlags; + + if (flags & VIR_LOCK_MANAGER_RESOURCE_SHARED) + priv->resources[priv->nresources-1].flags |=3D + VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED; + + if (autoCreate) + priv->resources[priv->nresources-1].flags |=3D + VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE; =20 ret =3D 0; cleanup: diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index b10d8197c5..86efc83b5a 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -811,7 +811,7 @@ static int virLockManagerSanlockAddResource(virLockMana= gerPtr lock, if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY) return 0; =20 - switch ((virLockManagerResourceType) type) { + switch (type) { case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK: if (driver->autoDiskLease) { if (virLockManagerSanlockAddDisk(driver, lock, name, nparams, = params, @@ -835,7 +835,6 @@ static int virLockManagerSanlockAddResource(virLockMana= gerPtr lock, return -1; break; =20 - case VIR_LOCK_MANAGER_RESOURCE_TYPE_METADATA: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown lock manager object type %d for domain l= ock object"), --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200579436631.1908612121246; Wed, 14 Nov 2018 05:02:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA106307DAB7; Wed, 14 Nov 2018 13:02:57 +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 6B39461B96; Wed, 14 Nov 2018 13:02:57 +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 7038D4CAA8; Wed, 14 Nov 2018 13:02:52 +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 wAECj2GI026287 for ; Wed, 14 Nov 2018 07:45:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id DD2006E724; Wed, 14 Nov 2018 12:45:02 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 621A86E71E for ; Wed, 14 Nov 2018 12:45:02 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:40 +0100 Message-Id: <606b7f4a3a4f9cc59886e629a69d9941d4d7557a.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 12/15] Revert "_virLockManagerLockDaemonPrivate: Move @hasRWDisks into dom union" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 14 Nov 2018 13:02:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit aaf34cb9013d6d746f4edf9807408cb9dfbcf01d. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_driver_lockd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index 268676c407..22a5a97913 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -63,8 +63,6 @@ struct _virLockManagerLockDaemonPrivate { char *name; int id; pid_t pid; - - bool hasRWDisks; } dom; =20 struct { @@ -76,6 +74,8 @@ struct _virLockManagerLockDaemonPrivate { =20 size_t nresources; virLockManagerLockDaemonResourcePtr resources; + + bool hasRWDisks; }; =20 =20 @@ -585,7 +585,7 @@ static int virLockManagerLockDaemonAddResource(virLockM= anagerPtr lock, if (!driver->autoDiskLease) { if (!(flags & (VIR_LOCK_MANAGER_RESOURCE_SHARED | VIR_LOCK_MANAGER_RESOURCE_READONLY))) - priv->t.dom.hasRWDisks =3D true; + priv->hasRWDisks =3D true; return 0; } =20 @@ -731,7 +731,7 @@ static int virLockManagerLockDaemonAcquire(virLockManag= erPtr lock, =20 if (priv->type =3D=3D VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN && priv->nresources =3D=3D 0 && - priv->t.dom.hasRWDisks && + priv->hasRWDisks && driver->requireLeaseForDisks) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Read/write, exclusive access, disks were present= , but no leases specified")); --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200586237319.67848586988873; Wed, 14 Nov 2018 05:03:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4587F3078ABE; Wed, 14 Nov 2018 13:03:04 +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 11D605D738; Wed, 14 Nov 2018 13:03:04 +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 BC3334CAA8; Wed, 14 Nov 2018 13:03:03 +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 wAECj37v026297 for ; Wed, 14 Nov 2018 07:45:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id B61546E723; Wed, 14 Nov 2018 12:45:03 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 371EC6E71E for ; Wed, 14 Nov 2018 12:45:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:41 +0100 Message-Id: <1809a663e8c069fd657e0997ff44f07d01ffcae5.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 13/15] Revert "lock_driver: Introduce new VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 14 Nov 2018 13:03:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 22baf6e08c65d9174b24f66370724ce961ce9576. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_driver.h | 2 - src/locking/lock_driver_lockd.c | 297 +++++++++++------------------- src/locking/lock_driver_sanlock.c | 37 ++-- 3 files changed, 116 insertions(+), 220 deletions(-) diff --git a/src/locking/lock_driver.h b/src/locking/lock_driver.h index a9d2041c30..8b7cccc521 100644 --- a/src/locking/lock_driver.h +++ b/src/locking/lock_driver.h @@ -42,8 +42,6 @@ typedef enum { typedef enum { /* The managed object is a virtual guest domain */ VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN =3D 0, - /* The managed object is a daemon (e.g. libvirtd) */ - VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON =3D 1, } virLockManagerObjectType; =20 typedef enum { diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index 22a5a97913..ca825e6026 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -56,21 +56,10 @@ struct _virLockManagerLockDaemonResource { }; =20 struct _virLockManagerLockDaemonPrivate { - virLockManagerObjectType type; - union { - struct { - unsigned char uuid[VIR_UUID_BUFLEN]; - char *name; - int id; - pid_t pid; - } dom; - - struct { - unsigned char uuid[VIR_UUID_BUFLEN]; - char *name; - pid_t pid; - } daemon; - } t; + unsigned char uuid[VIR_UUID_BUFLEN]; + char *name; + int id; + pid_t pid; =20 size_t nresources; virLockManagerLockDaemonResourcePtr resources; @@ -167,30 +156,10 @@ virLockManagerLockDaemonConnectionRegister(virLockMan= agerPtr lock, memset(&args, 0, sizeof(args)); =20 args.flags =3D 0; - - switch (priv->type) { - case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: - memcpy(args.owner.uuid, priv->t.dom.uuid, VIR_UUID_BUFLEN); - args.owner.name =3D priv->t.dom.name; - args.owner.id =3D priv->t.dom.id; - args.owner.pid =3D priv->t.dom.pid; - break; - - case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON: - memcpy(args.owner.uuid, priv->t.daemon.uuid, VIR_UUID_BUFLEN); - args.owner.name =3D priv->t.daemon.name; - args.owner.pid =3D priv->t.daemon.pid; - /* This one should not be needed. However, virtlockd - * checks for ID because not every domain has a PID. */ - args.owner.id =3D priv->t.daemon.pid; - break; - - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown lock manager object type %d"), - priv->type); - return -1; - } + memcpy(args.owner.uuid, priv->uuid, VIR_UUID_BUFLEN); + args.owner.name =3D priv->name; + args.owner.id =3D priv->id; + args.owner.pid =3D priv->pid; =20 if (virNetClientProgramCall(program, client, @@ -422,18 +391,7 @@ virLockManagerLockDaemonPrivateFree(virLockManagerLock= DaemonPrivatePtr priv) } VIR_FREE(priv->resources); =20 - switch (priv->type) { - case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: - VIR_FREE(priv->t.dom.name); - break; - - case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON: - VIR_FREE(priv->t.daemon.name); - break; - - default: - break; - } + VIR_FREE(priv->name); VIR_FREE(priv); } =20 @@ -462,82 +420,46 @@ static int virLockManagerLockDaemonNew(virLockManager= Ptr lock, if (VIR_ALLOC(priv) < 0) return -1; =20 - priv->type =3D type; - - switch ((virLockManagerObjectType) type) { + switch (type) { case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: for (i =3D 0; i < nparams; i++) { if (STREQ(params[i].key, "uuid")) { - memcpy(priv->t.dom.uuid, params[i].value.uuid, VIR_UUID_BU= FLEN); + memcpy(priv->uuid, params[i].value.uuid, VIR_UUID_BUFLEN); } else if (STREQ(params[i].key, "name")) { - if (VIR_STRDUP(priv->t.dom.name, params[i].value.str) < 0) + if (VIR_STRDUP(priv->name, params[i].value.str) < 0) goto cleanup; } else if (STREQ(params[i].key, "id")) { - priv->t.dom.id =3D params[i].value.iv; + priv->id =3D params[i].value.iv; } else if (STREQ(params[i].key, "pid")) { - priv->t.dom.pid =3D params[i].value.iv; + priv->pid =3D params[i].value.iv; } else if (STREQ(params[i].key, "uri")) { /* ignored */ } else { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected parameter %s for domain objec= t"), + _("Unexpected parameter %s for object"), params[i].key); goto cleanup; } } - if (priv->t.dom.id =3D=3D 0) { + if (priv->id =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing ID parameter for domain object")); goto cleanup; } - if (priv->t.dom.pid =3D=3D 0) + if (priv->pid =3D=3D 0) VIR_DEBUG("Missing PID parameter for domain object"); - if (!priv->t.dom.name) { + if (!priv->name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing name parameter for domain object")); goto cleanup; } - if (!virUUIDIsValid(priv->t.dom.uuid)) { + if (!virUUIDIsValid(priv->uuid)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing UUID parameter for domain object")); goto cleanup; } break; =20 - case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON: - for (i =3D 0; i < nparams; i++) { - if (STREQ(params[i].key, "uuid")) { - memcpy(priv->t.daemon.uuid, params[i].value.uuid, VIR_UUID= _BUFLEN); - } else if (STREQ(params[i].key, "name")) { - if (VIR_STRDUP(priv->t.daemon.name, params[i].value.str) <= 0) - goto cleanup; - } else if (STREQ(params[i].key, "pid")) { - priv->t.daemon.pid =3D params[i].value.iv; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected parameter %s for daemon objec= t"), - params[i].key); - goto cleanup; - } - } - - if (!virUUIDIsValid(priv->t.daemon.uuid)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing UUID parameter for daemon object")); - goto cleanup; - } - if (!priv->t.daemon.name) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing name parameter for daemon object")); - goto cleanup; - } - if (priv->t.daemon.pid =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing PID parameter for daemon object")); - goto cleanup; - } - break; - default: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown lock manager object type %d"), @@ -572,119 +494,107 @@ static int virLockManagerLockDaemonAddResource(virL= ockManagerPtr lock, if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY) return 0; =20 - switch (priv->type) { - case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: + switch (type) { + case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK: + if (params || nparams) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpected parameters for disk resource")); + goto cleanup; + } + if (!driver->autoDiskLease) { + if (!(flags & (VIR_LOCK_MANAGER_RESOURCE_SHARED | + VIR_LOCK_MANAGER_RESOURCE_READONLY))) + priv->hasRWDisks =3D true; + return 0; + } =20 - switch (type) { - case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK: - if (params || nparams) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unexpected parameters for disk resource"= )); + /* XXX we should somehow pass in TYPE=3DBLOCK info + * from the domain_lock code, instead of assuming /dev + */ + if (STRPREFIX(name, "/dev") && + driver->lvmLockSpaceDir) { + VIR_DEBUG("Trying to find an LVM UUID for %s", name); + if (virStorageFileGetLVMKey(name, &newName) < 0) goto cleanup; - } - if (!driver->autoDiskLease) { - if (!(flags & (VIR_LOCK_MANAGER_RESOURCE_SHARED | - VIR_LOCK_MANAGER_RESOURCE_READONLY))) - priv->hasRWDisks =3D true; - return 0; - } =20 - /* XXX we should somehow pass in TYPE=3DBLOCK info - * from the domain_lock code, instead of assuming /dev - */ - if (STRPREFIX(name, "/dev") && - driver->lvmLockSpaceDir) { - VIR_DEBUG("Trying to find an LVM UUID for %s", name); - if (virStorageFileGetLVMKey(name, &newName) < 0) + if (newName) { + VIR_DEBUG("Got an LVM UUID %s for %s", newName, name); + if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) < 0) goto cleanup; - - if (newName) { - VIR_DEBUG("Got an LVM UUID %s for %s", newName, name); - if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) = < 0) - goto cleanup; - autoCreate =3D true; - break; - } - virResetLastError(); - /* Fallback to generic non-block code */ + autoCreate =3D true; + break; } + virResetLastError(); + /* Fallback to generic non-block code */ + } =20 - if (STRPREFIX(name, "/dev") && - driver->scsiLockSpaceDir) { - VIR_DEBUG("Trying to find an SCSI ID for %s", name); - if (virStorageFileGetSCSIKey(name, &newName) < 0) - goto cleanup; - - if (newName) { - VIR_DEBUG("Got an SCSI ID %s for %s", newName, name); - if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir)= < 0) - goto cleanup; - autoCreate =3D true; - break; - } - virResetLastError(); - /* Fallback to generic non-block code */ - } + if (STRPREFIX(name, "/dev") && + driver->scsiLockSpaceDir) { + VIR_DEBUG("Trying to find an SCSI ID for %s", name); + if (virStorageFileGetSCSIKey(name, &newName) < 0) + goto cleanup; =20 - if (driver->fileLockSpaceDir) { - if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0) - goto cleanup; - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &new= Name) < 0) + if (newName) { + VIR_DEBUG("Got an SCSI ID %s for %s", newName, name); + if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir) < 0) goto cleanup; autoCreate =3D true; - VIR_DEBUG("Using indirect lease %s for %s", newName, name); - } else { - if (VIR_STRDUP(newLockspace, "") < 0) - goto cleanup; - if (VIR_STRDUP(newName, name) < 0) - goto cleanup; - VIR_DEBUG("Using direct lease for %s", name); + break; } + virResetLastError(); + /* Fallback to generic non-block code */ + } =20 - break; - case VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE: { - size_t i; - char *path =3D NULL; - char *lockspace =3D NULL; - for (i =3D 0; i < nparams; i++) { - if (STREQ(params[i].key, "offset")) { - if (params[i].value.ul !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Offset must be zero for this loc= k manager")); - goto cleanup; - } - } else if (STREQ(params[i].key, "lockspace")) { - lockspace =3D params[i].value.str; - } else if (STREQ(params[i].key, "path")) { - path =3D params[i].value.str; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected parameter %s for lease re= source"), - params[i].key); - goto cleanup; - } - } - if (!path || !lockspace) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing path or lockspace for lease reso= urce")); + if (driver->fileLockSpaceDir) { + if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0) goto cleanup; - } - if (virAsprintf(&newLockspace, "%s/%s", - path, lockspace) < 0) + if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &newName= ) < 0) + goto cleanup; + autoCreate =3D true; + VIR_DEBUG("Using indirect lease %s for %s", newName, name); + } else { + if (VIR_STRDUP(newLockspace, "") < 0) goto cleanup; if (VIR_STRDUP(newName, name) < 0) goto cleanup; - - } break; - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown lock manager object type %d for doma= in lock object"), - type); - goto cleanup; + VIR_DEBUG("Using direct lease for %s", name); } + break; + case VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE: { + size_t i; + char *path =3D NULL; + char *lockspace =3D NULL; + for (i =3D 0; i < nparams; i++) { + if (STREQ(params[i].key, "offset")) { + if (params[i].value.ul !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Offset must be zero for this lock ma= nager")); + goto cleanup; + } + } else if (STREQ(params[i].key, "lockspace")) { + lockspace =3D params[i].value.str; + } else if (STREQ(params[i].key, "path")) { + path =3D params[i].value.str; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected parameter %s for lease resour= ce"), + params[i].key); + goto cleanup; + } + } + if (!path || !lockspace) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing path or lockspace for lease resource= ")); + goto cleanup; + } + if (virAsprintf(&newLockspace, "%s/%s", + path, lockspace) < 0) + goto cleanup; + if (VIR_STRDUP(newName, name) < 0) + goto cleanup; =20 - case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON: + } break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown lock manager object type %d"), @@ -729,8 +639,7 @@ static int virLockManagerLockDaemonAcquire(virLockManag= erPtr lock, virCheckFlags(VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY | VIR_LOCK_MANAGER_ACQUIRE_RESTRICT, -1); =20 - if (priv->type =3D=3D VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN && - priv->nresources =3D=3D 0 && + if (priv->nresources =3D=3D 0 && priv->hasRWDisks && driver->requireLeaseForDisks) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 86efc83b5a..ff0c9be8f7 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -509,32 +509,21 @@ static int virLockManagerSanlockNew(virLockManagerPtr= lock, =20 priv->flags =3D flags; =20 - switch ((virLockManagerObjectType) type) { - case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: - for (i =3D 0; i < nparams; i++) { - param =3D ¶ms[i]; + for (i =3D 0; i < nparams; i++) { + param =3D ¶ms[i]; =20 - if (STREQ(param->key, "uuid")) { - memcpy(priv->vm_uuid, param->value.uuid, 16); - } else if (STREQ(param->key, "name")) { - if (VIR_STRDUP(priv->vm_name, param->value.str) < 0) - goto error; - } else if (STREQ(param->key, "pid")) { - priv->vm_pid =3D param->value.iv; - } else if (STREQ(param->key, "id")) { - priv->vm_id =3D param->value.ui; - } else if (STREQ(param->key, "uri")) { - priv->vm_uri =3D param->value.cstr; - } + if (STREQ(param->key, "uuid")) { + memcpy(priv->vm_uuid, param->value.uuid, 16); + } else if (STREQ(param->key, "name")) { + if (VIR_STRDUP(priv->vm_name, param->value.str) < 0) + goto error; + } else if (STREQ(param->key, "pid")) { + priv->vm_pid =3D param->value.iv; + } else if (STREQ(param->key, "id")) { + priv->vm_id =3D param->value.ui; + } else if (STREQ(param->key, "uri")) { + priv->vm_uri =3D param->value.cstr; } - break; - - case VIR_LOCK_MANAGER_OBJECT_TYPE_DAEMON: - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown lock manager object type %d"), - type); - goto error; } =20 /* Sanlock needs process registration, but the only way how to probe --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542201484978332.2992813218998; Wed, 14 Nov 2018 05:18:04 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C63C280508; Wed, 14 Nov 2018 13:17:57 +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 9F07C5E25F; Wed, 14 Nov 2018 13:17:56 +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 6270C3D38F; Wed, 14 Nov 2018 13:17:52 +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 wAECj4NR026302 for ; Wed, 14 Nov 2018 07:45:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8B66F6E71E; Wed, 14 Nov 2018 12:45:04 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EE826E727 for ; Wed, 14 Nov 2018 12:45:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:42 +0100 Message-Id: <1d58fddd206901483c238040d6b2620ce1e15196.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 14/15] Revert "lock_driver_lockd: Introduce VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA flag" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 14 Nov 2018 13:18:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit 21c34b86be5233634eb38f77be64e2263bfc4e48. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_daemon_dispatch.c | 10 ++-------- src/locking/lock_driver_lockd.c | 3 +-- src/locking/lock_driver_lockd.h | 1 - 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_d= ispatch.c index a683ad3d6b..10248ec0b5 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -37,9 +37,6 @@ VIR_LOG_INIT("locking.lock_daemon_dispatch"); =20 #include "lock_daemon_dispatch_stubs.h" =20 -#define DEFAULT_OFFSET 0 -#define METADATA_OFFSET 1 - static int virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server ATTRIBU= TE_UNUSED, virNetServerClientPtr client, @@ -53,14 +50,13 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServe= rPtr server ATTRIBUTE_UNU virNetServerClientGetPrivateData(client); virLockSpacePtr lockspace; unsigned int newFlags; - off_t start =3D DEFAULT_OFFSET; + off_t start =3D 0; off_t len =3D 1; =20 virMutexLock(&priv->lock); =20 virCheckFlagsGoto(VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED | - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE | - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA, c= leanup); + VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE,= cleanup); =20 if (priv->restricted) { virReportError(VIR_ERR_OPERATION_DENIED, "%s", @@ -86,8 +82,6 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerP= tr server ATTRIBUTE_UNU newFlags |=3D VIR_LOCK_SPACE_ACQUIRE_SHARED; if (flags & VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE) newFlags |=3D VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE; - if (flags & VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA) - start =3D METADATA_OFFSET; =20 if (virLockSpaceAcquireResource(lockspace, args->name, diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index ca825e6026..16fce551c3 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -723,8 +723,7 @@ static int virLockManagerLockDaemonRelease(virLockManag= erPtr lock, =20 args.flags &=3D ~(VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED | - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE | - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA); + VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE); =20 if (virNetClientProgramCall(program, client, diff --git a/src/locking/lock_driver_lockd.h b/src/locking/lock_driver_lock= d.h index bebd804365..6931fe7425 100644 --- a/src/locking/lock_driver_lockd.h +++ b/src/locking/lock_driver_lockd.h @@ -25,7 +25,6 @@ enum virLockSpaceProtocolAcquireResourceFlags { VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED =3D (1 << 0), VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE =3D (1 << 1), - VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_METADATA =3D (1 << 2), }; =20 #endif /* __VIR_LOCK_DRIVER_LOCKD_H__ */ --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 16:49:16 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542200599262232.2272198135082; Wed, 14 Nov 2018 05:03:19 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C14988AE71; Wed, 14 Nov 2018 13:03:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52989608EE; Wed, 14 Nov 2018 13:03:16 +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 E983718005AD; Wed, 14 Nov 2018 13:03:15 +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 wAECjCdH026324 for ; Wed, 14 Nov 2018 07:45:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id BEEF36E727; Wed, 14 Nov 2018 12:45:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44AD56E731 for ; Wed, 14 Nov 2018 12:45:04 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Nov 2018 13:44:43 +0100 Message-Id: <1d4e0960113d1953c77e22408eb5ba7765935973.1542193371.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 15/15] Revert "virlockspace: Allow caller to specify start and length offset in virLockSpaceAcquireResource" 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 14 Nov 2018 13:03:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit afd5a27575e8b6a494d2728552fe0e89c71e32b4. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/locking/lock_daemon_dispatch.c | 3 --- src/util/virlockspace.c | 15 +++++---------- src/util/virlockspace.h | 4 ---- tests/virlockspacetest.c | 29 +++++------------------------ 4 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_d= ispatch.c index 10248ec0b5..1b479db55d 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -50,8 +50,6 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerP= tr server ATTRIBUTE_UNU virNetServerClientGetPrivateData(client); virLockSpacePtr lockspace; unsigned int newFlags; - off_t start =3D 0; - off_t len =3D 1; =20 virMutexLock(&priv->lock); =20 @@ -86,7 +84,6 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerP= tr server ATTRIBUTE_UNU if (virLockSpaceAcquireResource(lockspace, args->name, priv->ownerPid, - start, len, newFlags) < 0) goto cleanup; =20 diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 79fa48d365..0736b4b85b 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -115,10 +115,8 @@ static void virLockSpaceResourceFree(virLockSpaceResou= rcePtr res) static virLockSpaceResourcePtr virLockSpaceResourceNew(virLockSpacePtr lockspace, const char *resname, - pid_t owner, - off_t start, - off_t len, - unsigned int flags) + unsigned int flags, + pid_t owner) { virLockSpaceResourcePtr res; bool shared =3D !!(flags & VIR_LOCK_SPACE_ACQUIRE_SHARED); @@ -159,7 +157,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; } =20 - if (virFileLock(res->fd, shared, start, len, false) < 0) { + if (virFileLock(res->fd, shared, 0, 1, false) < 0) { if (errno =3D=3D EACCES || errno =3D=3D EAGAIN) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), @@ -206,7 +204,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; } =20 - if (virFileLock(res->fd, shared, start, len, false) < 0) { + if (virFileLock(res->fd, shared, 0, 1, false) < 0) { if (errno =3D=3D EACCES || errno =3D=3D EAGAIN) { virReportError(VIR_ERR_RESOURCE_BUSY, _("Lockspace resource '%s' is locked"), @@ -614,8 +612,6 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspac= e, int virLockSpaceAcquireResource(virLockSpacePtr lockspace, const char *resname, pid_t owner, - off_t start, - off_t len, unsigned int flags) { int ret =3D -1; @@ -645,8 +641,7 @@ int virLockSpaceAcquireResource(virLockSpacePtr lockspa= ce, goto cleanup; } =20 - if (!(res =3D virLockSpaceResourceNew(lockspace, resname, - owner, start, len, flags))) + if (!(res =3D virLockSpaceResourceNew(lockspace, resname, flags, owner= ))) goto cleanup; =20 if (virHashAddEntry(lockspace->resources, resname, res) < 0) { diff --git a/src/util/virlockspace.h b/src/util/virlockspace.h index 24f2c89be6..041cf20396 100644 --- a/src/util/virlockspace.h +++ b/src/util/virlockspace.h @@ -22,8 +22,6 @@ #ifndef __VIR_LOCK_SPACE_H__ # define __VIR_LOCK_SPACE_H__ =20 -# include - # include "internal.h" # include "virjson.h" =20 @@ -52,8 +50,6 @@ typedef enum { int virLockSpaceAcquireResource(virLockSpacePtr lockspace, const char *resname, pid_t owner, - off_t start, - off_t len, unsigned int flags); =20 int virLockSpaceReleaseResource(virLockSpacePtr lockspace, diff --git a/tests/virlockspacetest.c b/tests/virlockspacetest.c index 3c621e7eb0..93353be285 100644 --- a/tests/virlockspacetest.c +++ b/tests/virlockspacetest.c @@ -98,8 +98,6 @@ static int testLockSpaceResourceLockExcl(const void *args= ATTRIBUTE_UNUSED) { virLockSpacePtr lockspace; int ret =3D -1; - const off_t start =3D 0; - const off_t len =3D 1; =20 rmdir(LOCKSPACE_DIR); =20 @@ -112,13 +110,13 @@ static int testLockSpaceResourceLockExcl(const void *= args ATTRIBUTE_UNUSED) if (virLockSpaceCreateResource(lockspace, "foo") < 0) goto cleanup; =20 - if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), start, le= n, 0) < 0) + if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), 0) < 0) goto cleanup; =20 if (!virFileExists(LOCKSPACE_DIR "/foo")) goto cleanup; =20 - if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), start, le= n, 0) =3D=3D 0) + if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), 0) =3D=3D= 0) goto cleanup; =20 if (virLockSpaceDeleteResource(lockspace, "foo") =3D=3D 0) @@ -146,8 +144,6 @@ static int testLockSpaceResourceLockExclAuto(const void= *args ATTRIBUTE_UNUSED) { virLockSpacePtr lockspace; int ret =3D -1; - const off_t start =3D 0; - const off_t len =3D 1; =20 rmdir(LOCKSPACE_DIR); =20 @@ -161,7 +157,6 @@ static int testLockSpaceResourceLockExclAuto(const void= *args ATTRIBUTE_UNUSED) goto cleanup; =20 if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), - start, len, VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) < 0) goto cleanup; =20 @@ -187,8 +182,6 @@ static int testLockSpaceResourceLockShr(const void *arg= s ATTRIBUTE_UNUSED) { virLockSpacePtr lockspace; int ret =3D -1; - const off_t start =3D 0; - const off_t len =3D 1; =20 rmdir(LOCKSPACE_DIR); =20 @@ -202,16 +195,13 @@ static int testLockSpaceResourceLockShr(const void *a= rgs ATTRIBUTE_UNUSED) goto cleanup; =20 if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), - start, len, VIR_LOCK_SPACE_ACQUIRE_SHARED) < 0) goto cleanup; =20 - if (virLockSpaceAcquireResource(lockspace, "foo", - geteuid(), start, len, 0) =3D=3D 0) + if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), 0) =3D=3D= 0) goto cleanup; =20 if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), - start, len, VIR_LOCK_SPACE_ACQUIRE_SHARED) < 0) goto cleanup; =20 @@ -246,8 +236,6 @@ static int testLockSpaceResourceLockShrAuto(const void = *args ATTRIBUTE_UNUSED) { virLockSpacePtr lockspace; int ret =3D -1; - const off_t start =3D 0; - const off_t len =3D 1; =20 rmdir(LOCKSPACE_DIR); =20 @@ -261,7 +249,6 @@ static int testLockSpaceResourceLockShrAuto(const void = *args ATTRIBUTE_UNUSED) goto cleanup; =20 if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), - start, len, VIR_LOCK_SPACE_ACQUIRE_SHARED | VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) < 0) goto cleanup; @@ -270,7 +257,6 @@ static int testLockSpaceResourceLockShrAuto(const void = *args ATTRIBUTE_UNUSED) goto cleanup; =20 if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), - start, len, VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) =3D= =3D 0) goto cleanup; =20 @@ -278,7 +264,6 @@ static int testLockSpaceResourceLockShrAuto(const void = *args ATTRIBUTE_UNUSED) goto cleanup; =20 if (virLockSpaceAcquireResource(lockspace, "foo", geteuid(), - start, len, VIR_LOCK_SPACE_ACQUIRE_SHARED | VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) < 0) goto cleanup; @@ -311,8 +296,6 @@ static int testLockSpaceResourceLockPath(const void *ar= gs ATTRIBUTE_UNUSED) { virLockSpacePtr lockspace; int ret =3D -1; - const off_t start =3D 0; - const off_t len =3D 1; =20 rmdir(LOCKSPACE_DIR); =20 @@ -325,15 +308,13 @@ static int testLockSpaceResourceLockPath(const void *= args ATTRIBUTE_UNUSED) if (virLockSpaceCreateResource(lockspace, LOCKSPACE_DIR "/foo") < 0) goto cleanup; =20 - if (virLockSpaceAcquireResource(lockspace, LOCKSPACE_DIR "/foo", - geteuid(), start, len, 0) < 0) + if (virLockSpaceAcquireResource(lockspace, LOCKSPACE_DIR "/foo", geteu= id(), 0) < 0) goto cleanup; =20 if (!virFileExists(LOCKSPACE_DIR "/foo")) goto cleanup; =20 - if (virLockSpaceAcquireResource(lockspace, LOCKSPACE_DIR "/foo", - geteuid(), start, len, 0) =3D=3D 0) + if (virLockSpaceAcquireResource(lockspace, LOCKSPACE_DIR "/foo", geteu= id(), 0) =3D=3D 0) goto cleanup; =20 if (virLockSpaceDeleteResource(lockspace, LOCKSPACE_DIR "/foo") =3D=3D= 0) --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list