vhost-scsi: Support migration
v2 cover vhost-scsi: Support migration
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-Liran
PATCH v2 1/3 vhost-scsi: The vhost backend should be stopped when the VM is not running
From: Nir Weiner <[email protected]>
vhost-scsi doesn’t takes into account whether the VM is running or not in order to decide if it should start/stop vhost backend.
This would lead to vhost backend still being active when VM's RunState suddenly change to stopped.
An example of when this issue is encountered is when Live-Migration Pre-Copy phase completes. As in this case, VM state will be changed to stopped (while vhost backend is still active), which will result in virtio_vmstate_change() -> virtio_set_status() -> vhost_scsi_set_status() executed but vhost_scsi_set_status() will just return without stopping vhost backend.
To handle this, change code to consider that vhost processing should be stopped when VM is not running. Similar to how it is done in vhost-vsock device at vhost_vsock_set_status().
--- hw/scsi/vhost-scsi.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/scsi/vhost-scsi.c +4 -0
@@ -114,6 +114,10 @@ static void vhost_scsi_set_status(VirtIODevice *vdev, uint8_t val)VHostSCSICommon *vsc =VHOST_SCSI_COMMON (s);bool start = (val &VIRTIO_CONFIG_S_DRIVER_OK ); +if (!vdev->vm_running) { + start = false; + } +if (vsc->dev.started == start) {return ; }
Signature · 1 line
2.20.1
PATCH v2 2/3 vhost-scsi: Add VMState descriptor
In reply to Liran AlonFrom: Nir Weiner <[email protected]>
As preparation of enabling migration of vhost-scsi device, define it’s VMState. Note, we keep the convention of verifying in the pre_save() method that the vhost backend must be stopped before attempting to save the device state. Similar to how it is done for vhost-vsock.
--- hw/scsi/vhost-scsi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
hw/scsi/vhost-scsi.c +23 -0
@@ -139,6 +139,28 @@ static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq) { } +static int vhost_scsi_pre_save (void *opaque) +{ +VHostSCSICommon *vsc = opaque; + +/* At this point, backend must be stopped, otherwise +* it might keep writing to memory. */ +assert (!vsc->dev.started); + +return 0 ; +} + +static const VMStateDescription vmstate_virtio_vhost_scsi = { + .name ="virtio-vhost_scsi" , + .minimum_version_id =1 , + .version_id =1 , + .fields = (VMStateField []) { +VMSTATE_VIRTIO_DEVICE , +VMSTATE_END_OF_LIST () + }, + .pre_save = vhost_scsi_pre_save, +}; +static void vhost_scsi_realize (DeviceState *dev,Error **errp) {VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (dev);
@@ -256,6 +278,7 @@ static void vhost_scsi_class_init(ObjectClass *klass, void *data)FWPathProviderClass *fwc =FW_PATH_PROVIDER_CLASS (klass); dc->props = vhost_scsi_properties; + dc->vmsd = &vmstate_virtio_vhost_scsi;set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); vdc->realize = vhost_scsi_realize; vdc->unrealize = vhost_scsi_unrealize;
Signature · 1 line
2.20.1
PATCH v2 3/3 vhost-scsi: Allow user to enable migration
In reply to Liran AlonIn order to perform a valid migration of a vhost-scsi device, the following requirements must be met:
(1) The virtio-scsi device state needs to be saved & loaded.
(2) The vhost backend must be stopped before virtio-scsi device state is saved:
(2.1) Sync vhost backend state to virtio-scsi device state. (2.2) No further I/O requests are made by vhost backend to target
SCSI device.
(2.3) No further guest memory access takes place after VM is stopped.
(3) Requests in-flight to target SCSI device are completed before migration handover.
(4) Target SCSI device state needs to be saved & loaded into the destination host target SCSI device.
Previous commit ("vhost-scsi: Add VMState descriptor") add support to save & load the device state using VMState. This meets requirement (1).
When VM is stopped by migration thread (On Pre-Copy complete), the following code path is executed:migration_completion() -> vm_stop_force_state() -> vm_stop() -> do_vm_stop().
do_vm_stop() calls first pause_all_vcpus() which pause all guest vCPUs and then call vm_state_notify().
In case of vhost-scsi device, this will lead to the following code path to be executed:vm_state_notify() -> virtio_vmstate_change() -> virtio_set_status() -> vhost_scsi_set_status() -> vhost_scsi_stop(). vhost_scsi_stop() then calls vhost_scsi_clear_endpoint() and vhost_scsi_common_stop().
vhost_scsi_clear_endpoint() sends VHOST_SCSI_CLEAR_ENDPOINT ioctl to vhost backend which will reach kernel's vhost_scsi_clear_endpoint() which process all pending I/O requests and wait for them to complete (vhost_scsi_flush()). This meets requirement (3).
vhost_scsi_common_stop() will stop the vhost backend.
As part of this stop, dirty-bitmap is synced and vhost backend state is synced with virtio-scsi device state. As at this point guest vCPUs are already paused, this meets requirement (2).
At this point we are left with requirement (4) which is target SCSI device specific and therefore cannot be done by QEMU. Which is the main reason why vhost-scsi adds a migration blocker.
However, as this can be handled either by an external orchestrator or by using shared-storage (i.e. iSCSI), there is no reason to limit the orchestrator from being able to explictly specify it wish to enable migration even when VM have a vhost-scsi device.
Considering all the above, this commit allows orchestrator to explictly specify that it is responsbile for taking care of requirement (4) and therefore vhost-scsi should not add a migration blocker.
--- hw/scsi/vhost-scsi.c | 30 ++++++++++++++++++--------- include/hw/virtio/vhost-scsi-common.h | 1 + 2 files changed, 21 insertions(+), 10 deletions(-)
hw/scsi/vhost-scsi.c +20 -10
@@ -199,13 +199,18 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) goto close_fd; } -error_setg (&vsc->migration_blocker, -"vhost-scsi does not support migration" ); -migrate_add_blocker (vsc->migration_blocker, &err); -if (err) { -error_propagate (errp, err); -error_free (vsc->migration_blocker); - goto close_fd; +if (!vsc->migratable) { +error_setg (&vsc->migration_blocker, +"vhost-scsi does not support migration in all cases. " +"When external environment supports it (Orchestrator migrates " +"target SCSI device state or use shared storage over network), " +"set 'migratable' property to true to enable migration." ); +migrate_add_blocker (vsc->migration_blocker, &err); +if (err) { +error_propagate (errp, err); +error_free (vsc->migration_blocker); + goto close_fd; + } } vsc->dev.nvqs =VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;
@@ -230,7 +235,9 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)return ; free_vqs: -migrate_del_blocker (vsc->migration_blocker); +if (!vsc->migratable) { +migrate_del_blocker (vsc->migration_blocker); + }g_free (vsc->dev.vqs); close_fd:close (vhostfd);
@@ -243,8 +250,10 @@ static void vhost_scsi_unrealize(DeviceState *dev, Error **errp)VHostSCSICommon *vsc =VHOST_SCSI_COMMON (dev);struct vhost_virtqueue *vqs = vsc->dev.vqs; -migrate_del_blocker (vsc->migration_blocker); -error_free (vsc->migration_blocker); +if (!vsc->migratable) { +migrate_del_blocker (vsc->migration_blocker); +error_free (vsc->migration_blocker); + }/* This will stop vhost backend. */ vhost_scsi_set_status (vdev,0 );
@@ -268,6 +277,7 @@ static Property vhost_scsi_properties[] = {DEFINE_PROP_BIT64 ("t10_pi" , VHostSCSICommon, host_features,VIRTIO_SCSI_F_T10_PI , false), +DEFINE_PROP_BOOL ("migratable" , VHostSCSICommon, migratable, false), DEFINE_PROP_END_OF_LIST(), };
include/hw/virtio/vhost-scsi-common.h +1 -0
@@ -36,6 +36,7 @@ typedef struct VHostSCSICommon {int target;int lun;uint64_t host_features; +bool migratable; } VHostSCSICommon;int vhost_scsi_common_start (VHostSCSICommon *vsc);
Signature · 1 line
2.20.1
Quoted 7 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
Quoted 8 lines
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-Liran
Looks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Quoted 18 lines · Stefan Hajnoczi
Quoted 13 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Quoted 7 lines
Quoted 2 lines
Regards,
-LiranLooks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Reviewed-by Stefan Hajnoczi <[email protected]>
Gentle Ping.
-Liran
Quoted 21 lines · Liran Alon
Quoted 21 lines · Stefan Hajnoczi
Quoted 15 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-Liran
Quoted 6 lines
Quoted 4 lines
Looks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Reviewed-by Stefan Hajnoczi <[email protected]>Gentle Ping.
This should go either through Michael's virtio/vhost tree or Paolo's SCSI tree.
Stefan
Quoted 25 lines · Stefan Hajnoczi
Quoted 24 lines · Liran Alon
Quoted 24 lines · Stefan Hajnoczi
Quoted 7 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
Quoted 8 lines
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-LiranLooks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Stefan Hajnoczi <[email protected]>Gentle Ping.
This should go either through Michael's virtio/vhost tree or Paolo's SCSI tree.
Stefan
OK I'll queue it.
Quoted 32 lines · Michael S. Tsirkin
Quoted 27 lines · Stefan Hajnoczi
Quoted 26 lines · Liran Alon
Quoted 25 lines · Stefan Hajnoczi
Quoted 7 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
Quoted 8 lines
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-LiranLooks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Reviewed-by Stefan Hajnoczi <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Gentle Ping.
This should go either through Michael's virtio/vhost tree or Paolo's SCSI tree.
Stefan
OK I'll queue it.
Thanks.
When is this expected to be merged to QEMU’s master?
-Liran
Any news on when this patch-series is expected to be merged to upstream QEMU? It was accepted 2 months ago.
Thanks,
-Liran
Quoted 38 lines · Michael S. Tsirkin
Quoted 25 lines · Stefan Hajnoczi
Quoted 24 lines · Liran Alon
Quoted 24 lines · Stefan Hajnoczi
Quoted 7 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
Quoted 8 lines
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-LiranLooks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Stefan Hajnoczi <[email protected]>Gentle Ping.
This should go either through Michael's virtio/vhost tree or Paolo's SCSI tree.
Stefan
OK I'll queue it.
Quoted 44 lines · Liran Alon
Any news on when this patch-series is expected to be merged to upstream QEMU? It was accepted 2 months ago.
Thanks,
-LiranQuoted 38 lines · Michael S. Tsirkin
Quoted 25 lines · Stefan Hajnoczi
Quoted 24 lines · Liran Alon
Quoted 24 lines · Stefan Hajnoczi
Quoted 7 lines · Liran Alon
Hi,
This patch series aims to add supprot to migrate a VM with a vhost-scsi device.
The 1st patch fixes a bug of mistakenly not stopping vhost-scsi backend when a VM is stopped (As happens on migratino pre-copy completion).
Quoted 8 lines
The 2nd patch adds ability to save/load vhost-scsi device state in VMState.
The 3rd and final paqtch adds a flag to vhost-scsi which allows admin to specify it's setup supports vhost-scsi migratino. For more detailed information on why this is valid, see commit message of specific patch.
Regards,
-LiranLooks fine for vhost_scsi.ko. I have not checked how this interacts with vhost-user-scsi.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Stefan Hajnoczi <[email protected]>Gentle Ping.
This should go either through Michael's virtio/vhost tree or Paolo's SCSI tree.
Stefan
OK I'll queue it.
Sorry dropped it by mistake after queueing and was not cc'd so forgot to reapply. Queued now.
Signature · 1 line
MST
Quoted 2 lines · Liran Alon
Any news on when this patch-series is expected to be merged to upstream QEMU? It was accepted 2 months ago.
It was merged on June 6th.
Paolo