resend slave fd to vhost when reconnect to vhost
PATCH 1/1 resend slave fd to vhost when reconnect to vhost
From: Ni Xun <[email protected]>
when reconnecting to vhost server, it doesn't send slave fd to vhost as the slave fd is only sent in vhost_user_init. also resend the slave fd in vhost reconnect.
--- hw/block/vhost-user-blk.c | 6 ++++++ hw/virtio/vhost-user.c | 2 +- include/hw/virtio/vhost.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-)
hw/block/vhost-user-blk.c +6 -0
@@ -138,6 +138,12 @@ static int vhost_user_blk_start(VirtIODevice *vdev)error_report ("Error get inflight: %d" , -ret); goto err_guest_notifiers; } + }else { + ret =vhost_setup_slave_channel (&s->dev); +if (ret <0 ) { +error_report ("Error setting vhost slave channel: %d" , -ret); +return ret; + } } ret =vhost_dev_set_inflight (&s->dev, s->inflight);
hw/virtio/vhost-user.c +1 -1
@@ -1115,7 +1115,7 @@ err:return ; } -static int vhost_setup_slave_channel (struct vhost_dev *dev) +int vhost_setup_slave_channel (struct vhost_dev *dev) {VhostUserMsg msg = { .hdr.request =VHOST_USER_SET_SLAVE_REQ_FD ,
include/hw/virtio/vhost.h +1 -0
@@ -100,6 +100,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);void vhost_dev_stop (struct vhost_dev *hdev,VirtIODevice *vdev);int vhost_dev_enable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev);void vhost_dev_disable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev); +int vhost_setup_slave_channel (struct vhost_dev *hdev);/* Test and clear masked event pending status. * Should be called after unmask to avoid losing events.
Signature · 1 line
2.24.1 (Apple Git-126)
Quoted 7 lines · On Fri, Apr 17, 2020 at 01:14:00PM +0800, [email protected] wrote:
From: Ni Xun <[email protected]>
when reconnecting to vhost server, it doesn't send slave fd to vhost as the slave fd is only sent in
vhost_user_init. also resend the slave fd in vhost reconnect.
I don’t think that’s correct. See vhost_user_init() here:
Rather, vhost_setup_slave_channel() is called by vhost_user_backend_init(), which is called on every reconnect inside vhost_dev_init().
see vhost_user_blk_connect(): https://git.qemu.org/?p=qemu.git;a=blob;f=hw/block/vhost-user-blk.c;h=17df5338e77c684175a86e882b508849c246e78a;hb=HEAD#l297
and vhost_dev_init():https://git.qemu.org/?p=qemu.git;a=blob;f=hw/virtio/vhost.c;h=01ebe12f28e9d7e3150375dda6f55b6b8f04a42a;hb=HEAD#l1224
Note that the dev->vq_index is also set to 0 right before the vhost_dev_init() call.
I tested myself and saw a VHOST_USER_SET_SLAVE_REQ_FD message sent on each reconnect with the vhost-user-blk sample.
Are you seeing different behavior? If so, please provide more details on your setup?
hw/block/vhost-user-blk.c static int vhost_user_blk_start(VirtIODevice *vdev) · line 140
Quoted 9 lines
hw/block/vhost-user-blk.c +0
-0@@ -138,6 +138,12 @@ static int vhost_user_blk_start(VirtIODevice *vdev)error_report ("Error get inflight: %d" , -ret); goto err_guest_notifiers; }
What's the justification for sending the slave fd here? Please elaborate.
include/hw/virtio/vhost.h
Quoted 11 lines
hw/block/vhost-user-blk.c +6
-0+ }else { + ret =vhost_setup_slave_channel (&s->dev); +if (ret <0 ) { +error_report ("Error setting vhost slave channel: %d" , -ret); +return ret; + } }include/hw/virtio/vhost.h +0
-0
Why expose this through vhost.h? This is vhost-user specific.
Quoted 12 lines
include/hw/virtio/vhost.h +1
-0@@ -100,6 +100,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);void vhost_dev_stop (struct vhost_dev *hdev,VirtIODevice *vdev);int vhost_dev_enable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev);void vhost_dev_disable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev); +int vhost_setup_slave_channel (struct vhost_dev *hdev);/* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. Signature · 1 line
2.24.1 (Apple Git-126)
oh, yes, there is some mis-config here, thanks for pointing that out. looks like the upstream has fixed it.
Thanks,
Xun
Quoted 67 lines · Raphael Norwitz <[email protected]> 于2020年4月18日周六 上午9:46写道:
Quoted 7 lines · On Fri, Apr 17, 2020 at 01:14:00PM +0800, [email protected] wrote:
From: Ni Xun <[email protected]>
when reconnecting to vhost server, it doesn't send slave fd to vhost as the slave fd is only sent in
vhost_user_init. also resend the slave fd in vhost reconnect.I don’t think that’s correct. See
vhost_user_init()here:Rather,
vhost_setup_slave_channel()is called byvhost_user_backend_init(), which is called on every reconnect insidevhost_dev_init().see
vhost_user_blk_connect(): https://git.qemu.org/?p=qemu.git;a=blob;f=hw/block/vhost-user-blk.c;h=17df5338e77c684175a86e882b508849c246e78a;hb=HEAD#l297
and vhost_dev_init():https://git.qemu.org/?p=qemu.git;a=blob;f=hw/virtio/vhost.c;h=01ebe12f28e9d7e3150375dda6f55b6b8f04a42a;hb=HEAD#l1224Note that the
dev->vq_indexis also set to 0 right before thevhost_dev_init()call.I tested myself and saw a
VHOST_USER_SET_SLAVE_REQ_FDmessage sent on each reconnect with the vhost-user-blk sample.Are you seeing different behavior? If so, please provide more details on your setup?
hw/block/vhost-user-blk.c static int vhost_user_blk_start(VirtIODevice *vdev) · line 140
Quoted 9 lines
hw/block/vhost-user-blk.c +0
-0@@ -138,6 +138,12 @@ static int vhost_user_blk_start(VirtIODevice *vdev)error_report ("Error get inflight: %d" , -ret); goto err_guest_notifiers; }What's the justification for sending the slave fd here? Please elaborate.
include/hw/virtio/vhost.h
Quoted 11 lines
hw/block/vhost-user-blk.c +6
-0+ }else { + ret =vhost_setup_slave_channel (&s->dev); +if (ret <0 ) { +error_report ("Error setting vhost slave channel: %d" , -ret); +return ret; + } }include/hw/virtio/vhost.h +0
-0Why expose this through
vhost.h? This is vhost-user specific.Quoted 12 lines
include/hw/virtio/vhost.h +1
-1@@ -100,6 +100,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);void vhost_dev_stop (struct vhost_dev *hdev,VirtIODevice *vdev);int vhost_dev_enable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev);void vhost_dev_disable_notifiers (struct vhost_dev *hdev,VirtIODevice *vdev); +int vhost_setup_slave_channel (struct vhost_dev *hdev);/* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. -- 2.24.1 (Apple Git-126)