diff options
author | Alexander Larsson <alexl@redhat.com> | 2017-02-14 14:36:28 +0100 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-02-14 14:59:28 +0000 |
commit | 4e908f867d3577a418fb54adb356f396a1181259 (patch) | |
tree | 47f237c028dd21a7ca6cc97b7091c72dcfaea050 /src/rofiles-fuse/main.c | |
parent | ba350982e89660ecf0caf1f4422d4266cadedf86 (diff) | |
download | ostree-4e908f867d3577a418fb54adb356f396a1181259.tar.gz |
rofiles-fuse: Support write/read_buf()
These allow us to avoid copying a lot of data around
in userspace. Instead we splice the data directly from
the fd to the destination fd.
Closes: #684
Approved by: cgwalters
Diffstat (limited to 'src/rofiles-fuse/main.c')
-rw-r--r-- | src/rofiles-fuse/main.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/rofiles-fuse/main.c b/src/rofiles-fuse/main.c index ac44a438..3f0832f5 100644 --- a/src/rofiles-fuse/main.c +++ b/src/rofiles-fuse/main.c @@ -345,6 +345,26 @@ callback_create(const char *path, mode_t mode, struct fuse_file_info *finfo) } static int +callback_read_buf (const char *path, struct fuse_bufvec **bufp, + size_t size, off_t offset, struct fuse_file_info *finfo) +{ + struct fuse_bufvec *src; + + src = malloc (sizeof (struct fuse_bufvec)); + if (src == NULL) + return -ENOMEM; + + *src = FUSE_BUFVEC_INIT (size); + + src->buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK; + src->buf[0].fd = finfo->fh; + src->buf[0].pos = offset; + *bufp = src; + + return 0; +} + +static int callback_read (const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *finfo) { @@ -356,6 +376,19 @@ callback_read (const char *path, char *buf, size_t size, off_t offset, } static int +callback_write_buf (const char *path, struct fuse_bufvec *buf, off_t offset, + struct fuse_file_info *finfo) +{ + struct fuse_bufvec dst = FUSE_BUFVEC_INIT (fuse_buf_size (buf)); + + dst.buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK; + dst.buf[0].fd = finfo->fh; + dst.buf[0].pos = offset; + + return fuse_buf_copy (&dst, buf, FUSE_BUF_SPLICE_NONBLOCK); +} + +static int callback_write (const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *finfo) { @@ -454,7 +487,9 @@ struct fuse_operations callback_oper = { .utime = callback_utime, .create = callback_create, .open = callback_open, + .read_buf = callback_read_buf, .read = callback_read, + .write_buf = callback_write_buf, .write = callback_write, .statfs = callback_statfs, .release = callback_release, |