r12230: prepare for a generic periodic processing scheduling of
authorStefan Metzmacher <metze@samba.org>
Wed, 14 Dec 2005 10:56:43 +0000 (10:56 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:47:22 +0000 (13:47 -0500)
pull,push,scavenging and reread-config events

metze

source/wrepl_server/config.mk
source/wrepl_server/wrepl_periodic.c [new file with mode: 0644]
source/wrepl_server/wrepl_server.c
source/wrepl_server/wrepl_server.h

index cc4621ba4509201b63fe19007f9b77f8c03aa1dc..6a6ce7185aaf1233355fa1d01767d10264d730c5 100644 (file)
@@ -9,7 +9,8 @@ INIT_OBJ_FILES = \
                wrepl_in_call.o \
                wrepl_out_connection.o \
                wrepl_out_helpers.o \
-               wrepl_apply_records.o
+               wrepl_apply_records.o \
+               wrepl_periodic.o
 REQUIRED_SUBSYSTEMS = \
                LIBCLI_WREPL WINSDB
 # End SUBSYSTEM WREPL_SRV
diff --git a/source/wrepl_server/wrepl_periodic.c b/source/wrepl_server/wrepl_periodic.c
new file mode 100644 (file)
index 0000000..4ba047d
--- /dev/null
@@ -0,0 +1,82 @@
+/* 
+   Unix SMB/CIFS implementation.
+   
+   WINS Replication server
+   
+   Copyright (C) Stefan Metzmacher     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 2 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, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "dlinklist.h"
+#include "lib/events/events.h"
+#include "lib/socket/socket.h"
+#include "smbd/service_task.h"
+#include "smbd/service_stream.h"
+#include "lib/messaging/irpc.h"
+#include "librpc/gen_ndr/ndr_winsrepl.h"
+#include "wrepl_server/wrepl_server.h"
+#include "nbt_server/wins/winsdb.h"
+#include "ldb/include/ldb.h"
+#include "libcli/composite/composite.h"
+#include "libcli/wrepl/winsrepl.h"
+#include "wrepl_server/wrepl_out_helpers.h"
+
+static uint32_t wreplsrv_periodic_run(struct wreplsrv_service *service, uint32_t next_interval)
+{
+       DEBUG(2,("wreplsrv_periodic_run: next in %u secs\n", next_interval));
+       return next_interval;
+}
+
+static void wreplsrv_periodic_handler_te(struct event_context *ev, struct timed_event *te,
+                                        struct timeval t, void *ptr)
+{
+       struct wreplsrv_service *service = talloc_get_type(ptr, struct wreplsrv_service);
+       uint32_t next_interval;
+
+       service->periodic.te = NULL;
+
+       next_interval = wreplsrv_periodic_run(service, service->config.periodic_interval);
+
+       service->periodic.next_event = timeval_current_ofs(next_interval, 0);
+       service->periodic.te = event_add_timed(service->task->event_ctx, service,
+                                              service->periodic.next_event,
+                                              wreplsrv_periodic_handler_te, service);
+       if (!service->periodic.te) {
+               task_server_terminate(service->task,"event_add_timed() failed! no memory!\n");
+               return;
+       }
+}
+
+NTSTATUS wreplsrv_setup_periodic(struct wreplsrv_service *service)
+{
+       NTSTATUS status;
+
+       /*
+        * TODO: this should go away, and we should do everything
+        *        within the wreplsrv_periodic_run()
+        */
+       status = wreplsrv_setup_out_connections(service);
+       NT_STATUS_NOT_OK_RETURN(status);
+
+       service->periodic.next_event = timeval_current();
+       service->periodic.te = event_add_timed(service->task->event_ctx, service,
+                                              service->periodic.next_event,
+                                              wreplsrv_periodic_handler_te, service);
+       NT_STATUS_HAVE_NO_MEMORY(service->periodic.te);
+
+       return NT_STATUS_OK;
+}
index effd547260cfb894dd32d114271d3facf9b7d327..5a7ad57f8678a537b76cd58c2040925c6c65b968 100644 (file)
@@ -55,6 +55,9 @@ static NTSTATUS wreplsrv_open_winsdb(struct wreplsrv_service *service)
        /* the default verify interval is 24 days */
        service->config.verify_interval   = lp_parm_int(-1,"wreplsrv","verify_interval", 24*24*60*60);
 
+       /* the maximun interval to the next periodic processing event */
+       service->config.periodic_interval = lp_parm_int(-1,"wreplsrv","periodic_interval", 60);
+
        return NT_STATUS_OK;
 }
 
@@ -333,9 +336,6 @@ static NTSTATUS wreplsrv_setup_partners(struct wreplsrv_service *service)
        status = wreplsrv_load_table(service);
        NT_STATUS_NOT_OK_RETURN(status);
 
-       status = wreplsrv_setup_out_connections(service);
-       NT_STATUS_NOT_OK_RETURN(status);
-
        return NT_STATUS_OK;
 }
 
@@ -383,6 +383,12 @@ static void wreplsrv_task_init(struct task_server *task)
                return;
        }
 
+       status = wreplsrv_setup_periodic(service);
+       if (!NT_STATUS_IS_OK(status)) {
+               task_server_terminate(task, "wreplsrv_task_init: wreplsrv_setup_periodic() failed");
+               return;
+       }
+
        irpc_add_name(task->msg_ctx, "wrepl_server");
 }
 
index 118686622ec69506f801f7bbf132d37dfbb56603..0e0ed35e946335511dca35f60873496814826f2c 100644 (file)
@@ -232,6 +232,12 @@ struct wreplsrv_service {
                 * with the owning wins server
                 */
                uint32_t verify_interval;
+
+               /* 
+                * the interval (in secs) to the next periodic processing
+                * (this is the maximun interval)
+                */
+               uint32_t periodic_interval;
        } config;
 
        /* all incoming connections */
@@ -242,4 +248,16 @@ struct wreplsrv_service {
 
        /* this is a list of each wins_owner we know about in our database */
        struct wreplsrv_owner *table;
+
+       /* some stuff for periodic processing */
+       struct {
+               /*
+                * the timestamp for the current or next event,
+                * this is the timstamp passed to event_add_timed()
+                */
+               struct timeval next_event;
+
+               /* here we have a reference to the timed event the schedules the periodic stuff */
+               struct timed_event *te;
+       } periodic;
 };