xen: do not use '%ms' scanf specifier

The 'm' parameter used to request auto-allocation of the destination variable
is not supported on FreeBSD, and as such leads to failures to parse.

What's more, the current usage of '%ms' with xs_node_scanf() is pointless, as
it just leads to a double allocation of the same string.  Instead use
xs_node_read() to read the whole xenstore node.

Fixes: a783f8ad4e ('xen: add a mechanism to automatically create XenDevice-s...')
Fixes: 9b77374690 ('hw/xen: update Xen console to XenDevice model')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
This commit is contained in:
Roger Pau Monne 2025-01-10 10:35:31 +01:00 committed by David Woodhouse
parent e6cdeee959
commit 7a0b74d871
4 changed files with 19 additions and 5 deletions

View file

@ -239,7 +239,8 @@ static void xen_block_connect(XenDevice *xendev, Error **errp)
return;
}
if (xen_device_frontend_scanf(xendev, "protocol", "%ms", &str) != 1) {
str = xen_device_frontend_read(xendev, "protocol");
if (!str) {
/* x86 defaults to the 32-bit protocol even for 64-bit guests. */
if (object_dynamic_cast(OBJECT(qdev_get_machine()), "x86-machine")) {
protocol = BLKIF_PROTOCOL_X86_32;

View file

@ -550,7 +550,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
goto fail;
}
if (xs_node_scanf(xsh, XBT_NULL, fe, "type", errp, "%ms", &type) != 1) {
type = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "type");
if (!type) {
error_prepend(errp, "failed to read console device type: ");
goto fail;
}
@ -568,7 +569,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
snprintf(label, sizeof(label), "xencons%ld", number);
if (xs_node_scanf(xsh, XBT_NULL, fe, "output", NULL, "%ms", &output) == 1) {
output = xs_node_read(xsh, XBT_NULL, NULL, NULL, "%s/%s", fe, "output");
if (output) {
/*
* FIXME: sure we want to support implicit
* muxed monitors here?

View file

@ -156,8 +156,8 @@ again:
!strcmp(key[i], "hotplug-status"))
continue;
if (xs_node_scanf(xenbus->xsh, tid, path, key[i], NULL, "%ms",
&val) == 1) {
val = xs_node_read(xenbus->xsh, tid, NULL, NULL, "%s/%s", path, key[i]);
if (val) {
qdict_put_str(opts, key[i], val);
free(val);
}
@ -650,6 +650,16 @@ int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
return rc;
}
char *xen_device_frontend_read(XenDevice *xendev, const char *key)
{
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
g_assert(xenbus->xsh);
return xs_node_read(xenbus->xsh, XBT_NULL, NULL, NULL, "%s/%s",
xendev->frontend_path, key);
}
static void xen_device_frontend_set_state(XenDevice *xendev,
enum xenbus_state state,
bool publish)

View file

@ -91,6 +91,7 @@ void xen_device_frontend_printf(XenDevice *xendev, const char *key,
int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
const char *fmt, ...)
G_GNUC_SCANF(3, 4);
char *xen_device_frontend_read(XenDevice *xendev, const char *key);
void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
Error **errp);