* [Qemu-devel] [patch 0/5] block migration interaction fixes
@ 2011-01-26 14:12 Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 1/5] block-migration: actually disable dirty tracking on cleanup Marcelo Tosatti
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2011-01-26 14:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf
See individual patches for details.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [patch 1/5] block-migration: actually disable dirty tracking on cleanup
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
@ 2011-01-26 14:12 ` Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 2/5] blockdev: add refcount to DriveInfo Marcelo Tosatti
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2011-01-26 14:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Marcelo Tosatti
[-- Attachment #1: 00-fix-dirty-log-disable --]
[-- Type: text/plain, Size: 739 bytes --]
Call to set_dirty_tracking() is misplaced.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu/block-migration.c
===================================================================
--- qemu.orig/block-migration.c
+++ qemu/block-migration.c
@@ -528,6 +528,8 @@ static void blk_mig_cleanup(Monitor *mon
BlkMigDevState *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 *mon
qemu_free(blk);
}
- set_dirty_tracking(0);
-
monitor_printf(mon, "\n");
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [patch 2/5] blockdev: add refcount to DriveInfo
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 1/5] block-migration: actually disable dirty tracking on cleanup Marcelo Tosatti
@ 2011-01-26 14:12 ` Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 3/5] block-migration: add reference to target DriveInfo Marcelo Tosatti
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2011-01-26 14:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Marcelo Tosatti, Markus Armbruster
[-- Attachment #1: 01-driveinfo-ref --]
[-- Type: text/plain, Size: 2628 bytes --]
The 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.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -40,7 +40,7 @@ void blockdev_auto_del(BlockDriverState
DriveInfo *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 *opaq
fprintf(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);
Index: qemu/blockdev.h
===================================================================
--- qemu.orig/blockdev.h
+++ qemu/blockdev.h
@@ -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);
Index: qemu/hw/pci-hotplug.c
===================================================================
--- qemu.orig/hw/pci-hotplug.c
+++ qemu/hw/pci-hotplug.c
@@ -146,7 +146,7 @@ void drive_hot_add(Monitor *mon, const Q
err:
if (dinfo)
- drive_uninit(dinfo);
+ drive_put_ref(dinfo);
return;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [patch 3/5] block-migration: add reference to target DriveInfo
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 1/5] block-migration: actually disable dirty tracking on cleanup Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 2/5] blockdev: add refcount to DriveInfo Marcelo Tosatti
@ 2011-01-26 14:12 ` Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 4/5] Add flag to indicate external users to block device Marcelo Tosatti
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2011-01-26 14:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Marcelo Tosatti, Markus Armbruster
[-- Attachment #1: 02-block-migration-use-drive-ref --]
[-- Type: text/plain, Size: 1196 bytes --]
So that ejection of attached device by guest does not free data
in use by block migration instance.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
Index: qemu/block-migration.c
===================================================================
--- qemu.orig/block-migration.c
+++ qemu/block-migration.c
@@ -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 *mon
while ((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);
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [patch 4/5] Add flag to indicate external users to block device
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
` (2 preceding siblings ...)
2011-01-26 14:12 ` [Qemu-devel] [patch 3/5] block-migration: add reference to target DriveInfo Marcelo Tosatti
@ 2011-01-26 14:12 ` Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 5/5] block: enable in_use flag Marcelo Tosatti
2011-02-07 11:27 ` [Qemu-devel] Re: [patch 0/5] block migration interaction fixes Kevin Wolf
5 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2011-01-26 14:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Marcelo Tosatti
[-- Attachment #1: 03-driveinfo-inuse --]
[-- Type: text/plain, Size: 1673 bytes --]
Certain 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.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -2770,6 +2770,17 @@ int64_t bdrv_get_dirty_count(BlockDriver
return 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)
Index: qemu/block_int.h
===================================================================
--- qemu.orig/block_int.h
+++ qemu/block_int.h
@@ -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;
};
Index: qemu/block.h
===================================================================
--- qemu.orig/block.h
+++ qemu/block.h
@@ -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,
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [patch 5/5] block: enable in_use flag
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
` (3 preceding siblings ...)
2011-01-26 14:12 ` [Qemu-devel] [patch 4/5] Add flag to indicate external users to block device Marcelo Tosatti
@ 2011-01-26 14:12 ` Marcelo Tosatti
2011-02-07 11:27 ` [Qemu-devel] Re: [patch 0/5] block migration interaction fixes Kevin Wolf
5 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2011-01-26 14:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Marcelo Tosatti
[-- Attachment #1: 04-driveinfo-use-inuse --]
[-- Type: text/plain, Size: 1880 bytes --]
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>
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);
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] Re: [patch 0/5] block migration interaction fixes
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
` (4 preceding siblings ...)
2011-01-26 14:12 ` [Qemu-devel] [patch 5/5] block: enable in_use flag Marcelo Tosatti
@ 2011-02-07 11:27 ` Kevin Wolf
5 siblings, 0 replies; 7+ messages in thread
From: Kevin Wolf @ 2011-02-07 11:27 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: qemu-devel
Am 26.01.2011 15:12, schrieb Marcelo Tosatti:
> See individual patches for details.
Thanks, applied all to the block branch.
Kevin
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-02-07 11:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-26 14:12 [Qemu-devel] [patch 0/5] block migration interaction fixes Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 1/5] block-migration: actually disable dirty tracking on cleanup Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 2/5] blockdev: add refcount to DriveInfo Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 3/5] block-migration: add reference to target DriveInfo Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 4/5] Add flag to indicate external users to block device Marcelo Tosatti
2011-01-26 14:12 ` [Qemu-devel] [patch 5/5] block: enable in_use flag Marcelo Tosatti
2011-02-07 11:27 ` [Qemu-devel] Re: [patch 0/5] block migration interaction fixes Kevin Wolf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.