]> Git Repo - qemu.git/log
qemu.git
4 years agoiotests: Set LC_ALL=C for sort
Max Reitz [Fri, 10 Jul 2020 16:32:52 +0000 (18:32 +0200)]
iotests: Set LC_ALL=C for sort

Otherwise the result is basically unpredictable.

(Note that the precise environment variable to control sorting order is
LC_COLLATE, but LC_ALL overrides LC_COLLATE, and we do not want the
sorting order to be messed up if LC_ALL is set in the environment.)

Reported-by: John Snow <[email protected]>
Signed-off-by: Max Reitz <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200710163253[email protected]>

4 years agoRevert "vga: build virtio-gpu as module"
Gerd Hoffmann [Fri, 10 Jul 2020 20:36:52 +0000 (22:36 +0200)]
Revert "vga: build virtio-gpu as module"

This reverts commit 8d5a24c83dba90b08ef163bbf166d6dfbad9019b.

Compiling all virtio-gpu objects into a single module isn't a good plan
because the individual objects have different CONFIG_* dependencies.
Leads to module load failures on s390x due to vga support being
disabled, which in turn breaks '-device virtio-gpu-device' (flagged by
travis ci).

So back to the drawing board for modular virtio-gpu ...

Signed-off-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200710203652[email protected]>

4 years agotests: fix "make check-qtest" for modular builds
Gerd Hoffmann [Fri, 10 Jul 2020 20:36:51 +0000 (22:36 +0200)]
tests: fix "make check-qtest" for modular builds

Signed-off-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200710203652[email protected]>

4 years ago.cirrus.yml: add bash to the brew packages
Alex Bennée [Fri, 10 Jul 2020 16:30:21 +0000 (17:30 +0100)]
.cirrus.yml: add bash to the brew packages

Like the sed we include earlier we want something more recent for
iotests to work.

Fixes: 57ee95ed
Cc: Max Reitz <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200710182238[email protected]>

4 years agotests/docker: update toolchain set in debian-xtensa-cross
Max Filippov [Thu, 9 Jul 2020 14:13:26 +0000 (15:13 +0100)]
tests/docker: update toolchain set in debian-xtensa-cross

Switch to the prebuilt xtensa toolchains release 2020.07.
Drop csp toolchain as the csp core is not a part of QEMU.
Add de233_fpu and dsp3400 toolchains to enable DFPU and FPU2000 tests.

Signed-off-by: Max Filippov <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
[AJB: fix path in configure.sh]
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200708082347[email protected]>
Message-Id: <20200709141327[email protected]>

4 years agotests/docker: fall back more gracefully when pull fails
Alex Bennée [Thu, 9 Jul 2020 14:13:25 +0000 (15:13 +0100)]
tests/docker: fall back more gracefully when pull fails

I only spotted this in the small window between my testing with my
registry while waiting for the gitlab PR to go in. As we pre-pull the
registry image we know if that fails there isn't any point attempting
to use the cache. Fall back to the way we used to do it at that point.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200709141327[email protected]>

4 years agodocs: Add to gdbstub documentation the PhyMemMode
Jon Doron [Thu, 9 Jul 2020 14:13:17 +0000 (15:13 +0100)]
docs: Add to gdbstub documentation the PhyMemMode

The PhyMemMode gdb extension command was missing from the gdb.rst
document.

Signed-off-by: Jon Doron <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200601171609.1665397[email protected]>
Message-Id: <20200709141327[email protected]>

4 years agodocs/devel: add some notes on tcg-icount for developers
Alex Bennée [Thu, 9 Jul 2020 14:13:16 +0000 (15:13 +0100)]
docs/devel: add some notes on tcg-icount for developers

This attempts to bring together my understanding of the requirements
for icount behaviour into one reference document for our developer
notes.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Pavel Dovgalyuk <[email protected]>
Cc: Peter Maydell <[email protected]>
Message-Id: <20200709141327[email protected]>

4 years agodocs/devel: convert and update MTTCG design document
Alex Bennée [Thu, 9 Jul 2020 14:13:15 +0000 (15:13 +0100)]
docs/devel: convert and update MTTCG design document

Do a light conversion to .rst and clean-up some of the language at the
start now MTTCG has been merged for a while.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-Id: <20200709141327[email protected]>

4 years agotests/qht-bench: Adjust threshold computation
Richard Henderson [Fri, 26 Jun 2020 20:09:50 +0000 (13:09 -0700)]
tests/qht-bench: Adjust threshold computation

In 06c4cc3660b3, we split the multiplication in two parts to avoid
a clang warning.  But because double still rounds to 53 bits, this
does not provide additional precision beyond multiplication by
nextafter(0x1p64, 0), the largest representable value smaller
than 2**64.

However, since we have eliminated 1.0, mutiplying by 2**64 produces
a better distribution of input values to the output values.

Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200626200950.1015121[email protected]>

4 years agotests/qht-bench: Adjust testing rate by -1
Richard Henderson [Fri, 26 Jun 2020 20:09:49 +0000 (13:09 -0700)]
tests/qht-bench: Adjust testing rate by -1

Since the seed must be non-zero, subtracting 1 means puts the
rate in 0..UINT64_MAX-1, which allows the 0 and UINT64_MAX
thresholds to corrspond to 0% (never) and 100% (always).

Suggested-by: Emilio G. Cota <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200626200950.1015121[email protected]>

4 years agotravis.yml: Test also the other targets on s390x
Thomas Huth [Mon, 8 Jun 2020 11:40:49 +0000 (13:40 +0200)]
travis.yml: Test also the other targets on s390x

s390x is our only big endian host in our CI, so building and testing QEMU
there is quite valuable. Thus let's also test the other targets with
additional jobs (also using different sets of pre-installed libraries to
get a better coverage of the things that we test).

Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200608114049[email protected]>

4 years agoshippable: pull images from registry instead of building
Alex Bennée [Wed, 1 Jul 2020 13:56:52 +0000 (14:56 +0100)]
shippable: pull images from registry instead of building

Now we have a source for registry images pull from there rather than
re-building every time on shippable.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotesting: add check-build target
Alex Bennée [Wed, 1 Jul 2020 13:56:51 +0000 (14:56 +0100)]
testing: add check-build target

If we want to continue to split build and check phase it seems like a
good idea to allow building of the tests during our multi-threaded
build phase.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Cc: Daniel P. Berrangé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agocontainers.yml: build with docker.py tooling
Alex Bennée [Wed, 1 Jul 2020 13:56:50 +0000 (14:56 +0100)]
containers.yml: build with docker.py tooling

Instead of building the docker files directly use the same docker.py
scripting as we do for building locally. This should help ensure we
use the exact same steps and allow us to cache properly when building
locally.

To get this working you have to have a fairly recent docker binary
otherwise you will see the error message:

 => ERROR importing cache manifest from registry.gitlab....

So far docker 19.03.12 works (from the docker apt repos) but 18.09.1,
build 4c52b90 which is packaged in Debian Buster fails.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: limit re-builds of the containers
Alex Bennée [Wed, 1 Jul 2020 13:56:49 +0000 (14:56 +0100)]
gitlab: limit re-builds of the containers

Most of the time we are just rebuilding the same things. We can skip
this although currently there is no mechanism for picking up new
distro releases.

Rather than try to be too fine grained allow any change to trigger all
the images being rebuilt.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests: improve performance of device-introspect-test
Daniel P. Berrangé [Fri, 10 Jul 2020 06:07:19 +0000 (08:07 +0200)]
tests: improve performance of device-introspect-test

