Skip to content

Commit

Permalink
incusd/storage/lvm: Add lvm.metadata_size
Browse files Browse the repository at this point in the history
Closes #1066

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Sep 1, 2024
1 parent 915b620 commit 2bc2f69
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions internal/server/storage/drivers/driver_lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,20 @@ func (d *lvm) Create() error {
return fmt.Errorf("No name for physical volume detected")
}

_, err := subprocess.TryRunCommand("pvcreate", pvName)
args := []string{}

metadataSizeBytes, err := d.roundedSizeBytesString(d.config["lvm.metadata_size"])
if err != nil {
return fmt.Errorf("Invalid lvm.metadata_size: %w", err)
}

if metadataSizeBytes > 0 {
args = append(args, "--metadatasize", fmt.Sprintf("%db", metadataSizeBytes))
}

args = append(args, pvName)

_, err = subprocess.TryRunCommand("pvcreate", args...)
if err != nil {
return err
}
Expand Down Expand Up @@ -549,7 +562,8 @@ func (d *lvm) Delete(op *operations.Operation) error {

func (d *lvm) Validate(config map[string]string) error {
rules := map[string]func(value string) error{
"lvm.vg_name": validate.IsAny,
"lvm.vg_name": validate.IsAny,
"lvm.metadata_size": validate.Optional(validate.IsSize),
}

if !d.clustered {
Expand Down Expand Up @@ -590,6 +604,11 @@ func (d *lvm) Update(changedConfig map[string]string) error {
return fmt.Errorf("lvm.thinpool_metadata_size cannot be changed")
}

_, changed = changedConfig["lvm.metadata_size"]
if changed {
return fmt.Errorf("lvm.metadata_size cannot be changed")
}

_, changed = changedConfig["volume.lvm.stripes"]
if changed && d.usesThinpool() {
return fmt.Errorf("volume.lvm.stripes cannot be changed when using thin pool")
Expand Down

0 comments on commit 2bc2f69

Please sign in to comment.