From 8ba9c4d9b088d66aebfcb019f61ddc36fba2db88 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Mon, 14 Dec 2020 18:51:58 +0100 Subject: [PATCH 01/17] iotests/210: Fix reference output Commit 8b1170012b1 has added a global maximum disk length for the block layer, so the error message when creating an overly large disk has changed. Fixes: 8b1170012b1de6649c66ac1887f4df7e312abf3b ("block: introduce BDRV_MAX_LENGTH") Signed-off-by: Max Reitz Message-Id: <20201214175158.299919-1-mreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- tests/qemu-iotests/210.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/210.out b/tests/qemu-iotests/210.out index a5e88e2a8242..dc1a3c9786ee 100644 --- a/tests/qemu-iotests/210.out +++ b/tests/qemu-iotests/210.out @@ -182,7 +182,7 @@ Job failed: The requested file size is too large === Resize image with invalid sizes === {"execute": "block_resize", "arguments": {"node-name": "node1", "size": 9223372036854775296}} -{"error": {"class": "GenericError", "desc": "The requested file size is too large"}} +{"error": {"class": "GenericError", "desc": "Required too big image size, it must be not greater than 9223372035781033984"}} {"execute": "block_resize", "arguments": {"node-name": "node1", "size": 9223372036854775808}} {"error": {"class": "GenericError", "desc": "Invalid parameter type for 'size', expected: integer"}} {"execute": "block_resize", "arguments": {"node-name": "node1", "size": 18446744073709551104}} From 9d1cc1d0942b12587c9218661b78fdd7d5e508f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 14 Dec 2020 01:26:20 +0100 Subject: [PATCH 02/17] hw/block/nand: Decommission the NAND museum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the QEMU equivalent of this Linux commit (but 7 years later): https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f7025a43a9da2 The MTD subsystem has its own small museum of ancient NANDs in a form of the CONFIG_MTD_NAND_MUSEUM_IDS configuration option. The museum contains stone age NANDs with 256 bytes pages, as well as iron age NANDs with 512 bytes per page and up to 8MiB page size. It is with great sorrow that I inform you that the museum is being decommissioned. The MTD subsystem is out of budget for Kconfig options and already has too many of them, and there is a general kernel trend to simplify the configuration menu. We remove the stone age exhibits along with closing the museum, but some of the iron age ones are transferred to the regular NAND depot. Namely, only those which have unique device IDs are transferred, and the ones which have conflicting device IDs are removed. The machine using this device are: - axis-dev88 - tosa (via tc6393xb_init) - spitz based (akita, borzoi, terrier) Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20201214002620.342384-1-f4bug@amsat.org> Reviewed-by: Peter Maydell Signed-off-by: Kevin Wolf --- hw/block/nand.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/hw/block/nand.c b/hw/block/nand.c index 1d7a48a2ec2a..9ed54a0a9222 100644 --- a/hw/block/nand.c +++ b/hw/block/nand.c @@ -137,7 +137,7 @@ static void mem_and(uint8_t *dest, const uint8_t *src, size_t n) # define ADDR_SHIFT 16 # include "nand.c" -/* Information based on Linux drivers/mtd/nand/nand_ids.c */ +/* Information based on Linux drivers/mtd/nand/raw/nand_ids.c */ static const struct { int size; int width; @@ -147,21 +147,11 @@ static const struct { } nand_flash_ids[0x100] = { [0 ... 0xff] = { 0 }, - [0x6e] = { 1, 8, 8, 4, 0 }, - [0x64] = { 2, 8, 8, 4, 0 }, [0x6b] = { 4, 8, 9, 4, 0 }, - [0xe8] = { 1, 8, 8, 4, 0 }, - [0xec] = { 1, 8, 8, 4, 0 }, - [0xea] = { 2, 8, 8, 4, 0 }, - [0xd5] = { 4, 8, 9, 4, 0 }, [0xe3] = { 4, 8, 9, 4, 0 }, [0xe5] = { 4, 8, 9, 4, 0 }, [0xd6] = { 8, 8, 9, 4, 0 }, - - [0x39] = { 8, 8, 9, 4, 0 }, [0xe6] = { 8, 8, 9, 4, 0 }, - [0x49] = { 8, 16, 9, 4, NAND_BUSWIDTH_16 }, - [0x59] = { 8, 16, 9, 4, NAND_BUSWIDTH_16 }, [0x33] = { 16, 8, 9, 5, 0 }, [0x73] = { 16, 8, 9, 5, 0 }, From 182454dc63c66ff5a29eddd60cc987b6a1b45e7f Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Wed, 9 Dec 2020 13:17:35 +0100 Subject: [PATCH 03/17] block/nfs: fix int overflow in nfs_client_open_qdict nfs_client_open returns the file size in sectors. This effectively makes it impossible to open files larger than 1TB. Fixes: c22a03454544c2a08f1107c5cc8481a5574533d5 Cc: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Message-Id: <20201209121735.16437-1-pl@kamp.de> Reviewed-by: Stefano Garzarella Signed-off-by: Kevin Wolf --- block/nfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nfs.c b/block/nfs.c index 77905f516d20..8c1968bb415d 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -592,7 +592,7 @@ static int64_t nfs_client_open_qdict(NFSClient *client, QDict *options, int flags, int open_flags, Error **errp) { BlockdevOptionsNfs *opts; - int ret; + int64_t ret; opts = nfs_options_qdict_to_qapi(options, errp); if (opts == NULL) { From 23c02ace3508dba5f781ed9ecfde400e462f3a37 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 9 Dec 2020 10:38:00 +0000 Subject: [PATCH 04/17] docs: generate qemu-storage-daemon-qmp-ref(7) man page Although individual qemu-storage-daemon QMP commands are identical to QEMU QMP commands, qemu-storage-daemon only supports a subset of QEMU's QMP commands. Generate a manual page of just the commands supported by qemu-storage-daemon so that users know exactly what is available in qemu-storage-daemon. Add an h1 heading in storage-daemon/qapi/qapi-schema.json so that block-core.json is at the h2 heading level. Signed-off-by: Stefan Hajnoczi Message-Id: <20201209103802.350848-2-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- docs/interop/conf.py | 2 ++ docs/interop/index.rst | 1 + docs/interop/qemu-storage-daemon-qmp-ref.rst | 13 +++++++++++++ docs/meson.build | 1 + storage-daemon/qapi/qapi-schema.json | 3 +++ 5 files changed, 20 insertions(+) create mode 100644 docs/interop/qemu-storage-daemon-qmp-ref.rst diff --git a/docs/interop/conf.py b/docs/interop/conf.py index 2634ca3410a5..f4370aaa13f5 100644 --- a/docs/interop/conf.py +++ b/docs/interop/conf.py @@ -23,4 +23,6 @@ [], 7), ('qemu-qmp-ref', 'qemu-qmp-ref', 'QEMU QMP Reference Manual', [], 7), + ('qemu-storage-daemon-qmp-ref', 'qemu-storage-daemon-qmp-ref', + 'QEMU Storage Daemon QMP Reference Manual', [], 7), ] diff --git a/docs/interop/index.rst b/docs/interop/index.rst index cd78d679d824..95d56495f6f7 100644 --- a/docs/interop/index.rst +++ b/docs/interop/index.rst @@ -20,6 +20,7 @@ Contents: qemu-ga qemu-ga-ref qemu-qmp-ref + qemu-storage-daemon-qmp-ref vhost-user vhost-user-gpu vhost-vdpa diff --git a/docs/interop/qemu-storage-daemon-qmp-ref.rst b/docs/interop/qemu-storage-daemon-qmp-ref.rst new file mode 100644 index 000000000000..caf9dad23a7b --- /dev/null +++ b/docs/interop/qemu-storage-daemon-qmp-ref.rst @@ -0,0 +1,13 @@ +QEMU Storage Daemon QMP Reference Manual +======================================== + +.. + TODO: the old Texinfo manual used to note that this manual + is GPL-v2-or-later. We should make that reader-visible + both here and in our Sphinx manuals more generally. + +.. + TODO: display the QEMU version, both here and in our Sphinx manuals + more generally. + +.. qapi-doc:: storage-daemon/qapi/qapi-schema.json diff --git a/docs/meson.build b/docs/meson.build index bb8fe4c9e466..71641b4fe074 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -56,6 +56,7 @@ if build_docs 'qemu-ga.8': (have_tools ? 'man8' : ''), 'qemu-ga-ref.7': 'man7', 'qemu-qmp-ref.7': 'man7', + 'qemu-storage-daemon-qmp-ref.7': (have_tools ? 'man7' : ''), }, 'tools': { 'qemu-img.1': (have_tools ? 'man1' : ''), diff --git a/storage-daemon/qapi/qapi-schema.json b/storage-daemon/qapi/qapi-schema.json index c6ad5ae1e397..28117c3aac8a 100644 --- a/storage-daemon/qapi/qapi-schema.json +++ b/storage-daemon/qapi/qapi-schema.json @@ -15,6 +15,9 @@ { 'include': '../../qapi/pragma.json' } +## +# = Block devices +## { 'include': '../../qapi/block-core.json' } { 'include': '../../qapi/block-export.json' } { 'include': '../../qapi/char.json' } From 1982e1602d15313cd82f225e821c37733ece3404 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 9 Dec 2020 10:38:01 +0000 Subject: [PATCH 05/17] docs: add qemu-storage-daemon(1) man page Document the qemu-storage-daemon tool. Most of the command-line options are identical to their QEMU counterparts. Perhaps Sphinx hxtool integration could be extended to extract documentation for individual command-line options so they can be shared. For now the qemu-storage-daemon simply refers to the qemu(1) man page where the command-line options are identical. Signed-off-by: Stefan Hajnoczi Message-Id: <20201209103802.350848-3-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- docs/tools/conf.py | 2 + docs/tools/index.rst | 1 + docs/tools/qemu-storage-daemon.rst | 148 +++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 docs/tools/qemu-storage-daemon.rst diff --git a/docs/tools/conf.py b/docs/tools/conf.py index 4760d36ff2a6..7072d993246b 100644 --- a/docs/tools/conf.py +++ b/docs/tools/conf.py @@ -20,6 +20,8 @@ man_pages = [ ('qemu-img', 'qemu-img', u'QEMU disk image utility', ['Fabrice Bellard'], 1), + ('qemu-storage-daemon', 'qemu-storage-daemon', u'QEMU storage daemon', + [], 1), ('qemu-nbd', 'qemu-nbd', u'QEMU Disk Network Block Device Server', ['Anthony Liguori '], 8), ('qemu-pr-helper', 'qemu-pr-helper', 'QEMU persistent reservation helper', diff --git a/docs/tools/index.rst b/docs/tools/index.rst index b99f86c7c661..3a5829c17a54 100644 --- a/docs/tools/index.rst +++ b/docs/tools/index.rst @@ -11,6 +11,7 @@ Contents: :maxdepth: 2 qemu-img + qemu-storage-daemon qemu-nbd qemu-pr-helper qemu-trace-stap diff --git a/docs/tools/qemu-storage-daemon.rst b/docs/tools/qemu-storage-daemon.rst new file mode 100644 index 000000000000..f63627eaf60f --- /dev/null +++ b/docs/tools/qemu-storage-daemon.rst @@ -0,0 +1,148 @@ +QEMU Storage Daemon +=================== + +Synopsis +-------- + +**qemu-storage-daemon** [options] + +Description +----------- + +qemu-storage-daemon provides disk image functionality from QEMU, qemu-img, and +qemu-nbd in a long-running process controlled via QMP commands without running +a virtual machine. It can export disk images, run block job operations, and +perform other disk-related operations. The daemon is controlled via a QMP +monitor and initial configuration from the command-line. + +The daemon offers the following subset of QEMU features: + +* Block nodes +* Block jobs +* Block exports +* Throttle groups +* Character devices +* Crypto and secrets +* QMP +* IOThreads + +Commands can be sent over a QEMU Monitor Protocol (QMP) connection. See the +:manpage:`qemu-storage-daemon-qmp-ref(7)` manual page for a description of the +commands. + +The daemon runs until it is stopped using the ``quit`` QMP command or +SIGINT/SIGHUP/SIGTERM. + +**Warning:** Never modify images in use by a running virtual machine or any +other process; this may destroy the image. Also, be aware that querying an +image that is being modified by another process may encounter inconsistent +state. + +Options +------- + +.. program:: qemu-storage-daemon + +Standard options: + +.. option:: -h, --help + + Display help and exit + +.. option:: -V, --version + + Display version information and exit + +.. option:: -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE] + + .. include:: ../qemu-option-trace.rst.inc + +.. option:: --blockdev BLOCKDEVDEF + + is a block node definition. See the :manpage:`qemu(1)` manual page for a + description of block node properties and the :manpage:`qemu-block-drivers(7)` + manual page for a description of driver-specific parameters. + +.. option:: --chardev CHARDEVDEF + + is a character device definition. See the :manpage:`qemu(1)` manual page for + a description of character device properties. A common character device + definition configures a UNIX domain socket:: + + --chardev socket,id=char1,path=/tmp/qmp.sock,server,nowait + +.. option:: --export [type=]nbd,id=,node-name=[,name=][,writable=on|off][,bitmap=] + --export [type=]vhost-user-blk,id=,node-name=,addr.type=unix,addr.path=[,writable=on|off][,logical-block-size=][,num-queues=] + --export [type=]vhost-user-blk,id=,node-name=,addr.type=fd,addr.str=[,writable=on|off][,logical-block-size=][,num-queues=] + + is a block export definition. ``node-name`` is the block node that should be + exported. ``writable`` determines whether or not the export allows write + requests for modifying data (the default is off). + + The ``nbd`` export type requires ``--nbd-server`` (see below). ``name`` is + the NBD export name. ``bitmap`` is the name of a dirty bitmap reachable from + the block node, so the NBD client can use NBD_OPT_SET_META_CONTEXT with the + metadata context name "qemu:dirty-bitmap:BITMAP" to inspect the bitmap. + + The ``vhost-user-blk`` export type takes a vhost-user socket address on which + it accept incoming connections. Both + ``addr.type=unix,addr.path=`` for UNIX domain sockets and + ``addr.type=fd,addr.str=`` for file descriptor passing are supported. + ``logical-block-size`` sets the logical block size in bytes (the default is + 512). ``num-queues`` sets the number of virtqueues (the default is 1). + +.. option:: --monitor MONITORDEF + + is a QMP monitor definition. See the :manpage:`qemu(1)` manual page for + a description of QMP monitor properties. A common QMP monitor definition + configures a monitor on character device ``char1``:: + + --monitor chardev=char1 + +.. option:: --nbd-server addr.type=inet,addr.host=,addr.port=[,tls-creds=][,tls-authz=][,max-connections=] + --nbd-server addr.type=unix,addr.path=[,tls-creds=][,tls-authz=][,max-connections=] + + is a server for NBD exports. Both TCP and UNIX domain sockets are supported. + TLS encryption can be configured using ``--object`` tls-creds-* and authz-* + secrets (see below). + + To configure an NBD server on UNIX domain socket path ``/tmp/nbd.sock``:: + + --nbd-server addr.type=unix,addr.path=/tmp/nbd.sock + +.. option:: --object help + --object ,help + --object [,=...] + + is a QEMU user creatable object definition. List object types with ``help``. + List object properties with ``,help``. See the :manpage:`qemu(1)` + manual page for a description of the object properties. + +Examples +-------- +Launch the daemon with QMP monitor socket ``qmp.sock`` so clients can execute +QMP commands:: + + $ qemu-storage-daemon \ + --chardev socket,path=qmp.sock,server,nowait,id=char1 \ + --monitor chardev=char1 + +Export raw image file ``disk.img`` over NBD UNIX domain socket ``nbd.sock``:: + + $ qemu-storage-daemon \ + --blockdev driver=file,node-name=disk,filename=disk.img \ + --nbd-server addr.type=unix,addr.path=nbd.sock \ + --export type=nbd,id=export,node-name=disk,writable=on + +Export a qcow2 image file ``disk.qcow2`` as a vhosts-user-blk device over UNIX +domain socket ``vhost-user-blk.sock``:: + + $ qemu-storage-daemon \ + --blockdev driver=file,node-name=file,filename=disk.qcow2 \ + --blockdev driver=qcow2,node-name=qcow2,file=file \ + --export type=vhost-user-blk,id=export,addr.type=unix,addr.path=vhost-user-blk.sock,node-name=qcow2 + +See also +-------- + +:manpage:`qemu(1)`, :manpage:`qemu-block-drivers(7)`, :manpage:`qemu-storage-daemon-qmp-ref(7)` From c607c7fb88122e7dfa97159bce2237dd7987c558 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 9 Dec 2020 10:38:02 +0000 Subject: [PATCH 06/17] MAINTAINERS: add Kevin Wolf as storage daemon maintainer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MAINTAINERS file was not updated when the storage daemon was merged. Signed-off-by: Stefan Hajnoczi Acked-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20201209103802.350848-4-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 1e7c8f04885d..0e139d96128b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2165,6 +2165,15 @@ F: qobject/block-qdict.c F: tests/check-block-qdict.c T: git https://repo.or.cz/qemu/kevin.git block +Storage daemon +M: Kevin Wolf +L: qemu-block@nongnu.org +S: Supported +F: storage-daemon/ +F: docs/interop/qemu-storage-daemon-qmp-ref.rst +F: docs/tools/qemu-storage-daemon.rst +T: git https://repo.or.cz/qemu/kevin.git block + Block I/O path M: Stefan Hajnoczi M: Fam Zheng From 7ba9646c6044afc715212981b8747e0418198c1d Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Wed, 16 Dec 2020 12:52:04 +0300 Subject: [PATCH 07/17] iotests: make _filter_qom_path more strict According to original commit, that added this filter (627f607e3dddb2), the problematic thing in qom path is device[NUMBER], not the whole path. Seems that tracking the other parts of the path in iotest output is not bad. Let's make _filter_qom_path stricter. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20201216095205.526235-2-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- tests/qemu-iotests/186.out | 56 ++++++++++++++++---------------- tests/qemu-iotests/common.filter | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/qemu-iotests/186.out b/tests/qemu-iotests/186.out index 5b3504042af8..01530040e5f4 100644 --- a/tests/qemu-iotests/186.out +++ b/tests/qemu-iotests/186.out @@ -7,7 +7,7 @@ Testing: -device floppy QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block /machine/peripheral-anon/device[1]: [not inserted] - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed (qemu) quit @@ -23,7 +23,7 @@ Testing: -device ide-cd QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block /machine/peripheral-anon/device[1]: [not inserted] - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed (qemu) quit @@ -39,7 +39,7 @@ Testing: -device scsi-cd QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block /machine/peripheral-anon/device[1]: [not inserted] - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed (qemu) quit @@ -58,7 +58,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device ide-hd,d QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Cache mode: writeback (qemu) quit @@ -74,7 +74,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device scsi-hd, QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Cache mode: writeback (qemu) quit @@ -90,7 +90,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-b QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N]/virtio-backend Cache mode: writeback (qemu) quit @@ -98,7 +98,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-b QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral/qdev_id/virtio-backend Cache mode: writeback (qemu) quit @@ -106,7 +106,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device floppy,d QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -124,7 +124,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device ide-cd,d QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -142,7 +142,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device scsi-cd, QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block null: json:{"read-zeroes": true, "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -191,7 +191,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) Cache mode: writeback null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral/qdev_id/virtio-backend Cache mode: writeback (qemu) quit @@ -241,7 +241,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device ide QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Cache mode: writeback (qemu) quit @@ -257,7 +257,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device scs QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Cache mode: writeback (qemu) quit @@ -273,7 +273,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device vir QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N]/virtio-backend Cache mode: writeback (qemu) quit @@ -281,7 +281,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device vir QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral/qdev_id/virtio-backend Cache mode: writeback (qemu) quit @@ -289,7 +289,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device flo QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -307,7 +307,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device ide QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -325,7 +325,7 @@ Testing: -drive if=none,driver=null-co,read-zeroes=on,node-name=null -device scs QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -353,7 +353,7 @@ Testing: -drive if=none -device floppy,drive=none0 QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0: [not inserted] - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed (qemu) quit @@ -369,7 +369,7 @@ Testing: -drive if=none -device ide-cd,drive=none0 QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0: [not inserted] - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed (qemu) quit @@ -385,7 +385,7 @@ Testing: -drive if=none -device scsi-cd,drive=none0 QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block none0: [not inserted] - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed (qemu) quit @@ -404,7 +404,7 @@ Testing: -drive if=floppy QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block floppy0: [not inserted] - Attached to: PATH + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed (qemu) quit @@ -412,7 +412,7 @@ Testing: -drive if=floppy,driver=null-co,read-zeroes=on QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block floppy0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -421,7 +421,7 @@ Testing: -drive if=ide,driver=null-co,read-zeroes=on QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block ide0-hd0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/unattached/device[N] Cache mode: writeback (qemu) quit @@ -429,7 +429,7 @@ Testing: -drive if=ide,media=cdrom QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block ide0-cd0: [not inserted] - Attached to: PATH + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed (qemu) quit @@ -437,7 +437,7 @@ Testing: -drive if=ide,driver=null-co,read-zeroes=on,media=cdrom QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block ide0-cd0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co, read-only) - Attached to: PATH + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback (qemu) quit @@ -446,7 +446,7 @@ Testing: -drive if=virtio,driver=null-co,read-zeroes=on QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block virtio0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: PATH + Attached to: /machine/peripheral-anon/device[N]/virtio-backend Cache mode: writeback (qemu) quit @@ -454,7 +454,7 @@ Testing: -drive if=pflash,driver=null-co,read-zeroes=on,size=1M QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block pflash0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co", "size": "1M"} (null-co) - Attached to: PATH + Attached to: /machine/system.flash0 Cache mode: writeback (qemu) quit diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter index 172ea5752ecf..268b749e2fa8 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -37,7 +37,7 @@ _filter_generated_node_ids() _filter_qom_path() { - $SED -e 's#\(Attached to: *\) /.*#\1 PATH#' + $SED -e '/Attached to:/s/\device[[0-9]\+\]/device[N]/g' } # replace occurrences of the actual TEST_DIR value with TEST_DIR From 1a35110150e38beea15865f886022fe329028e12 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Wed, 16 Dec 2020 12:52:05 +0300 Subject: [PATCH 08/17] iotests:172: use _filter_qom_path device[NUMBER] thing in QOM path is not stable and tracking it during code modifications is not fun. Let's filter it like it's already done in iotest 186. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20201216095205.526235-3-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- tests/qemu-iotests/172 | 2 +- tests/qemu-iotests/172.out | 152 ++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/tests/qemu-iotests/172 b/tests/qemu-iotests/172 index 3abfa72948f6..b45782e8db6d 100755 --- a/tests/qemu-iotests/172 +++ b/tests/qemu-iotests/172 @@ -73,7 +73,7 @@ check_floppy_qtree() (QEMU_OPTIONS="" do_run_qemu "$@" | _filter_testdir |_filter_generated_node_ids | _filter_hmp | sed -ne '/^ dev: isa-fdc/,/^ dev:/{x;p};/^[a-z][^ ]* (NODE_NAME):* /,/^(qemu)$/{p}') 2>&1 | - _filter_win32 | _filter_qemu + _filter_win32 | _filter_qemu | _filter_qom_path } check_cache_mode() diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out index cca2894af092..2cd4a8fd83ca 100644 --- a/tests/qemu-iotests/172.out +++ b/tests/qemu-iotests/172.out @@ -63,12 +63,12 @@ Testing: -fda TEST_DIR/t.qcow2 share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -114,16 +114,16 @@ Testing: -fdb TEST_DIR/t.qcow2 share-rw = false drive-type = "288" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed floppy0: [not inserted] - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -169,17 +169,17 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback floppy1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -255,12 +255,12 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -306,16 +306,16 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 share-rw = false drive-type = "288" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed floppy0: [not inserted] - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -361,17 +361,17 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback floppy1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -411,12 +411,12 @@ Use -device floppy,unit=0,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -453,12 +453,12 @@ Use -device floppy,unit=1,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -508,17 +508,17 @@ Use -device floppy,unit=1,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -556,12 +556,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -596,12 +596,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1 share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -647,17 +647,17 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[1] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -708,17 +708,17 @@ Use -device floppy,unit=1,drive=... instead. share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -766,17 +766,17 @@ Use -device floppy,unit=0,drive=... instead. share-rw = false drive-type = "144" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[16] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[23] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -838,17 +838,17 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -894,17 +894,17 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -950,17 +950,17 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl share-rw = false drive-type = "144" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1006,17 +1006,17 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl share-rw = false drive-type = "144" floppy1 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1071,17 +1071,17 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1127,17 +1127,17 @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q share-rw = false drive-type = "144" floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1191,17 +1191,17 @@ Use -device floppy,unit=0,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1249,17 +1249,17 @@ Use -device floppy,unit=0,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1307,17 +1307,17 @@ Use -device floppy,unit=1,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1365,17 +1365,17 @@ Use -device floppy,unit=1,drive=... instead. share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/unattached/device[15] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed Cache mode: writeback none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[22] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1410,12 +1410,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1603,12 +1603,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t share-rw = false drive-type = "120" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1643,12 +1643,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t share-rw = false drive-type = "288" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1686,12 +1686,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] @@ -1726,12 +1726,12 @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica share-rw = false drive-type = "144" none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) - Attached to: /machine/peripheral-anon/device[0] + Attached to: /machine/peripheral-anon/device[N] Removable device: not locked, tray closed Cache mode: writeback ide1-cd0: [not inserted] - Attached to: /machine/unattached/device[21] + Attached to: /machine/unattached/device[N] Removable device: not locked, tray closed sd0: [not inserted] From 02df95c4a1746aac168dc70a6d8aec062e3f6250 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:19:55 +0100 Subject: [PATCH 09/17] block/vpc: Make vpc_open() read the full dynamic header The dynamic header's size is 1024 bytes. vpc_open() reads only the 512 bytes of the dynamic header into buf[]. Works, because it doesn't actually access the second half. However, a colleague told me that GCC 11 warns: ../block/vpc.c:358:51: error: array subscript 'struct VHDDynDiskHeader[0]' is partly outside array bounds of 'uint8_t[512]' [-Werror=array-bounds] Clean up to read the full header. Rename buf[] to dyndisk_header_buf[] while there. Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-2-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 1ab55f92877f..2fcf3f6283f9 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -220,7 +220,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, QemuOpts *opts = NULL; Error *local_err = NULL; bool use_chs; - uint8_t buf[HEADER_SIZE]; + uint8_t dyndisk_header_buf[1024]; uint32_t checksum; uint64_t computed_size; uint64_t pagetable_size; @@ -340,14 +340,14 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } if (disk_type == VHD_DYNAMIC) { - ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), buf, - HEADER_SIZE); + ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), + dyndisk_header_buf, 1024); if (ret < 0) { error_setg(errp, "Error reading dynamic VHD header"); goto fail; } - dyndisk_header = (VHDDynDiskHeader *) buf; + dyndisk_header = (VHDDynDiskHeader *)dyndisk_header_buf; if (strncmp(dyndisk_header->magic, "cxsparse", 8)) { error_setg(errp, "Invalid header magic"); From b0ce8cb0e8470b37963d1db7e4baca9c3647b0a1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:19:56 +0100 Subject: [PATCH 10/17] block/vpc: Don't abuse the footer buffer as BAT sector buffer create_dynamic_disk() takes a buffer holding the footer as first argument. It writes out the footer (512 bytes), then reuses the buffer to initialize and write out the dynamic header (1024 bytes), then reuses it again to initialize and write out BAT sectors (512). Works, because the caller passes a buffer that is large enough for all three purposes. I hate that. Use a separate buffer for writing out BAT sectors. The next commit will do the same for the dynamic header. Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-3-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 2fcf3f6283f9..d18ecc3da11d 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -824,6 +824,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, { VHDDynDiskHeader *dyndisk_header = (VHDDynDiskHeader *) buf; + uint8_t bat_sector[512]; size_t block_size, num_bat_entries; int i; int ret; @@ -847,9 +848,9 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, /* Write the initial BAT */ offset = 3 * 512; - memset(buf, 0xFF, 512); + memset(bat_sector, 0xFF, 512); for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) { - ret = blk_pwrite(blk, offset, buf, 512, 0); + ret = blk_pwrite(blk, offset, bat_sector, 512, 0); if (ret < 0) { goto fail; } From a18dc3a14d8455c0b7673f9c3b6cdc4f10a7dade Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:19:57 +0100 Subject: [PATCH 11/17] block/vpc: Don't abuse the footer buffer for dynamic header create_dynamic_disk() takes a buffer holding the footer as first argument. It writes out the footer (512 bytes), then reuses the buffer to initialize and write out the dynamic header (1024 bytes). Works, because the caller passes a buffer that is large enough for both purposes. I hate that. Use a separate buffer for the dynamic header, and adjust the caller's buffer. Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-4-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index d18ecc3da11d..34186640ee9f 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -822,8 +822,9 @@ static int calculate_geometry(int64_t total_sectors, uint16_t *cyls, static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, int64_t total_sectors) { + uint8_t dyndisk_header_buf[1024]; VHDDynDiskHeader *dyndisk_header = - (VHDDynDiskHeader *) buf; + (VHDDynDiskHeader *)dyndisk_header_buf; uint8_t bat_sector[512]; size_t block_size, num_bat_entries; int i; @@ -858,7 +859,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, } /* Prepare the Dynamic Disk Header */ - memset(buf, 0, 1024); + memset(dyndisk_header_buf, 0, 1024); memcpy(dyndisk_header->magic, "cxsparse", 8); @@ -872,12 +873,13 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, dyndisk_header->block_size = cpu_to_be32(block_size); dyndisk_header->max_table_entries = cpu_to_be32(num_bat_entries); - dyndisk_header->checksum = cpu_to_be32(vpc_checksum(buf, 1024)); + dyndisk_header->checksum = cpu_to_be32(vpc_checksum(dyndisk_header_buf, + 1024)); /* Write the header */ offset = 512; - ret = blk_pwrite(blk, offset, buf, 1024, 0); + ret = blk_pwrite(blk, offset, dyndisk_header_buf, 1024, 0); if (ret < 0) { goto fail; } @@ -972,8 +974,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, BlockBackend *blk = NULL; BlockDriverState *bs = NULL; - uint8_t buf[1024]; - VHDFooter *footer = (VHDFooter *) buf; + uint8_t footer_buf[HEADER_SIZE]; + VHDFooter *footer = (VHDFooter *)footer_buf; uint16_t cyls = 0; uint8_t heads = 0; uint8_t secs_per_cyl = 0; @@ -1036,7 +1038,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, } /* Prepare the Hard Disk Footer */ - memset(buf, 0, 1024); + memset(footer_buf, 0, HEADER_SIZE); memcpy(footer->creator, "conectix", 8); if (vpc_opts->force_size) { @@ -1069,15 +1071,15 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, qemu_uuid_generate(&uuid); footer->uuid = uuid; - footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE)); + footer->checksum = cpu_to_be32(vpc_checksum(footer_buf, HEADER_SIZE)); if (disk_type == VHD_DYNAMIC) { - ret = create_dynamic_disk(blk, buf, total_sectors); + ret = create_dynamic_disk(blk, footer_buf, total_sectors); if (ret < 0) { error_setg(errp, "Unable to create or write VHD header"); } } else { - ret = create_fixed_disk(blk, buf, total_size, errp); + ret = create_fixed_disk(blk, footer_buf, total_size, errp); } out: From 7550379dedc4e0791ffadc3b18ac202fce51e21c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:19:58 +0100 Subject: [PATCH 12/17] block/vpc: Make vpc_checksum() take void * Some of the next commits will checksum structs. Change vpc_checksum() to take void * instead of uint8_t, to save us pointless casts to uint8_t *. Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-5-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/vpc.c b/block/vpc.c index 34186640ee9f..5af983780605 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -172,8 +172,9 @@ static QemuOptsList vpc_runtime_opts = { static QemuOptsList vpc_create_opts; -static uint32_t vpc_checksum(uint8_t *buf, size_t size) +static uint32_t vpc_checksum(void *p, size_t size) { + uint8_t *buf = p; uint32_t res = 0; int i; From e326f0783ed06ed7360f63c7223424cc1d910406 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:19:59 +0100 Subject: [PATCH 13/17] block/vpc: Pad VHDDynDiskHeader, replace uint8_t[] buffers Pad VHDDynDiskHeader as specified in the "Virtual Hard Disk Image Format Specification" version 1.0[*]. Change dynamic disk header buffers from uint8_t[1024] to VHDDynDiskHeader. Their size remains the same. The VHDDynDiskHeader * variables pointing to a VHDDynDiskHeader variable right next to it are now silly. Eliminate them. [*] http://download.microsoft.com/download/f/f/e/ffef50a5-07dd-4cf8-aaa3-442c0673a029/Virtual%20Hard%20Disk%20Format%20Spec_10_18_06.doc Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-6-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 5af983780605..08a0f710ad4d 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -127,8 +127,11 @@ typedef struct vhd_dyndisk_header { uint32_t reserved; uint64_t data_offset; } parent_locator[8]; + uint8_t reserved2[256]; } QEMU_PACKED VHDDynDiskHeader; +QEMU_BUILD_BUG_ON(sizeof(VHDDynDiskHeader) != 1024); + typedef struct BDRVVPCState { CoMutex lock; uint8_t footer_buf[HEADER_SIZE]; @@ -217,11 +220,10 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, BDRVVPCState *s = bs->opaque; int i; VHDFooter *footer; - VHDDynDiskHeader *dyndisk_header; QemuOpts *opts = NULL; Error *local_err = NULL; bool use_chs; - uint8_t dyndisk_header_buf[1024]; + VHDDynDiskHeader dyndisk_header; uint32_t checksum; uint64_t computed_size; uint64_t pagetable_size; @@ -342,21 +344,19 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, if (disk_type == VHD_DYNAMIC) { ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), - dyndisk_header_buf, 1024); + &dyndisk_header, 1024); if (ret < 0) { error_setg(errp, "Error reading dynamic VHD header"); goto fail; } - dyndisk_header = (VHDDynDiskHeader *)dyndisk_header_buf; - - if (strncmp(dyndisk_header->magic, "cxsparse", 8)) { + if (strncmp(dyndisk_header.magic, "cxsparse", 8)) { error_setg(errp, "Invalid header magic"); ret = -EINVAL; goto fail; } - s->block_size = be32_to_cpu(dyndisk_header->block_size); + s->block_size = be32_to_cpu(dyndisk_header.block_size); if (!is_power_of_2(s->block_size) || s->block_size < BDRV_SECTOR_SIZE) { error_setg(errp, "Invalid block size %" PRIu32, s->block_size); ret = -EINVAL; @@ -364,7 +364,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } s->bitmap_size = ((s->block_size / (8 * 512)) + 511) & ~511; - s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries); + s->max_table_entries = be32_to_cpu(dyndisk_header.max_table_entries); if ((bs->total_sectors * 512) / s->block_size > 0xffffffffU) { error_setg(errp, "Too many blocks"); @@ -396,7 +396,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - s->bat_offset = be64_to_cpu(dyndisk_header->table_offset); + s->bat_offset = be64_to_cpu(dyndisk_header.table_offset); ret = bdrv_pread(bs->file, s->bat_offset, s->pagetable, pagetable_size); @@ -823,9 +823,7 @@ static int calculate_geometry(int64_t total_sectors, uint16_t *cyls, static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, int64_t total_sectors) { - uint8_t dyndisk_header_buf[1024]; - VHDDynDiskHeader *dyndisk_header = - (VHDDynDiskHeader *)dyndisk_header_buf; + VHDDynDiskHeader dyndisk_header; uint8_t bat_sector[512]; size_t block_size, num_bat_entries; int i; @@ -860,27 +858,26 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, } /* Prepare the Dynamic Disk Header */ - memset(dyndisk_header_buf, 0, 1024); + memset(&dyndisk_header, 0, 1024); - memcpy(dyndisk_header->magic, "cxsparse", 8); + memcpy(dyndisk_header.magic, "cxsparse", 8); /* * Note: The spec is actually wrong here for data_offset, it says * 0xFFFFFFFF, but MS tools expect all 64 bits to be set. */ - dyndisk_header->data_offset = cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); - dyndisk_header->table_offset = cpu_to_be64(3 * 512); - dyndisk_header->version = cpu_to_be32(0x00010000); - dyndisk_header->block_size = cpu_to_be32(block_size); - dyndisk_header->max_table_entries = cpu_to_be32(num_bat_entries); + dyndisk_header.data_offset = cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); + dyndisk_header.table_offset = cpu_to_be64(3 * 512); + dyndisk_header.version = cpu_to_be32(0x00010000); + dyndisk_header.block_size = cpu_to_be32(block_size); + dyndisk_header.max_table_entries = cpu_to_be32(num_bat_entries); - dyndisk_header->checksum = cpu_to_be32(vpc_checksum(dyndisk_header_buf, - 1024)); + dyndisk_header.checksum = cpu_to_be32(vpc_checksum(&dyndisk_header, 1024)); /* Write the header */ offset = 512; - ret = blk_pwrite(blk, offset, dyndisk_header_buf, 1024, 0); + ret = blk_pwrite(blk, offset, &dyndisk_header, 1024, 0); if (ret < 0) { goto fail; } From 3d6101a3f2c88176b3abfe60b0759a75243d0592 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:20:00 +0100 Subject: [PATCH 14/17] block/vpc: Use sizeof() instead of 1024 for dynamic header size Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-7-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 08a0f710ad4d..6cb656ac82c5 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -344,7 +344,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, if (disk_type == VHD_DYNAMIC) { ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), - &dyndisk_header, 1024); + &dyndisk_header, sizeof(dyndisk_header)); if (ret < 0) { error_setg(errp, "Error reading dynamic VHD header"); goto fail; @@ -858,7 +858,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, } /* Prepare the Dynamic Disk Header */ - memset(&dyndisk_header, 0, 1024); + memset(&dyndisk_header, 0, sizeof(dyndisk_header)); memcpy(dyndisk_header.magic, "cxsparse", 8); @@ -872,12 +872,13 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, dyndisk_header.block_size = cpu_to_be32(block_size); dyndisk_header.max_table_entries = cpu_to_be32(num_bat_entries); - dyndisk_header.checksum = cpu_to_be32(vpc_checksum(&dyndisk_header, 1024)); + dyndisk_header.checksum = cpu_to_be32( + vpc_checksum(&dyndisk_header, sizeof(dyndisk_header))); /* Write the header */ offset = 512; - ret = blk_pwrite(blk, offset, &dyndisk_header, 1024, 0); + ret = blk_pwrite(blk, offset, &dyndisk_header, sizeof(dyndisk_header), 0); if (ret < 0) { goto fail; } From 275734e4794bb7a3d73f7517fbd769727f2479af Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:20:01 +0100 Subject: [PATCH 15/17] block/vpc: Pad VHDFooter, replace uint8_t[] buffers Pad VHDFooter as specified in the "Virtual Hard Disk Image Format Specification" version 1.0[*]. Change footer buffers from uint8_t[HEADER_SIZE] to VHDFooter. Their size remains the same. The VHDFooter * variables pointing to a VHDFooter variable right next to it are now silly. Eliminate them, and shorten the remaining variables' names. Most variables pointing to s->footer are now also silly. Eliminate them, too. [*] http://download.microsoft.com/download/f/f/e/ffef50a5-07dd-4cf8-aaa3-442c0673a029/Virtual%20Hard%20Disk%20Format%20Spec_10_18_06.doc Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-8-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 77 +++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 6cb656ac82c5..f3ea92dcb0b6 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -95,8 +95,11 @@ typedef struct vhd_footer { QemuUUID uuid; uint8_t in_saved_state; + uint8_t reserved[427]; } QEMU_PACKED VHDFooter; +QEMU_BUILD_BUG_ON(sizeof(VHDFooter) != 512); + typedef struct vhd_dyndisk_header { char magic[8]; /* "cxsparse" */ @@ -134,7 +137,7 @@ QEMU_BUILD_BUG_ON(sizeof(VHDDynDiskHeader) != 1024); typedef struct BDRVVPCState { CoMutex lock; - uint8_t footer_buf[HEADER_SIZE]; + VHDFooter footer; uint64_t free_data_block_offset; int max_table_entries; uint32_t *pagetable; @@ -250,13 +253,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - ret = bdrv_pread(bs->file, 0, s->footer_buf, HEADER_SIZE); + ret = bdrv_pread(bs->file, 0, &s->footer, HEADER_SIZE); if (ret < 0) { error_setg(errp, "Unable to read VHD header"); goto fail; } - footer = (VHDFooter *) s->footer_buf; + footer = &s->footer; if (strncmp(footer->creator, "conectix", 8)) { int64_t offset = bdrv_getlength(bs->file->bs); if (offset < 0) { @@ -270,7 +273,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } /* If a fixed disk, the footer is found only at the end of the file */ - ret = bdrv_pread(bs->file, offset-HEADER_SIZE, s->footer_buf, + ret = bdrv_pread(bs->file, offset - HEADER_SIZE, footer, HEADER_SIZE); if (ret < 0) { goto fail; @@ -285,7 +288,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, checksum = be32_to_cpu(footer->checksum); footer->checksum = 0; - if (vpc_checksum(s->footer_buf, HEADER_SIZE) != checksum) { + if (vpc_checksum(footer, HEADER_SIZE) != checksum) { error_setg(errp, "Incorrect header checksum"); ret = -EINVAL; goto fail; @@ -535,7 +538,7 @@ static int rewrite_footer(BlockDriverState *bs) BDRVVPCState *s = bs->opaque; int64_t offset = s->free_data_block_offset; - ret = bdrv_pwrite_sync(bs->file, offset, s->footer_buf, HEADER_SIZE); + ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, HEADER_SIZE); if (ret < 0) return ret; @@ -598,9 +601,8 @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset) static int vpc_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVVPCState *s = (BDRVVPCState *)bs->opaque; - VHDFooter *footer = (VHDFooter *) s->footer_buf; - if (be32_to_cpu(footer->type) != VHD_FIXED) { + if (be32_to_cpu(s->footer.type) != VHD_FIXED) { bdi->cluster_size = s->block_size; } @@ -616,10 +618,9 @@ vpc_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, int64_t image_offset; int64_t n_bytes; int64_t bytes_done = 0; - VHDFooter *footer = (VHDFooter *) s->footer_buf; QEMUIOVector local_qiov; - if (be32_to_cpu(footer->type) == VHD_FIXED) { + if (be32_to_cpu(s->footer.type) == VHD_FIXED) { return bdrv_co_preadv(bs->file, offset, bytes, qiov, 0); } @@ -667,10 +668,9 @@ vpc_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, int64_t n_bytes; int64_t bytes_done = 0; int ret = 0; - VHDFooter *footer = (VHDFooter *) s->footer_buf; QEMUIOVector local_qiov; - if (be32_to_cpu(footer->type) == VHD_FIXED) { + if (be32_to_cpu(s->footer.type) == VHD_FIXED) { return bdrv_co_pwritev(bs->file, offset, bytes, qiov, 0); } @@ -724,13 +724,12 @@ static int coroutine_fn vpc_co_block_status(BlockDriverState *bs, BlockDriverState **file) { BDRVVPCState *s = bs->opaque; - VHDFooter *footer = (VHDFooter*) s->footer_buf; int64_t image_offset; bool allocated; int ret; int64_t n; - if (be32_to_cpu(footer->type) == VHD_FIXED) { + if (be32_to_cpu(s->footer.type) == VHD_FIXED) { *pnum = bytes; *map = offset; *file = bs->file->bs; @@ -973,8 +972,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, BlockBackend *blk = NULL; BlockDriverState *bs = NULL; - uint8_t footer_buf[HEADER_SIZE]; - VHDFooter *footer = (VHDFooter *)footer_buf; + VHDFooter footer; uint16_t cyls = 0; uint8_t heads = 0; uint8_t secs_per_cyl = 0; @@ -1037,48 +1035,48 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, } /* Prepare the Hard Disk Footer */ - memset(footer_buf, 0, HEADER_SIZE); + memset(&footer, 0, HEADER_SIZE); - memcpy(footer->creator, "conectix", 8); + memcpy(footer.creator, "conectix", 8); if (vpc_opts->force_size) { - memcpy(footer->creator_app, "qem2", 4); + memcpy(footer.creator_app, "qem2", 4); } else { - memcpy(footer->creator_app, "qemu", 4); + memcpy(footer.creator_app, "qemu", 4); } - memcpy(footer->creator_os, "Wi2k", 4); + memcpy(footer.creator_os, "Wi2k", 4); - footer->features = cpu_to_be32(0x02); - footer->version = cpu_to_be32(0x00010000); + footer.features = cpu_to_be32(0x02); + footer.version = cpu_to_be32(0x00010000); if (disk_type == VHD_DYNAMIC) { - footer->data_offset = cpu_to_be64(HEADER_SIZE); + footer.data_offset = cpu_to_be64(HEADER_SIZE); } else { - footer->data_offset = cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); + footer.data_offset = cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); } - footer->timestamp = cpu_to_be32(time(NULL) - VHD_TIMESTAMP_BASE); + footer.timestamp = cpu_to_be32(time(NULL) - VHD_TIMESTAMP_BASE); /* Version of Virtual PC 2007 */ - footer->major = cpu_to_be16(0x0005); - footer->minor = cpu_to_be16(0x0003); - footer->orig_size = cpu_to_be64(total_size); - footer->current_size = cpu_to_be64(total_size); - footer->cyls = cpu_to_be16(cyls); - footer->heads = heads; - footer->secs_per_cyl = secs_per_cyl; + footer.major = cpu_to_be16(0x0005); + footer.minor = cpu_to_be16(0x0003); + footer.orig_size = cpu_to_be64(total_size); + footer.current_size = cpu_to_be64(total_size); + footer.cyls = cpu_to_be16(cyls); + footer.heads = heads; + footer.secs_per_cyl = secs_per_cyl; - footer->type = cpu_to_be32(disk_type); + footer.type = cpu_to_be32(disk_type); qemu_uuid_generate(&uuid); - footer->uuid = uuid; + footer.uuid = uuid; - footer->checksum = cpu_to_be32(vpc_checksum(footer_buf, HEADER_SIZE)); + footer.checksum = cpu_to_be32(vpc_checksum(&footer, HEADER_SIZE)); if (disk_type == VHD_DYNAMIC) { - ret = create_dynamic_disk(blk, footer_buf, total_sectors); + ret = create_dynamic_disk(blk, (uint8_t *)&footer, total_sectors); if (ret < 0) { error_setg(errp, "Unable to create or write VHD header"); } } else { - ret = create_fixed_disk(blk, footer_buf, total_size, errp); + ret = create_fixed_disk(blk, (uint8_t *)&footer, total_size, errp); } out: @@ -1172,9 +1170,8 @@ static int coroutine_fn vpc_co_create_opts(BlockDriver *drv, static int vpc_has_zero_init(BlockDriverState *bs) { BDRVVPCState *s = bs->opaque; - VHDFooter *footer = (VHDFooter *) s->footer_buf; - if (be32_to_cpu(footer->type) == VHD_FIXED) { + if (be32_to_cpu(s->footer.type) == VHD_FIXED) { return bdrv_has_zero_init(bs->file->bs); } else { return 1; From a3d2761719c0ff35419ad030ef6a8da2101c424f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:20:02 +0100 Subject: [PATCH 16/17] block/vpc: Pass footer buffers as VHDFooter * instead of uint8_t * Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-9-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index f3ea92dcb0b6..aac13788df52 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -819,7 +819,7 @@ static int calculate_geometry(int64_t total_sectors, uint16_t *cyls, return 0; } -static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, +static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer, int64_t total_sectors) { VHDDynDiskHeader dyndisk_header; @@ -833,13 +833,13 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, block_size = 0x200000; num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512); - ret = blk_pwrite(blk, offset, buf, HEADER_SIZE, 0); + ret = blk_pwrite(blk, offset, footer, HEADER_SIZE, 0); if (ret < 0) { goto fail; } offset = 1536 + ((num_bat_entries * 4 + 511) & ~511); - ret = blk_pwrite(blk, offset, buf, HEADER_SIZE, 0); + ret = blk_pwrite(blk, offset, footer, HEADER_SIZE, 0); if (ret < 0) { goto fail; } @@ -887,7 +887,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, return ret; } -static int create_fixed_disk(BlockBackend *blk, uint8_t *buf, +static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer, int64_t total_size, Error **errp) { int ret; @@ -900,7 +900,7 @@ static int create_fixed_disk(BlockBackend *blk, uint8_t *buf, return ret; } - ret = blk_pwrite(blk, total_size - HEADER_SIZE, buf, HEADER_SIZE, 0); + ret = blk_pwrite(blk, total_size - HEADER_SIZE, footer, HEADER_SIZE, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Unable to write VHD header"); return ret; @@ -1071,12 +1071,12 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, footer.checksum = cpu_to_be32(vpc_checksum(&footer, HEADER_SIZE)); if (disk_type == VHD_DYNAMIC) { - ret = create_dynamic_disk(blk, (uint8_t *)&footer, total_sectors); + ret = create_dynamic_disk(blk, &footer, total_sectors); if (ret < 0) { error_setg(errp, "Unable to create or write VHD header"); } } else { - ret = create_fixed_disk(blk, (uint8_t *)&footer, total_size, errp); + ret = create_fixed_disk(blk, &footer, total_size, errp); } out: From be7c5ddd0d80e2d6cf8e3ef12c049851d28d9c26 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 17 Dec 2020 17:20:03 +0100 Subject: [PATCH 17/17] block/vpc: Use sizeof() instead of HEADER_SIZE for footer size Signed-off-by: Markus Armbruster Message-Id: <20201217162003.1102738-10-armbru@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vpc.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index aac13788df52..17a705b482af 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -39,8 +39,6 @@ /**************************************************************/ -#define HEADER_SIZE 512 - //#define CACHE enum vhd_type { @@ -253,7 +251,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - ret = bdrv_pread(bs->file, 0, &s->footer, HEADER_SIZE); + ret = bdrv_pread(bs->file, 0, &s->footer, sizeof(s->footer)); if (ret < 0) { error_setg(errp, "Unable to read VHD header"); goto fail; @@ -266,15 +264,15 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, ret = offset; error_setg(errp, "Invalid file size"); goto fail; - } else if (offset < HEADER_SIZE) { + } else if (offset < sizeof(*footer)) { ret = -EINVAL; error_setg(errp, "File too small for a VHD header"); goto fail; } /* If a fixed disk, the footer is found only at the end of the file */ - ret = bdrv_pread(bs->file, offset - HEADER_SIZE, footer, - HEADER_SIZE); + ret = bdrv_pread(bs->file, offset - sizeof(*footer), + footer, sizeof(*footer)); if (ret < 0) { goto fail; } @@ -288,7 +286,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, checksum = be32_to_cpu(footer->checksum); footer->checksum = 0; - if (vpc_checksum(footer, HEADER_SIZE) != checksum) { + if (vpc_checksum(footer, sizeof(*footer)) != checksum) { error_setg(errp, "Incorrect header checksum"); ret = -EINVAL; goto fail; @@ -538,7 +536,7 @@ static int rewrite_footer(BlockDriverState *bs) BDRVVPCState *s = bs->opaque; int64_t offset = s->free_data_block_offset; - ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, HEADER_SIZE); + ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, sizeof(s->footer)); if (ret < 0) return ret; @@ -833,13 +831,13 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer, block_size = 0x200000; num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512); - ret = blk_pwrite(blk, offset, footer, HEADER_SIZE, 0); + ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0); if (ret < 0) { goto fail; } offset = 1536 + ((num_bat_entries * 4 + 511) & ~511); - ret = blk_pwrite(blk, offset, footer, HEADER_SIZE, 0); + ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0); if (ret < 0) { goto fail; } @@ -893,14 +891,15 @@ static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer, int ret; /* Add footer to total size */ - total_size += HEADER_SIZE; + total_size += sizeof(*footer); ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, errp); if (ret < 0) { return ret; } - ret = blk_pwrite(blk, total_size - HEADER_SIZE, footer, HEADER_SIZE, 0); + ret = blk_pwrite(blk, total_size - sizeof(*footer), + footer, sizeof(*footer), 0); if (ret < 0) { error_setg_errno(errp, -ret, "Unable to write VHD header"); return ret; @@ -1035,7 +1034,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, } /* Prepare the Hard Disk Footer */ - memset(&footer, 0, HEADER_SIZE); + memset(&footer, 0, sizeof(footer)); memcpy(footer.creator, "conectix", 8); if (vpc_opts->force_size) { @@ -1048,7 +1047,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, footer.features = cpu_to_be32(0x02); footer.version = cpu_to_be32(0x00010000); if (disk_type == VHD_DYNAMIC) { - footer.data_offset = cpu_to_be64(HEADER_SIZE); + footer.data_offset = cpu_to_be64(sizeof(footer)); } else { footer.data_offset = cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); } @@ -1068,7 +1067,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, qemu_uuid_generate(&uuid); footer.uuid = uuid; - footer.checksum = cpu_to_be32(vpc_checksum(&footer, HEADER_SIZE)); + footer.checksum = cpu_to_be32(vpc_checksum(&footer, sizeof(footer))); if (disk_type == VHD_DYNAMIC) { ret = create_dynamic_disk(blk, &footer, total_sectors);