OSDN Git Service

qmiga/qemu.git
3 years agoiotests: Test committing to overridden backing
Max Reitz [Mon, 6 Aug 2018 22:12:22 +0000 (00:12 +0200)]
iotests: Test committing to overridden backing

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoiotests: Add test for commit in sub directory
Max Reitz [Mon, 6 Aug 2018 21:33:07 +0000 (23:33 +0200)]
iotests: Add test for commit in sub directory

Add a test for committing an overlay in a sub directory to one of the
images in its backing chain, using both relative and absolute filenames.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoiotests: Add filter mirror test cases
Max Reitz [Mon, 6 Aug 2018 21:11:40 +0000 (23:11 +0200)]
iotests: Add filter mirror test cases

This patch adds some test cases how mirroring relates to filters.  One
of them tests what happens when you mirror off a filtered COW node, two
others use the mirror filter node as basically our only example of an
implicitly created filter node so far (besides the commit filter).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoiotests: Add filter commit test cases
Max Reitz [Wed, 1 Aug 2018 18:43:46 +0000 (20:43 +0200)]
iotests: Add filter commit test cases

This patch adds some tests on how commit copes with filter nodes.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoiotests: Let complete_and_wait() work with commit
Max Reitz [Tue, 11 Jun 2019 19:04:49 +0000 (21:04 +0200)]
iotests: Let complete_and_wait() work with commit

complete_and_wait() and wait_ready() currently only work for mirror
jobs.  Let them work for active commit jobs, too.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoiotests: Test that qcow2's data-file is flushed
Max Reitz [Wed, 13 Nov 2019 16:26:07 +0000 (17:26 +0100)]
iotests: Test that qcow2's data-file is flushed

Flushing a qcow2 node must lead to the data-file node being flushed as
well.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Leave BDS.backing_{file,format} constant
Max Reitz [Wed, 1 Aug 2018 18:34:11 +0000 (20:34 +0200)]
block: Leave BDS.backing_{file,format} constant

Parts of the block layer treat BDS.backing_file as if it were whatever
the image header says (i.e., if it is a relative path, it is relative to
the overlay), other parts treat it like a cache for
bs->backing->bs->filename (relative paths are relative to the CWD).
Considering bs->backing->bs->filename exists, let us make it mean the
former.

Among other things, this now allows the user to specify a base when
using qemu-img to commit an image file in a directory that is not the
CWD (assuming, everything uses relative filenames).

Before this patch:

$ ./qemu-img create -f qcow2 foo/bot.qcow2 1M
$ ./qemu-img create -f qcow2 -b bot.qcow2 foo/mid.qcow2
$ ./qemu-img create -f qcow2 -b mid.qcow2 foo/top.qcow2
$ ./qemu-img commit -b mid.qcow2 foo/top.qcow2
qemu-img: Did not find 'mid.qcow2' in the backing chain of 'foo/top.qcow2'
$ ./qemu-img commit -b foo/mid.qcow2 foo/top.qcow2
qemu-img: Did not find 'foo/mid.qcow2' in the backing chain of 'foo/top.qcow2'
$ ./qemu-img commit -b $PWD/foo/mid.qcow2 foo/top.qcow2
qemu-img: Did not find '[...]/foo/mid.qcow2' in the backing chain of 'foo/top.qcow2'

After this patch:

$ ./qemu-img commit -b mid.qcow2 foo/top.qcow2
Image committed.
$ ./qemu-img commit -b foo/mid.qcow2 foo/top.qcow2
qemu-img: Did not find 'foo/mid.qcow2' in the backing chain of 'foo/top.qcow2'
$ ./qemu-img commit -b $PWD/foo/mid.qcow2 foo/top.qcow2
Image committed.

With this change, bdrv_find_backing_image() must look at whether the
user has overridden a BDS's backing file.  If so, it can no longer use
bs->backing_file, but must instead compare the given filename against
the backing node's filename directly.

Note that this changes the QAPI output for a node's backing_file.  We
had very inconsistent output there (sometimes what the image header
said, sometimes the actual filename of the backing image).  This
inconsistent output was effectively useless, so we have to decide one
way or the other.  Considering that bs->backing_file usually at runtime
contained the path to the image relative to qemu's CWD (or absolute),
this patch changes QAPI's backing_file to always report the
bs->backing->bs->filename from now on.  If you want to receive the image
header information, you have to refer to full-backing-filename.

This necessitates a change to iotest 228.  The interesting information
it really wanted is the image header, and it can get that now, but it
has to use full-backing-filename instead of backing_file.  Because of
this patch's changes to bs->backing_file's behavior, we also need some
reference output changes.

Along with the changes to bs->backing_file, stop updating
BDS.backing_format in bdrv_backing_attach() as well.  This way,
ImageInfo's backing-filename and backing-filename-format fields will
represent what the image header says and nothing else.

iotest 245 changes in behavior: With the backing node no longer
overriding the parent node's backing_file string, you can now omit the
@backing option when reopening a node with neither a default nor a
current backing file even if it used to have a backing node at some
point.

273 also changes: The base image is opened without a format layer, so
ImageInfo.backing-filename-format used to report "file" for the base
image's overlay after blockdev-snapshot.  However, the image header
never says "file" anywhere, so it now reports $IMGFMT.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Inline bdrv_co_block_status_from_*()
Max Reitz [Wed, 13 Feb 2019 17:05:23 +0000 (18:05 +0100)]
block: Inline bdrv_co_block_status_from_*()

With bdrv_filter_bs(), we can easily handle this default filter behavior
in bdrv_co_block_status().

blkdebug wants to have an additional assertion, so it keeps its own
implementation, except bdrv_co_block_status_from_file() needs to be
inlined there.

Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblockdev: Fix active commit choice
Max Reitz [Tue, 11 Jun 2019 19:19:26 +0000 (21:19 +0200)]
blockdev: Fix active commit choice

We have to perform an active commit whenever the top node has a parent
that has taken the WRITE permission on it.

This means that block-commit's @backing-file parameter is no longer
allowed for such nodes, and that users will have to issue a
block-job-complete command.  Neither should pose a problem in practice,
because this case was basically just broken until now.

(Since this commit already touches block-commit's documentation, it also
moves up the chunk explaining general block-commit behavior that for
some reason was situated under @backing-file.)

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Drop backing_bs()
Max Reitz [Mon, 1 Apr 2019 20:16:14 +0000 (22:16 +0200)]
block: Drop backing_bs()

We want to make it explicit where bs->backing is used, and we have done
so.  The old role of backing_bs() is now effectively taken by
bdrv_cow_bs().

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoqemu-img: Use child access functions
Max Reitz [Wed, 12 Jun 2019 17:00:30 +0000 (19:00 +0200)]
qemu-img: Use child access functions

This changes iotest 204's output, because blkdebug on top of a COW node
used to make qemu-img map disregard the rest of the backing chain (the
backing chain was broken by the filter).  With this patch, the
allocation in the base image is reported correctly.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agonbd: Use CAF when looking for dirty bitmap
Max Reitz [Wed, 12 Jun 2019 16:55:04 +0000 (18:55 +0200)]
nbd: Use CAF when looking for dirty bitmap

When looking for a dirty bitmap to share, we should handle filters by
just including them in the search (so they do not break backing chains).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agocommit: Deal with filters
Max Reitz [Wed, 12 Jun 2019 15:47:37 +0000 (17:47 +0200)]
commit: Deal with filters

This includes some permission limiting (for example, we only need to
take the RESIZE permission if the base is smaller than the top).

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agobackup: Deal with filters
Max Reitz [Wed, 12 Jun 2019 15:46:45 +0000 (17:46 +0200)]
backup: Deal with filters

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agomirror: Deal with filters
Max Reitz [Wed, 12 Jun 2019 14:27:32 +0000 (16:27 +0200)]
mirror: Deal with filters

