From patchwork Wed Jul 7 16:29:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 110682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o67HYotT014960 for ; Wed, 7 Jul 2010 17:34:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754999Ab0GGRes (ORCPT ); Wed, 7 Jul 2010 13:34:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3186 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753945Ab0GGRer (ORCPT ); Wed, 7 Jul 2010 13:34:47 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o67HYi8Y006714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Jul 2010 13:34:47 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o67GTmlB024244; Wed, 7 Jul 2010 12:29:48 -0400 From: Alex Williamson Subject: [PATCH] device-assignment: Better fd tracking To: kvm@vger.kernel.org Cc: ddutile@redhat.com, alex.williamson@redhat.com Date: Wed, 07 Jul 2010 10:29:48 -0600 Message-ID: <20100707162948.5414.51749.stgit@localhost.localdomain> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 07 Jul 2010 17:34:50 +0000 (UTC) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 48ac73c..3bcb63d 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -694,6 +694,7 @@ again: rp = dev->regions + r; rp->valid = 0; + rp->resource_fd = -1; size = end - start + 1; flags &= IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH; if (size == 0 || (flags & ~IORESOURCE_PREFETCH) == 0) @@ -785,7 +786,8 @@ static void free_assigned_device(AssignedDevice *dev) fprintf(stderr, "Failed to unmap assigned device region: %s\n", strerror(errno)); - close(pci_region->resource_fd); + if (pci_region->resource_fd >= 0) + close(pci_region->resource_fd); } } } @@ -793,10 +795,8 @@ static void free_assigned_device(AssignedDevice *dev) if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) assigned_dev_unregister_msix_mmio(dev); - if (dev->real_device.config_fd) { + if (dev->real_device.config_fd >= 0) close(dev->real_device.config_fd); - dev->real_device.config_fd = 0; - } #ifdef KVM_CAP_IRQ_ROUTING free_dev_irq_entries(dev); @@ -1415,7 +1415,7 @@ static int assigned_initfn(struct PCIDevice *pci_dev) if (!dev->host.seg && !dev->host.bus && !dev->host.dev && !dev->host.func) { error_report("pci-assign: error: no host device specified"); - goto out; + return -1; } if (get_real_device(dev, dev->host.seg, dev->host.bus,