Skip to content

Commit

Permalink
lxd/storage/connectors: Add WaitDiskDeviceResize func
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Jan 29, 2025
1 parent 92d91e2 commit 011fbe0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lxd/storage/connectors/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/canonical/lxd/lxd/locking"
"github.com/canonical/lxd/lxd/resources"
"github.com/canonical/lxd/lxd/storage/block"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/revert"
Expand Down Expand Up @@ -132,6 +133,29 @@ func WaitDiskDeviceGone(ctx context.Context, diskPath string) bool {
}
}

// WaitDiskDeviceResize waits until the disk device reflects the new size.
func WaitDiskDeviceResize(ctx context.Context, diskPath string, newSizeBytes int64) error {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

for {
sizeBytes, err := block.DiskSizeBytes(diskPath)
if err != nil {
return fmt.Errorf("Error getting disk size: %w", err)
}

if sizeBytes == newSizeBytes {
return nil
}

if ctx.Err() != nil {
return ctx.Err()
}

time.Sleep(500 * time.Millisecond)
}
}

// connectFunc is invoked by "connect" for each provided address.
// It receives a session and a target address. A non-nil session indicates
// an existing session for the target.
Expand Down

0 comments on commit 011fbe0

Please sign in to comment.