[Ocfs2-commits] mfasheh commits r1565 - trunk/src

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Oct 12 16:30:14 CDT 2004


Author: mfasheh
Date: 2004-10-12 16:30:12 -0500 (Tue, 12 Oct 2004)
New Revision: 1565

Modified:
   trunk/src/journal.c
   trunk/src/ocfs_journal.h
Log:
* get rid of abort_trans and all the junk which supported / used it in
  journal.c. yay!



Modified: trunk/src/journal.c
===================================================================
--- trunk/src/journal.c	2004-10-12 21:28:34 UTC (rev 1564)
+++ trunk/src/journal.c	2004-10-12 21:30:12 UTC (rev 1565)
@@ -396,11 +396,7 @@
 	memset(retval, 0, sizeof(*retval));
 
 	retval->max_buffs = 0;
-	retval->num_buffs = 0;
 	retval->num_locks = 0;
-	retval->num_co = 0;
-	retval->buffs = NULL;
-	retval->co_buffs = NULL;
 	retval->k_handle = NULL;
 
 	INIT_LIST_HEAD(&(retval->h_list));
@@ -442,20 +438,6 @@
 		goto done_free;
 	}
 
-	handle->buffs = ocfs_malloc(sizeof(struct buffer_head *) * max_buffs);
-	if (!handle->buffs) {
-		LOG_ERROR_STR("Failed to allocate memory for journal buffs!");
-		goto done_free;
-	}
-	memset(handle->buffs, 0, sizeof(struct buffer_head *) * max_buffs);
-
-	handle->co_buffs = ocfs_malloc(sizeof(ocfs_journal_copyout)*max_buffs);
-	if (!handle->co_buffs) {
-		LOG_ERROR_STR("Failed to allocate memory for journal co_buffs!");
-		goto done_free;
-	}
-	memset(handle->co_buffs, 0, sizeof(ocfs_journal_copyout) * max_buffs);
-
 	handle->max_buffs = max_buffs;
 
 	down_read(&osb->journal->trans_barrier);
@@ -481,9 +463,6 @@
 
 	if (handle) {
 		ocfs_commit_unstarted_handle(handle);
-
-		if (handle->buffs)
-			kfree(handle->buffs);
 		kfree(handle);
 	}
 	LOG_EXIT_PTR(NULL);
@@ -545,7 +524,7 @@
 	}								\
 } while (0)
 
-/* This is trivial so we do it out of the main commit/abort
+/* This is trivial so we do it out of the main commit
  * paths. Beware, it can be called from start_trans too! */
 static void ocfs_commit_unstarted_handle(ocfs_journal_handle *handle)
 {
@@ -554,8 +533,6 @@
 	LOG_ENTRY();
 
 	OCFS_ASSERT(!(handle->flags & OCFS_HANDLE_STARTED));
-	OCFS_ASSERT(!handle->num_co);
-	OCFS_ASSERT(!handle->num_buffs);
 
 	ocfs_handle_unlock_inodes(handle);
 	/* You are allowed to add journal locks before the transaction
@@ -579,8 +556,9 @@
 	ocfs_super *osb;
 	handle_t *kern_handle;
 	transaction_t *kern_trans;
-	int retval, i, sync;
+	int retval, sync;
 	ocfs_journal *journal;
+
 	LOG_ENTRY();
 
 	OCFS_ASSERT(handle);
@@ -596,9 +574,6 @@
 	journal = osb->journal;
 	sync = handle->flags & OCFS_HANDLE_SYNC;
 
-	LOG_TRACE_ARGS("Commiting %d blocks, sync = %s\n", handle->num_buffs, 
-		       sync ? "true" : "false");
-
 	if (sync)
 		kern_handle->h_sync = 1;
 	else
@@ -625,160 +600,13 @@
 
 	handle->k_handle = NULL; /* it's been free'd in journal_stop */
 
-	if (handle->flags & OCFS_HANDLE_MAY_ABORT) {
-		for(i = 0; i < handle->num_buffs; i++) {
-			brelse(handle->buffs[i]);
-			handle->buffs[i] = NULL;
-		}
-	}
-	handle->num_buffs = 0;
-	if (handle->buffs) {
-		kfree(handle->buffs);
-		handle->buffs = NULL;
-	}
-
-	/* At this point, we don't need the copyout buffers. */
-	ocfs_handle_free_all_copyout(handle);
-
-/* done: */
-
 	kfree(handle);
-
 bail:
 	LOG_EXIT();
 
 	return;
 } /* ocfs_commit_trans */
 
