From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq31x-0001O8-V3 for qemu-devel@nongnu.org; Mon, 09 Dec 2013 10:46:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vq31r-0000RS-SD for qemu-devel@nongnu.org; Mon, 09 Dec 2013 10:45:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq31r-0000R9-KG for qemu-devel@nongnu.org; Mon, 09 Dec 2013 10:45:51 -0500 Message-ID: <52A5DEE9.9030901@redhat.com> Date: Mon, 09 Dec 2013 16:16:57 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1386349395-5710-1-git-send-email-imammedo@redhat.com> <1386349395-5710-8-git-send-email-imammedo@redhat.com> <52A20996.8020308@redhat.com> <20131209144139.7f9ac562@nial.usersys.redhat.com> <52A5C9D4.7080404@redhat.com> <20131209151431.57d49bd4@nial.usersys.redhat.com> <52A5D573.7010803@redhat.com> <20131209160834.59bfdc98@nial.usersys.redhat.com> In-Reply-To: <20131209160834.59bfdc98@nial.usersys.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 7/7] hw/pci: convert PCI bus to use "hotplug-device" interface. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, marcel.a@redhat.com, qemu-devel@nongnu.org, blauwirbel@gmail.com, alex.williamson@redhat.com, anthony@codemonkey.ws, afaerber@suse.de Il 09/12/2013 16:08, Igor Mammedov ha scritto: > On Mon, 09 Dec 2013 15:36:35 +0100 > Paolo Bonzini wrote: > >> Il 09/12/2013 15:14, Igor Mammedov ha scritto: >>>>> >>>>> Makes sense. realize() for the "plug" handler, and qdev_unplug for the >>>>> unplug handler, I guess. >>> Just to be sure, I've meant not DEVICE.realize() but each device specific >>> one. >> >> If it's each specific device, then why should the hotplug handler link >> be in DeviceState? > The reason I've put it there is to eventually replace allow_hotplug field with it, > it also reduces code duplication (i.e. we wont' have to add it in PCIDevice, > DimmDevice ...) and potentially allows to use NULL for error in > property lookup since each bus will have it. I agree that's the right thing to do. >> I think it should be in device_set_realized. > if we dub it nofail then it's fine, otherwise failure path becomes more complicated. > > Calling handler in specific device realize() allows to gracefully abort > realize() since that device knows what needs to be done to do so: > For example: > @@ -1720,6 +1714,8 @@ static int pci_qdev_init(DeviceState *qdev) > ... > + hdc->hotplug(hotplug_dev, qdev, &local_err); > + if (error_is_set(&local_err)) { > + int r = pci_unregister_device(&pci_dev->qdev); > > Calling handler in realize will not allow to do it. > It's just much more flexible to call handler from specific device since it knows > when it's the best to call handler and how to deal with failure. We could have separate check/plug methods. Only check can fail, it must be idempotent, and it can be invoked while the device is still unrealized. The reason I liked the interface, is because it removes the need for each bus to add its own plug/unplug handling. Paolo >>> qdev_unplug() might work for now, but I haven't checked all devices that >>> might use interface and if it would break anything. Ideally it should be >>> in device's unrealize() complementing realize() part. >>> >>> I'd wait till all buses converted to new interface before attempting to >>> generalize current plug/unplug call pathes though. >> >> I agree that adding a default behavior for no link probably requires >> conversion of all buses. However, looking for the link in the generic >> code can be done now. >> >> Paolo >> >