Block patches
v2:
* Dropped Fam's dataplane virtio header patches that break win32 build [Peter]
The following changes since commit f102f224556f292f55b6e25147741bb8c48c9451:
Merge remote-tracking branch 'remotes/afaerber/tags/qom-cpu-for-peter' into staging (2014-09-05 16:03:56 +0100)
are available in the git repository at:
git://github.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 01ce352e62c3f86df6f4ad32c3ab9353e55af799:
ide: Add resize callback to ide/core (2014-09-08 11:12:44 +0100)
----------------------------------------------------------------
Block pull request
----------------------------------------------------------------
Chrysostomos Nanakos (1):
block/archipelago: Use QEMU atomic builtins
John Snow (5):
libqos: add a simple first-fit memory allocator qtest/ide: Uninitialize PC allocator
ide: Add wwn support to IDE-ATAPI drive
IDE: Fill the IDENTIFY request consistently
ide: Add resize callback to ide/core
Laszlo Ersek (2):
pflash_cfi01: fixup stale DPRINTF() calls
pflash_cfi01: write flash contents to bdrv on incoming migration
Liu Yuan (1):
block: kill tail whitespace in block.c
MORITA Kazutaka (1):
MAINTAINERS: update sheepdog maintainer
Marc Marí (7):
tests: Functions bus_foreach and device_find from libqos virtio API
tests: Add virtio device initialization
libqos: Added basic virtqueue support to virtio implementation
libqos: Added indirect descriptor support to virtio implementation
libqos: Added test case for configuration changes in virtio-blk test
libqos: Added MSI-X support
libqos: Added EVENT_IDX support
Peter Lieven (3):
rename parse_enum_option to qapi_enum_parse and make it public
qemu-nbd: add option to set detect-zeroes mode
qemu-nbd: fix indentation and coding style
Stefan Hajnoczi (4):
qemu-img: clarify src_cache option documentation
qemu-img: fix rebase src_cache option documentation
vmdk: fix vmdk_parse_extents() extent_file leaks
vmdk: fix buf leak in vmdk_parse_extents()
MAINTAINERS | 2 +- block.c | 2 +- block/archipelago.c | 76 ++---- block/vmdk.c | 4 +- blockdev.c | 30 +-- hw/block/pflash_cfi01.c | 18 +- hw/ide/core.c | 111 ++++++-- include/qapi/util.h | 17 ++ qapi/Makefile.objs | 2 +- qapi/qapi-util.c | 34 +++ qemu-img.c | 3 +- qemu-img.texi | 7 +- qemu-nbd.c | 100 +++++--- tests/Makefile | 3 +- tests/ide-test.c | 2 + tests/libqos/malloc-pc.c | 280 +++++++++++++++++++- tests/libqos/malloc-pc.h | 9 + tests/libqos/pci.c | 111 +++++++- tests/libqos/pci.h | 10 + tests/libqos/virtio-pci.c | 343 +++++++++++++++++++++++++ tests/libqos/virtio-pci.h | 61 +++++ tests/libqos/virtio.c | 257 +++++++++++++++++++ tests/libqos/virtio.h | 182 +++++++++++++ tests/libqtest.c | 48 ++++ tests/libqtest.h | 7 + tests/virtio-blk-test.c | 640 +++++++++++++++++++++++++++++++++++++++++++++- 26 files changed, 2192 insertions(+), 167 deletions(-) create mode 100644 include/qapi/util.h create mode 100644 qapi/qapi-util.c create mode 100644 tests/libqos/virtio-pci.c create mode 100644 tests/libqos/virtio-pci.h create mode 100644 tests/libqos/virtio.c create mode 100644 tests/libqos/virtio.h
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 01/24] block: kill tail whitespace in block.c
From: Liu Yuan <[email protected]>
--- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
@@ -2246,7 +2246,7 @@ int bdrv_commit(BlockDriverState *bs)if (!drv)return -ENOMEDIUM ; - +if (!bs->backing_hd) {return -ENOTSUP ; }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 02/24] pflash_cfi01: fixup stale DPRINTF() calls
In reply to Stefan HajnocziFrom: Laszlo Ersek <[email protected]>
--- hw/block/pflash_cfi01.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/pflash_cfi01.c +2 -2
@@ -209,11 +209,11 @@ static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)switch (boff &0xFF ) {case 0 : resp = pfl->ident0; -DPRINTF ("%s: Manufacturer Code %04x\n" , __func__, ret); +DPRINTF ("%s: Manufacturer Code %04x\n" , __func__, resp);break ;case 1 : resp = pfl->ident1; -DPRINTF ("%s: Device ID Code %04x\n" , __func__, ret); +DPRINTF ("%s: Device ID Code %04x\n" , __func__, resp);break ;default : DPRINTF("%s: Read Device Information offset=%x\n", __func__,
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 03/24] pflash_cfi01: write flash contents to bdrv on incoming migration
In reply to Stefan HajnocziFrom: Laszlo Ersek <[email protected]>
A drive that backs a pflash device is special:
- it is very small,
- its entire contents are kept in a RAMBlock at all times, covering the guest-phys address range that provides the guest's view of the emulated flash chip.
The pflash device model keeps the drive (the host-side file) and the guest-visible flash contents in sync. When migrating the guest, the guest-visible flash contents (the RAMBlock) is migrated by default, but on the target host, the drive (the host-side file) remains in full sync with the RAMBlock only if:
- the source and target hosts share the storage underlying the pflash drive,
- or the migration requests full or incremental block migration too, which then covers all drives.
Due to the special nature of pflash drives, the following scenario makes sense as well:
- no full nor incremental block migration, covering all drives, alongside the base migration (justified eg. by shared storage for "normal" (big) drives),
- non-shared storage for pflash drives.
In this case, currently only those portions of the flash drive are updated on the target disk that the guest reprograms while running on the target host.
In order to restore accord, dump the entire flash contents to the bdrv in a post_load() callback.
- The read-only check follows the other call-sites of pflash_update();
- both "pfl->ro" and pflash_update() reflect / consider the case when "pfl->bs" is NULL;
- the total size of the flash device is calculated as in pflash_cfi01_realize().
When using shared storage, or requesting full or incremental block migration along with the normal migration, the patch should incur a harmless rewrite from the target side.
It is assumed that, on the target host, RAM is loaded ahead of the call to pflash_post_load().
--- hw/block/pflash_cfi01.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/block/pflash_cfi01.c +14 -0
@@ -94,10 +94,13 @@ struct pflash_t {void *storage; }; +static int pflash_post_load (void *opaque,int version_id); +static const VMStateDescription vmstate_pflash = { .name ="pflash_cfi01" , .version_id =1 , .minimum_version_id =1 , + .post_load = pflash_post_load, .fields = (VMStateField []) {VMSTATE_UINT8 (wcycle, pflash_t),VMSTATE_UINT8 (cmd, pflash_t),
@@ -982,3 +985,14 @@ MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) {return &fl->mem; } + +static int pflash_post_load (void *opaque,int version_id) +{ +pflash_t *pfl = opaque; + +if (!pfl->ro) { +DPRINTF ("%s: updating bdrv for %s\n" , __func__, pfl->name); +pflash_update (pfl,0 , pfl->sector_len * pfl->nb_blocs); + } +return 0 ; +}
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 04/24] tests: Functions bus_foreach and device_find from libqos virtio API
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
Virtio header has been changed to compile and work with a real device. Functions bus_foreach and device_find have been implemented for PCI. Virtio-blk test case now opens a fake device.
--- tests/Makefile | 3 +- tests/libqos/virtio-pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-pci.h | 24 +++++++++++++++ tests/libqos/virtio.h | 23 +++++++++++++++ tests/virtio-blk-test.c | 61 +++++++++++++++++++++++++++++++++----- 5 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 tests/libqos/virtio-pci.c create mode 100644 tests/libqos/virtio-pci.h create mode 100644 tests/libqos/virtio.h
tests/Makefile +2 -1
@@ -299,6 +299,7 @@ libqos-obj-y += tests/libqos/i2c.o libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y += tests/libqos/malloc-pc.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o +libqos-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio-pci.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o
@@ -320,7 +321,7 @@ tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o -tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o +tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y) tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o
tests/libqos/virtio-pci.c new file +75 -0
75 lines not on this page · raw message
tests/libqos/virtio-pci.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* libqos virtio PCI definitions +* +* Copyright (c) 2014 Marc Marí +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef LIBQOS_VIRTIO_PCI_H +#define LIBQOS_VIRTIO_PCI_H + +#include "libqos/virtio.h" +#include "libqos/pci.h" + +typedef struct QVirtioPCIDevice { +QVirtioDevice vdev; +QPCIDevice *pdev; +}QVirtioPCIDevice ; + +void qvirtio_pci_foreach (QPCIBus *bus,uint16_t device_type, +void (*func)(QVirtioDevice *d,void *data),void *data); +QVirtioPCIDevice *qvirtio_pci_device_find (QPCIBus *bus,uint16_t device_type); +#endif
tests/libqos/virtio.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* libqos virtio definitions +* +* Copyright (c) 2014 Marc Marí +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef LIBQOS_VIRTIO_H +#define LIBQOS_VIRTIO_H + +#define QVIRTIO_VENDOR_ID 0x1AF4 + +#define QVIRTIO_NET_DEVICE_ID 0x1 +#define QVIRTIO_BLK_DEVICE_ID 0x2 + +typedef struct QVirtioDevice { +/* Device type */ +uint16_t device_type; +}QVirtioDevice ; + +#endif
tests/virtio-blk-test.c +53 -8
84 lines not on this page · raw message
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 05/24] tests: Add virtio device initialization
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
Add functions to read and write virtio header fields. Add status bit setting in virtio-blk-device.
--- tests/Makefile | 2 +- tests/libqos/virtio-pci.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-pci.h | 18 ++++++++++++ tests/libqos/virtio.c | 55 ++++++++++++++++++++++++++++++++++++ tests/libqos/virtio.h | 30 ++++++++++++++++++++ tests/libqtest.c | 48 ++++++++++++++++++++++++++++++++ tests/libqtest.h | 7 +++++ tests/virtio-blk-test.c | 31 ++++++++++++++++++--- 8 files changed, 257 insertions(+), 5 deletions(-) create mode 100644 tests/libqos/virtio.c
tests/Makefile +1 -1
@@ -299,7 +299,7 @@ libqos-obj-y += tests/libqos/i2c.o libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y += tests/libqos/malloc-pc.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o -libqos-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio-pci.o +libqos-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/libqos/virtio-pci.c +71 -0
86 lines not on this page · raw message
tests/libqos/virtio-pci.h +18 -0
@@ -13,12 +13,30 @@#include "libqos/virtio.h" #include "libqos/pci.h" +#define QVIRTIO_DEVICE_FEATURES 0x00 +#define QVIRTIO_GUEST_FEATURES 0x04 +#define QVIRTIO_QUEUE_ADDRESS 0x08 +#define QVIRTIO_QUEUE_SIZE 0x0C +#define QVIRTIO_QUEUE_SELECT 0x0E +#define QVIRTIO_QUEUE_NOTIFY 0x10 +#define QVIRTIO_DEVICE_STATUS 0x12 +#define QVIRTIO_ISR_STATUS 0x13 +#define QVIRTIO_MSIX_CONF_VECTOR 0x14 +#define QVIRTIO_MSIX_QUEUE_VECTOR 0x16 +#define QVIRTIO_DEVICE_SPECIFIC_MSIX 0x18 +#define QVIRTIO_DEVICE_SPECIFIC_NO_MSIX 0x14 +typedef struct QVirtioPCIDevice {QVirtioDevice vdev;QPCIDevice *pdev; +void *addr; }QVirtioPCIDevice ; +extern const QVirtioBus qvirtio_pci; +void qvirtio_pci_foreach (QPCIBus *bus,uint16_t device_type,void (*func)(QVirtioDevice *d,void *data),void *data);QVirtioPCIDevice *qvirtio_pci_device_find (QPCIBus *bus,uint16_t device_type); +void qvirtio_pci_device_enable (QVirtioPCIDevice *d); +void qvirtio_pci_device_disable (QVirtioPCIDevice *d);#endif
tests/libqos/virtio.c new file +55 -0
55 lines not on this page · raw message
tests/libqos/virtio.h +30 -0
@@ -12,6 +12,10 @@#define QVIRTIO_VENDOR_ID 0x1AF4 +#define QVIRTIO_RESET 0x0 +#define QVIRTIO_ACKNOWLEDGE 0x1 +#define QVIRTIO_DRIVER 0x2 +#define QVIRTIO_NET_DEVICE_ID 0x1#define QVIRTIO_BLK_DEVICE_ID 0x2
@@ -20,4 +24,30 @@ typedef struct QVirtioDevice {uint16_t device_type; } QVirtioDevice; +typedef struct QVirtioBus { +uint8_t (*config_readb)(QVirtioDevice *d,void *addr); +uint16_t (*config_readw)(QVirtioDevice *d,void *addr); +uint32_t (*config_readl)(QVirtioDevice *d,void *addr); +uint64_t (*config_readq)(QVirtioDevice *d,void *addr); + +/* Get status of the device */ +uint8_t (*get_status)(QVirtioDevice *d); + +/* Set status of the device */ +void (*set_status)(QVirtioDevice *d,uint8_t status); +}QVirtioBus ; + +uint8_t qvirtio_config_readb (const QVirtioBus *bus,QVirtioDevice *d, +void *addr); +uint16_t qvirtio_config_readw (const QVirtioBus *bus,QVirtioDevice *d, +void *addr); +uint32_t qvirtio_config_readl (const QVirtioBus *bus,QVirtioDevice *d, +void *addr); +uint64_t qvirtio_config_readq (const QVirtioBus *bus,QVirtioDevice *d, +void *addr); + +void qvirtio_reset (const QVirtioBus *bus,QVirtioDevice *d); +void qvirtio_set_acknowledge (const QVirtioBus *bus,QVirtioDevice *d); +void qvirtio_set_driver (const QVirtioBus *bus,QVirtioDevice *d); +#endif
tests/libqtest.c +48 -0
51 lines not on this page · raw message
tests/libqtest.h +7 -0
@@ -682,4 +682,11 @@ static inline int64_t clock_set(int64_t val) return qtest_clock_set(global_qtest, val); } +/** +* qtest_big_endian: +* +* Returns: True if the architecture under test has a big endian configuration. +*/ +bool qtest_big_endian (void ); +#endif
tests/virtio-blk-test.c +27 -4
@@ -49,18 +49,41 @@ static void test_end(void)qtest_end (); } -static void pci_basic (void ) +static QVirtioPCIDevice *virtio_blk_init (QPCIBus *bus) {QVirtioPCIDevice *dev; -QPCIBus *bus; - - bus =test_start (); dev =qvirtio_pci_device_find (bus,QVIRTIO_BLK_DEVICE_ID );g_assert (dev !=NULL ); g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID); g_assert_cmphex(dev->pdev->devfn, ==, ((PCI_SLOT << 3) | PCI_FN)); +qvirtio_pci_device_enable (dev); +qvirtio_reset (&qvirtio_pci, &dev->vdev); +qvirtio_set_acknowledge (&qvirtio_pci, &dev->vdev); +qvirtio_set_driver (&qvirtio_pci, &dev->vdev); + +return dev; +} + +static void pci_basic (void ) +{ +QVirtioPCIDevice *dev; +QPCIBus *bus; +void *addr; +uint64_t capacity; + + bus =test_start (); + + dev =virtio_blk_init (bus); + +/* MSI-X is not enabled */ + addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; + + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); + +qvirtio_pci_device_disable (dev);g_free (dev);test_end (); }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 06/24] libqos: Added basic virtqueue support to virtio implementation
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
Add status changing and feature negotiation.
Add basic virtqueue support for adding and sending virtqueue requests. Add ISR checking.
[Squashed request endianness fix by Greg Kurz <[email protected]> --Stefan]
--- tests/libqos/virtio-pci.c | 82 +++++++++++++++++++ tests/libqos/virtio-pci.h | 2 + tests/libqos/virtio.c | 100 +++++++++++++++++++++++ tests/libqos/virtio.h | 99 +++++++++++++++++++++++ tests/virtio-blk-test.c | 196 +++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 476 insertions(+), 3 deletions(-)
tests/libqos/virtio-pci.c +82 -0
@@ -14,6 +14,8 @@#include "libqos/virtio-pci.h" #include "libqos/pci.h" #include "libqos/pci-pc.h" +#include "libqos/malloc.h" +#include "libqos/malloc-pc.h" #include "hw/pci/pci_regs.h"
@@ -93,6 +95,18 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)return u64; } +static uint32_t qvirtio_pci_get_features (QVirtioDevice *d) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_DEVICE_FEATURES ); +} + +static void qvirtio_pci_set_features (QVirtioDevice *d,uint32_t features) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_GUEST_FEATURES , features); +} +static uint8_t qvirtio_pci_get_status (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
@@ -105,13 +119,81 @@ static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t status)qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_DEVICE_STATUS , status); } +static uint8_t qvirtio_pci_get_isr_status (QVirtioDevice *d) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_ISR_STATUS ); +} + +static void qvirtio_pci_queue_select (QVirtioDevice *d,uint16_t index) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_QUEUE_SELECT , index); +} + +static uint16_t qvirtio_pci_get_queue_size (QVirtioDevice *d) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +return qpci_io_readw (dev->pdev, dev->addr +QVIRTIO_QUEUE_SIZE ); +} + +static void qvirtio_pci_set_queue_address (QVirtioDevice *d,uint32_t pfn) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_QUEUE_ADDRESS , pfn); +} + +static QVirtQueue *qvirtio_pci_virtqueue_setup (QVirtioDevice *d, +QGuestAllocator *alloc,uint16_t index) +{ +uint64_t addr; +QVirtQueue *vq; + + vq =g_malloc0 (sizeof (*vq)); + +qvirtio_pci_queue_select (d, index); + vq->index = index; + vq->size =qvirtio_pci_get_queue_size (d); + vq->free_head =0 ; + vq->num_free = vq->size; + vq->align =QVIRTIO_PCI_ALIGN ; + +/* Check different than 0 */ + g_assert_cmpint(vq->size, !=, 0); + +/* Check power of 2 */ + g_assert_cmpint(vq->size & (vq->size - 1), ==, 0); + + addr =guest_alloc (alloc,qvring_size (vq->size,QVIRTIO_PCI_ALIGN )); +qvring_init (alloc, vq, addr); +qvirtio_pci_set_queue_address (d, vq->desc /QVIRTIO_PCI_ALIGN ); + +/* TODO: MSI-X configuration */ + +return vq; +} + +static void qvirtio_pci_virtqueue_kick (QVirtioDevice *d,QVirtQueue *vq) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +qpci_io_writew (dev->pdev, dev->addr +QVIRTIO_QUEUE_NOTIFY , vq->index); +} +const QVirtioBus qvirtio_pci = { .config_readb = qvirtio_pci_config_readb, .config_readw = qvirtio_pci_config_readw, .config_readl = qvirtio_pci_config_readl, .config_readq = qvirtio_pci_config_readq, + .get_features = qvirtio_pci_get_features, + .set_features = qvirtio_pci_set_features, .get_status = qvirtio_pci_get_status, .set_status = qvirtio_pci_set_status, + .get_isr_status = qvirtio_pci_get_isr_status, + .queue_select = qvirtio_pci_queue_select, + .get_queue_size = qvirtio_pci_get_queue_size, + .set_queue_address = qvirtio_pci_set_queue_address, + .virtqueue_setup = qvirtio_pci_virtqueue_setup, + .virtqueue_kick = qvirtio_pci_virtqueue_kick, }; void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type,
tests/libqos/virtio-pci.h +2 -0
@@ -26,6 +26,8 @@#define QVIRTIO_DEVICE_SPECIFIC_MSIX 0x18#define QVIRTIO_DEVICE_SPECIFIC_NO_MSIX 0x14 +#define QVIRTIO_PCI_ALIGN 4096 + typedef struct QVirtioPCIDevice { QVirtioDevice vdev; QPCIDevice *pdev;
tests/libqos/virtio.c +100 -0
109 lines not on this page · raw message
tests/libqos/virtio.h +99 -0
141 lines not on this page · raw message
tests/virtio-blk-test.c +193 -3
221 lines not on this page · raw message
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 07/24] libqos: Added indirect descriptor support to virtio implementation
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
Add functions necessary for working with indirect descriptors. Add test using new functions.
--- tests/libqos/virtio-pci.c | 10 +++++ tests/libqos/virtio.c | 64 +++++++++++++++++++++++++++++ tests/libqos/virtio.h | 22 +++++++++- tests/virtio-blk-test.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 1 deletion(-)
tests/libqos/virtio-pci.c +10 -0
@@ -107,6 +107,12 @@ static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features)qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_GUEST_FEATURES , features); } +static uint32_t qvirtio_pci_get_guest_features (QVirtioDevice *d) +{ +QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; +return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_GUEST_FEATURES ); +} +static uint8_t qvirtio_pci_get_status (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
@@ -146,10 +152,12 @@ static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn)static QVirtQueue *qvirtio_pci_virtqueue_setup (QVirtioDevice *d,QGuestAllocator *alloc,uint16_t index) { +uint32_t feat;uint64_t addr;QVirtQueue *vq; vq =g_malloc0 (sizeof (*vq)); + feat =qvirtio_pci_get_guest_features (d);qvirtio_pci_queue_select (d, index); vq->index = index;
@@ -157,6 +165,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, vq->free_head =0 ; vq->num_free = vq->size; vq->align =QVIRTIO_PCI_ALIGN ; + vq->indirect = (feat &QVIRTIO_F_RING_INDIRECT_DESC ) !=0 ;/* Check different than 0 */ g_assert_cmpint(vq->size, !=, 0);
@@ -186,6 +195,7 @@ const QVirtioBus qvirtio_pci = { .config_readq = qvirtio_pci_config_readq, .get_features = qvirtio_pci_get_features, .set_features = qvirtio_pci_set_features, + .get_guest_features = qvirtio_pci_get_guest_features, .get_status = qvirtio_pci_get_status, .set_status = qvirtio_pci_set_status, .get_isr_status = qvirtio_pci_get_isr_status,
tests/libqos/virtio.c +64 -0
76 lines not on this page · raw message
tests/libqos/virtio.h +21 -1
@@ -22,6 +22,11 @@#define QVIRTIO_NET_DEVICE_ID 0x1#define QVIRTIO_BLK_DEVICE_ID 0x2 +#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 +#define QVIRTIO_F_ANY_LAYOUT 0x08000000 +#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 +#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 +#define QVRING_DESC_F_NEXT 0x1#define QVRING_DESC_F_WRITE 0x2#define QVRING_DESC_F_INDIRECT 0x4
@@ -74,8 +79,15 @@ typedef struct QVirtQueue {uint32_t free_head;uint32_t num_free;uint32_t align; +bool indirect; } QVirtQueue; +typedef struct QVRingIndirectDesc { +uint64_t desc;/* This points to an array fo QVRingDesc */ +uint16_t index; +uint16_t elem; +}QVRingIndirectDesc ; + typedef struct QVirtioBus { uint8_t (*config_readb)(QVirtioDevice *d, void *addr); uint16_t (*config_readw)(QVirtioDevice *d, void *addr);
@@ -85,9 +97,12 @@ typedef struct QVirtioBus {/* Get features of the device */ uint32_t (*get_features)(QVirtioDevice *d); -/* Get features of the device */ +/* Set features of the device */ void (*set_features)(QVirtioDevice *d,uint32_t features); +/* Get features of the guest */ +uint32_t (*get_guest_features)(QVirtioDevice *d); +/* Get status of the device */ uint8_t (*get_status)(QVirtioDevice *d);
@@ -144,8 +159,13 @@ QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index);void qvring_init (const QGuestAllocator *alloc,QVirtQueue *vq,uint64_t addr); +QVRingIndirectDesc *qvring_indirect_desc_setup (QVirtioDevice *d, +QGuestAllocator *alloc,uint16_t elem); +void qvring_indirect_desc_add (QVRingIndirectDesc *indirect,uint64_t data, +uint32_t len,bool write);uint32_t qvirtqueue_add (QVirtQueue *vq,uint64_t data,uint32_t len,bool write,bool next); +uint32_t qvirtqueue_add_indirect (QVirtQueue *vq,QVRingIndirectDesc *indirect);void qvirtqueue_kick (const QVirtioBus *bus,QVirtioDevice *d,QVirtQueue *vq,uint32_t free_head);
tests/virtio-blk-test.c +100 -0
112 lines not on this page · raw message
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 08/24] libqos: Added test case for configuration changes in virtio-blk test
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
--- tests/virtio-blk-test.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
tests/virtio-blk-test.c +34 -0
@@ -377,6 +377,39 @@ static void pci_indirect(void)test_end (); } +static void pci_config (void ) +{ +QVirtioPCIDevice *dev; +QPCIBus *bus; +int n_size =TEST_IMAGE_SIZE /2 ; +void *addr; +uint64_t capacity; + + bus =test_start (); + + dev =virtio_blk_init (bus); + +/* MSI-X is not enabled */ + addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; + + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); + +qvirtio_set_driver_ok (&qvirtio_pci, &dev->vdev); + +qmp ("{ 'execute': 'block_resize', 'arguments': { 'device': 'drive0', " +" 'size': %d } }" , n_size); +g_assert (qvirtio_wait_isr (&qvirtio_pci, &dev->vdev,0x2 , +QVIRTIO_BLK_TIMEOUT )); + + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + g_assert_cmpint(capacity, ==, n_size / 512); + +qvirtio_pci_device_disable (dev); +g_free (dev); +test_end (); +} +int main (int argc,char **argv) {int ret;
@@ -385,6 +418,7 @@ int main(int argc, char **argv)g_test_add_func ("/virtio/blk/pci/basic" , pci_basic);g_test_add_func ("/virtio/blk/pci/indirect" , pci_indirect); +g_test_add_func ("/virtio/blk/pci/config" , pci_config); ret =g_test_run ();
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 09/24] libqos: Added MSI-X support
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
Added MSI-X support for qtest PCI.
Added MSI-X support for virtio-pci.
Added MSI-X test case in virtio-blk-test.
--- tests/libqos/pci.c | 111 +++++++++++++++++++++++++++- tests/libqos/pci.h | 10 +++ tests/libqos/virtio-pci.c | 142 +++++++++++++++++++++++++++++++----- tests/libqos/virtio-pci.h | 17 +++++ tests/libqos/virtio.c | 17 ++++- tests/libqos/virtio.h | 11 ++- tests/virtio-blk-test.c | 180 ++++++++++++++++++++++++++++++++++++---------- 7 files changed, 426 insertions(+), 62 deletions(-)
tests/libqos/pci.c +109 -2
@@ -15,8 +15,6 @@#include "hw/pci/pci_regs.h" #include <glib.h> -#include <stdio.h> -void qpci_device_foreach (QPCIBus *bus,int vendor_id,int device_id,void (*func)(QPCIDevice *dev,int devfn,void *data),void *data)
@@ -75,6 +73,115 @@ void qpci_device_enable(QPCIDevice *dev)qpci_config_writew (dev,PCI_COMMAND , cmd); } +uint8_t qpci_find_capability (QPCIDevice *dev,uint8_t id) +{ +uint8_t cap; +uint8_t addr =qpci_config_readb (dev,PCI_CAPABILITY_LIST ); + +do { + cap =qpci_config_readb (dev, addr); +if (cap != id) { + addr =qpci_config_readb (dev, addr +PCI_CAP_LIST_NEXT ); + } + }while (cap != id && addr !=0 ); + +return addr; +} + +void qpci_msix_enable (QPCIDevice *dev) +{ +uint8_t addr; +uint16_t val; +uint32_t table; +uint8_t bir_table; +uint8_t bir_pba; +void *offset; + + addr =qpci_find_capability (dev,PCI_CAP_ID_MSIX ); + g_assert_cmphex(addr, !=, 0); + + val =qpci_config_readw (dev, addr +PCI_MSIX_FLAGS ); +qpci_config_writew (dev, addr +PCI_MSIX_FLAGS , val |PCI_MSIX_FLAGS_ENABLE ); + + table =qpci_config_readl (dev, addr +PCI_MSIX_TABLE ); + bir_table = table &PCI_MSIX_FLAGS_BIRMASK ; + offset =qpci_iomap (dev, bir_table,NULL ); + dev->msix_table = offset + (table & ~PCI_MSIX_FLAGS_BIRMASK ); + + table =qpci_config_readl (dev, addr +PCI_MSIX_PBA ); + bir_pba = table &PCI_MSIX_FLAGS_BIRMASK ; +if (bir_pba != bir_table) { + offset =qpci_iomap (dev, bir_pba,NULL ); + } + dev->msix_pba = offset + (table & ~PCI_MSIX_FLAGS_BIRMASK ); + +g_assert (dev->msix_table !=NULL ); +g_assert (dev->msix_pba !=NULL ); + dev->msix_enabled = true; +} + +void qpci_msix_disable (QPCIDevice *dev) +{ +uint8_t addr; +uint16_t val; + +g_assert (dev->msix_enabled); + addr =qpci_find_capability (dev,PCI_CAP_ID_MSIX ); + g_assert_cmphex(addr, !=, 0); + val =qpci_config_readw (dev, addr +PCI_MSIX_FLAGS ); +qpci_config_writew (dev, addr +PCI_MSIX_FLAGS , + val & ~PCI_MSIX_FLAGS_ENABLE ); + +qpci_iounmap (dev, dev->msix_table); +qpci_iounmap (dev, dev->msix_pba); + dev->msix_enabled =0 ; + dev->msix_table =NULL ; + dev->msix_pba =NULL ; +} + +bool qpci_msix_pending (QPCIDevice *dev,uint16_t entry) +{ +uint32_t pba_entry; +uint8_t bit_n = entry %32 ; +void *addr = dev->msix_pba + (entry /32 ) *PCI_MSIX_ENTRY_SIZE /4 ; + +g_assert (dev->msix_enabled); + pba_entry =qpci_io_readl (dev, addr); +qpci_io_writel (dev, addr, pba_entry & ~(1 << bit_n)); +return (pba_entry & (1 << bit_n)) !=0 ; +} + +bool qpci_msix_masked (QPCIDevice *dev,uint16_t entry) +{ +uint8_t addr; +uint16_t val; +void *vector_addr = dev->msix_table + (entry *PCI_MSIX_ENTRY_SIZE ); + +g_assert (dev->msix_enabled); + addr =qpci_find_capability (dev,PCI_CAP_ID_MSIX ); + g_assert_cmphex(addr, !=, 0); + val =qpci_config_readw (dev, addr +PCI_MSIX_FLAGS ); + +if (val &PCI_MSIX_FLAGS_MASKALL ) { +return true; + }else { +return (qpci_io_readl (dev, vector_addr +PCI_MSIX_ENTRY_VECTOR_CTRL ) + &PCI_MSIX_ENTRY_CTRL_MASKBIT ) !=0 ; + } +} + +uint16_t qpci_msix_table_size (QPCIDevice *dev) +{ +uint8_t addr; +uint16_t control; + + addr =qpci_find_capability (dev,PCI_CAP_ID_MSIX ); + g_assert_cmphex(addr, !=, 0); + + control =qpci_config_readw (dev, addr +PCI_MSIX_FLAGS ); +return (control &PCI_MSIX_FLAGS_QSIZE ) +1 ; +} +uint8_t qpci_config_readb (QPCIDevice *dev,uint8_t offset) {return dev->bus->config_readb (dev->bus, dev->devfn, offset);
tests/libqos/pci.h +10 -0
@@ -14,6 +14,7 @@#define LIBQOS_PCI_H #include <stdint.h> +#include "libqtest.h" #define QPCI_DEVFN (dev, fn) (((dev) << 3) | (fn))
@@ -49,6 +50,9 @@ struct QPCIDevice {QPCIBus *bus;int devfn; +bool msix_enabled; +void *msix_table; +void *msix_pba; }; void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
@@ -57,6 +61,12 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,QPCIDevice *qpci_device_find (QPCIBus *bus,int devfn);void qpci_device_enable (QPCIDevice *dev); +uint8_t qpci_find_capability (QPCIDevice *dev,uint8_t id); +void qpci_msix_enable (QPCIDevice *dev); +void qpci_msix_disable (QPCIDevice *dev); +bool qpci_msix_pending (QPCIDevice *dev,uint16_t entry); +bool qpci_msix_masked (QPCIDevice *dev,uint16_t entry); +uint16_t qpci_msix_table_size (QPCIDevice *dev);uint8_t qpci_config_readb (QPCIDevice *dev,uint8_t offset);uint16_t qpci_config_readw (QPCIDevice *dev,uint8_t offset);
tests/libqos/virtio-pci.c +123 -19
182 lines not on this page · raw message
tests/libqos/virtio-pci.h +17 -0
@@ -28,12 +28,24 @@#define QVIRTIO_PCI_ALIGN 4096 +#define QVIRTIO_MSI_NO_VECTOR 0xFFFF +typedef struct QVirtioPCIDevice {QVirtioDevice vdev;QPCIDevice *pdev;void *addr; +uint16_t config_msix_entry; +uint64_t config_msix_addr; +uint32_t config_msix_data; }QVirtioPCIDevice ; +typedef struct QVirtQueuePCI { +QVirtQueue vq; +uint16_t msix_entry; +uint64_t msix_addr; +uint32_t msix_data; +}QVirtQueuePCI ; +extern const QVirtioBus qvirtio_pci; void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type,
@@ -41,4 +53,9 @@ void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type,QVirtioPCIDevice *qvirtio_pci_device_find (QPCIBus *bus,uint16_t device_type);void qvirtio_pci_device_enable (QVirtioPCIDevice *d);void qvirtio_pci_device_disable (QVirtioPCIDevice *d); + +void qvirtio_pci_set_msix_configuration_vector (QVirtioPCIDevice *d, +QGuestAllocator *alloc,uint16_t entry); +void qvirtqueue_pci_msix_setup (QVirtioPCIDevice *d,QVirtQueuePCI *vqpci, +QGuestAllocator *alloc,uint16_t entry);#endif
tests/libqos/virtio.c +15 -2
@@ -78,12 +78,25 @@ void qvirtio_set_driver_ok(const QVirtioBus *bus, QVirtioDevice *d) QVIRTIO_DRIVER_OK | QVIRTIO_DRIVER | QVIRTIO_ACKNOWLEDGE); } -bool qvirtio_wait_isr (const QVirtioBus *bus,QVirtioDevice *d,uint8_t mask, +bool qvirtio_wait_queue_isr (const QVirtioBus *bus,QVirtioDevice *d, +QVirtQueue *vq,uint64_t timeout) +{ +do { +clock_step (10 ); +if (bus->get_queue_isr_status (d, vq)) { +break ;/* It has ended */ + } + }while (--timeout); + +return timeout !=0 ; +} + +bool qvirtio_wait_config_isr (const QVirtioBus *bus,QVirtioDevice *d,uint64_t timeout) {do {clock_step (10 ); -if (bus->get_isr_status (d) & mask) { +if (bus->get_config_isr_status (d)) {break ;/* It has ended */ } }while (--timeout);
tests/libqos/virtio.h +8 -3
@@ -109,8 +109,11 @@ typedef struct QVirtioBus {/* Set status of the device */ void (*set_status)(QVirtioDevice *d,uint8_t status); -/* Get the ISR status of the device */ -uint8_t (*get_isr_status)(QVirtioDevice *d); +/* Get the queue ISR status of the device */ +bool (*get_queue_isr_status)(QVirtioDevice *d,QVirtQueue *vq); + +/* Get the configuration ISR status of the device */ +bool (*get_config_isr_status)(QVirtioDevice *d);/* Select a queue to work on */ void (*queue_select)(QVirtioDevice *d,uint16_t index);
@@ -153,7 +156,9 @@ void qvirtio_set_acknowledge(const QVirtioBus *bus, QVirtioDevice *d);void qvirtio_set_driver (const QVirtioBus *bus,QVirtioDevice *d);void qvirtio_set_driver_ok (const QVirtioBus *bus,QVirtioDevice *d); -bool qvirtio_wait_isr (const QVirtioBus *bus,QVirtioDevice *d,uint8_t mask, +bool qvirtio_wait_queue_isr (const QVirtioBus *bus,QVirtioDevice *d, +QVirtQueue *vq,uint64_t timeout); +bool qvirtio_wait_config_isr (const QVirtioBus *bus,QVirtioDevice *d,uint64_t timeout);QVirtQueue *qvirtqueue_setup (const QVirtioBus *bus,QVirtioDevice *d,QGuestAllocator *alloc,uint16_t index);
tests/virtio-blk-test.c +144 -36
283 lines not on this page · raw message
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 10/24] libqos: Added EVENT_IDX support
In reply to Stefan HajnocziFrom: Marc Marí <[email protected]>
Added avail_event and NO_NOTIFY check before notifying. Added used_event setting.
--- tests/libqos/virtio-pci.c | 1 + tests/libqos/virtio.c | 27 +++++++++- tests/libqos/virtio.h | 5 ++ tests/virtio-blk-test.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-)
tests/libqos/virtio-pci.c +1 -0
@@ -203,6 +203,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, vqpci->vq.num_free = vqpci->vq.size; vqpci->vq.align =QVIRTIO_PCI_ALIGN ; vqpci->vq.indirect = (feat &QVIRTIO_F_RING_INDIRECT_DESC ) !=0 ; + vqpci->vq.event = (feat &QVIRTIO_F_RING_EVENT_IDX ) !=0 ; vqpci->msix_entry =-1 ; vqpci->msix_addr =0 ;
tests/libqos/virtio.c +26 -1
@@ -124,9 +124,13 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)writew (vq->avail,0 );/* vq->avail->idx */ writew (vq->avail +2 ,0 ); +/* vq->avail->used_event */ +writew (vq->avail +4 + (2 * vq->size),0 );/* vq->used->flags */ writew (vq->used,0 ); +/* vq->used->avail_event */ +writew (vq->used+2 +(sizeof (struct QVRingUsedElem )*vq->size),0 ); } QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
@@ -222,11 +226,32 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq, {/* vq->avail->idx */ uint16_t idx =readl (vq->avail +2 ); +/* vq->used->flags */ +uint16_t flags; +/* vq->used->avail_event */ +uint16_t avail_event;/* vq->avail->ring[idx % vq->size] */ writel (vq->avail +4 + (2 * (idx % vq->size)), free_head);/* vq->avail->idx */ writel (vq->avail +2 , idx +1 ); - bus->virtqueue_kick (d, vq); +/* Must read after idx is updated */ + flags =readw (vq->avail); + avail_event =readw (vq->used +4 + + (sizeof (struct QVRingUsedElem ) * vq->size)); + +/* < 1 because we add elements to avail queue one by one */ +if ((flags &QVRING_USED_F_NO_NOTIFY ) ==0 && + (!vq->event || (uint16_t )(idx-avail_event) <1 )) { + bus->virtqueue_kick (d, vq); + } +} + +void qvirtqueue_set_used_event (QVirtQueue *vq,uint16_t idx) +{ +g_assert (vq->event); + +/* vq->avail->used_event */ +writew (vq->avail +4 + (2 * vq->size), idx); }
tests/libqos/virtio.h +5 -0
@@ -26,6 +26,7 @@#define QVIRTIO_F_ANY_LAYOUT 0x08000000#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 +#define QVIRTIO_F_BAD_FEATURE 0x40000000#define QVRING_DESC_F_NEXT 0x1#define QVRING_DESC_F_WRITE 0x2
@@ -57,6 +58,7 @@ typedef struct QVRingAvail {uint16_t flags;uint16_t idx;uint16_t ring[0 ];/* This is an array of uint16_t */ +uint16_t used_event; } QVRingAvail; typedef struct QVRingUsedElem {
@@ -68,6 +70,7 @@ typedef struct QVRingUsed {uint16_t flags;uint16_t idx;QVRingUsedElem ring[0 ];/* This is an array of QVRingUsedElem structs */ +uint16_t avail_event; } QVRingUsed; typedef struct QVirtQueue {
@@ -80,6 +83,7 @@ typedef struct QVirtQueue {uint32_t num_free;uint32_t align;bool indirect; +bool event; } QVirtQueue; typedef struct QVRingIndirectDesc {
@@ -174,4 +178,5 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect);void qvirtqueue_kick (const QVirtioBus *bus,QVirtioDevice *d,QVirtQueue *vq,uint32_t free_head); +void qvirtqueue_set_used_event (QVirtQueue *vq,uint16_t idx);#endif
tests/virtio-blk-test.c +124 -0
136 lines not on this page · raw message
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 12/24] qemu-img: fix rebase src_cache option documentation
In reply to Stefan HajnocziThe src_cache option (-T) specifies the cache mode for backing files. It applies both the image's old backing file as well as the new backing file:
ret = bdrv_open(&bs_old_backing, backing_name, NULL, NULL, src_flags,
old_backing_drv, &local_err);
if (ret) {
...
}
if (out_baseimg[0]) {
bs_new_backing = bdrv_new("new_backing", &error_abort);
ret = bdrv_open(&bs_new_backing, out_baseimg, NULL, NULL, src_flags,
new_backing_drv, &local_err);
if (ret) {
...
}
}The documentation only mentions the new backing file but it really applies to both.
--- qemu-img.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.texi +1 -1
@@ -341,7 +341,7 @@ string), then the image is rebased onto no backing file (i.e. it will exist independently of any backing file). @var{cache} specifies the cache mode to be used for @var{filename}, whereas -@var{src_cache} specifies the cache mode for reading the new backing file. +@var{src_cache} specifies the cache mode for reading backing files. There are two different modes in which @code{rebase} can operate: @table @option
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 11/24] qemu-img: clarify src_cache option documentation
In reply to Stefan HajnocziThe source cache option takes the same values as the cache option. The documentation reads a little strange because it starts with "In contrast the src_cache option ...". The fact that this is comparing with the previous documented option (the 'cache' option) is implicit. Readers may be confused, especially if they jump to src_cache without reading cache documentation first.
--- qemu-img.c | 3 ++- qemu-img.texi | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-)
qemu-img.c +2 -1
@@ -95,7 +95,8 @@ static void QEMU_NORETURN help(void)" 'cache' is the cache mode used to write the output disk image, the valid\n" " options are: 'none', 'writeback' (default, except for convert), 'writethrough',\n" " 'directsync' and 'unsafe' (default for convert)\n" -" 'src_cache' in contrast is the cache mode used to read input disk images\n" +" 'src_cache' is the cache mode used to read input disk images, the valid\n" +" options are the same as for the 'cache' option\n" " 'size' is the disk image size in bytes. Optional suffixes\n" " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M),\n" " 'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 1024P) are\n"
qemu-img.texi +3 -2
@@ -73,8 +73,9 @@ specifies the cache mode that should be used with the (destination) file. See the documentation of the emulator's @code{-drive cache=...} option for allowed values. @item -T @var{src_cache} -in contrast specifies the cache mode that should be used with the source -file(s). +specifies the cache mode that should be used with the source file(s). See +the documentation of the emulator's @code{-drive cache=...} option for allowed +values. @end table Parameters to snapshot subcommand:
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 16/24] qemu-nbd: fix indentation and coding style
In reply to Stefan HajnocziFrom: Peter Lieven <[email protected]>
--- qemu-nbd.c | 75 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 36 deletions(-)
qemu-nbd.c +39 -36
@@ -39,10 +39,10 @@#include <libgen.h> #include <pthread.h> -#define SOCKET_PATH "/var/lock/qemu-nbd-%s" -#define QEMU_NBD_OPT_CACHE 1 -#define QEMU_NBD_OPT_AIO 2 -#define QEMU_NBD_OPT_DISCARD 3 +#define SOCKET_PATH "/var/lock/qemu-nbd-%s" +#define QEMU_NBD_OPT_CACHE 1 +#define QEMU_NBD_OPT_AIO 2 +#define QEMU_NBD_OPT_DISCARD 3#define QEMU_NBD_OPT_DETECT_ZEROES 4static NBDExport *exp;
@@ -60,44 +60,44 @@ static void usage(const char *name) "Usage: %s [OPTIONS] FILE\n" "QEMU Disk Network Block Device Server\n" "\n" -" -h, --help display this help and exit\n" -" -V, --version output version information and exit\n" +" -h, --help display this help and exit\n" +" -V, --version output version information and exit\n" "\n" "Connection properties:\n" -" -p, --port=PORT port to listen on (default `%d')\n" -" -b, --bind=IFACE interface to bind to (default `0.0.0.0')\n" -" -k, --socket=PATH path to the unix socket\n" -" (default '"SOCKET_PATH"')\n" -" -e, --shared=NUM device can be shared by NUM clients (default '1')\n" -" -t, --persistent don't exit on the last connection\n" -" -v, --verbose display extra debugging information\n" +" -p, --port=PORT port to listen on (default `%d')\n" +" -b, --bind=IFACE interface to bind to (default `0.0.0.0')\n" +" -k, --socket=PATH path to the unix socket\n" +" (default '"SOCKET_PATH"')\n" +" -e, --shared=NUM device can be shared by NUM clients (default '1')\n" +" -t, --persistent don't exit on the last connection\n" +" -v, --verbose display extra debugging information\n" "\n" "Exposing part of the image:\n" -" -o, --offset=OFFSET offset into the image\n" -" -P, --partition=NUM only expose partition NUM\n" +" -o, --offset=OFFSET offset into the image\n" +" -P, --partition=NUM only expose partition NUM\n" "\n" #ifdef __linux__ "Kernel NBD client support:\n" -" -c, --connect=DEV connect FILE to the local NBD device DEV\n" -" -d, --disconnect disconnect the specified device\n" +" -c, --connect=DEV connect FILE to the local NBD device DEV\n" +" -d, --disconnect disconnect the specified device\n" "\n" #endif"\n" "Block device options:\n" -" -f, --format=FORMAT set image format (raw, qcow2, ...)\n" -" -r, --read-only export read-only\n" -" -s, --snapshot use FILE as an external snapshot, create a temporary\n" -" file with backing_file=FILE, redirect the write to\n" -" the temporary one\n" +" -f, --format=FORMAT set image format (raw, qcow2, ...)\n" +" -r, --read-only export read-only\n" +" -s, --snapshot use FILE as an external snapshot, create a temporary\n" +" file with backing_file=FILE, redirect the write to\n" +" the temporary one\n" " -l, --load-snapshot=SNAPSHOT_PARAM\n" -" load an internal snapshot inside FILE and export it\n" -" as an read-only device, SNAPSHOT_PARAM format is\n" -" 'snapshot.id=[ID],snapshot.name=[NAME]', or\n" -" '[ID_OR_NAME]'\n" -" -n, --nocache disable host cache\n" -" --cache=MODE set cache mode (none, writeback, ...)\n" +" load an internal snapshot inside FILE and export it\n" +" as an read-only device, SNAPSHOT_PARAM format is\n" +" 'snapshot.id=[ID],snapshot.name=[NAME]', or\n" +" '[ID_OR_NAME]'\n" +" -n, --nocache disable host cache\n" +" --cache=MODE set cache mode (none, writeback, ...)\n" #ifdef CONFIG_LINUX_AIO -" --aio=MODE set AIO mode (native or threads)\n" +" --aio=MODE set AIO mode (native or threads)\n" #endif " --discard=MODE set discard mode (ignore, unmap)\n" " --detect-zeroes=MODE set detect-zeroes mode (off, on, discard)\n"
@@ -546,15 +546,18 @@ int main(int argc, char **argv)break ;case 'P' : partition =strtol (optarg, &end,0 ); -if (*end) +if (*end) {errx (EXIT_FAILURE ,"Invalid partition `%s'" , optarg); -if (partition <1 || partition >8 ) + } +if (partition <1 || partition >8 ) {errx (EXIT_FAILURE ,"Invalid partition %d" , partition); + }break ;case 'k' : sockpath = optarg; -if (sockpath[0 ] !='/' ) +if (sockpath[0 ] !='/' ) {errx (EXIT_FAILURE ,"socket path must be absolute\n" ); + }break ;case 'd' : disconnect = true;
@@ -574,9 +577,9 @@ int main(int argc, char **argv)case 'f' : fmt = optarg;break ; -case 't' : - persistent =1 ; -break ; +case 't' : + persistent =1 ; +break ;case 'v' : verbose =1 ;break ;
@@ -611,7 +614,7 @@ int main(int argc, char **argv)printf ("%s disconnected\n" , argv[optind]); -return 0 ; +return 0 ; }if (device && !verbose) {
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 13/24] block/archipelago: Use QEMU atomic builtins
In reply to Stefan HajnocziFrom: Chrysostomos Nanakos <[email protected]>
Replace __sync builtins with ones provided by QEMU for atomic operations.
Special thanks goes to Paolo Bonzini for his refactoring suggestion in order to use the already existing atomic builtins interface.
--- block/archipelago.c | 76 ++++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 53 deletions(-)
block/archipelago.c +23 -53
@@ -57,6 +57,7 @@#include "qapi/qmp/qint.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp/qjson.h" +#include "qemu/atomic.h" #include <inttypes.h> #include <xseg/xseg.h>
@@ -214,7 +215,7 @@ static void xseg_request_handler(void *state)xseg_put_request (s->xseg, req, s->srcport); -if ((__sync_add_and_fetch (&segreq->ref,-1 )) ==0 ) { +if (atomic_fetch_dec (&segreq->ref) ==1 ) {if (!segreq->failed) { reqdata->aio_cb->ret = segreq->count;archipelago_finish_aiocb (reqdata);
@@ -233,7 +234,7 @@ static void xseg_request_handler(void *state) segreq->count += req->serviced;xseg_put_request (s->xseg, req, s->srcport); -if ((__sync_add_and_fetch (&segreq->ref,-1 )) ==0 ) { +if (atomic_fetch_dec (&segreq->ref) ==1 ) {if (!segreq->failed) { reqdata->aio_cb->ret = segreq->count;archipelago_finish_aiocb (reqdata);
@@ -824,78 +825,47 @@ static int archipelago_aio_segmented_rw(BDRVArchipelagoState *s,ArchipelagoAIOCB *aio_cb, int op) { - int i, ret, segments_nr, last_segment_size; + int ret, segments_nr; +size_t pos =0 ;ArchipelagoSegmentedRequest *segreq; - segreq =g_new (ArchipelagoSegmentedRequest,1 ); + segreq =g_new0 (ArchipelagoSegmentedRequest,1 );if (op ==ARCHIP_OP_FLUSH ) { segments_nr =1 ; - segreq->ref = segments_nr; - segreq->total = count; - segreq->count =0 ; - segreq->failed =0 ; - ret =archipelago_submit_request (s,0 , count, offset, aio_cb, - segreq,ARCHIP_OP_FLUSH ); -if (ret <0 ) { - goto err_exit; - } -return 0 ; + }else { + segments_nr = (int )(count /MAX_REQUEST_SIZE ) + \ + ((count %MAX_REQUEST_SIZE ) ?1 :0 ); } - - segments_nr = (int )(count /MAX_REQUEST_SIZE ) + \ - ((count %MAX_REQUEST_SIZE ) ?1 :0 ); - last_segment_size = (int )(count %MAX_REQUEST_SIZE ); - - segreq->ref = segments_nr; segreq->total = count; - segreq->count =0 ; - segreq->failed =0 ; +atomic_mb_set (&segreq->ref, segments_nr); -for (i =0 ; i < segments_nr -1 ; i++) { - ret =archipelago_submit_request (s, i *MAX_REQUEST_SIZE , -MAX_REQUEST_SIZE , - offset + i *MAX_REQUEST_SIZE , - aio_cb, segreq, op); +while (segments_nr >1 ) { + ret =archipelago_submit_request (s, pos, +MAX_REQUEST_SIZE , + offset + pos, + aio_cb, segreq, op);if (ret <0 ) { goto err_exit; } + count -=MAX_REQUEST_SIZE ; + pos +=MAX_REQUEST_SIZE ; + segments_nr--; } - -if ((segments_nr >1 ) && last_segment_size) { - ret =archipelago_submit_request (s, i *MAX_REQUEST_SIZE , - last_segment_size, - offset + i *MAX_REQUEST_SIZE , - aio_cb, segreq, op); - }else if ((segments_nr >1 ) && !last_segment_size) { - ret =archipelago_submit_request (s, i *MAX_REQUEST_SIZE , -MAX_REQUEST_SIZE , - offset + i *MAX_REQUEST_SIZE , - aio_cb, segreq, op); - }else if (segments_nr ==1 ) { - ret =archipelago_submit_request (s,0 , count, offset, aio_cb, - segreq, op); - } + ret =archipelago_submit_request (s, pos, count, offset + pos, + aio_cb, segreq, op);if (ret <0 ) { goto err_exit; } -return 0 ; err_exit: -__sync_add_and_fetch (&segreq->failed,1 ); -if (segments_nr ==1 ) { -if (__sync_add_and_fetch (&segreq->ref,-1 ) ==0 ) { -g_free (segreq); - } - }else { -if ((__sync_add_and_fetch (&segreq->ref, -segments_nr + i)) ==0 ) { -g_free (segreq); - } + segreq->failed =1 ; +if (atomic_fetch_sub (&segreq->ref, segments_nr) == segments_nr) { +g_free (segreq); } -return ret; }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 15/24] qemu-nbd: add option to set detect-zeroes mode
In reply to Stefan HajnocziFrom: Peter Lieven <[email protected]>
--- qemu-nbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
qemu-nbd.c +25 -0
@@ -18,11 +18,13 @@#include "qemu-common.h" #include "block/block.h" +#include "block/block_int.h" #include "block/nbd.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" #include "qemu/error-report.h" #include "block/snapshot.h" +#include "qapi/util.h" #include <stdarg.h> #include <stdio.h>
@@ -41,6 +43,7 @@#define QEMU_NBD_OPT_CACHE 1#define QEMU_NBD_OPT_AIO 2#define QEMU_NBD_OPT_DISCARD 3 +#define QEMU_NBD_OPT_DETECT_ZEROES 4static NBDExport *exp;static int verbose;
@@ -96,6 +99,8 @@ static void usage(const char *name)#ifdef CONFIG_LINUX_AIO " --aio=MODE set AIO mode (native or threads)\n" #endif +" --discard=MODE set discard mode (ignore, unmap)\n" +" --detect-zeroes=MODE set detect-zeroes mode (off, on, discard)\n" "\n" "Report bugs to <[email protected]>\n" , name, NBD_DEFAULT_PORT, "DEVICE");
@@ -410,6 +415,7 @@ int main(int argc, char **argv) { "aio", 1, NULL, QEMU_NBD_OPT_AIO }, #endif { "discard", 1, NULL, QEMU_NBD_OPT_DISCARD }, + { "detect-zeroes", 1, NULL, QEMU_NBD_OPT_DETECT_ZEROES }, { "shared", 1, NULL, 'e' }, { "format", 1, NULL, 'f' }, { "persistent", 0, NULL, 't' },
@@ -432,6 +438,7 @@ int main(int argc, char **argv)pthread_t client_thread;const char *fmt =NULL ;Error *local_err =NULL ; +BlockdevDetectZeroesOptions detect_zeroes =BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF ;/* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -483,6 +490,23 @@ int main(int argc, char **argv)errx (EXIT_FAILURE ,"Invalid discard mode `%s'" , optarg); }break ; +case QEMU_NBD_OPT_DETECT_ZEROES : + detect_zeroes = +qapi_enum_parse (BlockdevDetectZeroesOptions_lookup, + optarg, +BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX , +BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF , + &local_err); +if (local_err) { +errx (EXIT_FAILURE ,"Failed to parse detect_zeroes mode: %s" , +error_get_pretty (local_err)); + } +if (detect_zeroes ==BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP && + !(flags &BDRV_O_UNMAP )) { +errx (EXIT_FAILURE ,"setting detect-zeroes to unmap is not allowed " +"without setting discard operation to unmap" ); + } +break ;case 'b' : bindto = optarg;break ;
@@ -686,6 +710,7 @@ int main(int argc, char **argv) error_get_pretty(local_err)); } + bs->detect_zeroes = detect_zeroes; fd_size =bdrv_getlength (bs);if (partition !=-1 ) {
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 14/24] rename parse_enum_option to qapi_enum_parse and make it public
In reply to Stefan HajnocziFrom: Peter Lieven <[email protected]>
relaxing the license to LGPLv2+ is intentional.
--- blockdev.c | 30 ++++++------------------------ include/qapi/util.h | 17 +++++++++++++++++ qapi/Makefile.objs | 2 +- qapi/qapi-util.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 include/qapi/util.h create mode 100644 qapi/qapi-util.c
blockdev.c +6 -24
@@ -39,6 +39,7 @@#include "qapi/qmp/types.h" #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" +#include "qapi/util.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h"
@@ -274,25 +275,6 @@ static int parse_block_error_action(const char *buf, bool is_read, Error **errp) } } -static inline int parse_enum_option (const char *lookup[],const char *buf, -int max,int def,Error **errp) -{ -int i; - -if (!buf) { -return def; - } - -for (i =0 ; i < max; i++) { -if (!strcmp (buf, lookup[i])) { -return i; - } - } - -error_setg (errp,"invalid parameter value: %s" , buf); -return def; -} -static bool check_throttle_config (ThrottleConfig *cfg,Error **errp) {if (throttle_conflicting (cfg)) {
@@ -456,11 +438,11 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts, } detect_zeroes = -parse_enum_option (BlockdevDetectZeroesOptions_lookup, -qemu_opt_get (opts,"detect-zeroes" ), -BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX , -BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF , - &error); +qapi_enum_parse (BlockdevDetectZeroesOptions_lookup, +qemu_opt_get (opts,"detect-zeroes" ), +BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX , +BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF , + &error);if (error) {error_propagate (errp, error); goto early_err;
include/qapi/util.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* QAPI util functions +* +* Copyright Fujitsu, Inc. 2014 +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef QAPI_UTIL_H +#define QAPI_UTIL_H + +int qapi_enum_parse (const char *lookup[],const char *buf, +int max,int def,Error **errp); + +#endif
qapi/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ util-obj-y = qapi-visit-core.o qapi-dealloc-visitor.o qmp-input-visitor.o util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o - util-obj-y += opts-visitor.o util-obj-y += qmp-event.o +util-obj-y += qapi-util.o
qapi/qapi-util.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* QAPI util functions +* +* Authors: +* Hu Tao <[email protected]> +* Peter Lieven <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#include "qemu-common.h" +#include "qapi/error.h" +#include "qapi/util.h" + +int qapi_enum_parse (const char *lookup[],const char *buf, +int max,int def,Error **errp) +{ +int i; + +if (!buf) { +return def; + } + +for (i =0 ; i < max; i++) { +if (!strcmp (buf, lookup[i])) { +return i; + } + } + +error_setg (errp,"invalid parameter value: %s" , buf); +return def; +}
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 17/24] MAINTAINERS: update sheepdog maintainer
In reply to Stefan HajnocziFrom: MORITA Kazutaka <[email protected]>
Hitoshi takes over sheepdog maintenance from me.
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -980,7 +980,7 @@ S: Supported F: block/rbd.c Sheepdog -M: MORITA Kazutaka <[email protected]> +M: Hitoshi Mitake <[email protected]> M: Liu Yuan <[email protected]> L: [email protected] S: Supported
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 18/24] libqos: add a simple first-fit memory allocator
In reply to Stefan HajnocziFrom: John Snow <[email protected]>
Implement a simple first-fit memory allocator that attempts to keep track of leased blocks of memory in order to be able to re-use blocks.
Additionally, allow the user to specify when initializing the device that upon cleanup, we would like to assert that there are no blocks in use. This may be useful for identifying problems in qtests that use more complicated set-up and tear-down routines.
This functionality is used in my upcoming ahci-test v2 patch set, but I didn't see fit to enable it for any existing tests, which will continue to operate the same as they have prior.
--- tests/libqos/malloc-pc.c | 280 +++++++++++++++++++++++++++++++++++++++++++++-- tests/libqos/malloc-pc.h | 9 ++ 2 files changed, 279 insertions(+), 10 deletions(-)
tests/libqos/malloc-pc.c +270 -10
@@ -17,45 +17,294 @@#include "hw/nvram/fw_cfg.h" #include "qemu-common.h" +#include "qemu/queue.h" #include <glib.h> #define PAGE_SIZE (4096) +#define MLIST_ENTNAME entries +typedef QTAILQ_HEAD(MemList, MemBlock) MemList; +typedef struct MemBlock { +QTAILQ_ENTRY (MemBlock) MLIST_ENTNAME; +uint64_t size; +uint64_t addr; +}MemBlock ; +typedef struct PCAlloc {QGuestAllocator alloc; - +PCAllocOpts opts;uint64_t start;uint64_t end; + +MemList used; +MemList free; }PCAlloc ; -static uint64_t pc_alloc (QGuestAllocator *allocator,size_t size) +static MemBlock *mlist_new (uint64_t addr,uint64_t size) { -PCAlloc *s =container_of (allocator, PCAlloc, alloc); -uint64_t addr; +MemBlock *block; + +if (!size) { +return NULL ; + } + block =g_malloc0 (sizeof (MemBlock)); + block->addr = addr; + block->size = size; - size += (PAGE_SIZE -1 ); - size &= -PAGE_SIZE ; +return block; +} + +static void mlist_delete (MemList *list,MemBlock *node) +{ +g_assert (list && node); +QTAILQ_REMOVE (list, node,MLIST_ENTNAME ); +g_free (node); +} + +static MemBlock *mlist_find_key (MemList *head,uint64_t addr) +{ +MemBlock *node; + QTAILQ_FOREACH(node, head, MLIST_ENTNAME) { +if (node->addr == addr) { +return node; + } + } +return NULL ; +} + +static MemBlock *mlist_find_space (MemList *head,uint64_t size) +{ +MemBlock *node; + + QTAILQ_FOREACH(node, head, MLIST_ENTNAME) { +if (node->size >= size) { +return node; + } + } +return NULL ; +} + +static MemBlock *mlist_sort_insert (MemList *head,MemBlock *insr) +{ +MemBlock *node; +g_assert (head && insr); + + QTAILQ_FOREACH(node, head, MLIST_ENTNAME) { +if (insr->addr < node->addr) { +QTAILQ_INSERT_BEFORE (node, insr,MLIST_ENTNAME ); +return insr; + } + } + +QTAILQ_INSERT_TAIL (head, insr,MLIST_ENTNAME ); +return insr; +} + +static inline uint64_t mlist_boundary (MemBlock *node) +{ +return node->size + node->addr; +} + +static MemBlock *mlist_join (MemList *head,MemBlock *left,MemBlock *right) +{ +g_assert (head && left && right); + + left->size += right->size; +mlist_delete (head, right); +return left; +} + +static void mlist_coalesce (MemList *head,MemBlock *node) +{ +g_assert (node); +MemBlock *left; +MemBlock *right; +char merge; + +do { + merge =0 ; + left =QTAILQ_PREV (node, MemList,MLIST_ENTNAME ); + right =QTAILQ_NEXT (node,MLIST_ENTNAME ); + +/* clowns to the left of me */ +if (left &&mlist_boundary (left) == node->addr) { + node =mlist_join (head, left, node); + merge =1 ; + } + +/* jokers to the right */ +if (right &&mlist_boundary (node) == right->addr) { + node =mlist_join (head, node, right); + merge =1 ; + } + + }while (merge); +} + +static uint64_t pc_mlist_fulfill (PCAlloc *s,MemBlock *freenode,uint64_t size) +{ +uint64_t addr; +MemBlock *usednode; - g_assert_cmpint((s->start + size), <=, s->end); +g_assert (freenode); + g_assert_cmpint(freenode->size, >=, size); - addr = s->start; - s->start += size; + addr = freenode->addr; +if (freenode->size == size) { +/* re-use this freenode as our used node */ +QTAILQ_REMOVE (&s->free, freenode,MLIST_ENTNAME ); + usednode = freenode; + }else { +/* adjust the free node and create a new used node */ + freenode->addr += size; + freenode->size -= size; + usednode =mlist_new (addr, size); + } +mlist_sort_insert (&s->used, usednode);return addr; } +/* To assert the correctness of the list. +* Used only if PC_ALLOC_PARANOID is set. */ +static void pc_mlist_check (PCAlloc *s) +{ +MemBlock *node; +uint64_t addr = s->start >0 ? s->start -1 :0 ; +uint64_t next = s->start; + + QTAILQ_FOREACH(node, &s->free, MLIST_ENTNAME) { + g_assert_cmpint(node->addr, >, addr); + g_assert_cmpint(node->addr, >=, next); + addr = node->addr; + next = node->addr + node->size; + } + + addr = s->start >0 ? s->start -1 :0 ; + next = s->start; + QTAILQ_FOREACH(node, &s->used, MLIST_ENTNAME) { + g_assert_cmpint(node->addr, >, addr); + g_assert_cmpint(node->addr, >=, next); + addr = node->addr; + next = node->addr + node->size; + } +} + +static uint64_t pc_mlist_alloc (PCAlloc *s,uint64_t size) +{ +MemBlock *node; + + node =mlist_find_space (&s->free, size); +if (!node) { +fprintf (stderr,"Out of guest memory.\n" ); +g_assert_not_reached (); + } +return pc_mlist_fulfill (s, node, size); +} + +static void pc_mlist_free (PCAlloc *s,uint64_t addr) +{ +MemBlock *node; + +if (addr ==0 ) { +return ; + } + + node =mlist_find_key (&s->used, addr); +if (!node) { +fprintf (stderr,"Error: no record found for an allocation at " +"0x%016" PRIx64".\n" , + addr); +g_assert_not_reached (); + } + +/* Rip it out of the used list and re-insert back into the free list. */ +QTAILQ_REMOVE (&s->used, node,MLIST_ENTNAME ); +mlist_sort_insert (&s->free, node); +mlist_coalesce (&s->free, node); +} + +static uint64_t pc_alloc (QGuestAllocator *allocator,size_t size) +{ +PCAlloc *s =container_of (allocator, PCAlloc, alloc); +uint64_t rsize = size; +uint64_t naddr; + + rsize += (PAGE_SIZE -1 ); + rsize &= -PAGE_SIZE ; + g_assert_cmpint((s->start + rsize), <=, s->end); + g_assert_cmpint(rsize, >=, size); + + naddr =pc_mlist_alloc (s, rsize); +if (s->opts &PC_ALLOC_PARANOID ) { +pc_mlist_check (s); + } + +return naddr; +} +static void pc_free (QGuestAllocator *allocator,uint64_t addr) { +PCAlloc *s =container_of (allocator, PCAlloc, alloc); + +pc_mlist_free (s, addr); +if (s->opts &PC_ALLOC_PARANOID ) { +pc_mlist_check (s); + } +} + +/* +* Mostly for valgrind happiness, but it does offer +* a chokepoint for debugging guest memory leaks, too. +*/ +void pc_alloc_uninit (QGuestAllocator *allocator) +{ +PCAlloc *s =container_of (allocator, PCAlloc, alloc); +MemBlock *node; +MemBlock *tmp; +PCAllocOpts mask; + +/* Check for guest leaks, and destroy the list. */ + QTAILQ_FOREACH_SAFE(node, &s->used, MLIST_ENTNAME, tmp) { +if (s->opts & (PC_ALLOC_LEAK_WARN |PC_ALLOC_LEAK_ASSERT )) { +fprintf (stderr,"guest malloc leak @ 0x%016" PRIx64"; " +"size 0x%016" PRIx64".\n" , + node->addr, node->size); + } +if (s->opts & (PC_ALLOC_LEAK_ASSERT )) { +g_assert_not_reached (); + } +g_free (node); + } + +/* If we have previously asserted that there are no leaks, then there +* should be only one node here with a specific address and size. */ + mask =PC_ALLOC_LEAK_ASSERT |PC_ALLOC_PARANOID ; + QTAILQ_FOREACH_SAFE(node, &s->free, MLIST_ENTNAME, tmp) { +if ((s->opts & mask) == mask) { +if ((node->addr != s->start) || + (node->size != s->end - s->start)) { +fprintf (stderr,"Free list is corrupted.\n" ); +g_assert_not_reached (); + } + } + +g_free (node); + } + +g_free (s); } -QGuestAllocator *pc_alloc_init (void ) +QGuestAllocator *pc_alloc_init_flags (PCAllocOpts flags) {PCAlloc *s =g_malloc0 (sizeof (*s));uint64_t ram_size;QFWCFG *fw_cfg =pc_fw_cfg_init (); +MemBlock *node; + s->opts = flags; s->alloc.alloc = pc_alloc; s->alloc.free = pc_free;
@@ -70,5 +319,16 @@ QGuestAllocator *pc_alloc_init(void)/* clean-up */ g_free (fw_cfg); +QTAILQ_INIT (&s->used); +QTAILQ_INIT (&s->free); + + node =mlist_new (s->start, s->end - s->start); +QTAILQ_INSERT_HEAD (&s->free, node,MLIST_ENTNAME ); +return &s->alloc; } + +inline QGuestAllocator *pc_alloc_init (void ) +{ +return pc_alloc_init_flags (PC_ALLOC_NO_FLAGS ); +}
tests/libqos/malloc-pc.h +9 -0
@@ -15,6 +15,15 @@#include "libqos/malloc.h" +typedef enum { +PC_ALLOC_NO_FLAGS =0x00 , +PC_ALLOC_LEAK_WARN =0x01 , +PC_ALLOC_LEAK_ASSERT =0x02 , +PC_ALLOC_PARANOID =0x04 +}PCAllocOpts ; +QGuestAllocator *pc_alloc_init (void ); +QGuestAllocator *pc_alloc_init_flags (PCAllocOpts flags); +void pc_alloc_uninit (QGuestAllocator *allocator);#endif
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 19/24] qtest/ide: Uninitialize PC allocator
In reply to Stefan HajnocziFrom: John Snow <[email protected]>
Use the new call to pc_alloc_uninit as a test for the new pathways.
The leak checking / assert pathways are not enabled in this patch, leaving this as an option to future test writers.
--- tests/ide-test.c | 2 ++ 1 file changed, 2 insertions(+)
tests/ide-test.c +2 -0
@@ -126,6 +126,8 @@ static void ide_test_start(const char *cmdline_fmt, ...)static void ide_test_quit (void ) { +pc_alloc_uninit (guest_malloc); + guest_malloc =NULL ;qtest_end (); }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 21/24] vmdk: fix vmdk_parse_extents() extent_file leaks
In reply to Stefan Hajnoczi--- block/vmdk.c | 2 ++ 1 file changed, 2 insertions(+)
block/vmdk.c +2 -0
@@ -834,6 +834,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, ret =vmdk_add_extent (bs, extent_file, true, sectors,0 ,0 ,0 ,0 ,0 , &extent, errp);if (ret <0 ) { +bdrv_unref (extent_file);return ret; } extent->flat_start_offset = flat_offset <<9 ;
@@ -853,6 +854,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, extent = &s->extents[s->num_extents -1 ]; }else {error_setg (errp,"Unsupported extent type '%s'" , type); +bdrv_unref (extent_file);return -ENOTSUP ; } extent->type =g_strdup (type);
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 20/24] ide: Add wwn support to IDE-ATAPI drive
In reply to Stefan HajnocziFrom: John Snow <[email protected]>
Although it is possible to specify the wwn property for cdrom devices on the command line, the underlying driver fails to relay this information to the guest operating system via IDENTIFY.
This is a simple patch to correct that.
See ATA8-ACS, Table 22 parts 5, 6, and 9.
--- hw/ide/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/ide/core.c +14 -0
@@ -230,9 +230,23 @@ static void ide_atapi_identify(IDEState *s) }put_le16 (p +80 ,0x1e );/* support up to ATA/ATAPI-4 */ +if (s->wwn) { +put_le16 (p +84 , (1 <<8 ));/* supports WWN for words 108-111 */ +put_le16 (p +87 , (1 <<8 ));/* WWN enabled */ + } +#ifdef USE_DMA_CDROM put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */ #endif + +if (s->wwn) { +/* LE 16-bit words 111-108 contain 64-bit World Wide Name */ +put_le16 (p +108 , s->wwn >>48 ); +put_le16 (p +109 , s->wwn >>32 ); +put_le16 (p +110 , s->wwn >>16 ); +put_le16 (p +111 , s->wwn); + } +memcpy (s->identify_data, p,sizeof (s->identify_data)); s->identify_set =1 ; }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 22/24] vmdk: fix buf leak in vmdk_parse_extents()
In reply to Stefan Hajnoczivmdk_open_sparse() does not take ownership of buf so the caller always needs to free it.
--- block/vmdk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/vmdk.c +1 -1
@@ -846,8 +846,8 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, }else { ret =vmdk_open_sparse (bs, extent_file, bs->open_flags, buf, errp); } +g_free (buf);if (ret) { -g_free (buf);bdrv_unref (extent_file);return ret; }
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 23/24] IDE: Fill the IDENTIFY request consistently
In reply to Stefan HajnocziFrom: John Snow <[email protected]>
IDE-HD, IDE-ATAPI and IDE-CFATA all fill the identify buffer in slightly different ways, this is a relatively minor patch to make them uniform, to emphasize that:
(1) We build the s->identify_data cache first, then
(2) We copy it to s->io_buffer to fulfill the request.
--- hw/ide/core.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
hw/ide/core.c +15 -13
@@ -81,13 +81,12 @@ static void ide_identify(IDEState *s)unsigned int oldsize;IDEDevice *dev = s->unit ? s->bus->slave : s->bus->master; + p = (uint16_t *)s->identify_data;if (s->identify_set) { -memcpy (s->io_buffer, s->identify_data,sizeof (s->identify_data)); -return ; + goto fill_buffer; } +memset (p,0 ,sizeof (s->identify_data)); -memset (s->io_buffer,0 ,512 ); - p = (uint16_t *)s->io_buffer;put_le16 (p +0 ,0x0040 );put_le16 (p +1 , s->cylinders);put_le16 (p +3 , s->heads);
@@ -180,21 +179,22 @@ static void ide_identify(IDEState *s)put_le16 (p +169 ,1 );/* TRIM support */ } -memcpy (s->identify_data, p,sizeof (s->identify_data)); s->identify_set =1 ; + +fill_buffer: +memcpy (s->io_buffer, p,sizeof (s->identify_data)); }static void ide_atapi_identify (IDEState *s) {uint16_t *p; + p = (uint16_t *)s->identify_data;if (s->identify_set) { -memcpy (s->io_buffer, s->identify_data,sizeof (s->identify_data)); -return ; + goto fill_buffer; } +memset (p,0 ,sizeof (s->identify_data)); -memset (s->io_buffer,0 ,512 ); - p = (uint16_t *)s->io_buffer;/* Removable CDROM, 50us response, 12 byte packets */ put_le16 (p +0 , (2 <<14 ) | (5 <<8 ) | (1 <<7 ) | (2 <<5 ) | (0 <<0 ));padstr ((char *)(p +10 ), s->drive_serial_str,20 );/* serial number */
@@ -247,8 +247,10 @@ static void ide_atapi_identify(IDEState *s)put_le16 (p +111 , s->wwn); } -memcpy (s->identify_data, p,sizeof (s->identify_data)); s->identify_set =1 ; + +fill_buffer: +memcpy (s->io_buffer, p,sizeof (s->identify_data)); }static void ide_cfata_identify (IDEState *s)
@@ -256,10 +258,10 @@ static void ide_cfata_identify(IDEState *s)uint16_t *p;uint32_t cur_sec; - p = (uint16_t *) s->identify_data; -if (s->identify_set) + p = (uint16_t *)s->identify_data; +if (s->identify_set) { goto fill_buffer; - + }memset (p,0 ,sizeof (s->identify_data)); cur_sec = s->cylinders * s->heads * s->sectors;
Signature · 1 line
1.9.3
[Qemu-devel] [PULL 24/24] ide: Add resize callback to ide/core
In reply to Stefan HajnocziFrom: John Snow <[email protected]>
Currently, if the block device backing the IDE drive is resized, the information about the device as cached inside of the IDEState structure is not updated, thus when a guest OS re-queries the drive, it is unable to see the expanded size.
This patch adds a resize callback that updates the IDENTIFY data buffer in order to correct this.
Lastly, a Linux guest as-is cannot resize a libata drive while in-use, but it can see the expanded size as part of a bus rescan event. This patch also allows guests such as Linux to see the new drive size after a soft reboot event, without having to exit the QEMU process.
--- hw/ide/core.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 10 deletions(-)
hw/ide/core.c +59 -10
@@ -75,6 +75,17 @@ static void put_le16(uint16_t *p, unsigned int v) *p =cpu_to_le16 (v); } +static void ide_identify_size (IDEState *s) +{ +uint16_t *p = (uint16_t *)s->identify_data; +put_le16 (p +60 , s->nb_sectors); +put_le16 (p +61 , s->nb_sectors >>16 ); +put_le16 (p +100 , s->nb_sectors); +put_le16 (p +101 , s->nb_sectors >>16 ); +put_le16 (p +102 , s->nb_sectors >>32 ); +put_le16 (p +103 , s->nb_sectors >>48 ); +} +static void ide_identify (IDEState *s) {uint16_t *p;
@@ -115,8 +126,8 @@ static void ide_identify(IDEState *s)put_le16 (p +58 , oldsize >>16 );if (s->mult_sectors)put_le16 (p +59 ,0x100 | s->mult_sectors); -put_le16 (p +60 , s->nb_sectors); -put_le16 (p +61 , s->nb_sectors >>16 ); +/* *(p + 60) := nb_sectors -- see ide_identify_size */ +/* *(p + 61) := nb_sectors >> 16 -- see ide_identify_size */ put_le16 (p +62 ,0x07 );/* single word dma0-2 supported */ put_le16 (p +63 ,0x07 );/* mdma0-2 supported */ put_le16 (p +64 ,0x03 );/* pio3-4 supported */
@@ -161,10 +172,10 @@ static void ide_identify(IDEState *s) }put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */ put_le16 (p +93 ,1 | (1 <<14 ) |0x2000 ); -put_le16 (p +100 , s->nb_sectors); -put_le16 (p +101 , s->nb_sectors >>16 ); -put_le16 (p +102 , s->nb_sectors >>32 ); -put_le16 (p +103 , s->nb_sectors >>48 ); +/* *(p + 100) := nb_sectors -- see ide_identify_size */ +/* *(p + 101) := nb_sectors >> 16 -- see ide_identify_size */ +/* *(p + 102) := nb_sectors >> 32 -- see ide_identify_size */ +/* *(p + 103) := nb_sectors >> 48 -- see ide_identify_size */ if (dev && dev->conf.physical_block_size)put_le16 (p +106 ,0x6000 |get_physical_block_exp (&dev->conf));
@@ -179,6 +190,7 @@ static void ide_identify(IDEState *s)put_le16 (p +169 ,1 );/* TRIM support */ } +ide_identify_size (s); s->identify_set =1 ; fill_buffer:
@@ -253,6 +265,15 @@ fill_buffer:memcpy (s->io_buffer, p,sizeof (s->identify_data)); } +static void ide_cfata_identify_size (IDEState *s) +{ +uint16_t *p = (uint16_t *)s->identify_data; +put_le16 (p +7 , s->nb_sectors >>16 );/* Sectors per card */ +put_le16 (p +8 , s->nb_sectors);/* Sectors per card */ +put_le16 (p +60 , s->nb_sectors);/* Total LBA sectors */ +put_le16 (p +61 , s->nb_sectors >>16 );/* Total LBA sectors */ +} +static void ide_cfata_identify (IDEState *s) {uint16_t *p;
@@ -270,8 +291,8 @@ static void ide_cfata_identify(IDEState *s)put_le16 (p +1 , s->cylinders);/* Default cylinders */ put_le16 (p +3 , s->heads);/* Default heads */ put_le16 (p +6 , s->sectors);/* Default sectors per track */ -put_le16 (p +7 , s->nb_sectors >>16 );/* Sectors per card */ -put_le16 (p +8 , s->nb_sectors);/* Sectors per card */ +/* *(p + 7) := nb_sectors >> 16 -- see ide_cfata_identify_size */ +/* *(p + 8) := nb_sectors -- see ide_cfata_identify_size */ padstr ((char *)(p +10 ), s->drive_serial_str,20 );/* serial number */ put_le16 (p +22 ,0x0004 );/* ECC bytes */ padstr ((char *) (p +23 ), s->version,8 );/* Firmware Revision */
@@ -292,8 +313,8 @@ static void ide_cfata_identify(IDEState *s)put_le16 (p +58 , cur_sec >>16 );/* Current capacity */ if (s->mult_sectors)/* Multiple sector setting */ put_le16 (p +59 ,0x100 | s->mult_sectors); -put_le16 (p +60 , s->nb_sectors);/* Total LBA sectors */ -put_le16 (p +61 , s->nb_sectors >>16 );/* Total LBA sectors */ +/* *(p + 60) := nb_sectors -- see ide_cfata_identify_size */ +/* *(p + 61) := nb_sectors >> 16 -- see ide_cfata_identify_size */ put_le16 (p +63 ,0x0203 );/* Multiword DMA capability */ put_le16 (p +64 ,0x0001 );/* Flow Control PIO support */ put_le16 (p +65 ,0x0096 );/* Min. Multiword DMA cycle */
@@ -313,6 +334,7 @@ static void ide_cfata_identify(IDEState *s)put_le16 (p +160 ,0x8100 );/* Power requirement */ put_le16 (p +161 ,0x8001 );/* CF command set */ +ide_cfata_identify_size (s); s->identify_set =1 ; fill_buffer:
@@ -2131,6 +2153,28 @@ static bool ide_cd_is_medium_locked(void *opaque)return ((IDEState *)opaque)->tray_locked; } +static void ide_resize_cb (void *opaque) +{ +IDEState *s = opaque; +uint64_t nb_sectors; + +if (!s->identify_set) { +return ; + } + +bdrv_get_geometry (s->bs, &nb_sectors); + s->nb_sectors = nb_sectors; + +/* Update the identify data buffer. */ +if (s->drive_kind ==IDE_CFATA ) { +ide_cfata_identify_size (s); + }else { +/* IDE_CD uses a different set of callbacks entirely. */ +assert (s->drive_kind !=IDE_CD ); +ide_identify_size (s); + } +} +static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, .eject_request_cb = ide_cd_eject_request_cb,
@@ -2138,6 +2182,10 @@ static const BlockDevOps ide_cd_block_ops = { .is_medium_locked = ide_cd_is_medium_locked, }; +static const BlockDevOps ide_hd_block_ops = { + .resize_cb = ide_resize_cb, +}; + int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, const char *version, const char *serial, const char *model, uint64_t wwn,
@@ -2174,6 +2222,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,error_report ("Can't use a read-only drive" );return -1 ; } +bdrv_set_dev_ops (bs, &ide_hd_block_ops, s); }if (serial) {pstrcpy (s->drive_serial_str,sizeof (s->drive_serial_str), serial);
Signature · 1 line
1.9.3
Peter Maydell
AppliedQuoted 7 lines · Stefan Hajnoczi
v2:
* Dropped Fam's dataplane virtio header patches that break win32 build [Peter]The following changes since commit
f102f224556f292f55b6e25147741bb8c48c9451:Merge remote-tracking branch 'remotes/afaerber/tags/qom-cpu-for-peter' into staging (2014-09-05 16:03:56 +0100)
Quoted 9 lines
are available in the git repository at:
git://github.com/stefanha/qemu.gittags/block-pull-requestfor you to fetch changes up to
01ce352e62c3f86df6f4ad32c3ab9353e55af799:ide: Add resize callback to ide/core (2014-09-08 11:12:44 +0100)
Applied, thanks.
-- PMM