util: Extract path formatting into virResctrlAllocDeterminePath

We can use this from more places later, so just a future code de-duplication.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2018-01-30 23:57:42 +01:00
parent 272649a1d7
commit b9ceacba7c
3 changed files with 25 additions and 9 deletions

View File

@ -2560,6 +2560,7 @@ virCacheTypeFromString;
virCacheTypeToString;
virResctrlAllocAddPID;
virResctrlAllocCreate;
virResctrlAllocDeterminePath;
virResctrlAllocForeachSize;
virResctrlAllocFormat;
virResctrlAllocGetID;

View File

@ -1501,6 +1501,25 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
}
int
virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
const char *machinename)
{
if (!alloc->id) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Resctrl Allocation ID must be set before creation"));
return -1;
}
if (!alloc->path &&
virAsprintf(&alloc->path, "%s/%s-%s",
SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0)
return -1;
return 0;
}
/* This checks if the directory for the alloc exists. If not it tries to create
* it and apply appropriate alloc settings. */
int
@ -1522,15 +1541,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
return -1;
}
if (!alloc->id) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Resctrl Allocation ID must be set before creation"));
return -1;
}
if (!alloc->path &&
virAsprintf(&alloc->path, "%s/%s-%s",
SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0)
if (virResctrlAllocDeterminePath(alloc, machinename) < 0)
return -1;
if (virFileExists(alloc->path)) {

View File

@ -102,6 +102,10 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc);
char *
virResctrlAllocFormat(virResctrlAllocPtr alloc);
int
virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
const char *machinename);
int
virResctrlAllocCreate(virResctrlInfoPtr r_info,
virResctrlAllocPtr alloc,