This includes some permission limiting (for example, we only need to
take the RESIZE permission for active commits where the base is smaller
than the top).

base_overlay is introduced so we can query bdrv_is_allocated_above() on
it - we cannot do that with base itself, because a filter's block_status
is the same as its child node, so if there are filters on base,
bdrv_is_allocated_above() on base would return information including
base.

Use this opportunity to rename qmp_drive_mirror()'s "source" BDS to
"target_backing_bs", because that is what it really refers to.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock-copy: Use CAF to find sync=top base
Max Reitz [Tue, 23 Jun 2020 09:29:04 +0000 (11:29 +0200)]
block-copy: Use CAF to find sync=top base

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Use child access functions for QAPI queries
Max Reitz [Wed, 12 Jun 2019 16:23:25 +0000 (18:23 +0200)]
block: Use child access functions for QAPI queries

query-block, query-named-block-nodes, and query-blockstats now return
any filtered child under "backing", not just bs->backing or COW
children.  This is so that filters do not interrupt the reported backing
chain.  This changes the output for iotest 184, as the throttled node
now appears as a backing child.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Report data child for query-blockstats
Max Reitz [Thu, 28 Nov 2019 08:49:22 +0000 (09:49 +0100)]
block: Report data child for query-blockstats

It makes no sense to report the block stats of a purely metadata-storing
child in query-blockstats.  So if the primary child does not have any
data, try to find a unique data-storing child.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblockdev: Use CAF in external_snapshot_prepare()
Max Reitz [Wed, 12 Jun 2019 16:34:46 +0000 (18:34 +0200)]
blockdev: Use CAF in external_snapshot_prepare()

This allows us to differentiate between filters and nodes with COW
backing files: Filters cannot be used as overlays at all (for this
function).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/null: Implement bdrv_get_allocated_file_size
Max Reitz [Mon, 22 Jun 2020 11:58:45 +0000 (13:58 +0200)]
block/null: Implement bdrv_get_allocated_file_size

It is trivial, so we might as well do it.

Remove _filter_actual_image_size from iotest 184, so we get to see the
result in its reference output.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Improve get_allocated_file_size's default
Max Reitz [Wed, 12 Jun 2019 16:14:13 +0000 (18:14 +0200)]
block: Improve get_allocated_file_size's default

There are two practical problems with bdrv_get_allocated_file_size()'s
default right now:
(1) For drivers with children, we should generally sum all their sizes
    instead of just passing the request through to bs->file.  The latter
    is good for filters, but not so much for format drivers.

(2) Filters need not have bs->file, so we should actually go to the
    filtered child instead of hard-coding bs->file.

Fix this by splitting the default implementation into three branches:
(1) For filter drivers: Return the size of the filtered child
(2) For protocol drivers: Return -ENOTSUP, because the default
    implementation cannot make a guess
(3) For other drivers: Sum all data-bearing children's sizes

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Use CAFs for debug breakpoints
Max Reitz [Wed, 12 Jun 2019 15:42:13 +0000 (17:42 +0200)]
block: Use CAFs for debug breakpoints

When looking for a blkdebug node (which implements debug breakpoints),
use bdrv_primary_bs() to iterate through the graph, because that is
where a blkdebug node would be.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/snapshot: Fix fallback
Max Reitz [Wed, 12 Jun 2019 16:21:07 +0000 (18:21 +0200)]
block/snapshot: Fix fallback

If the top node's driver does not provide snapshot functionality and we
want to fall back to a node down the chain, we need to snapshot all
non-COW children.  For simplicity's sake, just do not fall back if there
is more than one such child.  Furthermore, we really only can fall back
to bs->file and bs->backing, because bdrv_snapshot_goto() has to modify
the child link (notably, set it to NULL).

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Use CAF in bdrv_co_rw_vmstate()
Max Reitz [Wed, 12 Jun 2019 16:17:06 +0000 (18:17 +0200)]
block: Use CAF in bdrv_co_rw_vmstate()

If a node whose driver does not provide VM state functions has a
metadata child, the VM state should probably go there; if it is a
filter, the VM state should probably go there.  It follows that we
should generally go down to the primary child.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Use CAFs in bdrv_refresh_filename()
Max Reitz [Wed, 12 Jun 2019 15:43:03 +0000 (17:43 +0200)]
block: Use CAFs in bdrv_refresh_filename()

bdrv_refresh_filename() and the kind of related bdrv_dirname() should
look to the primary child when they wish to copy the underlying file's
filename.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Iterate over children in refresh_limits
Max Reitz [Wed, 12 Jun 2019 16:15:03 +0000 (18:15 +0200)]
block: Iterate over children in refresh_limits

Instead of looking at just bs->file and bs->backing, we should look at
all children that could end up receiving forwarded requests.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agovmdk: Drop vmdk_co_flush()
Max Reitz [Wed, 13 Nov 2019 14:53:42 +0000 (15:53 +0100)]
vmdk: Drop vmdk_co_flush()

Before HEAD^, we needed this because bdrv_co_flush() by itself would
only flush bs->file.  With HEAD^, bdrv_co_flush() will flush all
children on which a WRITE or WRITE_UNCHANGED permission has been taken.
Thus, vmdk no longer needs to do it itself.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Flush all children in generic code
Max Reitz [Wed, 12 Jun 2019 16:18:05 +0000 (18:18 +0200)]
block: Flush all children in generic code

If the driver does not support .bdrv_co_flush() so bdrv_co_flush()
itself has to flush the children of the given node, it should not flush
just bs->file->bs, but in fact all children that might have been written
to (judging from the permissions taken on them).

This is a bug fix for qcow2 images with an external data file, as they
so far did not flush that data_file node.

In any case, the BLKDBG_EVENT() should be emitted on the primary child,
because that is where a blkdebug node would be if there is any.

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Re-evaluate backing file handling in reopen
Max Reitz [Wed, 12 Jun 2019 15:24:39 +0000 (17:24 +0200)]
block: Re-evaluate backing file handling in reopen

Reopening a node's backing child needs a bit of special handling because
the "backing" child has different defaults than all other children
(among other things).  Adding filter support here is a bit more
difficult than just using the child access functions.  In fact, we often
have to directly use bs->backing because these functions are about the
"backing" child (which may or may not be the COW backing file).

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Use bdrv_cow_child() in bdrv_co_truncate()
Max Reitz [Thu, 18 Jun 2020 15:39:28 +0000 (17:39 +0200)]
block: Use bdrv_cow_child() in bdrv_co_truncate()

The condition modified here is not about potentially filtered children,
but only about COW sources (i.e. traditional backing files).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Use CAFs when working with backing chains
Max Reitz [Wed, 12 Jun 2019 15:34:45 +0000 (17:34 +0200)]
block: Use CAFs when working with backing chains

Use child access functions when iterating through backing chains so
filters do not break the chain.

In addition, bdrv_find_overlay() will now always return the actual
overlay; that is, it will never return a filter node but only one with a
COW backing file (there may be filter nodes between that node and @bs).

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agostream: Deal with filters
Max Reitz [Wed, 12 Jun 2019 15:48:11 +0000 (17:48 +0200)]
stream: Deal with filters

Because of the (not so recent anymore) changes that make the stream job
independent of the base node and instead track the node above it, we
have to split that "bottom" node into two cases: The bottom COW node,
and the node directly above the base node (which may be an R/W filter
or the bottom COW node).

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Use CAFs in block status functions
Max Reitz [Wed, 12 Jun 2019 15:59:07 +0000 (17:59 +0200)]
block: Use CAFs in block status functions

Use the child access functions in the block status inquiry functions as
appropriate.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Use bdrv_filter_(bs|child) where obvious
Max Reitz [Wed, 12 Jun 2019 15:03:38 +0000 (17:03 +0200)]
block: Use bdrv_filter_(bs|child) where obvious

