util: Refactor code for adding PID to the resource group
The code of adding PID to the allocation could be reused, refactor it for later reuse. Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
0087378f67
commit
575a32f63f
@ -2390,26 +2390,21 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
virResctrlAllocAddPID(virResctrlAllocPtr alloc,
|
virResctrlAddPID(const char *path,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
char *tasks = NULL;
|
char *tasks = NULL;
|
||||||
char *pidstr = NULL;
|
char *pidstr = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* If the allocation is empty, then it is impossible to add a PID to
|
if (!path) {
|
||||||
* allocation due to lacking of its 'tasks' file so just return */
|
|
||||||
if (virResctrlAllocIsEmpty(alloc))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!alloc->path) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Cannot add pid to non-existing resctrl allocation"));
|
_("Cannot add pid to non-existing resctrl group"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&tasks, "%s/tasks", alloc->path) < 0)
|
if (virAsprintf(&tasks, "%s/tasks", path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virAsprintf(&pidstr, "%lld", (long long int) pid) < 0)
|
if (virAsprintf(&pidstr, "%lld", (long long int) pid) < 0)
|
||||||
@ -2430,6 +2425,19 @@ virResctrlAllocAddPID(virResctrlAllocPtr alloc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virResctrlAllocAddPID(virResctrlAllocPtr alloc,
|
||||||
|
pid_t pid)
|
||||||
|
{
|
||||||
|
/* If the allocation is empty, then it is impossible to add a PID to
|
||||||
|
* allocation due to lacking of its 'tasks' file so just return */
|
||||||
|
if (virResctrlAllocIsEmpty(alloc))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return virResctrlAddPID(alloc->path, pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virResctrlAllocRemove(virResctrlAllocPtr alloc)
|
virResctrlAllocRemove(virResctrlAllocPtr alloc)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user