On Thu, 28 Nov 2019 13:33:58 -0300 Eduardo Habkost <ehabk...@redhat.com> wrote:
> On Thu, Nov 28, 2019 at 04:00:06PM +0000, Peter Maydell wrote: > > Hi; this is a question which came up in Damien's reset series > > which I don't know the answer to: > > > > What is the interaction of the QOM device lifecycle (instance_init/realize/ > > unrealize/instance_finalize) with hotplug and hot-unplug ? I couldn't > > find any documentation of this but maybe I was looking in the wrong > > place... > > > > Looking at device_set_realized() it seems like we treat "realize" > > as meaning "and also do the hot-plug if this is a device we're > > trying to hotplug". On the other hand hot-unplug is I think the > > other way around: when we get a hot-unplug event we assume that > > it should also imply an "unrealize" (but just unrealizing doesn't > > auto-hot-unplug) ? > > Your description seems accurate, and I agree it is confusing. > > It would be more consistent if realized=true didn't plug the > device automatically, and qdev_device_add() asked the hotplug > handler to plug the device instead. agreed, it's confusing. But that would not allow to o = object_new() set props o.realize() reuse the same plug handlers. we potentially can convert it to device_add input arguments and then call qdev_device_add() instead, which would then handle plug handlers, not sure it's doable though. Other than that I don't have any ideas how to make it less confusing. > > Once a device is hot-unplugged (and thus unrealized) is it valid > > for it to be re-hot-plugged, or is the assumption that it's then > > destroyed and a fresh device is created if the user wants to plug > > something in again later ? Put another way, is it valid for a qdev > > device to see state transitions realize -> unrealize -> realize ? > > My interpretation is that this is valid in theory, but likely to > crash a large portion of our devices if we tried it. >