[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1243893048-17031-6-git-send-email-ebiederm@xmission.com>
Date: Mon, 1 Jun 2009 14:50:31 -0700
From: "Eric W. Biederman" <ebiederm@...ssion.com>
To: Al Viro <viro@...IV.linux.org.uk>
Cc: <linux-kernel@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<linux-mm@...ck.org>, <linux-fsdevel@...r.kernel.org>,
Hugh Dickins <hugh@...itas.com>, Tejun Heo <tj@...nel.org>,
Alexey Dobriyan <adobriyan@...il.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Alan Cox <alan@...rguk.ukuu.org.uk>,
Greg Kroah-Hartman <gregkh@...e.de>,
Nick Piggin <npiggin@...e.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Christoph Hellwig <hch@...radead.org>,
"Eric W. Biederman" <ebiederm@...well.arastra.com>,
"Eric W. Biederman" <ebiederm@...stanetworks.com>
Subject: [PATCH 06/23] vfs: Teach read/write to use file_hotplug_read_lock
From: Eric W. Biederman <ebiederm@...well.arastra.com>
Signed-off-by: Eric W. Biederman <ebiederm@...stanetworks.com>
---
fs/compat.c | 16 +++++++++++-
fs/read_write.c | 70 +++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 72 insertions(+), 14 deletions(-)
diff --git a/fs/compat.c b/fs/compat.c
index 25be41c..dad9957 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1196,12 +1196,18 @@ static size_t compat_readv(struct file *file,
if (!(file->f_mode & FMODE_READ))
goto out;
+ ret = -EIO;
+ if (!file_hotplug_read_trylock(file))
+ goto out;
+
ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
- goto out;
+ goto out_unlock;
ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
+out_unlock:
+ file_hotplug_read_unlock(file);
out:
if (ret > 0)
add_rchar(current, ret);
@@ -1253,12 +1259,18 @@ static size_t compat_writev(struct file *file,
if (!(file->f_mode & FMODE_WRITE))
goto out;
+ ret = -EIO;
+ if (!file_hotplug_read_trylock(file))
+ goto out;
+
ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
- goto out;
+ goto out_unlock;
ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
+out_unlock:
+ file_hotplug_read_unlock(file);
out:
if (ret > 0)
add_wchar(current, ret);
diff --git a/fs/read_write.c b/fs/read_write.c
index c9511ce..718baea 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -288,12 +288,18 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ssize_t ret;
+ ret = -EBADF;
if (!(file->f_mode & FMODE_READ))
- return -EBADF;
+ goto out;
+ ret = -EIO;
+ if (!file_hotplug_read_trylock(file))
+ goto out;
+ ret = -EINVAL;
if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read))
- return -EINVAL;
+ goto out_unlock;
+ ret = -EFAULT;
if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
- return -EFAULT;
+ goto out_unlock;
ret = rw_verify_area(READ, file, pos, count);
if (ret >= 0) {
@@ -309,6 +315,9 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
inc_syscr(current);
}
+out_unlock:
+ file_hotplug_read_unlock(file);
+out:
return ret;
}
@@ -343,12 +352,18 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
{
ssize_t ret;
+ ret = -EBADF;
if (!(file->f_mode & FMODE_WRITE))
- return -EBADF;
+ goto out;
+ ret = -EIO;
+ if (!file_hotplug_read_trylock(file))
+ goto out;
+ ret = -EINVAL;
if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
- return -EINVAL;
+ goto out_unlock;
+ ret = -EFAULT;
if (unlikely(!access_ok(VERIFY_READ, buf, count)))
- return -EFAULT;
+ goto out_unlock;
ret = rw_verify_area(WRITE, file, pos, count);
if (ret >= 0) {
@@ -364,6 +379,9 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
inc_syscw(current);
}
+out_unlock:
+ file_hotplug_read_unlock(file);
+out:
return ret;
}
@@ -676,12 +694,26 @@ out:
ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
unsigned long vlen, loff_t *pos)
{
+ ssize_t ret;
+
+ ret = -EBADF;
if (!(file->f_mode & FMODE_READ))
- return -EBADF;
+ goto out;
+
+ ret = -EIO;
+ if (!file_hotplug_read_trylock(file))
+ goto out;
+
+ ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
- return -EINVAL;
+ goto out_unlock;
+
+ ret = do_readv_writev(READ, file, vec, vlen, pos);
- return do_readv_writev(READ, file, vec, vlen, pos);
+out_unlock:
+ file_hotplug_read_unlock(file);
+out:
+ return ret;
}
EXPORT_SYMBOL(vfs_readv);
@@ -689,12 +721,26 @@ EXPORT_SYMBOL(vfs_readv);
ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
unsigned long vlen, loff_t *pos)
{
+ ssize_t ret;
+
+ ret = -EBADF;
if (!(file->f_mode & FMODE_WRITE))
- return -EBADF;
+ goto out;
+
+ ret = -EIO;
+ if (!file_hotplug_read_trylock(file))
+ goto out;
+
+ ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
- return -EINVAL;
+ goto out_unlock;
- return do_readv_writev(WRITE, file, vec, vlen, pos);
+ ret = do_readv_writev(WRITE, file, vec, vlen, pos);
+
+out_unlock:
+ file_hotplug_read_unlock(file);
+out:
+ return ret;
}
EXPORT_SYMBOL(vfs_writev);
--
1.6.3.1.54.g99dd.dirty
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists