Shared folder between container and host is cached?

I have 2 computers. 1 computer install ubuntu server and 1 machine working daily. On ubuntu I installed lxd with snap and I created a container called webServ

webServ container và ubuntu host chia sẻ chung folder sites bằng lệnh

lxc config device add webServ sites disk source=~/rslsync/sites path=/var/www shift=true

Ubuntu host and my 2nd computer sync data with Resilio, including ~/rslsync/sites directory on ubuntu host.

The problem I am having is that if I edit the file directly in the ~/rslsync/sites folder on the ubuntu host then when I go into the webServ container I read the file I will see the updates. But if I edit the file on 2nd computer, it will only see the update on ubuntu host but not in webServ container.

Before:
image

After:
image

I don’t know where the problem is and is there a way to work it out?

That’s most likely a shiftfs caching bug. This can happen in some cases when the underlay is changed but the overlay has cached the file.

I’ve personally had better luck with this with more recent kernels (5.8), so you may want to install the linux-generic-hwe-20.04 kernel on your system and see if that helps.

In general, those kind of issues is what’s caused us to go a completely different route when upstreaming this feature in the Linux kernel and instead doing things at the VFS layer rather than as a standalone filesystem.

The Linux 5.12 kernel should release with this new approach and LXC and LXD will automatically use the new logic when available, hopefully making this a problem of the past over the next year or so (we need some time for things to mature and distributions to adopt suitable kernels).

2 Likes

Thank you very much for your quick response.

I’ll try the way you mentioned and let you know the results. I also hope it helps

Unfortunately, after updating the linux kernel, it didn’t help me either @stgraber
image

That sounds very interesting.
I am looking forward for the release and an announcement.

1 Like

@stgraber As Kernel Version 5.12 is now released, I would like to ask some questions:
Above you say that LXD will use the new approach automatically, so I assume it is already included in the latest LXD version?
And does it automatically replace shiftfs and all the shift options?
Or are further settings (like new options) necessary?

Also I assume there will be more information available, especially regarding potential differences and downsides?

1 Like

@brauner is currently working on it. Once implemented it will automatically replace shiftfs on systems that can handle it.

2 Likes

Is currently any workaround for this? Like a drop cache or so?

1 Like

Yes, that usually helps!

1 Like

@stgraber Followup-Question:
So I assume that shiftfs will still be supported on systems with older kernels than 5.12?

1 Like

Yeah, we intend to keep supporting shiftfs in LXD until LXD 5.0 at which point we’ll drop support for it and the only mount shifting option will be to run a 5.12 kernel or higher.

2 Likes

And if I may ask, what timeframe are we talking about (approximately)?

1 Like

LXD 5.0 would be April 2022

2 Likes

Useful topic for me, useful information to be applied in my workflow, thanks to all!

1 Like

@stgraber @brauner Is there any solution so far? I haven’t been able to use shift for a while.

My kernel:
Linux 5.11.0-38-generic #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Update2: Oh sry, didn’t see that you are the original reporter.
So your problem is not that you don’t have shiftfs…
In that case everything is explained above.


For everyone else who might be searching for a solution for 5.11:

There is a version available, see: ~ubuntu-kernel/ubuntu/+source/linux/+git/hirsute - [no description]

https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/hirsute/tree/fs/shiftfs.c?h=master-next

So you can either use that kernel or modify my dkms scripts to use the shiftfs.c from above.

1 Like

@ducnm Here (LXD 4.16 has been released - #16 by stgraber) you find the last state of information that I got.

1 Like