diff mbox

[v6,13/33] pc-dimm: make pc_existing_dimms_capacity static and rename it

Message ID 1446184587-142784-14-git-send-email-guangrong.xiao@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xiao Guangrong Oct. 30, 2015, 5:56 a.m. UTC
pc_existing_dimms_capacity() can be static since it is not used out of
pc-dimm.c and drop the pc_ prefix to prepare the work which abstracts
dimm device type from pc-dimm

Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
 hw/mem/pc-dimm.c         | 73 ++++++++++++++++++++++++------------------------
 include/hw/mem/pc-dimm.h |  1 -
 2 files changed, 36 insertions(+), 38 deletions(-)

Comments

Vladimir Sementsov-Ogievskiy Oct. 30, 2015, 3:38 p.m. UTC | #1
On 30.10.2015 08:56, Xiao Guangrong wrote:
> pc_existing_dimms_capacity() can be static since it is not used out of
> pc-dimm.c and drop the pc_ prefix to prepare the work which abstracts
> dimm device type from pc-dimm
>
> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> ---
>   hw/mem/pc-dimm.c         | 73 ++++++++++++++++++++++++------------------------
>   include/hw/mem/pc-dimm.h |  1 -
>   2 files changed, 36 insertions(+), 38 deletions(-)
>
> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index 80f424b..2dcbbcd 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -32,6 +32,38 @@ typedef struct pc_dimms_capacity {
>        Error    **errp;
>   } pc_dimms_capacity;
>   
> +static int existing_dimms_capacity_internal(Object *obj, void *opaque)
> +{
> +    pc_dimms_capacity *cap = opaque;
> +    uint64_t *size = &cap->size;
> +
> +    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,
> +                cap->errp);
> +        }
> +
> +        if (cap->errp && *cap->errp) {
> +            return 1;
> +        }
> +    }
> +    object_child_foreach(obj, existing_dimms_capacity_internal, opaque);
> +    return 0;
> +}
> +
> +static uint64_t existing_dimms_capacity(Error **errp)
> +{
> +    pc_dimms_capacity cap;
> +
> +    cap.size = 0;
> +    cap.errp = errp;
> +
> +    existing_dimms_capacity_internal(qdev_get_machine(), &cap);
> +    return cap.size;
> +}
> +
>   void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
>                            MemoryRegion *mr, uint64_t align, Error **errp)
>   {
> @@ -39,7 +71,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
>       MachineState *machine = MACHINE(qdev_get_machine());
>       PCDIMMDevice *dimm = PC_DIMM(dev);
>       Error *local_err = NULL;
> -    uint64_t existing_dimms_capacity = 0;
> +    uint64_t dimms_capacity = 0;
>       uint64_t addr;
>   
>       addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &local_err);
> @@ -55,17 +87,16 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
>           goto out;
>       }
>   
> -    existing_dimms_capacity = pc_existing_dimms_capacity(&local_err);
> +    dimms_capacity = existing_dimms_capacity(&local_err);
>       if (local_err) {
>           goto out;
>       }
>   
> -    if (existing_dimms_capacity + memory_region_size(mr) >
> +    if (dimms_capacity + memory_region_size(mr) >
>           machine->maxram_size - machine->ram_size) {
>           error_setg(&local_err, "not enough space, currently 0x%" PRIx64
>                      " in use of total hot pluggable 0x" RAM_ADDR_FMT,
> -                   existing_dimms_capacity,
> -                   machine->maxram_size - machine->ram_size);
> +                   dimms_capacity, machine->maxram_size - machine->ram_size);
>           goto out;
>       }
>   
> @@ -120,38 +151,6 @@ void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,
>       vmstate_unregister_ram(mr, dev);
>   }
>   
> -static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque)
> -{
> -    pc_dimms_capacity *cap = opaque;
> -    uint64_t *size = &cap->size;
> -
> -    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,
> -                cap->errp);
> -        }
> -
> -        if (cap->errp && *cap->errp) {
> -            return 1;
> -        }
> -    }
> -    object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque);
> -    return 0;
> -}
> -
> -uint64_t pc_existing_dimms_capacity(Error **errp)
> -{
> -    pc_dimms_capacity cap;
> -
> -    cap.size = 0;
> -    cap.errp = errp;
> -
> -    pc_existing_dimms_capacity_internal(qdev_get_machine(), &cap);
> -    return cap.size;
> -}
> -
>   int qmp_pc_dimm_device_list(Object *obj, void *opaque)
>   {
>       MemoryDeviceInfoList ***prev = opaque;
> diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
> index 11a8937..8a43548 100644
> --- a/include/hw/mem/pc-dimm.h
> +++ b/include/hw/mem/pc-dimm.h
> @@ -87,7 +87,6 @@ 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);
> -uint64_t pc_existing_dimms_capacity(Error **errp);
>   void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
>                            MemoryRegion *mr, uint64_t align, Error **errp);
>   void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
diff mbox

