From: Chris Wright Subject: Re: [PATCH] device-assignment: Reset device on system reset Date: Thu, 17 Mar 2011 14:12:10 -0700 Message-ID: <20110317211210.GL15007@x200.localdomain> References: <20110317192923.24889.79288.stgit@s20.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, ddutile@redhat.com, chrisw@redhat.com, bernhard.kohl@nsn.com, libvir-list@redhat.com To: Alex Williamson Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55457 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755422Ab1CQVMU (ORCPT ); Thu, 17 Mar 2011 17:12:20 -0400 Content-Disposition: inline In-Reply-To: <20110317192923.24889.79288.stgit@s20.home> Sender: kvm-owner@vger.kernel.org List-ID: * Alex Williamson (alex.williamson@redhat.com) wrote: > static void reset_assigned_device(DeviceState *dev) > { > - PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev); > + PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev); > + AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev); > + char reset_file[64]; > + const char reset[] = "1"; > + int fd, ret; > + > + snprintf(reset_file, sizeof(reset_file), > + "/sys/bus/pci/devices/0000:%02x:%02x.%01x/reset", > + adev->host.bus, adev->host.dev, adev->host.func); need to consider segment: %04x:..., adev->host.seg, ... > + /* > + * Issue a device reset via pci-sysfs. Note that we use write(2) here > + * and ignore the return value because some kernels have a bug that > + * returns 0 rather than bytes written on success, sending us into an > + * infinite retry loop using other write mechanisms. > + */ > + fd = open(reset_file, O_WRONLY); > + if (fd != -1) { > + ret = write(fd, reset, strlen(reset)); > + close(fd); > + } This will probably fail when it's managed by libvirt. I expect it will need some file ownership and security label mgmt added to device assignement path I expect.