Skip to contentSkip to conversation

block: introduce bdev_rot()

PATCH Applied Damien Le Moal 3 participants 3 messages Jan 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: introduce bdev_rot()

Introduce the helper function bdev_rot() to test if a block device is a rotational one. The existing function bdev_nonrot() which tests for the opposite condition is redefined using this new helper.
This avoids the double negation (operator and name) that appears when testing if a block device is a rotational device, thus making the code a little easier to read.

Call sites of bdev_nonrot() in the block layer are updated to use this new helper. Remaining users in other subsystems are left unchanged for now.

---
 block/ioctl.c                   | 2 +-
 drivers/block/loop.c            | 2 +-
 drivers/nvme/target/admin-cmd.c | 4 ++--
 include/linux/blkdev.h          | 7 ++++++-
 4 files changed, 10 insertions(+), 5 deletions(-)
block/ioctl.c +1 -1
index 344478348a54..fd48f82f9f03 100644
@@ -692,7 +692,7 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
 				    queue_max_sectors(bdev_get_queue(bdev)));
 		return put_ushort(argp, max_sectors);
 	case BLKROTATIONAL:
-		return put_ushort(argp, !bdev_nonrot(bdev));
+		return put_ushort(argp, bdev_rot(bdev));
 	case BLKRASET:
 	case BLKFRASET:
 		if(!capable(CAP_SYS_ADMIN))
drivers/block/loop.c +1 -1
index bd59c0e9508b..ae3039584045 100644
@@ -969,7 +969,7 @@ static void loop_update_limits(struct loop_device *lo, struct queue_limits *lim,
 	lim->features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_ROTATIONAL);
 	if (file->f_op->fsync && !(lo->lo_flags & LO_FLAGS_READ_ONLY))
 		lim->features |= BLK_FEAT_WRITE_CACHE;
-	if (backing_bdev && !bdev_nonrot(backing_bdev))
+	if (backing_bdev && bdev_rot(backing_bdev))
 		lim->features |= BLK_FEAT_ROTATIONAL;
 	lim->max_hw_discard_sectors = max_discard_sectors;
 	lim->max_write_zeroes_sectors = max_discard_sectors;
drivers/nvme/target/admin-cmd.c +2 -2
index 3da31bb1183e..5e366502fb75 100644
@@ -298,7 +298,7 @@ static void nvmet_execute_get_log_page_rmi(struct nvmet_req *req)
 	if (status)
 		goto out;
 
-	if (!req->ns->bdev || bdev_nonrot(req->ns->bdev)) {
+	if (!req->ns->bdev || !bdev_rot(req->ns->bdev)) {
 		status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
 		goto out;
 	}
@@ -1084,7 +1084,7 @@ static void nvmet_execute_id_cs_indep(struct nvmet_req *req)
 	id->nmic = NVME_NS_NMIC_SHARED;
 	if (req->ns->readonly)
 		id->nsattr |= NVME_NS_ATTR_RO;
-	if (req->ns->bdev && !bdev_nonrot(req->ns->bdev))
+	if (req->ns->bdev && bdev_rot(req->ns->bdev))
 		id->nsfeat |= NVME_NS_ROTATIONAL;
 	/*
 	 * We need flush command to flush the file's metadata,
include/linux/blkdev.h +6 -1
index 1e5b5547929f..2ae4c45e4959 100644
@@ -1461,9 +1461,14 @@ bdev_write_zeroes_unmap_sectors(struct block_device *bdev)
 	return bdev_limits(bdev)->max_wzeroes_unmap_sectors;
 }
 
+static inline bool bdev_rot(struct block_device *bdev)
+{
+	return blk_queue_rot(bdev_get_queue(bdev));
+}
+
 static inline bool bdev_nonrot(struct block_device *bdev)
 {
-	return !blk_queue_rot(bdev_get_queue(bdev));
+	return !bdev_rot(bdev);
 }
 
 static inline bool bdev_synchronous(struct block_device *bdev)
Signature · 1 line
2.52.0
maintainer Applied
#2 lore raw
In reply to Damien Le Moal
Quoted 8 lines · Damien Le Moal

Introduce the helper function bdev_rot() to test if a block device is a rotational one. The existing function bdev_nonrot() which tests for the opposite condition is redefined using this new helper.
This avoids the double negation (operator and name) that appears when testing if a block device is a rotational device, thus making the code a little easier to read.

[...]

Applied, thanks!

[1/1] block: introduce bdev_rot()

      commit: da562d92e6755c00cd67845a8dbfb908dac51a9c

Best regards,

Signature · 1 line
Jens Axboe