vhost-user: Add ability to know vhost-user backend disconnection
PATCH 1/1 vhost-user: Add ability to know vhost-user backend disconnection
Current QEMU cannot detect vhost-user backend disconnection. The patch adds ability to know it.
To know disconnection, add watcher to detect G_IO_HUP event. When G_IO_HUP event is detected, the disconnected socket will be read to cause a CHR_EVENT_CLOSED.
--- net/vhost-user.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/vhost-user.c +14 -0
@@ -19,6 +19,7 @@ typedef struct VhostUserState {NetClientState nc;CharDriverState *chr;VHostNetState *vhost_net; +int watch; } VhostUserState; typedef struct VhostUserChardevProps {
@@ -113,12 +114,23 @@ static void net_vhost_link_down(VhostUserState *s, bool link_down) } } +static gboolean net_vhost_user_watch (GIOChannel *chan,GIOCondition cond, +void *opaque) +{ +VhostUserState *s = opaque; +uint8_t buf[1 ]; + +qemu_chr_fe_read_all (s->chr, buf,sizeof (buf)); +return FALSE; +} +static void net_vhost_user_event (void *opaque,int event) {VhostUserState *s = opaque;switch (event) {case CHR_EVENT_OPENED : + s->watch =qemu_chr_fe_add_watch (s->chr,G_IO_HUP , net_vhost_user_watch, s);vhost_user_start (s);net_vhost_link_down (s, false);error_report ("chardev \"%s\" went up" , s->chr->label);
@@ -126,6 +138,8 @@ static void net_vhost_user_event(void *opaque, int event)case CHR_EVENT_CLOSED :net_vhost_link_down (s, true);vhost_user_stop (s); +g_source_remove (s->watch); + s->watch =0 ;error_report ("chardev \"%s\" went down" , s->chr->label);break ; }
Signature · 1 line
1.9.1
Quoted 24 lines · Tetsuya Mukawa
Current QEMU cannot detect vhost-user backend disconnection. The patch adds ability to know it.
To know disconnection, add watcher to detectG_IO_HUPevent. WhenG_IO_HUPevent is detected, the disconnected socket will be read to cause aCHR_EVENT_CLOSED.Signed-off-by Tetsuya Mukawa <[email protected]>--- net/vhost-user.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)net/vhost-user.c +1
-0@@ -19,6 +19,7 @@ typedef struct VhostUserState {NetClientState nc;CharDriverState *chr;VHostNetState *vhost_net; +int watch; } VhostUserState; typedef struct VhostUserChardevProps {
net/vhost-user.c static void net_vhost_link_down(VhostUserState *s, bool link_down) · line 123
Quoted 10 lines
net/vhost-user.c +7
-0@@ -113,12 +114,23 @@ static void net_vhost_link_down(VhostUserState *s, bool link_down) } } +static gboolean net_vhost_user_watch (GIOChannel *chan,GIOCondition cond, +void *opaque) +{ +VhostUserState *s = opaque; +uint8_t buf[1 ]; + +qemu_chr_fe_read_all (s->chr, buf,sizeof (buf));
So you read the date from the buffer and just discard it? Are you going to miss messages this way?
Please clarify.
regards,
Nikolay Nikolaev
Quoted 26 lines
net/vhost-user.c +6
-1+return FALSE; +} +static void net_vhost_user_event (void *opaque,int event) {VhostUserState *s = opaque;switch (event) {case CHR_EVENT_OPENED : + s->watch =qemu_chr_fe_add_watch (s->chr,G_IO_HUP , net_vhost_user_watch, s);vhost_user_start (s);net_vhost_link_down (s, false);error_report ("chardev \"%s\" went up" , s->chr->label);@@ -126,6 +138,8 @@ static void net_vhost_user_event(void *opaque, int event)case CHR_EVENT_CLOSED :net_vhost_link_down (s, true);vhost_user_stop (s); +g_source_remove (s->watch); + s->watch =0 ;error_report ("chardev \"%s\" went down" , s->chr->label);break ; } --1.9.1
Quoted 38 lines · Nikolay Nikolaev
Quoted 24 lines · Tetsuya Mukawa
Current QEMU cannot detect vhost-user backend disconnection. The patch adds ability to know it.
To know disconnection, add watcher to detectG_IO_HUPevent. WhenG_IO_HUPevent is detected, the disconnected socket will be read to cause aCHR_EVENT_CLOSED.Signed-off-by Tetsuya Mukawa <[email protected]>--- net/vhost-user.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)net/vhost-user.c +1
-0@@ -19,6 +19,7 @@ typedef struct VhostUserState {NetClientState nc;CharDriverState *chr;VHostNetState *vhost_net; +int watch; } VhostUserState; typedef struct VhostUserChardevProps {net/vhost-user.c static void net_vhost_link_down(VhostUserState *s, bool link_down) · line 123
Quoted 10 lines
net/vhost-user.c +7
-0@@ -113,12 +114,23 @@ static void net_vhost_link_down(VhostUserState *s, bool link_down) } } +static gboolean net_vhost_user_watch (GIOChannel *chan,GIOCondition cond, +void *opaque) +{ +VhostUserState *s = opaque; +uint8_t buf[1 ]; + +qemu_chr_fe_read_all (s->chr, buf,sizeof (buf));So you read the date from the buffer and just discard it? Are you going to miss messages this way?
Quoted 1 line
Please clarify.
Hi Nikolay,
Thanks for comment.
Yes, some messages might be lost, but it will be only happened after unix domain socket is closed by vhost-user backend.
So I guess there is no side effect.
Anyway, I just want to know vhost-user disconnection, so other ways are also nice.
Do you have any suggestions about how to implement?
Regards,
Tetsuya
Quoted 29 lines
regards,
Nikolay NikolaevQuoted 26 lines
net/vhost-user.c +6
-1+return FALSE; +} +static void net_vhost_user_event (void *opaque,int event) {VhostUserState *s = opaque;switch (event) {case CHR_EVENT_OPENED : + s->watch =qemu_chr_fe_add_watch (s->chr,G_IO_HUP , net_vhost_user_watch, s);vhost_user_start (s);net_vhost_link_down (s, false);error_report ("chardev \"%s\" went up" , s->chr->label);@@ -126,6 +138,8 @@ static void net_vhost_user_event(void *opaque, int event)case CHR_EVENT_CLOSED :net_vhost_link_down (s, true);vhost_user_stop (s); +g_source_remove (s->watch); + s->watch =0 ;error_report ("chardev \"%s\" went down" , s->chr->label);break ; } --1.9.1