From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Cc: minios-devel@lists.xenproject.org,
xen-devel@lists.xenproject.org, wl@xen.org
Subject: Re: [PATCH v2 1/7] Mini-OS: xenbus: add support for reading node from directory
Date: Fri, 10 Feb 2023 19:43:48 +0100 [thread overview]
Message-ID: <20230210184348.mbbxhuroralr7q64@begin> (raw)
In-Reply-To: <20230210104628.14374-2-jgross@suse.com>
Juergen Gross, le ven. 10 févr. 2023 11:46:22 +0100, a ecrit:
> Especially PV device drivers often need to read multiple Xenstore
> nodes from a common directory. Add support for reading a string or an
> unsigned value by specifying the directory and the node.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
> V2:
> - check sscanf() return value (Samuel Thibault)
> ---
> include/xenbus.h | 6 ++++++
> xenbus.c | 40 +++++++++++++++++++++++++++++++++++++---
> 2 files changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/include/xenbus.h b/include/xenbus.h
> index 3871f358..c0fc0ac5 100644
> --- a/include/xenbus.h
> +++ b/include/xenbus.h
> @@ -108,6 +108,12 @@ int xenbus_read_integer(const char *path);
> * read and parsing were successful, 0 if not */
> int xenbus_read_uuid(const char* path, unsigned char uuid[16]);
>
> +/* Support functions for reading values from directory/node tuple. */
> +char *xenbus_read_string(xenbus_transaction_t xbt, const char *dir,
> + const char *node, char **value);
> +char *xenbus_read_unsigned(xenbus_transaction_t xbt, const char *dir,
> + const char *node, unsigned int *value);
> +
> /* Contraction of snprintf and xenbus_write(path/node). */
> char* xenbus_printf(xenbus_transaction_t xbt,
> const char* node, const char* path,
> diff --git a/xenbus.c b/xenbus.c
> index 81e9b65d..923e8181 100644
> --- a/xenbus.c
> +++ b/xenbus.c
> @@ -936,16 +936,21 @@ int xenbus_read_uuid(const char *path, unsigned char uuid[16])
> return 1;
> }
>
> +#define BUFFER_SIZE 256
> +static void xenbus_build_path(const char *dir, const char *node, char *res)
> +{
> + BUG_ON(strlen(dir) + strlen(node) + 1 >= BUFFER_SIZE);
> + sprintf(res,"%s/%s", dir, node);
> +}
> +
> char *xenbus_printf(xenbus_transaction_t xbt, const char* node,
> const char* path, const char* fmt, ...)
> {
> -#define BUFFER_SIZE 256
> char fullpath[BUFFER_SIZE];
> char val[BUFFER_SIZE];
> va_list args;
>
> - BUG_ON(strlen(node) + strlen(path) + 1 >= BUFFER_SIZE);
> - sprintf(fullpath,"%s/%s", node, path);
> + xenbus_build_path(node, path, fullpath);
> va_start(args, fmt);
> vsprintf(val, fmt, args);
> va_end(args);
> @@ -964,6 +969,35 @@ domid_t xenbus_get_self_id(void)
> return ret;
> }
>
> +char *xenbus_read_string(xenbus_transaction_t xbt, const char *dir,
> + const char *node, char **value)
> +{
> + char path[BUFFER_SIZE];
> +
> + xenbus_build_path(dir, node, path);
> +
> + return xenbus_read(xbt, path, value);
> +}
> +
> +char *xenbus_read_unsigned(xenbus_transaction_t xbt, const char *dir,
> + const char *node, unsigned int *value)
> +{
> + char path[BUFFER_SIZE];
> + char *msg;
> + char *str;
> +
> + xenbus_build_path(dir, node, path);
> + msg = xenbus_read(xbt, path, &str);
> + if ( msg )
> + return msg;
> +
> + if ( sscanf(str, "%u", value) != 1 )
> + msg = strdup("EINVAL");
> + free(str);
> +
> + return msg;
> +}
> +
> /*
> * Local variables:
> * mode: C
> --
> 2.35.3
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
next prev parent reply other threads:[~2023-02-10 18:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 10:46 [PATCH v2 0/7] Mini-OS: add minimal 9pfs support Juergen Gross
2023-02-10 10:46 ` [PATCH v2 1/7] Mini-OS: xenbus: add support for reading node from directory Juergen Gross
2023-02-10 18:43 ` Samuel Thibault [this message]
2023-02-10 10:46 ` [PATCH v2 2/7] Mini-OS: add concept of mount points Juergen Gross
2023-02-10 18:44 ` Samuel Thibault
2023-02-10 10:46 ` [PATCH v2 3/7] Mini-OS: add support for runtime mounts Juergen Gross
2023-02-10 11:43 ` Andrew Cooper
2023-02-10 12:14 ` Juergen Gross
2023-02-10 12:44 ` Samuel Thibault
2023-02-10 18:51 ` Andrew Cooper
2023-02-10 10:46 ` [PATCH v2 4/7] Mini-OS: add 9pfs frontend Juergen Gross
2023-02-10 18:46 ` Samuel Thibault
2023-02-10 10:46 ` [PATCH v2 5/7] Mini-OS: add 9pfs transport layer Juergen Gross
2023-02-10 18:48 ` Samuel Thibault
2023-02-10 10:46 ` [PATCH v2 6/7] Mini-OS: add open and close handling to the 9pfs frontend Juergen Gross
2023-02-10 18:53 ` Samuel Thibault
2023-02-11 6:23 ` Juergen Gross
2023-02-10 10:46 ` [PATCH v2 7/7] Mini-OS: add read and write support to 9pfsfront Juergen Gross
2023-02-10 18:59 ` Samuel Thibault
2023-02-13 6:47 ` Juergen Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230210184348.mbbxhuroralr7q64@begin \
--to=samuel.thibault@ens-lyon.org \
--cc=jgross@suse.com \
--cc=minios-devel@lists.xenproject.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.