]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Initialize virResctrlInfo struct right away
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 8 Feb 2018 14:47:46 +0000 (15:47 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Fri, 8 Jun 2018 08:28:46 +0000 (10:28 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/capabilities.c
src/libvirt_private.syms
src/util/virresctrl.c
src/util/virresctrl.h

index d5f6f007300ad5465e870afa84ddb46ee0d29a7f..978edf871943efc2df33c61289f6e38e626692ce 100644 (file)
@@ -1604,7 +1604,7 @@ virCapabilitiesInitResctrl(virCapsPtr caps)
     if (!caps->host.resctrl)
         return -1;
 
-    return virResctrlGetInfo(caps->host.resctrl);
+    return 0;
 }
 
 
index 3a9680b3cd2b9fd983215ea10c1c9f3839fb1c66..3f54790297fba8104bd672b16177c6fb75fb3ce7 100644 (file)
@@ -2632,7 +2632,6 @@ virResctrlAllocNew;
 virResctrlAllocRemove;
 virResctrlAllocSetID;
 virResctrlAllocSetSize;
-virResctrlGetInfo;
 virResctrlInfoGetCache;
 virResctrlInfoNew;
 
index 13baa82be0ac7d1cae2b8b73e655ad84a78e9738..06a85d0d409841a35b84d146f6d02f645a45a692 100644 (file)
@@ -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;
 }
 
 
index cc648b521e8f90e855467667d902d5edba3e6dc5..a348fa7ab195a55462b7f80be76aedbb2a4cee1f 100644 (file)
@@ -55,9 +55,6 @@ typedef virResctrlInfo *virResctrlInfoPtr;
 virResctrlInfoPtr
 virResctrlInfoNew(void);
 
-int
-virResctrlGetInfo(virResctrlInfoPtr resctrl);
-
 int
 virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
                        unsigned int level,