Skip to contentSkip to conversation

eliminate struct semaphore from reiserfs

PATCH In review Jeff Mahoney 2 participants 9 messages May 7, 2008 – May 14, 2008

lore
Share & tools
lore
#0 lore raw

cover eliminate struct semaphore from reiserfs

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

#1 lore raw

PATCH 1/3 reiserfs: convert j_lock to mutex

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

---
 fs/reiserfs/journal.c          |    6 +++---
 include/linux/reiserfs_fs_sb.h |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/reiserfs/journal.c +3 -3
@@ -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;
include/linux/reiserfs_fs_sb.h +1 -1
@@ -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 */
#2 lore raw

PATCH 1/3 reiserfs: convert j_lock to mutex

In reply to Jeff Mahoney

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

---
 fs/reiserfs/journal.c          |    6 +++---
 include/linux/reiserfs_fs_sb.h |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/reiserfs/journal.c +3 -3
@@ -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;
include/linux/reiserfs_fs_sb.h +1 -1
@@ -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 */
#3 lore raw

PATCH 2/3 reiserfs: convert j_flush_sem to mutex

In reply to Jeff Mahoney

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

---
 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(-)
fs/reiserfs/journal.c +7 -7
@@ -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;
include/linux/reiserfs_fs_sb.h +1 -1
@@ -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 */
#4 lore raw

Re: [patch 2/3] [PATCH] reiserfs: convert j_flush_sem to mutex

Quoted 5 lines · Jeff Mahoney

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

fs/reiserfs/journal.c static int flush_journal_list(struct sup · line 1417

Quoted 9 lines
fs/reiserfs/journal.c +2 -2
@@ -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

---
 fs/reiserfs/journal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/reiserfs/journal.c +1 -1
@@ -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();
 	}
 
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#5 lore raw

Re: [patch 2/3] [PATCH] reiserfs: convert j_flush_sem to mutex

Quoted 18 lines · Jeff Mahoney
Quoted 5 lines · Jeff Mahoney

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

fs/reiserfs/journal.c static int flush_journal_list(struct sup · line 1417

Quoted 9 lines
fs/reiserfs/journal.c +2 -2
@@ -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.

Quoted 1 line

-Jeff

Thanks, the patch resolves the kernel bug.

Quoted 16 lines
---
 fs/reiserfs/journal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/reiserfs/journal.c +1 -1
@@ -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();
 	}
 
Signature · 4 lines
Thanks & Regards,
Kamalesh Babulal,
Linux Technology Center,
IBM, ISTL.
#6 lore raw

PATCH 2/3 reiserfs: convert j_flush_sem to mutex

In reply to Jeff Mahoney

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

---
 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(-)
fs/reiserfs/journal.c +7 -7
@@ -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;
include/linux/reiserfs_fs_sb.h +1 -1
@@ -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 */
#7 lore raw

PATCH 3/3 reiserfs: convert j_commit_lock to mutex

In reply to Jeff Mahoney

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

---
 fs/reiserfs/journal.c          |   18 +++++++-----------
 include/linux/reiserfs_fs_sb.h |    2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)
fs/reiserfs/journal.c +7 -11
@@ -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
include/linux/reiserfs_fs_sb.h +1 -1
@@ -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;
#8 lore raw

PATCH 3/3 reiserfs: convert j_commit_lock to mutex

In reply to Jeff Mahoney

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

---
 fs/reiserfs/journal.c          |   18 +++++++-----------
 include/linux/reiserfs_fs_sb.h |    2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)
fs/reiserfs/journal.c +7 -11
@@ -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
include/linux/reiserfs_fs_sb.h +1 -1
@@ -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;