[Ocfs2-commits] mfasheh commits r1481 - branches/dlm-changes/src
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Sep 24 17:50:22 CDT 2004
Author: mfasheh
Date: 2004-09-24 17:50:20 -0500 (Fri, 24 Sep 2004)
New Revision: 1481
Modified:
branches/dlm-changes/src/journal.c
branches/dlm-changes/src/ocfs_journal.h
Log:
* optimize more in journal_dirty for the always-commits case
* add ocfs_extend_trans, so our alloc path can continue try to continue
an allocation transaction when it runs out of credits.
* add some credits macros for group alloc stuff and the new data allocation
stuff.
* some api changes which will be completed in a later commit.
Modified: branches/dlm-changes/src/journal.c
===================================================================
--- branches/dlm-changes/src/journal.c 2004-09-24 22:44:35 UTC (rev 1480)
+++ branches/dlm-changes/src/journal.c 2004-09-24 22:50:20 UTC (rev 1481)
@@ -426,6 +426,7 @@
BUG();
OCFS_ASSERT(osb->journal->state != OCFS_JOURNAL_FREE);
+ OCFS_ASSERT(max_buffs > 0);
/* JBD might support this, but our journalling code doesn't yet. */
if (journal_current_handle()) {
@@ -644,9 +645,11 @@
handle->k_handle = NULL; /* it's been free'd in journal_stop */
- for(i = 0; i < handle->num_buffs; i++) {
- brelse(handle->buffs[i]);
- handle->buffs[i] = NULL;
+ if (!(handle->flags & OCFS_HANDLE_ALWAYS_COMMITS)) {
+ for(i = 0; i < handle->num_buffs; i++) {
+ brelse(handle->buffs[i]);
+ handle->buffs[i] = NULL;
+ }
}
handle->num_buffs = 0;
if (handle->buffs) {
@@ -806,6 +809,110 @@
return;
} /* ocfs_abort_trans */
+/* will either extend the current handle by nblocks, or commit it and
+ * start a new one with nblocks credits.
+ *
+ * WARNING: This will not release any semaphores or disk locks taken
+ * during the transaction, so make sure they were taken *before*
+ * start_trans or we'll have ordering deadlocks.
+ *
+ * This function would be alot simpler if we didn't have to worry
+ * about abort.
+ */
+int ocfs_extend_trans(ocfs_journal_handle *handle, int nblocks)
+{
+ int status, new_max_buffs, new_num_co, new_num_buffs, i;
+ int restarted = 0;
+ struct buffer_head **new_buffs = NULL;
+ ocfs_journal_copyout *new_co_buffs = NULL;
+
+ OCFS_ASSERT(handle);
+ OCFS_ASSERT(handle->flags & OCFS_HANDLE_STARTED);
+ OCFS_ASSERT(nblocks);
+
+ LOG_ENTRY();
+
+ printk("Trying to extend by %d blocks\n", nblocks);
+
+ status = journal_extend(handle->k_handle, nblocks);
+ if (status < 0) {
+ LOG_ERROR_STATUS(status);
+ goto bail;
+ }
+
+ if (status > 0) {
+ status = journal_restart(handle->k_handle, nblocks);
+ if (status < 0) {
+#warning we need to handle this better
+ handle->k_handle = NULL;
+ LOG_ERROR_STATUS(status);
+ goto bail;
+ }
+
+ new_num_buffs = 0;
+ new_num_co = 0;
+ new_max_buffs = nblocks;
+ restarted = 1;
+ } else {
+ new_num_co = handle->num_co;
+ new_num_buffs = handle->num_buffs;
+ new_max_buffs = handle->max_buffs + nblocks;
+ }
+
+ new_buffs = ocfs_malloc(sizeof(struct buffer_head *) * new_max_buffs);
+ if (!new_buffs) {
+ LOG_ERROR_STR("Failed to allocate memory for journal buffs!");
+ goto bail;
+ }
+ memset(new_buffs, 0, sizeof(struct buffer_head *) * new_max_buffs);
+
+ new_co_buffs = ocfs_malloc(sizeof(ocfs_journal_copyout)*new_max_buffs);
+ if (!new_co_buffs) {
+ kfree(new_buffs);
+ LOG_ERROR_STR("Failed to allocate memory for co_buffs!");
+ goto bail;
+ }
+ memset(new_co_buffs, 0, sizeof(ocfs_journal_copyout) * new_max_buffs);
+
+ if (!restarted) {
+ memcpy(new_buffs, handle->buffs,
+ sizeof(*new_buffs) * handle->num_buffs);
+ memcpy(new_co_buffs, handle->co_buffs,
+ sizeof(*new_co_buffs) * handle->num_co);
+ }
+
+ if (restarted) {
+ /* only brelse and free copyout buffers if we restarted. */
+ if (!(handle->flags & OCFS_HANDLE_ALWAYS_COMMITS)) {
+ for(i = 0; i < handle->num_buffs; i++) {
+ brelse(handle->buffs[i]);
+ handle->buffs[i] = NULL;
+ }
+ }
+
+ if (handle->buffs) {
+ kfree(handle->buffs);
+ handle->buffs = NULL;
+ }
+
+ ocfs_handle_free_all_copyout(handle);
+ } else {
+ kfree(handle->buffs);
+ kfree(handle->co_buffs);
+ }
+
+ handle->max_buffs = new_max_buffs;
+ handle->buffs = new_buffs;
+ handle->num_buffs = new_num_buffs;
+ handle->co_buffs = new_co_buffs;
+ handle->num_co = new_num_co;
+ status = 0;
+bail:
+
+ LOG_EXIT_STATUS(status);
+ return(status);
+}
+
/*
* ocfs_journal_access
*/
@@ -933,7 +1040,7 @@
int ocfs_journal_dirty(ocfs_journal_handle *handle, struct buffer_head *bh)
{
int status = -1;
- int i;
+ int i = 0;
OCFS_ASSERT((handle->flags & OCFS_HANDLE_STARTED));
@@ -948,6 +1055,9 @@
goto done;
}
+ if (handle->flags & OCFS_HANDLE_ALWAYS_COMMITS)
+ goto inc_buffs_count;
+
/* First, make sure we aren't already in the list. If we've
* already been added, then that's OK as JBD knows how to
* handle this so just jump ahead.
@@ -967,6 +1077,7 @@
* around in case of abort */
get_bh(bh);
handle->buffs[i] = bh;
+inc_buffs_count:
handle->num_buffs++;
call_jbd:
@@ -975,9 +1086,12 @@
LOG_ERROR_ARGS("Could not dirty metadata buffer. "
"(bh->b_blocknr=%llu)\n",
(unsigned long long)bh->b_blocknr);
- LOG_TRACE_ARGS("Setting handle->buffs[%d] = NULL\n", i);
- brelse(bh);
- handle->buffs[i] = NULL;
+ if (!(handle->flags & OCFS_HANDLE_ALWAYS_COMMITS)) {
+ LOG_TRACE_ARGS("Setting handle->buffs[%d] = NULL\n",
+ i);
+ brelse(bh);
+ handle->buffs[i] = NULL;
+ }
handle->num_buffs--;
goto done;
}
@@ -1690,7 +1804,7 @@
while(offset < orphan_dir_inode->i_size) {
blk = offset >> sb->s_blocksize_bits;
- bh = ocfs_bread(NULL, orphan_dir_inode, blk, 0, &status, 0);
+ bh = ocfs_bread(orphan_dir_inode, blk, &status, 0);
if (!bh)
status = -EINVAL;
if (status < 0) {
Modified: branches/dlm-changes/src/ocfs_journal.h
===================================================================
--- branches/dlm-changes/src/ocfs_journal.h 2004-09-24 22:44:35 UTC (rev 1480)
+++ branches/dlm-changes/src/ocfs_journal.h 2004-09-24 22:50:20 UTC (rev 1481)
@@ -301,6 +301,9 @@
* this handle.
* ocfs_commit_trans - Complete a handle.
* ocfs_abort_trans - Abort a handle.
+ * ocfs_extend_trans - Extend a handle by nblocks credits. This may
+ * commit the handle to disk in the process, but will
+ * not release any locks taken during the transaction.
* 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 .
@@ -321,6 +324,9 @@
int max_buffs);
void ocfs_commit_trans(ocfs_journal_handle *handle);
void ocfs_abort_trans(ocfs_journal_handle *handle);
+int ocfs_extend_trans(ocfs_journal_handle *handle,
+ int nblocks);
+
/*
* 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
@@ -396,7 +402,7 @@
OCFS_JOURNAL_FUZZ_CREDITS)
/* local alloc metadata change + main bitmap updates */
-#define OCFS_WINDOW_MOVE_CREDIT (1 + 8)
+#define OCFS_WINDOW_MOVE_CREDITS (1 + 8 + 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
@@ -405,18 +411,15 @@
#define OCFS_FILE_EXTEND_CREDITS (OCFS_SINGLE_FILE_EXTEND_CREDITS * 3 \
+ 1 + 2 + 8 + 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(struct super_block *sb,
- __u32 bytes_wanted)
+ __u32 bits_wanted)
{
int bitmap_blocks, sysfile_bitmap_blocks;
- unsigned int bits_wanted;
- bits_wanted = ocfs_clusters_for_bytes(sb, bytes_wanted);
/* take advantage of the fact that we always allocate in one
* large chunk. */
bitmap_blocks = ocfs_blocks_for_bits(sb, bits_wanted) + 1;
@@ -437,16 +440,25 @@
return (bitmap_blocks + sysfile_bitmap_blocks + OCFS_FILE_EXTEND_CREDITS);
}
-static inline int ocfs_calc_symlink_credits(struct super_block *sb,
- int size)
+static inline int ocfs_calc_symlink_credits(struct super_block *sb)
{
/* get our fuzz from mknod and extend credits. */
int blocks = OCFS_MKNOD_CREDITS + 1;
- blocks += ocfs_calc_extend_credits(sb, size);
+ blocks += ocfs_calc_extend_credits(sb, 1);
+ blocks += ocfs_clusters_to_blocks(sb, 1);
- blocks += (size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+ return(blocks);
+}
+static inline int ocfs_calc_group_alloc_credits(struct super_block *sb,
+ unsigned int cpg)
+{
+ int blocks;
+ int bitmap_blocks = ocfs_blocks_for_bits(sb, cpg) + 1;
+ /* parent inode update + new block group header + bitmap inode update
+ + bitmap blocks affected */
+ blocks = 1 + 1 + 1 + bitmap_blocks + OCFS_JOURNAL_FUZZ_CREDITS;
return(blocks);
}
More information about the Ocfs2-commits
mailing list