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

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Jul 26 15:00:04 CDT 2004


Author: mfasheh
Date: 2004-07-26 14:00:02 -0500 (Mon, 26 Jul 2004)
New Revision: 1304

Modified:
   trunk/src/file.c
Log:
* save us some stack in file.c

* remove some useless instructions



Modified: trunk/src/file.c
===================================================================
--- trunk/src/file.c	2004-07-26 01:03:56 UTC (rev 1303)
+++ trunk/src/file.c	2004-07-26 19:00:02 UTC (rev 1304)
@@ -546,10 +546,8 @@
 				   struct inode *inode)
 {
 	int status = 0;
-	int tmpstat;
 	ocfs2_dinode *fileEntry = NULL;
-	int have_disk_lock = 0;
-	__u32 lockFlags = 0;
+	u32 lock_flags = FLAG_FILE_UPDATE;
 	struct buffer_head *bh = NULL;
 	ocfs_journal_handle *handle = NULL;
 
@@ -572,9 +570,6 @@
 		goto leave;
 	}
 
-	/* now we always take an UPDATE lock */
-	lockFlags = FLAG_FILE_UPDATE;
-
 	/* Start a transaction - need a minimal amount of block credits (1) */
 	handle = ocfs_start_trans(osb, 1);
 	if (handle == NULL) {
@@ -585,14 +580,13 @@
 	ocfs_handle_set_checkpoint(handle, 0);
 	ocfs_handle_set_sync(handle, 0);
 
-	status = ocfs_acquire_lock (osb, OCFS_LKM_EXMODE, lockFlags,
+	status = ocfs_acquire_lock (osb, OCFS_LKM_EXMODE, lock_flags,
 				    &bh, inode);
 	if (status < 0) {
 		if (status != -EINTR)
 			LOG_ERROR_STATUS (status);
 		goto leave;
 	}
-	have_disk_lock = 1;
 
 	status = ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
 	if (status < 0) {
@@ -614,25 +608,19 @@
 	}
 
 leave:
-	lockFlags |= FLAG_FILE_UPDATE_OIN;
 
 	if (handle) {
-		if (status < 0) {
-			ocfs_abort_trans(handle);
-		} else {
-			ocfs_handle_add_lock(handle, OCFS_LKM_EXMODE, 
-					     lockFlags, bh, inode, 0);
-			have_disk_lock = 0;
+		if (!status)
+			lock_flags |= FLAG_FILE_UPDATE_OIN;
 
+		ocfs_handle_add_lock(handle, OCFS_LKM_EXMODE, 
+				     lock_flags, bh, inode, 0);
+
+		if (status < 0)
+			ocfs_abort_trans(handle);
+		else
 			ocfs_commit_trans(handle);
-		}
 	}
-	if (have_disk_lock) {
-		tmpstat = ocfs_release_lock (osb, OCFS_LKM_EXMODE,
-					     lockFlags, bh, inode);
-		if (tmpstat < 0)
-			LOG_ERROR_STATUS (tmpstat);
-	}
 
 	if (bh != NULL)
 		brelse(bh);
@@ -925,9 +913,8 @@
 static int ocfs_truncate_file(ocfs_super *osb, __u64 file_size,
 			      struct inode *inode)
 {
-	int status = 0, tmpstat;
+	int status = 0;
 	ocfs2_dinode *fe = NULL;
-	int have_disk_lock = 0;
 	__u64 new_alloc_size;
 	struct buffer_head *bh = NULL;
 	ocfs_journal_handle *handle = NULL;
@@ -971,7 +958,9 @@
 			LOG_ERROR_STATUS (status);
 		goto leave;
 	}
-	have_disk_lock = 1;
+	ocfs_handle_add_lock(handle, OCFS_LKM_EXMODE, 
+			     FLAG_FILE_TRUNCATE|FLAG_FILE_UPDATE_OIN, bh, 
+			     inode, 0);
 
 	/* add this fe to the journal transaction */
 	status = ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
@@ -1028,13 +1017,6 @@
 	else if (handle)
 		ocfs_abort_trans(handle);
 
-	if (have_disk_lock) {
-		tmpstat = ocfs_release_lock (osb, OCFS_LKM_EXMODE,
-					     FLAG_FILE_TRUNCATE|FLAG_FILE_UPDATE_OIN, bh, inode);
-		if (tmpstat < 0)
-			LOG_ERROR_STATUS (tmpstat);
-	}
-
 	if (bh != NULL)
 		brelse(bh);
 
@@ -1056,15 +1038,12 @@
 		     int system_file, struct buffer_head *fe_bh)
 {
 	int status = 0;
-	int tmpstat;
 	ocfs2_dinode *fe;
 	__u64 tempOffset = 0;
 	__u64 current_alloc;
 	__u64 alloc_size;
 	u32 bitmapOffset = 0;
 	u32 numClustersAlloc = 0;
-	__u32 lockFlags = 0;
-	int have_disk_lock = 0;
 	u64 block_off;
 	u64 num_blocks;
 	struct buffer_head *bh = NULL;
@@ -1105,7 +1084,6 @@
 
 	current_alloc = (u64)fe->i_clusters << osb->s_clustersize_bits;
 	alloc_size = file_size - current_alloc;
-	fe = NULL;
 
 	LOG_TRACE_ARGS("current_alloc=%llu, alloc_size=%llu\n",
 		       current_alloc, alloc_size);
@@ -1124,24 +1102,17 @@
 		ocfs_handle_set_checkpoint(handle, 0);
 		ocfs_handle_set_sync(handle, 0);
 
-		/* Grab a lock on the entry found if we have more than
-		 * 1 extents and also make this node the master*/
-		fe = (ocfs2_dinode *) bh->b_data;
-
-		/* now we always take an EXTEND lock */
-		lockFlags = FLAG_FILE_EXTEND;
-
-		brelse(bh);
-		bh = NULL;
-
 		status = ocfs_acquire_lock (osb, OCFS_LKM_EXMODE, 
-					    lockFlags, &bh, inode);
+					    FLAG_FILE_EXTEND, &bh, inode);
 		if (status < 0) {
 			if (status != -EINTR)
 				LOG_ERROR_STATUS (status);
 			goto leave;
 		}
-		have_disk_lock = 1;
+		ocfs_handle_add_lock(handle, 
+				     OCFS_LKM_EXMODE,
+				     FLAG_FILE_EXTEND|FLAG_FILE_UPDATE_OIN, bh,
+				     inode, 0);
 	} else {
 		handle = passed_handle;
 	}
