Patchwork [3/6] Switch block migration lists to QSIMPLEQ

login
register
mail settings
Submitter Pierre Riteau
Date Nov. 26, 2009, 6:44 p.m.
Message ID <1259261046-32650-4-git-send-email-Pierre.Riteau@irisa.fr>
Download mbox | patch
Permalink /patch/39585/
State New
Headers show

Comments

Pierre Riteau - Nov. 26, 2009, 6:44 p.m.
Signed-off-by: Pierre Riteau <Pierre.Riteau@irisa.fr>
---
 block-migration.c |   53 +++++++++++++++++++----------------------------------
 block-migration.h |    2 +-
 2 files changed, 20 insertions(+), 35 deletions(-)

Patch

diff --git a/block-migration.c b/block-migration.c
index 0cb162a..1626168 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -14,6 +14,7 @@ 
 #include "qemu-common.h"
 #include "block_int.h"
 #include "hw/hw.h"
+#include "qemu-queue.h"
 #include "block-migration.h"
 #include <assert.h>
 
@@ -49,7 +50,7 @@  typedef struct BlkMigBlock {
     QEMUIOVector qiov;
     BlockDriverAIOCB *aiocb;
     int ret;
-    struct BlkMigBlock *next;
+    QSIMPLEQ_ENTRY(BlkMigBlock) entries;
 } BlkMigBlock;
 
 typedef struct BlkMigState {
@@ -58,10 +59,9 @@  typedef struct BlkMigState {
     int shared_base;
     int no_dirty;
     QEMUFile *load_file;
-    BlkMigDevState *bmds_first;
+    QSIMPLEQ_HEAD(, BlkMigDevState) bmds_list;
     int sectors_per_block;
-    BlkMigBlock *first_blk;
-    BlkMigBlock *last_blk;
+    QSIMPLEQ_HEAD(, BlkMigBlock) block_list;
     int submitted;
     int read_done;
     int transferred;
@@ -76,14 +76,7 @@  static void blk_mig_read_cb(void *opaque, int ret)
 
     blk->ret = ret;
 
-    /* insert at the end */
-    if (block_mig_state->last_blk == NULL) {
-        block_mig_state->first_blk = blk;
-        block_mig_state->last_blk = blk;
-    } else {
-        block_mig_state->last_blk->next = blk;
-        block_mig_state->last_blk = blk;
-    }
+    QSIMPLEQ_INSERT_TAIL(&block_mig_state->block_list, blk, entries);
 
     block_mig_state->submitted--;
     block_mig_state->read_done++;
@@ -139,7 +132,6 @@  static int mig_read_device_bulk(QEMUFile *f, BlkMigDevState *bms)
     bms->cur_sector = cur_sector + nr_sectors;
     blk->sector = cur_sector;
     blk->bmds = bms;
-    blk->next = NULL;
 
     blk->iov.iov_base = blk->buf;
     blk->iov.iov_len = nr_sectors * SECTOR_SIZE;
@@ -247,7 +239,7 @@  static void blk_mig_save_dev_info(QEMUFile *f, BlkMigDevState *bmds)
 static void set_dirty_tracking(int enable)
 {
     BlkMigDevState *bmds;
-    for (bmds = block_mig_state->bmds_first; bmds != NULL; bmds = bmds->next) {
+    QSIMPLEQ_FOREACH(bmds, &block_mig_state->bmds_list, entries) {
         bdrv_set_dirty_tracking(bmds->bs, enable);
     }
 
@@ -256,7 +248,7 @@  static void set_dirty_tracking(int enable)
 
 static void init_blk_migration(QEMUFile *f)
 {
-    BlkMigDevState **pbmds, *bmds;
+    BlkMigDevState *bmds;
     BlockDriverState *bs;
 
     for (bs = bdrv_first; bs != NULL; bs = bs->next) {
@@ -274,13 +266,7 @@  static void init_blk_migration(QEMUFile *f)
                 printf("Start full migration for %s\n", bs->device_name);
             }
 
-            /* insert at the end */
-            pbmds = &block_mig_state->bmds_first;
-            while (*pbmds != NULL) {
-                pbmds = &(*pbmds)->next;
-            }
-            *pbmds = bmds;
-
+            QSIMPLEQ_INSERT_TAIL(&block_mig_state->bmds_list, bmds, entries);
             blk_mig_save_dev_info(f, bmds);
         }
     }
@@ -294,7 +280,7 @@  static int blk_mig_save_bulked_block(QEMUFile *f, int is_async)
 {
     BlkMigDevState *bmds;
 
-    for (bmds = block_mig_state->bmds_first; bmds != NULL; bmds = bmds->next) {
+    QSIMPLEQ_FOREACH(bmds, &block_mig_state->bmds_list, entries) {
         if (bmds->bulk_completed == 0) {
             if (is_async) {
                 if (mig_read_device_bulk(f, bmds) == 1) {
@@ -326,7 +312,7 @@  static void blk_mig_save_dirty_blocks(QEMUFile *f)
     int64_t sector;
     int len;
 
-    for (bmds = block_mig_state->bmds_first; bmds != NULL; bmds = bmds->next) {
+    QSIMPLEQ_FOREACH(bmds, &block_mig_state->bmds_list, entries) {
         for (sector = 0; sector < bmds->cur_sector;) {
 
             if (bdrv_get_dirty(bmds->bs, sector)) {
@@ -364,27 +350,24 @@  static void blk_mig_save_dirty_blocks(QEMUFile *f)
 
 static void flush_blks(QEMUFile* f)
 {
-    BlkMigBlock *blk, *tmp;
+    BlkMigBlock *blk;
 
     dprintf("%s Enter submitted %d read_done %d transfered\n", __FUNCTION__,
             submitted, read_done, transfered);
 
-    for (blk = block_mig_state->first_blk;
-        blk != NULL && !qemu_file_rate_limit(f); blk = tmp) {
+    while ((blk = QSIMPLEQ_FIRST(&block_mig_state->block_list)) != NULL) {
         send_blk(f, blk);
 
-        tmp = blk->next;
+        QSIMPLEQ_REMOVE_HEAD(&block_mig_state->block_list, entries);
         qemu_free(blk->buf);
         qemu_free(blk);
 
         block_mig_state->read_done--;
         block_mig_state->transferred++;
         assert(block_mig_state->read_done >= 0);
-    }
-    block_mig_state->first_blk = blk;
-
-    if (block_mig_state->first_blk == NULL) {
-        block_mig_state->last_blk = NULL;
+        if (qemu_file_rate_limit(f)) {
+            break;
+        }
     }
 
     dprintf("%s Exit submitted %d read_done %d transferred%d\n", __FUNCTION__,
@@ -402,7 +385,7 @@  static int is_stage2_completed(void)
         return 0;
     }
 
-    for (bmds = block_mig_state->bmds_first; bmds != NULL; bmds = bmds->next) {
+    QSIMPLEQ_FOREACH(bmds, &block_mig_state->bmds_list, entries) {
         if (bmds->bulk_completed == 0) {
             return 0;
         }
@@ -541,6 +524,8 @@  void blk_mig_info(void)
 void blk_mig_init(void)
 {
     block_mig_state = qemu_mallocz(sizeof(BlkMigState));
+    QSIMPLEQ_INIT(&block_mig_state->block_list);
+    QSIMPLEQ_INIT(&block_mig_state->bmds_list);
 
     register_savevm_live("block", 0, 1, block_set_params, block_save_live,
                          NULL, block_load, block_mig_state);
diff --git a/block-migration.h b/block-migration.h
index 9961abd..2d6a3cc 100644
--- a/block-migration.h
+++ b/block-migration.h
@@ -18,7 +18,7 @@  typedef struct BlkMigDevState {
     BlockDriverState *bs;
     int bulk_completed;
     int shared_base;
-    struct BlkMigDevState *next;
+    QSIMPLEQ_ENTRY(BlkMigDevState) entries;
     int64_t cur_sector;
     int64_t total_sectors;
     int64_t dirty;