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

Storage: Attach VM snapshots as disk devices #14930

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

MggMuggins
Copy link
Contributor

@MggMuggins MggMuggins commented Feb 6, 2025

Attach a snapshot of v1 to another VM as a disk device using this device config:

devices:
  v1-snap0:
    pool: default
    source: v1
    source.type: virtual-machine
    source.snapshot: snap0
    type: disk

Attempting to attach custom volume snapshots using this API will fail. I am planning to complete that functionality next week.

Tests in the works for lxd-cicanonical/lxd-ci#413

@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from 52455e2 to 604cbf0 Compare February 6, 2025 23:59
@github-actions github-actions bot added the Documentation Documentation needs updating label Feb 8, 2025
@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from 75acc94 to cc24a1b Compare February 12, 2025 22:32
@MggMuggins MggMuggins marked this pull request as ready for review February 13, 2025 00:04
@tomponline
Copy link
Member

@MggMuggins when we added source-type field it looks like we didnt update the instance_root_volume_attachment API extension, as it still says "Introduces the <type>/<volume> syntax for the source property of
disk devices."

Also can you update that API extension to include the new snapshot field too? Then that single API extension can cover both new features.

@github-actions github-actions bot added the API Changes to the REST API label Feb 13, 2025
@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from 91bf766 to b146396 Compare February 13, 2025 14:41
@MggMuggins
Copy link
Contributor Author

Good catch; should be good to go.

minaelee
minaelee previously approved these changes Feb 13, 2025
@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch 2 times, most recently from 90bc474 to 3b6a98c Compare February 14, 2025 06:11
@MggMuggins
Copy link
Contributor Author

Still chasing down a bug, this is not GTM.

@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from 0391ad1 to cedd3db Compare February 14, 2025 06:24
@tomponline tomponline marked this pull request as draft February 14, 2025 11:09
@tomponline
Copy link
Member

@MggMuggins please can you rebase

@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from cedd3db to ee74bcb Compare February 20, 2025 01:22
@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from ee74bcb to eab486d Compare February 20, 2025 01:36
@MggMuggins MggMuggins marked this pull request as ready for review February 20, 2025 02:05
@MggMuggins
Copy link
Contributor Author

Spun my wheels a bit today on checking that deleting a snapshot isn't possible if it's attached to an instance. Added a test to the lxd-ci PR to check that; this is good for review.

Still working on the LVM refcount bug. When the LVM driver deactivates a volume snapshot it checks to see if the parent volume is still in use. We need the inverse; the driver also needs to make sure when deactivating the parent that there aren't any snapshots in use. It looks like deactivating the parent also deactivates the snapshot (hence the error below), but I doubt the opposite is true. More on this tomorrow.

Putting this here for future travelers:

$ lxc storage volume detach vmpool292382 virtual-machine/v2 v1
Error: Failed to stop device "v2-root": Failed to deactivate LVM logical volume "/dev/vmpool292382/virtual-machines_test_v2": Failed to run: lvchange --activate n --ignoreactivationskip /dev/vmpool292382/virtual-machines_test_v2: exit status 5 (Logical volume vmpool292382/virtual-machines_test_v2-snap0 contains a filesystem in use.

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MggMuggins did you consider supporting source: vol/snap rather than source-snapshot? As we tend to use vol/snap format most other places?

@tomponline
Copy link
Member

tomponline commented Feb 26, 2025

@MggMuggins did you consider supporting source: vol/snap rather than source-snapshot? As we tend to use vol/snap format most other places?

Just want to check u didnt miss this question?

@MggMuggins
Copy link
Contributor Author

I did not 😉

Here is this set of changes with that syntax instead (tests failing atm, def broken). From an implementation perspective it makes complete sense (much smaller delta with the existing disk device driver and lxc, consistent with StorageVolume.Name, etc); and there are a few places where <instance>/<snap> synxtax is exposed in the API.

I don't love it for the same reasons that I switched to source.type though: multiple discrete pieces of information in the same field is very opaque when reading the code. It also requires parsing the field before using it (even if, as is the case here, my changes aren't doing the parsing). Using source.snapshot is more of an ugly band-aid than a real fix though, so I'm willing to go with the delimited syntax if that's what you'd prefer. I will get that other branch in order tomorrow.

Fixed 2 bugs (ceph ro block vols and docs) in the process 🙂

@tomponline
Copy link
Member

Using source.snapshot is more of an ugly band-aid than a real fix though, so I'm willing to go with the delimited syntax if that's what you'd prefer. I will get that other branch in order tomorrow.

How about we stick with source.snapshot because it makes the config and code itself clearer, and we can then still use vol/snapshot in the CLI if needed (like volume attach)?

@MggMuggins
Copy link
Contributor Author

I'm happy with that; the [<type>/]<vol>[/<snapshot>] syntax will stick around regardless.

I'll get this ready to go ASAP.

...to reflect changes in syntax & snapshots

Signed-off-by: Wesley Hershberger <[email protected]>
@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from eab486d to c3d24f5 Compare February 27, 2025 16:45
Link to the `source` disk device key for clarity

Signed-off-by: Wesley Hershberger <[email protected]>
Bring the fix from canonical#13258 to `lxc storage volume attach-profile`

Signed-off-by: Wesley Hershberger <[email protected]>
Prevents a disk device that refers from a snapshot from being identified
as a reference to its parent volume.

Signed-off-by: Wesley Hershberger <[email protected]>
Signed-off-by: Wesley Hershberger <[email protected]>
Signed-off-by: Wesley Hershberger <[email protected]>
@MggMuggins
Copy link
Contributor Author

@tomponline This is ready to go.

Added tests for readonly ceph block devices to canonical/lxd-ci#413

@MggMuggins
Copy link
Contributor Author

Nevermind, the readonly fix regressed something else and I don't have time today to dig into it. I'll pull those commits out so that this PR is unblocked and keep working on it on Monday.

@MggMuggins MggMuggins force-pushed the snapshot-disk-devices branch from 5a43b28 to 16abd2c Compare February 27, 2025 23:41
func parseVolumeSnapshot(defaultType string, name string) (volName string, volType string, snapshot string) {
volName, volType = parseVolume(defaultType, name)

parts := strings.SplitN(volName, "/", 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.Cut would also be an option here

@@ -2549,8 +2549,8 @@ This adds support for listing network zones across all projects using the `all-p

## `instance_root_volume_attachment`
Copy link
Member

@tomponline tomponline Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MggMuggins shall we rename this to vm_root_volume_attachment as my understanding is that we dont support containers yet, and we dont plan to before LXD 6.3 is released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes to the REST API Documentation Documentation needs updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants