[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 04/18] xen: create xenstore areas for XenDevice-
From: |
Anthony PERARD |
Subject: |
Re: [Qemu-devel] [PATCH 04/18] xen: create xenstore areas for XenDevice-s |
Date: |
Thu, 29 Nov 2018 18:48:41 +0000 |
User-agent: |
Mutt/1.11.0 (2018-11-25) |
On Wed, Nov 21, 2018 at 03:11:57PM +0000, Paul Durrant wrote:
> This patch adds a new source module, xen-bus-helper.c, which builds on
> basic libxenstore primitives to provide functions to create (setting
> permissions appropriately) and destroy xenstore areas, and functions to
> 'printf' and 'scanf' nodes therein. The main xen-bus code then uses
> these primitives [1] to initialize and destroy the frontend and backend
> areas for a XenDevice during realize and unrealize respectively.
>
> The 'xen-qdisk' implementation is extended with a 'get_name' method that
> returns the VBD number. This number is reqired to 'name' the xenstore
^ required
> diff --git a/hw/xen/xen-bus-helper.c b/hw/xen/xen-bus-helper.c
> new file mode 100644
> index 0000000000..d9ee2ed6a0
> --- /dev/null
> +++ b/hw/xen/xen-bus-helper.c
[...]
> +void xs_node_destroy(struct xs_handle *xsh, const char *node)
> +{
> + xs_rm(xsh, XBT_NULL, node);
We should check for error, and grab errno.
> +}
> +
> +void xs_node_vprintf(struct xs_handle *xsh, const char *node,
> + const char *key, const char *fmt, va_list ap)
> +{
> + char *path, *value;
> +
> + path = (strlen(node) != 0) ? g_strdup_printf("%s/%s", node, key) :
> + g_strdup(key);
A comment would be helpful to findout how to use that function,
especialy the fact that with node="", we write to $key instead of
$node/$key.
> + value = g_strdup_vprintf(fmt, ap);
Looks like g_vasprintf() would be better, since it returns the lenght as
well.
> +
> + xs_write(xsh, XBT_NULL, path, value, strlen(value));
You should check for failures, and grab errno.
> + g_free(value);
> + g_free(path);
> +}
> +
> +int xs_node_vscanf(struct xs_handle *xsh, const char *node, const char *key,
> + const char *fmt, va_list ap)
> +{
> + char *path, *value;
> + int rc;
> +
> + path = (strlen(node) != 0) ? g_strdup_printf("%s/%s", node, key) :
> + g_strdup(key);
> +
> + value = xs_read(xsh, XBT_NULL, path, NULL);
The xenstore.h isn't clear about failure of this function, it is
supposed to return a malloced value. Do we actually need to check if value
is NULL?
> +
> + rc = value ? vsscanf(value, fmt, ap) : EOF;
> +
> + free(value);
> + g_free(path);
> +
> + return rc;
> +}
> +
> diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
> index dede2d914a..663aa8e117 100644
> --- a/hw/xen/xen-bus.c
> +++ b/hw/xen/xen-bus.c
[...]
> +static void xen_device_backend_destroy(XenDevice *xendev)
> +{
> + XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
> +
> + if (!xendev->backend_path) {
> + return;
> + }
> +
> + g_assert(xenbus->xsh);
> +
> + xs_node_destroy(xenbus->xsh, xendev->backend_path);
> + g_free(xendev->backend_path);
It would be nice to also set backend_path to NULL.
> diff --git a/include/hw/xen/xen-bus-helper.h b/include/hw/xen/xen-bus-helper.h
> new file mode 100644
> index 0000000000..53570650db
> --- /dev/null
> +++ b/include/hw/xen/xen-bus-helper.h
> @@ -0,0 +1,26 @@
> +/*
> + * Copyright (c) Citrix Systems Inc.
> + * All rights reserved.
> + */
> +
> +#ifndef HW_XEN_BUS_HELPER_H
> +#define HW_XEN_BUS_HELPER_H
That should probably include xen_common.h, to have `enum xenbus_state`,
`struct xs_handle`, ..
> +const char *xs_strstate(enum xenbus_state state);
> +
> +void xs_node_create(struct xs_handle *xsh, const char *node,
> + struct xs_permissions perms[],
> + unsigned int nr_perms, Error **errp);
> +void xs_node_destroy(struct xs_handle *xsh, const char *node);
> +
> +void xs_node_vprintf(struct xs_handle *xsh, const char *node,
> + const char *key, const char *fmt, va_list ap);
> +void xs_node_printf(struct xs_handle *xsh, const char *node, const char *key,
> + const char *fmt, ...);
This prototype needs GCC_FMT_ATTR(), that's the printf format
__attribute__.
> +
> +int xs_node_vscanf(struct xs_handle *xsh, const char *node, const char *key,
> + const char *fmt, va_list ap);
> +int xs_node_scanf(struct xs_handle *xsh, const char *node, const char *key,
> + const char *fmt, ...);
Maybe here as well.
--
Anthony PERARD
- Re: [Qemu-devel] [PATCH 02/18] xen: introduce new 'XenBus' and 'XenDevice' object hierarchy, (continued)
- [Qemu-devel] [PATCH 07/18] xen: add event channel interface for XenDevice-s, Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 08/18] xen: duplicate xen_disk.c as basis of dataplane/xen-qdisk.c, Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 03/18] xen: introduce 'xen-qdisk', Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 01/18] xen: re-name XenDevice to XenLegacyDevice..., Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 04/18] xen: create xenstore areas for XenDevice-s, Paul Durrant, 2018/11/21
- Re: [Qemu-devel] [PATCH 04/18] xen: create xenstore areas for XenDevice-s,
Anthony PERARD <=
- [Qemu-devel] [PATCH 05/18] xen: add xenstore watcher infratructure, Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 06/18] xen: add grant table interface for XenDevice-s, Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 13/18] xen: purge 'blk' and 'ioreq' from function names in dataplane/xen-qdisk.c, Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 11/18] xen: remove 'XenBlkDev' and 'blkdev' names from dataplane/xen-qdisk, Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 15/18] xen: add a mechanism to automatically create XenDevice-s..., Paul Durrant, 2018/11/21
- [Qemu-devel] [PATCH 14/18] xen: add implementations of xen-qdisk connect and disconnect functions..., Paul Durrant, 2018/11/21