[Devel] [PATCH RHEL9 COMMIT] blk-cbt: Don't open-code DIV_ROUND_UP macro

Konstantin Khorenko khorenko at virtuozzo.com
Wed Feb 22 21:00:42 MSK 2023


The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.11
------>
commit bb76c4d622a04696162e0b248df05db73eef2eaf
Author: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
Date:   Fri Jan 27 13:34:41 2023 +0200

    blk-cbt: Don't open-code DIV_ROUND_UP macro
    
    Using the macro makes the code more explicit and somewhat easier to
    comprehend.
    
    Fixes: ea18c5e9d2ba ("cbt: introduce changed block tracking")
    
    Signed-off-by: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
    Reviewed-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 block/blk-cbt.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/block/blk-cbt.c b/block/blk-cbt.c
index 352eb9802e58..2fa19ba7630e 100644
--- a/block/blk-cbt.c
+++ b/block/blk-cbt.c
@@ -18,11 +18,12 @@
 #include <linux/pagemap.h>
 #include <linux/vmalloc.h>
 #include <linux/log2.h>
+#include <linux/math.h>
 #include <asm/atomic.h>
 #include <asm/uaccess.h>
 
 #define CBT_MAX_EXTENTS	512
-#define NR_PAGES(bits) (((bits) + PAGE_SIZE*8 - 1) / (PAGE_SIZE*8))
+#define NR_PAGES(bits)		DIV_ROUND_UP((bits), PAGE_SIZE*8)
 #define BITS_PER_PAGE		(1UL << (PAGE_SHIFT + 3))
 
 #define CBT_PAGE_MISSED (struct page *)(0x1)
@@ -230,7 +231,7 @@ static void blk_cbt_add(struct request_queue *q, blkcnt_t start, blkcnt_t len)
 
 	if (unlikely(test_bit(CBT_ERROR, &cbt->flags)))
 		goto out_rcu;
-	end = (start + len + (1 << cbt->block_bits) -1) >> cbt->block_bits;
+	end = DIV_ROUND_UP(start + len, 1 << cbt->block_bits);
 	start >>= cbt->block_bits;
 	len = end - start;
 	if (unlikely(test_bit(CBT_NOCACHE, &cbt->flags))) {
@@ -273,7 +274,7 @@ static struct cbt_info* do_cbt_alloc(struct request_queue *q, __u8 *uuid,
 		return ERR_PTR(-ENOMEM);
 
 	cbt->block_bits = ilog2(blocksize);
-	cbt->block_max  = (size + blocksize - 1) >> cbt->block_bits;
+	cbt->block_max  = DIV_ROUND_UP(size, blocksize);
 	spin_lock_init(&cbt->lock);
 	memcpy(cbt->uuid, uuid, sizeof(cbt->uuid));
 	cbt->cache = alloc_percpu(struct cbt_extent);
@@ -588,7 +589,7 @@ void blk_cbt_update_size(struct block_device *bdev)
 		return;
 	}
 	bsz = 1 << cbt->block_bits;
-	if ((new_sz + bsz - 1) >> cbt->block_bits <= cbt->block_max)
+	if (DIV_ROUND_UP(new_sz, bsz) <= cbt->block_max)
 		goto err_mtx;
 
 	new = do_cbt_alloc(q, cbt->uuid, new_sz, bsz);
@@ -946,7 +947,7 @@ static int cbt_ioc_set(struct block_device *bdev, struct blk_user_cbt_info __use
 		struct cbt_extent ex;
 
 		ex.start  = cur_ex->ce_physical >> cbt->block_bits;
-		ex.len  = (cur_ex->ce_length + (1 << cbt->block_bits) -1) >> cbt->block_bits;
+		ex.len  = DIV_ROUND_UP(cur_ex->ce_length, 1 << cbt->block_bits);
 		if (ex.start > q->cbt->block_max ||
 		    ex.start + ex.len > q->cbt->block_max ||
 		    ex.len == 0) {


More information about the Devel mailing list