From patchwork Thu Nov 9 18:45:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10051631 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 46746601EA for ; Thu, 9 Nov 2017 18:45:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AA362ABC5 for ; Thu, 9 Nov 2017 18:45:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F8602AFD4; Thu, 9 Nov 2017 18:45:41 +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 B18F92ABC5 for ; Thu, 9 Nov 2017 18:45:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753777AbdKISpj (ORCPT ); Thu, 9 Nov 2017 13:45:39 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:55490 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753764AbdKISpg (ORCPT ); Thu, 9 Nov 2017 13:45:36 -0500 Received: by mail-wr0-f196.google.com with SMTP id l8so6468801wre.12 for ; Thu, 09 Nov 2017 10:45:36 -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=643tesap43bwtUEkp/4fKA1aLFqNY8eQGjOzkeCO5kM=; b=QNE1A40kMGnfbEq612FyWL7rUEXx2yEVuMT7P3BcgaDcfeWGdE/qV7V9DaSRcjHrI0 7DiDGMVfwH4B04SRH5wGA1hjf9g2+YFpQxp4vLSfYwcjWhunmYRQ2iKCxfIvSdKtHxII gmTz32VXN35v4+lla6SeXRGiLL9AHeGAEBSc2TyZ0BuYyW+PLusFwTU7XhNAvl39C80l /YlEgGDh56BirkgWj/dcYtU/thlHIYZpT5aqMsvNhj4X9olHsQFyVMTFgydRhQUujUqT EJKu4NEWTdcuP343BTchbhSgH3MgoYYCuNzUTBT0vTzwRkLGgvZgWkx+Hy8uz1WKBEWu AoIw== 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=643tesap43bwtUEkp/4fKA1aLFqNY8eQGjOzkeCO5kM=; b=ODhA46C/qIjWZrrf/qD3vZvJQ8vZxfVr55MSRbb3kM7vcsPxkZFaSWjuTjmJN+Lq8p LcOjIhnpAZAWBB/6/kY0jRCM2dxuHt+kOE3Cz70qYYKF2cytH5cc1OiKeYGs7pKIkS3g FWu9kYvc1LNblLN5Zsfk11s4h+2vumRlWBKjyiM95cmPBSIIXeC/kGh7kqE6HRXIcicU +76/cTP1AmTjD1sqziBQF9hujbvS5MNJX1cSo/9inFesq7/cJuLfH985Hr2Vu660L0H0 DxShui2wXqt8M6c/AQAldzg8Rk4xbmCs5eksKcvaZudLfz/Ef6X37Qb50w4gsv1gTyzh l3iA== X-Gm-Message-State: AJaThX6e4s7b8UnExuba8jWbo8Y+s+QD3MAnRUYjuU9cz/ViFBVrMYE3 PBkJnqOwJSaJDKI3EI0t3sQrLcO7 X-Google-Smtp-Source: ABhQp+RY8IuMvhqx/XS9wgiqtjsdFCgf69jRPVfrlybwmZY5Ae5OQp+pyfOmBSgM8JA2Tx7XXNNeYQ== X-Received: by 10.223.196.174 with SMTP id m43mr1368905wrf.7.1510253135496; Thu, 09 Nov 2017 10:45:35 -0800 (PST) Received: from orange.local (ip-62-245-115-99.net.upcbroadband.cz. [62.245.115.99]) by smtp.gmail.com with ESMTPSA id x52sm3251569wrb.25.2017.11.09.10.45.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 10:45:34 -0800 (PST) From: Ilya Dryomov To: linux-block@vger.kernel.org Cc: Christoph Hellwig , Jens Axboe , Tejun Heo , David Disseldorp Subject: [PATCH 2/2] block: add bdev_read_only() checks to common helpers Date: Thu, 9 Nov 2017 19:45:01 +0100 Message-Id: <1510253101-10291-3-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1510253101-10291-1-git-send-email-idryomov@gmail.com> References: <1510253101-10291-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 --- block/blk-lib.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index f625fda5f095..64fe863ae43a 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -36,6 +36,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; @@ -155,6 +158,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; @@ -232,6 +238,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); @@ -286,6 +295,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);