OSDN Git Service

block: introduce blk_req_zone_write_trylock
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 12 May 2020 08:55:48 +0000 (17:55 +0900)
committerJens Axboe <axboe@kernel.dk>
Wed, 13 May 2020 02:36:28 +0000 (20:36 -0600)
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>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-zoned.c
include/linux/blkdev.h

index f87956e..c822cfa 100644 (file)
@@ -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),
index 5647c78..73f4f4f 100644 (file)
@@ -1738,6 +1738,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);