tuxera / ntfs-3g

NTFS-3G Safe Read/Write NTFS Driver
https://www.tuxera.com/company/open-source
GNU General Public License v2.0
981 stars 148 forks source link

Does ntfs-3g support Mandatory File Locking? #128

Open sibidharan opened 3 days ago

sibidharan commented 3 days ago

I am trying to run multiple Tally Prime software instances via Wine running inside KASM containers sharing data simulating Citrix on Windows. When Tally is run on Citrix on Windows, the NTFS driver provides mandatory file locking that makes multiple clients access tally data simultaneously. But this is not happening in Linux since Linux do not have real support for mandatory file locking and recently deprecated mand mount option also, that throws a warning in dmesg.

Can I rely on ntfs-3g for Mandatory File Locking? Is this really implemented into the linux driver? If so can I use them inside containers?

jpandre commented 2 days ago

the NTFS driver provides mandatory file locking that makes multiple clients access tally data simultaneously.

ntfs-3g runs in user space and does not implement any locking at all, however fuse serializes the requests from the clients. So what matters here is whether you need several ntfs-3g processes acting on the same partition. This would be unsafe. Having several clients to a single ntfs-3g process would be safe.

sibidharan commented 2 days ago

That means mounting the ntfs-3g in host with sudo ntfs-3g /dev/sdX1 /mnt/ntfs-mount and then bind mounting all containers to access this mount will ensure all operations happen sequentially? Is this safe?

With Ext4 bind mounts the data gets corrupt while multiple clients access, that does not happen on NTFS on windows. Can I make the same with docker and ntfs-3g ? Lets say I run a container with

docker run -d \ --name container_name \ -v /mnt/ntfs-mount:/path/in/container \ your_image

Does this work like multiple clients access single ntfs-3g process?

jpandre commented 2 days ago

That means mounting the ntfs-3g in host with sudo ntfs-3g /dev/sdX1 /mnt/ntfs-mount and then bind mounting all containers to access this mount will ensure all operations happen sequentially? Is this safe?

When mounting with "sudo ntfs-3g /dev/sdX1 /mnt/ntfs-mount" a single process is created, and /dev/sdX1 is opened with O_EXCL so preventing another process from accessing it.

I imagine that a bind mount is sort of symbolic link, using the existing mount relying on the existing process, this is easy to check, and I would say this is safe.

With Ext4 bind mounts the data gets corrupt while multiple clients access,

ext4 is reentrant code acting on behalf of client processes, so it has to deal with interprocess lockings, which your architecture apparently defeats.