Skip to content

Commit 4d5d933

Browse files
committed
Merge tag 'pull-xenfv-20250116' of git://git.infradead.org/users/dwmw2/qemu into staging
Xen regression fixes and cleanups # -----BEGIN PGP SIGNATURE----- # # iQJGBAABCAAwFiEEMUsIrNDeSBEzpfKGm+mA/QrAFUQFAmeIxhcSHGR3bXdAYW1h # em9uLmNvLnVrAAoJEJvpgP0KwBVEbKoP/iqQ+PhbwT9+xz6lxW+g1Dx+YGrT/ugp # d3xHn9AEkR0EHC42J6RB/llyWbKVD/IIhYwUk5GDm+4InGrtuQDhG6UqWxqvIRht # 0JuZvVm7x5akmKv73igxNqZHVg0ZEAS+EllBUaBYWj0pvpMbBK93Sdz9PXKxA7Nm # dPeFrOpL2TAmnDCH1UuBbXypHEjAghmv7WFphMtk6qLX+wYVaK3F2J/ed2TNyT0V # LliOdQH0Pxt445SSVJIZRe9bW3FH7qyvZV1gCnxSnqPUlN7vBhpjzgl4hWEzVYcp # 7X21ZAD9kPc81DJjYucbLjAbrqSmlDrJqL05qtRigfPcnqz2NoKrYxhj8B0F8mgt # 1IbymPyeab5gk5Hi1QgMmG5eobDDaglDSxpq6gRfJBiJW+1adif00z/HVvt5onS0 # uQ6i6w5NzQciBX77muAb2ZDEMysjk+3wSJMMpkfl90D0kjlMqeWWs4FH9ThasjC+ # EhQioUD0euedgnzOSfQjNNtAW4gzv9rcShkcV84bjxP/0Es+Pgx9f6wtCUTzdeqy # Cid8/72lHIgrkZGfpv8BBZkA1XP09vgtUGKyAWm4yHOcB57l8cNiL1nKtqoCLwkQ # 8JWFWzFeEY19KoiRGY5saH6ExeOx8fmc/lYwqImZqFqvuFX4Vf2RJdTIRIYr7g05 # 2QffxFmskg+A # =Wz0V # -----END PGP SIGNATURE----- # gpg: Signature made Thu 16 Jan 2025 03:40:55 EST # gpg: using RSA key 314B08ACD0DE481133A5F2869BE980FD0AC01544 # gpg: issuer "dwmw@amazon.co.uk" # gpg: Good signature from "David Woodhouse <dwmw@amazon.co.uk>" [unknown] # gpg: aka "David Woodhouse <dwmw@amazon.com>" [unknown] # gpg: WARNING: The key's User ID is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 314B 08AC D0DE 4811 33A5 F286 9BE9 80FD 0AC0 1544 * tag 'pull-xenfv-20250116' of git://git.infradead.org/users/dwmw2/qemu: system/runstate: Fix regression, clarify BQL status of exit notifiers hw/xen: Fix errp handling in xen_console hw/xen: Use xs_node_read() from xenstore_read_str() instead of open-coding it hw/xen: Use xs_node_read() from xen_netdev_get_name() hw/xen: Use xs_node_read() from xen_console_get_name() hw/xen: Use xs_node_read() from xs_node_vscanf() xen: do not use '%ms' scanf specifier hw/xen: Add xs_node_read() helper function Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2 parents 9061ee2 + e7bc020 commit 4d5d933

File tree

11 files changed

+96
-47
lines changed

11 files changed

+96
-47
lines changed

hw/block/xen-block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ static void xen_block_connect(XenDevice *xendev, Error **errp)
239239
return;
240240
}
241241

