Skip to contentSkip to conversation

Xen PV backend 'qdevification'

PATCH Superseded Paul Durrant 3 participants 52 messages Dec 6, 2018 – Dec 10, 2018

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover Xen PV backend 'qdevification'

This series introduces a new QOM compliant framework for Xen PV backends. This is achieved by first moving the current non-compliant framework aside, before building up a new framework incrementally.

This series was prompted by a thread [1] started by Kevin Wolf in response to patches against xen_disk.c posted by Tim Smith. Therefore, alongside the patches introducing the new framework, other patches build up a QOM compliant replacement for 'xen_disk', called 'xen-qdisk'. Patch #16 swaps this new device into place (having establisheda mechanism to auto- instantiate devices that is compliant with existing Xen toolstacks in patch #15) and patch #18 then removes the old xen_disk code.

Subsequent series will port other Xen PV backends across to the new framework.

The series is also available as a repository branch [2] on xenbits.xen.org.

[1] https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg00259.html
[2] http://xenbits.xen.org/gitweb/?p=people/pauldu/qemu.git;a=shortlog;h=refs/heads/qom27

Paul Durrant (18):
xen: re-name XenDevice to XenLegacyDevice...
xen: introduce new 'XenBus' and 'XenDevice' object hierarchy
xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'
xen: create xenstore areas for XenDevice-s
xen: add xenstore watcher infrastructure
xen: add grant table interface for XenDevice-s
xen: add event channel interface for XenDevice-s
xen: duplicate xen_disk.c as basis of dataplane/xen-block.c
xen: remove unnecessary code from dataplane/xen-block.c
xen: add header and build dataplane/xen-block.c
xen: remove 'XenBlkDev' and 'blkdev' names from dataplane/xen-block
xen: remove 'ioreq' struct/varable/field names from
dataplane/xen-block.c
xen: purge 'blk' and 'ioreq' from function names in
dataplane/xen-block.c
xen: add implementations of xen-block connect and disconnect
functions...
xen: add a mechanism to automatically create XenDevice-s...
xen: automatically create XenBlockDevice-s
MAINTAINERS: add myself as a Xen maintainer
xen: remove the legacy 'xen_disk' backend

 MAINTAINERS                         |    5 +-
 hw/9pfs/xen-9p-backend.c            |   16 +-
 hw/block/Makefile.objs              |    2 +-
 hw/block/dataplane/Makefile.objs    |    1 +
 hw/block/dataplane/xen-block.c      |  814 ++++++++++++++++++++++++++
 hw/block/dataplane/xen-block.h      |   29 +
 hw/block/trace-events               |   11 +
 hw/block/xen-block.c                |  853 +++++++++++++++++++++++++++
 hw/block/xen_disk.c                 | 1011 --------------------------------
 hw/char/xen_console.c               |   12 +-
 hw/display/xenfb.c                  |   25 +-
 hw/i386/xen/xen-hvm.c               |    5 +-
 hw/i386/xen/xen-mapcache.c          |    2 +-
 hw/i386/xen/xen_platform.c          |    2 +-
 hw/net/xen_nic.c                    |   14 +-
 hw/usb/xen-usb.c                    |   25 +-
 hw/xen/Makefile.objs                |    2 +-
 hw/xen/trace-events                 |   25 +
 hw/xen/xen-backend.c                |   69 +++
 hw/xen/xen-bus-helper.c             |  181 ++++++
 hw/xen/xen-bus.c                    | 1094 +++++++++++++++++++++++++++++++++++
 hw/xen/xen-common.c                 |    2 +-
 hw/xen/xen-legacy-backend.c         |  853 +++++++++++++++++++++++++++
 hw/xen/xen_backend.c                |  845 ---------------------------
 hw/xen/xen_devconfig.c              |    2 +-
 hw/xen/xen_pt.c                     |    2 +-
 hw/xen/xen_pt_config_init.c         |    2 +-
 hw/xen/xen_pt_graphics.c            |    2 +-
 hw/xen/xen_pt_msi.c                 |    2 +-
 hw/xen/xen_pvdev.c                  |   20 +-
 hw/xenpv/xen_domainbuild.c          |    2 +-
 hw/xenpv/xen_machine_pv.c           |    5 +-
 include/hw/xen/xen-backend.h        |   26 +
 include/hw/xen/xen-block.h          |   79 +++
 include/hw/xen/xen-bus-helper.h     |   40 ++
 include/hw/xen/xen-bus.h            |  138 +++++
 include/hw/xen/xen-legacy-backend.h |  104 ++++
 include/hw/xen/xen_backend.h        |   99 ----
 include/hw/xen/xen_pvdev.h          |   38 +-
 include/qemu/module.h               |    3 +
 40 files changed, 4420 insertions(+), 2042 deletions(-)
 create mode 100644 hw/block/dataplane/xen-block.c
 create mode 100644 hw/block/dataplane/xen-block.h
 create mode 100644 hw/block/xen-block.c
 delete mode 100644 hw/block/xen_disk.c
 create mode 100644 hw/xen/xen-backend.c
 create mode 100644 hw/xen/xen-bus-helper.c
 create mode 100644 hw/xen/xen-bus.c
 create mode 100644 hw/xen/xen-legacy-backend.c
 delete mode 100644 hw/xen/xen_backend.c
 create mode 100644 include/hw/xen/xen-backend.h
 create mode 100644 include/hw/xen/xen-block.h
 create mode 100644 include/hw/xen/xen-bus-helper.h
 create mode 100644 include/hw/xen/xen-bus.h
 create mode 100644 include/hw/xen/xen-legacy-backend.h
 delete mode 100644 include/hw/xen/xen_backend.h

---
Cc: Anthony Perard <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: "Marc-André Lureau" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Smith <[email protected]>

v2:
- Fix boilerplates of introduced files and leave existing ones alone

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/18 xen: re-name XenDevice to XenLegacyDevice...

...and xen_backend.h to xen-legacy-backend.h

Rather than attempting to convert the existing backend infrastructure to be QOM compliant (which would be hard to do in an incremental fashion), subsequent patches will introduce a completely new framework for Xen PV backends. Hence it is necessary to re-name parts of existing code to avoid name clashes. The re-named 'legacy' infrastructure will be removed once all backends have been ported to the new framework.

This patch is purely cosmetic. No functional change.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Greg Kurz <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: "Marc-André Lureau" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Gerd Hoffmann <[email protected]>

---
 hw/9pfs/xen-9p-backend.c            |  16 +-
 hw/block/xen_disk.c                 |  24 +-
 hw/char/xen_console.c               |  12 +-
 hw/display/xenfb.c                  |  25 +-
 hw/i386/xen/xen-hvm.c               |   2 +-
 hw/i386/xen/xen-mapcache.c          |   2 +-
 hw/i386/xen/xen_platform.c          |   2 +-
 hw/net/xen_nic.c                    |  14 +-
 hw/usb/xen-usb.c                    |  25 +-
 hw/xen/Makefile.objs                |   2 +-
 hw/xen/xen-common.c                 |   2 +-
 hw/xen/xen-legacy-backend.c         | 854 ++++++++++++++++++++++++++++++++++++
 hw/xen/xen_backend.c                | 845 -----------------------------------
 hw/xen/xen_devconfig.c              |   2 +-
 hw/xen/xen_pt.c                     |   2 +-
 hw/xen/xen_pt_config_init.c         |   2 +-
 hw/xen/xen_pt_graphics.c            |   2 +-
 hw/xen/xen_pt_msi.c                 |   2 +-
 hw/xen/xen_pvdev.c                  |  20 +-
 hw/xenpv/xen_domainbuild.c          |   2 +-
 hw/xenpv/xen_machine_pv.c           |   2 +-
 include/hw/xen/xen-legacy-backend.h | 104 +++++
 include/hw/xen/xen_backend.h        |  99 -----
 include/hw/xen/xen_pvdev.h          |  38 +-
 24 files changed, 1059 insertions(+), 1041 deletions(-)
 create mode 100644 hw/xen/xen-legacy-backend.c
 delete mode 100644 hw/xen/xen_backend.c
 create mode 100644 include/hw/xen/xen-legacy-backend.h
 delete mode 100644 include/hw/xen/xen_backend.h
hw/9pfs/xen-9p-backend.c +8 -8
index 3f54a21..3859a06 100644
@@ -12,7 +12,7 @@
 
 #include "hw/hw.h"
 #include "hw/9pfs/9p.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "hw/9pfs/xen-9pfs.h"
 #include "qapi/error.h"
 #include "qemu/config-file.h"
@@ -45,7 +45,7 @@ typedef struct Xen9pfsRing {
 } Xen9pfsRing;
 
 typedef struct Xen9pfsDev {
-    struct XenDevice xendev;  /* must be first */
+    struct XenLegacyDevice xendev;  /* must be first */
     V9fsState state;
     char *path;
     char *security_model;
@@ -56,7 +56,7 @@ typedef struct Xen9pfsDev {
     Xen9pfsRing *rings;
 } Xen9pfsDev;
 
-static void xen_9pfs_disconnect(struct XenDevice *xendev);
+static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev);
 
 static void xen_9pfs_in_sg(Xen9pfsRing *ring,
                            struct iovec *in_sg,
@@ -243,7 +243,7 @@ static const V9fsTransport xen_9p_transport = {
     .push_and_notify = xen_9pfs_push_and_notify,
 };
 
-static int xen_9pfs_init(struct XenDevice *xendev)
+static int xen_9pfs_init(struct XenLegacyDevice *xendev)
 {
     return 0;
 }
@@ -305,7 +305,7 @@ static void xen_9pfs_evtchn_event(void *opaque)
     qemu_bh_schedule(ring->bh);
 }
 
-static void xen_9pfs_disconnect(struct XenDevice *xendev)
+static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev)
 {
     Xen9pfsDev *xen_9pdev = container_of(xendev, Xen9pfsDev, xendev);
     int i;
@@ -321,7 +321,7 @@ static void xen_9pfs_disconnect(struct XenDevice *xendev)
     }
 }
 
-static int xen_9pfs_free(struct XenDevice *xendev)
+static int xen_9pfs_free(struct XenLegacyDevice *xendev)
 {
     Xen9pfsDev *xen_9pdev = container_of(xendev, Xen9pfsDev, xendev);
     int i;
@@ -354,7 +354,7 @@ static int xen_9pfs_free(struct XenDevice *xendev)
     return 0;
 }
 
-static int xen_9pfs_connect(struct XenDevice *xendev)
+static int xen_9pfs_connect(struct XenLegacyDevice *xendev)
 {
     Error *err = NULL;
     int i;
@@ -467,7 +467,7 @@ out:
     return -1;
 }
 
