From nobody Tue Feb 10 11:55:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1623854632; cv=none; d=zohomail.com; s=zohoarc; b=NpdHcXny0NcWgkA3qBKK3eCVNJiqk2K/K9k3tv9XxEKN8oZ7tKEruwcJE1z3Ci32+is9BHlIEldZFtUzPDGuM9eJCFg0t4NAKgNQzIAa0248u4kfnBUCz1KqPTDMxNub3bxgn3EYMWzOqWhhQeGmZJySX4nnPJco0rotOdLPUgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623854632; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ZvLpylj/UqcYoOOmC8VRLGxCMI8WwLt87nHoKc1byWA=; b=JkTA9cjosH2WRSYDeLbiTzeC6mZN8qiAg3811jxyDEMq5+N0jeZ4ME27x3y5ypPXSdiuwH7PWkvu2y/YFlbfuXCWj5sEARIZUCkaeS4uxACW0pT9Ovph1EvVaDYCDcFODIfclPYuvg4UZSKCjL08cwtHnjhdb2g6T7nBd9IXF1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1623854632505452.5558529458971; Wed, 16 Jun 2021 07:43:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.143285.264179 (Exim 4.92) (envelope-from ) id 1ltWlX-0006kH-1N; Wed, 16 Jun 2021 14:43:39 +0000 Received: by outflank-mailman (output) from mailman id 143285.264179; Wed, 16 Jun 2021 14:43:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltWlW-0006jk-SR; Wed, 16 Jun 2021 14:43:38 +0000 Received: by outflank-mailman (input) for mailman id 143285; Wed, 16 Jun 2021 14:43:37 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltWlV-0006Mk-5F for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 14:43:37 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltWlU-0004E6-6M; Wed, 16 Jun 2021 14:43:36 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltWlT-0007D0-U4; Wed, 16 Jun 2021 14:43:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZvLpylj/UqcYoOOmC8VRLGxCMI8WwLt87nHoKc1byWA=; b=FYK8bYQfTjgnv0czNv4OhkHKe fPm5TAmEg1tQm63lBFvvY2P/mdoDDnRH6FLSvrv05vR38D2NXBtJ4nSrPYxW8I4anfx15txQMWTS5 klUweyg5PW5A7yUraRaA0Qjd4mHPIcMDsq2hpu6Xo4882oi6ehJj45LJS4qxkH4Ac/tds=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: raphning@amazon.co.uk, doebel@amazon.de, Julien Grall , Ian Jackson , Wei Liu , Juergen Gross , Julien Grall Subject: [PATCH 06/10] tools/xenstored: Introduce a wrapper for conn->funcs->can_{read, write} Date: Wed, 16 Jun 2021 15:43:20 +0100 Message-Id: <20210616144324.31652-7-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210616144324.31652-1-julien@xen.org> References: <20210616144324.31652-1-julien@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, the callbacks can_read and can_write are called directly. This doesn't allow us to add generic check and therefore requires duplication. At the moment, one check that could benefit to be common is whether the connection should ignored. The position is slightly different between domain and socket because for the latter we want to check the state of the file descriptor first. In follow-up patches, there will be more potential generic checks. This patch provides wrappers to read/write a connection and move the check ->is_ignored after the callback for everyone. This also requires to replace the direct call to domain_can_read() and domain_can_write() with the new wrapper. At the same time, both functions can now be static. Note that the implementations need to be moved earlier in the file xenstored_domain.c to avoid declaring the prototype. Signed-off-by: Julien Grall Reviewed-by: Juergen Gross Reviewed-by: Luca Fancellu --- tools/xenstore/xenstored_core.c | 18 ++++++++++---- tools/xenstore/xenstored_domain.c | 40 +++++++++++++------------------ tools/xenstore/xenstored_domain.h | 4 ---- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 51d210828922..2e5760fe4599 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -334,6 +334,16 @@ static int destroy_conn(void *_conn) return 0; } =20 +static bool conn_can_read(struct connection *conn) +{ + return conn->funcs->can_read(conn) && !conn->is_ignored; +} + +static bool conn_can_write(struct connection *conn) +{ + return conn->funcs->can_write(conn) && !conn->is_ignored; +} + /* This function returns index inside the array if succeed, -1 if fail */ static int set_fd(int fd, short events) { @@ -396,8 +406,8 @@ static void initialize_fds(int *p_sock_pollfd_idx, int = *ptimeout) list_for_each_entry(conn, &connections, list) { if (conn->domain) { wrl_check_timeout(conn->domain, now, ptimeout); - if (domain_can_read(conn) || - (domain_can_write(conn) && + if (conn_can_read(conn) || + (conn_can_write(conn) && !list_empty(&conn->out_list))) *ptimeout =3D 0; } else { @@ -2325,14 +2335,14 @@ int main(int argc, char *argv[]) if (&next->list !=3D &connections) talloc_increase_ref_count(next); =20 - if (conn->funcs->can_read(conn)) + if (conn_can_read(conn)) handle_input(conn); if (talloc_free(conn) =3D=3D 0) continue; =20 talloc_increase_ref_count(conn); =20 - if (conn->funcs->can_write(conn)) + if (conn_can_write(conn)) handle_output(conn); if (talloc_free(conn) =3D=3D 0) continue; diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 6d8d29cbe41c..47e9107c144e 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -172,6 +172,23 @@ static int readchn(struct connection *conn, void *data= , unsigned int len) return len; } =20 +static bool domain_can_write(struct connection *conn) +{ + struct xenstore_domain_interface *intf =3D conn->domain->interface; + + return ((intf->rsp_prod - intf->rsp_cons) !=3D XENSTORE_RING_SIZE); +} + +static bool domain_can_read(struct connection *conn) +{ + struct xenstore_domain_interface *intf =3D conn->domain->interface; + + if (domain_is_unprivileged(conn) && conn->domain->wrl_credit < 0) + return false; + + return (intf->req_cons !=3D intf->req_prod); +} + static const struct interface_funcs domain_funcs =3D { .write =3D writechn, .read =3D readchn, @@ -290,19 +307,6 @@ void handle_event(void) barf_perror("Failed to write to event fd"); } =20 -bool domain_can_read(struct connection *conn) -{ - struct xenstore_domain_interface *intf =3D conn->domain->interface; - - if (domain_is_unprivileged(conn) && conn->domain->wrl_credit < 0) - return false; - - if (conn->is_ignored) - return false; - - return (intf->req_cons !=3D intf->req_prod); -} - static bool domid_is_unprivileged(unsigned int domid) { return domid !=3D 0 && domid !=3D priv_domid; @@ -314,16 +318,6 @@ bool domain_is_unprivileged(struct connection *conn) domid_is_unprivileged(conn->domain->domid); } =20 -bool domain_can_write(struct connection *conn) -{ - struct xenstore_domain_interface *intf =3D conn->domain->interface; - - if (conn->is_ignored) - return false; - - return ((intf->rsp_prod - intf->rsp_cons) !=3D XENSTORE_RING_SIZE); -} - static char *talloc_domain_path(void *context, unsigned int domid) { return talloc_asprintf(context, "/local/domain/%u", domid); diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_d= omain.h index 62ee471ea6aa..1e929b8f8c6f 100644 --- a/tools/xenstore/xenstored_domain.h +++ b/tools/xenstore/xenstored_domain.h @@ -51,10 +51,6 @@ void domain_deinit(void); /* Returns the implicit path of a connection (only domains have this) */ const char *get_implicit_path(const struct connection *conn); =20 -/* Can connection attached to domain read/write. */ -bool domain_can_read(struct connection *conn); -bool domain_can_write(struct connection *conn); - bool domain_is_unprivileged(struct connection *conn); =20 /* Remove node permissions for no longer existing domains. */ --=20 2.17.1