@@ -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;
}