virfile: Introduce and use virFileGetDefaultHugepage

This helper returns the default hugetlbfs mount point from given
array of mount points.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2019-03-29 16:10:09 +01:00
parent 59a22be864
commit 465df4771a
4 changed files with 33 additions and 8 deletions

View File

@ -1864,6 +1864,7 @@ virFileFindResourceFull;
virFileFlock;
virFileFreeACLs;
virFileGetACLs;
virFileGetDefaultHugepage;
virFileGetHugepageSize;
virFileGetMountReverseSubtree;
virFileGetMountSubtree;

View File

@ -1914,16 +1914,12 @@ qemuGetDomainDefaultHugepath(const virDomainDef *def,
virHugeTLBFSPtr hugetlbfs,
size_t nhugetlbfs)
{
size_t i;
virHugeTLBFSPtr p;
for (i = 0; i < nhugetlbfs; i++)
if (hugetlbfs[i].deflt)
break;
if (!(p = virFileGetDefaultHugepage(hugetlbfs, nhugetlbfs)))
p = &hugetlbfs[0];
if (i == nhugetlbfs)
i = 0;
return qemuGetDomainHugepagePath(def, &hugetlbfs[i]);
return qemuGetDomainHugepagePath(def, p);
}

View File

@ -3735,6 +3735,31 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs ATTRIBUTE_UNUSED,
}
#endif /* defined __linux__ */
/**
* virFileGetDefaultHugepage:
* @fs: array of hugetlbfs mount points
* @nfs: number of items in @fs
*
* In the passed array of hugetlbfs mount points @fs find the
* default one. It's the one which has no '-o pagesize'.
*
* Returns: default hugepage, or
* NULL if none found
*/
virHugeTLBFSPtr
virFileGetDefaultHugepage(virHugeTLBFSPtr fs,
size_t nfs)
{
size_t i;
for (i = 0; i < nfs; i++) {
if (fs[i].deflt)
return &fs[i];
}
return NULL;
}
int virFileIsSharedFS(const char *path)
{
return virFileIsSharedFSType(path,

View File

@ -334,6 +334,9 @@ int virFileGetHugepageSize(const char *path,
int virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
size_t *ret_nfs);
virHugeTLBFSPtr virFileGetDefaultHugepage(virHugeTLBFSPtr fs,
size_t nfs);
int virFileSetupDev(const char *path,
const char *mount_options);