Message ID | 1421035354-14721-3-git-send-email-bharata@linux.vnet.ibm.com |
---|---|
State | New |
Headers | show |
On Mon, 12 Jan 2015 09:32:34 +0530 Bharata B Rao <bharata@linux.vnet.ibm.com> wrote: > Move pc_existing_dimms_capacity() to pc-dimm.c since it would be needed > by PowerPC memory hotplug code too. > > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> > --- > hw/i386/pc.c | 24 ------------------------ > hw/mem/pc-dimm.c | 25 +++++++++++++++++++++++++ > include/hw/mem/pc-dimm.h | 1 + > 3 files changed, 26 insertions(+), 24 deletions(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index 125cf0a..2ec45a4 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1552,30 +1552,6 @@ void qemu_register_pc_machine(QEMUMachine *m) > g_free(name); > } > > -static int pc_existing_dimms_capacity(Object *obj, void *opaque) > -{ > - Error *local_err = NULL; > - uint64_t *size = opaque; > - > - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { > - DeviceState *dev = DEVICE(obj); > - > - if (dev->realized) { > - (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, > - &local_err); > - } > - > - if (local_err) { > - qerror_report_err(local_err); > - error_free(local_err); > - return 1; > - } > - } > - > - object_child_foreach(obj, pc_existing_dimms_capacity, opaque); > - return 0; > -} > - > static void pc_dimm_plug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c > index d431834..f02ce6e 100644 > --- a/hw/mem/pc-dimm.c > +++ b/hw/mem/pc-dimm.c > @@ -22,6 +22,31 @@ > #include "qemu/config-file.h" > #include "qapi/visitor.h" > #include "qemu/range.h" > +#include "qapi/qmp/qerror.h" > + > +int pc_existing_dimms_capacity(Object *obj, void *opaque) > +{ since you are making it API, could you pass Error **errp argument and deal with error in caller? Along with it you can make function return void. > + Error *local_err = NULL; > + uint64_t *size = opaque; > + > + if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { > + DeviceState *dev = DEVICE(obj); > + > + if (dev->realized) { > + (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, > + &local_err); > + } > + > + if (local_err) { > + qerror_report_err(local_err); > + error_free(local_err); > + return 1; > + } > + } > + > + object_child_foreach(obj, pc_existing_dimms_capacity, opaque); > + return 0; > +} > > int qmp_pc_dimm_device_list(Object *obj, void *opaque) > { > diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h > index e1dcbbc..bbfa53f 100644 > --- a/include/hw/mem/pc-dimm.h > +++ b/include/hw/mem/pc-dimm.h > @@ -78,4 +78,5 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, > int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); > > int qmp_pc_dimm_device_list(Object *obj, void *opaque); > +int pc_existing_dimms_capacity(Object *obj, void *opaque); > #endif
On Tue, Jan 20, 2015 at 11:18:37AM +0100, Igor Mammedov wrote: > On Mon, 12 Jan 2015 09:32:34 +0530 > Bharata B Rao <bharata@linux.vnet.ibm.com> wrote: > > > Move pc_existing_dimms_capacity() to pc-dimm.c since it would be needed > > by PowerPC memory hotplug code too. > > > > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> > > --- > > hw/i386/pc.c | 24 ------------------------ > > hw/mem/pc-dimm.c | 25 +++++++++++++++++++++++++ > > include/hw/mem/pc-dimm.h | 1 + > > 3 files changed, 26 insertions(+), 24 deletions(-) > > > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > > index 125cf0a..2ec45a4 100644 > > --- a/hw/i386/pc.c > > +++ b/hw/i386/pc.c > > @@ -1552,30 +1552,6 @@ void qemu_register_pc_machine(QEMUMachine *m) > > g_free(name); > > } > > > > -static int pc_existing_dimms_capacity(Object *obj, void *opaque) > > -{ > > - Error *local_err = NULL; > > - uint64_t *size = opaque; > > - > > - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { > > - DeviceState *dev = DEVICE(obj); > > - > > - if (dev->realized) { > > - (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, > > - &local_err); > > - } > > - > > - if (local_err) { > > - qerror_report_err(local_err); > > - error_free(local_err); > > - return 1; > > - } > > - } > > - > > - object_child_foreach(obj, pc_existing_dimms_capacity, opaque); > > - return 0; > > -} > > - > > static void pc_dimm_plug(HotplugHandler *hotplug_dev, > > DeviceState *dev, Error **errp) > > { > > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c > > index d431834..f02ce6e 100644 > > --- a/hw/mem/pc-dimm.c > > +++ b/hw/mem/pc-dimm.c > > @@ -22,6 +22,31 @@ > > #include "qemu/config-file.h" > > #include "qapi/visitor.h" > > #include "qemu/range.h" > > +#include "qapi/qmp/qerror.h" > > + > > +int pc_existing_dimms_capacity(Object *obj, void *opaque) > > +{ > since you are making it API, could you pass Error **errp argument > and deal with error in caller? > Along with it you can make function return void. I don't think that can be done because pc_existing_dimms_capacity() calls itself recursively via object_child_foreach() and hence its signature if fixed. > > > + Error *local_err = NULL; > > + uint64_t *size = opaque; > > + > > + if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { > > + DeviceState *dev = DEVICE(obj); > > + > > + if (dev->realized) { > > + (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, > > + &local_err); > > + } > > + > > + if (local_err) { > > + qerror_report_err(local_err); > > + error_free(local_err); > > + return 1; > > + } > > + } > > + > > + object_child_foreach(obj, pc_existing_dimms_capacity, opaque); > > + return 0; > > +}
On Wed, 21 Jan 2015 14:28:18 +0530 Bharata B Rao <bharata@linux.vnet.ibm.com> wrote: > On Tue, Jan 20, 2015 at 11:18:37AM +0100, Igor Mammedov wrote: > > On Mon, 12 Jan 2015 09:32:34 +0530 > > Bharata B Rao <bharata@linux.vnet.ibm.com> wrote: > > > > > Move pc_existing_dimms_capacity() to pc-dimm.c since it would be needed > > > by PowerPC memory hotplug code too. > > > > > > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> > > > --- > > > hw/i386/pc.c | 24 ------------------------ > > > hw/mem/pc-dimm.c | 25 +++++++++++++++++++++++++ > > > include/hw/mem/pc-dimm.h | 1 + > > > 3 files changed, 26 insertions(+), 24 deletions(-) > > > > > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > > > index 125cf0a..2ec45a4 100644 > > > --- a/hw/i386/pc.c > > > +++ b/hw/i386/pc.c > > > @@ -1552,30 +1552,6 @@ void qemu_register_pc_machine(QEMUMachine *m) > > > g_free(name); > > > } > > > > > > -static int pc_existing_dimms_capacity(Object *obj, void *opaque) > > > -{ > > > - Error *local_err = NULL; > > > - uint64_t *size = opaque; > > > - > > > - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { > > > - DeviceState *dev = DEVICE(obj); > > > - > > > - if (dev->realized) { > > > - (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, > > > - &local_err); > > > - } > > > - > > > - if (local_err) { > > > - qerror_report_err(local_err); > > > - error_free(local_err); > > > - return 1; > > > - } > > > - } > > > - > > > - object_child_foreach(obj, pc_existing_dimms_capacity, opaque); > > > - return 0; > > > -} > > > - > > > static void pc_dimm_plug(HotplugHandler *hotplug_dev, > > > DeviceState *dev, Error **errp) > > > { > > > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c > > > index d431834..f02ce6e 100644 > > > --- a/hw/mem/pc-dimm.c > > > +++ b/hw/mem/pc-dimm.c > > > @@ -22,6 +22,31 @@ > > > #include "qemu/config-file.h" > > > #include "qapi/visitor.h" > > > #include "qemu/range.h" > > > +#include "qapi/qmp/qerror.h" > > > + > > > +int pc_existing_dimms_capacity(Object *obj, void *opaque) > > > +{ > > since you are making it API, could you pass Error **errp argument > > and deal with error in caller? > > Along with it you can make function return void. > > I don't think that can be done because pc_existing_dimms_capacity() calls > itself recursively via object_child_foreach() and hence its signature > if fixed. how about: typedef struct somename { uint64_t size; Error **errp; } somename; somename *foo = opaque; ... and if you'd be able to hide this structure from API caller, then function could return it's existing capacity via its return value. For example: static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque) { ... } /* API */ uint64_t pc_existing_dimms_capacity(Error **errp) { ... object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque); ... } > > > + > > > + if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { > > > + DeviceState *dev = DEVICE(obj); > > > + > > > + if (dev->realized) { > > > + (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, > > > + &local_err); > > > + } > > > + > > > + if (local_err) { > > > + qerror_report_err(local_err); > > > + error_free(local_err); > > > + return 1; > > > + } > > > + } > > > + > > > + object_child_foreach(obj, pc_existing_dimms_capacity, opaque); > > > + return 0; > > > +} >
diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 125cf0a..2ec45a4 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1552,30 +1552,6 @@ void qemu_register_pc_machine(QEMUMachine *m) g_free(name); } -static int pc_existing_dimms_capacity(Object *obj, void *opaque) -{ - Error *local_err = NULL; - uint64_t *size = opaque; - - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - DeviceState *dev = DEVICE(obj); - - if (dev->realized) { - (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, - &local_err); - } - - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); - return 1; - } - } - - object_child_foreach(obj, pc_existing_dimms_capacity, opaque); - return 0; -} - static void pc_dimm_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index d431834..f02ce6e 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -22,6 +22,31 @@ #include "qemu/config-file.h" #include "qapi/visitor.h" #include "qemu/range.h" +#include "qapi/qmp/qerror.h" + +int pc_existing_dimms_capacity(Object *obj, void *opaque) +{ + Error *local_err = NULL; + uint64_t *size = opaque; + + if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { + DeviceState *dev = DEVICE(obj); + + if (dev->realized) { + (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, + &local_err); + } + + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + return 1; + } + } + + object_child_foreach(obj, pc_existing_dimms_capacity, opaque); + return 0; +} int qmp_pc_dimm_device_list(Object *obj, void *opaque) { diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index e1dcbbc..bbfa53f 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -78,4 +78,5 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); int qmp_pc_dimm_device_list(Object *obj, void *opaque); +int pc_existing_dimms_capacity(Object *obj, void *opaque); #endif
Move pc_existing_dimms_capacity() to pc-dimm.c since it would be needed by PowerPC memory hotplug code too. Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> --- hw/i386/pc.c | 24 ------------------------ hw/mem/pc-dimm.c | 25 +++++++++++++++++++++++++ include/hw/mem/pc-dimm.h | 1 + 3 files changed, 26 insertions(+), 24 deletions(-)