Hi,
I was just wondering what the point of the wrappers around the semaphore
locking was, so I ginned up this patch against the linux25 cvs tree. I
believe it should be functionally equivalent and get rid of the ugly
wrappers. Now I just need to get 2.5.6-pre2 compiling instead of
erroring out :-). Hopefully you won't hate it, and hopefully I didn't
screw things up too badly.
Regards,
Rob Radez
Index: linux25/fs/jfs/jfs_incore.h
===================================================================
RCS file: /usr/cvs/jfs/linux25/fs/jfs/jfs_incore.h,v
retrieving revision 1.1
diff -u -r1.1 jfs_incore.h
--- linux25/fs/jfs/jfs_incore.h 2002/02/12 15:18:24 1.1
+++ linux25/fs/jfs/jfs_incore.h 2002/03/01 23:14:07
@@ -32,14 +32,6 @@
#define JFS_SUPER_MAGIC 0x3153464a /* "JFS1" */
/*
- * Due to header ordering problems this can't be in jfs_lock.h
- */
-typedef struct jfs_rwlock {
- struct rw_semaphore rw_sem;
- atomic_t in_use; /* for hacked implementation of trylock */
-} jfs_rwlock_t;
-
-/*
* JFS-private inode information
*/
struct jfs_inode_info {
@@ -63,7 +55,7 @@
lid_t atltail; /* anonymous tlock list tail */
struct list_head anon_inode_list; /* inodes having anonymous txns */
struct list_head mp_list; /* metapages in inode's address space */
- jfs_rwlock_t rdwrlock; /* read/write lock */
+ struct rw_semaphore rw_sem; /* read/write lock */
lid_t xtlid; /* lid of xtree lock on directory */
union {
struct {
Index: linux25/fs/jfs/jfs_lock.h
===================================================================
RCS file: /usr/cvs/jfs/linux25/fs/jfs/jfs_lock.h,v
retrieving revision 1.1
diff -u -r1.1 jfs_lock.h
--- linux25/fs/jfs/jfs_lock.h 2002/02/12 15:18:24 1.1
+++ linux25/fs/jfs/jfs_lock.h 2002/03/01 23:14:07
@@ -30,53 +30,32 @@
/* readers/writer lock: thread-thread */
/*
- * RW semaphores do not currently have a trylock function. Since the
- * implementation varies by platform, I have implemented a platform-independent
- * wrapper around the rw_semaphore routines. If this turns out to be the best
- * way of avoiding our locking problems, I will push to get a trylock
- * implemented in the kernel, but I'd rather find a way to avoid having to
- * use it.
+ * trylock for writing -- returns 1 if successful, 0 if contention
+ * copied from Brian Watson's code, delete and use generic routines if
+ * those get accepted into the kernel
*/
-#define RDWRLOCK_T jfs_rwlock_t
-static inline void RDWRLOCK_INIT(jfs_rwlock_t * Lock)
+int jdown_write_trylock(struct rw_semaphore *sem)
{
- init_rwsem(&Lock->rw_sem);
- atomic_set(&Lock->in_use, 0);
-}
-static inline void READ_LOCK(jfs_rwlock_t * Lock)
-{
- atomic_inc(&Lock->in_use);
- down_read(&Lock->rw_sem);
-}
-static inline void READ_UNLOCK(jfs_rwlock_t * Lock)
-{
- up_read(&Lock->rw_sem);
- atomic_dec(&Lock->in_use);
-}
-static inline void WRITE_LOCK(jfs_rwlock_t * Lock)
-{
- atomic_inc(&Lock->in_use);
- down_write(&Lock->rw_sem);
-}
+ int ret = 0;
-static inline int WRITE_TRYLOCK(jfs_rwlock_t * Lock)
-{
- if (atomic_read(&Lock->in_use))
- return 0;
- WRITE_LOCK(Lock);
- return 1;
-}
-static inline void WRITE_UNLOCK(jfs_rwlock_t * Lock)
-{
- up_write(&Lock->rw_sem);
- atomic_dec(&Lock->in_use);
+ spin_lock(&sem->wait_lock);
+
+ if (sem->activity==0 && list_empty(&sem->wait_list)) {
+ /* granted */
+ sem->activity = -1;
+ ret = 1;
+ }
+
+ spin_unlock(&sem->wait_lock);
+
+ return ret;
}
-#define IREAD_LOCK(ip) READ_LOCK(&JFS_IP(ip)->rdwrlock)
-#define IREAD_UNLOCK(ip) READ_UNLOCK(&JFS_IP(ip)->rdwrlock)
-#define IWRITE_LOCK(ip) WRITE_LOCK(&JFS_IP(ip)->rdwrlock)
-#define IWRITE_TRYLOCK(ip) WRITE_TRYLOCK(&JFS_IP(ip)->rdwrlock)
-#define IWRITE_UNLOCK(ip) WRITE_UNLOCK(&JFS_IP(ip)->rdwrlock)
+#define IREAD_LOCK(ip) down_read(&JFS_IP(ip)->rw_sem)
+#define IREAD_UNLOCK(ip) up_read(&JFS_IP(ip)->rw_sem)
+#define IWRITE_LOCK(ip) down_write(&JFS_IP(ip)->rw_sem)
+#define IWRITE_TRYLOCK(ip) jdown_write_trylock(&JFS_IP(ip)->rw_sem)
+#define IWRITE_UNLOCK(ip) up_write(&JFS_IP(ip)->rw_sem)
#define IWRITE_LOCK_LIST iwritelocklist
extern void iwritelocklist(int, ...);
Index: linux25/fs/jfs/super.c
===================================================================
RCS file: /usr/cvs/jfs/linux25/fs/jfs/super.c,v
retrieving revision 1.12
diff -u -r1.12 super.c
--- linux25/fs/jfs/super.c 2002/02/12 15:18:25 1.12
+++ linux25/fs/jfs/super.c 2002/03/01 23:14:07
@@ -380,7 +380,7 @@
SLAB_CTOR_CONSTRUCTOR) {
INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
INIT_LIST_HEAD(&jfs_ip->mp_list);
- RDWRLOCK_INIT(&jfs_ip->rdwrlock);
+ init_rwsem(&jfs_ip->rw_sem);
inode_init_once(&jfs_ip->vfs_inode);
}
}
_______________________________________________
Jfs-discussion mailing list
[EMAIL PROTECTED]
http://www-124.ibm.com/developerworks/oss/mailman/listinfo/jfs-discussion