aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-01-09 20:31:38 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-09 20:31:38 -0500
commit80c0531514516e43ae118ddf38424e06e5c3cb3c (patch)
tree2eef8cf8fdf505b18f83078d1eb41167e98f5b54 /include/linux
parenta457aa6c2bdd743bbbffd3f9e4fdbd8c71f8af1b (diff)
parent11b751ae8c8ca3fa24c85bd5a3e51dd9f95cda17 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/mingo/mutex-2.6
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/ext3_fs_i.h2
-rw-r--r--include/linux/fs.h13
-rw-r--r--include/linux/ide.h5
-rw-r--r--include/linux/jffs2_fs_i.h4
-rw-r--r--include/linux/kernel.h9
-rw-r--r--include/linux/loop.h4
-rw-r--r--include/linux/mm.h4
-rw-r--r--include/linux/mutex-debug.h21
-rw-r--r--include/linux/mutex.h119
-rw-r--r--include/linux/nfsd/nfsfh.h6
-rw-r--r--include/linux/pipe_fs_i.h2
-rw-r--r--include/linux/reiserfs_fs.h2
-rw-r--r--include/linux/sched.h5
13 files changed, 178 insertions, 18 deletions
diff --git a/include/linux/ext3_fs_i.h b/include/linux/ext3_fs_i.h
index 2914f7b07156..e71dd98dbcae 100644
--- a/include/linux/ext3_fs_i.h
+++ b/include/linux/ext3_fs_i.h
@@ -87,7 +87,7 @@ struct ext3_inode_info {
87#ifdef CONFIG_EXT3_FS_XATTR 87#ifdef CONFIG_EXT3_FS_XATTR
88 /* 88 /*
89 * Extended attributes can be read independently of the main file 89 * Extended attributes can be read independently of the main file
90 * data. Taking i_sem even when reading would cause contention 90 * data. Taking i_mutex even when reading would cause contention
91 * between readers of EAs and writers of regular file data, so 91 * between readers of EAs and writers of regular file data, so
92 * instead we synchronize on xattr_sem when reading or changing 92 * instead we synchronize on xattr_sem when reading or changing
93 * EAs. 93 * EAs.
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 4c82219b0fae..92ae3e2067b0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -219,6 +219,7 @@ extern int dir_notify_enable;
219#include <linux/prio_tree.h> 219#include <linux/prio_tree.h>
220#include <linux/init.h> 220#include <linux/init.h>
221#include <linux/sched.h> 221#include <linux/sched.h>
222#include <linux/mutex.h>
222 223
223#include <asm/atomic.h> 224#include <asm/atomic.h>
224#include <asm/semaphore.h> 225#include <asm/semaphore.h>
@@ -484,7 +485,7 @@ struct inode {
484 unsigned long i_blocks; 485 unsigned long i_blocks;
485 unsigned short i_bytes; 486 unsigned short i_bytes;
486 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ 487 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
487 struct semaphore i_sem; 488 struct mutex i_mutex;
488 struct rw_semaphore i_alloc_sem; 489 struct rw_semaphore i_alloc_sem;
489 struct inode_operations *i_op; 490 struct inode_operations *i_op;
490 struct file_operations *i_fop; /* former ->i_op->default_file_ops */ 491 struct file_operations *i_fop; /* former ->i_op->default_file_ops */
@@ -820,7 +821,7 @@ struct super_block {
820 unsigned long s_magic; 821 unsigned long s_magic;
821 struct dentry *s_root; 822 struct dentry *s_root;
822 struct rw_semaphore s_umount; 823 struct rw_semaphore s_umount;
823 struct semaphore s_lock; 824 struct mutex s_lock;
824 int s_count; 825 int s_count;
825 int s_syncing; 826 int s_syncing;
826 int s_need_sync_fs; 827 int s_need_sync_fs;
@@ -892,13 +893,13 @@ static inline int has_fs_excl(void)
892static inline void lock_super(struct super_block * sb) 893static inline void lock_super(struct super_block * sb)
893{ 894{
894 get_fs_excl(); 895 get_fs_excl();
895 down(&sb->s_lock); 896 mutex_lock(&sb->s_lock);
896} 897}
897 898
898static inline void unlock_super(struct super_block * sb) 899static inline void unlock_super(struct super_block * sb)
899{ 900{
900 put_fs_excl(); 901 put_fs_excl();
901 up(&sb->s_lock); 902 mutex_unlock(&sb->s_lock);
902} 903}
903 904
904/* 905/*
@@ -1191,7 +1192,7 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc);
1191 * directory. The name should be stored in the @name (with the 1192 * directory. The name should be stored in the @name (with the
1192 * understanding that it is already pointing to a a %NAME_MAX+1 sized 1193 * understanding that it is already pointing to a a %NAME_MAX+1 sized
1193 * buffer. get_name() should return %0 on success, a negative error code 1194 * buffer. get_name() should return %0 on success, a negative error code
1194 * or error. @get_name will be called without @parent->i_sem held. 1195 * or error. @get_name will be called without @parent->i_mutex held.
1195 * 1196 *
1196 * get_parent: 1197 * get_parent:
1197 * @get_parent should find the parent directory for the given @child which 1198 * @get_parent should find the parent directory for the given @child which
@@ -1213,7 +1214,7 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc);
1213 * nfsd_find_fh_dentry() in either the @obj or @parent parameters. 1214 * nfsd_find_fh_dentry() in either the @obj or @parent parameters.
1214 * 1215 *
1215 * Locking rules: 1216 * Locking rules:
1216 * get_parent is called with child->d_inode->i_sem down 1217 * get_parent is called with child->d_inode->i_mutex down
1217 * get_name is not (which is possibly inconsistent) 1218 * get_name is not (which is possibly inconsistent)
1218 */ 1219 */
1219 1220
diff --git a/include/linux/ide.h b/include/linux/ide.h
index ef8d0cbb832f..9a8c05dbe4f3 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -18,6 +18,7 @@
18#include <linux/bio.h> 18#include <linux/bio.h>
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/pci.h> 20#include <linux/pci.h>
21#include <linux/completion.h>
21#include <asm/byteorder.h> 22#include <asm/byteorder.h>
22#include <asm/system.h> 23#include <asm/system.h>
23#include <asm/io.h> 24#include <asm/io.h>
@@ -638,7 +639,7 @@ typedef struct ide_drive_s {
638 int crc_count; /* crc counter to reduce drive speed */ 639 int crc_count; /* crc counter to reduce drive speed */
639 struct list_head list; 640 struct list_head list;
640 struct device gendev; 641 struct device gendev;
641 struct semaphore gendev_rel_sem; /* to deal with device release() */ 642 struct completion gendev_rel_comp; /* to deal with device release() */
642} ide_drive_t; 643} ide_drive_t;
643 644
644#define to_ide_device(dev)container_of(dev, ide_drive_t, gendev) 645#define to_ide_device(dev)container_of(dev, ide_drive_t, gendev)
@@ -794,7 +795,7 @@ typedef struct hwif_s {
794 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */ 795 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */
795 796
796 struct device gendev; 797 struct device gendev;
797 struct semaphore gendev_rel_sem; /* To deal with device release() */ 798 struct completion gendev_rel_comp; /* To deal with device release() */
798 799
799 void *hwif_data; /* extra hwif data */ 800 void *hwif_data; /* extra hwif data */
800 801
diff --git a/include/linux/jffs2_fs_i.h b/include/linux/jffs2_fs_i.h
index ef85ab56302b..ad565bf9dcc1 100644
--- a/include/linux/jffs2_fs_i.h
+++ b/include/linux/jffs2_fs_i.h
@@ -8,11 +8,11 @@
8#include <asm/semaphore.h> 8#include <asm/semaphore.h>
9 9
10struct jffs2_inode_info { 10struct jffs2_inode_info {
11 /* We need an internal semaphore similar to inode->i_sem. 11 /* We need an internal mutex similar to inode->i_mutex.
12 Unfortunately, we can't used the existing one, because 12 Unfortunately, we can't used the existing one, because
13 either the GC would deadlock, or we'd have to release it 13 either the GC would deadlock, or we'd have to release it
14 before letting GC proceed. Or we'd have to put ugliness 14 before letting GC proceed. Or we'd have to put ugliness
15 into the GC code so it didn't attempt to obtain the i_sem 15 into the GC code so it didn't attempt to obtain the i_mutex
16 for the inode(s) which are already locked */ 16 for the inode(s) which are already locked */
17 struct semaphore sem; 17 struct semaphore sem;
18 18
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ca7ff8fdd090..d0e6ca3b00ef 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -286,6 +286,15 @@ extern void dump_stack(void);
286 1; \ 286 1; \
287}) 287})
288 288
289/*
290 * Check at compile time that 'function' is a certain type, or is a pointer
291 * to that type (needs to use typedef for the function type.)
292 */
293#define typecheck_fn(type,function) \
294({ typeof(type) __tmp = function; \
295 (void)__tmp; \
296})
297
289#endif /* __KERNEL__ */ 298#endif /* __KERNEL__ */
290 299
291#define SI_LOAD_SHIFT 16 300#define SI_LOAD_SHIFT 16
diff --git a/include/linux/loop.h b/include/linux/loop.h
index 40f63c9879d2..f96506782ebe 100644
--- a/include/linux/loop.h
+++ b/include/linux/loop.h
@@ -58,9 +58,9 @@ struct loop_device {
58 struct bio *lo_bio; 58 struct bio *lo_bio;
59 struct bio *lo_biotail; 59 struct bio *lo_biotail;
60 int lo_state; 60 int lo_state;
61 struct semaphore lo_sem; 61 struct completion lo_done;
62 struct completion lo_bh_done;
62 struct semaphore lo_ctl_mutex; 63 struct semaphore lo_ctl_mutex;
63 struct semaphore lo_bh_mutex;
64 int lo_pending; 64 int lo_pending;
65 65
66 request_queue_t *lo_queue; 66 request_queue_t *lo_queue;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index df80e63903b5..3f1fafc0245e 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -13,6 +13,7 @@
13#include <linux/rbtree.h> 13#include <linux/rbtree.h>
14#include <linux/prio_tree.h> 14#include <linux/prio_tree.h>
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <linux/mutex.h>
16 17
17struct mempolicy; 18struct mempolicy;
18struct anon_vma; 19struct anon_vma;
@@ -1024,6 +1025,9 @@ static inline void vm_stat_account(struct mm_struct *mm,
1024static inline void 1025static inline void
1025kernel_map_pages(struct page *page, int numpages, int enable) 1026kernel_map_pages(struct page *page, int numpages, int enable)
1026{ 1027{
1028 if (!PageHighMem(page) && !enable)
1029 mutex_debug_check_no_locks_freed(page_address(page),
1030 page_address(page + numpages));
1027} 1031}
1028#endif 1032#endif
1029 1033
diff --git a/include/linux/mutex-debug.h b/include/linux/mutex-debug.h
new file mode 100644
index 000000000000..0ccd8f983b50
--- /dev/null
+++ b/include/linux/mutex-debug.h
@@ -0,0 +1,21 @@
1#ifndef __LINUX_MUTEX_DEBUG_H
2#define __LINUX_MUTEX_DEBUG_H
3
4/*
5 * Mutexes - debugging helpers:
6 */
7
8#define __DEBUG_MUTEX_INITIALIZER(lockname) \
9 , .held_list = LIST_HEAD_INIT(lockname.held_list), \
10 .name = #lockname , .magic = &lockname
11
12#define mutex_init(sem) __mutex_init(sem, __FUNCTION__)
13
14extern void FASTCALL(mutex_destroy(struct mutex *lock));
15
16extern void mutex_debug_show_all_locks(void);
17extern void mutex_debug_show_held_locks(struct task_struct *filter);
18extern void mutex_debug_check_no_locks_held(struct task_struct *task);
19extern void mutex_debug_check_no_locks_freed(const void *from, const void *to);
20
21#endif
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
new file mode 100644
index 000000000000..9bce0fee68d4
--- /dev/null
+++ b/include/linux/mutex.h
@@ -0,0 +1,119 @@
1/*
2 * Mutexes: blocking mutual exclusion locks
3 *
4 * started by Ingo Molnar:
5 *
6 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
7 *
8 * This file contains the main data structure and API definitions.
9 */
10#ifndef __LINUX_MUTEX_H
11#define __LINUX_MUTEX_H
12
13#include <linux/list.h>
14#include <linux/spinlock_types.h>
15
16#include <asm/atomic.h>
17
18/*
19 * Simple, straightforward mutexes with strict semantics:
20 *
21 * - only one task can hold the mutex at a time
22 * - only the owner can unlock the mutex
23 * - multiple unlocks are not permitted
24 * - recursive locking is not permitted
25 * - a mutex object must be initialized via the API
26 * - a mutex object must not be initialized via memset or copying
27 * - task may not exit with mutex held
28 * - memory areas where held locks reside must not be freed
29 * - held mutexes must not be reinitialized
30 * - mutexes may not be used in irq contexts
31 *
32 * These semantics are fully enforced when DEBUG_MUTEXES is
33 * enabled. Furthermore, besides enforcing the above rules, the mutex
34 * debugging code also implements a number of additional features
35 * that make lock debugging easier and faster:
36 *
37 * - uses symbolic names of mutexes, whenever they are printed in debug output
38 * - point-of-acquire tracking, symbolic lookup of function names
39 * - list of all locks held in the system, printout of them
40 * - owner tracking
41 * - detects self-recursing locks and prints out all relevant info
42 * - detects multi-task circular deadlocks and prints out all affected
43 * locks and tasks (and only those tasks)
44 */
45struct mutex {
46 /* 1: unlocked, 0: locked, negative: locked, possible waiters */
47 atomic_t count;
48 spinlock_t wait_lock;
49 struct list_head wait_list;
50#ifdef CONFIG_DEBUG_MUTEXES
51 struct thread_info *owner;
52 struct list_head held_list;
53 unsigned long acquire_ip;
54 const char *name;
55 void *magic;
56#endif
57};
58
59/*
60 * This is the control structure for tasks blocked on mutex,
61 * which resides on the blocked task's kernel stack:
62 */
63struct mutex_waiter {
64 struct list_head list;
65 struct task_struct *task;
66#ifdef CONFIG_DEBUG_MUTEXES
67 struct mutex *lock;
68 void *magic;
69#endif
70};
71
72#ifdef CONFIG_DEBUG_MUTEXES
73# include <linux/mutex-debug.h>
74#else
75# define __DEBUG_MUTEX_INITIALIZER(lockname)
76# define mutex_init(mutex) __mutex_init(mutex, NULL)
77# define mutex_destroy(mutex) do { } while (0)
78# define mutex_debug_show_all_locks() do { } while (0)
79# define mutex_debug_show_held_locks(p) do { } while (0)
80# define mutex_debug_check_no_locks_held(task) do { } while (0)
81# define mutex_debug_check_no_locks_freed(from, to) do { } while (0)
82#endif
83
84#define __MUTEX_INITIALIZER(lockname) \
85 { .count = ATOMIC_INIT(1) \
86 , .wait_lock = SPIN_LOCK_UNLOCKED \
87 , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
88 __DEBUG_MUTEX_INITIALIZER(lockname) }
89
90#define DEFINE_MUTEX(mutexname) \
91 struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
92
93extern void fastcall __mutex_init(struct mutex *lock, const char *name);
94
95/***
96 * mutex_is_locked - is the mutex locked
97 * @lock: the mutex to be queried
98 *
99 * Returns 1 if the mutex is locked, 0 if unlocked.
100 */
101static inline int fastcall mutex_is_locked(struct mutex *lock)
102{
103 return atomic_read(&lock->count) != 1;
104}
105
106/*
107 * See kernel/mutex.c for detailed documentation of these APIs.
108 * Also see Documentation/mutex-design.txt.
109 */
110extern void fastcall mutex_lock(struct mutex *lock);
111extern int fastcall mutex_lock_interruptible(struct mutex *lock);
112/*
113 * NOTE: mutex_trylock() follows the spin_trylock() convention,
114 * not the down_trylock() convention!
115 */
116extern int fastcall mutex_trylock(struct mutex *lock);
117extern void fastcall mutex_unlock(struct mutex *lock);
118
119#endif
diff --git a/include/linux/nfsd/nfsfh.h b/include/linux/nfsd/nfsfh.h
index bb842ea41033..0798b7781a6e 100644
--- a/include/linux/nfsd/nfsfh.h
+++ b/include/linux/nfsd/nfsfh.h
@@ -294,7 +294,7 @@ fill_post_wcc(struct svc_fh *fhp)
294/* 294/*
295 * Lock a file handle/inode 295 * Lock a file handle/inode
296 * NOTE: both fh_lock and fh_unlock are done "by hand" in 296 * NOTE: both fh_lock and fh_unlock are done "by hand" in
297 * vfs.c:nfsd_rename as it needs to grab 2 i_sem's at once 297 * vfs.c:nfsd_rename as it needs to grab 2 i_mutex's at once
298 * so, any changes here should be reflected there. 298 * so, any changes here should be reflected there.
299 */ 299 */
300static inline void 300static inline void
@@ -317,7 +317,7 @@ fh_lock(struct svc_fh *fhp)
317 } 317 }
318 318
319 inode = dentry->d_inode; 319 inode = dentry->d_inode;
320 down(&inode->i_sem); 320 mutex_lock(&inode->i_mutex);
321 fill_pre_wcc(fhp); 321 fill_pre_wcc(fhp);
322 fhp->fh_locked = 1; 322 fhp->fh_locked = 1;
323} 323}
@@ -333,7 +333,7 @@ fh_unlock(struct svc_fh *fhp)
333 333
334 if (fhp->fh_locked) { 334 if (fhp->fh_locked) {
335 fill_post_wcc(fhp); 335 fill_post_wcc(fhp);
336 up(&fhp->fh_dentry->d_inode->i_sem); 336 mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex);
337 fhp->fh_locked = 0; 337 fhp->fh_locked = 0;
338 } 338 }
339} 339}
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
index 1767073df26f..b12e59c75752 100644
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -37,7 +37,7 @@ struct pipe_inode_info {
37 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */ 37 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
38#define PIPE_SIZE PAGE_SIZE 38#define PIPE_SIZE PAGE_SIZE
39 39
40#define PIPE_SEM(inode) (&(inode).i_sem) 40#define PIPE_MUTEX(inode) (&(inode).i_mutex)
41#define PIPE_WAIT(inode) (&(inode).i_pipe->wait) 41#define PIPE_WAIT(inode) (&(inode).i_pipe->wait)
42#define PIPE_READERS(inode) ((inode).i_pipe->readers) 42#define PIPE_READERS(inode) ((inode).i_pipe->readers)
43#define PIPE_WRITERS(inode) ((inode).i_pipe->writers) 43#define PIPE_WRITERS(inode) ((inode).i_pipe->writers)
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 001ab82df051..e276c5ba2bb7 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -1857,7 +1857,7 @@ void padd_item(char *item, int total_length, int length);
1857#define GET_BLOCK_CREATE 1 /* add anything you need to find block */ 1857#define GET_BLOCK_CREATE 1 /* add anything you need to find block */
1858#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */ 1858#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */
1859#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */ 1859#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */
1860#define GET_BLOCK_NO_ISEM 8 /* i_sem is not held, don't preallocate */ 1860#define GET_BLOCK_NO_IMUX 8 /* i_mutex is not held, don't preallocate */
1861#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */ 1861#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */
1862 1862
1863int restart_transaction(struct reiserfs_transaction_handle *th, 1863int restart_transaction(struct reiserfs_transaction_handle *th,
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 78eb92ae4d94..85b53f87c703 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -817,6 +817,11 @@ struct task_struct {
817/* Protection of proc_dentry: nesting proc_lock, dcache_lock, write_lock_irq(&tasklist_lock); */ 817/* Protection of proc_dentry: nesting proc_lock, dcache_lock, write_lock_irq(&tasklist_lock); */
818 spinlock_t proc_lock; 818 spinlock_t proc_lock;
819 819
820#ifdef CONFIG_DEBUG_MUTEXES
821 /* mutex deadlock detection */
822 struct mutex_waiter *blocked_on;
823#endif
824
820/* journalling filesystem info */ 825/* journalling filesystem info */
821 void *journal_info; 826 void *journal_info;
822 827