render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From 58dcefeeb3ab01e687d1d73b0219db68cc79b362 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <58dcefeeb3ab01e687d1d73b0219db68cc79b362.1391615407.git.jdenemar@redhat.com>
c401cc
From: John Ferlan <jferlan@redhat.com>
c401cc
Date: Tue, 4 Feb 2014 13:34:55 -0500
c401cc
Subject: [PATCH] Honor blacklist for modprobe command
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1045124
c401cc
c401cc
When loading modules, libvirt does not honor the modprobe blacklist.
c401cc
Use the new virKModLoad() API in order to attempt load with blacklist check.
c401cc
Use the new virKModIsBlacklisted() API to check if the failure to load
c401cc
was due to the blacklist
c401cc
c401cc
Signed-off-by: John Ferlan <jferlan@redhat.com>
c401cc
(cherry picked from commit 19259574d58d0cfaa95593b484508e50c5a24b43)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/util/virpci.c | 33 ++++++++++++++++++++++-----------
c401cc
 1 file changed, 22 insertions(+), 11 deletions(-)
c401cc
c401cc
diff --git a/src/util/virpci.c b/src/util/virpci.c
c401cc
index f689961..3a21975 100644
c401cc
--- a/src/util/virpci.c
c401cc
+++ b/src/util/virpci.c
c401cc
@@ -42,6 +42,7 @@
c401cc
 #include "vircommand.h"
c401cc
 #include "virerror.h"
c401cc
 #include "virfile.h"
c401cc
+#include "virkmod.h"
c401cc
 #include "virstring.h"
c401cc
 #include "virutil.h"
c401cc
 
c401cc
@@ -958,18 +959,32 @@ recheck:
c401cc
     VIR_FREE(drvpath);
c401cc
 
c401cc
     if (!probed) {
c401cc
-        const char *const probecmd[] = { MODPROBE, driver, NULL };
c401cc
+        char *errbuf = NULL;
c401cc
         probed = true;
c401cc
-        if (virRun(probecmd, NULL) < 0) {
c401cc
-            char ebuf[1024];
c401cc
-            VIR_WARN("failed to load driver %s: %s", driver,
c401cc
-                     virStrerror(errno, ebuf, sizeof(ebuf)));
c401cc
-            return -1;
c401cc
+        if ((errbuf = virKModLoad(driver, true))) {
c401cc
+            VIR_WARN("failed to load driver %s: %s", driver, errbuf);
c401cc
+            VIR_FREE(errbuf);
c401cc
+            goto cleanup;
c401cc
         }
c401cc
 
c401cc
         goto recheck;
c401cc
     }
c401cc
 
c401cc
+cleanup:
c401cc
+    /* If we know failure was because of blacklist, let's report that;
c401cc
+     * otherwise, report a more generic failure message
c401cc
+     */
c401cc
+    if (virKModIsBlacklisted(driver)) {
c401cc
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                       _("Failed to load PCI stub module %s: "
c401cc
+                         "administratively prohibited"),
c401cc
+                       driver);
c401cc
+    } else {
c401cc
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                       _("Failed to load PCI stub module %s"),
c401cc
+                       driver);
c401cc
+    }
c401cc
+
c401cc
     return -1;
c401cc
 }
c401cc
 
c401cc
@@ -1271,12 +1286,8 @@ virPCIDeviceDetach(virPCIDevicePtr dev,
c401cc
                    virPCIDeviceList *activeDevs,
c401cc
                    virPCIDeviceList *inactiveDevs)
c401cc
 {
c401cc
-    if (virPCIProbeStubDriver(dev->stubDriver) < 0) {
c401cc
-        virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-                       _("Failed to load PCI stub module %s"),
c401cc
-                       dev->stubDriver);
c401cc
+    if (virPCIProbeStubDriver(dev->stubDriver) < 0)
c401cc
         return -1;
c401cc
-    }
c401cc
 
c401cc
     if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) {
c401cc
         virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-- 
c401cc
1.8.5.3
c401cc