From patchwork Thu Jan 11 13:09:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10157985 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 63F38605F8 for ; Thu, 11 Jan 2018 13:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3124928792 for ; Thu, 11 Jan 2018 13:09:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FDA828796; Thu, 11 Jan 2018 13:09:26 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBA6F287EF for ; Thu, 11 Jan 2018 13:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752317AbeAKNJX (ORCPT ); Thu, 11 Jan 2018 08:09:23 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35975 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754498AbeAKNJW (ORCPT ); Thu, 11 Jan 2018 08:09:22 -0500 Received: by mail-wm0-f67.google.com with SMTP id b76so5389944wmg.1 for ; Thu, 11 Jan 2018 05:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=t6M6sWIEPBcyjnf/Av1DgBCWuko3U8lEnQRr8An8X/U=; b=atjtQUJv0ZWfvJw3Hy68sYRcjXigfle4hVElKPjIeCngYGHF6mmlqvr29HhbT0tSRP ouxygX7f7AKa6OxIKfDlOYesSJm99d9QksHp2CSw1Fi1nXgE/AhE33Z6eACFhbHM2gQF dAnpgCcb1AVRcJ1IXdNCdbK8N/mUA/zHJiq5L62Rt+wnXxUXu7Fnwm9B1sLoX7NEtGaO hTIX28ESWTLr0BGTkgnDPnbhaHuMw91MicTC6zij2P0FOf7BfouYNdh7IRF5s4LMTj7O Cb+lKYEPglhkXRIx7s0vhvnMxZvVq6lXDqROjS2/EQ42/NTEB7z/ysYU91x5ZLWf6cAp AtUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t6M6sWIEPBcyjnf/Av1DgBCWuko3U8lEnQRr8An8X/U=; b=iP6st1eIcQ8h8UbZoaaREcX/WOwogAyIxZP4vh5Rv9HOlq0R67hj0T6Rpjk+0zQhVI zLbxzMUY8eZ7tfhs1qWlIsrPk1j0sKE7a7L4Go0NLCSfZsaO8pu8csQqnqRuaL2IiNbY 90NMSSWeZLlul+UapzCnhxYXqIVHA+sZWHyKkKaaJ7HOhEPvz+7sAwqa8IZyTvkpMAo/ euP5KBlnh4S1ebjF/xElFM+R3BTdVdnPDlttaeBNxhH9Q8E2c1XNWkht1Qpi3THuzqNr tsMakvHYGMqnaYNvXArlZW0+V9baGWBBLP80NTKLjB/gzPJy6qvlxjGdDifuxtn17L9i Ppaw== X-Gm-Message-State: AKwxytdBCTPq/pn9SlMZwxx+YVSQ4Esxziw2rO56HvthcrJacaHBEOsC ADMVeajhMgabV1Kg14H1WgSS2p9N X-Google-Smtp-Source: ACJfBovcJxXyU8DGukBricbEZBXinKVcOgpEvjSBcj9MKLZC0JIZb9PzJCL5OSDex03sMVmF3WkrZg== X-Received: by 10.28.6.6 with SMTP id 6mr1119475wmg.8.1515676160866; Thu, 11 Jan 2018 05:09:20 -0800 (PST) Received: from orange.brq.redhat.com. (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id r3sm552960wmg.31.2018.01.11.05.09.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jan 2018 05:09:20 -0800 (PST) From: Ilya Dryomov To: linux-block@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Tejun Heo , David Disseldorp , Sagi Grimberg Subject: [PATCH v3 2/2] block: add bdev_read_only() checks to common helpers Date: Thu, 11 Jan 2018 14:09:12 +0100 Message-Id: <1515676152-18476-3-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1515676152-18476-1-git-send-email-idryomov@gmail.com> References: <1515676152-18476-1-git-send-email-idryomov@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similar to blkdev_write_iter(), return -EPERM if the partition is read-only. This covers ioctl(), fallocate() and most in-kernel users but isn't meant to be exhaustive -- everything else will be caught in generic_make_request_checks(), fail with -EIO and can be fixed later. Signed-off-by: Ilya Dryomov Reviewed-by: Sagi Grimberg --- block/blk-lib.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index 2bc544ce3d2e..a676084d4740 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -37,6 +37,9 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, if (!q) return -ENXIO; + if (bdev_read_only(bdev)) + return -EPERM; + if (flags & BLKDEV_DISCARD_SECURE) { if (!blk_queue_secure_erase(q)) return -EOPNOTSUPP; @@ -156,6 +159,9 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector, if (!q) return -ENXIO; + if (bdev_read_only(bdev)) + return -EPERM; + bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; if ((sector | nr_sects) & bs_mask) return -EINVAL; @@ -233,6 +239,9 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, if (!q) return -ENXIO; + if (bdev_read_only(bdev)) + return -EPERM; + /* Ensure that max_write_zeroes_sectors doesn't overflow bi_size */ max_write_zeroes_sectors = bdev_write_zeroes_sectors(bdev); @@ -287,6 +296,9 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, if (!q) return -ENXIO; + if (bdev_read_only(bdev)) + return -EPERM; + while (nr_sects != 0) { bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), gfp_mask);