From mboxrd@z Thu Jan 1 00:00:00 1970 From: Don Dutile Subject: Re: [PATCH v2] device-assignment: Better fd tracking Date: Thu, 08 Jul 2010 11:28:04 -0400 Message-ID: <4C35EE84.60407@redhat.com> References: <20100707162948.5414.51749.stgit@localhost.localdomain> <20100708145732.4310.85610.stgit@localhost.localdomain> Reply-To: ddutile@redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, avi@redhat.com To: Alex Williamson Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46926 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753969Ab0GHP3H (ORCPT ); Thu, 8 Jul 2010 11:29:07 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o68FT7E9028460 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 8 Jul 2010 11:29:07 -0400 In-Reply-To: <20100708145732.4310.85610.stgit@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: Alex Williamson wrote: > Commit 909bfdba fixed a hole with not closing resource file descriptors > but we need to be more careful about tracking which are real fds, > otherwise we might close fd 0, which doesn't work out so well for stdio. > > Signed-off-by: Alex Williamson > --- > > v2: fix qemu style braces > > hw/device-assignment.c | 10 ++++++---- > 1 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/hw/device-assignment.c b/hw/device-assignment.c > index 48ac73c..de9470c 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,9 @@ 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,9 +796,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 > @@ -1415,7 +1417,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, > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html thanks for reply on other if check's. Acked-by: Donald Dutile