Places that use patterns like

    if (bs->drv->is_filter && bs->file) {
        ... something about bs->file->bs ...
    }

should be

    BlockDriverState *filtered = bdrv_filter_bs(bs);
    if (filtered) {
        ... something about @filtered ...
    }

instead.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agocopy-on-read: Support compressed writes
Max Reitz [Thu, 28 Nov 2019 15:12:36 +0000 (16:12 +0100)]
copy-on-read: Support compressed writes

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agothrottle: Support compressed writes
Max Reitz [Wed, 12 Jun 2019 20:52:27 +0000 (22:52 +0200)]
throttle: Support compressed writes

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Add bdrv_supports_compressed_writes()
Max Reitz [Wed, 12 Jun 2019 20:57:15 +0000 (22:57 +0200)]
block: Add bdrv_supports_compressed_writes()

Filters cannot compress data themselves but they have to implement
.bdrv_co_pwritev_compressed() still (or they cannot forward compressed
writes).  Therefore, checking whether
bs->drv->bdrv_co_pwritev_compressed is non-NULL is not sufficient to
know whether the node can actually handle compressed writes.  This
function looks down the filter chain to see whether there is a
non-filter that can actually convert the compressed writes into
compressed data (and thus normal writes).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Drop bdrv_is_encrypted()
Max Reitz [Wed, 12 Jun 2019 15:08:20 +0000 (17:08 +0200)]
block: Drop bdrv_is_encrypted()

The original purpose of bdrv_is_encrypted() was to inquire whether a BDS
can be used without the user entering a password or not.  It has not
been used for that purpose for quite some time.

Actually, it is not even fit for that purpose, because to answer that
question, it would have recursively query all of the given node's
children.

So now we have to decide in which direction we want to fix
bdrv_is_encrypted(): Recursively query all children, or drop it and just
use bs->encrypted to get the current node's status?

Nowadays, its only purpose is to report through bdrv_query_image_info()
whether the given image is encrypted or not.  For this purpose, it is
probably more interesting to see whether a given node itself is
encrypted or not (otherwise, a management application cannot discern for
certain which nodes are really encrypted and which just have encrypted
children).

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Include filters when freezing backing chain
Max Reitz [Wed, 12 Jun 2019 14:07:11 +0000 (16:07 +0200)]
block: Include filters when freezing backing chain

In order to make filters work in backing chains, the associated
functions must be able to deal with them and freeze both COW and filter
child links.

While at it, add some comments that note which functions require their
caller to ensure that a given child link is not frozen, and how the
callers do so.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: bdrv_set_backing_hd() is about bs->backing
Max Reitz [Wed, 12 Jun 2019 16:42:34 +0000 (18:42 +0200)]
block: bdrv_set_backing_hd() is about bs->backing

bdrv_set_backing_hd() is a function that explicitly cares about the
bs->backing child.  Highlight that in its description and use
child_bs(bs->backing) instead of backing_bs(bs) to make it more obvious.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: bdrv_cow_child() for bdrv_has_zero_init()
Max Reitz [Wed, 12 Jun 2019 15:10:46 +0000 (17:10 +0200)]
block: bdrv_cow_child() for bdrv_has_zero_init()

bdrv_has_zero_init() should use bdrv_cow_child() if it wants to check
whether the given BDS has a COW backing file.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Add chain helper functions
Max Reitz [Wed, 12 Jun 2019 13:06:37 +0000 (15:06 +0200)]
block: Add chain helper functions

Add some helper functions for skipping filters in a chain of block
nodes.

Signed-off-by: Max Reitz <mreitz@redhat.com>
3 years agoblock: Add child access functions
Max Reitz [Fri, 31 May 2019 13:23:11 +0000 (15:23 +0200)]
block: Add child access functions

There are BDS children that the general block layer code can access,
namely bs->file and bs->backing.  Since the introduction of filters and
external data files, their meaning is not quite clear.  bs->backing can
be a COW source, or it can be a filtered child; bs->file can be a
filtered child, it can be data and metadata storage, or it can be just
metadata storage.

This overloading really is not helpful.  This patch adds functions that
retrieve the correct child for each exact purpose.  Later patches in
this series will make use of them.  Doing so will allow us to handle
filter nodes in a meaningful way.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
3 years agoblock/nvme: Use an array of EventNotifier
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:59 +0000 (21:53 +0200)]
block/nvme: Use an array of EventNotifier

In preparation of using multiple IRQ (thus multiple eventfds)
make BDRVNVMeState::irq_notifier an array (for now of a single
element, the admin queue notifier).

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-16-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Extract nvme_poll_queue()
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:58 +0000 (21:53 +0200)]
block/nvme: Extract nvme_poll_queue()

As we want to do per-queue polling, extract the nvme_poll_queue()
method which operates on a single queue.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-15-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Simplify nvme_create_queue_pair() arguments
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:57 +0000 (21:53 +0200)]
block/nvme: Simplify nvme_create_queue_pair() arguments

nvme_create_queue_pair() doesn't require BlockDriverState anymore.
Replace it by BDRVNVMeState and AioContext to simplify.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-14-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Replace BDRV_POLL_WHILE by AIO_WAIT_WHILE
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:56 +0000 (21:53 +0200)]
block/nvme: Replace BDRV_POLL_WHILE by AIO_WAIT_WHILE

BDRV_POLL_WHILE() is defined as:

  #define BDRV_POLL_WHILE(bs, cond) ({          \
      BlockDriverState *bs_ = (bs);             \
      AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \
                     cond); })

As we will remove the BlockDriverState use in the next commit,
start by using the exploded version of BDRV_POLL_WHILE().

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-13-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Simplify nvme_init_queue() arguments
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:55 +0000 (21:53 +0200)]
block/nvme: Simplify nvme_init_queue() arguments

nvme_init_queue() doesn't require BlockDriverState anymore.
Replace it by BDRVNVMeState to simplify.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-12-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Replace qemu_try_blockalign(bs) by qemu_try_memalign(pg_sz)
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:54 +0000 (21:53 +0200)]
block/nvme: Replace qemu_try_blockalign(bs) by qemu_try_memalign(pg_sz)

qemu_try_blockalign() is a generic API that call back to the
block driver to return its page alignment. As we call from
within the very same driver, we already know to page alignment
stored in our state. Remove indirections and use the value from
BDRVNVMeState.
This change is required to later remove the BlockDriverState
argument, to make nvme_init_queue() per hardware, and not per
block driver.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-11-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:53 +0000 (21:53 +0200)]
block/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset

In the next commit we'll get rid of qemu_try_blockalign().
To ease review, first replace qemu_try_blockalign0() by explicit
calls to qemu_try_blockalign() and memset().

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-10-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Use union of NvmeIdCtrl / NvmeIdNs structures
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:52 +0000 (21:53 +0200)]
block/nvme: Use union of NvmeIdCtrl / NvmeIdNs structures

We allocate an unique chunk of memory then use it for two
different structures. By using an union, we make it clear
the data is overlapping (and we can remove the casts).

Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-9-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Rename local variable
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:51 +0000 (21:53 +0200)]
block/nvme: Rename local variable

We are going to modify the code in the next commit. Renaming
the 'resp' variable to 'id' first makes the next commit easier
to review. No logical changes.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-8-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Use common error path in nvme_add_io_queue()
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:50 +0000 (21:53 +0200)]
block/nvme: Use common error path in nvme_add_io_queue()

Rearrange nvme_add_io_queue() by using a common error path.
This will be proven useful in few commits where we add IRQ
notification to the IO queues.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-7-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Improve error message when IO queue creation failed
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:49 +0000 (21:53 +0200)]
block/nvme: Improve error message when IO queue creation failed

