Skip to content

Commit 07de11f

Browse files
committed
incusd/instance: Add support for creating qcow2 snapshots while instance is running
Signed-off-by: Piotr Resztak <piotr.resztak@futurfusion.io>
1 parent e2d1d6e commit 07de11f

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

internal/server/instance/drivers/driver_lxc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9379,3 +9379,8 @@ func (d *lxc) setupCredentials(update bool) error {
93799379
func (d *lxc) GuestOS() string {
93809380
return "linux"
93819381
}
9382+
9383+
// CreateQcow2Snapshot creates a qcow2 snapshot for a running instance. Not supported by containers.
9384+
func (d *lxc) CreateQcow2Snapshot(snapName string, backingFilename string) error {
9385+
return nil
9386+
}

internal/server/instance/drivers/driver_qemu.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"os/exec"
2626
"path/filepath"
27+
"regexp"
2728
"slices"
2829
"sort"
2930
"strconv"
@@ -10455,9 +10456,6 @@ func (d *qemu) GuestOS() string {
1045510456
return "unknown"
1045610457
}
1045710458

10458-
<<<<<<< Updated upstream
10459-
func (b *qemu) isQCOW2(devPath string) (bool, error) {
10460-
=======
1046110459
// CreateQcow2Snapshot creates a qcow2 snapshot for a running instance.
1046210460
func (d *qemu) CreateQcow2Snapshot(snapshotName string, backingFilename string) error {
1046310461
monitor, err := d.qmpConnect()
@@ -10518,12 +10516,12 @@ func (d *qemu) CreateQcow2Snapshot(snapshotName string, backingFilename string)
1051810516
}
1051910517

1052010518
blockDev := map[string]any{
10521-
"driver": "qcow2",
10519+
"driver": "qcow2",
1052210520
"discard": "unmap", // Forward as an unmap request. This is the same as `discard=on` in the qemu config file.
1052310521
"node-name": nextOverlayName,
1052410522
"read-only": false,
1052510523
"file": map[string]any{
10526-
"driver": "host_device",
10524+
"driver": "host_device",
1052710525
"filename": fmt.Sprintf("/dev/fdset/%d", info.ID),
1052810526
},
1052910527
}
@@ -10550,7 +10548,6 @@ func (d *qemu) CreateQcow2Snapshot(snapshotName string, backingFilename string)
1055010548
}
1055110549

1055210550
func (d *qemu) isQCOW2(devPath string) (bool, error) {
10553-
>>>>>>> Stashed changes
1055410551
imgInfo, err := storageDrivers.Qcow2Info(devPath)
1055510552
if err != nil {
1055610553
return false, err
@@ -10603,3 +10600,22 @@ func (d *qemu) qcow2BlockDev(m *qmp.Monitor, nodeName string, aioMode string, di
1060310600

1060410601
return blockDev, nil
1060510602
}
10603+
10604+
// currentQcow2OverlayIndex returns the current maximum overlay index.
10605+
func currentQcow2OverlayIndex(names []string, prefix string) int {
10606+
re := regexp.MustCompile(fmt.Sprintf(`^%s_overlay(\d+)$`, prefix))
10607+
10608+
maxIndex := -1
10609+
10610+
for _, name := range names {
10611+
m := re.FindStringSubmatch(name)
10612+
if len(m) == 2 {
10613+
n, err := strconv.Atoi(m[1])
10614+
if err == nil && n > maxIndex {
10615+
maxIndex = n
10616+
}
10617+
}
10618+
}
10619+
10620+
return maxIndex
10621+
}

internal/server/instance/instance_interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type Instance interface {
9898
Backups() ([]backup.InstanceBackup, error)
9999
UpdateBackupFile() error
100100
CanLiveMigrate() bool
101+
CreateQcow2Snapshot(snapshotName string, backingFilename string) error
101102

102103
// Config handling.
103104
Rename(newName string, applyTemplateTrigger bool) error

0 commit comments

Comments
 (0)