Re: [Qemu-devel] [PATCH 0/2] convert device initialization functions

2016-07-13 Thread Wei, Jiangang
cc qemu-trivial

The following patches had been reviewed one month ago, 
But so far, It haven't been merged.
May I trouble any maintainer give me some feedback?

hw/pci-bridge: Convert pxb initialization functions to Error
apb: convert init to realize

Thanks,
wei
On Thu, 2016-07-07 at 01:39 +, Wei, Jiangang wrote:
> Ping again ...
> May I ask for some attention for these two patches?
> 
> Thanks
> wei
> On Thu, 2016-06-30 at 03:36 +0000, Wei, Jiangang wrote:
> > Ping
> > These two patches seem to be forgotten ...
> > 
> > On Tue, 2016-05-17 at 18:18 +0800, Wei Jiangang wrote:
> > > The first had been reviewed.
> > > The second had been posted last month, but no feedback.
> > > They're similar, so resend them together.
> > > 
> > > Wei Jiangang (2):
> > >   hw/pci-bridge: Convert pxb initialization functions to Error
> > >   apb: convert init to realize
> > > 
> > >  hw/pci-bridge/pci_expander_bridge.c | 52 
> > > ++---
> > >  hw/pci-host/apb.c   |  5 ++--
> > >  2 files changed, 27 insertions(+), 30 deletions(-)
> > > 
> > 
> > 
> > 
> 
> 
> 





Re: [Qemu-devel] [PATCH 0/2] convert device initialization functions

2016-07-06 Thread Wei, Jiangang
Ping again ...
May I ask for some attention for these two patches?

Thanks
wei
On Thu, 2016-06-30 at 03:36 +, Wei, Jiangang wrote:
> Ping
> These two patches seem to be forgotten ...
> 
> On Tue, 2016-05-17 at 18:18 +0800, Wei Jiangang wrote:
> > The first had been reviewed.
> > The second had been posted last month, but no feedback.
> > They're similar, so resend them together.
> > 
> > Wei Jiangang (2):
> >   hw/pci-bridge: Convert pxb initialization functions to Error
> >   apb: convert init to realize
> > 
> >  hw/pci-bridge/pci_expander_bridge.c | 52 
> > ++---
> >  hw/pci-host/apb.c   |  5 ++--
> >  2 files changed, 27 insertions(+), 30 deletions(-)
> > 
> 
> 
> 





Re: [Qemu-devel] [PATCH 0/2] convert device initialization functions

2016-06-29 Thread Wei, Jiangang
Ping
These two patches seem to be forgotten ...

On Tue, 2016-05-17 at 18:18 +0800, Wei Jiangang wrote:
> The first had been reviewed.
> The second had been posted last month, but no feedback.
> They're similar, so resend them together.
> 
> Wei Jiangang (2):
>   hw/pci-bridge: Convert pxb initialization functions to Error
>   apb: convert init to realize
> 
>  hw/pci-bridge/pci_expander_bridge.c | 52 
> ++---
>  hw/pci-host/apb.c   |  5 ++--
>  2 files changed, 27 insertions(+), 30 deletions(-)
> 





Re: [Qemu-devel] [PATCH] block/raw-posix: Fix error_report of mounting message

2016-06-03 Thread Wei, Jiangang
On Fri, 2016-06-03 at 17:00 +0800, Fam Zheng wrote:
> On Thu, 06/02 10:46, Wei, Jiangang wrote:
> > My intention is only to avoid the output of multiple location
> > information.
> 
> Then I think this should have gone into the commit message.

OK, I'll  make more detailed description in next version.
> 
> Fam
> 
> 





Re: [Qemu-devel] [PATCH] block/raw-posix: Fix error_report of mounting message

2016-06-02 Thread Wei, Jiangang
On Thu, 2016-06-02 at 09:57 +0200, Markus Armbruster wrote:
> Wei Jiangang <weijg.f...@cn.fujitsu.com> writes:
> 
> > Use a single error_printf to replace triple error_report.
> >
> > Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> > ---
> >  block/raw-posix.c | 10 +-
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/block/raw-posix.c b/block/raw-posix.c
> > index a4f5a1b..141b01a 100644
> > --- a/block/raw-posix.c
> > +++ b/block/raw-posix.c
> > @@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error 
> > **errp)
> >  /* Prints directions on mounting and unmounting a device */
> >  static void print_unmounting_directions(const char *file_name)
> >  {
> > -error_report("If device %s is mounted on the desktop, unmount"
> > - " it first before using it in QEMU", file_name);
> > -error_report("Command to unmount device: diskutil unmountDisk %s",
> > - file_name);
> > -error_report("Command to mount device: diskutil mountDisk %s", 
> > file_name);
> > +error_printf("If device %s is mounted on the desktop, unmount"
> > +" it first before using it in QEMU\n"
> > +"Command to unmount device: diskutil unmountDisk %s\n"
> > +"Command to mount device: diskutil mountDisk %s\n",
> > +file_name, file_name, file_name);
> >  }
> >  
> >  #endif /* defined(__APPLE__) && defined(__MACH__) */
> 
> This is less wrong :)
> 
> Beware, I have no suitable machine to actually test this, so the
> following is based on code inspection.
> 
> print_unmounting_directions() is used by hdev_open().  hdev_open() is a
> BlockDriver method bdrv_file_open(), and as such returns errors to its
> caller via parameter Error **errp.  The caller may or may not report
> errors it gets from hdev_open().
> 
> If it reports them, then print_unmounting_directions()'s output
> "overtakes" the error message, i.e. the "If device ... is mounted ..."
> hint is printed before the error message.  Wrong, it should be printed
> after the error message.
> 
> If it doesn't report them, the hint gets printed anyway.  More wrong.
> 
> In any case, printing each line of the hint with error_report() is also
> wrong, because that prefixes each line with program name and location
> information.  Your patch fixes this part.
> 
> A more complete fix uses error_append_hint(errp, ...) instead of
> error_printf().  hdev_open() needs to pass errp to
> print_unmounting_directions() for that.  errp must have an error set, or
> else error_append_hint() makes no sense.
I think you gave me a wonderful lesson about how to deal with error
report.
Thank you very much.

My intention is only to avoid the output of multiple location
information.

I'll check it again.

Thanks,
wei
> 
> 





Re: [Qemu-devel] [PATCH] block/raw-posix: Fix error_report of mounting message

2016-06-01 Thread Wei, Jiangang
On Wed, 2016-06-01 at 15:23 +0800, Fam Zheng wrote:
> On Wed, 06/01 15:08, Wei Jiangang wrote:
> > Use a single error_printf to replace triple error_report.
> > 
> > Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> > ---
> >  block/raw-posix.c | 10 +-
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/block/raw-posix.c b/block/raw-posix.c
> > index a4f5a1b..141b01a 100644
> > --- a/block/raw-posix.c
> > +++ b/block/raw-posix.c
> > @@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error 
> > **errp)
> >  /* Prints directions on mounting and unmounting a device */
> >  static void print_unmounting_directions(const char *file_name)
> >  {
> > -error_report("If device %s is mounted on the desktop, unmount"
> > - " it first before using it in QEMU", file_name);
> > -error_report("Command to unmount device: diskutil unmountDisk %s",
> > - file_name);
> > -error_report("Command to mount device: diskutil mountDisk %s", 
> > file_name);
> > +error_printf("If device %s is mounted on the desktop, unmount"
> > +" it first before using it in QEMU\n"
> > +"Command to unmount device: diskutil unmountDisk %s\n"
> > +"Command to mount device: diskutil mountDisk %s\n",
> > +file_name, file_name, file_name);
> 
> I'd say it's less readable with a worse alignment to the parameters.
Hi, Fam

Thanks for your comment.
You mean every error_report() followed by file_name is more readable ?
or my codes dosen't follow a good alignment format?

Wei
> 
> Fam
> 
> 





[Qemu-devel] [PATCH] block/raw-posix: Fix error_report of mounting message

2016-06-01 Thread Wei Jiangang
Use a single error_printf to replace triple error_report.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 block/raw-posix.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index a4f5a1b..141b01a 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {
-error_report("If device %s is mounted on the desktop, unmount"
- " it first before using it in QEMU", file_name);
-error_report("Command to unmount device: diskutil unmountDisk %s",
- file_name);
-error_report("Command to mount device: diskutil mountDisk %s", file_name);
+error_printf("If device %s is mounted on the desktop, unmount"
+" it first before using it in QEMU\n"
+"Command to unmount device: diskutil unmountDisk %s\n"
+"Command to mount device: diskutil mountDisk %s\n",
+file_name, file_name, file_name);
 }
 
 #endif /* defined(__APPLE__) && defined(__MACH__) */
-- 
1.9.3






Re: [Qemu-devel] [PATCH 0/2] convert device initialization functions

2016-05-30 Thread Wei, Jiangang
Ping 
Any comments?
Thanks in advance. 

On Tue, 2016-05-17 at 18:18 +0800, Wei Jiangang wrote:
> The first had been reviewed.
> The second had been posted last month, but no feedback.
> They're similar, so resend them together.
> 
> Wei Jiangang (2):
>   hw/pci-bridge: Convert pxb initialization functions to Error
>   apb: convert init to realize
> 
>  hw/pci-bridge/pci_expander_bridge.c | 52 
> ++---
>  hw/pci-host/apb.c   |  5 ++--
>  2 files changed, 27 insertions(+), 30 deletions(-)
> 





Re: [Qemu-devel] [PATCH] docs/multi-thread-compression: Fix wrong command string

2016-05-29 Thread Wei, Jiangang
Add qemu-trivial <qemu-triv...@nongnu.org>

Reviewed-by: Eric Blake <ebl...@redhat.com>
Reviewed-by: Liang Li <liang.z...@intel.com>

Thanks,
wei

On Mon, 2016-05-23 at 17:43 +0800, Wei Jiangang wrote:
> s/info_migrate_capabilities/info migrate_capabilities
> 
> Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> ---
>  docs/multi-thread-compression.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/docs/multi-thread-compression.txt 
> b/docs/multi-thread-compression.txt
> index 3d477c3..d0caaf7 100644
> --- a/docs/multi-thread-compression.txt
> +++ b/docs/multi-thread-compression.txt
> @@ -110,7 +110,7 @@ Usage
>  =
>  1. Verify both the source and destination QEMU are able
>  to support the multiple thread compression migration:
> -{qemu} info_migrate_capabilities
> +{qemu} info migrate_capabilities
>  {qemu} ... compress: off ...
>  
>  2. Activate compression on the source:





[Qemu-devel] RFC: do we need ordered dict?

2016-05-23 Thread Wei, Jiangang
Hi all,

I found a problem about the output of 'query-version'

As the qmp-command.hx said, it shoud be 
-> { "execute": "query-version" }
<- {
  "return":{
 "qemu":{
"major":0,
"minor":11,
"micro":5
 },
 "package":""
  }
   }

Actually, It's as following,
-> { "execute": "query-version" }
<- {
  "return":{
 "qemu":{
"micro":50,
"minor":6,
"major":2
 },
 "package":""
  }
   }

The reason is that the member ''qemu" is regarded as Un-ordered dict.
and  tdb_hash() returns the same bucket(225) for both  "micro" and
"minor". 
and The "major" is bigger (481).

All of the above metioned introduces the disorder for major , minor and
micro.

Thanks,
wei





[Qemu-devel] [PATCH] docs/multi-thread-compression: Fix wrong command string

2016-05-23 Thread Wei Jiangang
s/info_migrate_capabilities/info migrate_capabilities

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 docs/multi-thread-compression.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/multi-thread-compression.txt 
b/docs/multi-thread-compression.txt
index 3d477c3..d0caaf7 100644
--- a/docs/multi-thread-compression.txt
+++ b/docs/multi-thread-compression.txt
@@ -110,7 +110,7 @@ Usage
 =
 1. Verify both the source and destination QEMU are able
 to support the multiple thread compression migration:
-{qemu} info_migrate_capabilities
+{qemu} info migrate_capabilities
 {qemu} ... compress: off ...
 
 2. Activate compression on the source:
-- 
1.9.3






Re: [Qemu-devel] [PATCH 0/2] convert device initialization functions

2016-05-17 Thread Wei, Jiangang
received hint that Message to <*@redhat.com> was undeliverable.
ping to confirm my message had been sent successfully.

On Tue, 2016-05-17 at 18:18 +0800, Wei Jiangang wrote:
> The first had been reviewed.
> The second had been posted last month, but no feedback.
> They're similar, so resend them together.
> 
> Wei Jiangang (2):
>   hw/pci-bridge: Convert pxb initialization functions to Error
>   apb: convert init to realize
> 
>  hw/pci-bridge/pci_expander_bridge.c | 52 
> ++---
>  hw/pci-host/apb.c   |  5 ++--
>  2 files changed, 27 insertions(+), 30 deletions(-)
> 





Re: [Qemu-devel] [PATCH] configure: fix error messages

2016-05-17 Thread Wei, Jiangang
ping ...
Any comments?
On Tue, 2016-05-10 at 18:13 +0800, Wei Jiangang wrote:
> spice-server-devel is required, not spice-protocol-devel.
> "spice-protocol(>=0.12.3) devel" maybe mislead user.
> 
> when configure isn't able to find the required usb-redir,
> It's better to explicitly output version requirement.
> 
> Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> ---
>  configure | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index c37fc5f..0190fb7 100755
> --- a/configure
> +++ b/configure
> @@ -3974,7 +3974,7 @@ EOF
>else
>  if test "$spice" = "yes" ; then
>feature_not_found "spice" \
> -  "Install spice-server(>=0.12.0) and spice-protocol(>=0.12.3) devel"
> +  "Install spice-server(>=0.12.0) devel and spice-protocol(>=0.12.3)"
>  fi
>  spice="no"
>fi
> @@ -4023,7 +4023,7 @@ if test "$usb_redir" != "no" ; then
>  libs_softmmu="$libs_softmmu $usb_redir_libs"
>  else
>  if test "$usb_redir" = "yes"; then
> -feature_not_found "usb-redir" "Install usbredir devel"
> +feature_not_found "usb-redir" "Install usbredir devel(>=0.6)"
>  fi
>  usb_redir="no"
>  fi





[Qemu-devel] [PATCH 0/2] convert device initialization functions

2016-05-17 Thread Wei Jiangang
The first had been reviewed.
The second had been posted last month, but no feedback.
They're similar, so resend them together.

Wei Jiangang (2):
  hw/pci-bridge: Convert pxb initialization functions to Error
  apb: convert init to realize

 hw/pci-bridge/pci_expander_bridge.c | 52 ++---
 hw/pci-host/apb.c   |  5 ++--
 2 files changed, 27 insertions(+), 30 deletions(-)

-- 
1.9.3






[Qemu-devel] [PATCH 1/2] hw/pci-bridge: Convert pxb initialization functions to Error

2016-05-17 Thread Wei Jiangang
Firstly, convert pxb_dev_init_common() to Error and rename
it to pxb_dev_realize_common().
Actually, pxb_register_bus() is converted as well.

And then,
convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
respectively.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
Reviewed-by: Marcel Apfelbaum <mar...@redhat.com>
Reviewed-by: Markus Armbruster <arm...@redhat.com>
Reviewed-by: Michael S. Tsirkin <m...@redhat.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 52 ++---
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index ba320bd..cbea9c1 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
@@ -160,30 +161,25 @@ static const TypeInfo pxb_host_info = {
 };
 
 /*
- * Registers the PXB bus as a child of the i440fx root bus.
- *
- * Returns 0 on successs, -1 if i440fx host was not
- * found or the bus number is already in use.
+ * Registers the PXB bus as a child of pci host root bus.
  */
-static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus)
+static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp)
 {
 PCIBus *bus = dev->bus;
 int pxb_bus_num = pci_bus_num(pxb_bus);
 
 if (bus->parent_dev) {
-error_report("PXB devices can be attached only to root bus.");
-return -1;
+error_setg(errp, "PXB devices can be attached only to root bus");
+return;
 }
 
 QLIST_FOREACH(bus, >child, sibling) {
 if (pci_bus_num(bus) == pxb_bus_num) {
-error_report("Bus %d is already in use.", pxb_bus_num);
-return -1;
+error_setg(errp, "Bus %d is already in use", pxb_bus_num);
+return;
 }
 }
 QLIST_INSERT_HEAD(>bus->child, pxb_bus, sibling);
-
-return 0;
 }
 
 static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
@@ -213,17 +209,18 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)
0;
 }
 
-static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
+static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
 {
 PXBDev *pxb = convert_to_pxb(dev);
 DeviceState *ds, *bds = NULL;
 PCIBus *bus;
 const char *dev_name = NULL;
+Error *local_err = NULL;
 
 if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
 pxb->numa_node >= nb_numa_nodes) {
-error_report("Illegal numa node %d.", pxb->numa_node);
-return -EINVAL;
+error_setg(errp, "Illegal numa node %d", pxb->numa_node);
+return;
 }
 
 if (dev->qdev.id && *dev->qdev.id) {
@@ -248,7 +245,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
-if (pxb_register_bus(dev, bus)) {
+pxb_register_bus(dev, bus, _err);
+if (local_err) {
+error_propagate(errp, local_err);
 goto err_register_bus;
 }
 
@@ -262,23 +261,22 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
-return 0;
+return;
 
 err_register_bus:
 object_unref(OBJECT(bds));
 object_unparent(OBJECT(bus));
 object_unref(OBJECT(ds));
-return -EINVAL;
 }
 
-static int pxb_dev_initfn(PCIDevice *dev)
+static void pxb_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (pci_bus_is_express(dev->bus)) {
-error_report("pxb devices cannot reside on a PCIe bus!");
-return -EINVAL;
+error_setg(errp, "pxb devices cannot reside on a PCIe bus");
+return;
 }
 
-return pxb_dev_init_common(dev, false);
+pxb_dev_realize_common(dev, false, errp);
 }
 
 static void pxb_dev_exitfn(PCIDevice *pci_dev)
@@ -300,7 +298,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_dev_initfn;
+k->realize = pxb_dev_realize;
 k->exit = pxb_dev_exitfn;
 k->vendor_id = PCI_VENDOR_ID_REDHAT;
 k->device_id = PCI_DEVICE_ID_REDHAT_PXB;
@@ -318,14 +316,14 @@ static const TypeInfo pxb_dev_info = {
 .class_init= pxb_dev_class_init,
 };
 
-static int pxb_pcie_dev_initfn(PCIDevice *dev)
+static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (!pci_bus_is_express(dev->bus)) 

[Qemu-devel] [PATCH 2/2] apb: convert init to realize

2016-05-17 Thread Wei Jiangang
Convert a device model where initialization obviously can't fail,
make it implement realize() rather than init().

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 hw/pci-host/apb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index aaef7bb..b29789c 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -633,7 +633,7 @@ static void pci_apb_set_irq(void *opaque, int irq_num, int 
level)
 }
 }
 
-static int apb_pci_bridge_initfn(PCIDevice *dev)
+static void apb_pci_bridge_realize(PCIDevice *dev, Error **errp)
 {
 pci_bridge_initfn(dev, TYPE_PCI_BUS);
 
@@ -651,7 +651,6 @@ static int apb_pci_bridge_initfn(PCIDevice *dev)
 pci_set_word(dev->config + PCI_STATUS,
  PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
  PCI_STATUS_DEVSEL_MEDIUM);
-return 0;
 }
 
 PCIBus *pci_apb_init(hwaddr special_base,
@@ -843,7 +842,7 @@ static void pbm_pci_bridge_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = apb_pci_bridge_initfn;
+k->realize = apb_pci_bridge_realize;
 k->exit = pci_bridge_exitfn;
 k->vendor_id = PCI_VENDOR_ID_SUN;
 k->device_id = PCI_DEVICE_ID_SUN_SIMBA;
-- 
1.9.3






[Qemu-devel] [PATCH] configure: fix error messages

2016-05-10 Thread Wei Jiangang
spice-server-devel is required, not spice-protocol-devel.
"spice-protocol(>=0.12.3) devel" maybe mislead user.

when configure isn't able to find the required usb-redir,
It's better to explicitly output version requirement.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 configure | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c37fc5f..0190fb7 100755
--- a/configure
+++ b/configure
@@ -3974,7 +3974,7 @@ EOF
   else
 if test "$spice" = "yes" ; then
   feature_not_found "spice" \
-  "Install spice-server(>=0.12.0) and spice-protocol(>=0.12.3) devel"
+  "Install spice-server(>=0.12.0) devel and spice-protocol(>=0.12.3)"
 fi
 spice="no"
   fi
@@ -4023,7 +4023,7 @@ if test "$usb_redir" != "no" ; then
 libs_softmmu="$libs_softmmu $usb_redir_libs"
 else
 if test "$usb_redir" = "yes"; then
-feature_not_found "usb-redir" "Install usbredir devel"
+feature_not_found "usb-redir" "Install usbredir devel(>=0.6)"
 fi
 usb_redir="no"
 fi
-- 
1.9.3






Re: [Qemu-devel] [PATCH v2] hw/net/opencores_eth: Allocating Large sized arrays to heap

2016-04-26 Thread Wei, Jiangang
On Wed, 2016-04-27 at 06:44 +0300, Max Filippov wrote:
> Hi Wei,
> 
> On Wed, Apr 27, 2016 at 03:27:47AM +0000, Wei, Jiangang wrote:
> > On Wed, 2016-04-27 at 10:07 +0800, Zhou Jie wrote:
> > >  static void open_eth_start_xmit(OpenEthState *s, desc *tx)
> > >  {
> > > -uint8_t buf[65536];
> > > +uint8_t *buf = NULL;
> > > +uint8_t buffer[0x600];
> > Hi,
> > 
> > I'm curious about 0x600.
> > How do you determine this size?
> > IMO, Max's suggestion looks more reasonable.
> > (1536 bytes, maximal frame length when HUGEN bit is not set in MODER)
> 
> This is the same value. Opencores 10/100 ethernet spec uses both
> decimal and hexadecimal notation.
I got it
Thanks for your reply.

Wei





Re: [Qemu-devel] [PATCH v2] hw/net/opencores_eth: Allocating Large sized arrays to heap

2016-04-26 Thread Wei, Jiangang
On Wed, 2016-04-27 at 10:07 +0800, Zhou Jie wrote:
> open_eth_start_xmit has a huge stack usage of 65536 bytes approx.
> Moving large arrays to heap to reduce stack usage.
> 
> Signed-off-by: Zhou Jie 
> ---
>  hw/net/opencores_eth.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c
> index c6094fb..fa0a4e7 100644
> --- a/hw/net/opencores_eth.c
> +++ b/hw/net/opencores_eth.c
> @@ -483,7 +483,8 @@ static NetClientInfo net_open_eth_info = {
>  
>  static void open_eth_start_xmit(OpenEthState *s, desc *tx)
>  {
> -uint8_t buf[65536];
> +uint8_t *buf = NULL;
> +uint8_t buffer[0x600];
Hi,

I'm curious about 0x600.
How do you determine this size?
IMO, Max's suggestion looks more reasonable.
(1536 bytes, maximal frame length when HUGEN bit is not set in MODER)

Regards,
wei
>  unsigned len = GET_FIELD(tx->len_flags, TXD_LEN);
>  unsigned tx_len = len;
>  
> @@ -498,6 +499,11 @@ static void open_eth_start_xmit(OpenEthState *s, desc 
> *tx)
>  
>  trace_open_eth_start_xmit(tx->buf_ptr, len, tx_len);
>  
> +if (tx_len > 0x600) {
> +buf = g_new(uint8_t, tx_len);
> +} else {
> +buf = buffer;
> +}
>  if (len > tx_len) {
>  len = tx_len;
>  }
> @@ -506,6 +512,9 @@ static void open_eth_start_xmit(OpenEthState *s, desc *tx)
>  memset(buf + len, 0, tx_len - len);
>  }
>  qemu_send_packet(qemu_get_queue(s->nic), buf, tx_len);
> +if (tx_len > 0x600) {
> +g_free(buf);
> +}
>  
>  if (tx->len_flags & TXD_WR) {
>  s->tx_desc = 0;





[Qemu-devel] [PATCH] iotests: fix the redirection order in 083

2016-04-26 Thread Wei Jiangang
It should redirect stdout to /dev/null first,
then redirect stderr to whatever stdout currently points at.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 tests/qemu-iotests/083 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/083 b/tests/qemu-iotests/083
index aa99278..7d368b5 100755
--- a/tests/qemu-iotests/083
+++ b/tests/qemu-iotests/083
@@ -44,7 +44,7 @@ choose_tcp_port() {
 
 wait_for_tcp_port() {
while ! (netstat --tcp --listening --numeric | \
-grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") 2>&1 >/dev/null; do
+grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do
sleep 0.1
done
 }
@@ -71,7 +71,7 @@ EOF
nbd_url="nbd:127.0.0.1:$port:exportname=foo"
fi
 
-   $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" 
"$TEST_DIR/nbd-fault-injector.conf" 2>&1 >/dev/null &
+   $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" 
"$TEST_DIR/nbd-fault-injector.conf" >/dev/null 2>&1 &
wait_for_tcp_port "127\\.0\\.0\\.1:$port"
$QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
 
-- 
1.9.3






[Qemu-devel] [PATCH] apb: convert init to realize

2016-04-26 Thread Wei Jiangang
Convert a device model where initialization obviously can't fail,
make it implement realize() rather than init().

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 hw/pci-host/apb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index aaef7bb..b29789c 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -633,7 +633,7 @@ static void pci_apb_set_irq(void *opaque, int irq_num, int 
level)
 }
 }
 
-static int apb_pci_bridge_initfn(PCIDevice *dev)
+static void apb_pci_bridge_realize(PCIDevice *dev, Error **errp)
 {
 pci_bridge_initfn(dev, TYPE_PCI_BUS);
 
@@ -651,7 +651,6 @@ static int apb_pci_bridge_initfn(PCIDevice *dev)
 pci_set_word(dev->config + PCI_STATUS,
  PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
  PCI_STATUS_DEVSEL_MEDIUM);
-return 0;
 }
 
 PCIBus *pci_apb_init(hwaddr special_base,
@@ -843,7 +842,7 @@ static void pbm_pci_bridge_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = apb_pci_bridge_initfn;
+k->realize = apb_pci_bridge_realize;
 k->exit = pci_bridge_exitfn;
 k->vendor_id = PCI_VENDOR_ID_SUN;
 k->device_id = PCI_DEVICE_ID_SUN_SIMBA;
-- 
1.9.3






[Qemu-devel] [PATCH] block: Fix typo in comment

2016-04-26 Thread Wei Jiangang
s/imlement/implement/

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 blockdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index f1f520a..f74eb43 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -73,7 +73,7 @@ static int if_max_devs[IF_COUNT] = {
  * Do not change these numbers!  They govern how drive option
  * index maps to unit and bus.  That mapping is ABI.
  *
- * All controllers used to imlement if=T drives need to support
+ * All controllers used to implement if=T drives need to support
  * if_max_devs[T] units, for any T with if_max_devs[T] != 0.
  * Otherwise, some index values map to "impossible" bus, unit
  * values.
-- 
1.9.3






Re: [Qemu-devel] [PATCH] rng-random: rename RndRandom to RngRandom

2016-04-14 Thread Wei, Jiangang
I'm not sure...
Any comments and suggestions are welcome.
Thanks in advance.
On Fri, 2016-04-15 at 09:36 +0800, Wei Jiangang wrote:
> Usually, Random Number Generator is abbreviated to RNG/rng.
> so replacing RndRandom with RngRandom seems more reasonable
> and keep consistent with RngBackend.
> 
> Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> ---
>  backends/rng-random.c  | 18 +-
>  include/hw/virtio/virtio-rng.h |  2 +-
>  include/sysemu/rng-random.h|  4 ++--
>  3 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/backends/rng-random.c b/backends/rng-random.c
> index 2e44e25..e2a49b0 100644
> --- a/backends/rng-random.c
> +++ b/backends/rng-random.c
> @@ -17,7 +17,7 @@
>  #include "qapi/qmp/qerror.h"
>  #include "qemu/main-loop.h"
>  
> -struct RndRandom
> +struct RngRandom
>  {
>  RngBackend parent;
>  
> @@ -34,7 +34,7 @@ struct RndRandom
>  
>  static void entropy_available(void *opaque)
>  {
> -RndRandom *s = RNG_RANDOM(opaque);
> +RngRandom *s = RNG_RANDOM(opaque);
>  
>  while (!QSIMPLEQ_EMPTY(>parent.requests)) {
>  RngRequest *req = QSIMPLEQ_FIRST(>parent.requests);
> @@ -57,7 +57,7 @@ static void entropy_available(void *opaque)
>  
>  static void rng_random_request_entropy(RngBackend *b, RngRequest *req)
>  {
> -RndRandom *s = RNG_RANDOM(b);
> +RngRandom *s = RNG_RANDOM(b);
>  
>  if (QSIMPLEQ_EMPTY(>parent.requests)) {
>  /* If there are no pending requests yet, we need to
> @@ -68,7 +68,7 @@ static void rng_random_request_entropy(RngBackend *b, 
> RngRequest *req)
>  
>  static void rng_random_opened(RngBackend *b, Error **errp)
>  {
> -RndRandom *s = RNG_RANDOM(b);
> +RngRandom *s = RNG_RANDOM(b);
>  
>  if (s->filename == NULL) {
>  error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
> @@ -83,7 +83,7 @@ static void rng_random_opened(RngBackend *b, Error **errp)
>  
>  static char *rng_random_get_filename(Object *obj, Error **errp)
>  {
> -RndRandom *s = RNG_RANDOM(obj);
> +RngRandom *s = RNG_RANDOM(obj);
>  
>  return g_strdup(s->filename);
>  }
> @@ -92,7 +92,7 @@ static void rng_random_set_filename(Object *obj, const char 
> *filename,
>   Error **errp)
>  {
>  RngBackend *b = RNG_BACKEND(obj);
> -RndRandom *s = RNG_RANDOM(obj);
> +RngRandom *s = RNG_RANDOM(obj);
>  
>  if (b->opened) {
>  error_setg(errp, QERR_PERMISSION_DENIED);
> @@ -105,7 +105,7 @@ static void rng_random_set_filename(Object *obj, const 
> char *filename,
>  
>  static void rng_random_init(Object *obj)
>  {
> -RndRandom *s = RNG_RANDOM(obj);
> +RngRandom *s = RNG_RANDOM(obj);
>  
>  object_property_add_str(obj, "filename",
>  rng_random_get_filename,
> @@ -118,7 +118,7 @@ static void rng_random_init(Object *obj)
>  
>  static void rng_random_finalize(Object *obj)
>  {
> -RndRandom *s = RNG_RANDOM(obj);
> +RngRandom *s = RNG_RANDOM(obj);
>  
>  if (s->fd != -1) {
>  qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
> @@ -139,7 +139,7 @@ static void rng_random_class_init(ObjectClass *klass, 
> void *data)
>  static const TypeInfo rng_random_info = {
>  .name = TYPE_RNG_RANDOM,
>  .parent = TYPE_RNG_BACKEND,
> -.instance_size = sizeof(RndRandom),
> +.instance_size = sizeof(RngRandom),
>  .class_init = rng_random_class_init,
>  .instance_init = rng_random_init,
>  .instance_finalize = rng_random_finalize,
> diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
> index 3f07de7..2bc1ee5 100644
> --- a/include/hw/virtio/virtio-rng.h
> +++ b/include/hw/virtio/virtio-rng.h
> @@ -26,7 +26,7 @@ struct VirtIORNGConf {
>  RngBackend *rng;
>  uint64_t max_bytes;
>  uint32_t period_ms;
> -RndRandom *default_backend;
> +RngRandom *default_backend;
>  };
>  
>  typedef struct VirtIORNG {
> diff --git a/include/sysemu/rng-random.h b/include/sysemu/rng-random.h
> index 4332772..38186fe 100644
> --- a/include/sysemu/rng-random.h
> +++ b/include/sysemu/rng-random.h
> @@ -15,8 +15,8 @@
>  #include "qom/object.h"
>  
>  #define TYPE_RNG_RANDOM "rng-random"
> -#define RNG_RANDOM(obj) OBJECT_CHECK(RndRandom, (obj), TYPE_RNG_RANDOM)
> +#define RNG_RANDOM(obj) OBJECT_CHECK(RngRandom, (obj), TYPE_RNG_RANDOM)
>  
> -typedef struct RndRandom RndRandom;
> +typedef struct RngRandom RngRandom;
>  
>  #endif





[Qemu-devel] [PATCH] rng-random: rename RndRandom to RngRandom

2016-04-14 Thread Wei Jiangang
Usually, Random Number Generator is abbreviated to RNG/rng.
so replacing RndRandom with RngRandom seems more reasonable
and keep consistent with RngBackend.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 backends/rng-random.c  | 18 +-
 include/hw/virtio/virtio-rng.h |  2 +-
 include/sysemu/rng-random.h|  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/backends/rng-random.c b/backends/rng-random.c
index 2e44e25..e2a49b0 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -17,7 +17,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/main-loop.h"
 
-struct RndRandom
+struct RngRandom
 {
 RngBackend parent;
 
@@ -34,7 +34,7 @@ struct RndRandom
 
 static void entropy_available(void *opaque)
 {
-RndRandom *s = RNG_RANDOM(opaque);
+RngRandom *s = RNG_RANDOM(opaque);
 
 while (!QSIMPLEQ_EMPTY(>parent.requests)) {
 RngRequest *req = QSIMPLEQ_FIRST(>parent.requests);
@@ -57,7 +57,7 @@ static void entropy_available(void *opaque)
 
 static void rng_random_request_entropy(RngBackend *b, RngRequest *req)
 {
-RndRandom *s = RNG_RANDOM(b);
+RngRandom *s = RNG_RANDOM(b);
 
 if (QSIMPLEQ_EMPTY(>parent.requests)) {
 /* If there are no pending requests yet, we need to
@@ -68,7 +68,7 @@ static void rng_random_request_entropy(RngBackend *b, 
RngRequest *req)
 
 static void rng_random_opened(RngBackend *b, Error **errp)
 {
-RndRandom *s = RNG_RANDOM(b);
+RngRandom *s = RNG_RANDOM(b);
 
 if (s->filename == NULL) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
@@ -83,7 +83,7 @@ static void rng_random_opened(RngBackend *b, Error **errp)
 
 static char *rng_random_get_filename(Object *obj, Error **errp)
 {
-RndRandom *s = RNG_RANDOM(obj);
+RngRandom *s = RNG_RANDOM(obj);
 
 return g_strdup(s->filename);
 }
@@ -92,7 +92,7 @@ static void rng_random_set_filename(Object *obj, const char 
*filename,
  Error **errp)
 {
 RngBackend *b = RNG_BACKEND(obj);
-RndRandom *s = RNG_RANDOM(obj);
+RngRandom *s = RNG_RANDOM(obj);
 
 if (b->opened) {
 error_setg(errp, QERR_PERMISSION_DENIED);
@@ -105,7 +105,7 @@ static void rng_random_set_filename(Object *obj, const char 
*filename,
 
 static void rng_random_init(Object *obj)
 {
-RndRandom *s = RNG_RANDOM(obj);
+RngRandom *s = RNG_RANDOM(obj);
 
 object_property_add_str(obj, "filename",
 rng_random_get_filename,
@@ -118,7 +118,7 @@ static void rng_random_init(Object *obj)
 
 static void rng_random_finalize(Object *obj)
 {
-RndRandom *s = RNG_RANDOM(obj);
+RngRandom *s = RNG_RANDOM(obj);
 
 if (s->fd != -1) {
 qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
@@ -139,7 +139,7 @@ static void rng_random_class_init(ObjectClass *klass, void 
*data)
 static const TypeInfo rng_random_info = {
 .name = TYPE_RNG_RANDOM,
 .parent = TYPE_RNG_BACKEND,
-.instance_size = sizeof(RndRandom),
+.instance_size = sizeof(RngRandom),
 .class_init = rng_random_class_init,
 .instance_init = rng_random_init,
 .instance_finalize = rng_random_finalize,
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 3f07de7..2bc1ee5 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -26,7 +26,7 @@ struct VirtIORNGConf {
 RngBackend *rng;
 uint64_t max_bytes;
 uint32_t period_ms;
-RndRandom *default_backend;
+RngRandom *default_backend;
 };
 
 typedef struct VirtIORNG {
diff --git a/include/sysemu/rng-random.h b/include/sysemu/rng-random.h
index 4332772..38186fe 100644
--- a/include/sysemu/rng-random.h
+++ b/include/sysemu/rng-random.h
@@ -15,8 +15,8 @@
 #include "qom/object.h"
 
 #define TYPE_RNG_RANDOM "rng-random"
-#define RNG_RANDOM(obj) OBJECT_CHECK(RndRandom, (obj), TYPE_RNG_RANDOM)
+#define RNG_RANDOM(obj) OBJECT_CHECK(RngRandom, (obj), TYPE_RNG_RANDOM)
 
-typedef struct RndRandom RndRandom;
+typedef struct RngRandom RngRandom;
 
 #endif
-- 
1.9.3






[Qemu-devel] [PATCH v2] accel: make configure_accelerator return void

2016-04-13 Thread Wei Jiangang
Return the negated value of accel_initialised is meaningless,
and the caller vl doesn't check it.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 accel.c| 4 +---
 include/sysemu/accel.h | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/accel.c b/accel.c
index 0510b90..403eb5e 100644
--- a/accel.c
+++ b/accel.c
@@ -77,7 +77,7 @@ static int accel_init_machine(AccelClass *acc, MachineState 
*ms)
 return ret;
 }
 
-int configure_accelerator(MachineState *ms)
+void configure_accelerator(MachineState *ms)
 {
 const char *p;
 char buf[10];
@@ -128,8 +128,6 @@ int configure_accelerator(MachineState *ms)
 if (init_failed) {
 fprintf(stderr, "Back to %s accelerator.\n", acc->name);
 }
-
-return !accel_initialised;
 }
 
 
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 997720f..c230f1b 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -57,6 +57,6 @@ typedef struct AccelClass {
 
 extern int tcg_tb_size;
 
-int configure_accelerator(MachineState *ms);
+void configure_accelerator(MachineState *ms);
 
 #endif
-- 
1.9.3






Re: [Qemu-devel] [PATCH] accel: make configure_accelerator return void

2016-04-13 Thread Wei, Jiangang
On Thu, 2016-04-14 at 11:34 +0800, Changlong Xie wrote:
> On 04/14/2016 11:19 AM, Wei, Jiangang wrote:
> > ping...
> > Any comments?
> > On Tue, 2016-03-15 at 18:07 +0800, Wei Jiangang wrote:
> >> Return the negated value of accel_initialised is meaningless,
> >> and the caller vl doesn't check it.
> >>
> >> Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> >> ---
> >>   accel.c | 4 +---
> >>   1 file changed, 1 insertion(+), 3 deletions(-)
> >>
> >> diff --git a/accel.c b/accel.c
> >> index 0510b90..403eb5e 100644
> >> --- a/accel.c
> >> +++ b/accel.c
> >> @@ -77,7 +77,7 @@ static int accel_init_machine(AccelClass *acc, 
> >> MachineState *ms)
> >>   return ret;
> >>   }
> >>
> >> -int configure_accelerator(MachineState *ms)
> >> +void configure_accelerator(MachineState *ms)
> >>   {
> >>   const char *p;
> >>   char buf[10];
> >> @@ -128,8 +128,6 @@ int configure_accelerator(MachineState *ms)
> >>   if (init_failed) {
> >>   fprintf(stderr, "Back to %s accelerator.\n", acc->name);
> >>   }
> >> -
> >> -return !accel_initialised;
> >>   }
> 
> Have you compiled the code with this path?

Thanks for your remind.
I compiled it,
But  I forgot to add the changed head file together with accel.c.

I will resend the second version.

Regards,
wei
> 
> Thanks
>   -Xie
> >>
> >>
> >
> >
> >





Re: [Qemu-devel] [PATCH] accel: make configure_accelerator return void

2016-04-13 Thread Wei, Jiangang
ping...
Any comments?
On Tue, 2016-03-15 at 18:07 +0800, Wei Jiangang wrote:
> Return the negated value of accel_initialised is meaningless,
> and the caller vl doesn't check it.
> 
> Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> ---
>  accel.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/accel.c b/accel.c
> index 0510b90..403eb5e 100644
> --- a/accel.c
> +++ b/accel.c
> @@ -77,7 +77,7 @@ static int accel_init_machine(AccelClass *acc, MachineState 
> *ms)
>  return ret;
>  }
>  
> -int configure_accelerator(MachineState *ms)
> +void configure_accelerator(MachineState *ms)
>  {
>  const char *p;
>  char buf[10];
> @@ -128,8 +128,6 @@ int configure_accelerator(MachineState *ms)
>  if (init_failed) {
>  fprintf(stderr, "Back to %s accelerator.\n", acc->name);
>  }
> -
> -return !accel_initialised;
>  }
>  
> 





Re: [Qemu-devel] [PATCH 0/3] bitsized task for glib conversion

2016-04-12 Thread Wei, Jiangang
ping...
Any comments? Thanks in advance.
On Thu, 2016-04-07 at 10:46 +0800, Wei Jiangang wrote:
> The series used to change basename and dirname to
> g_path_get_basename() and g_path_get_dirname() respectively.
> 
> Refer to http://wiki.qemu.org/BiteSizedTasks#API_conversion
> 
> *** BLURB HERE ***
> 
> Wei Jiangang (3):
>   linux-user: complete omission of removing uses of strdup
>   use g_path_get_dirname instead of dirname
>   use g_path_get_basename instead of basename
> 
>  fsdev/virtfs-proxy-helper.c |  6 +-
>  hw/9pfs/9p-local.c  |  6 +++---
>  hw/vfio/pci.c   |  6 --
>  hw/vfio/platform.c  |  6 --
>  linux-user/elfload.c|  7 ++-
>  os-posix.c  |  3 ++-
>  qemu-io.c   | 33 -
>  qemu-nbd.c  |  4 +++-
>  qga/commands-posix.c|  4 ++--
>  util/oslib-posix.c  |  4 +++-
>  10 files changed, 48 insertions(+), 31 deletions(-)
> 





Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error

2016-04-08 Thread Wei, Jiangang
On Thu, 2016-04-07 at 19:55 +0300, Michael S. Tsirkin wrote:
> On Thu, Apr 07, 2016 at 07:44:17PM +0300, Michael S. Tsirkin wrote:
> > On Thu, Apr 07, 2016 at 06:39:10PM +0200, Markus Armbruster wrote:
> > > Marcel Apfelbaum <mar...@redhat.com> writes:
> > > 
> > > > On 03/23/2016 01:56 PM, Markus Armbruster wrote:
> > > >> Wei Jiangang <weijg.f...@cn.fujitsu.com> writes:
> > > >>
> > > >>> v1 -> v2:
> > > >>>
> > > >>> - Extract a separate bugfix patch
> > > >>> - Squash v1 patches 1-3 together
> > > >>> - Drop the period and exclamation mark
> > > >>> - Modify commit message
> > > >>>
> > > >>> v1: cover-letter
> > > >>>
> > > >>> The original patch named '[PATCH v3] PXB: convert to realize()'
> > > >>> was raised by Cao jin <caoj.f...@cn.fujitsu.com>,
> > > >>> and reviewed by Marcel Apfelbaum <mar...@redhat.com>.
> > > >>>
> > > >>> It conflicts with 02b0743 that had been merged,
> > > >>> so resend a newer version, including the following,
> > > >>
> > > >> Series
> > > >> Reviewed-by: Markus Armbruster <arm...@redhat.com>
> > > >>
> > > >
> > > > Thanks Markus, will you take it in your tree, or Michael ?
> > > 
> > > As error reporting maintainer, I cover error reporting infrastructure.
> > > I also take non-infrastructure error reporting patches that cross
> > > subsystems when no affected maintainer objects, single-subsystem patches
> > > when the maintainer asks me to, and patches to unmaintained code.
> > > 
> > > I encourage you to take this series through the PCI tree.  But if you
> > > want me to take it through my tree instead, let me know.
> > 
> > I applied this, thanks!
> 
> In fact, I applied patch 1/2. 2/2 fails build and is not a bugfix.
> I think it's best to defer it to after 2.6.
> Pls repost it then.

Hi,
I have fixed the compile error.
In fact, I missed including the qapi/error.h.
May I trouble you to check and apply v3 again ?
Thanks in advance.

wei
> 





[Qemu-devel] [PATCH v3 2/2] hw/pci-bridge: Convert pxb initialization functions to Error

2016-04-08 Thread Wei Jiangang
Firstly, convert pxb_dev_init_common() to Error and rename
it to pxb_dev_realize_common().
Actually, pxb_register_bus() is converted as well.

And then,
convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
respectively.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 52 ++---
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index ba320bd..cbea9c1 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
@@ -160,30 +161,25 @@ static const TypeInfo pxb_host_info = {
 };
 
 /*
- * Registers the PXB bus as a child of the i440fx root bus.
- *
- * Returns 0 on successs, -1 if i440fx host was not
- * found or the bus number is already in use.
+ * Registers the PXB bus as a child of pci host root bus.
  */
-static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus)
+static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp)
 {
 PCIBus *bus = dev->bus;
 int pxb_bus_num = pci_bus_num(pxb_bus);
 
 if (bus->parent_dev) {
-error_report("PXB devices can be attached only to root bus.");
-return -1;
+error_setg(errp, "PXB devices can be attached only to root bus");
+return;
 }
 
 QLIST_FOREACH(bus, >child, sibling) {
 if (pci_bus_num(bus) == pxb_bus_num) {
-error_report("Bus %d is already in use.", pxb_bus_num);
-return -1;
+error_setg(errp, "Bus %d is already in use", pxb_bus_num);
+return;
 }
 }
 QLIST_INSERT_HEAD(>bus->child, pxb_bus, sibling);
-
-return 0;
 }
 
 static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
@@ -213,17 +209,18 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)
0;
 }
 
-static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
+static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
 {
 PXBDev *pxb = convert_to_pxb(dev);
 DeviceState *ds, *bds = NULL;
 PCIBus *bus;
 const char *dev_name = NULL;
+Error *local_err = NULL;
 
 if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
 pxb->numa_node >= nb_numa_nodes) {
-error_report("Illegal numa node %d.", pxb->numa_node);
-return -EINVAL;
+error_setg(errp, "Illegal numa node %d", pxb->numa_node);
+return;
 }
 
 if (dev->qdev.id && *dev->qdev.id) {
@@ -248,7 +245,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
-if (pxb_register_bus(dev, bus)) {
+pxb_register_bus(dev, bus, _err);
+if (local_err) {
+error_propagate(errp, local_err);
 goto err_register_bus;
 }
 
@@ -262,23 +261,22 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
-return 0;
+return;
 
 err_register_bus:
 object_unref(OBJECT(bds));
 object_unparent(OBJECT(bus));
 object_unref(OBJECT(ds));
-return -EINVAL;
 }
 
-static int pxb_dev_initfn(PCIDevice *dev)
+static void pxb_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (pci_bus_is_express(dev->bus)) {
-error_report("pxb devices cannot reside on a PCIe bus!");
-return -EINVAL;
+error_setg(errp, "pxb devices cannot reside on a PCIe bus");
+return;
 }
 
-return pxb_dev_init_common(dev, false);
+pxb_dev_realize_common(dev, false, errp);
 }
 
 static void pxb_dev_exitfn(PCIDevice *pci_dev)
@@ -300,7 +298,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_dev_initfn;
+k->realize = pxb_dev_realize;
 k->exit = pxb_dev_exitfn;
 k->vendor_id = PCI_VENDOR_ID_REDHAT;
 k->device_id = PCI_DEVICE_ID_REDHAT_PXB;
@@ -318,14 +316,14 @@ static const TypeInfo pxb_dev_info = {
 .class_init= pxb_dev_class_init,
 };
 
-static int pxb_pcie_dev_initfn(PCIDevice *dev)
+static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (!pci_bus_is_express(dev->bus)) {
-error_report("pxb-pcie devices cannot reside on a PCI bus!");
-return -EINVAL;
+error_setg(errp, "pxb-pcie devices cannot reside on a PCI bus");
+   

[Qemu-devel] [PATCH 3/3] use g_path_get_basename instead of basename

2016-04-06 Thread Wei Jiangang
Using g_strdup and g_basename to get the last component
of filename is not the best solution,
Only g_path_get_basename can achive the purpose we want.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 fsdev/virtfs-proxy-helper.c |  6 +-
 hw/9pfs/9p-local.c  |  6 +++---
 hw/vfio/pci.c   |  6 --
 hw/vfio/platform.c  |  6 --
 qemu-io.c   | 33 -
 qemu-nbd.c  |  4 +++-
 qga/commands-posix.c|  4 ++--
 7 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 54f7ad1..a0d6118 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -787,6 +787,8 @@ error:
 
 static void usage(char *prog)
 {
+char *base_filename = g_path_get_basename(prog);
+
 fprintf(stderr, "usage: %s\n"
 " -p|--path  9p path to export\n"
 " {-f|--fd } socket file descriptor to be 
used\n"
@@ -795,7 +797,9 @@ static void usage(char *prog)
 " access to this socket\n"
 " \tNote: -s & -f can not be used together\n"
 " [-n|--nodaemon] Run as a normal program\n",
-basename(prog));
+base_filename);
+
+g_free(base_filename);
 }
 
 static int process_reply(int sock, int type,
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 16f45f4..4e6c17a 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -160,17 +160,17 @@ static int local_create_mapped_attr_dir(FsContext *ctx, 
const char *path)
 {
 int err;
 char *attr_dir;
-char *tmp_path = g_strdup(path);
+char *base_filename = g_path_get_basename(path);
 
 attr_dir = g_strdup_printf("%s/%s/%s",
- ctx->fs_root, dirname(tmp_path), VIRTFS_META_DIR);
+ ctx->fs_root, base_filename, VIRTFS_META_DIR);
 
 err = mkdir(attr_dir, 0700);
 if (err < 0 && errno == EEXIST) {
 err = 0;
 }
 g_free(attr_dir);
-g_free(tmp_path);
+g_free(base_filename);
 return err;
 }
 
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index d091d8c..d23b871 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2413,7 +2413,7 @@ static int vfio_initfn(PCIDevice *pdev)
 return -errno;
 }
 
-vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
+vdev->vbasedev.name = g_path_get_basename(vdev->vbasedev.sysfsdev);
 vdev->vbasedev.ops = _pci_ops;
 vdev->vbasedev.type = VFIO_DEVICE_TYPE_PCI;
 
@@ -2428,11 +2428,13 @@ static int vfio_initfn(PCIDevice *pdev)
 
 group_path[len] = 0;
 
-group_name = basename(group_path);
+group_name = g_path_get_basename(group_path);
 if (sscanf(group_name, "%d", ) != 1) {
 error_report("vfio: error reading %s: %m", group_path);
+g_free(group_name);
 return -errno;
 }
+g_free(group_name);
 
 trace_vfio_initfn(vdev->vbasedev.name, groupid);
 
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 1798a00..47134db 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -557,7 +557,7 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
 /* @sysfsdev takes precedence over @host */
 if (vbasedev->sysfsdev) {
 g_free(vbasedev->name);
-vbasedev->name = g_strdup(basename(vbasedev->sysfsdev));
+vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
 } else {
 if (!vbasedev->name || strchr(vbasedev->name, '/')) {
 return -EINVAL;
@@ -584,11 +584,13 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
 
 group_path[len] = 0;
 
-group_name = basename(group_path);
+group_name = g_path_get_basename(group_path);
 if (sscanf(group_name, "%d", ) != 1) {
 error_report("vfio: error reading %s: %m", group_path);
+g_free(group_name);
 return -errno;
 }
+g_free(group_name);
 
 trace_vfio_platform_base_device_init(vbasedev->name, groupid);
 
diff --git a/qemu-io.c b/qemu-io.c
index 0a738f1..2f5c616 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -249,6 +249,12 @@ static char *get_prompt(void)
 return prompt;
 }
 
+static void cleanup_and_exit(int status)
+{
+g_free(progname);
+exit(status);
+}
+
 static void GCC_FMT_ATTR(2, 3) readline_printf_func(void *opaque,
 const char *fmt, ...)
 {
@@ -440,7 +446,7 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
-progname = basename(argv[0]);
+progname = g_path_get_basename(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
 module_call_init(MODULE_INIT_QOM);
@@ -459,7 +465,7 @@ int main(int argc, char **argv)
 case 'd':
 if (bdrv_parse_discard_flags(optarg, ) < 0) {
 error_report(&qu

[Qemu-devel] [PATCH 0/3] bitsized task for glib conversion

2016-04-06 Thread Wei Jiangang
The series used to change basename and dirname to
g_path_get_basename() and g_path_get_dirname() respectively.

Refer to http://wiki.qemu.org/BiteSizedTasks#API_conversion

*** BLURB HERE ***

Wei Jiangang (3):
  linux-user: complete omission of removing uses of strdup
  use g_path_get_dirname instead of dirname
  use g_path_get_basename instead of basename

 fsdev/virtfs-proxy-helper.c |  6 +-
 hw/9pfs/9p-local.c  |  6 +++---
 hw/vfio/pci.c   |  6 --
 hw/vfio/platform.c  |  6 --
 linux-user/elfload.c|  7 ++-
 os-posix.c  |  3 ++-
 qemu-io.c   | 33 -
 qemu-nbd.c  |  4 +++-
 qga/commands-posix.c|  4 ++--
 util/oslib-posix.c  |  4 +++-
 10 files changed, 48 insertions(+), 31 deletions(-)

-- 
1.9.3






[Qemu-devel] [PATCH 1/3] linux-user: complete omission of removing uses of strdup

2016-04-06 Thread Wei Jiangang
The 900cfbc just removed two unchecked uses of strdup
in fill_psinfo and missed the rest in core_dump_filename.
This patch fixes it.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 linux-user/elfload.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index e47caff..6373320 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2718,7 +2718,6 @@ static int core_dump_filename(const TaskState *ts, char 
*buf,
   size_t bufsize)
 {
 char timestamp[64];
-char *filename = NULL;
 char *base_filename = NULL;
 struct timeval tv;
 struct tm tm;
@@ -2731,14 +2730,12 @@ static int core_dump_filename(const TaskState *ts, char 
*buf,
 return (-1);
 }
 
-filename = strdup(ts->bprm->filename);
-base_filename = strdup(basename(filename));
+base_filename = g_path_get_basename(ts->bprm->filename);
 (void) strftime(timestamp, sizeof (timestamp), "%Y%m%d-%H%M%S",
 localtime_r(_sec, ));
 (void) snprintf(buf, bufsize, "qemu_%s_%s_%d.core",
 base_filename, timestamp, (int)getpid());
-free(base_filename);
-free(filename);
+g_free(base_filename);
 
 return (0);
 }
-- 
1.9.3






[Qemu-devel] [PATCH 2/3] use g_path_get_dirname instead of dirname

2016-04-06 Thread Wei Jiangang
Use g_path_get_basename to get the directory components of
a file name, and free its return when no longer needed.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 os-posix.c | 3 ++-
 util/oslib-posix.c | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 107fde3..bcaef17 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -90,7 +90,7 @@ char *os_find_datadir(void)
 if (exec_dir == NULL) {
 return NULL;
 }
-dir = dirname(exec_dir);
+dir = g_path_get_dirname(exec_dir);
 
 max_len = strlen(dir) +
 MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
@@ -104,6 +104,7 @@ char *os_find_datadir(void)
 }
 }
 
+g_free(dir);
 g_free(exec_dir);
 return res;
 }
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 20ca141..1d3248c 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -312,9 +312,11 @@ void qemu_init_exec_dir(const char *argv0)
 return;
 }
 }
-dir = dirname(p);
+dir = g_path_get_dirname(p);
 
 pstrcpy(exec_dir, sizeof(exec_dir), dir);
+
+g_free(dir);
 }
 
 char *qemu_get_exec_dir(void)
-- 
1.9.3






Re: [Qemu-devel] [PATCH] docs: fix typo in memory.txt

2016-04-05 Thread Wei, Jiangang
On Wed, 2016-04-06 at 01:02 +0200, Paolo Bonzini wrote:
> 
> On 22/03/2016 10:45, Wei Jiangang wrote:
> > The scale line should align with A line's end,
> 
> No, A ends at 0x7fff so the line should end just before.  See what
> happens for B/C/D/E.

Yes, you're right.
Thanks for your reply.

Regards,
wei
> However, the space between 7000 and 8000 is indede 7 characters instead
> of 6, so I will take your patch and also reduce the space between A's
> brackets.
> 
> Thanks,
> 
> Paolo
> 
> > and correct the range of vga-window example 0xa-0xb.
> 
> 
> > Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> > ---
> >  docs/memory.txt | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/docs/memory.txt b/docs/memory.txt
> > index 97134e1..5a7163c 100644
> > --- a/docs/memory.txt
> > +++ b/docs/memory.txt
> > @@ -185,8 +185,8 @@ an MMIO region mapped at 0x0, size 0x6000, priority 1. 
> > B currently has two
> >  of its own subregions: D of size 0x1000 at offset 0 and E of size 0x1000 at
> >  offset 0x2000. As a diagram:
> >  
> > -0  1000   2000   3000   4000   5000   6000   70008000
> > -|--|--|--|--|--|--|--|---|
> > +0  1000   2000   3000   4000   5000   6000   7000   8000
> > +|--|--|--|--|--|--|--|--|
> >A:[   ]
> >C:[]
> >B:  [  ]
> > @@ -247,7 +247,7 @@ system_memory: container@0-2^48-1
> >   |
> >   + himem: alias@0x1-0x11fff ---> #ram 
> > (0xe000-0x)
> >   |
> > - + vga-window: alias@0xa-0xbf ---> #pci (0xa-0xb)
> > + + vga-window: alias@0xa-0xb ---> #pci (0xa-0xb)
> >   |  (prio 1)
> >   |
> >   + pci-hole: alias@0xe000-0x ---> #pci 
> > (0xe000-0x)
> > 
> 
> 





Re: [Qemu-devel] [PATCH] docs: fix typo in memory.txt

2016-04-04 Thread Wei, Jiangang
ping...
Any feedback?
On Tue, 2016-03-22 at 17:45 +0800, Wei Jiangang wrote:
> The scale line should align with A line's end,
> and correct the range of vga-window example 0xa-0xb.
> 
> Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
> ---
>  docs/memory.txt | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/docs/memory.txt b/docs/memory.txt
> index 97134e1..5a7163c 100644
> --- a/docs/memory.txt
> +++ b/docs/memory.txt
> @@ -185,8 +185,8 @@ an MMIO region mapped at 0x0, size 0x6000, priority 1. B 
> currently has two
>  of its own subregions: D of size 0x1000 at offset 0 and E of size 0x1000 at
>  offset 0x2000. As a diagram:
>  
> -0  1000   2000   3000   4000   5000   6000   70008000
> -|--|--|--|--|--|--|--|---|
> +0  1000   2000   3000   4000   5000   6000   7000   8000
> +|--|--|--|--|--|--|--|--|
>A:[   ]
>C:[]
>B:  [  ]
> @@ -247,7 +247,7 @@ system_memory: container@0-2^48-1
>   |
>   + himem: alias@0x1-0x11fff ---> #ram (0xe000-0x)
>   |
> - + vga-window: alias@0xa-0xbf ---> #pci (0xa-0xb)
> + + vga-window: alias@0xa-0xb ---> #pci (0xa-0xb)
>   |  (prio 1)
>   |
>   + pci-hole: alias@0xe000-0x ---> #pci 
> (0xe000-0x)





Re: [Qemu-devel] [PATCH v3 2/2] hw/pci-bridge: Convert pxb initialization functions to Error

2016-03-23 Thread Wei, Jiangang
On Wed, 2016-03-23 at 13:05 +0100, Markus Armbruster wrote:
> Wei Jiangang <weijg.f...@cn.fujitsu.com> writes:
> 
> > Firstly, convert pxb_dev_init_common() to Error and rename
> > it to pxb_dev_realize_common().
> > Actually, pxb_register_bus() is converted as well.
> >
> > And then,
> > convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
> > rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
> > respectively.
> > ---
> >  hw/pci-bridge/pci_expander_bridge.c | 54 
> > ++---
> >  1 file changed, 27 insertions(+), 27 deletions(-)
> >
> > diff --git a/hw/pci-bridge/pci_expander_bridge.c 
> > b/hw/pci-bridge/pci_expander_bridge.c
> > index ba320bd..6f53a6b 100644
> > --- a/hw/pci-bridge/pci_expander_bridge.c
> > +++ b/hw/pci-bridge/pci_expander_bridge.c
> > @@ -160,30 +160,25 @@ static const TypeInfo pxb_host_info = {
> >  };
> >  
> >  /*
> > - * Registers the PXB bus as a child of the i440fx root bus.
> > - *
> > - * Returns 0 on successs, -1 if i440fx host was not
> > - * found or the bus number is already in use.
> > + * Registers the PXB bus as a child of pci host root bus.
> >   */
> > -static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus)
> > +static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp)
> >  {
> >  PCIBus *bus = dev->bus;
> >  int pxb_bus_num = pci_bus_num(pxb_bus);
> >  
> >  if (bus->parent_dev) {
> > -error_report("PXB devices can be attached only to root bus.");
> > -return -1;
> > +error_setg(errp, "PXB devices can be attached only to root bus");
> > +return;
> >  }
> >  
> >  QLIST_FOREACH(bus, >child, sibling) {
> >  if (pci_bus_num(bus) == pxb_bus_num) {
> > -error_report("Bus %d is already in use.", pxb_bus_num);
> > -return -1;
> > +error_setg(errp, "Bus %d is already in use", pxb_bus_num);
> > +return;
> >  }
> >  }
> >  QLIST_INSERT_HEAD(>bus->child, pxb_bus, sibling);
> > -
> > -return 0;
> >  }
> >  
> >  static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
> > @@ -213,17 +208,21 @@ static gint pxb_compare(gconstpointer a, 
> > gconstpointer b)
> > 0;
> >  }
> >  
> > -static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
> > +static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
> >  {
> >  PXBDev *pxb = convert_to_pxb(dev);
> >  DeviceState *ds, *bds = NULL;
> >  PCIBus *bus;
> >  const char *dev_name = NULL;
> > +Error *err = NULL;
> >  
> >  if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
> >  pxb->numa_node >= nb_numa_nodes) {
> > -error_report("Illegal numa node %d.", pxb->numa_node);
> > -return -EINVAL;
> > +error_setg(, "Illegal numa node %d", pxb->numa_node);
> > +if (err) {
> > +error_propagate(errp, err);
> > +}
> 
> No.  v2 got it right.
Thanks for your response.
OK, Let us discard v3.

> 
> > +return;
> >  }
> >  
> >  if (dev->qdev.id && *dev->qdev.id) {
> [...]
> 
> 





[Qemu-devel] [PATCH v3 2/2] hw/pci-bridge: Convert pxb initialization functions to Error

2016-03-23 Thread Wei Jiangang
Firstly, convert pxb_dev_init_common() to Error and rename
it to pxb_dev_realize_common().
Actually, pxb_register_bus() is converted as well.

And then,
convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
respectively.
---
 hw/pci-bridge/pci_expander_bridge.c | 54 ++---
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index ba320bd..6f53a6b 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -160,30 +160,25 @@ static const TypeInfo pxb_host_info = {
 };
 
 /*
- * Registers the PXB bus as a child of the i440fx root bus.
- *
- * Returns 0 on successs, -1 if i440fx host was not
- * found or the bus number is already in use.
+ * Registers the PXB bus as a child of pci host root bus.
  */
-static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus)
+static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp)
 {
 PCIBus *bus = dev->bus;
 int pxb_bus_num = pci_bus_num(pxb_bus);
 
 if (bus->parent_dev) {
-error_report("PXB devices can be attached only to root bus.");
-return -1;
+error_setg(errp, "PXB devices can be attached only to root bus");
+return;
 }
 
 QLIST_FOREACH(bus, >child, sibling) {
 if (pci_bus_num(bus) == pxb_bus_num) {
-error_report("Bus %d is already in use.", pxb_bus_num);
-return -1;
+error_setg(errp, "Bus %d is already in use", pxb_bus_num);
+return;
 }
 }
 QLIST_INSERT_HEAD(>bus->child, pxb_bus, sibling);
-
-return 0;
 }
 
 static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
@@ -213,17 +208,21 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)
0;
 }
 
-static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
+static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
 {
 PXBDev *pxb = convert_to_pxb(dev);
 DeviceState *ds, *bds = NULL;
 PCIBus *bus;
 const char *dev_name = NULL;
+Error *err = NULL;
 
 if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
 pxb->numa_node >= nb_numa_nodes) {
-error_report("Illegal numa node %d.", pxb->numa_node);
-return -EINVAL;
+error_setg(, "Illegal numa node %d", pxb->numa_node);
+if (err) {
+error_propagate(errp, err);
+}
+return;
 }
 
 if (dev->qdev.id && *dev->qdev.id) {
@@ -248,7 +247,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
-if (pxb_register_bus(dev, bus)) {
+pxb_register_bus(dev, bus, );
+if (err) {
+error_propagate(errp, err);
 goto err_register_bus;
 }
 
@@ -262,23 +263,22 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
-return 0;
+return;
 
 err_register_bus:
 object_unref(OBJECT(bds));
 object_unparent(OBJECT(bus));
 object_unref(OBJECT(ds));
-return -EINVAL;
 }
 
-static int pxb_dev_initfn(PCIDevice *dev)
+static void pxb_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (pci_bus_is_express(dev->bus)) {
-error_report("pxb devices cannot reside on a PCIe bus!");
-return -EINVAL;
+error_setg(errp, "pxb devices cannot reside on a PCIe bus");
+return;
 }
 
-return pxb_dev_init_common(dev, false);
+pxb_dev_realize_common(dev, false, errp);
 }
 
 static void pxb_dev_exitfn(PCIDevice *pci_dev)
@@ -300,7 +300,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_dev_initfn;
+k->realize = pxb_dev_realize;
 k->exit = pxb_dev_exitfn;
 k->vendor_id = PCI_VENDOR_ID_REDHAT;
 k->device_id = PCI_DEVICE_ID_REDHAT_PXB;
@@ -318,14 +318,14 @@ static const TypeInfo pxb_dev_info = {
 .class_init= pxb_dev_class_init,
 };
 
-static int pxb_pcie_dev_initfn(PCIDevice *dev)
+static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (!pci_bus_is_express(dev->bus)) {
-error_report("pxb-pcie devices cannot reside on a PCI bus!");
-return -EINVAL;
+error_setg(errp, "pxb-pcie devices cannot reside on a PCI bus");
+return;
 }
 
-return pxb_dev_init_common(dev, true);
+pxb_dev_realize_common(dev, true, errp);
 }
 
 static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
@@ -333,7 +333,7 @@ static void pxb_pcie_dev_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_pcie_dev_initfn;
+k->realize = pxb_pcie_dev_realize;
 k->exit = 

[Qemu-devel] [PATCH v3 0/2] Convert pxb initfn to Error

2016-03-23 Thread Wei Jiangang
v2 -> v3:
- Pass local *err to error_setg() in pxb_dev_realize_common()

v1 -> v2:

- Extract a separate bugfix patch
- Squash v1 patches 1-3 together
- Drop the period and exclamation mark
- Modify commit message 

v1: cover-letter

The original patch named '[PATCH v3] PXB: convert to realize()'
was raised by Cao jin <caoj.f...@cn.fujitsu.com>,
and reviewed by Marcel Apfelbaum <mar...@redhat.com>.

It conflicts with 02b0743 that had been merged,
so resend a newer version, including the following,

hw/pci-bridge: modify pxb_dev_init_common
pxb: convert to realize()
pxb-pcie: convert to realize()

Wei Jiangang (2):
  hw/pci-bridge: Add missing unref in case register-bus fails
  hw/pci-bridge: Convert pxb initialization functions to Error

 hw/pci-bridge/pci_expander_bridge.c | 60 -
 1 file changed, 33 insertions(+), 27 deletions(-)

-- 
1.9.3






[Qemu-devel] [PATCH v3 1/2] hw/pci-bridge: Add missing unref in case register-bus fails

2016-03-23 Thread Wei Jiangang
The error paths after a successful qdev_create/pci_bus_new
should contain a object_unref/object_unparent.
pxb_dev_init_common() did not yet, so add it.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index 5e7e546..ba320bd 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -249,7 +249,7 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
 if (pxb_register_bus(dev, bus)) {
-return -EINVAL;
+goto err_register_bus;
 }
 
 qdev_init_nofail(ds);
