diff mbox series

[v4,3/6] xen: decouple generic xen code from legacy backends codebase

Message ID 20231202014108.2017803-4-volodymyr_babchuk@epam.com (mailing list archive)
State New, archived
Headers show
Series [v4,1/6] hw/xen: Set XenBackendInstance in the XenDevice before realizing it | expand

Commit Message

Volodymyr Babchuk Dec. 2, 2023, 1:41 a.m. UTC
In xen-all.c there are unneeded dependencies on xen-legacy-backend.c:

 - xen_init() uses xen_pv_printf() to report errors, but it does not
 provide a pointer to the struct XenLegacyDevice, so it is kind of
 useless, we can use standard error_report() instead.

 - xen-all.c has function xenstore_record_dm_state() which uses global
 variable "xenstore" defined and initialized in xen-legacy-backend.c
 It is used exactly once, so we can just open a new connection to the
 xenstore, update DM state and close connection back.

Those two changes allows us to remove xen-legacy-backend.c at all,
what should be done in the future anyways. But right now this patch
moves us one step close to have QEMU build without legacy Xen
backends.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

---

In v4:

 - New in v4, previous was part of "xen: add option to disable legacy
 backends"
 - Do not move xenstore global variable from xen-legacy-backend.c,
   instead use a local variable.
---
 accel/xen/xen-all.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Paul Durrant Dec. 4, 2023, 2:50 p.m. UTC | #1
On 02/12/2023 01:41, Volodymyr Babchuk wrote:
> In xen-all.c there are unneeded dependencies on xen-legacy-backend.c:
> 
>   - xen_init() uses xen_pv_printf() to report errors, but it does not
>   provide a pointer to the struct XenLegacyDevice, so it is kind of
>   useless, we can use standard error_report() instead.
> 
>   - xen-all.c has function xenstore_record_dm_state() which uses global
>   variable "xenstore" defined and initialized in xen-legacy-backend.c
>   It is used exactly once, so we can just open a new connection to the
>   xenstore, update DM state and close connection back.
> 
> Those two changes allows us to remove xen-legacy-backend.c at all,
> what should be done in the future anyways. But right now this patch
> moves us one step close to have QEMU build without legacy Xen
> backends.
> 
> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
> 
> ---
> 
> In v4:
> 
>   - New in v4, previous was part of "xen: add option to disable legacy
>   backends"
>   - Do not move xenstore global variable from xen-legacy-backend.c,
>     instead use a local variable.
> ---
>   accel/xen/xen-all.c | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
> 

Reviewed-by: Paul Durrant <paul@xen.org>
diff mbox series

Patch

diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c
index 5ff0cb8bd9..6c2342581f 100644
--- a/accel/xen/xen-all.c
+++ b/accel/xen/xen-all.c
@@ -33,12 +33,20 @@  xendevicemodel_handle *xen_dmod;
 static void xenstore_record_dm_state(const char *state)
 {
     char path[50];
+    struct qemu_xs_handle *xsh = qemu_xen_xs_open();
+
+    if (!xsh) {
+        error_report("error opening xenstore");
+        exit(1);
+    }
 
     snprintf(path, sizeof (path), "device-model/%u/state", xen_domid);
-    if (!qemu_xen_xs_write(xenstore, XBT_NULL, path, state, strlen(state))) {
+    if (!qemu_xen_xs_write(xsh, XBT_NULL, path, state, strlen(state))) {
         error_report("error recording dm state");
         exit(1);
     }
+
+    qemu_xen_xs_close(xsh);
 }
 
 
@@ -80,18 +88,18 @@  static int xen_init(MachineState *ms)
 
     xen_xc = xc_interface_open(0, 0, 0);
     if (xen_xc == NULL) {
-        xen_pv_printf(NULL, 0, "can't open xen interface\n");
+        error_report("can't open xen interface\n");
         return -1;
     }
     xen_fmem = xenforeignmemory_open(0, 0);
     if (xen_fmem == NULL) {
-        xen_pv_printf(NULL, 0, "can't open xen fmem interface\n");
+        error_report("can't open xen fmem interface\n");
         xc_interface_close(xen_xc);
         return -1;
     }
     xen_dmod = xendevicemodel_open(0, 0);
     if (xen_dmod == NULL) {
-        xen_pv_printf(NULL, 0, "can't open xen devicemodel interface\n");
+        error_report("can't open xen devicemodel interface\n");
         xenforeignmemory_close(xen_fmem);
         xc_interface_close(xen_xc);
         return -1;