vfs_default: add sync fallback to fsync_send/recv
[samba.git] / source3 / smbd / smb2_write.c
index 40a59372ee40b04297fef9c4edbe7fd9e2fcc099..ee95bd317aefff1ad614b446ec6e179ab4918f07 100644 (file)
@@ -25,6 +25,9 @@
 #include "../lib/util/tevent_ntstatus.h"
 #include "rpc_server/srv_pipe_hnd.h"
 
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_SMB2
+
 static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
@@ -38,7 +41,7 @@ static NTSTATUS smbd_smb2_write_recv(struct tevent_req *req,
 static void smbd_smb2_request_write_done(struct tevent_req *subreq);
 NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req)
 {
-       struct smbXsrv_connection *xconn = req->sconn->conn;
+       struct smbXsrv_connection *xconn = req->xconn;
        NTSTATUS status;
        const uint8_t *inbody;
        uint16_t in_data_offset;
@@ -134,7 +137,7 @@ static void smbd_smb2_request_write_done(struct tevent_req *subreq)
        if (!NT_STATUS_IS_OK(status)) {
                error = smbd_smb2_request_error(req, status);
                if (!NT_STATUS_IS_OK(error)) {
-                       smbd_server_connection_terminate(req->sconn,
+                       smbd_server_connection_terminate(req->xconn,
                                                         nt_errstr(error));
                        return;
                }
@@ -145,7 +148,7 @@ static void smbd_smb2_request_write_done(struct tevent_req *subreq)
        if (outbody.data == NULL) {
                error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
                if (!NT_STATUS_IS_OK(error)) {
-                       smbd_server_connection_terminate(req->sconn,
+                       smbd_server_connection_terminate(req->xconn,
                                                         nt_errstr(error));
                        return;
                }
@@ -163,7 +166,7 @@ static void smbd_smb2_request_write_done(struct tevent_req *subreq)
 
        error = smbd_smb2_request_done(req, outbody, &outdyn);
        if (!NT_STATUS_IS_OK(error)) {
-               smbd_server_connection_terminate(req->sconn, nt_errstr(error));
+               smbd_server_connection_terminate(req->xconn, nt_errstr(error));
                return;
        }
 }
@@ -275,6 +278,11 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
                return NULL;
        }
        state->smb2req = smb2req;
+       if (smb2req->xconn->protocol >= PROTOCOL_SMB3_02) {
+               if (in_flags & SMB2_WRITEFLAG_WRITE_UNBUFFERED) {
+                       state->write_through = true;
+               }
+       }
        if (in_flags & SMB2_WRITEFLAG_WRITE_THROUGH) {
                state->write_through = true;
        }
@@ -349,7 +357,7 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
                                WRITE_LOCK,
                                &lock);
 
-       if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
+       if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
                tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
                return tevent_req_post(req, ev);
        }
@@ -364,8 +372,6 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
 
        status = smb2_write_complete(req, nwritten, errno);
 
-       SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
-
        DEBUG(10,("smb2: write on "
                "file %s, offset %.0f, requested %u, written = %u\n",
                fsp_str_dbg(fsp),