The attached patch moves the cleaning of the RUV into the topology plugin.
I encountered a problem when removing a replica, which disconnects the topology, but it was fixed with my WIP for #5072.
I want to keep these issues separate, so please review and test the patch and let me know about issues found
Ludwig
>From 08c015c2bca36551239cab39e8f8fc26ed433d56 Mon Sep 17 00:00:00 2001 From: Ludwig Krispenz <lkris...@redhat.com> Date: Wed, 22 Jul 2015 10:59:36 +0200 Subject: [PATCH] handle cleaning of RUV in the topology plugin After removing a server the replicaid needs to be cleared in the ruv entry and in the changelog. This was triggere by initiating a cleanallruv task in "ipa-replica-manage del", but the removal of a master already triggers a cleanup of segments and replication agreement by the topology plugin, so this could be handled by the plugin as well. Ticket: https://fedorahosted.org/freeipa/ticket/5112 --- daemons/ipa-slapi-plugins/topology/topology.h | 1 + daemons/ipa-slapi-plugins/topology/topology_post.c | 1 + daemons/ipa-slapi-plugins/topology/topology_util.c | 93 ++++++++++++++++++++++ install/tools/ipa-replica-manage | 7 +- 4 files changed, 96 insertions(+), 6 deletions(-) diff --git a/daemons/ipa-slapi-plugins/topology/topology.h b/daemons/ipa-slapi-plugins/topology/topology.h index be9737679153ad4b2f8d07bc1622bcd6775bc8b1..0e5f523873589b8bbdd728297b0c98c31ddc694b 100644 --- a/daemons/ipa-slapi-plugins/topology/topology.h +++ b/daemons/ipa-slapi-plugins/topology/topology.h @@ -278,6 +278,7 @@ void ipa_topo_util_update_segments_for_host(Slapi_Entry *hostentry); char *ipa_topo_util_get_ldap_principal(char *repl_root, char *hostname); void ipa_topo_util_disable_repl_for_principal(char *repl_root, char *principal); void ipa_topo_util_delete_host(Slapi_Entry *hostentry); +void ipa_topo_util_cleanruv(Slapi_Entry *hostentry); void ipa_topo_util_disable_repl_from_host(char *repl_root, char *delhost); void ipa_topo_util_delete_segments_for_host(char *repl_root, char *delhost); diff --git a/daemons/ipa-slapi-plugins/topology/topology_post.c b/daemons/ipa-slapi-plugins/topology/topology_post.c index 4eb3c2fd10643658804943112c1466091f9f624e..d9d9993d7a7dbbd68e29b08c318b98d1d9cef3aa 100644 --- a/daemons/ipa-slapi-plugins/topology/topology_post.c +++ b/daemons/ipa-slapi-plugins/topology/topology_post.c @@ -268,6 +268,7 @@ ipa_topo_post_del(Slapi_PBlock *pb) */ ipa_topo_util_delete_host(del_entry); ipa_topo_cfg_host_del(del_entry); + ipa_topo_util_cleanruv(del_entry); break; case TOPO_IGNORE_ENTRY: break; diff --git a/daemons/ipa-slapi-plugins/topology/topology_util.c b/daemons/ipa-slapi-plugins/topology/topology_util.c index 523f6123c6db942860939842b64a098dd25839c9..ef9b454003dbaa80bf591d28511a6861bd28c868 100644 --- a/daemons/ipa-slapi-plugins/topology/topology_util.c +++ b/daemons/ipa-slapi-plugins/topology/topology_util.c @@ -1673,3 +1673,96 @@ ipa_topo_util_reset_init(char *repl_root) slapi_mods_free(&smods); } } + +int +ipa_topo_util_cleanruv_task(char *repl_root, int replicaID) +{ + Slapi_Entry *e = NULL; + Slapi_PBlock *pb; + char *dn = NULL; + char *repl_rid; + Slapi_DN *sdn = NULL; + int ret = 0; + dn = slapi_ch_smprintf("cn=clean %d,cn=cleanallruv,cn=tasks,cn=config", replicaID); + if (dn == NULL) return -1; + sdn = slapi_sdn_new_normdn_byref(dn); + + e = slapi_entry_alloc(); + /* the entry now owns the dup'd dn */ + slapi_entry_init_ext(e, sdn, NULL); /* sdn is copied into e */ + slapi_sdn_free(&sdn); + + slapi_entry_add_string(e, SLAPI_ATTR_OBJECTCLASS, "extensibleobject"); + slapi_entry_add_string(e, "replica-base-dn",repl_root); + repl_rid = slapi_ch_smprintf("%d",replicaID); + slapi_entry_add_string(e, "replica-id",repl_rid); + slapi_entry_add_string(e, "replica-force-cleaning", "yes"); + + pb = slapi_pblock_new(); + slapi_pblock_init(pb); + + /* e will be consumed by slapi_add_internal() */ + slapi_add_entry_internal_set_pb(pb, e, NULL, ipa_topo_get_plugin_id(), 0); + slapi_add_internal_pb(pb); + slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret); + slapi_pblock_destroy(pb); + slapi_ch_free_string(&repl_rid); + + return ret; + +} + +void +ipa_topo_util_cleanruv_element(char *repl_root, char *hostname) +{ + Slapi_PBlock *pb = NULL; + char *filter = "(&(objectclass=nstombstone)(nsuniqueid=ffffffff-ffffffff-ffffffff-ffffffff))"; + char **ruv_ele = NULL; + int ret; + Slapi_Entry **entries = NULL; + + /* find ruv object */ + pb = slapi_pblock_new(); + slapi_search_internal_set_pb(pb, repl_root, LDAP_SCOPE_SUB, + filter, NULL, 0, NULL, NULL, + ipa_topo_get_plugin_id(), 0); + slapi_search_internal_pb(pb); + slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret); + if (ret != 0) { + slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM, + "ipa_topo_util_cleanruv: no RUV entry found\n"); + } else { + slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries); + if (NULL == entries || NULL == entries[0]) { + slapi_log_error(SLAPI_LOG_PLUGIN, IPA_TOPO_PLUGIN_SUBSYSTEM, + "ipa_topo_util_cleanruv: no RUV entry found\n"); + } else { + ruv_ele = slapi_entry_attr_get_charray(entries[0], "nsds50ruv"); + int i = 0; + int rid = 0; + while (ruv_ele[i]) { + if (strstr(ruv_ele[i], hostname)) { + rid = atoi(ruv_ele[i]+strlen("{replica ")); + ipa_topo_util_cleanruv_task(repl_root,rid); + break; + } + i++; + } + } + } +} + +void +ipa_topo_util_cleanruv(Slapi_Entry *del_entry) +{ + char* delhost = NULL; + char **shared_root = ipa_topo_get_plugin_replica_root(); + int i = 0; + + delhost = slapi_entry_attr_get_charptr(del_entry,"cn"); + + while (shared_root[i]) { + ipa_topo_util_cleanruv_element(shared_root[i], delhost); + i++; + } +} diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage index e525a02f4c60350b7a943abab4b4aedd957e984a..77b10eb4a2cf09d47343a4ba09d72b60153c98e9 100755 --- a/install/tools/ipa-replica-manage +++ b/install/tools/ipa-replica-manage @@ -793,12 +793,7 @@ def del_master_managed(realm, hostname, options): break i += 1 - # Clean RUV - if rid is not None: - try: - thisrepl.cleanallruv(rid) - except KeyboardInterrupt: - print "Wait for task interrupted. It will continue to run in the background" + # Clean RUV is hanbdled by the topology plugin # 8. And clean up the removed replica DNS entries if any. cleanup_server_dns_entries(realm, hostname, thisrepl.suffix, options) -- 2.4.3
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code