From nobody Sat May 18 05:04:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1560183152; cv=none; d=zoho.com; s=zohoarc; b=HXMNiopqAt1uDUeHxBBitbyqtI+MFP7S4/4QN9XquEvXkZXNXS/nA8phSgWzWzeBv4P1MSHl1ji+EWQcig+4JEFkzCQIym27izjTPryJxQ4WaGtooLyMbrGKmYRgv1+Fuw9zYqP6FqkQgGKGQkT+Dd+k9SoeUl5G8dspmq2jBEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560183152; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=fb3PtqCWE+46yjGhFqM0EekuTB/+pTJCSHjjsdeOC4Y=; b=SB3VPxtBZ7PPJ8UAClxRj+g5lMh+cNXlBzuCxcJEUJ28ahrHkrR34m5rtmq5wP62n43LbgcjpJPzOzJtpBGI9f0V9r8ziA8WNUUXH+l3IOHnjdaHlCj61pbRIU5MiDZ3FHvLURoTeWwY+jC7ODXtZf6vFklC4sy2d/+GBF0/T38= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560183152757191.4905673168215; Mon, 10 Jun 2019 09:12:32 -0700 (PDT) Received: from localhost ([::1]:48178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1haMuH-0004v0-Pk for importer@patchew.org; Mon, 10 Jun 2019 12:12:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60637) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1haMsL-0003Dl-LG for qemu-devel@nongnu.org; Mon, 10 Jun 2019 12:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1haMsD-0005ma-Gm for qemu-devel@nongnu.org; Mon, 10 Jun 2019 12:10:21 -0400 Received: from relay.sw.ru ([185.231.240.75]:39460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1haMs7-0005X5-OF for qemu-devel@nongnu.org; Mon, 10 Jun 2019 12:10:13 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1haMrv-0004hK-1U; Mon, 10 Jun 2019 19:09:59 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Mon, 10 Jun 2019 19:09:57 +0300 Message-Id: <20190610160957.46809-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2] qapi: InitSocketAddress: add keepalive option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vsementsov@virtuozzo.com, berrange@redhat.com, armbru@redhat.com, kraxel@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's needed to provide keepalive for nbd client to track server availability. Signed-off-by: Vladimir Sementsov-Ogievskiy --- v2: [by Markus's comments] - improve commit message - s/keepalive/keep-alive - update inet_parse() qapi/sockets.json | 5 ++++- util/qemu-sockets.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/qapi/sockets.json b/qapi/sockets.json index fc81d8d5e8..13a2627e1d 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 # +# @keep-alive: enable keep-alive 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', + '*keep-alive': 'bool' } } =20 ## # @UnixSocketAddress: diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8850a280a8..9c842c4a93 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -457,6 +457,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error= **errp) } =20 freeaddrinfo(res); + + if (saddr->keep_alive) { + int val =3D 1; + int ret =3D 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; } =20 @@ -652,6 +665,15 @@ int inet_parse(InetSocketAddress *addr, const char *st= r, Error **errp) } addr->has_ipv6 =3D true; } + begin =3D strstr(optstr, ",keep-alive"); + if (begin) { + if (inet_parse_flag("keep-alive", begin + strlen("keep-alive=3D"), + &addr->keep_alive, errp) < 0) + { + return -1; + } + addr->has_keep_alive =3D true; + } return 0; } =20 --=20 2.18.0