From nobody Tue Nov 11 08:50:24 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1569324821; cv=none; d=zoho.com; s=zohoarc; b=kjZ/T7DiL7ybKAzRxZv7fIlmCrXU3DBcuPiPV0YRuHUEUGRdgNXf0RObK866mazCdxc+0LPrKTKl2fsDcZzT0Lksev2abadc0sw7dLPj39ijhjAkqxfuR06PGejU0EH3OsYwpttrV4rAQ1WqlNdMPHohtlLdkdKQOicYNGSaOBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569324821; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FVL0UWEIovl6vsCh7zDAhRAIEm//jvyKY/wKJeGukUk=; b=PH2egdq8h4ecmUehmM9f9yi+a9fNg7/iDjt3h/8bUuwaZICLr90tEWU6bc3zJVig5d+NBVYPAR9qagqK43bJ3KmsZGyjduRzpqTgs1KNzlqyqAJ+0Aw9xoNzBZ0G+YNqRepKt0w7IqZ9luAsv+LTUn3b9BtXzg8XnCyXs0m8tVw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1569324821856848.1376503486482; Tue, 24 Sep 2019 04:33:41 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCj2M-00074K-8L; Tue, 24 Sep 2019 11:31:18 +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 1iCj2K-00073c-B9 for xen-devel@lists.xenproject.org; Tue, 24 Sep 2019 11:31:16 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by localhost (Halon) with ESMTPS id d05226a7-debe-11e9-9616-12813bfff9fa; Tue, 24 Sep 2019 11:31:15 +0000 (UTC) X-Inumbo-ID: d05226a7-debe-11e9-9616-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1569324676; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7L6iSgcHG/c+uve0NKelK5BctXcMVLX+wsTXUpwg2PA=; b=gVWMdnSXOgGum1hsw5KwBAploLA8Rud/jqxnz2hZtnpCgDSjJodQVWkC IwtdP4dyXjfUBPA5RXlWQosviuw4qJZCQQc2ZyosW5PE/6D8Jn2E8R+ww tJtU+SV8T+t2SO9rXZVGDovmNBmtooKRSzCPM9SYLiXDZi6emDVfUXaKA U=; Authentication-Results: esa2.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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.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=esa2.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 ~all" Received-SPF: None (esa2.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=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: HuWOP7dnM3Q5DQaZOixldM+ggIx6YQ8di8TGOZIxjE0xodRTpU2ECA9uQ5jwpR4v0zam/B367q OFq+z1960EFxc3QQWuD22sz+710TD+SwIt0hCX+uZm5mbXQ9yQD6kEy18GOjoc7PWKR2lihvOl 1sipdwWFjKpYa/hInkpnU1OcKxzx+IhdylJxQF7qLaO6rwzR7nBMSHdZHHFlla0NY+e37SQNgm DXtBCucEgT1/choIucV+rh1zb+U3gMlLZOMtHC8pZlBcueBBs5aOtrI8EarOAeTg3fhhbG8keC MKE= X-SBRS: 2.7 X-MesageID: 5977597 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,543,1559534400"; d="scan'208";a="5977597" From: Anthony PERARD To: Date: Tue, 24 Sep 2019 12:30:21 +0100 Message-ID: <20190924113026.255634-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190924113026.255634-1-anthony.perard@citrix.com> References: <20190924113026.255634-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PULL 2/7] xen / notify: introduce a new XenWatchList abstraction 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 , xen-devel@lists.xenproject.org, Peter Maydell Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Paul Durrant Xenstore watch call-backs are already abstracted away from XenBus using the XenWatch data structure but the associated NotifierList manipulation and file handle registration is still open coded in various xen_bus_...() functions. This patch creates a new XenWatchList data structure to allow these interactions to be abstracted away from XenBus as well. This is in preparation for a subsequent patch which will introduce separate watch lists for XenBus and XenDevice objects. NOTE: This patch also introduces a new notifier_list_empty() helper function for the purposes of adding an assertion that a XenWatchList is not freed whilst its associated NotifierList is still occupied. Signed-off-by: Paul Durrant Reviewed-by: Anthony Perard Message-Id: <20190913082159.31338-2-paul.durrant@citrix.com> Signed-off-by: Anthony PERARD --- hw/xen/trace-events | 5 +- hw/xen/xen-bus.c | 117 +++++++++++++++++++++++++-------------- include/hw/xen/xen-bus.h | 3 +- include/qemu/notify.h | 2 + util/notify.c | 5 ++ 5 files changed, 87 insertions(+), 45 deletions(-) diff --git a/hw/xen/trace-events b/hw/xen/trace-events index bc82ecb1a5..ac8d9c20d2 100644 --- a/hw/xen/trace-events +++ b/hw/xen/trace-events @@ -19,9 +19,8 @@ xen_bus_unrealize(void) "" xen_bus_enumerate(void) "" xen_bus_type_enumerate(const char *type) "type: %s" xen_bus_backend_create(const char *type, const char *path) "type: %s path:= %s" -xen_bus_add_watch(const char *node, const char *key, char *token) "node: %= s key: %s token: %s" -xen_bus_remove_watch(const char *node, const char *key, char *token) "node= : %s key: %s token: %s" -xen_bus_watch(const char *token) "token: %s" +xen_bus_add_watch(const char *node, const char *key) "node: %s key: %s" +xen_bus_remove_watch(const char *node, const char *key) "node: %s key: %s" xen_device_realize(const char *type, char *name) "type: %s name: %s" xen_device_unrealize(const char *type, char *name) "type: %s name: %s" xen_device_backend_state(const char *type, char *name, const char *state) = "type: %s name: %s -> %s" diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 025df5e59f..28efaccff2 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -157,18 +157,60 @@ static void free_watch(XenWatch *watch) g_free(watch); } =20 -static XenWatch *xen_bus_add_watch(XenBus *xenbus, const char *node, - const char *key, XenWatchHandler handle= r, - void *opaque, Error **errp) +struct XenWatchList { + struct xs_handle *xsh; + NotifierList notifiers; +}; + +static void watch_list_event(void *opaque) +{ + XenWatchList *watch_list =3D opaque; + char **v; + const char *token; + + v =3D xs_check_watch(watch_list->xsh); + if (!v) { + return; + } + + token =3D v[XS_WATCH_TOKEN]; + + notifier_list_notify(&watch_list->notifiers, (void *)token); + + free(v); +} + +static XenWatchList *watch_list_create(struct xs_handle *xsh) +{ + XenWatchList *watch_list =3D g_new0(XenWatchList, 1); + + g_assert(xsh); + + watch_list->xsh =3D xsh; + notifier_list_init(&watch_list->notifiers); + qemu_set_fd_handler(xs_fileno(watch_list->xsh), watch_list_event, NULL, + watch_list); + + return watch_list; +} + +static void watch_list_destroy(XenWatchList *watch_list) +{ + g_assert(notifier_list_empty(&watch_list->notifiers)); + qemu_set_fd_handler(xs_fileno(watch_list->xsh), NULL, NULL, NULL); + g_free(watch_list); +} + +static XenWatch *watch_list_add(XenWatchList *watch_list, const char *node, + const char *key, XenWatchHandler handler, + void *opaque, Error **errp) { XenWatch *watch =3D new_watch(node, key, handler, opaque); Error *local_err =3D NULL; =20 - trace_xen_bus_add_watch(watch->node, watch->key, watch->token); - - notifier_list_add(&xenbus->watch_notifiers, &watch->notifier); + notifier_list_add(&watch_list->notifiers, &watch->notifier); =20 - xs_node_watch(xenbus->xsh, node, key, watch->token, &local_err); + xs_node_watch(watch_list->xsh, node, key, watch->token, &local_err); if (local_err) { error_propagate(errp, local_err); =20 @@ -181,18 +223,34 @@ static XenWatch *xen_bus_add_watch(XenBus *xenbus, co= nst char *node, return watch; } =20 -static void xen_bus_remove_watch(XenBus *xenbus, XenWatch *watch, - Error **errp) +static void watch_list_remove(XenWatchList *watch_list, XenWatch *watch, + Error **errp) { - trace_xen_bus_remove_watch(watch->node, watch->key, watch->token); - - xs_node_unwatch(xenbus->xsh, watch->node, watch->key, watch->token, + xs_node_unwatch(watch_list->xsh, watch->node, watch->key, watch->token, errp); =20 notifier_remove(&watch->notifier); free_watch(watch); } =20 +static XenWatch *xen_bus_add_watch(XenBus *xenbus, const char *node, + const char *key, XenWatchHandler handle= r, + void *opaque, Error **errp) +{ + trace_xen_bus_add_watch(node, key); + + return watch_list_add(xenbus->watch_list, node, key, handler, opaque, + errp); +} + +static void xen_bus_remove_watch(XenBus *xenbus, XenWatch *watch, + Error **errp) +{ + trace_xen_bus_remove_watch(watch->node, watch->key); + + watch_list_remove(xenbus->watch_list, watch, errp); +} + static void xen_bus_backend_create(XenBus *xenbus, const char *type, const char *name, char *path, Error **errp) @@ -338,35 +396,14 @@ static void xen_bus_unrealize(BusState *bus, Error **= errp) xenbus->backend_watch =3D NULL; } =20 - if (!xenbus->xsh) { - return; + if (xenbus->watch_list) { + watch_list_destroy(xenbus->watch_list); + xenbus->watch_list =3D NULL; } =20 - qemu_set_fd_handler(xs_fileno(xenbus->xsh), NULL, NULL, NULL); - - xs_close(xenbus->xsh); -} - -static void xen_bus_watch(void *opaque) -{ - XenBus *xenbus =3D opaque; - char **v; - const char *token; - - g_assert(xenbus->xsh); - - v =3D xs_check_watch(xenbus->xsh); - if (!v) { - return; + if (xenbus->xsh) { + xs_close(xenbus->xsh); } - - token =3D v[XS_WATCH_TOKEN]; - - trace_xen_bus_watch(token); - - notifier_list_notify(&xenbus->watch_notifiers, (void *)token); - - free(v); } =20 static void xen_bus_realize(BusState *bus, Error **errp) @@ -390,9 +427,7 @@ static void xen_bus_realize(BusState *bus, Error **errp) xenbus->backend_id =3D 0; /* Assume lack of node means dom0 */ } =20 - notifier_list_init(&xenbus->watch_notifiers); - qemu_set_fd_handler(xs_fileno(xenbus->xsh), xen_bus_watch, NULL, - xenbus); + xenbus->watch_list =3D watch_list_create(xenbus->xsh); =20 module_call_init(MODULE_INIT_XEN_BACKEND); =20 diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index 1c2d9dfdb8..88b84e29bb 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -14,6 +14,7 @@ =20 typedef void (*XenWatchHandler)(void *opaque); =20 +typedef struct XenWatchList XenWatchList; typedef struct XenWatch XenWatch; typedef struct XenEventChannel XenEventChannel; =20 @@ -63,7 +64,7 @@ typedef struct XenBus { BusState qbus; domid_t backend_id; struct xs_handle *xsh; - NotifierList watch_notifiers; + XenWatchList *watch_list; XenWatch *backend_watch; } XenBus; =20 diff --git a/include/qemu/notify.h b/include/qemu/notify.h index a3d73e4bc7..bcfa70fb2e 100644 --- a/include/qemu/notify.h +++ b/include/qemu/notify.h @@ -40,6 +40,8 @@ void notifier_remove(Notifier *notifier); =20 void notifier_list_notify(NotifierList *list, void *data); =20 +bool notifier_list_empty(NotifierList *list); + /* Same as Notifier but allows .notify() to return errors */ typedef struct NotifierWithReturn NotifierWithReturn; =20 diff --git a/util/notify.c b/util/notify.c index aee8d93cb0..76bab212ae 100644 --- a/util/notify.c +++ b/util/notify.c @@ -40,6 +40,11 @@ void notifier_list_notify(NotifierList *list, void *data) } } =20 +bool notifier_list_empty(NotifierList *list) +{ + return QLIST_EMPTY(&list->notifiers); +} + void notifier_with_return_list_init(NotifierWithReturnList *list) { QLIST_INIT(&list->notifiers); --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel