shithub: lwext4

Download patch

ref: bc6e18d5bce604736a77a15ebcfca8a54b2488c0
parent: 6665a61fa4be7816b22cd005a7cfb720acce8e15
author: Kaho Ng <ngkaho1234@gmail.com>
date: Tue May 24 09:37:12 EDT 2016

ext4_journal: handle trans_id wrapping around cases

--- a/src/ext4_journal.c
+++ b/src/ext4_journal.c
@@ -103,6 +103,12 @@
 		var -= (jbd_get32((sb), maxlen) - jbd_get32((sb), first));	\
 } while (0)
 
+static inline int32_t
+trans_id_diff(uint32_t x, uint32_t y)
+{
+	int32_t diff = x - y;
+	return (diff >= 0);
+}
 
 static int
 jbd_revoke_entry_cmp(struct revoke_entry *a, struct revoke_entry *b)
@@ -878,7 +884,7 @@
 	 * is equal or greater than that in revoke entry.*/
 	revoke_entry = jbd_revoke_entry_lookup(info, block);
 	if (revoke_entry &&
-	    arg->this_trans_id < revoke_entry->trans_id)
+	    trans_id_diff(arg->this_trans_id, revoke_entry->trans_id) < 0)
 		return;
 
 	ext4_dbg(DEBUG_JBD,
@@ -1066,7 +1072,7 @@
 		 * we will stop when we reach the end of
 		 * the journal.*/
 		if (action != ACTION_SCAN)
-			if (this_trans_id > info->last_trans_id) {
+			if (trans_id_diff(this_trans_id, info->last_trans_id) > 0) {
 				log_end = true;
 				continue;
 			}
@@ -1176,7 +1182,7 @@
 	if (r == EOK && action == ACTION_SCAN) {
 		/* We have finished scanning the journal. */
 		info->start_trans_id = start_trans_id;
-		if (this_trans_id > start_trans_id)
+		if (trans_id_diff(this_trans_id, start_trans_id) > 0)
 			info->last_trans_id = this_trans_id - 1;
 		else
 			info->last_trans_id = this_trans_id;