1 | The following changes since commit 474f3938d79ab36b9231c9ad3b5a9314c2aeacde: | 1 | The following changes since commit 54b89db5309d5fa8b5d3fe5fe56f81704e2f9706: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jun-21-2019' into staging (2019-06-21 15:40:50 +0100) | 3 | Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2019-09-03 09:43:26 +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-06-24 | 7 | https://github.com/XanClic/qemu.git tags/pull-block-2019-09-03 |
8 | 8 | ||
9 | for you to fetch changes up to ab5d4a30f7f3803ca5106b370969c1b7b54136f8: | 9 | for you to fetch changes up to 755c5fe79d88717600356d3edf04835bba43dcb6: |
10 | 10 | ||
11 | iotests: Fix 205 for concurrent runs (2019-06-24 16:01:40 +0200) | 11 | iotests: Unify cache mode quoting (2019-09-03 14:56:06 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches: | 14 | Block patches: |
15 | - The SSH block driver now uses libssh instead of libssh2 | 15 | - qemu-io now accepts a file to read a write pattern from |
16 | - The VMDK block driver gets read-only support for the seSparse | 16 | - Ensure that raw files have their first block allocated so we can probe |
17 | subformat | 17 | the O_DIRECT alignment if necessary |
18 | - Various fixes | 18 | - Various fixes |
19 | 19 | ||
20 | --- | 20 | ---------------------------------------------------------------- |
21 | |||
22 | v2: | 21 | v2: |
23 | - Squashed Pino's fix for pre-0.8 libssh into the libssh patch | 22 | - Added a patch we already had on the list to keep the iotests passing |
23 | when $DISPLAY is not set | ||
24 | 24 | ||
25 | ---------------------------------------------------------------- | 25 | ---------------------------------------------------------------- |
26 | Anton Nefedov (1): | 26 | Denis Plotnikov (1): |
27 | iotest 134: test cluster-misaligned encrypted write | 27 | qemu-io: add pattern file for write command |
28 | 28 | ||
29 | Klaus Birkelund Jensen (1): | 29 | Max Reitz (8): |
30 | nvme: do not advertise support for unsupported arbitration mechanism | 30 | iotests: Fix _filter_img_create() |
31 | vmdk: Use bdrv_dirname() for relative extent paths | ||
32 | iotests: Keep testing broken relative extent paths | ||
33 | vmdk: Reject invalid compressed writes | ||
34 | iotests: Disable broken streamOptimized tests | ||
35 | iotests: Disable 110 for vmdk.twoGbMaxExtentSparse | ||
36 | iotests: Disable 126 for flat vmdk subformats | ||
37 | iotests: Add -display none to the qemu options | ||
31 | 38 | ||
32 | Max Reitz (1): | 39 | Nir Soffer (3): |
33 | iotests: Fix 205 for concurrent runs | 40 | block: posix: Always allocate the first block |
41 | iotests: Test allocate_first_block() with O_DIRECT | ||
42 | iotests: Unify cache mode quoting | ||
34 | 43 | ||
35 | Pino Toscano (1): | 44 | Stefan Hajnoczi (1): |
36 | ssh: switch from libssh2 to libssh | 45 | file-posix: fix request_alignment typo |
37 | 46 | ||
38 | Sam Eiderman (3): | 47 | Thomas Huth (2): |
39 | vmdk: Fix comment regarding max l1_size coverage | 48 | iotests: Check for enabled drivers before testing them |
40 | vmdk: Reduce the max bound for L1 table size | 49 | tests/check-block: Skip iotests when sanitizers are enabled |
41 | vmdk: Add read-only support for seSparse snapshots | ||
42 | 50 | ||
43 | Vladimir Sementsov-Ogievskiy (1): | 51 | Vladimir Sementsov-Ogievskiy (1): |
44 | blockdev: enable non-root nodes for transaction drive-backup source | 52 | block: fix permission update in bdrv_replace_node |
45 | 53 | ||
46 | configure | 65 +- | 54 | block.c | 5 +- |
47 | block/Makefile.objs | 6 +- | 55 | block/file-posix.c | 53 +++++++++- |
48 | block/ssh.c | 652 ++++++++++-------- | 56 | block/vmdk.c | 64 ++++++++---- |
49 | block/vmdk.c | 372 +++++++++- | 57 | qemu-io-cmds.c | 99 +++++++++++++++++-- |
50 | blockdev.c | 2 +- | 58 | tests/check-block.sh | 5 + |
51 | hw/block/nvme.c | 1 - | 59 | tests/qemu-iotests/002 | 1 + |
52 | .travis.yml | 4 +- | 60 | tests/qemu-iotests/003 | 1 + |
53 | block/trace-events | 14 +- | 61 | tests/qemu-iotests/005 | 3 +- |
54 | docs/qemu-block-drivers.texi | 2 +- | 62 | tests/qemu-iotests/009 | 1 + |
55 | .../dockerfiles/debian-win32-cross.docker | 1 - | 63 | tests/qemu-iotests/010 | 1 + |
56 | .../dockerfiles/debian-win64-cross.docker | 1 - | 64 | tests/qemu-iotests/011 | 1 + |
57 | tests/docker/dockerfiles/fedora.docker | 4 +- | 65 | tests/qemu-iotests/017 | 3 +- |
58 | tests/docker/dockerfiles/ubuntu.docker | 2 +- | 66 | tests/qemu-iotests/018 | 3 +- |
59 | tests/docker/dockerfiles/ubuntu1804.docker | 2 +- | 67 | tests/qemu-iotests/019 | 3 +- |
60 | tests/qemu-iotests/059.out | 2 +- | 68 | tests/qemu-iotests/020 | 3 +- |
61 | tests/qemu-iotests/134 | 9 + | 69 | tests/qemu-iotests/026 | 4 +- |
62 | tests/qemu-iotests/134.out | 10 + | 70 | tests/qemu-iotests/027 | 1 + |
63 | tests/qemu-iotests/205 | 2 +- | 71 | tests/qemu-iotests/032 | 1 + |
64 | tests/qemu-iotests/207 | 54 +- | 72 | tests/qemu-iotests/033 | 1 + |
65 | tests/qemu-iotests/207.out | 2 +- | 73 | tests/qemu-iotests/034 | 3 +- |
66 | 20 files changed, 823 insertions(+), 384 deletions(-) | 74 | tests/qemu-iotests/037 | 3 +- |
75 | tests/qemu-iotests/039 | 4 +- | ||
76 | tests/qemu-iotests/052 | 2 +- | ||
77 | tests/qemu-iotests/059 | 34 ++++++- | ||
78 | tests/qemu-iotests/059.out | 26 +++-- | ||
79 | tests/qemu-iotests/063 | 3 +- | ||
80 | tests/qemu-iotests/071 | 1 + | ||
81 | tests/qemu-iotests/072 | 1 + | ||
82 | tests/qemu-iotests/081 | 4 +- | ||
83 | tests/qemu-iotests/091 | 4 +- | ||
84 | tests/qemu-iotests/099 | 1 + | ||
85 | tests/qemu-iotests/105 | 3 +- | ||
86 | tests/qemu-iotests/110 | 3 +- | ||
87 | tests/qemu-iotests/120 | 1 + | ||
88 | tests/qemu-iotests/126 | 2 + | ||
89 | tests/qemu-iotests/{150.out => 150.out.qcow2} | 0 | ||
90 | tests/qemu-iotests/150.out.raw | 12 +++ | ||
91 | tests/qemu-iotests/162 | 4 +- | ||
92 | tests/qemu-iotests/175 | 47 +++++++-- | ||
93 | tests/qemu-iotests/175.out | 16 ++- | ||
94 | tests/qemu-iotests/178.out.qcow2 | 4 +- | ||
95 | tests/qemu-iotests/184 | 1 + | ||
96 | tests/qemu-iotests/186 | 1 + | ||
97 | tests/qemu-iotests/197 | 1 + | ||
98 | tests/qemu-iotests/215 | 1 + | ||
99 | tests/qemu-iotests/221.out | 12 ++- | ||
100 | tests/qemu-iotests/251 | 1 + | ||
101 | tests/qemu-iotests/253.out | 12 ++- | ||
102 | tests/qemu-iotests/check | 6 +- | ||
103 | tests/qemu-iotests/common.filter | 4 +- | ||
104 | tests/qemu-iotests/common.rc | 14 +++ | ||
105 | 51 files changed, 394 insertions(+), 90 deletions(-) | ||
106 | rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%) | ||
107 | create mode 100644 tests/qemu-iotests/150.out.raw | ||
67 | 108 | ||
68 | -- | 109 | -- |
69 | 2.21.0 | 110 | 2.21.0 |
70 | 111 | ||
71 | 112 | diff view generated by jsdifflib |
1 | From: Pino Toscano <ptoscano@redhat.com> | 1 | From: Denis Plotnikov <dplotnikov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | Rewrite the implementation of the ssh block driver to use libssh instead | 3 | The patch allows to provide a pattern file for write |
4 | of libssh2. The libssh library has various advantages over libssh2: | 4 | command. There was no similar ability before. |
5 | - easier API for authentication (for example for using ssh-agent) | ||
6 | - easier API for known_hosts handling | ||
7 | - supports newer types of keys in known_hosts | ||
8 | 5 | ||
9 | Use APIs/features available in libssh 0.8 conditionally, to support | 6 | Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com> |
10 | older versions (which are not recommended though). | 7 | Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com |
11 | 8 | Reviewed-by: Eric Blake <eblake@redhat.com> | |
12 | Adjust the iotest 207 according to the different error message, and to | 9 | [mreitz: Keep optstring in alphabetical order] |
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 | ||
27 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 10 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
28 | --- | 11 | --- |
29 | configure | 65 +- | 12 | qemu-io-cmds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++--- |
30 | block/Makefile.objs | 6 +- | 13 | 1 file changed, 93 insertions(+), 6 deletions(-) |
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(-) | ||
43 | 14 | ||
44 | diff --git a/configure b/configure | 15 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c |
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 | ||
166 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
167 | --- a/block/Makefile.objs | 17 | --- a/qemu-io-cmds.c |
168 | +++ b/block/Makefile.objs | 18 | +++ b/qemu-io-cmds.c |
169 | @@ -XXX,XX +XXX,XX @@ block-obj-$(CONFIG_CURL) += curl.o | 19 | @@ -XXX,XX +XXX,XX @@ static void qemu_io_free(void *p) |
170 | block-obj-$(CONFIG_RBD) += rbd.o | 20 | qemu_vfree(p); |
171 | block-obj-$(CONFIG_GLUSTERFS) += gluster.o | ||
172 | block-obj-$(CONFIG_VXHS) += vxhs.o | ||
173 | -block-obj-$(CONFIG_LIBSSH2) += ssh.o | ||
174 | +block-obj-$(CONFIG_LIBSSH) += ssh.o | ||
175 | block-obj-y += accounting.o dirty-bitmap.o | ||
176 | block-obj-y += write-threshold.o | ||
177 | block-obj-y += backup.o | ||
178 | @@ -XXX,XX +XXX,XX @@ rbd.o-libs := $(RBD_LIBS) | ||
179 | gluster.o-cflags := $(GLUSTERFS_CFLAGS) | ||
180 | gluster.o-libs := $(GLUSTERFS_LIBS) | ||
181 | vxhs.o-libs := $(VXHS_LIBS) | ||
182 | -ssh.o-cflags := $(LIBSSH2_CFLAGS) | ||
183 | -ssh.o-libs := $(LIBSSH2_LIBS) | ||
184 | +ssh.o-cflags := $(LIBSSH_CFLAGS) | ||
185 | +ssh.o-libs := $(LIBSSH_LIBS) | ||
186 | block-obj-dmg-bz2-$(CONFIG_BZIP2) += dmg-bz2.o | ||
187 | block-obj-$(if $(CONFIG_DMG),m,n) += $(block-obj-dmg-bz2-y) | ||
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); | ||
253 | } | 21 | } |
254 | 22 | ||
255 | @@ -XXX,XX +XXX,XX @@ static void ssh_state_free(BDRVSSHState *s) | 23 | +/* |
256 | { | 24 | + * qemu_io_alloc_from_file() |
257 | g_free(s->user); | 25 | + * |
258 | 26 | + * Allocates the buffer and populates it with the content of the given file | |
259 | + if (s->attrs) { | 27 | + * up to @len bytes. If the file length is less than @len, then the buffer |
260 | + sftp_attributes_free(s->attrs); | 28 | + * is populated with the file content cyclically. |
261 | + } | 29 | + * |
262 | if (s->sftp_handle) { | 30 | + * @blk - the block backend where the buffer content is going to be written to |
263 | - libssh2_sftp_close(s->sftp_handle); | 31 | + * @len - the buffer length |
264 | + sftp_close(s->sftp_handle); | 32 | + * @file_name - the file to read the content from |
265 | } | 33 | + * |
266 | if (s->sftp) { | 34 | + * Returns: the buffer pointer on success |
267 | - libssh2_sftp_shutdown(s->sftp); | 35 | + * NULL on error |
268 | + sftp_free(s->sftp); | 36 | + */ |
269 | } | 37 | +static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len, |
270 | if (s->session) { | 38 | + const char *file_name) |
271 | - libssh2_session_disconnect(s->session, | 39 | +{ |
272 | - "from qemu ssh client: " | 40 | + char *buf, *buf_origin; |
273 | - "user closed the connection"); | 41 | + FILE *f = fopen(file_name, "r"); |
274 | - libssh2_session_free(s->session); | 42 | + int pattern_len; |
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 | + | 43 | + |
381 | + state = ssh_session_is_known_server(s->session); | 44 | + if (!f) { |
382 | + trace_ssh_server_status(state); | 45 | + perror(file_name); |
383 | + | 46 | + return NULL; |
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 | + } | 47 | + } |
559 | + | 48 | + |
560 | + r = compare_fingerprint(server_hash, server_hash_len, hash); | 49 | + if (qemuio_misalign) { |
561 | + ssh_clean_pubkey_hash(&server_hash); | 50 | + len += MISALIGN_OFFSET; |
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 | + } | 51 | + } |
732 | + | 52 | + |
733 | /* Create SSH session. */ | 53 | + buf_origin = buf = blk_blockalign(blk, len); |
734 | - s->session = libssh2_session_init(); | 54 | + |
735 | + s->session = ssh_new(); | 55 | + if (qemuio_misalign) { |
736 | if (!s->session) { | 56 | + buf_origin += MISALIGN_OFFSET; |
737 | ret = -EINVAL; | 57 | + buf += MISALIGN_OFFSET; |
738 | - session_error_setg(errp, s, "failed to initialize libssh2 session"); | 58 | + len -= MISALIGN_OFFSET; |
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 | + } | 59 | + } |
761 | + | 60 | + |
762 | + r = ssh_options_set(s->session, SSH_OPTIONS_HOST, s->inet->host); | 61 | + pattern_len = fread(buf_origin, 1, len, f); |
763 | + if (r < 0) { | 62 | + |
764 | + ret = -EINVAL; | 63 | + if (ferror(f)) { |
765 | + session_error_setg(errp, s, | 64 | + perror(file_name); |
766 | + "failed to set the host in the libssh session"); | 65 | + goto error; |
767 | + goto err; | ||
768 | + } | 66 | + } |
769 | + | 67 | + |
770 | + if (port > 0) { | 68 | + if (pattern_len == 0) { |
771 | + r = ssh_options_set(s->session, SSH_OPTIONS_PORT, &port); | 69 | + fprintf(stderr, "%s: file is empty\n", file_name); |
772 | + if (r < 0) { | 70 | + goto error; |
773 | + ret = -EINVAL; | 71 | + } |
774 | + session_error_setg(errp, s, | 72 | + |
775 | + "failed to set the port in the libssh session"); | 73 | + fclose(f); |
776 | + goto err; | 74 | + |
75 | + if (len > pattern_len) { | ||
76 | + len -= pattern_len; | ||
77 | + buf += pattern_len; | ||
78 | + | ||
79 | + while (len > 0) { | ||
80 | + size_t len_to_copy = MIN(pattern_len, len); | ||
81 | + | ||
82 | + memcpy(buf, buf_origin, len_to_copy); | ||
83 | + | ||
84 | + len -= len_to_copy; | ||
85 | + buf += len_to_copy; | ||
777 | + } | 86 | + } |
778 | + } | 87 | + } |
779 | + | 88 | + |
780 | + r = ssh_options_set(s->session, SSH_OPTIONS_COMPRESSION, "none"); | 89 | + return buf_origin; |
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 | + | 90 | + |
789 | + /* Read ~/.ssh/config. */ | 91 | +error: |
790 | + r = ssh_options_parse_config(s->session, NULL); | 92 | + qemu_io_free(buf_origin); |
791 | + if (r < 0) { | 93 | + return NULL; |
792 | + ret = -EINVAL; | 94 | +} |
793 | + session_error_setg(errp, s, "failed to parse ~/.ssh/config"); | ||
794 | + goto err; | ||
795 | + } | ||
796 | + | 95 | + |
797 | + r = ssh_options_set(s->session, SSH_OPTIONS_FD, &new_sock); | 96 | static void dump_buffer(const void *buffer, int64_t offset, int64_t len) |
798 | + if (r < 0) { | 97 | { |
799 | + ret = -EINVAL; | 98 | uint64_t i; |
800 | + session_error_setg(errp, s, | 99 | @@ -XXX,XX +XXX,XX @@ static void write_help(void) |
801 | + "failed to set the socket in the libssh session"); | 100 | " -n, -- with -z, don't allow slow fallback\n" |
802 | + goto err; | 101 | " -p, -- ignored for backwards compatibility\n" |
803 | + } | 102 | " -P, -- use different pattern to fill file\n" |
804 | + /* libssh took ownership of the socket. */ | 103 | +" -s, -- use a pattern file to fill the write buffer\n" |
805 | + s->sock = new_sock; | 104 | " -C, -- report statistics in a machine parsable format\n" |
806 | + new_sock = -1; | 105 | " -q, -- quiet mode, do not show I/O statistics\n" |
807 | + | 106 | " -u, -- with -z, allow unmapping\n" |
808 | + /* Connect. */ | 107 | @@ -XXX,XX +XXX,XX @@ static const cmdinfo_t write_cmd = { |
809 | + r = ssh_connect(s->session); | 108 | .perm = BLK_PERM_WRITE, |
810 | + if (r != SSH_OK) { | 109 | .argmin = 2, |
811 | ret = -EINVAL; | 110 | .argmax = -1, |
812 | session_error_setg(errp, s, "failed to establish SSH session"); | 111 | - .args = "[-bcCfnquz] [-P pattern] off len", |
813 | goto err; | 112 | + .args = "[-bcCfnquz] [-P pattern | -s source_file] off len", |
814 | } | 113 | .oneline = "writes a number of bytes at a specified offset", |
815 | 114 | .help = write_help, | |
816 | /* Check the remote host's key against known_hosts. */ | 115 | }; |
817 | - ret = check_host_key(s, s->inet->host, port, opts->host_key_check, errp); | 116 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
818 | + ret = check_host_key(s, opts->host_key_check, errp); | 117 | { |
819 | if (ret < 0) { | 118 | struct timespec t1, t2; |
820 | goto err; | 119 | bool Cflag = false, qflag = false, bflag = false; |
821 | } | 120 | - bool Pflag = false, zflag = false, cflag = false; |
822 | 121 | + bool Pflag = false, zflag = false, cflag = false, sflag = false; | |
823 | /* Authenticate. */ | 122 | int flags = 0; |
824 | - ret = authenticate(s, s->user, errp); | 123 | int c, cnt, ret; |
825 | + ret = authenticate(s, errp); | 124 | char *buf = NULL; |
826 | if (ret < 0) { | 125 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
827 | goto err; | 126 | /* Some compilers get confused and warn if this is not initialized. */ |
828 | } | 127 | int64_t total = 0; |
829 | 128 | int pattern = 0xcd; | |
830 | /* Start SFTP. */ | 129 | + const char *file_name = NULL; |
831 | - s->sftp = libssh2_sftp_init(s->session); | 130 | |
832 | + s->sftp = sftp_new(s->session); | 131 | - while ((c = getopt(argc, argv, "bcCfnpP:quz")) != -1) { |
833 | if (!s->sftp) { | 132 | + while ((c = getopt(argc, argv, "bcCfnpP:qs:uz")) != -1) { |
834 | - session_error_setg(errp, s, "failed to initialize sftp handle"); | 133 | switch (c) { |
835 | + session_error_setg(errp, s, "failed to create sftp handle"); | 134 | case 'b': |
836 | + ret = -EINVAL; | 135 | bflag = true; |
837 | + goto err; | 136 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
838 | + } | 137 | case 'q': |
839 | + | 138 | qflag = true; |
840 | + r = sftp_init(s->sftp); | 139 | break; |
841 | + if (r < 0) { | 140 | + case 's': |
842 | + sftp_error_setg(errp, s, "failed to initialize sftp handle"); | 141 | + sflag = true; |
843 | ret = -EINVAL; | 142 | + file_name = optarg; |
844 | goto err; | 143 | + break; |
845 | } | 144 | case 'u': |
846 | 145 | flags |= BDRV_REQ_MAY_UNMAP; | |
847 | /* Open the remote file. */ | 146 | break; |
848 | trace_ssh_connect_to_ssh(opts->path, ssh_flags, creat_mode); | 147 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
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; | 148 | return -EINVAL; |
870 | } | 149 | } |
871 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | 150 | |
872 | return 0; | 151 | - if (zflag && Pflag) { |
873 | 152 | - printf("-z and -P cannot be specified at the same time\n"); | |
874 | err: | 153 | + if (zflag + Pflag + sflag > 1) { |
875 | + if (s->attrs) { | 154 | + printf("Only one of -z, -P, and -s " |
876 | + sftp_attributes_free(s->attrs); | 155 | + "can be specified at the same time\n"); |
877 | + } | 156 | return -EINVAL; |
878 | + s->attrs = NULL; | ||
879 | if (s->sftp_handle) { | ||
880 | - libssh2_sftp_close(s->sftp_handle); | ||
881 | + sftp_close(s->sftp_handle); | ||
882 | } | 157 | } |
883 | s->sftp_handle = NULL; | 158 | |
884 | if (s->sftp) { | 159 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
885 | - libssh2_sftp_shutdown(s->sftp); | ||
886 | + sftp_free(s->sftp); | ||
887 | } | 160 | } |
888 | s->sftp = NULL; | 161 | |
889 | if (s->session) { | 162 | if (!zflag) { |
890 | - libssh2_session_disconnect(s->session, | 163 | - buf = qemu_io_alloc(blk, count, pattern); |
891 | - "from qemu ssh client: " | 164 | + if (sflag) { |
892 | - "error opening connection"); | 165 | + buf = qemu_io_alloc_from_file(blk, count, file_name); |
893 | - libssh2_session_free(s->session); | 166 | + if (!buf) { |
894 | + ssh_disconnect(s->session); | 167 | + return -EINVAL; |
895 | + ssh_free(s->session); | 168 | + } |
896 | } | 169 | + } else { |
897 | s->session = NULL; | 170 | + buf = qemu_io_alloc(blk, count, pattern); |
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 | + } | 171 | + } |
1174 | } | 172 | } |
1175 | 173 | ||
1176 | return 0; | 174 | clock_gettime(CLOCK_MONOTONIC, &t1); |
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 | { | ||
1186 | int r; | ||
1187 | |||
1188 | trace_ssh_flush(); | ||
1189 | + | ||
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) | ||
1218 | { | ||
1219 | BDRVSSHState *s = bs->opaque; | ||
1220 | |||
1221 | - unsafe_flush_warning(s, "libssh2 >= 1.4.4"); | ||
1222 | + unsafe_flush_warning(s, "libssh >= 0.8.0"); | ||
1223 | return 0; | ||
1224 | } | ||
1225 | |||
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 | |||
1527 | -- | 175 | -- |
1528 | 2.21.0 | 176 | 2.21.0 |
1529 | 177 | ||
1530 | 178 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | We forget to enable it for transaction .prepare, while it is already | 3 | It's wrong to OR shared permissions. It may lead to crash on further |
4 | enabled in do_drive_backup since commit a2d665c1bc362 | 4 | permission updates. |
5 | "blockdev: loosen restrictions on drive-backup source node" | 5 | Also, no needs to consider previously calculated permissions, as at |
6 | this point we already bind all new parents and bdrv_get_cumulative_perm | ||
7 | result is enough. So fix the bug by just set permissions by | ||
8 | bdrv_get_cumulative_perm result. | ||
9 | |||
10 | Bug was introduced in long ago 234ac1a9025, in 2.9. | ||
6 | 11 | ||
7 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 12 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
8 | Message-id: 20190618140804.59214-1-vsementsov@virtuozzo.com | 13 | Message-id: 20190824100740.61635-1-vsementsov@virtuozzo.com |
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 14 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
11 | --- | 15 | --- |
12 | blockdev.c | 2 +- | 16 | block.c | 5 ++--- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 17 | 1 file changed, 2 insertions(+), 3 deletions(-) |
14 | 18 | ||
15 | diff --git a/blockdev.c b/blockdev.c | 19 | diff --git a/block.c b/block.c |
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/blockdev.c | 21 | --- a/block.c |
18 | +++ b/blockdev.c | 22 | +++ b/block.c |
19 | @@ -XXX,XX +XXX,XX @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) | 23 | @@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, |
20 | assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); | 24 | { |
21 | backup = common->action->u.drive_backup.data; | 25 | BdrvChild *c, *next; |
22 | 26 | GSList *list = NULL, *p; | |
23 | - bs = qmp_get_root_bs(backup->device, errp); | 27 | - uint64_t old_perm, old_shared; |
24 | + bs = bdrv_lookup_bs(backup->device, backup->device, errp); | 28 | uint64_t perm = 0, shared = BLK_PERM_ALL; |
25 | if (!bs) { | 29 | int ret; |
26 | return; | 30 | |
31 | @@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
32 | bdrv_unref(from); | ||
27 | } | 33 | } |
34 | |||
35 | - bdrv_get_cumulative_perm(to, &old_perm, &old_shared); | ||
36 | - bdrv_set_perm(to, old_perm | perm, old_shared | shared); | ||
37 | + bdrv_get_cumulative_perm(to, &perm, &shared); | ||
38 | + bdrv_set_perm(to, perm, shared); | ||
39 | |||
40 | out: | ||
41 | g_slist_free(list); | ||
28 | -- | 42 | -- |
29 | 2.21.0 | 43 | 2.21.0 |
30 | 44 | ||
31 | 45 | diff view generated by jsdifflib |
1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> | 1 | From: Nir Soffer <nirsof@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | 512M of L1 entries is a very loose bound, only 32M are required to store | 3 | When creating an image with preallocation "off" or "falloc", the first |
4 | the maximal supported VMDK file size of 2TB. | 4 | block of the image is typically not allocated. When using Gluster |
5 | 5 | storage backed by XFS filesystem, reading this block using direct I/O | |
6 | Fixed qemu-iotest 59# - now failure occures before on impossible L1 | 6 | succeeds regardless of request length, fooling alignment detection. |
7 | table size. | 7 | |
8 | 8 | In this case we fallback to a safe value (4096) instead of the optimal | |
9 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> | 9 | value (512), which may lead to unneeded data copying when aligning |
10 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> | 10 | requests. Allocating the first block avoids the fallback. |
11 | Reviewed-by: Liran Alon <liran.alon@oracle.com> | 11 | |
12 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> | 12 | Since we allocate the first block even with preallocation=off, we no |
13 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | 13 | longer create images with zero disk size: |
14 | Message-id: 20190620091057.47441-3-shmuel.eiderman@oracle.com | 14 | |
15 | $ ./qemu-img create -f raw test.raw 1g | ||
16 | Formatting 'test.raw', fmt=raw size=1073741824 | ||
17 | |||
18 | $ ls -lhs test.raw | ||
19 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw | ||
20 | |||
21 | And converting the image requires additional cluster: | ||
22 | |||
23 | $ ./qemu-img measure -f raw -O qcow2 test.raw | ||
24 | required size: 458752 | ||
25 | fully allocated size: 1074135040 | ||
26 | |||
27 | When using format like vmdk with multiple files per image, we allocate | ||
28 | one block per file: | ||
29 | |||
30 | $ ./qemu-img create -f vmdk -o subformat=twoGbMaxExtentFlat test.vmdk 4g | ||
31 | Formatting 'test.vmdk', fmt=vmdk size=4294967296 compat6=off hwversion=undefined subformat=twoGbMaxExtentFlat | ||
32 | |||
33 | $ ls -lhs test*.vmdk | ||
34 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f001.vmdk | ||
35 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f002.vmdk | ||
36 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 353 Aug 27 03:23 test.vmdk | ||
37 | |||
38 | I did quick performance test for copying disks with qemu-img convert to | ||
39 | new raw target image to Gluster storage with sector size of 512 bytes: | ||
40 | |||
41 | for i in $(seq 10); do | ||
42 | rm -f dst.raw | ||
43 | sleep 10 | ||
44 | time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.raw | ||
45 | done | ||
46 | |||
47 | Here is a table comparing the total time spent: | ||
48 | |||
49 | Type Before(s) After(s) Diff(%) | ||
50 | --------------------------------------- | ||
51 | real 530.028 469.123 -11.4 | ||
52 | user 17.204 10.768 -37.4 | ||
53 | sys 17.881 7.011 -60.7 | ||
54 | |||
55 | We can see very clear improvement in CPU usage. | ||
56 | |||
57 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
58 | Message-id: 20190827010528.8818-2-nsoffer@redhat.com | ||
15 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 59 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
16 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 60 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
17 | --- | 61 | --- |
18 | block/vmdk.c | 13 +++++++------ | 62 | block/file-posix.c | 51 +++++++++++++++++++ |
19 | tests/qemu-iotests/059.out | 2 +- | 63 | tests/qemu-iotests/059.out | 2 +- |
20 | 2 files changed, 8 insertions(+), 7 deletions(-) | 64 | tests/qemu-iotests/{150.out => 150.out.qcow2} | 0 |
21 | 65 | tests/qemu-iotests/150.out.raw | 12 +++++ | |
22 | diff --git a/block/vmdk.c b/block/vmdk.c | 66 | tests/qemu-iotests/175 | 19 ++++--- |
23 | index XXXXXXX..XXXXXXX 100644 | 67 | tests/qemu-iotests/175.out | 8 +-- |
24 | --- a/block/vmdk.c | 68 | tests/qemu-iotests/178.out.qcow2 | 4 +- |
25 | +++ b/block/vmdk.c | 69 | tests/qemu-iotests/221.out | 12 +++-- |
26 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, | 70 | tests/qemu-iotests/253.out | 12 +++-- |
27 | error_setg(errp, "Invalid granularity, image may be corrupt"); | 71 | 9 files changed, 99 insertions(+), 21 deletions(-) |
28 | return -EFBIG; | 72 | rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%) |
29 | } | 73 | create mode 100644 tests/qemu-iotests/150.out.raw |
30 | - if (l1_size > 512 * 1024 * 1024) { | 74 | |
31 | + if (l1_size > 32 * 1024 * 1024) { | 75 | diff --git a/block/file-posix.c b/block/file-posix.c |
32 | /* | 76 | index XXXXXXX..XXXXXXX 100644 |
33 | * Although with big capacity and small l1_entry_sectors, we can get a | 77 | --- a/block/file-posix.c |
34 | * big l1_size, we don't want unbounded value to allocate the table. | 78 | +++ b/block/file-posix.c |
35 | - * Limit it to 512M, which is: | 79 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque) |
36 | - * 16PB - for default "Hosted Sparse Extent" (VMDK4) | 80 | return ret; |
37 | - * cluster size: 64KB, L2 table size: 512 entries | 81 | } |
38 | - * 1PB - for default "ESXi Host Sparse Extent" (VMDK3/vmfsSparse) | 82 | |
39 | - * cluster size: 512B, L2 table size: 4096 entries | 83 | +/* |
40 | + * Limit it to 32M, which is enough to store: | 84 | + * Help alignment probing by allocating the first block. |
41 | + * 8TB - for both VMDK3 & VMDK4 with | 85 | + * |
42 | + * minimal cluster size: 512B | 86 | + * When reading with direct I/O from unallocated area on Gluster backed by XFS, |
43 | + * minimal L2 table size: 512 entries | 87 | + * reading succeeds regardless of request length. In this case we fallback to |
44 | + * 8 TB is still more than the maximal value supported for | 88 | + * safe alignment which is not optimal. Allocating the first block avoids this |
45 | + * VMDK3 & VMDK4 which is 2TB. | 89 | + * fallback. |
46 | */ | 90 | + * |
47 | error_setg(errp, "L1 size too big"); | 91 | + * fd may be opened with O_DIRECT, but we don't know the buffer alignment or |
48 | return -EFBIG; | 92 | + * request alignment, so we use safe values. |
93 | + * | ||
94 | + * Returns: 0 on success, -errno on failure. Since this is an optimization, | ||
95 | + * caller may ignore failures. | ||
96 | + */ | ||
97 | +static int allocate_first_block(int fd, size_t max_size) | ||
98 | +{ | ||
99 | + size_t write_size = (max_size < MAX_BLOCKSIZE) | ||
100 | + ? BDRV_SECTOR_SIZE | ||
101 | + : MAX_BLOCKSIZE; | ||
102 | + size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize()); | ||
103 | + void *buf; | ||
104 | + ssize_t n; | ||
105 | + int ret; | ||
106 | + | ||
107 | + buf = qemu_memalign(max_align, write_size); | ||
108 | + memset(buf, 0, write_size); | ||
109 | + | ||
110 | + do { | ||
111 | + n = pwrite(fd, buf, write_size, 0); | ||
112 | + } while (n == -1 && errno == EINTR); | ||
113 | + | ||
114 | + ret = (n == -1) ? -errno : 0; | ||
115 | + | ||
116 | + qemu_vfree(buf); | ||
117 | + return ret; | ||
118 | +} | ||
119 | + | ||
120 | static int handle_aiocb_truncate(void *opaque) | ||
121 | { | ||
122 | RawPosixAIOData *aiocb = opaque; | ||
123 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque) | ||
124 | /* posix_fallocate() doesn't set errno. */ | ||
125 | error_setg_errno(errp, -result, | ||
126 | "Could not preallocate new data"); | ||
127 | + } else if (current_length == 0) { | ||
128 | + /* | ||
129 | + * posix_fallocate() uses fallocate() if the filesystem | ||
130 | + * supports it, or fallback to manually writing zeroes. If | ||
131 | + * fallocate() was used, unaligned reads from the fallocated | ||
132 | + * area in raw_probe_alignment() will succeed, hence we need to | ||
133 | + * allocate the first block. | ||
134 | + * | ||
135 | + * Optimize future alignment probing; ignore failures. | ||
136 | + */ | ||
137 | + allocate_first_block(fd, offset); | ||
138 | } | ||
139 | } else { | ||
140 | result = 0; | ||
141 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque) | ||
142 | if (ftruncate(fd, offset) != 0) { | ||
143 | result = -errno; | ||
144 | error_setg_errno(errp, -result, "Could not resize file"); | ||
145 | + } else if (current_length == 0 && offset > current_length) { | ||
146 | + /* Optimize future alignment probing; ignore failures. */ | ||
147 | + allocate_first_block(fd, offset); | ||
148 | } | ||
149 | return result; | ||
150 | default: | ||
49 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | 151 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out |
50 | index XXXXXXX..XXXXXXX 100644 | 152 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/tests/qemu-iotests/059.out | 153 | --- a/tests/qemu-iotests/059.out |
52 | +++ b/tests/qemu-iotests/059.out | 154 | +++ b/tests/qemu-iotests/059.out |
53 | @@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File | 155 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMax |
54 | 0x140000000 0x10000 0x50000 TEST_DIR/t-s003.vmdk | 156 | image: TEST_DIR/t.vmdk |
55 | 157 | file format: vmdk | |
56 | === Testing afl image with a very large capacity === | 158 | virtual size: 0.977 TiB (1073741824000 bytes) |
57 | -qemu-img: Can't get image size 'TEST_DIR/afl9.IMGFMT': File too large | 159 | -disk size: 16 KiB |
58 | +qemu-img: Could not open 'TEST_DIR/afl9.IMGFMT': L1 size too big | 160 | +disk size: 1.97 MiB |
161 | Format specific information: | ||
162 | cid: XXXXXXXX | ||
163 | parent cid: XXXXXXXX | ||
164 | diff --git a/tests/qemu-iotests/150.out b/tests/qemu-iotests/150.out.qcow2 | ||
165 | similarity index 100% | ||
166 | rename from tests/qemu-iotests/150.out | ||
167 | rename to tests/qemu-iotests/150.out.qcow2 | ||
168 | diff --git a/tests/qemu-iotests/150.out.raw b/tests/qemu-iotests/150.out.raw | ||
169 | new file mode 100644 | ||
170 | index XXXXXXX..XXXXXXX | ||
171 | --- /dev/null | ||
172 | +++ b/tests/qemu-iotests/150.out.raw | ||
173 | @@ -XXX,XX +XXX,XX @@ | ||
174 | +QA output created by 150 | ||
175 | + | ||
176 | +=== Mapping sparse conversion === | ||
177 | + | ||
178 | +Offset Length File | ||
179 | +0 0x1000 TEST_DIR/t.IMGFMT | ||
180 | + | ||
181 | +=== Mapping non-sparse conversion === | ||
182 | + | ||
183 | +Offset Length File | ||
184 | +0 0x100000 TEST_DIR/t.IMGFMT | ||
185 | +*** done | ||
186 | diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 | ||
187 | index XXXXXXX..XXXXXXX 100755 | ||
188 | --- a/tests/qemu-iotests/175 | ||
189 | +++ b/tests/qemu-iotests/175 | ||
190 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
191 | # the file size. This function hides the resulting difference in the | ||
192 | # stat -c '%b' output. | ||
193 | # Parameter 1: Number of blocks an empty file occupies | ||
194 | -# Parameter 2: Image size in bytes | ||
195 | +# Parameter 2: Minimal number of blocks in an image | ||
196 | +# Parameter 3: Image size in bytes | ||
197 | _filter_blocks() | ||
198 | { | ||
199 | extra_blocks=$1 | ||
200 | - img_size=$2 | ||
201 | + min_blocks=$2 | ||
202 | + img_size=$3 | ||
203 | |||
204 | - sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \ | ||
205 | - -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/" | ||
206 | + sed -e "s/blocks=$min_blocks\\(\$\\|[^0-9]\\)/min allocation/" \ | ||
207 | + -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/" | ||
208 | } | ||
209 | |||
210 | # get standard environment, filters and checks | ||
211 | @@ -XXX,XX +XXX,XX @@ size=$((1 * 1024 * 1024)) | ||
212 | touch "$TEST_DIR/empty" | ||
213 | extra_blocks=$(stat -c '%b' "$TEST_DIR/empty") | ||
214 | |||
215 | +# We always write the first byte; check how many blocks this filesystem | ||
216 | +# allocates to match empty image alloation. | ||
217 | +printf "\0" > "$TEST_DIR/empty" | ||
218 | +min_blocks=$(stat -c '%b' "$TEST_DIR/empty") | ||
219 | + | ||
220 | echo | ||
221 | echo "== creating image with default preallocation ==" | ||
222 | _make_test_img $size | _filter_imgfmt | ||
223 | -stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size | ||
224 | +stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
225 | |||
226 | for mode in off full falloc; do | ||
227 | echo | ||
228 | echo "== creating image with preallocation $mode ==" | ||
229 | IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt | ||
230 | - stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size | ||
231 | + stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
232 | done | ||
233 | |||
234 | # success, all done | ||
235 | diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out | ||
236 | index XXXXXXX..XXXXXXX 100644 | ||
237 | --- a/tests/qemu-iotests/175.out | ||
238 | +++ b/tests/qemu-iotests/175.out | ||
239 | @@ -XXX,XX +XXX,XX @@ QA output created by 175 | ||
240 | |||
241 | == creating image with default preallocation == | ||
242 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 | ||
243 | -size=1048576, nothing allocated | ||
244 | +size=1048576, min allocation | ||
245 | |||
246 | == creating image with preallocation off == | ||
247 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off | ||
248 | -size=1048576, nothing allocated | ||
249 | +size=1048576, min allocation | ||
250 | |||
251 | == creating image with preallocation full == | ||
252 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full | ||
253 | -size=1048576, everything allocated | ||
254 | +size=1048576, max allocation | ||
255 | |||
256 | == creating image with preallocation falloc == | ||
257 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc | ||
258 | -size=1048576, everything allocated | ||
259 | +size=1048576, max allocation | ||
260 | *** done | ||
261 | diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2 | ||
262 | index XXXXXXX..XXXXXXX 100644 | ||
263 | --- a/tests/qemu-iotests/178.out.qcow2 | ||
264 | +++ b/tests/qemu-iotests/178.out.qcow2 | ||
265 | @@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608 | ||
266 | == raw input image with data (human) == | ||
267 | |||
268 | Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824 | ||
269 | -required size: 393216 | ||
270 | +required size: 458752 | ||
271 | fully allocated size: 1074135040 | ||
272 | wrote 512/512 bytes at offset 512 | ||
273 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
274 | @@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608 | ||
275 | |||
276 | Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824 | ||
277 | { | ||
278 | - "required": 393216, | ||
279 | + "required": 458752, | ||
280 | "fully-allocated": 1074135040 | ||
281 | } | ||
282 | wrote 512/512 bytes at offset 512 | ||
283 | diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out | ||
284 | index XXXXXXX..XXXXXXX 100644 | ||
285 | --- a/tests/qemu-iotests/221.out | ||
286 | +++ b/tests/qemu-iotests/221.out | ||
287 | @@ -XXX,XX +XXX,XX @@ QA output created by 221 | ||
288 | === Check mapping of unaligned raw image === | ||
289 | |||
290 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65537 | ||
291 | -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
292 | -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
293 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
294 | +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
295 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
296 | +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
297 | wrote 1/1 bytes at offset 65536 | ||
298 | 1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
299 | -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
300 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
301 | +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
302 | { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
303 | { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
304 | -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
305 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
306 | +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
307 | { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
308 | { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
309 | *** done | ||
310 | diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out | ||
311 | index XXXXXXX..XXXXXXX 100644 | ||
312 | --- a/tests/qemu-iotests/253.out | ||
313 | +++ b/tests/qemu-iotests/253.out | ||
314 | @@ -XXX,XX +XXX,XX @@ QA output created by 253 | ||
315 | === Check mapping of unaligned raw image === | ||
316 | |||
317 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575 | ||
318 | -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
319 | -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
320 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
321 | +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
322 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
323 | +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
324 | wrote 65535/65535 bytes at offset 983040 | ||
325 | 63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
326 | -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
327 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
328 | +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
329 | { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
330 | -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
331 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
332 | +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
333 | { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
59 | *** done | 334 | *** done |
60 | -- | 335 | -- |
61 | 2.21.0 | 336 | 2.21.0 |
62 | 337 | ||
63 | 338 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Nir Soffer <nirsof@gmail.com> | ||
1 | 2 | ||
3 | Using block_resize we can test allocate_first_block() with file | ||
4 | descriptor opened with O_DIRECT, ensuring that it works for any size | ||
5 | larger than 4096 bytes. | ||
6 | |||
7 | Testing smaller sizes is tricky as the result depends on the filesystem | ||
8 | used for testing. For example on NFS any size will work since O_DIRECT | ||
9 | does not require any alignment. | ||
10 | |||
11 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
12 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
13 | Message-id: 20190827010528.8818-3-nsoffer@redhat.com | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | --- | ||
16 | tests/qemu-iotests/175 | 28 ++++++++++++++++++++++++++++ | ||
17 | tests/qemu-iotests/175.out | 8 ++++++++ | ||
18 | 2 files changed, 36 insertions(+) | ||
19 | |||
20 | diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 | ||
21 | index XXXXXXX..XXXXXXX 100755 | ||
22 | --- a/tests/qemu-iotests/175 | ||
23 | +++ b/tests/qemu-iotests/175 | ||
24 | @@ -XXX,XX +XXX,XX @@ _filter_blocks() | ||
25 | -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/" | ||
26 | } | ||
27 | |||
28 | +# Resize image using block_resize. | ||
29 | +# Parameter 1: image path | ||
30 | +# Parameter 2: new size | ||
31 | +_block_resize() | ||
32 | +{ | ||
33 | + local path=$1 | ||
34 | + local size=$2 | ||
35 | + | ||
36 | + $QEMU -qmp stdio -nographic -nodefaults \ | ||
37 | + -blockdev file,node-name=file,filename=$path,cache.direct=on \ | ||
38 | + <<EOF | ||
39 | +{'execute': 'qmp_capabilities'} | ||
40 | +{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}} | ||
41 | +{'execute': 'quit'} | ||
42 | +EOF | ||
43 | +} | ||
44 | + | ||
45 | # get standard environment, filters and checks | ||
46 | . ./common.rc | ||
47 | . ./common.filter | ||
48 | @@ -XXX,XX +XXX,XX @@ _supported_fmt raw | ||
49 | _supported_proto file | ||
50 | _supported_os Linux | ||
51 | |||
52 | +_default_cache_mode none | ||
53 | +_supported_cache_modes none directsync | ||
54 | + | ||
55 | size=$((1 * 1024 * 1024)) | ||
56 | |||
57 | touch "$TEST_DIR/empty" | ||
58 | @@ -XXX,XX +XXX,XX @@ for mode in off full falloc; do | ||
59 | stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
60 | done | ||
61 | |||
62 | +for new_size in 4096 1048576; do | ||
63 | + echo | ||
64 | + echo "== resize empty image with block_resize ==" | ||
65 | + _make_test_img 0 | _filter_imgfmt | ||
66 | + _block_resize $TEST_IMG $new_size >/dev/null | ||
67 | + stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $new_size | ||
68 | +done | ||
69 | + | ||
70 | # success, all done | ||
71 | echo "*** done" | ||
72 | rm -f $seq.full | ||
73 | diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/tests/qemu-iotests/175.out | ||
76 | +++ b/tests/qemu-iotests/175.out | ||
77 | @@ -XXX,XX +XXX,XX @@ size=1048576, max allocation | ||
78 | == creating image with preallocation falloc == | ||
79 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc | ||
80 | size=1048576, max allocation | ||
81 | + | ||
82 | +== resize empty image with block_resize == | ||
83 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 | ||
84 | +size=4096, min allocation | ||
85 | + | ||
86 | +== resize empty image with block_resize == | ||
87 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 | ||
88 | +size=1048576, min allocation | ||
89 | *** done | ||
90 | -- | ||
91 | 2.21.0 | ||
92 | |||
93 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | fe646693acc changed qemu-img create's output so that it no longer prints | ||
2 | single quotes around parameter values. The subformat and adapter_type | ||
3 | filters in _filter_img_create() have never been adapted to that change. | ||
1 | 4 | ||
5 | Fixes: fe646693acc13ac48b98435d14149ab04dc597bc | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Message-id: 20190815153638.4600-2-mreitz@redhat.com | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/059.out | 16 ++++++++-------- | ||
13 | tests/qemu-iotests/common.filter | 4 ++-- | ||
14 | 2 files changed, 10 insertions(+), 10 deletions(-) | ||
15 | |||
16 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/tests/qemu-iotests/059.out | ||
19 | +++ b/tests/qemu-iotests/059.out | ||
20 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
21 | qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big | ||
22 | |||
23 | === Testing monolithicFlat creation and opening === | ||
24 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat | ||
25 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 | ||
26 | image: TEST_DIR/t.IMGFMT | ||
27 | file format: IMGFMT | ||
28 | virtual size: 2 GiB (2147483648 bytes) | ||
29 | |||
30 | === Testing monolithicFlat with zeroed_grain === | ||
31 | qemu-img: TEST_DIR/t.IMGFMT: Flat image can't enable zeroed grain | ||
32 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat | ||
33 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 | ||
34 | |||
35 | === Testing big twoGbMaxExtentFlat === | ||
36 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMaxExtentFlat | ||
37 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 | ||
38 | image: TEST_DIR/t.vmdk | ||
39 | file format: vmdk | ||
40 | virtual size: 0.977 TiB (1073741824000 bytes) | ||
41 | @@ -XXX,XX +XXX,XX @@ Format specific information: | ||
42 | qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1 | ||
43 | |||
44 | === Testing truncated sparse === | ||
45 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse | ||
46 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 | ||
47 | qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes | ||
48 | |||
49 | === Converting to streamOptimized from image with small cluster size=== | ||
50 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | ||
51 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
52 | |||
53 | === Testing monolithicFlat with internally generated JSON file name === | ||
54 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 subformat=monolithicFlat | ||
55 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
56 | qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}' | ||
57 | |||
58 | === Testing version 3 === | ||
59 | @@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 64931328 | ||
60 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
61 | |||
62 | === Testing 4TB monolithicFlat creation and IO === | ||
63 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 subformat=monolithicFlat | ||
64 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 | ||
65 | image: TEST_DIR/t.IMGFMT | ||
66 | file format: IMGFMT | ||
67 | virtual size: 4 TiB (4398046511104 bytes) | ||
68 | @@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 966367641600 | ||
69 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
70 | |||
71 | === Testing qemu-img map on extents === | ||
72 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=monolithicSparse | ||
73 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 | ||
74 | wrote 1024/1024 bytes at offset 65024 | ||
75 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
76 | wrote 1024/1024 bytes at offset 2147483136 | ||
77 | @@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File | ||
78 | 0 0x20000 0x3f0000 TEST_DIR/t.vmdk | ||
79 | 0x7fff0000 0x20000 0x410000 TEST_DIR/t.vmdk | ||
80 | 0x140000000 0x10000 0x430000 TEST_DIR/t.vmdk | ||
81 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentSparse | ||
82 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 | ||
83 | wrote 1024/1024 bytes at offset 65024 | ||
84 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
85 | wrote 1024/1024 bytes at offset 2147483136 | ||
86 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/tests/qemu-iotests/common.filter | ||
89 | +++ b/tests/qemu-iotests/common.filter | ||
90 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() | ||
91 | -e "s# compat6=\\(on\\|off\\)##g" \ | ||
92 | -e "s# static=\\(on\\|off\\)##g" \ | ||
93 | -e "s# zeroed_grain=\\(on\\|off\\)##g" \ | ||
94 | - -e "s# subformat='[^']*'##g" \ | ||
95 | - -e "s# adapter_type='[^']*'##g" \ | ||
96 | + -e "s# subformat=[^ ]*##g" \ | ||
97 | + -e "s# adapter_type=[^ ]*##g" \ | ||
98 | -e "s# hwversion=[^ ]*##g" \ | ||
99 | -e "s# lazy_refcounts=\\(on\\|off\\)##g" \ | ||
100 | -e "s# block_size=[0-9]\\+##g" \ | ||
101 | -- | ||
102 | 2.21.0 | ||
103 | |||
104 | diff view generated by jsdifflib |
1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> | 1 | This makes iotest 033 pass with e.g. subformat=monolithicFlat. It also |
---|---|---|---|
2 | turns a former error in 059 into success. | ||
2 | 3 | ||
3 | Until ESXi 6.5 VMware used the vmfsSparse format for snapshots (VMDK3 in | 4 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
4 | QEMU). | 5 | Message-id: 20190815153638.4600-3-mreitz@redhat.com |
5 | 6 | Reviewed-by: John Snow <jsnow@redhat.com> | |
6 | This format was lacking in the following: | ||
7 | |||
8 | * Grain directory (L1) and grain table (L2) entries were 32-bit, | ||
9 | allowing access to only 2TB (slightly less) of data. | ||
10 | * The grain size (default) was 512 bytes - leading to data | ||
11 | fragmentation and many grain tables. | ||
12 | * For space reclamation purposes, it was necessary to find all the | ||
13 | grains which are not pointed to by any grain table - so a reverse | ||
14 | mapping of "offset of grain in vmdk" to "grain table" must be | ||
15 | constructed - which takes large amounts of CPU/RAM. | ||
16 | |||
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 | ||
151 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 7 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
152 | --- | 8 | --- |
153 | block/vmdk.c | 358 ++++++++++++++++++++++++++++++++++++++++++++++++--- | 9 | block/vmdk.c | 54 ++++++++++++++++++++++++-------------- |
154 | 1 file changed, 342 insertions(+), 16 deletions(-) | 10 | tests/qemu-iotests/059 | 7 +++-- |
11 | tests/qemu-iotests/059.out | 4 ++- | ||
12 | 3 files changed, 42 insertions(+), 23 deletions(-) | ||
155 | 13 | ||
156 | diff --git a/block/vmdk.c b/block/vmdk.c | 14 | diff --git a/block/vmdk.c b/block/vmdk.c |
157 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
158 | --- a/block/vmdk.c | 16 | --- a/block/vmdk.c |
159 | +++ b/block/vmdk.c | 17 | +++ b/block/vmdk.c |
160 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 18 | @@ -XXX,XX +XXX,XX @@ static const char *next_line(const char *s) |
161 | uint16_t compressAlgorithm; | ||
162 | } QEMU_PACKED VMDK4Header; | ||
163 | |||
164 | +typedef struct VMDKSESparseConstHeader { | ||
165 | + uint64_t magic; | ||
166 | + uint64_t version; | ||
167 | + uint64_t capacity; | ||
168 | + uint64_t grain_size; | ||
169 | + uint64_t grain_table_size; | ||
170 | + uint64_t flags; | ||
171 | + uint64_t reserved1; | ||
172 | + uint64_t reserved2; | ||
173 | + uint64_t reserved3; | ||
174 | + uint64_t reserved4; | ||
175 | + uint64_t volatile_header_offset; | ||
176 | + uint64_t volatile_header_size; | ||
177 | + uint64_t journal_header_offset; | ||
178 | + uint64_t journal_header_size; | ||
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); | ||
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; | ||
289 | } | 19 | } |
290 | 20 | ||
291 | +#define SESPARSE_CONST_HEADER_MAGIC UINT64_C(0x00000000cafebabe) | 21 | static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, |
292 | +#define SESPARSE_VOLATILE_HEADER_MAGIC UINT64_C(0x00000000cafecafe) | 22 | - const char *desc_file_path, QDict *options, |
293 | + | 23 | - Error **errp) |
294 | +/* Strict checks - format not officially documented */ | 24 | + QDict *options, Error **errp) |
295 | +static int check_se_sparse_const_header(VMDKSESparseConstHeader *header, | 25 | { |
296 | + Error **errp) | 26 | int ret; |
297 | +{ | 27 | int matches; |
298 | + header->magic = le64_to_cpu(header->magic); | ||
299 | + header->version = le64_to_cpu(header->version); | ||
300 | + header->grain_size = le64_to_cpu(header->grain_size); | ||
301 | + header->grain_table_size = le64_to_cpu(header->grain_table_size); | ||
302 | + header->flags = le64_to_cpu(header->flags); | ||
303 | + header->reserved1 = le64_to_cpu(header->reserved1); | ||
304 | + header->reserved2 = le64_to_cpu(header->reserved2); | ||
305 | + header->reserved3 = le64_to_cpu(header->reserved3); | ||
306 | + header->reserved4 = le64_to_cpu(header->reserved4); | ||
307 | + | ||
308 | + header->volatile_header_offset = | ||
309 | + le64_to_cpu(header->volatile_header_offset); | ||
310 | + header->volatile_header_size = le64_to_cpu(header->volatile_header_size); | ||
311 | + | ||
312 | + header->journal_header_offset = le64_to_cpu(header->journal_header_offset); | ||
313 | + header->journal_header_size = le64_to_cpu(header->journal_header_size); | ||
314 | + | ||
315 | + header->journal_offset = le64_to_cpu(header->journal_offset); | ||
316 | + header->journal_size = le64_to_cpu(header->journal_size); | ||
317 | + | ||
318 | + header->grain_dir_offset = le64_to_cpu(header->grain_dir_offset); | ||
319 | + header->grain_dir_size = le64_to_cpu(header->grain_dir_size); | ||
320 | + | ||
321 | + header->grain_tables_offset = le64_to_cpu(header->grain_tables_offset); | ||
322 | + header->grain_tables_size = le64_to_cpu(header->grain_tables_size); | ||
323 | + | ||
324 | + header->free_bitmap_offset = le64_to_cpu(header->free_bitmap_offset); | ||
325 | + header->free_bitmap_size = le64_to_cpu(header->free_bitmap_size); | ||
326 | + | ||
327 | + header->backmap_offset = le64_to_cpu(header->backmap_offset); | ||
328 | + header->backmap_size = le64_to_cpu(header->backmap_size); | ||
329 | + | ||
330 | + header->grains_offset = le64_to_cpu(header->grains_offset); | ||
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, | 28 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, |
494 | * RW [size in sectors] SPARSE "file-name.vmdk" | 29 | const char *p, *np; |
495 | * RW [size in sectors] VMFS "file-name.vmdk" | 30 | int64_t sectors = 0; |
496 | * RW [size in sectors] VMFSSPARSE "file-name.vmdk" | 31 | int64_t flat_offset; |
497 | + * RW [size in sectors] SESPARSE "file-name.vmdk" | 32 | + char *desc_file_dir = NULL; |
498 | */ | 33 | char *extent_path; |
499 | flat_offset = -1; | 34 | BdrvChild *extent_file; |
500 | matches = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, | 35 | BDRVVmdkState *s = bs->opaque; |
501 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 36 | @@ -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; | 37 | continue; |
510 | } | 38 | } |
39 | |||
40 | - if (!path_is_absolute(fname) && !path_has_protocol(fname) && | ||
41 | - !desc_file_path[0]) | ||
42 | - { | ||
43 | - bdrv_refresh_filename(bs->file->bs); | ||
44 | - error_setg(errp, "Cannot use relative extent paths with VMDK " | ||
45 | - "descriptor file '%s'", bs->file->bs->filename); | ||
46 | - return -EINVAL; | ||
47 | - } | ||
48 | + if (path_is_absolute(fname)) { | ||
49 | + extent_path = g_strdup(fname); | ||
50 | + } else { | ||
51 | + if (!desc_file_dir) { | ||
52 | + desc_file_dir = bdrv_dirname(bs->file->bs, errp); | ||
53 | + if (!desc_file_dir) { | ||
54 | + bdrv_refresh_filename(bs->file->bs); | ||
55 | + error_prepend(errp, "Cannot use relative paths with VMDK " | ||
56 | + "descriptor file '%s': ", | ||
57 | + bs->file->bs->filename); | ||
58 | + ret = -EINVAL; | ||
59 | + goto out; | ||
60 | + } | ||
61 | + } | ||
62 | |||
63 | - extent_path = path_combine(desc_file_path, fname); | ||
64 | + extent_path = g_strconcat(desc_file_dir, fname, NULL); | ||
65 | + } | ||
66 | |||
67 | ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents); | ||
68 | assert(ret < 32); | ||
511 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | 69 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, |
512 | return ret; | 70 | g_free(extent_path); |
71 | if (local_err) { | ||
72 | error_propagate(errp, local_err); | ||
73 | - return -EINVAL; | ||
74 | + ret = -EINVAL; | ||
75 | + goto out; | ||
76 | } | ||
77 | |||
78 | /* save to extents array */ | ||
79 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
80 | 0, 0, 0, 0, 0, &extent, errp); | ||
81 | if (ret < 0) { | ||
82 | bdrv_unref_child(bs, extent_file); | ||
83 | - return ret; | ||
84 | + goto out; | ||
85 | } | ||
86 | extent->flat_start_offset = flat_offset << 9; | ||
87 | } else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) { | ||
88 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
89 | g_free(buf); | ||
90 | if (ret) { | ||
91 | bdrv_unref_child(bs, extent_file); | ||
92 | - return ret; | ||
93 | + goto out; | ||
513 | } | 94 | } |
514 | extent = &s->extents[s->num_extents - 1]; | 95 | extent = &s->extents[s->num_extents - 1]; |
515 | + } else if (!strcmp(type, "SESPARSE")) { | 96 | } else if (!strcmp(type, "SESPARSE")) { |
516 | + ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp); | 97 | ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp); |
517 | + if (ret) { | 98 | if (ret) { |
518 | + bdrv_unref_child(bs, extent_file); | 99 | bdrv_unref_child(bs, extent_file); |
519 | + return ret; | 100 | - return ret; |
520 | + } | 101 | + goto out; |
521 | + extent = &s->extents[s->num_extents - 1]; | 102 | } |
103 | extent = &s->extents[s->num_extents - 1]; | ||
522 | } else { | 104 | } else { |
523 | error_setg(errp, "Unsupported extent type '%s'", type); | 105 | error_setg(errp, "Unsupported extent type '%s'", type); |
524 | bdrv_unref_child(bs, extent_file); | 106 | bdrv_unref_child(bs, extent_file); |
107 | - return -ENOTSUP; | ||
108 | + ret = -ENOTSUP; | ||
109 | + goto out; | ||
110 | } | ||
111 | extent->type = g_strdup(type); | ||
112 | } | ||
113 | - return 0; | ||
114 | + | ||
115 | + ret = 0; | ||
116 | + goto out; | ||
117 | |||
118 | invalid: | ||
119 | np = next_line(p); | ||
120 | @@ -XXX,XX +XXX,XX @@ invalid: | ||
121 | np--; | ||
122 | } | ||
123 | error_setg(errp, "Invalid extent line: %.*s", (int)(np - p), p); | ||
124 | - return -EINVAL; | ||
125 | + ret = -EINVAL; | ||
126 | + | ||
127 | +out: | ||
128 | + g_free(desc_file_dir); | ||
129 | + return ret; | ||
130 | } | ||
131 | |||
132 | static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | ||
525 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | 133 | @@ -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 | } | 134 | } |
551 | - l2_offset = extent->l1_table[l1_index]; | 135 | s->create_type = g_strdup(ct); |
552 | + if (extent->sesparse) { | 136 | s->desc_offset = 0; |
553 | + uint64_t l2_offset_u64; | 137 | - ret = vmdk_parse_extents(buf, bs, bs->file->bs->exact_filename, options, |
554 | + | 138 | - errp); |
555 | + assert(extent->entry_size == sizeof(uint64_t)); | 139 | + ret = vmdk_parse_extents(buf, bs, options, errp); |
556 | + | 140 | exit: |
557 | + l2_offset_u64 = ((uint64_t *)extent->l1_table)[l1_index]; | 141 | return ret; |
558 | + if (l2_offset_u64 == 0) { | 142 | } |
559 | + l2_offset = 0; | 143 | diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 |
560 | + } else if ((l2_offset_u64 & 0xffffffff00000000) != 0x1000000000000000) { | 144 | index XXXXXXX..XXXXXXX 100755 |
561 | + /* | 145 | --- a/tests/qemu-iotests/059 |
562 | + * Top most nibble is 0x1 if grain table is allocated. | 146 | +++ b/tests/qemu-iotests/059 |
563 | + * strict check - top most 4 bytes must be 0x10000000 since max | 147 | @@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2 |
564 | + * supported size is 64TB for disk - so no more than 64TB / 16MB | 148 | |
565 | + * grain directories which is smaller than uint32, | 149 | echo |
566 | + * where 16MB is the only supported default grain table coverage. | 150 | echo "=== Testing monolithicFlat with internally generated JSON file name ===" |
567 | + */ | 151 | +# Should work, because bdrv_dirname() works fine with blkdebug |
568 | + return VMDK_ERROR; | 152 | IMGOPTS="subformat=monolithicFlat" _make_test_img 64M |
569 | + } else { | 153 | -$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" 2>&1 \ |
570 | + l2_offset_u64 = l2_offset_u64 & 0x00000000ffffffff; | 154 | - | _filter_testdir | _filter_imgfmt |
571 | + l2_offset_u64 = extent->sesparse_l2_tables_offset + | 155 | +$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \ |
572 | + l2_offset_u64 * l2_size_bytes / SECTOR_SIZE; | 156 | + -c info \ |
573 | + if (l2_offset_u64 > 0x00000000ffffffff) { | 157 | + 2>&1 \ |
574 | + return VMDK_ERROR; | 158 | + | _filter_testdir | _filter_imgfmt | _filter_img_info |
575 | + } | 159 | _cleanup_test_img |
576 | + l2_offset = (unsigned int)(l2_offset_u64); | 160 | |
577 | + } | 161 | echo |
578 | + } else { | 162 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out |
579 | + assert(extent->entry_size == sizeof(uint32_t)); | 163 | index XXXXXXX..XXXXXXX 100644 |
580 | + l2_offset = ((uint32_t *)extent->l1_table)[l1_index]; | 164 | --- a/tests/qemu-iotests/059.out |
581 | + } | 165 | +++ b/tests/qemu-iotests/059.out |
582 | if (!l2_offset) { | 166 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 |
583 | return VMDK_UNALLOC; | 167 | |
584 | } | 168 | === Testing monolithicFlat with internally generated JSON file name === |
585 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | 169 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 |
586 | extent->l2_cache_counts[j] >>= 1; | 170 | -qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}' |
587 | } | 171 | +format name: IMGFMT |
588 | } | 172 | +cluster size: 0 bytes |
589 | - l2_table = extent->l2_cache + (i * extent->l2_size); | 173 | +vm state offset: 0 bytes |
590 | + l2_table = (char *)extent->l2_cache + (i * l2_size_bytes); | 174 | |
591 | goto found; | 175 | === Testing version 3 === |
592 | } | 176 | image: TEST_DIR/iotest-version3.IMGFMT |
593 | } | ||
594 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
595 | min_index = i; | ||
596 | } | ||
597 | } | ||
598 | - l2_table = extent->l2_cache + (min_index * extent->l2_size); | ||
599 | + l2_table = (char *)extent->l2_cache + (min_index * l2_size_bytes); | ||
600 | BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD); | ||
601 | if (bdrv_pread(extent->file, | ||
602 | (int64_t)l2_offset * 512, | ||
603 | l2_table, | ||
604 | - extent->l2_size * sizeof(uint32_t) | ||
605 | - ) != extent->l2_size * sizeof(uint32_t)) { | ||
606 | + l2_size_bytes | ||
607 | + ) != l2_size_bytes) { | ||
608 | return VMDK_ERROR; | ||
609 | } | ||
610 | |||
611 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
612 | extent->l2_cache_counts[min_index] = 1; | ||
613 | found: | ||
614 | l2_index = ((offset >> 9) / extent->cluster_sectors) % extent->l2_size; | ||
615 | - cluster_sector = le32_to_cpu(l2_table[l2_index]); | ||
616 | |||
617 | - if (extent->has_zero_grain && cluster_sector == VMDK_GTE_ZEROED) { | ||
618 | - zeroed = true; | ||
619 | + if (extent->sesparse) { | ||
620 | + cluster_sector = le64_to_cpu(((uint64_t *)l2_table)[l2_index]); | ||
621 | + switch (cluster_sector & 0xf000000000000000) { | ||
622 | + case 0x0000000000000000: | ||
623 | + /* unallocated grain */ | ||
624 | + if (cluster_sector != 0) { | ||
625 | + return VMDK_ERROR; | ||
626 | + } | ||
627 | + break; | ||
628 | + case 0x1000000000000000: | ||
629 | + /* scsi-unmapped grain - fallthrough */ | ||
630 | + case 0x2000000000000000: | ||
631 | + /* zero grain */ | ||
632 | + zeroed = true; | ||
633 | + break; | ||
634 | + case 0x3000000000000000: | ||
635 | + /* allocated grain */ | ||
636 | + cluster_sector = (((cluster_sector & 0x0fff000000000000) >> 48) | | ||
637 | + ((cluster_sector & 0x0000ffffffffffff) << 12)); | ||
638 | + cluster_sector = extent->sesparse_clusters_offset + | ||
639 | + cluster_sector * extent->cluster_sectors; | ||
640 | + break; | ||
641 | + default: | ||
642 | + return VMDK_ERROR; | ||
643 | + } | ||
644 | + } else { | ||
645 | + cluster_sector = le32_to_cpu(((uint32_t *)l2_table)[l2_index]); | ||
646 | + | ||
647 | + if (extent->has_zero_grain && cluster_sector == VMDK_GTE_ZEROED) { | ||
648 | + zeroed = true; | ||
649 | + } | ||
650 | } | ||
651 | |||
652 | if (!cluster_sector || zeroed) { | ||
653 | if (!allocate) { | ||
654 | return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; | ||
655 | } | ||
656 | + assert(!extent->sesparse); | ||
657 | |||
658 | if (extent->next_cluster_sector >= VMDK_EXTENT_MAX_SECTORS) { | ||
659 | return VMDK_ERROR; | ||
660 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
661 | m_data->l1_index = l1_index; | ||
662 | m_data->l2_index = l2_index; | ||
663 | m_data->l2_offset = l2_offset; | ||
664 | - m_data->l2_cache_entry = &l2_table[l2_index]; | ||
665 | + m_data->l2_cache_entry = ((uint32_t *)l2_table) + l2_index; | ||
666 | } | ||
667 | } | ||
668 | *cluster_offset = cluster_sector << BDRV_SECTOR_BITS; | ||
669 | @@ -XXX,XX +XXX,XX @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, | ||
670 | if (!extent) { | ||
671 | return -EIO; | ||
672 | } | ||
673 | + if (extent->sesparse) { | ||
674 | + return -ENOTSUP; | ||
675 | + } | ||
676 | offset_in_cluster = vmdk_find_offset_in_cluster(extent, offset); | ||
677 | n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE | ||
678 | - offset_in_cluster); | ||
679 | -- | 177 | -- |
680 | 2.21.0 | 178 | 2.21.0 |
681 | 179 | ||
682 | 180 | diff view generated by jsdifflib |
1 | From: Anton Nefedov <anton.nefedov@virtuozzo.com> | 1 | We had a test for a case where relative extent paths did not work, but |
---|---|---|---|
2 | unfortunately we just fixed the underlying problem, so it works now. | ||
3 | This patch adds a new test case that still fails. | ||
2 | 4 | ||
3 | COW (even empty/zero) areas require encryption too | 5 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
4 | 6 | Reviewed-by: John Snow <jsnow@redhat.com> | |
5 | Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com> | 7 | Message-id: 20190815153638.4600-4-mreitz@redhat.com |
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | 8 | Reviewed-by: John Snow <jsnow@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 | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 9 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
11 | --- | 10 | --- |
12 | tests/qemu-iotests/134 | 9 +++++++++ | 11 | tests/qemu-iotests/059 | 27 +++++++++++++++++++++++++++ |
13 | tests/qemu-iotests/134.out | 10 ++++++++++ | 12 | tests/qemu-iotests/059.out | 4 ++++ |
14 | 2 files changed, 19 insertions(+) | 13 | 2 files changed, 31 insertions(+) |
15 | 14 | ||
16 | diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 | 15 | diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 |
17 | index XXXXXXX..XXXXXXX 100755 | 16 | index XXXXXXX..XXXXXXX 100755 |
18 | --- a/tests/qemu-iotests/134 | 17 | --- a/tests/qemu-iotests/059 |
19 | +++ b/tests/qemu-iotests/134 | 18 | +++ b/tests/qemu-iotests/059 |
20 | @@ -XXX,XX +XXX,XX @@ echo | 19 | @@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2 |
21 | echo "== reading whole image ==" | 20 | |
22 | $QEMU_IO --object $SECRET -c "read 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | 21 | echo |
23 | 22 | echo "=== Testing monolithicFlat with internally generated JSON file name ===" | |
24 | +echo | ||
25 | +echo "== rewriting cluster part ==" | ||
26 | +$QEMU_IO --object $SECRET -c "write -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | ||
27 | + | 23 | + |
28 | +echo | 24 | +echo '--- blkdebug ---' |
29 | +echo "== verify pattern ==" | 25 | # Should work, because bdrv_dirname() works fine with blkdebug |
30 | +$QEMU_IO --object $SECRET -c "read -P 0 0 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | 26 | IMGOPTS="subformat=monolithicFlat" _make_test_img 64M |
31 | +$QEMU_IO --object $SECRET -c "read -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | 27 | $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \ |
28 | @@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TE | ||
29 | | _filter_testdir | _filter_imgfmt | _filter_img_info | ||
30 | _cleanup_test_img | ||
31 | |||
32 | +echo '--- quorum ---' | ||
33 | +# Should not work, because bdrv_dirname() does not work with quorum | ||
34 | +IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | ||
35 | +cp "$TEST_IMG" "$TEST_IMG.orig" | ||
36 | + | ||
37 | +filename="json:{ | ||
38 | + \"driver\": \"$IMGFMT\", | ||
39 | + \"file\": { | ||
40 | + \"driver\": \"quorum\", | ||
41 | + \"children\": [ { | ||
42 | + \"driver\": \"file\", | ||
43 | + \"filename\": \"$TEST_IMG\" | ||
44 | + }, { | ||
45 | + \"driver\": \"file\", | ||
46 | + \"filename\": \"$TEST_IMG.orig\" | ||
47 | + } ], | ||
48 | + \"vote-threshold\": 1 | ||
49 | + } }" | ||
50 | + | ||
51 | +filename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g') | ||
52 | +$QEMU_IMG info "$filename" 2>&1 \ | ||
53 | + | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \ | ||
54 | + | _filter_testdir | _filter_imgfmt | _filter_img_info | ||
55 | + | ||
32 | + | 56 | + |
33 | echo | 57 | echo |
34 | echo "== rewriting whole image ==" | 58 | echo "=== Testing version 3 ===" |
35 | $QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | 59 | _use_sample_img iotest-version3.vmdk.bz2 |
36 | diff --git a/tests/qemu-iotests/134.out b/tests/qemu-iotests/134.out | 60 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out |
37 | index XXXXXXX..XXXXXXX 100644 | 61 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/tests/qemu-iotests/134.out | 62 | --- a/tests/qemu-iotests/059.out |
39 | +++ b/tests/qemu-iotests/134.out | 63 | +++ b/tests/qemu-iotests/059.out |
40 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on encrypt. | 64 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 |
41 | read 134217728/134217728 bytes at offset 0 | 65 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
42 | 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 66 | |
43 | 67 | === Testing monolithicFlat with internally generated JSON file name === | |
44 | +== rewriting cluster part == | 68 | +--- blkdebug --- |
45 | +wrote 512/512 bytes at offset 512 | 69 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 |
46 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 70 | format name: IMGFMT |
47 | + | 71 | cluster size: 0 bytes |
48 | +== verify pattern == | 72 | vm state offset: 0 bytes |
49 | +read 512/512 bytes at offset 0 | 73 | +--- quorum --- |
50 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 74 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 |
51 | +read 512/512 bytes at offset 512 | 75 | +qemu-img: Could not open $QUORUM_FILE: Cannot use relative paths with VMDK descriptor file $QUORUM_FILE: Cannot generate a base directory for quorum nodes |
52 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 76 | |
53 | + | 77 | === Testing version 3 === |
54 | == rewriting whole image == | 78 | image: TEST_DIR/iotest-version3.IMGFMT |
55 | wrote 134217728/134217728 bytes at offset 0 | ||
56 | 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
57 | -- | 79 | -- |
58 | 2.21.0 | 80 | 2.21.0 |
59 | 81 | ||
60 | 82 | diff view generated by jsdifflib |
1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> | 1 | Compressed writes generally have to write full clusters, not just in |
---|---|---|---|
2 | theory but also in practice when it comes to vmdk's streamOptimized | ||
3 | subformat. It currently is just silently broken for writes with | ||
4 | non-zero in-cluster offsets: | ||
2 | 5 | ||
3 | Commit b0651b8c246d ("vmdk: Move l1_size check into vmdk_add_extent") | 6 | $ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M |
4 | extended the l1_size check from VMDK4 to VMDK3 but did not update the | 7 | $ qemu-io -c 'write 4k 4k' -c 'read 4k 4k' foo.vmdk |
5 | default coverage in the moved comment. | 8 | wrote 4096/4096 bytes at offset 4096 |
9 | 4 KiB, 1 ops; 00.01 sec (443.724 KiB/sec and 110.9309 ops/sec) | ||
10 | read failed: Invalid argument | ||
6 | 11 | ||
7 | The previous vmdk4 calculation: | 12 | (The technical reason is that vmdk_write_extent() just writes the |
13 | incomplete compressed data actually to offset 4k. When reading the | ||
14 | data, vmdk_read_extent() looks at offset 0 and finds the compressed data | ||
15 | size to be 0, because that is what it reads from there. This yields an | ||
16 | error.) | ||
8 | 17 | ||
9 | (512 * 1024 * 1024) * 512(l2 entries) * 65536(grain) = 16PB | 18 | For incomplete writes with zero in-cluster offsets, the error path when |
19 | reading the rest of the cluster is a bit different, but the result is | ||
20 | the same: | ||
10 | 21 | ||
11 | The added vmdk3 calculation: | 22 | $ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M |
23 | $ qemu-io -c 'write 0k 4k' -c 'read 4k 4k' foo.vmdk | ||
24 | wrote 4096/4096 bytes at offset 0 | ||
25 | 4 KiB, 1 ops; 00.01 sec (362.641 KiB/sec and 90.6603 ops/sec) | ||
26 | read failed: Invalid argument | ||
12 | 27 | ||
13 | (512 * 1024 * 1024) * 4096(l2 entries) * 512(grain) = 1PB | 28 | (Here, vmdk_read_extent() finds the data and then sees that the |
29 | uncompressed data is short.) | ||
14 | 30 | ||
15 | Adding the calculation of vmdk3 to the comment. | 31 | It is better to reject invalid writes than to make the user believe they |
32 | might have succeeded and then fail when trying to read it back. | ||
16 | 33 | ||
17 | In any case, VMware does not offer virtual disks more than 2TB for | 34 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
18 | vmdk4/vmdk3 or 64TB for the new undocumented seSparse format which is | 35 | Reviewed-by: John Snow <jsnow@redhat.com> |
19 | not implemented yet in qemu. | 36 | Message-id: 20190815153638.4600-5-mreitz@redhat.com |
20 | 37 | Reviewed-by: John Snow <jsnow@redhat.com> | |
21 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> | ||
22 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> | ||
23 | Reviewed-by: Liran Alon <liran.alon@oracle.com> | ||
24 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> | ||
25 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | ||
26 | Message-id: 20190620091057.47441-2-shmuel.eiderman@oracle.com | ||
27 | Reviewed-by: yuchenlin <yuchenlin@synology.com> | ||
28 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
29 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 38 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
30 | --- | 39 | --- |
31 | block/vmdk.c | 11 ++++++++--- | 40 | block/vmdk.c | 10 ++++++++++ |
32 | 1 file changed, 8 insertions(+), 3 deletions(-) | 41 | 1 file changed, 10 insertions(+) |
33 | 42 | ||
34 | diff --git a/block/vmdk.c b/block/vmdk.c | 43 | diff --git a/block/vmdk.c b/block/vmdk.c |
35 | index XXXXXXX..XXXXXXX 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/block/vmdk.c | 45 | --- a/block/vmdk.c |
37 | +++ b/block/vmdk.c | 46 | +++ b/block/vmdk.c |
38 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, | 47 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, |
39 | return -EFBIG; | 48 | if (extent->compressed) { |
40 | } | 49 | void *compressed_data; |
41 | if (l1_size > 512 * 1024 * 1024) { | 50 | |
42 | - /* Although with big capacity and small l1_entry_sectors, we can get a | 51 | + /* Only whole clusters */ |
43 | + /* | 52 | + if (offset_in_cluster || |
44 | + * Although with big capacity and small l1_entry_sectors, we can get a | 53 | + n_bytes > (extent->cluster_sectors * SECTOR_SIZE) || |
45 | * big l1_size, we don't want unbounded value to allocate the table. | 54 | + (n_bytes < (extent->cluster_sectors * SECTOR_SIZE) && |
46 | - * Limit it to 512M, which is 16PB for default cluster and L2 table | 55 | + offset + n_bytes != extent->end_sector * SECTOR_SIZE)) |
47 | - * size */ | 56 | + { |
48 | + * Limit it to 512M, which is: | 57 | + ret = -EINVAL; |
49 | + * 16PB - for default "Hosted Sparse Extent" (VMDK4) | 58 | + goto out; |
50 | + * cluster size: 64KB, L2 table size: 512 entries | 59 | + } |
51 | + * 1PB - for default "ESXi Host Sparse Extent" (VMDK3/vmfsSparse) | 60 | + |
52 | + * cluster size: 512B, L2 table size: 4096 entries | 61 | if (!extent->has_marker) { |
53 | + */ | 62 | ret = -EINVAL; |
54 | error_setg(errp, "L1 size too big"); | 63 | goto out; |
55 | return -EFBIG; | ||
56 | } | ||
57 | -- | 64 | -- |
58 | 2.21.0 | 65 | 2.21.0 |
59 | 66 | ||
60 | 67 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | streamOptimized does not support writes that do not span exactly one | ||
2 | cluster. Furthermore, it cannot rewrite already allocated clusters. | ||
3 | As such, many iotests do not work with it. Disable them. | ||
1 | 4 | ||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
6 | Message-id: 20190815153638.4600-6-mreitz@redhat.com | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | tests/qemu-iotests/002 | 1 + | ||
11 | tests/qemu-iotests/003 | 1 + | ||
12 | tests/qemu-iotests/005 | 3 ++- | ||
13 | tests/qemu-iotests/009 | 1 + | ||
14 | tests/qemu-iotests/010 | 1 + | ||
15 | tests/qemu-iotests/011 | 1 + | ||
16 | tests/qemu-iotests/017 | 3 ++- | ||
17 | tests/qemu-iotests/018 | 3 ++- | ||
18 | tests/qemu-iotests/019 | 3 ++- | ||
19 | tests/qemu-iotests/020 | 3 ++- | ||
20 | tests/qemu-iotests/027 | 1 + | ||
21 | tests/qemu-iotests/032 | 1 + | ||
22 | tests/qemu-iotests/033 | 1 + | ||
23 | tests/qemu-iotests/034 | 3 ++- | ||
24 | tests/qemu-iotests/037 | 3 ++- | ||
25 | tests/qemu-iotests/063 | 3 ++- | ||
26 | tests/qemu-iotests/072 | 1 + | ||
27 | tests/qemu-iotests/105 | 3 ++- | ||
28 | tests/qemu-iotests/197 | 1 + | ||
29 | tests/qemu-iotests/215 | 1 + | ||
30 | tests/qemu-iotests/251 | 1 + | ||
31 | 21 files changed, 30 insertions(+), 9 deletions(-) | ||
32 | |||
33 | diff --git a/tests/qemu-iotests/002 b/tests/qemu-iotests/002 | ||
34 | index XXXXXXX..XXXXXXX 100755 | ||
35 | --- a/tests/qemu-iotests/002 | ||
36 | +++ b/tests/qemu-iotests/002 | ||
37 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
38 | |||
39 | _supported_fmt generic | ||
40 | _supported_proto generic | ||
41 | +_unsupported_imgopts "subformat=streamOptimized" | ||
42 | |||
43 | |||
44 | size=128M | ||
45 | diff --git a/tests/qemu-iotests/003 b/tests/qemu-iotests/003 | ||
46 | index XXXXXXX..XXXXXXX 100755 | ||
47 | --- a/tests/qemu-iotests/003 | ||
48 | +++ b/tests/qemu-iotests/003 | ||
49 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
50 | |||
51 | _supported_fmt generic | ||
52 | _supported_proto generic | ||
53 | +_unsupported_imgopts "subformat=streamOptimized" | ||
54 | |||
55 | size=128M | ||
56 | offset=67M | ||
57 | diff --git a/tests/qemu-iotests/005 b/tests/qemu-iotests/005 | ||
58 | index XXXXXXX..XXXXXXX 100755 | ||
59 | --- a/tests/qemu-iotests/005 | ||
60 | +++ b/tests/qemu-iotests/005 | ||
61 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
62 | _supported_proto generic | ||
63 | _supported_os Linux | ||
64 | _unsupported_imgopts "subformat=twoGbMaxExtentFlat" \ | ||
65 | - "subformat=twoGbMaxExtentSparse" | ||
66 | + "subformat=twoGbMaxExtentSparse" \ | ||
67 | + "subformat=streamOptimized" | ||
68 | |||
69 | # vpc is limited to 127GB, so we can't test it here | ||
70 | if [ "$IMGFMT" = "vpc" ]; then | ||
71 | diff --git a/tests/qemu-iotests/009 b/tests/qemu-iotests/009 | ||
72 | index XXXXXXX..XXXXXXX 100755 | ||
73 | --- a/tests/qemu-iotests/009 | ||
74 | +++ b/tests/qemu-iotests/009 | ||
75 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
76 | |||
77 | _supported_fmt generic | ||
78 | _supported_proto generic | ||
79 | +_unsupported_imgopts "subformat=streamOptimized" | ||
80 | |||
81 | |||
82 | size=6G | ||
83 | diff --git a/tests/qemu-iotests/010 b/tests/qemu-iotests/010 | ||
84 | index XXXXXXX..XXXXXXX 100755 | ||
85 | --- a/tests/qemu-iotests/010 | ||
86 | +++ b/tests/qemu-iotests/010 | ||
87 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
88 | |||
89 | _supported_fmt generic | ||
90 | _supported_proto generic | ||
91 | +_unsupported_imgopts "subformat=streamOptimized" | ||
92 | |||
93 | |||
94 | size=6G | ||
95 | diff --git a/tests/qemu-iotests/011 b/tests/qemu-iotests/011 | ||
96 | index XXXXXXX..XXXXXXX 100755 | ||
97 | --- a/tests/qemu-iotests/011 | ||
98 | +++ b/tests/qemu-iotests/011 | ||
99 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
100 | |||
101 | _supported_fmt generic | ||
102 | _supported_proto generic | ||
103 | +_unsupported_imgopts "subformat=streamOptimized" | ||
104 | |||
105 | |||
106 | size=6G | ||
107 | diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017 | ||
108 | index XXXXXXX..XXXXXXX 100755 | ||
109 | --- a/tests/qemu-iotests/017 | ||
110 | +++ b/tests/qemu-iotests/017 | ||
111 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
112 | _supported_fmt qcow qcow2 vmdk qed | ||
113 | _supported_proto generic | ||
114 | _unsupported_proto vxhs | ||
115 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
116 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
117 | + "subformat=streamOptimized" | ||
118 | |||
119 | TEST_OFFSETS="0 4294967296" | ||
120 | |||
121 | diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018 | ||
122 | index XXXXXXX..XXXXXXX 100755 | ||
123 | --- a/tests/qemu-iotests/018 | ||
124 | +++ b/tests/qemu-iotests/018 | ||
125 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
126 | _supported_fmt qcow qcow2 vmdk qed | ||
127 | _supported_proto file | ||
128 | _supported_os Linux | ||
129 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
130 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
131 | + "streamOptimized" | ||
132 | |||
133 | TEST_OFFSETS="0 4294967296" | ||
134 | |||
135 | diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019 | ||
136 | index XXXXXXX..XXXXXXX 100755 | ||
137 | --- a/tests/qemu-iotests/019 | ||
138 | +++ b/tests/qemu-iotests/019 | ||
139 | @@ -XXX,XX +XXX,XX @@ _supported_proto file | ||
140 | _supported_os Linux | ||
141 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
142 | "subformat=twoGbMaxExtentFlat" \ | ||
143 | - "subformat=twoGbMaxExtentSparse" | ||
144 | + "subformat=twoGbMaxExtentSparse" \ | ||
145 | + "subformat=streamOptimized" | ||
146 | |||
147 | TEST_OFFSETS="0 4294967296" | ||
148 | CLUSTER_SIZE=65536 | ||
149 | diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 | ||
150 | index XXXXXXX..XXXXXXX 100755 | ||
151 | --- a/tests/qemu-iotests/020 | ||
152 | +++ b/tests/qemu-iotests/020 | ||
153 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed | ||
154 | _supported_proto file | ||
155 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
156 | "subformat=twoGbMaxExtentFlat" \ | ||
157 | - "subformat=twoGbMaxExtentSparse" | ||
158 | + "subformat=twoGbMaxExtentSparse" \ | ||
159 | + "subformat=streamOptimized" | ||
160 | |||
161 | TEST_OFFSETS="0 4294967296" | ||
162 | |||
163 | diff --git a/tests/qemu-iotests/027 b/tests/qemu-iotests/027 | ||
164 | index XXXXXXX..XXXXXXX 100755 | ||
165 | --- a/tests/qemu-iotests/027 | ||
166 | +++ b/tests/qemu-iotests/027 | ||
167 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
168 | |||
169 | _supported_fmt vmdk qcow qcow2 qed | ||
170 | _supported_proto generic | ||
171 | +_unsupported_imgopts "subformat=streamOptimized" | ||
172 | |||
173 | |||
174 | size=128M | ||
175 | diff --git a/tests/qemu-iotests/032 b/tests/qemu-iotests/032 | ||
176 | index XXXXXXX..XXXXXXX 100755 | ||
177 | --- a/tests/qemu-iotests/032 | ||
178 | +++ b/tests/qemu-iotests/032 | ||
179 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
180 | # This works for any image format (though unlikely to segfault for raw) | ||
181 | _supported_fmt generic | ||
182 | _supported_proto generic | ||
183 | +_unsupported_imgopts "subformat=streamOptimized" | ||
184 | |||
185 | echo | ||
186 | echo === Prepare image === | ||
187 | diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 | ||
188 | index XXXXXXX..XXXXXXX 100755 | ||
189 | --- a/tests/qemu-iotests/033 | ||
190 | +++ b/tests/qemu-iotests/033 | ||
191 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
192 | |||
193 | _supported_fmt generic | ||
194 | _supported_proto generic | ||
195 | +_unsupported_imgopts "subformat=streamOptimized" | ||
196 | |||
197 | |||
198 | size=128M | ||
199 | diff --git a/tests/qemu-iotests/034 b/tests/qemu-iotests/034 | ||
200 | index XXXXXXX..XXXXXXX 100755 | ||
201 | --- a/tests/qemu-iotests/034 | ||
202 | +++ b/tests/qemu-iotests/034 | ||
203 | @@ -XXX,XX +XXX,XX @@ _supported_proto file | ||
204 | _supported_os Linux | ||
205 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
206 | "subformat=twoGbMaxExtentFlat" \ | ||
207 | - "subformat=twoGbMaxExtentSparse" | ||
208 | + "subformat=twoGbMaxExtentSparse" \ | ||
209 | + "subformat=streamOptimized" | ||
210 | |||
211 | CLUSTER_SIZE=4k | ||
212 | size=128M | ||
213 | diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037 | ||
214 | index XXXXXXX..XXXXXXX 100755 | ||
215 | --- a/tests/qemu-iotests/037 | ||
216 | +++ b/tests/qemu-iotests/037 | ||
217 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed | ||
218 | _supported_proto file | ||
219 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
220 | "subformat=twoGbMaxExtentFlat" \ | ||
221 | - "subformat=twoGbMaxExtentSparse" | ||
222 | + "subformat=twoGbMaxExtentSparse" \ | ||
223 | + "subformat=streamOptimized" | ||
224 | |||
225 | CLUSTER_SIZE=4k | ||
226 | size=128M | ||
227 | diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063 | ||
228 | index XXXXXXX..XXXXXXX 100755 | ||
229 | --- a/tests/qemu-iotests/063 | ||
230 | +++ b/tests/qemu-iotests/063 | ||
231 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed raw | ||
232 | _supported_proto file | ||
233 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
234 | "subformat=twoGbMaxExtentFlat" \ | ||
235 | - "subformat=twoGbMaxExtentSparse" | ||
236 | + "subformat=twoGbMaxExtentSparse" \ | ||
237 | + "subformat=streamOptimized" | ||
238 | |||
239 | _make_test_img 4M | ||
240 | |||
241 | diff --git a/tests/qemu-iotests/072 b/tests/qemu-iotests/072 | ||
242 | index XXXXXXX..XXXXXXX 100755 | ||
243 | --- a/tests/qemu-iotests/072 | ||
244 | +++ b/tests/qemu-iotests/072 | ||
245 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
246 | |||
247 | _supported_fmt vpc vmdk vhdx vdi qed qcow2 qcow | ||
248 | _supported_proto file | ||
249 | +_unsupported_imgopts "subformat=streamOptimized" | ||
250 | |||
251 | IMG_SIZE=64M | ||
252 | |||
253 | diff --git a/tests/qemu-iotests/105 b/tests/qemu-iotests/105 | ||
254 | index XXXXXXX..XXXXXXX 100755 | ||
255 | --- a/tests/qemu-iotests/105 | ||
256 | +++ b/tests/qemu-iotests/105 | ||
257 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
258 | _supported_fmt qcow2 vmdk vhdx qed | ||
259 | _supported_proto generic | ||
260 | _unsupported_imgopts "subformat=twoGbMaxExtentFlat" \ | ||
261 | - "subformat=twoGbMaxExtentSparse" | ||
262 | + "subformat=twoGbMaxExtentSparse" \ | ||
263 | + "subformat=streamOptimized" | ||
264 | |||
265 | echo | ||
266 | echo "creating large image" | ||
267 | diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 | ||
268 | index XXXXXXX..XXXXXXX 100755 | ||
269 | --- a/tests/qemu-iotests/197 | ||
270 | +++ b/tests/qemu-iotests/197 | ||
271 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
272 | _supported_proto generic | ||
273 | # LUKS support may be possible, but it complicates things. | ||
274 | _unsupported_fmt luks | ||
275 | +_unsupported_imgopts "subformat=streamOptimized" | ||
276 | |||
277 | echo | ||
278 | echo '=== Copy-on-read ===' | ||
279 | diff --git a/tests/qemu-iotests/215 b/tests/qemu-iotests/215 | ||
280 | index XXXXXXX..XXXXXXX 100755 | ||
281 | --- a/tests/qemu-iotests/215 | ||
282 | +++ b/tests/qemu-iotests/215 | ||
283 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
284 | _supported_proto generic | ||
285 | # LUKS support may be possible, but it complicates things. | ||
286 | _unsupported_fmt luks | ||
287 | +_unsupported_imgopts "subformat=streamOptimized" | ||
288 | |||
289 | echo | ||
290 | echo '=== Copy-on-read ===' | ||
291 | diff --git a/tests/qemu-iotests/251 b/tests/qemu-iotests/251 | ||
292 | index XXXXXXX..XXXXXXX 100755 | ||
293 | --- a/tests/qemu-iotests/251 | ||
294 | +++ b/tests/qemu-iotests/251 | ||
295 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
296 | _supported_fmt generic | ||
297 | _supported_proto file | ||
298 | _supported_os Linux | ||
299 | +_unsupported_imgopts "subformat=streamOptimized" | ||
300 | |||
301 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
302 | # We use json:{} filenames here, so we cannot work with additional options. | ||
303 | -- | ||
304 | 2.21.0 | ||
305 | |||
306 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The error message for the test case where we have a quorum node for | ||
2 | which no directory name can be generated is different: For | ||
3 | twoGbMaxExtentSparse, it complains that it cannot open the extent file. | ||
4 | For other (sub)formats, it just notes that it cannot determine the | ||
5 | backing file path. Both are fine, but just disable twoGbMaxExtentSparse | ||
6 | for simplicity's sake. | ||
1 | 7 | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Message-id: 20190815153638.4600-7-mreitz@redhat.com | ||
11 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | --- | ||
14 | tests/qemu-iotests/110 | 3 ++- | ||
15 | 1 file changed, 2 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110 | ||
18 | index XXXXXXX..XXXXXXX 100755 | ||
19 | --- a/tests/qemu-iotests/110 | ||
20 | +++ b/tests/qemu-iotests/110 | ||
21 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
22 | # Any format supporting backing files | ||
23 | _supported_fmt qed qcow qcow2 vmdk | ||
24 | _supported_proto file | ||
25 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
26 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
27 | + "subformat=twoGbMaxExtentSparse" | ||
28 | |||
29 | TEST_IMG_REL=$(basename "$TEST_IMG") | ||
30 | |||
31 | -- | ||
32 | 2.21.0 | ||
33 | |||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | iotest 126 requires backing file support, which flat vmdks cannot offer. | ||
2 | Skip this test for such subformats. | ||
1 | 3 | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
5 | Message-id: 20190815153638.4600-8-mreitz@redhat.com | ||
6 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
8 | --- | ||
9 | tests/qemu-iotests/126 | 2 ++ | ||
10 | 1 file changed, 2 insertions(+) | ||
11 | |||
12 | diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126 | ||
13 | index XXXXXXX..XXXXXXX 100755 | ||
14 | --- a/tests/qemu-iotests/126 | ||
15 | +++ b/tests/qemu-iotests/126 | ||
16 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
17 | |||
18 | # Needs backing file support | ||
19 | _supported_fmt qcow qcow2 qed vmdk | ||
20 | +_unsupported_imgopts "subformat=monolithicFlat" \ | ||
21 | + "subformat=twoGbMaxExtentFlat" | ||
22 | # This is the default protocol (and we want to test the difference between | ||
23 | # colons which separate a protocol prefix from the rest and colons which are | ||
24 | # just part of the filename, so we cannot test protocols which require a prefix) | ||
25 | -- | ||
26 | 2.21.0 | ||
27 | |||
28 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Stefan Hajnoczi <stefanha@redhat.com> | ||
1 | 2 | ||
3 | Fixes: a6b257a08e3d72219f03e461a52152672fec0612 | ||
4 | ("file-posix: Handle undetectable alignment") | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Message-id: 20190827101328.4062-1-stefanha@redhat.com | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | block/file-posix.c | 2 +- | ||
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/block/file-posix.c | ||
16 | +++ b/block/file-posix.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) | ||
18 | for (i = 0; i < ARRAY_SIZE(alignments); i++) { | ||
19 | align = alignments[i]; | ||
20 | if (raw_is_io_aligned(fd, buf + align, max_align)) { | ||
21 | - /* Fallback to request_aligment. */ | ||
22 | + /* Fallback to request_alignment. */ | ||
23 | s->buf_align = (align != 1) ? align : bs->bl.request_alignment; | ||
24 | break; | ||
25 | } | ||
26 | -- | ||
27 | 2.21.0 | ||
28 | |||
29 | diff view generated by jsdifflib |
1 | Tests should place their files into the test directory. This includes | 1 | Without this argument, qemu will print an angry message about not being |
---|---|---|---|
2 | Unix sockets. 205 currently fails to do so, which prevents it from | 2 | able to connect to a display server if $DISPLAY is not set. For me, |
3 | being run concurrently. | 3 | that breaks iotests.supported_formats() because it thus only sees |
4 | ["Could", "not", "connect"] as the supported formats. | ||
4 | 5 | ||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 6 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
6 | Message-id: 20190618210238.9524-1-mreitz@redhat.com | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | 8 | Message-id: 20190819201851.24418-2-mreitz@redhat.com |
9 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 10 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
9 | --- | 11 | --- |
10 | tests/qemu-iotests/205 | 2 +- | 12 | tests/qemu-iotests/check | 6 +++--- |
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | 13 | 1 file changed, 3 insertions(+), 3 deletions(-) |
12 | 14 | ||
13 | diff --git a/tests/qemu-iotests/205 b/tests/qemu-iotests/205 | 15 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check |
14 | index XXXXXXX..XXXXXXX 100755 | 16 | index XXXXXXX..XXXXXXX 100755 |
15 | --- a/tests/qemu-iotests/205 | 17 | --- a/tests/qemu-iotests/check |
16 | +++ b/tests/qemu-iotests/205 | 18 | +++ b/tests/qemu-iotests/check |
17 | @@ -XXX,XX +XXX,XX @@ import iotests | 19 | @@ -XXX,XX +XXX,XX @@ export QEMU_PROG="$(type -p "$QEMU_PROG")" |
18 | import time | 20 | |
19 | from iotests import qemu_img_create, qemu_io, filter_qemu_io, QemuIoInteractive | 21 | case "$QEMU_PROG" in |
20 | 22 | *qemu-system-arm|*qemu-system-aarch64) | |
21 | -nbd_sock = 'nbd_sock' | 23 | - export QEMU_OPTIONS="-nodefaults -machine virt,accel=qtest" |
22 | +nbd_sock = os.path.join(iotests.test_dir, 'nbd_sock') | 24 | + export QEMU_OPTIONS="-nodefaults -display none -machine virt,accel=qtest" |
23 | nbd_uri = 'nbd+unix:///exp?socket=' + nbd_sock | 25 | ;; |
24 | disk = os.path.join(iotests.test_dir, 'disk') | 26 | *qemu-system-tricore) |
27 | - export QEMU_OPTIONS="-nodefaults -machine tricore_testboard,accel=qtest" | ||
28 | + export QEMU_OPTIONS="-nodefaults -display none -machine tricore_testboard,accel=qtest" | ||
29 | ;; | ||
30 | *) | ||
31 | - export QEMU_OPTIONS="-nodefaults -machine accel=qtest" | ||
32 | + export QEMU_OPTIONS="-nodefaults -display none -machine accel=qtest" | ||
33 | ;; | ||
34 | esac | ||
25 | 35 | ||
26 | -- | 36 | -- |
27 | 2.21.0 | 37 | 2.21.0 |
28 | 38 | ||
29 | 39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | It is possible to enable only a subset of the block drivers with the | ||
4 | "--block-drv-rw-whitelist" option of the "configure" script. All other | ||
5 | drivers are marked as unusable (or only included as read-only with the | ||
6 | "--block-drv-ro-whitelist" option). If an iotest is now using such a | ||
7 | disabled block driver, it is failing - which is bad, since at least the | ||
8 | tests in the "auto" group should be able to deal with this situation. | ||
9 | Thus let's introduce a "_require_drivers" function that can be used by | ||
10 | the shell tests to check for the availability of certain drivers first, | ||
11 | and marks the test as "not run" if one of the drivers is missing. | ||
12 | |||
13 | This patch mainly targets the test in the "auto" group which should | ||
14 | never fail in such a case, but also improves some of the other tests | ||
15 | along the way. Note that we also assume that the "qcow2" and "file" | ||
16 | drivers are always available - otherwise it does not make sense to | ||
17 | run "make check-block" at all (which only tests with qcow2 by default). | ||
18 | |||
19 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
20 | Message-id: 20190823133552.11680-1-thuth@redhat.com | ||
21 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
22 | --- | ||
23 | tests/qemu-iotests/071 | 1 + | ||
24 | tests/qemu-iotests/081 | 4 +--- | ||
25 | tests/qemu-iotests/099 | 1 + | ||
26 | tests/qemu-iotests/120 | 1 + | ||
27 | tests/qemu-iotests/162 | 4 +--- | ||
28 | tests/qemu-iotests/184 | 1 + | ||
29 | tests/qemu-iotests/186 | 1 + | ||
30 | tests/qemu-iotests/common.rc | 14 ++++++++++++++ | ||
31 | 8 files changed, 21 insertions(+), 6 deletions(-) | ||
32 | |||
33 | diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071 | ||
34 | index XXXXXXX..XXXXXXX 100755 | ||
35 | --- a/tests/qemu-iotests/071 | ||
36 | +++ b/tests/qemu-iotests/071 | ||
37 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
38 | |||
39 | _supported_fmt qcow2 | ||
40 | _supported_proto file | ||
41 | +_require_drivers blkdebug blkverify | ||
42 | |||
43 | do_run_qemu() | ||
44 | { | ||
45 | diff --git a/tests/qemu-iotests/081 b/tests/qemu-iotests/081 | ||
46 | index XXXXXXX..XXXXXXX 100755 | ||
47 | --- a/tests/qemu-iotests/081 | ||
48 | +++ b/tests/qemu-iotests/081 | ||
49 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
50 | _supported_fmt raw | ||
51 | _supported_proto file | ||
52 | _supported_os Linux | ||
53 | +_require_drivers quorum | ||
54 | |||
55 | do_run_qemu() | ||
56 | { | ||
57 | @@ -XXX,XX +XXX,XX @@ run_qemu() | ||
58 | | _filter_qemu_io | _filter_generated_node_ids | ||
59 | } | ||
60 | |||
61 | -test_quorum=$($QEMU_IMG --help|grep quorum) | ||
62 | -[ "$test_quorum" = "" ] && _supported_fmt quorum | ||
63 | - | ||
64 | quorum="driver=raw,file.driver=quorum,file.vote-threshold=2" | ||
65 | quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" | ||
66 | quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" | ||
67 | diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099 | ||
68 | index XXXXXXX..XXXXXXX 100755 | ||
69 | --- a/tests/qemu-iotests/099 | ||
70 | +++ b/tests/qemu-iotests/099 | ||
71 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
72 | _supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc | ||
73 | _supported_proto file | ||
74 | _supported_os Linux | ||
75 | +_require_drivers blkdebug blkverify | ||
76 | _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
77 | "subformat=twoGbMaxExtentSparse" | ||
78 | |||
79 | diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120 | ||
80 | index XXXXXXX..XXXXXXX 100755 | ||
81 | --- a/tests/qemu-iotests/120 | ||
82 | +++ b/tests/qemu-iotests/120 | ||
83 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
84 | _supported_fmt generic | ||
85 | _supported_proto file | ||
86 | _unsupported_fmt luks | ||
87 | +_require_drivers raw | ||
88 | |||
89 | _make_test_img 64M | ||
90 | |||
91 | diff --git a/tests/qemu-iotests/162 b/tests/qemu-iotests/162 | ||
92 | index XXXXXXX..XXXXXXX 100755 | ||
93 | --- a/tests/qemu-iotests/162 | ||
94 | +++ b/tests/qemu-iotests/162 | ||
95 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
96 | . ./common.filter | ||
97 | |||
98 | _supported_fmt generic | ||
99 | - | ||
100 | -test_ssh=$($QEMU_IMG --help | grep '^Supported formats:.* ssh\( \|$\)') | ||
101 | -[ "$test_ssh" = "" ] && _notrun "ssh support required" | ||
102 | +_require_drivers ssh | ||
103 | |||
104 | echo | ||
105 | echo '=== NBD ===' | ||
106 | diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184 | ||
107 | index XXXXXXX..XXXXXXX 100755 | ||
108 | --- a/tests/qemu-iotests/184 | ||
109 | +++ b/tests/qemu-iotests/184 | ||
110 | @@ -XXX,XX +XXX,XX @@ trap "exit \$status" 0 1 2 3 15 | ||
111 | . ./common.filter | ||
112 | |||
113 | _supported_os Linux | ||
114 | +_require_drivers throttle | ||
115 | |||
116 | do_run_qemu() | ||
117 | { | ||
118 | diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186 | ||
119 | index XXXXXXX..XXXXXXX 100755 | ||
120 | --- a/tests/qemu-iotests/186 | ||
121 | +++ b/tests/qemu-iotests/186 | ||
122 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
123 | |||
124 | _supported_fmt qcow2 | ||
125 | _supported_proto file | ||
126 | +_require_drivers null-co | ||
127 | |||
128 | if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then | ||
129 | _notrun "Requires a PC machine" | ||
130 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/tests/qemu-iotests/common.rc | ||
133 | +++ b/tests/qemu-iotests/common.rc | ||
134 | @@ -XXX,XX +XXX,XX @@ _require_command() | ||
135 | [ -x "$c" ] || _notrun "$1 utility required, skipped this test" | ||
136 | } | ||
137 | |||
138 | +# Check that a set of drivers has been whitelisted in the QEMU binary | ||
139 | +# | ||
140 | +_require_drivers() | ||
141 | +{ | ||
142 | + available=$($QEMU -drive format=help | \ | ||
143 | + sed -e '/Supported formats:/!d' -e 's/Supported formats://') | ||
144 | + for driver | ||
145 | + do | ||
146 | + if ! echo "$available" | grep -q " $driver\( \|$\)"; then | ||
147 | + _notrun "$driver not available" | ||
148 | + fi | ||
149 | + done | ||
150 | +} | ||
151 | + | ||
152 | # make sure this script returns success | ||
153 | true | ||
154 | -- | ||
155 | 2.21.0 | ||
156 | |||
157 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | The sanitizers (especially the address sanitizer from Clang) are | ||
4 | sometimes printing out warnings or false positives - this spoils | ||
5 | the output of the iotests, causing some of the tests to fail. | ||
6 | Thus let's skip the automatic iotests during "make check" when the | ||
7 | user configured QEMU with --enable-sanitizers. | ||
8 | |||
9 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
10 | Message-id: 20190823084203.29734-1-thuth@redhat.com | ||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
12 | --- | ||
13 | tests/check-block.sh | 5 +++++ | ||
14 | 1 file changed, 5 insertions(+) | ||
15 | |||
16 | diff --git a/tests/check-block.sh b/tests/check-block.sh | ||
17 | index XXXXXXX..XXXXXXX 100755 | ||
18 | --- a/tests/check-block.sh | ||
19 | +++ b/tests/check-block.sh | ||
20 | @@ -XXX,XX +XXX,XX @@ if grep -q "TARGET_GPROF=y" *-softmmu/config-target.mak 2>/dev/null ; then | ||
21 | exit 0 | ||
22 | fi | ||
23 | |||
24 | +if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then | ||
25 | + echo "Sanitizers are enabled ==> Not running the qemu-iotests." | ||
26 | + exit 0 | ||
27 | +fi | ||
28 | + | ||
29 | if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then | ||
30 | echo "No qemu-system binary available ==> Not running the qemu-iotests." | ||
31 | exit 0 | ||
32 | -- | ||
33 | 2.21.0 | ||
34 | |||
35 | diff view generated by jsdifflib |
1 | From: Klaus Birkelund Jensen <klaus@birkelund.eu> | 1 | From: Nir Soffer <nirsof@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The device mistakenly reports that the Weighted Round Robin with Urgent | 3 | Quoting cache mode is not needed, and most tests use unquoted values. |
4 | Priority Class arbitration mechanism is supported. | 4 | Unify all test to use the same style. |
5 | 5 | ||
6 | It is not. | 6 | Message-id: 20190827173432.7656-1-nsoffer@redhat.com |
7 | 7 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | |
8 | Signed-off-by: Klaus Birkelund Jensen <klaus.jensen@cnexlabs.com> | ||
9 | Message-id: 20190606092530.14206-1-klaus@birkelund.eu | ||
10 | Acked-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 8 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
12 | --- | 9 | --- |
13 | hw/block/nvme.c | 1 - | 10 | tests/qemu-iotests/026 | 4 ++-- |
14 | 1 file changed, 1 deletion(-) | 11 | tests/qemu-iotests/039 | 4 ++-- |
12 | tests/qemu-iotests/052 | 2 +- | ||
13 | tests/qemu-iotests/091 | 4 ++-- | ||
14 | 4 files changed, 7 insertions(+), 7 deletions(-) | ||
15 | 15 | ||
16 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c | 16 | diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026 |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100755 |
18 | --- a/hw/block/nvme.c | 18 | --- a/tests/qemu-iotests/026 |
19 | +++ b/hw/block/nvme.c | 19 | +++ b/tests/qemu-iotests/026 |
20 | @@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) | 20 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 |
21 | n->bar.cap = 0; | 21 | # Currently only qcow2 supports rebasing |
22 | NVME_CAP_SET_MQES(n->bar.cap, 0x7ff); | 22 | _supported_fmt qcow2 |
23 | NVME_CAP_SET_CQR(n->bar.cap, 1); | 23 | _supported_proto file |
24 | - NVME_CAP_SET_AMS(n->bar.cap, 1); | 24 | -_default_cache_mode "writethrough" |
25 | NVME_CAP_SET_TO(n->bar.cap, 0xf); | 25 | -_supported_cache_modes "writethrough" "none" |
26 | NVME_CAP_SET_CSS(n->bar.cap, 1); | 26 | +_default_cache_mode writethrough |
27 | NVME_CAP_SET_MPSMAX(n->bar.cap, 4); | 27 | +_supported_cache_modes writethrough none |
28 | # The refcount table tests expect a certain minimum width for refcount entries | ||
29 | # (so that the refcount table actually needs to grow); that minimum is 16 bits, | ||
30 | # being the default refcount entry width. | ||
31 | diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039 | ||
32 | index XXXXXXX..XXXXXXX 100755 | ||
33 | --- a/tests/qemu-iotests/039 | ||
34 | +++ b/tests/qemu-iotests/039 | ||
35 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
36 | _supported_fmt qcow2 | ||
37 | _supported_proto file | ||
38 | _supported_os Linux | ||
39 | -_default_cache_mode "writethrough" | ||
40 | -_supported_cache_modes "writethrough" | ||
41 | +_default_cache_mode writethrough | ||
42 | +_supported_cache_modes writethrough | ||
43 | |||
44 | size=128M | ||
45 | |||
46 | diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052 | ||
47 | index XXXXXXX..XXXXXXX 100755 | ||
48 | --- a/tests/qemu-iotests/052 | ||
49 | +++ b/tests/qemu-iotests/052 | ||
50 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
51 | _supported_proto file | ||
52 | |||
53 | # Don't do O_DIRECT on tmpfs | ||
54 | -_supported_cache_modes "writeback" "writethrough" "unsafe" | ||
55 | +_supported_cache_modes writeback writethrough unsafe | ||
56 | |||
57 | size=128M | ||
58 | _make_test_img $size | ||
59 | diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091 | ||
60 | index XXXXXXX..XXXXXXX 100755 | ||
61 | --- a/tests/qemu-iotests/091 | ||
62 | +++ b/tests/qemu-iotests/091 | ||
63 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
64 | _supported_fmt qcow2 | ||
65 | _supported_proto file | ||
66 | _supported_os Linux | ||
67 | -_default_cache_mode "none" | ||
68 | -_supported_cache_modes "writethrough" "none" "writeback" | ||
69 | +_default_cache_mode none | ||
70 | +_supported_cache_modes writethrough none writeback | ||
71 | |||
72 | size=1G | ||
73 | |||
28 | -- | 74 | -- |
29 | 2.21.0 | 75 | 2.21.0 |
30 | 76 | ||
31 | 77 | diff view generated by jsdifflib |