microsoft / go-winio

Win32 IO-related utilities for Go
MIT License
953 stars 181 forks source link

Add some basic bind filter functions #274

Closed gabriel-samfira closed 1 year ago

gabriel-samfira commented 1 year ago

This change adds the ability to mount a a single folder or a volume inside another folder, using the bind filter API.

While the API allows mounting multiple sources inside a single mount point, acting as an overlay, we disable this functionality in the ApplyFileBinding() function. We could add another flags parameter to this function to allow using any of the existing flags, making it more generic. Let me know if this is preferred.

Tests will be added shortly.

Signed-off-by: Gabriel Adrian Samfira gsamfira@cloudbasesolutions.com

TBBle commented 1 year ago

Cross-tagging from https://github.com/microsoft/go-winio/pull/187#issuecomment-1419296718: I suggest that once this lands, hcsshim be updated to use this for wclayer mount and wclayer unmount replacing the Volume Mount Point APIs that #187 was deduplicating, and hence allowing #187 to be sunset as "No current users": The lowest-maintenance-cost code is the code never committed. ^_^

TBBle commented 1 year ago

I realise the current layout of this repo is... adventurous... but should this API be somewhere under pkg/ rather than in the root?

gabriel-samfira commented 1 year ago

I realise the current layout of this repo is... adventurous... but should this API be somewhere under pkg/ rather than in the root?

I am extremely malleable in regard to this. Any suggestions or preferences are fine with me.

gabriel-samfira commented 1 year ago

I added some tests. It would be nice to add some tests with volume mount points, but I am not sure if pulling in computestorage dependencies (I think it requires additional windows features?) in order to format a VHD and make it mountable, is desirable.

TBBle commented 1 year ago

Thinking more about my earlier thought regarding hcsshim, I just remembered that there's already code in hcsshim that uses Bind Filter (and a syscall wrapper for the one call they use), so converting that to use this API would be a good validation of the API, including questions about generalisation.

gabriel-samfira commented 1 year ago

Thinking more about my earlier thought regarding hcsshim, I just remembered that there's already code in hcsshim that uses Bind Filter (and a syscall wrapper for the one call they use), so converting that to use this API would be a good validation of the API, including questions about generalisation.

Yup. It's in use in hcsshim. I think we can replace some things in hcsshim with this, but the BfGetMappings seems to only be available in ltsc2022. The tests seem to fail on 2019. Initially, this will be used in containerd to allow us to add support for buildkitd. Come to think of it, we may need to put the containerd windows snapshotter behind a feature flag or a check that the OS version is supported. We'll circle back to that later, though.

gabriel-samfira commented 1 year ago

Come to think of it, we may need to put the containerd windows snapshotter behind a feature flag or a check that the OS version is supported. We'll circle back to that later, though.

There is no way to list mappings on ltsc2019. We can however blindly try to remove a mapping and ignore the error if it's The parameter is incorrect. That way we can support this starting with RS5.