render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 58dcefeeb3ab01e687d1d73b0219db68cc79b362 Mon Sep 17 00:00:00 2001
Message-Id: <58dcefeeb3ab01e687d1d73b0219db68cc79b362.1391615407.git.jdenemar@redhat.com>
From: John Ferlan <jferlan@redhat.com>
Date: Tue, 4 Feb 2014 13:34:55 -0500
Subject: [PATCH] Honor blacklist for modprobe command

https://bugzilla.redhat.com/show_bug.cgi?id=1045124

When loading modules, libvirt does not honor the modprobe blacklist.
Use the new virKModLoad() API in order to attempt load with blacklist check.
Use the new virKModIsBlacklisted() API to check if the failure to load
was due to the blacklist

Signed-off-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit 19259574d58d0cfaa95593b484508e50c5a24b43)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/util/virpci.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index f689961..3a21975 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -42,6 +42,7 @@
 #include "vircommand.h"
 #include "virerror.h"
 #include "virfile.h"
+#include "virkmod.h"
 #include "virstring.h"
 #include "virutil.h"
 
@@ -958,18 +959,32 @@ recheck:
     VIR_FREE(drvpath);
 
     if (!probed) {
-        const char *const probecmd[] = { MODPROBE, driver, NULL };
+        char *errbuf = NULL;
         probed = true;
-        if (virRun(probecmd, NULL) < 0) {
-            char ebuf[1024];
-            VIR_WARN("failed to load driver %s: %s", driver,
-                     virStrerror(errno, ebuf, sizeof(ebuf)));
-            return -1;
+        if ((errbuf = virKModLoad(driver, true))) {
+            VIR_WARN("failed to load driver %s: %s", driver, errbuf);
+            VIR_FREE(errbuf);
+            goto cleanup;
         }
 
         goto recheck;
     }
 
+cleanup:
+    /* If we know failure was because of blacklist, let's report that;
+     * otherwise, report a more generic failure message
+     */
+    if (virKModIsBlacklisted(driver)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to load PCI stub module %s: "
+                         "administratively prohibited"),
+                       driver);
+    } else {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to load PCI stub module %s"),
+                       driver);
+    }
+
     return -1;
 }
 
@@ -1271,12 +1286,8 @@ virPCIDeviceDetach(virPCIDevicePtr dev,
                    virPCIDeviceList *activeDevs,
                    virPCIDeviceList *inactiveDevs)
 {
-    if (virPCIProbeStubDriver(dev->stubDriver) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to load PCI stub module %s"),
-                       dev->stubDriver);
+    if (virPCIProbeStubDriver(dev->stubDriver) < 0)
         return -1;
-    }
 
     if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-- 
1.8.5.3