Do not use the same error message for different failures.
Display a different error whether it is the CQ or the SQ.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-6-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Define INDEX macros to ease code review
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:48 +0000 (21:53 +0200)]
block/nvme: Define INDEX macros to ease code review

Use definitions instead of '0' or '1' indexes. Also this will
be useful when using multi-queues later.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-5-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Let nvme_create_queue_pair() fail gracefully
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:47 +0000 (21:53 +0200)]
block/nvme: Let nvme_create_queue_pair() fail gracefully

As nvme_create_queue_pair() is allowed to fail, replace the
alloc() calls by try_alloc() to avoid aborting QEMU.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-4-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Avoid further processing if trace event not enabled
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:46 +0000 (21:53 +0200)]
block/nvme: Avoid further processing if trace event not enabled

Avoid further processing if TRACE_NVME_SUBMIT_COMMAND_RAW is
not enabled. This is an untested intend of performance optimization.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-3-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock/nvme: Replace magic value by SCALE_MS definition
Philippe Mathieu-Daudé [Fri, 21 Aug 2020 19:53:45 +0000 (21:53 +0200)]
block/nvme: Replace magic value by SCALE_MS definition

Use self-explicit SCALE_MS definition instead of magic value.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200821195359.1285345-2-philmd@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoblock: Raise an error when backing file parameter is an empty string
Connor Kuehl [Thu, 13 Aug 2020 13:47:22 +0000 (08:47 -0500)]
block: Raise an error when backing file parameter is an empty string

Providing an empty string for the backing file parameter like so:

qemu-img create -f qcow2 -b '' /tmp/foo

allows the flow of control to reach and subsequently fail an assert
statement because passing an empty string to

bdrv_get_full_backing_filename_from_filename()

simply results in NULL being returned without an error being raised.

To fix this, let's check for an empty string when getting the value from
the opts list.

Reported-by: Attila Fazekas <afazekas@redhat.com>
Fixes: https://bugzilla.redhat.com/1809553
Signed-off-by: Connor Kuehl <ckuehl@redhat.com>
Message-Id: <20200813134722.802180-1-ckuehl@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3 years agoMerge remote-tracking branch 'remotes/kraxel/tags/ui-20200904-pull-request' into...
Peter Maydell [Sun, 6 Sep 2020 15:23:55 +0000 (16:23 +0100)]
Merge remote-tracking branch 'remotes/kraxel/tags/ui-20200904-pull-request' into staging

ui: memleak fixes.
gtk: refresh interval fix.
spice: add mouse buttons.

# gpg: Signature made Fri 04 Sep 2020 08:00:55 BST
# gpg:                using RSA key 4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full]
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>" [full]
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full]
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/ui-20200904-pull-request:
  ui/gtk: Update refresh interval after widget is realized
  ui: Add more mouse buttons to SPICE
  vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string
  ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agoMerge remote-tracking branch 'remotes/rth/tags/pull-tcg-20200903' into staging
Peter Maydell [Sat, 5 Sep 2020 14:30:40 +0000 (15:30 +0100)]
Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20200903' into staging

Improve inlining in cputlb.c.
Fix vector abs fallback.
Only set parallel_cpus for SMP.
Add vector dupm for 256-bit elements.

# gpg: Signature made Thu 03 Sep 2020 22:38:25 BST
# gpg:                using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F
# gpg:                issuer "richard.henderson@linaro.org"
# gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full]
# Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A  05C0 64DF 38E8 AF7E 215F

* remotes/rth/tags/pull-tcg-20200903:
  tcg: Implement 256-bit dup for tcg_gen_gvec_dup_mem
  tcg: Eliminate one store for in-place 128-bit dup_mem
  softmmu/cpus: Only set parallel_cpus for SMP
  tcg: Fix tcg gen for vectorized absolute value
  cputlb: Make store_helper less fragile to compiler optimizations

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agoMerge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-09-03' into staging
Peter Maydell [Fri, 4 Sep 2020 22:24:02 +0000 (23:24 +0100)]
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-09-03' into staging

QAPI patches patches for 2020-09-03

# gpg: Signature made Thu 03 Sep 2020 09:00:37 BST
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-qapi-2020-09-03:
  docs/qdev-device-use: Don't suggest -drive and -net can do USB
  qapi: Document event VSERPORT_CHANGE is rate-limited
  docs/interop/qmp-spec: Point to the QEMU QMP reference manual
  scripts/qmp/qom-fuse: Fix getattr(), read() for files in /
  scripts/qmp/qom-fuse: Port to current Python module fuse
  scripts/qmp/qom-fuse: Unbreak import of QEMUMonitorProtocol
  qapi/block-core.json: Remove stale description of 'blockdev-add'
  qapi: enable use of g_autoptr with QAPI types

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agoMerge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.2-pull-request...
Peter Maydell [Fri, 4 Sep 2020 14:53:56 +0000 (15:53 +0100)]
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.2-pull-request' into staging

Add btrfs support
Fix MK_ARRAY()

# gpg: Signature made Thu 03 Sep 2020 00:26:37 BST
# gpg:                using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C
# gpg:                issuer "laurent@vivier.eu"
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full]
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>" [full]
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full]
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* remotes/vivier2/tags/linux-user-for-5.2-pull-request:
  linux-user: Add support for btrfs ioctls used to scrub a filesystem
  linux-user: Add support for btrfs ioctls used to manage quota
  linux-user: Add support for two btrfs ioctls used for subvolume
  linux-user: Add support for a group of btrfs inode ioctls
  linux-user: Add support for btrfs ioctls used to get/set features
  linux-user: Add support for btrfs ioctls used to manipulate with devices
  linux-user: Add support for a group of btrfs ioctls used for snapshots
  linux-user: Add support for a group of btrfs ioctls used for subvolumes
  linux-user: fix implicit conversion from enumeration type error

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agoui/gtk: Update refresh interval after widget is realized
Philippe Mathieu-Daudé [Mon, 17 Aug 2020 17:23:31 +0000 (19:23 +0200)]
ui/gtk: Update refresh interval after widget is realized

Nikola reported on Windows when gd_vc_gfx_init() is called, the
window is not yet realized, so we run gd_refresh_rate_millihz(NULL)
which returns 0 milli-Hertz.
When a Widget is realized, it fires a 'realized' event. We already
have the gd_draw_event() handler registered for this even, so simply
move the gd_refresh_rate_millihz() there. When the event fires, the
window is known to exist.
This completes commit c4c00922cc original intention.

Reported-by: Nikola Pavlica <pavlica.nikola@gmail.com>
Tested-by: Nikola Pavlica <pavlica.nikola@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200817172331.598255-1-philmd@redhat.com
Suggested-by: Nikola Pavlica <pavlica.nikola@gmail.com>
Tested-by: Nikola Pavlica <pavlica.nikola@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agoui: Add more mouse buttons to SPICE
Frediano Ziglio [Thu, 20 Aug 2020 14:58:51 +0000 (15:58 +0100)]
ui: Add more mouse buttons to SPICE

Add support for SIDE and EXTRA buttons.

The constants for buttons in both SPICE and QEMU are defined as
  LEFT
  MIDDLE
  RIGHT
  UP
  DOWN
  SIDE
  EXTRA
(same order).

"button_mask" contains for each bit the state of a button. Qemu currently
uses bits 0, 1, 2 respectively as LEFT, RIGHT, MIDDLE; also add bits 4
and 5 as UP and DOWN (using wheel movements). SPICE protocol uses
a bitmask based on the order above where LEFT is bit 0, MIDDLE is
bit 1 and so on till EXTRA being bit 6. To avoid clash with Qemu usage
SPICE bitmask from SIDE are move a bit more resulting respectively
in 0x40 and 0x80 values.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Message-id: 20200820145851.50846-1-fziglio@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agovnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string
Pan Nengyuan [Mon, 31 Aug 2020 13:43:15 +0000 (09:43 -0400)]
vnc-auth-sasl: Plug memleak in vnc_socket_ip_addr_string

