[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Sep 18 21:28:03 UTC 2019


The branch, master has been updated
       via  bc4e8b1abaf messaging: Do POOL_USAGE via a socket
       via  23bee5da950 lib: Add talloc_full_report_printf()
       via  930ec152123 lib: Align integer types
       via  3084928383c messaging4: Pass fds to messaging handlers
      from  3263dd32fed Argument to control number of operations -o no longer valid

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


- Log -----------------------------------------------------------------
commit bc4e8b1abaf8431d1f507107cf60e57da75c0bef
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 30 15:08:40 2019 +0200

    messaging: Do POOL_USAGE via a socket
    
    This makes debugging run-away processes much more efficient and even
    possible at all: If the pool-usage output is more than 256MB, the
    previous code could not realloc it and threw it away. Also, it is not
    helpful for an already huge process to allocate even more.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed Sep 18 21:27:30 UTC 2019 on sn-devel-184

commit 23bee5da95026d161159da74a032780a713c820a
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 30 17:09:20 2019 +0200

    lib: Add talloc_full_report_printf()
    
    Print the talloc full report into a FILE*. talloc itself provides a
    very similar function, talloc_report_full(). However, that has a
    slightly different output, in particular it does not print the
    contents of strings, which is very handy for debugging.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 930ec152123e6a7c37f38e52cc7fd32f755a6b83
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 2 11:41:05 2019 +0200

    lib: Align integer types
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3084928383cdeafc53b2154f458464d9174faff2
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 18 09:19:37 2019 -0700

    messaging4: Pass fds to messaging handlers
    
    Boiler-plate replacement moving the (num_fds!=0) check down
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 lib/util/talloc_report_printf.c                    | 109 +++++++++++++++++
 .../smb2_lock.h => lib/util/talloc_report_printf.h |  17 ++-
 lib/util/wscript_build                             |   7 ++
 source3/lib/tallocmsg.c                            | 135 ++++++++++-----------
 source3/utils/smbcontrol.c                         |  45 +++----
 source3/winbindd/winbindd_util.c                   |   7 ++
 source3/wscript_build                              |   2 +-
 source4/dsdb/repl/drepl_ridalloc.c                 |  12 +-
 source4/lib/messaging/messaging.c                  | 107 ++++++++++++----
 source4/lib/messaging/messaging.h                  |  11 +-
 source4/lib/messaging/messaging_handlers.c         |  14 +++
 source4/lib/messaging/pymessaging.c                |  16 ++-
 source4/lib/messaging/tests/messaging.c            |  79 +++++++++++-
 source4/ntvfs/common/notify.c                      |  23 +++-
 source4/ntvfs/posix/pvfs_oplock.c                  |  13 +-
 source4/ntvfs/posix/pvfs_wait.c                    |  13 +-
 source4/smbd/server.c                              |   7 ++
 17 files changed, 457 insertions(+), 160 deletions(-)
 create mode 100644 lib/util/talloc_report_printf.c
 copy libcli/smb/smb2_lock.h => lib/util/talloc_report_printf.h (73%)


Changeset truncated at 500 lines:

diff --git a/lib/util/talloc_report_printf.c b/lib/util/talloc_report_printf.c
new file mode 100644
index 00000000000..cdf75b64913
--- /dev/null
+++ b/lib/util/talloc_report_printf.c
@@ -0,0 +1,109 @@
+/*
+ * talloc_report into a FILE
+ *
+ * Copyright Volker Lendecke <vl at samba.org> 2015
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "talloc_report_printf.h"
+
+static void talloc_report_printf_helper(
+	const void *ptr,
+	int depth,
+	int max_depth,
+	int is_ref,
+	void *private_data)
+{
+	FILE *f = private_data;
+	const char *name = talloc_get_name(ptr);
+
+	if (is_ref) {
+		fprintf(f,
+			"%*sreference to: %s\n",
+			depth*4,
+			"",
+			name);
+		return;
+	}
+
+	if (depth == 0) {
+		fprintf(f,
+			"%stalloc report on '%s' "
+			"(total %6zu bytes in %3zu blocks)\n",
+			(max_depth < 0 ? "full " :""), name,
+			talloc_total_size(ptr),
+			talloc_total_blocks(ptr));
+		return;
+	}
+
+	if (strcmp(name, "char") == 0) {
+		/*
+		 * Print out the first 50 bytes of the string
+		 */
+		fprintf(f,
+			"%*s%-30s contains %6zu bytes in %3zu blocks "
+			"(ref %zu): %*s\n", depth*4, "", name,
+			talloc_total_size(ptr),
+			talloc_total_blocks(ptr),
+			talloc_reference_count(ptr),
+			(int)MIN(50, talloc_get_size(ptr)),
+			(const char *)ptr);
+		return;
+	}
+
+	fprintf(f,
+		"%*s%-30s contains %6zu bytes in %3zu blocks (ref %zu) %p\n",
+		depth*4, "", name,
+		talloc_total_size(ptr),
+		talloc_total_blocks(ptr),
+		talloc_reference_count(ptr),
+		ptr);
+}
+
+void talloc_full_report_printf(TALLOC_CTX *root, FILE *f)
+{
+	talloc_report_depth_cb(root, 0, -1, talloc_report_printf_helper, f);
+
+#ifdef HAVE_MALLINFO
+	{
+		struct mallinfo mi;
+
+		mi = mallinfo();
+		fprintf(f,
+			"mallinfo:\n"
+			"    arena: %d\n"
+			"    ordblks: %d\n"
+			"    smblks: %d\n"
+			"    hblks: %d\n"
+			"    hblkhd: %d\n"
+			"    usmblks: %d\n"
+			"    fsmblks: %d\n"
+			"    uordblks: %d\n"
+			"    fordblks: %d\n"
+			"    keepcost: %d\n",
+			mi.arena,
+			mi.ordblks,
+			mi.smblks,
+			mi.hblks,
+			mi.hblkhd,
+			mi.usmblks,
+			mi.fsmblks,
+			mi.uordblks,
+			mi.fordblks,
+			mi.keepcost);
+	}
+#endif /* HAVE_MALLINFO */
+}
diff --git a/libcli/smb/smb2_lock.h b/lib/util/talloc_report_printf.h
similarity index 73%
copy from libcli/smb/smb2_lock.h
copy to lib/util/talloc_report_printf.h
index f0e05355232..7881e655243 100644
--- a/libcli/smb/smb2_lock.h
+++ b/lib/util/talloc_report_printf.h
@@ -1,7 +1,7 @@
 /*
- * Unix SMB/CIFS implementation.
+ * talloc_report into a FILE
  *
- * Copyright (C) Volker Lendecke 2019
+ * Copyright Volker Lendecke <vl at samba.org> 2019
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,16 +17,13 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __LIBCLI_SMB_SMB2_LOCK_H__
-#define __LIBCLI_SMB_SMB2_LOCK_H__
+#ifndef _TALLOC_REPORT_PRINTF_H_
+#define _TALLOC_REPORT_PRINTF_H_
 
 #include "replace.h"
+#include "system/filesys.h"
+#include <talloc.h>
 
-struct smb2_lock_element {
-	uint64_t offset;
-	uint64_t length;
-	uint32_t flags;
-	uint32_t reserved;
-};
+void talloc_full_report_printf(TALLOC_CTX *root, FILE *f);
 
 #endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 5f005c41e49..7d446d810d1 100644
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -67,6 +67,13 @@ bld.SAMBA_LIBRARY('talloc_report',
                   private_library=True
                   )
 
+bld.SAMBA_LIBRARY('talloc_report_printf',
+                  source='talloc_report_printf.c',
+                  local_include=False,
+                  public_deps='talloc',
+                  private_library=True
+                  )
+
 bld.SAMBA_SUBSYSTEM('samba-util-core',
                     source='''data_blob.c util_file.c sys_popen.c time.c
                               signal.c util.c idtree.c fault.c
diff --git a/source3/lib/tallocmsg.c b/source3/lib/tallocmsg.c
index 9be1bf58a3c..42cbe2d9c02 100644
--- a/source3/lib/tallocmsg.c
+++ b/source3/lib/tallocmsg.c
@@ -18,92 +18,69 @@
 
 #include "includes.h"
 #include "messages.h"
-#include "lib/util/talloc_report.h"
+#include "lib/util/talloc_report_printf.h"
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
 #endif /* HAVE_MALLINFO */
 
