[Qemu-devel] a probem about qemu doesn't support for setting master volume/mute when guest is winxp

2013-01-28 Thread liequan . che
 Hi all:
 I found a bug that qemu doesn't support for setting master volume/mute 
when guest is winxp. but the wave volume in the volume control works fine.I 
don't know why it does. 
  Any help is welcome.
  Best Regards!

 


[Qemu-devel] the patch about win7 guest unable to disable the sound completely

2013-01-28 Thread liequan . che
Hi all:
I slove the problem that qemu doesn't support to disable the sound completely 
when someone choose ich6 sound card.
I test it in centos 6.3,guest win7,ich6 sound card.it works fine. 

my patch:
--- qemu-kvm-0.12.1.2/hw/hda-audio.c    2013-01-29 
10:07:34.750968170 +0800
+++ qemu-kvm-0.12.1.2.new/hw/hda-audio.c    2013-01-29 
10:07:05.696283899 +0800
@@ -647,10 +647,59 @@
 hda_codec_response(hda, true, 
node->pinctl);
 break;
 case AC_VERB_SET_PIN_WIDGET_CONTROL:
-    if (node->pinctl != payload) {
+    if (node->pinctl != payload)
+    {
+    if 
(node->pinctl == 0x40 && payload == 0)
+    {
+   
 st = a->st + node->stindex;
+   
 if (st->node == NULL)
+   
 {
+   
 goto fail;
+   
 }
+   
 dprint(a, 1, "amp (%s): %s%s%s%s index %d  gain %3d %s\n",
+  
 st->node->name,
+  
 (payload & AC_AMP_SET_OUTPUT) ? "o" : "-",
+  
 (payload & AC_AMP_SET_INPUT)  ? "i" : "-",
+  
 (payload & AC_AMP_SET_LEFT)   ? "l" : "-",
+  
 (payload & AC_AMP_SET_RIGHT)  ? "r" : "-",
+  
 (payload & AC_AMP_SET_INDEX) >> AC_AMP_SET_INDEX_SHIFT,
+  
 (payload & AC_AMP_GAIN),
+  
 (payload & AC_AMP_MUTE) ? "muted" : "");
+   
 st->gain_left = payload & AC_AMP_GAIN;
+   
 st->mute_left = payload & AC_AMP_MUTE;
+   
 st->gain_right = payload & AC_AMP_GAIN;
+   
 st->mute_right = payload & AC_AMP_MUTE;
+   
 
hda_audio_setup(st);   
 
+   
 hda_audio_set_amp(st);
+   
 hda_audio_set_running(st, false);
+    }  
 
dprint(a, 1, "unhandled pin control bit\n");
 }
-    hda_codec_response(hda, true, 0);
+    else
+    {
+    st = a->st 
+ node->stindex;
+    if 
(st->node == NULL)
+    {
+   
 goto fail;
+    }
+    dprint(a, 
1, "amp (%s): %s%s%s%s index %d  gain %3d %s\n",
+  
 st->node->name,
+  
 (payload & AC_AMP_SET_OUTPUT) ? "o" : "-",
+  
 (payload & AC_AMP_SET_INPUT)  ? "i" : "-",
+  
 (payload & AC_AMP_SET_LEFT)   ? "l" : "-",
+  
 (payload & AC_AMP_SET_RIGHT)  ? "r" : "-",
+  
 (payload & AC_AMP_SET_INDEX) >> AC_AMP_SET_INDEX_SHIFT,
+  
 (payload & AC_AMP_GAIN),
+  
 (payload & AC_AMP_MUTE) ? "muted" : "");
+    
st->gain_left = payload & AC_AMP_GAIN;
+    
st->mute_left = payload & AC_AMP_MUTE;
+    
st->gain_right = payload & AC_AMP_GAIN;
+    
st->mute_right = payload & AC_AMP_MUTE;
+    
hda_audio_setup(st);   
 
+    
hda_audio_set_amp(st);
+    
hda_audio_set_running(st, true);
+    }
+    hda_codec_response(hda, true, 0);
 break;
 
 /* audio in/out widget */ 
 


Re: [Qemu-devel] [PATCH 1/2] usb-ehci: replace PORTSC macros with variables

2013-01-28 Thread Gerd Hoffmann
  Hi,

>  hw/usb/hcd-ehci-sysbus.c |6 ++
>  hw/usb/hcd-ehci.c|   21 +
>  hw/usb/hcd-ehci.h|   12 ++--

> +s->portscbase = sec->portscbase;
> +s->portnr = sec->portnr;

These two must be initialized in usb_ehci_pci_initfn too.

Otherwise the patch looks fine.

cheers,
  Gerd




Re: [Qemu-devel] [PATCH 1/2] usb-ehci: replace PORTSC macros with variables

2013-01-28 Thread Kuo-Jung Su
Hi Gerd:

Thanks for reminding me of the usb_ehci_pci_initfn.

But I have a stupid question...

Which one do the upcoming path v2 looks like ?

1. It contains only the diff to usb_ehci_pci_initfn, for example:

[Qemu-devel][PATCH v2 0/1] usb-ehci: add Faraday FUSBH200 support
[Qemu-devel][PATCH v2 1/1] usb-ehci: update usb_ehci_pci_initfn to use
variable version of portsc

2. It contains the entired change logs, for example:

[Qemu-devel][PATCH v2 0/3] usb-ehci: add Faraday FUSBH200 support
[Qemu-devel][PATCH v2 1/3] usb-ehci: replace PORTSC macros with
variables ..
[Qemu-devel][PATCH v2 2/3] usb-ehci: add Faraday FUSBH200 support
[Qemu-devel][PATCH v2 3/3] usb-ehci: update usb_ehci_pci_initfn ...

I know this is stupid, but I really need the answer.
Thanks you!

Best Wishes
Dante Su



2013/1/29 Gerd Hoffmann 

>   Hi,
>
> >  hw/usb/hcd-ehci-sysbus.c |6 ++
> >  hw/usb/hcd-ehci.c|   21 +
> >  hw/usb/hcd-ehci.h|   12 ++--
>
> > +s->portscbase = sec->portscbase;
> > +s->portnr = sec->portnr;
>
> These two must be initialized in usb_ehci_pci_initfn too.
>
> Otherwise the patch looks fine.
>
> cheers,
>   Gerd
>
>


-- 
Best wishes,
Kuo-Jung Su


Re: [Qemu-devel] [RFC] qemu snapshot enchancement

2013-01-28 Thread Dietmar Maurer
>The solution seems OK in improving the performance, I just wondering if it
> is possible to put it in lower level component, not qemu? It will make qemu
> block layer more complicate, 

Not that I am aware off - it just add a few lines to block.c, and only uses 
existing
functionality already used inside qemu.

> and since it can ignore the format so it is more
> likely a storage dedicated function, so could u check if it can be offloaded
> from qemu?

The whole trick is to do it inside qemu, to be independent of storage type.




[Qemu-devel] [PATCH V16 1/9] build: add command check-clean

2013-01-28 Thread Wenchao Xia
  This command will package the clean operations in tests,
to make it easy to be extended. Now root Makefile simply calls
the command and do not care the details of it any more.

Signed-off-by: Wenchao Xia 
---
 Makefile   |1 -
 tests/Makefile |   12 +++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 0d9099a..b2d7798 100644
--- a/Makefile
+++ b/Makefile
@@ -225,7 +225,6 @@ clean:
rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
rm -rf qapi-generated
rm -rf qga/qapi-generated
-   $(MAKE) -C tests/tcg clean
for d in $(ALL_SUBDIRS); do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
rm -f $$d/qemu-options.def; \
diff --git a/tests/Makefile b/tests/Makefile
index c681ceb..a653532 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -134,6 +134,10 @@ qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a
 qtest-obj-y += tests/libi2c.o tests/libi2c-omap.o
 $(check-qtest-y): $(qtest-obj-y)
 
+#clean rules
+
+CHECK_CLEAN_TARGETS = $(check-unit-y) $(check-qtest-i386-y) 
$(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y) 
tests/*.o
+
 .PHONY: check-help
 check-help:
@echo "Regression testing targets:"
@@ -144,6 +148,7 @@ check-help:
@echo " make check-unit   Run qobject tests"
@echo " make check-block  Run block tests"
@echo " make check-report.htmlGenerates an HTML test report"
+   @echo " make check-clean  Clean the tests"
@echo
@echo "Please note that HTML reports do not regenerate if the unit 
tests"
@echo "has not changed."
@@ -203,10 +208,15 @@ check-tests/qemu-iotests-quick.sh: 
tests/qemu-iotests-quick.sh qemu-img$(EXESUF)
 
 # Consolidated targets
 
-.PHONY: check-qtest check-unit check
+.PHONY: check-qtest check-unit check check-clean
 check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS))
 check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-unit check-qtest
 
+check-clean:
+   $(MAKE) -C tests/tcg clean
+   rm -rf $(CHECK_CLEAN_TARGETS)
+
+clean: check-clean
 -include $(wildcard tests/*.d)
-- 
1.7.1





[Qemu-devel] [PATCH V16 2/9] libqblock: build: add configure support

2013-01-28 Thread Wenchao Xia
  Rule for libqblock.la will be included if it is enabled, and
will be added to 'all' to be automatically built.

Signed-off-by: Wenchao Xia 
---
 Makefile   |3 +++
 configure  |   26 ++
 libqblock/Makefile |4 
 3 files changed, 33 insertions(+), 0 deletions(-)
 create mode 100644 libqblock/Makefile

diff --git a/Makefile b/Makefile
index b2d7798..a472fd3 100644
--- a/Makefile
+++ b/Makefile
@@ -114,6 +114,9 @@ endif
 ifeq ($(CONFIG_SMARTCARD_NSS),y)
 include $(SRC_PATH)/libcacard/Makefile
 endif
+ifeq ($(CONFIG_LIBQBLOCK),y)
+include $(SRC_PATH)/libqblock/Makefile
+endif
 
 all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all
 
diff --git a/configure b/configure
index b7635e4..df61c0e 100755
--- a/configure
+++ b/configure
@@ -226,6 +226,7 @@ coroutine=""
 seccomp=""
 glusterfs=""
 virtio_blk_data_plane=""
+libqblock=""
 
 # parse CC options first
 for opt do
@@ -897,6 +898,10 @@ for opt do
   ;;
   --enable-virtio-blk-data-plane) virtio_blk_data_plane="yes"
   ;;
+  --disable-libqblock) libqblock="no"
+  ;;
+  --enable-libqblock) libqblock="yes"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -1146,6 +1151,8 @@ echo "  --enable-glusterfs   enable GlusterFS backend"
 echo "  --disable-glusterfs  disable GlusterFS backend"
 echo "  --enable-gcovenable test coverage analysis with gcov"
 echo "  --gcov=GCOV  use specified gcov [$gcov_tool]"
+echo "  --enable-libqblock   enable shared library libqblock"
+echo "  --disable-libqblock  disable shared library libqblock"
 echo ""
 echo "NOTE: The object files are built at the place where configure is 
launched"
 exit 1
@@ -2429,6 +2436,19 @@ EOF
   fi
 fi
 
+##
+# libqblock probe
+if test "$libqblock" != "no"; then
+if test -n "$libtool"; then
+libqblock="yes"
+else
+if test "$libqblock" = "yes"; then
+feature_not_found "libqblock"
+fi
+libqblock="no"
+fi
+fi
+
 #
 # Check for xxxat() functions when we are building linux-user
 # emulator.  This is done because older glibc versions don't
@@ -3344,6 +3364,7 @@ echo "GlusterFS support $glusterfs"
 echo "virtio-blk-data-plane $virtio_blk_data_plane"
 echo "gcov  $gcov_tool"
 echo "gcov enabled  $gcov"
+echo "libqblock support $libqblock"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3700,6 +3721,10 @@ if test "$virtio_blk_data_plane" = "yes" ; then
   echo "CONFIG_VIRTIO_BLK_DATA_PLANE=y" >> $config_host_mak
 fi
 
+if test "$libqblock" = "yes" ; then
+  echo "CONFIG_LIBQBLOCK=y" >> $config_host_mak
+fi
+
 # USB host support
 case "$usb" in
 linux)
@@ -4283,6 +4308,7 @@ DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32"
 DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas"
 DIRS="$DIRS roms/seabios roms/vgabios"
 DIRS="$DIRS qapi-generated"
+DIRS="$DIRS libqblock"
 FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
 FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
 FILES="$FILES tests/tcg/lm32/Makefile"
diff --git a/libqblock/Makefile b/libqblock/Makefile
new file mode 100644
index 000..8173da7
--- /dev/null
+++ b/libqblock/Makefile
@@ -0,0 +1,4 @@
+all: libqblock.la
+
+libqblock.la:
+   @true
-- 
1.7.1





[Qemu-devel] [PATCH V16 5/9] block: export function path_has_protocol()

2013-01-28 Thread Wenchao Xia
  libqblock need to use it.

Signed-off-by: Wenchao Xia 
---
 block.c   |2 +-
 include/block/block.h |2 ++
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index ba67c0d..44db62f 100644
--- a/block.c
+++ b/block.c
@@ -195,7 +195,7 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,
 }
 
 /* check if the path starts with ":" */
-static int path_has_protocol(const char *path)
+int path_has_protocol(const char *path)
 {
 const char *p;
 
diff --git a/include/block/block.h b/include/block/block.h
index 5c3b911..40b63b1 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -395,6 +395,8 @@ void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie 
*cookie,
 int64_t bytes, enum BlockAcctType type);
 void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
 
+int path_has_protocol(const char *path);
+
 typedef enum {
 BLKDBG_L1_UPDATE,
 
-- 
1.7.1





[Qemu-devel] [PATCH V16 4/9] libqblock: build: add packaging support

2013-01-28 Thread Wenchao Xia
  Now libqblock can be packaged and installed by
"sudo make install-libqblock'.

Signed-off-by: Wenchao Xia 
---
 libqblock/Makefile  |   35 ++-
 libqblock/libqblock.pc.in   |   13 +
 2 files changed, 43 insertions(+), 5 deletions(-)
 create mode 100644 libqblock/libqblock-error.h
 create mode 100644 libqblock/libqblock-types.h
 create mode 100644 libqblock/libqblock.h
 create mode 100644 libqblock/libqblock.pc.in

diff --git a/libqblock/Makefile b/libqblock/Makefile
index 73974e9..d3f11b0 100644
--- a/libqblock/Makefile
+++ b/libqblock/Makefile
@@ -1,4 +1,4 @@
-all: libqblock.la
+libqblock_includedir= $(includedir)/qblock
 
 # objects linked into a shared library, built with libtool with -fPIC if 
required
 libqblock-obj-y = libqblock/libqblock.o libqblock/libqblock-error.o
@@ -7,12 +7,21 @@ libqblock-obj-y += $(util-obj-y) $(block-obj-y)
 
 libqblock-lobj-y=$(patsubst %.o, %.lo, $(libqblock-obj-y))
 
+libqblock-pub-headers= $(SRC_PATH)/libqblock/libqblock.h \
+   $(SRC_PATH)/libqblock/libqblock-types.h \
+   $(SRC_PATH)/libqblock/libqblock-error.h
+
+libqblock-requires-y = rt gthread-2.0 glib-2.0 z
+libqblock-requires-$(CONFIG_CURL) += curl
+libqblock-requires-$(CONFIG_LIBCAP) += cap-ng
+libqblock-requires-$(CONFIG_UUID) += uuid
+
 # libtool will build the .o files, too
 $(libqblock-obj-y): | $(libqblock-lobj-y)
 
-LIBQBLOCK_CLEAN_TARGETS=$(libqblock-lobj-y) libqblock.la libqblock/.libs
+LIBQBLOCK_CLEAN_TARGETS=$(libqblock-lobj-y) libqblock.la libqblock.pc 
libqblock/.libs
 
-all: libqblock.la
+all: libqblock.la libqblock.pc
 
 #
 # Rules for building libqblock standalone library
@@ -23,8 +32,24 @@ libqblock.la: LDFLAGS += -rpath $(libdir) -no-undefined \
 libqblock.la: $(libqblock-lobj-y)
$(call LINK,$^)
 
-
-.PHONY: libqblock-clean
+libqblock.pc: $(SRC_PATH)/libqblock/libqblock.pc.in
+   $(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
+   -e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
+   -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
+   -e 's|@PREFIX@|$(prefix)|' \
+   -e 's|@REQUIRES@|$(libqblock-requires-y)|' \
+   $< > libqblock.pc,\
+   "  GEN   $@")
+
+.PHONY: libqblock-clean install-libqblock
+
+install-libqblock: libqblock.la libqblock.pc
+   $(INSTALL_DIR) "$(DESTDIR)$(libdir)"
+   $(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
+   $(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
+   $(INSTALL_LIB) libqblock.la "$(DESTDIR)$(libdir)"
+   $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
+   $(INSTALL_DATA) $(libqblock-pub-headers) 
"$(DESTDIR)$(libqblock_includedir)"
 
 libqblock-clean:
rm $(LIBQBLOCK_CLEAN_TARGETS) -rf
diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
new file mode 100644
index 000..e69de29
diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
new file mode 100644
index 000..e69de29
diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
new file mode 100644
index 000..e69de29
diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
new file mode 100644
index 000..0901672
--- /dev/null
+++ b/libqblock/libqblock.pc.in
@@ -0,0 +1,13 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: qblock
+Description: Qemu block layer library
+Version: @VERSION@
+
+Requires: @REQUIRES@
+Libs: -L${libdir} -lqblock
+Libs.private:
+Cflags: -I${includedir}
-- 
1.7.1





[Qemu-devel] [PATCH V16 8/9] libqblock: build: add rules for test case

2013-01-28 Thread Wenchao Xia
  Libtool will be used for final link, the rules do nothing if
libqblock was disabled. Temp directory was used to store image
created in test, which will be deleted in clean.

Signed-off-by: Wenchao Xia 
---
 tests/Makefile |   13 -
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index a653532..ac7f477 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -134,9 +134,20 @@ qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a
 qtest-obj-y += tests/libi2c.o tests/libi2c-omap.o
 $(check-qtest-y): $(qtest-obj-y)
 
+#libqblock build rules
+
+LIBQBLOCK_TEST_DIR = tests/test_images
+check-libqblock-$(CONFIG_LIBQBLOCK) = tests/check-libqblock-qcow2$(EXESUF)
+$(check-libqblock-y): QEMU_INCLUDES += -I$(SRC_PATH)/tests 
-I$(SRC_PATH)/libqblock
+
+$(check-libqblock-y): %$(EXESUF): %.o libqblock.la
+   $(call LINK, $^)
+
+check-unit-y += $(check-libqblock-y)
+
 #clean rules
 
-CHECK_CLEAN_TARGETS = $(check-unit-y) $(check-qtest-i386-y) 
$(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y) 
tests/*.o
+CHECK_CLEAN_TARGETS = $(check-unit-y) $(check-qtest-i386-y) 
$(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y) 
tests/*.o $(check-libqblock-y) $(LIBQBLOCK_TEST_DIR)
 
 .PHONY: check-help
 check-help:
-- 
1.7.1





Re: [Qemu-devel] [PATCH V2 00/20] Multiqueue virtio-net

2013-01-28 Thread Jason Wang
On 01/29/2013 01:36 PM, Wanlong Gao wrote:
> On 01/28/2013 12:24 PM, Jason Wang wrote:
>> On 01/28/2013 11:27 AM, Wanlong Gao wrote:
>>> On 01/25/2013 06:35 PM, Jason Wang wrote:
 Hello all:

 This seires is an update of last version of multiqueue virtio-net support.

 This series tries to brings multiqueue support to virtio-net through a
 multiqueue support tap backend and multiple vhost threads.

 To support this, multiqueue nic support were added to qemu. This is done by
 introducing an array of NetClientStates in NICState, and make each pair of 
 peers
 to be an queue of the nic. This is done in patch 1-7.

 Tap were also converted to be able to create a multiple queue
 backend. Currently, only linux support this by issuing TUNSETIFF N times 
 with
 the same device name to create N queues. Each fd returned by TUNSETIFF 
 were a
 queue supported by kernel. Three new command lines were introduced, 
 "queues"
 were used to tell how many queues will be created by qemu; "fds" were used 
 to
 pass multiple pre-created tap file descriptors to qemu; "vhostfds" were 
 used to
 pass multiple pre-created vhost descriptors to qemu. This is done in patch 
 8-13.

 A method of deleting a queue and queue_index were also introduce for 
 virtio,
 this is done in patch 14-15.

 Vhost were also changed to support multiqueue by introducing a start vq 
 index
 which tracks the first virtqueue that will be used by vhost instead of the
 assumption that the vhost always use virtqueue from index 0. This is done 
 in
 patch 16.

 The last part is the multiqueue userspace changes, this is done in patch 
 17-20.

 With this changes, user could start a multiqueue virtio-net device through

 ./qemu -netdev tap,id=hn0,queues=2,vhost=on -device 
 virtio-net-pci,netdev=hn0

 Management tools such as libvirt can pass multiple pre-created 
 fds/vhostfds through

 ./qemu -netdev tap,id=hn0,fds=X:Y,vhostfds=M:N -device 
 virtio-net-pci,netdev=hn0

 No git tree this round since github is unavailable in China...
>>> I saw that github had already been opened again. I can use it.
>> Thanks for reminding, I've pushed the new bits to
>> git://github.com/jasowang/qemu.git.
> I got host kernel oops here using your qemu tree and 3.8-rc5 kernel on host,
>
> [31499.754779] BUG: unable to handle kernel NULL pointer dereference at   
> (null)
> [31499.757098] IP: [] _raw_spin_lock_irqsave+0x1f/0x40
> [31499.758304] PGD 0 
> [31499.759498] Oops: 0002 [#1] SMP 
> [31499.760704] Modules linked in: tcp_lp fuse xt_CHECKSUM lockd 
> ipt_MASQUERADE sunrpc bnep bluetooth rfkill bridge stp llc iptable_nat 
> nf_nat_ipv4 nf_nat iptable_mangle nf_conntr
> ack_ipv4 nf_defrag_ipv4 nf_conntrack snd_hda_codec_realtek snd_hda_intel 
> snd_hda_codec vhost_net tun snd_hwdep macvtap snd_seq macvlan coretemp 
> kvm_intel snd_seq_device kvm snd_p
> cm crc32c_intel r8169 snd_page_alloc snd_timer ghash_clmulni_intel snd mei 
> iTCO_wdt mii microcode iTCO_vendor_support uinput serio_raw wmi i2c_i801 
> lpc_ich soundcore pcspkr mfd_c
> ore i915 video i2c_algo_bit drm_kms_helper drm i2c_core [last unloaded: 
> ip6t_REJECT]
> [31499.766412] CPU 2 
> [31499.766426] Pid: 18742, comm: vhost-18728 Not tainted 3.8.0-rc5 #1 LENOVO 
> QiTianM4300/To be filled by O.E.M.
> [31499.769340] RIP: 0010:[]  [] 
> _raw_spin_lock_irqsave+0x1f/0x40
> [31499.770861] RSP: 0018:8801b2f9dd08  EFLAGS: 00010086
> [31499.772380] RAX: 0286 RBX:  RCX: 
> 
> [31499.773916] RDX: 0100 RSI: 0286 RDI: 
> 
> [31499.775394] RBP: 8801b2f9dd08 R08: 880132ed4368 R09: 
> 
> [31499.776923] R10: 0001 R11: 0001 R12: 
> 880132ed8590
> [31499.778466] R13: 880232a6c290 R14: 880132ed42b0 R15: 
> 880132ed0078
> [31499.780012] FS:  () GS:88023fb0() 
> knlGS:
> [31499.781574] CS:  0010 DS:  ES:  CR0: 80050033
> [31499.783126] CR2:  CR3: 000132d9c000 CR4: 
> 000427e0
> [31499.784696] DR0:  DR1:  DR2: 
> 
> [31499.786267] DR3:  DR6: 0ff0 DR7: 
> 0400
> [31499.787822] Process vhost-18728 (pid: 18742, threadinfo 8801b2f9c000, 
> task 880036959740)
> [31499.788821] Stack:
> [31499.790392]  8801b2f9dd38 81082534  
> 0001
> [31499.792029]  880132ed 880232a6c290 8801b2f9dd48 
> a023fab6
> [31499.793677]  8801b2f9de28 a0242f64 8801b2f9ddb8 
> 8109e0e0
> [31499.795332] Call Trace:
> [31499.796974]  [] remove_wait_queue+0x24/0x50
> [31499.798641]  [] vhost_poll_stop+0x16/0x20 [vhost_net]
> [31499.800313]

[Qemu-devel] [PATCH 2/2] usb-ehci: add Faraday FUSBH200 support

2013-01-28 Thread Kuo-Jung Su
From: Kuo-Jung Su 

Add Faraday FUSBH200 support, which is slightly different from EHCI spec.
(Or maybe simply a bad/wrong implementation...)

Signed-off-by: Kuo-Jung Su 
Cc: Gerd Hoffmann 
Cc: Andreas 
Cc: Peter Crosthwaite 
---
 hw/usb/hcd-ehci-sysbus.c |   66 ++
 hw/usb/hcd-ehci.h|5 
 2 files changed, 71 insertions(+)

diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index ae2db1a..404a227 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -17,6 +17,49 @@
 
 #include "hw/usb/hcd-ehci.h"
 
+/*
+ * Faraday FUSBH200 USB 2.0 EHCI
+ */
+
+static uint64_t
+ehci_fusbh200_read(void *ptr, hwaddr addr, unsigned size)
+{
+hwaddr off = 0x34 + addr;
+
+switch (off) {
+case 0x34:  /* fusbh200: EOF/Async. Sleep Timer Register */
+return 0x0041;
+case 0x40:  /* fusbh200: Bus Monitor Control/Status Register */
+/* High-Speed, VBUS valid, interrupt level-high active */
+return (2 << 9) | (1 << 8) | (1 << 3);
+}
+
+return 0;
+}
+
+static void
+ehci_fusbh200_write(void *ptr, hwaddr addr, uint64_t val, unsigned size)
+{
+}
+
+static const MemoryRegionOps ehci_mmio_fusbh200_ops = {
+.read = ehci_fusbh200_read,
+.write = ehci_fusbh200_write,
+.valid.min_access_size = 4,
+.valid.max_access_size = 4,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static void
+usb_ehci_fusbh200_initfn(EHCIState *s, DeviceState *dev)
+{
+memory_region_init_io(&s->mem_vendor, &ehci_mmio_fusbh200_ops, s,
+  "fusbh200", 0x4c);
+memory_region_add_subregion(&s->mem,
+s->opregbase + s->portscbase + 4 * s->portnr,
+&s->mem_vendor);
+}
+
 static const VMStateDescription vmstate_ehci_sysbus = {
 .name= "ehci-sysbus",
 .version_id  = 2,
@@ -46,6 +89,9 @@ static void usb_ehci_sysbus_realizefn(DeviceState *dev, Error 
**errp)
 s->dma = &dma_context_memory;
 
 usb_ehci_initfn(s, dev);
+if (sec->vendor_init) {
+sec->vendor_init(s, DEVICE(dev));
+}
 sysbus_init_irq(d, &s->irq);
 sysbus_init_mmio(d, &s->mem);
 }
@@ -76,6 +122,7 @@ static void ehci_xlnx_class_init(ObjectClass *oc, void *data)
 sec->opregbase = 0x140;
 sec->portscbase = 0x44;
 sec->portnr = NB_PORTS;
+sec->vendor_init = NULL;
 }
 
 static const TypeInfo ehci_xlnx_type_info = {
@@ -92,6 +139,7 @@ static void ehci_exynos4210_class_init(ObjectClass *oc, void 
*data)
 sec->opregbase = 0x10;
 sec->portscbase = 0x44;
 sec->portnr = NB_PORTS;
+sec->vendor_init = NULL;
 }
 
 static const TypeInfo ehci_exynos4210_type_info = {
@@ -100,11 +148,29 @@ static const TypeInfo ehci_exynos4210_type_info = {
 .class_init= ehci_exynos4210_class_init,
 };
 
+static void ehci_fusbh200_class_init(ObjectClass *oc, void *data)
+{
+SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
+
+sec->capsbase = 0x0;
+sec->opregbase = 0x10;
+sec->portscbase = 0x20;
+sec->portnr = 1;
+sec->vendor_init = usb_ehci_fusbh200_initfn;
+}
+
+static const TypeInfo ehci_fusbh200_type_info = {
+.name  = TYPE_FUSBH200_EHCI,
+.parent= TYPE_SYS_BUS_EHCI,
+.class_init= ehci_fusbh200_class_init,
+};
+
 static void ehci_sysbus_register_types(void)
 {
 type_register_static(&ehci_type_info);
 type_register_static(&ehci_xlnx_type_info);
 type_register_static(&ehci_exynos4210_type_info);
+type_register_static(&ehci_fusbh200_type_info);
 }
 
 type_init(ehci_sysbus_register_types)
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index e587b67..3ca9c8f 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -261,6 +261,7 @@ struct EHCIState {
 MemoryRegion mem_caps;
 MemoryRegion mem_opreg;
 MemoryRegion mem_ports;
+MemoryRegion mem_vendor;
 int companion_count;
 uint16_t capsbase;
 uint16_t opregbase;
@@ -336,6 +337,7 @@ typedef struct EHCIPCIState {
 
 #define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"
 #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
+#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
 
 #define SYS_BUS_EHCI(obj) \
 OBJECT_CHECK(EHCISysBusState, (obj), TYPE_SYS_BUS_EHCI)
@@ -361,6 +363,9 @@ typedef struct SysBusEHCIClass {
 uint16_t opregbase;
 uint16_t portscbase;
 uint16_t portnr;
+
+/* vendor specific init function */
+void (*vendor_init)(EHCIState *s, DeviceState *dev);
 } SysBusEHCIClass;
 
 #endif
-- 
1.7.9.5




[Qemu-devel] [PATCH 1/2] usb-ehci: replace PORTSC macros with variables

2013-01-28 Thread Kuo-Jung Su
From: Kuo-Jung Su 

Replace PORTSC macros with variables which could then be
configured in ehci__class_init(...)

Signed-off-by: Kuo-Jung Su 
Cc: Gerd Hoffmann 
Cc: Andreas 
Cc: Peter Crosthwaite 
---
 hw/usb/hcd-ehci-sysbus.c |6 ++
 hw/usb/hcd-ehci.c|   21 +
 hw/usb/hcd-ehci.h|   12 ++--
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index e504703..ae2db1a 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -41,6 +41,8 @@ static void usb_ehci_sysbus_realizefn(DeviceState *dev, Error 
**errp)
 
 s->capsbase = sec->capsbase;
 s->opregbase = sec->opregbase;
+s->portscbase = sec->portscbase;
+s->portnr = sec->portnr;
 s->dma = &dma_context_memory;
 
 usb_ehci_initfn(s, dev);
@@ -72,6 +74,8 @@ static void ehci_xlnx_class_init(ObjectClass *oc, void *data)
 
 sec->capsbase = 0x100;
 sec->opregbase = 0x140;
+sec->portscbase = 0x44;
+sec->portnr = NB_PORTS;
 }
 
 static const TypeInfo ehci_xlnx_type_info = {
@@ -86,6 +90,8 @@ static void ehci_exynos4210_class_init(ObjectClass *oc, void 
*data)
 
 sec->capsbase = 0x0;
 sec->opregbase = 0x10;
+sec->portscbase = 0x44;
+sec->portnr = NB_PORTS;
 }
 
 static const TypeInfo ehci_exynos4210_type_info = {
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 7040659..4c17990 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -988,7 +988,7 @@ static uint64_t ehci_port_read(void *ptr, hwaddr addr,
 uint32_t val;
 
 val = s->portsc[addr >> 2];
-trace_usb_ehci_portsc_read(addr + PORTSC_BEGIN, addr >> 2, val);
+trace_usb_ehci_portsc_read(addr + s->portscbase, addr >> 2, val);
 return val;
 }
 
@@ -1029,7 +1029,7 @@ static void ehci_port_write(void *ptr, hwaddr addr,
 uint32_t old = *portsc;
 USBDevice *dev = s->ports[port].dev;
 
-trace_usb_ehci_portsc_write(addr + PORTSC_BEGIN, addr >> 2, val);
+trace_usb_ehci_portsc_write(addr + s->portscbase, addr >> 2, val);
 
 /* Clear rwc bits */
 *portsc &= ~(val & PORTSC_RWC_MASK);
@@ -1062,7 +1062,7 @@ static void ehci_port_write(void *ptr, hwaddr addr,
 
 *portsc &= ~PORTSC_RO_MASK;
 *portsc |= val;
-trace_usb_ehci_portsc_change(addr + PORTSC_BEGIN, addr >> 2, *portsc, old);
+trace_usb_ehci_portsc_change(addr + s->portscbase, addr >> 2, *portsc, 
old);
 }
 
 static void ehci_opreg_write(void *ptr, hwaddr addr,
@@ -2510,7 +2510,7 @@ void usb_ehci_initfn(EHCIState *s, DeviceState *dev)
 s->caps[0x01] = 0x00;
 s->caps[0x02] = 0x00;
 s->caps[0x03] = 0x01;/* HC version */
-s->caps[0x04] = NB_PORTS;/* Number of downstream ports */
+s->caps[0x04] = s->portnr;   /* Number of downstream ports */
 s->caps[0x05] = 0x00;/* No companion ports at present */
 s->caps[0x06] = 0x00;
 s->caps[0x07] = 0x00;
@@ -2518,8 +2518,13 @@ void usb_ehci_initfn(EHCIState *s, DeviceState *dev)
 s->caps[0x0a] = 0x00;
 s->caps[0x0b] = 0x00;
 
+if (s->portnr > NB_PORTS) {
+hw_error("hcd-ehci: too many ports! max. port number=%d\n", NB_PORTS);
+exit(1);
+}
+
 usb_bus_new(&s->bus, &ehci_bus_ops, dev);
-for(i = 0; i < NB_PORTS; i++) {
+for (i = 0; i < s->portnr; i++) {
 usb_register_port(&s->bus, &s->ports[i], s, i, &ehci_port_ops,
   USB_SPEED_MASK_HIGH);
 s->ports[i].dev = 0;
@@ -2538,13 +2543,13 @@ void usb_ehci_initfn(EHCIState *s, DeviceState *dev)
 memory_region_init_io(&s->mem_caps, &ehci_mmio_caps_ops, s,
   "capabilities", CAPA_SIZE);
 memory_region_init_io(&s->mem_opreg, &ehci_mmio_opreg_ops, s,
-  "operational", PORTSC_BEGIN);
+  "operational", s->portscbase);
 memory_region_init_io(&s->mem_ports, &ehci_mmio_port_ops, s,
-  "ports", PORTSC_END - PORTSC_BEGIN);
+  "ports", 4 * s->portnr);
 
 memory_region_add_subregion(&s->mem, s->capsbase, &s->mem_caps);
 memory_region_add_subregion(&s->mem, s->opregbase, &s->mem_opreg);
-memory_region_add_subregion(&s->mem, s->opregbase + PORTSC_BEGIN,
+memory_region_add_subregion(&s->mem, s->opregbase + s->portscbase,
 &s->mem_ports);
 }
 
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index e95bb7e..e587b67 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -40,11 +40,7 @@
 #define MMIO_SIZE0x1000
 #define CAPA_SIZE0x10
 
-#define PORTSC   0x0044
-#define PORTSC_BEGIN PORTSC
-#define PORTSC_END   (PORTSC + 4 * NB_PORTS)
-
-#define NB_PORTS 6/* Number of downstream ports */
+#define NB_PORTS 6/* Max. Number of downstream ports */
 
 typedef struct EHCIPacket EHCIPacket;
 typedef struct EHCIQueue EHCIQueue;
@@ -268,6 +264,8 @@ struct EHCIState {
 int companio

[Qemu-devel] [PATCH 0/2] usb-ehci: add Faraday FUSBH200 support

2013-01-28 Thread Kuo-Jung Su
From: Kuo-Jung Su 

First of all, Andreas's QOM realizefn patch for hcd-ehci-sysbus
must be applied prior to this patch set.

Here is the link to Andreas's QOM realizefn patch:

http://patchwork.ozlabs.org/patch/215919/


Now return to the topic, this patch set has 2 parts:

1. Replace PORTSC macros with variables which could then be
   configured in ehci__class_init(...)

2. Add Faraday FUSBH200 support, which is slightly different from EHCI spec.
   (Or maybe simply a bad/wrong implementation...)

Kuo-Jung Su (2):
  usb-ehci: replace PORTSC macros with variables
  usb-ehci: add Faraday FUSBH200 support

 hw/usb/hcd-ehci-sysbus.c |   72 ++
 hw/usb/hcd-ehci.c|   21 --
 hw/usb/hcd-ehci.h|   17 +++
 3 files changed, 96 insertions(+), 14 deletions(-)

-- 
1.7.9.5




Re: [Qemu-devel] [PATCH V2 00/20] Multiqueue virtio-net

2013-01-28 Thread Wanlong Gao
On 01/28/2013 12:24 PM, Jason Wang wrote:
> On 01/28/2013 11:27 AM, Wanlong Gao wrote:
>> On 01/25/2013 06:35 PM, Jason Wang wrote:
>>> Hello all:
>>>
>>> This seires is an update of last version of multiqueue virtio-net support.
>>>
>>> This series tries to brings multiqueue support to virtio-net through a
>>> multiqueue support tap backend and multiple vhost threads.
>>>
>>> To support this, multiqueue nic support were added to qemu. This is done by
>>> introducing an array of NetClientStates in NICState, and make each pair of 
>>> peers
>>> to be an queue of the nic. This is done in patch 1-7.
>>>
>>> Tap were also converted to be able to create a multiple queue
>>> backend. Currently, only linux support this by issuing TUNSETIFF N times 
>>> with
>>> the same device name to create N queues. Each fd returned by TUNSETIFF were 
>>> a
>>> queue supported by kernel. Three new command lines were introduced, "queues"
>>> were used to tell how many queues will be created by qemu; "fds" were used 
>>> to
>>> pass multiple pre-created tap file descriptors to qemu; "vhostfds" were 
>>> used to
>>> pass multiple pre-created vhost descriptors to qemu. This is done in patch 
>>> 8-13.
>>>
>>> A method of deleting a queue and queue_index were also introduce for virtio,
>>> this is done in patch 14-15.
>>>
>>> Vhost were also changed to support multiqueue by introducing a start vq 
>>> index
>>> which tracks the first virtqueue that will be used by vhost instead of the
>>> assumption that the vhost always use virtqueue from index 0. This is done in
>>> patch 16.
>>>
>>> The last part is the multiqueue userspace changes, this is done in patch 
>>> 17-20.
>>>
>>> With this changes, user could start a multiqueue virtio-net device through
>>>
>>> ./qemu -netdev tap,id=hn0,queues=2,vhost=on -device 
>>> virtio-net-pci,netdev=hn0
>>>
>>> Management tools such as libvirt can pass multiple pre-created fds/vhostfds 
>>> through
>>>
>>> ./qemu -netdev tap,id=hn0,fds=X:Y,vhostfds=M:N -device 
>>> virtio-net-pci,netdev=hn0
>>>
>>> No git tree this round since github is unavailable in China...
>> I saw that github had already been opened again. I can use it.
> 
> Thanks for reminding, I've pushed the new bits to
> git://github.com/jasowang/qemu.git.

I got host kernel oops here using your qemu tree and 3.8-rc5 kernel on host,

[31499.754779] BUG: unable to handle kernel NULL pointer dereference at 
  (null)
[31499.757098] IP: [] _raw_spin_lock_irqsave+0x1f/0x40
[31499.758304] PGD 0 
[31499.759498] Oops: 0002 [#1] SMP 
[31499.760704] Modules linked in: tcp_lp fuse xt_CHECKSUM lockd ipt_MASQUERADE 
sunrpc bnep bluetooth rfkill bridge stp llc iptable_nat nf_nat_ipv4 nf_nat 
iptable_mangle nf_conntr
ack_ipv4 nf_defrag_ipv4 nf_conntrack snd_hda_codec_realtek snd_hda_intel 
snd_hda_codec vhost_net tun snd_hwdep macvtap snd_seq macvlan coretemp 
kvm_intel snd_seq_device kvm snd_p
cm crc32c_intel r8169 snd_page_alloc snd_timer ghash_clmulni_intel snd mei 
iTCO_wdt mii microcode iTCO_vendor_support uinput serio_raw wmi i2c_i801 
lpc_ich soundcore pcspkr mfd_c
ore i915 video i2c_algo_bit drm_kms_helper drm i2c_core [last unloaded: 
ip6t_REJECT]
[31499.766412] CPU 2 
[31499.766426] Pid: 18742, comm: vhost-18728 Not tainted 3.8.0-rc5 #1 LENOVO 
QiTianM4300/To be filled by O.E.M.
[31499.769340] RIP: 0010:[]  [] 
_raw_spin_lock_irqsave+0x1f/0x40
[31499.770861] RSP: 0018:8801b2f9dd08  EFLAGS: 00010086
[31499.772380] RAX: 0286 RBX:  RCX: 
[31499.773916] RDX: 0100 RSI: 0286 RDI: 
[31499.775394] RBP: 8801b2f9dd08 R08: 880132ed4368 R09: 
[31499.776923] R10: 0001 R11: 0001 R12: 880132ed8590
[31499.778466] R13: 880232a6c290 R14: 880132ed42b0 R15: 880132ed0078
[31499.780012] FS:  () GS:88023fb0() 
knlGS:
[31499.781574] CS:  0010 DS:  ES:  CR0: 80050033
[31499.783126] CR2:  CR3: 000132d9c000 CR4: 000427e0
[31499.784696] DR0:  DR1:  DR2: 
[31499.786267] DR3:  DR6: 0ff0 DR7: 0400
[31499.787822] Process vhost-18728 (pid: 18742, threadinfo 8801b2f9c000, 
task 880036959740)
[31499.788821] Stack:
[31499.790392]  8801b2f9dd38 81082534  
0001
[31499.792029]  880132ed 880232a6c290 8801b2f9dd48 
a023fab6
[31499.793677]  8801b2f9de28 a0242f64 8801b2f9ddb8 
8109e0e0
[31499.795332] Call Trace:
[31499.796974]  [] remove_wait_queue+0x24/0x50
[31499.798641]  [] vhost_poll_stop+0x16/0x20 [vhost_net]
[31499.800313]  [] handle_tx+0x4c4/0x680 [vhost_net]
[31499.801995]  [] ? idle_balance+0x1b0/0x2f0
[31499.803685]  [] handle_tx_kick+0x15/0x20 [vhost_net]
[31499.805128]  [] vhost_worker+0xed/0x190 [vhost_net]
[31499.806842]  [] ? vhost_work_flus

[Qemu-devel] [PATCH V16 7/9] libqblock: libqblock API implement

2013-01-28 Thread Wenchao Xia
  This patch contains implemention for APIs. Basically it is a layer
above qemu block general layer now.

Signed-off-by: Wenchao Xia 
---
 libqblock/libqblock-error.c |   57 +++
 libqblock/libqblock.c   | 1069 +++
 2 files changed, 1126 insertions(+), 0 deletions(-)

diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
index e69de29..ca78b50 100644
--- a/libqblock/libqblock-error.c
+++ b/libqblock/libqblock-error.c
@@ -0,0 +1,57 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "libqblock-error.h"
+#include "libqblock-internal.h"
+
+void qb_error_get_human_str(QBlockContext *context,
+char *buf, size_t buf_size)
+{
+const char *err_ret_str;
+switch (context->err_ret) {
+case QB_ERR_INTERNAL_ERR:
+err_ret_str = "Internal error.";
+break;
+case QB_ERR_INVALID_PARAM:
+err_ret_str = "Invalid param.";
+break;
+case QB_ERR_BLOCK_OUT_OF_RANGE:
+err_ret_str = "request is out of image's range.";
+break;
+default:
+err_ret_str = "Unknown error.";
+break;
+}
+if (context == NULL) {
+snprintf(buf, buf_size, "%s", err_ret_str);
+return;
+}
+
+if (context->err_ret == QB_ERR_INTERNAL_ERR) {
+snprintf(buf, buf_size, "%s %s errno [%d]. strerror [%s].",
+ err_ret_str, context->g_error->message,
+ context->err_no, strerror(-context->err_no));
+} else {
+snprintf(buf, buf_size, "%s %s",
+ err_ret_str, context->g_error->message);
+}
+return;
+}
+
+int qb_error_get_errno(QBlockContext *context)
+{
+if (context->err_ret == QB_ERR_INTERNAL_ERR) {
+return context->err_no;
+}
+return 0;
+}
diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
index e69de29..6d5b497 100644
--- a/libqblock/libqblock.c
+++ b/libqblock/libqblock.c
@@ -0,0 +1,1069 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include "libqblock.h"
+#include "libqblock-internal.h"
+
+#include "block/block_int.h"
+
+#define LIBQB_FILENAME_MAX 4096
+
+typedef struct LibqbFormatStrMapping {
+const char *fmt_str;
+QBlockFormat fmt_type;
+} LibqbFormatStrMapping;
+
+LibqbFormatStrMapping libqb_fmtstr_table[] = {
+{"cow", QB_FMT_COW},
+{"qed", QB_FMT_QED},
+{"qcow", QB_FMT_QCOW},
+{"qcow2", QB_FMT_QCOW2},
+{"raw", QB_FMT_RAW},
+{"rbd", QB_FMT_RBD},
+{"sheepdog", QB_FMT_SHEEPDOG},
+{"vdi", QB_FMT_VDI},
+{"vmdk", QB_FMT_VMDK},
+{"vpc", QB_FMT_VPC},
+{NULL, 0},
+};
+
+__attribute__((constructor))
+static void libqblock_init(void)
+{
+/* Todo: add an assertion about the ABI. */
+qemu_init_main_loop();
+bdrv_init();
+}
+
+const char *qb_fmttype2str(QBlockFormat fmt_type)
+{
+int i = 0;
+LibqbFormatStrMapping *tb = libqb_fmtstr_table;
+
+if ((fmt_type <= QB_FMT_NONE) || (fmt_type >= QB_FMT_MAX)) {
+return NULL;
+}
+while (tb[i].fmt_str != NULL) {
+if (tb[i].fmt_type == fmt_type) {
+return tb[i].fmt_str;
+}
+i++;
+}
+return NULL;
+}
+
+QBlockFormat qb_str2fmttype(const char *fmt_str)
+{
+int i = 0;
+LibqbFormatStrMapping *tb = libqb_fmtstr_table;
+
+if (fmt_str == NULL) {
+return QB_FMT_NONE;
+}
+while (tb[i].fmt_str != NULL) {
+if ((strcmp(fmt_str, tb[i].fmt_str) == 0)) {
+return tb[i].fmt_type;
+}
+i++;
+}
+return QB_FMT_NONE;
+}
+
+static void set_context_err(QBlockContext *context, int err_ret,
+const char *fmt, ...)
+{
+va_list ap;
+
+if (context->g_error != NULL) {
+g_error_free(context->g_error);
+}
+
+va_start(ap, fmt);
+context->g_error = g_error_new_valist(G_LIBQBLOCK_ERROR, err_ret, fmt, ap);
+va_end(ap);
+
+context->err_ret = err_ret;
+if (err_ret == QB_ERR_INTERNAL_ERR) {
+context->err_no = -errno;
+} else {
+context->err_no = 0;
+}
+}
+
+int qb_context_new(QBlockContext **p_context)
+{
+*p_context = g_malloc0_n(1, sizeof(QBlockContext));
+
+/* AIO code could comes here later. */
+return 0;
+}
+
+void qb_context_delete(QBlockContext **p_context)
+{
+if ((*p_context)->g_error != NULL) {
+g_error_free((*p_context)->g_error);
+}
+QB_FREE(*p_context);
+return;
+}
+
+int qb_image_new(QBlockContext *context,
+ QBlockImage **p_qbi)
+{
+*p_qbi = g_malloc0

[Qemu-devel] [PATCH V16 9/9] libqblock: test: libqblock test example

2013-01-28 Thread Wenchao Xia
  In this example, first it will create some qcow2 images, then try get
information including backing file relationship, then it will do sync IO on
the image.

Signed-off-by: Wenchao Xia 
---
 tests/check-libqblock-qcow2.c |  392 +
 1 files changed, 392 insertions(+), 0 deletions(-)
 create mode 100644 tests/check-libqblock-qcow2.c

diff --git a/tests/check-libqblock-qcow2.c b/tests/check-libqblock-qcow2.c
new file mode 100644
index 000..0cbe8da
--- /dev/null
+++ b/tests/check-libqblock-qcow2.c
@@ -0,0 +1,392 @@
+/*
+ * QEMU block layer library test
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ * Limitation:
+ *1 filename do not support relative path, to save trouble in creating
+ * backing files.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include "libqblock.h"
+#include "libqtest.h"
+
+#define LIBQB_TEST_ENV_DIR "LIBQBLOCK_TEST_DIR"
+#define LIBQB_TEST_DEFAULT_DIR "/tmp"
+#define LIBQB_TEST_DEFAULT_FILENAME "libqblock_qcow2_test_img"
+
+typedef struct LibqbTestSettings {
+const char *image_filename;
+uint64_t image_size;
+unsigned int num_backings;
+unsigned int io_buf_size;
+uint64_t io_offset;
+int print_flag;
+} LibqbTestSettings;
+
+LibqbTestSettings libqb_test_settings;
+
+static void print_loc(const QBlockLocationInfo *loc)
+{
+if (loc == NULL) {
+printf("loc is NULL.");
+return;
+}
+switch (loc->prot_type) {
+case QB_PROTO_NONE:
+printf("protocol type [none].");
+break;
+case QB_PROTO_FILE:
+printf("protocol type [file], filename [%s].",
+   loc->o_file.filename);
+break;
+default:
+printf("protocol type not supported.");
+break;
+}
+}
+
+static void print_info_image_static(QBlockStaticInfo *info)
+{
+const uint64_t *virt_size = qb_get_virt_size(info);
+const QBlockLocationInfo *backing_loc = qb_get_backing_loc(info);
+g_assert(virt_size != NULL);
+
+printf("===image location:\n");
+print_loc(&info->loc);
+printf("\nvirtual_size %" PRId64 ", format type %d [%s]",
+   *(virt_size),
+   info->fmt.fmt_type, qb_fmttype2str(info->fmt.fmt_type));
+printf("\nbacking image location:\n");
+print_loc(backing_loc);
+printf("\n");
+}
+
+static char *generate_backing_filename(const char *filename, int index)
+{
+char *backing_filename = NULL;
+
+backing_filename = g_strdup_printf("%s_backing_%d", filename, index);
+return backing_filename;
+}
+
+/* get filename in a full path */
+static const char *get_filename(const char *path)
+{
+const char *filename;
+filename = strrchr(path, '/');
+if (filename == NULL) {
+filename = path;
+} else {
+filename++;
+}
+return filename;
+}
+
+/* create a chain of files, num_backings must >= 0. */
+static void files_create_qcow2(const char *filename,
+   int num_backings,
+   uint64_t virt_size)
+{
+QBlockContext *context = NULL;
+QBlockImage *qbi = NULL;
+QBlockLocationInfo *loc_info = NULL;
+QBlockFormatInfo *fmt_info = NULL;
+int ret;
+int index;
+int flag;
+char *backing_filename = NULL, *new_filename = NULL;
+const char *relative_filename = NULL;
+
+ret = qb_context_new(&context);
+g_assert(ret == 0);
+
+ret = qb_image_new(context, &qbi);
+g_assert(ret == 0);
+
+ret = qb_loc_info_new(context, &loc_info);
+g_assert(ret == 0);
+
+ret = qb_fmt_info_new(context, &fmt_info);
+g_assert(ret == 0);
+
+loc_info->prot_type = QB_PROTO_FILE;
+fmt_info->fmt_type = QB_FMT_QCOW2;
+fmt_info->virt_size = virt_size;
+flag = 0;
+
+index = 0;
+while (index < num_backings) {
+new_filename = generate_backing_filename(filename, index);
+loc_info->o_file.filename = new_filename;
+if (backing_filename != NULL) {
+fmt_info->o_qcow2.backing_loc.prot_type = QB_PROTO_FILE;
+relative_filename = get_filename(backing_filename);
+fmt_info->o_qcow2.backing_loc.o_file.filename =
+ relative_filename;
+}
+ret = qb_create(context, qbi, loc_info, fmt_info, flag);
+g_assert(ret == 0);
+free(backing_filename);
+backing_filename = new_filename;
+new_filename = NULL;
+index++;
+}
+
+loc_info->o_file.filename = filename;
+if (backing_filename != NULL) {
+fmt_info->o_qcow2.backing_loc.prot_type = QB_PROTO_FILE;
+relative_filename = get_filename(backing_filename);
+fmt_info->o_qcow2.backing_loc.o_file.filename =
+  

[Qemu-devel] [PATCH V16 3/9] libqblock: build: add rule for libqblock.la

2013-01-28 Thread Wenchao Xia
  Now libqblock.la can be built with neccessary object files,
and can be automatically cleaned by make clean in root directory.
make libqblock-clean also clean it. -fvisibility=hidden was used
to hide symbols, and a special macro was introduced to export
symbols that marked as public.

Signed-off-by: Wenchao Xia 
---
 libqblock/Makefile  |   32 ++--
 1 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock.c

diff --git a/libqblock/Makefile b/libqblock/Makefile
index 8173da7..73974e9 100644
--- a/libqblock/Makefile
+++ b/libqblock/Makefile
@@ -1,4 +1,32 @@
 all: libqblock.la
 
-libqblock.la:
-   @true
+# objects linked into a shared library, built with libtool with -fPIC if 
required
+libqblock-obj-y = libqblock/libqblock.o libqblock/libqblock-error.o
+libqblock-obj-y += $(filter-out stubs/set-fd-handler.o, $(stub-obj-y))
+libqblock-obj-y += $(util-obj-y) $(block-obj-y)
+
+libqblock-lobj-y=$(patsubst %.o, %.lo, $(libqblock-obj-y))
+
+# libtool will build the .o files, too
+$(libqblock-obj-y): | $(libqblock-lobj-y)
+
+LIBQBLOCK_CLEAN_TARGETS=$(libqblock-lobj-y) libqblock.la libqblock/.libs
+
+all: libqblock.la
+
+#
+# Rules for building libqblock standalone library
+
+$(libqblock-lobj-y): QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
+libqblock.la: LDFLAGS += -rpath $(libdir) -no-undefined \
+   -export-syms $(SRC_PATH)/libqblock/libqblock.syms
+libqblock.la: $(libqblock-lobj-y)
+   $(call LINK,$^)
+
+
+.PHONY: libqblock-clean
+
+libqblock-clean:
+   rm $(LIBQBLOCK_CLEAN_TARGETS) -rf
+
+clean: libqblock-clean
diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
new file mode 100644
index 000..e69de29
diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
new file mode 100644
index 000..e69de29
-- 
1.7.1





[Qemu-devel] [PATCH V16 6/9] libqblock: libqblock API design and type defines

2013-01-28 Thread Wenchao Xia
  Public API design header files: libqblock.h, libqblock-error.h.
Public type define header files: libqblock-types.h. Private internal used
header files: libqblock-internal. For ABI some reserved bytes are used in
structure defines. Macro LIBQB_DLL_PUBLIC was used to export symbols.

Important APIs:
  1 QBlockContext. This structure was used to retrieve errors, every thread
must create one first.
  2 QBlockImage. It stands for an block image object.
  3 QBlockStaticInfo. It contains static information such as location, backing
file, size.
  4 Sync I/O. It is similar to C file open, read, write and close operations.

Signed-off-by: Wenchao Xia 
---
 libqblock/libqblock-error.h|   49 ++
 libqblock/libqblock-internal.h |   68 
 libqblock/libqblock-types.h|  245 +++
 libqblock/libqblock.h  |  355 
 4 files changed, 717 insertions(+), 0 deletions(-)
 create mode 100644 libqblock/libqblock-internal.h

diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
index e69de29..3fe9e40 100644
--- a/libqblock/libqblock-error.h
+++ b/libqblock/libqblock-error.h
@@ -0,0 +1,49 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef LIBQBLOCK_ERROR
+#define LIBQBLOCK_ERROR
+
+#include "libqblock-types.h"
+
+#define QB_ERR_INTERNAL_ERR (-1)
+#define QB_ERR_INVALID_PARAM (-100)
+#define QB_ERR_BLOCK_OUT_OF_RANGE (-101)
+
+/* error handling */
+/**
+ * qb_error_get_human_str: get human readable error string.
+ *
+ * return a human readable string, it would be truncated if buf is not big
+ *  enough.
+ *
+ * @context: operation context, must be valid.
+ * @buf: buf to receive the string.
+ * @buf_size: the size of the string buf.
+ */
+LIBQB_DLL_PUBLIC
+void qb_error_get_human_str(QBlockContext *context,
+char *buf, size_t buf_size);
+
+/**
+ * qb_error_get_errno: get error number, only valid when err_ret is
+ *   QB_ERR_INTERNAL_ERR.
+ *
+ * return negative errno if last error is QB_ERR_INTERNAL_ERR, otherwise 0.
+ *
+ * @context: operation context.
+ */
+LIBQB_DLL_PUBLIC
+int qb_error_get_errno(QBlockContext *context);
+
+#endif
diff --git a/libqblock/libqblock-internal.h b/libqblock/libqblock-internal.h
new file mode 100644
index 000..91521f5
--- /dev/null
+++ b/libqblock/libqblock-internal.h
@@ -0,0 +1,68 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef LIBQBLOCK_INTERNAL
+#define LIBQBLOCK_INTERNAL
+
+#include 
+
+#include "block/block.h"
+#include "libqblock-types.h"
+
+/* this file contains defines and types used inside the library. */
+
+#define QB_FREE(p) { \
+g_free(p); \
+(p) = NULL; \
+}
+
+/* details should be hidden to user */
+struct QBlockImage {
+BlockDriverState *bdrvs;
+/* internal used file name now, if it is not NULL, it means
+   image was opened.
+*/
+char *filename;
+int ref_count;
+};
+
+struct QBlockContext {
+/* last error */
+GError *g_error;
+int err_ret; /* 1st level of error, the libqblock error number */
+int err_no; /* 2nd level of error, errno what below reports */
+};
+
+/**
+ * QBlockStaticInfoAddr: a structure contains a set of pointer.
+ *
+ *this struct contains a set of pointer pointing to some
+ *  property related to format or protocol. If a property is not available,
+ *  it will be set as NULL. User could use this to get properties directly.
+ *
+ *  @backing_loc: backing file location.
+ *  @encrypt: encryption flag.
+*/
+
+typedef struct QBlockStaticInfoAddr {
+QBlockLocationInfo *backing_loc;
+bool *encrypt;
+} QBlockStaticInfoAddr;
+
+#define G_LIBQBLOCK_ERROR g_libqblock_error_quark()
+
+static inline GQuark g_libqblock_error_quark(void)
+{
+return g_quark_from_static_string("g-libqblock-error-quark");
+}
+#endif
diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
index e69de29..20504ea 100644
--- a/libqblock/libqblock-types.h
+++ b/libqblock/libqblock-types.h
@@ -0,0 +1,245 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef LIBQBLOCK_TYPES_H
+#define LIBQBLOCK_TYPES_H
+
+#include 
+#include 
+#include 
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#ifdef LIBQB_BUILD
+#define LIBQB_DLL_PUBLIC __attribute__((__visibility__("default")))
+#else
+#define LIBQB_DLL_PUBLIC
+#endif
+#endif
+
+/* this lib

[Qemu-devel] [PATCH V16 0/9] libqblock qemu block layer library

2013-01-28 Thread Wenchao Xia
  These patches introduce libqblock API, make subdir-libqblock and make
check-libqblock could build this library.
Functionalities:
 1 create a new image.
 2 sync access of an image.
 3 basic image information retrieving such as backing file.
 4 detect if a sector is allocated in an image.
Supported Formats:
 ALL using file protocols.

  Patch 1 to 3 prepares qemu to accept libqblock.

v2:
  Insert reserved bytes into union.
  Use uint64_t instead of size_t, offset.
  Use const char * in filename pointer.
  Initialization function removed and it was automatically executed when
library is loaded.
  Added compile flag visibility=hidden, to avoid name space pollution.
  Structure naming style changed.
  Using byte unit instead of sector for every API.
  Added a member in image static information structure, to report logical
sector size, which is always 512 now.
  Read and write API can take request not aligned to 512 now. It returns the
byte number that have succeed in operation, but now either negative value
or the number requested would be returned, because qemu block sync I/O API
would not return such number.
  Typo fix due to comments and improved documents.

v3:
  Removed the code about OOM error, introduced GError.
  Used a table to map from string to enum types about format.
  Use typedef for every structure.
  Improved the gcc compiler macro to warn if gcc was not used.
  Global variable name changed with prefix libqb_.
  The struct QBlockStaticInfo was changed to folder full format related
information inside, and a new member with pointers pointing to the mostly used
members, such as backing file, virt size, was added. This would allow the user
to get full information about how it is created in the future.
  Each patch in the serial can work with qemu now.
  Typo fixes.

v4:
  Renamed QBroker to QBlockContext.
  Removed tool objs out of libqblock.
  Added a check in initialization about structure size for ABI.
  Added a new helper API to duplicate protocol information, helps to open files
in a backing file chain.
  Check-libqblock will not rebuild libqblock every time now.
  Test case file renamed to "libqblock-[FMT].c".
  Test use gtest framework now.
  Test do random creation of test file now, added check for information API in
it.
  Test do random sync io instead of fixed offset io now.
  Test accept one parameter about where to place the test image, now it is
./tests/libqblock/test_images.

v5:
  Makefile of libqblock was adjusted to be similar as libcacard, added spec
file and install section.
  Removed warning when GCC was not found.
  Structure names were changed to better ones.
  Removed the union typedef that contain reserved bytes to reduce the folder
depth.
  Some format related enum options was changed to better name.
  Added accessors about image static information, hide indirect accessing
member detail in the structure.
  Test Makefile do not create diretory now, test case create it themself.
  Test build system do not use libtool now, and removed qtest-obj-y in its
dependency, make check will automatically execute test anyway now.
  Removed "ifeq ($(LIBTOOL),)" in Makefile.

v6:
  Remove address pointer member in image static info structure.

v7:
  Support out of tree building.

v8:
  Fix a bug in out of tree building.

v9:
  Rebase and splitted out small fix patch for qemu.

v10:
  Rebased to upstream, adjusted libqblock build system according to Paolo's
comments.

v11:
  Adjusting code in patch 4 to 7, details are in the child patch's commit
message.

v12:
  Split a patch to add a function in stubs, other change are in patch 4 to 7
commit messages.

v13:
  Moved another function into stubs, added xml rule in tests/makefile, little
changes in patch 4, 6, 7.

v14:
  all: Rebased.
  1/10, 2/10: automatically call subdir's clean command if subdir's Makefile
added $SUBDIR_CLEAN_RULES, so tests/Makefile do not need to be always included,
libqblock's rule can also use it.
  3/10: seperated patch for configure support, modified as libcacard's style.
  4/10: modifed as libcacard's rule.
  5/10: seperated patch, also changed a bit to be a mirror as libcacard's rule.
  8/10: use bdrv_pread/bdrv_pwrite, instead of handling the buf allignment by
libqblock itself. Removed libqblock-aio.c because most function are in
block-obj-y now.
  9/10: seperated patch, use LINK instead of custom LT_LINK rule, and now
libqblock.la is a dependence in the link rule of test program, to make
LINK invoke libtool.

v15:
  1/9: merged from 1/10, 2/10 of previous version, and use dependce of "clean"
in sub Makefile instead of a intermedia variable.
  2/9: drop $TOOLS adding in libqblock's Makefile, the rule is added in "all".
  3/9: drop libqblock-y in Makefile.objs, directly add them in libqblock's
Makfile.
  6/9: use __visibility__ in special public marking macro, change macro name
to LIBQB_DLL_PUBLIC to avoid confilict in name space, use sizeof(uint64_t)
instead of magic number 8 in reserved member, spelling fix. Da

[Qemu-devel] [PATCH 34/37] target-unicore32: Use type_register() instead of type_register_static()

2013-01-28 Thread Andreas Färber
According to its documentation, type_register_static()'s TypeInfo
argument should exist for the life type of the type.
Therefore use type_register() when registering the list of CPU subtypes.

No functional change with the current implementation.

Cf. 918fd0839eeafc83bd4984364321a947d29041fe for arm.

Signed-off-by: Andreas Färber 
---
 target-unicore32/cpu.c |2 +-
 1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index 6735b25..c120440 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -111,7 +111,7 @@ static void uc32_register_cpu_type(const UniCore32CPUInfo 
*info)
 .instance_init = info->instance_init,
 };
 
-type_register_static(&type_info);
+type_register(&type_info);
 }
 
 static const TypeInfo uc32_cpu_type_info = {
-- 
1.7.10.4




[Qemu-devel] [PATCH 37/37] kvm: Pass CPUState to kvm_on_sigbus_vcpu()

2013-01-28 Thread Andreas Färber
Since commit 20d695a9254c1b086a456d3b79a3c311236643ba (kvm: Pass
CPUState to kvm_arch_*) CPUArchState is no longer needed.

Allows to change qemu_kvm_eat_signals() argument as well.

Signed-off-by: Andreas Färber 
Reviewed-by: Gleb Natapov 
---
 cpus.c   |8 
 include/sysemu/kvm.h |2 +-
 kvm-all.c|3 +--
 kvm-stub.c   |2 +-
 4 Dateien geändert, 7 Zeilen hinzugefügt(+), 8 Zeilen entfernt(-)

diff --git a/cpus.c b/cpus.c
index a4390c3..41779eb 100644
--- a/cpus.c
+++ b/cpus.c
@@ -517,7 +517,7 @@ static void qemu_init_sigbus(void)
 prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
 }
 
-static void qemu_kvm_eat_signals(CPUArchState *env)
+static void qemu_kvm_eat_signals(CPUState *cpu)
 {
 struct timespec ts = { 0, 0 };
 siginfo_t siginfo;
@@ -538,7 +538,7 @@ static void qemu_kvm_eat_signals(CPUArchState *env)
 
 switch (r) {
 case SIGBUS:
-if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
+if (kvm_on_sigbus_vcpu(cpu, siginfo.si_code, siginfo.si_addr)) {
 sigbus_reraise();
 }
 break;
@@ -560,7 +560,7 @@ static void qemu_init_sigbus(void)
 {
 }
 
-static void qemu_kvm_eat_signals(CPUArchState *env)
+static void qemu_kvm_eat_signals(CPUState *cpu)
 {
 }
 #endif /* !CONFIG_LINUX */
@@ -727,7 +727,7 @@ static void qemu_kvm_wait_io_event(CPUArchState *env)
 qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
 }
 
-qemu_kvm_eat_signals(env);
+qemu_kvm_eat_signals(cpu);
 qemu_wait_io_event_common(cpu);
 }
 
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 384ee66..6e6dfb3 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -159,7 +159,7 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned long 
reinject_trap);
 int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset);
 #endif
 
-int kvm_on_sigbus_vcpu(CPUArchState *env, int code, void *addr);
+int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
 int kvm_on_sigbus(int code, void *addr);
 
 /* internal API */
diff --git a/kvm-all.c b/kvm-all.c
index 363a358..04ec2d5 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2026,9 +2026,8 @@ int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, 
uint16_t val, bool assign)
 return 0;
 }
 
-int kvm_on_sigbus_vcpu(CPUArchState *env, int code, void *addr)
+int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 return kvm_arch_on_sigbus_vcpu(cpu, code, addr);
 }
 
diff --git a/kvm-stub.c b/kvm-stub.c
index 47f8dca..760aadc 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -112,7 +112,7 @@ int kvm_set_ioeventfd_mmio(int fd, uint32_t adr, uint32_t 
val, bool assign, uint
 return -ENOSYS;
 }
 
-int kvm_on_sigbus_vcpu(CPUArchState *env, int code, void *addr)
+int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
 {
 return 1;
 }
-- 
1.7.10.4




Re: [Qemu-devel] [RFC] qemu snapshot enchancement

2013-01-28 Thread Wenchao Xia

于 2013-1-28 21:00, Stefan Hajnoczi 写道:

On Fri, Jan 25, 2013 at 05:16:46PM +0800, Wenchao Xia wrote:

于 2013-1-24 17:47, Stefan Hajnoczi 写道:



Case 3:

  * What does "blank data" mean?  Besides that the use case
makes sense.


   Will remove the words.


  * When discussing this use case in the past it was suggested that the
guest doesn't need to be paused during the LVM snapshot.  Instead the
QEMU block layer might be able to queue I/O requests, allowing the
guest to run.


   That is a good idea, but seems need more work(event, block layer...),
hope it can be added as an enchancement of this case. Now let the
dedicated storage software/hardware take the job by pausing for a while
(<200ms?)


Yes, allowing the guest to continue but queuing I/O will require extra
block layer work and maybe a QMP command.  There is a also a risk: if
the snapshot takes too long to complete, the guest may notice that its
I/O request are taking a long time.  It may decide that they have timed
out and report an error to the application or in the message logs.

In the beginning it's easier to pause the VM but let's keep queuing I/O
in mind so it can be added later, if necessary.


   Yep, the code should leave a room for queuing.

   I have updated the wiki, which added the step details of the cases
. Cases 3 are fixed, which have best performance in qemu management
type. But I am not sure if it is workable in theory to export base
data of an qcow2 image having internal snapshot, what do you think
of it?


Yes, it is theoretically possible to access snapshot data while the
guest is running.

Open the qcow2 read-only and use bdrv_snapshot_load_tmp() to activate
the snapshot without modifying the qcow2 file on disk.  This is pretty
easy to implement today by adding options to qemu-nbd or the in-process
NBD server QMP commands.

Stefan


  Hi, Stefan, thank u for the information. Still I want to show more
about the steps needed in incremental backup:
1 vm have disk.qcow2.
2 take internal snapshot snap1.
3 export snap1 as base to incremental backup server.
4 take internal snapshot snap2.
5 export snap2 as delta to server, note snap2 must be delta data with
snap1, not full data.
6 delete snap1.
repeat 4-6...

the VM must keeps running.

  It seems in step 3, base can be load by bdrv_snapshot_load_tmp(), but 
a problem that disk's top content can't be used by VM at that time.

and in step 5, may need export the delta data, not the whole disk
data. Step 6 need make sure it is quick enough in sync API type.
  I am a bit worried if it is totally theoretically OK, may need
to check it before trying to code.




--
Best Regards

Wenchao Xia




[Qemu-devel] [PATCH 31/37] target-openrisc: Catch attempt to instantiate abstract type in cpu_init()

2013-01-28 Thread Andreas Färber
There is no abstract OpenRISCCPU yet, but that seems a bug of its own.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Andreas Färber 
---
 target-openrisc/cpu.c |3 ++-
 1 Datei geändert, 2 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index e23100f..adc03ef 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -98,7 +98,8 @@ static ObjectClass *openrisc_cpu_class_by_name(const char 
*cpu_model)
 }
 
 oc = object_class_by_name(cpu_model);
-if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU)) {
+if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU) ||
+   object_class_is_abstract(oc))) {
 return NULL;
 }
 return oc;
-- 
1.7.10.4




Re: [Qemu-devel] [RFC] qemu snapshot enchancement

2013-01-28 Thread Wenchao Xia

于 2013-1-28 21:38, Dietmar Maurer 写道:

If you've been using it for 4 years then it was without dm-thin, which is a new
snapshot mechanism that solves limitations of classic LVM snapshot
volumes.  So if you're referring to inefficient LVM snapshots then that should
be solvable now.


Are you sure this work on shared iSCSI devices (I have my doubts)?

Besides, we use RHEL6.3 kernel, and AFAIK dm-thin is still not marked stable 
there.


Or is LVM a pain for other reasons?


a.) it only works on LVM (new solution works on any storage type)
b.) You need free space on the VG (almost every user configures LVM without 
leaving
any free space on the VG).
c.) you need to specify snapshot size in advance
d.) performance is bad on writes.