Patch

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 80f424b..2dcbbcd 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -32,6 +32,38 @@  typedef struct pc_dimms_capacity {
      Error    **errp;
 } pc_dimms_capacity;
 
+static int existing_dimms_capacity_internal(Object *obj, void *opaque)
+{
+    pc_dimms_capacity *cap = opaque;
+    uint64_t *size = &cap->size;
+
+    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,
+                cap->errp);
+        }
+
+        if (cap->errp && *cap->errp) {
+            return 1;
+        }
+    }
+    object_child_foreach(obj, existing_dimms_capacity_internal, opaque);
+    return 0;
+}
+
+static uint64_t existing_dimms_capacity(Error **errp)
+{
+    pc_dimms_capacity cap;
+
+    cap.size = 0;
+    cap.errp = errp;
+
+    existing_dimms_capacity_internal(qdev_get_machine(), &cap);
+    return cap.size;
+}
+
 void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
                          MemoryRegion *mr, uint64_t align, Error **errp)
 {
@@ -39,7 +71,7 @@  void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
     MachineState *machine = MACHINE(qdev_get_machine());
     PCDIMMDevice *dimm = PC_DIMM(dev);
     Error *local_err = NULL;
-    uint64_t existing_dimms_capacity = 0;
+    uint64_t dimms_capacity = 0;
     uint64_t addr;
 
     addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &local_err);
@@ -55,17 +87,16 @@  void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
         goto out;
     }
 
-    existing_dimms_capacity = pc_existing_dimms_capacity(&local_err);
+    dimms_capacity = existing_dimms_capacity(&local_err);
     if (local_err) {
         goto out;
     }
 
-    if (existing_dimms_capacity + memory_region_size(mr) >
+    if (dimms_capacity + memory_region_size(mr) >
         machine->maxram_size - machine->ram_size) {
         error_setg(&local_err, "not enough space, currently 0x%" PRIx64
                    " in use of total hot pluggable 0x" RAM_ADDR_FMT,
-                   existing_dimms_capacity,
-                   machine->maxram_size - machine->ram_size);
+                   dimms_capacity, machine->maxram_size - machine->ram_size);
         goto out;
     }
 
@@ -120,38 +151,6 @@  void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,
     vmstate_unregister_ram(mr, dev);
 }
 
-static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque)
-{
-    pc_dimms_capacity *cap = opaque;
-    uint64_t *size = &cap->size;
-
-    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,
-                cap->errp);
-        }
-
-        if (cap->errp && *cap->errp) {
-            return 1;
-        }
-    }
-    object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque);
-    return 0;
-}
-
-uint64_t pc_existing_dimms_capacity(Error **errp)
-{
-    pc_dimms_capacity cap;
-
-    cap.size = 0;
-    cap.errp = errp;
-
-    pc_existing_dimms_capacity_internal(qdev_get_machine(), &cap);
-    return cap.size;
-}
-
 int qmp_pc_dimm_device_list(Object *obj, void *opaque)
 {
     MemoryDeviceInfoList ***prev = opaque;
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 11a8937..8a43548 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -87,7 +87,6 @@  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);
-uint64_t pc_existing_dimms_capacity(Error **errp);
 void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
                          MemoryRegion *mr, uint64_t align, Error **errp);
 void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,