From nobody Mon Feb 9 23:01:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529374559946770.5601008274044; Mon, 18 Jun 2018 19:15:59 -0700 (PDT) Received: from localhost ([::1]:38549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6Bb-0007oo-4f for importer@patchew.org; Mon, 18 Jun 2018 22:15:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5hI-0000py-Sz for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:44:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5hH-00080F-RF for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:44:40 -0400 Received: from mail-ot0-x236.google.com ([2607:f8b0:4003:c0f::236]:36653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5hH-000802-NM; Mon, 18 Jun 2018 21:44:39 -0400 Received: by mail-ot0-x236.google.com with SMTP id c15-v6so20776119otl.3; Mon, 18 Jun 2018 18:44:39 -0700 (PDT) Received: from localhost ([2600:1700:70:e488:b0ee:9bda:ee6f:91be]) by smtp.gmail.com with ESMTPSA id k141-v6sm12951496oih.42.2018.06.18.18.44.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=5YqEmkB+l2PXxl690+87L+4eeF4z8lD2PjH9NlED+vE=; b=dmm9+i7EaUdFdiQx/cEwFWa9zCNLRIycd1ybpDOM5ra0FYcKWZJs6kktIbrclRSGbM jiokEt8l0BdxA5NsRlRw6bXfZQgitAW6sJDcqUcyWaSk8M85IBZ1Lbo7TFbiT7MoVtBA /t6g+WUUidfTgjIhx/rlAvGHskDFyg6WXpi2FS/y6eMGWT5sYIpgeal6iW1hgLL0QzbJ j5dCLRSDKa5n9FgctszpH186mKpRh/bvB0uZctu7Mdtc+RxeMozw/claGI7CS7HIPd+e THckYvDniJlgzXfLppGEj6nzrm0numkpCncou2Ytfc+RDC2lWfzcSeXMR0vwzS2itswj de4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=5YqEmkB+l2PXxl690+87L+4eeF4z8lD2PjH9NlED+vE=; b=Csv6PEGP+/f//EBbcO51szKuGOVlgXZCEtVKIYH0MJavH8ycot8eLTXxTJkYimLP71 osQflv4Huhrde7IdCBOtTbFCsI7zweC9RpWkzD02kWqfzYzdZRY6cReeE3dEf/AIFY4E JNozQhIfSdermOnP//tzkr+CvvDnRSGEZwQKkjvOOQJi3FAbkNjdG3BdzoFeUXEn5poj RSQjUw3+0IfADVBGKzqr8P6Nt/ruIy6C+WLqFd0F3TmL0Hq7mQAp5g5sDWwWCR3FLfna h3QOc65d5ZcwKK23wl3vP0LFmMI138AZHSJcpsDV93Iuzmr2Kw3bO/uJKb9LapsuLgs3 JY/Q== X-Gm-Message-State: APt69E04a7Tg1VYBWjRGBsvXwPLFdGQYydqPKVBGhpqG1B9ABXngX2+p IrDVs+g0z5qZrlvEazPYgl5FOykc X-Google-Smtp-Source: ADUXVKIfTI7lS/YAz/EApinOuRYqf4K6bed5qu4ITtSBh5btZP26vW26AMxqF16Anw3FVc2bDyzVDg== X-Received: by 2002:a9d:1df4:: with SMTP id w49-v6mr9719677otw.8.1529372678547; Mon, 18 Jun 2018 18:44:38 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:41:43 -0500 Message-Id: <20180619014319.28272-18-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c0f::236 Subject: [Qemu-devel] [PATCH 017/113] nbd: Honor server's advertised minimum block size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake Commit 79ba8c98 (v2.7) changed the setting of request_alignment to occur only during bdrv_refresh_limits(), rather than at at bdrv_open() time; but at the time, NBD was unaffected, because it still used sector-based callbacks, so the block layer defaulted NBD to use 512 request_alignment. Later, commit 70c4fb26 (also v2.7) changed NBD to use byte-based callbacks, without setting request_alignment. This resulted in NBD using request_alignment of 1, which works great when the server supports it (as is the case for qemu-nbd), but falls apart miserably if the server requires alignment (but only if qemu actually sends a sub-sector request; qemu-io can do it, but most qemu operations still perform on sectors or larger). Even later, the NBD protocol was updated to document that clients should learn the server's minimum alignment during NBD_OPT_GO; and recommended that clients should assume a minimum size of 512 unless the server understands NBD_OPT_GO and replied with a smaller size. Commit 081dd1fe (v2.10) attempted to do that, by assigning request_alignment to whatever was learned from the server; but it has two flaws: the assignment is done during bdrv_open() so it gets unconditionally wiped out back to 1 during any later bdrv_refresh_limits(); and the code is not using a default of 512 when the server did not report a minimum size. Fix these issues by moving the assignment to request_alignment to the right function, and by using a sane default when the server does not advertise a minimum size. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Message-Id: <20180215032905.27146-1-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy (cherry picked from commit fd8d372dd36e839568a718684914d9960d8b1ebd) Signed-off-by: Michael Roth --- block/nbd-client.c | 3 --- block/nbd.c | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 9206652e45..7b68499b76 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -846,9 +846,6 @@ int nbd_client_init(BlockDriverState *bs, if (client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES) { bs->supported_zero_flags |=3D BDRV_REQ_MAY_UNMAP; } - if (client->info.min_block > bs->bl.request_alignment) { - bs->bl.request_alignment =3D client->info.min_block; - } =20 qemu_co_mutex_init(&client->send_mutex); qemu_co_queue_init(&client->free_sema); diff --git a/block/nbd.c b/block/nbd.c index 8b8ba56cdd..c32ea9fd73 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -474,8 +474,10 @@ static int nbd_co_flush(BlockDriverState *bs) static void nbd_refresh_limits(BlockDriverState *bs, Error **errp) { NBDClientSession *s =3D nbd_get_client_session(bs); + uint32_t min =3D s->info.min_block; uint32_t max =3D MIN_NON_ZERO(NBD_MAX_BUFFER_SIZE, s->info.max_block); =20 + bs->bl.request_alignment =3D min ? min : BDRV_SECTOR_SIZE; bs->bl.max_pdiscard =3D max; bs->bl.max_pwrite_zeroes =3D max; bs->bl.max_transfer =3D max; --=20 2.11.0