From patchwork Tue Dec 8 16:28:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 339809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB0EEC4167B for ; Tue, 8 Dec 2020 16:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38E2A23A75 for ; Tue, 8 Dec 2020 16:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730368AbgLHQds (ORCPT ); Tue, 8 Dec 2020 11:33:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730235AbgLHQds (ORCPT ); Tue, 8 Dec 2020 11:33:48 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E119AC061749; Tue, 8 Dec 2020 08:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Hk3FmyWBTPX2vs5vD3kbYiMzUxQSn7PXGcIMyCilJYs=; b=CkahAQx5oWjZpm2CgHg+wqC7e1 1bg1rgf/jlvMwyLut5vfSRxEIAlVFCyHO++A60PldTocwGftMFCcyjQyHkAc/ElwUzkzswVortiFZ LsZ67xbCb2Jq5RuJxaYrM3hjauAgAjRKGKTUGh1CNgDfCVup0tMuQfXlRXeWCGCl5XoJf++lKIQDB H9QB3B2nwIsNWar5Zp926j6b2DTZ+WeJK3FZGHK30mVWtdeiWfaKulhhKpFFu3VzmrvgIj9AJSFYA iy1D8YXe6iCbHl1w1QNoOZs3XSDBG+QlHDwLGyoA5WIwhlrqFvNNqdYn0rxqBgyKhgIKfM6dNN+PL CbBzKHQQ==; Received: from 089144200046.atnat0009.highway.a1.net ([89.144.200.46] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmfv2-00014p-QV; Tue, 08 Dec 2020 16:32:53 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , Oleksii Kurochko , Sagi Grimberg , Mike Snitzer , Ilya Dryomov , Dongsheng Yang , ceph-devel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Ming Lei , Hannes Reinecke Subject: [PATCH 1/6] dm: use bdev_read_only to check if a device is read-only Date: Tue, 8 Dec 2020 17:28:24 +0100 Message-Id: <20201208162829.2424563-2-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208162829.2424563-1-hch@lst.de> References: <20201208162829.2424563-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org dm-thin and dm-cache also work on partitions, so use the proper interface to check if the device is read-only. Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- drivers/md/dm-cache-metadata.c | 2 +- drivers/md/dm-thin-metadata.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c index af6d4f898e4c1d..89a73204dbf47f 100644 --- a/drivers/md/dm-cache-metadata.c +++ b/drivers/md/dm-cache-metadata.c @@ -449,7 +449,7 @@ static int __check_incompat_features(struct cache_disk_superblock *disk_super, /* * Check for read-only metadata to skip the following RDWR checks. */ - if (get_disk_ro(cmd->bdev->bd_disk)) + if (bdev_read_only(cmd->bdev)) return 0; features = le32_to_cpu(disk_super->compat_ro_flags) & ~DM_CACHE_FEATURE_COMPAT_RO_SUPP; diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c index 6ebb2127f3e2e0..e75b20480e460e 100644 --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c @@ -636,7 +636,7 @@ static int __check_incompat_features(struct thin_disk_superblock *disk_super, /* * Check for read-only metadata to skip the following RDWR checks. */ - if (get_disk_ro(pmd->bdev->bd_disk)) + if (bdev_read_only(pmd->bdev)) return 0; features = le32_to_cpu(disk_super->compat_ro_flags) & ~THIN_FEATURE_COMPAT_RO_SUPP; From patchwork Tue Dec 8 16:28:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 340401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF98C4167B for ; Tue, 8 Dec 2020 16:36:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76AE123B00 for ; Tue, 8 Dec 2020 16:36:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730237AbgLHQfy (ORCPT ); Tue, 8 Dec 2020 11:35:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbgLHQfx (ORCPT ); Tue, 8 Dec 2020 11:35:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17BE3C061749; Tue, 8 Dec 2020 08:35:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=FcrfDLXDMA6oQ175CyeC3VNyPVZW/odXwBqmYwf7d6s=; b=NbDUxu3AofBgFFaEc6xSfIhXOw c7uvYPpuX5u9/zeVdKnrjZFeNQaTZKOBIJ7Yp9OXPLhRHUm/XzX46cZdPGlAc4Nfb6S2XsbS/e4x6 tINnMYr9bWpAHYEY7HZ3nZC5wTVtr2zNzLsF+sB0ZBQgdsZBvgrdZ05ZPRzOm7m6CEiLFpkkfvV++ XMuSfHOgIbo0JYdoThDm+vhmMvPg73O1tZkI0nRNRchwezl803XDFGmt4WUEICTMr93kqLKXSAms8 z5gpTzgFAJyIR2cSDudEYXqtXbbSoDJ69nkjyMrq8padi8W8wewDHZiKQ35URTLaEAan/7FGABTap Ljz+GWiQ==; Received: from 089144200046.atnat0009.highway.a1.net ([89.144.200.46] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmfx9-0001Dj-SE; Tue, 08 Dec 2020 16:35:04 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , Oleksii Kurochko , Sagi Grimberg , Mike Snitzer , Ilya Dryomov , Dongsheng Yang , ceph-devel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Ming Lei Subject: [PATCH 2/6] block: remove the NULL bdev check in bdev_read_only Date: Tue, 8 Dec 2020 17:28:25 +0100 Message-Id: <20201208162829.2424563-3-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208162829.2424563-1-hch@lst.de> References: <20201208162829.2424563-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Only a single caller can end up in bdev_read_only, so move the check there. Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei Reviewed-by: Martin K. Petersen --- block/genhd.c | 3 --- fs/super.c | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index b84b8671e6270a..8f2b89d1161813 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1652,11 +1652,8 @@ EXPORT_SYMBOL(set_disk_ro); int bdev_read_only(struct block_device *bdev) { - if (!bdev) - return 0; return bdev->bd_read_only; } - EXPORT_SYMBOL(bdev_read_only); /* diff --git a/fs/super.c b/fs/super.c index 2c6cdea2ab2d9e..5a1f384ffc74f6 100644 --- a/fs/super.c +++ b/fs/super.c @@ -865,7 +865,8 @@ int reconfigure_super(struct fs_context *fc) if (fc->sb_flags_mask & SB_RDONLY) { #ifdef CONFIG_BLOCK - if (!(fc->sb_flags & SB_RDONLY) && bdev_read_only(sb->s_bdev)) + if (!(fc->sb_flags & SB_RDONLY) && sb->s_bdev && + bdev_read_only(sb->s_bdev)) return -EACCES; #endif From patchwork Tue Dec 8 16:28:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 339808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB8BFC4167B for ; Tue, 8 Dec 2020 16:38:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B9CA23B05 for ; Tue, 8 Dec 2020 16:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730361AbgLHQiD (ORCPT ); Tue, 8 Dec 2020 11:38:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728602AbgLHQiD (ORCPT ); Tue, 8 Dec 2020 11:38:03 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07BF9C061749; Tue, 8 Dec 2020 08:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=EBhLdT431wF39exhzTZiipbDTSt+Tm7KUxYzNdjbIMs=; b=DLCeJ9Nb2t/STiB3KylgCsjak5 LDood77yKQEqfZTm4zLEsCmVIyMd1ND36bzWvuToIkpzQ3wuEsq3KyaHCDfMP7i94Wj7JEfKAZKLH IoQp5PgJ1eO5UAWw5ZviRO5Zr+CGjmYK0FgwEi+mvX17T9ZnKOO/ghCAw08Iu3Z1NNMQnmWmE05K3 URr7/4HBJPTfFsq4ctwQCa3CrCCMYNQ9ArDtVFoe5FCCMF2GZMgapb//ZHz/dJ/ZlJnZB3Z3e5dwQ ZrFEKZibGWXVPK/d6+d09nxS8YZ1V6tOdpzK+4MbBMbgYM1KfRzqKnIlYFOBpjdo/BmgPg/nVMi/f TV4ZkloA==; Received: from 089144200046.atnat0009.highway.a1.net ([89.144.200.46] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmfzH-0001Nq-0q; Tue, 08 Dec 2020 16:37:15 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , Oleksii Kurochko , Sagi Grimberg , Mike Snitzer , Ilya Dryomov , Dongsheng Yang , ceph-devel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Ming Lei , Hannes Reinecke Subject: [PATCH 3/6] block: add a hard-readonly flag to struct gendisk Date: Tue, 8 Dec 2020 17:28:26 +0100 Message-Id: <20201208162829.2424563-4-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208162829.2424563-1-hch@lst.de> References: <20201208162829.2424563-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Commit 20bd1d026aac ("scsi: sd: Keep disk read-only when re-reading partition") addressed a long-standing problem with user read-only policy being overridden as a result of a device-initiated revalidate. The commit has since been reverted due to a regression that left some USB devices read-only indefinitely. To fix the underlying problems with revalidate we need to keep track of hardware state and user policy separately. The gendisk has been updated to reflect the current hardware state set by the device driver. This is done to allow returning the device to the hardware state once the user clears the BLKROSET flag. The resulting semantics are as follows: - If BLKROSET sets a given partition read-only, that partition will remain read-only even if the underlying storage stack initiates a revalidate. However, the BLKRRPART ioctl will cause the partition table to be dropped and any user policy on partitions will be lost. - If BLKROSET has not been set, both the whole disk device and any partitions will reflect the current write-protect state of the underlying device. Based on a patch from Martin K. Petersen . Reported-by: Oleksii Kurochko Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201221 Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- block/blk-core.c | 4 +--- block/genhd.c | 33 +++++++++++++++++++-------------- block/partitions/core.c | 3 +-- include/linux/genhd.h | 6 ++++-- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 96e5fcd7f071b6..9123c2c86414ae 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -693,9 +693,7 @@ static inline bool should_fail_request(struct block_device *part, static inline bool bio_check_ro(struct bio *bio, struct block_device *part) { - const int op = bio_op(bio); - - if (part->bd_read_only && op_is_write(op)) { + if (op_is_write(bio_op(bio)) && bdev_read_only(part)) { char b[BDEVNAME_SIZE]; if (op_is_flush(bio->bi_opf) && !bio_sectors(bio)) diff --git a/block/genhd.c b/block/genhd.c index 8f2b89d1161813..d9f989c1514123 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1632,27 +1632,32 @@ static void set_disk_ro_uevent(struct gendisk *gd, int ro) kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp); } -void set_disk_ro(struct gendisk *disk, int flag) +/** + * set_disk_ro - set a gendisk read-only + * @disk: gendisk to operate on + * @ready_only: %true to set the disk read-only, %false set the disk read/write + * + * This function is used to indicate whether a given disk device should have its + * read-only flag set. set_disk_ro() is typically used by device drivers to + * indicate whether the underlying physical device is write-protected. + */ +void set_disk_ro(struct gendisk *disk, bool read_only) { - struct disk_part_iter piter; - struct block_device *part; - - if (disk->part0->bd_read_only != flag) { - set_disk_ro_uevent(disk, flag); - disk->part0->bd_read_only = flag; + if (read_only) { + if (test_and_set_bit(GD_READ_ONLY, &disk->state)) + return; + } else { + if (!test_and_clear_bit(GD_READ_ONLY, &disk->state)) + return; } - - disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY); - while ((part = disk_part_iter_next(&piter))) - part->bd_read_only = flag; - disk_part_iter_exit(&piter); + set_disk_ro_uevent(disk, read_only); } - EXPORT_SYMBOL(set_disk_ro); int bdev_read_only(struct block_device *bdev) { - return bdev->bd_read_only; + return bdev->bd_read_only || + test_bit(GD_READ_ONLY, &bdev->bd_disk->state); } EXPORT_SYMBOL(bdev_read_only); diff --git a/block/partitions/core.c b/block/partitions/core.c index deca253583bd3f..5a9633183343c0 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -194,7 +194,7 @@ static ssize_t part_start_show(struct device *dev, static ssize_t part_ro_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", dev_to_bdev(dev)->bd_read_only); + return sprintf(buf, "%d\n", bdev_read_only(dev_to_bdev(dev))); } static ssize_t part_alignment_offset_show(struct device *dev, @@ -360,7 +360,6 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, bdev->bd_start_sect = start; bdev_set_nr_sectors(bdev, len); - bdev->bd_read_only = get_disk_ro(disk); if (info) { err = -ENOMEM; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 809aaa32d53cba..a62ccbfac54b48 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -163,6 +163,7 @@ struct gendisk { int flags; unsigned long state; #define GD_NEED_PART_SCAN 0 +#define GD_READ_ONLY 1 struct kobject *slave_dir; struct timer_rand_state *random; @@ -249,11 +250,12 @@ static inline void add_disk_no_queue_reg(struct gendisk *disk) extern void del_gendisk(struct gendisk *gp); extern struct block_device *bdget_disk(struct gendisk *disk, int partno); -extern void set_disk_ro(struct gendisk *disk, int flag); +void set_disk_ro(struct gendisk *disk, bool read_only); static inline int get_disk_ro(struct gendisk *disk) { - return disk->part0->bd_read_only; + return disk->part0->bd_read_only || + test_bit(GD_READ_ONLY, &disk->state); } extern void disk_block_events(struct gendisk *disk); From patchwork Tue Dec 8 16:28:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 340400 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0575FC1B0D8 for ; Tue, 8 Dec 2020 16:38:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D12FE233CF for ; Tue, 8 Dec 2020 16:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730381AbgLHQiE (ORCPT ); Tue, 8 Dec 2020 11:38:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728602AbgLHQiE (ORCPT ); Tue, 8 Dec 2020 11:38:04 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62DD4C0613D6; Tue, 8 Dec 2020 08:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=elpIgX+cTsb2dqzbwyG4mhhxmB2j6M8UmSJFUU3cmP0=; b=ku/Ut2+yV4kFeNDDzU3/Gz0gty xKg3I1ZYaBfKuo8vMnrV/wa+5sdvtI2PqU0AYrGf3mU7w+pj9DFVIZWt3CAk70dXi2BwusOpNCG97 hbpVaV3f1thTtnt571Ucm6mf+53WHPZHNQlOe9gwFtSBdD8cPPbv+dNbWqjk/vDXIyfcN/+wKNl42 Vjm6YaZj9hVudn2S1PgeVPwyfE5mcCz1aSKFDfPTB0Z8Pu7jeRdKLwRKeGF80Or+HvuJkf79iNwd5 fHIcakd96svG/ThN9KKezO5QqtECF8R9/HMTrFCyX+7HJ+Wg13U+eZPPrQQeISP6RjKmr4k+nKHay bWj2U4Tg==; Received: from [2001:4bb8:188:f36:7a30:8a2b:aea3:231b] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmfzI-0001Nu-He; Tue, 08 Dec 2020 16:37:16 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , Oleksii Kurochko , Sagi Grimberg , Mike Snitzer , Ilya Dryomov , Dongsheng Yang , ceph-devel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 4/6] block: propagate BLKROSET on the whole device to all partitions Date: Tue, 8 Dec 2020 17:28:27 +0100 Message-Id: <20201208162829.2424563-5-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208162829.2424563-1-hch@lst.de> References: <20201208162829.2424563-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Change the policy so that a BLKROSET on the whole device also affects partitions. To quote Martin K. Petersen: It's very common for database folks to twiddle the read-only state of block devices and partitions. I know that our users will find it very counter-intuitive that setting /dev/sda read-only won't prevent writes to /dev/sda1. The existing behavior is inconsistent in the sense that doing: # blockdev --setro /dev/sda # echo foo > /dev/sda1 permits writes. But: # blockdev --setro /dev/sda # echo foo > /dev/sda1 doesn't. And a subsequent: # blockdev --setrw /dev/sda # echo foo > /dev/sda1 doesn't work either since sda1's read-only policy has been inherited from the whole-disk device. You need to do: # blockdev --rereadpt after setting the whole-disk device rw to effectuate the same change on the partitions, otherwise they are stuck being read-only indefinitely. However, setting the read-only policy on a partition does *not* require the revalidate step. As a matter of fact, doing the revalidate will blow away the policy setting you just made. So the user needs to take different actions depending on whether they are trying to read-protect a whole-disk device or a partition. Despite using the same ioctl. That is really confusing. I have lost count how many times our customers have had data clobbered because of ambiguity of the existing whole-disk device policy. The current behavior violates the principle of least surprise by letting the user think they write protected the whole disk when they actually didn't. Suggested-by: Martin K. Petersen Signed-off-by: Christoph Hellwig Reviewed-by: Martin K. Petersen --- block/genhd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index d9f989c1514123..6e51ecb9280aca 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1656,8 +1656,7 @@ EXPORT_SYMBOL(set_disk_ro); int bdev_read_only(struct block_device *bdev) { - return bdev->bd_read_only || - test_bit(GD_READ_ONLY, &bdev->bd_disk->state); + return bdev->bd_read_only || get_disk_ro(bdev->bd_disk); } EXPORT_SYMBOL(bdev_read_only); From patchwork Tue Dec 8 16:28:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 339807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D78FC2BB40 for ; Tue, 8 Dec 2020 16:38:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D5C6233CF for ; Tue, 8 Dec 2020 16:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730394AbgLHQiG (ORCPT ); Tue, 8 Dec 2020 11:38:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728602AbgLHQiF (ORCPT ); Tue, 8 Dec 2020 11:38:05 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A466EC061793; Tue, 8 Dec 2020 08:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=v4slHGDTT2Sku92ts8Y9y7CGrHZhu+VFefigrYM6LO8=; b=q8qsh046BojX4/WMceI+MqtOU5 kLan7bFMfpJkXWMYs0KHbin2QITMe7hvMpL5IB4YpLG+ju8a9elK0PxytX9qAWOxvZk+E3SJ/tBpw kvfT5n68TmQAp2ClzU4C0aI7yM18Bgit0RecaUOolGKGFJx7q9osA4t1ylQXw+84hUG9XVkA6VJp1 14lHzPo2Zizkg2YEdlBXSRxkqHBswHz3FbXJXBtbWNC//xa6J8n+3bmwhUfnoequauSgr+qv5Lr2H A7s9vR2xrTSVO0X6Na7OyLPpdTdp+KeqvPd87m+ozGkKsQltHOFjgjwU78jCZGmirCDEW+hj1+4LI RgtEWAyA==; Received: from [2001:4bb8:188:f36:7a30:8a2b:aea3:231b] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmfzJ-0001O6-Oc; Tue, 08 Dec 2020 16:37:18 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , Oleksii Kurochko , Sagi Grimberg , Mike Snitzer , Ilya Dryomov , Dongsheng Yang , ceph-devel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Hannes Reinecke Subject: [PATCH 5/6] rbd: remove the ->set_read_only method Date: Tue, 8 Dec 2020 17:28:28 +0100 Message-Id: <20201208162829.2424563-6-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208162829.2424563-1-hch@lst.de> References: <20201208162829.2424563-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Now that the hardware read-only state can't be changed by the BLKROSET ioctl, the code in this method is not required anymore. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Acked-by: Ilya Dryomov Reviewed-by: Martin K. Petersen Reviewed-by: Ming Lei --- drivers/block/rbd.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2ed79b09439a82..2c64ca15ca079f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -692,29 +692,10 @@ static void rbd_release(struct gendisk *disk, fmode_t mode) put_device(&rbd_dev->dev); } -static int rbd_set_read_only(struct block_device *bdev, bool ro) -{ - struct rbd_device *rbd_dev = bdev->bd_disk->private_data; - - /* - * Both images mapped read-only and snapshots can't be marked - * read-write. - */ - if (!ro) { - if (rbd_is_ro(rbd_dev)) - return -EROFS; - - rbd_assert(!rbd_is_snap(rbd_dev)); - } - - return 0; -} - static const struct block_device_operations rbd_bd_ops = { .owner = THIS_MODULE, .open = rbd_open, .release = rbd_release, - .set_read_only = rbd_set_read_only, }; /* From patchwork Tue Dec 8 16:28:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 340399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62AA9C2BB9A for ; Tue, 8 Dec 2020 16:38:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DEBF23AFA for ; Tue, 8 Dec 2020 16:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730406AbgLHQiG (ORCPT ); Tue, 8 Dec 2020 11:38:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730403AbgLHQiG (ORCPT ); Tue, 8 Dec 2020 11:38:06 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B57AC061794; Tue, 8 Dec 2020 08:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=mDWnaDevg6j/LIqbxuNXDRQmS3LZ4FlK87nsZVHjQJ8=; b=JFMbcCImgU0rQUC46Gh5jSfyXr R7nm/tGTSpS/6kdC5nXL0AcPvDP40nPp/xnt3K/t0jcNxJSy2Q00sNapIdBCx2b17aOaWfL2viSLb 47tiNb+yd8CJy2aC1M+1ZWgg+0TQiG2VyKp7kdrO9eVD0TftLKPaM1GNODR7R53T8XiaJdQlzVdse sngMuhgBgn9AbqpL+X1QiU78oC1SF/J7r7DPoKLZyhopVWOMTBQL/1mCBUouLBSaa4r7jorYr9uoa AxkxjKPnp82d7a6vH8VlGv8HCE+DtQGF9GPk+/kycHqR3cnS7P4KER/8iMbofhUXyiu64iqu9ITK1 IZNixDFg==; Received: from [2001:4bb8:188:f36:7a30:8a2b:aea3:231b] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmfzK-0001OD-V7; Tue, 08 Dec 2020 16:37:19 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K . Petersen" , Oleksii Kurochko , Sagi Grimberg , Mike Snitzer , Ilya Dryomov , Dongsheng Yang , ceph-devel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Keith Busch Subject: [PATCH 6/6] nvme: allow revalidate to set a namespace read-only Date: Tue, 8 Dec 2020 17:28:29 +0100 Message-Id: <20201208162829.2424563-7-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201208162829.2424563-1-hch@lst.de> References: <20201208162829.2424563-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Unconditionally call set_disk_ro now that it only updates the hardware state. This allows to properly set up the Linux devices read-only when the controller turns a previously writable namespace read-only. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Martin K. Petersen Reviewed-by: Ming Lei --- drivers/nvme/host/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index ce1b6151944131..3a0557ccc9fc5d 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2114,9 +2114,8 @@ static void nvme_update_disk_info(struct gendisk *disk, nvme_config_discard(disk, ns); nvme_config_write_zeroes(disk, ns); - if ((id->nsattr & NVME_NS_ATTR_RO) || - test_bit(NVME_NS_FORCE_RO, &ns->flags)) - set_disk_ro(disk, true); + set_disk_ro(disk, (id->nsattr & NVME_NS_ATTR_RO) || + test_bit(NVME_NS_FORCE_RO, &ns->flags)); } static inline bool nvme_first_scan(struct gendisk *disk)