Skip to content

Commit

Permalink
Merge pull request #1653 from presztak/fix_lvmcluster_storage_creation
Browse files Browse the repository at this point in the history
Fix incorrect volume group naming when `vg_name` is not specified
  • Loading branch information
stgraber authored Feb 13, 2025
2 parents d1cd220 + 1910ae7 commit bd92072
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/server/storage/drivers/driver_lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ func (d *lvm) init(s *state.State, name string, config map[string]string, log lo
if d.clustered && d.config != nil {
_, exists := d.config["lvm.vg_name"]
if !exists {
d.config["lvm.vg_name"] = d.name
sourceType := d.getSourceType()
if sourceType == lvmSourceTypeDefault || sourceType == lvmSourceTypePhysicalDevice {
d.config["lvm.vg_name"] = d.name
} else if sourceType == lvmSourceTypeVolumeGroup {
d.config["lvm.vg_name"] = d.config["source"]
}
}
}
}
Expand Down Expand Up @@ -155,7 +160,6 @@ func (d *lvm) FillConfig() error {
func (d *lvm) Create() error {
d.config["volatile.initial_source"] = d.config["source"]

defaultSource := loopFilePath(d.name)
var err error
var pvExists, vgExists bool
var pvName string
Expand All @@ -171,8 +175,11 @@ func (d *lvm) Create() error {

var usingLoopFile bool

if d.config["source"] == "" || d.config["source"] == defaultSource {
sourceType := d.getSourceType()

if sourceType == lvmSourceTypeDefault {
usingLoopFile = true
defaultSource := loopFilePath(d.name)

// We are using an internal loopback file.
d.config["source"] = defaultSource
Expand Down Expand Up @@ -234,7 +241,7 @@ func (d *lvm) Create() error {
if vgExists {
return fmt.Errorf("A volume group already exists called %q", d.config["lvm.vg_name"])
}
} else if filepath.IsAbs(d.config["source"]) {
} else if sourceType == lvmSourceTypePhysicalDevice {
// We are using an existing physical device.
srcPath := d.config["source"]

Expand Down Expand Up @@ -279,7 +286,7 @@ func (d *lvm) Create() error {
if err != nil {
return err
}
} else if d.config["source"] != "" {
} else if sourceType == lvmSourceTypeVolumeGroup {
// We are using an existing volume group, so physical must exist already.
pvExists = true

Expand Down
24 changes: 24 additions & 0 deletions internal/server/storage/drivers/driver_lvm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ const lvmEscapedHyphen = "--"
// lvmThinpoolDefaultName is the default name for the thinpool volume.
const lvmThinpoolDefaultName = "IncusThinPool"

type lvmSourceType int

const (
lvmSourceTypeUnknown lvmSourceType = iota
lvmSourceTypeDefault
lvmSourceTypePhysicalDevice
lvmSourceTypeVolumeGroup
)

// usesThinpool indicates whether the config specifies to use a thin pool or not.
func (d *lvm) usesThinpool() bool {
// No thin pool on clustered LVM.
Expand Down Expand Up @@ -885,3 +894,18 @@ func (d *lvm) deactivateVolume(vol Volume) (bool, error) {

return false, nil
}

// getSourceType determines the source type based on the config["source"] value.
func (d *lvm) getSourceType() lvmSourceType {
defaultSource := loopFilePath(d.name)

if d.config["source"] == "" || d.config["source"] == defaultSource {
return lvmSourceTypeDefault
} else if filepath.IsAbs(d.config["source"]) {
return lvmSourceTypePhysicalDevice
} else if d.config["source"] != "" {
return lvmSourceTypeVolumeGroup
}

return lvmSourceTypeUnknown
}

0 comments on commit bd92072

Please sign in to comment.