All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiri Denemark <jdenemar@redhat.com>,
	qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2] migration: flush migration data to disk.
Date: Tue, 01 Nov 2011 13:03:14 -0500	[thread overview]
Message-ID: <4EB03462.6040502@codemonkey.ws> (raw)
In-Reply-To: <1319699524-32758-1-git-send-email-kraxel@redhat.com>

On 10/27/2011 02:12 AM, Gerd Hoffmann wrote:
> This patch increases robustness when migrating to a file with
> two little changes:
>
>   (1) Before closing the migration file handle checks if it happens to be
>       a regular file and if so it issues a fsync.  This way the data is
>       flushed to disk before qemu sends the migration completed event.
>   (2) It adds error checking.  In case either fsync or close syscall
>       fails pass up the error (and fail migration).
>
> [ v2: return -errno instead of -1 ]
>
> Cc: Juan Quintela<quintela@redhat.com>
> Cc: Jiri Denemark<jdenemar@redhat.com>
> Signed-off-by: Gerd Hoffmann<kraxel@redhat.com>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
>   migration-fd.c |   23 ++++++++++++++++++++++-
>   1 files changed, 22 insertions(+), 1 deletions(-)
>
> diff --git a/migration-fd.c b/migration-fd.c
> index d0aec89..6211124 100644
> --- a/migration-fd.c
> +++ b/migration-fd.c
> @@ -42,10 +42,31 @@ static int fd_write(MigrationState *s, const void * buf, size_t size)
>
>   static int fd_close(MigrationState *s)
>   {
> +    struct stat st;
> +    int ret;
> +
>       DPRINTF("fd_close\n");
>       if (s->fd != -1) {
> -        close(s->fd);
> +        ret = fstat(s->fd,&st);
> +        if (ret == 0&&  S_ISREG(st.st_mode)) {
> +            /*
> +             * If the file handle is a regular file make sure the
> +             * data is flushed to disk before signaling success.
> +             */
> +            ret = fsync(s->fd);
> +            if (ret != 0) {
> +                ret = -errno;
> +                perror("migration-fd: fsync");
> +                return ret;
> +            }
> +        }
> +        ret = close(s->fd);
>           s->fd = -1;
> +        if (ret != 0) {
> +            ret = -errno;
> +            perror("migration-fd: close");
> +            return ret;
> +        }
>       }
>       return 0;
>   }

      reply	other threads:[~2011-11-01 18:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-27  7:12 [Qemu-devel] [PATCH v2] migration: flush migration data to disk Gerd Hoffmann
2011-11-01 18:03 ` Anthony Liguori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EB03462.6040502@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=jdenemar@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.