Total execution time with "-m slow" and x86_64 QEMU, drops from 3
minutes 15 seconds, down to 54 seconds.

Individual tests drop from 17-20 seconds, down to 3-4 seconds.

The cost of this change is that any QOM bugs resulting in the test
failure will not be directly associated with the device that caused
the failure. The test case is not frequently identifying such bugs
though, and the cause is likely easily visible in the patch series
that causes the failure. So overall the shorter running time is
considered the more important factor.

Signed-off-by: Daniel P. Berrangé <[email protected]>
[thuth: Add the tree check to test_device_intro_none() and
 test_device_intro_abstract(), too, just to be sure...]
Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200710060719[email protected]>

4 years agogitlab: add avocado asset caching
Alex Bennée [Wed, 1 Jul 2020 13:56:47 +0000 (14:56 +0100)]
gitlab: add avocado asset caching

These can be quite big so lets cache them. I couldn't find any nots on
ccache in the gitlab docs so I've just ignored it for now.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: enable check-tcg for linux-user tests
Alex Bennée [Wed, 1 Jul 2020 13:56:46 +0000 (14:56 +0100)]
gitlab: enable check-tcg for linux-user tests

Switch to building in the new debian-all-test-cross image which has
most of the cross compilers inline.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agolinux-user/elfload: use MAP_FIXED_NOREPLACE in pgb_reserved_va
Alex Bennée [Wed, 1 Jul 2020 13:56:45 +0000 (14:56 +0100)]
linux-user/elfload: use MAP_FIXED_NOREPLACE in pgb_reserved_va

Given we assert the requested address matches what we asked we should
also make that clear in the mmap flags. Otherwise we see failures in
the GitLab environment for some currently unknown but allowable
reason. We use MAP_FIXED_NOREPLACE if we can so we don't just clobber
an existing mapping. Also include the strerror string for a bit more
info on failure.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/docker: add a linux-user testing focused image
Alex Bennée [Wed, 1 Jul 2020 13:56:44 +0000 (14:56 +0100)]
tests/docker: add a linux-user testing focused image

We happily use all the cross images for both cross-building QEMU as
well as building the linux-user tests. However calling docker from
within docker seems not to work. As we can build in Debian anyway why
not include an image that has all the compilers available for
non-docker invocation.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/tcg: add more default compilers to configure.sh
Alex Bennée [Wed, 1 Jul 2020 13:56:43 +0000 (14:56 +0100)]
tests/tcg: add more default compilers to configure.sh

We were missing a bunch of compilers which we could use if they were
locally installed. The defaults are based on Debian as they seem to be
the best distro for well distributed cross-build compilers.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: add acceptance testing to system builds
Alex Bennée [Wed, 1 Jul 2020 13:56:42 +0000 (14:56 +0100)]
gitlab: add acceptance testing to system builds

As part of migrating things from Travis to GitLab add the acceptance
tests. To do this:

  - rename system1 to system-ubuntu-main
  - rename system2 to system-fedora-misc
  - split into build/check/acceptance
  - remove -j from check stages
  - use artifacts to save build stage
  - add post acceptance template and use

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/acceptance: skip LinuxInitrd 2gib with v4.16 on GitLab
Alex Bennée [Wed, 1 Jul 2020 13:56:41 +0000 (14:56 +0100)]
tests/acceptance: skip LinuxInitrd 2gib with v4.16 on GitLab

This fails on GitLab but not when run locally on the same container
image. It's very confusing.

Signed-off-by: Alex Bennée <[email protected]>
Acked-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/acceptance: skip multicore mips_malta tests on GitLab
Alex Bennée [Wed, 1 Jul 2020 13:56:40 +0000 (14:56 +0100)]
tests/acceptance: skip multicore mips_malta tests on GitLab

For some reason these tests fail all the time on GitLab. I can
re-create the hang around 3% of the time locally but it doesn't seem
to be MTTCG related. For now skipIf on GITLAB_CI.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Cc: Aleksandar Markovic <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/acceptance: fix dtb path for machine_rx_gdbsim
Alex Bennée [Wed, 1 Jul 2020 13:56:39 +0000 (14:56 +0100)]
tests/acceptance: fix dtb path for machine_rx_gdbsim

The old path doesn't exist but the rx-virt.dtb file has the same
checksum so lets use that.

Signed-off-by: Alex Bennée <[email protected]>
Acked-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/acceptance: skip s390x_ccw_vrtio_tcg on GitLab
Alex Bennée [Wed, 1 Jul 2020 13:56:38 +0000 (14:56 +0100)]
tests/acceptance: skip s390x_ccw_vrtio_tcg on GitLab

Currently the test takes more the 900 seconds on GitLab and then times
out. Running on Travis seems to be OK.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/docker: add packages needed for check-acceptance
Alex Bennée [Wed, 1 Jul 2020 13:56:37 +0000 (14:56 +0100)]
tests/docker: add packages needed for check-acceptance

We need additional python packages to run check-acceptance. Add them
to the docker images we will be using later.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/docker: add --registry support to tooling
Alex Bennée [Wed, 1 Jul 2020 13:56:36 +0000 (14:56 +0100)]
tests/docker: add --registry support to tooling

This allows us to point the tools towards a registry from which they
can grab pre-built layers instead of doing everything from scratch
each time. To enable this we need to be using the DOCKER_BUILDKIT
engine.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: build containers with buildkit and metadata
Alex Bennée [Wed, 1 Jul 2020 13:56:35 +0000 (14:56 +0100)]
gitlab: build containers with buildkit and metadata

According to the documentation to be able to use --cache-from for
remote registries you need to enable both buildkit and inline the
metadata. We want to do this to support pulling from gitlab when users
build their local docker images.

Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: convert jobs to use custom built containers
Daniel P. Berrangé [Wed, 1 Jul 2020 13:56:34 +0000 (14:56 +0100)]
gitlab: convert jobs to use custom built containers

Now that we're building standard container images from
dockerfiles in tests/docker/dockerfiles, we can convert
the build jobs to use them. The key benefit of this is
that a contributor can now more easily replicate the CI
environment on their local machine. The container images
are cached too, so we are not spending time waiting for
the apt-get/dnf package installs to complete.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Message-Id: <20200622153318[email protected]>
[AJB: tweak naming convention]
Signed-off-by: Alex Bennée <[email protected]>
Acked-by: Thomas Huth <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: build all container images during CI
Daniel P. Berrangé [Wed, 1 Jul 2020 13:56:33 +0000 (14:56 +0100)]
gitlab: build all container images during CI

We have a number of container images in tests/docker/dockerfiles
that are intended to provide well defined environments for doing
test builds. We want our CI system to use these containers too.

This introduces builds of all of them as the first stage in the
CI, so that the built containers are available for later build
jobs. The containers are setup to use the GitLab container
registry as the cache, so we only pay the penalty of the full
build when the dockerfiles change. The main qemu-project/qemu
repo is used as a second cache, so that users forking QEMU will
see a fast turnaround time on their CI jobs.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Message-Id: <20200622153318[email protected]>
[AJB: tweak the tag format]
Signed-off-by: Alex Bennée <[email protected]>
Acked-by: Thomas Huth <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab: introduce explicit "container" and "build" stages
Daniel P. Berrangé [Wed, 1 Jul 2020 13:56:32 +0000 (14:56 +0100)]
gitlab: introduce explicit "container" and "build" stages

If no stage is listed, jobs get put in an implicit "test" stage.
Some jobs which create container images to be used by later stages
are currently listed as in a "build" stages.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Acked-by: Laszlo Ersek <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200622153318[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agogitlab-ci: Fix the change rules after moving the YML files
Thomas Huth [Wed, 1 Jul 2020 13:56:31 +0000 (14:56 +0100)]
gitlab-ci: Fix the change rules after moving the YML files

The edk2.yml and opensbi.yml files have recently been moved/renamed,
but the change has not been reflected in the rules in the YML files
yet.

Fixes: 922febe2af ("Move edk2 and opensbi YAML files to .gitlab-ci.d folder")
Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Message-Id: <20200625151627[email protected]>
Message-Id: <20200701135652[email protected]>

4 years ago.gitignore: un-ignore .gitlab-ci.d
Alex Bennée [Wed, 1 Jul 2020 13:56:30 +0000 (14:56 +0100)]
.gitignore: un-ignore .gitlab-ci.d

The sooner we deprecate in-tree builds the sooner this mess of regexes
can be thrown away.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/docker: change tag naming scheme of our images
Alex Bennée [Wed, 1 Jul 2020 13:56:29 +0000 (14:56 +0100)]
tests/docker: change tag naming scheme of our images

We've been misusing the tag naming scheme for some time by overloading
the post : section with the image type. Really it should be saved for
the revision of that particular build. Move the details to the other
side so we have:

  qemu/image-name

with the implied :latest version added by the tooling.

Suggested-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/docker: check for an parameters not empty string
Alex Bennée [Wed, 1 Jul 2020 13:56:28 +0000 (14:56 +0100)]
tests/docker: check for an parameters not empty string

Reported-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Suggested-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: allow us to take advantage of MTTCG
Alex Bennée [Wed, 1 Jul 2020 13:56:27 +0000 (14:56 +0100)]
tests/vm: allow us to take advantage of MTTCG

We currently limit TCG guests to -smp 1 but now we have added some
aarch64 guests we can do better when running on x86_64 hardware.
Raise the limit for TCG guests when it is safe to do so.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Robert Foley <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: switch from optsparse to argparse
Alex Bennée [Wed, 1 Jul 2020 13:56:26 +0000 (14:56 +0100)]
tests/vm: switch from optsparse to argparse

optparse has been deprecated since version 3.2 and argparse is the
blessed replacement. Take the opportunity to enhance our help output
showing defaults when called.

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Reviewed-by: Robert Foley <[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: Add workaround to consume console
Robert Foley [Wed, 1 Jul 2020 13:56:25 +0000 (14:56 +0100)]
tests/vm: Add workaround to consume console

This adds support to basevm.py so that we always
drain the console chars.  This makes use of
support added in an earlier commit that allows
QEMUMachine to use the ConsoleSocket.

This is a workaround we found was needed since
there is a known issue where QEMU will hang waiting
for console characters to be consumed.

We also added the option of logging the console to a file.
LOG_CONSOLE=1 will now log the output to a file.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Acked-by: Alex Bennée <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agopython/qemu: Add ConsoleSocket for optional use in QEMUMachine
Robert Foley [Wed, 1 Jul 2020 13:56:24 +0000 (14:56 +0100)]
python/qemu: Add ConsoleSocket for optional use in QEMUMachine

We add the ConsoleSocket object, which has a socket interface
and which will consume all arriving characters on the
socket, placing them into an in memory buffer.
This will also provide those chars via recv() as
would a regular socket.
ConsoleSocket also has the option of dumping
the console bytes to a log file.

We also give QEMUMachine the option of using ConsoleSocket
to drain and to use for logging console to a file.
By default QEMUMachine does not use ConsoleSocket.

This is added in preparation for use by basevm.py in a later commit.
This is a workaround we found was needed for basevm.py since
there is a known issue where QEMU will hang waiting
for console characters to be consumed.

Cc: Eduardo Habkost <[email protected]>
Cc: Cleber Rosa <[email protected]>
Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Acked-by: Alex Bennée <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: change scripts to use self._config
Robert Foley [Wed, 1 Jul 2020 13:56:23 +0000 (14:56 +0100)]
tests/vm: change scripts to use self._config

This change converts existing scripts to using for example self.ROOT_PASS,
to self._config['root_pass'].
We made similar changes for GUEST_USER, and GUEST_PASS.
This allows us also to remove the change in basevm.py,
which adds __getattr__ for backwards compatibility.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: Added a new script for centos.aarch64.
Robert Foley [Wed, 1 Jul 2020 13:56:22 +0000 (14:56 +0100)]
tests/vm: Added a new script for centos.aarch64.

centos.aarch64 creates a CentOS 8 image.
Also added a new kickstart script used to build the centos.aarch64 image.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: Added a new script for ubuntu.aarch64.
Robert Foley [Wed, 1 Jul 2020 13:56:21 +0000 (14:56 +0100)]
tests/vm: Added a new script for ubuntu.aarch64.

ubuntu.aarch64 provides a script to create an Ubuntu 18.04 VM.
Another new file is also added aarch64vm.py, which is a module with
common methods used by aarch64 VMs, such as how to create the
flash images.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: Add common Ubuntu python module
Robert Foley [Wed, 1 Jul 2020 13:56:20 +0000 (14:56 +0100)]
tests/vm: Add common Ubuntu python module

Add a common Ubuntu python module and make use of
it with the ubuntu.i386 script.
This is preparation for adding an Ubuntu script
ubuntu.aarch64.  Splitting out the common
logic such as build_image() will reduce duplication.

Signed-off-by: Robert Foley <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: Added configuration file support
Robert Foley [Wed, 1 Jul 2020 13:56:19 +0000 (14:56 +0100)]
tests/vm: Added configuration file support

Changes to tests/vm/basevm.py to allow accepting a configuration file
as a parameter. Allows for specifying VM options such as
cpu, machine, memory, and arbitrary qemu arguments for specifying options
such as NUMA configuration.
Also added an example conf_example_aarch64.yml and conf_example_x86.yml.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: Add configuration to basevm.py
Robert Foley [Wed, 1 Jul 2020 13:56:18 +0000 (14:56 +0100)]
tests/vm: Add configuration to basevm.py

Added use of a configuration to tests/vm/basevm.py.
The configuration provides parameters used to configure a VM.
This allows for providing alternate configurations to the VM being
created/launched. cpu, machine, memory, and NUMA configuration are all
examples of configuration which we might want to vary on the VM being created
or launched.
This will for example allow for creating an aarch64 vm.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Peter Puhov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agotests/vm: pass args through to BaseVM's __init__
Robert Foley [Wed, 1 Jul 2020 13:56:17 +0000 (14:56 +0100)]
tests/vm: pass args through to BaseVM's __init__

Adding the args parameter to BaseVM's __init__.
We will shortly need to pass more parameters to the class
so let's just pass args rather than growing the parameter list.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200601211421[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agoutil/coroutine: Cleanup start_switch_fiber_ for TSAN.
Robert Foley [Wed, 1 Jul 2020 13:56:16 +0000 (14:56 +0100)]
util/coroutine: Cleanup start_switch_fiber_ for TSAN.

This is a cleanup patch to follow-up the patch which introduced TSAN.
This patch makes separate start_switch_fiber_ functions for TSAN and ASAN.

This does two things:
1. Unrelated ASAN and TSAN code is separate and each function only
   has arguments that are actually needed.
2. The co->tsan_caller_fiber and co->tsan_co_fiber fields are only
   access from within #ifdef CONFIG_TSAN.

Signed-off-by: Robert Foley <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <20200626170001[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agocrypto/linux_keyring: fix 'secret_keyring' configure test
David Edmondson [Wed, 1 Jul 2020 13:56:15 +0000 (14:56 +0100)]
crypto/linux_keyring: fix 'secret_keyring' configure test

The configure test for 'secret_keyring' incorrectly checked the
'have_keyring' variable.

Fixes: 54e7aac0562452e4fcab65ca5001d030eef2de15
Signed-off-by: David Edmondson <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Message-Id: <20200618092636[email protected]>
Message-Id: <20200701135652[email protected]>

4 years agoMerge remote-tracking branch 'remotes/aperard/tags/pull-xen-20200710' into staging
Peter Maydell [Sat, 11 Jul 2020 12:56:03 +0000 (13:56 +0100)]
Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20200710' into staging

xen patches

Fixes following harden checks in qdev.

# gpg: Signature made Fri 10 Jul 2020 14:05:46 BST
# gpg:                using RSA key F80C006308E22CFD8A92E7980CF5572FD7FB55AF
# gpg:                issuer "[email protected]"
# gpg: Good signature from "Anthony PERARD <[email protected]>" [marginal]
# gpg:                 aka "Anthony PERARD <[email protected]>" [marginal]
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 5379 2F71 024C 600F 778A  7161 D8D5 7199 DF83 42C8
#      Subkey fingerprint: F80C 0063 08E2 2CFD 8A92  E798 0CF5 572F D7FB 55AF

* remotes/aperard/tags/pull-xen-20200710:
  xen: cleanup unrealized flash devices
  xen: Fix xen-legacy-backend qdev types

Signed-off-by: Peter Maydell <[email protected]>
4 years agoMerge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
Peter Maydell [Fri, 10 Jul 2020 18:29:07 +0000 (19:29 +0100)]
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging

virtio: bugfix

fixes vdpa on non-kvm platforms

Signed-off-by: Michael S. Tsirkin <[email protected]>
# gpg: Signature made Wed 08 Jul 2020 11:17:48 BST
# gpg:                using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469
# gpg:                issuer "[email protected]"
# gpg: Good signature from "Michael S. Tsirkin <[email protected]>" [full]
# gpg:                 aka "Michael S. Tsirkin <[email protected]>" [full]
# Primary key fingerprint: 0270 606B 6F3C DF3D 0B17  0970 C350 3912 AFBE 8E67
#      Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA  8A0D 281F 0DB8 D28D 5469

* remotes/mst/tags/for_upstream:
  vhost-vdpa: fix the compile issue without kvm

Signed-off-by: Peter Maydell <[email protected]>
4 years agoMerge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-20200707' into...
Peter Maydell [Fri, 10 Jul 2020 15:43:40 +0000 (16:43 +0100)]
Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-20200707' into staging

qemu-openbios queue

# gpg: Signature made Tue 07 Jul 2020 21:57:37 BST
# gpg:                using RSA key CC621AB98E82200D915CC9C45BC2C56FAE0F321F
# gpg:                issuer "[email protected]"
# gpg: Good signature from "Mark Cave-Ayland <[email protected]>" [full]
# Primary key fingerprint: CC62 1AB9 8E82 200D 915C  C9C4 5BC2 C56F AE0F 321F

* remotes/mcayland/tags/qemu-openbios-20200707:
  Update OpenBIOS images to 75fbb41d built from submodule.

Signed-off-by: Peter Maydell <[email protected]>
4 years agoMerge remote-tracking branch 'remotes/armbru/tags/pull-error-2020-07-07-v2' into...
Peter Maydell [Fri, 10 Jul 2020 13:41:23 +0000 (14:41 +0100)]
Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2020-07-07-v2' into staging

Error reporting patches patches for 2020-07-07

# gpg: Signature made Fri 10 Jul 2020 14:24:42 BST
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "[email protected]"
# gpg: Good signature from "Markus Armbruster <[email protected]>" [full]
# gpg:                 aka "Markus Armbruster <[email protected]>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-error-2020-07-07-v2: (53 commits)
  xen: Use ERRP_GUARD()
  nbd: Use ERRP_GUARD()
  virtio-9p: Use ERRP_GUARD()
  fw_cfg: Use ERRP_GUARD()
  pflash: Use ERRP_GUARD()
  sd: Use ERRP_GUARD()
  scripts: Coccinelle script to use ERRP_GUARD()
  error: New macro ERRP_GUARD()
  hmp: Ignore Error objects where the return value suffices
  qdev: Ignore Error objects where the return value suffices
  qemu-img: Ignore Error objects where the return value suffices
  error: Avoid error_propagate() after migrate_add_blocker()
  qapi: Purge error_propagate() from QAPI core
  qapi: Smooth visitor error checking in generated code
  qapi: Smooth another visitor error checking pattern
  block/parallels: Simplify parallels_open() after previous commit
  error: Reduce unnecessary error propagation
  error: Eliminate error_propagate() manually
  error: Eliminate error_propagate() with Coccinelle, part 2
  error: Eliminate error_propagate() with Coccinelle, part 1
  ...

Signed-off-by: Peter Maydell <[email protected]>
4 years agoxen: Use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:37 +0000 (18:50 +0200)]
xen: Use ERRP_GUARD()

If we want to check error after errp-function call, we need to
introduce local_err and then propagate it to errp. Instead, use
the ERRP_GUARD() macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_GUARD() leaves errp as is if it's not NULL or
   &error_fatal, this means that we don't break error_abort
   (we'll abort on error_set, not on error_propagate)

If we want to add some info to errp (by error_prepend() or
error_append_hint()), we must use the ERRP_GUARD() macro.
Otherwise, this info will not be added when errp == &error_fatal
(the program will exit prior to the error_append_hint() or
error_prepend() call).  No such cases are being fixed here.

This commit is generated by command

    sed -n '/^X86 Xen CPUs$/,/^$/{s/^F: //p}' MAINTAINERS | \
    xargs git ls-files | grep '\.[hc]$' | \
    xargs spatch \
        --sp-file scripts/coccinelle/errp-guard.cocci \
        --macro-file scripts/cocci-macro-file.h \
        --in-place --no-show-diff --max-width 80

Reported-by: Kevin Wolf <[email protected]>
Reported-by: Greg Kurz <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
tweaked again.]

4 years agonbd: Use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:36 +0000 (18:50 +0200)]
nbd: Use ERRP_GUARD()

If we want to check error after errp-function call, we need to
introduce local_err and then propagate it to errp. Instead, use
the ERRP_GUARD() macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_GUARD() leaves errp as is if it's not NULL or
   &error_fatal, this means that we don't break error_abort
   (we'll abort on error_set, not on error_propagate)

If we want to add some info to errp (by error_prepend() or
error_append_hint()), we must use the ERRP_GUARD() macro.
Otherwise, this info will not be added when errp == &error_fatal
(the program will exit prior to the error_append_hint() or
error_prepend() call).  Fix several such cases, e.g. in nbd_read().

This commit is generated by command

    sed -n '/^Network Block Device (NBD)$/,/^$/{s/^F: //p}' \
        MAINTAINERS | \
    xargs git ls-files | grep '\.[hc]$' | \
    xargs spatch \
        --sp-file scripts/coccinelle/errp-guard.cocci \
        --macro-file scripts/cocci-macro-file.h \
        --in-place --no-show-diff --max-width 80

Reported-by: Kevin Wolf <[email protected]>
Reported-by: Greg Kurz <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Markus Armbruster <[email protected]>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
Reviewed-by: Eric Blake <[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
tweaked again.]

4 years agovirtio-9p: Use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:35 +0000 (18:50 +0200)]
virtio-9p: Use ERRP_GUARD()

If we want to check error after errp-function call, we need to
introduce local_err and then propagate it to errp. Instead, use
the ERRP_GUARD() macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_GUARD() leaves errp as is if it's not NULL or
   &error_fatal, this means that we don't break error_abort
   (we'll abort on error_set, not on error_propagate)

If we want to add some info to errp (by error_prepend() or
error_append_hint()), we must use the ERRP_GUARD() macro.
Otherwise, this info will not be added when errp == &error_fatal
(the program will exit prior to the error_append_hint() or
error_prepend() call).  Fix such a case in
v9fs_device_realize_common().

This commit is generated by command

    sed -n '/^virtio-9p$/,/^$/{s/^F: //p}' MAINTAINERS | \
    xargs git ls-files | grep '\.[hc]$' | \
    xargs spatch \
        --sp-file scripts/coccinelle/errp-guard.cocci \
        --macro-file scripts/cocci-macro-file.h \
        --in-place --no-show-diff --max-width 80

Reported-by: Kevin Wolf <[email protected]>
Reported-by: Greg Kurz <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Acked-by: Greg Kurz <[email protected]>
Reviewed-by: Christian Schoenebeck <[email protected]>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
tweaked again.]

4 years agofw_cfg: Use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:34 +0000 (18:50 +0200)]
fw_cfg: Use ERRP_GUARD()

