[lxc-devel] [lxd/master] lxd/device/disk: Apply limits through post hook

stgraber on Github lxc-bot at linuxcontainers.org
Mon Oct 7 21:14:55 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191007/a04de67b/attachment.bin>
-------------- next part --------------
From e2f18530b7bd634386ca7b039d4b083bec15edd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 7 Oct 2019 16:57:26 -0400
Subject: [PATCH] lxd/device/disk: Apply limits through post hook
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #6277

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/device/disk.go | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/lxd/device/disk.go b/lxd/device/disk.go
index eec1bed125..54157504cd 100644
--- a/lxd/device/disk.go
+++ b/lxd/device/disk.go
@@ -191,13 +191,25 @@ func (d *disk) Start() (*RunConfig, error) {
 
 	runConf := RunConfig{}
 
-	err = d.generateLimits(&runConf)
-	if err != nil {
-		return nil, err
-	}
-
 	isReadOnly := shared.IsTrue(d.config["readonly"])
 
+	// Apply cgroups only after all the mounts have been processed
+	runConf.PostHooks = append(runConf.PostHooks, func() error {
+		runConf := RunConfig{}
+
+		err := d.generateLimits(&runConf)
+		if err != nil {
+			return err
+		}
+
+		err = d.instance.DeviceEventHandler(&runConf)
+		if err != nil {
+			return err
+		}
+
+		return nil
+	})
+
 	// Deal with a rootfs.
 	if shared.IsRootDiskDevice(d.config) {
 		// Set the rootfs path.
@@ -701,8 +713,8 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) {
 		}
 
 		// Set the source path
-		source := shared.HostPath(dev["source"])
-		if source == "" {
+		source := d.getDevicePath()
+		if dev["source"] == "" {
 			source = d.instance.RootfsPath()
 		}
 


More information about the lxc-devel mailing list