Commit bcd78e49 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

tmpfs: support aio

We have a request for tmpfs to support the AIO interface: easily done, no
more than replacing the old shmem_file_read by shmem_file_aio_read,
cribbed from generic_file_aio_read.  (In 2.6.25 its write side was already
changed to use generic_file_aio_write.)

Incorporate cleanups from Andrew Morton and Harvey Harrison.

Tests out fine with LTP's ltp-aiodio.sh, given hacks (not included) to
support O_DIRECT.  tmpfs cannot honestly support O_DIRECT: its
cache-avoiding-IO nature is at odds with direct IO-avoiding-cache.
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Tested-by: default avatarLawrence Greenfield <leg@google.com>
Cc: Christoph Rohland <hans-christoph.rohland@sap.com>
Cc: Badari Pulavarty <pbadari@us.ibm.com>
Cc: Zach Brown <zach.brown@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 11fa977e
...@@ -1690,26 +1690,38 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_ ...@@ -1690,26 +1690,38 @@ static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_
file_accessed(filp); file_accessed(filp);
} }
static ssize_t shmem_file_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) static ssize_t shmem_file_aio_read(struct kiocb *iocb,
const struct iovec *iov, unsigned long nr_segs, loff_t pos)
{ {
read_descriptor_t desc; struct file *filp = iocb->ki_filp;
ssize_t retval;
unsigned long seg;
size_t count;
loff_t *ppos = &iocb->ki_pos;
if ((ssize_t) count < 0) retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE);
return -EINVAL; if (retval)
if (!access_ok(VERIFY_WRITE, buf, count)) return retval;
return -EFAULT;
if (!count) for (seg = 0; seg < nr_segs; seg++) {
return 0; read_descriptor_t desc;
desc.written = 0; desc.written = 0;
desc.count = count; desc.arg.buf = iov[seg].iov_base;
desc.arg.buf = buf; desc.count = iov[seg].iov_len;
if (desc.count == 0)
continue;
desc.error = 0; desc.error = 0;
do_shmem_file_read(filp, ppos, &desc, file_read_actor); do_shmem_file_read(filp, ppos, &desc, file_read_actor);
if (desc.written) retval += desc.written;
return desc.written; if (desc.error) {
return desc.error; retval = retval ?: desc.error;
break;
}
if (desc.count > 0)
break;
}
return retval;
} }
static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf) static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
...@@ -2369,8 +2381,9 @@ static const struct file_operations shmem_file_operations = { ...@@ -2369,8 +2381,9 @@ static const struct file_operations shmem_file_operations = {
.mmap = shmem_mmap, .mmap = shmem_mmap,
#ifdef CONFIG_TMPFS #ifdef CONFIG_TMPFS
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read = shmem_file_read, .read = do_sync_read,
.write = do_sync_write, .write = do_sync_write,
.aio_read = shmem_file_aio_read,
.aio_write = generic_file_aio_write, .aio_write = generic_file_aio_write,
.fsync = simple_sync_file, .fsync = simple_sync_file,
.splice_read = generic_file_splice_read, .splice_read = generic_file_splice_read,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment