Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incusd/storage/drivers/lvm: Cache VG extent size #1192

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/server/storage/drivers/driver_lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"time"

"github.com/lxc/incus/v6/internal/linux"
Expand All @@ -26,6 +27,9 @@ import (

const lvmVgPoolMarker = "incus_pool" // Indicator tag used to mark volume groups as in use.

var lvmExtentSize map[string]int64
var lvmExtentSizeMu sync.Mutex

var lvmLoaded bool
var lvmVersion string

Expand Down
19 changes: 18 additions & 1 deletion internal/server/storage/drivers/driver_lvm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func (d *lvm) volumeGroupExists(vgName string) (bool, []string, error) {

// volumeGroupExtentSize gets the volume group's physical extent size in bytes.
func (d *lvm) volumeGroupExtentSize(vgName string) (int64, error) {
// Look for cached value.
lvmExtentSizeMu.Lock()
defer lvmExtentSizeMu.Unlock()

if lvmExtentSize == nil {
lvmExtentSize = map[string]int64{}
} else if lvmExtentSize[d.name] > 0 {
return lvmExtentSize[d.name], nil
}

output, err := subprocess.TryRunCommand("vgs", "--noheadings", "--nosuffix", "--units", "b", "-o", "vg_extent_size", vgName)
if err != nil {
if d.isLVMNotFoundExitError(err) {
Expand All @@ -142,7 +152,14 @@ func (d *lvm) volumeGroupExtentSize(vgName string) (int64, error) {
}

output = strings.TrimSpace(output)
return strconv.ParseInt(output, 10, 64)
val, err := strconv.ParseInt(output, 10, 64)
if err != nil {
return -1, err
}

lvmExtentSize[d.name] = val

return val, nil
}

// countLogicalVolumes gets the count of volumes (both normal and thin) in a volume group.
Expand Down
Loading