[lxc-devel] [lxd/master] Storage fixes

stgraber on Github lxc-bot at linuxcontainers.org
Thu Jan 9 22:53:18 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/20200109/d77e9c95/attachment.bin>
-------------- next part --------------
From fdbc2d8e89c25f0f06ab3ae36b10f3db359d1bd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jan 2020 17:25:26 -0500
Subject: [PATCH 1/3] lxd/storage/drivers: Use standard errors

---
 lxd/storage/drivers/driver_btrfs_volumes.go  | 12 ++++++------
 lxd/storage/drivers/driver_cephfs_volumes.go |  8 ++++----
 lxd/storage/drivers/driver_dir_volumes.go    | 10 +++++-----
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/lxd/storage/drivers/driver_btrfs_volumes.go b/lxd/storage/drivers/driver_btrfs_volumes.go
index c8826b447f..80e26bf1ee 100644
--- a/lxd/storage/drivers/driver_btrfs_volumes.go
+++ b/lxd/storage/drivers/driver_btrfs_volumes.go
@@ -240,14 +240,14 @@ func (d *btrfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots bo
 // CreateVolumeFromMigration creates a volume being sent via a migration.
 func (d *btrfs) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	// Handle simple rsync through generic.
 	if volTargetArgs.MigrationType.FSType == migration.MigrationFSType_RSYNC {
 		return genericCreateVolumeFromMigration(d, nil, vol, conn, volTargetArgs, preFiller, op)
 	} else if volTargetArgs.MigrationType.FSType != migration.MigrationFSType_BTRFS {
-		return fmt.Errorf("Migration type not supported")
+		return ErrNotSupported
 	}
 
 	// Handle btrfs send/receive migration.
@@ -349,11 +349,11 @@ func (d *btrfs) ValidateVolume(vol Volume, removeUnknownKeys bool) error {
 // UpdateVolume applies config changes to the volume.
 func (d *btrfs) UpdateVolume(vol Volume, changedConfig map[string]string) error {
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	if vol.volType != VolumeTypeCustom {
-		return fmt.Errorf("Volume type not supported")
+		return ErrNotSupported
 	}
 
 	return d.SetVolumeQuota(vol, vol.config["size"], nil)
@@ -476,14 +476,14 @@ func (d *btrfs) RenameVolume(vol Volume, newVolName string, op *operations.Opera
 // MigrateVolume sends a volume for migration.
 func (d *btrfs) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs migration.VolumeSourceArgs, op *operations.Operation) error {
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	// Handle simple rsync through generic.
 	if volSrcArgs.MigrationType.FSType == migration.MigrationFSType_RSYNC {
 		return d.vfsMigrateVolume(vol, conn, volSrcArgs, op)
 	} else if volSrcArgs.MigrationType.FSType != migration.MigrationFSType_BTRFS {
-		return fmt.Errorf("Migration type not supported")
+		return ErrNotSupported
 	}
 
 	// Handle btrfs send/receive migration.
diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go
index a1cb7ebde9..857ea0ce96 100644
--- a/lxd/storage/drivers/driver_cephfs_volumes.go
+++ b/lxd/storage/drivers/driver_cephfs_volumes.go
@@ -18,11 +18,11 @@ import (
 // CreateVolume creates a new storage volume on disk.
 func (d *cephfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Operation) error {
 	if vol.volType != VolumeTypeCustom {
-		return fmt.Errorf("Volume type not supported")
+		return ErrNotSupported
 	}
 
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	// Create the main volume path.
@@ -141,7 +141,7 @@ func (d *cephfs) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots b
 // CreateVolumeFromMigration creates a new volume (with or without snapshots) from a migration data stream.
 func (d *cephfs) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
 	if volTargetArgs.MigrationType.FSType != migration.MigrationFSType_RSYNC {
-		return fmt.Errorf("Migration type not supported")
+		return ErrNotSupported
 	}
 
 	// Create the main volume path.
@@ -427,7 +427,7 @@ func (d *cephfs) RenameVolume(vol Volume, newName string, op *operations.Operati
 // MigrateVolume streams the volume (with or without snapshots)
 func (d *cephfs) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs migration.VolumeSourceArgs, op *operations.Operation) error {
 	if volSrcArgs.MigrationType.FSType != migration.MigrationFSType_RSYNC {
-		return fmt.Errorf("Migration type not supported")
+		return ErrNotSupported
 	}
 
 	return d.vfsMigrateVolume(vol, conn, volSrcArgs, op)
diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go
index 67df0ffe44..3a1c8d92b0 100644
--- a/lxd/storage/drivers/driver_dir_volumes.go
+++ b/lxd/storage/drivers/driver_dir_volumes.go
@@ -118,11 +118,11 @@ func (d *dir) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots bool
 // CreateVolumeFromMigration creates a volume being sent via a migration.
 func (d *dir) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	if volTargetArgs.MigrationType.FSType != migration.MigrationFSType_RSYNC {
-		return fmt.Errorf("Migration type not supported")
+		return ErrNotSupported
 	}
 
 	return genericCreateVolumeFromMigration(d, d.setupInitialQuota, vol, conn, volTargetArgs, preFiller, op)
@@ -193,7 +193,7 @@ func (d *dir) ValidateVolume(vol Volume, removeUnknownKeys bool) error {
 // UpdateVolume applies config changes to the volume.
 func (d *dir) UpdateVolume(vol Volume, changedConfig map[string]string) error {
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	if _, changed := changedConfig["size"]; changed {
@@ -268,11 +268,11 @@ func (d *dir) RenameVolume(vol Volume, newVolName string, op *operations.Operati
 // MigrateVolume sends a volume for migration.
 func (d *dir) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs migration.VolumeSourceArgs, op *operations.Operation) error {
 	if vol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
+		return ErrNotSupported
 	}
 
 	if volSrcArgs.MigrationType.FSType != migration.MigrationFSType_RSYNC {
-		return fmt.Errorf("Migration type not supported")
+		return ErrNotSupported
 	}
 
 	return d.vfsMigrateVolume(vol, conn, volSrcArgs, op)

From 5636f107bc0b62f6bb9720f5f101f9b5bcf9e229 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jan 2020 17:45:25 -0500
Subject: [PATCH 2/3] lxd/storage/btrfs: Disable send/receive inside containers
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/storage/drivers/driver_btrfs.go | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/drivers/driver_btrfs.go b/lxd/storage/drivers/driver_btrfs.go
index 3f0de22616..e51abbd710 100644
--- a/lxd/storage/drivers/driver_btrfs.go
+++ b/lxd/storage/drivers/driver_btrfs.go
@@ -347,10 +347,8 @@ func (d *btrfs) MigrationTypes(contentType ContentType, refresh bool) []migratio
 		return nil
 	}
 
-	// When performing a refresh, always use rsync. Using btrfs send/receive
-	// here doesn't make sense since it would need to send everything again
-	// which defeats the purpose of a refresh.
-	if refresh {
+	// Only use rsync for refreshes and if running in an unprivileged container.
+	if refresh || d.state.OS.RunningInUserNS {
 		return []migration.Type{
 			{
 				FSType:   migration.MigrationFSType_RSYNC,

From d35758530b054a4c3fa1355745c1571a4112807f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jan 2020 16:59:07 -0500
Subject: [PATCH 3/3] lxd/init: Support new storage drivers
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_init.go | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/lxd/main_init.go b/lxd/main_init.go
index a0a26cb157..00a4a574a5 100644
--- a/lxd/main_init.go
+++ b/lxd/main_init.go
@@ -7,6 +7,9 @@ import (
 	"github.com/spf13/cobra"
 
 	"github.com/lxc/lxd/client"
+	"github.com/lxc/lxd/lxd/state"
+	storageDrivers "github.com/lxc/lxd/lxd/storage/drivers"
+	"github.com/lxc/lxd/lxd/sys"
 	"github.com/lxc/lxd/lxd/util"
 	"github.com/lxc/lxd/shared"
 )
@@ -163,6 +166,14 @@ func (c *cmdInit) availableStorageDrivers(poolType string) []string {
 		backingFs = "dir"
 	}
 
+	// Get info for new drivers.
+	s := state.NewState(nil, nil, nil, sys.DefaultOS(), nil, nil, nil, nil, nil)
+	info := storageDrivers.SupportedDrivers(s)
+	availableDrivers := []string{}
+	for _, entry := range info {
+		availableDrivers = append(availableDrivers, entry.Name)
+	}
+
 	// Check available backends
 	for _, driver := range supportedStoragePoolDrivers {
 		if poolType == "remote" && !shared.StringInSlice(driver, []string{"ceph", "cephfs"}) {
@@ -182,19 +193,23 @@ func (c *cmdInit) availableStorageDrivers(poolType string) []string {
 			continue
 		}
 
-		// btrfs can work in user namespaces too. (If
-		// source=/some/path/on/btrfs is used.)
+		// btrfs can work in user namespaces too. (If source=/some/path/on/btrfs is used.)
 		if shared.RunningInUserNS() && (backingFs != "btrfs" || driver != "btrfs") {
 			continue
 		}
 
-		// Initialize a core storage interface for the given driver.
-		_, err := storageCoreInit(driver)
-		if err != nil {
+		// Check if available as a new style driver.
+		if shared.StringInSlice(driver, availableDrivers) {
+			drivers = append(drivers, driver)
 			continue
 		}
 
-		drivers = append(drivers, driver)
+		// Check if available as an old style driver.
+		_, err := storageCoreInit(driver)
+		if err == nil {
+			drivers = append(drivers, driver)
+			continue
+		}
 	}
 
 	return drivers


More information about the lxc-devel mailing list