'addr' is forgot to free in vnc_socket_ip_addr_string error path. Fix that.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Message-Id: <20200831134315.1221-11-pannengyuan@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agoui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()
Pan Nengyuan [Mon, 31 Aug 2020 13:43:10 +0000 (09:43 -0400)]
ui/gtk-gl-area: Plug memleak in gd_gl_area_create_context()

Receiving error in local variable err, and forgot to free it.
This patch check the return value of 'gdk_window_create_gl_context'
and 'gdk_gl_context_realize', then free err to fix it.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Message-Id: <20200831134315.1221-6-pannengyuan@huawei.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agoMerge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2020-09-02' into staging
Peter Maydell [Thu, 3 Sep 2020 20:35:01 +0000 (21:35 +0100)]
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2020-09-02' into staging

nbd patches for 2020-09-02

- fix a few iotests affected by earlier nbd changes
- avoid blocking qemu by nbd client in connect()
- build qemu-nbd for mingw

# gpg: Signature made Wed 02 Sep 2020 22:52:31 BST
# gpg:                using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full]
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full]
# gpg:                 aka "[jpeg image of size 6874]" [full]
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2020-09-02:
  nbd: disable signals and forking on Windows builds
  nbd: skip SIGTERM handler if NBD device support is not built
  block: add missing socket_init() calls to tools
  block/nbd: use non-blocking connect: fix vm hang on connect()
  iotests/259: Fix reference output
  iotests/059: Fix reference output

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agotcg: Implement 256-bit dup for tcg_gen_gvec_dup_mem
Richard Henderson [Wed, 17 Jun 2020 21:13:43 +0000 (14:13 -0700)]
tcg: Implement 256-bit dup for tcg_gen_gvec_dup_mem

We already support duplication of 128-bit blocks.  This extends
that support to 256-bit blocks.  This will be needed by SVE2.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3 years agotcg: Eliminate one store for in-place 128-bit dup_mem
Richard Henderson [Fri, 14 Aug 2020 22:02:57 +0000 (15:02 -0700)]
tcg: Eliminate one store for in-place 128-bit dup_mem

Do not store back to the exact memory from which we just loaded.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3 years agosoftmmu/cpus: Only set parallel_cpus for SMP
Richard Henderson [Wed, 5 Aug 2020 23:06:26 +0000 (16:06 -0700)]
softmmu/cpus: Only set parallel_cpus for SMP

Do not set parallel_cpus if there is only one cpu instantiated.
This will allow tcg to use serial code to implement atomics.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3 years agotcg: Fix tcg gen for vectorized absolute value
Stephen Long [Thu, 13 Aug 2020 16:18:18 +0000 (09:18 -0700)]
tcg: Fix tcg gen for vectorized absolute value

The fallback inline expansion for vectorized absolute value,
when the host doesn't support such an insn was flawed.

E.g. when a vector of bytes has all elements negative, mask
will be 0xffff_ffff_ffff_ffff.  Subtracting mask only adds 1
to the low element instead of all elements becase -mask is 1
and not 0x0101_0101_0101_0101.

Signed-off-by: Stephen Long <steplong@quicinc.com>
Message-Id: <20200813161818.190-1-steplong@quicinc.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3 years agocputlb: Make store_helper less fragile to compiler optimizations
Richard Henderson [Sun, 26 Jul 2020 22:39:53 +0000 (15:39 -0700)]
cputlb: Make store_helper less fragile to compiler optimizations

This has no functional change.

The current function structure is:

    inline QEMU_ALWAYSINLINE
    store_memop() {
        switch () {
            ...
        default:
            qemu_build_not_reached();
        }
    }
    inline QEMU_ALWAYSINLINE
    store_helper() {
        ...
        if (span_two_pages_or_io) {
            ...
            helper_ret_stb_mmu();
        }
        store_memop();
    }
    helper_ret_stb_mmu() {
        store_helper();
    }

Whereas GCC will generate an error at compile-time when an always_inline
function is not inlined, Clang does not.  Nor does Clang prioritize the
inlining of always_inline functions.  Both of these are arguably bugs.

Both `store_memop` and `store_helper` need to be inlined and allow
constant propogations to eliminate the `qemu_build_not_reached` call.

However, if the compiler instead chooses to inline helper_ret_stb_mmu
into store_helper, then store_helper is now self-recursive and the
compiler is no longer able to propagate the constant in the same way.

This does not produce at current QEMU head, but was reproducible
at v4.2.0 with `clang-10 -O2 -fexperimental-new-pass-manager`.

The inline recursion problem can be fixed solely by marking
helper_ret_stb_mmu as noinline, so the compiler does not make an
incorrect decision about which functions to inline.

In addition, extract store_helper_unaligned as a noinline subroutine
that can be shared by all of the helpers.  This saves about 6k code
size in an optimized x86_64 build.

Reported-by: Shu-Chun Weng <scw@google.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3 years agoMerge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-09-03' into...
Peter Maydell [Thu, 3 Sep 2020 15:58:24 +0000 (16:58 +0100)]
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-09-03' into staging

* Cirrus-CI improvements and fixes (compile with -Werror & fix for 1h problem)
* Two build system fixes to fix some failures the CI
* One m68k QOMification patch
* Some trivial qtest patches
* Some small improvements for the Gitlab CI

# gpg: Signature made Thu 03 Sep 2020 12:04:32 BST
# gpg:                using RSA key 27B88847EEE0250118F3EAB92ED9D774FE702DB5
# gpg:                issuer "thuth@redhat.com"
# gpg: Good signature from "Thomas Huth <th.huth@gmx.de>" [full]
# gpg:                 aka "Thomas Huth <thuth@redhat.com>" [full]
# gpg:                 aka "Thomas Huth <huth@tuxfamily.org>" [full]
# gpg:                 aka "Thomas Huth <th.huth@posteo.de>" [unknown]
# Primary key fingerprint: 27B8 8847 EEE0 2501 18F3  EAB9 2ED9 D774 FE70 2DB5

* remotes/huth-gitlab/tags/pull-request-2020-09-03:
  gitlab-ci.yml: Set artifacts expiration time
  gitlab-ci.yml: Run check-qtest and check-unit at the end of the fuzzer job
  gitlab/travis: Rework the disabled features tests
  libqtest: Rename qmp_assert_error_class() to qmp_expect_error_and_unref()
  tests/qtest/ipmi-kcs: Fix assert side-effect
  tests/qtest/tpm: Declare input buffers const and static
  tests/qtest/ahci: Improve error handling (NEGATIVE_RETURNS)
  hw/m68k: QOMify the mcf5206 system integration module
  configure: Add system = 'linux' for meson when cross-compiling
  meson: fix keymaps without qemu-keymap
  cirrus.yml: Split FreeBSD job into two parts
  cirrus.yml: Update the macOS jobs to Catalina
  cirrus.yml: Compile macOS with -Werror
  cirrus.yml: Compile FreeBSD with -Werror
  configure: Fix atomic64 test for --enable-werror on macOS

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agoMerge remote-tracking branch 'remotes/legoater/tags/pull-aspeed-20200901' into staging
Peter Maydell [Thu, 3 Sep 2020 13:12:48 +0000 (14:12 +0100)]
Merge remote-tracking branch 'remotes/legoater/tags/pull-aspeed-20200901' into staging

Various fixes of Aspeed machines :

* New Supermicro X11 BMC machine (Erik)
* Fixed valid access size on AST2400 SCU
* Improved robustness of the ftgmac100 model.
* New flash models in m25p80 (Igor)
* Fixed reset sequence of SDHCI/eMMC controllers
* Improved support of the AST2600 SDMC  (Joel)
* Couple of SMC cleanups

