diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2013-03-21 02:16:30 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-04-09 14:12:59 -0400 |
commit | 18c03cfd403b88852f75f200206983ee6df28423 (patch) | |
tree | 97ed126248046cbd3ec0c17f7cac3a8a0071704d /fs | |
parent | fc7478a2bfa9abd19657d2bbc9ae24185a41e21b (diff) |
pipe: preparation to new locking rules
* use the fact that file_inode(file)->i_pipe doesn't change
while the file is opened - no locks needed to access that.
* switch to pipe_lock/pipe_unlock where it's easy to do
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/pipe.c | 38 |
1 files changed, 15 insertions, 23 deletions
@@ -363,8 +363,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov, | |||
363 | unsigned long nr_segs, loff_t pos) | 363 | unsigned long nr_segs, loff_t pos) |
364 | { | 364 | { |
365 | struct file *filp = iocb->ki_filp; | 365 | struct file *filp = iocb->ki_filp; |
366 | struct inode *inode = file_inode(filp); | 366 | struct pipe_inode_info *pipe = file_inode(filp)->i_pipe; |
367 | struct pipe_inode_info *pipe; | ||
368 | int do_wakeup; | 367 | int do_wakeup; |
369 | ssize_t ret; | 368 | ssize_t ret; |
370 | struct iovec *iov = (struct iovec *)_iov; | 369 | struct iovec *iov = (struct iovec *)_iov; |
@@ -377,8 +376,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov, | |||
377 | 376 | ||
378 | do_wakeup = 0; | 377 | do_wakeup = 0; |
379 | ret = 0; | 378 | ret = 0; |
380 | mutex_lock(&inode->i_mutex); | 379 | pipe_lock(pipe); |
381 | pipe = inode->i_pipe; | ||
382 | for (;;) { | 380 | for (;;) { |
383 | int bufs = pipe->nrbufs; | 381 | int bufs = pipe->nrbufs; |
384 | if (bufs) { | 382 | if (bufs) { |
@@ -466,7 +464,7 @@ redo: | |||
466 | } | 464 | } |
467 | pipe_wait(pipe); | 465 | pipe_wait(pipe); |
468 | } | 466 | } |
469 | mutex_unlock(&inode->i_mutex); | 467 | pipe_unlock(pipe); |
470 | 468 | ||
471 | /* Signal writers asynchronously that there is more room. */ | 469 | /* Signal writers asynchronously that there is more room. */ |
472 | if (do_wakeup) { | 470 | if (do_wakeup) { |
@@ -488,8 +486,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov, | |||
488 | unsigned long nr_segs, loff_t ppos) | 486 | unsigned long nr_segs, loff_t ppos) |
489 | { | 487 | { |
490 | struct file *filp = iocb->ki_filp; | 488 | struct file *filp = iocb->ki_filp; |
491 | struct inode *inode = file_inode(filp); | 489 | struct pipe_inode_info *pipe = file_inode(filp)->i_pipe; |
492 | struct pipe_inode_info *pipe; | ||
493 | ssize_t ret; | 490 | ssize_t ret; |
494 | int do_wakeup; | 491 | int do_wakeup; |
495 | struct iovec *iov = (struct iovec *)_iov; | 492 | struct iovec *iov = (struct iovec *)_iov; |
@@ -503,8 +500,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov, | |||
503 | 500 | ||
504 | do_wakeup = 0; | 501 | do_wakeup = 0; |
505 | ret = 0; | 502 | ret = 0; |
506 | mutex_lock(&inode->i_mutex); | 503 | pipe_lock(pipe); |
507 | pipe = inode->i_pipe; | ||
508 | 504 | ||
509 | if (!pipe->readers) { | 505 | if (!pipe->readers) { |
510 | send_sig(SIGPIPE, current, 0); | 506 | send_sig(SIGPIPE, current, 0); |
@@ -651,7 +647,7 @@ redo2: | |||
651 | pipe->waiting_writers--; | 647 | pipe->waiting_writers--; |
652 | } | 648 | } |
653 | out: | 649 | out: |
654 | mutex_unlock(&inode->i_mutex); | 650 | pipe_unlock(pipe); |
655 | if (do_wakeup) { | 651 | if (do_wakeup) { |
656 | wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM); | 652 | wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM); |
657 | kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); | 653 | kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); |
@@ -666,14 +662,12 @@ out: | |||
666 | 662 | ||
667 | static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 663 | static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
668 | { | 664 | { |
669 | struct inode *inode = file_inode(filp); | 665 | struct pipe_inode_info *pipe = file_inode(filp)->i_pipe; |
670 | struct pipe_inode_info *pipe; | ||
671 | int count, buf, nrbufs; | 666 | int count, buf, nrbufs; |
672 | 667 | ||
673 | switch (cmd) { | 668 | switch (cmd) { |
674 | case FIONREAD: | 669 | case FIONREAD: |
675 | mutex_lock(&inode->i_mutex); | 670 | pipe_lock(pipe); |
676 | pipe = inode->i_pipe; | ||
677 | count = 0; | 671 | count = 0; |
678 | buf = pipe->curbuf; | 672 | buf = pipe->curbuf; |
679 | nrbufs = pipe->nrbufs; | 673 | nrbufs = pipe->nrbufs; |
@@ -681,7 +675,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
681 | count += pipe->bufs[buf].len; | 675 | count += pipe->bufs[buf].len; |
682 | buf = (buf+1) & (pipe->buffers - 1); | 676 | buf = (buf+1) & (pipe->buffers - 1); |
683 | } | 677 | } |
684 | mutex_unlock(&inode->i_mutex); | 678 | pipe_unlock(pipe); |
685 | 679 | ||
686 | return put_user(count, (int __user *)arg); | 680 | return put_user(count, (int __user *)arg); |
687 | default: | 681 | default: |
@@ -694,8 +688,7 @@ static unsigned int | |||
694 | pipe_poll(struct file *filp, poll_table *wait) | 688 | pipe_poll(struct file *filp, poll_table *wait) |
695 | { | 689 | { |
696 | unsigned int mask; | 690 | unsigned int mask; |
697 | struct inode *inode = file_inode(filp); | 691 | struct pipe_inode_info *pipe = file_inode(filp)->i_pipe; |
698 | struct pipe_inode_info *pipe = inode->i_pipe; | ||
699 | int nrbufs; | 692 | int nrbufs; |
700 | 693 | ||
701 | poll_wait(filp, &pipe->wait, wait); | 694 | poll_wait(filp, &pipe->wait, wait); |
@@ -749,11 +742,10 @@ pipe_release(struct inode *inode, struct file *file) | |||
749 | static int | 742 | static int |
750 | pipe_fasync(int fd, struct file *filp, int on) | 743 | pipe_fasync(int fd, struct file *filp, int on) |
751 | { | 744 | { |
752 | struct inode *inode = file_inode(filp); | 745 | struct pipe_inode_info *pipe = file_inode(filp)->i_pipe; |
753 | struct pipe_inode_info *pipe = inode->i_pipe; | ||
754 | int retval = 0; | 746 | int retval = 0; |
755 | 747 | ||
756 | mutex_lock(&inode->i_mutex); | 748 | pipe_lock(pipe); |
757 | if (filp->f_mode & FMODE_READ) | 749 | if (filp->f_mode & FMODE_READ) |
758 | retval = fasync_helper(fd, filp, on, &pipe->fasync_readers); | 750 | retval = fasync_helper(fd, filp, on, &pipe->fasync_readers); |
759 | if ((filp->f_mode & FMODE_WRITE) && retval >= 0) { | 751 | if ((filp->f_mode & FMODE_WRITE) && retval >= 0) { |
@@ -762,7 +754,7 @@ pipe_fasync(int fd, struct file *filp, int on) | |||
762 | /* this can happen only if on == T */ | 754 | /* this can happen only if on == T */ |
763 | fasync_helper(-1, filp, 0, &pipe->fasync_readers); | 755 | fasync_helper(-1, filp, 0, &pipe->fasync_readers); |
764 | } | 756 | } |
765 | mutex_unlock(&inode->i_mutex); | 757 | pipe_unlock(pipe); |
766 | return retval; | 758 | return retval; |
767 | } | 759 | } |
768 | 760 | ||
@@ -1224,7 +1216,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1224 | if (!pipe) | 1216 | if (!pipe) |
1225 | return -EBADF; | 1217 | return -EBADF; |
1226 | 1218 | ||
1227 | mutex_lock(&pipe->inode->i_mutex); | 1219 | pipe_lock(pipe); |
1228 | 1220 | ||
1229 | switch (cmd) { | 1221 | switch (cmd) { |
1230 | case F_SETPIPE_SZ: { | 1222 | case F_SETPIPE_SZ: { |
@@ -1253,7 +1245,7 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1253 | } | 1245 | } |
1254 | 1246 | ||
1255 | out: | 1247 | out: |
1256 | mutex_unlock(&pipe->inode->i_mutex); | 1248 | pipe_unlock(pipe); |
1257 | return ret; | 1249 | return ret; |
1258 | } | 1250 | } |
1259 | 1251 | ||