Patchwork [21/26] FVD: add impl of interface bdrv_close()

login
register
mail settings
Submitter Chunqiang Tang
Date Feb. 25, 2011, 10:38 p.m.
Message ID <1298673486-3573-21-git-send-email-ctang@us.ibm.com>
Download mbox | patch
Permalink /patch/84580/
State New
Headers show

Comments

Chunqiang Tang - Feb. 25, 2011, 10:38 p.m.
This patch is part of the Fast Virtual Disk (FVD) proposal.
See http://wiki.qemu.org/Features/FVD.

This patch adds FVD's implementation of the bdrv_close() interface.

Signed-off-by: Chunqiang Tang <ctang@us.ibm.com>
---
 block/fvd-misc.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)

Patch

diff --git a/block/fvd-misc.c b/block/fvd-misc.c
index c515d74..63ed168 100644
--- a/block/fvd-misc.c
+++ b/block/fvd-misc.c
@@ -81,6 +81,84 @@  static void fvd_aio_cancel(BlockDriverAIOCB * blockacb)
 
 static void fvd_close(BlockDriverState * bs)
 {
+    BDRVFvdState *s = bs->opaque;
+    FvdAIOCB *acb;
+    int i;
+
+    if (s->prefetch_state == PREFETCH_STATE_RUNNING) {
+        s->prefetch_state = PREFETCH_STATE_DISABLED;
+    }
+    if (s->prefetch_timer) {
+        qemu_del_timer(s->prefetch_timer);
+        qemu_free_timer(s->prefetch_timer);
+        s->prefetch_timer = NULL;
+    }
+
+    if (s->prefetch_acb) {
+        /* Clean up prefetch operations. */
+        for (i = 0; i < s->num_prefetch_slots; i++) {
+            if (s->prefetch_acb[i] != NULL) {
+                fvd_aio_cancel_copy(s->prefetch_acb[i]);
+                s->prefetch_acb[i] = NULL;
+            }
+        }
+        my_qemu_free(s->prefetch_acb);
+        s->prefetch_acb = NULL;
+    }
+
+    if (s->use_bjnl) {
+        /* Clean up buffered journal update. */
+        bjnl_sync_flush(bs);
+        if (s->bjnl.timer_scheduled) {
+            qemu_del_timer(s->bjnl.clean_buf_timer);
+        }
+        qemu_free_timer(s->bjnl.clean_buf_timer);
+    }
+
+    /* Clean up unfinished copy_on_read operations. */
+    QLIST_FOREACH(acb, &s->copy_locks, copy_lock.next) {
+        fvd_aio_cancel_copy(acb);
+    }
+
+    flush_metadata_to_disk_on_exit(bs);
+
+    if (s->stale_bitmap) {
+        my_qemu_vfree(s->stale_bitmap);
+        if (s->fresh_bitmap != s->stale_bitmap) {
+            my_qemu_vfree(s->fresh_bitmap);
+        }
+        s->stale_bitmap = NULL;
+        s->fresh_bitmap = NULL;
+    }
+
+    if (s->table) {
+        my_qemu_vfree(s->table);
+        s->table = NULL;
+    }
+
+    if (s->fvd_metadata) {
+        if (s->fvd_metadata != s->fvd_data) {
+            bdrv_delete(s->fvd_metadata);
+        }
+        s->fvd_metadata = NULL;
+    }
+    if (s->fvd_data) {
+        bdrv_delete(s->fvd_data);
+        s->fvd_data = NULL;
+    }
+
+    if (s->add_storage_cmd) {
+        my_qemu_free(s->add_storage_cmd);
+        s->add_storage_cmd = NULL;
+    }
+
+    if (s->leaked_chunks) {
+        my_qemu_free(s->leaked_chunks);
+        s->leaked_chunks = NULL;
+    }
+#ifdef FVD_DEBUG
+    dump_resource_summary(s);
+#endif
 }
 
 static int fvd_probe(const uint8_t * buf, int buf_size, const char *filename)