I created a sysfs attribute for a mediated device to enable/block migration
of the associated VFIODevice in QEMU. When the sysfs attribute is changed,
an eventfd is signaled to QEMU to enable or block migration. In response,
QEMU adds a migration blocker to the VFIODevice object and sets it's
'enable_migration' field to 'ON_OFF_AUTO_OFF'.
I do not want to send the signal to block migration if a migration of the
VFIODevice is already in progress, so I need to detect when migration is
initiated/completed in QEMU and notify the VFIO device driver so it
can respond to a request to block migration via the sysfs attribute with
an -EBUSY error while migration is in progress.
The only way I've been able to find to do this is via callbacks to the
VFIO device
driver in response to the 'VFIO_DEVICE_FEATURE_MIG_DATA_SIZE' and
'VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE' ioctl calls. In the former case, a
flag is set via the driver to indicate that migration is in progress.
This flag is
checked when a user attempts to block migration via the sysfs attribute and
is prevented from doing so by returning -EBUSY from the attribute's store
function. In the latter case, the flag is cleared when the VFIO device
migration
state transitions from 'VFIO_DEVICE_STATE_STOP_COPY' to
'VFIO_DEVICE_STATE_STOP'.
This works for the most part, but it's not foolproof because the eventfd
can
still be signaled after migration is started but before the saving phase of
of VFIODevice migration is initiated. It would be great if the VFIO device
could be notified by QEMU when migration is initiated and when it ends.
Is there any way in the QEMU code that manages my VFIODevice to get
notified that a migration has been initiated/ended? I tried registering a
migration notifier, but the only notification I got was
'MIG_EVENT_PRECOPY_DONE' which wasn't helpful. I also tried setting
a 'pre_save_errp' callback in the VMStateDescription for the VFIODevice,
but that also got called too late in the migration process.
So, the main question is, does QEMU provide a means for getting notified
earlier in the migration process or even when it is initiated? Thanks
for any
suggestions you can provide.