Re: [PATCH] iohelper: use saferead if later write with O_DIRECT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ping

On 28.09.2017 10:06, Nikolay Shirokovskiy wrote:
> One of the usecases of iohelper is to read from pipe and write
> to file with O_DIRECT. As we read from pipe we can have partial
> read and then we fail to write this data because output file
> is open with O_DIRECT and buffer size is not aligned.
> ---
>  src/util/iohelper.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/iohelper.c b/src/util/iohelper.c
> index 5416d45..bb8a8dd 100644
> --- a/src/util/iohelper.c
> +++ b/src/util/iohelper.c
> @@ -109,9 +109,21 @@ runIO(const char *path, int fd, int oflags)
>      while (1) {
>          ssize_t got;
>  
> -        if ((got = read(fdin, buf, buflen)) < 0) {
> -            if (errno == EINTR)
> +        /* If we read with O_DIRECT from file we can't use saferead as
> +         * it can lead to unaligned read after reading last bytes.
> +         * If we write with O_DIRECT use should use saferead so that
> +         * writes will be aligned.
> +         * In other cases using saferead reduces number of syscalls.
> +         */
> +        if (fdin == fd && direct) {
> +            if ((got = read(fdin, buf, buflen)) < 0 &&
> +                errno == EINTR)
>                  continue;
> +        } else {
> +            got = saferead(fdin, buf, buflen);
> +        }
> +
> +        if (got < 0) {
>              virReportSystemError(errno, _("Unable to read %s"), fdinname);
>              goto cleanup;
>          }
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux