test: virtio-scsi: check if hot-plug/unplug works

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
test: virtio-serial: check if hot-plug/unplug works

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
test: libqos: add qpci_plug_device_test() and qpci_unplug_acpi_device_test()

functions will be used for testing hot(un)plug of PCI
devices.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
test: virtio-rng: check if hot-plug/unplug works

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  moved code duplication into library
test: virtio-net: check if hot-plug/unplug works

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  moved code duplication into library
test: virtio-blk: check if hot-plug/unplug works

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  moved code duplication into library
test: usb: move uhci port test code to libqos/usb.c

Move code necessary for testing uhci port into library
so it could be used by other USB tests.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
test: usb: add port test to uhci unit test

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  split patch from code movment for ehci test
test: usb: generic usb device hotplug

use usb-tablet as a hotplugged usb device.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
Since I'm not familiar with internals of USB,
for OHCI/XHCI test doesn't verify that usb device
has been hotplugged except of checking for error
after hotplug. So port checks similar to that of
ehci/uhci, left as excercise for future.
test: usb: usb-storage hotplug test

usb-storage is different from usual usb devices
in that it uses child SCSI bus for underlying storage.
That patch verifies that SCSI bus is hotpluggable for
hotplug operation wouldn't succeed without it.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
test: usb: usb-uas hotplug test

checks that it's possible to hotplug usb-uas HBA and
then if it's possible to hot(un)plug scsi-disk to it.
Thest basically covers hot(un)plug on dummy HBAs
without means of hot(un)plug notification of the guest.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
access BusState.allow_hotplug using wraper qbus_is_hotpluggable()

it would allow transparently switch detection if Bus
is hotpluggable from allow_hotplug field to hotplug_handler
link and drop allow_hotplug field once all users are
converted to hotplug handler API.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
qdev: do not allow to instantiate non hotpluggable device with device_add

It will allow explicitly mark device as not hotpluggable and
avoid its creation with following error at realize time
and destroying it afterwards anyway. Instead of it will
error out even before instance of device is created.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
qdev: HotplugHandler: rename unplug callback to unplug_request

'HotplugHandler.unplug' callback is currently used as async
call to issue unplug request for device that implements it.
Renaming 'unplug' callback to 'unplug_request' should help to
avoid confusion about what callback does and would allow to
introduce 'unplug' callback that would perform actual device
removal when guest is ready for it.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
Patch is prompted by reviewing https://patchwork.ozlabs.org/patch/383372/

Dedicated 'unplug' callback could be used by bus-less pc-dimm
device. It would allow to call HotplugHandler.unplug callback
from ACPI code when guest calls _EJ0 method and execute board
specific code (PCMachine) to unmap pc-dimm from guest's address
space and perform necessary cleanup. The same applies to CPU
unplug.
qdev: HotplugHandler: provide unplug callback

it to be called for actual device removal and
will allow to separate request and removal handling
phases of x86-CPU devices and also it's a handler
to be called for synchronously removable devices.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
unplug handling for bus-less devices will be added
later in this series.

v2:
 - fixup copypast error, s/unplug_request/unplug/
    spotted by Tang Chen <tangchen@cn.fujitsu.com>
qdev: add simple/generic unplug callback for HotplugHandler

it will be used in shallow conversion from legacy hotplug
mechanism and eventually replace all the uses of old mechanism
DeviceClass->unplug = qdev_simple_unplug_cb()

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
qdev: add wrapper to set BUS as HotplugHandler

to be used for conversion of SCSI and USB devices,
and would allow to make every HBA/USB host switch
to HotplugHandler API without touching each controller
explicitly.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
qdev: drop hotplug check from bus_add_child()

check is too restrictive and does not allow
to add childs to just created bus during hotplug
when the bus is part of composite device.

Removing check from bus_add_child() doesn't affect
devices creatable with device_add/del commands since
they have a similar builtin checks and patch will
allow to create complex composite devices during
hotplug.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
target-i386: ICC bus: drop BusState.allow_hotplug

since bus_add_child() no longer cares if BUS is hotpluggable
or not, there is no need in setting allow_hotplug field.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
virtio-pci: drop BusState.allow_hotplug

virtio-pci-bus is an internal object of composite
virtio-pci device and it doesn't participate in
-device/device_add hotplug flow, and since it's
not required by bus_add_child() that BUS must
be hotpluggable to be able to add child at runtime,
it's possible to drop not needed 'allow_hotplug'
field.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>