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

Backports (stable-5.0) #13215

Merged
merged 119 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
33fd909
lxd/instance/drivers/qemu: do not check for `size.state` if shared st…
gabrielmougard Jan 29, 2024
e8d1841
github: ask bug reporters to provide the list of relevant snaps
simondeziel Feb 9, 2024
28ce2eb
lxd/storage/drivers/generic_vfs: Return if the right file was found
roosterfish Feb 9, 2024
d5b1223
Fix linter errors (revive: exported).
markylaing Feb 10, 2024
f74f9ea
lxd/cluster: Fix lint error (revive: early-return).
markylaing Feb 6, 2024
f63996b
lxd: Fix lint errors (revive: exported).
markylaing Feb 9, 2024
8344f24
lxd: Ignore lint error (revive: defer).
markylaing Feb 9, 2024
5cea035
lxd/storage/drivers: Add VolumeCopy struct
roosterfish Feb 12, 2024
96f878d
lxd/device: Fix lint error (revive: exported).
markylaing Feb 9, 2024
650309c
lxd/device: Fix lint errors (revive: useless-break).
markylaing Feb 9, 2024
840d5ba
lxd/instance/drivers: Fix lint errors (revive: confusing-results).
markylaing Feb 9, 2024
ddc8acd
lxd/network: Fix lint errors (revive: exported).
markylaing Feb 9, 2024
321805f
lxd/network: Fix lint errors (revive: comment-spacings).
markylaing Feb 9, 2024
2f00f7a
lxd/project: Fix lint errors (revive: confusing-results).
markylaing Feb 9, 2024
ace7cdc
lxd: Fix lint error (revive: unchecked-type-assertion).
markylaing Feb 9, 2024
1b2673b
lxd/storage/drivers/interface: Change function signatures
roosterfish Feb 12, 2024
f3f0e7f
lxd/storage/drivers/generic_vfs: Use updated snapshots slice
roosterfish Feb 13, 2024
dc00ec5
client: Remove `WithUnsecure` from cookie handler options.
markylaing Feb 13, 2024
29bc668
lxd/storage/drivers/generic_vfs: Use VolumeCopy struct
roosterfish Feb 13, 2024
c6e937e
lxd/storage/drivers/btrfs: Use updated driver interface
roosterfish Feb 12, 2024
c68cf79
lxd/storage/drivers/ceph: Use updated driver interface
roosterfish Feb 12, 2024
775871d
lxd/storage/drivers/cephfs: Use updated driver interface
roosterfish Feb 12, 2024
c61fae1
lxd/storage/drivers/dir: Use updated driver interface
roosterfish Feb 12, 2024
41707d6
lxd/storage/drivers/lvm: Use updated driver interface
roosterfish Feb 12, 2024
f965f28
lxd/storage/drivers/zfs: Use updated driver interface
roosterfish Feb 12, 2024
6fcd4ca
lxd/storage/drivers/common: Use updated driver interface
roosterfish Feb 12, 2024
b07a7c6
lxd/storage/drivers/mock: Use updated driver interface
roosterfish Feb 12, 2024
7d2d556
github: build lxc and lxd-migrate binaries with trimpath
simondeziel Feb 13, 2024
3a4cb54
github: strip lxc and lxd-migrate native binaries
simondeziel Feb 13, 2024
86be7d1
lxd/storage/backend_lxd: Update storage driver invocations
roosterfish Feb 12, 2024
a219cfb
lxd/storage/backend_lxd: Don't validate custom storage volumes twice
roosterfish Feb 12, 2024
73218dc
github: build lxc and lxd-migrate binaries with trimpath
simondeziel Feb 13, 2024
a0de3fc
doc: build lxc with trimpath and without debug info
simondeziel Feb 13, 2024
21b77f0
github: use regex matching to purge disabled snaps
simondeziel Feb 13, 2024
645f907
lxd/instance/drivers/qemu: Handle SELinux for LXD agent
stgraber Feb 12, 2024
b8e7401
lxd/storage/backend_lxd: Don't use storage name when creating source …
roosterfish Feb 14, 2024
8abd194
github: add labels when PRs target LTS branches
simondeziel Feb 14, 2024
d63edf2
lxd/storage/backend_lxd: Append the snapshots creation date
roosterfish Feb 14, 2024
f80697a
lxd/migrate_storage_volumes: Send snapshot creation timestamp
roosterfish Feb 15, 2024
d73bbba
lxd-generate: Return helpful error instead of panicking.
markylaing Feb 15, 2024
3a1d1a8
lxd/storage/backend_lxd: Block volume's volatile.uuid from modification
roosterfish Feb 5, 2024
362991a
lxd/storage/backend_lxd: Use quotes consistently for error messages
roosterfish Feb 14, 2024
423b13e
lxd/storage/drivers/volume: Set the snapshots parent in NewVolumeCopy
roosterfish Feb 15, 2024
4deec4b
lxd/storage/drivers/generic_vfs: Handle volatile.uuid for volume imports
roosterfish Feb 8, 2024
15695b2
lxd/storage/drivers/generic_vfs: Handle volatile.uuid for volume exports
roosterfish Feb 8, 2024
afffe42
lxd/storage/drivers/generic_vfs: Handle volatile.uuid for volume migr…
roosterfish Feb 8, 2024
90dcd9f
test: Pass the storage pool name into the snapshots suite
roosterfish Feb 14, 2024
b02ae84
lxd/storage/drivers/zfs: Pass snapshots when copying
roosterfish Feb 15, 2024
156b92b
lxd/storage/drivers/ceph: Pass snapshots when copying
roosterfish Feb 15, 2024
52aefc8
lxd/project: Don't panic on StorageVolumeParts
roosterfish Feb 16, 2024
8c6388d
lxd/storage/drivers/generic_vfs: Use VolumeCopy for genericVFSCopyVolume
roosterfish Feb 16, 2024
e130288
lxd/storage/drivers/btrfs: Pass the CopyVolume struct to genericVFSCo…
roosterfish Feb 16, 2024
4d51a5e
lxd/storage/drivers/ceph: Pass the CopyVolume struct to genericVFSCop…
roosterfish Feb 16, 2024
a84e512
lxd/storage/drivers/dir: Pass the CopyVolume struct to genericVFSCopy…
roosterfish Feb 16, 2024
fb19fe5
lxd/storage/drivers/lvm: Pass the CopyVolume struct to genericVFSCopy…
roosterfish Feb 16, 2024
6564c65
lxd/storage/drivers/zfs: Pass the CopyVolume struct to genericVFSCopy…
roosterfish Feb 16, 2024
c75e1c8
lxd/storage/drivers/interface: Add HasVolumeSnapshots function
roosterfish Feb 19, 2024
1b8498c
lxd/storage/drivers/common: Implement HasVolumeSnapshots
roosterfish Feb 19, 2024
5ca8774
lxd/storage/drivers: Replace vol.SnapshotsMatch with driver.HasVolume…
roosterfish Feb 19, 2024
997ef29
lxd/storage/drivers/volume: Remove SnapshotsMatch
roosterfish Feb 19, 2024
4d8e294
github: don't abort on remount failures
simondeziel Feb 19, 2024
457b3ff
lxd/storage/pool_interface: Remove deleteMissing from CheckInstanceBa…
roosterfish Feb 19, 2024
f728362
lxd/api_internal: Remove deleteMissing from CheckInstanceBackupFileSn…
roosterfish Feb 19, 2024
985e97d
lxd/storage/backend_mock: Remove deleteMissing from CheckInstanceBack…
roosterfish Feb 19, 2024
26400c2
lxd/storage/backend_lxd: Move the snapshot comparison logic into the …
roosterfish Feb 19, 2024
d5b93fd
lxd/storage/backend_lxd: Remove deleteMissing from CheckInstanceBacku…
roosterfish Feb 19, 2024
09d30ce
incusd: Correctly update event location
stgraber Jan 18, 2024
94b4747
incusd/events: Upgrade to websocket as late as possible
stgraber Jan 18, 2024
2668094
internal/server/db: Remove function `doDbScan`
monstermunchkin Nov 17, 2023
631e906
internal/server: Use `Retry` function
monstermunchkin Nov 17, 2023
15ae713
internal/server/db: Unwrap dbQueryRowScan function
monstermunchkin Nov 17, 2023
7cb0585
internal/server/db: Unwrap queryScan function
monstermunchkin Nov 17, 2023
e309583
internal/server/db: Remove exec function
monstermunchkin Nov 17, 2023
2c4cd28
lxd/dns: Serialize DNS queries
stgraber Jan 27, 2024
b1e67a0
lxd/backups: Simplify missing backup errors
stgraber Jan 27, 2024
44c764d
tests: Update for current backup errors
stgraber Jan 27, 2024
42735e8
lxd/cluster: Optimize ConnectIfInstanceIsRemote
stgraber Jan 27, 2024
cff8b66
lxd/backup/utils: Ensure the volume's config gets updated too
roosterfish Feb 20, 2024
2891d38
lxd/storage/backend_lxd: Block volume's volatile.uuid from modification
roosterfish Feb 5, 2024
5b141a1
lxd/storage/backend_lxd: Set volume's volatile.uuid for storage drive…
roosterfish Feb 5, 2024
7784e33
lxd/storage/backend_lxd: Consistently use GetNewVolume for config gen…
roosterfish Feb 19, 2024
1f3deaf
lxd/storage/drivers/volume: Deep copy the volume's config when instan…
roosterfish Feb 16, 2024
f43a21a
lxd/resources/storage: Add GetDisksByID function
roosterfish Oct 16, 2023
7106e42
lxd/instance/qemu: No `size.state` checks at startup needed
gabrielmougard Feb 19, 2024
5f71a54
lxd/request: Add a generic methods for getting and setting context va…
markylaing Feb 19, 2024
04552b3
lxd/request: Adds an effective project name context key.
markylaing Feb 20, 2024
4d700c1
test/suites: Ensure restricted clients can list inherited resources.
markylaing Feb 20, 2024
75704eb
lxd/instance/drivers/qemu: Revert linter fix
roosterfish Feb 21, 2024
6067ca1
lxd/storage/backend_lxd: Don't instantiate a new volume if existent d…
roosterfish Feb 21, 2024
6803a8f
lxd/storage/drivers/generic: Use VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
f88ef44
lxd/storage/drivers/zfs: Pass VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
c36eeed
lxd/storage/drivers/lvm: Pass VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
da312fd
lxd/storage/drivers/dir: Pass VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
2a4f7ff
lxd/storage/drivers/cephfs: Pass VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
75e9a65
lxd/storage/drivers/ceph: Pass VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
15141ea
lxd/storage/drivers/btrfs: Pass VolumeCopy for genericVFSMigrateVolume
roosterfish Feb 21, 2024
e4cb448
test/main: add log grouping (GHA)
simondeziel Feb 21, 2024
f3423d1
test/main: show dmesg on failure
simondeziel Feb 21, 2024
1c6e998
github: capture dmesg if setting up microceph fails
simondeziel Feb 21, 2024
ecaf768
lxd/db/networks: Differentiate not found errors from other errors in …
tomponline Feb 22, 2024
2ea5a29
lxd/networks/utils: Don't log not found errors in networkAutoAttach
tomponline Feb 22, 2024
5a26893
lxd/devices: Log the device concerning the error from networkAutoAttach
tomponline Feb 22, 2024
d86aa62
lxd/patches: Remove VM block vols from patchStorageUnsetInvalidBlockS…
roosterfish Feb 22, 2024
5266042
lxd/storage/drivers/ceph: Don't unset the block.* settings for VMs
roosterfish Feb 22, 2024
c0635d0
lxd/storage/drivers/lvm: Don't unset the block.* settings for VMs
roosterfish Feb 22, 2024
cd6d58d
lxd/api/internal: Use correct quoting for error in internalImportFrom…
tomponline Feb 22, 2024
e12f8fa
lxd/db/cluster/devices: Use correct string quoting of device type for…
tomponline Feb 22, 2024
7b512a2
lxd/instances/post: Improve error in createFromBackup
tomponline Feb 22, 2024
f5bd4f1
lxd/storage/backend/lxd: Update backup.yaml after instance and volume…
tomponline Feb 22, 2024
989393a
lxd: Move `ExpandInstanceConfig` and `ExpandInstanceDevices` from `lx…
gabrielmougard Feb 7, 2024
5f889b5
lxd: Removes duplicate implementation of ExpandInstanceConfig and Exp…
tomponline Feb 22, 2024
2e9c9ac
lxd/endpoints/network/util/test: Remove incus references in Test_netw…
tomponline Feb 22, 2024
491112d
lxd/storage/backend_lxd: Pass right volume name when refreshing custo…
roosterfish Feb 22, 2024
050f86b
client/lxd/instances: Adds API extension check for device override on…
tomponline Feb 23, 2024
dd485e9
github: build lxd-benchmark binaries and upload as artifacts
simondeziel Feb 24, 2024
88d9924
github: exit on error in microceph setup step
simondeziel Feb 26, 2024
b9518eb
test/main: don't wrap tests logs in log groups
simondeziel Feb 26, 2024
6eed569
lxc: Remove unnecessary client import alias.
markylaing Feb 27, 2024
6be15fc
client: Add Devices field to InstanceBackupArgs
tomponline Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Feel free to remove anything which doesn't apply to you and add more information

* Distribution:
* Distribution version:
* The output of "snap list --all lxd core20 core22 core24 snapd":
* The output of "lxc info" or if that fails:
* Kernel version:
* LXC version:
Expand Down
9 changes: 9 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ Documentation:
- changed-files:
- any-glob-to-any-file:
- doc/**/*

"5.21 LTS":
- base-branch: 'stable-5.21'

"5.0 LTS":
- base-branch: 'stable-5.0'

"4.0 LTS":
- base-branch: 'stable-4.0'
22 changes: 16 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
# optimize ext4 FSes for performance, not reliability
for fs in $(findmnt --noheading --type ext4 --list --uniq | awk '{print $1}'); do
# nombcache and data=writeback cannot be changed on remount
sudo mount -o remount,noatime,barrier=0,commit=6000 "${fs}"
sudo mount -o remount,noatime,barrier=0,commit=6000 "${fs}" || true
done

# disable dpkg from calling sync()
Expand All @@ -174,7 +174,7 @@ jobs:
sudo snap remove lxd --purge
# Purge older snap revisions that are disabled/superseded by newer revisions of the same snap
snap list --all | while read -r name _ rev _ _ notes _; do
[ "${notes}" = "disabled" ] && snap remove "${name}" --revision "${rev}" --purge
[[ "${notes}" =~ disabled$ ]] && snap remove "${name}" --revision "${rev}" --purge
done || true

# This was inspired from https://github.com/easimon/maximize-build-space
Expand Down Expand Up @@ -391,22 +391,32 @@ jobs:
CGO_ENABLED: 0
GOARCH: amd64
run: |
go build -o bin/lxc.x86_64 ./lxc
go build -ldflags "-s -w" -o trimpath -o bin/lxc.x86_64 ./lxc

- name: Build static lxc (aarch64)
env:
CGO_ENABLED: 0
GOARCH: arm64
run: |
go build -o bin/lxc.aarch64 ./lxc
go build -ldflags "-s -w" -o trimpath -o bin/lxc.aarch64 ./lxc

- name: Build static lxd-benchmark
if: runner.os == 'Linux'
env:
CGO_ENABLED: 0
run: |
set -eux
GOARCH=amd64 go build -ldflags "-s -w" -o trimpath -o bin/lxd-benchmark.x86_64 ./lxd-benchmark
GOARCH=arm64 go build -ldflags "-s -w" -o trimpath -o bin/lxd-benchmark.aarch64 ./lxd-benchmark

- name: Build static lxd-migrate
if: runner.os == 'Linux'
env:
CGO_ENABLED: 0
run: |
GOARCH=amd64 go build -o bin/lxd-migrate.x86_64 ./lxd-migrate
GOARCH=arm64 go build -o bin/lxd-migrate.aarch64 ./lxd-migrate
set -eux
GOARCH=amd64 go build -ldflags "-s -w" -o trimpath -o bin/lxd-migrate.x86_64 ./lxd-migrate
GOARCH=arm64 go build -ldflags "-s -w" -o trimpath -o bin/lxd-migrate.aarch64 ./lxd-migrate

- name: Unit tests (client)
env:
Expand Down
3 changes: 3 additions & 0 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ type InstanceBackupArgs struct {

// Name to import backup as
Name string

// If set, it would override devices
Devices map[string]map[string]string
}

// The InstanceCopyArgs struct is used to pass additional options during instance copy.
Expand Down
24 changes: 23 additions & 1 deletion client/lxd_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (r *ProtocolLXD) CreateInstanceFromBackup(args InstanceBackupArgs) (Operati
return nil, err
}

if args.PoolName == "" && args.Name == "" {
if args.PoolName == "" && args.Name == "" && len(args.Devices) == 0 {
// Send the request
op, _, err := r.queryOperation("POST", path, args.BackupFile, "", true)
if err != nil {
Expand All @@ -569,6 +569,13 @@ func (r *ProtocolLXD) CreateInstanceFromBackup(args InstanceBackupArgs) (Operati
}
}

if len(args.Devices) > 0 {
err = r.CheckExtension("import_instance_devices")
if err != nil {
return nil, fmt.Errorf("Cannot use device override: %w", err)
}
}

// Prepare the HTTP request
reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path))
if err != nil {
Expand All @@ -590,6 +597,21 @@ func (r *ProtocolLXD) CreateInstanceFromBackup(args InstanceBackupArgs) (Operati
req.Header.Set("X-LXD-name", args.Name)
}

if len(args.Devices) > 0 {
devProps := url.Values{}

for dev := range args.Devices {
props := url.Values{}
for k, v := range args.Devices[dev] {
props.Set(k, v)
}

devProps.Set(dev, props.Encode())
}

req.Header.Set("X-LXD-devices", devProps.Encode())
}

// Send the request
resp, err := r.DoHTTP(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/lxd_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (o *oidcClient) getProvider(issuer string, clientID string) (rp.RelyingPart
return nil, err
}

cookieHandler := httphelper.NewCookieHandler(hashKey, encryptKey, httphelper.WithUnsecure())
cookieHandler := httphelper.NewCookieHandler(hashKey, encryptKey)
options := []rp.Option{
rp.WithCookieHandler(cookieHandler),
rp.WithVerifierOpts(rp.WithIssuedAtOffset(5 * time.Second)),
Expand Down
3 changes: 3 additions & 0 deletions doc/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ build:
tools:
golang: "1.19"
python: "3.11"
jobs:
pre_build:
- go build -ldflags "-s -w" -o trimpath -o lxc.bin ./lxc

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand Down
7 changes: 7 additions & 0 deletions lxc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ To easily setup a local LXD server in a virtual machine, consider using: https:/
}
}

// PreRun is set as the (*cobra.Command).PersistentPreRunE for the top level lxc command. It loads configuration and
// performs additional checks if it detects that LXD has not been configured yet.
func (c *cmdGlobal) PreRun(cmd *cobra.Command, args []string) error {
var err error

Expand Down Expand Up @@ -416,6 +418,8 @@ Or for a virtual machine: lxc launch ubuntu:22.04 --vm`)+"\n")
return nil
}

// PostRun is set as the (*cobra.Command).PersistentPostRunE hook on the top level lxc command.
// It saves any configuration that must persist between runs.
func (c *cmdGlobal) PostRun(cmd *cobra.Command, args []string) error {
// Macaroon teardown
if c.conf != nil && shared.PathExists(c.confPath) {
Expand All @@ -432,6 +436,8 @@ type remoteResource struct {
name string
}

// ParseServers parses a list of remotes (`<remote>:<resource>...`) and calls (*config.Config).GetInstanceServer
// for each remote to configure a new connection.
func (c *cmdGlobal) ParseServers(remotes ...string) ([]remoteResource, error) {
servers := map[string]lxd.InstanceServer{}
resources := []remoteResource{}
Expand Down Expand Up @@ -471,6 +477,7 @@ func (c *cmdGlobal) ParseServers(remotes ...string) ([]remoteResource, error) {
return resources, nil
}

// CheckArgs checks that the given list of arguments has length between minArgs and maxArgs.
func (c *cmdGlobal) CheckArgs(cmd *cobra.Command, args []string, minArgs int, maxArgs int) (bool, error) {
if len(args) < minArgs || (maxArgs != -1 && len(args) > maxArgs) {
_ = cmd.Help()
Expand Down
2 changes: 1 addition & 1 deletion lxc/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

lxd "github.com/canonical/lxd/client"
"github.com/canonical/lxd/client"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
cli "github.com/canonical/lxd/shared/cmd"
Expand Down
9 changes: 8 additions & 1 deletion lxd/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func clusterPutBootstrap(d *Daemon, r *http.Request, req api.ClusterPut) respons
d.serverClustered = true
d.globalConfigMu.Unlock()

d.events.SetLocalLocation(d.serverName)
// Start clustering tasks
d.startClusterTasks()

Expand Down Expand Up @@ -563,17 +564,21 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res
defer revert.Fail()

// Update server name.
oldServerName := d.serverName
d.globalConfigMu.Lock()
d.serverName = req.ServerName
d.serverClustered = true
d.globalConfigMu.Unlock()
revert.Add(func() {
d.globalConfigMu.Lock()
d.serverName = ""
d.serverName = oldServerName
d.serverClustered = false
d.globalConfigMu.Unlock()

d.events.SetLocalLocation(d.serverName)
})

d.events.SetLocalLocation(d.serverName)
localRevert, err := clusterInitMember(localClient, client, req.MemberConfig)
if err != nil {
return fmt.Errorf("Failed to initialize member: %w", err)
Expand Down Expand Up @@ -1856,6 +1861,8 @@ func clusterNodePost(d *Daemon, r *http.Request) response.Response {
d.serverName = req.ServerName
d.globalConfigMu.Unlock()

d.events.SetLocalLocation(d.serverName)

requestor := request.CreateRequestor(r)
s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterMemberRenamed.Event(req.ServerName, requestor, logger.Ctx{"old_name": memberName}))

Expand Down
6 changes: 3 additions & 3 deletions lxd/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func internalImportFromBackup(s *state.State, projectName string, instName strin

if backupConf.Pool == nil {
// We don't know what kind of storage type the pool is.
return fmt.Errorf(`No storage pool struct in the backup file found. The storage pool needs to be recovered manually`)
return fmt.Errorf("No storage pool struct in the backup file found. The storage pool needs to be recovered manually")
}

// Try to retrieve the storage pool the instance supposedly lives on.
Expand Down Expand Up @@ -694,7 +694,7 @@ func internalImportFromBackup(s *state.State, projectName string, instName strin
}

// Check snapshots are consistent.
existingSnapshots, err := pool.CheckInstanceBackupFileSnapshots(backupConf, projectName, false, nil)
existingSnapshots, err := pool.CheckInstanceBackupFileSnapshots(backupConf, projectName, nil)
if err != nil {
return fmt.Errorf("Failed checking snapshots: %w", err)
}
Expand Down Expand Up @@ -918,7 +918,7 @@ func internalImportRootDevicePopulate(instancePoolName string, localDevices map[
expandedRootName, expandedRootConfig, _ := instancetype.GetRootDiskDevice(expandedDevices)

// Extract root disk from expanded profile devices.
profileExpandedDevices := db.ExpandInstanceDevices(deviceConfig.NewDevices(localDevices), profiles)
profileExpandedDevices := instancetype.ExpandInstanceDevices(deviceConfig.NewDevices(localDevices), profiles)
profileExpandedRootName, profileExpandedRootConfig, _ := instancetype.GetRootDiskDevice(profileExpandedDevices.CloneNative())

// Record whether we need to add a new local disk device.
Expand Down
4 changes: 4 additions & 0 deletions lxd/backup/backup_config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func UpdateInstanceConfig(c *db.Cluster, b Info, mountPath string) error {
if backup.Volume != nil {
backup.Volume.Name = b.Name
backup.Volume.Project = b.Project

// Ensure the most recent volume UUIDs get updated.
backup.Volume.Config = b.Config.Volume.Config
backup.VolumeSnapshots = b.Config.VolumeSnapshots
}

// Load the storage pool.
Expand Down
37 changes: 21 additions & 16 deletions lxd/cluster/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ func Connect(address string, networkCert *shared.CertInfo, serverCert *shared.Ce
// ConnectIfInstanceIsRemote figures out the address of the cluster member which is running the instance with the
// given name in the specified project. If it's not the local member will connect to it and return the connected
// client (configured with the specified project), otherwise it will just return nil.
func ConnectIfInstanceIsRemote(cluster *db.Cluster, projectName string, instName string, networkCert *shared.CertInfo, serverCert *shared.CertInfo, r *http.Request, instanceType instancetype.Type) (lxd.InstanceServer, error) {
func ConnectIfInstanceIsRemote(s *state.State, projectName string, instName string, r *http.Request, instanceType instancetype.Type) (lxd.InstanceServer, error) {
// No need to connect if not clustered.
if !s.ServerClustered {
return nil, nil
}

var address string // Cluster member address.
err := cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
err := s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
var err error
address, err = tx.GetNodeAddressOfInstance(ctx, projectName, instName, instanceType)
return err
Expand All @@ -94,7 +99,7 @@ func ConnectIfInstanceIsRemote(cluster *db.Cluster, projectName string, instName
return nil, nil // The instance is running on this local member, no need to connect.
}

client, err := Connect(address, networkCert, serverCert, r, false)
client, err := Connect(address, s.Endpoints.NetworkCert(), s.ServerCert(), r, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -148,22 +153,22 @@ func ConnectIfVolumeIsRemote(s *state.State, poolName string, projectName string
return nil, fmt.Errorf("Failed checking if volume %q is available: %w", volumeName, err)
}

if remoteInstance != nil {
var instNode db.NodeInfo
err := s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
instNode, err = tx.GetNodeByName(ctx, remoteInstance.Node)
return err
})
if err != nil {
return nil, fmt.Errorf("Failed getting cluster member info for %q: %w", remoteInstance.Node, err)
}

// Replace node list with instance's cluster member node (which might be local member).
nodes = []db.NodeInfo{instNode}
} else {
if remoteInstance == nil {
// Volume isn't exclusively attached to an instance. Use local cluster member.
return nil, nil
}

var instNode db.NodeInfo
err = s.DB.Cluster.Transaction(s.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
instNode, err = tx.GetNodeByName(ctx, remoteInstance.Node)
return err
})
if err != nil {
return nil, fmt.Errorf("Failed getting cluster member info for %q: %w", remoteInstance.Node, err)
}

// Replace node list with instance's cluster member node (which might be local member).
nodes = []db.NodeInfo{instNode}
}

nodeCount := len(nodes)
Expand Down
2 changes: 1 addition & 1 deletion lxd/cluster/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (g *Gateway) heartbeat(ctx context.Context, mode heartbeatMode) {
// Initialise slice to indicate to HeartbeatNodeHook that its being called from leader.
unavailableMembers := make([]string, 0)

err = query.Retry(func() error {
err = query.Retry(ctx, func(ctx context.Context) error {
// Durating cluster member fluctuations/upgrades the cluster can become unavailable so check here.
if g.Cluster == nil {
return fmt.Errorf("Cluster unavailable")
Expand Down
4 changes: 4 additions & 0 deletions lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ func (d *Daemon) init() error {
return err
}

d.events.SetLocalLocation(d.serverName)

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

d.events.SetLocalLocation(d.serverName)

// Get daemon configuration.
bgpAddress := d.localConfig.BGPAddress()
bgpRouterID := d.localConfig.BGPRouterID()
Expand Down