[lxc-devel] [lxd/master] Fix thinpool typo
AndrewElvisDeng on Github
lxc-bot at linuxcontainers.org
Sun Oct 11 19:14:31 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 473 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201011/6a03f475/attachment.bin>
-------------- next part --------------
From 47d218473ca0ecf9fd8af16bad056c5549a018f6 Mon Sep 17 00:00:00 2001
From: Andrew Deng <adeng1433 at gmail.com>
Date: Fri, 2 Oct 2020 15:46:30 -0500
Subject: [PATCH 1/3] fixed typo in storage_pools.go
---
lxd/db/storage_pools.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index e27a3d1e12..76d12693d1 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -885,7 +885,7 @@ var StoragePoolNodeConfigKeys = []string{
"source",
"volatile.initial_source",
"zfs.pool_name",
- "lvm.thinpool",
+ "lvm.thinpool_name",
"lvm.vg_name",
}
From 24f0a70f543ae88bce0eb4f3e021081f400dc90d Mon Sep 17 00:00:00 2001
From: Andrew Deng <adeng1433 at gmail.com>
Date: Fri, 2 Oct 2020 17:30:49 -0500
Subject: [PATCH 2/3] initial patch fix implementation done
---
lxd/patches.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/lxd/patches.go b/lxd/patches.go
index 170976700f..54967ecffd 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -101,6 +101,7 @@ var patches = []patch{
{name: "clustering_drop_database_role", stage: patchPostDaemonStorage, run: patchClusteringDropDatabaseRole},
{name: "network_clear_bridge_volatile_hwaddr", stage: patchPostDaemonStorage, run: patchNetworkCearBridgeVolatileHwaddr},
{name: "move_backups_instances", stage: patchPostDaemonStorage, run: patchMoveBackupsInstances},
+ {name: "TEMPNAME", stage: TEMP, run: patchTEMPNAME},
}
type patch struct {
@@ -165,6 +166,68 @@ func patchesApply(d *Daemon, stage patchStage) error {
// Patches begin here
+//
+func patchTEMPNAME(name string, d *Daemon) error {
+ tx, err := d.cluster.Begin()
+ if err != nil {
+ return errors.Wrap(err, "failed to begin transaction")
+ }
+
+ // Fetch the IDs of all existing nodes.
+ nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes")
+ if err != nil {
+ return errors.Wrap(err, "failed to get IDs of current nodes")
+ }
+
+ // Fetch the IDs of all existing lvm pools.
+ poolIDs, err := query.SelectIntegers(tx, "SELECT id FROM storage_pools WHERE driver='lvm'")
+ if err != nil {
+ return errors.Wrap(err, "failed to get IDs of current lvm pools")
+ }
+
+ for _, poolID := range poolIDs {
+ // Fetch the config for this lvm pool and check if it has the
+ // lvn.thinpool_name key.
+ config, err := query.SelectConfig(
+ tx, "storage_pools_config", "storage_pool_id=?", poolID)
+ if err != nil {
+ return errors.Wrap(err, "failed a fetch of lvm pool config")
+ }
+
+ value, ok := "lvm.thinpool"
+ if !ok {
+ continue
+ }
+
+ // Delete the current key
+ _, err = tx.Exec(`
+ DELETE FROM storage_pools_config WHERE key='lvm.thinpool' AND storage_pool_id=?`, poolID)
+ if err != nil {
+ return errors.Wrapf(err, "failed to delete %s config", key)
+ }
+
+ // Add the config entry for each node
+ for _, nodeID := range nodeIDs {
+ _, err := tx.Exec(`
+ INSERT INTO storage_pools_config(storage_pool_id, node_id, key, value)
+ VALUES(?, ?, 'lvm.thinpool_name', ?)
+ `, poolID, curNodeID, value)
+ if err != nil {
+ return errors.Wrapf(err, "failed to create %s node config", key)
+ }
+ }
+ }
+ }
+
+ err = tx.Commit()
+ if err != nil {
+ return errors.Wrap(err, "failed to commit transaction")
+ }
+
+ return err
+
+}
+
// Moves backups from shared.VarPath("backups") to shared.VarPath("backups", "instances").
func patchMoveBackupsInstances(name string, d *Daemon) error {
if !shared.PathExists(shared.VarPath("backups")) {
From 133825f12eabc5c8fef70049d8504a1c6ba6b908 Mon Sep 17 00:00:00 2001
From: Andrew Deng <adeng1433 at gmail.com>
Date: Sun, 11 Oct 2020 14:10:11 -0500
Subject: [PATCH 3/3] renamed functions, comments, adhered to patches.go's
style
---
lxd/patches.go | 128 ++++++++++++++++++++++++-------------------------
1 file changed, 63 insertions(+), 65 deletions(-)
diff --git a/lxd/patches.go b/lxd/patches.go
index 54967ecffd..25d7af4d1d 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -101,7 +101,7 @@ var patches = []patch{
{name: "clustering_drop_database_role", stage: patchPostDaemonStorage, run: patchClusteringDropDatabaseRole},
{name: "network_clear_bridge_volatile_hwaddr", stage: patchPostDaemonStorage, run: patchNetworkCearBridgeVolatileHwaddr},
{name: "move_backups_instances", stage: patchPostDaemonStorage, run: patchMoveBackupsInstances},
- {name: "TEMPNAME", stage: TEMP, run: patchTEMPNAME},
+ {name: "thinpool_typo_fix", stage: patchPostDaemonStorage, run: patchThinpoolTypoFix},
}
type patch struct {
@@ -164,70 +164,6 @@ func patchesApply(d *Daemon, stage patchStage) error {
return nil
}
-// Patches begin here
-
-//
-func patchTEMPNAME(name string, d *Daemon) error {
- tx, err := d.cluster.Begin()
- if err != nil {
- return errors.Wrap(err, "failed to begin transaction")
- }
-
- // Fetch the IDs of all existing nodes.
- nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes")
- if err != nil {
- return errors.Wrap(err, "failed to get IDs of current nodes")
- }
-
- // Fetch the IDs of all existing lvm pools.
- poolIDs, err := query.SelectIntegers(tx, "SELECT id FROM storage_pools WHERE driver='lvm'")
- if err != nil {
- return errors.Wrap(err, "failed to get IDs of current lvm pools")
- }
-
- for _, poolID := range poolIDs {
- // Fetch the config for this lvm pool and check if it has the
- // lvn.thinpool_name key.
- config, err := query.SelectConfig(
- tx, "storage_pools_config", "storage_pool_id=?", poolID)
- if err != nil {
- return errors.Wrap(err, "failed a fetch of lvm pool config")
- }
-
- value, ok := "lvm.thinpool"
- if !ok {
- continue
- }
-
- // Delete the current key
- _, err = tx.Exec(`
- DELETE FROM storage_pools_config WHERE key='lvm.thinpool' AND storage_pool_id=?`, poolID)
- if err != nil {
- return errors.Wrapf(err, "failed to delete %s config", key)
- }
-
- // Add the config entry for each node
- for _, nodeID := range nodeIDs {
- _, err := tx.Exec(`
- INSERT INTO storage_pools_config(storage_pool_id, node_id, key, value)
- VALUES(?, ?, 'lvm.thinpool_name', ?)
- `, poolID, curNodeID, value)
- if err != nil {
- return errors.Wrapf(err, "failed to create %s node config", key)
- }
- }
- }
- }
-
- err = tx.Commit()
- if err != nil {
- return errors.Wrap(err, "failed to commit transaction")
- }
-
- return err
-
-}
-
// Moves backups from shared.VarPath("backups") to shared.VarPath("backups", "instances").
func patchMoveBackupsInstances(name string, d *Daemon) error {
if !shared.PathExists(shared.VarPath("backups")) {
@@ -3777,3 +3713,65 @@ func patchUpdateFromV30(_ *sql.Tx) error {
return nil
}
+
+//renames any config incorrectly set config file entries due to the lvm.thinpool_name typo
+func patchThinpoolTypoFix(name string, d *Daemon) error {
+ tx, err := d.cluster.Begin()
+ if err != nil {
+ return errors.Wrap(err, "failed to begin transaction")
+ }
+
+ // Fetch the IDs of all existing nodes.
+ nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes")
+ if err != nil {
+ return errors.Wrap(err, "failed to get IDs of current nodes")
+ }
+
+ // Fetch the IDs of all existing lvm pools.
+ poolIDs, err := query.SelectIntegers(tx, "SELECT id FROM storage_pools WHERE driver='lvm'")
+ if err != nil {
+ return errors.Wrap(err, "failed to get IDs of current lvm pools")
+ }
+
+ for _, poolID := range poolIDs {
+ // Fetch the config for this lvm pool and check if it has the
+ // lvn.thinpool_name key.
+ config, err := query.SelectConfig(
+ tx, "storage_pools_config", "storage_pool_id=?", poolID)
+ if err != nil {
+ return errors.Wrap(err, "failed a fetch of lvm pool config")
+ }
+
+ value, ok := "lvm.thinpool"
+ if !ok {
+ continue
+ }
+
+ // Delete the current key
+ _, err = tx.Exec(`
+ DELETE FROM storage_pools_config WHERE key='lvm.thinpool' AND storage_pool_id=?`, poolID)
+ if err != nil {
+ return errors.Wrapf(err, "failed to delete %s config", key)
+ }
+
+ // Add the config entry for each node
+ for _, nodeID := range nodeIDs {
+ _, err := tx.Exec(`
+ INSERT INTO storage_pools_config(storage_pool_id, node_id, key, value)
+ VALUES(?, ?, 'lvm.thinpool_name', ?)
+ `, poolID, curNodeID, value)
+ if err != nil {
+ return errors.Wrapf(err, "failed to create %s node config", key)
+ }
+ }
+ }
+ }
+
+ err = tx.Commit()
+ if err != nil {
+ return errors.Wrap(err, "failed to commit transaction")
+ }
+
+ return err
+
+}
\ No newline at end of file
More information about the lxc-devel
mailing list