[Ocfs2-commits] mfasheh commits r917 - in trunk/src: . inc
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon May 17 15:28:13 CDT 2004
Author: mfasheh
Date: 2004-05-17 14:28:12 -0500 (Mon, 17 May 2004)
New Revision: 917
Modified:
trunk/src/dcache.c
trunk/src/file.c
trunk/src/inc/journal.h
trunk/src/journal.c
trunk/src/nm.c
Log:
* Cleaned up some unused variables in getattr
* Always just take a cache_lock during extend
* Cleaned up the open path a tiny bit
* Tixed a bunch of StuDlYCapS in file.c
* Take i_sem in setattr only when appropriate
* i_sem was getting dropped early in process_vote, fix that. It's much
more clear now. If you've got an inode (all cases, except
delete/rename release) then it's locked
* Take locks on inodes in commit thread during ocfs_journal_release_locks
* don't hit disk in dentry_revalidate anymore
Modified: trunk/src/dcache.c
===================================================================
--- trunk/src/dcache.c 2004-05-16 17:04:17 UTC (rev 916)
+++ trunk/src/dcache.c 2004-05-17 19:28:12 UTC (rev 917)
@@ -41,10 +41,9 @@
int ocfs_dentry_revalidate (struct dentry *dentry, int flags)
#endif
{
- int tmpstat, ret = 0; /* if all else fails, just return false */
+ int ret = 0; /* if all else fails, just return false */
struct inode *inode = dentry->d_inode;
ocfs_super *osb;
- int needs_trunc;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
int flags = nd ? nd->flags : 0;
#endif
@@ -84,18 +83,10 @@
goto bail;
}
- ret = 1; /* with an oin we cannot fail revalidate */
+ ret = 1;
- /* hit the disk */
- /* TODO: optimize */
- down (&(OCFS_I(inode)->priv_sem));
+ /* TODO: Is this really necessary? */
OCFS_I(inode)->needs_verification = 1;
- tmpstat = ocfs_verify_update_inode(osb, inode, &needs_trunc, 0);
- if (tmpstat < 0)
- LOG_ERROR_STATUS (tmpstat);
- up (&(OCFS_I(inode)->priv_sem));
- if (needs_trunc)
- ocfs_truncate_inode_pages(inode, 0);
bail:
Modified: trunk/src/file.c
===================================================================
--- trunk/src/file.c 2004-05-16 17:04:17 UTC (rev 916)
+++ trunk/src/file.c 2004-05-17 19:28:12 UTC (rev 917)
@@ -93,7 +93,7 @@
int ret =0, err = 0, status = 0;
int mode = file->f_flags;
ocfs_super *osb = NULL;
- int bAcquiredOIN = 0;
+ int have_oin_sem = 0;
struct buffer_head *fe_bh = NULL;
int truncate_pages = 0;
@@ -112,13 +112,12 @@
* inode, and therefore we are given the oin too */
down(&inode->i_sem);
down (&(OCFS_I(inode)->priv_sem));
- bAcquiredOIN = 1;
+ have_oin_sem = 1;
- /* If the in use flag is set, forget about it. This will go
- * eventually. */
if (OCFS_I(inode)->oin_flags & OCFS_OIN_DELETE_ON_CLOSE) {
LOG_ERROR_STR ("oin deleted");
up(&inode->i_sem);
+ status = -ENOENT;
goto leave;
}
@@ -153,25 +152,20 @@
goto leave;
}
}
- up(&inode->i_sem);
- /* yes, hold onto priv_sem. */
- if (OCFS_I(inode)->oin_flags & OCFS_OIN_DELETE_ON_CLOSE) {
- LOG_TRACE_STR ("oin has DELETE_ON_CLOSE set, returning DELETE_PENDING");
- status = -ENOENT;
- goto leave;
- }
-
if (OCFS_I(inode)->needs_verification) {
status = ocfs_verify_update_inode (osb, inode, &truncate_pages,
0);
if (status < 0) {
- /* disable VOLUME TODO */
+ up(&inode->i_sem);
LOG_ERROR_STATUS (status);
goto leave;
}
}
+ up(&inode->i_sem);
+ /* yes, hold onto priv_sem. */
+
if (OCFS_I(inode)->open_hndl_cnt > 0) {
/* The OIN is currently in use by some thread. */
/* We must check whether the requested access/share access */
@@ -211,9 +205,9 @@
OCFS_I(inode)->open_hndl_cnt++;
- if (bAcquiredOIN) {
+ if (have_oin_sem) {
up (&(OCFS_I(inode)->priv_sem));
- bAcquiredOIN = 0;
+ have_oin_sem = 0;
}
if (truncate_pages) {
@@ -229,9 +223,9 @@
status = 0;
leave:
- if (bAcquiredOIN) {
+ if (have_oin_sem) {
up (&(OCFS_I(inode)->priv_sem));
- bAcquiredOIN = 0;
+ have_oin_sem = 0;
}
if (fe_bh)
@@ -412,10 +406,9 @@
int status = 0;
int tmpstat;
ocfs_file_entry *fileEntry = NULL;
- int bAcquiredLock = 0;
+ int have_disk_lock = 0;
__u64 lockId = 0;
__u32 lockFlags = 0, locktype = 0;
- int bCacheLock = 0;
struct buffer_head *bh = NULL;
ocfs_journal_handle *handle = NULL;
int flags = 0;
@@ -437,11 +430,11 @@
goto leave;
}
- /* Acquire the Lock using TCP/IP and disk based locking */
if ((DISK_LOCK_FILE_LOCK (fileEntry) == OCFS_DLM_ENABLE_CACHE_LOCK) &&
- (DISK_LOCK_CURRENT_MASTER (fileEntry) == osb->node_num)) {
- bCacheLock = 1;
- }
+ (DISK_LOCK_CURRENT_MASTER (fileEntry) == osb->node_num))
+ locktype = OCFS_DLM_ENABLE_CACHE_LOCK;
+ else
+ locktype = OCFS_DLM_EXCLUSIVE_LOCK;
/* now we always take an UPDATE lock */
lockId = fileEntry->this_sector;
@@ -458,7 +451,6 @@
ocfs_handle_set_checkpoint(handle, 0);
ocfs_handle_set_sync(handle, 0);
- locktype = bCacheLock ? OCFS_DLM_ENABLE_CACHE_LOCK : OCFS_DLM_EXCLUSIVE_LOCK;
status = ocfs_acquire_lock (osb, lockId, locktype, lockFlags,
&bh, inode);
if (status < 0) {
@@ -466,7 +458,7 @@
LOG_ERROR_STATUS (status);
goto leave;
}
- bAcquiredLock = 1;
+ have_disk_lock = 1;
status = ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
if (status < 0) {
@@ -476,11 +468,6 @@
fileEntry = (ocfs_file_entry *)OCFS_BH_GET_DATA_WRITE(bh); /* write */
- if (bCacheLock) {
- DISK_LOCK_FILE_LOCK (fileEntry) = OCFS_DLM_ENABLE_CACHE_LOCK;
- DISK_LOCK_CURRENT_MASTER (fileEntry) = osb->node_num;
- }
-
fileEntry->modify_time = OCFS_CURRENT_TIME;
DISK_LOCK_SEQNUM (fileEntry) = 0;
@@ -501,7 +488,6 @@
leave:
lockFlags |= FLAG_FILE_UPDATE_OIN;
- locktype = bCacheLock ? OCFS_DLM_ENABLE_CACHE_LOCK : OCFS_DLM_EXCLUSIVE_LOCK;
if (handle) {
if (status < 0) {
@@ -509,12 +495,12 @@
} else {
ocfs_journal_add_lock(handle, locktype, lockFlags,
bh, inode);
- bAcquiredLock = 0;
+ have_disk_lock = 0;
ocfs_commit_trans(handle);
}
}
- if (bAcquiredLock) {
+ if (have_disk_lock) {
tmpstat = ocfs_release_lock (osb, lockId, locktype,
lockFlags, bh, inode);
if (tmpstat < 0)
@@ -734,10 +720,13 @@
}
if (OCFS_I(inode)->needs_verification) {
+ /* yay, locking hell! */
+ down(&inode->i_sem);
down (&(OCFS_I(inode)->priv_sem));
status = ocfs_verify_update_inode (osb, inode, &needs_trunc,
0);
up (&(OCFS_I(inode)->priv_sem));
+ up(&inode->i_sem);
if (needs_trunc)
ocfs_truncate_inode_pages(inode, 0);
if (status < 0) {
@@ -779,9 +768,7 @@
ocfs_file_entry *fe = NULL;
__u64 lockId = 0;
__u32 lockFlags = 0, locktype = 0;
- int bFileLockAcquired = 0;
- int bAcquiredLock = 0;
- int bCacheLock = 0;
+ int have_disk_lock = 0;
__u64 new_alloc_size;
struct buffer_head *bh = NULL;
int flags = 0;
@@ -816,15 +803,16 @@
lockId = fe->this_sector;
lockFlags = FLAG_FILE_TRUNCATE;
- bFileLockAcquired = 1;
if ((DISK_LOCK_FILE_LOCK (fe) == OCFS_DLM_ENABLE_CACHE_LOCK)
- && (DISK_LOCK_CURRENT_MASTER (fe) == osb->node_num)) {
- bCacheLock = 1;
- }
+ && (DISK_LOCK_CURRENT_MASTER (fe) == osb->node_num))
+ locktype = OCFS_DLM_ENABLE_CACHE_LOCK;
+ else
+ locktype = OCFS_DLM_EXCLUSIVE_LOCK;
+
OCFS_BH_PUT_DATA(bh);
- locktype = bCacheLock ? OCFS_DLM_ENABLE_CACHE_LOCK : OCFS_DLM_EXCLUSIVE_LOCK;
+
status = ocfs_acquire_lock (osb, lockId, locktype, lockFlags,
&bh, inode);
if (status < 0) {
@@ -832,7 +820,7 @@
LOG_ERROR_STATUS (status);
goto leave;
}
- bAcquiredLock = 1;
+ have_disk_lock = 1;
/* add this fe to the journal transaction */
status = ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
@@ -871,11 +859,6 @@
goto leave;
}
- if (bCacheLock) {
- DISK_LOCK_FILE_LOCK (fe) = OCFS_DLM_ENABLE_CACHE_LOCK;
- DISK_LOCK_CURRENT_MASTER (fe) = osb->node_num;
- }
-
DISK_LOCK_SEQNUM (fe) = 0;
SET_VALID_BIT (fe->sync_flags);
fe->sync_flags &= ~(OCFS_SYNC_FLAG_CHANGE);
@@ -901,11 +884,9 @@
else if (handle)
ocfs_abort_trans(handle);
- if (bAcquiredLock) {
- if (bFileLockAcquired)
- lockFlags |= FLAG_FILE_UPDATE_OIN;
+ if (have_disk_lock) {
+ lockFlags |= FLAG_FILE_UPDATE_OIN;
- locktype = bCacheLock ? OCFS_DLM_ENABLE_CACHE_LOCK : OCFS_DLM_EXCLUSIVE_LOCK;
tmpstat = ocfs_release_lock (osb, lockId, locktype,
lockFlags, bh, inode);
if (tmpstat < 0)
@@ -938,12 +919,11 @@
__u64 bitmapOffset = 0;
__u64 numClustersAlloc = 0;
__u64 lockId = 0;
- __u32 lockFlags = 0, locktype = 0;
- int bFileLockAcquired = 0;
- int bAcquiredLock = 0;
+ __u32 lockFlags = 0;
+ __u32 locktype = OCFS_DLM_ENABLE_CACHE_LOCK;
+ int have_disk_lock = 0;
__u64 actualDiskOffset = 0;
__u64 actualLength = 0;
- int bCacheLock = 0;
struct buffer_head *bh = NULL;
int flags = 0;
ocfs_journal_handle *handle = NULL;
@@ -995,24 +975,18 @@
/* now we always take an EXTEND lock */
lockId = fileEntry->this_sector;
lockFlags = FLAG_FILE_EXTEND;
- bFileLockAcquired = 1;
-
- if ((DISK_LOCK_FILE_LOCK (fileEntry) == OCFS_DLM_ENABLE_CACHE_LOCK) &&
- (DISK_LOCK_CURRENT_MASTER (fileEntry) == osb->node_num)) {
- bCacheLock = 1;
- }
+
OCFS_BH_PUT_DATA(bh);
brelse(bh);
bh = NULL;
- locktype = bCacheLock ? OCFS_DLM_ENABLE_CACHE_LOCK : OCFS_DLM_EXCLUSIVE_LOCK;
status = ocfs_acquire_lock (osb, lockId, locktype, lockFlags, &bh, inode);
if (status < 0) {
if (status != -EINTR)
LOG_ERROR_STATUS (status);
goto leave;
}
- bAcquiredLock = 1;
+ have_disk_lock = 1;
} else {
handle = passed_handle;
}
@@ -1025,11 +999,6 @@
fileEntry = (ocfs_file_entry *)OCFS_BH_GET_DATA_WRITE(bh); /* write */ /* journal access */
- if (bCacheLock) {
- DISK_LOCK_FILE_LOCK (fileEntry) = OCFS_DLM_ENABLE_CACHE_LOCK;
- DISK_LOCK_CURRENT_MASTER (fileEntry) = osb->node_num;
- }
-
if (file_size > (__s64) fileEntry->alloc_size) {
allocSize = file_size - fileEntry->alloc_size;
@@ -1136,32 +1105,26 @@
goto leave;
}
- /* Our local update is done, if somebody had asked for a bdcast lock */
- /* He shd set the state */
-
leave:
if (passed_handle == NULL) {
if (handle) {
if (status < 0) {
ocfs_abort_trans(handle);
} else {
- if (bFileLockAcquired)
- lockFlags |= FLAG_FILE_UPDATE_OIN;
+ lockFlags |= FLAG_FILE_UPDATE_OIN;
ocfs_journal_add_lock(handle, locktype,
lockFlags, bh, inode);
- bAcquiredLock = 0;
+ have_disk_lock = 0;
ocfs_commit_trans(handle);
}
}
}
- if (bAcquiredLock) {
- if (bFileLockAcquired)
- lockFlags |= FLAG_FILE_UPDATE_OIN;
+ if (have_disk_lock) {
+ lockFlags |= FLAG_FILE_UPDATE_OIN;
- locktype = bCacheLock ? OCFS_DLM_ENABLE_CACHE_LOCK : OCFS_DLM_EXCLUSIVE_LOCK;
tmpstat = ocfs_release_lock (osb, lockId, OCFS_DLM_EXCLUSIVE_LOCK,
lockFlags, bh, inode);
if (tmpstat < 0)
@@ -1174,7 +1137,6 @@
if (bh != NULL)
brelse(bh);
-
LOG_EXIT_STATUS (status);
return status;
} /* ocfs_extend_file */
@@ -1185,7 +1147,6 @@
*/
int ocfs_setattr (struct dentry *dentry, struct iattr *attr)
{
- struct inode *parentInode;
struct inode *inode = dentry->d_inode;
int error = 0;
__u64 newsize;
@@ -1201,6 +1162,11 @@
osb = OCFS_SB(inode->i_sb);
+ /* NOTE: Other filesystems get away without locking this, but
+ * we're clustered and this has to hit disk now... */
+ if (!(attr->ia_valid & ATTR_SIZE))
+ down(&inode->i_sem);
+
if (!dentry->d_parent || !dentry->d_parent->d_inode) {
LOG_ERROR_STR ("bad inode or root inode");
goto bail;
@@ -1218,8 +1184,6 @@
goto bail;
}
- parentInode = dentry->d_parent->d_inode;
-
newsize = attr->ia_size;
if (attr->ia_valid & ATTR_MODE)
@@ -1290,7 +1254,7 @@
}
status = -EFAIL;
- if ((fileOff != -1) && !extended) {
+ if (!extended) {
status = ocfs_change_file_attrib(osb, fileOff, attr, inode);
if (status < 0) {
if (status != -EINTR)
@@ -1302,7 +1266,9 @@
inode_setattr (inode, attr);
bail:
-
+ if (!(attr->ia_valid & ATTR_SIZE))
+ up(&inode->i_sem);
+
#ifndef BH_SEM_LEAK_CHECKING
if (error < 0)
#endif
@@ -1379,6 +1345,8 @@
if (inode->i_ino == OCFS_ROOT_INODE_NUMBER)
goto bail;
+ /* yay, locking hell! Why do we hit disk for this?! */
+ down(&inode->i_sem);
down (&(OCFS_I(inode)->priv_sem));
status = ocfs_verify_update_inode (osb, inode, &needs_trunc, 0);
up (&(OCFS_I(inode)->priv_sem));
@@ -1386,7 +1354,7 @@
ocfs_truncate_inode_pages(inode, 0);
if (status < 0)
LOG_ERROR_STATUS (status);
-
+ up(&inode->i_sem);
bail:
LOG_EXIT_INT (0);
return 0;
Modified: trunk/src/inc/journal.h
===================================================================
--- trunk/src/inc/journal.h 2004-05-16 17:04:17 UTC (rev 916)
+++ trunk/src/inc/journal.h 2004-05-17 19:28:12 UTC (rev 917)
@@ -149,8 +149,6 @@
* original copy back into the
* buffer. */
- /* The next two structures are ONLY to be used for local alloc
- * code. It's very, very ugly. */
struct _ocfs_bitmap_free_head *commit_bits; /* bits to be
* freed ONLY if
* we commit the
Modified: trunk/src/journal.c
===================================================================
--- trunk/src/journal.c 2004-05-16 17:04:17 UTC (rev 916)
+++ trunk/src/journal.c 2004-05-17 19:28:12 UTC (rev 917)
@@ -28,12 +28,18 @@
#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_JOURNAL
+typedef enum _release_locks_action {
+ TRANS_COMMIT,
+ TRANS_ABORT,
+ TRANS_CACHE
+} release_locks_action;
+
static int ocfs_checkpoint_handle(ocfs_journal_handle *handle);
static int ocfs_revoke_handle(ocfs_journal_handle *handle);
static int ocfs_journal_toggle_mounted(ocfs_super *osb, int node_num, int value);
static int ocfs_journal_get_mount_state(ocfs_super *osb, int node_num);
static int ocfs_reset_publish (ocfs_super * osb, __u64 node_num);
-static int ocfs_journal_release_locks(ocfs_journal_handle *handle, int abort);
+static int ocfs_journal_release_locks(ocfs_journal_handle *handle, release_locks_action action);
static int ocfs_force_read_journal(ocfs_super *osb, __u64 size,
struct inode *inode);
static int ocfs_recover_vol(struct _ocfs_super *osb, int node_num);
@@ -212,7 +218,8 @@
/* This does no locking of the handle, so make sure that the handle
* isn't on journal->curr. If the handle is on journal->commited, then
* you want to be holding the commit_sem before calling this. */
-static int ocfs_journal_release_locks(ocfs_journal_handle *handle, int abort)
+static int ocfs_journal_release_locks(ocfs_journal_handle *handle,
+ release_locks_action action)
{
ocfs_super *osb;
ocfs_journal_lock *lock;
@@ -232,9 +239,15 @@
list_for_each_safe(p, n, &(handle->locks)) {
lock = list_entry(p, ocfs_journal_lock, lock_list);
+ if (!lock->inode)
+ BUG();
+
+ /* The cache list holds unlocked inodes */
+ if (action == TRANS_CACHE)
+ down(&lock->inode->i_sem);
+
/* The file may have been deleted before we got to
- * this lock release. If so, just skip it.
- * *** This test of the deleted flag is not locked!!! */
+ * this lock release. If so, just skip it. */
if ((!lock->inode)
|| (lock->inode && !INODE_DELETED(lock->inode))) {
@@ -242,7 +255,8 @@
GET_INODE_FEOFF(lock->inode),
lock->type,
lock->flags,
- (abort ? NULL : lock->bh),
+ (action == TRANS_ABORT
+ ? NULL : lock->bh),
lock->inode);
if (tmpstat < 0) {
LOG_ERROR_ARGS("Could not release lock: "
@@ -252,6 +266,10 @@
status = tmpstat;
}
}
+
+ if (action == TRANS_CACHE)
+ up(&lock->inode->i_sem);
+
if (lock->bh != NULL)
brelse(lock->bh);
if (lock->inode)
@@ -402,7 +420,7 @@
atomic_dec(&(osb->journal.num_trans));
/* Release locks associated with this handle. */
- retval = ocfs_journal_release_locks(handle, 0);
+ retval = ocfs_journal_release_locks(handle, TRANS_COMMIT);
if (retval < 0)
LOG_ERROR_STATUS(retval);
} else {
@@ -588,7 +606,7 @@
}
/* drop locks associated with the handle here. */
- retval = ocfs_journal_release_locks(handle, 1);
+ retval = ocfs_journal_release_locks(handle, TRANS_ABORT);
if (retval < 0)
LOG_ERROR_STATUS(retval);
@@ -1740,9 +1758,9 @@
/* flush all pending commits and checkpoint the journal. */
journal_lock_updates(journal->k_journal);
status = journal_flush(journal->k_journal);
- journal_unlock_updates(journal->k_journal);
if (status < 0) {
up(&osb->trans_lock);
+ journal_unlock_updates(journal->k_journal);
LOG_ERROR_STATUS(status);
goto finally;
@@ -1758,6 +1776,11 @@
down(&journal->commit_sem);
down(&commit->c_lock);
+ /* Once we've got commit_sem, we can let transactions start
+ * again -- it should protect us against people mucking with
+ * the commited list... */
+ journal_unlock_updates(journal->k_journal);
+
/* we want to take everything off the commited list and
* process it independently, so we can drop the trans_lock
* earlier. */
@@ -1776,7 +1799,7 @@
down(&commit->c_lock);
list_for_each_safe(p, n, &commit->c_list) {
handle = list_entry(p, ocfs_journal_handle, h_list);
- tmpstat = ocfs_journal_release_locks(handle, 0);
+ tmpstat = ocfs_journal_release_locks(handle, TRANS_CACHE);
if (tmpstat < 0)
LOG_ERROR_STATUS((status = tmpstat));
list_del(&(handle->h_list));
Modified: trunk/src/nm.c
===================================================================
--- trunk/src/nm.c 2004-05-16 17:04:17 UTC (rev 916)
+++ trunk/src/nm.c 2004-05-17 19:28:12 UTC (rev 917)
@@ -730,13 +730,6 @@
* data or metadata under the lock.
*/
- if (inode && (vote_type != DELETE_RENAME_ACQUIRE)) {
- /* Ok, for all operations where we no longer need
- * isem, drop it now. */
- up(&inode->i_sem);
- have_i_sem = 0;
- }
-
if (disk_vote) {
/* Zero out the vote for everybody, if any already set and hung */
vote = (ocfs_vote *) OCFS_BH_GET_DATA_WRITE(vote_bh); /* write */
More information about the Ocfs2-commits
mailing list