linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 00/10] semaphore to mutex conversions
@ 2010-01-29 20:38 Thomas Gleixner
  2010-01-29 20:38 ` [patch 01/10] smbfs: Convert server->sem to mutex Thomas Gleixner
                   ` (9 more replies)
  0 siblings, 10 replies; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar

The following series converts semaphores which are semantically
mutexes to real mutexes. This is part of the effort to remove
init_MUTEX*

Most of the patches have been in the -rt tree for quite a while with
no bad side effects.

Thanks,

	tglx




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

* [patch 01/10] smbfs: Convert server->sem to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 22:14   ` Christoph Hellwig
  2010-01-29 20:38 ` [patch 02/10] hpfs: Convert sbi->hpfs_creation_de " Thomas Gleixner
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML
  Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro,
	Jeff Layton, Steve French

[-- Attachment #1: smbfs-convert-sema.patch --]
[-- Type: text/plain, Size: 1848 bytes --]

The semaphore server->sem is used as mutex. Rename it to server->mutex
and convert it to a real mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Steve French <sfrench@us.ibm.com>

---
 fs/smbfs/inode.c          |    2 +-
 include/linux/smb_fs_sb.h |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

Index: linux-2.6-tip/fs/smbfs/inode.c
===================================================================
--- linux-2.6-tip.orig/fs/smbfs/inode.c
+++ linux-2.6-tip/fs/smbfs/inode.c
@@ -530,7 +530,7 @@ static int smb_fill_super(struct super_b
 	server->mnt = NULL;
 	server->sock_file = NULL;
 	init_waitqueue_head(&server->conn_wq);
-	init_MUTEX(&server->sem);
+	mutex_init(&server->mutex);
 	INIT_LIST_HEAD(&server->entry);
 	INIT_LIST_HEAD(&server->xmitq);
 	INIT_LIST_HEAD(&server->recvq);
Index: linux-2.6-tip/include/linux/smb_fs_sb.h
===================================================================
--- linux-2.6-tip.orig/include/linux/smb_fs_sb.h
+++ linux-2.6-tip/include/linux/smb_fs_sb.h
@@ -57,7 +57,7 @@ struct smb_sb_info {
 	struct smb_conn_opt opt;
 	wait_queue_head_t conn_wq;
 	int conn_complete;
-	struct semaphore sem;
+	struct mutex mutex;
 
 	unsigned char      header[SMB_HEADER_LEN + 20*2 + 2];
 	u32                header_len;
@@ -79,19 +79,19 @@ struct smb_sb_info {
 static inline int
 smb_lock_server_interruptible(struct smb_sb_info *server)
 {
-	return down_interruptible(&(server->sem));
+	return mutex_lock_interruptible(&server->mutex);
 }
 
 static inline void
 smb_lock_server(struct smb_sb_info *server)
 {
-	down(&(server->sem));
+	mutex_lock(&server->mutex);
 }
 
 static inline void
 smb_unlock_server(struct smb_sb_info *server)
 {
-	up(&(server->sem));
+	mutex_unlock(&server->mutex);
 }
 
 #endif



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

* [patch 02/10] hpfs: Convert sbi->hpfs_creation_de to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
  2010-01-29 20:38 ` [patch 01/10] smbfs: Convert server->sem to mutex Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 22:20   ` Christoph Hellwig
  2010-01-29 20:38 ` [patch 03/10] hpfsplus: Convert tree_lock " Thomas Gleixner
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

[-- Attachment #1: hpfs-convert-sema.patch --]
[-- Type: text/plain, Size: 2066 bytes --]

The sbi->hpfs_creation_de semaphore is used as mutex. Convert it to a
real mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/hpfs/buffer.c  |    4 ++--
 fs/hpfs/hpfs_fn.h |    2 +-
 fs/hpfs/super.c   |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6-tip/fs/hpfs/buffer.c
===================================================================
--- linux-2.6-tip.orig/fs/hpfs/buffer.c
+++ linux-2.6-tip/fs/hpfs/buffer.c
@@ -13,7 +13,7 @@ void hpfs_lock_creation(struct super_blo
 #ifdef DEBUG_LOCKS
 	printk("lock creation\n");
 #endif
-	down(&hpfs_sb(s)->hpfs_creation_de);
+	mutex_lock(&hpfs_sb(s)->hpfs_creation_de);
 }
 
 void hpfs_unlock_creation(struct super_block *s)
@@ -21,7 +21,7 @@ void hpfs_unlock_creation(struct super_b
 #ifdef DEBUG_LOCKS
 	printk("unlock creation\n");
 #endif
-	up(&hpfs_sb(s)->hpfs_creation_de);
+	mutex_unlock(&hpfs_sb(s)->hpfs_creation_de);
 }
 
 /* Map a sector into a buffer and return pointers to it and to the buffer. */
Index: linux-2.6-tip/fs/hpfs/hpfs_fn.h
===================================================================
--- linux-2.6-tip.orig/fs/hpfs/hpfs_fn.h
+++ linux-2.6-tip/fs/hpfs/hpfs_fn.h
@@ -87,7 +87,7 @@ struct hpfs_sb_info {
 	unsigned *sb_bmp_dir;		/* main bitmap directory */
 	unsigned sb_c_bitmap;		/* current bitmap */
 	unsigned sb_max_fwd_alloc;	/* max forwad allocation */
-	struct semaphore hpfs_creation_de; /* when creating dirents, nobody else
+	struct mutex hpfs_creation_de;	/* when creating dirents, nobody else
 					   can alloc blocks */
 	/*unsigned sb_mounting : 1;*/
 	int sb_timeshift;
Index: linux-2.6-tip/fs/hpfs/super.c
===================================================================
--- linux-2.6-tip.orig/fs/hpfs/super.c
+++ linux-2.6-tip/fs/hpfs/super.c
@@ -486,7 +486,7 @@ static int hpfs_fill_super(struct super_
 	sbi->sb_bmp_dir = NULL;
 	sbi->sb_cp_table = NULL;
 
-	init_MUTEX(&sbi->hpfs_creation_de);
+	mutex_init(&sbi->hpfs_creation_de);
 
 	uid = current_uid();
 	gid = current_gid();



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

* [patch 03/10] hpfsplus: Convert tree_lock to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
  2010-01-29 20:38 ` [patch 01/10] smbfs: Convert server->sem to mutex Thomas Gleixner
  2010-01-29 20:38 ` [patch 02/10] hpfs: Convert sbi->hpfs_creation_de " Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 22:23   ` Christoph Hellwig
  2010-01-29 20:38 ` [patch 04/10] hfs: " Thomas Gleixner
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

[-- Attachment #1: hfsplus-convert-sema.patch --]
[-- Type: text/plain, Size: 1928 bytes --]

The tree_lock semaphore is used as mutex. Convert it to a real mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>

---
 fs/hfsplus/bfind.c      |    4 ++--
 fs/hfsplus/btree.c      |    2 +-
 fs/hfsplus/hfsplus_fs.h |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6-tip/fs/hfsplus/bfind.c
===================================================================
--- linux-2.6-tip.orig/fs/hfsplus/bfind.c
+++ linux-2.6-tip/fs/hfsplus/bfind.c
@@ -23,7 +23,7 @@ int hfs_find_init(struct hfs_btree *tree
 	fd->search_key = ptr;
 	fd->key = ptr + tree->max_key_len + 2;
 	dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n", tree->cnid, __builtin_return_address(0));
-	down(&tree->tree_lock);
+	mutex_lock(&tree->tree_lock);
 	return 0;
 }
 
@@ -32,7 +32,7 @@ void hfs_find_exit(struct hfs_find_data 
 	hfs_bnode_put(fd->bnode);
 	kfree(fd->search_key);
 	dprint(DBG_BNODE_REFS, "find_exit: %d (%p)\n", fd->tree->cnid, __builtin_return_address(0));
-	up(&fd->tree->tree_lock);
+	mutex_unlock(&fd->tree->tree_lock);
 	fd->tree = NULL;
 }
 
Index: linux-2.6-tip/fs/hfsplus/btree.c
===================================================================
--- linux-2.6-tip.orig/fs/hfsplus/btree.c
+++ linux-2.6-tip/fs/hfsplus/btree.c
@@ -30,7 +30,7 @@ struct hfs_btree *hfs_btree_open(struct 
 	if (!tree)
 		return NULL;
 
-	init_MUTEX(&tree->tree_lock);
+	mutex_init(&tree->tree_lock);
 	spin_lock_init(&tree->hash_lock);
 	tree->sb = sb;
 	tree->cnid = id;
Index: linux-2.6-tip/fs/hfsplus/hfsplus_fs.h
===================================================================
--- linux-2.6-tip.orig/fs/hfsplus/hfsplus_fs.h
+++ linux-2.6-tip/fs/hfsplus/hfsplus_fs.h
@@ -62,7 +62,7 @@ struct hfs_btree {
 	unsigned int depth;
 
 	//unsigned int map1_size, map_size;
-	struct semaphore tree_lock;
+	struct mutex tree_lock;
 
 	unsigned int pages_per_bnode;
 	spinlock_t hash_lock;



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

* [patch 04/10] hfs: Convert tree_lock to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (2 preceding siblings ...)
  2010-01-29 20:38 ` [patch 03/10] hpfsplus: Convert tree_lock " Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 22:26   ` Christoph Hellwig
  2010-01-29 20:38 ` [patch 05/10] cifs: convert semaphore " Thomas Gleixner
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

[-- Attachment #1: hfs-convert-sema.patch --]
[-- Type: text/plain, Size: 1871 bytes --]

The tree_lock semaphore is used as mutex. Convert it to a real mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/hfs/bfind.c |    4 ++--
 fs/hfs/btree.c |    2 +-
 fs/hfs/btree.h |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6-tip/fs/hfs/bfind.c
===================================================================
--- linux-2.6-tip.orig/fs/hfs/bfind.c
+++ linux-2.6-tip/fs/hfs/bfind.c
@@ -23,7 +23,7 @@ int hfs_find_init(struct hfs_btree *tree
 	fd->search_key = ptr;
 	fd->key = ptr + tree->max_key_len + 2;
 	dprint(DBG_BNODE_REFS, "find_init: %d (%p)\n", tree->cnid, __builtin_return_address(0));
-	down(&tree->tree_lock);
+	mutex_lock(&tree->tree_lock);
 	return 0;
 }
 
@@ -32,7 +32,7 @@ void hfs_find_exit(struct hfs_find_data 
 	hfs_bnode_put(fd->bnode);
 	kfree(fd->search_key);
 	dprint(DBG_BNODE_REFS, "find_exit: %d (%p)\n", fd->tree->cnid, __builtin_return_address(0));
-	up(&fd->tree->tree_lock);
+	mutex_unlock(&fd->tree->tree_lock);
 	fd->tree = NULL;
 }
 
Index: linux-2.6-tip/fs/hfs/btree.c
===================================================================
--- linux-2.6-tip.orig/fs/hfs/btree.c
+++ linux-2.6-tip/fs/hfs/btree.c
@@ -26,7 +26,7 @@ struct hfs_btree *hfs_btree_open(struct 
 	if (!tree)
 		return NULL;
 
-	init_MUTEX(&tree->tree_lock);
+	mutex_init(&tree->tree_lock);
 	spin_lock_init(&tree->hash_lock);
 	/* Set the correct compare function */
 	tree->sb = sb;
Index: linux-2.6-tip/fs/hfs/btree.h
===================================================================
--- linux-2.6-tip.orig/fs/hfs/btree.h
+++ linux-2.6-tip/fs/hfs/btree.h
@@ -33,7 +33,7 @@ struct hfs_btree {
 	unsigned int depth;
 
 	//unsigned int map1_size, map_size;
-	struct semaphore tree_lock;
+	struct mutex tree_lock;
 
 	unsigned int pages_per_bnode;
 	spinlock_t hash_lock;



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

* [patch 05/10] cifs: convert semaphore to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (3 preceding siblings ...)
  2010-01-29 20:38 ` [patch 04/10] hfs: " Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 22:29   ` Christoph Hellwig
  2010-01-29 20:38 ` [patch 06/10] affs: Convert semaphores to mutexes Thomas Gleixner
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML
  Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Jeff Layton,
	Steve French

[-- Attachment #1: cifs-convert-sema.patch --]
[-- Type: text/plain, Size: 4051 bytes --]

pSesInfo->sesSem is used as mutex. Rename it to session_mutex and
convert it to a real mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Steve French <sfrench@us.ibm.com>
---
 fs/cifs/cifsglob.h |    2 +-
 fs/cifs/cifssmb.c  |   12 ++++++------
 fs/cifs/connect.c  |    8 ++++----
 fs/cifs/misc.c     |    2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

Index: linux-2.6-tip/fs/cifs/cifsglob.h
===================================================================
--- linux-2.6-tip.orig/fs/cifs/cifsglob.h
+++ linux-2.6-tip/fs/cifs/cifsglob.h
@@ -204,7 +204,7 @@ struct cifsUidInfo {
 struct cifsSesInfo {
 	struct list_head smb_ses_list;
 	struct list_head tcon_list;
-	struct semaphore sesSem;
+	struct mutex session_mutex;
 #if 0
 	struct cifsUidInfo *uidInfo;	/* pointer to user info */
 #endif
Index: linux-2.6-tip/fs/cifs/cifssmb.c
===================================================================
--- linux-2.6-tip.orig/fs/cifs/cifssmb.c
+++ linux-2.6-tip/fs/cifs/cifssmb.c
@@ -170,19 +170,19 @@ cifs_reconnect_tcon(struct cifsTconInfo 
 	 * need to prevent multiple threads trying to simultaneously
 	 * reconnect the same SMB session
 	 */
-	down(&ses->sesSem);
+	mutex_lock(&ses->session_mutex);
 	if (ses->need_reconnect)
 		rc = cifs_setup_session(0, ses, nls_codepage);
 
 	/* do we need to reconnect tcon? */
 	if (rc || !tcon->need_reconnect) {
-		up(&ses->sesSem);
+		mutex_unlock(&ses->session_mutex);
 		goto out;
 	}
 
 	mark_open_files_invalid(tcon);
 	rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage);
-	up(&ses->sesSem);
+	mutex_unlock(&ses->session_mutex);
 	cFYI(1, ("reconnect tcon rc = %d", rc));
 
 	if (rc)
@@ -700,13 +700,13 @@ CIFSSMBLogoff(const int xid, struct cifs
 	if (!ses || !ses->server)
 		return -EIO;
 
-	down(&ses->sesSem);
+	mutex_lock(&ses->session_mutex);
 	if (ses->need_reconnect)
 		goto session_already_dead; /* no need to send SMBlogoff if uid
 					      already closed due to reconnect */
 	rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB);
 	if (rc) {
-		up(&ses->sesSem);
+		mutex_unlock(&ses->session_mutex);
 		return rc;
 	}
 
@@ -721,7 +721,7 @@ CIFSSMBLogoff(const int xid, struct cifs
 	pSMB->AndXCommand = 0xFF;
 	rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0);
 session_already_dead:
-	up(&ses->sesSem);
+	mutex_unlock(&ses->session_mutex);
 
 	/* if session dead then we do not need to do ulogoff,
 		since server closed smb session, no sense reporting
Index: linux-2.6-tip/fs/cifs/connect.c
===================================================================
--- linux-2.6-tip.orig/fs/cifs/connect.c
+++ linux-2.6-tip/fs/cifs/connect.c
@@ -2366,13 +2366,13 @@ try_mount_again:
 		 */
 		cifs_put_tcp_session(srvTcp);
 
-		down(&pSesInfo->sesSem);
+		mutex_lock(&pSesInfo->session_mutex);
 		if (pSesInfo->need_reconnect) {
 			cFYI(1, ("Session needs reconnect"));
 			rc = cifs_setup_session(xid, pSesInfo,
 						cifs_sb->local_nls);
 		}
-		up(&pSesInfo->sesSem);
+		mutex_unlock(&pSesInfo->session_mutex);
 	} else if (!rc) {
 		cFYI(1, ("Existing smb sess not found"));
 		pSesInfo = sesInfoAlloc();
@@ -2415,12 +2415,12 @@ try_mount_again:
 		}
 		pSesInfo->linux_uid = volume_info->linux_uid;
 		pSesInfo->overrideSecFlg = volume_info->secFlg;
-		down(&pSesInfo->sesSem);
+		mutex_lock(&pSesInfo->session_mutex);
 
 		/* BB FIXME need to pass vol->secFlgs BB */
 		rc = cifs_setup_session(xid, pSesInfo,
 					cifs_sb->local_nls);
-		up(&pSesInfo->sesSem);
+		mutex_unlock(&pSesInfo->session_mutex);
 	}
 
 	/* search for existing tcon to this server share */
Index: linux-2.6-tip/fs/cifs/misc.c
===================================================================
--- linux-2.6-tip.orig/fs/cifs/misc.c
+++ linux-2.6-tip/fs/cifs/misc.c
@@ -79,7 +79,7 @@ sesInfoAlloc(void)
 		++ret_buf->ses_count;
 		INIT_LIST_HEAD(&ret_buf->smb_ses_list);
 		INIT_LIST_HEAD(&ret_buf->tcon_list);
-		init_MUTEX(&ret_buf->sesSem);
+		mutex_init(&ret_buf->session_mutex);
 	}
 	return ret_buf;
 }



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

* [patch 06/10] affs: Convert semaphores to mutexes
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (4 preceding siblings ...)
  2010-01-29 20:38 ` [patch 05/10] cifs: convert semaphore " Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 22:25   ` Al Viro
  2010-01-29 22:36   ` Christoph Hellwig
  2010-01-29 20:38 ` [patch 07/10] usb: gadgetfs: Convert semaphore to mutex Thomas Gleixner
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

[-- Attachment #1: affs-convert-sema.patch --]
[-- Type: text/plain, Size: 2499 bytes --]

These semaphores are plain mutexes. Convert them to struct mutex.

Map affs_[un]lock_dir() to affs_[un]lock_ext() instead of the "#define
i_hash_lock i_ext_lock" magic.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>

---
 fs/affs/affs.h  |   26 +++++++++-----------------
 fs/affs/super.c |    4 ++--
 2 files changed, 11 insertions(+), 19 deletions(-)

Index: linux-2.6-tip/fs/affs/affs.h
===================================================================
--- linux-2.6-tip.orig/fs/affs/affs.h
+++ linux-2.6-tip/fs/affs/affs.h
@@ -50,9 +50,8 @@ struct affs_ext_key {
  */
 struct affs_inode_info {
 	atomic_t i_opencnt;
-	struct semaphore i_link_lock;		/* Protects internal inode access. */
-	struct semaphore i_ext_lock;		/* Protects internal inode access. */
-#define i_hash_lock i_ext_lock
+	struct mutex i_link_lock;		/* Protects internal inode access. */
+	struct mutex i_ext_lock;		/* Protects internal inode access. */
 	u32	 i_blkcnt;			/* block count */
 	u32	 i_extcnt;			/* extended block count */
 	u32	*i_lc;				/* linear cache of extended blocks */
@@ -275,30 +274,23 @@ affs_adjust_bitmapchecksum(struct buffer
 static inline void
 affs_lock_link(struct inode *inode)
 {
-	down(&AFFS_I(inode)->i_link_lock);
+	mutex_lock(&AFFS_I(inode)->i_link_lock);
 }
 static inline void
 affs_unlock_link(struct inode *inode)
 {
-	up(&AFFS_I(inode)->i_link_lock);
-}
-static inline void
-affs_lock_dir(struct inode *inode)
-{
-	down(&AFFS_I(inode)->i_hash_lock);
-}
-static inline void
-affs_unlock_dir(struct inode *inode)
-{
-	up(&AFFS_I(inode)->i_hash_lock);
+	mutex_unlock(&AFFS_I(inode)->i_link_lock);
 }
 static inline void
 affs_lock_ext(struct inode *inode)
 {
-	down(&AFFS_I(inode)->i_ext_lock);
+	mutex_lock(&AFFS_I(inode)->i_ext_lock);
 }
 static inline void
 affs_unlock_ext(struct inode *inode)
 {
-	up(&AFFS_I(inode)->i_ext_lock);
+	mutex_unlock(&AFFS_I(inode)->i_ext_lock);
 }
+
+#define affs_lock_dir(i)	affs_lock_ext(i)
+#define affs_unlock_dir(i)	affs_unlock_ext(i)
Index: linux-2.6-tip/fs/affs/super.c
===================================================================
--- linux-2.6-tip.orig/fs/affs/super.c
+++ linux-2.6-tip/fs/affs/super.c
@@ -113,8 +113,8 @@ static void init_once(void *foo)
 {
 	struct affs_inode_info *ei = (struct affs_inode_info *) foo;
 
-	init_MUTEX(&ei->i_link_lock);
-	init_MUTEX(&ei->i_ext_lock);
+	mutex_init(&ei->i_link_lock);
+	mutex_init(&ei->i_ext_lock);
 	inode_init_once(&ei->vfs_inode);
 }
 



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

* [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (5 preceding siblings ...)
  2010-01-29 20:38 ` [patch 06/10] affs: Convert semaphores to mutexes Thomas Gleixner
@ 2010-01-29 20:38 ` Thomas Gleixner
  2010-01-29 21:14   ` Greg KH
  2010-01-29 20:39 ` [patch 08/10] drivers/base: Convert dev->sem " Thomas Gleixner
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:38 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Greg Kroah-Hartman

[-- Attachment #1: usb-gadgetfs-convert-sema.patch --]
[-- Type: text/plain, Size: 4568 bytes --]

The semaphore data->lock is semantically a mutex. Convert it to a real
mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/usb/gadget/inode.c |   39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

Index: linux-2.6-tip/drivers/usb/gadget/inode.c
===================================================================
--- linux-2.6-tip.orig/drivers/usb/gadget/inode.c
+++ linux-2.6-tip/drivers/usb/gadget/inode.c
@@ -194,7 +194,7 @@ enum ep_state {
 };
 
 struct ep_data {
-	struct semaphore		lock;
+	struct mutex			lock;
 	enum ep_state			state;
 	atomic_t			count;
 	struct dev_data			*dev;
@@ -298,10 +298,10 @@ get_ready_ep (unsigned f_flags, struct e
 	int	val;
 
 	if (f_flags & O_NONBLOCK) {
-		if (down_trylock (&epdata->lock) != 0)
+		if (!mutex_trylock(&epdata->lock))
 			goto nonblock;
 		if (epdata->state != STATE_EP_ENABLED) {
-			up (&epdata->lock);
+			mutex_unlock(&epdata->lock);
 nonblock:
 			val = -EAGAIN;
 		} else
@@ -309,7 +309,8 @@ nonblock:
 		return val;
 	}
 
-	if ((val = down_interruptible (&epdata->lock)) < 0)
+	val = mutex_lock_interruptible(&epdata->lock);
+	if (val < 0)
 		return val;
 
 	switch (epdata->state) {
@@ -323,7 +324,7 @@ nonblock:
 		// FALLTHROUGH
 	case STATE_EP_UNBOUND:			/* clean disconnect */
 		val = -ENODEV;
-		up (&epdata->lock);
+		mutex_unlock(&epdata->lock);
 	}
 	return val;
 }
@@ -393,7 +394,7 @@ ep_read (struct file *fd, char __user *b
 		if (likely (data->ep != NULL))
 			usb_ep_set_halt (data->ep);
 		spin_unlock_irq (&data->dev->lock);
-		up (&data->lock);
+		mutex_unlock(&data->lock);
 		return -EBADMSG;
 	}
 
@@ -411,7 +412,7 @@ ep_read (struct file *fd, char __user *b
 		value = -EFAULT;
 
 free1:
-	up (&data->lock);
+	mutex_unlock(&data->lock);
 	kfree (kbuf);
 	return value;
 }
@@ -436,7 +437,7 @@ ep_write (struct file *fd, const char __
 		if (likely (data->ep != NULL))
 			usb_ep_set_halt (data->ep);
 		spin_unlock_irq (&data->dev->lock);
-		up (&data->lock);
+		mutex_unlock(&data->lock);
 		return -EBADMSG;
 	}
 
@@ -455,7 +456,7 @@ ep_write (struct file *fd, const char __
 	VDEBUG (data->dev, "%s write %zu IN, status %d\n",
 		data->name, len, (int) value);
 free1:
-	up (&data->lock);
+	mutex_unlock(&data->lock);
 	kfree (kbuf);
 	return value;
 }
@@ -466,7 +467,8 @@ ep_release (struct inode *inode, struct 
 	struct ep_data		*data = fd->private_data;
 	int value;
 
-	if ((value = down_interruptible(&data->lock)) < 0)
+	value = mutex_lock_interruptible(&data->lock);
+	if (value < 0)
 		return value;
 
 	/* clean up if this can be reopened */
@@ -476,7 +478,7 @@ ep_release (struct inode *inode, struct 
 		data->hs_desc.bDescriptorType = 0;
 		usb_ep_disable(data->ep);
 	}
-	up (&data->lock);
+	mutex_unlock(&data->lock);
 	put_ep (data);
 	return 0;
 }
@@ -507,7 +509,7 @@ static long ep_ioctl(struct file *fd, un
 	} else
 		status = -ENODEV;
 	spin_unlock_irq (&data->dev->lock);
-	up (&data->lock);
+	mutex_unlock(&data->lock);
 	return status;
 }
 
@@ -673,7 +675,7 @@ fail:
 		value = -ENODEV;
 	spin_unlock_irq(&epdata->dev->lock);
 
-	up(&epdata->lock);
+	mutex_unlock(&epdata->lock);
 
 	if (unlikely(value)) {
 		kfree(priv);
@@ -765,7 +767,8 @@ ep_config (struct file *fd, const char _
 	u32			tag;
 	int			value, length = len;
 
-	if ((value = down_interruptible (&data->lock)) < 0)
+	value = mutex_lock_interruptible(&data->lock);
+	if (value < 0)
 		return value;
 
 	if (data->state != STATE_EP_READY) {
@@ -854,7 +857,7 @@ fail:
 		data->desc.bDescriptorType = 0;
 		data->hs_desc.bDescriptorType = 0;
 	}
-	up (&data->lock);
+	mutex_unlock(&data->lock);
 	return value;
 fail0:
 	value = -EINVAL;
@@ -870,7 +873,7 @@ ep_open (struct inode *inode, struct fil
 	struct ep_data		*data = inode->i_private;
 	int			value = -EBUSY;
 
-	if (down_interruptible (&data->lock) != 0)
+	if (mutex_lock_interruptible(&data->lock) != 0)
 		return -EINTR;
 	spin_lock_irq (&data->dev->lock);
 	if (data->dev->state == STATE_DEV_UNBOUND)
@@ -885,7 +888,7 @@ ep_open (struct inode *inode, struct fil
 		DBG (data->dev, "%s state %d\n",
 			data->name, data->state);
 	spin_unlock_irq (&data->dev->lock);
-	up (&data->lock);
+	mutex_unlock(&data->lock);
 	return value;
 }
 
@@ -1631,7 +1634,7 @@ static int activate_ep_files (struct dev
 		if (!data)
 			goto enomem0;
 		data->state = STATE_EP_DISABLED;
-		init_MUTEX (&data->lock);
+		mutex_init(&data->lock);
 		init_waitqueue_head (&data->wait);
 
 		strncpy (data->name, ep->name, sizeof (data->name) - 1);



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

* [patch 08/10] drivers/base: Convert dev->sem to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (6 preceding siblings ...)
  2010-01-29 20:38 ` [patch 07/10] usb: gadgetfs: Convert semaphore to mutex Thomas Gleixner
@ 2010-01-29 20:39 ` Thomas Gleixner
  2010-01-29 21:13   ` Greg KH
  2010-01-29 20:39 ` [patch 09/10] block: drbd: Convert semaphore " Thomas Gleixner
  2010-01-29 20:39 ` [patch 10/10] hwmon: s3c-hwmon: " Thomas Gleixner
  9 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:39 UTC (permalink / raw)
  To: LKML; +Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Greg Kroah-Hartman

[-- Attachment #1: drivers-base-convert-sema.patch --]
[-- Type: text/plain, Size: 17249 bytes --]

The semaphore is semantically a mutex. Convert it to a real mutex and
clean up all users outside of drivers/base as well.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/bus.c             |   20 ++++++++++----------
 drivers/base/core.c            |    3 +--
 drivers/base/dd.c              |   38 +++++++++++++++++++-------------------
 drivers/base/power/main.c      |   20 ++++++++++----------
 drivers/firewire/core-device.c |    4 ++--
 drivers/ieee1394/nodemgr.c     |    4 ++--
 drivers/net/mlx4/mlx4.h        |    1 +
 drivers/pci/bus.c              |    4 ++--
 drivers/pci/pci.c              |    4 ++--
 drivers/pcmcia/ds.c            |    8 ++++----
 drivers/usb/core/driver.c      |    4 ++--
 drivers/usb/core/usb.c         |    2 +-
 drivers/uwb/umc-bus.c          |    4 ++--
 drivers/uwb/uwb-internal.h     |    4 ++--
 include/linux/device.h         |    5 ++---
 include/linux/usb.h            |    6 +++---
 16 files changed, 65 insertions(+), 66 deletions(-)

Index: linux-2.6-tip/drivers/base/bus.c
===================================================================
--- linux-2.6-tip.orig/drivers/base/bus.c
+++ linux-2.6-tip/drivers/base/bus.c
@@ -173,10 +173,10 @@ static ssize_t driver_unbind(struct devi
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
+			mutex_lock(&dev->parent->mutex);
 		device_release_driver(dev);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 		err = count;
 	}
 	put_device(dev);
@@ -200,12 +200,12 @@ static ssize_t driver_bind(struct device
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
-		down(&dev->sem);
+			mutex_lock(&dev->parent->mutex);
+		mutex_lock(&dev->mutex);
 		err = driver_probe_device(drv, dev);
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 
 		if (err > 0) {
 			/* success */
@@ -744,10 +744,10 @@ static int __must_check bus_rescan_devic
 
 	if (!dev->driver) {
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
+			mutex_lock(&dev->parent->mutex);
 		ret = device_attach(dev);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 	}
 	return ret < 0 ? ret : 0;
 }
@@ -779,10 +779,10 @@ int device_reprobe(struct device *dev)
 {
 	if (dev->driver) {
 		if (dev->parent)        /* Needed for USB */
-			down(&dev->parent->sem);
+			mutex_lock(&dev->parent->mutex);
 		device_release_driver(dev);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 	}
 	return bus_rescan_devices_helper(dev, NULL);
 }
Index: linux-2.6-tip/drivers/base/core.c
===================================================================
--- linux-2.6-tip.orig/drivers/base/core.c
+++ linux-2.6-tip/drivers/base/core.c
@@ -20,7 +20,6 @@
 #include <linux/notifier.h>
 #include <linux/genhd.h>
 #include <linux/kallsyms.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
 
@@ -564,7 +563,7 @@ void device_initialize(struct device *de
 	dev->kobj.kset = devices_kset;
 	kobject_init(&dev->kobj, &device_ktype);
 	INIT_LIST_HEAD(&dev->dma_pools);
-	init_MUTEX(&dev->sem);
+	mutex_init(&dev->mutex);
 	spin_lock_init(&dev->devres_lock);
 	INIT_LIST_HEAD(&dev->devres_head);
 	device_init_wakeup(dev, 0);
Index: linux-2.6-tip/drivers/base/dd.c
===================================================================
--- linux-2.6-tip.orig/drivers/base/dd.c
+++ linux-2.6-tip/drivers/base/dd.c
@@ -85,7 +85,7 @@ static void driver_sysfs_remove(struct d
  * for before calling this. (It is ok to call with no other effort
  * from a driver's probe() method.)
  *
- * This function must be called with @dev->sem held.
+ * This function must be called with @dev->mutex held.
  */
 int device_bind_driver(struct device *dev)
 {
@@ -190,8 +190,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe)
  * This function returns -ENODEV if the device is not registered,
  * 1 if the device is bound successfully and 0 otherwise.
  *
- * This function must be called with @dev->sem held.  When called for a
- * USB interface, @dev->parent->sem must be held as well.
+ * This function must be called with @dev->mutex  held.  When called for a
+ * USB interface, @dev->parent->mutex must be held as well.
  */
 int driver_probe_device(struct device_driver *drv, struct device *dev)
 {
@@ -233,13 +233,13 @@ static int __device_attach(struct device
  * 0 if no matching driver was found;
  * -ENODEV if the device is not registered.
  *
- * When called for a USB interface, @dev->parent->sem must be held.
+ * When called for a USB interface, @dev->parent->mutex must be held.
  */
 int device_attach(struct device *dev)
 {
 	int ret = 0;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	if (dev->driver) {
 		ret = device_bind_driver(dev);
 		if (ret == 0)
@@ -253,7 +253,7 @@ int device_attach(struct device *dev)
 		ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
 		pm_runtime_put_sync(dev);
 	}
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(device_attach);
@@ -276,13 +276,13 @@ static int __driver_attach(struct device
 		return 0;
 
 	if (dev->parent)	/* Needed for USB */
-		down(&dev->parent->sem);
-	down(&dev->sem);
+		mutex_lock(&dev->parent->mutex);
+	mutex_lock(&dev->mutex);
 	if (!dev->driver)
 		driver_probe_device(drv, dev);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 	if (dev->parent)
-		up(&dev->parent->sem);
+		mutex_unlock(&dev->parent->mutex);
 
 	return 0;
 }
@@ -303,8 +303,8 @@ int driver_attach(struct device_driver *
 EXPORT_SYMBOL_GPL(driver_attach);
 
 /*
- * __device_release_driver() must be called with @dev->sem held.
- * When called for a USB interface, @dev->parent->sem must be held as well.
+ * __device_release_driver() must be called with @dev->mutex held.
+ * When called for a USB interface, @dev->parent->mutex must be held as well.
  */
 static void __device_release_driver(struct device *dev)
 {
@@ -343,7 +343,7 @@ static void __device_release_driver(stru
  * @dev: device.
  *
  * Manually detach device from driver.
- * When called for a USB interface, @dev->parent->sem must be held.
+ * When called for a USB interface, @dev->parent->mutex must be held.
  */
 void device_release_driver(struct device *dev)
 {
@@ -352,9 +352,9 @@ void device_release_driver(struct device
 	 * within their ->remove callback for the same device, they
 	 * will deadlock right here.
 	 */
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	__device_release_driver(dev);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 }
 EXPORT_SYMBOL_GPL(device_release_driver);
 
@@ -381,13 +381,13 @@ void driver_detach(struct device_driver 
 		spin_unlock(&drv->p->klist_devices.k_lock);
 
 		if (dev->parent)	/* Needed for USB */
-			down(&dev->parent->sem);
-		down(&dev->sem);
+			mutex_lock(&dev->parent->mutex);
+		mutex_lock(&dev->mutex);
 		if (dev->driver == drv)
 			__device_release_driver(dev);
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 		if (dev->parent)
-			up(&dev->parent->sem);
+			mutex_unlock(&dev->parent->mutex);
 		put_device(dev);
 	}
 }
Index: linux-2.6-tip/drivers/base/power/main.c
===================================================================
--- linux-2.6-tip.orig/drivers/base/power/main.c
+++ linux-2.6-tip/drivers/base/power/main.c
@@ -34,8 +34,8 @@
  * because children are guaranteed to be discovered after parents, and
  * are inserted at the back of the list on discovery.
  *
- * Since device_pm_add() may be called with a device semaphore held,
- * we must never try to acquire a device semaphore while holding
+ * Since device_pm_add() may be called with a device mutex held,
+ * we must never try to acquire a device mutex while holding
  * dpm_list_mutex.
  */
 
@@ -476,7 +476,7 @@ static int device_resume(struct device *
 	TRACE_DEVICE(dev);
 	TRACE_RESUME(0);
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->bus) {
 		if (dev->bus->pm) {
@@ -509,7 +509,7 @@ static int device_resume(struct device *
 		}
 	}
  End:
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 
 	TRACE_RESUME(error);
 	return error;
@@ -564,7 +564,7 @@ static void dpm_resume(pm_message_t stat
  */
 static void device_complete(struct device *dev, pm_message_t state)
 {
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->class && dev->class->pm && dev->class->pm->complete) {
 		pm_dev_dbg(dev, state, "completing class ");
@@ -581,7 +581,7 @@ static void device_complete(struct devic
 		dev->bus->pm->complete(dev);
 	}
 
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 }
 
 /**
@@ -740,7 +740,7 @@ static int device_suspend(struct device 
 {
 	int error = 0;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->class) {
 		if (dev->class->pm) {
@@ -773,7 +773,7 @@ static int device_suspend(struct device 
 		}
 	}
  End:
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 
 	return error;
 }
@@ -828,7 +828,7 @@ static int device_prepare(struct device 
 {
 	int error = 0;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 
 	if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
 		pm_dev_dbg(dev, state, "preparing ");
@@ -852,7 +852,7 @@ static int device_prepare(struct device 
 		suspend_report_result(dev->class->pm->prepare, error);
 	}
  End:
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 
 	return error;
 }
Index: linux-2.6-tip/drivers/firewire/core-device.c
===================================================================
--- linux-2.6-tip.orig/drivers/firewire/core-device.c
+++ linux-2.6-tip/drivers/firewire/core-device.c
@@ -762,9 +762,9 @@ static int update_unit(struct device *de
 	struct fw_driver *driver = (struct fw_driver *)dev->driver;
 
 	if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) {
-		down(&dev->sem);
+		mutex_lock(&dev->mutex);
 		driver->update(unit);
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 	}
 
 	return 0;
Index: linux-2.6-tip/drivers/ieee1394/nodemgr.c
===================================================================
--- linux-2.6-tip.orig/drivers/ieee1394/nodemgr.c
+++ linux-2.6-tip/drivers/ieee1394/nodemgr.c
@@ -1397,9 +1397,9 @@ static int update_pdrv(struct device *de
 			pdrv = container_of(drv, struct hpsb_protocol_driver,
 					    driver);
 			if (pdrv->update) {
-				down(&ud->device.sem);
+				mutex_lock(&ud->device.mutex);
 				error = pdrv->update(ud);
-				up(&ud->device.sem);
+				mutex_unlock(&ud->device.mutex);
 			}
 			if (error)
 				device_release_driver(&ud->device);
Index: linux-2.6-tip/drivers/net/mlx4/mlx4.h
===================================================================
--- linux-2.6-tip.orig/drivers/net/mlx4/mlx4.h
+++ linux-2.6-tip/drivers/net/mlx4/mlx4.h
@@ -40,6 +40,7 @@
 #include <linux/mutex.h>
 #include <linux/radix-tree.h>
 #include <linux/timer.h>
+#include <linux/semaphore.h>
 #include <linux/workqueue.h>
 
 #include <linux/mlx4/device.h>
Index: linux-2.6-tip/drivers/pci/bus.c
===================================================================
--- linux-2.6-tip.orig/drivers/pci/bus.c
+++ linux-2.6-tip/drivers/pci/bus.c
@@ -240,9 +240,9 @@ void pci_walk_bus(struct pci_bus *top, i
 			next = dev->bus_list.next;
 
 		/* Run device routines with the device locked */
-		down(&dev->dev.sem);
+		mutex_lock(&dev->dev.mutex);
 		retval = cb(dev, userdata);
-		up(&dev->dev.sem);
+		mutex_unlock(&dev->dev.mutex);
 		if (retval)
 			break;
 	}
Index: linux-2.6-tip/drivers/pci/pci.c
===================================================================
--- linux-2.6-tip.orig/drivers/pci/pci.c
+++ linux-2.6-tip/drivers/pci/pci.c
@@ -2304,7 +2304,7 @@ static int pci_dev_reset(struct pci_dev 
 	if (!probe) {
 		pci_block_user_cfg_access(dev);
 		/* block PM suspend, driver probe, etc. */
-		down(&dev->dev.sem);
+		mutex_lock(&dev->dev.mutex);
 	}
 
 	rc = pci_dev_specific_reset(dev, probe);
@@ -2326,7 +2326,7 @@ static int pci_dev_reset(struct pci_dev 
 	rc = pci_parent_bus_reset(dev, probe);
 done:
 	if (!probe) {
-		up(&dev->dev.sem);
+		mutex_unlock(&dev->dev.mutex);
 		pci_unblock_user_cfg_access(dev);
 	}
 
Index: linux-2.6-tip/drivers/pcmcia/ds.c
===================================================================
--- linux-2.6-tip.orig/drivers/pcmcia/ds.c
+++ linux-2.6-tip/drivers/pcmcia/ds.c
@@ -964,9 +964,9 @@ static int runtime_suspend(struct device
 {
 	int rc;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	rc = pcmcia_dev_suspend(dev, PMSG_SUSPEND);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 	return rc;
 }
 
@@ -974,9 +974,9 @@ static void runtime_resume(struct device
 {
 	int rc;
 
-	down(&dev->sem);
+	mutex_lock(&dev->mutex);
 	rc = pcmcia_dev_resume(dev);
-	up(&dev->sem);
+	mutex_unlock(&dev->mutex);
 }
 
 /************************ per-device sysfs output ***************************/
Index: linux-2.6-tip/drivers/usb/core/driver.c
===================================================================
--- linux-2.6-tip.orig/drivers/usb/core/driver.c
+++ linux-2.6-tip/drivers/usb/core/driver.c
@@ -470,10 +470,10 @@ void usb_driver_release_interface(struct
 	if (device_is_registered(dev)) {
 		device_release_driver(dev);
 	} else {
-		down(&dev->sem);
+		mutex_lock(&dev->mutex);
 		usb_unbind_interface(dev);
 		dev->driver = NULL;
-		up(&dev->sem);
+		mutex_unlock(&dev->mutex);
 	}
 }
 EXPORT_SYMBOL_GPL(usb_driver_release_interface);
Index: linux-2.6-tip/drivers/usb/core/usb.c
===================================================================
--- linux-2.6-tip.orig/drivers/usb/core/usb.c
+++ linux-2.6-tip/drivers/usb/core/usb.c
@@ -601,7 +601,7 @@ int usb_lock_device_for_reset(struct usb
 			iface->condition == USB_INTERFACE_UNBOUND))
 		return -EINTR;
 
-	while (usb_trylock_device(udev) != 0) {
+	while (!usb_trylock_device(udev)) {
 
 		/* If we can't acquire the lock after waiting one second,
 		 * we're probably deadlocked */
Index: linux-2.6-tip/drivers/uwb/umc-bus.c
===================================================================
--- linux-2.6-tip.orig/drivers/uwb/umc-bus.c
+++ linux-2.6-tip/drivers/uwb/umc-bus.c
@@ -62,12 +62,12 @@ int umc_controller_reset(struct umc_dev 
 	struct device *parent = umc->dev.parent;
 	int ret = 0;
 
-	if(down_trylock(&parent->sem))
+	if (!mutex_trylock(&parent->mutex))
 		return -EAGAIN;
 	ret = device_for_each_child(parent, parent, umc_bus_pre_reset_helper);
 	if (ret >= 0)
 		ret = device_for_each_child(parent, parent, umc_bus_post_reset_helper);
-	up(&parent->sem);
+	mutex_unlock(&parent->mutex);
 
 	return ret;
 }
Index: linux-2.6-tip/drivers/uwb/uwb-internal.h
===================================================================
--- linux-2.6-tip.orig/drivers/uwb/uwb-internal.h
+++ linux-2.6-tip/drivers/uwb/uwb-internal.h
@@ -366,12 +366,12 @@ struct dentry *uwb_dbg_create_pal_dir(st
 
 static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
 {
-	down(&uwb_dev->dev.sem);
+	mutex_lock(&uwb_dev->dev.mutex);
 }
 
 static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
 {
-	up(&uwb_dev->dev.sem);
+	mutex_unlock(&uwb_dev->dev.mutex);
 }
 
 #endif /* #ifndef __UWB_INTERNAL_H__ */
Index: linux-2.6-tip/include/linux/device.h
===================================================================
--- linux-2.6-tip.orig/include/linux/device.h
+++ linux-2.6-tip/include/linux/device.h
@@ -22,7 +22,6 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/semaphore.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
 
@@ -106,7 +105,7 @@ extern int bus_unregister_notifier(struc
 
 /* All 4 notifers below get called with the target struct device *
  * as an argument. Note that those functions are likely to be called
- * with the device semaphore held in the core, so be careful.
+ * with the device mutex held in the core, so be careful.
  */
 #define BUS_NOTIFY_ADD_DEVICE		0x00000001 /* device added */
 #define BUS_NOTIFY_DEL_DEVICE		0x00000002 /* device removed */
@@ -385,7 +384,7 @@ struct device {
 	const char		*init_name; /* initial name of the device */
 	struct device_type	*type;
 
-	struct semaphore	sem;	/* semaphore to synchronize calls to
+	struct mutex		mutex;	/* mutex to synchronize calls to
 					 * its driver.
 					 */
 
Index: linux-2.6-tip/include/linux/usb.h
===================================================================
--- linux-2.6-tip.orig/include/linux/usb.h
+++ linux-2.6-tip/include/linux/usb.h
@@ -527,9 +527,9 @@ extern struct usb_device *usb_get_dev(st
 extern void usb_put_dev(struct usb_device *dev);
 
 /* USB device locking */
-#define usb_lock_device(udev)		down(&(udev)->dev.sem)
-#define usb_unlock_device(udev)		up(&(udev)->dev.sem)
-#define usb_trylock_device(udev)	down_trylock(&(udev)->dev.sem)
+#define usb_lock_device(udev)		mutex_lock(&(udev)->dev.mutex)
+#define usb_unlock_device(udev)		mutex_unlock(&(udev)->dev.mutex)
+#define usb_trylock_device(udev)	mutex_trylock(&(udev)->dev.mutex)
 extern int usb_lock_device_for_reset(struct usb_device *udev,
 				     const struct usb_interface *iface);
 



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

* [patch 09/10] block: drbd: Convert semaphore to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (7 preceding siblings ...)
  2010-01-29 20:39 ` [patch 08/10] drivers/base: Convert dev->sem " Thomas Gleixner
@ 2010-01-29 20:39 ` Thomas Gleixner
  2010-01-29 20:39 ` [patch 10/10] hwmon: s3c-hwmon: " Thomas Gleixner
  9 siblings, 0 replies; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:39 UTC (permalink / raw)
  To: LKML
  Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Lars Ellenberg,
	Philipp Reisner, Jens Axboe, drbd-user

[-- Attachment #1: drivers-block-drbd-use-mutex.patch --]
[-- Type: text/plain, Size: 2055 bytes --]

The bm_change semaphore is semantically a mutex. Convert it to a real
mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Lars Ellenberg <drbd-dev@lists.linbit.com>
Cc: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: drbd-user@lists.linbit.com

---
 drivers/block/drbd/drbd_bitmap.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Index: linux-2.6-tip/drivers/block/drbd/drbd_bitmap.c
===================================================================
--- linux-2.6-tip.orig/drivers/block/drbd/drbd_bitmap.c
+++ linux-2.6-tip/drivers/block/drbd/drbd_bitmap.c
@@ -66,7 +66,7 @@ struct drbd_bitmap {
 	size_t   bm_words;
 	size_t   bm_number_of_pages;
 	sector_t bm_dev_capacity;
-	struct semaphore bm_change; /* serializes resize operations */
+	struct mutex bm_change; /* serializes resize operations */
 
 	atomic_t bm_async_io;
 	wait_queue_head_t bm_io_wait;
@@ -114,7 +114,7 @@ void drbd_bm_lock(struct drbd_conf *mdev
 		return;
 	}
 
-	trylock_failed = down_trylock(&b->bm_change);
+	trylock_failed = !mutex_trylock(&b->bm_change);
 
 	if (trylock_failed) {
 		dev_warn(DEV, "%s going to '%s' but bitmap already locked for '%s' by %s\n",
@@ -125,7 +125,7 @@ void drbd_bm_lock(struct drbd_conf *mdev
 		    b->bm_task == mdev->receiver.task ? "receiver" :
 		    b->bm_task == mdev->asender.task  ? "asender"  :
 		    b->bm_task == mdev->worker.task   ? "worker"   : "?");
-		down(&b->bm_change);
+		mutex_lock(&b->bm_change);
 	}
 	if (__test_and_set_bit(BM_LOCKED, &b->bm_flags))
 		dev_err(DEV, "FIXME bitmap already locked in bm_lock\n");
@@ -147,7 +147,7 @@ void drbd_bm_unlock(struct drbd_conf *md
 
 	b->bm_why  = NULL;
 	b->bm_task = NULL;
-	up(&b->bm_change);
+	mutex_unlock(&b->bm_change);
 }
 
 /* word offset to long pointer */
@@ -295,7 +295,7 @@ int drbd_bm_init(struct drbd_conf *mdev)
 	if (!b)
 		return -ENOMEM;
 	spin_lock_init(&b->bm_lock);
-	init_MUTEX(&b->bm_change);
+	mutex_init(&b->bm_change);
 	init_waitqueue_head(&b->bm_io_wait);
 
 	mdev->bitmap = b;



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

* [patch 10/10] hwmon: s3c-hwmon: Convert semaphore to mutex
  2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
                   ` (8 preceding siblings ...)
  2010-01-29 20:39 ` [patch 09/10] block: drbd: Convert semaphore " Thomas Gleixner
@ 2010-01-29 20:39 ` Thomas Gleixner
  9 siblings, 0 replies; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 20:39 UTC (permalink / raw)
  To: LKML
  Cc: Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Ben Dooks,
	Jean Delvare, lm-sensors

[-- Attachment #1: hwmon-23c-hwmon-sema.patch --]
[-- Type: text/plain, Size: 1315 bytes --]

hwmon->lock is used as a mutex. Make it a real mutex.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Ben Dooks <ben-linux@fluff.org>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: lm-sensors@lm-sensors.org
---
 drivers/hwmon/s3c-hwmon.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6-tip/drivers/hwmon/s3c-hwmon.c
===================================================================
--- linux-2.6-tip.orig/drivers/hwmon/s3c-hwmon.c
+++ linux-2.6-tip/drivers/hwmon/s3c-hwmon.c
@@ -51,7 +51,7 @@ struct s3c_hwmon_attr {
  * @attr: The holders for the channel attributes.
 */
 struct s3c_hwmon {
-	struct semaphore	lock;
+	struct mutex		lock;
 	struct s3c_adc_client	*client;
 	struct device		*hwmon_dev;
 
@@ -73,14 +73,14 @@ static int s3c_hwmon_read_ch(struct devi
 {
 	int ret;
 
-	ret = down_interruptible(&hwmon->lock);
+	ret = mutex_lock_interruptible(&hwmon->lock);
 	if (ret < 0)
 		return ret;
 
 	dev_dbg(dev, "reading channel %d\n", channel);
 
 	ret = s3c_adc_read(hwmon->client, channel);
-	up(&hwmon->lock);
+	mutex_unlock(&hwmon->lock);
 
 	return ret;
 }
@@ -296,7 +296,7 @@ static int __devinit s3c_hwmon_probe(str
 
 	platform_set_drvdata(dev, hwmon);
 
-	init_MUTEX(&hwmon->lock);
+	mutex_init(&hwmon->lock);
 
 	/* Register with the core ADC driver. */
 



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

* Re: [patch 08/10] drivers/base: Convert dev->sem to mutex
  2010-01-29 20:39 ` [patch 08/10] drivers/base: Convert dev->sem " Thomas Gleixner
@ 2010-01-29 21:13   ` Greg KH
  2010-01-29 21:48     ` Thomas Gleixner
  0 siblings, 1 reply; 28+ messages in thread
From: Greg KH @ 2010-01-29 21:13 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, Jan 29, 2010 at 08:39:02PM -0000, Thomas Gleixner wrote:
> The semaphore is semantically a mutex. Convert it to a real mutex and
> clean up all users outside of drivers/base as well.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Greg Kroah-Hartman <gregkh@suse.de>

Acked-by: Greg Kroah-Hartman <gregkh@suse.de>


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

* Re: [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
  2010-01-29 20:38 ` [patch 07/10] usb: gadgetfs: Convert semaphore to mutex Thomas Gleixner
@ 2010-01-29 21:14   ` Greg KH
  2010-01-29 21:48     ` Thomas Gleixner
  0 siblings, 1 reply; 28+ messages in thread
From: Greg KH @ 2010-01-29 21:14 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, Jan 29, 2010 at 08:38:59PM -0000, Thomas Gleixner wrote:
> The semaphore data->lock is semantically a mutex. Convert it to a real
> mutex.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Greg Kroah-Hartman <gregkh@suse.de>

Acked-by: Greg Kroah-Hartman <gregkh@suse.de>

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

* Re: [patch 08/10] drivers/base: Convert dev->sem to mutex
  2010-01-29 21:13   ` Greg KH
@ 2010-01-29 21:48     ` Thomas Gleixner
  2010-01-30  5:26       ` Greg KH
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 21:48 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, 29 Jan 2010, Greg KH wrote:

> On Fri, Jan 29, 2010 at 08:39:02PM -0000, Thomas Gleixner wrote:
> > The semaphore is semantically a mutex. Convert it to a real mutex and
> > clean up all users outside of drivers/base as well.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Greg Kroah-Hartman <gregkh@suse.de>
> 
> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>

Can you take that via your drivers tree or do you want me to push it
linuswards for .34 ?

Thanks,

	tglx


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

* Re: [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
  2010-01-29 21:14   ` Greg KH
@ 2010-01-29 21:48     ` Thomas Gleixner
  2010-01-29 22:07       ` Greg KH
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 21:48 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, 29 Jan 2010, Greg KH wrote:

> On Fri, Jan 29, 2010 at 08:38:59PM -0000, Thomas Gleixner wrote:
> > The semaphore data->lock is semantically a mutex. Convert it to a real
> > mutex.
> > 
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Greg Kroah-Hartman <gregkh@suse.de>
> 
> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>

Can you take that via your usb tree or do you want me to push it
linuswards for .34 ?

Thanks,

        tglx
 

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

* Re: [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
  2010-01-29 21:48     ` Thomas Gleixner
@ 2010-01-29 22:07       ` Greg KH
  2010-01-29 23:04         ` Thomas Gleixner
  0 siblings, 1 reply; 28+ messages in thread
From: Greg KH @ 2010-01-29 22:07 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, Jan 29, 2010 at 10:48:36PM +0100, Thomas Gleixner wrote:
> On Fri, 29 Jan 2010, Greg KH wrote:
> 
> > On Fri, Jan 29, 2010 at 08:38:59PM -0000, Thomas Gleixner wrote:
> > > The semaphore data->lock is semantically a mutex. Convert it to a real
> > > mutex.
> > > 
> > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > > Cc: Greg Kroah-Hartman <gregkh@suse.de>
> > 
> > Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
> 
> Can you take that via your usb tree or do you want me to push it
> linuswards for .34 ?

I tried to do this last time the patches were posted, but the core mutex
changes were not in Linus's tree yet, so I could not as it broke my
build.

Has this changed?  If so, I would be glad to do so.  If not, I can't :(

thanks,

greg k-h

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

* Re: [patch 01/10] smbfs: Convert server->sem to mutex
  2010-01-29 20:38 ` [patch 01/10] smbfs: Convert server->sem to mutex Thomas Gleixner
@ 2010-01-29 22:14   ` Christoph Hellwig
  0 siblings, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2010-01-29 22:14 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro,
	Jeff Layton, Steve French

On Fri, Jan 29, 2010 at 08:38:34PM -0000, Thomas Gleixner wrote:
> The semaphore server->sem is used as mutex. Rename it to server->mutex
> and convert it to a real mutex.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Jeff Layton <jlayton@redhat.com>
> Cc: Steve French <sfrench@us.ibm.com>

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>

>  static inline int
>  smb_lock_server_interruptible(struct smb_sb_info *server)
>  {
> -	return down_interruptible(&(server->sem));
> +	return mutex_lock_interruptible(&server->mutex);
>  }
>  
>  static inline void
>  smb_lock_server(struct smb_sb_info *server)
>  {
> -	down(&(server->sem));
> +	mutex_lock(&server->mutex);
>  }
>  
>  static inline void
>  smb_unlock_server(struct smb_sb_info *server)
>  {
> -	up(&(server->sem));
> +	mutex_unlock(&server->mutex);
>  }

Eventually someone should also kill this useless wrappers, but let's do
one thing at a time for now.


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

* Re: [patch 02/10] hpfs: Convert sbi->hpfs_creation_de to mutex
  2010-01-29 20:38 ` [patch 02/10] hpfs: Convert sbi->hpfs_creation_de " Thomas Gleixner
@ 2010-01-29 22:20   ` Christoph Hellwig
  0 siblings, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2010-01-29 22:20 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

On Fri, Jan 29, 2010 at 08:38:38PM -0000, Thomas Gleixner wrote:
> The sbi->hpfs_creation_de semaphore is used as mutex. Convert it to a
> real mutex.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Al Viro <viro@zeniv.linux.org.uk>

Looks good, although it was a bit nasty to verify with the useless
wrappers and conditional locking all over the place.


Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [patch 03/10] hpfsplus: Convert tree_lock to mutex
  2010-01-29 20:38 ` [patch 03/10] hpfsplus: Convert tree_lock " Thomas Gleixner
@ 2010-01-29 22:23   ` Christoph Hellwig
  0 siblings, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2010-01-29 22:23 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

On Fri, Jan 29, 2010 at 08:38:42PM -0000, Thomas Gleixner wrote:
> The tree_lock semaphore is used as mutex. Convert it to a real mutex.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> 
> ---
>  fs/hfsplus/bfind.c      |    4 ++--
>  fs/hfsplus/btree.c      |    2 +-
>  fs/hfsplus/hfsplus_fs.h |    2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [patch 06/10] affs: Convert semaphores to mutexes
  2010-01-29 20:38 ` [patch 06/10] affs: Convert semaphores to mutexes Thomas Gleixner
@ 2010-01-29 22:25   ` Al Viro
  2010-01-29 22:36   ` Christoph Hellwig
  1 sibling, 0 replies; 28+ messages in thread
From: Al Viro @ 2010-01-29 22:25 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, Jan 29, 2010 at 08:38:55PM -0000, Thomas Gleixner wrote:
> These semaphores are plain mutexes. Convert them to struct mutex.
> 
> Map affs_[un]lock_dir() to affs_[un]lock_ext() instead of the "#define
> i_hash_lock i_ext_lock" magic.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Al Viro <viro@zeniv.linux.org.uk>

Umm...  I'm not ready to sign off on that one without serious analysis;
there might be dragons.

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

* Re: [patch 04/10] hfs: Convert tree_lock to mutex
  2010-01-29 20:38 ` [patch 04/10] hfs: " Thomas Gleixner
@ 2010-01-29 22:26   ` Christoph Hellwig
  0 siblings, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2010-01-29 22:26 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

On Fri, Jan 29, 2010 at 08:38:46PM -0000, Thomas Gleixner wrote:
> The tree_lock semaphore is used as mutex. Convert it to a real mutex.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Al Viro <viro@zeniv.linux.org.uk>

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [patch 05/10] cifs: convert semaphore to mutex
  2010-01-29 20:38 ` [patch 05/10] cifs: convert semaphore " Thomas Gleixner
@ 2010-01-29 22:29   ` Christoph Hellwig
  0 siblings, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2010-01-29 22:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar,
	Jeff Layton, Steve French

On Fri, Jan 29, 2010 at 08:38:50PM -0000, Thomas Gleixner wrote:
> pSesInfo->sesSem is used as mutex. Rename it to session_mutex and
> convert it to a real mutex.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Jeff Layton <jlayton@redhat.com>
> Cc: Steve French <sfrench@us.ibm.com>

Looks good, but I'm pretty sure I've seen an equivalent patch on the
linux-cifs-client list before.


Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [patch 06/10] affs: Convert semaphores to mutexes
  2010-01-29 20:38 ` [patch 06/10] affs: Convert semaphores to mutexes Thomas Gleixner
  2010-01-29 22:25   ` Al Viro
@ 2010-01-29 22:36   ` Christoph Hellwig
  2010-01-29 23:03     ` Thomas Gleixner
  2010-01-29 23:41     ` Al Viro
  1 sibling, 2 replies; 28+ messages in thread
From: Christoph Hellwig @ 2010-01-29 22:36 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar, Al Viro

On Fri, Jan 29, 2010 at 08:38:55PM -0000, Thomas Gleixner wrote:
> These semaphores are plain mutexes. Convert them to struct mutex.

Looks good.

> Map affs_[un]lock_dir() to affs_[un]lock_ext() instead of the "#define
> i_hash_lock i_ext_lock" magic.

I'm not sure which of the remapping tricks is the worth one..

Btw, if we don't want lockdep to complain we'll need annotations on
affs_lock_dir as it's taken both on parent and child.


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

* Re: [patch 06/10] affs: Convert semaphores to mutexes
  2010-01-29 22:36   ` Christoph Hellwig
@ 2010-01-29 23:03     ` Thomas Gleixner
  2010-01-29 23:41     ` Al Viro
  1 sibling, 0 replies; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 23:03 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: LKML, Peter Zijlstra, Ingo Molnar, Al Viro

On Fri, 29 Jan 2010, Christoph Hellwig wrote:

> On Fri, Jan 29, 2010 at 08:38:55PM -0000, Thomas Gleixner wrote:
> > These semaphores are plain mutexes. Convert them to struct mutex.
> 
> Looks good.
> 
> > Map affs_[un]lock_dir() to affs_[un]lock_ext() instead of the "#define
> > i_hash_lock i_ext_lock" magic.
> 
> I'm not sure which of the remapping tricks is the worth one..
> 
> Btw, if we don't want lockdep to complain we'll need annotations on
> affs_lock_dir as it's taken both on parent and child.

Can we postpone this to the point where an actual affs user runs with
lockdep enabled ?

Thanks,

	tglx


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

* Re: [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
  2010-01-29 22:07       ` Greg KH
@ 2010-01-29 23:04         ` Thomas Gleixner
  2010-01-30  5:27           ` Greg KH
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Gleixner @ 2010-01-29 23:04 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, 29 Jan 2010, Greg KH wrote:

> On Fri, Jan 29, 2010 at 10:48:36PM +0100, Thomas Gleixner wrote:
> > On Fri, 29 Jan 2010, Greg KH wrote:
> > 
> > > On Fri, Jan 29, 2010 at 08:38:59PM -0000, Thomas Gleixner wrote:
> > > > The semaphore data->lock is semantically a mutex. Convert it to a real
> > > > mutex.
> > > > 
> > > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > > > Cc: Greg Kroah-Hartman <gregkh@suse.de>
> > > 
> > > Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
> > 
> > Can you take that via your usb tree or do you want me to push it
> > linuswards for .34 ?
> 
> I tried to do this last time the patches were posted, but the core mutex
> changes were not in Linus's tree yet, so I could not as it broke my
> build.
> 
> Has this changed?  If so, I would be glad to do so.  If not, I can't :(

The two patches have no dependencies on anything else. They just
convert to the existing mutex infrastructure.

Thanks,

	tglx

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

* Re: [patch 06/10] affs: Convert semaphores to mutexes
  2010-01-29 22:36   ` Christoph Hellwig
  2010-01-29 23:03     ` Thomas Gleixner
@ 2010-01-29 23:41     ` Al Viro
  1 sibling, 0 replies; 28+ messages in thread
From: Al Viro @ 2010-01-29 23:41 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Thomas Gleixner, LKML, Peter Zijlstra, Ingo Molnar

On Fri, Jan 29, 2010 at 05:36:27PM -0500, Christoph Hellwig wrote:
> On Fri, Jan 29, 2010 at 08:38:55PM -0000, Thomas Gleixner wrote:
> > These semaphores are plain mutexes. Convert them to struct mutex.
> 
> Looks good.
> 
> > Map affs_[un]lock_dir() to affs_[un]lock_ext() instead of the "#define
> > i_hash_lock i_ext_lock" magic.
> 
> I'm not sure which of the remapping tricks is the worth one..
> 
> Btw, if we don't want lockdep to complain we'll need annotations on
> affs_lock_dir as it's taken both on parent and child.

OK, I've recalled what's going on in there.

AFFS has really crappy layout.  What happens:
	* each file and each directory have on-disk entry that acts more
or less like an inode.
	* when file has N links, there are N-1 additional on-disk entries
with a linked list going through them and primary.
	* directory has a bunch of linked lists going through entries of
directory elements (primaries or add-ons).  Choice of list depends on
entry name (i.e. it's a hash).
	* there's even worse mess we fortunately do not support at all
(hardlinks to directories, years after everyone knew that it can't work).

Now imagine what has to happen on e.g. overwriting cross-directory rename()
when victim happens to be primary with several more links.  Draw the objects
and pointers involved, then draw the changes needed.  No, really - do that.

The worst part of PITA comes from the need to change unrelated (and
unpredictable) directory.  Primary _must_ remain linked from some directory.
So if some links are still around, we must choose some add-on, transplant
the primary in its place in whatever directory list it's on and then free
the orphaned add-on.

So we have two kinds of locks in addition to normal VFS one (i_mutex).
One protects the list of add-ons ("link" lock), another - directory
lists ("hash" lock).  Link lock is taken outside of any hash locks.

lookup and readdir take hash lock on directory.

create, symlink, mkdir and link are identical wrt locking - they take
link lock on object being added to directory, then hash lock on directory
itself.  Only link(2) needs both locks, obviously, but it's really not
worth complicating the common helper.

rmdir and unlink use the same helper; it
	* takes link lock on victim
	* takes hash lock on parent
	* if it's a directory
		* take hash lock on victim
		* check that it's empty
		* drop hash lock on victim
	* evicts the victim from the directory list
	* unlocks parent
	* if the victim is primary and there are extra links
		* grab hash lock on parent of another link [*]
		* transplant the victim into the directory list that used
		  to hold an alias, evicting the alias from it
		* drop hash lock
	* evict victim (or substitute victim) from the link list
	* drop link lock.

rename... is interesting.  First of all, if the target exist, it's killed
off a-la unlink().  Error recovery?  What error recovery?  Then we grab
hash lock on old parent, remove the object from directory list, unlock old
parent, grab hash lock on new parent, put the object into directory list in
new place and unlock new parent.  No error recovery again.  Trying to add
aforementioned error recovery would make locking even more interesting,
of course.

Trying to make the thing reasonably robust in case of a crash... forget
about it.

The bottom line: it is safe to convert to mutex, so ACK on that patch.
As for the lockdep, it should treat emptiness check in affs_remove_header()
as "nested, known to be safe" since we already hold i_mutex on both and
no other operation holds hash lock on more than one inode.

[*] Yes, it does mean bringing it in-core if it hadn't been there already.
Essentially with iget().  Isn't life wonderful?  Good thing we don't have
NFS exports for that wonder of software engineering...

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

* Re: [patch 08/10] drivers/base: Convert dev->sem to mutex
  2010-01-29 21:48     ` Thomas Gleixner
@ 2010-01-30  5:26       ` Greg KH
  0 siblings, 0 replies; 28+ messages in thread
From: Greg KH @ 2010-01-30  5:26 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Fri, Jan 29, 2010 at 10:48:08PM +0100, Thomas Gleixner wrote:
> On Fri, 29 Jan 2010, Greg KH wrote:
> 
> > On Fri, Jan 29, 2010 at 08:39:02PM -0000, Thomas Gleixner wrote:
> > > The semaphore is semantically a mutex. Convert it to a real mutex and
> > > clean up all users outside of drivers/base as well.
> > > 
> > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > > Cc: Greg Kroah-Hartman <gregkh@suse.de>
> > 
> > Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
> 
> Can you take that via your drivers tree or do you want me to push it
> linuswards for .34 ?

I will take it.

thanks,

greg k-h

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

* Re: [patch 07/10] usb: gadgetfs: Convert semaphore to mutex
  2010-01-29 23:04         ` Thomas Gleixner
@ 2010-01-30  5:27           ` Greg KH
  0 siblings, 0 replies; 28+ messages in thread
From: Greg KH @ 2010-01-30  5:27 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Christoph Hellwig, Peter Zijlstra, Ingo Molnar

On Sat, Jan 30, 2010 at 12:04:46AM +0100, Thomas Gleixner wrote:
> On Fri, 29 Jan 2010, Greg KH wrote:
> 
> > On Fri, Jan 29, 2010 at 10:48:36PM +0100, Thomas Gleixner wrote:
> > > On Fri, 29 Jan 2010, Greg KH wrote:
> > > 
> > > > On Fri, Jan 29, 2010 at 08:38:59PM -0000, Thomas Gleixner wrote:
> > > > > The semaphore data->lock is semantically a mutex. Convert it to a real
> > > > > mutex.
> > > > > 
> > > > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > > > > Cc: Greg Kroah-Hartman <gregkh@suse.de>
> > > > 
> > > > Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
> > > 
> > > Can you take that via your usb tree or do you want me to push it
> > > linuswards for .34 ?
> > 
> > I tried to do this last time the patches were posted, but the core mutex
> > changes were not in Linus's tree yet, so I could not as it broke my
> > build.
> > 
> > Has this changed?  If so, I would be glad to do so.  If not, I can't :(
> 
> The two patches have no dependencies on anything else. They just
> convert to the existing mutex infrastructure.

Oops, I was thinking this was the same as the last type of patches that
went out.  I'll queue these up in my tree and send them to Linus for
.34.

thanks,

greg k-h

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

end of thread, other threads:[~2010-01-30  5:31 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-29 20:38 [patch 00/10] semaphore to mutex conversions Thomas Gleixner
2010-01-29 20:38 ` [patch 01/10] smbfs: Convert server->sem to mutex Thomas Gleixner
2010-01-29 22:14   ` Christoph Hellwig
2010-01-29 20:38 ` [patch 02/10] hpfs: Convert sbi->hpfs_creation_de " Thomas Gleixner
2010-01-29 22:20   ` Christoph Hellwig
2010-01-29 20:38 ` [patch 03/10] hpfsplus: Convert tree_lock " Thomas Gleixner
2010-01-29 22:23   ` Christoph Hellwig
2010-01-29 20:38 ` [patch 04/10] hfs: " Thomas Gleixner
2010-01-29 22:26   ` Christoph Hellwig
2010-01-29 20:38 ` [patch 05/10] cifs: convert semaphore " Thomas Gleixner
2010-01-29 22:29   ` Christoph Hellwig
2010-01-29 20:38 ` [patch 06/10] affs: Convert semaphores to mutexes Thomas Gleixner
2010-01-29 22:25   ` Al Viro
2010-01-29 22:36   ` Christoph Hellwig
2010-01-29 23:03     ` Thomas Gleixner
2010-01-29 23:41     ` Al Viro
2010-01-29 20:38 ` [patch 07/10] usb: gadgetfs: Convert semaphore to mutex Thomas Gleixner
2010-01-29 21:14   ` Greg KH
2010-01-29 21:48     ` Thomas Gleixner
2010-01-29 22:07       ` Greg KH
2010-01-29 23:04         ` Thomas Gleixner
2010-01-30  5:27           ` Greg KH
2010-01-29 20:39 ` [patch 08/10] drivers/base: Convert dev->sem " Thomas Gleixner
2010-01-29 21:13   ` Greg KH
2010-01-29 21:48     ` Thomas Gleixner
2010-01-30  5:26       ` Greg KH
2010-01-29 20:39 ` [patch 09/10] block: drbd: Convert semaphore " Thomas Gleixner
2010-01-29 20:39 ` [patch 10/10] hwmon: s3c-hwmon: " Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).