From patchwork Thu Nov 17 16:27:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 9434565 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 EBD0760469 for ; Thu, 17 Nov 2016 16:30:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1CDA29643 for ; Thu, 17 Nov 2016 16:30:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C511C29646; Thu, 17 Nov 2016 16:30:37 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 C5EAC29643 for ; Thu, 17 Nov 2016 16:30:35 +0000 (UTC) Received: from localhost ([::1]:60132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7Pa6-0005pc-PZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Nov 2016 11:30:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7PX9-0003fr-9P for qemu-devel@nongnu.org; Thu, 17 Nov 2016 11:27:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7PX8-0007Xv-5h for qemu-devel@nongnu.org; Thu, 17 Nov 2016 11:27:31 -0500 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::7]:34021) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c7PX7-0007XS-S1; Thu, 17 Nov 2016 11:27:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1479400047; l=2745; s=domk; d=aepfle.de; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Subject:Cc:To:From:Date; bh=2BUnjzLiJqghRP+j2VWbZnI6uADvpi1Cv6mR8xKeib4=; b=pLt31hHMA9eLgtuNa5Dmwdif2bdRnLqC8z8Mo7lp+c/RfQwCjnxpLi98N3FRkblW0n wzUc/nbxKeXCl+Bm+xhi7tc3qR5qSlqvffYMB1iRH/+N1l/CsqQ16yzsQZf9nr7DoKAN 5YECDaeyCHuxkTv8mzT7ZgqhPqbz7kU+qUkQ0= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+zrwiavkK6tmQaLfswM/RAW08C8KYHUlxfwrhu4f27QZY X-RZG-CLASS-ID: mo00 Received: from aepfle.de (nat.nue.novell.com [IPv6:2620:113:80c0:5::2222]) by smtp.strato.de (RZmta 39.9 AUTH) with ESMTPSA id I0accesAHGRPUP9 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 17 Nov 2016 17:27:25 +0100 (CET) Date: Thu, 17 Nov 2016 17:27:19 +0100 From: Olaf Hering To: Max Reitz Message-ID: <20161117162719.GA18909@aepfle.de> References: <1459513321-3776-1-git-send-email-olaf@aepfle.de> <56FEAD92.5010802@redhat.com> <20160401174953.GD22458@aepfle.de> <7bcb7f33-5fb1-20d8-e92f-3b913b54e53b@redhat.com> <20161117135409.GA31152@aepfle.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161117135409.GA31152@aepfle.de> User-Agent: Mutt/1.6.2 (6759) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 2a01:238:20a:202:5300::7 Subject: Re: [Qemu-devel] [Qemu-block] [PATCH] block: split large discard requests from block frontend 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: Kevin Wolf , qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Nov 17, Olaf Hering wrote: > Looking at current master, BLKIF_OP_DISCARD is indeed broken. The values > passed from the guest are u64 and get stashed into signed values. I will > add a loop to repeatedly call blk_aio_pdiscard with small chunks of > BDRV_REQUEST_MAX_SECTORS. I have not compile tested the change below, but thats the way how I would deal with it: Olaf diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 3a7dc19..5962c4b 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -660,6 +660,38 @@ static void qemu_aio_complete(void *opaque, int ret) qemu_bh_schedule(ioreq->blkdev->bh); } +static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number, uint64_t nr_sectors) +{ + struct XenBlkDev *blkdev = ioreq->blkdev; + int64_t byte_offset; + int bytes; + uint64_t byte_limit = INT64_MAX + INT_MAX; + uint64_t sec_start = sector_number; + uint64_t sec_count = nr_sectors; + uint64_t byte_remaining; + uint64_t limit = BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS; + + /* Wrap around? */ + if ((sec_start + sec_count) < sec_count) + return false; + /* Overflowing byte limit? */ + if ((sec_start + sec_count) > (byte_limit >> BDRV_SECTOR_BITS)) + return false; + + byte_offset = sec_start << BDRV_SECTOR_BITS; + byte_remaining = sec_count << BDRV_SECTOR_BITS; + do { + bytes = byte_remaining > limit ? limit : byte_remaining; + ioreq->aio_inflight++; + blk_aio_pdiscard(blkdev->blk, byte_offset, bytes, + qemu_aio_complete, ioreq); + byte_remaining -= bytes; + byte_offset += bytes; + } while (byte_remaining > 0); + + return true; +} + static int ioreq_runio_qemu_aio(struct ioreq *ioreq) { struct XenBlkDev *blkdev = ioreq->blkdev; @@ -708,12 +740,9 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) break; case BLKIF_OP_DISCARD: { - struct blkif_request_discard *discard_req = (void *)&ioreq->req; - ioreq->aio_inflight++; - blk_aio_pdiscard(blkdev->blk, - discard_req->sector_number << BDRV_SECTOR_BITS, - discard_req->nr_sectors << BDRV_SECTOR_BITS, - qemu_aio_complete, ioreq); + struct blkif_request_discard *req = (void *)&ioreq->req; + if (blk_split_discard(ioreq, req->sector_number, req->nr_sectors)) + goto err; break; } default: