From 03b6383f33a8d4638ced6fbb6212812314b53a01 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Wed, 11 Sep 2024 15:08:28 +0200 Subject: [PATCH] resctrl: Move virResctrlAllocCopyMemBW up in the file This way it can be used later in virResctrlAllocGetUnused(). Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/util/virresctrl.c | 63 ++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index e0a7a3e127..000191c5d4 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1798,6 +1798,38 @@ virResctrlAllocNewFromInfo(virResctrlInfo *info) return g_steal_pointer(&ret); } + +static int +virResctrlAllocCopyMemBW(virResctrlAlloc *dst, + virResctrlAlloc *src) +{ + size_t i = 0; + virResctrlAllocMemBW *dst_bw = NULL; + virResctrlAllocMemBW *src_bw = src->mem_bw; + + if (!src->mem_bw) + return 0; + + if (!dst->mem_bw) + dst->mem_bw = g_new0(virResctrlAllocMemBW, 1); + + dst_bw = dst->mem_bw; + + if (src_bw->nbandwidths > dst_bw->nbandwidths) + VIR_EXPAND_N(dst_bw->bandwidths, dst_bw->nbandwidths, + src_bw->nbandwidths - dst_bw->nbandwidths); + + for (i = 0; i < src_bw->nbandwidths; i++) { + if (dst_bw->bandwidths[i]) + continue; + dst_bw->bandwidths[i] = g_new0(unsigned int, 1); + *dst_bw->bandwidths[i] = *src_bw->bandwidths[i]; + } + + return 0; +} + + /* * This function creates an allocation that represents all unused parts of all * caches in the system. It uses virResctrlInfo for creating a new full @@ -2031,37 +2063,6 @@ virResctrlAllocMemoryBandwidth(virResctrlInfo *resctrl, } -static int -virResctrlAllocCopyMemBW(virResctrlAlloc *dst, - virResctrlAlloc *src) -{ - size_t i = 0; - virResctrlAllocMemBW *dst_bw = NULL; - virResctrlAllocMemBW *src_bw = src->mem_bw; - - if (!src->mem_bw) - return 0; - - if (!dst->mem_bw) - dst->mem_bw = g_new0(virResctrlAllocMemBW, 1); - - dst_bw = dst->mem_bw; - - if (src_bw->nbandwidths > dst_bw->nbandwidths) - VIR_EXPAND_N(dst_bw->bandwidths, dst_bw->nbandwidths, - src_bw->nbandwidths - dst_bw->nbandwidths); - - for (i = 0; i < src_bw->nbandwidths; i++) { - if (dst_bw->bandwidths[i]) - continue; - dst_bw->bandwidths[i] = g_new0(unsigned int, 1); - *dst_bw->bandwidths[i] = *src_bw->bandwidths[i]; - } - - return 0; -} - - static int virResctrlAllocCopyMasks(virResctrlAlloc *dst, virResctrlAlloc *src)