qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: agraf@suse.de, stefanb@linux.vnet.ibm.com, quintela@redhat.com,
	mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
	aliguori@amazon.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [RFC PATCH v2 15/16] Wire in BER visitors
Date: Wed, 7 May 2014 11:08:03 +0100	[thread overview]
Message-ID: <20140507100801.GB2644@work-vm> (raw)
In-Reply-To: <20140507100226.GC12259@redhat.com>

* Michael S. Tsirkin (mst@redhat.com) wrote:
> On Wed, Apr 23, 2014 at 05:37:48PM +0100, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > BER output visitor to be selected with env
> > BER input visitor recognized by file header
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> >  include/migration/migration.h |   2 +
> >  savevm.c                      | 105 +++++++++++++++++++++++++++++++-----------
> >  2 files changed, 80 insertions(+), 27 deletions(-)
> > 
> > diff --git a/include/migration/migration.h b/include/migration/migration.h
> > index 8111125..5d500ec 100644
> > --- a/include/migration/migration.h
> > +++ b/include/migration/migration.h
> > @@ -27,6 +27,8 @@
> >  #define QEMU_VM_FILE_VERSION_COMPAT  0x00000002
> >  #define QEMU_VM_FILE_VERSION         0x00000003
> >  
> > +#define QEMU_VM_BER_FILE_MAGIC       0x7fcdc551
> > +
> 
> Where does this come from? I presume this matches
> something in BER format?

