From 4ab1559085d688dddf4de77f1ead3102e243e668 Mon Sep 17 00:00:00 2001 From: Chunyan Liu Date: Mon, 30 Jun 2014 14:29:58 +0800 Subject: qemu-img create: add 'nocow' option Add 'nocow' option so that users could have a chance to set NOCOW flag to newly created files. It's useful on btrfs file system to enhance performance. Btrfs has low performance when hosting VM images, even more when the guest in those VM are also using btrfs as file system. One way to mitigate this bad performance is to turn off COW attributes on VM files. Generally, there are two ways to turn off NOCOW on btrfs: a) by mounting fs with nodatacow, then all newly created files will be NOCOW. b) per file. Add the NOCOW file attribute. It could only be done to empty or new files. This patch tries the second way, according to the option, it could add NOCOW per file. For most block drivers, since the create file step is in raw-posix.c, so we can do setting NOCOW flag ioctl in raw-posix.c only. But there are some exceptions, like block/vpc.c and block/vdi.c, they are creating file by calling qemu_open directly. For them, do the same setting NOCOW flag ioctl work in them separately. [Fixed up 082.out due to the new 'nocow' creation option --Stefan] Signed-off-by: Chunyan Liu Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/082.out | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 28309a0..413e7ef 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -66,6 +66,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o ? TEST_DIR/t.qcow2 128M Supported options: @@ -77,6 +78,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o cluster_size=4k,help TEST_DIR/t.qcow2 128M Supported options: @@ -88,6 +90,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o cluster_size=4k,? TEST_DIR/t.qcow2 128M Supported options: @@ -99,6 +102,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o help,cluster_size=4k TEST_DIR/t.qcow2 128M Supported options: @@ -110,6 +114,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o ?,cluster_size=4k TEST_DIR/t.qcow2 128M Supported options: @@ -121,6 +126,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o cluster_size=4k -o help TEST_DIR/t.qcow2 128M Supported options: @@ -132,6 +138,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o cluster_size=4k -o ? TEST_DIR/t.qcow2 128M Supported options: @@ -143,6 +150,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: create -f qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2 128M Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=134217728 backing_file='TEST_DIR/t.qcow2,help' encryption=off cluster_size=65536 lazy_refcounts=off @@ -247,6 +255,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o ? TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -258,6 +267,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o cluster_size=4k,help TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -269,6 +279,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o cluster_size=4k,? TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -280,6 +291,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o help,cluster_size=4k TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -291,6 +303,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o ?,cluster_size=4k TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -302,6 +315,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o cluster_size=4k -o help TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -313,6 +327,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o cluster_size=4k -o ? TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base Supported options: @@ -324,6 +339,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: convert -O qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing file: Could not open 'TEST_DIR/t.qcow2,help': No such file or directory @@ -417,6 +433,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o ? TEST_DIR/t.qcow2 Supported options: @@ -428,6 +445,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o cluster_size=4k,help TEST_DIR/t.qcow2 Supported options: @@ -439,6 +457,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o cluster_size=4k,? TEST_DIR/t.qcow2 Supported options: @@ -450,6 +469,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o help,cluster_size=4k TEST_DIR/t.qcow2 Supported options: @@ -461,6 +481,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o ?,cluster_size=4k TEST_DIR/t.qcow2 Supported options: @@ -472,6 +493,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o cluster_size=4k -o help TEST_DIR/t.qcow2 Supported options: @@ -483,6 +505,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o cluster_size=4k -o ? TEST_DIR/t.qcow2 Supported options: @@ -494,6 +517,7 @@ encryption Encrypt the image cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata) lazy_refcounts Postpone refcount updates +nocow Turn off copy-on-write (valid only on btrfs) Testing: amend -f qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2 -- cgit v1.1 From 214a081a0dd44e69f7db4a741880a8ae9d174fa2 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Fri, 27 Jun 2014 22:47:46 +0200 Subject: iotests: Simplify qemu-iotests-quick.sh As of the "iotests: Allow out-of-tree run" series, the qemu-iotests may (and should) be run directly in the build tree and will then guess the binary paths themselves. Therefore, qemu-iotests-quick.sh does not need to (and should not) enter the source path anymore; also, it does not need to specify the binaries because "check" will guess them automatically. As a side-effect, tests using qemu may now be added to the quick group. Signed-off-by: Max Reitz Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests-quick.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests-quick.sh b/tests/qemu-iotests-quick.sh index c449e8a..8a9a4c6 100755 --- a/tests/qemu-iotests-quick.sh +++ b/tests/qemu-iotests-quick.sh @@ -1,16 +1,6 @@ #!/bin/sh -# We don't know which of the system emulator binaries there is (or if there is -# any at all), so the 'quick' group doesn't contain any tests that require -# running qemu proper. Assign a fake binary name so that qemu-iotests doesn't -# complain about the missing binary. -export QEMU_PROG="this_should_be_unused" - -export QEMU_IMG_PROG="$(pwd)/qemu-img" -export QEMU_IO_PROG="$(pwd)/qemu-io" -export QEMU_NBD_PROG="$(pwd)/qemu-nbd" - -cd $SRC_PATH/tests/qemu-iotests +cd tests/qemu-iotests ret=0 ./check -T -nocache -qcow2 -g quick || ret=1 -- cgit v1.1 From ee9dd1fc901f7098a1c2af5a2202bd7f41124dbc Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Fri, 27 Jun 2014 22:47:47 +0200 Subject: iotests: Add qemu tests to quick group Now that qemu-iotests-quick.sh supports tests using the qemu binary, we are free to add such tests to the quick group. Signed-off-by: Max Reitz Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/group | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index e3dc4e8..7a2bfca 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -51,7 +51,7 @@ 042 rw auto quick 043 rw auto backing 044 rw auto -045 rw auto +045 rw auto quick 046 rw auto aio 047 rw auto 048 img auto quick @@ -71,13 +71,13 @@ 062 rw auto quick 063 rw auto quick 064 rw auto quick -065 rw auto +065 rw auto quick 066 rw auto quick -067 rw auto -068 rw auto +067 rw auto quick +068 rw auto quick 069 rw auto quick 070 rw auto quick -071 rw auto +071 rw auto quick 072 rw auto quick 073 rw auto quick 074 rw auto quick @@ -87,16 +87,16 @@ 078 rw auto 079 rw auto 080 rw auto -081 rw auto +081 rw auto quick 082 rw auto quick 083 rw auto 084 img auto 085 rw auto 086 rw auto quick -087 rw auto +087 rw auto quick 088 rw auto 089 rw auto quick 090 rw auto quick -091 rw auto +091 rw auto quick 092 rw auto quick -095 rw auto +095 rw auto quick -- cgit v1.1 From c891e3bbc5bc3d74ad0ba896852a9796ceb147c2 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Fri, 27 Jun 2014 22:47:48 +0200 Subject: iotests: Add more tests to quick group While at it, add some more tests to the quick group (those that run with -nocache in under three seconds on my HDD). Signed-off-by: Max Reitz Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/group | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 7a2bfca..6e67f61 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -7,16 +7,16 @@ # # test-group association ... one line per test # -001 rw auto +001 rw auto quick 002 rw auto quick 003 rw auto 004 rw auto quick -005 img auto +005 img auto quick 006 img auto 007 snapshot auto -008 rw auto -009 rw auto -010 rw auto +008 rw auto quick +009 rw auto quick +010 rw auto quick 011 rw auto quick 012 auto quick 013 rw auto @@ -24,36 +24,36 @@ 015 rw snapshot auto 016 rw auto quick 017 rw backing auto quick -018 rw backing auto +018 rw backing auto quick 019 rw backing auto quick 020 rw backing auto quick -021 io auto +021 io auto quick 022 rw snapshot auto 023 rw auto 024 rw backing auto quick 025 rw auto quick 026 rw blkdbg auto 027 rw auto quick -028 rw backing auto +028 rw backing auto quick 029 rw auto quick 030 rw auto backing 031 rw auto quick -032 rw auto +032 rw auto quick 033 rw auto quick -034 rw auto backing +034 rw auto backing quick 035 rw auto quick 036 rw auto quick -037 rw auto backing -038 rw auto backing -039 rw auto +037 rw auto backing quick +038 rw auto backing quick +039 rw auto quick 040 rw auto 041 rw auto backing 042 rw auto quick 043 rw auto backing 044 rw auto 045 rw auto quick -046 rw auto aio -047 rw auto +046 rw auto aio quick +047 rw auto quick 048 img auto quick 049 rw auto 050 rw auto backing quick @@ -81,20 +81,20 @@ 072 rw auto quick 073 rw auto quick 074 rw auto quick -075 rw auto +075 rw auto quick 076 auto 077 rw auto quick -078 rw auto +078 rw auto quick 079 rw auto 080 rw auto 081 rw auto quick 082 rw auto quick 083 rw auto -084 img auto +084 img auto quick 085 rw auto 086 rw auto quick 087 rw auto quick -088 rw auto +088 rw auto quick 089 rw auto quick 090 rw auto quick 091 rw auto quick -- cgit v1.1 From 7676e2c597000eff3a7233b40cca768b358f9bc9 Mon Sep 17 00:00:00 2001 From: Jeff Cody Date: Mon, 30 Jun 2014 15:14:15 +0200 Subject: block: make 'top' argument to block-commit optional Now that active layer block-commit is supported, the 'top' argument no longer needs to be mandatory. Change it to optional, with the default being the active layer in the device chain. [kwolf: Rebased and resolved conflict in tests/qemu-iotests/040] Reviewed-by: Eric Blake Reviewed-by: Benoit Canet Signed-off-by: Jeff Cody Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/040 | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index d166810..f1e16c1 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -35,11 +35,7 @@ test_img = os.path.join(iotests.test_dir, 'test.img') class ImageCommitTestCase(iotests.QMPTestCase): '''Abstract base class for image commit test cases''' - def run_commit_test(self, top, base, need_ready=False): - self.assert_no_active_block_jobs() - result = self.vm.qmp('block-commit', device='drive0', top=top, base=base) - self.assert_qmp(result, 'return', {}) - + def wait_for_complete(self, need_ready=False): completed = False ready = False while not completed: @@ -62,6 +58,18 @@ class ImageCommitTestCase(iotests.QMPTestCase): self.assert_no_active_block_jobs() self.vm.shutdown() + def run_commit_test(self, top, base, need_ready=False): + self.assert_no_active_block_jobs() + result = self.vm.qmp('block-commit', device='drive0', top=top, base=base) + self.assert_qmp(result, 'return', {}) + self.wait_for_complete(need_ready) + + def run_default_commit_test(self): + self.assert_no_active_block_jobs() + result = self.vm.qmp('block-commit', device='drive0') + self.assert_qmp(result, 'return', {}) + self.wait_for_complete() + class TestSingleDrive(ImageCommitTestCase): image_len = 1 * 1024 * 1024 test_len = 1 * 1024 * 256 @@ -113,17 +121,17 @@ class TestSingleDrive(ImageCommitTestCase): self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) + def test_top_is_default_active(self): + self.run_default_commit_test() + self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) + self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) + def test_top_and_base_reversed(self): self.assert_no_active_block_jobs() result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % mid_img) self.assert_qmp(result, 'error/class', 'GenericError') self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img) - def test_top_omitted(self): - self.assert_no_active_block_jobs() - result = self.vm.qmp('block-commit', device='drive0') - self.assert_qmp(result, 'error/class', 'GenericError') - self.assert_qmp(result, 'error/desc', "Parameter 'top' is missing") class TestRelativePaths(ImageCommitTestCase): image_len = 1 * 1024 * 1024 -- cgit v1.1