提交 b9ceacba 编写于 作者: M Martin Kletzander

util: Extract path formatting into virResctrlAllocDeterminePath

We can use this from more places later, so just a future code de-duplication.
Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 272649a1
...@@ -2560,6 +2560,7 @@ virCacheTypeFromString; ...@@ -2560,6 +2560,7 @@ virCacheTypeFromString;
virCacheTypeToString; virCacheTypeToString;
virResctrlAllocAddPID; virResctrlAllocAddPID;
virResctrlAllocCreate; virResctrlAllocCreate;
virResctrlAllocDeterminePath;
virResctrlAllocForeachSize; virResctrlAllocForeachSize;
virResctrlAllocFormat; virResctrlAllocFormat;
virResctrlAllocGetID; virResctrlAllocGetID;
......
...@@ -1501,6 +1501,25 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, ...@@ -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 /* This checks if the directory for the alloc exists. If not it tries to create
* it and apply appropriate alloc settings. */ * it and apply appropriate alloc settings. */
int int
...@@ -1522,15 +1541,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, ...@@ -1522,15 +1541,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
return -1; return -1;
} }
if (!alloc->id) { if (virResctrlAllocDeterminePath(alloc, machinename) < 0)
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 -1;
if (virFileExists(alloc->path)) { if (virFileExists(alloc->path)) {
......
...@@ -102,6 +102,10 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc); ...@@ -102,6 +102,10 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc);
char * char *
virResctrlAllocFormat(virResctrlAllocPtr alloc); virResctrlAllocFormat(virResctrlAllocPtr alloc);
int
virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
const char *machinename);
int int
virResctrlAllocCreate(virResctrlInfoPtr r_info, virResctrlAllocCreate(virResctrlInfoPtr r_info,
virResctrlAllocPtr alloc, virResctrlAllocPtr alloc,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册