- /**
- * Prepare memory allocation report based on mallinfo()
- **/
-static char *get_mallinfo_report(void *mem_ctx)
+static bool pool_usage_filter(struct messaging_rec *rec, void *private_data)
 {
-	char *report = NULL;
-#ifdef HAVE_MALLINFO
-	struct mallinfo mi;
-
-	mi = mallinfo();
-	report = talloc_asprintf(mem_ctx,
-				 "mallinfo:\n"
-				 "    arena: %d\n"
-				 "    ordblks: %d\n"
-				 "    smblks: %d\n"
-				 "    hblks: %d\n"
-				 "    hblkhd: %d\n"
-				 "    usmblks: %d\n"
-				 "    fsmblks: %d\n"
-				 "    uordblks: %d\n"
-				 "    fordblks: %d\n"
-				 "    keepcost: %d\n",
-				 mi.arena,
-				 mi.ordblks,
-				 mi.smblks,
-				 mi.hblks,
-				 mi.hblkhd,
-				 mi.usmblks,
-				 mi.fsmblks,
-				 mi.uordblks,
-				 mi.fordblks,
-				 mi.keepcost);
-#endif /* HAVE_MALLINFO */
+	if (rec->msg_type != MSG_REQ_POOL_USAGE) {
+		return false;
+	}
+
+	DBG_DEBUG("Got MSG_REQ_POOL_USAGE\n");
 
-	return report;
+	if (rec->num_fds != 1) {
+		DBG_DEBUG("Got %"PRIu8" fds, expected one\n", rec->num_fds);
+		return false;
+	}
+
+	return true;
 }
