[Ocfs2-tools-devel] [PATCH 2/6] fsck.ocfs2: Add truncate_log clear process.v4

Tao Ma tao.ma at oracle.com
Tue Oct 7 00:29:00 PDT 2008


Add functions in fsck.ocfs2 to clear the truncate_log
for all the nodes.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 fsck.ocfs2/Makefile                |    1 +
 fsck.ocfs2/include/slot_recovery.h |   28 ++++++++++++
 fsck.ocfs2/include/util.h          |    5 ++
 fsck.ocfs2/slot_recovery.c         |   85 ++++++++++++++++++++++++++++++++++++
 fsck.ocfs2/util.c                  |   45 +++++++++++++++++++
 5 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 fsck.ocfs2/include/slot_recovery.h
 create mode 100644 fsck.ocfs2/slot_recovery.c

diff --git a/fsck.ocfs2/Makefile b/fsck.ocfs2/Makefile
index b804f67..74963d7 100644
--- a/fsck.ocfs2/Makefile
+++ b/fsck.ocfs2/Makefile
@@ -29,6 +29,7 @@ CFILES =	fsck.c		\
 		pass3.c 	\
 		pass4.c 	\
 		problem.c 	\
+		slot_recovery.c \
 		strings.c 	\
 		util.c
 
diff --git a/fsck.ocfs2/include/slot_recovery.h b/fsck.ocfs2/include/slot_recovery.h
new file mode 100644
index 0000000..7b96c4e
--- /dev/null
+++ b/fsck.ocfs2/include/slot_recovery.h
@@ -0,0 +1,28 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * slot_recovery.c
+ *
+ * Slot recovery handler.
+ *
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef __O2FSCK_SLOT_RECOVERY_H__
+#define __O2FSCK_SLOT_RECOVERY_H__
+
+#include "fsck.h"
+
+errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs);
+
+#endif /* __O2FSCK_SLOT_RECOVERY_H__ */
+
diff --git a/fsck.ocfs2/include/util.h b/fsck.ocfs2/include/util.h
index 5ee4f8e..98fc24a 100644
--- a/fsck.ocfs2/include/util.h
+++ b/fsck.ocfs2/include/util.h
@@ -48,4 +48,9 @@ errcode_t o2fsck_type_from_dinode(o2fsck_state *ost, uint64_t ino,
 errcode_t o2fsck_read_publish(o2fsck_state *ost);
 size_t o2fsck_bitcount(unsigned char *bytes, size_t len);
 
+errcode_t handle_slots_system_file(ocfs2_filesys *fs,
+				   int type,
+				   errcode_t (*func)(ocfs2_filesys *fs,
+						     struct ocfs2_dinode *di,
+						     int slot));
 #endif /* __O2FSCK_UTIL_H__ */
diff --git a/fsck.ocfs2/slot_recovery.c b/fsck.ocfs2/slot_recovery.c
new file mode 100644
index 0000000..77f6ed7
--- /dev/null
+++ b/fsck.ocfs2/slot_recovery.c
@@ -0,0 +1,85 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * slot_recovery.c
+ *
+ * Slot recovery handler.
+ *
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include "util.h"
+#include "slot_recovery.h"
+
+static errcode_t ocfs2_clear_truncate_log(ocfs2_filesys *fs,
+					  struct ocfs2_dinode *di,
+					  int slot)
+{
+	errcode_t ret = 0;
+	struct ocfs2_truncate_log *tl;
+	struct ocfs2_truncate_rec *tr;
+	int i, was_set = 0, cleared = 0;
+	int max = ocfs2_truncate_recs_per_inode(fs->fs_blocksize);
+	uint64_t blkno;
+
+	if (!(di->i_flags & OCFS2_VALID_FL) ||
+	    !(di->i_flags & OCFS2_SYSTEM_FL) ||
+	    !(di->i_flags & OCFS2_DEALLOC_FL))
+		return OCFS2_ET_INVALID_ARGUMENT;
+
+	tl = &di->id2.i_dealloc;
+
+	if (tl->tl_used > max)
+		return OCFS2_ET_INTERNAL_FAILURE;
+
+	for (i = 0; i < tl->tl_used; i++) {
+		tr = &tl->tl_recs[i];
+
+		if (tr->t_start == 0)
+			continue;
+
+		blkno = ocfs2_clusters_to_blocks(fs, tr->t_start);
+
+		ret = ocfs2_test_clusters(fs, tr->t_clusters,
+					  blkno, 1, &was_set);
+		if (ret)
+			goto bail;
+
+		if (!was_set) {
+			ret = OCFS2_ET_INVALID_BIT;
+			goto bail;
+		}
+
+		ret = ocfs2_free_clusters(fs, tr->t_clusters, blkno);
+		if (ret)
+			goto bail;
+
+		cleared = 1;
+	}
+
+	tl->tl_used = 0;
+	memset(tl->tl_recs, 0, fs->fs_blocksize -
+	       offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs));
+	ret = ocfs2_write_inode(fs, di->i_blkno, (char *)di);
+	if (!ret && cleared)
+		printf("Slot %d's truncate log replayed successfully\n", slot);
+
+bail:
+	return ret;
+}
+
+errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs)
+{
+	return handle_slots_system_file(fs,
+					TRUNCATE_LOG_SYSTEM_INODE,
+					ocfs2_clear_truncate_log);
+}
diff --git a/fsck.ocfs2/util.c b/fsck.ocfs2/util.c
index c2382ac..86d5972 100644
--- a/fsck.ocfs2/util.c
+++ b/fsck.ocfs2/util.c
@@ -124,3 +124,48 @@ size_t o2fsck_bitcount(unsigned char *bytes, size_t len)
 
 	return count;
 }
+
+errcode_t handle_slots_system_file(ocfs2_filesys *fs,
+				   int type,
+				   errcode_t (*func)(ocfs2_filesys *fs,
+						     struct ocfs2_dinode *di,
+						     int slot))
+{
+	errcode_t ret;
+	uint64_t blkno;
+	int slot, max_slots;
+	char *buf = NULL;
+	struct ocfs2_dinode *di;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		goto bail;
+
+	di = (struct ocfs2_dinode *)buf;
+
+	max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
+
+	for (slot = 0; slot < max_slots; slot++) {
+		ret = ocfs2_lookup_system_inode(fs,
+						type,
+						slot, &blkno);
+		if (ret)
+			goto bail;
+
+		ret = ocfs2_read_inode(fs, blkno, buf);
+		if (ret)
+			goto bail;
+
+		if (func) {
+			ret = func(fs, di, slot);
+			if (ret)
+				goto bail;
+		}
+	}
+
+bail:
+
+	if (buf)
+		ocfs2_free(&buf);
+	return ret;
+}
-- 
1.5.4.GIT




More information about the Ocfs2-tools-devel mailing list