Patchwork set proper migration status on ->write error (v3)

login
register
mail settings
Submitter Marcelo Tosatti
Date July 9, 2010, 6:18 p.m.
Message ID <20100709181851.GB7444@amt.cnet>
Download mbox | patch
Permalink /patch/58421/
State New
Headers show

Comments

Marcelo Tosatti - July 9, 2010, 6:18 p.m.
If ->write fails, declare migration status as MIG_STATE_ERROR. 

Also, in buffered_file.c, ->close the object in case of an 
error.

Fixes "migrate -d "exec:dd of=file", where dd fails to open file.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Luiz Capitulino - July 13, 2010, 1:33 a.m.
On Fri, 9 Jul 2010 15:18:51 -0300
Marcelo Tosatti <mtosatti@redhat.com> wrote:

> 
> If ->write fails, declare migration status as MIG_STATE_ERROR. 
> 
> Also, in buffered_file.c, ->close the object in case of an 
> error.
> 
> Fixes "migrate -d "exec:dd of=file", where dd fails to open file.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> diff --git a/buffered_file.c b/buffered_file.c
> index 54dc6c2..be147d6 100644
> --- a/buffered_file.c
> +++ b/buffered_file.c
> @@ -222,8 +222,10 @@ static void buffered_rate_tick(void *opaque)
>  {
>      QEMUFileBuffered *s = opaque;
>  
> -    if (s->has_error)
> +    if (s->has_error) {
> +        buffered_close(s);
>          return;
> +    }
>  
>      qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 100);
>  
> diff --git a/migration.c b/migration.c
> index b49964c..862dc4f 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -316,8 +316,12 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
>      if (ret == -1)
>          ret = -(s->get_error(s));
>  
> -    if (ret == -EAGAIN)
> +    if (ret == -EAGAIN) {
>          qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
> +    } else if (ret < 0) {
> +        monitor_resume(s);

You have to pass s->mon, but I forgot to mention that you also have to
check for NULL like migrate_fd_cleanup():

if (s->mon) {
    monitor_resume(s->mon);
}

Also, there's a comment in migrate_fd_cleanup() saying that we should only
resume the monitor when all buffers have been flushed. I assume
buffred_close() will do that.

> +        s->state = MIG_STATE_ERROR;
> +    }
>  
>      return ret;
>  }
>

Patch

diff --git a/buffered_file.c b/buffered_file.c
index 54dc6c2..be147d6 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -222,8 +222,10 @@  static void buffered_rate_tick(void *opaque)
 {
     QEMUFileBuffered *s = opaque;
 
-    if (s->has_error)
+    if (s->has_error) {
+        buffered_close(s);
         return;
+    }
 
     qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 100);
 
diff --git a/migration.c b/migration.c
index b49964c..862dc4f 100644
--- a/migration.c
+++ b/migration.c
@@ -316,8 +316,12 @@  ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
     if (ret == -1)
         ret = -(s->get_error(s));
 
-    if (ret == -EAGAIN)
+    if (ret == -EAGAIN) {
         qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
+    } else if (ret < 0) {
+        monitor_resume(s);
+        s->state = MIG_STATE_ERROR;
+    }
 
     return ret;
 }