From 50a74fdf381c97bd56d09151e05d726093145a68 Mon Sep 17 00:00:00 2001 From: Din Music Date: Thu, 1 Aug 2024 10:59:30 +0000 Subject: [PATCH 1/3] lxd/storage/backend_lxd: Create missing file when receiving raw image Signed-off-by: Din Music --- 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 de330d9a8467..bd1b2ed16a2e 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -1870,7 +1870,7 @@ func (b *lxdBackend) recvVolumeFiller(conn io.ReadWriteCloser, contentType drive } } else { // Receive block volume. - to, err := os.OpenFile(rootBlockPath, os.O_WRONLY|os.O_TRUNC, 0) + to, err := os.OpenFile(rootBlockPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600) if err != nil { return -1, fmt.Errorf("Error opening file for writing %q: %w", rootBlockPath, err) } From a249d0cf23d4749093ed7ee30ec1413073786bb9 Mon Sep 17 00:00:00 2001 From: Din Music Date: Thu, 1 Aug 2024 11:00:52 +0000 Subject: [PATCH 2/3] lxd/storage/backend_lxd: Set volume size directly on volume config Signed-off-by: Din Music --- lxd/storage/backend_lxd.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go index bd1b2ed16a2e..319a66d0f764 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -2434,10 +2434,6 @@ func (b *lxdBackend) CreateInstanceFromConversion(inst instance.Instance, conn i return err } - // Override args.Name and args.Config to ensure volume is created based on instance. - args.Config = vol.Config() - args.Name = inst.Name() - // Get instance's root disk device from local devices. Do not use expanded devices, as we want // to determine whether the root disk volume size was explicitly set by the client. canResizeRootDiskSize := true @@ -2488,7 +2484,7 @@ func (b *lxdBackend) CreateInstanceFromConversion(inst instance.Instance, conn i if canResizeRootDiskSize { // Set size of the volume to the uncompressed image size. l.Debug("Setting volume size to uncompressed image size", logger.Ctx{"size": fmt.Sprintf("%d", imgBytes)}) - args.Config["size"] = fmt.Sprintf("%d", imgBytes) + vol.SetConfigSize(fmt.Sprintf("%d", imgBytes)) } // Convert received image into intance volume. @@ -2499,7 +2495,7 @@ func (b *lxdBackend) CreateInstanceFromConversion(inst instance.Instance, conn i // block volume will still be able to accommodate it. if canResizeRootDiskSize && contentType == drivers.ContentTypeBlock && args.VolumeSize > 0 { l.Debug("Setting volume size to source disk size", logger.Ctx{"size": args.VolumeSize}) - args.Config["size"] = fmt.Sprintf("%d", args.VolumeSize) + vol.SetConfigSize(fmt.Sprintf("%d", args.VolumeSize)) } srcDiskSize = args.VolumeSize From d268b7ef2f0a7589ba7121d1e85480109f3ea64c Mon Sep 17 00:00:00 2001 From: Din Music Date: Thu, 1 Aug 2024 11:05:36 +0000 Subject: [PATCH 3/3] lxd/storage/backend_lxd: Remove unnecessary usage of volume copy Signed-off-by: Din Music --- lxd/storage/backend_lxd.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go index 319a66d0f764..6ea64a7788d6 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -2525,14 +2525,12 @@ func (b *lxdBackend) CreateInstanceFromConversion(inst instance.Instance, conn i return fmt.Errorf("Volume size (%s) is lower then source disk size (%s)", volSize, imgSize) } - volCopy := drivers.NewVolumeCopy(vol) - - err = b.driver.CreateVolume(volCopy.Volume, &volFiller, op) + err = b.driver.CreateVolume(vol, &volFiller, op) if err != nil { return err } - revert.Add(func() { _ = b.driver.DeleteVolume(volCopy.Volume, op) }) + revert.Add(func() { _ = b.driver.DeleteVolume(vol, op) }) // At this point, the instance's volume is populated. If "virtio" option is enabled, // inject the virtio drivers.