Skip to content

Commit 5820a3b

Browse files
israelrumstsirkin
authored andcommitted
virtio_blk: Add support for transport error recovery
Add support for proper cleanup and re-initialization of virtio-blk devices during transport reset error recovery flow. This enhancement includes: - Pre-reset handler (reset_prepare) to perform device-specific cleanup - Post-reset handler (reset_done) to re-initialize the device These changes allow the device to recover from various reset scenarios, ensuring proper functionality after a reset event occurs. Without this implementation, the device cannot properly recover from resets, potentially leading to undefined behavior or device malfunction. This feature has been tested using PCI transport with Function Level Reset (FLR) as an example reset mechanism. The reset can be triggered manually via sysfs (echo 1 > /sys/bus/pci/devices/$PCI_ADDR/reset). Signed-off-by: Israel Rukshin <[email protected]> Reviewed-by: Max Gurtovoy <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a0ec4fb commit 5820a3b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

drivers/block/virtio_blk.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,7 @@ static void virtblk_remove(struct virtio_device *vdev)
15821582
put_disk(vblk->disk);
15831583
}
15841584

1585-
#ifdef CONFIG_PM_SLEEP
1586-
static int virtblk_freeze(struct virtio_device *vdev)
1585+
static int virtblk_freeze_priv(struct virtio_device *vdev)
15871586
{
15881587
struct virtio_blk *vblk = vdev->priv;
15891588
struct request_queue *q = vblk->disk->queue;
@@ -1605,7 +1604,7 @@ static int virtblk_freeze(struct virtio_device *vdev)
16051604
return 0;
16061605
}
16071606

1608-
static int virtblk_restore(struct virtio_device *vdev)
1607+
static int virtblk_restore_priv(struct virtio_device *vdev)
16091608
{
16101609
struct virtio_blk *vblk = vdev->priv;
16111610
int ret;
@@ -1619,8 +1618,29 @@ static int virtblk_restore(struct virtio_device *vdev)
16191618

16201619
return 0;
16211620
}
1621+
1622+
#ifdef CONFIG_PM_SLEEP
1623+
static int virtblk_freeze(struct virtio_device *vdev)
1624+
{
1625+
return virtblk_freeze_priv(vdev);
1626+
}
1627+
1628+
static int virtblk_restore(struct virtio_device *vdev)
1629+
{
1630+
return virtblk_restore_priv(vdev);
1631+
}
16221632
#endif
16231633

1634+
static int virtblk_reset_prepare(struct virtio_device *vdev)
1635+
{
1636+
return virtblk_freeze_priv(vdev);
1637+
}
1638+
1639+
static int virtblk_reset_done(struct virtio_device *vdev)
1640+
{
1641+
return virtblk_restore_priv(vdev);
1642+
}
1643+
16241644
static const struct virtio_device_id id_table[] = {
16251645
{ VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
16261646
{ 0 },
@@ -1656,6 +1676,8 @@ static struct virtio_driver virtio_blk = {
16561676
.freeze = virtblk_freeze,
16571677
.restore = virtblk_restore,
16581678
#endif
1679+
.reset_prepare = virtblk_reset_prepare,
1680+
.reset_done = virtblk_reset_done,
16591681
};
16601682

16611683
static int __init virtio_blk_init(void)

0 commit comments

Comments
 (0)