# gpg: Signature made Tue 01 Sep 2020 13:39:20 BST
# gpg:                using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1
# gpg: Good signature from "Cédric Le Goater <clg@kaod.org>" [undefined]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: A0F6 6548 F048 95EB FE6B  0B60 51A3 43C7 CFFB ECA1

* remotes/legoater/tags/pull-aspeed-20200901:
  hw: add a number of SPI-flash's of m25p80 family
  arm: aspeed: add strap define `25HZ` of AST2500
  aspeed/smc: Open AHB window of the second chip of the AST2600 FMC controller
  aspeed/sdmc: Simplify calculation of RAM bits
  aspeed/sdmc: Allow writes to unprotected registers
  aspeed/sdmc: Perform memory training
  ftgmac100: Improve software reset
  ftgmac100: Fix integer overflow in ftgmac100_do_tx()
  ftgmac100: Check for invalid len and address before doing a DMA transfer
  ftgmac100: Change interrupt status when a DMA error occurs
  ftgmac100: Fix interrupt status "Packet moved to RX FIFO"
  ftgmac100: Fix interrupt status "Packet transmitted on ethernet"
  ftgmac100: Fix registers that can be read
  aspeed/sdhci: Fix reset sequence
  aspeed/smc: Fix max_slaves of the legacy SMC device
  aspeed/smc: Fix MemoryRegionOps definition
  hw/arm/aspeed: Add board model for Supermicro X11 BMC
  aspeed/scu: Fix valid access size on AST2400
  m25p80: Add support for n25q512ax3
  m25p80: Return the JEDEC ID twice for mx25l25635e

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3 years agogitlab-ci.yml: Set artifacts expiration time
Thomas Huth [Wed, 5 Aug 2020 21:10:44 +0000 (23:10 +0200)]
gitlab-ci.yml: Set artifacts expiration time

The default expiration time for artifacts seems to be very high (30 days?).
Since we only need the artifacts to pass the binaries from one stage to
the next one, we can decrease the expiration time to avoid to spam the
file server too much. Two days should be enough in case someone still wants
to have a look after the pipeline finished.

Message-Id: <20200806161546.15325-1-thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agogitlab-ci.yml: Run check-qtest and check-unit at the end of the fuzzer job
Thomas Huth [Wed, 5 Aug 2020 20:59:09 +0000 (22:59 +0200)]
gitlab-ci.yml: Run check-qtest and check-unit at the end of the fuzzer job

The fuzzer job finishes quite early, so we can run the unit tests and
qtests with -fsanitize=address here without extending the total test time.

Message-Id: <20200831153228.229185-1-thuth@redhat.com>
Reviewed-by: Alexander Bulekov <alxndr@bu.edu>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agogitlab/travis: Rework the disabled features tests
Thomas Huth [Wed, 5 Aug 2020 19:19:59 +0000 (21:19 +0200)]
gitlab/travis: Rework the disabled features tests

Let's focus on the gitlab-ci when testing the compilation with disabled
features, thus add more switches there (and while we're at it, sort them
also alphabetically). This should cover the test from the Travis CI now,
too, so that we can remove the now-redundant job from the Travis CI.

Message-Id: <20200806155306.13717-1-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agolibqtest: Rename qmp_assert_error_class() to qmp_expect_error_and_unref()
Markus Armbruster [Wed, 2 Sep 2020 11:57:33 +0000 (13:57 +0200)]
libqtest: Rename qmp_assert_error_class() to qmp_expect_error_and_unref()

qmp_assert_error_class() does more than just assert: it also unrefs
the @rsp argument.  Rename to qmp_expect_error_and_unref() to reduce
confusion.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200902115733.1229537-1-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agotests/qtest/ipmi-kcs: Fix assert side-effect
Philippe Mathieu-Daudé [Wed, 2 Sep 2020 08:07:57 +0000 (10:07 +0200)]
tests/qtest/ipmi-kcs: Fix assert side-effect

