Skip to content

Commit e6cdeee

Browse files
committed
hw/xen: Add xs_node_read() helper function
This returns the full contents of the node, having created the node path from the printf-style format string provided in its arguments. This will save various callers from having to do so for themselves (and from using xs_node_scanf() with the non-portable %ms format string. Signed-off-by: David Woodhouse <[email protected]> [remove double newline and constify trace parameters] Signed-off-by: Roger Pau Monné <[email protected]> Reviewed-by: Anthony PERARD <[email protected]>
1 parent 7433709 commit e6cdeee

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

hw/xen/trace-events

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ xs_node_create(const char *node) "%s"
3939
xs_node_destroy(const char *node) "%s"
4040
xs_node_vprintf(char *path, char *value) "%s %s"
4141
xs_node_vscanf(char *path, char *value) "%s %s"
42+
xs_node_read(const char *path, const char *value) "%s %s"
4243
xs_node_watch(char *path) "%s"
4344
xs_node_unwatch(char *path) "%s"
4445

hw/xen/xen-bus-helper.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ int xs_node_scanf(struct qemu_xs_handle *h, xs_transaction_t tid,
142142
return rc;
143143
}
144144

145+
char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
146+
unsigned int *len, Error **errp,
147+
const char *path_fmt, ...)
148+
{
149+
char *path, *value;
150+
va_list ap;
151+
152+
va_start(ap, path_fmt);
153+
path = g_strdup_vprintf(path_fmt, ap);
154+
va_end(ap);
155+
156+
value = qemu_xen_xs_read(h, tid, path, len);
157+
trace_xs_node_read(path, value);
158+
if (!value) {
159+
error_setg_errno(errp, errno, "failed to read from '%s'", path);
160+
}
161+
162+
g_free(path);
163+
164+
return value;
165+
}
166+
145167
struct qemu_xs_watch *xs_node_watch(struct qemu_xs_handle *h, const char *node,
146168
const char *key, xs_watch_fn fn,
147169
void *opaque, Error **errp)

include/hw/xen/xen-bus-helper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ int xs_node_scanf(struct qemu_xs_handle *h, xs_transaction_t tid,
3838
const char *fmt, ...)
3939
G_GNUC_SCANF(6, 7);
4040

41+
/*
42+
* Unlike other functions here, the printf-formatted path_fmt is for
43+
* the XenStore path, not the contents of the node.
44+
*/
45+
char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
46+
unsigned int *len, Error **errp,
47+
const char *path_fmt, ...)
48+
G_GNUC_PRINTF(5, 6);
49+
4150
/* Watch node/key unless node is empty, in which case watch key */
4251
struct qemu_xs_watch *xs_node_watch(struct qemu_xs_handle *h, const char *node,
4352
const char *key, xs_watch_fn fn,

0 commit comments

Comments
 (0)