[Ocfs2-tools-commits] smushran commits r467 - in trunk/fswreck: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Dec 6 19:17:16 CST 2004


Author: smushran
Date: 2004-12-06 19:17:14 -0600 (Mon, 06 Dec 2004)
New Revision: 467

Added:
   trunk/fswreck/chain.c
   trunk/fswreck/corrupt.c
   trunk/fswreck/include/chain.h
   trunk/fswreck/include/corrupt.h
Modified:
   trunk/fswreck/
   trunk/fswreck/Makefile
   trunk/fswreck/include/main.h
   trunk/fswreck/main.c
Log:
delink chain groups in global bitmap added in fswreck


Property changes on: trunk/fswreck
___________________________________________________________________
Name: svn:ignore
   - cscope.*
fswrk

   + cscope.*
fswreck


Modified: trunk/fswreck/Makefile
===================================================================
--- trunk/fswreck/Makefile	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/Makefile	2004-12-07 01:17:14 UTC (rev 467)
@@ -16,10 +16,12 @@
 CFLAGS = -Wall -O2
 endif
 
-CFILES = main.c
+CFILES = main.c corrupt.c chain.c
 
 HFILES = 			\
-	include/main.h
+	include/main.h		\
+	include/corrupt.h	\
+	include/chain.c
 
 OBJS = $(subst .c,.o,$(CFILES))
 

Added: trunk/fswreck/chain.c
===================================================================
--- trunk/fswreck/chain.c	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/chain.c	2004-12-07 01:17:14 UTC (rev 467)
@@ -0,0 +1,80 @@
+/*
+ * chain.c
+ *
+ * chain group corruptions
+ *
+ * Copyright (C) 2004 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#include <main.h>
+
+extern char *progname;
+
+/*
+ * delink_chain_group()
+ *
+ */
+void delink_chain_group(ocfs2_filesys *fs, int blkno, int count)
+{
+	errcode_t ret;
+	char *buf = NULL;
+	ocfs2_dinode *di;
+	ocfs2_chain_list *cl;
+	ocfs2_chain_rec *cr;
+	int i, j;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		FSWRK_COM_FATAL(progname, ret);
+
+	ret = ocfs2_read_inode(fs, blkno, buf);
+	if (ret)
+		FSWRK_COM_FATAL(progname, ret);
+
+	di = (ocfs2_dinode *)buf;
+
+	if (!(di->i_flags & OCFS2_CHAIN_FL))
+		FSWRK_FATAL("not a chain group");
+
+	cl = &(di->id2.i_chain);
+
+	/* delink 'count' chains from the inode */
+	for (i = cl->cl_next_free_rec, j = 0; i && j < count; --i, ++j) {
+		cr = &(cl->cl_recs[i - 1]);
+		fprintf(stdout, "Delinking ind=%d, block#=%"PRIu64", free=%u, total=%u\n",
+			i - 1, cr->c_blkno, cr->c_free, cr->c_total);
+		cr->c_free = 12345;
+		cr->c_total = 67890;
+		cr->c_blkno = 1234567890;
+	}
+
+	cl->cl_next_free_rec = i;
+
+	ret = ocfs2_write_inode(fs, blkno, buf);
+	if (ret)
+		FSWRK_COM_FATAL(progname, ret);
+
+	fprintf(stdout, "Delinked %d blocks\n", j);
+
+	if (buf)
+		ocfs2_free(&buf);
+
+	return ;
+}

Added: trunk/fswreck/corrupt.c
===================================================================
--- trunk/fswreck/corrupt.c	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/corrupt.c	2004-12-07 01:17:14 UTC (rev 467)
@@ -0,0 +1,50 @@
+/*
+ * corrupt.c
+ *
+ * corruption routines
+ *
+ * Copyright (C) 2004 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#include <main.h>
+
+extern char *progname;
+
+void corrupt_3(ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	uint64_t blkno;
+	ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+	char *global_bitmap = sysfile_info[GLOBAL_BITMAP_SYSTEM_INODE].name;
+
+	ret = ocfs2_lookup(fs, sb->s_system_dir_blkno, global_bitmap,
+			   strlen(global_bitmap), NULL, &blkno);
+	if (ret)
+		FSWRK_FATAL();
+
+	fprintf(stdout, "Corrupt #3: Delink group descriptor from "
+		"global bitmap at block#%"PRIu64"\n", blkno);
+
+	delink_chain_group(fs, blkno, 1);
+
+	fprintf(stdout, "Corrupt #3: Finito\n");
+
+	return ;
+}

Added: trunk/fswreck/include/chain.h
===================================================================
--- trunk/fswreck/include/chain.h	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/include/chain.h	2004-12-07 01:17:14 UTC (rev 467)
@@ -0,0 +1,31 @@
+/*
+ * chain.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * Copyright (C) 2004 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#ifndef __CHAIN_H__
+#define __CHAIN_H__
+
+void delink_chain_group(ocfs2_filesys *fs, int blkno, int count);
+
+#endif		/* __CHAIN_H__ */

Added: trunk/fswreck/include/corrupt.h
===================================================================
--- trunk/fswreck/include/corrupt.h	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/include/corrupt.h	2004-12-07 01:17:14 UTC (rev 467)
@@ -0,0 +1,31 @@
+/*
+ * corrupt.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * Copyright (C) 2004 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#ifndef __CORRUPT_H
+#define __CORRUPT_H
+
+void corrupt_3(ocfs2_filesys *fs);
+
+#endif		/* __CORRUPT_H */

Modified: trunk/fswreck/include/main.h
===================================================================
--- trunk/fswreck/include/main.h	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/include/main.h	2004-12-07 01:17:14 UTC (rev 467)
@@ -63,12 +63,14 @@
 					   exit(1); \
 					 })
 
-#define FSWRK_FATAL_STR(str)		DBGFS_FATAL(str, "")
+#define FSWRK_COM_FATAL(__p, __r)	do { com_err(__p, __r, ""); raise (SIGTERM); exit(1); } while(0)
 
+#define FSWRK_FATAL_STR(str)		FSWRK_FATAL(str, "")
+
 #define FSWRK_WARN(fmt, arg...)		fprintf(stderr, "WARNING at %s, %d: " fmt ".\n", \
 						__FILE__, __LINE__, ##arg)
 
-#define FSWRK_WARN_STR(str)		DBGFS_WARN(str, "")
+#define FSWRK_WARN_STR(str)		FSWRK_WARN(str, "")
 
 #undef max
 #define max(a,b)	((a) > (b) ? (a) : (b))
@@ -76,5 +78,7 @@
 #define min(a,b)	((a) < (b) ? (a) : (b))
 
 /* remaining headers */
+#include <corrupt.h>
+#include <chain.h>
 
 #endif		/* __MAIN_H__ */

Modified: trunk/fswreck/main.c
===================================================================
--- trunk/fswreck/main.c	2004-12-06 23:09:51 UTC (rev 466)
+++ trunk/fswreck/main.c	2004-12-07 01:17:14 UTC (rev 467)
@@ -25,12 +25,19 @@
 
 #include <main.h>
 
-#define MAX_CORRUPT		1
+#define MAX_CORRUPT		3
 
 char *progname = NULL;
 char *device = NULL;
 int corrupt[MAX_CORRUPT];
 
+void (*corrupt_func[]) (ocfs2_filesys *fs) = {
+	NULL,
+	NULL,
+	NULL,
+	&corrupt_3
+};
+
 /*
  * usage()
  *
@@ -91,7 +98,7 @@
 		switch (c) {
 		case 'c':	/* corrupt */
 			ind = strtoul(optarg, NULL, 0);
-			if (ind < MAX_CORRUPT)
+			if (ind <= MAX_CORRUPT)
 				corrupt[ind] = 1;
 			else {
 				printf("booo\n");
@@ -118,8 +125,7 @@
 {
 	ocfs2_filesys *fs = NULL;
 	errcode_t ret = 0;
-	uint64_t boo;
-	int len;
+	int i;
 
 #define INSTALL_SIGNAL(sig)					\
 	do {							\
@@ -150,6 +156,15 @@
 		goto bail;
 	}
 
+	for (i = 1; i <= MAX_CORRUPT; ++i) {
+		if (corrupt[i]) {
+			if (corrupt_func[i])
+				corrupt_func[i](fs);
+			else
+				printf("Unimplemented corrupt code = %d\n", i);
+		}
+	}
+
 bail:
 	ret = ocfs2_close(fs);
 	if (ret)



More information about the Ocfs2-tools-commits mailing list