From patchwork Wed Dec 9 18:04:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 66024 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB9I4I7S007817 for ; Wed, 9 Dec 2009 18:04:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756381AbZLISEJ (ORCPT ); Wed, 9 Dec 2009 13:04:09 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756293AbZLISEI (ORCPT ); Wed, 9 Dec 2009 13:04:08 -0500 Received: from cantor.suse.de ([195.135.220.2]:35485 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756200AbZLISEH (ORCPT ); Wed, 9 Dec 2009 13:04:07 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 1475190847 for ; Wed, 9 Dec 2009 19:04:14 +0100 (CET) From: Alexander Graf To: kvm@vger.kernel.org Subject: [PATCH] Inform users about busy device assignment attempt Date: Wed, 9 Dec 2009 19:04:13 +0100 Message-Id: <1260381853-8954-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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; }