From nobody Fri May 17 11:58:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1612884677; cv=none; d=zohomail.com; s=zohoarc; b=kdnX9fdCf7zfmlORG/xZmrDX0azuggKD2O6tJ/sfDOLrYG2DW8BOZ/SKSX5PCOfSF0Anf1c6Q7mO8FmWaUpYNv8P+bEqUpoN00+3nC7pQy6iw4g7LeBPsTSYps7DmReQjLrT6ekR4GU3I2N/9YrNEUA9gYpoA1gUKLTHsJYUzCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612884677; 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; bh=lDFDY261wZp/LgJ4CqOOWZztGEFUiZcwKglFLBxC7p0=; b=J0erKsDXzDYqWprgLP2+r1cesAujNKFqO3iNSqRLbE7YTABEOr78a8y3XlAg86Pvi/oXZySvegW1ErfjS5BrtKRvnfIneMl4/PNPo/MoFqHKCsNy/zsDr4H8krYyUU6noOHsswieuwILSRYfGPbww+pxZbCmwG0ddMhsKo+39I4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1612884676557913.3119298535315; Tue, 9 Feb 2021 07:31:16 -0800 (PST) Received: from localhost ([::1]:37492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Uyx-00070r-GD for importer@patchew.org; Tue, 09 Feb 2021 10:31:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9Uw0-0005R4-Rw for qemu-devel@nongnu.org; Tue, 09 Feb 2021 10:28:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9Uvx-0003rT-Ct for qemu-devel@nongnu.org; Tue, 09 Feb 2021 10:28:12 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-lgVL6X03PwKyW4ILcWGmYA-1; Tue, 09 Feb 2021 10:28:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE658107ACE6; Tue, 9 Feb 2021 15:28:04 +0000 (UTC) Received: from blue.redhat.com (ovpn-114-150.phx2.redhat.com [10.3.114.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id E59D95D730; Tue, 9 Feb 2021 15:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612884488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lDFDY261wZp/LgJ4CqOOWZztGEFUiZcwKglFLBxC7p0=; b=S6CF8L3glKQpwGtyeD/Iu+tRU12h4txPruMsGDhqIjYFDKLWVxZMj9l/wXyNuvRpAtRqug if4w19Min+levdaTWsrrKLaiQMZTd0V91vvEjv1BeaI2EBlsjD0NV++V84gF4OB2nn84pq ViQAv29s162s3YQljmm2SXjwGmY2VuM= X-MC-Unique: lgVL6X03PwKyW4ILcWGmYA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v3 1/2] qemu-nbd: Use SOMAXCONN for socket listen() backlog Date: Tue, 9 Feb 2021 09:27:58 -0600 Message-Id: <20210209152759.209074-2-eblake@redhat.com> In-Reply-To: <20210209152759.209074-1-eblake@redhat.com> References: <20210209152759.209074-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , berrange@redhat.com, qemu-block@nongnu.org, rjones@redhat.com, qemu-stable@nongnu.org, nsoffer@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Our default of a backlog of 1 connection is rather puny; it gets in the way when we are explicitly allowing multiple clients (such as qemu-nbd -e N [--shared], or nbd-server-start with its default "max-connections":0 for unlimited), but is even a problem when we stick to qemu-nbd's default of only 1 active client but use -t [--persistent] where a second client can start using the server once the first finishes. While the effects are less noticeable on TCP sockets (since the client can poll() to learn when the server is ready again), it is definitely observable on Unix sockets, where on Unix, a client will fail with EAGAIN and no recourse but to sleep an arbitrary amount of time before retrying if the server backlog is already full. Since QMP nbd-server-start is always persistent, it now always requests a backlog of SOMAXCONN; meanwhile, qemu-nbd will request SOMAXCONN if persistent, otherwise its backlog should be based on the expected number of clients. See https://bugzilla.redhat.com/1925045 for a demonstration of where our low backlog prevents libnbd from connecting as many parallel clients as it wants. Reported-by: Richard W.M. Jones Signed-off-by: Eric Blake CC: qemu-stable@nongnu.org Reviewed-by: Daniel P. Berrang=C3=A9 Tested-by: Richard W.M. Jones --- blockdev-nbd.c | 7 ++++++- qemu-nbd.c | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d8443d235b73..b264620b98d8 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -134,7 +134,12 @@ void nbd_server_start(SocketAddress *addr, const char = *tls_creds, qio_net_listener_set_name(nbd_server->listener, "nbd-listener"); - if (qio_net_listener_open_sync(nbd_server->listener, addr, 1, errp) < = 0) { + /* + * Because this server is persistent, a backlog of SOMAXCONN is + * better than trying to size it to max_connections. + */ + if (qio_net_listener_open_sync(nbd_server->listener, addr, SOMAXCONN, + errp) < 0) { goto error; } diff --git a/qemu-nbd.c b/qemu-nbd.c index 608c63e82a25..1a340ea4858d 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -964,8 +964,16 @@ int main(int argc, char **argv) server =3D qio_net_listener_new(); if (socket_activation =3D=3D 0) { + int backlog; + + if (persistent) { + backlog =3D SOMAXCONN; + } else { + backlog =3D MIN(shared, SOMAXCONN); + } saddr =3D nbd_build_socket_address(sockpath, bindto, port); - if (qio_net_listener_open_sync(server, saddr, 1, &local_err) < 0) { + if (qio_net_listener_open_sync(server, saddr, backlog, + &local_err) < 0) { object_unref(OBJECT(server)); error_report_err(local_err); exit(EXIT_FAILURE); --=20 2.30.0 From nobody Fri May 17 11:58:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1612884688; cv=none; d=zohomail.com; s=zohoarc; b=Mow7IMA68jwSz8XwVYJEXknPZrdaZl4rNPt0V6g53V7l2DJaljtTSeJf9IVcqVGoPP8l+krZtHfaRjf23UhaVum2KIY1iOdSEcMQa2YNlTLLpZ161BxNtDkunL4Pc5EKJ6cxZW4bhmcQLTdeVK3XDJTwq3VvanOMyGp/WzijTqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612884688; 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; bh=qPYHZIKTjp0F6PV0mXe+JBNSwQCJy3TRM4fJ22nMm0s=; b=Q2xlJ9xH/4jO1nBKyGNORE1BWccAbSDkNnRQG6bNDXukdiVp4lfyJfHyNtmkUj66NgdhnCareyvmcXPjxg+DqEW7hbiZFtVitUIzxgc3NNrQ8wVFEPelGNcLJpNLLPERzA2biZPOuGo1RPBlPXdaTlQxq17YJVYsFE0FI6N9vOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1612884688534115.899718307581; Tue, 9 Feb 2021 07:31:28 -0800 (PST) Received: from localhost ([::1]:37792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Uz4-0007A3-5C for importer@patchew.org; Tue, 09 Feb 2021 10:31:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9Uw0-0005Pu-B2 for qemu-devel@nongnu.org; Tue, 09 Feb 2021 10:28:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9Uvx-0003rb-KN for qemu-devel@nongnu.org; Tue, 09 Feb 2021 10:28:12 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-TopCDnMLOv2PyykPnOnnHQ-1; Tue, 09 Feb 2021 10:28:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 875A9192AB7B; Tue, 9 Feb 2021 15:28:05 +0000 (UTC) Received: from blue.redhat.com (ovpn-114-150.phx2.redhat.com [10.3.114.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A8A75D747; Tue, 9 Feb 2021 15:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612884489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qPYHZIKTjp0F6PV0mXe+JBNSwQCJy3TRM4fJ22nMm0s=; b=OH7jRoGvCnWlPwQAnArvmJh8ocbcUgGHrQD9/BfDRDRNrsVEyY3DcFtrv1wCMVyVrts3Sf 33ZRlj3GSLo6q7lvbbl06p+yZAuGcjw1MUbmyguf588l8WKHlv6TgMnoz9RAHcIvwcUF+z MXV2Zlwrjg2kahUXbUL5FL1RBDSv3mA= X-MC-Unique: TopCDnMLOv2PyykPnOnnHQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v3 2/2] qemu-nbd: Permit --shared=0 for unlimited clients Date: Tue, 9 Feb 2021 09:27:59 -0600 Message-Id: <20210209152759.209074-3-eblake@redhat.com> In-Reply-To: <20210209152759.209074-1-eblake@redhat.com> References: <20210209152759.209074-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: nsoffer@redhat.com, berrange@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This gives us better feature parity with QMP nbd-server-start, where max-connections defaults to 0 for unlimited. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Nir Soffer --- docs/tools/qemu-nbd.rst | 4 ++-- qemu-nbd.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst index fe41336dc550..ee862fa0bc02 100644 --- a/docs/tools/qemu-nbd.rst +++ b/docs/tools/qemu-nbd.rst @@ -136,8 +136,8 @@ driver options if ``--image-opts`` is specified. .. option:: -e, --shared=3DNUM Allow up to *NUM* clients to share the device (default - ``1``). Safe for readers, but for now, consistency is not - guaranteed between multiple writers. + ``1``), 0 for unlimited. Safe for readers, but for now, + consistency is not guaranteed between multiple writers. .. option:: -t, --persistent diff --git a/qemu-nbd.c b/qemu-nbd.c index 1a340ea4858d..5416509ece18 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -328,7 +328,7 @@ static void *nbd_client_thread(void *arg) static int nbd_can_accept(void) { - return state =3D=3D RUNNING && nb_fds < shared; + return state =3D=3D RUNNING && (shared =3D=3D 0 || nb_fds < shared); } static void nbd_update_server_watch(void); @@ -706,8 +706,8 @@ int main(int argc, char **argv) device =3D optarg; break; case 'e': if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 || - shared < 1) { + shared < 0) { error_report("Invalid shared device number '%s'", optarg); exit(EXIT_FAILURE); } @@ -966,7 +965,7 @@ int main(int argc, char **argv) if (socket_activation =3D=3D 0) { int backlog; - if (persistent) { + if (persistent || shared =3D=3D 0) { backlog =3D SOMAXCONN; } else { backlog =3D MIN(shared, SOMAXCONN); --=20 2.30.0