[PATCH 07/10] util: Initialize virResctrlInfo struct right away

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is no need to have virResctrlGetInfo() when it must be called after
virResctrlInfoNew() anyway, otherwise it's just an unusable object.  When we
wrap the logic inside the New() function we'll save some calls later as well.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/conf/capabilities.c  |  2 +-
 src/libvirt_private.syms |  1 -
 src/util/virresctrl.c    | 15 +++++++++++++--
 src/util/virresctrl.h    |  3 ---
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index d5f6f007300a..978edf871943 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1604,7 +1604,7 @@ virCapabilitiesInitResctrl(virCapsPtr caps)
     if (!caps->host.resctrl)
         return -1;
 
-    return virResctrlGetInfo(caps->host.resctrl);
+    return 0;
 }
 
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6a8b40bbbdb1..20ec8760ec27 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2633,7 +2633,6 @@ virResctrlAllocNew;
 virResctrlAllocRemove;
 virResctrlAllocSetID;
 virResctrlAllocSetSize;
-virResctrlGetInfo;
 virResctrlInfoGetCache;
 virResctrlInfoNew;
 
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 0266fee4e959..4e35b19649ca 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -314,7 +314,7 @@ virResctrlUnlock(int fd)
 
 
 /* virResctrlInfo-related definitions */
-int
+static int
 virResctrlGetInfo(virResctrlInfoPtr resctrl)
 {
     DIR *dirp = NULL;
@@ -448,10 +448,21 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
 virResctrlInfoPtr
 virResctrlInfoNew(void)
 {
+    virResctrlInfoPtr ret = NULL;
+
     if (virResctrlInitialize() < 0)
         return NULL;
 
-    return virObjectNew(virResctrlInfoClass);
+    ret = virObjectNew(virResctrlInfoClass);
+    if (!ret)
+        return NULL;
+
+    if (virResctrlGetInfo(ret) < 0) {
+        virObjectUnref(ret);
+        return NULL;
+    }
+
+    return ret;
 }
 
 
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index cc648b521e8f..a348fa7ab195 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -55,9 +55,6 @@ typedef virResctrlInfo *virResctrlInfoPtr;
 virResctrlInfoPtr
 virResctrlInfoNew(void);
 
-int
-virResctrlGetInfo(virResctrlInfoPtr resctrl);
-
 int
 virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
                        unsigned int level,
-- 
2.17.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux