On Thursday, December 12, 2019, Dr. David Alan Gilbert (git) <
dgilb...@redhat.com> wrote:

> From: "Dr. David Alan Gilbert" <dgilb...@redhat.com>
>
> Mostly using a set like:
>
> indent -nut -i 4 -nlp -br -cs -ce --no-space-after-function-call-names
> file
> clang-format -style=file -i -- file
> clang-tidy -fix-errors -checks=readability-braces-around-statements file
> clang-format -style=file -i -- file
>
> With manual cleanups.
>
> The .clang-format used is below.
>
> Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com>
>
> Language:        Cpp
> AlignAfterOpenBracket: Align
> AlignConsecutiveAssignments: false # although we like it, it creates churn
> AlignConsecutiveDeclarations: false
> AlignEscapedNewlinesLeft: true
> AlignOperands:   true
> AlignTrailingComments: false # churn
> AllowAllParametersOfDeclarationOnNextLine: true
> AllowShortBlocksOnASingleLine: false
> AllowShortCaseLabelsOnASingleLine: false
> AllowShortFunctionsOnASingleLine: None
> AllowShortIfStatementsOnASingleLine: false
> AllowShortLoopsOnASingleLine: false
> AlwaysBreakAfterReturnType: None # AlwaysBreakAfterDefinitionReturnType
> is taken into account
> AlwaysBreakBeforeMultilineStrings: false
> BinPackArguments: true
> BinPackParameters: true
> BraceWrapping:
>   AfterControlStatement: false
>   AfterEnum:       false
>   AfterFunction:   true
>   AfterStruct:     false
>   AfterUnion:      false
>   BeforeElse:      false
>   IndentBraces:    false
> BreakBeforeBinaryOperators: None
> BreakBeforeBraces: Custom
> BreakBeforeTernaryOperators: false
> BreakStringLiterals: true
> ColumnLimit:     80
> ContinuationIndentWidth: 4
> Cpp11BracedListStyle: false
> DerivePointerAlignment: false
> DisableFormat:   false
> ForEachMacros:   [
>   'CPU_FOREACH',
>   'CPU_FOREACH_REVERSE',
>   'CPU_FOREACH_SAFE',
>   'IOMMU_NOTIFIER_FOREACH',
>   'QLIST_FOREACH',
>   'QLIST_FOREACH_ENTRY',
>   'QLIST_FOREACH_RCU',
>   'QLIST_FOREACH_SAFE',
>   'QLIST_FOREACH_SAFE_RCU',
>   'QSIMPLEQ_FOREACH',
>   'QSIMPLEQ_FOREACH_SAFE',
>   'QSLIST_FOREACH',
>   'QSLIST_FOREACH_SAFE',
>   'QTAILQ_FOREACH',
>   'QTAILQ_FOREACH_REVERSE',
>   'QTAILQ_FOREACH_SAFE',
>   'QTAILQ_RAW_FOREACH',
>   'RAMBLOCK_FOREACH'
> ]
> IncludeCategories:
>   - Regex:           '^"qemu/osdep.h'
>     Priority:        -3
>   - Regex:           '^"(block|chardev|crypto|disas|exec|fpu|hw|io|
> libdecnumber|migration|monitor|net|qapi|qemu|qom|
> standard-headers|sysemu|ui)/'
>     Priority:        -2
>   - Regex:           '^"(elf.h|qemu-common.h|glib-
> compat.h|qemu-io.h|trace-tcg.h)'
>     Priority:        -1
>   - Regex:           '.*'
>     Priority:        1
> IncludeIsMainRegex: '$'
> IndentCaseLabels: false
> IndentWidth:     4
> IndentWrappedFunctionNames: false
> KeepEmptyLinesAtTheStartOfBlocks: false
> MacroBlockBegin: '.*_BEGIN$' # only PREC_BEGIN ?
> MacroBlockEnd:   '.*_END$'
> MaxEmptyLinesToKeep: 2
> PointerAlignment: Right
> ReflowComments:  true
> SortIncludes:    true
> SpaceAfterCStyleCast: false
> SpaceBeforeAssignmentOperators: true
> SpaceBeforeParens: ControlStatements
> SpaceInEmptyParentheses: false
> SpacesBeforeTrailingComments: 1
> SpacesInContainerLiterals: true
> SpacesInParentheses: false
> SpacesInSquareBrackets: false
> Standard:        Auto
> UseTab:          Never
> ...
> ---
>  tools/virtiofsd/buffer.c              |  550 ++--
>  tools/virtiofsd/fuse.h                | 1572 +++++------
>  tools/virtiofsd/fuse_common.h         |  764 ++---
>  tools/virtiofsd/fuse_i.h              |  127 +-
>  tools/virtiofsd/fuse_log.c            |   38 +-
>  tools/virtiofsd/fuse_log.h            |   32 +-
>  tools/virtiofsd/fuse_loop_mt.c        |   66 +-
>  tools/virtiofsd/fuse_lowlevel.c       | 3678 +++++++++++++------------
>  tools/virtiofsd/fuse_lowlevel.h       | 2401 ++++++++--------
>  tools/virtiofsd/fuse_misc.h           |   30 +-
>  tools/virtiofsd/fuse_opt.c            |  659 ++---
>  tools/virtiofsd/fuse_opt.h            |   79 +-
>  tools/virtiofsd/fuse_signals.c        |  118 +-
>  tools/virtiofsd/helper.c              |  517 ++--
>  tools/virtiofsd/passthrough_helpers.h |   33 +-
>  tools/virtiofsd/passthrough_ll.c      | 2063 +++++++-------
>  16 files changed, 6530 insertions(+), 6197 deletions(-)
>
>
Reviewed by: Aleksandar Markovic <amarko...@wavecomp.com>


> diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c
> index 5ab9b87455..38521f5889 100644
> --- a/tools/virtiofsd/buffer.c
> +++ b/tools/virtiofsd/buffer.c
> @@ -1,321 +1,343 @@
>  /*
> -  FUSE: Filesystem in Userspace
> -  Copyright (C) 2010  Miklos Szeredi <mik...@szeredi.hu>
> -
> -  Functions for dealing with `struct fuse_buf` and `struct
> -  fuse_bufvec`.
> -
> -  This program can be distributed under the terms of the GNU LGPLv2.
> -  See the file COPYING.LIB
> -*/
> + * FUSE: Filesystem in Userspace
> + * Copyright (C) 2010  Miklos Szeredi <mik...@szeredi.hu>
> + *
> + * Functions for dealing with `struct fuse_buf` and `struct
> + * fuse_bufvec`.
> + *
> + * This program can be distributed under the terms of the GNU LGPLv2.
> + * See the file COPYING.LIB
> + */
>
>  #define _GNU_SOURCE
>
>  #include "config.h"
>  #include "fuse_i.h"
>  #include "fuse_lowlevel.h"
> +#include <assert.h>
> +#include <errno.h>
>  #include <string.h>
>  #include <unistd.h>
> -#include <errno.h>
> -#include <assert.h>
>
>  size_t fuse_buf_size(const struct fuse_bufvec *bufv)
>  {
> -       size_t i;
> -       size_t size = 0;
> -
> -       for (i = 0; i < bufv->count; i++) {
> -               if (bufv->buf[i].size == SIZE_MAX)
> -                       size = SIZE_MAX;
> -               else
> -                       size += bufv->buf[i].size;
> -       }
> -
> -       return size;
> +    size_t i;
> +    size_t size = 0;
> +
> +    for (i = 0; i < bufv->count; i++) {
> +        if (bufv->buf[i].size == SIZE_MAX) {
> +            size = SIZE_MAX;
> +        } else {
> +            size += bufv->buf[i].size;
> +        }
> +    }
> +
> +    return size;
>  }
>
>  static size_t min_size(size_t s1, size_t s2)
>  {
> -       return s1 < s2 ? s1 : s2;
> +    return s1 < s2 ? s1 : s2;
>  }
>
>  static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off,
> -                             const struct fuse_buf *src, size_t src_off,
> -                             size_t len)
> +                              const struct fuse_buf *src, size_t src_off,
> +                              size_t len)
>  {
> -       ssize_t res = 0;
> -       size_t copied = 0;
> -
> -       while (len) {
> -               if (dst->flags & FUSE_BUF_FD_SEEK) {
> -                       res = pwrite(dst->fd, (char *)src->mem + src_off,
> len,
> -                                    dst->pos + dst_off);
> -               } else {
> -                       res = write(dst->fd, (char *)src->mem + src_off,
> len);
> -               }
> -               if (res == -1) {
> -                       if (!copied)
> -                               return -errno;
> -                       break;
> -               }
> -               if (res == 0)
> -                       break;
> -
> -               copied += res;
> -               if (!(dst->flags & FUSE_BUF_FD_RETRY))
> -                       break;
> -
> -               src_off += res;
> -               dst_off += res;
> -               len -= res;
> -       }
> -
> -       return copied;
> +    ssize_t res = 0;
> +    size_t copied = 0;
> +
> +    while (len) {
> +        if (dst->flags & FUSE_BUF_FD_SEEK) {
> +            res = pwrite(dst->fd, (char *)src->mem + src_off, len,
> +                         dst->pos + dst_off);
> +        } else {
> +            res = write(dst->fd, (char *)src->mem + src_off, len);
> +        }
> +        if (res == -1) {
> +            if (!copied) {
> +                return -errno;
> +            }
> +            break;
> +        }
> +        if (res == 0) {
> +            break;
> +        }
> +
> +        copied += res;
> +        if (!(dst->flags & FUSE_BUF_FD_RETRY)) {
> +            break;
> +        }
> +
> +        src_off += res;
> +        dst_off += res;
> +        len -= res;
> +    }
> +
> +    return copied;
>  }
>
>  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)
> +                             const struct fuse_buf *src, size_t src_off,
> +                             size_t len)
>  {
> -       ssize_t res = 0;
> -       size_t copied = 0;
> -
> -       while (len) {
> -               if (src->flags & FUSE_BUF_FD_SEEK) {
> -                       res = pread(src->fd, (char *)dst->mem + dst_off,
> len,
> -                                    src->pos + src_off);
> -               } else {
> -                       res = read(src->fd, (char *)dst->mem + dst_off,
> len);
> -               }
> -               if (res == -1) {
> -                       if (!copied)
> -                               return -errno;
> -                       break;
> -               }
> -               if (res == 0)
> -                       break;
> -
> -               copied += res;
> -               if (!(src->flags & FUSE_BUF_FD_RETRY))
> -                       break;
> -
> -               dst_off += res;
> -               src_off += res;
> -               len -= res;
> -       }
> -
> -       return copied;
> +    ssize_t res = 0;
> +    size_t copied = 0;
> +
> +    while (len) {
> +        if (src->flags & FUSE_BUF_FD_SEEK) {
> +            res = pread(src->fd, (char *)dst->mem + dst_off, len,
> +                        src->pos + src_off);
> +        } else {
> +            res = read(src->fd, (char *)dst->mem + dst_off, len);
> +        }
> +        if (res == -1) {
> +            if (!copied) {
> +                return -errno;
> +            }
> +            break;
> +        }
> +        if (res == 0) {
> +            break;
> +        }
> +
> +        copied += res;
> +        if (!(src->flags & FUSE_BUF_FD_RETRY)) {
> +            break;
> +        }
> +
> +        dst_off += res;
> +        src_off += res;
> +        len -= res;
> +    }
> +
> +    return copied;
>  }
>
>  static ssize_t fuse_buf_fd_to_fd(const struct fuse_buf *dst, size_t
> dst_off,
> -                                const struct fuse_buf *src, size_t
> src_off,
> -                                size_t len)
> +                                 const struct fuse_buf *src, size_t
> src_off,
> +                                 size_t len)
>  {
> -       char buf[4096];
> -       struct fuse_buf tmp = {
> -               .size = sizeof(buf),
> -               .flags = 0,
> -       };
> -       ssize_t res;
> -       size_t copied = 0;
> -
> -       tmp.mem = buf;
> -
> -       while (len) {
> -               size_t this_len = min_size(tmp.size, len);
> -               size_t read_len;
> -
> -               res = fuse_buf_read(&tmp, 0, src, src_off, this_len);
> -               if (res < 0) {
> -                       if (!copied)
> -                               return res;
> -                       break;
> -               }
> -               if (res == 0)
> -                       break;
> -
> -               read_len = res;
> -               res = fuse_buf_write(dst, dst_off, &tmp, 0, read_len);
> -               if (res < 0) {
> -                       if (!copied)
> -                               return res;
> -                       break;
> -               }
> -               if (res == 0)
> -                       break;
> -
> -               copied += res;
> -
> -               if (res < this_len)
> -                       break;
> -
> -               dst_off += res;
> -               src_off += res;
> -               len -= res;
> -       }
> -
> -       return copied;
> +    char buf[4096];
> +    struct fuse_buf tmp = {
> +        .size = sizeof(buf),
> +        .flags = 0,
> +    };
> +    ssize_t res;
> +    size_t copied = 0;
> +
> +    tmp.mem = buf;
> +
> +    while (len) {
> +        size_t this_len = min_size(tmp.size, len);
> +        size_t read_len;
> +
> +        res = fuse_buf_read(&tmp, 0, src, src_off, this_len);
> +        if (res < 0) {
> +            if (!copied) {
> +                return res;
> +            }
> +            break;
> +        }
> +        if (res == 0) {
> +            break;
> +        }
> +
> +        read_len = res;
> +        res = fuse_buf_write(dst, dst_off, &tmp, 0, read_len);
> +        if (res < 0) {
> +            if (!copied) {
> +                return res;
> +            }
> +            break;
> +        }
> +        if (res == 0) {
> +            break;
> +        }
> +
> +        copied += res;
> +
> +        if (res < this_len) {
> +            break;
> +        }
> +
> +        dst_off += res;
> +        src_off += res;
> +        len -= res;
> +    }
> +
> +    return copied;
>  }
>
>  #ifdef HAVE_SPLICE
>  static ssize_t fuse_buf_splice(const struct fuse_buf *dst, size_t dst_off,
> -                              const struct fuse_buf *src, size_t src_off,
> -                              size_t len, enum fuse_buf_copy_flags flags)
> +                               const struct fuse_buf *src, size_t src_off,
> +                               size_t len, enum fuse_buf_copy_flags flags)
>  {
> -       int splice_flags = 0;
> -       off_t *srcpos = NULL;
> -       off_t *dstpos = NULL;
> -       off_t srcpos_val;
> -       off_t dstpos_val;
> -       ssize_t res;
> -       size_t copied = 0;
> -
> -       if (flags & FUSE_BUF_SPLICE_MOVE)
> -               splice_flags |= SPLICE_F_MOVE;
> -       if (flags & FUSE_BUF_SPLICE_NONBLOCK)
> -               splice_flags |= SPLICE_F_NONBLOCK;
> -
> -       if (src->flags & FUSE_BUF_FD_SEEK) {
> -               srcpos_val = src->pos + src_off;
> -               srcpos = &srcpos_val;
> -       }
> -       if (dst->flags & FUSE_BUF_FD_SEEK) {
> -               dstpos_val = dst->pos + dst_off;
> -               dstpos = &dstpos_val;
> -       }
> -
> -       while (len) {
> -               res = splice(src->fd, srcpos, dst->fd, dstpos, len,
> -                            splice_flags);
> -               if (res == -1) {
> -                       if (copied)
> -                               break;
> -
> -                       if (errno != EINVAL || (flags &
> FUSE_BUF_FORCE_SPLICE))
> -                               return -errno;
> -
> -                       /* Maybe splice is not supported for this
> combination */
> -                       return fuse_buf_fd_to_fd(dst, dst_off, src,
> src_off,
> -                                                len);
> -               }
> -               if (res == 0)
> -                       break;
> -
> -               copied += res;
> -               if (!(src->flags & FUSE_BUF_FD_RETRY) &&
> -                   !(dst->flags & FUSE_BUF_FD_RETRY)) {
> -                       break;
> -               }
> -
> -               len -= res;
> -       }
> -
> -       return copied;
> +    int splice_flags = 0;
> +    off_t *srcpos = NULL;
> +    off_t *dstpos = NULL;
> +    off_t srcpos_val;
> +    off_t dstpos_val;
> +    ssize_t res;
> +    size_t copied = 0;
> +
> +    if (flags & FUSE_BUF_SPLICE_MOVE) {
> +        splice_flags |= SPLICE_F_MOVE;
> +    }
> +    if (flags & FUSE_BUF_SPLICE_NONBLOCK) {
> +        splice_flags |= SPLICE_F_NONBLOCK;
> +    }
> +    if (src->flags & FUSE_BUF_FD_SEEK) {
> +        srcpos_val = src->pos + src_off;
> +        srcpos = &srcpos_val;
> +    }
> +    if (dst->flags & FUSE_BUF_FD_SEEK) {
> +        dstpos_val = dst->pos + dst_off;
> +        dstpos = &dstpos_val;
> +    }
> +
> +    while (len) {
> +        res = splice(src->fd, srcpos, dst->fd, dstpos, len, splice_flags);
> +        if (res == -1) {
> +            if (copied) {
> +                break;
> +            }
> +
> +            if (errno != EINVAL || (flags & FUSE_BUF_FORCE_SPLICE)) {
> +                return -errno;
> +            }
> +
> +            /* Maybe splice is not supported for this combination */
> +            return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
> +        }
> +        if (res == 0) {
> +            break;
> +        }
> +
> +        copied += res;
> +        if (!(src->flags & FUSE_BUF_FD_RETRY) &&
> +            !(dst->flags & FUSE_BUF_FD_RETRY)) {
> +            break;
> +        }
> +
> +        len -= res;
> +    }
> +
> +    return copied;
>  }
>  #else
>  static ssize_t fuse_buf_splice(const struct fuse_buf *dst, size_t dst_off,
> -                              const struct fuse_buf *src, size_t src_off,
> -                              size_t len, enum fuse_buf_copy_flags flags)
> +                               const struct fuse_buf *src, size_t src_off,
> +                               size_t len, enum fuse_buf_copy_flags flags)
>  {
> -       (void) flags;
> +    (void)flags;
>
> -       return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
> +    return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
>  }
>  #endif
>
>
>  static ssize_t fuse_buf_copy_one(const struct fuse_buf *dst, size_t
> dst_off,
> -                                const struct fuse_buf *src, size_t
> src_off,
> -                                size_t len, enum fuse_buf_copy_flags
> flags)
> +                                 const struct fuse_buf *src, size_t
> src_off,
> +                                 size_t len, enum fuse_buf_copy_flags
> flags)
>  {
> -       int src_is_fd = src->flags & FUSE_BUF_IS_FD;
> -       int dst_is_fd = dst->flags & FUSE_BUF_IS_FD;
> -
> -       if (!src_is_fd && !dst_is_fd) {
> -               char *dstmem = (char *)dst->mem + dst_off;
> -               char *srcmem = (char *)src->mem + src_off;
> -
> -               if (dstmem != srcmem) {
> -                       if (dstmem + len <= srcmem || srcmem + len <=
> dstmem)
> -                               memcpy(dstmem, srcmem, len);
> -                       else
> -                               memmove(dstmem, srcmem, len);
> -               }
> -
> -               return len;
> -       } else if (!src_is_fd) {
> -               return fuse_buf_write(dst, dst_off, src, src_off, len);
> -       } else if (!dst_is_fd) {
> -               return fuse_buf_read(dst, dst_off, src, src_off, len);
> -       } else if (flags & FUSE_BUF_NO_SPLICE) {
> -               return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
> -       } else {
> -               return fuse_buf_splice(dst, dst_off, src, src_off, len,
> flags);
> -       }
> +    int src_is_fd = src->flags & FUSE_BUF_IS_FD;
> +    int dst_is_fd = dst->flags & FUSE_BUF_IS_FD;
> +
> +    if (!src_is_fd && !dst_is_fd) {
> +        char *dstmem = (char *)dst->mem + dst_off;
> +        char *srcmem = (char *)src->mem + src_off;
> +
> +        if (dstmem != srcmem) {
> +            if (dstmem + len <= srcmem || srcmem + len <= dstmem) {
> +                memcpy(dstmem, srcmem, len);
> +            } else {
> +                memmove(dstmem, srcmem, len);
> +            }
> +        }
> +
> +        return len;
> +    } else if (!src_is_fd) {
> +        return fuse_buf_write(dst, dst_off, src, src_off, len);
> +    } else if (!dst_is_fd) {
> +        return fuse_buf_read(dst, dst_off, src, src_off, len);
> +    } else if (flags & FUSE_BUF_NO_SPLICE) {
> +        return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
> +    } else {
> +        return fuse_buf_splice(dst, dst_off, src, src_off, len, flags);
> +    }
>  }
>
>  static const struct fuse_buf *fuse_bufvec_current(struct fuse_bufvec
> *bufv)
>  {
> -       if (bufv->idx < bufv->count)
> -               return &bufv->buf[bufv->idx];
> -       else
> -               return NULL;
> +    if (bufv->idx < bufv->count) {
> +        return &bufv->buf[bufv->idx];
> +    } else {
> +        return NULL;
> +    }
>  }
>
>  static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len)
>  {
> -       const struct fuse_buf *buf = fuse_bufvec_current(bufv);
> -
> -       bufv->off += len;
> -       assert(bufv->off <= buf->size);
> -       if (bufv->off == buf->size) {
> -               assert(bufv->idx < bufv->count);
> -               bufv->idx++;
> -               if (bufv->idx == bufv->count)
> -                       return 0;
> -               bufv->off = 0;
> -       }
> -       return 1;
> +    const struct fuse_buf *buf = fuse_bufvec_current(bufv);
> +
> +    bufv->off += len;
> +    assert(bufv->off <= buf->size);
> +    if (bufv->off == buf->size) {
> +        assert(bufv->idx < bufv->count);
> +        bufv->idx++;
> +        if (bufv->idx == bufv->count) {
> +            return 0;
> +        }
> +        bufv->off = 0;
> +    }
> +    return 1;
>  }
>
>  ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct fuse_bufvec *srcv,
> -                     enum fuse_buf_copy_flags flags)
> +                      enum fuse_buf_copy_flags flags)
>  {
> -       size_t copied = 0;
> -
> -       if (dstv == srcv)
> -               return fuse_buf_size(dstv);
> -
> -       for (;;) {
> -               const struct fuse_buf *src = fuse_bufvec_current(srcv);
> -               const struct fuse_buf *dst = fuse_bufvec_current(dstv);
> -               size_t src_len;
> -               size_t dst_len;
> -               size_t len;
> -               ssize_t res;
> -
> -               if (src == NULL || dst == NULL)
> -                       break;
> -
> -               src_len = src->size - srcv->off;
> -               dst_len = dst->size - dstv->off;
> -               len = min_size(src_len, dst_len);
> -
> -               res = fuse_buf_copy_one(dst, dstv->off, src, srcv->off,
> len, flags);
> -               if (res < 0) {
> -                       if (!copied)
> -                               return res;
> -                       break;
> -               }
> -               copied += res;
> -
> -               if (!fuse_bufvec_advance(srcv, res) ||
> -                   !fuse_bufvec_advance(dstv, res))
> -                       break;
> -
> -               if (res < len)
> -                       break;
> -       }
> -
> -       return copied;
> +    size_t copied = 0;
> +
> +    if (dstv == srcv) {
> +        return fuse_buf_size(dstv);
> +    }
> +
> +    for (;;) {
> +        const struct fuse_buf *src = fuse_bufvec_current(srcv);
> +        const struct fuse_buf *dst = fuse_bufvec_current(dstv);
> +        size_t src_len;
> +        size_t dst_len;
> +        size_t len;
> +        ssize_t res;
> +
> +        if (src == NULL || dst == NULL) {
> +            break;
> +        }
> +
> +        src_len = src->size - srcv->off;
> +        dst_len = dst->size - dstv->off;
> +        len = min_size(src_len, dst_len);
> +
> +        res = fuse_buf_copy_one(dst, dstv->off, src, srcv->off, len,
> flags);
> +        if (res < 0) {
> +            if (!copied) {
> +                return res;
> +            }
> +            break;
> +        }
> +        copied += res;
> +
> +        if (!fuse_bufvec_advance(srcv, res) ||
> +            !fuse_bufvec_advance(dstv, res)) {
> +            break;
> +        }
> +
> +        if (res < len) {
> +            break;
> +        }
> +    }
> +
> +    return copied;
>  }
> diff --git a/tools/virtiofsd/fuse.h b/tools/virtiofsd/fuse.h
> index 6c16a0041d..945ebc7a0d 100644
> --- a/tools/virtiofsd/fuse.h
> +++ b/tools/virtiofsd/fuse.h
> @@ -1,15 +1,15 @@
>  /*
> -  FUSE: Filesystem in Userspace
> -  Copyright (C) 2001-2007  Miklos Szeredi <mik...@szeredi.hu>
> -
> -  This program can be distributed under the terms of the GNU LGPLv2.
> -  See the file COPYING.LIB.
> -*/
> + * FUSE: Filesystem in Userspace
> + * Copyright (C) 2001-2007  Miklos Szeredi <mik...@szeredi.hu>
> + *
> + * This program can be distributed under the terms of the GNU LGPLv2.
> + * See the file COPYING.LIB.
> + */
>
>  #ifndef FUSE_H_
>  #define FUSE_H_
>
> -/** @file
> +/*
>   *
>   * This file defines the library interface of FUSE
>   *
> @@ -19,15 +19,15 @@
>  #include "fuse_common.h"
>
>  #include <fcntl.h>
> -#include <time.h>
> -#include <sys/types.h>
>  #include <sys/stat.h>
>  #include <sys/statvfs.h>
> +#include <sys/types.h>
>  #include <sys/uio.h>
> +#include <time.h>
>
> -/* ----------------------------------------------------------- *
> - * Basic FUSE API                                             *
> - * ----------------------------------------------------------- */
> +/*
> + * Basic FUSE API
> + */
>
>  /** Handle for a FUSE filesystem */
>  struct fuse;
> @@ -36,38 +36,39 @@ struct fuse;
>   * Readdir flags, passed to ->readdir()
>   */
>  enum fuse_readdir_flags {
> -       /**
> -        * "Plus" mode.
> -        *
> -        * The kernel wants to prefill the inode cache during readdir.  The
> -        * filesystem may honour this by filling in the attributes and
> setting
> -        * FUSE_FILL_DIR_FLAGS for the filler function.  The filesystem
> may also
> -        * just ignore this flag completely.
> -        */
> -       FUSE_READDIR_PLUS = (1 << 0),
> +    /**
> +     * "Plus" mode.
> +     *
> +     * The kernel wants to prefill the inode cache during readdir.  The
> +     * filesystem may honour this by filling in the attributes and setting
> +     * FUSE_FILL_DIR_FLAGS for the filler function.  The filesystem may
> also
> +     * just ignore this flag completely.
> +     */
> +    FUSE_READDIR_PLUS = (1 << 0),
>  };
>
>  enum fuse_fill_dir_flags {
> -       /**
> -        * "Plus" mode: all file attributes are valid
> -        *
> -        * The attributes are used by the kernel to prefill the inode cache
> -        * during a readdir.
> -        *
> -        * It is okay to set FUSE_FILL_DIR_PLUS if FUSE_READDIR_PLUS is
> not set
> -        * and vice versa.
> -        */
> -       FUSE_FILL_DIR_PLUS = (1 << 1),
> +    /**
> +     * "Plus" mode: all file attributes are valid
> +     *
> +     * The attributes are used by the kernel to prefill the inode cache
> +     * during a readdir.
> +     *
> +     * It is okay to set FUSE_FILL_DIR_PLUS if FUSE_READDIR_PLUS is not
> set
> +     * and vice versa.
> +     */
> +    FUSE_FILL_DIR_PLUS = (1 << 1),
>  };
>
> -/** Function to add an entry in a readdir() operation
> +/**
> + * Function to add an entry in a readdir() operation
>   *
>   * The *off* parameter can be any non-zero value that enables the
>   * filesystem to identify the current point in the directory
>   * stream. It does not need to be the actual physical position. A
>   * value of zero is reserved to indicate that seeking in directories
>   * is not supported.
> - *
> + *
>   * @param buf the buffer passed to the readdir() operation
>   * @param name the file name of the directory entry
>   * @param stat file attributes, can be NULL
> @@ -75,9 +76,9 @@ enum fuse_fill_dir_flags {
>   * @param flags fill flags
>   * @return 1 if buffer is full, zero otherwise
>   */
> -typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
> -                               const struct stat *stbuf, off_t off,
> -                               enum fuse_fill_dir_flags flags);
> +typedef int (*fuse_fill_dir_t)(void *buf, const char *name,
> +                               const struct stat *stbuf, off_t off,
> +                               enum fuse_fill_dir_flags flags);
>  /**
>   * Configuration of the high-level API
>   *
> @@ -87,186 +88,186 @@ typedef int (*fuse_fill_dir_t) (void *buf, const
> char *name,
>   * file system implementation.
>   */
>  struct fuse_config {
> -       /**
> -        * If `set_gid` is non-zero, the st_gid attribute of each file
> -        * is overwritten with the value of `gid`.
> -        */
> -       int set_gid;
> -       unsigned int gid;
> -
> -       /**
> -        * If `set_uid` is non-zero, the st_uid attribute of each file
> -        * is overwritten with the value of `uid`.
> -        */
> -       int set_uid;
> -       unsigned int uid;
> -
> -       /**
> -        * If `set_mode` is non-zero, the any permissions bits set in
> -        * `umask` are unset in the st_mode attribute of each file.
> -        */
> -       int set_mode;
> -       unsigned int umask;
> -
> -       /**
> -        * The timeout in seconds for which name lookups will be
> -        * cached.
> -        */
> -       double entry_timeout;
> -
> -       /**
> -        * The timeout in seconds for which a negative lookup will be
> -        * cached. This means, that if file did not exist (lookup
> -        * retuned ENOENT), the lookup will only be redone after the
> -        * timeout, and the file/directory will be assumed to not
> -        * exist until then. A value of zero means that negative
> -        * lookups are not cached.
> -        */
> -       double negative_timeout;
> -
> -       /**
> -        * The timeout in seconds for which file/directory attributes
> -        * (as returned by e.g. the `getattr` handler) are cached.
> -        */
> -       double attr_timeout;
> -
> -       /**
> -        * Allow requests to be interrupted
> -        */
> -       int intr;
> -
> -       /**
> -        * Specify which signal number to send to the filesystem when
> -        * a request is interrupted.  The default is hardcoded to
> -        * USR1.
> -        */
> -       int intr_signal;
> -
> -       /**
> -        * Normally, FUSE assigns inodes to paths only for as long as
> -        * the kernel is aware of them. With this option inodes are
> -        * instead remembered for at least this many seconds.  This
> -        * will require more memory, but may be necessary when using
> -        * applications that make use of inode numbers.
> -        *
> -        * A number of -1 means that inodes will be remembered for the
> -        * entire life-time of the file-system process.
> -        */
> -       int remember;
> -
> -       /**
> -        * The default behavior is that if an open file is deleted,
> -        * the file is renamed to a hidden file (.fuse_hiddenXXX), and
> -        * only removed when the file is finally released.  This
> -        * relieves the filesystem implementation of having to deal
> -        * with this problem. This option disables the hiding
> -        * behavior, and files are removed immediately in an unlink
> -        * operation (or in a rename operation which overwrites an
> -        * existing file).
> -        *
> -        * It is recommended that you not use the hard_remove
> -        * option. When hard_remove is set, the following libc
> -        * functions fail on unlinked files (returning errno of
> -        * ENOENT): read(2), write(2), fsync(2), close(2), f*xattr(2),
> -        * ftruncate(2), fstat(2), fchmod(2), fchown(2)
> -        */
> -       int hard_remove;
> -
> -       /**
> -        * Honor the st_ino field in the functions getattr() and
> -        * fill_dir(). This value is used to fill in the st_ino field
> -        * in the stat(2), lstat(2), fstat(2) functions and the d_ino
> -        * field in the readdir(2) function. The filesystem does not
> -        * have to guarantee uniqueness, however some applications
> -        * rely on this value being unique for the whole filesystem.
> -        *
> -        * Note that this does *not* affect the inode that libfuse
> -        * and the kernel use internally (also called the "nodeid").
> -        */
> -       int use_ino;
> -
> -       /**
> -        * If use_ino option is not given, still try to fill in the
> -        * d_ino field in readdir(2). If the name was previously
> -        * looked up, and is still in the cache, the inode number
> -        * found there will be used.  Otherwise it will be set to -1.
> -        * If use_ino option is given, this option is ignored.
> -        */
> -       int readdir_ino;
> -
> -       /**
> -        * This option disables the use of page cache (file content cache)
> -        * in the kernel for this filesystem. This has several affects:
> -        *
> -        * 1. Each read(2) or write(2) system call will initiate one
> -        *    or more read or write operations, data will not be
> -        *    cached in the kernel.
> -        *
> -        * 2. The return value of the read() and write() system calls
> -        *    will correspond to the return values of the read and
> -        *    write operations. This is useful for example if the
> -        *    file size is not known in advance (before reading it).
> -        *
> -        * Internally, enabling this option causes fuse to set the
> -        * `direct_io` field of `struct fuse_file_info` - overwriting
> -        * any value that was put there by the file system.
> -        */
> -       int direct_io;
> -
> -       /**
> -        * This option disables flushing the cache of the file
> -        * contents on every open(2).  This should only be enabled on
> -        * filesystems where the file data is never changed
> -        * externally (not through the mounted FUSE filesystem).  Thus
> -        * it is not suitable for network filesystems and other
> -        * intermediate filesystems.
> -        *
> -        * NOTE: if this option is not specified (and neither
> -        * direct_io) data is still cached after the open(2), so a
> -        * read(2) system call will not always initiate a read
> -        * operation.
> -        *
> -        * Internally, enabling this option causes fuse to set the
> -        * `keep_cache` field of `struct fuse_file_info` - overwriting
> -        * any value that was put there by the file system.
> -        */
> -       int kernel_cache;
> -
> -       /**
> -        * This option is an alternative to `kernel_cache`. Instead of
> -        * unconditionally keeping cached data, the cached data is
> -        * invalidated on open(2) if if the modification time or the
> -        * size of the file has changed since it was last opened.
> -        */
> -       int auto_cache;
> -
> -       /**
> -        * The timeout in seconds for which file attributes are cached
> -        * for the purpose of checking if auto_cache should flush the
> -        * file data on open.
> -        */
> -       int ac_attr_timeout_set;
> -       double ac_attr_timeout;
> -
> -       /**
> -        * If this option is given the file-system handlers for the
> -        * following operations will not receive path information:
> -        * read, write, flush, release, fsync, readdir, releasedir,
> -        * fsyncdir, lock, ioctl and poll.
> -        *
> -        * For the truncate, getattr, chmod, chown and utimens
> -        * operations the path will be provided only if the struct
> -        * fuse_file_info argument is NULL.
> -        */
> -       int nullpath_ok;
> -
> -       /**
> -        * The remaining options are used by libfuse internally and
> -        * should not be touched.
> -        */
> -       int show_help;
> -       char *modules;
> -       int debug;
> +    /**
> +     * If `set_gid` is non-zero, the st_gid attribute of each file
> +     * is overwritten with the value of `gid`.
> +     */
> +    int set_gid;
> +    unsigned int gid;
> +
> +    /**
> +     * If `set_uid` is non-zero, the st_uid attribute of each file
> +     * is overwritten with the value of `uid`.
> +     */
> +    int set_uid;
> +    unsigned int uid;
> +
> +    /**
> +     * If `set_mode` is non-zero, the any permissions bits set in
> +     * `umask` are unset in the st_mode attribute of each file.
> +     */
> +    int set_mode;
> +    unsigned int umask;
> +
> +    /**
> +     * The timeout in seconds for which name lookups will be
> +     * cached.
> +     */
> +    double entry_timeout;
> +
> +    /**
> +     * The timeout in seconds for which a negative lookup will be
> +     * cached. This means, that if file did not exist (lookup
> +     * retuned ENOENT), the lookup will only be redone after the
> +     * timeout, and the file/directory will be assumed to not
> +     * exist until then. A value of zero means that negative
> +     * lookups are not cached.
> +     */
> +    double negative_timeout;
> +
> +    /**
> +     * The timeout in seconds for which file/directory attributes
> +     * (as returned by e.g. the `getattr` handler) are cached.
> +     */
> +    double attr_timeout;
> +
> +    /**
> +     * Allow requests to be interrupted
> +     */
> +    int intr;
> +
> +    /**
> +     * Specify which signal number to send to the filesystem when
> +     * a request is interrupted.  The default is hardcoded to
> +     * USR1.
> +     */
> +    int intr_signal;
> +
> +    /**
> +     * Normally, FUSE assigns inodes to paths only for as long as
> +     * the kernel is aware of them. With this option inodes are
> +     * instead remembered for at least this many seconds.  This
> +     * will require more memory, but may be necessary when using
> +     * applications that make use of inode numbers.
> +     *
> +     * A number of -1 means that inodes will be remembered for the
> +     * entire life-time of the file-system process.
> +     */
> +    int remember;
> +
> +    /**
> +     * The default behavior is that if an open file is deleted,
> +     * the file is renamed to a hidden file (.fuse_hiddenXXX), and
> +     * only removed when the file is finally released.  This
> +     * relieves the filesystem implementation of having to deal
> +     * with this problem. This option disables the hiding
> +     * behavior, and files are removed immediately in an unlink
> +     * operation (or in a rename operation which overwrites an
> +     * existing file).
> +     *
> +     * It is recommended that you not use the hard_remove
> +     * option. When hard_remove is set, the following libc
> +     * functions fail on unlinked files (returning errno of
> +     * ENOENT): read(2), write(2), fsync(2), close(2), f*xattr(2),
> +     * ftruncate(2), fstat(2), fchmod(2), fchown(2)
> +     */
> +    int hard_remove;
> +
> +    /**
> +     * Honor the st_ino field in the functions getattr() and
> +     * fill_dir(). This value is used to fill in the st_ino field
> +     * in the stat(2), lstat(2), fstat(2) functions and the d_ino
> +     * field in the readdir(2) function. The filesystem does not
> +     * have to guarantee uniqueness, however some applications
> +     * rely on this value being unique for the whole filesystem.
> +     *
> +     * Note that this does *not* affect the inode that libfuse
> +     * and the kernel use internally (also called the "nodeid").
> +     */
> +    int use_ino;
> +
> +    /**
> +     * If use_ino option is not given, still try to fill in the
> +     * d_ino field in readdir(2). If the name was previously
> +     * looked up, and is still in the cache, the inode number
> +     * found there will be used.  Otherwise it will be set to -1.
> +     * If use_ino option is given, this option is ignored.
> +     */
> +    int readdir_ino;
> +
> +    /**
> +     * This option disables the use of page cache (file content cache)
> +     * in the kernel for this filesystem. This has several affects:
> +     *
> +     * 1. Each read(2) or write(2) system call will initiate one
> +     *    or more read or write operations, data will not be
> +     *    cached in the kernel.
> +     *
> +     * 2. The return value of the read() and write() system calls
> +     *    will correspond to the return values of the read and
> +     *    write operations. This is useful for example if the
> +     *    file size is not known in advance (before reading it).
> +     *
> +     * Internally, enabling this option causes fuse to set the
> +     * `direct_io` field of `struct fuse_file_info` - overwriting
> +     * any value that was put there by the file system.
> +     */
> +    int direct_io;
> +
> +    /**
> +     * This option disables flushing the cache of the file
> +     * contents on every open(2).  This should only be enabled on
> +     * filesystems where the file data is never changed
> +     * externally (not through the mounted FUSE filesystem).  Thus
> +     * it is not suitable for network filesystems and other
> +     * intermediate filesystems.
> +     *
> +     * NOTE: if this option is not specified (and neither
> +     * direct_io) data is still cached after the open(2), so a
> +     * read(2) system call will not always initiate a read
> +     * operation.
> +     *
> +     * Internally, enabling this option causes fuse to set the
> +     * `keep_cache` field of `struct fuse_file_info` - overwriting
> +     * any value that was put there by the file system.
> +     */
> +    int kernel_cache;
> +
> +    /**
> +     * This option is an alternative to `kernel_cache`. Instead of
> +     * unconditionally keeping cached data, the cached data is
> +     * invalidated on open(2) if if the modification time or the
> +     * size of the file has changed since it was last opened.
> +     */
> +    int auto_cache;
> +
> +    /**
> +     * The timeout in seconds for which file attributes are cached
> +     * for the purpose of checking if auto_cache should flush the
> +     * file data on open.
> +     */
> +    int ac_attr_timeout_set;
> +    double ac_attr_timeout;
> +
> +    /**
> +     * If this option is given the file-system handlers for the
> +     * following operations will not receive path information:
> +     * read, write, flush, release, fsync, readdir, releasedir,
> +     * fsyncdir, lock, ioctl and poll.
> +     *
> +     * For the truncate, getattr, chmod, chown and utimens
> +     * operations the path will be provided only if the struct
> +     * fuse_file_info argument is NULL.
> +     */
> +    int nullpath_ok;
> +
> +    /**
> +     * The remaining options are used by libfuse internally and
> +     * should not be touched.
> +     */
> +    int show_help;
> +    char *modules;
> +    int debug;
>  };
>
>
> @@ -293,515 +294,535 @@ struct fuse_config {
>   * Almost all operations take a path which can be of any length.
>   */
>  struct fuse_operations {
> -       /** Get file attributes.
> -        *
> -        * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
> -        * ignored. The 'st_ino' field is ignored except if the 'use_ino'
> -        * mount option is given. In that case it is passed to userspace,
> -        * but libfuse and the kernel will still assign a different
> -        * inode for internal use (called the "nodeid").
> -        *
> -        * `fi` will always be NULL if the file is not currently open, but
> -        * may also be NULL if the file is open.
> -        */
> -       int (*getattr) (const char *, struct stat *, struct fuse_file_info
> *fi);
> -
> -       /** Read the target of a symbolic link
> -        *
> -        * The buffer should be filled with a null terminated string.  The
> -        * buffer size argument includes the space for the terminating
> -        * null character.      If the linkname is too long to fit in the
> -        * buffer, it should be truncated.      The return value should be
> 0
> -        * for success.
> -        */
> -       int (*readlink) (const char *, char *, size_t);
> -
> -       /** Create a file node
> -        *
> -        * This is called for creation of all non-directory, non-symlink
> -        * nodes.  If the filesystem defines a create() method, then for
> -        * regular files that will be called instead.
> -        */
> -       int (*mknod) (const char *, mode_t, dev_t);
> -
> -       /** Create a directory
> -        *
> -        * Note that the mode argument may not have the type specification
> -        * bits set, i.e. S_ISDIR(mode) can be false.  To obtain the
> -        * correct directory type bits use  mode|S_IFDIR
> -        * */
> -       int (*mkdir) (const char *, mode_t);
> -
> -       /** Remove a file */
> -       int (*unlink) (const char *);
> -
> -       /** Remove a directory */
> -       int (*rmdir) (const char *);
> -
> -       /** Create a symbolic link */
> -       int (*symlink) (const char *, const char *);
> -
> -       /** Rename a file
> -        *
> -        * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
> -        * RENAME_NOREPLACE is specified, the filesystem must not
> -        * overwrite *newname* if it exists and return an error
> -        * instead. If `RENAME_EXCHANGE` is specified, the filesystem
> -        * must atomically exchange the two files, i.e. both must
> -        * exist and neither may be deleted.
> -        */
> -       int (*rename) (const char *, const char *, unsigned int flags);
> -
> -       /** Create a hard link to a file */
> -       int (*link) (const char *, const char *);
> -
> -       /** Change the permission bits of a file
> -        *
> -        * `fi` will always be NULL if the file is not currenlty open, but
> -        * may also be NULL if the file is open.
> -        */
> -       int (*chmod) (const char *, mode_t, struct fuse_file_info *fi);
> -
> -       /** Change the owner and group of a file
> -        *
> -        * `fi` will always be NULL if the file is not currenlty open, but
> -        * may also be NULL if the file is open.
> -        *
> -        * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
> -        * expected to reset the setuid and setgid bits.
> -        */
> -       int (*chown) (const char *, uid_t, gid_t, struct fuse_file_info
> *fi);
> -
> -       /** Change the size of a file
> -        *
> -        * `fi` will always be NULL if the file is not currenlty open, but
> -        * may also be NULL if the file is open.
> -        *
> -        * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
> -        * expected to reset the setuid and setgid bits.
> -        */
> -       int (*truncate) (const char *, off_t, struct fuse_file_info *fi);
> -
> -       /** Open a file
> -        *
> -        * Open flags are available in fi->flags. The following rules
> -        * apply.
> -        *
> -        *  - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
> -        *    filtered out / handled by the kernel.
> -        *
> -        *  - Access modes (O_RDONLY, O_WRONLY, O_RDWR, O_EXEC, O_SEARCH)
> -        *    should be used by the filesystem to check if the operation is
> -        *    permitted.  If the ``-o default_permissions`` mount option is
> -        *    given, this check is already done by the kernel before
> calling
> -        *    open() and may thus be omitted by the filesystem.
> -        *
> -        *  - When writeback caching is enabled, the kernel may send
> -        *    read requests even for files opened with O_WRONLY. The
> -        *    filesystem should be prepared to handle this.
> -        *
> -        *  - When writeback caching is disabled, the filesystem is
> -        *    expected to properly handle the O_APPEND flag and ensure
> -        *    that each write is appending to the end of the file.
> -        *
> -         *  - When writeback caching is enabled, the kernel will
> -        *    handle O_APPEND. However, unless all changes to the file
> -        *    come through the kernel this will not work reliably. The
> -        *    filesystem should thus either ignore the O_APPEND flag
> -        *    (and let the kernel handle it), or return an error
> -        *    (indicating that reliably O_APPEND is not available).
> -        *
> -        * Filesystem may store an arbitrary file handle (pointer,
> -        * index, etc) in fi->fh, and use this in other all other file
> -        * operations (read, write, flush, release, fsync).
> -        *
> -        * Filesystem may also implement stateless file I/O and not store
> -        * anything in fi->fh.
> -        *
> -        * There are also some flags (direct_io, keep_cache) which the
> -        * filesystem may set in fi, to change the way the file is opened.
> -        * See fuse_file_info structure in <fuse_common.h> for more
> details.
> -        *
> -        * If this request is answered with an error code of ENOSYS
> -        * and FUSE_CAP_NO_OPEN_SUPPORT is set in
> -        * `fuse_conn_info.capable`, this is treated as success and
> -        * future calls to open will also succeed without being send
> -        * to the filesystem process.
> -        *
> -        */
> -       int (*open) (const char *, struct fuse_file_info *);
> -
> -       /** Read data from an open file
> -        *
> -        * Read should return exactly the number of bytes requested except
> -        * on EOF or error, otherwise the rest of the data will be
> -        * substituted with zeroes.      An exception to this is when the
> -        * 'direct_io' mount option is specified, in which case the return
> -        * value of the read system call will reflect the return value of
> -        * this operation.
> -        */
> -       int (*read) (const char *, char *, size_t, off_t,
> -                    struct fuse_file_info *);
> -
> -       /** Write data to an open file
> -        *
> -        * Write should return exactly the number of bytes requested
> -        * except on error.      An exception to this is when the
> 'direct_io'
> -        * mount option is specified (see read operation).
> -        *
> -        * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this meth

Reply via email to