public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 0/3] eliminate struct semaphore from reiserfs
@ 2008-05-08  6:35 Jeff Mahoney
  2008-05-08  6:35 ` [patch 1/3] [PATCH] reiserfs: convert j_lock to mutex Jeff Mahoney
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jeff Mahoney @ 2008-05-08  6:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: reiserfs-devel

 Reiserfs uses sems for a few different locks, but only uses them as
 mutexes. The following three patches replace the semaphores with
 mutexes.

 -Jeff

--
Jeff Mahoney
SuSE Labs



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch 1/3] [PATCH] reiserfs: convert j_lock to mutex
  2008-05-08  6:35 [patch 0/3] eliminate struct semaphore from reiserfs Jeff Mahoney
@ 2008-05-08  6:35 ` Jeff Mahoney
  2008-05-08  6:35 ` [patch 2/3] [PATCH] reiserfs: convert j_flush_sem " Jeff Mahoney
  2008-05-08  6:36 ` [patch 3/3] [PATCH] reiserfs: convert j_commit_lock " Jeff Mahoney
  2 siblings, 0 replies; 6+ messages in thread
From: Jeff Mahoney @ 2008-05-08  6:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: reiserfs-devel

[-- Attachment #1: reiserfs-j_lock-mutex --]
[-- Type: text/plain, Size: 1615 bytes --]

 j_lock is a semaphore but uses it as if it were a mutex. This
 patch converts it to a mutex.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/reiserfs/journal.c          |    6 +++---
 include/linux/reiserfs_fs_sb.h |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -558,13 +558,13 @@ static inline void insert_journal_hash(s
 static inline void lock_journal(struct super_block *p_s_sb)
 {
 	PROC_INFO_INC(p_s_sb, journal.lock_journal);
-	down(&SB_JOURNAL(p_s_sb)->j_lock);
+	mutex_lock(&SB_JOURNAL(p_s_sb)->j_mutex);
 }
 
 /* unlock the current transaction */
 static inline void unlock_journal(struct super_block *p_s_sb)
 {
-	up(&SB_JOURNAL(p_s_sb)->j_lock);
+	mutex_unlock(&SB_JOURNAL(p_s_sb)->j_mutex);
 }
 
 static inline void get_journal_list(struct reiserfs_journal_list *jl)
@@ -2841,7 +2841,7 @@ int journal_init(struct super_block *p_s
 	journal->j_last = NULL;
 	journal->j_first = NULL;
 	init_waitqueue_head(&(journal->j_join_wait));
-	sema_init(&journal->j_lock, 1);
+	mutex_init(&journal->j_mutex);
 	sema_init(&journal->j_flush_sem, 1);
 
 	journal->j_trans_id = 10;
--- a/include/linux/reiserfs_fs_sb.h
+++ b/include/linux/reiserfs_fs_sb.h
@@ -194,7 +194,7 @@ struct reiserfs_journal {
 	struct buffer_head *j_header_bh;
 
 	time_t j_trans_start_time;	/* time this transaction started */
-	struct semaphore j_lock;
+	struct mutex j_mutex;
 	struct semaphore j_flush_sem;
 	wait_queue_head_t j_join_wait;	/* wait for current transaction to finish before starting new one */
 	atomic_t j_jlock;	/* lock for j_join_wait */


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch 2/3] [PATCH] reiserfs: convert j_flush_sem to mutex
  2008-05-08  6:35 [patch 0/3] eliminate struct semaphore from reiserfs Jeff Mahoney
  2008-05-08  6:35 ` [patch 1/3] [PATCH] reiserfs: convert j_lock to mutex Jeff Mahoney
@ 2008-05-08  6:35 ` Jeff Mahoney
  2008-05-14 14:41   ` Jeff Mahoney
  2008-05-08  6:36 ` [patch 3/3] [PATCH] reiserfs: convert j_commit_lock " Jeff Mahoney
  2 siblings, 1 reply; 6+ messages in thread
From: Jeff Mahoney @ 2008-05-08  6:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: reiserfs-devel

[-- Attachment #1: reiserfs-j_flush_sem-mutex --]
[-- Type: text/plain, Size: 2442 bytes --]

 j_flush_sem is a semaphore but uses it as if it were a mutex. This
 patch converts it to a mutex.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/reiserfs/journal.c           |   14 +++++++-------
 include/linux/reiserfs_fs_sb.h  |    2 +-
 include/linux/reiserfs_fs_sb.h~ |    2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1411,8 +1411,8 @@ static int flush_journal_list(struct sup
 
 	/* if flushall == 0, the lock is already held */
 	if (flushall) {
-		down(&journal->j_flush_sem);
-	} else if (!down_trylock(&journal->j_flush_sem)) {
+		mutex_lock(&journal->j_flush_mutex);
+	} else if (!mutex_trylock(&journal->j_flush_mutex)) {
 		BUG();
 	}
 
@@ -1642,7 +1642,7 @@ static int flush_journal_list(struct sup
 	jl->j_state = 0;
 	put_journal_list(s, jl);
 	if (flushall)
-		up(&journal->j_flush_sem);
+		mutex_unlock(&journal->j_flush_mutex);
 	put_fs_excl();
 	return err;
 }
@@ -1772,12 +1772,12 @@ static int kupdate_transactions(struct s
 	struct reiserfs_journal *journal = SB_JOURNAL(s);
 	chunk.nr = 0;
 
-	down(&journal->j_flush_sem);
+	mutex_lock(&journal->j_flush_mutex);
 	if (!journal_list_still_alive(s, orig_trans_id)) {
 		goto done;
 	}
 
-	/* we've got j_flush_sem held, nobody is going to delete any
+	/* we've got j_flush_mutex held, nobody is going to delete any
 	 * of these lists out from underneath us
 	 */
 	while ((num_trans && transactions_flushed < num_trans) ||
@@ -1812,7 +1812,7 @@ static int kupdate_transactions(struct s
 	}
 
       done:
-	up(&journal->j_flush_sem);
+	mutex_unlock(&journal->j_flush_mutex);
 	return ret;
 }
 
@@ -2842,7 +2842,7 @@ int journal_init(struct super_block *p_s
 	journal->j_first = NULL;
 	init_waitqueue_head(&(journal->j_join_wait));
 	mutex_init(&journal->j_mutex);
-	sema_init(&journal->j_flush_sem, 1);
+	mutex_init(&journal->j_flush_mutex);
 
 	journal->j_trans_id = 10;
 	journal->j_mount_id = 10;
--- a/include/linux/reiserfs_fs_sb.h
+++ b/include/linux/reiserfs_fs_sb.h
@@ -195,7 +195,7 @@ struct reiserfs_journal {
 
 	time_t j_trans_start_time;	/* time this transaction started */
 	struct mutex j_mutex;
-	struct semaphore j_flush_sem;
+	struct mutex j_flush_mutex;
 	wait_queue_head_t j_join_wait;	/* wait for current transaction to finish before starting new one */
 	atomic_t j_jlock;	/* lock for j_join_wait */
 	int j_list_bitmap_index;	/* number of next list bitmap to use */


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch 3/3] [PATCH] reiserfs: convert j_commit_lock to mutex
  2008-05-08  6:35 [patch 0/3] eliminate struct semaphore from reiserfs Jeff Mahoney
  2008-05-08  6:35 ` [patch 1/3] [PATCH] reiserfs: convert j_lock to mutex Jeff Mahoney
  2008-05-08  6:35 ` [patch 2/3] [PATCH] reiserfs: convert j_flush_sem " Jeff Mahoney
@ 2008-05-08  6:36 ` Jeff Mahoney
  2 siblings, 0 replies; 6+ messages in thread
From: Jeff Mahoney @ 2008-05-08  6:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: reiserfs-devel

[-- Attachment #1: reiserfs-j_commit_lock-mutex --]
[-- Type: text/plain, Size: 2831 bytes --]

 j_commit_lock is a semaphore but uses it as if it were a mutex. This
 patch converts it to a mutex.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/reiserfs/journal.c          |   18 +++++++-----------
 include/linux/reiserfs_fs_sb.h |    2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)

--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -36,13 +36,9 @@
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
-
 #include <linux/time.h>
-#include <asm/semaphore.h>
-
 #include <linux/vmalloc.h>
 #include <linux/reiserfs_fs.h>
-
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/fcntl.h>
@@ -1045,9 +1041,9 @@ static int flush_commit_list(struct supe
 	}
 
 	/* make sure nobody is trying to flush this one at the same time */
-	down(&jl->j_commit_lock);
+	mutex_lock(&jl->j_commit_mutex);
 	if (!journal_list_still_alive(s, trans_id)) {
-		up(&jl->j_commit_lock);
+		mutex_unlock(&jl->j_commit_mutex);
 		goto put_jl;
 	}
 	BUG_ON(jl->j_trans_id == 0);
@@ -1057,7 +1053,7 @@ static int flush_commit_list(struct supe
 		if (flushall) {
 			atomic_set(&(jl->j_older_commits_done), 1);
 		}
-		up(&jl->j_commit_lock);
+		mutex_unlock(&jl->j_commit_mutex);
 		goto put_jl;
 	}
 
@@ -1181,7 +1177,7 @@ static int flush_commit_list(struct supe
 	if (flushall) {
 		atomic_set(&(jl->j_older_commits_done), 1);
 	}
-	up(&jl->j_commit_lock);
+	mutex_unlock(&jl->j_commit_mutex);
       put_jl:
 	put_journal_list(s, jl);
 
@@ -2556,7 +2552,7 @@ static struct reiserfs_journal_list *all
 	INIT_LIST_HEAD(&jl->j_working_list);
 	INIT_LIST_HEAD(&jl->j_tail_bh_list);
 	INIT_LIST_HEAD(&jl->j_bh_list);
-	sema_init(&jl->j_commit_lock, 1);
+	mutex_init(&jl->j_commit_mutex);
 	SB_JOURNAL(s)->j_num_lists++;
 	get_journal_list(jl);
 	return jl;
@@ -4034,7 +4030,7 @@ static int do_journal_end(struct reiserf
 	 * the new transaction is fully setup, and we've already flushed the
 	 * ordered bh list
 	 */
-	down(&jl->j_commit_lock);
+	mutex_lock(&jl->j_commit_mutex);
 
 	/* save the transaction id in case we need to commit it later */
 	commit_trans_id = jl->j_trans_id;
@@ -4200,7 +4196,7 @@ static int do_journal_end(struct reiserf
 		lock_kernel();
 	}
 	BUG_ON(!list_empty(&jl->j_tail_bh_list));
-	up(&jl->j_commit_lock);
+	mutex_unlock(&jl->j_commit_mutex);
 
 	/* honor the flush wishes from the caller, simple commits can
 	 ** be done outside the journal lock, they are done below
--- a/include/linux/reiserfs_fs_sb.h
+++ b/include/linux/reiserfs_fs_sb.h
@@ -152,7 +152,7 @@ struct reiserfs_journal_list {
 	atomic_t j_nonzerolen;
 	atomic_t j_commit_left;
 	atomic_t j_older_commits_done;	/* all commits older than this on disk */
-	struct semaphore j_commit_lock;
+	struct mutex j_commit_mutex;
 	unsigned long j_trans_id;
 	time_t j_timestamp;
 	struct reiserfs_list_bitmap *j_list_bitmap;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/3] [PATCH] reiserfs: convert j_flush_sem to mutex
  2008-05-08  6:35 ` [patch 2/3] [PATCH] reiserfs: convert j_flush_sem " Jeff Mahoney
@ 2008-05-14 14:41   ` Jeff Mahoney
  2008-05-14 18:22     ` Kamalesh Babulal
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Mahoney @ 2008-05-14 14:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: reiserfs-devel, Andrew Morton, kamalesh

Jeff Mahoney wrote:
>  j_flush_sem is a semaphore but uses it as if it were a mutex. This
>  patch converts it to a mutex.
> --- a/fs/reiserfs/journal.c
> +++ b/fs/reiserfs/journal.c
> @@ -1411,8 +1411,8 @@ static int flush_journal_list(struct sup
>  
>  	/* if flushall == 0, the lock is already held */
>  	if (flushall) {
> -		down(&journal->j_flush_sem);
> -	} else if (!down_trylock(&journal->j_flush_sem)) {
> +		mutex_lock(&journal->j_flush_mutex);
> +	} else if (!mutex_trylock(&journal->j_flush_mutex)) {
>  		BUG();
>  	}

Oops. This chunk didn't get refreshed, here's the right one.

-Jeff

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/reiserfs/journal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1410,7 +1410,7 @@ static int flush_journal_list(struct sup
 	/* if flushall == 0, the lock is already held */
 	if (flushall) {
 		mutex_lock(&journal->j_flush_mutex);
-	} else if (!mutex_trylock(&journal->j_flush_mutex)) {
+	} else if (mutex_trylock(&journal->j_flush_mutex)) {
 		BUG();
 	}
 


-- 
Jeff Mahoney
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/3] [PATCH] reiserfs: convert j_flush_sem to mutex
  2008-05-14 14:41   ` Jeff Mahoney
@ 2008-05-14 18:22     ` Kamalesh Babulal
  0 siblings, 0 replies; 6+ messages in thread
From: Kamalesh Babulal @ 2008-05-14 18:22 UTC (permalink / raw)
  To: Jeff Mahoney; +Cc: linux-kernel, reiserfs-devel, Andrew Morton

Jeff Mahoney wrote:
> Jeff Mahoney wrote:
>>  j_flush_sem is a semaphore but uses it as if it were a mutex. This
>>  patch converts it to a mutex.
>> --- a/fs/reiserfs/journal.c
>> +++ b/fs/reiserfs/journal.c
>> @@ -1411,8 +1411,8 @@ static int flush_journal_list(struct sup
>>  
>>  	/* if flushall == 0, the lock is already held */
>>  	if (flushall) {
>> -		down(&journal->j_flush_sem);
>> -	} else if (!down_trylock(&journal->j_flush_sem)) {
>> +		mutex_lock(&journal->j_flush_mutex);
>> +	} else if (!mutex_trylock(&journal->j_flush_mutex)) {
>>  		BUG();
>>  	}
> 
> Oops. This chunk didn't get refreshed, here's the right one.
> 
> -Jeff

Thanks, the patch resolves the kernel bug.

Tested-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> 
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  fs/reiserfs/journal.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/fs/reiserfs/journal.c
> +++ b/fs/reiserfs/journal.c
> @@ -1410,7 +1410,7 @@ static int flush_journal_list(struct sup
>  	/* if flushall == 0, the lock is already held */
>  	if (flushall) {
>  		mutex_lock(&journal->j_flush_mutex);
> -	} else if (!mutex_trylock(&journal->j_flush_mutex)) {
> +	} else if (mutex_trylock(&journal->j_flush_mutex)) {
>  		BUG();
>  	}
> 


-- 
Thanks & Regards,
Kamalesh Babulal,
Linux Technology Center,
IBM, ISTL.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-05-14 18:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-08  6:35 [patch 0/3] eliminate struct semaphore from reiserfs Jeff Mahoney
2008-05-08  6:35 ` [patch 1/3] [PATCH] reiserfs: convert j_lock to mutex Jeff Mahoney
2008-05-08  6:35 ` [patch 2/3] [PATCH] reiserfs: convert j_flush_sem " Jeff Mahoney
2008-05-14 14:41   ` Jeff Mahoney
2008-05-14 18:22     ` Kamalesh Babulal
2008-05-08  6:36 ` [patch 3/3] [PATCH] reiserfs: convert j_commit_lock " Jeff Mahoney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox