[Ocfs2-commits] mfasheh commits r2295 - trunk/fs/ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu May 19 19:07:29 CDT 2005


Author: mfasheh
Signed-off-by: zab
Date: 2005-05-19 19:07:27 -0500 (Thu, 19 May 2005)
New Revision: 2295

Modified:
   trunk/fs/ocfs2/alloc.c
Log:
* ignore invalid truncate log records

* if possible, coalesce the most recent truncate log record and the
  current one in truncate_log_append

Signed-off-by: zab



Modified: trunk/fs/ocfs2/alloc.c
===================================================================
--- trunk/fs/ocfs2/alloc.c	2005-05-19 23:57:18 UTC (rev 2294)
+++ trunk/fs/ocfs2/alloc.c	2005-05-20 00:07:27 UTC (rev 2295)
@@ -871,6 +871,22 @@
 	return le16_to_cpu(tl->tl_used) == le16_to_cpu(tl->tl_count);
 }
 
+static int ocfs2_truncate_log_can_coalesce(ocfs2_truncate_log *tl,
+					   unsigned int new_start)
+{
+	unsigned int index = le16_to_cpu(tl->tl_used);
+	unsigned int current_tail;
+
+	/* No records, nothing to coalesce */
+	if (!index)
+		return 0;
+
+	current_tail = le32_to_cpu(tl->tl_recs[index].t_start);
+	current_tail += le32_to_cpu(tl->tl_recs[index].t_clusters);
+
+	return current_tail == new_start;
+}
+
 static int ocfs2_truncate_log_append(ocfs_super *osb,
 				     ocfs_journal_handle *handle,
 				     u64 start_blk,
@@ -919,11 +935,17 @@
 	     "%"MLFu64" (index = %d)\n", num_clusters, start_cluster,
 	     OCFS_I(tl_inode)->ip_blkno, index);
 
-	/* TODO: Do we bother searching the truncate records for a
-	 * contiguous one and coalesce? */
-	tl->tl_recs[index].t_start = cpu_to_le32(start_cluster);
+	if (ocfs2_truncate_log_can_coalesce(tl, start_cluster)) {
+		/* Coalesce with the most recent record if possible */
+		num_clusters += le32_to_cpu(tl->tl_recs[index].t_clusters);
+		mlog(0, "Coalesce with index %u (start = %u, clusters = %u)\n",
+		     index, le32_to_cpu(tl->tl_recs[index].t_start),
+		     num_clusters);
+	} else {
+		tl->tl_recs[index].t_start = cpu_to_le32(start_cluster);
+		tl->tl_used = cpu_to_le16(index + 1);
+	}
 	tl->tl_recs[index].t_clusters = cpu_to_le32(num_clusters);
-	tl->tl_used = cpu_to_le16(index + 1);
 
 	status = ocfs_journal_dirty(handle, tl_bh);
 	if (status < 0) {
@@ -989,17 +1011,20 @@
 						    le32_to_cpu(rec.t_start));
 		num_clusters = le32_to_cpu(rec.t_clusters);
 
-		mlog(0, "free record %d, start = %u, clusters = %u\n", i,
-		     le32_to_cpu(rec.t_start), num_clusters);
+		/* if start_blk is not set, we ignore the record as
+		 * invalid. */
+		if (start_blk) {
+			mlog(0, "free record %d, start = %u, clusters = %u\n",
+			     i, le32_to_cpu(rec.t_start), num_clusters);
 
-		status = ocfs_free_clusters(handle, data_alloc_inode,
-					    data_alloc_bh, start_blk,
-					    num_clusters);
-		if (status < 0) {
-			mlog_errno(status);
-			goto bail;
+			status = ocfs_free_clusters(handle, data_alloc_inode,
+						    data_alloc_bh, start_blk,
+						    num_clusters);
+			if (status < 0) {
+				mlog_errno(status);
+				goto bail;
+			}
 		}
-
 		i--;
 	}
 



More information about the Ocfs2-commits mailing list