Block layer patches
[Qemu-devel] [PULL 01/48] block: Remove bdrv_make_anon()
In reply to Kevin WolfThe call in hmp_drive_del() is dead code because blk_remove_bs() is called a few lines above. The only other remaining user is bdrv_delete(), which only abuses bdrv_make_anon() to remove it from the named nodes list. This path inlines the list entry removal into bdrv_delete() and removes bdrv_make_anon().
--- block.c | 15 +++------------ blockdev.c | 3 --- include/block/block.h | 1 - 3 files changed, 3 insertions(+), 16 deletions(-)
block.c +3 -12
@@ -2241,16 +2241,6 @@ void bdrv_close_all(void) } } -/* make a BlockDriverState anonymous by removing from graph_bdrv_state list. -* Also, NULL terminate the device_name to prevent double remove */ -void bdrv_make_anon (BlockDriverState *bs) -{ -if (bs->node_name[0 ] !='\0' ) { -QTAILQ_REMOVE (&graph_bdrv_states, bs, node_list); - } - bs->node_name[0 ] ='\0' ; -} -/* Fields that need to stay with the top-level BDS */ static void bdrv_move_feature_fields (BlockDriverState *bs_dest,BlockDriverState *bs_src)
@@ -2380,8 +2370,9 @@ static void bdrv_delete(BlockDriverState *bs)bdrv_close (bs);/* remove from list, if necessary */ -bdrv_make_anon (bs); - +if (bs->node_name[0 ] !='\0' ) { +QTAILQ_REMOVE (&graph_bdrv_states, bs, node_list); + }QTAILQ_REMOVE (&all_bdrv_states, bs, bs_list);g_free (bs);
blockdev.c +0 -3
@@ -2867,9 +2867,6 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict)/* Make the BlockBackend and the attached BlockDriverState anonymous */ monitor_remove_blk (blk); -if (blk_bs (blk)) { -bdrv_make_anon (blk_bs (blk)); - }/* If this BlockBackend has a device attached to it, its refcount will be * decremented when the device is removed; otherwise we have to do so here.
include/block/block.h +0 -1
@@ -201,7 +201,6 @@ int bdrv_create(BlockDriver *drv, const char* filename,int bdrv_create_file (const char *filename,QemuOpts *opts,Error **errp);BlockDriverState *bdrv_new_root (void );BlockDriverState *bdrv_new (void ); -void bdrv_make_anon (BlockDriverState *bs);void bdrv_append (BlockDriverState *bs_new,BlockDriverState *bs_top);void bdrv_replace_in_backing_chain (BlockDriverState *old,BlockDriverState *new);
Signature · 1 line
1.8.3.1
The following changes since commit b68a80139e37e806f004237e55311ebc42151434:
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20160324' into staging (2016-03-24 16:24:02 +0000)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to b63f2a6772ca774ec58b2fc6e26fdeeda44a99c1:
iotests: Test qemu-img convert -S 0 behavior (2016-03-29 16:30:13 +0200)
----------------------------------------------------------------
Block layer patches
----------------------------------------------------------------
Daniel P. Berrange (8):
block: add flag to indicate that no I/O will be performed qemu-img/qemu-io: don't prompt for passwords if not required
tests: redirect stderr to stdout for iotests
tests: refactor python I/O tests helper main method
tests: add output filter to python I/O tests helper
block: add generic full disk encryption driver
block: move encryption deprecation warning into qcow code
block: an interoperability test for luks vs dm-crypt/cryptsetup
Kevin Wolf (27):
block: Remove bdrv_make_anon()
block: Remove copy-on-read from bdrv_move_feature_fields()
block: Remove dirty bitmaps from bdrv_move_feature_fields()
block: Remove cache.writeback from blockdev-add
block: Make backing files always writeback
block: Reject writethrough mode except at the root
block: Remove blk_set_bs()
block: Add bdrv_parse_cache_mode()
qemu-nbd: Call blk_set_enable_write_cache() explicitly
qemu-io: Call blk_set_enable_write_cache() explicitly
qemu-img: Expand all BDRV_O_FLAGS uses
qemu-img: Call blk_set_enable_write_cache() explicitly
xen_disk: Call blk_set_enable_write_cache() explicitly
block: blockdev_init(): Call blk_set_enable_write_cache() explicitly
block: Always set writeback mode in blk_new_open()
block: Handle flush error in bdrv_pwrite_sync()
block: Move enable_write_cache to BB level
block/qapi: Use blk_enable_write_cache()
block: Introduce bdrv_co_writev_flags()
iscsi: Support BDRV_REQ_FUA
nbd: Support BDRV_REQ_FUA
raw: Support BDRV_REQ_FUA
block: Use bdrv_parse_cache_mode() in drive_init()
qemu-io: Use bdrv_parse_cache_mode() in reopen_f()
block: Remove bdrv_parse_cache_flags()
block: Remove BDRV_O_CACHE_WB
block: Remove bdrv_(set_)enable_write_cache()
Max Reitz (6):
block/qapi: Set s->device in bdrv_query_stats() block/qapi: Pass bdrv_query_blk_stats() s->stats
qemu-img: Fix preallocation with -S 0 for convert block/null-{co,aio}: Allow reading zeroes block/null-{co,aio}: Implement get_block_status()
iotests: Test qemu-img convert -S 0 behavior
Pavel Dovgalyuk (4):
block: add flush callback
replay: bh scheduling fix
replay: fix error message
replay: introduce block devices record/replay
Peter Xu (2):
block/qapi: make two printf() formats literal block/qapi: fix unbounded stack for dump_qdict
Programmingkid (1):
block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host
block.c | 111 +-- block/Makefile.objs | 4 +- block/backup.c | 1 - block/blkreplay.c | 159 ++++ block/block-backend.c | 62 +- block/crypto.c | 585 +++++++++++++ block/io.c | 24 +- block/iscsi.c | 30 +- block/mirror.c | 1 - block/nbd-client.c | 13 +- block/nbd-client.h | 2 +- block/nbd.c | 27 +- block/null.c | 42 + block/parallels.c | 3 +- block/qapi.c | 75 +- block/qcow.c | 12 +- block/qcow2.c | 17 +- block/qed.c | 3 +- block/raw-posix.c | 165 +++- block/raw_bsd.c | 17 +- block/sheepdog.c | 5 +- block/vdi.c | 3 +- block/vhdx.c | 3 +- block/vmdk.c | 8 +- block/vpc.c | 3 +- block/vvfat.c | 3 +- blockdev.c | 26 +- docs/replay.txt | 20 + hw/block/xen_disk.c | 5 +- include/block/block.h | 11 +- include/block/block_int.h | 17 +- include/block/qapi.h | 3 +- include/sysemu/replay.h | 2 + qapi/block-core.json | 26 +- qemu-img.c | 120 +-- qemu-io-cmds.c | 13 +- qemu-io.c | 23 +- qemu-nbd.c | 5 +- replay/replay-events.c | 24 +- replay/replay-internal.h | 1 + replay/replay.c | 2 +- stubs/replay.c | 4 + tests/qemu-iotests/049.out | 6 - tests/qemu-iotests/051 | 2 +- tests/qemu-iotests/051.pc.out | 10 +- tests/qemu-iotests/087 | 3 +- tests/qemu-iotests/087.out | 26 +- tests/qemu-iotests/122.out | 6 +- tests/qemu-iotests/134.out | 18 - tests/qemu-iotests/142 | 63 +- tests/qemu-iotests/142.out | 175 ++-- tests/qemu-iotests/149 | 519 ++++++++++++ tests/qemu-iotests/149.out | 1880 +++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/150 | 105 +++ tests/qemu-iotests/150.out | 14 + tests/qemu-iotests/common | 1 + tests/qemu-iotests/group | 2 + tests/qemu-iotests/iotests.py | 48 +- 58 files changed, 4013 insertions(+), 545 deletions(-) create mode 100755 block/blkreplay.c create mode 100644 block/crypto.c create mode 100755 tests/qemu-iotests/149 create mode 100644 tests/qemu-iotests/149.out create mode 100755 tests/qemu-iotests/150 create mode 100644 tests/qemu-iotests/150.out
[Qemu-devel] [PULL 04/48] block: Remove cache.writeback from blockdev-add
The WCE bit is a frontend property and should not be part of the backend configuration. This is especially important because the same BDS can be used by different users with different WCE requirements.
--- qapi/block-core.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
qapi/block-core.json +1 -3
@@ -1614,7 +1614,6 @@ # # Includes cache-related options for block devices # -# @writeback: #optional enables writeback mode for any caches (default: true) # @direct: #optional enables use of O_DIRECT (bypass the host page cache; # default: false) # @no-flush: #optional ignore any flush requests for the device (default:
@@ -1623,8 +1622,7 @@ # Since: 1.7 ## { 'struct': 'BlockdevCacheOptions', - 'data': { '*writeback': 'bool', - '*direct': 'bool', + 'data': { '*direct': 'bool', '*no-flush': 'bool' } } ##
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/48] block: Remove copy-on-read from bdrv_move_feature_fields()
In reply to Kevin WolfEver since we first introduced bdrv_append() in commit 8802d1fd ('qapi:
Introduce blockdev-group-snapshot-sync command'), the copy-on-read flag was moved to the new top layer when taking a snapshot. The only problem is that it doesn't make a whole lot of sense.
The use case for manually enabled CoR is to avoid reading data twice from a slow remote image, so we want to save it to a local overlay, say an ISO image accessed via HTTP to a local qcow2 overlay. When taking a snapshot, we end up with a backing chain like this:
http <- local.qcow2 <- snap_overlay.qcow2
There is no point in doing CoR from local.qcow2 into snap_overlay.qcow2, we just want to keep copying data from the remote source into local.qcow2.
The other use case of CoR is in the context of streaming, which isn't very interesting for bdrv_move_feature_fields() because op blockers prevent this combination.
This patch makes the copy-on-read flag stay on the image for which it was originally set and prevents it from being propagated to the new overlay. It is no longer intended to move CoR to the BlockBackend level. In order for this to make sense, we also need to keep the respective image read-write.
As a side effect of these changes, creating a live snapshot image (as opposed to using an existing externally created one) on top of a COR block device works now. It used to fail because it tried to open its backing file both read-only and with COR.
--- block.c | 2 -- blockdev.c | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-)
block.c +0 -2
@@ -2248,8 +2248,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,/* move some fields that need to stay attached to the device */ /* dev info */ - bs_dest->copy_on_read = bs_src->copy_on_read; - bs_dest->enable_write_cache = bs_src->enable_write_cache;/* dirty bitmap */
blockdev.c +5 -2
@@ -1741,6 +1741,7 @@ static void external_snapshot_prepare(BlkActionState *common, } flags = state->old_bs->open_flags; + flags &= ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_COPY_ON_READ );/* create new image w/backing file */ mode = s->has_mode ? s->mode :NEW_IMAGE_MODE_ABSOLUTE_PATHS ;
@@ -1811,8 +1812,10 @@ static void external_snapshot_commit(BlkActionState *common)/* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ -bdrv_reopen (state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDWR , -NULL ); +if (!state->old_bs->copy_on_read) { +bdrv_reopen (state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDWR , +NULL ); + } }static void external_snapshot_abort (BlkActionState *common)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/48] block: Remove dirty bitmaps from bdrv_move_feature_fields()
In reply to Kevin WolfThis patch changes dirty bitmaps from following a BlockBackend in graph changes to sticking with the node they were created at. For the full discussion, read the following mailing list thread:
[Qemu-block] block: Dirty bitmaps and COR in bdrv_move_feature_fields()
https://lists.nongnu.org/archive/html/qemu-block/2016-02/msg00745.html
In summary, the justification for this change is:
* When moving the dirty bitmap to the top of the tree was introduced in bdrv_append() in commit a9fc4408, it didn't actually have any effect because there could never be a bitmap in use when bdrv_append() was called (op blockers would prevent this). This is still true today for all internal uses of dirty bitmaps.
* Support for user-defined dirty bitmaps was introduced in 2.4, but we discouraged users from using it because we didn't consider it ready yet.
Moreover, in 2.5, the bdrv_swap() removal introduced a bug that left dangling pointers if a dirty bitmap was present (the anchors of the dirty bitmap were swapped, but the back link in the first element wasn't updated), so it didn't even work correctly.
* block-dirty-bitmap-add takes an arbitrary node name, even if no BlockBackend is attached. This suggests that it is a node level operation and not a BlockBackend one. Consequently, there is no reason for dirty bitmaps to stay with a BlockBackend that was attached to the node they were created for.
* It was suggested that block-dirty-bitmap-add could track the node if a node name was specified, and track the BlockBackend if the device name was specified. This would however be inconsistent with other QMP commands. Commands that accept both device and node names currently interpret the device name just as an alias for the current root node of that BlockBackend.
* Dirty bitmaps have a name that is only unique amongst the bitmaps in a specific node. Moving bitmaps could lead to name clashes. Automatic renaming would involve too much magic.
* Persistent bitmaps are stored in a specific node. Moving them around automatically might be at least surprising, but it would probably also become a real problem because that would have to happen atomically without the management tool knowing of the operation.
At the end of the day it seems to be very clear that it was a mistake to include dirty bitmaps in bdrv_move_feature_fields(). The functionality of moving bitmaps and/or attaching them to a BlockBackend instead will probably be needed, but it should be done with a new explicit QMP command or option.
--- block.c | 3 --- 1 file changed, 3 deletions(-)
block.c +0 -3
@@ -2249,9 +2249,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,/* dev info */ bs_dest->enable_write_cache = bs_src->enable_write_cache; - -/* dirty bitmap */ - bs_dest->dirty_bitmaps = bs_src->dirty_bitmaps; } static void change_parent_backing_link(BlockDriverState *from,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/48] block: Make backing files always writeback
In reply to Kevin WolfFirst of all, we're generally not writing to backing files, but when we do, it's in the context of block jobs which know very well when to flush the image.
--- block.c | 5 +++-- tests/qemu-iotests/142.out | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-)
block.c +3 -2
@@ -737,8 +737,9 @@ static void bdrv_backing_options(int *child_flags, QDict *child_options, {int flags = parent_flags; -/* The cache mode is inherited unmodified for backing files */ -qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_WB ); +/* The cache mode is inherited unmodified for backing files; except WCE, +* which is only applied on the top level (BlockBackend) */ +qdict_set_default_str (child_options,BDRV_OPT_CACHE_WB ,"on" );qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_DIRECT );qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_NO_FLUSH );
tests/qemu-iotests/142.out +5 -5
@@ -62,7 +62,7 @@ cache.direct=on on backing-file cache.writeback=off on none0 Cache mode: writethrough Cache mode: writeback - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback cache.writeback=off on file
@@ -143,7 +143,7 @@ cache.writeback=off on none0 Cache mode: writethrough Cache mode: writethrough Cache mode: writeback - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback cache.writeback=off on file
@@ -302,7 +302,7 @@ cache.direct=on on backing-file cache.writeback=off on none0 Cache mode: writethrough, direct Cache mode: writeback, direct - Cache mode: writethrough, direct + Cache mode: writeback, direct Cache mode: writeback, direct cache.writeback=off on file
@@ -383,7 +383,7 @@ cache.writeback=off on none0 Cache mode: writeback, direct Cache mode: writethrough Cache mode: writeback - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback cache.writeback=off on file
@@ -718,7 +718,7 @@ cache.direct=on on backing-file cache.writeback=off on none0 Cache mode: writethrough Cache mode: writeback - Cache mode: writethrough, direct + Cache mode: writeback, direct Cache mode: writeback, direct cache.writeback=off on file
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/48] block/qapi: make two printf() formats literal
In reply to Kevin WolfFrom: Peter Xu <[email protected]>
Fix two places to use literal printf format when possible.
--- block/qapi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
block/qapi.c +4 -6
@@ -651,9 +651,8 @@ static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,for (entry =qlist_first (list); entry; entry =qlist_next (entry), i++) {QType type =qobject_type (entry->value);bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); -const char *format = composite ?"%*s[%i]:\n" :"%*s[%i]: " ; - -func_fprintf (f, format, indentation *4 ,"" , i); +func_fprintf (f,"%*s[%i]:%c" , indentation *4 ,"" , i, + composite ?'\n' :' ' );dump_qobject (func_fprintf, f, indentation +1 , entry->value);if (!composite) {func_fprintf (f,"\n" );
@@ -669,7 +668,6 @@ static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,for (entry =qdict_first (dict); entry; entry =qdict_next (dict, entry)) {QType type =qobject_type (entry->value);bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); -const char *format = composite ?"%*s%s:\n" :"%*s%s: " ;char key[strlen (entry->key) +1 ];int i;
@@ -678,8 +676,8 @@ static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation, key[i] = entry->key[i] =='-' ?' ' : entry->key[i]; } key[i] =0 ; - -func_fprintf (f, format, indentation *4 ,"" , key); +func_fprintf (f,"%*s%s:%c" , indentation *4 ,"" , key, + composite ?'\n' :' ' );dump_qobject (func_fprintf, f, indentation +1 , entry->value);if (!composite) {func_fprintf (f,"\n" );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/48] block/qapi: Set s->device in bdrv_query_stats()
In reply to Kevin WolfFrom: Max Reitz <[email protected]>
This is the only instance of bdrv_query_blk_stats() accessing anything in the BlockStats structure other than s->stats, so let us move it to its caller (where it makes just as much sense) allowing us to make bdrv_query_blk_stats() take a pointer to the BlockDeviceStats instead of BlockStats.
--- block/qapi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
block/qapi.c +2 -3
@@ -364,9 +364,6 @@ static void bdrv_query_blk_stats(BlockStats *s, BlockBackend *blk)BlockAcctStats *stats =blk_get_stats (blk);BlockAcctTimedStats *ts =NULL ; - s->has_device = true; - s->device =g_strdup (blk_name (blk)); - s->stats->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ ]; s->stats->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE ]; s->stats->rd_operations = stats->nr_ops[BLOCK_ACCT_READ ];
@@ -461,6 +458,8 @@ static BlockStats *bdrv_query_stats(BlockBackend *blk, s->stats =g_malloc0 (sizeof (*s->stats));if (blk) { + s->has_device = true; + s->device =g_strdup (blk_name (blk));bdrv_query_blk_stats (s, blk); }if (bs) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/48] block: Remove blk_set_bs()
In reply to Kevin WolfThe function is unused since commit f21d96d0 ('block: Use BdrvChild in BlockBackend').
--- block/block-backend.c | 17 ----------------- include/block/block_int.h | 2 -- 2 files changed, 19 deletions(-)
block/block-backend.c +0 -17
@@ -371,23 +371,6 @@ BlockDriverState *blk_bs(BlockBackend *blk) }/* -* Changes the BlockDriverState attached to @blk -*/ -void blk_set_bs (BlockBackend *blk,BlockDriverState *bs) -{ -bdrv_ref (bs); - -if (blk->root) { - blk->root->bs->blk =NULL ; -bdrv_root_unref_child (blk->root); - } -assert (bs->blk ==NULL ); - - blk->root =bdrv_root_attach_child (bs,"root" , &child_root); - bs->blk = blk; -} - -/* * Return @blk's DriveInfo if any, else null. */ DriveInfo *blk_legacy_dinfo (BlockBackend *blk)
include/block/block_int.h +0 -2
@@ -704,8 +704,6 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const BdrvChildRole *child_role);void bdrv_root_unref_child (BdrvChild *child); -void blk_set_bs (BlockBackend *blk,BlockDriverState *bs); -void blk_dev_change_media_cb (BlockBackend *blk,bool load);bool blk_dev_has_removable_media (BlockBackend *blk);bool blk_dev_has_tray (BlockBackend *blk);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 06/48] block: Reject writethrough mode except at the root
In reply to Kevin WolfWritethrough mode is going to become a BlockBackend feature rather than a BDS one, so forbid it in places where we won't be able to support it when the code finally matches the envisioned design.
We only allowed setting the cache mode of non-root nodes after the 2.5 release, so we're still free to make this change.
The target of block jobs is now always opened in a writeback mode because it doesn't have a BlockBackend attached. This makes more sense anyway because block jobs know when to flush. If the graph is modified on job completion, the original cache mode moves to the new root, so for the guest device writethough always stays enabled if it was configured this way.
--- block.c | 7 ++++ blockdev.c | 19 ++++++++- tests/qemu-iotests/142 | 50 +++++++++++------------ tests/qemu-iotests/142.out | 98 +++++++++------------------------------------- 4 files changed, 68 insertions(+), 106 deletions(-)
block.c +7 -0
@@ -974,6 +974,13 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,/* Apply cache mode options */ update_flags_from_options (&bs->open_flags, opts); + +if (!bs->blk && (bs->open_flags &BDRV_O_CACHE_WB ) ==0 ) { +error_setg (errp,"Can't set writethrough mode except for the root" ); + ret = -EINVAL ; + goto free_and_fail; + } +bdrv_set_enable_write_cache (bs, bs->open_flags &BDRV_O_CACHE_WB );/* Open the image, either directly or using a protocol */
blockdev.c +17 -2
@@ -1771,6 +1771,12 @@ static void external_snapshot_prepare(BlkActionState *common, flags |=BDRV_O_NO_BACKING ; } +/* There is no BB attached during bdrv_open(), so we can't set a +* writethrough mode. bdrv_append() will swap the WCE setting so that the +* backing file becomes unconditionally writeback (which is what backing +* files should always be) and the new overlay gets the original setting. */ + flags |=BDRV_O_CACHE_WB ; +assert (state->new_bs ==NULL ); ret =bdrv_open (&state->new_bs, new_image_file, snapshot_ref, options, flags, errp);
@@ -2515,6 +2521,7 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,BlockBackend *blk;BlockDriverState *medium_bs =NULL ;int bdrv_flags, ret; +bool writethrough;QDict *options =NULL ;Error *err =NULL ;
@@ -2533,6 +2540,12 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, bdrv_flags &= ~(BDRV_O_TEMPORARY |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_PROTOCOL ); +/* Must open the image in writeback mode as long as no BlockBackend is +* attached. The right mode can be set as the final step after changing the +* medium. */ + writethrough = !(bdrv_flags &BDRV_O_CACHE_WB ); + bdrv_flags |=BDRV_O_CACHE_WB ; +if (!has_read_only) { read_only =BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN ; }
@@ -2590,6 +2603,8 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, goto fail; } +bdrv_set_enable_write_cache (medium_bs, !writethrough); +qmp_blockdev_close_tray (device, errp); fail:
@@ -3215,7 +3230,7 @@ static void do_drive_backup(const char *device, const char *target, goto out; } - flags = bs->open_flags |BDRV_O_RDWR ; + flags = bs->open_flags |BDRV_O_CACHE_WB |BDRV_O_RDWR ;/* See if we have a backing HD we can use to create our new image * on top of. */
@@ -3510,7 +3525,7 @@ void qmp_drive_mirror(const char *device, const char *target, format = mode ==NEW_IMAGE_MODE_EXISTING ?NULL : bs->drv->format_name; } - flags = bs->open_flags |BDRV_O_RDWR ; + flags = bs->open_flags |BDRV_O_CACHE_WB |BDRV_O_RDWR ; source =backing_bs (bs);if (!source && sync ==MIRROR_SYNC_MODE_TOP ) { sync =MIRROR_SYNC_MODE_FULL ;
tests/qemu-iotests/142 +25 -25
103 lines not on this page · raw message
tests/qemu-iotests/142.out +19 -79
164 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/48] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host
In reply to Kevin WolfFrom: Programmingkid <[email protected]>
Mac OS X can be picky when it comes to allowing the user to use physical devices in QEMU. Most mounted volumes appear to be off limits to QEMU. If an issue is detected, a message is displayed showing the user how to unmount a volume. Now QEMU uses both CD and DVD media.
--- block/raw-posix.c | 165 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 126 insertions(+), 39 deletions(-)
block/raw-posix.c +126 -39
@@ -44,6 +44,7 @@#include <IOKit/storage/IOMedia.h> #include <IOKit/storage/IOCDMedia.h> //#include <IOKit/storage/IOCDTypes.h> +#include <IOKit/storage/IODVDMedia.h> #include <CoreFoundation/CoreFoundation.h> #endif
@@ -1965,33 +1966,47 @@ BlockDriver bdrv_file = {/* host device */ #if defined(__APPLE__) && defined(__MACH__) -static kern_return_t FindEjectableCDMedia (io_iterator_t *mediaIterator );static kern_return_t GetBSDPath (io_iterator_t mediaIterator,char *bsdPath,CFIndex maxPathSize,int flags); -kern_return_t FindEjectableCDMedia (io_iterator_t *mediaIterator ) +static char *FindEjectableOpticalMedia (io_iterator_t *mediaIterator) { -kern_return_t kernResult; +kern_return_t kernResult =KERN_FAILURE ;mach_port_t masterPort;CFMutableDictionaryRef classesToMatch; +const char *matching_array[] = {kIODVDMediaClass, kIOCDMediaClass}; +char *mediaType =NULL ; kernResult =IOMasterPort (MACH_PORT_NULL , &masterPort );if (KERN_SUCCESS != kernResult ) {printf ("IOMasterPort returned %d\n" , kernResult ); } - classesToMatch =IOServiceMatching ( kIOCDMediaClass ); -if ( classesToMatch ==NULL ) { -printf ("IOServiceMatching returned a NULL dictionary.\n" ); - }else { -CFDictionarySetValue ( classesToMatch,CFSTR ( kIOMediaEjectableKey ), kCFBooleanTrue ); - } - kernResult =IOServiceGetMatchingServices ( masterPort, classesToMatch, mediaIterator ); -if (KERN_SUCCESS != kernResult ) - { -printf ("IOServiceGetMatchingServices returned %d\n" , kernResult ); - } +int index; +for (index =0 ; index <ARRAY_SIZE (matching_array); index++) { + classesToMatch =IOServiceMatching (matching_array[index]); +if (classesToMatch ==NULL ) { +error_report ("IOServiceMatching returned NULL for %s" , + matching_array[index]); +continue ; + } +CFDictionarySetValue (classesToMatch,CFSTR (kIOMediaEjectableKey), + kCFBooleanTrue); + kernResult =IOServiceGetMatchingServices (masterPort, classesToMatch, + mediaIterator); +if (kernResult !=KERN_SUCCESS ) { +error_report ("Note: IOServiceGetMatchingServices returned %d" , + kernResult); +continue ; + } -return kernResult; +/* If a match was found, leave the loop */ +if (*mediaIterator !=0 ) { +DPRINTF ("Matching using %s\n" , matching_array[index]); + mediaType =g_strdup (matching_array[index]); +break ; + } + } +return mediaType; } kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
@@ -2023,7 +2038,46 @@ kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath, return kernResult; } -#endif +/* Sets up a real cdrom for use in QEMU */ +static bool setup_cdrom (char *bsd_path,Error **errp) +{ +int index, num_of_test_partitions =2 , fd; +char test_partition[MAXPATHLEN ]; +bool partition_found = false; + +/* look for a working partition */ +for (index =0 ; index < num_of_test_partitions; index++) { +snprintf (test_partition,sizeof (test_partition),"%ss%d" , bsd_path, + index); + fd =qemu_open (test_partition,O_RDONLY |O_BINARY |O_LARGEFILE ); +if (fd >=0 ) { + partition_found = true; +qemu_close (fd); +break ; + } + } + +/* if a working partition on the device was not found */ +if (partition_found == false) { +error_setg (errp,"Failed to find a working partition on disc" ); + }else { +DPRINTF ("Using %s as optical disc\n" , test_partition); +pstrcpy (bsd_path,MAXPATHLEN , test_partition); + } +return partition_found; +} + +/* Prints directions on mounting and unmounting a device */ +static void print_unmounting_directions (const char *file_name) +{ +error_report ("If device %s is mounted on the desktop, unmount" +" it first before using it in QEMU" , file_name); +error_report ("Command to unmount device: diskutil unmountDisk %s" , + file_name); +error_report ("Command to mount device: diskutil mountDisk %s" , file_name); +} + +#endif /* defined(__APPLE__) && defined(__MACH__) */ static int hdev_probe_device (const char *filename) {
@@ -2114,33 +2168,57 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,#if defined(__APPLE__) && defined(__MACH__)const char *filename =qdict_get_str (options,"filename" ); +char bsd_path[MAXPATHLEN ] ="" ; +bool error_occurred = false; + +/* If using a real cdrom */ +if (strcmp (filename,"/dev/cdrom" ) ==0 ) { +char *mediaType =NULL ; +kern_return_t ret_val; +io_iterator_t mediaIterator =0 ; + + mediaType =FindEjectableOpticalMedia (&mediaIterator); +if (mediaType ==NULL ) { +error_setg (errp,"Please make sure your CD/DVD is in the optical" +" drive" ); + error_occurred = true; + goto hdev_open_Mac_error; + } -if (strstart (filename,"/dev/cdrom" ,NULL )) { -kern_return_t kernResult; -io_iterator_t mediaIterator; -char bsdPath[MAXPATHLEN ]; -int fd; - - kernResult =FindEjectableCDMedia ( &mediaIterator ); - kernResult =GetBSDPath (mediaIterator, bsdPath,sizeof (bsdPath), - flags); -if ( bsdPath[0 ] !='\0' ) { -strcat (bsdPath,"s0" ); -/* some CDs don't have a partition 0 */ - fd =qemu_open (bsdPath,O_RDONLY |O_BINARY |O_LARGEFILE ); -if (fd <0 ) { - bsdPath[strlen (bsdPath)-1 ] ='1' ; - }else { -qemu_close (fd); - } - filename = bsdPath; -qdict_put (options,"filename" ,qstring_from_str (filename)); + ret_val =GetBSDPath (mediaIterator, bsd_path,sizeof (bsd_path), flags); +if (ret_val !=KERN_SUCCESS ) { +error_setg (errp,"Could not get BSD path for optical drive" ); + error_occurred = true; + goto hdev_open_Mac_error; + } + +/* If a real optical drive was not found */ +if (bsd_path[0 ] =='\0' ) { +error_setg (errp,"Failed to obtain bsd path for optical drive" ); + error_occurred = true; + goto hdev_open_Mac_error; + } + +/* If using a cdrom disc and finding a partition on the disc failed */ +if (strncmp (mediaType, kIOCDMediaClass,9 ) ==0 && +setup_cdrom (bsd_path, errp) == false) { +print_unmounting_directions (bsd_path); + error_occurred = true; + goto hdev_open_Mac_error; } -if ( mediaIterator ) -IOObjectRelease ( mediaIterator ); +qdict_put (options,"filename" ,qstring_from_str (bsd_path)); + +hdev_open_Mac_error: +g_free (mediaType); +if (mediaIterator) { +IOObjectRelease (mediaIterator); + } +if (error_occurred) { +return -ENOENT ; + } } -#endif +#endif /* defined(__APPLE__) && defined(__MACH__) */ s->type =FTYPE_FILE ;
@@ -2149,6 +2227,15 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,if (local_err) {error_propagate (errp, local_err); } +#if defined(__APPLE__) && defined(__MACH__) +if (*bsd_path) { + filename = bsd_path; + } +/* if a physical device experienced an error while being opened */ +if (strncmp (filename,"/dev/" ,5 ) ==0 ) { +print_unmounting_directions (filename); + } +#endif /* defined(__APPLE__) && defined(__MACH__) */ return ret; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/48] block/qapi: fix unbounded stack for dump_qdict
In reply to Kevin WolfFrom: Peter Xu <[email protected]>
Using heap instead of stack for better safety.
--- block/qapi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/qapi.c +2 -1
@@ -668,7 +668,7 @@ static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,for (entry =qdict_first (dict); entry; entry =qdict_next (dict, entry)) {QType type =qobject_type (entry->value);bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); -char key[strlen (entry->key) +1 ]; +char *key =g_malloc (strlen (entry->key) +1 );int i;/* replace dashes with spaces in key (variable) names */
@@ -682,6 +682,7 @@ static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,if (!composite) {func_fprintf (f,"\n" ); } +g_free (key); } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/48] block/qapi: Pass bdrv_query_blk_stats() s->stats
In reply to Kevin WolfFrom: Max Reitz <[email protected]>
bdrv_query_blk_stats() does not need access to all of BlockStats, BlockDeviceStats is enough and is what this function is actually supposed to fill.
--- block/qapi.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
block/qapi.c +25 -25
@@ -359,47 +359,47 @@ static BlockStats *bdrv_query_stats(BlockBackend *blk,const BlockDriverState *bs, bool query_backing); -static void bdrv_query_blk_stats (BlockStats *s,BlockBackend *blk) +static void bdrv_query_blk_stats (BlockDeviceStats *ds,BlockBackend *blk) {BlockAcctStats *stats =blk_get_stats (blk);BlockAcctTimedStats *ts =NULL ; - s->stats->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ ]; - s->stats->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE ]; - s->stats->rd_operations = stats->nr_ops[BLOCK_ACCT_READ ]; - s->stats->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE ]; + ds->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ ]; + ds->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE ]; + ds->rd_operations = stats->nr_ops[BLOCK_ACCT_READ ]; + ds->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE ]; - s->stats->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ ]; - s->stats->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE ]; - s->stats->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH ]; + ds->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ ]; + ds->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE ]; + ds->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH ]; - s->stats->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ ]; - s->stats->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE ]; - s->stats->invalid_flush_operations = + ds->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ ]; + ds->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE ]; + ds->invalid_flush_operations = stats->invalid_ops[BLOCK_ACCT_FLUSH ]; - s->stats->rd_merged = stats->merged[BLOCK_ACCT_READ ]; - s->stats->wr_merged = stats->merged[BLOCK_ACCT_WRITE ]; - s->stats->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH ]; - s->stats->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE ]; - s->stats->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ ]; - s->stats->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH ]; + ds->rd_merged = stats->merged[BLOCK_ACCT_READ ]; + ds->wr_merged = stats->merged[BLOCK_ACCT_WRITE ]; + ds->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH ]; + ds->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE ]; + ds->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ ]; + ds->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH ]; - s->stats->has_idle_time_ns = stats->last_access_time_ns >0 ; -if (s->stats->has_idle_time_ns) { - s->stats->idle_time_ns =block_acct_idle_time_ns (stats); + ds->has_idle_time_ns = stats->last_access_time_ns >0 ; +if (ds->has_idle_time_ns) { + ds->idle_time_ns =block_acct_idle_time_ns (stats); } - s->stats->account_invalid = stats->account_invalid; - s->stats->account_failed = stats->account_failed; + ds->account_invalid = stats->account_invalid; + ds->account_failed = stats->account_failed;while ((ts =block_acct_interval_next (stats, ts))) {BlockDeviceTimedStatsList *timed_stats =g_malloc0 (sizeof (*timed_stats));BlockDeviceTimedStats *dev_stats =g_malloc0 (sizeof (*dev_stats)); - timed_stats->next = s->stats->timed_stats; + timed_stats->next = ds->timed_stats; timed_stats->value = dev_stats; - s->stats->timed_stats = timed_stats; + ds->timed_stats = timed_stats;TimedAverage *rd = &ts->latency[BLOCK_ACCT_READ ];TimedAverage *wr = &ts->latency[BLOCK_ACCT_WRITE ];
@@ -460,7 +460,7 @@ static BlockStats *bdrv_query_stats(BlockBackend *blk,if (blk) { s->has_device = true; s->device =g_strdup (blk_name (blk)); -bdrv_query_blk_stats (s, blk); +bdrv_query_blk_stats (s->stats, blk); }if (bs) {bdrv_query_bds_stats (s, bs, query_backing);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 14/48] qemu-img/qemu-io: don't prompt for passwords if not required
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
The qemu-img/qemu-io tools prompt for disk encryption passwords regardless of whether any are actually required. Adding a check on bdrv_key_required() avoids this prompt for disk formats which have been converted to the QCryptoSecret APIs.
This is just a temporary hack to ensure the block I/O tests continue to work after each patch, since the last patch will completely delete all the password prompting code.
--- qemu-img.c | 3 ++- qemu-io.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
qemu-img.c +2 -1
@@ -230,7 +230,8 @@ static int img_open_password(BlockBackend *blk, const char *filename,char password[256 ]; bs =blk_bs (blk); -if (bdrv_is_encrypted (bs) && !(flags &BDRV_O_NO_IO )) { +if (bdrv_is_encrypted (bs) &&bdrv_key_required (bs) && + !(flags &BDRV_O_NO_IO )) {qprintf (quiet,"Disk image '%s' is encrypted.\n" , filename);if (qemu_read_password (password,sizeof (password)) <0 ) {error_report ("No password given" );
qemu-io.c +1 -1
@@ -69,7 +69,7 @@ static int openfile(char *name, int flags, QDict *opts) } bs =blk_bs (qemuio_blk); -if (bdrv_is_encrypted (bs)) { +if (bdrv_is_encrypted (bs) &&bdrv_key_required (bs)) {char password[256 ];printf ("Disk image '%s' is encrypted.\n" , name);if (qemu_read_password (password,sizeof (password)) <0 ) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/48] block: add flag to indicate that no I/O will be performed
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
When opening an image it is useful to know whether the caller intends to perform I/O on the image or not. In the case of encrypted images this will allow the block driver to avoid having to prompt for decryption keys when we merely want to query header metadata about the image. eg qemu-img info
This flag is enforced at the top level only, since even if we don't want todo I/O on the 'qcow2' file payload, the underlying 'file' driver will still need todo I/O to read the qcow2 header, for example.
--- block.c | 5 +++-- block/io.c | 2 ++ include/block/block.h | 1 + qemu-img.c | 44 ++++++++++++++++++++++---------------------- 4 files changed, 28 insertions(+), 24 deletions(-)
block.c +3 -2
@@ -701,7 +701,8 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options, flags |=BDRV_O_UNMAP ;/* Clear flags that only apply to the top layer */ - flags &= ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_COPY_ON_READ ); + flags &= ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_COPY_ON_READ | +BDRV_O_NO_IO ); *child_flags = flags; }
@@ -721,7 +722,7 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, child_file.inherit_options (child_flags, child_options, parent_flags, parent_options); - *child_flags &= ~BDRV_O_PROTOCOL ; + *child_flags &= ~(BDRV_O_PROTOCOL |BDRV_O_NO_IO ); }const BdrvChildRole child_format = {
block/io.c +2 -0
@@ -842,6 +842,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 );assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 );assert (!qiov || bytes == qiov->size); +assert ((bs->open_flags &BDRV_O_NO_IO ) ==0 );/* Handle Copy on Read and associated serialisation */ if (flags &BDRV_REQ_COPY_ON_READ ) {
@@ -1128,6 +1129,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 );assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 );assert (!qiov || bytes == qiov->size); +assert ((bs->open_flags &BDRV_O_NO_IO ) ==0 ); waited =wait_serialising_requests (req);assert (!waited || !req->serialising);
include/block/block.h +1 -0
@@ -93,6 +93,7 @@ typedef struct HDGeometry {#define BDRV_O_PROTOCOL 0x8000/* if no block driver is explicitly given: select an appropriate protocol driver, ignoring the format layer */ +#define BDRV_O_NO_IO 0x10000/* don't initialize for I/O */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
qemu-img.c +22 -22
163 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 15/48] tests: redirect stderr to stdout for iotests
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
The python I/O tests helper for running qemu-img/qemu-io setup stdout to be captured to a pipe, but left stderr untouched. As a result, if something failed in qemu-img/ qemu-io, data written to stderr would get output directly and not line up with data on the test stdout due to buffering. If we explicitly redirect stderr to the same pipe as stdout, things are much clearer when they go wrong.
--- tests/qemu-iotests/iotests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +5 -2
@@ -71,7 +71,9 @@ def qemu_img_verbose(*args): def qemu_img_pipe(*args): '''Run qemu-img and return its output''' - subp = subprocess.Popen(qemu_img_args + list(args), stdout=subprocess.PIPE) + subp = subprocess.Popen(qemu_img_args + list(args), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) exitcode = subp.wait() if exitcode < 0: sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
@@ -80,7 +82,8 @@ def qemu_img_pipe(*args): def qemu_io(*args): '''Run qemu-io and return the stdout data''' args = qemu_io_args + list(args) - subp = subprocess.Popen(args, stdout=subprocess.PIPE) + subp = subprocess.Popen(args, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) exitcode = subp.wait() if exitcode < 0: sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, ' '.join(args)))
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 16/48] tests: refactor python I/O tests helper main method
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
The iotests.py helper provides a main() method for running tests via the python unit test framework. Not all tests will want to use this, so refactor it to split the testing of compatible formats and platforms into separate helper methods
--- tests/qemu-iotests/iotests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
tests/qemu-iotests/iotests.py +12 -6
@@ -29,7 +29,8 @@ import qtest import struct __all__ = ['imgfmt', 'imgproto', 'test_dir' 'qemu_img', 'qemu_io', - 'VM', 'QMPTestCase', 'notrun', 'main'] + 'VM', 'QMPTestCase', 'notrun', 'main', 'verify_image_format', + 'verify_platform'] # This will not work if arguments contain spaces but is necessary if we # want to support the override options that ./check supports.
@@ -394,17 +395,22 @@ def notrun(reason): print '%s not run: %s' % (seq, reason) sys.exit(0) -def main(supported_fmts=[], supported_oses=['linux']): - '''Run tests''' - - debug = '-d' in sys.argv - verbosity = 1 +def verify_image_format(supported_fmts=[]): if supported_fmts and (imgfmt not in supported_fmts): notrun('not suitable for this image format: %s' % imgfmt) +def verify_platform(supported_oses=['linux']): if True not in [sys.platform.startswith(x) for x in supported_oses]: notrun('not suitable for this OS: %s' % sys.platform) +def main(supported_fmts=[], supported_oses=['linux']): + '''Run tests''' + + debug = '-d' in sys.argv + verbosity = 1 + verify_image_format(supported_fmts) + verify_platform(supported_oses) + # We need to filter out the time taken from the output so that qemu-iotest # can reliably diff the results against master output. import StringIO
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 17/48] tests: add output filter to python I/O tests helper
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
Add a 'log' method to iotests.py which prints messages to stdout, with optional filtering of data. Port over some standard filters already present in the shell common.filter code to be usable in python too.
--- tests/qemu-iotests/iotests.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
tests/qemu-iotests/iotests.py +24 -1
@@ -30,7 +30,8 @@ import struct __all__ = ['imgfmt', 'imgproto', 'test_dir' 'qemu_img', 'qemu_io', 'VM', 'QMPTestCase', 'notrun', 'main', 'verify_image_format', - 'verify_platform'] + 'verify_platform', 'filter_test_dir', 'filter_win32', + 'filter_qemu_io', 'filter_chown', 'log'] # This will not work if arguments contain spaces but is necessary if we # want to support the override options that ./check supports.
@@ -105,6 +106,28 @@ def create_image(name, size): i = i + 512 file.close() +test_dir_re = re.compile(r"%s" % test_dir) +def filter_test_dir(msg): + return test_dir_re.sub("TEST_DIR", msg) + +win32_re = re.compile(r"\r") +def filter_win32(msg): + return win32_re.sub("", msg) + +qemu_io_re = re.compile(r"[0-9]* ops; [0-9\/:. sec]* \([0-9\/.inf]* [EPTGMKiBbytes]*\/sec and [0-9\/.inf]* ops\/sec\)") +def filter_qemu_io(msg): + msg = filter_win32(msg) + return qemu_io_re.sub("X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)", msg) + +chown_re = re.compile(r"chown [0-9]+:[0-9]+") +def filter_chown(msg): + return chown_re.sub("chown UID:GID", msg) + +def log(msg, filters=[]): + for flt in filters: + msg = flt(msg) + print msg + # Test if 'match' is a recursive subset of 'event' def event_match(event, match=None): if match is None:
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 18/48] block: add generic full disk encryption driver
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
Add a block driver that is capable of supporting any full disk encryption format. This utilizes the previously added block encryption code, and at this time supports the LUKS format.
The driver code is capable of supporting any format supported by the QCryptoBlock module, so it registers one block driver for each format. This patch only registers the "luks" driver since the "qcow" driver is there only for back-compatibility with existing qcow built-in encryption.
New LUKS compatible volumes can be formatted using qemu-img with defaults for all settings.
$ qemu-img create --object secret,data=123456,id=sec0 \
-f luks -o key-secret=sec0 demo.luks 10GAlternatively the cryptographic settings can be explicitly set
$ qemu-img create --object secret,data=123456,id=sec0 \
-f luks -o key-secret=sec0,cipher-alg=aes-256,\
cipher-mode=cbc,ivgen-alg=plain64,hash-alg=sha256 \
demo.luks 10GAnd query its size
$ qemu-img info demo.img image: demo.img file format: luks virtual size: 10G (10737418240 bytes) disk size: 132K encrypted: yes
Note that it was not necessary to provide the password when querying info for the volume. The password is only required when performing I/O on the volume
All volumes created by this new 'luks' driver should be capable of being opened by the kernel dm-crypt driver.
The only algorithms listed in the LUKS spec that are not currently supported by this impl are sha512 and ripemd160 hashes and cast6 cipher.
--- block/Makefile.objs | 2 + block/crypto.c | 586 +++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 22 +- 3 files changed, 608 insertions(+), 2 deletions(-) create mode 100644 block/crypto.c
block/Makefile.objs +2 -0
@@ -23,6 +23,8 @@ block-obj-$(CONFIG_LIBSSH2) += ssh.o block-obj-y += accounting.o dirty-bitmap.o block-obj-y += write-threshold.o +block-obj-y += crypto.o + common-obj-y += stream.o common-obj-y += commit.o common-obj-y += backup.o
block/crypto.c new file +586 -0
586 lines not on this page · raw message
qapi/block-core.json +20 -2
@@ -242,11 +242,12 @@ # @drv: the name of the block format used to open the backing device. As of # 0.14.0 this can be: 'blkdebug', 'bochs', 'cloop', 'cow', 'dmg', # 'file', 'file', 'ftp', 'ftps', 'host_cdrom', 'host_device', -# 'http', 'https', 'nbd', 'parallels', 'qcow', +# 'http', 'https', 'luks', 'nbd', 'parallels', 'qcow', # 'qcow2', 'raw', 'tftp', 'vdi', 'vmdk', 'vpc', 'vvfat' # 2.2: 'archipelago' added, 'cow' dropped # 2.3: 'host_floppy' deprecated # 2.5: 'host_floppy' dropped +# 2.6: 'luks' added # # @backing_file: #optional the name of the backing file (for copy-on-write) #
@@ -1637,7 +1638,7 @@ { 'enum': 'BlockdevDriver', 'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop', 'dmg', 'file', 'ftp', 'ftps', 'host_cdrom', 'host_device', - 'http', 'https', 'null-aio', 'null-co', 'parallels', + 'http', 'https', 'luks', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
@@ -1704,6 +1705,22 @@ 'data': { 'file': 'BlockdevRef' } } ## +# @BlockdevOptionsLUKS +# +# Driver specific block device options for LUKS. +# +# @key-secret: #optional the ID of a QCryptoSecret object providing +# the decryption key (since 2.6). Mandatory except when +# doing a metadata-only probe of the image. +# +# Since: 2.6 +## +{ 'struct': 'BlockdevOptionsLUKS', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*key-secret': 'str' } } + + +## # @BlockdevOptionsGenericCOWFormat # # Driver specific block device options for image format that have no option
@@ -2083,6 +2100,7 @@ 'http': 'BlockdevOptionsFile', 'https': 'BlockdevOptionsFile', # TODO iscsi: Wait for structured options + 'luks': 'BlockdevOptionsLUKS', # TODO nbd: Should take InetSocketAddress for 'host'? # TODO nfs: Wait for structured options 'null-aio': 'BlockdevOptionsNull',
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 19/48] block: move encryption deprecation warning into qcow code
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
For a couple of releases we have been warning
Encrypted images are deprecated
Support for them will be removed in a future release.
You can use 'qemu-img convert' to convert your image to an unencrypted one.
This warning was issued by system emulators, qemu-img, qemu-nbd and qemu-io. Such a broad warning was issued because the original intention was to rip out all the code for dealing with encryption inside the QEMU block layer APIs.
The new block encryption framework used for the LUKS driver does not rely on the unloved block layer API for encryption keys, instead using the QOM 'secret' object type. It is thus no longer appropriate to warn about encryption unconditionally.
When the qcow/qcow2 drivers are converted to use the new encryption framework too, it will be practical to keep AES-CBC support present for use in qemu-img, qemu-io & qemu-nbd to allow for interoperability with older QEMU versions and liberation of data from existing encrypted qcow2 files.
This change moves the warning out of the generic block code and into the qcow/qcow2 drivers. Further, the warning is set to only appear when running the system emulators, since qemu-img, qemu-io, qemu-nbd are expected to support qcow2 encryption long term now that the maint burden has been eliminated.
--- block.c | 12 +++++------- block/qcow.c | 9 +++++++++ block/qcow2.c | 8 ++++++++ include/block/block.h | 1 + tests/qemu-iotests/049.out | 6 ------ tests/qemu-iotests/087 | 3 ++- tests/qemu-iotests/087.out | 26 ++++++++------------------ tests/qemu-iotests/134.out | 18 ------------------ 8 files changed, 33 insertions(+), 50 deletions(-)
block.c +5 -7
@@ -288,6 +288,11 @@ static int bdrv_is_whitelisted(BlockDriver *drv, bool read_only)return 0 ; } +bool bdrv_uses_whitelist (void ) +{ +return use_bdrv_whitelist; +} + typedef struct CreateCo { BlockDriver *drv; char *filename;
@@ -1012,13 +1017,6 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, goto free_and_fail; } -if (bs->encrypted) { -error_report ("Encrypted images are deprecated" ); -error_printf ("Support for them will be removed in a future release.\n" -"You can use 'qemu-img convert' to convert your image" -" to an unencrypted one.\n" ); - } - ret =refresh_total_sectors (bs, bs->total_sectors);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not refresh total sector count" );
block/qcow.c +9 -0
@@ -23,6 +23,7 @@*/ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/error-report.h" #include "block/block_int.h" #include "sysemu/block-backend.h" #include "qemu/module.h"
@@ -157,6 +158,14 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, } s->crypt_method_header = header.crypt_method;if (s->crypt_method_header) { +if (bdrv_uses_whitelist () && + s->crypt_method_header ==QCOW_CRYPT_AES ) { +error_report ("qcow built-in AES encryption is deprecated" ); +error_printf ("Support for it will be removed in a future release.\n" +"You can use 'qemu-img convert' to switch to an\n" +"unencrypted qcow image, or a LUKS raw image.\n" ); + } + bs->encrypted =1 ; } s->cluster_bits = header.cluster_bits;
block/qcow2.c +8 -0
@@ -965,6 +965,14 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, } s->crypt_method_header = header.crypt_method;if (s->crypt_method_header) { +if (bdrv_uses_whitelist () && + s->crypt_method_header ==QCOW_CRYPT_AES ) { +error_report ("qcow2 built-in AES encryption is deprecated" ); +error_printf ("Support for it will be removed in a future release.\n" +"You can use 'qemu-img convert' to switch to an\n" +"unencrypted qcow2 image, or a LUKS raw image.\n" ); + } + bs->encrypted =1 ; }
include/block/block.h +1 -0
@@ -193,6 +193,7 @@ void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group);void bdrv_init (void );void bdrv_init_with_whitelist (void ); +bool bdrv_uses_whitelist (void );BlockDriver *bdrv_find_protocol (const char *filename,bool allow_protocol_prefix,Error **errp);
tests/qemu-iotests/049.out +0 -6
@@ -187,12 +187,6 @@ qemu-img create -f qcow2 -o encryption=off TEST_DIR/t.qcow2 64M Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16 qemu-img create -f qcow2 -o encryption=on TEST_DIR/t.qcow2 64M -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 encryption=on cluster_size=65536 lazy_refcounts=off refcount_bits=16 == Check lazy_refcounts option (only with v3) ==
tests/qemu-iotests/087 +2 -1
@@ -45,7 +45,8 @@ function do_run_qemu() function run_qemu() { - do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ + | _filter_qemu | _filter_imgfmt \ | sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g' }
tests/qemu-iotests/087.out +8 -18
@@ -38,19 +38,14 @@ QMP_VERSION === Encrypted image === -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on Testing: -S QMP_VERSION {"return": {}} -Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. +IMGFMT built-in AES encryption is deprecated +Support for it will be removed in a future release. +You can use 'qemu-img convert' to switch to an +unencrypted IMGFMT image, or a LUKS raw image. {"error": {"class": "GenericError", "desc": "blockdev-add doesn't support encrypted devices"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"}
@@ -58,9 +53,10 @@ You can use 'qemu-img convert' to convert your image to an unencrypted one. Testing: QMP_VERSION {"return": {}} -Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. +IMGFMT built-in AES encryption is deprecated +Support for it will be removed in a future release. +You can use 'qemu-img convert' to switch to an +unencrypted IMGFMT image, or a LUKS raw image. {"error": {"class": "GenericError", "desc": "Guest must be stopped for opening of encrypted image"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"}
@@ -68,12 +64,6 @@ You can use 'qemu-img convert' to convert your image to an unencrypted one. === Missing driver === -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on Testing: -S QMP_VERSION
tests/qemu-iotests/134.out +0 -18
@@ -1,43 +1,25 @@ QA output created by 134 -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. -qemu-img: Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on == reading whole image == -Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Disk image 'TEST_DIR/t.qcow2' is encrypted. password: read 134217728/134217728 bytes at offset 0 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == rewriting whole image == -Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Disk image 'TEST_DIR/t.qcow2' is encrypted. password: wrote 134217728/134217728 bytes at offset 0 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == verify pattern == -Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Disk image 'TEST_DIR/t.qcow2' is encrypted. password: read 134217728/134217728 bytes at offset 0 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == verify pattern failure with wrong password == -Encrypted images are deprecated -Support for them will be removed in a future release. -You can use 'qemu-img convert' to convert your image to an unencrypted one. Disk image 'TEST_DIR/t.qcow2' is encrypted. password: Pattern verification failed at offset 0, 134217728 bytes
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 23/48] replay: fix error message
In reply to Kevin WolfFrom: Pavel Dovgalyuk <[email protected]>
This patch fixes error message in saving loop of the asynchronous events queue.
--- replay/replay-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
replay/replay-events.c +1 -1
@@ -175,7 +175,7 @@ static void replay_save_event(Event *event, int checkpoint)replay_event_char_read_save (event->opaque);break ;default : -error_report ("Unknown ID %d of replay event" , read_event_kind); +error_report ("Unknown ID %" PRId64" of replay event" , event->id);exit (1 ); } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 21/48] block: add flush callback
In reply to Kevin WolfFrom: Pavel Dovgalyuk <[email protected]>
This patch adds callback for flush request. This callback is responsible for flushing whole block devices stack. bdrv_flush function does not proceed to underlying devices. It should be performed by this callback function, if needed.
--- block/io.c | 7 +++++++ include/block/block_int.h | 7 +++++++ 2 files changed, 14 insertions(+)
block/io.c +7 -0
@@ -2331,6 +2331,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) }tracked_request_begin (&req, bs,0 ,0 ,BDRV_TRACKED_FLUSH ); + +/* Write back all layers by calling one driver function */ +if (bs->drv->bdrv_co_flush) { + ret = bs->drv->bdrv_co_flush (bs); + goto out; + } +/* Write back cached data to the OS even with cache=unsafe */ BLKDBG_EVENT (bs->file,BLKDBG_FLUSH_TO_OS );if (bs->drv->bdrv_co_flush_to_os) {
include/block/block_int.h +7 -0
@@ -176,6 +176,13 @@ struct BlockDriver {int (*bdrv_inactivate)(BlockDriverState *bs);/* +* Flushes all data for all layers by calling bdrv_co_flush for underlying +* layers, if needed. This function is needed for deterministic +* synchronization of the flush finishing callback. +*/ + int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); + +/* * Flushes all data that was already written to the OS all the way down to * the disk (for example raw-posix calls fsync()). */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 25/48] block: Add bdrv_parse_cache_mode()
In reply to Kevin WolfIt's like bdrv_parse_cache_flags(), except that writethrough mode isn't included in the flags, but returned as a separate bool.
--- block.c | 17 +++++++++++++++++ include/block/block.h | 1 + 2 files changed, 18 insertions(+)
block.c +17 -0
@@ -666,6 +666,23 @@ int bdrv_parse_cache_flags(const char *mode, int *flags)return 0 ; } +int bdrv_parse_cache_mode (const char *mode,int *flags,bool *writethrough) +{ +int ret =bdrv_parse_cache_flags (mode, flags); +if (ret <0 ) { +return ret; + } + +if (*flags &BDRV_O_CACHE_WB ) { + *flags &= ~BDRV_O_CACHE_WB ; + *writethrough = false; + }else { + *writethrough = true; + } + +return 0 ; +} +/* * Returns the options and flags that a temporary snapshot should get, based on * the originally requested flags (the originally requested image will have
include/block/block.h +1 -0
@@ -208,6 +208,7 @@ void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new);int bdrv_parse_cache_flags (const char *mode,int *flags); +int bdrv_parse_cache_mode (const char *mode,int *flags,bool *writethrough);int bdrv_parse_discard_flags (const char *mode,int *flags); BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 22/48] replay: bh scheduling fix
In reply to Kevin WolfFrom: Pavel Dovgalyuk <[email protected]>
This patch fixes scheduling of bottom halves when record/replay is enabled. Now BH are not added to replay queue when asynchronous events are disabled. This may happen in startup and loadvm/savevm phases of execution.
--- replay/replay-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
replay/replay-events.c +1 -1
@@ -135,7 +135,7 @@ void replay_add_event(ReplayAsyncEventKind event_kind,void replay_bh_schedule_event (QEMUBH *bh) { -if (replay_mode !=REPLAY_MODE_NONE ) { +if (replay_mode !=REPLAY_MODE_NONE && events_enabled) {uint64_t id =replay_get_current_step ();replay_add_event (REPLAY_ASYNC_EVENT_BH , bh,NULL , id); }else {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 26/48] qemu-nbd: Call blk_set_enable_write_cache() explicitly
In reply to Kevin Wolf--- qemu-nbd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
qemu-nbd.c +4 -1
@@ -507,6 +507,7 @@ int main(int argc, char **argv)const char *export_name =NULL ;const char *tlscredsid =NULL ;bool imageOpts = false; +bool writethrough = true;/* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -533,7 +534,7 @@ int main(int argc, char **argv)exit (EXIT_FAILURE ); } seen_cache = true; -if (bdrv_parse_cache_flags (optarg, &flags) ==-1 ) { +if (bdrv_parse_cache_mode (optarg, &flags, &writethrough) ==-1 ) {error_report ("Invalid cache mode `%s'" , optarg);exit (EXIT_FAILURE ); }
@@ -847,6 +848,8 @@ int main(int argc, char **argv) } bs =blk_bs (blk); +blk_set_enable_write_cache (blk, !writethrough); +if (sn_opts) { ret = bdrv_snapshot_load_tmp(bs, qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID),
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 24/48] replay: introduce block devices record/replay
In reply to Kevin WolfFrom: Pavel Dovgalyuk <[email protected]>
This patch introduces block driver that implement recording and replaying of block devices' operations.
All block completion operations are added to the queue. Queue is flushed at checkpoints and information about processed requests is recorded to the log. In replay phase the queue is matched with events read from the log. Therefore block devices requests are processed deterministically.
--- block/Makefile.objs | 2 +- block/blkreplay.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++ docs/replay.txt | 20 ++++++ include/sysemu/replay.h | 2 + replay/replay-events.c | 20 ++++++ replay/replay-internal.h | 1 + replay/replay.c | 2 +- stubs/replay.c | 4 ++ 8 files changed, 208 insertions(+), 2 deletions(-) create mode 100755 block/blkreplay.c
block/Makefile.objs +1 -1
@@ -4,7 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o block-obj-y += quorum.o -block-obj-y += parallels.o blkdebug.o blkverify.o +block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o block-obj-y += block-backend.o snapshot.o qapi.o block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o block-obj-$(CONFIG_POSIX) += raw-posix.o
block/blkreplay.c new file +159 -0
159 lines not on this page · raw message
docs/replay.txt +20 -0
@@ -175,3 +175,23 @@ Sometimes the block layer uses asynchronous callbacks for its internal purposes (like reading or writing VM snapshots or disk image cluster tables). In this case bottom halves are not marked as "replayable" and do not saved into the log. + +Block devices +------------- + +Block devices record/replay module intercepts calls of +bdrv coroutine functions at the top of block drivers stack. +To record and replay block operations the drive must be configured +as following: + -drive file=disk.qcow,if=none,id=img-direct + -drive driver=blkreplay,if=none,image=img-direct,id=img-blkreplay + -device ide-hd,drive=img-blkreplay + +blkreplay driver should be inserted between disk image and virtual driver +controller. Therefore all disk requests may be recorded and replayed. + +All block completion operations are added to the queue in the coroutines. +Queue is flushed at checkpoints and information about processed requests +is recorded to the log. In replay phase the queue is matched with +events read from the log. Therefore block devices requests are processed +deterministically.
include/sysemu/replay.h +2 -0
@@ -114,6 +114,8 @@ void replay_bh_schedule_event(QEMUBH *bh);void replay_input_event (QemuConsole *src,InputEvent *evt);/*! Adds input sync event to the queue */ void replay_input_sync_event (void ); +/*! Adds block layer event to the queue */ +void replay_block_event (QEMUBH *bh,uint64_t id);/* Character device */
replay/replay-events.c +20 -0
@@ -51,6 +51,9 @@ static void replay_run_event(Event *event)case REPLAY_ASYNC_EVENT_CHAR_READ :replay_event_char_read_run (event->opaque);break ; +case REPLAY_ASYNC_EVENT_BLOCK : +aio_bh_call (event->opaque); +break ;default :error_report ("Replay: invalid async event ID (%d) in the queue" , event->event_kind);
@@ -153,6 +156,15 @@ void replay_add_input_sync_event(void)replay_add_event (REPLAY_ASYNC_EVENT_INPUT_SYNC ,NULL ,NULL ,0 ); } +void replay_block_event (QEMUBH *bh,uint64_t id) +{ +if (replay_mode !=REPLAY_MODE_NONE && events_enabled) { +replay_add_event (REPLAY_ASYNC_EVENT_BLOCK , bh,NULL , id); + }else { +qemu_bh_schedule (bh); + } +} +static void replay_save_event (Event *event,int checkpoint) {if (replay_mode !=REPLAY_MODE_PLAY ) {
@@ -174,6 +186,9 @@ static void replay_save_event(Event *event, int checkpoint)case REPLAY_ASYNC_EVENT_CHAR_READ :replay_event_char_read_save (event->opaque);break ; +case REPLAY_ASYNC_EVENT_BLOCK : +replay_put_qword (event->id); +break ;default :error_report ("Unknown ID %" PRId64" of replay event" , event->id);exit (1 );
@@ -232,6 +247,11 @@ static Event *replay_read_event(int checkpoint) event->event_kind = read_event_kind; event->opaque =replay_event_char_read_load ();return event; +case REPLAY_ASYNC_EVENT_BLOCK : +if (read_id ==-1 ) { + read_id =replay_get_qword (); + } +break ;default :error_report ("Unknown ID %d of replay event" , read_event_kind);exit (1 );
replay/replay-internal.h +1 -0
@@ -49,6 +49,7 @@ enum ReplayAsyncEventKind {REPLAY_ASYNC_EVENT_INPUT ,REPLAY_ASYNC_EVENT_INPUT_SYNC ,REPLAY_ASYNC_EVENT_CHAR_READ , +REPLAY_ASYNC_EVENT_BLOCK , REPLAY_ASYNC_COUNT };
replay/replay.c +1 -1
@@ -20,7 +20,7 @@/* Current version of the replay mechanism. Increase it when file format changes. */ -#define REPLAY_VERSION 0xe02003 +#define REPLAY_VERSION 0xe02004/* Size of replay log header */ #define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
stubs/replay.c +4 -0
@@ -63,3 +63,7 @@ void replay_char_read_all_save_buf(uint8_t *buf, int offset) {abort (); } + +void replay_block_event (QEMUBH *bh,uint64_t id) +{ +}
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 28/48] qemu-img: Expand all BDRV_O_FLAGS uses
In reply to Kevin WolfIt always only set the BDRV_O_CACHE_WB flag, which is going to go away. In order to make the next changes more local for better reviewability this patches expands the macro.
--- qemu-img.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
qemu-img.c +11 -12
@@ -58,8 +58,7 @@ typedef enum OutputFormat {OFORMAT_HUMAN , } OutputFormat; -/* Default to cache=writeback as data integrity is not important for qemu-tcg. */ -#define BDRV_O_FLAGS BDRV_O_CACHE_WB +/* Default to cache=writeback as data integrity is not important for qemu-img */ #define BDRV_DEFAULT_CACHE "writeback"static void format_print (void *opaque,const char *name)
@@ -461,7 +460,7 @@ static int img_create(int argc, char **argv) }bdrv_img_create (filename, fmt, base_filename, base_fmt, - options, img_size,BDRV_O_FLAGS , &local_err, quiet); + options, img_size,BDRV_O_CACHE_WB , &local_err, quiet);if (local_err) {error_reportf_err (local_err,"%s: " , filename); goto fail;
@@ -591,7 +590,7 @@ static int img_check(int argc, char **argv)BlockBackend *blk;BlockDriverState *bs;int fix =0 ; -int flags =BDRV_O_FLAGS |BDRV_O_CHECK ; +int flags =BDRV_O_CACHE_WB |BDRV_O_CHECK ;ImageCheck *check;bool quiet = false;Error *local_err =NULL ;
@@ -1203,7 +1202,7 @@ static int img_compare(int argc, char **argv)/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =BDRV_O_FLAGS ; + flags =BDRV_O_CACHE_WB ; ret =bdrv_parse_cache_flags (cache, &flags);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);
@@ -1883,7 +1882,7 @@ static int img_convert(int argc, char **argv) goto out; } - src_flags =BDRV_O_FLAGS ; + src_flags =BDRV_O_CACHE_WB ; ret =bdrv_parse_cache_flags (src_cache, &src_flags);if (ret <0 ) {error_report ("Invalid source cache option: %s" , src_cache);
@@ -2236,7 +2235,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts,g_hash_table_insert (filenames, (gpointer )filename,NULL ); blk =img_open (image_opts, filename, fmt, -BDRV_O_FLAGS |BDRV_O_NO_BACKING |BDRV_O_NO_IO , +BDRV_O_CACHE_WB |BDRV_O_NO_BACKING |BDRV_O_NO_IO , false);if (!blk) { goto err;
@@ -2567,7 +2566,7 @@ static int img_map(int argc, char **argv)return 1 ; } - blk =img_open (image_opts, filename, fmt,BDRV_O_FLAGS , false); + blk =img_open (image_opts, filename, fmt,BDRV_O_CACHE_WB , false);if (!blk) {return 1 ; }
@@ -2631,7 +2630,7 @@ static int img_snapshot(int argc, char **argv)Error *err =NULL ;bool image_opts = false; - bdrv_oflags =BDRV_O_FLAGS |BDRV_O_RDWR ; + bdrv_oflags =BDRV_O_CACHE_WB |BDRV_O_RDWR ;/* Parse commandline parameters */ for (;;) {static const struct option long_options[] = {
@@ -2870,7 +2869,7 @@ static int img_rebase(int argc, char **argv) goto out; } - src_flags =BDRV_O_FLAGS ; + src_flags =BDRV_O_CACHE_WB ; ret =bdrv_parse_cache_flags (src_cache, &src_flags);if (ret <0 ) {error_report ("Invalid source cache option: %s" , src_cache);
@@ -3221,7 +3220,7 @@ static int img_resize(int argc, char **argv)qemu_opts_del (param); blk =img_open (image_opts, filename, fmt, -BDRV_O_FLAGS |BDRV_O_RDWR , quiet); +BDRV_O_CACHE_WB |BDRV_O_RDWR , quiet);if (!blk) { ret =-1 ; goto out;
@@ -3373,7 +3372,7 @@ static int img_amend(int argc, char **argv) goto out; } - flags =BDRV_O_FLAGS |BDRV_O_RDWR ; + flags =BDRV_O_CACHE_WB |BDRV_O_RDWR ; ret =bdrv_parse_cache_flags (cache, &flags);if (ret <0 ) {error_report ("Invalid cache option: %s" , cache);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 27/48] qemu-io: Call blk_set_enable_write_cache() explicitly
In reply to Kevin Wolf--- qemu-io.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
qemu-io.c +13 -8
@@ -50,7 +50,7 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile (char *name,int flags,QDict *opts) +static int openfile (char *name,int flags,bool writethrough,QDict *opts) {Error *local_err =NULL ;BlockDriverState *bs;
@@ -82,6 +82,7 @@ static int openfile(char *name, int flags, QDict *opts) } } +blk_set_enable_write_cache (qemuio_blk, !writethrough);return 0 ;
@@ -136,6 +137,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv) {int flags =0 ;int readonly =0 ; +bool writethrough = true;int c;QemuOpts *qopts;QDict *opts;
@@ -146,7 +148,8 @@ static int open_f(BlockBackend *blk, int argc, char **argv) flags |=BDRV_O_SNAPSHOT ;break ;case 'n' : - flags |=BDRV_O_NOCACHE |BDRV_O_CACHE_WB ; + flags |=BDRV_O_NOCACHE ; + writethrough = false;break ;case 'r' : readonly =1 ;
@@ -184,9 +187,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)qemu_opts_reset (&empty_opts);if (optind == argc -1 ) { -return openfile (argv[optind], flags, opts); +return openfile (argv[optind], flags, writethrough, opts); }else if (optind == argc) { -return openfile (NULL , flags, opts); +return openfile (NULL , flags, writethrough, opts); }else {QDECREF (opts);return qemuio_command_usage (&open_cmd);
@@ -427,6 +430,7 @@ int main(int argc, char **argv)int c;int opt_index =0 ;int flags =BDRV_O_UNMAP ; +bool writethrough = true;Error *local_error =NULL ;QDict *opts =NULL ;const char *format =NULL ;
@@ -448,7 +452,8 @@ int main(int argc, char **argv) flags |=BDRV_O_SNAPSHOT ;break ;case 'n' : - flags |=BDRV_O_NOCACHE |BDRV_O_CACHE_WB ; + flags |=BDRV_O_NOCACHE ; + writethrough = false;break ;case 'd' :if (bdrv_parse_discard_flags (optarg, &flags) <0 ) {
@@ -472,7 +477,7 @@ int main(int argc, char **argv) flags |=BDRV_O_NATIVE_AIO ;break ;case 't' : -if (bdrv_parse_cache_flags (optarg, &flags) <0 ) { +if (bdrv_parse_cache_mode (optarg, &flags, &writethrough) <0 ) {error_report ("Invalid cache option: %s" , optarg);exit (1 ); }
@@ -554,13 +559,13 @@ int main(int argc, char **argv)exit (1 ); } opts =qemu_opts_to_qdict (qopts,NULL ); -openfile (NULL , flags, opts); +openfile (NULL , flags, writethrough, opts); }else {if (format) { opts =qdict_new ();qdict_put (opts,"driver" ,qstring_from_str (format)); } -openfile (argv[optind], flags, opts); +openfile (argv[optind], flags, writethrough, opts); } }command_loop ();
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 29/48] qemu-img: Call blk_set_enable_write_cache() explicitly
In reply to Kevin Wolf--- qemu-img.c | 76 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 32 deletions(-)
qemu-img.c +44 -32
@@ -246,7 +246,7 @@ static int img_open_password(BlockBackend *blk, const char *filename,static BlockBackend *img_open_opts (const char *optstr, -QemuOpts *opts,int flags, +QemuOpts *opts,int flags,bool writethrough,bool quiet) {QDict *options;
@@ -258,6 +258,7 @@ static BlockBackend *img_open_opts(const char *optstr,error_reportf_err (local_err,"Could not open '%s'" , optstr);return NULL ; } +blk_set_enable_write_cache (blk, !writethrough);if (img_open_password (blk, optstr, flags, quiet) <0 ) {blk_unref (blk);
@@ -268,7 +269,7 @@ static BlockBackend *img_open_opts(const char *optstr,static BlockBackend *img_open_file (const char *filename,const char *fmt,int flags, -bool quiet) +bool writethrough,bool quiet) {BlockBackend *blk;Error *local_err =NULL ;
@@ -284,6 +285,7 @@ static BlockBackend *img_open_file(const char *filename,error_reportf_err (local_err,"Could not open '%s': " , filename);return NULL ; } +blk_set_enable_write_cache (blk, !writethrough);if (img_open_password (blk, filename, flags, quiet) <0 ) {blk_unref (blk);
@@ -295,7 +297,7 @@ static BlockBackend *img_open_file(const char *filename,static BlockBackend *img_open (bool image_opts,const char *filename, -const char *fmt,int flags, +const char *fmt,int flags,bool writethrough,bool quiet) {BlockBackend *blk;
@@ -310,9 +312,9 @@ static BlockBackend *img_open(bool image_opts,if (!opts) {return NULL ; } - blk =img_open_opts (filename, opts, flags, quiet); + blk =img_open_opts (filename, opts, flags, writethrough, quiet); }else { - blk =img_open_file (filename, fmt, flags, quiet); + blk =img_open_file (filename, fmt, flags, writethrough, quiet); }return blk; }
@@ -590,7 +592,8 @@ static int img_check(int argc, char **argv)BlockBackend *blk;BlockDriverState *bs;int fix =0 ; -int flags =BDRV_O_CACHE_WB |BDRV_O_CHECK ; +int flags =BDRV_O_CHECK ; +bool writethrough;ImageCheck *check;bool quiet = false;Error *local_err =NULL ;
@@ -599,6 +602,7 @@ static int img_check(int argc, char **argv) fmt =NULL ; output =NULL ; cache =BDRV_DEFAULT_CACHE ; +for (;;) {int option_index =0 ;static const struct option long_options[] = {
@@ -678,13 +682,13 @@ static int img_check(int argc, char **argv)return 1 ; } - ret =bdrv_parse_cache_flags (cache, &flags); + ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);return 1 ; } - blk =img_open (image_opts, filename, fmt, flags, quiet); + blk =img_open (image_opts, filename, fmt, flags, writethrough, quiet);if (!blk) {return 1 ; }
@@ -794,6 +798,7 @@ static int img_commit(int argc, char **argv)BlockBackend *blk;BlockDriverState *bs, *base_bs;bool progress = false, quiet = false, drop = false; +bool writethrough;Error *local_err =NULL ;CommonBlockJobCBInfo cbi;bool image_opts = false;
@@ -870,13 +875,13 @@ static int img_commit(int argc, char **argv) } flags =BDRV_O_RDWR |BDRV_O_UNMAP ; - ret =bdrv_parse_cache_flags (cache, &flags); + ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid cache option: %s" , cache);return 1 ; } - blk =img_open (image_opts, filename, fmt, flags, quiet); + blk =img_open (image_opts, filename, fmt, flags, writethrough, quiet);if (!blk) {return 1 ; }
@@ -1120,6 +1125,7 @@ static int img_compare(int argc, char **argv)int ret =0 ;/* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false;int flags; +bool writethrough;int64_t total_sectors;int64_t sector_num =0 ;int64_t nb_sectors;
@@ -1202,21 +1208,21 @@ static int img_compare(int argc, char **argv)/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =BDRV_O_CACHE_WB ; - ret =bdrv_parse_cache_flags (cache, &flags); + flags =0 ; + ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache); ret =2 ; goto out3; } - blk1 =img_open (image_opts, filename1, fmt1, flags, quiet); + blk1 =img_open (image_opts, filename1, fmt1, flags, writethrough, quiet);if (!blk1) { ret =2 ; goto out3; } - blk2 =img_open (image_opts, filename2, fmt2, flags, quiet); + blk2 =img_open (image_opts, filename2, fmt2, flags, writethrough, quiet);if (!blk2) { ret =2 ; goto out2;
@@ -1710,6 +1716,7 @@ static int img_convert(int argc, char **argv)int c, bs_n, bs_i, compress, cluster_sectors, skip_create;int64_t ret =0 ;int progress =0 , flags, src_flags; +bool writethrough, src_writethrough;const char *fmt, *out_fmt, *cache, *src_cache, *out_baseimg, *out_filename;BlockDriver *drv, *proto_drv;BlockBackend **blk =NULL , *out_blk =NULL ;
@@ -1882,8 +1889,8 @@ static int img_convert(int argc, char **argv) goto out; } - src_flags =BDRV_O_CACHE_WB ; - ret =bdrv_parse_cache_flags (src_cache, &src_flags); + src_flags =0 ; + ret =bdrv_parse_cache_mode (src_cache, &src_flags, &src_writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , src_cache); goto out;
@@ -1898,7 +1905,7 @@ static int img_convert(int argc, char **argv) total_sectors =0 ;for (bs_i =0 ; bs_i < bs_n; bs_i++) { blk[bs_i] =img_open (image_opts, argv[optind + bs_i], - fmt, src_flags, quiet); + fmt, src_flags, src_writethrough, quiet);if (!blk[bs_i]) { ret =-1 ; goto out;
@@ -2032,7 +2039,7 @@ static int img_convert(int argc, char **argv) } flags = min_sparse ? (BDRV_O_RDWR |BDRV_O_UNMAP ) :BDRV_O_RDWR ; - ret =bdrv_parse_cache_flags (cache, &flags); + ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid cache option: %s" , cache); goto out;
@@ -2043,7 +2050,7 @@ static int img_convert(int argc, char **argv)* the bdrv_create() call which takes different params. * Not critical right now, so fix can wait... */ - out_blk =img_open_file (out_filename, out_fmt, flags, quiet); + out_blk =img_open_file (out_filename, out_fmt, flags, writethrough, quiet);if (!out_blk) { ret =-1 ; goto out;
@@ -2235,8 +2242,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts,g_hash_table_insert (filenames, (gpointer )filename,NULL ); blk =img_open (image_opts, filename, fmt, -BDRV_O_CACHE_WB |BDRV_O_NO_BACKING |BDRV_O_NO_IO , - false); +BDRV_O_NO_BACKING |BDRV_O_NO_IO , false, false);if (!blk) { goto err; }
@@ -2566,7 +2572,7 @@ static int img_map(int argc, char **argv)return 1 ; } - blk =img_open (image_opts, filename, fmt,BDRV_O_CACHE_WB , false); + blk =img_open (image_opts, filename, fmt,0 , false, false);if (!blk) {return 1 ; }
@@ -2630,7 +2636,7 @@ static int img_snapshot(int argc, char **argv)Error *err =NULL ;bool image_opts = false; - bdrv_oflags =BDRV_O_CACHE_WB |BDRV_O_RDWR ; + bdrv_oflags =BDRV_O_RDWR ;/* Parse commandline parameters */ for (;;) {static const struct option long_options[] = {
@@ -2711,7 +2717,7 @@ static int img_snapshot(int argc, char **argv) }/* Open the image */ - blk =img_open (image_opts, filename,NULL , bdrv_oflags, quiet); + blk =img_open (image_opts, filename,NULL , bdrv_oflags, false, quiet);if (!blk) {return 1 ; }
@@ -2773,6 +2779,7 @@ static int img_rebase(int argc, char **argv)char *filename;const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;int c, flags, src_flags, ret; +bool writethrough, src_writethrough;int unsafe =0 ;int progress =0 ;bool quiet = false;
@@ -2863,26 +2870,30 @@ static int img_rebase(int argc, char **argv)qemu_progress_print (0 ,100 ); flags =BDRV_O_RDWR | (unsafe ?BDRV_O_NO_BACKING :0 ); - ret =bdrv_parse_cache_flags (cache, &flags); + ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid cache option: %s" , cache); goto out; } - src_flags =BDRV_O_CACHE_WB ; - ret =bdrv_parse_cache_flags (src_cache, &src_flags); + src_flags =0 ; + ret =bdrv_parse_cache_mode (src_cache, &src_flags, &src_writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , src_cache); goto out; } +/* The source files are opened read-only, don't care about WCE */ +assert ((src_flags &BDRV_O_RDWR ) ==0 ); + (void ) src_writethrough; +/* * Open the images. * * Ignore the old backing file for unsafe rebase in case we want to correct * the reference to a renamed or moved backing file. */ - blk =img_open (image_opts, filename, fmt, flags, quiet); + blk =img_open (image_opts, filename, fmt, flags, writethrough, quiet);if (!blk) { ret =-1 ; goto out;
@@ -3220,7 +3231,7 @@ static int img_resize(int argc, char **argv)qemu_opts_del (param); blk =img_open (image_opts, filename, fmt, -BDRV_O_CACHE_WB |BDRV_O_RDWR , quiet); +BDRV_O_RDWR , false, quiet);if (!blk) { ret =-1 ; goto out;
@@ -3276,6 +3287,7 @@ static int img_amend(int argc, char **argv)QemuOpts *opts =NULL ;const char *fmt =NULL , *filename, *cache;int flags; +bool writethrough;bool quiet = false, progress = false;BlockBackend *blk =NULL ;BlockDriverState *bs =NULL ;
@@ -3372,14 +3384,14 @@ static int img_amend(int argc, char **argv) goto out; } - flags =BDRV_O_CACHE_WB |BDRV_O_RDWR ; - ret =bdrv_parse_cache_flags (cache, &flags); + flags =BDRV_O_RDWR ; + ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid cache option: %s" , cache); goto out; } - blk =img_open (image_opts, filename, fmt, flags, quiet); + blk =img_open (image_opts, filename, fmt, flags, writethrough, quiet);if (!blk) { ret =-1 ; goto out;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 30/48] xen_disk: Call blk_set_enable_write_cache() explicitly
In reply to Kevin Wolf--- hw/block/xen_disk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/block/xen_disk.c +4 -1
@@ -888,12 +888,14 @@ static int blk_connect(struct XenDevice *xendev) struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int pers, index, qflags;bool readonly = true; +bool writethrough = true;/* read-only ? */ if (blkdev->directiosafe) { qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; }else { - qflags =BDRV_O_CACHE_WB ; + qflags =0 ; + writethrough = false; }if (strcmp (blkdev->mode,"w" ) ==0 ) { qflags |=BDRV_O_RDWR ;
@@ -925,6 +927,7 @@ static int blk_connect(struct XenDevice *xendev)error_free (local_err);return -1 ; } +blk_set_enable_write_cache (blkdev->blk, !writethrough); }else {/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 33/48] block: Handle flush error in bdrv_pwrite_sync()
In reply to Kevin WolfWe don't want to silently ignore a flush error.
Also, there is little point in avoiding the flush for writethrough modes and once WCE is moved to the BB layer, we definitely need the flush here because bdrv_pwrite() won't involve one any more.
--- block/io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
block/io.c +3 -3
@@ -745,9 +745,9 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,return ret; } -/* No flush needed for cache modes that already do it */ -if (bs->enable_write_cache) { -bdrv_flush (bs); + ret =bdrv_flush (bs); +if (ret <0 ) { +return ret; }return 0 ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 31/48] block: blockdev_init(): Call blk_set_enable_write_cache() explicitly
In reply to Kevin Wolf--- blockdev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
blockdev.c +9 -1
@@ -467,6 +467,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,int bdrv_flags =0 ;int on_read_error, on_write_error;bool account_invalid, account_failed; +bool writethrough;BlockBackend *blk;BlockDriverState *bs;ThrottleConfig cfg;
@@ -505,6 +506,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, account_invalid =qemu_opt_get_bool (opts,"stats-account-invalid" , true); account_failed =qemu_opt_get_bool (opts,"stats-account-failed" , true); + writethrough = !qemu_opt_get_bool (opts,BDRV_OPT_CACHE_WB , true); +qdict_extract_subqdict (bs_opts, &interval_dict,"stats-intervals." );qdict_array_split (interval_dict, &interval_list);
@@ -590,7 +593,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,/* bdrv_open() defaults to the values in bdrv_flags (for compatibility * with other callers) rather than what we want as the real defaults. * Apply the defaults here instead. */ -qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_WB ,"on" ); +qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_WB , writethrough ?"off" :"on" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_DIRECT ,"off" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_NO_FLUSH ,"off" );
@@ -628,6 +631,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, } } +blk_set_enable_write_cache (blk, !writethrough);blk_set_on_error (blk, on_read_error, on_write_error);if (!monitor_add_blk (blk,qemu_opts_id (opts), errp)) {
@@ -4129,6 +4133,10 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_STRING, .help = "host AIO implementation (threads, native)", },{ + .name = BDRV_OPT_CACHE_WB, + .type = QEMU_OPT_BOOL, + .help = "Enable writeback mode", + },{ .name = "format", .type = QEMU_OPT_STRING, .help = "disk format (raw, qcow2, ...)",
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 34/48] block: Move enable_write_cache to BB level
In reply to Kevin WolfWhether a write cache is used or not is a decision that concerns the user (e.g. the guest device) rather than the backend. It was already logically part of the BB level as bdrv_move_feature_fields() always kept it on top of the BDS tree; with this patch, the core of it (the actual flag and the additional flushes) is also implemented there.
Direct callers of bdrv_open() must pass BDRV_O_CACHE_WB now if bs doesn't have a BlockBackend attached.
--- block.c | 26 +++++++++++++++++--------- block/block-backend.c | 42 +++++++++++++++++++++++++++--------------- block/io.c | 2 +- block/iscsi.c | 2 +- include/block/block.h | 1 + include/block/block_int.h | 3 --- tests/qemu-iotests/142 | 4 ++-- tests/qemu-iotests/142.out | 8 ++++---- 8 files changed, 53 insertions(+), 35 deletions(-)
block.c +17 -9
@@ -2037,6 +2037,11 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, goto error; } } +if (!reopen_state->bs->blk && !(reopen_state->flags &BDRV_O_CACHE_WB )) { +error_setg (errp,"Cannot disable cache.writeback: No BlockBackend" ); + ret = -EINVAL ; + goto error; + }/* node-name and driver must be unchanged. Put them back into the QDict, so * that they are checked at the end of this function. */
@@ -2137,10 +2142,10 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) reopen_state->bs->explicit_options = reopen_state->explicit_options; reopen_state->bs->open_flags = reopen_state->flags; - reopen_state->bs->enable_write_cache = !!(reopen_state->flags & -BDRV_O_CACHE_WB ); reopen_state->bs->read_only = !(reopen_state->flags &BDRV_O_RDWR ); +bdrv_set_enable_write_cache (reopen_state->bs, + !!(reopen_state->flags &BDRV_O_CACHE_WB ));bdrv_refresh_limits (reopen_state->bs,NULL ); }
@@ -2270,9 +2275,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest, BlockDriverState *bs_src) {/* move some fields that need to stay attached to the device */ - -/* dev info */ - bs_dest->enable_write_cache = bs_src->enable_write_cache; } static void change_parent_backing_link(BlockDriverState *from,
@@ -2752,12 +2754,18 @@ int bdrv_is_sg(BlockDriverState *bs)int bdrv_enable_write_cache (BlockDriverState *bs) { -return bs->enable_write_cache; +if (bs->blk) { +return blk_enable_write_cache (bs->blk); + }else { +return true; + } }void bdrv_set_enable_write_cache (BlockDriverState *bs,bool wce) { - bs->enable_write_cache = wce; +if (bs->blk) { +blk_set_enable_write_cache (bs->blk, wce); + }/* so a reopen() will preserve wce */ if (wce) {
@@ -3617,8 +3625,8 @@ void bdrv_img_create(const char *filename, const char *fmt, }/* backing files always opened read-only */ - back_flags = - flags & ~(BDRV_O_RDWR |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING ); + back_flags = flags |BDRV_O_CACHE_WB ; + back_flags &= ~(BDRV_O_RDWR |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING );if (backing_fmt) { backing_options =qdict_new ();
block/block-backend.c +27 -15
81 lines not on this page · raw message
block/io.c +1 -1
@@ -1158,7 +1158,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, }bdrv_debug_event (bs,BLKDBG_PWRITEV_DONE ); -if (ret ==0 && !bs->enable_write_cache) { +if (ret ==0 && (flags &BDRV_REQ_FUA )) { ret =bdrv_co_flush (bs); }
block/iscsi.c +1 -1
@@ -476,7 +476,7 @@ static int coroutine_fn iscsi_co_writev(BlockDriverState *bs, num_sectors =sector_qemu2lun (nb_sectors, iscsilun);iscsi_co_init_iscsitask (iscsilun, &iTask); retry: - fua = iscsilun->dpofua && !bs->enable_write_cache; + fua = iscsilun->dpofua && !bdrv_enable_write_cache (bs); iTask.force_next_flush = !fua;if (iscsilun->use_16_for_rw) { iTask.task = iscsi_write16_task(iscsilun->iscsi, iscsilun->lun, lba,
include/block/block.h +1 -0
@@ -64,6 +64,7 @@ typedef enum {*/ BDRV_REQ_MAY_UNMAP =0x4 ,BDRV_REQ_NO_SERIALISING =0x8 , +BDRV_REQ_FUA =0x10 , } BdrvRequestFlags; typedef struct BlockSizes {
include/block/block_int.h +0 -3
@@ -442,9 +442,6 @@ struct BlockDriverState {/* Alignment requirement for offset/length of I/O requests */ unsigned int request_alignment; -/* do we need to tell the quest if we have a volatile write cache? */ -int enable_write_cache; -/* the following member gives a name to every node on the bs graph. */ char node_name[32 ];/* element of the list of named nodes building the graph */
tests/qemu-iotests/142 +2 -2
@@ -338,8 +338,8 @@ echo # TODO Implement node-name support for 'qemu-io' HMP command for -c # Can use only -o to access child node options for now -hmp_cmds="qemu-io none0 \"reopen -o file.cache.writeback=off,file.cache.direct=off,file.cache.no-flush=off\" -qemu-io none0 \"reopen -o backing.file.cache.writeback=on,backing.file.cache.direct=off,backing.file.cache.no-flush=on\" +hmp_cmds="qemu-io none0 \"reopen -o file.cache.direct=off,file.cache.no-flush=off\" +qemu-io none0 \"reopen -o backing.file.cache.direct=off,backing.file.cache.no-flush=on\" qemu-io none0 \"reopen -c none\" info block image info block file
tests/qemu-iotests/142.out +4 -4
@@ -132,7 +132,7 @@ cache.direct=on on backing-file cache.writeback=off on none0 Cache mode: writethrough - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback Cache mode: writeback Cache mode: writeback
@@ -342,7 +342,7 @@ cache.direct=on on backing-file cache.writeback=off on none0 Cache mode: writeback, direct - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback Cache mode: writeback Cache mode: writeback
@@ -503,7 +503,7 @@ cache.direct=on on backing-file cache.writeback=off on blk Cache mode: writethrough - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback Cache mode: writeback Cache mode: writeback
@@ -707,7 +707,7 @@ cache.no-flush=on on backing-file --- Change cache mode after reopening child --- Cache mode: writeback, direct - Cache mode: writethrough + Cache mode: writeback Cache mode: writeback, direct Cache mode: writeback, ignore flushes *** done
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 37/48] iscsi: Support BDRV_REQ_FUA
In reply to Kevin WolfThis replaces the existing hack in the iscsi driver that sent the FUA bit in writethrough mode and ignored the following flush in order to optimise the number of roundtrips (see commit 73b5394e).
--- block/iscsi.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
block/iscsi.c +14 -16
@@ -70,7 +70,6 @@ typedef struct IscsiLun {bool lbprz;bool dpofua;bool has_write_same; -bool force_next_flush;bool request_timed_out; } IscsiLun;
@@ -84,7 +83,6 @@ typedef struct IscsiTask {QEMUBH *bh;IscsiLun *iscsilun;QEMUTimer retry_timer; -bool force_next_flush;int err_code; } IscsiTask;
@@ -282,8 +280,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status, } iTask->err_code =iscsi_translate_sense (&task->sense);error_report ("iSCSI Failure: %s" ,iscsi_get_error (iscsi)); - }else { - iTask->iscsilun->force_next_flush |= iTask->force_next_flush; } out:
@@ -452,15 +448,15 @@ static void iscsi_allocationmap_clear(IscsiLun *iscsilun, int64_t sector_num, } } -static int coroutine_fn iscsi_co_writev(BlockDriverState *bs, -int64_t sector_num,int nb_sectors, -QEMUIOVector *iov) +static int coroutine_fn +iscsi_co_writev_flags (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *iov,int flags) {IscsiLun *iscsilun = bs->opaque;struct IscsiTask iTask;uint64_t lba;uint32_t num_sectors; -int fua; +bool fua;if (!is_request_lun_aligned (sector_num, nb_sectors, iscsilun)) {return -EINVAL ;
@@ -476,8 +472,7 @@ static int coroutine_fn iscsi_co_writev(BlockDriverState *bs, num_sectors =sector_qemu2lun (nb_sectors, iscsilun);iscsi_co_init_iscsitask (iscsilun, &iTask); retry: - fua = iscsilun->dpofua && !bdrv_enable_write_cache (bs); - iTask.force_next_flush = !fua; + fua = iscsilun->dpofua && (flags &BDRV_REQ_FUA );if (iscsilun->use_16_for_rw) { iTask.task = iscsi_write16_task(iscsilun->iscsi, iscsilun->lun, lba, NULL, num_sectors * iscsilun->block_size,
@@ -518,6 +513,13 @@ retry:return 0 ; } +static int coroutine_fn +iscsi_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *iov) +{ +return iscsi_co_writev_flags (bs, sector_num, nb_sectors, iov,0 ); +} +static bool iscsi_allocationmap_is_allocated (IscsiLun *iscsilun,int64_t sector_num,int nb_sectors)
@@ -715,11 +717,6 @@ static int coroutine_fn iscsi_co_flush(BlockDriverState *bs)IscsiLun *iscsilun = bs->opaque;struct IscsiTask iTask; -if (!iscsilun->force_next_flush) { -return 0 ; - } - iscsilun->force_next_flush = false; -iscsi_co_init_iscsitask (iscsilun, &iTask); retry: if (iscsi_synchronizecache10_task(iscsilun->iscsi, iscsilun->lun, 0, 0, 0,
@@ -1019,7 +1016,6 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, }iscsi_co_init_iscsitask (iscsilun, &iTask); - iTask.force_next_flush = true; retry:if (use_16_for_ws) { iTask.task = iscsi_writesame16_task(iscsilun->iscsi, iscsilun->lun, lba,
@@ -1852,6 +1848,8 @@ static BlockDriver bdrv_iscsi = { .bdrv_co_write_zeroes = iscsi_co_write_zeroes, .bdrv_co_readv = iscsi_co_readv, .bdrv_co_writev = iscsi_co_writev, + .bdrv_co_writev_flags = iscsi_co_writev_flags, + .supported_write_flags = BDRV_REQ_FUA, .bdrv_co_flush_to_disk = iscsi_co_flush, #ifdef __linux__
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 32/48] block: Always set writeback mode in blk_new_open()
In reply to Kevin WolfAll callers of blk_new_open() either don't rely on the WCE bit set after blk_new_open() because they explicitly set it anyway, or they pass BDRV_O_CACHE_WB unconditionally.
This patch changes blk_new_open() so that it always enables writeback mode and asserts that BDRV_O_CACHE_WB is clear. For those callers that used to pass BDRV_O_CACHE_WB unconditionally, the flag is removed now.
--- block/block-backend.c | 4 ++++ block/crypto.c | 3 +-- block/parallels.c | 3 +-- block/qcow.c | 3 +-- block/qcow2.c | 9 +++------ block/qed.c | 3 +-- block/sheepdog.c | 5 ++--- block/vdi.c | 3 +-- block/vhdx.c | 3 +-- block/vmdk.c | 8 +++----- block/vpc.c | 3 +-- blockdev.c | 1 + 12 files changed, 20 insertions(+), 28 deletions(-)
block/block-backend.c +4 -0
@@ -147,6 +147,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,BlockBackend *blk;int ret; +assert ((flags &BDRV_O_CACHE_WB ) ==0 ); + blk =blk_new_with_bs (errp);if (!blk) {QDECREF (options);
@@ -159,6 +161,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,return NULL ; } +blk_set_enable_write_cache (blk, true); +return blk; }
block/crypto.c +1 -2
@@ -120,8 +120,7 @@ static ssize_t block_crypto_init_func(QCryptoBlock *block, } data->blk =blk_new_open (data->filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - errp); +BDRV_O_RDWR |BDRV_O_PROTOCOL , errp);if (!data->blk) {return -1 ; }
block/parallels.c +1 -2
@@ -479,8 +479,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp) } file =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (file ==NULL ) {error_propagate (errp, local_err);return -EIO ;
block/qcow.c +1 -2
@@ -803,8 +803,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) } qcow_blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (qcow_blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
block/qcow2.c +3 -6
@@ -2168,8 +2168,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, } blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err);return -EIO ;
@@ -2233,8 +2232,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, options =qdict_new ();qdict_put (options,"driver" ,qstring_from_str ("qcow2" )); blk =blk_new_open (filename,NULL , options, -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_FLUSH , - &local_err); +BDRV_O_RDWR |BDRV_O_NO_FLUSH , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
@@ -2295,8 +2293,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, options =qdict_new ();qdict_put (options,"driver" ,qstring_from_str ("qcow2" )); blk =blk_new_open (filename,NULL , options, -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_BACKING , - &local_err); +BDRV_O_RDWR |BDRV_O_NO_BACKING , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
block/qed.c +1 -2
@@ -575,8 +575,7 @@ static int qed_create(const char *filename, uint32_t cluster_size, } blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err);return -EIO ;
block/sheepdog.c +2 -3
@@ -1647,8 +1647,7 @@ static int sd_prealloc(const char *filename, Error **errp)int ret; blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - errp); +BDRV_O_RDWR |BDRV_O_PROTOCOL , errp);if (blk ==NULL ) { ret = -EIO ; goto out_with_err_set;
@@ -1844,7 +1843,7 @@ static int sd_create(const char *filename, QemuOpts *opts, } blk =blk_new_open (backing_file,NULL ,NULL , -BDRV_O_PROTOCOL |BDRV_O_CACHE_WB , errp); +BDRV_O_PROTOCOL , errp);if (blk ==NULL ) { ret = -EIO ; goto out;
block/vdi.c +1 -2
@@ -769,8 +769,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp) } blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
block/vhdx.c +1 -2
@@ -1839,8 +1839,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) } blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
block/vmdk.c +3 -5
@@ -1662,8 +1662,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, } blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
@@ -1947,7 +1946,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) } blk =blk_new_open (full_backing,NULL ,NULL , -BDRV_O_NO_BACKING |BDRV_O_CACHE_WB , errp); +BDRV_O_NO_BACKING , errp);g_free (full_backing);if (blk ==NULL ) { ret = -EIO ;
@@ -2019,8 +2018,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) } new_blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (new_blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
block/vpc.c +1 -2
@@ -889,8 +889,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) } blk =blk_new_open (filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); +BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err);if (blk ==NULL ) {error_propagate (errp, local_err); ret = -EIO ;
blockdev.c +1 -0
@@ -596,6 +596,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_WB , writethrough ?"off" :"on" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_DIRECT ,"off" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_NO_FLUSH ,"off" ); +assert ((bdrv_flags &BDRV_O_CACHE_MASK ) ==0 );if (runstate_check (RUN_STATE_INMIGRATE )) { bdrv_flags |=BDRV_O_INACTIVE ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 36/48] block: Introduce bdrv_co_writev_flags()
In reply to Kevin WolfThis function will allow drivers to implement BDRV_REQ_FUA natively instead of sending a separate flush after the write.
--- block/io.c | 9 ++++++++- include/block/block_int.h | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-)
block/io.c +8 -1
@@ -1152,13 +1152,20 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, }else if (flags &BDRV_REQ_ZERO_WRITE ) {bdrv_debug_event (bs,BLKDBG_PWRITEV_ZERO ); ret =bdrv_co_do_write_zeroes (bs, sector_num, nb_sectors, flags); + }else if (drv->bdrv_co_writev_flags) { +bdrv_debug_event (bs,BLKDBG_PWRITEV ); + ret = drv->bdrv_co_writev_flags (bs, sector_num, nb_sectors, qiov, + flags); }else { +assert (drv->supported_write_flags ==0 );bdrv_debug_event (bs,BLKDBG_PWRITEV ); ret = drv->bdrv_co_writev (bs, sector_num, nb_sectors, qiov); }bdrv_debug_event (bs,BLKDBG_PWRITEV_DONE ); -if (ret ==0 && (flags &BDRV_REQ_FUA )) { +if (ret ==0 && (flags &BDRV_REQ_FUA ) && + !(drv->supported_write_flags &BDRV_REQ_FUA )) + { ret =bdrv_co_flush (bs); }
include/block/block_int.h +5 -0
@@ -155,6 +155,11 @@ struct BlockDriver { int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov); + int coroutine_fn (*bdrv_co_writev_flags)(BlockDriverState *bs, +int64_t sector_num,int nb_sectors,QEMUIOVector *qiov,int flags); + +int supported_write_flags; +/* * Efficiently zero a region of the disk image. Typically an image format * would use a compact metadata representation to implement this. This
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 35/48] block/qapi: Use blk_enable_write_cache()
In reply to Kevin WolfNow that WCE is handled on the BlockBackend level, the flag is meaningless for BDSes. As the schema requires us to fill the field, we return an enabled write cache for them.
Note that this means that querying the BlockBackend name may return writethrough as the cache information, whereas querying the node-name of the root of that same BlockBackend will return writeback.
This may appear odd at first, but it actually makes sense because it correctly repesents the layer that implements the WCE handling. This becomes more apparent when you consider nodes that are the root node of multiple BlockBackends, where each BB can have its own WCE setting.
--- block.c | 2 +- block/qapi.c | 7 +++--- include/block/qapi.h | 3 ++- tests/qemu-iotests/142 | 7 +++++- tests/qemu-iotests/142.out | 57 ++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 60 insertions(+), 16 deletions(-)
block.c +1 -1
@@ -2916,7 +2916,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(Error **errp) list =NULL ; QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) { -BlockDeviceInfo *info =bdrv_block_device_info (bs, errp); +BlockDeviceInfo *info =bdrv_block_device_info (NULL , bs, errp);if (!info) {qapi_free_BlockDeviceInfoList (list);return NULL ;
block/qapi.c +4 -3
@@ -33,7 +33,8 @@#include "qapi/qmp/types.h" #include "sysemu/block-backend.h" -BlockDeviceInfo *bdrv_block_device_info (BlockDriverState *bs,Error **errp) +BlockDeviceInfo *bdrv_block_device_info (BlockBackend *blk, +BlockDriverState *bs,Error **errp) {ImageInfo **p_image_info;BlockDriverState *bs0;
@@ -47,7 +48,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp) info->cache =g_new (BlockdevCacheInfo,1 ); *info->cache = (BlockdevCacheInfo ) { - .writeback =bdrv_enable_write_cache (bs), + .writeback = blk ?blk_enable_write_cache (blk) : true, .direct = !!(bs->open_flags &BDRV_O_NOCACHE ), .no_flush = !!(bs->open_flags &BDRV_O_NO_FLUSH ), };
@@ -342,7 +343,7 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,if (bs && bs->drv) { info->has_inserted = true; - info->inserted =bdrv_block_device_info (bs, errp); + info->inserted =bdrv_block_device_info (blk, bs, errp);if (info->inserted ==NULL ) { goto err; }
include/block/qapi.h +2 -1
@@ -29,7 +29,8 @@#include "block/block.h" #include "block/snapshot.h" -BlockDeviceInfo *bdrv_block_device_info (BlockDriverState *bs,Error **errp); +BlockDeviceInfo *bdrv_block_device_info (BlockBackend *blk, +BlockDriverState *bs,Error **errp);int bdrv_query_snapshot_info_list (BlockDriverState *bs,SnapshotInfoList **p_list,Error **errp);
tests/qemu-iotests/142 +6 -1
@@ -134,7 +134,8 @@ echo # First check the inherited cache mode after opening the image. -hmp_cmds="info block image +hmp_cmds="info block none0 +info block image info block file info block backing info block backing-file"
@@ -164,6 +165,7 @@ echo # new cache mode is specified in the flags, not as an option. hmp_cmds='qemu-io none0 "reopen -c none" +info block none0 info block image info block file info block backing
@@ -179,6 +181,7 @@ echo # new cache mode is specified as an option, not in the flags. hmp_cmds='qemu-io none0 "reopen -o cache.direct=on" +info block none0 info block image info block file info block backing
@@ -214,6 +217,7 @@ echo # options from its parent node. hmp_cmds="qemu-io none0 \"reopen -o cache.writeback=off,cache.direct=on,cache.no-flush=on\" +info block none0 info block image info block blkdebug info block file"
@@ -321,6 +325,7 @@ echo "--- Basic reopen ---" echo hmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on" +info block none0 info block image info block file info block backing
tests/qemu-iotests/142.out +47 -10
323 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 39/48] raw: Support BDRV_REQ_FUA
In reply to Kevin WolfPass through the FUA flag to the lower layer so that the separate flush can be saved in practically relevant cases where a (raw) format driver sits on top of the protocol driver.
--- block/raw_bsd.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
block/raw_bsd.c +14 -3
@@ -56,8 +56,9 @@ static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,return bdrv_co_readv (bs->file->bs, sector_num, nb_sectors, qiov); } -static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num, -int nb_sectors,QEMUIOVector *qiov) +static int coroutine_fn +raw_co_writev_flags (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov,int flags) {void *buf =NULL ;BlockDriver *drv;
@@ -103,7 +104,8 @@ static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num, }BLKDBG_EVENT (bs->file,BLKDBG_WRITE_AIO ); - ret =bdrv_co_writev (bs->file->bs, sector_num, nb_sectors, qiov); + ret =bdrv_co_do_pwritev (bs->file->bs, sector_num *BDRV_SECTOR_SIZE , + nb_sectors *BDRV_SECTOR_SIZE , qiov, flags); fail:if (qiov == &local_qiov) {
@@ -113,6 +115,13 @@ fail:return ret; } +static int coroutine_fn +raw_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors, +QEMUIOVector *qiov) +{ +return raw_co_writev_flags (bs, sector_num, nb_sectors, qiov,0 ); +} + static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum,
@@ -247,6 +256,8 @@ BlockDriver bdrv_raw = { .bdrv_create = &raw_create, .bdrv_co_readv = &raw_co_readv, .bdrv_co_writev = &raw_co_writev, + .bdrv_co_writev_flags = &raw_co_writev_flags, + .supported_write_flags = BDRV_REQ_FUA, .bdrv_co_write_zeroes = &raw_co_write_zeroes, .bdrv_co_discard = &raw_co_discard, .bdrv_co_get_block_status = &raw_co_get_block_status,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 38/48] nbd: Support BDRV_REQ_FUA
In reply to Kevin WolfThe NBD server already used to send a FUA flag when the writethrough mode was set. This code was a remnant from the times where protocol drivers actually had to implement writethrough modes. Since nowadays the block layer sends flushes in writethrough mode and non-root nodes are always writeback, this was mostly dead code - only mostly because if NBD was configured to be used without a format, we sent _both_ FUA and an explicit flush afterwards, which makes the code not technically dead, but useless overhead.
This patch changes the code so that the block layer's FUA flag is recognised and translated into a NBD FUA flag. The additional flush is avoided now.
--- block/nbd-client.c | 13 +++++++------ block/nbd-client.h | 2 +- block/nbd.c | 27 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-)
block/nbd-client.c +7 -6
@@ -243,15 +243,15 @@ static int nbd_co_readv_1(BlockDriverState *bs, int64_t sector_num,static int nbd_co_writev_1 (BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov, -int offset) +int offset,int *flags) {NbdClientSession *client =nbd_get_client_session (bs);struct nbd_request request = { .type =NBD_CMD_WRITE };struct nbd_reply reply;ssize_t ret; -if (!bdrv_enable_write_cache (bs) && - (client->nbdflags &NBD_FLAG_SEND_FUA )) { +if ((*flags &BDRV_REQ_FUA ) && (client->nbdflags &NBD_FLAG_SEND_FUA )) { + *flags &= ~BDRV_REQ_FUA ; request.type |=NBD_CMD_FLAG_FUA ; }
@@ -291,12 +291,13 @@ int nbd_client_co_readv(BlockDriverState *bs, int64_t sector_num, }int nbd_client_co_writev (BlockDriverState *bs,int64_t sector_num, -int nb_sectors,QEMUIOVector *qiov) +int nb_sectors,QEMUIOVector *qiov,int *flags) {int offset =0 ;int ret;while (nb_sectors >NBD_MAX_SECTORS ) { - ret =nbd_co_writev_1 (bs, sector_num,NBD_MAX_SECTORS , qiov, offset); + ret =nbd_co_writev_1 (bs, sector_num,NBD_MAX_SECTORS , qiov, offset, + flags);if (ret <0 ) {return ret; }
@@ -304,7 +305,7 @@ int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num, sector_num +=NBD_MAX_SECTORS ; nb_sectors -=NBD_MAX_SECTORS ; } -return nbd_co_writev_1 (bs, sector_num, nb_sectors, qiov, offset); +return nbd_co_writev_1 (bs, sector_num, nb_sectors, qiov, offset, flags); }int nbd_client_co_flush (BlockDriverState *bs)
block/nbd-client.h +1 -1
@@ -48,7 +48,7 @@ int nbd_client_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);int nbd_client_co_flush (BlockDriverState *bs);int nbd_client_co_writev (BlockDriverState *bs,int64_t sector_num, -int nb_sectors,QEMUIOVector *qiov); +int nb_sectors,QEMUIOVector *qiov,int *flags);int nbd_client_co_readv (BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov);
block/nbd.c +26 -1
@@ -354,10 +354,29 @@ static int nbd_co_readv(BlockDriverState *bs, int64_t sector_num,return nbd_client_co_readv (bs, sector_num, nb_sectors, qiov); } +static int nbd_co_writev_flags (BlockDriverState *bs,int64_t sector_num, +int nb_sectors,QEMUIOVector *qiov,int flags) +{ +int ret; + + ret =nbd_client_co_writev (bs, sector_num, nb_sectors, qiov, &flags); +if (ret <0 ) { +return ret; + } + +/* The flag wasn't sent to the server, so we need to emulate it with an +* explicit flush */ +if (flags &BDRV_REQ_FUA ) { + ret =nbd_client_co_flush (bs); + } + +return ret; +} +static int nbd_co_writev (BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov) { -return nbd_client_co_writev (bs, sector_num, nb_sectors, qiov); +return nbd_co_writev_flags (bs, sector_num, nb_sectors, qiov,0 ); }static int nbd_co_flush (BlockDriverState *bs)
@@ -457,6 +476,8 @@ static BlockDriver bdrv_nbd = { .bdrv_file_open = nbd_open, .bdrv_co_readv = nbd_co_readv, .bdrv_co_writev = nbd_co_writev, + .bdrv_co_writev_flags = nbd_co_writev_flags, + .supported_write_flags = BDRV_REQ_FUA, .bdrv_close = nbd_close, .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard,
@@ -475,6 +496,8 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_file_open = nbd_open, .bdrv_co_readv = nbd_co_readv, .bdrv_co_writev = nbd_co_writev, + .bdrv_co_writev_flags = nbd_co_writev_flags, + .supported_write_flags = BDRV_REQ_FUA, .bdrv_close = nbd_close, .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard,
@@ -493,6 +516,8 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_file_open = nbd_open, .bdrv_co_readv = nbd_co_readv, .bdrv_co_writev = nbd_co_writev, + .bdrv_co_writev_flags = nbd_co_writev_flags, + .supported_write_flags = BDRV_REQ_FUA, .bdrv_close = nbd_close, .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 41/48] qemu-io: Use bdrv_parse_cache_mode() in reopen_f()
In reply to Kevin WolfWe must forbid changing the WCE flag in bdrv_reopen() in the same patch, as otherwise the behaviour would change so that the flag takes precedence over the explicitly specified option.
The correct value of the WCE flag depends on the BlockBackend user (e.g. guest device) and isn't a decision that the QMP client makes, so this change is what we want.
--- block.c | 18 ++++++------------ qemu-io-cmds.c | 14 +++++++++++++- tests/qemu-iotests/142 | 2 +- tests/qemu-iotests/142.out | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-)
block.c +6 -12
@@ -2027,18 +2027,12 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,update_flags_from_options (&reopen_state->flags, opts); -/* If a guest device is attached, it owns WCE */ -if (reopen_state->bs->blk &&blk_get_attached_dev (reopen_state->bs->blk)) { -bool old_wce =bdrv_enable_write_cache (reopen_state->bs); -bool new_wce = (reopen_state->flags &BDRV_O_CACHE_WB ); -if (old_wce != new_wce) { -error_setg (errp,"Cannot change cache.writeback: Device attached" ); - ret = -EINVAL ; - goto error; - } - } -if (!reopen_state->bs->blk && !(reopen_state->flags &BDRV_O_CACHE_WB )) { -error_setg (errp,"Cannot disable cache.writeback: No BlockBackend" ); +/* WCE is a BlockBackend level option, can't change it */ +bool old_wce =bdrv_enable_write_cache (reopen_state->bs); +bool new_wce = (reopen_state->flags &BDRV_O_CACHE_WB ); + +if (old_wce != new_wce) { +error_setg (errp,"Cannot change cache.writeback" ); ret = -EINVAL ; goto error; }
qemu-io-cmds.c +13 -1
@@ -2104,6 +2104,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)QDict *opts;int c;int flags = bs->open_flags; +bool writethrough = !blk_enable_write_cache (blk);BlockReopenQueue *brq;Error *local_err =NULL ;
@@ -2111,7 +2112,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)while ((c =getopt (argc, argv,"c:o:r" )) !=-1 ) {switch (c) {case 'c' : -if (bdrv_parse_cache_flags (optarg, &flags) <0 ) { +if (bdrv_parse_cache_mode (optarg, &flags, &writethrough) <0 ) {error_report ("Invalid cache option: %s" , optarg);return 0 ; }
@@ -2136,14 +2137,25 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)return qemuio_command_usage (&reopen_cmd); } +if (writethrough !=blk_enable_write_cache (blk) && +blk_get_attached_dev (blk)) + { +error_report ("Cannot change cache.writeback: Device attached" ); +qemu_opts_reset (&reopen_opts); +return 0 ; + } + qopts =qemu_opts_find (&reopen_opts,NULL ); opts = qopts ?qemu_opts_to_qdict (qopts,NULL ) :NULL ;qemu_opts_reset (&reopen_opts); + flags |=blk_enable_write_cache (blk) ?BDRV_O_CACHE_WB :0 ; brq =bdrv_reopen_queue (NULL , bs, opts, flags);bdrv_reopen_multiple (brq, &local_err);if (local_err) {error_report_err (local_err); + }else { +blk_set_enable_write_cache (blk, !writethrough); }return 0 ;
tests/qemu-iotests/142 +1 -1
@@ -216,7 +216,7 @@ echo # BDS initialised with the json: pseudo-protocol, but still have it inherit # options from its parent node. -hmp_cmds="qemu-io none0 \"reopen -o cache.writeback=off,cache.direct=on,cache.no-flush=on\" +hmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\" info block none0 info block image info block blkdebug
tests/qemu-iotests/142.out +1 -1
@@ -414,7 +414,7 @@ cache.no-flush=on on backing-file --- Change cache mode in parent, child has explicit option in JSON --- - Cache mode: writethrough, direct, ignore flushes + Cache mode: writeback, direct, ignore flushes Cache mode: writeback, direct, ignore flushes Cache mode: writeback, direct, ignore flushes Cache mode: writeback, ignore flushes
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 40/48] block: Use bdrv_parse_cache_mode() in drive_init()
In reply to Kevin Wolf--- blockdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
blockdev.c +3 -2
@@ -897,8 +897,9 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) value =qemu_opt_get (all_opts,"cache" );if (value) {int flags =0 ; +bool writethrough; -if (bdrv_parse_cache_flags (value, &flags) !=0 ) { +if (bdrv_parse_cache_mode (value, &flags, &writethrough) !=0 ) {error_report ("invalid cache option" );return NULL ; }
@@ -906,7 +907,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)/* Specific options take precedence */ if (!qemu_opt_get (all_opts,BDRV_OPT_CACHE_WB )) {qemu_opt_set_bool (all_opts,BDRV_OPT_CACHE_WB , - !!(flags &BDRV_O_CACHE_WB ), &error_abort); + !writethrough, &error_abort); }if (!qemu_opt_get (all_opts,BDRV_OPT_CACHE_DIRECT )) { qemu_opt_set_bool(all_opts, BDRV_OPT_CACHE_DIRECT,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 42/48] block: Remove bdrv_parse_cache_flags()
In reply to Kevin WolfAll users are converted to bdrv_parse_cache_mode() now.
--- block.c | 29 +++++++---------------------- include/block/block.h | 1 - 2 files changed, 7 insertions(+), 23 deletions(-)
block.c +7 -22
@@ -644,21 +644,23 @@ int bdrv_parse_discard_flags(const char *mode, int *flags)* * Return 0 on success, -1 if the cache mode was invalid. */ -int bdrv_parse_cache_flags (const char *mode,int *flags) +int bdrv_parse_cache_mode (const char *mode,int *flags,bool *writethrough) { *flags &= ~BDRV_O_CACHE_MASK ;if (!strcmp (mode,"off" ) || !strcmp (mode,"none" )) { - *flags |=BDRV_O_NOCACHE |BDRV_O_CACHE_WB ; + *writethrough = false; + *flags |=BDRV_O_NOCACHE ; }else if (!strcmp (mode,"directsync" )) { + *writethrough = true; *flags |=BDRV_O_NOCACHE ; }else if (!strcmp (mode,"writeback" )) { - *flags |=BDRV_O_CACHE_WB ; + *writethrough = false; }else if (!strcmp (mode,"unsafe" )) { - *flags |=BDRV_O_CACHE_WB ; + *writethrough = false; *flags |=BDRV_O_NO_FLUSH ; }else if (!strcmp (mode,"writethrough" )) { -/* this is the default */ + *writethrough = true; }else {return -1 ; }
@@ -666,23 +668,6 @@ int bdrv_parse_cache_flags(const char *mode, int *flags)return 0 ; } -int bdrv_parse_cache_mode (const char *mode,int *flags,bool *writethrough) -{ -int ret =bdrv_parse_cache_flags (mode, flags); -if (ret <0 ) { -return ret; - } - -if (*flags &BDRV_O_CACHE_WB ) { - *flags &= ~BDRV_O_CACHE_WB ; - *writethrough = false; - }else { - *writethrough = true; - } - -return 0 ; -} -/* * Returns the options and flags that a temporary snapshot should get, based on * the originally requested flags (the originally requested image will have
include/block/block.h +0 -1
@@ -208,7 +208,6 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);void bdrv_replace_in_backing_chain (BlockDriverState *old,BlockDriverState *new); -int bdrv_parse_cache_flags (const char *mode,int *flags);int bdrv_parse_cache_mode (const char *mode,int *flags,bool *writethrough);int bdrv_parse_discard_flags (const char *mode,int *flags); BdrvChild *bdrv_open_child(const char *filename,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 20/48] block: an interoperability test for luks vs dm-crypt/cryptsetup
In reply to Kevin WolfFrom: "Daniel P. Berrange" <[email protected]>
It is important that the QEMU luks implementation retains 100% compatibility with the reference implementation provided by the combination of the linux kernel dm-crypt module and cryptsetup userspace tools.
There is a matrix of tests to be performed with different sets of encryption settings. For each matrix entry, two tests will be performed. One will create a LUKS image with the cryptsetup tool and then do I/O with both cryptsetup & qemu-io. The other will create the image with qemu-img and then again do I/O with both cryptsetup and qemu-io.
The new I/O test 149 performs interoperability testing between QEMU and the reference implementation. Such testing inherantly requires elevated privileges, so to this this the user must have configured passwordless sudo access. The test will automatically skip if sudo is not available.
The test has to be run explicitly thus:
cd tests/qemu-iotests
./check -luks 149--- tests/qemu-iotests/149 | 519 ++++++++++++ tests/qemu-iotests/149.out | 1880 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/common | 1 + tests/qemu-iotests/group | 1 + 4 files changed, 2401 insertions(+) create mode 100755 tests/qemu-iotests/149 create mode 100644 tests/qemu-iotests/149.out
tests/qemu-iotests/149 new file +519 -0
@@ -0,0 +1,519 @@ +#!/usr/bin/python +# +# Copyright (C) 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Creator/Owner: Daniel P. Berrange <[email protected]> +# +# Exercise the QEMU 'luks' block driver to validate interoperability +# with the Linux dm-crypt + cryptsetup implementation + +import subprocess +import os +import os.path + +import base64 + +import iotests + + +class LUKSConfig(object): + """Represent configuration parameters for a single LUKS + setup to be tested""" + + def __init__(self, name, cipher, keylen, mode, ivgen, + ivgen_hash, hash, password=None, passwords=None): + + self.name = name + self.cipher = cipher + self.keylen = keylen + self.mode = mode + self.ivgen = ivgen + self.ivgen_hash = ivgen_hash + self.hash = hash + + if passwords is not None: + self.passwords = passwords + else: + self.passwords = {} + + if password is None: + self.passwords["0"] = "123456" + else: + self.passwords["0"] = password + + def __repr__(self): + return self.name + + def image_name(self): + return "luks-%s.img" % self.name + + def image_path(self): + return os.path.join(iotests.test_dir, self.image_name()) + + def device_name(self): + return "qiotest-145-%s" % self.name + + def device_path(self): + return "/dev/mapper/" + self.device_name() + + def first_password(self): + for i in range(8): + slot = str(i) + if slot in self.passwords: + return (self.passwords[slot], slot) + raise Exception("No password found") + + def first_password_base64(self): + (pw, slot) = self.first_password() + return base64.b64encode(pw) + + def active_slots(self): + slots = [] + for i in range(8): + slot = str(i) + if slot in self.passwords: + slots.append(slot) + return slots + +def verify_passwordless_sudo(): + """Check whether sudo is configured to allow + password-less access to commands""" + + args = ["sudo", "-n", "/bin/true"] + + proc = subprocess.Popen(args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + msg = proc.communicate()[0] + + if proc.returncode != 0: + iotests.notrun('requires password-less sudo access: %s' % msg) + + +def cryptsetup(args, password=None): + """Run the cryptsetup command in batch mode""" + + fullargs = ["sudo", "cryptsetup", "-q", "-v"] + fullargs.extend(args) + + iotests.log(" ".join(fullargs), filters=[iotests.filter_test_dir]) + proc = subprocess.Popen(fullargs, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + msg = proc.communicate(password)[0] + + if proc.returncode != 0: + raise Exception(msg) + + +def cryptsetup_add_password(config, slot): + """Add another password to a LUKS key slot""" + + (password, mainslot) = config.first_password() + + pwfile = os.path.join(iotests.test_dir, "passwd.txt") + with open(pwfile, "w") as fh: + fh.write(config.passwords[slot]) + + try: + args = ["luksAddKey", config.image_path(), + "--key-slot", slot, + "--key-file", "-", + pwfile] + + cryptsetup(args, password) + finally: + os.unlink(pwfile) + + +def cryptsetup_format(config): + """Format a new LUKS volume with cryptsetup, adding the + first key slot only""" + + (password, slot) = config.first_password() + + args = ["luksFormat"] + cipher = config.cipher + "-" + config.mode + "-" + config.ivgen + if config.ivgen_hash is not None: + cipher = cipher + ":" + config.ivgen_hash + args.extend(["--cipher", cipher]) + if config.mode == "xts": + args.extend(["--key-size", str(config.keylen * 2)]) + else: + args.extend(["--key-size", str(config.keylen)]) + if config.hash is not None: + args.extend(["--hash", config.hash]) + args.extend(["--key-slot", slot]) + args.extend(["--key-file", "-"]) + args.append(config.image_path()) + + cryptsetup(args, password) + + +def chown(config): + """Set the ownership of a open LUKS device to this user""" + + path = config.device_path() + + args = ["sudo", "chown", "%d:%d" % (os.getuid(), os.getgid()), path] + iotests.log(" ".join(args), filters=[iotests.filter_chown]) + proc = subprocess.Popen(args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + msg = proc.communicate()[0] + + if proc.returncode != 0: + raise Exception("Cannot change owner on %s" % path) + + +def cryptsetup_open(config): + """Open an image as a LUKS device""" + + (password, slot) = config.first_password() + + args = ["luksOpen", config.image_path(), config.device_name()] + + cryptsetup(args, password) + + +def cryptsetup_close(config): + """Close an active LUKS device """ + + args = ["luksClose", config.device_name()] + cryptsetup(args) + + +def delete_image(config): + """Delete a disk image""" + + try: + os.unlink(config.image_path()) + iotests.log("unlink %s" % config.image_path(), + filters=[iotests.filter_test_dir]) + except Exception as e: + pass + + +def create_image(config, size_mb): + """Create a bare disk image with requested size""" + + delete_image(config) + iotests.log("truncate %s --size %dMB" % (config.image_path(), size_mb), + filters=[iotests.filter_test_dir]) + with open(config.image_path(), "w") as fn: + fn.truncate(size_mb * 1024 * 1024) + + +def qemu_img_create(config, size_mb): + """Create and format a disk image with LUKS using qemu-img""" + + opts = [ + "key-secret=sec0", + "cipher-alg=%s-%d" % (config.cipher, config.keylen), + "cipher-mode=%s" % config.mode, + "ivgen-alg=%s" % config.ivgen, + "hash-alg=%s" % config.hash, + ] + if config.ivgen_hash is not None: + opts.append("ivgen-hash-alg=%s" % config.ivgen_hash) + + args = ["create", "-f", "luks", + "--object", + ("secret,id=sec0,data=%s,format=base64" % + config.first_password_base64()), + "-o", ",".join(opts), + config.image_path(), + "%dM" % size_mb] + + iotests.log("qemu-img " + " ".join(args), filters=[iotests.filter_test_dir]) + iotests.log(iotests.qemu_img_pipe(*args), filters=[iotests.filter_test_dir]) + +def qemu_io_image_args(config, dev=False): + """Get the args for access an image or device with qemu-io""" + + if dev: + return [ + "--image-opts", + "driver=file,filename=%s" % config.device_path()] + else: + return [ + "--object", + ("secret,id=sec0,data=%s,format=base64" % + config.first_password_base64()), + "--image-opts", + ("driver=luks,key-secret=sec0,file.filename=%s" % + config.image_path())] + +def qemu_io_write_pattern(config, pattern, offset_mb, size_mb, dev=False): + """Write a pattern of data to a LUKS image or device""" + + args = ["-c", "write -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)] + args.extend(qemu_io_image_args(config, dev)) + iotests.log("qemu-io " + " ".join(args), filters=[iotests.filter_test_dir]) + iotests.log(iotests.qemu_io(*args), filters=[iotests.filter_test_dir, + iotests.filter_qemu_io]) + + +def qemu_io_read_pattern(config, pattern, offset_mb, size_mb, dev=False): + """Read a pattern of data to a LUKS image or device""" + + args = ["-c", "read -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)] + args.extend(qemu_io_image_args(config, dev)) + iotests.log("qemu-io " + " ".join(args), filters=[iotests.filter_test_dir]) + iotests.log(iotests.qemu_io(*args), filters=[iotests.filter_test_dir, + iotests.filter_qemu_io]) + + +def test_once(config, qemu_img=False): + """Run the test with a desired LUKS configuration. Can either + use qemu-img for creating the initial volume, or cryptsetup, + in order to test interoperability in both directions""" + + iotests.log("# ================= %s %s =================" % ( + "qemu-img" if qemu_img else "dm-crypt", config)) + + oneKB = 1024 + oneMB = oneKB * 1024 + oneGB = oneMB * 1024 + oneTB = oneGB * 1024 + + # 4 TB, so that we pass the 32-bit sector number boundary. + # Important for testing correctness of some IV generators + # The files are sparse, so not actually using this much space + image_size = 4 * oneTB + if qemu_img: + iotests.log("# Create image") + qemu_img_create(config, image_size / oneMB) + else: + iotests.log("# Create image") + create_image(config, image_size / oneMB) + + lowOffsetMB = 100 + highOffsetMB = 3 * oneTB / oneMB + + try: + if not qemu_img: + iotests.log("# Format image") + cryptsetup_format(config) + + for slot in config.active_slots()[1:]: + iotests.log("# Add password slot %s" % slot) + cryptsetup_add_password(config, slot) + + # First we'll open the image using cryptsetup and write a + # known pattern of data that we'll then verify with QEMU + + iotests.log("# Open dev") + cryptsetup_open(config) + + try: + iotests.log("# Set dev owner") + chown(config) + + iotests.log("# Write test pattern 0xa7") + qemu_io_write_pattern(config, 0xa7, lowOffsetMB, 10, dev=True) + iotests.log("# Write test pattern 0x13") + qemu_io_write_pattern(config, 0x13, highOffsetMB, 10, dev=True) + finally: + iotests.log("# Close dev") + cryptsetup_close(config) + + # Ok, now we're using QEMU to verify the pattern just + # written via dm-crypt + + iotests.log("# Read test pattern 0xa7") + qemu_io_read_pattern(config, 0xa7, lowOffsetMB, 10, dev=False) + iotests.log("# Read test pattern 0x13") + qemu_io_read_pattern(config, 0x13, highOffsetMB, 10, dev=False) + + + # Write a new pattern to the image, which we'll later + # verify with dm-crypt + iotests.log("# Write test pattern 0x91") + qemu_io_write_pattern(config, 0x91, lowOffsetMB, 10, dev=False) + iotests.log("# Write test pattern 0x5e") + qemu_io_write_pattern(config, 0x5e, highOffsetMB, 10, dev=False) + + + # Now we're opening the image with dm-crypt once more + # and verifying what QEMU wrote, completing the circle + iotests.log("# Open dev") + cryptsetup_open(config) + + try: + iotests.log("# Set dev owner") + chown(config) + + iotests.log("# Read test pattern 0x91") + qemu_io_read_pattern(config, 0x91, lowOffsetMB, 10, dev=True) + iotests.log("# Read test pattern 0x5e") + qemu_io_read_pattern(config, 0x5e, highOffsetMB, 10, dev=True) + finally: + iotests.log("# Close dev") + cryptsetup_close(config) + finally: + iotests.log("# Delete image") + delete_image(config) + print + + +# Obviously we only work with the luks image format +iotests.verify_image_format(supported_fmts=['luks']) +iotests.verify_platform() + +# We need sudo in order to run cryptsetup to create +# dm-crypt devices. This is safe to use on any +# machine, since all dm-crypt devices are backed +# by newly created plain files, and have a dm-crypt +# name prefix of 'qiotest' to avoid clashing with +# user LUKS volumes +verify_passwordless_sudo() + + +# If we look at all permutations of cipher, key size, +# mode, ivgen, hash, there are ~1000 possible configs. +# +# We certainly don't want/need to test every permutation +# to get good validation of interoperability between QEMU +# and dm-crypt/cryptsetup. +# +# The configs below are a representative set that aim to +# exercise each axis of configurability. +# +configs = [ + # A common LUKS default + LUKSConfig("aes-256-xts-plain64-sha1", + "aes", 256, "xts", "plain64", None, "sha1"), + + + # LUKS default but diff ciphers + LUKSConfig("twofish-256-xts-plain64-sha1", + "twofish", 256, "xts", "plain64", None, "sha1"), + LUKSConfig("serpent-256-xts-plain64-sha1", + "serpent", 256, "xts", "plain64", None, "sha1"), + # Should really be xts, but kernel doesn't support xts+cast5 + # nor does it do essiv+cast5 + LUKSConfig("cast5-128-cbc-plain64-sha1", + "cast5", 128, "cbc", "plain64", None, "sha1"), + LUKSConfig("cast6-256-xts-plain64-sha1", + "cast6", 256, "xts", "plain64", None, "sha1"), + + + # LUKS default but diff modes / ivgens + LUKSConfig("aes-256-cbc-plain-sha1", + "aes", 256, "cbc", "plain", None, "sha1"), + LUKSConfig("aes-256-cbc-plain64-sha1", + "aes", 256, "cbc", "plain64", None, "sha1"), + LUKSConfig("aes-256-cbc-essiv-sha256-sha1", + "aes", 256, "cbc", "essiv", "sha256", "sha1"), + LUKSConfig("aes-256-xts-essiv-sha256-sha1", + "aes", 256, "xts", "essiv", "sha256", "sha1"), + + + # LUKS default but smaller key sizes + LUKSConfig("aes-128-xts-plain64-sha256-sha1", + "aes", 128, "xts", "plain64", None, "sha1"), + LUKSConfig("aes-192-xts-plain64-sha256-sha1", + "aes", 192, "xts", "plain64", None, "sha1"), + + LUKSConfig("twofish-128-xts-plain64-sha1", + "twofish", 128, "xts", "plain64", None, "sha1"), + LUKSConfig("twofish-192-xts-plain64-sha1", + "twofish", 192, "xts", "plain64", None, "sha1"), + + LUKSConfig("serpent-128-xts-plain64-sha1", + "serpent", 128, "xts", "plain64", None, "sha1"), + LUKSConfig("serpent-192-xts-plain64-sha1", + "serpent", 192, "xts", "plain64", None, "sha1"), + + LUKSConfig("cast6-128-xts-plain64-sha1", + "cast6", 128, "xts", "plain", None, "sha1"), + LUKSConfig("cast6-192-xts-plain64-sha1", + "cast6", 192, "xts", "plain64", None, "sha1"), + + + # LUKS default but diff hash + LUKSConfig("aes-256-xts-plain64-sha256", + "aes", 256, "xts", "plain64", None, "sha256"), + LUKSConfig("aes-256-xts-plain64-sha512", + "aes", 256, "xts", "plain64", None, "sha512"), + LUKSConfig("aes-256-xts-plain64-ripemd160", + "aes", 256, "xts", "plain64", None, "ripemd160"), + + # Password in slot 3 + LUKSConfig("aes-256-xts-plain-sha1-pwslot3", + "aes", 256, "xts", "plain", None, "sha1", + passwords={ + "3": "slot3", + }), + + # Passwords in every slot + LUKSConfig("aes-256-xts-plain-sha1-pwallslots", + "aes", 256, "xts", "plain", None, "sha1", + passwords={ + "0": "slot1", + "1": "slot1", + "2": "slot2", + "3": "slot3", + "4": "slot4", + "5": "slot5", + "6": "slot6", + "7": "slot7", + }), +] + +blacklist = [ + # We don't have a cast-6 cipher impl for QEMU yet + "cast6-256-xts-plain64-sha1", + "cast6-128-xts-plain64-sha1", + "cast6-192-xts-plain64-sha1", + + # GCrypt doesn't support Twofish with 192 bit key + "twofish-192-xts-plain64-sha1", + + # We don't have sha512 hash wired up yet + "aes-256-xts-plain64-sha512", + + # We don't have ripemd160 hash wired up yet + "aes-256-xts-plain64-ripemd160", +] + +whitelist = [] +if "LUKS_CONFIG" in os.environ: + whitelist = os.environ["LUKS_CONFIG"].split(",") + +for config in configs: + if config.name in blacklist: + iotests.log("Skipping %s in blacklist" % config.name) + continue + + if len(whitelist) > 0 and config.name not in whitelist: + iotests.log("Skipping %s not in whitelist" % config.name) + continue + + test_once(config, qemu_img=False) + + # XXX we should support setting passwords in a non-0 + # key slot with 'qemu-img create' in future + (pw, slot) = config.first_password() + if slot == "0": + test_once(config, qemu_img=True)
tests/qemu-iotests/149.out new file +1880 -0
1,880 lines not on this page · raw message
tests/qemu-iotests/common +1 -0
@@ -155,6 +155,7 @@ check options -ssh test ssh -nfs test nfs -archipelago test archipelago + -luks test luks -xdiff graphical mode diff -nocache use O_DIRECT on backing file -misalign misalign memory allocations
tests/qemu-iotests/group +1 -0
@@ -150,3 +150,4 @@ 145 auto quick 146 auto quick 148 rw auto quick +149 rw auto sudo
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 44/48] block: Remove bdrv_(set_)enable_write_cache()
In reply to Kevin WolfThe only remaining users were block jobs (mirror and backup) which unconditionally enabled WCE on the BlockBackend of the target image. As these block jobs don't go through BlockBackend for their I/O requests, they aren't affected by this setting anyway but always get a writeback mode, so that call can be removed.
--- block.c | 16 ---------------- block/backup.c | 1 - block/mirror.c | 1 - include/block/block.h | 2 -- 4 files changed, 20 deletions(-)
block.c +0 -16
@@ -2694,22 +2694,6 @@ int bdrv_is_sg(BlockDriverState *bs)return bs->sg; } -int bdrv_enable_write_cache (BlockDriverState *bs) -{ -if (bs->blk) { -return blk_enable_write_cache (bs->blk); - }else { -return true; - } -} - -void bdrv_set_enable_write_cache (BlockDriverState *bs,bool wce) -{ -if (bs->blk) { -blk_set_enable_write_cache (bs->blk, wce); - } -} -int bdrv_is_encrypted (BlockDriverState *bs) {if (bs->backing && bs->backing->bs->encrypted) {
block/backup.c +0 -1
@@ -402,7 +402,6 @@ static void coroutine_fn backup_run(void *opaque) job->done_bitmap =bitmap_new (end); -bdrv_set_enable_write_cache (target, true);if (target->blk) {blk_set_on_error (target->blk, on_target_error, on_target_error);blk_iostatus_enable (target->blk);
block/mirror.c +0 -1
@@ -855,7 +855,6 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,bdrv_op_block_all (s->target, s->common.blocker); -bdrv_set_enable_write_cache (s->target, true);if (s->target->blk) {blk_set_on_error (s->target->blk, on_target_error, on_target_error);blk_iostatus_enable (s->target->blk);
include/block/block.h +0 -2
@@ -395,8 +395,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs); -int bdrv_enable_write_cache (BlockDriverState *bs); -void bdrv_set_enable_write_cache (BlockDriverState *bs,bool wce);bool bdrv_is_inserted (BlockDriverState *bs);int bdrv_media_changed (BlockDriverState *bs);void bdrv_lock_medium (BlockDriverState *bs,bool locked);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 46/48] block/null-{co, aio}: Allow reading zeroes
In reply to Kevin WolfFrom: Max Reitz <[email protected]>
This is optional so that it does not impede the null block driver's performance unless this behavior is desired.
--- block/null.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
block/null.c +20 -0
@@ -14,10 +14,12 @@#include "block/block_int.h" #define NULL_OPT_LATENCY "latency-ns" +#define NULL_OPT_ZEROES "read-zeroes"typedef struct {int64_t length;int64_t latency_ns; +bool read_zeroes; }BDRVNullState ;static QemuOptsList runtime_opts = {
@@ -40,6 +42,11 @@ static QemuOptsList runtime_opts = { .help = "nanoseconds (approximated) to wait " "before completing request", }, + { + .name = NULL_OPT_ZEROES, + .type = QEMU_OPT_BOOL, + .help = "return zeroes when read", + }, {/* end of list */ } }, };
@@ -61,6 +68,7 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,error_setg (errp,"latency-ns is invalid" ); ret = -EINVAL ; } + s->read_zeroes =qemu_opt_get_bool (opts,NULL_OPT_ZEROES , false);qemu_opts_del (opts);return ret; }
@@ -90,6 +98,12 @@ static coroutine_fn int null_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { + BDRVNullState *s = bs->opaque; + +if (s->read_zeroes) { +qemu_iovec_memset (qiov,0 ,0 , nb_sectors *BDRV_SECTOR_SIZE ); + } +return null_co_common (bs); }
@@ -159,6 +173,12 @@ static BlockAIOCB *null_aio_readv(BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque) { +BDRVNullState *s = bs->opaque; + +if (s->read_zeroes) { +qemu_iovec_memset (qiov,0 ,0 , nb_sectors *BDRV_SECTOR_SIZE ); + } +return null_aio_common (bs, cb, opaque); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 43/48] block: Remove BDRV_O_CACHE_WB
In reply to Kevin WolfThe previous patches have successively made blk->enable_write_cache the true source for the information whether a writethrough mode must be implemented. The corresponding BDRV_O_CACHE_WB is only useless baggage we're carrying around, so now's the time to remove it.
At the same time, we remove the 'cache.writeback' option parsing on the BDS level as the only effect was setting the BDRV_O_CACHE_WB flag.
This change requires test cases that explicitly enabled the option to drop it. Other than that and the change of the error message when writethrough is enabled on the BDS level (from "Can't set writethrough mode" to "doesn't support the option"), there should be no change in behaviour.
--- block.c | 48 ++----------------------------------------- block/block-backend.c | 11 ---------- block/vvfat.c | 3 +-- blockdev.c | 21 ++----------------- include/block/block.h | 3 +-- qemu-img.c | 2 +- qemu-io-cmds.c | 1 - tests/qemu-iotests/051 | 2 +- tests/qemu-iotests/051.pc.out | 10 ++++----- tests/qemu-iotests/142 | 6 +++--- tests/qemu-iotests/142.out | 36 ++++++++++++++++---------------- 11 files changed, 34 insertions(+), 109 deletions(-)
block.c +2 -46
@@ -679,7 +679,6 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, *child_flags = (parent_flags & ~BDRV_O_SNAPSHOT ) |BDRV_O_TEMPORARY ;/* For temporary files, unconditional cache=unsafe is fine */ -qdict_set_default_str (child_options,BDRV_OPT_CACHE_WB ,"on" );qdict_set_default_str (child_options,BDRV_OPT_CACHE_DIRECT ,"off" );qdict_set_default_str (child_options,BDRV_OPT_CACHE_NO_FLUSH ,"on" ); }
@@ -704,7 +703,6 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,/* Our block drivers take care to send flushes and respect unmap policy, * so we can default to enable both on lower layers regardless of the * corresponding parent options. */ -qdict_set_default_str (child_options,BDRV_OPT_CACHE_WB ,"on" ); flags |=BDRV_O_UNMAP ;/* Clear flags that only apply to the top layer */
@@ -747,7 +745,6 @@ static void bdrv_backing_options(int *child_flags, QDict *child_options,/* The cache mode is inherited unmodified for backing files; except WCE, * which is only applied on the top level (BlockBackend) */ -qdict_set_default_str (child_options,BDRV_OPT_CACHE_WB ,"on" );qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_DIRECT );qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_NO_FLUSH );
@@ -766,7 +763,7 @@ static const BdrvChildRole child_backing = {static int bdrv_open_flags (BlockDriverState *bs,int flags) { -int open_flags = flags |BDRV_O_CACHE_WB ; +int open_flags = flags;/* * Clear flags that are internal to the block layer before opening the
@@ -788,11 +785,6 @@ static void update_flags_from_options(int *flags, QemuOpts *opts) { *flags &= ~BDRV_O_CACHE_MASK ; -assert (qemu_opt_find (opts,BDRV_OPT_CACHE_WB )); -if (qemu_opt_get_bool (opts,BDRV_OPT_CACHE_WB , false)) { - *flags |=BDRV_O_CACHE_WB ; - } -assert (qemu_opt_find (opts,BDRV_OPT_CACHE_NO_FLUSH ));if (qemu_opt_get_bool (opts,BDRV_OPT_CACHE_NO_FLUSH , false)) { *flags |=BDRV_O_NO_FLUSH ;
@@ -806,10 +798,6 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)static void update_options_from_flags (QDict *options,int flags) { -if (!qdict_haskey (options,BDRV_OPT_CACHE_WB )) { -qdict_put (options,BDRV_OPT_CACHE_WB , -qbool_from_bool (flags &BDRV_O_CACHE_WB )); - }if (!qdict_haskey (options,BDRV_OPT_CACHE_DIRECT )) {qdict_put (options,BDRV_OPT_CACHE_DIRECT ,qbool_from_bool (flags &BDRV_O_NOCACHE ));
@@ -872,11 +860,6 @@ static QemuOptsList bdrv_runtime_opts = { .help = "Block driver to use for the node", }, { - .name = BDRV_OPT_CACHE_WB, - .type = QEMU_OPT_BOOL, - .help = "Enable writeback mode", - }, - { .name = BDRV_OPT_CACHE_DIRECT, .type = QEMU_OPT_BOOL, .help = "Bypass software writeback cache on the host",
@@ -983,14 +966,6 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,/* Apply cache mode options */ update_flags_from_options (&bs->open_flags, opts); -if (!bs->blk && (bs->open_flags &BDRV_O_CACHE_WB ) ==0 ) { -error_setg (errp,"Can't set writethrough mode except for the root" ); - ret = -EINVAL ; - goto free_and_fail; - } - -bdrv_set_enable_write_cache (bs, bs->open_flags &BDRV_O_CACHE_WB ); -/* Open the image, either directly or using a protocol */ open_flags =bdrv_open_flags (bs, bs->open_flags);if (drv->bdrv_file_open) {
@@ -2012,16 +1987,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,update_flags_from_options (&reopen_state->flags, opts); -/* WCE is a BlockBackend level option, can't change it */ -bool old_wce =bdrv_enable_write_cache (reopen_state->bs); -bool new_wce = (reopen_state->flags &BDRV_O_CACHE_WB ); - -if (old_wce != new_wce) { -error_setg (errp,"Cannot change cache.writeback" ); - ret = -EINVAL ; - goto error; - } -/* node-name and driver must be unchanged. Put them back into the QDict, so * that they are checked at the end of this function. */ value =qemu_opt_get (opts,"node-name" );
@@ -2123,8 +2088,6 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) reopen_state->bs->open_flags = reopen_state->flags; reopen_state->bs->read_only = !(reopen_state->flags &BDRV_O_RDWR ); -bdrv_set_enable_write_cache (reopen_state->bs, - !!(reopen_state->flags &BDRV_O_CACHE_WB ));bdrv_refresh_limits (reopen_state->bs,NULL ); }
@@ -2745,13 +2708,6 @@ void bdrv_set_enable_write_cache(BlockDriverState *bs, bool wce)if (bs->blk) {blk_set_enable_write_cache (bs->blk, wce); } - -/* so a reopen() will preserve wce */ -if (wce) { - bs->open_flags |=BDRV_O_CACHE_WB ; - }else { - bs->open_flags &= ~BDRV_O_CACHE_WB ; - } }int bdrv_is_encrypted (BlockDriverState *bs)
@@ -3604,7 +3560,7 @@ void bdrv_img_create(const char *filename, const char *fmt, }/* backing files always opened read-only */ - back_flags = flags |BDRV_O_CACHE_WB ; + back_flags = flags; back_flags &= ~(BDRV_O_RDWR |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING );if (backing_fmt) {
block/block-backend.c +0 -11
@@ -149,8 +149,6 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,BlockBackend *blk;int ret; -assert ((flags &BDRV_O_CACHE_WB ) ==0 ); - blk =blk_new_with_bs (errp);if (!blk) {QDECREF (options);
@@ -1223,15 +1221,6 @@ int blk_enable_write_cache(BlockBackend *blk)void blk_set_enable_write_cache (BlockBackend *blk,bool wce) { blk->enable_write_cache = wce; - -/* TODO Remove this when BDRV_O_CACHE_WB isn't used any more */ -if (blk->root) { -if (wce) { - blk->root->bs->open_flags |=BDRV_O_CACHE_WB ; - }else { - blk->root->bs->open_flags &= ~BDRV_O_CACHE_WB ; - } - } }void blk_invalidate_cache (BlockBackend *blk,Error **errp)
block/vvfat.c +1 -2
@@ -2956,8 +2956,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp) options =qdict_new ();qdict_put (options,"driver" ,qstring_from_str ("qcow" )); ret =bdrv_open (&s->qcow, s->qcow_filename,NULL , options, -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_FLUSH , - errp); +BDRV_O_RDWR |BDRV_O_NO_FLUSH , errp);if (ret <0 ) { goto err; }
blockdev.c +2 -19
@@ -593,7 +593,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,/* bdrv_open() defaults to the values in bdrv_flags (for compatibility * with other callers) rather than what we want as the real defaults. * Apply the defaults here instead. */ -qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_WB , writethrough ?"off" :"on" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_DIRECT ,"off" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_NO_FLUSH ,"off" );assert ((bdrv_flags &BDRV_O_CACHE_MASK ) ==0 );
@@ -689,7 +688,6 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp)/* bdrv_open() defaults to the values in bdrv_flags (for compatibility * with other callers) rather than what we want as the real defaults. * Apply the defaults here instead. */ -qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_WB ,"on" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_DIRECT ,"off" );qdict_set_default_str (bs_opts,BDRV_OPT_CACHE_NO_FLUSH ,"off" );
@@ -1777,12 +1775,6 @@ static void external_snapshot_prepare(BlkActionState *common, flags |=BDRV_O_NO_BACKING ; } -/* There is no BB attached during bdrv_open(), so we can't set a -* writethrough mode. bdrv_append() will swap the WCE setting so that the -* backing file becomes unconditionally writeback (which is what backing -* files should always be) and the new overlay gets the original setting. */ - flags |=BDRV_O_CACHE_WB ; -assert (state->new_bs ==NULL ); ret =bdrv_open (&state->new_bs, new_image_file, snapshot_ref, options, flags, errp);
@@ -2527,7 +2519,6 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,BlockBackend *blk;BlockDriverState *medium_bs =NULL ;int bdrv_flags, ret; -bool writethrough;QDict *options =NULL ;Error *err =NULL ;
@@ -2546,12 +2537,6 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, bdrv_flags &= ~(BDRV_O_TEMPORARY |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_PROTOCOL ); -/* Must open the image in writeback mode as long as no BlockBackend is -* attached. The right mode can be set as the final step after changing the -* medium. */ - writethrough = !(bdrv_flags &BDRV_O_CACHE_WB ); - bdrv_flags |=BDRV_O_CACHE_WB ; -if (!has_read_only) { read_only =BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN ; }
@@ -2609,8 +2594,6 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, goto fail; } -bdrv_set_enable_write_cache (medium_bs, !writethrough); -qmp_blockdev_close_tray (device, errp); fail:
@@ -3236,7 +3219,7 @@ static void do_drive_backup(const char *device, const char *target, goto out; } - flags = bs->open_flags |BDRV_O_CACHE_WB |BDRV_O_RDWR ; + flags = bs->open_flags |BDRV_O_RDWR ;/* See if we have a backing HD we can use to create our new image * on top of. */
@@ -3531,7 +3514,7 @@ void qmp_drive_mirror(const char *device, const char *target, format = mode ==NEW_IMAGE_MODE_EXISTING ?NULL : bs->drv->format_name; } - flags = bs->open_flags |BDRV_O_CACHE_WB |BDRV_O_RDWR ; + flags = bs->open_flags |BDRV_O_RDWR ; source =backing_bs (bs);if (!source && sync ==MIRROR_SYNC_MODE_TOP ) { sync =MIRROR_SYNC_MODE_FULL ;
include/block/block.h +1 -2
@@ -82,7 +82,6 @@ typedef struct HDGeometry {#define BDRV_O_SNAPSHOT 0x0008/* open the file read only and save writes in a snapshot */ #define BDRV_O_TEMPORARY 0x0010/* delete the file after use */ #define BDRV_O_NOCACHE 0x0020/* do not use the host page cache */ -#define BDRV_O_CACHE_WB 0x0040/* use write-back caching */ #define BDRV_O_NATIVE_AIO 0x0080/* use native AIO instead of the thread pool */ #define BDRV_O_NO_BACKING 0x0100/* don't open the backing file */ #define BDRV_O_NO_FLUSH 0x0200/* disable flushing on this disk */
@@ -96,7 +95,7 @@ typedef struct HDGeometry {ignoring the format layer */ #define BDRV_O_NO_IO 0x10000/* don't initialize for I/O */ -#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH) +#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_NO_FLUSH)/* Option names of options parsed by the block layer */
qemu-img.c +1 -1
@@ -462,7 +462,7 @@ static int img_create(int argc, char **argv) }bdrv_img_create (filename, fmt, base_filename, base_fmt, - options, img_size,BDRV_O_CACHE_WB , &local_err, quiet); + options, img_size,0 , &local_err, quiet);if (local_err) {error_reportf_err (local_err,"%s: " , filename); goto fail;
qemu-io-cmds.c +0 -1
@@ -2149,7 +2149,6 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) opts = qopts ?qemu_opts_to_qdict (qopts,NULL ) :NULL ;qemu_opts_reset (&reopen_opts); - flags |=blk_enable_write_cache (blk) ?BDRV_O_CACHE_WB :0 ; brq =bdrv_reopen_queue (NULL , bs, opts, flags);bdrv_reopen_multiple (brq, &local_err);if (local_err) {
tests/qemu-iotests/051 +1 -1
@@ -218,7 +218,7 @@ run_qemu -drive driver=null-co,cache=invalid_value for cache in writeback writethrough unsafe invalid_value; do echo -e "info block\ninfo block file\ninfo block backing\ninfo block backing-file" | \ - run_qemu -drive file="$TEST_IMG",cache=$cache,backing.file.filename="$TEST_IMG.base",backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=$device_id -nodefaults + run_qemu -drive file="$TEST_IMG",cache=$cache,backing.file.filename="$TEST_IMG.base",backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=$device_id -nodefaults done echo
tests/qemu-iotests/051.pc.out +5 -5
@@ -239,7 +239,7 @@ QEMU X.Y.Z monitor - type 'help' for more information Testing: -drive driver=null-co,cache=invalid_value QEMU_PROG: -drive driver=null-co,cache=invalid_value: invalid cache option -Testing: -drive file=TEST_DIR/t.qcow2,cache=writeback,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +Testing: -drive file=TEST_DIR/t.qcow2,cache=writeback,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2)
@@ -259,7 +259,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Cache mode: writeback, ignore flushes (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K -Testing: -drive file=TEST_DIR/t.qcow2,cache=writethrough,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +Testing: -drive file=TEST_DIR/t.qcow2,cache=writethrough,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2)
@@ -279,7 +279,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Cache mode: writeback, ignore flushes (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K -Testing: -drive file=TEST_DIR/t.qcow2,cache=unsafe,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +Testing: -drive file=TEST_DIR/t.qcow2,cache=unsafe,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2)
@@ -299,8 +299,8 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Cache mode: writeback, ignore flushes (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K -Testing: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults -QEMU_PROG: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0: invalid cache option +Testing: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +QEMU_PROG: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0: invalid cache option === Specifying the protocol layer ===
tests/qemu-iotests/142 +3 -3
@@ -110,11 +110,11 @@ function check_cache_all() echo -e "\n\ncache.writeback=off on none0" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" echo -e "\ncache.writeback=off on file" - echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" + echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "doesn't" -e "does not" echo -e "\ncache.writeback=off on backing" - echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" + echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "doesn't" -e "does not" echo -e "\ncache.writeback=off on backing-file" - echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" + echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "doesn't" -e "does not" # cache.no-flush is supposed to be inherited by both bs->file and bs->backing
tests/qemu-iotests/142.out +18 -18
@@ -71,13 +71,13 @@ cache.writeback=off on none0 Cache mode: writeback cache.writeback=off on file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Block protocol 'file' doesn't support the option 'cache.writeback' cache.writeback=off on backing -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Block format 'qcow2' does not support the option 'cache.writeback' cache.writeback=off on backing-file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Block protocol 'file' doesn't support the option 'cache.writeback' cache.no-flush=on on none0
@@ -147,13 +147,13 @@ cache.writeback=off on none0 Cache mode: writeback cache.writeback=off on file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Block protocol 'file' doesn't support the option 'cache.writeback' cache.writeback=off on backing -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Block format 'qcow2' does not support the option 'cache.writeback' cache.writeback=off on backing-file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Block protocol 'file' doesn't support the option 'cache.writeback' cache.no-flush=on on none0
@@ -223,13 +223,13 @@ cache.writeback=off on none0 Cache mode: writeback, direct cache.writeback=off on file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Block protocol 'file' doesn't support the option 'cache.writeback' cache.writeback=off on backing -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Block format 'qcow2' does not support the option 'cache.writeback' cache.writeback=off on backing-file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Block protocol 'file' doesn't support the option 'cache.writeback' cache.no-flush=on on none0
@@ -299,13 +299,13 @@ cache.writeback=off on none0 Cache mode: writeback, direct cache.writeback=off on file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Block protocol 'file' doesn't support the option 'cache.writeback' cache.writeback=off on backing -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Block format 'qcow2' does not support the option 'cache.writeback' cache.writeback=off on backing-file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Block protocol 'file' doesn't support the option 'cache.writeback' cache.no-flush=on on none0
@@ -375,13 +375,13 @@ cache.writeback=off on none0 Cache mode: writeback cache.writeback=off on file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Block protocol 'file' doesn't support the option 'cache.writeback' cache.writeback=off on backing -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Block format 'qcow2' does not support the option 'cache.writeback' cache.writeback=off on backing-file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Block protocol 'file' doesn't support the option 'cache.writeback' cache.no-flush=on on none0
@@ -704,13 +704,13 @@ cache.writeback=off on none0 Cache mode: writeback, direct cache.writeback=off on file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Block protocol 'file' doesn't support the option 'cache.writeback' cache.writeback=off on backing -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.cache.writeback=off: Could not open backing file: Block format 'qcow2' does not support the option 'cache.writeback' cache.writeback=off on backing-file -QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Can't set writethrough mode except for the root +QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,backing.file.cache.writeback=off: Could not open backing file: Block protocol 'file' doesn't support the option 'cache.writeback' cache.no-flush=on on none0
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 45/48] qemu-img: Fix preallocation with -S 0 for convert
In reply to Kevin WolfFrom: Max Reitz <[email protected]>
When passing -S 0 to qemu-img convert, the target image is supposed to be fully allocated. Right now, this is not the case if the source image contains areas which bdrv_get_block_status() reports as being zero.
This patch changes a zeroed area's status from BLK_ZERO to BLK_DATA before invoking convert_write() if -S 0 has been specified. In addition, the check whether convert_read() actually needs to do anything (basically only if the current area is a BLK_DATA area) is pulled out of that function to the caller.
If -S 0 has been specified, zeroed areas need to be written as data to the output, thus they then have to be accounted when calculating the progress made.
This patch changes the reference output for iotest 122; contrary to what it assumed, -S 0 really should allocate everything in the output, not just areas that are filled with zeros (as opposed to being zeroed).
--- qemu-img.c | 26 +++++++++++++++----------- tests/qemu-iotests/122.out | 6 ++---- 2 files changed, 17 insertions(+), 15 deletions(-)
qemu-img.c +15 -11
@@ -1513,10 +1513,6 @@ static int convert_read(ImgConvertState *s, int64_t sector_num, int nb_sectors,int n;int ret; -if (s->status ==BLK_ZERO || s->status ==BLK_BACKING_FILE ) { -return 0 ; - } -assert (nb_sectors <= s->buf_sectors);while (nb_sectors >0 ) {BlockBackend *blk;
@@ -1654,7 +1650,8 @@ static int convert_do_copy(ImgConvertState *s) ret = n; goto fail; } -if (s->status ==BLK_DATA ) { +if (s->status ==BLK_DATA || (!s->min_sparse && s->status ==BLK_ZERO )) + { s->allocated_sectors += n; } sector_num += n;
@@ -1674,17 +1671,24 @@ static int convert_do_copy(ImgConvertState *s) ret = n; goto fail; } -if (s->status ==BLK_DATA ) { +if (s->status ==BLK_DATA || (!s->min_sparse && s->status ==BLK_ZERO )) + { allocated_done += n;qemu_progress_print (100.0 * allocated_done / s->allocated_sectors,0 ); } - ret =convert_read (s, sector_num, n, buf); -if (ret <0 ) { -error_report ("error while reading sector %" PRId64 -": %s" , sector_num,strerror (-ret)); - goto fail; +if (s->status ==BLK_DATA ) { + ret =convert_read (s, sector_num, n, buf); +if (ret <0 ) { +error_report ("error while reading sector %" PRId64 +": %s" , sector_num,strerror (-ret)); + goto fail; + } + }else if (!s->min_sparse && s->status ==BLK_ZERO ) { + n =MIN (n, s->buf_sectors); +memset (buf,0 , n *BDRV_SECTOR_SIZE ); + s->status =BLK_DATA ; } ret =convert_write (s, sector_num, n, buf);
tests/qemu-iotests/122.out +2 -4
@@ -112,16 +112,14 @@ read 3145728/3145728 bytes at offset 0 3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 63963136/63963136 bytes at offset 3145728 61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -[{ "start": 0, "length": 6291456, "depth": 0, "zero": false, "data": true, "offset": 327680}, -{ "start": 6291456, "length": 60817408, "depth": 0, "zero": true, "data": false}] +[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}] convert -c -S 0: read 3145728/3145728 bytes at offset 0 3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 63963136/63963136 bytes at offset 3145728 61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -[{ "start": 0, "length": 6291456, "depth": 0, "zero": false, "data": true}, -{ "start": 6291456, "length": 60817408, "depth": 0, "zero": true, "data": false}] +[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true}] Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 wrote 33554432/33554432 bytes at offset 0 32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 47/48] block/null-{co, aio}: Implement get_block_status()
In reply to Kevin WolfFrom: Max Reitz <[email protected]>
--- block/null.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
block/null.c +22 -0
@@ -204,6 +204,24 @@ static int null_reopen_prepare(BDRVReopenState *reopen_state,return 0 ; } +static int64_t coroutine_fn null_co_get_block_status(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors,int *pnum, +BlockDriverState **file) +{ +BDRVNullState *s = bs->opaque; +off_t start = sector_num *BDRV_SECTOR_SIZE ; + + *pnum = nb_sectors; + *file = bs; + +if (s->read_zeroes) { +return BDRV_BLOCK_OFFSET_VALID | start |BDRV_BLOCK_ZERO ; + }else { +return BDRV_BLOCK_OFFSET_VALID | start; + } +} +static BlockDriver bdrv_null_co = { .format_name ="null-co" , .protocol_name ="null-co" ,
@@ -217,6 +235,8 @@ static BlockDriver bdrv_null_co = { .bdrv_co_writev = null_co_writev, .bdrv_co_flush_to_disk = null_co_flush, .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_get_block_status = null_co_get_block_status, };static BlockDriver bdrv_null_aio = {
@@ -232,6 +252,8 @@ static BlockDriver bdrv_null_aio = { .bdrv_aio_writev = null_aio_writev, .bdrv_aio_flush = null_aio_flush, .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_get_block_status = null_co_get_block_status, };static void bdrv_null_init (void )
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 48/48] iotests: Test qemu-img convert -S 0 behavior
In reply to Kevin WolfFrom: Max Reitz <[email protected]>
Passing -S 0 to qemu-img convert should result in all source data being copied to the output, even if that source data is known to be 0. The output image should therefore have exactly the same size on disk as an image which we explicitly filled with data.
--- tests/qemu-iotests/150 | 105 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/150.out | 14 ++++++ tests/qemu-iotests/group | 1 + 3 files changed, 120 insertions(+) create mode 100755 tests/qemu-iotests/150 create mode 100644 tests/qemu-iotests/150.out
tests/qemu-iotests/150 new file +105 -0
@@ -0,0 +1,105 @@ +#!/bin/bash +# +# Test that qemu-img convert -S 0 fully allocates the target image +# +# Copyright (C) 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto file +_supported_os Linux + + +on_disk_size() +{ + du "$@" | sed -e 's/\t\+.*//' +} + + +img_size=1048576 + + +echo +echo '=== Comparing empty image against sparse conversion ===' +echo + +_make_test_img $img_size + +empty_size=$(on_disk_size "$TEST_IMG") + + +$QEMU_IMG_PROG convert -O "$IMGFMT" -S 512 \ + "json:{ 'driver': 'null-co', 'size': $img_size, 'read-zeroes': true }" \ + "$TEST_IMG" + +sparse_convert_size=$(on_disk_size "$TEST_IMG") + + +if [ "$empty_size" -eq "$sparse_convert_size" ]; then + echo 'Equal image size' +else + echo 'Different image size' +fi + + +echo +echo '=== Comparing full image against non-sparse conversion ===' +echo + +_make_test_img $img_size +$QEMU_IO -c "write 0 $img_size" "$TEST_IMG" | _filter_qemu_io + +full_size=$(on_disk_size "$TEST_IMG") + + +$QEMU_IMG convert -O "$IMGFMT" -S 0 \ + "json:{ 'driver': 'null-co', 'size': $img_size, 'read-zeroes': true }" \ + "$TEST_IMG" + +non_sparse_convert_size=$(on_disk_size "$TEST_IMG") + + +if [ "$full_size" -eq "$non_sparse_convert_size" ]; then + echo 'Equal image size' +else + echo 'Different image size' +fi + + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/150.out new file +14 -0
@@ -0,0 +1,14 @@ +QA output created by 150 + +=== Comparing empty image against sparse conversion === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +Equal image size + +=== Comparing full image against non-sparse conversion === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Equal image size +*** done
tests/qemu-iotests/group +1 -0
@@ -151,3 +151,4 @@ 146 auto quick 148 rw auto quick 149 rw auto sudo +150 rw auto quick
Signature · 1 line
1.8.3.1
Quoted 7 lines · Kevin Wolf
The following changes since commit
b68a80139e37e806f004237e55311ebc42151434:Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20160324' into staging (2016-03-24 16:24:02 +0000)
are available in the git repository at:
Quoted 8 lines
git://repo.or.cz/qemu/kevin.gittags/for-upstreamfor you to fetch changes up to
b63f2a6772ca774ec58b2fc6e26fdeeda44a99c1:iotests: Test qemu-img convert -S 0 behavior (2016-03-29 16:30:13 +0200)
----------------------------------------------------------------
Block layer patches
Hi. I'm afraid this doesn't compile:
/Users/pm215/src/qemu-for-merges/block/blkreplay.c:38:9: warning:
implicit declaration of function 'error_propagate' is invalid in C99 [-Wimplicit-function-declaration]
error_propagate(errp, local_err);
^/Users/pm215/src/qemu-for-merges/block/crypto.c:68:9: warning:
implicit declaration of function 'error_setg_errno' is invalid in C99 [-Wimplicit-function-declaration]
error_setg_errno(errp, -ret, "Could not read encryption header");
^
/Users/pm215/src/qemu-for-merges/block/crypto.c:116:66: error: use of
undeclared identifier 'error_abort'
qemu_opt_set_number(data->opts, BLOCK_OPT_SIZE, data->size, &error_abort);
^
/Users/pm215/src/qemu-for-merges/block/crypto.c:217:9: warning:
implicit declaration of function 'error_setg' is invalid in C99
[-Wimplicit-function-declaration]
error_setg(&local_err, "Unsupported block format %d", format);
^
/Users/pm215/src/qemu-for-merges/block/crypto.c:220:5: warning:
implicit declaration of function 'error_propagate' is invalid in C99
[-Wimplicit-function-declaration]
error_propagate(errp, local_err);
^
/Users/pm215/src/qemu-for-merges/block/crypto.c:296:50: error: use of
undeclared identifier 'error_abort'
opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
^Looks like you've also been hit by commit da34e65cb4025, which means you now need to explicitly include qapi/error.h if you need it.
thanks
-- PMM
Am 29.03.2016 um 21:56 hat Peter Maydell geschrieben:
Quoted 14 lines · Kevin Wolf
Quoted 13 lines
The following changes since commit
b68a80139e37e806f004237e55311ebc42151434:Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20160324' into staging (2016-03-24 16:24:02 +0000)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.gittags/for-upstreamfor you to fetch changes up to
b63f2a6772ca774ec58b2fc6e26fdeeda44a99c1:iotests: Test qemu-img convert -S 0 behavior (2016-03-29 16:30:13 +0200)
Quoted 7 lines
Quoted 2 lines
----------------------------------------------------------------
Block layer patchesHi. I'm afraid this doesn't compile:
[...]
Looks like you've also been hit by commitda34e65cb4025, which means you now need to explicitly includeqapi/error.hif you need it.
Ok, I can (and will, unless you tell me not to) send a v2 of the pull request; but generally speaking, wouldn't it make more sense and be easier for everyone involved (including yourself) if such merge conflicts where you know exactly what trivial fixup needs to be done were handled in the merge commit?
Kevin
Quoted 11 lines · Kevin Wolf
Am 29.03.2016 um 21:56 hat Peter Maydell geschrieben:
Quoted 4 lines
Hi. I'm afraid this doesn't compile:
[...]
Looks like you've also been hit by commitda34e65cb4025, which means you now need to explicitly includeqapi/error.hif you need it.Ok, I can (and will, unless you tell me not to) send a v2 of the pull request; but generally speaking, wouldn't it make more sense and be easier for everyone involved (including yourself) if such merge conflicts where you know exactly what trivial fixup needs to be done were handled in the merge commit?
Sometimes, yes, but I often prefer not to for two reasons:
(1) I often have a big queue of merges to process and time spent by me trying to by-hand fix up bad merges is time not spent processing somebody else's merge
(2) I may be able to get the merge to compile but my testing process for the affected code is likely to be much less comprehensive than the submaintainer's
So mostly I reserve fixes during the merge for trivial textual-only conflicts.
thanks
-- PMM
Am 30.03.2016 um 13:29 hat Peter Maydell geschrieben:
Quoted 13 lines · Kevin Wolf
Quoted 11 lines
Am 29.03.2016 um 21:56 hat Peter Maydell geschrieben:
Quoted 4 lines
Hi. I'm afraid this doesn't compile:
[...]
Looks like you've also been hit by commitda34e65cb4025, which means you now need to explicitly includeqapi/error.hif you need it.Ok, I can (and will, unless you tell me not to) send a v2 of the pull request; but generally speaking, wouldn't it make more sense and be easier for everyone involved (including yourself) if such merge conflicts where you know exactly what trivial fixup needs to be done were handled in the merge commit?
Quoted 4 lines
Sometimes, yes, but I often prefer not to for two reasons:
(1) I often have a big queue of merges to process and time spent by me trying to by-hand fix up bad merges is time not spent processing somebody else's merge
Right, but so is time spent for sending an email describing the problem and later processing a v2. In more complicated cases that certainly still saves time for you and you should continue to do that. I was talking only about the really obvious cases where you already tell me in your email what the exact problem is and how I need to fix it.
Quoted 3 lines
(2) I may be able to get the merge to compile but my testing process for the affected code is likely to be much less comprehensive than the submaintainer's
Okay, that's a fair point.
Kevin
Re: [Qemu-devel] [PULL 48/48] iotests: Test qemu-img convert -S 0 behavior
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
From: Max Reitz <[email protected]>
Passing -S 0 to qemu-img convert should result in all source data being copied to the output, even if that source data is known to be 0. The output image should therefore have exactly the same size on disk as an image which we explicitly filled with data.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Fam Zheng <[email protected]>Signed-off-by Kevin Wolf <[email protected]>
This fails with XFS and raw format, which preallocates an extra cluster at the end of the file created with qemu-io (so that the on-disk size is 2056 512-byte blocks).
Paolo
Re: [Qemu-devel] [PULL 48/48] iotests: Test qemu-img convert -S 0 behavior
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · Kevin Wolf
From: Max Reitz <[email protected]>
Passing -S 0 to qemu-img convert should result in all source data being copied to the output, even if that source data is known to be 0. The output image should therefore have exactly the same size on disk as an image which we explicitly filled with data.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Max Reitz <[email protected]>Reviewed-by Fam Zheng <[email protected]>Signed-off-by Kevin Wolf <[email protected]>This fails with XFS and raw format, which preallocates an extra cluster at the end of the file created with qemu-io (so that the on-disk size is 2056 512-byte blocks).
Maybe squash in http://patchwork.ozlabs.org/patch/603047/ ?
Fam
Re: [Qemu-devel] [PULL 48/48] iotests: Test qemu-img convert -S 0 behavior
Am 08.04.2016 um 03:18 hat Fam Zheng geschrieben:
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Kevin Wolf
Quoted 10 lines
From: Max Reitz <[email protected]>
Passing -S 0 to qemu-img convert should result in all source data being copied to the output, even if that source data is known to be 0. The output image should therefore have exactly the same size on disk as an image which we explicitly filled with data.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Fam Zheng <[email protected]>Signed-off-by Kevin Wolf <[email protected]>
Quoted 5 lines
Quoted 3 lines
This fails with XFS and raw format, which preallocates an extra cluster at the end of the file created with qemu-io (so that the on-disk size is 2056 512-byte blocks).
Maybe squash in http://patchwork.ozlabs.org/patch/603047/ ?
It's too late to squash it in, but yes, that should be the fix for it.
Kevin
Re: [Qemu-devel] [PULL 48/48] iotests: Test qemu-img convert -S 0 behavior
Quoted 16 lines · Kevin Wolf
Am 08.04.2016 um 03:18 hat Fam Zheng geschrieben:
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Kevin Wolf
Quoted 10 lines
From: Max Reitz <[email protected]>
Passing -S 0 to qemu-img convert should result in all source data being copied to the output, even if that source data is known to be 0. The output image should therefore have exactly the same size on disk as an image which we explicitly filled with data.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Fam Zheng <[email protected]>Signed-off-by Kevin Wolf <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
This fails with XFS and raw format, which preallocates an extra cluster at the end of the file created with qemu-io (so that the on-disk size is 2056 512-byte blocks).
Maybe squash in http://patchwork.ozlabs.org/patch/603047/ ?
It's too late to squash it in, but yes, that should be the fix for it.
Yes, didn't know it's already merged.
Fam