none
SMB2 Server Write request required execute on sequence (guaranteed to complete in order)? RRS feed

  • Question

  • Let's say the SMB2 Server received two Write Request and after these two requests both completed and client received the responses, the client send a read request to check for the result. All the request are targeting the same file.

    Write Request 01 - offset: 0, length: 3, buffer: "111", ...

    Write Request 02 - offset: 2, length: 3, buffer: "222", ...

    After these two write request both completed  and client received the responses, the client send a read request to verify the result.

    Read Request 01 - offset: 0, length: 5.

    Questions:

    1. Does SMB2 header type affect the result? (SMB2 Packet Header SYNC and SMB2 Packet Header - ASYNC)
    2. Could the client always expecting the result "11222"?
    3. If the write request 01 and 02 changed to a "Compounded Requests", could the client always expecting the result "11222"?

    Extra Question:

    From this MSDN blog,

    https://blogs.msdn.microsoft.com/oldnewthing/20160205-00/?p=92981

    Base on my understanding, it states overlapped write wouldn't guaranteed to complete in order. And SMB2 seems is always asynchronous (because we can always sending another request before the previous one response).

    1. Does SMB2 always consider as overlapped I/O (Asynchronous I/O)?
    2. Does this means SMB2 would not guaranteed to complete in order?

    Thursday, May 17, 2018 4:50 AM

Answers

  • Hi Michael:

    I have answers to most of your questions. Here they are in the Q&A fashion:

    Q. Does SMB2 header type affect the result? (SMB2 Packet Header SYNC and SMB2 Packet Header - ASYNC)

    A. As MS-SMB2 explains in section 2.2.1, "This header format is used for responses to requests processed asynchronously by the server...", the type of ASYNC header only tells if that the operation is asynchronous, not the order in which it would be executed. There is no guarantee in which order the writes will happen. It is random.

    Q. Could the client always expecting the result "11222"?

    A. No. Please see above. In Windows, If the two writes use the same handle and the file is opened for “synchronous” access (meaning not specifying FILE_FLAG_OVERLAPPED from Win32 CreateFile) then the I IO manager in the client machines will serialize the two writes before going to SMB, meaning the first write will be sent and when completed the second write will be sent thus guaranteeing order. 

    Q. If the write request 01 and 02 changed to a "Compounded Requests", could the client always expecting the result "11222"?

    A. As stated in MS-SMB2 section "3.3.5.2.7.2 Handing Compounded Related Requests", the SMB server MUST handle each operation in order. Therefore, if you make the two write compounded and set the flag  SMB2_FLAGS_RELATED_OPERATIONS appropriately, the writes will be executed in order. 

    Q. Does SMB2 always consider as overlapped I/O (Asynchronous I/O)?

    A. The order is determined by how file handle is opened by IO manager, not SMB server or the file system. If the file is opened for ASYNC access then there is no guarantee in write order at both the SMB and file system layer.

    Q. Does this means SMB2 would not guaranteed to complete in order?

    A. Correct. The only way you can guarantee is to act like IO manager i.e. wait for response of first request and then send the second request.

    Please let me know if it does not answer your question.



     


    Regards, Obaid Farooqi


    Wednesday, May 23, 2018 4:38 PM
    Owner

All replies

  • Hi Michael_Leung,

    Thank you for your inquiry about Microsoft Office Specifications. We have created an incident for investigating this issue. One of the Open specifications team member will contact you to assist further.

    Thanks


    Tarun Chopra | Escalation Engineer | Open Specifications Support Team

    Thursday, May 17, 2018 7:23 AM
  • Hi Michael:

    I'll help you with this issue and will be in touch as soon as I have an answer.


    Regards, Obaid Farooqi

    Thursday, May 17, 2018 10:16 PM
    Owner
  • Hi Obaid,

    Any update on this question? It already took a few days. Do I need to explain the scenario more detail? Or simply you need more time to find out the answer?

    Wednesday, May 23, 2018 7:53 AM
  • Hi Michael:

    I have answers to most of your questions. Here they are in the Q&A fashion:

    Q. Does SMB2 header type affect the result? (SMB2 Packet Header SYNC and SMB2 Packet Header - ASYNC)

    A. As MS-SMB2 explains in section 2.2.1, "This header format is used for responses to requests processed asynchronously by the server...", the type of ASYNC header only tells if that the operation is asynchronous, not the order in which it would be executed. There is no guarantee in which order the writes will happen. It is random.

    Q. Could the client always expecting the result "11222"?

    A. No. Please see above. In Windows, If the two writes use the same handle and the file is opened for “synchronous” access (meaning not specifying FILE_FLAG_OVERLAPPED from Win32 CreateFile) then the I IO manager in the client machines will serialize the two writes before going to SMB, meaning the first write will be sent and when completed the second write will be sent thus guaranteeing order. 

    Q. If the write request 01 and 02 changed to a "Compounded Requests", could the client always expecting the result "11222"?

    A. As stated in MS-SMB2 section "3.3.5.2.7.2 Handing Compounded Related Requests", the SMB server MUST handle each operation in order. Therefore, if you make the two write compounded and set the flag  SMB2_FLAGS_RELATED_OPERATIONS appropriately, the writes will be executed in order. 

    Q. Does SMB2 always consider as overlapped I/O (Asynchronous I/O)?

    A. The order is determined by how file handle is opened by IO manager, not SMB server or the file system. If the file is opened for ASYNC access then there is no guarantee in write order at both the SMB and file system layer.

    Q. Does this means SMB2 would not guaranteed to complete in order?

    A. Correct. The only way you can guarantee is to act like IO manager i.e. wait for response of first request and then send the second request.

    Please let me know if it does not answer your question.



     


    Regards, Obaid Farooqi


    Wednesday, May 23, 2018 4:38 PM
    Owner
  • Hi Obaid,

    Thank you! Your answer had already answer my questions! 

    Thursday, May 24, 2018 8:56 AM