qapi: InitSocketAddress: add keepalive option
PATCH 1/1 qapi: InitSocketAddress: add keepalive option
---
Hi all!
This is a continuation of "[PATCH v2 0/2] nbd: enable keepalive", but it's a try from another side, so almost nothing common with v2.
qapi/sockets.json | 5 ++++- util/qemu-sockets.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
qapi/sockets.json +4 -1
@@ -53,6 +53,8 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keepalive: enable keepalive when connecting to this socket (Since 4.1) +# # Since: 1.3 ## { 'struct': 'InetSocketAddress',
@@ -61,7 +63,8 @@ '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keepalive': 'bool' } } ## # @UnixSocketAddress:
util/qemu-sockets.c +13 -0
@@ -457,6 +457,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) }freeaddrinfo (res); + +if (saddr->keepalive) { +int val =1 ; +int ret =qemu_setsockopt (sock,SOL_SOCKET ,SO_KEEPALIVE , + &val,sizeof (val)); + +if (ret <0 ) { +error_setg_errno (errp, errno,"Unable to set KEEPALIVE" ); +close (sock); +return -1 ; + } + } +return sock; }
Signature · 1 line
2.18.0
Quoted 41 lines · Vladimir Sementsov-Ogievskiy
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Hi all!
This is a continuation of "[PATCH v2 0/2] nbd: enable keepalive", but it's a try from another side, so almost nothing common with v2.
qapi/sockets.json | 5 ++++- util/qemu-sockets.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)qapi/sockets.json +4
-1@@ -53,6 +53,8 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keepalive: enable keepalive when connecting to this socket (Since 4.1) +# # Since: 1.3 ## { 'struct': 'InetSocketAddress',@@ -61,7 +63,8 @@ '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keepalive': 'bool' } } ## # @UnixSocketAddress:util/qemu-sockets.c +0
-0
util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 461
Quoted 5 lines
util/qemu-sockets.c +2
-0@@ -457,6 +457,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) }freeaddrinfo (res); + +if (saddr->keepalive) {
IIUC, best practice is to use 'saddr->has_keepalive && saddr->keepalive'
util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 474
Quoted 13 lines
util/qemu-sockets.c +11
-0+int val =1 ; +int ret =qemu_setsockopt (sock,SOL_SOCKET ,SO_KEEPALIVE , + &val,sizeof (val)); + +if (ret <0 ) { +error_setg_errno (errp, errno,"Unable to set KEEPALIVE" ); +close (sock); +return -1 ; + } + } +return sock; }
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 44 lines · Daniel P. Berrangé
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Hi all!
This is a continuation of "[PATCH v2 0/2] nbd: enable keepalive", but it's a try from another side, so almost nothing common with v2.
qapi/sockets.json | 5 ++++- util/qemu-sockets.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)qapi/sockets.json +4
-1@@ -53,6 +53,8 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keepalive: enable keepalive when connecting to this socket (Since 4.1) +# # Since: 1.3 ## { 'struct': 'InetSocketAddress',@@ -61,7 +63,8 @@ '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keepalive': 'bool' } } ## # @UnixSocketAddress:util/qemu-sockets.c +0
-0@@ -457,6 +457,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) }
Quoted 5 lines
util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 461
Quoted 3 lines
util/qemu-sockets.c +2
-0freeaddrinfo (res); + +if (saddr->keepalive) {IIUC, best practice is to use '
saddr->has_keepalive&&saddr->keepalive'
As I remember, now all optional fields are zeroed. But I'm not against stricter condition.
Quoted 18 lines
Quoted 4 lines
util/qemu-sockets.c +3
-0+int val =1 ; +int ret =qemu_setsockopt (sock,SOL_SOCKET ,SO_KEEPALIVE , + &val,sizeof (val));util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 474
Quoted 10 lines
util/qemu-sockets.c +8
-0+ +if (ret <0 ) { +error_setg_errno (errp, errno,"Unable to set KEEPALIVE" ); +close (sock); +return -1 ; + } + } +return sock; }Regards,
Daniel
Signature · 2 lines
Best regards, Vladimir
Quoted 9 lines · Vladimir Sementsov-Ogievskiy
Quoted 8 lines · Daniel P. Berrangé
Quoted 7 lines · Vladimir Sementsov-Ogievskiy
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Hi all!
This is a continuation of "[PATCH v2 0/2] nbd: enable keepalive", but it's a try from another side, so almost nothing common with v2.
Please explain intended use of your new option in your commit message.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
qapi/sockets.json | 5 ++++- util/qemu-sockets.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)qapi/sockets.json +2
-0@@ -53,6 +53,8 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keepalive: enable keepalive when connecting to this socket (Since 4.1) +# # Since: 1.3 ##
Quoted 8 lines
Quoted 8 lines
qapi/sockets.json line 67
Quoted 8 lines
qapi/sockets.json +2
-1{ 'struct': 'InetSocketAddress',@@ -61,7 +63,8 @@ '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keepalive': 'bool' } }
I know the C identifier is SO_KEEPALIVE, but let's stick to proper English words in QMP: keep-alive.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
qapi/sockets.json +0
-0## # @UnixSocketAddress:util/qemu-sockets.c +0
-0@@ -457,6 +457,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) }
Quoted 7 lines
Quoted 5 lines
util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 461
Quoted 3 lines
util/qemu-sockets.c +2
-0freeaddrinfo (res); + +if (saddr->keepalive) {IIUC, best practice is to use '
saddr->has_keepalive&&saddr->keepalive'As I remember, now all optional fields are zeroed. But I'm not against stricter condition.
As far as I'm concerned, relying on zero-initialization of optional members is fine.
Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
util/qemu-sockets.c +3
-0+int val =1 ; +int ret =qemu_setsockopt (sock,SOL_SOCKET ,SO_KEEPALIVE , + &val,sizeof (val));util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 474
Quoted 10 lines
util/qemu-sockets.c +8
-0+ +if (ret <0 ) { +error_setg_errno (errp, errno,"Unable to set KEEPALIVE" ); +close (sock); +return -1 ; + } + } +return sock; }
Possibly ignorant question: why obey the keep-alive option for active connections (made with inet_connect_saddr()), but not passive ones (made with inet_listen_saddr() + accept())?
Do you need to update inet_parse()?
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Vladimir Sementsov-Ogievskiy
Quoted 4 lines · Daniel P. Berrangé
Quoted 3 lines · Vladimir Sementsov-Ogievskiy
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Hi all!
This is a continuation of "[PATCH v2 0/2] nbd: enable keepalive", but it's a try from another side, so almost nothing common with v2.
Please explain intended use of your new option in your commit message.
Will do. Actual reason is keepalive for nbd-client.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
qapi/sockets.json | 5 ++++- util/qemu-sockets.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)qapi/sockets.json +2
-0@@ -53,6 +53,8 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keepalive: enable keepalive when connecting to this socket (Since 4.1) +# # Since: 1.3 ## { 'struct': 'InetSocketAddress',@@ -61,7 +63,8 @@ '*numeric': 'bool',
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
qapi/sockets.json line 67
Quoted 5 lines
qapi/sockets.json +2
-1'*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keepalive': 'bool' } }I know the C identifier is
SO_KEEPALIVE, but let's stick to proper English words in QMP: keep-alive.
Ok
Quoted 33 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
qapi/sockets.json +0
-0## # @UnixSocketAddress:util/qemu-sockets.c +0
-0@@ -457,6 +457,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) }Quoted 7 lines
Quoted 5 lines
util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 461
Quoted 3 lines
util/qemu-sockets.c +2
-0freeaddrinfo (res); + +if (saddr->keepalive) {IIUC, best practice is to use '
saddr->has_keepalive&&saddr->keepalive'As I remember, now all optional fields are zeroed. But I'm not against stricter condition.
As far as I'm concerned, relying on zero-initialization of optional members is fine.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
util/qemu-sockets.c +9
-0+int val =1 ; +int ret =qemu_setsockopt (sock,SOL_SOCKET ,SO_KEEPALIVE , + &val,sizeof (val)); + +if (ret <0 ) { +error_setg_errno (errp, errno,"Unable to set KEEPALIVE" ); +close (sock); +return -1 ; + }
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
util/qemu-sockets.c int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) · line 474
Quoted 4 lines
util/qemu-sockets.c +2
-0+ } +return sock; }Possibly ignorant question: why obey the keep-alive option for active connections (made with
inet_connect_saddr()), but not passive ones (made withinet_listen_saddr()+accept())?
Hmm. It's a bit trickier, as seems I can't do it on socket level, as parameter keep-alive I get for listen part, but keep-alive should be enabled on socket from accept. So this should be implemented on qio_channel level.. I'd prefer not implement it now. We now only interested in keep-alive for client, and seems generally keep-alive is more usable for client part.
Quoted 2 lines
Do you need to update
inet_parse()?
will do, thank you for reviewing!
Signature · 2 lines
Best regards, Vladimir