[PATCH] Remove some unused code, optimize leases_db.c

Jeremy Allison jra at samba.org
Tue Oct 2 17:17:26 UTC 2018


On Tue, Oct 02, 2018 at 08:32:45AM +0200, Volker Lendecke via samba-technical wrote:
> Hi!
> 
> Review appreciated!
> 
> Thanks, Volker
> 
> https://gitlab.com/samba-team/devel/samba/pipelines/31643297

Nice cleanups ! RB+ and pushed.

Jeremy.

> SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
> phone: +49-551-370000-0, fax: +49-551-370000-9
> AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
> http://www.sernet.de, mailto:kontakt at sernet.de

> From 5eb07037da2b5497c479470e4eacd072ded39ca0 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 25 Sep 2018 03:58:16 -0700
> Subject: [PATCH 1/6] includes: Remove an unused #define
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/include/smb.h | 5 -----
>  1 file changed, 5 deletions(-)
> 
> diff --git a/source3/include/smb.h b/source3/include/smb.h
> index 89469fc1433..7f22a60a3aa 100644
> --- a/source3/include/smb.h
> +++ b/source3/include/smb.h
> @@ -546,11 +546,6 @@ enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT,
>  
>  #define FNUM_FIELD_INVALID 0
>  
> -/* 
> - * Size of buffer to use when moving files across filesystems. 
> - */
> -#define COPYBUF_SIZE (8*1024)
> -
>  /*
>   * Map the Core and Extended Oplock requesst bits down
>   * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
> -- 
> 2.11.0
> 
> 
> From 1cf4b7683e7ac3e7ed496c595b8cc58dd35d65e8 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 25 Sep 2018 03:58:29 -0700
> Subject: [PATCH 2/6] includes: Fix a typo
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/include/smb.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/include/smb.h b/source3/include/smb.h
> index 7f22a60a3aa..c37dbeb1286 100644
> --- a/source3/include/smb.h
> +++ b/source3/include/smb.h
> @@ -547,7 +547,7 @@ enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT,
>  #define FNUM_FIELD_INVALID 0
>  
>  /*
> - * Map the Core and Extended Oplock requesst bits down
> + * Map the Core and Extended Oplock request bits down
>   * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
>   */
>  
> -- 
> 2.11.0
> 
> 
> From 741dfdf07ad75e4edffff60deabeafd97604c26a Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 25 Sep 2018 04:02:35 -0700
> Subject: [PATCH 3/6] includes: Remove an unused #define
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/include/smb.h | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/source3/include/smb.h b/source3/include/smb.h
> index c37dbeb1286..0fd9471c356 100644
> --- a/source3/include/smb.h
> +++ b/source3/include/smb.h
> @@ -50,10 +50,6 @@
>  
>  #define SIZEOFWORD 2
>  
> -#ifndef DEF_CREATE_MASK
> -#define DEF_CREATE_MASK (0755)
> -#endif
> -
>  /* string manipulation flags - see clistr.c and srvstr.c */
>  #define STR_TERMINATE 1
>  #define STR_UPPER 2
> -- 
> 2.11.0
> 
> 
> From 6bfe3407e3d7a24c574745a87f0f5153e07fbbad Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 25 Sep 2018 08:57:17 -0700
> Subject: [PATCH 4/6] lib: Remove unused tdb_pack_append()
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/include/util_tdb.h |  2 --
>  source3/lib/util_tdb.c     | 34 ----------------------------------
>  2 files changed, 36 deletions(-)
> 
> diff --git a/source3/include/util_tdb.h b/source3/include/util_tdb.h
> index 11160335975..8dc104834e8 100644
> --- a/source3/include/util_tdb.h
> +++ b/source3/include/util_tdb.h
> @@ -38,8 +38,6 @@ int tdb_trans_delete(struct tdb_context *tdb, TDB_DATA key);
>   */
>  int tdb_unpack(const uint8_t *buf, int bufsize, const char *fmt, ...);
>  size_t tdb_pack(uint8_t *buf, int bufsize, const char *fmt, ...);
> -bool tdb_pack_append(TALLOC_CTX *mem_ctx, uint8_t **buf, size_t *len,
> -		     const char *fmt, ...);
>  
>  struct tdb_context *tdb_open_log(const char *name, int hash_size,
>  				 int tdb_flags, int open_flags, mode_t mode);
> diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
> index 1e533e82534..80e66e0a108 100644
> --- a/source3/lib/util_tdb.c
> +++ b/source3/lib/util_tdb.c
> @@ -140,40 +140,6 @@ size_t tdb_pack(uint8_t *buf, int bufsize, const char *fmt, ...)
>  	return result;
>  }
>  
> -bool tdb_pack_append(TALLOC_CTX *mem_ctx, uint8_t **buf, size_t *len,
> -		     const char *fmt, ...)
> -{
> -	va_list ap;
> -	size_t len1, len2;
> -
> -	va_start(ap, fmt);
> -	len1 = tdb_pack_va(NULL, 0, fmt, ap);
> -	va_end(ap);
> -
> -	if (mem_ctx != NULL) {
> -		*buf = talloc_realloc(mem_ctx, *buf, uint8_t,
> -					    (*len) + len1);
> -	} else {
> -		*buf = SMB_REALLOC_ARRAY(*buf, uint8_t, (*len) + len1);
> -	}
> -
> -	if (*buf == NULL) {
> -		return False;
> -	}
> -
> -	va_start(ap, fmt);
> -	len2 = tdb_pack_va((*buf)+(*len), len1, fmt, ap);
> -	va_end(ap);
> -
> -	if (len1 != len2) {
> -		return False;
> -	}
> -
> -	*len += len2;
> -
> -	return True;
> -}
> -
>  /****************************************************************************
>   Useful pair of routines for packing/unpacking data consisting of
>   integers and strings.
> -- 
> 2.11.0
> 
> 
> From 7c33a00d9c0cc101e34a9dd6f870c4fa0d929c59 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Mon, 10 Sep 2018 14:59:14 +0200
> Subject: [PATCH 5/6] smbd: Fix a warning
> 
> gcc complains that the "const" is ignored on function return
> types. Right now I'm compiling this file a lot, so silence this
> warning :-)
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/share_mode_lock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
> index 919e74c0851..a97d8d44930 100644
> --- a/source3/locking/share_mode_lock.c
> +++ b/source3/locking/share_mode_lock.c
> @@ -142,7 +142,7 @@ static TDB_DATA locking_key(const struct file_id *id)
>   necessary we can always make this a separate (smaller) cache.
>  ******************************************************************/
>  
> -static const DATA_BLOB memcache_key(const struct file_id *id)
> +static DATA_BLOB memcache_key(const struct file_id *id)
>  {
>  	return data_blob_const((const void *)id, sizeof(*id));
>  }
> -- 
> 2.11.0
> 
> 
> From 7fc5b76302fdc98d36b5de2de84021dd3d126a36 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Thu, 13 Sep 2018 21:05:05 +0200
> Subject: [PATCH 6/6] leases: Streamline leases_db_key a bit
> 
> We don't need to talloc the blob, it's always the same size
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/leases_db.c | 62 +++++++++++++++------------------------------
>  1 file changed, 21 insertions(+), 41 deletions(-)
> 
> diff --git a/source3/locking/leases_db.c b/source3/locking/leases_db.c
> index ea63b00e272..31576280fb6 100644
> --- a/source3/locking/leases_db.c
> +++ b/source3/locking/leases_db.c
> @@ -60,33 +60,30 @@ bool leases_db_init(bool read_only)
>  	return true;
>  }
>  
> -static bool leases_db_key(TALLOC_CTX *mem_ctx,
> -			  const struct GUID *client_guid,
> -			  const struct smb2_lease_key *lease_key,
> -			  TDB_DATA *key)
> +struct leases_db_key_buf {
> +	uint8_t buf[32];
> +};
> +
> +static TDB_DATA leases_db_key(struct leases_db_key_buf *buf,
> +			      const struct GUID *client_guid,
> +			      const struct smb2_lease_key *lease_key)
>  {
>  	struct leases_db_key db_key = {
>  		.client_guid = *client_guid,
>  		.lease_key = *lease_key };
> -	DATA_BLOB blob;
> +	DATA_BLOB blob = { .data = buf->buf, .length = sizeof(buf->buf) };
>  	enum ndr_err_code ndr_err;
>  
>  	if (DEBUGLEVEL >= 10) {
> -		DEBUG(10, ("%s:\n", __func__));
> +		DBG_DEBUG("\n");
>  		NDR_PRINT_DEBUG(leases_db_key, &db_key);
>  	}
>  
> -	ndr_err = ndr_push_struct_blob(
> -		&blob, mem_ctx, &db_key,
> -		(ndr_push_flags_fn_t)ndr_push_leases_db_key);
> -	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
> -		DEBUG(10, ("%s: ndr_push_struct_blob_failed: %s\n",
> -			   __func__, ndr_errstr(ndr_err)));
> -		return false;
> -	}
> +	ndr_err = ndr_push_struct_into_fixed_blob(
> +		&blob, &db_key, (ndr_push_flags_fn_t)ndr_push_leases_db_key);
> +	SMB_ASSERT(NDR_ERR_CODE_IS_SUCCESS(ndr_err));
>  
> -	*key = make_tdb_data(blob.data, blob.length);
> -	return true;
> +	return (TDB_DATA) { .dptr = buf->buf, .dsize = sizeof(buf->buf) };
>  }
>  
>  NTSTATUS leases_db_add(const struct GUID *client_guid,
> @@ -96,11 +93,12 @@ NTSTATUS leases_db_add(const struct GUID *client_guid,
>  		       const char *base_name,
>  		       const char *stream_name)
>  {
> -	TDB_DATA db_key, db_value;
> +	struct leases_db_key_buf keybuf;
> +	TDB_DATA db_key = leases_db_key(&keybuf, client_guid, lease_key);
> +	TDB_DATA db_value;
>  	DATA_BLOB blob;
>  	struct db_record *rec;
>  	NTSTATUS status;
> -	bool ok;
>  	struct leases_db_value new_value;
>  	struct leases_db_file new_file;
>  	struct leases_db_value *value = NULL;
> @@ -110,14 +108,7 @@ NTSTATUS leases_db_add(const struct GUID *client_guid,
>  		return NT_STATUS_INTERNAL_ERROR;
>  	}
>  
> -	ok = leases_db_key(talloc_tos(), client_guid, lease_key, &db_key);
> -	if (!ok) {
> -		DEBUG(10, ("%s: leases_db_key failed\n", __func__));
> -		return NT_STATUS_NO_MEMORY;
> -	}
> -
>  	rec = dbwrap_fetch_locked(leases_db, talloc_tos(), db_key);
> -	TALLOC_FREE(db_key.dptr);
>  	if (rec == NULL) {
>  		return NT_STATUS_INTERNAL_ERROR;
>  	}
> @@ -221,26 +212,21 @@ NTSTATUS leases_db_del(const struct GUID *client_guid,
>  		       const struct smb2_lease_key *lease_key,
>  		       const struct file_id *id)
>  {
> -	TDB_DATA db_key, db_value;
> +	struct leases_db_key_buf keybuf;
> +	TDB_DATA db_key = leases_db_key(&keybuf, client_guid, lease_key);
> +	TDB_DATA db_value;
>  	struct db_record *rec;
>  	NTSTATUS status;
>  	struct leases_db_value *value;
>  	enum ndr_err_code ndr_err;
>  	DATA_BLOB blob;
>  	uint32_t i;
> -	bool ok;
>  
>  	if (!leases_db_init(false)) {
>  		return NT_STATUS_INTERNAL_ERROR;
>  	}
>  
> -	ok = leases_db_key(talloc_tos(), client_guid, lease_key, &db_key);
> -	if (!ok) {
> -		return NT_STATUS_NO_MEMORY;
> -	}
> -
>  	rec = dbwrap_fetch_locked(leases_db, talloc_tos(), db_key);
> -	TALLOC_FREE(db_key.dptr);
>  	if (rec == NULL) {
>  		return NT_STATUS_NOT_FOUND;
>  	}
> @@ -372,20 +358,15 @@ NTSTATUS leases_db_parse(const struct GUID *client_guid,
>  					void *private_data),
>  			 void *private_data)
>  {
> -	TDB_DATA db_key;
> +	struct leases_db_key_buf keybuf;
> +	TDB_DATA db_key = leases_db_key(&keybuf, client_guid, lease_key);
>  	struct leases_db_fetch_state state;
>  	NTSTATUS status;
> -	bool ok;
>  
>  	if (!leases_db_init(true)) {
>  		return NT_STATUS_INTERNAL_ERROR;
>  	}
>  
> -	ok = leases_db_key(talloc_tos(), client_guid, lease_key, &db_key);
> -	if (!ok) {
> -		return NT_STATUS_NO_MEMORY;
> -	}
> -
>  	state = (struct leases_db_fetch_state) {
>  		.parser = parser,
>  		.private_data = private_data,
> @@ -394,7 +375,6 @@ NTSTATUS leases_db_parse(const struct GUID *client_guid,
>  
>  	status = dbwrap_parse_record(leases_db, db_key, leases_db_parser,
>  				     &state);
> -	TALLOC_FREE(db_key.dptr);
>  	if (!NT_STATUS_IS_OK(status)) {
>  		return status;
>  	}
> -- 
> 2.11.0
> 




More information about the samba-technical mailing list