[lxc-devel] [lxd/master] Bugfixes
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Dec 8 10:32:16 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161208/f9292670/attachment.bin>
-------------- next part --------------
From 70e9034cc9159a7f486caed81b0f6bfd9e55d3c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 8 Dec 2016 10:26:44 +0100
Subject: [PATCH 1/3] Make it easier to grep for the backup functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/api_internal.go | 6 +++---
lxd/container.go | 4 ++--
lxd/container_lxc.go | 16 ++++++++--------
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index 11ca5aa..6723535 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -100,13 +100,13 @@ var internalReadyCmd = Command{name: "ready", put: internalReady, get: internalW
var internalContainerOnStartCmd = Command{name: "containers/{id}/onstart", get: internalContainerOnStart}
var internalContainerOnStopCmd = Command{name: "containers/{id}/onstop", get: internalContainerOnStop}
-func slurpSlurpFile(path string) (*slurpFile, error) {
+func slurpBackupFile(path string) (*backupFile, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
- sf := slurpFile{}
+ sf := backupFile{}
if err := yaml.Unmarshal(data, &sf); err != nil {
return nil, err
@@ -129,7 +129,7 @@ func internalImport(d *Daemon, r *http.Request) Response {
defer d.Storage.ContainerStop(name, path)
- sf, err := slurpSlurpFile(shared.VarPath("containers", name, "backup.yaml"))
+ sf, err := slurpBackupFile(shared.VarPath("containers", name, "backup.yaml"))
if err != nil {
return SmartError(err)
}
diff --git a/lxd/container.go b/lxd/container.go
index 373b1bd..fdd3223 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -566,7 +566,7 @@ func containerCreateAsSnapshot(d *Daemon, args containerArgs, sourceContainer co
return nil, err
}
- err = writeSlurpFile(sourceContainer)
+ err = writeBackupFile(sourceContainer)
if err != nil {
c.Delete()
return nil, err
@@ -694,7 +694,7 @@ func containerConfigureInternal(c container) error {
break
}
- err := writeSlurpFile(c)
+ err := writeBackupFile(c)
if err != nil {
return err
}
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index e13e43d..cac6b4b 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2511,10 +2511,10 @@ func (c *containerLXC) Restore(sourceContainer container) error {
return err
}
- // The old slurp file may be out of date (e.g. it doesn't have all the
+ // The old backup file may be out of date (e.g. it doesn't have all the
// current snapshots of the container listed); let's write a new one to
// be safe.
- err = writeSlurpFile(c)
+ err = writeBackupFile(c)
if err != nil {
return err
}
@@ -2746,13 +2746,13 @@ func (c *containerLXC) ConfigKeySet(key string, value string) error {
return c.Update(args, false)
}
-type slurpFile struct {
+type backupFile struct {
Container *shared.ContainerInfo `yaml:"container"`
Snapshots []*shared.SnapshotInfo `yaml:"snapshots"`
}
-func writeSlurpFile(c container) error {
- /* we only write slurp files out for actual containers */
+func writeBackupFile(c container) error {
+ /* we only write backup files out for actual containers */
if c.IsSnapshot() {
return nil
}
@@ -2778,7 +2778,7 @@ func writeSlurpFile(c container) error {
sis = append(sis, si.(*shared.SnapshotInfo))
}
- data, err := yaml.Marshal(&slurpFile{
+ data, err := yaml.Marshal(&backupFile{
Container: ci.(*shared.ContainerInfo),
Snapshots: sis,
})
@@ -3555,9 +3555,9 @@ func (c *containerLXC) Update(args containerArgs, userRequested bool) error {
/* we can call Update in some cases when the directory doesn't exist
* yet before container creation; this is okay, because at the end of
- * container creation we write the slurp file, so let's not worry about
+ * container creation we write the backup file, so let's not worry about
* ENOENT. */
- if err := writeSlurpFile(c); err != nil && !os.IsNotExist(err) {
+ if err := writeBackupFile(c); err != nil && !os.IsNotExist(err) {
return err
}
From b5864b712071f884350e2651b6ca757d2b2e6b92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 8 Dec 2016 10:50:42 +0100
Subject: [PATCH 2/3] Don't write backup.yaml if container isn't mounted
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #2691
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/container_lxc.go | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index cac6b4b..40f8c3f 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1789,6 +1789,23 @@ func (c *containerLXC) startCommon() (string, error) {
return "", err
}
+ // Update the backup.yaml file (as storage is guaranteed to be mountable now)
+ err = c.StorageStart()
+ if err != nil {
+ return "", err
+ }
+
+ err = writeBackupFile(c)
+ if err != nil {
+ c.StorageStop()
+ return "", err
+ }
+
+ err = c.StorageStop()
+ if err != nil {
+ return "", err
+ }
+
// Update time container was last started
err = dbContainerLastUsedUpdate(c.daemon.db, c.id, time.Now().UTC())
if err != nil {
@@ -2757,6 +2774,17 @@ func writeBackupFile(c container) error {
return nil
}
+ /* immediately return if the container directory doesn't exist yet */
+ if !shared.PathExists(c.Path()) {
+ return os.ErrNotExist
+ }
+
+ /* deal with the container occasionaly not being monuted */
+ if !shared.PathExists(c.RootfsPath()) {
+ shared.LogWarn("Unable to update backup.yaml at this time.", log.Ctx{"name": c.Name()})
+ return nil
+ }
+
ci, _, err := c.Render()
if err != nil {
return err
From 55ece48b6a5f0419a352669b4ca09ea5c9ad68e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 8 Dec 2016 11:31:07 +0100
Subject: [PATCH 3/3] Don't record last_state.power twice
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Saves us from a full Update() run for every container at every daemon startup.
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/containers.go | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/lxd/containers.go b/lxd/containers.go
index a002c8e..46b74b1 100644
--- a/lxd/containers.go
+++ b/lxd/containers.go
@@ -128,19 +128,6 @@ func containersRestart(d *Daemon) error {
}
}
- // Reset the recorded state (to ensure it's up to date)
- _, err = dbExec(d.db, "DELETE FROM containers_config WHERE key='volatile.last_state.power'")
- if err != nil {
- return err
- }
-
- for _, c := range containers {
- err = c.ConfigKeySet("volatile.last_state.power", c.State())
- if err != nil {
- return err
- }
- }
-
return nil
}
More information about the lxc-devel
mailing list