From patchwork Fri Oct 25 17:05:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11212723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DE9513BD for ; Fri, 25 Oct 2019 17:06:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E98D72084C for ; Fri, 25 Oct 2019 17:06:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="K8P5vqr/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E98D72084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31T-0000D0-6t; Fri, 25 Oct 2019 17:05:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO31R-0000Ch-Tv for xen-devel@lists.xenproject.org; Fri, 25 Oct 2019 17:05:09 +0000 X-Inumbo-ID: 9907aa56-f749-11e9-8aca-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9907aa56-f749-11e9-8aca-bc764e2007e4; Fri, 25 Oct 2019 17:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572023108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eQNKxqrS2zcY6hc8GgmyvHkuncNCP0wD6X8ZyfLhupM=; b=K8P5vqr/ZbPW6SBuCy0A3lAeGb2FUcprbFtAs+4znO5jE221vCl4TlXr dJm8QNDpD0TqV7Ibu1xwH6jMpsjhekc6uFu3X9AKHjAnM1IWNCSsyXMn+ PXfLB7/vw4NcAO3o9qVhnSpZjqelmlAWcsPuZIZUeP3dpjzJDa/Y22r3F o=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: JR+eR7ViY7qRP2OcH3NO3hK9tS1Tg6nXawQvB7pU2Bj3QHKO57fYArKTMK5F3ZowaaL5k/d0iQ cUPmJMEVaGix/fBiZaBiDeENbl1WjAITM07iD7XM+rjrsdaATl74V975tZFDwZ/ib4xK44P7x+ hCI0LY7WAFZmWdh4PDOnDaJEzXjhXOnP2NIQEWmPkLRHWp1HfRjE+tnRFZOWUeqayA+BVOoR2Q iLGr8TiZGL2/GG9WzpTPzEmzxBj1zoIKvtvB7XgwxBpMtN3n7O94HgAi2JhGFWaFw6t0acyAnM dbM= X-SBRS: 2.7 X-MesageID: 7801960 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.68,229,1569297600"; d="scan'208";a="7801960" From: Anthony PERARD To: Date: Fri, 25 Oct 2019 18:05:03 +0100 Message-ID: <20191025170505.2834957-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191025170505.2834957-1-anthony.perard@citrix.com> References: <20191025170505.2834957-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC XEN PATCH for-4.13 2/4] libxl: Introduce libxl__ev_qmplock X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This lock will be used to prevent concurrent access the QEMU's QMP socket. It is based on libxl__ev_devlock implementation and have the same properties. There is one addition to the ev_devlock API, libxl__ev_qmplock_dispose, which allow to cancel the lock operation while it is in Active state. Signed-off-by: Anthony PERARD --- tools/libxl/libxl_internal.c | 31 ++++++++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 0750b69cba61..afbb01c5722f 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -583,17 +583,25 @@ void libxl__ev_devlock_init(libxl__ev_devlock *lock) lock->held = false; } +static void ev_lock_lock(libxl__egc *egc, libxl__ev_devlock *lock, + const char *userdata_userid); static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock); static void ev_lock_child_callback(libxl__egc *egc, libxl__ev_child *child, pid_t pid, int status); void libxl__ev_devlock_lock(libxl__egc *egc, libxl__ev_devlock *lock) +{ + ev_lock_lock(egc, lock, "libxl-device-changes-lock"); +} + +static void ev_lock_lock(libxl__egc *egc, libxl__ev_devlock *lock, + const char *userdata_userid) { STATE_AO_GC(lock->ao); const char *lockfile; lockfile = libxl__userdata_path(gc, lock->domid, - "libxl-device-changes-lock", "l"); + userdata_userid, "l"); if (!lockfile) goto out; lock->path = libxl__strdup(NOGC, lockfile); @@ -757,6 +765,27 @@ void libxl__ev_devlock_unlock(libxl__gc *gc, libxl__ev_devlock *lock) libxl__ev_devlock_init(lock); } +void libxl__ev_qmplock_init(libxl__ev_qmplock *lock) +{ + libxl__ev_devlock_init(lock); +} + +void libxl__ev_qmplock_lock(libxl__egc *egc, libxl__ev_qmplock *lock) +{ + ev_lock_lock(egc, lock, "qmp-socket-lock"); +} + +void libxl__ev_qmplock_unlock(libxl__gc *gc, libxl__ev_qmplock *lock) +{ + libxl__ev_devlock_unlock(gc, lock); +} + +void libxl__ev_qmplock_dispose(libxl__gc *gc, libxl__ev_qmplock *lock) +{ + libxl__ev_child_kill(lock->ao, &lock->child); + libxl__ev_devlock_unlock(gc, lock); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 5823890703ad..115c79d034d4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -197,6 +197,7 @@ typedef struct libxl__device_type libxl__device_type; typedef struct libxl__json_object libxl__json_object; typedef struct libxl__carefd libxl__carefd; typedef struct libxl__ev_devlock libxl__ev_devlock; +typedef struct libxl__ev_devlock libxl__ev_qmplock; typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__ao_device libxl__ao_device; typedef struct libxl__multidev libxl__multidev; @@ -4725,6 +4726,19 @@ _hidden void libxl__ev_devlock_init(libxl__ev_devlock *); _hidden void libxl__ev_devlock_lock(libxl__egc *, libxl__ev_devlock *); _hidden void libxl__ev_devlock_unlock(libxl__gc *, libxl__ev_devlock *); +/* libxl__ev_qmplock + * + * See "Lock for device hotplug, qmp_lock." as it is similar but is used + * to regulate access the QEMU's QMP socket. + * + * libxl__ev_qmplock_dispose: Idle/Active/LockAcquired -> Idle + * The callback will not be called anymore. + */ +_hidden void libxl__ev_qmplock_init(libxl__ev_qmplock *); +_hidden void libxl__ev_qmplock_lock(libxl__egc *, libxl__ev_qmplock *); +_hidden void libxl__ev_qmplock_unlock(libxl__gc *, libxl__ev_qmplock *); +_hidden void libxl__ev_qmplock_dispose(libxl__gc *, libxl__ev_qmplock *); + /* Send control commands over xenstore and wait for an Ack. */ _hidden int libxl__domain_pvcontrol(libxl__egc *egc, libxl__xswait_state *pvcontrol,