242-
if (xen_device_frontend_scanf(xendev, "protocol", "%ms", &str) != 1) {
242+
str = xen_device_frontend_read(xendev, "protocol");
243+
if (!str) {
243244
/* x86 defaults to the 32-bit protocol even for 64-bit guests. */
244245
if (object_dynamic_cast(OBJECT(qdev_get_machine()), "x86-machine")) {
245246
protocol = BLKIF_PROTOCOL_X86_32;

hw/char/xen_console.c

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -367,28 +367,28 @@ static char *xen_console_get_name(XenDevice *xendev, Error **errp)
367367

368368
if (con->dev == -1) {
369369
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
370-
char fe_path[XENSTORE_ABS_PATH_MAX + 1];
371370
int idx = (xen_mode == XEN_EMULATE) ? 0 : 1;
371+
Error *local_err = NULL;
372372
char *value;
373373

374374
/* Theoretically we could go up to INT_MAX here but that's overkill */
375375
while (idx < 100) {
376376
if (!idx) {
377-
snprintf(fe_path, sizeof(fe_path),
378-
"/local/domain/%u/console", xendev->frontend_id);
377+
value = xs_node_read(xenbus->xsh, XBT_NULL, NULL, &local_err,
378+
"/local/domain/%u/console",
379+
xendev->frontend_id);
379380
} else {
380-
snprintf(fe_path, sizeof(fe_path),
381-
"/local/domain/%u/device/console/%u",
382-
xendev->frontend_id, idx);
381+
value = xs_node_read(xenbus->xsh, XBT_NULL, NULL, &local_err,
382+
"/local/domain/%u/device/console/%u",
383+
xendev->frontend_id, idx);
383384
}
384-
value = qemu_xen_xs_read(xenbus->xsh, XBT_NULL, fe_path, NULL);
385385
if (!value) {
386386
if (errno == ENOENT) {
387387
con->dev = idx;
388+
error_free(local_err);
388389
goto found;
389390
}
390-
error_setg(errp, "cannot read %s: %s", fe_path,
391-
strerror(errno));
391+
error_propagate(errp, local_err);
392392
return NULL;
393393
}
394394
free(value);
@@ -550,7 +550,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
550550
goto fail;
551551
}
552552

553-
if (xs_node_scanf(xsh, XBT_NULL, fe, "type", errp, "%ms", &type) != 1) {
553+
type = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "type");
554+
if (!type) {
554555
error_prepend(errp, "failed to read console device type: ");
555556
goto fail;
556557
}
@@ -568,7 +569,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
568569

569570
snprintf(label, sizeof(label), "xencons%ld", number);
570571

571-
if (xs_node_scanf(xsh, XBT_NULL, fe, "output", NULL, "%ms", &output) == 1) {
572+
output = xs_node_read(xsh, XBT_NULL, NULL, errp, "%s/%s", fe, "output");
573+
if (output) {
572574
/*
573575
* FIXME: sure we want to support implicit
574576
* muxed monitors here?
@@ -579,19 +581,27 @@ static void xen_console_device_create(XenBackendInstance *backend,
579581
output);
580582
goto fail;
581583
}
582-
} else if (number) {
583-
cd = serial_hd(number);
584-
if (!cd) {
585-
error_prepend(errp, "console: No serial device #%ld found: ",
586-
number);
587-
goto fail;
588-
}
584+
} else if (errno != ENOENT) {
585+
error_prepend(errp, "console: No valid chardev found: ");
586+
goto fail;
589587
} else {
590-
/* No 'output' node on primary console: use null. */
591-
cd = qemu_chr_new(label, "null", NULL);
592-
if (!cd) {
593-
error_setg(errp, "console: failed to create null device");
594-
goto fail;
588+
error_free(*errp);
589+
*errp = NULL;
590+
591+
if (number) {
592+
cd = serial_hd(number);
593+
if (!cd) {
594+
error_setg(errp, "console: No serial device #%ld found",
595+
number);
596+
goto fail;
597+
}
598+
} else {
599+
/* No 'output' node on primary console: use null. */
600+
cd = qemu_chr_new(label, "null", NULL);
601+
if (!cd) {
602+
error_setg(errp, "console: failed to create null device");
603+
goto fail;
604+
}
595605
}
596606
}
597607

hw/net/xen_nic.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,23 +510,22 @@ static char *xen_netdev_get_name(XenDevice *xendev, Error **errp)
510510

511511
if (netdev->dev == -1) {
512512
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
513-
char fe_path[XENSTORE_ABS_PATH_MAX + 1];
514513
int idx = (xen_mode == XEN_EMULATE) ? 0 : 1;
514+
Error *local_err = NULL;
515515
char *value;
516516

517517
/* Theoretically we could go up to INT_MAX here but that's overkill */
518518
while (idx < 100) {
519-
snprintf(fe_path, sizeof(fe_path),
520-
"/local/domain/%u/device/vif/%u",
521-
xendev->frontend_id, idx);
522-
value = qemu_xen_xs_read(xenbus->xsh, XBT_NULL, fe_path, NULL);
519+
value = xs_node_read(xenbus->xsh, XBT_NULL, NULL, &local_err,
520+
"/local/domain/%u/device/vif/%u",
521+
xendev->frontend_id, idx);
523522
if (!value) {
524523
if (errno == ENOENT) {
525524
netdev->dev = idx;
525+
error_free(local_err);
526526
goto found;
527527
}
528-
error_setg(errp, "cannot read %s: %s", fe_path,
529-
strerror(errno));
528+
error_propagate(errp, local_err);
530529
return NULL;
531530
}
532531
free(value);

hw/xen/trace-events

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ xen_device_remove_watch(const char *type, char *name, const char *node, const ch
3838
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"
41-
xs_node_vscanf(char *path, char *value) "%s %s"
41+
xs_node_read(const char *path, const char *value) "%s %s"
4242
xs_node_watch(char *path) "%s"
4343
xs_node_unwatch(char *path) "%s"
4444

hw/xen/xen-bus-helper.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,22 @@ int xs_node_vscanf(struct qemu_xs_handle *h, xs_transaction_t tid,
105105
const char *node, const char *key, Error **errp,
106106
const char *fmt, va_list ap)
107107
{
108-
char *path, *value;
108+
char *value;
109109
int rc;
110110

111-
path = (strlen(node) != 0) ? g_strdup_printf("%s/%s", node, key) :
112-
g_strdup(key);
113-
value = qemu_xen_xs_read(h, tid, path, NULL);
114-
115-
trace_xs_node_vscanf(path, value);
111+
if (node && strlen(node) != 0) {
112+
value = xs_node_read(h, tid, NULL, errp, "%s/%s", node, key);
113+
} else {
114+
value = xs_node_read(h, tid, NULL, errp, "%s", key);
115+
}
116116

117117
if (value) {
118118
rc = vsscanf(value, fmt, ap);
119119
} else {
120-
error_setg_errno(errp, errno, "failed to read from '%s'",
121-
path);
122120
rc = EOF;
123121
}
124122

125123
free(value);
126-
g_free(path);
127124

128125
return rc;
129126
}
@@ -142,6 +139,28 @@ int xs_node_scanf(struct qemu_xs_handle *h, xs_transaction_t tid,
142139
return rc;
143140
}
144141

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

hw/xen/xen-bus.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ static void xen_bus_backend_create(XenBus *xenbus, const char *type,
156156
!strcmp(key[i], "hotplug-status"))
157157
continue;
158158

159-
if (xs_node_scanf(xenbus->xsh, tid, path, key[i], NULL, "%ms",
160-
&val) == 1) {
159+
val = xs_node_read(xenbus->xsh, tid, NULL, NULL, "%s/%s", path, key[i]);
160+
if (val) {
161161
qdict_put_str(opts, key[i], val);
162162
free(val);
163163
}
@@ -650,6 +650,16 @@ int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
650650
return rc;
651651
}
652652

653+
char *xen_device_frontend_read(XenDevice *xendev, const char *key)
654+
{
655+
XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
656+
657+
g_assert(xenbus->xsh);
658+
659+
return xs_node_read(xenbus->xsh, XBT_NULL, NULL, NULL, "%s/%s",
660+
xendev->frontend_path, key);
661+
}
662+
653663
static void xen_device_frontend_set_state(XenDevice *xendev,
654664
enum xenbus_state state,
655665
bool publish)

hw/xen/xen_pvdev.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qemu/main-loop.h"
2323
#include "hw/qdev-core.h"
2424
#include "hw/xen/xen-legacy-backend.h"
25+
#include "hw/xen/xen-bus-helper.h"
2526
#include "hw/xen/xen_pvdev.h"
2627

2728
/* private */
@@ -81,12 +82,9 @@ int xenstore_write_str(const char *base, const char *node, const char *val)
8182

8283
char *xenstore_read_str(const char *base, const char *node)
8384
{
84-
char abspath[XEN_BUFSIZE];
85-
unsigned int len;
8685
char *str, *ret = NULL;
8786

88-
snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
89-
str = qemu_xen_xs_read(xenstore, 0, abspath, &len);
87+
str = xs_node_read(xenstore, 0, NULL, NULL, "%s/%s", base, node);
9088
if (str != NULL) {
9189
/* move to qemu-allocated memory to make sure
9290
* callers can safely g_free() stuff. */

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,

include/hw/xen/xen-bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void xen_device_frontend_printf(XenDevice *xendev, const char *key,
9191
int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
9292
const char *fmt, ...)
9393
G_GNUC_SCANF(3, 4);
94+
char *xen_device_frontend_read(XenDevice *xendev, const char *key);
9495

9596
void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
9697
Error **errp);

include/system/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern bool qemu_uuid_set;
1515

1616
const char *qemu_get_vm_name(void);
1717

18+
/* Exit notifiers will run with BQL held. */
1819
void qemu_add_exit_notifier(Notifier *notify);
1920
void qemu_remove_exit_notifier(Notifier *notify);
2021

0 commit comments

Comments
 (0)