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

lxd: Initialise server name and global config before storage patches are run #12421

Merged
merged 4 commits into from
Oct 19, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ doc/.sphinx/warnings.txt
doc/.sphinx/.wordlist.dic
doc/.sphinx/_static/swagger-ui
doc/.sphinx/_static/download
doc/__pycache__

# For Atom ctags
.tags
Expand Down
71 changes: 48 additions & 23 deletions lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,30 @@ func (d *Daemon) init() error {
version.UserAgentFeatures([]string{"cluster"})
}

// Load server name and config before patches run (so they can access them from d.State()).
err = d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
config, err := clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

// Get the local node (will be used if clustered).
serverName, err := tx.GetLocalNodeName(ctx)
if err != nil {
return err
}

d.globalConfigMu.Lock()
d.serverName = serverName
d.globalConfig = config
d.globalConfigMu.Unlock()

return nil
})
if err != nil {
return err
}

// Mount the storage pools.
logger.Infof("Initializing storage pools")
err = storageStartup(d.State(), false)
Expand Down Expand Up @@ -1262,6 +1286,30 @@ func (d *Daemon) init() error {
return err
}

// Load server name and config after patches run (in case its been changed).
err = d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
config, err := clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

// Get the local node (will be used if clustered).
serverName, err := tx.GetLocalNodeName(ctx)
if err != nil {
return err
}

d.globalConfigMu.Lock()
d.serverName = serverName
d.globalConfig = config
d.globalConfigMu.Unlock()

return nil
})
if err != nil {
return err
}

// Get daemon configuration.
bgpAddress := d.localConfig.BGPAddress()
bgpRouterID := d.localConfig.BGPRouterID()
Expand All @@ -1286,29 +1334,6 @@ func (d *Daemon) init() error {
maasAPIKey := ""
maasMachine := d.localConfig.MAASMachine()

err = d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
config, err := clusterConfig.Load(ctx, tx)
if err != nil {
return err
}

// Get the local node (will be used if clustered).
serverName, err := tx.GetLocalNodeName(ctx)
if err != nil {
return err
}

d.globalConfigMu.Lock()
d.serverName = serverName
d.globalConfig = config
d.globalConfigMu.Unlock()

return nil
})
if err != nil {
return err
}

// Get specific config keys.
d.globalConfigMu.Lock()
bgpASN = d.globalConfig.BGPASN()
Expand Down
28 changes: 24 additions & 4 deletions lxd/patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,18 @@ func patchStorageZfsUnsetInvalidBlockSettings(_ string, d *Daemon) error {
continue
}

delete(config, "block.filesystem")
delete(config, "block.mount_options")
update := false
for _, k := range []string{"block.filesystem", "block.mount_options"} {
_, found := config[k]
if found {
delete(config, k)
update = true
}
}

if !update {
continue
}

if vol.Type == db.StoragePoolVolumeTypeNameVM {
volType = volTypeVM
Expand Down Expand Up @@ -1096,8 +1106,18 @@ func patchStorageZfsUnsetInvalidBlockSettingsV2(_ string, d *Daemon) error {
continue
}

delete(config, "block.filesystem")
delete(config, "block.mount_options")
update := false
for _, k := range []string{"block.filesystem", "block.mount_options"} {
_, found := config[k]
if found {
delete(config, k)
update = true
}
}

if !update {
continue
}

if vol.Type == db.StoragePoolVolumeTypeNameVM {
volType = volTypeVM
Expand Down
Loading