[libvirt] [PATCH 04/10] util: Avoid needless preprocessor conditionals in virresctrl

Martin Kletzander posted 10 patches 6 years, 11 months ago
[libvirt] [PATCH 04/10] util: Avoid needless preprocessor conditionals in virresctrl
Posted by Martin Kletzander 6 years, 11 months ago
By exporting virResctrlAllocMasksAssign() we can remove most of the
conditionals.  And that function should be used from the tests later anyway.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virresctrl.c     | 30 +-----------------------------
 src/util/virresctrlpriv.h |  4 ++++
 3 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3a9680b3cd2b..6a8b40bbbdb1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2628,6 +2628,7 @@ virResctrlAllocForeachSize;
 virResctrlAllocFormat;
 virResctrlAllocGetID;
 virResctrlAllocGetUnused;
+virResctrlAllocMasksAssign;
 virResctrlAllocNew;
 virResctrlAllocRemove;
 virResctrlAllocSetID;
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 9a118fc3595d..787db31b6126 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -380,8 +380,6 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl)
 }
 
 
-#ifdef __linux__
-
 int
 virResctrlGetInfo(virResctrlInfoPtr resctrl)
 {
@@ -512,18 +510,6 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
     return ret;
 }
 
-#else /* ! __linux__ */
-
-int
-virResctrlGetInfo(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Cache tune not supported on this platform"));
-    return -1;
-}
-
-#endif /* ! __linux__ */
-
 
 int
 virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
@@ -1089,8 +1075,6 @@ virResctrlAllocGetDefault(virResctrlInfoPtr resctrl)
 }
 
 
-#ifdef __linux__
-
 static void
 virResctrlAllocSubtractPerType(virResctrlAllocPerTypePtr dst,
                                virResctrlAllocPerTypePtr src)
@@ -1246,18 +1230,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
     goto cleanup;
 }
 
-#else /* ! __linux__ */
-
-virResctrlAllocPtr
-virResctrlAllocGetUnused(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Cache tune not supported on this platform"));
-    return NULL;
-}
-
-#endif /* ! __linux__ */
-
 
 /*
  * Given the information about requested allocation type `a_type`, the host
@@ -1434,7 +1406,7 @@ virResctrlAllocCopyMasks(virResctrlAllocPtr dst,
  * then tries to find a proper space for every requested allocation effectively
  * transforming `sizes` into `masks`.
  */
-static int
+int
 virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
                            virResctrlAllocPtr alloc)
 {
diff --git a/src/util/virresctrlpriv.h b/src/util/virresctrlpriv.h
index 72b115afd13e..80ddd4b875a3 100644
--- a/src/util/virresctrlpriv.h
+++ b/src/util/virresctrlpriv.h
@@ -24,4 +24,8 @@
 virResctrlAllocPtr
 virResctrlAllocGetUnused(virResctrlInfoPtr resctrl);
 
+int
+virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
+                           virResctrlAllocPtr alloc);
+
 #endif /* __VIR_RESCTRL_PRIV_H__ */
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/10] util: Avoid needless preprocessor conditionals in virresctrl
Posted by Ján Tomko 6 years, 11 months ago
On Thu, Jun 07, 2018 at 03:54:25PM +0200, Martin Kletzander wrote:
>By exporting virResctrlAllocMasksAssign() we can remove most of the
>conditionals.  And that function should be used from the tests later anyway.
>

I fail to see the relevance of exporting virResctrlAllocMasksAssign in
this patch or series.

The conditionals removed here can be removed because the functions
do not contain Linux-specific code, the d_type access was removed by:
f2e16994f7d660a54daba1059441dc0dcf4d9cbd
    util: Don't check if entries under /sys/fs/resctrl/(info/) are directories


>Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
>---
> src/libvirt_private.syms  |  1 +
> src/util/virresctrl.c     | 30 +-----------------------------
> src/util/virresctrlpriv.h |  4 ++++
> 3 files changed, 6 insertions(+), 29 deletions(-)
>

If you drop the virResctrlAllocMasksAssign-related hunks:

Reviewed-by: Ján Tomko <jtomko@redhat.com>

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