From patchwork Tue Jun 19 01:41:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10472873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6896D601D7 for ; Tue, 19 Jun 2018 02:16:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B2F228D7E for ; Tue, 19 Jun 2018 02:16:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FB8328D82; Tue, 19 Jun 2018 02:16:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95A7128D7E for ; Tue, 19 Jun 2018 02:16:27 +0000 (UTC) Received: from localhost ([::1]:38549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6C2-0007oo-O2 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jun 2018 22:16:26 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 |= BDRV_REQ_MAY_UNMAP; } - if (client->info.min_block > bs->bl.request_alignment) { - bs->bl.request_alignment = client->info.min_block; - } 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 = nbd_get_client_session(bs); + uint32_t min = s->info.min_block; uint32_t max = MIN_NON_ZERO(NBD_MAX_BUFFER_SIZE, s->info.max_block); + bs->bl.request_alignment = min ? min : BDRV_SECTOR_SIZE; bs->bl.max_pdiscard = max; bs->bl.max_pwrite_zeroes = max; bs->bl.max_transfer = max;