Re: [Qemu-devel] Re: [PATCH 07/18] Introduce fault tolerant VM transaction QEMUFile and ft_mode.

2011-02-22 Thread Yoshiaki Tamura
2011/2/23 ya su suya94...@gmail.com:
 Yoshi:

    thanks for your explaining.
    if you introduce a new stage as 3, I think stage 1 also need to change as
 it will mark all pages dirty.
    looking forward to your new patch update.

Unless there're strong comments from others, I won't put it in
this series though because I don't want to touch other components
as much as possible this time.

Yoshi


 Green.


 2011/2/21 Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp

 Hi Green,

 2011/2/21 ya su suya94...@gmail.com:
  Yoshiaki:
 
      I have one question about ram_save_live, during migration 3
  stage(completation stage), it will call
  cpu_physical_memory_set_dirty_tracking(0) to stop recording ram dirty
  pages.
  at the end of migrate_ft_trans_connect function, it will invoke
  vm_start(),
  at this time, cpu_physical_memory_set_dirty_tracking(1) is not called
  yet,
  so there may have some ram pages not recorded when
  qemu_savevm_trans_begin
  is called.  I think you need calll
  cpu_physical_memory_set_dirty_tracking(1) in migrate_ft_trans_connect
  function, Am I right?

 Thank you for taking a look.
 When qemu_savevm_trans_begin is called for the first time, it
 calls ram_save_live with stage 1, that sends all pages and sets
 dirty tracking, so there won't be missing pages.  Note that
 event-tap is turned on by then, meaning no outputs are sent before
 finishing the first transaction.  I understand that this
 implementation is inefficient, and planning to introduce a new
 stage that is almost same as stage 3 but keeps dirty tracking in
 the future.

 Thanks,

 Yoshi

 
  BR
 
  Green.
 
 
  2011/2/10 Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
 
  This code implements VM transaction protocol.  Like buffered_file, it
  sits between savevm and migration layer.  With this architecture, VM
  transaction protocol is implemented mostly independent from other
  existing code.
 
  Signed-off-by: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
  Signed-off-by: OHMURA Kei ohmura@lab.ntt.co.jp
  ---
   Makefile.objs   |    1 +
   ft_trans_file.c |  624
  +++
   ft_trans_file.h |   72 +++
   migration.c     |    3 +
   trace-events    |   15 ++
   5 files changed, 715 insertions(+), 0 deletions(-)
   create mode 100644 ft_trans_file.c
   create mode 100644 ft_trans_file.h
 
  diff --git a/Makefile.objs b/Makefile.objs
  index 353b1a8..04148b5 100644
  --- a/Makefile.objs
  +++ b/Makefile.objs
  @@ -100,6 +100,7 @@ common-obj-y += msmouse.o ps2.o
   common-obj-y += qdev.o qdev-properties.o
   common-obj-y += block-migration.o
   common-obj-y += pflib.o
  +common-obj-y += ft_trans_file.o
 
   common-obj-$(CONFIG_BRLAPI) += baum.o
   common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o
  migration-fd.o
  diff --git a/ft_trans_file.c b/ft_trans_file.c
  new file mode 100644
  index 000..2b42b95
  --- /dev/null
  +++ b/ft_trans_file.c
  @@ -0,0 +1,624 @@
  +/*
  + * Fault tolerant VM transaction QEMUFile
  + *
  + * Copyright (c) 2010 Nippon Telegraph and Telephone Corporation.
  + *
  + * This work is licensed under the terms of the GNU GPL, version 2.
   See
  + * the COPYING file in the top-level directory.
  + *
  + * This source code is based on buffered_file.c.
  + * Copyright IBM, Corp. 2008
  + * Authors:
  + *  Anthony Liguori        aligu...@us.ibm.com
  + */
  +
  +#include qemu-common.h
  +#include qemu-error.h
  +#include hw/hw.h
  +#include qemu-timer.h
  +#include sysemu.h
  +#include qemu-char.h
  +#include trace.h
  +#include ft_trans_file.h
  +
  +typedef struct FtTransHdr
  +{
  +    uint16_t cmd;
  +    uint16_t id;
  +    uint32_t seq;
  +    uint32_t payload_len;
  +} FtTransHdr;
  +
  +typedef struct QEMUFileFtTrans
  +{
  +    FtTransPutBufferFunc *put_buffer;
  +    FtTransGetBufferFunc *get_buffer;
  +    FtTransPutReadyFunc *put_ready;
  +    FtTransGetReadyFunc *get_ready;
  +    FtTransWaitForUnfreezeFunc *wait_for_unfreeze;
  +    FtTransCloseFunc *close;
  +    void *opaque;
  +    QEMUFile *file;
  +
  +    enum QEMU_VM_TRANSACTION_STATE state;
  +    uint32_t seq;
  +    uint16_t id;
  +
  +    int has_error;
  +
  +    bool freeze_output;
  +    bool freeze_input;
  +    bool rate_limit;
  +    bool is_sender;
  +    bool is_payload;
  +
  +    uint8_t *buf;
  +    size_t buf_max_size;
  +    size_t put_offset;
  +    size_t get_offset;
  +
  +    FtTransHdr header;
  +    size_t header_offset;
  +} QEMUFileFtTrans;
  +
  +#define IO_BUF_SIZE 32768
  +
  +static void ft_trans_append(QEMUFileFtTrans *s,
  +                            const uint8_t *buf, size_t size)
  +{
  +    if (size  (s-buf_max_size - s-put_offset)) {
  +        trace_ft_trans_realloc(s-buf_max_size, size + 1024);
  +        s-buf_max_size += size + 1024;
  +        s-buf = qemu_realloc(s-buf, s-buf_max_size);
  +    }
  +
  +    trace_ft_trans_append(size);
  +    memcpy(s-buf + s-put_offset, buf, size);
  +    s-put_offset += size;
  

Re: [Qemu-devel] Re: [PATCH 07/18] Introduce fault tolerant VM transaction QEMUFile and ft_mode.

2011-02-21 Thread Yoshiaki Tamura
Hi Green,

2011/2/21 ya su suya94...@gmail.com:
 Yoshiaki:

     I have one question about ram_save_live, during migration 3
 stage(completation stage), it will call
 cpu_physical_memory_set_dirty_tracking(0) to stop recording ram dirty pages.
 at the end of migrate_ft_trans_connect function, it will invoke vm_start(),
 at this time, cpu_physical_memory_set_dirty_tracking(1) is not called yet,
 so there may have some ram pages not recorded when qemu_savevm_trans_begin
 is called.  I think you need calll
 cpu_physical_memory_set_dirty_tracking(1) in migrate_ft_trans_connect
 function, Am I right?

Thank you for taking a look.
When qemu_savevm_trans_begin is called for the first time, it
calls ram_save_live with stage 1, that sends all pages and sets
dirty tracking, so there won't be missing pages.  Note that
event-tap is turned on by then, meaning no outputs are sent before
finishing the first transaction.  I understand that this
implementation is inefficient, and planning to introduce a new
stage that is almost same as stage 3 but keeps dirty tracking in
the future.

Thanks,

Yoshi


 BR

 Green.


 2011/2/10 Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp

 This code implements VM transaction protocol.  Like buffered_file, it
 sits between savevm and migration layer.  With this architecture, VM
 transaction protocol is implemented mostly independent from other
 existing code.

 Signed-off-by: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
 Signed-off-by: OHMURA Kei ohmura@lab.ntt.co.jp
 ---
  Makefile.objs   |    1 +
  ft_trans_file.c |  624
 +++
  ft_trans_file.h |   72 +++
  migration.c     |    3 +
  trace-events    |   15 ++
  5 files changed, 715 insertions(+), 0 deletions(-)
  create mode 100644 ft_trans_file.c
  create mode 100644 ft_trans_file.h

 diff --git a/Makefile.objs b/Makefile.objs
 index 353b1a8..04148b5 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -100,6 +100,7 @@ common-obj-y += msmouse.o ps2.o
  common-obj-y += qdev.o qdev-properties.o
  common-obj-y += block-migration.o
  common-obj-y += pflib.o
 +common-obj-y += ft_trans_file.o

  common-obj-$(CONFIG_BRLAPI) += baum.o
  common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o
 migration-fd.o
 diff --git a/ft_trans_file.c b/ft_trans_file.c
 new file mode 100644
 index 000..2b42b95
 --- /dev/null
 +++ b/ft_trans_file.c
 @@ -0,0 +1,624 @@
 +/*
 + * Fault tolerant VM transaction QEMUFile
 + *
 + * Copyright (c) 2010 Nippon Telegraph and Telephone Corporation.
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2.  See
 + * the COPYING file in the top-level directory.
 + *
 + * This source code is based on buffered_file.c.
 + * Copyright IBM, Corp. 2008
 + * Authors:
 + *  Anthony Liguori        aligu...@us.ibm.com
 + */
 +
 +#include qemu-common.h
 +#include qemu-error.h
 +#include hw/hw.h
 +#include qemu-timer.h
 +#include sysemu.h
 +#include qemu-char.h
 +#include trace.h
 +#include ft_trans_file.h
 +
 +typedef struct FtTransHdr
 +{
 +    uint16_t cmd;
 +    uint16_t id;
 +    uint32_t seq;
 +    uint32_t payload_len;
 +} FtTransHdr;
 +
 +typedef struct QEMUFileFtTrans
 +{
 +    FtTransPutBufferFunc *put_buffer;
 +    FtTransGetBufferFunc *get_buffer;
 +    FtTransPutReadyFunc *put_ready;
 +    FtTransGetReadyFunc *get_ready;
 +    FtTransWaitForUnfreezeFunc *wait_for_unfreeze;
 +    FtTransCloseFunc *close;
 +    void *opaque;
 +    QEMUFile *file;
 +
 +    enum QEMU_VM_TRANSACTION_STATE state;
 +    uint32_t seq;
 +    uint16_t id;
 +
 +    int has_error;
 +
 +    bool freeze_output;
 +    bool freeze_input;
 +    bool rate_limit;
 +    bool is_sender;
 +    bool is_payload;
 +
 +    uint8_t *buf;
 +    size_t buf_max_size;
 +    size_t put_offset;
 +    size_t get_offset;
 +
 +    FtTransHdr header;
 +    size_t header_offset;
 +} QEMUFileFtTrans;
 +
 +#define IO_BUF_SIZE 32768
 +
 +static void ft_trans_append(QEMUFileFtTrans *s,
 +                            const uint8_t *buf, size_t size)
 +{
 +    if (size  (s-buf_max_size - s-put_offset)) {
 +        trace_ft_trans_realloc(s-buf_max_size, size + 1024);
 +        s-buf_max_size += size + 1024;
 +        s-buf = qemu_realloc(s-buf, s-buf_max_size);
 +    }
 +
 +    trace_ft_trans_append(size);
 +    memcpy(s-buf + s-put_offset, buf, size);
 +    s-put_offset += size;
 +}
 +
 +static void ft_trans_flush(QEMUFileFtTrans *s)
 +{
 +    size_t offset = 0;
 +
 +    if (s-has_error) {
 +        error_report(flush when error %d, bailing, s-has_error);
 +        return;
 +    }
 +
 +    while (offset  s-put_offset) {
 +        ssize_t ret;
 +
 +        ret = s-put_buffer(s-opaque, s-buf + offset, s-put_offset -
 offset);
 +        if (ret == -EAGAIN) {
 +            break;
 +        }
 +
 +        if (ret = 0) {
 +            error_report(error flushing data, %s, strerror(errno));
 +            s-has_error = FT_TRANS_ERR_FLUSH;
 +            break;
 +        } else {
 +            offset +=