[CRIU] [PATCH v2] bfd: bread: read in a loop when running with --remote

Rodrigo Bruno rbruno at gsd.inesc-id.pt
Mon Jul 10 15:15:09 MSK 2017


Hi,

isn't it a good idea to extract the read loop into a separate function (I
thought we already had one in the past...)?

I mean, the read syscall is not guaranteed to actually read the number
requested bytes (not even if we are reading from a local file).

Besides, if I remember correctly, there are multiple code locations that
could use that new function.

cheers,
rodrigo

2017-07-10 12:56 GMT+01:00 Omri Kramer <omri.kramer at gmail.com>:

> When the --remote option is used, the file descriptor
> used in bread is a socketand it may return after only
> part of the data is read. Keep going looping until all
> the data is received when --remote option is on.
>
> Signed-off-by: Omri Kramer <omri.kramer at gmail.com>
> Signed-off-by: Lior Fisch <fischlior at gmail.com>
> ---
>  criu/bfd.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/criu/bfd.c b/criu/bfd.c
> index 8269ab1..7c54d9b 100644
> --- a/criu/bfd.c
> +++ b/criu/bfd.c
> @@ -15,6 +15,7 @@
>  #include "util.h"
>  #include "xmalloc.h"
>  #include "page.h"
> +#include "cr_options.h"
>
>  #undef LOG_PREFIX
>  #define LOG_PREFIX "bfd: "
> @@ -298,9 +299,29 @@ int bread(struct bfd *bfd, void *buf, int size)
>  {
>         struct xbuf *b = &bfd->b;
>         int more = 1, filled = 0;
> +       int ret;
> +       size_t curr = 0;
>
> -       if (!bfd_buffered(bfd))
> -               return read(bfd->fd, buf, size);
> +       if (!bfd_buffered(bfd)) {
> +               if(!opts.remote)
> +                       return read(bfd->fd, buf, size);
> +               /*
> +                * Required to keep reading,
> +                * for succesfully Reading all the data
> +                * from the socket, when on remote option.
> +                */
> +               while (1) {
> +                       ret = read(bfd->fd, buf + curr, size - curr);
> +                       if (ret < 0) {
> +                               pr_perror("Can't read from buffer\n");
> +                               return -1;
> +                       }
> +
> +                       curr += ret;
> +                       if (curr == size || ret == 0)
> +                               return curr;
> +               }
> +       }
>
>         while (more > 0) {
>                 int chunk;
> --
> 2.7.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20170710/4d9aa878/attachment.html>


More information about the CRIU mailing list