VIR_DEBUG("Opening IOMMU FD for domain %s", vm->def->name);
- if ((fd = open(VIR_IOMMU_DEV_PATH, O_RDWR | O_CLOEXEC)) < 0) {
- virReportSystemError(errno, "%s", _("cannot open /dev/iommu"));
+ if ((fd = virIOMMUFDOpenDevice()) < 0)
return -1;
- }
-
- if (virIOMMUFDSetRLimitMode(fd, true) < 0) {
- VIR_FORCE_CLOSE(fd);
- return -1;
- }
VIR_DEBUG("Opened IOMMU FD %d for domain %s", fd, vm->def->name);
return fd;
#include <config.h>
+#include <fcntl.h>
+
#include "viriommufd.h"
#include "virlog.h"
#include "virerror.h"
*
* Returns: 0 on success, -1 on error
*/
-int
+static int
virIOMMUFDSetRLimitMode(int fd, bool processAccounting)
{
struct iommu_option option = {
return 0;
}
+int
+virIOMMUFDOpenDevice(void)
+{
+ int fd = -1;
+
+ if ((fd = open(VIR_IOMMU_DEV_PATH, O_RDWR | O_CLOEXEC)) < 0)
+ virReportSystemError(errno, "%s", _("cannot open IOMMUFD device"));
+
+ if (virIOMMUFDSetRLimitMode(fd, true) < 0)
+ return -1;
+
+ return fd;
+}
+
#else
-int virIOMMUFDSetRLimitMode(int fd G_GNUC_UNUSED,
- bool processAccounting G_GNUC_UNUSED)
+int
+virIOMMUFDOpenDevice(void)
{
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("IOMMUFD is not supported on this platform"));
#define VIR_IOMMU_DEV_PATH "/dev/iommu"
-int virIOMMUFDSetRLimitMode(int fd, bool processAccounting);
+int virIOMMUFDOpenDevice(void);
bool virIOMMUFDSupported(void);