From: Christoph Hellwig <hch@lst.de> To: Jens Axboe <axboe@kernel.dk> Cc: Ilya Dryomov <idryomov@gmail.com>, Song Liu <song@kernel.org>, Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>, Stefan Haberland <sth@linux.ibm.com>, Jan Hoeppner <hoeppner@linux.ibm.com>, linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org, linux-mtd@lists.infradead.org, linux-s390@vger.kernel.org Subject: [PATCH 05/10] md: implement ->set_read_only to hook into BLKROSET processing Date: Tue, 3 Nov 2020 11:00:13 +0100 [thread overview] Message-ID: <20201103100018.683694-6-hch@lst.de> (raw) In-Reply-To: <20201103100018.683694-1-hch@lst.de> Implement the ->set_read_only method instead of parsing the actual ioctl command. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/md/md.c | 62 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 98bac4f304ae26..96d31336ad43fe 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7480,7 +7480,6 @@ static inline bool md_ioctl_valid(unsigned int cmd) { switch (cmd) { case ADD_NEW_DISK: - case BLKROSET: case GET_ARRAY_INFO: case GET_BITMAP_FILE: case GET_DISK_INFO: @@ -7507,7 +7506,6 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, int err = 0; void __user *argp = (void __user *)arg; struct mddev *mddev = NULL; - int ro; bool did_set_md_closing = false; if (!md_ioctl_valid(cmd)) @@ -7687,35 +7685,6 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, goto unlock; } break; - - case BLKROSET: - if (get_user(ro, (int __user *)(arg))) { - err = -EFAULT; - goto unlock; - } - err = -EINVAL; - - /* if the bdev is going readonly the value of mddev->ro - * does not matter, no writes are coming - */ - if (ro) - goto unlock; - - /* are we are already prepared for writes? */ - if (mddev->ro != 1) - goto unlock; - - /* transitioning to readauto need only happen for - * arrays that call md_write_start - */ - if (mddev->pers) { - err = restart_array(mddev); - if (err == 0) { - mddev->ro = 2; - set_disk_ro(mddev->gendisk, 0); - } - } - goto unlock; } /* @@ -7809,6 +7778,36 @@ static int md_compat_ioctl(struct block_device *bdev, fmode_t mode, } #endif /* CONFIG_COMPAT */ +static int md_set_read_only(struct block_device *bdev, bool ro) +{ + struct mddev *mddev = bdev->bd_disk->private_data; + int err; + + err = mddev_lock(mddev); + if (err) + return err; + + if (!mddev->raid_disks && !mddev->external) { + err = -ENODEV; + goto out_unlock; + } + + /* + * Transitioning to read-auto need only happen for arrays that call + * md_write_start and which are not ready for writes yet. + */ + if (!ro && mddev->ro == 1 && mddev->pers) { + err = restart_array(mddev); + if (err) + goto out_unlock; + mddev->ro = 2; + } + +out_unlock: + mddev_unlock(mddev); + return err; +} + static int md_open(struct block_device *bdev, fmode_t mode) { /* @@ -7886,6 +7885,7 @@ const struct block_device_operations md_fops = #endif .getgeo = md_getgeo, .check_events = md_check_events, + .set_read_only = md_set_read_only, }; static int md_thread(void *arg) -- 2.28.0
WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de> To: Jens Axboe <axboe@kernel.dk> Cc: linux-raid@vger.kernel.org, Jan Hoeppner <hoeppner@linux.ibm.com>, Vignesh Raghavendra <vigneshr@ti.com>, linux-s390@vger.kernel.org, Richard Weinberger <richard@nod.at>, linux-block@vger.kernel.org, Song Liu <song@kernel.org>, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, Stefan Haberland <sth@linux.ibm.com>, Miquel Raynal <miquel.raynal@bootlin.com>, Ilya Dryomov <idryomov@gmail.com>, ceph-devel@vger.kernel.org Subject: [PATCH 05/10] md: implement ->set_read_only to hook into BLKROSET processing Date: Tue, 3 Nov 2020 11:00:13 +0100 [thread overview] Message-ID: <20201103100018.683694-6-hch@lst.de> (raw) In-Reply-To: <20201103100018.683694-1-hch@lst.de> Implement the ->set_read_only method instead of parsing the actual ioctl command. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/md/md.c | 62 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 98bac4f304ae26..96d31336ad43fe 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7480,7 +7480,6 @@ static inline bool md_ioctl_valid(unsigned int cmd) { switch (cmd) { case ADD_NEW_DISK: - case BLKROSET: case GET_ARRAY_INFO: case GET_BITMAP_FILE: case GET_DISK_INFO: @@ -7507,7 +7506,6 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, int err = 0; void __user *argp = (void __user *)arg; struct mddev *mddev = NULL; - int ro; bool did_set_md_closing = false; if (!md_ioctl_valid(cmd)) @@ -7687,35 +7685,6 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, goto unlock; } break; - - case BLKROSET: - if (get_user(ro, (int __user *)(arg))) { - err = -EFAULT; - goto unlock; - } - err = -EINVAL; - - /* if the bdev is going readonly the value of mddev->ro - * does not matter, no writes are coming - */ - if (ro) - goto unlock; - - /* are we are already prepared for writes? */ - if (mddev->ro != 1) - goto unlock; - - /* transitioning to readauto need only happen for - * arrays that call md_write_start - */ - if (mddev->pers) { - err = restart_array(mddev); - if (err == 0) { - mddev->ro = 2; - set_disk_ro(mddev->gendisk, 0); - } - } - goto unlock; } /* @@ -7809,6 +7778,36 @@ static int md_compat_ioctl(struct block_device *bdev, fmode_t mode, } #endif /* CONFIG_COMPAT */ +static int md_set_read_only(struct block_device *bdev, bool ro) +{ + struct mddev *mddev = bdev->bd_disk->private_data; + int err; + + err = mddev_lock(mddev); + if (err) + return err; + + if (!mddev->raid_disks && !mddev->external) { + err = -ENODEV; + goto out_unlock; + } + + /* + * Transitioning to read-auto need only happen for arrays that call + * md_write_start and which are not ready for writes yet. + */ + if (!ro && mddev->ro == 1 && mddev->pers) { + err = restart_array(mddev); + if (err) + goto out_unlock; + mddev->ro = 2; + } + +out_unlock: + mddev_unlock(mddev); + return err; +} + static int md_open(struct block_device *bdev, fmode_t mode) { /* @@ -7886,6 +7885,7 @@ const struct block_device_operations md_fops = #endif .getgeo = md_getgeo, .check_events = md_check_events, + .set_read_only = md_set_read_only, }; static int md_thread(void *arg) -- 2.28.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2020-11-03 10:13 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-03 10:00 block ioctl cleanups v2 Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 01/10] mtd_blkdevs: don't override BLKFLSBUF Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 02/10] block: don't call into the driver for BLKFLSBUF Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 03/10] block: add a new set_read_only method Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 04/10] rbd: implement ->set_read_only to hook into BLKROSET processing Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig [this message] 2020-11-03 10:00 ` [PATCH 05/10] md: " Christoph Hellwig 2020-11-06 0:59 ` Song Liu 2020-11-06 0:59 ` Song Liu 2020-11-03 10:00 ` [PATCH 06/10] dasd: " Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-05 20:56 ` Stefan Haberland 2020-11-05 20:56 ` Stefan Haberland 2020-11-06 14:02 ` Christoph Hellwig 2020-11-06 14:02 ` Christoph Hellwig 2020-11-06 16:08 ` Stefan Haberland 2020-11-06 16:08 ` Stefan Haberland 2020-11-03 10:00 ` [PATCH 07/10] block: don't call into the driver for BLKROSET Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 08/10] loop: use set_disk_ro Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 09/10] block: remove set_device_ro Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-03 10:00 ` [PATCH 10/10] block: remove __blkdev_driver_ioctl Christoph Hellwig 2020-11-03 10:00 ` Christoph Hellwig 2020-11-11 7:58 ` block ioctl cleanups v2 Christoph Hellwig 2020-11-11 7:58 ` Christoph Hellwig 2020-11-11 16:13 ` Jens Axboe 2020-11-11 16:13 ` Jens Axboe 2020-11-11 16:20 ` Christoph Hellwig 2020-11-11 16:20 ` Christoph Hellwig 2020-11-11 16:23 ` Jens Axboe 2020-11-11 16:23 ` Jens Axboe
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201103100018.683694-6-hch@lst.de \ --to=hch@lst.de \ --cc=axboe@kernel.dk \ --cc=ceph-devel@vger.kernel.org \ --cc=hoeppner@linux.ibm.com \ --cc=idryomov@gmail.com \ --cc=linux-bcache@vger.kernel.org \ --cc=linux-block@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=linux-raid@vger.kernel.org \ --cc=linux-s390@vger.kernel.org \ --cc=miquel.raynal@bootlin.com \ --cc=richard@nod.at \ --cc=song@kernel.org \ --cc=sth@linux.ibm.com \ --cc=vigneshr@ti.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.