[Ocfs2-tools-commits] mfasheh commits r925 - trunk/extras
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Jun 2 16:36:16 CDT 2005
Author: mfasheh
Date: 2005-06-02 16:36:14 -0500 (Thu, 02 Jun 2005)
New Revision: 925
Modified:
trunk/extras/mark_journal_dirty.c
Log:
* add code so mark_journal_dirty inserts nodes into slots
Modified: trunk/extras/mark_journal_dirty.c
===================================================================
--- trunk/extras/mark_journal_dirty.c 2005-06-02 19:12:29 UTC (rev 924)
+++ trunk/extras/mark_journal_dirty.c 2005-06-02 21:36:14 UTC (rev 925)
@@ -34,11 +34,14 @@
#include "ocfs2.h"
+static int debug = 1;
+
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");
+ "Usage: mark_journal_dirty <device> <node #> <slot #>\n");
+ fprintf(stderr, "Will insert node <node #> into slot <slot #> and "
+ "mark the journal in <slot #> as needing recovery.\n");
}
static errcode_t mark_journal(ocfs2_filesys *fs,
@@ -59,6 +62,7 @@
di = (ocfs2_dinode *) buf;
if (!(di->i_flags & OCFS2_JOURNAL_FL)) {
+ ret = OCFS2_ET_INVALID_ARGUMENT;
fprintf(stderr, "Block %"PRIu64" is not a journal inode!\n",
blkno);
goto out_free;
@@ -67,15 +71,103 @@
di->id1.journal1.ij_flags |= OCFS2_JOURNAL_DIRTY_FL;
ret = ocfs2_write_inode(fs, blkno, buf);
+
+out_free:
+ ocfs2_free(&buf);
+
+ return ret;
+}
+
+static errcode_t write_back_slot_map(ocfs2_filesys *fs,
+ uint64_t slot_map_blkno,
+ char *slots_buf)
+{
+ errcode_t ret;
+ char *di_buf = NULL;
+ ocfs2_dinode *di;
+ uint64_t block;
+ ocfs2_extent_list *el;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &di_buf);
if (ret)
+ return ret;
+
+ ret = ocfs2_read_inode(fs, slot_map_blkno, di_buf);
+ if (ret)
goto out_free;
+ di = (ocfs2_dinode *) di_buf;
+ el = &di->id2.i_list;
+ block = el->l_recs[0].e_blkno;
+ if (el->l_tree_depth || !block) {
+ ret = OCFS2_ET_INVALID_EXTENT_LOOKUP;
+ goto out_free;
+ }
+
+ if (debug)
+ fprintf(stdout, "Write back slot data at block %"PRIu64"\n",
+ block);
+
+ ret = io_write_block(fs->fs_io, block, 1, slots_buf);
+
out_free:
- ocfs2_free(&buf);
+ ocfs2_free(&di_buf);
return ret;
}
+static errcode_t insert_node_into_slot(ocfs2_filesys *fs,
+ int node,
+ int slot)
+{
+ errcode_t ret;
+ int i, num_slots;
+ char *buf = NULL;
+ uint64_t slot_map_blkno;
+ uint32_t len = fs->fs_blocksize;
+ int16_t *slots;
+
+ ret = ocfs2_lookup_system_inode(fs, SLOT_MAP_SYSTEM_INODE, -1,
+ &slot_map_blkno);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_read_whole_file(fs, slot_map_blkno, &buf, &len);
+ if (ret)
+ goto out;
+
+ num_slots = fs->fs_super->id2.i_super.s_max_slots;
+
+ if (debug)
+ fprintf(stdout, "%d slots on this device\n", num_slots);
+
+ if (len < fs->fs_blocksize) {
+ ret = OCFS2_ET_SHORT_READ;
+ goto out;
+ }
+
+ slots = (int16_t *) buf;
+
+ /* We'll allow the caller to put a different node in a
+ * currently filled slot, but we must watch out for duplicate
+ * nodes in slots. */
+ for(i = 0; i < num_slots; i++) {
+ if (le16_to_cpu(slots[i]) == node) {
+ ret = OCFS2_ET_INTERNAL_FAILURE;
+ fprintf(stdout, "node %d already found in slot_map "
+ "slot %d\n", node, i);
+ goto out;
+ }
+ }
+
+ slots[slot] = cpu_to_le16(node);
+
+ ret = write_back_slot_map(fs, slot_map_blkno, buf);
+
+out:
+ return ret;
+}
+
static unsigned int read_number(const char *num)
{
unsigned long val;
@@ -83,7 +175,7 @@
val = strtoul(num, &ptr, 0);
if (!ptr || *ptr)
- return 0;
+ return -1;
return (unsigned int) val;
}
@@ -95,22 +187,29 @@
char *argv[])
{
errcode_t ret;
- unsigned int slot;
+ int slot, node;
uint64_t journal_blkno;
char *filename;
ocfs2_filesys *fs;
initialize_ocfs_error_table();
- if (argc < 3) {
+ if (argc < 4) {
fprintf(stderr, "Missing parameters\n");
print_usage();
return 1;
}
filename = argv[1];
- slot = read_number(argv[2]);
- if (!slot) {
+ node = read_number(argv[2]);
+ if (node == -1) {
+ fprintf(stderr, "invalid node number\n");
+ print_usage();
+ return 1;
+ }
+
+ slot = read_number(argv[3]);
+ if (slot == -1) {
fprintf(stderr, "invalid slot number\n");
print_usage();
return 1;
@@ -118,21 +217,31 @@
ret = ocfs2_open(filename, OCFS2_FLAG_RW, 0, 0, &fs);
if (ret) {
- com_err(argv[0], ret,
- "while opening file \"%s\"", filename);
+ com_err(argv[0], ret, "while opening file \"%s\"", filename);
goto out_close;
}
+ if (debug)
+ fprintf(stdout, "Inserting node %d into slot %d\n", node,
+ slot);
+
+ ret = insert_node_into_slot(fs, node, slot);
+ if (ret) {
+ com_err(argv[0], ret, "while inserting node\n");
+ 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);
+ "while looking up journal in slot %d\n", slot);
goto out_close;
}
- fprintf(stdout, "Marking journal (block %"PRIu64") in slot %u\n",
- journal_blkno, slot);
+ if (debug)
+ fprintf(stdout, "Marking journal (block %"PRIu64") in slot "
+ "%d\n", journal_blkno, slot);
ret = mark_journal(fs, journal_blkno);
if (ret) {
@@ -150,4 +259,3 @@
return 0;
}
-
More information about the Ocfs2-tools-commits
mailing list