Signed-off-by: Filip Alac <filipalac@gmail.com>
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_hostdev.c | 29 ++++-------------------------
src/util/virutil.c | 28 ++++++++++++++++++++++++++++
src/util/virutil.h | 2 ++
4 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6001635916..dacaf9d94b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3073,6 +3073,7 @@ virGetUserName;
virGetUserRuntimeDirectory;
virGetUserShell;
virHexToBin;
+virHostHasIOMMU;
virIndexToDiskName;
virIsDevMapperDevice;
virIsSUID;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 955b5df1a3..25e2dcf868 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -23,7 +23,6 @@
#include <config.h>
-#include <dirent.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
@@ -124,33 +123,13 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver,
bool
qemuHostdevHostSupportsPassthroughVFIO(void)
{
- DIR *iommuDir = NULL;
- struct dirent *iommuGroup = NULL;
- bool ret = false;
- int direrr;
-
- /* condition 1 - /sys/kernel/iommu_groups/ contains entries */
- if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
- goto cleanup;
-
- while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) {
- /* assume we found a group */
- break;
- }
-
- if (direrr < 0 || !iommuGroup)
- goto cleanup;
- /* okay, iommu is on and recognizes groups */
+ if (!virHostHasIOMMU())
+ return false;
- /* condition 2 - /dev/vfio/vfio exists */
if (!virFileExists("/dev/vfio/vfio"))
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- VIR_DIR_CLOSE(iommuDir);
- return ret;
+ return true;
}
diff --git a/src/util/virutil.c b/src/util/virutil.c
index bb4474acd5..7edcda0ee7 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -2090,3 +2090,31 @@ virMemoryMaxValue(bool capped)
else
return LLONG_MAX;
}
+
+bool
+virHostHasIOMMU(void)
+{
+ DIR *iommuDir = NULL;
+ struct dirent *iommuGroup = NULL;
+ bool ret = false;
+ int direrr;
+
+ /* condition 1 - /sys/kernel/iommu_groups/ contains entries */
+ if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
+ goto cleanup;
+
+ while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) {
+ /* assume we found a group */
+ break;
+ }
+
+ if (direrr < 0 || !iommuGroup)
+ goto cleanup;
+ /* okay, iommu is on and recognizes groups */
+
+ ret = true;
+
+ cleanup:
+ VIR_DIR_CLOSE(iommuDir);
+ return ret;
+}
diff --git a/src/util/virutil.h b/src/util/virutil.h
index be0f6b0ea8..1ba9635bd9 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long long value);
bool virMemoryLimitIsSet(unsigned long long value);
unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE;
+bool virHostHasIOMMU(void);
+
/**
* VIR_ASSIGN_IS_OVERFLOW:
* @rvalue: value that is checked (evaluated twice)
--
2.17.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On 06/01/2018 10:15 AM, Filip Alac wrote: > Signed-off-by: Filip Alac <filipalac@gmail.com> > --- > src/libvirt_private.syms | 1 + > src/qemu/qemu_hostdev.c | 29 ++++------------------------- > src/util/virutil.c | 28 ++++++++++++++++++++++++++++ > src/util/virutil.h | 2 ++ > 4 files changed, 35 insertions(+), 25 deletions(-) > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > index 6001635916..dacaf9d94b 100644 > --- a/src/libvirt_private.syms > +++ b/src/libvirt_private.syms > @@ -3073,6 +3073,7 @@ virGetUserName; > virGetUserRuntimeDirectory; > virGetUserShell; > virHexToBin; > +virHostHasIOMMU; > virIndexToDiskName; > virIsDevMapperDevice; > virIsSUID; > diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c > index 955b5df1a3..25e2dcf868 100644 > --- a/src/qemu/qemu_hostdev.c > +++ b/src/qemu/qemu_hostdev.c > @@ -23,7 +23,6 @@ > > #include <config.h> > > -#include <dirent.h> > #include <fcntl.h> > #include <sys/ioctl.h> > #include <errno.h> > @@ -124,33 +123,13 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, > bool > qemuHostdevHostSupportsPassthroughVFIO(void) > { > - DIR *iommuDir = NULL; > - struct dirent *iommuGroup = NULL; > - bool ret = false; > - int direrr; > - > - /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ Thos comment should stay in here. I mean, whether host supports VFIO passthrough depends on two conditions. Removing comments that say does not increase code readability. > - if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) > - goto cleanup; > - > - while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { > - /* assume we found a group */ > - break; > - } > - > - if (direrr < 0 || !iommuGroup) > - goto cleanup; > - /* okay, iommu is on and recognizes groups */ > + if (!virHostHasIOMMU()) > + return false; > > - /* condition 2 - /dev/vfio/vfio exists */ > if (!virFileExists("/dev/vfio/vfio")) > - goto cleanup; > - > - ret = true; > + return false; > > - cleanup: > - VIR_DIR_CLOSE(iommuDir); > - return ret; > + return true; > } > > > diff --git a/src/util/virutil.c b/src/util/virutil.c > index bb4474acd5..7edcda0ee7 100644 > --- a/src/util/virutil.c > +++ b/src/util/virutil.c > @@ -2090,3 +2090,31 @@ virMemoryMaxValue(bool capped) > else > return LLONG_MAX; > } > + See how other functions are separated by two empty lines? Might be worth to honour the consistency. > +bool > +virHostHasIOMMU(void) > +{ > + DIR *iommuDir = NULL; > + struct dirent *iommuGroup = NULL; > + bool ret = false; > + int direrr; > + > + /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ Huh, this comment does not belong here. It doesn't make much sense here. You need to keep it in the original function. > + if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) > + goto cleanup; > + > + while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { > + /* assume we found a group */ > + break; > + } > + > + if (direrr < 0 || !iommuGroup) > + goto cleanup; > + /* okay, iommu is on and recognizes groups */ > + > + ret = true; > + > + cleanup: > + VIR_DIR_CLOSE(iommuDir); > + return ret; > +} > diff --git a/src/util/virutil.h b/src/util/virutil.h > index be0f6b0ea8..1ba9635bd9 100644 > --- a/src/util/virutil.h > +++ b/src/util/virutil.h > @@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long long value); > bool virMemoryLimitIsSet(unsigned long long value); > unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE; > > +bool virHostHasIOMMU(void); > + > /** > * VIR_ASSIGN_IS_OVERFLOW: > * @rvalue: value that is checked (evaluated twice) > Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On 06/01/2018 04:15 AM, Filip Alac wrote: > Signed-off-by: Filip Alac <filipalac@gmail.com> > --- > src/libvirt_private.syms | 1 + > src/qemu/qemu_hostdev.c | 29 ++++------------------------- > src/util/virutil.c | 28 ++++++++++++++++++++++++++++ > src/util/virutil.h | 2 ++ > 4 files changed, 35 insertions(+), 25 deletions(-) > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > index 6001635916..dacaf9d94b 100644 > --- a/src/libvirt_private.syms > +++ b/src/libvirt_private.syms > @@ -3073,6 +3073,7 @@ virGetUserName; > virGetUserRuntimeDirectory; > virGetUserShell; > virHexToBin; > +virHostHasIOMMU; > virIndexToDiskName; > virIsDevMapperDevice; > virIsSUID; > diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c > index 955b5df1a3..25e2dcf868 100644 > --- a/src/qemu/qemu_hostdev.c > +++ b/src/qemu/qemu_hostdev.c > @@ -23,7 +23,6 @@ > > #include <config.h> > > -#include <dirent.h> > #include <fcntl.h> > #include <sys/ioctl.h> > #include <errno.h> > @@ -124,33 +123,13 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, > bool > qemuHostdevHostSupportsPassthroughVFIO(void) > { > - DIR *iommuDir = NULL; > - struct dirent *iommuGroup = NULL; > - bool ret = false; > - int direrr; > - > - /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ > - if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) > - goto cleanup; > - > - while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { > - /* assume we found a group */ > - break; > - } > - > - if (direrr < 0 || !iommuGroup) > - goto cleanup; > - /* okay, iommu is on and recognizes groups */ > + if (!virHostHasIOMMU()) > + return false; > > - /* condition 2 - /dev/vfio/vfio exists */ > if (!virFileExists("/dev/vfio/vfio")) > - goto cleanup; > - > - ret = true; > + return false; > > - cleanup: > - VIR_DIR_CLOSE(iommuDir); > - return ret; > + return true; > } > > > diff --git a/src/util/virutil.c b/src/util/virutil.c > index bb4474acd5..7edcda0ee7 100644 > --- a/src/util/virutil.c > +++ b/src/util/virutil.c > @@ -2090,3 +2090,31 @@ virMemoryMaxValue(bool capped) > else > return LLONG_MAX; > } > + > +bool > +virHostHasIOMMU(void) > +{ > + DIR *iommuDir = NULL; > + struct dirent *iommuGroup = NULL; > + bool ret = false; > + int direrr; > + > + /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ remove the '1' since there's no '2' anymore? > + if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) > + goto cleanup; > + > + while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { > + /* assume we found a group */ > + break; > + } > + > + if (direrr < 0 || !iommuGroup) > + goto cleanup; > + /* okay, iommu is on and recognizes groups */ > + > + ret = true; > + > + cleanup: > + VIR_DIR_CLOSE(iommuDir); > + return ret; > +} > diff --git a/src/util/virutil.h b/src/util/virutil.h > index be0f6b0ea8..1ba9635bd9 100644 > --- a/src/util/virutil.h > +++ b/src/util/virutil.h > @@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long long value); > bool virMemoryLimitIsSet(unsigned long long value); > unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE; > > +bool virHostHasIOMMU(void); > + > /** > * VIR_ASSIGN_IS_OVERFLOW: > * @rvalue: value that is checked (evaluated twice) Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.