[SCM] Samba Shared Repository - branch master updated - tevent-0-9-8-283-g55a9ea2
Andrew Tridgell
tridge at samba.org
Sun Sep 13 17:42:04 MDT 2009
The branch, master has been updated
via 55a9ea2b33cbcd39ae44972b71922c9c87748d75 (commit)
via 348efd5cbb2e7880671cbc75d01b92c4c9008d9e (commit)
via 02c9a7e4b634e5c971ac86031799df6421d02164 (commit)
via 424d1c580a68d8464411de755a07fcadcd882677 (commit)
via 80c575923f40def2770b7ed2b95f458c605c6ece (commit)
via 73e380deec5a5ddcb71401d657fce3ba96ad32e7 (commit)
from c3da2056ec5ef41699453022e3cb762c5f0115e8 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 55a9ea2b33cbcd39ae44972b71922c9c87748d75
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Sep 13 18:16:13 2009 +1000
s4-repl: added a preiodic notification check to the repl task
The dreplsrv_notify code checks the partition uSN values every N
seconds, and if one has changed then it sends a DsReplicaSync to all
the replication partners listed in the repsTo attribute for the
partition.
commit 348efd5cbb2e7880671cbc75d01b92c4c9008d9e
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Sep 13 18:14:35 2009 +1000
s4-drs: fixed search expression
At least on the command line the braces are needed. Strange.
commit 02c9a7e4b634e5c971ac86031799df6421d02164
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Sep 13 18:13:56 2009 +1000
s4-repl: use the new dsdb partition uSN helper fns
commit 424d1c580a68d8464411de755a07fcadcd882677
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Sep 13 18:13:17 2009 +1000
s4-dsdb: added dsdb_load_partition_usn and dsdb_save_partition_usn
These are used to load/save the per-partition uSN values managed by
the repl_meta_data module
commit 80c575923f40def2770b7ed2b95f458c605c6ece
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Sep 13 18:12:05 2009 +1000
s4-sam: allow a search to specify a partition
You can now attach a partition control to searches to search within a
specific partition. This is used to get at the per-partition
@REPLCHANGED object
commit 73e380deec5a5ddcb71401d657fce3ba96ad32e7
Author: Andrew Tridgell <tridge at samba.org>
Date: Sun Sep 13 14:24:08 2009 +1000
s4-repl: keep a @REPLCHANGED object on each partition
This object tracks the highest uSN in each partition. It will be used
to allow us to efficiently detect changes in a partition for sending
DsReplicaSync messages to our replication partners.
-----------------------------------------------------------------------
Summary of changes:
source4/dsdb/common/util.c | 146 ++++++++
source4/dsdb/config.mk | 3 +-
source4/dsdb/repl/drepl_notify.c | 426 +++++++++++++++++++++++
source4/dsdb/repl/drepl_out_helpers.c | 4 +-
source4/dsdb/repl/drepl_out_pull.c | 3 +-
source4/dsdb/repl/drepl_periodic.c | 1 +
source4/dsdb/repl/drepl_service.c | 10 +
source4/dsdb/repl/drepl_service.h | 37 ++
source4/dsdb/samdb/ldb_modules/partition.c | 19 +-
source4/dsdb/samdb/ldb_modules/repl_meta_data.c | 272 +++++++++++++--
source4/rpc_server/drsuapi/getncchanges.c | 2 +-
11 files changed, 892 insertions(+), 31 deletions(-)
create mode 100644 source4/dsdb/repl/drepl_notify.c
Changeset truncated at 500 lines:
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index b500544..c2636e1 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -2257,3 +2257,149 @@ failed:
}
+/*
+ load the uSNHighest attribute from the @REPLCHANGED object for a
+ partition
+ */
+int dsdb_load_partition_usn(struct ldb_context *ldb, struct ldb_dn *dn, uint64_t *uSN)
+{
+ struct ldb_request *req;
+ int ret;
+ TALLOC_CTX *tmp_ctx = talloc_new(ldb);
+ struct dsdb_control_current_partition *p_ctrl;
+ struct ldb_result *res;
+
+ res = talloc_zero(tmp_ctx, struct ldb_result);
+ if (!res) {
+ talloc_free(tmp_ctx);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ret = ldb_build_search_req(&req, ldb, tmp_ctx,
+ ldb_dn_new(tmp_ctx, ldb, "@REPLCHANGED"),
+ LDB_SCOPE_BASE,
+ NULL, NULL,
+ NULL,
+ res, ldb_search_default_callback,
+ NULL);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }
+
+ p_ctrl = talloc(req, struct dsdb_control_current_partition);
+ if (p_ctrl == NULL) {
+ talloc_free(res);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ p_ctrl->version = DSDB_CONTROL_CURRENT_PARTITION_VERSION;
+ p_ctrl->dn = dn;
+
+
+ ret = ldb_request_add_control(req,
+ DSDB_CONTROL_CURRENT_PARTITION_OID,
+ false, p_ctrl);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }
+
+ /* Run the new request */
+ ret = ldb_request(ldb, req);
+
+ if (ret == LDB_SUCCESS) {
+ ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+ }
+
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }
+
+ if (res->count < 1) {
+ *uSN = 0;
+ } else {
+ *uSN = ldb_msg_find_attr_as_uint64(res->msgs[0], "uSNHighest", 0);
+ }
+
+ talloc_free(tmp_ctx);
+
+ return LDB_SUCCESS;
+}
+
+/*
+ save the uSNHighest attribute in the @REPLCHANGED object for a
+ partition
+ */
+int dsdb_save_partition_usn(struct ldb_context *ldb, struct ldb_dn *dn, uint64_t uSN)
+{
+ struct ldb_request *req;
+ struct ldb_message *msg;
+ struct dsdb_control_current_partition *p_ctrl;
+ int ret;
+
+ msg = ldb_msg_new(ldb);
+ if (msg == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ msg->dn = ldb_dn_new(msg, ldb, "@REPLCHANGED");
+ if (msg->dn == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ret = ldb_msg_add_fmt(msg, "uSNHighest", "%llu", (unsigned long long)uSN);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(msg);
+ return ret;
+ }
+ msg->elements[0].flags = LDB_FLAG_MOD_REPLACE;
+
+
+ p_ctrl = talloc(msg, struct dsdb_control_current_partition);
+ if (p_ctrl == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ p_ctrl->version = DSDB_CONTROL_CURRENT_PARTITION_VERSION;
+ p_ctrl->dn = dn;
+
+ ret = ldb_build_mod_req(&req, ldb, msg,
+ msg,
+ NULL,
+ NULL, ldb_op_default_callback,
+ NULL);
+again:
+ if (ret != LDB_SUCCESS) {
+ talloc_free(msg);
+ return ret;
+ }
+
+ ret = ldb_request_add_control(req,
+ DSDB_CONTROL_CURRENT_PARTITION_OID,
+ false, p_ctrl);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(msg);
+ return ret;
+ }
+
+ /* Run the new request */
+ ret = ldb_request(ldb, req);
+
+ if (ret == LDB_SUCCESS) {
+ ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+ }
+ if (ret == LDB_ERR_NO_SUCH_OBJECT) {
+ ret = ldb_build_add_req(&req, ldb, msg,
+ msg,
+ NULL,
+ NULL, ldb_op_default_callback,
+ NULL);
+ goto again;
+ }
+
+ talloc_free(msg);
+
+ return ret;
+}
diff --git a/source4/dsdb/config.mk b/source4/dsdb/config.mk
index eb26f5b..4150ba0 100644
--- a/source4/dsdb/config.mk
+++ b/source4/dsdb/config.mk
@@ -62,7 +62,8 @@ DREPL_SRV_OBJ_FILES = $(addprefix $(dsdbsrcdir)/repl/, \
drepl_periodic.o \
drepl_partitions.o \
drepl_out_pull.o \
- drepl_out_helpers.o)
+ drepl_out_helpers.o \
+ drepl_notify.o)
$(eval $(call proto_header_template,$(dsdbsrcdir)/repl/drepl_service_proto.h,$(DREPL_SRV_OBJ_FILES:.o=.c)))
diff --git a/source4/dsdb/repl/drepl_notify.c b/source4/dsdb/repl/drepl_notify.c
new file mode 100644
index 0000000..83c6df4
--- /dev/null
+++ b/source4/dsdb/repl/drepl_notify.c
@@ -0,0 +1,426 @@
+/*
+ Unix SMB/CIFS mplementation.
+
+ DSDB replication service periodic notification handling
+
+ Copyright (C) Andrew Tridgell 2009
+ based on drepl_periodic
+
+ 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 "lib/events/events.h"
+#include "dsdb/samdb/samdb.h"
+#include "auth/auth.h"
+#include "smbd/service.h"
+#include "lib/messaging/irpc.h"
+#include "dsdb/repl/drepl_service.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "../lib/util/dlinklist.h"
+#include "librpc/gen_ndr/ndr_misc.h"
+#include "librpc/gen_ndr/ndr_drsuapi.h"
+#include "librpc/gen_ndr/ndr_drsblobs.h"
+#include "libcli/composite/composite.h"
+
+
+struct dreplsrv_op_notify_state {
+ struct composite_context *creq;
+
+ struct dreplsrv_out_connection *conn;
+
+ struct dreplsrv_drsuapi_connection *drsuapi;
+
+ struct drsuapi_DsBindInfoCtr bind_info_ctr;
+ struct drsuapi_DsBind bind_r;
+ struct dreplsrv_notify_operation *op;
+};
+
+/*
+ receive a DsReplicaSync reply
+ */
+static void dreplsrv_op_notify_replica_sync_recv(struct rpc_request *req)
+{
+ struct dreplsrv_op_notify_state *st = talloc_get_type(req->async.private_data,
+ struct dreplsrv_op_notify_state);
+ struct composite_context *c = st->creq;
+ struct drsuapi_DsReplicaSync *r = talloc_get_type(req->ndr.struct_ptr,
+ struct drsuapi_DsReplicaSync);
+
+ c->status = dcerpc_ndr_request_recv(req);
+ if (!composite_is_ok(c)) return;
+
+ if (!W_ERROR_IS_OK(r->out.result)) {
+ composite_error(c, werror_to_ntstatus(r->out.result));
+ return;
+ }
+
+ composite_done(c);
+}
+
+/*
+ send a DsReplicaSync
+*/
+static void dreplsrv_op_notify_replica_sync_send(struct dreplsrv_op_notify_state *st)
+{
+ struct composite_context *c = st->creq;
+ struct dreplsrv_partition *partition = st->op->source_dsa->partition;
+ struct dreplsrv_drsuapi_connection *drsuapi = st->op->source_dsa->conn->drsuapi;
+ struct rpc_request *req;
+ struct drsuapi_DsReplicaSync *r;
+
+ r = talloc_zero(st, struct drsuapi_DsReplicaSync);
+ if (composite_nomem(r, c)) return;
+
+ r->in.bind_handle = &drsuapi->bind_handle;
+ r->in.level = 1;
+ r->in.req.req1.naming_context = &partition->nc;
+ r->in.req.req1.source_dsa_guid = st->op->service->ntds_guid;
+ r->in.req.req1.options =
+ DRSUAPI_DS_REPLICA_SYNC_ASYNCHRONOUS_OPERATION |
+ DRSUAPI_DS_REPLICA_SYNC_WRITEABLE |
+ DRSUAPI_DS_REPLICA_SYNC_ALL_SOURCES;
+
+
+ req = dcerpc_drsuapi_DsReplicaSync_send(drsuapi->pipe, r, r);
+ composite_continue_rpc(c, req, dreplsrv_op_notify_replica_sync_recv, st);
+}
+
+/*
+ called when we have an established connection
+ */
+static void dreplsrv_op_notify_connect_recv(struct composite_context *creq)
+{
+ struct dreplsrv_op_notify_state *st = talloc_get_type(creq->async.private_data,
+ struct dreplsrv_op_notify_state);
+ struct composite_context *c = st->creq;
+
+ c->status = dreplsrv_out_drsuapi_recv(creq);
+ if (!composite_is_ok(c)) return;
+
+ dreplsrv_op_notify_replica_sync_send(st);
+}
+
+/*
+ start the ReplicaSync async call
+ */
+static struct composite_context *dreplsrv_op_notify_send(struct dreplsrv_notify_operation *op)
+{
+ struct composite_context *c;
+ struct composite_context *creq;
+ struct dreplsrv_op_notify_state *st;
+
+ c = composite_create(op, op->service->task->event_ctx);
+ if (c == NULL) return NULL;
+
+ st = talloc_zero(c, struct dreplsrv_op_notify_state);
+ if (composite_nomem(st, c)) return c;
+
+ st->creq = c;
+ st->op = op;
+
+ creq = dreplsrv_out_drsuapi_send(op->source_dsa->conn);
+ composite_continue(c, creq, dreplsrv_op_notify_connect_recv, st);
+
+ return c;
+}
+
+static void dreplsrv_notify_del_repsTo(struct dreplsrv_notify_operation *op)
+{
+ uint32_t count;
+ struct repsFromToBlob *reps;
+ WERROR werr;
+ struct dreplsrv_service *s = op->service;
+ int i;
+
+ werr = dsdb_loadreps(s->samdb, op, op->source_dsa->partition->dn, "repsTo", &reps, &count);
+ if (!W_ERROR_IS_OK(werr)) {
+ DEBUG(0,(__location__ ": Failed to load repsTo for %s\n",
+ ldb_dn_get_linearized(op->source_dsa->partition->dn)));
+ return;
+ }
+
+ for (i=0; i<count; i++) {
+ if (GUID_compare(&reps[i].ctr.ctr1.source_dsa_obj_guid,
+ &op->source_dsa->repsFrom1->source_dsa_obj_guid) == 0) {
+ memmove(&reps[i], &reps[i+1],
+ sizeof(reps[i])*(count-(i+1)));
+ count--;
+ }
+ }
+
+ werr = dsdb_savereps(s->samdb, op, op->source_dsa->partition->dn, "repsTo", reps, count);
+ if (!W_ERROR_IS_OK(werr)) {
+ DEBUG(0,(__location__ ": Failed to save repsTo for %s\n",
+ ldb_dn_get_linearized(op->source_dsa->partition->dn)));
+ return;
+ }
+}
+
+/*
+ called when a notify operation has completed
+ */
+static void dreplsrv_notify_op_callback(struct dreplsrv_notify_operation *op)
+{
+ NTSTATUS status;
+ struct dreplsrv_service *s = op->service;
+
+ status = composite_wait(op->creq);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("dreplsrv_notify: Failed to send DsReplicaSync to %s - %s\n",
+ op->source_dsa->repsFrom1->other_info->dns_name,
+ nt_errstr(status)));
+ } else {
+ DEBUG(2,("dreplsrv_notify: DsReplicaSync OK for %s\n",
+ op->source_dsa->repsFrom1->other_info->dns_name));
+ op->source_dsa->notify_uSN = op->uSN;
+ /* delete the repsTo for this replication partner in the
+ partition, as we have successfully told him to sync */
+ dreplsrv_notify_del_repsTo(op);
+ }
+ talloc_free(op->creq);
+
+ talloc_free(op);
+ s->ops.n_current = NULL;
+ dreplsrv_notify_run_ops(s);
+}
+
+
+static void dreplsrv_notify_op_callback_creq(struct composite_context *creq)
+{
+ struct dreplsrv_notify_operation *op = talloc_get_type(creq->async.private_data,
+ struct dreplsrv_notify_operation);
+ dreplsrv_notify_op_callback(op);
+}
+
+/*
+ run any pending replica sync calls
+ */
+void dreplsrv_notify_run_ops(struct dreplsrv_service *s)
+{
+ struct dreplsrv_notify_operation *op;
+
+ if (s->ops.n_current || s->ops.current) {
+ /* if there's still one running, we're done */
+ return;
+ }
+
+ if (!s->ops.notifies) {
+ /* if there're no pending operations, we're done */
+ return;
+ }
+
+ op = s->ops.notifies;
+ s->ops.n_current = op;
+ DLIST_REMOVE(s->ops.notifies, op);
+
+ op->creq = dreplsrv_op_notify_send(op);
+ if (!op->creq) {
+ dreplsrv_notify_op_callback(op);
+ return;
+ }
+
+ op->creq->async.fn = dreplsrv_notify_op_callback_creq;
+ op->creq->async.private_data = op;
+}
+
+
+/*
+ find a source_dsa for a given guid
+ */
+static struct dreplsrv_partition_source_dsa *dreplsrv_find_source_dsa(struct dreplsrv_partition *p,
+ struct GUID *guid)
+{
+ struct dreplsrv_partition_source_dsa *s;
+
+ for (s=p->sources; s; s=s->next) {
+ if (GUID_compare(&s->repsFrom1->source_dsa_obj_guid, guid) == 0) {
+ return s;
+ }
+ }
+ return NULL;
+}
+
+
+/*
+ schedule a replicaSync message
+ */
+static WERROR dreplsrv_schedule_notify_sync(struct dreplsrv_service *service,
+ struct dreplsrv_partition *p,
+ struct repsFromToBlob *reps,
+ TALLOC_CTX *mem_ctx,
+ uint64_t uSN)
+{
+ struct dreplsrv_notify_operation *op;
+ struct dreplsrv_partition_source_dsa *s;
+
+ s = dreplsrv_find_source_dsa(p, &reps->ctr.ctr1.source_dsa_obj_guid);
+ if (s == NULL) {
+ DEBUG(0,(__location__ ": Unable to find source_dsa for %s\n",
+ GUID_string(mem_ctx, &reps->ctr.ctr1.source_dsa_obj_guid)));
+ return WERR_DS_UNAVAILABLE;
+ }
+
+ op = talloc_zero(mem_ctx, struct dreplsrv_notify_operation);
+ W_ERROR_HAVE_NO_MEMORY(op);
+
+ op->service = service;
+ op->source_dsa = s;
+ op->uSN = uSN;
+
+ DLIST_ADD_END(service->ops.notifies, op, struct dreplsrv_notify_operation *);
+ talloc_steal(service, op);
+ return WERR_OK;
+}
+
+/*
+ see if a partition has a hugher uSN than what is in the repsTo and
+ if so then send a DsReplicaSync
+ */
+static WERROR dreplsrv_notify_check(struct dreplsrv_service *s,
+ struct dreplsrv_partition *p,
+ TALLOC_CTX *mem_ctx)
+{
+ uint32_t count;
+ struct repsFromToBlob *reps;
+ WERROR werr;
+ uint64_t uSN;
+ int ret, i;
+
+ werr = dsdb_loadreps(s->samdb, mem_ctx, p->dn, "repsTo", &reps, &count);
+ if (!W_ERROR_IS_OK(werr)) {
+ DEBUG(0,(__location__ ": Failed to load repsTo for %s\n",
+ ldb_dn_get_linearized(p->dn)));
+ return werr;
+ }
+
+ /* loads the partition uSNHighest */
+ ret = dsdb_load_partition_usn(s->samdb, p->dn, &uSN);
+ if (ret != LDB_SUCCESS || uSN == 0) {
+ /* nothing to do */
+ return WERR_OK;
+ }
+
+ /* see if any of our partners need some of our objects */
+ for (i=0; i<count; i++) {
+ struct dreplsrv_partition_source_dsa *sdsa;
+ sdsa = dreplsrv_find_source_dsa(p, &reps[i].ctr.ctr1.source_dsa_obj_guid);
+ if (sdsa == NULL) continue;
+ if (sdsa->notify_uSN < uSN) {
+ /* we need to tell this partner to replicate
+ with us */
+ werr = dreplsrv_schedule_notify_sync(s, p, &reps[i], mem_ctx, uSN);
+ if (!W_ERROR_IS_OK(werr)) {
+ DEBUG(0,(__location__ ": Failed to setup notify to %s for %s\n",
--
Samba Shared Repository
More information about the samba-cvs
mailing list