lxd icon indicating copy to clipboard operation
lxd copied to clipboard

Removing a `disk` device with an existing target path on a VM leads to unreachable target directory

Open gabrielmougard opened this issue 1 year ago • 4 comments

Required information

Distribution: ubuntu Distribution version: 22.04 The output of "lxc info" or if that fails: Kernel version: LXC version: LXD version: 5.19-8635f82 Storage backend in use: zfs

Issue description

Similarly to https://github.com/canonical/lxd/issues/12648, but for a VM instance this time, we observe an issue while removing a disk device that was bind mounted over an existing empty directory. This time, the underlying directory doesn't get removed but cannot but interacted with :

mkdir /tmp/empty-dir
lxc launch ubuntu:jammy v1 --vm
lxc config device add v1 test disk source=/tmp/empty-dir path=/opt
lxc config device remove v1 test
lxc exec v1 -- ls /opt
ls: cannot access '/opt': Transport endpoint is not connected

I would expect that, for an already existing directory, the target directory would be unmounted but still present, whereas a target directory created through LXD during the mount would be unmounted and deleted when the device gets removed.

We should also check that, within the VM, the target path we're attempting to unmount has no overmounts as calling umount on the target directory will first unmount the last mount but not all of them (could inspecting /proc/self/mountinfo within the VM would help to know what to unmount?)

gabrielmougard avatar Jan 09 '24 13:01 gabrielmougard

@tomponline I opened a new issue as this is a bit different than https://github.com/canonical/lxd/issues/12648

gabrielmougard avatar Jan 09 '24 13:01 gabrielmougard

@gabrielmougard thanks, I suspect this is due to:

https://discuss.linuxcontainers.org/t/incus-0-3-has-been-released/18351#hot-plughot-remove-of-paths-in-virtual-machines-5

Worth noting that the agent will not automatically unmount the filesystem prior to hot-remove. If the filesystem is mounted in the guest, you’ll get an error during hot-remove.

tomponline avatar Jan 10 '24 09:01 tomponline

Thanks for opening this @gabrielmougard I suspect we'll need to add support to the lxd-agent to trigger an unmount when the device is being removed.

tomponline avatar Jan 10 '24 09:01 tomponline