1 | The following changes since commit 23919ddfd56135cad3cb468a8f54d5a595f024f4: | 1 | The following changes since commit 171199f56f5f9bdf1e5d670d09ef1351d8f01bae: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20190827' into staging (2019-08-27 15:52:36 +0100) | 3 | Merge remote-tracking branch 'remotes/alistair/tags/pull-riscv-to-apply-20200619-3' into staging (2020-06-22 14:45:25 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/XanClic/qemu.git tags/pull-block-2019-08-27 | 7 | https://github.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to bb043c056cffcc2f3ce88bfdaf2e76e455c09e2c: | 9 | for you to fetch changes up to 7838c67f22a81fcf669785cd6c0876438422071a: |
10 | 10 | ||
11 | iotests: Unify cache mode quoting (2019-08-27 19:48:44 +0200) | 11 | block/nvme: support nested aio_poll() (2020-06-23 15:46:08 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches: | 14 | Pull request |
15 | - qemu-io now accepts a file to read a write pattern from | ||
16 | - Ensure that raw files have their first block allocated so we can probe | ||
17 | the O_DIRECT alignment if necessary | ||
18 | - Various fixes | ||
19 | 15 | ||
20 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
21 | Denis Plotnikov (1): | ||
22 | qemu-io: add pattern file for write command | ||
23 | 17 | ||
24 | Max Reitz (7): | 18 | Daniele Buono (4): |
25 | iotests: Fix _filter_img_create() | 19 | coroutine: support SafeStack in ucontext backend |
26 | vmdk: Use bdrv_dirname() for relative extent paths | 20 | coroutine: add check for SafeStack in sigaltstack |
27 | iotests: Keep testing broken relative extent paths | 21 | configure: add flags to support SafeStack |
28 | vmdk: Reject invalid compressed writes | 22 | check-block: enable iotests with SafeStack |
29 | iotests: Disable broken streamOptimized tests | ||
30 | iotests: Disable 110 for vmdk.twoGbMaxExtentSparse | ||
31 | iotests: Disable 126 for flat vmdk subformats | ||
32 | 23 | ||
33 | Nir Soffer (3): | 24 | Stefan Hajnoczi (8): |
34 | block: posix: Always allocate the first block | 25 | minikconf: explicitly set encoding to UTF-8 |
35 | iotests: Test allocate_first_block() with O_DIRECT | 26 | block/nvme: poll queues without q->lock |
36 | iotests: Unify cache mode quoting | 27 | block/nvme: drop tautologous assertion |
28 | block/nvme: don't access CQE after moving cq.head | ||
29 | block/nvme: switch to a NVMeRequest freelist | ||
30 | block/nvme: clarify that free_req_queue is protected by q->lock | ||
31 | block/nvme: keep BDRVNVMeState pointer in NVMeQueuePair | ||
32 | block/nvme: support nested aio_poll() | ||
37 | 33 | ||
38 | Stefan Hajnoczi (1): | 34 | configure | 73 ++++++++++++ |
39 | file-posix: fix request_alignment typo | 35 | include/qemu/coroutine_int.h | 5 + |
40 | 36 | block/nvme.c | 220 +++++++++++++++++++++++++---------- | |
41 | Thomas Huth (2): | 37 | util/coroutine-sigaltstack.c | 4 + |
42 | iotests: Check for enabled drivers before testing them | 38 | util/coroutine-ucontext.c | 28 +++++ |
43 | tests/check-block: Skip iotests when sanitizers are enabled | 39 | block/trace-events | 2 +- |
44 | 40 | scripts/minikconf.py | 6 +- | |
45 | Vladimir Sementsov-Ogievskiy (1): | 41 | tests/check-block.sh | 12 +- |
46 | block: fix permission update in bdrv_replace_node | 42 | 8 files changed, 284 insertions(+), 66 deletions(-) |
47 | |||
48 | block.c | 5 +- | ||
49 | block/file-posix.c | 53 +++++++++- | ||
50 | block/vmdk.c | 64 ++++++++---- | ||
51 | qemu-io-cmds.c | 99 +++++++++++++++++-- | ||
52 | tests/check-block.sh | 5 + | ||
53 | tests/qemu-iotests/002 | 1 + | ||
54 | tests/qemu-iotests/003 | 1 + | ||
55 | tests/qemu-iotests/005 | 3 +- | ||
56 | tests/qemu-iotests/009 | 1 + | ||
57 | tests/qemu-iotests/010 | 1 + | ||
58 | tests/qemu-iotests/011 | 1 + | ||
59 | tests/qemu-iotests/017 | 3 +- | ||
60 | tests/qemu-iotests/018 | 3 +- | ||
61 | tests/qemu-iotests/019 | 3 +- | ||
62 | tests/qemu-iotests/020 | 3 +- | ||
63 | tests/qemu-iotests/026 | 4 +- | ||
64 | tests/qemu-iotests/027 | 1 + | ||
65 | tests/qemu-iotests/032 | 1 + | ||
66 | tests/qemu-iotests/033 | 1 + | ||
67 | tests/qemu-iotests/034 | 3 +- | ||
68 | tests/qemu-iotests/037 | 3 +- | ||
69 | tests/qemu-iotests/039 | 4 +- | ||
70 | tests/qemu-iotests/052 | 2 +- | ||
71 | tests/qemu-iotests/059 | 34 ++++++- | ||
72 | tests/qemu-iotests/059.out | 26 +++-- | ||
73 | tests/qemu-iotests/063 | 3 +- | ||
74 | tests/qemu-iotests/071 | 1 + | ||
75 | tests/qemu-iotests/072 | 1 + | ||
76 | tests/qemu-iotests/081 | 4 +- | ||
77 | tests/qemu-iotests/091 | 4 +- | ||
78 | tests/qemu-iotests/099 | 1 + | ||
79 | tests/qemu-iotests/105 | 3 +- | ||
80 | tests/qemu-iotests/110 | 3 +- | ||
81 | tests/qemu-iotests/120 | 1 + | ||
82 | tests/qemu-iotests/126 | 2 + | ||
83 | tests/qemu-iotests/{150.out => 150.out.qcow2} | 0 | ||
84 | tests/qemu-iotests/150.out.raw | 12 +++ | ||
85 | tests/qemu-iotests/162 | 4 +- | ||
86 | tests/qemu-iotests/175 | 47 +++++++-- | ||
87 | tests/qemu-iotests/175.out | 16 ++- | ||
88 | tests/qemu-iotests/178.out.qcow2 | 4 +- | ||
89 | tests/qemu-iotests/184 | 1 + | ||
90 | tests/qemu-iotests/186 | 1 + | ||
91 | tests/qemu-iotests/197 | 1 + | ||
92 | tests/qemu-iotests/215 | 1 + | ||
93 | tests/qemu-iotests/221.out | 12 ++- | ||
94 | tests/qemu-iotests/251 | 1 + | ||
95 | tests/qemu-iotests/253.out | 12 ++- | ||
96 | tests/qemu-iotests/common.filter | 4 +- | ||
97 | tests/qemu-iotests/common.rc | 14 +++ | ||
98 | 50 files changed, 391 insertions(+), 87 deletions(-) | ||
99 | rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%) | ||
100 | create mode 100644 tests/qemu-iotests/150.out.raw | ||
101 | 43 | ||
102 | -- | 44 | -- |
103 | 2.21.0 | 45 | 2.26.2 |
104 | 46 | ||
105 | diff view generated by jsdifflib |
1 | From: Nir Soffer <nirsof@gmail.com> | 1 | QEMU currently only has ASCII Kconfig files but Linux actually uses |
---|---|---|---|
2 | UTF-8. Explicitly specify the encoding and that we're doing text file | ||
3 | I/O. | ||
2 | 4 | ||
3 | Quoting cache mode is not needed, and most tests use unquoted values. | 5 | It's unclear whether or not QEMU will ever need Unicode in its Kconfig |
4 | Unify all test to use the same style. | 6 | files. If we start using the help text then it will become an issue |
7 | sooner or later. Make this change now for consistency with Linux | ||
8 | Kconfig. | ||
5 | 9 | ||
6 | Message-id: 20190827173432.7656-1-nsoffer@redhat.com | 10 | Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
7 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
13 | Message-id: 20200521153616.307100-1-stefanha@redhat.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 15 | --- |
10 | tests/qemu-iotests/026 | 4 ++-- | 16 | scripts/minikconf.py | 6 +++--- |
11 | tests/qemu-iotests/039 | 4 ++-- | 17 | 1 file changed, 3 insertions(+), 3 deletions(-) |
12 | tests/qemu-iotests/052 | 2 +- | ||
13 | tests/qemu-iotests/091 | 4 ++-- | ||
14 | 4 files changed, 7 insertions(+), 7 deletions(-) | ||
15 | 18 | ||
16 | diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026 | 19 | diff --git a/scripts/minikconf.py b/scripts/minikconf.py |
17 | index XXXXXXX..XXXXXXX 100755 | 20 | index XXXXXXX..XXXXXXX 100755 |
18 | --- a/tests/qemu-iotests/026 | 21 | --- a/scripts/minikconf.py |
19 | +++ b/tests/qemu-iotests/026 | 22 | +++ b/scripts/minikconf.py |
20 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 23 | @@ -XXX,XX +XXX,XX @@ class KconfigParser: |
21 | # Currently only qcow2 supports rebasing | 24 | if incl_abs_fname in self.data.previously_included: |
22 | _supported_fmt qcow2 | 25 | return |
23 | _supported_proto file | 26 | try: |
24 | -_default_cache_mode "writethrough" | 27 | - fp = open(incl_abs_fname, 'r') |
25 | -_supported_cache_modes "writethrough" "none" | 28 | + fp = open(incl_abs_fname, 'rt', encoding='utf-8') |
26 | +_default_cache_mode writethrough | 29 | except IOError as e: |
27 | +_supported_cache_modes writethrough none | 30 | raise KconfigParserError(self, |
28 | # The refcount table tests expect a certain minimum width for refcount entries | 31 | '%s: %s' % (e.strerror, include)) |
29 | # (so that the refcount table actually needs to grow); that minimum is 16 bits, | 32 | @@ -XXX,XX +XXX,XX @@ if __name__ == '__main__': |
30 | # being the default refcount entry width. | 33 | parser.do_assignment(name, value == 'y') |
31 | diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039 | 34 | external_vars.add(name[7:]) |
32 | index XXXXXXX..XXXXXXX 100755 | 35 | else: |
33 | --- a/tests/qemu-iotests/039 | 36 | - fp = open(arg, 'r') |
34 | +++ b/tests/qemu-iotests/039 | 37 | + fp = open(arg, 'rt', encoding='utf-8') |
35 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 38 | parser.parse_file(fp) |
36 | _supported_fmt qcow2 | 39 | fp.close() |
37 | _supported_proto file | 40 | |
38 | _supported_os Linux | 41 | @@ -XXX,XX +XXX,XX @@ if __name__ == '__main__': |
39 | -_default_cache_mode "writethrough" | 42 | if key not in external_vars and config[key]: |
40 | -_supported_cache_modes "writethrough" | 43 | print ('CONFIG_%s=y' % key) |
41 | +_default_cache_mode writethrough | 44 | |
42 | +_supported_cache_modes writethrough | 45 | - deps = open(argv[2], 'w') |
43 | 46 | + deps = open(argv[2], 'wt', encoding='utf-8') | |
44 | size=128M | 47 | for fname in data.previously_included: |
45 | 48 | print ('%s: %s' % (argv[1], fname), file=deps) | |
46 | diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052 | 49 | deps.close() |
47 | index XXXXXXX..XXXXXXX 100755 | ||
48 | --- a/tests/qemu-iotests/052 | ||
49 | +++ b/tests/qemu-iotests/052 | ||
50 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
51 | _supported_proto file | ||
52 | |||
53 | # Don't do O_DIRECT on tmpfs | ||
54 | -_supported_cache_modes "writeback" "writethrough" "unsafe" | ||
55 | +_supported_cache_modes writeback writethrough unsafe | ||
56 | |||
57 | size=128M | ||
58 | _make_test_img $size | ||
59 | diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091 | ||
60 | index XXXXXXX..XXXXXXX 100755 | ||
61 | --- a/tests/qemu-iotests/091 | ||
62 | +++ b/tests/qemu-iotests/091 | ||
63 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
64 | _supported_fmt qcow2 | ||
65 | _supported_proto file | ||
66 | _supported_os Linux | ||
67 | -_default_cache_mode "none" | ||
68 | -_supported_cache_modes "writethrough" "none" "writeback" | ||
69 | +_default_cache_mode none | ||
70 | +_supported_cache_modes writethrough none writeback | ||
71 | |||
72 | size=1G | ||
73 | |||
74 | -- | 50 | -- |
75 | 2.21.0 | 51 | 2.26.2 |
76 | 52 | ||
77 | diff view generated by jsdifflib |
1 | The error message for the test case where we have a quorum node for | 1 | From: Daniele Buono <dbuono@linux.vnet.ibm.com> |
---|---|---|---|
2 | which no directory name can be generated is different: For | ||
3 | twoGbMaxExtentSparse, it complains that it cannot open the extent file. | ||
4 | For other (sub)formats, it just notes that it cannot determine the | ||
5 | backing file path. Both are fine, but just disable twoGbMaxExtentSparse | ||
6 | for simplicity's sake. | ||
7 | 2 | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 3 | LLVM's SafeStack instrumentation does not yet support programs that make |
9 | Reviewed-by: John Snow <jsnow@redhat.com> | 4 | use of the APIs in ucontext.h |
10 | Message-id: 20190815153638.4600-7-mreitz@redhat.com | 5 | With the current implementation of coroutine-ucontext, the resulting |
11 | Reviewed-by: John Snow <jsnow@redhat.com> | 6 | binary is incorrect, with different coroutines sharing the same unsafe |
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 7 | stack and producing undefined behavior at runtime. |
8 | This fix allocates an additional unsafe stack area for each coroutine, | ||
9 | and sets the new unsafe stack pointer before calling swapcontext() in | ||
10 | qemu_coroutine_new. | ||
11 | This is the only place where the pointer needs to be manually updated, | ||
12 | since sigsetjmp/siglongjmp are already instrumented by LLVM to properly | ||
13 | support SafeStack. | ||
14 | The additional stack is then freed in qemu_coroutine_delete. | ||
15 | |||
16 | Signed-off-by: Daniele Buono <dbuono@linux.vnet.ibm.com> | ||
17 | Message-id: 20200529205122.714-2-dbuono@linux.vnet.ibm.com | ||
18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | 19 | --- |
14 | tests/qemu-iotests/110 | 3 ++- | 20 | include/qemu/coroutine_int.h | 5 +++++ |
15 | 1 file changed, 2 insertions(+), 1 deletion(-) | 21 | util/coroutine-ucontext.c | 28 ++++++++++++++++++++++++++++ |
22 | 2 files changed, 33 insertions(+) | ||
16 | 23 | ||
17 | diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110 | 24 | diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h |
18 | index XXXXXXX..XXXXXXX 100755 | 25 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tests/qemu-iotests/110 | 26 | --- a/include/qemu/coroutine_int.h |
20 | +++ b/tests/qemu-iotests/110 | 27 | +++ b/include/qemu/coroutine_int.h |
21 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 28 | @@ -XXX,XX +XXX,XX @@ |
22 | # Any format supporting backing files | 29 | #include "qemu/queue.h" |
23 | _supported_fmt qed qcow qcow2 vmdk | 30 | #include "qemu/coroutine.h" |
24 | _supported_proto file | 31 | |
25 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | 32 | +#ifdef CONFIG_SAFESTACK |
26 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | 33 | +/* Pointer to the unsafe stack, defined by the compiler */ |
27 | + "subformat=twoGbMaxExtentSparse" | 34 | +extern __thread void *__safestack_unsafe_stack_ptr; |
28 | 35 | +#endif | |
29 | TEST_IMG_REL=$(basename "$TEST_IMG") | 36 | + |
37 | #define COROUTINE_STACK_SIZE (1 << 20) | ||
38 | |||
39 | typedef enum { | ||
40 | diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/util/coroutine-ucontext.c | ||
43 | +++ b/util/coroutine-ucontext.c | ||
44 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
45 | Coroutine base; | ||
46 | void *stack; | ||
47 | size_t stack_size; | ||
48 | +#ifdef CONFIG_SAFESTACK | ||
49 | + /* Need an unsafe stack for each coroutine */ | ||
50 | + void *unsafe_stack; | ||
51 | + size_t unsafe_stack_size; | ||
52 | +#endif | ||
53 | sigjmp_buf env; | ||
54 | |||
55 | void *tsan_co_fiber; | ||
56 | @@ -XXX,XX +XXX,XX @@ Coroutine *qemu_coroutine_new(void) | ||
57 | co = g_malloc0(sizeof(*co)); | ||
58 | co->stack_size = COROUTINE_STACK_SIZE; | ||
59 | co->stack = qemu_alloc_stack(&co->stack_size); | ||
60 | +#ifdef CONFIG_SAFESTACK | ||
61 | + co->unsafe_stack_size = COROUTINE_STACK_SIZE; | ||
62 | + co->unsafe_stack = qemu_alloc_stack(&co->unsafe_stack_size); | ||
63 | +#endif | ||
64 | co->base.entry_arg = &old_env; /* stash away our jmp_buf */ | ||
65 | |||
66 | uc.uc_link = &old_uc; | ||
67 | @@ -XXX,XX +XXX,XX @@ Coroutine *qemu_coroutine_new(void) | ||
68 | COROUTINE_YIELD, | ||
69 | &fake_stack_save, | ||
70 | co->stack, co->stack_size, co->tsan_co_fiber); | ||
71 | + | ||
72 | +#ifdef CONFIG_SAFESTACK | ||
73 | + /* | ||
74 | + * Before we swap the context, set the new unsafe stack | ||
75 | + * The unsafe stack grows just like the normal stack, so start from | ||
76 | + * the last usable location of the memory area. | ||
77 | + * NOTE: we don't have to re-set the usp afterwards because we are | ||
78 | + * coming back to this context through a siglongjmp. | ||
79 | + * The compiler already wrapped the corresponding sigsetjmp call with | ||
80 | + * code that saves the usp on the (safe) stack before the call, and | ||
81 | + * restores it right after (which is where we return with siglongjmp). | ||
82 | + */ | ||
83 | + void *usp = co->unsafe_stack + co->unsafe_stack_size; | ||
84 | + __safestack_unsafe_stack_ptr = usp; | ||
85 | +#endif | ||
86 | + | ||
87 | swapcontext(&old_uc, &uc); | ||
88 | } | ||
89 | |||
90 | @@ -XXX,XX +XXX,XX @@ void qemu_coroutine_delete(Coroutine *co_) | ||
91 | #endif | ||
92 | |||
93 | qemu_free_stack(co->stack, co->stack_size); | ||
94 | +#ifdef CONFIG_SAFESTACK | ||
95 | + qemu_free_stack(co->unsafe_stack, co->unsafe_stack_size); | ||
96 | +#endif | ||
97 | g_free(co); | ||
98 | } | ||
30 | 99 | ||
31 | -- | 100 | -- |
32 | 2.21.0 | 101 | 2.26.2 |
33 | 102 | ||
34 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Daniele Buono <dbuono@linux.vnet.ibm.com> |
---|---|---|---|
2 | 2 | ||
3 | It is possible to enable only a subset of the block drivers with the | 3 | Current implementation of LLVM's SafeStack is not compatible with |
4 | "--block-drv-rw-whitelist" option of the "configure" script. All other | 4 | code that uses an alternate stack created with sigaltstack(). |
5 | drivers are marked as unusable (or only included as read-only with the | 5 | Since coroutine-sigaltstack relies on sigaltstack(), it is not |
6 | "--block-drv-ro-whitelist" option). If an iotest is now using such a | 6 | compatible with SafeStack. The resulting binary is incorrect, with |
7 | disabled block driver, it is failing - which is bad, since at least the | 7 | different coroutines sharing the same unsafe stack and producing |
8 | tests in the "auto" group should be able to deal with this situation. | 8 | undefined behavior at runtime. |
9 | Thus let's introduce a "_require_drivers" function that can be used by | ||
10 | the shell tests to check for the availability of certain drivers first, | ||
11 | and marks the test as "not run" if one of the drivers is missing. | ||
12 | 9 | ||
13 | This patch mainly targets the test in the "auto" group which should | 10 | In the future LLVM may provide a SafeStack implementation compatible with |
14 | never fail in such a case, but also improves some of the other tests | 11 | sigaltstack(). In the meantime, if SafeStack is desired, the coroutine |
15 | along the way. Note that we also assume that the "qcow2" and "file" | 12 | implementation from coroutine-ucontext should be used. |
16 | drivers are always available - otherwise it does not make sense to | 13 | As a safety check, add a control in coroutine-sigaltstack to throw a |
17 | run "make check-block" at all (which only tests with qcow2 by default). | 14 | preprocessor #error if SafeStack is enabled and we are trying to |
15 | use coroutine-sigaltstack to implement coroutines. | ||
18 | 16 | ||
19 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 17 | Signed-off-by: Daniele Buono <dbuono@linux.vnet.ibm.com> |
20 | Message-id: 20190823133552.11680-1-thuth@redhat.com | 18 | Message-id: 20200529205122.714-3-dbuono@linux.vnet.ibm.com |
21 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 19 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
22 | --- | 20 | --- |
23 | tests/qemu-iotests/071 | 1 + | 21 | util/coroutine-sigaltstack.c | 4 ++++ |
24 | tests/qemu-iotests/081 | 4 +--- | 22 | 1 file changed, 4 insertions(+) |
25 | tests/qemu-iotests/099 | 1 + | ||
26 | tests/qemu-iotests/120 | 1 + | ||
27 | tests/qemu-iotests/162 | 4 +--- | ||
28 | tests/qemu-iotests/184 | 1 + | ||
29 | tests/qemu-iotests/186 | 1 + | ||
30 | tests/qemu-iotests/common.rc | 14 ++++++++++++++ | ||
31 | 8 files changed, 21 insertions(+), 6 deletions(-) | ||
32 | 23 | ||
33 | diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071 | 24 | diff --git a/util/coroutine-sigaltstack.c b/util/coroutine-sigaltstack.c |
34 | index XXXXXXX..XXXXXXX 100755 | ||
35 | --- a/tests/qemu-iotests/071 | ||
36 | +++ b/tests/qemu-iotests/071 | ||
37 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
38 | |||
39 | _supported_fmt qcow2 | ||
40 | _supported_proto file | ||
41 | +_require_drivers blkdebug blkverify | ||
42 | |||
43 | do_run_qemu() | ||
44 | { | ||
45 | diff --git a/tests/qemu-iotests/081 b/tests/qemu-iotests/081 | ||
46 | index XXXXXXX..XXXXXXX 100755 | ||
47 | --- a/tests/qemu-iotests/081 | ||
48 | +++ b/tests/qemu-iotests/081 | ||
49 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
50 | _supported_fmt raw | ||
51 | _supported_proto file | ||
52 | _supported_os Linux | ||
53 | +_require_drivers quorum | ||
54 | |||
55 | do_run_qemu() | ||
56 | { | ||
57 | @@ -XXX,XX +XXX,XX @@ run_qemu() | ||
58 | | _filter_qemu_io | _filter_generated_node_ids | ||
59 | } | ||
60 | |||
61 | -test_quorum=$($QEMU_IMG --help|grep quorum) | ||
62 | -[ "$test_quorum" = "" ] && _supported_fmt quorum | ||
63 | - | ||
64 | quorum="driver=raw,file.driver=quorum,file.vote-threshold=2" | ||
65 | quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" | ||
66 | quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" | ||
67 | diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099 | ||
68 | index XXXXXXX..XXXXXXX 100755 | ||
69 | --- a/tests/qemu-iotests/099 | ||
70 | +++ b/tests/qemu-iotests/099 | ||
71 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
72 | _supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc | ||
73 | _supported_proto file | ||
74 | _supported_os Linux | ||
75 | +_require_drivers blkdebug blkverify | ||
76 | _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
77 | "subformat=twoGbMaxExtentSparse" | ||
78 | |||
79 | diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120 | ||
80 | index XXXXXXX..XXXXXXX 100755 | ||
81 | --- a/tests/qemu-iotests/120 | ||
82 | +++ b/tests/qemu-iotests/120 | ||
83 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
84 | _supported_fmt generic | ||
85 | _supported_proto file | ||
86 | _unsupported_fmt luks | ||
87 | +_require_drivers raw | ||
88 | |||
89 | _make_test_img 64M | ||
90 | |||
91 | diff --git a/tests/qemu-iotests/162 b/tests/qemu-iotests/162 | ||
92 | index XXXXXXX..XXXXXXX 100755 | ||
93 | --- a/tests/qemu-iotests/162 | ||
94 | +++ b/tests/qemu-iotests/162 | ||
95 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
96 | . ./common.filter | ||
97 | |||
98 | _supported_fmt generic | ||
99 | - | ||
100 | -test_ssh=$($QEMU_IMG --help | grep '^Supported formats:.* ssh\( \|$\)') | ||
101 | -[ "$test_ssh" = "" ] && _notrun "ssh support required" | ||
102 | +_require_drivers ssh | ||
103 | |||
104 | echo | ||
105 | echo '=== NBD ===' | ||
106 | diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184 | ||
107 | index XXXXXXX..XXXXXXX 100755 | ||
108 | --- a/tests/qemu-iotests/184 | ||
109 | +++ b/tests/qemu-iotests/184 | ||
110 | @@ -XXX,XX +XXX,XX @@ trap "exit \$status" 0 1 2 3 15 | ||
111 | . ./common.filter | ||
112 | |||
113 | _supported_os Linux | ||
114 | +_require_drivers throttle | ||
115 | |||
116 | do_run_qemu() | ||
117 | { | ||
118 | diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186 | ||
119 | index XXXXXXX..XXXXXXX 100755 | ||
120 | --- a/tests/qemu-iotests/186 | ||
121 | +++ b/tests/qemu-iotests/186 | ||
122 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
123 | |||
124 | _supported_fmt qcow2 | ||
125 | _supported_proto file | ||
126 | +_require_drivers null-co | ||
127 | |||
128 | if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then | ||
129 | _notrun "Requires a PC machine" | ||
130 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
131 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
132 | --- a/tests/qemu-iotests/common.rc | 26 | --- a/util/coroutine-sigaltstack.c |
133 | +++ b/tests/qemu-iotests/common.rc | 27 | +++ b/util/coroutine-sigaltstack.c |
134 | @@ -XXX,XX +XXX,XX @@ _require_command() | 28 | @@ -XXX,XX +XXX,XX @@ |
135 | [ -x "$c" ] || _notrun "$1 utility required, skipped this test" | 29 | #include "qemu-common.h" |
136 | } | 30 | #include "qemu/coroutine_int.h" |
137 | 31 | ||
138 | +# Check that a set of drivers has been whitelisted in the QEMU binary | 32 | +#ifdef CONFIG_SAFESTACK |
139 | +# | 33 | +#error "SafeStack is not compatible with code run in alternate signal stacks" |
140 | +_require_drivers() | 34 | +#endif |
141 | +{ | ||
142 | + available=$($QEMU -drive format=help | \ | ||
143 | + sed -e '/Supported formats:/!d' -e 's/Supported formats://') | ||
144 | + for driver | ||
145 | + do | ||
146 | + if ! echo "$available" | grep -q " $driver\( \|$\)"; then | ||
147 | + _notrun "$driver not available" | ||
148 | + fi | ||
149 | + done | ||
150 | +} | ||
151 | + | 35 | + |
152 | # make sure this script returns success | 36 | typedef struct { |
153 | true | 37 | Coroutine base; |
38 | void *stack; | ||
154 | -- | 39 | -- |
155 | 2.21.0 | 40 | 2.26.2 |
156 | 41 | ||
157 | diff view generated by jsdifflib |
1 | We had a test for a case where relative extent paths did not work, but | 1 | From: Daniele Buono <dbuono@linux.vnet.ibm.com> |
---|---|---|---|
2 | unfortunately we just fixed the underlying problem, so it works now. | ||
3 | This patch adds a new test case that still fails. | ||
4 | 2 | ||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 3 | This patch adds a flag to enable/disable the SafeStack instrumentation |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 4 | provided by LLVM. |
7 | Message-id: 20190815153638.4600-4-mreitz@redhat.com | 5 | |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 6 | On enable, make sure that the compiler supports the flags, and that we |
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 7 | are using the proper coroutine implementation (coroutine-ucontext). |
8 | On disable, explicitly disable the option if it was enabled by default. | ||
9 | |||
10 | While SafeStack is supported only on Linux, NetBSD, FreeBSD and macOS, | ||
11 | we are not checking for the O.S. since this is already done by LLVM. | ||
12 | |||
13 | Signed-off-by: Daniele Buono <dbuono@linux.vnet.ibm.com> | ||
14 | Message-id: 20200529205122.714-4-dbuono@linux.vnet.ibm.com | ||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | 16 | --- |
11 | tests/qemu-iotests/059 | 27 +++++++++++++++++++++++++++ | 17 | configure | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | tests/qemu-iotests/059.out | 4 ++++ | 18 | 1 file changed, 73 insertions(+) |
13 | 2 files changed, 31 insertions(+) | ||
14 | 19 | ||
15 | diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 | 20 | diff --git a/configure b/configure |
16 | index XXXXXXX..XXXXXXX 100755 | 21 | index XXXXXXX..XXXXXXX 100755 |
17 | --- a/tests/qemu-iotests/059 | 22 | --- a/configure |
18 | +++ b/tests/qemu-iotests/059 | 23 | +++ b/configure |
19 | @@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2 | 24 | @@ -XXX,XX +XXX,XX @@ audio_win_int="" |
20 | 25 | libs_qga="" | |
21 | echo | 26 | debug_info="yes" |
22 | echo "=== Testing monolithicFlat with internally generated JSON file name ===" | 27 | stack_protector="" |
23 | + | 28 | +safe_stack="" |
24 | +echo '--- blkdebug ---' | 29 | use_containers="yes" |
25 | # Should work, because bdrv_dirname() works fine with blkdebug | 30 | gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb") |
26 | IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | 31 | |
27 | $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \ | 32 | @@ -XXX,XX +XXX,XX @@ for opt do |
28 | @@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TE | 33 | ;; |
29 | | _filter_testdir | _filter_imgfmt | _filter_img_info | 34 | --disable-stack-protector) stack_protector="no" |
30 | _cleanup_test_img | 35 | ;; |
31 | 36 | + --enable-safe-stack) safe_stack="yes" | |
32 | +echo '--- quorum ---' | 37 | + ;; |
33 | +# Should not work, because bdrv_dirname() does not work with quorum | 38 | + --disable-safe-stack) safe_stack="no" |
34 | +IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | 39 | + ;; |
35 | +cp "$TEST_IMG" "$TEST_IMG.orig" | 40 | --disable-curses) curses="no" |
36 | + | 41 | ;; |
37 | +filename="json:{ | 42 | --enable-curses) curses="yes" |
38 | + \"driver\": \"$IMGFMT\", | 43 | @@ -XXX,XX +XXX,XX @@ disabled with --disable-FEATURE, default is enabled if available: |
39 | + \"file\": { | 44 | debug-tcg TCG debugging (default is disabled) |
40 | + \"driver\": \"quorum\", | 45 | debug-info debugging information |
41 | + \"children\": [ { | 46 | sparse sparse checker |
42 | + \"driver\": \"file\", | 47 | + safe-stack SafeStack Stack Smash Protection. Depends on |
43 | + \"filename\": \"$TEST_IMG\" | 48 | + clang/llvm >= 3.7 and requires coroutine backend ucontext. |
44 | + }, { | 49 | |
45 | + \"driver\": \"file\", | 50 | gnutls GNUTLS cryptography support |
46 | + \"filename\": \"$TEST_IMG.orig\" | 51 | nettle nettle cryptography support |
47 | + } ], | 52 | @@ -XXX,XX +XXX,XX @@ if test "$debug_stack_usage" = "yes"; then |
48 | + \"vote-threshold\": 1 | 53 | fi |
49 | + } }" | 54 | fi |
50 | + | 55 | |
51 | +filename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g') | 56 | +################################################## |
52 | +$QEMU_IMG info "$filename" 2>&1 \ | 57 | +# SafeStack |
53 | + | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \ | ||
54 | + | _filter_testdir | _filter_imgfmt | _filter_img_info | ||
55 | + | 58 | + |
56 | + | 59 | + |
57 | echo | 60 | +if test "$safe_stack" = "yes"; then |
58 | echo "=== Testing version 3 ===" | 61 | +cat > $TMPC << EOF |
59 | _use_sample_img iotest-version3.vmdk.bz2 | 62 | +int main(int argc, char *argv[]) |
60 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | 63 | +{ |
61 | index XXXXXXX..XXXXXXX 100644 | 64 | +#if ! __has_feature(safe_stack) |
62 | --- a/tests/qemu-iotests/059.out | 65 | +#error SafeStack Disabled |
63 | +++ b/tests/qemu-iotests/059.out | 66 | +#endif |
64 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | 67 | + return 0; |
65 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 68 | +} |
66 | 69 | +EOF | |
67 | === Testing monolithicFlat with internally generated JSON file name === | 70 | + flag="-fsanitize=safe-stack" |
68 | +--- blkdebug --- | 71 | + # Check that safe-stack is supported and enabled. |
69 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | 72 | + if compile_prog "-Werror $flag" "$flag"; then |
70 | format name: IMGFMT | 73 | + # Flag needed both at compilation and at linking |
71 | cluster size: 0 bytes | 74 | + QEMU_CFLAGS="$QEMU_CFLAGS $flag" |
72 | vm state offset: 0 bytes | 75 | + QEMU_LDFLAGS="$QEMU_LDFLAGS $flag" |
73 | +--- quorum --- | 76 | + else |
74 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | 77 | + error_exit "SafeStack not supported by your compiler" |
75 | +qemu-img: Could not open $QUORUM_FILE: Cannot use relative paths with VMDK descriptor file $QUORUM_FILE: Cannot generate a base directory for quorum nodes | 78 | + fi |
76 | 79 | + if test "$coroutine" != "ucontext"; then | |
77 | === Testing version 3 === | 80 | + error_exit "SafeStack is only supported by the coroutine backend ucontext" |
78 | image: TEST_DIR/iotest-version3.IMGFMT | 81 | + fi |
82 | +else | ||
83 | +cat > $TMPC << EOF | ||
84 | +int main(int argc, char *argv[]) | ||
85 | +{ | ||
86 | +#if defined(__has_feature) | ||
87 | +#if __has_feature(safe_stack) | ||
88 | +#error SafeStack Enabled | ||
89 | +#endif | ||
90 | +#endif | ||
91 | + return 0; | ||
92 | +} | ||
93 | +EOF | ||
94 | +if test "$safe_stack" = "no"; then | ||
95 | + # Make sure that safe-stack is disabled | ||
96 | + if ! compile_prog "-Werror" ""; then | ||
97 | + # SafeStack was already enabled, try to explicitly remove the feature | ||
98 | + flag="-fno-sanitize=safe-stack" | ||
99 | + if ! compile_prog "-Werror $flag" "$flag"; then | ||
100 | + error_exit "Configure cannot disable SafeStack" | ||
101 | + fi | ||
102 | + QEMU_CFLAGS="$QEMU_CFLAGS $flag" | ||
103 | + QEMU_LDFLAGS="$QEMU_LDFLAGS $flag" | ||
104 | + fi | ||
105 | +else # "$safe_stack" = "" | ||
106 | + # Set safe_stack to yes or no based on pre-existing flags | ||
107 | + if compile_prog "-Werror" ""; then | ||
108 | + safe_stack="no" | ||
109 | + else | ||
110 | + safe_stack="yes" | ||
111 | + if test "$coroutine" != "ucontext"; then | ||
112 | + error_exit "SafeStack is only supported by the coroutine backend ucontext" | ||
113 | + fi | ||
114 | + fi | ||
115 | +fi | ||
116 | +fi | ||
117 | |||
118 | ########################################## | ||
119 | # check if we have open_by_handle_at | ||
120 | @@ -XXX,XX +XXX,XX @@ echo "sparse enabled $sparse" | ||
121 | echo "strip binaries $strip_opt" | ||
122 | echo "profiler $profiler" | ||
123 | echo "static build $static" | ||
124 | +echo "safe stack $safe_stack" | ||
125 | if test "$darwin" = "yes" ; then | ||
126 | echo "Cocoa support $cocoa" | ||
127 | fi | ||
128 | @@ -XXX,XX +XXX,XX @@ if test "$ccache_cpp2" = "yes"; then | ||
129 | echo "export CCACHE_CPP2=y" >> $config_host_mak | ||
130 | fi | ||
131 | |||
132 | +if test "$safe_stack" = "yes"; then | ||
133 | + echo "CONFIG_SAFESTACK=y" >> $config_host_mak | ||
134 | +fi | ||
135 | + | ||
136 | # If we're using a separate build tree, set it up now. | ||
137 | # DIRS are directories which we simply mkdir in the build tree; | ||
138 | # LINKS are things to symlink back into the source tree | ||
79 | -- | 139 | -- |
80 | 2.21.0 | 140 | 2.26.2 |
81 | 141 | ||
82 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Daniele Buono <dbuono@linux.vnet.ibm.com> |
---|---|---|---|
2 | 2 | ||
3 | The sanitizers (especially the address sanitizer from Clang) are | 3 | SafeStack is a stack protection technique implemented in llvm. It is |
4 | sometimes printing out warnings or false positives - this spoils | 4 | enabled with a -fsanitize flag. |
5 | the output of the iotests, causing some of the tests to fail. | 5 | iotests are currently disabled when any -fsanitize option is used, |
6 | Thus let's skip the automatic iotests during "make check" when the | 6 | because such options tend to produce additional warnings and false |
7 | user configured QEMU with --enable-sanitizers. | 7 | positives. |
8 | 8 | ||
9 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 9 | While common -fsanitize options are used to verify the code and not |
10 | Message-id: 20190823084203.29734-1-thuth@redhat.com | 10 | added in production, SafeStack's main use is in production environments |
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 11 | to protect against stack smashing. |
12 | |||
13 | Since SafeStack does not print any warning or false positive, enable | ||
14 | iotests when SafeStack is the only -fsanitize option used. | ||
15 | This is likely going to be a production binary and we want to make sure | ||
16 | it works correctly. | ||
17 | |||
18 | Signed-off-by: Daniele Buono <dbuono@linux.vnet.ibm.com> | ||
19 | Message-id: 20200529205122.714-5-dbuono@linux.vnet.ibm.com | ||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | 21 | --- |
13 | tests/check-block.sh | 5 +++++ | 22 | tests/check-block.sh | 12 +++++++++++- |
14 | 1 file changed, 5 insertions(+) | 23 | 1 file changed, 11 insertions(+), 1 deletion(-) |
15 | 24 | ||
16 | diff --git a/tests/check-block.sh b/tests/check-block.sh | 25 | diff --git a/tests/check-block.sh b/tests/check-block.sh |
17 | index XXXXXXX..XXXXXXX 100755 | 26 | index XXXXXXX..XXXXXXX 100755 |
18 | --- a/tests/check-block.sh | 27 | --- a/tests/check-block.sh |
19 | +++ b/tests/check-block.sh | 28 | +++ b/tests/check-block.sh |
20 | @@ -XXX,XX +XXX,XX @@ if grep -q "TARGET_GPROF=y" *-softmmu/config-target.mak 2>/dev/null ; then | 29 | @@ -XXX,XX +XXX,XX @@ if grep -q "CONFIG_GPROF=y" config-host.mak 2>/dev/null ; then |
21 | exit 0 | 30 | exit 0 |
22 | fi | 31 | fi |
23 | 32 | ||
24 | +if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then | 33 | -if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then |
25 | + echo "Sanitizers are enabled ==> Not running the qemu-iotests." | 34 | +# Disable tests with any sanitizer except for SafeStack |
26 | + exit 0 | 35 | +CFLAGS=$( grep "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ) |
27 | +fi | 36 | +SANITIZE_FLAGS="" |
28 | + | 37 | +#Remove all occurrencies of -fsanitize=safe-stack |
29 | if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then | 38 | +for i in ${CFLAGS}; do |
30 | echo "No qemu-system binary available ==> Not running the qemu-iotests." | 39 | + if [ "${i}" != "-fsanitize=safe-stack" ]; then |
40 | + SANITIZE_FLAGS="${SANITIZE_FLAGS} ${i}" | ||
41 | + fi | ||
42 | +done | ||
43 | +if echo ${SANITIZE_FLAGS} | grep -q "\-fsanitize" 2>/dev/null; then | ||
44 | + # Have a sanitize flag that is not allowed, stop | ||
45 | echo "Sanitizers are enabled ==> Not running the qemu-iotests." | ||
31 | exit 0 | 46 | exit 0 |
47 | fi | ||
32 | -- | 48 | -- |
33 | 2.21.0 | 49 | 2.26.2 |
34 | 50 | ||
35 | diff view generated by jsdifflib |
1 | Compressed writes generally have to write full clusters, not just in | 1 | A lot of CPU time is spent simply locking/unlocking q->lock during |
---|---|---|---|
2 | theory but also in practice when it comes to vmdk's streamOptimized | 2 | polling. Check for completion outside the lock to make q->lock disappear |
3 | subformat. It currently is just silently broken for writes with | 3 | from the profile. |
4 | non-zero in-cluster offsets: | ||
5 | 4 | ||
6 | $ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M | 5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | $ qemu-io -c 'write 4k 4k' -c 'read 4k 4k' foo.vmdk | 6 | Reviewed-by: Sergio Lopez <slp@redhat.com> |
8 | wrote 4096/4096 bytes at offset 4096 | 7 | Message-id: 20200617132201.1832152-2-stefanha@redhat.com |
9 | 4 KiB, 1 ops; 00.01 sec (443.724 KiB/sec and 110.9309 ops/sec) | 8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | read failed: Invalid argument | 9 | --- |
10 | block/nvme.c | 12 ++++++++++++ | ||
11 | 1 file changed, 12 insertions(+) | ||
11 | 12 | ||
12 | (The technical reason is that vmdk_write_extent() just writes the | 13 | diff --git a/block/nvme.c b/block/nvme.c |
13 | incomplete compressed data actually to offset 4k. When reading the | ||
14 | data, vmdk_read_extent() looks at offset 0 and finds the compressed data | ||
15 | size to be 0, because that is what it reads from there. This yields an | ||
16 | error.) | ||
17 | |||
18 | For incomplete writes with zero in-cluster offsets, the error path when | ||
19 | reading the rest of the cluster is a bit different, but the result is | ||
20 | the same: | ||
21 | |||
22 | $ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M | ||
23 | $ qemu-io -c 'write 0k 4k' -c 'read 4k 4k' foo.vmdk | ||
24 | wrote 4096/4096 bytes at offset 0 | ||
25 | 4 KiB, 1 ops; 00.01 sec (362.641 KiB/sec and 90.6603 ops/sec) | ||
26 | read failed: Invalid argument | ||
27 | |||
28 | (Here, vmdk_read_extent() finds the data and then sees that the | ||
29 | uncompressed data is short.) | ||
30 | |||
31 | It is better to reject invalid writes than to make the user believe they | ||
32 | might have succeeded and then fail when trying to read it back. | ||
33 | |||
34 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
35 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
36 | Message-id: 20190815153638.4600-5-mreitz@redhat.com | ||
37 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
38 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
39 | --- | ||
40 | block/vmdk.c | 10 ++++++++++ | ||
41 | 1 file changed, 10 insertions(+) | ||
42 | |||
43 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/block/vmdk.c | 15 | --- a/block/nvme.c |
46 | +++ b/block/vmdk.c | 16 | +++ b/block/nvme.c |
47 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, | 17 | @@ -XXX,XX +XXX,XX @@ static bool nvme_poll_queues(BDRVNVMeState *s) |
48 | if (extent->compressed) { | 18 | |
49 | void *compressed_data; | 19 | for (i = 0; i < s->nr_queues; i++) { |
50 | 20 | NVMeQueuePair *q = s->queues[i]; | |
51 | + /* Only whole clusters */ | 21 | + const size_t cqe_offset = q->cq.head * NVME_CQ_ENTRY_BYTES; |
52 | + if (offset_in_cluster || | 22 | + NvmeCqe *cqe = (NvmeCqe *)&q->cq.queue[cqe_offset]; |
53 | + n_bytes > (extent->cluster_sectors * SECTOR_SIZE) || | 23 | + |
54 | + (n_bytes < (extent->cluster_sectors * SECTOR_SIZE) && | 24 | + /* |
55 | + offset + n_bytes != extent->end_sector * SECTOR_SIZE)) | 25 | + * Do an early check for completions. q->lock isn't needed because |
56 | + { | 26 | + * nvme_process_completion() only runs in the event loop thread and |
57 | + ret = -EINVAL; | 27 | + * cannot race with itself. |
58 | + goto out; | 28 | + */ |
29 | + if ((le16_to_cpu(cqe->status) & 0x1) == q->cq_phase) { | ||
30 | + continue; | ||
59 | + } | 31 | + } |
60 | + | 32 | + |
61 | if (!extent->has_marker) { | 33 | qemu_mutex_lock(&q->lock); |
62 | ret = -EINVAL; | 34 | while (nvme_process_completion(s, q)) { |
63 | goto out; | 35 | /* Keep polling */ |
64 | -- | 36 | -- |
65 | 2.21.0 | 37 | 2.26.2 |
66 | 38 | ||
67 | diff view generated by jsdifflib |
1 | iotest 126 requires backing file support, which flat vmdks cannot offer. | 1 | nvme_process_completion() explicitly checks cid so the assertion that |
---|---|---|---|
2 | Skip this test for such subformats. | 2 | follows is always true: |
3 | 3 | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 4 | if (cid == 0 || cid > NVME_QUEUE_SIZE) { |
5 | Message-id: 20190815153638.4600-8-mreitz@redhat.com | 5 | ... |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 6 | continue; |
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 7 | } |
8 | assert(cid <= NVME_QUEUE_SIZE); | ||
9 | |||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
13 | Message-id: 20200617132201.1832152-3-stefanha@redhat.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | 15 | --- |
9 | tests/qemu-iotests/126 | 2 ++ | 16 | block/nvme.c | 1 - |
10 | 1 file changed, 2 insertions(+) | 17 | 1 file changed, 1 deletion(-) |
11 | 18 | ||
12 | diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126 | 19 | diff --git a/block/nvme.c b/block/nvme.c |
13 | index XXXXXXX..XXXXXXX 100755 | 20 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tests/qemu-iotests/126 | 21 | --- a/block/nvme.c |
15 | +++ b/tests/qemu-iotests/126 | 22 | +++ b/block/nvme.c |
16 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | 23 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) |
17 | 24 | cid); | |
18 | # Needs backing file support | 25 | continue; |
19 | _supported_fmt qcow qcow2 qed vmdk | 26 | } |
20 | +_unsupported_imgopts "subformat=monolithicFlat" \ | 27 | - assert(cid <= NVME_QUEUE_SIZE); |
21 | + "subformat=twoGbMaxExtentFlat" | 28 | trace_nvme_complete_command(s, q->index, cid); |
22 | # This is the default protocol (and we want to test the difference between | 29 | preq = &q->reqs[cid - 1]; |
23 | # colons which separate a protocol prefix from the rest and colons which are | 30 | req = *preq; |
24 | # just part of the filename, so we cannot test protocols which require a prefix) | ||
25 | -- | 31 | -- |
26 | 2.21.0 | 32 | 2.26.2 |
27 | 33 | ||
28 | diff view generated by jsdifflib |
1 | streamOptimized does not support writes that do not span exactly one | 1 | Do not access a CQE after incrementing q->cq.head and releasing q->lock. |
---|---|---|---|
2 | cluster. Furthermore, it cannot rewrite already allocated clusters. | 2 | It is unlikely that this causes problems in practice but it's a latent |
3 | As such, many iotests do not work with it. Disable them. | 3 | bug. |
4 | 4 | ||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 5 | The reason why it should be safe at the moment is that completion |
6 | Message-id: 20190815153638.4600-6-mreitz@redhat.com | 6 | processing is not re-entrant and the CQ doorbell isn't written until the |
7 | Reviewed-by: John Snow <jsnow@redhat.com> | 7 | end of nvme_process_completion(). |
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 8 | |
9 | Make this change now because QEMU expects completion processing to be | ||
10 | re-entrant and later patches will do that. | ||
11 | |||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
15 | Message-id: 20200617132201.1832152-4-stefanha@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 17 | --- |
10 | tests/qemu-iotests/002 | 1 + | 18 | block/nvme.c | 5 ++++- |
11 | tests/qemu-iotests/003 | 1 + | 19 | 1 file changed, 4 insertions(+), 1 deletion(-) |
12 | tests/qemu-iotests/005 | 3 ++- | ||
13 | tests/qemu-iotests/009 | 1 + | ||
14 | tests/qemu-iotests/010 | 1 + | ||
15 | tests/qemu-iotests/011 | 1 + | ||
16 | tests/qemu-iotests/017 | 3 ++- | ||
17 | tests/qemu-iotests/018 | 3 ++- | ||
18 | tests/qemu-iotests/019 | 3 ++- | ||
19 | tests/qemu-iotests/020 | 3 ++- | ||
20 | tests/qemu-iotests/027 | 1 + | ||
21 | tests/qemu-iotests/032 | 1 + | ||
22 | tests/qemu-iotests/033 | 1 + | ||
23 | tests/qemu-iotests/034 | 3 ++- | ||
24 | tests/qemu-iotests/037 | 3 ++- | ||
25 | tests/qemu-iotests/063 | 3 ++- | ||
26 | tests/qemu-iotests/072 | 1 + | ||
27 | tests/qemu-iotests/105 | 3 ++- | ||
28 | tests/qemu-iotests/197 | 1 + | ||
29 | tests/qemu-iotests/215 | 1 + | ||
30 | tests/qemu-iotests/251 | 1 + | ||
31 | 21 files changed, 30 insertions(+), 9 deletions(-) | ||
32 | 20 | ||
33 | diff --git a/tests/qemu-iotests/002 b/tests/qemu-iotests/002 | 21 | diff --git a/block/nvme.c b/block/nvme.c |
34 | index XXXXXXX..XXXXXXX 100755 | 22 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/tests/qemu-iotests/002 | 23 | --- a/block/nvme.c |
36 | +++ b/tests/qemu-iotests/002 | 24 | +++ b/block/nvme.c |
37 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 25 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) |
38 | 26 | q->busy = true; | |
39 | _supported_fmt generic | 27 | assert(q->inflight >= 0); |
40 | _supported_proto generic | 28 | while (q->inflight) { |
41 | +_unsupported_imgopts "subformat=streamOptimized" | 29 | + int ret; |
42 | 30 | int16_t cid; | |
43 | 31 | + | |
44 | size=128M | 32 | c = (NvmeCqe *)&q->cq.queue[q->cq.head * NVME_CQ_ENTRY_BYTES]; |
45 | diff --git a/tests/qemu-iotests/003 b/tests/qemu-iotests/003 | 33 | if ((le16_to_cpu(c->status) & 0x1) == q->cq_phase) { |
46 | index XXXXXXX..XXXXXXX 100755 | 34 | break; |
47 | --- a/tests/qemu-iotests/003 | 35 | } |
48 | +++ b/tests/qemu-iotests/003 | 36 | + ret = nvme_translate_error(c); |
49 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 37 | q->cq.head = (q->cq.head + 1) % NVME_QUEUE_SIZE; |
50 | 38 | if (!q->cq.head) { | |
51 | _supported_fmt generic | 39 | q->cq_phase = !q->cq_phase; |
52 | _supported_proto generic | 40 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) |
53 | +_unsupported_imgopts "subformat=streamOptimized" | 41 | preq->busy = false; |
54 | 42 | preq->cb = preq->opaque = NULL; | |
55 | size=128M | 43 | qemu_mutex_unlock(&q->lock); |
56 | offset=67M | 44 | - req.cb(req.opaque, nvme_translate_error(c)); |
57 | diff --git a/tests/qemu-iotests/005 b/tests/qemu-iotests/005 | 45 | + req.cb(req.opaque, ret); |
58 | index XXXXXXX..XXXXXXX 100755 | 46 | qemu_mutex_lock(&q->lock); |
59 | --- a/tests/qemu-iotests/005 | 47 | q->inflight--; |
60 | +++ b/tests/qemu-iotests/005 | 48 | progress = true; |
61 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
62 | _supported_proto generic | ||
63 | _supported_os Linux | ||
64 | _unsupported_imgopts "subformat=twoGbMaxExtentFlat" \ | ||
65 | - "subformat=twoGbMaxExtentSparse" | ||
66 | + "subformat=twoGbMaxExtentSparse" \ | ||
67 | + "subformat=streamOptimized" | ||
68 | |||
69 | # vpc is limited to 127GB, so we can't test it here | ||
70 | if [ "$IMGFMT" = "vpc" ]; then | ||
71 | diff --git a/tests/qemu-iotests/009 b/tests/qemu-iotests/009 | ||
72 | index XXXXXXX..XXXXXXX 100755 | ||
73 | --- a/tests/qemu-iotests/009 | ||
74 | +++ b/tests/qemu-iotests/009 | ||
75 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
76 | |||
77 | _supported_fmt generic | ||
78 | _supported_proto generic | ||
79 | +_unsupported_imgopts "subformat=streamOptimized" | ||
80 | |||
81 | |||
82 | size=6G | ||
83 | diff --git a/tests/qemu-iotests/010 b/tests/qemu-iotests/010 | ||
84 | index XXXXXXX..XXXXXXX 100755 | ||
85 | --- a/tests/qemu-iotests/010 | ||
86 | +++ b/tests/qemu-iotests/010 | ||
87 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
88 | |||
89 | _supported_fmt generic | ||
90 | _supported_proto generic | ||
91 | +_unsupported_imgopts "subformat=streamOptimized" | ||
92 | |||
93 | |||
94 | size=6G | ||
95 | diff --git a/tests/qemu-iotests/011 b/tests/qemu-iotests/011 | ||
96 | index XXXXXXX..XXXXXXX 100755 | ||
97 | --- a/tests/qemu-iotests/011 | ||
98 | +++ b/tests/qemu-iotests/011 | ||
99 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
100 | |||
101 | _supported_fmt generic | ||
102 | _supported_proto generic | ||
103 | +_unsupported_imgopts "subformat=streamOptimized" | ||
104 | |||
105 | |||
106 | size=6G | ||
107 | diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017 | ||
108 | index XXXXXXX..XXXXXXX 100755 | ||
109 | --- a/tests/qemu-iotests/017 | ||
110 | +++ b/tests/qemu-iotests/017 | ||
111 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
112 | _supported_fmt qcow qcow2 vmdk qed | ||
113 | _supported_proto generic | ||
114 | _unsupported_proto vxhs | ||
115 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
116 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
117 | + "subformat=streamOptimized" | ||
118 | |||
119 | TEST_OFFSETS="0 4294967296" | ||
120 | |||
121 | diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018 | ||
122 | index XXXXXXX..XXXXXXX 100755 | ||
123 | --- a/tests/qemu-iotests/018 | ||
124 | +++ b/tests/qemu-iotests/018 | ||
125 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
126 | _supported_fmt qcow qcow2 vmdk qed | ||
127 | _supported_proto file | ||
128 | _supported_os Linux | ||
129 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
130 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
131 | + "streamOptimized" | ||
132 | |||
133 | TEST_OFFSETS="0 4294967296" | ||
134 | |||
135 | diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019 | ||
136 | index XXXXXXX..XXXXXXX 100755 | ||
137 | --- a/tests/qemu-iotests/019 | ||
138 | +++ b/tests/qemu-iotests/019 | ||
139 | @@ -XXX,XX +XXX,XX @@ _supported_proto file | ||
140 | _supported_os Linux | ||
141 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
142 | "subformat=twoGbMaxExtentFlat" \ | ||
143 | - "subformat=twoGbMaxExtentSparse" | ||
144 | + "subformat=twoGbMaxExtentSparse" \ | ||
145 | + "subformat=streamOptimized" | ||
146 | |||
147 | TEST_OFFSETS="0 4294967296" | ||
148 | CLUSTER_SIZE=65536 | ||
149 | diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 | ||
150 | index XXXXXXX..XXXXXXX 100755 | ||
151 | --- a/tests/qemu-iotests/020 | ||
152 | +++ b/tests/qemu-iotests/020 | ||
153 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed | ||
154 | _supported_proto file | ||
155 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
156 | "subformat=twoGbMaxExtentFlat" \ | ||
157 | - "subformat=twoGbMaxExtentSparse" | ||
158 | + "subformat=twoGbMaxExtentSparse" \ | ||
159 | + "subformat=streamOptimized" | ||
160 | |||
161 | TEST_OFFSETS="0 4294967296" | ||
162 | |||
163 | diff --git a/tests/qemu-iotests/027 b/tests/qemu-iotests/027 | ||
164 | index XXXXXXX..XXXXXXX 100755 | ||
165 | --- a/tests/qemu-iotests/027 | ||
166 | +++ b/tests/qemu-iotests/027 | ||
167 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
168 | |||
169 | _supported_fmt vmdk qcow qcow2 qed | ||
170 | _supported_proto generic | ||
171 | +_unsupported_imgopts "subformat=streamOptimized" | ||
172 | |||
173 | |||
174 | size=128M | ||
175 | diff --git a/tests/qemu-iotests/032 b/tests/qemu-iotests/032 | ||
176 | index XXXXXXX..XXXXXXX 100755 | ||
177 | --- a/tests/qemu-iotests/032 | ||
178 | +++ b/tests/qemu-iotests/032 | ||
179 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
180 | # This works for any image format (though unlikely to segfault for raw) | ||
181 | _supported_fmt generic | ||
182 | _supported_proto generic | ||
183 | +_unsupported_imgopts "subformat=streamOptimized" | ||
184 | |||
185 | echo | ||
186 | echo === Prepare image === | ||
187 | diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 | ||
188 | index XXXXXXX..XXXXXXX 100755 | ||
189 | --- a/tests/qemu-iotests/033 | ||
190 | +++ b/tests/qemu-iotests/033 | ||
191 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
192 | |||
193 | _supported_fmt generic | ||
194 | _supported_proto generic | ||
195 | +_unsupported_imgopts "subformat=streamOptimized" | ||
196 | |||
197 | |||
198 | size=128M | ||
199 | diff --git a/tests/qemu-iotests/034 b/tests/qemu-iotests/034 | ||
200 | index XXXXXXX..XXXXXXX 100755 | ||
201 | --- a/tests/qemu-iotests/034 | ||
202 | +++ b/tests/qemu-iotests/034 | ||
203 | @@ -XXX,XX +XXX,XX @@ _supported_proto file | ||
204 | _supported_os Linux | ||
205 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
206 | "subformat=twoGbMaxExtentFlat" \ | ||
207 | - "subformat=twoGbMaxExtentSparse" | ||
208 | + "subformat=twoGbMaxExtentSparse" \ | ||
209 | + "subformat=streamOptimized" | ||
210 | |||
211 | CLUSTER_SIZE=4k | ||
212 | size=128M | ||
213 | diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037 | ||
214 | index XXXXXXX..XXXXXXX 100755 | ||
215 | --- a/tests/qemu-iotests/037 | ||
216 | +++ b/tests/qemu-iotests/037 | ||
217 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed | ||
218 | _supported_proto file | ||
219 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
220 | "subformat=twoGbMaxExtentFlat" \ | ||
221 | - "subformat=twoGbMaxExtentSparse" | ||
222 | + "subformat=twoGbMaxExtentSparse" \ | ||
223 | + "subformat=streamOptimized" | ||
224 | |||
225 | CLUSTER_SIZE=4k | ||
226 | size=128M | ||
227 | diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063 | ||
228 | index XXXXXXX..XXXXXXX 100755 | ||
229 | --- a/tests/qemu-iotests/063 | ||
230 | +++ b/tests/qemu-iotests/063 | ||
231 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed raw | ||
232 | _supported_proto file | ||
233 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
234 | "subformat=twoGbMaxExtentFlat" \ | ||
235 | - "subformat=twoGbMaxExtentSparse" | ||
236 | + "subformat=twoGbMaxExtentSparse" \ | ||
237 | + "subformat=streamOptimized" | ||
238 | |||
239 | _make_test_img 4M | ||
240 | |||
241 | diff --git a/tests/qemu-iotests/072 b/tests/qemu-iotests/072 | ||
242 | index XXXXXXX..XXXXXXX 100755 | ||
243 | --- a/tests/qemu-iotests/072 | ||
244 | +++ b/tests/qemu-iotests/072 | ||
245 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
246 | |||
247 | _supported_fmt vpc vmdk vhdx vdi qed qcow2 qcow | ||
248 | _supported_proto file | ||
249 | +_unsupported_imgopts "subformat=streamOptimized" | ||
250 | |||
251 | IMG_SIZE=64M | ||
252 | |||
253 | diff --git a/tests/qemu-iotests/105 b/tests/qemu-iotests/105 | ||
254 | index XXXXXXX..XXXXXXX 100755 | ||
255 | --- a/tests/qemu-iotests/105 | ||
256 | +++ b/tests/qemu-iotests/105 | ||
257 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
258 | _supported_fmt qcow2 vmdk vhdx qed | ||
259 | _supported_proto generic | ||
260 | _unsupported_imgopts "subformat=twoGbMaxExtentFlat" \ | ||
261 | - "subformat=twoGbMaxExtentSparse" | ||
262 | + "subformat=twoGbMaxExtentSparse" \ | ||
263 | + "subformat=streamOptimized" | ||
264 | |||
265 | echo | ||
266 | echo "creating large image" | ||
267 | diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 | ||
268 | index XXXXXXX..XXXXXXX 100755 | ||
269 | --- a/tests/qemu-iotests/197 | ||
270 | +++ b/tests/qemu-iotests/197 | ||
271 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
272 | _supported_proto generic | ||
273 | # LUKS support may be possible, but it complicates things. | ||
274 | _unsupported_fmt luks | ||
275 | +_unsupported_imgopts "subformat=streamOptimized" | ||
276 | |||
277 | echo | ||
278 | echo '=== Copy-on-read ===' | ||
279 | diff --git a/tests/qemu-iotests/215 b/tests/qemu-iotests/215 | ||
280 | index XXXXXXX..XXXXXXX 100755 | ||
281 | --- a/tests/qemu-iotests/215 | ||
282 | +++ b/tests/qemu-iotests/215 | ||
283 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
284 | _supported_proto generic | ||
285 | # LUKS support may be possible, but it complicates things. | ||
286 | _unsupported_fmt luks | ||
287 | +_unsupported_imgopts "subformat=streamOptimized" | ||
288 | |||
289 | echo | ||
290 | echo '=== Copy-on-read ===' | ||
291 | diff --git a/tests/qemu-iotests/251 b/tests/qemu-iotests/251 | ||
292 | index XXXXXXX..XXXXXXX 100755 | ||
293 | --- a/tests/qemu-iotests/251 | ||
294 | +++ b/tests/qemu-iotests/251 | ||
295 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
296 | _supported_fmt generic | ||
297 | _supported_proto file | ||
298 | _supported_os Linux | ||
299 | +_unsupported_imgopts "subformat=streamOptimized" | ||
300 | |||
301 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
302 | # We use json:{} filenames here, so we cannot work with additional options. | ||
303 | -- | 49 | -- |
304 | 2.21.0 | 50 | 2.26.2 |
305 | 51 | ||
306 | diff view generated by jsdifflib |
1 | From: Denis Plotnikov <dplotnikov@virtuozzo.com> | 1 | There are three issues with the current NVMeRequest->busy field: |
---|---|---|---|
2 | 1. The busy field is accidentally accessed outside q->lock when request | ||
3 | submission fails. | ||
4 | 2. Waiters on free_req_queue are not woken when a request is returned | ||
5 | early due to submission failure. | ||
6 | 2. Finding a free request involves scanning all requests. This makes | ||
7 | request submission O(n^2). | ||
2 | 8 | ||
3 | The patch allows to provide a pattern file for write | 9 | Switch to an O(1) freelist that is always accessed under the lock. |
4 | command. There was no similar ability before. | ||
5 | 10 | ||
6 | Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com> | 11 | Also differentiate between NVME_QUEUE_SIZE, the actual SQ/CQ size, and |
7 | Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com | 12 | NVME_NUM_REQS, the number of usable requests. This makes the code |
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | 13 | simpler than using NVME_QUEUE_SIZE everywhere and having to keep in mind |
9 | [mreitz: Keep optstring in alphabetical order] | 14 | that one slot is reserved. |
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 15 | |
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
18 | Message-id: 20200617132201.1832152-5-stefanha@redhat.com | ||
19 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | 20 | --- |
12 | qemu-io-cmds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++--- | 21 | block/nvme.c | 81 ++++++++++++++++++++++++++++++++++------------------ |
13 | 1 file changed, 93 insertions(+), 6 deletions(-) | 22 | 1 file changed, 54 insertions(+), 27 deletions(-) |
14 | 23 | ||
15 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c | 24 | diff --git a/block/nvme.c b/block/nvme.c |
16 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/qemu-io-cmds.c | 26 | --- a/block/nvme.c |
18 | +++ b/qemu-io-cmds.c | 27 | +++ b/block/nvme.c |
19 | @@ -XXX,XX +XXX,XX @@ static void qemu_io_free(void *p) | 28 | @@ -XXX,XX +XXX,XX @@ |
20 | qemu_vfree(p); | 29 | #define NVME_QUEUE_SIZE 128 |
30 | #define NVME_BAR_SIZE 8192 | ||
31 | |||
32 | +/* | ||
33 | + * We have to leave one slot empty as that is the full queue case where | ||
34 | + * head == tail + 1. | ||
35 | + */ | ||
36 | +#define NVME_NUM_REQS (NVME_QUEUE_SIZE - 1) | ||
37 | + | ||
38 | typedef struct { | ||
39 | int32_t head, tail; | ||
40 | uint8_t *queue; | ||
41 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
42 | int cid; | ||
43 | void *prp_list_page; | ||
44 | uint64_t prp_list_iova; | ||
45 | - bool busy; | ||
46 | + int free_req_next; /* q->reqs[] index of next free req */ | ||
47 | } NVMeRequest; | ||
48 | |||
49 | typedef struct { | ||
50 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
51 | /* Fields protected by @lock */ | ||
52 | NVMeQueue sq, cq; | ||
53 | int cq_phase; | ||
54 | - NVMeRequest reqs[NVME_QUEUE_SIZE]; | ||
55 | + int free_req_head; | ||
56 | + NVMeRequest reqs[NVME_NUM_REQS]; | ||
57 | bool busy; | ||
58 | int need_kick; | ||
59 | int inflight; | ||
60 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, | ||
61 | qemu_mutex_init(&q->lock); | ||
62 | q->index = idx; | ||
63 | qemu_co_queue_init(&q->free_req_queue); | ||
64 | - q->prp_list_pages = qemu_blockalign0(bs, s->page_size * NVME_QUEUE_SIZE); | ||
65 | + q->prp_list_pages = qemu_blockalign0(bs, s->page_size * NVME_NUM_REQS); | ||
66 | r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, | ||
67 | - s->page_size * NVME_QUEUE_SIZE, | ||
68 | + s->page_size * NVME_NUM_REQS, | ||
69 | false, &prp_list_iova); | ||
70 | if (r) { | ||
71 | goto fail; | ||
72 | } | ||
73 | - for (i = 0; i < NVME_QUEUE_SIZE; i++) { | ||
74 | + q->free_req_head = -1; | ||
75 | + for (i = 0; i < NVME_NUM_REQS; i++) { | ||
76 | NVMeRequest *req = &q->reqs[i]; | ||
77 | req->cid = i + 1; | ||
78 | + req->free_req_next = q->free_req_head; | ||
79 | + q->free_req_head = i; | ||
80 | req->prp_list_page = q->prp_list_pages + i * s->page_size; | ||
81 | req->prp_list_iova = prp_list_iova + i * s->page_size; | ||
82 | } | ||
83 | + | ||
84 | nvme_init_queue(bs, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err); | ||
85 | if (local_err) { | ||
86 | error_propagate(errp, local_err); | ||
87 | @@ -XXX,XX +XXX,XX @@ static void nvme_kick(BDRVNVMeState *s, NVMeQueuePair *q) | ||
88 | */ | ||
89 | static NVMeRequest *nvme_get_free_req(NVMeQueuePair *q) | ||
90 | { | ||
91 | - int i; | ||
92 | - NVMeRequest *req = NULL; | ||
93 | + NVMeRequest *req; | ||
94 | |||
95 | qemu_mutex_lock(&q->lock); | ||
96 | - while (q->inflight + q->need_kick > NVME_QUEUE_SIZE - 2) { | ||
97 | - /* We have to leave one slot empty as that is the full queue case (head | ||
98 | - * == tail + 1). */ | ||
99 | + | ||
100 | + while (q->free_req_head == -1) { | ||
101 | if (qemu_in_coroutine()) { | ||
102 | trace_nvme_free_req_queue_wait(q); | ||
103 | qemu_co_queue_wait(&q->free_req_queue, &q->lock); | ||
104 | @@ -XXX,XX +XXX,XX @@ static NVMeRequest *nvme_get_free_req(NVMeQueuePair *q) | ||
105 | return NULL; | ||
106 | } | ||
107 | } | ||
108 | - for (i = 0; i < NVME_QUEUE_SIZE; i++) { | ||
109 | - if (!q->reqs[i].busy) { | ||
110 | - q->reqs[i].busy = true; | ||
111 | - req = &q->reqs[i]; | ||
112 | - break; | ||
113 | - } | ||
114 | - } | ||
115 | - /* We have checked inflight and need_kick while holding q->lock, so one | ||
116 | - * free req must be available. */ | ||
117 | - assert(req); | ||
118 | + | ||
119 | + req = &q->reqs[q->free_req_head]; | ||
120 | + q->free_req_head = req->free_req_next; | ||
121 | + req->free_req_next = -1; | ||
122 | + | ||
123 | qemu_mutex_unlock(&q->lock); | ||
124 | return req; | ||
21 | } | 125 | } |
22 | 126 | ||
23 | +/* | 127 | +/* With q->lock */ |
24 | + * qemu_io_alloc_from_file() | 128 | +static void nvme_put_free_req_locked(NVMeQueuePair *q, NVMeRequest *req) |
25 | + * | ||
26 | + * Allocates the buffer and populates it with the content of the given file | ||
27 | + * up to @len bytes. If the file length is less than @len, then the buffer | ||
28 | + * is populated with the file content cyclically. | ||
29 | + * | ||
30 | + * @blk - the block backend where the buffer content is going to be written to | ||
31 | + * @len - the buffer length | ||
32 | + * @file_name - the file to read the content from | ||
33 | + * | ||
34 | + * Returns: the buffer pointer on success | ||
35 | + * NULL on error | ||
36 | + */ | ||
37 | +static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len, | ||
38 | + const char *file_name) | ||
39 | +{ | 129 | +{ |
40 | + char *buf, *buf_origin; | 130 | + req->free_req_next = q->free_req_head; |
41 | + FILE *f = fopen(file_name, "r"); | 131 | + q->free_req_head = req - q->reqs; |
42 | + int pattern_len; | ||
43 | + | ||
44 | + if (!f) { | ||
45 | + perror(file_name); | ||
46 | + return NULL; | ||
47 | + } | ||
48 | + | ||
49 | + if (qemuio_misalign) { | ||
50 | + len += MISALIGN_OFFSET; | ||
51 | + } | ||
52 | + | ||
53 | + buf_origin = buf = blk_blockalign(blk, len); | ||
54 | + | ||
55 | + if (qemuio_misalign) { | ||
56 | + buf_origin += MISALIGN_OFFSET; | ||
57 | + buf += MISALIGN_OFFSET; | ||
58 | + len -= MISALIGN_OFFSET; | ||
59 | + } | ||
60 | + | ||
61 | + pattern_len = fread(buf_origin, 1, len, f); | ||
62 | + | ||
63 | + if (ferror(f)) { | ||
64 | + perror(file_name); | ||
65 | + goto error; | ||
66 | + } | ||
67 | + | ||
68 | + if (pattern_len == 0) { | ||
69 | + fprintf(stderr, "%s: file is empty\n", file_name); | ||
70 | + goto error; | ||
71 | + } | ||
72 | + | ||
73 | + fclose(f); | ||
74 | + | ||
75 | + if (len > pattern_len) { | ||
76 | + len -= pattern_len; | ||
77 | + buf += pattern_len; | ||
78 | + | ||
79 | + while (len > 0) { | ||
80 | + size_t len_to_copy = MIN(pattern_len, len); | ||
81 | + | ||
82 | + memcpy(buf, buf_origin, len_to_copy); | ||
83 | + | ||
84 | + len -= len_to_copy; | ||
85 | + buf += len_to_copy; | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
89 | + return buf_origin; | ||
90 | + | ||
91 | +error: | ||
92 | + qemu_io_free(buf_origin); | ||
93 | + return NULL; | ||
94 | +} | 132 | +} |
95 | + | 133 | + |
96 | static void dump_buffer(const void *buffer, int64_t offset, int64_t len) | 134 | +/* With q->lock */ |
135 | +static void nvme_wake_free_req_locked(BDRVNVMeState *s, NVMeQueuePair *q) | ||
136 | +{ | ||
137 | + if (!qemu_co_queue_empty(&q->free_req_queue)) { | ||
138 | + replay_bh_schedule_oneshot_event(s->aio_context, | ||
139 | + nvme_free_req_queue_cb, q); | ||
140 | + } | ||
141 | +} | ||
142 | + | ||
143 | +/* Insert a request in the freelist and wake waiters */ | ||
144 | +static void nvme_put_free_req_and_wake(BDRVNVMeState *s, NVMeQueuePair *q, | ||
145 | + NVMeRequest *req) | ||
146 | +{ | ||
147 | + qemu_mutex_lock(&q->lock); | ||
148 | + nvme_put_free_req_locked(q, req); | ||
149 | + nvme_wake_free_req_locked(s, q); | ||
150 | + qemu_mutex_unlock(&q->lock); | ||
151 | +} | ||
152 | + | ||
153 | static inline int nvme_translate_error(const NvmeCqe *c) | ||
97 | { | 154 | { |
98 | uint64_t i; | 155 | uint16_t status = (le16_to_cpu(c->status) >> 1) & 0xFF; |
99 | @@ -XXX,XX +XXX,XX @@ static void write_help(void) | 156 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) |
100 | " -n, -- with -z, don't allow slow fallback\n" | 157 | req = *preq; |
101 | " -p, -- ignored for backwards compatibility\n" | 158 | assert(req.cid == cid); |
102 | " -P, -- use different pattern to fill file\n" | 159 | assert(req.cb); |
103 | +" -s, -- use a pattern file to fill the write buffer\n" | 160 | - preq->busy = false; |
104 | " -C, -- report statistics in a machine parsable format\n" | 161 | + nvme_put_free_req_locked(q, preq); |
105 | " -q, -- quiet mode, do not show I/O statistics\n" | 162 | preq->cb = preq->opaque = NULL; |
106 | " -u, -- with -z, allow unmapping\n" | 163 | qemu_mutex_unlock(&q->lock); |
107 | @@ -XXX,XX +XXX,XX @@ static const cmdinfo_t write_cmd = { | 164 | req.cb(req.opaque, ret); |
108 | .perm = BLK_PERM_WRITE, | 165 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) |
109 | .argmin = 2, | 166 | /* Notify the device so it can post more completions. */ |
110 | .argmax = -1, | 167 | smp_mb_release(); |
111 | - .args = "[-bcCfnquz] [-P pattern] off len", | 168 | *q->cq.doorbell = cpu_to_le32(q->cq.head); |
112 | + .args = "[-bcCfnquz] [-P pattern | -s source_file] off len", | 169 | - if (!qemu_co_queue_empty(&q->free_req_queue)) { |
113 | .oneline = "writes a number of bytes at a specified offset", | 170 | - replay_bh_schedule_oneshot_event(s->aio_context, |
114 | .help = write_help, | 171 | - nvme_free_req_queue_cb, q); |
115 | }; | 172 | - } |
116 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) | 173 | + nvme_wake_free_req_locked(s, q); |
117 | { | ||
118 | struct timespec t1, t2; | ||
119 | bool Cflag = false, qflag = false, bflag = false; | ||
120 | - bool Pflag = false, zflag = false, cflag = false; | ||
121 | + bool Pflag = false, zflag = false, cflag = false, sflag = false; | ||
122 | int flags = 0; | ||
123 | int c, cnt, ret; | ||
124 | char *buf = NULL; | ||
125 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) | ||
126 | /* Some compilers get confused and warn if this is not initialized. */ | ||
127 | int64_t total = 0; | ||
128 | int pattern = 0xcd; | ||
129 | + const char *file_name = NULL; | ||
130 | |||
131 | - while ((c = getopt(argc, argv, "bcCfnpP:quz")) != -1) { | ||
132 | + while ((c = getopt(argc, argv, "bcCfnpP:qs:uz")) != -1) { | ||
133 | switch (c) { | ||
134 | case 'b': | ||
135 | bflag = true; | ||
136 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) | ||
137 | case 'q': | ||
138 | qflag = true; | ||
139 | break; | ||
140 | + case 's': | ||
141 | + sflag = true; | ||
142 | + file_name = optarg; | ||
143 | + break; | ||
144 | case 'u': | ||
145 | flags |= BDRV_REQ_MAY_UNMAP; | ||
146 | break; | ||
147 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) | ||
148 | return -EINVAL; | ||
149 | } | 174 | } |
150 | 175 | q->busy = false; | |
151 | - if (zflag && Pflag) { | 176 | return progress; |
152 | - printf("-z and -P cannot be specified at the same time\n"); | 177 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, |
153 | + if (zflag + Pflag + sflag > 1) { | 178 | r = nvme_cmd_map_qiov(bs, &cmd, req, qiov); |
154 | + printf("Only one of -z, -P, and -s " | 179 | qemu_co_mutex_unlock(&s->dma_map_lock); |
155 | + "can be specified at the same time\n"); | 180 | if (r) { |
156 | return -EINVAL; | 181 | - req->busy = false; |
182 | + nvme_put_free_req_and_wake(s, ioq, req); | ||
183 | return r; | ||
157 | } | 184 | } |
158 | 185 | nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); | |
159 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) | 186 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, |
187 | qemu_co_mutex_unlock(&s->dma_map_lock); | ||
188 | |||
189 | if (ret) { | ||
190 | - req->busy = false; | ||
191 | + nvme_put_free_req_and_wake(s, ioq, req); | ||
192 | goto out; | ||
160 | } | 193 | } |
161 | 194 | ||
162 | if (!zflag) { | ||
163 | - buf = qemu_io_alloc(blk, count, pattern); | ||
164 | + if (sflag) { | ||
165 | + buf = qemu_io_alloc_from_file(blk, count, file_name); | ||
166 | + if (!buf) { | ||
167 | + return -EINVAL; | ||
168 | + } | ||
169 | + } else { | ||
170 | + buf = qemu_io_alloc(blk, count, pattern); | ||
171 | + } | ||
172 | } | ||
173 | |||
174 | clock_gettime(CLOCK_MONOTONIC, &t1); | ||
175 | -- | 195 | -- |
176 | 2.21.0 | 196 | 2.26.2 |
177 | 197 | ||
178 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | It's wrong to OR shared permissions. It may lead to crash on further | ||
4 | permission updates. | ||
5 | Also, no needs to consider previously calculated permissions, as at | ||
6 | this point we already bind all new parents and bdrv_get_cumulative_perm | ||
7 | result is enough. So fix the bug by just set permissions by | ||
8 | bdrv_get_cumulative_perm result. | ||
9 | |||
10 | Bug was introduced in long ago 234ac1a9025, in 2.9. | ||
11 | |||
12 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
13 | Message-id: 20190824100740.61635-1-vsementsov@virtuozzo.com | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | --- | ||
16 | block.c | 5 ++--- | ||
17 | 1 file changed, 2 insertions(+), 3 deletions(-) | ||
18 | |||
19 | diff --git a/block.c b/block.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block.c | ||
22 | +++ b/block.c | ||
23 | @@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
24 | { | ||
25 | BdrvChild *c, *next; | ||
26 | GSList *list = NULL, *p; | ||
27 | - uint64_t old_perm, old_shared; | ||
28 | uint64_t perm = 0, shared = BLK_PERM_ALL; | ||
29 | int ret; | ||
30 | |||
31 | @@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
32 | bdrv_unref(from); | ||
33 | } | ||
34 | |||
35 | - bdrv_get_cumulative_perm(to, &old_perm, &old_shared); | ||
36 | - bdrv_set_perm(to, old_perm | perm, old_shared | shared); | ||
37 | + bdrv_get_cumulative_perm(to, &perm, &shared); | ||
38 | + bdrv_set_perm(to, perm, shared); | ||
39 | |||
40 | out: | ||
41 | g_slist_free(list); | ||
42 | -- | ||
43 | 2.21.0 | ||
44 | |||
45 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Nir Soffer <nirsof@gmail.com> | ||
2 | 1 | ||
3 | When creating an image with preallocation "off" or "falloc", the first | ||
4 | block of the image is typically not allocated. When using Gluster | ||
5 | storage backed by XFS filesystem, reading this block using direct I/O | ||
6 | succeeds regardless of request length, fooling alignment detection. | ||
7 | |||
8 | In this case we fallback to a safe value (4096) instead of the optimal | ||
9 | value (512), which may lead to unneeded data copying when aligning | ||
10 | requests. Allocating the first block avoids the fallback. | ||
11 | |||
12 | Since we allocate the first block even with preallocation=off, we no | ||
13 | longer create images with zero disk size: | ||
14 | |||
15 | $ ./qemu-img create -f raw test.raw 1g | ||
16 | Formatting 'test.raw', fmt=raw size=1073741824 | ||
17 | |||
18 | $ ls -lhs test.raw | ||
19 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw | ||
20 | |||
21 | And converting the image requires additional cluster: | ||
22 | |||
23 | $ ./qemu-img measure -f raw -O qcow2 test.raw | ||
24 | required size: 458752 | ||
25 | fully allocated size: 1074135040 | ||
26 | |||
27 | When using format like vmdk with multiple files per image, we allocate | ||
28 | one block per file: | ||
29 | |||
30 | $ ./qemu-img create -f vmdk -o subformat=twoGbMaxExtentFlat test.vmdk 4g | ||
31 | Formatting 'test.vmdk', fmt=vmdk size=4294967296 compat6=off hwversion=undefined subformat=twoGbMaxExtentFlat | ||
32 | |||
33 | $ ls -lhs test*.vmdk | ||
34 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f001.vmdk | ||
35 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f002.vmdk | ||
36 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 353 Aug 27 03:23 test.vmdk | ||
37 | |||
38 | I did quick performance test for copying disks with qemu-img convert to | ||
39 | new raw target image to Gluster storage with sector size of 512 bytes: | ||
40 | |||
41 | for i in $(seq 10); do | ||
42 | rm -f dst.raw | ||
43 | sleep 10 | ||
44 | time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.raw | ||
45 | done | ||
46 | |||
47 | Here is a table comparing the total time spent: | ||
48 | |||
49 | Type Before(s) After(s) Diff(%) | ||
50 | --------------------------------------- | ||
51 | real 530.028 469.123 -11.4 | ||
52 | user 17.204 10.768 -37.4 | ||
53 | sys 17.881 7.011 -60.7 | ||
54 | |||
55 | We can see very clear improvement in CPU usage. | ||
56 | |||
57 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
58 | Message-id: 20190827010528.8818-2-nsoffer@redhat.com | ||
59 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
60 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
61 | --- | ||
62 | block/file-posix.c | 51 +++++++++++++++++++ | ||
63 | tests/qemu-iotests/059.out | 2 +- | ||
64 | tests/qemu-iotests/{150.out => 150.out.qcow2} | 0 | ||
65 | tests/qemu-iotests/150.out.raw | 12 +++++ | ||
66 | tests/qemu-iotests/175 | 19 ++++--- | ||
67 | tests/qemu-iotests/175.out | 8 +-- | ||
68 | tests/qemu-iotests/178.out.qcow2 | 4 +- | ||
69 | tests/qemu-iotests/221.out | 12 +++-- | ||
70 | tests/qemu-iotests/253.out | 12 +++-- | ||
71 | 9 files changed, 99 insertions(+), 21 deletions(-) | ||
72 | rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%) | ||
73 | create mode 100644 tests/qemu-iotests/150.out.raw | ||
74 | |||
75 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/block/file-posix.c | ||
78 | +++ b/block/file-posix.c | ||
79 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque) | ||
80 | return ret; | ||
81 | } | ||
82 | |||
83 | +/* | ||
84 | + * Help alignment probing by allocating the first block. | ||
85 | + * | ||
86 | + * When reading with direct I/O from unallocated area on Gluster backed by XFS, | ||
87 | + * reading succeeds regardless of request length. In this case we fallback to | ||
88 | + * safe alignment which is not optimal. Allocating the first block avoids this | ||
89 | + * fallback. | ||
90 | + * | ||
91 | + * fd may be opened with O_DIRECT, but we don't know the buffer alignment or | ||
92 | + * request alignment, so we use safe values. | ||
93 | + * | ||
94 | + * Returns: 0 on success, -errno on failure. Since this is an optimization, | ||
95 | + * caller may ignore failures. | ||
96 | + */ | ||
97 | +static int allocate_first_block(int fd, size_t max_size) | ||
98 | +{ | ||
99 | + size_t write_size = (max_size < MAX_BLOCKSIZE) | ||
100 | + ? BDRV_SECTOR_SIZE | ||
101 | + : MAX_BLOCKSIZE; | ||
102 | + size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize()); | ||
103 | + void *buf; | ||
104 | + ssize_t n; | ||
105 | + int ret; | ||
106 | + | ||
107 | + buf = qemu_memalign(max_align, write_size); | ||
108 | + memset(buf, 0, write_size); | ||
109 | + | ||
110 | + do { | ||
111 | + n = pwrite(fd, buf, write_size, 0); | ||
112 | + } while (n == -1 && errno == EINTR); | ||
113 | + | ||
114 | + ret = (n == -1) ? -errno : 0; | ||
115 | + | ||
116 | + qemu_vfree(buf); | ||
117 | + return ret; | ||
118 | +} | ||
119 | + | ||
120 | static int handle_aiocb_truncate(void *opaque) | ||
121 | { | ||
122 | RawPosixAIOData *aiocb = opaque; | ||
123 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque) | ||
124 | /* posix_fallocate() doesn't set errno. */ | ||
125 | error_setg_errno(errp, -result, | ||
126 | "Could not preallocate new data"); | ||
127 | + } else if (current_length == 0) { | ||
128 | + /* | ||
129 | + * posix_fallocate() uses fallocate() if the filesystem | ||
130 | + * supports it, or fallback to manually writing zeroes. If | ||
131 | + * fallocate() was used, unaligned reads from the fallocated | ||
132 | + * area in raw_probe_alignment() will succeed, hence we need to | ||
133 | + * allocate the first block. | ||
134 | + * | ||
135 | + * Optimize future alignment probing; ignore failures. | ||
136 | + */ | ||
137 | + allocate_first_block(fd, offset); | ||
138 | } | ||
139 | } else { | ||
140 | result = 0; | ||
141 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque) | ||
142 | if (ftruncate(fd, offset) != 0) { | ||
143 | result = -errno; | ||
144 | error_setg_errno(errp, -result, "Could not resize file"); | ||
145 | + } else if (current_length == 0 && offset > current_length) { | ||
146 | + /* Optimize future alignment probing; ignore failures. */ | ||
147 | + allocate_first_block(fd, offset); | ||
148 | } | ||
149 | return result; | ||
150 | default: | ||
151 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/tests/qemu-iotests/059.out | ||
154 | +++ b/tests/qemu-iotests/059.out | ||
155 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMax | ||
156 | image: TEST_DIR/t.vmdk | ||
157 | file format: vmdk | ||
158 | virtual size: 0.977 TiB (1073741824000 bytes) | ||
159 | -disk size: 16 KiB | ||
160 | +disk size: 1.97 MiB | ||
161 | Format specific information: | ||
162 | cid: XXXXXXXX | ||
163 | parent cid: XXXXXXXX | ||
164 | diff --git a/tests/qemu-iotests/150.out b/tests/qemu-iotests/150.out.qcow2 | ||
165 | similarity index 100% | ||
166 | rename from tests/qemu-iotests/150.out | ||
167 | rename to tests/qemu-iotests/150.out.qcow2 | ||
168 | diff --git a/tests/qemu-iotests/150.out.raw b/tests/qemu-iotests/150.out.raw | ||
169 | new file mode 100644 | ||
170 | index XXXXXXX..XXXXXXX | ||
171 | --- /dev/null | ||
172 | +++ b/tests/qemu-iotests/150.out.raw | ||
173 | @@ -XXX,XX +XXX,XX @@ | ||
174 | +QA output created by 150 | ||
175 | + | ||
176 | +=== Mapping sparse conversion === | ||
177 | + | ||
178 | +Offset Length File | ||
179 | +0 0x1000 TEST_DIR/t.IMGFMT | ||
180 | + | ||
181 | +=== Mapping non-sparse conversion === | ||
182 | + | ||
183 | +Offset Length File | ||
184 | +0 0x100000 TEST_DIR/t.IMGFMT | ||
185 | +*** done | ||
186 | diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 | ||
187 | index XXXXXXX..XXXXXXX 100755 | ||
188 | --- a/tests/qemu-iotests/175 | ||
189 | +++ b/tests/qemu-iotests/175 | ||
190 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
191 | # the file size. This function hides the resulting difference in the | ||
192 | # stat -c '%b' output. | ||
193 | # Parameter 1: Number of blocks an empty file occupies | ||
194 | -# Parameter 2: Image size in bytes | ||
195 | +# Parameter 2: Minimal number of blocks in an image | ||
196 | +# Parameter 3: Image size in bytes | ||
197 | _filter_blocks() | ||
198 | { | ||
199 | extra_blocks=$1 | ||
200 | - img_size=$2 | ||
201 | + min_blocks=$2 | ||
202 | + img_size=$3 | ||
203 | |||
204 | - sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \ | ||
205 | - -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/" | ||
206 | + sed -e "s/blocks=$min_blocks\\(\$\\|[^0-9]\\)/min allocation/" \ | ||
207 | + -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/" | ||
208 | } | ||
209 | |||
210 | # get standard environment, filters and checks | ||
211 | @@ -XXX,XX +XXX,XX @@ size=$((1 * 1024 * 1024)) | ||
212 | touch "$TEST_DIR/empty" | ||
213 | extra_blocks=$(stat -c '%b' "$TEST_DIR/empty") | ||
214 | |||
215 | +# We always write the first byte; check how many blocks this filesystem | ||
216 | +# allocates to match empty image alloation. | ||
217 | +printf "\0" > "$TEST_DIR/empty" | ||
218 | +min_blocks=$(stat -c '%b' "$TEST_DIR/empty") | ||
219 | + | ||
220 | echo | ||
221 | echo "== creating image with default preallocation ==" | ||
222 | _make_test_img $size | _filter_imgfmt | ||
223 | -stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size | ||
224 | +stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
225 | |||
226 | for mode in off full falloc; do | ||
227 | echo | ||
228 | echo "== creating image with preallocation $mode ==" | ||
229 | IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt | ||
230 | - stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size | ||
231 | + stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
232 | done | ||
233 | |||
234 | # success, all done | ||
235 | diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out | ||
236 | index XXXXXXX..XXXXXXX 100644 | ||
237 | --- a/tests/qemu-iotests/175.out | ||
238 | +++ b/tests/qemu-iotests/175.out | ||
239 | @@ -XXX,XX +XXX,XX @@ QA output created by 175 | ||
240 | |||
241 | == creating image with default preallocation == | ||
242 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 | ||
243 | -size=1048576, nothing allocated | ||
244 | +size=1048576, min allocation | ||
245 | |||
246 | == creating image with preallocation off == | ||
247 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off | ||
248 | -size=1048576, nothing allocated | ||
249 | +size=1048576, min allocation | ||
250 | |||
251 | == creating image with preallocation full == | ||
252 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full | ||
253 | -size=1048576, everything allocated | ||
254 | +size=1048576, max allocation | ||
255 | |||
256 | == creating image with preallocation falloc == | ||
257 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc | ||
258 | -size=1048576, everything allocated | ||
259 | +size=1048576, max allocation | ||
260 | *** done | ||
261 | diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2 | ||
262 | index XXXXXXX..XXXXXXX 100644 | ||
263 | --- a/tests/qemu-iotests/178.out.qcow2 | ||
264 | +++ b/tests/qemu-iotests/178.out.qcow2 | ||
265 | @@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608 | ||
266 | == raw input image with data (human) == | ||
267 | |||
268 | Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824 | ||
269 | -required size: 393216 | ||
270 | +required size: 458752 | ||
271 | fully allocated size: 1074135040 | ||
272 | wrote 512/512 bytes at offset 512 | ||
273 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
274 | @@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608 | ||
275 | |||
276 | Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824 | ||
277 | { | ||
278 | - "required": 393216, | ||
279 | + "required": 458752, | ||
280 | "fully-allocated": 1074135040 | ||
281 | } | ||
282 | wrote 512/512 bytes at offset 512 | ||
283 | diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out | ||
284 | index XXXXXXX..XXXXXXX 100644 | ||
285 | --- a/tests/qemu-iotests/221.out | ||
286 | +++ b/tests/qemu-iotests/221.out | ||
287 | @@ -XXX,XX +XXX,XX @@ QA output created by 221 | ||
288 | === Check mapping of unaligned raw image === | ||
289 | |||
290 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65537 | ||
291 | -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
292 | -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
293 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
294 | +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
295 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
296 | +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
297 | wrote 1/1 bytes at offset 65536 | ||
298 | 1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
299 | -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
300 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
301 | +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
302 | { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
303 | { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
304 | -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
305 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
306 | +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
307 | { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
308 | { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
309 | *** done | ||
310 | diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out | ||
311 | index XXXXXXX..XXXXXXX 100644 | ||
312 | --- a/tests/qemu-iotests/253.out | ||
313 | +++ b/tests/qemu-iotests/253.out | ||
314 | @@ -XXX,XX +XXX,XX @@ QA output created by 253 | ||
315 | === Check mapping of unaligned raw image === | ||
316 | |||
317 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575 | ||
318 | -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
319 | -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
320 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
321 | +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
322 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
323 | +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
324 | wrote 65535/65535 bytes at offset 983040 | ||
325 | 63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
326 | -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
327 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
328 | +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
329 | { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
330 | -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
331 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
332 | +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
333 | { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
334 | *** done | ||
335 | -- | ||
336 | 2.21.0 | ||
337 | |||
338 | diff view generated by jsdifflib |
1 | From: Stefan Hajnoczi <stefanha@redhat.com> | 1 | Existing users access free_req_queue under q->lock. Document this. |
---|---|---|---|
2 | 2 | ||
3 | Fixes: a6b257a08e3d72219f03e461a52152672fec0612 | ||
4 | ("file-posix: Handle undetectable alignment") | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | Message-id: 20190827101328.4062-1-stefanha@redhat.com | 4 | Reviewed-by: Sergio Lopez <slp@redhat.com> |
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | 5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 6 | Message-id: 20200617132201.1832152-6-stefanha@redhat.com |
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 8 | --- |
10 | block/file-posix.c | 2 +- | 9 | block/nvme.c | 2 +- |
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | 10 | 1 file changed, 1 insertion(+), 1 deletion(-) |
12 | 11 | ||
13 | diff --git a/block/file-posix.c b/block/file-posix.c | 12 | diff --git a/block/nvme.c b/block/nvme.c |
14 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/file-posix.c | 14 | --- a/block/nvme.c |
16 | +++ b/block/file-posix.c | 15 | +++ b/block/nvme.c |
17 | @@ -XXX,XX +XXX,XX @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) | 16 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
18 | for (i = 0; i < ARRAY_SIZE(alignments); i++) { | 17 | } NVMeRequest; |
19 | align = alignments[i]; | 18 | |
20 | if (raw_is_io_aligned(fd, buf + align, max_align)) { | 19 | typedef struct { |
21 | - /* Fallback to request_aligment. */ | 20 | - CoQueue free_req_queue; |
22 | + /* Fallback to request_alignment. */ | 21 | QemuMutex lock; |
23 | s->buf_align = (align != 1) ? align : bs->bl.request_alignment; | 22 | |
24 | break; | 23 | /* Fields protected by BQL */ |
25 | } | 24 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
25 | uint8_t *prp_list_pages; | ||
26 | |||
27 | /* Fields protected by @lock */ | ||
28 | + CoQueue free_req_queue; | ||
29 | NVMeQueue sq, cq; | ||
30 | int cq_phase; | ||
31 | int free_req_head; | ||
26 | -- | 32 | -- |
27 | 2.21.0 | 33 | 2.26.2 |
28 | 34 | ||
29 | diff view generated by jsdifflib |
1 | This makes iotest 033 pass with e.g. subformat=monolithicFlat. It also | 1 | Passing around both BDRVNVMeState and NVMeQueuePair is unwieldy. Reduce |
---|---|---|---|
2 | turns a former error in 059 into success. | 2 | the number of function arguments by keeping the BDRVNVMeState pointer in |
3 | NVMeQueuePair. This will come in handly when a BH is introduced in a | ||
4 | later patch and only one argument can be passed to it. | ||
3 | 5 | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
5 | Message-id: 20190815153638.4600-3-mreitz@redhat.com | 7 | Reviewed-by: Sergio Lopez <slp@redhat.com> |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 9 | Message-id: 20200617132201.1832152-7-stefanha@redhat.com |
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | 11 | --- |
9 | block/vmdk.c | 54 ++++++++++++++++++++++++-------------- | 12 | block/nvme.c | 70 ++++++++++++++++++++++++++++------------------------ |
10 | tests/qemu-iotests/059 | 7 +++-- | 13 | 1 file changed, 38 insertions(+), 32 deletions(-) |
11 | tests/qemu-iotests/059.out | 4 ++- | ||
12 | 3 files changed, 42 insertions(+), 23 deletions(-) | ||
13 | 14 | ||
14 | diff --git a/block/vmdk.c b/block/vmdk.c | 15 | diff --git a/block/nvme.c b/block/nvme.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block/vmdk.c | 17 | --- a/block/nvme.c |
17 | +++ b/block/vmdk.c | 18 | +++ b/block/nvme.c |
18 | @@ -XXX,XX +XXX,XX @@ static const char *next_line(const char *s) | 19 | @@ -XXX,XX +XXX,XX @@ |
19 | } | 20 | */ |
20 | 21 | #define NVME_NUM_REQS (NVME_QUEUE_SIZE - 1) | |
21 | static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 22 | |
22 | - const char *desc_file_path, QDict *options, | 23 | +typedef struct BDRVNVMeState BDRVNVMeState; |
23 | - Error **errp) | 24 | + |
24 | + QDict *options, Error **errp) | 25 | typedef struct { |
25 | { | 26 | int32_t head, tail; |
26 | int ret; | 27 | uint8_t *queue; |
27 | int matches; | 28 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
28 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 29 | typedef struct { |
29 | const char *p, *np; | 30 | QemuMutex lock; |
30 | int64_t sectors = 0; | 31 | |
31 | int64_t flat_offset; | 32 | + /* Read from I/O code path, initialized under BQL */ |
32 | + char *desc_file_dir = NULL; | 33 | + BDRVNVMeState *s; |
33 | char *extent_path; | 34 | + int index; |
34 | BdrvChild *extent_file; | 35 | + |
35 | BDRVVmdkState *s = bs->opaque; | 36 | /* Fields protected by BQL */ |
36 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 37 | - int index; |
37 | continue; | 38 | uint8_t *prp_list_pages; |
39 | |||
40 | /* Fields protected by @lock */ | ||
41 | @@ -XXX,XX +XXX,XX @@ typedef volatile struct { | ||
42 | |||
43 | QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) != 0x1000); | ||
44 | |||
45 | -typedef struct { | ||
46 | +struct BDRVNVMeState { | ||
47 | AioContext *aio_context; | ||
48 | QEMUVFIOState *vfio; | ||
49 | NVMeRegs *regs; | ||
50 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
51 | |||
52 | /* PCI address (required for nvme_refresh_filename()) */ | ||
53 | char *device; | ||
54 | -} BDRVNVMeState; | ||
55 | +}; | ||
56 | |||
57 | #define NVME_BLOCK_OPT_DEVICE "device" | ||
58 | #define NVME_BLOCK_OPT_NAMESPACE "namespace" | ||
59 | @@ -XXX,XX +XXX,XX @@ static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q, | ||
60 | } | ||
61 | } | ||
62 | |||
63 | -static void nvme_free_queue_pair(BlockDriverState *bs, NVMeQueuePair *q) | ||
64 | +static void nvme_free_queue_pair(NVMeQueuePair *q) | ||
65 | { | ||
66 | qemu_vfree(q->prp_list_pages); | ||
67 | qemu_vfree(q->sq.queue); | ||
68 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, | ||
69 | uint64_t prp_list_iova; | ||
70 | |||
71 | qemu_mutex_init(&q->lock); | ||
72 | + q->s = s; | ||
73 | q->index = idx; | ||
74 | qemu_co_queue_init(&q->free_req_queue); | ||
75 | q->prp_list_pages = qemu_blockalign0(bs, s->page_size * NVME_NUM_REQS); | ||
76 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, | ||
77 | |||
78 | return q; | ||
79 | fail: | ||
80 | - nvme_free_queue_pair(bs, q); | ||
81 | + nvme_free_queue_pair(q); | ||
82 | return NULL; | ||
83 | } | ||
84 | |||
85 | /* With q->lock */ | ||
86 | -static void nvme_kick(BDRVNVMeState *s, NVMeQueuePair *q) | ||
87 | +static void nvme_kick(NVMeQueuePair *q) | ||
88 | { | ||
89 | + BDRVNVMeState *s = q->s; | ||
90 | + | ||
91 | if (s->plugged || !q->need_kick) { | ||
92 | return; | ||
93 | } | ||
94 | @@ -XXX,XX +XXX,XX @@ static void nvme_put_free_req_locked(NVMeQueuePair *q, NVMeRequest *req) | ||
95 | } | ||
96 | |||
97 | /* With q->lock */ | ||
98 | -static void nvme_wake_free_req_locked(BDRVNVMeState *s, NVMeQueuePair *q) | ||
99 | +static void nvme_wake_free_req_locked(NVMeQueuePair *q) | ||
100 | { | ||
101 | if (!qemu_co_queue_empty(&q->free_req_queue)) { | ||
102 | - replay_bh_schedule_oneshot_event(s->aio_context, | ||
103 | + replay_bh_schedule_oneshot_event(q->s->aio_context, | ||
104 | nvme_free_req_queue_cb, q); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | /* Insert a request in the freelist and wake waiters */ | ||
109 | -static void nvme_put_free_req_and_wake(BDRVNVMeState *s, NVMeQueuePair *q, | ||
110 | - NVMeRequest *req) | ||
111 | +static void nvme_put_free_req_and_wake(NVMeQueuePair *q, NVMeRequest *req) | ||
112 | { | ||
113 | qemu_mutex_lock(&q->lock); | ||
114 | nvme_put_free_req_locked(q, req); | ||
115 | - nvme_wake_free_req_locked(s, q); | ||
116 | + nvme_wake_free_req_locked(q); | ||
117 | qemu_mutex_unlock(&q->lock); | ||
118 | } | ||
119 | |||
120 | @@ -XXX,XX +XXX,XX @@ static inline int nvme_translate_error(const NvmeCqe *c) | ||
121 | } | ||
122 | |||
123 | /* With q->lock */ | ||
124 | -static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) | ||
125 | +static bool nvme_process_completion(NVMeQueuePair *q) | ||
126 | { | ||
127 | + BDRVNVMeState *s = q->s; | ||
128 | bool progress = false; | ||
129 | NVMeRequest *preq; | ||
130 | NVMeRequest req; | ||
131 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q) | ||
132 | /* Notify the device so it can post more completions. */ | ||
133 | smp_mb_release(); | ||
134 | *q->cq.doorbell = cpu_to_le32(q->cq.head); | ||
135 | - nvme_wake_free_req_locked(s, q); | ||
136 | + nvme_wake_free_req_locked(q); | ||
137 | } | ||
138 | q->busy = false; | ||
139 | return progress; | ||
140 | @@ -XXX,XX +XXX,XX @@ static void nvme_trace_command(const NvmeCmd *cmd) | ||
141 | } | ||
142 | } | ||
143 | |||
144 | -static void nvme_submit_command(BDRVNVMeState *s, NVMeQueuePair *q, | ||
145 | - NVMeRequest *req, | ||
146 | +static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req, | ||
147 | NvmeCmd *cmd, BlockCompletionFunc cb, | ||
148 | void *opaque) | ||
149 | { | ||
150 | @@ -XXX,XX +XXX,XX @@ static void nvme_submit_command(BDRVNVMeState *s, NVMeQueuePair *q, | ||
151 | req->opaque = opaque; | ||
152 | cmd->cid = cpu_to_le32(req->cid); | ||
153 | |||
154 | - trace_nvme_submit_command(s, q->index, req->cid); | ||
155 | + trace_nvme_submit_command(q->s, q->index, req->cid); | ||
156 | nvme_trace_command(cmd); | ||
157 | qemu_mutex_lock(&q->lock); | ||
158 | memcpy((uint8_t *)q->sq.queue + | ||
159 | q->sq.tail * NVME_SQ_ENTRY_BYTES, cmd, sizeof(*cmd)); | ||
160 | q->sq.tail = (q->sq.tail + 1) % NVME_QUEUE_SIZE; | ||
161 | q->need_kick++; | ||
162 | - nvme_kick(s, q); | ||
163 | - nvme_process_completion(s, q); | ||
164 | + nvme_kick(q); | ||
165 | + nvme_process_completion(q); | ||
166 | qemu_mutex_unlock(&q->lock); | ||
167 | } | ||
168 | |||
169 | @@ -XXX,XX +XXX,XX @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, | ||
170 | NvmeCmd *cmd) | ||
171 | { | ||
172 | NVMeRequest *req; | ||
173 | - BDRVNVMeState *s = bs->opaque; | ||
174 | int ret = -EINPROGRESS; | ||
175 | req = nvme_get_free_req(q); | ||
176 | if (!req) { | ||
177 | return -EBUSY; | ||
178 | } | ||
179 | - nvme_submit_command(s, q, req, cmd, nvme_cmd_sync_cb, &ret); | ||
180 | + nvme_submit_command(q, req, cmd, nvme_cmd_sync_cb, &ret); | ||
181 | |||
182 | BDRV_POLL_WHILE(bs, ret == -EINPROGRESS); | ||
183 | return ret; | ||
184 | @@ -XXX,XX +XXX,XX @@ static bool nvme_poll_queues(BDRVNVMeState *s) | ||
38 | } | 185 | } |
39 | 186 | ||
40 | - if (!path_is_absolute(fname) && !path_has_protocol(fname) && | 187 | qemu_mutex_lock(&q->lock); |
41 | - !desc_file_path[0]) | 188 | - while (nvme_process_completion(s, q)) { |
42 | - { | 189 | + while (nvme_process_completion(q)) { |
43 | - bdrv_refresh_filename(bs->file->bs); | 190 | /* Keep polling */ |
44 | - error_setg(errp, "Cannot use relative extent paths with VMDK " | 191 | progress = true; |
45 | - "descriptor file '%s'", bs->file->bs->filename); | ||
46 | - return -EINVAL; | ||
47 | - } | ||
48 | + if (path_is_absolute(fname)) { | ||
49 | + extent_path = g_strdup(fname); | ||
50 | + } else { | ||
51 | + if (!desc_file_dir) { | ||
52 | + desc_file_dir = bdrv_dirname(bs->file->bs, errp); | ||
53 | + if (!desc_file_dir) { | ||
54 | + bdrv_refresh_filename(bs->file->bs); | ||
55 | + error_prepend(errp, "Cannot use relative paths with VMDK " | ||
56 | + "descriptor file '%s': ", | ||
57 | + bs->file->bs->filename); | ||
58 | + ret = -EINVAL; | ||
59 | + goto out; | ||
60 | + } | ||
61 | + } | ||
62 | |||
63 | - extent_path = path_combine(desc_file_path, fname); | ||
64 | + extent_path = g_strconcat(desc_file_dir, fname, NULL); | ||
65 | + } | ||
66 | |||
67 | ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents); | ||
68 | assert(ret < 32); | ||
69 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
70 | g_free(extent_path); | ||
71 | if (local_err) { | ||
72 | error_propagate(errp, local_err); | ||
73 | - return -EINVAL; | ||
74 | + ret = -EINVAL; | ||
75 | + goto out; | ||
76 | } | 192 | } |
77 | 193 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) | |
78 | /* save to extents array */ | 194 | }; |
79 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 195 | if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { |
80 | 0, 0, 0, 0, 0, &extent, errp); | 196 | error_setg(errp, "Failed to create io queue [%d]", n); |
81 | if (ret < 0) { | 197 | - nvme_free_queue_pair(bs, q); |
82 | bdrv_unref_child(bs, extent_file); | 198 | + nvme_free_queue_pair(q); |
83 | - return ret; | 199 | return false; |
84 | + goto out; | 200 | } |
85 | } | 201 | cmd = (NvmeCmd) { |
86 | extent->flat_start_offset = flat_offset << 9; | 202 | @@ -XXX,XX +XXX,XX @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) |
87 | } else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) { | 203 | }; |
88 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 204 | if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { |
89 | g_free(buf); | 205 | error_setg(errp, "Failed to create io queue [%d]", n); |
90 | if (ret) { | 206 | - nvme_free_queue_pair(bs, q); |
91 | bdrv_unref_child(bs, extent_file); | 207 | + nvme_free_queue_pair(q); |
92 | - return ret; | 208 | return false; |
93 | + goto out; | 209 | } |
94 | } | 210 | s->queues = g_renew(NVMeQueuePair *, s->queues, n + 1); |
95 | extent = &s->extents[s->num_extents - 1]; | 211 | @@ -XXX,XX +XXX,XX @@ static void nvme_close(BlockDriverState *bs) |
96 | } else if (!strcmp(type, "SESPARSE")) { | 212 | BDRVNVMeState *s = bs->opaque; |
97 | ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp); | 213 | |
98 | if (ret) { | 214 | for (i = 0; i < s->nr_queues; ++i) { |
99 | bdrv_unref_child(bs, extent_file); | 215 | - nvme_free_queue_pair(bs, s->queues[i]); |
100 | - return ret; | 216 | + nvme_free_queue_pair(s->queues[i]); |
101 | + goto out; | 217 | } |
102 | } | 218 | g_free(s->queues); |
103 | extent = &s->extents[s->num_extents - 1]; | 219 | aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, |
104 | } else { | 220 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, |
105 | error_setg(errp, "Unsupported extent type '%s'", type); | 221 | r = nvme_cmd_map_qiov(bs, &cmd, req, qiov); |
106 | bdrv_unref_child(bs, extent_file); | 222 | qemu_co_mutex_unlock(&s->dma_map_lock); |
107 | - return -ENOTSUP; | 223 | if (r) { |
108 | + ret = -ENOTSUP; | 224 | - nvme_put_free_req_and_wake(s, ioq, req); |
109 | + goto out; | 225 | + nvme_put_free_req_and_wake(ioq, req); |
110 | } | 226 | return r; |
111 | extent->type = g_strdup(type); | 227 | } |
112 | } | 228 | - nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); |
113 | - return 0; | 229 | + nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); |
114 | + | 230 | |
115 | + ret = 0; | 231 | data.co = qemu_coroutine_self(); |
116 | + goto out; | 232 | while (data.ret == -EINPROGRESS) { |
117 | 233 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_flush(BlockDriverState *bs) | |
118 | invalid: | 234 | assert(s->nr_queues > 1); |
119 | np = next_line(p); | 235 | req = nvme_get_free_req(ioq); |
120 | @@ -XXX,XX +XXX,XX @@ invalid: | 236 | assert(req); |
121 | np--; | 237 | - nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); |
122 | } | 238 | + nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); |
123 | error_setg(errp, "Invalid extent line: %.*s", (int)(np - p), p); | 239 | |
124 | - return -EINVAL; | 240 | data.co = qemu_coroutine_self(); |
125 | + ret = -EINVAL; | 241 | if (data.ret == -EINPROGRESS) { |
126 | + | 242 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs, |
127 | +out: | 243 | req = nvme_get_free_req(ioq); |
128 | + g_free(desc_file_dir); | 244 | assert(req); |
129 | + return ret; | 245 | |
130 | } | 246 | - nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); |
131 | 247 | + nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); | |
132 | static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | 248 | |
133 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | 249 | data.co = qemu_coroutine_self(); |
134 | } | 250 | while (data.ret == -EINPROGRESS) { |
135 | s->create_type = g_strdup(ct); | 251 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, |
136 | s->desc_offset = 0; | 252 | qemu_co_mutex_unlock(&s->dma_map_lock); |
137 | - ret = vmdk_parse_extents(buf, bs, bs->file->bs->exact_filename, options, | 253 | |
138 | - errp); | 254 | if (ret) { |
139 | + ret = vmdk_parse_extents(buf, bs, options, errp); | 255 | - nvme_put_free_req_and_wake(s, ioq, req); |
140 | exit: | 256 | + nvme_put_free_req_and_wake(ioq, req); |
141 | return ret; | 257 | goto out; |
142 | } | 258 | } |
143 | diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 | 259 | |
144 | index XXXXXXX..XXXXXXX 100755 | 260 | trace_nvme_dsm(s, offset, bytes); |
145 | --- a/tests/qemu-iotests/059 | 261 | |
146 | +++ b/tests/qemu-iotests/059 | 262 | - nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); |
147 | @@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2 | 263 | + nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); |
148 | 264 | ||
149 | echo | 265 | data.co = qemu_coroutine_self(); |
150 | echo "=== Testing monolithicFlat with internally generated JSON file name ===" | 266 | while (data.ret == -EINPROGRESS) { |
151 | +# Should work, because bdrv_dirname() works fine with blkdebug | 267 | @@ -XXX,XX +XXX,XX @@ static void nvme_aio_unplug(BlockDriverState *bs) |
152 | IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | 268 | for (i = 1; i < s->nr_queues; i++) { |
153 | -$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" 2>&1 \ | 269 | NVMeQueuePair *q = s->queues[i]; |
154 | - | _filter_testdir | _filter_imgfmt | 270 | qemu_mutex_lock(&q->lock); |
155 | +$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \ | 271 | - nvme_kick(s, q); |
156 | + -c info \ | 272 | - nvme_process_completion(s, q); |
157 | + 2>&1 \ | 273 | + nvme_kick(q); |
158 | + | _filter_testdir | _filter_imgfmt | _filter_img_info | 274 | + nvme_process_completion(q); |
159 | _cleanup_test_img | 275 | qemu_mutex_unlock(&q->lock); |
160 | 276 | } | |
161 | echo | 277 | } |
162 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/tests/qemu-iotests/059.out | ||
165 | +++ b/tests/qemu-iotests/059.out | ||
166 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | ||
167 | |||
168 | === Testing monolithicFlat with internally generated JSON file name === | ||
169 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
170 | -qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}' | ||
171 | +format name: IMGFMT | ||
172 | +cluster size: 0 bytes | ||
173 | +vm state offset: 0 bytes | ||
174 | |||
175 | === Testing version 3 === | ||
176 | image: TEST_DIR/iotest-version3.IMGFMT | ||
177 | -- | 278 | -- |
178 | 2.21.0 | 279 | 2.26.2 |
179 | 280 | ||
180 | diff view generated by jsdifflib |
1 | From: Nir Soffer <nirsof@gmail.com> | 1 | QEMU block drivers are supposed to support aio_poll() from I/O |
---|---|---|---|
2 | completion callback functions. This means completion processing must be | ||
3 | re-entrant. | ||
2 | 4 | ||
3 | Using block_resize we can test allocate_first_block() with file | 5 | The standard approach is to schedule a BH during completion processing |
4 | descriptor opened with O_DIRECT, ensuring that it works for any size | 6 | and cancel it at the end of processing. If aio_poll() is invoked by a |
5 | larger than 4096 bytes. | 7 | callback function then the BH will run. The BH continues the suspended |
8 | completion processing. | ||
6 | 9 | ||
7 | Testing smaller sizes is tricky as the result depends on the filesystem | 10 | All of this means that request A's cb() can synchronously wait for |
8 | used for testing. For example on NFS any size will work since O_DIRECT | 11 | request B to complete. Previously the nvme block driver would hang |
9 | does not require any alignment. | 12 | because it didn't process completions from nested aio_poll(). |
10 | 13 | ||
11 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 15 | Reviewed-by: Sergio Lopez <slp@redhat.com> |
13 | Message-id: 20190827010528.8818-3-nsoffer@redhat.com | 16 | Message-id: 20200617132201.1832152-8-stefanha@redhat.com |
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
15 | --- | 18 | --- |
16 | tests/qemu-iotests/175 | 28 ++++++++++++++++++++++++++++ | 19 | block/nvme.c | 67 ++++++++++++++++++++++++++++++++++++++++------ |
17 | tests/qemu-iotests/175.out | 8 ++++++++ | 20 | block/trace-events | 2 +- |
18 | 2 files changed, 36 insertions(+) | 21 | 2 files changed, 60 insertions(+), 9 deletions(-) |
19 | 22 | ||
20 | diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 | 23 | diff --git a/block/nvme.c b/block/nvme.c |
21 | index XXXXXXX..XXXXXXX 100755 | 24 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/tests/qemu-iotests/175 | 25 | --- a/block/nvme.c |
23 | +++ b/tests/qemu-iotests/175 | 26 | +++ b/block/nvme.c |
24 | @@ -XXX,XX +XXX,XX @@ _filter_blocks() | 27 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
25 | -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/" | 28 | int cq_phase; |
29 | int free_req_head; | ||
30 | NVMeRequest reqs[NVME_NUM_REQS]; | ||
31 | - bool busy; | ||
32 | int need_kick; | ||
33 | int inflight; | ||
34 | + | ||
35 | + /* Thread-safe, no lock necessary */ | ||
36 | + QEMUBH *completion_bh; | ||
37 | } NVMeQueuePair; | ||
38 | |||
39 | /* Memory mapped registers */ | ||
40 | @@ -XXX,XX +XXX,XX @@ struct BDRVNVMeState { | ||
41 | #define NVME_BLOCK_OPT_DEVICE "device" | ||
42 | #define NVME_BLOCK_OPT_NAMESPACE "namespace" | ||
43 | |||
44 | +static void nvme_process_completion_bh(void *opaque); | ||
45 | + | ||
46 | static QemuOptsList runtime_opts = { | ||
47 | .name = "nvme", | ||
48 | .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), | ||
49 | @@ -XXX,XX +XXX,XX @@ static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q, | ||
50 | |||
51 | static void nvme_free_queue_pair(NVMeQueuePair *q) | ||
52 | { | ||
53 | + if (q->completion_bh) { | ||
54 | + qemu_bh_delete(q->completion_bh); | ||
55 | + } | ||
56 | qemu_vfree(q->prp_list_pages); | ||
57 | qemu_vfree(q->sq.queue); | ||
58 | qemu_vfree(q->cq.queue); | ||
59 | @@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, | ||
60 | q->index = idx; | ||
61 | qemu_co_queue_init(&q->free_req_queue); | ||
62 | q->prp_list_pages = qemu_blockalign0(bs, s->page_size * NVME_NUM_REQS); | ||
63 | + q->completion_bh = aio_bh_new(bdrv_get_aio_context(bs), | ||
64 | + nvme_process_completion_bh, q); | ||
65 | r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, | ||
66 | s->page_size * NVME_NUM_REQS, | ||
67 | false, &prp_list_iova); | ||
68 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) | ||
69 | NvmeCqe *c; | ||
70 | |||
71 | trace_nvme_process_completion(s, q->index, q->inflight); | ||
72 | - if (q->busy || s->plugged) { | ||
73 | - trace_nvme_process_completion_queue_busy(s, q->index); | ||
74 | + if (s->plugged) { | ||
75 | + trace_nvme_process_completion_queue_plugged(s, q->index); | ||
76 | return false; | ||
77 | } | ||
78 | - q->busy = true; | ||
79 | + | ||
80 | + /* | ||
81 | + * Support re-entrancy when a request cb() function invokes aio_poll(). | ||
82 | + * Pending completions must be visible to aio_poll() so that a cb() | ||
83 | + * function can wait for the completion of another request. | ||
84 | + * | ||
85 | + * The aio_poll() loop will execute our BH and we'll resume completion | ||
86 | + * processing there. | ||
87 | + */ | ||
88 | + qemu_bh_schedule(q->completion_bh); | ||
89 | + | ||
90 | assert(q->inflight >= 0); | ||
91 | while (q->inflight) { | ||
92 | int ret; | ||
93 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) | ||
94 | assert(req.cb); | ||
95 | nvme_put_free_req_locked(q, preq); | ||
96 | preq->cb = preq->opaque = NULL; | ||
97 | - qemu_mutex_unlock(&q->lock); | ||
98 | - req.cb(req.opaque, ret); | ||
99 | - qemu_mutex_lock(&q->lock); | ||
100 | q->inflight--; | ||
101 | + qemu_mutex_unlock(&q->lock); | ||
102 | + req.cb(req.opaque, ret); | ||
103 | + qemu_mutex_lock(&q->lock); | ||
104 | progress = true; | ||
105 | } | ||
106 | if (progress) { | ||
107 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) | ||
108 | *q->cq.doorbell = cpu_to_le32(q->cq.head); | ||
109 | nvme_wake_free_req_locked(q); | ||
110 | } | ||
111 | - q->busy = false; | ||
112 | + | ||
113 | + qemu_bh_cancel(q->completion_bh); | ||
114 | + | ||
115 | return progress; | ||
26 | } | 116 | } |
27 | 117 | ||
28 | +# Resize image using block_resize. | 118 | +static void nvme_process_completion_bh(void *opaque) |
29 | +# Parameter 1: image path | ||
30 | +# Parameter 2: new size | ||
31 | +_block_resize() | ||
32 | +{ | 119 | +{ |
33 | + local path=$1 | 120 | + NVMeQueuePair *q = opaque; |
34 | + local size=$2 | ||
35 | + | 121 | + |
36 | + $QEMU -qmp stdio -nographic -nodefaults \ | 122 | + /* |
37 | + -blockdev file,node-name=file,filename=$path,cache.direct=on \ | 123 | + * We're being invoked because a nvme_process_completion() cb() function |
38 | + <<EOF | 124 | + * called aio_poll(). The callback may be waiting for further completions |
39 | +{'execute': 'qmp_capabilities'} | 125 | + * so notify the device that it has space to fill in more completions now. |
40 | +{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}} | 126 | + */ |
41 | +{'execute': 'quit'} | 127 | + smp_mb_release(); |
42 | +EOF | 128 | + *q->cq.doorbell = cpu_to_le32(q->cq.head); |
129 | + nvme_wake_free_req_locked(q); | ||
130 | + | ||
131 | + nvme_process_completion(q); | ||
43 | +} | 132 | +} |
44 | + | 133 | + |
45 | # get standard environment, filters and checks | 134 | static void nvme_trace_command(const NvmeCmd *cmd) |
46 | . ./common.rc | 135 | { |
47 | . ./common.filter | 136 | int i; |
48 | @@ -XXX,XX +XXX,XX @@ _supported_fmt raw | 137 | @@ -XXX,XX +XXX,XX @@ static void nvme_detach_aio_context(BlockDriverState *bs) |
49 | _supported_proto file | 138 | { |
50 | _supported_os Linux | 139 | BDRVNVMeState *s = bs->opaque; |
51 | 140 | ||
52 | +_default_cache_mode none | 141 | + for (int i = 0; i < s->nr_queues; i++) { |
53 | +_supported_cache_modes none directsync | 142 | + NVMeQueuePair *q = s->queues[i]; |
54 | + | 143 | + |
55 | size=$((1 * 1024 * 1024)) | 144 | + qemu_bh_delete(q->completion_bh); |
56 | 145 | + q->completion_bh = NULL; | |
57 | touch "$TEST_DIR/empty" | 146 | + } |
58 | @@ -XXX,XX +XXX,XX @@ for mode in off full falloc; do | ||
59 | stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
60 | done | ||
61 | |||
62 | +for new_size in 4096 1048576; do | ||
63 | + echo | ||
64 | + echo "== resize empty image with block_resize ==" | ||
65 | + _make_test_img 0 | _filter_imgfmt | ||
66 | + _block_resize $TEST_IMG $new_size >/dev/null | ||
67 | + stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $new_size | ||
68 | +done | ||
69 | + | 147 | + |
70 | # success, all done | 148 | aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, |
71 | echo "*** done" | 149 | false, NULL, NULL); |
72 | rm -f $seq.full | 150 | } |
73 | diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out | 151 | @@ -XXX,XX +XXX,XX @@ static void nvme_attach_aio_context(BlockDriverState *bs, |
152 | s->aio_context = new_context; | ||
153 | aio_set_event_notifier(new_context, &s->irq_notifier, | ||
154 | false, nvme_handle_event, nvme_poll_cb); | ||
155 | + | ||
156 | + for (int i = 0; i < s->nr_queues; i++) { | ||
157 | + NVMeQueuePair *q = s->queues[i]; | ||
158 | + | ||
159 | + q->completion_bh = | ||
160 | + aio_bh_new(new_context, nvme_process_completion_bh, q); | ||
161 | + } | ||
162 | } | ||
163 | |||
164 | static void nvme_aio_plug(BlockDriverState *bs) | ||
165 | diff --git a/block/trace-events b/block/trace-events | ||
74 | index XXXXXXX..XXXXXXX 100644 | 166 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/tests/qemu-iotests/175.out | 167 | --- a/block/trace-events |
76 | +++ b/tests/qemu-iotests/175.out | 168 | +++ b/block/trace-events |
77 | @@ -XXX,XX +XXX,XX @@ size=1048576, max allocation | 169 | @@ -XXX,XX +XXX,XX @@ nvme_kick(void *s, int queue) "s %p queue %d" |
78 | == creating image with preallocation falloc == | 170 | nvme_dma_flush_queue_wait(void *s) "s %p" |
79 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc | 171 | nvme_error(int cmd_specific, int sq_head, int sqid, int cid, int status) "cmd_specific %d sq_head %d sqid %d cid %d status 0x%x" |
80 | size=1048576, max allocation | 172 | nvme_process_completion(void *s, int index, int inflight) "s %p queue %d inflight %d" |
81 | + | 173 | -nvme_process_completion_queue_busy(void *s, int index) "s %p queue %d" |
82 | +== resize empty image with block_resize == | 174 | +nvme_process_completion_queue_plugged(void *s, int index) "s %p queue %d" |
83 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 | 175 | nvme_complete_command(void *s, int index, int cid) "s %p queue %d cid %d" |
84 | +size=4096, min allocation | 176 | nvme_submit_command(void *s, int index, int cid) "s %p queue %d cid %d" |
85 | + | 177 | nvme_submit_command_raw(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7) "%02x %02x %02x %02x %02x %02x %02x %02x" |
86 | +== resize empty image with block_resize == | ||
87 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 | ||
88 | +size=1048576, min allocation | ||
89 | *** done | ||
90 | -- | 178 | -- |
91 | 2.21.0 | 179 | 2.26.2 |
92 | 180 | ||
93 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | fe646693acc changed qemu-img create's output so that it no longer prints | ||
2 | single quotes around parameter values. The subformat and adapter_type | ||
3 | filters in _filter_img_create() have never been adapted to that change. | ||
4 | 1 | ||
5 | Fixes: fe646693acc13ac48b98435d14149ab04dc597bc | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Message-id: 20190815153638.4600-2-mreitz@redhat.com | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/059.out | 16 ++++++++-------- | ||
13 | tests/qemu-iotests/common.filter | 4 ++-- | ||
14 | 2 files changed, 10 insertions(+), 10 deletions(-) | ||
15 | |||
16 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/tests/qemu-iotests/059.out | ||
19 | +++ b/tests/qemu-iotests/059.out | ||
20 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
21 | qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big | ||
22 | |||
23 | === Testing monolithicFlat creation and opening === | ||
24 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat | ||
25 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 | ||
26 | image: TEST_DIR/t.IMGFMT | ||
27 | file format: IMGFMT | ||
28 | virtual size: 2 GiB (2147483648 bytes) | ||
29 | |||
30 | === Testing monolithicFlat with zeroed_grain === | ||
31 | qemu-img: TEST_DIR/t.IMGFMT: Flat image can't enable zeroed grain | ||
32 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat | ||
33 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 | ||
34 | |||
35 | === Testing big twoGbMaxExtentFlat === | ||
36 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMaxExtentFlat | ||
37 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 | ||
38 | image: TEST_DIR/t.vmdk | ||
39 | file format: vmdk | ||
40 | virtual size: 0.977 TiB (1073741824000 bytes) | ||
41 | @@ -XXX,XX +XXX,XX @@ Format specific information: | ||
42 | qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1 | ||
43 | |||
44 | === Testing truncated sparse === | ||
45 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse | ||
46 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 | ||
47 | qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes | ||
48 | |||
49 | === Converting to streamOptimized from image with small cluster size=== | ||
50 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | ||
51 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
52 | |||
53 | === Testing monolithicFlat with internally generated JSON file name === | ||
54 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 subformat=monolithicFlat | ||
55 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
56 | qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}' | ||
57 | |||
58 | === Testing version 3 === | ||
59 | @@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 64931328 | ||
60 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
61 | |||
62 | === Testing 4TB monolithicFlat creation and IO === | ||
63 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 subformat=monolithicFlat | ||
64 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 | ||
65 | image: TEST_DIR/t.IMGFMT | ||
66 | file format: IMGFMT | ||
67 | virtual size: 4 TiB (4398046511104 bytes) | ||
68 | @@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 966367641600 | ||
69 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
70 | |||
71 | === Testing qemu-img map on extents === | ||
72 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=monolithicSparse | ||
73 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 | ||
74 | wrote 1024/1024 bytes at offset 65024 | ||
75 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
76 | wrote 1024/1024 bytes at offset 2147483136 | ||
77 | @@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File | ||
78 | 0 0x20000 0x3f0000 TEST_DIR/t.vmdk | ||
79 | 0x7fff0000 0x20000 0x410000 TEST_DIR/t.vmdk | ||
80 | 0x140000000 0x10000 0x430000 TEST_DIR/t.vmdk | ||
81 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentSparse | ||
82 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 | ||
83 | wrote 1024/1024 bytes at offset 65024 | ||
84 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
85 | wrote 1024/1024 bytes at offset 2147483136 | ||
86 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/tests/qemu-iotests/common.filter | ||
89 | +++ b/tests/qemu-iotests/common.filter | ||
90 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() | ||
91 | -e "s# compat6=\\(on\\|off\\)##g" \ | ||
92 | -e "s# static=\\(on\\|off\\)##g" \ | ||
93 | -e "s# zeroed_grain=\\(on\\|off\\)##g" \ | ||
94 | - -e "s# subformat='[^']*'##g" \ | ||
95 | - -e "s# adapter_type='[^']*'##g" \ | ||
96 | + -e "s# subformat=[^ ]*##g" \ | ||
97 | + -e "s# adapter_type=[^ ]*##g" \ | ||
98 | -e "s# hwversion=[^ ]*##g" \ | ||
99 | -e "s# lazy_refcounts=\\(on\\|off\\)##g" \ | ||
100 | -e "s# block_size=[0-9]\\+##g" \ | ||
101 | -- | ||
102 | 2.21.0 | ||
103 | |||
104 | diff view generated by jsdifflib |