xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Wei Liu <wei.liu2@citrix.com>, Andrew Jones <drjones@redhat.com>,
	Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@linaro.org>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Olaf Hering <olaf@aepfle.de>, Tim Deegan <tim@xen.org>,
	David Vrabel <david.vrabel@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	xen-devel@lists.xenproject.org,
	Daniel De Graaf <dgdegra@tycho.nsa.gov>
Subject: Re: [PATCH v9 11/11] (lib)xl: soft reset support
Date: Thu, 16 Jul 2015 14:51:01 -0400	[thread overview]
Message-ID: <20150716185101.GJ14309@x230.dumpdata.com> (raw)
In-Reply-To: <1437064046-12174-12-git-send-email-vkuznets@redhat.com>

> diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5
> index 3489b27..caed758 100644
> --- a/docs/man/xl.cfg.pod.5
> +++ b/docs/man/xl.cfg.pod.5
> @@ -346,6 +346,11 @@ destroy the domain.
>  write a "coredump" of the domain to F</var/lib/xen/dump/NAME> and then
>  restart the domain.
>  
> +=item B<soft-reset>
> +
> +reset all Xen specific interfaces for the Xen-aware HVM domain allowing

s/reset/Reset/
> +it to reastablish these interfaces and continue executing the domain.
> +
>  =back
>  
>  The default for C<on_poweroff> is C<destroy>.
> @@ -367,7 +372,7 @@ Action to take if the domain crashes.  Default is C<destroy>.
>  =item B<on_soft_reset="ACTION">
>  
>  Action to take if the domain performs 'soft reset' (e.g. does kexec).
> -Default is C<restart>.
> +Default is C<soft-reset>.
>  
>  =back
>  

.. snip..
> @@ -518,13 +515,17 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
>          goto out;
>      }
>  
> -    ret = xc_domain_create_config(ctx->xch, info->ssidref,
> -                                  handle, flags, domid,
> -                                  xc_config);
> -    if (ret < 0) {
> -        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "domain creation fail");
> -        rc = ERROR_FAIL;
> -        goto out;
> +    /* Valid domid here means we're soft resetting */

Missing full stop.
> +    if (!libxl_domid_valid_guest(*domid)) {
> +        ret = xc_domain_create_config(ctx->xch, info->ssidref,
> +                                      handle, flags, domid,
> +                                      xc_config);
> +        if (ret < 0) {
> +            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
> +                             "domain creation fail");
> +            rc = ERROR_FAIL;
> +            goto out;
> +        }
>      }
>  
>      rc = libxl__arch_domain_save_config(gc, d_config, xc_config);
> @@ -734,9 +735,8 @@ static void initiate_domain_create(libxl__egc *egc,
>      libxl_domain_config *const d_config = dcs->guest_config;
>      libxl__domain_build_state *const state = &dcs->build_state;
>      const int restore_fd = dcs->restore_fd;
> -    memset(&dcs->build_state, 0, sizeof(dcs->build_state));
>  
> -    domid = 0;
> +    domid = dcs->domid_soft_reset;
>  
>      if (d_config->c_info.ssid_label) {
>          char *s = d_config->c_info.ssid_label;
> @@ -884,7 +884,7 @@ static void initiate_domain_create(libxl__egc *egc,
>              d_config->nics[i].devid = ++last_devid;
>      }
>  
> -    if (restore_fd >= 0) {
> +    if (restore_fd >= 0 || dcs->domid_soft_reset != INVALID_DOMID) {
>          LOG(DEBUG, "restoring, not running bootloader");
>          domcreate_bootloader_done(egc, &dcs->bl, 0);
>      } else  {
> @@ -958,7 +958,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
>      dcs->dmss.dm.callback = domcreate_devmodel_started;
>      dcs->dmss.callback = domcreate_devmodel_started;
>  
> -    if ( restore_fd < 0 ) {
> +    if ( restore_fd < 0 && dcs->domid_soft_reset == INVALID_DOMID) {
>          rc = libxl__domain_build(gc, d_config, domid, state);
>          domcreate_rebuild_done(egc, dcs, rc);
>          return;
> @@ -988,9 +988,11 @@ static void domcreate_bootloader_done(libxl__egc *egc,
>          rc = ERROR_INVAL;
>          goto out;
>      }
> -    libxl__xc_domain_restore(egc, dcs,
> -                             hvm, pae, superpages);
> -    return;
> +    if ( restore_fd >= 0 ) {
> +        libxl__xc_domain_restore(egc, dcs,
> +                                 hvm, pae, superpages);
> +        return;
> +    }
>  
>   out:
>      libxl__xc_domain_restore_done(egc, dcs, rc, 0, 0);
> @@ -1074,8 +1076,12 @@ void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,
>          goto out;
>  
>      if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
> -        state->saved_state = GCSPRINTF(
> -                       XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
> +        if (fd != -1)
> +            state->saved_state = GCSPRINTF(
> +                XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
> +        else
> +            state->saved_state = GCSPRINTF(
> +                XC_DEVICE_MODEL_SAVE_FILE".%d", domid);
>      }
>  
>  out:
> @@ -1084,9 +1090,12 @@ out:
>          libxl__file_reference_unmap(&state->pv_ramdisk);
>      }
>  
> -    esave = errno;
> -    libxl_fd_set_nonblock(ctx, fd, 0);
> -    errno = esave;
> +    /* fd == -1 here means we're doing soft reset */

Missing full stop.

> +    if (fd != -1) {
> +        esave = errno;
> +        libxl_fd_set_nonblock(ctx, fd, 0);
> +        errno = esave;
> +    }
>      domcreate_rebuild_done(egc, dcs, ret);
>  }
>  
> @@ -1507,6 +1516,14 @@ typedef struct {
>      uint32_t *domid_out;
>  } libxl__app_domain_create_state;
>  
> +typedef struct {
> +    libxl__app_domain_create_state cdcs;
> +    libxl__domain_destroy_state dds;
> +    libxl__domain_suspend_state dss;
> +    uint8_t *toolstack_buf;
> +    uint32_t toolstack_len;
> +} libxl__domain_soft_reset_state;
> +
>  static void domain_create_cb(libxl__egc *egc,
>                               libxl__domain_create_state *dcs,
>                               int rc, uint32_t domid);
> @@ -1528,6 +1545,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
>      cdcs->dcs.restore_fd = restore_fd;
>      cdcs->dcs.callback = domain_create_cb;
>      cdcs->dcs.checkpointed_stream = checkpointed_stream;
> +    cdcs->dcs.domid_soft_reset = INVALID_DOMID;
>      libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
>      cdcs->domid_out = domid;
>  
> @@ -1536,6 +1554,122 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
>      return AO_INPROGRESS;
>  }
>  
> +static void domain_soft_reset_cb(libxl__egc *egc,
> +                                 libxl__domain_destroy_state *dds,
> +                                 int rc)
> +{
> +    STATE_AO_GC(dds->ao);
> +    libxl__domain_soft_reset_state *srs = CONTAINER_OF(dds, *srs, dds);
> +    libxl__app_domain_create_state *cdcs = &srs->cdcs;
> +
> +    if (rc) {
> +        LOG(ERROR, "destruction of domain %u failed", dds->domid);

s/failed/failed!/ or s/failed/failed./

> +        goto error;
> +    }
> +
> +    rc = libxl__toolstack_restore(cdcs->dcs.domid_soft_reset,
> +                                  srs->toolstack_buf,
> +                                  srs->toolstack_len,
> +                                  &cdcs->dcs.shs);
> +    if (rc) {
> +        LOG(ERROR, "failed to restore toolstack record");

I bet you know what I am going to say here :-)

> +        goto error;
> +    }
> +
> +    initiate_domain_create(egc, &cdcs->dcs);
> +    return;
> +
> +error:
> +    domcreate_complete(egc, &cdcs->dcs, rc);
> +}
> +
> +static int do_domain_soft_reset(libxl_ctx *ctx,
> +                                libxl_domain_config *d_config,
> +                                uint32_t domid_soft_reset,
> +                                const libxl_asyncop_how *ao_how,
> +                                const libxl_asyncprogress_how
> +                                *aop_console_how)
> +{
> +    AO_CREATE(ctx, 0, ao_how);
> +    libxl__domain_soft_reset_state *srs;
> +    libxl__app_domain_create_state *cdcs;
> +    libxl__domain_create_state *dcs;
> +    libxl__domain_build_state *state;
> +    libxl__domain_suspend_state *dss;
> +    char *dom_path, *xs_store_mfn, *xs_console_mfn;
> +    uint32_t domid_out;
> +    int rc;
> +
> +    GCNEW(srs);
> +    cdcs = &srs->cdcs;
> +    dcs = &cdcs->dcs;
> +    state = &dcs->build_state;
> +    dss = &srs->dss;
> +
> +    srs->cdcs.dcs.ao = ao;
> +    srs->cdcs.dcs.guest_config = d_config;
> +    libxl_domain_config_init(&srs->cdcs.dcs.guest_config_saved);
> +    libxl_domain_config_copy(ctx, &srs->cdcs.dcs.guest_config_saved,
> +                             d_config);
> +    cdcs->dcs.restore_fd = -1;
> +    cdcs->dcs.domid_soft_reset = domid_soft_reset;
> +    cdcs->dcs.callback = domain_create_cb;
> +    libxl__ao_progress_gethow(&srs->cdcs.dcs.aop_console_how,
> +                              aop_console_how);
> +    cdcs->domid_out = &domid_out;
> +
> +    dom_path = libxl__xs_get_dompath(gc, domid_soft_reset);
> +    if (!dom_path) {
> +        LOG(ERROR, "failed to read domain path");
> +        return AO_CREATE_FAIL(ERROR_FAIL);
> +    }
> +
> +    xs_store_mfn = xs_read(ctx->xsh, XBT_NULL,
> +                           GCSPRINTF("%s/store/ring-ref", dom_path),
> +                           NULL);
> +    state->store_mfn = xs_store_mfn ? atol(xs_store_mfn): 0;
> +    free(xs_store_mfn);
> +
> +    xs_console_mfn = xs_read(ctx->xsh, XBT_NULL,
> +                             GCSPRINTF("%s/console/ring-ref", dom_path),
> +                             NULL);
> +    state->console_mfn = xs_console_mfn ? atol(xs_console_mfn): 0;
> +    free(xs_console_mfn);
> +
> +    dss->ao = ao;
> +    dss->domid = domid_soft_reset;
> +    dss->dm_savefile = GCSPRINTF(XC_DEVICE_MODEL_SAVE_FILE".%d",
> +                                 domid_soft_reset);
> +
> +    rc = libxl__toolstack_save(domid_soft_reset, &srs->toolstack_buf,
> +                               &srs->toolstack_len, dss);
> +    if (rc) {
> +        LOG(ERROR, "failed to save toolstack record");

Here.
> +        return AO_CREATE_FAIL(ERROR_FAIL);
> +    }
> +
> +    rc = libxl__domain_suspend_device_model(gc, dss);
> +    if (rc) {
> +        LOG(ERROR, "failed to suspend device model");

Ditto
> +        return AO_CREATE_FAIL(ERROR_FAIL);
> +    }
> +
> +    /*
> +     * On the domain creation path it will be introduced to xenstore

What is 'it'?

> +     * with (probably) different store/console channels so we need to
> +     * release it here.

I think what you mean is that:
On the domain creation path the store/console channels will be
introduced which will probably different so we need to release
the old ones here.
?

> +     */
> +    xs_release_domain(ctx->xsh, cdcs->dcs.domid_soft_reset);
> +
> +    srs->dds.ao = ao;
> +    srs->dds.domid = domid_soft_reset;
> +    srs->dds.callback = domain_soft_reset_cb;
> +    srs->dds.soft_reset = true;
> +    libxl__domain_destroy(egc, &srs->dds);
> +
> +    return AO_INPROGRESS;
> +}
> +

.. snip..
> @@ -2775,7 +2783,13 @@ start:
>           * restore/migrate-receive it again.
>           */
>          restoring = 0;
> -    }else{
> +    } else if ( domid_soft_reset != INVALID_DOMID ) {
> +        /* Do soft reset */

Full stop missing.
> +        ret = libxl_domain_soft_reset(ctx, &d_config, domid_soft_reset,
> +                                      0, autoconnect_console_how);
> +        domid = domid_soft_reset;
> +        domid_soft_reset = INVALID_DOMID;
> +    } else {
>          ret = libxl_domain_create_new(ctx, &d_config, &domid,
>                                        0, autoconnect_console_how);
>      }
> @@ -2839,8 +2853,13 @@ start:
>                  event->u.domain_shutdown.shutdown_reason,
>                  event->u.domain_shutdown.shutdown_reason);
>              switch (handle_domain_death(&domid, event, &d_config)) {
> +            case DOMAIN_RESTART_SOFT_RESET:
> +                domid_soft_reset = domid;
> +                domid = INVALID_DOMID;
> +                /* fall through */
>              case DOMAIN_RESTART_RENAME:
> -                if (!preserve_domain(&domid, event, &d_config)) {
> +                if (domid_soft_reset == INVALID_DOMID &&
> +                    !preserve_domain(&domid, event, &d_config)) {
>                      /* If we fail then exit leaving the old domain in place. */
>                      ret = -1;
>                      goto out;
> -- 
> 2.4.3
> 

  reply	other threads:[~2015-07-16 18:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16 16:27 [PATCH v9 00/11] toolstack-assisted approach to PVHVM guest kexec Vitaly Kuznetsov
2015-07-16 16:27 ` [PATCH v9 01/11] xen: introduce SHUTDOWN_soft_reset shutdown reason Vitaly Kuznetsov
2015-07-16 18:42   ` Konrad Rzeszutek Wilk
2015-07-24 11:54   ` Jan Beulich
2015-07-16 16:27 ` [PATCH v9 02/11] libxl: support " Vitaly Kuznetsov
2015-07-16 16:27 ` [PATCH v9 03/11] xl: introduce enum domain_restart_type Vitaly Kuznetsov
2015-07-16 16:27 ` [PATCH v9 04/11] xen: evtchn: make evtchn_reset() ready for soft reset Vitaly Kuznetsov
2015-07-16 18:43   ` Konrad Rzeszutek Wilk
2015-07-24 11:56   ` Jan Beulich
2015-07-16 16:27 ` [PATCH v9 05/11] xen: grant_table: implement grant_table_warn_active_grants() Vitaly Kuznetsov
2015-07-16 18:43   ` Konrad Rzeszutek Wilk
2015-07-24 12:00   ` Jan Beulich
2015-07-16 16:27 ` [PATCH v9 06/11] xen: Introduce XEN_DOMCTL_soft_reset Vitaly Kuznetsov
2015-07-16 18:45   ` Konrad Rzeszutek Wilk
2015-07-17 12:30     ` Vitaly Kuznetsov
2015-07-24 12:03   ` Jan Beulich
2015-07-16 16:27 ` [PATCH v9 07/11] flask: DOMCTL_soft_reset support Vitaly Kuznetsov
2015-07-16 16:27 ` [PATCH v9 08/11] xen: arch-specific hooks for domain_soft_reset() Vitaly Kuznetsov
2015-07-16 18:45   ` Konrad Rzeszutek Wilk
2015-07-24 12:20   ` Jan Beulich
2015-07-24 12:41     ` Vitaly Kuznetsov
2015-07-24 12:45       ` Jan Beulich
2015-07-16 16:27 ` [PATCH v9 09/11] libxc: support XEN_DOMCTL_soft_reset operation Vitaly Kuznetsov
2015-07-16 16:27 ` [PATCH v9 10/11] libxc: add XC_DEVICE_MODEL_SAVE_FILE Vitaly Kuznetsov
2015-07-16 16:27 ` [PATCH v9 11/11] (lib)xl: soft reset support Vitaly Kuznetsov
2015-07-16 18:51   ` Konrad Rzeszutek Wilk [this message]
2015-07-17 12:33     ` Vitaly Kuznetsov

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=20150716185101.GJ14309@x230.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=david.vrabel@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=drjones@redhat.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@linaro.org \
    --cc=keir@xen.org \
    --cc=olaf@aepfle.de \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.org \
    --cc=vkuznets@redhat.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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).