[PATCH] Fix build without CONFIG_XEN_EMU
From: Miroslav Rezanina Upstream commit ddf0fd9ae1 "hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback" added kvm_xen_maybe_deassert_callback usage to target/i386/kvm/kvm.c file without conditional preprocessing check. This breaks any build not using CONFIG_XEN_EMU. Protect call by conditional preprocessing to allow build without CONFIG_XEN_EMU. Signed-off-by: Miroslav Rezanina --- target/i386/kvm/kvm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 1aef54f87e..de531842f6 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4991,6 +4991,7 @@ MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run) kvm_rate_limit_on_bus_lock(); } +#ifdef CONFIG_XEN_EMU /* * If the callback is asserted as a GSI (or PCI INTx) then check if * vcpu_info->evtchn_upcall_pending has been cleared, and deassert @@ -5001,6 +5002,7 @@ MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run) if (x86_cpu->env.xen_callback_asserted) { kvm_xen_maybe_deassert_callback(cpu); } +#endif /* We need to protect the apic state against concurrent accesses from * different threads in case the userspace irqchip is used. */ -- 2.39.1
[PATCH 4/4] host-libusb: Remove unused variable
From: Miroslav Rezanina Variable unconnected used in usb_host_auto_check function is only incremented but never read as line where it is read was disabled since introducing the code. This causes 'Unused but set variable' warning on Clang 15.0.1 compiler. Removing the variable and disabled code to prevent the warning. Signed-off-by: Miroslav Rezanina --- hw/usb/host-libusb.c | 15 --- 1 file changed, 15 deletions(-) diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index 28f8af8941..176868d345 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -1837,7 +1837,6 @@ static void usb_host_auto_check(void *unused) struct USBAutoFilter *f; libusb_device **devs = NULL; struct libusb_device_descriptor ddesc; -int unconnected = 0; int i, n; if (usb_host_init() != 0) { @@ -1897,9 +1896,6 @@ static void usb_host_auto_check(void *unused) libusb_free_device_list(devs, 1); QTAILQ_FOREACH(s, , next) { -if (s->dh == NULL) { -unconnected++; -} if (s->seen == 0) { if (s->dh) { usb_host_close(s); @@ -1908,17 +1904,6 @@ static void usb_host_auto_check(void *unused) } s->seen = 0; } - -#if 0 -if (unconnected == 0) { -/* nothing to watch */ -if (usb_auto_timer) { -timer_del(usb_auto_timer); -trace_usb_host_auto_scan_disabled(); -} -return; -} -#endif } if (!usb_vmstate) { -- 2.31.1
[PATCH 1/4] rtl8139: Remove unused variable
From: Miroslav Rezanina Variable send_count used in rtl8139_cplus_transmit_one function is only incremented but never read. This causes 'Unused but set variable' warning on Clang 15.0.1 compiler. Removing the variable to prevent the warning. Signed-off-by: Miroslav Rezanina --- hw/net/rtl8139.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 6b65823b4b..e6643e3c9d 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -2156,7 +2156,6 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) ip_data_len, saved_size - ETH_HLEN, large_send_mss); int tcp_send_offset = 0; -int send_count = 0; /* maximum IP header length is 60 bytes */ uint8_t saved_ip_header[60]; @@ -2261,7 +2260,6 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) /* add transferred count to TCP sequence number */ stl_be_p(_tcp_hdr->th_seq, chunk_size + ldl_be_p(_tcp_hdr->th_seq)); -++send_count; } /* Stop sending this frame */ -- 2.31.1
[PATCH 3/4] qemu-img: remove unused variable
From: Miroslav Rezanina Variable block_count used in img_dd function is only incremented but never read. This causes 'Unused but set variable' warning on Clang 15.0.1 compiler. Removing the variable to prevent the warning. Signed-off-by: Miroslav Rezanina --- qemu-img.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index a3b64c88af..a9b3a8103c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4922,7 +4922,7 @@ static int img_dd(int argc, char **argv) const char *out_fmt = "raw"; const char *fmt = NULL; int64_t size = 0; -int64_t block_count = 0, out_pos, in_pos; +int64_t out_pos, in_pos; bool force_share = false; struct DdInfo dd = { .flags = 0, @@ -5122,7 +5122,7 @@ static int img_dd(int argc, char **argv) in.buf = g_new(uint8_t, in.bsz); -for (out_pos = 0; in_pos < size; block_count++) { +for (out_pos = 0; in_pos < size; ) { int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; ret = blk_pread(blk1, in_pos, bytes, in.buf, 0); -- 2.31.1
[PATCH 0/4] Removal of several unused variables causing
From: Miroslav Rezanina When trying to run qemu build using clang 15.0.1 compiler with --enable-werror option, several 'Unused but set variable' warnings was breaking the build. These variables show similar pattern - they are only incremented but final value of the variable is never used. Removing this variables to enable using --enable-werror option with Clang 15.0.1. Miroslav Rezanina (4): rtl8139: Remove unused variable tulip: Remove unused variable qemu-img: remove unused variable host-libusb: Remove unused variable hw/net/rtl8139.c | 2 -- hw/net/tulip.c | 4 +--- hw/usb/host-libusb.c | 15 --- qemu-img.c | 4 ++-- 4 files changed, 3 insertions(+), 22 deletions(-) -- 2.31.1
[PATCH 2/4] tulip: Remove unused variable
From: Miroslav Rezanina Variable n used in tulip_idblock_crc function is only incremented but never read. This causes 'Unused but set variable' warning on Clang 15.0.1 compiler. Removing the variable to prevent the warning. Signed-off-by: Miroslav Rezanina --- hw/net/tulip.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/net/tulip.c b/hw/net/tulip.c index b9e42c322a..c2b3b1bdfa 100644 --- a/hw/net/tulip.c +++ b/hw/net/tulip.c @@ -870,11 +870,10 @@ static const MemoryRegionOps tulip_ops = { static void tulip_idblock_crc(TULIPState *s, uint16_t *srom) { -int word, n; +int word; int bit; unsigned char bitval, crc; const int len = 9; -n = 0; crc = -1; for (word = 0; word < len; word++) { @@ -887,7 +886,6 @@ static void tulip_idblock_crc(TULIPState *s, uint16_t *srom) srom[len - 1] = (srom[len - 1] & 0xff00) | (unsigned short)crc; break; } -n++; bitval = ((srom[word] >> bit) & 1) ^ ((crc >> 7) & 1); crc = crc << 1; if (bitval == 1) { -- 2.31.1
[PATCH] Add missing pixman dependecy
From: Miroslav Rezanina Commit cfead31326 'acpi: pc: vga: use AcpiDevAmlIf interface to build VGA device descriptors' added a new file - acpi-vga.c. This file (indirectly) includes pixman.h file so we need to ensure pixman is available when file is compiled. Signed-off-by: Miroslav Rezanina --- hw/display/meson.build | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/display/meson.build b/hw/display/meson.build index 7a725ed80e..c8e84e9707 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -43,7 +43,7 @@ if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or config_all_devices.has_key('CONFIG_VMWARE_VGA') or config_all_devices.has_key('CONFIG_ATI_VGA') ) - softmmu_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'), + softmmu_ss.add(when: 'CONFIG_ACPI', if_true: [files('acpi-vga.c'), pixman], if_false: files('acpi-vga-stub.c')) endif @@ -51,7 +51,7 @@ if config_all_devices.has_key('CONFIG_QXL') qxl_ss = ss.source_set() qxl_ss.add(when: 'CONFIG_QXL', if_true: [files('qxl.c', 'qxl-logger.c', 'qxl-render.c'), pixman, spice]) - qxl_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'), + qxl_ss.add(when: 'CONFIG_ACPI', if_true: [files('acpi-vga.c'), pixman], if_false: files('acpi-vga-stub.c')) hw_display_modules += {'qxl': qxl_ss} endif @@ -99,14 +99,14 @@ if config_all_devices.has_key('CONFIG_VIRTIO_VGA') if_true: [files('virtio-vga.c'), pixman]) virtio_vga_ss.add(when: 'CONFIG_VHOST_USER_VGA', if_true: files('vhost-user-vga.c')) - virtio_vga_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'), + virtio_vga_ss.add(when: 'CONFIG_ACPI', if_true: [files('acpi-vga.c'), pixman], if_false: files('acpi-vga-stub.c')) hw_display_modules += {'virtio-vga': virtio_vga_ss} virtio_vga_gl_ss = ss.source_set() virtio_vga_gl_ss.add(when: ['CONFIG_VIRTIO_VGA', virgl, opengl], if_true: [files('virtio-vga-gl.c'), pixman]) - virtio_vga_gl_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'), + virtio_vga_gl_ss.add(when: 'CONFIG_ACPI', if_true: [files('acpi-vga.c'), pixman], if_false: files('acpi-vga-stub.c')) hw_display_modules += {'virtio-vga-gl': virtio_vga_gl_ss} endif -- 2.31.1
[PATCH] configure: Use -mlittle-endian instead of -mlittle for ppc64
From: Miroslav Rezanina GCC options -mlittle and -mlittle-endian are equivalent on ppc64 architecture. However, clang supports only -mlittle-endian option. Use longer form in configure to properly support both GCC and clang compiler. Signed-off-by: Miroslav Rezanina --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index e1a31fb332..e63c78ca67 100755 --- a/configure +++ b/configure @@ -658,7 +658,7 @@ case "$cpu" in CPU_CFLAGS="-m64 -mbig" ;; ppc64le) cpu="ppc64" -CPU_CFLAGS="-m64 -mlittle" ;; +CPU_CFLAGS="-m64 -mlittle-endian" ;; s390) CPU_CFLAGS="-m31" ;; -- 2.27.0
[PATCH] configure: Do not use default_feature for EXESUF
From: Miroslav Rezanina Commit "c87ea11631 configure: add --without-default-features" use default_feature to set default values for configure option. This value is used for EXESUF too. However, EXESUF is not option to be tested, it is just append to any binary name so using --without-default-features set EXESUF to "n"o and all binaries using it has form no (e.g. qemu-imgno). This is not expected behavior as disabling features should not cause generating different binary names. Reverting back to setting EXESUF to empty value unless needed otherwise. Signed-off-by: Miroslav Rezanina --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 535e6a9269..8275df1506 100755 --- a/configure +++ b/configure @@ -365,7 +365,7 @@ tcg_interpreter="false" bigendian="no" mingw32="no" gcov="no" -EXESUF="$default_feature" +EXESUF="" HOST_DSOSUF=".so" modules="no" module_upgrades="no" -- 2.27.0
[PATCH v3] Add missing initialization for g_autofree variables
From: Miroslav Rezanina When declaring g_autofree variable without inicialization, compiler will raise "may be used uninitialized in this function" warning due to automatic free handling. This is mentioned in docs/devel/style.rst (quote from section "Automatic memory deallocation"): * Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory Add inicialization for these declarations to prevent the warning and comply with coding style. Signed-off-by: Miroslav Rezanina --- * v3: -- allocate in s390_pci_update_dma_avail instead of NULL init * v2: -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c fixed by patch sent by Zenghui Yu (multi-process: Initialize variables declared with g_auto*) --- hw/s390x/s390-pci-vfio.c | 9 +++-- 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index ead4f222d5..2a153fa8c9 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -29,14 +29,11 @@ */ bool s390_pci_update_dma_avail(int fd, unsigned int *avail) { -g_autofree struct vfio_iommu_type1_info *info; -uint32_t argsz; +uint32_t argsz = sizeof(struct vfio_iommu_type1_info); +g_autofree struct vfio_iommu_type1_info *info = g_malloc0(argsz); assert(avail); -argsz = sizeof(struct vfio_iommu_type1_info); -info = g_malloc0(argsz); - /* * If the specified argsz is not large enough to contain all capabilities * it will be updated upon return from the ioctl. Retry until we have @@ -230,7 +227,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev, */ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { -g_autofree struct vfio_device_info *info; +g_autofree struct vfio_device_info *info = NULL; VFIOPCIDevice *vfio_pci; uint32_t argsz; int fd; -- 2.27.0
[PATCH v2] Add missing initialization for g_autofree variables
From: Miroslav Rezanina When declaring g_autofree variable without inicialization, compiler will raise "may be used uninitialized in this function" warning due to automatic free handling. This is mentioned in docs/devel/style.rst (quote from section "Automatic memory deallocation"): * Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory Add inicialization to NULL for these declaration to prevent this warning. Signed-off-by: Miroslav Rezanina --- * From v1: -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c fixed by patch sent by Zenghui Yu (multi-process: Initialize variables declared with g_auto*) --- hw/s390x/s390-pci-vfio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index ead4f222d5..0ee7dc21f2 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -29,7 +29,7 @@ */ bool s390_pci_update_dma_avail(int fd, unsigned int *avail) { -g_autofree struct vfio_iommu_type1_info *info; +g_autofree struct vfio_iommu_type1_info *info = NULL; uint32_t argsz; assert(avail); @@ -230,7 +230,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev, */ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { -g_autofree struct vfio_device_info *info; +g_autofree struct vfio_device_info *info = NULL; VFIOPCIDevice *vfio_pci; uint32_t argsz; int fd; -- 2.27.0
[PATCH] Use identical prototype for tcg_out_vec_op and tcg_out_op function
From: Miroslav Rezanina There are two different versions of prototype for tcg_out_op and tcg_out_vec_op functions: 1) using const TCGArg *args and const int *const_args arguments 2) using const TCGArg args[TCG_MAX_OP_ARGS] and const int const_args[TCG_MAX_OP_ARGS] aguments. This duality cause warning on GCC 11 and prevent build using --enable-werror. As second version provides more information, unify functions prototypes to this variant. Signed-off-by: Miroslav Rezanina -- Note: These changes were send to mailing list before: - First sending by me using first variant - Several iterations sended by Philippe Mathieu-Daudé with additional fixes that were not accepted. --- tcg/aarch64/tcg-target.c.inc | 3 ++- tcg/i386/tcg-target.c.inc| 6 -- tcg/mips/tcg-target.c.inc| 3 ++- tcg/ppc/tcg-target.c.inc | 8 +--- tcg/riscv/tcg-target.c.inc | 3 ++- tcg/s390/tcg-target.c.inc| 3 ++- tcg/tcg.c| 19 +++ tcg/tci/tcg-target.c.inc | 5 +++-- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index fcaa5aface..f07ba98aa4 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -2286,7 +2286,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, unsigned vecl, unsigned vece, - const TCGArg *args, const int *const_args) + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { static const AArch64Insn cmp_vec_insn[16] = { [TCG_COND_EQ] = I3616_CMEQ, diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index 40326c2806..415c5c0796 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -2177,7 +2177,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) } static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, - const TCGArg *args, const int *const_args) + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { TCGArg a0, a1, a2; int c, const_a2, vexop, rexw = 0; @@ -2613,7 +2614,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, unsigned vecl, unsigned vece, - const TCGArg *args, const int *const_args) + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { static int const add_insn[4] = { OPC_PADDB, OPC_PADDW, OPC_PADDD, OPC_PADDQ diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc index ab55f3109b..8738a3a581 100644 --- a/tcg/mips/tcg-target.c.inc +++ b/tcg/mips/tcg-target.c.inc @@ -1651,7 +1651,8 @@ static void tcg_out_clz(TCGContext *s, MIPSInsn opcv2, MIPSInsn opcv6, } static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, - const TCGArg *args, const int *const_args) + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { MIPSInsn i1, i2; TCGArg a0, a1, a2; diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc index 4377d15d62..838ccfa42d 100644 --- a/tcg/ppc/tcg-target.c.inc +++ b/tcg/ppc/tcg-target.c.inc @@ -2319,8 +2319,9 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out32(s, BCLR | BO_ALWAYS); } -static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, - const int *const_args) +static void tcg_out_op(TCGContext *s, TCGOpcode opc, + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { TCGArg a0, a1, a2; int c; @@ -3115,7 +3116,8 @@ static bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece, static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, unsigned vecl, unsigned vece, - const TCGArg *args, const int *const_args) + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { static const uint32_t add_op[4] = { VADDUBM, VADDUHM, VADDUWM, VADDUDM }, diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc index e700c52067..ef43147040 100644 --- a/tcg/riscv/tcg-target.c.inc +++ b/tcg/riscv/tcg-target.c.inc @@ -1212,7 +1212,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64) static const tcg_insn_unit *tb_ret_addr; static void tcg_out_op(TCGContext *s, TCGOpcode opc, - const TCGArg *args, const int *const_args) +
[PATCH] Add missing initialization for g_autofree variables
From: Miroslav Rezanina When declaring g_autofree variable without inicialization, compiler will raise "may be used uninitialized in this function" warning due to automatic free handling. This usage can cause gfree using unknown. Such behavior can be dangerous and exploitable. Add inicialization to NULL for these declaration to ensure uninitialized value is not used. Signed-off-by: Miroslav Rezanina --- hw/remote/memory.c | 2 +- hw/remote/proxy.c| 2 +- hw/s390x/s390-pci-vfio.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/remote/memory.c b/hw/remote/memory.c index 32085b1e05..bf0047a81b 100644 --- a/hw/remote/memory.c +++ b/hw/remote/memory.c @@ -43,7 +43,7 @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) remote_sysmem_reset(); for (region = 0; region < msg->num_fds; region++) { -g_autofree char *name; +g_autofree char *name = NULL; subregion = g_new(MemoryRegion, 1); name = g_strdup_printf("remote-mem-%u", suffix++); memory_region_init_ram_from_fd(subregion, NULL, diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 4fa4be079d..253c1aa7ec 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -347,7 +347,7 @@ static void probe_pci_info(PCIDevice *dev, Error **errp) PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY; if (size) { -g_autofree char *name; +g_autofree char *name = NULL; pdev->region[i].dev = pdev; pdev->region[i].present = true; if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index ead4f222d5..0ee7dc21f2 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -29,7 +29,7 @@ */ bool s390_pci_update_dma_avail(int fd, unsigned int *avail) { -g_autofree struct vfio_iommu_type1_info *info; +g_autofree struct vfio_iommu_type1_info *info = NULL; uint32_t argsz; assert(avail); @@ -230,7 +230,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev, */ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { -g_autofree struct vfio_device_info *info; +g_autofree struct vfio_device_info *info = NULL; VFIOPCIDevice *vfio_pci; uint32_t argsz; int fd; -- 2.27.0
[RHEL7 qemu-kvm PATCH 1/3] Fix net.c warning on GCC 11
From: Miroslav Rezanina When building qemu with GCC 11, compiling eth.c file produce following warning: warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds] This caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more attributes. As this usage is expected, suppress the warning temporarily through the function using this retyping. Signed-off-by: Miroslav Rezanina --- net/eth.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/eth.c b/net/eth.c index 1e0821c5f8..b9bdd0435c 100644 --- a/net/eth.c +++ b/net/eth.c @@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags, struct ip6_ext_hdr *ext_hdr, struct in6_address *dst_addr) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr; if ((rthdr->rtype == 2) && @@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags, } return false; +#pragma GCC diagnostic pop } static bool -- 2.18.4
[RHEL7 qemu-kvm PATCH 3/3] Fix tcg_out_op argument mismatch warning
From: Miroslav Rezanina There's prototype mismatch between tcg/tcg.c and tcg/aarch/tcg-target.c.inc: tcg.c: static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, const int *const_args); tcg-target.c.inc: static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS]) This missmatch cause warnings on GCC 11: tcg/aarch64/tcg-target.c.inc:1855:37: error: argument 3 of type 'const TCGArg[16]' {aka 'const long unsigned int[16]'} with mismatched bound [-Werror=array-parameter=] tcg/aarch64/tcg-target.c.inc:1856:34: error: argument 4 of type 'const int[16]' with mismatched bound [-Werror=array-parameter=] Only architectures with this definition are aarch and sparc. Fixing both archs to use proper argument type. --- tcg/aarch64/tcg-target.c.inc | 3 +-- tcg/sparc/tcg-target.c.inc | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index 26f71cb599..fe6bdbf721 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -1852,8 +1852,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg, static tcg_insn_unit *tb_ret_addr; static void tcg_out_op(TCGContext *s, TCGOpcode opc, - const TCGArg args[TCG_MAX_OP_ARGS], - const int const_args[TCG_MAX_OP_ARGS]) + const TCGArg *args, const int *const_args) { /* 99% of the time, we can signal the use of extension registers by looking to see if the opcode handles 64-bit data. */ diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc index 6775bd30fc..976f0f05af 100644 --- a/tcg/sparc/tcg-target.c.inc +++ b/tcg/sparc/tcg-target.c.inc @@ -1294,8 +1294,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr, } static void tcg_out_op(TCGContext *s, TCGOpcode opc, - const TCGArg args[TCG_MAX_OP_ARGS], - const int const_args[TCG_MAX_OP_ARGS]) + const TCGArg *args, const int *const_args) { TCGArg a0, a1, a2; int c, c2; -- 2.18.4
[RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length
From: Miroslav Rezanina There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters). Updating length to copy so there is space for closing \0. Signed-off-by: Miroslav Rezanina --- target/s390x/kvm.c | 2 +- target/s390x/misc_helper.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index b8385e6b95..2313b5727e 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) */ if (qemu_name) { strncpy((char *)sysib.ext_names[0], qemu_name, -sizeof(sysib.ext_names[0])); +sizeof(sysib.ext_names[0]) - 1); } else { strcpy((char *)sysib.ext_names[0], "KVMguest"); } diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c index 58dbc023eb..7c478b9e58 100644 --- a/target/s390x/misc_helper.c +++ b/target/s390x/misc_helper.c @@ -369,8 +369,10 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1) ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name, MIN(sizeof(sysib.sysib_322.vm[0].name), strlen(qemu_name))); + memset((char *)sysib.sysib_322.ext_names[0], 0, + sizeof(sysib.sysib_322.ext_names[0])); strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name, -sizeof(sysib.sysib_322.ext_names[0])); +sizeof(sysib.sysib_322.ext_names[0]) - 1); } else { ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8); strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest"); -- 2.18.4
[RHEL7 qemu-kvm PATCH 0/3] Fixing several GCC 11 warnings
From: Miroslav Rezanina Compiling qemu using GCC 11 we got several new warnings. To allow build with --enable-werror, we need to solve issues generating these warnings. Signed-of-by: Miroslav Rezanina Miroslav Rezanina (3): Fix net.c warning on GCC 11 s390x: Fix vm name copy length Fix tcg_out_op argument mismatch warning net/eth.c| 3 +++ target/s390x/kvm.c | 2 +- target/s390x/misc_helper.c | 4 +++- tcg/aarch64/tcg-target.c.inc | 3 +-- tcg/sparc/tcg-target.c.inc | 3 +-- 5 files changed, 9 insertions(+), 6 deletions(-) -- 2.18.4
[PATCH 1/2] test-logging: Fix -Werror=maybe-uninitialized warning
From: Miroslav Rezanina Checking for uninitialized variables raises warning for file path variables in test_logfile_write and test_logfile_lock functions. To suppress this warning, initialize varibles to NULL. This is safe change as result of g_build_filename is stored to them before any usage. Signed-off-by: Miroslav Rezanina --- tests/test-logging.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-logging.c b/tests/test-logging.c index 1e646f0..6387e49 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -114,8 +114,8 @@ static void test_logfile_write(gconstpointer data) QemuLogFile *logfile2; gchar const *dir = data; Error *err = NULL; -g_autofree gchar *file_path; -g_autofree gchar *file_path1; +g_autofree gchar *file_path = NULL; +g_autofree gchar *file_path1 = NULL; FILE *orig_fd; /* @@ -157,7 +157,7 @@ static void test_logfile_lock(gconstpointer data) FILE *logfile; gchar const *dir = data; Error *err = NULL; -g_autofree gchar *file_path; +g_autofree gchar *file_path = NULL; file_path = g_build_filename(dir, "qemu_test_logfile_lock0.log", NULL); -- 1.8.3.1
[PATCH 0/2] Prevent uninitialized warnings
From: Miroslav Rezanina Using -Wmaybe-uninitialized when optimalization is enabled can cause several warnings during build. This will break build in case -Werror is used. This series fixes two cases of this warnings that can happen during build of QEMU. Miroslav Rezanina (2): test-logging: Fix -Werror=maybe-uninitialized warning aspeed/i2c: Prevent uninitialized warning hw/i2c/aspeed_i2c.c | 2 +- tests/test-logging.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) -- 1.8.3.1
[PATCH 2/2] aspeed/i2c: Prevent uninitialized warning
From: Miroslav Rezanina Compiler reports uninitialized warning for cmd_flags variable. Adding NULL initialization to prevent this warning. Signed-off-by: Miroslav Rezanina --- hw/i2c/aspeed_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index 2da04a4..445182a 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -400,7 +400,7 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus) static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus) { -g_autofree char *cmd_flags; +g_autofree char *cmd_flags = NULL; uint32_t count; if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) { -- 1.8.3.1
[Qemu-devel] [PATCH] Use CONFIG_VHOST_USER_SCSI to enable vhost-scsi-pci
From: Miroslav RezaninaCurrently, "defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)" is used to enable/disable vhost-scsi-pci build as this condition is used to enable/disable CONFIG_VHOST_USER_SCSI too. However, when CONFIG_VHOST_USER_SCSI is manually disable vhost-scsi-pci is still registered although it should be disabled. Changing condition to use CONFIG_VHOST_USER_SCSI so vhost-scsi-pci can be controled by CONFIG_VHOST_USER_SCSI option. Signed-off-by: Miroslav Rezanina --- hw/virtio/virtio-pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1e8ab7b..df59d6b 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2163,7 +2163,7 @@ static const TypeInfo vhost_scsi_pci_info = { }; #endif -#if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) +#if defined(CONFIG_VHOST_USER_SCSI) /* vhost-user-scsi-pci */ static Property vhost_user_scsi_pci_properties[] = { DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, @@ -2696,7 +2696,7 @@ static void virtio_pci_register_types(void) #ifdef CONFIG_VHOST_SCSI type_register_static(_scsi_pci_info); #endif -#if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) +#if defined(CONFIG_VHOST_USER_SCSI) type_register_static(_user_scsi_pci_info); #endif #ifdef CONFIG_VHOST_VSOCK -- 1.8.3.1
[Qemu-devel] [PATCH] Whitelist sysinfo call
From: Miroslav RezaninaNewer version of nss-softokn libraries (> 3.16.2.3) use sysinfo call so qemu using rbd image hang after start when run in sandbox mode. To allow using rbd images in sandbox mode we have to whitelist it. Signed-off-by: Miroslav Rezanina --- qemu-seccomp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qemu-seccomp.c b/qemu-seccomp.c index 2866e3c..e29fca1 100644 --- a/qemu-seccomp.c +++ b/qemu-seccomp.c @@ -250,6 +250,7 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = { #ifdef HAVE_CACHEFLUSH { SCMP_SYS(cacheflush), 240 }, #endif +{ SCMP_SYS(sysinfo), 240 }, }; int seccomp_start(void) -- 2.5.0
[Qemu-devel] [PATCH] net: fix insecure temporary file creation in SLiRP
From: Miroslav Rezanina mreza...@redhat.com Qemu's user mode networking stack(-net user) is vulnerable to a predictable temporary file creation flaw. This patch uses mkdtemp(3) routine to fix it. Fixes CVE-2015-4037. Signed-off-by: P J P p...@fedoraproject.org Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- [1] http://seclists.org/oss-sec/2015/q2/538 --- net/slirp.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 0e15cf6..804b095 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -27,6 +27,7 @@ #ifndef _WIN32 #include pwd.h +#include stdlib.h #include sys/wait.h #endif #include net/net.h @@ -481,9 +482,9 @@ static void slirp_smb_cleanup(SlirpState *s) static int slirp_smb(SlirpState* s, const char *exported_dir, struct in_addr vserver_addr) { -static int instance; char smb_conf[128]; char smb_cmdline[128]; +char smb_dir[] = /tmp/qemu-smb.XX, *tmpdir = NULL; struct passwd *passwd; FILE *f; @@ -505,12 +506,11 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, return -1; } -snprintf(s-smb_dir, sizeof(s-smb_dir), /tmp/qemu-smb.%ld-%d, - (long)getpid(), instance++); -if (mkdir(s-smb_dir, 0700) 0) { -error_report(could not create samba server dir '%s', s-smb_dir); +if (!(tmpdir = mkdtemp(smb_dir))) { +error_report(could not create samba server dir '%s', smb_dir); return -1; } +strncpy(s-smb_dir, tmpdir, sizeof(s-smb_dir)); snprintf(smb_conf, sizeof(smb_conf), %s/%s, s-smb_dir, smb.conf); f = fopen(smb_conf, w); -- 2.4.1
[Qemu-devel] [PATCHv4] Move parallel_hds_isa_init to hw/isa/isa-bus.c
From: Miroslav Rezanina mreza...@redhat.com Disabling CONFIG_PARALLEL cause removing parallel_hds_isa_init defined in parallel.c. This function is called during initialization of some boards so disabling CONFIG_PARALLEL cause build failure. This patch moves parallel_hds_isa_init to hw/isa/isa-bus.c so it is included in case of disabled CONFIG_PARALLEL. Build is successful but qemu will abort with Unknown device error when function is called. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/char/parallel.c | 25 - hw/isa/isa-bus.c | 26 ++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/hw/char/parallel.c b/hw/char/parallel.c index 4079554..c2b553f 100644 --- a/hw/char/parallel.c +++ b/hw/char/parallel.c @@ -641,28 +641,3 @@ static void parallel_register_types(void) } type_init(parallel_register_types) - -static void parallel_init(ISABus *bus, int index, CharDriverState *chr) -{ -DeviceState *dev; -ISADevice *isadev; - -isadev = isa_create(bus, isa-parallel); -dev = DEVICE(isadev); -qdev_prop_set_uint32(dev, index, index); -qdev_prop_set_chr(dev, chardev, chr); -qdev_init_nofail(dev); -} - -void parallel_hds_isa_init(ISABus *bus, int n) -{ -int i; - -assert(n = MAX_PARALLEL_PORTS); - -for (i = 0; i n; i++) { -if (parallel_hds[i]) { -parallel_init(bus, i, parallel_hds[i]); -} -} -} diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index 825aa62..ec8e7de 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -21,6 +21,7 @@ #include hw/sysbus.h #include sysemu/sysemu.h #include hw/isa/isa.h +#include hw/i386/pc.h static ISABus *isabus; @@ -267,3 +268,28 @@ MemoryRegion *isa_address_space_io(ISADevice *dev) } type_init(isabus_register_types) + +static void parallel_init(ISABus *bus, int index, CharDriverState *chr) +{ +DeviceState *dev; +ISADevice *isadev; + +isadev = isa_create(bus, isa-parallel); +dev = DEVICE(isadev); +qdev_prop_set_uint32(dev, index, index); +qdev_prop_set_chr(dev, chardev, chr); +qdev_init_nofail(dev); +} + +void parallel_hds_isa_init(ISABus *bus, int n) +{ +int i; + +assert(n = MAX_PARALLEL_PORTS); + +for (i = 0; i n; i++) { +if (parallel_hds[i]) { +parallel_init(bus, i, parallel_hds[i]); +} +} +} -- 2.1.0
[Qemu-devel] [PATCHv3 0/2] parallel: Allow to disable CONFIG_PARALLEL
From: Miroslav Rezanina mreza...@redhat.com There's few uncoditional calls to functions in hw/char/parallel.c so disabling CONFIG_PARALLEL can cause build failure. This series allow building with CONFIG_PARALLEL disabled. In addition, it changes behavior so the run of qemu -parallel will abort in case target expects parallel device to exists. Affected targets are: - i386 (pc.c) - mips (mips_fulong2e.c, mips_malta.c, mips_jazz.c) - sparc64 (sun4u.c) Signed-off-by: Miroslav Rezanina mreza...@redhat.com Miroslav Rezanina (2): Move parallel_hds_isa_init to hw/isa/isa-bus.c stubs: Provide parallel_mm_init stub version hw/char/parallel.c | 25 - hw/isa/isa-bus.c| 29 + stubs/Makefile.objs | 1 + stubs/parallel.c| 8 4 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 stubs/parallel.c -- 2.1.0
[Qemu-devel] [PATCHv3 1/2] Move parallel_hds_isa_init to hw/isa/isa-bus.c
From: Miroslav Rezanina mreza...@redhat.com Disabling CONFIG_PARALLEL cause removing parallel_hds_isa_init defined in parallel.c. This function is called during initialization of some boards so disabling CONFIG_PARALLEL cause build failure. This patch moves parallel_hds_isa_init to hw/isa/isa-bus.c so it is included in case of disabled CONFIG_PARALLEL. Build is successful but qemu will abort with Unknown device error when function is called. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/char/parallel.c | 25 - hw/isa/isa-bus.c | 29 + 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/hw/char/parallel.c b/hw/char/parallel.c index 4079554..c2b553f 100644 --- a/hw/char/parallel.c +++ b/hw/char/parallel.c @@ -641,28 +641,3 @@ static void parallel_register_types(void) } type_init(parallel_register_types) - -static void parallel_init(ISABus *bus, int index, CharDriverState *chr) -{ -DeviceState *dev; -ISADevice *isadev; - -isadev = isa_create(bus, isa-parallel); -dev = DEVICE(isadev); -qdev_prop_set_uint32(dev, index, index); -qdev_prop_set_chr(dev, chardev, chr); -qdev_init_nofail(dev); -} - -void parallel_hds_isa_init(ISABus *bus, int n) -{ -int i; - -assert(n = MAX_PARALLEL_PORTS); - -for (i = 0; i n; i++) { -if (parallel_hds[i]) { -parallel_init(bus, i, parallel_hds[i]); -} -} -} diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index 825aa62..94f645c 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -21,6 +21,7 @@ #include hw/sysbus.h #include sysemu/sysemu.h #include hw/isa/isa.h +#include hw/i386/pc.h static ISABus *isabus; @@ -267,3 +268,31 @@ MemoryRegion *isa_address_space_io(ISADevice *dev) } type_init(isabus_register_types) + +static void parallel_init(ISABus *bus, int index, CharDriverState *chr) +{ +DeviceState *dev; +ISADevice *isadev; + +isadev = isa_try_create(bus, isa-parallel); +if (!isadev) { + return; +} +dev = DEVICE(isadev); +qdev_prop_set_uint32(dev, index, index); +qdev_prop_set_chr(dev, chardev, chr); +qdev_init_nofail(dev); +} + +void parallel_hds_isa_init(ISABus *bus, int n) +{ +int i; + +assert(n = MAX_PARALLEL_PORTS); + +for (i = 0; i n; i++) { +if (parallel_hds[i]) { +parallel_init(bus, i, parallel_hds[i]); +} +} +} -- 2.1.0
[Qemu-devel] [PATCHv3 2/2] stubs: Provide parallel_mm_init stub version
From: Miroslav Rezanina mreza...@redhat.com mips build fail with link error in case PARALLEL_CONFIG is disabled as hw/mips/mips_jazz.c calls parallel_mm_init. Due to dependecies to content of parallel.c we can't simply move it to hw/isa/isa-devices.c. This patch adds stubs/parallel.c file that contains stub version of parallel_mm_init. This ensure successful build with PARALLEL_CONFIG disabled. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- stubs/Makefile.objs | 1 + stubs/parallel.c| 8 2 files changed, 9 insertions(+) create mode 100644 stubs/parallel.c diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 8beff4c..ad4e110 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -24,6 +24,7 @@ stub-obj-y += mon-printf.o stub-obj-y += mon-set-error.o stub-obj-y += monitor-init.o stub-obj-y += notify-event.o +stub-obj-y += parallel.o stub-obj-$(CONFIG_SPICE) += qemu-chr-open-spice.o stub-obj-y += qtest.o stub-obj-y += reset.o diff --git a/stubs/parallel.c b/stubs/parallel.c new file mode 100644 index 000..8293d52 --- /dev/null +++ b/stubs/parallel.c @@ -0,0 +1,8 @@ +#include hw/i386/pc.h + +bool parallel_mm_init(MemoryRegion *address_space, + hwaddr base, int it_shift, qemu_irq irq, + CharDriverState *chr) +{ +return false; +} -- 2.1.0
[Qemu-devel] [PATCHv2] parallel: Allow to disable CONFIG_PARALLEL
From: Miroslav Rezanina mreza...@redhat.com Disabling CONFIG_PARALLEL cause build failure as commit 07dc788 factored out initialization to parallel_hds_isa_init function in hw/char/parallel.c that is not build. Stub file is added to be able to disable CONFIG_PARALLEL. This file is used in targets using parallel_hds_isa_init and provide empty definition of this function. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/i386/Makefile.objs| 1 + hw/mips/Makefile.objs| 2 ++ hw/sparc64/Makefile.objs | 2 ++ stubs/parallel-stub.c| 7 +++ 4 files changed, 12 insertions(+) create mode 100644 stubs/parallel-stub.c diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index e058a39..2b7131a 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -4,6 +4,7 @@ obj-y += pc.o pc_piix.o pc_q35.o obj-y += pc_sysfw.o obj-y += intel_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ +obj-$(call lnot,$(CONFIG_PARALLEL)) += ../../stubs/parallel-stub.o obj-y += kvmvapic.o obj-y += acpi-build.o diff --git a/hw/mips/Makefile.objs b/hw/mips/Makefile.objs index 0a652f8..2e65305 100644 --- a/hw/mips/Makefile.objs +++ b/hw/mips/Makefile.objs @@ -2,3 +2,5 @@ obj-y += mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o obj-y += addr.o cputimer.o mips_int.o obj-$(CONFIG_FULONG) += mips_fulong2e.o obj-y += gt64xxx_pci.o +obj-$(call lnot,$(CONFIG_PARALLEL)) += ../../stubs/parallel-stub.o + diff --git a/hw/sparc64/Makefile.objs b/hw/sparc64/Makefile.objs index a84cfe3..7696611 100644 --- a/hw/sparc64/Makefile.objs +++ b/hw/sparc64/Makefile.objs @@ -1 +1,3 @@ obj-y += sun4u.o +obj-$(call lnot,$(CONFIG_PARALLEL)) += ../../stubs/parallel-stub.o + diff --git a/stubs/parallel-stub.c b/stubs/parallel-stub.c new file mode 100644 index 000..949c1b2 --- /dev/null +++ b/stubs/parallel-stub.c @@ -0,0 +1,7 @@ +#include qemu/typedefs.h +#include hw/isa/isa.h +#include hw/i386/pc.h + +void parallel_hds_isa_init(ISABus *bus, int n) +{ +} -- 2.1.0
[Qemu-devel] [PATCH] parallel: Allow to disable CONFIG_PARALLEL
From: Miroslav Rezanina mreza...@redhat.com Disabling CONFIG_PARALLEL cause build failure as commit 07dc788 factored out initialization to parallel_hds_isa_init that is not build. Make calling parallel_hds_isa_init depending on CONFIG_PARALLEL so it can be correctly disabled. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/i386/pc.c| 2 ++ hw/mips/mips_fulong2e.c | 2 ++ hw/mips/mips_malta.c| 2 ++ hw/sparc64/sun4u.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index a8e6be1..560464e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1465,7 +1465,9 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, } serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS); +#ifdef CONFIG_PARALLEL parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS); +#endif a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2); i8042 = isa_create_simple(isa_bus, i8042); diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index dea941a..bd73fa6 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -384,7 +384,9 @@ static void mips_fulong2e_init(MachineState *machine) rtc_init(isa_bus, 2000, NULL); serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS); +#ifdef CONFIG_PARALLEL parallel_hds_isa_init(isa_bus, 1); +#endif /* Sound card */ audio_init(pci_bus); diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 482250d..f2246fb 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -1173,7 +1173,9 @@ void mips_malta_init(MachineState *machine) rtc_init(isa_bus, 2000, NULL); serial_hds_isa_init(isa_bus, 2); +#ifdef CONFIG_PARALLEL parallel_hds_isa_init(isa_bus, 1); +#endif for(i = 0; i MAX_FD; i++) { fd[i] = drive_get(IF_FLOPPY, 0, i); diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 6f34e87..6b88558 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -855,7 +855,9 @@ static void sun4uv_init(MemoryRegion *address_space_mem, } serial_hds_isa_init(isa_bus, MAX_SERIAL_PORTS); +#ifdef CONFIG_PARALLEL parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS); +#endif for(i = 0; i nb_nics; i++) pci_nic_init_nofail(nd_table[i], pci_bus, ne2k_pci, NULL); -- 2.1.0
[Qemu-devel] [PATCHv2] Prevent segmentation fault in case of relative resolve of uri
From: Miroslav Rezanina mreza...@redhat.com It was possible to call strcmp with NULL argument, that can cause segmentation fault. Properly checking parameters to prevent this situation. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- v2: - instead of adding NULL checks to strcmp call refactor whole NULL checking path. This will remove dead code and make whole checking easier to understand. Relative path generation part is not touched as I'm not fully sure of correct behavior and purpose of this patch is to prevent segmentation fault. --- util/uri.c | 55 +-- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/util/uri.c b/util/uri.c index 918d235..23dbaca 100644 --- a/util/uri.c +++ b/util/uri.c @@ -1964,44 +1964,39 @@ uri_resolve_relative (const char *uri, const char * base) * If the scheme / server on the URI differs from the base, * just return the URI */ -if ((ref-scheme != NULL) - ((bas-scheme == NULL) || -(strcmp (bas-scheme, ref-scheme)) || -(strcmp (bas-server, ref-server { - val = g_strdup (uri); - goto done; + +if ((ref-scheme != NULL) +((bas-scheme == NULL) || (strcmp (bas-scheme, ref-scheme { +val = g_strdup(uri); +goto done; } -if (!strcmp(bas-path, ref-path)) { - val = g_strdup(); - goto done; -} -if (bas-path == NULL) { - val = g_strdup(ref-path); - goto done; +if ((ref-server != NULL) +((bas-server == NULL) || (strcmp (bas-server, ref-server { +val = g_strdup(uri); +goto done; } + if (ref-path == NULL) { ref-path = (char *) /; - remove_path = 1; +remove_path = 1; } -/* - * At this point (at last!) we can compare the two paths - * - * First we take care of the special case where either of the - * two path components may be missing (bug 316224) - */ if (bas-path == NULL) { - if (ref-path != NULL) { - uptr = ref-path; - if (*uptr == '/') - uptr++; - /* exception characters from uri_to_string */ - val = uri_string_escape(uptr, /;=+$,); - } - goto done; +uptr = ref-path; +if (*uptr == '/') +uptr++; +/* exception characters from uri_to_string */ +val = uri_string_escape(uptr, /;=+$,); +goto done; } + +if (!strcmp(bas-path, ref-path)) { +val = g_strdup(); +goto done; +} + bptr = bas-path; -if (ref-path == NULL) { +if (remove_path == 1) { for (ix = 0; bptr[ix] != 0; ix++) { if (bptr[ix] == '/') nbslash++; @@ -2010,7 +2005,7 @@ uri_resolve_relative (const char *uri, const char * base) len = 1;/* this is for a string terminator only */ } else { /* - * Next we compare the two strings and find where they first differ + * We compare the two strings and find where they first differ */ if ((ref-path[pos] == '.') (ref-path[pos+1] == '/')) pos += 2; -- 2.1.0
[Qemu-devel] [PATCH] Prevent segmentation fault in case of relative resolve of uri
From: Miroslav Rezanina mreza...@redhat.com It was possible to call strcmp with NULL argument, that can cause segmentation fault. Properly checking parameters to prevent this situation. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- util/uri.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/uri.c b/util/uri.c index e348c17..16c01d0 100644 --- a/util/uri.c +++ b/util/uri.c @@ -1985,7 +1985,8 @@ uri_resolve_relative (const char *uri, const char * base) val = g_strdup (uri); goto done; } -if (!strcmp(bas-path, ref-path)) { +if (bas-path != NULL ref-path != NULL +!strcmp(bas-path, ref-path)) { val = g_strdup(); goto done; } -- 1.9.3
[Qemu-devel] [PATCH] Enforce stack protector usage
From: Miroslav Rezanina mreza...@redhat.com If --enable-stack-protector is used is used, configure script try to use --fstack-protector-strong. In case it's not supported, --fstack-protector-all is enabled. If both protectors are not supported, configure does not use any protector at all without any notification. This patch reports error when user requests stack protector to be used and both protector modes are not supported. Behavior is not changed in case user do not use any of --enable-stack-protector/--disable-stack-protector. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- configure | 7 +++ 1 file changed, 7 insertions(+) diff --git a/configure b/configure index 7dd43fd..b880954 100755 --- a/configure +++ b/configure @@ -1491,6 +1491,7 @@ done if test $stack_protector != no ; then gcc_flags=-fstack-protector-strong -fstack-protector-all + sp_on=0 for flag in $gcc_flags; do # We need to check both a compile and a link, since some compiler # setups fail only on a .c-.o compile and some only at link time @@ -1498,9 +1499,15 @@ if test $stack_protector != no ; then compile_prog -Werror $flag ; then QEMU_CFLAGS=$QEMU_CFLAGS $flag LIBTOOLFLAGS=$LIBTOOLFLAGS -Wc,$flag + sp_on=1 break fi done + if test $stack_protector == yes ; then +if test $sp_on == 0 ; then + error_exit Stack protector not supported +fi + fi fi # Workaround for http://gcc.gnu.org/PR55489. Happens with -fPIE/-fPIC and -- 1.9.3
[Qemu-devel] [PATCH v7] vl.c: Output error on invalid machine type
From: Miroslav Rezanina mreza...@redhat.com Output error message using qemu's error_report() function when user provides the invalid machine type on the command line. This also saves time to find what issue is when you downgrade from one version of qemu to another that doesn't support required machine type yet (the version user downgraded to have to have this patch applied too, of course). Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- v7: - use -machine instead of -M in error help message - rebase to commit 0056ae2 v6: - print help instead of list supported machines on error --- vl.c | 21 + 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/vl.c b/vl.c index 862cf20..cbd1381 100644 --- a/vl.c +++ b/vl.c @@ -2649,15 +2649,20 @@ static MachineClass *machine_parse(const char *name) if (mc) { return mc; } -printf(Supported machines are:\n); -for (el = machines; el; el = el-next) { -MachineClass *mc = el-data; -QEMUMachine *m = mc-qemu_machine; -if (m-alias) { -printf(%-20s %s (alias of %s)\n, m-alias, m-desc, m-name); +if (name !is_help_option(name)) { +error_report(Unsupported machine type); +printf(\nUse -machine help to list supported machines!\n); +} else { +printf(Supported machines are:\n); +for (el = machines; el; el = el-next) { +MachineClass *mc = el-data; +QEMUMachine *m = mc-qemu_machine; +if (m-alias) { +printf(%-20s %s (alias of %s)\n, m-alias, m-desc, m-name); +} +printf(%-20s %s%s\n, m-name, m-desc, + m-is_default ? (default) : ); } -printf(%-20s %s%s\n, m-name, m-desc, - m-is_default ? (default) : ); } g_slist_free(machines); -- 1.8.5.3
[Qemu-devel] [PATCH] qemu-doc.texi: Replace remaining obsolete -M option
From: Miroslav Rezanina mreza...@redhat.com When -M option was deprecated (commit 80f52a6) and removed from documentation, two occurrencies were not updated corectly. Fixing them. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- qemu-doc.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-doc.texi b/qemu-doc.texi index ad31f2d..a7eab5c 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2047,7 +2047,7 @@ qemu-system-sparc -prom-env 'auto-boot?=false' \ -prom-env 'boot-device=sd(0,2,0):d' -prom-env 'boot-args=linux single' @end example -@item -M [SS-4|SS-5|SS-10|SS-20|SS-600MP|LX|Voyager|SPARCClassic] [|SPARCbook] +@item -machine [SS-4|SS-5|SS-10|SS-20|SS-600MP|LX|Voyager|SPARCClassic] [|SPARCbook] Set the emulated machine type. Default is SS-5. @@ -2097,7 +2097,7 @@ Set OpenBIOS variables in NVRAM, for example: qemu-system-sparc64 -prom-env 'auto-boot?=false' @end example -@item -M [sun4u|sun4v|Niagara] +@item -machine [sun4u|sun4v|Niagara] Set the emulated machine type. The default is sun4u. -- 1.8.5.3
[Qemu-devel] [PATCH v6] vl.c: Output error on invalid machine type
From: Miroslav Rezanina mreza...@redhat.com Output error message using qemu's error_report() function when user provides the invalid machine type on the command line. This also saves time to find what issue is when you downgrade from one version of qemu to another that doesn't support required machine type yet (the version user downgraded to have to have this patch applied too, of course). Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- v6: - print help instead of list supported machines on error vl.c | 18 -- 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vl.c b/vl.c index 383be1b..3297c0a 100644 --- a/vl.c +++ b/vl.c @@ -2600,13 +2600,19 @@ static QEMUMachine *machine_parse(const char *name) if (machine) { return machine; } -printf(Supported machines are:\n); -for (m = first_machine; m != NULL; m = m-next) { -if (m-alias) { -printf(%-20s %s (alias of %s)\n, m-alias, m-desc, m-name); + +if (name !is_help_option(name)) { +error_report(Unsupported machine type); +printf(\nUse '-M help' to list supported machines!\n); +} else { +printf(Supported machines are:\n); +for (m = first_machine; m != NULL; m = m-next) { +if (m-alias) { +printf(%-20s %s (alias of %s)\n, m-alias, m-desc, m-name); +} +printf(%-20s %s%s\n, m-name, m-desc, + m-is_default ? (default) : ); } -printf(%-20s %s%s\n, m-name, m-desc, - m-is_default ? (default) : ); } exit(!name || !is_help_option(name)); } -- 1.8.5.3
[Qemu-devel] [PATCH] Move hpet_find function from hpet.c to pc.c
From: Miroslav Rezanina mreza...@redhat.com Function hpet_find could not be used for checking hpet availability becouse it was not build when hpet was disabled. To allow proper use of this function, moving it from hw/timer/hpet.c to hw/i386/pc.c. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/i386/pc.c| 5 + hw/timer/hpet.c | 5 - include/hw/i386/pc.h| 2 ++ include/hw/timer/hpet.h | 1 - 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 12c436e..7fd08dd 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1403,3 +1403,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) gsi_state-ioapic_irq[i] = qdev_get_gpio_in(dev, i); } } + +bool hpet_find(void) +{ +return object_resolve_path_type(, hpet, NULL); +} diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 2eb75ea..fcd22ae 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -757,11 +757,6 @@ static void hpet_device_class_init(ObjectClass *klass, void *data) dc-props = hpet_device_properties; } -bool hpet_find(void) -{ -return object_resolve_path_type(, TYPE_HPET, NULL); -} - static const TypeInfo hpet_device_info = { .name = TYPE_HPET, .parent= TYPE_SYS_BUS_DEVICE, diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 09652fb..f81b615 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -178,6 +178,8 @@ void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr); /* hpet.c */ extern int no_hpet; +bool hpet_find(void); + /* piix_pci.c */ struct PCII440FXState; typedef struct PCII440FXState PCII440FXState; diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h index ab44bd3..3fae8ad 100644 --- a/include/hw/timer/hpet.h +++ b/include/hw/timer/hpet.h @@ -72,5 +72,4 @@ struct hpet_fw_config extern struct hpet_fw_config hpet_cfg; -bool hpet_find(void); #endif -- 1.8.3.1
[Qemu-devel] [PATCHv2] Make usb-bt-dongle configurable
From: Miroslav Rezanina mreza...@redhat.com Use usb_legacy_register handling to create bt-dongle device. This allows to disable usb-bt-dongle device using CONFIG_BLUETOOTH option. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/bt/core.c | 25 hw/bt/hci.c| 51 hw/usb/Makefile.objs | 3 -- hw/usb/dev-bluetooth.c | 10 ++- include/hw/bt.h| 3 ++ include/hw/usb.h | 3 -- vl.c | 79 ++ 7 files changed, 91 insertions(+), 83 deletions(-) diff --git a/hw/bt/core.c b/hw/bt/core.c index 49012e0..ef27b15 100644 --- a/hw/bt/core.c +++ b/hw/bt/core.c @@ -119,3 +119,28 @@ void bt_device_done(struct bt_device_s *dev) *p = dev-next; } + +static struct bt_vlan_s { +struct bt_scatternet_s net; +int id; +struct bt_vlan_s *next; +} *first_bt_vlan; + +/* find or alloc a new bluetooth VLAN */ +struct bt_scatternet_s *qemu_find_bt_vlan(int id) +{ +struct bt_vlan_s **pvlan, *vlan; +for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) { +if (vlan-id == id) { +return vlan-net; +} +} +vlan = g_malloc0(sizeof(struct bt_vlan_s)); +vlan-id = id; +pvlan = first_bt_vlan; +while (*pvlan != NULL) { +pvlan = (*pvlan)-next; +} +*pvlan = vlan; +return vlan-net; +} diff --git a/hw/bt/hci.c b/hw/bt/hci.c index d1c0604..d69ab53 100644 --- a/hw/bt/hci.c +++ b/hw/bt/hci.c @@ -429,6 +429,24 @@ static const uint8_t bt_event_reserved_mask[8] = { 0xff, 0x9f, 0xfb, 0xff, 0x07, 0x18, 0x00, 0x00, }; + +static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) +{ +} + +static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) +{ +return -ENOTSUP; +} + +struct HCIInfo null_hci = { +.cmd_send = null_hci_send, +.sco_send = null_hci_send, +.acl_send = null_hci_send, +.bdaddr_set = null_hci_addr_set, +}; + + static inline uint8_t *bt_hci_event_start(struct bt_hci_s *hci, int evt, int len) { @@ -2176,6 +2194,39 @@ struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net) return s-info; } +struct HCIInfo *hci_init(const char *str) +{ +char *endp; +struct bt_scatternet_s *vlan = 0; + +if (!strcmp(str, null)) { +/* null */ +return null_hci; +} else if (!strncmp(str, host, 4) (str[4] == '\0' || str[4] == ':')) { +/* host[:hciN] */ +return bt_host_hci(str[4] ? str + 5 : hci0); +} else if (!strncmp(str, hci, 3)) { +/* hci[,vlan=n] */ +if (str[3]) { +if (!strncmp(str + 3, ,vlan=, 6)) { +vlan = qemu_find_bt_vlan(strtol(str + 9, endp, 0)); +if (*endp) { +vlan = 0; +} +} +} else { +vlan = qemu_find_bt_vlan(0); +} +if (vlan) { +return bt_new_hci(vlan); +} +} + +fprintf(stderr, qemu: Unknown bluetooth HCI `%s'.\n, str); + +return 0; +} + static void bt_hci_done(struct HCIInfo *info) { struct bt_hci_s *hci = hci_from_info(info); diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs index f9695e7..a3eac3e 100644 --- a/hw/usb/Makefile.objs +++ b/hw/usb/Makefile.objs @@ -18,9 +18,6 @@ common-obj-$(CONFIG_USB_STORAGE_UAS) += dev-uas.o common-obj-$(CONFIG_USB_AUDIO)+= dev-audio.o common-obj-$(CONFIG_USB_SERIAL) += dev-serial.o common-obj-$(CONFIG_USB_NETWORK) += dev-network.o - -# FIXME: make configurable too -CONFIG_USB_BLUETOOTH := y common-obj-$(CONFIG_USB_BLUETOOTH)+= dev-bluetooth.o ifeq ($(CONFIG_USB_SMARTCARD),y) diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c index f2fc2a8..7f292b1 100644 --- a/hw/usb/dev-bluetooth.c +++ b/hw/usb/dev-bluetooth.c @@ -511,10 +511,17 @@ static int usb_bt_initfn(USBDevice *dev) return 0; } -USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci) +static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline) { USBDevice *dev; struct USBBtState *s; +HCIInfo *hci; + +if (*cmdline) { +hci = hci_init(cmdline); +} else { +hci = bt_new_hci(qemu_find_bt_vlan(0)); +} if (!hci) return NULL; @@ -566,6 +573,7 @@ static const TypeInfo bt_info = { static void usb_bt_register_types(void) { type_register_static(bt_info); +usb_legacy_register(usb-bt-dongle, bt, usb_bt_init); } type_init(usb_bt_register_types) diff --git a/include/hw/bt.h b/include/hw/bt.h index 830af94..49a9d03 100644 --- a/include/hw/bt.h +++ b/include/hw/bt.h @@ -108,12 +108,15 @@ struct bt_device_s { uint16_t clkoff; /* Note: Always little-endian */ }; +extern struct HCIInfo null_hci; /* bt.c */ void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net); void bt_device_done(struct bt_device_s *dev); +struct bt_scatternet_s *qemu_find_bt_vlan(int
[Qemu-devel] [PATCHv3 0/2] Make usb-bt-dongle configurable
From: Miroslav Rezanina mreza...@redhat.com There's group of options allowing enable/disable usb devices. However, CONFIG_USB_BLUETOOTH can't be removed as there's dependency in vl.c file. This serie allow CONFIG_USB_BLUETOOTH to be disabled. v3: - split patch to two parts v2: - patch rewritten to use usb_legacy_register Miroslav Rezanina (2): Preparation for usb-bt-dongle conditional build Make usb-bt-dongle configurable hw/bt/core.c | 23 ++ hw/bt/hci.c| 48 + hw/usb/Makefile.objs | 3 -- hw/usb/dev-bluetooth.c | 10 +- include/hw/bt.h| 3 ++ include/hw/usb.h | 3 -- vl.c | 82 +++--- 7 files changed, 87 insertions(+), 85 deletions(-) -- 1.8.3.1
[Qemu-devel] [PATCHv3 1/2] Preparation for usb-bt-dongle conditional build
From: Miroslav Rezanina mreza...@redhat.com To allow disable usb-bt-dongle device using CONFIG_BLUETOOTH option, some of functions in vl.c file has to be made accessible in dev-bluetooth.c. This is pure code moving. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/bt/core.c| 23 +++ hw/bt/hci.c | 48 +++ include/hw/bt.h | 3 +++ vl.c| 69 - 4 files changed, 74 insertions(+), 69 deletions(-) diff --git a/hw/bt/core.c b/hw/bt/core.c index 49012e0..0ffc948 100644 --- a/hw/bt/core.c +++ b/hw/bt/core.c @@ -119,3 +119,26 @@ void bt_device_done(struct bt_device_s *dev) *p = dev-next; } + +static struct bt_vlan_s { +struct bt_scatternet_s net; +int id; +struct bt_vlan_s *next; +} *first_bt_vlan; + +/* find or alloc a new bluetooth VLAN */ +struct bt_scatternet_s *qemu_find_bt_vlan(int id) +{ +struct bt_vlan_s **pvlan, *vlan; +for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) { +if (vlan-id == id) +return vlan-net; +} +vlan = g_malloc0(sizeof(struct bt_vlan_s)); +vlan-id = id; +pvlan = first_bt_vlan; +while (*pvlan != NULL) +pvlan = (*pvlan)-next; +*pvlan = vlan; +return vlan-net; +} diff --git a/hw/bt/hci.c b/hw/bt/hci.c index d1c0604..7ea3dc6 100644 --- a/hw/bt/hci.c +++ b/hw/bt/hci.c @@ -429,6 +429,24 @@ static const uint8_t bt_event_reserved_mask[8] = { 0xff, 0x9f, 0xfb, 0xff, 0x07, 0x18, 0x00, 0x00, }; + +static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) +{ +} + +static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) +{ +return -ENOTSUP; +} + +struct HCIInfo null_hci = { +.cmd_send = null_hci_send, +.sco_send = null_hci_send, +.acl_send = null_hci_send, +.bdaddr_set = null_hci_addr_set, +}; + + static inline uint8_t *bt_hci_event_start(struct bt_hci_s *hci, int evt, int len) { @@ -2176,6 +2194,36 @@ struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net) return s-info; } +struct HCIInfo *hci_init(const char *str) +{ +char *endp; +struct bt_scatternet_s *vlan = 0; + +if (!strcmp(str, null)) +/* null */ +return null_hci; +else if (!strncmp(str, host, 4) (str[4] == '\0' || str[4] == ':')) +/* host[:hciN] */ +return bt_host_hci(str[4] ? str + 5 : hci0); +else if (!strncmp(str, hci, 3)) { +/* hci[,vlan=n] */ +if (str[3]) { +if (!strncmp(str + 3, ,vlan=, 6)) { +vlan = qemu_find_bt_vlan(strtol(str + 9, endp, 0)); +if (*endp) +vlan = 0; +} +} else +vlan = qemu_find_bt_vlan(0); +if (vlan) + return bt_new_hci(vlan); +} + +fprintf(stderr, qemu: Unknown bluetooth HCI `%s'.\n, str); + +return 0; +} + static void bt_hci_done(struct HCIInfo *info) { struct bt_hci_s *hci = hci_from_info(info); diff --git a/include/hw/bt.h b/include/hw/bt.h index 830af94..49a9d03 100644 --- a/include/hw/bt.h +++ b/include/hw/bt.h @@ -108,12 +108,15 @@ struct bt_device_s { uint16_t clkoff; /* Note: Always little-endian */ }; +extern struct HCIInfo null_hci; /* bt.c */ void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net); void bt_device_done(struct bt_device_s *dev); +struct bt_scatternet_s *qemu_find_bt_vlan(int id); /* bt-hci.c */ struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net); +struct HCIInfo *hci_init(const char *str); /* bt-vhci.c */ void bt_vhci_init(struct HCIInfo *info); diff --git a/vl.c b/vl.c index dfbc071..2721a62 100644 --- a/vl.c +++ b/vl.c @@ -843,45 +843,6 @@ static int nb_hcis; static int cur_hci; static struct HCIInfo *hci_table[MAX_NICS]; -static struct bt_vlan_s { -struct bt_scatternet_s net; -int id; -struct bt_vlan_s *next; -} *first_bt_vlan; - -/* find or alloc a new bluetooth VLAN */ -static struct bt_scatternet_s *qemu_find_bt_vlan(int id) -{ -struct bt_vlan_s **pvlan, *vlan; -for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan-next) { -if (vlan-id == id) -return vlan-net; -} -vlan = g_malloc0(sizeof(struct bt_vlan_s)); -vlan-id = id; -pvlan = first_bt_vlan; -while (*pvlan != NULL) -pvlan = (*pvlan)-next; -*pvlan = vlan; -return vlan-net; -} - -static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) -{ -} - -static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) -{ -return -ENOTSUP; -} - -static struct HCIInfo null_hci = { -.cmd_send = null_hci_send, -.sco_send = null_hci_send, -.acl_send = null_hci_send, -.bdaddr_set = null_hci_addr_set, -}; - struct HCIInfo *qemu_next_hci(void) { if (cur_hci == nb_hcis) @@ -890,36 +851,6 @@ struct HCIInfo *qemu_next_hci(void) return hci_table[cur_hci++];
[Qemu-devel] [PATCHv3 2/2] Remove dev-bluetooth.c dependency from vl.c
From: Miroslav Rezanina mreza...@redhat.com Use usb_legacy_register handling to create bt-dongle device and remove code dependency from vl.c so CONFIG_USB_BLUETOOTH can be disabled. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- hw/usb/Makefile.objs | 3 --- hw/usb/dev-bluetooth.c | 10 +- include/hw/usb.h | 3 --- vl.c | 13 - 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs index f9695e7..a3eac3e 100644 --- a/hw/usb/Makefile.objs +++ b/hw/usb/Makefile.objs @@ -18,9 +18,6 @@ common-obj-$(CONFIG_USB_STORAGE_UAS) += dev-uas.o common-obj-$(CONFIG_USB_AUDIO)+= dev-audio.o common-obj-$(CONFIG_USB_SERIAL) += dev-serial.o common-obj-$(CONFIG_USB_NETWORK) += dev-network.o - -# FIXME: make configurable too -CONFIG_USB_BLUETOOTH := y common-obj-$(CONFIG_USB_BLUETOOTH)+= dev-bluetooth.o ifeq ($(CONFIG_USB_SMARTCARD),y) diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c index f2fc2a8..7f292b1 100644 --- a/hw/usb/dev-bluetooth.c +++ b/hw/usb/dev-bluetooth.c @@ -511,10 +511,17 @@ static int usb_bt_initfn(USBDevice *dev) return 0; } -USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci) +static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline) { USBDevice *dev; struct USBBtState *s; +HCIInfo *hci; + +if (*cmdline) { +hci = hci_init(cmdline); +} else { +hci = bt_new_hci(qemu_find_bt_vlan(0)); +} if (!hci) return NULL; @@ -566,6 +573,7 @@ static const TypeInfo bt_info = { static void usb_bt_register_types(void) { type_register_static(bt_info); +usb_legacy_register(usb-bt-dongle, bt, usb_bt_init); } type_init(usb_bt_register_types) diff --git a/include/hw/usb.h b/include/hw/usb.h index 901b0da..695d853 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -442,9 +442,6 @@ int set_usb_string(uint8_t *buf, const char *str); USBDevice *usb_host_device_open(USBBus *bus, const char *devname); void usb_host_info(Monitor *mon, const QDict *qdict); -/* usb-bt.c */ -USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci); - /* usb ports of the VM */ #define VM_USB_HUB_SIZE 8 diff --git a/vl.c b/vl.c index 2721a62..794e6b3 100644 --- a/vl.c +++ b/vl.c @@ -1457,8 +1457,10 @@ static void configure_msg(QemuOpts *opts) static int usb_device_add(const char *devname) { -const char *p; USBDevice *dev = NULL; +#ifndef CONFIG_LINUX +const char *p; +#endif if (!usb_enabled(false)) { return -1; @@ -1474,15 +1476,8 @@ static int usb_device_add(const char *devname) /* only the linux version is qdev-ified, usb-bsd still needs this */ if (strstart(devname, host:, p)) { dev = usb_host_device_open(usb_bus_find(-1), p); -} else -#endif -if (!strcmp(devname, bt) || strstart(devname, bt:, p)) { -dev = usb_bt_init(usb_bus_find(-1), - devname[2] ? hci_init(p) - : bt_new_hci(qemu_find_bt_vlan(0))); -} else { -return -1; } +#endif if (!dev) return -1; -- 1.8.3.1
[Qemu-devel] [PATCH v7 0/4] Add subcommand compare for qemu-img
From: Miroslav Rezanina mreza...@redhat.com This is seventh version of patch adding compare subcommand that compares two images. Compare has following criteria: - only data part is compared - unallocated sectors are not read - in case of different image size, exceeding part of bigger disk has to be zeroed/unallocated to compare rest - qemu-img returns: - 0 if images are identical - 1 if images differ - 2 on error v7: - split patch into pieces - Quiet mode added for all relevant subcommands - check non-shared part of disk after shared one - minor docummentation and naming fixes v6: - added handling -?, -h options for compare subcommand v5 (only minor changes): - removed redundant comment - removed dead code (goto after help()) - set final total_sectors on first assignment v4: - Fixed various typos - Added functions for empty sector check and sector-to-bytes offset conversion - Fixed command-line parameters processing v3: - options -f/-F are orthogonal - documentation updated to new syntax and behavior - used byte offset instead of sector number for output v2: - changed option for second image format to -F - changed handling of -f and -F [1] - added strict mode (-s) - added quiet mode (-q) - improved output messages [2] - rename variables for larger image handling - added man page content Signed-off-by: Miroslav Rezanina mreza...@redhat.com Miroslav Rezanina (4): block: Add synchronous wrapper for bdrv_co_is_allocated_above qemu-img: Add Quiet mode option qemu-img: Add compare subcommand Add qemu-img compare documentation block.c | 50 +++- block.h | 4 +- blockdev.c | 6 +- qemu-img-cmds.hx | 34 +++-- qemu-img.c | 383 ++- qemu-img.texi| 35 + 6 files changed, 460 insertions(+), 52 deletions(-) -- 1.7.11.7
[Qemu-devel] [PATCH v7 4/4] Add qemu-img compare documentation
From: Miroslav Rezanina mreza...@redhat.com Adding documentation for new qemu-img subcommand compare. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- qemu-img.c| 7 ++- qemu-img.texi | 32 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 8b4f01f..a185e9e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -103,7 +103,12 @@ static void help(void) '-a' applies a snapshot (revert disk to saved state)\n '-c' creates a snapshot\n '-d' deletes a snapshot\n - '-l' lists all snapshots in the given image\n; + '-l' lists all snapshots in the given image\n + \n + Parameters to compare subcommand:\n + '-f' First image format\n + '-F' Second image format\n + '-s' Strict mode - fail on different image size or sector allocation\n; printf(%s\nSupported formats:, help_msg); bdrv_iterate_format(format_print, NULL); diff --git a/qemu-img.texi b/qemu-img.texi index bb82a3d..7eb1934 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -84,6 +84,18 @@ deletes a snapshot lists all snapshots in the given image @end table +Parameters to compare subcommand: + +@table @option + +@item -f +First image format +@item -F +Second image format +@item -s +Strict mode - fail on on different image size or sector allocation +@end table + Command description: @table @option @@ -117,6 +129,26 @@ it doesn't need to be specified separately in this case. Commit the changes recorded in @var{filename} in its base image. +@item compare [-f @var{fmt}] [-F @var{fmt}] [-p] [-s] [-q] @var{filename1} @var{filename2} + +Check if two images have the same content. You can compare images with +different format or settings. + +The format is probed unless you specify it by @var{-f} (used for @var{filename1}) and/or @var{-F} (used for @var{filename2}) option. + +By default, images with different size are considered identical if the larger +image contains only unallocated and/or zeroed sectors in the area after the end +of the other image. In addition, if any sector is not allocated in one image +and contains only zero bytes in the second one, it is evaluated as equal. You +can use Strict mode by specifying the @var{-s} option. When compare runs in +Strict mode, it fails in case image size differs or a sector is allocated in +one image and is not allocated in the second one. + +By default, compare prints out a result message. This message displays +information that both images are same or the position of the first different +byte. In addition, result message can report different image size in case +Strict mode is used. + @item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename} -- 1.7.11.7
[Qemu-devel] [PATCH v7 2/4] qemu-img: Add Quiet mode option
From: Miroslav Rezanina mreza...@redhat.com There can be need to turn output to stdout off. This patch adds a -q option that enable Quiet mode. In Quiet mode, only errors are printed out. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- block.c | 11 +++--- block.h | 2 +- blockdev.c | 6 ++-- qemu-img-cmds.hx | 28 +++ qemu-img.c | 108 +-- qemu-img.texi| 3 ++ 6 files changed, 108 insertions(+), 50 deletions(-) diff --git a/block.c b/block.c index 24c06ab..5450ff9 100644 --- a/block.c +++ b/block.c @@ -4449,7 +4449,7 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie) int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, -char *options, uint64_t img_size, int flags) +char *options, uint64_t img_size, int flags, bool quiet) { QEMUOptionParameter *param = NULL, *create_options = NULL; QEMUOptionParameter *backing_fmt, *backing_file, *size; @@ -4565,10 +4565,11 @@ int bdrv_img_create(const char *filename, const char *fmt, } } -printf(Formatting '%s', fmt=%s , filename, fmt); -print_option_parameters(param); -puts(); - +if (!quiet) { +printf(Formatting '%s', fmt=%s , filename, fmt); +print_option_parameters(param); +puts(); +} ret = bdrv_create(drv, filename, param); if (ret 0) { diff --git a/block.h b/block.h index 2cb8d71..a7e7220 100644 --- a/block.h +++ b/block.h @@ -347,7 +347,7 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, -char *options, uint64_t img_size, int flags); +char *options, uint64_t img_size, int flags, bool quiet); void bdrv_set_buffer_alignment(BlockDriverState *bs, int align); void *qemu_blockalign(BlockDriverState *bs, size_t size); diff --git a/blockdev.c b/blockdev.c index e73fd6e..b2fb7f7 100644 --- a/blockdev.c +++ b/blockdev.c @@ -789,7 +789,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) ret = bdrv_img_create(new_image_file, format, states-old_bs-filename, states-old_bs-drv-format_name, - NULL, -1, flags); + NULL, -1, flags, false); if (ret) { error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file); goto delete_and_fail; @@ -1264,7 +1264,7 @@ void qmp_drive_mirror(const char *device, const char *target, bdrv_get_geometry(bs, size); size *= 512; ret = bdrv_img_create(target, format, - NULL, NULL, NULL, size, flags); + NULL, NULL, NULL, size, flags, false); } else { switch (mode) { case NEW_IMAGE_MODE_EXISTING: @@ -1275,7 +1275,7 @@ void qmp_drive_mirror(const char *device, const char *target, ret = bdrv_img_create(target, format, source-filename, source-drv-format_name, - NULL, -1, flags); + NULL, -1, flags,false); break; default: abort(); diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index a181363..90b93e0 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -10,27 +10,27 @@ STEXI ETEXI DEF(check, img_check, -check [-f fmt] [-r [leaks | all]] filename) +check [-q] [-f fmt] [-r [leaks | all]] filename) STEXI -@item check [-f @var{fmt}] [-r [leaks | all]] @var{filename} +@item check [-q] [-f @var{fmt}] [-r [leaks | all]] @var{filename} ETEXI DEF(create, img_create, -create [-f fmt] [-o options] filename [size]) +create [-q] [-f fmt] [-o options] filename [size]) STEXI -@item create [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}] +@item create [-q] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}] ETEXI DEF(commit, img_commit, -commit [-f fmt] [-t cache] filename) +commit [-q] [-f fmt] [-t cache] filename) STEXI -@item commit [-f @var{fmt}] [-t @var{cache}] @var{filename} +@item commit [-q] [-f @var{fmt}] [-t @var{cache}] @var{filename} ETEXI DEF(convert, img_convert, -convert [-c] [-p] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename) +convert [-c] [-p] [-q] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename) STEXI -@item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s
[Qemu-devel] [PATCH v7 1/4] block: Add synchronous wrapper for bdrv_co_is_allocated_above
From: Miroslav Rezanina mreza...@redhat.com There's no synchronous wrapper for bdrv_co_is_allocated_above function so it's not possible to check for sector allocation in image with backing file. This patch add missing synchronous wrapper. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- block.c | 39 +++ block.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/block.c b/block.c index c05875f..24c06ab 100644 --- a/block.c +++ b/block.c @@ -2699,6 +2699,7 @@ int bdrv_has_zero_init(BlockDriverState *bs) typedef struct BdrvCoIsAllocatedData { BlockDriverState *bs; +BlockDriverState *base; int64_t sector_num; int nb_sectors; int *pnum; @@ -2829,6 +2830,44 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, return 0; } +/* Coroutine wrapper for bdrv_is_allocated_above() */ +static void coroutine_fn bdrv_is_allocated_above_co_entry(void *opaque) +{ +BdrvCoIsAllocatedData *data = opaque; +BlockDriverState *top = data-bs; +BlockDriverState *base = data-base; + +data-ret = bdrv_co_is_allocated_above(top, base, data-sector_num, + data-nb_sectors, data-pnum); +data-done = true; +} + +/* + * Synchronous wrapper around bdrv_co_is_allocated_above(). + * + * See bdrv_co_is_allocated_above() for details. + */ +int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + int64_t sector_num, int nb_sectors, int *pnum) +{ +Coroutine *co; +BdrvCoIsAllocatedData data = { +.bs = top, +.base = base, +.sector_num = sector_num, +.nb_sectors = nb_sectors, +.pnum = pnum, +.done = false, +}; + +co = qemu_coroutine_create(bdrv_is_allocated_above_co_entry); +qemu_coroutine_enter(co, data); +while (!data.done) { +qemu_aio_wait(); +} +return data.ret; +} + BlockInfo *bdrv_query_info(BlockDriverState *bs) { BlockInfo *info = g_malloc0(sizeof(*info)); diff --git a/block.h b/block.h index 722c620..2cb8d71 100644 --- a/block.h +++ b/block.h @@ -278,6 +278,8 @@ int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_has_zero_init(BlockDriverState *bs); int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); +int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, +int64_t sector_num, int nb_sectors, int *pnum); void bdrv_set_on_error(BlockDriverState *bs, BlockdevOnError on_read_error, BlockdevOnError on_write_error); -- 1.7.11.7
[Qemu-devel] [PATCH v7 3/4] qemu-img: Add compare subcommand
From: Miroslav Rezanina mreza...@redhat.com This patch adds new qemu-img subcommand that compare content of two disk images. Signed-off-by: Miroslav Rezanina mreza...@redhat.com --- qemu-img-cmds.hx | 6 ++ qemu-img.c | 268 ++- 2 files changed, 273 insertions(+), 1 deletion(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 90b93e0..bc1ccfa 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -27,6 +27,12 @@ STEXI @item commit [-q] [-f @var{fmt}] [-t @var{cache}] @var{filename} ETEXI +DEF(compare, img_compare, +compare [-f fmt] [-F fmt] [-p] [-q] [-s] filename1 filename2) +STEXI +@item compare [-f @var{fmt}] [-F @var{fmt}] [-p] [-q] [-s] @var{filename1} @var{filename2} +ETEXI + DEF(convert, img_convert, convert [-c] [-p] [-q] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename) STEXI diff --git a/qemu-img.c b/qemu-img.c index b9a45f1..8b4f01f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -587,7 +587,7 @@ static int img_commit(int argc, char **argv) } /* - * Returns true iff the first sector pointed to by 'buf' contains at least + * Returns true if the first sector pointed to by 'buf' contains at least * a non-NUL byte. * * 'pnum' is set to the number of sectors (including and immediately following @@ -688,6 +688,272 @@ static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n, #define IO_BUF_SIZE (2 * 1024 * 1024) +static int64_t sectors_to_bytes(int64_t sectors) +{ +return sectors BDRV_SECTOR_BITS; +} + +static int64_t sectors_to_process(int64_t total, int64_t from) +{ +int64_t ret = total - from; + +if (ret (IO_BUF_SIZE BDRV_SECTOR_BITS)) { +return IO_BUF_SIZE BDRV_SECTOR_BITS; +} + +return ret; +} + +/* + * Check if passed sectors are empty (not allocated or contain only 0 bytes) + * + * Returns 0 in case sectors are filled with 0, 1 if sectors contain non-zero + * data and negative value on error. + * + * @param bs: Driver used for accessing file + * @param sect_num: Number of first sector to check + * @param sect_count: Number of sectors to check + * @param filename: Name of disk file we are checking (logging purpose) + * @param buffer: Allocated buffer for storing read data + * @param quiet: Flag for quiet mode + */ +static int check_empty_sectors(BlockDriverState *bs, int64_t sect_num, + int sect_count, const char *filename, + uint8_t *buffer, bool quiet) +{ +int pnum, ret = 0; +ret = bdrv_read(bs, sect_num, buffer, sect_count); +if (ret 0) { +error_report(Error while reading offset % PRId64 of %s: %s, + sectors_to_bytes(sect_num), filename, strerror(-ret)); +return ret; +} +ret = is_allocated_sectors(buffer, sect_count, pnum); +if (ret || pnum != sect_count) { +qprintf(quiet, Content mismatch at offset % PRId64 !\n, +sectors_to_bytes(ret ? sect_num : sect_num + pnum)); +return 1; +} + +return 0; +} + +/* + * Compares two images. Exit codes: + * + * 0 - Images are identical + * 1 - Images differ + * 2 - Error occurred + */ +static int img_compare(int argc, char **argv) +{ +const char *fmt1 = NULL, *fmt2 = NULL, *filename1, *filename2; +BlockDriverState *bs1, *bs2; +int64_t total_sectors1, total_sectors2; +uint8_t *buf1 = NULL, *buf2 = NULL; +int pnum1, pnum2; +int allocated1, allocated2; +int ret = 0; /* return value - 0 Ident, 1 Different, 2 Error */ +int progress = 0, quiet = 0, strict = 0; +int64_t total_sectors; +int64_t sector_num = 0; +int64_t nb_sectors; +int c, pnum; +uint64_t bs_sectors; +uint64_t progress_base; + +for (;;) { +c = getopt(argc, argv, hpf:F:sq); +if (c == -1) { +break; +} +switch (c) { +case '?': +case 'h': +help(); +break; +case 'f': +fmt1 = optarg; +break; +case 'F': +fmt2 = optarg; +break; +case 'p': +progress = 1; +break; +case 'q': +quiet = 1; +break; +case 's': +strict = 1; +break; +} +} + +/* Progress is not shown in Quiet mode */ +if (quiet) { +progress = 0; +} + + +if (optind argc - 2) { +help(); +} +filename1 = argv[optind++]; +filename2 = argv[optind++]; + +/* Initialize before goto out */ +qemu_progress_init(progress, 2.0); + +bs1 = bdrv_new_open(filename1, fmt1, BDRV_O_FLAGS, true, quiet); +if (!bs1) { +error_report(Can't open file %s, filename1); +ret = 2; +goto out3; +} + +bs2 = bdrv_new_open(filename2, fmt2, BDRV_O_FLAGS, true, quiet); +if (!bs2) { +