This helper returns the default hugetlbfs mount point from given
array of mount points.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_conf.c | 12 ++++--------
src/util/virfile.c | 25 +++++++++++++++++++++++++
src/util/virfile.h | 3 +++
4 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 73ef24d66f..d372997605 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1862,6 +1862,7 @@ virFileFindResourceFull;
virFileFlock;
virFileFreeACLs;
virFileGetACLs;
+virFileGetDefaultHugepage;
virFileGetHugepageSize;
virFileGetMountReverseSubtree;
virFileGetMountSubtree;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 42122dcd97..41ce0a978d 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -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);
}
diff --git a/src/util/virfile.c b/src/util/virfile.c
index ec8d85929c..9f1a965acb 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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,
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 3dedb7666a..df35a32bcc 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -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);
--
2.21.0