See ber.h, this corresponds to an Application class tag with
the BER_TYPE_QEMU_FILE; from ber.h:

    BER_TYPE_QEMU_FILE = 1270481, /* come out as 7f cd c5 51  - the 51 is Q
                                   * the c5 and cd being E,M but with the top
                                   * bit set which BER requires.

I'll add a comment pointing to that.

Dave

> 
> >  #define QEMU_VM_EOF                  0x00
> >  #define QEMU_VM_SECTION_START        0x01
> >  #define QEMU_VM_SECTION_PART         0x02
> > diff --git a/savevm.c b/savevm.c
> > index 515dd77..2bbbcdc 100644
> > --- a/savevm.c
> > +++ b/savevm.c
> > @@ -24,6 +24,8 @@
> >  
> >  #include "config-host.h"
> >  #include "qemu-common.h"
> > +#include "qapi/qemu-file-ber-output-visitor.h"
> > +#include "qapi/qemu-file-ber-input-visitor.h"
> >  #include "qapi/qemu-file-binary-input-visitor.h"
> >  #include "qapi/qemu-file-binary-output-visitor.h"
> >  #include "hw/hw.h"
> > @@ -527,6 +529,34 @@ bool qemu_savevm_state_blocked(Error **errp)
> >      return false;
> >  }
> >  
> > +/* Return a visitor for use on the QEMUFile; visit_destroy should be
> > + * called on it to clean it up.
> > + */
> > +static Visitor *qemu_savevm_get_visitor(QEMUFile *f)
> > +{
> > +    char *formatvar = getenv("QEMUMIGFORMAT");
> > +
> > +    if (formatvar && (!strcmp(formatvar, "BER"))) {
> > +        QemuFileBEROutputVisitor *qfberov = qemu_file_ber_output_visitor_new(f);
> > +        Visitor *v = qemu_file_ber_output_get_visitor(qfberov);
> > +
> > +        qemu_file_set_tmp_visitor(f, v);
> > +        return v;
> > +    }
> > +
> > +    if (formatvar) {
> > +        error_report("QEMUMIGFORMAT set to unknown value '%s'", formatvar);
> > +        assert(0);
> > +    }
> > +
> > +    QemuFileBinOutputVisitor *qfbov = qemu_file_bin_output_visitor_new(f);
> > +    Visitor *v = qemu_file_bin_output_get_visitor(qfbov);
> > +
> > +    qemu_file_set_tmp_visitor(f, v);
> > +
> > +    return v;
> > +}
> > +
> >  void qemu_savevm_state_begin(QEMUFile *f,
> >                               const MigrationParams *params)
> >  {
> > @@ -534,10 +564,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
> >      int ret;
> >      Error *local_err = NULL;
> >      SectionHeader sh;
> > -
> > -    QemuFileBinOutputVisitor *qfbov = qemu_file_bin_output_visitor_new(f);
> > -    Visitor *v = qemu_file_bin_output_get_visitor(qfbov);
> > -    qemu_file_set_tmp_visitor(f, v);
> > +    Visitor *v = qemu_savevm_get_visitor(f);
> >  
> >      trace_savevm_state_begin();
> >      QTAILQ_FOREACH(se, &savevm_handlers, entry) {
> > @@ -789,13 +816,11 @@ static int qemu_savevm_state(QEMUFile *f)
> >  
> >  static int qemu_save_device_state(QEMUFile *f)
> >  {
> > +    Visitor *v = qemu_savevm_get_visitor(f);
> >      SaveStateEntry *se;
> >      Error *local_err;
> >      SectionHeader sh;
> >  
> > -    QemuFileBinOutputVisitor *qfbov = qemu_file_bin_output_visitor_new(f);
> > -    qemu_file_set_tmp_visitor(f, qemu_file_bin_output_get_visitor(qfbov));
> > -    Visitor *v = qemu_file_bin_output_get_visitor(qfbov);
> >      int32_t section_type;
> >  
> >      cpu_synchronize_all_states();
> > @@ -861,41 +886,65 @@ typedef struct LoadStateEntry {
> >      int version_id;
> >  } LoadStateEntry;
> >  
> > +/* Given a just opened input QEMUFile, peak at the header and figure
> > + * out which visitor should be used for it.
> > + * Return the visitor ready for use.
> > + */
> > +static Visitor *pick_input_visitor(QEMUFile *f)
> > +{
> > +    uint32_t tmp32;
> > +
> > +    if (qemu_peek_buffer(f, (uint8_t *)&tmp32, 4, 0) != 4) {
> > +        fprintf(stderr, "Failed to read SaveVM header word\n");
> > +        return NULL;
> > +    }
> > +
> > +    tmp32 = be32_to_cpu(tmp32);
> > +
> > +    switch (tmp32) {
> > +    case QEMU_VM_FILE_MAGIC: {
> > +        QemuFileBinInputVisitor *qfbiv = qemu_file_bin_input_visitor_new(f);
> > +        Visitor *v = qemu_file_bin_input_get_visitor(qfbiv);
> > +        qemu_file_set_tmp_visitor(f, v);
> > +
> > +        return v;
> > +        }
> > +
> > +    case QEMU_VM_BER_FILE_MAGIC: {
> > +        QemuFileBERInputVisitor *qfberiv = qemu_file_ber_input_visitor_new(f);
> > +        Visitor *v = qemu_file_ber_input_get_visitor(qfberiv);
> > +        qemu_file_set_tmp_visitor(f, v);
> > +
> > +        return v;
> > +        }
> > +
> > +    default:
> > +        fprintf(stderr, "Invalid SaveVM header (0x%x)\n", tmp32);
> > +        return NULL;
> > +    }
> > +}
> > +
> >  int qemu_loadvm_state(QEMUFile *f)
> >  {
> >      QLIST_HEAD(, LoadStateEntry) loadvm_handlers =
> >          QLIST_HEAD_INITIALIZER(loadvm_handlers);
> >      LoadStateEntry *le, *new_le;
> > +    Visitor *v;
> >      Error *local_err = NULL;
> >      int32_t section_type;
> > -    unsigned int tmp;
> >      int ret;
> >  
> >      if (qemu_savevm_state_blocked(NULL)) {
> >          return -EINVAL;
> >      }
> >  
> > -    tmp = qemu_get_be32(f);
> > -    if (tmp != QEMU_VM_FILE_MAGIC) {
> > -        return -EINVAL;
> > -    }
> > -
> > -    tmp = qemu_get_be32(f);
> > -    if (tmp == QEMU_VM_FILE_VERSION_COMPAT) {
> > -        error_report("SaveVM v2 format is obsolete and don't work anymore");
> > +    v = pick_input_visitor(f);
> > +    if (!v) {
> >          return -ENOTSUP;
> >      }
> > -    if (tmp != QEMU_VM_FILE_VERSION) {
> > -        return -ENOTSUP;
> > -    }
> > -
> > -    /* TODO: Here we should be able to figure out if it's a binary file
> > -     * or what and open the right type of visitor
> > -     */
> > -    QemuFileBinInputVisitor *qfbiv = qemu_file_bin_input_visitor_new(f);
> > -    Visitor *v = qemu_file_bin_input_get_visitor(qfbiv);
> > -    qemu_file_set_tmp_visitor(f, v);
> >  
> > +    visit_start_sequence_compat(v, "file", VISIT_SEQ_COMPAT_FILE, NULL,
> > +                                &local_err);
> >      visit_start_sequence_compat(v, "top", VISIT_SEQ_COMPAT_BYTE0TERM,
> >                                  NULL, &local_err);
> >      while (visit_get_next_type(v, &section_type, NULL, "section", &local_err),
> > @@ -912,6 +961,7 @@ int qemu_loadvm_state(QEMUFile *f)
> >                        "secstart" : "secfull",
> >                    VISIT_SEQ_COMPAT_SECTION_HEADER, &sh, &local_err);
> >              if (local_err) {
> > +                error_report("%s", error_get_pretty(local_err));
> >                  ret = -EINVAL;
> >                  goto out;
> >              }
> > @@ -1001,6 +1051,7 @@ out:
> >      }
> >  
> >      visit_end_sequence_compat(v, "top", VISIT_SEQ_COMPAT_BYTE0TERM, &local_err);
> > +    visit_end_sequence_compat(v, "file", VISIT_SEQ_COMPAT_FILE, &local_err);
> >      if (local_err) {
> >          error_report("%s", error_get_pretty(local_err));
> >          ret = -EINVAL;
> > @@ -1010,7 +1061,7 @@ out:
> >          ret = qemu_file_get_error(f);
> >      }
> >  
> > -    qemu_file_bin_input_visitor_cleanup(qfbiv);
> > +    visit_destroy(v, &local_err);
> >      return ret;
> >  }
> >  
> > -- 
> > 1.9.0
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

      reply	other threads:[~2014-05-07 10:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1398271069-22057-1-git-send-email-dgilbert@redhat.com>
     [not found] ` <1398271069-22057-6-git-send-email-dgilbert@redhat.com>
2014-05-07  9:47   ` [Qemu-devel] [RFC PATCH v2 05/16] Header/constant/types fixes for visitors Michael S. Tsirkin
2014-05-07 10:33     ` Dr. David Alan Gilbert
     [not found] ` <1398271069-22057-2-git-send-email-dgilbert@redhat.com>
2014-05-07  9:50   ` [Qemu-devel] [RFC PATCH v2 01/16] Visitor: Add methods for migration format use Michael S. Tsirkin
2014-05-07 10:23     ` Dr. David Alan Gilbert
2014-05-07 10:32       ` Michael S. Tsirkin
     [not found] ` <5357EF56.4010703@redhat.com>
     [not found]   ` <20140423171622.GG2516@work-vm>
     [not found]     ` <87sip3dvsj.fsf@blackfin.pond.sub.org>
     [not found]       ` <20140424082059.GB2459@work-vm>
     [not found]         ` <20140424082923.GA31845@redhat.com>
     [not found]           ` <87wqeduc0d.fsf@blackfin.pond.sub.org>
2014-05-06 18:58             ` [Qemu-devel] [RFC PATCH v2 00/16] visitor+BER migration format Dr. David Alan Gilbert
2014-05-06 20:26               ` Michael S. Tsirkin
2014-05-07  5:49                 ` Markus Armbruster
2014-05-07  9:22                   ` Dr. David Alan Gilbert
     [not found]     ` <5357FCA9.8040801@redhat.com>
     [not found]       ` <20140423175410.GA28308@redhat.com>
     [not found]         ` <53580D27.2080507@redhat.com>
2014-05-07  9:57           ` Michael S. Tsirkin
     [not found] ` <1398271069-22057-16-git-send-email-dgilbert@redhat.com>
2014-05-07 10:02   ` [Qemu-devel] [RFC PATCH v2 15/16] Wire in BER visitors Michael S. Tsirkin
2014-05-07 10:08     ` Dr. David Alan Gilbert [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=20140507100801.GB2644@work-vm \
    --to=dgilbert@redhat.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=aliguori@amazon.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanb@linux.vnet.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).