diff --git a/internal/server/storage/drivers/driver_lvm.go b/internal/server/storage/drivers/driver_lvm.go index ab8c1db0134..9f620be85ab 100644 --- a/internal/server/storage/drivers/driver_lvm.go +++ b/internal/server/storage/drivers/driver_lvm.go @@ -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 } @@ -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 { @@ -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")