[Ocfs2-tools-commits] mfasheh commits r924 - trunk/extras
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Jun 2 14:12:32 CDT 2005
Author: mfasheh
Date: 2005-06-02 14:12:29 -0500 (Thu, 02 Jun 2005)
New Revision: 924
Added:
trunk/extras/encode_lockres.c
trunk/extras/mark_journal_dirty.c
Modified:
trunk/extras/Makefile
Log:
* add two programs in extras:
-encode_lockres - the opposite of decode_lockres
-mark_journal_dirty - marks a given slots journal as needing
recovery. Useful in testing.
Modified: trunk/extras/Makefile
===================================================================
--- trunk/extras/Makefile 2005-06-02 03:43:19 UTC (rev 923)
+++ trunk/extras/Makefile 2005-06-02 19:12:29 UTC (rev 924)
@@ -11,7 +11,7 @@
CFLAGS = $(OPTS) $(WARNINGS)
-UNINST_PROGRAMS = find_hardlinks find_dup_extents find_inode_paths set_random_bits decode_lockres
+UNINST_PROGRAMS = find_hardlinks find_dup_extents find_inode_paths set_random_bits decode_lockres encode_lockres mark_journal_dirty
INCLUDES = -I../libocfs2/include -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include
@@ -26,14 +26,18 @@
FIND_INODE_PATHS_CFILES = find_inode_paths.c
SET_RANDOM_BITS_CFILES = set_random_bits.c
DECODE_LOCKRES_CFILES = decode_lockres.c
+ENCODE_LOCKRES_CFILES = encode_lockres.c
+MARK_JOURNAL_DIRTY_CFILES = mark_journal_dirty.c
-DIST_FILES = $(FIND_HARDLINKS_CFILES) $(FIND_DUP_EXTENTS_CFILES) $(FIND_INODE_PATHS_CFILES) $(SET_RANDOM_BITS_CFILES) $(DECODE_LOCKRES_CFILES)
+DIST_FILES = $(FIND_HARDLINKS_CFILES) $(FIND_DUP_EXTENTS_CFILES) $(FIND_INODE_PATHS_CFILES) $(SET_RANDOM_BITS_CFILES) $(DECODE_LOCKRES_CFILES) $(ENCODE_LOCKRES_CFILES) $(MARK_JOURNAL_DIRTY_CFILES)
FIND_HARDLINKS_OBJS = $(subst .c,.o,$(FIND_HARDLINKS_CFILES))
FIND_DUP_EXTENTS_OBJS = $(subst .c,.o,$(FIND_DUP_EXTENTS_CFILES))
FIND_INODE_PATHS_OBJS = $(subst .c,.o,$(FIND_INODE_PATHS_CFILES))
SET_RANDOM_BITS_OBJS = $(subst .c,.o,$(SET_RANDOM_BITS_CFILES))
DECODE_LOCKRES_OBJS = $(subst .c,.o,$(DECODE_LOCKRES_CFILES))
+ENCODE_LOCKRES_OBJS = $(subst .c,.o,$(ENCODE_LOCKRES_CFILES))
+MARK_JOURNAL_DIRTY_OBJS = $(subst .c,.o,$(MARK_JOURNAL_DIRTY_CFILES))
LIBOCFS2 = ../libocfs2/libocfs2.a
LIBS = $(LIBOCFS2) $(COM_ERR_LIBS)
@@ -52,4 +56,10 @@
decode_lockres: $(DECODE_LOCKRES_OBJS) $(LIBS)
$(LINK)
+encode_lockres: $(ENCODE_LOCKRES_OBJS) $(LIBS)
+ $(LINK)
+
+mark_journal_dirty: $(MARK_JOURNAL_DIRTY_OBJS) $(LIBS)
+ $(LINK)
+
include $(TOPDIR)/Postamble.make
Added: trunk/extras/encode_lockres.c
===================================================================
--- trunk/extras/encode_lockres.c 2005-06-02 03:43:19 UTC (rev 923)
+++ trunk/extras/encode_lockres.c 2005-06-02 19:12:29 UTC (rev 924)
@@ -0,0 +1,94 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * encode_lockres.c
+ *
+ * Encodes a lockres name based on information passed
+ *
+ * Copyright (C) 2005 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.
+ *
+ * Authors: Mark Fasheh
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <stdlib.h>
+
+/* Begin paste from kernel module */
+enum ocfs2_lock_type {
+ OCFS_TYPE_META = 0,
+ OCFS_TYPE_DATA,
+ OCFS_TYPE_SUPER,
+ OCFS_NUM_LOCK_TYPES
+};
+
+/* lock ids are made up in the following manner:
+ * name[0] --> type
+ * name[1-6] --> 6 pad characters, reserved for now
+ * name[7-22] --> block number, expressed in hex as 16 chars
+ * name[23-30] --> i_generation, expressed in hex 8 chars
+ * name[31] --> '\0' */
+#define OCFS2_LOCK_ID_MAX_LEN 32
+#define OCFS2_LOCK_ID_PAD "000000"
+
+static char ocfs2_lock_type_char[OCFS_NUM_LOCK_TYPES] = {
+ [OCFS_TYPE_META] 'M',
+ [OCFS_TYPE_DATA] 'D',
+ [OCFS_TYPE_SUPER] 'S'
+};
+/* End paste from kernel module */
+
+static void usage(char *program)
+{
+ printf("%s [M|D|S] [blkno] [generation]\n", program);
+ printf("encodes a lockres name\n");
+}
+
+int main(int argc, char **argv)
+{
+ uint64_t blkno;
+ uint32_t generation;
+ char type;
+ int i;
+
+ if (argc < 4) {
+ usage(argv[0]);
+ return 0;
+ }
+
+ type = argv[1][0];
+ blkno = atoll(argv[2]);
+ generation = atoi(argv[3]);
+
+ for (i = 0; i < OCFS_NUM_LOCK_TYPES; i++)
+ if (type == ocfs2_lock_type_char[i])
+ break;
+
+ if (i == OCFS_NUM_LOCK_TYPES) {
+ fprintf(stderr, "Invalid lock type '%c'\n", type);
+ return 1;
+ }
+
+ fprintf(stdout, "%c%s%016"PRIx64"%08x\n", type, OCFS2_LOCK_ID_PAD,
+ blkno, generation);
+
+ return 0;
+}
Added: trunk/extras/mark_journal_dirty.c
===================================================================
--- trunk/extras/mark_journal_dirty.c 2005-06-02 03:43:19 UTC (rev 923)
+++ trunk/extras/mark_journal_dirty.c 2005-06-02 19:12:29 UTC (rev 924)
@@ -0,0 +1,153 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mark_journal_dirty.c
+ *
+ * Marks the journal for a given slot # as dirty.
+ *
+ * Copyright (C) 2005 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.
+ *
+ * Authors: Mark Fasheh
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <inttypes.h>
+
+#include "ocfs2.h"
+
+static void print_usage(void)
+{
+ fprintf(stderr, "Usage: mark_journal_dirty <device> <slot #>\n");
+ fprintf(stderr,
+ "Will mark the journal in <slot #> as needing recovery\n");
+}
+
+static errcode_t mark_journal(ocfs2_filesys *fs,
+ uint64_t blkno)
+{
+ errcode_t ret;
+ char *buf = NULL;
+ ocfs2_dinode *di;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ return ret;
+
+ ret = ocfs2_read_inode(fs, blkno, buf);
+ if (ret)
+ goto out_free;
+
+ di = (ocfs2_dinode *) buf;
+
+ if (!(di->i_flags & OCFS2_JOURNAL_FL)) {
+ fprintf(stderr, "Block %"PRIu64" is not a journal inode!\n",
+ blkno);
+ goto out_free;
+ }
+
+ di->id1.journal1.ij_flags |= OCFS2_JOURNAL_DIRTY_FL;
+
+ ret = ocfs2_write_inode(fs, blkno, buf);
+ if (ret)
+ goto out_free;
+
+out_free:
+ ocfs2_free(&buf);
+
+ return ret;
+}
+
+static unsigned int read_number(const char *num)
+{
+ unsigned long val;
+ char *ptr;
+
+ val = strtoul(num, &ptr, 0);
+ if (!ptr || *ptr)
+ return 0;
+
+ return (unsigned int) val;
+}
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc,
+ char *argv[])
+{
+ errcode_t ret;
+ unsigned int slot;
+ uint64_t journal_blkno;
+ char *filename;
+ ocfs2_filesys *fs;
+
+ initialize_ocfs_error_table();
+
+ if (argc < 3) {
+ fprintf(stderr, "Missing parameters\n");
+ print_usage();
+ return 1;
+ }
+ filename = argv[1];
+
+ slot = read_number(argv[2]);
+ if (!slot) {
+ fprintf(stderr, "invalid slot number\n");
+ print_usage();
+ return 1;
+ }
+
+ ret = ocfs2_open(filename, OCFS2_FLAG_RW, 0, 0, &fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while opening file \"%s\"", filename);
+ goto out_close;
+ }
+
+ ret = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, slot,
+ &journal_blkno);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while looking up journal in slot %u\n", slot);
+ goto out_close;
+ }
+
+ fprintf(stdout, "Marking journal (block %"PRIu64") in slot %u\n",
+ journal_blkno, slot);
+
+ ret = mark_journal(fs, journal_blkno);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while marking journal dirty");
+ goto out_close;
+ }
+
+out_close:
+ ret = ocfs2_close(fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while closing file \"%s\"", filename);
+ }
+
+ return 0;
+}
+
More information about the Ocfs2-tools-commits
mailing list