The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6700
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) ===
From 7899a7e6af8f13ba246bcbde9a9d4da64ef53b59 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:56:25 +0000 Subject: [PATCH 1/6] lxd/storage: Updates storageRootFSApplyQuota to support VMs Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lxd/storage.go b/lxd/storage.go index 3351aed653..971465b28a 100644 --- a/lxd/storage.go +++ b/lxd/storage.go @@ -925,18 +925,18 @@ func storageVolumeUmount(state *state.State, poolName string, volumeName string, // storageRootFSApplyQuota applies a quota to an instance if it can, if it cannot then it will // return false indicating that the quota needs to be stored in volatile to be applied on next boot. func storageRootFSApplyQuota(state *state.State, inst instance.Instance, size string) error { - c, ok := inst.(*containerLXC) - if !ok { - return fmt.Errorf("Received non-LXC container instance") - } - - pool, err := storagePools.GetPoolByInstance(state, c) + pool, err := storagePools.GetPoolByInstance(state, inst) if err != storageDrivers.ErrUnknownDriver && err != storageDrivers.ErrNotImplemented { - err = pool.SetInstanceQuota(c, size, nil) + err = pool.SetInstanceQuota(inst, size, nil) if err != nil { return err } } else { + c, ok := inst.(*containerLXC) + if !ok { + return fmt.Errorf("Received non-LXC container instance") + } + err := c.initStorage() if err != nil { return errors.Wrap(err, "Initialize storage") From 700cb01c8361e235afdf5f54a7eabdc64752c532 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 15:24:10 +0000 Subject: [PATCH 2/6] lxd/device/disk: Allow VM disks to be updated Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/device/disk.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lxd/device/disk.go b/lxd/device/disk.go index 252a42b57c..a963ece965 100644 --- a/lxd/device/disk.go +++ b/lxd/device/disk.go @@ -397,11 +397,7 @@ func (d *disk) postStart() error { // Update applies configuration changes to a started device. func (d *disk) Update(oldDevices deviceConfig.Devices, isRunning bool) error { - if d.inst.Type() == instancetype.VM { - if shared.IsRootDiskDevice(d.config) { - return nil - } - + if d.inst.Type() == instancetype.VM && !shared.IsRootDiskDevice(d.config) { return fmt.Errorf("Non-root disks not supported for VMs") } From ef8d69010ffa1afb1aaefdb6009a188ae1ed7710 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 14:52:35 +0000 Subject: [PATCH 3/6] lxd/storage/drivers/utils: Adds copyDevice function Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/utils.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go index cf26c5aa80..781e5a6c56 100644 --- a/lxd/storage/drivers/utils.go +++ b/lxd/storage/drivers/utils.go @@ -2,6 +2,7 @@ package drivers import ( "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -529,3 +530,25 @@ func regenerateFilesystemXFSUUID(devPath string) error { return nil } + +// copyDevice copies one device path to another. +func copyDevice(inputPath, outputPath string) error { + from, err := os.Open(inputPath) + if err != nil { + return errors.Wrapf(err, "Error opening file for reading: %s", inputPath) + } + defer from.Close() + + to, err := os.OpenFile(outputPath, os.O_WRONLY, 0) + if err != nil { + return errors.Wrapf(err, "Error opening file writing: %s", outputPath) + } + defer to.Close() + + _, err = io.Copy(to, from) + if err != nil { + return errors.Wrapf(err, "Error copying file '%s' to '%s'", inputPath, outputPath) + } + + return nil +} From 34b07ea9e2f202a36b51c4544b46f9a70fa4ba8d Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 14:38:27 +0000 Subject: [PATCH 4/6] lxd/storage/drivers: Filler logging Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_cephfs_volumes.go | 3 ++- lxd/storage/drivers/driver_dir_volumes.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go index 447fec82b8..c49b8ee17b 100644 --- a/lxd/storage/drivers/driver_cephfs_volumes.go +++ b/lxd/storage/drivers/driver_cephfs_volumes.go @@ -12,6 +12,7 @@ import ( "github.com/lxc/lxd/lxd/rsync" "github.com/lxc/lxd/shared" "github.com/lxc/lxd/shared/ioprogress" + log "github.com/lxc/lxd/shared/log15" "github.com/lxc/lxd/shared/units" ) @@ -42,7 +43,7 @@ func (d *cephfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.O // Fill the volume. if filler != nil && filler.Fill != nil { - d.logger.Debug("Running filler function") + d.logger.Debug("Running filler function", log.Ctx{"path": volPath}) err = filler.Fill(volPath, "") if err != nil { return err diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go index 6e55d1781d..30ab4892db 100644 --- a/lxd/storage/drivers/driver_dir_volumes.go +++ b/lxd/storage/drivers/driver_dir_volumes.go @@ -11,6 +11,7 @@ import ( "github.com/lxc/lxd/lxd/rsync" "github.com/lxc/lxd/lxd/storage/quota" "github.com/lxc/lxd/shared" + log "github.com/lxc/lxd/shared/log15" ) // CreateVolume creates an empty volume and can optionally fill it by executing the supplied @@ -49,7 +50,7 @@ func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper // Run the volume filler function if supplied. if filler != nil && filler.Fill != nil { - d.logger.Debug("Running filler function") + d.logger.Debug("Running filler function", log.Ctx{"path": volPath}) err = filler.Fill(volPath, rootBlockPath) if err != nil { return err From 7a7862d4accacdbe91fa322a4ae08c8c3b535960 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 14:37:51 +0000 Subject: [PATCH 5/6] lxd/storage/drivers/generic: Updates genericCopyVolume to be VM block aware using copyDevice Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/generic.go | 50 +++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/lxd/storage/drivers/generic.go b/lxd/storage/drivers/generic.go index 56df274740..b3ac53cde6 100644 --- a/lxd/storage/drivers/generic.go +++ b/lxd/storage/drivers/generic.go @@ -16,8 +16,8 @@ import ( // genericCopyVolume copies a volume and its snapshots using a non-optimized method. // initVolume is run against the main volume (not the snapshots) and is often used for quota initialization. func genericCopyVolume(d Driver, initVolume func(vol Volume) (func(), error), vol Volume, srcVol Volume, srcSnapshots []Volume, refresh bool, op *operations.Operation) error { - if vol.contentType != ContentTypeFS || srcVol.contentType != ContentTypeFS { - return fmt.Errorf("Content type not supported") + if vol.contentType != srcVol.contentType { + return fmt.Errorf("Content type of source and target must be the same") } bwlimit := d.Config()["rsync.bwlimit"] @@ -46,7 +46,28 @@ func genericCopyVolume(d Driver, initVolume func(vol Volume) (func(), error), vo err := srcSnapshot.MountTask(func(srcMountPath string, op *operations.Operation) error { // Copy the snapshot. _, err := rsync.LocalCopy(srcMountPath, mountPath, bwlimit, true) - return err + if err != nil { + return err + } + + if srcSnapshot.IsVMBlock() { + srcDevPath, err := d.GetVolumeDiskPath(srcSnapshot) + if err != nil { + return err + } + + targetDevPath, err := d.GetVolumeDiskPath(vol) + if err != nil { + return err + } + + err = copyDevice(srcDevPath, targetDevPath) + if err != nil { + return err + } + } + + return nil }, op) if err != nil { return err @@ -79,7 +100,28 @@ func genericCopyVolume(d Driver, initVolume func(vol Volume) (func(), error), vo // Copy source to destination (mounting each volume if needed). err := srcVol.MountTask(func(srcMountPath string, op *operations.Operation) error { _, err := rsync.LocalCopy(srcMountPath, mountPath, bwlimit, true) - return err + if err != nil { + return err + } + + if srcVol.IsVMBlock() { + srcDevPath, err := d.GetVolumeDiskPath(srcVol) + if err != nil { + return err + } + + targetDevPath, err := d.GetVolumeDiskPath(vol) + if err != nil { + return err + } + + err = copyDevice(srcDevPath, targetDevPath) + if err != nil { + return err + } + } + + return nil }, op) if err != nil { return err From 709547f98ad6ab9a021d68126913c29027f38e84 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 13 Jan 2020 11:46:07 +0000 Subject: [PATCH 6/6] client/lxd/instances: Sends instance type when copying instances Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- client/lxd_instances.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/lxd_instances.go b/client/lxd_instances.go index 340a4b9bf5..b40b995863 100644 --- a/client/lxd_instances.go +++ b/client/lxd_instances.go @@ -352,6 +352,7 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance, req := api.InstancesPost{ Name: instance.Name, InstancePut: instance.Writable(), + Type: api.InstanceType(instance.Type), } req.Source.BaseImage = instance.Config["volatile.base_image"]
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel