diff mbox

Inform users about busy device assignment attempt

Message ID 1260381853-8954-1-git-send-email-agraf@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Alexander Graf Dec. 9, 2009, 6:04 p.m. UTC
None
diff mbox

Patch

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index beb488c..2612c25 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -747,7 +747,8 @@  static uint32_t calc_assigned_dev_id(uint8_t bus, uint8_t devfn)
 static int assign_device(AssignedDevice *dev)
 {
     struct kvm_assigned_pci_dev assigned_dev_data;
-    int r;
+    char dir[128], driver[128], *ns;
+    int r, v;
 
     memset(&assigned_dev_data, 0, sizeof(assigned_dev_data));
     assigned_dev_data.assigned_dev_id  =
@@ -769,9 +770,25 @@  static int assign_device(AssignedDevice *dev)
 #endif
 
     r = kvm_assign_pci_device(kvm_context, &assigned_dev_data);
-    if (r < 0)
+    if (r < 0) {
 	fprintf(stderr, "Failed to assign device \"%s\" : %s\n",
                 dev->dev.qdev.id, strerror(-r));
+
+        snprintf(dir, sizeof(dir),
+                 "/sys/bus/pci/devices/0000:%02x:%02x.%x/driver",
+	         dev->host.bus, dev->host.dev, dev->host.func);
+
+        v = readlink(dir, driver, sizeof(driver));
+        if ((v > 0) && (ns = strrchr(driver, '/'))) {
+            ns++;
+            fprintf(stderr, "*** The driver '%s' is occupying your "
+                                 "device %02x:%02x.%x.\n"
+                            "*** Try running \"rmmod %s\" on the command"
+                                 "line\n",
+                            ns, dev->host.bus, dev->host.dev, dev->host.func,
+                            ns);
+        }
+    }
     return r;
 }