[PATCH v6 10/10] qemu-img: Deprecate use of -b without -F

2020-07-06 Thread Eric Blake
Creating an image that requires format probing of the backing image is
potentially unsafe (we've had several CVEs over the years based on
probes leaking information to the guest on a subsequent boot, although
these days tools like libvirt are aware of the issue enough to prevent
the worst effects).  For example, if our probing algorithm ever
changes, or if other tools like libvirt determine a different probe
result than we do, then subsequent use of that backing file under a
different format will present corrupted data to the guest.
Fortunately, the worst effects occur only when the backing image is
originally raw, and we at least prevent commit into a probed raw
backing file that would change its probed type.

Still, it is worth starting a deprecation clock so that future
qemu-img can refuse to create backing chains that would rely on
probing, to encourage clients to avoid unsafe practices.  Most
warnings are intentionally emitted from bdrv_img_create() in the block
layer, but qemu-img convert uses bdrv_create() which cannot emit its
own warning without causing spurious warnings on other code paths.  In
the end, all command-line image creation or backing file rewriting now
performs a check.

Furthermore, if we probe a backing file as non-raw, then it is safe to
explicitly record that result (rather than relying on future probes);
only where we probe a raw image do we care about further warnings to
the user when using such an image (for example, commits into a
probed-raw backing file are prevented), to help them improve their
tooling.  But whether or not we make the probe results explicit, we
still warn the user to remind them to upgrade their workflow to supply
-F always.

iotest 114 specifically wants to create an unsafe image for later
amendment rather than defaulting to our new default of recording a
probed format, so it needs an update.  While touching it, expand it to
cover all of the various warnings enabled by this patch.  iotest 293
also shows a change to qcow messages.

Signed-off-by: Eric Blake 
---
 docs/system/deprecated.rst | 20 
 block.c| 27 ++-
 qemu-img.c |  9 -
 tests/qemu-iotests/114 | 12 
 tests/qemu-iotests/114.out |  9 +
 tests/qemu-iotests/293.out |  4 +++-
 6 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index b312ad27aa04..ca994e3ef53a 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -430,6 +430,26 @@ image).  Rather, any changes to the backing chain should 
be performed
 with ``qemu-img rebase -u`` either before or after the remaining
 changes being performed by amend, as appropriate.

+qemu-img backing file without format (since 5.1)
+
+
+The use of ``qemu-img create``, ``qemu-img rebase``, or ``qemu-img
+convert`` to create or modify an image that depends on a backing file
+now recommends that an explicit backing format be provided.  This is
+for safety: if QEMU probes a different format than what you thought,
+the data presented to the guest will be corrupt; similarly, presenting
+a raw image to a guest allows a potential security exploit if a future
+probe sees a non-raw image based on guest writes.
+
+To avoid the warning message, or even future refusal to create an
+unsafe image, you must pass ``-o backing_fmt=`` (or the shorthand
+``-F`` during create) to specify the intended backing format.  You may
+use ``qemu-img rebase -u`` to retroactively add a backing format to an
+existing image.  However, be aware that there are already potential
+security risks to blindly using ``qemu-img info`` to probe the format
+of an untrusted backing image, when deciding what format to add into
+an existing image.
+
 Backwards compatibility
 ---

