On 01/13/2012 10:34 AM, Paolo Bonzini wrote:
QSLIST is equivalent to an open-coded free list, use it.

Signed-off-by: Paolo Bonzini<pbonz...@redhat.com>

Surprisingly enough, this breaks hotplug (causes QEMU to segv).

I'll drop this patch and you can bring the next one in through Kevin's queue to make sure it gets adequate review.

Regards,

Anthony Liguori

---
  block.c     |    9 ++++-----
  block_int.h |    4 ++--
  2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index 3f072f6..acb54b1 100644
--- a/block.c
+++ b/block.c
@@ -3242,9 +3242,9 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
  {
      BlockDriverAIOCB *acb;

-    if (pool->free_aiocb) {
-        acb = pool->free_aiocb;
-        pool->free_aiocb = acb->next;
+    if (!QSLIST_EMPTY(pool->free_aiocb)) {
+        acb = QSLIST_FIRST(pool->free_aiocb);
+        QSLIST_REMOVE_HEAD(pool->free_aiocb, next);
      } else {
          acb = g_malloc0(pool->aiocb_size);
          acb->pool = pool;
@@ -3259,8 +3259,7 @@ void qemu_aio_release(void *p)
  {
      BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p;
      AIOPool *pool = acb->pool;
-    acb->next = pool->free_aiocb;
-    pool->free_aiocb = acb;
+    QSLIST_INSERT_HEAD(pool->free_aiocb, acb, next);
  }

  /**************************************************************/
diff --git a/block_int.h b/block_int.h
index 311bd2a..c592e54 100644
--- a/block_int.h
+++ b/block_int.h
@@ -56,7 +56,7 @@ typedef struct BdrvTrackedRequest BdrvTrackedRequest;
  typedef struct AIOPool {
      void (*cancel)(BlockDriverAIOCB *acb);
      int aiocb_size;
-    BlockDriverAIOCB *free_aiocb;
+    QSLIST_HEAD(, BlockDriverAIOCB) *free_aiocb;
  } AIOPool;

  typedef struct BlockIOLimit {
@@ -268,7 +268,7 @@ struct BlockDriverAIOCB {
      BlockDriverState *bs;
      BlockDriverCompletionFunc *cb;
      void *opaque;
-    BlockDriverAIOCB *next;
+    QSLIST_ENTRY(BlockDriverAIOCB) next;
  };

  void get_tmp_filename(char *filename, int size);


Reply via email to