From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Keith Busch <kbusch@kernel.org>,
Conrad Meyer <conradmeyer@meta.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
linux-mmc@vger.kernel.org, linux-block@vger.kernel.org
Subject: [PATCH 03/10] block: add a blk_alloc_secure_erase_bio helper
Date: Mon, 1 Jul 2024 18:51:13 +0200 [thread overview]
Message-ID: <20240701165219.1571322-4-hch@lst.de> (raw)
In-Reply-To: <20240701165219.1571322-1-hch@lst.de>
Factor out a helper from blkdev_issue_secure_erase that chews off as much
as possible from a secure_erase range and allocates a bio for it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-lib.c | 36 +++++++++++++++++++++++-------------
include/linux/bio.h | 2 ++
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index ff12c3d2de5aae..cf4f0ee6b14503 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -293,26 +293,36 @@ static sector_t bio_secure_erase_limit(struct block_device *bdev)
(UINT_MAX >> SECTOR_SHIFT) & ~bs_mask);
}
+struct bio *blk_alloc_secure_erase_bio(struct block_device *bdev,
+ sector_t *sector, sector_t *nr_sects, gfp_t gfp)
+{
+ sector_t bio_sects = min(*nr_sects, bio_secure_erase_limit(bdev));
+ struct bio *bio;
+
+ if (!bio_sects)
+ return NULL;
+ bio = bio_alloc(bdev, 0, REQ_OP_SECURE_ERASE, gfp);
+ if (!bio)
+ return NULL;
+ bio->bi_iter.bi_sector = *sector;
+ bio->bi_iter.bi_size = bio_sects << SECTOR_SHIFT;
+ *sector += bio_sects;
+ *nr_sects -= bio_sects;
+ cond_resched();
+ return bio;
+}
+
int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
sector_t nr_sects, gfp_t gfp)
{
- unsigned int max_sectors = bio_secure_erase_limit(bdev);
- struct bio *bio = NULL;
+ struct bio *bio = NULL, *next;
struct blk_plug plug;
int ret = 0;
blk_start_plug(&plug);
- while (nr_sects) {
- unsigned int len = min_t(sector_t, nr_sects, max_sectors);
-
- bio = blk_next_bio(bio, bdev, 0, REQ_OP_SECURE_ERASE, gfp);
- bio->bi_iter.bi_sector = sector;
- bio->bi_iter.bi_size = len << SECTOR_SHIFT;
-
- sector += len;
- nr_sects -= len;
- cond_resched();
- }
+ while ((next = blk_alloc_secure_erase_bio(bdev, §or, &nr_sects,
+ gfp)))
+ bio = bio_chain_and_submit(bio, next);
if (bio) {
ret = submit_bio_wait(bio);
bio_put(bio);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index d5379548d684e1..e1da5fe49baca1 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -835,5 +835,7 @@ struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new);
struct bio *blk_alloc_discard_bio(struct block_device *bdev,
sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask);
+struct bio *blk_alloc_secure_erase_bio(struct block_device *bdev,
+ sector_t *sector, sector_t *nr_sects, gfp_t gfp);
#endif /* __LINUX_BIO_H */
--
2.43.0
next prev parent reply other threads:[~2024-07-01 16:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 16:51 make secure erase and write zeroes ioctls interruptible as well Christoph Hellwig
2024-07-01 16:51 ` [PATCH 01/10] block: move secure erase checks into the ioctl handler Christoph Hellwig
2024-07-01 16:51 ` [PATCH 02/10] block: factor out a bio_secure_erase_limit helper Christoph Hellwig
2024-07-01 16:51 ` Christoph Hellwig [this message]
2024-07-01 16:51 ` [PATCH 04/10] blk-lib: check for kill signal in ioctl BLKSECDISCARD Christoph Hellwig
2024-07-01 16:51 ` [PATCH 05/10] block: factor out a blk_write_zeroes_limit helper Christoph Hellwig
2024-07-01 16:51 ` [PATCH 06/10] block: remove the LBA alignment check in __blkdev_issue_zeroout Christoph Hellwig
2024-07-01 16:51 ` [PATCH 07/10] block: move read-only and supported checks into (__)blkdev_issue_zeroout Christoph Hellwig
2024-07-01 16:51 ` [PATCH 08/10] block: refacto blkdev_issue_zeroout Christoph Hellwig
2024-07-01 16:51 ` [PATCH 09/10] block: limit the Write Zeroes to manually writing zeroes fallback Christoph Hellwig
2024-07-01 16:51 ` [PATCH 10/10] blk-lib: check for kill signal in ioctl BLKZEROOUT Christoph Hellwig
2024-07-05 4:03 ` make secure erase and write zeroes ioctls interruptible as well Martin K. Petersen
2024-07-05 6:45 ` Jens Axboe
2024-07-05 6:50 ` Christoph Hellwig
2024-07-05 7:03 ` Jens Axboe
2024-07-05 12:12 ` Christoph Hellwig
2024-07-05 6:53 ` (subset) " 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=20240701165219.1571322-4-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=conradmeyer@meta.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ulf.hansson@linaro.org \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox