[Jfs-patches] [PATCH] rwlock hacks
Brought to you by:
blaschke-oss,
shaggyk
|
From: Christoph H. <hc...@ca...> - 2002-03-01 16:28:32
|
I had some discussion with Al Viro vs the hacked up write trylock
operation in JFS and we came to the conclusion that, too be save
we really want the bkl in the hacked locking primitives.
The below patch implements this and also reverses the WRITE_TRYLOCK
return value to match the behaviour of the other linux trylock
operators. I've done this so that the trylock operations for rwsems
will fit into JFS nicely once they'll get added to the kernel.
Christoph
--
Of course it doesn't work. We've performed a software upgrade.
Index: fs/jfs/jfs_incore.h
===================================================================
RCS file: /usr/cvs/jfs/linux24/fs/jfs/jfs_incore.h,v
retrieving revision 1.1
diff -u -u -r1.1 jfs_incore.h
--- fs/jfs/jfs_incore.h 2002/02/12 15:18:20 1.1
+++ fs/jfs/jfs_incore.h 2002/03/01 13:21:35
@@ -35,7 +35,7 @@
*/
typedef struct jfs_rwlock {
struct rw_semaphore rw_sem;
- atomic_t in_use; /* for hacked implementation of trylock */
+ int in_use; /* for hacked implementation of trylock */
} jfs_rwlock_t;
/*
Index: fs/jfs/jfs_lock.h
===================================================================
RCS file: /usr/cvs/jfs/linux24/fs/jfs/jfs_lock.h,v
retrieving revision 1.1
diff -u -u -r1.1 jfs_lock.h
--- fs/jfs/jfs_lock.h 2002/02/12 15:18:20 1.1
+++ fs/jfs/jfs_lock.h 2002/03/01 13:21:35
@@ -19,6 +19,7 @@
#define _H_JFS_LOCK
#include <linux/spinlock.h>
+#include <linux/smp_lock.h>
#include <linux/sched.h>
/*
@@ -41,35 +42,49 @@
static inline void RDWRLOCK_INIT(jfs_rwlock_t * Lock)
{
init_rwsem(&Lock->rw_sem);
- atomic_set(&Lock->in_use, 0);
+ Lock->in_use = 0;
}
static inline void READ_LOCK(jfs_rwlock_t * Lock)
{
- atomic_inc(&Lock->in_use);
+ lock_kernel();
+ Lock->in_use++;
down_read(&Lock->rw_sem);
+ unlock_kernel();
}
static inline void READ_UNLOCK(jfs_rwlock_t * Lock)
{
+ lock_kernel();
up_read(&Lock->rw_sem);
- atomic_dec(&Lock->in_use);
+ Lock->in_use--;
+ unlock_kernel();
}
static inline void WRITE_LOCK(jfs_rwlock_t * Lock)
{
- atomic_inc(&Lock->in_use);
+ lock_kernel();
+ Lock->in_use++;
down_write(&Lock->rw_sem);
+ unlock_kernel();
}
static inline int WRITE_TRYLOCK(jfs_rwlock_t * Lock)
{
- if (atomic_read(&Lock->in_use))
- return 0;
- WRITE_LOCK(Lock);
- return 1;
+ lock_kernel();
+ if (Lock->in_use) {
+ unlock_kernel();
+ return 1;
+ }
+
+ Lock->in_use++;
+ down_write(&Lock->rw_sem);
+ unlock_kernel();
+ return 0;
}
static inline void WRITE_UNLOCK(jfs_rwlock_t * Lock)
{
+ lock_kernel();
up_write(&Lock->rw_sem);
- atomic_dec(&Lock->in_use);
+ Lock->in_use--;
+ unlock_kernel();
}
#define IREAD_LOCK(ip) READ_LOCK(&JFS_IP(ip)->rdwrlock)
Index: fs/jfs/jfs_txnmgr.c
===================================================================
RCS file: /usr/cvs/jfs/linux24/fs/jfs/jfs_txnmgr.c,v
retrieving revision 1.29
diff -u -u -r1.29 jfs_txnmgr.c
--- fs/jfs/jfs_txnmgr.c 2002/02/12 15:18:20 1.29
+++ fs/jfs/jfs_txnmgr.c 2002/03/01 13:21:45
@@ -2909,7 +2909,7 @@
* IWRITE_TRYLOCK implementation may still block
*/
TXN_UNLOCK();
- if (IWRITE_TRYLOCK(ip)) {
+ if (!IWRITE_TRYLOCK(ip)) {
/*
* inode will be removed from anonymous list
* when it is committed
|