From patchwork Wed Oct 30 18:07:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11219909 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 7F0861390 for ; Wed, 30 Oct 2019 18:08:53 +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 4D91E2087E for ; Wed, 30 Oct 2019 18:08:53 +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="OHP3O1JI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D91E2087E 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 1iPsNV-0003aO-DX; Wed, 30 Oct 2019 18:07:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iPsNU-0003a0-Hn for xen-devel@lists.xenproject.org; Wed, 30 Oct 2019 18:07:28 +0000 X-Inumbo-ID: 17681b5c-fb40-11e9-9534-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 17681b5c-fb40-11e9-9534-12813bfff9fa; Wed, 30 Oct 2019 18:07:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572458830; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0dWefj4/+b8rbkVlOsUUbwQY0QNVR+1RMsxu4gErpjo=; b=OHP3O1JILDZ71whQAJBS5zY8a17Er7H/l0UMI/83SnCWduSRmOrwzq/L KEUyhbF96/xB9oxTekSLltBxyMjMyrFW7HceAFS9+KA9c7mt0NVDIzK41 og2EBewK6P2Uu3Fd2WHybFXZ+dn9/kZ+XppGyVh9VJ6WhSylnv0I1tLr6 Q=; Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: FCq58AD39Og94oeVKwynXkjn320R/1xN0wWMWqAEsKQynlsRmxuqvu2B9jHTa1pLgZxxphBYU1 PW2ilTGqZccnMDI4j5sVD5WjfJhvo7H2r7w7bvEfLTMMf8yYGnoOGsD/ZODzFAgzpWS5/dIyao 75gpWrw+LFC91KYfZaCVOrdq23PthYQem8H17GrqYdDUlqqWGGswWGx0VF+7RK6pdN8B8pDWa3 Z/48HIvpe7UHQT8WXy+VS8SUN3yBochqg97ng+A/vHe+XoKIh5zrD7ZWpi9F7IAb8hLNaW+TvT MDs= X-SBRS: 2.7 X-MesageID: 7739502 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.68,248,1569297600"; d="scan'208";a="7739502" From: Anthony PERARD To: Date: Wed, 30 Oct 2019 18:07:01 +0000 Message-ID: <20191030180704.261320-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191030180704.261320-1-anthony.perard@citrix.com> References: <20191030180704.261320-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v2 3/6] libxl: Rename ev_devlock to ev_slowlock 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 , =?utf-8?b?SsO8cmdlbiBHcm8=?= =?utf-8?b?w58=?= , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We are going to introduce a different lock based on the same implementation as the ev_devlock but with a different path. The different slowlock will be differentiated by calling different _init() functions. So we rename libxl__ev_devlock to lib__ev_slowlock, but keep libxl__ev_devlock_init(). Some log messages produced ev_slowlock are changed to print the name of the lock file (userdata_userid). Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- Notes: New patch in v2. Instead of introducing many libxl__ev_qmplock*. tools/libxl/libxl_disk.c | 10 +++++----- tools/libxl/libxl_domain.c | 10 +++++----- tools/libxl/libxl_internal.c | 30 +++++++++++++++++++----------- tools/libxl/libxl_internal.h | 33 +++++++++++++++++---------------- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index 733ad284c866..77ae3a59bfb6 100644 --- a/tools/libxl/libxl_disk.c +++ b/tools/libxl/libxl_disk.c @@ -648,13 +648,13 @@ typedef struct { libxl_domid domid; libxl_device_disk *disk; libxl_device_disk disk_saved; - libxl__ev_devlock qmp_lock; + libxl__ev_slowlock qmp_lock; int dm_ver; libxl__ev_time time; libxl__ev_qmp qmp; } libxl__cdrom_insert_state; -static void cdrom_insert_lock_acquired(libxl__egc *, libxl__ev_devlock *, +static void cdrom_insert_lock_acquired(libxl__egc *, libxl__ev_slowlock *, int rc); static void cdrom_insert_ejected(libxl__egc *egc, libxl__ev_qmp *, const libxl__json_object *, int rc); @@ -746,13 +746,13 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, cdrom_insert_done(egc, cis, rc); /* must be last */ } else { cis->qmp_lock.callback = cdrom_insert_lock_acquired; - libxl__ev_devlock_lock(egc, &cis->qmp_lock); /* must be last */ + libxl__ev_slowlock_lock(egc, &cis->qmp_lock); /* must be last */ } return AO_INPROGRESS; } static void cdrom_insert_lock_acquired(libxl__egc *egc, - libxl__ev_devlock *lock, + libxl__ev_slowlock *lock, int rc) { libxl__cdrom_insert_state *cis = CONTAINER_OF(lock, *cis, qmp_lock); @@ -1052,7 +1052,7 @@ static void cdrom_insert_done(libxl__egc *egc, libxl__ev_time_deregister(gc, &cis->time); libxl__ev_qmp_dispose(gc, &cis->qmp); if (cis->qmp.payload_fd >= 0) close(cis->qmp.payload_fd); - libxl__ev_devlock_unlock(gc, &cis->qmp_lock); + libxl__ev_slowlock_unlock(gc, &cis->qmp_lock); libxl_device_disk_dispose(&cis->disk_saved); libxl__ao_complete(egc, cis->ao, rc); } diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 9d0eb5aed11d..84ebfcceb83e 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1874,12 +1874,12 @@ typedef struct { libxl__ev_qmp qmp; libxl__ev_time timeout; libxl_domain_config *d_config; /* user pointer */ - libxl__ev_devlock devlock; + libxl__ev_slowlock devlock; libxl_bitmap qemuu_cpus; } retrieve_domain_configuration_state; static void retrieve_domain_configuration_lock_acquired( - libxl__egc *egc, libxl__ev_devlock *, int rc); + libxl__egc *egc, libxl__ev_slowlock *, int rc); static void retrieve_domain_configuration_cpu_queried( libxl__egc *egc, libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); @@ -1907,12 +1907,12 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, rdcs->devlock.ao = ao; rdcs->devlock.domid = domid; rdcs->devlock.callback = retrieve_domain_configuration_lock_acquired; - libxl__ev_devlock_lock(egc, &rdcs->devlock); + libxl__ev_slowlock_lock(egc, &rdcs->devlock); return AO_INPROGRESS; } static void retrieve_domain_configuration_lock_acquired( - libxl__egc *egc, libxl__ev_devlock *devlock, int rc) + libxl__egc *egc, libxl__ev_slowlock *devlock, int rc) { retrieve_domain_configuration_state *rdcs = CONTAINER_OF(devlock, *rdcs, devlock); @@ -2202,7 +2202,7 @@ static void retrieve_domain_configuration_end(libxl__egc *egc, } out: - libxl__ev_devlock_unlock(gc, &rdcs->devlock); + libxl__ev_slowlock_unlock(gc, &rdcs->devlock); if (lock) libxl__unlock_domain_userdata(lock); libxl_bitmap_dispose(&rdcs->qemuu_cpus); libxl__ev_qmp_dispose(gc, &rdcs->qmp); diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 0750b69cba61..9520ac36149e 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -575,25 +575,32 @@ void libxl__update_domain_configuration(libxl__gc *gc, dst->b_info.video_memkb = src->b_info.video_memkb; } -void libxl__ev_devlock_init(libxl__ev_devlock *lock) +static void ev_slowlock_init_internal(libxl__ev_slowlock *lock, + const char *userdata_userid) { libxl__ev_child_init(&lock->child); + lock->userdata_userid = userdata_userid; lock->path = NULL; lock->fd = -1; lock->held = false; } -static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock); +void libxl__ev_devlock_init(libxl__ev_slowlock *lock) +{ + ev_slowlock_init_internal(lock, "libxl-device-changes-lock"); +} + +static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_slowlock *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) +void libxl__ev_slowlock_lock(libxl__egc *egc, libxl__ev_slowlock *lock) { STATE_AO_GC(lock->ao); const char *lockfile; lockfile = libxl__userdata_path(gc, lock->domid, - "libxl-device-changes-lock", "l"); + lock->userdata_userid, "l"); if (!lockfile) goto out; lock->path = libxl__strdup(NOGC, lockfile); @@ -603,7 +610,7 @@ void libxl__ev_devlock_lock(libxl__egc *egc, libxl__ev_devlock *lock) lock->callback(egc, lock, ERROR_LOCK_FAIL); } -static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock) +static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_slowlock *lock) { STATE_AO_GC(lock->ao); pid_t pid; @@ -670,7 +677,7 @@ static void ev_lock_prepare_fork(libxl__egc *egc, libxl__ev_devlock *lock) libxl_fd_set_cloexec(CTX, fd, 1); return; out: - libxl__ev_devlock_unlock(gc, lock); + libxl__ev_slowlock_unlock(gc, lock); lock->callback(egc, lock, ERROR_LOCK_FAIL); } @@ -678,7 +685,7 @@ static void ev_lock_child_callback(libxl__egc *egc, libxl__ev_child *child, pid_t pid, int status) { EGC_GC; - libxl__ev_devlock *lock = CONTAINER_OF(child, *lock, child); + libxl__ev_slowlock *lock = CONTAINER_OF(child, *lock, child); struct stat stab, fstab; int rc = ERROR_LOCK_FAIL; @@ -726,13 +733,14 @@ static void ev_lock_child_callback(libxl__egc *egc, libxl__ev_child *child, rc = ERROR_LOCK_FAIL; } if (rc) { - LOGD(ERROR, domid, "Failed to grab qmp-lock"); - libxl__ev_devlock_unlock(gc, lock); + LOGD(ERROR, domid, "Failed to grab lock for %s", + lock->userdata_userid); + libxl__ev_slowlock_unlock(gc, lock); } lock->callback(egc, lock, rc); } -void libxl__ev_devlock_unlock(libxl__gc *gc, libxl__ev_devlock *lock) +void libxl__ev_slowlock_unlock(libxl__gc *gc, libxl__ev_slowlock *lock) { int r; @@ -754,7 +762,7 @@ void libxl__ev_devlock_unlock(libxl__gc *gc, libxl__ev_devlock *lock) close(lock->fd); } free(lock->path); - libxl__ev_devlock_init(lock); + ev_slowlock_init_internal(lock, lock->userdata_userid); } /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 69d572c1866a..a0f99252c39c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -196,7 +196,7 @@ typedef struct libxl__osevent_hook_nexi libxl__osevent_hook_nexi; 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_slowlock libxl__ev_slowlock; typedef struct libxl__dm_resume_state libxl__dm_resume_state; typedef struct libxl__ao_device libxl__ao_device; typedef struct libxl__multidev libxl__multidev; @@ -366,7 +366,7 @@ struct libxl__ev_child { /* * Lock for device hotplug, qmp_lock. * - * libxl__ev_devlock implement a lock that is outside of CTX_LOCK in the + * libxl__ev_slowlock implement a lock that is outside of CTX_LOCK in the * lock hierarchy. It can be used when one want to make QMP calls to QEMU, * which may take a significant amount time. * It is to be acquired by an ao event callback. @@ -374,42 +374,43 @@ struct libxl__ev_child { * It is to be acquired when adding/removing devices or making changes * to them when this is a slow operation and json_lock isn't appropriate. * - * Possible states of libxl__ev_devlock: + * Possible states of libxl__ev_slowlock: * Undefined * Might contain anything. * Idle * Struct contents are defined enough to pass to any - * libxl__ev_devlock_* function. + * libxl__ev_slowlock_* function. * The struct does not contain references to any allocated private * resources so can be thrown away. * Active * Waiting to get a lock. * Needs to wait until the callback is called. * LockAcquired - * libxl__ev_devlock_unlock will need to be called to release the lock - * and the resources of libxl__ev_devlock. + * libxl__ev_slowlock_unlock will need to be called to release the lock + * and the resources of libxl__ev_slowlock. * - * libxl__ev_devlock_init: Undefined/Idle -> Idle - * libxl__ev_devlock_lock: Idle -> Active + * libxl__ev_*lock_init: Undefined/Idle -> Idle + * libxl__ev_slowlock_lock: Idle -> Active * May call callback synchronously. - * libxl__ev_devlock_unlock: LockAcquired/Idle -> Idle + * libxl__ev_slowlock_unlock: LockAcquired/Idle -> Idle * callback: When called: Active -> LockAcquired (on error: Idle) * The callback is only called once. */ -struct libxl__ev_devlock { +struct libxl__ev_slowlock { /* filled by user */ libxl__ao *ao; libxl_domid domid; - void (*callback)(libxl__egc *, libxl__ev_devlock *, int rc); - /* private to libxl__ev_devlock* */ + void (*callback)(libxl__egc *, libxl__ev_slowlock *, int rc); + /* private to libxl__ev_slowlock* */ libxl__ev_child child; + const char *userdata_userid; char *path; /* path of the lock file itself */ int fd; bool held; }; -_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 *); +_hidden void libxl__ev_devlock_init(libxl__ev_slowlock *); +_hidden void libxl__ev_slowlock_lock(libxl__egc *, libxl__ev_slowlock *); +_hidden void libxl__ev_slowlock_unlock(libxl__gc *, libxl__ev_slowlock *); /* * QMP asynchronous calls @@ -2853,7 +2854,7 @@ struct libxl__multidev { * unlock json config * * Or in case QEMU is the primary config, this pattern can be use: - * qmp_lock (libxl__ev_devlock) + * qmp_lock (libxl__ev_devlock_init) * lock json config (json_lock) * read json config * update in-memory json config with new entry, replacing