Re: [Qemu-devel] [PATCH v9 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap
about naming: We will need functions for set/unset a subregion of BdrvDirtyBitmap, to fix migration and mirror (accordingly to my [PATCH v2] block: fix spoiling all dirty bitmaps by mirror and migration). Having the function 'bdrv_reset_dirty_bitmap' from this patch, we'll have to add functions like bdrv_set_dirty_bitmap_region and bdrv_reset_dirty_bitmap_region But, may be, it is more consistent to have bdrv_set_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, uint64_t start, uint64_t count) bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, uint64_t start, uint64_t count) for more transparent access to underlaying hbitmap interface? And then, name the considered function like 'bdrv_clear_dirty_bitmap'? Best regards, Vladimir On 01.12.2014 23:30, John Snow wrote: bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
Re: [Qemu-devel] [Qemu-trivial] [PATCH 0/2] acpi-build: trivial fixes
13.11.2014 05:59, arei.gong...@huawei.com wrote: Gonglei (2): acpi-build: adjust indention 8 - 4 spaces acpi-build: Make DPRINTF working for acpi-build Applied both to -trivial, thank you! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH] virtio-bus: avoid breaking build when open DEBUG switch
Applied to -trivial as is, for now, since the fixes are necessary anyway. Good suggestion by Stefan, to turn it into constant-depending always-compilable code stands, but it is not a show-stopper for the actual fix. Thanks, /mnt
Re: [Qemu-devel] [v2 2/2] migration: Implement multiple compression threads
## { 'enum': 'MigrationCapability', - 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks'] } + 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', + 'compress'] } I'll repeat what I said on v1 (but this time, with some links to back it up :) We really need to avoid a proliferation of new commands, two per tunable does not scale well. I think now is the time to implement my earlier suggestion at making MigrationCapability become THE resource for tunables: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg02274.html Hi Eric, I tried to follow your suggestion to implement a back-compat method to reuse the 'migrate-set-capabilities' and 'query-migrate-capabilities' , I found that I should change a lot of current code to make it work, and I don’t know how to deal with the HMP interface. So I add 'migrate-set-parameter' and 'query-migrate-parameter' interface to reduce the migrate-tunable commands, they can deal with all the 'int' type parameter, now the ' compress-threads' ' , 'decompress-threads', and 'compress-level' and be set/queried with the two interfaces. { 'enum': 'MigrationParameter', 'data': ['compress-level', 'compress-threads', 'decompress-threads'] } { 'type': 'MigrationParameterStatus', 'data': { 'parameter' : 'MigrationParameter', 'value' : 'int' } } I am not sure if it's a good solution, but it's much more simple, and it can minimize the change of current code. Is that OK? Hi Eric, What do you think about this solution? Liang
Re: [Qemu-devel] [Qemu-trivial] [PATCH] usb: delete redundant brackets in usb_host_handle_control()
19.11.2014 10:09, Fam Zheng wrote: On Wed, 11/19 14:57, Jun Li wrote: When see usb codes, find there are redundant brackets !((udev-port-speedmask USB_SPEED_MASK_SUPER)) here. So delete it. Applied to -trivial, thank you! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH] Drop superfluous conditionals around qemu_opts_del()
Applied to -trivial, thank you! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH] Drop superfluous conditionals around g_strdup()
Applied to -trivial, thanks! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH 0/3] util: Trivial cleanups around g_malloc()
04.12.2014 17:00, Markus Armbruster wrote: Markus Armbruster (3): util: Drop superfluous conditionals around g_free() Fuse g_malloc(); memset() into g_new0() util: Use g_new() friends where that makes obvious sense Applied to trivial (fixing 2/3 subject prefix), thank you! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH for-2.3] configure: Replace which(1) with has
04.12.2014 09:18, Fam Zheng wrote: Using has is more slick because which(1) is not always there. Applied to -trivial, thank you! /mjt
Re: [Qemu-devel] [PATCH 4/4] virtio-blk: introduce multiread
On Tue, 12/09 17:26, Peter Lieven wrote: diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 3f2652f..0ee9582 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -134,13 +134,6 @@ typedef struct VirtIOBlock { struct VirtIOBlockDataPlane *dataplane; } VirtIOBlock; -#define VIRTIO_BLK_MAX_MERGE_REQS 32 - -typedef struct MultiReqBuffer { -BlockRequestblkreq[VIRTIO_BLK_MAX_MERGE_REQS]; -unsigned intnum_writes; -} MultiReqBuffer; - typedef struct VirtIOBlockReq { VirtIOBlock *dev; VirtQueueElement elem; @@ -149,8 +142,21 @@ typedef struct VirtIOBlockReq { QEMUIOVector qiov; struct VirtIOBlockReq *next; BlockAcctCookie acct; +QEMUIOVector mr_qiov; +struct VirtIOBlockReq *mr_next; } VirtIOBlockReq; +#define MAX_MERGE_REQS 32 Why do you need to rename this macro after introducing it in previous patch? + +typedef struct MultiReqBuffer { +VirtIOBlockReq *reqs[MAX_MERGE_REQS]; +unsigned int num_reqs; +bool is_write; +int niov; +int64_t sector_num; +int nb_sectors; +} MultiReqBuffer; + VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s); void virtio_blk_free_request(VirtIOBlockReq *req); @@ -160,6 +166,6 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk, void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb); -void virtio_submit_multiwrite(BlockBackend *blk, MultiReqBuffer *mrb); +void virtio_submit_multireq(BlockBackend *blk, MultiReqBuffer *mrb); #endif
[Qemu-devel] [PATCH v7 0/7] Netduino 2 Machine Model
This patch series adds the Netduino 2 Machine to QEMU Information on the board is avalible at: http://www.netduino.com/netduino2/specs.htm The git tree can be found at: https://github.com/alistair23/qemu/tree/netduino2.7 This patch series makes some changes to the armv7m_init function that allows the code to be reused with the Netduino 2 and the Stellaris machines. Some example code that runs on QEMU is avaliable at: at: https://github.com/alistair23/CSSE3010-QEMU-Examples There are more devices in the works, I figured I would just start with these three V7: - Rebase to QEMU 2.2 V6: - Rename the three devices to STM32FXX* - Correct the timer to use ns - Correct the number of devices that are inited - Rename memory regions V5: - Remove the reset changes based on the ELF entry V4: - Rebase - Correct timer units V3: - Correct the timer interrupts - Update debug printing - Remove the sram_size argument from armv7m_init Alistair Francis (7): stm32f2xx_timer: Add the stm32f2xx Timer stm32f2xx_USART: Add the stm32f2xx USART Controller stm32f2xx_SYSCFG: Add the stm32f2xx SYSCFG target_arm: Remove memory region init from armv7m_init target_arm: Parameterise the irq lines for armv7m_init stm32f205: Add the stm32f205 SoC netduino2: Add the Netduino 2 Machine default-configs/arm-softmmu.mak| 4 + hw/arm/Makefile.objs | 2 + hw/arm/armv7m.c| 38 + hw/arm/netduino2.c | 54 ++ hw/arm/stellaris.c | 27 ++- hw/arm/stm32f205_soc.c | 157 ++ hw/char/Makefile.objs | 1 + hw/char/stm32f2xx_usart.c | 219 hw/misc/Makefile.objs | 1 + hw/misc/stm32f2xx_syscfg.c | 160 ++ hw/timer/Makefile.objs | 2 + hw/timer/stm32f2xx_timer.c | 331 + include/hw/arm/arm.h | 3 +- include/hw/arm/stm32f205_soc.h | 69 include/hw/char/stm32f2xx_usart.h | 69 include/hw/misc/stm32f2xx_syscfg.h | 61 +++ include/hw/timer/stm32f2xx_timer.h | 101 +++ 17 files changed, 1261 insertions(+), 38 deletions(-) create mode 100644 hw/arm/netduino2.c create mode 100644 hw/arm/stm32f205_soc.c create mode 100644 hw/char/stm32f2xx_usart.c create mode 100644 hw/misc/stm32f2xx_syscfg.c create mode 100644 hw/timer/stm32f2xx_timer.c create mode 100644 include/hw/arm/stm32f205_soc.h create mode 100644 include/hw/char/stm32f2xx_usart.h create mode 100644 include/hw/misc/stm32f2xx_syscfg.h create mode 100644 include/hw/timer/stm32f2xx_timer.h -- 2.1.0
[Qemu-devel] [PATCH v7 2/7] stm32f2xx_USART: Add the stm32f2xx USART Controller
This patch adds the stm32f2xx USART controller (UART also uses the same controller). Signed-off-by: Alistair Francis alistai...@gmail.com --- V6: - Rename to STM32F2XX - Fix up unimplemented printing - Add a qemu_chr_accept() V3: - Update debug printing V2: - Drop charecters if the device is not enabled - Thanks to Peter C default-configs/arm-softmmu.mak | 1 + hw/char/Makefile.objs | 1 + hw/char/stm32f2xx_usart.c | 219 ++ include/hw/char/stm32f2xx_usart.h | 69 4 files changed, 290 insertions(+) create mode 100644 hw/char/stm32f2xx_usart.c create mode 100644 include/hw/char/stm32f2xx_usart.h diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index faea100..1348104 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -79,6 +79,7 @@ CONFIG_REALVIEW=y CONFIG_ZAURUS=y CONFIG_ZYNQ=y CONFIG_STM32F2XX_TIMER=y +CONFIG_STM32F2XX_USART=y CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs index 317385d..5931cc8 100644 --- a/hw/char/Makefile.objs +++ b/hw/char/Makefile.objs @@ -15,6 +15,7 @@ obj-$(CONFIG_OMAP) += omap_uart.o obj-$(CONFIG_SH4) += sh_serial.o obj-$(CONFIG_PSERIES) += spapr_vty.o obj-$(CONFIG_DIGIC) += digic-uart.o +obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c new file mode 100644 index 000..843ff4a --- /dev/null +++ b/hw/char/stm32f2xx_usart.c @@ -0,0 +1,219 @@ +/* + * STM32F2XX USART + * + * Copyright (c) 2014 Alistair Francis alist...@alistair23.me + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include hw/char/stm32f2xx_usart.h + +#ifndef STM_USART_ERR_DEBUG +#define STM_USART_ERR_DEBUG 0 +#endif + +#define DB_PRINT_L(lvl, fmt, args...) do { \ +if (STM_USART_ERR_DEBUG = lvl) { \ +qemu_log(%s: fmt, __func__, ## args); \ +} \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +static int stm32f2xx_usart_can_receive(void *opaque) +{ +STM32F2XXUsartState *s = opaque; + +if (!(s-usart_sr USART_SR_RXNE)) { +return 1; +} + +return 0; +} + +static void stm32f2xx_usart_receive(void *opaque, const uint8_t *buf, int size) +{ +STM32F2XXUsartState *s = opaque; + +s-usart_dr = *buf; + +if (!(s-usart_cr1 USART_CR1_UE s-usart_cr1 USART_CR1_RE)) { +/* USART not enabled - drop the chars */ +DB_PRINT(Dropping the chars\n); +return; +} + +s-usart_sr |= USART_SR_RXNE; + +if (s-usart_cr1 USART_CR1_RXNEIE) { +qemu_set_irq(s-irq, 1); +} + +DB_PRINT(Receiving: %c\n, s-usart_dr); +} + +static void stm32f2xx_usart_reset(DeviceState *dev) +{ +STM32F2XXUsartState *s = STM32F2XX_USART(dev); + +s-usart_sr = USART_SR_RESET; +s-usart_dr = 0x; +s-usart_brr = 0x; +s-usart_cr1 = 0x; +s-usart_cr2 = 0x; +s-usart_cr3 = 0x; +s-usart_gtpr = 0x; +} + +static uint64_t stm32f2xx_usart_read(void *opaque, hwaddr addr, + unsigned int size) +{ +STM32F2XXUsartState *s = opaque; +uint64_t retvalue; + +DB_PRINT(Read 0x%HWADDR_PRIx\n, addr); + +switch (addr) { +case USART_SR: +retvalue = s-usart_sr; +s-usart_sr = ~USART_SR_TC; +if (s-chr) { +qemu_chr_accept_input(s-chr); +} +return retvalue; +case USART_DR: +DB_PRINT(Value: 0x% PRIx32 , %c\n, s-usart_dr, (char) s-usart_dr); +s-usart_sr |= USART_SR_TXE; +s-usart_sr = ~USART_SR_RXNE; +if (s-chr) { +qemu_chr_accept_input(s-chr); +} +return s-usart_dr 0x3FF; +case USART_BRR: +return
[Qemu-devel] [PATCH v7 3/7] stm32f2xx_SYSCFG: Add the stm32f2xx SYSCFG
This patch adds the stm32f2xx System Configuration Controller. This is used to configure what memory is mapped at address 0 (although that is not supported) as well as configure how the EXTI interrupts work (also not supported at the moment). This device is not required for basic examples, but more complex systems will require it (as well as the EXTI device) Signed-off-by: Alistair Francis alistai...@gmail.com Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com --- V6: - Rename to STM32F2XX - Remove all casts from debug printing V5: - Correct the masks used for writing V3: - Update debug printing default-configs/arm-softmmu.mak| 1 + hw/misc/Makefile.objs | 1 + hw/misc/stm32f2xx_syscfg.c | 160 + include/hw/misc/stm32f2xx_syscfg.h | 61 ++ 4 files changed, 223 insertions(+) create mode 100644 hw/misc/stm32f2xx_syscfg.c create mode 100644 include/hw/misc/stm32f2xx_syscfg.h diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 1348104..a5aab7f 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -80,6 +80,7 @@ CONFIG_ZAURUS=y CONFIG_ZYNQ=y CONFIG_STM32F2XX_TIMER=y CONFIG_STM32F2XX_USART=y +CONFIG_STM32F2XX_SYSCFG=y CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 979e532..f2c0082 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -39,5 +39,6 @@ obj-$(CONFIG_OMAP) += omap_sdrc.o obj-$(CONFIG_OMAP) += omap_tap.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o +obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o obj-$(CONFIG_PVPANIC) += pvpanic.o diff --git a/hw/misc/stm32f2xx_syscfg.c b/hw/misc/stm32f2xx_syscfg.c new file mode 100644 index 000..4ae4042 --- /dev/null +++ b/hw/misc/stm32f2xx_syscfg.c @@ -0,0 +1,160 @@ +/* + * STM32F2XX SYSCFG + * + * Copyright (c) 2014 Alistair Francis alist...@alistair23.me + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include hw/misc/stm32f2xx_syscfg.h + +#ifndef STM_SYSCFG_ERR_DEBUG +#define STM_SYSCFG_ERR_DEBUG 0 +#endif + +#define DB_PRINT_L(lvl, fmt, args...) do { \ +if (STM_SYSCFG_ERR_DEBUG = lvl) { \ +qemu_log(%s: fmt, __func__, ## args); \ +} \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +static void stm32f2xx_syscfg_reset(DeviceState *dev) +{ +STM32F2XXSyscfgState *s = STM32F2XX_SYSCFG(dev); + +s-syscfg_memrmp = 0x; +s-syscfg_pmc = 0x; +s-syscfg_exticr1 = 0x; +s-syscfg_exticr2 = 0x; +s-syscfg_exticr3 = 0x; +s-syscfg_exticr4 = 0x; +s-syscfg_cmpcr = 0x; +} + +static uint64_t stm32f2xx_syscfg_read(void *opaque, hwaddr addr, + unsigned int size) +{ +STM32F2XXSyscfgState *s = opaque; + +DB_PRINT(0x%HWADDR_PRIx\n, addr); + +switch (addr) { +case SYSCFG_MEMRMP: +return s-syscfg_memrmp; +case SYSCFG_PMC: +return s-syscfg_pmc; +case SYSCFG_EXTICR1: +return s-syscfg_exticr1; +case SYSCFG_EXTICR2: +return s-syscfg_exticr2; +case SYSCFG_EXTICR3: +return s-syscfg_exticr3; +case SYSCFG_EXTICR4: +return s-syscfg_exticr4; +case SYSCFG_CMPCR: +return s-syscfg_cmpcr; +default: +qemu_log_mask(LOG_GUEST_ERROR, + %s: Bad offset 0x%HWADDR_PRIx\n, __func__, addr); +return 0; +} + +return 0; +} + +static void stm32f2xx_syscfg_write(void *opaque, hwaddr addr, + uint64_t val64, unsigned int size) +{ +STM32F2XXSyscfgState *s = opaque; +uint32_t value = val64; + +DB_PRINT(0x%x, 0x%HWADDR_PRIx\n, value, addr); + +switch (addr) { +case SYSCFG_MEMRMP: +qemu_log_mask(LOG_UNIMP, + %s: Changeing the memory
[Qemu-devel] [PATCH v7 7/7] netduino2: Add the Netduino 2 Machine
This patch adds the Netduino 2 Machine. This is a Cortex-M3 based machine. Information can be found at: http://www.netduino.com/netduino2/specs.htm Signed-off-by: Alistair Francis alistai...@gmail.com --- hw/arm/Makefile.objs | 1 + hw/arm/netduino2.c | 54 2 files changed, 55 insertions(+) create mode 100644 hw/arm/netduino2.c diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs index 9769317..2577f68 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -3,6 +3,7 @@ obj-$(CONFIG_DIGIC) += digic_boards.o obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o +obj-y += netduino2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-$(CONFIG_DIGIC) += digic.o diff --git a/hw/arm/netduino2.c b/hw/arm/netduino2.c new file mode 100644 index 000..305983f --- /dev/null +++ b/hw/arm/netduino2.c @@ -0,0 +1,54 @@ +/* + * Netduino 2 Machine Model + * + * Copyright (c) 2014 Alistair Francis alist...@alistair23.me + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include hw/arm/stm32f205_soc.h + +static void netduino2_init(MachineState *machine) +{ +DeviceState *dev; +Error *err = NULL; + +dev = qdev_create(NULL, TYPE_STM32F205_SOC); +if (machine-kernel_filename) { +qdev_prop_set_string(dev, kernel-filename, machine-kernel_filename); +} +object_property_set_bool(OBJECT(dev), true, realized, err); +if (err != NULL) { +error_report(%s, error_get_pretty(err)); +exit(1); +} +} + +static QEMUMachine netduino2_machine = { +.name = netduino2, +.desc = Netduino 2 Machine, +.init = netduino2_init, +}; + +static void netduino2_machine_init(void) +{ +qemu_register_machine(netduino2_machine); +} + +machine_init(netduino2_machine_init); -- 2.1.0
[Qemu-devel] [PATCH v7 1/7] stm32f2xx_timer: Add the stm32f2xx Timer
This patch adds the stm32f2xx timers: TIM2, TIM3, TIM4 and TIM5 to QEMU. Signed-off-by: Alistair Francis alistai...@gmail.com --- V6: - Rename to STM32F2XX - Change the timer calculations to use ns - Update the value to timer_mod to ensure it is in ns - Account for reloadable/resetable timer - Thanks to Peter C for pointing this out V4: - Update timer units again - Thanks to Peter C V3: - Update debug statements - Correct the units for timer_mod - Correctly set timer_offset from resets V2: - Reorder the Makefile config - Fix up the debug printing - Correct the timer event trigger default-configs/arm-softmmu.mak| 1 + hw/timer/Makefile.objs | 2 + hw/timer/stm32f2xx_timer.c | 331 + include/hw/timer/stm32f2xx_timer.h | 101 +++ 4 files changed, 435 insertions(+) create mode 100644 hw/timer/stm32f2xx_timer.c create mode 100644 include/hw/timer/stm32f2xx_timer.h diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index f3513fa..faea100 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -78,6 +78,7 @@ CONFIG_NSERIES=y CONFIG_REALVIEW=y CONFIG_ZAURUS=y CONFIG_ZYNQ=y +CONFIG_STM32F2XX_TIMER=y CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs index 2c86c3d..133bd0d 100644 --- a/hw/timer/Makefile.objs +++ b/hw/timer/Makefile.objs @@ -31,3 +31,5 @@ obj-$(CONFIG_DIGIC) += digic-timer.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o + +common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c new file mode 100644 index 000..df27540 --- /dev/null +++ b/hw/timer/stm32f2xx_timer.c @@ -0,0 +1,331 @@ +/* + * STM32F2XX Timer + * + * Copyright (c) 2014 Alistair Francis alist...@alistair23.me + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include hw/timer/stm32f2xx_timer.h + +#ifndef STM_TIMER_ERR_DEBUG +#define STM_TIMER_ERR_DEBUG 0 +#endif + +#define DB_PRINT_L(lvl, fmt, args...) do { \ +if (STM_TIMER_ERR_DEBUG = lvl) { \ +qemu_log(%s: fmt, __func__, ## args); \ +} \ +} while (0); + +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) + +static void stm32f2xx_timer_set_alarm(STM32F2XXTimerState *s); + +static void stm32f2xx_timer_interrupt(void *opaque) +{ +STM32F2XXTimerState *s = opaque; + +DB_PRINT(Interrupt\n); + +if (s-tim_dier TIM_DIER_UIE s-tim_cr1 TIM_CR1_CEN) { +s-tim_sr |= 1; +qemu_irq_pulse(s-irq); +stm32f2xx_timer_set_alarm(s); +} +} + +static void stm32f2xx_timer_set_alarm(STM32F2XXTimerState *s) +{ +uint32_t ticks; +int64_t now; + +DB_PRINT(Alarm set at: 0x%x\n, s-tim_cr1); + +now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); +ticks = s-tim_arr - +((muldiv64(s-freq_hz, now, 10ULL) - s-tick_offset) / +(s-tim_psc + 1)); + +DB_PRINT(Alarm set in %d ticks\n, ticks); + +if (ticks == 0) { +timer_del(s-timer); +stm32f2xx_timer_interrupt(s); +} else { +timer_mod(s-timer, now + + muldiv64(ticks, 10ULL, get_ticks_per_sec())); + +DB_PRINT(Wait Time: % PRId64 ticks\n, + now + muldiv64(ticks, 10ULL, get_ticks_per_sec())); +} +} + +static void stm32f2xx_timer_reset(DeviceState *dev) +{ +STM32F2XXTimerState *s = STM32F2XXTIMER(dev); + +s-tim_cr1 = 0; +s-tim_cr2 = 0; +s-tim_smcr = 0; +s-tim_dier = 0; +s-tim_sr = 0; +s-tim_egr = 0; +s-tim_ccmr1 = 0; +s-tim_ccmr2 = 0; +s-tim_ccer = 0; +s-tim_cnt = 0; +s-tim_psc = 0; +s-tim_arr = 0; +s-tim_ccr1 = 0; +s-tim_ccr2 = 0; +s-tim_ccr3 = 0; +s-tim_ccr4 = 0; +s-tim_dcr = 0; +s-tim_dmar = 0; +s-tim_or = 0; + +
[Qemu-devel] [PATCH v7 5/7] target_arm: Parameterise the irq lines for armv7m_init
This patch allows the board to specifiy the number of NVIC interrupt lines when using armv7m_init. Signed-off-by: Alistair Francis alistai...@gmail.com Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com --- hw/arm/armv7m.c | 7 --- hw/arm/stellaris.c | 5 - include/hw/arm/arm.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index 50281f7..7169027 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -166,14 +166,14 @@ static void armv7m_reset(void *opaque) mem_size is in bytes. Returns the NVIC array. */ -qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, +qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq, const char *kernel_filename, const char *cpu_model) { ARMCPU *cpu; CPUARMState *env; DeviceState *nvic; /* FIXME: make this local state. */ -static qemu_irq pic[64]; +qemu_irq *pic = g_new(qemu_irq, num_irq); int image_size; uint64_t entry; uint64_t lowaddr; @@ -194,11 +194,12 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, armv7m_bitband_init(); nvic = qdev_create(NULL, armv7m_nvic); +qdev_prop_set_uint32(nvic, num-irq, num_irq); env-nvic = nvic; qdev_init_nofail(nvic); sysbus_connect_irq(SYS_BUS_DEVICE(nvic), 0, qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ)); -for (i = 0; i 64; i++) { +for (i = 0; i num_irq; i++) { pic[i] = qdev_get_gpio_in(nvic, i); } diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index d0c61c5..6fad10f 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -29,6 +29,8 @@ #define BP_OLED_SSI 0x02 #define BP_GAMEPAD 0x04 +#define NUM_IRQ_LINES 64 + typedef const struct { const char *name; uint32_t did0; @@ -1239,7 +1241,8 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, vmstate_register_ram_global(sram); memory_region_add_subregion(system_memory, 0x2000, sram); -pic = armv7m_init(system_memory, flash_size, kernel_filename, cpu_model); +pic = armv7m_init(system_memory, flash_size, NUM_IRQ_LINES, + kernel_filename, cpu_model); if (board-dc1 (1 16)) { dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000, diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index a112930..94e55a4 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -15,7 +15,7 @@ #include hw/irq.h /* armv7m.c */ -qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, +qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq, const char *kernel_filename, const char *cpu_model); /* arm_boot.c */ -- 2.1.0
Re: [Qemu-devel] [Qemu-trivial] [PATCH] get_maintainer.pl: Remove the --git-chief-penguins option
04.12.2014 14:59, Thomas Huth wrote: Ping? Ping again Thomas, we was in freeze trying to get 2.2 out of the door. During this time I didn't process -trivial patches, to not pollute incoming changes stream even further. Your patch for some reason does not apply to current state of get_maintainer.pl script, failing this hunk: - foreach my $chief (@penguin_chief) { - if ($chief =~ m/^(.*):(.*)/) { - my $email_address; - - $email_address = format_email($1, $2, $email_usename); - if ($email_git_penguin_chiefs) { - push(@email_to, [$email_address, 'chief penguin']); - } else { - @email_to = grep($_-[0] !~ /${email_address}/, @email_to); - } - } - } - I didn't look at the details, because this is a trivial delete of a block of code, so I just deleted it manually. So I applied your patch now. Note there's one more reference to penguin chief left in the code, in get_maintainer_role function. I don't think it is wrong. Thanks, /mjt
[Qemu-devel] [PATCH v7 4/7] target_arm: Remove memory region init from armv7m_init
This patch moves the memory region init code from the armv7m_init function to the stellaris_init function Signed-off-by: Alistair Francis alistai...@gmail.com Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com --- V3: - Rename the flash_size argument to mem_size - Remove the sram_size and related code - Thanks to Peter C V2: - Change the memory region names to match the machine hw/arm/armv7m.c | 33 +++-- hw/arm/stellaris.c | 24 include/hw/arm/arm.h | 3 +-- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index ef24ca4..50281f7 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -163,11 +163,10 @@ static void armv7m_reset(void *opaque) } /* Init CPU and memory for a v7-M based board. - flash_size and sram_size are in kb. + mem_size is in bytes. Returns the NVIC array. */ -qemu_irq *armv7m_init(MemoryRegion *system_memory, - int flash_size, int sram_size, +qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, const char *kernel_filename, const char *cpu_model) { ARMCPU *cpu; @@ -180,13 +179,8 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory, uint64_t lowaddr; int i; int big_endian; -MemoryRegion *sram = g_new(MemoryRegion, 1); -MemoryRegion *flash = g_new(MemoryRegion, 1); MemoryRegion *hack = g_new(MemoryRegion, 1); -flash_size *= 1024; -sram_size *= 1024; - if (cpu_model == NULL) { cpu_model = cortex-m3; } @@ -197,27 +191,6 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory, } env = cpu-env; -#if 0 -/* 32Mb SRAM gets complicated because it overlaps the bitband area. - We don't have proper commandline options, so allocate half of memory - as SRAM, up to a maximum of 32Mb, and the rest as code. */ -if (ram_size (512 + 32) * 1024 * 1024) -ram_size = (512 + 32) * 1024 * 1024; -sram_size = (ram_size / 2) TARGET_PAGE_MASK; -if (sram_size 32 * 1024 * 1024) -sram_size = 32 * 1024 * 1024; -code_size = ram_size - sram_size; -#endif - -/* Flash programming is done via the SCU, so pretend it is ROM. */ -memory_region_init_ram(flash, NULL, armv7m.flash, flash_size, - error_abort); -vmstate_register_ram_global(flash); -memory_region_set_readonly(flash, true); -memory_region_add_subregion(system_memory, 0, flash); -memory_region_init_ram(sram, NULL, armv7m.sram, sram_size, error_abort); -vmstate_register_ram_global(sram); -memory_region_add_subregion(system_memory, 0x2000, sram); armv7m_bitband_init(); nvic = qdev_create(NULL, armv7m_nvic); @@ -244,7 +217,7 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory, image_size = load_elf(kernel_filename, NULL, NULL, entry, lowaddr, NULL, big_endian, ELF_MACHINE, 1); if (image_size 0) { -image_size = load_image_targphys(kernel_filename, 0, flash_size); +image_size = load_image_targphys(kernel_filename, 0, mem_size); lowaddr = 0; } if (image_size 0) { diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index 64bd4b4..d0c61c5 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -1220,10 +1220,26 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, int i; int j; -flash_size = ((board-dc0 0x) + 1) 1; -sram_size = (board-dc0 18) + 1; -pic = armv7m_init(get_system_memory(), - flash_size, sram_size, kernel_filename, cpu_model); +MemoryRegion *sram = g_new(MemoryRegion, 1); +MemoryRegion *flash = g_new(MemoryRegion, 1); +MemoryRegion *system_memory = get_system_memory(); + +flash_size = (((board-dc0 0x) + 1) 1) * 1024; +sram_size = ((board-dc0 18) + 1) * 1024; + +/* Flash programming is done via the SCU, so pretend it is ROM. */ +memory_region_init_ram(flash, NULL, stellaris.flash, flash_size, + error_abort); +vmstate_register_ram_global(flash); +memory_region_set_readonly(flash, true); +memory_region_add_subregion(system_memory, 0, flash); + +memory_region_init_ram(sram, NULL, stellaris.sram, sram_size, + error_abort); +vmstate_register_ram_global(sram); +memory_region_add_subregion(system_memory, 0x2000, sram); + +pic = armv7m_init(system_memory, flash_size, kernel_filename, cpu_model); if (board-dc1 (1 16)) { dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000, diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index cefc9e6..a112930 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -15,8 +15,7 @@ #include hw/irq.h /* armv7m.c */ -qemu_irq *armv7m_init(MemoryRegion *system_memory, - int flash_size,
[Qemu-devel] [PATCH v7 6/7] stm32f205: Add the stm32f205 SoC
This patch adds the stm32f205 SoC. This will be used by the Netduino 2 to create a machine. Signed-off-by: Alistair Francis alistai...@gmail.com --- V6: - Correct the number of USART/UART devices - Use macros to define how many devices are inited - Update the memory regions name from netduino.* to STM32F205.* default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs| 1 + hw/arm/stm32f205_soc.c | 157 include/hw/arm/stm32f205_soc.h | 69 ++ 4 files changed, 228 insertions(+) create mode 100644 hw/arm/stm32f205_soc.c create mode 100644 include/hw/arm/stm32f205_soc.h diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index a5aab7f..9ac755e 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -81,6 +81,7 @@ CONFIG_ZYNQ=y CONFIG_STM32F2XX_TIMER=y CONFIG_STM32F2XX_USART=y CONFIG_STM32F2XX_SYSCFG=y +CONFIG_STM32F205_SOC=y CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs index 6088e53..9769317 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -8,3 +8,4 @@ obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-$(CONFIG_DIGIC) += digic.o obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o +obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o diff --git a/hw/arm/stm32f205_soc.c b/hw/arm/stm32f205_soc.c new file mode 100644 index 000..186e15d --- /dev/null +++ b/hw/arm/stm32f205_soc.c @@ -0,0 +1,157 @@ +/* + * STM32F205 SoC + * + * Copyright (c) 2014 Alistair Francis alist...@alistair23.me + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include hw/arm/stm32f205_soc.h + +/* At the moment only Timer 2 to 5 are modelled */ +static const uint32_t timer_addr[STM_NUM_TIMERS] = { 0x4000, 0x4400, +0x4800, 0x4C00 }; +static const uint32_t usart_addr[STM_NUM_USARTS] = { 0x40011000, 0x40004400, +0x40004800, 0x40004C00, 0x40005000, 0x40011400 }; + +static const int timer_irq[STM_NUM_TIMERS] = {28, 29, 30, 50}; +static const int usart_irq[STM_NUM_USARTS] = {37, 38, 39, 52, 53, 71}; + +static void stm32f205_soc_initfn(Object *obj) +{ +STM32F205State *s = STM32F205_SOC(obj); +int i; + +object_initialize(s-syscfg, sizeof(s-syscfg), TYPE_STM32F2XX_SYSCFG); +qdev_set_parent_bus(DEVICE(s-syscfg), sysbus_get_default()); + +for (i = 0; i STM_NUM_USARTS; i++) { +object_initialize(s-usart[i], sizeof(s-usart[i]), + TYPE_STM32F2XX_USART); +qdev_set_parent_bus(DEVICE(s-usart[i]), sysbus_get_default()); +} + +for (i = 0; i STM_NUM_TIMERS; i++) { +object_initialize(s-timer[i], sizeof(s-timer[i]), + TYPE_STM32F2XX_TIMER); +qdev_set_parent_bus(DEVICE(s-timer[i]), sysbus_get_default()); +} +} + +static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) +{ +STM32F205State *s = STM32F205_SOC(dev_soc); +DeviceState *syscfgdev, *usartdev, *timerdev; +SysBusDevice *syscfgbusdev, *usartbusdev, *timerbusdev; +qemu_irq *pic; +Error *err = NULL; +int i; + +MemoryRegion *system_memory = get_system_memory(); +MemoryRegion *sram = g_new(MemoryRegion, 1); +MemoryRegion *flash = g_new(MemoryRegion, 1); +MemoryRegion *flash_alias = g_new(MemoryRegion, 1); + +memory_region_init_ram(flash, NULL, STM32F205.flash, FLASH_SIZE, + error_abort); +memory_region_init_alias(flash_alias, NULL, STM32F205.flash.alias, + flash, 0, FLASH_SIZE); + +vmstate_register_ram_global(flash); + +memory_region_set_readonly(flash, true); +memory_region_set_readonly(flash_alias, true); + +memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash); +
Re: [Qemu-devel] [Qemu-trivial] [PATCH] fw_cfg: remove superfluous blank line
Applied to trivial. However, I think this patch is too trivial even for trivial-patches queue... ;) As in, don't bother fixing things like this unless there's other code around being changed too. Thanks, /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] virtio: remove useless declaration of virtio_net_init()
applied to -trivial, thank you! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH] qapi-schema: fix typo about change-vnc-password
Applied to -trivial, thanks! /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] vt82c686: fix coverity warning about out-of-bounds write
09.12.2014 10:15, zhanghailiang wrote: Refactor superio_ioport_writeb to fix the out of bounds write warning. Is it just a warning, or real oob write? From the code it looks like it's just a warning... [] + +} +if (can_write == true) { 09.12.2014 17:08, Paolo Bonzini wrote: Michael, can you remove == true when applying this patch? Sure, just did. Does it mean I can add your R-b too? ;) Thanks, /mjt
Re: [Qemu-devel] migration from qemu2.1.2 to qemu2.2
* William Dauchy (will...@gandi.net) wrote: Hi David, Thank you for the quick answer. On Dec09 18:55, Dr. David Alan Gilbert wrote: You don't tell us what that command line is! If you're using -M pc or -M q35 that's expected; if you're not it's probably a bug - please show us the command line. sorry it's indeed with `-M pc`. So I misunderstood the usage of supported machines option since I was looking for a way to upgrade the version and avoiding being stuck on a specific release. I now understand I am supposed to keep the same version between live migration and wait for a complete stop/start to upgrade. Or if there is a trick, please advice. Yes, you've got to keep the same machine type to do a live migration; think of it like keeping the same motherboard/cpu combination in a real machine - we can't squash the state from one shape machine into a different shape machine without the guest getting very confused. Dave -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK
Re: [Qemu-devel] [Qemu-trivial] [PATCH] pflash_cfi02.c: associate cfi.pflash02 to Storage devices category
07.12.2014 21:20, Antony Pavlov wrote: Signed-off-by: Antony Pavlov antonynpav...@gmail.com --- hw/block/pflash_cfi02.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 8513a17..389b4aa 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -744,6 +744,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data) dc-realize = pflash_cfi02_realize; dc-props = pflash_cfi02_properties; +set_bit(DEVICE_CATEGORY_STORAGE, dc-categories); } static const TypeInfo pflash_cfi02_info = { Hm. While the patch itself is trivial, and it _seems_ it fixes a bug, I'm not sure of possible effects of this. What prob it has now, does this device work? If yes, why it needs fixing? Do we care about compatibility with previous versions, about migration? Cc'ing block device people... Thanks, /mjt
Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] vt82c686: fix coverity warning about out-of-bounds write
On 10/12/2014 09:57, Michael Tokarev wrote: 09.12.2014 10:15, zhanghailiang wrote: Refactor superio_ioport_writeb to fix the out of bounds write warning. Is it just a warning, or real oob write? From the code it looks like it's just a warning... It's a bug. The simpler patch would have been just to remove the useless assignment superio_conf-config[superio_conf-index] = data 0xff; that is *outside* the switch and not protected by if (can_write). Apart from this, there is an off-by-one that I'll send a patch for right away. Paolo [] + +} +if (can_write == true) { 09.12.2014 17:08, Paolo Bonzini wrote: Michael, can you remove == true when applying this patch? Sure, just did. Does it mean I can add your R-b too? ;) Sure. Paolo
[Qemu-devel] [PATCH] vt82c686: avoid out-of-bounds read
superio_ioport_readb can read the 256th element of the array. Coverity reports an out-of-bounds write in superio_ioport_writeb, but it does not show the corresponding out-of-bounds read because it cannot prove that it can happen. Fix the root cause of the problem (zhanghailang's patch instead fixes the logic in superio_ioport_writeb). Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- hw/isa/vt82c686.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index e0c235c..a43e26d 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -36,7 +36,7 @@ typedef struct SuperIOConfig { -uint8_t config[0xff]; +uint8_t config[0x100]; uint8_t index; uint8_t data; } SuperIOConfig; -- 1.8.3.1
Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] vt82c686: fix coverity warning about out-of-bounds write
On 2014/12/10 16:57, Michael Tokarev wrote: 09.12.2014 10:15, zhanghailiang wrote: Refactor superio_ioport_writeb to fix the out of bounds write warning. Is it just a warning, or real oob write? From the code it looks like it's just a warning... Er, i don't know when input 'data' will be oxff, if this happens, it will access superio_conf-config[0xff] which is out of bounds for superio_conf-config. Actually, we should check the 'can_write' when access superio_conf-config[] in the follow codes, but these codes seem a little odd, so refactor it is better choice. ;) [] + +} +if (can_write == true) { 09.12.2014 17:08, Paolo Bonzini wrote: Michael, can you remove == true when applying this patch? Sure, just did. Does it mean I can add your R-b too? ;) cc: Paolo Thanks. zhanghailiang
[Qemu-devel] [PULL 0/2] vnc patch queue
Hi, Starting to flush queues after the 2.2 release, starting with two little vnc fixes. Well, keymap is strictly speaking not vnc, but vnc is the major user of keymap support, so I sticked it in here. please pull, Gerd The following changes since commit 45e1611de8be0eae55967694dd6e627c2dc354f2: Update version for v2.2.0 release (2014-12-09 12:13:37 +) are available in the git repository at: git://git.kraxel.org/qemu tags/pull-vnc-20141210-1 for you to fetch changes up to 43948386bb109b97b3de0bb48573f317bdcb5008: keymaps: correct keymaps.c following Qemu coding style (2014-12-10 10:08:12 +0100) vnc-enc-tight fix, keymaps code style. Gonglei (2): vnc-enc-tight: fix Arguments in wrong order keymaps: correct keymaps.c following Qemu coding style ui/keymaps.c | 196 + ui/vnc-enc-tight.c | 2 +- 2 files changed, 109 insertions(+), 89 deletions(-)
[Qemu-devel] [PULL 1/2] vnc-enc-tight: fix Arguments in wrong order
From: Gonglei arei.gong...@huawei.com Arguments in wrong order (SWAPPED_ARGUMENTS) The positions of arguments in the call to tight_fill_palette do not match the ordering of the parameters: fg is passed to bg bg is passed to fg Cc: Gerd Hoffmann kra...@redhat.com Signed-off-by: Gonglei arei.gong...@huawei.com Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc-enc-tight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index 3d1b5cd..9a9ddf2 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -1489,7 +1489,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h) } #endif -colors = tight_fill_palette(vs, x, y, w * h, fg, bg, palette); +colors = tight_fill_palette(vs, x, y, w * h, bg, fg, palette); #ifdef CONFIG_VNC_JPEG if (allow_jpeg vs-tight.quality != (uint8_t)-1) { -- 1.8.3.1
[Qemu-devel] [PULL 2/2] keymaps: correct keymaps.c following Qemu coding style
From: Gonglei arei.gong...@huawei.com It's hard to read because of the confused coding style in this file. Let's correct it following Qemu coding style. Signed-off-by: Gonglei arei.gong...@huawei.com Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/keymaps.c | 196 --- 1 file changed, 108 insertions(+), 88 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index 80d658d..49410ae 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -26,18 +26,20 @@ #include sysemu/sysemu.h static int get_keysym(const name2keysym_t *table, - const char *name) + const char *name) { const name2keysym_t *p; for(p = table; p-name != NULL; p++) { -if (!strcmp(p-name, name)) +if (!strcmp(p-name, name)) { return p-keysym; +} } if (name[0] == 'U' strlen(name) == 5) { /* try unicode U */ char *end; int ret = (int)strtoul(name + 1, end, 16); -if (*end == '\0' ret 0) - return ret; +if (*end == '\0' ret 0) { +return ret; +} } return 0; } @@ -46,19 +48,20 @@ static int get_keysym(const name2keysym_t *table, static void add_to_key_range(struct key_range **krp, int code) { struct key_range *kr; for (kr = *krp; kr; kr = kr-next) { - if (code = kr-start code = kr-end) - break; - if (code == kr-start - 1) { - kr-start--; - break; - } - if (code == kr-end + 1) { - kr-end++; - break; - } +if (code = kr-start code = kr-end) { +break; +} +if (code == kr-start - 1) { +kr-start--; +break; +} +if (code == kr-end + 1) { +kr-end++; +break; +} } if (kr == NULL) { - kr = g_malloc0(sizeof(*kr)); +kr = g_malloc0(sizeof(*kr)); kr-start = kr-end = code; kr-next = *krp; *krp = kr; @@ -67,30 +70,30 @@ static void add_to_key_range(struct key_range **krp, int code) { static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k) { if (keysym MAX_NORMAL_KEYCODE) { - //fprintf(stderr,Setting keysym %s (%d) to %d\n,line,keysym,keycode); - k-keysym2keycode[keysym] = keycode; +/* fprintf(stderr,Setting keysym %s (%d) to %d\n, + line, keysym, keycode); */ +k-keysym2keycode[keysym] = keycode; } else { - if (k-extra_count = MAX_EXTRA_COUNT) { - fprintf(stderr, - Warning: Could not assign keysym %s (0x%x) because of memory constraints.\n, - line, keysym); - } else { +if (k-extra_count = MAX_EXTRA_COUNT) { +fprintf(stderr, Warning: Could not assign keysym %s (0x%x) + because of memory constraints.\n, line, keysym); +} else { #if 0 - fprintf(stderr, Setting %d: %d,%d\n, - k-extra_count, keysym, keycode); +fprintf(stderr, Setting %d: %d,%d\n, +k-extra_count, keysym, keycode); #endif - k-keysym2keycode_extra[k-extra_count]. - keysym = keysym; - k-keysym2keycode_extra[k-extra_count]. - keycode = keycode; - k-extra_count++; - } +k-keysym2keycode_extra[k-extra_count]. +keysym = keysym; +k-keysym2keycode_extra[k-extra_count]. +keycode = keycode; +k-extra_count++; +} } } static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, - const char *language, - kbd_layout_t * k) + const char *language, + kbd_layout_t *k) { FILE *f; char * filename; @@ -101,69 +104,78 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, f = filename ? fopen(filename, r) : NULL; g_free(filename); if (!f) { - fprintf(stderr, - Could not read keymap file: '%s'\n, language); - return NULL; +fprintf(stderr, Could not read keymap file: '%s'\n, language); +return NULL; } -if (!k) - k = g_malloc0(sizeof(kbd_layout_t)); +if (!k) { +k = g_malloc0(sizeof(kbd_layout_t)); +} for(;;) { - if (fgets(line, 1024, f) == NULL) +if (fgets(line, 1024, f) == NULL) { break; +} len = strlen(line); -if (len 0 line[len - 1] == '\n') +if (len 0 line[len - 1] == '\n') { line[len - 1] = '\0'; -if (line[0] == '#') - continue; - if (!strncmp(line, map , 4)) - continue; - if (!strncmp(line, include , 8)) { - parse_keyboard_layout(table,
Re: [Qemu-devel] [PATCH] vt82c686: avoid out-of-bounds read
Hi paolo, Will this change affects the migration? I noticed that there is a member 'SuperIOConfig superio_conf' in VT82C686BState. vt82c686 seems only to be used in mips64el target, Do we support migration for mips target? Thanks, zhanghailiang On 2014/12/10 17:17, Paolo Bonzini wrote: superio_ioport_readb can read the 256th element of the array. Coverity reports an out-of-bounds write in superio_ioport_writeb, but it does not show the corresponding out-of-bounds read because it cannot prove that it can happen. Fix the root cause of the problem (zhanghailang's patch instead fixes the logic in superio_ioport_writeb). Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- hw/isa/vt82c686.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index e0c235c..a43e26d 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -36,7 +36,7 @@ typedef struct SuperIOConfig { -uint8_t config[0xff]; +uint8_t config[0x100]; uint8_t index; uint8_t data; } SuperIOConfig;
[Qemu-devel] [PATCH v2 00/10] vnc: add support for multiple vnc displays
Hi, New version of the series after a logn break. No major changes in the existing patches, added some new patches though: Patch #3 to add the vnc display name to the acls, and patches 8-10 adding a new monitor command to query vnc server information. please review, Gerd Gerd Hoffmann (10): vnc: remove vnc_display global vnc: remove unused DisplayState parameter, add id instead. vnc: add display id to acl names vnc: switch to QemuOpts, allow multiple servers vnc: allow binding servers to qemu consoles vnc: update docs/multiseat.txt vnc: track limit connections vnc: factor out qmp_query_client_list monitor: add query-vnc2 command monitor: add vnc websockets docs/multiseat.txt | 18 +- include/ui/console.h | 18 +- qapi-schema.json | 55 - qmp-commands.hx | 5 + qmp.c| 15 +- ui/vnc.c | 567 +-- ui/vnc.h | 5 + vl.c | 41 ++-- 8 files changed, 526 insertions(+), 198 deletions(-) -- 1.8.3.1
[Qemu-devel] [PATCH v2 01/10] vnc: remove vnc_display global
Replace with a vnc_displays list, so we can have multiple vnc server instances. Add vnc_server_find function to lookup a display by id. With no id supplied return the first vnc server, for backward compatibility reasons. It is not possible (yet) to actually create mutiple vnc server instances. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc.c | 63 +-- ui/vnc.h | 2 ++ 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 5707015..a6549c8 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -46,7 +46,8 @@ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 }; #include vnc_keysym.h #include d3des.h -static VncDisplay *vnc_display; /* needed for info vnc */ +static QTAILQ_HEAD(, VncDisplay) vnc_displays = +QTAILQ_HEAD_INITIALIZER(vnc_displays); static int vnc_cursor_define(VncState *vs); static void vnc_release_modifiers(VncState *vs); @@ -226,10 +227,10 @@ static const char *vnc_auth_name(VncDisplay *vd) { return unknown; } -static VncServerInfo *vnc_server_info_get(void) +static VncServerInfo *vnc_server_info_get(VncDisplay *vd) { VncServerInfo *info; -VncBasicInfo *bi = vnc_basic_info_get_from_server_addr(vnc_display-lsock); +VncBasicInfo *bi = vnc_basic_info_get_from_server_addr(vd-lsock); if (!bi) { return NULL; } @@ -237,7 +238,7 @@ static VncServerInfo *vnc_server_info_get(void) info = g_malloc(sizeof(*info)); info-base = bi; info-has_auth = true; -info-auth = g_strdup(vnc_auth_name(vnc_display)); +info-auth = g_strdup(vnc_auth_name(vd)); return info; } @@ -282,7 +283,7 @@ static void vnc_qmp_event(VncState *vs, QAPIEvent event) } g_assert(vs-info-base); -si = vnc_server_info_get(); +si = vnc_server_info_get(vs-vd); if (!si) { return; } @@ -345,11 +346,27 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client) return info; } +static VncDisplay *vnc_display_find(const char *id) +{ +VncDisplay *vd; + +if (id == NULL) { +return QTAILQ_FIRST(vnc_displays); +} +QTAILQ_FOREACH(vd, vnc_displays, next) { +if (strcmp(id, vd-id) == 0) { +return vd; +} +} +return NULL; +} + VncInfo *qmp_query_vnc(Error **errp) { VncInfo *info = g_malloc0(sizeof(*info)); +VncDisplay *vd = vnc_display_find(NULL); -if (vnc_display == NULL || vnc_display-display == NULL) { +if (vd == NULL || vd-display == NULL) { info-enabled = false; } else { VncClientInfoList *cur_item = NULL; @@ -364,7 +381,7 @@ VncInfo *qmp_query_vnc(Error **errp) /* for compatibility with the original command */ info-has_clients = true; -QTAILQ_FOREACH(client, vnc_display-clients, next) { +QTAILQ_FOREACH(client, vd-clients, next) { VncClientInfoList *cinfo = g_malloc0(sizeof(*info)); cinfo-value = qmp_query_vnc_client(client); @@ -377,11 +394,11 @@ VncInfo *qmp_query_vnc(Error **errp) } } -if (vnc_display-lsock == -1) { +if (vd-lsock == -1) { return info; } -if (getsockname(vnc_display-lsock, (struct sockaddr *)sa, +if (getsockname(vd-lsock, (struct sockaddr *)sa, salen) == -1) { error_set(errp, QERR_UNDEFINED_ERROR); goto out_error; @@ -405,7 +422,7 @@ VncInfo *qmp_query_vnc(Error **errp) info-family = inet_netfamily(sa.ss_family); info-has_auth = true; -info-auth = g_strdup(vnc_auth_name(vnc_display)); +info-auth = g_strdup(vnc_auth_name(vd)); } return info; @@ -853,7 +870,7 @@ static int vnc_cursor_define(VncState *vs) static void vnc_dpy_cursor_define(DisplayChangeListener *dcl, QEMUCursor *c) { -VncDisplay *vd = vnc_display; +VncDisplay *vd = container_of(dcl, VncDisplay, dcl); VncState *vs; cursor_put(vd-cursor); @@ -2818,6 +2835,7 @@ static void vnc_connect(VncDisplay *vd, int csock, int i; vs-csock = csock; +vs-vd = vd; if (skipauth) { vs-auth = VNC_AUTH_NONE; @@ -2862,8 +2880,6 @@ static void vnc_connect(VncDisplay *vd, int csock, vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED); vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING); -vs-vd = vd; - #ifdef CONFIG_VNC_WS if (!vs-websocket) #endif @@ -2955,7 +2971,7 @@ void vnc_display_init(DisplayState *ds) { VncDisplay *vs = g_malloc0(sizeof(*vs)); -vnc_display = vs; +QTAILQ_INSERT_TAIL(vnc_displays, vs, next); vs-lsock = -1; #ifdef CONFIG_VNC_WS @@ -2985,7 +3001,7 @@ void vnc_display_init(DisplayState *ds) static void vnc_display_close(DisplayState *ds) { -VncDisplay *vs = vnc_display; +VncDisplay *vs = vnc_display_find(NULL); if (!vs) return; @@ -3014,7 +3030,7 @@
[Qemu-devel] [PATCH v2 10/10] monitor: add vnc websockets
Add websockets bool to VncBasicInfo, report websocket server sockets, flag websocket client connections. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- qapi-schema.json | 5 - ui/vnc.c | 14 -- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 677a762..a945693 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -672,12 +672,15 @@ # # @family: address family # +# @websocket: #optional true in case the socket is a websocket (since 2.2). +# # Since: 2.1 ## { 'type': 'VncBasicInfo', 'data': { 'host': 'str', 'service': 'str', -'family': 'NetworkAddressFamily' } } +'family': 'NetworkAddressFamily', +'*websocket': 'bool' } } ## # @VncServerInfo diff --git a/ui/vnc.c b/ui/vnc.c index 0574631..f3beb4b 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -353,6 +353,10 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client) info-base-host = g_strdup(host); info-base-service = g_strdup(serv); info-base-family = inet_netfamily(sa.ss_family); +if (client-websocket) { +info-base-has_websocket = true; +info-base-websocket = true; +} #ifdef CONFIG_VNC_TLS if (client-tls.session client-tls.dname) { @@ -457,6 +461,7 @@ out_error: } static VncBasicInfoList *qmp_query_server_entry(int socket, +bool websocket, VncBasicInfoList *prev) { VncBasicInfoList *list; @@ -477,6 +482,10 @@ static VncBasicInfoList *qmp_query_server_entry(int socket, info-host = g_strdup(host); info-service = g_strdup(serv); info-family = inet_netfamily(sa.ss_family); +if (websocket) { +info-has_websocket = true; +info-websocket = true; +} list = g_new0(VncBasicInfoList, 1); list-value = info; @@ -503,12 +512,13 @@ VncInfo2List *qmp_query_vnc2(Error **errp) info-display = g_strdup(dev-id); } if (vd-lsock != -1) { -info-server = qmp_query_server_entry(vd-lsock, +info-server = qmp_query_server_entry(vd-lsock, false, info-server); } #ifdef CONFIG_VNC_WS if (vd-lwebsock != -1) { -/* TODO */ +info-server = qmp_query_server_entry(vd-lwebsock, true, + info-server); } #endif -- 1.8.3.1
[Qemu-devel] [PATCH v2 04/10] vnc: switch to QemuOpts, allow multiple servers
This patch switches vnc over to QemuOpts, and it (more or less as side effect) allows multiple vnc server instances. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 4 +- qmp.c| 15 ++- ui/vnc.c | 271 --- vl.c | 42 +++- 4 files changed, 200 insertions(+), 132 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 5ff2e27..887ed91 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -328,12 +328,14 @@ void cocoa_display_init(DisplayState *ds, int full_screen); /* vnc.c */ void vnc_display_init(const char *id); -void vnc_display_open(const char *id, const char *display, Error **errp); +void vnc_display_open(const char *id, Error **errp); void vnc_display_add_client(const char *id, int csock, bool skipauth); char *vnc_display_local_addr(const char *id); #ifdef CONFIG_VNC int vnc_display_password(const char *id, const char *password); int vnc_display_pw_expire(const char *id, time_t expires); +QemuOpts *vnc_parse_func(const char *str); +int vnc_init_func(QemuOpts *opts, void *opaque); #else static inline int vnc_display_password(const char *id, const char *password) { diff --git a/qmp.c b/qmp.c index 0b4f131..3fda973 100644 --- a/qmp.c +++ b/qmp.c @@ -368,7 +368,20 @@ void qmp_change_vnc_password(const char *password, Error **errp) static void qmp_change_vnc_listen(const char *target, Error **errp) { -vnc_display_open(NULL, target, errp); +QemuOptsList *olist = qemu_find_opts(vnc); +QemuOpts *opts; + +if (strstr(target, id=)) { +error_setg(errp, id not supported); +return; +} + +opts = qemu_opts_find(olist, default); +if (opts) { +qemu_opts_del(opts); +} +opts = vnc_parse_func(target); +vnc_init_func(opts, NULL); } static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, diff --git a/ui/vnc.c b/ui/vnc.c index 1b86365..cf8bed8 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -31,6 +31,7 @@ #include qemu/sockets.h #include qemu/timer.h #include qemu/acl.h +#include qemu/config-file.h #include qapi/qmp/types.h #include qmp-commands.h #include qemu/osdep.h @@ -2969,7 +2970,12 @@ static const DisplayChangeListenerOps dcl_ops = { void vnc_display_init(const char *id) { -VncDisplay *vs = g_malloc0(sizeof(*vs)); +VncDisplay *vs; + +if (vnc_display_find(id) != NULL) { +return; +} +vs = g_malloc0(sizeof(*vs)); vs-id = strdup(id); QTAILQ_INSERT_TAIL(vnc_displays, vs, next); @@ -3065,14 +3071,65 @@ char *vnc_display_local_addr(const char *id) return vnc_socket_local_addr(%s:%s, vs-lsock); } -void vnc_display_open(const char *id, const char *display, Error **errp) +static QemuOptsList qemu_vnc_opts = { +.name = vnc, +.head = QTAILQ_HEAD_INITIALIZER(qemu_vnc_opts.head), +.implied_opt_name = vnc, +.desc = { +{ +.name = vnc, +.type = QEMU_OPT_STRING, +},{ +.name = websocket, +.type = QEMU_OPT_STRING, +},{ +.name = x509, +.type = QEMU_OPT_STRING, +},{ +.name = share, +.type = QEMU_OPT_STRING, +},{ +.name = password, +.type = QEMU_OPT_BOOL, +},{ +.name = reverse, +.type = QEMU_OPT_BOOL, +},{ +.name = lock-key-sync, +.type = QEMU_OPT_BOOL, +},{ +.name = sasl, +.type = QEMU_OPT_BOOL, +},{ +.name = tls, +.type = QEMU_OPT_BOOL, +},{ +.name = x509verify, +.type = QEMU_OPT_BOOL, +},{ +.name = acl, +.type = QEMU_OPT_BOOL, +},{ +.name = lossy, +.type = QEMU_OPT_BOOL, +},{ +.name = non-adaptive, +.type = QEMU_OPT_BOOL, +}, +{ /* end of list */ } +}, +}; + +void vnc_display_open(const char *id, Error **errp) { VncDisplay *vs = vnc_display_find(id); -const char *options; +QemuOpts *opts = qemu_opts_find(qemu_vnc_opts, id); +const char *display, *websocket, *share; int password = 0; int reverse = 0; #ifdef CONFIG_VNC_TLS int tls = 0, x509 = 0; +const char *path; #endif #ifdef CONFIG_VNC_SASL int sasl = 0; @@ -3088,115 +3145,86 @@ void vnc_display_open(const char *id, const char *display, Error **errp) return; } vnc_display_close(vs); -if (strcmp(display, none) == 0) -return; +if (!opts) { +return; +} +display = qemu_opt_get(opts, vnc); +if (!display || strcmp(display, none) == 0) { +return; +} vs-display = g_strdup(display); -vs-share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE; - -options = display; -while ((options = strchr(options, ','))) { -
[Qemu-devel] [PATCH v2 06/10] vnc: update docs/multiseat.txt
vnc joins the party ;) Also some s/head/seat/ to clarify. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- docs/multiseat.txt | 18 ++ 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/multiseat.txt b/docs/multiseat.txt index 67151e0..b963665 100644 --- a/docs/multiseat.txt +++ b/docs/multiseat.txt @@ -7,7 +7,7 @@ host side First you must compile qemu with a user interface supporting multihead/multiseat and input event routing. Right now this -list includes sdl2 and gtk (both 2+3): +list includes sdl2, gtk (both 2+3) and vnc: ./configure --enable-sdl --with-sdlabi=2.0 @@ -16,16 +16,16 @@ or ./configure --enable-gtk -Next put together the qemu command line: +Next put together the qemu command line (sdk/gtk): qemu -enable-kvm -usb $memory $disk $whatever \ -display [ sdl | gtk ] \ -vga std \ -device usb-tablet -That is it for the first head, which will use the standard vga, the +That is it for the first seat, which will use the standard vga, the standard ps/2 keyboard (implicitly there) and the usb-tablet. Now the -additional switches for the second head: +additional switches for the second seat: -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \ -device secondary-vga,bus=head.2,addr=02.0,id=video.2 \ @@ -47,6 +47,16 @@ in a separate tab. You can either simply switch tabs to switch heads, or use the View / Detach tab menu item to move one of the displays to its own window so you can see both display devices side-by-side. +For vnc some additional configuration on the command line is needed. +We'll create two vnc server instances, and bind the second one to the +second seat, simliar to input devices: + + -display vnc=:1,id=primary \ + -display vnc=:2,id=secondary,display=video.2 + +Connecting to vnc display :1 gives you access to the first seat, and +likewise connecting to vnc display :2 shows the second seat. + Note on spice: Spice handles multihead just fine. But it can't do multiseat. For tablet events the event source is sent to the spice agent. But qemu can't figure it, so it can't do input routing. -- 1.8.3.1
[Qemu-devel] [PATCH v2 07/10] vnc: track limit connections
Also track the number of connections in connecting and shared state (in addition to the exclusive state). Apply a configurable limit to these connections. The logic to apply the limit to connections in shared state is pretty simple: When the limit is reached no new connections are allowed. The logic to apply the limit to connections in connecting state (this is the state you are in *before* successful authentication) is slightly different: A new connect kicks out the oldest client which is still in connecting state. This avoids a easy DoS by unauthenticated users by simply opening connections until the limit is reached. Cc: Dr. David Alan Gilbert dgilb...@redhat.com Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc.c | 46 +++--- ui/vnc.h | 3 +++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 210a115..8d189e7 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -68,12 +68,34 @@ static void vnc_set_share_mode(VncState *vs, VncShareMode mode) vs-csock, mn[vs-share_mode], mn[mode]); #endif -if (vs-share_mode == VNC_SHARE_MODE_EXCLUSIVE) { +switch (vs-share_mode) { +case VNC_SHARE_MODE_CONNECTING: +vs-vd-num_connecting--; +break; +case VNC_SHARE_MODE_SHARED: +vs-vd-num_shared--; +break; +case VNC_SHARE_MODE_EXCLUSIVE: vs-vd-num_exclusive--; +break; +default: +break; } + vs-share_mode = mode; -if (vs-share_mode == VNC_SHARE_MODE_EXCLUSIVE) { + +switch (vs-share_mode) { +case VNC_SHARE_MODE_CONNECTING: +vs-vd-num_connecting++; +break; +case VNC_SHARE_MODE_SHARED: +vs-vd-num_shared++; +break; +case VNC_SHARE_MODE_EXCLUSIVE: vs-vd-num_exclusive++; +break; +default: +break; } } @@ -2337,6 +2359,11 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) } vnc_set_share_mode(vs, mode); +if (vs-vd-num_shared vs-vd-connections_limit) { +vnc_disconnect_start(vs); +return 0; +} + vs-client_width = pixman_image_get_width(vs-vd-server); vs-client_height = pixman_image_get_height(vs-vd-server); vnc_write_u16(vs, vs-client_width); @@ -2889,6 +2916,15 @@ static void vnc_connect(VncDisplay *vd, int csock, { vnc_init_state(vs); } + +if (vd-num_connecting vd-connections_limit) { +QTAILQ_FOREACH(vs, vd-clients, next) { +if (vs-share_mode == VNC_SHARE_MODE_CONNECTING) { +vnc_disconnect_start(vs); +return; +} +} +} } void vnc_init_state(VncState *vs) @@ -2907,7 +2943,7 @@ void vnc_init_state(VncState *vs) qemu_mutex_init(vs-output_mutex); vs-bh = qemu_bh_new(vnc_jobs_bh, vs); -QTAILQ_INSERT_HEAD(vd-clients, vs, next); +QTAILQ_INSERT_TAIL(vd-clients, vs, next); graphic_hw_update(vd-dcl.con); @@ -3097,6 +3133,9 @@ static QemuOptsList qemu_vnc_opts = { .name = head, .type = QEMU_OPT_NUMBER, },{ +.name = connections, +.type = QEMU_OPT_NUMBER, +},{ .name = password, .type = QEMU_OPT_BOOL, },{ @@ -3210,6 +3249,7 @@ void vnc_display_open(const char *id, Error **errp) } else { vs-share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE; } +vs-connections_limit = qemu_opt_get_number(opts, connections, 32); #ifdef CONFIG_VNC_WS websocket = qemu_opt_get(opts, websocket); diff --git a/ui/vnc.h b/ui/vnc.h index 6fe8278..5e2b1a5 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -150,7 +150,10 @@ typedef enum VncSharePolicy { struct VncDisplay { QTAILQ_HEAD(, VncState) clients; +int num_connecting; +int num_shared; int num_exclusive; +int connections_limit; VncSharePolicy share_policy; int lsock; #ifdef CONFIG_VNC_WS -- 1.8.3.1
[Qemu-devel] [PATCH v2 09/10] monitor: add query-vnc2 command
Add new query vnc qmp command, for the lack of better ideas just name it query-vnc2. Changes over query-vnc: * It returns a list of vnc servers, so multiple vnc server instances are covered. * Each vnc server returns a list of server sockets. Followup patch will use that to also report websockets. In case we add support for multiple server sockets server sockets (to better support ipv4+ipv6 dualstack) we can add them to the list too. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- qapi-schema.json | 50 +++ qmp-commands.hx | 5 + ui/vnc.c | 64 3 files changed, 119 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 9ffdcf8..677a762 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -751,6 +751,45 @@ '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} } ## +# @VncInfo2: +# +# Information about a vnc server +# +# @id: vnc server name. +# +# @server: A list of @VncBasincInfo describing all listening sockets. +# The list can be empty (in case the vnc server is disabled). +# It also may have multiple entries: normal + websocket, +# possibly also ipv4 + ipv6 in the future. +# +# @clients: A list of @VncClientInfo of all currently connected clients. +# The list can be empty, for obvious reasons. +# +# @auth: The current authentication type used by the server +#'none' if no authentication is being used +#'vnc' if VNC authentication is being used +#'vencrypt+plain' if VEncrypt is used with plain text authentication +#'vencrypt+tls+none' if VEncrypt is used with TLS and no authentication +#'vencrypt+tls+vnc' if VEncrypt is used with TLS and VNC authentication +#'vencrypt+tls+plain' if VEncrypt is used with TLS and plain text auth +#'vencrypt+x509+none' if VEncrypt is used with x509 and no auth +#'vencrypt+x509+vnc' if VEncrypt is used with x509 and VNC auth +#'vencrypt+x509+plain' if VEncrypt is used with x509 and plain text auth +#'vencrypt+tls+sasl' if VEncrypt is used with TLS and SASL auth +#'vencrypt+x509+sasl' if VEncrypt is used with x509 and SASL auth +# +# @display: #optional The display device the vnc server is linked to. +# +# Since: 2.3 +## +{ 'type': 'VncInfo2', + 'data': { 'id' : 'str', +'server' : ['VncBasicInfo'], +'clients' : ['VncClientInfo'], +'auth' : 'str', +'*display' : 'str' } } + +## # @query-vnc: # # Returns information about the current VNC server @@ -762,6 +801,17 @@ { 'command': 'query-vnc', 'returns': 'VncInfo' } ## +# @query-vnc2: +# +# Returns a list of vnc servers. The list can be empty. +# +# Returns: @VncInfo +# +# Since: 2.3 +## +{ 'command': 'query-vnc2', 'returns': ['VncInfo2'] } + +## # @SpiceBasicInfo # # The basic information for SPICE network connection diff --git a/qmp-commands.hx b/qmp-commands.hx index 718dd92..704522e 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2825,6 +2825,11 @@ EQMP .args_type = , .mhandler.cmd_new = qmp_marshal_input_query_vnc, }, +{ +.name = query-vnc2, +.args_type = , +.mhandler.cmd_new = qmp_marshal_input_query_vnc2, +}, SQMP query-spice diff --git a/ui/vnc.c b/ui/vnc.c index d04802c..0574631 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -456,6 +456,70 @@ out_error: return NULL; } +static VncBasicInfoList *qmp_query_server_entry(int socket, +VncBasicInfoList *prev) +{ +VncBasicInfoList *list; +VncBasicInfo *info; +struct sockaddr_storage sa; +socklen_t salen = sizeof(sa); +char host[NI_MAXHOST]; +char serv[NI_MAXSERV]; + +if (getsockname(socket, (struct sockaddr *)sa, salen) 0 || +getnameinfo((struct sockaddr *)sa, salen, +host, sizeof(host), serv, sizeof(serv), +NI_NUMERICHOST | NI_NUMERICSERV) 0) { +return prev; +} + +info = g_new0(VncBasicInfo, 1); +info-host = g_strdup(host); +info-service = g_strdup(serv); +info-family = inet_netfamily(sa.ss_family); + +list = g_new0(VncBasicInfoList, 1); +list-value = info; +list-next = prev; +return list; +} + +VncInfo2List *qmp_query_vnc2(Error **errp) +{ +VncInfo2List *item, *prev = NULL; +VncInfo2 *info; +VncDisplay *vd; +DeviceState *dev; + +QTAILQ_FOREACH(vd, vnc_displays, next) { +info = g_new0(VncInfo2, 1); +info-id = g_strdup(vd-id); +info-auth = g_strdup(vnc_auth_name(vd)); +info-clients = qmp_query_client_list(vd); +if (vd-dcl.con) { +dev = DEVICE(object_property_get_link(OBJECT(vd-dcl.con), + device, NULL)); +info-has_display = true; +
[Qemu-devel] [PATCH v2 05/10] vnc: allow binding servers to qemu consoles
This patch adds a display= parameter to the vnc options. This allows to bind a vnc server instance to a specific display, allowing to create a multiseat setup with a vnc server for each seat. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc.c | 50 +++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index cf8bed8..210a115 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -27,6 +27,7 @@ #include vnc.h #include vnc-jobs.h #include trace.h +#include hw/qdev.h #include sysemu/sysemu.h #include qemu/sockets.h #include qemu/timer.h @@ -1665,7 +1666,8 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) vs-modifiers_state[keycode] = 0; break; case 0x02 ... 0x0a: /* '1' to '9' keys */ -if (down vs-modifiers_state[0x1d] vs-modifiers_state[0x38]) { +if (vs-vd-dcl.con == NULL +down vs-modifiers_state[0x1d] vs-modifiers_state[0x38]) { /* Reset the modifiers sent to the current console */ reset_keys(vs); console_select(keycode - 0x02); @@ -2073,8 +2075,8 @@ static void set_pixel_format(VncState *vs, set_pixel_conversion(vs); -graphic_hw_invalidate(NULL); -graphic_hw_update(NULL); +graphic_hw_invalidate(vs-vd-dcl.con); +graphic_hw_update(vs-vd-dcl.con); } static void pixel_format_message (VncState *vs) { @@ -2801,7 +2803,7 @@ static void vnc_refresh(DisplayChangeListener *dcl) return; } -graphic_hw_update(NULL); +graphic_hw_update(vd-dcl.con); if (vnc_trylock_display(vd)) { update_displaychangelistener(vd-dcl, VNC_REFRESH_INTERVAL_BASE); @@ -2907,7 +2909,7 @@ void vnc_init_state(VncState *vs) QTAILQ_INSERT_HEAD(vd-clients, vs, next); -graphic_hw_update(NULL); +graphic_hw_update(vd-dcl.con); vnc_write(vs, RFB 003.008\n, 12); vnc_flush(vs); @@ -2930,7 +2932,7 @@ static void vnc_listen_read(void *opaque, bool websocket) int csock; /* Catch-up */ -graphic_hw_update(NULL); +graphic_hw_update(vs-dcl.con); #ifdef CONFIG_VNC_WS if (websocket) { csock = qemu_accept(vs-lwebsock, (struct sockaddr *)addr, addrlen); @@ -3089,6 +3091,12 @@ static QemuOptsList qemu_vnc_opts = { .name = share, .type = QEMU_OPT_STRING, },{ +.name = display, +.type = QEMU_OPT_STRING, +},{ +.name = head, +.type = QEMU_OPT_NUMBER, +},{ .name = password, .type = QEMU_OPT_BOOL, },{ @@ -3124,7 +3132,8 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vs = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(qemu_vnc_opts, id); -const char *display, *websocket, *share; +const char *display, *websocket, *share, *device_id; +QemuConsole *con; int password = 0; int reverse = 0; #ifdef CONFIG_VNC_TLS @@ -3353,6 +3362,33 @@ void vnc_display_open(const char *id, Error **errp) #endif vs-lock_key_sync = lock_key_sync; +device_id = qemu_opt_get(opts, display); +if (device_id) { +DeviceState *dev; +int head = qemu_opt_get_number(opts, head, 0); + +dev = qdev_find_recursive(sysbus_get_default(), device_id); +if (dev == NULL) { +error_set(errp, QERR_DEVICE_NOT_FOUND, device_id); +goto fail; +} + +con = qemu_console_lookup_by_device(dev, head); +if (con == NULL) { +error_setg(errp, Device %s is not bound to a QemuConsole, + device_id); +goto fail; +} +} else { +con = NULL; +} + +if (con != vs-dcl.con) { +unregister_displaychangelistener(vs-dcl); +vs-dcl.con = con; +register_displaychangelistener(vs-dcl); +} + if (reverse) { /* connect to viewer */ int csock; -- 1.8.3.1
[Qemu-devel] [PATCH v2 03/10] vnc: add display id to acl names
In case the display id is default (which is the one you get if you don't explicitly assign one) we keep the old name scheme, without display, for backward compatibility reasons. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc.c | 22 -- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index fce4861..1b86365 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3206,18 +3206,36 @@ void vnc_display_open(const char *id, const char *display, Error **errp) #ifdef CONFIG_VNC_TLS if (acl x509 vs-tls.x509verify) { -if (!(vs-tls.acl = qemu_acl_init(vnc.x509dname))) { +char *aclname; + +if (strcmp(vs-id, default) == 0) { +aclname = g_strdup(vnc.x509dname); +} else { +aclname = g_strdup_printf(vnc.%s.x509dname, vs-id); +} +vs-tls.acl = qemu_acl_init(aclname); +if (!vs-tls.acl) { fprintf(stderr, Failed to create x509 dname ACL\n); exit(1); } +g_free(aclname); } #endif #ifdef CONFIG_VNC_SASL if (acl sasl) { -if (!(vs-sasl.acl = qemu_acl_init(vnc.username))) { +char *aclname; + +if (strcmp(vs-id, default) == 0) { +aclname = g_strdup(vnc.username); +} else { +aclname = g_strdup_printf(vnc.%s.username, vs-id); +} +vs-sasl.acl = qemu_acl_init(aclname); +if (!vs-sasl.acl) { fprintf(stderr, Failed to create username ACL\n); exit(1); } +g_free(aclname); } #endif -- 1.8.3.1
[Qemu-devel] [PATCH v2 08/10] vnc: factor out qmp_query_client_list
so we can reuse it for the new vnc query command. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- ui/vnc.c | 30 +++--- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 8d189e7..d04802c 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -385,6 +385,20 @@ static VncDisplay *vnc_display_find(const char *id) return NULL; } +static VncClientInfoList *qmp_query_client_list(VncDisplay *vd) +{ +VncClientInfoList *cinfo, *prev = NULL; +VncState *client; + +QTAILQ_FOREACH(client, vd-clients, next) { +cinfo = g_new0(VncClientInfoList, 1); +cinfo-value = qmp_query_vnc_client(client); +cinfo-next = prev; +prev = cinfo; +} +return prev; +} + VncInfo *qmp_query_vnc(Error **errp) { VncInfo *info = g_malloc0(sizeof(*info)); @@ -393,30 +407,16 @@ VncInfo *qmp_query_vnc(Error **errp) if (vd == NULL || vd-display == NULL) { info-enabled = false; } else { -VncClientInfoList *cur_item = NULL; struct sockaddr_storage sa; socklen_t salen = sizeof(sa); char host[NI_MAXHOST]; char serv[NI_MAXSERV]; -VncState *client; info-enabled = true; /* for compatibility with the original command */ info-has_clients = true; - -QTAILQ_FOREACH(client, vd-clients, next) { -VncClientInfoList *cinfo = g_malloc0(sizeof(*info)); -cinfo-value = qmp_query_vnc_client(client); - -/* XXX: waiting for the qapi to support GSList */ -if (!cur_item) { -info-clients = cur_item = cinfo; -} else { -cur_item-next = cinfo; -cur_item = cinfo; -} -} +info-clients = qmp_query_client_list(vd); if (vd-lsock == -1) { return info; -- 1.8.3.1
Re: [Qemu-devel] [PATCH] vt82c686: avoid out-of-bounds read
On 10/12/2014 10:31, zhanghailiang wrote: Hi paolo, Will this change affects the migration? I noticed that there is a member 'SuperIOConfig superio_conf' in VT82C686BState. vt82c686 seems only to be used in mips64el target, Do we support migration for mips target? No, there is no VMState for superio_conf. Paolo
Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] vt82c686: fix coverity warning about out-of-bounds write
On 10/12/2014 09:57, Michael Tokarev wrote: 09.12.2014 10:15, zhanghailiang wrote: Refactor superio_ioport_writeb to fix the out of bounds write warning. Is it just a warning, or real oob write? From the code it looks like it's just a warning... [] + +} +if (can_write == true) { 09.12.2014 17:08, Paolo Bonzini wrote: Michael, can you remove == true when applying this patch? Sure, just did. Does it mean I can add your R-b too? ;) Yes, please do. Paolo
Re: [Qemu-devel] [Qemu-trivial] [PATCH] pflash_cfi02.c: associate cfi.pflash02 to Storage devices category
On 10/12/2014 10:11, Michael Tokarev wrote: 07.12.2014 21:20, Antony Pavlov wrote: Signed-off-by: Antony Pavlov antonynpav...@gmail.com --- hw/block/pflash_cfi02.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 8513a17..389b4aa 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -744,6 +744,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data) dc-realize = pflash_cfi02_realize; dc-props = pflash_cfi02_properties; +set_bit(DEVICE_CATEGORY_STORAGE, dc-categories); } static const TypeInfo pflash_cfi02_info = { Hm. While the patch itself is trivial, and it _seems_ it fixes a bug, I'm not sure of possible effects of this. What prob it has now, does this device work? If yes, why it needs fixing? Do we care about compatibility with previous versions, about migration? This affects nothing but help messages. Paolo
Re: [Qemu-devel] [PATCH] block: fix big write
On 10/12/2014 02:41, Ming Lei wrote: On Wed, Dec 10, 2014 at 1:45 AM, Paolo Bonzini pbonz...@redhat.com wrote: On 08/12/2014 08:19, Ming Lei wrote: Alternatively, I'd accept a SCSI patch setting max_ws_blocks and friends to 2GB - 1 block. It should be better to not introduce the limit and split the writes into size of 2GB - 1 block since there is only the limit for write zero. Why? That's exactly what the max_ws_blocks is for, and there's code in the guest already to do the split. We're talking about 2GB, not 1MB. The split in write same does not cover write zero, and that is the problem. Otherwise write same just works fine. That said write same of QEMU SCSI can work well without max write same sectors limit. If we introduce the limit of max write same sectors, this limit will be put on both write zero and write non-zero path. Yeah, but the 2GB limit happens also for the regular I/O path. The quirk is that it doesn't happen for non-zero WRITE SAME, not the other way round. Also MAXIMUM WRITE SAME LENGTH is just introduced on sbc3r35 in Jan, 2013, and some old host drivers may not support it, and not using the limit should have better compatibility. Again, we're talking of 2GB and this is something that should never happen in practice. I'll write the patch myself. Paolo Thanks, Ming Lei
[Qemu-devel] [Bug 1385934] Re: USB with passthrougth guest cannot enumerate USB host
Can you check if the same error messages appear in /var/log/syslog and /var/log/libvirt/qemu/machine.log as I described in bug #1392504? Because I think it is apparmor related. -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1385934 Title: USB with passthrougth guest cannot enumerate USB host Status in QEMU: New Bug description: Following the guide at http://www.linux-kvm.org/page/USB_Host_Device_Assigned_to_Guest Qemu is launched with qemu-system-x86_64 /dev/vgstripe/kvm_wifi -enable-kvm -m 512 -k fr -net nic -net tap,ifname=tap1,script=/bin/ifup.script -kernel /usr/src/linux_git/arch/x86_64/boot/bzImage -append root=/dev/sda -usb -device usb-host,hostbus=1,hostaddr=6 The USB device does not show and USB stack seems not working On the guest: dmesg |grep -i usb [1.416966] hub 1-0:1.0: USB hub found [1.420431] usbcore: registered new interface driver usb-storage [1.445374] usbcore: registered new interface driver usbhid [1.446839] usbhid: USB HID core driver [1.863226] usb 1-1: new low-speed USB device number 2 using uhci_hcd [2.126173] usb 1-1: Invalid ep0 maxpacket: 64 [2.373161] usb 1-1: new low-speed USB device number 3 using uhci_hcd [2.648112] usb 1-1: Invalid ep0 maxpacket: 64 [2.892404] usb 1-1: new low-speed USB device number 4 using uhci_hcd [2.913001] usb 1-1: Invalid ep0 maxpacket: 64 [3.161367] usb 1-1: new low-speed USB device number 5 using uhci_hcd [3.180070] usb 1-1: Invalid ep0 maxpacket: 64 [3.181633] usb usb1-port1: unable to enumerate USB device lsusb Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub On the host: lsusb Bus 001 Device 006: ID 0457:0163 Silicon Integrated Systems Corp. SiS163U 802.11 Wireless LAN Adapter qemu-system-x86_64 --version QEMU emulator version 2.1.2, Copyright (c) 2003-2008 Fabrice Bellard To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1385934/+subscriptions
[Qemu-devel] [Bug 1392504] Re: USB Passthrough is not working anymore
Found the following lines in /var/log/libvirt/qemu/machine.log libusbx: error [_get_usbfs_fd] libusbx couldn't open USB device /dev/bus/usb/001/004: Permission denied libusbx: error [_get_usbfs_fd] libusbx requires write access to USB device nodes. libusbx: error [_get_usbfs_fd] libusbx couldn't open USB device /dev/bus/usb/001/004: Permission denied libusbx: error [_get_usbfs_fd] libusbx requires write access to USB device nodes. libusbx: error [_get_usbfs_fd] libusbx couldn't open USB device /dev/bus/usb/001/004: Permission denied libusbx: error [_get_usbfs_fd] libusbx requires write access to USB device nodes. -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1392504 Title: USB Passthrough is not working anymore Status in QEMU: New Status in qemu package in Ubuntu: Incomplete Bug description: After upgrading from Ubuntu 14.04 to Ubuntu 14.10 USB passthrough in QEMU (version is now 2.1.0 - Debian2.1+dfsg-4ubuntu6.1) is not working any more. Already tried to remove and attach the USB devices. I use 1 USB2 HDD + 1 USB3 HDD to a virtual linux machine; 1 USB2 HDD to a virual FNAS machine and a USB 2camera to virtual Win7 machine. All these devices are not working any more. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1392504/+subscriptions
Re: [Qemu-devel] [PATCH RESEND for 2.3 4/6] xbzrle: check 8 bytes at a time after an concurrency scene
On (Wed) 10 Dec 2014 [11:55:49], ChenLiang wrote: On 2014/12/10 11:18, Amit Shah wrote: On (Mon) 24 Nov 2014 [19:55:50], arei.gong...@huawei.com wrote: From: ChenLiang chenlian...@huawei.com The logic of old code is correct. But Checking byte by byte will consume time after an concurrency scene. Signed-off-by: ChenLiang chenlian...@huawei.com Signed-off-by: Gonglei arei.gong...@huawei.com --- xbzrle.c | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/xbzrle.c b/xbzrle.c index d27a140..0477367 100644 --- a/xbzrle.c +++ b/xbzrle.c @@ -50,16 +50,24 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, /* word at a time for speed */ if (!res) { -while (i slen - (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { -i += sizeof(long); -zrun_len += sizeof(long); -} - -/* go over the rest */ -while (i slen old_buf[i] == new_buf[i]) { -zrun_len++; -i++; +while (i slen) { +if ((*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { +i += sizeof(long); +zrun_len += sizeof(long); +} else { +/* go over the rest */ +for (j = 0; j sizeof(long); j++) { +if (old_buf[i] == new_buf[i]) { +i++; +zrun_len++; I don't see how this is different from the code it's replacing. The check and increments are all the same. Difficult to see why there'll be a speed benefit. Can you please explain? Do you have any performance numbers for before/after? Thanks, Amit . Hi Amit: +for (j = 0; j sizeof(long); j++) { +if (old_buf[i] == new_buf[i]) { +i++; +zrun_len++; +} else { +break; +} +} +if (j != sizeof(long)) { +break; +} The branch of *j != sizeof(long)* may not be hit after an concurrency scene. so we can continue doing (*(long *)(old_buf + i)) == (*(long *)(new_buf + i)). On the another side the old code does old_buf[i] == new_buf[i]. Frankly, I still don't see it. Earlier: while.. match words while.. match bytes Now: while.. match words if word mismatch match bytes to me, essentially looks the same. I'll propose to drop this patch till we have a proper justification. Amit
[Qemu-devel] [PATCH v2 02/10] vnc: remove unused DisplayState parameter, add id instead.
DisplayState isn't used anywhere, drop it. Add the vnc server ID as parameter instead, so it is possible to specify the server instance. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- include/ui/console.h | 16 ui/vnc.c | 29 ++--- vl.c | 7 --- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 22ef8ca..5ff2e27 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -327,19 +327,19 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame); void cocoa_display_init(DisplayState *ds, int full_screen); /* vnc.c */ -void vnc_display_init(DisplayState *ds); -void vnc_display_open(DisplayState *ds, const char *display, Error **errp); -void vnc_display_add_client(DisplayState *ds, int csock, bool skipauth); -char *vnc_display_local_addr(DisplayState *ds); +void vnc_display_init(const char *id); +void vnc_display_open(const char *id, const char *display, Error **errp); +void vnc_display_add_client(const char *id, int csock, bool skipauth); +char *vnc_display_local_addr(const char *id); #ifdef CONFIG_VNC -int vnc_display_password(DisplayState *ds, const char *password); -int vnc_display_pw_expire(DisplayState *ds, time_t expires); +int vnc_display_password(const char *id, const char *password); +int vnc_display_pw_expire(const char *id, time_t expires); #else -static inline int vnc_display_password(DisplayState *ds, const char *password) +static inline int vnc_display_password(const char *id, const char *password) { return -ENODEV; } -static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires) +static inline int vnc_display_pw_expire(const char *id, time_t expires) { return -ENODEV; }; diff --git a/ui/vnc.c b/ui/vnc.c index a6549c8..fce4861 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2967,10 +2967,11 @@ static const DisplayChangeListenerOps dcl_ops = { .dpy_cursor_define = vnc_dpy_cursor_define, }; -void vnc_display_init(DisplayState *ds) +void vnc_display_init(const char *id) { VncDisplay *vs = g_malloc0(sizeof(*vs)); +vs-id = strdup(id); QTAILQ_INSERT_TAIL(vnc_displays, vs, next); vs-lsock = -1; @@ -2999,10 +3000,8 @@ void vnc_display_init(DisplayState *ds) } -static void vnc_display_close(DisplayState *ds) +static void vnc_display_close(VncDisplay *vs) { -VncDisplay *vs = vnc_display_find(NULL); - if (!vs) return; g_free(vs-display); @@ -3028,9 +3027,9 @@ static void vnc_display_close(DisplayState *ds) #endif } -int vnc_display_password(DisplayState *ds, const char *password) +int vnc_display_password(const char *id, const char *password) { -VncDisplay *vs = vnc_display_find(NULL); +VncDisplay *vs = vnc_display_find(id); if (!vs) { return -EINVAL; @@ -3047,9 +3046,9 @@ int vnc_display_password(DisplayState *ds, const char *password) return 0; } -int vnc_display_pw_expire(DisplayState *ds, time_t expires) +int vnc_display_pw_expire(const char *id, time_t expires) { -VncDisplay *vs = vnc_display_find(NULL); +VncDisplay *vs = vnc_display_find(id); if (!vs) { return -EINVAL; @@ -3059,16 +3058,16 @@ int vnc_display_pw_expire(DisplayState *ds, time_t expires) return 0; } -char *vnc_display_local_addr(DisplayState *ds) +char *vnc_display_local_addr(const char *id) { -VncDisplay *vs = vnc_display_find(NULL); +VncDisplay *vs = vnc_display_find(id); return vnc_socket_local_addr(%s:%s, vs-lsock); } -void vnc_display_open(DisplayState *ds, const char *display, Error **errp) +void vnc_display_open(const char *id, const char *display, Error **errp) { -VncDisplay *vs = vnc_display_find(NULL); +VncDisplay *vs = vnc_display_find(id); const char *options; int password = 0; int reverse = 0; @@ -3088,7 +3087,7 @@ void vnc_display_open(DisplayState *ds, const char *display, Error **errp) error_setg(errp, VNC display not active); return; } -vnc_display_close(ds); +vnc_display_close(vs); if (strcmp(display, none) == 0) return; @@ -3381,9 +3380,9 @@ fail: #endif /* CONFIG_VNC_WS */ } -void vnc_display_add_client(DisplayState *ds, int csock, bool skipauth) +void vnc_display_add_client(const char *id, int csock, bool skipauth) { -VncDisplay *vs = vnc_display_find(NULL); +VncDisplay *vs = vnc_display_find(id); if (!vs) { return; diff --git a/vl.c b/vl.c index eb89d62..08b73ee 100644 --- a/vl.c +++ b/vl.c @@ -4323,8 +4323,9 @@ int main(int argc, char **argv, char **envp) /* init remote displays */ if (vnc_display) { Error *local_err = NULL; -vnc_display_init(ds); -vnc_display_open(ds, vnc_display, local_err); +const char *id = default; +vnc_display_init(id); +vnc_display_open(id, vnc_display, local_err); if (local_err != NULL)
[Qemu-devel] [PATCH] scsi-disk: provide maximum transfer length
The QEMU block layer has a limit of INT_MAX bytes per transfer. Expose it in the block limits VPD page for both regular transfers and WRITE SAME. Reported-by: Ming Lei ming@canonical.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com --- hw/scsi/scsi-disk.c | 27 +++ 1 file changed, 27 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 2f75d7d..f65618d 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -49,6 +49,7 @@ do { printf(scsi-disk: fmt , ## __VA_ARGS__); } while (0) #define DEFAULT_DISCARD_GRANULARITY 4096 #define DEFAULT_MAX_UNMAP_SIZE (1 30) /* 1 GB */ +#define DEFAULT_MAX_IO_SIZE INT_MAX /* 2 GB - 1 block */ typedef struct SCSIDiskState SCSIDiskState; @@ -79,6 +80,7 @@ struct SCSIDiskState uint64_t port_wwn; uint16_t port_index; uint64_t max_unmap_size; +uint64_t max_io_size; QEMUBH *bh; char *version; char *serial; @@ -635,6 +637,8 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) s-qdev.conf.opt_io_size / s-qdev.blocksize; unsigned int max_unmap_sectors = s-max_unmap_size / s-qdev.blocksize; +unsigned int max_io_sectors = +s-max_io_size / s-qdev.blocksize; if (s-qdev.type == TYPE_ROM) { DPRINTF(Inquiry (EVPD[%02X] not supported for CDROM\n, @@ -651,6 +655,12 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[6] = (min_io_size 8) 0xff; outbuf[7] = min_io_size 0xff; +/* maximum transfer length */ +outbuf[8] = (max_io_sectors 24) 0xff; +outbuf[9] = (max_io_sectors 16) 0xff; +outbuf[10] = (max_io_sectors 8) 0xff; +outbuf[11] = max_io_sectors 0xff; + /* optimal transfer length */ outbuf[12] = (opt_io_size 24) 0xff; outbuf[13] = (opt_io_size 16) 0xff; @@ -674,6 +684,17 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[29] = (unmap_sectors 16) 0xff; outbuf[30] = (unmap_sectors 8) 0xff; outbuf[31] = unmap_sectors 0xff; + +/* max write same size */ +outbuf[36] = 0; +outbuf[37] = 0; +outbuf[38] = 0; +outbuf[39] = 0; + +outbuf[40] = (max_io_sectors 24) 0xff; +outbuf[41] = (max_io_sectors 16) 0xff; +outbuf[42] = (max_io_sectors 8) 0xff; +outbuf[43] = max_io_sectors 0xff; break; } case 0xb2: /* thin provisioning */ @@ -2579,6 +2600,8 @@ static Property scsi_hd_properties[] = { DEFINE_PROP_UINT16(port_index, SCSIDiskState, port_index, 0), DEFINE_PROP_UINT64(max_unmap_size, SCSIDiskState, max_unmap_size, DEFAULT_MAX_UNMAP_SIZE), +DEFINE_PROP_UINT64(max_io_size, SCSIDiskState, max_io_size, + DEFAULT_MAX_IO_SIZE), DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), }; @@ -2625,6 +2648,8 @@ static Property scsi_cd_properties[] = { DEFINE_PROP_UINT64(wwn, SCSIDiskState, wwn, 0), DEFINE_PROP_UINT64(port_wwn, SCSIDiskState, port_wwn, 0), DEFINE_PROP_UINT16(port_index, SCSIDiskState, port_index, 0), +DEFINE_PROP_UINT64(max_io_size, SCSIDiskState, max_io_size, + DEFAULT_MAX_IO_SIZE), DEFINE_PROP_END_OF_LIST(), }; @@ -2690,6 +2715,8 @@ static Property scsi_disk_properties[] = { DEFINE_PROP_UINT16(port_index, SCSIDiskState, port_index, 0), DEFINE_PROP_UINT64(max_unmap_size, SCSIDiskState, max_unmap_size, DEFAULT_MAX_UNMAP_SIZE), +DEFINE_PROP_UINT64(max_io_size, SCSIDiskState, max_io_size, + DEFAULT_MAX_IO_SIZE), DEFINE_PROP_END_OF_LIST(), }; -- 1.8.3.1
[Qemu-devel] [PULL 06/73] chardev: Add -qmp-pretty
From: Max Reitz mre...@redhat.com Add a command line option for adding a QMP monitor using pretty JSON formatting. Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- qemu-options.hx | 8 vl.c| 15 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index 64af16d..6f273ee 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2790,6 +2790,14 @@ STEXI @findex -qmp Like -monitor but opens in 'control' mode. ETEXI +DEF(qmp-pretty, HAS_ARG, QEMU_OPTION_qmp_pretty, \ +-qmp-pretty dev like -qmp but uses pretty JSON formatting\n, +QEMU_ARCH_ALL) +STEXI +@item -qmp-pretty @var{dev} +@findex -qmp-pretty +Like -qmp but uses pretty JSON formatting. +ETEXI DEF(mon, HAS_ARG, QEMU_OPTION_mon, \ -mon [chardev=]name[,mode=readline|control][,default]\n, QEMU_ARCH_ALL) diff --git a/vl.c b/vl.c index eb89d62..f1a5d66 100644 --- a/vl.c +++ b/vl.c @@ -2284,7 +2284,7 @@ static int mon_init_func(QemuOpts *opts, void *opaque) return 0; } -static void monitor_parse(const char *optarg, const char *mode) +static void monitor_parse(const char *optarg, const char *mode, bool pretty) { static int monitor_device_index = 0; QemuOpts *opts; @@ -2314,6 +2314,7 @@ static void monitor_parse(const char *optarg, const char *mode) } qemu_opt_set(opts, mode, mode); qemu_opt_set(opts, chardev, label); +qemu_opt_set_bool(opts, pretty, pretty); if (def) qemu_opt_set(opts, default, on); monitor_device_index++; @@ -3292,11 +3293,15 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_monitor: default_monitor = 0; if (strncmp(optarg, none, 4)) { -monitor_parse(optarg, readline); +monitor_parse(optarg, readline, false); } break; case QEMU_OPTION_qmp: -monitor_parse(optarg, control); +monitor_parse(optarg, control, false); +default_monitor = 0; +break; +case QEMU_OPTION_qmp_pretty: +monitor_parse(optarg, control, true); default_monitor = 0; break; case QEMU_OPTION_mon: @@ -3994,7 +3999,7 @@ int main(int argc, char **argv, char **envp) add_device_config(DEV_SCLP, stdio); } if (default_monitor) -monitor_parse(stdio, readline); +monitor_parse(stdio, readline, false); } } else { if (default_serial) @@ -4002,7 +4007,7 @@ int main(int argc, char **argv, char **envp) if (default_parallel) add_device_config(DEV_PARALLEL, vc:80Cx24C); if (default_monitor) -monitor_parse(vc:80Cx24C, readline); +monitor_parse(vc:80Cx24C, readline, false); if (default_virtcon) add_device_config(DEV_VIRTCON, vc:80Cx24C); if (default_sclp) { -- 1.8.3.1
[Qemu-devel] [PULL 01/73] block: Add bdrv_next_node
From: Fam Zheng f...@redhat.com Similar to bdrv_next, this traverses through graph_bdrv_states. Will be useful to enumerate all the named nodes. Signed-off-by: Fam Zheng f...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c | 8 include/block/block.h | 1 + 2 files changed, 9 insertions(+) diff --git a/block.c b/block.c index a612594..e8a0342 100644 --- a/block.c +++ b/block.c @@ -3801,6 +3801,14 @@ bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base) return top != NULL; } +BlockDriverState *bdrv_next_node(BlockDriverState *bs) +{ +if (!bs) { +return QTAILQ_FIRST(graph_bdrv_states); +} +return QTAILQ_NEXT(bs, node_list); +} + BlockDriverState *bdrv_next(BlockDriverState *bs) { if (!bs) { diff --git a/include/block/block.h b/include/block/block.h index 5450610..c3a68d8 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -374,6 +374,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device, const char *node_name, Error **errp); bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base); +BlockDriverState *bdrv_next_node(BlockDriverState *bs); BlockDriverState *bdrv_next(BlockDriverState *bs); int bdrv_is_encrypted(BlockDriverState *bs); int bdrv_key_required(BlockDriverState *bs); -- 1.8.3.1
[Qemu-devel] [PULL 09/73] blockdev: acquire AioContext in blockdev-snapshot-delete-internal-sync
From: Stefan Hajnoczi stefa...@redhat.com Add dataplane support to the blockdev-snapshot-delete-internal-sync QMP command. By acquiring the AioContext we avoid race conditions with the dataplane thread which may also be accessing the BlockDriverState. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 16 +--- hw/block/dataplane/virtio-blk.c | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 57910b8..fb9a005 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1105,6 +1105,7 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, Error **errp) { BlockDriverState *bs = bdrv_find(device); +AioContext *aio_context; QEMUSnapshotInfo sn; Error *local_err = NULL; SnapshotInfo *info = NULL; @@ -1128,25 +1129,30 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, return NULL; } +aio_context = bdrv_get_aio_context(bs); +aio_context_acquire(aio_context); + ret = bdrv_snapshot_find_by_id_and_name(bs, id, name, sn, local_err); if (local_err) { error_propagate(errp, local_err); -return NULL; +goto out_aio_context; } if (!ret) { error_setg(errp, Snapshot with id '%s' and name '%s' does not exist on device '%s', STR_OR_NULL(id), STR_OR_NULL(name), device); -return NULL; +goto out_aio_context; } bdrv_snapshot_delete(bs, id, name, local_err); if (local_err) { error_propagate(errp, local_err); -return NULL; +goto out_aio_context; } +aio_context_release(aio_context); + info = g_new0(SnapshotInfo, 1); info-id = g_strdup(sn.id_str); info-name = g_strdup(sn.name); @@ -1157,6 +1163,10 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, info-vm_clock_sec = sn.vm_clock_nsec / 10; return info; + +out_aio_context: +aio_context_release(aio_context); +return NULL; } /* New and old BlockDriverState structs for group snapshots */ diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 1222a37..5ab64c5 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -198,6 +198,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_BACKUP_SOURCE, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_COMMIT, s-blocker); +blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE, + s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_MIRROR, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_STREAM, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_REPLACE, s-blocker); -- 1.8.3.1
[Qemu-devel] [PULL 07/73] iotests: _filter_qmp for pretty JSON output
From: Max Reitz mre...@redhat.com _filter_qmp should be able to correctly filter out the QMP version object for pretty JSON output. Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/common.filter | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter index 3acdb30..dfb9726 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -167,7 +167,9 @@ _filter_qmp() { _filter_win32 | \ sed -e 's#\(\(micro\)\?seconds: \)[0-9]\+#\1 TIMESTAMP#g' \ --e 's#^{QMP:.*}$#QMP_VERSION#' +-e 's#^{QMP:.*}$#QMP_VERSION#' \ +-e '/^QMP: {\s*$/, /^}\s*$/ c\' \ +-e 'QMP_VERSION' } # replace driver-specific options in the Formatting... line -- 1.8.3.1
[Qemu-devel] [PULL 15/73] block/hmp: Allow info = NULL in print_block_info()
This allows printing infos of BlockDriverStates that aren't at the root of the graph (and logically implementing a BlockBackend). Signed-off-by: Kevin Wolf kw...@redhat.com --- hmp.c | 34 +- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/hmp.c b/hmp.c index 2e2b91b..05ccf5f 100644 --- a/hmp.c +++ b/hmp.c @@ -295,7 +295,21 @@ static void print_block_info(Monitor *mon, BlockInfo *info, { ImageInfo *image_info; -monitor_printf(mon, %s, info-device); +assert(!info || !info-has_inserted || info-inserted == inserted); + +if (info) { +monitor_printf(mon, %s, info-device); +if (inserted inserted-has_node_name) { +monitor_printf(mon, (%s), inserted-node_name); +} +} else { +assert(inserted); +monitor_printf(mon, %s, + inserted-has_node_name + ? inserted-node_name + : anonymous); +} + if (inserted) { monitor_printf(mon, : %s (%s%s%s)\n, inserted-file, @@ -306,15 +320,17 @@ static void print_block_info(Monitor *mon, BlockInfo *info, monitor_printf(mon, : [not inserted]\n); } -if (info-has_io_status info-io_status != BLOCK_DEVICE_IO_STATUS_OK) { -monitor_printf(mon, I/O status: %s\n, - BlockDeviceIoStatus_lookup[info-io_status]); -} +if (info) { +if (info-has_io_status info-io_status != BLOCK_DEVICE_IO_STATUS_OK) { +monitor_printf(mon, I/O status: %s\n, + BlockDeviceIoStatus_lookup[info-io_status]); +} -if (info-removable) { -monitor_printf(mon, Removable device: %slocked, tray %s\n, - info-locked ? : not , - info-tray_open ? open : closed); +if (info-removable) { +monitor_printf(mon, Removable device: %slocked, tray %s\n, + info-locked ? : not , + info-tray_open ? open : closed); +} } -- 1.8.3.1
[Qemu-devel] [PULL 02/73] block: Add bdrv_get_node_name
From: Fam Zheng f...@redhat.com This returns the node name of a BDS. Remove the TODO comment and expect the callers to be explicit. Signed-off-by: Fam Zheng f...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c | 5 + include/block/block.h | 1 + 2 files changed, 6 insertions(+) diff --git a/block.c b/block.c index e8a0342..866c8b4 100644 --- a/block.c +++ b/block.c @@ -3817,6 +3817,11 @@ BlockDriverState *bdrv_next(BlockDriverState *bs) return QTAILQ_NEXT(bs, device_list); } +const char *bdrv_get_node_name(const BlockDriverState *bs) +{ +return bs-node_name; +} + /* TODO check what callers really want: bs-node_name or blk_name() */ const char *bdrv_get_device_name(const BlockDriverState *bs) { diff --git a/include/block/block.h b/include/block/block.h index c3a68d8..610be9f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -382,6 +382,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key); int bdrv_query_missing_keys(void); void bdrv_iterate_format(void (*it)(void *opaque, const char *name), void *opaque); +const char *bdrv_get_node_name(const BlockDriverState *bs); const char *bdrv_get_device_name(const BlockDriverState *bs); int bdrv_get_flags(BlockDriverState *bs); int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num, -- 1.8.3.1
[Qemu-devel] [PULL 03/73] block: Include node-name if present in query-blockstats
From: Fam Zheng f...@redhat.com Node name is a better identifier of BDS. We will want to query statistics of a BDS node buried in the BDS graph, so reporting the node's name if there is one will do the trick. Signed-off-by: Fam Zheng f...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/qapi.c | 5 + qapi/block-core.json | 5 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/block/qapi.c b/block/qapi.c index a87a34a..d70336a 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -311,6 +311,11 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs) s-device = g_strdup(bdrv_get_device_name(bs)); } +if (bdrv_get_node_name(bs)[0]) { +s-has_node_name = true; +s-node_name = g_strdup(bdrv_get_node_name(bs)); +} + s-stats = g_malloc0(sizeof(*s-stats)); s-stats-rd_bytes = bs-stats.nr_bytes[BLOCK_ACCT_READ]; s-stats-wr_bytes = bs-stats.nr_bytes[BLOCK_ACCT_WRITE]; diff --git a/qapi/block-core.json b/qapi/block-core.json index a14e6ab..de1bd45 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -405,6 +405,8 @@ # @device: #optional If the stats are for a virtual block device, the name # corresponding to the virtual block device. # +# @device: #optional The node name of the device. (Since 2.3) +# # @stats: A @BlockDeviceStats for the device. # # @parent: #optional This describes the file block device if it has one. @@ -415,7 +417,8 @@ # Since: 0.14.0 ## { 'type': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', + 'data': {'*device': 'str', '*node-name': 'str', + 'stats': 'BlockDeviceStats', '*parent': 'BlockStats', '*backing': 'BlockStats'} } -- 1.8.3.1
[Qemu-devel] [PULL 11/73] blockdev: acquire AioContext in eject, change, and block_passwd
From: Stefan Hajnoczi stefa...@redhat.com By acquiring the AioContext we avoid race conditions with the dataplane thread which may also be accessing the BlockDriverState. Fix up eject, change, and block_passwd in a single patch because qmp_eject() and qmp_change_blockdev() both call eject_device(). Also fix block_passwd while we're tackling a command that takes a block encryption password. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 36 +--- hw/block/dataplane/virtio-blk.c | 1 + 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/blockdev.c b/blockdev.c index a7f1e09..7bf88d4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1617,14 +1617,18 @@ exit: static void eject_device(BlockBackend *blk, int force, Error **errp) { BlockDriverState *bs = blk_bs(blk); +AioContext *aio_context; + +aio_context = bdrv_get_aio_context(bs); +aio_context_acquire(aio_context); if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) { -return; +goto out; } if (!blk_dev_has_removable_media(blk)) { error_setg(errp, Device '%s' is not removable, bdrv_get_device_name(bs)); -return; +goto out; } if (blk_dev_is_medium_locked(blk) !blk_dev_is_tray_open(blk)) { @@ -1632,11 +1636,14 @@ static void eject_device(BlockBackend *blk, int force, Error **errp) if (!force) { error_setg(errp, Device '%s' is locked, bdrv_get_device_name(bs)); -return; +goto out; } } bdrv_close(bs); + +out: +aio_context_release(aio_context); } void qmp_eject(const char *device, bool has_force, bool force, Error **errp) @@ -1658,6 +1665,7 @@ void qmp_block_passwd(bool has_device, const char *device, { Error *local_err = NULL; BlockDriverState *bs; +AioContext *aio_context; int err; bs = bdrv_lookup_bs(has_device ? device : NULL, @@ -1668,16 +1676,23 @@ void qmp_block_passwd(bool has_device, const char *device, return; } +aio_context = bdrv_get_aio_context(bs); +aio_context_acquire(aio_context); + err = bdrv_set_key(bs, password); if (err == -EINVAL) { error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); -return; +goto out; } else if (err 0) { error_set(errp, QERR_INVALID_PASSWORD); -return; +goto out; } + +out: +aio_context_release(aio_context); } +/* Assumes AioContext is held */ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename, int bdrv_flags, BlockDriver *drv, const char *password, Error **errp) @@ -1710,6 +1725,7 @@ void qmp_change_blockdev(const char *device, const char *filename, { BlockBackend *blk; BlockDriverState *bs; +AioContext *aio_context; BlockDriver *drv = NULL; int bdrv_flags; Error *err = NULL; @@ -1721,24 +1737,30 @@ void qmp_change_blockdev(const char *device, const char *filename, } bs = blk_bs(blk); +aio_context = bdrv_get_aio_context(bs); +aio_context_acquire(aio_context); + if (format) { drv = bdrv_find_whitelisted_format(format, bs-read_only); if (!drv) { error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); -return; +goto out; } } eject_device(blk, 0, err); if (err) { error_propagate(errp, err); -return; +goto out; } bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR; bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0; qmp_bdrv_open_encrypted(bs, filename, bdrv_flags, drv, NULL, errp); + +out: +aio_context_release(aio_context); } /* throttling disk I/O limits */ diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 5ab64c5..2548113 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -198,6 +198,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_BACKUP_SOURCE, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_COMMIT, s-blocker); +blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_EJECT, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE, s-blocker); blk_op_unblock(conf-conf.blk, BLOCK_OP_TYPE_MIRROR, s-blocker); -- 1.8.3.1
[Qemu-devel] [PULL 10/73] blockdev: check for BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE
From: Stefan Hajnoczi stefa...@redhat.com The BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE op blocker exists but was never used! Let's fix that so snapshot delete can be blocked. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 4 1 file changed, 4 insertions(+) diff --git a/blockdev.c b/blockdev.c index fb9a005..a7f1e09 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1132,6 +1132,10 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); +if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE, errp)) { +goto out_aio_context; +} + ret = bdrv_snapshot_find_by_id_and_name(bs, id, name, sn, local_err); if (local_err) { error_propagate(errp, local_err); -- 1.8.3.1
[Qemu-devel] [PULL 13/73] block/qapi: Add cache information to query-block
Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com --- block/qapi.c | 7 +++ hmp.c | 8 qapi/block-core.json | 20 +++- tests/qemu-iotests/051.out | 1 + tests/qemu-iotests/067.out | 25 + 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/block/qapi.c b/block/qapi.c index 3a14559..fa68ba7 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -40,6 +40,13 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs) info-encrypted = bs-encrypted; info-encryption_key_missing = bdrv_key_required(bs); +info-cache = g_new(BlockdevCacheInfo, 1); +*info-cache = (BlockdevCacheInfo) { +.writeback = bdrv_enable_write_cache(bs), +.direct = !!(bs-open_flags BDRV_O_NOCACHE), +.no_flush = !!(bs-open_flags BDRV_O_NO_FLUSH), +}; + if (bs-node_name[0]) { info-has_node_name = true; info-node_name = g_strdup(bs-node_name); diff --git a/hmp.c b/hmp.c index 94b27df..05c3730 100644 --- a/hmp.c +++ b/hmp.c @@ -294,6 +294,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) { BlockInfoList *block_list, *info; ImageInfo *image_info; +BlockDeviceInfo *inserted; const char *device = qdict_get_try_str(qdict, device); bool verbose = qdict_get_try_bool(qdict, verbose, 0); @@ -335,6 +336,13 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) continue; } +inserted = info-value-inserted; + +monitor_printf(mon, Cache mode: %s%s%s\n, + inserted-cache-writeback ? writeback : writethrough, + inserted-cache-direct ? , direct : , + inserted-cache-no_flush ? , ignore flushes : ); + if (info-value-inserted-has_backing_file) { monitor_printf(mon, Backing file: %s diff --git a/qapi/block-core.json b/qapi/block-core.json index 8e51e78..6e8db15 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -183,6 +183,22 @@ '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } } ## +# @BlockdevCacheInfo +# +# Cache mode information for a block device +# +# @writeback: true if writeback mode is enabled +# @direct: true if the host page cache is bypassed (O_DIRECT) +# @no-flush:true if flush requests are ignored for the device +# +# Since: 2.3 +## +{ 'type': 'BlockdevCacheInfo', + 'data': { 'writeback': 'bool', +'direct': 'bool', +'no-flush': 'bool' } } + +## # @BlockDeviceInfo: # # Information about the backing device for a block device. @@ -239,6 +255,8 @@ # # @iops_size: #optional an I/O size in bytes (Since 1.7) # +# @cache: the cache mode used for the block device (since: 2.3) +# # Since: 0.14.0 # ## @@ -253,7 +271,7 @@ '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', '*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*iops_size': 'int' } } +'*iops_size': 'int', 'cache': 'BlockdevCacheInfo' } } ## # @BlockDeviceIoStatus: diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 2c7e808..7f16134 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -50,6 +50,7 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DI QEMU X.Y.Z monitor - type 'help' for more information (qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K ide0-hd0: TEST_DIR/t.qcow2 (qcow2) +Cache mode: writeback Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1) (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out index 929dc74..7c3735f 100644 --- a/tests/qemu-iotests/067.out +++ b/tests/qemu-iotests/067.out @@ -46,6 +46,11 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti encrypted: false, bps: 0, bps_rd: 0, +cache: { +no-flush: false, +direct: false, +writeback: true +}, file: TEST_DIR/t.qcow2, encryption_key_missing: false }, @@ -216,6 +221,11 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk encrypted: false, bps: 0, bps_rd: 0, +cache: { +no-flush: false, +direct: false, +writeback: true +}, file: TEST_DIR/t.qcow2,
[Qemu-devel] [PULL 17/73] monitor: Fix HMP tab completion
Commands with multiple boolean flag options (like 'info block') didn't provide correct completion because only the first one was skipped. Signed-off-by: Kevin Wolf kw...@redhat.com --- monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index f63a3aa..b37ddda 100644 --- a/monitor.c +++ b/monitor.c @@ -4695,7 +4695,7 @@ static void monitor_find_completion_by_table(Monitor *mon, } } str = args[nb_args - 1]; -if (*ptype == '-' ptype[1] != '\0') { +while (*ptype == '-' ptype[1] != '\0') { ptype = next_arg_type(ptype); } switch(*ptype) { -- 1.8.3.1
[Qemu-devel] [PULL 23/73] block: Add AioContextNotifier functions to BB
From: Max Reitz mre...@redhat.com Because all BlockDriverStates behind a single BlockBackend reside in a single AioContext, it is fine to just pass these functions (blk_add_aio_context_notifier() and blk_remove_aio_context_notifier()) through to the root BlockDriverState. Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1416309679-333-3-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/block-backend.c | 18 ++ include/sysemu/block-backend.h | 8 2 files changed, 26 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 89f69b7..7a7f690 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -624,6 +624,24 @@ void blk_set_aio_context(BlockBackend *blk, AioContext *new_context) bdrv_set_aio_context(blk-bs, new_context); } +void blk_add_aio_context_notifier(BlockBackend *blk, +void (*attached_aio_context)(AioContext *new_context, void *opaque), +void (*detach_aio_context)(void *opaque), void *opaque) +{ +bdrv_add_aio_context_notifier(blk-bs, attached_aio_context, + detach_aio_context, opaque); +} + +void blk_remove_aio_context_notifier(BlockBackend *blk, + void (*attached_aio_context)(AioContext *, + void *), + void (*detach_aio_context)(void *), + void *opaque) +{ +bdrv_remove_aio_context_notifier(blk-bs, attached_aio_context, + detach_aio_context, opaque); +} + void blk_io_plug(BlockBackend *blk) { bdrv_io_plug(blk-bs); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 0c46b82..d9c1337 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -135,6 +135,14 @@ void blk_op_block_all(BlockBackend *blk, Error *reason); void blk_op_unblock_all(BlockBackend *blk, Error *reason); AioContext *blk_get_aio_context(BlockBackend *blk); void blk_set_aio_context(BlockBackend *blk, AioContext *new_context); +void blk_add_aio_context_notifier(BlockBackend *blk, +void (*attached_aio_context)(AioContext *new_context, void *opaque), +void (*detach_aio_context)(void *opaque), void *opaque); +void blk_remove_aio_context_notifier(BlockBackend *blk, + void (*attached_aio_context)(AioContext *, + void *), + void (*detach_aio_context)(void *), + void *opaque); void blk_io_plug(BlockBackend *blk); void blk_io_unplug(BlockBackend *blk); BlockAcctStats *blk_get_stats(BlockBackend *blk); -- 1.8.3.1
[Qemu-devel] [PULL 14/73] block/hmp: Factor out print_block_info()
The new function prints the info for a single BlockDriverState. Signed-off-by: Kevin Wolf kw...@redhat.com --- hmp.c | 192 +- 1 file changed, 97 insertions(+), 95 deletions(-) diff --git a/hmp.c b/hmp.c index 05c3730..2e2b91b 100644 --- a/hmp.c +++ b/hmp.c @@ -290,118 +290,120 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict) qapi_free_CpuInfoList(cpu_list); } -void hmp_info_block(Monitor *mon, const QDict *qdict) +static void print_block_info(Monitor *mon, BlockInfo *info, + BlockDeviceInfo *inserted, bool verbose) { -BlockInfoList *block_list, *info; ImageInfo *image_info; -BlockDeviceInfo *inserted; -const char *device = qdict_get_try_str(qdict, device); -bool verbose = qdict_get_try_bool(qdict, verbose, 0); - -block_list = qmp_query_block(NULL); -for (info = block_list; info; info = info-next) { -if (device strcmp(device, info-value-device)) { -continue; -} +monitor_printf(mon, %s, info-device); +if (inserted) { +monitor_printf(mon, : %s (%s%s%s)\n, + inserted-file, + inserted-drv, + inserted-ro ? , read-only : , + inserted-encrypted ? , encrypted : ); +} else { +monitor_printf(mon, : [not inserted]\n); +} -if (info != block_list) { -monitor_printf(mon, \n); -} +if (info-has_io_status info-io_status != BLOCK_DEVICE_IO_STATUS_OK) { +monitor_printf(mon, I/O status: %s\n, + BlockDeviceIoStatus_lookup[info-io_status]); +} -monitor_printf(mon, %s, info-value-device); -if (info-value-has_inserted) { -monitor_printf(mon, : %s (%s%s%s)\n, - info-value-inserted-file, - info-value-inserted-drv, - info-value-inserted-ro ? , read-only : , - info-value-inserted-encrypted ? , encrypted : ); -} else { -monitor_printf(mon, : [not inserted]\n); -} +if (info-removable) { +monitor_printf(mon, Removable device: %slocked, tray %s\n, + info-locked ? : not , + info-tray_open ? open : closed); +} -if (info-value-has_io_status info-value-io_status != BLOCK_DEVICE_IO_STATUS_OK) { -monitor_printf(mon, I/O status: %s\n, - BlockDeviceIoStatus_lookup[info-value-io_status]); -} -if (info-value-removable) { -monitor_printf(mon, Removable device: %slocked, tray %s\n, - info-value-locked ? : not , - info-value-tray_open ? open : closed); -} +if (!inserted) { +return; +} +monitor_printf(mon, Cache mode: %s%s%s\n, + inserted-cache-writeback ? writeback : writethrough, + inserted-cache-direct ? , direct : , + inserted-cache-no_flush ? , ignore flushes : ); -if (!info-value-has_inserted) { -continue; +if (inserted-has_backing_file) { +monitor_printf(mon, + Backing file: %s + (chain depth: % PRId64 )\n, + inserted-backing_file, + inserted-backing_file_depth); +} + +if (inserted-detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { +monitor_printf(mon, Detect zeroes:%s\n, + BlockdevDetectZeroesOptions_lookup[inserted-detect_zeroes]); +} + +if (inserted-bps || inserted-bps_rd || inserted-bps_wr || +inserted-iops || inserted-iops_rd || inserted-iops_wr) +{ +monitor_printf(mon, I/O throttling: bps=% PRId64 + bps_rd=% PRId64 bps_wr=% PRId64 + bps_max=% PRId64 + bps_rd_max=% PRId64 + bps_wr_max=% PRId64 + iops=% PRId64 iops_rd=% PRId64 + iops_wr=% PRId64 + iops_max=% PRId64 + iops_rd_max=% PRId64 + iops_wr_max=% PRId64 + iops_size=% PRId64 \n, +inserted-bps, +inserted-bps_rd, +inserted-bps_wr, +inserted-bps_max, +inserted-bps_rd_max, +inserted-bps_wr_max, +inserted-iops, +inserted-iops_rd, +inserted-iops_wr, +inserted-iops_max, +inserted-iops_rd_max, +inserted-iops_wr_max, +
[Qemu-devel] [PULL 16/73] block/hmp: Allow node-name in 'info block'
The optional parameter specifying a block device allows now to use a node-name instead of a drive name (and therefore to inspect any node in the graph). The new -n options allows listing all named nodes instead of BlockBackends. Signed-off-by: Kevin Wolf kw...@redhat.com --- hmp.c | 31 ++- monitor.c | 6 +++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/hmp.c b/hmp.c index 05ccf5f..481be80 100644 --- a/hmp.c +++ b/hmp.c @@ -403,10 +403,18 @@ static void print_block_info(Monitor *mon, BlockInfo *info, void hmp_info_block(Monitor *mon, const QDict *qdict) { BlockInfoList *block_list, *info; +BlockDeviceInfoList *blockdev_list, *blockdev; const char *device = qdict_get_try_str(qdict, device); bool verbose = qdict_get_try_bool(qdict, verbose, 0); +bool nodes = qdict_get_try_bool(qdict, nodes, 0); +bool printed = false; -block_list = qmp_query_block(false); +/* Print BlockBackend information */ +if (!nodes) { +block_list = qmp_query_block(false); +} else { +block_list = NULL; +} for (info = block_list; info; info = info-next) { if (device strcmp(device, info-value-device)) { @@ -420,9 +428,30 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) print_block_info(mon, info-value, info-value-has_inserted ? info-value-inserted : NULL, verbose); +printed = true; } qapi_free_BlockInfoList(block_list); + +if ((!device !nodes) || printed) { +return; +} + +/* Print node information */ +blockdev_list = qmp_query_named_block_nodes(NULL); +for (blockdev = blockdev_list; blockdev; blockdev = blockdev-next) { +assert(blockdev-value-has_node_name); +if (device strcmp(device, blockdev-value-node_name)) { +continue; +} + +if (blockdev != blockdev_list) { +monitor_printf(mon, \n); +} + +print_block_info(mon, NULL, blockdev-value, verbose); +} +qapi_free_BlockDeviceInfoList(blockdev_list); } void hmp_info_blockstats(Monitor *mon, const QDict *qdict) diff --git a/monitor.c b/monitor.c index f1031a1..f63a3aa 100644 --- a/monitor.c +++ b/monitor.c @@ -2628,10 +2628,10 @@ static mon_cmd_t info_cmds[] = { }, { .name = block, -.args_type = verbose:-v,device:B?, -.params = [-v] [device], +.args_type = nodes:-n,verbose:-v,device:B?, +.params = [-n] [-v] [device], .help = show info of one block device or all block devices - (and details of images with -v option), + (-n: show named nodes; -v: show details), .mhandler.cmd = hmp_info_block, }, { -- 1.8.3.1
[Qemu-devel] [PULL 24/73] block: Add blk_add_close_notifier() for BB
From: Max Reitz mre...@redhat.com Adding something like a delete notifier to a BlockBackend would not make much sense, because whoever is interested in registering there will probably hold a reference to that BlockBackend; therefore, the notifier will never be called (or only when the notifiee already relinquished its reference and thus most probably is no longer interested in that notification). Therefore, this patch just passes through the close notifier interface of the root BDS. This will be called when the device is ejected, for instance, and therefore does make sense. Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1416309679-333-4-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/block-backend.c | 5 + include/sysemu/block-backend.h | 1 + 2 files changed, 6 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 7a7f690..ef16d73 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -642,6 +642,11 @@ void blk_remove_aio_context_notifier(BlockBackend *blk, detach_aio_context, opaque); } +void blk_add_close_notifier(BlockBackend *blk, Notifier *notify) +{ +bdrv_add_close_notifier(blk-bs, notify); +} + void blk_io_plug(BlockBackend *blk) { bdrv_io_plug(blk-bs); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index d9c1337..8871a02 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -143,6 +143,7 @@ void blk_remove_aio_context_notifier(BlockBackend *blk, void *), void (*detach_aio_context)(void *), void *opaque); +void blk_add_close_notifier(BlockBackend *blk, Notifier *notify); void blk_io_plug(BlockBackend *blk); void blk_io_unplug(BlockBackend *blk); BlockAcctStats *blk_get_stats(BlockBackend *blk); -- 1.8.3.1
[Qemu-devel] [PULL 21/73] ahci: replace SATA FIS type magic numbers with constants
From: Stefan Hajnoczi stefa...@redhat.com SATA 3.0 10.3.1 FIS Type values defines the constants used to differentiate between FIS types. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: John Snow js...@redhat.com Message-id: 1415874281-7371-3-git-send-email-stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- hw/ide/ahci.c | 6 +++--- hw/ide/ahci.h | 5 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 9cfa82b..5651372 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -580,7 +580,7 @@ static void ahci_write_fis_sdb(AHCIState *s, int port, uint32_t finished) sdb_fis = (SDBFIS *)ad-res_fis[RES_FIS_SDBFIS]; ide_state = ad-port.ifs[0]; -sdb_fis-type = 0xA1; +sdb_fis-type = SATA_FIS_TYPE_SDB; /* Interrupt pending Notification bit */ sdb_fis-flags = (ad-hba-control_regs.irqstatus ? (1 6) : 0); sdb_fis-status = ide_state-status 0x77; @@ -631,7 +631,7 @@ static void ahci_write_fis_pio(AHCIDevice *ad, uint16_t len) pio_fis = ad-res_fis[RES_FIS_PSFIS]; -pio_fis[0] = 0x5f; +pio_fis[0] = SATA_FIS_TYPE_PIO_SETUP; pio_fis[1] = (ad-hba-control_regs.irqstatus ? (1 6) : 0); pio_fis[2] = s-status; pio_fis[3] = s-error; @@ -690,7 +690,7 @@ static void ahci_write_fis_d2h(AHCIDevice *ad, uint8_t *cmd_fis) d2h_fis = ad-res_fis[RES_FIS_RFIS]; -d2h_fis[0] = 0x34; +d2h_fis[0] = SATA_FIS_TYPE_REGISTER_D2H; d2h_fis[1] = (ad-hba-control_regs.irqstatus ? (1 6) : 0); d2h_fis[2] = s-status; d2h_fis[3] = s-error; diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index e0d2eb8..99aa0c9 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -156,7 +156,10 @@ #define AHCI_SCR_SCTL_DET 0xf #define SATA_FIS_TYPE_REGISTER_H2D0x27 -#define SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER 0x80 +#define SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER 0x80 +#define SATA_FIS_TYPE_REGISTER_D2H0x34 +#define SATA_FIS_TYPE_PIO_SETUP 0x5f +#define SATA_FIS_TYPE_SDB 0xA1 #define AHCI_CMD_HDR_CMD_FIS_LEN 0x1f #define AHCI_CMD_HDR_PRDT_LEN 16 -- 1.8.3.1
[Qemu-devel] [PULL 22/73] block: Lift more functions into BlockBackend
From: Max Reitz mre...@redhat.com There are already some blk_aio_* functions, so we might as well have blk_co_* functions (as far as we need them). This patch adds blk_co_flush(), blk_co_discard(), and also blk_invalidate_cache() (which is not a blk_co_* function but is needed nonetheless). Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1416309679-333-2-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/block-backend.c | 15 +++ include/sysemu/block-backend.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index d0692b1..89f69b7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -497,6 +497,16 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf, return bdrv_aio_ioctl(blk-bs, req, buf, cb, opaque); } +int blk_co_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors) +{ +return bdrv_co_discard(blk-bs, sector_num, nb_sectors); +} + +int blk_co_flush(BlockBackend *blk) +{ +return bdrv_co_flush(blk-bs); +} + int blk_flush(BlockBackend *blk) { return bdrv_flush(blk-bs); @@ -549,6 +559,11 @@ void blk_set_enable_write_cache(BlockBackend *blk, bool wce) bdrv_set_enable_write_cache(blk-bs, wce); } +void blk_invalidate_cache(BlockBackend *blk, Error **errp) +{ +bdrv_invalidate_cache(blk-bs, errp); +} + int blk_is_inserted(BlockBackend *blk) { return bdrv_is_inserted(blk-bs); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 52d13c1..0c46b82 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -108,6 +108,8 @@ int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf, BlockCompletionFunc *cb, void *opaque); +int blk_co_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors); +int blk_co_flush(BlockBackend *blk); int blk_flush(BlockBackend *blk); int blk_flush_all(void); void blk_drain_all(void); @@ -120,6 +122,7 @@ int blk_is_read_only(BlockBackend *blk); int blk_is_sg(BlockBackend *blk); int blk_enable_write_cache(BlockBackend *blk); void blk_set_enable_write_cache(BlockBackend *blk, bool wce); +void blk_invalidate_cache(BlockBackend *blk, Error **errp); int blk_is_inserted(BlockBackend *blk); void blk_lock_medium(BlockBackend *blk, bool locked); void blk_eject(BlockBackend *blk, bool eject_flag); -- 1.8.3.1
[Qemu-devel] [PULL 20/73] ahci: avoid #ifdef DEBUG_AHCI bitrot
From: Stefan Hajnoczi stefa...@redhat.com Debug code using #ifdef is susceptible to bitrot because the compiler never checks the debug code. This is easy to avoid, change the DPRINTF() macro to use if (DEBUG_AHCI) and always give it a 0 or 1 value. This also allows us to drop an #ifdef DEBUG_AHCI in ahci_start_dma() since the compiler can now see the local variable is used. The motivation for this change is a recent DEBUG_AHCI build failure due to an outdated DPRINTF() format string. From now on the compiler will catch these errors. Cc: John Snow js...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: John Snow js...@redhat.com Message-id: 1415874281-7371-2-git-send-email-stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- hw/ide/ahci.c | 18 -- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 94f28e6..9cfa82b 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -34,15 +34,15 @@ #include hw/ide/pci.h #include hw/ide/ahci.h -/* #define DEBUG_AHCI */ +#define DEBUG_AHCI 0 -#ifdef DEBUG_AHCI #define DPRINTF(port, fmt, ...) \ -do { fprintf(stderr, ahci: %s: [%d] , __FUNCTION__, port); \ - fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(port, fmt, ...) do {} while(0) -#endif +do { \ +if (DEBUG_AHCI) { \ +fprintf(stderr, ahci: %s: [%d] , __func__, port); \ +fprintf(stderr, fmt, ## __VA_ARGS__); \ +} \ +} while (0) static void check_cmd(AHCIState *s, int port); static int handle_cmd(AHCIState *s,int port,int slot); @@ -551,7 +551,7 @@ static void ahci_reset_port(AHCIState *s, int port) static void debug_print_fis(uint8_t *fis, int cmd_len) { -#ifdef DEBUG_AHCI +#if DEBUG_AHCI int i; fprintf(stderr, fis:); @@ -1154,9 +1154,7 @@ out: static void ahci_start_dma(IDEDMA *dma, IDEState *s, BlockCompletionFunc *dma_cb) { -#ifdef DEBUG_AHCI AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma); -#endif DPRINTF(ad-port_no, \n); s-io_buffer_offset = 0; dma_cb(s, 0); -- 1.8.3.1
[Qemu-devel] [PULL 19/73] iotests: Plain blkdebug filename generation
From: Max Reitz mre...@redhat.com Add one test whether blkdebug is able to generate a plain filename if given a configuration file and a file to be tested only; and add another test whether blkdebug is able to do the same without being given a configuration file. Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Message-id: 1415697825-26678-3-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/099 | 15 ++- tests/qemu-iotests/099.out | 8 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099 index ffc7ea7..132aa0b 100755 --- a/tests/qemu-iotests/099 +++ b/tests/qemu-iotests/099 @@ -107,8 +107,21 @@ echo # generate a JSON object here as well test_qemu file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.driver=blkdebug,file.test.file.image.filename=$TEST_IMG,file.test.file.inject-error.0.event=l1_update +echo +echo '=== Testing plain filename for blkdebug ===' +echo + +touch $TEST_DIR/blkdebug.conf +test_qemu file.driver=blkdebug,file.config=$TEST_DIR/blkdebug.conf,file.image.filename=$TEST_IMG + +echo +echo '=== Testing plain filename for blkdebug without configuration file ===' +echo + +test_qemu file.driver=blkdebug,file.image.filename=$TEST_IMG + -rm -f $TEST_IMG.compare +rm -f $TEST_IMG.compare $TEST_DIR/blkdebug.conf # success, all done echo *** done diff --git a/tests/qemu-iotests/099.out b/tests/qemu-iotests/099.out index 50cc527..2fa06ff 100644 --- a/tests/qemu-iotests/099.out +++ b/tests/qemu-iotests/099.out @@ -17,4 +17,12 @@ json:{driver: IMGFMT, file: {image: {driver: file, filename: TEST === Testing indirectly enforced JSON filename === json:{driver: raw, file: {test: {driver: IMGFMT, file: {image: {driver: file, filename: TEST_DIR/t.IMGFMT}, driver: blkdebug, inject-error.0.event: l1_update}}, driver: blkverify, raw: {driver: file, filename: TEST_DIR/t.IMGFMT.compare}}} + +=== Testing plain filename for blkdebug === + +blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT + +=== Testing plain filename for blkdebug without configuration file === + +blkdebug::TEST_DIR/t.IMGFMT *** done -- 1.8.3.1
[Qemu-devel] [PULL 28/73] tests: Use command -v instead of which(1) in shell scripts
From: Fam Zheng f...@redhat.com When which(1) is not installed, we would complain perl not found because it's the first set_prog_path check. The error message is wrong. Fix it by using command -v, a native way to query the existence of a command. Suggested-by: Eric Blake ebl...@redhat.com Signed-off-by: Fam Zheng f...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Message-id: 1416380832-9697-1-git-send-email-f...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/common| 8 tests/qemu-iotests/common.config | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common index 9e12bec..bc27f6a 100644 --- a/tests/qemu-iotests/common +++ b/tests/qemu-iotests/common @@ -289,10 +289,10 @@ testlist options if [ ! -z $DISPLAY ] then -which xdiff /dev/null 21 diff=xdiff -which gdiff /dev/null 21 diff=gdiff -which tkdiff /dev/null 21 diff=tkdiff -which xxdiff /dev/null 21 diff=xxdiff +command -v xdiff /dev/null 21 diff=xdiff +command -v gdiff /dev/null 21 diff=gdiff +command -v tkdiff /dev/null 21 diff=tkdiff +command -v xxdiff /dev/null 21 diff=xxdiff fi ;; diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config index bd6790b..91a5ef6 100644 --- a/tests/qemu-iotests/common.config +++ b/tests/qemu-iotests/common.config @@ -47,7 +47,7 @@ export PWD=`pwd` # $1 = prog to look for, $2* = default pathnames if not found in $PATH set_prog_path() { -p=`which $1 2 /dev/null` +p=`command -v $1 2 /dev/null` if [ -n $p -a -x $p ]; then echo $p return 0 -- 1.8.3.1
[Qemu-devel] [PULL 25/73] nbd: Change external interface to BlockBackend
From: Max Reitz mre...@redhat.com Substitute BlockDriverState by BlockBackend in every globally visible function provided by nbd. Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1416309679-333-5-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev-nbd.c | 15 --- include/block/nbd.h | 7 +++ nbd.c | 11 ++- qemu-nbd.c | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 06f901e..22e95d1 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -10,6 +10,7 @@ */ #include sysemu/blockdev.h +#include sysemu/block-backend.h #include hw/block/block.h #include monitor/monitor.h #include qapi/qmp/qerror.h @@ -73,7 +74,7 @@ static void nbd_close_notifier(Notifier *n, void *data) void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, Error **errp) { -BlockDriverState *bs; +BlockBackend *blk; NBDExport *exp; NBDCloseNotifier *n; @@ -87,12 +88,12 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, return; } -bs = bdrv_find(device); -if (!bs) { +blk = blk_by_name(device); +if (!blk) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } -if (!bdrv_is_inserted(bs)) { +if (!blk_is_inserted(blk)) { error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; } @@ -100,18 +101,18 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, if (!has_writable) { writable = false; } -if (bdrv_is_read_only(bs)) { +if (blk_is_read_only(blk)) { writable = false; } -exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL); +exp = nbd_export_new(blk, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL); nbd_export_set_name(exp, device); n = g_new0(NBDCloseNotifier, 1); n-n.notify = nbd_close_notifier; n-exp = exp; -bdrv_add_close_notifier(bs, n-n); +blk_add_close_notifier(blk, n-n); QTAILQ_INSERT_TAIL(close_notifiers, n, next); } diff --git a/include/block/nbd.h b/include/block/nbd.h index 9e835d2..348302c 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -85,14 +85,13 @@ int nbd_disconnect(int fd); typedef struct NBDExport NBDExport; typedef struct NBDClient NBDClient; -NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, - off_t size, uint32_t nbdflags, - void (*close)(NBDExport *)); +NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size, + uint32_t nbdflags, void (*close)(NBDExport *)); void nbd_export_close(NBDExport *exp); void nbd_export_get(NBDExport *exp); void nbd_export_put(NBDExport *exp); -BlockDriverState *nbd_export_get_blockdev(NBDExport *exp); +BlockBackend *nbd_export_get_blockdev(NBDExport *exp); NBDExport *nbd_export_find(const char *name); void nbd_export_set_name(NBDExport *exp, const char *name); diff --git a/nbd.c b/nbd.c index a7bce45..3fd5743 100644 --- a/nbd.c +++ b/nbd.c @@ -19,6 +19,7 @@ #include block/nbd.h #include block/block.h #include block/block_int.h +#include sysemu/block-backend.h #include block/coroutine.h @@ -957,10 +958,10 @@ static void bs_aio_detach(void *opaque) exp-ctx = NULL; } -NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, - off_t size, uint32_t nbdflags, - void (*close)(NBDExport *)) +NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size, + uint32_t nbdflags, void (*close)(NBDExport *)) { +BlockDriverState *bs = blk_bs(blk); NBDExport *exp = g_malloc0(sizeof(NBDExport)); exp-refcount = 1; QTAILQ_INIT(exp-clients); @@ -1056,9 +1057,9 @@ void nbd_export_put(NBDExport *exp) } } -BlockDriverState *nbd_export_get_blockdev(NBDExport *exp) +BlockBackend *nbd_export_get_blockdev(NBDExport *exp) { -return exp-bs; +return exp-bs-blk; } void nbd_export_close_all(void) diff --git a/qemu-nbd.c b/qemu-nbd.c index 5cd6c6d..60ce50f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -730,7 +730,7 @@ int main(int argc, char **argv) } } -exp = nbd_export_new(bs, dev_offset, fd_size, nbdflags, nbd_export_closed); +exp = nbd_export_new(blk, dev_offset, fd_size, nbdflags, nbd_export_closed); if (sockpath) { fd = unix_socket_incoming(sockpath); -- 1.8.3.1
[Qemu-devel] [PULL 31/73] qemu-iotests: Add qemu-io format option in Python tests
Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-4-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/030 | 22 +++--- tests/qemu-iotests/040 | 32 tests/qemu-iotests/055 | 18 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index 8ce2373..952a524 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -34,7 +34,7 @@ class TestSingleDrive(iotests.QMPTestCase): iotests.create_image(backing_img, TestSingleDrive.image_len) qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) -qemu_io('-c', 'write -P 0x1 0 512', backing_img) +qemu_io('-f', 'raw', '-c', 'write -P 0x1 0 512', backing_img) self.vm = iotests.VM().add_drive(blkdebug:: + test_img) self.vm.launch() @@ -55,8 +55,8 @@ class TestSingleDrive(iotests.QMPTestCase): self.assert_no_active_block_jobs() self.vm.shutdown() -self.assertEqual(qemu_io('-c', 'map', backing_img), - qemu_io('-c', 'map', test_img), +self.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img), + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), 'image file map does not match backing file after streaming') def test_stream_pause(self): @@ -86,8 +86,8 @@ class TestSingleDrive(iotests.QMPTestCase): self.assert_no_active_block_jobs() self.vm.shutdown() -self.assertEqual(qemu_io('-c', 'map', backing_img), - qemu_io('-c', 'map', test_img), +self.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img), + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), 'image file map does not match backing file after streaming') def test_stream_partial(self): @@ -101,8 +101,8 @@ class TestSingleDrive(iotests.QMPTestCase): self.assert_no_active_block_jobs() self.vm.shutdown() -self.assertEqual(qemu_io('-c', 'map', mid_img), - qemu_io('-c', 'map', test_img), +self.assertEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img), + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), 'image file map does not match backing file after streaming') def test_device_not_found(self): @@ -359,9 +359,9 @@ class TestStreamStop(iotests.QMPTestCase): def setUp(self): qemu_img('create', backing_img, str(TestStreamStop.image_len)) -qemu_io('-c', 'write -P 0x1 0 32M', backing_img) +qemu_io('-f', 'raw', '-c', 'write -P 0x1 0 32M', backing_img) qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) -qemu_io('-c', 'write -P 0x1 32M 32M', test_img) +qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0x1 32M 32M', test_img) self.vm = iotests.VM().add_drive(blkdebug:: + test_img) self.vm.launch() @@ -388,9 +388,9 @@ class TestSetSpeed(iotests.QMPTestCase): def setUp(self): qemu_img('create', backing_img, str(TestSetSpeed.image_len)) -qemu_io('-c', 'write -P 0x1 0 32M', backing_img) +qemu_io('-f', 'raw', '-c', 'write -P 0x1 0 32M', backing_img) qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) -qemu_io('-c', 'write -P 0x1 32M 32M', test_img) +qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0x1 32M 32M', test_img) self.vm = iotests.VM().add_drive('blkdebug::' + test_img) self.vm.launch() diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index 2b432ad..ea2f98e 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -76,8 +76,8 @@ class TestSingleDrive(ImageCommitTestCase): iotests.create_image(backing_img, self.image_len) qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) -qemu_io('-c', 'write -P 0xab 0 524288', backing_img) -qemu_io('-c', 'write -P 0xef 524288 524288', mid_img) +qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) +qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) self.vm = iotests.VM().add_drive(test_img) self.vm.launch() @@ -89,8 +89,8 @@ class TestSingleDrive(ImageCommitTestCase): def test_commit(self):
[Qemu-devel] [PULL 30/73] qemu-iotests: Use qemu-io -f $IMGFMT
This patch changes $QEMU_IO so that all tests by default pass a format argument to qemu-io. There are a few cases where -f $IMGFMT is not wanted because it selects the wrong driver or json: filenames including a driver are used. They are changed to use $QEMU_IO_PROG, which doesn't include any options. Tests 071 and 081 have output changes because now the actual request fails instead of reading the 2k probing buffer. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-3-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/016 | 11 +++ tests/qemu-iotests/048 | 2 +- tests/qemu-iotests/058 | 11 +++ tests/qemu-iotests/071 | 10 +- tests/qemu-iotests/071.out | 6 +++--- tests/qemu-iotests/077 | 2 +- tests/qemu-iotests/081 | 8 ++-- tests/qemu-iotests/081.out | 2 +- tests/qemu-iotests/089 | 6 -- tests/qemu-iotests/common | 2 +- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/tests/qemu-iotests/016 b/tests/qemu-iotests/016 index 7ea9e94..52397aa 100755 --- a/tests/qemu-iotests/016 +++ b/tests/qemu-iotests/016 @@ -43,25 +43,28 @@ _supported_proto file sheepdog nfs _supported_os Linux +# No -f, use probing for the protocol driver +QEMU_IO_PROTO=$QEMU_IO_PROG -g --cache $CACHEMODE + size=128M _make_test_img $size echo echo == reading at EOF == -$QEMU_IO -g -c read -P 0 $size 512 $TEST_IMG | _filter_qemu_io +$QEMU_IO_PROTO -c read -P 0 $size 512 $TEST_IMG | _filter_qemu_io echo echo == reading far past EOF == -$QEMU_IO -g -c read -P 0 256M 512 $TEST_IMG | _filter_qemu_io +$QEMU_IO_PROTO -c read -P 0 256M 512 $TEST_IMG | _filter_qemu_io echo echo == writing at EOF == -$QEMU_IO -g -c write -P 66 $size 512 $TEST_IMG | _filter_qemu_io +$QEMU_IO_PROTO -c write -P 66 $size 512 $TEST_IMG | _filter_qemu_io $QEMU_IO -c read -P 66 $size 512 $TEST_IMG | _filter_qemu_io echo echo == writing far past EOF == -$QEMU_IO -g -c write -P 66 256M 512 $TEST_IMG | _filter_qemu_io +$QEMU_IO_PROTO -c write -P 66 256M 512 $TEST_IMG | _filter_qemu_io $QEMU_IO -c read -P 66 256M 512 $TEST_IMG | _filter_qemu_io # success, all done diff --git a/tests/qemu-iotests/048 b/tests/qemu-iotests/048 index 65da46d..e1eeac2 100755 --- a/tests/qemu-iotests/048 +++ b/tests/qemu-iotests/048 @@ -64,7 +64,7 @@ _compare _compare -q # Compare images with different size -$QEMU_IMG resize $TEST_IMG +512M +$QEMU_IMG resize -f $IMGFMT $TEST_IMG +512M _compare _compare -s diff --git a/tests/qemu-iotests/058 b/tests/qemu-iotests/058 index 14584cd..2d5ca85 100755 --- a/tests/qemu-iotests/058 +++ b/tests/qemu-iotests/058 @@ -89,6 +89,9 @@ _supported_fmt qcow2 _supported_proto file _require_command QEMU_NBD +# Use -f raw instead of -f $IMGFMT for the NBD connection +QEMU_IO_NBD=$QEMU_IO -f raw --cache=$CACHEMODE + echo echo == preparing image == _make_test_img 64M @@ -108,15 +111,15 @@ _export_nbd_snapshot sn1 echo echo == verifying the exported snapshot with patterns, method 1 == -$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io -$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO_NBD -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO_NBD -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io _export_nbd_snapshot1 sn1 echo echo == verifying the exported snapshot with patterns, method 2 == -$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io -$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO_NBD -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO_NBD -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io $QEMU_IMG convert $TEST_IMG -l sn1 -O qcow2 $converted_image diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071 index 3924e51..5d61ef6 100755 --- a/tests/qemu-iotests/071 +++ b/tests/qemu-iotests/071 @@ -63,12 +63,12 @@ echo TEST_IMG=$TEST_IMG.base IMGOPTS= IMGFMT=raw _make_test_img $IMG_SIZE |\ _filter_imgfmt _make_test_img $IMG_SIZE -$QEMU_IO -c open -o file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG \ +$QEMU_IO -c open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG \ -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io $QEMU_IO -c 'write -P 42 0 512' $TEST_IMG | _filter_qemu_io -$QEMU_IO -c open -o file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG \ +$QEMU_IO -c open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG \ -c 'read -P 42 0 512' | _filter_qemu_io echo @@ -78,12 +78,12 @@ echo TEST_IMG=$TEST_IMG.base IMGOPTS= IMGFMT=raw
[Qemu-devel] [PULL 26/73] nbd: Use BlockBackend internally
From: Max Reitz mre...@redhat.com With all externally visible functions changed to use BlockBackend, this patch makes nbd use BlockBackend for everything internally as well. While touching them, substitute 512 by BDRV_SECTOR_SIZE in the calls to blk_read(), blk_write() and blk_co_discard(). Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1416309679-333-6-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- nbd.c | 56 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/nbd.c b/nbd.c index 3fd5743..53cf82b 100644 --- a/nbd.c +++ b/nbd.c @@ -17,8 +17,6 @@ */ #include block/nbd.h -#include block/block.h -#include block/block_int.h #include sysemu/block-backend.h #include block/coroutine.h @@ -102,7 +100,7 @@ struct NBDExport { int refcount; void (*close)(NBDExport *exp); -BlockDriverState *bs; +BlockBackend *blk; char *name; off_t dev_offset; off_t size; @@ -930,7 +928,7 @@ static void nbd_request_put(NBDRequest *req) nbd_client_put(client); } -static void bs_aio_attached(AioContext *ctx, void *opaque) +static void blk_aio_attached(AioContext *ctx, void *opaque) { NBDExport *exp = opaque; NBDClient *client; @@ -944,7 +942,7 @@ static void bs_aio_attached(AioContext *ctx, void *opaque) } } -static void bs_aio_detach(void *opaque) +static void blk_aio_detach(void *opaque) { NBDExport *exp = opaque; NBDClient *client; @@ -961,24 +959,23 @@ static void bs_aio_detach(void *opaque) NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size, uint32_t nbdflags, void (*close)(NBDExport *)) { -BlockDriverState *bs = blk_bs(blk); NBDExport *exp = g_malloc0(sizeof(NBDExport)); exp-refcount = 1; QTAILQ_INIT(exp-clients); -exp-bs = bs; +exp-blk = blk; exp-dev_offset = dev_offset; exp-nbdflags = nbdflags; -exp-size = size == -1 ? bdrv_getlength(bs) : size; +exp-size = size == -1 ? blk_getlength(blk) : size; exp-close = close; -exp-ctx = bdrv_get_aio_context(bs); -bdrv_ref(bs); -bdrv_add_aio_context_notifier(bs, bs_aio_attached, bs_aio_detach, exp); +exp-ctx = blk_get_aio_context(blk); +blk_ref(blk); +blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp); /* * NBD exports are used for non-shared storage migration. Make sure * that BDRV_O_INCOMING is cleared and the image is ready for write * access since the export could be available before migration handover. */ -bdrv_invalidate_cache(bs, NULL); +blk_invalidate_cache(blk, NULL); return exp; } @@ -1025,11 +1022,11 @@ void nbd_export_close(NBDExport *exp) } nbd_export_set_name(exp, NULL); nbd_export_put(exp); -if (exp-bs) { -bdrv_remove_aio_context_notifier(exp-bs, bs_aio_attached, - bs_aio_detach, exp); -bdrv_unref(exp-bs); -exp-bs = NULL; +if (exp-blk) { +blk_remove_aio_context_notifier(exp-blk, blk_aio_attached, +blk_aio_detach, exp); +blk_unref(exp-blk); +exp-blk = NULL; } } @@ -1059,7 +1056,7 @@ void nbd_export_put(NBDExport *exp) BlockBackend *nbd_export_get_blockdev(NBDExport *exp) { -return exp-bs-blk; +return exp-blk; } void nbd_export_close_all(void) @@ -1138,7 +1135,7 @@ static ssize_t nbd_co_receive_request(NBDRequest *req, struct nbd_request *reque command = request-type NBD_CMD_MASK_COMMAND; if (command == NBD_CMD_READ || command == NBD_CMD_WRITE) { -req-data = qemu_blockalign(client-exp-bs, request-len); +req-data = blk_blockalign(client-exp-blk, request-len); } if (command == NBD_CMD_WRITE) { TRACE(Reading %u byte(s), request-len); @@ -1204,7 +1201,7 @@ static void nbd_trip(void *opaque) TRACE(Request type is READ); if (request.type NBD_CMD_FLAG_FUA) { -ret = bdrv_co_flush(exp-bs); +ret = blk_co_flush(exp-blk); if (ret 0) { LOG(flush failed); reply.error = -ret; @@ -1212,8 +1209,9 @@ static void nbd_trip(void *opaque) } } -ret = bdrv_read(exp-bs, (request.from + exp-dev_offset) / 512, -req-data, request.len / 512); +ret = blk_read(exp-blk, + (request.from + exp-dev_offset) / BDRV_SECTOR_SIZE, + req-data, request.len / BDRV_SECTOR_SIZE); if (ret 0) { LOG(reading from file failed); reply.error = -ret; @@ -1235,8 +1233,9 @@ static void nbd_trip(void *opaque) TRACE(Writing to device); -ret = bdrv_write(exp-bs, (request.from +
[Qemu-devel] [PULL 29/73] qemu-io: Allow explicitly specifying format
This adds a -f option to qemu-io which allows to explicitly specify the block driver to use for the given image. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-2-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- qemu-io.c | 28 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 60f84dd..91a445a 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -51,7 +51,8 @@ static const cmdinfo_t close_cmd = { .oneline= close the current open file, }; -static int openfile(char *name, int flags, int growable, QDict *opts) +static int openfile(char *name, BlockDriver *drv, int flags, int growable, +QDict *opts) { Error *local_err = NULL; @@ -68,7 +69,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts) flags |= BDRV_O_PROTOCOL; } -if (bdrv_open(qemuio_bs, name, NULL, opts, flags, NULL, local_err) 0) { +if (bdrv_open(qemuio_bs, name, NULL, opts, flags, drv, local_err) 0) { fprintf(stderr, %s: can't open%s%s: %s\n, progname, name ? device : , name ?: , error_get_pretty(local_err)); @@ -169,9 +170,9 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) qemu_opts_reset(empty_opts); if (optind == argc - 1) { -return openfile(argv[optind], flags, growable, opts); +return openfile(argv[optind], NULL, flags, growable, opts); } else if (optind == argc) { -return openfile(NULL, flags, growable, opts); +return openfile(NULL, NULL, flags, growable, opts); } else { QDECREF(opts); return qemuio_command_usage(open_cmd); @@ -196,11 +197,12 @@ static const cmdinfo_t quit_cmd = { static void usage(const char *name) { printf( -Usage: %s [-h] [-V] [-rsnm] [-c STRING] ... [file]\n +Usage: %s [-h] [-V] [-rsnm] [-f FMT] [-c STRING] ... [file]\n QEMU Disk exerciser\n \n -c, --cmd STRING execute command with its arguments\n from the given string\n + -f, --format FMT specifies the block driver to use\n -r, --read-only export read-only\n -s, --snapshot use snapshot file\n -n, --nocachedisable host cache\n @@ -364,12 +366,13 @@ int main(int argc, char **argv) { int readonly = 0; int growable = 0; -const char *sopt = hVc:d:rsnmgkt:T:; +const char *sopt = hVc:d:f:rsnmgkt:T:; const struct option lopt[] = { { help, 0, NULL, 'h' }, { version, 0, NULL, 'V' }, { offset, 1, NULL, 'o' }, { cmd, 1, NULL, 'c' }, +{ format, 1, NULL, 'f' }, { read-only, 0, NULL, 'r' }, { snapshot, 0, NULL, 's' }, { nocache, 0, NULL, 'n' }, @@ -384,6 +387,7 @@ int main(int argc, char **argv) int c; int opt_index = 0; int flags = BDRV_O_UNMAP; +BlockDriver *drv = NULL; Error *local_error = NULL; #ifdef CONFIG_POSIX @@ -393,6 +397,8 @@ int main(int argc, char **argv) progname = basename(argv[0]); qemu_init_exec_dir(argv[0]); +bdrv_init(); + while ((c = getopt_long(argc, argv, sopt, lopt, opt_index)) != -1) { switch (c) { case 's': @@ -407,6 +413,13 @@ int main(int argc, char **argv) exit(1); } break; +case 'f': +drv = bdrv_find_format(optarg); +if (!drv) { +error_report(Invalid format '%s', optarg); +exit(EXIT_FAILURE); +} +break; case 'c': add_user_command(optarg); break; @@ -455,7 +468,6 @@ int main(int argc, char **argv) error_free(local_error); exit(1); } -bdrv_init(); /* initialize commands */ qemuio_add_command(quit_cmd); @@ -477,7 +489,7 @@ int main(int argc, char **argv) } if ((argc - optind) == 1) { -openfile(argv[optind], flags, growable, NULL); +openfile(argv[optind], drv, flags, growable, NULL); } command_loop(); -- 1.8.3.1
[Qemu-devel] [PULL 27/73] qemu-nbd: Use BlockBackend where reasonable
From: Max Reitz mre...@redhat.com Because qemu-nbd creates the BlockBackend by itself, it should create the according BlockDriverState tree by itself as well; that means, it has call bdrv_open() on its own. This is one of the places where qemu-nbd still needs to use a BlockDriverState directly (the root BDS below the BB); other places are the configuration of zero detection (which may be lifted into the BB eventually, but is not yet) and temporarily loading a snapshot. Everywhere else, though, qemu-nbd can and thus should use BlockBackend. Suggested-by: Paolo Bonzini pbonz...@redhat.com Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1416309679-333-7-git-send-email-mre...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- qemu-nbd.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 60ce50f..d222512 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -146,7 +146,7 @@ static void read_partition(uint8_t *p, struct partition_record *r) r-nb_sectors_abs = p[12] | p[13] 8 | p[14] 16 | p[15] 24; } -static int find_partition(BlockDriverState *bs, int partition, +static int find_partition(BlockBackend *blk, int partition, off_t *offset, off_t *size) { struct partition_record mbr[4]; @@ -155,7 +155,7 @@ static int find_partition(BlockDriverState *bs, int partition, int ext_partnum = 4; int ret; -if ((ret = bdrv_read(bs, 0, data, 1)) 0) { +if ((ret = blk_read(blk, 0, data, 1)) 0) { errno = -ret; err(EXIT_FAILURE, error while reading); } @@ -175,7 +175,7 @@ static int find_partition(BlockDriverState *bs, int partition, uint8_t data1[512]; int j; -if ((ret = bdrv_read(bs, mbr[i].start_sector_abs, data1, 1)) 0) { +if ((ret = blk_read(blk, mbr[i].start_sector_abs, data1, 1)) 0) { errno = -ret; err(EXIT_FAILURE, error while reading); } @@ -720,10 +720,10 @@ int main(int argc, char **argv) } bs-detect_zeroes = detect_zeroes; -fd_size = bdrv_getlength(bs); +fd_size = blk_getlength(blk); if (partition != -1) { -ret = find_partition(bs, partition, dev_offset, fd_size); +ret = find_partition(blk, partition, dev_offset, fd_size); if (ret 0) { errno = -ret; err(EXIT_FAILURE, Could not find partition %d, partition); -- 1.8.3.1
[Qemu-devel] [PULL 32/73] qtests: Specify image format explicitly
Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-5-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/ahci-test.c | 3 ++- tests/bios-tables-test.c | 2 +- tests/drive_del-test.c| 2 +- tests/fdc-test.c | 2 +- tests/hd-geo-test.c | 2 +- tests/i440fx-test.c | 5 +++-- tests/ide-test.c | 9 + tests/nvme-test.c | 2 +- tests/usb-hcd-uhci-test.c | 2 +- tests/usb-hcd-xhci-test.c | 2 +- tests/virtio-blk-test.c | 4 ++-- tests/virtio-scsi-test.c | 4 ++-- 12 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 4c77ebe..e77fa3a 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -487,7 +487,8 @@ static void qtest_shutdown(void) */ static QPCIDevice *ahci_boot(void) { -qtest_boot(-drive if=none,id=drive0,file=%s,cache=writeback,serial=%s +qtest_boot(-drive if=none,id=drive0,file=%s,cache=writeback,serial=%s, + format=raw -M q35 -device ide-hd,drive=drive0 -global ide-hd.ver=%s, diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 9e4d205..2519f7d 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -716,7 +716,7 @@ static void test_acpi_one(const char *params, test_data *data) int i; args = g_strdup_printf(-net none -display none %s - -drive id=hd0,if=none,file=%s + -drive id=hd0,if=none,file=%s,format=raw -device ide-hd,drive=hd0 , params ? params : , disk); diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c index 53fa969..8951f6f 100644 --- a/tests/drive_del-test.c +++ b/tests/drive_del-test.c @@ -103,7 +103,7 @@ static void test_after_failed_device_add(void) static void test_drive_del_device_del(void) { /* Start with a drive used by a device that unplugs instantaneously */ -qtest_start(-drive if=none,id=drive0,file=/dev/null +qtest_start(-drive if=none,id=drive0,file=/dev/null,format=raw -device virtio-scsi-pci -device scsi-hd,drive=drive0,id=dev0); diff --git a/tests/fdc-test.c b/tests/fdc-test.c index 203074c..3c6c83c 100644 --- a/tests/fdc-test.c +++ b/tests/fdc-test.c @@ -291,7 +291,7 @@ static void test_media_insert(void) /* Insert media in drive. DSKCHK should not be reset until a step pulse * is sent. */ qmp_discard_response({'execute':'change', 'arguments':{ - 'device':'floppy0', 'target': %s }}, + 'device':'floppy0', 'target': %s, 'arg': 'raw' }}, test_image); qmp_discard_response(); /* ignore event (FIXME open - open transition?!) */ diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c index c84d1e7..7cc8dff 100644 --- a/tests/hd-geo-test.c +++ b/tests/hd-geo-test.c @@ -208,7 +208,7 @@ static int setup_ide(int argc, char *argv[], int argv_sz, { char *s1, *s2, *s3; -s1 = g_strdup_printf(-drive id=drive%d,if=%s, +s1 = g_strdup_printf(-drive id=drive%d,if=%s,format=raw, ide_idx, dev ? none : ide); s2 = dev ? g_strdup() : g_strdup_printf(,index=%d, ide_idx); diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c index ad232b5..a3f7279 100644 --- a/tests/i440fx-test.c +++ b/tests/i440fx-test.c @@ -342,8 +342,9 @@ static void test_i440fx_firmware(FirmwareTestFixture *fixture, g_assert(fw_pathname != NULL); /* Better hope the user didn't put metacharacters in TMPDIR and co. */ -cmdline = g_strdup_printf(-S %s %s, - fixture-is_bios ? -bios : -pflash, +cmdline = g_strdup_printf(-S %s%s, fixture-is_bios + ? -bios + : -drive if=pflash,format=raw,file=, fw_pathname); g_test_message(qemu cmdline: %s, cmdline); qtest_start(cmdline); diff --git a/tests/ide-test.c b/tests/ide-test.c index b7a97e9..29f4039 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -385,7 +385,7 @@ static void test_bmdma_no_busmaster(void) static void test_bmdma_setup(void) { ide_test_start( --drive file=%s,if=ide,serial=%s,cache=writeback +-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw -global ide-hd.ver=%s, tmp_path, testdisk, version); } @@ -414,7 +414,7 @@ static void test_identify(void) int ret; ide_test_start( --drive file=%s,if=ide,serial=%s,cache=writeback +-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw -global ide-hd.ver=%s, tmp_path, testdisk,
[Qemu-devel] [PULL 36/73] qemu-iotests: Fix stderr handling in common.qemu
The original intention was to pipe stderr of qemu into $fifo_out. However, the redirections were specified in the wrong order for this. This patch fixes it. Now qemu's output on stderr can be retrieved with _send_qemu_cmd, which applies several useful filters on the output that were missing before. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-9-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/common.qemu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu index ee7ebb4..8e618b5 100644 --- a/tests/qemu-iotests/common.qemu +++ b/tests/qemu-iotests/common.qemu @@ -153,8 +153,9 @@ function _launch_qemu() mkfifo ${fifo_out} mkfifo ${fifo_in} -${QEMU} -nographic -serial none ${comm} -machine accel=qtest ${@} 21 \ +${QEMU} -nographic -serial none ${comm} -machine accel=qtest ${@} \ ${fifo_out} \ +21 \ ${fifo_in} QEMU_PID[${_QEMU_HANDLE}]=$! -- 1.8.3.1
[Qemu-devel] [PULL 38/73] blockdev: update outdated qmp_transaction() comments
From: Stefan Hajnoczi stefa...@redhat.com Originally the transaction QMP command was just for taking snapshots. The command became more general when drive-backup and abort were added. It is more accurate to say the command is about performing operations on an atomic group than to say it is about snapshots. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416566940-4430-2-git-send-email-stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 16 ++-- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/blockdev.c b/blockdev.c index a52f205..490f698 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1173,7 +1173,7 @@ out_aio_context: return NULL; } -/* New and old BlockDriverState structs for group snapshots */ +/* New and old BlockDriverState structs for atomic group operations */ typedef struct BlkTransactionState BlkTransactionState; @@ -1544,9 +1544,8 @@ static const BdrvActionOps actions[] = { }; /* - * 'Atomic' group snapshots. The snapshots are taken as a set, and if any fail - * then we do not pivot any of the devices in the group, and abandon the - * snapshots + * 'Atomic' group operations. The operations are performed as a set, and if + * any fail then we roll back all operations in the group. */ void qmp_transaction(TransactionActionList *dev_list, Error **errp) { @@ -1557,10 +1556,10 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp) QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states; QSIMPLEQ_INIT(snap_bdrv_states); -/* drain all i/o before any snapshots */ +/* drain all i/o before any operations */ bdrv_drain_all(); -/* We don't do anything in this loop that commits us to the snapshot */ +/* We don't do anything in this loop that commits us to the operations */ while (NULL != dev_entry) { TransactionAction *dev_info = NULL; const BdrvActionOps *ops; @@ -1595,10 +1594,7 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp) goto exit; delete_and_fail: -/* -* failure, and it is all-or-none; abandon each new bs, and keep using -* the original bs for all images -*/ +/* failure, and it is all-or-none; roll back all operations */ QSIMPLEQ_FOREACH(state, snap_bdrv_states, entry) { if (state-ops-abort) { state-ops-abort(state); -- 1.8.3.1
[Qemu-devel] [PULL 34/73] block: Read only one sector for format probing
The only image format driver that even potentially accesses anything after 512 bytes in its bdrv_probe() implementation is VMDK, which reads a plain-text descriptor file. In practice, the field it's looking for seems to come first and will be well within the first 512 bytes, too. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-7-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c | 6 +++--- include/block/block_int.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index aa7edf8..809ec54 100644 --- a/block.c +++ b/block.c @@ -654,8 +654,8 @@ BlockDriver *bdrv_find_protocol(const char *filename, * we do it anyway for backward compatibility. * * @buf contains the image's first @buf_size bytes. - * @buf_sizeis the buffer size in bytes (generally 2048, but can be smaller - * if the image file is smaller) + * @buf_sizeis the buffer size in bytes (generally BLOCK_PROBE_BUF_SIZE, + * but can be smaller if the image file is smaller) * @filenameis its filename. * * For all block drivers, call the bdrv_probe() method to get its @@ -685,7 +685,7 @@ static int find_image_format(BlockDriverState *bs, const char *filename, BlockDriver **pdrv, Error **errp) { BlockDriver *drv; -uint8_t buf[2048]; +uint8_t buf[BLOCK_PROBE_BUF_SIZE]; int ret = 0; /* Return the raw BlockDriver * to scsi-generic devices or empty drives */ diff --git a/include/block/block_int.h b/include/block/block_int.h index a1c17b9..cd94559 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -57,6 +57,8 @@ #define BLOCK_OPT_REDUNDANCYredundancy #define BLOCK_OPT_NOCOW nocow +#define BLOCK_PROBE_BUF_SIZE512 + typedef struct BdrvTrackedRequest { BlockDriverState *bs; int64_t offset; -- 1.8.3.1
[Qemu-devel] [PULL 35/73] raw: Prohibit dangerous writes for probed images
If the user neglects to specify the image format, QEMU probes the image to guess it automatically, for convenience. Relying on format probing is insecure for raw images (CVE-2008-2004). If the guest writes a suitable header to the device, the next probe will recognize a format chosen by the guest. A malicious guest can abuse this to gain access to host files, e.g. by crafting a QCOW2 header with backing file /etc/shadow. Commit 1e72d3b (April 2008) provided -drive parameter format to let users disable probing. Commit f965509 (March 2009) extended QCOW2 to optionally store the backing file format, to let users disable backing file probing. QED has had a flag to suppress probing since the beginning (2010), set whenever a raw backing file is assigned. All of these additions that allow to avoid format probing have to be specified explicitly. The default still allows the attack. In order to fix this, commit 79368c8 (July 2010) put probed raw images in a restricted mode, in which they wouldn't be able to overwrite the first few bytes of the image so that they would identify as a different image. If a write to the first sector would write one of the signatures of another driver, qemu would instead zero out the first four bytes. This patch was later reverted in commit 8b33d9e (September 2010) because it didn't get the handling of unaligned qiov members right. Today's block layer that is based on coroutines and has qiov utility functions makes it much easier to get this functionality right, so this patch implements it. The other differences of this patch to the old one are that it doesn't silently write something different than the guest requested by zeroing out some bytes (it fails the request instead) and that it doesn't maintain a list of signatures in the raw driver (it calls the usual probe function instead). Note that this change doesn't introduce new breakage for false positive cases where the guest legitimately writes data into the first sector that matches the signatures of an image format (e.g. for nested virt): These cases were broken before, only the failure mode changes from corruption after the next restart (when the wrong format is probed) to failing the problematic write request. Also note that like in the original patch, the restrictions only apply if the image format has been guessed by probing. Explicitly specifying a format allows guests to write anything they like. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Message-id: 1416497234-29880-8-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c | 5 ++-- block/raw_bsd.c | 64 ++- include/block/block_int.h | 3 +++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 809ec54..35f7a0a 100644 --- a/block.c +++ b/block.c @@ -662,8 +662,8 @@ BlockDriver *bdrv_find_protocol(const char *filename, * probing score. * Return the first block driver with the highest probing score. */ -static BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, - const char *filename) +BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, +const char *filename) { int score_max = 0, score; BlockDriver *drv = NULL, *d; @@ -1489,6 +1489,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, } /* Image format probing */ +bs-probed = !drv; if (!drv file) { ret = find_image_format(file, filename, drv, local_err); if (ret 0) { diff --git a/block/raw_bsd.c b/block/raw_bsd.c index 401b967..2ce5409 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -58,8 +58,58 @@ static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num, static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { +void *buf = NULL; +BlockDriver *drv; +QEMUIOVector local_qiov; +int ret; + +if (bs-probed sector_num == 0) { +/* As long as these conditions are true, we can't get partial writes to + * the probe buffer and can just directly check the request. */ +QEMU_BUILD_BUG_ON(BLOCK_PROBE_BUF_SIZE != 512); +QEMU_BUILD_BUG_ON(BDRV_SECTOR_SIZE != 512); + +if (nb_sectors == 0) { +/* qemu_iovec_to_buf() would fail, but we want to return success + * instead of -EINVAL in this case. */ +return 0; +} + +buf = qemu_try_blockalign(bs-file, 512); +if (!buf) { +ret = -ENOMEM; +goto fail; +} + +ret = qemu_iovec_to_buf(qiov, 0, buf, 512); +if (ret != 512) { +
[Qemu-devel] [PULL 37/73] qemu-iotests: Test writing non-raw image headers to raw image
This is forbidden if the raw driver was probed. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416497234-29880-10-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/109| 132 + tests/qemu-iotests/109.out| 231 ++ tests/qemu-iotests/group | 1 + tests/qemu-iotests/sample_images/grub_mbr.raw.bz2 | Bin 0 - 552 bytes 4 files changed, 364 insertions(+) create mode 100755 tests/qemu-iotests/109 create mode 100644 tests/qemu-iotests/109.out create mode 100644 tests/qemu-iotests/sample_images/grub_mbr.raw.bz2 diff --git a/tests/qemu-iotests/109 b/tests/qemu-iotests/109 new file mode 100755 index 000..0b668da --- /dev/null +++ b/tests/qemu-iotests/109 @@ -0,0 +1,132 @@ +#!/bin/bash +# +# Test writing image headers of other formats into raw images +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# + +# creator +owner=kw...@redhat.com + +seq=$(basename $0) +echo QA output created by $seq + +here=$PWD +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ +rm -f $TEST_IMG.src + _cleanup_test_img +} +trap _cleanup; exit \$status 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.qemu + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +qemu_comm_method=qmp + +function run_qemu() +{ +local raw_img=$1 +local source_img=$2 +local qmp_format=$3 +local qmp_event=$4 + +_launch_qemu -drive file=${source_img},format=raw,cache=${CACHEMODE},id=src +_send_qemu_cmd $QEMU_HANDLE { 'execute': 'qmp_capabilities' } return + +_send_qemu_cmd $QEMU_HANDLE \ +{'execute':'drive-mirror', 'arguments':{ +'device': 'src', 'target': '$raw_img', $qmp_format +'mode': 'existing', 'sync': 'full'}} \ +return + +_send_qemu_cmd $QEMU_HANDLE '' $qmp_event +_send_qemu_cmd $QEMU_HANDLE '{execute:query-block-jobs}' return +_cleanup_qemu +} + +for fmt in qcow qcow2 qed vdi vmdk vpc; do + +echo +echo === Writing a $fmt header into raw === +echo + +_make_test_img 64M +TEST_IMG=$TEST_IMG.src IMGFMT=$fmt _make_test_img 64M + +# This first test should fail: The image format was probed, we may not +# write an image header at the start of the image +run_qemu $TEST_IMG $TEST_IMG.src BLOCK_JOB_ERROR +$QEMU_IO -c 'read -P 0 0 64k' $TEST_IMG | _filter_qemu_io + + +# When raw was explicitly specified, the same must succeed +run_qemu $TEST_IMG $TEST_IMG.src 'format': 'raw', BLOCK_JOB_READY +$QEMU_IMG compare -f raw -F raw $TEST_IMG $TEST_IMG.src + +done + + +for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \ + simple-pattern.cloop; do + +echo +echo === Copying sample image $sample_img into raw === +echo + +# Can't use _use_sample_img because that isn't designed to be used multiple +# times and it overwrites $TEST_IMG (both breaks cleanup) +_make_test_img 64M +bzcat $SAMPLE_IMG_DIR/$sample_img.bz2 $TEST_IMG.src + +run_qemu $TEST_IMG $TEST_IMG.src BLOCK_JOB_ERROR +$QEMU_IO -c 'read -P 0 0 64k' $TEST_IMG | _filter_qemu_io + +run_qemu $TEST_IMG $TEST_IMG.src 'format': 'raw', BLOCK_JOB_READY +# qemu-img compare can't handle unaligned file sizes +$QEMU_IMG resize -f raw $TEST_IMG.src +0 +$QEMU_IMG compare -f raw -F raw $TEST_IMG $TEST_IMG.src +done + +echo +echo === Write legitimate MBR into raw === +echo + +for sample_img in grub_mbr.raw; do +_make_test_img 64M +bzcat $SAMPLE_IMG_DIR/$sample_img.bz2 $TEST_IMG.src + +run_qemu $TEST_IMG $TEST_IMG.src BLOCK_JOB_READY +$QEMU_IMG compare -f raw -F raw $TEST_IMG $TEST_IMG.src + +run_qemu $TEST_IMG $TEST_IMG.src 'format': 'raw', BLOCK_JOB_READY +$QEMU_IMG compare -f raw -F raw $TEST_IMG $TEST_IMG.src +done + + +# success, all done +echo '*** done' +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/109.out b/tests/qemu-iotests/109.out new file mode 100644 index 000..7db92c9 --- /dev/null +++ b/tests/qemu-iotests/109.out @@ -0,0 +1,231 @@ +QA output created by 109 + +=== Writing a qcow
[Qemu-devel] [PULL 40/73] blockdev: acquire AioContext in QMP 'transaction' actions
From: Stefan Hajnoczi stefa...@redhat.com The transaction QMP command performs operations atomically on a group of drives. This command needs to acquire AioContext in order to work safely when virtio-blk dataplane IOThreads are accessing drives. The transactional nature of the command means that actions are split into prepare, commit, abort, and clean functions. Acquire the AioContext in prepare and don't release it until one of the other functions is called. This prevents the IOThread from running the AioContext before the transaction has completed. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416566940-4430-4-git-send-email-stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 52 - hw/block/dataplane/virtio-blk.c | 2 ++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index b58ce30..ea59c39 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1207,6 +1207,7 @@ struct BlkTransactionState { typedef struct InternalSnapshotState { BlkTransactionState common; BlockDriverState *bs; +AioContext *aio_context; QEMUSnapshotInfo sn; } InternalSnapshotState; @@ -1240,6 +1241,10 @@ static void internal_snapshot_prepare(BlkTransactionState *common, return; } +/* AioContext is released in .clean() */ +state-aio_context = bdrv_get_aio_context(bs); +aio_context_acquire(state-aio_context); + if (!bdrv_is_inserted(bs)) { error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; @@ -1317,11 +1322,22 @@ static void internal_snapshot_abort(BlkTransactionState *common) } } +static void internal_snapshot_clean(BlkTransactionState *common) +{ +InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState, + common, common); + +if (state-aio_context) { +aio_context_release(state-aio_context); +} +} + /* external snapshot private data */ typedef struct ExternalSnapshotState { BlkTransactionState common; BlockDriverState *old_bs; BlockDriverState *new_bs; +AioContext *aio_context; } ExternalSnapshotState; static void external_snapshot_prepare(BlkTransactionState *common, @@ -1388,6 +1404,10 @@ static void external_snapshot_prepare(BlkTransactionState *common, return; } +/* Acquire AioContext now so any threads operating on old_bs stop */ +state-aio_context = bdrv_get_aio_context(state-old_bs); +aio_context_acquire(state-aio_context); + if (!bdrv_is_inserted(state-old_bs)) { error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; @@ -1446,6 +1466,8 @@ static void external_snapshot_commit(BlkTransactionState *common) ExternalSnapshotState *state = DO_UPCAST(ExternalSnapshotState, common, common); +bdrv_set_aio_context(state-new_bs, state-aio_context); + /* This removes our old bs and adds the new bs */ bdrv_append(state-new_bs, state-old_bs); /* We don't need (or want) to use the transactional @@ -1453,6 +1475,8 @@ static void external_snapshot_commit(BlkTransactionState *common) * don't want to abort all of them if one of them fails the reopen */ bdrv_reopen(state-new_bs, state-new_bs-open_flags ~BDRV_O_RDWR, NULL); + +aio_context_release(state-aio_context); } static void external_snapshot_abort(BlkTransactionState *common) @@ -1462,23 +1486,38 @@ static void external_snapshot_abort(BlkTransactionState *common) if (state-new_bs) { bdrv_unref(state-new_bs); } +if (state-aio_context) { +aio_context_release(state-aio_context); +} } typedef struct DriveBackupState { BlkTransactionState common; BlockDriverState *bs; +AioContext *aio_context; BlockJob *job; } DriveBackupState; static void drive_backup_prepare(BlkTransactionState *common, Error **errp) { DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); +BlockDriverState *bs; DriveBackup *backup; Error *local_err = NULL; assert(common-action-kind == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); backup = common-action-drive_backup; +bs = bdrv_find(backup-device); +if (!bs) { +error_set(errp, QERR_DEVICE_NOT_FOUND, backup-device); +return; +} + +/* AioContext is released in .clean() */ +state-aio_context = bdrv_get_aio_context(bs); +aio_context_acquire(state-aio_context); + qmp_drive_backup(backup-device, backup-target, backup-has_format, backup-format, backup-sync, @@ -1492,7 +1531,7 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp) return; } -state-bs = bdrv_find(backup-device); +state-bs = bs; state-job = state-bs-job; } @@
[Qemu-devel] [PULL 39/73] blockdev: drop unnecessary DriveBackupState field assignment
From: Stefan Hajnoczi stefa...@redhat.com drive_backup_prepare() assigns DriveBackupState fields to NULL in the error path. This is unnecessary because the DriveBackupState is allocated using g_malloc0() and other functions like external_snapshot_prepare() already rely on this. Do not explicitly assign fields to NULL so that the error path is concise and does not require modification when fields are added to DriveBackupState. Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416566940-4430-3-git-send-email-stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 490f698..b58ce30 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1489,8 +1489,6 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp) local_err); if (local_err) { error_propagate(errp, local_err); -state-bs = NULL; -state-job = NULL; return; } -- 1.8.3.1
[Qemu-devel] [PULL 49/73] ide: Check validity of logical block size
Our IDE emulation can't handle logical block sizes other than 512. Check for it. The original assumption was that other values would silently be ignored (which is bad enough), but it's not quite true: The physical block size is exposed in IDENTIFY DEVICE as a multiple of the logical block size. Setting a logical block size therefore also corrupts the physical block size (4096/4096 doesn't silently downgrade to 4096/512, but 512/512). Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Markus Armbruster arm...@redhat.com Reviewed-by: John Snow js...@redhat.com --- hw/ide/qdev.c | 5 + 1 file changed, 5 insertions(+) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index b4f096e..1ebb58d 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -163,6 +163,11 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) return -1; } +if (dev-conf.logical_block_size != 512) { +error_report(logical_block_size must be 512 for IDE); +return -1; +} + blkconf_serial(dev-conf, dev-serial); if (kind != IDE_CD) { blkconf_geometry(dev-conf, dev-chs_trans, 65536, 16, 255, err); -- 1.8.3.1
[Qemu-devel] [PULL 41/73] blockdev: check for BLOCK_OP_TYPE_INTERNAL_SNAPSHOT
From: Stefan Hajnoczi stefa...@redhat.com The BLOCK_OP_TYPE_INTERNAL_SNAPSHOT op blocker exists but was never used! Let's fix that so internal snapshots can be blocked. [Fixed s/external/internal/ typo as pointed out by Paolo Bonzini and Max Reitz. --Stefan] Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416566940-4430-5-git-send-email-stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- blockdev.c | 4 1 file changed, 4 insertions(+) diff --git a/blockdev.c b/blockdev.c index ea59c39..5651a8e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1250,6 +1250,10 @@ static void internal_snapshot_prepare(BlkTransactionState *common, return; } +if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) { +return; +} + if (bdrv_is_read_only(bs)) { error_set(errp, QERR_DEVICE_IS_READ_ONLY, device); return; -- 1.8.3.1
[Qemu-devel] [PULL 42/73] qcow2: Fix header extension size check
After reading the extension header, offset is incremented, but not checked against end_offset any more. This way an integer overflow could happen when checking whether the extension end is within the allowed range, effectively disabling the check. This patch adds the missing check and a test case for it. Cc: qemu-sta...@nongnu.org Reported-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416935562-7760-2-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/qcow2.c | 2 +- tests/qemu-iotests/080 | 2 ++ tests/qemu-iotests/080.out | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index d120494..8b9ffc4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -117,7 +117,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, #ifdef DEBUG_EXT printf(ext.magic = 0x%x\n, ext.magic); #endif -if (ext.len end_offset - offset) { +if (offset end_offset || ext.len end_offset - offset) { error_setg(errp, Header extension too large); return -EINVAL; } diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 index 9de337c..73795f1 100755 --- a/tests/qemu-iotests/080 +++ b/tests/qemu-iotests/080 @@ -78,6 +78,8 @@ poke_file $TEST_IMG $offset_backing_file_offset \xff\xff\xff\xff\xff\xff\xf poke_file $TEST_IMG $offset_ext_magic \x12\x34\x56\x78 poke_file $TEST_IMG $offset_ext_size \x7f\xff\xff\xff { $QEMU_IO -c read 0 512 $TEST_IMG; } 21 | _filter_qemu_io | _filter_testdir +poke_file $TEST_IMG $offset_backing_file_offset \x00\x00\x00\x00\x00\x00\x00\x$(printf %x $offset_ext_size) +{ $QEMU_IO -c read 0 512 $TEST_IMG; } 21 | _filter_qemu_io | _filter_testdir poke_file $TEST_IMG $offset_backing_file_offset \x00\x00\x00\x00\x00\x00\x00\x00 { $QEMU_IO -c read 0 512 $TEST_IMG; } 21 | _filter_qemu_io | _filter_testdir diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index f7a943c..33d1f71 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -13,6 +13,8 @@ qemu-io: can't open device TEST_DIR/t.qcow2: Invalid backing file offset no file open, try 'help open' qemu-io: can't open device TEST_DIR/t.qcow2: Header extension too large no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow2: Header extension too large +no file open, try 'help open' == Huge refcount table size == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 -- 1.8.3.1
[Qemu-devel] [PULL 44/73] block: Don't probe for unknown backing file format
If a qcow2 image specifies a backing file format that doesn't correspond to any format driver that qemu knows, we shouldn't fall back to probing, but simply error out. Not looking up the backing file driver in bdrv_open_backing_file(), but just filling in the driver option if it isn't there moves us closer to the goal of having everything in QDict options and gets us the error handling of bdrv_open(), which correctly refuses unknown drivers. Cc: qemu-sta...@nongnu.org Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Max Reitz mre...@redhat.com Message-id: 1416935562-7760-4-git-send-email-kw...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c| 7 +++--- tests/qemu-iotests/114 | 61 ++ tests/qemu-iotests/114.out | 13 ++ tests/qemu-iotests/group | 1 + 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100755 tests/qemu-iotests/114 create mode 100644 tests/qemu-iotests/114.out diff --git a/block.c b/block.c index 35f7a0a..591fbe4 100644 --- a/block.c +++ b/block.c @@ -1202,7 +1202,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) { char *backing_filename = g_malloc0(PATH_MAX); int ret = 0; -BlockDriver *back_drv = NULL; BlockDriverState *backing_hd; Error *local_err = NULL; @@ -1235,14 +1234,14 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) backing_hd = bdrv_new(); -if (bs-backing_format[0] != '\0') { -back_drv = bdrv_find_format(bs-backing_format); +if (bs-backing_format[0] != '\0' !qdict_haskey(options, driver)) { +qdict_put(options, driver, qstring_from_str(bs-backing_format)); } assert(bs-backing_hd == NULL); ret = bdrv_open(backing_hd, *backing_filename ? backing_filename : NULL, NULL, options, -bdrv_backing_flags(bs-open_flags), back_drv, local_err); +bdrv_backing_flags(bs-open_flags), NULL, local_err); if (ret 0) { bdrv_unref(backing_hd); backing_hd = NULL; diff --git a/tests/qemu-iotests/114 b/tests/qemu-iotests/114 new file mode 100755 index 000..d02e7ff --- /dev/null +++ b/tests/qemu-iotests/114 @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Test invalid backing file format in qcow2 images +# +# Copyright (C) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# + +# creator +owner=kw...@redhat.com + +seq=$(basename $0) +echo QA output created by $seq + +here=$PWD +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap _cleanup; exit \$status 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto generic +_supported_os Linux + + +TEST_IMG=$TEST_IMG.base _make_test_img 64M +_make_test_img -b $TEST_IMG.base 64M + +# Set an invalid backing file format +$PYTHON qcow2.py $TEST_IMG add-header-ext 0xE2792ACA foo +_img_info + +# Try opening the image. Should fail (and not probe) in the first case, but +# overriding the backing file format should be possible. +$QEMU_IO -c open $TEST_IMG -c read 0 4k 21 | _filter_qemu_io | _filter_testdir +$QEMU_IO -c open -o backing.driver=$IMGFMT $TEST_IMG -c read 0 4k | _filter_qemu_io + +# success, all done +echo '*** done' +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/114.out b/tests/qemu-iotests/114.out new file mode 100644 index 000..6c6b210 --- /dev/null +++ b/tests/qemu-iotests/114.out @@ -0,0 +1,13 @@ +QA output created by 114 +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file='TEST_DIR/t.IMGFMT.base' +image: TEST_DIR/t.IMGFMT +file format: IMGFMT +virtual size: 64M (67108864 bytes) +cluster_size: 65536 +backing file: TEST_DIR/t.IMGFMT.base +backing file format: foo +qemu-io: can't open device TEST_DIR/t.qcow2: Could not open backing file: Unknown driver 'foo' +read 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index af58a68..2ba10ad 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -113,3 +113,4 @@
[Qemu-devel] [PULL 51/73] block: Make essential BlockDriver objects public
From: Max Reitz mre...@redhat.com There are some block drivers which are essential to QEMU and may not be removed: These are raw, file and qcow2 (as the default non-raw format). Make their BlockDriver objects public so they can be directly referenced throughout the block layer without needing to call bdrv_find_format() and having to deal with an error at runtime, while the real problem occurred during linking (where raw, file or qcow2 were not linked into qemu). Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/qcow2.c | 2 +- block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- block/raw_bsd.c | 2 +- include/block/block_int.h | 8 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 8b9ffc4..cbc327b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2847,7 +2847,7 @@ static QemuOptsList qcow2_create_opts = { } }; -static BlockDriver bdrv_qcow2 = { +BlockDriver bdrv_qcow2 = { .format_name= qcow2, .instance_size = sizeof(BDRVQcowState), .bdrv_probe = qcow2_probe, diff --git a/block/raw-posix.c b/block/raw-posix.c index 02e107f..2e6a919 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1684,7 +1684,7 @@ static QemuOptsList raw_create_opts = { } }; -static BlockDriver bdrv_file = { +BlockDriver bdrv_file = { .format_name = file, .protocol_name = file, .instance_size = sizeof(BDRVRawState), diff --git a/block/raw-win32.c b/block/raw-win32.c index 7b58881..06243d7 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -540,7 +540,7 @@ static QemuOptsList raw_create_opts = { } }; -static BlockDriver bdrv_file = { +BlockDriver bdrv_file = { .format_name = file, .protocol_name = file, .instance_size = sizeof(BDRVRawState), diff --git a/block/raw_bsd.c b/block/raw_bsd.c index 2ce5409..05b02c7 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -235,7 +235,7 @@ static int raw_probe(const uint8_t *buf, int buf_size, const char *filename) return 1; } -static BlockDriver bdrv_raw = { +BlockDriver bdrv_raw = { .format_name = raw, .bdrv_probe = raw_probe, .bdrv_reopen_prepare = raw_reopen_prepare, diff --git a/include/block/block_int.h b/include/block/block_int.h index 192fce8..06a21dd 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -414,6 +414,14 @@ struct BlockDriverState { Error *backing_blocker; }; + +/* Essential block drivers which must always be statically linked into qemu, and + * which therefore can be accessed without using bdrv_find_format() */ +extern BlockDriver bdrv_file; +extern BlockDriver bdrv_raw; +extern BlockDriver bdrv_qcow2; + + int get_tmp_filename(char *filename, int size); BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, const char *filename); -- 1.8.3.1
[Qemu-devel] [PULL 45/73] block: do not use get_clock()
From: Paolo Bonzini pbonz...@redhat.com Use the external qemu-timer API instead. No one else should be calling cpu_get_clock(), get_clock() and get_clock_realtime() directly; they are internal functions and they should be confined to qemu-timer.c and cpus.c (where the icount implementation resides). All accesses should go through qemu_clock_get_ns. Cc: kw...@redhat.com Cc: stefa...@redhat.com Signed-off-by: Paolo Bonzini pbonz...@redhat.com Message-id: 1417010463-3527-2-git-send-email-pbonz...@redhat.com Signed-off-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/accounting.c | 6 -- block/raw-posix.c | 8 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/block/accounting.c b/block/accounting.c index edbb1cc..18102f0 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -24,6 +24,7 @@ #include block/accounting.h #include block/block_int.h +#include qemu/timer.h void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie, int64_t bytes, enum BlockAcctType type) @@ -31,7 +32,7 @@ void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie, assert(type BLOCK_MAX_IOTYPE); cookie-bytes = bytes; -cookie-start_time_ns = get_clock(); +cookie-start_time_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); cookie-type = type; } @@ -41,7 +42,8 @@ void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) stats-nr_bytes[cookie-type] += cookie-bytes; stats-nr_ops[cookie-type]++; -stats-total_time_ns[cookie-type] += get_clock() - cookie-start_time_ns; +stats-total_time_ns[cookie-type] += +qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - cookie-start_time_ns; } diff --git a/block/raw-posix.c b/block/raw-posix.c index b1af77e..02e107f 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1922,7 +1922,7 @@ static int fd_open(BlockDriverState *bs) return 0; last_media_present = (s-fd = 0); if (s-fd = 0 -(get_clock() - s-fd_open_time) = FD_OPEN_TIMEOUT) { +(qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s-fd_open_time) = FD_OPEN_TIMEOUT) { qemu_close(s-fd); s-fd = -1; #ifdef DEBUG_FLOPPY @@ -1931,7 +1931,7 @@ static int fd_open(BlockDriverState *bs) } if (s-fd 0) { if (s-fd_got_error -(get_clock() - s-fd_error_time) FD_OPEN_TIMEOUT) { +(qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s-fd_error_time) FD_OPEN_TIMEOUT) { #ifdef DEBUG_FLOPPY printf(No floppy (open delayed)\n); #endif @@ -1939,7 +1939,7 @@ static int fd_open(BlockDriverState *bs) } s-fd = qemu_open(bs-filename, s-open_flags ~O_NONBLOCK); if (s-fd 0) { -s-fd_error_time = get_clock(); +s-fd_error_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); s-fd_got_error = 1; if (last_media_present) s-fd_media_changed = 1; @@ -1954,7 +1954,7 @@ static int fd_open(BlockDriverState *bs) } if (!last_media_present) s-fd_media_changed = 1; -s-fd_open_time = get_clock(); +s-fd_open_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); s-fd_got_error = 0; return 0; } -- 1.8.3.1
[Qemu-devel] [PULL 55/73] block: Check create_opts before image creation
From: Max Reitz mre...@redhat.com If a driver supports image creation, it needs to set the .create_opts field. We can use that to make sure .create_opts for both drivers involved is not NULL in bdrv_img_create(), which is important so that the create_opts pointer in that function is not NULL after the qemu_opts_append() calls and when going into qemu_opts_create(). Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Kevin Wolf kw...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c | 12 1 file changed, 12 insertions(+) diff --git a/block.c b/block.c index e995008..82f33c5 100644 --- a/block.c +++ b/block.c @@ -5569,6 +5569,18 @@ void bdrv_img_create(const char *filename, const char *fmt, return; } +if (!drv-create_opts) { +error_setg(errp, Format driver '%s' does not support image creation, + drv-format_name); +return; +} + +if (!proto_drv-create_opts) { +error_setg(errp, Protocol driver '%s' does not support image creation, + proto_drv-format_name); +return; +} + create_opts = qemu_opts_append(create_opts, drv-create_opts); create_opts = qemu_opts_append(create_opts, proto_drv-create_opts); -- 1.8.3.1
[Qemu-devel] [PULL 46/73] qemu-iotests: 060: Filter the real disk size
The real on-disk size of an image depends on things like the host filesystem. _img_info already filters it out, use the function in 060. Signed-off-by: Kevin Wolf kw...@redhat.com Reviewed-by: Michael Mueller m...@linux.vnet.ibm.com Reviewed-by: Max Reitz mre...@redhat.com --- tests/qemu-iotests/060 | 2 +- tests/qemu-iotests/060.out | 5 ++--- tests/qemu-iotests/common.rc | 11 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060 index 9772d36..73863bf 100755 --- a/tests/qemu-iotests/060 +++ b/tests/qemu-iotests/060 @@ -77,7 +77,7 @@ $QEMU_IO -c $OPEN_RW -c write -P 0x2a 0 512 | _filter_qemu_io $PYTHON qcow2.py $TEST_IMG dump-header | grep incompatible_features # This information should be available through qemu-img info -$QEMU_IMG info $TEST_IMG | _filter_testdir +_img_info --format-specific # Try to open the image R/W (which should fail) $QEMU_IO -c $OPEN_RW -c read 0 512 21 | _filter_qemu_io \ diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 9419da1..4cdf62b 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -11,10 +11,9 @@ incompatible_features 0x0 qcow2: Marking image as corrupt: Preventing invalid write on metadata (overlaps with active L1 table); further corruption events will be suppressed write failed: Input/output error incompatible_features 0x2 -image: TEST_DIR/t.qcow2 -file format: qcow2 +image: TEST_DIR/t.IMGFMT +file format: IMGFMT virtual size: 64M (67108864 bytes) -disk size: 196K cluster_size: 65536 Format specific information: compat: 1.1 diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 9c49deb..89cbc13 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -213,6 +213,13 @@ _check_test_img() _img_info() { +if [[ $1 == --format-specific ]]; then +local format_specific=1 +shift +else +local format_specific=0 +fi + discard=0 regex_json_spec_start='^ *format-specific: \{' $QEMU_IMG info $@ $TEST_IMG 21 | \ @@ -222,7 +229,9 @@ _img_info() -e /^disk size:/ D \ -e /actual-size/ D | \ while IFS='' read line; do -if [[ $line == Format specific information: ]]; then +if [[ $format_specific == 1 ]]; then +discard=0 +elif [[ $line == Format specific information: ]]; then discard=1 elif [[ $line =~ $regex_json_spec_start ]]; then discard=2 -- 1.8.3.1
[Qemu-devel] [PULL 48/73] nvme: 64kB page size fixes
From: Anton Blanchard an...@samba.org Initialise our maximum page size capability to 64kB and increase the page_size variable from 16 to 32 bits. Signed-off-by: Anton Blanchard an...@samba.org Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- hw/block/nvme.c | 1 + hw/block/nvme.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 1327658..aa1ed98 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -811,6 +811,7 @@ static int nvme_init(PCIDevice *pci_dev) NVME_CAP_SET_AMS(n-bar.cap, 1); NVME_CAP_SET_TO(n-bar.cap, 0xf); NVME_CAP_SET_CSS(n-bar.cap, 1); +NVME_CAP_SET_MPSMAX(n-bar.cap, 4); n-bar.vs = 0x00010001; n-bar.intmc = n-bar.intms = 0; diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 993c511..b6ccb65 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -688,7 +688,7 @@ typedef struct NvmeCtrl { NvmeBar bar; BlockConfconf; -uint16_tpage_size; +uint32_tpage_size; uint16_tpage_bits; uint16_tmax_prp_ents; uint16_tcqe_size; -- 1.8.3.1
[Qemu-devel] [PULL 52/73] block: Omit bdrv_find_format for essential drivers
From: Max Reitz mre...@redhat.com We can always assume raw, file and qcow2 being available; so do not use bdrv_find_format() to locate their BlockDriver objects but statically reference the respective objects. Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block.c | 17 + block/qcow2.c | 7 +++ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index 591fbe4..e995008 100644 --- a/block.c +++ b/block.c @@ -629,7 +629,7 @@ BlockDriver *bdrv_find_protocol(const char *filename, } if (!path_has_protocol(filename) || !allow_protocol_prefix) { -return bdrv_find_format(file); +return bdrv_file; } p = strchr(filename, ':'); @@ -690,12 +690,7 @@ static int find_image_format(BlockDriverState *bs, const char *filename, /* Return the raw BlockDriver * to scsi-generic devices or empty drives */ if (bs-sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) { -drv = bdrv_find_format(raw); -if (!drv) { -error_setg(errp, Could not find raw image format); -ret = -ENOENT; -} -*pdrv = drv; +*pdrv = bdrv_raw; return ret; } @@ -1315,7 +1310,6 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp) /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */ char *tmp_filename = g_malloc0(PATH_MAX + 1); int64_t total_size; -BlockDriver *bdrv_qcow2; QemuOpts *opts = NULL; QDict *snapshot_options; BlockDriverState *bs_snapshot; @@ -1340,11 +1334,10 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp) goto out; } -bdrv_qcow2 = bdrv_find_format(qcow2); -opts = qemu_opts_create(bdrv_qcow2-create_opts, NULL, 0, +opts = qemu_opts_create(bdrv_qcow2.create_opts, NULL, 0, error_abort); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size); -ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, local_err); +ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, local_err); qemu_opts_del(opts); if (ret 0) { error_setg_errno(errp, -ret, Could not create temporary overlay @@ -1364,7 +1357,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp) bs_snapshot = bdrv_new(); ret = bdrv_open(bs_snapshot, NULL, NULL, snapshot_options, -flags, bdrv_qcow2, local_err); +flags, bdrv_qcow2, local_err); if (ret 0) { error_propagate(errp, local_err); goto out; diff --git a/block/qcow2.c b/block/qcow2.c index cbc327b..d597b2d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1915,10 +1915,9 @@ static int qcow2_create2(const char *filename, int64_t total_size, * refcount of the cluster that is occupied by the header and the refcount * table) */ -BlockDriver* drv = bdrv_find_format(qcow2); -assert(drv != NULL); ret = bdrv_open(bs, filename, NULL, NULL, -BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, local_err); +BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, +bdrv_qcow2, local_err); if (ret 0) { error_propagate(errp, local_err); goto out; @@ -1970,7 +1969,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */ ret = bdrv_open(bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING, -drv, local_err); +bdrv_qcow2, local_err); if (local_err) { error_propagate(errp, local_err); goto out; -- 1.8.3.1
[Qemu-devel] [PULL 53/73] block/vvfat: qcow driver may not be found
From: Max Reitz mre...@redhat.com Although virtually impossible right now, bdrv_find_format(qcow) may fail. The vvfat block driver should heed that case. Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Kevin Wolf kw...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/vvfat.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/block/vvfat.c b/block/vvfat.c index cefe3a4..e34a789 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2917,6 +2917,12 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp) } bdrv_qcow = bdrv_find_format(qcow); +if (!bdrv_qcow) { +error_setg(errp, Failed to locate qcow driver); +ret = -ENOENT; +goto err; +} + opts = qemu_opts_create(bdrv_qcow-create_opts, NULL, 0, error_abort); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s-sector_count * 512); qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, fat:); -- 1.8.3.1
[Qemu-devel] [PULL 47/73] qemu-iotests: 082: Filter the real disk size
From: Michael Mueller m...@linux.vnet.ibm.com The real on-disk size of an image depends on things like the host filesystem. _img_info already filters it out, use the function in 082. Signed-off-by: Michael Mueller m...@linux.vnet.ibm.com Reviewed-by: Max Reitz mre...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/082 | 14 ++--- tests/qemu-iotests/082.out | 49 +- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/tests/qemu-iotests/082 b/tests/qemu-iotests/082 index e64de27..c83e01e 100755 --- a/tests/qemu-iotests/082 +++ b/tests/qemu-iotests/082 @@ -60,11 +60,11 @@ _img_info # Multiple -o should be merged run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on $TEST_IMG $size -run_qemu_img info $TEST_IMG +_img_info --format-specific # If the same -o key is specified more than once, the last one wins run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k $TEST_IMG $size -run_qemu_img info $TEST_IMG +_img_info --format-specific run_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k $TEST_IMG $size _img_info @@ -114,11 +114,11 @@ TEST_IMG=${TEST_IMG}.base _img_info # Multiple -o should be merged run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on $TEST_IMG $TEST_IMG.base -run_qemu_img info $TEST_IMG.base +TEST_IMG=${TEST_IMG}.base _img_info --format-specific # If the same -o key is specified more than once, the last one wins run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k $TEST_IMG $TEST_IMG.base -run_qemu_img info $TEST_IMG.base +TEST_IMG=${TEST_IMG}.base _img_info --format-specific run_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k $TEST_IMG $TEST_IMG.base TEST_IMG=${TEST_IMG}.base _img_info @@ -157,15 +157,15 @@ echo === amend: Options specified more than once === # Last -f should win run_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on $TEST_IMG -run_qemu_img info $TEST_IMG +_img_info --format-specific # Multiple -o should be merged run_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off $TEST_IMG -run_qemu_img info $TEST_IMG +_img_info --format-specific # If the same -o key is specified more than once, the last one wins run_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M $TEST_IMG -run_qemu_img info $TEST_IMG +_img_info --format-specific run_qemu_img amend -f $IMGFMT -o size=4M,size=148M $TEST_IMG _img_info diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 0a3ab5a..5adfd08 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -11,12 +11,9 @@ cluster_size: 65536 Testing: create -f qcow2 -o cluster_size=4k -o lazy_refcounts=on TEST_DIR/t.qcow2 128M Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=134217728 encryption=off cluster_size=4096 lazy_refcounts=on - -Testing: info TEST_DIR/t.qcow2 -image: TEST_DIR/t.qcow2 -file format: qcow2 +image: TEST_DIR/t.IMGFMT +file format: IMGFMT virtual size: 128M (134217728 bytes) -disk size: 16K cluster_size: 4096 Format specific information: compat: 1.1 @@ -25,12 +22,9 @@ Format specific information: Testing: create -f qcow2 -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k TEST_DIR/t.qcow2 128M Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=134217728 encryption=off cluster_size=8192 lazy_refcounts=on - -Testing: info TEST_DIR/t.qcow2 -image: TEST_DIR/t.qcow2 -file format: qcow2 +image: TEST_DIR/t.IMGFMT +file format: IMGFMT virtual size: 128M (134217728 bytes) -disk size: 28K cluster_size: 8192 Format specific information: compat: 1.1 @@ -189,12 +183,9 @@ virtual size: 128M (134217728 bytes) cluster_size: 65536 Testing: convert -O qcow2 -o cluster_size=4k -o lazy_refcounts=on TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base - -Testing: info TEST_DIR/t.qcow2.base -image: TEST_DIR/t.qcow2.base -file format: qcow2 +image: TEST_DIR/t.IMGFMT.base +file format: IMGFMT virtual size: 128M (134217728 bytes) -disk size: 16K cluster_size: 4096 Format specific information: compat: 1.1 @@ -202,12 +193,9 @@ Format specific information: corrupt: false Testing: convert -O qcow2 -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base - -Testing: info TEST_DIR/t.qcow2.base -image: TEST_DIR/t.qcow2.base -file format: qcow2 +image: TEST_DIR/t.IMGFMT.base +file format: IMGFMT virtual size: 128M (134217728 bytes) -disk size: 28K cluster_size: 8192 Format specific information: compat: 1.1 @@ -351,12 +339,9 @@ size Virtual disk size === amend: Options specified more than once === Testing: amend -f foo -f qcow2 -o lazy_refcounts=on TEST_DIR/t.qcow2 - -Testing: info TEST_DIR/t.qcow2 -image: TEST_DIR/t.qcow2 -file format: qcow2 +image: TEST_DIR/t.IMGFMT +file format: IMGFMT virtual size: 128M (134217728 bytes)
[Qemu-devel] [PULL 56/73] qemu-img: Check create_opts before image creation
From: Max Reitz mre...@redhat.com If a driver supports image creation, it needs to set the .create_opts field. We can use that to make sure .create_opts for both drivers involved is not NULL for the target image in qemu-img convert, which is important so that the create_opts pointer in img_convert() is not NULL after the qemu_opts_append() calls and when going into qemu_opts_create(). Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Kevin Wolf kw...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- qemu-img.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index a42335c..8c4edf3 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1531,6 +1531,20 @@ static int img_convert(int argc, char **argv) goto out; } +if (!drv-create_opts) { +error_report(Format driver '%s' does not support image creation, + drv-format_name); +ret = -1; +goto out; +} + +if (!proto_drv-create_opts) { +error_report(Protocol driver '%s' does not support image creation, + proto_drv-format_name); +ret = -1; +goto out; +} + create_opts = qemu_opts_append(create_opts, drv-create_opts); create_opts = qemu_opts_append(create_opts, proto_drv-create_opts); -- 1.8.3.1
[Qemu-devel] [PULL 54/73] block/nfs: Add create_opts
From: Max Reitz mre...@redhat.com The nfs protocol driver is capable of creating images, but did not specify any creation options. Fix it. A way to test this issue is the following: $ qemu-img create -f nfs nfs://127.0.0.1/foo.qcow2 64M Without this patch, it segfaults. With this patch, it does not. However, this is not something that should really work; qemu-img should check whether the parameter for the -f option (and -O for convert) is indeed a format, and error out if it is not. Therefore, I am not making it an iotest. Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Kevin Wolf kw...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- block/nfs.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/block/nfs.c b/block/nfs.c index c76e368..ca9e24e 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -409,6 +409,19 @@ out: return ret; } +static QemuOptsList nfs_create_opts = { +.name = nfs-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(nfs_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} +}; + static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp) { int ret = 0; @@ -470,6 +483,8 @@ static BlockDriver bdrv_nfs = { .instance_size = sizeof(NFSClient), .bdrv_needs_filename= true, +.create_opts= nfs_create_opts, + .bdrv_has_zero_init = nfs_has_zero_init, .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, .bdrv_truncate = nfs_file_truncate, -- 1.8.3.1
[Qemu-devel] [PULL 58/73] iotests: Only kill NBD server if it runs
From: Max Reitz mre...@redhat.com There may be NBD tests which do not create a sample image and simply test whether wrong usage of the protocol is rejected as expected. In this case, there will be no NBD server and trying to kill it during clean-up will fail. Cc: qemu-sta...@nongnu.org Signed-off-by: Max Reitz mre...@redhat.com Reviewed-by: Kevin Wolf kw...@redhat.com Signed-off-by: Kevin Wolf kw...@redhat.com --- tests/qemu-iotests/common.rc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 89cbc13..3b14053 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -175,7 +175,9 @@ _cleanup_test_img() case $IMGPROTO in nbd) -kill $QEMU_NBD_PID +if [ -n $QEMU_NBD_PID ]; then +kill $QEMU_NBD_PID +fi rm -f $TEST_IMG_FILE ;; file) -- 1.8.3.1