aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-03-21 12:24:01 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-04-09 14:13:01 -0400
commitebec73f4752b777b79b384bd52e5240203cb9b00 (patch)
tree20507f68fdc45c18c8f7a975aef2f6479194251c
parentde32ec4cfeb3b3afd2abf5116068deace10e420f (diff)
introduce variants of pipe_lock/pipe_unlock for real pipes/FIFOs
fs/pipe.c file_operations methods *know* that pipe is not an internal one; no need to check pipe->inode for those callers. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/pipe.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/fs/pipe.c b/fs/pipe.c
index 161b2099a7af..e2fc5ccb0d49 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -75,6 +75,16 @@ void pipe_unlock(struct pipe_inode_info *pipe)
75} 75}
76EXPORT_SYMBOL(pipe_unlock); 76EXPORT_SYMBOL(pipe_unlock);
77 77
78static inline void __pipe_lock(struct pipe_inode_info *pipe)
79{
80 mutex_lock_nested(&pipe->mutex, I_MUTEX_PARENT);
81}
82
83static inline void __pipe_unlock(struct pipe_inode_info *pipe)
84{
85 mutex_unlock(&pipe->mutex);
86}
87
78void pipe_double_lock(struct pipe_inode_info *pipe1, 88void pipe_double_lock(struct pipe_inode_info *pipe1,
79 struct pipe_inode_info *pipe2) 89 struct pipe_inode_info *pipe2)
80{ 90{
@@ -376,7 +386,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
376 386
377 do_wakeup = 0; 387 do_wakeup = 0;
378 ret = 0; 388 ret = 0;
379 pipe_lock(pipe); 389 __pipe_lock(pipe);
380 for (;;) { 390 for (;;) {
381 int bufs = pipe->nrbufs; 391 int bufs = pipe->nrbufs;
382 if (bufs) { 392 if (bufs) {
@@ -464,7 +474,7 @@ redo:
464 } 474 }
465 pipe_wait(pipe); 475 pipe_wait(pipe);
466 } 476 }
467 pipe_unlock(pipe); 477 __pipe_unlock(pipe);
468 478
469 /* Signal writers asynchronously that there is more room. */ 479 /* Signal writers asynchronously that there is more room. */
470 if (do_wakeup) { 480 if (do_wakeup) {
@@ -500,7 +510,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
500 510
501 do_wakeup = 0; 511 do_wakeup = 0;
502 ret = 0; 512 ret = 0;
503 pipe_lock(pipe); 513 __pipe_lock(pipe);
504 514
505 if (!pipe->readers) { 515 if (!pipe->readers) {
506 send_sig(SIGPIPE, current, 0); 516 send_sig(SIGPIPE, current, 0);
@@ -647,7 +657,7 @@ redo2:
647 pipe->waiting_writers--; 657 pipe->waiting_writers--;
648 } 658 }
649out: 659out:
650 pipe_unlock(pipe); 660 __pipe_unlock(pipe);
651 if (do_wakeup) { 661 if (do_wakeup) {
652 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM); 662 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
653 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); 663 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
@@ -667,7 +677,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
667 677
668 switch (cmd) { 678 switch (cmd) {
669 case FIONREAD: 679 case FIONREAD:
670 pipe_lock(pipe); 680 __pipe_lock(pipe);
671 count = 0; 681 count = 0;
672 buf = pipe->curbuf; 682 buf = pipe->curbuf;
673 nrbufs = pipe->nrbufs; 683 nrbufs = pipe->nrbufs;
@@ -675,7 +685,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
675 count += pipe->bufs[buf].len; 685 count += pipe->bufs[buf].len;
676 buf = (buf+1) & (pipe->buffers - 1); 686 buf = (buf+1) & (pipe->buffers - 1);
677 } 687 }
678 pipe_unlock(pipe); 688 __pipe_unlock(pipe);
679 689
680 return put_user(count, (int __user *)arg); 690 return put_user(count, (int __user *)arg);
681 default: 691 default:
@@ -721,7 +731,7 @@ pipe_release(struct inode *inode, struct file *file)
721 struct pipe_inode_info *pipe = inode->i_pipe; 731 struct pipe_inode_info *pipe = inode->i_pipe;
722 int kill = 0; 732 int kill = 0;
723 733
724 pipe_lock(pipe); 734 __pipe_lock(pipe);
725 if (file->f_mode & FMODE_READ) 735 if (file->f_mode & FMODE_READ)
726 pipe->readers--; 736 pipe->readers--;
727 if (file->f_mode & FMODE_WRITE) 737 if (file->f_mode & FMODE_WRITE)
@@ -738,7 +748,7 @@ pipe_release(struct inode *inode, struct file *file)
738 kill = 1; 748 kill = 1;
739 } 749 }
740 spin_unlock(&inode->i_lock); 750 spin_unlock(&inode->i_lock);
741 pipe_unlock(pipe); 751 __pipe_unlock(pipe);
742 752
743 if (kill) 753 if (kill)
744 __free_pipe_info(pipe); 754 __free_pipe_info(pipe);
@@ -752,7 +762,7 @@ pipe_fasync(int fd, struct file *filp, int on)
752 struct pipe_inode_info *pipe = filp->private_data; 762 struct pipe_inode_info *pipe = filp->private_data;
753 int retval = 0; 763 int retval = 0;
754 764
755 pipe_lock(pipe); 765 __pipe_lock(pipe);
756 if (filp->f_mode & FMODE_READ) 766 if (filp->f_mode & FMODE_READ)
757 retval = fasync_helper(fd, filp, on, &pipe->fasync_readers); 767 retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
758 if ((filp->f_mode & FMODE_WRITE) && retval >= 0) { 768 if ((filp->f_mode & FMODE_WRITE) && retval >= 0) {
@@ -761,7 +771,7 @@ pipe_fasync(int fd, struct file *filp, int on)
761 /* this can happen only if on == T */ 771 /* this can happen only if on == T */
762 fasync_helper(-1, filp, 0, &pipe->fasync_readers); 772 fasync_helper(-1, filp, 0, &pipe->fasync_readers);
763 } 773 }
764 pipe_unlock(pipe); 774 __pipe_unlock(pipe);
765 return retval; 775 return retval;
766} 776}
767 777
@@ -1040,7 +1050,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
1040 filp->private_data = pipe; 1050 filp->private_data = pipe;
1041 /* OK, we have a pipe and it's pinned down */ 1051 /* OK, we have a pipe and it's pinned down */
1042 1052
1043 pipe_lock(pipe); 1053 __pipe_lock(pipe);
1044 1054
1045 /* We can only do regular read/write on fifos */ 1055 /* We can only do regular read/write on fifos */
1046 filp->f_mode &= (FMODE_READ | FMODE_WRITE); 1056 filp->f_mode &= (FMODE_READ | FMODE_WRITE);
@@ -1110,7 +1120,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
1110 } 1120 }
1111 1121
1112 /* Ok! */ 1122 /* Ok! */
1113 pipe_unlock(pipe); 1123 __pipe_unlock(pipe);
1114 return 0; 1124 return 0;
1115 1125
1116err_rd: 1126err_rd:
@@ -1132,7 +1142,7 @@ err:
1132 kill = 1; 1142 kill = 1;
1133 } 1143 }
1134 spin_unlock(&inode->i_lock); 1144 spin_unlock(&inode->i_lock);
1135 pipe_unlock(pipe); 1145 __pipe_unlock(pipe);
1136 if (kill) 1146 if (kill)
1137 __free_pipe_info(pipe); 1147 __free_pipe_info(pipe);
1138 return ret; 1148 return ret;
@@ -1248,7 +1258,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1248 if (!pipe) 1258 if (!pipe)
1249 return -EBADF; 1259 return -EBADF;
1250 1260
1251 pipe_lock(pipe); 1261 __pipe_lock(pipe);
1252 1262
1253 switch (cmd) { 1263 switch (cmd) {
1254 case F_SETPIPE_SZ: { 1264 case F_SETPIPE_SZ: {
@@ -1277,7 +1287,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1277 } 1287 }
1278 1288
1279out: 1289out:
1280 pipe_unlock(pipe); 1290 __pipe_unlock(pipe);
1281 return ret; 1291 return ret;
1282} 1292}
1283 1293