[PATCHES] net: Add net tdb command to print information from tdb records

Christof Schmitt cs at samba.org
Wed Apr 27 17:54:16 UTC 2016


Please ignore for now. I will expand on this a bit and also add a
testcase. New patches will follow.

Christof

On Fri, Apr 22, 2016 at 03:42:36PM -0700, Christof Schmitt wrote:

> From d09af7183760492848a33e3ef04d4b5614e1bbeb Mon Sep 17 00:00:00 2001
> From: Christof Schmitt <cs at samba.org>
> Date: Tue, 19 Apr 2016 15:53:41 -0700
> Subject: [PATCH 1/2] net: Add net tdb command to print information from tdb
>  records
> 
> The main purpose is to debug "hot" records from ctdb. ctdb tracks
> contended records and identifies them by key in the dbstatistics:
> 
> DB Statistics: locking.tdb
> [...]
>  Num Hot Keys:     1
>      Count:3 Key:6a4128e3ced4681b02a00000000000000000000000000000
> 
> This command allows querying additional information for the associated
> key to identify the affected file. For now this only adds a subcommand
> for the locking.tdb, but could be extended to others:
> 
> net tdb locking 6a4128e3ced4681b02a00000000000000000000000000000
> Share path: /test/share
> Name:       README
> 
> Signed-off-by: Christof Schmitt <cs at samba.org>
> ---
>  source3/utils/net.c       |  8 +++++
>  source3/utils/net_proto.h |  3 ++
>  source3/utils/net_tdb.c   | 79 +++++++++++++++++++++++++++++++++++++++++++++++
>  source3/wscript_build     |  1 +
>  4 files changed, 91 insertions(+)
>  create mode 100644 source3/utils/net_tdb.c
> 
> diff --git a/source3/utils/net.c b/source3/utils/net.c
> index 3d0940d..a6817f5 100644
> --- a/source3/utils/net.c
> +++ b/source3/utils/net.c
> @@ -751,6 +751,14 @@ static struct functable net_func[] = {
>  		   "'net notify' commands.")
>  	},
>  
> +	{	"tdb",
> +		net_tdb,
> +		NET_TRANSPORT_LOCAL,
> +		N_("Show information from tdb records"),
> +		N_("  Use 'net help tdb' to get more information about "
> +		   "'net tdb' commands.")
> +	},
> +
>  #ifdef WITH_FAKE_KASERVER
>  	{	"afs",
>  		net_afs,
> diff --git a/source3/utils/net_proto.h b/source3/utils/net_proto.h
> index 093aa4b..f0ae538 100644
> --- a/source3/utils/net_proto.h
> +++ b/source3/utils/net_proto.h
> @@ -462,4 +462,7 @@ int net_rpc_trust(struct net_context *c, int argc, const char **argv);
>  int net_rpc_conf(struct net_context *c, int argc, const char **argv);
>  
>  int net_notify(struct net_context *c, int argc, const char **argv);
> +
> +int net_tdb(struct net_context *c, int argc, const char **argv);
> +
>  #endif /*  _NET_PROTO_H_  */
> diff --git a/source3/utils/net_tdb.c b/source3/utils/net_tdb.c
> new file mode 100644
> index 0000000..d33de20
> --- /dev/null
> +++ b/source3/utils/net_tdb.c
> @@ -0,0 +1,79 @@
> +/*
> + * Samba Unix/Linux client library
> + * net tdb commands to query tdb record information
> + * Copyright (C) 2016 Christof Schmitt <cs at samba.org>
> + *
> + * 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 "includes.h"
> +#include "utils/net.h"
> +#include "locking/proto.h"
> +#include "librpc/gen_ndr/open_files.h"
> +
> +static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
> +{
> +	DATA_BLOB blob;
> +	TALLOC_CTX *mem_ctx = talloc_stackframe();
> +	const char *hexkey;
> +	struct file_id id;
> +	struct share_mode_lock *lock;
> +
> +	if (argc != 1) {
> +		d_printf("Usage: net tdb locking <key>\n");
> +		TALLOC_FREE(mem_ctx);
> +		return -1;
> +	}
> +
> +	hexkey = argv[0];
> +
> +	blob = strhex_to_data_blob(mem_ctx, hexkey);
> +	if (blob.length != sizeof(struct file_id)) {
> +		d_printf("Invalid length of key\n");
> +		TALLOC_FREE(mem_ctx);
> +		return -1;
> +	}
> +
> +	id = *(struct file_id *)blob.data;
> +
> +	locking_init_readonly();
> +
> +	lock = fetch_share_mode_unlocked(mem_ctx, id);
> +
> +	if (lock == NULL) {
> +		d_printf("Record with key %s not found.\n", hexkey);
> +		return -1;
> +	}
> +
> +	d_printf("Share path: %s\n", lock->data->servicepath);
> +	d_printf("Name:       %s\n", lock->data->base_name);
> +
> +	TALLOC_FREE(mem_ctx);
> +	return 0;
> +}
> +
> +int net_tdb(struct net_context *c, int argc, const char **argv)
> +{
> +	struct functable func[] = {
> +		{ "locking",
> +		  net_tdb_locking,
> +		  NET_TRANSPORT_LOCAL,
> +		  N_("Show information for a record in locking.tdb"),
> +		  N_("net tdb locking <key>")
> +		},
> +		{NULL, NULL, 0, NULL, NULL}
> +	};
> +
> +	return net_run_function(c, argc, argv, "net tdb", func);
> +}
> diff --git a/source3/wscript_build b/source3/wscript_build
> index ed2424d..383e225 100755
> --- a/source3/wscript_build
> +++ b/source3/wscript_build
> @@ -1117,6 +1117,7 @@ bld.SAMBA3_BINARY('net',
>                   utils/net_rpc_conf.c
>                   utils/net_afs.c
>                   utils/net_notify.c
> +                 utils/net_tdb.c
>                   registry/reg_parse.c
>                   registry/reg_format.c
>                   registry/reg_import.c
> -- 
> 1.8.3.1
> 
> 
> From b048732fcaf3e39126ce7d208c54511a696e5807 Mon Sep 17 00:00:00 2001
> From: Christof Schmitt <cs at samba.org>
> Date: Fri, 22 Apr 2016 15:38:43 -0700
> Subject: [PATCH 2/2] docs-xml: Document net tdb command
> 
> Signed-off-by: Christof Schmitt <cs at samba.org>
> ---
>  docs-xml/manpages/net.8.xml | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/docs-xml/manpages/net.8.xml b/docs-xml/manpages/net.8.xml
> index 6612191..0497e57 100644
> --- a/docs-xml/manpages/net.8.xml
> +++ b/docs-xml/manpages/net.8.xml
> @@ -2708,6 +2708,27 @@ Dump the locking table of a certain global lock.
>  </refsect2>
>  
>  <refsect2>
> +	<title>TDB</title>
> +
> +	<para>Print information from tdb records.</para>
> +
> +	<refsect3>
> +		<title>TDB LOCKING <replaceable>key</replaceable></title>
> +
> +		<para>List sharename and filename for a record from
> +		locking.tdb</para>
> +
> +		<itemizedlist>
> +			<listitem>
> +				<para><replaceable>KEY</replaceable>
> +				Key of the tdb record as hex string.</para>
> +			</listitem>
> +		</itemizedlist>
> +
> +	</refsect3>
> +</refsect2>
> +
> +<refsect2>
>  <title>HELP [COMMAND]</title>
>  
>  <para>Gives usage information for the specified command.</para>
> -- 
> 1.8.3.1
> 




More information about the samba-technical mailing list