From nobody Sun Feb 8 14:59:45 2026 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516291516015675.3979949414585; Thu, 18 Jan 2018 08:05:16 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 404F14E918; Thu, 18 Jan 2018 16:05:14 +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 14DD318A5F; Thu, 18 Jan 2018 16:05:14 +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 CEBBB18033DB; Thu, 18 Jan 2018 16:05:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0IG5Cws023717 for ; Thu, 18 Jan 2018 11:05:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0254A171E5; Thu, 18 Jan 2018 16:05:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84CA851895; Thu, 18 Jan 2018 16:05:01 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 18 Jan 2018 17:04:36 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: pbonzini@redhat.com Subject: [libvirt] [PATCH 04/14] qemu_domain: Introduce qemuDomainDiskPRObject 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 18 Jan 2018 16:05:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is an extended definition of virStoragePRDef because it contains runtime information (like path to pr helper socket, its pid and alias). Since these are driver dependant we should have a driver specific structure instead of putting all of that into driver agnostic structure. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 120 +++++++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_domain.h | 18 ++++++++ 2 files changed, 138 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e8539dcab..7fa8c93b7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -65,6 +65,7 @@ #endif #include #include +#include #if defined(HAVE_SYS_MOUNT_H) # include #endif @@ -1829,6 +1830,9 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) =20 virBitmapFree(priv->migrationCaps); priv->migrationCaps =3D NULL; + + virHashFree(priv->prHelpers); + priv->prHelpers =3D NULL; } =20 =20 @@ -10917,6 +10921,122 @@ qemuDomainCheckMigrationCapabilities(virQEMUDrive= rPtr driver, } =20 =20 +static void +qemuDomainDiskPRObjectHashFree(void *payload, + const void *name) +{ + qemuDomainDiskPRObjectPtr tmp =3D payload; + + if (tmp->managed && + tmp->pid !=3D (pid_t) -1) { + VIR_DEBUG("Forcibly killing pr-manager: %s", (const char *) name); + virProcessKillPainfully(tmp->pid, true); + } + VIR_FREE(tmp->path); + VIR_FREE(tmp); +} + + +/** + * qemuDomainDiskPRObjectRegister: + * @priv: Domain private data + * @alias: alias of the pr-manager object + * @managed: true if pr-managed object is manged by libvirt + * @path: socket path for the pr-manager object + * + * Records [alias, managed, path] tuple for pr-manager objects. + * On successful return @path is stolen and set to NULL. + * + * Returns 0 on success (with @path stolen), + * -1 otherwise (with error reported). + */ +int +qemuDomainDiskPRObjectRegister(qemuDomainObjPrivatePtr priv, + const char *alias, + bool managed, + char **path) +{ + qemuDomainDiskPRObjectPtr tmp; + int ret =3D -1; + + if (!priv->prHelpers && + !(priv->prHelpers =3D virHashCreate(10, qemuDomainDiskPRObjectHash= Free))) + return -1; + + if ((tmp =3D virHashLookup(priv->prHelpers, alias))) { + /* Entry exists, check if it matches path. This shouldn't + * happen, but it's better to be safe than sorry. */ + if (STRNEQ(tmp->path, *path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("trying to change path for pr helper object")= ); + + return -1; + } + + /* Claim success */ + VIR_FREE(*path); + return 0; + } + + if (VIR_ALLOC(tmp) < 0) + goto cleanup; + + tmp->managed =3D managed, + tmp->path =3D *path; + tmp->pid =3D (pid_t) -1; + + if (virHashAddEntry(priv->prHelpers, alias, tmp) < 0) + goto cleanup; + + *path =3D NULL; + tmp =3D NULL; + ret =3D 0; + cleanup: + VIR_FREE(tmp); + return ret; +} + + +static int +qemuDomainDiskPRObjectKillOne(void *payload, + const void *name, + void *data ATTRIBUTE_UNUSED) +{ + qemuDomainDiskPRObjectPtr tmp =3D payload; + + if (!tmp->managed) + return 0; + + VIR_DEBUG("Killing pr-manager: %s", (const char *) name); + if (tmp->pid !=3D (pid_t) -1 && + virProcessKill(tmp->pid, SIGTERM) < 0) { + virReportSystemError(errno, + _("Unable to kill pr-manager: %s"), + (const char *) name); + /* Don't return error; we want to kill as many as + * possible. */ + } else { + tmp->pid =3D (pid_t) -1; + } + + return 0; +} + + +void +qemuDomainDiskPRObjectKillAll(qemuDomainObjPrivatePtr priv) +{ + if (!priv->prHelpers) + return; + + virHashForEach(priv->prHelpers, + qemuDomainDiskPRObjectKillOne, NULL); + + virHashFree(priv->prHelpers); + priv->prHelpers =3D NULL; +} + + int qemuDomainPrepareDiskSource(virConnectPtr conn, virDomainDiskDefPtr disk, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index ddfc46dcd..f741f3039 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -329,6 +329,8 @@ struct _qemuDomainObjPrivate { /* Migration capabilities. Rechecked on reconnect, not to be saved in * private XML. */ virBitmapPtr migrationCaps; + + virHashTablePtr prHelpers; }; =20 # define QEMU_DOMAIN_PRIVATE(vm) \ @@ -990,4 +992,20 @@ qemuDomainPrepareDiskSource(virConnectPtr conn, qemuDomainObjPrivatePtr priv, virQEMUDriverConfigPtr cfg); =20 +typedef struct _qemuDomainDiskPRObject qemuDomainDiskPRObject; +typedef qemuDomainDiskPRObject *qemuDomainDiskPRObjectPtr; +struct _qemuDomainDiskPRObject { + bool managed; + char *path; /* socket path */ + pid_t pid; /* daemon pid */ +}; + +int +qemuDomainDiskPRObjectRegister(qemuDomainObjPrivatePtr priv, + const char *alias, + bool managed, + char **path); +void +qemuDomainDiskPRObjectKillAll(qemuDomainObjPrivatePtr priv); + #endif /* __QEMU_DOMAIN_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list