提交 65bae2f1 编写于 作者: B Bing Niu 提交者: John Ferlan

util: Refactor virResctrlAllocFormat of virresctrl

Refactor virResctrlAllocFormat so that it is easy to support other
resource allocation technologies.
Signed-off-by: NBing Niu <bing.niu@intel.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 3a1356d4
...@@ -849,17 +849,14 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc) ...@@ -849,17 +849,14 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc)
} }
char * static int
virResctrlAllocFormat(virResctrlAllocPtr alloc) virResctrlAllocFormatCache(virResctrlAllocPtr alloc,
virBufferPtr buf)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned int level = 0; unsigned int level = 0;
unsigned int type = 0; unsigned int type = 0;
unsigned int cache = 0; unsigned int cache = 0;
if (!alloc)
return NULL;
for (level = 0; level < alloc->nlevels; level++) { for (level = 0; level < alloc->nlevels; level++) {
virResctrlAllocPerLevelPtr a_level = alloc->levels[level]; virResctrlAllocPerLevelPtr a_level = alloc->levels[level];
...@@ -872,7 +869,7 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) ...@@ -872,7 +869,7 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc)
if (!a_type) if (!a_type)
continue; continue;
virBufferAsprintf(&buf, "L%u%s:", level, virResctrlTypeToString(type)); virBufferAsprintf(buf, "L%u%s:", level, virResctrlTypeToString(type));
for (cache = 0; cache < a_type->nmasks; cache++) { for (cache = 0; cache < a_type->nmasks; cache++) {
virBitmapPtr mask = a_type->masks[cache]; virBitmapPtr mask = a_type->masks[cache];
...@@ -882,21 +879,35 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) ...@@ -882,21 +879,35 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc)
continue; continue;
mask_str = virBitmapToString(mask, false, true); mask_str = virBitmapToString(mask, false, true);
if (!mask_str) { if (!mask_str)
virBufferFreeAndReset(&buf); return -1;
return NULL;
}
virBufferAsprintf(&buf, "%u=%s;", cache, mask_str); virBufferAsprintf(buf, "%u=%s;", cache, mask_str);
VIR_FREE(mask_str); VIR_FREE(mask_str);
} }
virBufferTrim(&buf, ";", 1); virBufferTrim(buf, ";", 1);
virBufferAddChar(&buf, '\n'); virBufferAddChar(buf, '\n');
} }
} }
virBufferCheckError(&buf); return virBufferCheckError(buf);
}
char *
virResctrlAllocFormat(virResctrlAllocPtr alloc)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (!alloc)
return NULL;
if (virResctrlAllocFormatCache(alloc, &buf) < 0) {
virBufferFreeAndReset(&buf);
return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册