From nobody Sun Oct 5 21:10:03 2025 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565894111; cv=none; d=zoho.com; s=zohoarc; b=nNsLfY2aq5j+I4FEAxnp1CQdTUic/RyiGLojGkPqdPgZZSZWljfogHcF0fVpO03klenfFKRgiO4hf1jz6voK3KQwp4xq4gYfl0vDVDpTOcprnIVzd7w8BT8U9xQ4ex2RrORl3ZMye/hHoYWrx44QM+VR1F1c7/oNLxIGQ/ILl4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565894111; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZtOupEQPrS8mufNfELTMouVyf6aRjBqEE+3pChb2bSE=; b=GYdiHNVQMb8/IMMFVrC4U4U3+MLJoNe7me7AVnjjmaN7oUR3ncjU2zLdD/k94O2cRKo1Hpf79V40D1gFJxSCz6epXJq3fyrNPahChazO3vO8mwHQngO8G4tmdTHLmW/pIeBdbl125hKNK2fBiLTlSqsvlbNtjSsPxRX903YdWlQ= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565894111063636.5580850773568; Thu, 15 Aug 2019 11:35:11 -0700 (PDT) Received: from localhost ([::1]:46064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKaP-0004vL-IJ for importer@patchew.org; Thu, 15 Aug 2019 14:34:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37333) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyKWW-0002m8-TI for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:30:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyKWU-0001JJ-Ak for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:30:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35056) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyKWU-0001I8-1a for qemu-devel@nongnu.org; Thu, 15 Aug 2019 14:30:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63A1AC08E2BD; Thu, 15 Aug 2019 18:30:53 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-22.phx2.redhat.com [10.3.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21BFE8388F; Thu, 15 Aug 2019 18:30:41 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 15 Aug 2019 13:30:31 -0500 Message-Id: <20190815183039.4264-2-eblake@redhat.com> In-Reply-To: <20190815183039.4264-1-eblake@redhat.com> References: <20190815183039.4264-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 15 Aug 2019 18:30:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/9] qapi: Add InetSocketAddress member keep-alive 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: Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Markus Armbruster , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy It's needed to provide keepalive for nbd client to track server availability. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20190725094937.32454-1-vsementsov@virtuozzo.com> Reviewed-by: Markus Armbruster Acked-by: Daniel P. Berrang=C3=A9 [eblake: Fix error message typo] Signed-off-by: Eric Blake --- qapi/sockets.json | 6 +++++- util/qemu-sockets.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/qapi/sockets.json b/qapi/sockets.json index fc81d8d5e8b9..32375f3a361e 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -53,6 +53,9 @@ # # @ipv6: whether to accept IPv6 addresses, default try both IPv4 and IPv6 # +# @keep-alive: enable keep-alive when connecting to this socket. Not suppo= rted +# for passive sockets. (Since 4.2) +# # Since: 1.3 ## { 'struct': 'InetSocketAddress', @@ -61,7 +64,8 @@ '*numeric': 'bool', '*to': 'uint16', '*ipv4': 'bool', - '*ipv6': 'bool' } } + '*ipv6': 'bool', + '*keep-alive': 'bool' } } ## # @UnixSocketAddress: diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index a5092dbd12e7..e3a1666578d9 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -219,6 +219,12 @@ static int inet_listen_saddr(InetSocketAddress *saddr, bool socket_created =3D false; Error *err =3D NULL; + if (saddr->keep_alive) { + error_setg(errp, "keep-alive option is not supported for passive " + "sockets"); + return -1; + } + memset(&ai,0, sizeof(ai)); ai.ai_flags =3D AI_PASSIVE; if (saddr->has_numeric && saddr->numeric) { @@ -458,6 +464,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error= **errp) } 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; } @@ -653,6 +672,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"), + &addr->keep_alive, errp) < 0) + { + return -1; + } + addr->has_keep_alive =3D true; + } return 0; } --=20 2.20.1