Editing files locally on server: interoperability

From SambaWiki
Revision as of 14:31, 22 January 2023 by Mjt (talk | contribs) (Created page with "== Editing files locally on server: interoperability == Samba file server (smbd) implements access to unix files from SMB clients. This means, among other things, that multip...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Editing files locally on server: interoperability

Samba file server (smbd) implements access to unix files from SMB clients. This means, among other things, that multiple clients can access and modify files at once. SMB file access protocol allows clients to know when a file is modified on server (for example by another client or by the server itself), allows for efficient local file caching as long as the file hasn't been modified on the server, and for file locking, to prevent others from modifying (or reading) the file while it is being used (or written) by one of the clients. This all is to ensure everyone see consistent and up to date data and to prevent unwanted concurrent updates and losing data in the process. It has always been common in windows world to have files locked when a process had a file open, this is ensured by the system kernel by default. The same semantics is extended to network file access too, so if a file is being open from anywhere on the network, it is locked locally and for all clients too. On unix this has not been the case though, — the only case of this automatic file locking is for executables which are being executed (ETXTBUSY error), which is not used much on linux today.

There are several aspects of this concurrent file access.

- open file locking: preventing access or modification of a file being open for writing or read. This is something which is always implemented on a local filesystem by windows.

- notification of file change on server: when a file is changed on server, clients don't know about this without special setup. SMB protocol includes ways for a client to subscribe to change notifications, and the server will send such notifications on actual file changes. (Windows) clients usually performs such subscription automatically.

- remote file caching locally: for better efficiency and speed, it is possible for a client to cache some files locally. This is done in forms of file leases (or oplocks). Also usually requested by windows clients automatically.

- ability to invalidate local caches when the file on server changes. This is to ensure clients do not continue caching stale data after the file changed on the server.


. When an SMB client opens a file and requests it to be locked, smbd does this by creating records in an internal tdb database, `/run/samba/locking.tdb` on a modern system. This way, all smbd processes know about currently locked files. Optionally, smbd can duplicate this file locking information using POSIX locking mechanism (fcntl(2) locks), so that non-samba processes can know about these

Samba fully implements this windows semantics internally.