diff mbox series

[v7,05/11] block: introduce blk_req_zone_write_trylock

Message ID 20200417121536.5393-6-johannes.thumshirn@wdc.com (mailing list archive)
State Superseded
Headers show
Series Introduce Zone Append for writing to zoned block devices | expand

Commit Message

Johannes Thumshirn April 17, 2020, 12:15 p.m. UTC
Introduce blk_req_zone_write_trylock(), which either grabs the write-lock
for a sequential zone or returns false, if the zone is already locked.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-zoned.c      | 14 ++++++++++++++
 include/linux/blkdev.h |  1 +
 2 files changed, 15 insertions(+)

Comments

Bart Van Assche April 18, 2020, 4:52 p.m. UTC | #1
On 2020-04-17 05:15, Johannes Thumshirn wrote:
> +bool blk_req_zone_write_trylock(struct request *rq)
> +{
> +	unsigned int zno = blk_rq_zone_no(rq);
> +
> +	if (test_and_set_bit(zno, rq->q->seq_zones_wlock))
> +		return false;
> +
> +	WARN_ON_ONCE(rq->rq_flags & RQF_ZONE_WRITE_LOCKED);
> +	rq->rq_flags |= RQF_ZONE_WRITE_LOCKED;
> +
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(blk_req_zone_write_trylock);

Although different requests can be processed concurrently by the block
layer, all processing steps for an individual request happen
sequentially. So I think it is safe to move the
WARN_ON_ONCE(rq->rq_flags & RQF_ZONE_WRITE_LOCKED) above the
test_and_set_bit() call.

Thanks,

Bart.
diff mbox series

Patch

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index f87956e0dcaf..c822cfa7a102 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -82,6 +82,20 @@  bool blk_req_needs_zone_write_lock(struct request *rq)
 }
 EXPORT_SYMBOL_GPL(blk_req_needs_zone_write_lock);
 
+bool blk_req_zone_write_trylock(struct request *rq)
+{
+	unsigned int zno = blk_rq_zone_no(rq);
+
+	if (test_and_set_bit(zno, rq->q->seq_zones_wlock))
+		return false;
+
+	WARN_ON_ONCE(rq->rq_flags & RQF_ZONE_WRITE_LOCKED);
+	rq->rq_flags |= RQF_ZONE_WRITE_LOCKED;
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(blk_req_zone_write_trylock);
+
 void __blk_req_zone_write_lock(struct request *rq)
 {
 	if (WARN_ON_ONCE(test_and_set_bit(blk_rq_zone_no(rq),
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 774947365341..0797d1e81802 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1740,6 +1740,7 @@  extern int bdev_write_page(struct block_device *, sector_t, struct page *,
 
 #ifdef CONFIG_BLK_DEV_ZONED
 bool blk_req_needs_zone_write_lock(struct request *rq);
+bool blk_req_zone_write_trylock(struct request *rq);
 void __blk_req_zone_write_lock(struct request *rq);
 void __blk_req_zone_write_unlock(struct request *rq);