* [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option
@ 2019-06-06 10:15 Vladimir Sementsov-Ogievskiy
2019-06-06 11:17 ` Daniel P. Berrangé
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-06-06 10:15 UTC (permalink / raw)
To: qemu-devel; +Cc: vsementsov, berrange, armbru, kraxel, den
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
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(-)
diff --git a/qapi/sockets.json b/qapi/sockets.json
index fc81d8d5e8..aefa024051 100644
--- a/qapi/sockets.json
+++ b/qapi/sockets.json
@@ -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:
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 8850a280a8..d2cd2a9d4f 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -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;
}
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option
2019-06-06 10:15 [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option Vladimir Sementsov-Ogievskiy
@ 2019-06-06 11:17 ` Daniel P. Berrangé
2019-06-06 11:33 ` Vladimir Sementsov-Ogievskiy
0 siblings, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2019-06-06 11:17 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy; +Cc: den, kraxel, qemu-devel, armbru
On Thu, Jun 06, 2019 at 01:15:33PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>
> 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(-)
>
> diff --git a/qapi/sockets.json b/qapi/sockets.json
> index fc81d8d5e8..aefa024051 100644
> --- a/qapi/sockets.json
> +++ b/qapi/sockets.json
> @@ -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:
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 8850a280a8..d2cd2a9d4f 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -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'
> + 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
--
|: 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 :|
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option
2019-06-06 11:17 ` Daniel P. Berrangé
@ 2019-06-06 11:33 ` Vladimir Sementsov-Ogievskiy
2019-06-07 17:22 ` Markus Armbruster
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-06-06 11:33 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: Denis Lunev, kraxel, qemu-devel, armbru
06.06.2019 14:17, Daniel P. Berrangé wrote:
> On Thu, Jun 06, 2019 at 01:15:33PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>
>> 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(-)
>>
>> diff --git a/qapi/sockets.json b/qapi/sockets.json
>> index fc81d8d5e8..aefa024051 100644
>> --- a/qapi/sockets.json
>> +++ b/qapi/sockets.json
>> @@ -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:
>> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
>> index 8850a280a8..d2cd2a9d4f 100644
>> --- a/util/qemu-sockets.c
>> +++ b/util/qemu-sockets.c
>> @@ -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'
As I remember, now all optional fields are zeroed. But I'm not against stricter condition.
>
>> + 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
>
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option
2019-06-06 11:33 ` Vladimir Sementsov-Ogievskiy
@ 2019-06-07 17:22 ` Markus Armbruster
2019-06-10 16:01 ` Vladimir Sementsov-Ogievskiy
0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2019-06-07 17:22 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: qemu-devel, Daniel P. Berrangé, Denis Lunev, kraxel
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
> 06.06.2019 14:17, Daniel P. Berrangé wrote:
>> On Thu, Jun 06, 2019 at 01:15:33PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>> ---
>>>
>>> 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.
>>> qapi/sockets.json | 5 ++++-
>>> util/qemu-sockets.c | 13 +++++++++++++
>>> 2 files changed, 17 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/qapi/sockets.json b/qapi/sockets.json
>>> index fc81d8d5e8..aefa024051 100644
>>> --- a/qapi/sockets.json
>>> +++ b/qapi/sockets.json
>>> @@ -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' } }
I know the C identifier is SO_KEEPALIVE, but let's stick to proper
English words in QMP: keep-alive.
>>>
>>> ##
>>> # @UnixSocketAddress:
>>> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
>>> index 8850a280a8..d2cd2a9d4f 100644
>>> --- a/util/qemu-sockets.c
>>> +++ b/util/qemu-sockets.c
>>> @@ -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'
>
> 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.
>
>>
>>> + 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;
>>> }
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()?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option
2019-06-07 17:22 ` Markus Armbruster
@ 2019-06-10 16:01 ` Vladimir Sementsov-Ogievskiy
0 siblings, 0 replies; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-06-10 16:01 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-devel, Daniel P. Berrangé, Denis Lunev, kraxel
07.06.2019 20:22, Markus Armbruster wrote:
> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
>
>> 06.06.2019 14:17, Daniel P. Berrangé wrote:
>>> On Thu, Jun 06, 2019 at 01:15:33PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>> ---
>>>>
>>>> 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.
>
>>>> qapi/sockets.json | 5 ++++-
>>>> util/qemu-sockets.c | 13 +++++++++++++
>>>> 2 files changed, 17 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/qapi/sockets.json b/qapi/sockets.json
>>>> index fc81d8d5e8..aefa024051 100644
>>>> --- a/qapi/sockets.json
>>>> +++ b/qapi/sockets.json
>>>> @@ -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' } }
>
> I know the C identifier is SO_KEEPALIVE, but let's stick to proper
> English words in QMP: keep-alive.
Ok
>
>>>>
>>>> ##
>>>> # @UnixSocketAddress:
>>>> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
>>>> index 8850a280a8..d2cd2a9d4f 100644
>>>> --- a/util/qemu-sockets.c
>>>> +++ b/util/qemu-sockets.c
>>>> @@ -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'
>>
>> 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.
>
>>
>>>
>>>> + 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;
>>>> }
>
> 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())?
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.
>
> Do you need to update inet_parse()?
will do, thank you for reviewing!
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-10 16:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-06 10:15 [Qemu-devel] [PATCH] qapi: InitSocketAddress: add keepalive option Vladimir Sementsov-Ogievskiy
2019-06-06 11:17 ` Daniel P. Berrangé
2019-06-06 11:33 ` Vladimir Sementsov-Ogievskiy
2019-06-07 17:22 ` Markus Armbruster
2019-06-10 16:01 ` Vladimir Sementsov-Ogievskiy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.