]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4-dsdb: simplify migration of old-style seqence numbers to metadata.tdb
authorAndrew Bartlett <abartlet@samba.org>
Thu, 9 Aug 2012 02:20:37 +0000 (12:20 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 9 Aug 2012 02:32:18 +0000 (04:32 +0200)
This simple operation does not need to be encased in generic ldb extended operations.

Andrew Bartlett

source4/dsdb/samdb/ldb_modules/partition.c
source4/dsdb/samdb/ldb_modules/partition_metadata.c

index 3533810deb4afb2957992f3ee7cae2fe66bf0ba6..8546d2f290cfff3aee9ce7e6ade64944634f7c77 100644 (file)
@@ -1027,115 +1027,73 @@ int partition_primary_sequence_number(struct ldb_module *module, TALLOC_CTX *mem
  * Older version of sequence number as sum of sequence numbers for each partition
  */
 int partition_sequence_number_from_partitions(struct ldb_module *module,
-                                             struct ldb_request *req,
-                                             struct ldb_extended **ext)
+                                             uint64_t *seqr)
 {
        int ret;
        unsigned int i;
        uint64_t seq_number = 0;
        struct partition_private_data *data = talloc_get_type(ldb_module_get_private(module),
                                                              struct partition_private_data);
-       struct ldb_seqnum_request *seq;
-       struct ldb_seqnum_result *seqr;
-       struct ldb_request *treq;
-       struct ldb_seqnum_request *tseq;
-       struct ldb_seqnum_result *tseqr;
-       struct ldb_result *res;
-       struct dsdb_partition *p;
 
-       p = find_partition(data, NULL, req);
-       if (p != NULL) {
-               /* the caller specified what partition they want the
-                * sequence number operation on - just pass it on
-                */
-               return ldb_next_request(p->module, req);                
+       ret = partition_primary_sequence_number(module, module, LDB_SEQ_HIGHEST_SEQ, &seq_number, NULL);
+       if (ret != LDB_SUCCESS) {
+               return ret;
        }
-
-       seq = talloc_get_type(req->op.extended.data, struct ldb_seqnum_request);
-
-       switch (seq->type) {
-       case LDB_SEQ_NEXT:
-       case LDB_SEQ_HIGHEST_SEQ:
-
-               ret = partition_primary_sequence_number(module, req, seq->type, &seq_number, req);
+       
+       /* Skip the lot if 'data' isn't here yet (initialisation) */
+       for (i=0; data && data->partitions && data->partitions[i]; i++) {
+               struct ldb_seqnum_request *tseq;
+               struct ldb_seqnum_result *tseqr;
+               struct ldb_request *treq;
+               struct ldb_result *res = talloc_zero(data, struct ldb_result);
+               if (res == NULL) {
+                       return ldb_oom(ldb_module_get_ctx(module));
+               }
+               tseq = talloc_zero(res, struct ldb_seqnum_request);
+               if (tseq == NULL) {
+                       talloc_free(res);
+                       return ldb_oom(ldb_module_get_ctx(module));
+               }
+               tseq->type = LDB_SEQ_HIGHEST_SEQ;
+               
+               ret = ldb_build_extended_req(&treq, ldb_module_get_ctx(module), res,
+                                            LDB_EXTENDED_SEQUENCE_NUMBER,
+                                            tseq,
+                                            NULL,
+                                            res,
+                                            ldb_extended_default_callback,
+                                            NULL);
+               LDB_REQ_SET_LOCATION(treq);
                if (ret != LDB_SUCCESS) {
+                       talloc_free(res);
                        return ret;
-               }
-
-               /* Skip the lot if 'data' isn't here yet (initialisation) */
-               for (i=0; data && data->partitions && data->partitions[i]; i++) {
-
-                       res = talloc_zero(req, struct ldb_result);
-                       if (res == NULL) {
-                               return ldb_oom(ldb_module_get_ctx(module));
-                       }
-                       tseq = talloc_zero(res, struct ldb_seqnum_request);
-                       if (tseq == NULL) {
-                               talloc_free(res);
-                               return ldb_oom(ldb_module_get_ctx(module));
-                       }
-                       tseq->type = seq->type;
-
-                       ret = ldb_build_extended_req(&treq, ldb_module_get_ctx(module), res,
-                                                    LDB_EXTENDED_SEQUENCE_NUMBER,
-                                                    tseq,
-                                                    NULL,
-                                                    res,
-                                                    ldb_extended_default_callback,
-                                                    req);
-                       LDB_REQ_SET_LOCATION(treq);
-                       if (ret != LDB_SUCCESS) {
-                               talloc_free(res);
-                               return ret;
-                       }
-
-                       ret = ldb_request_add_control(treq,
-                                                     DSDB_CONTROL_CURRENT_PARTITION_OID,
-                                                     false, data->partitions[i]->ctrl);
-                       if (ret != LDB_SUCCESS) {
-                               talloc_free(res);
-                               return ret;
-                       }
-
-                       ret = partition_request(data->partitions[i]->module, treq);
-                       if (ret != LDB_SUCCESS) {
-                               talloc_free(res);
-                               return ret;
-                       }
-                       ret = ldb_wait(treq->handle, LDB_WAIT_ALL);
-                       if (ret != LDB_SUCCESS) {
-                               talloc_free(res);
-                               return ret;
                        }
-                       tseqr = talloc_get_type(res->extended->data,
-                                               struct ldb_seqnum_result);
-                       seq_number += tseqr->seq_num;
+               
+               ret = ldb_request_add_control(treq,
+                                             DSDB_CONTROL_CURRENT_PARTITION_OID,
+                                             false, data->partitions[i]->ctrl);
+               if (ret != LDB_SUCCESS) {
                        talloc_free(res);
+                       return ret;
                }
-               break;
-
-       case LDB_SEQ_HIGHEST_TIMESTAMP:
-               return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR, "LDB_SEQ_HIGHEST_TIMESTAMP not supported");
-       }
-
-       *ext = talloc_zero(req, struct ldb_extended);
-       if (!*ext) {
-               return ldb_oom(ldb_module_get_ctx(module));
-       }
-       seqr = talloc_zero(*ext, struct ldb_seqnum_result);
-       if (seqr == NULL) {
-               talloc_free(*ext);
-               return ldb_oom(ldb_module_get_ctx(module));
-       }
-       (*ext)->oid = LDB_EXTENDED_SEQUENCE_NUMBER;
-       (*ext)->data = seqr;
-
-       seqr->seq_num = seq_number;
-       if (seq->type == LDB_SEQ_NEXT) {
-               seqr->seq_num++;
+               
+               ret = partition_request(data->partitions[i]->module, treq);
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(res);
+                       return ret;
+               }
+               ret = ldb_wait(treq->handle, LDB_WAIT_ALL);
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(res);
+                       return ret;
+               }
+               tseqr = talloc_get_type(res->extended->data,
+                                       struct ldb_seqnum_result);
+               seq_number += tseqr->seq_num;
+               talloc_free(res);
        }
 
-       seqr->flags |= LDB_SEQ_GLOBAL_SEQUENCE;
+       *seqr = seq_number;
        return LDB_SUCCESS;
 }
 
index 0bf7a406401eb82140ad396dce84814e223be65c..5826ac2ee1128ede0f89914f9d7e5b6af22e5822 100644 (file)
@@ -260,69 +260,14 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
  */
 static int partition_metadata_set_sequence_number(struct ldb_module *module)
 {
-       struct partition_private_data *data;
-       struct ldb_result *res;
-       struct ldb_request *req;
-       struct ldb_seqnum_request *seq;
-       struct ldb_seqnum_result *seqr;
-       struct ldb_extended *ext;
-       TALLOC_CTX *tmp_ctx;
        int ret;
        uint64_t seq_number;
 
-       data = talloc_get_type_abort(ldb_module_get_private(module),
-                                   struct partition_private_data);
-       if (!data || !data->metadata) {
-               return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
-                                       "partition_metadata: metadata not initialized");
-       }
-
-       tmp_ctx = talloc_new(data->metadata);
-       if (tmp_ctx == NULL) {
-               return ldb_module_oom(module);
-       }
-
-       res = talloc_zero(tmp_ctx, struct ldb_result);
-       if (res == NULL) {
-               talloc_free(tmp_ctx);
-               return ldb_module_oom(module);
-       }
-
-       seq = talloc_zero(tmp_ctx, struct ldb_seqnum_request);
-       if (seq == NULL) {
-               talloc_free(tmp_ctx);
-               return ldb_module_oom(module);
-       }
-       seq->type = LDB_SEQ_HIGHEST_SEQ;
-
-       /* Build an extended request, so it can be passed to each partition in
-          partition_sequence_number_from_partitions() */
-       ret = ldb_build_extended_req(&req,
-                                    ldb_module_get_ctx(module),
-                                    tmp_ctx,
-                                    LDB_EXTENDED_SEQUENCE_NUMBER,
-                                    seq,
-                                    NULL,
-                                    res,
-                                    ldb_extended_default_callback,
-                                    NULL);
-       LDB_REQ_SET_LOCATION(req);
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-
-       ret = partition_sequence_number_from_partitions(module, req, &ext);
+       ret = partition_sequence_number_from_partitions(module, &seq_number);
        if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
                return ret;
        }
 
-       seqr = talloc_get_type_abort(ext->data, struct ldb_seqnum_result);
-       seq_number = seqr->seq_num;
-
-       talloc_free(tmp_ctx);
-
        return partition_metadata_set_uint64(module, LDB_METADATA_SEQ_NUM, seq_number, true);
 }