1 | The following changes since commit dd25f97c66a75d1508f1d4c6478ed2c95bec428f: | 1 | The following changes since commit 474f3938d79ab36b9231c9ad3b5a9314c2aeacde: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20190913' into staging (2019-09-16 10:15:15 +0100) | 3 | Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jun-21-2019' into staging (2019-06-21 15:40:50 +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-09-16 | 7 | https://github.com/XanClic/qemu.git tags/pull-block-2019-06-24 |
8 | 8 | ||
9 | for you to fetch changes up to 1825cc0783ccf0ec5d9f0b225a99b340bdd4c68f: | 9 | for you to fetch changes up to ab5d4a30f7f3803ca5106b370969c1b7b54136f8: |
10 | 10 | ||
11 | qemu-iotests: Add test for bz #1745922 (2019-09-16 15:37:12 +0200) | 11 | iotests: Fix 205 for concurrent runs (2019-06-24 16:01:40 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches: | 14 | Block patches: |
15 | - Fix for block jobs when used with I/O threads | 15 | - The SSH block driver now uses libssh instead of libssh2 |
16 | - Fix for a corruption when using qcow2's LUKS encryption mode | 16 | - The VMDK block driver gets read-only support for the seSparse |
17 | - cURL fix | 17 | subformat |
18 | - check-block.sh cleanups (for make check) | 18 | - Various fixes |
19 | - Refactoring | 19 | |
20 | --- | ||
21 | |||
22 | v2: | ||
23 | - Squashed Pino's fix for pre-0.8 libssh into the libssh patch | ||
20 | 24 | ||
21 | ---------------------------------------------------------------- | 25 | ---------------------------------------------------------------- |
22 | Max Reitz (7): | 26 | Anton Nefedov (1): |
23 | curl: Keep pointer to the CURLState in CURLSocket | 27 | iotest 134: test cluster-misaligned encrypted write |
24 | curl: Keep *socket until the end of curl_sock_cb() | ||
25 | curl: Check completion in curl_multi_do() | ||
26 | curl: Pass CURLSocket to curl_multi_do() | ||
27 | curl: Report only ready sockets | ||
28 | curl: Handle success in multi_check_completion | ||
29 | curl: Check curl_multi_add_handle()'s return code | ||
30 | 28 | ||
31 | Maxim Levitsky (3): | 29 | Klaus Birkelund Jensen (1): |
32 | block/qcow2: Fix corruption introduced by commit 8ac0f15f335 | 30 | nvme: do not advertise support for unsupported arbitration mechanism |
33 | block/qcow2: refactor encryption code | ||
34 | qemu-iotests: Add test for bz #1745922 | ||
35 | 31 | ||
36 | Nir Soffer (2): | 32 | Max Reitz (1): |
37 | block: Use QEMU_IS_ALIGNED | 33 | iotests: Fix 205 for concurrent runs |
38 | block: Remove unused masks | ||
39 | 34 | ||
40 | Sergio Lopez (1): | 35 | Pino Toscano (1): |
41 | blockjob: update nodes head while removing all bdrv | 36 | ssh: switch from libssh2 to libssh |
42 | 37 | ||
43 | Thomas Huth (2): | 38 | Sam Eiderman (3): |
44 | tests/qemu-iotests/check: Replace "tests" with "iotests" in final | 39 | vmdk: Fix comment regarding max l1_size coverage |
45 | status text | 40 | vmdk: Reduce the max bound for L1 table size |
46 | tests/Makefile: Do not print the name of the check-block.sh shell | 41 | vmdk: Add read-only support for seSparse snapshots |
47 | script | ||
48 | 42 | ||
49 | Vladimir Sementsov-Ogievskiy (1): | 43 | Vladimir Sementsov-Ogievskiy (1): |
50 | tests/qemu-iotests: Fix qemu-io related output in 026.out.nocache | 44 | blockdev: enable non-root nodes for transaction drive-backup source |
51 | 45 | ||
52 | tests/Makefile.include | 2 +- | 46 | configure | 65 +- |
53 | block/qcow2.h | 8 +- | 47 | block/Makefile.objs | 6 +- |
54 | include/block/block.h | 2 - | 48 | block/ssh.c | 652 ++++++++++-------- |
55 | block/bochs.c | 4 +- | 49 | block/vmdk.c | 372 +++++++++- |
56 | block/cloop.c | 4 +- | 50 | blockdev.c | 2 +- |
57 | block/curl.c | 133 ++++++++++------------- | 51 | hw/block/nvme.c | 1 - |
58 | block/dmg.c | 4 +- | 52 | .travis.yml | 4 +- |
59 | block/io.c | 8 +- | 53 | block/trace-events | 14 +- |
60 | block/qcow2-cluster.c | 40 +++---- | 54 | docs/qemu-block-drivers.texi | 2 +- |
61 | block/qcow2-threads.c | 63 ++++++++--- | 55 | .../dockerfiles/debian-win32-cross.docker | 1 - |
62 | block/qcow2.c | 9 +- | 56 | .../dockerfiles/debian-win64-cross.docker | 1 - |
63 | block/vvfat.c | 8 +- | 57 | tests/docker/dockerfiles/fedora.docker | 4 +- |
64 | blockjob.c | 17 ++- | 58 | tests/docker/dockerfiles/ubuntu.docker | 2 +- |
65 | migration/block.c | 2 +- | 59 | tests/docker/dockerfiles/ubuntu1804.docker | 2 +- |
66 | qemu-img.c | 2 +- | 60 | tests/qemu-iotests/059.out | 2 +- |
67 | tests/qemu-iotests/026.out.nocache | 168 ++++++++++++++--------------- | 61 | tests/qemu-iotests/134 | 9 + |
68 | tests/qemu-iotests/263 | 91 ++++++++++++++++ | 62 | tests/qemu-iotests/134.out | 10 + |
69 | tests/qemu-iotests/263.out | 40 +++++++ | 63 | tests/qemu-iotests/205 | 2 +- |
70 | tests/qemu-iotests/check | 8 +- | 64 | tests/qemu-iotests/207 | 54 +- |
71 | tests/qemu-iotests/group | 1 + | 65 | tests/qemu-iotests/207.out | 2 +- |
72 | 20 files changed, 380 insertions(+), 234 deletions(-) | 66 | 20 files changed, 823 insertions(+), 384 deletions(-) |
73 | create mode 100755 tests/qemu-iotests/263 | ||
74 | create mode 100644 tests/qemu-iotests/263.out | ||
75 | 67 | ||
76 | -- | 68 | -- |
77 | 2.21.0 | 69 | 2.21.0 |
78 | 70 | ||
79 | 71 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Nir Soffer <nirsof@gmail.com> | ||
2 | 1 | ||
3 | Replace instances of: | ||
4 | |||
5 | (n & (BDRV_SECTOR_SIZE - 1)) == 0 | ||
6 | |||
7 | And: | ||
8 | |||
9 | (n & ~BDRV_SECTOR_MASK) == 0 | ||
10 | |||
11 | With: | ||
12 | |||
13 | QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE) | ||
14 | |||
15 | Which reveals the intent of the code better, and makes it easier to | ||
16 | locate the code checking alignment. | ||
17 | |||
18 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
19 | Message-id: 20190827185913.27427-2-nsoffer@redhat.com | ||
20 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
21 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
22 | --- | ||
23 | block/bochs.c | 4 ++-- | ||
24 | block/cloop.c | 4 ++-- | ||
25 | block/dmg.c | 4 ++-- | ||
26 | block/io.c | 8 ++++---- | ||
27 | block/qcow2-cluster.c | 4 ++-- | ||
28 | block/qcow2.c | 4 ++-- | ||
29 | block/vvfat.c | 8 ++++---- | ||
30 | qemu-img.c | 2 +- | ||
31 | 8 files changed, 19 insertions(+), 19 deletions(-) | ||
32 | |||
33 | diff --git a/block/bochs.c b/block/bochs.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/block/bochs.c | ||
36 | +++ b/block/bochs.c | ||
37 | @@ -XXX,XX +XXX,XX @@ bochs_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
38 | QEMUIOVector local_qiov; | ||
39 | int ret; | ||
40 | |||
41 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
42 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
43 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
44 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
45 | |||
46 | qemu_iovec_init(&local_qiov, qiov->niov); | ||
47 | qemu_co_mutex_lock(&s->lock); | ||
48 | diff --git a/block/cloop.c b/block/cloop.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/block/cloop.c | ||
51 | +++ b/block/cloop.c | ||
52 | @@ -XXX,XX +XXX,XX @@ cloop_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
53 | int nb_sectors = bytes >> BDRV_SECTOR_BITS; | ||
54 | int ret, i; | ||
55 | |||
56 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
57 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
58 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
59 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
60 | |||
61 | qemu_co_mutex_lock(&s->lock); | ||
62 | |||
63 | diff --git a/block/dmg.c b/block/dmg.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/block/dmg.c | ||
66 | +++ b/block/dmg.c | ||
67 | @@ -XXX,XX +XXX,XX @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
68 | int nb_sectors = bytes >> BDRV_SECTOR_BITS; | ||
69 | int ret, i; | ||
70 | |||
71 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
72 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
73 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
74 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
75 | |||
76 | qemu_co_mutex_lock(&s->lock); | ||
77 | |||
78 | diff --git a/block/io.c b/block/io.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/block/io.c | ||
81 | +++ b/block/io.c | ||
82 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, | ||
83 | sector_num = offset >> BDRV_SECTOR_BITS; | ||
84 | nb_sectors = bytes >> BDRV_SECTOR_BITS; | ||
85 | |||
86 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
87 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
88 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
89 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
90 | assert(bytes <= BDRV_REQUEST_MAX_BYTES); | ||
91 | assert(drv->bdrv_co_readv); | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs, | ||
94 | sector_num = offset >> BDRV_SECTOR_BITS; | ||
95 | nb_sectors = bytes >> BDRV_SECTOR_BITS; | ||
96 | |||
97 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
98 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
99 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
100 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
101 | assert(bytes <= BDRV_REQUEST_MAX_BYTES); | ||
102 | |||
103 | assert(drv->bdrv_co_writev); | ||
104 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/block/qcow2-cluster.c | ||
107 | +++ b/block/qcow2-cluster.c | ||
108 | @@ -XXX,XX +XXX,XX @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs, | ||
109 | { | ||
110 | if (bytes && bs->encrypted) { | ||
111 | BDRVQcow2State *s = bs->opaque; | ||
112 | - assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0); | ||
113 | - assert((bytes & ~BDRV_SECTOR_MASK) == 0); | ||
114 | + assert(QEMU_IS_ALIGNED(offset_in_cluster, BDRV_SECTOR_SIZE)); | ||
115 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
116 | assert(s->crypto); | ||
117 | if (qcow2_co_encrypt(bs, cluster_offset, | ||
118 | src_cluster_offset + offset_in_cluster, | ||
119 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/block/qcow2.c | ||
122 | +++ b/block/qcow2.c | ||
123 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, | ||
124 | goto fail; | ||
125 | } | ||
126 | |||
127 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
128 | - assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
129 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
130 | + assert(QEMU_IS_ALIGNED(cur_bytes, BDRV_SECTOR_SIZE)); | ||
131 | if (qcow2_co_decrypt(bs, cluster_offset, offset, | ||
132 | cluster_data, cur_bytes) < 0) { | ||
133 | ret = -EIO; | ||
134 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/block/vvfat.c | ||
137 | +++ b/block/vvfat.c | ||
138 | @@ -XXX,XX +XXX,XX @@ vvfat_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
139 | int nb_sectors = bytes >> BDRV_SECTOR_BITS; | ||
140 | void *buf; | ||
141 | |||
142 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
143 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
144 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
145 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
146 | |||
147 | buf = g_try_malloc(bytes); | ||
148 | if (bytes && buf == NULL) { | ||
149 | @@ -XXX,XX +XXX,XX @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
150 | int nb_sectors = bytes >> BDRV_SECTOR_BITS; | ||
151 | void *buf; | ||
152 | |||
153 | - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
154 | - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | ||
155 | + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
156 | + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | ||
157 | |||
158 | buf = g_try_malloc(bytes); | ||
159 | if (bytes && buf == NULL) { | ||
160 | diff --git a/qemu-img.c b/qemu-img.c | ||
161 | index XXXXXXX..XXXXXXX 100644 | ||
162 | --- a/qemu-img.c | ||
163 | +++ b/qemu-img.c | ||
164 | @@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv) | ||
165 | int64_t sval; | ||
166 | |||
167 | sval = cvtnum(optarg); | ||
168 | - if (sval < 0 || sval & (BDRV_SECTOR_SIZE - 1) || | ||
169 | + if (sval < 0 || !QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || | ||
170 | sval / BDRV_SECTOR_SIZE > MAX_BUF_SECTORS) { | ||
171 | error_report("Invalid buffer size for sparse output specified. " | ||
172 | "Valid sizes are multiples of %llu up to %llu. Select " | ||
173 | -- | ||
174 | 2.21.0 | ||
175 | |||
176 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Nir Soffer <nirsof@gmail.com> | ||
2 | 1 | ||
3 | Replace confusing usage: | ||
4 | |||
5 | ~BDRV_SECTOR_MASK | ||
6 | |||
7 | With more clear: | ||
8 | |||
9 | (BDRV_SECTOR_SIZE - 1) | ||
10 | |||
11 | Remove BDRV_SECTOR_MASK and the unused BDRV_BLOCK_OFFSET_MASK which was | ||
12 | it's last user. | ||
13 | |||
14 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
15 | Message-id: 20190827185913.27427-3-nsoffer@redhat.com | ||
16 | Reviewed-by: Juan Quintela <quintela@redhat.com> | ||
17 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
18 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
19 | --- | ||
20 | include/block/block.h | 2 -- | ||
21 | migration/block.c | 2 +- | ||
22 | 2 files changed, 1 insertion(+), 3 deletions(-) | ||
23 | |||
24 | diff --git a/include/block/block.h b/include/block/block.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/block/block.h | ||
27 | +++ b/include/block/block.h | ||
28 | @@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry { | ||
29 | |||
30 | #define BDRV_SECTOR_BITS 9 | ||
31 | #define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS) | ||
32 | -#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1) | ||
33 | |||
34 | #define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ | ||
35 | INT_MAX >> BDRV_SECTOR_BITS) | ||
36 | @@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry { | ||
37 | #define BDRV_BLOCK_ALLOCATED 0x10 | ||
38 | #define BDRV_BLOCK_EOF 0x20 | ||
39 | #define BDRV_BLOCK_RECURSE 0x40 | ||
40 | -#define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK | ||
41 | |||
42 | typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue; | ||
43 | |||
44 | diff --git a/migration/block.c b/migration/block.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/migration/block.c | ||
47 | +++ b/migration/block.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static int block_load(QEMUFile *f, void *opaque, int version_id) | ||
49 | do { | ||
50 | addr = qemu_get_be64(f); | ||
51 | |||
52 | - flags = addr & ~BDRV_SECTOR_MASK; | ||
53 | + flags = addr & (BDRV_SECTOR_SIZE - 1); | ||
54 | addr >>= BDRV_SECTOR_BITS; | ||
55 | |||
56 | if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) { | ||
57 | -- | ||
58 | 2.21.0 | ||
59 | |||
60 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | When running "make check -j8" or something similar, the iotests are | ||
4 | running in parallel with the other tests. So when they are printing | ||
5 | out "Passed all xx tests" or a similar status message at the end, | ||
6 | it might not be quite clear that this message belongs to the iotests, | ||
7 | since the output might be mixed with the other tests. Thus change the | ||
8 | word "tests" here to "iotests" instead to avoid confusion. | ||
9 | |||
10 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
11 | Message-id: 20190906113920.11271-1-thuth@redhat.com | ||
12 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
13 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
14 | --- | ||
15 | tests/qemu-iotests/check | 8 ++++---- | ||
16 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
17 | |||
18 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | ||
19 | index XXXXXXX..XXXXXXX 100755 | ||
20 | --- a/tests/qemu-iotests/check | ||
21 | +++ b/tests/qemu-iotests/check | ||
22 | @@ -XXX,XX +XXX,XX @@ END { if (NR > 0) { | ||
23 | if [ ! -z "$n_bad" -a $n_bad != 0 ] | ||
24 | then | ||
25 | echo "Failures:$bad" | ||
26 | - echo "Failed $n_bad of $try tests" | ||
27 | + echo "Failed $n_bad of $try iotests" | ||
28 | echo "Failures:$bad" | fmt >>check.log | ||
29 | - echo "Failed $n_bad of $try tests" >>check.log | ||
30 | + echo "Failed $n_bad of $try iotests" >>check.log | ||
31 | else | ||
32 | - echo "Passed all $try tests" | ||
33 | - echo "Passed all $try tests" >>check.log | ||
34 | + echo "Passed all $try iotests" | ||
35 | + echo "Passed all $try iotests" >>check.log | ||
36 | fi | ||
37 | needwrap=false | ||
38 | fi | ||
39 | -- | ||
40 | 2.21.0 | ||
41 | |||
42 | diff view generated by jsdifflib |
1 | From: Sergio Lopez <slp@redhat.com> | 1 | From: Klaus Birkelund Jensen <klaus@birkelund.eu> |
---|---|---|---|
2 | 2 | ||
3 | block_job_remove_all_bdrv() iterates through job->nodes, calling | 3 | The device mistakenly reports that the Weighted Round Robin with Urgent |
4 | bdrv_root_unref_child() for each entry. The call to the latter may | 4 | Priority Class arbitration mechanism is supported. |
5 | reach child_job_[can_]set_aio_ctx(), which will also attempt to | ||
6 | traverse job->nodes, potentially finding entries that where freed | ||
7 | on previous iterations. | ||
8 | 5 | ||
9 | To avoid this situation, update job->nodes head on each iteration to | 6 | It is not. |
10 | ensure that already freed entries are no longer linked to the list. | ||
11 | 7 | ||
12 | RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1746631 | 8 | Signed-off-by: Klaus Birkelund Jensen <klaus.jensen@cnexlabs.com> |
13 | Signed-off-by: Sergio Lopez <slp@redhat.com> | 9 | Message-id: 20190606092530.14206-1-klaus@birkelund.eu |
14 | Cc: qemu-stable@nongnu.org | 10 | Acked-by: Maxim Levitsky <mlevitsk@redhat.com> |
15 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
16 | Message-id: 20190911100316.32282-1-mreitz@redhat.com | ||
17 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
18 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 11 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
19 | --- | 12 | --- |
20 | blockjob.c | 17 +++++++++++++---- | 13 | hw/block/nvme.c | 1 - |
21 | 1 file changed, 13 insertions(+), 4 deletions(-) | 14 | 1 file changed, 1 deletion(-) |
22 | 15 | ||
23 | diff --git a/blockjob.c b/blockjob.c | 16 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c |
24 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/blockjob.c | 18 | --- a/hw/block/nvme.c |
26 | +++ b/blockjob.c | 19 | +++ b/hw/block/nvme.c |
27 | @@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_job = { | 20 | @@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) |
28 | 21 | n->bar.cap = 0; | |
29 | void block_job_remove_all_bdrv(BlockJob *job) | 22 | NVME_CAP_SET_MQES(n->bar.cap, 0x7ff); |
30 | { | 23 | NVME_CAP_SET_CQR(n->bar.cap, 1); |
31 | - GSList *l; | 24 | - NVME_CAP_SET_AMS(n->bar.cap, 1); |
32 | - for (l = job->nodes; l; l = l->next) { | 25 | NVME_CAP_SET_TO(n->bar.cap, 0xf); |
33 | + /* | 26 | NVME_CAP_SET_CSS(n->bar.cap, 1); |
34 | + * bdrv_root_unref_child() may reach child_job_[can_]set_aio_ctx(), | 27 | NVME_CAP_SET_MPSMAX(n->bar.cap, 4); |
35 | + * which will also traverse job->nodes, so consume the list one by | ||
36 | + * one to make sure that such a concurrent access does not attempt | ||
37 | + * to process an already freed BdrvChild. | ||
38 | + */ | ||
39 | + while (job->nodes) { | ||
40 | + GSList *l = job->nodes; | ||
41 | BdrvChild *c = l->data; | ||
42 | + | ||
43 | + job->nodes = l->next; | ||
44 | + | ||
45 | bdrv_op_unblock_all(c->bs, job->blocker); | ||
46 | bdrv_root_unref_child(c); | ||
47 | + | ||
48 | + g_slist_free_1(l); | ||
49 | } | ||
50 | - g_slist_free(job->nodes); | ||
51 | - job->nodes = NULL; | ||
52 | } | ||
53 | |||
54 | bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs) | ||
55 | -- | 28 | -- |
56 | 2.21.0 | 29 | 2.21.0 |
57 | 30 | ||
58 | 31 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | qemu-io now prefixes its error and warnings with "qemu-io:". | 3 | We forget to enable it for transaction .prepare, while it is already |
4 | 36b9986b08787019e fixed a lot of iotests output but forget about | 4 | enabled in do_drive_backup since commit a2d665c1bc362 |
5 | 026.out.nocache. Fix it too. | 5 | "blockdev: loosen restrictions on drive-backup source node" |
6 | 6 | ||
7 | Fixes: 99e98d7c9fc1a1639fad ("qemu-io: Use error_[gs]et_progname()") | ||
8 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 7 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
9 | Message-id: 20190816153015.447957-2-vsementsov@virtuozzo.com | 8 | Message-id: 20190618140804.59214-1-vsementsov@virtuozzo.com |
10 | Reviewed-by: John Snow <jsnow@redhat.com> | 9 | Reviewed-by: John Snow <jsnow@redhat.com> |
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 10 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
12 | --- | 11 | --- |
13 | tests/qemu-iotests/026.out.nocache | 168 ++++++++++++++--------------- | 12 | blockdev.c | 2 +- |
14 | 1 file changed, 84 insertions(+), 84 deletions(-) | 13 | 1 file changed, 1 insertion(+), 1 deletion(-) |
15 | 14 | ||
16 | diff --git a/tests/qemu-iotests/026.out.nocache b/tests/qemu-iotests/026.out.nocache | 15 | diff --git a/blockdev.c b/blockdev.c |
17 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/qemu-iotests/026.out.nocache | 17 | --- a/blockdev.c |
19 | +++ b/tests/qemu-iotests/026.out.nocache | 18 | +++ b/blockdev.c |
20 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | 19 | @@ -XXX,XX +XXX,XX @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) |
21 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | 20 | assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); |
22 | 21 | backup = common->action->u.drive_backup.data; | |
23 | Event: l1_update; errno: 5; imm: off; once: off; write | 22 | |
24 | -Failed to flush the L2 table cache: Input/output error | 23 | - bs = qmp_get_root_bs(backup->device, errp); |
25 | -Failed to flush the refcount block cache: Input/output error | 24 | + bs = bdrv_lookup_bs(backup->device, backup->device, errp); |
26 | +qemu-io: Failed to flush the L2 table cache: Input/output error | 25 | if (!bs) { |
27 | +qemu-io: Failed to flush the refcount block cache: Input/output error | 26 | return; |
28 | write failed: Input/output error | 27 | } |
29 | |||
30 | 1 leaked clusters were found on the image. | ||
31 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
32 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
33 | |||
34 | Event: l1_update; errno: 5; imm: off; once: off; write -b | ||
35 | -Failed to flush the L2 table cache: Input/output error | ||
36 | -Failed to flush the refcount block cache: Input/output error | ||
37 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
38 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
39 | write failed: Input/output error | ||
40 | |||
41 | 1 leaked clusters were found on the image. | ||
42 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
43 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
44 | |||
45 | Event: l1_update; errno: 28; imm: off; once: off; write | ||
46 | -Failed to flush the L2 table cache: No space left on device | ||
47 | -Failed to flush the refcount block cache: No space left on device | ||
48 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
49 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
50 | write failed: No space left on device | ||
51 | |||
52 | 1 leaked clusters were found on the image. | ||
53 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
54 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
55 | |||
56 | Event: l1_update; errno: 28; imm: off; once: off; write -b | ||
57 | -Failed to flush the L2 table cache: No space left on device | ||
58 | -Failed to flush the refcount block cache: No space left on device | ||
59 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
60 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
61 | write failed: No space left on device | ||
62 | |||
63 | 1 leaked clusters were found on the image. | ||
64 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
65 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
66 | |||
67 | Event: l2_update; errno: 5; imm: off; once: off; write | ||
68 | -Failed to flush the L2 table cache: Input/output error | ||
69 | -Failed to flush the refcount block cache: Input/output error | ||
70 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
71 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
72 | wrote 131072/131072 bytes at offset 0 | ||
73 | 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
74 | |||
75 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
76 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
77 | |||
78 | Event: l2_update; errno: 5; imm: off; once: off; write -b | ||
79 | -Failed to flush the L2 table cache: Input/output error | ||
80 | -Failed to flush the refcount block cache: Input/output error | ||
81 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
82 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
83 | wrote 131072/131072 bytes at offset 0 | ||
84 | 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
85 | |||
86 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
87 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
88 | |||
89 | Event: l2_update; errno: 28; imm: off; once: off; write | ||
90 | -Failed to flush the L2 table cache: No space left on device | ||
91 | -Failed to flush the refcount block cache: No space left on device | ||
92 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
93 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
94 | wrote 131072/131072 bytes at offset 0 | ||
95 | 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
96 | |||
97 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
98 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
99 | |||
100 | Event: l2_update; errno: 28; imm: off; once: off; write -b | ||
101 | -Failed to flush the L2 table cache: No space left on device | ||
102 | -Failed to flush the refcount block cache: No space left on device | ||
103 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
104 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
105 | wrote 131072/131072 bytes at offset 0 | ||
106 | 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
107 | |||
108 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
109 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
110 | |||
111 | Event: l2_alloc_write; errno: 5; imm: off; once: off; write | ||
112 | -Failed to flush the L2 table cache: Input/output error | ||
113 | -Failed to flush the refcount block cache: Input/output error | ||
114 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
115 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
116 | write failed: Input/output error | ||
117 | No errors were found on the image. | ||
118 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
119 | |||
120 | Event: l2_alloc_write; errno: 5; imm: off; once: off; write -b | ||
121 | -Failed to flush the L2 table cache: Input/output error | ||
122 | -Failed to flush the refcount block cache: Input/output error | ||
123 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
124 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
125 | write failed: Input/output error | ||
126 | |||
127 | 1 leaked clusters were found on the image. | ||
128 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
129 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
130 | |||
131 | Event: l2_alloc_write; errno: 28; imm: off; once: off; write | ||
132 | -Failed to flush the L2 table cache: No space left on device | ||
133 | -Failed to flush the refcount block cache: No space left on device | ||
134 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
135 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
136 | write failed: No space left on device | ||
137 | No errors were found on the image. | ||
138 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
139 | |||
140 | Event: l2_alloc_write; errno: 28; imm: off; once: off; write -b | ||
141 | -Failed to flush the L2 table cache: No space left on device | ||
142 | -Failed to flush the refcount block cache: No space left on device | ||
143 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
144 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
145 | write failed: No space left on device | ||
146 | |||
147 | 1 leaked clusters were found on the image. | ||
148 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
149 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
150 | |||
151 | Event: write_aio; errno: 5; imm: off; once: off; write | ||
152 | -Failed to flush the L2 table cache: Input/output error | ||
153 | -Failed to flush the refcount block cache: Input/output error | ||
154 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
155 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
156 | write failed: Input/output error | ||
157 | No errors were found on the image. | ||
158 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
159 | |||
160 | Event: write_aio; errno: 5; imm: off; once: off; write -b | ||
161 | -Failed to flush the L2 table cache: Input/output error | ||
162 | -Failed to flush the refcount block cache: Input/output error | ||
163 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
164 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
165 | write failed: Input/output error | ||
166 | No errors were found on the image. | ||
167 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
168 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
169 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
170 | |||
171 | Event: write_aio; errno: 28; imm: off; once: off; write | ||
172 | -Failed to flush the L2 table cache: No space left on device | ||
173 | -Failed to flush the refcount block cache: No space left on device | ||
174 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
175 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
176 | write failed: No space left on device | ||
177 | No errors were found on the image. | ||
178 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
179 | |||
180 | Event: write_aio; errno: 28; imm: off; once: off; write -b | ||
181 | -Failed to flush the L2 table cache: No space left on device | ||
182 | -Failed to flush the refcount block cache: No space left on device | ||
183 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
184 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
185 | write failed: No space left on device | ||
186 | No errors were found on the image. | ||
187 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
188 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
189 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
190 | |||
191 | Event: refblock_load; errno: 5; imm: off; once: off; write | ||
192 | -Failed to flush the L2 table cache: Input/output error | ||
193 | -Failed to flush the refcount block cache: Input/output error | ||
194 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
195 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
196 | write failed: Input/output error | ||
197 | No errors were found on the image. | ||
198 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
199 | |||
200 | Event: refblock_load; errno: 5; imm: off; once: off; write -b | ||
201 | -Failed to flush the L2 table cache: Input/output error | ||
202 | -Failed to flush the refcount block cache: Input/output error | ||
203 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
204 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
205 | write failed: Input/output error | ||
206 | No errors were found on the image. | ||
207 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
208 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
209 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
210 | |||
211 | Event: refblock_load; errno: 28; imm: off; once: off; write | ||
212 | -Failed to flush the L2 table cache: No space left on device | ||
213 | -Failed to flush the refcount block cache: No space left on device | ||
214 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
215 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
216 | write failed: No space left on device | ||
217 | No errors were found on the image. | ||
218 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
219 | |||
220 | Event: refblock_load; errno: 28; imm: off; once: off; write -b | ||
221 | -Failed to flush the L2 table cache: No space left on device | ||
222 | -Failed to flush the refcount block cache: No space left on device | ||
223 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
224 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
225 | write failed: No space left on device | ||
226 | No errors were found on the image. | ||
227 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
228 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
229 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
230 | |||
231 | Event: refblock_update_part; errno: 5; imm: off; once: off; write | ||
232 | -Failed to flush the L2 table cache: Input/output error | ||
233 | -Failed to flush the refcount block cache: Input/output error | ||
234 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
235 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
236 | write failed: Input/output error | ||
237 | No errors were found on the image. | ||
238 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
239 | |||
240 | Event: refblock_update_part; errno: 5; imm: off; once: off; write -b | ||
241 | -Failed to flush the L2 table cache: Input/output error | ||
242 | -Failed to flush the refcount block cache: Input/output error | ||
243 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
244 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
245 | write failed: Input/output error | ||
246 | No errors were found on the image. | ||
247 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
248 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
249 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
250 | |||
251 | Event: refblock_update_part; errno: 28; imm: off; once: off; write | ||
252 | -Failed to flush the L2 table cache: No space left on device | ||
253 | -Failed to flush the refcount block cache: No space left on device | ||
254 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
255 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
256 | write failed: No space left on device | ||
257 | No errors were found on the image. | ||
258 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
259 | |||
260 | Event: refblock_update_part; errno: 28; imm: off; once: off; write -b | ||
261 | -Failed to flush the L2 table cache: No space left on device | ||
262 | -Failed to flush the refcount block cache: No space left on device | ||
263 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
264 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
265 | write failed: No space left on device | ||
266 | No errors were found on the image. | ||
267 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
268 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
269 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
270 | |||
271 | Event: refblock_alloc; errno: 5; imm: off; once: off; write | ||
272 | -Failed to flush the L2 table cache: Input/output error | ||
273 | -Failed to flush the refcount block cache: Input/output error | ||
274 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
275 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
276 | write failed: Input/output error | ||
277 | No errors were found on the image. | ||
278 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
279 | |||
280 | Event: refblock_alloc; errno: 5; imm: off; once: off; write -b | ||
281 | -Failed to flush the L2 table cache: Input/output error | ||
282 | -Failed to flush the refcount block cache: Input/output error | ||
283 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
284 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
285 | write failed: Input/output error | ||
286 | No errors were found on the image. | ||
287 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
288 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
289 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
290 | |||
291 | Event: refblock_alloc; errno: 28; imm: off; once: off; write | ||
292 | -Failed to flush the L2 table cache: No space left on device | ||
293 | -Failed to flush the refcount block cache: No space left on device | ||
294 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
295 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
296 | write failed: No space left on device | ||
297 | No errors were found on the image. | ||
298 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
299 | |||
300 | Event: refblock_alloc; errno: 28; imm: off; once: off; write -b | ||
301 | -Failed to flush the L2 table cache: No space left on device | ||
302 | -Failed to flush the refcount block cache: No space left on device | ||
303 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
304 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
305 | write failed: No space left on device | ||
306 | No errors were found on the image. | ||
307 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
308 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
309 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
310 | |||
311 | Event: refblock_alloc_hookup; errno: 28; imm: off; once: off; write | ||
312 | -Failed to flush the L2 table cache: No space left on device | ||
313 | -Failed to flush the refcount block cache: No space left on device | ||
314 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
315 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
316 | write failed: No space left on device | ||
317 | |||
318 | 55 leaked clusters were found on the image. | ||
319 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
320 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
321 | |||
322 | Event: refblock_alloc_hookup; errno: 28; imm: off; once: off; write -b | ||
323 | -Failed to flush the L2 table cache: No space left on device | ||
324 | -Failed to flush the refcount block cache: No space left on device | ||
325 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
326 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
327 | write failed: No space left on device | ||
328 | |||
329 | 251 leaked clusters were found on the image. | ||
330 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
331 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
332 | |||
333 | Event: refblock_alloc_write; errno: 28; imm: off; once: off; write | ||
334 | -Failed to flush the L2 table cache: No space left on device | ||
335 | -Failed to flush the refcount block cache: No space left on device | ||
336 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
337 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
338 | write failed: No space left on device | ||
339 | No errors were found on the image. | ||
340 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
341 | |||
342 | Event: refblock_alloc_write; errno: 28; imm: off; once: off; write -b | ||
343 | -Failed to flush the L2 table cache: No space left on device | ||
344 | -Failed to flush the refcount block cache: No space left on device | ||
345 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
346 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
347 | write failed: No space left on device | ||
348 | No errors were found on the image. | ||
349 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
350 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
351 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
352 | |||
353 | Event: refblock_alloc_write_blocks; errno: 28; imm: off; once: off; write | ||
354 | -Failed to flush the L2 table cache: No space left on device | ||
355 | -Failed to flush the refcount block cache: No space left on device | ||
356 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
357 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
358 | write failed: No space left on device | ||
359 | |||
360 | 10 leaked clusters were found on the image. | ||
361 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
362 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
363 | |||
364 | Event: refblock_alloc_write_blocks; errno: 28; imm: off; once: off; write -b | ||
365 | -Failed to flush the L2 table cache: No space left on device | ||
366 | -Failed to flush the refcount block cache: No space left on device | ||
367 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
368 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
369 | write failed: No space left on device | ||
370 | |||
371 | 23 leaked clusters were found on the image. | ||
372 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
373 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
374 | |||
375 | Event: refblock_alloc_write_table; errno: 28; imm: off; once: off; write | ||
376 | -Failed to flush the L2 table cache: No space left on device | ||
377 | -Failed to flush the refcount block cache: No space left on device | ||
378 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
379 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
380 | write failed: No space left on device | ||
381 | |||
382 | 10 leaked clusters were found on the image. | ||
383 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
384 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
385 | |||
386 | Event: refblock_alloc_write_table; errno: 28; imm: off; once: off; write -b | ||
387 | -Failed to flush the L2 table cache: No space left on device | ||
388 | -Failed to flush the refcount block cache: No space left on device | ||
389 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
390 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
391 | write failed: No space left on device | ||
392 | |||
393 | 23 leaked clusters were found on the image. | ||
394 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
395 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
396 | |||
397 | Event: refblock_alloc_switch_table; errno: 28; imm: off; once: off; write | ||
398 | -Failed to flush the L2 table cache: No space left on device | ||
399 | -Failed to flush the refcount block cache: No space left on device | ||
400 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
401 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
402 | write failed: No space left on device | ||
403 | |||
404 | 10 leaked clusters were found on the image. | ||
405 | @@ -XXX,XX +XXX,XX @@ This means waste of disk space, but no harm to data. | ||
406 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
407 | |||
408 | Event: refblock_alloc_switch_table; errno: 28; imm: off; once: off; write -b | ||
409 | -Failed to flush the L2 table cache: No space left on device | ||
410 | -Failed to flush the refcount block cache: No space left on device | ||
411 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
412 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
413 | write failed: No space left on device | ||
414 | |||
415 | 23 leaked clusters were found on the image. | ||
416 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
417 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
418 | |||
419 | Event: l1_grow_write_table; errno: 5; imm: off; once: off | ||
420 | -Failed to flush the L2 table cache: Input/output error | ||
421 | -Failed to flush the refcount block cache: Input/output error | ||
422 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
423 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
424 | write failed: Input/output error | ||
425 | No errors were found on the image. | ||
426 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
427 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
428 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
429 | |||
430 | Event: l1_grow_write_table; errno: 28; imm: off; once: off | ||
431 | -Failed to flush the L2 table cache: No space left on device | ||
432 | -Failed to flush the refcount block cache: No space left on device | ||
433 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
434 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
435 | write failed: No space left on device | ||
436 | No errors were found on the image. | ||
437 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
438 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
439 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
440 | |||
441 | Event: l1_grow_activate_table; errno: 5; imm: off; once: off | ||
442 | -Failed to flush the L2 table cache: Input/output error | ||
443 | -Failed to flush the refcount block cache: Input/output error | ||
444 | +qemu-io: Failed to flush the L2 table cache: Input/output error | ||
445 | +qemu-io: Failed to flush the refcount block cache: Input/output error | ||
446 | write failed: Input/output error | ||
447 | |||
448 | 96 leaked clusters were found on the image. | ||
449 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
450 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 | ||
451 | |||
452 | Event: l1_grow_activate_table; errno: 28; imm: off; once: off | ||
453 | -Failed to flush the L2 table cache: No space left on device | ||
454 | -Failed to flush the refcount block cache: No space left on device | ||
455 | +qemu-io: Failed to flush the L2 table cache: No space left on device | ||
456 | +qemu-io: Failed to flush the refcount block cache: No space left on device | ||
457 | write failed: No space left on device | ||
458 | |||
459 | 96 leaked clusters were found on the image. | ||
460 | -- | 28 | -- |
461 | 2.21.0 | 29 | 2.21.0 |
462 | 30 | ||
463 | 31 | diff view generated by jsdifflib |
1 | From: Maxim Levitsky <mlevitsk@redhat.com> | 1 | From: Anton Nefedov <anton.nefedov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> | 3 | COW (even empty/zero) areas require encryption too |
4 | Tested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 4 | |
5 | Message-id: 20190915203655.21638-4-mlevitsk@redhat.com | 5 | Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com> |
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
6 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 7 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
8 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
9 | Message-id: 20190516143028.81155-1-anton.nefedov@virtuozzo.com | ||
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 10 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
8 | --- | 11 | --- |
9 | tests/qemu-iotests/263 | 91 ++++++++++++++++++++++++++++++++++++++ | 12 | tests/qemu-iotests/134 | 9 +++++++++ |
10 | tests/qemu-iotests/263.out | 40 +++++++++++++++++ | 13 | tests/qemu-iotests/134.out | 10 ++++++++++ |
11 | tests/qemu-iotests/group | 1 + | 14 | 2 files changed, 19 insertions(+) |
12 | 3 files changed, 132 insertions(+) | ||
13 | create mode 100755 tests/qemu-iotests/263 | ||
14 | create mode 100644 tests/qemu-iotests/263.out | ||
15 | 15 | ||
16 | diff --git a/tests/qemu-iotests/263 b/tests/qemu-iotests/263 | 16 | diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 |
17 | new file mode 100755 | 17 | index XXXXXXX..XXXXXXX 100755 |
18 | index XXXXXXX..XXXXXXX | 18 | --- a/tests/qemu-iotests/134 |
19 | --- /dev/null | 19 | +++ b/tests/qemu-iotests/134 |
20 | +++ b/tests/qemu-iotests/263 | 20 | @@ -XXX,XX +XXX,XX @@ echo |
21 | @@ -XXX,XX +XXX,XX @@ | 21 | echo "== reading whole image ==" |
22 | +#!/usr/bin/env bash | 22 | $QEMU_IO --object $SECRET -c "read 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
23 | +# | 23 | |
24 | +# Test encrypted write that crosses cluster boundary of two unallocated clusters | 24 | +echo |
25 | +# Based on 188 | 25 | +echo "== rewriting cluster part ==" |
26 | +# | 26 | +$QEMU_IO --object $SECRET -c "write -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
27 | +# Copyright (C) 2019 Red Hat, Inc. | ||
28 | +# | ||
29 | +# This program is free software; you can redistribute it and/or modify | ||
30 | +# it under the terms of the GNU General Public License as published by | ||
31 | +# the Free Software Foundation; either version 2 of the License, or | ||
32 | +# (at your option) any later version. | ||
33 | +# | ||
34 | +# This program is distributed in the hope that it will be useful, | ||
35 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
36 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
37 | +# GNU General Public License for more details. | ||
38 | +# | ||
39 | +# You should have received a copy of the GNU General Public License | ||
40 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
41 | +# | ||
42 | + | ||
43 | +# creator | ||
44 | +owner=mlevitsk@redhat.com | ||
45 | + | ||
46 | +seq=`basename $0` | ||
47 | +echo "QA output created by $seq" | ||
48 | + | ||
49 | +status=1 # failure is the default! | ||
50 | + | ||
51 | +_cleanup() | ||
52 | +{ | ||
53 | + _cleanup_test_img | ||
54 | +} | ||
55 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
56 | + | ||
57 | +# get standard environment, filters and checks | ||
58 | +. ./common.rc | ||
59 | +. ./common.filter | ||
60 | + | ||
61 | +_supported_fmt qcow2 | ||
62 | +_supported_proto generic | ||
63 | +_supported_os Linux | ||
64 | + | ||
65 | + | ||
66 | +size=1M | ||
67 | + | ||
68 | +SECRET="secret,id=sec0,data=astrochicken" | ||
69 | +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT | ||
70 | + | ||
71 | + | ||
72 | +_run_test() | ||
73 | +{ | ||
74 | + echo "== reading the whole image ==" | ||
75 | + $QEMU_IO --object $SECRET -c "read -P 0 0 $size" --image-opts "$1" | _filter_qemu_io | _filter_testdir | ||
76 | + | ||
77 | + echo | ||
78 | + echo "== write two 512 byte sectors on a cluster boundary ==" | ||
79 | + $QEMU_IO --object $SECRET -c "write -P 0xAA 0xFE00 0x400" --image-opts "$1" | _filter_qemu_io | _filter_testdir | ||
80 | + | ||
81 | + echo | ||
82 | + echo "== verify that the rest of the image is not changed ==" | ||
83 | + $QEMU_IO --object $SECRET -c "read -P 0x00 0x00000 0xFE00" --image-opts "$1" | _filter_qemu_io | _filter_testdir | ||
84 | + $QEMU_IO --object $SECRET -c "read -P 0xAA 0x0FE00 0x400" --image-opts "$1" | _filter_qemu_io | _filter_testdir | ||
85 | + $QEMU_IO --object $SECRET -c "read -P 0x00 0x10200 0xEFE00" --image-opts "$1" | _filter_qemu_io | _filter_testdir | ||
86 | + | ||
87 | +} | ||
88 | + | ||
89 | + | 27 | + |
90 | +echo | 28 | +echo |
91 | +echo "testing LUKS qcow2 encryption" | 29 | +echo "== verify pattern ==" |
92 | +echo | 30 | +$QEMU_IO --object $SECRET -c "read -P 0 0 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
31 | +$QEMU_IO --object $SECRET -c "read -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | ||
93 | + | 32 | + |
94 | +_make_test_img --object $SECRET -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10,cluster_size=64K" $size | 33 | echo |
95 | +_run_test "driver=$IMGFMT,encrypt.key-secret=sec0,file.filename=$TEST_IMG" | 34 | echo "== rewriting whole image ==" |
96 | +_cleanup_test_img | 35 | $QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
36 | diff --git a/tests/qemu-iotests/134.out b/tests/qemu-iotests/134.out | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/tests/qemu-iotests/134.out | ||
39 | +++ b/tests/qemu-iotests/134.out | ||
40 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on encrypt. | ||
41 | read 134217728/134217728 bytes at offset 0 | ||
42 | 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
43 | |||
44 | +== rewriting cluster part == | ||
45 | +wrote 512/512 bytes at offset 512 | ||
46 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
97 | + | 47 | + |
98 | +echo | 48 | +== verify pattern == |
99 | +echo "testing legacy AES qcow2 encryption" | 49 | +read 512/512 bytes at offset 0 |
100 | +echo | 50 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
51 | +read 512/512 bytes at offset 512 | ||
52 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
101 | + | 53 | + |
102 | + | 54 | == rewriting whole image == |
103 | +_make_test_img --object $SECRET -o "encrypt.format=aes,encrypt.key-secret=sec0,cluster_size=64K" $size | 55 | wrote 134217728/134217728 bytes at offset 0 |
104 | +_run_test "driver=$IMGFMT,encrypt.key-secret=sec0,file.filename=$TEST_IMG" | 56 | 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
105 | +_cleanup_test_img | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | +# success, all done | ||
110 | +echo "*** done" | ||
111 | +rm -f $seq.full | ||
112 | +status=0 | ||
113 | diff --git a/tests/qemu-iotests/263.out b/tests/qemu-iotests/263.out | ||
114 | new file mode 100644 | ||
115 | index XXXXXXX..XXXXXXX | ||
116 | --- /dev/null | ||
117 | +++ b/tests/qemu-iotests/263.out | ||
118 | @@ -XXX,XX +XXX,XX @@ | ||
119 | +QA output created by 263 | ||
120 | + | ||
121 | +testing LUKS qcow2 encryption | ||
122 | + | ||
123 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 encrypt.format=luks encrypt.key-secret=sec0 encrypt.iter-time=10 | ||
124 | +== reading the whole image == | ||
125 | +read 1048576/1048576 bytes at offset 0 | ||
126 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
127 | + | ||
128 | +== write two 512 byte sectors on a cluster boundary == | ||
129 | +wrote 1024/1024 bytes at offset 65024 | ||
130 | +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
131 | + | ||
132 | +== verify that the rest of the image is not changed == | ||
133 | +read 65024/65024 bytes at offset 0 | ||
134 | +63.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
135 | +read 1024/1024 bytes at offset 65024 | ||
136 | +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
137 | +read 982528/982528 bytes at offset 66048 | ||
138 | +959.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
139 | + | ||
140 | +testing legacy AES qcow2 encryption | ||
141 | + | ||
142 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 encrypt.format=aes encrypt.key-secret=sec0 | ||
143 | +== reading the whole image == | ||
144 | +read 1048576/1048576 bytes at offset 0 | ||
145 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
146 | + | ||
147 | +== write two 512 byte sectors on a cluster boundary == | ||
148 | +wrote 1024/1024 bytes at offset 65024 | ||
149 | +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
150 | + | ||
151 | +== verify that the rest of the image is not changed == | ||
152 | +read 65024/65024 bytes at offset 0 | ||
153 | +63.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
154 | +read 1024/1024 bytes at offset 65024 | ||
155 | +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
156 | +read 982528/982528 bytes at offset 66048 | ||
157 | +959.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
158 | +*** done | ||
159 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/tests/qemu-iotests/group | ||
162 | +++ b/tests/qemu-iotests/group | ||
163 | @@ -XXX,XX +XXX,XX @@ | ||
164 | 257 rw | ||
165 | 258 rw quick | ||
166 | 262 rw quick migration | ||
167 | +263 rw quick | ||
168 | 265 rw auto quick | ||
169 | 266 rw quick | ||
170 | -- | 57 | -- |
171 | 2.21.0 | 58 | 2.21.0 |
172 | 59 | ||
173 | 60 | diff view generated by jsdifflib |
1 | From: Maxim Levitsky <mlevitsk@redhat.com> | 1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | This fixes subtle corruption introduced by luks threaded encryption | 3 | Commit b0651b8c246d ("vmdk: Move l1_size check into vmdk_add_extent") |
4 | in commit 8ac0f15f335 | 4 | extended the l1_size check from VMDK4 to VMDK3 but did not update the |
5 | default coverage in the moved comment. | ||
5 | 6 | ||
6 | Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1745922 | 7 | The previous vmdk4 calculation: |
7 | 8 | ||
8 | The corruption happens when we do a write that | 9 | (512 * 1024 * 1024) * 512(l2 entries) * 65536(grain) = 16PB |
9 | * writes to two or more unallocated clusters at once | ||
10 | * doesn't fully cover the first sector | ||
11 | * doesn't fully cover the last sector | ||
12 | * uses luks encryption | ||
13 | 10 | ||
14 | In this case, when allocating the new clusters we COW both areas | 11 | The added vmdk3 calculation: |
15 | prior to the write and after the write, and we encrypt them. | ||
16 | 12 | ||
17 | The above mentioned commit accidentally made it so we encrypt the | 13 | (512 * 1024 * 1024) * 4096(l2 entries) * 512(grain) = 1PB |
18 | second COW area using the physical cluster offset of the first area. | ||
19 | 14 | ||
20 | The problem is that offset_in_cluster in do_perform_cow_encrypt | 15 | Adding the calculation of vmdk3 to the comment. |
21 | can be larger that the cluster size, thus cluster_offset | ||
22 | will no longer point to the start of the cluster at which encrypted | ||
23 | area starts. | ||
24 | 16 | ||
25 | Next patch in this series will refactor the code to avoid all these | 17 | In any case, VMware does not offer virtual disks more than 2TB for |
26 | assumptions. | 18 | vmdk4/vmdk3 or 64TB for the new undocumented seSparse format which is |
19 | not implemented yet in qemu. | ||
27 | 20 | ||
28 | In the bugreport that was triggered by rebasing a luks image to new, | 21 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> |
29 | zero filled base, which lot of such writes, and causes some files | 22 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> |
30 | with zero areas to contain garbage there instead. | 23 | Reviewed-by: Liran Alon <liran.alon@oracle.com> |
31 | But as described above it can happen elsewhere as well | 24 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> |
32 | 25 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | |
33 | Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> | 26 | Message-id: 20190620091057.47441-2-shmuel.eiderman@oracle.com |
34 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 27 | Reviewed-by: yuchenlin <yuchenlin@synology.com> |
35 | Message-id: 20190915203655.21638-2-mlevitsk@redhat.com | ||
36 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 28 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
37 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 29 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
38 | --- | 30 | --- |
39 | block/qcow2-cluster.c | 7 ++++--- | 31 | block/vmdk.c | 11 ++++++++--- |
40 | 1 file changed, 4 insertions(+), 3 deletions(-) | 32 | 1 file changed, 8 insertions(+), 3 deletions(-) |
41 | 33 | ||
42 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c | 34 | diff --git a/block/vmdk.c b/block/vmdk.c |
43 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/block/qcow2-cluster.c | 36 | --- a/block/vmdk.c |
45 | +++ b/block/qcow2-cluster.c | 37 | +++ b/block/vmdk.c |
46 | @@ -XXX,XX +XXX,XX @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs, | 38 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, |
47 | assert(QEMU_IS_ALIGNED(offset_in_cluster, BDRV_SECTOR_SIZE)); | 39 | return -EFBIG; |
48 | assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | 40 | } |
49 | assert(s->crypto); | 41 | if (l1_size > 512 * 1024 * 1024) { |
50 | - if (qcow2_co_encrypt(bs, cluster_offset, | 42 | - /* Although with big capacity and small l1_entry_sectors, we can get a |
51 | - src_cluster_offset + offset_in_cluster, | 43 | + /* |
52 | - buffer, bytes) < 0) { | 44 | + * Although with big capacity and small l1_entry_sectors, we can get a |
53 | + if (qcow2_co_encrypt(bs, | 45 | * big l1_size, we don't want unbounded value to allocate the table. |
54 | + start_of_cluster(s, cluster_offset + offset_in_cluster), | 46 | - * Limit it to 512M, which is 16PB for default cluster and L2 table |
55 | + src_cluster_offset + offset_in_cluster, | 47 | - * size */ |
56 | + buffer, bytes) < 0) { | 48 | + * Limit it to 512M, which is: |
57 | return false; | 49 | + * 16PB - for default "Hosted Sparse Extent" (VMDK4) |
58 | } | 50 | + * cluster size: 64KB, L2 table size: 512 entries |
51 | + * 1PB - for default "ESXi Host Sparse Extent" (VMDK3/vmfsSparse) | ||
52 | + * cluster size: 512B, L2 table size: 4096 entries | ||
53 | + */ | ||
54 | error_setg(errp, "L1 size too big"); | ||
55 | return -EFBIG; | ||
59 | } | 56 | } |
60 | -- | 57 | -- |
61 | 2.21.0 | 58 | 2.21.0 |
62 | 59 | ||
63 | 60 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | The check script is already printing out which iotest is currently | 3 | 512M of L1 entries is a very loose bound, only 32M are required to store |
4 | running, so printing out the name of the check-block.sh shell script | 4 | the maximal supported VMDK file size of 2TB. |
5 | looks superfluous here. | ||
6 | 5 | ||
7 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 6 | Fixed qemu-iotest 59# - now failure occures before on impossible L1 |
8 | Message-id: 20190906113534.10907-1-thuth@redhat.com | 7 | table size. |
9 | Acked-by: John Snow <jsnow@redhat.com> | 8 | |
9 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> | ||
10 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> | ||
11 | Reviewed-by: Liran Alon <liran.alon@oracle.com> | ||
12 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> | ||
13 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | ||
14 | Message-id: 20190620091057.47441-3-shmuel.eiderman@oracle.com | ||
10 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 15 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 16 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
12 | --- | 17 | --- |
13 | tests/Makefile.include | 2 +- | 18 | block/vmdk.c | 13 +++++++------ |
14 | 1 file changed, 1 insertion(+), 1 deletion(-) | 19 | tests/qemu-iotests/059.out | 2 +- |
20 | 2 files changed, 8 insertions(+), 7 deletions(-) | ||
15 | 21 | ||
16 | diff --git a/tests/Makefile.include b/tests/Makefile.include | 22 | diff --git a/block/vmdk.c b/block/vmdk.c |
17 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/Makefile.include | 24 | --- a/block/vmdk.c |
19 | +++ b/tests/Makefile.include | 25 | +++ b/block/vmdk.c |
20 | @@ -XXX,XX +XXX,XX @@ QEMU_IOTESTS_HELPERS-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_LINUX)) = tests/qemu | 26 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, |
21 | check-tests/check-block.sh: tests/check-block.sh qemu-img$(EXESUF) \ | 27 | error_setg(errp, "Invalid granularity, image may be corrupt"); |
22 | qemu-io$(EXESUF) qemu-nbd$(EXESUF) $(QEMU_IOTESTS_HELPERS-y) \ | 28 | return -EFBIG; |
23 | $(patsubst %,%/all,$(filter %-softmmu,$(TARGET_DIRS))) | 29 | } |
24 | - $< | 30 | - if (l1_size > 512 * 1024 * 1024) { |
25 | + @$< | 31 | + if (l1_size > 32 * 1024 * 1024) { |
26 | 32 | /* | |
27 | .PHONY: $(patsubst %, check-%, $(check-qapi-schema-y)) | 33 | * Although with big capacity and small l1_entry_sectors, we can get a |
28 | $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json | 34 | * big l1_size, we don't want unbounded value to allocate the table. |
35 | - * Limit it to 512M, which is: | ||
36 | - * 16PB - for default "Hosted Sparse Extent" (VMDK4) | ||
37 | - * cluster size: 64KB, L2 table size: 512 entries | ||
38 | - * 1PB - for default "ESXi Host Sparse Extent" (VMDK3/vmfsSparse) | ||
39 | - * cluster size: 512B, L2 table size: 4096 entries | ||
40 | + * Limit it to 32M, which is enough to store: | ||
41 | + * 8TB - for both VMDK3 & VMDK4 with | ||
42 | + * minimal cluster size: 512B | ||
43 | + * minimal L2 table size: 512 entries | ||
44 | + * 8 TB is still more than the maximal value supported for | ||
45 | + * VMDK3 & VMDK4 which is 2TB. | ||
46 | */ | ||
47 | error_setg(errp, "L1 size too big"); | ||
48 | return -EFBIG; | ||
49 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/tests/qemu-iotests/059.out | ||
52 | +++ b/tests/qemu-iotests/059.out | ||
53 | @@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File | ||
54 | 0x140000000 0x10000 0x50000 TEST_DIR/t-s003.vmdk | ||
55 | |||
56 | === Testing afl image with a very large capacity === | ||
57 | -qemu-img: Can't get image size 'TEST_DIR/afl9.IMGFMT': File too large | ||
58 | +qemu-img: Could not open 'TEST_DIR/afl9.IMGFMT': L1 size too big | ||
59 | *** done | ||
29 | -- | 60 | -- |
30 | 2.21.0 | 61 | 2.21.0 |
31 | 62 | ||
32 | 63 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | A follow-up patch will make curl_multi_do() and curl_multi_read() take a | ||
2 | CURLSocket instead of the CURLState. They still need the latter, | ||
3 | though, so add a pointer to it to the former. | ||
4 | 1 | ||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Message-id: 20190910124136.10565-2-mreitz@redhat.com | ||
9 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | block/curl.c | 3 +++ | ||
13 | 1 file changed, 3 insertions(+) | ||
14 | |||
15 | diff --git a/block/curl.c b/block/curl.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/curl.c | ||
18 | +++ b/block/curl.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle, | ||
20 | #define CURL_BLOCK_OPT_TIMEOUT_DEFAULT 5 | ||
21 | |||
22 | struct BDRVCURLState; | ||
23 | +struct CURLState; | ||
24 | |||
25 | static bool libcurl_initialized; | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ typedef struct CURLAIOCB { | ||
28 | |||
29 | typedef struct CURLSocket { | ||
30 | int fd; | ||
31 | + struct CURLState *state; | ||
32 | QLIST_ENTRY(CURLSocket) next; | ||
33 | } CURLSocket; | ||
34 | |||
35 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | ||
36 | if (!socket) { | ||
37 | socket = g_new0(CURLSocket, 1); | ||
38 | socket->fd = fd; | ||
39 | + socket->state = state; | ||
40 | QLIST_INSERT_HEAD(&state->sockets, socket, next); | ||
41 | } | ||
42 | socket = NULL; | ||
43 | -- | ||
44 | 2.21.0 | ||
45 | |||
46 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | This does not really change anything, but it makes the code a bit easier | ||
2 | to follow once we use @socket as the opaque pointer for | ||
3 | aio_set_fd_handler(). | ||
4 | 1 | ||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Message-id: 20190910124136.10565-3-mreitz@redhat.com | ||
8 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | block/curl.c | 10 +++++----- | ||
13 | 1 file changed, 5 insertions(+), 5 deletions(-) | ||
14 | |||
15 | diff --git a/block/curl.c b/block/curl.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/curl.c | ||
18 | +++ b/block/curl.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | ||
20 | |||
21 | QLIST_FOREACH(socket, &state->sockets, next) { | ||
22 | if (socket->fd == fd) { | ||
23 | - if (action == CURL_POLL_REMOVE) { | ||
24 | - QLIST_REMOVE(socket, next); | ||
25 | - g_free(socket); | ||
26 | - } | ||
27 | break; | ||
28 | } | ||
29 | } | ||
30 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | ||
31 | socket->state = state; | ||
32 | QLIST_INSERT_HEAD(&state->sockets, socket, next); | ||
33 | } | ||
34 | - socket = NULL; | ||
35 | |||
36 | trace_curl_sock_cb(action, (int)fd); | ||
37 | switch (action) { | ||
38 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | ||
39 | break; | ||
40 | } | ||
41 | |||
42 | + if (action == CURL_POLL_REMOVE) { | ||
43 | + QLIST_REMOVE(socket, next); | ||
44 | + g_free(socket); | ||
45 | + } | ||
46 | + | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | -- | ||
51 | 2.21.0 | ||
52 | |||
53 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | While it is more likely that transfers complete after some file | ||
2 | descriptor has data ready to read, we probably should not rely on it. | ||
3 | Better be safe than sorry and call curl_multi_check_completion() in | ||
4 | curl_multi_do(), too, just like it is done in curl_multi_read(). | ||
5 | 1 | ||
6 | With this change, curl_multi_do() and curl_multi_read() are actually the | ||
7 | same, so drop curl_multi_read() and use curl_multi_do() as the sole FD | ||
8 | handler. | ||
9 | |||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | Message-id: 20190910124136.10565-4-mreitz@redhat.com | ||
12 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
13 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | --- | ||
16 | block/curl.c | 14 ++------------ | ||
17 | 1 file changed, 2 insertions(+), 12 deletions(-) | ||
18 | |||
19 | diff --git a/block/curl.c b/block/curl.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/curl.c | ||
22 | +++ b/block/curl.c | ||
23 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVCURLState { | ||
24 | |||
25 | static void curl_clean_state(CURLState *s); | ||
26 | static void curl_multi_do(void *arg); | ||
27 | -static void curl_multi_read(void *arg); | ||
28 | |||
29 | #ifdef NEED_CURL_TIMER_CALLBACK | ||
30 | /* Called from curl_multi_do_locked, with s->mutex held. */ | ||
31 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | ||
32 | switch (action) { | ||
33 | case CURL_POLL_IN: | ||
34 | aio_set_fd_handler(s->aio_context, fd, false, | ||
35 | - curl_multi_read, NULL, NULL, state); | ||
36 | + curl_multi_do, NULL, NULL, state); | ||
37 | break; | ||
38 | case CURL_POLL_OUT: | ||
39 | aio_set_fd_handler(s->aio_context, fd, false, | ||
40 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | ||
41 | break; | ||
42 | case CURL_POLL_INOUT: | ||
43 | aio_set_fd_handler(s->aio_context, fd, false, | ||
44 | - curl_multi_read, curl_multi_do, NULL, state); | ||
45 | + curl_multi_do, curl_multi_do, NULL, state); | ||
46 | break; | ||
47 | case CURL_POLL_REMOVE: | ||
48 | aio_set_fd_handler(s->aio_context, fd, false, | ||
49 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_do(void *arg) | ||
50 | { | ||
51 | CURLState *s = (CURLState *)arg; | ||
52 | |||
53 | - qemu_mutex_lock(&s->s->mutex); | ||
54 | - curl_multi_do_locked(s); | ||
55 | - qemu_mutex_unlock(&s->s->mutex); | ||
56 | -} | ||
57 | - | ||
58 | -static void curl_multi_read(void *arg) | ||
59 | -{ | ||
60 | - CURLState *s = (CURLState *)arg; | ||
61 | - | ||
62 | qemu_mutex_lock(&s->s->mutex); | ||
63 | curl_multi_do_locked(s); | ||
64 | curl_multi_check_completion(s->s); | ||
65 | -- | ||
66 | 2.21.0 | ||
67 | |||
68 | diff view generated by jsdifflib |
1 | From: Maxim Levitsky <mlevitsk@redhat.com> | 1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | * Change the qcow2_co_{encrypt|decrypt} to just receive full host and | 3 | Until ESXi 6.5 VMware used the vmfsSparse format for snapshots (VMDK3 in |
4 | guest offsets and use this function directly instead of calling | 4 | QEMU). |
5 | do_perform_cow_encrypt (which is removed by that patch). | 5 | |
6 | 6 | This format was lacking in the following: | |
7 | * Adjust qcow2_co_encdec to take full host and guest offsets as well. | 7 | |
8 | 8 | * Grain directory (L1) and grain table (L2) entries were 32-bit, | |
9 | * Document the qcow2_co_{encrypt|decrypt} arguments | 9 | allowing access to only 2TB (slightly less) of data. |
10 | to prevent the bug fixed in former commit from hopefully | 10 | * The grain size (default) was 512 bytes - leading to data |
11 | happening again. | 11 | fragmentation and many grain tables. |
12 | 12 | * For space reclamation purposes, it was necessary to find all the | |
13 | Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> | 13 | grains which are not pointed to by any grain table - so a reverse |
14 | Message-id: 20190915203655.21638-3-mlevitsk@redhat.com | 14 | mapping of "offset of grain in vmdk" to "grain table" must be |
15 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 15 | constructed - which takes large amounts of CPU/RAM. |
16 | [mreitz: Let perform_cow() return the error value returned by | 16 | |
17 | qcow2_co_encrypt(), as proposed by Vladimir] | 17 | The format specification can be found in VMware's documentation: |
18 | https://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf | ||
19 | |||
20 | In ESXi 6.5, to support snapshot files larger than 2TB, a new format was | ||
21 | introduced: SESparse (Space Efficient). | ||
22 | |||
23 | This format fixes the above issues: | ||
24 | |||
25 | * All entries are now 64-bit. | ||
26 | * The grain size (default) is 4KB. | ||
27 | * Grain directory and grain tables are now located at the beginning | ||
28 | of the file. | ||
29 | + seSparse format reserves space for all grain tables. | ||
30 | + Grain tables can be addressed using an index. | ||
31 | + Grains are located in the end of the file and can also be | ||
32 | addressed with an index. | ||
33 | - seSparse vmdks of large disks (64TB) have huge preallocated | ||
34 | headers - mainly due to L2 tables, even for empty snapshots. | ||
35 | * The header contains a reverse mapping ("backmap") of "offset of | ||
36 | grain in vmdk" to "grain table" and a bitmap ("free bitmap") which | ||
37 | specifies for each grain - whether it is allocated or not. | ||
38 | Using these data structures we can implement space reclamation | ||
39 | efficiently. | ||
40 | * Due to the fact that the header now maintains two mappings: | ||
41 | * The regular one (grain directory & grain tables) | ||
42 | * A reverse one (backmap and free bitmap) | ||
43 | These data structures can lose consistency upon crash and result | ||
44 | in a corrupted VMDK. | ||
45 | Therefore, a journal is also added to the VMDK and is replayed | ||
46 | when the VMware reopens the file after a crash. | ||
47 | |||
48 | Since ESXi 6.7 - SESparse is the only snapshot format available. | ||
49 | |||
50 | Unfortunately, VMware does not provide documentation regarding the new | ||
51 | seSparse format. | ||
52 | |||
53 | This commit is based on black-box research of the seSparse format. | ||
54 | Various in-guest block operations and their effect on the snapshot file | ||
55 | were tested. | ||
56 | |||
57 | The only VMware provided source of information (regarding the underlying | ||
58 | implementation) was a log file on the ESXi: | ||
59 | |||
60 | /var/log/hostd.log | ||
61 | |||
62 | Whenever an seSparse snapshot is created - the log is being populated | ||
63 | with seSparse records. | ||
64 | |||
65 | Relevant log records are of the form: | ||
66 | |||
67 | [...] Const Header: | ||
68 | [...] constMagic = 0xcafebabe | ||
69 | [...] version = 2.1 | ||
70 | [...] capacity = 204800 | ||
71 | [...] grainSize = 8 | ||
72 | [...] grainTableSize = 64 | ||
73 | [...] flags = 0 | ||
74 | [...] Extents: | ||
75 | [...] Header : <1 : 1> | ||
76 | [...] JournalHdr : <2 : 2> | ||
77 | [...] Journal : <2048 : 2048> | ||
78 | [...] GrainDirectory : <4096 : 2048> | ||
79 | [...] GrainTables : <6144 : 2048> | ||
80 | [...] FreeBitmap : <8192 : 2048> | ||
81 | [...] BackMap : <10240 : 2048> | ||
82 | [...] Grain : <12288 : 204800> | ||
83 | [...] Volatile Header: | ||
84 | [...] volatileMagic = 0xcafecafe | ||
85 | [...] FreeGTNumber = 0 | ||
86 | [...] nextTxnSeqNumber = 0 | ||
87 | [...] replayJournal = 0 | ||
88 | |||
89 | The sizes that are seen in the log file are in sectors. | ||
90 | Extents are of the following format: <offset : size> | ||
91 | |||
92 | This commit is a strict implementation which enforces: | ||
93 | * magics | ||
94 | * version number 2.1 | ||
95 | * grain size of 8 sectors (4KB) | ||
96 | * grain table size of 64 sectors | ||
97 | * zero flags | ||
98 | * extent locations | ||
99 | |||
100 | Additionally, this commit proivdes only a subset of the functionality | ||
101 | offered by seSparse's format: | ||
102 | * Read-only | ||
103 | * No journal replay | ||
104 | * No space reclamation | ||
105 | * No unmap support | ||
106 | |||
107 | Hence, journal header, journal, free bitmap and backmap extents are | ||
108 | unused, only the "classic" (L1 -> L2 -> data) grain access is | ||
109 | implemented. | ||
110 | |||
111 | However there are several differences in the grain access itself. | ||
112 | Grain directory (L1): | ||
113 | * Grain directory entries are indexes (not offsets) to grain | ||
114 | tables. | ||
115 | * Valid grain directory entries have their highest nibble set to | ||
116 | 0x1. | ||
117 | * Since grain tables are always located in the beginning of the | ||
118 | file - the index can fit into 32 bits - so we can use its low | ||
119 | part if it's valid. | ||
120 | Grain table (L2): | ||
121 | * Grain table entries are indexes (not offsets) to grains. | ||
122 | * If the highest nibble of the entry is: | ||
123 | 0x0: | ||
124 | The grain in not allocated. | ||
125 | The rest of the bytes are 0. | ||
126 | 0x1: | ||
127 | The grain is unmapped - guest sees a zero grain. | ||
128 | The rest of the bits point to the previously mapped grain, | ||
129 | see 0x3 case. | ||
130 | 0x2: | ||
131 | The grain is zero. | ||
132 | 0x3: | ||
133 | The grain is allocated - to get the index calculate: | ||
134 | ((entry & 0x0fff000000000000) >> 48) | | ||
135 | ((entry & 0x0000ffffffffffff) << 12) | ||
136 | * The difference between 0x1 and 0x2 is that 0x1 is an unallocated | ||
137 | grain which results from the guest using sg_unmap to unmap the | ||
138 | grain - but the grain itself still exists in the grain extent - a | ||
139 | space reclamation procedure should delete it. | ||
140 | Unmapping a zero grain has no effect (0x2 will not change to 0x1) | ||
141 | but unmapping an unallocated grain will (0x0 to 0x1) - naturally. | ||
142 | |||
143 | In order to implement seSparse some fields had to be changed to support | ||
144 | both 32-bit and 64-bit entry sizes. | ||
145 | |||
146 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> | ||
147 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> | ||
148 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> | ||
149 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | ||
150 | Message-id: 20190620091057.47441-4-shmuel.eiderman@oracle.com | ||
18 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 151 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
19 | --- | 152 | --- |
20 | block/qcow2.h | 8 +++--- | 153 | block/vmdk.c | 358 ++++++++++++++++++++++++++++++++++++++++++++++++--- |
21 | block/qcow2-cluster.c | 41 +++++++++------------------- | 154 | 1 file changed, 342 insertions(+), 16 deletions(-) |
22 | block/qcow2-threads.c | 63 +++++++++++++++++++++++++++++++++---------- | 155 | |
23 | block/qcow2.c | 5 ++-- | 156 | diff --git a/block/vmdk.c b/block/vmdk.c |
24 | 4 files changed, 69 insertions(+), 48 deletions(-) | ||
25 | |||
26 | diff --git a/block/qcow2.h b/block/qcow2.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | 157 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/block/qcow2.h | 158 | --- a/block/vmdk.c |
29 | +++ b/block/qcow2.h | 159 | +++ b/block/vmdk.c |
30 | @@ -XXX,XX +XXX,XX @@ ssize_t coroutine_fn | 160 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
31 | qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size, | 161 | uint16_t compressAlgorithm; |
32 | const void *src, size_t src_size); | 162 | } QEMU_PACKED VMDK4Header; |
33 | int coroutine_fn | 163 | |
34 | -qcow2_co_encrypt(BlockDriverState *bs, uint64_t file_cluster_offset, | 164 | +typedef struct VMDKSESparseConstHeader { |
35 | - uint64_t offset, void *buf, size_t len); | 165 | + uint64_t magic; |
36 | +qcow2_co_encrypt(BlockDriverState *bs, uint64_t host_offset, | 166 | + uint64_t version; |
37 | + uint64_t guest_offset, void *buf, size_t len); | 167 | + uint64_t capacity; |
38 | int coroutine_fn | 168 | + uint64_t grain_size; |
39 | -qcow2_co_decrypt(BlockDriverState *bs, uint64_t file_cluster_offset, | 169 | + uint64_t grain_table_size; |
40 | - uint64_t offset, void *buf, size_t len); | 170 | + uint64_t flags; |
41 | +qcow2_co_decrypt(BlockDriverState *bs, uint64_t host_offset, | 171 | + uint64_t reserved1; |
42 | + uint64_t guest_offset, void *buf, size_t len); | 172 | + uint64_t reserved2; |
43 | 173 | + uint64_t reserved3; | |
44 | #endif | 174 | + uint64_t reserved4; |
45 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c | 175 | + uint64_t volatile_header_offset; |
46 | index XXXXXXX..XXXXXXX 100644 | 176 | + uint64_t volatile_header_size; |
47 | --- a/block/qcow2-cluster.c | 177 | + uint64_t journal_header_offset; |
48 | +++ b/block/qcow2-cluster.c | 178 | + uint64_t journal_header_size; |
49 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, | 179 | + uint64_t journal_offset; |
180 | + uint64_t journal_size; | ||
181 | + uint64_t grain_dir_offset; | ||
182 | + uint64_t grain_dir_size; | ||
183 | + uint64_t grain_tables_offset; | ||
184 | + uint64_t grain_tables_size; | ||
185 | + uint64_t free_bitmap_offset; | ||
186 | + uint64_t free_bitmap_size; | ||
187 | + uint64_t backmap_offset; | ||
188 | + uint64_t backmap_size; | ||
189 | + uint64_t grains_offset; | ||
190 | + uint64_t grains_size; | ||
191 | + uint8_t pad[304]; | ||
192 | +} QEMU_PACKED VMDKSESparseConstHeader; | ||
193 | + | ||
194 | +typedef struct VMDKSESparseVolatileHeader { | ||
195 | + uint64_t magic; | ||
196 | + uint64_t free_gt_number; | ||
197 | + uint64_t next_txn_seq_number; | ||
198 | + uint64_t replay_journal; | ||
199 | + uint8_t pad[480]; | ||
200 | +} QEMU_PACKED VMDKSESparseVolatileHeader; | ||
201 | + | ||
202 | #define L2_CACHE_SIZE 16 | ||
203 | |||
204 | typedef struct VmdkExtent { | ||
205 | @@ -XXX,XX +XXX,XX @@ typedef struct VmdkExtent { | ||
206 | bool compressed; | ||
207 | bool has_marker; | ||
208 | bool has_zero_grain; | ||
209 | + bool sesparse; | ||
210 | + uint64_t sesparse_l2_tables_offset; | ||
211 | + uint64_t sesparse_clusters_offset; | ||
212 | + int32_t entry_size; | ||
213 | int version; | ||
214 | int64_t sectors; | ||
215 | int64_t end_sector; | ||
216 | int64_t flat_start_offset; | ||
217 | int64_t l1_table_offset; | ||
218 | int64_t l1_backup_table_offset; | ||
219 | - uint32_t *l1_table; | ||
220 | + void *l1_table; | ||
221 | uint32_t *l1_backup_table; | ||
222 | unsigned int l1_size; | ||
223 | uint32_t l1_entry_sectors; | ||
224 | |||
225 | unsigned int l2_size; | ||
226 | - uint32_t *l2_cache; | ||
227 | + void *l2_cache; | ||
228 | uint32_t l2_cache_offsets[L2_CACHE_SIZE]; | ||
229 | uint32_t l2_cache_counts[L2_CACHE_SIZE]; | ||
230 | |||
231 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, | ||
232 | * minimal L2 table size: 512 entries | ||
233 | * 8 TB is still more than the maximal value supported for | ||
234 | * VMDK3 & VMDK4 which is 2TB. | ||
235 | + * 64TB - for "ESXi seSparse Extent" | ||
236 | + * minimal cluster size: 512B (default is 4KB) | ||
237 | + * L2 table size: 4096 entries (const). | ||
238 | + * 64TB is more than the maximal value supported for | ||
239 | + * seSparse VMDKs (which is slightly less than 64TB) | ||
240 | */ | ||
241 | error_setg(errp, "L1 size too big"); | ||
242 | return -EFBIG; | ||
243 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, | ||
244 | extent->l2_size = l2_size; | ||
245 | extent->cluster_sectors = flat ? sectors : cluster_sectors; | ||
246 | extent->next_cluster_sector = ROUND_UP(nb_sectors, cluster_sectors); | ||
247 | + extent->entry_size = sizeof(uint32_t); | ||
248 | |||
249 | if (s->num_extents > 1) { | ||
250 | extent->end_sector = (*(extent - 1)).end_sector + extent->sectors; | ||
251 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
252 | int i; | ||
253 | |||
254 | /* read the L1 table */ | ||
255 | - l1_size = extent->l1_size * sizeof(uint32_t); | ||
256 | + l1_size = extent->l1_size * extent->entry_size; | ||
257 | extent->l1_table = g_try_malloc(l1_size); | ||
258 | if (l1_size && extent->l1_table == NULL) { | ||
259 | return -ENOMEM; | ||
260 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
261 | goto fail_l1; | ||
262 | } | ||
263 | for (i = 0; i < extent->l1_size; i++) { | ||
264 | - le32_to_cpus(&extent->l1_table[i]); | ||
265 | + if (extent->entry_size == sizeof(uint64_t)) { | ||
266 | + le64_to_cpus((uint64_t *)extent->l1_table + i); | ||
267 | + } else { | ||
268 | + assert(extent->entry_size == sizeof(uint32_t)); | ||
269 | + le32_to_cpus((uint32_t *)extent->l1_table + i); | ||
270 | + } | ||
271 | } | ||
272 | |||
273 | if (extent->l1_backup_table_offset) { | ||
274 | + assert(!extent->sesparse); | ||
275 | extent->l1_backup_table = g_try_malloc(l1_size); | ||
276 | if (l1_size && extent->l1_backup_table == NULL) { | ||
277 | ret = -ENOMEM; | ||
278 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
279 | } | ||
280 | |||
281 | extent->l2_cache = | ||
282 | - g_new(uint32_t, extent->l2_size * L2_CACHE_SIZE); | ||
283 | + g_malloc(extent->entry_size * extent->l2_size * L2_CACHE_SIZE); | ||
50 | return 0; | 284 | return 0; |
285 | fail_l1b: | ||
286 | g_free(extent->l1_backup_table); | ||
287 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, | ||
288 | return ret; | ||
51 | } | 289 | } |
52 | 290 | ||
53 | -static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs, | 291 | +#define SESPARSE_CONST_HEADER_MAGIC UINT64_C(0x00000000cafebabe) |
54 | - uint64_t src_cluster_offset, | 292 | +#define SESPARSE_VOLATILE_HEADER_MAGIC UINT64_C(0x00000000cafecafe) |
55 | - uint64_t cluster_offset, | 293 | + |
56 | - unsigned offset_in_cluster, | 294 | +/* Strict checks - format not officially documented */ |
57 | - uint8_t *buffer, | 295 | +static int check_se_sparse_const_header(VMDKSESparseConstHeader *header, |
58 | - unsigned bytes) | 296 | + Error **errp) |
59 | -{ | 297 | +{ |
60 | - if (bytes && bs->encrypted) { | 298 | + header->magic = le64_to_cpu(header->magic); |
61 | - BDRVQcow2State *s = bs->opaque; | 299 | + header->version = le64_to_cpu(header->version); |
62 | - assert(QEMU_IS_ALIGNED(offset_in_cluster, BDRV_SECTOR_SIZE)); | 300 | + header->grain_size = le64_to_cpu(header->grain_size); |
63 | - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); | 301 | + header->grain_table_size = le64_to_cpu(header->grain_table_size); |
64 | - assert(s->crypto); | 302 | + header->flags = le64_to_cpu(header->flags); |
65 | - if (qcow2_co_encrypt(bs, | 303 | + header->reserved1 = le64_to_cpu(header->reserved1); |
66 | - start_of_cluster(s, cluster_offset + offset_in_cluster), | 304 | + header->reserved2 = le64_to_cpu(header->reserved2); |
67 | - src_cluster_offset + offset_in_cluster, | 305 | + header->reserved3 = le64_to_cpu(header->reserved3); |
68 | - buffer, bytes) < 0) { | 306 | + header->reserved4 = le64_to_cpu(header->reserved4); |
69 | - return false; | 307 | + |
70 | - } | 308 | + header->volatile_header_offset = |
71 | - } | 309 | + le64_to_cpu(header->volatile_header_offset); |
72 | - return true; | 310 | + header->volatile_header_size = le64_to_cpu(header->volatile_header_size); |
73 | -} | 311 | + |
74 | - | 312 | + header->journal_header_offset = le64_to_cpu(header->journal_header_offset); |
75 | static int coroutine_fn do_perform_cow_write(BlockDriverState *bs, | 313 | + header->journal_header_size = le64_to_cpu(header->journal_header_size); |
76 | uint64_t cluster_offset, | 314 | + |
77 | unsigned offset_in_cluster, | 315 | + header->journal_offset = le64_to_cpu(header->journal_offset); |
78 | @@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m) | 316 | + header->journal_size = le64_to_cpu(header->journal_size); |
79 | 317 | + | |
80 | /* Encrypt the data if necessary before writing it */ | 318 | + header->grain_dir_offset = le64_to_cpu(header->grain_dir_offset); |
81 | if (bs->encrypted) { | 319 | + header->grain_dir_size = le64_to_cpu(header->grain_dir_size); |
82 | - if (!do_perform_cow_encrypt(bs, m->offset, m->alloc_offset, | 320 | + |
83 | - start->offset, start_buffer, | 321 | + header->grain_tables_offset = le64_to_cpu(header->grain_tables_offset); |
84 | - start->nb_bytes) || | 322 | + header->grain_tables_size = le64_to_cpu(header->grain_tables_size); |
85 | - !do_perform_cow_encrypt(bs, m->offset, m->alloc_offset, | 323 | + |
86 | - end->offset, end_buffer, end->nb_bytes)) { | 324 | + header->free_bitmap_offset = le64_to_cpu(header->free_bitmap_offset); |
87 | - ret = -EIO; | 325 | + header->free_bitmap_size = le64_to_cpu(header->free_bitmap_size); |
88 | + ret = qcow2_co_encrypt(bs, | 326 | + |
89 | + m->alloc_offset + start->offset, | 327 | + header->backmap_offset = le64_to_cpu(header->backmap_offset); |
90 | + m->offset + start->offset, | 328 | + header->backmap_size = le64_to_cpu(header->backmap_size); |
91 | + start_buffer, start->nb_bytes); | 329 | + |
92 | + if (ret < 0) { | 330 | + header->grains_offset = le64_to_cpu(header->grains_offset); |
93 | + goto fail; | 331 | + header->grains_size = le64_to_cpu(header->grains_size); |
332 | + | ||
333 | + if (header->magic != SESPARSE_CONST_HEADER_MAGIC) { | ||
334 | + error_setg(errp, "Bad const header magic: 0x%016" PRIx64, | ||
335 | + header->magic); | ||
336 | + return -EINVAL; | ||
337 | + } | ||
338 | + | ||
339 | + if (header->version != 0x0000000200000001) { | ||
340 | + error_setg(errp, "Unsupported version: 0x%016" PRIx64, | ||
341 | + header->version); | ||
342 | + return -ENOTSUP; | ||
343 | + } | ||
344 | + | ||
345 | + if (header->grain_size != 8) { | ||
346 | + error_setg(errp, "Unsupported grain size: %" PRIu64, | ||
347 | + header->grain_size); | ||
348 | + return -ENOTSUP; | ||
349 | + } | ||
350 | + | ||
351 | + if (header->grain_table_size != 64) { | ||
352 | + error_setg(errp, "Unsupported grain table size: %" PRIu64, | ||
353 | + header->grain_table_size); | ||
354 | + return -ENOTSUP; | ||
355 | + } | ||
356 | + | ||
357 | + if (header->flags != 0) { | ||
358 | + error_setg(errp, "Unsupported flags: 0x%016" PRIx64, | ||
359 | + header->flags); | ||
360 | + return -ENOTSUP; | ||
361 | + } | ||
362 | + | ||
363 | + if (header->reserved1 != 0 || header->reserved2 != 0 || | ||
364 | + header->reserved3 != 0 || header->reserved4 != 0) { | ||
365 | + error_setg(errp, "Unsupported reserved bits:" | ||
366 | + " 0x%016" PRIx64 " 0x%016" PRIx64 | ||
367 | + " 0x%016" PRIx64 " 0x%016" PRIx64, | ||
368 | + header->reserved1, header->reserved2, | ||
369 | + header->reserved3, header->reserved4); | ||
370 | + return -ENOTSUP; | ||
371 | + } | ||
372 | + | ||
373 | + /* check that padding is 0 */ | ||
374 | + if (!buffer_is_zero(header->pad, sizeof(header->pad))) { | ||
375 | + error_setg(errp, "Unsupported non-zero const header padding"); | ||
376 | + return -ENOTSUP; | ||
377 | + } | ||
378 | + | ||
379 | + return 0; | ||
380 | +} | ||
381 | + | ||
382 | +static int check_se_sparse_volatile_header(VMDKSESparseVolatileHeader *header, | ||
383 | + Error **errp) | ||
384 | +{ | ||
385 | + header->magic = le64_to_cpu(header->magic); | ||
386 | + header->free_gt_number = le64_to_cpu(header->free_gt_number); | ||
387 | + header->next_txn_seq_number = le64_to_cpu(header->next_txn_seq_number); | ||
388 | + header->replay_journal = le64_to_cpu(header->replay_journal); | ||
389 | + | ||
390 | + if (header->magic != SESPARSE_VOLATILE_HEADER_MAGIC) { | ||
391 | + error_setg(errp, "Bad volatile header magic: 0x%016" PRIx64, | ||
392 | + header->magic); | ||
393 | + return -EINVAL; | ||
394 | + } | ||
395 | + | ||
396 | + if (header->replay_journal) { | ||
397 | + error_setg(errp, "Image is dirty, Replaying journal not supported"); | ||
398 | + return -ENOTSUP; | ||
399 | + } | ||
400 | + | ||
401 | + /* check that padding is 0 */ | ||
402 | + if (!buffer_is_zero(header->pad, sizeof(header->pad))) { | ||
403 | + error_setg(errp, "Unsupported non-zero volatile header padding"); | ||
404 | + return -ENOTSUP; | ||
405 | + } | ||
406 | + | ||
407 | + return 0; | ||
408 | +} | ||
409 | + | ||
410 | +static int vmdk_open_se_sparse(BlockDriverState *bs, | ||
411 | + BdrvChild *file, | ||
412 | + int flags, Error **errp) | ||
413 | +{ | ||
414 | + int ret; | ||
415 | + VMDKSESparseConstHeader const_header; | ||
416 | + VMDKSESparseVolatileHeader volatile_header; | ||
417 | + VmdkExtent *extent; | ||
418 | + | ||
419 | + ret = bdrv_apply_auto_read_only(bs, | ||
420 | + "No write support for seSparse images available", errp); | ||
421 | + if (ret < 0) { | ||
422 | + return ret; | ||
423 | + } | ||
424 | + | ||
425 | + assert(sizeof(const_header) == SECTOR_SIZE); | ||
426 | + | ||
427 | + ret = bdrv_pread(file, 0, &const_header, sizeof(const_header)); | ||
428 | + if (ret < 0) { | ||
429 | + bdrv_refresh_filename(file->bs); | ||
430 | + error_setg_errno(errp, -ret, | ||
431 | + "Could not read const header from file '%s'", | ||
432 | + file->bs->filename); | ||
433 | + return ret; | ||
434 | + } | ||
435 | + | ||
436 | + /* check const header */ | ||
437 | + ret = check_se_sparse_const_header(&const_header, errp); | ||
438 | + if (ret < 0) { | ||
439 | + return ret; | ||
440 | + } | ||
441 | + | ||
442 | + assert(sizeof(volatile_header) == SECTOR_SIZE); | ||
443 | + | ||
444 | + ret = bdrv_pread(file, | ||
445 | + const_header.volatile_header_offset * SECTOR_SIZE, | ||
446 | + &volatile_header, sizeof(volatile_header)); | ||
447 | + if (ret < 0) { | ||
448 | + bdrv_refresh_filename(file->bs); | ||
449 | + error_setg_errno(errp, -ret, | ||
450 | + "Could not read volatile header from file '%s'", | ||
451 | + file->bs->filename); | ||
452 | + return ret; | ||
453 | + } | ||
454 | + | ||
455 | + /* check volatile header */ | ||
456 | + ret = check_se_sparse_volatile_header(&volatile_header, errp); | ||
457 | + if (ret < 0) { | ||
458 | + return ret; | ||
459 | + } | ||
460 | + | ||
461 | + ret = vmdk_add_extent(bs, file, false, | ||
462 | + const_header.capacity, | ||
463 | + const_header.grain_dir_offset * SECTOR_SIZE, | ||
464 | + 0, | ||
465 | + const_header.grain_dir_size * | ||
466 | + SECTOR_SIZE / sizeof(uint64_t), | ||
467 | + const_header.grain_table_size * | ||
468 | + SECTOR_SIZE / sizeof(uint64_t), | ||
469 | + const_header.grain_size, | ||
470 | + &extent, | ||
471 | + errp); | ||
472 | + if (ret < 0) { | ||
473 | + return ret; | ||
474 | + } | ||
475 | + | ||
476 | + extent->sesparse = true; | ||
477 | + extent->sesparse_l2_tables_offset = const_header.grain_tables_offset; | ||
478 | + extent->sesparse_clusters_offset = const_header.grains_offset; | ||
479 | + extent->entry_size = sizeof(uint64_t); | ||
480 | + | ||
481 | + ret = vmdk_init_tables(bs, extent, errp); | ||
482 | + if (ret) { | ||
483 | + /* free extent allocated by vmdk_add_extent */ | ||
484 | + vmdk_free_last_extent(bs); | ||
485 | + } | ||
486 | + | ||
487 | + return ret; | ||
488 | +} | ||
489 | + | ||
490 | static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | ||
491 | QDict *options, Error **errp); | ||
492 | |||
493 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
494 | * RW [size in sectors] SPARSE "file-name.vmdk" | ||
495 | * RW [size in sectors] VMFS "file-name.vmdk" | ||
496 | * RW [size in sectors] VMFSSPARSE "file-name.vmdk" | ||
497 | + * RW [size in sectors] SESPARSE "file-name.vmdk" | ||
498 | */ | ||
499 | flat_offset = -1; | ||
500 | matches = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, | ||
501 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
502 | |||
503 | if (sectors <= 0 || | ||
504 | (strcmp(type, "FLAT") && strcmp(type, "SPARSE") && | ||
505 | - strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE")) || | ||
506 | + strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE") && | ||
507 | + strcmp(type, "SESPARSE")) || | ||
508 | (strcmp(access, "RW"))) { | ||
509 | continue; | ||
510 | } | ||
511 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
512 | return ret; | ||
513 | } | ||
514 | extent = &s->extents[s->num_extents - 1]; | ||
515 | + } else if (!strcmp(type, "SESPARSE")) { | ||
516 | + ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp); | ||
517 | + if (ret) { | ||
518 | + bdrv_unref_child(bs, extent_file); | ||
519 | + return ret; | ||
520 | + } | ||
521 | + extent = &s->extents[s->num_extents - 1]; | ||
522 | } else { | ||
523 | error_setg(errp, "Unsupported extent type '%s'", type); | ||
524 | bdrv_unref_child(bs, extent_file); | ||
525 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | ||
526 | if (strcmp(ct, "monolithicFlat") && | ||
527 | strcmp(ct, "vmfs") && | ||
528 | strcmp(ct, "vmfsSparse") && | ||
529 | + strcmp(ct, "seSparse") && | ||
530 | strcmp(ct, "twoGbMaxExtentSparse") && | ||
531 | strcmp(ct, "twoGbMaxExtentFlat")) { | ||
532 | error_setg(errp, "Unsupported image type '%s'", ct); | ||
533 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
534 | { | ||
535 | unsigned int l1_index, l2_offset, l2_index; | ||
536 | int min_index, i, j; | ||
537 | - uint32_t min_count, *l2_table; | ||
538 | + uint32_t min_count; | ||
539 | + void *l2_table; | ||
540 | bool zeroed = false; | ||
541 | int64_t ret; | ||
542 | int64_t cluster_sector; | ||
543 | + unsigned int l2_size_bytes = extent->l2_size * extent->entry_size; | ||
544 | |||
545 | if (m_data) { | ||
546 | m_data->valid = 0; | ||
547 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
548 | if (l1_index >= extent->l1_size) { | ||
549 | return VMDK_ERROR; | ||
550 | } | ||
551 | - l2_offset = extent->l1_table[l1_index]; | ||
552 | + if (extent->sesparse) { | ||
553 | + uint64_t l2_offset_u64; | ||
554 | + | ||
555 | + assert(extent->entry_size == sizeof(uint64_t)); | ||
556 | + | ||
557 | + l2_offset_u64 = ((uint64_t *)extent->l1_table)[l1_index]; | ||
558 | + if (l2_offset_u64 == 0) { | ||
559 | + l2_offset = 0; | ||
560 | + } else if ((l2_offset_u64 & 0xffffffff00000000) != 0x1000000000000000) { | ||
561 | + /* | ||
562 | + * Top most nibble is 0x1 if grain table is allocated. | ||
563 | + * strict check - top most 4 bytes must be 0x10000000 since max | ||
564 | + * supported size is 64TB for disk - so no more than 64TB / 16MB | ||
565 | + * grain directories which is smaller than uint32, | ||
566 | + * where 16MB is the only supported default grain table coverage. | ||
567 | + */ | ||
568 | + return VMDK_ERROR; | ||
569 | + } else { | ||
570 | + l2_offset_u64 = l2_offset_u64 & 0x00000000ffffffff; | ||
571 | + l2_offset_u64 = extent->sesparse_l2_tables_offset + | ||
572 | + l2_offset_u64 * l2_size_bytes / SECTOR_SIZE; | ||
573 | + if (l2_offset_u64 > 0x00000000ffffffff) { | ||
574 | + return VMDK_ERROR; | ||
575 | + } | ||
576 | + l2_offset = (unsigned int)(l2_offset_u64); | ||
94 | + } | 577 | + } |
95 | + | 578 | + } else { |
96 | + ret = qcow2_co_encrypt(bs, | 579 | + assert(extent->entry_size == sizeof(uint32_t)); |
97 | + m->alloc_offset + end->offset, | 580 | + l2_offset = ((uint32_t *)extent->l1_table)[l1_index]; |
98 | + m->offset + end->offset, | 581 | + } |
99 | + end_buffer, end->nb_bytes); | 582 | if (!l2_offset) { |
100 | + if (ret < 0) { | 583 | return VMDK_UNALLOC; |
101 | goto fail; | 584 | } |
585 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
586 | extent->l2_cache_counts[j] >>= 1; | ||
587 | } | ||
588 | } | ||
589 | - l2_table = extent->l2_cache + (i * extent->l2_size); | ||
590 | + l2_table = (char *)extent->l2_cache + (i * l2_size_bytes); | ||
591 | goto found; | ||
102 | } | 592 | } |
103 | } | 593 | } |
104 | diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c | 594 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, |
105 | index XXXXXXX..XXXXXXX 100644 | 595 | min_index = i; |
106 | --- a/block/qcow2-threads.c | 596 | } |
107 | +++ b/block/qcow2-threads.c | 597 | } |
108 | @@ -XXX,XX +XXX,XX @@ static int qcow2_encdec_pool_func(void *opaque) | 598 | - l2_table = extent->l2_cache + (min_index * extent->l2_size); |
109 | } | 599 | + l2_table = (char *)extent->l2_cache + (min_index * l2_size_bytes); |
110 | 600 | BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD); | |
111 | static int coroutine_fn | 601 | if (bdrv_pread(extent->file, |
112 | -qcow2_co_encdec(BlockDriverState *bs, uint64_t file_cluster_offset, | 602 | (int64_t)l2_offset * 512, |
113 | - uint64_t offset, void *buf, size_t len, Qcow2EncDecFunc func) | 603 | l2_table, |
114 | +qcow2_co_encdec(BlockDriverState *bs, uint64_t host_offset, | 604 | - extent->l2_size * sizeof(uint32_t) |
115 | + uint64_t guest_offset, void *buf, size_t len, | 605 | - ) != extent->l2_size * sizeof(uint32_t)) { |
116 | + Qcow2EncDecFunc func) | 606 | + l2_size_bytes |
117 | { | 607 | + ) != l2_size_bytes) { |
118 | BDRVQcow2State *s = bs->opaque; | 608 | return VMDK_ERROR; |
119 | Qcow2EncDecData arg = { | 609 | } |
120 | .block = s->crypto, | 610 | |
121 | - .offset = s->crypt_physical_offset ? | 611 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, |
122 | - file_cluster_offset + offset_into_cluster(s, offset) : | 612 | extent->l2_cache_counts[min_index] = 1; |
123 | - offset, | 613 | found: |
124 | + .offset = s->crypt_physical_offset ? host_offset : guest_offset, | 614 | l2_index = ((offset >> 9) / extent->cluster_sectors) % extent->l2_size; |
125 | .buf = buf, | 615 | - cluster_sector = le32_to_cpu(l2_table[l2_index]); |
126 | .len = len, | 616 | |
127 | .func = func, | 617 | - if (extent->has_zero_grain && cluster_sector == VMDK_GTE_ZEROED) { |
128 | }; | 618 | - zeroed = true; |
129 | 619 | + if (extent->sesparse) { | |
130 | - return qcow2_co_process(bs, qcow2_encdec_pool_func, &arg); | 620 | + cluster_sector = le64_to_cpu(((uint64_t *)l2_table)[l2_index]); |
131 | + assert(QEMU_IS_ALIGNED(guest_offset, BDRV_SECTOR_SIZE)); | 621 | + switch (cluster_sector & 0xf000000000000000) { |
132 | + assert(QEMU_IS_ALIGNED(host_offset, BDRV_SECTOR_SIZE)); | 622 | + case 0x0000000000000000: |
133 | + assert(QEMU_IS_ALIGNED(len, BDRV_SECTOR_SIZE)); | 623 | + /* unallocated grain */ |
134 | + assert(s->crypto); | 624 | + if (cluster_sector != 0) { |
135 | + | 625 | + return VMDK_ERROR; |
136 | + return len == 0 ? 0 : qcow2_co_process(bs, qcow2_encdec_pool_func, &arg); | 626 | + } |
137 | } | 627 | + break; |
138 | 628 | + case 0x1000000000000000: | |
139 | +/* | 629 | + /* scsi-unmapped grain - fallthrough */ |
140 | + * qcow2_co_encrypt() | 630 | + case 0x2000000000000000: |
141 | + * | 631 | + /* zero grain */ |
142 | + * Encrypts one or more contiguous aligned sectors | 632 | + zeroed = true; |
143 | + * | 633 | + break; |
144 | + * @host_offset - underlying storage offset of the first sector of the | 634 | + case 0x3000000000000000: |
145 | + * data to be encrypted | 635 | + /* allocated grain */ |
146 | + * | 636 | + cluster_sector = (((cluster_sector & 0x0fff000000000000) >> 48) | |
147 | + * @guest_offset - guest (virtual) offset of the first sector of the | 637 | + ((cluster_sector & 0x0000ffffffffffff) << 12)); |
148 | + * data to be encrypted | 638 | + cluster_sector = extent->sesparse_clusters_offset + |
149 | + * | 639 | + cluster_sector * extent->cluster_sectors; |
150 | + * @buf - buffer with the data to encrypt, that after encryption | 640 | + break; |
151 | + * will be written to the underlying storage device at | 641 | + default: |
152 | + * @host_offset | 642 | + return VMDK_ERROR; |
153 | + * | 643 | + } |
154 | + * @len - length of the buffer (must be a BDRV_SECTOR_SIZE multiple) | 644 | + } else { |
155 | + * | 645 | + cluster_sector = le32_to_cpu(((uint32_t *)l2_table)[l2_index]); |
156 | + * Depending on the encryption method, @host_offset and/or @guest_offset | 646 | + |
157 | + * may be used for generating the initialization vector for | 647 | + if (extent->has_zero_grain && cluster_sector == VMDK_GTE_ZEROED) { |
158 | + * encryption. | 648 | + zeroed = true; |
159 | + * | 649 | + } |
160 | + * Note that while the whole range must be aligned on sectors, it | 650 | } |
161 | + * does not have to be aligned on clusters and can also cross cluster | 651 | |
162 | + * boundaries | 652 | if (!cluster_sector || zeroed) { |
163 | + */ | 653 | if (!allocate) { |
164 | int coroutine_fn | 654 | return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; |
165 | -qcow2_co_encrypt(BlockDriverState *bs, uint64_t file_cluster_offset, | 655 | } |
166 | - uint64_t offset, void *buf, size_t len) | 656 | + assert(!extent->sesparse); |
167 | +qcow2_co_encrypt(BlockDriverState *bs, uint64_t host_offset, | 657 | |
168 | + uint64_t guest_offset, void *buf, size_t len) | 658 | if (extent->next_cluster_sector >= VMDK_EXTENT_MAX_SECTORS) { |
169 | { | 659 | return VMDK_ERROR; |
170 | - return qcow2_co_encdec(bs, file_cluster_offset, offset, buf, len, | 660 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, |
171 | - qcrypto_block_encrypt); | 661 | m_data->l1_index = l1_index; |
172 | + return qcow2_co_encdec(bs, host_offset, guest_offset, buf, len, | 662 | m_data->l2_index = l2_index; |
173 | + qcrypto_block_encrypt); | 663 | m_data->l2_offset = l2_offset; |
174 | } | 664 | - m_data->l2_cache_entry = &l2_table[l2_index]; |
175 | 665 | + m_data->l2_cache_entry = ((uint32_t *)l2_table) + l2_index; | |
176 | +/* | 666 | } |
177 | + * qcow2_co_decrypt() | 667 | } |
178 | + * | 668 | *cluster_offset = cluster_sector << BDRV_SECTOR_BITS; |
179 | + * Decrypts one or more contiguous aligned sectors | 669 | @@ -XXX,XX +XXX,XX @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, |
180 | + * Similar to qcow2_co_encrypt | 670 | if (!extent) { |
181 | + */ | 671 | return -EIO; |
182 | int coroutine_fn | 672 | } |
183 | -qcow2_co_decrypt(BlockDriverState *bs, uint64_t file_cluster_offset, | 673 | + if (extent->sesparse) { |
184 | - uint64_t offset, void *buf, size_t len) | 674 | + return -ENOTSUP; |
185 | +qcow2_co_decrypt(BlockDriverState *bs, uint64_t host_offset, | 675 | + } |
186 | + uint64_t guest_offset, void *buf, size_t len) | 676 | offset_in_cluster = vmdk_find_offset_in_cluster(extent, offset); |
187 | { | 677 | n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE |
188 | - return qcow2_co_encdec(bs, file_cluster_offset, offset, buf, len, | 678 | - offset_in_cluster); |
189 | - qcrypto_block_decrypt); | ||
190 | + return qcow2_co_encdec(bs, host_offset, guest_offset, buf, len, | ||
191 | + qcrypto_block_decrypt); | ||
192 | } | ||
193 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
194 | index XXXXXXX..XXXXXXX 100644 | ||
195 | --- a/block/qcow2.c | ||
196 | +++ b/block/qcow2.c | ||
197 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, | ||
198 | |||
199 | assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); | ||
200 | assert(QEMU_IS_ALIGNED(cur_bytes, BDRV_SECTOR_SIZE)); | ||
201 | - if (qcow2_co_decrypt(bs, cluster_offset, offset, | ||
202 | + if (qcow2_co_decrypt(bs, cluster_offset + offset_in_cluster, | ||
203 | + offset, | ||
204 | cluster_data, cur_bytes) < 0) { | ||
205 | ret = -EIO; | ||
206 | goto fail; | ||
207 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev_part( | ||
208 | qemu_iovec_to_buf(qiov, qiov_offset + bytes_done, | ||
209 | cluster_data, cur_bytes); | ||
210 | |||
211 | - if (qcow2_co_encrypt(bs, cluster_offset, offset, | ||
212 | + if (qcow2_co_encrypt(bs, cluster_offset + offset_in_cluster, offset, | ||
213 | cluster_data, cur_bytes) < 0) { | ||
214 | ret = -EIO; | ||
215 | goto out_unlocked; | ||
216 | -- | 679 | -- |
217 | 2.21.0 | 680 | 2.21.0 |
218 | 681 | ||
219 | 682 | diff view generated by jsdifflib |
1 | curl_multi_do_locked() currently marks all sockets as ready. That is | 1 | From: Pino Toscano <ptoscano@redhat.com> |
---|---|---|---|
2 | not only inefficient, but in fact unsafe (the loop is). A follow-up | ||
3 | patch will change that, but to do so, curl_multi_do_locked() needs to | ||
4 | know exactly which socket is ready; and that is accomplished by this | ||
5 | patch here. | ||
6 | 2 | ||
7 | Cc: qemu-stable@nongnu.org | 3 | Rewrite the implementation of the ssh block driver to use libssh instead |
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 4 | of libssh2. The libssh library has various advantages over libssh2: |
9 | Message-id: 20190910124136.10565-5-mreitz@redhat.com | 5 | - easier API for authentication (for example for using ssh-agent) |
10 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | 6 | - easier API for known_hosts handling |
11 | Reviewed-by: John Snow <jsnow@redhat.com> | 7 | - supports newer types of keys in known_hosts |
8 | |||
9 | Use APIs/features available in libssh 0.8 conditionally, to support | ||
10 | older versions (which are not recommended though). | ||
11 | |||
12 | Adjust the iotest 207 according to the different error message, and to | ||
13 | find the default key type for localhost (to properly compare the | ||
14 | fingerprint with). | ||
15 | Contributed-by: Max Reitz <mreitz@redhat.com> | ||
16 | |||
17 | Adjust the various Docker/Travis scripts to use libssh when available | ||
18 | instead of libssh2. The mingw/mxe testing is dropped for now, as there | ||
19 | are no packages for it. | ||
20 | |||
21 | Signed-off-by: Pino Toscano <ptoscano@redhat.com> | ||
22 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
23 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
24 | Message-id: 20190620200840.17655-1-ptoscano@redhat.com | ||
25 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
26 | Message-id: 5873173.t2JhDm7DL7@lindworm.usersys.redhat.com | ||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 27 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
13 | --- | 28 | --- |
14 | block/curl.c | 20 +++++++++++--------- | 29 | configure | 65 +- |
15 | 1 file changed, 11 insertions(+), 9 deletions(-) | 30 | block/Makefile.objs | 6 +- |
31 | block/ssh.c | 652 ++++++++++-------- | ||
32 | .travis.yml | 4 +- | ||
33 | block/trace-events | 14 +- | ||
34 | docs/qemu-block-drivers.texi | 2 +- | ||
35 | .../dockerfiles/debian-win32-cross.docker | 1 - | ||
36 | .../dockerfiles/debian-win64-cross.docker | 1 - | ||
37 | tests/docker/dockerfiles/fedora.docker | 4 +- | ||
38 | tests/docker/dockerfiles/ubuntu.docker | 2 +- | ||
39 | tests/docker/dockerfiles/ubuntu1804.docker | 2 +- | ||
40 | tests/qemu-iotests/207 | 54 +- | ||
41 | tests/qemu-iotests/207.out | 2 +- | ||
42 | 13 files changed, 449 insertions(+), 360 deletions(-) | ||
16 | 43 | ||
17 | diff --git a/block/curl.c b/block/curl.c | 44 | diff --git a/configure b/configure |
45 | index XXXXXXX..XXXXXXX 100755 | ||
46 | --- a/configure | ||
47 | +++ b/configure | ||
48 | @@ -XXX,XX +XXX,XX @@ auth_pam="" | ||
49 | vte="" | ||
50 | virglrenderer="" | ||
51 | tpm="" | ||
52 | -libssh2="" | ||
53 | +libssh="" | ||
54 | live_block_migration="yes" | ||
55 | numa="" | ||
56 | tcmalloc="no" | ||
57 | @@ -XXX,XX +XXX,XX @@ for opt do | ||
58 | ;; | ||
59 | --enable-tpm) tpm="yes" | ||
60 | ;; | ||
61 | - --disable-libssh2) libssh2="no" | ||
62 | + --disable-libssh) libssh="no" | ||
63 | ;; | ||
64 | - --enable-libssh2) libssh2="yes" | ||
65 | + --enable-libssh) libssh="yes" | ||
66 | ;; | ||
67 | --disable-live-block-migration) live_block_migration="no" | ||
68 | ;; | ||
69 | @@ -XXX,XX +XXX,XX @@ disabled with --disable-FEATURE, default is enabled if available: | ||
70 | coroutine-pool coroutine freelist (better performance) | ||
71 | glusterfs GlusterFS backend | ||
72 | tpm TPM support | ||
73 | - libssh2 ssh block device support | ||
74 | + libssh ssh block device support | ||
75 | numa libnuma support | ||
76 | libxml2 for Parallels image format | ||
77 | tcmalloc tcmalloc support | ||
78 | @@ -XXX,XX +XXX,XX @@ EOF | ||
79 | fi | ||
80 | |||
81 | ########################################## | ||
82 | -# libssh2 probe | ||
83 | -min_libssh2_version=1.2.8 | ||
84 | -if test "$libssh2" != "no" ; then | ||
85 | - if $pkg_config --atleast-version=$min_libssh2_version libssh2; then | ||
86 | - libssh2_cflags=$($pkg_config libssh2 --cflags) | ||
87 | - libssh2_libs=$($pkg_config libssh2 --libs) | ||
88 | - libssh2=yes | ||
89 | +# libssh probe | ||
90 | +if test "$libssh" != "no" ; then | ||
91 | + if $pkg_config --exists libssh; then | ||
92 | + libssh_cflags=$($pkg_config libssh --cflags) | ||
93 | + libssh_libs=$($pkg_config libssh --libs) | ||
94 | + libssh=yes | ||
95 | else | ||
96 | - if test "$libssh2" = "yes" ; then | ||
97 | - error_exit "libssh2 >= $min_libssh2_version required for --enable-libssh2" | ||
98 | + if test "$libssh" = "yes" ; then | ||
99 | + error_exit "libssh required for --enable-libssh" | ||
100 | fi | ||
101 | - libssh2=no | ||
102 | + libssh=no | ||
103 | fi | ||
104 | fi | ||
105 | |||
106 | ########################################## | ||
107 | -# libssh2_sftp_fsync probe | ||
108 | +# Check for libssh 0.8 | ||
109 | +# This is done like this instead of using the LIBSSH_VERSION_* and | ||
110 | +# SSH_VERSION_* macros because some distributions in the past shipped | ||
111 | +# snapshots of the future 0.8 from Git, and those snapshots did not | ||
112 | +# have updated version numbers (still referring to 0.7.0). | ||
113 | |||
114 | -if test "$libssh2" = "yes"; then | ||
115 | +if test "$libssh" = "yes"; then | ||
116 | cat > $TMPC <<EOF | ||
117 | -#include <stdio.h> | ||
118 | -#include <libssh2.h> | ||
119 | -#include <libssh2_sftp.h> | ||
120 | -int main(void) { | ||
121 | - LIBSSH2_SESSION *session; | ||
122 | - LIBSSH2_SFTP *sftp; | ||
123 | - LIBSSH2_SFTP_HANDLE *sftp_handle; | ||
124 | - session = libssh2_session_init (); | ||
125 | - sftp = libssh2_sftp_init (session); | ||
126 | - sftp_handle = libssh2_sftp_open (sftp, "/", 0, 0); | ||
127 | - libssh2_sftp_fsync (sftp_handle); | ||
128 | - return 0; | ||
129 | -} | ||
130 | +#include <libssh/libssh.h> | ||
131 | +int main(void) { return ssh_get_server_publickey(NULL, NULL); } | ||
132 | EOF | ||
133 | - # libssh2_cflags/libssh2_libs defined in previous test. | ||
134 | - if compile_prog "$libssh2_cflags" "$libssh2_libs" ; then | ||
135 | - QEMU_CFLAGS="-DHAS_LIBSSH2_SFTP_FSYNC $QEMU_CFLAGS" | ||
136 | + if compile_prog "$libssh_cflags" "$libssh_libs"; then | ||
137 | + libssh_cflags="-DHAVE_LIBSSH_0_8 $libssh_cflags" | ||
138 | fi | ||
139 | fi | ||
140 | |||
141 | @@ -XXX,XX +XXX,XX @@ echo "GlusterFS support $glusterfs" | ||
142 | echo "gcov $gcov_tool" | ||
143 | echo "gcov enabled $gcov" | ||
144 | echo "TPM support $tpm" | ||
145 | -echo "libssh2 support $libssh2" | ||
146 | +echo "libssh support $libssh" | ||
147 | echo "QOM debugging $qom_cast_debug" | ||
148 | echo "Live block migration $live_block_migration" | ||
149 | echo "lzo support $lzo" | ||
150 | @@ -XXX,XX +XXX,XX @@ if test "$glusterfs_iocb_has_stat" = "yes" ; then | ||
151 | echo "CONFIG_GLUSTERFS_IOCB_HAS_STAT=y" >> $config_host_mak | ||
152 | fi | ||
153 | |||
154 | -if test "$libssh2" = "yes" ; then | ||
155 | - echo "CONFIG_LIBSSH2=m" >> $config_host_mak | ||
156 | - echo "LIBSSH2_CFLAGS=$libssh2_cflags" >> $config_host_mak | ||
157 | - echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak | ||
158 | +if test "$libssh" = "yes" ; then | ||
159 | + echo "CONFIG_LIBSSH=m" >> $config_host_mak | ||
160 | + echo "LIBSSH_CFLAGS=$libssh_cflags" >> $config_host_mak | ||
161 | + echo "LIBSSH_LIBS=$libssh_libs" >> $config_host_mak | ||
162 | fi | ||
163 | |||
164 | if test "$live_block_migration" = "yes" ; then | ||
165 | diff --git a/block/Makefile.objs b/block/Makefile.objs | ||
18 | index XXXXXXX..XXXXXXX 100644 | 166 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/curl.c | 167 | --- a/block/Makefile.objs |
20 | +++ b/block/curl.c | 168 | +++ b/block/Makefile.objs |
21 | @@ -XXX,XX +XXX,XX @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, | 169 | @@ -XXX,XX +XXX,XX @@ block-obj-$(CONFIG_CURL) += curl.o |
22 | switch (action) { | 170 | block-obj-$(CONFIG_RBD) += rbd.o |
23 | case CURL_POLL_IN: | 171 | block-obj-$(CONFIG_GLUSTERFS) += gluster.o |
24 | aio_set_fd_handler(s->aio_context, fd, false, | 172 | block-obj-$(CONFIG_VXHS) += vxhs.o |
25 | - curl_multi_do, NULL, NULL, state); | 173 | -block-obj-$(CONFIG_LIBSSH2) += ssh.o |
26 | + curl_multi_do, NULL, NULL, socket); | 174 | +block-obj-$(CONFIG_LIBSSH) += ssh.o |
27 | break; | 175 | block-obj-y += accounting.o dirty-bitmap.o |
28 | case CURL_POLL_OUT: | 176 | block-obj-y += write-threshold.o |
29 | aio_set_fd_handler(s->aio_context, fd, false, | 177 | block-obj-y += backup.o |
30 | - NULL, curl_multi_do, NULL, state); | 178 | @@ -XXX,XX +XXX,XX @@ rbd.o-libs := $(RBD_LIBS) |
31 | + NULL, curl_multi_do, NULL, socket); | 179 | gluster.o-cflags := $(GLUSTERFS_CFLAGS) |
32 | break; | 180 | gluster.o-libs := $(GLUSTERFS_LIBS) |
33 | case CURL_POLL_INOUT: | 181 | vxhs.o-libs := $(VXHS_LIBS) |
34 | aio_set_fd_handler(s->aio_context, fd, false, | 182 | -ssh.o-cflags := $(LIBSSH2_CFLAGS) |
35 | - curl_multi_do, curl_multi_do, NULL, state); | 183 | -ssh.o-libs := $(LIBSSH2_LIBS) |
36 | + curl_multi_do, curl_multi_do, NULL, socket); | 184 | +ssh.o-cflags := $(LIBSSH_CFLAGS) |
37 | break; | 185 | +ssh.o-libs := $(LIBSSH_LIBS) |
38 | case CURL_POLL_REMOVE: | 186 | block-obj-dmg-bz2-$(CONFIG_BZIP2) += dmg-bz2.o |
39 | aio_set_fd_handler(s->aio_context, fd, false, | 187 | block-obj-$(if $(CONFIG_DMG),m,n) += $(block-obj-dmg-bz2-y) |
40 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_check_completion(BDRVCURLState *s) | 188 | dmg-bz2.o-libs := $(BZIP2_LIBS) |
189 | diff --git a/block/ssh.c b/block/ssh.c | ||
190 | index XXXXXXX..XXXXXXX 100644 | ||
191 | --- a/block/ssh.c | ||
192 | +++ b/block/ssh.c | ||
193 | @@ -XXX,XX +XXX,XX @@ | ||
194 | |||
195 | #include "qemu/osdep.h" | ||
196 | |||
197 | -#include <libssh2.h> | ||
198 | -#include <libssh2_sftp.h> | ||
199 | +#include <libssh/libssh.h> | ||
200 | +#include <libssh/sftp.h> | ||
201 | |||
202 | #include "block/block_int.h" | ||
203 | #include "block/qdict.h" | ||
204 | @@ -XXX,XX +XXX,XX @@ | ||
205 | #include "trace.h" | ||
206 | |||
207 | /* | ||
208 | - * TRACE_LIBSSH2=<bitmask> enables tracing in libssh2 itself. Note | ||
209 | - * that this requires that libssh2 was specially compiled with the | ||
210 | - * `./configure --enable-debug' option, so most likely you will have | ||
211 | - * to compile it yourself. The meaning of <bitmask> is described | ||
212 | - * here: http://www.libssh2.org/libssh2_trace.html | ||
213 | + * TRACE_LIBSSH=<level> enables tracing in libssh itself. | ||
214 | + * The meaning of <level> is described here: | ||
215 | + * http://api.libssh.org/master/group__libssh__log.html | ||
216 | */ | ||
217 | -#define TRACE_LIBSSH2 0 /* or try: LIBSSH2_TRACE_SFTP */ | ||
218 | +#define TRACE_LIBSSH 0 /* see: SSH_LOG_* */ | ||
219 | |||
220 | typedef struct BDRVSSHState { | ||
221 | /* Coroutine. */ | ||
222 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVSSHState { | ||
223 | |||
224 | /* SSH connection. */ | ||
225 | int sock; /* socket */ | ||
226 | - LIBSSH2_SESSION *session; /* ssh session */ | ||
227 | - LIBSSH2_SFTP *sftp; /* sftp session */ | ||
228 | - LIBSSH2_SFTP_HANDLE *sftp_handle; /* sftp remote file handle */ | ||
229 | + ssh_session session; /* ssh session */ | ||
230 | + sftp_session sftp; /* sftp session */ | ||
231 | + sftp_file sftp_handle; /* sftp remote file handle */ | ||
232 | |||
233 | - /* See ssh_seek() function below. */ | ||
234 | - int64_t offset; | ||
235 | - bool offset_op_read; | ||
236 | - | ||
237 | - /* File attributes at open. We try to keep the .filesize field | ||
238 | + /* | ||
239 | + * File attributes at open. We try to keep the .size field | ||
240 | * updated if it changes (eg by writing at the end of the file). | ||
241 | */ | ||
242 | - LIBSSH2_SFTP_ATTRIBUTES attrs; | ||
243 | + sftp_attributes attrs; | ||
244 | |||
245 | InetSocketAddress *inet; | ||
246 | |||
247 | @@ -XXX,XX +XXX,XX @@ static void ssh_state_init(BDRVSSHState *s) | ||
248 | { | ||
249 | memset(s, 0, sizeof *s); | ||
250 | s->sock = -1; | ||
251 | - s->offset = -1; | ||
252 | qemu_co_mutex_init(&s->lock); | ||
41 | } | 253 | } |
42 | 254 | ||
43 | /* Called with s->mutex held. */ | 255 | @@ -XXX,XX +XXX,XX @@ static void ssh_state_free(BDRVSSHState *s) |
44 | -static void curl_multi_do_locked(CURLState *s) | ||
45 | +static void curl_multi_do_locked(CURLSocket *ready_socket) | ||
46 | { | 256 | { |
47 | CURLSocket *socket, *next_socket; | 257 | g_free(s->user); |
48 | + CURLState *s = ready_socket->state; | 258 | |
49 | int running; | 259 | + if (s->attrs) { |
260 | + sftp_attributes_free(s->attrs); | ||
261 | + } | ||
262 | if (s->sftp_handle) { | ||
263 | - libssh2_sftp_close(s->sftp_handle); | ||
264 | + sftp_close(s->sftp_handle); | ||
265 | } | ||
266 | if (s->sftp) { | ||
267 | - libssh2_sftp_shutdown(s->sftp); | ||
268 | + sftp_free(s->sftp); | ||
269 | } | ||
270 | if (s->session) { | ||
271 | - libssh2_session_disconnect(s->session, | ||
272 | - "from qemu ssh client: " | ||
273 | - "user closed the connection"); | ||
274 | - libssh2_session_free(s->session); | ||
275 | - } | ||
276 | - if (s->sock >= 0) { | ||
277 | - close(s->sock); | ||
278 | + ssh_disconnect(s->session); | ||
279 | + ssh_free(s->session); /* This frees s->sock */ | ||
280 | } | ||
281 | } | ||
282 | |||
283 | @@ -XXX,XX +XXX,XX @@ session_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...) | ||
284 | va_end(args); | ||
285 | |||
286 | if (s->session) { | ||
287 | - char *ssh_err; | ||
288 | + const char *ssh_err; | ||
289 | int ssh_err_code; | ||
290 | |||
291 | - /* This is not an errno. See <libssh2.h>. */ | ||
292 | - ssh_err_code = libssh2_session_last_error(s->session, | ||
293 | - &ssh_err, NULL, 0); | ||
294 | - error_setg(errp, "%s: %s (libssh2 error code: %d)", | ||
295 | + /* This is not an errno. See <libssh/libssh.h>. */ | ||
296 | + ssh_err = ssh_get_error(s->session); | ||
297 | + ssh_err_code = ssh_get_error_code(s->session); | ||
298 | + error_setg(errp, "%s: %s (libssh error code: %d)", | ||
299 | msg, ssh_err, ssh_err_code); | ||
300 | } else { | ||
301 | error_setg(errp, "%s", msg); | ||
302 | @@ -XXX,XX +XXX,XX @@ sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...) | ||
303 | va_end(args); | ||
304 | |||
305 | if (s->sftp) { | ||
306 | - char *ssh_err; | ||
307 | + const char *ssh_err; | ||
308 | int ssh_err_code; | ||
309 | - unsigned long sftp_err_code; | ||
310 | + int sftp_err_code; | ||
311 | |||
312 | - /* This is not an errno. See <libssh2.h>. */ | ||
313 | - ssh_err_code = libssh2_session_last_error(s->session, | ||
314 | - &ssh_err, NULL, 0); | ||
315 | - /* See <libssh2_sftp.h>. */ | ||
316 | - sftp_err_code = libssh2_sftp_last_error((s)->sftp); | ||
317 | + /* This is not an errno. See <libssh/libssh.h>. */ | ||
318 | + ssh_err = ssh_get_error(s->session); | ||
319 | + ssh_err_code = ssh_get_error_code(s->session); | ||
320 | + /* See <libssh/sftp.h>. */ | ||
321 | + sftp_err_code = sftp_get_error(s->sftp); | ||
322 | |||
323 | error_setg(errp, | ||
324 | - "%s: %s (libssh2 error code: %d, sftp error code: %lu)", | ||
325 | + "%s: %s (libssh error code: %d, sftp error code: %d)", | ||
326 | msg, ssh_err, ssh_err_code, sftp_err_code); | ||
327 | } else { | ||
328 | error_setg(errp, "%s", msg); | ||
329 | @@ -XXX,XX +XXX,XX @@ sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...) | ||
330 | |||
331 | static void sftp_error_trace(BDRVSSHState *s, const char *op) | ||
332 | { | ||
333 | - char *ssh_err; | ||
334 | + const char *ssh_err; | ||
335 | int ssh_err_code; | ||
336 | - unsigned long sftp_err_code; | ||
337 | + int sftp_err_code; | ||
338 | |||
339 | - /* This is not an errno. See <libssh2.h>. */ | ||
340 | - ssh_err_code = libssh2_session_last_error(s->session, | ||
341 | - &ssh_err, NULL, 0); | ||
342 | - /* See <libssh2_sftp.h>. */ | ||
343 | - sftp_err_code = libssh2_sftp_last_error((s)->sftp); | ||
344 | + /* This is not an errno. See <libssh/libssh.h>. */ | ||
345 | + ssh_err = ssh_get_error(s->session); | ||
346 | + ssh_err_code = ssh_get_error_code(s->session); | ||
347 | + /* See <libssh/sftp.h>. */ | ||
348 | + sftp_err_code = sftp_get_error(s->sftp); | ||
349 | |||
350 | trace_sftp_error(op, ssh_err, ssh_err_code, sftp_err_code); | ||
351 | } | ||
352 | @@ -XXX,XX +XXX,XX @@ static void ssh_parse_filename(const char *filename, QDict *options, | ||
353 | parse_uri(filename, options, errp); | ||
354 | } | ||
355 | |||
356 | -static int check_host_key_knownhosts(BDRVSSHState *s, | ||
357 | - const char *host, int port, Error **errp) | ||
358 | +static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp) | ||
359 | { | ||
360 | - const char *home; | ||
361 | - char *knh_file = NULL; | ||
362 | - LIBSSH2_KNOWNHOSTS *knh = NULL; | ||
363 | - struct libssh2_knownhost *found; | ||
364 | - int ret, r; | ||
365 | - const char *hostkey; | ||
366 | - size_t len; | ||
367 | - int type; | ||
368 | - | ||
369 | - hostkey = libssh2_session_hostkey(s->session, &len, &type); | ||
370 | - if (!hostkey) { | ||
371 | + int ret; | ||
372 | +#ifdef HAVE_LIBSSH_0_8 | ||
373 | + enum ssh_known_hosts_e state; | ||
374 | + int r; | ||
375 | + ssh_key pubkey; | ||
376 | + enum ssh_keytypes_e pubkey_type; | ||
377 | + unsigned char *server_hash = NULL; | ||
378 | + size_t server_hash_len; | ||
379 | + char *fingerprint = NULL; | ||
380 | + | ||
381 | + state = ssh_session_is_known_server(s->session); | ||
382 | + trace_ssh_server_status(state); | ||
383 | + | ||
384 | + switch (state) { | ||
385 | + case SSH_KNOWN_HOSTS_OK: | ||
386 | + /* OK */ | ||
387 | + trace_ssh_check_host_key_knownhosts(); | ||
388 | + break; | ||
389 | + case SSH_KNOWN_HOSTS_CHANGED: | ||
390 | ret = -EINVAL; | ||
391 | - session_error_setg(errp, s, "failed to read remote host key"); | ||
392 | + r = ssh_get_server_publickey(s->session, &pubkey); | ||
393 | + if (r == 0) { | ||
394 | + r = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_SHA256, | ||
395 | + &server_hash, &server_hash_len); | ||
396 | + pubkey_type = ssh_key_type(pubkey); | ||
397 | + ssh_key_free(pubkey); | ||
398 | + } | ||
399 | + if (r == 0) { | ||
400 | + fingerprint = ssh_get_fingerprint_hash(SSH_PUBLICKEY_HASH_SHA256, | ||
401 | + server_hash, | ||
402 | + server_hash_len); | ||
403 | + ssh_clean_pubkey_hash(&server_hash); | ||
404 | + } | ||
405 | + if (fingerprint) { | ||
406 | + error_setg(errp, | ||
407 | + "host key (%s key with fingerprint %s) does not match " | ||
408 | + "the one in known_hosts; this may be a possible attack", | ||
409 | + ssh_key_type_to_char(pubkey_type), fingerprint); | ||
410 | + ssh_string_free_char(fingerprint); | ||
411 | + } else { | ||
412 | + error_setg(errp, | ||
413 | + "host key does not match the one in known_hosts; this " | ||
414 | + "may be a possible attack"); | ||
415 | + } | ||
416 | goto out; | ||
417 | - } | ||
418 | - | ||
419 | - knh = libssh2_knownhost_init(s->session); | ||
420 | - if (!knh) { | ||
421 | + case SSH_KNOWN_HOSTS_OTHER: | ||
422 | ret = -EINVAL; | ||
423 | - session_error_setg(errp, s, | ||
424 | - "failed to initialize known hosts support"); | ||
425 | + error_setg(errp, | ||
426 | + "host key for this server not found, another type exists"); | ||
427 | + goto out; | ||
428 | + case SSH_KNOWN_HOSTS_UNKNOWN: | ||
429 | + ret = -EINVAL; | ||
430 | + error_setg(errp, "no host key was found in known_hosts"); | ||
431 | + goto out; | ||
432 | + case SSH_KNOWN_HOSTS_NOT_FOUND: | ||
433 | + ret = -ENOENT; | ||
434 | + error_setg(errp, "known_hosts file not found"); | ||
435 | + goto out; | ||
436 | + case SSH_KNOWN_HOSTS_ERROR: | ||
437 | + ret = -EINVAL; | ||
438 | + error_setg(errp, "error while checking the host"); | ||
439 | + goto out; | ||
440 | + default: | ||
441 | + ret = -EINVAL; | ||
442 | + error_setg(errp, "error while checking for known server (%d)", state); | ||
443 | goto out; | ||
444 | } | ||
445 | +#else /* !HAVE_LIBSSH_0_8 */ | ||
446 | + int state; | ||
447 | |||
448 | - home = getenv("HOME"); | ||
449 | - if (home) { | ||
450 | - knh_file = g_strdup_printf("%s/.ssh/known_hosts", home); | ||
451 | - } else { | ||
452 | - knh_file = g_strdup_printf("/root/.ssh/known_hosts"); | ||
453 | - } | ||
454 | - | ||
455 | - /* Read all known hosts from OpenSSH-style known_hosts file. */ | ||
456 | - libssh2_knownhost_readfile(knh, knh_file, LIBSSH2_KNOWNHOST_FILE_OPENSSH); | ||
457 | + state = ssh_is_server_known(s->session); | ||
458 | + trace_ssh_server_status(state); | ||
459 | |||
460 | - r = libssh2_knownhost_checkp(knh, host, port, hostkey, len, | ||
461 | - LIBSSH2_KNOWNHOST_TYPE_PLAIN| | ||
462 | - LIBSSH2_KNOWNHOST_KEYENC_RAW, | ||
463 | - &found); | ||
464 | - switch (r) { | ||
465 | - case LIBSSH2_KNOWNHOST_CHECK_MATCH: | ||
466 | + switch (state) { | ||
467 | + case SSH_SERVER_KNOWN_OK: | ||
468 | /* OK */ | ||
469 | - trace_ssh_check_host_key_knownhosts(found->key); | ||
470 | + trace_ssh_check_host_key_knownhosts(); | ||
471 | break; | ||
472 | - case LIBSSH2_KNOWNHOST_CHECK_MISMATCH: | ||
473 | + case SSH_SERVER_KNOWN_CHANGED: | ||
474 | ret = -EINVAL; | ||
475 | - session_error_setg(errp, s, | ||
476 | - "host key does not match the one in known_hosts" | ||
477 | - " (found key %s)", found->key); | ||
478 | + error_setg(errp, | ||
479 | + "host key does not match the one in known_hosts; this " | ||
480 | + "may be a possible attack"); | ||
481 | goto out; | ||
482 | - case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND: | ||
483 | + case SSH_SERVER_FOUND_OTHER: | ||
484 | ret = -EINVAL; | ||
485 | - session_error_setg(errp, s, "no host key was found in known_hosts"); | ||
486 | + error_setg(errp, | ||
487 | + "host key for this server not found, another type exists"); | ||
488 | + goto out; | ||
489 | + case SSH_SERVER_FILE_NOT_FOUND: | ||
490 | + ret = -ENOENT; | ||
491 | + error_setg(errp, "known_hosts file not found"); | ||
492 | goto out; | ||
493 | - case LIBSSH2_KNOWNHOST_CHECK_FAILURE: | ||
494 | + case SSH_SERVER_NOT_KNOWN: | ||
495 | ret = -EINVAL; | ||
496 | - session_error_setg(errp, s, | ||
497 | - "failure matching the host key with known_hosts"); | ||
498 | + error_setg(errp, "no host key was found in known_hosts"); | ||
499 | + goto out; | ||
500 | + case SSH_SERVER_ERROR: | ||
501 | + ret = -EINVAL; | ||
502 | + error_setg(errp, "server error"); | ||
503 | goto out; | ||
504 | default: | ||
505 | ret = -EINVAL; | ||
506 | - session_error_setg(errp, s, "unknown error matching the host key" | ||
507 | - " with known_hosts (%d)", r); | ||
508 | + error_setg(errp, "error while checking for known server (%d)", state); | ||
509 | goto out; | ||
510 | } | ||
511 | +#endif /* !HAVE_LIBSSH_0_8 */ | ||
512 | |||
513 | /* known_hosts checking successful. */ | ||
514 | ret = 0; | ||
515 | |||
516 | out: | ||
517 | - if (knh != NULL) { | ||
518 | - libssh2_knownhost_free(knh); | ||
519 | - } | ||
520 | - g_free(knh_file); | ||
521 | return ret; | ||
522 | } | ||
523 | |||
524 | @@ -XXX,XX +XXX,XX @@ static int compare_fingerprint(const unsigned char *fingerprint, size_t len, | ||
525 | |||
526 | static int | ||
527 | check_host_key_hash(BDRVSSHState *s, const char *hash, | ||
528 | - int hash_type, size_t fingerprint_len, Error **errp) | ||
529 | + enum ssh_publickey_hash_type type, Error **errp) | ||
530 | { | ||
531 | - const char *fingerprint; | ||
532 | - | ||
533 | - fingerprint = libssh2_hostkey_hash(s->session, hash_type); | ||
534 | - if (!fingerprint) { | ||
535 | + int r; | ||
536 | + ssh_key pubkey; | ||
537 | + unsigned char *server_hash; | ||
538 | + size_t server_hash_len; | ||
539 | + | ||
540 | +#ifdef HAVE_LIBSSH_0_8 | ||
541 | + r = ssh_get_server_publickey(s->session, &pubkey); | ||
542 | +#else | ||
543 | + r = ssh_get_publickey(s->session, &pubkey); | ||
544 | +#endif | ||
545 | + if (r != SSH_OK) { | ||
546 | session_error_setg(errp, s, "failed to read remote host key"); | ||
547 | return -EINVAL; | ||
548 | } | ||
549 | |||
550 | - if(compare_fingerprint((unsigned char *) fingerprint, fingerprint_len, | ||
551 | - hash) != 0) { | ||
552 | + r = ssh_get_publickey_hash(pubkey, type, &server_hash, &server_hash_len); | ||
553 | + ssh_key_free(pubkey); | ||
554 | + if (r != 0) { | ||
555 | + session_error_setg(errp, s, | ||
556 | + "failed reading the hash of the server SSH key"); | ||
557 | + return -EINVAL; | ||
558 | + } | ||
559 | + | ||
560 | + r = compare_fingerprint(server_hash, server_hash_len, hash); | ||
561 | + ssh_clean_pubkey_hash(&server_hash); | ||
562 | + if (r != 0) { | ||
563 | error_setg(errp, "remote host key does not match host_key_check '%s'", | ||
564 | hash); | ||
565 | return -EPERM; | ||
566 | @@ -XXX,XX +XXX,XX @@ check_host_key_hash(BDRVSSHState *s, const char *hash, | ||
567 | return 0; | ||
568 | } | ||
569 | |||
570 | -static int check_host_key(BDRVSSHState *s, const char *host, int port, | ||
571 | - SshHostKeyCheck *hkc, Error **errp) | ||
572 | +static int check_host_key(BDRVSSHState *s, SshHostKeyCheck *hkc, Error **errp) | ||
573 | { | ||
574 | SshHostKeyCheckMode mode; | ||
575 | |||
576 | @@ -XXX,XX +XXX,XX @@ static int check_host_key(BDRVSSHState *s, const char *host, int port, | ||
577 | case SSH_HOST_KEY_CHECK_MODE_HASH: | ||
578 | if (hkc->u.hash.type == SSH_HOST_KEY_CHECK_HASH_TYPE_MD5) { | ||
579 | return check_host_key_hash(s, hkc->u.hash.hash, | ||
580 | - LIBSSH2_HOSTKEY_HASH_MD5, 16, errp); | ||
581 | + SSH_PUBLICKEY_HASH_MD5, errp); | ||
582 | } else if (hkc->u.hash.type == SSH_HOST_KEY_CHECK_HASH_TYPE_SHA1) { | ||
583 | return check_host_key_hash(s, hkc->u.hash.hash, | ||
584 | - LIBSSH2_HOSTKEY_HASH_SHA1, 20, errp); | ||
585 | + SSH_PUBLICKEY_HASH_SHA1, errp); | ||
586 | } | ||
587 | g_assert_not_reached(); | ||
588 | break; | ||
589 | case SSH_HOST_KEY_CHECK_MODE_KNOWN_HOSTS: | ||
590 | - return check_host_key_knownhosts(s, host, port, errp); | ||
591 | + return check_host_key_knownhosts(s, errp); | ||
592 | default: | ||
593 | g_assert_not_reached(); | ||
594 | } | ||
595 | @@ -XXX,XX +XXX,XX @@ static int check_host_key(BDRVSSHState *s, const char *host, int port, | ||
596 | return -EINVAL; | ||
597 | } | ||
598 | |||
599 | -static int authenticate(BDRVSSHState *s, const char *user, Error **errp) | ||
600 | +static int authenticate(BDRVSSHState *s, Error **errp) | ||
601 | { | ||
602 | int r, ret; | ||
603 | - const char *userauthlist; | ||
604 | - LIBSSH2_AGENT *agent = NULL; | ||
605 | - struct libssh2_agent_publickey *identity; | ||
606 | - struct libssh2_agent_publickey *prev_identity = NULL; | ||
607 | + int method; | ||
608 | |||
609 | - userauthlist = libssh2_userauth_list(s->session, user, strlen(user)); | ||
610 | - if (strstr(userauthlist, "publickey") == NULL) { | ||
611 | + /* Try to authenticate with the "none" method. */ | ||
612 | + r = ssh_userauth_none(s->session, NULL); | ||
613 | + if (r == SSH_AUTH_ERROR) { | ||
614 | ret = -EPERM; | ||
615 | - error_setg(errp, | ||
616 | - "remote server does not support \"publickey\" authentication"); | ||
617 | + session_error_setg(errp, s, "failed to authenticate using none " | ||
618 | + "authentication"); | ||
619 | goto out; | ||
620 | - } | ||
621 | - | ||
622 | - /* Connect to ssh-agent and try each identity in turn. */ | ||
623 | - agent = libssh2_agent_init(s->session); | ||
624 | - if (!agent) { | ||
625 | - ret = -EINVAL; | ||
626 | - session_error_setg(errp, s, "failed to initialize ssh-agent support"); | ||
627 | - goto out; | ||
628 | - } | ||
629 | - if (libssh2_agent_connect(agent)) { | ||
630 | - ret = -ECONNREFUSED; | ||
631 | - session_error_setg(errp, s, "failed to connect to ssh-agent"); | ||
632 | - goto out; | ||
633 | - } | ||
634 | - if (libssh2_agent_list_identities(agent)) { | ||
635 | - ret = -EINVAL; | ||
636 | - session_error_setg(errp, s, | ||
637 | - "failed requesting identities from ssh-agent"); | ||
638 | + } else if (r == SSH_AUTH_SUCCESS) { | ||
639 | + /* Authenticated! */ | ||
640 | + ret = 0; | ||
641 | goto out; | ||
642 | } | ||
643 | |||
644 | - for(;;) { | ||
645 | - r = libssh2_agent_get_identity(agent, &identity, prev_identity); | ||
646 | - if (r == 1) { /* end of list */ | ||
647 | - break; | ||
648 | - } | ||
649 | - if (r < 0) { | ||
650 | + method = ssh_userauth_list(s->session, NULL); | ||
651 | + trace_ssh_auth_methods(method); | ||
652 | + | ||
653 | + /* | ||
654 | + * Try to authenticate with publickey, using the ssh-agent | ||
655 | + * if available. | ||
656 | + */ | ||
657 | + if (method & SSH_AUTH_METHOD_PUBLICKEY) { | ||
658 | + r = ssh_userauth_publickey_auto(s->session, NULL, NULL); | ||
659 | + if (r == SSH_AUTH_ERROR) { | ||
660 | ret = -EINVAL; | ||
661 | - session_error_setg(errp, s, | ||
662 | - "failed to obtain identity from ssh-agent"); | ||
663 | + session_error_setg(errp, s, "failed to authenticate using " | ||
664 | + "publickey authentication"); | ||
665 | goto out; | ||
666 | - } | ||
667 | - r = libssh2_agent_userauth(agent, user, identity); | ||
668 | - if (r == 0) { | ||
669 | + } else if (r == SSH_AUTH_SUCCESS) { | ||
670 | /* Authenticated! */ | ||
671 | ret = 0; | ||
672 | goto out; | ||
673 | } | ||
674 | - /* Failed to authenticate with this identity, try the next one. */ | ||
675 | - prev_identity = identity; | ||
676 | } | ||
677 | |||
678 | ret = -EPERM; | ||
679 | @@ -XXX,XX +XXX,XX @@ static int authenticate(BDRVSSHState *s, const char *user, Error **errp) | ||
680 | "and the identities held by your ssh-agent"); | ||
681 | |||
682 | out: | ||
683 | - if (agent != NULL) { | ||
684 | - /* Note: libssh2 implementation implicitly calls | ||
685 | - * libssh2_agent_disconnect if necessary. | ||
686 | - */ | ||
687 | - libssh2_agent_free(agent); | ||
688 | - } | ||
689 | - | ||
690 | return ret; | ||
691 | } | ||
692 | |||
693 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | ||
694 | int ssh_flags, int creat_mode, Error **errp) | ||
695 | { | ||
696 | int r, ret; | ||
697 | - long port = 0; | ||
698 | + unsigned int port = 0; | ||
699 | + int new_sock = -1; | ||
700 | |||
701 | if (opts->has_user) { | ||
702 | s->user = g_strdup(opts->user); | ||
703 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | ||
704 | s->inet = opts->server; | ||
705 | opts->server = NULL; | ||
706 | |||
707 | - if (qemu_strtol(s->inet->port, NULL, 10, &port) < 0) { | ||
708 | + if (qemu_strtoui(s->inet->port, NULL, 10, &port) < 0) { | ||
709 | error_setg(errp, "Use only numeric port value"); | ||
710 | ret = -EINVAL; | ||
711 | goto err; | ||
712 | } | ||
713 | |||
714 | /* Open the socket and connect. */ | ||
715 | - s->sock = inet_connect_saddr(s->inet, errp); | ||
716 | - if (s->sock < 0) { | ||
717 | + new_sock = inet_connect_saddr(s->inet, errp); | ||
718 | + if (new_sock < 0) { | ||
719 | ret = -EIO; | ||
720 | goto err; | ||
721 | } | ||
722 | |||
723 | + /* | ||
724 | + * Try to disable the Nagle algorithm on TCP sockets to reduce latency, | ||
725 | + * but do not fail if it cannot be disabled. | ||
726 | + */ | ||
727 | + r = socket_set_nodelay(new_sock); | ||
728 | + if (r < 0) { | ||
729 | + warn_report("can't set TCP_NODELAY for the ssh server %s: %s", | ||
730 | + s->inet->host, strerror(errno)); | ||
731 | + } | ||
732 | + | ||
733 | /* Create SSH session. */ | ||
734 | - s->session = libssh2_session_init(); | ||
735 | + s->session = ssh_new(); | ||
736 | if (!s->session) { | ||
737 | ret = -EINVAL; | ||
738 | - session_error_setg(errp, s, "failed to initialize libssh2 session"); | ||
739 | + session_error_setg(errp, s, "failed to initialize libssh session"); | ||
740 | goto err; | ||
741 | } | ||
742 | |||
743 | -#if TRACE_LIBSSH2 != 0 | ||
744 | - libssh2_trace(s->session, TRACE_LIBSSH2); | ||
745 | -#endif | ||
746 | + /* | ||
747 | + * Make sure we are in blocking mode during the connection and | ||
748 | + * authentication phases. | ||
749 | + */ | ||
750 | + ssh_set_blocking(s->session, 1); | ||
751 | |||
752 | - r = libssh2_session_handshake(s->session, s->sock); | ||
753 | - if (r != 0) { | ||
754 | + r = ssh_options_set(s->session, SSH_OPTIONS_USER, s->user); | ||
755 | + if (r < 0) { | ||
756 | + ret = -EINVAL; | ||
757 | + session_error_setg(errp, s, | ||
758 | + "failed to set the user in the libssh session"); | ||
759 | + goto err; | ||
760 | + } | ||
761 | + | ||
762 | + r = ssh_options_set(s->session, SSH_OPTIONS_HOST, s->inet->host); | ||
763 | + if (r < 0) { | ||
764 | + ret = -EINVAL; | ||
765 | + session_error_setg(errp, s, | ||
766 | + "failed to set the host in the libssh session"); | ||
767 | + goto err; | ||
768 | + } | ||
769 | + | ||
770 | + if (port > 0) { | ||
771 | + r = ssh_options_set(s->session, SSH_OPTIONS_PORT, &port); | ||
772 | + if (r < 0) { | ||
773 | + ret = -EINVAL; | ||
774 | + session_error_setg(errp, s, | ||
775 | + "failed to set the port in the libssh session"); | ||
776 | + goto err; | ||
777 | + } | ||
778 | + } | ||
779 | + | ||
780 | + r = ssh_options_set(s->session, SSH_OPTIONS_COMPRESSION, "none"); | ||
781 | + if (r < 0) { | ||
782 | + ret = -EINVAL; | ||
783 | + session_error_setg(errp, s, | ||
784 | + "failed to disable the compression in the libssh " | ||
785 | + "session"); | ||
786 | + goto err; | ||
787 | + } | ||
788 | + | ||
789 | + /* Read ~/.ssh/config. */ | ||
790 | + r = ssh_options_parse_config(s->session, NULL); | ||
791 | + if (r < 0) { | ||
792 | + ret = -EINVAL; | ||
793 | + session_error_setg(errp, s, "failed to parse ~/.ssh/config"); | ||
794 | + goto err; | ||
795 | + } | ||
796 | + | ||
797 | + r = ssh_options_set(s->session, SSH_OPTIONS_FD, &new_sock); | ||
798 | + if (r < 0) { | ||
799 | + ret = -EINVAL; | ||
800 | + session_error_setg(errp, s, | ||
801 | + "failed to set the socket in the libssh session"); | ||
802 | + goto err; | ||
803 | + } | ||
804 | + /* libssh took ownership of the socket. */ | ||
805 | + s->sock = new_sock; | ||
806 | + new_sock = -1; | ||
807 | + | ||
808 | + /* Connect. */ | ||
809 | + r = ssh_connect(s->session); | ||
810 | + if (r != SSH_OK) { | ||
811 | ret = -EINVAL; | ||
812 | session_error_setg(errp, s, "failed to establish SSH session"); | ||
813 | goto err; | ||
814 | } | ||
815 | |||
816 | /* Check the remote host's key against known_hosts. */ | ||
817 | - ret = check_host_key(s, s->inet->host, port, opts->host_key_check, errp); | ||
818 | + ret = check_host_key(s, opts->host_key_check, errp); | ||
819 | if (ret < 0) { | ||
820 | goto err; | ||
821 | } | ||
822 | |||
823 | /* Authenticate. */ | ||
824 | - ret = authenticate(s, s->user, errp); | ||
825 | + ret = authenticate(s, errp); | ||
826 | if (ret < 0) { | ||
827 | goto err; | ||
828 | } | ||
829 | |||
830 | /* Start SFTP. */ | ||
831 | - s->sftp = libssh2_sftp_init(s->session); | ||
832 | + s->sftp = sftp_new(s->session); | ||
833 | if (!s->sftp) { | ||
834 | - session_error_setg(errp, s, "failed to initialize sftp handle"); | ||
835 | + session_error_setg(errp, s, "failed to create sftp handle"); | ||
836 | + ret = -EINVAL; | ||
837 | + goto err; | ||
838 | + } | ||
839 | + | ||
840 | + r = sftp_init(s->sftp); | ||
841 | + if (r < 0) { | ||
842 | + sftp_error_setg(errp, s, "failed to initialize sftp handle"); | ||
843 | ret = -EINVAL; | ||
844 | goto err; | ||
845 | } | ||
846 | |||
847 | /* Open the remote file. */ | ||
848 | trace_ssh_connect_to_ssh(opts->path, ssh_flags, creat_mode); | ||
849 | - s->sftp_handle = libssh2_sftp_open(s->sftp, opts->path, ssh_flags, | ||
850 | - creat_mode); | ||
851 | + s->sftp_handle = sftp_open(s->sftp, opts->path, ssh_flags, creat_mode); | ||
852 | if (!s->sftp_handle) { | ||
853 | - session_error_setg(errp, s, "failed to open remote file '%s'", | ||
854 | - opts->path); | ||
855 | + sftp_error_setg(errp, s, "failed to open remote file '%s'", | ||
856 | + opts->path); | ||
857 | ret = -EINVAL; | ||
858 | goto err; | ||
859 | } | ||
860 | |||
861 | - r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs); | ||
862 | - if (r < 0) { | ||
863 | + /* Make sure the SFTP file is handled in blocking mode. */ | ||
864 | + sftp_file_set_blocking(s->sftp_handle); | ||
865 | + | ||
866 | + s->attrs = sftp_fstat(s->sftp_handle); | ||
867 | + if (!s->attrs) { | ||
868 | sftp_error_setg(errp, s, "failed to read file attributes"); | ||
869 | return -EINVAL; | ||
870 | } | ||
871 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | ||
872 | return 0; | ||
873 | |||
874 | err: | ||
875 | + if (s->attrs) { | ||
876 | + sftp_attributes_free(s->attrs); | ||
877 | + } | ||
878 | + s->attrs = NULL; | ||
879 | if (s->sftp_handle) { | ||
880 | - libssh2_sftp_close(s->sftp_handle); | ||
881 | + sftp_close(s->sftp_handle); | ||
882 | } | ||
883 | s->sftp_handle = NULL; | ||
884 | if (s->sftp) { | ||
885 | - libssh2_sftp_shutdown(s->sftp); | ||
886 | + sftp_free(s->sftp); | ||
887 | } | ||
888 | s->sftp = NULL; | ||
889 | if (s->session) { | ||
890 | - libssh2_session_disconnect(s->session, | ||
891 | - "from qemu ssh client: " | ||
892 | - "error opening connection"); | ||
893 | - libssh2_session_free(s->session); | ||
894 | + ssh_disconnect(s->session); | ||
895 | + ssh_free(s->session); | ||
896 | } | ||
897 | s->session = NULL; | ||
898 | + s->sock = -1; | ||
899 | + if (new_sock >= 0) { | ||
900 | + close(new_sock); | ||
901 | + } | ||
902 | |||
903 | return ret; | ||
904 | } | ||
905 | @@ -XXX,XX +XXX,XX @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags, | ||
906 | |||
907 | ssh_state_init(s); | ||
908 | |||
909 | - ssh_flags = LIBSSH2_FXF_READ; | ||
910 | + ssh_flags = 0; | ||
911 | if (bdrv_flags & BDRV_O_RDWR) { | ||
912 | - ssh_flags |= LIBSSH2_FXF_WRITE; | ||
913 | + ssh_flags |= O_RDWR; | ||
914 | + } else { | ||
915 | + ssh_flags |= O_RDONLY; | ||
916 | } | ||
917 | |||
918 | opts = ssh_parse_options(options, errp); | ||
919 | @@ -XXX,XX +XXX,XX @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags, | ||
920 | } | ||
921 | |||
922 | /* Go non-blocking. */ | ||
923 | - libssh2_session_set_blocking(s->session, 0); | ||
924 | + ssh_set_blocking(s->session, 0); | ||
925 | |||
926 | qapi_free_BlockdevOptionsSsh(opts); | ||
927 | |||
928 | return 0; | ||
929 | |||
930 | err: | ||
931 | - if (s->sock >= 0) { | ||
932 | - close(s->sock); | ||
933 | - } | ||
934 | - s->sock = -1; | ||
935 | - | ||
936 | qapi_free_BlockdevOptionsSsh(opts); | ||
937 | |||
938 | return ret; | ||
939 | @@ -XXX,XX +XXX,XX @@ static int ssh_grow_file(BDRVSSHState *s, int64_t offset, Error **errp) | ||
940 | { | ||
941 | ssize_t ret; | ||
942 | char c[1] = { '\0' }; | ||
943 | - int was_blocking = libssh2_session_get_blocking(s->session); | ||
944 | + int was_blocking = ssh_is_blocking(s->session); | ||
945 | |||
946 | /* offset must be strictly greater than the current size so we do | ||
947 | * not overwrite anything */ | ||
948 | - assert(offset > 0 && offset > s->attrs.filesize); | ||
949 | + assert(offset > 0 && offset > s->attrs->size); | ||
950 | |||
951 | - libssh2_session_set_blocking(s->session, 1); | ||
952 | + ssh_set_blocking(s->session, 1); | ||
953 | |||
954 | - libssh2_sftp_seek64(s->sftp_handle, offset - 1); | ||
955 | - ret = libssh2_sftp_write(s->sftp_handle, c, 1); | ||
956 | + sftp_seek64(s->sftp_handle, offset - 1); | ||
957 | + ret = sftp_write(s->sftp_handle, c, 1); | ||
958 | |||
959 | - libssh2_session_set_blocking(s->session, was_blocking); | ||
960 | + ssh_set_blocking(s->session, was_blocking); | ||
961 | |||
962 | if (ret < 0) { | ||
963 | sftp_error_setg(errp, s, "Failed to grow file"); | ||
964 | return -EIO; | ||
965 | } | ||
966 | |||
967 | - s->attrs.filesize = offset; | ||
968 | + s->attrs->size = offset; | ||
969 | return 0; | ||
970 | } | ||
971 | |||
972 | @@ -XXX,XX +XXX,XX @@ static int ssh_co_create(BlockdevCreateOptions *options, Error **errp) | ||
973 | ssh_state_init(&s); | ||
974 | |||
975 | ret = connect_to_ssh(&s, opts->location, | ||
976 | - LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE| | ||
977 | - LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, | ||
978 | + O_RDWR | O_CREAT | O_TRUNC, | ||
979 | 0644, errp); | ||
980 | if (ret < 0) { | ||
981 | goto fail; | ||
982 | @@ -XXX,XX +XXX,XX @@ static int ssh_has_zero_init(BlockDriverState *bs) | ||
983 | /* Assume false, unless we can positively prove it's true. */ | ||
984 | int has_zero_init = 0; | ||
985 | |||
986 | - if (s->attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { | ||
987 | - if (s->attrs.permissions & LIBSSH2_SFTP_S_IFREG) { | ||
988 | - has_zero_init = 1; | ||
989 | - } | ||
990 | + if (s->attrs->type == SSH_FILEXFER_TYPE_REGULAR) { | ||
991 | + has_zero_init = 1; | ||
992 | } | ||
993 | |||
994 | return has_zero_init; | ||
995 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs) | ||
996 | .co = qemu_coroutine_self() | ||
997 | }; | ||
998 | |||
999 | - r = libssh2_session_block_directions(s->session); | ||
1000 | + r = ssh_get_poll_flags(s->session); | ||
1001 | |||
1002 | - if (r & LIBSSH2_SESSION_BLOCK_INBOUND) { | ||
1003 | + if (r & SSH_READ_PENDING) { | ||
1004 | rd_handler = restart_coroutine; | ||
1005 | } | ||
1006 | - if (r & LIBSSH2_SESSION_BLOCK_OUTBOUND) { | ||
1007 | + if (r & SSH_WRITE_PENDING) { | ||
1008 | wr_handler = restart_coroutine; | ||
1009 | } | ||
1010 | |||
1011 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs) | ||
1012 | trace_ssh_co_yield_back(s->sock); | ||
1013 | } | ||
1014 | |||
1015 | -/* SFTP has a function `libssh2_sftp_seek64' which seeks to a position | ||
1016 | - * in the remote file. Notice that it just updates a field in the | ||
1017 | - * sftp_handle structure, so there is no network traffic and it cannot | ||
1018 | - * fail. | ||
1019 | - * | ||
1020 | - * However, `libssh2_sftp_seek64' does have a catastrophic effect on | ||
1021 | - * performance since it causes the handle to throw away all in-flight | ||
1022 | - * reads and buffered readahead data. Therefore this function tries | ||
1023 | - * to be intelligent about when to call the underlying libssh2 function. | ||
1024 | - */ | ||
1025 | -#define SSH_SEEK_WRITE 0 | ||
1026 | -#define SSH_SEEK_READ 1 | ||
1027 | -#define SSH_SEEK_FORCE 2 | ||
1028 | - | ||
1029 | -static void ssh_seek(BDRVSSHState *s, int64_t offset, int flags) | ||
1030 | -{ | ||
1031 | - bool op_read = (flags & SSH_SEEK_READ) != 0; | ||
1032 | - bool force = (flags & SSH_SEEK_FORCE) != 0; | ||
1033 | - | ||
1034 | - if (force || op_read != s->offset_op_read || offset != s->offset) { | ||
1035 | - trace_ssh_seek(offset); | ||
1036 | - libssh2_sftp_seek64(s->sftp_handle, offset); | ||
1037 | - s->offset = offset; | ||
1038 | - s->offset_op_read = op_read; | ||
1039 | - } | ||
1040 | -} | ||
1041 | - | ||
1042 | static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, | ||
1043 | int64_t offset, size_t size, | ||
1044 | QEMUIOVector *qiov) | ||
1045 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, | ||
1046 | |||
1047 | trace_ssh_read(offset, size); | ||
1048 | |||
1049 | - ssh_seek(s, offset, SSH_SEEK_READ); | ||
1050 | + trace_ssh_seek(offset); | ||
1051 | + sftp_seek64(s->sftp_handle, offset); | ||
1052 | |||
1053 | /* This keeps track of the current iovec element ('i'), where we | ||
1054 | * will write to next ('buf'), and the end of the current iovec | ||
1055 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, | ||
1056 | buf = i->iov_base; | ||
1057 | end_of_vec = i->iov_base + i->iov_len; | ||
1058 | |||
1059 | - /* libssh2 has a hard-coded limit of 2000 bytes per request, | ||
1060 | - * although it will also do readahead behind our backs. Therefore | ||
1061 | - * we may have to do repeated reads here until we have read 'size' | ||
1062 | - * bytes. | ||
1063 | - */ | ||
1064 | for (got = 0; got < size; ) { | ||
1065 | + size_t request_read_size; | ||
1066 | again: | ||
1067 | - trace_ssh_read_buf(buf, end_of_vec - buf); | ||
1068 | - r = libssh2_sftp_read(s->sftp_handle, buf, end_of_vec - buf); | ||
1069 | - trace_ssh_read_return(r); | ||
1070 | + /* | ||
1071 | + * The size of SFTP packets is limited to 32K bytes, so limit | ||
1072 | + * the amount of data requested to 16K, as libssh currently | ||
1073 | + * does not handle multiple requests on its own. | ||
1074 | + */ | ||
1075 | + request_read_size = MIN(end_of_vec - buf, 16384); | ||
1076 | + trace_ssh_read_buf(buf, end_of_vec - buf, request_read_size); | ||
1077 | + r = sftp_read(s->sftp_handle, buf, request_read_size); | ||
1078 | + trace_ssh_read_return(r, sftp_get_error(s->sftp)); | ||
1079 | |||
1080 | - if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { | ||
1081 | + if (r == SSH_AGAIN) { | ||
1082 | co_yield(s, bs); | ||
1083 | goto again; | ||
1084 | } | ||
1085 | - if (r < 0) { | ||
1086 | - sftp_error_trace(s, "read"); | ||
1087 | - s->offset = -1; | ||
1088 | - return -EIO; | ||
1089 | - } | ||
1090 | - if (r == 0) { | ||
1091 | + if (r == SSH_EOF || (r == 0 && sftp_get_error(s->sftp) == SSH_FX_EOF)) { | ||
1092 | /* EOF: Short read so pad the buffer with zeroes and return it. */ | ||
1093 | qemu_iovec_memset(qiov, got, 0, size - got); | ||
1094 | return 0; | ||
1095 | } | ||
1096 | + if (r <= 0) { | ||
1097 | + sftp_error_trace(s, "read"); | ||
1098 | + return -EIO; | ||
1099 | + } | ||
1100 | |||
1101 | got += r; | ||
1102 | buf += r; | ||
1103 | - s->offset += r; | ||
1104 | if (buf >= end_of_vec && got < size) { | ||
1105 | i++; | ||
1106 | buf = i->iov_base; | ||
1107 | @@ -XXX,XX +XXX,XX @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs, | ||
1108 | |||
1109 | trace_ssh_write(offset, size); | ||
1110 | |||
1111 | - ssh_seek(s, offset, SSH_SEEK_WRITE); | ||
1112 | + trace_ssh_seek(offset); | ||
1113 | + sftp_seek64(s->sftp_handle, offset); | ||
1114 | |||
1115 | /* This keeps track of the current iovec element ('i'), where we | ||
1116 | * will read from next ('buf'), and the end of the current iovec | ||
1117 | @@ -XXX,XX +XXX,XX @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs, | ||
1118 | end_of_vec = i->iov_base + i->iov_len; | ||
1119 | |||
1120 | for (written = 0; written < size; ) { | ||
1121 | + size_t request_write_size; | ||
1122 | again: | ||
1123 | - trace_ssh_write_buf(buf, end_of_vec - buf); | ||
1124 | - r = libssh2_sftp_write(s->sftp_handle, buf, end_of_vec - buf); | ||
1125 | - trace_ssh_write_return(r); | ||
1126 | + /* | ||
1127 | + * Avoid too large data packets, as libssh currently does not | ||
1128 | + * handle multiple requests on its own. | ||
1129 | + */ | ||
1130 | + request_write_size = MIN(end_of_vec - buf, 131072); | ||
1131 | + trace_ssh_write_buf(buf, end_of_vec - buf, request_write_size); | ||
1132 | + r = sftp_write(s->sftp_handle, buf, request_write_size); | ||
1133 | + trace_ssh_write_return(r, sftp_get_error(s->sftp)); | ||
1134 | |||
1135 | - if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { | ||
1136 | + if (r == SSH_AGAIN) { | ||
1137 | co_yield(s, bs); | ||
1138 | goto again; | ||
1139 | } | ||
1140 | if (r < 0) { | ||
1141 | sftp_error_trace(s, "write"); | ||
1142 | - s->offset = -1; | ||
1143 | return -EIO; | ||
1144 | } | ||
1145 | - /* The libssh2 API is very unclear about this. A comment in | ||
1146 | - * the code says "nothing was acked, and no EAGAIN was | ||
1147 | - * received!" which apparently means that no data got sent | ||
1148 | - * out, and the underlying channel didn't return any EAGAIN | ||
1149 | - * indication. I think this is a bug in either libssh2 or | ||
1150 | - * OpenSSH (server-side). In any case, forcing a seek (to | ||
1151 | - * discard libssh2 internal buffers), and then trying again | ||
1152 | - * works for me. | ||
1153 | - */ | ||
1154 | - if (r == 0) { | ||
1155 | - ssh_seek(s, offset + written, SSH_SEEK_WRITE|SSH_SEEK_FORCE); | ||
1156 | - co_yield(s, bs); | ||
1157 | - goto again; | ||
1158 | - } | ||
1159 | |||
1160 | written += r; | ||
1161 | buf += r; | ||
1162 | - s->offset += r; | ||
1163 | if (buf >= end_of_vec && written < size) { | ||
1164 | i++; | ||
1165 | buf = i->iov_base; | ||
1166 | end_of_vec = i->iov_base + i->iov_len; | ||
1167 | } | ||
1168 | |||
1169 | - if (offset + written > s->attrs.filesize) | ||
1170 | - s->attrs.filesize = offset + written; | ||
1171 | + if (offset + written > s->attrs->size) { | ||
1172 | + s->attrs->size = offset + written; | ||
1173 | + } | ||
1174 | } | ||
1175 | |||
1176 | return 0; | ||
1177 | @@ -XXX,XX +XXX,XX @@ static void unsafe_flush_warning(BDRVSSHState *s, const char *what) | ||
1178 | } | ||
1179 | } | ||
1180 | |||
1181 | -#ifdef HAS_LIBSSH2_SFTP_FSYNC | ||
1182 | +#ifdef HAVE_LIBSSH_0_8 | ||
1183 | |||
1184 | static coroutine_fn int ssh_flush(BDRVSSHState *s, BlockDriverState *bs) | ||
1185 | { | ||
50 | int r; | 1186 | int r; |
51 | 1187 | ||
52 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_do_locked(CURLState *s) | 1188 | trace_ssh_flush(); |
53 | 1189 | + | |
54 | static void curl_multi_do(void *arg) | 1190 | + if (!sftp_extension_supported(s->sftp, "fsync@openssh.com", "1")) { |
1191 | + unsafe_flush_warning(s, "OpenSSH >= 6.3"); | ||
1192 | + return 0; | ||
1193 | + } | ||
1194 | again: | ||
1195 | - r = libssh2_sftp_fsync(s->sftp_handle); | ||
1196 | - if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { | ||
1197 | + r = sftp_fsync(s->sftp_handle); | ||
1198 | + if (r == SSH_AGAIN) { | ||
1199 | co_yield(s, bs); | ||
1200 | goto again; | ||
1201 | } | ||
1202 | - if (r == LIBSSH2_ERROR_SFTP_PROTOCOL && | ||
1203 | - libssh2_sftp_last_error(s->sftp) == LIBSSH2_FX_OP_UNSUPPORTED) { | ||
1204 | - unsafe_flush_warning(s, "OpenSSH >= 6.3"); | ||
1205 | - return 0; | ||
1206 | - } | ||
1207 | if (r < 0) { | ||
1208 | sftp_error_trace(s, "fsync"); | ||
1209 | return -EIO; | ||
1210 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int ssh_co_flush(BlockDriverState *bs) | ||
1211 | return ret; | ||
1212 | } | ||
1213 | |||
1214 | -#else /* !HAS_LIBSSH2_SFTP_FSYNC */ | ||
1215 | +#else /* !HAVE_LIBSSH_0_8 */ | ||
1216 | |||
1217 | static coroutine_fn int ssh_co_flush(BlockDriverState *bs) | ||
55 | { | 1218 | { |
56 | - CURLState *s = (CURLState *)arg; | 1219 | BDRVSSHState *s = bs->opaque; |
57 | + CURLSocket *socket = arg; | 1220 | |
58 | + BDRVCURLState *s = socket->state->s; | 1221 | - unsafe_flush_warning(s, "libssh2 >= 1.4.4"); |
59 | 1222 | + unsafe_flush_warning(s, "libssh >= 0.8.0"); | |
60 | - qemu_mutex_lock(&s->s->mutex); | 1223 | return 0; |
61 | - curl_multi_do_locked(s); | ||
62 | - curl_multi_check_completion(s->s); | ||
63 | - qemu_mutex_unlock(&s->s->mutex); | ||
64 | + qemu_mutex_lock(&s->mutex); | ||
65 | + curl_multi_do_locked(socket); | ||
66 | + curl_multi_check_completion(s); | ||
67 | + qemu_mutex_unlock(&s->mutex); | ||
68 | } | 1224 | } |
69 | 1225 | ||
70 | static void curl_multi_timeout_do(void *arg) | 1226 | -#endif /* !HAS_LIBSSH2_SFTP_FSYNC */ |
1227 | +#endif /* !HAVE_LIBSSH_0_8 */ | ||
1228 | |||
1229 | static int64_t ssh_getlength(BlockDriverState *bs) | ||
1230 | { | ||
1231 | BDRVSSHState *s = bs->opaque; | ||
1232 | int64_t length; | ||
1233 | |||
1234 | - /* Note we cannot make a libssh2 call here. */ | ||
1235 | - length = (int64_t) s->attrs.filesize; | ||
1236 | + /* Note we cannot make a libssh call here. */ | ||
1237 | + length = (int64_t) s->attrs->size; | ||
1238 | trace_ssh_getlength(length); | ||
1239 | |||
1240 | return length; | ||
1241 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn ssh_co_truncate(BlockDriverState *bs, int64_t offset, | ||
1242 | return -ENOTSUP; | ||
1243 | } | ||
1244 | |||
1245 | - if (offset < s->attrs.filesize) { | ||
1246 | + if (offset < s->attrs->size) { | ||
1247 | error_setg(errp, "ssh driver does not support shrinking files"); | ||
1248 | return -ENOTSUP; | ||
1249 | } | ||
1250 | |||
1251 | - if (offset == s->attrs.filesize) { | ||
1252 | + if (offset == s->attrs->size) { | ||
1253 | return 0; | ||
1254 | } | ||
1255 | |||
1256 | @@ -XXX,XX +XXX,XX @@ static void bdrv_ssh_init(void) | ||
1257 | { | ||
1258 | int r; | ||
1259 | |||
1260 | - r = libssh2_init(0); | ||
1261 | + r = ssh_init(); | ||
1262 | if (r != 0) { | ||
1263 | - fprintf(stderr, "libssh2 initialization failed, %d\n", r); | ||
1264 | + fprintf(stderr, "libssh initialization failed, %d\n", r); | ||
1265 | exit(EXIT_FAILURE); | ||
1266 | } | ||
1267 | |||
1268 | +#if TRACE_LIBSSH != 0 | ||
1269 | + ssh_set_log_level(TRACE_LIBSSH); | ||
1270 | +#endif | ||
1271 | + | ||
1272 | bdrv_register(&bdrv_ssh); | ||
1273 | } | ||
1274 | |||
1275 | diff --git a/.travis.yml b/.travis.yml | ||
1276 | index XXXXXXX..XXXXXXX 100644 | ||
1277 | --- a/.travis.yml | ||
1278 | +++ b/.travis.yml | ||
1279 | @@ -XXX,XX +XXX,XX @@ addons: | ||
1280 | - libseccomp-dev | ||
1281 | - libspice-protocol-dev | ||
1282 | - libspice-server-dev | ||
1283 | - - libssh2-1-dev | ||
1284 | + - libssh-dev | ||
1285 | - liburcu-dev | ||
1286 | - libusb-1.0-0-dev | ||
1287 | - libvte-2.91-dev | ||
1288 | @@ -XXX,XX +XXX,XX @@ matrix: | ||
1289 | - libseccomp-dev | ||
1290 | - libspice-protocol-dev | ||
1291 | - libspice-server-dev | ||
1292 | - - libssh2-1-dev | ||
1293 | + - libssh-dev | ||
1294 | - liburcu-dev | ||
1295 | - libusb-1.0-0-dev | ||
1296 | - libvte-2.91-dev | ||
1297 | diff --git a/block/trace-events b/block/trace-events | ||
1298 | index XXXXXXX..XXXXXXX 100644 | ||
1299 | --- a/block/trace-events | ||
1300 | +++ b/block/trace-events | ||
1301 | @@ -XXX,XX +XXX,XX @@ nbd_client_connect_success(const char *export_name) "export '%s'" | ||
1302 | # ssh.c | ||
1303 | ssh_restart_coroutine(void *co) "co=%p" | ||
1304 | ssh_flush(void) "fsync" | ||
1305 | -ssh_check_host_key_knownhosts(const char *key) "host key OK: %s" | ||
1306 | +ssh_check_host_key_knownhosts(void) "host key OK" | ||
1307 | ssh_connect_to_ssh(char *path, int flags, int mode) "opening file %s flags=0x%x creat_mode=0%o" | ||
1308 | ssh_co_yield(int sock, void *rd_handler, void *wr_handler) "s->sock=%d rd_handler=%p wr_handler=%p" | ||
1309 | ssh_co_yield_back(int sock) "s->sock=%d - back" | ||
1310 | ssh_getlength(int64_t length) "length=%" PRIi64 | ||
1311 | ssh_co_create_opts(uint64_t size) "total_size=%" PRIu64 | ||
1312 | ssh_read(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu" | ||
1313 | -ssh_read_buf(void *buf, size_t size) "sftp_read buf=%p size=%zu" | ||
1314 | -ssh_read_return(ssize_t ret) "sftp_read returned %zd" | ||
1315 | +ssh_read_buf(void *buf, size_t size, size_t actual_size) "sftp_read buf=%p size=%zu (actual size=%zu)" | ||
1316 | +ssh_read_return(ssize_t ret, int sftp_err) "sftp_read returned %zd (sftp error=%d)" | ||
1317 | ssh_write(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu" | ||
1318 | -ssh_write_buf(void *buf, size_t size) "sftp_write buf=%p size=%zu" | ||
1319 | -ssh_write_return(ssize_t ret) "sftp_write returned %zd" | ||
1320 | +ssh_write_buf(void *buf, size_t size, size_t actual_size) "sftp_write buf=%p size=%zu (actual size=%zu)" | ||
1321 | +ssh_write_return(ssize_t ret, int sftp_err) "sftp_write returned %zd (sftp error=%d)" | ||
1322 | ssh_seek(int64_t offset) "seeking to offset=%" PRIi64 | ||
1323 | +ssh_auth_methods(int methods) "auth methods=0x%x" | ||
1324 | +ssh_server_status(int status) "server status=%d" | ||
1325 | |||
1326 | # curl.c | ||
1327 | curl_timer_cb(long timeout_ms) "timer callback timeout_ms %ld" | ||
1328 | @@ -XXX,XX +XXX,XX @@ sheepdog_snapshot_create(const char *sn_name, const char *id) "%s %s" | ||
1329 | sheepdog_snapshot_create_inode(const char *name, uint32_t snap, uint32_t vdi) "s->inode: name %s snap_id 0x%" PRIx32 " vdi 0x%" PRIx32 | ||
1330 | |||
1331 | # ssh.c | ||
1332 | -sftp_error(const char *op, const char *ssh_err, int ssh_err_code, unsigned long sftp_err_code) "%s failed: %s (libssh2 error code: %d, sftp error code: %lu)" | ||
1333 | +sftp_error(const char *op, const char *ssh_err, int ssh_err_code, int sftp_err_code) "%s failed: %s (libssh error code: %d, sftp error code: %d)" | ||
1334 | diff --git a/docs/qemu-block-drivers.texi b/docs/qemu-block-drivers.texi | ||
1335 | index XXXXXXX..XXXXXXX 100644 | ||
1336 | --- a/docs/qemu-block-drivers.texi | ||
1337 | +++ b/docs/qemu-block-drivers.texi | ||
1338 | @@ -XXX,XX +XXX,XX @@ print a warning when @code{fsync} is not supported: | ||
1339 | |||
1340 | warning: ssh server @code{ssh.example.com:22} does not support fsync | ||
1341 | |||
1342 | -With sufficiently new versions of libssh2 and OpenSSH, @code{fsync} is | ||
1343 | +With sufficiently new versions of libssh and OpenSSH, @code{fsync} is | ||
1344 | supported. | ||
1345 | |||
1346 | @node disk_images_nvme | ||
1347 | diff --git a/tests/docker/dockerfiles/debian-win32-cross.docker b/tests/docker/dockerfiles/debian-win32-cross.docker | ||
1348 | index XXXXXXX..XXXXXXX 100644 | ||
1349 | --- a/tests/docker/dockerfiles/debian-win32-cross.docker | ||
1350 | +++ b/tests/docker/dockerfiles/debian-win32-cross.docker | ||
1351 | @@ -XXX,XX +XXX,XX @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \ | ||
1352 | mxe-$TARGET-w64-mingw32.shared-curl \ | ||
1353 | mxe-$TARGET-w64-mingw32.shared-glib \ | ||
1354 | mxe-$TARGET-w64-mingw32.shared-libgcrypt \ | ||
1355 | - mxe-$TARGET-w64-mingw32.shared-libssh2 \ | ||
1356 | mxe-$TARGET-w64-mingw32.shared-libusb1 \ | ||
1357 | mxe-$TARGET-w64-mingw32.shared-lzo \ | ||
1358 | mxe-$TARGET-w64-mingw32.shared-nettle \ | ||
1359 | diff --git a/tests/docker/dockerfiles/debian-win64-cross.docker b/tests/docker/dockerfiles/debian-win64-cross.docker | ||
1360 | index XXXXXXX..XXXXXXX 100644 | ||
1361 | --- a/tests/docker/dockerfiles/debian-win64-cross.docker | ||
1362 | +++ b/tests/docker/dockerfiles/debian-win64-cross.docker | ||
1363 | @@ -XXX,XX +XXX,XX @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \ | ||
1364 | mxe-$TARGET-w64-mingw32.shared-curl \ | ||
1365 | mxe-$TARGET-w64-mingw32.shared-glib \ | ||
1366 | mxe-$TARGET-w64-mingw32.shared-libgcrypt \ | ||
1367 | - mxe-$TARGET-w64-mingw32.shared-libssh2 \ | ||
1368 | mxe-$TARGET-w64-mingw32.shared-libusb1 \ | ||
1369 | mxe-$TARGET-w64-mingw32.shared-lzo \ | ||
1370 | mxe-$TARGET-w64-mingw32.shared-nettle \ | ||
1371 | diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfiles/fedora.docker | ||
1372 | index XXXXXXX..XXXXXXX 100644 | ||
1373 | --- a/tests/docker/dockerfiles/fedora.docker | ||
1374 | +++ b/tests/docker/dockerfiles/fedora.docker | ||
1375 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES \ | ||
1376 | libpng-devel \ | ||
1377 | librbd-devel \ | ||
1378 | libseccomp-devel \ | ||
1379 | - libssh2-devel \ | ||
1380 | + libssh-devel \ | ||
1381 | libubsan \ | ||
1382 | libusbx-devel \ | ||
1383 | libxml2-devel \ | ||
1384 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES \ | ||
1385 | mingw32-gtk3 \ | ||
1386 | mingw32-libjpeg-turbo \ | ||
1387 | mingw32-libpng \ | ||
1388 | - mingw32-libssh2 \ | ||
1389 | mingw32-libtasn1 \ | ||
1390 | mingw32-nettle \ | ||
1391 | mingw32-pixman \ | ||
1392 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES \ | ||
1393 | mingw64-gtk3 \ | ||
1394 | mingw64-libjpeg-turbo \ | ||
1395 | mingw64-libpng \ | ||
1396 | - mingw64-libssh2 \ | ||
1397 | mingw64-libtasn1 \ | ||
1398 | mingw64-nettle \ | ||
1399 | mingw64-pixman \ | ||
1400 | diff --git a/tests/docker/dockerfiles/ubuntu.docker b/tests/docker/dockerfiles/ubuntu.docker | ||
1401 | index XXXXXXX..XXXXXXX 100644 | ||
1402 | --- a/tests/docker/dockerfiles/ubuntu.docker | ||
1403 | +++ b/tests/docker/dockerfiles/ubuntu.docker | ||
1404 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES flex bison \ | ||
1405 | libsnappy-dev \ | ||
1406 | libspice-protocol-dev \ | ||
1407 | libspice-server-dev \ | ||
1408 | - libssh2-1-dev \ | ||
1409 | + libssh-dev \ | ||
1410 | libusb-1.0-0-dev \ | ||
1411 | libusbredirhost-dev \ | ||
1412 | libvdeplug-dev \ | ||
1413 | diff --git a/tests/docker/dockerfiles/ubuntu1804.docker b/tests/docker/dockerfiles/ubuntu1804.docker | ||
1414 | index XXXXXXX..XXXXXXX 100644 | ||
1415 | --- a/tests/docker/dockerfiles/ubuntu1804.docker | ||
1416 | +++ b/tests/docker/dockerfiles/ubuntu1804.docker | ||
1417 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES flex bison \ | ||
1418 | libsnappy-dev \ | ||
1419 | libspice-protocol-dev \ | ||
1420 | libspice-server-dev \ | ||
1421 | - libssh2-1-dev \ | ||
1422 | + libssh-dev \ | ||
1423 | libusb-1.0-0-dev \ | ||
1424 | libusbredirhost-dev \ | ||
1425 | libvdeplug-dev \ | ||
1426 | diff --git a/tests/qemu-iotests/207 b/tests/qemu-iotests/207 | ||
1427 | index XXXXXXX..XXXXXXX 100755 | ||
1428 | --- a/tests/qemu-iotests/207 | ||
1429 | +++ b/tests/qemu-iotests/207 | ||
1430 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ | ||
1431 | |||
1432 | iotests.img_info_log(remote_path) | ||
1433 | |||
1434 | - md5_key = subprocess.check_output( | ||
1435 | - 'ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' + | ||
1436 | - 'cut -d" " -f3 | base64 -d | md5sum -b | cut -d" " -f1', | ||
1437 | - shell=True).rstrip().decode('ascii') | ||
1438 | + keys = subprocess.check_output( | ||
1439 | + 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' + | ||
1440 | + 'cut -d" " -f3', | ||
1441 | + shell=True).rstrip().decode('ascii').split('\n') | ||
1442 | + | ||
1443 | + # Mappings of base64 representations to digests | ||
1444 | + md5_keys = {} | ||
1445 | + sha1_keys = {} | ||
1446 | + | ||
1447 | + for key in keys: | ||
1448 | + md5_keys[key] = subprocess.check_output( | ||
1449 | + 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key, | ||
1450 | + shell=True).rstrip().decode('ascii') | ||
1451 | + | ||
1452 | + sha1_keys[key] = subprocess.check_output( | ||
1453 | + 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key, | ||
1454 | + shell=True).rstrip().decode('ascii') | ||
1455 | |||
1456 | vm.launch() | ||
1457 | + | ||
1458 | + # Find correct key first | ||
1459 | + matching_key = None | ||
1460 | + for key in keys: | ||
1461 | + result = vm.qmp('blockdev-add', | ||
1462 | + driver='ssh', node_name='node0', path=disk_path, | ||
1463 | + server={ | ||
1464 | + 'host': '127.0.0.1', | ||
1465 | + 'port': '22', | ||
1466 | + }, host_key_check={ | ||
1467 | + 'mode': 'hash', | ||
1468 | + 'type': 'md5', | ||
1469 | + 'hash': md5_keys[key], | ||
1470 | + }) | ||
1471 | + | ||
1472 | + if 'error' not in result: | ||
1473 | + vm.qmp('blockdev-del', node_name='node0') | ||
1474 | + matching_key = key | ||
1475 | + break | ||
1476 | + | ||
1477 | + if matching_key is None: | ||
1478 | + vm.shutdown() | ||
1479 | + iotests.notrun('Did not find a key that fits 127.0.0.1') | ||
1480 | + | ||
1481 | blockdev_create(vm, { 'driver': 'ssh', | ||
1482 | 'location': { | ||
1483 | 'path': disk_path, | ||
1484 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ | ||
1485 | 'host-key-check': { | ||
1486 | 'mode': 'hash', | ||
1487 | 'type': 'md5', | ||
1488 | - 'hash': md5_key, | ||
1489 | + 'hash': md5_keys[matching_key], | ||
1490 | } | ||
1491 | }, | ||
1492 | 'size': 8388608 }) | ||
1493 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ | ||
1494 | |||
1495 | iotests.img_info_log(remote_path) | ||
1496 | |||
1497 | - sha1_key = subprocess.check_output( | ||
1498 | - 'ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' + | ||
1499 | - 'cut -d" " -f3 | base64 -d | sha1sum -b | cut -d" " -f1', | ||
1500 | - shell=True).rstrip().decode('ascii') | ||
1501 | - | ||
1502 | vm.launch() | ||
1503 | blockdev_create(vm, { 'driver': 'ssh', | ||
1504 | 'location': { | ||
1505 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ | ||
1506 | 'host-key-check': { | ||
1507 | 'mode': 'hash', | ||
1508 | 'type': 'sha1', | ||
1509 | - 'hash': sha1_key, | ||
1510 | + 'hash': sha1_keys[matching_key], | ||
1511 | } | ||
1512 | }, | ||
1513 | 'size': 4194304 }) | ||
1514 | diff --git a/tests/qemu-iotests/207.out b/tests/qemu-iotests/207.out | ||
1515 | index XXXXXXX..XXXXXXX 100644 | ||
1516 | --- a/tests/qemu-iotests/207.out | ||
1517 | +++ b/tests/qemu-iotests/207.out | ||
1518 | @@ -XXX,XX +XXX,XX @@ virtual size: 4 MiB (4194304 bytes) | ||
1519 | |||
1520 | {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "ssh", "location": {"host-key-check": {"mode": "none"}, "path": "/this/is/not/an/existing/path", "server": {"host": "127.0.0.1", "port": "22"}}, "size": 4194304}}} | ||
1521 | {"return": {}} | ||
1522 | -Job failed: failed to open remote file '/this/is/not/an/existing/path': Failed opening remote file (libssh2 error code: -31) | ||
1523 | +Job failed: failed to open remote file '/this/is/not/an/existing/path': SFTP server: No such file (libssh error code: 1, sftp error code: 2) | ||
1524 | {"execute": "job-dismiss", "arguments": {"id": "job0"}} | ||
1525 | {"return": {}} | ||
1526 | |||
71 | -- | 1527 | -- |
72 | 2.21.0 | 1528 | 2.21.0 |
73 | 1529 | ||
74 | 1530 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Instead of reporting all sockets to cURL, only report the one that has | ||
2 | caused curl_multi_do_locked() to be called. This lets us get rid of the | ||
3 | QLIST_FOREACH_SAFE() list, which was actually wrong: SAFE foreaches are | ||
4 | only safe when the current element is removed in each iteration. If it | ||
5 | possible for the list to be concurrently modified, we cannot guarantee | ||
6 | that only the current element will be removed. Therefore, we must not | ||
7 | use QLIST_FOREACH_SAFE() here. | ||
8 | 1 | ||
9 | Fixes: ff5ca1664af85b24a4180d595ea6873fd3deac57 | ||
10 | Cc: qemu-stable@nongnu.org | ||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
12 | Message-id: 20190910124136.10565-6-mreitz@redhat.com | ||
13 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
14 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
15 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
16 | --- | ||
17 | block/curl.c | 17 ++++++----------- | ||
18 | 1 file changed, 6 insertions(+), 11 deletions(-) | ||
19 | |||
20 | diff --git a/block/curl.c b/block/curl.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/block/curl.c | ||
23 | +++ b/block/curl.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_check_completion(BDRVCURLState *s) | ||
25 | } | ||
26 | |||
27 | /* Called with s->mutex held. */ | ||
28 | -static void curl_multi_do_locked(CURLSocket *ready_socket) | ||
29 | +static void curl_multi_do_locked(CURLSocket *socket) | ||
30 | { | ||
31 | - CURLSocket *socket, *next_socket; | ||
32 | - CURLState *s = ready_socket->state; | ||
33 | + BDRVCURLState *s = socket->state->s; | ||
34 | int running; | ||
35 | int r; | ||
36 | |||
37 | - if (!s->s->multi) { | ||
38 | + if (!s->multi) { | ||
39 | return; | ||
40 | } | ||
41 | |||
42 | - /* Need to use _SAFE because curl_multi_socket_action() may trigger | ||
43 | - * curl_sock_cb() which might modify this list */ | ||
44 | - QLIST_FOREACH_SAFE(socket, &s->sockets, next, next_socket) { | ||
45 | - do { | ||
46 | - r = curl_multi_socket_action(s->s->multi, socket->fd, 0, &running); | ||
47 | - } while (r == CURLM_CALL_MULTI_PERFORM); | ||
48 | - } | ||
49 | + do { | ||
50 | + r = curl_multi_socket_action(s->multi, socket->fd, 0, &running); | ||
51 | + } while (r == CURLM_CALL_MULTI_PERFORM); | ||
52 | } | ||
53 | |||
54 | static void curl_multi_do(void *arg) | ||
55 | -- | ||
56 | 2.21.0 | ||
57 | |||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Background: As of cURL 7.59.0, it verifies that several functions are | ||
2 | not called from within a callback. Among these functions is | ||
3 | curl_multi_add_handle(). | ||
4 | 1 | ||
5 | curl_read_cb() is a callback from cURL and not a coroutine. Waking up | ||
6 | acb->co will lead to entering it then and there, which means the current | ||
7 | request will settle and the caller (if it runs in the same coroutine) | ||
8 | may then issue the next request. In such a case, we will enter | ||
9 | curl_setup_preadv() effectively from within curl_read_cb(). | ||
10 | |||
11 | Calling curl_multi_add_handle() will then fail and the new request will | ||
12 | not be processed. | ||
13 | |||
14 | Fix this by not letting curl_read_cb() wake up acb->co. Instead, leave | ||
15 | the whole business of settling the AIOCB objects to | ||
16 | curl_multi_check_completion() (which is called from our timer callback | ||
17 | and our FD handler, so not from any cURL callbacks). | ||
18 | |||
19 | Reported-by: Natalie Gavrielov <ngavrilo@redhat.com> | ||
20 | Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1740193 | ||
21 | Cc: qemu-stable@nongnu.org | ||
22 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
23 | Message-id: 20190910124136.10565-7-mreitz@redhat.com | ||
24 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
25 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
26 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
27 | --- | ||
28 | block/curl.c | 69 ++++++++++++++++++++++------------------------------ | ||
29 | 1 file changed, 29 insertions(+), 40 deletions(-) | ||
30 | |||
31 | diff --git a/block/curl.c b/block/curl.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block/curl.c | ||
34 | +++ b/block/curl.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque) | ||
36 | { | ||
37 | CURLState *s = ((CURLState*)opaque); | ||
38 | size_t realsize = size * nmemb; | ||
39 | - int i; | ||
40 | |||
41 | trace_curl_read_cb(realsize); | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque) | ||
44 | memcpy(s->orig_buf + s->buf_off, ptr, realsize); | ||
45 | s->buf_off += realsize; | ||
46 | |||
47 | - for(i=0; i<CURL_NUM_ACB; i++) { | ||
48 | - CURLAIOCB *acb = s->acb[i]; | ||
49 | - | ||
50 | - if (!acb) | ||
51 | - continue; | ||
52 | - | ||
53 | - if ((s->buf_off >= acb->end)) { | ||
54 | - size_t request_length = acb->bytes; | ||
55 | - | ||
56 | - qemu_iovec_from_buf(acb->qiov, 0, s->orig_buf + acb->start, | ||
57 | - acb->end - acb->start); | ||
58 | - | ||
59 | - if (acb->end - acb->start < request_length) { | ||
60 | - size_t offset = acb->end - acb->start; | ||
61 | - qemu_iovec_memset(acb->qiov, offset, 0, | ||
62 | - request_length - offset); | ||
63 | - } | ||
64 | - | ||
65 | - acb->ret = 0; | ||
66 | - s->acb[i] = NULL; | ||
67 | - qemu_mutex_unlock(&s->s->mutex); | ||
68 | - aio_co_wake(acb->co); | ||
69 | - qemu_mutex_lock(&s->s->mutex); | ||
70 | - } | ||
71 | - } | ||
72 | - | ||
73 | read_end: | ||
74 | /* curl will error out if we do not return this value */ | ||
75 | return size * nmemb; | ||
76 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_check_completion(BDRVCURLState *s) | ||
77 | break; | ||
78 | |||
79 | if (msg->msg == CURLMSG_DONE) { | ||
80 | + int i; | ||
81 | CURLState *state = NULL; | ||
82 | + bool error = msg->data.result != CURLE_OK; | ||
83 | + | ||
84 | curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, | ||
85 | (char **)&state); | ||
86 | |||
87 | - /* ACBs for successful messages get completed in curl_read_cb */ | ||
88 | - if (msg->data.result != CURLE_OK) { | ||
89 | - int i; | ||
90 | + if (error) { | ||
91 | static int errcount = 100; | ||
92 | |||
93 | /* Don't lose the original error message from curl, since | ||
94 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_check_completion(BDRVCURLState *s) | ||
95 | error_report("curl: further errors suppressed"); | ||
96 | } | ||
97 | } | ||
98 | + } | ||
99 | |||
100 | - for (i = 0; i < CURL_NUM_ACB; i++) { | ||
101 | - CURLAIOCB *acb = state->acb[i]; | ||
102 | + for (i = 0; i < CURL_NUM_ACB; i++) { | ||
103 | + CURLAIOCB *acb = state->acb[i]; | ||
104 | |||
105 | - if (acb == NULL) { | ||
106 | - continue; | ||
107 | - } | ||
108 | + if (acb == NULL) { | ||
109 | + continue; | ||
110 | + } | ||
111 | + | ||
112 | + if (!error) { | ||
113 | + /* Assert that we have read all data */ | ||
114 | + assert(state->buf_off >= acb->end); | ||
115 | + | ||
116 | + qemu_iovec_from_buf(acb->qiov, 0, | ||
117 | + state->orig_buf + acb->start, | ||
118 | + acb->end - acb->start); | ||
119 | |||
120 | - acb->ret = -EIO; | ||
121 | - state->acb[i] = NULL; | ||
122 | - qemu_mutex_unlock(&s->mutex); | ||
123 | - aio_co_wake(acb->co); | ||
124 | - qemu_mutex_lock(&s->mutex); | ||
125 | + if (acb->end - acb->start < acb->bytes) { | ||
126 | + size_t offset = acb->end - acb->start; | ||
127 | + qemu_iovec_memset(acb->qiov, offset, 0, | ||
128 | + acb->bytes - offset); | ||
129 | + } | ||
130 | } | ||
131 | + | ||
132 | + acb->ret = error ? -EIO : 0; | ||
133 | + state->acb[i] = NULL; | ||
134 | + qemu_mutex_unlock(&s->mutex); | ||
135 | + aio_co_wake(acb->co); | ||
136 | + qemu_mutex_lock(&s->mutex); | ||
137 | } | ||
138 | |||
139 | curl_clean_state(state); | ||
140 | -- | ||
141 | 2.21.0 | ||
142 | |||
143 | diff view generated by jsdifflib |
1 | If we had done that all along, debugging would have been much simpler. | 1 | Tests should place their files into the test directory. This includes |
---|---|---|---|
2 | (Also, I/O errors are better than hangs.) | 2 | Unix sockets. 205 currently fails to do so, which prevents it from |
3 | being run concurrently. | ||
3 | 4 | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 5 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
5 | Message-id: 20190910124136.10565-8-mreitz@redhat.com | 6 | Message-id: 20190618210238.9524-1-mreitz@redhat.com |
6 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | 7 | Reviewed-by: Eric Blake <eblake@redhat.com> |
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 8 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
9 | --- | 9 | --- |
10 | block/curl.c | 8 +++++++- | 10 | tests/qemu-iotests/205 | 2 +- |
11 | 1 file changed, 7 insertions(+), 1 deletion(-) | 11 | 1 file changed, 1 insertion(+), 1 deletion(-) |
12 | 12 | ||
13 | diff --git a/block/curl.c b/block/curl.c | 13 | diff --git a/tests/qemu-iotests/205 b/tests/qemu-iotests/205 |
14 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100755 |
15 | --- a/block/curl.c | 15 | --- a/tests/qemu-iotests/205 |
16 | +++ b/block/curl.c | 16 | +++ b/tests/qemu-iotests/205 |
17 | @@ -XXX,XX +XXX,XX @@ static void curl_setup_preadv(BlockDriverState *bs, CURLAIOCB *acb) | 17 | @@ -XXX,XX +XXX,XX @@ import iotests |
18 | trace_curl_setup_preadv(acb->bytes, start, state->range); | 18 | import time |
19 | curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range); | 19 | from iotests import qemu_img_create, qemu_io, filter_qemu_io, QemuIoInteractive |
20 | 20 | ||
21 | - curl_multi_add_handle(s->multi, state->curl); | 21 | -nbd_sock = 'nbd_sock' |
22 | + if (curl_multi_add_handle(s->multi, state->curl) != CURLM_OK) { | 22 | +nbd_sock = os.path.join(iotests.test_dir, 'nbd_sock') |
23 | + state->acb[0] = NULL; | 23 | nbd_uri = 'nbd+unix:///exp?socket=' + nbd_sock |
24 | + acb->ret = -EIO; | 24 | disk = os.path.join(iotests.test_dir, 'disk') |
25 | + | 25 | |
26 | + curl_clean_state(state); | ||
27 | + goto out; | ||
28 | + } | ||
29 | |||
30 | /* Tell curl it needs to kick things off */ | ||
31 | curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); | ||
32 | -- | 26 | -- |
33 | 2.21.0 | 27 | 2.21.0 |
34 | 28 | ||
35 | 29 | diff view generated by jsdifflib |