-/**
- * Respond to a POOL_USAGE message by sending back string form of memory
- * usage stats.
- **/
-static void msg_pool_usage(struct messaging_context *msg_ctx,
-			   void *private_data, 
-			   uint32_t msg_type, 
-			   struct server_id src,
-			   DATA_BLOB *data)
-{
-	char *report = NULL;
-	char *mreport = NULL;
-	int iov_size = 0;
-	struct iovec iov[2];
 
-	SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
 
-	DEBUG(2,("Got POOL_USAGE\n"));
+static void msg_pool_usage_do(struct tevent_req *req)
+{
+	struct messaging_context *msg_ctx = tevent_req_callback_data(
+		req, struct messaging_context);
+	struct messaging_rec *rec = NULL;
+	FILE *f = NULL;
+	int ret;
 
-	report = talloc_report_str(msg_ctx, NULL);
-	if (report != NULL) {
-		iov[iov_size].iov_base = report;
-		iov[iov_size].iov_len = talloc_get_size(report) - 1;
-		iov_size++;
+	ret = messaging_filtered_read_recv(req, talloc_tos(), &rec);
+	TALLOC_FREE(req);
+	if (ret != 0) {
+		DBG_DEBUG("messaging_filtered_read_recv returned %s\n",
+			  strerror(ret));
+		return;
 	}
 
-	mreport = get_mallinfo_report(msg_ctx);
-	if (mreport != NULL) {
-		iov[iov_size].iov_base = mreport;
-		iov[iov_size].iov_len = talloc_get_size(mreport) - 1;
-		iov_size++;
+	f = fdopen(rec->fds[0], "w");
+	if (f == NULL) {
+		close(rec->fds[0]);
+		TALLOC_FREE(rec);
+		DBG_DEBUG("fdopen failed: %s\n", strerror(errno));
 	}
 
-	if (iov_size) {
-		messaging_send_iov(msg_ctx,
-				   src,
-				   MSG_POOL_USAGE,
-				   iov,
-				   iov_size,
-				   NULL,
-				   0);
-	}
+	TALLOC_FREE(rec);
+
+	talloc_full_report_printf(NULL, f);
+
+	fclose(f);
+	f = NULL;
 
-	TALLOC_FREE(report);
-	TALLOC_FREE(mreport);
+	req = messaging_filtered_read_send(
+		msg_ctx,
+		messaging_tevent_context(msg_ctx),
+		msg_ctx,
+		pool_usage_filter,
+		NULL);
+	if (req == NULL) {
+		DBG_WARNING("messaging_filtered_read_send failed\n");
+		return;
+	}
+	tevent_req_set_callback(req, msg_pool_usage_do, msg_ctx);
 }
 
 /**
@@ -111,6 +88,18 @@ static void msg_pool_usage(struct messaging_context *msg_ctx,
  **/
 void register_msg_pool_usage(struct messaging_context *msg_ctx)
 {
-	messaging_register(msg_ctx, NULL, MSG_REQ_POOL_USAGE, msg_pool_usage);
+	struct tevent_req *req = NULL;
+
+	req = messaging_filtered_read_send(
+		msg_ctx,
+		messaging_tevent_context(msg_ctx),
+		msg_ctx,
+		pool_usage_filter,
+		NULL);
+	if (req == NULL) {
+		DBG_WARNING("messaging_filtered_read_send failed\n");
+		return;
+	}
+	tevent_req_set_callback(req, msg_pool_usage_do, msg_ctx);
 	DEBUG(2, ("Registered MSG_REQ_POOL_USAGE\n"));
-}	
+}
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index 1435cc57d0a..35cb7d39a02 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -125,18 +125,6 @@ static void print_pid_string_cb(struct messaging_context *msg,
 	num_replies++;
 }
 
-/* Message handler callback that displays a string on stdout */
-
-static void print_string_cb(struct messaging_context *msg,
-			    void *private_data, 
-			    uint32_t msg_type, 
-			    struct server_id pid,
-			    DATA_BLOB *data)
-{
-	printf("%*s", (int)data->length, (const char *)data->data);
-	num_replies++;
-}
-
 /* Send no message.  Useful for testing. */
 
 static bool do_noop(struct tevent_context *ev_ctx,
@@ -861,31 +849,32 @@ static bool do_ip_dropped(struct tevent_context *ev_ctx,
 
 static bool do_poolusage(struct tevent_context *ev_ctx,
 			 struct messaging_context *msg_ctx,
-			 const struct server_id pid,
+			 const struct server_id dst,
 			 const int argc, const char **argv)
 {
+	pid_t pid = procid_to_pid(&dst);
+	int stdout_fd = 1;
+
 	if (argc != 1) {
 		fprintf(stderr, "Usage: smbcontrol <dest> pool-usage\n");
 		return False;
 	}
 
-	messaging_register(msg_ctx, NULL, MSG_POOL_USAGE, print_string_cb);
-
-	/* Send a message and register our interest in a reply */
-
-	if (!send_message(msg_ctx, pid, MSG_REQ_POOL_USAGE, NULL, 0))
-		return False;
-
-	wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0);
-
-	/* No replies were received within the timeout period */
-
-	if (num_replies == 0)
-		printf("No replies received\n");
+	if (pid == 0) {
+		fprintf(stderr, "Can only send to a specific PID\n");
+		return false;
+	}
 
-	messaging_deregister(msg_ctx, MSG_POOL_USAGE, NULL);
+	messaging_send_iov(
+		msg_ctx,
+		dst,
+		MSG_REQ_POOL_USAGE,
+		NULL,
+		0,
+		&stdout_fd,
+		1);
 
-	return num_replies;
+	return true;
 }
 
 /* Fetch and print the ringbuf log */
diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
index cc4c3f7391a..ebe283ec712 100644
--- a/source3/winbindd/winbindd_util.c
+++ b/source3/winbindd/winbindd_util.c
@@ -849,10 +849,17 @@ static void wb_imsg_new_trusted_domain(struct imessaging_context *msg,
 				       void *private_data,
 				       uint32_t msg_type,
 				       struct server_id server_id,
+				       size_t num_fds,
+				       int *fds,
 				       DATA_BLOB *data)
 {
 	bool ok;
 
+	if (num_fds != 0) {
+		DBG_WARNING("Received %zu fds, ignoring message\n", num_fds);
+		return;
+	}
+
 	DBG_NOTICE("Rescanning trusted domains\n");
 
 	ok = add_trusted_domains_dc();
diff --git a/source3/wscript_build b/source3/wscript_build
index b93ee6ff796..6707b4bb146 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -429,7 +429,7 @@ bld.SAMBA3_SUBSYSTEM('samba3core',
                         server_id_db
                         messages_util
                         messages_dgm
-                        talloc_report
+                        talloc_report_printf
                         access
                         TDB_LIB
                         ''')
diff --git a/source4/dsdb/repl/drepl_ridalloc.c b/source4/dsdb/repl/drepl_ridalloc.c
index 3615859ed9b..1e7d937b9a8 100644
--- a/source4/dsdb/repl/drepl_ridalloc.c
+++ b/source4/dsdb/repl/drepl_ridalloc.c
@@ -248,10 +248,18 @@ WERROR dreplsrv_ridalloc_check_rid_pool(struct dreplsrv_service *service)
 
 /* called by the samldb ldb module to tell us to ask for a new RID
    pool */
-void dreplsrv_allocate_rid(struct imessaging_context *msg, void *private_data,
+void dreplsrv_allocate_rid(struct imessaging_context *msg,
+			   void *private_data,
 			   uint32_t msg_type,
-			   struct server_id server_id, DATA_BLOB *data)
+			   struct server_id server_id,
+			   size_t num_fds,
+			   int *fds,
+			   DATA_BLOB *data)
 {
 	struct dreplsrv_service *service = talloc_get_type(private_data, struct dreplsrv_service);
+	if (num_fds != 0) {
+		DBG_WARNING("Received %zu fds, ignoring message\n", num_fds);
+		return;
+	}
 	dreplsrv_ridalloc_check_rid_pool(service);
 }
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 1f27cf74e17..ec7f5f7bad7 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -35,7 +35,7 @@
 #include "../lib/util/tevent_ntstatus.h"
 #include "lib/param/param.h"
 #include "lib/util/server_id_db.h"
-#include "lib/util/talloc_report.h"
+#include "lib/util/talloc_report_printf.h"
 #include "../source3/lib/messages_dgm.h"
 #include "../source3/lib/messages_dgm_ref.h"
 #include "../source3/lib/messages_util.h"
@@ -67,49 +67,81 @@ struct dispatch_fn {
 
 /* an individual message */
 
-static void irpc_handler(struct imessaging_context *, void *,
-			 uint32_t, struct server_id, DATA_BLOB *);
+static void irpc_handler(struct imessaging_context *,
+			 void *,
+			 uint32_t,
+			 struct server_id,
+			 size_t,
+			 int *,
+			 DATA_BLOB *);
 
 
 /*
  A useful function for testing the message system.


-- 
Samba Shared Repository



More information about the samba-cvs mailing list