@@ -1152,8 +1123,6 @@
 		goto leave;
 	}
 
-	fe = (ocfs2_dinode *) bh->b_data;
-
 	if (file_size <= (__s64)current_alloc)
 		goto no_alloc;
 
@@ -1200,8 +1169,6 @@
 	num_blocks = ocfs_clusters_to_blocks(osb->sb,
 					     numClustersAlloc);
 
-	fe = NULL;
-
 #define	OCFS_MAX_ZERO_BLOCKS (4096)
 
 	down(&OCFS_I(inode)->ip_sem);
@@ -1285,7 +1252,6 @@
 		LOG_ERROR_STATUS (status);
 		goto leave;
 	}
-	fe = (ocfs2_dinode *) bh->b_data;
 
 	/* update the total allocation size here */
 	fe->i_clusters += numClustersAlloc;
@@ -1330,32 +1296,13 @@
 	}
 
 leave:
-	if (passed_handle == NULL) {
-		if (handle) {
-			if (status < 0) {
-				ocfs_abort_trans(handle);
-			} else {
-				lockFlags |= FLAG_FILE_UPDATE_OIN;
-
-				ocfs_handle_add_lock(handle, 
-						     OCFS_LKM_EXMODE,
-						     lockFlags, bh, inode, 0);
-				have_disk_lock = 0;
-
-				ocfs_commit_trans(handle);
-			}
-		}
+	if ((passed_handle == NULL) && handle) {
+		if (status < 0)
+			ocfs_abort_trans(handle);
+		else 
+			ocfs_commit_trans(handle);
 	}
 
-	if (have_disk_lock) {
-		lockFlags |= FLAG_FILE_UPDATE_OIN;
-
-		tmpstat = ocfs_release_lock (osb, OCFS_LKM_EXMODE,
-					     lockFlags, bh, inode);
-		if (tmpstat < 0)
-			LOG_ERROR_STATUS (tmpstat);
-	}
-
 	if (bh != NULL)
 		LOG_TRACE_ARGS("bh->b_count = %d\n", 
 			       atomic_read(&(bh->b_count)));



More information about the Ocfs2-commits mailing list