Patchwork [RFC,v2,1/4] block: Fake a bdrv_aio_pwrite

login
register
mail settings
Submitter Kevin Wolf
Date Nov. 5, 2010, 6:38 p.m.
Message ID <1288982307-30559-2-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/70281/
State New
Headers show

Comments

Kevin Wolf - Nov. 5, 2010, 6:38 p.m.
Don't read this patch, it will be thrown away :-)
---
 block.c |   30 ++++++++++++++++++++++++++++++
 block.h |    2 ++
 2 files changed, 32 insertions(+), 0 deletions(-)

Patch

diff --git a/block.c b/block.c
index 985d0b7..f75da13 100644
--- a/block.c
+++ b/block.c
@@ -2053,6 +2053,36 @@  BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
     return ret;
 }
 
+struct pread_acb {
+    QEMUBH *bh;
+    BlockDriverCompletionFunc *cb;
+    void *opaque;
+    int ret;
+};
+
+static void bdrv_aio_pwrite_cb(void *opaque)
+{
+    struct pread_acb *x = opaque;
+
+    x->cb(x->opaque, x->ret);
+    qemu_bh_delete(x->bh);
+    free(x);
+}
+
+/* TODO Yes, this is a really bad fake implementation */
+BlockDriverAIOCB *bdrv_aio_pwrite(BlockDriverState *bs, int64_t offset, void* buf,
+    size_t bytes, BlockDriverCompletionFunc *cb, void *opaque)
+{
+    struct pread_acb *x = qemu_malloc(sizeof(*x));
+    x->bh = qemu_bh_new(bdrv_aio_pwrite_cb, x);
+    x->cb = cb;
+    x->opaque = opaque;
+    x->ret = bdrv_pwrite(bs, offset, buf, bytes);
+    qemu_bh_schedule(x->bh);
+
+    return (BlockDriverAIOCB*) 42;
+}
+
 
 typedef struct MultiwriteCB {
     int error;
diff --git a/block.h b/block.h
index a4facf2..5798cdb 100644
--- a/block.h
+++ b/block.h
@@ -116,6 +116,8 @@  BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
 BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
                                   QEMUIOVector *iov, int nb_sectors,
                                   BlockDriverCompletionFunc *cb, void *opaque);
+BlockDriverAIOCB *bdrv_aio_pwrite(BlockDriverState *bs, int64_t offset, void* buf,
+    size_t bytes, BlockDriverCompletionFunc *cb, void *opaque);
 BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
 				 BlockDriverCompletionFunc *cb, void *opaque);
 void bdrv_aio_cancel(BlockDriverAIOCB *acb);