If we want to check error after errp-function call, we need to
introduce local_err and then propagate it to errp. Instead, use
the ERRP_GUARD() macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_GUARD() leaves errp as is if it's not NULL or
   &error_fatal, this means that we don't break error_abort
   (we'll abort on error_set, not on error_propagate)

If we want to add some info to errp (by error_prepend() or
error_append_hint()), we must use the ERRP_GUARD() macro.
Otherwise, this info will not be added when errp == &error_fatal
(the program will exit prior to the error_append_hint() or
error_prepend() call).  No such cases are being fixed here.

This commit is generated by command

    sed -n '/^Firmware configuration (fw_cfg)$/,/^$/{s/^F: //p}' \
        MAINTAINERS | \
    xargs git ls-files | grep '\.[hc]$' | \
    xargs spatch \
        --sp-file scripts/coccinelle/errp-guard.cocci \
        --macro-file scripts/cocci-macro-file.h \
        --in-place --no-show-diff --max-width 80

Reported-by: Kevin Wolf <[email protected]>
Reported-by: Greg Kurz <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
tweaked again.  Coccinelle script rerun for commit 3203148917
"hw/nvram/fw_cfg: Add the FW_CFG_DATA_GENERATOR interface"]

4 years agopflash: Use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:33 +0000 (18:50 +0200)]
pflash: Use ERRP_GUARD()

