Again, wrong indentation and unnecessary parentheses.
Otherwise it looks good, so ACK with those differences and reworded
commit message. Let me know if you agree and I can push it immediately.
The suggested diff follows:
diff --git i/docs/schemas/capability.rng w/docs/schemas/capability.rng
index 927fc184de41..e5cbfa362ec0 100644
--- i/docs/schemas/capability.rng
+++ w/docs/schemas/capability.rng
@@ -261,13 +261,7 @@
<attribute name='level'>
<ref name='unsignedInt'/>
</attribute>
- <attribute name='type'>
- <choice>
- <value>both</value>
- <value>code</value>
- <value>data</value>
- </choice>
- </attribute>
+ <ref name='cacheType'/>
<attribute name='size'>
<ref name='unsignedInt'/>
</attribute>
@@ -285,14 +279,8 @@
<attribute name='unit'>
<ref name='unit'/>
</attribute>
- <attribute name='scope'>
- <choice>
- <value>both</value>
- <value>code</value>
- <value>data</value>
- </choice>
- </attribute>
- <attribute name='max_allocation'>
+ <ref name='cacheType'/>
+ <attribute name='maxAllocs'>
<ref name='unsignedInt'/>
</attribute>
</element>
@@ -302,6 +290,16 @@
</element>
</define>
+ <define name='cacheType'>
+ <attribute name='type'>
+ <choice>
+ <value>both</value>
+ <value>code</value>
+ <value>data</value>
+ </choice>
+ </attribute>
+ </define>
+
<define name='guestcaps'>
<element name='guest'>
<ref name='ostype'/>
diff --git i/src/conf/capabilities.c w/src/conf/capabilities.c
index 8cd2957e9c88..3becc7e18c62 100644
--- i/src/conf/capabilities.c
+++ w/src/conf/capabilities.c
@@ -909,7 +909,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
bool min_kilos = !(bank->controls[j]->min % 1024);
virBufferAsprintf(&controlBuf,
"<control min='%llu' unit='%s' "
- "scope='%s' max_allocation='%u'/>\n",
+ "type='%s' maxAllocs='%u'/>\n",
bank->controls[j]->min >> (min_kilos * 10),
min_kilos ? "KiB" : "B",
virCacheTypeToString(bank->controls[j]->scope),
@@ -920,12 +920,10 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &controlBuf);
virBufferAddLit(buf, "</bank>\n");
-
} else {
virBufferAddLit(buf, "/>\n");
}
- virBufferFreeAndReset(&controlBuf);
VIR_FREE(cpus_str);
}
@@ -1557,16 +1555,19 @@ virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr)
VIR_FREE(ptr);
}
-/* test which TYPE of cache control supported
- * -1: don't support
- * 0: cat
- * 1: cdp
+/*
+ * This function tests which TYPE of cache control is supported
+ * Return values are:
+ * -1: not supported
+ * 0: CAT
+ * 1: CDP
*/
static int
virCapabilitiesGetCacheControlType(virCapsHostCacheBankPtr bank)
{
int ret = -1;
char *path = NULL;
+
if (virAsprintf(&path,
SYSFS_RESCTRL_PATH "/info/L%u",
bank->level) < 0)
@@ -1576,7 +1577,10 @@ virCapabilitiesGetCacheControlType(virCapsHostCacheBankPtr bank)
ret = 0;
} else {
VIR_FREE(path);
- /* for CDP enabled case, CODE and DATA will show together */
+ /*
+ * If CDP is enabled, there will be both CODE and DATA, but it's enough
+ * to check one of those only.
+ */
if (virAsprintf(&path,
SYSFS_RESCTRL_PATH "/info/L%uCODE",
bank->level) < 0)
@@ -1597,13 +1601,14 @@ virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank,
char *path = NULL;
char *cbm_mask = NULL;
char *type_upper = NULL;
+ unsigned int min_cbm_bits = 0;
virCapsHostCacheControlPtr control;
if (VIR_ALLOC(control) < 0)
goto cleanup;
- if ((scope > VIR_CACHE_TYPE_BOTH)
- && (virStringToUpper(&type_upper, virCacheTypeToString(scope)) < 0))
+ if (scope != VIR_CACHE_TYPE_BOTH &&
+ virStringToUpper(&type_upper, virCacheTypeToString(scope)) < 0)
goto cleanup;
if (virFileReadValueUint(&control->max_allocation,
@@ -1619,10 +1624,16 @@ virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank,
type_upper ? type_upper: "") < 0)
goto cleanup;
+ if (virFileReadValueUint(&min_cbm_bits,
+ SYSFS_RESCTRL_PATH "/info/L%u%s/min_cbm_bits",
+ bank->level,
+ type_upper ? type_upper : "") < 0)
+ goto cleanup;
+
virStringTrimOptionalNewline(cbm_mask);
/* cbm_mask: cache bit mask, it's in hex, eg: fffff */
- control->min = bank->size / (strlen(cbm_mask) * 4);
+ control->min = min_cbm_bits * bank->size / (strlen(cbm_mask) * 4);