[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 06/10] tools/xenstored: Introduce a wrapper for conn->funcs->can_{read, write}


  • To: Julien Grall <julien@xxxxxxx>
  • From: Luca Fancellu <luca.fancellu@xxxxxxx>
  • Date: Mon, 21 Jun 2021 10:10:58 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N0S+LDj98BFOC45O6LsSQdEu3H3PdBd/n+fCFIcB5lA=; b=kbdwogkorj3E4yeOzIakV3KsrMrG+JDKbcRFZElNr5MBoa3utZQIxmVILefyFceQ4jZmIlsuP73MG8YAoxFWmxVxg8YbpyFrN3nK00ZD0cENhRc10Y12hvP8ojHKw95Pq/O5ENg/AD4MESFLeHDNFP36nNq1alO3H45vbGGMtbb6jtpLVhz8tmlE9kYSHBmSOXEGTeAXYsbS9oe4afXcDWQANvPKjxRgT59dNWjo7f4Psokzu585Oepf8u5ayTZvlShQWPOYueqssgSQ4h/RhKO3UUVL9x2lfueiCPqkyRLOEuged9xOKSVIWISmalAYTX0VKI5S2dliZYHaU8UF9w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LbQIy6WEYuLcfk59NGBdTIsDw64Dkabu91ra75Sp/PqvkMnZbA0F0xDaIDVgBeieSU11pYFuupt5qmLpGHOoBTbteIprF/YdWzdFtjFj9DwOl1c900zAQ3oTQQrRqvhqPxIdZHV3xrdhasJ0paoLjGYIY/Div2OGJ2wFuKfgJG19tsxMRDHBkLaSg84zEJjXHfFL1extLl56p6cs+XWagIiwkG/LknfpIBL4caVIVJhAIfpyxydfBrULV6AQ+9vaUrm517JTLlPyCTU/AhDh1SzLVNP1J5eFGiwAX5tubn1mA2p/NoPDQ7NcKvxAKi1pADf3l5Omi0j3FH/Q9Htc+w==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, raphning@xxxxxxxxxxxx, doebel@xxxxxxxxx, Julien Grall <jgrall@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Mon, 21 Jun 2021 09:11:59 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;


> On 16 Jun 2021, at 15:43, Julien Grall <julien@xxxxxxx> wrote:
> 
> From: Julien Grall <jgrall@xxxxxxxxxx>
> 
> 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 <jgrall@xxxxxxxxxx>

Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>

> ---
> 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_core.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;
> }
> 
> +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 = 0;
>               } else {
> @@ -2325,14 +2335,14 @@ int main(int argc, char *argv[])
>                       if (&next->list != &connections)
>                               talloc_increase_ref_count(next);
> 
> -                     if (conn->funcs->can_read(conn))
> +                     if (conn_can_read(conn))
>                               handle_input(conn);
>                       if (talloc_free(conn) == 0)
>                               continue;
> 
>                       talloc_increase_ref_count(conn);
> 
> -                     if (conn->funcs->can_write(conn))
> +                     if (conn_can_write(conn))
>                               handle_output(conn);
>                       if (talloc_free(conn) == 0)
>                               continue;
> diff --git a/tools/xenstore/xenstored_domain.c 
> b/tools/xenstore/xenstored_domain.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;
> }
> 
> +static bool domain_can_write(struct connection *conn)
> +{
> +     struct xenstore_domain_interface *intf = conn->domain->interface;
> +
> +     return ((intf->rsp_prod - intf->rsp_cons) != XENSTORE_RING_SIZE);
> +}
> +
> +static bool domain_can_read(struct connection *conn)
> +{
> +     struct xenstore_domain_interface *intf = conn->domain->interface;
> +
> +     if (domain_is_unprivileged(conn) && conn->domain->wrl_credit < 0)
> +             return false;
> +
> +     return (intf->req_cons != intf->req_prod);
> +}
> +
> static const struct interface_funcs domain_funcs = {
>       .write = writechn,
>       .read = readchn,
> @@ -290,19 +307,6 @@ void handle_event(void)
>               barf_perror("Failed to write to event fd");
> }
> 
> -bool domain_can_read(struct connection *conn)
> -{
> -     struct xenstore_domain_interface *intf = 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 != intf->req_prod);
> -}
> -
> static bool domid_is_unprivileged(unsigned int domid)
> {
>       return domid != 0 && domid != priv_domid;
> @@ -314,16 +318,6 @@ bool domain_is_unprivileged(struct connection *conn)
>              domid_is_unprivileged(conn->domain->domid);
> }
> 
> -bool domain_can_write(struct connection *conn)
> -{
> -     struct xenstore_domain_interface *intf = conn->domain->interface;
> -
> -     if (conn->is_ignored)
> -             return false;
> -
> -     return ((intf->rsp_prod - intf->rsp_cons) != 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_domain.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);
> 
> -/* 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);
> 
> /* Remove node permissions for no longer existing domains. */
> -- 
> 2.17.1
> 
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.