libxl_qmp: wait for completion of device removal
authorChao Gao <chao.gao@intel.com>
Fri, 19 Jul 2019 09:24:08 +0000 (10:24 +0100)
committerPatchew Importer <importer@patchew.org>
Fri, 19 Jul 2019 09:24:08 +0000 (10:24 +0100)
commitc4b1ef0f89aa6a74faa4618ce3efed1de246ec40
treeeb2729dbaadbfbea8137d0d90a1e90dbd6313f2b
parent643d8e566de59f247556e62a27ed7a5ac2e8a8cf
libxl_qmp: wait for completion of device removal

To remove a device from a domain, a qmp command is sent to qemu. But it is
handled by qemu asychronously. Even the qmp command is claimed to be done,
the actual handling in qemu side may happen later.
This behavior brings two questions:
1. Attaching a device back to a domain right after detaching the device from
that domain would fail with error:

libxl: error: libxl_qmp.c:341:qmp_handle_error_response: Domain 1:received an
error message from QMP server: Duplicate ID 'pci-pt-60_00.0' for device

2. Accesses to PCI configuration space in Qemu may overlap with later device
reset issued by 'xl' or by pciback.

In order to avoid mentioned questions, wait for the completion of device
removal by querying all pci devices using qmp command and ensuring the target
device isn't listed. Only retry 5 times to avoid 'xl' potentially being blocked
by qemu.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Message-Id: <1562133373-19208-1-git-send-email-chao.gao@intel.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
tools/libxl/libxl_qmp.c