From patchwork Mon Jul 23 20:17:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10541019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B7D4112B for ; Mon, 23 Jul 2018 21:13:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 455DD283F1 for ; Mon, 23 Jul 2018 21:13:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37B10284E9; Mon, 23 Jul 2018 21:13:33 +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 CCA6C283F1 for ; Mon, 23 Jul 2018 21:13:32 +0000 (UTC) Received: from localhost ([::1]:36678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhi95-0000kW-Qo for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 Jul 2018 17:13:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhK7-0003Kt-AG for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhhK6-00051I-9v for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:20:51 -0400 Received: from mail-oi0-x22b.google.com ([2607:f8b0:4003:c06::22b]:41660) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhhK6-000510-4q; Mon, 23 Jul 2018 16:20:50 -0400 Received: by mail-oi0-x22b.google.com with SMTP id k12-v6so3466682oiw.8; Mon, 23 Jul 2018 13:20:50 -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=zfNUWA2FT5JnALSz8JjIUuLr9sPx3kKVNCmRIeDr+04=; b=jwNGbniv3DEBY7SjHp6p1sB+bV0jeq+o0ncdlA+4Av6APxtCEwMXzs8Cmyeqsoaq+i bfZp92Rh40eEQdfwseq/fph7MzS70lRJNIe0Ecl99VGrIf5qQSVYC67KBebGAA84bTyz QJu1OxI7m5IsDhuOrrX8eWs53g6voXx0+oXBiK4Fn7ZaECTHuglWqAJWJ4wn3tDp7rDS GLSchx6H0EtDbUq0veAEhBxAPNFNZC/+v0COzXtZy4Ide8W8GLrPED8CeSdA0I08Ok+M yUVl2Mnu1+tzSeO4xzW4ar6J8FH5gN7aBk0ig1vRquzNIGAC+yP+oFi80C1hMJBSLyu2 db4Q== 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=zfNUWA2FT5JnALSz8JjIUuLr9sPx3kKVNCmRIeDr+04=; b=iH3ahOt1JhJ0FyuGu48dGSBt65eDwmWqOdqKrz9kyz3frPfCzCJQK7IS4skCdWuJrs fim9SLJjUho3NvZf5qgZeeIbHKG+VgkrkxC+3oBcs8ga7/YVFgmm096QQYeMWNi1DVv+ 3Cup9U/kRvfdNqQdL0LpsgK+OkC5cBSBe8yXPmmDDVgbgp2sBCSabA5a33NgKdX+81Vt JWnU1MtTdypYwkooCqxhFfqyiI1Nq/3EE9/KN9CVOuY+Fs2Arr3xodO6tAu/gB1EC8aQ IUlio9uVx1o99x7fnhFw0qtRTDTXHCp6YMaL/VyG+bvQKmgY/YO9JzHRO8Of/egqEFVx irfg== X-Gm-Message-State: AOUpUlHFEdVRrAnq44Pro2nffs4Mi7JD7Gjl8K55huyWuni28ijNBRnK kq37MsioNUmG7dhGM6aPcy92lC7BNr2ehg== X-Google-Smtp-Source: AAOMgpfFtrqHP8CcpV1Vr3MJUPr/VDHmKouQG1jpuFZytGfhr9U/vTsf2QngQKE7pHuiE8Ll1iAJfQ== X-Received: by 2002:aca:698c:: with SMTP id e134-v6mr332052oic.302.1532377249031; Mon, 23 Jul 2018 13:20:49 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id x5-v6sm7419935oix.3.2018.07.23.13.20.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 13:20:48 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 15:17:12 -0500 Message-Id: <20180723201748.25573-64-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> References: <20180723201748.25573-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:c06::22b Subject: [Qemu-devel] [PATCH 63/99] nbd/client: Relax handling of large NBD_CMD_BLOCK_STATUS reply 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 The NBD spec is proposing a relaxation of NBD_CMD_BLOCK_STATUS where a server may have the final extent per context give a length beyond the original request, if it can easily prove that subsequent bytes have the same status, on the grounds that a client can take advantage of this information for fewer block status requests. Since qemu 2.12 as a client always sends NBD_CMD_FLAG_REQ_ONE, and rejects a server that sends extra length, the upstream NBD spec will probably limit this behavior to clients that don't request REQ_ONE semantics; but it doesn't hurt to relax qemu to always be permissive of this server behavior, even if it continues to use REQ_ONE. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Message-Id: <20180503222626.1303410-1-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy (cherry picked from commit acfd8f7a5f92e703d2d046cbe3d510008a697194) Signed-off-by: Michael Roth --- block/nbd-client.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index e7caf49fbb..8d69eaaa32 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -259,14 +259,18 @@ static int nbd_parse_blockstatus_payload(NBDClientSession *client, if (extent->length == 0 || (client->info.min_block && !QEMU_IS_ALIGNED(extent->length, - client->info.min_block)) || - extent->length > orig_length) - { + client->info.min_block))) { error_setg(errp, "Protocol error: server sent status chunk with " "invalid length"); return -EINVAL; } + /* The server is allowed to send us extra information on the final + * extent; just clamp it to the length we requested. */ + if (extent->length > orig_length) { + extent->length = orig_length; + } + return 0; }