The new solution work perfectly on all storage types, works on shared storage, 
and
does not need any free space on the source storage.




  The solution seems OK in improving the performance, I just wondering
if it is possible to put it in lower level component, not qemu? It will
make qemu block layer more complicate, and since it can ignore the
format so it is more likely a storage dedicated function, so could
u check if it can be offloaded from qemu?

--
Best Regards

Wenchao Xia




[Qemu-devel] [PATCH 36/37] cpu: Unconditionalize CPUState fields

2013-01-28 Thread Andreas Färber
Commits fc8c5b8c41ee5ba69d7a2be63b02a08c7b0b155b (Makefile.user: Define
CONFIG_USER_ONLY for libuser/) and
dd83b06ae61cfa2dc4381ab49f365bd0995fc930 (qom: Introduce CPU class)
specifically prepared the qom/cpu.c file to be compiled differently for
softmmu and *-user. This broke as part of build system refactorings
while CPU patches were in flight, adding conditional fields
kvm_fd (8737c51c0444f832c4e97d7eb7540eae457e08e4) and
kvm_vcpu_dirty (20d695a9254c1b086a456d3b79a3c311236643ba) for softmmu.

linux-user and bsd-user would therefore get a CPUState type with
instance_size ~8 bytes longer than expected.
Fix this by unconditionally having the fields in CPUState.

In practice, target-specific CPU types' instance_size would compensate
this, and upstream qom/cpu.c does not yet touch any affected field.

Signed-off-by: Andreas Färber 
Reviewed-by: Paolo Bonzini 
---
 include/qom/cpu.h |2 --
 1 Datei geändert, 2 Zeilen entfernt(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 8097692..46f2247 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -93,10 +93,8 @@ struct CPUState {
 bool stop;
 bool stopped;
 
-#if !defined(CONFIG_USER_ONLY)
 int kvm_fd;
 bool kvm_vcpu_dirty;
-#endif
 struct KVMState *kvm_state;
 struct kvm_run *kvm_run;
 
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH V11 3/4] Use QemuOpts support in block layer

2013-01-28 Thread Dong Xu Wang
于 2013-1-29 1:41, Markus Armbruster 写道:
> Dong Xu Wang  writes:
> 
>> Markus Armbruster  writes:
>>> Dong Xu Wang  writes:
>>>
 This patch will use QemuOpts related functions in block layer, add
 a member bdrv_create_options to BlockDriver struct, it will return
 a QemuOptsList pointer, which includes the image format's create
 options.

 And create options's primary consumer is block creating related functions,
 so modify them together.


 Signed-off-by: Dong Xu Wang 
 ---
 v10->v11)
 1) qed.h move QED_DEFAULT_CLUSTER_SIZE from enum to macro, or
 qemu_opts_print produce un-expanded cluster_size.
 2) In qcow2.c and qcow.c, bdrv_create_file(filename, NULL), NULL -> opts,
 or while using protocol, there will be an error.

 v8->v9)
 1) add qemu_ prefix to gluster_create_opts.
 2) fix bug: bdrv_gluster_unix and bdrv_gluster_rdma should also be
  converted.

 v7->v8)
 1) rebase to upstream source tree.
 2) add gluster.c, raw-win32.c, and rbd.c.

 v6->v7:
 1) use osdep.h:stringify(), not redefining new macro.
 2) preserve TODO comment.
 3) fix typo. BLOCK_OPT_ENCRYPT->BLOCK_OPT_STATIC.
 4) initialize disk_type even when opts is NULL.

 v5->v6:
 1) judge if opts == NULL in block layer create functions.
 2) use bdrv_create_file(filename, NULL) in qcow_create and cow_create 
 funtion.
 3) made more readable while using qemu_opt_get_number.


block.c   |  91 
block/cow.c   |  46 ++---
block/gluster.c   |  37 +-
block/qcow.c  |  60 
block/qcow2.c | 171 
 +++---
block/qed.c   |  86 +++
block/qed.h   |   2 +-
block/raw-posix.c |  59 
block/raw-win32.c |  30 
block/raw.c   |  30 
block/rbd.c   |  62 -
block/sheepdog.c  |  75 ++--
block/vdi.c   |  69 +--
block/vmdk.c  |  74 ++--
block/vpc.c   |  67 +-
block/vvfat.c |  11 +--
include/block/block.h |   4 +-
include/block/block_int.h |   6 +-
qemu-img.c|  61 -
19 files changed, 519 insertions(+), 522 deletions(-)

 diff --git a/block.c b/block.c
 index 6fa7c90..56e4613 100644
 --- a/block.c
 +++ b/block.c
 @@ -357,7 +357,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char 
 *format_name)
typedef struct CreateCo {
BlockDriver *drv;
char *filename;
 -QEMUOptionParameter *options;
 +QemuOpts *opts;
int ret;
} CreateCo;

 @@ -366,11 +366,11 @@ static void coroutine_fn bdrv_create_co_entry(void 
 *opaque)
CreateCo *cco = opaque;
assert(cco->drv);

 -cco->ret = cco->drv->bdrv_create(cco->filename, cco->options);
 +cco->ret = cco->drv->bdrv_create(cco->filename, cco->opts);
}

int bdrv_create(BlockDriver *drv, const char* filename,
 -QEMUOptionParameter *options)
 +QemuOpts *opts)
{
int ret;

 @@ -378,7 +378,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
CreateCo cco = {
.drv = drv,
.filename = g_strdup(filename),
 -.options = options,
 +.opts = opts,
.ret = NOT_DONE,
};

 @@ -405,7 +405,7 @@ out:
return ret;
}

 -int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
 +int bdrv_create_file(const char *filename, QemuOpts *opts)
{
BlockDriver *drv;

 @@ -414,7 +414,7 @@ int bdrv_create_file(const char* filename, 
 QEMUOptionParameter *options)
return -ENOENT;
}

 -return bdrv_create(drv, filename, options);
 +return bdrv_create(drv, filename, opts);
}

/*
 @@ -794,7 +794,7 @@ int bdrv_open(BlockDriverState *bs, const char 
 *filename, int flags,
int64_t total_size;
int is_protocol = 0;
BlockDriver *bdrv_qcow2;
 -QEMUOptionParameter *options;
 +QemuOpts *opts;
char backing_filename[PATH_MAX];

/* if snapshot, we create a temporary backing file and open it
 @@ -827,17 +827,16 @@ int bdrv_open(BlockDriverState *bs, const char 
 *filename, int flags,
return -errno;
  

[Qemu-devel] qemu-1.2.2 black screen when the winxp guest change the resolution

2013-01-28 Thread zhou link
hello,  i  reproduce the problem:

when i use qemu-1.2.2 on  centos6.3  with spice-0.12.2,  run winxp guest
like that:

qemu-system-x86_64 -localtime --enable-kvm -spice
port=,disable-ticketing -m 2048 -smp 2 -vga qxl -drive
file=.xp32_full_stable.qcow2

the win32 xp  has install  the spice-guest-tool-0.3  and  the qxl driver
works well.

when i  change the guest 's screen resolution(1024*768 to 1280*800),  the
screen lost reponse  and black ,  so   i have to kill  the
qemu-system-x86_64 process.

but when i  restart the guest os again,  i  found the screen has change
to  1280*800, yes the new one.

then i run the guest without qxl support like that:

qemu-system-x86_64 -localtime --enable-kvm -spice
port=,disable-ticketing -m 2048 -smp 2 -drive
file=.xp32_full_stable.qcow2

the problem doesn't occur again, change screen resolution ok,  though guest
supports vga only.


then  i  install the  qemu-1.3.0,  and  run the same img file just like
above with the same command:

qemu-system-x86_64 -localtime --enable-kvm -spice
port=,disable-ticketing -m 2048 -smp 2 -vga qxl -drive
file=.xp32_full_stable.qcow2

well   the qemu-1.3.0  works smooth,  and the winxp guest  changes the
 screen resolution successfull.

maybe  the qemu-1.2.2's qxl support has a bug ?


if anyone is intersting with the problem,  i can supply more info,  like
logs or qcows img(but it is a little big guy),  thx very much.


Re: [Qemu-devel] [Qemu-ppc] [PATCH 3/6] target-ppc: Synchronize more SPRs to KVM using ONE_REG interface

2013-01-28 Thread David Gibson
On Fri, Jan 25, 2013 at 12:24:06PM +0100, Alexander Graf wrote:
> On 25.01.2013, at 03:39, David Gibson wrote:
> > On Thu, Jan 24, 2013 at 05:32:42PM +0100, Alexander Graf wrote:
[snip]
> >>> +static void kvm_get_one_spr(CPUState *cs, uint64_t id, int spr)
> >>> +{
> >>> +PowerPCCPU *cpu = POWERPC_CPU(cs);
> >>> +CPUPPCState *env = &cpu->env;
> >>> +union {
> >>> +uint32_t u32;
> >>> +uint64_t u64;
> >>> +} val;
> >>> +struct kvm_one_reg reg = {
> >>> +.id = id,
> >>> +.addr = (uintptr_t) &val,
> >>> +};
> >>> +int ret;
> >>> +
> >>> +ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
> >>> +if (ret != 0) {
> >>> +fprintf(stderr, "Warning: Unable to retrieve SPR %d from KVM: 
> >>> %s\n",
> >>> +spr, strerror(errno));
> >> 
> >> Any way you could make this a WARN_ONCE style message?
> > 
> > Uh.. I guess.  Afaict, qemu doesn't have any infrastructure for that,
> > so I'd have to roll my own.
> 
> As I stated in a later patch review, I think it makes sense to just
> not print anything by default.
> 
> Usually, you would do
> 
> if (cap_foo) {
> get_one_spr(...);
> }
> 
> right? With one_reg I consciously omitted caps for every register,
> because you can just as well read and push the reg itself and thus
> know whether it works.
> 
> So if you translate that to the above code, it would mean
> 
>get_one_spr(...);
> 
> without error message would be semantically identical to the first
> version.
> 
> It would however make sense to have a debug print version in case
> you want to know why something goes wrong. It might also make sense
> to have an initial get_one_spr() or so for a FULL register push to
> warn the user that live migration will not work on his machine.

So, I realised I need to rework this substantially anyway.  As you
say, I need to not attempt to sync these various SPRs for BookE.  But
more generally, different CPUs will have a different set of supported
SPRs.

I have a draft in the works that adds a ONE_REG id code to the
ppc_spr_t structure, which is (optionally) initialized by
spr_register() calls in the cpu initialization.  Then the kvm call
goes through the SPR table and just syncs all those with registered
ONE_REG ids.  I'm at linux.conf.au this week, so I don't expect to
finish that off until next week.  There are some uglies in that that I
still need to see if can be resolved yet.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: Digital signature


[Qemu-devel] [PATCH v3 4/5] sheepdog: use inet_connect to simplify connect code

2013-01-28 Thread MORITA Kazutaka
This uses the form ":" for the representation of the
sheepdog server to use inet_connect.

Signed-off-by: MORITA Kazutaka 
---
 block/sheepdog.c |  111 ++---
 1 files changed, 30 insertions(+), 81 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 646c1ff..f35de36 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -22,7 +22,7 @@
 #define SD_PROTO_VER 0x01
 
 #define SD_DEFAULT_ADDR "localhost"
-#define SD_DEFAULT_PORT "7000"
+#define SD_DEFAULT_PORT 7000
 
 #define SD_OP_CREATE_AND_WRITE_OBJ  0x01
 #define SD_OP_READ_OBJ   0x02
@@ -298,8 +298,7 @@ typedef struct BDRVSheepdogState {
 bool is_snapshot;
 uint32_t cache_flags;
 
-char *addr;
-char *port;
+char *host_spec;
 int fd;
 
 CoMutex lock;
@@ -447,56 +446,18 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, 
QEMUIOVector *qiov,
 return acb;
 }
 
-static int connect_to_sdog(const char *addr, const char *port)
+static int connect_to_sdog(BDRVSheepdogState *s)
 {
-char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
-int fd, ret;
-struct addrinfo hints, *res, *res0;
-
-if (!addr) {
-addr = SD_DEFAULT_ADDR;
-port = SD_DEFAULT_PORT;
-}
+int fd;
+Error *err = NULL;
 
-memset(&hints, 0, sizeof(hints));
-hints.ai_socktype = SOCK_STREAM;
+fd = inet_connect(s->host_spec, &err);
 
-ret = getaddrinfo(addr, port, &hints, &res0);
-if (ret) {
-error_report("unable to get address info %s, %s",
- addr, strerror(errno));
-return -errno;
+if (err != NULL) {
+qerror_report_err(err);
+error_free(err);
 }
 
-for (res = res0; res; res = res->ai_next) {
-ret = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
-  sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-if (ret) {
-continue;
-}
-
-fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
-if (fd < 0) {
-continue;
-}
-
-reconnect:
-ret = connect(fd, res->ai_addr, res->ai_addrlen);
-if (ret < 0) {
-if (errno == EINTR) {
-goto reconnect;
-}
-close(fd);
-break;
-}
-
-dprintf("connected to %s:%s\n", addr, port);
-goto success;
-}
-fd = -errno;
-error_report("failed connect to %s:%s", addr, port);
-success:
-freeaddrinfo(res0);
 return fd;
 }
 
@@ -798,9 +759,8 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 {
 int ret, fd;
 
-fd = connect_to_sdog(s->addr, s->port);
+fd = connect_to_sdog(s);
 if (fd < 0) {
-error_report("%s", strerror(errno));
 return fd;
 }
 
@@ -836,12 +796,8 @@ static int sd_parse_uri(BDRVSheepdogState *s, const char 
*filename,
 pstrcpy(vdi, SD_MAX_VDI_LEN, uri->path + 1);
 
 /* sheepdog[+tcp]://[host:port]/vdiname */
-s->addr = g_strdup(uri->server ?: SD_DEFAULT_ADDR);
-if (uri->port) {
-s->port = g_strdup_printf("%d", uri->port);
-} else {
-s->port = g_strdup(SD_DEFAULT_PORT);
-}
+s->host_spec = g_strdup_printf("%s:%d", uri->server ?: SD_DEFAULT_ADDR,
+   uri->port ?: SD_DEFAULT_PORT);
 
 /* snapshot tag */
 if (uri->fragment) {
@@ -935,7 +891,7 @@ static int find_vdi_name(BDRVSheepdogState *s, char 
*filename, uint32_t snapid,
 unsigned int wlen, rlen = 0;
 char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
 
-fd = connect_to_sdog(s->addr, s->port);
+fd = connect_to_sdog(s);
 if (fd < 0) {
 return fd;
 }
@@ -1178,9 +1134,8 @@ static int sd_open(BlockDriverState *bs, const char 
*filename, int flags)
 s->is_snapshot = true;
 }
 
-fd = connect_to_sdog(s->addr, s->port);
+fd = connect_to_sdog(s);
 if (fd < 0) {
-error_report("failed to connect");
 ret = fd;
 goto out;
 }
@@ -1213,9 +1168,8 @@ out:
 return ret;
 }
 
-static int do_sd_create(char *filename, int64_t vdi_size,
-uint32_t base_vid, uint32_t *vdi_id, int snapshot,
-const char *addr, const char *port)
+static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size,
+uint32_t base_vid, uint32_t *vdi_id, int snapshot)
 {
 SheepdogVdiReq hdr;
 SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
@@ -1223,7 +1177,7 @@ static int do_sd_create(char *filename, int64_t vdi_size,
 unsigned int wlen, rlen = 0;
 char buf[SD_MAX_VDI_LEN];
 
-fd = connect_to_sdog(addr, port);
+fd = connect_to_sdog(s);
 if (fd < 0) {
 return fd;
 }
@@ -1390,7 +1344,7 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options)
 bdrv_delete(bs);
 }
 
-ret = do_sd_create(vdi, vdi_size, base_vid, &vid, 0, s->addr, s->port);
+ret = do_sd_create(s, vd

[Qemu-devel] [PATCH v3 0/5] sheepdog: unix domain socket support

2013-01-28 Thread MORITA Kazutaka
This series makes sheepdog accept URI syntax, and adds a unix domain
socket support for a connection between qemu and local sheepdog server
based on the syntax.

Changes from v2:
 - fix coding style in tcp_connect
 - accept URI syntax

Changes from v1:
 - split patch for easy review
 - move set_nodelay to lib/osdep.c
 - remove redundant error checks
 - add a bit more explanation to qemu-options.hx

MORITA Kazutaka (5):
  slirp/tcp_subr.c: fix coding style in tcp_connect
  move socket_set_nodelay to osdep.c
  sheepdog: accept URIs
  sheepdog: use inet_connect to simplify connect code
  sheepdog: add support for connecting to unix domain socket

 block/sheepdog.c   |  315 +---
 gdbstub.c  |5 +-
 include/qemu/sockets.h |1 +
 qemu-char.c|6 -
 qemu-doc.texi  |   22 ++--
 qemu-options.hx|   18 +--
 slirp/tcp_subr.c   |  139 +++---
 util/osdep.c   |6 +
 8 files changed, 290 insertions(+), 222 deletions(-)

-- 
1.7.2.5




Re: [Qemu-devel] [PATCH 0/3] accel:some cleanup work for vm accelerator

2013-01-28 Thread li guang
ping ...

在 2013-01-24四的 13:03 +0800,liguang写道:
> do some cleanup work fo vm accelerator
> 
> patch 1/3: skip init accelerator if it's not available
> patch 2/3: correct error message when fail to init kvm
> patch 3/3: change {xen,kvm,tcg,qtest}_allowed from int to bool
> 
>  hw/xen.h   |4 +-
>  include/sysemu/kvm.h   |2 +-
>  include/sysemu/qtest.h |2 +-
>  qtest.c|2 +-
>  vl.c   |   40 ++--
>  5 files changed, 26 insertions(+), 24 deletions(-)
> 





[Qemu-devel] [PATCH v3 5/5] sheepdog: add support for connecting to unix domain socket

2013-01-28 Thread MORITA Kazutaka
This patch adds support for a unix domain socket for a connection
between qemu and local sheepdog server.  You can use the unix domain
socket with the following syntax:

 $ qemu sheepdog+unix:///?[#snapid]

Signed-off-by: MORITA Kazutaka 
---
 block/sheepdog.c |   82 ++
 qemu-doc.texi|6 
 qemu-options.hx  |2 +-
 3 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f35de36..eb7713a 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -299,6 +299,7 @@ typedef struct BDRVSheepdogState {
 uint32_t cache_flags;
 
 char *host_spec;
+bool is_unix;
 int fd;
 
 CoMutex lock;
@@ -451,7 +452,18 @@ static int connect_to_sdog(BDRVSheepdogState *s)
 int fd;
 Error *err = NULL;
 
-fd = inet_connect(s->host_spec, &err);
+if (s->is_unix) {
+fd = unix_connect(s->host_spec, &err);
+} else {
+fd = inet_connect(s->host_spec, &err);
+
+if (err == NULL) {
+int ret = socket_set_nodelay(fd);
+if (ret < 0) {
+error_report("%s", strerror(errno));
+}
+}
+}
 
 if (err != NULL) {
 qerror_report_err(err);
@@ -757,7 +769,7 @@ static int aio_flush_request(void *opaque)
  */
 static int get_sheep_fd(BDRVSheepdogState *s)
 {
-int ret, fd;
+int fd;
 
 fd = connect_to_sdog(s);
 if (fd < 0) {
@@ -766,13 +778,6 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 
 socket_set_nonblock(fd);
 
-ret = socket_set_nodelay(fd);
-if (ret) {
-error_report("%s", strerror(errno));
-closesocket(fd);
-return -errno;
-}
-
 qemu_aio_set_fd_handler(fd, co_read_response, NULL, aio_flush_request, s);
 return fd;
 }
@@ -789,15 +794,42 @@ static int sd_parse_uri(BDRVSheepdogState *s, const char 
*filename,
 return -EINVAL;
 }
 
+/* transport */
+if (!strcmp(uri->scheme, "sheepdog")) {
+s->is_unix = false;
+} else if (!strcmp(uri->scheme, "sheepdog+tcp")) {
+s->is_unix = false;
+} else if (!strcmp(uri->scheme, "sheepdog+unix")) {
+s->is_unix = true;
+} else {
+ret = -EINVAL;
+goto out;
+}
+
 if (uri->path == NULL || !strcmp(uri->path, "/")) {
 ret = -EINVAL;
 goto out;
 }
 pstrcpy(vdi, SD_MAX_VDI_LEN, uri->path + 1);
 
-/* sheepdog[+tcp]://[host:port]/vdiname */
-s->host_spec = g_strdup_printf("%s:%d", uri->server ?: SD_DEFAULT_ADDR,
-   uri->port ?: SD_DEFAULT_PORT);
+qp = query_params_parse(uri->query);
+if (qp->n > 1 || (s->is_unix && !qp->n) || (!s->is_unix && qp->n)) {
+ret = -EINVAL;
+goto out;
+}
+
+if (s->is_unix) {
+/* sheepdog+unix:///vdiname?socket=path */
+if (uri->server || uri->port || strcmp(qp->p[0].name, "socket")) {
+ret = -EINVAL;
+goto out;
+}
+s->host_spec = g_strdup(qp->p[0].value);
+} else {
+/* sheepdog[+tcp]://[host:port]/vdiname */
+s->host_spec = g_strdup_printf("%s:%d", uri->server ?: SD_DEFAULT_ADDR,
+   uri->port ?: SD_DEFAULT_PORT);
+}
 
 /* snapshot tag */
 if (uri->fragment) {
@@ -2097,9 +2129,35 @@ static BlockDriver bdrv_sheepdog_tcp = {
 .create_options = sd_create_options,
 };
 
+static BlockDriver bdrv_sheepdog_unix = {
+.format_name= "sheepdog",
+.protocol_name  = "sheepdog+unix",
+.instance_size  = sizeof(BDRVSheepdogState),
+.bdrv_file_open = sd_open,
+.bdrv_close = sd_close,
+.bdrv_create= sd_create,
+.bdrv_getlength = sd_getlength,
+.bdrv_truncate  = sd_truncate,
+
+.bdrv_co_readv  = sd_co_readv,
+.bdrv_co_writev = sd_co_writev,
+.bdrv_co_flush_to_disk  = sd_co_flush_to_disk,
+
+.bdrv_snapshot_create   = sd_snapshot_create,
+.bdrv_snapshot_goto = sd_snapshot_goto,
+.bdrv_snapshot_delete   = sd_snapshot_delete,
+.bdrv_snapshot_list = sd_snapshot_list,
+
+.bdrv_save_vmstate  = sd_save_vmstate,
+.bdrv_load_vmstate  = sd_load_vmstate,
+
+.create_options = sd_create_options,
+};
+
 static void bdrv_sheepdog_init(void)
 {
 bdrv_register(&bdrv_sheepdog);
 bdrv_register(&bdrv_sheepdog_tcp);
+bdrv_register(&bdrv_sheepdog_unix);
 }
 block_init(bdrv_sheepdog_init);
diff --git a/qemu-doc.texi b/qemu-doc.texi
index d4eb5eb..9f41589 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -865,6 +865,12 @@ qemu-img create -b sheepdog:///@var{base}#@var{tag} 
sheepdog:///@var{image}
 where @var{base} is a image name of the source snapshot and @var{tag}
 is its tag name.
 
+You can use an unix socket instead of an inet socket:
+
+@example
+qemu-system-i386 sheepdog+unix:///@var{image}?socket=@var{path}
+@end example
+
 If the Sheepdog daemon doesn't run on the local host, you need to
 specify one of the Sheepdog servers to c

[Qemu-devel] [PATCH v3 3/5] sheepdog: accept URIs

2013-01-28 Thread MORITA Kazutaka
The URI syntax is consistent with the NBD and Gluster syntax.  The
syntax is

  sheepdog[+tcp]://[host:port]/vdiname[#snapid|#tag]

Signed-off-by: MORITA Kazutaka 
---
 block/sheepdog.c |  139 -
 qemu-doc.texi|   16 +++---
 qemu-options.hx  |   18 ++-
 3 files changed, 117 insertions(+), 56 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 9746037..646c1ff 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -13,6 +13,7 @@
  */
 
 #include "qemu-common.h"
+#include "qemu/uri.h"
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
 #include "block/block_int.h"
@@ -816,8 +817,52 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 return fd;
 }
 
+static int sd_parse_uri(BDRVSheepdogState *s, const char *filename,
+char *vdi, uint32_t *snapid, char *tag)
+{
+URI *uri;
+QueryParams *qp = NULL;
+int ret = 0;
+
+uri = uri_parse(filename);
+if (!uri) {
+return -EINVAL;
+}
+
+if (uri->path == NULL || !strcmp(uri->path, "/")) {
+ret = -EINVAL;
+goto out;
+}
+pstrcpy(vdi, SD_MAX_VDI_LEN, uri->path + 1);
+
+/* sheepdog[+tcp]://[host:port]/vdiname */
+s->addr = g_strdup(uri->server ?: SD_DEFAULT_ADDR);
+if (uri->port) {
+s->port = g_strdup_printf("%d", uri->port);
+} else {
+s->port = g_strdup(SD_DEFAULT_PORT);
+}
+
+/* snapshot tag */
+if (uri->fragment) {
+*snapid = strtoul(uri->fragment, NULL, 10);
+if (*snapid == 0) {
+pstrcpy(tag, SD_MAX_VDI_TAG_LEN, uri->fragment);
+}
+} else {
+*snapid = CURRENT_VDI_ID; /* search current vdi */
+}
+
+out:
+if (qp) {
+query_params_free(qp);
+}
+uri_free(uri);
+return ret;
+}
+
 /*
- * Parse a filename
+ * Parse a filename (old syntax)
  *
  * filename must be one of the following formats:
  *   1. [vdiname]
@@ -836,9 +881,11 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 static int parse_vdiname(BDRVSheepdogState *s, const char *filename,
  char *vdi, uint32_t *snapid, char *tag)
 {
-char *p, *q;
-int nr_sep;
+char *p, *q, *uri;
+const char *host_spec, *vdi_spec;
+int nr_sep, ret;
 
+strstart(filename, "sheepdog:", (const char **)&filename);
 p = q = g_strdup(filename);
 
 /* count the number of separators */
@@ -851,38 +898,32 @@ static int parse_vdiname(BDRVSheepdogState *s, const char 
*filename,
 }
 p = q;
 
-/* use the first two tokens as hostname and port number. */
+/* use the first two tokens as host_spec. */
 if (nr_sep >= 2) {
-s->addr = p;
+host_spec = p;
 p = strchr(p, ':');
-*p++ = '\0';
-
-s->port = p;
+p++;
 p = strchr(p, ':');
 *p++ = '\0';
 } else {
-s->addr = NULL;
-s->port = 0;
+host_spec = "";
 }
 
-pstrcpy(vdi, SD_MAX_VDI_LEN, p);
+vdi_spec = p;
 
-p = strchr(vdi, ':');
+p = strchr(vdi_spec, ':');
 if (p) {
-*p++ = '\0';
-*snapid = strtoul(p, NULL, 10);
-if (*snapid == 0) {
-pstrcpy(tag, SD_MAX_VDI_TAG_LEN, p);
-}
-} else {
-*snapid = CURRENT_VDI_ID; /* search current vdi */
+*p++ = '#';
 }
 
-if (s->addr == NULL) {
-g_free(q);
-}
+uri = g_strdup_printf("sheepdog://%s/%s", host_spec, vdi_spec);
 
-return 0;
+ret = sd_parse_uri(s, uri, vdi, snapid, tag);
+
+g_free(q);
+g_free(uri);
+
+return ret;
 }
 
 static int find_vdi_name(BDRVSheepdogState *s, char *filename, uint32_t snapid,
@@ -1097,16 +1138,19 @@ static int sd_open(BlockDriverState *bs, const char 
*filename, int flags)
 uint32_t snapid;
 char *buf = NULL;
 
-strstart(filename, "sheepdog:", (const char **)&filename);
-
 QLIST_INIT(&s->inflight_aio_head);
 QLIST_INIT(&s->pending_aio_head);
 s->fd = -1;
 
 memset(vdi, 0, sizeof(vdi));
 memset(tag, 0, sizeof(tag));
-if (parse_vdiname(s, filename, vdi, &snapid, tag) < 0) {
-ret = -EINVAL;
+
+if (strstr(filename, "://")) {
+ret = sd_parse_uri(s, filename, vdi, &snapid, tag);
+} else {
+ret = parse_vdiname(s, filename, vdi, &snapid, tag);
+}
+if (ret < 0) {
 goto out;
 }
 s->fd = get_sheep_fd(s);
@@ -1275,17 +1319,17 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options)
 char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
 uint32_t snapid;
 bool prealloc = false;
-const char *vdiname;
 
 s = g_malloc0(sizeof(BDRVSheepdogState));
 
-strstart(filename, "sheepdog:", &vdiname);
-
 memset(vdi, 0, sizeof(vdi));
 memset(tag, 0, sizeof(tag));
-if (parse_vdiname(s, vdiname, vdi, &snapid, tag) < 0) {
-error_report("invalid filename");
-ret = -EINVAL;
+if (strstr(filename, "://")) {
+ret = sd_parse_uri(s, fi

[Qemu-devel] [PATCH v3 1/5] slirp/tcp_subr.c: fix coding style in tcp_connect

2013-01-28 Thread MORITA Kazutaka
Fix coding style in tcp_connect before the next patch.

Signed-off-by: MORITA Kazutaka 
---
 slirp/tcp_subr.c |  140 --
 1 files changed, 72 insertions(+), 68 deletions(-)

diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 1542e43..317dc07 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -384,83 +384,87 @@ int tcp_fconnect(struct socket *so)
  * the time it gets to accept(), so... We simply accept
  * here and SYN the local-host.
  */
-void
-tcp_connect(struct socket *inso)
+void tcp_connect(struct socket *inso)
 {
-   Slirp *slirp = inso->slirp;
-   struct socket *so;
-   struct sockaddr_in addr;
-   socklen_t addrlen = sizeof(struct sockaddr_in);
-   struct tcpcb *tp;
-   int s, opt;
+Slirp *slirp = inso->slirp;
+struct socket *so;
+struct sockaddr_in addr;
+socklen_t addrlen = sizeof(struct sockaddr_in);
+struct tcpcb *tp;
+int s, opt;
 
-   DEBUG_CALL("tcp_connect");
-   DEBUG_ARG("inso = %lx", (long)inso);
+DEBUG_CALL("tcp_connect");
+DEBUG_ARG("inso = %lx", (long)inso);
 
-   /*
-* If it's an SS_ACCEPTONCE socket, no need to socreate()
-* another socket, just use the accept() socket.
-*/
-   if (inso->so_state & SS_FACCEPTONCE) {
-   /* FACCEPTONCE already have a tcpcb */
-   so = inso;
-   } else {
-   if ((so = socreate(slirp)) == NULL) {
-   /* If it failed, get rid of the pending connection */
-   closesocket(accept(inso->s,(struct sockaddr 
*)&addr,&addrlen));
-   return;
-   }
-   if (tcp_attach(so) < 0) {
-   free(so); /* NOT sofree */
-   return;
-   }
-   so->so_laddr = inso->so_laddr;
-   so->so_lport = inso->so_lport;
-   }
+/*
+ * If it's an SS_ACCEPTONCE socket, no need to socreate()
+ * another socket, just use the accept() socket.
+ */
+if (inso->so_state & SS_FACCEPTONCE) {
+/* FACCEPTONCE already have a tcpcb */
+so = inso;
+} else {
+so = socreate(slirp);
+if (so == NULL) {
+/* If it failed, get rid of the pending connection */
+closesocket(accept(inso->s, (struct sockaddr *)&addr, &addrlen));
+return;
+}
+if (tcp_attach(so) < 0) {
+free(so); /* NOT sofree */
+return;
+}
+so->so_laddr = inso->so_laddr;
+so->so_lport = inso->so_lport;
+}
 
-   (void) tcp_mss(sototcpcb(so), 0);
+tcp_mss(sototcpcb(so), 0);
 
-   if ((s = accept(inso->s,(struct sockaddr *)&addr,&addrlen)) < 0) {
-   tcp_close(sototcpcb(so)); /* This will sofree() as well */
-   return;
-   }
-   socket_set_nonblock(s);
-   opt = 1;
-   setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
-   opt = 1;
-   setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
-   opt = 1;
-   setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&opt,sizeof(int));
-
-   so->so_fport = addr.sin_port;
-   so->so_faddr = addr.sin_addr;
-   /* Translate connections from localhost to the real hostname */
-if (so->so_faddr.s_addr == 0 ||
-(so->so_faddr.s_addr & loopback_mask) ==
-(loopback_addr.s_addr & loopback_mask)) {
-so->so_faddr = slirp->vhost_addr;
-}
+s = accept(inso->s, (struct sockaddr *)&addr, &addrlen);
+if (s < 0) {
+tcp_close(sototcpcb(so)); /* This will sofree() as well */
+return;
+}
+socket_set_nonblock(s);
+opt = 1;
+setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
+opt = 1;
+setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
+opt = 1;
+setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(int));
+
+so->so_fport = addr.sin_port;
+so->so_faddr = addr.sin_addr;
+/* Translate connections from localhost to the real hostname */
+if (so->so_faddr.s_addr == 0 ||
+(so->so_faddr.s_addr & loopback_mask) ==
+(loopback_addr.s_addr & loopback_mask)) {
+so->so_faddr = slirp->vhost_addr;
+}
 
-   /* Close the accept() socket, set right state */
-   if (inso->so_state & SS_FACCEPTONCE) {
-   closesocket(so->s); /* If we only accept once, close the 
accept() socket */
-   so->so_state = SS_NOFDREF; /* Don't select it yet, even though 
we have an FD */
-  /* if it's not FACCEPTONCE, it's 
already NOFDREF */
-   }
-   so->s = s;
-   so->so_state |= SS_INCOMING;
+/* Close the accept() socket, set right state */
+if (inso->so_state & SS_FACCEPTONCE) {
+/* If we only accept once, close the accept() socket */
+closesocket(so->s);
+
+/* Don'

[Qemu-devel] [PATCH v3 2/5] move socket_set_nodelay to osdep.c

2013-01-28 Thread MORITA Kazutaka
Signed-off-by: MORITA Kazutaka 
---
 block/sheepdog.c   |   11 +--
 gdbstub.c  |5 ++---
 include/qemu/sockets.h |1 +
 qemu-char.c|6 --
 slirp/tcp_subr.c   |3 +--
 util/osdep.c   |6 ++
 6 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 3e49bb8..9746037 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -787,15 +787,6 @@ static int aio_flush_request(void *opaque)
 !QLIST_EMPTY(&s->pending_aio_head);
 }
 
-static int set_nodelay(int fd)
-{
-int ret, opt;
-
-opt = 1;
-ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt));
-return ret;
-}
-
 /*
  * Return a socket discriptor to read/write objects.
  *
@@ -814,7 +805,7 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 
 socket_set_nonblock(fd);
 
-ret = set_nodelay(fd);
+ret = socket_set_nodelay(fd);
 if (ret) {
 error_report("%s", strerror(errno));
 closesocket(fd);
diff --git a/gdbstub.c b/gdbstub.c
index 6cd26f1..4cc1812 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2837,7 +2837,7 @@ static void gdb_accept(void)
 GDBState *s;
 struct sockaddr_in sockaddr;
 socklen_t len;
-int val, fd;
+int fd;
 
 for(;;) {
 len = sizeof(sockaddr);
@@ -2854,8 +2854,7 @@ static void gdb_accept(void)
 }
 
 /* set short latency */
-val = 1;
-setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
+socket_set_nodelay(fd);
 
 s = g_malloc0(sizeof(GDBState));
 s->c_cpu = first_cpu;
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 803ae17..6125bf7 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -34,6 +34,7 @@ int inet_aton(const char *cp, struct in_addr *ia);
 int qemu_socket(int domain, int type, int protocol);
 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 int socket_set_cork(int fd, int v);
+int socket_set_nodelay(int fd);
 void socket_set_block(int fd);
 void socket_set_nonblock(int fd);
 int send_all(int fd, const void *buf, int len1);
diff --git a/qemu-char.c b/qemu-char.c
index 9ba0573..156164c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2365,12 +2365,6 @@ static void tcp_chr_telnet_init(int fd)
 send(fd, (char *)buf, 3, 0);
 }
 
-static void socket_set_nodelay(int fd)
-{
-int val = 1;
-setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
-}
-
 static int tcp_chr_add_client(CharDriverState *chr, int fd)
 {
 TCPCharDriver *s = chr->opaque;
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 317dc07..7b7ad60 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -430,8 +430,7 @@ void tcp_connect(struct socket *inso)
 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
 opt = 1;
 setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
-opt = 1;
-setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(int));
+socket_set_nodelay(s);
 
 so->so_fport = addr.sin_port;
 so->so_faddr = addr.sin_addr;
diff --git a/util/osdep.c b/util/osdep.c
index 5b51a03..c408261 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -63,6 +63,12 @@ int socket_set_cork(int fd, int v)
 #endif
 }
 
+int socket_set_nodelay(int fd)
+{
+int v = 1;
+return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
+}
+
 int qemu_madvise(void *addr, size_t len, int advice)
 {
 if (advice == QEMU_MADV_INVALID) {
-- 
1.7.2.5




Re: [Qemu-devel] [PATCH] vmdk: Allow selecting SCSI adapter in image creation

2013-01-28 Thread Othmar Pasteka
Hello,


On Mon, Jan 28, 2013 at 11:56:47PM +0100, Othmar Pasteka wrote:
> @@ -1453,6 +1454,7 @@ static int vmdk_create(const char *filename, 
> QEMUOptionParameter *options)
>  const char *desc_extent_line;
>  char parent_desc_line[BUF_SIZE] = "";
>  uint32_t parent_cid = 0x;
> +uint32_t number_heads = 16;
>  const char desc_template[] =
>  "# Disk DescriptorFile\n"
>  "version=1\n"

right after sending the patch I discovered this indentation bug.
I check with checkpatch before sending it, but it didn't complain
and it slipped on my side. Should I resend the patch with that fixed?

regards,
Othmar




[Qemu-devel] [PATCH] vmdk: Allow selecting SCSI adapter in image creation

2013-01-28 Thread Othmar Pasteka
Introduce a new option "adapter_type" when converting to vmdk images.
It can be one of the following: ide (default), buslogic, lsilogic
or legacyESX (according to the vmdk spec from vmware).

In case of a non-ide adapter, heads is set to 255 instead of the 16.
The latter is used for "ide".

Also see LP#545089

Signed-off-by: Othmar Pasteka 
---
 block/vmdk.c  |   31 ---
 include/block/block_int.h |1 +
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 19298c2..2a84e1d 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1442,6 +1442,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 int fd, idx = 0;
 char desc[BUF_SIZE];
 int64_t total_size = 0, filesize;
+const char *adapter_type = NULL;
 const char *backing_file = NULL;
 const char *fmt = NULL;
 int flags = 0;
@@ -1453,6 +1454,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 const char *desc_extent_line;
 char parent_desc_line[BUF_SIZE] = "";
 uint32_t parent_cid = 0x;
+uint32_t number_heads = 16;
 const char desc_template[] =
 "# Disk DescriptorFile\n"
 "version=1\n"
@@ -1469,9 +1471,9 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 "\n"
 "ddb.virtualHWVersion = \"%d\"\n"
 "ddb.geometry.cylinders = \"%" PRId64 "\"\n"
-"ddb.geometry.heads = \"16\"\n"
+"ddb.geometry.heads = \"%d\"\n"
 "ddb.geometry.sectors = \"63\"\n"
-"ddb.adapterType = \"ide\"\n";
+"ddb.adapterType = \"%s\"\n";
 
 if (filename_decompose(filename, path, prefix, postfix, PATH_MAX)) {
 return -EINVAL;
@@ -1480,6 +1482,8 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 while (options && options->name) {
 if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
 total_size = options->value.n;
+} else if (!strcmp(options->name, BLOCK_OPT_ADAPTER_TYPE)) {
+adapter_type = options->value.s;
 } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
 backing_file = options->value.s;
 } else if (!strcmp(options->name, BLOCK_OPT_COMPAT6)) {
@@ -1489,6 +1493,20 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 }
 options++;
 }
+if (!adapter_type) {
+adapter_type = "ide";
+} else if (strcmp(adapter_type, "ide") &&
+   strcmp(adapter_type, "buslogic") &&
+   strcmp(adapter_type, "lsilogic") &&
+   strcmp(adapter_type, "legacyESX")) {
+fprintf(stderr, "VMDK: Unknown adapter type: '%s'.\n", adapter_type);
+return -EINVAL;
+}
+if (strcmp(adapter_type, "ide") != 0) {
+/* that's the number of heads with which vmware operates when
+   creating, exporting, etc. vmdk files with a non-ide adapter type */
+number_heads = 255;
+}
 if (!fmt) {
 /* Default format to monolithicSparse */
 fmt = "monolithicSparse";
@@ -1576,7 +1594,8 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options)
 parent_desc_line,
 ext_desc_lines,
 (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
-total_size / (int64_t)(63 * 16 * 512));
+total_size / (int64_t)(63 * number_heads * 512), number_heads,
+adapter_type);
 if (split || flat) {
 fd = qemu_open(filename,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
@@ -1661,6 +1680,12 @@ static QEMUOptionParameter vmdk_create_options[] = {
 .help = "Virtual disk size"
 },
 {
+.name = BLOCK_OPT_ADAPTER_TYPE,
+.type = OPT_STRING,
+.help = "Virtual adapter type can be one of "
+"ide (default), lsilogic, buslogic or legacyESX"
+},
+{
 .name = BLOCK_OPT_BACKING_FILE,
 .type = OPT_STRING,
 .help = "File name of a base image"
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f83ffb8..6040c67 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -55,6 +55,7 @@
 #define BLOCK_OPT_SUBFMT"subformat"
 #define BLOCK_OPT_COMPAT_LEVEL  "compat"
 #define BLOCK_OPT_LAZY_REFCOUNTS"lazy_refcounts"
+#define BLOCK_OPT_ADAPTER_TYPE  "adapter_type"
 
 typedef struct BdrvTrackedRequest BdrvTrackedRequest;
 
-- 
1.7.10.4




[Qemu-devel] qemu-system-i386 -machine pc-0.15 -usb -usbdevice host:xxxx:yyyy usb_handle_packet: Assertion

2013-01-28 Thread Peter Stuge
Hi list!

I have an XP guest originally from qemu-kvm-0.15 which I use for
a smart card application by passing a full-speed USB CCID card
reader from the host per subject, on an x86_64 host with kvm.

Avi's qemu-kvm.git at old tag v0.15.1 with -machine pc works fine.

qemu.git master commit 6034fe7 with -machine pc-0.15 asserts
halfway through Windows starting up:

qemu-system-i386: hw/usb/core.c:413: usb_handle_packet: Assertion `p->ep->type 
!= 3 || (dev->flags & USB_DEV_FLAG_IS_HOST)' failed.

qemu.git master commit 6034fe7 with -machine pc works fine.


I originally found this at all because in both qemu-1.1.2 and
qemu-kvm-1.2.0 the application doesn't work, but all is good in
master.

Hope this helps. Many thanks.


(I'm not subscribed to the list. Let me know about some more testing.)


//Peter



[Qemu-devel] [PATCH 1/2] qemu-ga: Plug memory leak in guest_fsfreeze_cleanup()

2013-01-28 Thread Michael Roth
From: Markus Armbruster 

Neglects to free errors allocated by qmp_guest_fsfreeze_thaw().
Spotted by Coverity.

While there, drop the test whether return value is negative (it's
never true), and improve logging.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Reviewed-by: Luiz Capitulino 
Signed-off-by: Michael Roth 
---
 qga/commands-posix.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 0ad73f3..498f5ca 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -611,13 +611,14 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
 
 static void guest_fsfreeze_cleanup(void)
 {
-int64_t ret;
 Error *err = NULL;
 
 if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) {
-ret = qmp_guest_fsfreeze_thaw(&err);
-if (ret < 0 || err) {
-slog("failed to clean up frozen filesystems");
+qmp_guest_fsfreeze_thaw(&err);
+if (err) {
+slog("failed to clean up frozen filesystems: %s",
+ error_get_pretty(err));
+error_free(err);
 }
 }
 }
-- 
1.7.9.5




[Qemu-devel] [PATCH 3/3] tests: Add unit tests for mulu64 and muls64

2013-01-28 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 tests/Makefile |  7 +-
 tests/test-mul64.c | 69 ++
 2 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-mul64.c

diff --git a/tests/Makefile b/tests/Makefile
index 442b286..e695ef6 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -45,6 +45,8 @@ gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c
 gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c
 check-unit-y += tests/test-thread-pool$(EXESUF)
 gcov-files-test-thread-pool-y = thread-pool.c
+check-unit-y += tests/test-mul64$(EXESUF)
+gcov-files-test-mul64-y = util/host-utils.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -72,7 +74,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-coroutine.o tests/test-string-output-visitor.o \
tests/test-string-input-visitor.o tests/test-qmp-output-visitor.o \
tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \
-   tests/test-qmp-commands.o tests/test-visitor-serialization.o
+   tests/test-qmp-commands.o tests/test-visitor-serialization.o \
+   tests/test-mul64.o
 
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o
 
@@ -108,6 +111,8 @@ tests/test-qmp-input-strict$(EXESUF): 
tests/test-qmp-input-strict.o $(test-qapi-
 tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o 
tests/test-qmp-marshal.o $(test-qapi-obj-y) qapi-types.o qapi-visit.o 
libqemuutil.a libqemustub.a
 tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 
+tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
+
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/fdc-test$(EXESUF): tests/fdc-test.o
diff --git a/tests/test-mul64.c b/tests/test-mul64.c
new file mode 100644
index 000..6abf57c
--- /dev/null
+++ b/tests/test-mul64.c
@@ -0,0 +1,69 @@
+/*
+ * Test 64x64 -> 128 multiply subroutines
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include 
+#include 
+#include "qemu/host-utils.h"
+#include "qemu/osdep.h"
+
+
+typedef struct {
+uint64_t a, b;
+uint64_t rh, rl;
+} Test;
+
+static const Test test_u_data[] = {
+{ 1, 1, 0, 1 },
+{ 1, 1, 0, 1 },
+{ -1ull, 2, 1, -2ull },
+{ -1ull, -1ull, -2ull, 1 },
+{ 0x1122334455667788ull, 0x8877665544332211ull,
+  0x092228FB777AE38Full, 0x0A3E963337C60008ull },
+};
+
+static const Test test_s_data[] = {
+{ 1, 1, 0, 1 },
+{ 1, -1, -1, -1 },
+{ -10, -10, 0, 100 },
+{ 1, 1, 0, 1 },
+{ -1, 2, -1, -2 },
+{ 0x1122334455667788ll, 0x1122334455667788ull,
+  0x01258F60BBC2975Cll, 0x1EACE4A3C82FB840ull },
+};
+
+static void test_u(void)
+{
+int i;
+
+for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) {
+uint64_t rl, rh;
+mulu64(&rl, &rh, test_u_data[i].a, test_u_data[i].b);
+g_assert_cmpuint(rl, ==, test_u_data[i].rl);
+g_assert_cmpuint(rh, ==, test_u_data[i].rh);
+}
+}
+
+static void test_s(void)
+{
+int i;
+
+for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) {
+uint64_t rl, rh;
+muls64(&rl, &rh, test_s_data[i].a, test_s_data[i].b);
+g_assert_cmpuint(rl, ==, test_s_data[i].rl);
+g_assert_cmpint(rh, ==, test_s_data[i].rh);
+}
+}
+
+int main(int argc, char **argv)
+{
+g_test_init(&argc, &argv, NULL);
+g_test_add_func("/host-utils/mulu64", test_u);
+g_test_add_func("/host-utils/muls64", test_s);
+return g_test_run();
+}
-- 
1.7.11.7




[Qemu-devel] [PATCH 2/3] host-utils: Improve mulu64 and muls64

2013-01-28 Thread Richard Henderson
The new formulation makes better use of add-with-carry type insns
that the host may have.  Use gcc's sign adjustment trick to avoid
having to perform a 128-bit negation.

Signed-off-by: Richard Henderson 
---
 util/host-utils.c | 92 +++
 1 file changed, 38 insertions(+), 54 deletions(-)

diff --git a/util/host-utils.c b/util/host-utils.c
index 2d06a2c..f0784d6 100644
--- a/util/host-utils.c
+++ b/util/host-utils.c
@@ -27,79 +27,63 @@
 #include 
 #include "qemu/host-utils.h"
 
-//#define DEBUG_MULDIV
-
 /* Long integer helpers */
 #ifndef CONFIG_INT128
-static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
-{
-*plow += a;
-/* carry test */
-if (*plow < a)
-(*phigh)++;
-*phigh += b;
-}
-
-static void neg128 (uint64_t *plow, uint64_t *phigh)
+static inline void mul64(uint64_t *plow, uint64_t *phigh,
+ uint64_t a, uint64_t b)
 {
-*plow = ~*plow;
-*phigh = ~*phigh;
-add128(plow, phigh, 1, 0);
-}
-
-static void mul64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
-{
-uint32_t a0, a1, b0, b1;
-uint64_t v;
-
-a0 = a;
-a1 = a >> 32;
-
-b0 = b;
-b1 = b >> 32;
+typedef union {
+uint64_t ll;
+struct {
+#ifdef HOST_WORDS_BIGENDIAN
+uint32_t high, low;
+#else
+uint32_t low, high;
+#endif
+} l;
+} LL;
+LL rl, rm, rn, rh, a0, b0;
+uint64_t c;
 
-v = (uint64_t)a0 * (uint64_t)b0;
-*plow = v;
-*phigh = 0;
+a0.ll = a;
+b0.ll = b;
 
-v = (uint64_t)a0 * (uint64_t)b1;
-add128(plow, phigh, v << 32, v >> 32);
+rl.ll = (uint64_t)a0.l.low * b0.l.low;
+rm.ll = (uint64_t)a0.l.low * b0.l.high;
+rn.ll = (uint64_t)a0.l.high * b0.l.low;
+rh.ll = (uint64_t)a0.l.high * b0.l.high;
 
-v = (uint64_t)a1 * (uint64_t)b0;
-add128(plow, phigh, v << 32, v >> 32);
+c = (uint64_t)rl.l.high + rm.l.low + rn.l.low;
+rl.l.high = c;
+c >>= 32;
+c = c + rm.l.high + rn.l.high + rh.l.low;
+rh.l.low = c;
+rh.l.high += (uint32_t)(c >> 32);
 
-v = (uint64_t)a1 * (uint64_t)b1;
-*phigh += v;
+*plow = rl.ll;
+*phigh = rh.ll;
 }
 
 /* Unsigned 64x64 -> 128 multiplication */
 void mulu64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
 {
 mul64(plow, phigh, a, b);
-#if defined(DEBUG_MULDIV)
-printf("mulu64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
-   a, b, *phigh, *plow);
-#endif
 }
 
 /* Signed 64x64 -> 128 multiplication */
 void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
 {
-int sa, sb;
+uint64_t rh;
 
-sa = (a < 0);
-if (sa)
-a = -a;
-sb = (b < 0);
-if (sb)
-b = -b;
-mul64(plow, phigh, a, b);
-if (sa ^ sb) {
-neg128(plow, phigh);
+mul64(plow, &rh, a, b);
+
+/* Adjust for signs.  */
+if (b < 0) {
+rh -= a;
 }
-#if defined(DEBUG_MULDIV)
-printf("muls64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
-   a, b, *phigh, *plow);
-#endif
+if (a < 0) {
+rh -= b;
+}
+*phigh = rh;
 }
 #endif /* !CONFIG_INT128 */
-- 
1.7.11.7




[Qemu-devel] [PATCH 1/3] host-utils: Use __int128_t for mul[us]64

2013-01-28 Thread Richard Henderson
Replace some x86_64 specific inline assembly with something that
all 64-bit hosts ought to optimize well.  At worst this becomes
a call to the gcc __multi3 routine, which is no worse than our
implementation in util/host-utils.c.

With gcc 4.7, we get identical code generation for x86_64.  We
now get native multiplication on ia64 and s390x hosts.  With minor
improvements to gcc we can get it for ppc64 as well.

Signed-off-by: Richard Henderson 
---
 configure | 20 
 include/qemu/host-utils.h | 17 -
 util/host-utils.c |  4 ++--
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/configure b/configure
index b7635e4..a1ec120 100755
--- a/configure
+++ b/configure
@@ -3150,6 +3150,22 @@ if compile_prog "" "" ; then
 cpuid_h=yes
 fi
 
+
+# check if __[u]int128_t is usable.
+
+int128=no
+cat > $TMPC << EOF
+__int128_t a;
+__uint128_t b;
+int main (void) {
+  a = a + b;
+  b = a * b;
+  return 0;
+}
+EOF
+if compile_prog "" "" ; then
+int128=yes
+fi
 
 ##
 # End of CC checks
@@ -3692,6 +3708,10 @@ if test "$cpuid_h" = "yes" ; then
   echo "CONFIG_CPUID_H=y" >> $config_host_mak
 fi
 
+if test "$int128" = "yes" ; then
+  echo "CONFIG_INT128=y" >> $config_host_mak
+fi
+
 if test "$glusterfs" = "yes" ; then
   echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
 fi
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 81c9a75..dbe96ca 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -27,22 +27,21 @@
 
 #include "qemu/compiler.h"   /* QEMU_GNUC_PREREQ */
 
-#if defined(__x86_64__)
-#define __HAVE_FAST_MULU64__
+#ifdef CONFIG_INT128
 static inline void mulu64(uint64_t *plow, uint64_t *phigh,
   uint64_t a, uint64_t b)
 {
-__asm__ ("mul %0\n\t"
- : "=d" (*phigh), "=a" (*plow)
- : "a" (a), "0" (b));
+__uint128_t r = (__uint128_t)a * b;
+*plow = r;
+*phigh = r >> 64;
 }
-#define __HAVE_FAST_MULS64__
+
 static inline void muls64(uint64_t *plow, uint64_t *phigh,
   int64_t a, int64_t b)
 {
-__asm__ ("imul %0\n\t"
- : "=d" (*phigh), "=a" (*plow)
- : "a" (a), "0" (b));
+__int128_t r = (__int128_t)a * b;
+*plow = r;
+*phigh = r >> 64;
 }
 #else
 void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, int64_t b);
diff --git a/util/host-utils.c b/util/host-utils.c
index 5e3915a..2d06a2c 100644
--- a/util/host-utils.c
+++ b/util/host-utils.c
@@ -30,7 +30,7 @@
 //#define DEBUG_MULDIV
 
 /* Long integer helpers */
-#if !defined(__x86_64__)
+#ifndef CONFIG_INT128
 static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
 {
 *plow += a;
@@ -102,4 +102,4 @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, 
int64_t b)
a, b, *phigh, *plow);
 #endif
 }
-#endif /* !defined(__x86_64__) */
+#endif /* !CONFIG_INT128 */
-- 
1.7.11.7




[Qemu-devel] [PATCH v2 0/3] Improve 128-bit multiply primitives

2013-01-28 Thread Richard Henderson
Changes v1->v2:
  * Use __[u]int128_t as per Blue's comment.  I'd actually forgotten
that gcc automatically addeds those typedefs.

  * Keep the internal mul64 routine, but mark it inline.  The v1
patch relied in gcc's pre-c99 inlining semantics.  The v2 patch
ought to compile in strict c99 mode.

  * Add unit tests, as per Andreas' comment.

Tested on x86_64, i686, and arm hosts.


r~


Richard Henderson (3):
  host-utils: Use __int128_t for mul[us]64
  host-utils: Improve mulu64 and muls64
  tests: Add unit tests for mulu64 and muls64

 configure | 20 ++
 include/qemu/host-utils.h | 17 -
 tests/Makefile|  7 +++-
 tests/test-mul64.c| 69 ++
 util/host-utils.c | 96 ---
 5 files changed, 143 insertions(+), 66 deletions(-)
 create mode 100644 tests/test-mul64.c

-- 
1.7.11.7




[Qemu-devel] [RFC PATCH RDMA support v1: 5/5] send memory over RDMA as blocks are iterated

2013-01-28 Thread mrhines
From: "Michael R. Hines" 


Signed-off-by: Michael R. Hines 
---
 arch_init.c   |  116 +++--
 include/migration/qemu-file.h |1 +
 savevm.c  |   90 +++-
 3 files changed, 189 insertions(+), 18 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index dada6de..7633fa6 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -42,6 +42,7 @@
 #include "migration/migration.h"
 #include "exec/gdbstub.h"
 #include "hw/smbios.h"
+#include "qemu/rdma.h"
 #include "exec/address-spaces.h"
 #include "hw/pcspk.h"
 #include "migration/page_cache.h"
@@ -113,6 +114,7 @@ const uint32_t arch_type = QEMU_ARCH;
 #define RAM_SAVE_FLAG_EOS  0x10
 #define RAM_SAVE_FLAG_CONTINUE 0x20
 #define RAM_SAVE_FLAG_XBZRLE   0x40
+#define RAM_SAVE_FLAG_RDMA 0x80
 
 #ifdef __ALTIVEC__
 #include 
@@ -434,6 +436,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 int bytes_sent = 0;
 MemoryRegion *mr;
 ram_addr_t current_addr;
+static int not_sent = 1;
 
 if (!block)
 block = QTAILQ_FIRST(&ram_list.blocks);
@@ -457,23 +460,75 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 int cont = (block == last_sent_block) ?
 RAM_SAVE_FLAG_CONTINUE : 0;
 
+current_addr = block->offset + offset;
 p = memory_region_get_ram_ptr(mr) + offset;
 
 /* In doubt sent page as normal */
 bytes_sent = -1;
-if (is_dup_page(p)) {
+
+/*
+ * RFC RDMA: The empirical cost of searching for zero pages here
+ *   plus the cost of communicating with the other side
+ *   seems to take significantly more time than simply
+ *   dumping the page into remote memory.
+ */
+if (!qemu_rdma_migration_enabled() && is_dup_page(p)) {
 acct_info.dup_pages++;
 bytes_sent = save_block_hdr(f, block, offset, cont,
 RAM_SAVE_FLAG_COMPRESS);
 qemu_put_byte(f, *p);
 bytes_sent += 1;
+/*
+ * RFC RDMA: Same comment as above. time(run-length encoding)
+ *   + time(communication) is too big. RDMA throughput 
tanks
+ *   when this feature is enabled. But there's no need
+ *   to change the code since the feature is optional.
+ */
 } else if (migrate_use_xbzrle()) {
-current_addr = block->offset + offset;
 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
   offset, cont, last_stage);
 if (!last_stage) {
 p = get_cached_data(XBZRLE.cache, current_addr);
 }
+} else if (qemu_rdma_migration_enabled()) {
+int ret;
+
+/*
+ * RFC RDMA: This bad hack was to cause the loop on the
+ *   receiving side to break. Comments are welcome
+ *   on how to get rid of it.
+ */
+if (not_sent == 1) {
+not_sent = 0;
+bytes_sent = save_block_hdr(f, block, offset,
+cont, RAM_SAVE_FLAG_RDMA);
+}
+acct_info.norm_pages++;
+/*
+ * use RDMA to send page
+ */
+if (qemu_rdma_migration_write(&rdma_mdata, current_addr,
+TARGET_PAGE_SIZE)) {
+fprintf(stderr, "rdma migration: write error!\n");
+qemu_file_set_error(f, -EIO);
+return 0;
+}
+
+/*
+ * do some polling
+ */
+while (1) {
+ret = qemu_rdma_migration_poll(&rdma_mdata);
+if (ret == QEMU_RDMA_MIGRATION_WRID_NONE) {
+break;
+}
+if (ret < 0) {
+fprintf(stderr, "rdma migration: polling error!\n");
+qemu_file_set_error(f, -EIO);
+return 0;
+}
+}
+bytes_sent += TARGET_PAGE_SIZE;
 }
 
 /* XBZRLE overflow or normal page */
@@ -601,12 +656,15 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 return 0;
 }
 
+
+int tprate = 1000;
+
 static int ram_save_iterate(QEMUFile *f, void *opaque)
 {
 int ret;
 int i;
-int64_t t0;
-int total_sent = 0;
+int64_t t0, tp0;
+int total_sent = 0, last_total_sent = 0;
 
 qemu_mutex_lock_ramlist();
 
@@ -625,23 +683,55 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 break;
 

[Qemu-devel] [RFC PATCH RDMA support v1: 4/5] connection-setup code between client/server

2013-01-28 Thread mrhines
From: "Michael R. Hines" 


Signed-off-by: Michael R. Hines 
---
 migration-tcp.c |   53 +
 migration.c |   41 +
 2 files changed, 94 insertions(+)

diff --git a/migration-tcp.c b/migration-tcp.c
index e78a296..b6c53ba 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -14,10 +14,12 @@
  */
 
 #include "qemu-common.h"
+#include "qemu/rdma.h"
 #include "qemu/sockets.h"
 #include "migration/migration.h"
 #include "migration/qemu-file.h"
 #include "block/block.h"
+#include 
 
 //#define DEBUG_MIGRATION_TCP
 
@@ -55,6 +57,9 @@ static void tcp_wait_for_connect(int fd, void *opaque)
 
 if (fd < 0) {
 DPRINTF("migrate connect error\n");
+if (qemu_use_rdma_migration()) {
+qemu_rdma_migration_cleanup(&rdma_mdata);
+}
 s->fd = -1;
 migrate_fd_error(s);
 } else {
@@ -62,6 +67,25 @@ static void tcp_wait_for_connect(int fd, void *opaque)
 s->fd = fd;
 socket_set_block(s->fd);
 migrate_fd_connect(s);
+
+/* RDMA initailization */
+if (qemu_use_rdma_migration()) {
+if (qemu_rdma_migration_client_init(&rdma_mdata)) {
+migrate_fd_error(s);
+return;
+}
+
+fprintf(stderr, "qemu_rdma_migration_client_init success\n");
+
+if (qemu_rdma_migration_client_connect(&rdma_mdata)) {
+migrate_fd_error(s);
+close(s->fd);
+return;
+}
+
+fprintf(stderr, "qemu_rdma_migration_client_connect success\n");
+}
+
 }
 }
 
@@ -101,6 +125,16 @@ static void tcp_accept_incoming_migration(void *opaque)
 goto out;
 }
 
+if (qemu_use_rdma_migration()) {
+printf("listen on port started: %d\n", rdma_mdata.port);
+
+if (qemu_rdma_migration_server_wait_for_client(&rdma_mdata)) {
+fprintf(stderr, "rdma migration: error waiting for client!\n");
+close(s);
+return;
+}
+}
+
 process_incoming_migration(f);
 return;
 
@@ -117,6 +151,25 @@ void tcp_start_incoming_migration(const char *host_port, 
Error **errp)
 return;
 }
 
+if (qemu_use_rdma_migration()) {
+int ret;
+
+ret = qemu_rdma_migration_server_init(&rdma_mdata);
+if (ret) {
+fprintf(stderr, "rdma migration: error init server!\n");
+close(s);
+return;
+}
+
+ret = qemu_rdma_migration_server_prepare(&rdma_mdata);
+if (ret) {
+fprintf(stderr, "rdma migration: error preparing server!\n");
+close(s);
+return;
+}
+
+}
+
 qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
  (void *)(intptr_t)s);
 }
diff --git a/migration.c b/migration.c
index 77c1971..cffe16f 100644
--- a/migration.c
+++ b/migration.c
@@ -22,6 +22,7 @@
 #include "qemu/sockets.h"
 #include "migration/block.h"
 #include "qemu/thread.h"
+#include "qemu/rdma.h"
 #include "qmp-commands.h"
 
 //#define DEBUG_MIGRATION
@@ -279,6 +280,11 @@ static int migrate_fd_cleanup(MigrationState *s)
 }
 
 assert(s->fd == -1);
+
+if (qemu_rdma_migration_enabled()) {
+qemu_rdma_migration_cleanup(&rdma_mdata);
+}
+
 return ret;
 }
 
@@ -481,6 +487,41 @@ int64_t qmp_query_migrate_cache_size(Error **errp)
 return migrate_xbzrle_cache_size();
 }
 
+void qmp_migrate_set_rdma_port(int64_t port, Error **errp)
+{
+MigrationState *s = migrate_get_current();
+if (s && (s->state == MIG_STATE_ACTIVE)) {
+return;
+}
+printf("rdma migration port: %" PRId64 "\n", port);
+rdma_mdata.port = port;
+}
+
+void qmp_migrate_set_rdma_host(const char *host, Error **errp)
+{
+MigrationState *s = migrate_get_current();
+if (s && (s->state == MIG_STATE_ACTIVE)) {
+return;
+}
+printf("rdma migration host name: %s\n", host);
+strncpy(rdma_mdata.host, host, 64);
+rdma_mdata.host[63] = '\0';
+}
+
+void qmp_migrate_rdma_prepare(Error **errp)
+{
+MigrationState *s = migrate_get_current();
+if (s && (s->state == MIG_STATE_ACTIVE)) {
+return;
+}
+qemu_rdma_migration_client_init(&rdma_mdata);
+}
+
+void qmp_migrate_rdma_release(Error **errp)
+{
+qemu_rdma_migration_cleanup(&rdma_mdata);
+}
+
 void qmp_migrate_set_speed(int64_t value, Error **errp)
 {
 MigrationState *s;
-- 
1.7.10.4




[Qemu-devel] [RFC PATCH RDMA support v1: 3/5] initialize RDMA options when QEMU first runs on command-line

2013-01-28 Thread mrhines
From: "Michael R. Hines" 


Signed-off-by: Michael R. Hines 
---
 exec.c |   27 +++
 vl.c   |   10 ++
 2 files changed, 37 insertions(+)

diff --git a/exec.c b/exec.c
index b85508b..4fc56d1 100644
--- a/exec.c
+++ b/exec.c
@@ -25,6 +25,8 @@
 #endif
 
 #include "qemu-common.h"
+#include "qemu/rdma.h"
+#include "monitor/monitor.h"
 #include "cpu.h"
 #include "tcg.h"
 #include "hw/hw.h"
@@ -104,6 +106,31 @@ static MemoryRegion io_mem_watch;
 
 #if !defined(CONFIG_USER_ONLY)
 
+/*
+ * Memory regions need to be registered with the device and queue pairs setup
+ * in advanced before the migration starts. This tells us where the RAM blocks
+ * are so that we can register them individually.
+ */
+int qemu_rdma_init_ram_blocks(struct qemu_rdma_ram_blocks *rdma_ram_blocks)
+{
+RAMBlock *block;
+int num_blocks = 0;
+
+memset(rdma_ram_blocks, 0, sizeof *rdma_ram_blocks);
+QTAILQ_FOREACH(block, &ram_list.blocks, next) {
+if (num_blocks >= QEMU_MAX_RAM_BLOCKS) {
+return -1;
+}
+rdma_ram_blocks->block[num_blocks].local_host_addr = block->host;
+rdma_ram_blocks->block[num_blocks].offset = (uint64_t)block->offset;
+rdma_ram_blocks->block[num_blocks].length = (uint64_t)block->length;
+num_blocks++;
+}
+rdma_ram_blocks->num_blocks = num_blocks;
+
+return 0;
+}
+
 static void phys_map_node_reserve(unsigned nodes)
 {
 if (phys_map_nodes_nb + nodes > phys_map_nodes_nb_alloc) {
diff --git a/vl.c b/vl.c
index 7aab73b..195a56e 100644
--- a/vl.c
+++ b/vl.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include "qemu/bitmap.h"
+#include "qemu/rdma.h"
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -3622,6 +3623,13 @@ int main(int argc, char **argv, char **envp)
 default_sdcard = 0;
 default_vga = 0;
 break;
+case QEMU_OPTION_rdmaport:
+rdmaport = atoi(optarg);
+break;
+case QEMU_OPTION_rdmahost:
+strncpy(rdmahost, optarg, 64);
+rdmahost[63] = '\0';
+break;
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
 printf("Option %s not supported for this target\n", 
popt->name);
@@ -4007,6 +4015,8 @@ int main(int argc, char **argv, char **envp)
 
 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
 
+qemu_rdma_migration_data_init(&rdma_mdata);
+
 if (nb_numa_nodes > 0) {
 int i;
 
-- 
1.7.10.4




[Qemu-devel] [RFC PATCH RDMA support v1: 1/5] add openfabrics RDMA libraries and base RDMA code to build

2013-01-28 Thread mrhines
From: "Michael R. Hines" 


Signed-off-by: Michael R. Hines 
---
 Makefile.target |5 +-
 include/qemu/rdma.h |  249 ++
 qemu-rdma.c | 1357 +++
 3 files changed, 1609 insertions(+), 2 deletions(-)
 create mode 100644 include/qemu/rdma.h
 create mode 100644 qemu-rdma.c

diff --git a/Makefile.target b/Makefile.target
index 760da1e..d1d6b8c 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -112,12 +112,13 @@ obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o 
ioport.o
 obj-y += hw/
 obj-$(CONFIG_KVM) += kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
-obj-y += memory.o savevm.o cputlb.o
+# "tracefunc.o" will go away - I use GCC's -finstrument-functions support 
inside tracefunc.o
+obj-y += memory.o savevm.o cputlb.o qemu-rdma.o #tracefunc.o
 obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o
 obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o
 obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
 obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o
-LIBS+=-lz
+LIBS+=-lz -lrdmacm
 
 # xen support
 obj-$(CONFIG_XEN) += xen-all.o xen-mapcache.o
diff --git a/include/qemu/rdma.h b/include/qemu/rdma.h
new file mode 100644
index 000..099622e
--- /dev/null
+++ b/include/qemu/rdma.h
@@ -0,0 +1,249 @@
+/*
+ * RDMA data structures and helper functions header (for migration)
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Michael R. Hines 
+ *  Jiuxing Liu 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef _QEMU_RDMA_H
+#define _QEMU_RDMA_H
+
+#include 
+#include "monitor/monitor.h"
+
+extern int rdmaport;
+extern char rdmahost[64];
+
+struct qemu_rdma_context {
+/* cm_id also has ibv_conext, rdma_event_channel, and ibv_qp in
+   cm_id->verbs, cm_id->channel, and cm_id->qp. */
+struct rdma_cm_id *cm_id;
+struct rdma_cm_id *listen_id;
+
+struct ibv_context *verbs;
+struct rdma_event_channel *channel;
+struct ibv_qp *qp;
+
+struct ibv_comp_channel *comp_channel;
+struct ibv_pd *pd;
+struct ibv_cq *cq;
+};
+
+static inline void qemu_rdma_init_context(struct qemu_rdma_context *rdma_ctx)
+{
+rdma_ctx->cm_id = NULL;
+rdma_ctx->listen_id = NULL;
+rdma_ctx->verbs = NULL;
+rdma_ctx->channel = NULL;
+rdma_ctx->qp = NULL;
+rdma_ctx->comp_channel = NULL;
+rdma_ctx->pd = NULL;
+rdma_ctx->cq = NULL;
+}
+
+void cpu_physical_memory_reset_dirty_all(void);
+
+int qemu_rdma_resolve_host(struct qemu_rdma_context *rdma_ctx,
+const char *host, int port);
+int qemu_rdma_alloc_pd_cq(struct qemu_rdma_context *rdma_ctx);
+int qemu_rdma_alloc_qp(struct qemu_rdma_context *rdma_ctx);
+int qemu_rdma_connect(struct qemu_rdma_context *rdma_ctx,
+void *in_data, int *in_len, void *out_data, int out_len);
+int qemu_rdma_accept(struct qemu_rdma_context *rdma_ctx,
+void *in_data, int *in_len, void *out_data, int out_len);
+void qemu_rdma_disconnect(struct qemu_rdma_context *rdma_ctx);
+void qemu_rdma_cleanup(struct qemu_rdma_context *rdma_ctx);
+
+/* Instead of registering whole ram blocks, we can register them in smaller
+ * chunks. This may be benefial if the ram blocks have holes in them */
+#define QEMU_RDMA_CHUNK_REGISTRATION
+
+#define QEMU_RDMA_LAZY_REGISTRATION
+
+#define QEMU_RDMA_REG_CHUNK_SHIFT 20
+#define QEMU_RDMA_REG_CHUNK_SIZE (1UL << (QEMU_RDMA_REG_CHUNK_SHIFT))
+#define QEMU_RDMA_REG_CHUNK_INDEX(start_addr, host_addr) \
+(((unsigned long)(host_addr) >> QEMU_RDMA_REG_CHUNK_SHIFT) - \
+((unsigned long)(start_addr) >> QEMU_RDMA_REG_CHUNK_SHIFT))
+#define QEMU_RDMA_REG_NUM_CHUNKS(rdma_ram_block) \
+(QEMU_RDMA_REG_CHUNK_INDEX((rdma_ram_block)->local_host_addr,\
+(rdma_ram_block)->local_host_addr +\
+(rdma_ram_block)->length) + 1)
+#define QEMU_RDMA_REG_CHUNK_START(rdma_ram_block, i) ((uint8_t *)\
+unsigned long)((rdma_ram_block)->local_host_addr) >> \
+QEMU_RDMA_REG_CHUNK_SHIFT) + (i)) << \
+QEMU_RDMA_REG_CHUNK_SHIFT))
+#define QEMU_RDMA_REG_CHUNK_END(rdma_ram_block, i) \
+(QEMU_RDMA_REG_CHUNK_START(rdma_ram_block, i) + \
+ QEMU_RDMA_REG_CHUNK_SIZE)
+
+struct qemu_rdma_ram_block {
+uint8_t *local_host_addr;
+uint64_t remote_host_addr;
+uint64_t offset;
+uint64_t length;
+struct ibv_mr **pmr;
+struct ibv_mr *mr;
+uint32_t remote_rkey;
+};
+
+struct qemu_rdma_remote_ram_block {
+uint64_t remote_host_addr;
+uint64_t offset;
+uint64_t length;
+uint32_t remote_rkey;
+};
+
+#define QEMU_MAX_RAM_BLOCKS 64
+
+struct qemu_rdma_ram_blocks {
+int num_blocks;
+struct qemu_rdma_ram_block block[QEMU_MAX_RAM_BLOCKS];
+};
+
+struct qemu_rdma_remote_ram_blocks {
+int num_blocks;
+struct qemu_rdma_remote_ram_block block[QEMU_MAX_RAM_BLOCKS];
+};
+
+int qemu_rdma_init_ram_blocks(struct qemu_rdma_

[Qemu-devel] [RFC PATCH RDMA support v1: 2/5] install new monitor commands to configure RDMA

2013-01-28 Thread mrhines
From: "Michael R. Hines" 


Signed-off-by: Michael R. Hines 
---
 hmp-commands.hx  |   56 ++
 hmp.c|   23 ++
 hmp.h|4 
 qapi-schema.json |   56 ++
 qemu-options.hx  |   10 ++
 5 files changed, 149 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 0934b9b..4cf8ece 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -895,6 +895,34 @@ Set cache size to @var{value} (in bytes) for xbzrle 
migrations.
 ETEXI
 
 {
+.name   = "migrate_rdma_prepare",
+.args_type  = "",
+.params = "",
+.help   = "prepare for RDMA VM migration",
+.mhandler.cmd = hmp_migrate_rdma_prepare,
+},
+
+STEXI
+@item migrate_rdma_prepare
+@findex migrate_rdma_prepare
+Prepare the VM for RDMA VM migration.
+ETEXI
+
+{
+.name   = "migrate_rdma_release",
+.args_type  = "",
+.params = "",
+.help   = "release RDMA resources for VM migration",
+.mhandler.cmd = hmp_migrate_rdma_release,
+},
+
+STEXI
+@item migrate_rdma_release
+@findex migrate_rdma_release
+Release the RDMA resources used during VM RDMA migration.
+ETEXI
+
+{
 .name   = "migrate_set_speed",
 .args_type  = "value:o",
 .params = "value",
@@ -910,6 +938,34 @@ Set maximum speed to @var{value} (in bytes) for migrations.
 ETEXI
 
 {
+.name   = "migrate_set_rdma_port",
+.args_type  = "port:i",
+.params = "port",
+.help   = "set RDMA port for migration",
+.mhandler.cmd = hmp_migrate_set_rdma_port,
+},
+
+STEXI
+@item migrate_set_rdma_port @var{value}
+@findex migrate_set_rdma_port
+Set RDMA migration port to @var{value}.
+ETEXI
+
+{
+.name   = "migrate_set_rdma_host",
+.args_type  = "host:s",
+.params = "host",
+.help   = "set RDMA host name for migration",
+.mhandler.cmd = hmp_migrate_set_rdma_host,
+},
+
+STEXI
+@item migrate_set_rdma_host @var{value}
+@findex migrate_set_rdma_host
+Set RDMA migration host name to @var{value}.
+ETEXI
+
+{
 .name   = "migrate_set_downtime",
 .args_type  = "value:T",
 .params = "value",
diff --git a/hmp.c b/hmp.c
index c7b6ba0..4a2dd3b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -848,6 +848,29 @@ void hmp_migrate_set_cache_size(Monitor *mon, const QDict 
*qdict)
 }
 }
 
+void hmp_migrate_set_rdma_port(Monitor *mon, const QDict *qdict)
+{
+int port = qdict_get_int(qdict, "port");
+qmp_migrate_set_rdma_port(port, NULL);
+}
+
+void hmp_migrate_set_rdma_host(Monitor *mon, const QDict *qdict)
+{
+const char *host = qdict_get_str(qdict, "host");
+qmp_migrate_set_rdma_host(host, NULL);
+}
+
+void hmp_migrate_rdma_prepare(Monitor *mon, const QDict *qdict)
+{
+qmp_migrate_rdma_prepare(NULL);
+}
+
+void hmp_migrate_rdma_release(Monitor *mon, const QDict *qdict)
+{
+qmp_migrate_rdma_release(NULL);
+}
+
+
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
 int64_t value = qdict_get_int(qdict, "value");
diff --git a/hmp.h b/hmp.h
index 44be683..185f343 100644
--- a/hmp.h
+++ b/hmp.h
@@ -55,6 +55,10 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_rdma_port(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_rdma_host(Monitor *mon, const QDict *qdict);
+void hmp_migrate_rdma_prepare(Monitor *mon, const QDict *qdict);
+void hmp_migrate_rdma_release(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index 6d7252b..181489b 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1695,6 +1695,62 @@
 { 'command': 'migrate_set_speed', 'data': {'value': 'int'} }
 
 ##
+# @migrate_set_rdma_port
+#
+# Set rdma communication port.
+#
+# @port: rdma communication port.
+#
+# Returns: nothing on success
+#
+# Notes: Nothing.
+#
+# Since: 1.3.0
+##
+{ 'command': 'migrate_set_rdma_port', 'data': {'port': 'int'} }
+
+##
+# @migrate_set_rdma_host
+#
+# Set rdma communication host address.
+#
+# @host: rdma communication host address.
+#
+# Returns: nothing on success
+#
+# Notes: Nothing.
+#
+# Since: 1.3.0
+##
+{ 'command': 'migrate_set_rdma_host', 'data': {'host': 'str'} }
+
+##
+# @migrate_rdma_prepare
+#
+# Tell the backup QEMU to pre-register all of the RDMA memory
+#
+# Returns: nothing on success
+#
+# Notes: Nothing.
+#
+# Since: 1.3.0
+##
+{ 'command': 'migrate_rdma_prepare' }
+
+##
+# @migrate_rdma_release
+#
+

[Qemu-devel] [PULL for-1.4 0/2] qemu-ga: fix memory/filehandle leaks

2013-01-28 Thread Michael Roth
The following changes since commit 6034fe7bdb555c43022706e228cde8d52a8b341a:

  xilinx_ethlite: Avoid build warnings in debug code (2013-01-27 01:05:00 +0100)

are available in the git repository at:

  git://github.com/mdroth/qemu.git qga-pull-1-28-13

for you to fetch changes up to 10a2158f52796e5b2b7ce7991bde09a3c985a37b:

  qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths 
(2013-01-28 13:46:54 -0600)


Markus Armbruster (2):
  qemu-ga: Plug memory leak in guest_fsfreeze_cleanup()
  qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths

 qga/commands-posix.c |   20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)




[Qemu-devel] [ANNOUNCE] QEMU 1.3.1 Stable released

2013-01-28 Thread mdroth
Hi everyone,

I am pleased to announce that the QEMU v1.3.1 stable release is now
available at:

http://wiki.qemu.org/download/qemu-1.3.1.tar.bz2

The official stable-1.3 repository has also been updated to v1.3.1:

http://git.qemu.org/?p=qemu-stable-1.3.git;a=summary

This release includes 29 build/bug fixes, including a number of critical
fixes for OpenBSD guests.

Please note this is the last planned released for the 1.3 series as we move
on to maintaining 1.4, after which we'll be moving to a more regular
schedule of 2 planned stable releases for each major release.


Thanks!

04024de: update VERSION for v1.3.1 (Michael Roth)
1bd4397: qxl: Fix SPICE_RING_PROD_ITEM(), SPICE_RING_CONS_ITEM() sanity check 
(Markus Armbruster)
e766724: Fix compile errors when enabling Xen debug logging. (Sander 
Eikelenboom)
df50a7e: xen: fix trivial PCI passthrough MSI-X bug (Stefano Stabellini)
90c96d3: xen_disk: fix memory leak (Roger Pau Monne)
4ee2879: tcg/target-arm: Add missing parens to assertions (Peter Maydell)
563068a: win32-aio: Fix memory leak (Kevin Wolf)
cdb4834: win32-aio: Fix vectored reads (Kevin Wolf)
9d173df: aio: Fix return value of aio_poll() (Kevin Wolf)
204dd38: raw-posix: fix bdrv_aio_ioctl (Paolo Bonzini)
86bab45: vfio-pci: Loosen sanity checks to allow future features (Alex 
Williamson)
006c747: pci-assign: Enable MSIX on device to match guest (Alex Williamson)
f042cca: vfio-pci: Make host MSI-X enable track guest (Alex Williamson)
1205b80: target-xtensa: fix search_pc for the last TB opcode (Max Filippov)
ff0c079: buffered_file: do not send more than s->bytes_xfer bytes per tick 
(Paolo Bonzini)
d745511: migration: fix migration_bitmap leak (Paolo Bonzini)
5afd0ec: e1000: Discard oversized packets based on SBP|LPE (Michael Contreras)
c4cd5b0: qxl+vnc: register a vm state change handler for dummy spice_server 
(Uri Lublin)
7ca2496: qxl: save qemu_create_displaysurface_from result (Gerd Hoffmann)
bfae937: target-xtensa: fix ITLB/DTLB page protection flags (Max Filippov)
b68c48f: pixman: fix vnc tight png/jpeg support (Gerd Hoffmann)
36fd817: Update seabios to a810e4e72a0d42c7bc04eda57382f8e019add901 (Gerd 
Hoffmann)
0bc5f4a: seabios: update to e8a76b0f225bba5ba9d63ab227e0a37b3beb1059 (Gerd 
Hoffmann)
37e1428: vfio-pci: Don't use kvm_irqchip_in_kernel (Alex Williamson)
518799a: target-mips: Fix incorrect shift for SHILO and SHILOV (Petar Jovanovic)
16c5fe4: target-mips: Fix incorrect code and test for INSV (Petar Jovanovic)
f1a2195: migration: Fix madvise breakage if host and guest have different page 
sizes (David Gibson)
3b4fc1f: Fix off-by-1 error in RAM migration code (David Gibson)
d67d95f: Disable semaphores fallback code for OpenBSD (Brad Smith)
0a7ad69: Fix semaphores fallback code (Brad Smith)




[Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths

2013-01-28 Thread Michael Roth
From: Markus Armbruster 

Spotted by Coverity.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Reviewed-by: Luiz Capitulino 
Signed-off-by: Michael Roth 
---
 qga/commands-posix.c |   11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 498f5ca..7a0202e 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -935,9 +935,11 @@ GuestNetworkInterfaceList 
*qmp_guest_network_get_interfaces(Error **errp)
 error_setg_errno(errp, errno,
  "failed to get MAC address of %s",
  ifa->ifa_name);
+close(sock);
 goto error;
 }
 
+close(sock);
 mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
 
 info->value->hardware_address =
@@ -947,20 +949,19 @@ GuestNetworkInterfaceList 
*qmp_guest_network_get_interfaces(Error **errp)
 (int) mac_addr[4], (int) mac_addr[5]);
 
 info->value->has_hardware_address = true;
-close(sock);
 }
 
 if (ifa->ifa_addr &&
 ifa->ifa_addr->sa_family == AF_INET) {
 /* interface with IPv4 address */
-address_item = g_malloc0(sizeof(*address_item));
-address_item->value = g_malloc0(sizeof(*address_item->value));
 p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
 if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) {
 error_setg_errno(errp, errno, "inet_ntop failed");
 goto error;
 }
 
+address_item = g_malloc0(sizeof(*address_item));
+address_item->value = g_malloc0(sizeof(*address_item->value));
 address_item->value->ip_address = g_strdup(addr4);
 address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4;
 
@@ -973,14 +974,14 @@ GuestNetworkInterfaceList 
*qmp_guest_network_get_interfaces(Error **errp)
 } else if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_INET6) {
 /* interface with IPv6 address */
-address_item = g_malloc0(sizeof(*address_item));
-address_item->value = g_malloc0(sizeof(*address_item->value));
 p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
 if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) {
 error_setg_errno(errp, errno, "inet_ntop failed");
 goto error;
 }
 
+address_item = g_malloc0(sizeof(*address_item));
+address_item->value = g_malloc0(sizeof(*address_item->value));
 address_item->value->ip_address = g_strdup(addr6);
 address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6;
 
-- 
1.7.9.5




Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Peter Maydell
On 28 January 2013 19:14, Andreas Färber  wrote:
> Am 28.01.2013 19:59, schrieb Peter Maydell:
>> Er, what? "do ... while (0)" is completely standard practice
>> for writing robust macros in C. Patches which don't do that
>> should fail code review.
>
> Oh really? None of our QOM cast macros use it, they passed your review,
> and there is zero reason to bring that plague upon us for any reasonably
> small macro.

Sorry, I didn't expand that fully because I thought it was
obvious that I didn't mean "apply this to every macro in QEMU".
To be clear:

This is a standard practice for writing a robust macro, but
by "standard practice" I mean "putting in the do..while
in the places where the practice states that it is required",
not "wrapping every single #define in it even when that makes
no sense".

Specifically, the loop is required where the macro:
 1. expands to several C statements, or a complex statement
like an "if"
 2. is used in a way that the user expects it to act like a
C function, ie as if it were a single C statement

and the rationale is that it is easy for users to use such
a macro in contexts like
 if (foo)
 MY_MACRO();
 else
 something;

and get confusing errors or unintended behaviour.
(Yes, I know qemu's coding style would mandate braces; not all
our code has braces and in any case it is good defensive
programming practice to make the macro robust to minor
style issues in its users.)

Therefore, when in QEMU we have macros which meet the
above conditions, we should follow this standard practice.

The QOM cast macros do not meet condition 1 above
(they expand to a single simple expression). Nor does
memread(). These examples are therefore irrelevant to this
discussion. Other weird cases like macros which expand
to entire function definitions don't meet condition 2 because
they don't "look like" simple C functions, so they are also
not relevant here.

> Anything larger in most use cases outside core TCG code is
> an overuse of macros.

This is (again) a completely different discussion. If you want
to suggest that we should in general make more use of inline
functions rather than macros then yes, I agree with you.
All I am saying is that
 1. if and when we do use complex macros we need to get them right!
 2. we should do this in the standard way that would be recognised
by any C programmer who's dealt with the issue before, not
with bizarre glib specific macros which obscure what's actually
going on

-- PMM



Re: [Qemu-devel] [PATCH 2/2] qga: add guest-set-time command

2013-01-28 Thread Eric Blake
On 01/27/2013 11:14 AM, Lei Li wrote:
> Signed-off-by: Lei Li 
> ---
>  qga/commands-posix.c |   76 
> ++
>  qga/qapi-schema.json |   42 +++
>  2 files changed, 118 insertions(+), 0 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 2fef2b6..5424c50 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -149,6 +149,82 @@ struct TimeInfo *qmp_guest_get_time(Error **errp)
>  return time_info;
>  }
>  
> +void qmp_guest_set_time(bool has_seconds, int64_t seconds,
> +bool has_microseconds, int64_t microseconds,
> +bool has_utc_offset, int64_t utc_offset, Error 
> **errp)
> +{
> +int ret;
> +int status;
> +pid_t pid, rpid;
> +struct timeval tv;
> +TimeInfo *time_info;
> +
> +/* year-2038 will overflow in case time_t is 32bit */
> +if (sizeof(time_t) == 4) {
> +return;
> +}

What? Silently giving up, without even seeing whether overflow happened?
 That just feels wrong.  Make the change if it is in range, and be vocal
about setting an error if there is overflow.

> +
> +if (!has_seconds) {
> +if (has_microseconds || has_utc_offset) {
> +error_setg(errp, "field 'seconds' missing");
> +return;
> +} else {
> +/* Grab time from the host if no arguments given. */
> +time_info = get_host_time(errp);

Does this even make sense?  Since this code will be executing in the
guest, you are getting the guest's current notion of time (as I said in
1/2, get_host_time() is misnamed); and then setting the guest's time
right back to the same value.  Why bother?

It seems like if the host is going to bother issuing the guest-set-time
agent command, then the host should have a mandatory argument to tell
the guest what to set its time to.

Then again, reading the rest of your code, I can see one case where it
_might_ make sense to allow the host to not pass in a time - namely, if
the host wants to force the guest to call hwclock to write its notion of
current system time (in RAM) back to the hardware.  But that seems like
a stretch.

> +if (!time_info) {
> +return;
> +}
> +
> +tv.tv_sec = time_info->seconds;
> +tv.tv_usec = time_info->microseconds;
> +}
> +} else {
> +if (abs(utc_offset) > (24 * 60)) {

Won't work.  abs() takes an int argument, so you can pass in int64_t
values that will overflow the range of int and not be detected by this
overflow check.

> +error_setg(errp, "'utc_offset' shoud be less than 24 hours");

s/shoud/should/

> +return;
> +}
> +
> +if (microseconds > 100) {
> +error_setg(errp, "'microseconds' overflow");
> +return;
> +}
> +
> +tv.tv_sec = (time_t) seconds + (has_utc_offset ? utc_offset * 60 : 
> 0);
> +tv.tv_usec = has_microseconds ? (time_t) microseconds : 0;
> +}
> +
> +
> +ret = settimeofday(&tv, NULL);
> +if (ret < 0) {
> +error_set(errp, QERR_QGA_COMMAND_FAILED, strerror(errno));

Prefer error_setg_errno.

> +return;
> +}
> +
> +/* Set the Hardware Clock to the current System Time. */
> +pid = fork();
> +if (pid == 0) {
> +setsid();
> +reopen_fd_to_null(0);
> +reopen_fd_to_null(1);
> +reopen_fd_to_null(2);
> +
> +execle("/sbin/hwclock", "hwclock", "-w", NULL, environ);
> +_exit(EXIT_FAILURE);
> +} else if (pid < 0) {
> +goto exit_err;
> +}
> +
> +do {
> +rpid = waitpid(pid, &status, 0);
> +} while (rpid == -1 && errno == EINTR);
> +if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {
> +return;
> +}
> +
> +exit_err:
> +error_set(errp, QERR_UNDEFINED_ERROR);

error_setg and a nicer message would be nicer to the end user.

> +}
> +
>  typedef struct GuestFileHandle {
>  uint64_t id;
>  FILE *fh;
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index d067fa5..6eba625 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -121,6 +121,48 @@
>'returns': 'TimeInfo' }
>  
>  ##
> +# @guest-set-time:
> +#
> +# Set guest time. If no arguments were given, will set
> +# host time to guest.

I don't see how omitted time arguments can possibly work.  It makes
sense from a management app point of view (tell me a time, and I'll call
guest-set-time with that value on your behalf; or don't tell me a time,
I'll get the host time, and then call guest-set-time with the right
value); but this file is not documenting the management app, but the
JSON interface that the guest sees.  In other words, I think time has to
be a mandatory argument by the time you get this low in the stack.

> +#
> +# Right now, when a guest is paused or migrated to a file
> +# then loaded from that file, the g

Re: [Qemu-devel] [RFC] Writeable files in fw_cfg

2013-01-28 Thread Gleb Natapov
On Mon, Jan 28, 2013 at 12:48:43PM -0600, Anthony Liguori wrote:
> Gleb Natapov  writes:
> 
> > On Mon, Jan 28, 2013 at 10:10:06AM -0600, Anthony Liguori wrote:
> >> David Woodhouse  writes:
> >> 
> >> > On Sun, 2013-01-27 at 18:53 -0600, Anthony Liguori wrote:
> >> >> Are you just trying to persist a single blob of a fixed maximum size?
> >> >
> >> > That would suffice.
> >> >
> >> >> Why not just have a second flash device then?
> >> >
> >> > Mostly because flash devices don't actually *work* with KVM.
> >> 
> >> They absolutely do.  What doesn't work is executing ROM from flash if
> >> the ROM cannot be treated as read-only memory.
> >> 
> >> That's because all we get is a PF in the kernel when trying to execute
> >> from unmapped ROM.  There's no way to turn that into MMIO to userspace
> >> without switching to running fully in emulation mode.  The x86 emulator
> >> is pretty close to complete but work would be needed to fully complete
> >> it to make this work.
> >> 
> > The x86 emulator cannot fetch from MMIO memory today. And protected mode
> > emulation is not so complete. We rarely, if ever, need to emulate
> > protected mode instructions without memory operands.
> 
> Ack.
> 
> >
> >> We normally handle this by mapping the ROM memory read-only so it can be
> >> executed without PF'ing but since the BIOS area is subject to PAM, we
> >> can't use this trick for that particular ROM.
> > Up until kernel 3.7 there was no support for read-only memory slots. As
> > far as I know QEMU still maps ROM as regular RAM to KVM.
> 
> Ack.
> 
> >> 
> >> SeaBIOS has hack to just not use PAM to do BIOS shadowing when running
> >> under KVM/QEMU but presumably OVMF lacks this.
> > Not sure that such hack exists and why is it needed. BIOS area is always
> > writable in KVM. 
> 
> shadow.c:
>   static void
>   make_bios_writable_intel(u16 bdf, u32 pam0)
>   {
>   int reg = pci_config_readb(bdf, pam0);
>   if (!(reg & 0x10)) {
>   // QEMU doesn't fully implement the piix shadow capabilities -
>   // if ram isn't backing the bios segment when shadowing is
>   // disabled, the code itself wont be in memory.  So, run the
>   // code from the high-memory flash location.
> 
> Normally when shadowing, you set the PAM registers to send read requests
> to ROM and write requests to RAM.  You then read the code segment (that
> you're executing from) and write that out to RAM and switch to executing
> from there.
> 
> That's just not possible without treating ROMs as MMIO and sending all
> requests down to QEMU.
> 
Ack.

> >> 
> >> But in this case, you're using the flash device purely for read/write,
> >> not for execution, so there's no limitation at all.
> >> 
> > Yes, on newer kernel we can use read-only slots to emulate flash. They
> > behaves like ROMD: memory on read MMIO on write. On older kernels we can
> > use pure MMIO.
> 
> Ack.
> 
> Regards,
> 
> Anthony Liguori
> 
> >
> > --
> > Gleb.

--
Gleb.



Re: [Qemu-devel] [PATCH 1/2] host-utils: Use __int128 for mul[us]64

2013-01-28 Thread Blue Swirl
On Mon, Jan 28, 2013 at 6:52 PM, Richard Henderson  wrote:
> Replace some x86_64 specific inline assembly with something that
> all 64-bit hosts ought to optimize well.  At worst this becomes a
> call to the gcc __multi3 routine, which is no worse than our
> implementation in util/host-utils.c.
>
> With gcc 4.7, we get identical code generation for x86_64.  We
> now get native multiplication on ia64 and s390x hosts.  With minor
> improvements to gcc we can get it for ppc64 as well.

In OpenBIOS we use __int128_t and __uint128_t, which are closer in
form to standard types. Could you use those instead of __int128 and
unsigned  __int128?

>
> Signed-off-by: Richard Henderson 
> ---
>  configure | 20 
>  include/qemu/host-utils.h | 17 -
>  util/host-utils.c |  4 ++--
>  3 files changed, 30 insertions(+), 11 deletions(-)
>
> diff --git a/configure b/configure
> index b7635e4..ecf1cbc 100755
> --- a/configure
> +++ b/configure
> @@ -3150,6 +3150,22 @@ if compile_prog "" "" ; then
>  cpuid_h=yes
>  fi
>
> +
> +# check if __int128 is usable.
> +
> +int128=no
> +cat > $TMPC << EOF
> +int main (void) {
> +  __int128 a = 0;
> +  unsigned __int128 b = 1;
> +  a = a + b;
> +  a = a * b;
> +  return 0;
> +}
> +EOF
> +if compile_prog "" "" ; then
> +int128=yes
> +fi
>
>  ##
>  # End of CC checks
> @@ -3692,6 +3708,10 @@ if test "$cpuid_h" = "yes" ; then
>echo "CONFIG_CPUID_H=y" >> $config_host_mak
>  fi
>
> +if test "$int128" = "yes" ; then
> +  echo "CONFIG_INT128=y" >> $config_host_mak
> +fi
> +
>  if test "$glusterfs" = "yes" ; then
>echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
>  fi
> diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
> index 81c9a75..01f6610 100644
> --- a/include/qemu/host-utils.h
> +++ b/include/qemu/host-utils.h
> @@ -27,22 +27,21 @@
>
>  #include "qemu/compiler.h"   /* QEMU_GNUC_PREREQ */
>
> -#if defined(__x86_64__)
> -#define __HAVE_FAST_MULU64__
> +#ifdef CONFIG_INT128
>  static inline void mulu64(uint64_t *plow, uint64_t *phigh,
>uint64_t a, uint64_t b)
>  {
> -__asm__ ("mul %0\n\t"
> - : "=d" (*phigh), "=a" (*plow)
> - : "a" (a), "0" (b));
> +unsigned __int128 r = (unsigned __int128)a * b;

__uint128_t?

> +*plow = r;
> +*phigh = r >> 64;
>  }
> -#define __HAVE_FAST_MULS64__
> +
>  static inline void muls64(uint64_t *plow, uint64_t *phigh,
>int64_t a, int64_t b)
>  {
> -__asm__ ("imul %0\n\t"
> - : "=d" (*phigh), "=a" (*plow)
> - : "a" (a), "0" (b));
> +__int128 r = (__int128)a * b;
> +*plow = r;
> +*phigh = r >> 64;
>  }
>  #else
>  void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, int64_t b);
> diff --git a/util/host-utils.c b/util/host-utils.c
> index 5e3915a..2d06a2c 100644
> --- a/util/host-utils.c
> +++ b/util/host-utils.c
> @@ -30,7 +30,7 @@
>  //#define DEBUG_MULDIV
>
>  /* Long integer helpers */
> -#if !defined(__x86_64__)
> +#ifndef CONFIG_INT128
>  static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
>  {
>  *plow += a;
> @@ -102,4 +102,4 @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, 
> int64_t b)
> a, b, *phigh, *plow);
>  #endif
>  }
> -#endif /* !defined(__x86_64__) */
> +#endif /* !CONFIG_INT128 */
> --
> 1.7.11.7
>
>



Re: [Qemu-devel] [PATCH 1/2] qga: add guest-get-time command

2013-01-28 Thread Anthony Liguori
Eric Blake  writes:

> On 01/27/2013 11:14 AM, Lei Li wrote:
>> Signed-off-by: Lei Li 
>> ---
>>  include/qapi/qmp/qerror.h |3 +++
>>  qga/commands-posix.c  |   30 ++
>>  qga/qapi-schema.json  |   38 ++
>>  3 files changed, 71 insertions(+), 0 deletions(-)
>> 
>> diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
>> index 6c0a18d..0baf1a4 100644
>> --- a/include/qapi/qmp/qerror.h
>> +++ b/include/qapi/qmp/qerror.h
>> @@ -129,6 +129,9 @@ void assert_no_error(Error *err);
>>  #define QERR_FEATURE_DISABLED \
>>  ERROR_CLASS_GENERIC_ERROR, "The feature '%s' is not enabled"
>>  
>> +#define QERR_GET_TIME_FAILED \
>> +ERROR_CLASS_GENERIC_ERROR, "Failed to get time"
>> +
>
> These days, you shouldn't be defining a new QERR wrapper.  Instead,...[1]
>
>>  
>> +static TimeInfo *get_host_time(Error **errp)
>
> This name is unusual...[2]
>
>> +{
>> +int ret;
>> +qemu_timeval tq;
>> +TimeInfo *time_info;
>> +
>> +ret = qemu_gettimeofday(&tq);
>> +if (ret < 0) {
>> +error_set_errno(errp, errno, QERR_GET_TIME_FAILED);
>
> [1]...use the right idiom here:
>
> error_setg_errno(errp, errno, "Failed to get time");
>
>> +return NULL;
>> +}
>> +
>> +time_info = g_malloc0(sizeof(TimeInfo));
>> +time_info->seconds = tq.tv_sec;
>> +time_info->microseconds = tq.tv_usec;
>
> Is microseconds the right unit to expose through JSON, or are we going
> to wish we had exposed nanoseconds down the road (you can still use
> qemu_gettimeofday() and scale tv_usec by 1000 before assigning to
> time_info->nanoseconds, if we desire the extra granularity).
>
> You aren't setting time_info->utc_offset.  Is that intentional?

Moreover, there's no need to specify microseconds and seconds.  A 64-bit
value for nanoseconds is sufficient.  A signed value can represent
1678 -> 2262.  If anyone is using qemu-ga in 2262, they'll have to
introduce a new command for their quantum emulators :-)

Setting time independent of date is a bit silly because time cannot be
interpreted correctly without a date.

A single value of nanoseconds since the epoch (interpreted as UTC/GMT
time) is really the best strategy.  The host shouldn't be involved in
guest time zones.  In a Cloud environment, it's pretty normal to have
different guests using different time zones.

Regards,

Anthony Liguori

>
>> +
>> +return time_info;
>> +}
>> +
>> +struct TimeInfo *qmp_guest_get_time(Error **errp)
>> +{
>> +TimeInfo *time_info = get_host_time(errp);
>
> [2]...given that it is only ever called from qmp_guest_get_time.
>
>> +
>> +if (!time_info) {
>> +return NULL;
>> +}
>
> These three lines can be deleted,
>
>> +
>> +return time_info;
>
> since this line will do the same thing if you let NULL time_info get
> this far.
>
>> +++ b/qga/qapi-schema.json
>> @@ -83,6 +83,44 @@
>>  { 'command': 'guest-ping' }
>>  
>>  ##
>> +# @TimeInfo
>> +#
>> +# Time Information. It is relative to the Epoch of 1970-01-01.
>> +#
>> +# @seconds: "seconds" time unit.
>> +#
>> +# @microseconds: "microseconds" time unit.
>> +#
>> +# @utc-offset: Information about utc offset. Represented as:
>> +#  ±[] based at a minimum on minutes, with
>
> s/based at a minimum on//
>
> This still doesn't state whether two hours east of UTC is represented as
> 120 or as 0200.
>
>> +#  negative values are west and positive values
>> +#  are east of UTC. The bounds of @utc-offset is
>> +#  at most 24 hours away from UTC.
>> +#
>> +# Since: 1.4
>> +##
>> +{ 'type': 'TimeInfo',
>> +  'data': { 'seconds': 'int', 'microseconds': 'int',
>> +'utc-offset': 'int' } }
>> +
>> +##
>> +# @guest-get-time:
>> +#
>> +# Get the information about host time in UTC and the
>
> s/host/guest/
>
>> +# UTC offset.
>> +#
>> +# This command tries to get the host time which is
>> +# presumably correct, since we need to be able to
>> +# resynchronize guest clock to host's in guest.
>
> This sentence doesn't make sense.  Better would be:
>
> Get the guest's notion of the current time.
>
>> +#
>> +# Returns: @TimeInfo on success.
>> +#
>> +# Since 1.4
>> +##
>> +{ 'command': 'guest-get-time',
>> +  'returns': 'TimeInfo' }
>> +
>> +##
>>  # @GuestAgentCommandInfo:
>>  #
>>  # Information about guest agent commands.
>> 
>
> -- 
> Eric Blake   eblake redhat com+1-919-301-3266
> Libvirt virtualization library http://libvirt.org




Re: [Qemu-devel] [PATCHv4 1/2] qemu-img: find the image end offset during check

2013-01-28 Thread Blue Swirl
On Mon, Jan 28, 2013 at 11:59 AM, Federico Simoncelli
 wrote:
> This patch adds the support for reporting the image end offset (in
> bytes). This is particularly useful after a conversion (or a rebase)
> where the destination is a block device in order to find the first
> unused byte at the end of the image.
>
> Signed-off-by: Federico Simoncelli 
> ---
>  block/qcow2-refcount.c   |   10 --
>  include/block/block.h|1 +
>  qemu-img.c   |4 
>  tests/qemu-iotests/026   |6 +++---
>  tests/qemu-iotests/036   |3 ++-
>  tests/qemu-iotests/039   |2 +-
>  tests/qemu-iotests/044.out   |1 +
>  tests/qemu-iotests/common.rc |5 +++--
>  8 files changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 6a95aa6..45ad043 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -1116,7 +1116,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>BdrvCheckMode fix)
>  {
>  BDRVQcowState *s = bs->opaque;
> -int64_t size, i;
> +int64_t size, i, highest_cluster;
>  int nb_clusters, refcount1, refcount2;
>  QCowSnapshot *sn;
>  uint16_t *refcount_table;
> @@ -1187,7 +1187,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>  }
>
>  /* compare ref counts */
> -for(i = 0; i < nb_clusters; i++) {
> +for(i = 0, highest_cluster = 0; i < nb_clusters; i++) {

Please add a space between 'for' and '('.

>  refcount1 = get_refcount(bs, i);
>  if (refcount1 < 0) {
>  fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": 
> %s\n",
> @@ -1197,6 +1197,11 @@ int qcow2_check_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>  }
>
>  refcount2 = refcount_table[i];
> +
> +if (refcount1 > 0 || refcount2 > 0) {
> +highest_cluster = i;
> +}
> +
>  if (refcount1 != refcount2) {
>
>  /* Check if we're allowed to fix the mismatch */
> @@ -1231,6 +1236,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, 
> BdrvCheckResult *res,
>  }
>  }
>
> +res->image_end_offset = (highest_cluster + 1) * s->cluster_size;
>  ret = 0;
>
>  fail:
> diff --git a/include/block/block.h b/include/block/block.h
> index ffd1936..85eb3d9 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -213,6 +213,7 @@ typedef struct BdrvCheckResult {
>  int check_errors;
>  int corruptions_fixed;
>  int leaks_fixed;
> +int64_t image_end_offset;
>  BlockFragInfo bfi;
>  } BdrvCheckResult;
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 85d3740..e80c1c5 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -475,6 +475,10 @@ static int img_check(int argc, char **argv)
>  result.bfi.fragmented_clusters * 100.0 / 
> result.bfi.allocated_clusters);
>  }
>
> +if (result.image_end_offset > 0) {
> +printf("Image end offset: %" PRId64 "\n", result.image_end_offset);
> +}
> +
>  bdrv_delete(bs);
>
>  if (ret < 0 || result.check_errors) {
> diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
> index 1602ccd..107a3ff 100755
> --- a/tests/qemu-iotests/026
> +++ b/tests/qemu-iotests/026
> @@ -102,7 +102,7 @@ if [ "$event" == "l2_load" ]; then
>  $QEMU_IO -c "read $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
>  fi
>
> -$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
> +_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
>
>  done
>  done
> @@ -147,7 +147,7 @@ echo
>  echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
>  $QEMU_IO -c "write $vmstate 0 64M" $BLKDBG_TEST_IMG | _filter_qemu_io
>
> -$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
> +_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
>
>  done
>  done
> @@ -186,7 +186,7 @@ echo
>  echo "Event: $event; errno: $errno; imm: $imm; once: $once"
>  $QEMU_IO -c "write -b 0 64k" $BLKDBG_TEST_IMG | _filter_qemu_io
>
> -$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
> +_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
>
>  done
>  done
> diff --git a/tests/qemu-iotests/036 b/tests/qemu-iotests/036
> index 329533e..4dbfc57 100755
> --- a/tests/qemu-iotests/036
> +++ b/tests/qemu-iotests/036
> @@ -59,7 +59,8 @@ _make_test_img 64M
>  echo
>  echo === Repair image ===
>  echo
> -$QEMU_IMG check -r all $TEST_IMG
> +_check_test_img -r all
> +
>  ./qcow2.py $TEST_IMG dump-header
>
>  # success, all done
> diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039
> index c5ae806..ae35175 100755
> --- a/tests/qemu-iotests/039
> +++ b/tests/qemu-iotests/039
> @@ -86,7 +86,7 @@ $QEMU_IO -r -c "read -P 0x5a 0 512" $TEST_IMG | 
> _filter_qemu_io
>  echo
>  echo "== Repairing the image file must succeed =="
>
> -$QEMU_IMG check -r all $TEST_IMG
> +_check_test_img -r all
>
>  # The dirty b

Re: [Qemu-devel] [PATCH v2 2/3] VFIO-AER: Vfio-pci driver changes for supporting AER

2013-01-28 Thread Alex Williamson
On Mon, 2013-01-28 at 09:54 +, Pandarathil, Vijaymohan R wrote:
>   - New VFIO_SET_IRQ ioctl option to pass the eventfd that is signalled 
> when
>   an error occurs in the vfio_pci_device
> 
>   - Register pci_error_handler for the vfio_pci driver
> 
>   - When the device encounters an error, the error handler registered by
>   the vfio_pci driver gets invoked by the AER infrastructure
> 
>   - In the error handler, signal the eventfd registered for the device.
> 
>   - This results in the qemu eventfd handler getting invoked and
>   appropriate action taken for the guest.
> 
> Signed-off-by: Vijay Mohan Pandarathil 
> ---
>  drivers/vfio/pci/vfio_pci.c | 44 
> -
>  drivers/vfio/pci/vfio_pci_intrs.c   | 32 +++
>  drivers/vfio/pci/vfio_pci_private.h |  1 +
>  include/uapi/linux/vfio.h   |  3 +++
>  4 files changed, 79 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index b28e66c..ff2a078 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -196,7 +196,9 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device 
> *vdev, int irq_type)
>  
>   return (flags & PCI_MSIX_FLAGS_QSIZE) + 1;
>   }
> - }
> + } else if (irq_type == VFIO_PCI_ERR_IRQ_INDEX)
> + if (pci_is_pcie(vdev->pdev))
> + return 1;
>  
>   return 0;
>  }
> @@ -223,9 +225,18 @@ static long vfio_pci_ioctl(void *device_data,
>   if (vdev->reset_works)
>   info.flags |= VFIO_DEVICE_FLAGS_RESET;
>  
> + if (pci_is_pcie(vdev->pdev)) {
> + info.flags |= VFIO_DEVICE_FLAGS_PCI_AER;
> + info.flags |= VFIO_DEVICE_FLAGS_PCI_AER_NOTIFY;

Not sure this second flag should be AER specific or if it's even needed,
see below for more comments on this.

> + }
> +
>   info.num_regions = VFIO_PCI_NUM_REGIONS;
>   info.num_irqs = VFIO_PCI_NUM_IRQS;
>  
> + /* Expose only implemented IRQs */
> + if (!(info.flags & VFIO_DEVICE_FLAGS_PCI_AER_NOTIFY))
> + info.num_irqs--;

I'm having second thoughts on this, see further below.

> +
>   return copy_to_user((void __user *)arg, &info, minsz);
>  
>   } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> @@ -302,6 +313,10 @@ static long vfio_pci_ioctl(void *device_data,
>   if (info.argsz < minsz || info.index >= VFIO_PCI_NUM_IRQS)
>   return -EINVAL;
>  
> + if ((info.index == VFIO_PCI_ERR_IRQ_INDEX) &&
> +  !pci_is_pcie(vdev->pdev))
> + return -EINVAL;
> +

Perhaps we could incorporate the index test above this too?

switch (info.index) {
case VFIO_PCI_INTX_IRQ_INDEX: ... VFIO_PCI_MSIX_IRQ_INDEX:
break;
case VFIO_PCI_ERR_IRQ_INDEX:
if (pci_is_pcie(vdev->pdev))
break;
default:
return -EINVAL;
}

This is more similar to how I've re-written the same for the proposed
VGA/legacy I/O support.

>   info.flags = VFIO_IRQ_INFO_EVENTFD;
>  
>   info.count = vfio_pci_get_irq_count(vdev, info.index);
> @@ -538,11 +553,38 @@ static void vfio_pci_remove(struct pci_dev *pdev)
>   kfree(vdev);
>  }
>  
> +static pci_ers_result_t vfio_err_detected(struct pci_dev *pdev,
> + pci_channel_state_t state)

This is actually AER specific, right?  So perhaps it should be
vfio_pci_aer_err_detected?

Also, please follow existing whitespace usage throughout, tabs followed
by spaces to align function parameter wrap.

> +{
> + struct vfio_pci_device *vpdev;
> + void *vdev;

struct vfio_device *vdev;

> +
> + vdev = vfio_device_get_from_dev(&pdev->dev);
> + if (vdev == NULL)
> + return PCI_ERS_RESULT_DISCONNECT;
> +
> + vpdev = vfio_device_data(vdev);
> + if (vpdev == NULL)
> + return PCI_ERS_RESULT_DISCONNECT;
> +
> + if (vpdev->err_trigger)
> + eventfd_signal(vpdev->err_trigger, 1);
> +
> + vfio_device_put_vdev(vdev);
> +
> + return PCI_ERS_RESULT_CAN_RECOVER;
> +}
> +
> +static const struct pci_error_handlers vfio_err_handlers = {
> + .error_detected = vfio_err_detected,
> +};
> +
>  static struct pci_driver vfio_pci_driver = {
>   .name   = "vfio-pci",
>   .id_table   = NULL, /* only dynamic ids */
>   .probe  = vfio_pci_probe,
>   .remove = vfio_pci_remove,
> + .err_handler= &vfio_err_handlers,
>  };
>  
>  static void __exit vfio_pci_cleanup(void)
> diff --git a/drivers/vfio/pci/vfio_pci_intrs.c 
> b/drivers/vfio/pci/vfio_pci_intrs.c
> index 3639371..f003e08 100644
> --- a/drivers/vfio/pci/vfio_pci_intrs.c
> +++ b/drivers/vfio/pci/vfio_pci_intrs.c
> @@ -745,6 +745,31 @@ static int vfio_pci_se

Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Andreas Färber
Am 28.01.2013 19:22, schrieb Richard Henderson:
> On 01/27/2013 05:32 AM, Andreas Färber wrote:
>> Make LOG_DISAS() arguments compile-testable even if disabled.
>>
>> Signed-off-by: Andreas Färber 
>> ---
>>   target-alpha/translate.c |   12 ++--
>>   1 Datei geändert, 6 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)
> 
> Acked-by: Richard Henderson 
> 
>> +#define LOG_DISAS(...) G_STMT_START \
>> +if (ALPHA_DEBUG_DISAS) { \
>> +qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
>> +} \
>> +G_STMT_END
> 
> I see zero advantage to using G_STMT_START/END over the
> shorter and significantly more obvious direct use of do/while.

Well, I see close to zero advantage in using a loop at all. We could
just as well review all callers and just code the pure logic. An inline
function by comparison would relieve us from all that \ ugliness, too.

> We just zapped useless gtype typedefs.  Do we have to add
> yet another useless glib thing?

We didn't. It was proposed and rejected in that form.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH 0/2] Improve 128-bit multiply primitives

2013-01-28 Thread Andreas Färber
Am 28.01.2013 19:52, schrieb Richard Henderson:
> Richard Henderson (2):
>   host-utils: Use __int128 for mul[us]64
>   host-utils: Improve mulu64 and muls64

Please fix Coding Style warnings in the latter (e.g., no space before
parenthesis, spacing aroung = ).

More importantly I wonder if we could get unit tests for such code being
refactored?

Andreas

>  configure |  20 +
>  include/qemu/host-utils.h |  17 
>  util/host-utils.c | 102 
> ++
>  3 files changed, 68 insertions(+), 71 deletions(-)

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Andreas Färber
Am 28.01.2013 19:59, schrieb Peter Maydell:
> On 28 January 2013 18:54, Andreas Färber  wrote:
>> Am 28.01.2013 19:22, schrieb Richard Henderson:
>>> On 01/27/2013 05:32 AM, Andreas Färber wrote:
 +#define LOG_DISAS(...) G_STMT_START \
 +if (ALPHA_DEBUG_DISAS) { \
 +qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
 +} \
 +G_STMT_END
>>>
>>> I see zero advantage to using G_STMT_START/END over the
>>> shorter and significantly more obvious direct use of do/while.
>>
>> Well, I see close to zero advantage in using a loop at all.
> 
> Er, what? "do ... while (0)" is completely standard practice
> for writing robust macros in C. Patches which don't do that
> should fail code review.

Oh really? None of our QOM cast macros use it, they passed your review,
and there is zero reason to bring that plague upon us for any reasonably
small macro. Anything larger in most use cases outside core TCG code is
an overuse of macros.

Misusing the memread() macros for instance gives you weird compiler
messages simply because it is in fact seeing qtest_memread() instead
with 1-shifted arguments. Those should be static inline functions
accessing a global variable IMO.

I simply didn't think of va_list here when hacking this RFC together.

Andreas

>> An inline function by comparison would relieve us from
>> all that \ ugliness, too.
> 
> This is a completely separate argument.
>  C macro with do..while(0): OK
>  inline function: also OK
>  C macro missing do..while(0) protection: not OK
>  C macro using glib obfuscated macros: also not OK
> 
> -- PMM

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH 1/2] host-utils: Use __int128 for mul[us]64

2013-01-28 Thread Richard Henderson

On 01/28/2013 11:02 AM, Peter Maydell wrote:

Have you written the test like this because you know
there are compilers out there that implement addition
but not multiplication (or unsigned but not signed, or
whatever), or just out of a vague sense of caution?


Vague sense of caution.  I tried to use all of the things
that I was actually going to use in the qemu source.


r~



Re: [Qemu-devel] [PATCH 1/2] host-utils: Use __int128 for mul[us]64

2013-01-28 Thread Peter Maydell
On 28 January 2013 18:52, Richard Henderson  wrote:
> Replace some x86_64 specific inline assembly with something that
> all 64-bit hosts ought to optimize well.  At worst this becomes a
> call to the gcc __multi3 routine, which is no worse than our
> implementation in util/host-utils.c.

Hurrah for dropping inline assembly.

> +
> +# check if __int128 is usable.
> +
> +int128=no
> +cat > $TMPC << EOF
> +int main (void) {
> +  __int128 a = 0;
> +  unsigned __int128 b = 1;
> +  a = a + b;
> +  a = a * b;
> +  return 0;
> +}

Have you written the test like this because you know
there are compilers out there that implement addition
but not multiplication (or unsigned but not signed, or
whatever), or just out of a vague sense of caution?

-- PMM



Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Andreas Färber
Am 28.01.2013 19:29, schrieb Peter Maydell:
> On 28 January 2013 18:22, Richard Henderson  wrote:
>> On 01/27/2013 05:32 AM, Andreas Färber wrote:
>>> +#define LOG_DISAS(...) G_STMT_START \
>>> +if (ALPHA_DEBUG_DISAS) { \
>>> +qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
>>> +} \
>>> +G_STMT_END
>>
>>
>> I see zero advantage to using G_STMT_START/END over the
>> shorter and significantly more obvious direct use of do/while.
> 
> Strong agreement -- G_STMT_START/END is just pointless
> obfuscation without even the rationale of matching a
> glib interface.

I happened to know them from another project and think their semantic is
much more clear if you read them out loud: statement start .. end vs. do
... while zero. We don't semantically want a loop, we use it as error
detection tool, it could just as well be (__extension__({...})) or
whatever funkiness of the day there is. :) A macro can be redefined,
replacing do { ... } while (0) is manual work.

I wouldn't mind a Q... or QEMU_... macro if you oppose the G, but best
if we can avoid it in the first place!

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Peter Maydell
On 28 January 2013 18:54, Andreas Färber  wrote:
> Am 28.01.2013 19:22, schrieb Richard Henderson:
>> On 01/27/2013 05:32 AM, Andreas Färber wrote:
>>> +#define LOG_DISAS(...) G_STMT_START \
>>> +if (ALPHA_DEBUG_DISAS) { \
>>> +qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
>>> +} \
>>> +G_STMT_END
>>
>> I see zero advantage to using G_STMT_START/END over the
>> shorter and significantly more obvious direct use of do/while.
>
> Well, I see close to zero advantage in using a loop at all.

Er, what? "do ... while (0)" is completely standard practice
for writing robust macros in C. Patches which don't do that
should fail code review.

> An inline function by comparison would relieve us from
> all that \ ugliness, too.

This is a completely separate argument.
 C macro with do..while(0): OK
 inline function: also OK
 C macro missing do..while(0) protection: not OK
 C macro using glib obfuscated macros: also not OK

-- PMM



[Qemu-devel] [PATCH 1/2] host-utils: Use __int128 for mul[us]64

2013-01-28 Thread Richard Henderson
Replace some x86_64 specific inline assembly with something that
all 64-bit hosts ought to optimize well.  At worst this becomes a
call to the gcc __multi3 routine, which is no worse than our
implementation in util/host-utils.c.

With gcc 4.7, we get identical code generation for x86_64.  We
now get native multiplication on ia64 and s390x hosts.  With minor
improvements to gcc we can get it for ppc64 as well.

Signed-off-by: Richard Henderson 
---
 configure | 20 
 include/qemu/host-utils.h | 17 -
 util/host-utils.c |  4 ++--
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/configure b/configure
index b7635e4..ecf1cbc 100755
--- a/configure
+++ b/configure
@@ -3150,6 +3150,22 @@ if compile_prog "" "" ; then
 cpuid_h=yes
 fi
 
+
+# check if __int128 is usable.
+
+int128=no
+cat > $TMPC << EOF
+int main (void) {
+  __int128 a = 0;
+  unsigned __int128 b = 1;
+  a = a + b;
+  a = a * b;
+  return 0;
+}
+EOF
+if compile_prog "" "" ; then
+int128=yes
+fi
 
 ##
 # End of CC checks
@@ -3692,6 +3708,10 @@ if test "$cpuid_h" = "yes" ; then
   echo "CONFIG_CPUID_H=y" >> $config_host_mak
 fi
 
+if test "$int128" = "yes" ; then
+  echo "CONFIG_INT128=y" >> $config_host_mak
+fi
+
 if test "$glusterfs" = "yes" ; then
   echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
 fi
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 81c9a75..01f6610 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -27,22 +27,21 @@
 
 #include "qemu/compiler.h"   /* QEMU_GNUC_PREREQ */
 
-#if defined(__x86_64__)
-#define __HAVE_FAST_MULU64__
+#ifdef CONFIG_INT128
 static inline void mulu64(uint64_t *plow, uint64_t *phigh,
   uint64_t a, uint64_t b)
 {
-__asm__ ("mul %0\n\t"
- : "=d" (*phigh), "=a" (*plow)
- : "a" (a), "0" (b));
+unsigned __int128 r = (unsigned __int128)a * b;
+*plow = r;
+*phigh = r >> 64;
 }
-#define __HAVE_FAST_MULS64__
+
 static inline void muls64(uint64_t *plow, uint64_t *phigh,
   int64_t a, int64_t b)
 {
-__asm__ ("imul %0\n\t"
- : "=d" (*phigh), "=a" (*plow)
- : "a" (a), "0" (b));
+__int128 r = (__int128)a * b;
+*plow = r;
+*phigh = r >> 64;
 }
 #else
 void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, int64_t b);
diff --git a/util/host-utils.c b/util/host-utils.c
index 5e3915a..2d06a2c 100644
--- a/util/host-utils.c
+++ b/util/host-utils.c
@@ -30,7 +30,7 @@
 //#define DEBUG_MULDIV
 
 /* Long integer helpers */
-#if !defined(__x86_64__)
+#ifndef CONFIG_INT128
 static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
 {
 *plow += a;
@@ -102,4 +102,4 @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, 
int64_t b)
a, b, *phigh, *plow);
 #endif
 }
-#endif /* !defined(__x86_64__) */
+#endif /* !CONFIG_INT128 */
-- 
1.7.11.7




[Qemu-devel] [PATCH 2/2] host-utils: Improve mulu64 and muls64

2013-01-28 Thread Richard Henderson
The new formulation makes better use of add-with-carry type insns
that the host may have.  Use gcc's sign adjustment trick to avoid
having to perform a 128-bit negation.

Signed-off-by: Richard Henderson 
---
 util/host-utils.c | 98 +--
 1 file changed, 38 insertions(+), 60 deletions(-)

diff --git a/util/host-utils.c b/util/host-utils.c
index 2d06a2c..3908b3a 100644
--- a/util/host-utils.c
+++ b/util/host-utils.c
@@ -27,79 +27,57 @@
 #include 
 #include "qemu/host-utils.h"
 
-//#define DEBUG_MULDIV
-
 /* Long integer helpers */
 #ifndef CONFIG_INT128
-static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
-{
-*plow += a;
-/* carry test */
-if (*plow < a)
-(*phigh)++;
-*phigh += b;
-}
-
-static void neg128 (uint64_t *plow, uint64_t *phigh)
-{
-*plow = ~*plow;
-*phigh = ~*phigh;
-add128(plow, phigh, 1, 0);
-}
-
-static void mul64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
+/* Unsigned 64x64 -> 128 multiplication */
+inline void mulu64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
 {
-uint32_t a0, a1, b0, b1;
-uint64_t v;
-
-a0 = a;
-a1 = a >> 32;
-
-b0 = b;
-b1 = b >> 32;
+typedef union {
+uint64_t ll;
+struct {
+#ifdef HOST_WORDS_BIGENDIAN
+uint32_t high, low;
+#else
+uint32_t low, high;
+#endif
+} l;
+} LL;
+LL rl, rm, rn, rh, a0, b0;
+uint64_t c;
 
-v = (uint64_t)a0 * (uint64_t)b0;
-*plow = v;
-*phigh = 0;
+a0.ll = a;
+b0.ll = b;
 
-v = (uint64_t)a0 * (uint64_t)b1;
-add128(plow, phigh, v << 32, v >> 32);
+rl.ll= (uint64_t)a0.l.low * (uint64_t)b0.l.low;
+rm.ll = (uint64_t)a0.l.low * (uint64_t)b0.l.high;
+rn.ll = (uint64_t)a0.l.high * (uint64_t)b0.l.low;
+rh.ll = (uint64_t)a0.l.high * (uint64_t)b0.l.high;
 
-v = (uint64_t)a1 * (uint64_t)b0;
-add128(plow, phigh, v << 32, v >> 32);
+c = (uint64_t)rl.l.high + rm.l.low + rn.l.low;
+rl.l.high = c;
+c >>= 32;
+c += (uint64_t)rm.l.high + rn.l.high + rh.l.low;
+rh.l.low = c;
+rh.l.high += (uint32_t)(c >> 32);
 
-v = (uint64_t)a1 * (uint64_t)b1;
-*phigh += v;
-}
-
-/* Unsigned 64x64 -> 128 multiplication */
-void mulu64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
-{
-mul64(plow, phigh, a, b);
-#if defined(DEBUG_MULDIV)
-printf("mulu64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
-   a, b, *phigh, *plow);
-#endif
+*plow = rl.ll;
+*phigh = rh.ll;
 }
 
 /* Signed 64x64 -> 128 multiplication */
 void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
 {
-int sa, sb;
+uint64_t rh;
+
+mulu64(plow, &rh, a, b);
 
-sa = (a < 0);
-if (sa)
-a = -a;
-sb = (b < 0);
-if (sb)
-b = -b;
-mul64(plow, phigh, a, b);
-if (sa ^ sb) {
-neg128(plow, phigh);
+/* Adjust for signs.  */
+if (b < 0) {
+rh -= a;
 }
-#if defined(DEBUG_MULDIV)
-printf("muls64: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
-   a, b, *phigh, *plow);
-#endif
+if (a < 0) {
+rh -= b;
+}
+*phigh = rh;
 }
 #endif /* !CONFIG_INT128 */
-- 
1.7.11.7




[Qemu-devel] [PATCH 0/2] Improve 128-bit multiply primitives

2013-01-28 Thread Richard Henderson
This improves code generation for mul[us]64 for all hosts.

In the case of ia64 and s390x we see immediate benefit as
we get to use the native 128-bit multiply insn.  In the
case of ppc64, we need a patch to gcc to enable this; I
hope to get such a patch into gcc 4.8.0, but it may have
to wait for gcc 4.8.1.

In the case of 32-bit hosts like i386 and arm, the second
patch enables better use of add-with-carry type insns.
Examining both of these targets reveals smaller code that
is also now branchless.

Perhaps this ought to be considered for 1.4?


r~



Richard Henderson (2):
  host-utils: Use __int128 for mul[us]64
  host-utils: Improve mulu64 and muls64

 configure |  20 +
 include/qemu/host-utils.h |  17 
 util/host-utils.c | 102 ++
 3 files changed, 68 insertions(+), 71 deletions(-)

-- 
1.7.11.7




Re: [Qemu-devel] [RFC] Writeable files in fw_cfg

2013-01-28 Thread Anthony Liguori
Gleb Natapov  writes:

> On Mon, Jan 28, 2013 at 10:10:06AM -0600, Anthony Liguori wrote:
>> David Woodhouse  writes:
>> 
>> > On Sun, 2013-01-27 at 18:53 -0600, Anthony Liguori wrote:
>> >> Are you just trying to persist a single blob of a fixed maximum size?
>> >
>> > That would suffice.
>> >
>> >> Why not just have a second flash device then?
>> >
>> > Mostly because flash devices don't actually *work* with KVM.
>> 
>> They absolutely do.  What doesn't work is executing ROM from flash if
>> the ROM cannot be treated as read-only memory.
>> 
>> That's because all we get is a PF in the kernel when trying to execute
>> from unmapped ROM.  There's no way to turn that into MMIO to userspace
>> without switching to running fully in emulation mode.  The x86 emulator
>> is pretty close to complete but work would be needed to fully complete
>> it to make this work.
>> 
> The x86 emulator cannot fetch from MMIO memory today. And protected mode
> emulation is not so complete. We rarely, if ever, need to emulate
> protected mode instructions without memory operands.

Ack.

>
>> We normally handle this by mapping the ROM memory read-only so it can be
>> executed without PF'ing but since the BIOS area is subject to PAM, we
>> can't use this trick for that particular ROM.
> Up until kernel 3.7 there was no support for read-only memory slots. As
> far as I know QEMU still maps ROM as regular RAM to KVM.

Ack.

>> 
>> SeaBIOS has hack to just not use PAM to do BIOS shadowing when running
>> under KVM/QEMU but presumably OVMF lacks this.
> Not sure that such hack exists and why is it needed. BIOS area is always
> writable in KVM. 

shadow.c:
  static void
  make_bios_writable_intel(u16 bdf, u32 pam0)
  {
  int reg = pci_config_readb(bdf, pam0);
  if (!(reg & 0x10)) {
  // QEMU doesn't fully implement the piix shadow capabilities -
  // if ram isn't backing the bios segment when shadowing is
  // disabled, the code itself wont be in memory.  So, run the
  // code from the high-memory flash location.

Normally when shadowing, you set the PAM registers to send read requests
to ROM and write requests to RAM.  You then read the code segment (that
you're executing from) and write that out to RAM and switch to executing
from there.

That's just not possible without treating ROMs as MMIO and sending all
requests down to QEMU.

>> 
>> But in this case, you're using the flash device purely for read/write,
>> not for execution, so there's no limitation at all.
>> 
> Yes, on newer kernel we can use read-only slots to emulate flash. They
> behaves like ROMD: memory on read MMIO on write. On older kernels we can
> use pure MMIO.

Ack.

Regards,

Anthony Liguori

>
> --
>   Gleb.



Re: [Qemu-devel] memcpy speed (Re: [PATCH v2] netmap backend (revised))

2013-01-28 Thread Luigi Rizzo
On Thu, Jan 24, 2013 at 11:24 PM, Stefan Hajnoczi wrote:

> On Thu, Jan 24, 2013 at 6:35 PM, Luigi Rizzo  wrote:
>


> >> >
> >> > never mind, pilot error. in my test program i had swapped the
> >> > arguments to __builtin_memcpy(). With the correct ones,
> >> > __builtin_memcpy()  == bcopy == memcpy on both machines,
> >> > and never faster than the pkt_copy().
> >>
> >> Are the bcopy()/memcpy() calls given a length that is a multiple of 64
> bytes?
> >>
> >> IIUC pkt_copy() assumes 64-byte multiple lengths and that optimization
> >> can matches with memcpy(dst, src, (len + 63) & ~63).  Maybe it helps and
> >> at least ensures they are doing equal amounts of byte copying.
> >
> > the length is a parameter from the command line.
> > For short packets, at least on the i7-2600 and freebsd the pkt_copy()
> > is only slightly faster than memcpy on multiples of 64, and *a lot*
> > faster when the length is not a multiple.
>
> How about dropping pkt_copy() and instead rounding the memcpy() length
> up to the next 64 byte multiple?
>

> Using memcpy() is more future-proof IMO, that's why I'm pushing for this.
>
>
fair enough, i'll make this conditional and enable memcpy() rounded to 64
bytes
multiples by default (though as i said the pkt_copy() is always at least
as fast as memcpy() on all machines i tried.

cheers
luigi


Re: [Qemu-devel] [RFC] Writeable files in fw_cfg

2013-01-28 Thread Gleb Natapov
On Mon, Jan 28, 2013 at 10:10:06AM -0600, Anthony Liguori wrote:
> David Woodhouse  writes:
> 
> > On Sun, 2013-01-27 at 18:53 -0600, Anthony Liguori wrote:
> >> Are you just trying to persist a single blob of a fixed maximum size?
> >
> > That would suffice.
> >
> >> Why not just have a second flash device then?
> >
> > Mostly because flash devices don't actually *work* with KVM.
> 
> They absolutely do.  What doesn't work is executing ROM from flash if
> the ROM cannot be treated as read-only memory.
> 
> That's because all we get is a PF in the kernel when trying to execute
> from unmapped ROM.  There's no way to turn that into MMIO to userspace
> without switching to running fully in emulation mode.  The x86 emulator
> is pretty close to complete but work would be needed to fully complete
> it to make this work.
> 
The x86 emulator cannot fetch from MMIO memory today. And protected mode
emulation is not so complete. We rarely, if ever, need to emulate
protected mode instructions without memory operands.

> We normally handle this by mapping the ROM memory read-only so it can be
> executed without PF'ing but since the BIOS area is subject to PAM, we
> can't use this trick for that particular ROM.
Up until kernel 3.7 there was no support for read-only memory slots. As
far as I know QEMU still maps ROM as regular RAM to KVM.

> 
> SeaBIOS has hack to just not use PAM to do BIOS shadowing when running
> under KVM/QEMU but presumably OVMF lacks this.
Not sure that such hack exists and why is it needed. BIOS area is always
writable in KVM. 

> 
> But in this case, you're using the flash device purely for read/write,
> not for execution, so there's no limitation at all.
> 
Yes, on newer kernel we can use read-only slots to emulate flash. They
behaves like ROMD: memory on read MMIO on write. On older kernels we can
use pure MMIO.

--
Gleb.



Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Peter Maydell
On 28 January 2013 18:22, Richard Henderson  wrote:
> On 01/27/2013 05:32 AM, Andreas Färber wrote:
>> +#define LOG_DISAS(...) G_STMT_START \
>> +if (ALPHA_DEBUG_DISAS) { \
>> +qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
>> +} \
>> +G_STMT_END
>
>
> I see zero advantage to using G_STMT_START/END over the
> shorter and significantly more obvious direct use of do/while.

Strong agreement -- G_STMT_START/END is just pointless
obfuscation without even the rationale of matching a
glib interface.

-- PMM



Re: [Qemu-devel] [PATCH 1/2] qga: add guest-get-time command

2013-01-28 Thread Eric Blake
On 01/27/2013 11:14 AM, Lei Li wrote:
> Signed-off-by: Lei Li 
> ---
>  include/qapi/qmp/qerror.h |3 +++
>  qga/commands-posix.c  |   30 ++
>  qga/qapi-schema.json  |   38 ++
>  3 files changed, 71 insertions(+), 0 deletions(-)
> 
> diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
> index 6c0a18d..0baf1a4 100644
> --- a/include/qapi/qmp/qerror.h
> +++ b/include/qapi/qmp/qerror.h
> @@ -129,6 +129,9 @@ void assert_no_error(Error *err);
>  #define QERR_FEATURE_DISABLED \
>  ERROR_CLASS_GENERIC_ERROR, "The feature '%s' is not enabled"
>  
> +#define QERR_GET_TIME_FAILED \
> +ERROR_CLASS_GENERIC_ERROR, "Failed to get time"
> +

These days, you shouldn't be defining a new QERR wrapper.  Instead,...[1]

>  
> +static TimeInfo *get_host_time(Error **errp)

This name is unusual...[2]

> +{
> +int ret;
> +qemu_timeval tq;
> +TimeInfo *time_info;
> +
> +ret = qemu_gettimeofday(&tq);
> +if (ret < 0) {
> +error_set_errno(errp, errno, QERR_GET_TIME_FAILED);

[1]...use the right idiom here:

error_setg_errno(errp, errno, "Failed to get time");

> +return NULL;
> +}
> +
> +time_info = g_malloc0(sizeof(TimeInfo));
> +time_info->seconds = tq.tv_sec;
> +time_info->microseconds = tq.tv_usec;

Is microseconds the right unit to expose through JSON, or are we going
to wish we had exposed nanoseconds down the road (you can still use
qemu_gettimeofday() and scale tv_usec by 1000 before assigning to
time_info->nanoseconds, if we desire the extra granularity).

You aren't setting time_info->utc_offset.  Is that intentional?

> +
> +return time_info;
> +}
> +
> +struct TimeInfo *qmp_guest_get_time(Error **errp)
> +{
> +TimeInfo *time_info = get_host_time(errp);

[2]...given that it is only ever called from qmp_guest_get_time.

> +
> +if (!time_info) {
> +return NULL;
> +}

These three lines can be deleted,

> +
> +return time_info;

since this line will do the same thing if you let NULL time_info get
this far.

> +++ b/qga/qapi-schema.json
> @@ -83,6 +83,44 @@
>  { 'command': 'guest-ping' }
>  
>  ##
> +# @TimeInfo
> +#
> +# Time Information. It is relative to the Epoch of 1970-01-01.
> +#
> +# @seconds: "seconds" time unit.
> +#
> +# @microseconds: "microseconds" time unit.
> +#
> +# @utc-offset: Information about utc offset. Represented as:
> +#  ±[] based at a minimum on minutes, with

s/based at a minimum on//

This still doesn't state whether two hours east of UTC is represented as
120 or as 0200.

> +#  negative values are west and positive values
> +#  are east of UTC. The bounds of @utc-offset is
> +#  at most 24 hours away from UTC.
> +#
> +# Since: 1.4
> +##
> +{ 'type': 'TimeInfo',
> +  'data': { 'seconds': 'int', 'microseconds': 'int',
> +'utc-offset': 'int' } }
> +
> +##
> +# @guest-get-time:
> +#
> +# Get the information about host time in UTC and the

s/host/guest/

> +# UTC offset.
> +#
> +# This command tries to get the host time which is
> +# presumably correct, since we need to be able to
> +# resynchronize guest clock to host's in guest.

This sentence doesn't make sense.  Better would be:

Get the guest's notion of the current time.

> +#
> +# Returns: @TimeInfo on success.
> +#
> +# Since 1.4
> +##
> +{ 'command': 'guest-get-time',
> +  'returns': 'TimeInfo' }
> +
> +##
>  # @GuestAgentCommandInfo:
>  #
>  # Information about guest agent commands.
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros

2013-01-28 Thread Richard Henderson

On 01/27/2013 05:32 AM, Andreas Färber wrote:

Make LOG_DISAS() arguments compile-testable even if disabled.

Signed-off-by: Andreas Färber 
---
  target-alpha/translate.c |   12 ++--
  1 Datei geändert, 6 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)


Acked-by: Richard Henderson 


+#define LOG_DISAS(...) G_STMT_START \
+if (ALPHA_DEBUG_DISAS) { \
+qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
+} \
+G_STMT_END


I see zero advantage to using G_STMT_START/END over the
shorter and significantly more obvious direct use of do/while.

We just zapped useless gtype typedefs.  Do we have to add
yet another useless glib thing?


r~




[Qemu-devel] [PATCH V2 4/4] block: Optionally block drivers to optionally reopen images after snapshot creation.

2013-01-28 Thread Benoît Canet
Protocols like quorum will be able to queue multiple reopens.

Signed-off-by: Benoit Canet 
---
 block.c   |   25 +
 blockdev.c|5 +++--
 include/block/block.h |2 ++
 include/block/block_int.h |3 +++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 843583f..e46a106 100644
--- a/block.c
+++ b/block.c
@@ -4652,3 +4652,28 @@ void bdrv_ext_snapshot_img_create(BlockDriverState 
*old_bs,
 options, img_size,
 flags, errp);
 }
+
+int bdrv_ext_snapshot_reopen(BlockDriverState *bs, int bdrv_flags,
+ Error **errp)
+{
+Error *local_err = NULL;
+int ret = -ENOTSUP;
+
+if (!bs->file || !bs->file->drv) {
+error_setg(errp, "Block driver not reachable.");
+return ret;
+}
+
+if (!bs->file->drv->bdrv_ext_snapshot_reopen) {
+ret = bdrv_reopen(bs, bdrv_flags, &local_err);
+} else {
+ret = bs->file->drv->bdrv_ext_snapshot_reopen(bs, bdrv_flags,
+  &local_err);
+}
+
+if (error_is_set(&local_err)) {
+error_propagate(errp, local_err);
+}
+
+return ret;
+}
diff --git a/blockdev.c b/blockdev.c
index b1f388b..e9d235b 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -817,8 +817,9 @@ void qmp_transaction(BlockdevActionList *dev_list, Error 
**errp)
 /* We don't need (or want) to use the transactional
  * bdrv_reopen_multiple() across all the entries at once, because we
  * don't want to abort all of them if one of them fails the reopen */
-bdrv_reopen(states->new_bs, states->new_bs->open_flags & ~BDRV_O_RDWR,
-NULL);
+bdrv_ext_snapshot_reopen(states->new_bs,
+ states->new_bs->open_flags & ~BDRV_O_RDWR,
+ NULL);
 }
 
 /* success */
diff --git a/include/block/block.h b/include/block/block.h
index b7be2d2..d7e7334 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -141,6 +141,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue 
*bs_queue,
 BlockDriverState *bs, int flags);
 int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp);
 int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp);
+int bdrv_ext_snapshot_reopen(BlockDriverState *bs, int bdrv_flags,
+ Error **errp);
 int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
 BlockReopenQueue *queue, Error **errp);
 void bdrv_reopen_commit(BDRVReopenState *reopen_state);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 5bab830..996fd9b 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -209,6 +209,9 @@ struct BlockDriver {
  const char *base_fmt,
  char *options, uint64_t img_size,
  int flags, Error **errp);
+/* optional field */
+int (*bdrv_ext_snapshot_reopen)(BlockDriverState *bs, int bdrv_flags,
+Error **errp);
 
 QLIST_ENTRY(BlockDriver) list;
 };
-- 
1.7.10.4




[Qemu-devel] [PULL 00/37] QOM CPUState patch queue 2013-01-28

2013-01-28 Thread Andreas Färber
Hello,

This is my current QOM CPU patch queue. Please pull.

It includes:
* x86 APIC ID topology fixes,
* -cpu bugfixes related to QOM CPU subtypes for alpha, arm, m68k, or32 and uc32,
* a new QOM accessor object_class_is_abstract(),
* a CPUClass::class_by_name hook and cpu_class_by_name() wrapper,
* various cleanups for x86, m68k, or32, uc32 and KVM.

Another pull is intended before the Hard Freeze to give pending for-1.4 patches
sufficient time for review.

Regards,
Andreas

Cc: Anthony Liguori 
Cc: Eduardo Habkost 
Cc: Igor Mammedov 


The following changes since commit 6034fe7bdb555c43022706e228cde8d52a8b341a:

  xilinx_ethlite: Avoid build warnings in debug code (2013-01-27 01:05:00 +0100)

are available in the git repository at:

  git://github.com/afaerber/qemu-cpu.git qom-cpu

for you to fetch changes up to 290adf38967787bd985a5ec67dc4717e83c29eaa:

  kvm: Pass CPUState to kvm_on_sigbus_vcpu() (2013-01-28 16:57:56 +0100)


Andreas Färber (21):
  target-openrisc: Drop OpenRISCCPUList
  target-openrisc: Clean up triple QOM casts
  target-i386: Simplify cpu_x86_find_by_name()
  target-i386: Drop redundant list of CPU definitions
  cpu: Add model resolution support to CPUClass
  target-arm: Detect attempt to instantiate non-CPU type in cpu_init()
  target-alpha: Detect attempt to instantiate non-CPU type in cpu_init()
  target-m68k: Detect attempt to instantiate non-CPU type in cpu_init()
  target-openrisc: Detect attempt to instantiate non-CPU type in cpu_init()
  target-unicore32: Detect attempt to instantiate non-CPU type in cpu_init()
  qom: Introduce object_class_is_abstract()
  target-alpha: Catch attempt to instantiate abstract type in cpu_init()
  target-arm: Catch attempt to instantiate abstract type in cpu_init()
  target-m68k: Catch attempt to instantiate abstract type in cpu_init()
  target-openrisc: Catch attempt to instantiate abstract type in cpu_init()
  target-unicore32: Catch attempt to instantiate abstract type in cpu_init()
  target-openrisc: Use type_register() instead of type_register_static()
  target-unicore32: Use type_register() instead of type_register_static()
  target-m68k: Use type_register() instead of type_register_static()
  cpu: Unconditionalize CPUState fields
  kvm: Pass CPUState to kvm_on_sigbus_vcpu()

Eduardo Habkost (11):
  kvm: Add fake KVM_FEATURE_CLOCKSOURCE_STABLE_BIT for builds without KVM
  target-i386: Don't set any KVM flag by default if KVM is disabled
  pc: Reverse pc_init_pci() compatibility logic
  kvm: Create kvm_arch_vcpu_id() function
  target-i386: kvm: Set vcpu_id to APIC ID instead of CPU index
  target-i386: Introduce x86_cpu_apic_id_from_index() function
  fw_cfg: Remove FW_CFG_MAX_CPUS from fw_cfg_init()
  cpus.h: Make constant smp_cores/smp_threads available on *-user
  pc: Set fw_cfg data based on APIC ID calculation
  target-i386: Topology & APIC ID utility functions
  pc: Generate APIC IDs according to CPU topology

Igor Mammedov (5):
  target-i386: Print deprecation warning if xlevel < 0x8000
  target-i386: Replace uint32_t vendor fields by vendor string in x86_def_t
  target-i386: Remove vendor_override field from CPUX86State
  target-i386: Set custom features/properties without intermediate x86_def_t
  target-i386: Remove setting tsc-frequency from x86_def_t

 cpus.c |8 +-
 hw/fw_cfg.c|1 -
 hw/pc.c|   40 +++-
 hw/pc_piix.c   |   26 ++-
 hw/ppc/mac_newworld.c  |1 +
 hw/ppc/mac_oldworld.c  |1 +
 hw/sun4m.c |3 +
 hw/sun4u.c |1 +
 include/qom/cpu.h  |   17 +-
 include/qom/object.h   |8 +
 include/sysemu/cpus.h  |7 +
 include/sysemu/kvm.h   |6 +-
 kvm-all.c  |5 +-
 kvm-stub.c |2 +-
 qom/cpu.c  |   13 ++
 qom/object.c   |5 +
 target-alpha/cpu.c |   16 +-
 target-arm/cpu.c   |   18 ++
 target-arm/helper.c|6 +-
 target-i386/cpu.c  |  389 
 target-i386/cpu.h  |   12 +-
 target-i386/kvm.c  |6 +
 target-i386/topology.h |  136 +
 target-m68k/cpu.c  |   20 +-
 target-m68k/helper.c   |6 +-
 target-openrisc/cpu.c  |   36 +++-
 target-openrisc/exception_helper.c |2 +-
 target-openrisc/fpu_helper.c   |   32 +--
 target-openrisc/int_helper.c   |2 +-
 target-openrisc/interrupt_helper.c |2 +-
 target-openrisc/mmu.c  |6 +-
 target-openrisc/sys_hel

[Qemu-devel] [PATCH V2 3/4] blockdev: Allow snapshoting of protocols.

2013-01-28 Thread Benoît Canet
Signed-off-by: Benoit Canet 
---
 blockdev.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index 0ce45c5..b1f388b 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -800,7 +800,8 @@ void qmp_transaction(BlockdevActionList *dev_list, Error 
**errp)
 /* We will manually add the backing_hd field to the bs later */
 states->new_bs = bdrv_new("");
 ret = bdrv_open(states->new_bs, new_image_file,
-flags | BDRV_O_NO_BACKING, drv);
+flags | BDRV_O_NO_BACKING,
+path_has_protocol(new_image_file) ?  NULL : drv);
 if (ret != 0) {
 error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
 goto delete_and_fail;
-- 
1.7.10.4




[Qemu-devel] [PATCH 01/37] target-openrisc: Drop OpenRISCCPUList

2013-01-28 Thread Andreas Färber
It was missed in 92a3136174f60ee45b113296cb2c2a5225b00369 (cpu:
Introduce CPUListState struct) because its naming did not match the
*CPUListState pattern. Use the generalized CPUListState instead.

Signed-off-by: Andreas Färber 
---
 target-openrisc/cpu.c |9 ++---
 1 Datei geändert, 2 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)

diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index 56544d8..7a55112 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -170,11 +170,6 @@ OpenRISCCPU *cpu_openrisc_init(const char *cpu_model)
 return cpu;
 }
 
-typedef struct OpenRISCCPUList {
-fprintf_function cpu_fprintf;
-FILE *file;
-} OpenRISCCPUList;
-
 /* Sort alphabetically by type name, except for "any". */
 static gint openrisc_cpu_list_compare(gconstpointer a, gconstpointer b)
 {
@@ -196,7 +191,7 @@ static gint openrisc_cpu_list_compare(gconstpointer a, 
gconstpointer b)
 static void openrisc_cpu_list_entry(gpointer data, gpointer user_data)
 {
 ObjectClass *oc = data;
-OpenRISCCPUList *s = user_data;
+CPUListState *s = user_data;
 
 (*s->cpu_fprintf)(s->file, "  %s\n",
   object_class_get_name(oc));
@@ -204,7 +199,7 @@ static void openrisc_cpu_list_entry(gpointer data, gpointer 
user_data)
 
 void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf)
 {
-OpenRISCCPUList s = {
+CPUListState s = {
 .file = f,
 .cpu_fprintf = cpu_fprintf,
 };
-- 
1.7.10.4




[Qemu-devel] [PATCH for-1.4] libqtest: Wait for the right child PID after killing QEMU

2013-01-28 Thread Eduardo Habkost
When running "make check" with gcov enabled, we get the following
message:

   hw/tmp105.gcda:cannot open data file, assuming not executed

The problem happens because:

 * tmp105-test exits before QEMU exits, because waitpid() at
   qtest_quit() fails;
 * waitpid() fails because there's another process already
   waiting for the QEMU process;
 * The process that is already waiting for QEMU is the child created by
   qtest_init() to run system();
 * qtest_quit() is incorrectly waiting for the QEMU PID directly instead
   of the child created by qtest_init().

This fixes the problem by sending SIGTERM to QEMU, but waiting for the
child process created by qtest_init() (that exits immediately after QEMU
exits).

Reported-by: Andreas Färber 
Signed-off-by: Eduardo Habkost 
---
 tests/libqtest.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 913fa05..762dec4 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -39,7 +39,8 @@ struct QTestState
 int qmp_fd;
 bool irq_level[MAX_IRQ];
 GString *rx;
-gchar *pid_file;
+gchar *pid_file; /* QEMU PID file */
+int child_pid;   /* Child process created to execute QEMU */
 char *socket_path, *qmp_socket_path;
 };
 
@@ -144,6 +145,7 @@ QTestState *qtest_init(const char *extra_args)
 
 s->rx = g_string_new("");
 s->pid_file = pid_file;
+s->child_pid = pid;
 for (i = 0; i < MAX_IRQ; i++) {
 s->irq_level[i] = false;
 }
@@ -165,8 +167,9 @@ void qtest_quit(QTestState *s)
 
 pid_t pid = qtest_qemu_pid(s);
 if (pid != -1) {
+/* kill QEMU, but wait for the child created by us to run system() */
 kill(pid, SIGTERM);
-waitpid(pid, &status, 0);
+waitpid(s->child_pid, &status, 0);
 }
 
 unlink(s->pid_file);
-- 
1.8.1




[Qemu-devel] [RFC V8 04/13] blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from blkverify.

2013-01-28 Thread Benoît Canet
Signed-off-by: Benoit Canet 
---
 block/blkverify.c |  108 +
 include/qemu-common.h |2 +
 util/iov.c|  103 ++
 3 files changed, 107 insertions(+), 106 deletions(-)

diff --git a/block/blkverify.c b/block/blkverify.c
index a7dd459..8c65425 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -123,110 +123,6 @@ static int64_t blkverify_getlength(BlockDriverState *bs)
 return bdrv_getlength(s->test_file);
 }
 
-/**
- * Check that I/O vector contents are identical
- *
- * @a:  I/O vector
- * @b:  I/O vector
- * @ret:Offset to first mismatching byte or -1 if match
- */
-static ssize_t blkverify_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
-{
-int i;
-ssize_t offset = 0;
-
-assert(a->niov == b->niov);
-for (i = 0; i < a->niov; i++) {
-size_t len = 0;
-uint8_t *p = (uint8_t *)a->iov[i].iov_base;
-uint8_t *q = (uint8_t *)b->iov[i].iov_base;
-
-assert(a->iov[i].iov_len == b->iov[i].iov_len);
-while (len < a->iov[i].iov_len && *p++ == *q++) {
-len++;
-}
-
-offset += len;
-
-if (len != a->iov[i].iov_len) {
-return offset;
-}
-}
-return -1;
-}
-
-typedef struct {
-int src_index;
-struct iovec *src_iov;
-void *dest_base;
-} IOVectorSortElem;
-
-static int sortelem_cmp_src_base(const void *a, const void *b)
-{
-const IOVectorSortElem *elem_a = a;
-const IOVectorSortElem *elem_b = b;
-
-/* Don't overflow */
-if (elem_a->src_iov->iov_base < elem_b->src_iov->iov_base) {
-return -1;
-} else if (elem_a->src_iov->iov_base > elem_b->src_iov->iov_base) {
-return 1;
-} else {
-return 0;
-}
-}
-
-static int sortelem_cmp_src_index(const void *a, const void *b)
-{
-const IOVectorSortElem *elem_a = a;
-const IOVectorSortElem *elem_b = b;
-
-return elem_a->src_index - elem_b->src_index;
-}
-
-/**
- * Copy contents of I/O vector
- *
- * The relative relationships of overlapping iovecs are preserved.  This is
- * necessary to ensure identical semantics in the cloned I/O vector.
- */
-static void blkverify_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src,
-  void *buf)
-{
-IOVectorSortElem sortelems[src->niov];
-void *last_end;
-int i;
-
-/* Sort by source iovecs by base address */
-for (i = 0; i < src->niov; i++) {
-sortelems[i].src_index = i;
-sortelems[i].src_iov = &src->iov[i];
-}
-qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_base);
-
-/* Allocate buffer space taking into account overlapping iovecs */
-last_end = NULL;
-for (i = 0; i < src->niov; i++) {
-struct iovec *cur = sortelems[i].src_iov;
-ptrdiff_t rewind = 0;
-
-/* Detect overlap */
-if (last_end && last_end > cur->iov_base) {
-rewind = last_end - cur->iov_base;
-}
-
-sortelems[i].dest_base = buf - rewind;
-buf += cur->iov_len - MIN(rewind, cur->iov_len);
-last_end = MAX(cur->iov_base + cur->iov_len, last_end);
-}
-
-/* Sort by source iovec index and build destination iovec */
-qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_index);
-for (i = 0; i < src->niov; i++) {
-qemu_iovec_add(dest, sortelems[i].dest_base, src->iov[i].iov_len);
-}
-}
-
 static BlkverifyAIOCB *blkverify_aio_get(BlockDriverState *bs, bool is_write,
  int64_t sector_num, QEMUIOVector 
*qiov,
  int nb_sectors,
@@ -290,7 +186,7 @@ static void blkverify_aio_cb(void *opaque, int ret)
 
 static void blkverify_verify_readv(BlkverifyAIOCB *acb)
 {
-ssize_t offset = blkverify_iovec_compare(acb->qiov, &acb->raw_qiov);
+ssize_t offset = qemu_iovec_compare(acb->qiov, &acb->raw_qiov);
 if (offset != -1) {
 blkverify_err(acb, "contents mismatch in sector %" PRId64,
   acb->sector_num + (int64_t)(offset / BDRV_SECTOR_SIZE));
@@ -308,7 +204,7 @@ static BlockDriverAIOCB 
*blkverify_aio_readv(BlockDriverState *bs,
 acb->verify = blkverify_verify_readv;
 acb->buf = qemu_blockalign(bs->file, qiov->size);
 qemu_iovec_init(&acb->raw_qiov, acb->qiov->niov);
-blkverify_iovec_clone(&acb->raw_qiov, qiov, acb->buf);
+qemu_iovec_clone(&acb->raw_qiov, qiov, acb->buf);
 
 bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors,
blkverify_aio_cb, acb);
diff --git a/include/qemu-common.h b/include/qemu-common.h
index f134629..8906285 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -346,6 +346,8 @@ size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t 
offset,
const void *buf, size_t bytes);
 size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
   

[Qemu-devel] [PATCH 29/37] target-arm: Catch attempt to instantiate abstract type in cpu_init()

2013-01-28 Thread Andreas Färber
This fixes -cpu arm-cpu asserting.

Cc: qemu-sta...@nongnu.org
Acked-by: Peter Maydell 
Signed-off-by: Andreas Färber 
---
 target-arm/cpu.c |3 ++-
 1 Datei geändert, 2 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 57126b6..d1a4c82 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -210,7 +210,8 @@ static ObjectClass *arm_cpu_class_by_name(const char 
*cpu_model)
 }
 
 oc = object_class_by_name(cpu_model);
-if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU)) {
+if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
+object_class_is_abstract(oc)) {
 return NULL;
 }
 return oc;
-- 
1.7.10.4




[Qemu-devel] [PATCH 04/37] target-i386: Don't set any KVM flag by default if KVM is disabled

2013-01-28 Thread Andreas Färber
From: Eduardo Habkost 

This is a cleanup that tries to solve two small issues:

 - We don't need a separate kvm_pv_eoi_features variable just to keep a
   constant calculated at compile-time, and this style would require
   adding a separate variable (that's declared twice because of the
   CONFIG_KVM ifdef) for each feature that's going to be
   enabled/disabled by machine-type compat code.
 - The pc-1.3 code is setting the kvm_pv_eoi flag on cpuid_kvm_features
   even when KVM is disabled at runtime. This small inconsistency in
   the cpuid_kvm_features field isn't a problem today because
   cpuid_kvm_features is ignored by the TCG code, but it may cause
   unexpected problems later when refactoring the CPUID handling code.

This patch eliminates the kvm_pv_eoi_features variable and simply uses
kvm_enabled() inside the enable_kvm_pv_eoi() compat function, so it
enables kvm_pv_eoi only if KVM is enabled. I believe this makes the
behavior of enable_kvm_pv_eoi() clearer and easier to understand.

Signed-off-by: Eduardo Habkost 
Acked-by: Gleb Natapov 
Reviewed-by: Marcelo Tosatti 
Signed-off-by: Andreas Färber 
---
 target-i386/cpu.c |   12 
 1 Datei geändert, 4 Zeilen hinzugefügt(+), 8 Zeilen entfernt(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 376d4c8..ac2ec24 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -206,22 +206,16 @@ typedef struct model_features_t {
 int check_cpuid = 0;
 int enforce_cpuid = 0;
 
-#if defined(CONFIG_KVM)
 static uint32_t kvm_default_features = (1 << KVM_FEATURE_CLOCKSOURCE) |
 (1 << KVM_FEATURE_NOP_IO_DELAY) |
 (1 << KVM_FEATURE_CLOCKSOURCE2) |
 (1 << KVM_FEATURE_ASYNC_PF) |
 (1 << KVM_FEATURE_STEAL_TIME) |
 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT);
-static const uint32_t kvm_pv_eoi_features = (0x1 << KVM_FEATURE_PV_EOI);
-#else
-static uint32_t kvm_default_features = 0;
-static const uint32_t kvm_pv_eoi_features = 0;
-#endif
 
 void enable_kvm_pv_eoi(void)
 {
-kvm_default_features |= kvm_pv_eoi_features;
+kvm_default_features |= (1UL << KVM_FEATURE_PV_EOI);
 }
 
 void host_cpuid(uint32_t function, uint32_t count,
@@ -1602,7 +1596,9 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
 goto out;
 }
 
-def->kvm_features |= kvm_default_features;
+if (kvm_enabled()) {
+def->kvm_features |= kvm_default_features;
+}
 def->ext_features |= CPUID_EXT_HYPERVISOR;
 
 if (cpu_x86_parse_featurestr(def, features) < 0) {
-- 
1.7.10.4




[Qemu-devel] [RFC V8 00/13] Quorum block filter.

2013-01-28 Thread Benoît Canet
This patchset is rebased on top of "cutils: unsigned int parsing functions"
by "Eduardo Habkost".

It must be applied on top of "Pave the way for protocol snapshot creation"

This patchset create a block driver implementing a quorum using total qemu disk
images. Writes are mirrored on the $total files.
For the reading part the $total files are read at the same time and a vote is
done to determine if a qiov version is present $threshold or more times. It then
return this majority version to the upper layers.
When i < $threshold versions of the data are returned by the lower layer the
quorum is broken and the read return -EIO.

The goal of this patchset is to be turned in a QEMU block filter living just
above raw-*.c and below qcow2/qed when the required infrastructure will be done.

Main use of this feature will be people using NFS appliances which can be
subjected to bitflip errors.

This patchset can be used to replace blkverify and the out of tree blkmirror.

usage: -drive
file=quorum:threshold/total:image_1.raw:...:image_total.raw,if=virtio,cache=none

v8: merge qiov in QuorumSingleAIOB [Stefan]

v7.5:
Allow creation of snapshots
Extract utility functions of quorum_open and quorum_close
reorder patches so quorum_open and quorum_close are added last

v7:
parse total and threshold with parse_uint [Eric]
return proper qerrors in quorum_open [Eric]
Use sha256 for comparing blocks [Eric]
Update the rest of the voting function to the new way of doing [Benoît]

V6:
fix commit message of "quorum: Add quorum_open() and quorum_close()." [Eric]
return error after a vote in quorum_co_flush [Eric]
Fix bitrot caused by headers and structures renaming [Benoît]
initialize finished to NULL to prevent crash [Benoît]
convert internal quorum code to uint64_t instead of int64_t [Benoît]

V5:

Eric Blake: revert back separator to ":"
rewrite quorum_getlength

Benoît Canet: use memcmp to compare iovec excepted for the blkverify case
  use strstart to parse argument in open

Benoît Canet (13):
  quorum: Create quorum.c, add QuorumSingleAIOCB and QuorumAIOCB.
  quorum: Create BDRVQuorumState and BlkDriver and do init.
  quorum: Add quorum_aio_writev and its dependencies.
  blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from
blkverify.
  quorum: Add quorum_aio_readv.
  quorum: Add quorum mechanism.
  quorum: Add quorum_getlength().
  quorum: Add quorum_invalidate_cache().
  quorum: Add quorum_co_is_allocated.
  quorum: Add quorum_co_flush().
  quorum: Add quorum_snapshot_img_create.
  quorum: Add quorum_snapshot_reopen.
  quorum: Add quorum_open() and quorum_close().

 block/Makefile.objs   |1 +
 block/blkverify.c |  108 +-
 block/quorum.c|  906 +
 configure |   22 ++
 include/qemu-common.h |2 +
 util/iov.c|  103 ++
 6 files changed, 1036 insertions(+), 106 deletions(-)
 create mode 100644 block/quorum.c

-- 
1.7.10.4




Re: [Qemu-devel] [PATCHv4 2/2] qemu-img: add json output option to the check command

2013-01-28 Thread Eric Blake
On 01/28/2013 04:59 AM, Federico Simoncelli wrote:
> This option --output=[human|json] makes qemu-img check output a human
> or JSON representation at the choice of the user.
> 
> Signed-off-by: Federico Simoncelli 
> ---
>  qapi-schema.json |   46 +++
>  qemu-img-cmds.hx |4 +-
>  qemu-img.c   |  232 
> +++---
>  qemu-img.texi|5 +-
>  4 files changed, 220 insertions(+), 67 deletions(-)

In my earlier review, I suggested splitting this into two patches:
https://lists.gnu.org/archive/html/qemu-devel/2013-01/msg03858.html

But I guess Kevin was okay with it as one patch.  Therefore:

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 35/37] target-m68k: Use type_register() instead of type_register_static()

2013-01-28 Thread Andreas Färber
According to its documentation, type_register_static()'s TypeInfo
argument should exist for the life type of the type.
Therefore use type_register() when registering the list of CPU subtypes.

No functional change with the current implementation.

Cf. 918fd0839eeafc83bd4984364321a947d29041fe for arm.

Signed-off-by: Andreas Färber 
---
 target-m68k/cpu.c |2 +-
 1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index e6df1ee..5c78031 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -162,7 +162,7 @@ static void register_cpu_type(const M68kCPUInfo *info)
 .instance_init = info->instance_init,
 };
 
-type_register_static(&type_info);
+type_register(&type_info);
 }
 
 static const TypeInfo m68k_cpu_type_info = {
-- 
1.7.10.4




[Qemu-devel] [PATCH 09/37] fw_cfg: Remove FW_CFG_MAX_CPUS from fw_cfg_init()

2013-01-28 Thread Andreas Färber
From: Eduardo Habkost 

PC will not use max_cpus for that field, so move it outside the common
code so it can use a different value on PC.

Signed-off-by: Eduardo Habkost 
Signed-off-by: Andreas Färber 
---
 hw/fw_cfg.c   |1 -
 hw/pc.c   |2 +-
 hw/ppc/mac_newworld.c |1 +
 hw/ppc/mac_oldworld.c |1 +
 hw/sun4m.c|3 +++
 hw/sun4u.c|1 +
 6 Dateien geändert, 7 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index bdcd836..02618f2 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -504,7 +504,6 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t 
data_port,
 fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
 fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == 
DT_NOGRAPHIC));
 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
-fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
 fw_cfg_bootsplash(s);
 fw_cfg_reboot(s);
diff --git a/hw/pc.c b/hw/pc.c
index 780b1e4..de53aa4 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -560,7 +560,7 @@ static void *bochs_bios_init(void)
 int i, j;
 
 fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
-
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES,
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 6de810b..065ea87 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -413,6 +413,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args)
 /* No PCI init: the BIOS will do it */
 
 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, machine_arch);
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 9ed303a..2778e45 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -299,6 +299,7 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args)
 /* No PCI init: the BIOS will do it */
 
 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 035a011..9903f44 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -1021,6 +1021,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef 
*hwdef, ram_addr_t RAM_size,
  hwdef->ecc_version);
 
 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
@@ -1665,6 +1666,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef 
*hwdef, ram_addr_t RAM_size,
"Sun4d");
 
 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
@@ -1865,6 +1867,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef 
*hwdef, ram_addr_t RAM_size,
"Sun4c");
 
 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
diff --git a/hw/sun4u.c b/hw/sun4u.c
index b891b84..9fbda29 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -878,6 +878,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
(uint8_t *)&nd_table[0].macaddr);
 
 fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
+fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
-- 
1.7.10.4




Re: [Qemu-devel] [RFC 6/6] tests: Workaround gcov being unable to open .gcda file

2013-01-28 Thread Eduardo Habkost
On Mon, Jan 28, 2013 at 03:26:36PM -0200, Eduardo Habkost wrote:
> On Sat, Jan 26, 2013 at 12:45:15PM +0100, Andreas Färber wrote:
> > Resolve the following error:
> > 
> >   hw/tmp105.gcda:cannot open data file, assuming not executed
> > 
> > by adding a sleep before running gcov after the qtest cases.
> 
> Do you understand why exactly this happens?

I believe I understand what's happening. See the strace output at the
end of this message.

* tmp105-test exits before QEMU exits, because the wait4() call fails.
* the wait4() call fails because there's another process already waiting for
  the QEMU process (7263)
* The process that is already waiting for QEMU is the child created to
  run system()

qtest_quit() is incorrectly waiting for the QEMU PID directly instead of
saving the pid from the fork() call at qtest_init(). Experimental fix:


diff --git a/tests/libqtest.c b/tests/libqtest.c
index 913fa05..4c151cd 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -40,6 +40,7 @@ struct QTestState
 bool irq_level[MAX_IRQ];
 GString *rx;
 gchar *pid_file;
+int child_pid;
 char *socket_path, *qmp_socket_path;
 };
 
@@ -144,6 +145,7 @@ QTestState *qtest_init(const char *extra_args)
 
 s->rx = g_string_new("");
 s->pid_file = pid_file;
+s->child_pid = pid;
 for (i = 0; i < MAX_IRQ; i++) {
 s->irq_level[i] = false;
 }
@@ -165,8 +167,9 @@ void qtest_quit(QTestState *s)
 
 pid_t pid = qtest_qemu_pid(s);
 if (pid != -1) {
-kill(pid, SIGTERM);
-waitpid(pid, &status, 0);
+kill(pid, SIGTERM);/* kill QEMU */
+waitpid(s->child_pid, &status, 0); /* but wait for the child created to
+* run system() */
 }
 
 unlink(s->pid_file);


-

PIDs on the strace output below:

 7254: make
 7259: shell process created by make
 7260, 7262: gtester
 7261: tests/tmp105-test
 7263: the child process created by qtest_init() to run system()
 7264: QEMU


7254  15:36:19.212328 execve("/usr/bin/make", ["make", "check-qtest-arm"], [/* 
65 vars */]) = 0
7259  15:36:21.726961 execve("/bin/sh", ["/bin/sh", "-c", "echo \"GTESTER 
check-qtest-arm\" &"...], [/* 69 vars */] 
7259  15:36:21.727490 <... execve resumed> ) = 0
7254  15:36:21.727517 wait4(-1,  
7259  15:36:21.738632 clone(child_stack=0, 
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0x7f4f3017ba10) = 7260
7259  15:36:21.739563 wait4(-1,  
7260  15:36:21.739712 execve("/usr/bin/gtester", ["gtester", "-k", "-q", 
"-m=quick", "tests/tmp105-test"], [/* 69 vars */]) = 0
7260  15:36:21.744830 clone(child_stack=0, 
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0x7f10a4d3ea10) = 7261
7261  15:36:21.745167 rt_sigaction(SIGTERM, {SIG_DFL, [TERM], 
SA_RESTORER|SA_RESTART, 0x3433e35c20}, {SIG_DFL, [], 0}, 8) = 0
7261  15:36:21.745769 execve("tests/tmp105-test", ["tests/tmp105-test", 
"--quiet", "--keep-going", "-m=quick", "--GTestLogFD=5"], [/* 69 vars */] 

7260  15:36:21.746685 clone(child_stack=0x7f10a4d3cfb0, 
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
 parent_tidptr=0x7f10a4d3d9d0, tls=0x7f10a4d3d700, child_tidptr=0x7f10a4d3d9d0) 
= 7262
7260  15:36:21.746813 wait4(7261, 0xe76664, WNOHANG, NULL) = 0
7261  15:36:21.746886 <... execve resumed> ) = 0
7261  15:36:21.776429 clone(child_stack=0, 
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0x7fa1e0996b50) = 7263
7263  15:36:21.776975 clone( 
7263  15:36:21.777228 <... clone resumed> child_stack=0, 
flags=CLONE_PARENT_SETTID|SIGCHLD, parent_tidptr=0x7fff6f5439e0) = 7264
7263  15:36:21.777249 wait4(7264,  

 HERE


7264  15:36:21.777315 execve("/bin/sh", ["sh", "-c", 
"arm-softmmu/qemu-system-arm -qte"...], [/* 69 vars */]) = 0
7264  15:36:21.781756 execve("arm-softmmu/qemu-system-arm", 
["arm-softmmu/qemu-system-arm", "-qtest", "unix:/tmp/qtest-7261.sock,nowait", 
"-qtest-log", "/dev/null", "-qmp", "unix:/tmp/qtest-7261.qmp,nowait", 
"-pidfile", "/tmp/qtest-7261.pid", "-machine", "accel=qtest", "-display", 
"none", "-machine", "n800"], [/* 69 vars */]) = 0
7264  15:36:21.852206 clone(child_stack=0x7f39d6424fb0, 
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
 parent_tidptr=0x7f39d64279d0, tls=0x7f39d6427700, child_tidptr=0x7f39d64279d0) 
= 7265
7260  15:36:22.107937 write(-1, "  
7261  15:36:22.107964 kill(7264, SIGTERM 
7261  15:36:22.108004 wait4(7264,  

 HERE

7264  15:36:22.108016 --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, 
si_pid=7261, si_uid=500} ---
7261  15:36:22.108026 <... wait4 resumed> 0x7fff6f543bb0, 0, NULL) = -1 ECHILD 
(No child processes)

^ 
HERE

7261  15:36:22.1103

Re: [Qemu-devel] [PATCH V2 2/4] block: make path_hash_protocol public.

2013-01-28 Thread Eric Blake
On 01/28/2013 10:04 AM, Benoît Canet wrote:
> Signed-off-by: Benoit Canet 
> ---
>  block.c   |2 +-
>  include/block/block.h |1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)

s/hash/has/ in the subject line.


>  /* check if the path starts with ":" */
> -static int path_has_protocol(const char *path)
> +int path_has_protocol(const char *path)
>  {

While you are touching this function, does it make sense to change it to
return 'bool' instead of 'int'?

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [RFC V8 09/13] quorum: Add quorum_co_is_allocated.

2013-01-28 Thread Benoît Canet
Signed-off-by: Benoit Canet 
---
 block/quorum.c |   53 +
 1 file changed, 53 insertions(+)

diff --git a/block/quorum.c b/block/quorum.c
index 1c50ed5..459434f 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -134,6 +134,22 @@ static int quorum_sha256_compare(QuorumVoteValue *a, 
QuorumVoteValue *b)
 return memcmp(a, b, HASH_LENGTH);
 }
 
+static int quorum_long_compare(QuorumVoteValue *a, QuorumVoteValue *b)
+{
+unsigned long i = a->l;
+unsigned long j = b->l;
+
+if (i < j) {
+return -1;
+}
+
+if (i > j) {
+return 1;
+}
+
+return 0;
+}
+
 static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
BlockDriverState *bs,
QEMUIOVector *qiov,
@@ -525,6 +541,42 @@ static void quorum_invalidate_cache(BlockDriverState *bs)
 }
 }
 
+static int coroutine_fn quorum_co_is_allocated(BlockDriverState *bs,
+   int64_t sector_num,
+   int nb_sectors,
+   int *pnum)
+{
+BDRVQuorumState *s = bs->opaque;
+QuorumVoteVersion *winner = NULL;
+QuorumVotes result_votes, num_votes;
+QuorumVoteValue result_value, num_value;
+int i, result = 0, num;
+
+QLIST_INIT(&result_votes.vote_list);
+QLIST_INIT(&num_votes.vote_list);
+result_votes.compare = quorum_long_compare;
+num_votes.compare = quorum_long_compare;
+
+for (i = 0; i < s->total; i++) {
+result = bdrv_co_is_allocated(s->bs[i], sector_num, nb_sectors, &num);
+result_value.l = result;
+num_value.l = num;
+quorum_count_vote(&result_votes, &result_value, i);
+quorum_count_vote(&num_votes, &num_value, i);
+}
+
+winner = quorum_get_vote_winner(&result_votes);
+result = winner->value.l;
+
+winner = quorum_get_vote_winner(&num_votes);
+*pnum = winner->value.l;
+
+quorum_free_vote_list(&result_votes);
+quorum_free_vote_list(&num_votes);
+
+return result;
+}
+
 static BlockDriver bdrv_quorum = {
 .format_name= "quorum",
 .protocol_name  = "quorum",
@@ -536,6 +588,7 @@ static BlockDriver bdrv_quorum = {
 .bdrv_aio_readv = quorum_aio_readv,
 .bdrv_aio_writev= quorum_aio_writev,
 .bdrv_invalidate_cache = quorum_invalidate_cache,
+.bdrv_co_is_allocated  = quorum_co_is_allocated,
 };
 
 static void bdrv_quorum_init(void)
-- 
1.7.10.4




[Qemu-devel] [PATCH V2 1/4] block: Add option to do external snapshot image creation in the block drivers.

2013-01-28 Thread Benoît Canet
This patch will allow protocols to implements snapshots as the image creation
can now delegated to the block driver.

Signed-off-by: Benoit Canet 
---
 block.c   |   26 ++
 blockdev.c|8 
 include/block/block.h |6 ++
 include/block/block_int.h |8 
 4 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/block.c b/block.c
index 6fa7c90..41a9ac0 100644
--- a/block.c
+++ b/block.c
@@ -4626,3 +4626,29 @@ out:
 bdrv_delete(bs);
 }
 }
+
+void bdrv_ext_snapshot_img_create(BlockDriverState *old_bs,
+  const char *filename, const char *fmt,
+  const char *base_filename,
+  const char *base_fmt,
+  char *options, uint64_t img_size,
+  int flags, Error **errp)
+{
+if (!old_bs || !old_bs->file || !old_bs->file->drv) {
+error_setg(errp, "Block driver not reachable.");
+return;
+}
+
+if (!old_bs->file->drv->bdrv_ext_snapshot_img_create) {
+bdrv_img_create(filename, fmt, base_filename, base_fmt, options,
+img_size, flags, errp);
+return;
+}
+
+old_bs->file->drv->bdrv_ext_snapshot_img_create(old_bs,
+filename, fmt,
+base_filename,
+base_fmt,
+options, img_size,
+flags, errp);
+}
diff --git a/blockdev.c b/blockdev.c
index 9126587..0ce45c5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -787,10 +787,10 @@ void qmp_transaction(BlockdevActionList *dev_list, Error 
**errp)
 
 /* create new image w/backing file */
 if (mode != NEW_IMAGE_MODE_EXISTING) {
-bdrv_img_create(new_image_file, format,
-states->old_bs->filename,
-states->old_bs->drv->format_name,
-NULL, -1, flags, &local_err);
+bdrv_ext_snapshot_img_create(states->old_bs, new_image_file, 
format,
+ states->old_bs->filename,
+ states->old_bs->drv->format_name,
+ NULL, -1, flags, &local_err);
 if (error_is_set(&local_err)) {
 error_propagate(errp, local_err);
 goto delete_and_fail;
diff --git a/include/block/block.h b/include/block/block.h
index ffd1936..12470fc 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -346,6 +346,12 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
 void 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, Error 
**errp);
+void bdrv_ext_snapshot_img_create(BlockDriverState *old_bs,
+  const char *filename, const char *fmt,
+  const char *base_filename,
+  const char *base_fmt,
+  char *options, uint64_t img_size,
+  int flags, Error **errp);
 
 void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f83ffb8..5bab830 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -202,6 +202,14 @@ struct BlockDriver {
  */
 int (*bdrv_has_zero_init)(BlockDriverState *bs);
 
+/* optional field */
+void (*bdrv_ext_snapshot_img_create)(BlockDriverState *bs,
+ const char *filename, const char *fmt,
+ const char *base_filename,
+ const char *base_fmt,
+ char *options, uint64_t img_size,
+ int flags, Error **errp);
+
 QLIST_ENTRY(BlockDriver) list;
 };
 
-- 
1.7.10.4




[Qemu-devel] [RFC V8 13/13] quorum: Add quorum_open() and quorum_close().

2013-01-28 Thread Benoît Canet
Valid quorum resources look like
quorum:threshold/total:path/to/image_1: ... :path/to/image_total

':' is used as a separator
'\' is the escaping character for filename containing ':'
'\' escape itself
',' must be escaped with ','

On the command line for quorum files "img:test.raw", "img2,raw"
and "img3.raw" invocation look like:

-drive file=quorum:2/3:img\\:test.raw:img2,,raw:img3.raw
(note the double \\ and the double ,,)

Signed-off-by: Benoit Canet 
---
 block/quorum.c |   65 
 1 file changed, 65 insertions(+)

diff --git a/block/quorum.c b/block/quorum.c
index 4d86c32..cf9fd22 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -814,12 +814,77 @@ static int quorum_snapshot_reopen(BlockDriverState *bs, 
int bdrv_flags,
 return ret;
 }
 
+/* Valid quorum resources look like
+ * quorum:threshold/total:path/to/image_1: ... :path/to/image_total
+ *
+ * ':' is used as a separator
+ * '\' is the escaping character for filename containing ':'
+ */
+static int quorum_open(BlockDriverState *bs, const char *filename, int flags)
+{
+BDRVQuorumState *s = bs->opaque;
+Error *local_err = NULL;
+int ret = 0;
+int i;
+
+ret = quorum_parse_url(s, filename, &local_err);
+if (ret < 0) {
+goto exit;
+}
+
+ret = quorum_validate_url(s, ret, &local_err);
+if (ret < 0) {
+goto free_exit;
+}
+
+/* Open files */
+for (i = 0; i < s->total; i++) {
+s->bs[i] = bdrv_new("");
+ret = bdrv_open(s->bs[i], s->filenames[i], flags, NULL);
+if (ret < 0) {
+goto error_exit;
+}
+}
+
+goto exit;
+
+error_exit:
+for (; i >= 0; i--) {
+bdrv_delete(s->bs[i]);
+s->bs[i] = NULL;
+}
+free_exit:
+quorum_free(s);
+exit:
+if (error_is_set(&local_err)) {
+qerror_report_err(local_err);
+}
+return ret;
+}
+
+static void quorum_close(BlockDriverState *bs)
+{
+BDRVQuorumState *s = bs->opaque;
+int i;
+
+for (i = 0; i < s->total; i++) {
+/* Ensure writes reach stable storage */
+bdrv_flush(s->bs[i]);
+bdrv_delete(s->bs[i]);
+}
+
+quorum_free(s);
+}
+
 static BlockDriver bdrv_quorum = {
 .format_name= "quorum",
 .protocol_name  = "quorum",
 
 .instance_size  = sizeof(BDRVQuorumState),
 
+.bdrv_file_open = quorum_open,
+.bdrv_close = quorum_close,
+
 .bdrv_co_flush_to_disk = quorum_co_flush,
 
 .bdrv_getlength = quorum_getlength,
-- 
1.7.10.4




Re: [Qemu-devel] [PATCHv4 1/2] qemu-img: find the image end offset during check

2013-01-28 Thread Eric Blake
On 01/28/2013 04:59 AM, Federico Simoncelli wrote:
> This patch adds the support for reporting the image end offset (in
> bytes). This is particularly useful after a conversion (or a rebase)
> where the destination is a block device in order to find the first
> unused byte at the end of the image.
> 
> Signed-off-by: Federico Simoncelli 
> ---
>  block/qcow2-refcount.c   |   10 --
>  include/block/block.h|1 +
>  qemu-img.c   |4 
>  tests/qemu-iotests/026   |6 +++---
>  tests/qemu-iotests/036   |3 ++-
>  tests/qemu-iotests/039   |2 +-
>  tests/qemu-iotests/044.out   |1 +
>  tests/qemu-iotests/common.rc |5 +++--
>  8 files changed, 23 insertions(+), 9 deletions(-)

> +++ b/tests/qemu-iotests/common.rc
> @@ -161,9 +161,10 @@ _cleanup_test_img()
>  
>  _check_test_img()
>  {
> -$QEMU_IMG check -f $IMGFMT $TEST_IMG 2>&1 | \
> +$QEMU_IMG check "$@" -f $IMGFMT $TEST_IMG 2>&1 | \
>  grep -v "fragmented$" | \
> - sed -e 's/qemu-img\: This image format does not support checks/No 
> errors were found on the image./'
> + sed -e 's/qemu-img\: This image format does not support checks/No 
> errors were found on the image./' | \

Pre-existing, but '\:' is not portable in sed; better is using ':' directly.

> + sed -e '/Image end offset: [0-9]\+/d'
>  }

'sed -e | sed -e' is a waste of a process.  Why not use a single sed for
both operations?  For that matter, since we are already using sed, why
not use it in place of 'grep -v'?

Use of '[0-9]\+' is not portable in all versions of sed. Better would
be: '[0-9][0-9]*'.  Then again, since you aren't anchoring the
expression, you don't really care whether there was more than one digit;
you still end up deleting the entire line.

Thus, a simpler version would be:

$QEMU_IMG check "$@" -f $IMGFMT $TEST_IMG 2>&1 | \
sed -e '/fragmented$/d' \
-e 's/qemu-img\: This image format does not support checks/No errors
were found on the image./' \
-e /Image end offset: [0-9]/d'

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 1/3] VFIO: Wrappers for getting/putting reference to vfio_device

2013-01-28 Thread Alex Williamson
On Mon, 2013-01-28 at 09:54 +, Pandarathil, Vijaymohan R wrote:
>   - Added vfio_device_get_from_vdev(), vfio_device_put_vdev()
>   as wrappers to get/put reference to vfio_device from struct device.
> 
>   - Added vfio_device_data() as a wrapper to get device_data from
>   vfio_device.
> 
> Signed-off-by: Vijay Mohan Pandarathil 
> ---
>  drivers/vfio/vfio.c  | 47 +--
>  include/linux/vfio.h |  3 +++
>  2 files changed, 44 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 12c264d..c2ff1b2 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -642,8 +642,13 @@ int vfio_add_group_dev(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(vfio_add_group_dev);
>  
> -/* Test whether a struct device is present in our tracking */
> -static bool vfio_dev_present(struct device *dev)
> +/**
> + * This does a get on the corresponding iommu_group,
> + * vfio_group and the vfio_device. Callers of this
> + * function will hae to call vfio_put_vdev() to

s/hae/have/

Note that your commit log and the patch don't agree on names.
vfio_device_get_from_dev vs vfio_device_get_from_vdev.  vfio_put_vdev vs
vfio_device_put_vdev.  Personally I think they should be:

vfio_device_get_from_dev
vfio_device_put

> + * remove the reference to all objects.

Why do we need to hold references to all the objects?  Holding a
reference to a vfio_device should implicitly hold the vfio_group, which
implicitly holds the iommu_group.  We have to get each to get to the
vfio_device, but once we hold of that reference I believe we can let the
others go.  Is this not the case?

> + */
> +void *vfio_device_get_from_dev(struct device *dev)

Return should be struct vfio_device*.  It doesn't have to be void to be
opaque.

>  {
>   struct iommu_group *iommu_group;
>   struct vfio_group *group;
> @@ -651,25 +656,55 @@ static bool vfio_dev_present(struct device *dev)
>  
>   iommu_group = iommu_group_get(dev);
>   if (!iommu_group)
> - return false;
> + return NULL;
>  
>   group = vfio_group_get_from_iommu(iommu_group);
>   if (!group) {
>   iommu_group_put(iommu_group);
> - return false;
> + return NULL;
>   }
>  
>   device = vfio_group_get_device(group, dev);
>   if (!device) {
>   vfio_group_put(group);
>   iommu_group_put(iommu_group);
> - return false;
> + return NULL;
>   }
> + return device;
> +}
> +EXPORT_SYMBOL_GPL(vfio_device_get_from_dev);
> +
> +void *vfio_device_data(void *data)
> +{

Why wouldn't this take struct vfio_device*?  We're ignoring free type
checking errors even though the user should be treating the device as
opaque.

> + struct vfio_device *device = data;
> + return device->device_data;
> +}
> +EXPORT_SYMBOL_GPL(vfio_device_data);
> +
> +void vfio_device_put_vdev(void *data)
> +{

This also should take a struct vfio_device* and be called
vfio_device_put().  If we fix the above extra reference holding then
it's just the existingvfio_device_put, which just needs to be exported.

> + struct vfio_device *device = data;
> + struct vfio_group *group = device->group;
> + struct iommu_group *iommu_group = group->iommu_group;
>  
>   vfio_device_put(device);
>   vfio_group_put(group);
>   iommu_group_put(iommu_group);
> - return true;
> + return;

Unnecessary explicit return.  Thanks,

Alex

> +}
> +EXPORT_SYMBOL_GPL(vfio_device_put_vdev);
> +
> +/* Test whether a struct device is present in our tracking */
> +static bool vfio_dev_present(struct device *dev)
> +{
> + struct vfio_device *device;
> +
> + device = vfio_device_get_from_dev(dev);
> + if (device) {
> + vfio_device_put_vdev(device);
> + return true;
> + } else
> + return false;
>  }
>  
>  /*
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index ab9e862..e550c09 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -45,6 +45,9 @@ extern int vfio_add_group_dev(struct device *dev,
> void *device_data);
>  
>  extern void *vfio_del_group_dev(struct device *dev);
> +extern void *vfio_device_get_from_dev(struct device *dev);
> +extern void vfio_device_put_vdev(void *device);
> +extern void *vfio_device_data(void *device);
>  
>  /**
>   * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks






Re: [Qemu-devel] [PATCH 4/7 v2] KVM regsync: Add register bitmap parameter to do_kvm_cpu_synchronize_state

2013-01-28 Thread Jason J. Herne

On 01/24/2013 07:01 PM, Marcelo Tosatti wrote:

On Thu, Jan 24, 2013 at 06:44:50PM -0200, Marcelo Tosatti wrote:

What 'subtle errors' are you thinking of?

It should be easy to convert as its greppable.


S/390 not synchronizing the env-> copy of the FULL register set is still
a bug, though (because the FULL set is what "cpu_synchronize_state" with
no parameter implies).






There seems to be a lot of good discussion going on regarding these 
changes.  Have we reached some kind of consensus on how we want to proceed?


If I understand the arguments being made... this patch set, as 
submitted, is wrong because KVM_ARCH_GET_REGS should always retrieve 
runtime regs only?  Or must it sync everything?  If there is not a clear 
answer here we'll need to decide this before going anywhere with this 
patch, yes?


Alex wrote:
"""
I think for now the best choice for get_regs() would be to ignore the 
FULL/RESET bits and always keep the syncing as it happens today under 
the RUNTIME umbrella only. So all of get_regs() only checks for RUNTIME.


Whenever get_xxx() happens, a bit gets set for set_xxx(). Up to this 
point, only the RUNTIME bit is ever set, because that's what 
cpu_synchronize_registers() sets.


Then s390 can add special separate bits for "sync GPRs" and "sync CRs". 
SYNC_RUNTIME would include those bits. The kvm hypercall exit calls a 
new synchronize_registers() function with a parameter telling it to only 
sync GPRs. This marks GPRs dirty, but not RUNTIME. The set_registers() 
function in s390 specific code could handle this particular case specially.


That way everything's solved and scalable, no?
"""

This is the most comprehensive suggestion I've been able to pick out of 
the discussion.  However, Marcelo has expressed concern over S390 not 
updating everything in env:


"""
S/390 not synchronizing the env-> copy of the FULL register set is still
a bug, though (because the FULL set is what "cpu_synchronize_state" with
no parameter implies).
"""

Also Alex, what did you mean by get_xxx() and set_xxx()?

--
-- Jason J. Herne (jjhe...@linux.vnet.ibm.com)




Re: [Qemu-devel] [PULL 00/15] s390 patch queue 2013-01-25

2013-01-28 Thread Stefan Weil
Am 28.01.2013 18:34, schrieb Cornelia Huck:
> On Mon, 28 Jan 2013 18:08:10 +0100
> Stefan Weil  wrote:
>
>> Am 28.01.2013 17:06, schrieb Cornelia Huck:
>>> On Sat, 26 Jan 2013 14:17:36 +
>>> Blue Swirl  wrote:
>>>
 On Fri, Jan 25, 2013 at 12:48 PM, Alexander Graf  wrote:
> Hi Blue / Aurelien,
>
> This is my current patch queue for s390.  Please pull.
>
> Alex
>
>
> The following changes since commit 
> 11c29918be32be5b00f367c7da9724a5cddbbb0f:
>   Anthony Liguori (1):
> Merge remote-tracking branch 'bonzini/scsi-next' into staging
>
> are available in the git repository at:
>
>   git://repo.or.cz/qemu/agraf.git s390-for-upstream
>
> Alexander Graf (3):
>   s390: Add default support for SCLP console
>   s390: Make typeinfo const
>   s390: Move hw files to hw/s390x
>
> Andreas Färber (1):
>   s390-virtio: Check for NULL device in reset hypercall
>
> Cornelia Huck (10):
>   s390: Lowcore mapping helper.
>   s390: Add mapping helper functions.
>   s390: Channel I/O basic definitions.
>   s390: I/O interrupt and machine check injection.
>   s390: Add channel I/O instructions.
>   s390: Virtual channel subsystem support.
 This would break build on mingw32:
   CCs390x-softmmu/hw/s390x/css.o
 /src/qemu/hw/s390x/css.c: In function 'css_interpret_ccw':
 /src/qemu/hw/s390x/css.c:226:17: error: 'ERESTART' undeclared (first
 use in this function)
 /src/qemu/hw/s390x/css.c:226:17: note: each undeclared identifier is
 reported only once for each function it appears in
 /src/qemu/hw/s390x/css.c:294:20: error: 'EOPNOTSUPP' undeclared (first
 use in this function)
 /src/qemu/hw/s390x/css.c: In function 'sch_handle_start_func':
 /src/qemu/hw/s390x/css.c:350:15: error: 'EOPNOTSUPP' undeclared (first
 use in this function)
 /src/qemu/hw/s390x/css.c:375:15: error: 'ERESTART' undeclared (first
 use in this function)
>>> The following patch might help for now, as those error codes already
>>> seem to be used in generic code.
>>>
>>> From a32da08a8474aa6fde65d7bc1616b42dce9d7252 Mon Sep 17 00:00:00 2001
>>> From: Cornelia Huck 
>>> Date: Mon, 28 Jan 2013 17:01:30 +0100
>>> Subject: [PATCH] s390: css error codes.
>>>
>>> Changed error codes in the channel subsystem / virtio-ccw code
>>> (-EOPNOTSUPP -> -ENOSYS, -ERESTART -> -EINPROGRESS).
>>>
>>> This should hopefully fix building on mingw32.
>>>
>>> Signed-off-by: Cornelia Huck 
>>> ---
>>>  hw/s390x/css.c|8 
>>>  hw/s390x/virtio-ccw.c |2 +-
>>>  2 files changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/hw/s390x/css.c b/hw/s390x/css.c
>>> index 84efd4a..3244201 100644
>>> --- a/hw/s390x/css.c
>>> +++ b/hw/s390x/css.c
>>> @@ -223,7 +223,7 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr 
>>> ccw_addr)
>>>  }
>>>  
>>>  if (ccw.flags & CCW_FLAG_SUSPEND) {
>>> -return -ERESTART;
>>> +return -EINPROGRESS;
>>>  }
>>>  
>>>  check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & 
>>> CCW_FLAG_DC));
>>> @@ -291,7 +291,7 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr 
>>> ccw_addr)
>>>  /* Handle device specific commands. */
>>>  ret = sch->ccw_cb(sch, ccw);
>>>  } else {
>>> -ret = -EOPNOTSUPP;
>>> +ret = -ENOSYS;
>>>  }
>>>  break;
>>>  }
>>> @@ -347,7 +347,7 @@ static void sch_handle_start_func(SubchDev *sch)
>>>  SCSW_STCTL_STATUS_PEND;
>>>  s->dstat = SCSW_DSTAT_CHANNEL_END | SCSW_DSTAT_DEVICE_END;
>>>  break;
>>> -case -EOPNOTSUPP:
>>> +case -ENOSYS:
>>>  /* unsupported command, generate unit check (command reject) */
>>>  s->ctrl &= ~SCSW_ACTL_START_PEND;
>>>  s->dstat = SCSW_DSTAT_UNIT_CHECK;
>>> @@ -372,7 +372,7 @@ static void sch_handle_start_func(SubchDev *sch)
>>>  s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
>>>  s->ctrl |= SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
>>>  break;
>>> -case -ERESTART:
>>> +case -EINPROGRESS:
>>>  /* channel program has been suspended */
>>>  s->ctrl &= ~SCSW_ACTL_START_PEND;
>>>  s->ctrl |= SCSW_ACTL_SUSP;
>>> diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
>>> index 8c9b745..7d7f336 100644
>>> --- a/hw/s390x/virtio-ccw.c
>>> +++ b/hw/s390x/virtio-ccw.c
>>> @@ -384,7 +384,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
>>>  }
>>>  break;
>>>  default:
>>> -ret = -EOPNOTSUPP;
>>> +ret = -ENOSYS;
>>>  break;
>>>  }
>>>  return ret;
>> ENOSYS is available for MinGW, but EINPROGRESS isn't.
>>
>> Here is a copy of MinGW's errno.h with all available values for errno:
>>
>> http://gitorious.org/mingw/mingw-runtime/blobs/75

[Qemu-devel] [RFC V8 02/13] quorum: Create BDRVQuorumState and BlkDriver and do init.

2013-01-28 Thread Benoît Canet
Signed-off-by: Benoit Canet 
---
 block/quorum.c |   22 ++
 1 file changed, 22 insertions(+)

diff --git a/block/quorum.c b/block/quorum.c
index 8dc6e4c..d8fffbe 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -15,6 +15,13 @@
 
 #include "block/block_int.h"
 
+typedef struct {
+BlockDriverState **bs;
+unsigned long long threshold;
+unsigned long long total;
+char **filenames;
+} BDRVQuorumState;
+
 typedef struct QuorumAIOCB QuorumAIOCB;
 
 typedef struct QuorumSingleAIOCB {
@@ -27,6 +34,7 @@ typedef struct QuorumSingleAIOCB {
 
 struct QuorumAIOCB {
 BlockDriverAIOCB common;
+BDRVQuorumState *bqs;
 QEMUBH *bh;
 
 /* Request metadata */
@@ -43,3 +51,17 @@ struct QuorumAIOCB {
 void (*vote)(QuorumAIOCB *acb);
 int vote_ret;
 };
+
+static BlockDriver bdrv_quorum = {
+.format_name= "quorum",
+.protocol_name  = "quorum",
+
+.instance_size  = sizeof(BDRVQuorumState),
+};
+
+static void bdrv_quorum_init(void)
+{
+bdrv_register(&bdrv_quorum);
+}
+
+block_init(bdrv_quorum_init);
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH V11 3/4] Use QemuOpts support in block layer

2013-01-28 Thread Markus Armbruster
Dong Xu Wang  writes:

> Markus Armbruster  writes:
>> Dong Xu Wang  writes:
>> 
>>> This patch will use QemuOpts related functions in block layer, add
>>> a member bdrv_create_options to BlockDriver struct, it will return
>>> a QemuOptsList pointer, which includes the image format's create
>>> options.
>>>
>>> And create options's primary consumer is block creating related functions,
>>> so modify them together.
>>>
>>>
>>> Signed-off-by: Dong Xu Wang 
>>> ---
>>> v10->v11)
>>> 1) qed.h move QED_DEFAULT_CLUSTER_SIZE from enum to macro, or
>>> qemu_opts_print produce un-expanded cluster_size.
>>> 2) In qcow2.c and qcow.c, bdrv_create_file(filename, NULL), NULL -> opts,
>>> or while using protocol, there will be an error.
>>>
>>> v8->v9)
>>> 1) add qemu_ prefix to gluster_create_opts.
>>> 2) fix bug: bdrv_gluster_unix and bdrv_gluster_rdma should also be
>>> converted.
>>>
>>> v7->v8)
>>> 1) rebase to upstream source tree.
>>> 2) add gluster.c, raw-win32.c, and rbd.c.
>>>
>>> v6->v7:
>>> 1) use osdep.h:stringify(), not redefining new macro.
>>> 2) preserve TODO comment.
>>> 3) fix typo. BLOCK_OPT_ENCRYPT->BLOCK_OPT_STATIC.
>>> 4) initialize disk_type even when opts is NULL.
>>>
>>> v5->v6:
>>> 1) judge if opts == NULL in block layer create functions.
>>> 2) use bdrv_create_file(filename, NULL) in qcow_create and cow_create 
>>> funtion.
>>> 3) made more readable while using qemu_opt_get_number.
>>>
>>>
>>>   block.c   |  91 
>>>   block/cow.c   |  46 ++---
>>>   block/gluster.c   |  37 +-
>>>   block/qcow.c  |  60 
>>>   block/qcow2.c | 171 
>>> +++---
>>>   block/qed.c   |  86 +++
>>>   block/qed.h   |   2 +-
>>>   block/raw-posix.c |  59 
>>>   block/raw-win32.c |  30 
>>>   block/raw.c   |  30 
>>>   block/rbd.c   |  62 -
>>>   block/sheepdog.c  |  75 ++--
>>>   block/vdi.c   |  69 +--
>>>   block/vmdk.c  |  74 ++--
>>>   block/vpc.c   |  67 +-
>>>   block/vvfat.c |  11 +--
>>>   include/block/block.h |   4 +-
>>>   include/block/block_int.h |   6 +-
>>>   qemu-img.c|  61 -
>>>   19 files changed, 519 insertions(+), 522 deletions(-)
>>>
>>> diff --git a/block.c b/block.c
>>> index 6fa7c90..56e4613 100644
>>> --- a/block.c
>>> +++ b/block.c
>>> @@ -357,7 +357,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char 
>>> *format_name)
>>>   typedef struct CreateCo {
>>>   BlockDriver *drv;
>>>   char *filename;
>>> -QEMUOptionParameter *options;
>>> +QemuOpts *opts;
>>>   int ret;
>>>   } CreateCo;
>>>   
>>> @@ -366,11 +366,11 @@ static void coroutine_fn bdrv_create_co_entry(void 
>>> *opaque)
>>>   CreateCo *cco = opaque;
>>>   assert(cco->drv);
>>>   
>>> -cco->ret = cco->drv->bdrv_create(cco->filename, cco->options);
>>> +cco->ret = cco->drv->bdrv_create(cco->filename, cco->opts);
>>>   }
>>>   
>>>   int bdrv_create(BlockDriver *drv, const char* filename,
>>> -QEMUOptionParameter *options)
>>> +QemuOpts *opts)
>>>   {
>>>   int ret;
>>>   
>>> @@ -378,7 +378,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
>>>   CreateCo cco = {
>>>   .drv = drv,
>>>   .filename = g_strdup(filename),
>>> -.options = options,
>>> +.opts = opts,
>>>   .ret = NOT_DONE,
>>>   };
>>>   
>>> @@ -405,7 +405,7 @@ out:
>>>   return ret;
>>>   }
>>>   
>>> -int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
>>> +int bdrv_create_file(const char *filename, QemuOpts *opts)
>>>   {
>>>   BlockDriver *drv;
>>>   
>>> @@ -414,7 +414,7 @@ int bdrv_create_file(const char* filename, 
>>> QEMUOptionParameter *options)
>>>   return -ENOENT;
>>>   }
>>>   
>>> -return bdrv_create(drv, filename, options);
>>> +return bdrv_create(drv, filename, opts);
>>>   }
>>>   
>>>   /*
>>> @@ -794,7 +794,7 @@ int bdrv_open(BlockDriverState *bs, const char 
>>> *filename, int flags,
>>>   int64_t total_size;
>>>   int is_protocol = 0;
>>>   BlockDriver *bdrv_qcow2;
>>> -QEMUOptionParameter *options;
>>> +QemuOpts *opts;
>>>   char backing_filename[PATH_MAX];
>>>   
>>>   /* if snapshot, we create a temporary backing file and open it
>>> @@ -827,17 +827,16 @@ int bdrv_open(BlockDriverState *bs, const char 
>>> *filename, int flags,
>>>   return -errno;
>>>   
>>>   bdrv_qcow2 = bdrv_find_format("qcow2");
>>> -options = parse_option_parameters("", bdrv_qcow2->create_options, 
>>> NULL);
>>> +opts = qemu_opts_create_nofail(bdrv_qcow2->bdrv_create_options);
>>>   
>>> -  

[Qemu-devel] [PATCH 33/37] target-openrisc: Use type_register() instead of type_register_static()

2013-01-28 Thread Andreas Färber
According to its documentation, type_register_static()'s TypeInfo
argument should exist for the life type of the type.
Therefore use type_register() when registering the list of CPU subtypes.

No functional change with the current implementation.

Cf. 918fd0839eeafc83bd4984364321a947d29041fe for arm.

Signed-off-by: Andreas Färber 
---
 target-openrisc/cpu.c |2 +-
 1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index adc03ef..54876d9 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -151,7 +151,7 @@ static void cpu_register(const OpenRISCCPUInfo *info)
 .class_size = sizeof(OpenRISCCPUClass),
 };
 
-type_register_static(&type_info);
+type_register(&type_info);
 }
 
 static const TypeInfo openrisc_cpu_type_info = {
-- 
1.7.10.4




[Qemu-devel] [PATCH 32/37] target-unicore32: Catch attempt to instantiate abstract type in cpu_init()

2013-01-28 Thread Andreas Färber
Fixes -cpu unicore32-cpu asserting.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Andreas Färber 
---
 target-unicore32/cpu.c |3 ++-
 1 Datei geändert, 2 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index 9239d49..6735b25 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -31,7 +31,8 @@ static ObjectClass *uc32_cpu_class_by_name(const char 
*cpu_model)
 }
 
 oc = object_class_by_name(cpu_model);
-if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU)) {
+if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
+   object_class_is_abstract(oc))) {
 oc = NULL;
 }
 return oc;
-- 
1.7.10.4




  1   2   3   >