[lxc-devel] [lxd/master] lxd/storage: Fix custom volume with underscores

stgraber on Github lxc-bot at linuxcontainers.org
Mon Nov 4 00:37:28 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 908 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191103/241f85c7/attachment.bin>
-------------- next part --------------
From a7e28cb25a40116e30c832fee3b22ee3768bce99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sun, 3 Nov 2019 19:32:45 -0500
Subject: [PATCH] lxd/storage: Fix custom volume with underscores
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The recently added project logic in the volume code incorrectly assumes
that underscores are only valid as separate between project names and
volume names.

This isn't true for custom volumes which may already have undercores in
their names despite us not having support for custom volumes in projects.

When we do implement custom volumes in projects, we will rename all
volumes to include the project prefix at which point we will be able to
always split those and extract the project. Until then, only do project
splitting on containers.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/load.go | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/load.go b/lxd/storage/load.go
index 725a0bf2b7..4cb903baff 100644
--- a/lxd/storage/load.go
+++ b/lxd/storage/load.go
@@ -34,10 +34,12 @@ func volIDFuncMake(state *state.State, poolID int64) func(volType drivers.Volume
 		// encoding format, so if there is no underscore in the volume name then we assume
 		// the project is default.
 		project := "default"
-		volParts := strings.SplitN(volName, "_", 2)
-		if len(volParts) > 1 {
-			project = volParts[0]
-			volName = volParts[1]
+		if volType == drivers.VolumeTypeContainer || volType == drivers.VolumeTypeVM {
+			volParts := strings.SplitN(volName, "_", 2)
+			if len(volParts) > 1 {
+				project = volParts[0]
+				volName = volParts[1]
+			}
 		}
 
 		volID, _, err := state.Cluster.StoragePoolNodeVolumeGetTypeByProject(project, volName, volTypeID, poolID)


More information about the lxc-devel mailing list