The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3644

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 7dcf1049334336ed5821437ff8047f233845645f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Tue, 8 Aug 2017 17:05:37 -0400
Subject: [PATCH] Make stateful snapshot restores work again
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/container.go     |  2 +-
 lxd/container_lxc.go |  9 +++++++--
 lxd/container_put.go | 20 +++-----------------
 3 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index ec6c656f3..a601c5270 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -425,7 +425,7 @@ type container interface {
        Unfreeze() error
 
        // Snapshots & migration
-       Restore(sourceContainer container) error
+       Restore(sourceContainer container, stateful bool) error
        /* actionScript here is a script called action.sh in the stateDir, to
         * be passed to CRIU as --action-script
         */
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index f0bc405b6..62356543d 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2655,7 +2655,7 @@ func (c *containerLXC) Snapshots() ([]container, error) {
        return containers, nil
 }
 
-func (c *containerLXC) Restore(sourceContainer container) error {
+func (c *containerLXC) Restore(sourceContainer container, stateful bool) error 
{
        var ctxMap log.Ctx
 
        // Initialize storage interface for the container.
@@ -2749,8 +2749,13 @@ func (c *containerLXC) Restore(sourceContainer 
container) error {
 
        // If the container wasn't running but was stateful, should we restore
        // it as running?
-       if shared.PathExists(c.StatePath()) {
+       if stateful == true {
+               if !shared.PathExists(c.StatePath()) {
+                       return fmt.Errorf("Stateful snapshot restore requested 
by snapshot is stateless")
+               }
+
                logger.Debug("Performing stateful restore", ctxMap)
+               c.stateful = true
                err := c.Migrate(lxc.MIGRATE_RESTORE, c.StatePath(), 
"snapshot", false, false)
                if err != nil {
                        return err
diff --git a/lxd/container_put.go b/lxd/container_put.go
index 29ae21db2..5ad47c6b5 100644
--- a/lxd/container_put.go
+++ b/lxd/container_put.go
@@ -10,10 +10,7 @@ import (
 
        "github.com/lxc/lxd/shared"
        "github.com/lxc/lxd/shared/api"
-       "github.com/lxc/lxd/shared/logger"
        "github.com/lxc/lxd/shared/osarch"
-
-       log "gopkg.in/inconshreveable/log15.v2"
 )
 
 /*
@@ -69,7 +66,7 @@ func containerPut(d *Daemon, r *http.Request) Response {
        } else {
                // Snapshot Restore
                do = func(op *operation) error {
-                       return containerSnapRestore(d, name, configRaw.Restore)
+                       return containerSnapRestore(d, name, configRaw.Restore, 
configRaw.Stateful)
                }
        }
 
@@ -84,25 +81,14 @@ func containerPut(d *Daemon, r *http.Request) Response {
        return OperationResponse(op)
 }
 
-func containerSnapRestore(d *Daemon, name string, snap string) error {
+func containerSnapRestore(d *Daemon, name string, snap string, stateful bool) 
error {
        // normalize snapshot name
        if !shared.IsSnapshot(snap) {
                snap = name + shared.SnapshotDelimiter + snap
        }
 
-       logger.Info(
-               "RESTORE => Restoring snapshot",
-               log.Ctx{
-                       "snapshot":  snap,
-                       "container": name})
-
        c, err := containerLoadByName(d, name)
        if err != nil {
-               logger.Error(
-                       "RESTORE => loadcontainerLXD() failed",
-                       log.Ctx{
-                               "container": name,
-                               "err":       err})
                return err
        }
 
@@ -116,7 +102,7 @@ func containerSnapRestore(d *Daemon, name string, snap 
string) error {
                }
        }
 
-       err = c.Restore(source)
+       err = c.Restore(source, stateful)
        if err != nil {
                return err
        }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to