SMB3 POSIX, byterange locks and close behaviour
Subsystems (2)
Hi folks,
while working on the part for byterange locks of the SMB3 POSIX spec, I noticed a problem in the protocol:
Neither MS-SMB2+ nor the SMB3 POSIX ext has a way to send a client side identifier for the process (like the pid) to the server. That means when processing SMB2-CLOSE we have no way to correlate opens by the same vs different applications (pids) on the client.
Suppose on the client this happens:
1. application A (pid=X on the client) opens fd1=open("file") and sets a brl
2. application A (pid=X on the client) opens another fd2=open("file") and sets a compatible brl
3. application B (pid=Y on the client) opens another fd3=open("file") and sets a compatible brl
4. application A closes fd1
According to POSIX rules we have to drop all brls on "file" when closing any fd on "file", but this can't be implemented on the server, as we have no way to tie opens from the same client side process together.
It's also not possible to implement OFD locks in the protocol, same problem.
Using OFD locks in the backend on the server doesn't help.
SMB1 had pidlow/pidhigh in the header and MS-FSA "2.1.5.8 Server Requests a Byte-Range Lock" has:
---8<---
The server provides:
LockKey: A 32-bit unsigned integer containing an identifier for the lock being obtained by a specific process. ---8<---
and this part of MS-CIFS "3.3.5.15 Receiving an SMB_COM_LOCK_BYTE_RANGE Request":
---8<---
Locks prevent attempts to lock, read, or write the locked portion of the file by other clients or PIDs from the same client. ---8<---
...implies the SMB1 server passes the PID as LockKey to the FSA layer.
SMB2+ doesn't have a PID nor has POSIX-SMB2 and I wonder if we need one, at least for the lock/unlock SMB2 requests. SMB2_LOCK_ELEMENT has a 32bit reserved field which we could repurpose, but there'll be dragons, so we might need a different way to extend the protocol.
We also have a 32bit reserved in FilePosixInformation, that would fit the bill.
Thoughts? Am I missing something?
Thanks!
Hi Ralph,
Quoted 31 lines
while working on the part for byterange locks of the SMB3 POSIX spec, I noticed a problem in the protocol:
Neither MS-SMB2+ nor the SMB3 POSIX ext has a way to send a client side identifier for the process (like the pid) to the server. That means when processing SMB2-CLOSE we have no way to correlate opens by the same vs different applications (pids) on the client.
Suppose on the client this happens:
1. application A (pid=X on the client) opens fd1=open("file") and sets a brl
2. application A (pid=X on the client) opens another fd2=open("file") and sets a compatible brl
3. application B (pid=Y on the client) opens another fd3=open("file") and sets a compatible brl
4. application A closes fd1According to POSIX rules we have to drop all brls on "file" when closing any fd on "file", but this can't be implemented on the server, as we have no way to tie opens from the same client side process together.
It's also not possible to implement OFD locks in the protocol, same problem.
Using OFD locks in the backend on the server doesn't help.
SMB1 had pidlow/pidhigh in the header and MS-FSA "2.1.5.8 Server Requests a Byte-Range Lock" has:
---8<---
The server provides:LockKey: A 32-bit unsigned integer containing an identifier for the lock being obtained by a specific process. ---8<---
and this part of MS-CIFS "3.3.5.15 Receiving an
SMB_COM_LOCK_BYTE_RANGERequest":---8<---
Locks prevent attempts to lock, read, or write the locked portion of the file by other clients or PIDs from the same client. ---8<---
Quoted 7 lines
...implies the SMB1 server passes the PID as LockKey to the FSA layer.
SMB2+ doesn't have a PID nor has POSIX-SMB2 and I wonder if we need one, at least for the lock/unlock SMB2 requests.
SMB2_LOCK_ELEMENThas a 32bit reserved field which we could repurpose, but there'll be dragons, so we might need a different way to extend the protocol.We also have a 32bit reserved in FilePosixInformation, that would fit the bill.
Thoughts? Am I missing something?
I think it's the job of the client to coordinate its local processes.
I guess the client can have just a single open to the server for local fd1 and fd2, but in the end it's a local problem on the client.
I guess a Windows client has to solve similar problems with multiple applications running.
metze
Quoted 38 lines · Stefan Metzmacher via samba-technical
Hi Ralph,
Quoted 35 lines
while working on the part for byterange locks of the SMB3 POSIX spec, I noticed a problem in the protocol:
Neither MS-SMB2+ nor the SMB3 POSIX ext has a way to send a client side identifier for the process (like the pid) to the server. That means when processing SMB2-CLOSE we have no way to correlate opens by the same vs different applications (pids) on the client.
Suppose on the client this happens:
1. application A (pid=X on the client) opens fd1=open("file") and sets a brl
2. application A (pid=X on the client) opens another fd2=open("file") and sets a compatible brl
3. application B (pid=Y on the client) opens another fd3=open("file") and sets a compatible brl
4. application A closes fd1According to POSIX rules we have to drop all brls on "file" when closing any fd on "file", but this can't be implemented on the server, as we have no way to tie opens from the same client side process together.
It's also not possible to implement OFD locks in the protocol, same problem.
Using OFD locks in the backend on the server doesn't help.
SMB1 had pidlow/pidhigh in the header and MS-FSA "2.1.5.8 Server Requests a Byte-Range Lock" has:
---8<---
The server provides:LockKey: A 32-bit unsigned integer containing an identifier for the lock being obtained by a specific process. ---8<---
and this part of MS-CIFS "3.3.5.15 Receiving an
SMB_COM_LOCK_BYTE_RANGERequest":---8<---
Locks prevent attempts to lock, read, or write the locked portion of the file by other clients or PIDs from the same client. ---8<---...implies the SMB1 server passes the PID as LockKey to the FSA layer.
Quoted 8 lines
Quoted 6 lines
SMB2+ doesn't have a PID nor has POSIX-SMB2 and I wonder if we need one, at least for the lock/unlock SMB2 requests.
SMB2_LOCK_ELEMENThas a 32bit reserved field which we could repurpose, but there'll be dragons, so we might need a different way to extend the protocol.We also have a 32bit reserved in FilePosixInformation, that would fit the bill.
Thoughts? Am I missing something?
I think it's the job of the client to coordinate its local processes.
Yes. But it would be good to have a test case to repro this to make sure client does proper behavior. In many cases the client will reuse the same open handle for multiple processes, but in cases where we have two handles open, it would be good to have a test case to repro this.
Quoted 8 lines
I guess the client can have just a single open to the server for local fd1 and fd2, but in the end it's a local problem on the client.
I guess a Windows client has to solve similar problems with multiple applications running.
metze
Signature · 3 lines
Thanks, Steve
Quoted 5 lines · Steve French
Quoted 3 lines
Quoted 1 line
Thoughts? Am I missing something?
I think it's the job of the client to coordinate its local processes.
Yes.
No. :) As described in the other mail I just send: for Windows there's no problem at all, so Windows client doesn't do any "coordination".
I guess a client might be allowed to "optimize" by resuing opens, but that's a different story. As soon as you have incompatible opens, say one read-only and a second read-write, you can't reuse.
Quoted 5 lines
But it would be good to have a test case to repro this to make sure client does proper behavior. In many cases the client will reuse the same open handle for multiple processes, but in cases where we have two handles open, it would be good to have a test case to repro this.
Testcase:
- connect to server with SMB3 POSIX
- 1st open with O_RDONLY
- 2nd open with O_RDWR (to bypass any possible client side open reuse)
- place shared lock range [0,1] on 1st open
- place exclusive lock on range [2,3] on 2nd open
- close 1st handle (according to POSIX this should drop both locks)
- place exclusive lock on range [0,3] -> should work
I'm going to add this a test to the Samba testsuite, my expectation being that it will fail.
Quoted 3 lines · Stefan Metzmacher
Quoted 1 line
Thoughts? Am I missing something?
I think it's the job of the client to coordinate its local processes.
Well, for Windows to Windows there is actually no problem with the locking semantics and no need to coordinate, as for Windows the simple rule from MS-FSA 2.1.5.5 "Server Requests Closing an Open" works just fine:
---8<---
All elements from Open.Stream.ByteRangeLockList where ByteRangeLock.OwnerOpen == Open MUST be removed.
---8<---
The problem only exists if we wanted to have POSIX lock semantics over SMB.
Quoted 2 lines
I guess the client can have just a single open to the server for local fd1 and fd2, but in the end it's a local problem on the client.
Just checked with a simple powershell script from a Windows client doing two opens on the same file: both opens are sent to the server.
It's not a client problem as Windows client don't have a problem...
Also, reusing opens locally on the client is only possible for compatible opens.
Quoted 2 lines
I guess a Windows client has to solve similar problems with multiple applications running.
No, that's the point, Windows lock just don't suffer from the problem.
Thinking a bit more about OFD locks: I'm not sure why I was thinking that it would also not be possible to implement OFD locks behaviour over pure SMB2 without extensions, with some server or client side extra handling of lock type conversion, splitting, shrinking, or coalescing with an existing lock.