Skip to content

Commit 84759c6

Browse files
author
Kent Overstreet
committed
Revert "rw_semaphore: remove up/down_read_non_owner"
This reverts commit 11b80f4. Bcache needs rw semaphores for cache coherency in writeback mode - writes have to take a read lock on a per cache device rw sem, and release it when the bio completes. But since this is for bios it's naturally not in the context of the process that originally took the lock. Signed-off-by: Kent Overstreet <[email protected]> CC: Christoph Hellwig <[email protected]> CC: David Howells <[email protected]>
1 parent a937536 commit 84759c6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/linux/rwsem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,20 @@ do { \
133133
_down_write_nest_lock(sem, &(nest_lock)->dep_map); \
134134
} while (0);
135135

136+
/*
137+
* Take/release a lock when not the owner will release it.
138+
*
139+
* [ This API should be avoided as much as possible - the
140+
* proper abstraction for this case is completions. ]
141+
*/
142+
extern void down_read_non_owner(struct rw_semaphore *sem);
143+
extern void up_read_non_owner(struct rw_semaphore *sem);
136144
#else
137145
# define down_read_nested(sem, subclass) down_read(sem)
138146
# define down_write_nest_lock(sem, nest_lock) down_write(sem)
139147
# define down_write_nested(sem, subclass) down_write(sem)
148+
# define down_read_non_owner(sem) down_read(sem)
149+
# define up_read_non_owner(sem) up_read(sem)
140150
#endif
141151

142152
#endif /* _LINUX_RWSEM_H */

kernel/rwsem.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest)
126126

127127
EXPORT_SYMBOL(_down_write_nest_lock);
128128

129+
void down_read_non_owner(struct rw_semaphore *sem)
130+
{
131+
might_sleep();
132+
133+
__down_read(sem);
134+
}
135+
136+
EXPORT_SYMBOL(down_read_non_owner);
137+
129138
void down_write_nested(struct rw_semaphore *sem, int subclass)
130139
{
131140
might_sleep();
@@ -136,6 +145,13 @@ void down_write_nested(struct rw_semaphore *sem, int subclass)
136145

137146
EXPORT_SYMBOL(down_write_nested);
138147

148+
void up_read_non_owner(struct rw_semaphore *sem)
149+
{
150+
__up_read(sem);
151+
}
152+
153+
EXPORT_SYMBOL(up_read_non_owner);
154+
139155
#endif
140156

141157

0 commit comments

Comments
 (0)