[Ocfs2-commits] jlbec commits r961 - in trunk/src: . inc
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Jun 1 18:42:24 CDT 2004
Author: jlbec
Date: 2004-06-01 17:42:22 -0500 (Tue, 01 Jun 2004)
New Revision: 961
Added:
trunk/src/inc/ocfs_journal.h
Removed:
trunk/src/inc/journal.h
Modified:
trunk/src/alloc.c
trunk/src/bitmap.c
trunk/src/dlm.c
trunk/src/file.c
trunk/src/inc/ocfs.h
trunk/src/inc/ocfs_log.h
trunk/src/inode.c
trunk/src/journal.c
trunk/src/namei.c
trunk/src/nm.c
trunk/src/super.c
trunk/src/sysfile.c
Log:
o Removed journal.h from ocfs.h
o Moved journal.h to ocfs_journal.h.
o Fixed up files that require ocfs_journal.h
Modified: trunk/src/alloc.c
===================================================================
--- trunk/src/alloc.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/alloc.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -29,6 +29,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#else
#include <debugocfs.h>
#endif
Modified: trunk/src/bitmap.c
===================================================================
--- trunk/src/bitmap.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/bitmap.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -29,6 +29,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#else
#include <asm/bitops.h>
#include <dummy.h>
Modified: trunk/src/dlm.c
===================================================================
--- trunk/src/dlm.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/dlm.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -28,6 +28,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
extern __u32 comm_voting;
Modified: trunk/src/file.c
===================================================================
--- trunk/src/file.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/file.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -28,6 +28,8 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
+
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_FILE
extern struct semaphore recovery_list_sem;
Deleted: trunk/src/inc/journal.h
===================================================================
--- trunk/src/inc/journal.h 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/inc/journal.h 2004-06-01 22:42:22 UTC (rev 961)
@@ -1,382 +0,0 @@
-/*
- * journal.h
- *
- * Defines journalling api and structures.
- *
- * Copyright (C) 2003, 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: Kurt Hackel, Mark Fasheh, Sunil Mushran, Wim Coekaerts,
- * Manish Singh
- */
-
-#ifndef _OCFSJOURNAL_H_
-#define _OCFSJOURNAL_H_
-
-#define OCFS_JOURNAL_CURRENT_VERSION 1
-#define OCFS_DEFAULT_COMMIT_INTERVAL (HZ * 5)
-#define OCFS_JOURNAL_DEFAULT_SIZE (8 * ONE_MEGA_BYTE)
-
-#undef OCFS_JOURNAL_USE_CB
-
-enum ocfs_journal_state {
- OCFS_JOURNAL_FREE = 0,
- OCFS_JOURNAL_LOADED,
- OCFS_JOURNAL_IN_SHUTDOWN,
-};
-
-struct _ocfs_super;
-struct _ocfs_file_entry;
-struct _ocfs_journal_handle;
-
-/* most of the ocfs_journal structure is protected by the
- * trans_lock. BEWARE. */
-typedef struct _ocfs_journal ocfs_journal;
-struct _ocfs_journal {
- enum ocfs_journal_state state; /* Journals current state */
-
- journal_t *k_journal; /* The kernels journal type */
- struct inode *k_inode; /* Kernel inode pointing to
- * this journal */
- __u8 version; /* Journal version */
- __u64 lock_id; /* Lock id for journal file */
- struct _ocfs_super *osb; /* pointer to the super
- * block for the node
- * we're currently
- * running on -- not
- * necessarily the super
- * block from the node
- * which we usually run
- * from (recovery,
- * etc) */
- __u32 node_num; /* Whose journal are we? */
- struct buffer_head *lockbh; /* Journal disk lock, used
- to access file entry */
- atomic_t num_trans; /* Number of transactions
- * currently in the system. */
- struct _ocfs_journal_handle *curr; /* pointer to currently
- * running handle. In
- * the future when we do
- * multiple concurrent
- * transactions this may
- * become a list.*/
- /* locking order: trans_lock -> commit_sem -> journal.curr.list_lock */
- struct semaphore commit_sem; /* protects *everything*
- * in the commited list
- * and also protects
- * 'curr' from
- * removal/creation. */
- struct list_head commited; /* doubly linked list of all
- * commited handles awaiting
- * checkpointing. */
-};
-
-typedef struct _ocfs_journal_lock ocfs_journal_lock;
-struct _ocfs_journal_lock {
- __u32 type;
- __u32 flags;
- struct buffer_head *bh;
- struct inode *inode;
- struct list_head lock_list;
-};
-
-typedef struct _ocfs_journal_copyout ocfs_journal_copyout;
-struct _ocfs_journal_copyout {
- __u8 forget; /* should we journal_forget this
- * buffer instead? */
- unsigned long blocknr; /* what block is this for? */
- char *data; /* the actual data */
-};
-
-#define ocfs_handle_free_all_copyout(handle) \
-do { \
- while (handle->num_co) { \
- handle->num_co--; \
- if (handle->co_buffs[handle->num_co].data) \
- ocfs_free(handle->co_buffs[handle->num_co].data); \
- } \
- ocfs_free(handle->co_buffs); \
- handle->co_buffs = NULL; \
-} while (0)
-
-typedef struct _ocfs_journal_handle ocfs_journal_handle;
-struct _ocfs_journal_handle {
- handle_t *k_handle; /* kernel handle. */
- ocfs_journal *journal;
- struct _ocfs_super *osb; /* what super block we belong to */
- __u32 flags; /* see flags below. */
- struct list_head h_list; /* points to whatever list we're
- * on. */
- int max_buffs; /* Buffs reserved by this handle */
-
- /* We know how many buffers (max) we'll have for this
- * transaction so we can just allocate an array of pointers at
- * the same time as the creation of this handle. */
- int num_buffs;
- struct buffer_head **buffs;
-
- /* The following three fields are for ocfs_journal_add_lock */
- spinlock_t list_lock; /* Used to protect the 'locks'
- * list. Only used if the
- * handle is the same as
- * journal->curr. otherwise, we
- * should be in the commited
- * list in which case we're
- * protected by commit_sem */
- int num_locks;
- struct list_head locks; /* A bunch of locks to
- * release on commit/abort. This
- * should be a list_head */
-
- int num_co;
- ocfs_journal_copyout *co_buffs; /* Copy-out buffers. On 1st
- * journal_access of a buffer
- * we make a copy of it into
- * one of these. That way if we
- * abort we can place the
- * original copy back into the
- * buffer. */
-
- struct _ocfs_bitmap_free_head *commit_bits; /* bits to be
- * freed ONLY if
- * we commit the
- * handle. */
- __u64 new_file_lockid; /* offset for the
- * most recently
- * created file
- * sitting on this
- * journal handle */
- struct list_head inode_list;
-};
-
-/* should we checkpoint this handle on commit? */
-#define OCFS_HANDLE_CHECKPOINT 1
-/* should we sync-commit this handle? */
-#define OCFS_HANDLE_SYNC 2
-/* was local alloc used (should we release the sem?) */
-#define OCFS_HANDLE_LOCAL_ALLOC 4
-
-static inline void ocfs_handle_set_checkpoint(ocfs_journal_handle *handle,
- int checkpoint)
-{
- if (checkpoint)
- handle->flags |= OCFS_HANDLE_CHECKPOINT;
- else
- handle->flags &= ~OCFS_HANDLE_CHECKPOINT;
-}
-
-static inline void ocfs_handle_set_sync(ocfs_journal_handle *handle, int sync)
-{
- if (sync)
- handle->flags |= OCFS_HANDLE_SYNC;
- else
- handle->flags &= ~OCFS_HANDLE_SYNC;
-}
-
-/* TODO: turn both of these into static inlines, once the include file
- * mess is sorted out. */
-#define ocfs_handle_add_commit_bits(handle, len, fileoff, nodenum, type) \
-({ \
- int rv = 0; \
- if (!handle->commit_bits) \
- handle->commit_bits = ocfs_alloc_bitmap_free_head(); \
- \
- if (!handle->commit_bits) \
- rv = -ENOMEM; \
- else \
- rv = ocfs_add_to_bitmap_free_head(handle->osb, \
- handle->commit_bits, \
- len, fileoff, nodenum, \
- type); \
- rv; \
-})
-
-
-/*
- * Journal Control:
- * Initialize, Load, Shutdown, Wipe, Create a journal.
- *
- * ocfs_journal_init - Initialize journal structures in the OSB.
- * ocfs_journal_load - Load the given journal off disk. Replay it if
- * there's transactions still in there.
- * ocfs_journal_shutdown - Shutdown a journal, this will flush all
- * uncommited, uncheckpointed transactions.
- * ocfs_journal_wipe - Wipe transactions from a journal. Optionally
- * zero out each block.
- * ocfs_recovery_thread - Perform recovery on a node. osb is our own osb.
- */
-int ocfs_journal_init(struct _ocfs_super *osb);
-void ocfs_journal_shutdown(struct _ocfs_super *osb);
-int ocfs_journal_wipe(ocfs_journal *journal, int full);
-int ocfs_journal_load(ocfs_journal *journal);
-void ocfs_recovery_thread(struct _ocfs_super *osb, int node_num);
-int ocfs_journal_new_file_search(struct _ocfs_super *osb, __u64 lockid);
-
-/*
- * Transaction Handling:
- * Manage the lifetime of a transaction handle.
- *
- * ocfs_start_trans - Begin a transaction. Give it an upper estimate of
- * the number of blocks that will be changed during
- * this handle.
- * ocfs_commit_trans - Complete a handle.
- * ocfs_abort_trans - Abort a running handle.
- * ocfs_journal_access - Notify the handle that we want to journal this
- * buffer. Will have to call ocfs_journal_dirty once
- * we've actually dirtied it. Type is one of . or .
- * ocfs_journal_dirty - Mark a journalled buffer as having dirty data.
- * ocfs_journal_add_lock - Sometimes we need to delay lock release
- * until after a transaction has been completed. Use
- * ocfs_journal_add_lock to indicate that a lock needs
- * to be released at the end of that handle. Locks
- * will be released in the order that they are added.
- * ocfs_handle_add_inode - Add a locked inode to a transaction.
- */
-/* You must always start_trans with a number of buffs > 0, but it's
- * perfectly legal to go through an entire transaction without having
- * dirtied any buffers. */
-ocfs_journal_handle *ocfs_start_trans(struct _ocfs_super *osb, int max_buffs);
-void ocfs_commit_trans(ocfs_journal_handle *handle);
-void ocfs_abort_trans(ocfs_journal_handle *handle);
-/*
- * Create access is for when we get a newly created buffer and we're
- * not gonna read it off disk, but rather fill it ourselves. If it's
- * not part of an already commiting transaction, we'll mark it to be
- * passed to journal_forget in case of abort. Otherwise, it's treated
- * just like a OCFS_JOURNAL_ACCESS_WRITE buffer.
- *
- * Write access is for when we read a block off disk and are going to
- * modify it. This way the journalling layer knows it may need to make
- * a copy of that block (if it's part of another, uncommited
- * transaction) before we do so.
- */
-#define OCFS_JOURNAL_ACCESS_CREATE 0
-#define OCFS_JOURNAL_ACCESS_WRITE 1
-#define OCFS_JOURNAL_ACCESS_UNDO 2
-int ocfs_journal_access(ocfs_journal_handle *handle,
- struct buffer_head *bh, int type);
-/*
- * A word about the journal_access/journal_dirty "dance". It is
- * entirely legal to journal_access a buffer more than once (as long
- * as the access type is the same -- I'm not sure what will happen if
- * access type is different but this should never happen anyway) It is
- * also legal to journal_dirty a buffer more than once. In fact, you
- * can even journal_access a buffer after you've done a
- * journal_access/journal_dirty pair. The only thing you cannot do
- * however, is journal_dirty a buffer which you haven't yet passed to
- * journal_access at least once.
- *
- * That said, 99% of the time this doesn't matter and this is what the
- * path looks like:
- *
- * <read a bh>
- * ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
- * <modify the bh>
- * ocfs_journal_dirty(handle, bh);
- */
-int ocfs_journal_dirty(ocfs_journal_handle *handle,
- struct buffer_head *bh);
-void ocfs_journal_add_lock(ocfs_journal_handle *handle,
- __u32 type, __u32 flags,
- struct buffer_head *bh,
- struct inode *inode);
-/*
- * Some transactions require us to leave inodes in a locked state
- * until we either commit or abort because the buffer state can change
- * in abort_trans. Use this function to lock those inodes and put them
- * on the handle where they'll be cleaned up after the transaction
- * completes.
- */
-void ocfs_handle_add_inode(ocfs_journal_handle *handle,
- struct inode *inode);
-
-/*
- * Credit Macros:
- * Convenience macros to calculate number of credits needed.
- *
- * For convenience sake, I have a set of macros here which calculate
- * the *maximum* number of sectors which will be changed for various
- * metadata updates. I also have a completely arbitrary 'fuzz' value
- * which I'll add to some of these in case of a miscalculation. The
- * journal is large enough, and we don't journal as much metadata
- * that I'm not worried about the 'fuzz' taking up potential credits.
- */
-#define OCFS_JOURNAL_FUZZ_CREDITS (5)
-#define OCFS_SINGLE_FILE_EXTEND_CREDITS (10)
-
-/* locknode + new fe + dirnode head + new dirnode for parent directory
- * + extending (diralloc, filealloc, dirallocbitmap, fileallocbitmap)
- * + a second dirnode for handling mkdir + 2 * 2 = 4 blocks for
- * setting the bits in the dir alloc bitmap and the metadata alloc
- * bitmap if dir alloc needs to be extended + some fuzz. */
-#define OCFS_MKNOD_CREDITS (1 + 1 + (OCFS_DEFAULT_DIR_NODE_SECTS*2) + \
- (OCFS_SINGLE_FILE_EXTEND_CREDITS * 4) + \
- OCFS_JOURNAL_FUZZ_CREDITS)
-
-/* single file metadata updates * 3 because we might have to extend
- * the file alloc and file alloc bitmap files + possible update to
- * local bitmap. + 2 blocks for bits to set in the metadata alloc
- * bitmap file */
-#define OCFS_FILE_EXTEND_CREDITS (OCFS_SINGLE_FILE_EXTEND_CREDITS * 3 \
- + 1 + 2 + OCFS_JOURNAL_FUZZ_CREDITS)
-
-/* Now that we journal bitmap writes, this might get a bit more
- * complicated, use this function to determine how many credits are
- * needed for an extend. Unfortunately, we're in bytes because the
- * rest of the file system is.
- */
-static inline int ocfs_calc_extend_credits(__u32 bytes_wanted,
- __u32 cluster_size)
-{
- int bitmap_blocks;
- unsigned int bits_wanted;
- bits_wanted = (__u32)OCFS_ALIGN(bytes_wanted, cluster_size) /
- cluster_size;
- /* take advantage of the fact that we always allocate in one
- * large chunk. */
- bitmap_blocks = 1 + OCFS_ALIGN(bits_wanted, OCFS_BITS_IN_CHUNK) /
- OCFS_BITS_IN_CHUNK;
-
- return(bitmap_blocks + OCFS_FILE_EXTEND_CREDITS);
-}
-
-/* fe, anything along new 'edge' of tree + fuzz*/
-#define OCFS_FILE_TRUNCATE_CREDITS (1 + 4 + OCFS_JOURNAL_FUZZ_CREDITS)
-
-/* the file entry + the locknode + possibily the parent dirnode + fuzz */
-#define OCFS_FILE_DELETE_CREDITS (1 + 1 + 1 + OCFS_JOURNAL_FUZZ_CREDITS)
-
-/* need to create a new file and extend it to hold the info for the
- * symlink we add one for a potential write of the main bitmap. Since
- * we wind up with twice the fuzz because we reuse some macros so we
- * subtract one.*/
-#define OCFS_SYMLINK_CREDITS (OCFS_MKNOD_CREDITS + OCFS_FILE_EXTEND_CREDITS \
- + 1 - OCFS_JOURNAL_FUZZ_CREDITS)
-
-/* fe change, locknode change, dirnode head, times two plus a possible
- * delete, three to fix the up_node_hdr_ptr values of any extents
- * below the moved fe, plus a possible dirnode addition in insert_file, and fuzz */
-#define OCFS_FILE_RENAME_CREDITS (2 * (1 + 1 + 1) + OCFS_FILE_DELETE_CREDITS \
- + OCFS_MAX_FILE_ENTRY_EXTENTS \
- + OCFS_JOURNAL_FUZZ_CREDITS + \
- OCFS_DEFAULT_DIR_NODE_SECTS)
-
-/* On very rare open operations (it's a first open and we're not in
- * the open map), we have to change the file entry. */
-#define OCFS_OPEN_CREDITS 1
-
-#endif /* _OCFSJOURNAL_H_ */
Modified: trunk/src/inc/ocfs.h
===================================================================
--- trunk/src/inc/ocfs.h 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/inc/ocfs.h 2004-06-01 22:42:22 UTC (rev 961)
@@ -134,7 +134,6 @@
(((__u64)val % align) ? (align - ((__u64)val % align)): 0))
-#include "journal.h"
#define OCFS_POINTER_SIZE (sizeof(void *))
@@ -822,17 +821,7 @@
#endif
#define OCFS_SB(sb) ((ocfs_super *)OCFS_GENERIC_SB_MEMBER(sb))
-#define LOG_TYPE_DISK_ALLOC 1
-#define LOG_TYPE_RECOVERY 3
-#define LOG_DELETE_ENTRY 8
-#define LOG_MARK_DELETE_ENTRY 9
-#define LOG_FREE_BITMAP 10
-#define LOG_DELETE_NEW_ENTRY 12
-
-#define LOG_RECOVER 1
-#define LOG_CLEANUP 2
-
#define OCFS_MINOR_VERSION (0)
#define OCFS_MAJOR_VERSION (2)
#define OCFS_MINOR_VER_STRING "0"
@@ -1339,6 +1328,8 @@
};
+struct _ocfs_journal;
+
/*
* ocfs_super
*
@@ -2133,7 +2124,6 @@
-#include "io.h"
#define OCFS_FE_CACHE_FLAGS(__osb, __fe) \
({ \
@@ -2170,9 +2160,7 @@
}
-#define ocfs_trace(p) do { printk("Trace in %s line %d called from [<%lx>]\n", __FILE__, __LINE__, __builtin_return_address(0) ); ocfs_show_trace(NULL); } while (0)
-
/*
* Trans Lock:
* Right now OCFS2 only supports a single transaction at a
@@ -2188,6 +2176,9 @@
up(&osb->trans_lock);
}
+typedef struct _ocfs_journal_handle ocfs_journal_handle;
+
#include "proto.h"
+#include "io.h"
#endif /* !OCFS_H */
Copied: trunk/src/inc/ocfs_journal.h (from rev 960, trunk/src/inc/journal.h)
===================================================================
--- trunk/src/inc/journal.h 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/inc/ocfs_journal.h 2004-06-01 22:42:22 UTC (rev 961)
@@ -0,0 +1,381 @@
+/*
+ * journal.h
+ *
+ * Defines journalling api and structures.
+ *
+ * Copyright (C) 2003, 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: Kurt Hackel, Mark Fasheh, Sunil Mushran, Wim Coekaerts,
+ * Manish Singh
+ */
+
+#ifndef _OCFSJOURNAL_H_
+#define _OCFSJOURNAL_H_
+
+#define OCFS_JOURNAL_CURRENT_VERSION 1
+#define OCFS_DEFAULT_COMMIT_INTERVAL (HZ * 5)
+#define OCFS_JOURNAL_DEFAULT_SIZE (8 * ONE_MEGA_BYTE)
+
+#undef OCFS_JOURNAL_USE_CB
+
+enum ocfs_journal_state {
+ OCFS_JOURNAL_FREE = 0,
+ OCFS_JOURNAL_LOADED,
+ OCFS_JOURNAL_IN_SHUTDOWN,
+};
+
+struct _ocfs_super;
+struct _ocfs_file_entry;
+struct _ocfs_journal_handle;
+
+/* most of the ocfs_journal structure is protected by the
+ * trans_lock. BEWARE. */
+typedef struct _ocfs_journal ocfs_journal;
+struct _ocfs_journal {
+ enum ocfs_journal_state state; /* Journals current state */
+
+ journal_t *k_journal; /* The kernels journal type */
+ struct inode *k_inode; /* Kernel inode pointing to
+ * this journal */
+ __u8 version; /* Journal version */
+ __u64 lock_id; /* Lock id for journal file */
+ struct _ocfs_super *osb; /* pointer to the super
+ * block for the node
+ * we're currently
+ * running on -- not
+ * necessarily the super
+ * block from the node
+ * which we usually run
+ * from (recovery,
+ * etc) */
+ __u32 node_num; /* Whose journal are we? */
+ struct buffer_head *lockbh; /* Journal disk lock, used
+ to access file entry */
+ atomic_t num_trans; /* Number of transactions
+ * currently in the system. */
+ struct _ocfs_journal_handle *curr; /* pointer to currently
+ * running handle. In
+ * the future when we do
+ * multiple concurrent
+ * transactions this may
+ * become a list.*/
+ /* locking order: trans_lock -> commit_sem -> journal.curr.list_lock */
+ struct semaphore commit_sem; /* protects *everything*
+ * in the commited list
+ * and also protects
+ * 'curr' from
+ * removal/creation. */
+ struct list_head commited; /* doubly linked list of all
+ * commited handles awaiting
+ * checkpointing. */
+};
+
+typedef struct _ocfs_journal_lock ocfs_journal_lock;
+struct _ocfs_journal_lock {
+ __u32 type;
+ __u32 flags;
+ struct buffer_head *bh;
+ struct inode *inode;
+ struct list_head lock_list;
+};
+
+typedef struct _ocfs_journal_copyout ocfs_journal_copyout;
+struct _ocfs_journal_copyout {
+ __u8 forget; /* should we journal_forget this
+ * buffer instead? */
+ unsigned long blocknr; /* what block is this for? */
+ char *data; /* the actual data */
+};
+
+#define ocfs_handle_free_all_copyout(handle) \
+do { \
+ while (handle->num_co) { \
+ handle->num_co--; \
+ if (handle->co_buffs[handle->num_co].data) \
+ ocfs_free(handle->co_buffs[handle->num_co].data); \
+ } \
+ ocfs_free(handle->co_buffs); \
+ handle->co_buffs = NULL; \
+} while (0)
+
+struct _ocfs_journal_handle {
+ handle_t *k_handle; /* kernel handle. */
+ ocfs_journal *journal;
+ struct _ocfs_super *osb; /* what super block we belong to */
+ __u32 flags; /* see flags below. */
+ struct list_head h_list; /* points to whatever list we're
+ * on. */
+ int max_buffs; /* Buffs reserved by this handle */
+
+ /* We know how many buffers (max) we'll have for this
+ * transaction so we can just allocate an array of pointers at
+ * the same time as the creation of this handle. */
+ int num_buffs;
+ struct buffer_head **buffs;
+
+ /* The following three fields are for ocfs_journal_add_lock */
+ spinlock_t list_lock; /* Used to protect the 'locks'
+ * list. Only used if the
+ * handle is the same as
+ * journal->curr. otherwise, we
+ * should be in the commited
+ * list in which case we're
+ * protected by commit_sem */
+ int num_locks;
+ struct list_head locks; /* A bunch of locks to
+ * release on commit/abort. This
+ * should be a list_head */
+
+ int num_co;
+ ocfs_journal_copyout *co_buffs; /* Copy-out buffers. On 1st
+ * journal_access of a buffer
+ * we make a copy of it into
+ * one of these. That way if we
+ * abort we can place the
+ * original copy back into the
+ * buffer. */
+
+ struct _ocfs_bitmap_free_head *commit_bits; /* bits to be
+ * freed ONLY if
+ * we commit the
+ * handle. */
+ __u64 new_file_lockid; /* offset for the
+ * most recently
+ * created file
+ * sitting on this
+ * journal handle */
+ struct list_head inode_list;
+};
+
+/* should we checkpoint this handle on commit? */
+#define OCFS_HANDLE_CHECKPOINT 1
+/* should we sync-commit this handle? */
+#define OCFS_HANDLE_SYNC 2
+/* was local alloc used (should we release the sem?) */
+#define OCFS_HANDLE_LOCAL_ALLOC 4
+
+static inline void ocfs_handle_set_checkpoint(ocfs_journal_handle *handle,
+ int checkpoint)
+{
+ if (checkpoint)
+ handle->flags |= OCFS_HANDLE_CHECKPOINT;
+ else
+ handle->flags &= ~OCFS_HANDLE_CHECKPOINT;
+}
+
+static inline void ocfs_handle_set_sync(ocfs_journal_handle *handle, int sync)
+{
+ if (sync)
+ handle->flags |= OCFS_HANDLE_SYNC;
+ else
+ handle->flags &= ~OCFS_HANDLE_SYNC;
+}
+
+/* TODO: turn both of these into static inlines, once the include file
+ * mess is sorted out. */
+#define ocfs_handle_add_commit_bits(handle, len, fileoff, nodenum, type) \
+({ \
+ int rv = 0; \
+ if (!handle->commit_bits) \
+ handle->commit_bits = ocfs_alloc_bitmap_free_head(); \
+ \
+ if (!handle->commit_bits) \
+ rv = -ENOMEM; \
+ else \
+ rv = ocfs_add_to_bitmap_free_head(handle->osb, \
+ handle->commit_bits, \
+ len, fileoff, nodenum, \
+ type); \
+ rv; \
+})
+
+
+/*
+ * Journal Control:
+ * Initialize, Load, Shutdown, Wipe, Create a journal.
+ *
+ * ocfs_journal_init - Initialize journal structures in the OSB.
+ * ocfs_journal_load - Load the given journal off disk. Replay it if
+ * there's transactions still in there.
+ * ocfs_journal_shutdown - Shutdown a journal, this will flush all
+ * uncommited, uncheckpointed transactions.
+ * ocfs_journal_wipe - Wipe transactions from a journal. Optionally
+ * zero out each block.
+ * ocfs_recovery_thread - Perform recovery on a node. osb is our own osb.
+ */
+int ocfs_journal_init(struct _ocfs_super *osb);
+void ocfs_journal_shutdown(struct _ocfs_super *osb);
+int ocfs_journal_wipe(ocfs_journal *journal, int full);
+int ocfs_journal_load(ocfs_journal *journal);
+void ocfs_recovery_thread(struct _ocfs_super *osb, int node_num);
+int ocfs_journal_new_file_search(struct _ocfs_super *osb, __u64 lockid);
+
+/*
+ * Transaction Handling:
+ * Manage the lifetime of a transaction handle.
+ *
+ * ocfs_start_trans - Begin a transaction. Give it an upper estimate of
+ * the number of blocks that will be changed during
+ * this handle.
+ * ocfs_commit_trans - Complete a handle.
+ * ocfs_abort_trans - Abort a running handle.
+ * ocfs_journal_access - Notify the handle that we want to journal this
+ * buffer. Will have to call ocfs_journal_dirty once
+ * we've actually dirtied it. Type is one of . or .
+ * ocfs_journal_dirty - Mark a journalled buffer as having dirty data.
+ * ocfs_journal_add_lock - Sometimes we need to delay lock release
+ * until after a transaction has been completed. Use
+ * ocfs_journal_add_lock to indicate that a lock needs
+ * to be released at the end of that handle. Locks
+ * will be released in the order that they are added.
+ * ocfs_handle_add_inode - Add a locked inode to a transaction.
+ */
+/* You must always start_trans with a number of buffs > 0, but it's
+ * perfectly legal to go through an entire transaction without having
+ * dirtied any buffers. */
+ocfs_journal_handle *ocfs_start_trans(struct _ocfs_super *osb, int max_buffs);
+void ocfs_commit_trans(ocfs_journal_handle *handle);
+void ocfs_abort_trans(ocfs_journal_handle *handle);
+/*
+ * Create access is for when we get a newly created buffer and we're
+ * not gonna read it off disk, but rather fill it ourselves. If it's
+ * not part of an already commiting transaction, we'll mark it to be
+ * passed to journal_forget in case of abort. Otherwise, it's treated
+ * just like a OCFS_JOURNAL_ACCESS_WRITE buffer.
+ *
+ * Write access is for when we read a block off disk and are going to
+ * modify it. This way the journalling layer knows it may need to make
+ * a copy of that block (if it's part of another, uncommited
+ * transaction) before we do so.
+ */
+#define OCFS_JOURNAL_ACCESS_CREATE 0
+#define OCFS_JOURNAL_ACCESS_WRITE 1
+#define OCFS_JOURNAL_ACCESS_UNDO 2
+int ocfs_journal_access(ocfs_journal_handle *handle,
+ struct buffer_head *bh, int type);
+/*
+ * A word about the journal_access/journal_dirty "dance". It is
+ * entirely legal to journal_access a buffer more than once (as long
+ * as the access type is the same -- I'm not sure what will happen if
+ * access type is different but this should never happen anyway) It is
+ * also legal to journal_dirty a buffer more than once. In fact, you
+ * can even journal_access a buffer after you've done a
+ * journal_access/journal_dirty pair. The only thing you cannot do
+ * however, is journal_dirty a buffer which you haven't yet passed to
+ * journal_access at least once.
+ *
+ * That said, 99% of the time this doesn't matter and this is what the
+ * path looks like:
+ *
+ * <read a bh>
+ * ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
+ * <modify the bh>
+ * ocfs_journal_dirty(handle, bh);
+ */
+int ocfs_journal_dirty(ocfs_journal_handle *handle,
+ struct buffer_head *bh);
+void ocfs_journal_add_lock(ocfs_journal_handle *handle,
+ __u32 type, __u32 flags,
+ struct buffer_head *bh,
+ struct inode *inode);
+/*
+ * Some transactions require us to leave inodes in a locked state
+ * until we either commit or abort because the buffer state can change
+ * in abort_trans. Use this function to lock those inodes and put them
+ * on the handle where they'll be cleaned up after the transaction
+ * completes.
+ */
+void ocfs_handle_add_inode(ocfs_journal_handle *handle,
+ struct inode *inode);
+
+/*
+ * Credit Macros:
+ * Convenience macros to calculate number of credits needed.
+ *
+ * For convenience sake, I have a set of macros here which calculate
+ * the *maximum* number of sectors which will be changed for various
+ * metadata updates. I also have a completely arbitrary 'fuzz' value
+ * which I'll add to some of these in case of a miscalculation. The
+ * journal is large enough, and we don't journal as much metadata
+ * that I'm not worried about the 'fuzz' taking up potential credits.
+ */
+#define OCFS_JOURNAL_FUZZ_CREDITS (5)
+#define OCFS_SINGLE_FILE_EXTEND_CREDITS (10)
+
+/* locknode + new fe + dirnode head + new dirnode for parent directory
+ * + extending (diralloc, filealloc, dirallocbitmap, fileallocbitmap)
+ * + a second dirnode for handling mkdir + 2 * 2 = 4 blocks for
+ * setting the bits in the dir alloc bitmap and the metadata alloc
+ * bitmap if dir alloc needs to be extended + some fuzz. */
+#define OCFS_MKNOD_CREDITS (1 + 1 + (OCFS_DEFAULT_DIR_NODE_SECTS*2) + \
+ (OCFS_SINGLE_FILE_EXTEND_CREDITS * 4) + \
+ OCFS_JOURNAL_FUZZ_CREDITS)
+
+/* single file metadata updates * 3 because we might have to extend
+ * the file alloc and file alloc bitmap files + possible update to
+ * local bitmap. + 2 blocks for bits to set in the metadata alloc
+ * bitmap file */
+#define OCFS_FILE_EXTEND_CREDITS (OCFS_SINGLE_FILE_EXTEND_CREDITS * 3 \
+ + 1 + 2 + OCFS_JOURNAL_FUZZ_CREDITS)
+
+/* Now that we journal bitmap writes, this might get a bit more
+ * complicated, use this function to determine how many credits are
+ * needed for an extend. Unfortunately, we're in bytes because the
+ * rest of the file system is.
+ */
+static inline int ocfs_calc_extend_credits(__u32 bytes_wanted,
+ __u32 cluster_size)
+{
+ int bitmap_blocks;
+ unsigned int bits_wanted;
+ bits_wanted = (__u32)OCFS_ALIGN(bytes_wanted, cluster_size) /
+ cluster_size;
+ /* take advantage of the fact that we always allocate in one
+ * large chunk. */
+ bitmap_blocks = 1 + OCFS_ALIGN(bits_wanted, OCFS_BITS_IN_CHUNK) /
+ OCFS_BITS_IN_CHUNK;
+
+ return(bitmap_blocks + OCFS_FILE_EXTEND_CREDITS);
+}
+
+/* fe, anything along new 'edge' of tree + fuzz*/
+#define OCFS_FILE_TRUNCATE_CREDITS (1 + 4 + OCFS_JOURNAL_FUZZ_CREDITS)
+
+/* the file entry + the locknode + possibily the parent dirnode + fuzz */
+#define OCFS_FILE_DELETE_CREDITS (1 + 1 + 1 + OCFS_JOURNAL_FUZZ_CREDITS)
+
+/* need to create a new file and extend it to hold the info for the
+ * symlink we add one for a potential write of the main bitmap. Since
+ * we wind up with twice the fuzz because we reuse some macros so we
+ * subtract one.*/
+#define OCFS_SYMLINK_CREDITS (OCFS_MKNOD_CREDITS + OCFS_FILE_EXTEND_CREDITS \
+ + 1 - OCFS_JOURNAL_FUZZ_CREDITS)
+
+/* fe change, locknode change, dirnode head, times two plus a possible
+ * delete, three to fix the up_node_hdr_ptr values of any extents
+ * below the moved fe, plus a possible dirnode addition in insert_file, and fuzz */
+#define OCFS_FILE_RENAME_CREDITS (2 * (1 + 1 + 1) + OCFS_FILE_DELETE_CREDITS \
+ + OCFS_MAX_FILE_ENTRY_EXTENTS \
+ + OCFS_JOURNAL_FUZZ_CREDITS + \
+ OCFS_DEFAULT_DIR_NODE_SECTS)
+
+/* On very rare open operations (it's a first open and we're not in
+ * the open map), we have to change the file entry. */
+#define OCFS_OPEN_CREDITS 1
+
+#endif /* _OCFSJOURNAL_H_ */
Modified: trunk/src/inc/ocfs_log.h
===================================================================
--- trunk/src/inc/ocfs_log.h 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/inc/ocfs_log.h 2004-06-01 22:42:22 UTC (rev 961)
@@ -311,4 +311,12 @@
#define LOG_ERROR_STR(str) LOG_ERROR_ARGS("%s\n", str)
#define LOG_ERROR_STATUS(st) LOG_ERROR_ARGS("status = %d\n", st)
+#define ocfs_trace(p) \
+ do { \
+ printk("Trace in %s line %d called from [<%lx>]\n", \
+ __FILE__, __LINE__, \
+ __builtin_return_address(0) ); \
+ ocfs_show_trace(NULL); \
+ } while (0)
+
#endif /* OCFS_LOG_H */
Modified: trunk/src/inode.c
===================================================================
--- trunk/src/inode.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/inode.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -28,6 +28,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_INODE
Modified: trunk/src/journal.c
===================================================================
--- trunk/src/journal.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/journal.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -28,6 +28,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_JOURNAL
Modified: trunk/src/namei.c
===================================================================
--- trunk/src/namei.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/namei.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -28,6 +28,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_NAMEI
Modified: trunk/src/nm.c
===================================================================
--- trunk/src/nm.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/nm.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -28,6 +28,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
/* Tracing */
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_NM
Modified: trunk/src/super.c
===================================================================
--- trunk/src/super.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/super.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -29,6 +29,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_SUPER
Modified: trunk/src/sysfile.c
===================================================================
--- trunk/src/sysfile.c 2004-06-01 20:56:30 UTC (rev 960)
+++ trunk/src/sysfile.c 2004-06-01 22:42:22 UTC (rev 961)
@@ -29,6 +29,7 @@
#include "inc/ocfs_log.h"
#include "inc/ocfs.h"
+#include "inc/ocfs_journal.h"
#else
#include <dummy.h>
#include <ocfsmalloc.h>
More information about the Ocfs2-commits
mailing list