If we want to check error after errp-function call, we need to
introduce local_err and then propagate it to errp. Instead, use
the ERRP_GUARD() macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_GUARD() leaves errp as is if it's not NULL or
   &error_fatal, this means that we don't break error_abort
   (we'll abort on error_set, not on error_propagate)

If we want to add some info to errp (by error_prepend() or
error_append_hint()), we must use the ERRP_GUARD() macro.
Otherwise, this info will not be added when errp == &error_fatal
(the program will exit prior to the error_append_hint() or
error_prepend() call).  No such cases are being fixed here.

This commit is generated by command

    sed -n '/^Parallel NOR Flash devices$/,/^$/{s/^F: //p}' \
        MAINTAINERS | \
    xargs git ls-files | grep '\.[hc]$' | \
    xargs spatch \
        --sp-file scripts/coccinelle/errp-guard.cocci \
        --macro-file scripts/cocci-macro-file.h \
        --in-place --no-show-diff --max-width 80

Reported-by: Kevin Wolf <[email protected]>
Reported-by: Greg Kurz <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
tweaked again.]

4 years agosd: Use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:32 +0000 (18:50 +0200)]
sd: Use ERRP_GUARD()

If we want to check error after errp-function call, we need to
introduce local_err and then propagate it to errp. Instead, use
the ERRP_GUARD() macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_GUARD() leaves errp as is if it's not NULL or
   &error_fatal, this means that we don't break error_abort
   (we'll abort on error_set, not on error_propagate)

If we want to add some info to errp (by error_prepend() or
error_append_hint()), we must use the ERRP_GUARD() macro.
Otherwise, this info will not be added when errp == &error_fatal
(the program will exit prior to the error_append_hint() or
error_prepend() call).  No such cases are being fixed here.

This commit is generated by command

    sed -n '/^SD (Secure Card)$/,/^$/{s/^F: //p}' \
        MAINTAINERS | \
    xargs git ls-files | grep '\.[hc]$' | \
    xargs spatch \
        --sp-file scripts/coccinelle/errp-guard.cocci \
        --macro-file scripts/cocci-macro-file.h \
        --in-place --no-show-diff --max-width 80

Reported-by: Kevin Wolf <[email protected]>
Reported-by: Greg Kurz <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
tweaked again.]

4 years agoscripts: Coccinelle script to use ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:31 +0000 (18:50 +0200)]
scripts: Coccinelle script to use ERRP_GUARD()

Script adds ERRP_GUARD() macro invocations where appropriate and
does corresponding changes in code (look for details in
include/qapi/error.h)

Usage example:
spatch --sp-file scripts/coccinelle/errp-guard.cocci \
 --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff \
 --max-width 80 FILES...

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Markus Armbruster <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
Reviewed-by: Eric Blake <[email protected]>
[ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
auto-propagated-errp.cocci to errp-guard.cocci]

4 years agoerror: New macro ERRP_GUARD()
Vladimir Sementsov-Ogievskiy [Tue, 7 Jul 2020 16:50:30 +0000 (18:50 +0200)]
error: New macro ERRP_GUARD()

Introduce a new ERRP_GUARD() macro, to be used at start of functions
with an errp OUT parameter.

It has three goals:

1. Fix issue with error_fatal and error_prepend/error_append_hint: the
user can't see this additional information, because exit() happens in
error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort and error_propagate: when we wrap
error_abort by local_err+error_propagate, the resulting coredump will
refer to error_propagate and not to the place where error happened.
(the macro itself doesn't fix the issue, but it allows us to [3.] drop
the local_err+error_propagate pattern, which will definitely fix the
issue) [Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround
void functions with errp parameter, when caller wants to know resulting
status. (Note: actually these functions could be merely updated to
return int error code).

To achieve these goals, later patches will add invocations
of this macro at the start of functions with either use
error_prepend/error_append_hint (solving 1) or which use
local_err+error_propagate to check errors, switching those
functions to use *errp instead (solving 2 and 3).

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Paul Durrant <[email protected]>
Reviewed-by: Greg Kurz <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
[Merge comments properly with recent commit "error: Document Error API
usage rules", and edit for clarity.  Put ERRP_AUTO_PROPAGATE() before
its helpers, and touch up style.  Tweak commit message.]
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <20200707165037.1026246[email protected]>
[Rename ERRP_AUTO_PROPAGATE() to ERRP_GUARD(), tweak commit message
again]

4 years agohmp: Ignore Error objects where the return value suffices
Markus Armbruster [Tue, 7 Jul 2020 16:06:13 +0000 (18:06 +0200)]
hmp: Ignore Error objects where the return value suffices

qdev_print_props() receives and throws away Error objects just to
check for object_property_get_str() and object_property_print()
failure.  Unnecessary, both return suitable values, so use those
instead.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqdev: Ignore Error objects where the return value suffices
Markus Armbruster [Tue, 7 Jul 2020 16:06:12 +0000 (18:06 +0200)]
qdev: Ignore Error objects where the return value suffices

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqemu-img: Ignore Error objects where the return value suffices
Markus Armbruster [Tue, 7 Jul 2020 16:06:11 +0000 (18:06 +0200)]
qemu-img: Ignore Error objects where the return value suffices

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>
[One more in img_amend() due to commit 0bc2a50e17 "qemu-option: Use
returned bool to check for failure"]

4 years agoerror: Avoid error_propagate() after migrate_add_blocker()
Markus Armbruster [Tue, 7 Jul 2020 16:06:10 +0000 (18:06 +0200)]
error: Avoid error_propagate() after migrate_add_blocker()

When migrate_add_blocker(blocker, &errp) is followed by
error_propagate(errp, err), we can often just as well do
migrate_add_blocker(..., errp).

Do that with this Coccinelle script:

    @@
    expression blocker, err, errp;
    expression ret;
    @@
    -    ret = migrate_add_blocker(blocker, &err);
    -    if (err) {
    +    ret = migrate_add_blocker(blocker, errp);
    +    if (ret < 0) {
             ... when != err;
    -        error_propagate(errp, err);
             ...
         }

    @@
    expression blocker, err, errp;
    @@
    -    migrate_add_blocker(blocker, &err);
    -    if (err) {
    +    if (migrate_add_blocker(blocker, errp) < 0) {
             ... when != err;
    -        error_propagate(errp, err);
             ...
         }

Double-check @err is not used afterwards.  Dereferencing it would be
use after free, but checking whether it's null would be legitimate.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqapi: Purge error_propagate() from QAPI core
Markus Armbruster [Tue, 7 Jul 2020 16:06:09 +0000 (18:06 +0200)]
qapi: Purge error_propagate() from QAPI core

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqapi: Smooth visitor error checking in generated code
Markus Armbruster [Tue, 7 Jul 2020 16:06:08 +0000 (18:06 +0200)]
qapi: Smooth visitor error checking in generated code

Use visitor functions' return values to check for failure.  Eliminate
error_propagate() that are now unnecessary.  Delete @err that are now
unused.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqapi: Smooth another visitor error checking pattern
Markus Armbruster [Tue, 7 Jul 2020 16:06:07 +0000 (18:06 +0200)]
qapi: Smooth another visitor error checking pattern

Convert

    visit_type_FOO(v, ..., &ptr, &err);
    ...
    if (err) {
        ...
    }

to

    visit_type_FOO(v, ..., &ptr, errp);
    ...
    if (!ptr) {
        ...
    }

for functions that set @ptr to non-null / null on success / error.

Eliminate error_propagate() that are now unnecessary.  Delete @err
that are now unused.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoblock/parallels: Simplify parallels_open() after previous commit
Markus Armbruster [Tue, 7 Jul 2020 16:06:06 +0000 (18:06 +0200)]
block/parallels: Simplify parallels_open() after previous commit

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoerror: Reduce unnecessary error propagation
Markus Armbruster [Tue, 7 Jul 2020 16:06:05 +0000 (18:06 +0200)]
error: Reduce unnecessary error propagation

When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away, even when we need to keep error_propagate() for other
error paths.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoerror: Eliminate error_propagate() manually
Markus Armbruster [Tue, 7 Jul 2020 16:06:04 +0000 (18:06 +0200)]
error: Eliminate error_propagate() manually

When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away.  The previous two commits did that for sufficiently simple
cases with Coccinelle.  Do it for several more manually.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoerror: Eliminate error_propagate() with Coccinelle, part 2
Markus Armbruster [Tue, 7 Jul 2020 16:06:03 +0000 (18:06 +0200)]
error: Eliminate error_propagate() with Coccinelle, part 2

When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away.  The previous commit did that with a Coccinelle script I
consider fairly trustworthy.  This commit uses the same script with
the matching of return taken out, i.e. we convert

    if (!foo(..., &err)) {
        ...
        error_propagate(errp, err);
        ...
    }

to

    if (!foo(..., errp)) {
        ...
        ...
    }

This is unsound: @err could still be read between afterwards.  I don't
know how to express "no read of @err without an intervening write" in
Coccinelle.  Instead, I manually double-checked for uses of @err.

Suboptimal line breaks tweaked manually.  qdev_realize() simplified
further to placate scripts/checkpatch.pl.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoerror: Eliminate error_propagate() with Coccinelle, part 1
Markus Armbruster [Tue, 7 Jul 2020 16:06:02 +0000 (18:06 +0200)]
error: Eliminate error_propagate() with Coccinelle, part 1

When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away.  Convert

    if (!foo(..., &err)) {
        ...
        error_propagate(errp, err);
        ...
        return ...
    }

to

    if (!foo(..., errp)) {
        ...
        ...
        return ...
    }

where nothing else needs @err.  Coccinelle script:

    @rule1 forall@
    identifier fun, err, errp, lbl;
    expression list args, args2;
    binary operator op;
    constant c1, c2;
    symbol false;
    @@
         if (
    (
    -        fun(args, &err, args2)
    +        fun(args, errp, args2)
    |
    -        !fun(args, &err, args2)
    +        !fun(args, errp, args2)
    |
    -        fun(args, &err, args2) op c1
    +        fun(args, errp, args2) op c1
    )
            )
         {
             ... when != err
                 when != lbl:
                 when strict
    -        error_propagate(errp, err);
             ... when != err
    (
             return;
    |
             return c2;
    |
             return false;
    )
         }

    @rule2 forall@
    identifier fun, err, errp, lbl;
    expression list args, args2;
    expression var;
    binary operator op;
    constant c1, c2;
    symbol false;
    @@
    -    var = fun(args, &err, args2);
    +    var = fun(args, errp, args2);
         ... when != err
         if (
    (
             var
    |
             !var
    |
             var op c1
    )
            )
         {
             ... when != err
                 when != lbl:
                 when strict
    -        error_propagate(errp, err);
             ... when != err
    (
             return;
    |
             return c2;
    |
             return false;
    |
             return var;
    )
         }

    @depends on rule1 || rule2@
    identifier err;
    @@
    -    Error *err = NULL;
         ... when != err

Not exactly elegant, I'm afraid.

The "when != lbl:" is necessary to avoid transforming

         if (fun(args, &err)) {
             goto out
         }
         ...
     out:
         error_propagate(errp, err);

even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().

Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly.  I don't know what exactly "when strict" does, only that
it helps here.

The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err".  For
an example where it's too narrow, see vfio_intx_enable().

Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there.  Converted manually.

Line breaks tidied up manually.  One nested declaration of @local_err
deleted manually.  Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoerror: Avoid unnecessary error_propagate() after error_setg()
Markus Armbruster [Tue, 7 Jul 2020 16:06:01 +0000 (18:06 +0200)]
error: Avoid unnecessary error_propagate() after error_setg()

Replace

    error_setg(&err, ...);
    error_propagate(errp, err);

by

    error_setg(errp, ...);

Related pattern:

    if (...) {
        error_setg(&err, ...);
        goto out;
    }
    ...
 out:
    error_propagate(errp, err);
    return;

When all paths to label out are that way, replace by

    if (...) {
        error_setg(errp, ...);
        return;
    }

and delete the label along with the error_propagate().

When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.

    foo(..., &err);
    if (err) {
        goto out;
    }
    ...
    bar(..., &err);
 out:
    error_propagate(errp, err);
    return;

move the error_propagate() to where it's needed, like

    if (...) {
        foo(..., &err);
        error_propagate(errp, err);
        return;
    }
    ...
    bar(..., errp);
    return;

and transform the error_setg() as above.

In some places, the transformation results in obviously unnecessary
error_propagate().  The next few commits will eliminate them.

Bonus: the elimination of gotos will make later patches in this series
easier to review.

Candidates for conversion tracked down with this Coccinelle script:

    @@
    identifier err, errp;
    expression list args;
    @@
    -    error_setg(&err, args);
    +    error_setg(errp, args);
         ... when != err
         error_propagate(errp, err);

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqdev: Use returned bool to check for failure, Coccinelle part
Markus Armbruster [Tue, 7 Jul 2020 16:06:00 +0000 (18:06 +0200)]
qdev: Use returned bool to check for failure, Coccinelle part

The previous commit enables conversion of

    qdev_prop_set_drive_err(..., &err);
    if (err) {
    ...
    }

to

    if (!qdev_prop_set_drive_err(..., errp)) {
    ...
    }

Coccinelle script:

    @@
    identifier fun = qdev_prop_set_drive_err;
    expression list args;
    typedef Error;
    Error *err;
    @@
    -    fun(args, &err);
    -    if (err)
    +    if (!fun(args, &err))
         {
             ...
         }

One line break tidied up manually.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqdev: Make functions taking Error ** return bool, not void
Markus Armbruster [Tue, 7 Jul 2020 16:05:59 +0000 (18:05 +0200)]
qdev: Make functions taking Error ** return bool, not void

See recent commit "error: Document Error API usage rules" for
rationale.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Make functions taking Error ** return bool, not 0/-1
Markus Armbruster [Tue, 7 Jul 2020 16:05:58 +0000 (18:05 +0200)]
qom: Make functions taking Error ** return bool, not 0/-1

Just for consistency.  Also fix the example in object_set_props()'s
documentation.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Use returned bool to check for failure, manual part
Markus Armbruster [Tue, 7 Jul 2020 16:05:57 +0000 (18:05 +0200)]
qom: Use returned bool to check for failure, manual part

The previous commit used Coccinelle to convert from checking the Error
object to checking the return value.  Convert a few more manually.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Use returned bool to check for failure, Coccinelle part
Markus Armbruster [Tue, 7 Jul 2020 16:05:56 +0000 (18:05 +0200)]
qom: Use returned bool to check for failure, Coccinelle part

The previous commit enables conversion of

    foo(..., &err);
    if (err) {
        ...
    }

to

    if (!foo(..., errp)) {
        ...
    }

for QOM functions that now return true / false on success / error.
Coccinelle script:

    @@
    identifier fun = {
        object_apply_global_props, object_initialize_child_with_props,
        object_initialize_child_with_propsv, object_property_get,
        object_property_get_bool, object_property_parse, object_property_set,
        object_property_set_bool, object_property_set_int,
        object_property_set_link, object_property_set_qobject,
        object_property_set_str, object_property_set_uint, object_set_props,
        object_set_propv, user_creatable_add_dict,
        user_creatable_complete, user_creatable_del
    };
    expression list args, args2;
    typedef Error;
    Error *err;
    @@
    -    fun(args, &err, args2);
    -    if (err)
    +    if (!fun(args, &err, args2))
         {
             ...
         }

Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.

Line breaks tidied up manually.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Make functions taking Error ** return bool, not void
Markus Armbruster [Tue, 7 Jul 2020 16:05:55 +0000 (18:05 +0200)]
qom: Make functions taking Error ** return bool, not void

See recent commit "error: Document Error API usage rules" for
rationale.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Put name parameter before value / visitor parameter
Markus Armbruster [Tue, 7 Jul 2020 16:05:54 +0000 (18:05 +0200)]
qom: Put name parameter before value / visitor parameter

The object_property_set_FOO() setters take property name and value in
an unusual order:

    void object_property_set_FOO(Object *obj, FOO_TYPE value,
                                 const char *name, Error **errp)

Having to pass value before name feels grating.  Swap them.

Same for object_property_set(), object_property_get(), and
object_property_parse().

Convert callers with this Coccinelle script:

    @@
    identifier fun = {
        object_property_get, object_property_parse, object_property_set_str,
        object_property_set_link, object_property_set_bool,
        object_property_set_int, object_property_set_uint, object_property_set,
        object_property_set_qobject
    };
    expression obj, v, name, errp;
    @@
    -    fun(obj, v, name, errp)
    +    fun(obj, name, v, errp)

Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information".  Convert that one manually.

Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.

Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually.  The other files using RXCPU that way don't need
conversion.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]

4 years agoqom: Use return values to check for error where that's simpler
Markus Armbruster [Tue, 7 Jul 2020 16:05:53 +0000 (18:05 +0200)]
qom: Use return values to check for error where that's simpler

When using the Error object to check for error, we need to receive it
into a local variable, then propagate() it to @errp.

Using the return value permits allows receiving it straight to @errp.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Don't handle impossible object_property_get_link() failure
Markus Armbruster [Tue, 7 Jul 2020 16:05:52 +0000 (18:05 +0200)]
qom: Don't handle impossible object_property_get_link() failure

Don't handle object_property_get_link() failure that can't happen
unless the programmer screwed up, pass &error_abort.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Crash more nicely on object_property_get_link() failure
Markus Armbruster [Tue, 7 Jul 2020 16:05:51 +0000 (18:05 +0200)]
qom: Crash more nicely on object_property_get_link() failure

Pass &error_abort instead of NULL where the returned value is
dereferenced or asserted to be non-null.  Drop a now redundant
assertion.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Rename qdev_get_type() to object_get_type()
Markus Armbruster [Tue, 7 Jul 2020 16:05:50 +0000 (18:05 +0200)]
qom: Rename qdev_get_type() to object_get_type()

Commit 2f262e06f0 lifted qdev_get_type() from qdev to object without
renaming it accordingly.  Do that now.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqom: Use error_reportf_err() instead of g_printerr() in examples
Markus Armbruster [Tue, 7 Jul 2020 16:05:49 +0000 (18:05 +0200)]
qom: Use error_reportf_err() instead of g_printerr() in examples

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agos390x/pci: Fix harmless mistake in zpci's property fid's setter
Markus Armbruster [Tue, 7 Jul 2020 16:05:48 +0000 (18:05 +0200)]
s390x/pci: Fix harmless mistake in zpci's property fid's setter

s390_pci_set_fid() sets zpci->fid_defined to true even when
visit_type_uint32() failed.  Reproducer: "-device zpci,fid=junk".
Harmless in practice, because qdev_device_add() then fails, throwing
away @zpci.  Fix it anyway.

Cc: Matthew Rosato <[email protected]>
Cc: Cornelia Huck <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Matthew Rosato <[email protected]>
Reviewed-by: Cornelia Huck <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqapi: Use returned bool to check for failure, manual part
Markus Armbruster [Tue, 7 Jul 2020 16:05:47 +0000 (18:05 +0200)]
qapi: Use returned bool to check for failure, manual part

The previous commit used Coccinelle to convert from checking the Error
object to checking the return value.  Convert a few more manually.
Also tweak control flow in places to conform to the conventional "if
error bail out" pattern.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqapi: Use returned bool to check for failure, Coccinelle part
Markus Armbruster [Tue, 7 Jul 2020 16:05:46 +0000 (18:05 +0200)]
qapi: Use returned bool to check for failure, Coccinelle part

The previous commit enables conversion of

    visit_foo(..., &err);
    if (err) {
        ...
    }

to

    if (!visit_foo(..., errp)) {
        ...
    }

for visitor functions that now return true / false on success / error.
Coccinelle script:

    @@
    identifier fun =~ "check_list|input_type_enum|lv_start_struct|lv_type_bool|lv_type_int64|lv_type_str|lv_type_uint64|output_type_enum|parse_type_bool|parse_type_int64|parse_type_null|parse_type_number|parse_type_size|parse_type_str|parse_type_uint64|print_type_bool|print_type_int64|print_type_null|print_type_number|print_type_size|print_type_str|print_type_uint64|qapi_clone_start_alternate|qapi_clone_start_list|qapi_clone_start_struct|qapi_clone_type_bool|qapi_clone_type_int64|qapi_clone_type_null|qapi_clone_type_number|qapi_clone_type_str|qapi_clone_type_uint64|qapi_dealloc_start_list|qapi_dealloc_start_struct|qapi_dealloc_type_anything|qapi_dealloc_type_bool|qapi_dealloc_type_int64|qapi_dealloc_type_null|qapi_dealloc_type_number|qapi_dealloc_type_str|qapi_dealloc_type_uint64|qobject_input_check_list|qobject_input_check_struct|qobject_input_start_alternate|qobject_input_start_list|qobject_input_start_struct|qobject_input_type_any|qobject_input_type_bool|qobject_input_type_bool_keyval|qobject_input_type_int64|qobject_input_type_int64_keyval|qobject_input_type_null|qobject_input_type_number|qobject_input_type_number_keyval|qobject_input_type_size_keyval|qobject_input_type_str|qobject_input_type_str_keyval|qobject_input_type_uint64|qobject_input_type_uint64_keyval|qobject_output_start_list|qobject_output_start_struct|qobject_output_type_any|qobject_output_type_bool|qobject_output_type_int64|qobject_output_type_null|qobject_output_type_number|qobject_output_type_str|qobject_output_type_uint64|start_list|visit_check_list|visit_check_struct|visit_start_alternate|visit_start_list|visit_start_struct|visit_type_.*";
    expression list args;
    typedef Error;
    Error *err;
    @@
    -    fun(args, &err);
    -    if (err)
    +    if (!fun(args, &err))
         {
             ...
         }

A few line breaks tidied up manually.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqapi: Make visitor functions taking Error ** return bool, not void
Markus Armbruster [Tue, 7 Jul 2020 16:05:45 +0000 (18:05 +0200)]
qapi: Make visitor functions taking Error ** return bool, not void

See recent commit "error: Document Error API usage rules" for
rationale.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agohmp: Eliminate a variable in hmp_migrate_set_parameter()
Markus Armbruster [Tue, 7 Jul 2020 16:05:44 +0000 (18:05 +0200)]
hmp: Eliminate a variable in hmp_migrate_set_parameter()

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoblock: Avoid error accumulation in bdrv_img_create()
Markus Armbruster [Tue, 7 Jul 2020 16:05:43 +0000 (18:05 +0200)]
block: Avoid error accumulation in bdrv_img_create()

When creating an image fails because the format doesn't support option
"backing_file" or "backing_fmt", bdrv_img_create() first has
qemu_opt_set() put a generic error into @local_err, then puts the real
error into @errp with error_setg(), and then propagates the former to
the latter, which throws away the generic error.  A bit complicated,
but works.

Now that qemu_opt_set() returns a useful value, we can simply ignore
the generic error instead.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqemu-option: Use returned bool to check for failure
Markus Armbruster [Tue, 7 Jul 2020 16:05:42 +0000 (18:05 +0200)]
qemu-option: Use returned bool to check for failure

The previous commit enables conversion of

    foo(..., &err);
    if (err) {
        ...
    }

to

    if (!foo(..., &err)) {
        ...
    }

for QemuOpts functions that now return true / false on success /
error.  Coccinelle script:

    @@
    identifier fun = {
        opts_do_parse, parse_option_bool, parse_option_number,
        parse_option_size, qemu_opt_parse, qemu_opt_rename, qemu_opt_set,
        qemu_opt_set_bool, qemu_opt_set_number, qemu_opts_absorb_qdict,
        qemu_opts_do_parse, qemu_opts_from_qdict_entry, qemu_opts_set,
        qemu_opts_validate
    };
    expression list args, args2;
    typedef Error;
    Error *err;
    @@
    -    fun(args, &err, args2);
    -    if (err)
    +    if (!fun(args, &err, args2))
         {
             ...
         }

A few line breaks tidied up manually.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>
[Conflict with commit 0b6786a9c1 "block/amend: refactor qcow2 amend
options" resolved by rerunning Coccinelle on master's version]

4 years agoqemu-option: Make functions taking Error ** return bool, not void
Markus Armbruster [Tue, 7 Jul 2020 16:05:41 +0000 (18:05 +0200)]
qemu-option: Make functions taking Error ** return bool, not void

See recent commit "error: Document Error API usage rules" for
rationale.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqemu-option: Replace opt_set() by cleaner opt_validate()
Markus Armbruster [Tue, 7 Jul 2020 16:05:40 +0000 (18:05 +0200)]
qemu-option: Replace opt_set() by cleaner opt_validate()

opt_set() frees its argument @value on failure.  Slightly unclean;
functions ideally do nothing on failure.

To tidy this up, move opt_create() from opt_set() into its callers,
along with the cleanup.  Rename opt_set() to opt_validate(), noting
its similarity to qemu_opts_validate().  Drop redundant parameter
@opts; use opt->opts instead.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqemu-option: Factor out helper opt_create()
Markus Armbruster [Tue, 7 Jul 2020 16:05:39 +0000 (18:05 +0200)]
qemu-option: Factor out helper opt_create()

There is just one use so far.  The next commit will add more.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqemu-option: Simplify around find_default_by_name()
Markus Armbruster [Tue, 7 Jul 2020 16:05:38 +0000 (18:05 +0200)]
qemu-option: Simplify around find_default_by_name()

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <20200707160613[email protected]>
Reviewed-by: Greg Kurz <[email protected]>
4 years agoqemu-option: Factor out helper find_default_by_name()
Markus Armbruster [Tue, 7 Jul 2020 16:05:37 +0000 (18:05 +0200)]
qemu-option: Factor out helper find_default_by_name()

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Greg Kurz <[email protected]>
Message-Id: <20200707160613[email protected]>

4 years agoqemu-option: Make uses of find_desc_by_name() more similar
Markus Armbruster [Tue, 7 Jul 2020 16:05:36 +0000 (18:05 +0200)]
qemu-option: Make uses of find_desc_by_name() more similar

This is to make the next commit easier to review.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Greg Kurz <[email protected]>
Message-Id: <20200707160613[email protected]>

This page took 0.100527 seconds and 4 git commands to generate.