Skip to content

Commit

Permalink
Merge pull request #1173 from stgraber/main
Browse files Browse the repository at this point in the history
Implement LVM metadatasize configuration
  • Loading branch information
hallyn authored Sep 2, 2024
2 parents 450ed7e + 2bc2f69 commit d9e8c38
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/api-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2592,3 +2592,9 @@ This adds the ability to run a scriptlet at various stages of startup: using the
This introduces a new `boot.autorestart` configuration key which when
set to `true` will have the instance automatically be restarted upon
unexpected exit for up to 10 times over a 1 minute period.

## `storage_lvm_metadatasize`

This introduces a new `lvm.metadata_size` option for LVM storage pools
which allows overriding the default metadata size when creating a new
LVM physical volume.
1 change: 1 addition & 0 deletions doc/reference/storage_lvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Key | Type | Driver | Default
:-- | :--- | :----- | :------ | :----------
`lvm.thinpool_name` | string | `lvm` | `IncusThinPool` | Thin pool where volumes are created
`lvm.thinpool_metadata_size` | string | `lvm` |`0` (auto) | The size of the thin pool metadata volume (the default is to let LVM calculate an appropriate size)
`lvm.metadata_size` | string | `lvm` |`0` (auto) | The size of the metadata space for the physical volume
`lvm.use_thinpool` | bool | `lvm` | `true` | Whether the storage pool uses a thin pool for logical volumes
`lvm.vg.force_reuse` | bool | `lvm` | `false` | Force using an existing non-empty volume group
`lvm.vg_name` | string | all | name of the pool | Name of the volume group to create
Expand Down
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
1 change: 1 addition & 0 deletions internal/version/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ var APIExtensions = []string{
"network_integrations_peer_name",
"qemu_scriptlet",
"instance_auto_restart",
"storage_lvm_metadatasize",
}

// APIExtensionsCount returns the number of available API extensions.
Expand Down

0 comments on commit d9e8c38

Please sign in to comment.