Patchwork [04/10] dma-helpers: prepare for adding dma_buf_* functions

login
register
mail settings
Submitter Paolo Bonzini
Date Aug. 4, 2011, 5:14 p.m.
Message ID <1312478089-806-5-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/108555/
State New
Headers show

Comments

Paolo Bonzini - Aug. 4, 2011, 5:14 p.m.
Store in the AIOCB which callback function we are using, and abstract
the process of starting DMA.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 dma-helpers.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

Patch

diff --git a/dma-helpers.c b/dma-helpers.c
index d716524..4469ce2 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -78,9 +78,13 @@  void qemu_sglist_destroy(QEMUSGList *qsg)
     qemu_free(qsg->sg);
 }
 
-typedef struct {
+typedef struct DMAAIOCB DMAAIOCB;
+
+struct DMAAIOCB {
     BlockDriverAIOCB common;
-    BlockDriverState *bs;
+    union {
+        BlockDriverState *bs;
+    } u;
     BlockDriverAIOCB *acb;
     QEMUSGList *sg;
     uint64_t sector_num;
@@ -88,9 +92,8 @@  typedef struct {
     QEMUIOVector iov;
     QEMUBH *bh;
     DMAIOFunc *io_func;
-} DMAAIOCB;
-
-static int dma_bdrv_cb(DMAAIOCB *opaque, int ret);
+    int (*cb)(DMAAIOCB *, int);
+};
 
 static void dma_bdrv_unmap(DMAAIOCB *dbs)
 {
@@ -122,11 +125,11 @@  static BlockDriverAIOCB *dma_continue(DMAAIOCB *dbs, int ret)
 {
     assert(ret != -EAGAIN);
     if (ret == 0) {
-        /* No error so far, try doing more DMA.  If dma_bdrv_cb starts an
+        /* No error so far, try doing more DMA.  If dbs->cb starts an
            asynchronous operation, it returns -EAGAIN and we will be
            called again by either reschedule_dma or dma_bdrv_aio_cb.
            If not, call the BlockDriverCompletionFunc.  */
-        ret = dma_bdrv_cb(dbs, ret);
+        ret = dbs->cb(dbs, ret);
     }
     if (ret != -EAGAIN) {
         dma_complete(dbs, ret);
@@ -180,7 +183,7 @@  static int dma_bdrv_cb(DMAAIOCB *dbs, int ret)
         return -EAGAIN;
     }
 
-    dbs->acb = dbs->io_func(dbs->bs, dbs->sector_num, &dbs->iov,
+    dbs->acb = dbs->io_func(dbs->u.bs, dbs->sector_num, &dbs->iov,
                             dbs->iov.size / 512, dma_bdrv_aio_cb, dbs);
     if (!dbs->acb) {
         dbs->common.cb = NULL;
@@ -216,12 +219,13 @@  BlockDriverAIOCB *dma_bdrv_io(
     DMAAIOCB *dbs = qemu_aio_get(&dma_aio_pool, bs, cb, opaque);
 
     dbs->acb = NULL;
-    dbs->bs = bs;
+    dbs->u.bs = bs;
     dbs->sg = sg;
     dbs->sector_num = sector_num;
     dbs->is_write = is_write;
     dbs->io_func = io_func;
     dbs->bh = NULL;
+    dbs->cb = dma_bdrv_cb;
     qemu_iovec_init(&dbs->iov, sg->nsg);
     qemu_sglist_rewind(sg);
     return dma_continue(dbs, 0);