add down_write_killable_nested()
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 26 May 2016 04:04:58 +0000 (00:04 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 26 May 2016 04:04:58 +0000 (00:04 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
include/linux/rwsem.h
kernel/locking/rwsem.c

index d1c12d160ace1491ad097477a03aa6820d304046..d37fbb34d06fed4494b3152300d71aba23663f63 100644 (file)
@@ -156,6 +156,7 @@ extern void downgrade_write(struct rw_semaphore *sem);
  */
 extern void down_read_nested(struct rw_semaphore *sem, int subclass);
 extern void down_write_nested(struct rw_semaphore *sem, int subclass);
+extern int down_write_killable_nested(struct rw_semaphore *sem, int subclass);
 extern void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest_lock);
 
 # define down_write_nest_lock(sem, nest_lock)                  \
@@ -176,6 +177,7 @@ extern void up_read_non_owner(struct rw_semaphore *sem);
 # define down_read_nested(sem, subclass)               down_read(sem)
 # define down_write_nest_lock(sem, nest_lock)  down_write(sem)
 # define down_write_nested(sem, subclass)      down_write(sem)
+# define down_write_killable_nested(sem, subclass)     down_write_killable(sem)
 # define down_read_non_owner(sem)              down_read(sem)
 # define up_read_non_owner(sem)                        up_read(sem)
 #endif
index c817216c161521b92cc64ef90e1da1c54e936839..2e853ad93a3a0f27ac3ce676ebe637ad8e03199e 100644 (file)
@@ -173,6 +173,22 @@ void down_write_nested(struct rw_semaphore *sem, int subclass)
 
 EXPORT_SYMBOL(down_write_nested);
 
+int __sched down_write_killable_nested(struct rw_semaphore *sem, int subclass)
+{
+       might_sleep();
+       rwsem_acquire(&sem->dep_map, subclass, 0, _RET_IP_);
+
+       if (LOCK_CONTENDED_RETURN(sem, __down_write_trylock, __down_write_killable)) {
+               rwsem_release(&sem->dep_map, 1, _RET_IP_);
+               return -EINTR;
+       }
+
+       rwsem_set_owner(sem);
+       return 0;
+}
+
+EXPORT_SYMBOL(down_write_killable_nested);
+
 void up_read_non_owner(struct rw_semaphore *sem)
 {
        __up_read(sem);