diff --git a/block.c b/block.c
index 5cfd10f6b45e..aad3b3635e6b 100644
--- a/block.c
+++ b/block.c
@@ -6161,6 +6161,26 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 error_append_hint(_err, "Could not open backing image.\n");
 goto out;
 } else {
+if (!backing_fmt) {
+warn_report("Deprecated use of backing file without explicit "
+"backing format (detected format of %s)",
+bs->drv->format_name);
+if (bs->drv != _raw) {
+/*
+ * A probe of raw deserves the most attention:
+ * leaving the backing format out of the image
+ * will ensure bs->probed is set (ensuring we
+ * don't accidentally commit into the backing
+ * file), and allow more spots to warn the users
+ * to fix their toolchain when opening this image
+ * later.  For other images, we can safely record
+

[PATCH v6 07/10] qcow2: Deprecate use of qemu-img amend to change backing file

2020-07-06 Thread Eric Blake
The use of 'qemu-img amend' to change qcow2 backing files is not
tested very well.  In particular, our implementation has a bug where
if a new backing file is provided without a format, then the prior
format is blindly reused, even if this results in data corruption, but
this is not caught by iotests.

There are also situations where amending other options needs access to
the original backing file (for example, on a downgrade to a v2 image,
knowing whether a v3 zero cluster must be allocated or may be left
unallocated depends on knowing whether the backing file already reads
as zero), but the command line does not have a nice way to tell us
both the backing file to use for opening the image as well as the
backing file to install after the operation is complete.

Even if we do allow changing the backing file, it is redundant with
the existing ability to change backing files via 'qemu-img rebase -u'.
It is time to deprecate this support (leaving the existing behavior
intact, even if it is buggy), and at a point in the future, require
the use of only 'qemu-img rebase' for adjusting backing chain
relations, saving 'qemu-img amend' for changes unrelated to the
backing chain.

Signed-off-by: Eric Blake 
---
 docs/system/deprecated.rst | 12 
 docs/tools/qemu-img.rst|  4 
 block/qcow2.c  |  5 +
 tests/qemu-iotests/061.out |  1 +
 tests/qemu-iotests/082.out |  2 ++
 5 files changed, 24 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 6fbec34b8b37..b312ad27aa04 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -418,6 +418,18 @@ kernel in 2018, and has also been dropped from glibc.
 Related binaries
 

+qemu-img amend to adjust backing file (since 5.1)
+'
+
+The use of ``qemu-img amend`` to modify the name or format of a qcow2
+backing image is deprecated; this functionality was never fully
+documented or tested, and interferes with other amend operations that
+need access to the original backing image (such as deciding whether a
+v3 zero cluster may be left unallocated when converting to a v2
+image).  Rather, any changes to the backing chain should be performed
+with ``qemu-img rebase -u`` either before or after the remaining
+changes being performed by amend, as appropriate.
+
 Backwards compatibility
 ---

diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst
index 7f0737488ade..fa53e30697e7 100644
--- a/docs/tools/qemu-img.rst
+++ b/docs/tools/qemu-img.rst
@@ -258,6 +258,10 @@ Command description:
   Amends the image format specific *OPTIONS* for the image file
   *FILENAME*. Not all file formats support this operation.

+  The set of options that can be amended are dependent on the image
+  format, but note that amending the backing chain relationship should
+  instead be performed with ``qemu-img rebase``.
+
 .. option:: bench [-c COUNT] [-d DEPTH] [-f FMT] 
[--flush-interval=FLUSH_INTERVAL] [-i AIO] [-n] [--no-drain] [-o OFFSET] 
[--pattern=PATTERN] [-q] [-s BUFFER_SIZE] [-S STEP_SIZE] [-t CACHE] [-w] [-U] 
FILENAME

   Run a simple sequential I/O benchmark on the specified image. If ``-w`` is
diff --git a/block/qcow2.c b/block/qcow2.c
index 0cd2e6757e8c..99aedb8eede6 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -5523,6 +5523,11 @@ static int qcow2_amend_options(BlockDriverState *bs, 
QemuOpts *opts,
 }

 if (backing_file || backing_format) {
+if (g_strcmp0(backing_file, s->image_backing_file) ||
+g_strcmp0(backing_format, s->image_backing_format)) {
+warn_report("Deprecated use of amend to alter the backing file; "
+"use qemu-img rebase instead");
+}
 ret = qcow2_change_backing_file(bs,
 backing_file ?: s->image_backing_file,
 backing_format ?: s->image_backing_format);
diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out
index 2f03cf045cce..c549b139da47 100644
--- a/tests/qemu-iotests/061.out
+++ b/tests/qemu-iotests/061.out
@@ -370,6 +370,7 @@ wrote 131072/131072 bytes at offset 0
 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 read 131072/131072 bytes at offset 0
 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+qemu-img: warning: Deprecated use of amend to alter the backing file; use 
qemu-img rebase instead
 read 131072/131072 bytes at offset 0
 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 No errors were found on the image.
diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out
index 529a1214e1ea..7f2b207d247b 100644
--- a/tests/qemu-iotests/082.out
+++ b/tests/qemu-iotests/082.out
@@ -839,10 +839,12 @@ Creation options for 'qcow2':
 Note that not all of these options may be amendable.

 Testing: amend -f qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2
+qemu-img: warning: Deprecated use of amend to alter the 

[PATCH v6 01/10] qemu-img: Flush stdout before before potential stderr messages

2020-07-06 Thread Eric Blake
During 'qemu-img create ... 2>&1', if --quiet is not in force, we can
end up with buffered I/O in stdout that was produced before failure,
but which appears in output after failure.  This is confusing; the fix
is to flush stdout prior to attempting anything that might produce an
error message.  Several iotests demonstrate the resulting ordering
change now that the merged outputs now reflect chronology.  (An even
better fix would be to avoid printf from within block.c altogether,
but that's much more invasive...)

Signed-off-by: Eric Blake 
---
 block.c| 1 +
 tests/qemu-iotests/049.out | 8 
 tests/qemu-iotests/054.out | 2 +-
 tests/qemu-iotests/079.out | 2 +-
 tests/qemu-iotests/112.out | 4 ++--
 tests/qemu-iotests/259.out | 2 +-
 6 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/block.c b/block.c
index 6dbcb7e083ea..a568196ba250 100644
--- a/block.c
+++ b/block.c
@@ -6186,6 +6186,7 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 printf("Formatting '%s', fmt=%s ", filename, fmt);
 qemu_opts_print(opts, " ");
 puts("");
+fflush(stdout);
 }

 ret = bdrv_create(drv, filename, opts, _err);
diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out
index c54ae21b868a..22f395246b37 100644
--- a/tests/qemu-iotests/049.out
+++ b/tests/qemu-iotests/049.out
@@ -167,12 +167,12 @@ qemu-img create -f qcow2 -o compat=1.1 TEST_DIR/t.qcow2 
64M
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 compat=1.1 
cluster_size=65536 lazy_refcounts=off refcount_bits=16 compression_type=zlib

 qemu-img create -f qcow2 -o compat=0.42 TEST_DIR/t.qcow2 64M
-qemu-img: TEST_DIR/t.qcow2: Invalid parameter '0.42'
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 compat=0.42 
cluster_size=65536 lazy_refcounts=off refcount_bits=16 compression_type=zlib
+qemu-img: TEST_DIR/t.qcow2: Invalid parameter '0.42'

 qemu-img create -f qcow2 -o compat=foobar TEST_DIR/t.qcow2 64M
-qemu-img: TEST_DIR/t.qcow2: Invalid parameter 'foobar'
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 compat=foobar 
cluster_size=65536 lazy_refcounts=off refcount_bits=16 compression_type=zlib
+qemu-img: TEST_DIR/t.qcow2: Invalid parameter 'foobar'

 == Check preallocation option ==

@@ -183,8 +183,8 @@ qemu-img create -f qcow2 -o preallocation=metadata 
TEST_DIR/t.qcow2 64M
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 cluster_size=65536 
preallocation=metadata lazy_refcounts=off refcount_bits=16 compression_type=zlib

 qemu-img create -f qcow2 -o preallocation=1234 TEST_DIR/t.qcow2 64M
-qemu-img: TEST_DIR/t.qcow2: Invalid parameter '1234'
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 cluster_size=65536 
preallocation=1234 lazy_refcounts=off refcount_bits=16 compression_type=zlib
+qemu-img: TEST_DIR/t.qcow2: Invalid parameter '1234'

 == Check encryption option ==

@@ -206,7 +206,7 @@ qemu-img create -f qcow2 -o compat=0.10,lazy_refcounts=off 
TEST_DIR/t.qcow2 64M
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 compat=0.10 
cluster_size=65536 lazy_refcounts=off refcount_bits=16 compression_type=zlib

 qemu-img create -f qcow2 -o compat=0.10,lazy_refcounts=on TEST_DIR/t.qcow2 64M
-qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibility 
level 1.1 and above (use version=v3 or greater)
 Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 compat=0.10 
cluster_size=65536 lazy_refcounts=on refcount_bits=16 compression_type=zlib
+qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibility 
level 1.1 and above (use version=v3 or greater)

 *** done
diff --git a/tests/qemu-iotests/054.out b/tests/qemu-iotests/054.out
index e6ec430edd47..71f18bb98760 100644
--- a/tests/qemu-iotests/054.out
+++ b/tests/qemu-iotests/054.out
@@ -1,8 +1,8 @@
 QA output created by 054

 creating too large image (1 EB)
-qemu-img: TEST_DIR/t.IMGFMT: The image size is too large for file format 
'IMGFMT' (try using a larger cluster size)
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1152921504606846976
+qemu-img: TEST_DIR/t.IMGFMT: The image size is too large for file format 
'IMGFMT' (try using a larger cluster size)

 creating too large image (1 EB) using qcow2.py
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296
diff --git a/tests/qemu-iotests/079.out b/tests/qemu-iotests/079.out
index aab922fb369b..f65a9ca84fea 100644
--- a/tests/qemu-iotests/079.out
+++ b/tests/qemu-iotests/079.out
@@ -9,6 +9,6 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296 
preallocation=metadat
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296 
preallocation=metadata
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296 
preallocation=metadata
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296 
preallocation=metadata
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296 
preallocation=metadata
 qemu-img: TEST_DIR/t.IMGFMT: Cluster size must be a power of two between 512 
and 2048k

[PATCH v6 02/10] block: Finish deprecation of 'qemu-img convert -n -o'

2020-07-06 Thread Eric Blake
It's been two releases since we started warning; time to make the
combination an error as promised.  There was no iotest coverage, so
add some.

While touching the documentation, tweak another section heading for
consistent style.

Signed-off-by: Eric Blake 
---
 docs/system/deprecated.rst | 18 --
 qemu-img.c |  4 ++--
 tests/qemu-iotests/122 |  7 +++
 tests/qemu-iotests/122.out |  4 
 4 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 47f84be8e09f..73b9d9f37848 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -418,14 +418,6 @@ kernel in 2018, and has also been dropped from glibc.
 Related binaries
 

-``qemu-img convert -n -o`` (since 4.2.0)
-
-
-All options specified in ``-o`` are image creation options, so
-they have no effect when used with ``-n`` to skip image creation.
-Silently ignored options can be confusing, so this combination of
-options will be made an error in future versions.
-
 Backwards compatibility
 ---

@@ -531,8 +523,8 @@ spec you can use the ``-cpu rv64gcsu,priv_spec=v1.10.0`` 
command line argument.
 Related binaries
 

-``qemu-nbd --partition`` (removed in 5.0.0)
-'''
+``qemu-nbd --partition`` (removed in 5.0)
+'

 The ``qemu-nbd --partition $digit`` code (also spelled ``-P``)
 could only handle MBR partitions, and never correctly handled logical
@@ -548,6 +540,12 @@ can be rewritten as::

   qemu-nbd -t --image-opts 
driver=raw,offset=1M,size=100M,file.driver=qcow2,file.file.driver=file,file.file.filename=file.qcow2

+``qemu-img convert -n -o`` (removed in 5.1)
+'''
+
+All options specified in ``-o`` are image creation options, so
+they are now rejected when used with ``-n`` to skip image creation.
+
 Command line options
 

diff --git a/qemu-img.c b/qemu-img.c
index bdb9f6aa46a3..9efe1f13482b 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2369,8 +2369,8 @@ static int img_convert(int argc, char **argv)
 }

 if (skip_create && options) {
-warn_report("-o has no effect when skipping image creation");
-warn_report("This will become an error in future QEMU versions.");
+error_report("-o has no effect when skipping image creation");
+goto fail_getopt;
 }

 if (s.has_zero_init && !skip_create) {
diff --git a/tests/qemu-iotests/122 b/tests/qemu-iotests/122
index f7a3ae684a7c..2dc16b2ca484 100755
--- a/tests/qemu-iotests/122
+++ b/tests/qemu-iotests/122
@@ -290,6 +290,13 @@ TEST_IMG="$TEST_IMG".orig _make_test_img 64M
 # backing file"
 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -n "$TEST_IMG" 
"$TEST_IMG".orig

+echo
+echo '=== -n incompatible with -o ==='
+echo
+
+$QEMU_IMG convert -O $IMGFMT -o preallocation=metadata -n \
+ "$TEST_IMG" "$TEST_IMG".orig && echo "unexpected success"
+
 # success, all done
 echo '*** done'
 rm -f $seq.full
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
index 1a35951a80a8..c2e154a1e556 100644
--- a/tests/qemu-iotests/122.out
+++ b/tests/qemu-iotests/122.out
@@ -233,4 +233,8 @@ Images are identical.

 Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
 Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864
+
+=== -n incompatible with -o ===
+
+qemu-img: -o has no effect when skipping image creation
 *** done
-- 
2.27.0



[PATCH v6 04/10] vmdk: Add trivial backing_fmt support

2020-07-06 Thread Eric Blake
vmdk already requires that if backing_file is present, that it be
another vmdk image (see vmdk_co_do_create).  Meanwhile, we want to
move towards always being explicit about the backing format for other
drivers where it matters.  So for convenience, make qemu-img create -F
vmdk work, while rejecting all other explicit formats (note that this
is only for QemuOpts usage; there is no change to the QAPI to allow a
format through -blockdev).

Signed-off-by: Eric Blake 
---
 block/vmdk.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/block/vmdk.c b/block/vmdk.c
index 62da4651263b..6c58e5ec2e43 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -2638,6 +2638,14 @@ static int coroutine_fn vmdk_co_create_opts(BlockDriver 
*drv,
 bool zeroed_grain;
 bool compat6;
 VMDKCreateOptsData data;
+char *backing_fmt = NULL;
+
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+if (backing_fmt && strcmp(backing_fmt, "vmdk") != 0) {
+error_setg(errp, "backing_file must be a vmdk image");
+ret = -EINVAL;
+goto exit;
+}

 if (filename_decompose(filename, path, prefix, postfix, PATH_MAX, errp)) {
 ret = -EINVAL;
@@ -2696,6 +2704,7 @@ static int coroutine_fn vmdk_co_create_opts(BlockDriver 
*drv,
 vmdk_co_create_opts_cb, , errp);

 exit:
+g_free(backing_fmt);
 g_free(adapter_type);
 g_free(backing_file);
 g_free(hw_version);
@@ -3031,6 +3040,11 @@ static QemuOptsList vmdk_create_opts = {
 .type = QEMU_OPT_STRING,
 .help = "File name of a base image"
 },
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Must be 'vmdk' if present",
+},
 {
 .name = BLOCK_OPT_COMPAT6,
 .type = QEMU_OPT_BOOL,
-- 
2.27.0



[PATCH v6 03/10] sheepdog: Add trivial backing_fmt support

2020-07-06 Thread Eric Blake
Sheepdog already requires that if backing_file is present, that it be
another sheepdog image (see sd_co_create).  Meanwhile, we want to move
towards always being explicit about the backing format for other
drivers where it matters.  So for convenience, make qemu-img create -F
sheepdog work, while rejecting all other explicit formats (note that
this is only for QemuOpts usage; there is no change to the QAPI to
allow a format through -blockdev).

Signed-off-by: Eric Blake 
---
 block/sheepdog.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 27a30d17f4c9..548ce54cbc7e 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2157,13 +2157,21 @@ static int coroutine_fn sd_co_create_opts(BlockDriver 
*drv,
   Error **errp)
 {
 BlockdevCreateOptions *create_options = NULL;
-QDict *qdict, *location_qdict;
+QDict *qdict = NULL, *location_qdict;
 Visitor *v;
-char *redundancy;
+char *redundancy = NULL;
 Error *local_err = NULL;
 int ret;
+char *backing_fmt = NULL;

 redundancy = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY);
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+
+if (backing_fmt && strcmp(backing_fmt, "sheepdog") != 0) {
+error_setg(errp, "backing_file must be a sheepdog image");
+ret = -EINVAL;
+goto fail;
+}

 qdict = qemu_opts_to_qdict(opts, NULL);
 qdict_put_str(qdict, "driver", "sheepdog");
@@ -2228,6 +2236,7 @@ fail:
 qapi_free_BlockdevCreateOptions(create_options);
 qobject_unref(qdict);
 g_free(redundancy);
+g_free(backing_fmt);
 return ret;
 }

@@ -3185,6 +3194,11 @@ static QemuOptsList sd_create_opts = {
 .type = QEMU_OPT_STRING,
 .help = "File name of a base image"
 },
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Must be 'sheepdog' if present",
+},
 {
 .name = BLOCK_OPT_PREALLOC,
 .type = QEMU_OPT_STRING,
-- 
2.27.0



[PATCH v6 06/10] block: Error if backing file fails during creation without -u

2020-07-06 Thread Eric Blake
Back in commit 6e6e55f5 (Jul 2017, v2.10), we tweaked the code to warn
if the backing file could not be opened but the user gave a size,
unless the user also passes the -u option to bypass the open of the
backing file.  As one common reason for failure to open the backing
file is when there is mismatch in the requested backing format in
relation to what the backing file actually contains, we actually want
to open the backing file and ensure that it has the right format in as
many cases as possible.  iotest 293 for qcow demonstrates how
detecting explicit format mismatch is useful to prevent the creation
of an image that would probe differently than the user requested.  Now
is the time to finally turn the warning an error, as promised.

Note that the original warning was added prior to our documentation of
an official deprecation policy (eb22aeca, also Jul 2017), and because
the warning didn't mention the word "deprecated", we never actually
remembered to document it as such.  But the warning has been around
long enough that I don't see prolonging it another two releases.

Signed-off-by: Eric Blake 
---
 docs/system/deprecated.rst | 12 
 block.c| 12 ++--
 tests/qemu-iotests/111.out |  2 +-
 tests/qemu-iotests/293.out | 13 +
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 73b9d9f37848..6fbec34b8b37 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -546,6 +546,18 @@ can be rewritten as::
 All options specified in ``-o`` are image creation options, so
 they are now rejected when used with ``-n`` to skip image creation.

+
+``qemu-img create -b bad file $size`` (removed in 5.1)
+''
+
+When creating an image with a backing file that could not be opened,
+``qemu-img create`` used to issue a warning about the failure but
+proceed with the image creation if an explicit size was provided.
+However, as the ``-u`` option exists for this purpose, it is safer to
+enforce that any failure to open the backing image (including if the
+backing file is missing or an incorrect format was specified) is an
+error when ``-u`` is not used.
+
 Command line options
 

diff --git a/block.c b/block.c
index a568196ba250..983b9bd29af5 100644
--- a/block.c
+++ b/block.c
@@ -6150,16 +6150,8 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
_err);
 g_free(full_backing);
-if (!bs && size != -1) {
-/* Couldn't open BS, but we have a size, so it's nonfatal */
-warn_reportf_err(local_err,
-"Could not verify backing image. "
-"This may become an error in future versions.\n");
-local_err = NULL;
-} else if (!bs) {
-/* Couldn't open bs, do not have size */
-error_append_hint(_err,
-  "Could not open backing image to determine 
size.\n");
+if (!bs) {
+error_append_hint(_err, "Could not open backing image.\n");
 goto out;
 } else {
 if (size == -1) {
diff --git a/tests/qemu-iotests/111.out b/tests/qemu-iotests/111.out
index 5279c462fc21..ba034e5c5886 100644
--- a/tests/qemu-iotests/111.out
+++ b/tests/qemu-iotests/111.out
@@ -1,4 +1,4 @@
 QA output created by 111
 qemu-img: TEST_DIR/t.IMGFMT: Could not open 'TEST_DIR/t.IMGFMT.inexistent': No 
such file or directory
-Could not open backing image to determine size.
+Could not open backing image.
 *** done
diff --git a/tests/qemu-iotests/293.out b/tests/qemu-iotests/293.out
index d07918b6d74b..3c612903f862 100644
--- a/tests/qemu-iotests/293.out
+++ b/tests/qemu-iotests/293.out
@@ -17,18 +17,15 @@ backing file: TEST_DIR/t.IMGFMT.base

 == mismatched command line detection ==
 qemu-img: TEST_DIR/t.IMGFMT: invalid VMDK image descriptor
-Could not open backing image to determine size.
-qemu-img: warning: Could not verify backing image. This may become an error in 
future versions.
-invalid VMDK image descriptor
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 
backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=vmdk
+Could not open backing image.
+qemu-img: TEST_DIR/t.IMGFMT: invalid VMDK image descriptor
+Could not open backing image.

 qemu-img: TEST_DIR/t.IMGFMT: Image creation needs a size parameter
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 
backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=vmdk

-qemu-img: warning: Could not verify backing image. This may become an error in 
future versions.
-Unknown driver 'garbage'
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 
backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=garbage
-qemu-img: TEST_DIR/t.IMGFMT: unrecognized backing format 'garbage'
+qemu-img: TEST_DIR/t.IMGFMT: 

[PATCH v6 09/10] block: Add support to warn on backing file change without format

2020-07-06 Thread Eric Blake
For now, this is a mechanical addition; all callers pass false. But
the next patch will use it to improve 'qemu-img rebase -u' when
selecting a backing file with no format.

Signed-off-by: Eric Blake 
Reviewed-by: Peter Krempa 
Reviewed-by: Ján Tomko 
---
 include/block/block.h |  4 ++--
 block.c   | 13 ++---
 block/qcow2.c |  2 +-
 block/stream.c|  2 +-
 blockdev.c|  3 ++-
 qemu-img.c|  4 ++--
 6 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index e8fc8149967f..b57a3806a592 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -410,8 +410,8 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t 
*nb_sectors_ptr);
 void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
 int bdrv_commit(BlockDriverState *bs);
 int bdrv_make_empty(BdrvChild *c, Error **errp);
-int bdrv_change_backing_file(BlockDriverState *bs,
-const char *backing_file, const char *backing_fmt);
+int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file,
+ const char *backing_fmt, bool warn);
 void bdrv_register(BlockDriver *bdrv);
 int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base,
const char *backing_file_str);
diff --git a/block.c b/block.c
index 983b9bd29af5..5cfd10f6b45e 100644
--- a/block.c
+++ b/block.c
@@ -1206,7 +1206,8 @@ static int bdrv_backing_update_filename(BdrvChild *c, 
BlockDriverState *base,
 }

 ret = bdrv_change_backing_file(parent, filename,
-   base->drv ? base->drv->format_name : "");
+   base->drv ? base->drv->format_name : "",
+   false);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not update backing file link");
 }
@@ -4684,8 +4685,8 @@ int bdrv_check(BlockDriverState *bs,
  *image file header
  * -ENOTSUP - format driver doesn't support changing the backing file
  */
-int bdrv_change_backing_file(BlockDriverState *bs,
-const char *backing_file, const char *backing_fmt)
+int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file,
+ const char *backing_fmt, bool warn)
 {
 BlockDriver *drv = bs->drv;
 int ret;
@@ -4699,6 +4700,12 @@ int bdrv_change_backing_file(BlockDriverState *bs,
 return -EINVAL;
 }

+if (warn && backing_file && !backing_fmt) {
+warn_report("Deprecated use of backing file without explicit "
+"backing format, use of this image requires "
+"potentially unsafe format probing");
+}
+
 if (drv->bdrv_change_backing_file != NULL) {
 ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
 } else {
diff --git a/block/qcow2.c b/block/qcow2.c
index 99aedb8eede6..36793e3bb0c7 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3630,7 +3630,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, 
Error **errp)
 }

 ret = bdrv_change_backing_file(blk_bs(blk), qcow2_opts->backing_file,
-   backing_format);
+   backing_format, false);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not assign backing file '%s' "
  "with format '%s'", qcow2_opts->backing_file,
diff --git a/block/stream.c b/block/stream.c
index aa2e7af98e37..310ccbaa4cfd 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -78,7 +78,7 @@ static int stream_prepare(Job *job)
 }
 }
 bdrv_set_backing_hd(bs, base, _err);
-ret = bdrv_change_backing_file(bs, base_id, base_fmt);
+ret = bdrv_change_backing_file(bs, base_id, base_fmt, false);
 if (local_err) {
 error_report_err(local_err);
 return -EPERM;
diff --git a/blockdev.c b/blockdev.c
index 31d5eaf6bf08..db0fbcd21499 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3429,7 +3429,8 @@ void qmp_change_backing_file(const char *device,
 }

 ret = bdrv_change_backing_file(image_bs, backing_file,
-   image_bs->drv ? image_bs->drv->format_name : 
"");
+   image_bs->drv ? image_bs->drv->format_name 
: "",
+   false);

 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not change backing file to '%s'",
diff --git a/qemu-img.c b/qemu-img.c
index 9efe1f13482b..71a919d73676 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3807,9 +3807,9 @@ static int img_rebase(int argc, char **argv)
  * doesn't change when we switch the backing file.
  */
 if (out_baseimg && *out_baseimg) {
-ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt, false);
 } else {
-ret = 

[PATCH v6 05/10] qcow: Tolerate backing_fmt=

2020-07-06 Thread Eric Blake
qcow has no space in the metadata to store a backing format, and there
are existing qcow images backed both by raw or by other formats
(usually qcow) images, reliant on probing to tell the difference.  On
the bright side, because we probe every time, raw files are marked as
probed and we thus forbid a commit action into the backing file where
guest-controlled contents could change the result of the probe next
time around (the iotest added here proves that).

Still, allowing the user to specify the backing format during
creation, even if we can't record it, is a good thing.  This patch
blindly allows any value that resolves to a known driver, even if the
user's request is a mismatch from what probing finds; then the next
patch will further enhance things to verify that the user's request
matches what we actually probe.  With this and the next patch in
place, we will finally be ready to deprecate the creation of images
where a backing format was not explicitly specified by the user.

Note that this is only for QemuOpts usage; there is no change to the
QAPI to allow a format through -blockdev.

Add a new iotest 293 just for qcow, to demonstrate the latest
behavior, and to make it easier to show the improvements made in the
next patch.

Signed-off-by: Eric Blake 
---
 block/qcow.c   | 20 -
 tests/qemu-iotests/293 | 88 ++
 tests/qemu-iotests/293.out | 60 ++
 tests/qemu-iotests/group   |  1 +
 4 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/293
 create mode 100644 tests/qemu-iotests/293.out

diff --git a/block/qcow.c b/block/qcow.c
index ee5d35fe20ed..e91aa2d8c4d0 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -940,11 +940,12 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver 
*drv,
 {
 BlockdevCreateOptions *create_options = NULL;
 BlockDriverState *bs = NULL;
-QDict *qdict;
+QDict *qdict = NULL;
 Visitor *v;
 const char *val;
 Error *local_err = NULL;
 int ret;
+char *backing_fmt;

 static const QDictRenames opt_renames[] = {
 { BLOCK_OPT_BACKING_FILE,   "backing-file" },
@@ -952,6 +953,17 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver 
*drv,
 { NULL, NULL },
 };

+/*
+ * We can't actually store a backing format, but can check that
+ * the user's request made sense.
+ */
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+if (backing_fmt && !bdrv_find_format(backing_fmt)) {
+error_setg(errp, "unrecognized backing format '%s'", backing_fmt);
+ret = -EINVAL;
+goto fail;
+}
+
 /* Parse options and convert legacy syntax */
 qdict = qemu_opts_to_qdict_filtered(opts, NULL, _create_opts, true);

@@ -1018,6 +1030,7 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver 
*drv,

 ret = 0;
 fail:
+g_free(backing_fmt);
 qobject_unref(qdict);
 bdrv_unref(bs);
 qapi_free_BlockdevCreateOptions(create_options);
@@ -1152,6 +1165,11 @@ static QemuOptsList qcow_create_opts = {
 .type = QEMU_OPT_STRING,
 .help = "File name of a base image"
 },
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Format of the backing image",
+},
 {
 .name = BLOCK_OPT_ENCRYPT,
 .type = QEMU_OPT_BOOL,
diff --git a/tests/qemu-iotests/293 b/tests/qemu-iotests/293
new file mode 100755
index ..3823e956175a
--- /dev/null
+++ b/tests/qemu-iotests/293
@@ -0,0 +1,88 @@
+#!/usr/bin/env bash
+#
+# Test qcow backing file warnings
+#
+# Copyright (C) 2020 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+#
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+status=1 # failure is the default!
+
+_cleanup()
+{
+_cleanup_test_img
+_rm_test_img "$TEST_IMG.qcow2"
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt qcow
+_supported_proto file
+_supported_os Linux
+
+size=32M
+
+echo
+echo "== qcow backed by qcow =="
+
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
+_make_test_img -b "$TEST_IMG.base" $size
+_img_info
+_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
+_img_info
+
+echo
+echo "== mismatched 

[PATCH v6 00/10] Tighten qemu-img rules on missing backing format

2020-07-06 Thread Eric Blake
v5 was here:
https://lists.gnu.org/archive/html/qemu-devel/2020-04/msg00679.html
In v6:
- add a few more patches
- change qcow semantics based on several iterations of mailing list
debates on what behavior is easiest to support
- add iotesting that a probed raw file cannot be committed into
- instead of recording an implicit probed raw file, instead we record
only a non-raw file
- rebase to a few more affected iotests, plus s/5.0/5.1/

Yes, I know this is really short notice to make it in before feature
freeze for 5.1 (removal in 6.0), so it may end up slipping into 5.2
(removal in 6.1); but we'll see how things go.

Also available at
https://repo.or.cz/qemu/ericb.git/shortlog/refs/tags/qemu-img-create-backing-v6

001/10:[down] 'qemu-img: Flush stdout before before potential stderr messages'
002/10:[down] 'block: Finish deprecation of 'qemu-img convert -n -o''
003/10:[] [--] 'sheepdog: Add trivial backing_fmt support'
004/10:[] [--] 'vmdk: Add trivial backing_fmt support'
005/10:[0088] [FC] 'qcow: Tolerate backing_fmt='
006/10:[down] 'block: Error if backing file fails during creation without -u'
007/10:[0004] [FC] 'qcow2: Deprecate use of qemu-img amend to change backing 
file'
008/10:[0059] [FC] 'iotests: Specify explicit backing format where sensible'
009/10:[] [-C] 'block: Add support to warn on backing file change without 
format'
010/10:[0027] [FC] 'qemu-img: Deprecate use of -b without -F'

Eric Blake (10):
  qemu-img: Flush stdout before before potential stderr messages
  block: Finish deprecation of 'qemu-img convert -n -o'
  sheepdog: Add trivial backing_fmt support
  vmdk: Add trivial backing_fmt support
  qcow: Tolerate backing_fmt=
  block: Error if backing file fails during creation without -u
  qcow2: Deprecate use of qemu-img amend to change backing file
  iotests: Specify explicit backing format where sensible
  block: Add support to warn on backing file change without format
  qemu-img: Deprecate use of -b without -F

 docs/system/deprecated.rst| 58 +++
 docs/tools/qemu-img.rst   |  4 ++
 include/block/block.h |  4 +-
 block.c   | 53 +++--
 block/qcow.c  | 20 +++-
 block/qcow2.c |  7 ++-
 block/sheepdog.c  | 18 ++-
 block/stream.c|  2 +-
 block/vmdk.c  | 14 ++
 blockdev.c|  3 +-
 qemu-img.c| 15 --
 tests/qemu-iotests/017|  2 +-
 tests/qemu-iotests/017.out|  2 +-
 tests/qemu-iotests/018|  2 +-
 tests/qemu-iotests/018.out|  2 +-
 tests/qemu-iotests/019|  5 +-
 tests/qemu-iotests/019.out|  2 +-
 tests/qemu-iotests/020|  4 +-
 tests/qemu-iotests/020.out|  4 +-
 tests/qemu-iotests/024|  8 ++--
 tests/qemu-iotests/024.out|  5 +-
 tests/qemu-iotests/028|  4 +-
 tests/qemu-iotests/028.out|  2 +-
 tests/qemu-iotests/030| 26 ---
 tests/qemu-iotests/034|  2 +-
 tests/qemu-iotests/034.out|  2 +-
 tests/qemu-iotests/037|  2 +-
 tests/qemu-iotests/037.out|  2 +-
 tests/qemu-iotests/038|  2 +-
 tests/qemu-iotests/038.out|  2 +-
 tests/qemu-iotests/039|  3 +-
 tests/qemu-iotests/039.out|  2 +-
 tests/qemu-iotests/040| 47 +--
 tests/qemu-iotests/041| 37 ++-
 tests/qemu-iotests/042|  4 +-
 tests/qemu-iotests/043| 18 +++
 tests/qemu-iotests/043.out| 16 ---
 tests/qemu-iotests/046|  2 +-
 tests/qemu-iotests/046.out|  2 +-
 tests/qemu-iotests/049.out|  8 ++--
 tests/qemu-iotests/050|  4 +-
 tests/qemu-iotests/050.out|  2 +-
 tests/qemu-iotests/051|  2 +-
 tests/qemu-iotests/051.out|  2 +-
 tests/qemu-iotests/051.pc.out |  2 +-
 tests/qemu-iotests/054.out|  2 +-
 tests/qemu-iotests/056|  3 +-
 tests/qemu-iotests/060|  2 +-
 tests/qemu-iotests/060.out|  2 +-
 tests/qemu-iotests/061| 10 ++--
 tests/qemu-iotests/061.out| 11 +++--
 tests/qemu-iotests/069|  2 +-
 tests/qemu-iotests/069.out|  2 +-
 tests/qemu-iotests/073|  2 +-
 tests/qemu-iotests/073.out|  2 +-
 tests/qemu-iotests/079.out|  2 +-
 tests/qemu-iotests/082| 10 ++--
 tests/qemu-iotests/082.out| 14 +++---
 tests/qemu-iotests/085|  4 +-
 tests/qemu-iotests/085.out|  6 +--
 tests/qemu-iotests/089|  2 +-
 tests/qemu-iotests/089.out|  2 +-
 tests/qemu-iotests/095|  4 +-
 tests/qemu-iotests/095.out|  4 +-
 tests/qemu-iotests/097|  4 +-
 tests/qemu-iotests/097.out| 16 +++
 tests/qemu-iotests/098|  2 +-
 tests/qemu-iotests/098.out|  8 ++--
 tests/qemu-iotests/110|  4 +-
 tests/qemu-iotests/110.out|  4 +-
 tests/qemu-iotests/111.out|  2 +-
 tests/qemu-iotests/112.out|  4 +-
 tests/qemu-iotests/114| 12 +
 tests/qemu-iotests/114.out|  

[PULL 16/20] audio: create pcspk device early

2020-07-06 Thread Gerd Hoffmann
Create the pcspk device early, so it exists at
machine type initialization time.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-17-kra...@redhat.com
---
 include/hw/i386/pc.h | 1 +
 hw/i386/pc.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index d7690bf4290f..a802e699749a 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -33,6 +33,7 @@ struct PCMachineState {
 PCIBus *bus;
 I2CBus *smbus;
 PFlashCFI01 *flash[2];
+ISADevice *pcspk;
 
 /* Configuration options: */
 uint64_t max_ram_below_4g;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4fc1b7048b28..88785f9dcc70 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1219,7 +1219,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 /* connect PIT to output control line of the HPET */
 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
 }
-pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
+pcspk_init(pcms->pcspk, isa_bus, pit);
 }
 
 i8257_dma_init(isa_bus, 0);
@@ -1891,6 +1891,7 @@ static void pc_machine_initfn(Object *obj)
 pcms->pit_enabled = true;
 
 pc_system_flash_create(pcms);
+pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
 }
 
 static void pc_machine_reset(MachineState *machine)
-- 
2.18.4



[PULL 11/20] pc_basic_device_init: pass PCMachineState

2020-07-06 Thread Gerd Hoffmann
Need access to pcms for pcspk initialization.
Just preparation, no functional change.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-12-kra...@redhat.com
---
 include/hw/i386/pc.h | 3 ++-
 hw/i386/pc.c | 3 ++-
 hw/i386/pc_piix.c| 2 +-
 hw/i386/pc_q35.c | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index dce1273c7dad..3a601dbe71da 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -160,7 +160,8 @@ void pc_memory_init(PCMachineState *pcms,
 MemoryRegion **ram_memory);
 uint64_t pc_pci_hole64_start(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(struct PCMachineState *pcms,
+  ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4af9679d039b..d89e577f6fa1 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1155,7 +1155,8 @@ static void pc_superio_init(ISABus *isa_bus, bool 
create_fdctrl, bool no_vmport)
 g_free(a20_line);
 }
 
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(struct PCMachineState *pcms,
+  ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1d832b2878b1..a3b416507286 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -235,7 +235,7 @@ static void pc_init1(MachineState *machine,
 }
 
 /* init basic PC hardware */
-pc_basic_device_init(isa_bus, x86ms->gsi, _state, true,
+pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
  (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
  0x4);
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 047ea8db28ea..b16e22c6cccd 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -275,7 +275,7 @@ static void pc_q35_init(MachineState *machine)
 }
 
 /* init basic PC hardware */
-pc_basic_device_init(isa_bus, x86ms->gsi, _state, !mc->no_floppy,
+pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
  (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
  0xff0104);
 
-- 
2.18.4



[PULL 10/20] audio: deprecate -soundhw hda

2020-07-06 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-11-kra...@redhat.com
---
 hw/audio/intel-hda.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index f673b8317a84..f6cea49686d7 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -25,6 +25,7 @@
 #include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "hw/audio/soundhw.h"
 #include "intel-hda.h"
 #include "migration/vmstate.h"
@@ -1307,6 +1308,8 @@ static int intel_hda_and_codec_init(PCIBus *bus)
 BusState *hdabus;
 DeviceState *codec;
 
+warn_report("'-soundhw hda' is deprecated, "
+"please use '-device intel-hda -device hda-duplex' instead");
 controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
 hdabus = QLIST_FIRST(>child_bus);
 codec = qdev_new("hda-duplex");
-- 
2.18.4



[PULL 12/20] pc_basic_device_init: drop has_pit arg

2020-07-06 Thread Gerd Hoffmann
Now that we pass pcms anyway, we don't need the has_pit arg any more.
No functional change.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-13-kra...@redhat.com
---
 include/hw/i386/pc.h | 1 -
 hw/i386/pc.c | 3 +--
 hw/i386/pc_piix.c| 2 +-
 hw/i386/pc_q35.c | 2 +-
 4 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 3a601dbe71da..bd447e380b5e 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -165,7 +165,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
-  bool has_pit,
   uint32_t hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(PCMachineState *pcms,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d89e577f6fa1..9f5153b6f24d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1160,7 +1160,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
-  bool has_pit,
   uint32_t hpet_irqs)
 {
 int i;
@@ -1211,7 +1210,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 
 qemu_register_boot_set(pc_boot_set, *rtc_state);
 
-if (!xen_enabled() && has_pit) {
+if (!xen_enabled() && pcms->pit_enabled) {
 if (kvm_pit_in_kernel()) {
 pit = kvm_pit_init(isa_bus, 0x40);
 } else {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index a3b416507286..6c1612d0ca45 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -236,7 +236,7 @@ static void pc_init1(MachineState *machine,
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
- (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
+ (pcms->vmport != ON_OFF_AUTO_ON),
  0x4);
 
 pc_nic_init(pcmc, isa_bus, pci_bus);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index b16e22c6cccd..6faf4458549a 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -276,7 +276,7 @@ static void pc_q35_init(MachineState *machine)
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
- (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
+ (pcms->vmport != ON_OFF_AUTO_ON),
  0xff0104);
 
 /* connect pm stuff to lpc */
-- 
2.18.4



[PULL 07/20] audio: deprecate -soundhw cs4231a

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-8-kra...@redhat.com
---
 hw/audio/cs4231a.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index ffdbb58d6a11..59705a8d4701 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -683,12 +683,6 @@ static void cs4231a_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("cs4231a", >card);
 }
 
-static int cs4231a_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_CS4231A);
-return 0;
-}
-
 static Property cs4231a_properties[] = {
 DEFINE_AUDIO_PROPERTIES(CSState, card),
 DEFINE_PROP_UINT32 ("iobase",  CSState, port, 0x534),
@@ -720,7 +714,7 @@ static const TypeInfo cs4231a_info = {
 static void cs4231a_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("cs4231a", "CS4231A", cs4231a_init);
+deprecated_register_soundhw("cs4231a", "CS4231A", 1, TYPE_CS4231A);
 }
 
 type_init (cs4231a_register_types)
-- 
2.18.4



[PULL 18/20] audio: add soundhw deprecation notice

2020-07-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-19-kra...@redhat.com
---
 docs/system/deprecated.rst | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 47f84be8e09f..58a9aeb85153 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -82,6 +82,15 @@ should specify an ``audiodev=`` property.  Additionally, 
when using
 vnc, you should specify an ``audiodev=`` propery if you plan to
 transmit audio through the VNC protocol.
 
+Creating sound card devices using ``-soundhw`` (since 5.1)
+''
+
+Sound card devices should be created using ``-device`` instead.  The
+names are the same for most devices.  The exceptions are ``hda`` which
+needs two devices (``-device intel-hda -device hda-duplex``) and
+``pcspk`` which can be activated using ``-machine
+pcspk-audiodev=``.
+
 ``-mon ...,control=readline,pretty=on|off`` (since 4.1)
 '''
 
-- 
2.18.4



[PULL 17/20] audio: deprecate -soundhw pcspk

2020-07-06 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Factor out audio initialization and call that from
both audio init and realize, so setting the audiodev
property is enough to properly initialize pcspk.

Add a property alias to the machine type to set the
audio device, so pcspk can be initialized using:
"-machine pcspk-audiodev="

Using "-global isa-pcspk.audiodev=" works too but
is not recommended.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-18-kra...@redhat.com
---
 hw/audio/pcspk.c | 24 +---
 hw/i386/pc.c |  2 ++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index c37a3878612e..4c7e339ac2b5 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -28,6 +28,7 @@
 #include "audio/audio.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "hw/timer/i8254.h"
 #include "migration/vmstate.h"
 #include "hw/audio/pcspk.h"
@@ -112,11 +113,15 @@ static void pcspk_callback(void *opaque, int free)
 }
 }
 
-static int pcspk_audio_init(ISABus *bus)
+static int pcspk_audio_init(PCSpkState *s)
 {
-PCSpkState *s = pcspk_state;
 struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUDIO_FORMAT_U8, 0};
 
+if (s->voice) {
+/* already initialized */
+return 0;
+}
+
 AUD_register_card(s_spk, >card);
 
 s->voice = AUD_open_out(>card, s->voice, s_spk, s, pcspk_callback, );
@@ -185,6 +190,10 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
 isa_register_ioport(isadev, >ioport, s->iobase);
 
+if (s->card.state) {
+pcspk_audio_init(s);
+}
+
 pcspk_state = s;
 }
 
@@ -236,9 +245,18 @@ static const TypeInfo pcspk_info = {
 .class_init = pcspk_class_initfn,
 };
 
+static int pcspk_audio_init_soundhw(ISABus *bus)
+{
+PCSpkState *s = pcspk_state;
+
+warn_report("'-soundhw pcspk' is deprecated, "
+"please set a backend using '-machine pcspk-audiodev=' 
instead");
+return pcspk_audio_init(s);
+}
+
 static void pcspk_register(void)
 {
 type_register_static(_info);
-isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init);
+isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init_soundhw);
 }
 type_init(pcspk_register)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 88785f9dcc70..c45e7bfd864b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1892,6 +1892,8 @@ static void pc_machine_initfn(Object *obj)
 
 pc_system_flash_create(pcms);
 pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
+object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
+  OBJECT(pcms->pcspk), "audiodev");
 }
 
 static void pc_machine_reset(MachineState *machine)
-- 
2.18.4



[PULL 19/20] pcspk: update docs/system/target-i386-desc.rst.inc

2020-07-06 Thread Gerd Hoffmann
Add PC speaker with config hints.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-20-kra...@redhat.com
---
 docs/system/target-i386-desc.rst.inc | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/docs/system/target-i386-desc.rst.inc 
b/docs/system/target-i386-desc.rst.inc
index 47a169e0ae2a..7d1fffacbea3 100644
--- a/docs/system/target-i386-desc.rst.inc
+++ b/docs/system/target-i386-desc.rst.inc
@@ -31,6 +31,8 @@ The QEMU PC System emulator simulates the following 
peripherals:
 
 -  CS4231A compatible sound card
 
+-  PC speaker
+
 -  PCI UHCI, OHCI, EHCI or XHCI USB controller and a virtual USB-1.1
hub.
 
@@ -49,7 +51,7 @@ must be told to not have parallel ports to have working GUS.
 
 .. parsed-literal::
 
-   |qemu_system_x86| dos.img -soundhw gus -parallel none
+   |qemu_system_x86| dos.img -device gus -parallel none
 
 Alternatively:
 
@@ -60,3 +62,12 @@ Alternatively:
 Or some other unclaimed IRQ.
 
 CS4231A is the chip used in Windows Sound System and GUSMAX products
+
+The PC speaker audio device can be configured using the pcspk-audiodev
+machine property, i.e.
+
+.. parsed-literal::
+
+   |qemu_system_x86| some.img \
+   -audiodev ,id= \
+   -machine pcspk-audiodev=
-- 
2.18.4



[PULL 20/20] audio: set default value for pcspk.iobase property

2020-07-06 Thread Gerd Hoffmann
Allows dropping the explicit qdev_prop_set_uint32 call in pcspk_init.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-21-kra...@redhat.com
---
 include/hw/audio/pcspk.h | 6 +-
 hw/audio/pcspk.c | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 8b485602675f..06cba00b8376 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -33,11 +33,7 @@
 
 static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
-DeviceState *dev;
-
-dev = DEVICE(isadev);
-qdev_prop_set_uint32(dev, "iobase", 0x61);
-object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
+object_property_set_link(OBJECT(isadev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 4c7e339ac2b5..ea539e7605a8 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -219,7 +219,7 @@ static const VMStateDescription vmstate_spk = {
 
 static Property pcspk_properties[] = {
 DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
-DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  -1),
+DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  0x61),
 DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
 DEFINE_PROP_END_OF_LIST(),
 };
-- 
2.18.4



[PULL 14/20] softmmu: initialize spice and audio earlier

2020-07-06 Thread Gerd Hoffmann
audiodev must be initialized before machine_set_property
so the machine can have audiodev property aliases.

spice must initialize before audiodev because the default
audiodev is spice only in case spice is actually enabled.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-15-kra...@redhat.com
---
 softmmu/vl.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 3e15ee243572..8ee91219060a 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4131,12 +4131,17 @@ void qemu_init(int argc, char **argv, char **envp)
   fsdev_init_func, NULL, _fatal);
 #endif
 
+/* spice needs the timers to be initialized by this point */
+/* spice must initialize before audio as it changes the default auiodev */
+qemu_spice_init();
+
 /*
- * Note: we need to create block backends before
+ * Note: we need to create audio and block backends before
  * machine_set_property(), so machine properties can refer to
  * them.
  */
 configure_blockdev(_queue, machine_class, snapshot);
+audio_init_audiodevs();
 
 machine_opts = qemu_get_machine_opts();
 qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
@@ -4230,9 +4235,6 @@ void qemu_init(int argc, char **argv, char **envp)
 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
 }
 
-/* spice needs the timers to be initialized by this point */
-qemu_spice_init();
-
 cpu_ticks_init();
 
 if (default_net) {
@@ -4342,8 +4344,6 @@ void qemu_init(int argc, char **argv, char **envp)
 create_default_memdev(current_machine, mem_path);
 }
 
-audio_init_audiodevs();
-
 /* from here on runstate is RUN_STATE_PRELAUNCH */
 machine_run_board_init(current_machine);
 
-- 
2.18.4



[PULL 13/20] pc_basic_device_init: drop no_vmport arg

2020-07-06 Thread Gerd Hoffmann
Now that we pass pcms anyway, we don't need the no_vmport arg any more.
No functional change.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-14-kra...@redhat.com
---
 include/hw/i386/pc.h | 1 -
 hw/i386/pc.c | 3 +--
 hw/i386/pc_piix.c| 1 -
 hw/i386/pc_q35.c | 1 -
 4 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index bd447e380b5e..d7690bf4290f 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -164,7 +164,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
-  bool no_vmport,
   uint32_t hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(PCMachineState *pcms,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9f5153b6f24d..407c782b5d42 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1159,7 +1159,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
-  bool no_vmport,
   uint32_t hpet_irqs)
 {
 int i;
@@ -1226,7 +1225,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 i8257_dma_init(isa_bus, 0);
 
 /* Super I/O */
-pc_superio_init(isa_bus, create_fdctrl, no_vmport);
+pc_superio_init(isa_bus, create_fdctrl, pcms->vmport != ON_OFF_AUTO_ON);
 }
 
 void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6c1612d0ca45..1ef3f39c55a5 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -236,7 +236,6 @@ static void pc_init1(MachineState *machine,
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
- (pcms->vmport != ON_OFF_AUTO_ON),
  0x4);
 
 pc_nic_init(pcmc, isa_bus, pci_bus);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6faf4458549a..5f8f21b84093 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -276,7 +276,6 @@ static void pc_q35_init(MachineState *machine)
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
- (pcms->vmport != ON_OFF_AUTO_ON),
  0xff0104);
 
 /* connect pm stuff to lpc */
-- 
2.18.4



[PULL 15/20] audio: rework pcspk_init()

2020-07-06 Thread Gerd Hoffmann
Instead of creating and returning the pc speaker accept it as argument.
That allows to rework the initialization workflow in followup patches.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-16-kra...@redhat.com
---
 include/hw/audio/pcspk.h | 6 +-
 hw/i386/pc.c | 2 +-
 hw/isa/i82378.c  | 2 +-
 hw/mips/jazz.c   | 2 +-
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 7e7f5f49dcb0..8b485602675f 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -31,18 +31,14 @@
 
 #define TYPE_PC_SPEAKER "isa-pcspk"
 
-static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
+static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
 DeviceState *dev;
-ISADevice *isadev;
 
-isadev = isa_new(TYPE_PC_SPEAKER);
 dev = DEVICE(isadev);
 qdev_prop_set_uint32(dev, "iobase", 0x61);
 object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
-
-return isadev;
 }
 
 #endif /* HW_PCSPK_H */
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 407c782b5d42..4fc1b7048b28 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1219,7 +1219,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 /* connect PIT to output control line of the HPET */
 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
 }
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 }
 
 i8257_dma_init(isa_bus, 0);
diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index d9e6c7fa0096..75a2da288157 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -102,7 +102,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
 pit = i8254_pit_init(isabus, 0x40, 0, NULL);
 
 /* speaker */
-pcspk_init(isabus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isabus, pit);
 
 /* 2 82C37 (dma) */
 isa_create_simple(isabus, "i82374");
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index c3b0da60ccc1..0002bff69590 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -250,7 +250,7 @@ static void mips_jazz_init(MachineState *machine,
 isa_bus_irqs(isa_bus, i8259);
 i8257_dma_init(isa_bus, 0);
 pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 
 /* Video card */
 switch (jazz_model) {
-- 
2.18.4



[PULL 08/20] audio: deprecate -soundhw gus

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-9-kra...@redhat.com
---
 hw/audio/gus.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index c8df2bde6b32..7e4a8cadad6f 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -286,12 +286,6 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
 AUD_set_active_out (s->voice, 1);
 }
 
-static int GUS_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_GUS);
-return 0;
-}
-
 static Property gus_properties[] = {
 DEFINE_AUDIO_PROPERTIES(GUSState, card),
 DEFINE_PROP_UINT32 ("freq",GUSState, freq,44100),
@@ -322,7 +316,7 @@ static const TypeInfo gus_info = {
 static void gus_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("gus", "Gravis Ultrasound GF1", GUS_init);
+deprecated_register_soundhw("gus", "Gravis Ultrasound GF1", 1, TYPE_GUS);
 }
 
 type_init (gus_register_types)
-- 
2.18.4



[PULL 09/20] audio: deprecate -soundhw sb16

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-10-kra...@redhat.com
---
 hw/audio/sb16.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index df6f755a37f8..2d9e50f99b5d 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -1415,12 +1415,6 @@ static void sb16_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("sb16", >card);
 }
 
-static int SB16_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_SB16);
-return 0;
-}
-
 static Property sb16_properties[] = {
 DEFINE_AUDIO_PROPERTIES(SB16State, card),
 DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
@@ -1453,7 +1447,8 @@ static const TypeInfo sb16_info = {
 static void sb16_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("sb16", "Creative Sound Blaster 16", SB16_init);
+deprecated_register_soundhw("sb16", "Creative Sound Blaster 16",
+1, TYPE_SB16);
 }
 
 type_init (sb16_register_types)
-- 
2.18.4



[PULL 04/20] audio: deprecate -soundhw ac97

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both ac97 and AC97 are working with -device.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-5-kra...@redhat.com
---
 hw/audio/ac97.c | 9 ++---
 qdev-monitor.c  | 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 8a9b9924c495..38522cf0ba44 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1393,12 +1393,6 @@ static void ac97_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int ac97_init (PCIBus *bus)
-{
-pci_create_simple(bus, -1, TYPE_AC97);
-return 0;
-}
-
 static Property ac97_properties[] = {
 DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
 DEFINE_PROP_END_OF_LIST (),
@@ -1436,7 +1430,8 @@ static const TypeInfo ac97_info = {
 static void ac97_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("ac97", "Intel 82801AA AC97 Audio", ac97_init);
+deprecated_register_soundhw("ac97", "Intel 82801AA AC97 Audio",
+0, TYPE_AC97);
 }
 
 type_init (ac97_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 22da107484c5..105d9792ecdf 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -53,6 +53,7 @@ typedef struct QDevAlias
 
 /* Please keep this table sorted by typename. */
 static const QDevAlias qdev_alias_table[] = {
+{ "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
-- 
2.18.4



[PULL 02/20] stubs: add pci_create_simple

2020-07-06 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Message-id: 20200702132525.6849-3-kra...@redhat.com
---
 stubs/pci-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/pci-bus.c

diff --git a/stubs/pci-bus.c b/stubs/pci-bus.c
new file mode 100644
index ..a8932fa93250
--- /dev/null
+++ b/stubs/pci-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+
+PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index ff0411d21f22..918e46bdc1ca 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -13,6 +13,7 @@ stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
 stub-obj-y += notify-event.o
+stub-obj-y += pci-bus.o
 stub-obj-y += qmp_memory_device.o
 stub-obj-y += qtest.o
 stub-obj-y += ramfb.o
-- 
2.18.4



[PULL 03/20] audio: add deprecated_register_soundhw

2020-07-06 Thread Gerd Hoffmann
Add helper function for -soundhw deprecation.  It can replace the
simple init functions which just call {isa,pci}_create_simple()
with a hardcoded type.  It also prints a deprecation message.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-4-kra...@redhat.com
---
 include/hw/audio/soundhw.h |  2 ++
 hw/audio/soundhw.c | 24 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/include/hw/audio/soundhw.h b/include/hw/audio/soundhw.h
index c8eef8241846..f09a297854af 100644
--- a/include/hw/audio/soundhw.h
+++ b/include/hw/audio/soundhw.h
@@ -6,6 +6,8 @@ void isa_register_soundhw(const char *name, const char *descr,
 
 void pci_register_soundhw(const char *name, const char *descr,
   int (*init_pci)(PCIBus *bus));
+void deprecated_register_soundhw(const char *name, const char *descr,
+ int isa, const char *typename);
 
 void soundhw_init(void);
 void select_soundhw(const char *optarg);
diff --git a/hw/audio/soundhw.c b/hw/audio/soundhw.c
index c750473c8f0c..173b674ff53a 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/soundhw.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/option.h"
 #include "qemu/help_option.h"
 #include "qemu/error-report.h"
 #include "qom/object.h"
@@ -32,6 +33,7 @@
 struct soundhw {
 const char *name;
 const char *descr;
+const char *typename;
 int enabled;
 int isa;
 union {
@@ -65,6 +67,17 @@ void pci_register_soundhw(const char *name, const char 
*descr,
 soundhw_count++;
 }
 
+void deprecated_register_soundhw(const char *name, const char *descr,
+ int isa, const char *typename)
+{
+assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
+soundhw[soundhw_count].name = name;
+soundhw[soundhw_count].descr = descr;
+soundhw[soundhw_count].isa = isa;
+soundhw[soundhw_count].typename = typename;
+soundhw_count++;
+}
+
 void select_soundhw(const char *optarg)
 {
 struct soundhw *c;
@@ -136,7 +149,16 @@ void soundhw_init(void)
 
 for (c = soundhw; c->name; ++c) {
 if (c->enabled) {
-if (c->isa) {
+if (c->typename) {
+warn_report("'-soundhw %s' is deprecated, "
+"please use '-device %s' instead",
+c->name, c->typename);
+if (c->isa) {
+isa_create_simple(isa_bus, c->typename);
+} else {
+pci_create_simple(pci_bus, -1, c->typename);
+}
+} else if (c->isa) {
 if (!isa_bus) {
 error_report("ISA bus not available for %s", c->name);
 exit(1);
-- 
2.18.4



[PULL 00/20] Audio 20200706 patches

2020-07-06 Thread Gerd Hoffmann
The following changes since commit eb6490f544388dd24c0d054a96dd304bc7284450:

  Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200703' 
into staging (2020-07-04 16:08:41 +0100)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/audio-20200706-pull-request

for you to fetch changes up to 2336172d9b396b4fa4483712f5560a563c25352f:

  audio: set default value for pcspk.iobase property (2020-07-06 17:01:11 +0200)


audio: deprecate -soundhw



Gerd Hoffmann (20):
  stubs: add isa_create_simple
  stubs: add pci_create_simple
  audio: add deprecated_register_soundhw
  audio: deprecate -soundhw ac97
  audio: deprecate -soundhw es1370
  audio: deprecate -soundhw adlib
  audio: deprecate -soundhw cs4231a
  audio: deprecate -soundhw gus
  audio: deprecate -soundhw sb16
  audio: deprecate -soundhw hda
  pc_basic_device_init: pass PCMachineState
  pc_basic_device_init: drop has_pit arg
  pc_basic_device_init: drop no_vmport arg
  softmmu: initialize spice and audio earlier
  audio: rework pcspk_init()
  audio: create pcspk device early
  audio: deprecate -soundhw pcspk
  audio: add soundhw deprecation notice
  pcspk: update docs/system/target-i386-desc.rst.inc
  audio: set default value for pcspk.iobase property

 include/hw/audio/pcspk.h | 12 ++--
 include/hw/audio/soundhw.h   |  2 ++
 include/hw/i386/pc.h |  6 +++---
 hw/audio/ac97.c  |  9 ++---
 hw/audio/adlib.c |  8 +---
 hw/audio/cs4231a.c   |  8 +---
 hw/audio/es1370.c|  9 ++---
 hw/audio/gus.c   |  8 +---
 hw/audio/intel-hda.c |  3 +++
 hw/audio/pcspk.c | 26 ++
 hw/audio/sb16.c  |  9 ++---
 hw/audio/soundhw.c   | 24 +++-
 hw/i386/pc.c | 14 --
 hw/i386/pc_piix.c|  3 +--
 hw/i386/pc_q35.c |  3 +--
 hw/isa/i82378.c  |  2 +-
 hw/mips/jazz.c   |  2 +-
 qdev-monitor.c   |  2 ++
 softmmu/vl.c | 12 ++--
 stubs/isa-bus.c  |  7 +++
 stubs/pci-bus.c  |  7 +++
 docs/system/deprecated.rst   |  9 +
 docs/system/target-i386-desc.rst.inc | 13 -
 stubs/Makefile.objs  |  2 ++
 24 files changed, 121 insertions(+), 79 deletions(-)
 create mode 100644 stubs/isa-bus.c
 create mode 100644 stubs/pci-bus.c

-- 
2.18.4



[PULL 01/20] stubs: add isa_create_simple

2020-07-06 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Message-id: 20200702132525.6849-2-kra...@redhat.com
---
 stubs/isa-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/isa-bus.c

diff --git a/stubs/isa-bus.c b/stubs/isa-bus.c
new file mode 100644
index ..522f448997d4
--- /dev/null
+++ b/stubs/isa-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/isa/isa.h"
+
+ISADevice *isa_create_simple(ISABus *bus, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index f32b9e47a3d8..ff0411d21f22 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -8,6 +8,7 @@ stub-obj-y += fdset.o
 stub-obj-y += gdbstub.o
 stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
+stub-obj-y += isa-bus.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
-- 
2.18.4



[PULL 06/20] audio: deprecate -soundhw adlib

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-7-kra...@redhat.com
---
 hw/audio/adlib.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 7c3b67dcfb8c..65dff5b6fca4 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -319,16 +319,10 @@ static const TypeInfo adlib_info = {
 .class_init= adlib_class_initfn,
 };
 
-static int Adlib_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_ADLIB);
-return 0;
-}
-
 static void adlib_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("adlib", ADLIB_DESC, Adlib_init);
+deprecated_register_soundhw("adlib", ADLIB_DESC, 1, TYPE_ADLIB);
 }
 
 type_init (adlib_register_types)
-- 
2.18.4



[PULL 05/20] audio: deprecate -soundhw es1370

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both es1370 and ES1370 are working with
-device.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-6-kra...@redhat.com
---
 hw/audio/es1370.c | 9 ++---
 qdev-monitor.c| 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 5f8a83ff5624..4255463a49ff 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -884,12 +884,6 @@ static void es1370_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int es1370_init (PCIBus *bus)
-{
-pci_create_simple (bus, -1, TYPE_ES1370);
-return 0;
-}
-
 static Property es1370_properties[] = {
 DEFINE_AUDIO_PROPERTIES(ES1370State, card),
 DEFINE_PROP_END_OF_LIST(),
@@ -928,7 +922,8 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370", es1370_init);
+deprecated_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370",
+0, TYPE_ES1370);
 }
 
 type_init (es1370_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 105d9792ecdf..e3083fae394b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -55,6 +55,7 @@ typedef struct QDevAlias
 static const QDevAlias qdev_alias_table[] = {
 { "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
+{ "ES1370", "es1370" }, /* -soundhw name */
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
 { "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X },
-- 
2.18.4



[PATCH 3/3] qemublocktest: add test of transient option for qcow2 disk

2020-07-06 Thread Masayoshi Mizuma
From: Masayoshi Mizuma 

Add a unit test for transient option for qcow2 file.

Signed-off-by: Masayoshi Mizuma 
---
 tests/qemublocktest.c   | 10 ++
 .../xml2json/qcow2-transient-srconly.json   |  9 +
 .../qemublocktestdata/xml2json/qcow2-transient.json | 13 +
 .../qemublocktestdata/xml2json/qcow2-transient.xml  | 13 +
 4 files changed, 45 insertions(+)
 create mode 100644 
tests/qemublocktestdata/xml2json/qcow2-transient-srconly.json
 create mode 100644 tests/qemublocktestdata/xml2json/qcow2-transient.json
 create mode 100644 tests/qemublocktestdata/xml2json/qcow2-transient.xml

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 0cdedb9..1294c18 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -266,6 +266,7 @@ testQemuDiskXMLToProps(const void *opaque)
 g_autoptr(virJSONValue) formatProps = NULL;
 g_autoptr(virJSONValue) storageProps = NULL;
 g_autoptr(virJSONValue) storageSrcOnlyProps = NULL;
+qemuDomainObjPrivate priv;
 g_autofree char *xmlpath = NULL;
 g_autofree char *xmlstr = NULL;
 
@@ -288,6 +289,13 @@ testQemuDiskXMLToProps(const void *opaque)
 return -1;
 }
 
+if (disk->transient) {
+priv.driver = data->driver;
+if (qemuBlockCreateTransientDisk(disk->src, ) < 0)
+return EXIT_AM_SKIP;
+unlink(disk->src->path);
+}
+
 for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
 g_autofree char *backingstore = NULL;
 
@@ -1226,6 +1234,8 @@ mymain(void)
 
 TEST_DISK_TO_JSON("nvme-raw-noopts");
 
+TEST_DISK_TO_JSON("qcow2-transient");
+
 #define TEST_JSON_TO_JSON(nme) \
 do { \
 jsontojsondata.name = nme; \
diff --git a/tests/qemublocktestdata/xml2json/qcow2-transient-srconly.json 
b/tests/qemublocktestdata/xml2json/qcow2-transient-srconly.json
new file mode 100644
index 000..3c2de91
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/qcow2-transient-srconly.json
@@ -0,0 +1,9 @@
+(
+  source only properties:
+  {
+"driver": "file",
+"filename": "/var/lib/libvirt/images/transient.qcow2.TRANSIENT"
+  }
+  backing store string:
+  /var/lib/libvirt/images/transient.qcow2.TRANSIENT
+)
diff --git a/tests/qemublocktestdata/xml2json/qcow2-transient.json 
b/tests/qemublocktestdata/xml2json/qcow2-transient.json
new file mode 100644
index 000..57463e1
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/qcow2-transient.json
@@ -0,0 +1,13 @@
+{
+  "node-name": "1234567890",
+  "read-only": false,
+  "driver": "qcow2",
+  "file": "1234567890"
+}
+{
+  "driver": "file",
+  "filename": "/var/lib/libvirt/images/transient.qcow2.TRANSIENT",
+  "node-name": "1234567890",
+  "auto-read-only": true,
+  "discard": "unmap"
+}
diff --git a/tests/qemublocktestdata/xml2json/qcow2-transient.xml 
b/tests/qemublocktestdata/xml2json/qcow2-transient.xml
new file mode 100644
index 000..d2e3919
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/qcow2-transient.xml
@@ -0,0 +1,13 @@
+
+  
+  
+
+  
+
+
+  
+
+  
+  
+  
+
-- 
2.27.0



[PATCH 1/3] qemu: implementation of transient option for qcow2 file

2020-07-06 Thread Masayoshi Mizuma
From: Masayoshi Mizuma 

Here is the implementation of transient option for qcow2 file.
This gets available  directive in domain xml file
like as:


  
  
  
  


The internal procedure is as follows.
When the qemu command line options are built, a new qcow2 image is created
with backing qcow2 image by using qemu-img command. The backing image is the
qcow2 file which is set as .
The filename of the new qcow2 image is original-source-file.TRANSIENT.
The qemu-img will be:

qemu-img create -f qcow2 -F qcow2 \
-b /var/lib/libvirt/images/guest.qcow2 \
/var/lib/libvirt/images/guest.qcow2.TRANSIENT

Then, it switches the disk path, virStorageSourcePtr src->path, to
the new qcow2 image. The new image and the backing image is handled and
the blockdev option of qemu will be built like as:

-blockdev 
'{"driver":"file","filename":"/var/lib/libvirt/images/guest.qcow2",

"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev 
'{"node-name":"libvirt-2-format","read-only":true,"driver":"qcow2",
"file":"libvirt-2-storage","backing":null}' \
-blockdev 
'{"driver":"file","filename":"/var/lib/libvirt/images/guest.qcow2.TRANSIENT",

"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev 
'{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2",
"file":"libvirt-1-storage","backing":"libvirt-2-format"}'

The new qcow2 image is removed when the Guest is shutdowned, 

Signed-off-by: Masayoshi Mizuma 
---
 src/qemu/qemu_block.c| 71 
 src/qemu/qemu_block.h|  7 
 src/qemu/qemu_domain.c   |  4 +++
 src/qemu/qemu_process.c  |  3 ++
 src/qemu/qemu_validate.c |  2 +-
 5 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 6f9c707..5eb0225 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -27,6 +27,7 @@
 #include "viralloc.h"
 #include "virstring.h"
 #include "virlog.h"
+#include "virqemu.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -3438,3 +3439,73 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
 
 return 0;
 }
+
+int
+qemuBlockCreateTransientDisk(virStorageSourcePtr src,
+ qemuDomainObjPrivatePtr priv)
+{
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+virCommandPtr cmd = NULL;
+g_autofree char *filename = NULL;
+g_autofree char *dirname = NULL;
+const char *qemuImgPath;
+char *newpath;
+int err = -1;
+
+if ((src->format != VIR_STORAGE_FILE_QCOW2)) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   "%s", _("transient option supports qcow2"));
+return -1;
+}
+
+if (!(qemuImgPath = qemuFindQemuImgBinary(priv->driver)))
+return -1;
+
+newpath = g_strdup_printf("%s.TRANSIENT", src->path);
+
+if (virFileExists(newpath)) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _(" '%s' is already exists. Please remove it."), 
newpath);
+goto cleanup;
+}
+
+if (!(cmd = virCommandNewArgList(qemuImgPath,
+ "create",
+ "-f",
+ "qcow2",
+ "-F",
+ "qcow2",
+ "-b",
+ NULL)))
+goto cleanup;
+
+virQEMUBuildBufferEscapeComma(, src->path);
+virCommandAddArgBuffer(cmd, );
+
+virQEMUBuildBufferEscapeComma(, newpath);
+virCommandAddArgBuffer(cmd, );
+
+if (virCommandRun(cmd, NULL) < 0)
+goto cleanup;
+
+VIR_DEBUG("Original disk: %s Transient disk: %s", src->path, newpath);
+
+g_free(src->path);
+src->path = newpath;
+
+err = 0;
+ cleanup:
+virBufferFreeAndReset();
+virCommandFree(cmd);
+if (err)
+g_free(newpath);
+
+return err;
+}
+
+void
+qemuBlockRemoveTransientDisk(virStorageSourcePtr src)
+{
+VIR_DEBUG("unlink transient disk: %s ", src->path);
+unlink(src->path);
+}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 2ad2ce1..60c6898 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -266,3 +266,10 @@ int
 qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
virStorageSourcePtr src,
virStorageSourcePtr topsrc);
+
+int
+qemuBlockCreateTransientDisk(virStorageSourcePtr src,
+ qemuDomainObjPrivatePtr priv);
+
+void
+qemuBlockRemoveTransientDisk(virStorageSourcePtr src);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d5e3d1a..9dbf73c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8301,6 +8301,10 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 
 qemuDomainGetImageIds(cfg, vm, 

[PATCH 2/3] testutilsqemu: Assign qemu-img path to driver->qemuImgBinary

2020-07-06 Thread Masayoshi Mizuma
From: Masayoshi Mizuma 

Assign qemu-img command file path to driver->qemuImgBinary
so that the unit tests can use qemu-img command.

Signed-off-by: Masayoshi Mizuma 
---
 tests/testutilsqemu.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 4dcc308..8517f31 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -104,7 +104,8 @@ char *
 virFindFileInPath(const char *file)
 {
 if (g_str_has_prefix(file, "qemu-system") ||
-g_str_equal(file, "qemu-kvm")) {
+g_str_equal(file, "qemu-kvm") ||
+g_str_equal(file, "qemu-img")) {
 return g_strdup_printf("/usr/bin/%s", file);
 }
 
@@ -317,6 +318,7 @@ void qemuTestDriverFree(virQEMUDriver *driver)
 virObjectUnref(driver->caps);
 virObjectUnref(driver->config);
 virObjectUnref(driver->securityManager);
+virObjectUnref(driver->qemuImgBinary);
 }
 
 int qemuTestCapsCacheInsert(virFileCachePtr cache,
@@ -447,6 +449,8 @@ int qemuTestDriverInit(virQEMUDriver *driver)
 
 qemuTestSetHostCPU(driver, driver->hostarch, NULL);
 
+driver->qemuImgBinary = virFindFileInPath("qemu-img");
+
 return 0;
 
  error:
-- 
2.27.0



[PATCH 0/3] qemu: implementation of transient option for qcow2 file

2020-07-06 Thread Masayoshi Mizuma
Hello,

This patchset tries to implement transient option for qcow2 file.

It gets user available to set  to the domain xml file like as:


  
  
  
  


Any changes which the Guest does to the disk is dropped when the Guest
is shutdowned.

Masayoshi Mizuma (3):
  qemu: implementation of transient option for qcow2 file
  testutilsqemu: Assign qemu-img path to driver->qemuImgBinary
  qemublocktest: add test of transient option for qcow2 file

 src/qemu/qemu_block.c | 71 +++
 src/qemu/qemu_block.h |  7 ++
 src/qemu/qemu_domain.c|  4 ++
 src/qemu/qemu_process.c   |  3 +
 src/qemu/qemu_validate.c  |  2 +-
 tests/qemublocktest.c | 10 +++
 .../xml2json/qcow2-transient-srconly.json |  9 +++
 .../xml2json/qcow2-transient.json | 13 
 .../xml2json/qcow2-transient.xml  | 13 
 tests/testutilsqemu.c |  6 +-
 10 files changed, 136 insertions(+), 2 deletions(-)
 create mode 100644 
tests/qemublocktestdata/xml2json/qcow2-transient-srconly.json
 create mode 100644 tests/qemublocktestdata/xml2json/qcow2-transient.json
 create mode 100644 tests/qemublocktestdata/xml2json/qcow2-transient.xml

-- 
2.27.0



Re: [RFC PATCH 0/2] hw/sd: Deprecate the SPI mode and the SPI to SD adapter

2020-07-06 Thread Philippe Mathieu-Daudé
On 7/6/20 6:41 PM, Alistair Francis wrote:
> On Sun, Jul 5, 2020 at 3:08 PM Philippe Mathieu-Daudé  wrote:
>>
>> I tried to maintain the SPI mode because it is useful in
>> tiny embedded devices, and thought it would be helpful for
>> the AVR MCUs.
>> As AVR was blocked, I thought it was wise to deprecate the
>> SPI mode as users are interested in the faster MMC mode.
>> Today Thomas surprised me by posting an update of it!
>> https://www.mail-archive.com/qemu-devel@nongnu.org/msg720089.html
>>
>> I'm still posting this as RFC to discuss, but I'm reconsiderating
>> keeping this mode a bit more.
> 
> I think it's worth keeping.
> 
> I'm pretty sure the HiFive Unleashed (sifive_u in QEMU) uses SD over
> SPI. There isn't an upstream model but I think there are out of tree
> patches that hopefully one day will make it upstream.

Glad to hear that! :)

> 
> Alistair
> 
>>
>> Philippe Mathieu-Daudé (2):
>>   hw/sd/ssi-sd: Deprecate the SPI to SD card 'adapter'
>>   hw/sd/sdcard: Deprecate the SPI mode
>>
>>  docs/system/deprecated.rst | 10 ++
>>  1 file changed, 10 insertions(+)
>>
>> --
>> 2.21.3
>>
>>
> 



Re: [RFC PATCH 1/2] hw/sd/ssi-sd: Deprecate the SPI to SD card 'adapter'

2020-07-06 Thread Eric Blake

On 7/5/20 5:07 PM, Philippe Mathieu-Daudé wrote:

This device duplicate the SPI mode of the sd-card device. The


duplicates


SPI protocol is better handler in the sd-card, however as the
TYPE_SSI_SLAVE is not an interface, the sd-card can not implement
it easily to be pluggable on a SPI bus. Meanwhile the ssi-sd
device acts as a bridge, but is bitroting. Deprecate it.


bitrotting



Signed-off-by: Philippe Mathieu-Daudé 
---
  docs/system/deprecated.rst | 5 +
  1 file changed, 5 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 47f84be8e0..5e67d7f3e0 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -343,6 +343,11 @@ The 'ide-drive' device is deprecated. Users should use 
'ide-hd' or
  The 'scsi-disk' device is deprecated. Users should use 'scsi-hd' or
  'scsi-cd' as appropriate to get a SCSI hard disk or CD-ROM as needed.
  
+``ssi-sd`` (since 5.1)

+'


Inconsistent line lengths


+
+The 'ssi-sd' (SSI to SD card adapter) device is deprecated.


What is the recommended replacement?  Or at least document if it is 
disappearing with no replacement.



+
  System emulator machines
  
  



--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



Re: Release of libvirt-6.5.0

2020-07-06 Thread Jim Fehlig

On 7/3/20 1:56 AM, Daniel Veillard wrote:

   Half a day late, but I pushed the 6.5.0 release out, it is as usual
available as a signed tarball and source rpms from the server:

https://libvirt.org/sources/

I also tagged and pushed the 6.5.0 python bindings that one can find at

https://libvirt.org/sources/python/

This release includes a number of new features and some improvement,
as well as a crash which had made its way in 6.4.0.
It will also be my last release of libvirt after close to 15 years,


Wow, has it been that long? :-)

Thanks for welcoming and helping a green newcomer (to virtualization and open 
source in general) in those early days of the project!


Cheers,
Jim



Re: [question]qemu: any plan to support ivshmem-plain migration?

2020-07-06 Thread Daniel P . Berrangé
On Mon, Jul 06, 2020 at 01:14:04PM +, Wangxin (Alexander, Cloud 
Infrastructure Service Product Dept.) wrote:
> Hi, Martin
> 
> Ivshmem-plain device support property role with 'master'(master=on) or 
> 'peer'(master=off, default mode), which controls
> to copy the shared memory on migration to the destination host or not.
> https://git.qemu.org/?p=qemu.git;a=blob;f=docs/system/ivshmem.rst;h=b03a48afa3ae7258bbe43490180fc5732b1f6c8c;hb=HEAD
> 
> And libvirt does not support to configure 'role' yet, see msg
> https://www.redhat.com/archives/libvir-list/2016-August/msg00591.html
> 
> Qemu use 'master=off' as ivshmem-plain default property, the guest create by 
> libvirt api can't be migrated now.
> 
> Do you have an plan to support the property 'role' and ivshmem-palin 
> migration?

I would assume no one is actively working on it since it is 4 years since
that quoted message. If you wish to try to implement it, we'll review any
patches.

Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



[question]qemu: any plan to support ivshmem-plain migration?

2020-07-06 Thread Wangxin (Alexander, Cloud Infrastructure Service Product Dept.)
Hi, Martin

Ivshmem-plain device support property role with 'master'(master=on) or 
'peer'(master=off, default mode), which controls
to copy the shared memory on migration to the destination host or not.
https://git.qemu.org/?p=qemu.git;a=blob;f=docs/system/ivshmem.rst;h=b03a48afa3ae7258bbe43490180fc5732b1f6c8c;hb=HEAD

And libvirt does not support to configure 'role' yet, see msg
https://www.redhat.com/archives/libvir-list/2016-August/msg00591.html

Qemu use 'master=off' as ivshmem-plain default property, the guest create by 
libvirt api can't be migrated now.

Do you have an plan to support the property 'role' and ivshmem-palin migration?


Regards,
Xin




Re: [PATCH 0/7] consider available CPUs in vcpupin/emulatorpin output

2020-07-06 Thread Daniel Henrique Barboza

Ping

On 6/26/20 7:10 PM, Daniel Henrique Barboza wrote:

Hi,

This series contains 5 cleanups and refactorings I found
on my way to fixing [1]. Last 2 patches contains the actual
fix for the bug.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1434276


Daniel Henrique Barboza (7):
   qemu_driver.c: use g_autoptr in qemuDomainGetEmulatorPinInfo()
   virhostcpu.c: use g_autoptr in virHostCPUGetMap()
   virsh-domain.c: modernize virshVcpuinfoInactive()
   virsh-domain.c: modernize cmdVcpuinfo()
   virhostcpu.c: refactor virHostCPUParseCountLinux()
   virhostcpu.c: introduce virHostCPUGetAvailableCPUsBitmap()
   conf, qemu: consider available CPUs in vcpupin/emulatorpin output

  src/conf/domain_conf.c   |  4 +--
  src/libvirt_private.syms |  1 +
  src/qemu/qemu_driver.c   | 10 ++-
  src/util/virhostcpu.c| 63 
  src/util/virhostcpu.h|  2 ++
  tools/virsh-domain.c | 44 ++--
  6 files changed, 59 insertions(+), 65 deletions(-)