Skip to content

Commit

Permalink
incusd/storage/btrfs: Report migration progress from receiver
Browse files Browse the repository at this point in the history
Closes #676

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Mar 27, 2024
1 parent 37b4228 commit 00ab527
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions internal/server/storage/drivers/driver_btrfs_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,22 @@ func (d *btrfs) loadOptimizedBackupHeader(r io.ReadSeeker, mountPath string) (*B
}

// receiveSubVolume receives a subvolume from an io.Reader into the receivePath and returns the path to the received subvolume.
func (d *btrfs) receiveSubVolume(r io.Reader, receivePath string) (string, error) {
func (d *btrfs) receiveSubVolume(r io.Reader, receivePath string, tracker *ioprogress.ProgressTracker) (string, error) {
files, err := os.ReadDir(receivePath)
if err != nil {
return "", fmt.Errorf("Failed listing contents of %q: %w", receivePath, err)
}

err = subprocess.RunCommandWithFds(context.TODO(), r, nil, "btrfs", "receive", "-e", receivePath)
// Setup progress tracker.
var stdin io.Reader = r
if tracker != nil {
stdin = &ioprogress.ProgressReader{
Reader: r,
Tracker: tracker,
}
}

err = subprocess.RunCommandWithFds(context.TODO(), stdin, nil, "btrfs", "receive", "-e", receivePath)
if err != nil {
return "", err
}
Expand Down
10 changes: 8 additions & 2 deletions internal/server/storage/drivers/driver_btrfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (d *btrfs) CreateVolumeFromBackup(vol Volume, srcBackup backup.Info, srcDat
}

if hdr.Name == srcFile {
subVolRecvPath, err := d.receiveSubVolume(tr, targetPath)
subVolRecvPath, err := d.receiveSubVolume(tr, targetPath, nil)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -628,6 +628,12 @@ func (d *btrfs) createVolumeFromMigrationOptimized(vol Volume, conn io.ReadWrite
receiveVolume := func(v Volume, receivePath string) error {
_, snapName, _ := api.GetParentAndSnapshotName(v.name)

// Setup progress tracking.
var wrapper *ioprogress.ProgressTracker
if volTargetArgs.TrackProgress {
wrapper = localMigration.ProgressTracker(op, "fs_progress", v.name)
}

for _, subVol := range subvolumes {
if subVol.Snapshot != snapName {
continue // Skip any subvolumes that dont belong to our volume (empty for main).
Expand All @@ -643,7 +649,7 @@ func (d *btrfs) createVolumeFromMigrationOptimized(vol Volume, conn io.ReadWrite
subVolTargetPath := filepath.Join(v.MountPath(), subVol.Path)
d.logger.Debug("Receiving volume", logger.Ctx{"name": v.name, "receivePath": receivePath, "path": subVolTargetPath})

subVolRecvPath, err := d.receiveSubVolume(conn, receivePath)
subVolRecvPath, err := d.receiveSubVolume(conn, receivePath, wrapper)
if err != nil {
return err
}
Expand Down

0 comments on commit 00ab527

Please sign in to comment.