From 73176bee9918a3738237b0e06eff72b497283869 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 7 Mar 2016 13:02:15 +0100 Subject: block: Fix snapshot=on cache modes Since commit 91a097e, we end up with a somewhat weird cache mode configuration with snapshot=on: The commit broke the cache mode inheritance for the snapshot overlay so that it is opened as writethrough instead of unsafe now. The following bdrv_append() call to put it on top of the tree swaps the WCE flag with the snapshot's backing file (i.e. the originally given file), so what we eventually get is cache=writeback on the temporary overlay and cache=writethrough,cache.no-flush=on on the real image file. This patch changes things so that the temporary overlay gets cache=unsafe again like it used to, and the real images get whatever the user specified. This means that cache.direct is now respected even with snapshot=on, and in the case of committing changes, the final flush is no longer ignored except explicitly requested by the user. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/block.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 1c4f4d8141..3900c4d8c3 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -215,7 +215,6 @@ BdrvChild *bdrv_open_child(const char *filename, void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd); int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, const char *bdref_key, Error **errp); -int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp); int bdrv_open(BlockDriverState **pbs, const char *filename, const char *reference, QDict *options, int flags, Error **errp); BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, -- cgit v1.2.3 From abb21ac3e602430bd7a35e88ecc2eb62c91c7b42 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 23 Feb 2016 17:33:24 +0100 Subject: hmp: 'drive_add -n' for creating a node without BB This patch adds an option to the drive_add HMP command to create only a BlockDriverState without a BlockBackend on top. The motivation for this is that libvirt needs to specify options to a migration target (specifically, detect-zeroes). drive-mirror doesn't allow specifying options, and the proper way to do this is to create the target BDS separately with blockdev-add (where you can specify options) and then use blockdev-mirror to that BDS. However, libvirt can't use blockdev-add as long as it is still experimental, and we're expecting that it will still take some time, so we need to resort to drive_add. The problem with drive_add is that so far it always created a BB, and BDSes with a BB can't be used as a mirroring target as long as we don't support multiple BBs per BDS - and while we're working towards that goal, it's another thing that will still take some time. So to achieve the goal, the simplest solution to provide the functionality now without adding one-off options to the mirror QMP commands is to extend drive_add to create nodes without BBs. Signed-off-by: Kevin Wolf --- include/block/block_int.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/block/block_int.h b/include/block/block_int.h index 9ef823a660..dda5ba0927 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -694,6 +694,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, BlockCompletionFunc *cb, void *opaque, BlockJobTxn *txn, Error **errp); +void hmp_drive_add_node(Monitor *mon, const char *optstr); + void blk_set_bs(BlockBackend *blk, BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load); -- cgit v1.2.3 From c10c9d96158ce4d05f4325e64c0ce6a5fcd64b8b Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 8 Mar 2016 16:39:49 +0100 Subject: block: Introduce blk_set_allow_write_beyond_eof() We check that the guest can't write beyond the end of its disk, but for other internal users it can make sense to allow growing a file. Signed-off-by: Kevin Wolf --- include/sysemu/block-backend.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 66c5cf22e1..00d69baa07 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -78,6 +78,7 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk); +void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); void blk_iostatus_enable(BlockBackend *blk); bool blk_iostatus_is_enabled(const BlockBackend *blk); BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk); -- cgit v1.2.3 From 78f9dc859d2db4c3bad382e09e0935bf959d07a6 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 8 Mar 2016 12:44:53 +0800 Subject: block: Include hbitmap.h in block.h Signed-off-by: Fam Zheng Reviewed-by: John Snow Message-id: 1457412306-18940-3-git-send-email-famz@redhat.com Signed-off-by: Max Reitz --- include/block/block.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 3900c4d8c3..66c55ea77b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -8,6 +8,7 @@ #include "block/accounting.h" #include "qapi/qmp/qobject.h" #include "qapi-types.h" +#include "qemu/hbitmap.h" /* block.c */ typedef struct BlockDriver BlockDriver; @@ -474,7 +475,6 @@ void *qemu_try_blockalign(BlockDriverState *bs, size_t size); void *qemu_try_blockalign0(BlockDriverState *bs, size_t size); bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov); -struct HBitmapIter; typedef struct BdrvDirtyBitmap BdrvDirtyBitmap; BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, uint32_t granularity, -- cgit v1.2.3 From 9a3f5cf1bfd2b1e11a496bdaf038cc7d825e01df Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 8 Mar 2016 12:44:54 +0800 Subject: typedefs: Add BdrvDirtyBitmap Following patches to refactor and move block dirty bitmap code could use this. Signed-off-by: Fam Zheng Reviewed-by: John Snow Message-id: 1457412306-18940-4-git-send-email-famz@redhat.com Signed-off-by: Max Reitz --- include/block/block.h | 1 - include/qemu/typedefs.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 66c55ea77b..a4031765ea 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -475,7 +475,6 @@ void *qemu_try_blockalign(BlockDriverState *bs, size_t size); void *qemu_try_blockalign0(BlockDriverState *bs, size_t size); bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov); -typedef struct BdrvDirtyBitmap BdrvDirtyBitmap; BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, uint32_t granularity, const char *name, diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 9a5ead69a1..fd039e0e81 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -10,6 +10,7 @@ typedef struct AddressSpace AddressSpace; typedef struct AioContext AioContext; typedef struct AllwinnerAHCIState AllwinnerAHCIState; typedef struct AudioState AudioState; +typedef struct BdrvDirtyBitmap BdrvDirtyBitmap; typedef struct BlockBackend BlockBackend; typedef struct BlockBackendRootState BlockBackendRootState; typedef struct BlockDriverState BlockDriverState; -- cgit v1.2.3 From ebab225910d7bb3d805176ff89b5efc5f18653c3 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 8 Mar 2016 12:44:55 +0800 Subject: block: Move block dirty bitmap code to separate files The only code change is making bdrv_dirty_bitmap_truncate public. It is used in block.c. Also two long lines (bdrv_get_dirty) are wrapped. Signed-off-by: Fam Zheng Reviewed-by: John Snow Message-id: 1457412306-18940-5-git-send-email-famz@redhat.com Signed-off-by: Max Reitz --- include/block/block.h | 35 +---------------------------------- include/block/dirty-bitmap.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 include/block/dirty-bitmap.h (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index a4031765ea..9688d7f421 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -6,6 +6,7 @@ #include "qemu/option.h" #include "qemu/coroutine.h" #include "block/accounting.h" +#include "block/dirty-bitmap.h" #include "qapi/qmp/qobject.h" #include "qapi-types.h" #include "qemu/hbitmap.h" @@ -475,40 +476,6 @@ void *qemu_try_blockalign(BlockDriverState *bs, size_t size); void *qemu_try_blockalign0(BlockDriverState *bs, size_t size); bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov); -BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, - uint32_t granularity, - const char *name, - Error **errp); -int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs, - BdrvDirtyBitmap *bitmap, - Error **errp); -BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs, - BdrvDirtyBitmap *bitmap, - Error **errp); -BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, - BdrvDirtyBitmap *bitmap, - Error **errp); -BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, - const char *name); -void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap); -void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); -void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); -void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); -BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); -uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); -uint32_t bdrv_dirty_bitmap_granularity(BdrvDirtyBitmap *bitmap); -bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); -bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap); -DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap); -int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector); -void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, - int64_t cur_sector, int nr_sectors); -void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, - int64_t cur_sector, int nr_sectors); -void bdrv_dirty_iter_init(BdrvDirtyBitmap *bitmap, struct HBitmapIter *hbi); -void bdrv_set_dirty_iter(struct HBitmapIter *hbi, int64_t offset); -int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); - void bdrv_enable_copy_on_read(BlockDriverState *bs); void bdrv_disable_copy_on_read(BlockDriverState *bs); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h new file mode 100644 index 0000000000..80afe603f6 --- /dev/null +++ b/include/block/dirty-bitmap.h @@ -0,0 +1,44 @@ +#ifndef BLOCK_DIRTY_BITMAP_H +#define BLOCK_DIRTY_BITMAP_H + +#include "qemu-common.h" +#include "qemu/hbitmap.h" + +BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, + uint32_t granularity, + const char *name, + Error **errp); +int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); +BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); +BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); +BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, + const char *name); +void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap); +void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); +void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); +void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); +void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); +BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); +uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); +uint32_t bdrv_dirty_bitmap_granularity(BdrvDirtyBitmap *bitmap); +bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); +bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap); +DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap); +int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, + int64_t sector); +void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int nr_sectors); +void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int nr_sectors); +void bdrv_dirty_iter_init(BdrvDirtyBitmap *bitmap, struct HBitmapIter *hbi); +void bdrv_set_dirty_iter(struct HBitmapIter *hbi, int64_t offset); +int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); +void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); + +#endif -- cgit v1.2.3 From fcce736719d04effab3d9a07d29ab4cecaf841dd Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 8 Mar 2016 12:44:56 +0800 Subject: block: Remove unused typedef of BlockDriverDirtyHandler Signed-off-by: Fam Zheng Reviewed-by: John Snow Message-id: 1457412306-18940-6-git-send-email-famz@redhat.com Signed-off-by: Max Reitz --- include/block/block.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 9688d7f421..eaa64262d9 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -321,8 +321,6 @@ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp); /* async block I/O */ -typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector, - int sector_num); BlockAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *iov, int nb_sectors, BlockCompletionFunc *cb, void *opaque); -- cgit v1.2.3