From 9a916ab0fbd2467e13896ba3d6f816536a6d31bb Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Oct 2023 16:22:59 +0100 Subject: [PATCH 1/4] gitignore: Ignore pycache Signed-off-by: Thomas Parrott --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 23bcac92b77b..77917552ae49 100644 --- a/.gitignore +++ b/.gitignore @@ -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 From 56fa98f726a1b844e637ff1a821c2e614e55eb12 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Oct 2023 16:24:00 +0100 Subject: [PATCH 2/4] lxd/daemon: Initialise server name and global config before patches And then reload them after patches have run in case its been modified. Signed-off-by: Thomas Parrott --- lxd/daemon.go | 71 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/lxd/daemon.go b/lxd/daemon.go index cee71ea88631..1bee124aea02 100644 --- a/lxd/daemon.go +++ b/lxd/daemon.go @@ -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) @@ -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() @@ -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() From 5235a06231b92fa4f2ef2775bfc3e98b59aaf103 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Oct 2023 16:45:47 +0100 Subject: [PATCH 3/4] lxd/patches: Only update volumes that need updating in patchStorageZfsUnsetInvalidBlockSettingsV2 Signed-off-by: Thomas Parrott Signed-off-by: Thomas Hipp --- lxd/patches.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lxd/patches.go b/lxd/patches.go index df9af2d805dc..6353e008467b 100644 --- a/lxd/patches.go +++ b/lxd/patches.go @@ -1096,8 +1096,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 From 942350ef274622e1857002f86902c964d61c111d Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Thu, 19 Oct 2023 20:14:19 +0200 Subject: [PATCH 4/4] lxd/patches: Only update volumes that need updating in patchStorageZfsUnsetInvalidBlockSettings Signed-off-by: Thomas Hipp --- lxd/patches.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lxd/patches.go b/lxd/patches.go index 6353e008467b..761ec578e83f 100644 --- a/lxd/patches.go +++ b/lxd/patches.go @@ -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