-static void xen_9pfs_alloc(struct XenDevice *xendev)
+static void xen_9pfs_alloc(struct XenLegacyDevice *xendev)
 {
     xenstore_write_be_str(xendev, "versions", VERSIONS);
     xenstore_write_be_int(xendev, "max-rings", MAX_RINGS);
hw/block/xen_disk.c +12 -12
index 36eff94..75fe55f 100644
@@ -25,7 +25,7 @@
 #include <sys/uio.h>
 
 #include "hw/hw.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "xen_blkif.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/iothread.h"
@@ -63,7 +63,7 @@ struct ioreq {
 #define MAX_RING_PAGE_ORDER 4
 
 struct XenBlkDev {
-    struct XenDevice    xendev;  /* must be first */
+    struct XenLegacyDevice    xendev;  /* must be first */
     char                *params;
     char                *mode;
     char                *type;
@@ -179,7 +179,7 @@ static void ioreq_release(struct ioreq *ioreq, bool finish)
 static int ioreq_parse(struct ioreq *ioreq)
 {
     struct XenBlkDev *blkdev = ioreq->blkdev;
-    struct XenDevice *xendev = &blkdev->xendev;
+    struct XenLegacyDevice *xendev = &blkdev->xendev;
     size_t len;
     int i;
 
@@ -243,7 +243,7 @@ err:
 static int ioreq_grant_copy(struct ioreq *ioreq)
 {
     struct XenBlkDev *blkdev = ioreq->blkdev;
-    struct XenDevice *xendev = &blkdev->xendev;
+    struct XenLegacyDevice *xendev = &blkdev->xendev;
     XenGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     int i, count, rc;
     int64_t file_blk = blkdev->file_blk;
@@ -289,7 +289,7 @@ static void qemu_aio_complete(void *opaque, int ret)
 {
     struct ioreq *ioreq = opaque;
     struct XenBlkDev *blkdev = ioreq->blkdev;
-    struct XenDevice *xendev = &blkdev->xendev;
+    struct XenLegacyDevice *xendev = &blkdev->xendev;
 
     aio_context_acquire(blkdev->ctx);
 
@@ -608,7 +608,7 @@ static void blk_bh(void *opaque)
     aio_context_release(blkdev->ctx);
 }
 
-static void blk_alloc(struct XenDevice *xendev)
+static void blk_alloc(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
     Error *err = NULL;
@@ -628,7 +628,7 @@ static void blk_alloc(struct XenDevice *xendev)
 
 static void blk_parse_discard(struct XenBlkDev *blkdev)
 {
-    struct XenDevice *xendev = &blkdev->xendev;
+    struct XenLegacyDevice *xendev = &blkdev->xendev;
     int enable;
 
     blkdev->feature_discard = true;
@@ -642,7 +642,7 @@ static void blk_parse_discard(struct XenBlkDev *blkdev)
     }
 }
 
-static int blk_init(struct XenDevice *xendev)
+static int blk_init(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
     int info = 0;
@@ -737,7 +737,7 @@ out_error:
     return -1;
 }
 
-static int blk_connect(struct XenDevice *xendev)
+static int blk_connect(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
     int index, qflags;
@@ -941,7 +941,7 @@ static int blk_connect(struct XenDevice *xendev)
     return 0;
 }
 
-static void blk_disconnect(struct XenDevice *xendev)
+static void blk_disconnect(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
 
@@ -966,7 +966,7 @@ static void blk_disconnect(struct XenDevice *xendev)
     }
 }
 
-static int blk_free(struct XenDevice *xendev)
+static int blk_free(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
     struct ioreq *ioreq;
@@ -992,7 +992,7 @@ static int blk_free(struct XenDevice *xendev)
     return 0;
 }
 
-static void blk_event(struct XenDevice *xendev)
+static void blk_event(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
 
hw/char/xen_console.c +6 -6
index 44f7236..460adc1 100644
@@ -26,7 +26,7 @@
 #include "qapi/error.h"
 #include "hw/hw.h"
 #include "chardev/char-fe.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 
 #include <xen/io/console.h>
 
@@ -39,7 +39,7 @@ struct buffer {
 };
 
 struct XenConsole {
-    struct XenDevice  xendev;  /* must be first */
+    struct XenLegacyDevice  xendev;  /* must be first */
     struct buffer     buffer;
     char              console[XEN_BUFSIZE];
     int               ring_ref;
@@ -173,7 +173,7 @@ static void xencons_send(struct XenConsole *con)
 
 /* -------------------------------------------------------------------- */
 
-static int con_init(struct XenDevice *xendev)
+static int con_init(struct XenLegacyDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
     char *type, *dom, label[32];
@@ -222,7 +222,7 @@ out:
     return ret;
 }
 
-static int con_initialise(struct XenDevice *xendev)
+static int con_initialise(struct XenLegacyDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
     int limit;
@@ -259,7 +259,7 @@ static int con_initialise(struct XenDevice *xendev)
     return 0;
 }
 
-static void con_disconnect(struct XenDevice *xendev)
+static void con_disconnect(struct XenLegacyDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
@@ -276,7 +276,7 @@ static void con_disconnect(struct XenDevice *xendev)
     }
 }
 
-static void con_event(struct XenDevice *xendev)
+static void con_event(struct XenLegacyDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
hw/display/xenfb.c +13 -12
index 0330dc6..6202f11 100644
@@ -30,7 +30,7 @@
 #include "hw/hw.h"
 #include "ui/input.h"
 #include "ui/console.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 
 #include <xen/event_channel.h>
 #include <xen/io/fbif.h>
@@ -46,7 +46,7 @@
 /* -------------------------------------------------------------------- */
 
 struct common {
-    struct XenDevice  xendev;  /* must be first */
+    struct XenLegacyDevice  xendev;  /* must be first */
     void              *page;
 };
 
@@ -342,14 +342,14 @@ static QemuInputHandler xenfb_rel_mouse = {
     .sync  = xenfb_mouse_sync,
 };
 
-static int input_init(struct XenDevice *xendev)
+static int input_init(struct XenLegacyDevice *xendev)
 {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
     xenstore_write_be_int(xendev, "feature-raw-pointer", 1);
     return 0;
 }
 
-static int input_initialise(struct XenDevice *xendev)
+static int input_initialise(struct XenLegacyDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
@@ -361,7 +361,7 @@ static int input_initialise(struct XenDevice *xendev)
     return 0;
 }
 
-static void input_connected(struct XenDevice *xendev)
+static void input_connected(struct XenLegacyDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
@@ -395,7 +395,7 @@ static void input_connected(struct XenDevice *xendev)
     }
 }
 
-static void input_disconnect(struct XenDevice *xendev)
+static void input_disconnect(struct XenLegacyDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
@@ -410,7 +410,7 @@ static void input_disconnect(struct XenDevice *xendev)
     common_unbind(&in->c);
 }
 
-static void input_event(struct XenDevice *xendev)
+static void input_event(struct XenLegacyDevice *xendev)
 {
     struct XenInput *xenfb = container_of(xendev, struct XenInput, c.xendev);
     struct xenkbd_page *page = xenfb->c.page;
@@ -867,7 +867,7 @@ static void xenfb_handle_events(struct XenFB *xenfb)
     page->out_cons = cons;
 }
 
-static int fb_init(struct XenDevice *xendev)
+static int fb_init(struct XenLegacyDevice *xendev)
 {
 #ifdef XENFB_TYPE_RESIZE
     xenstore_write_be_int(xendev, "feature-resize", 1);
@@ -875,7 +875,7 @@ static int fb_init(struct XenDevice *xendev)
     return 0;
 }
 
-static int fb_initialise(struct XenDevice *xendev)
+static int fb_initialise(struct XenLegacyDevice *xendev)
 {
     struct XenFB *fb = container_of(xendev, struct XenFB, c.xendev);
     struct xenfb_page *fb_page;
@@ -912,7 +912,7 @@ static int fb_initialise(struct XenDevice *xendev)
     return 0;
 }
 
-static void fb_disconnect(struct XenDevice *xendev)
+static void fb_disconnect(struct XenLegacyDevice *xendev)
 {
     struct XenFB *fb = container_of(xendev, struct XenFB, c.xendev);
 
@@ -935,7 +935,8 @@ static void fb_disconnect(struct XenDevice *xendev)
     fb->bug_trigger    = 0;
 }
 
-static void fb_frontend_changed(struct XenDevice *xendev, const char *node)
+static void fb_frontend_changed(struct XenLegacyDevice *xendev,
+                                const char *node)
 {
     struct XenFB *fb = container_of(xendev, struct XenFB, c.xendev);
 
@@ -953,7 +954,7 @@ static void fb_frontend_changed(struct XenDevice *xendev, const char *node)
     }
 }
 
-static void fb_event(struct XenDevice *xendev)
+static void fb_event(struct XenLegacyDevice *xendev)
 {
     struct XenFB *xenfb = container_of(xendev, struct XenFB, c.xendev);
 
hw/i386/xen/xen-hvm.c +1 -1
index 935a367..1d63763 100644
@@ -16,7 +16,7 @@
 #include "hw/i386/pc.h"
 #include "hw/i386/apic-msidef.h"
 #include "hw/xen/xen_common.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qemu/error-report.h"
hw/i386/xen/xen-mapcache.c +1 -1
index 4e4f069..9134a7b 100644
@@ -14,7 +14,7 @@
 
 #include <sys/resource.h>
 
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "qemu/bitmap.h"
 
 #include <xen/hvm/params.h>
hw/i386/xen/xen_platform.c +1 -1
index deb7a0c..16afb54 100644
@@ -30,7 +30,7 @@
 #include "hw/pci/pci.h"
 #include "hw/irq.h"
 #include "hw/xen/xen_common.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "trace.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
hw/net/xen_nic.c +7 -7
index 46a8dbf..37cda8e 100644
@@ -28,14 +28,14 @@
 #include "net/net.h"
 #include "net/checksum.h"
 #include "net/util.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 
 #include <xen/io/netif.h>
 
 /* ------------------------------------------------------------- */
 
 struct XenNetDev {
-    struct XenDevice      xendev;  /* must be first */
+    struct XenLegacyDevice      xendev;  /* must be first */
     char                  *mac;
     int                   tx_work;
     int                   tx_ring_ref;
@@ -276,7 +276,7 @@ static NetClientInfo net_xen_info = {
     .receive = net_rx_packet,
 };
 
-static int net_init(struct XenDevice *xendev)
+static int net_init(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
 
@@ -308,7 +308,7 @@ static int net_init(struct XenDevice *xendev)
     return 0;
 }
 
-static int net_connect(struct XenDevice *xendev)
+static int net_connect(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
     int rx_copy;
@@ -363,7 +363,7 @@ static int net_connect(struct XenDevice *xendev)
     return 0;
 }
 
-static void net_disconnect(struct XenDevice *xendev)
+static void net_disconnect(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
 
@@ -379,14 +379,14 @@ static void net_disconnect(struct XenDevice *xendev)
     }
 }
 
-static void net_event(struct XenDevice *xendev)
+static void net_event(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
     net_tx_packets(netdev);
     qemu_flush_queued_packets(qemu_get_queue(netdev->nic));
 }
 
-static int net_free(struct XenDevice *xendev)
+static int net_free(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
 
hw/usb/xen-usb.c +13 -12
index 5b2e21e..9b2da6e 100644
@@ -27,7 +27,7 @@
 #include "qemu/option.h"
 #include "hw/sysbus.h"
 #include "hw/usb.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "monitor/qdev.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
@@ -99,7 +99,7 @@ struct usbback_hotplug {
 };
 
 struct usbback_info {
-    struct XenDevice         xendev;  /* must be first */
+    struct XenLegacyDevice         xendev;  /* must be first */
     USBBus                   bus;
     void                     *urb_sring;
     void                     *conn_sring;
@@ -142,7 +142,7 @@ static int usbback_gnttab_map(struct usbback_req *usbback_req)
     unsigned int nr_segs, i, prot;
     uint32_t ref[USBIF_MAX_SEGMENTS_PER_REQUEST];
     struct usbback_info *usbif = usbback_req->usbif;
-    struct XenDevice *xendev = &usbif->xendev;
+    struct XenLegacyDevice *xendev = &usbif->xendev;
     struct usbif_request_segment *seg;
     void *addr;
 
@@ -220,7 +220,7 @@ static int usbback_gnttab_map(struct usbback_req *usbback_req)
 
 static int usbback_init_packet(struct usbback_req *usbback_req)
 {
-    struct XenDevice *xendev = &usbback_req->usbif->xendev;
+    struct XenLegacyDevice *xendev = &usbback_req->usbif->xendev;
     USBPacket *packet = &usbback_req->packet;
     USBDevice *dev = usbback_req->stub->dev;
     USBEndpoint *ep;
@@ -279,7 +279,7 @@ static void usbback_do_response(struct usbback_req *usbback_req, int32_t status,
 {
     struct usbback_info *usbif;
     struct usbif_urb_response *res;
-    struct XenDevice *xendev;
+    struct XenLegacyDevice *xendev;
     unsigned int notify;
 
     usbif = usbback_req->usbif;
@@ -824,7 +824,7 @@ static void usbback_process_port(struct usbback_info *usbif, unsigned port)
     g_free(busid);
 }
 
-static void usbback_disconnect(struct XenDevice *xendev)
+static void usbback_disconnect(struct XenLegacyDevice *xendev)
 {
     struct usbback_info *usbif;
     unsigned int i;
@@ -853,7 +853,7 @@ static void usbback_disconnect(struct XenDevice *xendev)
     TR_BUS(xendev, "finished\n");
 }
 
-static int usbback_connect(struct XenDevice *xendev)
+static int usbback_connect(struct XenLegacyDevice *xendev)
 {
     struct usbback_info *usbif;
     struct usbif_urb_sring *urb_sring;
@@ -909,7 +909,8 @@ static int usbback_connect(struct XenDevice *xendev)
     return 0;
 }
 
-static void usbback_backend_changed(struct XenDevice *xendev, const char *node)
+static void usbback_backend_changed(struct XenLegacyDevice *xendev,
+                                    const char *node)
 {
     struct usbback_info *usbif;
     unsigned int i;
@@ -922,7 +923,7 @@ static void usbback_backend_changed(struct XenDevice *xendev, const char *node)
     }
 }
 
-static int usbback_init(struct XenDevice *xendev)
+static int usbback_init(struct XenLegacyDevice *xendev)
 {
     struct usbback_info *usbif;
 
@@ -1001,7 +1002,7 @@ static USBPortOps xen_usb_port_ops = {
 static USBBusOps xen_usb_bus_ops = {
 };
 
-static void usbback_alloc(struct XenDevice *xendev)
+static void usbback_alloc(struct XenLegacyDevice *xendev)
 {
     struct usbback_info *usbif;
     USBPort *p;
@@ -1027,7 +1028,7 @@ static void usbback_alloc(struct XenDevice *xendev)
     xen_be_set_max_grant_refs(xendev, max_grants);
 }
 
-static int usbback_free(struct XenDevice *xendev)
+static int usbback_free(struct XenLegacyDevice *xendev)
 {
     struct usbback_info *usbif;
     struct usbback_req *usbback_req;
@@ -1066,7 +1067,7 @@ static int usbback_free(struct XenDevice *xendev)
     return 0;
 }
 
-static void usbback_event(struct XenDevice *xendev)
+static void usbback_event(struct XenLegacyDevice *xendev)
 {
     struct usbback_info *usbif;
 
hw/xen/Makefile.objs +1 -1
index 9ea5c73..3f64a44 100644
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen_backend.o xen_devconfig.o xen_pvdev.o xen-common.o
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
hw/xen/xen-common.c +1 -1
index 6ec14c7..ef130b2 100644
@@ -10,7 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "chardev/char.h"
 #include "sysemu/accel.h"
 #include "migration/misc.h"
hw/xen/xen-legacy-backend.c new file +854 -0

854 lines not on this page · raw message

hw/xen/xen_backend.c deleted +0 -845

845 lines not on this page · raw message

hw/xen/xen_devconfig.c +1 -1
index aebc19b..1b30bd7 100644
@@ -1,5 +1,5 @@
 #include "qemu/osdep.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "qemu/option.h"
 #include "sysemu/blockdev.h"
 
hw/xen/xen_pt.c +1 -1
index f1f3a37..b20bf3a 100644
@@ -59,7 +59,7 @@
 #include "hw/pci/pci.h"
 #include "hw/xen/xen.h"
 #include "hw/i386/pc.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "xen_pt.h"
 #include "qemu/range.h"
 #include "exec/address-spaces.h"
hw/xen/xen_pt_config_init.c +1 -1
index 47f9010..8111204 100644
@@ -15,7 +15,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/timer.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "xen_pt.h"
 
 #define XEN_PT_MERGE_VALUE(value, data, val_mask) \
hw/xen/xen_pt_graphics.c +1 -1
index 135c8df..130cc6c 100644
@@ -5,7 +5,7 @@
 #include "qapi/error.h"
 #include "xen_pt.h"
 #include "xen-host-pci-device.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 
 static unsigned long igd_guest_opregion;
 static unsigned long igd_host_opregion;
hw/xen/xen_pt_msi.c +1 -1
index cc514f9..fb4b887 100644
@@ -11,7 +11,7 @@
 
 #include "qemu/osdep.h"
 
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "xen_pt.h"
 #include "hw/i386/apic-msidef.h"
 
hw/xen/xen_pvdev.c +10 -10
index aed783e..61de091 100644
@@ -20,7 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "hw/qdev-core.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "hw/xen/xen_pvdev.h"
 
 /* private */
@@ -34,7 +34,7 @@ struct xs_dirs {
 static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup =
     QTAILQ_HEAD_INITIALIZER(xs_cleanup);
 
-static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs =
+static QTAILQ_HEAD(XenLegacyDeviceHead, XenLegacyDevice) xendevs =
     QTAILQ_HEAD_INITIALIZER(xendevs);
 
 /* ------------------------------------------------------------- */
@@ -195,7 +195,7 @@ const char *xenbus_strstate(enum xenbus_state state)
  *  2 == noisy debug messages (logfile only).
  *  3 == will flood your log (logfile only).
  */
-void xen_pv_printf(struct XenDevice *xendev, int msg_level,
+void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
                    const char *fmt, ...)
 {
     va_list args;
@@ -230,7 +230,7 @@ void xen_pv_printf(struct XenDevice *xendev, int msg_level,
 
 void xen_pv_evtchn_event(void *opaque)
 {
-    struct XenDevice *xendev = opaque;
+    struct XenLegacyDevice *xendev = opaque;
     evtchn_port_t port;
 
     port = xenevtchn_pending(xendev->evtchndev);
@@ -247,7 +247,7 @@ void xen_pv_evtchn_event(void *opaque)
     }
 }
 
-void xen_pv_unbind_evtchn(struct XenDevice *xendev)
+void xen_pv_unbind_evtchn(struct XenLegacyDevice *xendev)
 {
     if (xendev->local_port == -1) {
         return;
@@ -258,16 +258,16 @@ void xen_pv_unbind_evtchn(struct XenDevice *xendev)
     xendev->local_port = -1;
 }
 
-int xen_pv_send_notify(struct XenDevice *xendev)
+int xen_pv_send_notify(struct XenLegacyDevice *xendev)
 {
     return xenevtchn_notify(xendev->evtchndev, xendev->local_port);
 }
 
 /* ------------------------------------------------------------- */
 
-struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev)
+struct XenLegacyDevice *xen_pv_find_xendev(const char *type, int dom, int dev)
 {
-    struct XenDevice *xendev;
+    struct XenLegacyDevice *xendev;
 
     QTAILQ_FOREACH(xendev, &xendevs, next) {
         if (xendev->dom != dom) {
@@ -287,7 +287,7 @@ struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev)
 /*
  * release xen backend device.
  */
-void xen_pv_del_xendev(struct XenDevice *xendev)
+void xen_pv_del_xendev(struct XenLegacyDevice *xendev)
 {
     if (xendev->ops->free) {
         xendev->ops->free(xendev);
@@ -312,7 +312,7 @@ void xen_pv_del_xendev(struct XenDevice *xendev)
     qdev_unplug(&xendev->qdev, NULL);
 }
 
-void xen_pv_insert_xendev(struct XenDevice *xendev)
+void xen_pv_insert_xendev(struct XenLegacyDevice *xendev)
 {
     QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
 }
hw/xenpv/xen_domainbuild.c +1 -1
index 188acac..deb28cf 100644
@@ -1,6 +1,6 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "xen_domainbuild.h"
 #include "qemu/timer.h"
 #include "qemu/log.h"
hw/xenpv/xen_machine_pv.c +1 -1
index 44d67b8..8c86fb7 100644
@@ -26,7 +26,7 @@
 #include "qemu/error-report.h"
 #include "hw/hw.h"
 #include "hw/boards.h"
-#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen-legacy-backend.h"
 #include "xen_domainbuild.h"
 #include "sysemu/block-backend.h"
 
include/hw/xen/xen-legacy-backend.h new file +104 -0

104 lines not on this page · raw message

include/hw/xen/xen_backend.h deleted +0 -99

99 lines not on this page · raw message

include/hw/xen/xen_pvdev.h +20 -18
index d473e9b..83e5174 100644
@@ -6,7 +6,7 @@
 
 #define XEN_BUFSIZE 1024
 
-struct XenDevice;
+struct XenLegacyDevice;
 
 /* driver uses grant tables  ->  open gntdev device (xendev->gnttabdev) */
 #define DEVOPS_FLAG_NEED_GNTDEV   1
@@ -16,19 +16,21 @@ struct XenDevice;
 struct XenDevOps {
     size_t    size;
     uint32_t  flags;
-    void      (*alloc)(struct XenDevice *xendev);
-    int       (*init)(struct XenDevice *xendev);
-    int       (*initialise)(struct XenDevice *xendev);
-    void      (*connected)(struct XenDevice *xendev);
-    void      (*event)(struct XenDevice *xendev);
-    void      (*disconnect)(struct XenDevice *xendev);
-    int       (*free)(struct XenDevice *xendev);
-    void      (*backend_changed)(struct XenDevice *xendev, const char *node);
-    void      (*frontend_changed)(struct XenDevice *xendev, const char *node);
+    void      (*alloc)(struct XenLegacyDevice *xendev);
+    int       (*init)(struct XenLegacyDevice *xendev);
+    int       (*initialise)(struct XenLegacyDevice *xendev);
+    void      (*connected)(struct XenLegacyDevice *xendev);
+    void      (*event)(struct XenLegacyDevice *xendev);
+    void      (*disconnect)(struct XenLegacyDevice *xendev);
+    int       (*free)(struct XenLegacyDevice *xendev);
+    void      (*backend_changed)(struct XenLegacyDevice *xendev,
+                                 const char *node);
+    void      (*frontend_changed)(struct XenLegacyDevice *xendev,
+                                  const char *node);
     int       (*backend_register)(void);
 };
 
-struct XenDevice {
+struct XenLegacyDevice {
     DeviceState        qdev;
     const char         *type;
     int                dom;
@@ -49,7 +51,7 @@ struct XenDevice {
     xengnttab_handle   *gnttabdev;
 
     struct XenDevOps   *ops;
-    QTAILQ_ENTRY(XenDevice) next;
+    QTAILQ_ENTRY(XenLegacyDevice) next;
 };
 
 /* ------------------------------------------------------------- */
@@ -66,14 +68,14 @@ void xenstore_update(void *unused);
 const char *xenbus_strstate(enum xenbus_state state);
 
 void xen_pv_evtchn_event(void *opaque);
-void xen_pv_insert_xendev(struct XenDevice *xendev);
-void xen_pv_del_xendev(struct XenDevice *xendev);
-struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev);
+void xen_pv_insert_xendev(struct XenLegacyDevice *xendev);
+void xen_pv_del_xendev(struct XenLegacyDevice *xendev);
+struct XenLegacyDevice *xen_pv_find_xendev(const char *type, int dom, int dev);
 
-void xen_pv_unbind_evtchn(struct XenDevice *xendev);
-int xen_pv_send_notify(struct XenDevice *xendev);
+void xen_pv_unbind_evtchn(struct XenLegacyDevice *xendev);
+int xen_pv_send_notify(struct XenLegacyDevice *xendev);
 
-void xen_pv_printf(struct XenDevice *xendev, int msg_level,
+void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
                    const char *fmt, ...)  GCC_FMT_ATTR(3, 4);
 
 #endif /* QEMU_HW_XEN_PVDEV_H */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH v2 2/18 xen: introduce new 'XenBus' and 'XenDevice' object hierarchy

In reply to Paul Durrant

This patch adds the basic boilerplate for a 'XenBus' object that will act as a parent to 'XenDevice' PV backends.
A new 'XenBridge' object is also added to connect XenBus to the system bus.

The XenBus object is instantiated by a new xen_bus_init() function called from the same sites as the legacy xen_be_init() function.

Subsequent patches will flesh-out the functionality of these objects.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

v2:
- Fix boilerplate
- Make xen-bus hotplug capable

---
 hw/i386/xen/xen-hvm.c     |   3 ++
 hw/xen/Makefile.objs      |   2 +-
 hw/xen/trace-events       |   6 +++
 hw/xen/xen-bus.c          | 131 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/xenpv/xen_machine_pv.c |   3 ++
 include/hw/xen/xen-bus.h  |  55 +++++++++++++++++++
 6 files changed, 199 insertions(+), 1 deletion(-)
 create mode 100644 hw/xen/xen-bus.c
 create mode 100644 include/hw/xen/xen-bus.h
hw/i386/xen/xen-hvm.c +3 -0
index 1d63763..4497f75 100644
@@ -17,6 +17,7 @@
 #include "hw/i386/apic-msidef.h"
 #include "hw/xen/xen_common.h"
 #include "hw/xen/xen-legacy-backend.h"
+#include "hw/xen/xen-bus.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qemu/error-report.h"
@@ -1479,6 +1480,8 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
     QLIST_INIT(&state->dev_list);
     device_listener_register(&state->device_listener);
 
+    xen_bus_init();
+
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         error_report("xen backend core setup failed");
hw/xen/Makefile.objs +1 -1
index 3f64a44..d9d6d7b 100644
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o xen-bus.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
hw/xen/trace-events +6 -0
index c7e7a3b..0172cd4 100644
@@ -12,3 +12,9 @@ xen_unmap_portio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id:
 xen_map_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x"
 xen_unmap_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x"
 xen_domid_restrict(int err) "err: %u"
+
+# include/hw/xen/xen-bus.c
+xen_bus_realize(void) ""
+xen_bus_unrealize(void) ""
+xen_device_realize(const char *type) "type: %s"
+xen_device_unrealize(const char *type) "type: %s"
hw/xen/xen-bus.c new file +131 -0

131 lines not on this page · raw message

hw/xenpv/xen_machine_pv.c +3 -0
index 8c86fb7..608e591 100644
@@ -27,6 +27,7 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
 #include "hw/xen/xen-legacy-backend.h"
+#include "hw/xen/xen-bus.h"
 #include "xen_domainbuild.h"
 #include "sysemu/block-backend.h"
 
@@ -93,6 +94,8 @@ static void xen_init_pv(MachineState *machine)
         xen_config_dev_nic(nd_table + i);
     }
 
+    xen_bus_init();
+
     /* config cleanup hook */
     atexit(xen_config_cleanup);
 }
include/hw/xen/xen-bus.h new file +55 -0

55 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 2/18
#3 lore raw

Re: [Qemu-devel] [PATCH v2 02/18] xen: introduce new 'XenBus' and 'XenDevice' object hierarchy

Quoted 130 lines · Paul Durrant

This patch adds the basic boilerplate for a 'XenBus' object that will act as a parent to 'XenDevice' PV backends.
A new 'XenBridge' object is also added to connect XenBus to the system bus.

The XenBus object is instantiated by a new xen_bus_init() function called from the same sites as the legacy xen_be_init() function.

Subsequent patches will flesh-out the functionality of these objects.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

v2:
- Fix boilerplate
- Make xen-bus hotplug capable

---
 hw/i386/xen/xen-hvm.c     |   3 ++
 hw/xen/Makefile.objs      |   2 +-
 hw/xen/trace-events       |   6 +++
 hw/xen/xen-bus.c          | 131 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/xenpv/xen_machine_pv.c |   3 ++
 include/hw/xen/xen-bus.h  |  55 +++++++++++++++++++
 6 files changed, 199 insertions(+), 1 deletion(-)
 create mode 100644 hw/xen/xen-bus.c
 create mode 100644 include/hw/xen/xen-bus.h
hw/i386/xen/xen-hvm.c +3 -0
index 1d63763..4497f75 100644
@@ -17,6 +17,7 @@
 #include "hw/i386/apic-msidef.h"
 #include "hw/xen/xen_common.h"
 #include "hw/xen/xen-legacy-backend.h"
+#include "hw/xen/xen-bus.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qemu/error-report.h"
@@ -1479,6 +1480,8 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
     QLIST_INIT(&state->dev_list);
     device_listener_register(&state->device_listener);
 
+    xen_bus_init();
+
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         error_report("xen backend core setup failed");
hw/xen/Makefile.objs +1 -1
index 3f64a44..d9d6d7b 100644
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o xen-bus.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
hw/xen/trace-events +6 -0
index c7e7a3b..0172cd4 100644
@@ -12,3 +12,9 @@ xen_unmap_portio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id:
 xen_map_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x"
 xen_unmap_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x"
 xen_domid_restrict(int err) "err: %u"
+
+# include/hw/xen/xen-bus.c
+xen_bus_realize(void) ""
+xen_bus_unrealize(void) ""
+xen_device_realize(const char *type) "type: %s"
+xen_device_unrealize(const char *type) "type: %s"
hw/xen/xen-bus.c new file +45 -0
new file mode 100644
index 0000000..1385bab
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/xen/xen-bus.h"
+#include "qapi/error.h"
+#include "trace.h"
+
+static void xen_bus_unrealize(BusState *bus, Error **errp)
+{
+    trace_xen_bus_unrealize();
+}
+
+static void xen_bus_realize(BusState *bus, Error **errp)
+{
+    trace_xen_bus_realize();
+}
+
+static void xen_bus_class_init(ObjectClass *class, void *data)
+{
+    BusClass *bus_class = BUS_CLASS(class);
+
+    bus_class->realize = xen_bus_realize;
+    bus_class->unrealize = xen_bus_unrealize;
+}
+
+static const TypeInfo xen_bus_type_info = {
+    .name = TYPE_XEN_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = sizeof(XenBus),
+    .class_size = sizeof(XenBusClass),
+    .class_init = xen_bus_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_HOTPLUG_HANDLER },
+        { }
+    },
+};
+
+static void xen_device_unrealize(DeviceState *dev, Error **errp)

hw/xen/xen-bus.c line 55

Quoted 10 lines
hw/xen/xen-bus.c new file +10 -0
+{
+    XenDevice *xendev = XEN_DEVICE(dev);
+    XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev);
+    const char *type = object_get_typename(OBJECT(xendev));
+    Error *local_err = NULL;
+
+    trace_xen_device_unrealize(type);
+
+    if (xendev_class->unrealize) {
+        xendev_class->unrealize(xendev, &local_err);

Since all you do here is propagate the error, you could even pass errp' to unrealize(), instead of having local_err'. That "for readability", as explained in "qapi/error.h".

hw/xen/xen-bus.c line 61

Quoted 6 lines
hw/xen/xen-bus.c new file +6 -0
+        if (local_err) {
+            error_propagate(errp, local_err);
+        }
+    }
+}
+

With that nit fixed:

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Re: [PATCH v2 02/18] xen: introduce new 'XenBus' and 'XenDevice' object hierarchy

Quoted 161 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 12:15
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Stefano Stabellini <[email protected]>; Michael S. Tsirkin <[email protected]>; Marcel Apfelbaum <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>; Eduardo Habkost <[email protected]>
Subject: Re: [PATCH v2 02/18] xen: introduce new 'XenBus' and 'XenDevice' object hierarchy

Quoted 1 line · Paul Durrant

This patch adds the basic boilerplate for a 'XenBus' object that will

act

Quoted 2 lines

as a parent to 'XenDevice' PV backends.
A new 'XenBridge' object is also added to connect XenBus to the system

bus.

Quoted 2 lines

The XenBus object is instantiated by a new xen_bus_init() function

called

Quoted 14 lines

from the same sites as the legacy xen_be_init() function.

Subsequent patches will flesh-out the functionality of these objects.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

Quoted 8 lines

v2:
- Fix boilerplate
- Make xen-bus hotplug capable

---
 hw/i386/xen/xen-hvm.c     |   3 ++
 hw/xen/Makefile.objs      |   2 +-
 hw/xen/trace-events       |   6 +++
 hw/xen/xen-bus.c          | 131

++++++++++++++++++++++++++++++++++++++++++++++

hw/i386/xen/xen-hvm.c void xen_hvm_init(PCMachineState *pcms,

Quoted 19 lines
 hw/xenpv/xen_machine_pv.c |   3 ++
 include/hw/xen/xen-bus.h  |  55 +++++++++++++++++++
 6 files changed, 199 insertions(+), 1 deletion(-)
 create mode 100644 hw/xen/xen-bus.c
 create mode 100644 include/hw/xen/xen-bus.h
hw/i386/xen/xen-hvm.c +1 -0
index 1d63763..4497f75 100644
@@ -17,6 +17,7 @@
 #include "hw/i386/apic-msidef.h"
 #include "hw/xen/xen_common.h"
 #include "hw/xen/xen-legacy-backend.h"
+#include "hw/xen/xen-bus.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qemu/error-report.h"
@@ -1479,6 +1480,8 @@ void xen_hvm_init(PCMachineState *pcms,

MemoryRegion **ram_memory)

Quoted 13 lines
hw/i386/xen/xen-hvm.c +2 -0
     QLIST_INIT(&state->dev_list);
     device_listener_register(&state->device_listener);
 
+    xen_bus_init();
+
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         error_report("xen backend core setup failed");
hw/xen/Makefile.objs +0 -0
index 3f64a44..d9d6d7b 100644

hw/xen/Makefile.objs line 2

Quoted 2 lines
hw/xen/Makefile.objs +0 -1
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o

xen_pvdev.o xen-common.o

hw/xen/Makefile.objs line 2

Quoted 1 line
hw/xen/Makefile.objs +1 -0
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o

xen_pvdev.o xen-common.o xen-bus.o

hw/xen/Makefile.objs line 4

Quoted 3 lines
hw/xen/Makefile.objs +0 -0
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o

xen_pt_graphics.o xen_pt_msi.o

hw/xen/trace-events xen_unmap_portio_range(uint32_t id, uint64_t

Quoted 5 lines
hw/xen/trace-events +0 -0
index c7e7a3b..0172cd4 100644
@@ -12,3 +12,9 @@ xen_unmap_portio_range(uint32_t id, uint64_t

start_addr, uint64_t end_addr) "id:

hw/xen/trace-events xen_unmap_portio_range(uint32_t id, uint64_t · line 12

Quoted 1 line
hw/xen/trace-events +0 -0
 xen_map_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func)

"id: %u bdf: %02x.%02x.%02x"

hw/xen/trace-events xen_unmap_portio_range(uint32_t id, uint64_t · line 13

Quoted 1 line
hw/xen/trace-events +0 -0
 xen_unmap_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func)

"id: %u bdf: %02x.%02x.%02x"

Quoted 13 lines
hw/xen/trace-events +6 -0
 xen_domid_restrict(int err) "err: %u"
+
+# include/hw/xen/xen-bus.c
+xen_bus_realize(void) ""
+xen_bus_unrealize(void) ""
+xen_device_realize(const char *type) "type: %s"
+xen_device_unrealize(const char *type) "type: %s"
hw/xen/xen-bus.c new file +0 -0
new file mode 100644
index 0000000..1385bab

hw/xen/xen-bus.c line 4

Quoted 4 lines
hw/xen/xen-bus.c new file +4 -0
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or

later.

Quoted 47 lines
hw/xen/xen-bus.c new file +47 -0
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/xen/xen-bus.h"
+#include "qapi/error.h"
+#include "trace.h"
+
+static void xen_bus_unrealize(BusState *bus, Error **errp)
+{
+    trace_xen_bus_unrealize();
+}
+
+static void xen_bus_realize(BusState *bus, Error **errp)
+{
+    trace_xen_bus_realize();
+}
+
+static void xen_bus_class_init(ObjectClass *class, void *data)
+{
+    BusClass *bus_class = BUS_CLASS(class);
+
+    bus_class->realize = xen_bus_realize;
+    bus_class->unrealize = xen_bus_unrealize;
+}
+
+static const TypeInfo xen_bus_type_info = {
+    .name = TYPE_XEN_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = sizeof(XenBus),
+    .class_size = sizeof(XenBusClass),
+    .class_init = xen_bus_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_HOTPLUG_HANDLER },
+        { }
+    },
+};
+
+static void xen_device_unrealize(DeviceState *dev, Error **errp)
+{
+    XenDevice *xendev = XEN_DEVICE(dev);
+    XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev);
+    const char *type = object_get_typename(OBJECT(xendev));
+    Error *local_err = NULL;
+
Quoted 8 lines

hw/xen/xen-bus.c line 55

Quoted 4 lines
hw/xen/xen-bus.c new file +4 -0
+    trace_xen_device_unrealize(type);
+
+    if (xendev_class->unrealize) {
+        xendev_class->unrealize(xendev, &local_err);

Since all you do here is propagate the error, you could even pass errp' to unrealize(), instead of having local_err'. That "for readability", as explained in "qapi/error.h".

Yes, true.

Quoted 11 lines

hw/xen/xen-bus.c line 61

Quoted 7 lines
hw/xen/xen-bus.c new file +6 -0
+        if (local_err) {
+            error_propagate(errp, local_err);
+        }
+    }
+}
+

With that nit fixed:

Thanks :-)

Paul

Quoted 4 lines

Thanks,

--
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [Qemu-devel] [PATCH v2 02/18] xen: introduce new 'XenBus' and 'XenDevice' object hierarchy

In reply to Anthony PERARD
Quoted 161 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 12:15
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Stefano Stabellini <[email protected]>; Michael S. Tsirkin <[email protected]>; Marcel Apfelbaum <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>; Eduardo Habkost <[email protected]>
Subject: Re: [PATCH v2 02/18] xen: introduce new 'XenBus' and 'XenDevice' object hierarchy

Quoted 1 line · Paul Durrant

This patch adds the basic boilerplate for a 'XenBus' object that will

act

Quoted 2 lines

as a parent to 'XenDevice' PV backends.
A new 'XenBridge' object is also added to connect XenBus to the system

bus.

Quoted 2 lines

The XenBus object is instantiated by a new xen_bus_init() function

called

Quoted 14 lines

from the same sites as the legacy xen_be_init() function.

Subsequent patches will flesh-out the functionality of these objects.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>

Quoted 8 lines

v2:
- Fix boilerplate
- Make xen-bus hotplug capable

---
 hw/i386/xen/xen-hvm.c     |   3 ++
 hw/xen/Makefile.objs      |   2 +-
 hw/xen/trace-events       |   6 +++
 hw/xen/xen-bus.c          | 131

++++++++++++++++++++++++++++++++++++++++++++++

hw/i386/xen/xen-hvm.c void xen_hvm_init(PCMachineState *pcms,

Quoted 19 lines
 hw/xenpv/xen_machine_pv.c |   3 ++
 include/hw/xen/xen-bus.h  |  55 +++++++++++++++++++
 6 files changed, 199 insertions(+), 1 deletion(-)
 create mode 100644 hw/xen/xen-bus.c
 create mode 100644 include/hw/xen/xen-bus.h
hw/i386/xen/xen-hvm.c +1 -0
index 1d63763..4497f75 100644
@@ -17,6 +17,7 @@
 #include "hw/i386/apic-msidef.h"
 #include "hw/xen/xen_common.h"
 #include "hw/xen/xen-legacy-backend.h"
+#include "hw/xen/xen-bus.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qemu/error-report.h"
@@ -1479,6 +1480,8 @@ void xen_hvm_init(PCMachineState *pcms,

MemoryRegion **ram_memory)

Quoted 13 lines
hw/i386/xen/xen-hvm.c +2 -0
     QLIST_INIT(&state->dev_list);
     device_listener_register(&state->device_listener);
 
+    xen_bus_init();
+
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
         error_report("xen backend core setup failed");
hw/xen/Makefile.objs +0 -0
index 3f64a44..d9d6d7b 100644

hw/xen/Makefile.objs line 2

Quoted 2 lines
hw/xen/Makefile.objs +0 -1
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o

xen_pvdev.o xen-common.o

hw/xen/Makefile.objs line 2

Quoted 1 line
hw/xen/Makefile.objs +1 -0
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o

xen_pvdev.o xen-common.o xen-bus.o

hw/xen/Makefile.objs line 4

Quoted 3 lines
hw/xen/Makefile.objs +0 -0
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o

xen_pt_graphics.o xen_pt_msi.o

hw/xen/trace-events xen_unmap_portio_range(uint32_t id, uint64_t

Quoted 5 lines
hw/xen/trace-events +0 -0
index c7e7a3b..0172cd4 100644
@@ -12,3 +12,9 @@ xen_unmap_portio_range(uint32_t id, uint64_t

start_addr, uint64_t end_addr) "id:

hw/xen/trace-events xen_unmap_portio_range(uint32_t id, uint64_t · line 12

Quoted 1 line
hw/xen/trace-events +0 -0
 xen_map_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func)

"id: %u bdf: %02x.%02x.%02x"

hw/xen/trace-events xen_unmap_portio_range(uint32_t id, uint64_t · line 13

Quoted 1 line
hw/xen/trace-events +0 -0
 xen_unmap_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func)

"id: %u bdf: %02x.%02x.%02x"

Quoted 13 lines
hw/xen/trace-events +6 -0
 xen_domid_restrict(int err) "err: %u"
+
+# include/hw/xen/xen-bus.c
+xen_bus_realize(void) ""
+xen_bus_unrealize(void) ""
+xen_device_realize(const char *type) "type: %s"
+xen_device_unrealize(const char *type) "type: %s"
hw/xen/xen-bus.c new file +0 -0
new file mode 100644
index 0000000..1385bab

hw/xen/xen-bus.c line 4

Quoted 4 lines
hw/xen/xen-bus.c new file +4 -0
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or

later.

Quoted 47 lines
hw/xen/xen-bus.c new file +47 -0
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/xen/xen-bus.h"
+#include "qapi/error.h"
+#include "trace.h"
+
+static void xen_bus_unrealize(BusState *bus, Error **errp)
+{
+    trace_xen_bus_unrealize();
+}
+
+static void xen_bus_realize(BusState *bus, Error **errp)
+{
+    trace_xen_bus_realize();
+}
+
+static void xen_bus_class_init(ObjectClass *class, void *data)
+{
+    BusClass *bus_class = BUS_CLASS(class);
+
+    bus_class->realize = xen_bus_realize;
+    bus_class->unrealize = xen_bus_unrealize;
+}
+
+static const TypeInfo xen_bus_type_info = {
+    .name = TYPE_XEN_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = sizeof(XenBus),
+    .class_size = sizeof(XenBusClass),
+    .class_init = xen_bus_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_HOTPLUG_HANDLER },
+        { }
+    },
+};
+
+static void xen_device_unrealize(DeviceState *dev, Error **errp)
+{
+    XenDevice *xendev = XEN_DEVICE(dev);
+    XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev);
+    const char *type = object_get_typename(OBJECT(xendev));
+    Error *local_err = NULL;
+
Quoted 8 lines

hw/xen/xen-bus.c line 55

Quoted 4 lines
hw/xen/xen-bus.c new file +4 -0
+    trace_xen_device_unrealize(type);
+
+    if (xendev_class->unrealize) {
+        xendev_class->unrealize(xendev, &local_err);

Since all you do here is propagate the error, you could even pass errp' to unrealize(), instead of having local_err'. That "for readability", as explained in "qapi/error.h".

Yes, true.

Quoted 11 lines

hw/xen/xen-bus.c line 61

Quoted 7 lines
hw/xen/xen-bus.c new file +6 -0
+        if (local_err) {
+            error_propagate(errp, local_err);
+        }
+    }
+}
+

With that nit fixed:

Thanks :-)

Paul

Quoted 4 lines

Thanks,

--
Anthony PERARD

#6 lore raw

PATCH v2 3/18 xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Paul Durrant

This patch adds new XenDevice-s: 'xen-disk' and 'xen-cdrom', both derived from a common 'xen-block' parent type. These will eventually replace the 'xen_disk' (note the underscore rather than hyphen) legacy PV backend but it is illustrative to build up the implementation incrementally, along with the XenBus/XenDevice framework. Subsequent patches will therefore add to these devices' implementation as new features are added to the framework.

After this patch has been applied it is possible to instantiate new 'xen-disk' or 'xen-cdrom' devices with a single 'vdev' parameter, which accepts values adhering to the Xen VBD naming scheme [1]. For example, a command-line instantiation of a xen-disk can be done with an argument similar to the following:

-device xen-disk,vdev=hda

The implementation of the vdev parameter formulates the appropriate VBD number for use in the PV protocol.

[1] https://xenbits.xen.org/docs/unstable/man/xen-vbd-interface.7.html

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

v2:
- Fix boilerplate
- Fix vdev parsing
- Change name from 'xen-qdisk' to 'xen-block', make abstract, and split off 'xen-disk' and 'xen-cdrom' as concrete sub-types

---
 MAINTAINERS                |   2 +-
 hw/block/Makefile.objs     |   1 +
 hw/block/trace-events      |   8 ++
 hw/block/xen-block.c       | 347 +++++++++++++++++++++++++++++++++++++++++++++
 include/hw/xen/xen-block.h |  69 +++++++++
 5 files changed, 426 insertions(+), 1 deletion(-)
 create mode 100644 hw/block/xen-block.c
 create mode 100644 include/hw/xen/xen-block.h
MAINTAINERS +1 -1
index 63effdc..dd728c3 100644
@@ -403,7 +403,7 @@ F: hw/9pfs/xen-9p-backend.c
 F: hw/char/xen_console.c
 F: hw/display/xenfb.c
 F: hw/net/xen_nic.c
-F: hw/block/xen_*
+F: hw/block/xen*
 F: hw/xen/
 F: hw/xenpv/
 F: hw/i386/xen/
hw/block/Makefile.objs +1 -0
index 53ce575..f34813a 100644
@@ -4,6 +4,7 @@ common-obj-$(CONFIG_SSI_M25P80) += m25p80.o
 common-obj-$(CONFIG_NAND) += nand.o
 common-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 common-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+common-obj-$(CONFIG_XEN) += xen-block.o
 common-obj-$(CONFIG_XEN) += xen_disk.o
 common-obj-$(CONFIG_ECC) += ecc.o
 common-obj-$(CONFIG_ONENAND) += onenand.o
hw/block/trace-events +8 -0
index 335c092..4afbd62 100644
@@ -127,3 +127,11 @@ xen_disk_init(char *name) "%s"
 xen_disk_connect(char *name) "%s"
 xen_disk_disconnect(char *name) "%s"
 xen_disk_free(char *name) "%s"
+
+# hw/block/xen-block.c
+xen_block_realize(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
+xen_block_unrealize(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
+xen_disk_realize(void) ""
+xen_disk_unrealize(void) ""
+xen_cdrom_realize(void) ""
+xen_cdrom_unrealize(void) ""
hw/block/xen-block.c new file +347 -0

347 lines not on this page · raw message

include/hw/xen/xen-block.h new file +69 -0

69 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

hw/block/xen-block.c line 68

Quoted 6 lines · Paul Durrant
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Quoted 4 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+static unsigned int vbd_name_to_disk(const char *name, const char **endp)
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }
+
+        disk *= 26;

hw/block/xen-block.c line 130

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name,
+                               void *opaque, Error **errp)
+{

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

Re: [Qemu-devel] [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Paul Durrant

hw/block/xen-block.c line 68

Quoted 6 lines · Paul Durrant
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Quoted 4 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+static unsigned int vbd_name_to_disk(const char *name, const char **endp)
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }
+
+        disk *= 26;

hw/block/xen-block.c line 130

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name,
+                               void *opaque, Error **errp)
+{

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Signature · 1 line
Anthony PERARD
#9 lore raw

Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

Quoted 11 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

On Thu, Dec 06, 2018 at 03:08:29PM +0000, Paul Durrant wrote:

Quoted 9 lines

hw/block/xen-block.c line 68

Quoted 6 lines
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Damn, yes I was not allowing the >2 letters.

Quoted 28 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

Paul

Quoted 2 lines

--
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

Re: [Qemu-devel] [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Anthony PERARD
Quoted 11 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

On Thu, Dec 06, 2018 at 03:08:29PM +0000, Paul Durrant wrote:

Quoted 9 lines

hw/block/xen-block.c line 68

Quoted 6 lines
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Damn, yes I was not allowing the >2 letters.

Quoted 28 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

Paul

Quoted 2 lines

--
Anthony PERARD

#11 lore raw

Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

Quoted 54 lines · Paul Durrant
Quoted 11 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

On Thu, Dec 06, 2018 at 03:08:29PM +0000, Paul Durrant wrote:

Quoted 9 lines

hw/block/xen-block.c line 68

Quoted 6 lines
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Damn, yes I was not allowing the >2 letters.

Quoted 31 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{
Quoted 6 lines
Quoted 4 lines

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

It's probably because 'a' is somtime 0 and sometime is 1.

'a' should be 0
'aa' should be 26,
'aaa' Seems to be 702.

'xvda': 0     ->                     0 * 1
'xvdz': 25    ->                    25 * 1
'xvdaa': 26   ->            1 * 26 + 0 * 1

'xvdaaa': 702 -> 1 * 26^2 + 1 * 26 + 0 * 1

So, it's weird. Have fun fixing the algorithm for that.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#12 lore raw

Re: [Qemu-devel] [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Paul Durrant
Quoted 54 lines · Paul Durrant
Quoted 11 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

On Thu, Dec 06, 2018 at 03:08:29PM +0000, Paul Durrant wrote:

Quoted 9 lines

hw/block/xen-block.c line 68

Quoted 6 lines
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Damn, yes I was not allowing the >2 letters.

Quoted 31 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{
Quoted 6 lines
Quoted 4 lines

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

It's probably because 'a' is somtime 0 and sometime is 1.

'a' should be 0
'aa' should be 26,
'aaa' Seems to be 702.

'xvda': 0     ->                     0 * 1
'xvdz': 25    ->                    25 * 1
'xvdaa': 26   ->            1 * 26 + 0 * 1

'xvdaaa': 702 -> 1 * 26^2 + 1 * 26 + 0 * 1

So, it's weird. Have fun fixing the algorithm for that.

Signature · 1 line
Anthony PERARD
#13 lore raw

Re: [Qemu-devel] [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

Quoted 68 lines · Anthony PERARD
Quoted 54 lines · Paul Durrant
Quoted 11 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

On Thu, Dec 06, 2018 at 03:08:29PM +0000, Paul Durrant wrote:

Quoted 9 lines

hw/block/xen-block.c line 68

Quoted 6 lines
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Damn, yes I was not allowing the >2 letters.

Quoted 31 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{
Quoted 6 lines
Quoted 4 lines

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

It's probably because 'a' is somtime 0 and sometime is 1.

'a' should be 0
'aa' should be 26,
'aaa' Seems to be 702.

Quoted 6 lines
'xvda': 0     ->                     0 * 1
'xvdz': 25    ->                    25 * 1
'xvdaa': 26   ->            1 * 26 + 0 * 1

'xvdaaa': 702 -> 1 * 26^2 + 1 * 26 + 0 * 1

So, it's weird. Have fun fixing the algorithm for that.

Libvirt has code for going in both directions, that's LGPLv2+ licensed if you want it:

https://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/virutil.c;h=279e6aedc0f5921c850130499fc95c7d4a1e34c9;hb=HEAD#l546

Regards,
Daniel

Signature · 8 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#14 lore raw

Re: [Qemu-devel] [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Anthony PERARD
Quoted 68 lines · Anthony PERARD
Quoted 54 lines · Paul Durrant
Quoted 11 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

On Thu, Dec 06, 2018 at 03:08:29PM +0000, Paul Durrant wrote:

Quoted 9 lines

hw/block/xen-block.c line 68

Quoted 6 lines
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Damn, yes I was not allowing the >2 letters.

Quoted 31 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{
Quoted 6 lines
Quoted 4 lines

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or d0p0' (in the trace). (Same result with xvdaaa', and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

It's probably because 'a' is somtime 0 and sometime is 1.

'a' should be 0
'aa' should be 26,
'aaa' Seems to be 702.

Quoted 6 lines
'xvda': 0     ->                     0 * 1
'xvdz': 25    ->                    25 * 1
'xvdaa': 26   ->            1 * 26 + 0 * 1

'xvdaaa': 702 -> 1 * 26^2 + 1 * 26 + 0 * 1

So, it's weird. Have fun fixing the algorithm for that.

Libvirt has code for going in both directions, that's LGPLv2+ licensed if you want it:

https://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/virutil.c;h=279e6aedc0f5921c850130499fc95c7d4a1e34c9;hb=HEAD#l546

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#15 lore raw

Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Anthony PERARD
Quoted 80 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 15:26
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

Quoted 8 lines · Paul Durrant
Quoted 8 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk'

and

Quoted 13 lines
Quoted 12 lines

'xen-cdrom'

hw/block/xen-block.c line 68

Quoted 6 lines · Paul Durrant
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Quoted 35 lines

Damn, yes I was not allowing the >2 letters.

Quoted 33 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Review

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or `d0p0' (in the trace). (Same result with

`xvdaaa',

Quoted 4 lines
Quoted 2 lines

and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

It's probably because 'a' is somtime 0 and sometime is 1.

'a' should be 0
'aa' should be 26,
'aaa' Seems to be 702.

Quoted 6 lines
'xvda': 0     ->                     0 * 1
'xvdz': 25    ->                    25 * 1
'xvdaa': 26   ->            1 * 26 + 0 * 1

'xvdaaa': 702 -> 1 * 26^2 + 1 * 26 + 0 * 1

So, it's weird. Have fun fixing the algorithm for that.

Actually not as hard as it seemed at first... just treat 'a' as 1 while accumulating the number and then subtract 1 from the result. I wrote a tool to generate the first N disk names using a simple "overflow 'z' to 'aa'" (i.e. non-arithmetical) rule to check against and it matches all the cases I tried (up to 4 letters).

Paul

Quoted 3 lines

--
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

Re: [Qemu-devel] [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

In reply to Anthony PERARD
Quoted 80 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 15:26
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk' and 'xen-cdrom'

Quoted 8 lines · Paul Durrant
Quoted 8 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 14:35
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 03/18] xen: introduce 'xen-block', 'xen-disk'

and

Quoted 13 lines
Quoted 12 lines

'xen-cdrom'

hw/block/xen-block.c line 68

Quoted 6 lines · Paul Durrant
hw/block/xen-block.c new file +6 -0
+static char *disk_to_vbd_name(unsigned int disk)
+{
+    char *name, *prefix = (disk >= 26) ?
+        disk_to_vbd_name((disk / 26) - 1) : g_strdup("");
+
+    name = g_strdup_printf("%s%c", prefix, 'a' + disk);

I don't think that works, if disk is 27, we do ('a' + 27) here. It's probably missing a disk % 26.

Quoted 35 lines

Damn, yes I was not allowing the >2 letters.

Quoted 33 lines
Quoted 5 lines
hw/block/xen-block.c new file +4 -0
+    g_free(prefix);
+
+    return name;
+}

[...]

Quoted 1 line

+static unsigned int vbd_name_to_disk(const char *name, const char

**endp)

Quoted 7 lines
hw/block/xen-block.c new file +7 -0
+{
+    unsigned int disk = 0;
+
+    while (*name != '\0') {
+        if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) {
+            break;
+        }

hw/block/xen-block.c

Quoted 10 lines
hw/block/xen-block.c new file +10 -0
+
+        disk *= 26;
+        disk += *name++ - 'a';
+    }
+    *endp = name;
+
+    return disk;
+}
+
+static void xen_block_set_vdev(Object *obj, Visitor *v, const char

*name,

Review

Quoted 2 lines
(quoted diff) +2 -0
+                               void *opaque, Error **errp)
+{

Setting vdev doesn't work. I've tried to add a disk xvdaa', and it result in xvda', or `d0p0' (in the trace). (Same result with

`xvdaaa',

Quoted 4 lines
Quoted 2 lines

and 'xvdba' gives 'xvdaa'/d26p0)

Ok, that's weird. I'll have to figure that out.

It's probably because 'a' is somtime 0 and sometime is 1.

'a' should be 0
'aa' should be 26,
'aaa' Seems to be 702.

Quoted 6 lines
'xvda': 0     ->                     0 * 1
'xvdz': 25    ->                    25 * 1
'xvdaa': 26   ->            1 * 26 + 0 * 1

'xvdaaa': 702 -> 1 * 26^2 + 1 * 26 + 0 * 1

So, it's weird. Have fun fixing the algorithm for that.

Actually not as hard as it seemed at first... just treat 'a' as 1 while accumulating the number and then subtract 1 from the result. I wrote a tool to generate the first N disk names using a simple "overflow 'z' to 'aa'" (i.e. non-arithmetical) rule to check against and it matches all the cases I tried (up to 4 letters).

Paul

Quoted 3 lines

--
Anthony PERARD

#17 lore raw

PATCH v2 4/18 xen: create xenstore areas for XenDevice-s

In reply to Paul Durrant

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-block' implementation is extended with a 'get_name' method that returns the VBD number. This number is required to 'name' the xenstore areas.

NOTE: An exit handler is also added to make sure the xenstore areas are
cleaned up if QEMU terminates without devices being unrealized.

[1] The 'scanf' functions are actually not yet needed, but they will be needed by code delivered in subsequent patches.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

v2:
- Fix boilerplate
- Add error pointers to all xs_node... helpers
- Add GCC_FMT_ATTR to declarations of printf-like helpers

---
 hw/block/xen-block.c            |   9 ++
 hw/xen/Makefile.objs            |   2 +-
 hw/xen/trace-events             |  12 +-
 hw/xen/xen-bus-helper.c         | 147 ++++++++++++++++++
 hw/xen/xen-bus.c                | 319 +++++++++++++++++++++++++++++++++++++++-
 include/hw/xen/xen-bus-helper.h |  34 +++++
 include/hw/xen/xen-bus.h        |  12 ++
 7 files changed, 530 insertions(+), 5 deletions(-)
 create mode 100644 hw/xen/xen-bus-helper.c
 create mode 100644 include/hw/xen/xen-bus-helper.h
hw/block/xen-block.c +9 -0
index 78f4218..440bec2 100644
@@ -13,6 +13,14 @@
 #include "hw/xen/xen-block.h"
 #include "trace.h"
 
+static char *xen_block_get_name(XenDevice *xendev, Error **errp)
+{
+    XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
+    XenBlockVdev *vdev = &blockdev->vdev;
+
+    return g_strdup_printf("%lu", vdev->number);
+}
+
 static void xen_block_unrealize(XenDevice *xendev, Error **errp)
 {
     XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
@@ -266,6 +274,7 @@ static void xen_block_class_init(ObjectClass *class, void *data)
     DeviceClass *dev_class = DEVICE_CLASS(class);
     XenDeviceClass *xendev_class = XEN_DEVICE_CLASS(class);
 
+    xendev_class->get_name = xen_block_get_name;
     xendev_class->realize = xen_block_realize;
     xendev_class->unrealize = xen_block_unrealize;
 
hw/xen/Makefile.objs +1 -1
index d9d6d7b..77c0868 100644
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o xen-bus.o
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o xen-bus.o xen-bus-helper.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
hw/xen/trace-events +10 -2
index 0172cd4..75dc226 100644
@@ -16,5 +16,13 @@ xen_domid_restrict(int err) "err: %u"
 # include/hw/xen/xen-bus.c
 xen_bus_realize(void) ""
 xen_bus_unrealize(void) ""
-xen_device_realize(const char *type) "type: %s"
-xen_device_unrealize(const char *type) "type: %s"
+xen_device_realize(const char *type, char *name) "type: %s name: %s"
+xen_device_unrealize(const char *type, char *name) "type: %s name: %s"
+xen_device_backend_state(const char *type, char *name, const char *state) "type: %s name: %s -> %s"
+xen_device_frontend_state(const char *type, char *name, const char *state) "type: %s name: %s -> %s"
+
+# include/hw/xen/xen-bus-helper.c
+xs_node_create(const char *node) "%s"
+xs_node_destroy(const char *node) "%s"
+xs_node_vprintf(char *path, char *value) "%s %s"
+xs_node_vscanf(char *path, char *value) "%s %s"
hw/xen/xen-bus-helper.c new file +147 -0

147 lines not on this page · raw message

hw/xen/xen-bus.c +317 -2

388 lines not on this page · raw message

include/hw/xen/xen-bus-helper.h new file +34 -0
new file mode 100644
index 0000000..083e4de
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_XEN_BUS_HELPER_H
+#define HW_XEN_BUS_HELPER_H
+
+#include "hw/xen/xen_common.h"
+
+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, Error **errp);
+
+/* Write to node/key unless node is empty, in which case write to key */
+void xs_node_vprintf(struct xs_handle *xsh, const char *node, const char *key,
+                     Error **errp, const char *fmt, va_list ap)
+    GCC_FMT_ATTR(5, 0);
+void xs_node_printf(struct xs_handle *xsh, const char *node, const char *key,
+                    Error **errp, const char *fmt, ...)
+    GCC_FMT_ATTR(5, 6);
+
+/* Read from node/key unless node is empty, in which case read from key */
+int xs_node_vscanf(struct xs_handle *xsh, const char *node, const char *key,
+                   Error **errp, const char *fmt, va_list ap);
+int xs_node_scanf(struct xs_handle *xsh, const char *node, const char *key,
+                  Error **errp, const char *fmt, ...);
+
+#endif /* HW_XEN_BUS_HELPER_H */
include/hw/xen/xen-bus.h +12 -0
index 0cb1246..85a75d8 100644
@@ -8,12 +8,19 @@
 #ifndef HW_XEN_BUS_H
 #define HW_XEN_BUS_H
 
+#include "hw/xen/xen_common.h"
 #include "hw/sysbus.h"
 
 typedef struct XenDevice {
     DeviceState qdev;
+    domid_t frontend_id;
+    char *name;
+    char *backend_path, *frontend_path;
+    enum xenbus_state backend_state, frontend_state;
+    Notifier exit;
 } XenDevice;
 
+typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
 typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
 typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp);
 
@@ -21,6 +28,9 @@ typedef struct XenDeviceClass {
     /*< private >*/
     DeviceClass parent_class;
     /*< public >*/
+    const char *backend;
+    const char *device;
+    XenDeviceGetName get_name;
     XenDeviceRealize realize;
     XenDeviceUnrealize unrealize;
 } XenDeviceClass;
@@ -35,6 +45,8 @@ typedef struct XenDeviceClass {
 
 typedef struct XenBus {
     BusState qbus;
+    domid_t backend_id;
+    struct xs_handle *xsh;
 } XenBus;
 
 typedef struct XenBusClass {
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 4/18
#18 lore raw

Re: [PATCH v2 04/18] xen: create xenstore areas for XenDevice-s

Quoted 11 lines · Paul Durrant

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-block' implementation is extended with a 'get_name' method that returns the VBD number. This number is required to 'name' the xenstore areas.

Quoted 7 lines

NOTE: An exit handler is also added to make sure the xenstore areas are
cleaned up if QEMU terminates without devices being unrealized.

[1] The 'scanf' functions are actually not yet needed, but they will be needed by code delivered in subsequent patches.

Looks good,

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 4/18
#19 lore raw

Re: [Qemu-devel] [PATCH v2 04/18] xen: create xenstore areas for XenDevice-s

In reply to Paul Durrant
Quoted 11 lines · Paul Durrant

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-block' implementation is extended with a 'get_name' method that returns the VBD number. This number is required to 'name' the xenstore areas.

Quoted 7 lines

NOTE: An exit handler is also added to make sure the xenstore areas are
cleaned up if QEMU terminates without devices being unrealized.

[1] The 'scanf' functions are actually not yet needed, but they will be needed by code delivered in subsequent patches.

Looks good,

Thanks,

Signature · 1 line
Anthony PERARD
#20 lore raw

PATCH v2 5/18 xen: add xenstore watcher infrastructure

In reply to Paul Durrant

A Xen PV frontend communicates its state to the PV backend by writing to the 'state' key in the frontend area in xenstore. It is therefore necessary for a XenDevice implementation to be notified whenever the value of this key changes.

This patch adds code to do this as follows:

- an 'fd handler' is registered on the libxenstore handle which will be triggered whenever a 'watch' event occurs
- primitives are added to xen-bus-helper to add or remove watch events
- a list of Notifier objects is added to XenBus to provide a mechanism to call the appropriate 'watch handler' when its associated event occurs

The xen-block implementation is extended with a 'frontend_changed' method, which calls as-yet stub 'connect' and 'disconnect' functions when the relevant frontend state transitions occur. A subsequent patch will supply a full implementation for these functions.

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

v2:
- Don't crash when xen_block_disconnect() fails
- Check xs_unwatch() for error
- Add new_watch() and free_watch() utility functions
- Use xs_check_watch() rather than xs_read_watch()

---
 hw/block/trace-events           |   2 +
 hw/block/xen-block.c            |  73 ++++++++++++++
 hw/xen/trace-events             |   6 ++
 hw/xen/xen-bus-helper.c         |  34 +++++++
 hw/xen/xen-bus.c                | 217 +++++++++++++++++++++++++++++++++++++++-
 include/hw/xen/xen-bus-helper.h |   6 ++
 include/hw/xen/xen-bus.h        |  15 +++
 7 files changed, 351 insertions(+), 2 deletions(-)
hw/block/trace-events +2 -0
index 4afbd62..89e2583 100644
@@ -130,6 +130,8 @@ xen_disk_free(char *name) "%s"
 
 # hw/block/xen-block.c
 xen_block_realize(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
+xen_block_connect(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
+xen_block_disconnect(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
 xen_block_unrealize(const char *type, uint32_t disk, uint32_t partition) "%s d%up%u"
 xen_disk_realize(void) ""
 xen_disk_unrealize(void) ""
hw/block/xen-block.c +73 -0

97 lines not on this page · raw message

hw/xen/trace-events +6 -0
index 75dc226..22055b5 100644
@@ -16,13 +16,19 @@ xen_domid_restrict(int err) "err: %u"
 # include/hw/xen/xen-bus.c
 xen_bus_realize(void) ""
 xen_bus_unrealize(void) ""
+xen_bus_add_watch(const char *node, const char *key, char *token) "node: %s key: %s token: %s"
+xen_bus_remove_watch(const char *node, const char *key, char *token) "node: %s key: %s token: %s"
+xen_bus_watch(const char *token) "token: %s"
 xen_device_realize(const char *type, char *name) "type: %s name: %s"
 xen_device_unrealize(const char *type, char *name) "type: %s name: %s"
 xen_device_backend_state(const char *type, char *name, const char *state) "type: %s name: %s -> %s"
 xen_device_frontend_state(const char *type, char *name, const char *state) "type: %s name: %s -> %s"
+xen_device_frontend_changed(const char *type, char *name) "type: %s name: %s"
 
 # include/hw/xen/xen-bus-helper.c
 xs_node_create(const char *node) "%s"
 xs_node_destroy(const char *node) "%s"
 xs_node_vprintf(char *path, char *value) "%s %s"
 xs_node_vscanf(char *path, char *value) "%s %s"
+xs_node_watch(char *path) "%s"
+xs_node_unwatch(char *path) "%s"
hw/xen/xen-bus-helper.c +34 -0
index 2304f8e..d1d5512 100644
@@ -145,3 +145,37 @@ int xs_node_scanf(struct xs_handle *xsh, const char *node, const char *key,
 
     return rc;
 }
+
+void xs_node_watch(struct xs_handle *xsh, const char *node, const char *key,
+                   char *token, Error **errp)
+{
+    char *path;
+
+    path = (strlen(node) != 0) ? g_strdup_printf("%s/%s", node, key) :
+        g_strdup(key);
+
+    trace_xs_node_watch(path);
+
+    if (!xs_watch(xsh, path, token)) {
+        error_setg_errno(errp, errno, "failed to watch node '%s'", path);
+    }
+
+    g_free(path);
+}
+
+void xs_node_unwatch(struct xs_handle *xsh, const char *node,
+                     const char *key, const char *token, Error **errp)
+{
+    char *path;
+
+    path = (strlen(node) != 0) ? g_strdup_printf("%s/%s", node, key) :
+        g_strdup(key);
+
+    trace_xs_node_unwatch(path);
+
+    if (!xs_unwatch(xsh, path, token)) {
+        error_setg_errno(errp, errno, "failed to unwatch node '%s'", path);
+    }
+
+    g_free(path);
+}
hw/xen/xen-bus.c +215 -2

280 lines not on this page · raw message

include/hw/xen/xen-bus-helper.h +6 -0
index 083e4de..57935ff 100644
@@ -31,4 +31,10 @@ int xs_node_vscanf(struct xs_handle *xsh, const char *node, const char *key,
 int xs_node_scanf(struct xs_handle *xsh, const char *node, const char *key,
                   Error **errp, const char *fmt, ...);
 
+/* Watch node/key unless node is empty, in which case watch key */
+void xs_node_watch(struct xs_handle *xsh, const char *node, const char *key,
+                   char *token, Error **errp);
+void xs_node_unwatch(struct xs_handle *xsh, const char *node, const char *key,
+                     const char *token, Error **errp);
+
 #endif /* HW_XEN_BUS_HELPER_H */
include/hw/xen/xen-bus.h +15 -0
index 85a75d8..df73674 100644
@@ -10,6 +10,11 @@
 
 #include "hw/xen/xen_common.h"
 #include "hw/sysbus.h"
+#include "qemu/notify.h"
+
+typedef void (*XenWatchHandler)(void *opaque);
+
+typedef struct XenWatch XenWatch;
 
 typedef struct XenDevice {
     DeviceState qdev;
@@ -18,10 +23,14 @@ typedef struct XenDevice {
     char *backend_path, *frontend_path;
     enum xenbus_state backend_state, frontend_state;
     Notifier exit;
+    XenWatch *frontend_state_watch;
 } XenDevice;
 
 typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
 typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
+typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
+                                         enum xenbus_state frontend_state,
+                                         Error **errp);
 typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp);
 
 typedef struct XenDeviceClass {
@@ -32,6 +41,7 @@ typedef struct XenDeviceClass {
     const char *device;
     XenDeviceGetName get_name;
     XenDeviceRealize realize;
+    XenDeviceFrontendChanged frontend_changed;
     XenDeviceUnrealize unrealize;
 } XenDeviceClass;
 
@@ -47,6 +57,7 @@ typedef struct XenBus {
     BusState qbus;
     domid_t backend_id;
     struct xs_handle *xsh;
+    NotifierList watch_notifiers;
 } XenBus;
 
 typedef struct XenBusClass {
@@ -64,4 +75,8 @@ typedef struct XenBusClass {
 
 void xen_bus_init(void);
 
+void xen_device_backend_set_state(XenDevice *xendev,
+                                  enum xenbus_state state);
+enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
+
 #endif /* HW_XEN_BUS_H */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#21 lore raw

Re: [PATCH v2 05/18] xen: add xenstore watcher infrastructure

hw/block/xen-block.c static void xen_block_unrealize(XenDevice *xendev, Error **errp) · line 60

Quoted 8 lines · Paul Durrant
hw/block/xen-block.c +4 -0
@@ -36,6 +54,12 @@ static void xen_block_unrealize(XenDevice *xendev, Error **errp)
 
     trace_xen_block_unrealize(type, vdev->disk, vdev->partition);
 
+    /* Disconnect from the frontend in case this has not already happened */
+    xen_block_disconnect(xendev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);

If xen_block_disconnect fails, local_err is going to be reuse below. If it's fine to try unrealize, then local_err=NULL is probably enough.

Quoted 5 lines
hw/block/xen-block.c +2 -0
+    }
+
     if (blockdev_class->unrealize) {
         blockdev_class->unrealize(blockdev, &local_err);
         if (local_err) {

[...]

hw/xen/xen-bus.c static char *xen_bus_get_dev_path(DeviceState *dev) · line 141

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+static void xen_bus_remove_watch(XenBus *xenbus, XenWatch *watch,
+                                 Error **errp)
+{
+    Error *local_err = NULL;
+
+    trace_xen_bus_remove_watch(watch->node, watch->key, watch->token);
+
+    xs_node_unwatch(xenbus->xsh, watch->node, watch->key, watch->token,
+                    &local_err);

You could simply pass errp' directly instead of having local_err'.

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+
+    notifier_remove(&watch->notifier);
+    free_watch(watch);
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+
Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#22 lore raw

Re: [Qemu-devel] [PATCH v2 05/18] xen: add xenstore watcher infrastructure

In reply to Paul Durrant

hw/block/xen-block.c static void xen_block_unrealize(XenDevice *xendev, Error **errp) · line 60

Quoted 8 lines · Paul Durrant
hw/block/xen-block.c +4 -0
@@ -36,6 +54,12 @@ static void xen_block_unrealize(XenDevice *xendev, Error **errp)
 
     trace_xen_block_unrealize(type, vdev->disk, vdev->partition);
 
+    /* Disconnect from the frontend in case this has not already happened */
+    xen_block_disconnect(xendev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);

If xen_block_disconnect fails, local_err is going to be reuse below. If it's fine to try unrealize, then local_err=NULL is probably enough.

Quoted 5 lines
hw/block/xen-block.c +2 -0
+    }
+
     if (blockdev_class->unrealize) {
         blockdev_class->unrealize(blockdev, &local_err);
         if (local_err) {

[...]

hw/xen/xen-bus.c static char *xen_bus_get_dev_path(DeviceState *dev) · line 141

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+static void xen_bus_remove_watch(XenBus *xenbus, XenWatch *watch,
+                                 Error **errp)
+{
+    Error *local_err = NULL;
+
+    trace_xen_bus_remove_watch(watch->node, watch->key, watch->token);
+
+    xs_node_unwatch(xenbus->xsh, watch->node, watch->key, watch->token,
+                    &local_err);

You could simply pass errp' directly instead of having local_err'.

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+
+    notifier_remove(&watch->notifier);
+    free_watch(watch);
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+
Signature · 1 line
Anthony PERARD
#23 lore raw

Re: [PATCH v2 05/18] xen: add xenstore watcher infrastructure

Quoted 15 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 15:58
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 05/18] xen: add xenstore watcher infrastructure

Review static void xen_block_unrealize(XenDevice *xendev,

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0
@@ -36,6 +54,12 @@ static void xen_block_unrealize(XenDevice *xendev,

Error **errp)

Quoted 3 lines
hw/block/xen-block.c +0 -0
     trace_xen_block_unrealize(type, vdev->disk, vdev->partition);
 
Quoted 9 lines

Review static void xen_block_unrealize(XenDevice *xendev, · line 56

Quoted 1 line
(quoted diff) +1 -0
+    /* Disconnect from the frontend in case this has not already

happened */

hw/block/xen-block.c static void xen_block_unrealize(XenDevice *xendev, Error **errp) · line 60

Quoted 3 lines
hw/block/xen-block.c +3 -0
+    xen_block_disconnect(xendev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);

If xen_block_disconnect fails, local_err is going to be reuse below. If it's fine to try unrealize, then local_err=NULL is probably enough.

Actually, on this path there is nothing useful to be done with an error... disconnect really really should not fail, so I'll pass NULL instead to ignore any error.

Quoted 8 lines
Quoted 5 lines
hw/block/xen-block.c +2 -0
+    }
+
     if (blockdev_class->unrealize) {
         blockdev_class->unrealize(blockdev, &local_err);
         if (local_err) {

[...]

Quoted 12 lines

hw/xen/xen-bus.c static char *xen_bus_get_dev_path(DeviceState *dev) · line 141

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+static void xen_bus_remove_watch(XenBus *xenbus, XenWatch *watch,
+                                 Error **errp)
+{
+    Error *local_err = NULL;
+
+    trace_xen_bus_remove_watch(watch->node, watch->key, watch->token);
+
+    xs_node_unwatch(xenbus->xsh, watch->node, watch->key, watch->token,
+                    &local_err);

You could simply pass errp' directly instead of having local_err'.

Indeed.

Paul

Quoted 4 lines
Quoted 4 lines
hw/xen/xen-bus.c +4 -0
+
+    notifier_remove(&watch->notifier);
+    free_watch(watch);
+
Quoted 8 lines

hw/block/xen-block.c static void xen_block_realize(XenDevice *xendev, Error **errp) · line 120

Quoted 5 lines
hw/block/xen-block.c +5 -0
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+

--
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#24 lore raw

Re: [Qemu-devel] [PATCH v2 05/18] xen: add xenstore watcher infrastructure

In reply to Anthony PERARD
Quoted 15 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 15:58
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 05/18] xen: add xenstore watcher infrastructure

Review static void xen_block_unrealize(XenDevice *xendev,

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0
@@ -36,6 +54,12 @@ static void xen_block_unrealize(XenDevice *xendev,

Error **errp)

Quoted 3 lines
hw/block/xen-block.c +0 -0
     trace_xen_block_unrealize(type, vdev->disk, vdev->partition);
 
Quoted 9 lines

Review static void xen_block_unrealize(XenDevice *xendev, · line 56

Quoted 1 line
(quoted diff) +1 -0
+    /* Disconnect from the frontend in case this has not already

happened */

hw/block/xen-block.c static void xen_block_unrealize(XenDevice *xendev, Error **errp) · line 60

Quoted 3 lines
hw/block/xen-block.c +3 -0
+    xen_block_disconnect(xendev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);

If xen_block_disconnect fails, local_err is going to be reuse below. If it's fine to try unrealize, then local_err=NULL is probably enough.

Actually, on this path there is nothing useful to be done with an error... disconnect really really should not fail, so I'll pass NULL instead to ignore any error.

Quoted 8 lines
Quoted 5 lines
hw/block/xen-block.c +2 -0
+    }
+
     if (blockdev_class->unrealize) {
         blockdev_class->unrealize(blockdev, &local_err);
         if (local_err) {

[...]

Quoted 12 lines

hw/xen/xen-bus.c static char *xen_bus_get_dev_path(DeviceState *dev) · line 141

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+static void xen_bus_remove_watch(XenBus *xenbus, XenWatch *watch,
+                                 Error **errp)
+{
+    Error *local_err = NULL;
+
+    trace_xen_bus_remove_watch(watch->node, watch->key, watch->token);
+
+    xs_node_unwatch(xenbus->xsh, watch->node, watch->key, watch->token,
+                    &local_err);

You could simply pass errp' directly instead of having local_err'.

Indeed.

Paul

Quoted 12 lines

hw/xen/xen-bus.c static char *xen_bus_get_dev_path(DeviceState *dev) · line 150

Quoted 9 lines
hw/xen/xen-bus.c +9 -0
+
+    notifier_remove(&watch->notifier);
+    free_watch(watch);
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+    }
+}
+

--
Anthony PERARD

#25 lore raw

PATCH v2 6/18 xen: add grant table interface for XenDevice-s

In reply to Paul Durrant

The legacy PV backend infrastructure provides functions to map, unmap and copy pages granted by frontends. Similar functionality will be required by XenDevice implementations so this patch adds the necessary support.

---
Cc: Stefano Stabellini <[email protected]>

---
 hw/xen/xen-bus.c         | 146 +++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/xen/xen-bus.h |  25 ++++++++
 2 files changed, 171 insertions(+)
hw/xen/xen-bus.c +146 -0
index f0732f8..b40dc83 100644
@@ -489,6 +489,138 @@ static void xen_device_frontend_destroy(XenDevice *xendev)
     }
 }
 
+void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
+                                   Error **errp)
+{
+    if (xengnttab_set_max_grants(xendev->xgth, nr_refs)) {
+        error_setg_errno(errp, errno, "xengnttab_set_max_grants failed");
+    }
+}
+
+void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
+                                unsigned int nr_refs, int prot,
+                                Error **errp)
+{
+    void *map = xengnttab_map_domain_grant_refs(xendev->xgth, nr_refs,
+                                                xendev->frontend_id, refs,
+                                                prot);
+
+    if (!map) {
+        error_setg_errno(errp, errno,
+                         "xengnttab_map_domain_grant_refs failed");
+    }
+
+    return map;
+}
+
+void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
+                                 unsigned int nr_refs, Error **errp)
+{
+    if (xengnttab_unmap(xendev->xgth, map, nr_refs)) {
+        error_setg_errno(errp, errno, "xengnttab_unmap failed");
+    }
+}
+
+static void compat_copy_grant_refs(XenDevice *xendev, bool to_domain,
+                                   XenDeviceGrantCopySegment segs[],
+                                   unsigned int nr_segs, Error **errp)
+{
+    uint32_t *refs = g_new(uint32_t, nr_segs);
+    int prot = to_domain ? PROT_WRITE : PROT_READ;
+    void *map;
+    unsigned int i;
+
+    for (i = 0; i < nr_segs; i++) {
+        XenDeviceGrantCopySegment *seg = &segs[i];
+
+        refs[i] = to_domain ? seg->dest.foreign.ref :
+            seg->source.foreign.ref;
+    }
+
+    map = xengnttab_map_domain_grant_refs(xendev->xgth, nr_segs,
+                                          xendev->frontend_id, refs,
+                                          prot);
+    if (!map) {
+        error_setg_errno(errp, errno,
+                         "xengnttab_map_domain_grant_refs failed");
+        goto done;
+    }
+
+    for (i = 0; i < nr_segs; i++) {
+        XenDeviceGrantCopySegment *seg = &segs[i];
+        void *page = map + (i * XC_PAGE_SIZE);
+
+        if (to_domain) {
+            memcpy(page + seg->dest.foreign.offset, seg->source.virt,
+                   seg->len);
+        } else {
+            memcpy(seg->dest.virt, page + seg->source.foreign.offset,
+                   seg->len);
+        }
+    }
+
+    if (xengnttab_unmap(xendev->xgth, map, nr_segs)) {
+        error_setg_errno(errp, errno, "xengnttab_unmap failed");
+    }
+
+done:
+    g_free(refs);
+}
+
+void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
+                                XenDeviceGrantCopySegment segs[],
+                                unsigned int nr_segs, Error **errp)
+{
+    xengnttab_grant_copy_segment_t *xengnttab_segs;
+    unsigned int i;
+
+    if (!xendev->feature_grant_copy) {
+        compat_copy_grant_refs(xendev, to_domain, segs, nr_segs, errp);
+        return;
+    }
+
+    xengnttab_segs = g_new0(xengnttab_grant_copy_segment_t, nr_segs);
+
+    for (i = 0; i < nr_segs; i++) {
+        XenDeviceGrantCopySegment *seg = &segs[i];
+        xengnttab_grant_copy_segment_t *xengnttab_seg = &xengnttab_segs[i];
+
+        if (to_domain) {
+            xengnttab_seg->flags = GNTCOPY_dest_gref;
+            xengnttab_seg->dest.foreign.domid = xendev->frontend_id;
+            xengnttab_seg->dest.foreign.ref = seg->dest.foreign.ref;
+            xengnttab_seg->dest.foreign.offset = seg->dest.foreign.offset;
+            xengnttab_seg->source.virt = seg->source.virt;
+        } else {
+            xengnttab_seg->flags = GNTCOPY_source_gref;
+            xengnttab_seg->source.foreign.domid = xendev->frontend_id;
+            xengnttab_seg->source.foreign.ref = seg->source.foreign.ref;
+            xengnttab_seg->source.foreign.offset =
+                seg->source.foreign.offset;
+            xengnttab_seg->dest.virt = seg->dest.virt;
+        }
+
+        xengnttab_seg->len = seg->len;
+    }
+
+    if (xengnttab_grant_copy(xendev->xgth, nr_segs, xengnttab_segs)) {
+        error_setg_errno(errp, errno, "xengnttab_grant_copy failed");
+        goto done;
+    }
+
+    for (i = 0; i < nr_segs; i++) {
+        xengnttab_grant_copy_segment_t *xengnttab_seg = &xengnttab_segs[i];
+
+        if (xengnttab_seg->status != GNTST_okay) {
+            error_setg(errp, "xengnttab_grant_copy seg[%u] failed", i);
+            break;
+        }
+    }
+
+done:
+    g_free(xengnttab_segs);
+}
+
 static void xen_device_unrealize(DeviceState *dev, Error **errp)
 {
     XenDevice *xendev = XEN_DEVICE(dev);
@@ -517,6 +649,11 @@ static void xen_device_unrealize(DeviceState *dev, Error **errp)
     xen_device_frontend_destroy(xendev);
     xen_device_backend_destroy(xendev);
 
+    if (xendev->xgth) {
+        xengnttab_close(xendev->xgth);
+        xendev->xgth = NULL;
+    }
+
     g_free(xendev->name);
     xendev->name = NULL;
 }
@@ -559,6 +696,15 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
 
     trace_xen_device_realize(type, xendev->name);
 
+    xendev->xgth = xengnttab_open(NULL, 0);
+    if (!xendev->xgth) {
+        error_setg_errno(errp, errno, "failed xengnttab_open");
+        goto unrealize;
+    }
+
+    xendev->feature_grant_copy =
+        (xengnttab_grant_copy(xendev->xgth, 0, NULL) == 0);
+
     xen_device_backend_create(xendev, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
include/hw/xen/xen-bus.h +25 -0
index df73674..63a09b6 100644
@@ -24,6 +24,8 @@ typedef struct XenDevice {
     enum xenbus_state backend_state, frontend_state;
     Notifier exit;
     XenWatch *frontend_state_watch;
+    xengnttab_handle *xgth;
+    bool feature_grant_copy;
 } XenDevice;
 
 typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
@@ -79,4 +81,27 @@ void xen_device_backend_set_state(XenDevice *xendev,
                                   enum xenbus_state state);
 enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
 
+void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
+                                   Error **errp);
+void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
+                                unsigned int nr_refs, int prot,
+                                Error **errp);
+void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
+                                 unsigned int nr_refs, Error **errp);
+
+typedef struct XenDeviceGrantCopySegment {
+    union {
+        void *virt;
+        struct {
+            uint32_t ref;
+            off_t offset;
+        } foreign;
+    } source, dest;
+    size_t len;
+} XenDeviceGrantCopySegment;
+
+void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
+                                XenDeviceGrantCopySegment segs[],
+                                unsigned int nr_segs, Error **errp);
+
 #endif /* HW_XEN_BUS_H */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#26 lore raw

PATCH v2 7/18 xen: add event channel interface for XenDevice-s

In reply to Paul Durrant

The legacy PV backend infrastructure provides functions to bind, unbind and send notifications to event channnels. Similar functionality will be required by XenDevice implementations so this patch adds the necessary support.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

v2:
- Added error pointers to notify and unbind

---
 hw/xen/xen-bus.c         | 101 +++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/xen/xen-bus.h |  18 +++++++++
 2 files changed, 119 insertions(+)
hw/xen/xen-bus.c +101 -0
index b40dc83..0e6f194 100644
@@ -621,6 +621,81 @@ done:
     g_free(xengnttab_segs);
 }
 
+struct XenEventChannel {
+    unsigned int local_port;
+    XenEventHandler handler;
+    void *opaque;
+    Notifier notifier;
+};
+
+static void event_notify(Notifier *n, void *data)
+{
+    XenEventChannel *channel = container_of(n, XenEventChannel, notifier);
+    unsigned long port = (unsigned long)data;
+
+    if (port == channel->local_port) {
+        channel->handler(channel->opaque);
+    }
+}
+
+XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
+                                               unsigned int port,
+                                               XenEventHandler handler,
+                                               void *opaque, Error **errp)
+{
+    XenEventChannel *channel = g_new0(XenEventChannel, 1);
+
+    channel->local_port = xenevtchn_bind_interdomain(xendev->xeh,
+                                                     xendev->frontend_id,
+                                                     port);
+    if (xendev->local_port < 0) {
+        error_setg_errno(errp, errno, "xenevtchn_bind_interdomain failed");
+
+        g_free(channel);
+        return NULL;
+    }
+
+    channel->handler = handler;
+    channel->opaque = opaque;
+    channel->notifier.notify = event_notify;
+
+    notifier_list_add(&xendev->event_notifiers, &channel->notifier);
+
+    return channel;
+}
+
+void xen_device_notify_event_channel(XenDevice *xendev,
+                                     XenEventChannel *channel,
+                                     Error **errp)
+{
+    if (!channel) {
+        error_setg(errp, "bad channel");
+        return;
+    }
+
+    if (xenevtchn_notify(xendev->xeh, channel->local_port) < 0) {
+        error_setg_errno(errp, errno, "xenevtchn_notify failed");
+    }
+}
+
+void xen_device_unbind_event_channel(XenDevice *xendev,
+                                     XenEventChannel *channel,
+                                     Error **errp)
+{
+    if (!channel) {
+        error_setg(errp, "bad channel");
+        return;
+    }
+
+    notifier_remove(&channel->notifier);
+
+    if (xenevtchn_unbind(xendev->xeh, channel->local_port) < 0) {
+        error_setg_errno(errp, errno, "xenevtchn_unbind failed");
+    }
+
+    g_free(channel);
+}
+
 static void xen_device_unrealize(DeviceState *dev, Error **errp)
 {
     XenDevice *xendev = XEN_DEVICE(dev);
@@ -649,6 +724,12 @@ static void xen_device_unrealize(DeviceState *dev, Error **errp)
     xen_device_frontend_destroy(xendev);
     xen_device_backend_destroy(xendev);
 
+    if (xendev->xeh) {
+        qemu_set_fd_handler(xenevtchn_fd(xendev->xeh), NULL, NULL, NULL);
+        xenevtchn_close(xendev->xeh);
+        xendev->xeh = NULL;
+    }
+
     if (xendev->xgth) {
         xengnttab_close(xendev->xgth);
         xendev->xgth = NULL;
@@ -665,6 +746,16 @@ static void xen_device_exit(Notifier *n, void *data)
     xen_device_unrealize(DEVICE(xendev), &error_abort);
 }
 
+static void xen_device_event(void *opaque)
+{
+    XenDevice *xendev = opaque;
+    unsigned long port = xenevtchn_pending(xendev->xeh);
+
+    notifier_list_notify(&xendev->event_notifiers, (void *)port);
+
+    xenevtchn_unmask(xendev->xeh, port);
+}
+
 static void xen_device_realize(DeviceState *dev, Error **errp)
 {
     XenDevice *xendev = XEN_DEVICE(dev);
@@ -705,6 +796,16 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
     xendev->feature_grant_copy =
         (xengnttab_grant_copy(xendev->xgth, 0, NULL) == 0);
 
+    xendev->xeh = xenevtchn_open(NULL, 0);
+    if (!xendev->xeh) {
+        error_setg_errno(errp, errno, "failed xenevtchn_open");
+        goto unrealize;
+    }
+
+    notifier_list_init(&xendev->event_notifiers);
+    qemu_set_fd_handler(xenevtchn_fd(xendev->xeh), xen_device_event, NULL,
+                        xendev);
+
     xen_device_backend_create(xendev, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
include/hw/xen/xen-bus.h +18 -0
index 63a09b6..f83a95c 100644
@@ -26,6 +26,9 @@ typedef struct XenDevice {
     XenWatch *frontend_state_watch;
     xengnttab_handle *xgth;
     bool feature_grant_copy;
+    xenevtchn_handle *xeh;
+    xenevtchn_port_or_error_t local_port;
+    NotifierList event_notifiers;
 } XenDevice;
 
 typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
@@ -104,4 +107,19 @@ void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
                                 XenDeviceGrantCopySegment segs[],
                                 unsigned int nr_segs, Error **errp);
 
+typedef struct XenEventChannel XenEventChannel;
+
+typedef void (*XenEventHandler)(void *opaque);
+
+XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
+                                               unsigned int port,
+                                               XenEventHandler handler,
+                                               void *opaque, Error **errp);
+void xen_device_notify_event_channel(XenDevice *xendev,
+                                     XenEventChannel *channel,
+                                     Error **errp);
+void xen_device_unbind_event_channel(XenDevice *xendev,
+                                     XenEventChannel *channel,
+                                     Error **errp);
+
 #endif /* HW_XEN_BUS_H */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 7/18
#27 lore raw

Re: [PATCH v2 07/18] xen: add event channel interface for XenDevice-s

Quoted 6 lines · Paul Durrant

The legacy PV backend infrastructure provides functions to bind, unbind and send notifications to event channnels. Similar functionality will be required by XenDevice implementations so this patch adds the necessary support.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 7/18
#28 lore raw

Re: [Qemu-devel] [PATCH v2 07/18] xen: add event channel interface for XenDevice-s

In reply to Paul Durrant
Quoted 6 lines · Paul Durrant

The legacy PV backend infrastructure provides functions to bind, unbind and send notifications to event channnels. Similar functionality will be required by XenDevice implementations so this patch adds the necessary support.

Thanks,

Signature · 1 line
Anthony PERARD
#29 lore raw

PATCH v2 8/18 xen: duplicate xen_disk.c as basis of dataplane/xen-block.c

In reply to Paul Durrant

The new xen-block XenDevice implementation requires the same core dataplane as the legacy xen_disk implementation it will eventually replace. This patch therefore copies the legacy xen_disk.c source module into a new dataplane/xen-block.c source module as the basis for the new dataplane and adjusts the MAINTAINERS file accordingly.

NOTE: The duplicated code is not yet built. It is simply put into place by
this patch (just fixing style violations) such that the modifications that will need to be made to the code are not conflated with code movement, thus making review harder.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

---
 MAINTAINERS                    |    1 +
 hw/block/dataplane/xen-block.c | 1019 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1020 insertions(+)
 create mode 100644 hw/block/dataplane/xen-block.c
MAINTAINERS +1 -0
index dd728c3..ab62ad4 100644
@@ -404,6 +404,7 @@ F: hw/char/xen_console.c
 F: hw/display/xenfb.c
 F: hw/net/xen_nic.c
 F: hw/block/xen*
+F: hw/block/dataplane/xen*
 F: hw/xen/
 F: hw/xenpv/
 F: hw/i386/xen/
hw/block/dataplane/xen-block.c new file +1019 -0

1,019 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#30 lore raw

PATCH v2 9/18 xen: remove unnecessary code from dataplane/xen-block.c

In reply to Paul Durrant

Not all of the code duplicated from xen_disk.c is required as the basis for the new dataplane implementation so this patch removes extraneous code, along with the legacy #includes and calls to the legacy xen_pv_printf() function. Error messages are changed to be reported using error_report().

NOTE: The code is still not yet built. Further transformations will be
required to make it correctly interface to the new XenBus/XenDevice framework. They will be delivered in a subsequent patch.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

v2:
- Leave existing boilerplate alone, other than removing the now-incorrect description

---
 hw/block/dataplane/xen-block.c | 409 ++---------------------------------------
 1 file changed, 16 insertions(+), 393 deletions(-)
hw/block/dataplane/xen-block.c +16 -393
index 9fae505..98f987d 100644
@@ -1,6 +1,4 @@
 /*
- *  xen paravirt block device backend
- *
  *  (c) Gerd Hoffmann <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,26 +17,12 @@
  *  GNU GPL, version 2 or (at your option) any later version.
  */
 
-#include "qemu/osdep.h"
-#include "qemu/units.h"
-#include <sys/ioctl.h>
-#include <sys/uio.h>
-
-#include "hw/hw.h"
-#include "hw/xen/xen_backend.h"
-#include "xen_blkif.h"
-#include "sysemu/blockdev.h"
-#include "sysemu/iothread.h"
-#include "sysemu/block-backend.h"
-#include "qapi/error.h"
-#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qstring.h"
-#include "trace.h"
-
-/* ------------------------------------------------------------- */
-
-#define BLOCK_SIZE  512
-#define IOCB_COUNT  (BLKIF_MAX_SEGMENTS_PER_REQUEST + 2)
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
 
 struct ioreq {
     blkif_request_t     req;
@@ -101,8 +85,6 @@ struct XenBlkDev {
     AioContext          *ctx;
 };
 
-/* ------------------------------------------------------------- */
-
 static void ioreq_reset(struct ioreq *ioreq)
 {
     memset(&ioreq->req, 0, sizeof(ioreq->req));
@@ -183,11 +165,6 @@ static int ioreq_parse(struct ioreq *ioreq)
     size_t len;
     int i;
 
-    xen_pv_printf(
-        xendev, 3,
-        "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n",
-        ioreq->req.operation, ioreq->req.nr_segments,
-        ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number);
     switch (ioreq->req.operation) {
     case BLKIF_OP_READ:
         break;
@@ -202,28 +179,27 @@ static int ioreq_parse(struct ioreq *ioreq)
     case BLKIF_OP_DISCARD:
         return 0;
     default:
-        xen_pv_printf(xendev, 0, "error: unknown operation (%d)\n",
-                      ioreq->req.operation);
+        error_report("error: unknown operation (%d)", ioreq->req.operation);
         goto err;
     };
 
     if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') {
-        xen_pv_printf(xendev, 0, "error: write req for ro device\n");
+        error_report("error: write req for ro device");
         goto err;
     }
 
     ioreq->start = ioreq->req.sector_number * blkdev->file_blk;
     for (i = 0; i < ioreq->req.nr_segments; i++) {
         if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
-            xen_pv_printf(xendev, 0, "error: nr_segments too big\n");
+            error_report("error: nr_segments too big");
             goto err;
         }
         if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) {
-            xen_pv_printf(xendev, 0, "error: first > last sector\n");
+            error_report("error: first > last sector");
             goto err;
         }
         if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) {
-            xen_pv_printf(xendev, 0, "error: page crossing\n");
+            error_report("error: page crossing");
             goto err;
         }
 
@@ -232,7 +208,7 @@ static int ioreq_parse(struct ioreq *ioreq)
         ioreq->size += len;
     }
     if (ioreq->start + ioreq->size > blkdev->file_size) {
-        xen_pv_printf(xendev, 0, "error: access beyond end of file\n");
+        error_report("error: access beyond end of file");
         goto err;
     }
     return 0;
@@ -278,8 +254,7 @@ static int ioreq_grant_copy(struct ioreq *ioreq)
     rc = xen_be_copy_grant_refs(xendev, to_domain, segs, count);
 
     if (rc) {
-        xen_pv_printf(xendev, 0,
-                      "failed to copy data %d\n", rc);
+        error_report("failed to copy data %d", rc);
         ioreq->aio_errors++;
         return -1;
     }
@@ -298,8 +273,9 @@ static void qemu_aio_complete(void *opaque, int ret)
     aio_context_acquire(blkdev->ctx);
 
     if (ret != 0) {
-        xen_pv_printf(xendev, 0, "%s I/O error\n",
-                      ioreq->req.operation == BLKIF_OP_READ ? "read" : "write");
+        error_report("%s I/O error",
+                     ioreq->req.operation == BLKIF_OP_READ ?
+                     "read" : "write");
         ioreq->aio_errors++;
     }
 
@@ -605,8 +581,6 @@ static void blk_handle_requests(struct XenBlkDev *blkdev)
     }
 }
 
-/* ------------------------------------------------------------- */
-
 static void blk_bh(void *opaque)
 {
     struct XenBlkDev *blkdev = opaque;
@@ -634,346 +608,6 @@ static void blk_alloc(struct XenLegacyDevice *xendev)
     blkdev->bh = aio_bh_new(blkdev->ctx, blk_bh, blkdev);
 }
 
-static void blk_parse_discard(struct XenBlkDev *blkdev)
-{
-    struct XenLegacyDevice *xendev = &blkdev->xendev;
-    int enable;
-
-    blkdev->feature_discard = true;
-
-    if (xenstore_read_be_int(xendev, "discard-enable", &enable) == 0) {
-        blkdev->feature_discard = !!enable;
-    }
-
-    if (blkdev->feature_discard) {
-        xenstore_write_be_int(xendev, "feature-discard", 1);
-    }
-}
-
-static int blk_init(struct XenLegacyDevice *xendev)
-{
-    struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
-    int info = 0;
-    char *directiosafe = NULL;
-
-    trace_xen_disk_init(xendev->name);
-
-    /* read xenstore entries */
-    if (blkdev->params == NULL) {
-        char *h = NULL;
-        blkdev->params = xenstore_read_be_str(xendev, "params");
-        if (blkdev->params != NULL) {
-            h = strchr(blkdev->params, ':');
-        }
-        if (h != NULL) {
-            blkdev->fileproto = blkdev->params;
-            blkdev->filename  = h + 1;
-            *h = 0;
-        } else {
-            blkdev->fileproto = "<unset>";
-            blkdev->filename  = blkdev->params;
-        }
-    }
-    if (!strcmp("aio", blkdev->fileproto)) {
-        blkdev->fileproto = "raw";
-    }
-    if (!strcmp("vhd", blkdev->fileproto)) {
-        blkdev->fileproto = "vpc";
-    }
-    if (blkdev->mode == NULL) {
-        blkdev->mode = xenstore_read_be_str(xendev, "mode");
-    }
-    if (blkdev->type == NULL) {
-        blkdev->type = xenstore_read_be_str(xendev, "type");
-    }
-    if (blkdev->dev == NULL) {
-        blkdev->dev = xenstore_read_be_str(xendev, "dev");
-    }
-    if (blkdev->devtype == NULL) {
-        blkdev->devtype = xenstore_read_be_str(xendev, "device-type");
-    }
-    directiosafe = xenstore_read_be_str(xendev, "direct-io-safe");
-    blkdev->directiosafe = (directiosafe && atoi(directiosafe));
-
-    /* do we have all we need? */
-    if (blkdev->params == NULL ||
-        blkdev->mode == NULL   ||
-        blkdev->type == NULL   ||
-        blkdev->dev == NULL) {
-        goto out_error;
-    }
-
-    /* read-only ? */
-    if (strcmp(blkdev->mode, "w")) {
-        info  |= VDISK_READONLY;
-    }
-
-    /* cdrom ? */
-    if (blkdev->devtype && !strcmp(blkdev->devtype, "cdrom")) {
-        info  |= VDISK_CDROM;
-    }
-
-    blkdev->file_blk  = BLOCK_SIZE;
-
-    /* fill info
-     * blk_connect supplies sector-size and sectors
-     */
-    xenstore_write_be_int(xendev, "feature-flush-cache", 1);
-    xenstore_write_be_int(xendev, "info", info);
-
-    xenstore_write_be_int(xendev, "max-ring-page-order",
-                          MAX_RING_PAGE_ORDER);
-
-    blk_parse_discard(blkdev);
-
-    g_free(directiosafe);
-    return 0;
-
-out_error:
-    g_free(blkdev->params);
-    blkdev->params = NULL;
-    g_free(blkdev->mode);
-    blkdev->mode = NULL;
-    g_free(blkdev->type);
-    blkdev->type = NULL;
-    g_free(blkdev->dev);
-    blkdev->dev = NULL;
-    g_free(blkdev->devtype);
-    blkdev->devtype = NULL;
-    g_free(directiosafe);
-    blkdev->directiosafe = false;
-    return -1;
-}
-
-static int blk_connect(struct XenLegacyDevice *xendev)
-{
-    struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
-    int index, qflags;
-    bool readonly = true;
-    bool writethrough = true;
-    int order, ring_ref;
-    unsigned int ring_size, max_grants;
-    unsigned int i;
-
-    trace_xen_disk_connect(xendev->name);
-
-    /* read-only ? */
-    if (blkdev->directiosafe) {
-        qflags = BDRV_O_NOCACHE | BDRV_O_NATIVE_AIO;
-    } else {
-        qflags = 0;
-        writethrough = false;
-    }
-    if (strcmp(blkdev->mode, "w") == 0) {
-        qflags |= BDRV_O_RDWR;
-        readonly = false;
-    }
-    if (blkdev->feature_discard) {
-        qflags |= BDRV_O_UNMAP;
-    }
-
-    /* init qemu block driver */
-    index = (xendev->dev - 202 * 256) / 16;
-    blkdev->dinfo = drive_get(IF_XEN, 0, index);
-    if (!blkdev->dinfo) {
-        Error *local_err = NULL;
-        QDict *options = NULL;
-
-        if (strcmp(blkdev->fileproto, "<unset>")) {
-            options = qdict_new();
-            qdict_put_str(options, "driver", blkdev->fileproto);
-        }
-
-        /* setup via xenbus -> create new block driver instance */
-        xen_pv_printf(xendev, 2, "create new bdrv (xenbus setup)\n");
-        blkdev->blk = blk_new_open(blkdev->filename, NULL, options,
-                                   qflags, &local_err);
-        if (!blkdev->blk) {
-            xen_pv_printf(xendev, 0, "error: %s\n",
-                          error_get_pretty(local_err));
-            error_free(local_err);
-            return -1;
-        }
-        blk_set_enable_write_cache(blkdev->blk, !writethrough);
-    } else {
-        /* setup via qemu cmdline -> already setup for us */
-        xen_pv_printf(xendev, 2,
-                      "get configured bdrv (cmdline setup)\n");
-        blkdev->blk = blk_by_legacy_dinfo(blkdev->dinfo);
-        if (blk_is_read_only(blkdev->blk) && !readonly) {
-            xen_pv_printf(xendev, 0, "Unexpected read-only drive");
-            blkdev->blk = NULL;
-            return -1;
-        }
-        /* blkdev->blk is not create by us, we get a reference
-         * so we can blk_unref() unconditionally */
-        blk_ref(blkdev->blk);
-    }
-    blk_attach_dev_legacy(blkdev->blk, blkdev);
-    blkdev->file_size = blk_getlength(blkdev->blk);
-    if (blkdev->file_size < 0) {
-        BlockDriverState *bs = blk_bs(blkdev->blk);
-        const char *drv_name = bs ? bdrv_get_format_name(bs) : NULL;
-        xen_pv_printf(xendev, 1, "blk_getlength: %d (%s) | drv %s\n",
-                      (int)blkdev->file_size, strerror(-blkdev->file_size),
-                      drv_name ?: "-");
-        blkdev->file_size = 0;
-    }
-
-    xen_pv_printf(xendev, 1, "type \"%s\", fileproto \"%s\", filename \"%s\","
-                  " size %" PRId64 " (%" PRId64 " MB)\n",
-                  blkdev->type, blkdev->fileproto, blkdev->filename,
-                  blkdev->file_size, blkdev->file_size / MiB);
-
-    /* Fill in number of sector size and number of sectors */
-    xenstore_write_be_int(xendev, "sector-size", blkdev->file_blk);
-    xenstore_write_be_int64(xendev, "sectors",
-                            blkdev->file_size / blkdev->file_blk);
-
-    if (xenstore_read_fe_int(xendev, "ring-page-order",
-                             &order) == -1) {
-        blkdev->nr_ring_ref = 1;
-
-        if (xenstore_read_fe_int(xendev, "ring-ref",
-                                 &ring_ref) == -1) {
-            return -1;
-        }
-        blkdev->ring_ref[0] = ring_ref;
-
-    } else if (order >= 0 && order <= MAX_RING_PAGE_ORDER) {
-        blkdev->nr_ring_ref = 1 << order;
-
-        for (i = 0; i < blkdev->nr_ring_ref; i++) {
-            char *key;
-
-            key = g_strdup_printf("ring-ref%u", i);
-            if (!key) {
-                return -1;
-            }
-
-            if (xenstore_read_fe_int(xendev, key,
-                                     &ring_ref) == -1) {
-                g_free(key);
-                return -1;
-            }
-            blkdev->ring_ref[i] = ring_ref;
-
-            g_free(key);
-        }
-    } else {
-        xen_pv_printf(xendev, 0, "invalid ring-page-order: %d\n",
-                      order);
-        return -1;
-    }
-
-    if (xenstore_read_fe_int(xendev, "event-channel",
-                             &xendev->remote_port) == -1) {
-        return -1;
-    }
-
-    if (!xendev->protocol) {
-        blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
-    } else if (strcmp(xendev->protocol, XEN_IO_PROTO_ABI_NATIVE) == 0) {
-        blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
-    } else if (strcmp(xendev->protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {
-        blkdev->protocol = BLKIF_PROTOCOL_X86_32;
-    } else if (strcmp(xendev->protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {
-        blkdev->protocol = BLKIF_PROTOCOL_X86_64;
-    } else {
-        blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
-    }
-
-    ring_size = XC_PAGE_SIZE * blkdev->nr_ring_ref;
-    switch (blkdev->protocol) {
-    case BLKIF_PROTOCOL_NATIVE:
-    {
-        blkdev->max_requests = __CONST_RING_SIZE(blkif, ring_size);
-        break;
-    }
-    case BLKIF_PROTOCOL_X86_32:
-    {
-        blkdev->max_requests = __CONST_RING_SIZE(blkif_x86_32, ring_size);
-        break;
-    }
-    case BLKIF_PROTOCOL_X86_64:
-    {
-        blkdev->max_requests = __CONST_RING_SIZE(blkif_x86_64, ring_size);
-        break;
-    }
-    default:
-        return -1;
-    }
-
-    /* Add on the number needed for the ring pages */
-    max_grants = blkdev->nr_ring_ref;
-
-    xen_be_set_max_grant_refs(xendev, max_grants);
-    blkdev->sring = xen_be_map_grant_refs(xendev, blkdev->ring_ref,
-                                          blkdev->nr_ring_ref,
-                                          PROT_READ | PROT_WRITE);
-    if (!blkdev->sring) {
-        return -1;
-    }
-
-    switch (blkdev->protocol) {
-    case BLKIF_PROTOCOL_NATIVE:
-    {
-        blkif_sring_t *sring_native = blkdev->sring;
-        BACK_RING_INIT(&blkdev->rings.native, sring_native, ring_size);
-        break;
-    }
-    case BLKIF_PROTOCOL_X86_32:
-    {
-        blkif_x86_32_sring_t *sring_x86_32 = blkdev->sring;
-
-        BACK_RING_INIT(&blkdev->rings.x86_32_part, sring_x86_32, ring_size);
-        break;
-    }
-    case BLKIF_PROTOCOL_X86_64:
-    {
-        blkif_x86_64_sring_t *sring_x86_64 = blkdev->sring;
-
-        BACK_RING_INIT(&blkdev->rings.x86_64_part, sring_x86_64, ring_size);
-        break;
-    }
-    }
-
-    blk_set_aio_context(blkdev->blk, blkdev->ctx);
-
-    xen_be_bind_evtchn(xendev);
-
-    xen_pv_printf(xendev, 1, "ok: proto %s, nr-ring-ref %u, "
-                  "remote port %d, local port %d\n",
-                  xendev->protocol, blkdev->nr_ring_ref,
-                  xendev->remote_port, xendev->local_port);
-    return 0;
-}
-
-static void blk_disconnect(struct XenLegacyDevice *xendev)
-{
-    struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
-
-    trace_xen_disk_disconnect(xendev->name);
-
-    aio_context_acquire(blkdev->ctx);
-
-    if (blkdev->blk) {
-        blk_set_aio_context(blkdev->blk, qemu_get_aio_context());
-        blk_detach_dev(blkdev->blk, blkdev);
-        blk_unref(blkdev->blk);
-        blkdev->blk = NULL;
-    }
-    xen_pv_unbind_evtchn(xendev);
-
-    aio_context_release(blkdev->ctx);
-
-    if (blkdev->sring) {
-        xen_be_unmap_grant_refs(xendev, blkdev->sring,
-                                blkdev->nr_ring_ref);
-        blkdev->sring = NULL;
-    }
-}
-
 static int blk_free(struct XenLegacyDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
@@ -1006,14 +640,3 @@ static void blk_event(struct XenLegacyDevice *xendev)
 
     qemu_bh_schedule(blkdev->bh);
 }
-
-struct XenDevOps xen_blkdev_ops = {
-    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
-    .size       = sizeof(struct XenBlkDev),
-    .alloc      = blk_alloc,
-    .init       = blk_init,
-    .initialise = blk_connect,
-    .disconnect = blk_disconnect,
-    .event      = blk_event,
-    .free       = blk_free,
-};
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#31 lore raw

Re: [PATCH v2 09/18] xen: remove unnecessary code from dataplane/xen-block.c

Quoted 19 lines · Paul Durrant

v2:
- Leave existing boilerplate alone, other than removing the now-incorrect description

---
 hw/block/dataplane/xen-block.c | 409 ++---------------------------------------
 1 file changed, 16 insertions(+), 393 deletions(-)
hw/block/dataplane/xen-block.c +0 -2
index 9fae505..98f987d 100644
@@ -1,6 +1,4 @@
 /*
- *  xen paravirt block device backend
- *
  *  (c) Gerd Hoffmann <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify

hw/block/dataplane/xen-block.c line 21

Quoted 5 lines
hw/block/dataplane/xen-block.c +2 -0
@@ -19,26 +17,12 @@
  *  GNU GPL, version 2 or (at your option) any later version.
  */
 
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.

You can add this copyright line just after Gerd's one abrove.

hw/block/dataplane/xen-block.c line 24

Quoted 3 lines
hw/block/dataplane/xen-block.c +3 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.

And I'm pretty sure this should not be added. The boilerplate at the top of the file already state that your contributions is going to be GPLv2+.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#32 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH v2 09/18] xen: remove unnecessary code from dataplane/xen-block.c

In reply to Paul Durrant
Quoted 19 lines · Paul Durrant

v2:
- Leave existing boilerplate alone, other than removing the now-incorrect description

---
 hw/block/dataplane/xen-block.c | 409 ++---------------------------------------
 1 file changed, 16 insertions(+), 393 deletions(-)
hw/block/dataplane/xen-block.c +0 -2
index 9fae505..98f987d 100644
@@ -1,6 +1,4 @@
 /*
- *  xen paravirt block device backend
- *
  *  (c) Gerd Hoffmann <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify

hw/block/dataplane/xen-block.c line 21

Quoted 5 lines
hw/block/dataplane/xen-block.c +2 -0
@@ -19,26 +17,12 @@
  *  GNU GPL, version 2 or (at your option) any later version.
  */
 
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.

You can add this copyright line just after Gerd's one abrove.

hw/block/dataplane/xen-block.c line 24

Quoted 3 lines
hw/block/dataplane/xen-block.c +3 -0
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.

And I'm pretty sure this should not be added. The boilerplate at the top of the file already state that your contributions is going to be GPLv2+.

Signature · 1 line
Anthony PERARD
#33 lore raw

PATCH v2 10/18 xen: add header and build dataplane/xen-block.c

In reply to Paul Durrant

This patch adds the transformations necessary to get dataplane/xen-block.c to build against the new XenBus/XenDevice framework. MAINTAINERS is also updated due to the introduction of dataplane/xen-block.h.

NOTE: Existing data structure names are retained for the moment. These will
be modified by subsequent patches. A typedef for XenBlockDataPlane has been added to the header (based on the old struct XenBlkDev name for the moment) so that the old names don't need to leak out of the dataplane code.

---
Cc: Stefan Hajnoczi <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

v2:
- Tidy up header inclusions
- Get rid of error_fatal

---
 MAINTAINERS                      |   1 +
 hw/block/dataplane/Makefile.objs |   1 +
 hw/block/dataplane/xen-block.c   | 356 ++++++++++++++++++++++++++++-----------
 hw/block/dataplane/xen-block.h   |  29 ++++
 4 files changed, 287 insertions(+), 100 deletions(-)
 create mode 100644 hw/block/dataplane/xen-block.h
MAINTAINERS +1 -0
index ab62ad4..9875581 100644
@@ -408,6 +408,7 @@ F: hw/block/dataplane/xen*
 F: hw/xen/
 F: hw/xenpv/
 F: hw/i386/xen/
+F: include/hw/block/dataplane/xen*
 F: include/hw/xen/
 F: include/sysemu/xen-mapcache.h
 
hw/block/dataplane/Makefile.objs +1 -0
index e786f66..c6c68db 100644
@@ -1 +1,2 @@
 obj-y += virtio-blk.o
+obj-$(CONFIG_XEN) += xen-block.o
hw/block/dataplane/xen-block.c +256 -100

478 lines not on this page · raw message

hw/block/dataplane/xen-block.h new file +29 -0
new file mode 100644
index 0000000..f31da38
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_BLOCK_DATAPLANE_XEN_BLOCK_H
+#define HW_BLOCK_DATAPLANE_XEN_BLOCK_H
+
+#include "hw/block/block.h"
+#include "hw/xen/xen-bus.h"
+#include "sysemu/iothread.h"
+
+typedef struct XenBlkDev XenBlockDataPlane;
+
+XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
+                                              BlockConf *conf,
+                                              IOThread *iothread);
+void xen_block_dataplane_destroy(XenBlockDataPlane *dataplane);
+void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
+                               const unsigned int ring_ref[],
+                               unsigned int nr_ring_ref,
+                               unsigned int event_channel,
+                               unsigned int protocol,
+                               Error **errp);
+void xen_block_dataplane_stop(XenBlockDataPlane *dataplane);
+
+#endif /* HW_BLOCK_DATAPLANE_XEN_BLOCK_H */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 10/18
#34 lore raw

Re: [Qemu-devel] [PATCH v2 10/18] xen: add header and build dataplane/xen-block.c

Quoted 11 lines · Paul Durrant

This patch adds the transformations necessary to get dataplane/xen-block.c to build against the new XenBus/XenDevice framework. MAINTAINERS is also updated due to the introduction of dataplane/xen-block.h.

NOTE: Existing data structure names are retained for the moment. These will
be modified by subsequent patches. A typedef for XenBlockDataPlane has been added to the header (based on the old struct XenBlkDev name for the moment) so that the old names don't need to leak out of the dataplane code.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#35 lore raw

PATCH v2 11/18 xen: remove 'XenBlkDev' and 'blkdev' names from dataplane/xen-block

In reply to Paul Durrant

This is a purely cosmetic patch that substitutes the old 'struct XenBlkDev' name with 'XenBlockDataPlane' and 'blkdev' field/variable names with 'dataplane', and then does necessary fix-up to adhere to coding style.

No functional change.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

---
 hw/block/dataplane/xen-block.c | 352 +++++++++++++++++++++--------------------
 hw/block/dataplane/xen-block.h |   2 +-
 2 files changed, 183 insertions(+), 171 deletions(-)
hw/block/dataplane/xen-block.c +182 -170
index 20d16e7..6ecd160 100644
@@ -44,12 +44,12 @@ struct ioreq {
     int presync;
     int aio_inflight;
     int aio_errors;
-    struct XenBlkDev *blkdev;
+    XenBlockDataPlane *dataplane;
     QLIST_ENTRY(ioreq) list;
     BlockAcctCookie acct;
 };
 
-struct XenBlkDev {
+struct XenBlockDataPlane {
     XenDevice *xendev;
     XenEventChannel *event_channel;
     unsigned int *ring_ref;
@@ -85,33 +85,33 @@ static void ioreq_reset(struct ioreq *ioreq)
     ioreq->aio_inflight = 0;
     ioreq->aio_errors = 0;
 
-    ioreq->blkdev = NULL;
+    ioreq->dataplane = NULL;
     memset(&ioreq->list, 0, sizeof(ioreq->list));
     memset(&ioreq->acct, 0, sizeof(ioreq->acct));
 
     qemu_iovec_reset(&ioreq->v);
 }
 
-static struct ioreq *ioreq_start(struct XenBlkDev *blkdev)
+static struct ioreq *ioreq_start(XenBlockDataPlane *dataplane)
 {
     struct ioreq *ioreq = NULL;
 
-    if (QLIST_EMPTY(&blkdev->freelist)) {
-        if (blkdev->requests_total >= blkdev->max_requests) {
+    if (QLIST_EMPTY(&dataplane->freelist)) {
+        if (dataplane->requests_total >= dataplane->max_requests) {
             goto out;
         }
         /* allocate new struct */
         ioreq = g_malloc0(sizeof(*ioreq));
-        ioreq->blkdev = blkdev;
-        blkdev->requests_total++;
+        ioreq->dataplane = dataplane;
+        dataplane->requests_total++;
         qemu_iovec_init(&ioreq->v, 1);
     } else {
         /* get one from freelist */
-        ioreq = QLIST_FIRST(&blkdev->freelist);
+        ioreq = QLIST_FIRST(&dataplane->freelist);
         QLIST_REMOVE(ioreq, list);
     }
-    QLIST_INSERT_HEAD(&blkdev->inflight, ioreq, list);
-    blkdev->requests_inflight++;
+    QLIST_INSERT_HEAD(&dataplane->inflight, ioreq, list);
+    dataplane->requests_inflight++;
 
 out:
     return ioreq;
@@ -119,26 +119,26 @@ out:
 
 static void ioreq_finish(struct ioreq *ioreq)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
 
     QLIST_REMOVE(ioreq, list);
-    QLIST_INSERT_HEAD(&blkdev->finished, ioreq, list);
-    blkdev->requests_inflight--;
-    blkdev->requests_finished++;
+    QLIST_INSERT_HEAD(&dataplane->finished, ioreq, list);
+    dataplane->requests_inflight--;
+    dataplane->requests_finished++;
 }
 
 static void ioreq_release(struct ioreq *ioreq, bool finish)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
 
     QLIST_REMOVE(ioreq, list);
     ioreq_reset(ioreq);
-    ioreq->blkdev = blkdev;
-    QLIST_INSERT_HEAD(&blkdev->freelist, ioreq, list);
+    ioreq->dataplane = dataplane;
+    QLIST_INSERT_HEAD(&dataplane->freelist, ioreq, list);
     if (finish) {
-        blkdev->requests_finished--;
+        dataplane->requests_finished--;
     } else {
-        blkdev->requests_inflight--;
+        dataplane->requests_inflight--;
     }
 }
 
@@ -148,7 +148,7 @@ static void ioreq_release(struct ioreq *ioreq, bool finish)
  */
 static int ioreq_parse(struct ioreq *ioreq)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
     size_t len;
     int i;
 
@@ -171,12 +171,12 @@ static int ioreq_parse(struct ioreq *ioreq)
     };
 
     if (ioreq->req.operation != BLKIF_OP_READ &&
-        blk_is_read_only(blkdev->blk)) {
+        blk_is_read_only(dataplane->blk)) {
         error_report("error: write req for ro device");
         goto err;
     }
 
-    ioreq->start = ioreq->req.sector_number * blkdev->file_blk;
+    ioreq->start = ioreq->req.sector_number * dataplane->file_blk;
     for (i = 0; i < ioreq->req.nr_segments; i++) {
         if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
             error_report("error: nr_segments too big");
@@ -186,16 +186,16 @@ static int ioreq_parse(struct ioreq *ioreq)
             error_report("error: first > last sector");
             goto err;
         }
-        if (ioreq->req.seg[i].last_sect * blkdev->file_blk >= XC_PAGE_SIZE) {
+        if (ioreq->req.seg[i].last_sect * dataplane->file_blk >= XC_PAGE_SIZE) {
             error_report("error: page crossing");
             goto err;
         }
 
         len = (ioreq->req.seg[i].last_sect -
-               ioreq->req.seg[i].first_sect + 1) * blkdev->file_blk;
+               ioreq->req.seg[i].first_sect + 1) * dataplane->file_blk;
         ioreq->size += len;
     }
-    if (ioreq->start + ioreq->size > blkdev->file_size) {
+    if (ioreq->start + ioreq->size > dataplane->file_size) {
         error_report("error: access beyond end of file");
         goto err;
     }
@@ -208,11 +208,11 @@ err:
 
 static int ioreq_grant_copy(struct ioreq *ioreq)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
-    XenDevice *xendev = blkdev->xendev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenDevice *xendev = dataplane->xendev;
     XenDeviceGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     int i, count;
-    int64_t file_blk = blkdev->file_blk;
+    int64_t file_blk = dataplane->file_blk;
     bool to_domain = (ioreq->req.operation == BLKIF_OP_READ);
     void *virt = ioreq->buf;
     Error *local_err = NULL;
@@ -257,9 +257,9 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq);
 static void qemu_aio_complete(void *opaque, int ret)
 {
     struct ioreq *ioreq = opaque;
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
 
-    aio_context_acquire(blkdev->ctx);
+    aio_context_acquire(dataplane->ctx);
 
     if (ret != 0) {
         error_report("%s I/O error",
@@ -308,25 +308,25 @@ static void qemu_aio_complete(void *opaque, int ret)
         }
     case BLKIF_OP_READ:
         if (ioreq->status == BLKIF_RSP_OKAY) {
-            block_acct_done(blk_get_stats(blkdev->blk), &ioreq->acct);
+            block_acct_done(blk_get_stats(dataplane->blk), &ioreq->acct);
         } else {
-            block_acct_failed(blk_get_stats(blkdev->blk), &ioreq->acct);
+            block_acct_failed(blk_get_stats(dataplane->blk), &ioreq->acct);
         }
         break;
     case BLKIF_OP_DISCARD:
     default:
         break;
     }
-    qemu_bh_schedule(blkdev->bh);
+    qemu_bh_schedule(dataplane->bh);
 
 done:
-    aio_context_release(blkdev->ctx);
+    aio_context_release(dataplane->ctx);
 }
 
 static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number,
                               uint64_t nr_sectors)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
     int64_t byte_offset;
     int byte_chunk;
     uint64_t byte_remaining, limit;
@@ -335,18 +335,18 @@ static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number,
 
     /* Wrap around, or overflowing byte limit? */
     if (sec_start + sec_count < sec_count ||
-        sec_start + sec_count > INT64_MAX / blkdev->file_blk) {
+        sec_start + sec_count > INT64_MAX / dataplane->file_blk) {
         return false;
     }
 
-    limit = BDRV_REQUEST_MAX_SECTORS * blkdev->file_blk;
-    byte_offset = sec_start * blkdev->file_blk;
-    byte_remaining = sec_count * blkdev->file_blk;
+    limit = BDRV_REQUEST_MAX_SECTORS * dataplane->file_blk;
+    byte_offset = sec_start * dataplane->file_blk;
+    byte_remaining = sec_count * dataplane->file_blk;
 
     do {
         byte_chunk = byte_remaining > limit ? limit : byte_remaining;
         ioreq->aio_inflight++;
-        blk_aio_pdiscard(blkdev->blk, byte_offset, byte_chunk,
+        blk_aio_pdiscard(dataplane->blk, byte_offset, byte_chunk,
                          qemu_aio_complete, ioreq);
         byte_remaining -= byte_chunk;
         byte_offset += byte_chunk;
@@ -357,7 +357,7 @@ static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number,
 
 static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
 
     ioreq->buf = qemu_memalign(XC_PAGE_SIZE, ioreq->size);
     if (ioreq->req.nr_segments &&
@@ -370,17 +370,17 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
 
     ioreq->aio_inflight++;
     if (ioreq->presync) {
-        blk_aio_flush(ioreq->blkdev->blk, qemu_aio_complete, ioreq);
+        blk_aio_flush(ioreq->dataplane->blk, qemu_aio_complete, ioreq);
         return 0;
     }
 
     switch (ioreq->req.operation) {
     case BLKIF_OP_READ:
         qemu_iovec_add(&ioreq->v, ioreq->buf, ioreq->size);
-        block_acct_start(blk_get_stats(blkdev->blk), &ioreq->acct,
+        block_acct_start(blk_get_stats(dataplane->blk), &ioreq->acct,
                          ioreq->v.size, BLOCK_ACCT_READ);
         ioreq->aio_inflight++;
-        blk_aio_preadv(blkdev->blk, ioreq->start, &ioreq->v, 0,
+        blk_aio_preadv(dataplane->blk, ioreq->start, &ioreq->v, 0,
                        qemu_aio_complete, ioreq);
         break;
     case BLKIF_OP_WRITE:
@@ -390,12 +390,12 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
         }
 
         qemu_iovec_add(&ioreq->v, ioreq->buf, ioreq->size);
-        block_acct_start(blk_get_stats(blkdev->blk), &ioreq->acct,
+        block_acct_start(blk_get_stats(dataplane->blk), &ioreq->acct,
                          ioreq->v.size,
                          ioreq->req.operation == BLKIF_OP_WRITE ?
                          BLOCK_ACCT_WRITE : BLOCK_ACCT_FLUSH);
         ioreq->aio_inflight++;
-        blk_aio_pwritev(blkdev->blk, ioreq->start, &ioreq->v, 0,
+        blk_aio_pwritev(dataplane->blk, ioreq->start, &ioreq->v, 0,
                         qemu_aio_complete, ioreq);
         break;
     case BLKIF_OP_DISCARD:
@@ -423,27 +423,27 @@ err:
 
 static int blk_send_response_one(struct ioreq *ioreq)
 {
-    struct XenBlkDev *blkdev = ioreq->blkdev;
+    XenBlockDataPlane *dataplane = ioreq->dataplane;
     int send_notify = 0;
     int have_requests = 0;
     blkif_response_t *resp;
 
     /* Place on the response ring for the relevant domain. */
-    switch (blkdev->protocol) {
+    switch (dataplane->protocol) {
     case BLKIF_PROTOCOL_NATIVE:
         resp = (blkif_response_t *)RING_GET_RESPONSE(
-            &blkdev->rings.native,
-            blkdev->rings.native.rsp_prod_pvt);
+            &dataplane->rings.native,
+            dataplane->rings.native.rsp_prod_pvt);
         break;
     case BLKIF_PROTOCOL_X86_32:
         resp = (blkif_response_t *)RING_GET_RESPONSE(
-            &blkdev->rings.x86_32_part,
-            blkdev->rings.x86_32_part.rsp_prod_pvt);
+            &dataplane->rings.x86_32_part,
+            dataplane->rings.x86_32_part.rsp_prod_pvt);
         break;
     case BLKIF_PROTOCOL_X86_64:
         resp = (blkif_response_t *)RING_GET_RESPONSE(
-            &blkdev->rings.x86_64_part,
-            blkdev->rings.x86_64_part.rsp_prod_pvt);
+            &dataplane->rings.x86_64_part,
+            dataplane->rings.x86_64_part.rsp_prod_pvt);
         break;
     default:
         return 0;
@@ -453,42 +453,45 @@ static int blk_send_response_one(struct ioreq *ioreq)
     resp->operation = ioreq->req.operation;
     resp->status = ioreq->status;
 
-    blkdev->rings.common.rsp_prod_pvt++;
+    dataplane->rings.common.rsp_prod_pvt++;
 
-    RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&blkdev->rings.common, send_notify);
-    if (blkdev->rings.common.rsp_prod_pvt == blkdev->rings.common.req_cons) {
+    RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&dataplane->rings.common,
+                                         send_notify);
+    if (dataplane->rings.common.rsp_prod_pvt ==
+        dataplane->rings.common.req_cons) {
         /*
          * Tail check for pending requests. Allows frontend to avoid
          * notifications if requests are already in flight (lower
          * overheads and promotes batching).
          */
-        RING_FINAL_CHECK_FOR_REQUESTS(&blkdev->rings.common, have_requests);
-    } else if (RING_HAS_UNCONSUMED_REQUESTS(&blkdev->rings.common)) {
+        RING_FINAL_CHECK_FOR_REQUESTS(&dataplane->rings.common,
+                                      have_requests);
+    } else if (RING_HAS_UNCONSUMED_REQUESTS(&dataplane->rings.common)) {
         have_requests = 1;
     }
 
     if (have_requests) {
-        blkdev->more_work++;
+        dataplane->more_work++;
     }
     return send_notify;
 }
 
 /* walk finished list, send outstanding responses, free requests */
-static void blk_send_response_all(struct XenBlkDev *blkdev)
+static void blk_send_response_all(XenBlockDataPlane *dataplane)
 {
     struct ioreq *ioreq;
     int send_notify = 0;
 
-    while (!QLIST_EMPTY(&blkdev->finished)) {
-        ioreq = QLIST_FIRST(&blkdev->finished);
+    while (!QLIST_EMPTY(&dataplane->finished)) {
+        ioreq = QLIST_FIRST(&dataplane->finished);
         send_notify += blk_send_response_one(ioreq);
         ioreq_release(ioreq, true);
     }
     if (send_notify) {
         Error *local_err = NULL;
 
-        xen_device_notify_event_channel(blkdev->xendev,
-                                        blkdev->event_channel,
+        xen_device_notify_event_channel(dataplane->xendev,
+                                        dataplane->event_channel,
                                         &local_err);
         if (local_err) {
             error_report_err(local_err);
@@ -496,67 +499,76 @@ static void blk_send_response_all(struct XenBlkDev *blkdev)
     }
 }
 
-static int blk_get_request(struct XenBlkDev *blkdev, struct ioreq *ioreq,
+static int blk_get_request(XenBlockDataPlane *dataplane, struct ioreq *ioreq,
                            RING_IDX rc)
 {
-    switch (blkdev->protocol) {
-    case BLKIF_PROTOCOL_NATIVE:
-        memcpy(&ioreq->req, RING_GET_REQUEST(&blkdev->rings.native, rc),
-               sizeof(ioreq->req));
+    switch (dataplane->protocol) {
+    case BLKIF_PROTOCOL_NATIVE: {
+        blkif_request_t *req =
+            RING_GET_REQUEST(&dataplane->rings.native, rc);
+
+        memcpy(&ioreq->req, req, sizeof(ioreq->req));
         break;
-    case BLKIF_PROTOCOL_X86_32:
-        blkif_get_x86_32_req(&ioreq->req,
-                             RING_GET_REQUEST(&blkdev->rings.x86_32_part, rc));
+    }
+    case BLKIF_PROTOCOL_X86_32: {
+        blkif_x86_32_request_t *req =
+            RING_GET_REQUEST(&dataplane->rings.x86_32_part, rc);
+
+        blkif_get_x86_32_req(&ioreq->req, req);
         break;
-    case BLKIF_PROTOCOL_X86_64:
-        blkif_get_x86_64_req(&ioreq->req,
-                             RING_GET_REQUEST(&blkdev->rings.x86_64_part, rc));
+    }
+    case BLKIF_PROTOCOL_X86_64: {
+        blkif_x86_64_request_t *req =
+            RING_GET_REQUEST(&dataplane->rings.x86_64_part, rc);
+
+        blkif_get_x86_64_req(&ioreq->req, req);
         break;
     }
+    }
     /* Prevent the compiler from accessing the on-ring fields instead. */
     barrier();
     return 0;
 }
 
-static void blk_handle_requests(struct XenBlkDev *blkdev)
+static void blk_handle_requests(XenBlockDataPlane *dataplane)
 {
     RING_IDX rc, rp;
     struct ioreq *ioreq;
 
-    blkdev->more_work = 0;
+    dataplane->more_work = 0;
 
-    rc = blkdev->rings.common.req_cons;
-    rp = blkdev->rings.common.sring->req_prod;
+    rc = dataplane->rings.common.req_cons;
+    rp = dataplane->rings.common.sring->req_prod;
     xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
 
-    blk_send_response_all(blkdev);
+    blk_send_response_all(dataplane);
     while (rc != rp) {
         /* pull request from ring */
-        if (RING_REQUEST_CONS_OVERFLOW(&blkdev->rings.common, rc)) {
+        if (RING_REQUEST_CONS_OVERFLOW(&dataplane->rings.common, rc)) {
             break;
         }
-        ioreq = ioreq_start(blkdev);
+        ioreq = ioreq_start(dataplane);
         if (ioreq == NULL) {
-            blkdev->more_work++;
+            dataplane->more_work++;
             break;
         }
-        blk_get_request(blkdev, ioreq, rc);
-        blkdev->rings.common.req_cons = ++rc;
+        blk_get_request(dataplane, ioreq, rc);
+        dataplane->rings.common.req_cons = ++rc;
 
         /* parse them */
         if (ioreq_parse(ioreq) != 0) {
 
             switch (ioreq->req.operation) {
             case BLKIF_OP_READ:
-                block_acct_invalid(blk_get_stats(blkdev->blk),
+                block_acct_invalid(blk_get_stats(dataplane->blk),
                                    BLOCK_ACCT_READ);
                 break;
             case BLKIF_OP_WRITE:
-                block_acct_invalid(blk_get_stats(blkdev->blk),
+                block_acct_invalid(blk_get_stats(dataplane->blk),
                                    BLOCK_ACCT_WRITE);
                 break;
             case BLKIF_OP_FLUSH_DISKCACHE:
-                block_acct_invalid(blk_get_stats(blkdev->blk),
+                block_acct_invalid(blk_get_stats(dataplane->blk),
                                    BLOCK_ACCT_FLUSH);
             default:
                 break;
@@ -565,8 +577,8 @@ static void blk_handle_requests(struct XenBlkDev *blkdev)
             if (blk_send_response_one(ioreq)) {
                 Error *local_err = NULL;
 
-                xen_device_notify_event_channel(blkdev->xendev,
-                                                blkdev->event_channel,
+                xen_device_notify_event_channel(dataplane->xendev,
+                                                dataplane->event_channel,
                                                 &local_err);
                 if (local_err) {
                     error_report_err(local_err);
@@ -579,173 +591,173 @@ static void blk_handle_requests(struct XenBlkDev *blkdev)
         ioreq_runio_qemu_aio(ioreq);
     }
 
-    if (blkdev->more_work && blkdev->requests_inflight < blkdev->max_requests) {
-        qemu_bh_schedule(blkdev->bh);
+    if (dataplane->more_work &&
+        dataplane->requests_inflight < dataplane->max_requests) {
+        qemu_bh_schedule(dataplane->bh);
     }
 }
 
 static void blk_bh(void *opaque)
 {
-    struct XenBlkDev *blkdev = opaque;
+    XenBlockDataPlane *dataplane = opaque;
 
-    aio_context_acquire(blkdev->ctx);
-    blk_handle_requests(blkdev);
-    aio_context_release(blkdev->ctx);
+    aio_context_acquire(dataplane->ctx);
+    blk_handle_requests(dataplane);
+    aio_context_release(dataplane->ctx);
 }
 
 static void blk_event(void *opaque)
 {
-    struct XenBlkDev *blkdev = opaque;
+    XenBlockDataPlane *dataplane = opaque;
 
-    qemu_bh_schedule(blkdev->bh);
+    qemu_bh_schedule(dataplane->bh);
 }
 
-struct XenBlkDev *xen_block_dataplane_create(XenDevice *xendev,
-                                             BlockConf *conf,
-                                             IOThread *iothread)
+XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
+                                              BlockConf *conf,
+                                              IOThread *iothread)
 {
-    struct XenBlkDev *blkdev = g_new0(struct XenBlkDev, 1);
+    XenBlockDataPlane *dataplane = g_new0(XenBlockDataPlane, 1);
 
-    blkdev->xendev = xendev;
-    blkdev->file_blk = conf->logical_block_size;
-    blkdev->blk = conf->blk;
-    blkdev->file_size = blk_getlength(blkdev->blk);
+    dataplane->xendev = xendev;
+    dataplane->file_blk = conf->logical_block_size;
+    dataplane->blk = conf->blk;
+    dataplane->file_size = blk_getlength(dataplane->blk);
 
-    QLIST_INIT(&blkdev->inflight);
-    QLIST_INIT(&blkdev->finished);
-    QLIST_INIT(&blkdev->freelist);
+    QLIST_INIT(&dataplane->inflight);
+    QLIST_INIT(&dataplane->finished);
+    QLIST_INIT(&dataplane->freelist);
 
     if (iothread) {
-        blkdev->iothread = iothread;
-        object_ref(OBJECT(blkdev->iothread));
-        blkdev->ctx = iothread_get_aio_context(blkdev->iothread);
+        dataplane->iothread = iothread;
+        object_ref(OBJECT(dataplane->iothread));
+        dataplane->ctx = iothread_get_aio_context(dataplane->iothread);
     } else {
-        blkdev->ctx = qemu_get_aio_context();
+        dataplane->ctx = qemu_get_aio_context();
     }
-    blkdev->bh = aio_bh_new(blkdev->ctx, blk_bh, blkdev);
+    dataplane->bh = aio_bh_new(dataplane->ctx, blk_bh, dataplane);
 
-    return blkdev;
+    return dataplane;
 }
 
-void xen_block_dataplane_destroy(struct XenBlkDev *blkdev)
+void xen_block_dataplane_destroy(XenBlockDataPlane *dataplane)
 {
     struct ioreq *ioreq;
 
-    if (!blkdev) {
+    if (!dataplane) {
         return;
     }
 
-    while (!QLIST_EMPTY(&blkdev->freelist)) {
-        ioreq = QLIST_FIRST(&blkdev->freelist);
+    while (!QLIST_EMPTY(&dataplane->freelist)) {
+        ioreq = QLIST_FIRST(&dataplane->freelist);
         QLIST_REMOVE(ioreq, list);
         qemu_iovec_destroy(&ioreq->v);
         g_free(ioreq);
     }
 
-    qemu_bh_delete(blkdev->bh);
-    if (blkdev->iothread) {
-        object_unref(OBJECT(blkdev->iothread));
+    qemu_bh_delete(dataplane->bh);
+    if (dataplane->iothread) {
+        object_unref(OBJECT(dataplane->iothread));
     }
 
-    g_free(blkdev);
+    g_free(dataplane);
 }
 
-
-void xen_block_dataplane_stop(struct XenBlkDev *blkdev)
+void xen_block_dataplane_stop(XenBlockDataPlane *dataplane)
 {
     XenDevice *xendev;
 
-    if (!blkdev) {
+    if (!dataplane) {
         return;
     }
 
-    aio_context_acquire(blkdev->ctx);
-    blk_set_aio_context(blkdev->blk, qemu_get_aio_context());
-    aio_context_release(blkdev->ctx);
+    aio_context_acquire(dataplane->ctx);
+    blk_set_aio_context(dataplane->blk, qemu_get_aio_context());
+    aio_context_release(dataplane->ctx);
 
-    xendev = blkdev->xendev;
+    xendev = dataplane->xendev;
 
-    if (blkdev->event_channel) {
+    if (dataplane->event_channel) {
         Error *local_err = NULL;
 
-        xen_device_unbind_event_channel(xendev, blkdev->event_channel,
+        xen_device_unbind_event_channel(xendev, dataplane->event_channel,
                                         &local_err);
-        blkdev->event_channel = NULL;
+        dataplane->event_channel = NULL;
 
         if (local_err) {
             error_report_err(local_err);
         }
     }
 
-    if (blkdev->sring) {
+    if (dataplane->sring) {
         Error *local_err = NULL;
 
-        xen_device_unmap_grant_refs(xendev, blkdev->sring,
-                                    blkdev->nr_ring_ref, &local_err);
-        blkdev->sring = NULL;
+        xen_device_unmap_grant_refs(xendev, dataplane->sring,
+                                    dataplane->nr_ring_ref, &local_err);
+        dataplane->sring = NULL;
 
         if (local_err) {
             error_report_err(local_err);
         }
     }
 
-    g_free(blkdev->ring_ref);
-    blkdev->ring_ref = NULL;
+    g_free(dataplane->ring_ref);
+    dataplane->ring_ref = NULL;
 }
 
-void xen_block_dataplane_start(struct XenBlkDev *blkdev,
+void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
                                const unsigned int ring_ref[],
                                unsigned int nr_ring_ref,
                                unsigned int event_channel,
                                unsigned int protocol,
                                Error **errp)
 {
-    XenDevice *xendev = blkdev->xendev;
+    XenDevice *xendev = dataplane->xendev;
     Error *local_err = NULL;
     unsigned int ring_size;
     unsigned int i;
 
-    blkdev->nr_ring_ref = nr_ring_ref;
-    blkdev->ring_ref = g_new(unsigned int, nr_ring_ref);
+    dataplane->nr_ring_ref = nr_ring_ref;
+    dataplane->ring_ref = g_new(unsigned int, nr_ring_ref);
 
     for (i = 0; i < nr_ring_ref; i++) {
-        blkdev->ring_ref[i] = ring_ref[i];
+        dataplane->ring_ref[i] = ring_ref[i];
     }
 
-    blkdev->protocol = protocol;
+    dataplane->protocol = protocol;
 
-    ring_size = XC_PAGE_SIZE * blkdev->nr_ring_ref;
-    switch (blkdev->protocol) {
+    ring_size = XC_PAGE_SIZE * dataplane->nr_ring_ref;
+    switch (dataplane->protocol) {
     case BLKIF_PROTOCOL_NATIVE:
     {
-        blkdev->max_requests = __CONST_RING_SIZE(blkif, ring_size);
+        dataplane->max_requests = __CONST_RING_SIZE(blkif, ring_size);
         break;
     }
     case BLKIF_PROTOCOL_X86_32:
     {
-        blkdev->max_requests = __CONST_RING_SIZE(blkif_x86_32, ring_size);
+        dataplane->max_requests = __CONST_RING_SIZE(blkif_x86_32, ring_size);
         break;
     }
     case BLKIF_PROTOCOL_X86_64:
     {
-        blkdev->max_requests = __CONST_RING_SIZE(blkif_x86_64, ring_size);
+        dataplane->max_requests = __CONST_RING_SIZE(blkif_x86_64, ring_size);
         break;
     }
     default:
-        error_setg(errp, "unknown protocol %u", blkdev->protocol);
+        error_setg(errp, "unknown protocol %u", dataplane->protocol);
         return;
     }
 
-    xen_device_set_max_grant_refs(xendev, blkdev->nr_ring_ref,
+    xen_device_set_max_grant_refs(xendev, dataplane->nr_ring_ref,
                                   &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         goto stop;
     }
 
-    blkdev->sring = xen_device_map_grant_refs(xendev,
-                                              blkdev->ring_ref,
-                                              blkdev->nr_ring_ref,
+    dataplane->sring = xen_device_map_grant_refs(xendev,
+                                              dataplane->ring_ref,
+                                              dataplane->nr_ring_ref,
                                               PROT_READ | PROT_WRITE,
                                               &local_err);
     if (local_err) {
@@ -753,46 +765,46 @@ void xen_block_dataplane_start(struct XenBlkDev *blkdev,
         goto stop;
     }
 
-    switch (blkdev->protocol) {
+    switch (dataplane->protocol) {
     case BLKIF_PROTOCOL_NATIVE:
     {
-        blkif_sring_t *sring_native = blkdev->sring;
+        blkif_sring_t *sring_native = dataplane->sring;
 
-        BACK_RING_INIT(&blkdev->rings.native, sring_native, ring_size);
+        BACK_RING_INIT(&dataplane->rings.native, sring_native, ring_size);
         break;
     }
     case BLKIF_PROTOCOL_X86_32:
     {
-        blkif_x86_32_sring_t *sring_x86_32 = blkdev->sring;
+        blkif_x86_32_sring_t *sring_x86_32 = dataplane->sring;
 
-        BACK_RING_INIT(&blkdev->rings.x86_32_part, sring_x86_32,
+        BACK_RING_INIT(&dataplane->rings.x86_32_part, sring_x86_32,
                        ring_size);
         break;
     }
     case BLKIF_PROTOCOL_X86_64:
     {
-        blkif_x86_64_sring_t *sring_x86_64 = blkdev->sring;
+        blkif_x86_64_sring_t *sring_x86_64 = dataplane->sring;
 
-        BACK_RING_INIT(&blkdev->rings.x86_64_part, sring_x86_64,
+        BACK_RING_INIT(&dataplane->rings.x86_64_part, sring_x86_64,
                        ring_size);
         break;
     }
     }
 
-    blkdev->event_channel =
+    dataplane->event_channel =
         xen_device_bind_event_channel(xendev, event_channel,
-                                      blk_event, blkdev,
+                                      blk_event, dataplane,
                                       &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         goto stop;
     }
 
-    aio_context_acquire(blkdev->ctx);
-    blk_set_aio_context(blkdev->blk, blkdev->ctx);
-    aio_context_release(blkdev->ctx);
+    aio_context_acquire(dataplane->ctx);
+    blk_set_aio_context(dataplane->blk, dataplane->ctx);
+    aio_context_release(dataplane->ctx);
     return;
 
 stop:
-    xen_block_dataplane_stop(blkdev);
+    xen_block_dataplane_stop(dataplane);
 }
hw/block/dataplane/xen-block.h +1 -1
index f31da38..d6fa6d2 100644
@@ -12,7 +12,7 @@
 #include "hw/xen/xen-bus.h"
 #include "sysemu/iothread.h"
 
-typedef struct XenBlkDev XenBlockDataPlane;
+typedef struct XenBlockDataPlane XenBlockDataPlane;
 
 XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
                                               BlockConf *conf,
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#36 lore raw

PATCH v2 12/18 xen: remove 'ioreq' struct/varable/field names from dataplane/xen-block.c

In reply to Paul Durrant

This is a purely cosmetic patch that purges the name 'ioreq' from struct, variable and field names. (This name has been problematic for a long time as 'ioreq' is the name used for generic I/O requests coming from Xen). The patch replaces 'struct ioreq' with a new 'XenBlockRequest' type and 'ioreq' field/variable names with 'request', and then does necessary fix-up to adhere to coding style.

Function names are not modified by this patch. They will be dealt with in a subsequent patch.

No functional change.

---
Cc: Stefan Hajnoczi <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

---
 hw/block/dataplane/xen-block.c | 310 +++++++++++++++++++++--------------------
 1 file changed, 156 insertions(+), 154 deletions(-)
hw/block/dataplane/xen-block.c +156 -154
index 6ecd160..426e83c 100644
@@ -34,7 +34,7 @@
 #include "sysemu/iothread.h"
 #include "xen-block.h"
 
-struct ioreq {
+typedef struct XenBlockRequest {
     blkif_request_t req;
     int16_t status;
     off_t start;
@@ -45,9 +45,9 @@ struct ioreq {
     int aio_inflight;
     int aio_errors;
     XenBlockDataPlane *dataplane;
-    QLIST_ENTRY(ioreq) list;
+    QLIST_ENTRY(XenBlockRequest) list;
     BlockAcctCookie acct;
-};
+} XenBlockRequest;
 
 struct XenBlockDataPlane {
     XenDevice *xendev;
@@ -60,9 +60,9 @@ struct XenBlockDataPlane {
     int protocol;
     blkif_back_rings_t rings;
     int more_work;
-    QLIST_HEAD(inflight_head, ioreq) inflight;
-    QLIST_HEAD(finished_head, ioreq) finished;
-    QLIST_HEAD(freelist_head, ioreq) freelist;
+    QLIST_HEAD(inflight_head, XenBlockRequest) inflight;
+    QLIST_HEAD(finished_head, XenBlockRequest) finished;
+    QLIST_HEAD(freelist_head, XenBlockRequest) freelist;
     int requests_total;
     int requests_inflight;
     int requests_finished;
@@ -73,68 +73,68 @@ struct XenBlockDataPlane {
     AioContext *ctx;
 };
 
-static void ioreq_reset(struct ioreq *ioreq)
+static void ioreq_reset(XenBlockRequest *request)
 {
-    memset(&ioreq->req, 0, sizeof(ioreq->req));
-    ioreq->status = 0;
-    ioreq->start = 0;
-    ioreq->buf = NULL;
-    ioreq->size = 0;
-    ioreq->presync = 0;
+    memset(&request->req, 0, sizeof(request->req));
+    request->status = 0;
+    request->start = 0;
+    request->buf = NULL;
+    request->size = 0;
+    request->presync = 0;
 
-    ioreq->aio_inflight = 0;
-    ioreq->aio_errors = 0;
+    request->aio_inflight = 0;
+    request->aio_errors = 0;
 
-    ioreq->dataplane = NULL;
-    memset(&ioreq->list, 0, sizeof(ioreq->list));
-    memset(&ioreq->acct, 0, sizeof(ioreq->acct));
+    request->dataplane = NULL;
+    memset(&request->list, 0, sizeof(request->list));
+    memset(&request->acct, 0, sizeof(request->acct));
 
-    qemu_iovec_reset(&ioreq->v);
+    qemu_iovec_reset(&request->v);
 }
 
-static struct ioreq *ioreq_start(XenBlockDataPlane *dataplane)
+static XenBlockRequest *ioreq_start(XenBlockDataPlane *dataplane)
 {
-    struct ioreq *ioreq = NULL;
+    XenBlockRequest *request = NULL;
 
     if (QLIST_EMPTY(&dataplane->freelist)) {
         if (dataplane->requests_total >= dataplane->max_requests) {
             goto out;
         }
         /* allocate new struct */
-        ioreq = g_malloc0(sizeof(*ioreq));
-        ioreq->dataplane = dataplane;
+        request = g_malloc0(sizeof(*request));
+        request->dataplane = dataplane;
         dataplane->requests_total++;
-        qemu_iovec_init(&ioreq->v, 1);
+        qemu_iovec_init(&request->v, 1);
     } else {
         /* get one from freelist */
-        ioreq = QLIST_FIRST(&dataplane->freelist);
-        QLIST_REMOVE(ioreq, list);
+        request = QLIST_FIRST(&dataplane->freelist);
+        QLIST_REMOVE(request, list);
     }
-    QLIST_INSERT_HEAD(&dataplane->inflight, ioreq, list);
+    QLIST_INSERT_HEAD(&dataplane->inflight, request, list);
     dataplane->requests_inflight++;
 
 out:
-    return ioreq;
+    return request;
 }
 
-static void ioreq_finish(struct ioreq *ioreq)
+static void ioreq_finish(XenBlockRequest *request)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockDataPlane *dataplane = request->dataplane;
 
-    QLIST_REMOVE(ioreq, list);
-    QLIST_INSERT_HEAD(&dataplane->finished, ioreq, list);
+    QLIST_REMOVE(request, list);
+    QLIST_INSERT_HEAD(&dataplane->finished, request, list);
     dataplane->requests_inflight--;
     dataplane->requests_finished++;
 }
 
-static void ioreq_release(struct ioreq *ioreq, bool finish)
+static void ioreq_release(XenBlockRequest *request, bool finish)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockDataPlane *dataplane = request->dataplane;
 
-    QLIST_REMOVE(ioreq, list);
-    ioreq_reset(ioreq);
-    ioreq->dataplane = dataplane;
-    QLIST_INSERT_HEAD(&dataplane->freelist, ioreq, list);
+    QLIST_REMOVE(request, list);
+    ioreq_reset(request);
+    request->dataplane = dataplane;
+    QLIST_INSERT_HEAD(&dataplane->freelist, request, list);
     if (finish) {
         dataplane->requests_finished--;
     } else {
@@ -146,18 +146,18 @@ static void ioreq_release(struct ioreq *ioreq, bool finish)
  * translate request into iovec + start offset
  * do sanity checks along the way
  */
-static int ioreq_parse(struct ioreq *ioreq)
+static int ioreq_parse(XenBlockRequest *request)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockDataPlane *dataplane = request->dataplane;
     size_t len;
     int i;
 
-    switch (ioreq->req.operation) {
+    switch (request->req.operation) {
     case BLKIF_OP_READ:
         break;
     case BLKIF_OP_FLUSH_DISKCACHE:
-        ioreq->presync = 1;
-        if (!ioreq->req.nr_segments) {
+        request->presync = 1;
+        if (!request->req.nr_segments) {
             return 0;
         }
         /* fall through */
@@ -166,77 +166,78 @@ static int ioreq_parse(struct ioreq *ioreq)
     case BLKIF_OP_DISCARD:
         return 0;
     default:
-        error_report("error: unknown operation (%d)", ioreq->req.operation);
+        error_report("error: unknown operation (%d)", request->req.operation);
         goto err;
     };
 
-    if (ioreq->req.operation != BLKIF_OP_READ &&
+    if (request->req.operation != BLKIF_OP_READ &&
         blk_is_read_only(dataplane->blk)) {
         error_report("error: write req for ro device");
         goto err;
     }
 
-    ioreq->start = ioreq->req.sector_number * dataplane->file_blk;
-    for (i = 0; i < ioreq->req.nr_segments; i++) {
+    request->start = request->req.sector_number * dataplane->file_blk;
+    for (i = 0; i < request->req.nr_segments; i++) {
         if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
             error_report("error: nr_segments too big");
             goto err;
         }
-        if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) {
+        if (request->req.seg[i].first_sect > request->req.seg[i].last_sect) {
             error_report("error: first > last sector");
             goto err;
         }
-        if (ioreq->req.seg[i].last_sect * dataplane->file_blk >= XC_PAGE_SIZE) {
+        if (request->req.seg[i].last_sect * dataplane->file_blk >=
+            XC_PAGE_SIZE) {
             error_report("error: page crossing");
             goto err;
         }
 
-        len = (ioreq->req.seg[i].last_sect -
-               ioreq->req.seg[i].first_sect + 1) * dataplane->file_blk;
-        ioreq->size += len;
+        len = (request->req.seg[i].last_sect -
+               request->req.seg[i].first_sect + 1) * dataplane->file_blk;
+        request->size += len;
     }
-    if (ioreq->start + ioreq->size > dataplane->file_size) {
+    if (request->start + request->size > dataplane->file_size) {
         error_report("error: access beyond end of file");
         goto err;
     }
     return 0;
 
 err:
-    ioreq->status = BLKIF_RSP_ERROR;
+    request->status = BLKIF_RSP_ERROR;
     return -1;
 }
 
-static int ioreq_grant_copy(struct ioreq *ioreq)
+static int ioreq_grant_copy(XenBlockRequest *request)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockDataPlane *dataplane = request->dataplane;
     XenDevice *xendev = dataplane->xendev;
     XenDeviceGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     int i, count;
     int64_t file_blk = dataplane->file_blk;
-    bool to_domain = (ioreq->req.operation == BLKIF_OP_READ);
-    void *virt = ioreq->buf;
+    bool to_domain = (request->req.operation == BLKIF_OP_READ);
+    void *virt = request->buf;
     Error *local_err = NULL;
 
-    if (ioreq->req.nr_segments == 0) {
+    if (request->req.nr_segments == 0) {
         return 0;
     }
 
-    count = ioreq->req.nr_segments;
+    count = request->req.nr_segments;
 
     for (i = 0; i < count; i++) {
         if (to_domain) {
-            segs[i].dest.foreign.ref = ioreq->req.seg[i].gref;
-            segs[i].dest.foreign.offset = ioreq->req.seg[i].first_sect *
+            segs[i].dest.foreign.ref = request->req.seg[i].gref;
+            segs[i].dest.foreign.offset = request->req.seg[i].first_sect *
                 file_blk;
             segs[i].source.virt = virt;
         } else {
-            segs[i].source.foreign.ref = ioreq->req.seg[i].gref;
-            segs[i].source.foreign.offset = ioreq->req.seg[i].first_sect *
+            segs[i].source.foreign.ref = request->req.seg[i].gref;
+            segs[i].source.foreign.offset = request->req.seg[i].first_sect *
                 file_blk;
             segs[i].dest.virt = virt;
         }
-        segs[i].len = (ioreq->req.seg[i].last_sect -
-                       ioreq->req.seg[i].first_sect + 1) * file_blk;
+        segs[i].len = (request->req.seg[i].last_sect -
+                       request->req.seg[i].first_sect + 1) * file_blk;
         virt += segs[i].len;
     }
 
@@ -245,72 +246,72 @@ static int ioreq_grant_copy(struct ioreq *ioreq)
     if (local_err) {
         error_reportf_err(local_err, "failed to copy data: ");
 
-        ioreq->aio_errors++;
+        request->aio_errors++;
         return -1;
     }
 
     return 0;
 }
 
-static int ioreq_runio_qemu_aio(struct ioreq *ioreq);
+static int ioreq_runio_qemu_aio(XenBlockRequest *request);
 
 static void qemu_aio_complete(void *opaque, int ret)
 {
-    struct ioreq *ioreq = opaque;
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockRequest *request = opaque;
+    XenBlockDataPlane *dataplane = request->dataplane;
 
     aio_context_acquire(dataplane->ctx);
 
     if (ret != 0) {
         error_report("%s I/O error",
-                     ioreq->req.operation == BLKIF_OP_READ ?
+                     request->req.operation == BLKIF_OP_READ ?
                      "read" : "write");
-        ioreq->aio_errors++;
+        request->aio_errors++;
     }
 
-    ioreq->aio_inflight--;
-    if (ioreq->presync) {
-        ioreq->presync = 0;
-        ioreq_runio_qemu_aio(ioreq);
+    request->aio_inflight--;
+    if (request->presync) {
+        request->presync = 0;
+        ioreq_runio_qemu_aio(request);
         goto done;
     }
-    if (ioreq->aio_inflight > 0) {
+    if (request->aio_inflight > 0) {
         goto done;
     }
 
-    switch (ioreq->req.operation) {
+    switch (request->req.operation) {
     case BLKIF_OP_READ:
-        /* in case of failure ioreq->aio_errors is increased */
+        /* in case of failure request->aio_errors is increased */
         if (ret == 0) {
-            ioreq_grant_copy(ioreq);
+            ioreq_grant_copy(request);
         }
-        qemu_vfree(ioreq->buf);
+        qemu_vfree(request->buf);
         break;
     case BLKIF_OP_WRITE:
     case BLKIF_OP_FLUSH_DISKCACHE:
-        if (!ioreq->req.nr_segments) {
+        if (!request->req.nr_segments) {
             break;
         }
-        qemu_vfree(ioreq->buf);
+        qemu_vfree(request->buf);
         break;
     default:
         break;
     }
 
-    ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
-    ioreq_finish(ioreq);
+    request->status = request->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
+    ioreq_finish(request);
 
-    switch (ioreq->req.operation) {
+    switch (request->req.operation) {
     case BLKIF_OP_WRITE:
     case BLKIF_OP_FLUSH_DISKCACHE:
-        if (!ioreq->req.nr_segments) {
+        if (!request->req.nr_segments) {
             break;
         }
     case BLKIF_OP_READ:
-        if (ioreq->status == BLKIF_RSP_OKAY) {
-            block_acct_done(blk_get_stats(dataplane->blk), &ioreq->acct);
+        if (request->status == BLKIF_RSP_OKAY) {
+            block_acct_done(blk_get_stats(dataplane->blk), &request->acct);
         } else {
-            block_acct_failed(blk_get_stats(dataplane->blk), &ioreq->acct);
+            block_acct_failed(blk_get_stats(dataplane->blk), &request->acct);
         }
         break;
     case BLKIF_OP_DISCARD:
@@ -323,10 +324,11 @@ done:
     aio_context_release(dataplane->ctx);
 }
 
-static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number,
+static bool blk_split_discard(XenBlockRequest *request,
+                              blkif_sector_t sector_number,
                               uint64_t nr_sectors)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockDataPlane *dataplane = request->dataplane;
     int64_t byte_offset;
     int byte_chunk;
     uint64_t byte_remaining, limit;
@@ -345,9 +347,9 @@ static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number,
 
     do {
         byte_chunk = byte_remaining > limit ? limit : byte_remaining;
-        ioreq->aio_inflight++;
+        request->aio_inflight++;
         blk_aio_pdiscard(dataplane->blk, byte_offset, byte_chunk,
-                         qemu_aio_complete, ioreq);
+                         qemu_aio_complete, request);
         byte_remaining -= byte_chunk;
         byte_offset += byte_chunk;
     } while (byte_remaining > 0);
@@ -355,53 +357,53 @@ static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number,
     return true;
 }
 
-static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
+static int ioreq_runio_qemu_aio(XenBlockRequest *request)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
-
-    ioreq->buf = qemu_memalign(XC_PAGE_SIZE, ioreq->size);
-    if (ioreq->req.nr_segments &&
-        (ioreq->req.operation == BLKIF_OP_WRITE ||
-         ioreq->req.operation == BLKIF_OP_FLUSH_DISKCACHE) &&
-        ioreq_grant_copy(ioreq)) {
-        qemu_vfree(ioreq->buf);
+    XenBlockDataPlane *dataplane = request->dataplane;
+
+    request->buf = qemu_memalign(XC_PAGE_SIZE, request->size);
+    if (request->req.nr_segments &&
+        (request->req.operation == BLKIF_OP_WRITE ||
+         request->req.operation == BLKIF_OP_FLUSH_DISKCACHE) &&
+        ioreq_grant_copy(request)) {
+        qemu_vfree(request->buf);
         goto err;
     }
 
-    ioreq->aio_inflight++;
-    if (ioreq->presync) {
-        blk_aio_flush(ioreq->dataplane->blk, qemu_aio_complete, ioreq);
+    request->aio_inflight++;
+    if (request->presync) {
+        blk_aio_flush(request->dataplane->blk, qemu_aio_complete, request);
         return 0;
     }
 
-    switch (ioreq->req.operation) {
+    switch (request->req.operation) {
     case BLKIF_OP_READ:
-        qemu_iovec_add(&ioreq->v, ioreq->buf, ioreq->size);
-        block_acct_start(blk_get_stats(dataplane->blk), &ioreq->acct,
-                         ioreq->v.size, BLOCK_ACCT_READ);
-        ioreq->aio_inflight++;
-        blk_aio_preadv(dataplane->blk, ioreq->start, &ioreq->v, 0,
-                       qemu_aio_complete, ioreq);
+        qemu_iovec_add(&request->v, request->buf, request->size);
+        block_acct_start(blk_get_stats(dataplane->blk), &request->acct,
+                         request->v.size, BLOCK_ACCT_READ);
+        request->aio_inflight++;
+        blk_aio_preadv(dataplane->blk, request->start, &request->v, 0,
+                       qemu_aio_complete, request);
         break;
     case BLKIF_OP_WRITE:
     case BLKIF_OP_FLUSH_DISKCACHE:
-        if (!ioreq->req.nr_segments) {
+        if (!request->req.nr_segments) {
             break;
         }
 
-        qemu_iovec_add(&ioreq->v, ioreq->buf, ioreq->size);
-        block_acct_start(blk_get_stats(dataplane->blk), &ioreq->acct,
-                         ioreq->v.size,
-                         ioreq->req.operation == BLKIF_OP_WRITE ?
+        qemu_iovec_add(&request->v, request->buf, request->size);
+        block_acct_start(blk_get_stats(dataplane->blk), &request->acct,
+                         request->v.size,
+                         request->req.operation == BLKIF_OP_WRITE ?
                          BLOCK_ACCT_WRITE : BLOCK_ACCT_FLUSH);
-        ioreq->aio_inflight++;
-        blk_aio_pwritev(dataplane->blk, ioreq->start, &ioreq->v, 0,
-                        qemu_aio_complete, ioreq);
+        request->aio_inflight++;
+        blk_aio_pwritev(dataplane->blk, request->start, &request->v, 0,
+                        qemu_aio_complete, request);
         break;
     case BLKIF_OP_DISCARD:
     {
-        struct blkif_request_discard *req = (void *)&ioreq->req;
-        if (!blk_split_discard(ioreq, req->sector_number, req->nr_sectors)) {
+        struct blkif_request_discard *req = (void *)&request->req;
+        if (!blk_split_discard(request, req->sector_number, req->nr_sectors)) {
             goto err;
         }
         break;
@@ -411,19 +413,19 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
         goto err;
     }
 
-    qemu_aio_complete(ioreq, 0);
+    qemu_aio_complete(request, 0);
 
     return 0;
 
 err:
-    ioreq_finish(ioreq);
-    ioreq->status = BLKIF_RSP_ERROR;
+    ioreq_finish(request);
+    request->status = BLKIF_RSP_ERROR;
     return -1;
 }
 
-static int blk_send_response_one(struct ioreq *ioreq)
+static int blk_send_response_one(XenBlockRequest *request)
 {
-    XenBlockDataPlane *dataplane = ioreq->dataplane;
+    XenBlockDataPlane *dataplane = request->dataplane;
     int send_notify = 0;
     int have_requests = 0;
     blkif_response_t *resp;
@@ -449,9 +451,9 @@ static int blk_send_response_one(struct ioreq *ioreq)
         return 0;
     }
 
-    resp->id = ioreq->req.id;
-    resp->operation = ioreq->req.operation;
-    resp->status = ioreq->status;
+    resp->id = request->req.id;
+    resp->operation = request->req.operation;
+    resp->status = request->status;
 
     dataplane->rings.common.rsp_prod_pvt++;
 
@@ -479,13 +481,13 @@ static int blk_send_response_one(struct ioreq *ioreq)
 /* walk finished list, send outstanding responses, free requests */
 static void blk_send_response_all(XenBlockDataPlane *dataplane)
 {
-    struct ioreq *ioreq;
+    XenBlockRequest *request;
     int send_notify = 0;
 
     while (!QLIST_EMPTY(&dataplane->finished)) {
-        ioreq = QLIST_FIRST(&dataplane->finished);
-        send_notify += blk_send_response_one(ioreq);
-        ioreq_release(ioreq, true);
+        request = QLIST_FIRST(&dataplane->finished);
+        send_notify += blk_send_response_one(request);
+        ioreq_release(request, true);
     }
     if (send_notify) {
         Error *local_err = NULL;
@@ -499,29 +501,29 @@ static void blk_send_response_all(XenBlockDataPlane *dataplane)
     }
 }
 
-static int blk_get_request(XenBlockDataPlane *dataplane, struct ioreq *ioreq,
-                           RING_IDX rc)
+static int blk_get_request(XenBlockDataPlane *dataplane,
+                           XenBlockRequest *request, RING_IDX rc)
 {
     switch (dataplane->protocol) {
     case BLKIF_PROTOCOL_NATIVE: {
         blkif_request_t *req =
             RING_GET_REQUEST(&dataplane->rings.native, rc);
 
-        memcpy(&ioreq->req, req, sizeof(ioreq->req));
+        memcpy(&request->req, req, sizeof(request->req));
         break;
     }
     case BLKIF_PROTOCOL_X86_32: {
         blkif_x86_32_request_t *req =
             RING_GET_REQUEST(&dataplane->rings.x86_32_part, rc);
 
-        blkif_get_x86_32_req(&ioreq->req, req);
+        blkif_get_x86_32_req(&request->req, req);
         break;
     }
     case BLKIF_PROTOCOL_X86_64: {
         blkif_x86_64_request_t *req =
             RING_GET_REQUEST(&dataplane->rings.x86_64_part, rc);
 
-        blkif_get_x86_64_req(&ioreq->req, req);
+        blkif_get_x86_64_req(&request->req, req);
         break;
     }
     }
@@ -533,7 +535,7 @@ static int blk_get_request(XenBlockDataPlane *dataplane, struct ioreq *ioreq,
 static void blk_handle_requests(XenBlockDataPlane *dataplane)
 {
     RING_IDX rc, rp;
-    struct ioreq *ioreq;
+    XenBlockRequest *request;
 
     dataplane->more_work = 0;
 
@@ -547,18 +549,18 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
         if (RING_REQUEST_CONS_OVERFLOW(&dataplane->rings.common, rc)) {
             break;
         }
-        ioreq = ioreq_start(dataplane);
-        if (ioreq == NULL) {
+        request = ioreq_start(dataplane);
+        if (request == NULL) {
             dataplane->more_work++;
             break;
         }
-        blk_get_request(dataplane, ioreq, rc);
+        blk_get_request(dataplane, request, rc);
         dataplane->rings.common.req_cons = ++rc;
 
         /* parse them */
-        if (ioreq_parse(ioreq) != 0) {
+        if (ioreq_parse(request) != 0) {
 
-            switch (ioreq->req.operation) {
+            switch (request->req.operation) {
             case BLKIF_OP_READ:
                 block_acct_invalid(blk_get_stats(dataplane->blk),
                                    BLOCK_ACCT_READ);
@@ -574,7 +576,7 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
                 break;
             };
 
-            if (blk_send_response_one(ioreq)) {
+            if (blk_send_response_one(request)) {
                 Error *local_err = NULL;
 
                 xen_device_notify_event_channel(dataplane->xendev,
@@ -584,11 +586,11 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
                     error_report_err(local_err);
                 }
             }
-            ioreq_release(ioreq, false);
+            ioreq_release(request, false);
             continue;
         }
 
-        ioreq_runio_qemu_aio(ioreq);
+        ioreq_runio_qemu_aio(request);
     }
 
     if (dataplane->more_work &&
@@ -642,17 +644,17 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
 
 void xen_block_dataplane_destroy(XenBlockDataPlane *dataplane)
 {
-    struct ioreq *ioreq;
+    XenBlockRequest *request;
 
     if (!dataplane) {
         return;
     }
 
     while (!QLIST_EMPTY(&dataplane->freelist)) {
-        ioreq = QLIST_FIRST(&dataplane->freelist);
-        QLIST_REMOVE(ioreq, list);
-        qemu_iovec_destroy(&ioreq->v);
-        g_free(ioreq);
+        request = QLIST_FIRST(&dataplane->freelist);
+        QLIST_REMOVE(request, list);
+        qemu_iovec_destroy(&request->v);
+        g_free(request);
     }
 
     qemu_bh_delete(dataplane->bh);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#37 lore raw

PATCH v2 13/18 xen: purge 'blk' and 'ioreq' from function names in dataplane/xen-block.c

In reply to Paul Durrant

This is a purely cosmetic patch that purges remaining use of 'blk' and 'ioreq' in local function names, and then makes sure all functions are prefixed with 'xen_block_'.

No functional change.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

v2:
- Add 'xen_block_' prefix

---
 hw/block/dataplane/xen-block.c | 90 +++++++++++++++++++++---------------------
 1 file changed, 46 insertions(+), 44 deletions(-)
hw/block/dataplane/xen-block.c +46 -44
index 426e83c..8c451ae 100644
@@ -73,7 +73,7 @@ struct XenBlockDataPlane {
     AioContext *ctx;
 };
 
-static void ioreq_reset(XenBlockRequest *request)
+static void reset_request(XenBlockRequest *request)
 {
     memset(&request->req, 0, sizeof(request->req));
     request->status = 0;
@@ -92,7 +92,7 @@ static void ioreq_reset(XenBlockRequest *request)
     qemu_iovec_reset(&request->v);
 }
 
-static XenBlockRequest *ioreq_start(XenBlockDataPlane *dataplane)
+static XenBlockRequest *xen_block_start_request(XenBlockDataPlane *dataplane)
 {
     XenBlockRequest *request = NULL;
 
@@ -117,7 +117,7 @@ out:
     return request;
 }
 
-static void ioreq_finish(XenBlockRequest *request)
+static void xen_block_finish_request(XenBlockRequest *request)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
 
@@ -127,12 +127,12 @@ static void ioreq_finish(XenBlockRequest *request)
     dataplane->requests_finished++;
 }
 
-static void ioreq_release(XenBlockRequest *request, bool finish)
+static void xen_block_release_request(XenBlockRequest *request, bool finish)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
 
     QLIST_REMOVE(request, list);
-    ioreq_reset(request);
+    reset_request(request);
     request->dataplane = dataplane;
     QLIST_INSERT_HEAD(&dataplane->freelist, request, list);
     if (finish) {
@@ -146,7 +146,7 @@ static void ioreq_release(XenBlockRequest *request, bool finish)
  * translate request into iovec + start offset
  * do sanity checks along the way
  */
-static int ioreq_parse(XenBlockRequest *request)
+static int xen_block_parse_request(XenBlockRequest *request)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
     size_t len;
@@ -207,7 +207,7 @@ err:
     return -1;
 }
 
-static int ioreq_grant_copy(XenBlockRequest *request)
+static int xen_block_copy_request(XenBlockRequest *request)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
     XenDevice *xendev = dataplane->xendev;
@@ -253,9 +253,9 @@ static int ioreq_grant_copy(XenBlockRequest *request)
     return 0;
 }
 
-static int ioreq_runio_qemu_aio(XenBlockRequest *request);
+static int xen_block_do_aio(XenBlockRequest *request);
 
-static void qemu_aio_complete(void *opaque, int ret)
+static void xen_block_complete_aio(void *opaque, int ret)
 {
     XenBlockRequest *request = opaque;
     XenBlockDataPlane *dataplane = request->dataplane;
@@ -272,7 +272,7 @@ static void qemu_aio_complete(void *opaque, int ret)
     request->aio_inflight--;
     if (request->presync) {
         request->presync = 0;
-        ioreq_runio_qemu_aio(request);
+        xen_block_do_aio(request);
         goto done;
     }
     if (request->aio_inflight > 0) {
@@ -283,7 +283,7 @@ static void qemu_aio_complete(void *opaque, int ret)
     case BLKIF_OP_READ:
         /* in case of failure request->aio_errors is increased */
         if (ret == 0) {
-            ioreq_grant_copy(request);
+            xen_block_copy_request(request);
         }
         qemu_vfree(request->buf);
         break;
@@ -299,7 +299,7 @@ static void qemu_aio_complete(void *opaque, int ret)
     }
 
     request->status = request->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
-    ioreq_finish(request);
+    xen_block_finish_request(request);
 
     switch (request->req.operation) {
     case BLKIF_OP_WRITE:
@@ -324,9 +324,9 @@ done:
     aio_context_release(dataplane->ctx);
 }
 
-static bool blk_split_discard(XenBlockRequest *request,
-                              blkif_sector_t sector_number,
-                              uint64_t nr_sectors)
+static bool xen_block_split_discard(XenBlockRequest *request,
+                                    blkif_sector_t sector_number,
+                                    uint64_t nr_sectors)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
     int64_t byte_offset;
@@ -349,7 +349,7 @@ static bool blk_split_discard(XenBlockRequest *request,
         byte_chunk = byte_remaining > limit ? limit : byte_remaining;
         request->aio_inflight++;
         blk_aio_pdiscard(dataplane->blk, byte_offset, byte_chunk,
-                         qemu_aio_complete, request);
+                         xen_block_complete_aio, request);
         byte_remaining -= byte_chunk;
         byte_offset += byte_chunk;
     } while (byte_remaining > 0);
@@ -357,7 +357,7 @@ static bool blk_split_discard(XenBlockRequest *request,
     return true;
 }
 
-static int ioreq_runio_qemu_aio(XenBlockRequest *request)
+static int xen_block_do_aio(XenBlockRequest *request)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
 
@@ -365,14 +365,15 @@ static int ioreq_runio_qemu_aio(XenBlockRequest *request)
     if (request->req.nr_segments &&
         (request->req.operation == BLKIF_OP_WRITE ||
          request->req.operation == BLKIF_OP_FLUSH_DISKCACHE) &&
-        ioreq_grant_copy(request)) {
+        xen_block_copy_request(request)) {
         qemu_vfree(request->buf);
         goto err;
     }
 
     request->aio_inflight++;
     if (request->presync) {
-        blk_aio_flush(request->dataplane->blk, qemu_aio_complete, request);
+        blk_aio_flush(request->dataplane->blk, xen_block_complete_aio,
+                      request);
         return 0;
     }
 
@@ -383,7 +384,7 @@ static int ioreq_runio_qemu_aio(XenBlockRequest *request)
                          request->v.size, BLOCK_ACCT_READ);
         request->aio_inflight++;
         blk_aio_preadv(dataplane->blk, request->start, &request->v, 0,
-                       qemu_aio_complete, request);
+                       xen_block_complete_aio, request);
         break;
     case BLKIF_OP_WRITE:
     case BLKIF_OP_FLUSH_DISKCACHE:
@@ -398,12 +399,13 @@ static int ioreq_runio_qemu_aio(XenBlockRequest *request)
                          BLOCK_ACCT_WRITE : BLOCK_ACCT_FLUSH);
         request->aio_inflight++;
         blk_aio_pwritev(dataplane->blk, request->start, &request->v, 0,
-                        qemu_aio_complete, request);
+                        xen_block_complete_aio, request);
         break;
     case BLKIF_OP_DISCARD:
     {
         struct blkif_request_discard *req = (void *)&request->req;
-        if (!blk_split_discard(request, req->sector_number, req->nr_sectors)) {
+        if (!xen_block_split_discard(request, req->sector_number,
+                                     req->nr_sectors)) {
             goto err;
         }
         break;
@@ -413,17 +415,17 @@ static int ioreq_runio_qemu_aio(XenBlockRequest *request)
         goto err;
     }
 
-    qemu_aio_complete(request, 0);
+    xen_block_complete_aio(request, 0);
 
     return 0;
 
 err:
-    ioreq_finish(request);
+    xen_block_finish_request(request);
     request->status = BLKIF_RSP_ERROR;
     return -1;
 }
 
-static int blk_send_response_one(XenBlockRequest *request)
+static int xen_block_send_response_one(XenBlockRequest *request)
 {
     XenBlockDataPlane *dataplane = request->dataplane;
     int send_notify = 0;
@@ -479,15 +481,15 @@ static int blk_send_response_one(XenBlockRequest *request)
 }
 
 /* walk finished list, send outstanding responses, free requests */
-static void blk_send_response_all(XenBlockDataPlane *dataplane)
+static void xen_block_send_response_all(XenBlockDataPlane *dataplane)
 {
     XenBlockRequest *request;
     int send_notify = 0;
 
     while (!QLIST_EMPTY(&dataplane->finished)) {
         request = QLIST_FIRST(&dataplane->finished);
-        send_notify += blk_send_response_one(request);
-        ioreq_release(request, true);
+        send_notify += xen_block_send_response_one(request);
+        xen_block_release_request(request, true);
     }
     if (send_notify) {
         Error *local_err = NULL;
@@ -501,8 +503,8 @@ static void blk_send_response_all(XenBlockDataPlane *dataplane)
     }
 }
 
-static int blk_get_request(XenBlockDataPlane *dataplane,
-                           XenBlockRequest *request, RING_IDX rc)
+static int xen_block_get_request(XenBlockDataPlane *dataplane,
+                                 XenBlockRequest *request, RING_IDX rc)
 {
     switch (dataplane->protocol) {
     case BLKIF_PROTOCOL_NATIVE: {
@@ -532,7 +534,7 @@ static int blk_get_request(XenBlockDataPlane *dataplane,
     return 0;
 }
 
-static void blk_handle_requests(XenBlockDataPlane *dataplane)
+static void xen_block_handle_requests(XenBlockDataPlane *dataplane)
 {
     RING_IDX rc, rp;
     XenBlockRequest *request;
@@ -543,23 +545,22 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
     rp = dataplane->rings.common.sring->req_prod;
     xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
 
-    blk_send_response_all(dataplane);
+    xen_block_send_response_all(dataplane);
     while (rc != rp) {
         /* pull request from ring */
         if (RING_REQUEST_CONS_OVERFLOW(&dataplane->rings.common, rc)) {
             break;
         }
-        request = ioreq_start(dataplane);
+        request = xen_block_start_request(dataplane);
         if (request == NULL) {
             dataplane->more_work++;
             break;
         }
-        blk_get_request(dataplane, request, rc);
+        xen_block_get_request(dataplane, request, rc);
         dataplane->rings.common.req_cons = ++rc;
 
         /* parse them */
-        if (ioreq_parse(request) != 0) {
-
+        if (xen_block_parse_request(request) != 0) {
             switch (request->req.operation) {
             case BLKIF_OP_READ:
                 block_acct_invalid(blk_get_stats(dataplane->blk),
@@ -576,7 +577,7 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
                 break;
             };
 
-            if (blk_send_response_one(request)) {
+            if (xen_block_send_response_one(request)) {
                 Error *local_err = NULL;
 
                 xen_device_notify_event_channel(dataplane->xendev,
@@ -586,11 +587,11 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
                     error_report_err(local_err);
                 }
             }
-            ioreq_release(request, false);
+            xen_block_release_request(request, false);
             continue;
         }
 
-        ioreq_runio_qemu_aio(request);
+        xen_block_do_aio(request);
     }
 
     if (dataplane->more_work &&
@@ -599,16 +600,16 @@ static void blk_handle_requests(XenBlockDataPlane *dataplane)
     }
 }
 
-static void blk_bh(void *opaque)
+static void xen_block_dataplane_bh(void *opaque)
 {
     XenBlockDataPlane *dataplane = opaque;
 
     aio_context_acquire(dataplane->ctx);
-    blk_handle_requests(dataplane);
+    xen_block_handle_requests(dataplane);
     aio_context_release(dataplane->ctx);
 }
 
-static void blk_event(void *opaque)
+static void xen_block_dataplane_event(void *opaque)
 {
     XenBlockDataPlane *dataplane = opaque;
 
@@ -637,7 +638,8 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
     } else {
         dataplane->ctx = qemu_get_aio_context();
     }
-    dataplane->bh = aio_bh_new(dataplane->ctx, blk_bh, dataplane);
+    dataplane->bh = aio_bh_new(dataplane->ctx, xen_block_dataplane_bh,
+                               dataplane);
 
     return dataplane;
 }
@@ -795,7 +797,7 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
 
     dataplane->event_channel =
         xen_device_bind_event_channel(xendev, event_channel,
-                                      blk_event, dataplane,
+                                      xen_block_dataplane_event, dataplane,
                                       &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v2 13/18
#38 lore raw

Re: [Qemu-devel] [PATCH v2 13/18] xen: purge 'blk' and 'ioreq' from function names in dataplane/xen-block.c

Quoted 7 lines · Paul Durrant

This is a purely cosmetic patch that purges remaining use of 'blk' and 'ioreq' in local function names, and then makes sure all functions are prefixed with 'xen_block_'.

No functional change.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#39 lore raw

PATCH v2 14/18 xen: add implementations of xen-block connect and disconnect functions...

In reply to Paul Durrant

...and wire in the dataplane.

This patch adds the remaining code to make the xen-block XenDevice functional. The parameters that a block frontend expects to find are populated in the backend xenstore area, and the 'ring-ref' and 'event-channel' values specified in the frontend xenstore area are mapped/bound and used to set up the dataplane.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>

v2:
- Tidy up header inclusions
- Stop leaking ring_ref on error
- Auto-create drive for CDRom devices

---
 hw/block/xen-block.c       | 164 +++++++++++++++++++++++++++++++++++++++++++++
 hw/xen/xen-bus.c           |  12 ++--
 include/hw/xen/xen-block.h |   9 +++
 include/hw/xen/xen-bus.h   |  10 +++
 4 files changed, 189 insertions(+), 6 deletions(-)
hw/block/xen-block.c +164 -0
index d2334ef..fc64aaf 100644
@@ -10,7 +10,13 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "hw/hw.h"
+#include "hw/xen/xen_common.h"
+#include "hw/block/xen_blkif.h"
 #include "hw/xen/xen-block.h"
+#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
+#include "sysemu/iothread.h"
+#include "dataplane/xen-block.h"
 #include "trace.h"
 
 static char *xen_block_get_name(XenDevice *xendev, Error **errp)
@@ -28,6 +34,8 @@ static void xen_block_disconnect(XenDevice *xendev, Error **errp)
     XenBlockVdev *vdev = &blockdev->vdev;
 
     trace_xen_block_disconnect(type, vdev->disk, vdev->partition);
+
+    xen_block_dataplane_stop(blockdev->dataplane);
 }
 
 static void xen_block_connect(XenDevice *xendev, Error **errp)
@@ -35,8 +43,72 @@ static void xen_block_connect(XenDevice *xendev, Error **errp)
     XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev);
     const char *type = object_get_typename(OBJECT(blockdev));
     XenBlockVdev *vdev = &blockdev->vdev;
+    unsigned int order, nr_ring_ref, *ring_ref, event_channel, protocol;
+    char *str;
 
     trace_xen_block_connect(type, vdev->disk, vdev->partition);
+
+    if (xen_device_frontend_scanf(xendev, "ring-page-order", "%u",
+                                  &order) != 1) {
+        nr_ring_ref = 1;
+        ring_ref = g_new(unsigned int, nr_ring_ref);
+
+        if (xen_device_frontend_scanf(xendev, "ring-ref", "%u",
+                                      &ring_ref[0]) != 1) {
+            error_setg(errp, "failed to read ring-ref");
+            g_free(ring_ref);
+            return;
+        }
+    } else if (order <= blockdev->max_ring_page_order) {
+        unsigned int i;
+
+        nr_ring_ref = 1 << order;
+        ring_ref = g_new(unsigned int, nr_ring_ref);
+
+        for (i = 0; i < nr_ring_ref; i++) {
+            const char *key = g_strdup_printf("ring-ref%u", i);
+
+            if (xen_device_frontend_scanf(xendev, key, "%u",
+                                          &ring_ref[i]) != 1) {
+                error_setg(errp, "failed to read %s", key);
+                g_free((gpointer)key);
+                g_free(ring_ref);
+                return;
+            }
+
+            g_free((gpointer)key);
+        }
+    } else {
+        error_setg(errp, "invalid ring-page-order (%d)", order);
+        return;
+    }
+
+    if (xen_device_frontend_scanf(xendev, "event-channel", "%u",
+                                  &event_channel) != 1) {
+        error_setg(errp, "failed to read event-channel");
+        g_free(ring_ref);
+        return;
+    }
+
+    if (xen_device_frontend_scanf(xendev, "protocol", "%ms",
+                                  &str) != 1) {
+        protocol = BLKIF_PROTOCOL_NATIVE;
+    } else {
+        if (strcmp(str, XEN_IO_PROTO_ABI_X86_32) == 0) {
+            protocol = BLKIF_PROTOCOL_X86_32;
+        } else if (strcmp(str, XEN_IO_PROTO_ABI_X86_64) == 0) {
+            protocol = BLKIF_PROTOCOL_X86_64;
+        } else {
+            protocol = BLKIF_PROTOCOL_NATIVE;
+        }
+
+        free(str);
+    }
+
+    xen_block_dataplane_start(blockdev->dataplane, ring_ref, nr_ring_ref,
+                              event_channel, protocol, errp);
+
+    g_free(ring_ref);
 }
 
 static void xen_block_unrealize(XenDevice *xendev, Error **errp)
@@ -60,6 +132,9 @@ static void xen_block_unrealize(XenDevice *xendev, Error **errp)
         error_propagate(errp, local_err);
     }
 
+    xen_block_dataplane_destroy(blockdev->dataplane);
+    blockdev->dataplane = NULL;
+
     if (blockdev_class->unrealize) {
         blockdev_class->unrealize(blockdev, &local_err);
         if (local_err) {
@@ -76,6 +151,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
     const char *type = object_get_typename(OBJECT(blockdev));
     XenBlockVdev *vdev = &blockdev->vdev;
     Error *local_err = NULL;
+    BlockConf *conf = &blockdev->conf;
 
     if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
         error_setg(errp, "vdev property not set");
@@ -90,6 +166,59 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
             error_propagate(errp, local_err);
         }
     }
+
+    /*
+     * The blkif protocol does not deal with removable media, so it must
+     * always be present, even for CDRom devices.
+     */
+    assert(conf->blk);
+    if (!blk_is_inserted(conf->blk)) {
+        error_setg(errp, "device needs media, but drive is empty");
+        return;
+    }
+
+    if (!blkconf_apply_backend_options(conf, blockdev->info & VDISK_READONLY,
+                                       false, errp)) {
+        return;
+    }
+
+    if (!(blockdev->info & VDISK_CDROM) &&
+        !blkconf_geometry(conf, NULL, 65535, 255, 255, errp)) {
+        return;
+    }
+
+    blkconf_blocksizes(conf);
+
+    if (conf->logical_block_size > conf->physical_block_size) {
+        error_setg(
+            errp, "logical_block_size > physical_block_size not supported");
+        return;
+    }
+
+    blk_set_guest_block_size(conf->blk, conf->logical_block_size);
+
+    if (conf->discard_granularity > 0) {
+        xen_device_backend_printf(xendev, "feature-discard", "%u", 1);
+    }
+
+    xen_device_backend_printf(xendev, "feature-flush-cache", "%u", 1);
+    xen_device_backend_printf(xendev, "max-ring-page-order", "%u",
+                              blockdev->max_ring_page_order);
+    xen_device_backend_printf(xendev, "info", "%u", blockdev->info);
+
+    xen_device_frontend_printf(xendev, "virtual-device", "%lu",
+                               vdev->number);
+    xen_device_frontend_printf(xendev, "device-type", "%s",
+                               blockdev->device_type);
+
+    xen_device_backend_printf(xendev, "sector-size", "%u",
+                              conf->logical_block_size);
+    xen_device_backend_printf(xendev, "sectors", "%lu",
+                              blk_getlength(conf->blk) /
+                              conf->logical_block_size);
+
+    blockdev->dataplane = xen_block_dataplane_create(xendev, conf,
+                                                     blockdev->iothread);
 }
 
 static void xen_block_frontend_changed(XenDevice *xendev,
@@ -338,6 +467,11 @@ const PropertyInfo xen_block_prop_vdev = {
 static Property xen_block_props[] = {
     DEFINE_PROP("vdev", XenBlockDevice, vdev,
                 xen_block_prop_vdev, XenBlockVdev),
+    DEFINE_BLOCK_PROPERTIES(XenBlockDevice, conf),
+    DEFINE_PROP_UINT32("max-ring-page-order", XenBlockDevice,
+                       max_ring_page_order, 4),
+    DEFINE_PROP_LINK("iothread", XenBlockDevice, iothread, TYPE_IOTHREAD,
+                     IOThread *),
     DEFINE_PROP_END_OF_LIST()
 };
 
@@ -370,7 +504,18 @@ static void xen_disk_unrealize(XenBlockDevice *blockdev, Error **errp)
 
 static void xen_disk_realize(XenBlockDevice *blockdev, Error **errp)
 {
+    BlockConf *conf = &blockdev->conf;
+
     trace_xen_disk_realize();
+
+    blockdev->device_type = "disk";
+
+    if (!conf->blk) {
+        error_setg(errp, "drive property not set");
+        return;
+    }
+
+    blockdev->info = blk_is_read_only(conf->blk) ? VDISK_READONLY : 0;
 }
 
 static void xen_disk_class_init(ObjectClass *class, void *data)
@@ -398,7 +543,26 @@ static void xen_cdrom_unrealize(XenBlockDevice *blockdev, Error **errp)
 
 static void xen_cdrom_realize(XenBlockDevice *blockdev, Error **errp)
 {
+    BlockConf *conf = &blockdev->conf;
+
     trace_xen_cdrom_realize();
+
+    blockdev->device_type = "cdrom";
+
+    if (!conf->blk) {
+        int rc;
+
+        /* Set up an empty drive */
+        conf->blk = blk_new(0, BLK_PERM_ALL);
+
+        rc = blk_attach_dev(conf->blk, DEVICE(blockdev));
+        if (!rc) {
+            error_setg_errno(errp, -rc, "failed to create drive");
+            return;
+        }
+    }
+
+    blockdev->info = VDISK_READONLY | VDISK_CDROM;
 }
 
 static void xen_cdrom_class_init(ObjectClass *class, void *data)
hw/xen/xen-bus.c +6 -6
index 0e6f194..1b3837c 100644
@@ -236,8 +236,8 @@ static const TypeInfo xen_bus_type_info = {
     },
 };
 
-static void xen_device_backend_printf(XenDevice *xendev, const char *key,
-                                      const char *fmt, ...)
+void xen_device_backend_printf(XenDevice *xendev, const char *key,
+                               const char *fmt, ...)
 {
     XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
     Error *local_err = NULL;
@@ -336,8 +336,8 @@ static void xen_device_backend_destroy(XenDevice *xendev)
     }
 }
 
-static void xen_device_frontend_printf(XenDevice *xendev, const char *key,
-                                       const char *fmt, ...)
+void xen_device_frontend_printf(XenDevice *xendev, const char *key,
+                                const char *fmt, ...)
 {
     XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
     Error *local_err = NULL;
@@ -355,8 +355,8 @@ static void xen_device_frontend_printf(XenDevice *xendev, const char *key,
     }
 }
 
-static int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
-                                     const char *fmt, ...)
+int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
+                              const char *fmt, ...)
 {
     XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev)));
     va_list ap;
include/hw/xen/xen-block.h +9 -0
index 067932a..37ed8a6 100644
@@ -9,6 +9,9 @@
 #define HW_XEN_BLOCK_H
 
 #include "hw/xen/xen-bus.h"
+#include "hw/block/block.h"
+#include "hw/block/dataplane/xen-block.h"
+#include "sysemu/iothread.h"
 
 typedef enum XenBlockVdevType {
     XEN_BLOCK_VDEV_TYPE_INVALID,
@@ -29,6 +32,12 @@ typedef struct XenBlockVdev {
 typedef struct XenBlockDevice {
     XenDevice xendev;
     XenBlockVdev vdev;
+    BlockConf conf;
+    const char *device_type;
+    unsigned int info;
+    unsigned int max_ring_page_order;
+    IOThread *iothread;
+    XenBlockDataPlane *dataplane;
 } XenBlockDevice;
 
 typedef void (*XenBlockDeviceRealize)(XenBlockDevice *blockdev, Error **errp);
include/hw/xen/xen-bus.h +10 -0
index f83a95c..d7f0f0a 100644
@@ -84,6 +84,16 @@ void xen_device_backend_set_state(XenDevice *xendev,
                                   enum xenbus_state state);
 enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
 
+void xen_device_backend_printf(XenDevice *xendev, const char *key,
+                               const char *fmt, ...)
+    GCC_FMT_ATTR(3, 4);
+void xen_device_frontend_printf(XenDevice *xendev, const char *key,
+                                const char *fmt, ...)
+    GCC_FMT_ATTR(3, 4);
+
+int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
+                              const char *fmt, ...);
+
 void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
                                    Error **errp);
 void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#40 lore raw

Re: [Qemu-devel] [PATCH v2 14/18] xen: add implementations of xen-block connect and disconnect functions...

Quoted 9 lines · Paul Durrant

...and wire in the dataplane.

This patch adds the remaining code to make the xen-block XenDevice functional. The parameters that a block frontend expects to find are populated in the backend xenstore area, and the 'ring-ref' and 'event-channel' values specified in the frontend xenstore area are mapped/bound and used to set up the dataplane.

With this patch, we should be able to have QEMU instantiate a new backend for a guest, right ? (via command line or QMP)

I've tried, and that doesn't work, the xenstore path for the frontend is wrong. In the qemu trace, I have:

    xs_node_create /local/domain/0/backend/xen-disk/23/268572709
Which is probably fine, even if not described in xenstore-paths.markdown.
    xs_node_create /local/domain/23/device/xen-disk/268572709

Which is not, instead of "xen-disk", we should have "vbd".

I know that this is fixed in "xen: automatically create XenBlockDevice-s", but at least the "vbd" type couldn't be added in this patch, or maybe a previous one.

Another issue seems to be error handling. I've done a very simple test, I've added '-device xen-disk,vdev=d536p37,id=mydisk' to the command line (which is obvious wrong), and QEMU abort with:

    qemu-system-i386: hw/block/xen-block.c:174: xen_block_realize: Assertion `conf->blk' failed.

But I've pointed out the error in the code below.

And just for fun, adding then removing a xen-disk via QMP. Adding works fine (once I've fixed the frontend name). I've run the following with ./scripts/qmp/qmp-shell:
blockdev-add driver=file filename=/root/vm/disk/testing-disk.qcow2 node-name=emptyfile blockdev-add driver=qcow2 node-name=emptyqcow2 file=emptyfile
device_add driver=xen-disk vdev=xvdn id=fromqmp drive=emptyqcow2

But, then, remove doesn't work, running "device_del id=fromqmp" doesn't do anything. I guess we can try to fix that later if you don't find what's missing.

hw/block/xen-block.c static void xen_block_realize(XenDevice *xendev, Error **errp) · line 166

Quoted 10 lines
hw/block/xen-block.c +1 -0
@@ -76,6 +151,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
     const char *type = object_get_typename(OBJECT(blockdev));
     XenBlockVdev *vdev = &blockdev->vdev;
     Error *local_err = NULL;
+    BlockConf *conf = &blockdev->conf;
 
     if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
         error_setg(errp, "vdev property not set");
@@ -90,6 +166,59 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
             error_propagate(errp, local_err);

You probably want to add a return here, this is when `blockdev_class->realize' fails.

hw/block/xen-block.c static void xen_block_realize(XenDevice *xendev, Error **errp) · line 174

Quoted 8 lines
hw/block/xen-block.c +6 -0
         }
     }
+
+    /*
+     * The blkif protocol does not deal with removable media, so it must
+     * always be present, even for CDRom devices.
+     */
+    assert(conf->blk);

That assert should probably not be there, as a missing conf->blk isn't a programming error, but a user error, I think.

Actually, the issue is the missing return abrove, and the assert is probably fine.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#41 lore raw

Re: [Qemu-devel] [PATCH v2 14/18] xen: add implementations of xen-block connect and disconnect functions...

Quoted 26 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 18:21
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Stefano Stabellini <[email protected]>; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>
Subject: Re: [PATCH v2 14/18] xen: add implementations of xen-block connect and disconnect functions...

Quoted 9 lines · Paul Durrant

...and wire in the dataplane.

This patch adds the remaining code to make the xen-block XenDevice functional. The parameters that a block frontend expects to find are populated in the backend xenstore area, and the 'ring-ref' and 'event-channel' values specified in the frontend xenstore area are mapped/bound and used to set up the dataplane.

With this patch, we should be able to have QEMU instantiate a new backend for a guest, right ? (via command line or QMP)

I've tried, and that doesn't work, the xenstore path for the frontend is wrong. In the qemu trace, I have:

Quoted 8 lines
    xs_node_create /local/domain/0/backend/xen-disk/23/268572709
Which is probably fine, even if not described in xenstore-paths.markdown.
    xs_node_create /local/domain/23/device/xen-disk/268572709

Which is not, instead of "xen-disk", we should have "vbd".

I know that this is fixed in "xen: automatically create XenBlockDevice-s", but at least the "vbd" type couldn't be added in this patch, or maybe a previous one.

Yes, I guess I should move the name overrides into an earlier patch.

Quoted 18 lines

Another issue seems to be error handling. I've done a very simple test, I've added '-device xen-disk,vdev=d536p37,id=mydisk' to the command line (which is obvious wrong), and QEMU abort with:

    qemu-system-i386: hw/block/xen-block.c:174: xen_block_realize:

Assertion `conf->blk' failed.
But I've pointed out the error in the code below.

And just for fun, adding then removing a xen-disk via QMP. Adding works fine (once I've fixed the frontend name). I've run the following with ./scripts/qmp/qmp-shell:
blockdev-add driver=file filename=/root/vm/disk/testing-disk.qcow2 node- name=emptyfile
blockdev-add driver=qcow2 node-name=emptyqcow2 file=emptyfile device_add driver=xen-disk vdev=xvdn id=fromqmp drive=emptyqcow2

Quoted 3 lines

But, then, remove doesn't work, running "device_del id=fromqmp" doesn't do anything. I guess we can try to fix that later if you don't find what's missing.

Hmm, that's weird. I guess the name lookup must be failing somewhere.

Quoted 8 lines

Review static void xen_block_realize(XenDevice *xendev,

Quoted 2 lines
(quoted diff) +0 -0
@@ -76,6 +151,7 @@ static void xen_block_realize(XenDevice *xendev,

Error **errp)

Quoted 5 lines
hw/block/xen-block.c +1 -0
     const char *type = object_get_typename(OBJECT(blockdev));
     XenBlockVdev *vdev = &blockdev->vdev;
     Error *local_err = NULL;
+    BlockConf *conf = &blockdev->conf;
 
Quoted 9 lines

hw/block/xen-block.c static void xen_block_realize(XenDevice *xendev,

Quoted 3 lines
hw/block/xen-block.c +0 -0
     if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) {
         error_setg(errp, "vdev property not set");
@@ -90,6 +166,59 @@ static void xen_block_realize(XenDevice *xendev,

Error **errp)

Review static void xen_block_realize(XenDevice *xendev, · line 166

Quoted 1 line
(quoted diff) +0 -0
             error_propagate(errp, local_err);

You probably want to add a return here, this is when `blockdev_class->realize' fails.

Yes, I do.

Quoted 10 lines

hw/block/xen-block.c static void xen_block_realize(XenDevice *xendev, Error **errp)

Quoted 5 lines
hw/block/xen-block.c +3 -0
         }
     }
+
+    /*
+     * The blkif protocol does not deal with removable media, so it

must

hw/block/xen-block.c static void xen_block_realize(XenDevice *xendev, Error **errp) · line 174

Quoted 3 lines
hw/block/xen-block.c +3 -0
+     * always be present, even for CDRom devices.
+     */
+    assert(conf->blk);
Quoted 6 lines

That assert should probably not be there, as a missing conf->blk isn't a programming error, but a user error, I think.

Actually, the issue is the missing return abrove, and the assert is probably fine.

Yes, the assert is intentional and caught the programming error :-)

Paul

Quoted 2 lines

--
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#42 lore raw

Re: [Qemu-devel] [PATCH v2 14/18] xen: add implementations of xen-block connect and disconnect functions...

In reply to Anthony PERARD
Quoted 52 lines

-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 07 December 2018 18:21
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Stefano Stabellini <[email protected]>; Kevin Wolf <[email protected]>; Max Reitz <[email protected]>
Subject: Re: [PATCH v2 14/18] xen: add implementations of xen-block connect and disconnect functions...

Quoted 9 lines · Paul Durrant

...and wire in the dataplane.

This patch adds the remaining code to make the xen-block XenDevice functional. The parameters that a block frontend expects to find are populated in the backend xenstore area, and the 'ring-ref' and 'event-channel' values specified in the frontend xenstore area are mapped/bound and used to set up the dataplane.

With this patch, we should be able to have QEMU instantiate a new backend for a guest, right ? (via command line or QMP)

I've tried, and that doesn't work, the xenstore path for the frontend is wrong. In the qemu trace, I have:

    xs_node_create /local/domain/0/backend/xen-disk/23/268572709
Which is probably fine, even if not described in xenstore-paths.markdown.
    xs_node_create /local/domain/23/device/xen-disk/268572709

Which is not, instead of "xen-disk", we should have "vbd".

I know that this is fixed in "xen: automatically create XenBlockDevice-s", but at least the "vbd" type couldn't be added in this patch, or maybe a previous one.

Another issue seems to be error handling. I've done a very simple test, I've added '-device xen-disk,vdev=d536p37,id=mydisk' to the command line (which is obvious wrong), and QEMU abort with:

    qemu-system-i386: hw/block/xen-block.c:174: xen_block_realize:

Assertion `conf->blk' failed.
But I've pointed out the error in the code below.

And just for fun, adding then removing a xen-disk via QMP. Adding works fine (once I've fixed the frontend name). I've run the following with ./scripts/qmp/qmp-shell:
blockdev-add driver=file filename=/root/vm/disk/testing-disk.qcow2 node- name=emptyfile
blockdev-add driver=qcow2 node-name=emptyqcow2 file=emptyfile device_add driver=xen-disk vdev=xvdn id=fromqmp drive=emptyqcow2

Quoted 3 lines

But, then, remove doesn't work, running "device_del id=fromqmp" doesn't do anything. I guess we can try to fix that later if you don't find what's missing.

The missing piece is a hotplug controller 'unplug' or 'unplug_request' method implementation. I think the 'right' thing to do is implement 'unplug_request' and mimic the behaviour of libxl... i.e. set 'online' to 0 and 'state' to closing (i.e. 5) under transaction lock. This means that any connected frontend should go through a clean disconnect and then the device will get removed. To that end I'm going to need to add transaction support to my helper functions (in patch #4) and then add in the unplug_request implementation in this patch.

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#43 lore raw

PATCH v2 15/18 xen: add a mechanism to automatically create XenDevice-s...

In reply to Paul Durrant

...that maintains compatibility with existing Xen toolstacks.

Xen toolstacks instantiate PV backends by simply writing information into xenstore and expecting a backend implementation to be watching for this.

This patch adds a new 'xen-backend' module to allow individual XenDevice implementations to register a creator function to be called when a tool- stack instantiates a new backend in this way.

To support this it is also necessary to add new watchers into the XenBus implementation to handle enumeration of new backends and also destruction of XenDevice-s when the toolstack sets the backend 'online' key to 0.

NOTE: This patch only adds the framework. A subsequent patch will add a
creator function for xen-block devices.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

v2:
- Sort out error paths and error reporting

---
 hw/xen/Makefile.objs         |   2 +-
 hw/xen/trace-events          |   5 +
 hw/xen/xen-backend.c         |  69 +++++++++++++
 hw/xen/xen-bus.c             | 226 +++++++++++++++++++++++++++++++++++++++----
 include/hw/xen/xen-backend.h |  26 +++++
 include/hw/xen/xen-bus.h     |   5 +-
 include/qemu/module.h        |   3 +
 7 files changed, 315 insertions(+), 21 deletions(-)
 create mode 100644 hw/xen/xen-backend.c
 create mode 100644 include/hw/xen/xen-backend.h
hw/xen/Makefile.objs +1 -1
index 77c0868..84df60a 100644
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o xen-bus.o xen-bus-helper.o
+common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-common.o xen-bus.o xen-bus-helper.o xen-backend.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
hw/xen/trace-events +5 -0
index 22055b5..d567242 100644
@@ -16,13 +16,18 @@ xen_domid_restrict(int err) "err: %u"
 # include/hw/xen/xen-bus.c
 xen_bus_realize(void) ""
 xen_bus_unrealize(void) ""
+xen_bus_enumerate(void) ""
+xen_bus_type_enumerate(const char *type) "type: %s"
+xen_bus_backend_create(const char *type, const char *path) "type: %s path: %s"
 xen_bus_add_watch(const char *node, const char *key, char *token) "node: %s key: %s token: %s"
 xen_bus_remove_watch(const char *node, const char *key, char *token) "node: %s key: %s token: %s"
 xen_bus_watch(const char *token) "token: %s"
 xen_device_realize(const char *type, char *name) "type: %s name: %s"
 xen_device_unrealize(const char *type, char *name) "type: %s name: %s"
 xen_device_backend_state(const char *type, char *name, const char *state) "type: %s name: %s -> %s"
+xen_device_backend_online(const char *type, char *name, bool online) "type: %s name: %s -> %u"
 xen_device_frontend_state(const char *type, char *name, const char *state) "type: %s name: %s -> %s"
+xen_device_backend_changed(const char *type, char *name) "type: %s name: %s"
 xen_device_frontend_changed(const char *type, char *name) "type: %s name: %s"
 
 # include/hw/xen/xen-bus-helper.c
hw/xen/xen-backend.c new file +69 -0

69 lines not on this page · raw message

hw/xen/xen-bus.c +207 -19

292 lines not on this page · raw message

include/hw/xen/xen-backend.h new file +26 -0
new file mode 100644
index 0000000..dd9bd58
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018  Citrix Systems Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_XEN_BACKEND_H
+#define HW_XEN_BACKEND_H
+
+#include "hw/xen/xen-bus.h"
+
+typedef void (*XenBackendDeviceCreate)(BusState *bus, const char *name,
+                                       QDict *opts, Error **errp);
+
+typedef struct XenBackendInfo {
+    const char *type;
+    XenBackendDeviceCreate create;
+} XenBackendInfo;
+
+void xen_backend_register(const XenBackendInfo *info);
+
+void xen_backend_device_create(BusState *bus, const char *type,
+                               const char *name, QDict *opts, Error **errp);
+
+#endif /* HW_XEN_BACKEND_H */
include/hw/xen/xen-bus.h +4 -1
index d7f0f0a..e55a5de 100644
@@ -23,7 +23,9 @@ typedef struct XenDevice {
     char *backend_path, *frontend_path;
     enum xenbus_state backend_state, frontend_state;
     Notifier exit;
-    XenWatch *frontend_state_watch;
+    XenWatch *backend_state_watch, *frontend_state_watch;
+    bool backend_online;
+    XenWatch *backend_online_watch;
     xengnttab_handle *xgth;
     bool feature_grant_copy;
     xenevtchn_handle *xeh;
@@ -63,6 +65,7 @@ typedef struct XenBus {
     domid_t backend_id;
     struct xs_handle *xsh;
     NotifierList watch_notifiers;
+    XenWatch *backend_watch;
 } XenBus;
 
 typedef struct XenBusClass {
include/qemu/module.h +3 -0
index 54300ab..55dd2be 100644
@@ -44,6 +44,7 @@ typedef enum {
     MODULE_INIT_OPTS,
     MODULE_INIT_QOM,
     MODULE_INIT_TRACE,
+    MODULE_INIT_XEN_BACKEND,
     MODULE_INIT_MAX
 } module_init_type;
 
@@ -51,6 +52,8 @@ typedef enum {
 #define opts_init(function) module_init(function, MODULE_INIT_OPTS)
 #define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
+#define xen_backend_init(function) module_init(function, \
+                                               MODULE_INIT_XEN_BACKEND)
 
 #define block_module_load_one(lib) module_load_one("block-", lib)
 #define ui_module_load_one(lib) module_load_one("ui-", lib)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 15/18
#44 lore raw

Re: [PATCH v2 15/18] xen: add a mechanism to automatically create XenDevice-s...

Quoted 9 lines · Paul Durrant

...that maintains compatibility with existing Xen toolstacks.

Xen toolstacks instantiate PV backends by simply writing information into xenstore and expecting a backend implementation to be watching for this.

This patch adds a new 'xen-backend' module to allow individual XenDevice implementations to register a creator function to be called when a tool- stack instantiates a new backend in this way.

Quoted 8 lines

To support this it is also necessary to add new watchers into the XenBus implementation to handle enumeration of new backends and also destruction of XenDevice-s when the toolstack sets the backend 'online' key to 0.

NOTE: This patch only adds the framework. A subsequent patch will add a
creator function for xen-block devices.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 15/18
#45 lore raw

Re: [Qemu-devel] [PATCH v2 15/18] xen: add a mechanism to automatically create XenDevice-s...

In reply to Paul Durrant
Quoted 9 lines · Paul Durrant

...that maintains compatibility with existing Xen toolstacks.

Xen toolstacks instantiate PV backends by simply writing information into xenstore and expecting a backend implementation to be watching for this.

This patch adds a new 'xen-backend' module to allow individual XenDevice implementations to register a creator function to be called when a tool- stack instantiates a new backend in this way.

Quoted 8 lines

To support this it is also necessary to add new watchers into the XenBus implementation to handle enumeration of new backends and also destruction of XenDevice-s when the toolstack sets the backend 'online' key to 0.

NOTE: This patch only adds the framework. A subsequent patch will add a
creator function for xen-block devices.

Thanks,

Signature · 1 line
Anthony PERARD
#46 lore raw

PATCH v2 16/18 xen: automatically create XenBlockDevice-s

In reply to Paul Durrant

This patch adds a creator function for XenBlockDevice-s so that they can be created automatically when the Xen toolstack instantiates a new PV backend. When the XenBlockDevice is created this way it is also necessary to create a drive which matches the configuration that the Xen toolstack has written into xenstore. This drive is marked 'auto_del' so that it will be removed when the XenBlockDevice is destroyed. Also, for compatibility with the legacy 'xen_disk' implementation, an iothread is automatically created for the new XenBlockDevice. This will also be removed when the XenBlockDevice is destroyed.

Correspondingly the legacy backend scan for 'qdisk' is removed.

After this patch is applied the legacy 'xen_disk' code is redundant. It will be removed by a subsequent patch.

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

v2:
- Get rid of error_abort
- Don't use qdev_init_nofail
- Explain why file locking needs to be off

---
 hw/block/trace-events       |   1 +
 hw/block/xen-block.c        | 262 +++++++++++++++++++++++++++++++++++++++++++-
 hw/xen/xen-bus.c            |   2 +-
 hw/xen/xen-legacy-backend.c |   1 -
 include/hw/xen/xen-block.h  |   1 +
 5 files changed, 264 insertions(+), 3 deletions(-)
hw/block/trace-events +1 -0
index 89e2583..a89c8a6 100644
@@ -137,3 +137,4 @@ xen_disk_realize(void) ""
 xen_disk_unrealize(void) ""
 xen_cdrom_realize(void) ""
 xen_cdrom_unrealize(void) ""
+xen_block_device_create(const char *name) "name: %s"
hw/block/xen-block.c +261 -1

301 lines not on this page · raw message

hw/xen/xen-bus.c +1 -1
index 83edeb9..4a8baef 100644
@@ -193,7 +193,7 @@ static void xen_bus_backend_create(XenBus *xenbus, const char *type,
 
     if (local_err) {
         error_reportf_err(local_err, "failed to create '%s' device '%s': ",
-                      type, name);
+                          type, name);
     }
 }
 
hw/xen/xen-legacy-backend.c +0 -1
index 0c26023..fb227de 100644
@@ -753,7 +753,6 @@ void xen_be_register_common(void)
 
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
-    xen_be_register("qdisk", &xen_blkdev_ops);
 #ifdef CONFIG_VIRTFS
     xen_be_register("9pfs", &xen_9pfs_ops);
 #endif
include/hw/xen/xen-block.h +1 -0
index 37ed8a6..5bced60 100644
@@ -37,6 +37,7 @@ typedef struct XenBlockDevice {
     unsigned int info;
     unsigned int max_ring_page_order;
     IOThread *iothread;
+    IOThread *auto_iothread;
     XenBlockDataPlane *dataplane;
 } XenBlockDevice;
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 16/18
#47 lore raw

Re: [PATCH v2 16/18] xen: automatically create XenBlockDevice-s

Quoted 10 lines · Paul Durrant

This patch adds a creator function for XenBlockDevice-s so that they can be created automatically when the Xen toolstack instantiates a new PV backend. When the XenBlockDevice is created this way it is also necessary to create a drive which matches the configuration that the Xen toolstack has written into xenstore. This drive is marked 'auto_del' so that it will be removed when the XenBlockDevice is destroyed. Also, for compatibility with the legacy 'xen_disk' implementation, an iothread is automatically created for the new XenBlockDevice. This will also be removed when the XenBlockDevice is destroyed.

Quoted 6 lines

Correspondingly the legacy backend scan for 'qdisk' is removed.

After this patch is applied the legacy 'xen_disk' code is redundant. It will be removed by a subsequent patch.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 16/18
#48 lore raw

Re: [Qemu-devel] [PATCH v2 16/18] xen: automatically create XenBlockDevice-s

In reply to Paul Durrant
Quoted 10 lines · Paul Durrant

This patch adds a creator function for XenBlockDevice-s so that they can be created automatically when the Xen toolstack instantiates a new PV backend. When the XenBlockDevice is created this way it is also necessary to create a drive which matches the configuration that the Xen toolstack has written into xenstore. This drive is marked 'auto_del' so that it will be removed when the XenBlockDevice is destroyed. Also, for compatibility with the legacy 'xen_disk' implementation, an iothread is automatically created for the new XenBlockDevice. This will also be removed when the XenBlockDevice is destroyed.

Quoted 6 lines

Correspondingly the legacy backend scan for 'qdisk' is removed.

After this patch is applied the legacy 'xen_disk' code is redundant. It will be removed by a subsequent patch.

Thanks,

Signature · 1 line
Anthony PERARD
#49 lore raw

PATCH v2 17/18 MAINTAINERS: add myself as a Xen maintainer

In reply to Paul Durrant

I have made many significant contributions to the Xen code in QEMU, particularly the recent patches introducing a new PV device framework. I intend to make further significant contributions, porting other PV back- ends to the new framework with the intent of eventually removing the legacy code. It therefore seems reasonable that I become a maintainer of the Xen code.

---
Cc: Paolo Bonzini <[email protected]>

v2:
- Fix typo

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 9875581..e6bd441 100644
@@ -396,6 +396,7 @@ Guest CPU Cores (Xen):
 X86
 M: Stefano Stabellini <[email protected]>
 M: Anthony Perard <[email protected]>
+M: Paul Durrant <[email protected]>
 L: [email protected]
 S: Supported
 F: */xen*
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#50 lore raw

PATCH v2 18/18 xen: remove the legacy 'xen_disk' backend

In reply to Paul Durrant

This backend has now been replaced by the 'xen-qdisk' XenDevice.

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Stefano Stabellini <[email protected]>

---
 hw/block/Makefile.objs |    1 -
 hw/block/xen_disk.c    | 1011 ------------------------------------------------
 2 files changed, 1012 deletions(-)
 delete mode 100644 hw/block/xen_disk.c
hw/block/Makefile.objs +0 -1
index f34813a..e206b8e 100644
@@ -5,7 +5,6 @@ common-obj-$(CONFIG_NAND) += nand.o
 common-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 common-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
 common-obj-$(CONFIG_XEN) += xen-block.o
-common-obj-$(CONFIG_XEN) += xen_disk.o
 common-obj-$(CONFIG_ECC) += ecc.o
 common-obj-$(CONFIG_ONENAND) += onenand.o
 common-obj-$(CONFIG_NVME_PCI) += nvme.o
hw/block/xen_disk.c deleted +0 -1011

1,011 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v2 18/18
#51 lore raw

Re: [Qemu-devel] [PATCH v2 18/18] xen: remove the legacy 'xen_disk' backend

Quoted 3 lines · Paul Durrant

This backend has now been replaced by the 'xen-qdisk' XenDevice.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel