From patchwork Fri Jun 3 17:03:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9153761 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 3C8F26082E for ; Fri, 3 Jun 2016 17:08:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A4EE28304 for ; Fri, 3 Jun 2016 17:08:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F11C28327; Fri, 3 Jun 2016 17:08:18 +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 C1CDA28304 for ; Fri, 3 Jun 2016 17:08:17 +0000 (UTC) Received: from localhost ([::1]:56783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sa0-0002td-SZ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 13:08:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVM-0007JL-5q for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8sVB-0003Va-CM for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:27 -0400 Received: from resqmta-po-02v.sys.comcast.net ([2001:558:fe16:19:96:114:154:161]:51518) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVB-0003VP-7F for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:17 -0400 Received: from resomta-po-13v.sys.comcast.net ([96.114.154.237]) by comcast with SMTP id 8sUqbQ4FfGhQ08sVAb2YvP; Fri, 03 Jun 2016 17:03:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1464973396; bh=Lr5iKZxqDfMqVnvjPhnH+0wY6cjh8sx0kRDOVW3DiBs=; h=Received:Received:From:To:Subject:Date:Message-Id; b=FHpBlilftC2VRBDHDNVngkexSOs+z2pJ3e4b+2vmTtmubAJZP2n9qmNLopZOk6GBQ heNWRzWitUQuK50d7NacJ1DsF+qAi4Q1Wo6l3bPj1sDILwbtUzFvco4pihmepneq0t z6oRcSR4Hi+CE8thdMgTawarIPANCILAMLC4LwEBv+WHxgupm1b0JlVC4seqtBSQ5K S3LGSPYDbeJ0llF3gNMJYcj8oNltu4LftT+vnToHFOxrwUpQBD8x6eF33trbeJjTQL M49k01rM7hh8gCzBp7qxORqEe7voN9XYIxbrPuqpl4rN2VVPft5A9398GZi3lRuEZO EOQ0kHcL9y5xA== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-13v.sys.comcast.net with comcast id 2H381t00U2fD5rL01H3G5l; Fri, 03 Jun 2016 17:03:16 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 11:03:04 -0600 Message-Id: <1464973388-15821-2-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464973388-15821-1-git-send-email-eblake@redhat.com> References: <1464973388-15821-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:161 Subject: [Qemu-devel] [PATCH 1/5] block: Tighter assertions on bdrv_aligned_preadv() 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: kwolf@redhat.com, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make sure everything is aligned to the passed-in alignment, not just sectors. Also makes sure that the computation of max_nb_sectors later in the function will not divide by zero, by guaranteeing align is at least a sector. Signed-off-by: Eric Blake Reviewed-by: Kevin Wolf --- block/io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index dff4384..81618b9 100644 --- a/block/io.c +++ b/block/io.c @@ -947,8 +947,9 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, int64_t sector_num = offset >> BDRV_SECTOR_BITS; unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS; - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); + assert(align / BDRV_SECTOR_SIZE); + assert((offset & (align - 1)) == 0); + assert((bytes & (align - 1)) == 0); assert(!qiov || bytes == qiov->size); assert((bs->open_flags & BDRV_O_NO_IO) == 0);