From: Wang Huaqiang Date: Mon, 12 Nov 2018 13:31:40 +0000 (+0800) Subject: util: Refactor virResctrlAllocSetID to set allocation ID X-Git-Tag: v4.10.0-rc1~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e54c4b289d08bdc9f33978c200567217b87d81b;p=thirdparty%2Flibvirt.git 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 Reviewed-by: John Ferlan --- diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 3a8b6e2cf0..90eda726f8 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1361,17 +1361,32 @@ virResctrlAllocForeachMemory(virResctrlAllocPtr alloc, } -int -virResctrlAllocSetID(virResctrlAllocPtr alloc, - const char *id) +static int +virResctrlSetID(char **resctrlid, + const char *id) { if (!id) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Resctrl allocation 'id' cannot be NULL")); + _("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(alloc->id, id); + return VIR_STRDUP(*resctrlid, id); +} + + +int +virResctrlAllocSetID(virResctrlAllocPtr alloc, + const char *id) +{ + return virResctrlSetID(&alloc->id, id); }