[PATCH] A few cleanups
Jeremy Allison
jra at samba.org
Wed Jun 21 00:18:19 UTC 2017
On Tue, Jun 20, 2017 at 09:45:06PM +0200, Volker Lendecke via samba-technical wrote:
> Hi!
>
> Review appreciated!
LGTM. Pushed !
> --
> 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 a51fd177987d1f35d279f3c0be19bfe026454ecb Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Sat, 17 Jun 2017 09:46:43 +0200
> Subject: [PATCH 1/7] messaging: Use size_t for array sizes
>
> We use talloc_realloc, that takes size_t.
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> source3/lib/messages.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/source3/lib/messages.c b/source3/lib/messages.c
> index e0ef1f8..83def69 100644
> --- a/source3/lib/messages.c
> +++ b/source3/lib/messages.c
> @@ -73,10 +73,10 @@ struct messaging_context {
> struct messaging_callback *callbacks;
>
> struct tevent_req **new_waiters;
> - unsigned num_new_waiters;
> + size_t num_new_waiters;
>
> struct tevent_req **waiters;
> - unsigned num_waiters;
> + size_t num_waiters;
>
> void *msg_dgm_ref;
> struct messaging_backend *remote;
> @@ -212,7 +212,7 @@ close_fail:
>
> static int messaging_context_destructor(struct messaging_context *ctx)
> {
> - unsigned i;
> + size_t i;
>
> for (i=0; i<ctx->num_new_waiters; i++) {
> if (ctx->new_waiters[i] != NULL) {
> @@ -768,7 +768,7 @@ static void messaging_filtered_read_cleanup(struct tevent_req *req,
> struct messaging_filtered_read_state *state = tevent_req_data(
> req, struct messaging_filtered_read_state);
> struct messaging_context *msg_ctx = state->msg_ctx;
> - unsigned i;
> + size_t i;
>
> tevent_req_set_cleanup_fn(req, NULL);
>
> @@ -1056,14 +1056,14 @@ static void messaging_dispatch_rec(struct messaging_context *msg_ctx,
> struct tevent_context *ev,
> struct messaging_rec *rec)
> {
> - unsigned i;
> - size_t j;
> + size_t i;
>
> if (ev == msg_ctx->event_ctx) {
> messaging_dispatch_classic(msg_ctx, rec);
> }
>
> if (!messaging_append_new_waiters(msg_ctx)) {
> + size_t j;
> for (j=0; j < rec->num_fds; j++) {
> int fd = rec->fds[j];
> close(fd);
> @@ -1141,8 +1141,8 @@ static void messaging_dispatch_rec(struct messaging_context *msg_ctx,
> /*
> * If the fd-array isn't used, just close it.
> */
> - for (j=0; j < rec->num_fds; j++) {
> - int fd = rec->fds[j];
> + for (i=0; i < rec->num_fds; i++) {
> + int fd = rec->fds[i];
> close(fd);
> }
> rec->num_fds = 0;
> --
> 2.1.4
>
>
> From 3ee869af1f00367290d1b25199d76e84f1062917 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Thu, 1 Jun 2017 19:25:48 +0200
> Subject: [PATCH 2/7] lib: Give messages_ctdbd.c its own header
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> source3/include/messages.h | 8 --------
> source3/lib/ctdb_dummy.c | 1 +
> source3/lib/dbwrap/dbwrap_open.c | 1 +
> source3/lib/messages.c | 1 +
> source3/lib/messages_ctdbd.c | 1 +
> source3/lib/messages_ctdbd.h | 38 ++++++++++++++++++++++++++++++++++++++
> source3/lib/serverid.c | 1 +
> source3/smbd/notifyd/notifyd.h | 1 +
> source3/smbd/notifyd/notifydd.c | 1 +
> source3/smbd/process.c | 1 +
> source3/smbd/server.c | 1 +
> source3/torture/test_dbwrap_ctdb.c | 1 +
> 12 files changed, 48 insertions(+), 8 deletions(-)
> create mode 100644 source3/lib/messages_ctdbd.h
>
> diff --git a/source3/include/messages.h b/source3/include/messages.h
> index ea89383..806f7b0 100644
> --- a/source3/include/messages.h
> +++ b/source3/include/messages.h
> @@ -65,14 +65,6 @@ struct messaging_backend {
> void *private_data;
> };
>
> -int messaging_ctdbd_init(struct messaging_context *msg_ctx,
> - TALLOC_CTX *mem_ctx,
> - struct messaging_backend **presult);
> -int messaging_ctdbd_reinit(struct messaging_context *msg_ctx,
> - TALLOC_CTX *mem_ctx,
> - struct messaging_backend *backend);
> -struct ctdbd_connection *messaging_ctdbd_connection(void);
> -
> struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
> struct tevent_context *ev);
> NTSTATUS messaging_init_client(TALLOC_CTX *mem_ctx,
> diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
> index 0b1acb7..2ed7b10 100644
> --- a/source3/lib/ctdb_dummy.c
> +++ b/source3/lib/ctdb_dummy.c
> @@ -19,6 +19,7 @@
>
> #include "includes.h"
> #include "messages.h"
> +#include "lib/messages_ctdbd.h"
> #include "ctdbd_conn.h"
> #include "lib/dbwrap/dbwrap.h"
> #include "lib/dbwrap/dbwrap_ctdb.h"
> diff --git a/source3/lib/dbwrap/dbwrap_open.c b/source3/lib/dbwrap/dbwrap_open.c
> index feb9f5e..55e0adb 100644
> --- a/source3/lib/dbwrap/dbwrap_open.c
> +++ b/source3/lib/dbwrap/dbwrap_open.c
> @@ -26,6 +26,7 @@
> #include "dbwrap/dbwrap_ctdb.h"
> #include "lib/param/param.h"
> #include "lib/cluster_support.h"
> +#include "lib/messages_ctdbd.h"
> #include "util_tdb.h"
> #include "ctdbd_conn.h"
> #include "messages.h"
> diff --git a/source3/lib/messages.c b/source3/lib/messages.c
> index 83def69..a38f40e 100644
> --- a/source3/lib/messages.c
> +++ b/source3/lib/messages.c
> @@ -53,6 +53,7 @@
> #include "lib/util/tevent_unix.h"
> #include "lib/background.h"
> #include "lib/messages_dgm.h"
> +#include "lib/messages_ctdbd.h"
> #include "lib/util/iov_buf.h"
> #include "lib/util/server_id_db.h"
> #include "lib/messages_dgm_ref.h"
> diff --git a/source3/lib/messages_ctdbd.c b/source3/lib/messages_ctdbd.c
> index a32a80d..6ecec32 100644
> --- a/source3/lib/messages_ctdbd.c
> +++ b/source3/lib/messages_ctdbd.c
> @@ -18,6 +18,7 @@
> */
>
> #include "includes.h"
> +#include "lib/messages_ctdbd.h"
> #include "lib/util/server_id.h"
> #include "messages.h"
> #include "util_tdb.h"
> diff --git a/source3/lib/messages_ctdbd.h b/source3/lib/messages_ctdbd.h
> new file mode 100644
> index 0000000..67ec4b7
> --- /dev/null
> +++ b/source3/lib/messages_ctdbd.h
> @@ -0,0 +1,38 @@
> +/*
> + * Unix SMB/CIFS implementation.
> + * messages_ctdb.c header
> + * Copyright (C) Volker Lendecke 2017
> + *
> + * 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/>.
> + */
> +
> +#ifndef _MESSAGES_CTDB_H_
> +#define _MESSAGES_CTDB_H_
> +
> +#include "replace.h"
> +#include <talloc.h>
> +
> +struct messaging_context;
> +struct messaging_backend;
> +struct ctdbd_connection;
> +
> +int messaging_ctdbd_init(struct messaging_context *msg_ctx,
> + TALLOC_CTX *mem_ctx,
> + struct messaging_backend **presult);
> +int messaging_ctdbd_reinit(struct messaging_context *msg_ctx,
> + TALLOC_CTX *mem_ctx,
> + struct messaging_backend *backend);
> +struct ctdbd_connection *messaging_ctdbd_connection(void);
> +
> +#endif
> diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
> index 7cc8b57..fb32526 100644
> --- a/source3/lib/serverid.c
> +++ b/source3/lib/serverid.c
> @@ -28,6 +28,7 @@
> #include "lib/param/param.h"
> #include "ctdbd_conn.h"
> #include "messages.h"
> +#include "lib/messages_ctdbd.h"
> #include "lib/messages_dgm.h"
>
> struct serverid_key {
> diff --git a/source3/smbd/notifyd/notifyd.h b/source3/smbd/notifyd/notifyd.h
> index 82fdd6e..6904761 100644
> --- a/source3/smbd/notifyd/notifyd.h
> +++ b/source3/smbd/notifyd/notifyd.h
> @@ -121,6 +121,7 @@ struct notify_event_msg {
> };
>
> struct sys_notify_context;
> +struct ctdbd_connection;
>
> typedef int (*sys_notify_watch_fn)(TALLOC_CTX *mem_ctx,
> struct sys_notify_context *ctx,
> diff --git a/source3/smbd/notifyd/notifydd.c b/source3/smbd/notifyd/notifydd.c
> index 6856b3e..ad3621a 100644
> --- a/source3/smbd/notifyd/notifydd.c
> +++ b/source3/smbd/notifyd/notifydd.c
> @@ -19,6 +19,7 @@
>
> #include "replace.h"
> #include "notifyd.h"
> +#include "lib/messages_ctdbd.h"
> #include <tevent.h>
> #include "lib/util/tevent_unix.h"
>
> diff --git a/source3/smbd/process.c b/source3/smbd/process.c
> index d5c03b9..a19b8b7 100644
> --- a/source3/smbd/process.c
> +++ b/source3/smbd/process.c
> @@ -32,6 +32,7 @@
> #include "passdb.h"
> #include "auth.h"
> #include "messages.h"
> +#include "lib/messages_ctdbd.h"
> #include "smbprofile.h"
> #include "rpc_server/spoolss/srv_spoolss_nt.h"
> #include "libsmb/libsmb.h"
> diff --git a/source3/smbd/server.c b/source3/smbd/server.c
> index 4883c4e..fa13dbc 100644
> --- a/source3/smbd/server.c
> +++ b/source3/smbd/server.c
> @@ -40,6 +40,7 @@
> #include "passdb.h"
> #include "auth.h"
> #include "messages.h"
> +#include "messages_ctdbd.h"
> #include "smbprofile.h"
> #include "lib/id_cache.h"
> #include "lib/param/param.h"
> diff --git a/source3/torture/test_dbwrap_ctdb.c b/source3/torture/test_dbwrap_ctdb.c
> index b9bab9e..4512358 100644
> --- a/source3/torture/test_dbwrap_ctdb.c
> +++ b/source3/torture/test_dbwrap_ctdb.c
> @@ -23,6 +23,7 @@
> #include "lib/dbwrap/dbwrap.h"
> #include "lib/dbwrap/dbwrap_ctdb.h"
> #include "messages.h"
> +#include "lib/messages_ctdbd.h"
>
> bool run_local_dbwrap_ctdb(int dummy)
> {
> --
> 2.1.4
>
>
> From 6391e748f99de0d743c677d5d5aa62e7cafb45e9 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Sat, 17 Jun 2017 21:26:27 +0200
> Subject: [PATCH 3/7] tevent: Simplify create_immediate
>
> Not much change, just 9 lines less of code.
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> lib/tevent/tevent.c | 11 +----------
> 1 file changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
> index f3b18a1..5f44b03 100644
> --- a/lib/tevent/tevent.c
> +++ b/lib/tevent/tevent.c
> @@ -616,16 +616,7 @@ struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx,
> im = talloc(mem_ctx, struct tevent_immediate);
> if (im == NULL) return NULL;
>
> - im->prev = NULL;
> - im->next = NULL;
> - im->event_ctx = NULL;
> - im->create_location = location;
> - im->handler = NULL;
> - im->private_data = NULL;
> - im->handler_name = NULL;
> - im->schedule_location = NULL;
> - im->cancel_fn = NULL;
> - im->additional_data = NULL;
> + *im = (struct tevent_immediate) { .create_location = location };
>
> return im;
> }
> --
> 2.1.4
>
>
> From a5bf95204cd83fb1b049bdc8b8c114c85cb902c2 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Thu, 8 Jun 2017 11:44:36 +0200
> Subject: [PATCH 4/7] ctdb: Fix typos
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> ctdb/client/client.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ctdb/client/client.h b/ctdb/client/client.h
> index b7b657c..4a27ce1 100644
> --- a/ctdb/client/client.h
> +++ b/ctdb/client/client.h
> @@ -119,7 +119,7 @@ uint32_t ctdb_client_pnn(struct ctdb_client_context *client);
> /**
> * @brief Client event loop waiting for a flag
> *
> - * This can used to wait for asynchronous comptuations to complete.
> + * This can used to wait for asynchronous computations to complete.
> * When this function is called, it will run tevent event loop and wait
> * till the done flag is set to true. This function will block and will
> * not return as long as the done flag is false.
> @@ -151,7 +151,7 @@ int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done,
> /**
> * @brief Async computation start to wait till recovery is completed
> *
> - * CTDB deamon does not perform many operations while in recovery (specially
> + * CTDB daemon does not perform many operations while in recovery (specially
> * database operations). This computation allows to wait till ctdb daemon has
> * finished recovery.
> *
> --
> 2.1.4
>
>
> From 584e621a8a457592502078523d2df1316b316dae Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Thu, 8 Jun 2017 12:20:15 +0200
> Subject: [PATCH 5/7] lib: Fix typos
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> source3/lib/ctdbd_conn.c | 2 +-
> source3/lib/dbwrap/dbwrap_ctdb.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
> index 048e364..ce41db9 100644
> --- a/source3/lib/ctdbd_conn.c
> +++ b/source3/lib/ctdbd_conn.c
> @@ -60,7 +60,7 @@ struct ctdbd_connection {
> int fd;
> int timeout;
>
> - /* For async connections, enabled via ctdbd_setup_ev() */
> + /* For async connections, enabled via ctdbd_setup_fde() */
> struct tevent_fd *fde;
>
> /* State to track in-progress read */
> diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
> index 7f61dec..3334eca 100644
> --- a/source3/lib/dbwrap/dbwrap_ctdb.c
> +++ b/source3/lib/dbwrap/dbwrap_ctdb.c
> @@ -105,7 +105,7 @@ static int ctdb_async_ctx_init_internal(TALLOC_CTX *mem_ctx,
>
> ret = ctdbd_setup_fde(ctdb_async_ctx.async_conn, ev);
> if (ret != 0) {
> - DBG_ERR("ctdbd_setup_ev failed\n");
> + DBG_ERR("ctdbd_setup_fde failed\n");
> TALLOC_FREE(ctdb_async_ctx.async_conn);
> return ret;
> }
> --
> 2.1.4
>
>
> From c72703d247a89c02cdfb78ffe252d9bd819405df Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Fri, 26 May 2017 18:47:23 +0200
> Subject: [PATCH 6/7] dbwrap: Remove unused dbwrap_cache
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> lib/dbwrap/dbwrap_cache.c | 227 ----------------------------------------------
> lib/dbwrap/dbwrap_cache.h | 28 ------
> lib/dbwrap/wscript_build | 2 +-
> 3 files changed, 1 insertion(+), 256 deletions(-)
> delete mode 100644 lib/dbwrap/dbwrap_cache.c
> delete mode 100644 lib/dbwrap/dbwrap_cache.h
>
> diff --git a/lib/dbwrap/dbwrap_cache.c b/lib/dbwrap/dbwrap_cache.c
> deleted file mode 100644
> index e4cee55..0000000
> --- a/lib/dbwrap/dbwrap_cache.c
> +++ /dev/null
> @@ -1,227 +0,0 @@
> -/*
> - Unix SMB/CIFS implementation.
> - Cache db contents for parse_record based on seqnum
> - Copyright (C) Volker Lendecke 2012
> -
> - 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 "lib/param/loadparm.h"
> -#include "lib/dbwrap/dbwrap_cache.h"
> -#include "lib/dbwrap/dbwrap_private.h"
> -#include "lib/dbwrap/dbwrap_rbt.h"
> -#include "lib/util/talloc_stack.h"
> -
> -struct db_cache_ctx {
> - int seqnum;
> - struct db_context *backing;
> - struct db_context *positive;
> - struct db_context *negative;
> -};
> -
> -static bool dbwrap_cache_validate(struct db_cache_ctx *ctx)
> -{
> - int backing_seqnum;
> -
> - backing_seqnum = dbwrap_get_seqnum(ctx->backing);
> - if (backing_seqnum == ctx->seqnum) {
> - return true;
> - }
> -
> - TALLOC_FREE(ctx->positive);
> - ctx->positive = db_open_rbt(ctx);
> - if (ctx->positive == NULL) {
> - return false;
> - }
> -
> - TALLOC_FREE(ctx->negative);
> - ctx->negative = db_open_rbt(ctx);
> - if (ctx->negative == NULL) {
> - return false;
> - }
> -
> - ctx->seqnum = backing_seqnum;
> - return true;
> -}
> -
> -static NTSTATUS dbwrap_cache_parse_record(
> - struct db_context *db, TDB_DATA key,
> - void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data),
> - void *private_data)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - TDB_DATA value;
> - NTSTATUS status;
> -
> - if (!dbwrap_cache_validate(ctx)) {
> - return NT_STATUS_NO_MEMORY;
> - }
> -
> - if (dbwrap_exists(ctx->negative, key)) {
> - return NT_STATUS_NOT_FOUND;
> - }
> - status = dbwrap_parse_record(ctx->positive, key, parser, private_data);
> - if (NT_STATUS_IS_OK(status)) {
> - return status;
> - }
> -
> - status = dbwrap_fetch(ctx->backing, talloc_tos(), key, &value);
> -
> - if (NT_STATUS_IS_OK(status)) {
> - dbwrap_store(ctx->positive, key, value, 0);
> - parser(key, value, private_data);
> - TALLOC_FREE(value.dptr);
> - return NT_STATUS_OK;
> - }
> -
> - if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
> - char c = '\0';
> - value.dptr = (uint8_t *)&c;
> - value.dsize = sizeof(c);
> - dbwrap_store(ctx->negative, key, value, 0);
> - return NT_STATUS_NOT_FOUND;
> - }
> - return status;
> -}
> -
> -static struct db_record *dbwrap_cache_fetch_locked(
> - struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - return dbwrap_fetch_locked(ctx->backing, mem_ctx, key);
> -}
> -
> -static int dbwrap_cache_traverse(struct db_context *db,
> - int (*f)(struct db_record *rec,
> - void *private_data),
> - void *private_data)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - NTSTATUS status;
> - int ret;
> - status = dbwrap_traverse(ctx->backing, f, private_data, &ret);
> - if (!NT_STATUS_IS_OK(status)) {
> - return -1;
> - }
> - return ret;
> -}
> -
> -static int dbwrap_cache_traverse_read(struct db_context *db,
> - int (*f)(struct db_record *rec,
> - void *private_data),
> - void *private_data)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - NTSTATUS status;
> - int ret;
> - status = dbwrap_traverse_read(ctx->backing, f, private_data, &ret);
> - if (!NT_STATUS_IS_OK(status)) {
> - return -1;
> - }
> - return ret;
> -}
> -
> -static int dbwrap_cache_get_seqnum(struct db_context *db)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - return dbwrap_get_seqnum(ctx->backing);
> -}
> -
> -static int dbwrap_cache_transaction_start(struct db_context *db)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - return dbwrap_transaction_start(ctx->backing);
> -}
> -
> -static int dbwrap_cache_transaction_commit(struct db_context *db)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - return dbwrap_transaction_commit(ctx->backing);
> -}
> -
> -static int dbwrap_cache_transaction_cancel(struct db_context *db)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> - return dbwrap_transaction_cancel(ctx->backing);
> -}
> -
> -static int dbwrap_cache_exists(struct db_context *db, TDB_DATA key)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> -
> - if (ctx->positive && dbwrap_exists(ctx->positive, key)) {
> - return true;
> - }
> - if (ctx->negative && dbwrap_exists(ctx->negative, key)) {
> - return false;
> - }
> - return dbwrap_exists(ctx->backing, key);
> -}
> -
> -static size_t dbwrap_cache_id(struct db_context *db, uint8_t *id,
> - size_t idlen)
> -{
> - struct db_cache_ctx *ctx = talloc_get_type_abort(
> - db->private_data, struct db_cache_ctx);
> -
> - return dbwrap_db_id(ctx->backing, id, idlen);
> -}
> -
> -struct db_context *db_open_cache(TALLOC_CTX *mem_ctx,
> - struct db_context *backing)
> -{
> - struct db_context *db;
> - struct db_cache_ctx *ctx;
> -
> - db = talloc_zero(mem_ctx, struct db_context);
> - if (db == NULL) {
> - return NULL;
> - }
> - ctx = talloc_zero(db, struct db_cache_ctx);
> - if (ctx == NULL) {
> - TALLOC_FREE(db);
> - return NULL;
> - }
> -
> - ctx->seqnum = -1;
> - ctx->backing = talloc_move(ctx, &backing);
> - db->private_data = ctx;
> - if (!dbwrap_cache_validate(ctx)) {
> - TALLOC_FREE(db);
> - return NULL;
> - }
> -
> - db->fetch_locked = dbwrap_cache_fetch_locked;
> - db->traverse = dbwrap_cache_traverse;
> - db->traverse_read = dbwrap_cache_traverse_read;
> - db->get_seqnum = dbwrap_cache_get_seqnum;
> - db->transaction_start = dbwrap_cache_transaction_start;
> - db->transaction_commit = dbwrap_cache_transaction_commit;
> - db->transaction_cancel = dbwrap_cache_transaction_cancel;
> - db->parse_record = dbwrap_cache_parse_record;
> - db->exists = dbwrap_cache_exists;
> - db->id = dbwrap_cache_id;
> - db->name = dbwrap_name(ctx->backing);
> - return db;
> -}
> diff --git a/lib/dbwrap/dbwrap_cache.h b/lib/dbwrap/dbwrap_cache.h
> deleted file mode 100644
> index e69d58e..0000000
> --- a/lib/dbwrap/dbwrap_cache.h
> +++ /dev/null
> @@ -1,28 +0,0 @@
> -/*
> - Unix SMB/CIFS implementation.
> - Database interface wrapper around ctdbd
> - Copyright (C) Volker Lendecke 2012
> -
> - 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/>.
> -*/
> -
> -#ifndef __DBWRAP_CACHE_H__
> -#define __DBWRAP_CACHE_H__
> -
> -#include "dbwrap.h"
> -
> -struct db_context *db_open_cache(TALLOC_CTX *mem_ctx,
> - struct db_context *backing);
> -
> -#endif /* __DBWRAP_CACHE_H__ */
> diff --git a/lib/dbwrap/wscript_build b/lib/dbwrap/wscript_build
> index 83e5895..e6e9d5e 100644
> --- a/lib/dbwrap/wscript_build
> +++ b/lib/dbwrap/wscript_build
> @@ -1,4 +1,4 @@
> -SRC = '''dbwrap.c dbwrap_util.c dbwrap_rbt.c dbwrap_cache.c dbwrap_tdb.c
> +SRC = '''dbwrap.c dbwrap_util.c dbwrap_rbt.c dbwrap_tdb.c
> dbwrap_local_open.c'''
> DEPS= '''samba-util util_tdb samba-errors tdb tdb-wrap samba-hostconfig tevent tevent-util'''
>
> --
> 2.1.4
>
>
> From 5fb968df7797eb8c6daab37fe91c92bc93765b54 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Fri, 26 May 2017 18:48:32 +0200
> Subject: [PATCH 7/7] dbwrap: Remove unused dbwrap_file
>
> This has stopped working ages ago. The idea is clear, but if someone
> wants to revive it, I think it needs a completely fresh start.
>
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
> lib/dbwrap/dbwrap_file.c | 423 -----------------------------------------------
> lib/dbwrap/dbwrap_file.h | 33 ----
> 2 files changed, 456 deletions(-)
> delete mode 100644 lib/dbwrap/dbwrap_file.c
> delete mode 100644 lib/dbwrap/dbwrap_file.h
>
> diff --git a/lib/dbwrap/dbwrap_file.c b/lib/dbwrap/dbwrap_file.c
> deleted file mode 100644
> index 46e62c8..0000000
> --- a/lib/dbwrap/dbwrap_file.c
> +++ /dev/null
> @@ -1,423 +0,0 @@
> -/*
> - Unix SMB/CIFS implementation.
> - Database interface using a file per record
> - Copyright (C) Volker Lendecke 2005
> -
> - 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 "dbwrap/dbwrap.h"
> -#include "dbwrap/dbwrap_file.h"
> -#include "dbwrap/dbwrap_private.h"
> -#include "lib/tdb_wrap/tdb_wrap.h"
> -
> -struct db_file_ctx {
> - const char *dirname;
> -
> - /* We only support one locked record at a time -- everything else
> - * would lead to a potential deadlock anyway! */
> - struct db_record *locked_record;
> -};
> -
> -struct db_locked_file {
> - int fd;
> - uint8_t hash;
> - const char *name;
> - const char *path;
> - struct db_file_ctx *parent;
> -};
> -
> -/* Copy from statcache.c... */
> -
> -static uint32_t fsh(const uint8_t *p, int len)
> -{
> - uint32_t n = 0;
> - int i;
> - for (i=0; i<len; i++) {
> - n = ((n << 5) + n) ^ (uint32_t)(p[i]);
> - }
> - return n;
> -}
> -
> -static int db_locked_file_destr(struct db_locked_file *data)
> -{
> - if (data->parent != NULL) {
> - data->parent->locked_record = NULL;
> - }
> -
> - if (close(data->fd) != 0) {
> - DEBUG(3, ("close failed: %s\n", strerror(errno)));
> - return -1;
> - }
> -
> - return 0;
> -}
> -
> -static NTSTATUS db_file_store(struct db_record *rec, TDB_DATA data, int flag);
> -static NTSTATUS db_file_delete(struct db_record *rec);
> -
> -static struct db_record *db_file_fetch_locked(struct db_context *db,
> - TALLOC_CTX *mem_ctx,
> - TDB_DATA key)
> -{
> - struct db_file_ctx *ctx = talloc_get_type_abort(db->private_data,
> - struct db_file_ctx);
> - struct db_record *result;
> - struct db_locked_file *file;
> - struct flock fl;
> - SMB_STRUCT_STAT statbuf;
> - int ret;
> -
> - SMB_ASSERT(ctx->locked_record == NULL);
> -
> - again:
> - if (!(result = talloc(mem_ctx, struct db_record))) {
> - DEBUG(0, ("talloc failed\n"));
> - return NULL;
> - }
> -
> - if (!(file = talloc(result, struct db_locked_file))) {
> - DEBUG(0, ("talloc failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - result->private_data = file;
> - result->store = db_file_store;
> - result->delete_rec = db_file_delete;
> -
> - result->key.dsize = key.dsize;
> - result->key.dptr = (uint8_t *)talloc_memdup(result, key.dptr,
> - key.dsize);
> - if (result->key.dptr == NULL) {
> - DEBUG(0, ("talloc failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - /* Cut to 8 bits */
> - file->hash = fsh(key.dptr, key.dsize);
> - file->name = hex_encode_talloc(file, (unsigned char *)key.dptr, key.dsize);
> - if (file->name == NULL) {
> - DEBUG(0, ("hex_encode failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - file->path = talloc_asprintf(file, "%s/%2.2X/%s", ctx->dirname,
> - file->hash, file->name);
> - if (file->path == NULL) {
> - DEBUG(0, ("talloc_asprintf failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - become_root();
> - file->fd = open(file->path, O_RDWR|O_CREAT, 0644);
> - unbecome_root();
> -
> - if (file->fd < 0) {
> - DEBUG(3, ("Could not open/create %s: %s\n",
> - file->path, strerror(errno)));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - talloc_set_destructor(file, db_locked_file_destr);
> -
> - fl.l_type = F_WRLCK;
> - fl.l_whence = SEEK_SET;
> - fl.l_start = 0;
> - fl.l_len = 1;
> - fl.l_pid = 0;
> -
> - do {
> - ret = fcntl(file->fd, F_SETLKW, &fl);
> - } while ((ret == -1) && (errno == EINTR));
> -
> - if (ret == -1) {
> - DEBUG(3, ("Could not get lock on %s: %s\n",
> - file->path, strerror(errno)));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - if (sys_fstat(file->fd, &statbuf, false) != 0) {
> - DEBUG(3, ("Could not fstat %s: %s\n",
> - file->path, strerror(errno)));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - if (statbuf.st_ex_nlink == 0) {
> - /* Someone has deleted it under the lock, retry */
> - TALLOC_FREE(result);
> - goto again;
> - }
> -
> - result->value.dsize = 0;
> - result->value.dptr = NULL;
> -
> - if (statbuf.st_ex_size != 0) {
> - ssize_t read_bytes;
> -
> - result->value.dsize = statbuf.st_ex_size;
> - result->value.dptr = talloc_array(result, uint8_t,
> - statbuf.st_ex_size);
> - if (result->value.dptr == NULL) {
> - DEBUG(1, ("talloc failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - read_bytes = read_data(file->fd, (char *)result->value.dptr,
> - result->value.dsize);
> - if (read_bytes != result->value.dsize) {
> - DEBUG(3, ("read_data failed: %s\n", strerror(errno)));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> - }
> -
> - ctx->locked_record = result;
> - file->parent = (struct db_file_ctx *)talloc_reference(file, ctx);
> -
> - return result;
> -}
> -
> -static NTSTATUS db_file_store_root(int fd, TDB_DATA data)
> -{
> - if (lseek(fd, 0, SEEK_SET) != 0) {
> - DEBUG(0, ("lseek failed: %s\n", strerror(errno)));
> - return map_nt_error_from_unix(errno);
> - }
> -
> - if (write_data(fd, (char *)data.dptr, data.dsize) != data.dsize) {
> - DEBUG(3, ("write_data failed: %s\n", strerror(errno)));
> - return map_nt_error_from_unix(errno);
> - }
> -
> - if (ftruncate(fd, data.dsize) != 0) {
> - DEBUG(3, ("ftruncate failed: %s\n", strerror(errno)));
> - return map_nt_error_from_unix(errno);
> - }
> -
> - return NT_STATUS_OK;
> -}
> -
> -static NTSTATUS db_file_store(struct db_record *rec, TDB_DATA data, int flag)
> -{
> - struct db_locked_file *file =
> - talloc_get_type_abort(rec->private_data,
> - struct db_locked_file);
> - NTSTATUS status;
> -
> - become_root();
> - status = db_file_store_root(file->fd, data);
> - unbecome_root();
> -
> - return status;
> -}
> -
> -static NTSTATUS db_file_delete(struct db_record *rec)
> -{
> - struct db_locked_file *file =
> - talloc_get_type_abort(rec->private_data,
> - struct db_locked_file);
> - int res;
> -
> - become_root();
> - res = unlink(file->path);
> - unbecome_root();
> -
> - if (res == -1) {
> - DEBUG(3, ("unlink(%s) failed: %s\n", file->path,
> - strerror(errno)));
> - return map_nt_error_from_unix(errno);
> - }
> -
> - return NT_STATUS_OK;
> -}
> -
> -static int db_file_traverse(struct db_context *db,
> - int (*fn)(struct db_record *rec,
> - void *private_data),
> - void *private_data)
> -{
> - struct db_file_ctx *ctx = talloc_get_type_abort(db->private_data,
> - struct db_file_ctx);
> - TALLOC_CTX *mem_ctx = talloc_init("traversal %s\n", ctx->dirname);
> -
> - int i;
> - int count = 0;
> -
> - for (i=0; i<256; i++) {
> - const char *dirname = talloc_asprintf(mem_ctx, "%s/%2.2X",
> - ctx->dirname, i);
> - DIR *dir;
> - struct dirent *dirent;
> -
> - if (dirname == NULL) {
> - DEBUG(0, ("talloc failed\n"));
> - TALLOC_FREE(mem_ctx);
> - return -1;
> - }
> -
> - dir = opendir(dirname);
> - if (dir == NULL) {
> - DEBUG(3, ("Could not open dir %s: %s\n", dirname,
> - strerror(errno)));
> - TALLOC_FREE(mem_ctx);
> - return -1;
> - }
> -
> - while ((dirent = readdir(dir)) != NULL) {
> - DATA_BLOB keyblob;
> - TDB_DATA key;
> - struct db_record *rec;
> -
> - if ((dirent->d_name[0] == '.') &&
> - ((dirent->d_name[1] == '\0') ||
> - ((dirent->d_name[1] == '.') &&
> - (dirent->d_name[2] == '\0')))) {
> - continue;
> - }
> -
> - keyblob = strhex_to_data_blob(mem_ctx, dirent->d_name);
> - if (keyblob.data == NULL) {
> - DEBUG(5, ("strhex_to_data_blob failed\n"));
> - continue;
> - }
> -
> - key.dptr = keyblob.data;
> - key.dsize = keyblob.length;
> -
> - if ((ctx->locked_record != NULL) &&
> - (key.dsize == ctx->locked_record->key.dsize) &&
> - (memcmp(key.dptr, ctx->locked_record->key.dptr,
> - key.dsize) == 0)) {
> - count += 1;
> - if (fn(ctx->locked_record,
> - private_data) != 0) {
> - TALLOC_FREE(mem_ctx);
> - closedir(dir);
> - return count;
> - }
> - }
> -
> - rec = db_file_fetch_locked(db, mem_ctx, key);
> - if (rec == NULL) {
> - /* Someone might have deleted it */
> - continue;
> - }
> -
> - if (rec->value.dptr == NULL) {
> - TALLOC_FREE(rec);
> - continue;
> - }
> -
> - count += 1;
> -
> - if (fn(rec, private_data) != 0) {
> - TALLOC_FREE(mem_ctx);
> - closedir(dir);
> - return count;
> - }
> - TALLOC_FREE(rec);
> - }
> -
> - closedir(dir);
> - }
> -
> - TALLOC_FREE(mem_ctx);
> - return count;
> -}
> -
> -struct db_context *db_open_file(TALLOC_CTX *mem_ctx,
> - const char *name,
> - int tdb_flags,
> - int open_flags, mode_t mode)
> -{
> - struct db_context *result = NULL;
> - struct db_file_ctx *ctx;
> -
> - if (!(result = talloc_zero(mem_ctx, struct db_context))) {
> - DEBUG(0, ("talloc failed\n"));
> - return NULL;
> - }
> -
> - if (!(ctx = talloc(result, struct db_file_ctx))) {
> - DEBUG(0, ("talloc failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - result->private_data = ctx;
> - result->fetch_locked = db_file_fetch_locked;
> - result->try_fetch_locked = NULL;
> - result->traverse = db_file_traverse;
> - result->traverse_read = db_file_traverse;
> - result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
> - result->hash_size = 0;
> - result->name = talloc_strdup(result, name);
> - if (result->name == NULL) {
> - DEBUG(0, ("talloc failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - ctx->locked_record = NULL;
> - if (!(ctx->dirname = talloc_strdup(ctx, name))) {
> - DEBUG(0, ("talloc failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - if (open_flags & O_CREAT) {
> - int ret, i;
> -
> - mode |= (mode & S_IRUSR) ? S_IXUSR : 0;
> - mode |= (mode & S_IRGRP) ? S_IXGRP : 0;
> - mode |= (mode & S_IROTH) ? S_IXOTH : 0;
> -
> - ret = mkdir(name, mode);
> - if ((ret != 0) && (errno != EEXIST)) {
> - DEBUG(5, ("mkdir(%s,%o) failed: %s\n", name, mode,
> - strerror(errno)));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> -
> - for (i=0; i<256; i++) {
> - char *path;
> - path = talloc_asprintf(result, "%s/%2.2X", name, i);
> - if (path == NULL) {
> - DEBUG(0, ("asprintf failed\n"));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> - ret = mkdir(path, mode);
> - if ((ret != 0) && (errno != EEXIST)) {
> - DEBUG(5, ("mkdir(%s,%o) failed: %s\n", path,
> - mode, strerror(errno)));
> - TALLOC_FREE(result);
> - return NULL;
> - }
> - TALLOC_FREE(path);
> - }
> - }
> -
> - return result;
> -}
> diff --git a/lib/dbwrap/dbwrap_file.h b/lib/dbwrap/dbwrap_file.h
> deleted file mode 100644
> index 1766703..0000000
> --- a/lib/dbwrap/dbwrap_file.h
> +++ /dev/null
> @@ -1,33 +0,0 @@
> -/*
> - Unix SMB/CIFS implementation.
> - Database interface using a file per record
> - Copyright (C) Volker Lendecke 2005
> -
> - 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/>.
> -*/
> -
> -#ifndef __DBWRAP_FILE_H__
> -#define __DBWRAP_FILE_H__
> -
> -#include <talloc.h>
> -
> -struct db_context;
> -
> -struct db_context *db_open_file(TALLOC_CTX *mem_ctx,
> - const char *name,
> - int tdb_flags,
> - int open_flags, mode_t mode);
> -
> -
> -#endif /* __DBWRAP_FILE_H__ */
> --
> 2.1.4
>
More information about the samba-technical
mailing list