diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2018-01-11 08:09:12 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-01-18 14:57:19 -0500 |
commit | a13553c777375009584741e7d9982e775c4b0744 (patch) | |
tree | 2bba1cbb952f6cf35eef08c9dd28d6bd56ec5c72 /block/blk-lib.c | |
parent | 721c7fc701c71f693307d274d2b346a1ecd4a534 (diff) |
block: add bdev_read_only() checks to common helpers
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.
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-lib.c')
-rw-r--r-- | block/blk-lib.c | 12 |
1 files changed, 12 insertions, 0 deletions
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, | |||
37 | if (!q) | 37 | if (!q) |
38 | return -ENXIO; | 38 | return -ENXIO; |
39 | 39 | ||
40 | if (bdev_read_only(bdev)) | ||
41 | return -EPERM; | ||
42 | |||
40 | if (flags & BLKDEV_DISCARD_SECURE) { | 43 | if (flags & BLKDEV_DISCARD_SECURE) { |
41 | if (!blk_queue_secure_erase(q)) | 44 | if (!blk_queue_secure_erase(q)) |
42 | return -EOPNOTSUPP; | 45 | return -EOPNOTSUPP; |
@@ -156,6 +159,9 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector, | |||
156 | if (!q) | 159 | if (!q) |
157 | return -ENXIO; | 160 | return -ENXIO; |
158 | 161 | ||
162 | if (bdev_read_only(bdev)) | ||
163 | return -EPERM; | ||
164 | |||
159 | bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; | 165 | bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; |
160 | if ((sector | nr_sects) & bs_mask) | 166 | if ((sector | nr_sects) & bs_mask) |
161 | return -EINVAL; | 167 | return -EINVAL; |
@@ -233,6 +239,9 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, | |||
233 | if (!q) | 239 | if (!q) |
234 | return -ENXIO; | 240 | return -ENXIO; |
235 | 241 | ||
242 | if (bdev_read_only(bdev)) | ||
243 | return -EPERM; | ||
244 | |||
236 | /* Ensure that max_write_zeroes_sectors doesn't overflow bi_size */ | 245 | /* Ensure that max_write_zeroes_sectors doesn't overflow bi_size */ |
237 | max_write_zeroes_sectors = bdev_write_zeroes_sectors(bdev); | 246 | max_write_zeroes_sectors = bdev_write_zeroes_sectors(bdev); |
238 | 247 | ||
@@ -287,6 +296,9 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, | |||
287 | if (!q) | 296 | if (!q) |
288 | return -ENXIO; | 297 | return -ENXIO; |
289 | 298 | ||
299 | if (bdev_read_only(bdev)) | ||
300 | return -EPERM; | ||
301 | |||
290 | while (nr_sects != 0) { | 302 | while (nr_sects != 0) { |
291 | bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), | 303 | bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), |
292 | gfp_mask); | 304 | gfp_mask); |