Skip to content

Commit

Permalink
incusd/storage: Handle instance volume size on import
Browse files Browse the repository at this point in the history
Closes #798

Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Apr 28, 2024
1 parent ff1290c commit c50747f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/server/storage/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,18 @@ func (b *backend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io.Rea
volumeConfig = srcBackup.Config.Volume.Config
}

// Get instance root size information.
if srcBackup.Config != nil && srcBackup.Config.Container != nil {
_, rootConfig, err := internalInstance.GetRootDiskDevice(srcBackup.Config.Container.ExpandedDevices)
if err == nil && rootConfig["size"] != "" {
if volumeConfig == nil {
volumeConfig = map[string]string{}
}

volumeConfig["size"] = rootConfig["size"]
}
}

vol := b.GetVolume(volType, contentType, volStorageName, volumeConfig)

importRevert := revert.New()
Expand Down Expand Up @@ -795,6 +807,11 @@ func (b *backend) CreateInstanceFromBackup(srcBackup backup.Info, srcData io.Rea
})
}

// Make sure the size isn't part of the instance volume after initial creation.
if volumeConfig != nil {
delete(volumeConfig, "size")
}

// Update information in the backup.yaml file.
err = vol.MountTask(func(mountPath string, op *operations.Operation) error {
return backup.UpdateInstanceConfig(b.state.DB.Cluster, srcBackup, mountPath)
Expand Down

0 comments on commit c50747f

Please sign in to comment.