Skip to contentSkip to conversation

rpdfs-progs: Fix binary search in find_recent_commit()

PATCH Applied Chris Kirby 2 participants 2 messages Aug 13 – Oct 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rpdfs-progs: Fix binary search in find_recent_commit()

When setting the midpoint, divide by two instead of by four. This prevents the search from looping forever when there is only a single COMMIT at offset zero, like with a new-to-rpdfs device that was just formatted.

---
 devd/lstore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
devd/lstore.c +2 -2
index ad1849c..5c3d0c8 100644
@@ -367,7 +367,7 @@ static int lstore_blk_write(struct list_head *list)
 		goto out;
 	}
 
-	/* the first block must he a commit block, this is a pretty weak check */
+	/* the first block must be a commit block, this is a pretty weak check */
 	cmt = hnd->data;
 	if (cmt->hdr.type != RPDFS_LOG_BLOCK_TYPE_COMMIT) {
 		ret = -EINVAL;
@@ -834,7 +834,7 @@ static int find_recent_commit(struct lstore_instance *inst, u64 size, u64 *recen
 	*recent = U64_MAX;
 
 	while (start <= last) {
-		mid = (start + last) >> 2;
+		mid = (start + last) / 2;
 		dev_addr = mid << SEARCH_OFFSET_SHIFT;
 
 		hnd = lstore_read_block(dev_addr, RPDFS_LOG_BLOCK_TYPE_COMMIT, 0, NULL);
Signature · 1 line
2.55.0
Applied
#1 lore raw
Quoted 4 lines · Chris Kirby

When setting the midpoint, divide by two instead of by four. This prevents the search from looping forever when there is only a single COMMIT at offset zero, like with a new-to-rpdfs device that was just formatted.

Applied, thanks!

- z