@@ -263,6 +263,12 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
 return 0;
+
+err_register_bus:
+object_unref(OBJECT(bds));
+object_unparent(OBJECT(bus));
+object_unref(OBJECT(ds));
+return -EINVAL;
 }
 
 static int pxb_dev_initfn(PCIDevice *dev)
-- 
1.9.3






[Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error

2016-03-23 Thread Wei Jiangang
v1 -> v2:

- Extract a separate bugfix patch
- Squash v1 patches 1-3 together
- Drop the period and exclamation mark
- Modify commit message 

v1: cover-letter

The original patch named '[PATCH v3] PXB: convert to realize()'
was raised by Cao jin <caoj.f...@cn.fujitsu.com>,
and reviewed by Marcel Apfelbaum <mar...@redhat.com>.

It conflicts with 02b0743 that had been merged,
so resend a newer version, including the following,

hw/pci-bridge: modify pxb_dev_init_common
pxb: convert to realize()
pxb-pcie: convert to realize()

Wei Jiangang (2):
  hw/pci-bridge: Add missing unref in case register-bus fails
  hw/pci-bridge: Convert pxb initialization functions to Error

 hw/pci-bridge/pci_expander_bridge.c | 57 +++--
 1 file changed, 30 insertions(+), 27 deletions(-)

-- 
1.9.3






[Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error

2016-03-23 Thread Wei Jiangang
Firstly, convert pxb_dev_init_common() to Error and rename
it to pxb_dev_realize_common().
Actually, pxb_register_bus() is converted as well.

And then,
convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
respectively.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 51 +
 1 file changed, 24 insertions(+), 27 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index ba320bd..efb8863 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -160,30 +160,25 @@ static const TypeInfo pxb_host_info = {
 };
 
 /*
- * Registers the PXB bus as a child of the i440fx root bus.
- *
- * Returns 0 on successs, -1 if i440fx host was not
- * found or the bus number is already in use.
+ * Registers the PXB bus as a child of pci host root bus.
  */
-static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus)
+static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp)
 {
 PCIBus *bus = dev->bus;
 int pxb_bus_num = pci_bus_num(pxb_bus);
 
 if (bus->parent_dev) {
-error_report("PXB devices can be attached only to root bus.");
-return -1;
+error_setg(errp, "PXB devices can be attached only to root bus");
+return;
 }
 
 QLIST_FOREACH(bus, >child, sibling) {
 if (pci_bus_num(bus) == pxb_bus_num) {
-error_report("Bus %d is already in use.", pxb_bus_num);
-return -1;
+error_setg(errp, "Bus %d is already in use", pxb_bus_num);
+return;
 }
 }
 QLIST_INSERT_HEAD(>bus->child, pxb_bus, sibling);
-
-return 0;
 }
 
 static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
@@ -213,17 +208,18 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)
0;
 }
 
-static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
+static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
 {
 PXBDev *pxb = convert_to_pxb(dev);
 DeviceState *ds, *bds = NULL;
 PCIBus *bus;
 const char *dev_name = NULL;
+Error *local_err = NULL;
 
 if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
 pxb->numa_node >= nb_numa_nodes) {
-error_report("Illegal numa node %d.", pxb->numa_node);
-return -EINVAL;
+error_setg(errp, "Illegal numa node %d", pxb->numa_node);
+return;
 }
 
 if (dev->qdev.id && *dev->qdev.id) {
@@ -248,7 +244,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
-if (pxb_register_bus(dev, bus)) {
+pxb_register_bus(dev, bus, _err);
+if (local_err) {
+error_propagate(errp, local_err);
 goto err_register_bus;
 }
 
@@ -262,23 +260,22 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
-return 0;
+return;
 
 err_register_bus:
 object_unref(OBJECT(bds));
 object_unparent(OBJECT(bus));
 object_unref(OBJECT(ds));
-return -EINVAL;
 }
 
-static int pxb_dev_initfn(PCIDevice *dev)
+static void pxb_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (pci_bus_is_express(dev->bus)) {
-error_report("pxb devices cannot reside on a PCIe bus!");
-return -EINVAL;
+error_setg(errp, "pxb devices cannot reside on a PCIe bus");
+return;
 }
 
-return pxb_dev_init_common(dev, false);
+pxb_dev_realize_common(dev, false, errp);
 }
 
 static void pxb_dev_exitfn(PCIDevice *pci_dev)
@@ -300,7 +297,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_dev_initfn;
+k->realize = pxb_dev_realize;
 k->exit = pxb_dev_exitfn;
 k->vendor_id = PCI_VENDOR_ID_REDHAT;
 k->device_id = PCI_DEVICE_ID_REDHAT_PXB;
@@ -318,14 +315,14 @@ static const TypeInfo pxb_dev_info = {
 .class_init= pxb_dev_class_init,
 };
 
-static int pxb_pcie_dev_initfn(PCIDevice *dev)
+static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)
 {
 if (!pci_bus_is_express(dev->bus)) {
-error_report("pxb-pcie devices cannot reside on a PCI bus!");
-return -EINVAL;
+error_setg(errp, "pxb-pcie devices cannot reside on a PCI bus");
+return;
 }
 
-return pxb_dev_init_common(dev, true);
+pxb_dev_realize_common(dev, true, errp);
 }
 
 static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
@@ -33

[Qemu-devel] [PATCH v2 1/2] hw/pci-bridge: Add missing unref in case register-bus fails

2016-03-23 Thread Wei Jiangang
The error paths after a successful qdev_create/pci_bus_new
should contain a object_unref/object_unparent.
pxb_dev_init_common() did not yet, so add it.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index 5e7e546..ba320bd 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -249,7 +249,7 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
 if (pxb_register_bus(dev, bus)) {
-return -EINVAL;
+goto err_register_bus;
 }
 
 qdev_init_nofail(ds);
@@ -263,6 +263,12 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
 return 0;
+
+err_register_bus:
+object_unref(OBJECT(bds));
+object_unparent(OBJECT(bus));
+object_unref(OBJECT(ds));
+return -EINVAL;
 }
 
 static int pxb_dev_initfn(PCIDevice *dev)
-- 
1.9.3






[Qemu-devel] [PATCH] docs: fix typo in memory.txt

2016-03-22 Thread Wei Jiangang
The scale line should align with A line's end,
and correct the range of vga-window example 0xa-0xb.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 docs/memory.txt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/docs/memory.txt b/docs/memory.txt
index 97134e1..5a7163c 100644
--- a/docs/memory.txt
+++ b/docs/memory.txt
@@ -185,8 +185,8 @@ an MMIO region mapped at 0x0, size 0x6000, priority 1. B 
currently has two
 of its own subregions: D of size 0x1000 at offset 0 and E of size 0x1000 at
 offset 0x2000. As a diagram:
 
-0  1000   2000   3000   4000   5000   6000   70008000
-|--|--|--|--|--|--|--|---|
+0  1000   2000   3000   4000   5000   6000   7000   8000
+|--|--|--|--|--|--|--|--|
   A:[   ]
   C:[]
   B:  [  ]
@@ -247,7 +247,7 @@ system_memory: container@0-2^48-1
  |
  + himem: alias@0x1-0x11fff ---> #ram (0xe000-0x)
  |
- + vga-window: alias@0xa-0xbf ---> #pci (0xa-0xb)
+ + vga-window: alias@0xa-0xb ---> #pci (0xa-0xb)
  |  (prio 1)
  |
  + pci-hole: alias@0xe000-0x ---> #pci (0xe000-0x)
-- 
1.9.3






[Qemu-devel] [PATCH] vl: fix comment about when parsing cpu definitions

2016-03-16 Thread Wei Jiangang
machine->init() was replaced with machine_class->init().

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 vl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index 7a28982..3c403d1 100644
--- a/vl.c
+++ b/vl.c
@@ -4079,7 +4079,7 @@ int main(int argc, char **argv, char **envp)
 /* Init CPU def lists, based on config
  * - Must be called after all the qemu_read_config_file() calls
  * - Must be called before list_cpus()
- * - Must be called before machine->init()
+ * - Must be called before machine_class->init()
  */
 cpudef_init();
 
-- 
1.9.3






[Qemu-devel] [PATCH] accel: make configure_accelerator return void

2016-03-15 Thread Wei Jiangang
Return the negated value of accel_initialised is meaningless,
and the caller vl doesn't check it.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 accel.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/accel.c b/accel.c
index 0510b90..403eb5e 100644
--- a/accel.c
+++ b/accel.c
@@ -77,7 +77,7 @@ static int accel_init_machine(AccelClass *acc, MachineState 
*ms)
 return ret;
 }
 
-int configure_accelerator(MachineState *ms)
+void configure_accelerator(MachineState *ms)
 {
 const char *p;
 char buf[10];
@@ -128,8 +128,6 @@ int configure_accelerator(MachineState *ms)
 if (init_failed) {
 fprintf(stderr, "Back to %s accelerator.\n", acc->name);
 }
-
-return !accel_initialised;
 }
 
 
-- 
1.9.3






[Qemu-devel] [PATCH 1/3] hw/pci-bridge: modify pxb_dev_init_common

2016-03-14 Thread Wei Jiangang
1) add Error **errp parameter for it,
2) rename pxb_dev_init_common to pxb_dev_realize_common,
   and prepare for pxb/pxb-pcie convert to realize.
3) modify the callers,
   including pxb_dev_initfn and pxb_pcie_dev_initfn.

Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 56 -
 1 file changed, 37 insertions(+), 19 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index d23b8da..ce5baf8 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -160,30 +160,25 @@ static const TypeInfo pxb_host_info = {
 };
 
 /*
- * Registers the PXB bus as a child of the i440fx root bus.
- *
- * Returns 0 on successs, -1 if i440fx host was not
- * found or the bus number is already in use.
+ * Registers the PXB bus as a child of pci host root bus.
  */
-static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus)
+static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp)
 {
 PCIBus *bus = dev->bus;
 int pxb_bus_num = pci_bus_num(pxb_bus);
 
 if (bus->parent_dev) {
-error_report("PXB devices can be attached only to root bus.");
-return -1;
+error_setg(errp, "PXB devices can be attached only to root bus.");
+return;
 }
 
 QLIST_FOREACH(bus, >child, sibling) {
 if (pci_bus_num(bus) == pxb_bus_num) {
-error_report("Bus %d is already in use.", pxb_bus_num);
-return -1;
+error_setg(errp, "Bus %d is already in use.", pxb_bus_num);
+return;
 }
 }
 QLIST_INSERT_HEAD(>bus->child, pxb_bus, sibling);
-
-return 0;
 }
 
 static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
@@ -213,7 +208,7 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)
0;
 }
 
-static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
+static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)
 {
 PXBDev *pxb = convert_to_pxb(dev);
 DeviceState *ds, *bds = NULL;
@@ -222,8 +217,8 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
 pxb->numa_node >= nb_numa_nodes) {
-error_report("Illegal numa node %d.", pxb->numa_node);
-return -EINVAL;
+error_setg(errp, "Illegal numa node %d.", pxb->numa_node);
+return;
 }
 
 if (dev->qdev.id && *dev->qdev.id) {
@@ -248,8 +243,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
 PCI_HOST_BRIDGE(ds)->bus = bus;
 
-if (pxb_register_bus(dev, bus)) {
-return -EINVAL;
+pxb_register_bus(dev, bus, errp);
+if (*errp) {
+goto err_register_bus;
 }
 
 qdev_init_nofail(ds);
@@ -262,17 +258,31 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);
 
 pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
-return 0;
+
+return;
+
+err_register_bus:
+object_unref(OBJECT(bds));
+object_unparent(OBJECT(bus));
+object_unref(OBJECT(ds));
 }
 
 static int pxb_dev_initfn(PCIDevice *dev)
 {
+Error *err = NULL;
+
 if (pci_bus_is_express(dev->bus)) {
 error_report("pxb devices cannot reside on a PCIe bus!");
 return -EINVAL;
 }
 
-return pxb_dev_init_common(dev, false);
+pxb_dev_realize_common(dev, false, );
+if (err) {
+error_report_err(err);
+return -EINVAL;
+}
+
+return 0;
 }
 
 static void pxb_dev_exitfn(PCIDevice *pci_dev)
@@ -314,12 +324,20 @@ static const TypeInfo pxb_dev_info = {
 
 static int pxb_pcie_dev_initfn(PCIDevice *dev)
 {
+Error *err = NULL;
+
 if (!pci_bus_is_express(dev->bus)) {
 error_report("pxb-pcie devices cannot reside on a PCI bus!");
 return -EINVAL;
 }
 
-return pxb_dev_init_common(dev, true);
+pxb_dev_realize_common(dev, true, );
+if (err) {
+error_report_err(err);
+return -EINVAL;
+}
+
+return 0;
 }
 
 static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
-- 
1.9.3






[Qemu-devel] [PATCH 3/3] pxb-pcie: convert to realize()

2016-03-14 Thread Wei Jiangang
Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index cc5074d..64267d8 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -314,22 +314,14 @@ static const TypeInfo pxb_dev_info = {
 .class_init= pxb_dev_class_init,
 };
 
-static int pxb_pcie_dev_initfn(PCIDevice *dev)
+static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)
 {
-Error *err = NULL;
-
 if (!pci_bus_is_express(dev->bus)) {
-error_report("pxb-pcie devices cannot reside on a PCI bus!");
-return -EINVAL;
-}
-
-pxb_dev_realize_common(dev, true, );
-if (err) {
-error_report_err(err);
-return -EINVAL;
+error_setg(errp, "pxb-pcie devices cannot reside on a PCI bus!");
+return;
 }
 
-return 0;
+pxb_dev_realize_common(dev, true, errp);
 }
 
 static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
@@ -337,7 +329,7 @@ static void pxb_pcie_dev_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_pcie_dev_initfn;
+k->realize = pxb_pcie_dev_realize;
 k->exit = pxb_dev_exitfn;
 k->vendor_id = PCI_VENDOR_ID_REDHAT;
 k->device_id = PCI_DEVICE_ID_REDHAT_PXB_PCIE;
-- 
1.9.3






[Qemu-devel] [PATCH 0/3] conversion to realize for pxb/pxb-pcie

2016-03-14 Thread Wei Jiangang
The previous patch named '[PATCH v3] PXB: convert to realize()'
was raised by Cao jin <caoj.f...@cn.fujitsu.com>,
and reviewed by Marcel Apfelbaum <mar...@redhat.com>.

It conflicts with 02b0743 that had been merged,
so resend a newer version.

Wei Jiangang (3):
  hw/pci-bridge: modify pxb_dev_init_common
  pxb: convert to realize()
  pxb-pcie: convert to realize()

 hw/pci-bridge/pci_expander_bridge.c | 56 +++--
 1 file changed, 29 insertions(+), 27 deletions(-)

-- 
1.9.3






[Qemu-devel] [PATCH 2/3] pxb: convert to realize()

2016-03-14 Thread Wei Jiangang
Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index ce5baf8..cc5074d 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -267,22 +267,14 @@ err_register_bus:
 object_unref(OBJECT(ds));
 }
 
-static int pxb_dev_initfn(PCIDevice *dev)
+static void pxb_dev_realize(PCIDevice *dev, Error **errp)
 {
-Error *err = NULL;
-
 if (pci_bus_is_express(dev->bus)) {
-error_report("pxb devices cannot reside on a PCIe bus!");
-return -EINVAL;
-}
-
-pxb_dev_realize_common(dev, false, );
-if (err) {
-error_report_err(err);
-return -EINVAL;
+error_setg(errp, "pxb devices cannot reside on a PCIe bus!");
+return;
 }
 
-return 0;
+pxb_dev_realize_common(dev, false, errp);
 }
 
 static void pxb_dev_exitfn(PCIDevice *pci_dev)
@@ -304,7 +296,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k->init = pxb_dev_initfn;
+k->realize = pxb_dev_realize;
 k->exit = pxb_dev_exitfn;
 k->vendor_id = PCI_VENDOR_ID_REDHAT;
 k->device_id = PCI_DEVICE_ID_REDHAT_PXB;
-- 
1.9.3






[Qemu-devel] [PATCH v1] util: fix comment typos

2016-03-14 Thread Wei Jiangang
Signed-off-by: Wei Jiangang <weijg.f...@cn.fujitsu.com>
---
 util/buffer.c   | 4 ++--
 util/qemu-sockets.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/util/buffer.c b/util/buffer.c
index a6118bf..33e94d1 100644
--- a/util/buffer.c
+++ b/util/buffer.c
@@ -25,7 +25,7 @@
 #define BUFFER_MIN_INIT_SIZE 4096
 #define BUFFER_MIN_SHRINK_SIZE  65536
 
-/* define the factor alpha for the expentional smoothing
+/* define the factor alpha for the exponential smoothing
  * that is used in the average size calculation. a shift
  * of 7 results in an alpha of 1/2^7. */
 #define BUFFER_AVG_SIZE_SHIFT   7
@@ -45,7 +45,7 @@ static void buffer_adj_size(Buffer *buffer, size_t len)
 old, buffer->capacity);
 
 /* make it even harder for the buffer to shrink, reset average size
- * to currenty capacity if it is larger than the average. */
+ * to current capacity if it is larger than the average. */
 buffer->avg_size = MAX(buffer->avg_size,
buffer->capacity << BUFFER_AVG_SIZE_SHIFT);
 }
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index ad7c00c..e1ef4ad 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -90,7 +90,7 @@ NetworkAddressFamily inet_netfamily(int family)
  *   t f   PF_INET
  *   t t   PF_INET6
  *
- * NB, this matrix is only about getting the neccessary results
+ * NB, this matrix is only about getting the necessary results
  * from getaddrinfo(). Some of the cases require further work
  * after reading results from getaddrinfo in order to fully
  * apply the logic the end user wants. eg with the last case
-- 
1.9.3