From patchwork Mon Jun 13 18:56:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9173869 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 2F0136044F for ; Mon, 13 Jun 2016 18:57:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86E8027AC2 for ; Mon, 13 Jun 2016 18:57:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BD1127C0C; Mon, 13 Jun 2016 18:57:34 +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 1FCDB27AC2 for ; Mon, 13 Jun 2016 18:57:34 +0000 (UTC) Received: from localhost ([::1]:58702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCX3F-0003sY-9H for patchwork-qemu-devel@patchwork.kernel.org; Mon, 13 Jun 2016 14:57:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCX2a-0003cz-SO for qemu-devel@nongnu.org; Mon, 13 Jun 2016 14:57:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCX2Q-0004NP-W6 for qemu-devel@nongnu.org; Mon, 13 Jun 2016 14:56:52 -0400 Received: from resqmta-po-08v.sys.comcast.net ([2001:558:fe16:19:96:114:154:167]:47456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCX2Q-0004N4-RO for qemu-devel@nongnu.org; Mon, 13 Jun 2016 14:56:42 -0400 Received: from resomta-po-15v.sys.comcast.net ([96.114.154.239]) by resqmta-po-08v.sys.comcast.net with SMTP id CX1LbSGjHB1Y8CX2QbDchS; Mon, 13 Jun 2016 18:56:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1465844202; bh=TRKV96aY64GhXunIy9prre3y6EWeIZ+QTjiCRvy7qk8=; h=Received:Received:From:To:Subject:Date:Message-Id; b=CborTJpXX/JJecXd2eXkDK0WWUcFJAXpKmWUitBcj4KtVcOu8ITDQeT9f3kP3yrXA voZQvRBHAbDNwpzBvsAzCMkqAgFsbaVWudYd9AZbQTByxumGqCDFRpaxKB4Ww9yHHo TkHVMoWEwIysGFH5HhuG46tMx6dOz1/N81SQKamVW4UIR5YEDzZHSEd+tnC2qNsyfz 4i+OQ8WnWc2OfgXtt8JirwrVf1NUrGUPJpi6LGBkqBeCDec8KmqmKFC8+wZhTAayJf w+LAZqwmC9nlSPtGwAmHuWQ7Ng+4n9jiLHIiao1AFmFN5w15Z4q0fCstBm4r4q2t9K tzNX6EzLusaQg== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-15v.sys.comcast.net with comcast id 6Jwb1t00H2fD5rL01JwhJU; Mon, 13 Jun 2016 18:56:42 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 13 Jun 2016 12:56:35 -0600 Message-Id: <1465844195-25911-3-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465844195-25911-1-git-send-email-eblake@redhat.com> References: <1465844195-25911-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:167 Subject: [Qemu-devel] [PATCH v2 2/2] block: Assert that flags are in range 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, famz@redhat.com, Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a new BDRV_REQ_MASK constant, and use it to make sure that caller flags are always valid. Tested with 'make check' and with qemu-iotests on both '-raw' and '-qcow2'; the only failure turned up was fixed in the previous commit. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block.h | 3 +++ block/io.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index a158575..733a8ec 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -65,6 +65,9 @@ typedef enum { BDRV_REQ_MAY_UNMAP = 0x4, BDRV_REQ_NO_SERIALISING = 0x8, BDRV_REQ_FUA = 0x10, + + /* Mask of valid flags */ + BDRV_REQ_MASK = 0x1f, } BdrvRequestFlags; typedef struct BlockSizes { diff --git a/block/io.c b/block/io.c index d504443..b4f1235 100644 --- a/block/io.c +++ b/block/io.c @@ -802,6 +802,8 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, int64_t sector_num; unsigned int nb_sectors; + assert(!(flags & ~BDRV_REQ_MASK)); + if (drv->bdrv_co_preadv) { return drv->bdrv_co_preadv(bs, offset, bytes, qiov, flags); } @@ -841,6 +843,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs, unsigned int nb_sectors; int ret; + assert(!(flags & ~BDRV_REQ_MASK)); + if (drv->bdrv_co_pwritev) { ret = drv->bdrv_co_pwritev(bs, offset, bytes, qiov, flags & bs->supported_write_flags); @@ -967,6 +971,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, assert(!qiov || bytes == qiov->size); assert((bs->open_flags & BDRV_O_NO_IO) == 0); + assert(!(flags & ~BDRV_REQ_MASK)); /* Handle Copy on Read and associated serialisation */ if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1246,6 +1251,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, assert(!qiov || bytes == qiov->size); assert((bs->open_flags & BDRV_O_NO_IO) == 0); + assert(!(flags & ~BDRV_REQ_MASK)); waited = wait_serialising_requests(req); assert(!waited || !req->serialising);