From: Badari Pulavarty <pbadari@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
Hugh Dickins <hugh@veritas.com>, Tejun Heo <tj@kernel.org>,
Alexey Dobriyan <adobriyan@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Greg Kroah-Hartman <gregkh@suse.de>,
Nick Piggin <npiggin@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Hellwig <hch@infradead.org>,
"Eric W. Biederman" <ebiederm@maxwell.arastra.com>,
"Eric W. Biederman" <ebiederm@aristanetworks.com>
Subject: Re: [PATCH 07/23] vfs: Teach sendfile,splice,tee,and vmsplice to use file_hotplug_lock
Date: Wed, 03 Jun 2009 16:39:23 -0700 [thread overview]
Message-ID: <1244072363.6383.15.camel@badari-desktop> (raw)
In-Reply-To: <1243893048-17031-7-git-send-email-ebiederm@xmission.com>
On Mon, 2009-06-01 at 14:50 -0700, Eric W. Biederman wrote:
> From: Eric W. Biederman <ebiederm@maxwell.arastra.com>
>
> Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
> ---
> fs/read_write.c | 28 +++++++++----
> fs/splice.c | 111 +++++++++++++++++++++++++++++++++++++-----------------
> 2 files changed, 95 insertions(+), 44 deletions(-)
>
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 718baea..c473d74 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -861,21 +861,24 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
> goto out;
> if (!(in_file->f_mode & FMODE_READ))
> goto fput_in;
> + retval = -EIO;
> + if (!file_hotplug_read_trylock(in_file))
> + goto fput_in;
> retval = -EINVAL;
> in_inode = in_file->f_path.dentry->d_inode;
> if (!in_inode)
> - goto fput_in;
> + goto unlock_in;
> if (!in_file->f_op || !in_file->f_op->splice_read)
> - goto fput_in;
> + goto unlock_in;
> retval = -ESPIPE;
> if (!ppos)
> ppos = &in_file->f_pos;
> else
> if (!(in_file->f_mode & FMODE_PREAD))
> - goto fput_in;
> + goto unlock_in;
> retval = rw_verify_area(READ, in_file, ppos, count);
> if (retval < 0)
> - goto fput_in;
> + goto unlock_in;
> count = retval;
>
> /*
> @@ -884,16 +887,19 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
> retval = -EBADF;
> out_file = fget_light(out_fd, &fput_needed_out);
> if (!out_file)
> - goto fput_in;
> + goto unlock_in;
> if (!(out_file->f_mode & FMODE_WRITE))
> goto fput_out;
> + retval = -EIO;
> + if (!file_hotplug_read_trylock(out_file))
> + goto fput_out;
> retval = -EINVAL;
> if (!out_file->f_op || !out_file->f_op->sendpage)
> - goto fput_out;
> + goto unlock_out;
> out_inode = out_file->f_path.dentry->d_inode;
> retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count);
> if (retval < 0)
> - goto fput_out;
> + goto unlock_out;
> count = retval;
>
> if (!max)
> @@ -902,11 +908,11 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
> pos = *ppos;
> retval = -EINVAL;
> if (unlikely(pos < 0))
> - goto fput_out;
> + goto unlock_out;
> if (unlikely(pos + count > max)) {
> retval = -EOVERFLOW;
> if (pos >= max)
> - goto fput_out;
> + goto unlock_out;
> count = max - pos;
> }
>
> @@ -933,8 +939,12 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
> if (*ppos > max)
> retval = -EOVERFLOW;
>
> +unlock_out:
> + file_hotplug_read_unlock(out_file);
> fput_out:
> fput_light(out_file, fput_needed_out);
> +unlock_in:
> + file_hotplug_read_unlock(in_file);
> fput_in:
> fput_light(in_file, fput_needed_in);
> out:
> diff --git a/fs/splice.c b/fs/splice.c
> index 666953d..fc6b3a5 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -1464,15 +1464,21 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, iov,
>
> error = -EBADF;
> file = fget_light(fd, &fput);
> - if (file) {
> - if (file->f_mode & FMODE_WRITE)
> - error = vmsplice_to_pipe(file, iov, nr_segs, flags);
> - else if (file->f_mode & FMODE_READ)
> - error = vmsplice_to_user(file, iov, nr_segs, flags);
> + if (!file)
> + goto out;
>
> - fput_light(file, fput);
> - }
> + if (!file_hotplug_read_trylock(file))
> + goto fput_file;
>
> + if (file->f_mode & FMODE_WRITE)
> + error = vmsplice_to_pipe(file, iov, nr_segs, flags);
> + else if (file->f_mode & FMODE_READ)
> + error = vmsplice_to_user(file, iov, nr_segs, flags);
> +
> + file_hotplug_read_unlock(file);
> +fput_file:
> + fput_light(file, fput);
> +out:
> return error;
> }
>
> @@ -1489,21 +1495,39 @@ SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in,
>
> error = -EBADF;
> in = fget_light(fd_in, &fput_in);
> - if (in) {
> - if (in->f_mode & FMODE_READ) {
> - out = fget_light(fd_out, &fput_out);
> - if (out) {
> - if (out->f_mode & FMODE_WRITE)
> - error = do_splice(in, off_in,
> - out, off_out,
> - len, flags);
> - fput_light(out, fput_out);
> - }
> - }
> + if (!in)
> + goto out;
>
> - fput_light(in, fput_in);
> - }
> + if (!(in->f_mode & FMODE_READ))
> + goto fput_in;
> +
> + error = -EIO;
> + if (!file_hotplug_read_trylock(in))
> + goto fput_in;
> +
> + error = -EBADF;
> + out = fget_light(fd_out, &fput_out);
> + if (!out)
> + goto unlock_in;
> +
> + if (!(out->f_mode & FMODE_WRITE))
> + goto fput_out;
> +
> + error = -EIO;
> + if (!file_hotplug_read_trylock(out))
> + goto fput_out;
> +
> + error = do_splice(in, off_in, out, off_out, len, flags);
>
> + file_hotplug_read_unlock(out);
> +fput_out:
> + fput_light(out, fput_out);
> +unlock_in:
> + file_hotplug_read_unlock(in);
> +fput_in:
> + fput_light(in, fput_in);
> +
> +out:
> return error;
> }
>
> @@ -1703,27 +1727,44 @@ static long do_tee(struct file *in, struct file *out, size_t len,
>
> SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags)
> {
> - struct file *in;
> - int error, fput_in;
> + struct file *in, *out;
> + int error, fput_in, fput_out;
>
> if (unlikely(!len))
> return 0;
>
> error = -EBADF;
> in = fget_light(fdin, &fput_in);
> - if (in) {
> - if (in->f_mode & FMODE_READ) {
> - int fput_out;
> - struct file *out = fget_light(fdout, &fput_out);
> -
> - if (out) {
> - if (out->f_mode & FMODE_WRITE)
> - error = do_tee(in, out, len, flags);
> - fput_light(out, fput_out);
> - }
> - }
> - fput_light(in, fput_in);
> - }
> + if (!in)
> + goto out;
> +
> + if (!(in->f_mode & FMODE_READ))
> + goto unlock_in; <<<<<<<
Shouldn't this be
goto fput_in;
? btw, its confusing to have labels and variables with same name:
fput_in and fput_out. You may want to rename labels ?
>
> + error = -EIO;
> + if (!file_hotplug_read_trylock(in))
> + goto fput_in;
> +
> + error = -EBADF;
> + out = fget_light(fdout, &fput_out);
> + if (!out)
> + goto unlock_in;
> +
> + if (!(out->f_mode & FMODE_WRITE))
> + goto fput_out;
> +
> + if (!file_hotplug_read_trylock(out))
> + goto fput_out;
> +
> + error = do_tee(in, out, len, flags);
> +
> + file_hotplug_read_unlock(out);
> +fput_out:
> + fput_light(out, fput_out);
> +unlock_in:
> + file_hotplug_read_unlock(in);
> +fput_in:
> + fput_light(in, fput_in);
> +out:
> return error;
> }
Thanks,
Badari
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-06-03 23:39 UTC|newest]
Thread overview: 99+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-11 12:01 [RFC][PATCH 0/9] File descriptor hot-unplug support Eric W. Biederman
2009-04-11 12:03 ` [RFC][PATCH 1/9] mm: Introduce remap_file_mappings Eric W. Biederman
2009-04-11 12:05 ` [RFC][PATCH 2/9] mm: Implement generic support for revoking a mapping Eric W. Biederman
2009-04-11 12:06 ` [RFC][PATCH 3/9] sysfs: Use remap_file_mappings Eric W. Biederman
2009-04-11 12:07 ` [RFC][PATCH 4/9] vfs: Generalize the file_list Eric W. Biederman
2009-04-11 12:08 ` [RFC][PATCH 5/9] vfs: Introduce basic infrastructure for revoking a file Eric W. Biederman
2009-04-14 22:12 ` Jonathan Corbet
2009-04-15 2:55 ` Eric W. Biederman
2009-04-11 12:10 ` [RFC][PATCH 6/9] vfs: Utilize fops_read_lock where appropriate Eric W. Biederman
2009-04-11 12:11 ` [RFC][PATCH 7/9] vfs: Optimize fops_read_lock Eric W. Biederman
2009-04-11 12:13 ` [RFC][PATCH 8/9] vfs: Implement generic revoked file operations Eric W. Biederman
2009-04-12 18:56 ` Jamie Lokier
2009-04-12 20:04 ` Eric W. Biederman
2009-04-12 20:31 ` Jamie Lokier
2009-04-12 21:53 ` Eric W. Biederman
2009-04-12 20:54 ` Eric W. Biederman
2009-04-12 21:02 ` Jamie Lokier
2009-04-12 23:06 ` Eric W. Biederman
2009-04-11 12:14 ` [RFC][PATCH 9/9] proc: Use the generic vfs revoke facility that now exists Eric W. Biederman
2009-04-11 15:58 ` [RFC][PATCH 0/9] File descriptor hot-unplug support Al Viro
2009-04-11 16:49 ` Eric W. Biederman
2009-04-11 16:56 ` Al Viro
2009-04-11 23:57 ` Eric W. Biederman
2009-04-12 20:21 ` Eric W. Biederman
2009-04-14 3:16 ` Tejun Heo
2009-04-14 7:39 ` Eric W. Biederman
2009-04-14 7:45 ` Tejun Heo
2009-04-14 8:27 ` Eric W. Biederman
2009-04-14 8:49 ` Tejun Heo
2009-04-14 15:07 ` Jamie Lokier
2009-04-14 19:09 ` Eric W. Biederman
2009-06-01 21:45 ` [PATCH 0/23] File descriptor hot-unplug support v2 Eric W. Biederman
2009-06-01 21:50 ` [PATCH 01/23] mm: Introduce revoke_file_mappings Eric W. Biederman
2009-06-01 22:25 ` Andrew Morton
2009-06-02 0:12 ` Eric W. Biederman
2009-06-01 21:50 ` [PATCH 02/23] vfs: Implement unpoll_file Eric W. Biederman
2009-06-06 8:08 ` Al Viro
2009-06-01 21:50 ` [PATCH 03/23] vfs: Generalize the file_list Eric W. Biederman
2009-06-02 7:06 ` Nick Piggin
2009-06-05 19:33 ` Eric W. Biederman
2009-06-09 10:38 ` Nick Piggin
2009-06-09 18:38 ` Eric W. Biederman
2009-06-10 6:05 ` Nick Piggin
2009-06-01 21:50 ` [PATCH 04/23] vfs: Introduce infrastructure for revoking a file Eric W. Biederman
2009-06-02 5:16 ` Pekka Enberg
2009-06-02 6:51 ` Eric W. Biederman
2009-06-02 7:08 ` Pekka Enberg
2009-06-02 7:14 ` Nick Piggin
2009-06-02 17:06 ` Linus Torvalds
2009-06-02 20:52 ` Eric W. Biederman
2009-06-03 6:37 ` Nick Piggin
2009-06-02 22:56 ` Eric W. Biederman
2009-06-03 6:38 ` Nick Piggin
2009-06-05 9:03 ` Miklos Szeredi
2009-06-05 19:06 ` Eric W. Biederman
2009-06-01 21:50 ` [PATCH 05/23] vfs: Teach lseek to use file_hotplug_lock Eric W. Biederman
2009-06-01 21:50 ` [PATCH 06/23] vfs: Teach read/write to use file_hotplug_read_lock Eric W. Biederman
2009-06-01 21:50 ` [PATCH 07/23] vfs: Teach sendfile,splice,tee,and vmsplice to use file_hotplug_lock Eric W. Biederman
2009-06-03 23:39 ` Badari Pulavarty [this message]
2009-06-05 19:37 ` Eric W. Biederman
2009-06-01 21:50 ` [PATCH 08/23] vfs: Teach readdir " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 09/23] vfs: Teach poll and select " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 10/23] vfs: Teach do_path_lookup " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 11/23] mm: Teach mmap " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 12/23] vfs: Teach fcntl " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 13/23] vfs: Teach ioctl " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 14/23] vfs: Teach flock " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 15/23] vfs: Teach fallocate, and filp_close " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 16/23] vfs: Teach fstatfs, fstatfs64, ftruncate, fchdir, fchmod, fchown " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 17/23] proc: Teach /proc/<pid>/fd " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 18/23] vfs: Teach epoll " Eric W. Biederman
2009-06-02 16:51 ` Davide Libenzi
2009-06-02 21:23 ` Eric W. Biederman
2009-06-02 21:52 ` Davide Libenzi
2009-06-02 22:51 ` Eric W. Biederman
2009-06-03 14:57 ` Davide Libenzi
2009-06-03 20:53 ` Eric W. Biederman
2009-06-04 0:50 ` Davide Libenzi
2009-06-04 1:42 ` Eric W. Biederman
2009-06-01 21:50 ` [PATCH 19/23] eventpoll: Fix comment Eric W. Biederman
2009-06-01 21:50 ` [PATCH 20/23] vfs: Teach aio to use file_hotplug_lock Eric W. Biederman
2009-06-01 21:50 ` [PATCH 21/23] vfs: Teach fsync " Eric W. Biederman
2009-06-01 21:50 ` [PATCH 22/23] vfs: Teach fadvice to file_hotplug_lock Eric W. Biederman
2009-06-01 21:50 ` [PATCH 23/23] vfs: Teach readahead to use the file_hotplug_lock Eric W. Biederman
2009-06-03 23:25 ` Badari Pulavarty
2009-06-06 8:03 ` [PATCH 0/23] File descriptor hot-unplug support v2 Al Viro
2009-06-08 9:41 ` Miklos Szeredi
2009-06-08 10:24 ` Jamie Lokier
2009-06-08 16:29 ` Al Viro
2009-06-08 16:44 ` Miklos Szeredi
2009-06-08 17:50 ` Al Viro
2009-06-08 18:01 ` Linus Torvalds
2009-06-08 18:50 ` Al Viro
2009-06-08 19:18 ` Linus Torvalds
2009-06-09 6:42 ` Eric W. Biederman
2009-06-09 10:52 ` Nick Piggin
2009-06-09 5:50 ` Miklos Szeredi
2009-06-09 6:31 ` Eric W. Biederman
2009-06-09 6:22 ` Eric W. Biederman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1244072363.6383.15.camel@badari-desktop \
--to=pbadari@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=ebiederm@aristanetworks.com \
--cc=ebiederm@maxwell.arastra.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@suse.de \
--cc=hch@infradead.org \
--cc=hugh@veritas.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=npiggin@suse.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).