Skip to content

Commit e4243d2

Browse files
committed
snapshot: Snapshot.Restore returns SnapshotConfig by value
Mirrors the DataDir flip: the snap-DB-side Restore was the only place in the cmd/vm clone path that still forced \`*cfg\`/\`&cfg\` dancing. Drop the pointer return on the interface, value-out from LocalFile, and the cmd-side caller derefs once at the hypervisor boundary just like DirectClone.
1 parent 88d82bd commit e4243d2

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

cmd/vm/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ func (h Handler) Clone(cmd *cobra.Command, args []string) error {
128128
})
129129
defer stop()
130130

131-
vmCfg, vmID, netProvider, networkConfigs, err := h.prepareClone(ctx, cmd, conf, *cfg)
131+
vmCfg, vmID, netProvider, networkConfigs, err := h.prepareClone(ctx, cmd, conf, cfg)
132132
if err != nil {
133133
return err
134134
}
135135

136136
logger.Infof(ctx, "cloning VM from snapshot %s ...", snapRef)
137137

138-
vm, cloneErr := hyper.Clone(ctx, vmID, vmCfg, networkConfigs, cfg, stream)
138+
vm, cloneErr := hyper.Clone(ctx, vmID, vmCfg, networkConfigs, &cfg, stream)
139139
if cloneErr != nil {
140140
rollbackNetwork(ctx, netProvider, vmID)
141141
return fmt.Errorf("clone VM: %w", cloneErr)

snapshot/localfile/localfile.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,12 @@ func (lf *LocalFile) Delete(ctx context.Context, refs []string) ([]string, error
183183
return deleted, nil
184184
}
185185

186-
func (lf *LocalFile) Restore(ctx context.Context, ref string) (*types.SnapshotConfig, io.ReadCloser, error) {
186+
func (lf *LocalFile) Restore(ctx context.Context, ref string) (types.SnapshotConfig, io.ReadCloser, error) {
187187
rec, err := lf.resolveRecord(ctx, ref)
188188
if err != nil {
189-
return nil, nil, err
189+
return types.SnapshotConfig{}, nil, err
190190
}
191-
cfg := snapshotRecordToConfig(rec)
192-
return &cfg, utils.TarDirStream(rec.DataDir, nil), nil
191+
return snapshotRecordToConfig(rec), utils.TarDirStream(rec.DataDir, nil), nil
193192
}
194193

195194
func (lf *LocalFile) RegisterGC(orch *gc.Orchestrator) {

snapshot/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Snapshot interface {
4040
// Delete removes snapshots by ID or name. Returns the list of actually deleted IDs.
4141
Delete(ctx context.Context, refs []string) ([]string, error)
4242
// Restore restores a snapshot by ID or name, returning the snapshot config and a data stream.
43-
Restore(ctx context.Context, ref string) (*types.SnapshotConfig, io.ReadCloser, error)
43+
Restore(ctx context.Context, ref string) (types.SnapshotConfig, io.ReadCloser, error)
4444

4545
// Export streams the snapshot as a raw tar archive.
4646
// The archive includes a snapshot.json metadata entry followed by data files.

0 commit comments

Comments
 (0)