From patchwork Wed Jan 10 16:18:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10155541 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 1115260231 for ; Wed, 10 Jan 2018 16:19:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 038682854A for ; Wed, 10 Jan 2018 16:19:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBC5228558; Wed, 10 Jan 2018 16:19:11 +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 8BFE528555 for ; Wed, 10 Jan 2018 16:19:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965934AbeAJQTL (ORCPT ); Wed, 10 Jan 2018 11:19:11 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33723 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965935AbeAJQTJ (ORCPT ); Wed, 10 Jan 2018 11:19:09 -0500 Received: by mail-wm0-f65.google.com with SMTP id 123so6050761wme.0 for ; Wed, 10 Jan 2018 08:19:09 -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=Cy+7EbmekmmkNadyQ7lXmAuvVfj7dh02Hw7/bLlb+Pe0Z2GgXAQB4MK6teTUoRZRTN hFWoaqJoKp8pAGyQt6jQzQnQ4rCghpnAfmY3S/JZVlh7Vu/pfAy5LeOmcvlNZOaG2oBf SKiUBzN264BmtblxvhaPaNrSl7ZXN6yHrTkLTPpVfPloWAD7+hMG2jBnVqntvNvl426R xhmdMfHHk15h0PrRsXxpmDq06rjwe42zhqmT9GXy9BV6f5q78EMhZjlZJuQUb9Yi06do K5oGMRZTaj48TSQ+j/VcZJ1SP43meyF61Y7UWCStX8UnIqGBBO4AYsLNMBhPM6+Ewfvx NYNg== 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=cMX4c5kPsMZplqwnqiYfqmldeNFXo86peKD30qHRNtKieSeUNHw1TB7utUeKTlN0ug iGMWdMQwrALb3Gz4We3eA3vSZCeYFAe5d5huOmgHQY4x7u00jw1qA5Wa5cJ5rG4C9wkV 2ro9CblInofFlebJsxdb9PGN87eVr+r8fqa6MVTl8Iv2+1hs09pVizwFCwrAk23/hAJY 4t3qW4xmHvvu763ug9e5huu4c5MHbt+7BNJQdPaufPHK2gS3zmMYL6Di/eJ4+NLuUM2b VFZhCJEJOrvDbriLTi23qsC6LmbFAjiYosPJrAuprMpdahiinDbV/iOzIRxsqLzGSmQb Y7sw== X-Gm-Message-State: AKGB3mIVP9bdT0KgplhA3IKI9ZdgLWLerSwq52+lqAJa8U0KInKeIh16 ug0vu4U+7Hb6bx3NtBxLo5jUSm/R X-Google-Smtp-Source: ACJfBosMWTP7b6/DFpYDUWC9izb+b6kMXdnUDwPODMnb2kIfVKYWYDHTRhnEKi+dKbEY3YalCdM2OQ== X-Received: by 10.28.62.202 with SMTP id l193mr14075170wma.73.1515601148373; Wed, 10 Jan 2018 08:19:08 -0800 (PST) Received: from orange.redhat.com ([213.175.37.12]) by smtp.gmail.com with ESMTPSA id r68sm20250487wmd.47.2018.01.10.08.19.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 08:19:06 -0800 (PST) From: Ilya Dryomov To: linux-block@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Tejun Heo , David Disseldorp , Sagi Grimberg Subject: [PATCH v2 2/2] block: add bdev_read_only() checks to common helpers Date: Wed, 10 Jan 2018 17:18:38 +0100 Message-Id: <1515601118-23192-3-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1515601118-23192-1-git-send-email-idryomov@gmail.com> References: <1515601118-23192-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 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);