[SCM] Samba Shared Repository - branch master updated

Christof Schmitt cs at samba.org
Fri Nov 13 03:48:02 UTC 2015


The branch, master has been updated
       via  f9b92cf selftest: Use strict sync = yes
       via  c737fae smbd: Issue fsync for SMB2 FLUSH asynchronously
       via  17f4110 s3: smbd: Remove outstanding_aio_calls from globals.
       via  8039382 s3: smbd: Remove aio_pending_size from globals.
      from  0137105 s4-auth: Fix some debugging and crash in error cases

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f9b92cfea69eb10b61ae2f99540097c202fb82bf
Author: Christof Schmitt <cs at samba.org>
Date:   Wed Nov 11 13:28:09 2015 -0700

    selftest: Use strict sync = yes
    
    This enables the codepaths calling fsync for FLUSH requests during
    selftest.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Christof Schmitt <cs at samba.org>
    Autobuild-Date(master): Fri Nov 13 04:47:00 CET 2015 on sn-devel-104

commit c737fae5f79fa76118a914940e59408fd329037a
Author: Christof Schmitt <cs at samba.org>
Date:   Wed Nov 11 13:31:15 2015 -0700

    smbd: Issue fsync for SMB2 FLUSH asynchronously
    
    SMB2 FLUSH mainly calls fsync and there is already code in place to
    handle fsync asynchronously, so use the asynchronous code path for SMB2
    FLUSH. This avoids a SMB2 FLUSH stalling other requests processing.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 17f4110c47d53148979a3617e80b29fe3bd41efc
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Nov 12 09:25:41 2015 -0800

    s3: smbd: Remove outstanding_aio_calls from globals.
    
    Access via functions only.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Christof Schmitt <cs at samab.org>

commit 803938260dadef63d2685860bb63a700c95424e0
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Nov 12 09:20:05 2015 -0800

    s3: smbd: Remove aio_pending_size from globals.
    
    Access via functions only.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Christof Schmitt <cs at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 selftest/target/Samba3.pm         |  1 +
 source3/modules/vfs_aio_fork.c    |  2 +-
 source3/modules/vfs_aio_linux.c   |  8 ++---
 source3/modules/vfs_aio_pthread.c |  4 +--
 source3/modules/vfs_default.c     |  6 ++--
 source3/smbd/aio.c                | 57 +++++++++++++++++++++++-------
 source3/smbd/globals.c            |  3 --
 source3/smbd/globals.h            |  3 --
 source3/smbd/proto.h              |  5 +++
 source3/smbd/smb2_flush.c         | 74 +++++++++++++++++++++++++++++++++++----
 10 files changed, 128 insertions(+), 35 deletions(-)


Changeset truncated at 500 lines:

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 4b7882b..1c54dae 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1331,6 +1331,7 @@ sub provision($$$$$$$$)
 	create mask = 755
 	dos filemode = yes
 	strict rename = yes
+	strict sync = yes
 	vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
 
 	printing = vlp
diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index 7fca3d1..25a72c6 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -909,7 +909,7 @@ static int aio_fork_connect(vfs_handle_struct *handle, const char *service,
 	 * Essentially we want this to be unlimited unless smb.conf
 	 * says different.
 	 *********************************************************************/
-	aio_pending_size = 100;
+	set_aio_pending_size(100);
 	return 0;
 }
 
diff --git a/source3/modules/vfs_aio_linux.c b/source3/modules/vfs_aio_linux.c
index 74ebb3c..599272e 100644
--- a/source3/modules/vfs_aio_linux.c
+++ b/source3/modules/vfs_aio_linux.c
@@ -113,12 +113,12 @@ static bool init_aio_linux(struct vfs_handle_struct *handle)
 		goto fail;
 	}
 
-	if (io_queue_init(aio_pending_size, &io_ctx)) {
+	if (io_queue_init(get_aio_pending_size(), &io_ctx)) {
 		goto fail;
 	}
 
 	DEBUG(10,("init_aio_linux: initialized with up to %d events\n",
-		  aio_pending_size));
+		  get_aio_pending_size()));
 
 	return true;
 
@@ -333,8 +333,8 @@ static int aio_linux_connect(vfs_handle_struct *handle, const char *service,
 	 * Essentially we want this to be unlimited unless smb.conf
 	 * says different.
 	 *********************************************************************/
-	aio_pending_size = lp_parm_int(
-		SNUM(handle->conn), "aio_linux", "aio num events", 128);
+	set_aio_pending_size(lp_parm_int(
+		SNUM(handle->conn), "aio_linux", "aio num events", 128));
 	return SMB_VFS_NEXT_CONNECT(handle, service, user);
 }
 
diff --git a/source3/modules/vfs_aio_pthread.c b/source3/modules/vfs_aio_pthread.c
index 059d745..72c812f 100644
--- a/source3/modules/vfs_aio_pthread.c
+++ b/source3/modules/vfs_aio_pthread.c
@@ -51,7 +51,7 @@ static bool init_aio_threadpool(struct tevent_context *ev_ctx,
 		return true;
 	}
 
-	ret = pthreadpool_init(aio_pending_size, pp_pool);
+	ret = pthreadpool_init(get_aio_pending_size(), pp_pool);
 	if (ret) {
 		errno = ret;
 		return false;
@@ -69,7 +69,7 @@ static bool init_aio_threadpool(struct tevent_context *ev_ctx,
 	}
 
 	DEBUG(10,("init_aio_threadpool: initialized with up to %d threads\n",
-		  aio_pending_size));
+		  get_aio_pending_size()));
 
 	return true;
 }
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index bbe8cca..f3ebb89 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -716,7 +716,7 @@ static bool vfswrap_init_asys_ctx(struct smbd_server_connection *conn)
 		return true;
 	}
 
-	ret = asys_context_init(&ctx, aio_pending_size);
+	ret = asys_context_init(&ctx, get_aio_pending_size());
 	if (ret != 0) {
 		DEBUG(1, ("asys_context_init failed: %s\n", strerror(ret)));
 		return false;
@@ -866,14 +866,14 @@ static void vfswrap_asys_finished(struct tevent_context *ev,
 					uint16_t flags, void *p)
 {
 	struct asys_context *asys_ctx = (struct asys_context *)p;
-	struct asys_result results[outstanding_aio_calls];
+	struct asys_result results[get_outstanding_aio_calls()];
 	int i, ret;
 
 	if ((flags & TEVENT_FD_READ) == 0) {
 		return;
 	}
 
-	ret = asys_results(asys_ctx, results, outstanding_aio_calls);
+	ret = asys_results(asys_ctx, results, get_outstanding_aio_calls());
 	if (ret < 0) {
 		DEBUG(1, ("asys_results returned %s\n", strerror(-ret)));
 		return;
diff --git a/source3/smbd/aio.c b/source3/smbd/aio.c
index 253782b..1216a0d 100644
--- a/source3/smbd/aio.c
+++ b/source3/smbd/aio.c
@@ -26,6 +26,38 @@
 #include "lib/tevent_wait.h"
 
 /****************************************************************************
+ Statics plus accessor functions.
+*****************************************************************************/
+
+static int aio_pending_size = 100;  /* tevent supports 100 signals SA_SIGINFO */
+static int outstanding_aio_calls;
+
+int get_aio_pending_size(void)
+{
+	return aio_pending_size;
+}
+
+void set_aio_pending_size(int newsize)
+{
+	aio_pending_size = newsize;
+}
+
+int get_outstanding_aio_calls(void)
+{
+	return outstanding_aio_calls;
+}
+
+void increment_outstanding_aio_calls(void)
+{
+	outstanding_aio_calls++;
+}
+
+void decrement_outstanding_aio_calls(void)
+{
+	outstanding_aio_calls--;
+}
+
+/****************************************************************************
  The buffer we keep around whilst an aio request is in process.
 *****************************************************************************/
 
@@ -50,7 +82,7 @@ bool aio_write_through_requested(struct aio_extra *aio_ex)
 
 static int aio_extra_destructor(struct aio_extra *aio_ex)
 {
-	outstanding_aio_calls--;
+	decrement_outstanding_aio_calls();
 	return 0;
 }
 
@@ -82,7 +114,7 @@ static struct aio_extra *create_aio_extra(TALLOC_CTX *mem_ctx,
 	}
 	talloc_set_destructor(aio_ex, aio_extra_destructor);
 	aio_ex->fsp = fsp;
-	outstanding_aio_calls++;
+	increment_outstanding_aio_calls();
 	return aio_ex;
 }
 
@@ -186,10 +218,10 @@ NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
 		return NT_STATUS_RETRY;
 	}
 
-	if (outstanding_aio_calls >= aio_pending_size) {
+	if (get_outstanding_aio_calls() >= get_aio_pending_size()) {
 		DEBUG(10,("schedule_aio_read_and_X: Already have %d aio "
 			  "activities outstanding.\n",
-			  outstanding_aio_calls ));
+			  get_outstanding_aio_calls() ));
 		return NT_STATUS_RETRY;
 	}
 
@@ -452,10 +484,10 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
 		return NT_STATUS_RETRY;
 	}
 
-	if (outstanding_aio_calls >= aio_pending_size) {
+	if (get_outstanding_aio_calls() >= get_aio_pending_size()) {
 		DEBUG(3,("schedule_aio_write_and_X: Already have %d aio "
 			 "activities outstanding.\n",
-			  outstanding_aio_calls ));
+			  get_outstanding_aio_calls() ));
 		DEBUG(10,("schedule_aio_write_and_X: failed to schedule "
 			  "aio_write for file %s, offset %.0f, len = %u "
 			  "(mid = %u)\n",
@@ -538,7 +570,8 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
 		  "%s, offset %.0f, len = %u (mid = %u) "
 		  "outstanding_aio_calls = %d\n",
 		  fsp_str_dbg(fsp), (double)startpos, (unsigned int)numtowrite,
-		  (unsigned int)aio_ex->smbreq->mid, outstanding_aio_calls ));
+		  (unsigned int)aio_ex->smbreq->mid,
+		  get_outstanding_aio_calls() ));
 
 	return NT_STATUS_OK;
 }
@@ -711,10 +744,10 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
 		return NT_STATUS_RETRY;
 	}
 
-	if (outstanding_aio_calls >= aio_pending_size) {
+	if (get_outstanding_aio_calls() >= get_aio_pending_size()) {
 		DEBUG(10,("smb2: Already have %d aio "
 			"activities outstanding.\n",
-			outstanding_aio_calls ));
+			get_outstanding_aio_calls() ));
 		return NT_STATUS_RETRY;
 	}
 
@@ -867,10 +900,10 @@ NTSTATUS schedule_aio_smb2_write(connection_struct *conn,
 		return NT_STATUS_RETRY;
 	}
 
-	if (outstanding_aio_calls >= aio_pending_size) {
+	if (get_outstanding_aio_calls() >= get_aio_pending_size()) {
 		DEBUG(3,("smb2: Already have %d aio "
 			"activities outstanding.\n",
-			outstanding_aio_calls ));
+			get_outstanding_aio_calls() ));
 		return NT_STATUS_RETRY;
 	}
 
@@ -939,7 +972,7 @@ NTSTATUS schedule_aio_smb2_write(connection_struct *conn,
 		(double)in_offset,
 		(unsigned int)in_data.length,
 		(unsigned int)aio_ex->smbreq->mid,
-		outstanding_aio_calls ));
+		get_outstanding_aio_calls() ));
 
 	return NT_STATUS_OK;
 }
diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c
index a501234..70805a1 100644
--- a/source3/smbd/globals.c
+++ b/source3/smbd/globals.c
@@ -24,9 +24,6 @@
 #include "messages.h"
 #include <tdb.h>
 
-int aio_pending_size = 100;	/* tevent supports 100 signals SA_SIGINFO */
-int outstanding_aio_calls = 0;
-
 #ifdef USE_DMAPI
 struct smbd_dmapi_context *dmapi_ctx = NULL;
 #endif
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index b567a58..0422cbe 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -22,9 +22,6 @@
 #include "librpc/gen_ndr/smbXsrv.h"
 #include "smbprofile.h"
 
-extern int aio_pending_size;
-extern int outstanding_aio_calls;
-
 #ifdef USE_DMAPI
 struct smbd_dmapi_context;
 extern struct smbd_dmapi_context *dmapi_ctx;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 2eac3ec..95414e6 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -66,6 +66,11 @@ void srv_set_signing(struct smbXsrv_connection *conn,
 
 /* The following definitions come from smbd/aio.c  */
 
+int get_aio_pending_size(void);
+void set_aio_pending_size(int newsize);
+int get_outstanding_aio_calls(void);
+void increment_outstanding_aio_calls(void);
+void decrement_outstanding_aio_calls(void);
 struct aio_extra;
 bool aio_write_through_requested(struct aio_extra *aio_ex);
 NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
diff --git a/source3/smbd/smb2_flush.c b/source3/smbd/smb2_flush.c
index 04a8710..d26707a 100644
--- a/source3/smbd/smb2_flush.c
+++ b/source3/smbd/smb2_flush.c
@@ -110,15 +110,18 @@ struct smbd_smb2_flush_state {
 	struct smbd_smb2_request *smb2req;
 };
 
+static void smbd_smb2_flush_done(struct tevent_req *subreq);
+
 static struct tevent_req *smbd_smb2_flush_send(TALLOC_CTX *mem_ctx,
 					       struct tevent_context *ev,
 					       struct smbd_smb2_request *smb2req,
 					       struct files_struct *fsp)
 {
 	struct tevent_req *req;
+	struct tevent_req *subreq;
 	struct smbd_smb2_flush_state *state;
-	NTSTATUS status;
 	struct smb_request *smbreq;
+	int ret;
 
 	req = tevent_req_create(mem_ctx, &state,
 				struct smbd_smb2_flush_state);
@@ -145,16 +148,73 @@ static struct tevent_req *smbd_smb2_flush_send(TALLOC_CTX *mem_ctx,
 		return tevent_req_post(req, ev);
 	}
 
-	status = sync_file(smbreq->conn, fsp, true);
-	if (!NT_STATUS_IS_OK(status)) {
-		DEBUG(5,("smbd_smb2_flush: sync_file for %s returned %s\n",
-			 fsp_str_dbg(fsp), nt_errstr(status)));
-		tevent_req_nterror(req, status);
+	if (fsp->fh->fd == -1) {
+		tevent_req_nterror(req, NT_STATUS_INVALID_HANDLE);
+		return tevent_req_post(req, ev);
+	}
+
+	if (!lp_strict_sync(SNUM(smbreq->conn))) {
+		/*
+		 * No strict sync. Don't really do
+		 * anything here.
+		 */
+		tevent_req_done(req);
+		return tevent_req_post(req, ev);
+	}
+
+	if (get_outstanding_aio_calls() >= get_aio_pending_size()) {
+		/* No more allowed aio. Synchronous flush. */
+		NTSTATUS status = sync_file(smbreq->conn, fsp, true);
+		if (!NT_STATUS_IS_OK(status)) {
+			DEBUG(5,("sync_file for %s returned %s\n",
+				fsp_str_dbg(fsp),
+				nt_errstr(status)));
+			tevent_req_nterror(req, status);
+			return tevent_req_post(req, ev);
+		}
+		tevent_req_done(req);
+		return tevent_req_post(req, ev);
+	}
+
+	ret = flush_write_cache(fsp, SAMBA_SYNC_FLUSH);
+	if (ret == -1) {
+		tevent_req_nterror(req,  map_nt_error_from_unix(errno));
+		return tevent_req_post(req, ev);
+	}
+
+	subreq = SMB_VFS_FSYNC_SEND(state, ev, fsp);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+
+	tevent_req_set_callback(subreq, smbd_smb2_flush_done, req);
+
+	/* Ensure any close request knows about this outstanding IO. */
+	if (!aio_add_req_to_fsp(fsp, req)) {
+		tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
 		return tevent_req_post(req, ev);
 	}
 
+	increment_outstanding_aio_calls();
+	return req;
+
+}
+
+static void smbd_smb2_flush_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	int ret, err;
+
+	decrement_outstanding_aio_calls();
+
+	ret = SMB_VFS_FSYNC_RECV(subreq, &err);
+	TALLOC_FREE(subreq);
+	if (ret == -1) {
+		tevent_req_error(req, err);
+		return;
+	}
 	tevent_req_done(req);
-	return tevent_req_post(req, ev);
 }
 
 static NTSTATUS smbd_smb2_flush_recv(struct tevent_req *req)


-- 
Samba Shared Repository



More information about the samba-cvs mailing list