util: Refactor virResctrlAllocSetID to set allocation ID
Refactor virResctrlAllocSetID generating an error if an attempt is made to overwrite the existing value. Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
2f22364688
commit
4e54c4b289
@ -1361,17 +1361,32 @@ virResctrlAllocForeachMemory(virResctrlAllocPtr alloc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
virResctrlSetID(char **resctrlid,
|
||||||
|
const char *id)
|
||||||
|
{
|
||||||
|
if (!id) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("New resctrl 'id' cannot be NULL"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*resctrlid) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Attempt to overwrite resctrlid='%s' with id='%s'"),
|
||||||
|
*resctrlid, id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VIR_STRDUP(*resctrlid, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virResctrlAllocSetID(virResctrlAllocPtr alloc,
|
virResctrlAllocSetID(virResctrlAllocPtr alloc,
|
||||||
const char *id)
|
const char *id)
|
||||||
{
|
{
|
||||||
if (!id) {
|
return virResctrlSetID(&alloc->id, id);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Resctrl allocation 'id' cannot be NULL"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return VIR_STRDUP(alloc->id, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user