Fix assert side-effect reported by Coverity:

  /qemu/tests/qtest/ipmi-kcs-test.c: 84 in kcs_wait_obf()
  83         while (IPMI_KCS_CMDREG_GET_OBF() == 0) {
  >>>     CID 1432368:  Incorrect expression  (ASSERT_SIDE_EFFECT)
  >>>     Argument "--count" of g_assert() has a side effect.  The containing function might work differently in a non-debug build.
  84             g_assert(--count != 0);

Reported-by: Coverity (CID 1432368)
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200902080801.160652-2-philmd@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agotests/qtest/tpm: Declare input buffers const and static
Philippe Mathieu-Daudé [Wed, 2 Sep 2020 08:09:09 +0000 (10:09 +0200)]
tests/qtest/tpm: Declare input buffers const and static

The functions using these arrays expect a "const unsigned char *"
argument, it is safe to declare these as 'static const'.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200902080909.161034-1-philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agotests/qtest/ahci: Improve error handling (NEGATIVE_RETURNS)
Philippe Mathieu-Daudé [Wed, 2 Sep 2020 08:05:52 +0000 (10:05 +0200)]
tests/qtest/ahci: Improve error handling (NEGATIVE_RETURNS)

Fix an error handling issue reported by Coverity:

  /qemu/tests/qtest/ahci-test.c: 1452 in prepare_iso()
  1444         int fd = mkstemp(cdrom_path);
  >>>     CID 1432375:  Error handling issues  (NEGATIVE_RETURNS)
  >>>     "fd" is passed to a parameter that cannot be negative.
  1452         ret = write(fd, patt, size);

Reported-by: Coverity (CID 1432375)
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200902080552.159806-1-philmd@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agohw/m68k: QOMify the mcf5206 system integration module
Thomas Huth [Wed, 19 Aug 2020 06:52:01 +0000 (08:52 +0200)]
hw/m68k: QOMify the mcf5206 system integration module

The mcf5206 system integration module should be a proper device.
Let's finally QOMify it.

Signed-off-by: Thomas Huth <huth@tuxfamily.org>
Message-Id: <20200819065201.4045-1-huth@tuxfamily.org>

3 years agoconfigure: Add system = 'linux' for meson when cross-compiling
Thomas Huth [Sat, 22 Aug 2020 19:35:48 +0000 (21:35 +0200)]
configure: Add system = 'linux' for meson when cross-compiling

Meson needs the "system = xyz" line when cross-compiling. We are already
adding a "system = 'windows'" for the MinGW cross-compilation case here,
so let's add a "system = 'linux'" now for Linux hosts, too.

Message-Id: <20200823111757.72002-2-thuth@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agomeson: fix keymaps without qemu-keymap
Gerd Hoffmann [Thu, 27 Aug 2020 10:26:17 +0000 (12:26 +0200)]
meson: fix keymaps without qemu-keymap

In case the qemu-keymap tool generating them is neither installed on the
system nor built from sources (due to xkbcommon not being available)
qemu will not find the keymaps when started directly from the build
tree,

This happens because commit ddcf607fa3d6 ("meson: drop keymaps symlink")
removed the symlink to the source tree, and the special handling for
install doesn't help in case we do not install qemu.

Lets fix that by simply copying over the file from the source tree as
fallback.

Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <20200827102617.14448-1-kraxel@redhat.com>
[thuth: Rebased, changed "config_host['qemu_datadir']" to "qemu_datadir",
        added Gerd's UNLINK fix to configure script]
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agocirrus.yml: Split FreeBSD job into two parts
Thomas Huth [Mon, 24 Aug 2020 06:25:21 +0000 (08:25 +0200)]
cirrus.yml: Split FreeBSD job into two parts

The FreeBSD jobs currently hit the 1h time limit in the Cirrus-CI.
We have to split the build targets here to make sure that the job
finishes in time again. According to the Cirrus-CI docs and some
tests that I did, it also seems like the total amount of CPUs that
can be used for FreeBSD jobs is limited to 8, so each job now only
gets 4 CPUs. That increases the compilation time of each job a little
bit, but it still seems to be better to run two jobs with 4 CPUs each
in parallel than to run two jobs with 8 CPUs sequentially.

Message-Id: <20200831154405.229706-1-thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agocirrus.yml: Update the macOS jobs to Catalina
Thomas Huth [Fri, 24 Jul 2020 13:18:56 +0000 (15:18 +0200)]
cirrus.yml: Update the macOS jobs to Catalina

When looking at the CI jobs on cirrus-ci.com, it seems like the mojave-based
images have been decomissioned a while ago already, since apparently all our
jobs get automatically upgraded to catalina. So let's update our YML script
accordingly to avoid confusion.

Reviewed-by: Ed Maste <emaste@freebsd.org>
Message-Id: <20200728074405.13118-5-thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agocirrus.yml: Compile macOS with -Werror
Thomas Huth [Mon, 27 Jul 2020 15:24:26 +0000 (17:24 +0200)]
cirrus.yml: Compile macOS with -Werror

Compiler warnings currently go unnoticed in our macOS builds, since -Werror
is only enabled for Linux and MinGW builds by default. So let's enable them
here now, too.
Unfortunately, the sasl header is marked as deprecated in the macOS headers
and thus generates a lot of deprecation warnings. Thus we have to also use
-Wno-error=deprecated-declarations to be able to compile the code here.

Message-Id: <20200728074405.13118-4-thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agocirrus.yml: Compile FreeBSD with -Werror
Thomas Huth [Wed, 15 Jul 2020 17:47:07 +0000 (19:47 +0200)]
cirrus.yml: Compile FreeBSD with -Werror

Compiler warnings currently go unnoticed in our FreeBSD builds, since
-Werror is only enabled for Linux and MinGW builds by default. So let's
enable them here now, too.

Reviewed-by: Ed Maste <emaste@freebsd.org>
Message-Id: <20200728074405.13118-3-thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agoconfigure: Fix atomic64 test for --enable-werror on macOS
Thomas Huth [Thu, 16 Jul 2020 10:23:48 +0000 (12:23 +0200)]
configure: Fix atomic64 test for --enable-werror on macOS

When using --enable-werror for the macOS builders in the Cirrus-CI,
the atomic64 test is currently failing, and config.log shows a bunch
of error messages like this:

 config-temp/qemu-conf.c:6:7: error: implicit declaration of function
 '__atomic_load_8' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  y = __atomic_load_8(&x, 0);
      ^
 config-temp/qemu-conf.c:6:7: error: this function declaration is not a
 prototype [-Werror,-Wstrict-prototypes]

Seems like these __atomic_*_8 functions are available in one of the
libraries there, so that the test links and passes there when not
using --enable-werror. But there does not seem to be a valid prototype
for them in any of the header files, so that the test fails when using
--enable-werror.

Fix it by using the "official" built-in functions instead (see e.g.
https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html).
We are not using the *_8 variants in QEMU anyway.

Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20200728074405.13118-2-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
3 years agodocs/qdev-device-use: Don't suggest -drive and -net can do USB
Markus Armbruster [Thu, 6 Aug 2020 08:11:47 +0000 (10:11 +0200)]
docs/qdev-device-use: Don't suggest -drive and -net can do USB

Commit 480324ec8d "docs/qdev-device-use: Clean up the sentences
related to -usbdevice" deleted the information on syntax that no
longer works.  Unfortunately, the resulting text suggests you can
configure USB block devices with -drive, and USB network devices with
-net, which is misleading.

Instead of rephrasing the now misleading text, I'm putting the
information back, and just make clear it's about old versions of QEMU.

Cc: Thomas Huth <thuth@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200806081147.3123652-4-armbru@redhat.com>

3 years agoqapi: Document event VSERPORT_CHANGE is rate-limited
Markus Armbruster [Thu, 6 Aug 2020 08:11:46 +0000 (10:11 +0200)]
qapi: Document event VSERPORT_CHANGE is rate-limited

Commit e2ae6159de "virtio-serial: report frontend connection state via
monitor" neglected to document the new event is rate-limited.  Fix
that.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200806081147.3123652-3-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
3 years agodocs/interop/qmp-spec: Point to the QEMU QMP reference manual
Markus Armbruster [Thu, 6 Aug 2020 08:11:45 +0000 (10:11 +0200)]
docs/interop/qmp-spec: Point to the QEMU QMP reference manual

Commit 4d8bb958fa0..231aaf3a821 integrated the contents of
docs/qmp-events.txt into QAPI schema doc comments.  It left dangling
references to qmp-events.txt behind.  Fix to point to the QEMU QMP
reference manual generated from the QAPI schema.

Add a similar reference for commands.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200806081147.3123652-2-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
3 years agoscripts/qmp/qom-fuse: Fix getattr(), read() for files in /
Markus Armbruster [Thu, 23 Jul 2020 14:27:38 +0000 (16:27 +0200)]
scripts/qmp/qom-fuse: Fix getattr(), read() for files in /

path, prop = "type".rsplit('/', 1) sets path to "", which doesn't
work.  Correct to "/".

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200723142738.1868568-4-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
3 years agoscripts/qmp/qom-fuse: Port to current Python module fuse
Markus Armbruster [Thu, 23 Jul 2020 14:27:37 +0000 (16:27 +0200)]
scripts/qmp/qom-fuse: Port to current Python module fuse

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200723142738.1868568-3-armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
3 years agoscripts/qmp/qom-fuse: Unbreak import of QEMUMonitorProtocol
Markus Armbruster [Thu, 23 Jul 2020 14:27:36 +0000 (16:27 +0200)]
scripts/qmp/qom-fuse: Unbreak import of QEMUMonitorProtocol

Commit c7b942d7f8 "scripts/qmp: Fix shebang and imports" messed with
it for reasons I don't quite understand.  I do understand how it fails
now: it neglects to import sys.  Fix that.

It now fails because it expects an old version of module fuse.  That's
next.

Fixes: c7b942d7f84ef54f266921bf7668d43f1f2c7c79
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200723142738.1868568-2-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
3 years agoqapi/block-core.json: Remove stale description of 'blockdev-add'
Kashyap Chamarthy [Wed, 5 Aug 2020 10:01:58 +0000 (12:01 +0200)]
qapi/block-core.json: Remove stale description of 'blockdev-add'

On a 'qemu-discuss' thread[1], Kevin identifies that the current doc
blurb for @blockdev-add is stale:

    This is actually a documentation bug. @id doesn't exist,
    blockdev-add never creates a BlockBackend. This was different in the
    very first versions of the patches to add blockdev-add and we
    probably just forgot to update the documentation after removing it.

So remove the stale bits.

And the requirement for 'node-name' is already mentioned in the
documentation of @BlockdevOptions:

    [...]
    # @node-name: the node name of the new node (Since 2.0).
    #             This option is required on the top level of blockdev-add.
    #             Valid node names start with an alphabetic character and may
    #             contain only alphanumeric characters, '-', '.' and '_'. Their
    #             maximum length is 31 characters.
    [...]

[1] https://lists.nongnu.org/archive/html/qemu-discuss/2020-07/msg00071.html
    -- equivalent to "-drive if=ide,id=disk0....."

Fixes: be4b67bc7d ("blockdev: Allow creation of BDS trees without BB")

Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200805100158.1239390-1-kchamart@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
3 years agoqapi: enable use of g_autoptr with QAPI types
Daniel P. Berrangé [Thu, 23 Jul 2020 15:38:45 +0000 (16:38 +0100)]
qapi: enable use of g_autoptr with QAPI types

Currently QAPI generates a type and function for free'ing it:

  typedef struct QCryptoBlockCreateOptions QCryptoBlockCreateOptions;
  void qapi_free_QCryptoBlockCreateOptions(QCryptoBlockCreateOptions *obj);

This is used in the traditional manner:

  QCryptoBlockCreateOptions *opts = NULL;

  opts = g_new0(QCryptoBlockCreateOptions, 1);

  ....do stuff with opts...

  qapi_free_QCryptoBlockCreateOptions(opts);

Since bumping the min glib to 2.48, QEMU has incrementally adopted the
use of g_auto/g_autoptr. This allows the compiler to run a function to
free a variable when it goes out of scope, the benefit being the
compiler can guarantee it is freed in all possible code ptahs.

This benefit is applicable to QAPI types too, and given the seriously
long method names for some qapi_free_XXXX() functions, is much less
typing. This change thus makes the code generator emit:

 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlockCreateOptions,
                              qapi_free_QCryptoBlockCreateOptions)

The above code example now becomes

  g_autoptr(QCryptoBlockCreateOptions) opts = NULL;

  opts = g_new0(QCryptoBlockCreateOptions, 1);

  ....do stuff with opts...

Note, if the local pointer needs to live beyond the scope holding the
variable, then g_steal_pointer can be used. This is useful to return the
pointer to the caller in the success codepath, while letting it be freed
in all error codepaths.

  return g_steal_pointer(&opts);

The crypto/block.h header needs updating to avoid symbol clash now that
the g_autoptr support is a standard QAPI feature.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200723153845.2934357-1-berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
3 years agolinux-user: Add support for btrfs ioctls used to scrub a filesystem
Filip Bozuta [Sun, 23 Aug 2020 19:50:14 +0000 (21:50 +0200)]
linux-user: Add support for btrfs ioctls used to scrub a filesystem

This patch implements functionality for following ioctls:

BTRFS_IOC_SCRUB - Starting a btrfs filesystem scrub

    Start a btrfs filesystem scrub. The third ioctls argument
    is a pointer to a following type:

    struct btrfs_ioctl_scrub_args {
__u64 devid; /* in */
__u64 start; /* in */
__u64 end; /* in */
__u64 flags; /* in */
struct btrfs_scrub_progress progress; /* out */
/* pad to 1k */
__u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
    };

    Before calling this ioctl, field 'devid' should be filled
    with value that represents the device id of the btrfs filesystem
    for which the scrub is to be started.

BTRFS_IOC_SCRUB_CANCEL - Canceling scrub of a btrfs filesystem

    Cancel a btrfs filesystem scrub if it is running. The third
    ioctls argument is ignored.

BTRFS_IOC_SCRUB_PROGRESS - Getting status of a running scrub

    Read the status of a running btrfs filesystem scrub. The third
    ioctls argument is a pointer to the above mentioned
    'struct btrfs_ioctl_scrub_args'. Similarly as with 'BTRFS_IOC_SCRUB',
    the 'devid' field should be filled with value that represents the
    id of the btrfs device for which the scrub has started. The status
    of a running scrub is returned in the field 'progress' which is
    of type 'struct btrfs_scrub_progress' and its definition can be
    found at:
    https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L150

Implementation nots:

    Ioctls in this patch use type 'struct btrfs_ioctl_scrub_args' as their
    third argument. That is the reason why an aproppriate thunk type
    definition is added in file 'syscall_types.h'.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Tested-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200823195014.116226-9-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
3 years agolinux-user: Add support for btrfs ioctls used to manage quota
Filip Bozuta [Sun, 23 Aug 2020 19:50:13 +0000 (21:50 +0200)]
linux-user: Add support for btrfs ioctls used to manage quota

This patch implements functionality for following ioctls:

BTRFS_IOC_QUOTA_CTL - Enabling/Disabling quota support

    Enable or disable quota support for a btrfs filesystem. Quota
    support is enabled or disabled using the ioctls third argument
    which represents a pointer to a following type:

    struct btrfs_ioctl_quota_ctl_args {
__u64 cmd;
__u64 status;
    };

    Before calling this ioctl, the 'cmd' field should be filled
    with one of the values 'BTRFS_QUOTA_CTL_ENABLE' (enabling quota)
    'BTRFS_QUOTA_CTL_DISABLE' (disabling quota).

BTRFS_IOC_QGROUP_CREATE - Creating/Removing a subvolume quota group

    Create or remove a subvolume quota group. The subvolume quota
    group is created or removed using the ioctl's third argument which
    represents a pointer to a following type:

    struct btrfs_ioctl_qgroup_create_args {
__u64 create;
__u64 qgroupid;
    };

    Before calling this ioctl, the 'create' field should be filled
    with the aproppriate value depending on if the user wants to
    create or remove a quota group (0 for removing, everything else
    for creating). Also, the 'qgroupid' field should be filled with
    the value for the quota group id that is to be created.

BTRFS_IOC_QGROUP_ASSIGN - Asigning or removing a quota group as child group

    Asign or remove a quota group as child quota group of another
    group in the btrfs filesystem. The asignment is done using the
    ioctl's third argument which represents a pointert to a following type:

    struct btrfs_ioctl_qgroup_assign_args {
__u64 assign;
__u64 src;
__u64 dst;
    };

    Before calling this ioctl, the 'assign' field should be filled with
    the aproppriate value depending on if the user wants to asign or remove
    a quota group as a child quota group of another group (0 for removing,
    everythin else for asigning). Also, the 'src' and 'dst' fields should
    be filled with the aproppriate quota group id values depending on which
    quota group needs to asigned or removed as child quota group of another
    group ('src' gets asigned or removed as child group of 'dst').

BTRFS_IOC_QGROUP_LIMIT - Limiting the size of a quota group

    Limit the size of a quota group. The size of the quota group is limited
    with the ioctls third argument which represents a pointer to a following
    type:

    struct btrfs_ioctl_qgroup_limit_args {
__u64 qgroupid;
struct btrfs_qgroup_limit lim;
    };

    Before calling this ioctl, the 'qgroup' id field should be filled with
    aproppriate value of the quota group id for which the size is to be
    limited. The second field is of following type:

    struct btrfs_qgroup_limit {
__u64 flags;
__u64 max_rfer;
__u64 max_excl;
__u64 rsv_rfer;
__u64 rsv_excl;
    };

    The 'max_rfer' field should be filled with the size to which the quota
    group should be limited. The 'flags' field can be used for passing
    additional options and can have values which can be found on:
    https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L67

BTRFS_IOC_QUOTA_RESCAN_STATUS - Checking status of running rescan operation

    Check status of a running rescan operation. The status is checked using
    the ioctl's third argument which represents a pointer to a following type:

    struct btrfs_ioctl_quota_rescan_args {
        __u64   flags;
        __u64   progress;
        __u64   reserved[6];
    };

    If there is a rescan operation running, 'flags' field is set to 1, and
    'progress' field is set to aproppriate value which represents the progress
    of the operation.

BTRFS_IOC_QUOTA_RESCAN - Starting a rescan operation

    Start ar rescan operation to Trash all quota groups and scan the metadata
    again with the current config. Before calling this ioctl,
    BTRFS_IOC_QUOTA_RESCAN_STATUS sould be run to check if there is already a
    rescan operation runing. After that ioctl call, the received
    'struct btrfs_ioctl_quota_rescan_args' should be than passed as this ioctls
    third argument.

BTRFS_IOC_QUOTA_RESCAN_WAIT - Waiting for a rescan operation to finish

    Wait until a rescan operation is finished (if there is a rescan operation
    running). The third ioctls argument is ignored.

Implementation notes:

    Almost all of the ioctls in this patch use structure types as third arguments.
    That is the reason why aproppriate thunk definitions were added in file
    'syscall_types.h'.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Tested-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200823195014.116226-8-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>