-
Notifications
You must be signed in to change notification settings - Fork 930
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
Device: Don't remove an existing target directory when unmounting a disk
device if the original dir hasn't been created by LXD
#12700
base: main
Are you sure you want to change the base?
Conversation
Working on the integration tests now. |
9ee6693
to
20ba221
Compare
Tests should be ready |
20ba221
to
06cfd51
Compare
Also, @tomponline, the Or, we can introduce a new device option to say "not to track that kind of changes" so that I can set |
9504543
to
db861a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs look good now. :)
db861a7
to
eedfede
Compare
eedfede
to
8838e7c
Compare
@tomponline I implemented the logic for the VM as well within the lxd-agent. I tested it on my side without an issue. |
Thanks @gabrielmougard please can you add a PR description with what has changed so the reviewer can compare the code to the intended design. Please do include any new API endpoints you've added to the lxd-agent. Cheers |
Please can you rebase @gabrielmougard |
9140527
to
844ac0f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gabrielmougard when the disk
device is hot-plugged its mount inside the guest is triggered by an event in eventsProcess()
. Is there a reason you didn't feel that we could unmount the disk in the same fashion and required the API endpoint instead?
844ac0f
to
f4c1453
Compare
789a10f
to
cdc2492
Compare
@tomponline @roosterfish can you review this please? |
cdc2492
to
e9989e6
Compare
Heads up @mionaalex - the "Documentation" label was applied to this issue. |
e9989e6
to
1db74aa
Compare
@tomponline @roosterfish updated |
Please can you rebase |
1db74aa
to
4139a48
Compare
Signed-off-by: Gabriel Mougard <[email protected]>
Some devices like disk devices with a target path need to be cleanly unmounted. In the case of a VM instance, we prefer to handle the unmount logic within the agent and handle the unmounting of the potential overmounts of the guest. In some cases, we also need to remove a path resource (or not) on the guest side. That is why we also pass some extra metadata contained in the `Volatile` field, to handle the resource removal process in the agent and not on the LXD side (this would result in spawning aan SFTP client, which is a wasteful approach) Signed-off-by: Gabriel Mougard <[email protected]>
…k_dev_name>.last_state.created` for the disk device Signed-off-by: Gabriel Mougard <[email protected]>
… a device Signed-off-by: Gabriel Mougard <[email protected]>
…ory when unmounting When a disk device is removed while relying on a host directory and mapped to a target within a container, we detect if the target directory has been created by LXD or not in order to not delete the content of a target directory during the unmount. Example: - Let say we mounted a custom host empty directory (`test`) on the existing `/opt` directory of the container, when unmounted (`lxc device remove ...`), the target `/opt` won't be removed, because we marked it as NOT being created by LXD at mount time. - If, however, we created a custom empty target directory at mount time: `lxc config device add u1 test disk source=/home/user/test path=/new_dir`, the directory `new_dir` will be created on the target instance and if we decide to unmount `test`, the target `/new_dir` will be removed because is has been created by LXD Signed-off-by: Gabriel Mougard <[email protected]>
Signed-off-by: Gabriel Mougard <[email protected]>
fc5d572
to
370bb39
Compare
Signed-off-by: Gabriel Mougard <[email protected]>
Signed-off-by: Gabriel Mougard <[email protected]>
Signed-off-by: Gabriel Mougard <[email protected]>
… been unmounted Signed-off-by: Gabriel Mougard <[email protected]>
…n created by lxd Signed-off-by: Gabriel Mougard <[email protected]>
Signed-off-by: Gabriel Mougard <[email protected]>
Signed-off-by: Gabriel Mougard <[email protected]>
370bb39
to
96cd966
Compare
@tomponline updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up from our meeting, we need to:
- Check for performance reductions with this approach when starting instances.
- Consider what happens when part of the target path exists but part of it doesn't. What gets deleted?
closes #12648
closes #12716
Overall description
When a disk device is removed while relying on a host directory and mapped to a target within a container or a VM,
we detect if the target directory has been created by LXD or not in order to not delete the content of a target
directory during the unmount. Additionaly, with the VM case, we cleanly unmount the target path inside the VM.
Container case
Example:
Let say we mounted a custom host empty directory (
test
) on the existing/opt
directory of the container,when unmounted (
lxc device remove ...
), the target/opt
won't be removed, because we marked it as NOT being createdby LXD at mount time.
If, however, we created a custom empty target directory at mount time:
lxc config device add u1 test disk source=/home/user/test path=/new_dir
,the directory
new_dir
will be created on the target instance and if we decide to unmounttest
,the target
/new_dir
will be removed because is has been created by LXDParticular case for VMs
In addition to that, this fix also cleanly unmount the target directory inside the VM through an new LXD-agent API call. Before that, here is what would have happened:
mkdir /tmp/empty-dir lxc launch ubuntu:jammy v1 --vm lxc config device add v1 empty-dir disk source=/tmp/empty-dir path=/opt lxc config device remove v1 empty-dir lxc shell v1 -- stat /opt stat: cannot statx '/opt': Transport endpoint is not connected
This happens because the mounted device and its associated char device were removed using QEMU's QMP without unmounting the target.
Now, we inspect for the mounts and the over-mounts if any on the VM, and unmount them in the right order.