[lxc-devel] [lxd/stable-4.0] Storage: Adds custom content type for mount refcount tracking

tomponline on Github lxc-bot at linuxcontainers.org
Fri Nov 20 10:46:30 UTC 2020


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/20201120/b2d3ffe8/attachment.bin>
-------------- next part --------------
From 7cad91eccb88fc38a221d0bec30adaa2970216f1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 20 Nov 2020 10:44:38 +0000
Subject: [PATCH 1/2] lxd/db/storage/volumes: Adds content type constants and
 populates ContentType field in storagePoolVolumeGetType

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/db/storage_volumes.go | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index 19ba3a3045..16a834c7a6 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -278,6 +278,13 @@ func (c *Cluster) storagePoolVolumeGetType(project string, volumeName string, vo
 	storageVolume.Config = volumeConfig
 	storageVolume.Location = volumeNode
 
+	// Populate volume's ContentType based on volume type (this is before custom block volumes were supported).
+	// The ContentType field is used for volume mount ref counting so important it is consistently populated.
+	storageVolume.ContentType = StoragePoolVolumeContentTypeNameFS
+	if volumeType == StoragePoolVolumeTypeVM {
+		storageVolume.ContentType = StoragePoolVolumeContentTypeNameBlock
+	}
+
 	return volumeID, &storageVolume, nil
 }
 
@@ -523,6 +530,18 @@ const (
 	StoragePoolVolumeTypeNameCustom    string = "custom"
 )
 
+// Content types.
+const (
+	StoragePoolVolumeContentTypeFS = iota
+	StoragePoolVolumeContentTypeBlock
+)
+
+// Content type names.
+const (
+	StoragePoolVolumeContentTypeNameFS    string = "filesystem"
+	StoragePoolVolumeContentTypeNameBlock string = "block"
+)
+
 // StorageVolumeArgs is a value object holding all db-related details about a
 // storage volume.
 type StorageVolumeArgs struct {

From 030ca18bff04fda53b351f8fc1860945345b83e0 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 20 Nov 2020 10:45:12 +0000
Subject: [PATCH 2/2] lxd/storage/backend/lxd: Use volume's ContentType field
 in MountCustomVolume

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/backend_lxd.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index f7040022c1..68948a9211 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -2923,7 +2923,7 @@ func (b *lxdBackend) MountCustomVolume(projectName, volName string, op *operatio
 
 	// Get the volume name on storage.
 	volStorageName := project.StorageVolume(projectName, volName)
-	vol := b.newVolume(drivers.VolumeTypeCustom, drivers.ContentTypeFS, volStorageName, volume.Config)
+	vol := b.newVolume(drivers.VolumeTypeCustom, drivers.ContentType(volume.ContentType), volStorageName, volume.Config)
 
 	return b.driver.MountVolume(vol, op)
 }


More information about the lxc-devel mailing list