-/*
- * ocfs_abort_trans
- */
-void ocfs_abort_trans(ocfs_journal_handle * handle) 
-{
-	struct buffer_head *bh;
-	ocfs_super *osb = NULL;
-	int i;
-	int retval;
-	ocfs_journal * journal = NULL;
-	int j;
-	ocfs_journal_copyout *co = NULL;
-	char *data;
-	int dirtied;
-
-	LOG_ENTRY();
-
-	OCFS_ASSERT(handle);
-	OCFS_ASSERT(handle->flags & OCFS_HANDLE_MAY_ABORT);
-
-	if (!(handle->flags & OCFS_HANDLE_STARTED)) {
-		ocfs_commit_unstarted_handle(handle);
-		goto bail;
-	}
-
-	osb = handle->osb;
-	journal = osb->journal;
-
-	if (handle->num_co < handle->num_buffs)
-		BUG();
-
-	/* Ok, we're aborting. For all buffers I've seen, we want to
-	 * either forget it, or copy our old data back in. This should
-	 * revert what happened during the transaction.*/
-	for(i = 0; i < handle->num_co; i++) {
-		co = &(handle->co_buffs[i]);
-
-		/* Ok, search the dirtied buffers list for this
-		 * block. */
-		bh = NULL;
-		dirtied = 1;
-		for(j = 0; j < handle->num_buffs; j++)
-			if (handle->buffs[j]->b_blocknr == co->blocknr) {
-				bh = handle->buffs[j];
-				break;
-			}
-
-		/* If we didn't have it then it was passed to
-		 * journal_access but never dirtied. We still have to
-		 * process it though as our abort paths may have left
-		 * the buffer with data that needs to be aborted */
-		if (!bh) {
-			/* log_trace_args for tracing, can safely be
-			 * turned off later. */
-			LOG_ERROR_ARGS("block %lu was modified but never "
-				       "dirtied!\n", co->blocknr);
-			bh = sb_getblk(osb->sb, co->blocknr);
-			if (bh == NULL)
-#warning bingo, oops on oom
-				BUG();
-
-			dirtied = 0;
-		}
-
-		LOG_TRACE_ARGS("Aborting block %lu, forget=%u\n", co->blocknr,
-			       co->forget);
-
-		data = bh->b_data;
-		if (co->forget) {
-			/* journal_forget will perform a brelse for us */
-			get_bh(bh);
-			journal_forget(handle->k_handle, bh);
-
-			/* this buffer has changed data which we want to
-			 * consider invalid -- mark the sequence number as
-			 * old. */
-			CLEAR_BH_SEQNUM(bh);
-
-			if (buffer_jbd(bh))
-				LOG_ERROR_ARGS("Buffer %llu has JBD bit set "
-					       "after a journal_forget!\n",
-					       (unsigned long long)bh->b_blocknr);
-
-			lock_buffer(bh);
-			clear_buffer_uptodate(bh);
-			clear_buffer_dirty(bh);
-			unlock_buffer(bh);
-		} else {
-			memcpy(data, co->data, bh->b_size);
-		}
-
-		/* we no longer need the buffer in this case. */
-		if (!dirtied)
-			brelse(bh);
-	}
-
-	/* release inode semaphores we took during this transaction */
-	ocfs_handle_unlock_inodes(handle);
-
-	retval = journal_stop(handle->k_handle);
-	if (retval < 0) {
-		LOG_ERROR_STR("Could not commit aborted transaction!");
-		LOG_ERROR_STATUS(retval);
-	}
-
-	ocfs_handle_move_locks(osb->journal, handle);
-	spin_lock(&osb->journal->cmt_lock);
-	osb->needs_flush = 1;
-	spin_unlock(&osb->journal->cmt_lock);
-
-	up_read(&journal->trans_barrier);
-
-	handle->k_handle = NULL;
-
-/* done: */
-	ocfs_handle_free_all_copyout(handle);
-
-	for(i = 0; i < handle->num_buffs; i++)
-		brelse(handle->buffs[i]);
-
-	if (handle->buffs)
-		kfree(handle->buffs);
-	kfree(handle);
-
-bail:
-	LOG_EXIT();
-	return;
-} /* ocfs_abort_trans */
-
 /* 
  * 'nblocks' is what you want to add to the current
  * transaction. extend_trans will either extend the current handle by
@@ -793,10 +621,7 @@
  */
 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;
+	int status;
 
 	OCFS_ASSERT(handle);
 	OCFS_ASSERT(handle->flags & OCFS_HANDLE_STARTED);
