virtiofsd: virtiofsd: add definition of fuse_buf_writev()
RFC PATCH v2 1/2 virtiofsd: virtiofsd: add definition of fuse_buf_writev()
Define fuse_buf_writev() which use pwritev and writev to improve io bandwidth.
--- contrib/virtiofsd/buffer.c | 37 +++++++++++++++++++++++++++++++++++++ contrib/virtiofsd/fuse_common.h | 14 ++++++++++++++ contrib/virtiofsd/seccomp.c | 2 ++ 3 files changed, 53 insertions(+)
contrib/virtiofsd/buffer.c +37 -0
@@ -15,6 +15,7 @@#include <unistd.h> #include <errno.h> #include <assert.h> +#include <stdlib.h> size_t fuse_buf_size (const struct fuse_bufvec *bufv) {
@@ -71,6 +72,42 @@ static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off,return copied; } +ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags) +{ +ssize_t res, i, buf_index, iovcnt; +struct iovec * iov; +int fd = out_buf->buf[0 ].fd; +off_t pos = out_buf->buf[0 ].pos; + +if (in_buf->count >2 ) + iovcnt = in_buf->count -1 ; +else + iovcnt =1 ; + + iov =malloc (iovcnt *sizeof (struct iovec )); +if (!iov) +return -ENOMEM ; + +for (i =0 , buf_index =1 ; i < iovcnt; i++, buf_index++) { + iov[i].iov_base = in_buf->buf[buf_index].mem; + iov[i].iov_len = in_buf->buf[buf_index].size; + } + +if (flags &FUSE_BUF_FD_SEEK ) + res =pwritev (fd, iov, iovcnt, pos); +else + res =writev (fd, iov, iovcnt); + +if (res ==-1 || res ==0 ) + res = -errno; + +free (iov); +return res; +} +static ssize_t fuse_buf_read (const struct fuse_buf *dst,size_t dst_off,const struct fuse_buf *src,size_t src_off,size_t len)
contrib/virtiofsd/fuse_common.h +14 -0
@@ -730,6 +730,20 @@ ssize_t fuse_buf_copy(fuse_req_t req, enum fuse_buf_copy_flags flags);/** +* Write data from one buffer vector to another +* +* @param req The request this copy is part of +* @param out_buf destination buffer vector +* @param in_buf source buffer vector +* @param flags flags controlling the copy +* @return actual number of bytes written or -errno on error +*/ +ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags); + +/** * Memory buffer iterator * */
contrib/virtiofsd/seccomp.c +2 -0
@@ -60,6 +60,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (ppoll),SCMP_SYS (prctl),/* TODO restrict to just PR_SET_NAME? */ SCMP_SYS (preadv), +SCMP_SYS (pwritev),SCMP_SYS (pwrite64),SCMP_SYS (read), SCMP_SYS(readlinkat),
@@ -78,6 +79,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (unlinkat),SCMP_SYS (utimensat),SCMP_SYS (write), + SCMP_SYS(writev), };/* Syscalls used when --syslog is enabled */
Quoted 26 lines · * piaojun ([email protected]) wrote:
Define
fuse_buf_writev()which use pwritev and writev to improve io bandwidth.Signed-off-by Jun Piao <[email protected]>Suggested-by Dr. David Alan Gilbert <[email protected]>--- contrib/virtiofsd/buffer.c | 37 +++++++++++++++++++++++++++++++++++++ contrib/virtiofsd/fuse_common.h | 14 ++++++++++++++ contrib/virtiofsd/seccomp.c | 2 ++ 3 files changed, 53 insertions(+)contrib/virtiofsd/buffer.c +1
-0@@ -15,6 +15,7 @@#include <unistd.h> #include <errno.h> #include <assert.h> +#include <stdlib.h> size_t fuse_buf_size (const struct fuse_bufvec *bufv) {@@ -71,6 +72,42 @@ static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off,return copied; }
contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 83
Quoted 10 lines
contrib/virtiofsd/buffer.c +9
-0+ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags) +{ +ssize_t res, i, buf_index, iovcnt; +struct iovec * iov; +int fd = out_buf->buf[0 ].fd; +off_t pos = out_buf->buf[0 ].pos;
That's again assuming that the 'pos' in subsequent elements of out_buf is sequential; is it?
What about any other flags on in_buf?
contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 90
Quoted 6 lines
contrib/virtiofsd/buffer.c +6
-0+if (in_buf->count >2 ) + iovcnt = in_buf->count -1 ; +else + iovcnt =1 ; + + iov =malloc (iovcnt *sizeof (struct iovec ));
You could use calloc.
Quoted 5 lines
contrib/virtiofsd/buffer.c +5
-0+if (!iov) +return -ENOMEM ; + +for (i =0 , buf_index =1 ; i < iovcnt; i++, buf_index++) { + iov[i].iov_base = in_buf->buf[buf_index].mem;
contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 105
Quoted 10 lines
contrib/virtiofsd/buffer.c +10
-0+ iov[i].iov_len = in_buf->buf[buf_index].size; + } + +if (flags &FUSE_BUF_FD_SEEK ) + res =pwritev (fd, iov, iovcnt, pos); +else + res =writev (fd, iov, iovcnt); + +if (res ==-1 || res ==0 ) + res = -errno;
Does errno get set on a res == 0 ?
Dave
Quoted 46 lines
contrib/virtiofsd/buffer.c +4
-0+free (iov); +return res; +} +static ssize_t fuse_buf_read (const struct fuse_buf *dst,size_t dst_off,const struct fuse_buf *src,size_t src_off,size_t len)contrib/virtiofsd/fuse_common.h +14
-0@@ -730,6 +730,20 @@ ssize_t fuse_buf_copy(fuse_req_t req, enum fuse_buf_copy_flags flags);/** +* Write data from one buffer vector to another +* +* @param req The request this copy is part of +* @param out_buf destination buffer vector +* @param in_buf source buffer vector +* @param flags flags controlling the copy +* @return actual number of bytes written or -errno on error +*/ +ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags); + +/** * Memory buffer iterator * */ contrib/virtiofsd/seccomp.c +1
-0@@ -60,6 +60,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (ppoll),SCMP_SYS (prctl),/* TODO restrict to just PR_SET_NAME? */ SCMP_SYS (preadv), +SCMP_SYS (pwritev),SCMP_SYS (pwrite64),SCMP_SYS (read), SCMP_SYS(readlinkat),
contrib/virtiofsd/seccomp.c static const int syscall_whitelist[] = { · line 85
Quoted 7 lines
contrib/virtiofsd/seccomp.c +1
-0@@ -78,6 +79,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (unlinkat),SCMP_SYS (utimensat),SCMP_SYS (write), + SCMP_SYS(writev), };/* Syscalls used when --syslog is enabled */
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Hi Dave,
Quoted 28 lines · Dr. David Alan Gilbert
Quoted 27 lines · * piaojun ([email protected]) wrote:
Define
fuse_buf_writev()which use pwritev and writev to improve io bandwidth.Signed-off-by Jun Piao <[email protected]>Suggested-by Dr. David Alan Gilbert <[email protected]>--- contrib/virtiofsd/buffer.c | 37 +++++++++++++++++++++++++++++++++++++ contrib/virtiofsd/fuse_common.h | 14 ++++++++++++++ contrib/virtiofsd/seccomp.c | 2 ++ 3 files changed, 53 insertions(+)contrib/virtiofsd/buffer.c +1
-0@@ -15,6 +15,7 @@#include <unistd.h> #include <errno.h> #include <assert.h> +#include <stdlib.h> size_t fuse_buf_size (const struct fuse_bufvec *bufv) {@@ -71,6 +72,42 @@ static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off,return copied; }
Quoted 13 lines
contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 83
Quoted 9 lines
contrib/virtiofsd/buffer.c +9
-0+ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags) +{ +ssize_t res, i, buf_index, iovcnt; +struct iovec * iov; +int fd = out_buf->buf[0 ].fd; +off_t pos = out_buf->buf[0 ].pos;That's again assuming that the 'pos' in subsequent elements of
out_bufis sequential; is it?
What about any other flags onin_buf?
out_buf->buf[0].pos records the offset which the write starts, and I just moved it from lo_write_buf() without changing the logic. Then I will handle all the flags just as the last reply.
Quoted 9 lines
contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 90
Quoted 7 lines
contrib/virtiofsd/buffer.c +6
-0+if (in_buf->count >2 ) + iovcnt = in_buf->count -1 ; +else + iovcnt =1 ; + + iov =malloc (iovcnt *sizeof (struct iovec ));You could use calloc.
Accepted.
Quoted 10 lines
Quoted 10 lines
contrib/virtiofsd/buffer.c +9
-0+if (!iov) +return -ENOMEM ; + +for (i =0 , buf_index =1 ; i < iovcnt; i++, buf_index++) { + iov[i].iov_base = in_buf->buf[buf_index].mem; + iov[i].iov_len = in_buf->buf[buf_index].size; + } + +if (flags &FUSE_BUF_FD_SEEK )
Quoted 8 lines
contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 105
Quoted 6 lines
contrib/virtiofsd/buffer.c +6
-0+ res =pwritev (fd, iov, iovcnt, pos); + else + res =writev (fd, iov, iovcnt); + +if (res ==-1 || res ==0 ) + res = -errno;Does errno get set on a res == 0 ?
No, this should be fixed and I plan returning res when it's 0. Could we just consider this as copied none bytes?
Quoted 60 lines
Dave
Quoted 46 lines
contrib/virtiofsd/buffer.c +4
-0+free (iov); +return res; +} +static ssize_t fuse_buf_read (const struct fuse_buf *dst,size_t dst_off,const struct fuse_buf *src,size_t src_off,size_t len)contrib/virtiofsd/fuse_common.h +14
-0@@ -730,6 +730,20 @@ ssize_t fuse_buf_copy(fuse_req_t req, enum fuse_buf_copy_flags flags);/** +* Write data from one buffer vector to another +* +* @param req The request this copy is part of +* @param out_buf destination buffer vector +* @param in_buf source buffer vector +* @param flags flags controlling the copy +* @return actual number of bytes written or -errno on error +*/ +ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags); + +/** * Memory buffer iterator * */ contrib/virtiofsd/seccomp.c +1
-0@@ -60,6 +60,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (ppoll),SCMP_SYS (prctl),/* TODO restrict to just PR_SET_NAME? */ SCMP_SYS (preadv), +SCMP_SYS (pwritev),SCMP_SYS (pwrite64),SCMP_SYS (read), SCMP_SYS(readlinkat),contrib/virtiofsd/seccomp.c static const int syscall_whitelist[] = { · line 85
Quoted 7 lines
contrib/virtiofsd/seccomp.c +1
-0@@ -78,6 +79,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (unlinkat),SCMP_SYS (utimensat),SCMP_SYS (write), + SCMP_SYS(writev), };/* Syscalls used when --syslog is enabled */ --
Dr. David Alan Gilbert / [email protected] / Manchester, UK .
Hi Dave,
As Stefan's suggestion, I make the patch set in one thread [PATCH v3] which is more convenient for reviewing. Please make comments on the new patch set if you have any question. I'll be very grateful for your advice.
Thanks,
Jun
Quoted 128 lines · Dr. David Alan Gilbert
Quoted 26 lines · * piaojun ([email protected]) wrote:
Define
fuse_buf_writev()which use pwritev and writev to improve io bandwidth.Signed-off-by Jun Piao <[email protected]>Suggested-by Dr. David Alan Gilbert <[email protected]>--- contrib/virtiofsd/buffer.c | 37 +++++++++++++++++++++++++++++++++++++ contrib/virtiofsd/fuse_common.h | 14 ++++++++++++++ contrib/virtiofsd/seccomp.c | 2 ++ 3 files changed, 53 insertions(+)contrib/virtiofsd/buffer.c +1
-0@@ -15,6 +15,7 @@#include <unistd.h> #include <errno.h> #include <assert.h> +#include <stdlib.h> size_t fuse_buf_size (const struct fuse_bufvec *bufv) {@@ -71,6 +72,42 @@ static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off,return copied; }contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 83
Quoted 10 lines
contrib/virtiofsd/buffer.c +9
-0+ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags) +{ +ssize_t res, i, buf_index, iovcnt; +struct iovec * iov; +int fd = out_buf->buf[0 ].fd; +off_t pos = out_buf->buf[0 ].pos;That's again assuming that the 'pos' in subsequent elements of
out_bufis sequential; is it?
What about any other flags onin_buf?contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 90
Quoted 6 lines
contrib/virtiofsd/buffer.c +6
-0+if (in_buf->count >2 ) + iovcnt = in_buf->count -1 ; +else + iovcnt =1 ; + + iov =malloc (iovcnt *sizeof (struct iovec ));You could use calloc.
Quoted 5 lines
contrib/virtiofsd/buffer.c +5
-0+if (!iov) +return -ENOMEM ; + +for (i =0 , buf_index =1 ; i < iovcnt; i++, buf_index++) { + iov[i].iov_base = in_buf->buf[buf_index].mem;contrib/virtiofsd/buffer.c static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off, · line 105
Quoted 10 lines
contrib/virtiofsd/buffer.c +10
-0+ iov[i].iov_len = in_buf->buf[buf_index].size; + } + +if (flags &FUSE_BUF_FD_SEEK ) + res =pwritev (fd, iov, iovcnt, pos); +else + res =writev (fd, iov, iovcnt); + +if (res ==-1 || res ==0 ) + res = -errno;Does errno get set on a res == 0 ?
Dave
Quoted 46 lines
contrib/virtiofsd/buffer.c +4
-0+free (iov); +return res; +} +static ssize_t fuse_buf_read (const struct fuse_buf *dst,size_t dst_off,const struct fuse_buf *src,size_t src_off,size_t len)contrib/virtiofsd/fuse_common.h +14
-0@@ -730,6 +730,20 @@ ssize_t fuse_buf_copy(fuse_req_t req, enum fuse_buf_copy_flags flags);/** +* Write data from one buffer vector to another +* +* @param req The request this copy is part of +* @param out_buf destination buffer vector +* @param in_buf source buffer vector +* @param flags flags controlling the copy +* @return actual number of bytes written or -errno on error +*/ +ssize_t fuse_buf_writev (fuse_req_t req, +struct fuse_bufvec *out_buf, +struct fuse_bufvec *in_buf, +enum fuse_buf_copy_flags flags); + +/** * Memory buffer iterator * */ contrib/virtiofsd/seccomp.c +1
-0@@ -60,6 +60,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (ppoll),SCMP_SYS (prctl),/* TODO restrict to just PR_SET_NAME? */ SCMP_SYS (preadv), +SCMP_SYS (pwritev),SCMP_SYS (pwrite64),SCMP_SYS (read), SCMP_SYS(readlinkat),contrib/virtiofsd/seccomp.c static const int syscall_whitelist[] = { · line 85
Quoted 7 lines
contrib/virtiofsd/seccomp.c +1
-0@@ -78,6 +79,7 @@ static const int syscall_whitelist[] = {SCMP_SYS (unlinkat),SCMP_SYS (utimensat),SCMP_SYS (write), + SCMP_SYS(writev), };/* Syscalls used when --syslog is enabled */ --
Dr. David Alan Gilbert / [email protected] / Manchester, UK .