[libvirt] [PATCHv2 07/11] util: Refactor and rename 'virResctrlMonitorFreeStats'

Wang Huaqiang posted 11 patches 17 weeks ago

[libvirt] [PATCHv2 07/11] util: Refactor and rename 'virResctrlMonitorFreeStats'

Posted by Wang Huaqiang 17 weeks ago
Refactor and rename 'virResctrlMonitorFreeStats' to
'virResctrlMonitorStatsFree' to free one
'virResctrlMonitorStatsPtr' object.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
---
 src/libvirt_private.syms |  2 +-
 src/qemu/qemu_driver.c   |  6 +++++-
 src/util/virresctrl.c    | 14 ++++----------
 src/util/virresctrl.h    |  4 ++--
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b95f958..1d949b3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2769,13 +2769,13 @@ virResctrlInfoNew;
 virResctrlMonitorAddPID;
 virResctrlMonitorCreate;
 virResctrlMonitorDeterminePath;
-virResctrlMonitorFreeStats;
 virResctrlMonitorGetCacheOccupancy;
 virResctrlMonitorGetID;
 virResctrlMonitorNew;
 virResctrlMonitorRemove;
 virResctrlMonitorSetAlloc;
 virResctrlMonitorSetID;
+virResctrlMonitorStatsFree;
 
 
 # util/virrotatingfile.h
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 42b1ce2..85fbe21 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19977,9 +19977,13 @@ struct _virQEMUResctrlMonData {
 static void
 qemuDomainFreeResctrlMonData(virQEMUResctrlMonDataPtr resdata)
 {
+    size_t i = 0;
+
     VIR_FREE(resdata->name);
     VIR_FREE(resdata->vcpus);
-    virResctrlMonitorFreeStats(resdata->stats, resdata->nstats);
+    for (i = 0; i < resdata->nstats; i++)
+        virResctrlMonitorStatsFree(resdata->stats[i]);
+    VIR_FREE(resdata->stats);
     VIR_FREE(resdata);
 }
 
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index fb66ea3..af0e5c0 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -2765,25 +2765,19 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
  cleanup:
     VIR_FREE(datapath);
     VIR_FREE(filepath);
-    VIR_FREE(stat);
+    virResctrlMonitorStatsFree(stat);
     VIR_DIR_CLOSE(dirp);
     return ret;
 }
 
 
 void
-virResctrlMonitorFreeStats(virResctrlMonitorStatsPtr *stats,
-                           size_t nstats)
+virResctrlMonitorStatsFree(virResctrlMonitorStatsPtr stat)
 {
-    size_t i = 0;
-
-    if (!stats)
+    if (!stat)
         return;
 
-    for (i = 0; i < nstats; i++)
-        VIR_FREE(stats[i]);
-
-    VIR_FREE(stats);
+    VIR_FREE(stat);
 }
 
 
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index abdeb59..d46e533 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -233,6 +233,6 @@ virResctrlMonitorGetCacheOccupancy(virResctrlMonitorPtr monitor,
                                    size_t *nstats);
 
 void
-virResctrlMonitorFreeStats(virResctrlMonitorStatsPtr *stats,
-                           size_t nstats);
+virResctrlMonitorStatsFree(virResctrlMonitorStatsPtr stats);
+
 #endif /* LIBVIRT_VIRRESCTRL_H */
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list