From 67f7174d3658219cce1c7d6ae87886b13a2406b4 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 10:03:11 +0000 Subject: [PATCH 1/8] Revert "lxd/instance/drivers/qemu: Return status `Error` for remote VM" This reverts commit d734721b3d3e2000dd71bfc1c2cb7c92ff8c298d. Breaks VM live migration. Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_qemu.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index 949c17bec401..c6fa4be6592d 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -8250,11 +8250,6 @@ func (d *qemu) InitPID() int { } func (d *qemu) statusCode() api.StatusCode { - // If instance is running on a remote cluster member, we cannot determine instance state. - if d.state.ServerName != d.Location() { - return api.Error - } - // Shortcut to avoid spamming QMP during ongoing operations. operationStatus := d.operationStatusCode() if operationStatus != nil { From 31edea2f68e9d43c40bf9238c9078df0e32180e7 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 10:13:22 +0000 Subject: [PATCH 2/8] Revert "lxd/instance/drivers/lxc: Return status `Error` for remote container" This reverts commit dbead142a69f8782d0111af90beafc4e9ecf822a. We reverted the qemu equivalent as it broke VM live migration so reverting this too. Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_lxc.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go index 31ef1cb7c12a..43e60b5f2080 100644 --- a/lxd/instance/drivers/driver_lxc.go +++ b/lxd/instance/drivers/driver_lxc.go @@ -8151,11 +8151,6 @@ func (d *lxc) NextIdmap() (*idmap.IdmapSet, error) { // statusCode returns instance status code. func (d *lxc) statusCode() api.StatusCode { - // If instance is running on a remote cluster member, we cannot determine instance state. - if d.state.ServerName != d.Location() { - return api.Error - } - // Shortcut to avoid spamming liblxc during ongoing operations. operationStatus := d.operationStatusCode() if operationStatus != nil { From f614e771368eee99c4acacc372513046f4b594cc Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 10:47:15 +0000 Subject: [PATCH 3/8] lxd/instance/drivers/driver/qemu: Improve comment for size in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_qemu.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index c6fa4be6592d..cfb59cc40c7e 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -7783,7 +7783,10 @@ func (d *qemu) Render(options ...func(response any) error) (state any, etag any, LastUsedAt: d.lastUsedDate, Name: strings.SplitN(d.name, "/", 2)[1], Stateful: d.stateful, - Size: -1, // Default to uninitialised/error state (0 means no CoW usage). + + // Default to uninitialised/error state (0 means no CoW usage). + // The size can then be populated optionally via the options argument. + Size: -1, } snapState.Architecture = d.architectureName From 39e396b4179d3bdb4464f4ec726f795c3a14372f Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 10:47:45 +0000 Subject: [PATCH 4/8] lxd/instance/drivers/driver/qemu: Only call statusCode for local instances in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_qemu.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index cfb59cc40c7e..f86f6ec6a031 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -7808,18 +7808,23 @@ func (d *qemu) Render(options ...func(response any) error) (state any, etag any, // Prepare the ETag etag = []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles} - statusCode := d.statusCode() instState := api.Instance{ ExpandedConfig: d.expandedConfig, ExpandedDevices: d.expandedDevices.CloneNative(), Name: d.name, - Status: statusCode.String(), - StatusCode: statusCode, Location: d.node, Type: d.Type().String(), + StatusCode: api.Error, // Default to error status for remote instances that are unreachable. + } + + // If instance is local then request status. + if d.state.ServerName == d.Location() { + instState.StatusCode = d.statusCode() } + instState.Status = instState.StatusCode.String() + instState.Description = d.description instState.Architecture = d.architectureName instState.Config = d.localConfig From b88c124606bd3547c2a032a814450874e14818b2 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 10:56:20 +0000 Subject: [PATCH 5/8] lxd/instance/drivers/driver/qemu: Populate structs directly in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_qemu.go | 40 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index f86f6ec6a031..4d9d3efcac83 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -7777,11 +7777,17 @@ func (d *qemu) Render(options ...func(response any) error) (state any, etag any, etag := []any{d.expiryDate} snapState := api.InstanceSnapshot{ - CreatedAt: d.creationDate, + Name: strings.SplitN(d.name, "/", 2)[1], + Architecture: d.architectureName, + Profiles: profileNames, + Config: d.localConfig, ExpandedConfig: d.expandedConfig, + Devices: d.localDevices.CloneNative(), ExpandedDevices: d.expandedDevices.CloneNative(), + CreatedAt: d.creationDate, LastUsedAt: d.lastUsedDate, - Name: strings.SplitN(d.name, "/", 2)[1], + ExpiresAt: d.expiryDate, + Ephemeral: d.ephemeral, Stateful: d.stateful, // Default to uninitialised/error state (0 means no CoW usage). @@ -7789,13 +7795,6 @@ func (d *qemu) Render(options ...func(response any) error) (state any, etag any, Size: -1, } - snapState.Architecture = d.architectureName - snapState.Config = d.localConfig - snapState.Devices = d.localDevices.CloneNative() - snapState.Ephemeral = d.ephemeral - snapState.Profiles = profileNames - snapState.ExpiresAt = d.expiryDate - for _, option := range options { err := option(&snapState) if err != nil { @@ -7810,9 +7809,19 @@ func (d *qemu) Render(options ...func(response any) error) (state any, etag any, etag = []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles} instState := api.Instance{ + Name: d.name, + Description: d.description, + Architecture: d.architectureName, + Profiles: profileNames, + Config: d.localConfig, ExpandedConfig: d.expandedConfig, + Devices: d.localDevices.CloneNative(), ExpandedDevices: d.expandedDevices.CloneNative(), - Name: d.name, + CreatedAt: d.creationDate, + LastUsedAt: d.lastUsedDate, + Ephemeral: d.ephemeral, + Stateful: d.stateful, + Project: d.project.Name, Location: d.node, Type: d.Type().String(), StatusCode: api.Error, // Default to error status for remote instances that are unreachable. @@ -7825,17 +7834,6 @@ func (d *qemu) Render(options ...func(response any) error) (state any, etag any, instState.Status = instState.StatusCode.String() - instState.Description = d.description - instState.Architecture = d.architectureName - instState.Config = d.localConfig - instState.CreatedAt = d.creationDate - instState.Devices = d.localDevices.CloneNative() - instState.Ephemeral = d.ephemeral - instState.LastUsedAt = d.lastUsedDate - instState.Profiles = profileNames - instState.Stateful = d.stateful - instState.Project = d.project.Name - for _, option := range options { err := option(&instState) if err != nil { From 0ef7f0daa311d90189ae992a5d9589a12764589a Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 10:58:22 +0000 Subject: [PATCH 6/8] lxd/instance/drivers/driver/lxc: Only call statusCode for local instances in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_lxc.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go index 43e60b5f2080..4a5748f5b868 100644 --- a/lxd/instance/drivers/driver_lxc.go +++ b/lxd/instance/drivers/driver_lxc.go @@ -3283,17 +3283,22 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, // Prepare the ETag etag = []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles} - statusCode := d.statusCode() instState := api.Instance{ ExpandedConfig: d.expandedConfig, ExpandedDevices: d.expandedDevices.CloneNative(), Name: d.name, - Status: statusCode.String(), - StatusCode: statusCode, + StatusCode: api.Error, // Default to error status for remote instances that are unreachable. Location: d.node, Type: d.Type().String(), } + // If instance is local then request status. + if d.state.ServerName == d.Location() { + instState.StatusCode = d.statusCode() + } + + instState.Status = instState.StatusCode.String() + instState.Description = d.description instState.Architecture = architectureName instState.Config = d.localConfig From a374b0bd450bd9d12128b1269e24426564550a01 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 11:00:55 +0000 Subject: [PATCH 7/8] lxd/instance/drivers/driver/lxc: Improve comment for size in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_lxc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go index 4a5748f5b868..77814c34fee5 100644 --- a/lxd/instance/drivers/driver_lxc.go +++ b/lxd/instance/drivers/driver_lxc.go @@ -3260,7 +3260,10 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, LastUsedAt: d.lastUsedDate, Name: strings.SplitN(d.name, "/", 2)[1], Stateful: d.stateful, - Size: -1, // Default to uninitialised/error state (0 means no CoW usage). + + // Default to uninitialised/error state (0 means no CoW usage). + // The size can then be populated optionally via the options argument. + Size: -1, } snapState.Architecture = architectureName From b056e081d265c4eac464cb3426f76dbce1aaddd2 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 11:06:59 +0000 Subject: [PATCH 8/8] lxd/instance/drivers/driver/lxc: Populate structs directly in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_lxc.go | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go index 77814c34fee5..f090804800cb 100644 --- a/lxd/instance/drivers/driver_lxc.go +++ b/lxd/instance/drivers/driver_lxc.go @@ -3254,11 +3254,17 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, etag := []any{d.expiryDate} snapState := api.InstanceSnapshot{ - CreatedAt: d.creationDate, + Name: strings.SplitN(d.name, "/", 2)[1], + Architecture: architectureName, + Profiles: profileNames, + Config: d.localConfig, ExpandedConfig: d.expandedConfig, + Devices: d.localDevices.CloneNative(), ExpandedDevices: d.expandedDevices.CloneNative(), + CreatedAt: d.creationDate, LastUsedAt: d.lastUsedDate, - Name: strings.SplitN(d.name, "/", 2)[1], + ExpiresAt: d.expiryDate, + Ephemeral: d.ephemeral, Stateful: d.stateful, // Default to uninitialised/error state (0 means no CoW usage). @@ -3266,13 +3272,6 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, Size: -1, } - snapState.Architecture = architectureName - snapState.Config = d.localConfig - snapState.Devices = d.localDevices.CloneNative() - snapState.Ephemeral = d.ephemeral - snapState.Profiles = profileNames - snapState.ExpiresAt = d.expiryDate - for _, option := range options { err := option(&snapState) if err != nil { @@ -3287,12 +3286,22 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, etag = []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles} instState := api.Instance{ + Name: d.name, + Description: d.description, + Architecture: architectureName, + Profiles: profileNames, + Config: d.localConfig, ExpandedConfig: d.expandedConfig, + Devices: d.LocalDevices().CloneNative(), ExpandedDevices: d.expandedDevices.CloneNative(), - Name: d.name, - StatusCode: api.Error, // Default to error status for remote instances that are unreachable. + CreatedAt: d.creationDate, + LastUsedAt: d.lastUsedDate, + Ephemeral: d.ephemeral, + Stateful: d.stateful, + Project: d.project.Name, Location: d.node, Type: d.Type().String(), + StatusCode: api.Error, // Default to error status for remote instances that are unreachable. } // If instance is local then request status. @@ -3302,17 +3311,6 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, instState.Status = instState.StatusCode.String() - instState.Description = d.description - instState.Architecture = architectureName - instState.Config = d.localConfig - instState.CreatedAt = d.creationDate - instState.Devices = d.localDevices.CloneNative() - instState.Ephemeral = d.ephemeral - instState.LastUsedAt = d.lastUsedDate - instState.Profiles = profileNames - instState.Stateful = d.stateful - instState.Project = d.project.Name - for _, option := range options { err := option(&instState) if err != nil {