Skip to content

Commit

Permalink
lxd/instance/qemu: Add disk resize handling
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
(cherry picked from commit de3ea2ec6e7ac112ad0e91c0c08339adbae368b1)
Signed-off-by: Kadin Sayani <[email protected]>
License: Apache-2.0
  • Loading branch information
stgraber authored and kadinsayani committed Oct 4, 2024
1 parent d8ce497 commit c32cf54
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lxd/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -8081,7 +8081,7 @@ func (d *qemu) DeviceEventHandler(runConf *deviceConfig.RunConfig) error {

// Handle disk reconfiguration.
for _, mount := range runConf.Mounts {
if mount.Limits == nil {
if mount.Limits == nil && mount.Size == 0 {
continue
}

Expand All @@ -8094,10 +8094,20 @@ func (d *qemu) DeviceEventHandler(runConf *deviceConfig.RunConfig) error {
// Figure out the QEMU device ID.
devID := fmt.Sprintf("%s%s", qemuDeviceIDPrefix, filesystem.PathNameEncode(mount.DevName))

// Apply the limits.
err = m.SetBlockThrottle(devID, int(mount.Limits.ReadBytes), int(mount.Limits.WriteBytes), int(mount.Limits.ReadIOps), int(mount.Limits.WriteIOps))
if err != nil {
return fmt.Errorf("Failed applying limits for disk device %q: %w", mount.DevName, err)
if mount.Limits != nil {
// Apply the limits.
err = m.SetBlockThrottle(devID, int(mount.Limits.ReadBytes), int(mount.Limits.WriteBytes), int(mount.Limits.ReadIOps), int(mount.Limits.WriteIOps))
if err != nil {
return fmt.Errorf("Failed applying limits for disk device %q: %w", mount.DevName, err)
}
}

if mount.Size > 0 {
// Update the size.
err = m.UpdateBlockSize(strings.SplitN(devID, "-", 2)[1])
if err != nil {
return fmt.Errorf("Failed updating disk size %q: %w", mount.DevName, err)
}
}
}

Expand Down

0 comments on commit c32cf54

Please sign in to comment.