block migration interaction fixes
cover block migration interaction fixes
See individual patches for details.
PATCH 1/5 block-migration: actually disable dirty tracking on cleanup
Call to set_dirty_tracking() is misplaced.
block-migration.c +2 -2
@@ -528,6 +528,8 @@ static void blk_mig_cleanup(Monitor *monBlkMigDevState *bmds;BlkMigBlock *blk; +set_dirty_tracking (0 ); +while ((bmds =QSIMPLEQ_FIRST (&block_mig_state.bmds_list)) !=NULL ) {QSIMPLEQ_REMOVE_HEAD (&block_mig_state.bmds_list, entry);qemu_free (bmds->aio_bitmap);
@@ -540,8 +542,6 @@ static void blk_mig_cleanup(Monitor *monqemu_free (blk); } -set_dirty_tracking (0 ); -monitor_printf (mon,"\n" ); }
PATCH 2/5 blockdev: add refcount to DriveInfo
In reply to Marcelo TosattiThe host part of a block device can be deleted with in progress block migration.
To fix this, add a reference count to DriveInfo, freeing resources on last reference.
blockdev.c +16 -2
@@ -40,7 +40,7 @@ void blockdev_auto_del(BlockDriverStateDriveInfo *dinfo =drive_get_by_blockdev (bs);if (dinfo && dinfo->auto_del) { -drive_uninit (dinfo); +drive_put_ref (dinfo); } }
@@ -110,7 +110,7 @@ static void bdrv_format_print(void *opaqfprintf (stderr," %s" , name); } -void drive_uninit (DriveInfo *dinfo) +static void drive_uninit (DriveInfo *dinfo) {qemu_opts_del (dinfo->opts);bdrv_delete (dinfo->bdrv);
@@ -118,6 +118,19 @@ void drive_uninit(DriveInfo *dinfo)qemu_free (dinfo); } +void drive_put_ref (DriveInfo *dinfo) +{ +assert (dinfo->refcount); +if (--dinfo->refcount ==0 ) { +drive_uninit (dinfo); + } +} + +void drive_get_ref (DriveInfo *dinfo) +{ + dinfo->refcount++; +} +static int parse_block_error_action (const char *buf,int is_read) {if (!strcmp (buf,"ignore" )) {
@@ -421,6 +434,7 @@ DriveInfo *drive_init(QemuOpts *opts, in dinfo->bus = bus_id; dinfo->unit = unit_id; dinfo->opts = opts; + dinfo->refcount =1 ;if (serial)strncpy (dinfo->serial, serial,sizeof (dinfo->serial) -1 );QTAILQ_INSERT_TAIL (&drives, dinfo, next);
blockdev.h +3 -1
@@ -29,6 +29,7 @@ struct DriveInfo {QemuOpts *opts;char serial[BLOCK_SERIAL_STRLEN +1 ];QTAILQ_ENTRY (DriveInfo) next; +int refcount; };#define MAX_IDE_DEVS 2
@@ -36,7 +37,8 @@ struct DriveInfo {DriveInfo *drive_get (BlockInterfaceType type,int bus,int unit);int drive_get_max_bus (BlockInterfaceType type); -void drive_uninit (DriveInfo *dinfo); +void drive_get_ref (DriveInfo *dinfo); +void drive_put_ref (DriveInfo *dinfo);DriveInfo *drive_get_by_blockdev (BlockDriverState *bs);QemuOpts *drive_add (const char *file,const char *fmt, ...)GCC_FMT_ATTR (2 ,3 );
hw/pci-hotplug.c +1 -1
@@ -146,7 +146,7 @@ void drive_hot_add(Monitor *mon, const Q err:if (dinfo) -drive_uninit (dinfo); +drive_put_ref (dinfo);return ; }
PATCH 3/5 block-migration: add reference to target DriveInfo
In reply to Marcelo TosattiSo that ejection of attached device by guest does not free data in use by block migration instance.
block-migration.c +3 -0
@@ -19,6 +19,7 @@#include "monitor.h" #include "block-migration.h" #include "migration.h" +#include "blockdev.h" #include <assert.h> #define BLOCK_SIZE (BDRV_SECTORS_PER_DIRTY_CHUNK << BDRV_SECTOR_BITS)
@@ -299,6 +300,7 @@ static void init_blk_migration_it(void * bmds->completed_sectors =0 ; bmds->shared_base = block_mig_state.shared_base;alloc_aio_bitmap (bmds); +drive_get_ref (drive_get_by_blockdev (bs)); block_mig_state.total_sector_sum += sectors;
@@ -532,6 +534,7 @@ static void blk_mig_cleanup(Monitor *monwhile ((bmds =QSIMPLEQ_FIRST (&block_mig_state.bmds_list)) !=NULL ) {QSIMPLEQ_REMOVE_HEAD (&block_mig_state.bmds_list, entry); +drive_put_ref (drive_get_by_blockdev (bmds->bs));qemu_free (bmds->aio_bitmap);qemu_free (bmds); }
PATCH 4/5 Add flag to indicate external users to block device
In reply to Marcelo TosattiCertain operations such as drive_del or resize cannot be performed while external users (eg. block migration) reference the block device.
Add a flag to indicate that.
block.c +11 -0
@@ -2770,6 +2770,17 @@ int64_t bdrv_get_dirty_count(BlockDriverreturn bs->dirty_count; } +void bdrv_set_in_use (BlockDriverState *bs,int in_use) +{ +assert (bs->in_use != in_use); + bs->in_use = in_use; +} + +int bdrv_in_use (BlockDriverState *bs) +{ +return bs->in_use; +} +int bdrv_img_create (const char *filename,const char *fmt,const char *base_filename,const char *base_fmt,char *options,uint64_t img_size,int flags)
block_int.h +1 -0
@@ -199,6 +199,7 @@ struct BlockDriverState {char device_name[32 ];unsigned long *dirty_bitmap;int64_t dirty_count; +int in_use;/* users other than guest access, eg. block migration */ QTAILQ_ENTRY (BlockDriverState) list;void *private; };
block.h +2 -0
@@ -240,6 +240,8 @@ void bdrv_reset_dirty(BlockDriverState * int nr_sectors);int64_t bdrv_get_dirty_count (BlockDriverState *bs); +void bdrv_set_in_use (BlockDriverState *bs,int in_use); +int bdrv_in_use (BlockDriverState *bs); typedef enum { BLKDBG_L1_UPDATE,
PATCH 5/5 block: enable in_use flag
In reply to Marcelo TosattiSet block device in use during block migration, disallow drive_del and bdrv_truncate for in use devices.
blockdev.c +4 -0
@@ -690,6 +690,10 @@ int do_drive_del(Monitor *mon, const QDiqerror_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 ();
block-migration.c +2 -0
@@ -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 *monwhile ((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);
block.c +2 -0
@@ -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 );
Kevin Wolf
AppliedAm 26.01.2011 15:12, schrieb Marcelo Tosatti:
Quoted 1 line
See individual patches for details.
Thanks, applied all to the block branch.
Kevin