[Ocfs2-tools-devel] [PATCH 1/5] Add truncate_log clear process in fsck.ocfs2.v2
Tao Ma
tao.ma at oracle.com
Tue Sep 16 22:58:50 PDT 2008
Modification from V1 to V2:
1. Add a function named ocfs2_check_clusters_set to test
whether the clusters are already freed in bitmap. If it is,
we will exit do a force-check.
2. Return error if we find something wrong in ocfs2_dinode.
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 | 31 +++++++++++++
fsck.ocfs2/include/util.h | 4 ++
fsck.ocfs2/slot_recovery.c | 84 ++++++++++++++++++++++++++++++++++++
fsck.ocfs2/util.c | 44 +++++++++++++++++++
include/ocfs2/ocfs2.h | 4 ++
libocfs2/alloc.c | 36 +++++++++++++++
7 files changed, 204 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..2d8e756
--- /dev/null
+++ b/fsck.ocfs2/include/slot_recovery.h
@@ -0,0 +1,31 @@
+/*
+ * slot_recovery.h
+ *
+ * Copyright (C) 2008 Oracle Corporation. 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 as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#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..58146fb 100644
--- a/fsck.ocfs2/include/util.h
+++ b/fsck.ocfs2/include/util.h
@@ -48,4 +48,8 @@ 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));
#endif /* __O2FSCK_UTIL_H__ */
diff --git a/fsck.ocfs2/slot_recovery.c b/fsck.ocfs2/slot_recovery.c
new file mode 100644
index 0000000..a4fed82
--- /dev/null
+++ b/fsck.ocfs2/slot_recovery.c
@@ -0,0 +1,84 @@
+/* -*- 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+#include "util.h"
+#include "slot_recovery.h"
+
+static errcode_t ocfs2_clear_truncate_log(ocfs2_filesys *fs,
+ struct ocfs2_dinode *di)
+{
+ errcode_t ret = 0;
+ struct ocfs2_truncate_log *tl;
+ struct ocfs2_truncate_rec *tr;
+ int i, was_set = 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_check_clusters_set(fs, tr->t_clusters,
+ blkno, &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;
+ }
+
+ 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);
+
+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..60bb402 100644
--- a/fsck.ocfs2/util.c
+++ b/fsck.ocfs2/util.c
@@ -124,3 +124,47 @@ 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))
+{
+ 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);
+ if (ret)
+ goto bail;
+ }
+ }
+
+bail:
+
+ if (buf)
+ ocfs2_free(&buf);
+ return ret;
+}
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index fbc3146..3746d52 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -507,6 +507,10 @@ errcode_t ocfs2_new_clusters(ocfs2_filesys *fs,
errcode_t ocfs2_free_clusters(ocfs2_filesys *fs,
uint32_t len,
uint64_t start_blkno);
+errcode_t ocfs2_check_clusters_set(ocfs2_filesys *fs,
+ uint32_t len,
+ uint64_t start_blkno,
+ int *was_set);
errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir, const char *name,
int namelen, char *buf, uint64_t *inode);
diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index 03b3091..53dd790 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -513,6 +513,42 @@ out:
return ret;
}
+errcode_t ocfs2_check_clusters_set(ocfs2_filesys *fs,
+ uint32_t len,
+ uint64_t start_blkno,
+ int *was_set)
+{
+ errcode_t ret;
+ uint32_t start_cluster;
+ int set = 0;
+
+ *was_set = 0;
+
+ if (!len)
+ return 0;
+
+ ret = ocfs2_load_allocator(fs, GLOBAL_BITMAP_SYSTEM_INODE,
+ 0, &fs->fs_cluster_alloc);
+ if (ret)
+ goto out;
+
+ start_cluster = ocfs2_blocks_to_clusters(fs, start_blkno);
+
+ while (len) {
+ ret = ocfs2_bitmap_test(fs->fs_cluster_alloc->ci_chains,
+ start_cluster, &set);
+ if (ret || !set)
+ goto out;
+
+ len--;
+ start_cluster++;
+ }
+
+ *was_set = 1;
+out:
+ return ret;
+}
+
#ifdef DEBUG_EXE
#include <stdio.h>
--
1.5.4.GIT
More information about the Ocfs2-tools-devel
mailing list