[lxc-devel] [lxd/master] Speed up container start a bit
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Jul 8 22:25:50 UTC 2019
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/20190708/0d2ab0a2/attachment.bin>
-------------- next part --------------
From 4f80ef668452a957c72140cdf06473a3482dbc98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 8 Jul 2019 17:59:43 -0400
Subject: [PATCH 1/3] lxd/callhook: Don't call /1.0
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/main_callhook.go | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lxd/main_callhook.go b/lxd/main_callhook.go
index d96998ecb0..e2c7adfb11 100644
--- a/lxd/main_callhook.go
+++ b/lxd/main_callhook.go
@@ -58,7 +58,11 @@ func (c *cmdCallhook) Run(cmd *cobra.Command, args []string) error {
if socket == "" {
socket = filepath.Join(path, "unix.socket")
}
- d, err := lxd.ConnectLXDUnix(socket, nil)
+
+ lxdArgs := lxd.ConnectionArgs{
+ SkipGetServer: true,
+ }
+ d, err := lxd.ConnectLXDUnix(socket, &lxdArgs)
if err != nil {
return err
}
From 1052d153ae8bb6a41f096deb0530db3ae3b35fac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 8 Jul 2019 18:03:36 -0400
Subject: [PATCH 2/3] lxd/containers: Use current binary for early hooks
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/container_lxc.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 43d053e823..0e11eb8af9 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1197,7 +1197,7 @@ func (c *containerLXC) initLXC(config bool) error {
return err
}
- err = lxcSetConfigItem(cc, "lxc.hook.pre-start", fmt.Sprintf("%s callhook %s %d start", c.state.OS.ExecPath, shared.VarPath(""), c.id))
+ err = lxcSetConfigItem(cc, "lxc.hook.pre-start", fmt.Sprintf("/proc/%d/exe callhook %s %d start", os.Getpid(), shared.VarPath(""), c.id))
if err != nil {
return err
}
@@ -1689,7 +1689,7 @@ func (c *containerLXC) initLXC(config bool) error {
// Run network up hook for bridged and p2p nics.
if shared.StringInSlice(m["nictype"], []string{"bridged", "p2p"}) {
- err = lxcSetConfigItem(cc, fmt.Sprintf("%s.%d.script.up", networkKeyPrefix, networkidx), fmt.Sprintf("%s callhook %s %d network-up %s", c.state.OS.ExecPath, shared.VarPath(""), c.id, k))
+ err = lxcSetConfigItem(cc, fmt.Sprintf("%s.%d.script.up", networkKeyPrefix, networkidx), fmt.Sprintf("/proc/%d/exe callhook %s %d network-up %s", os.Getpid(), shared.VarPath(""), c.id, k))
if err != nil {
return err
}
From 51bd2da2f96cf99b91c3fd47fb58631d2cc2665b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 8 Jul 2019 18:24:33 -0400
Subject: [PATCH 3/3] lxd/containers: Speed up startCommon a bit
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/container_lxc.go | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 0e11eb8af9..dd4faed75c 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2109,6 +2109,8 @@ func UnshiftBtrfsRootfs(path string, diskIdmap *idmap.IdmapSet) error {
// Start functions
func (c *containerLXC) startCommon() (string, error) {
+ var ourStart bool
+
// Load the go-lxc struct
err := c.initLXC(true)
if err != nil {
@@ -2174,7 +2176,6 @@ func (c *containerLXC) startCommon() (string, error) {
}
}
- var ourStart bool
newSize, ok := c.LocalConfig()["volatile.apply_quota"]
if ok {
err := c.initStorage()
@@ -2629,15 +2630,11 @@ func (c *containerLXC) startCommon() (string, error) {
return "", err
}
+ // If starting stateless, wipe state
if !c.IsStateful() && shared.PathExists(c.StatePath()) {
os.RemoveAll(c.StatePath())
}
- _, err = c.StorageStop()
- if err != nil {
- return "", err
- }
-
// Update time container was last started
err = c.state.Cluster.ContainerLastUsedUpdate(c.id, time.Now().UTC())
if err != nil {
More information about the lxc-devel
mailing list