@@ -822,66 +647,10 @@
 			LOG_ERROR_STATUS(status);
 			goto bail;
 		}
+		handle->max_buffs = nblocks;
+	} else
+		handle->max_buffs += nblocks;
 
-		restarted = 1;
-		new_num_co = 0;
-		new_num_buffs = 0;
-		new_max_buffs = nblocks;
-	} 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) {
-		if (handle->num_buffs)
-			memcpy(new_buffs, handle->buffs, 
-			       sizeof(*new_buffs) * handle->num_buffs);
-		if (handle->num_co)
-			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_MAY_ABORT) {
-			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->buffs = new_buffs;
-	handle->num_buffs = new_num_buffs;
-	handle->max_buffs = new_max_buffs;
-	handle->co_buffs = new_co_buffs;
-	handle->num_co = new_num_co;
 	status = 0;
 bail:
 
@@ -895,8 +664,6 @@
 int ocfs_journal_access(ocfs_journal_handle *handle, struct buffer_head *bh, int type) 
 {
 	int status;
-	int i;
-	int found = 0;
 
 	OCFS_ASSERT(handle);
 	OCFS_ASSERT(bh);
@@ -917,71 +684,6 @@
 		BUG();
 	}
 
-	/* the copyout junk is only for abort... */
-	if (!(handle->flags & OCFS_HANDLE_MAY_ABORT))
-		goto skip_copyout;
-
-	/* search for this buffer in our copyout list. If it's already
-	 * there, we need to do nothing. Otherwise, add it to the
-	 * handle. 
-	 *
-	 * Note that we want to make a copy of the buffer on the 1st access
-	 * call as that's when we know for sure it's clean. */
-	for (i = 0; i < handle->num_co; i++) {
-		if (handle->co_buffs[i].blocknr == bh->b_blocknr) {
-			found = 1;
-			break;
-		}
-	}
-
-	if (!found) {
-		i = handle->num_co;
-		handle->num_co++;
-
-		if (handle->num_co > handle->max_buffs) {
-			printk("ocfs2: Block %llu exceeds maximum handle "
-			       "credits of %u!\n",
-			       (unsigned long long)bh->b_blocknr,
-			       handle->max_buffs);
-			BUG();
-		}
-
-		handle->co_buffs[i].blocknr = bh->b_blocknr;
-
-		/* The buffer has no copy out, we have two choices below.
-		 *
-		 * If we haven't read the buffer off disk (like in a
-		 * create where we're going to completely fill in the
-		 * bh anyway), and we know that the buffer isn't in
-		 * JBD for another transaction, then we can just
-		 * perform a journal_forget at abort time instead of
-		 * filling it with whatever junk was in memory.
-		 *
-		 * Otherwise, we make a copy of the data in the buffer. */
-		if (!buffer_jbd(bh) && type == OCFS_JOURNAL_ACCESS_CREATE) {
-			LOG_TRACE_ARGS("Making block (%llu) a forget block at "
-				       "position %d\n",
-				       (unsigned long long)bh->b_blocknr, i);
-			handle->co_buffs[i].data = NULL;
-			handle->co_buffs[i].forget = 1;
-		} else {
-			/* WRITE or UNDO access */
-			LOG_TRACE_ARGS("Copying block (%llu) out to position "
-				       "%d\n",
-				       (unsigned long long)bh->b_blocknr, i);
-
-			/* This malloc should just be a slab. */
-			handle->co_buffs[i].data = ocfs_malloc(bh->b_size);
-			if (handle->co_buffs[i].data == NULL) {
-				status = -ENOMEM;
-				goto done;
-			}
-			memcpy(handle->co_buffs[i].data, bh->b_data,
-			       bh->b_size);
-		}
-	}
-
-skip_copyout:
 	switch (type) {
 	case OCFS_JOURNAL_ACCESS_CREATE:
 	case OCFS_JOURNAL_ACCESS_WRITE:
@@ -997,14 +699,13 @@
 		LOG_ERROR_STR("Uknown access type!");
 		goto done;
 	}
-	
+
 	if (status < 0) {
-		LOG_ERROR_ARGS("Error getting %s access to buffer!\n", 
-			       (type == OCFS_JOURNAL_ACCESS_CREATE ? "create" : "write"));
+		LOG_ERROR_ARGS("Error %d getting %d access to buffer!\n",
+			       status, type);
 		goto done;
 	}
 
-	status = 0;
 done:
 	LOG_EXIT_STATUS(status);
 	return(status);
@@ -1017,56 +718,23 @@
  */
 int ocfs_journal_dirty(ocfs_journal_handle *handle, struct buffer_head *bh) 
 {
-	int status = -EINVAL;
-	int i = 0;
+	int status;
 
 	OCFS_ASSERT((handle->flags & OCFS_HANDLE_STARTED));
 
 	LOG_ENTRY_ARGS("(bh->b_blocknr=%llu)\n",
 			(unsigned long long)bh->b_blocknr);
 
-	if (!(handle->flags & OCFS_HANDLE_MAY_ABORT))
-		goto call_jbd;
-
-	/* 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.
-	 */
-	for(i = 0; i < handle->num_buffs; i++) {
-		if (handle->buffs[i] == bh) {
-			LOG_TRACE_ARGS("block (%llu) already added to dirty "
-				       "list!\n",
-				       (unsigned long long)bh->b_blocknr);
-			goto call_jbd;
-		}
-	}
-
-	OCFS_ASSERT(handle->num_buffs < handle->max_buffs);
-
-	i = handle->num_buffs;
-	/* Increase the ref count on this buffer. We
-	 * do this because we still want to keep them
-	 * around in case of abort */
-	get_bh(bh);
-	handle->buffs[i] = bh;
-	handle->num_buffs++;
-
-call_jbd:
 	status = journal_dirty_metadata(handle->k_handle, bh);
-	if (status < 0) {
+	if (status < 0)
 		LOG_ERROR_ARGS("Could not dirty metadata buffer. "
 			       "(bh->b_blocknr=%llu)\n",
 			       (unsigned long long)bh->b_blocknr);
-		goto done;
-	}
 
-	status = 0;
-done:
 	LOG_EXIT_STATUS(status);
 	return(status);
 } /* ocfs_journal_dirty */
 
-
 void ocfs_handle_add_lock(ocfs_journal_handle *handle, __u32 type, 
 			  __u32 flags, struct inode *inode)
 {

Modified: trunk/src/ocfs_journal.h
===================================================================
--- trunk/src/ocfs_journal.h	2004-10-12 21:28:34 UTC (rev 1564)
+++ trunk/src/ocfs_journal.h	2004-10-12 21:30:12 UTC (rev 1565)
@@ -166,14 +166,6 @@
 	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 */
-};
-
 struct _ocfs_journal_handle {
 	handle_t            *k_handle; /* kernel handle.                */
 	ocfs_journal        *journal;
@@ -183,54 +175,23 @@
 					* 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.
-	 *
-	 * NOTE: 'num_buffs' will always be zero if your transaction
-	 * is roll-forward only. */
-	int                 num_buffs;
-	struct buffer_head  **buffs;
-
 	/* The following two fields are for ocfs_handle_add_lock */
 	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 list_head     inode_list;
 };
 
 #define OCFS_HANDLE_STARTED			1
 /* should we sync-commit this handle? */
 #define OCFS_HANDLE_SYNC			2
-/* ocfs_abort_trans is mostly a relic at this point. */
-#define OCFS_HANDLE_MAY_ABORT			4
 static inline int ocfs_handle_started(ocfs_journal_handle *handle)
 {
 	return handle->flags & OCFS_HANDLE_STARTED;
 }
 
-static inline void ocfs_handle_free_all_copyout(ocfs_journal_handle *handle)
-{
-	while (handle->num_co) {
-		handle->num_co--;
-		if (handle->co_buffs[handle->num_co].data)
-			kfree(handle->co_buffs[handle->num_co].data);
-	}
-	kfree(handle->co_buffs);
-	handle->co_buffs = NULL;
-}
-
 static inline void ocfs_handle_set_sync(ocfs_journal_handle *handle, int sync)
 {
 	if (sync)
@@ -239,15 +200,6 @@
 		handle->flags &= ~OCFS_HANDLE_SYNC;
 }
 
-static inline void ocfs_handle_set_may_abort(ocfs_journal_handle *handle, 
-					     int aborts)
-{
-	if (aborts)
-		handle->flags |= OCFS_HANDLE_MAY_ABORT;
-	else
-		handle->flags &= ~OCFS_HANDLE_MAY_ABORT;
-}
-
 /*
  *  Journal Control:
  *  Initialize, Load, Shutdown, Wipe, Create a journal.
@@ -281,7 +233,6 @@
  *                          the number of blocks that will be changed during 
  *                          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.
@@ -304,7 +255,6 @@
 				      ocfs_journal_handle *handle, 
 				      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);
 



More information about the Ocfs2-commits mailing list