Patchwork [5/5] block: enable in_use flag

login
register
mail settings
Submitter Marcelo Tosatti
Date Jan. 26, 2011, 2:12 p.m.
Message ID <20110126141348.365483427@redhat.com>
Download mbox | patch
Permalink /patch/80508/
State New
Headers show

Comments

Marcelo Tosatti - Jan. 26, 2011, 2:12 p.m.
Set block device in use during block migration, disallow drive_del and
bdrv_truncate for in use devices.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Patch

Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -690,6 +690,10 @@  int do_drive_del(Monitor *mon, const QDi
         qerror_report(QERR_DEVICE_NOT_FOUND, id);
         return -1;
     }
+    if (bdrv_in_use(bs)) {
+        qerror_report(QERR_DEVICE_IN_USE, id);
+        return -1;
+    }
 
     /* quiesce block driver; prevent further io */
     qemu_aio_flush();
Index: qemu/block-migration.c
===================================================================
--- qemu.orig/block-migration.c
+++ qemu/block-migration.c
@@ -301,6 +301,7 @@  static void init_blk_migration_it(void *
         bmds->shared_base = block_mig_state.shared_base;
         alloc_aio_bitmap(bmds);
         drive_get_ref(drive_get_by_blockdev(bs));
+        bdrv_set_in_use(bs, 1);
 
         block_mig_state.total_sector_sum += sectors;
 
@@ -534,6 +535,7 @@  static void blk_mig_cleanup(Monitor *mon
 
     while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
         QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry);
+        bdrv_set_in_use(bmds->bs, 0);
         drive_put_ref(drive_get_by_blockdev(bmds->bs));
         qemu_free(bmds->aio_bitmap);
         qemu_free(bmds);
Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -1132,6 +1132,8 @@  int bdrv_truncate(BlockDriverState *bs, 
         return -ENOTSUP;
     if (bs->read_only)
         return -EACCES;
+    if (bdrv_in_use(bs))
+        return -EBUSY;
     ret = drv->bdrv_truncate(bs, offset);
     if (ret == 0) {
         ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);