Skip to content

Commit

Permalink
lxd/storage_volumes_state: Handle unsupported response from drivers
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
(cherry picked from commit 4f5efd6132a263fe56e98ad1262a70159f8f8934)
Signed-off-by: Wesley Hershberger <[email protected]>
License: Apache-2.0
  • Loading branch information
stgraber authored and MggMuggins committed Aug 28, 2024
1 parent 7f763d5 commit 4018acd
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lxd/storage_volumes_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
storagePools "github.com/canonical/lxd/lxd/storage"
storageDrivers "github.com/canonical/lxd/lxd/storage/drivers"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/entity"
Expand Down Expand Up @@ -121,7 +122,7 @@ func storagePoolVolumeTypeStateGet(d *Daemon, r *http.Request) response.Response
if volumeType == cluster.StoragePoolVolumeTypeCustom {
// Custom volumes.
usage, err = pool.GetCustomVolumeUsage(projectName, volumeName)
if err != nil {
if err != nil && err != storageDrivers.ErrNotSupported {
return response.SmartError(err)
}
} else {
Expand All @@ -141,23 +142,26 @@ func storagePoolVolumeTypeStateGet(d *Daemon, r *http.Request) response.Response
}

usage, err = pool.GetInstanceUsage(inst)
if err != nil {
if err != nil && err != storageDrivers.ErrNotSupported {
return response.SmartError(err)
}
}

// Prepare the state struct.
state := api.StorageVolumeState{}
state.Usage = &api.StorageVolumeStateUsage{}

// Only fill 'used' field if receiving a valid value.
if usage.Used >= 0 {
state.Usage.Used = uint64(usage.Used)
}
if usage != nil {
state.Usage = &api.StorageVolumeStateUsage{}

// Only fill 'total' field if receiving a valid value.
if usage.Total >= 0 {
state.Usage.Total = usage.Total
// Only fill 'used' field if receiving a valid value.
if usage.Used >= 0 {
state.Usage.Used = uint64(usage.Used)
}

// Only fill 'total' field if receiving a valid value.
if usage.Total >= 0 {
state.Usage.Total = usage.Total
}
}

return response.SyncResponse(true, state)
Expand Down

0 comments on commit 4018acd

Please sign in to comment.