repl5_init.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /*
  42. repl5_init.c - plugin initialization functions
  43. */
  44. /*
  45. * Add an entry like the following to dse.ldif to enable this plugin:
  46. dn: cn=Multi-Master Replication Plugin,cn=plugins,cn=config
  47. objectclass: top
  48. objectclass: nsSlapdPlugin
  49. objectclass: extensibleObject
  50. cn: Legacy Replication Plugin
  51. nsslapd-pluginpath: /export2/servers/Hydra-supplier/lib/replication-plugin.so
  52. nsslapd-plugininitfunc: replication_multimaster_plugin_init
  53. nsslapd-plugintype: object
  54. nsslapd-pluginenabled: on
  55. nsslapd-plugin-depends-on-type: database
  56. nsslapd-plugin-depends-on-named: Class of Service
  57. nsslapd-pluginid: replication-multimaster
  58. nsslapd-pluginversion: 5.0b1
  59. nsslapd-pluginvendor: Netscape Communications
  60. nsslapd-plugindescription: Multi-Master Replication Plugin
  61. */
  62. #include "slapi-plugin.h"
  63. #include "repl.h"
  64. #include "repl5.h"
  65. #include "cl5.h" /* changelog interface */
  66. #include "plstr.h"
  67. /* #ifdef _WIN32
  68. int *module_ldap_debug = 0;
  69. void plugin_init_debug_level(int *level_ptr)
  70. {
  71. module_ldap_debug = level_ptr;
  72. }
  73. #endif*/
  74. #define NSDS_REPL_NAME_PREFIX "Netscape Replication"
  75. static char *start_oid_list[] = {
  76. REPL_START_NSDS50_REPLICATION_REQUEST_OID,
  77. REPL_START_NSDS90_REPLICATION_REQUEST_OID,
  78. NULL
  79. };
  80. static char *start_name_list[] = {
  81. NSDS_REPL_NAME_PREFIX " Start Session",
  82. NULL
  83. };
  84. static char *end_oid_list[] = {
  85. REPL_END_NSDS50_REPLICATION_REQUEST_OID,
  86. NULL
  87. };
  88. static char *end_name_list[] = {
  89. NSDS_REPL_NAME_PREFIX " End Session",
  90. NULL
  91. };
  92. static char *total_oid_list[] = {
  93. REPL_NSDS50_REPLICATION_ENTRY_REQUEST_OID,
  94. REPL_NSDS71_REPLICATION_ENTRY_REQUEST_OID,
  95. NULL
  96. };
  97. static char *total_name_list[] = {
  98. NSDS_REPL_NAME_PREFIX " Total Update Entry",
  99. NULL
  100. };
  101. static char *response_oid_list[] = {
  102. REPL_NSDS50_REPLICATION_RESPONSE_OID,
  103. NULL
  104. };
  105. static char *response_name_list[] = {
  106. NSDS_REPL_NAME_PREFIX " Response",
  107. NULL
  108. };
  109. static char *cleanruv_oid_list[] = {
  110. REPL_CLEANRUV_OID,
  111. NULL
  112. };
  113. static char *cleanruv_name_list[] = {
  114. NSDS_REPL_NAME_PREFIX " CleanAllRUV",
  115. NULL
  116. };
  117. static char *cleanruv_abort_oid_list[] = {
  118. REPL_ABORT_CLEANRUV_OID,
  119. NULL
  120. };
  121. static char *cleanruv_abort_name_list[] = {
  122. NSDS_REPL_NAME_PREFIX " CleanAllRUV Abort",
  123. NULL
  124. };
  125. static char *cleanruv_maxcsn_oid_list[] = {
  126. REPL_CLEANRUV_GET_MAXCSN_OID,
  127. NULL
  128. };
  129. static char *cleanruv_maxcsn_name_list[] = {
  130. NSDS_REPL_NAME_PREFIX " CleanAllRUV Retrieve MaxCSN",
  131. NULL
  132. };
  133. static char *cleanruv_status_oid_list[] = {
  134. REPL_CLEANRUV_CHECK_STATUS_OID,
  135. NULL
  136. };
  137. static char *cleanruv_status_name_list[] = {
  138. NSDS_REPL_NAME_PREFIX " CleanAllRUV Check Status",
  139. NULL
  140. };
  141. /* List of plugin identities for every plugin registered. Plugin identity
  142. is passed by the server in the plugin init function and must be supplied
  143. by the plugin to all internal operations it initiates
  144. */
  145. /* ----------------------------- Multi-Master Replication Plugin */
  146. static Slapi_PluginDesc multimasterdesc = {"replication-multimaster", VENDOR, DS_PACKAGE_VERSION, "Multi-master Replication Plugin"};
  147. static Slapi_PluginDesc multimasterpreopdesc = {"replication-multimaster-preop", VENDOR, DS_PACKAGE_VERSION, "Multi-master replication pre-operation plugin"};
  148. static Slapi_PluginDesc multimasterpostopdesc = {"replication-multimaster-postop", VENDOR, DS_PACKAGE_VERSION, "Multi-master replication post-operation plugin"};
  149. static Slapi_PluginDesc multimasterinternalpreopdesc = {"replication-multimaster-internalpreop", VENDOR, DS_PACKAGE_VERSION, "Multi-master replication internal pre-operation plugin"};
  150. static Slapi_PluginDesc multimasterinternalpostopdesc = {"replication-multimaster-internalpostop", VENDOR, DS_PACKAGE_VERSION, "Multimaster replication internal post-operation plugin"};
  151. static Slapi_PluginDesc multimasterbepreopdesc = {"replication-multimaster-bepreop", VENDOR, DS_PACKAGE_VERSION, "Multimaster replication bepre-operation plugin"};
  152. static Slapi_PluginDesc multimasterbepostopdesc = {"replication-multimaster-bepostop", VENDOR, DS_PACKAGE_VERSION, "Multimaster replication bepost-operation plugin"};
  153. static Slapi_PluginDesc multimasterbetxnpostopdesc = {"replication-multimaster-betxnpostop", VENDOR, DS_PACKAGE_VERSION, "Multimaster replication be transaction post-operation plugin"};
  154. static Slapi_PluginDesc multimasterextopdesc = { "replication-multimaster-extop", VENDOR, DS_PACKAGE_VERSION, "Multimaster replication extended-operation plugin" };
  155. static int multimaster_stopped_flag; /* A flag which is set when all the plugin threads are to stop */
  156. static int multimaster_started_flag = 0;
  157. /* Thread private data and interface */
  158. static PRUintn thread_private_agmtname; /* thread private index for logging*/
  159. static PRUintn thread_private_cache;
  160. char*
  161. get_thread_private_agmtname()
  162. {
  163. char *agmtname = NULL;
  164. if (thread_private_agmtname)
  165. agmtname = PR_GetThreadPrivate(thread_private_agmtname);
  166. return (agmtname ? agmtname : "");
  167. }
  168. void
  169. set_thread_private_agmtname(const char *agmtname)
  170. {
  171. if (thread_private_agmtname)
  172. PR_SetThreadPrivate(thread_private_agmtname, (void *)agmtname);
  173. }
  174. void*
  175. get_thread_private_cache ()
  176. {
  177. void *buf = NULL;
  178. if ( thread_private_cache )
  179. buf = PR_GetThreadPrivate ( thread_private_cache );
  180. return buf;
  181. }
  182. void
  183. set_thread_private_cache ( void *buf )
  184. {
  185. if ( thread_private_cache )
  186. PR_SetThreadPrivate ( thread_private_cache, buf );
  187. }
  188. char*
  189. get_repl_session_id (Slapi_PBlock *pb, char *idstr, CSN **csn)
  190. {
  191. int opid=-1;
  192. PRUint64 connid = 0;
  193. CSN *opcsn;
  194. char opcsnstr[CSN_STRSIZE];
  195. *idstr = '\0';
  196. opcsn = NULL;
  197. opcsnstr[0] = '\0';
  198. if (pb) {
  199. Slapi_Operation *op;
  200. slapi_pblock_get (pb, SLAPI_OPERATION_ID, &opid);
  201. /* Avoid "Connection is NULL and hence cannot access SLAPI_CONN_ID" */
  202. if (opid) {
  203. slapi_pblock_get (pb, SLAPI_CONN_ID, &connid);
  204. PR_snprintf (idstr, REPL_SESSION_ID_SIZE, "conn=%" NSPRIu64 " op=%d",
  205. (long long unsigned int)connid, opid);
  206. }
  207. slapi_pblock_get ( pb, SLAPI_OPERATION, &op );
  208. opcsn = operation_get_csn (op);
  209. if (opcsn) {
  210. csn_as_string (opcsn, PR_FALSE, opcsnstr);
  211. PL_strcatn (idstr, REPL_SESSION_ID_SIZE, " csn=");
  212. PL_strcatn (idstr, REPL_SESSION_ID_SIZE, opcsnstr);
  213. }
  214. }
  215. if (csn) {
  216. *csn = opcsn;
  217. }
  218. return idstr;
  219. }
  220. /* preop acquires csn generator handle */
  221. int repl5_is_betxn = 0;
  222. int
  223. multimaster_preop_init( Slapi_PBlock *pb )
  224. {
  225. int rc= 0; /* OK */
  226. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  227. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterpreopdesc ) != 0 ||
  228. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *) multimaster_preop_bind ) != 0 ||
  229. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *) multimaster_preop_add ) != 0 ||
  230. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_DELETE_FN, (void *) multimaster_preop_delete ) != 0 ||
  231. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *) multimaster_preop_modify ) != 0 ||
  232. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODRDN_FN, (void *) multimaster_preop_modrdn ) != 0 ||
  233. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) multimaster_preop_search ) != 0 ||
  234. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_COMPARE_FN, (void *) multimaster_preop_compare ) != 0 ||
  235. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *) multimaster_ruv_search ) != 0)
  236. {
  237. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_preop_init failed\n" );
  238. rc= -1;
  239. }
  240. return rc;
  241. }
  242. /* process_postop (core op of post op) frees CSN,
  243. * which should be called after betxn is finieshed. */
  244. int
  245. multimaster_postop_init( Slapi_PBlock *pb )
  246. {
  247. int rc= 0; /* OK */
  248. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  249. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterpostopdesc ) != 0 ||
  250. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_BIND_FN, (void *) multimaster_postop_bind ) != 0 ||
  251. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_ADD_FN, (void *) multimaster_postop_add ) != 0 ||
  252. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *) multimaster_postop_delete ) != 0 ||
  253. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *) multimaster_postop_modify ) != 0 ||
  254. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *) multimaster_postop_modrdn ) != 0 )
  255. {
  256. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_postop_init failed\n" );
  257. rc= -1;
  258. }
  259. return rc;
  260. }
  261. int
  262. multimaster_internalpreop_init( Slapi_PBlock *pb )
  263. {
  264. int rc= 0; /* OK */
  265. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  266. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterinternalpreopdesc ) != 0 ||
  267. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN, (void *) multimaster_preop_add ) != 0 ||
  268. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN, (void *) multimaster_preop_delete ) != 0 ||
  269. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN, (void *) multimaster_preop_modify ) != 0 ||
  270. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN, (void *) multimaster_preop_modrdn ) != 0 )
  271. {
  272. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_internalpreop_init failed\n" );
  273. rc= -1;
  274. }
  275. return rc;
  276. }
  277. int
  278. multimaster_internalpostop_init( Slapi_PBlock *pb )
  279. {
  280. int rc= 0; /* OK */
  281. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  282. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterinternalpostopdesc ) != 0 ||
  283. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, (void *) multimaster_postop_add ) != 0 ||
  284. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, (void *) multimaster_postop_delete ) != 0 ||
  285. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, (void *) multimaster_postop_modify ) != 0 ||
  286. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, (void *) multimaster_postop_modrdn ) != 0 )
  287. {
  288. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_internalpostop_init failed\n" );
  289. rc= -1;
  290. }
  291. return rc;
  292. }
  293. /*
  294. * bepreop: setting SLAPI_TXN_RUV_MODS_FN, cleanup old stateinfo.
  295. * If betxn is off, preop urp is called here, too.
  296. */
  297. int
  298. multimaster_bepreop_init( Slapi_PBlock *pb )
  299. {
  300. int rc= 0; /* OK */
  301. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  302. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepreopdesc ) != 0 ||
  303. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_ADD_FN, (void *) multimaster_bepreop_add ) != 0 ||
  304. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN, (void *) multimaster_bepreop_delete ) != 0 ||
  305. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN, (void *) multimaster_bepreop_modify ) != 0 ||
  306. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN, (void *) multimaster_bepreop_modrdn ) != 0 ||
  307. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_CLOSE_FN, (void *) cl5Close ) != 0 ||
  308. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_BACKUP_FN, (void *) cl5WriteRUV ) != 0 )
  309. {
  310. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_bepreop_init failed\n" );
  311. rc= -1;
  312. }
  313. return rc;
  314. }
  315. /*
  316. * betxnpreop: if betxn is on, call preop urp at betxnpreop.
  317. */
  318. int
  319. multimaster_betxnpreop_init( Slapi_PBlock *pb )
  320. {
  321. int rc= 0; /* OK */
  322. return rc;
  323. }
  324. /*
  325. * This bepostop_init is registered only if plugintype is NOT betxn.
  326. * if plugintype is betxn, callbacks are set in each multimaster_betxnpostop
  327. * function.
  328. */
  329. int
  330. multimaster_bepostop_init( Slapi_PBlock *pb )
  331. {
  332. int rc= 0; /* OK */
  333. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  334. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepostopdesc ) != 0 ||
  335. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_MODRDN_FN, (void *) multimaster_bepostop_modrdn ) != 0 ||
  336. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_DELETE_FN, (void *) multimaster_bepostop_delete ) != 0 ||
  337. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_OPEN_FN, (void *) changelog5_init ) != 0 ||
  338. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_BACKUP_FN, (void *) cl5DeleteRUV ) != 0 )
  339. {
  340. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_bepostop_init failed\n" );
  341. rc= -1;
  342. }
  343. return rc;
  344. }
  345. /*
  346. * This betxn_bepostop_init is registered only if plugintype is betxn.
  347. * Note: other callbacks (add/delete/modify/modrdn) are set in each
  348. * multimaster_betxnpostop function.
  349. */
  350. int
  351. multimaster_betxn_bepostop_init( Slapi_PBlock *pb )
  352. {
  353. int rc= 0; /* OK */
  354. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) ||
  355. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepostopdesc ) ||
  356. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_OPEN_FN, (void *) changelog5_init ) ||
  357. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_BACKUP_FN, (void *) cl5DeleteRUV ) )
  358. {
  359. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_betxn_bepostop_init failed\n" );
  360. rc= -1;
  361. }
  362. return rc;
  363. }
  364. int
  365. multimaster_betxnpostop_init( Slapi_PBlock *pb )
  366. {
  367. int rc = 0; /* OK */
  368. void *add_fn;
  369. void *del_fn;
  370. void *mod_fn;
  371. void *mdn_fn;
  372. if (repl5_is_betxn) {
  373. add_fn = multimaster_be_betxnpostop_add;
  374. del_fn = multimaster_be_betxnpostop_delete;
  375. mod_fn = multimaster_be_betxnpostop_modify;
  376. mdn_fn = multimaster_be_betxnpostop_modrdn;
  377. } else {
  378. add_fn = multimaster_betxnpostop_add;
  379. del_fn = multimaster_betxnpostop_delete;
  380. mod_fn = multimaster_betxnpostop_modify;
  381. mdn_fn = multimaster_betxnpostop_modrdn;
  382. }
  383. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) ||
  384. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  385. (void *)&multimasterbetxnpostopdesc) ||
  386. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN, add_fn) ||
  387. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN, del_fn) ||
  388. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN, mdn_fn) ||
  389. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN, mod_fn)) {
  390. slapi_log_error(SLAPI_LOG_PLUGIN, repl_plugin_name,
  391. "multimaster_betxnpostop_init failed\n");
  392. rc = -1;
  393. }
  394. return rc;
  395. }
  396. int
  397. multimaster_start_extop_init( Slapi_PBlock *pb )
  398. {
  399. int rc= 0; /* OK */
  400. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  401. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  402. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)start_oid_list ) != 0 ||
  403. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)start_name_list ) != 0 ||
  404. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_StartNSDS50ReplicationRequest ))
  405. {
  406. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_start_extop_init (StartNSDS50ReplicationRequest) failed\n" );
  407. rc= -1;
  408. }
  409. return rc;
  410. }
  411. int
  412. multimaster_end_extop_init( Slapi_PBlock *pb )
  413. {
  414. int rc= 0; /* OK */
  415. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  416. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  417. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)end_oid_list ) != 0 ||
  418. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)end_name_list ) != 0 ||
  419. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_EndNSDS50ReplicationRequest ))
  420. {
  421. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_end_extop_init (EndNSDS50ReplicationRequest) failed\n" );
  422. rc= -1;
  423. }
  424. return rc;
  425. }
  426. int
  427. multimaster_cleanruv_maxcsn_extop_init( Slapi_PBlock *pb )
  428. {
  429. int rc= 0; /* OK */
  430. void *identity = NULL;
  431. /* get plugin identity and store it to pass to internal operations */
  432. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  433. PR_ASSERT (identity);
  434. if (slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  435. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  436. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_maxcsn_oid_list ) != 0 ||
  437. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_maxcsn_name_list ) != 0 ||
  438. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_cleanruv_get_maxcsn ))
  439. {
  440. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_cleanruv_extop_init failed\n" );
  441. rc= -1;
  442. }
  443. return rc;
  444. }
  445. int
  446. multimaster_cleanruv_status_extop_init( Slapi_PBlock *pb )
  447. {
  448. int rc= 0; /* OK */
  449. void *identity = NULL;
  450. /* get plugin identity and store it to pass to internal operations */
  451. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  452. PR_ASSERT (identity);
  453. if (slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  454. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  455. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_status_oid_list ) != 0 ||
  456. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_status_name_list ) != 0 ||
  457. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_cleanruv_check_status ))
  458. {
  459. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_cleanruv_extop_init failed\n" );
  460. rc= -1;
  461. }
  462. return rc;
  463. }
  464. int
  465. multimaster_total_extop_init( Slapi_PBlock *pb )
  466. {
  467. int rc= 0; /* OK */
  468. void *identity = NULL;
  469. /* get plugin identity and store it to pass to internal operations */
  470. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  471. PR_ASSERT (identity);
  472. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  473. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  474. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)total_oid_list ) != 0 ||
  475. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)total_name_list ) != 0 ||
  476. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_NSDS50ReplicationEntry ))
  477. {
  478. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_start_extop_init (NSDS50ReplicationEntry failed\n" );
  479. rc= -1;
  480. }
  481. return rc;
  482. }
  483. int
  484. multimaster_response_extop_init( Slapi_PBlock *pb )
  485. {
  486. int rc= 0; /* OK */
  487. void *identity = NULL;
  488. /* get plugin identity and store it to pass to internal operations */
  489. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  490. PR_ASSERT (identity);
  491. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  492. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  493. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)response_oid_list ) != 0 ||
  494. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)response_name_list ) != 0 ||
  495. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)extop_noop ))
  496. {
  497. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_start_extop_init (NSDS50ReplicationResponse failed\n" );
  498. rc= -1;
  499. }
  500. return rc;
  501. }
  502. int
  503. multimaster_cleanruv_extop_init( Slapi_PBlock *pb )
  504. {
  505. int rc= 0; /* OK */
  506. void *identity = NULL;
  507. /* get plugin identity and store it to pass to internal operations */
  508. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  509. PR_ASSERT (identity);
  510. if (slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  511. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  512. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_oid_list ) != 0 ||
  513. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_name_list ) != 0 ||
  514. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_cleanruv ))
  515. {
  516. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_cleanruv_extop_init failed\n" );
  517. rc= -1;
  518. }
  519. return rc;
  520. }
  521. int
  522. multimaster_cleanruv_abort_extop_init( Slapi_PBlock *pb )
  523. {
  524. int rc= 0; /* OK */
  525. void *identity = NULL;
  526. /* get plugin identity and store it to pass to internal operations */
  527. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  528. PR_ASSERT (identity);
  529. if (slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  530. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  531. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_abort_oid_list ) != 0 ||
  532. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_abort_name_list ) != 0 ||
  533. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_abort_cleanruv ))
  534. {
  535. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_cleanruv_abort_extop_init failed\n" );
  536. rc= -1;
  537. }
  538. return rc;
  539. }
  540. static PRBool
  541. check_for_ldif_dump(Slapi_PBlock *pb)
  542. {
  543. int i;
  544. int argc;
  545. char **argv;
  546. PRBool return_value = PR_FALSE;
  547. slapi_pblock_get( pb, SLAPI_ARGC, &argc);
  548. slapi_pblock_get( pb, SLAPI_ARGV, &argv);
  549. for (i = 1; i < argc && !return_value; i++)
  550. {
  551. if (strcmp(argv[i], "db2ldif") == 0)
  552. {
  553. return_value = PR_TRUE;
  554. }
  555. }
  556. return return_value;
  557. }
  558. static PRBool is_ldif_dump = PR_FALSE;
  559. PRBool
  560. ldif_dump_is_running()
  561. {
  562. return is_ldif_dump;
  563. }
  564. int
  565. multimaster_start( Slapi_PBlock *pb )
  566. {
  567. int rc= 0; /* OK */
  568. if (!multimaster_started_flag)
  569. {
  570. /* Get any registered replication session API */
  571. repl_session_plugin_init();
  572. /* Initialize thread private data for logging. Ignore if fails */
  573. PR_NewThreadPrivateIndex (&thread_private_agmtname, NULL);
  574. PR_NewThreadPrivateIndex (&thread_private_cache, NULL);
  575. /* Decode the command line args to see if we're dumping to LDIF */
  576. is_ldif_dump = check_for_ldif_dump(pb);
  577. /* allow online replica configuration */
  578. rc = replica_config_init ();
  579. if (rc != 0)
  580. goto out;
  581. slapi_register_supported_control(REPL_NSDS50_UPDATE_INFO_CONTROL_OID,
  582. SLAPI_OPERATION_ADD | SLAPI_OPERATION_DELETE |
  583. SLAPI_OPERATION_MODIFY | SLAPI_OPERATION_MODDN);
  584. /* Stash away our partial URL, used in RUVs */
  585. rc = multimaster_set_local_purl();
  586. if (rc != 0)
  587. goto out;
  588. /* Initialise support for cn=monitor */
  589. rc = repl_monitor_init();
  590. if (rc != 0)
  591. goto out;
  592. /* initialize name hash */
  593. rc = replica_init_name_hash ();
  594. if (rc != 0)
  595. goto out;
  596. /* initialize dn hash */
  597. rc = replica_init_dn_hash ();
  598. if (rc != 0)
  599. goto out;
  600. /* create replicas */
  601. multimaster_mtnode_construct_replicas ();
  602. /* Initialise the 5.0 Changelog */
  603. rc = changelog5_init();
  604. if (rc != 0)
  605. goto out;
  606. /* Initialize the replication agreements, unless we're dumping LDIF */
  607. if (!is_ldif_dump)
  608. {
  609. rc = agmtlist_config_init();
  610. if (rc != 0)
  611. goto out;
  612. }
  613. /* check if the replica's data was reloaded offline and we need
  614. to reinitialize replica's changelog. This should be done
  615. after the changelog is initialized */
  616. replica_enumerate_replicas (replica_check_for_data_reload, NULL);
  617. /* register to be notified when backend state changes */
  618. slapi_register_backend_state_change((void *)multimaster_be_state_change,
  619. multimaster_be_state_change);
  620. multimaster_started_flag = 1;
  621. multimaster_stopped_flag = 0;
  622. }
  623. out:
  624. return rc;
  625. }
  626. int
  627. multimaster_stop( Slapi_PBlock *pb )
  628. {
  629. int rc= 0; /* OK */
  630. if (!multimaster_stopped_flag)
  631. {
  632. if (!is_ldif_dump)
  633. {
  634. /* Shut down replication agreements */
  635. agmtlist_shutdown();
  636. }
  637. /* if we are cleaning a ruv, stop */
  638. stop_ruv_cleaning();
  639. /* unregister backend state change notification */
  640. slapi_unregister_backend_state_change((void *)multimaster_be_state_change);
  641. changelog5_cleanup(); /* Shut down the changelog */
  642. multimaster_mtnode_extension_destroy(); /* Destroy mapping tree node exts */
  643. replica_destroy_name_hash(); /* destroy the hash and its remaining content */
  644. replica_config_destroy (); /* Destroy replica config info */
  645. multimaster_stopped_flag = 1;
  646. }
  647. return rc;
  648. }
  649. PRBool
  650. multimaster_started()
  651. {
  652. return(multimaster_started_flag != 0);
  653. }
  654. /*
  655. * Initialize the multimaster replication plugin.
  656. */
  657. int replication_multimaster_plugin_init(Slapi_PBlock *pb)
  658. {
  659. static int multimaster_initialised= 0;
  660. int rc= 0; /* OK */
  661. void *identity = NULL;
  662. Slapi_Entry *plugin_entry = NULL;
  663. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  664. PR_ASSERT (identity);
  665. repl_set_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION, identity);
  666. /* need the repl plugin path for the chain on update function */
  667. /* slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &entry);
  668. PR_ASSERT(entry);
  669. path = slapi_entry_attr_get_charptr(entry, "nsslapd-pluginpath");
  670. repl_set_repl_plugin_path(path);
  671. slapi_ch_free_string(&path);
  672. */
  673. multimaster_mtnode_extension_init ();
  674. if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
  675. plugin_entry) {
  676. repl5_is_betxn = slapi_entry_attr_get_bool(plugin_entry,
  677. "nsslapd-pluginbetxn");
  678. }
  679. if(!multimaster_initialised)
  680. {
  681. /* Initialize extensions */
  682. repl_con_init_ext();
  683. repl_sup_init_ext();
  684. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 );
  685. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterdesc );
  686. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_START_FN, (void *) multimaster_start );
  687. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_CLOSE_FN, (void *) multimaster_stop );
  688. /* Register the plugin interfaces we implement */
  689. /* preop acquires csn generator handle */
  690. rc = slapi_register_plugin("preoperation", 1 /* Enabled */,
  691. "multimaster_preop_init",
  692. multimaster_preop_init,
  693. "Multimaster replication preoperation plugin",
  694. NULL, identity);
  695. /* bepreop: setting SLAPI_TXN_RUV_MODS_FN and cleanup old stateinfo
  696. * -- should be done before transaction */
  697. /* if betxn is off, urp is called at bepreop. */
  698. rc = slapi_register_plugin("bepreoperation", 1 /* Enabled */,
  699. "multimaster_bepreop_init",
  700. multimaster_bepreop_init,
  701. "Multimaster replication bepreoperation plugin",
  702. NULL, identity);
  703. /* is_betxn: be post ops (add/del/mod/mdn) are combined into betxn ops.
  704. * no betxn: be post ops are regsitered at bepostoperation. */
  705. rc = slapi_register_plugin("betxnpostoperation", 1 /* Enabled */,
  706. "multimaster_betxnpostop_init",
  707. multimaster_betxnpostop_init,
  708. "Multimaster replication betxnpostoperation plugin",
  709. NULL, identity);
  710. if (repl5_is_betxn) {
  711. /* if betxn is on, urp is called at betxnpreop. */
  712. rc = slapi_register_plugin("betxnpreoperation", 1 /* Enabled */,
  713. "multimaster_betxnpreop_init",
  714. multimaster_betxnpreop_init,
  715. "Multimaster replication betxnpreoperation plugin",
  716. NULL, identity);
  717. /* bepostop configures open and backup only (no betxn) */
  718. rc = slapi_register_plugin("bepostoperation", 1 /* Enabled */,
  719. "multimaster_betxn_bepostop_init",
  720. multimaster_betxn_bepostop_init,
  721. "Multimaster replication bepostoperation plugin",
  722. NULL, identity);
  723. } else {
  724. /* bepostop configures open and backup only as well as add/del/
  725. * mod/mdn bepost ops */
  726. rc = slapi_register_plugin("bepostoperation", 1 /* Enabled */,
  727. "multimaster_bepostop_init",
  728. multimaster_bepostop_init,
  729. "Multimaster replication bepostoperation2 plugin",
  730. NULL, identity);
  731. }
  732. /* process_postop (core op of post op) frees CSN,
  733. * which should wait until betxn is done. */
  734. rc = slapi_register_plugin("postoperation", 1 /* Enabled */,
  735. "multimaster_postop_init",
  736. multimaster_postop_init,
  737. "Multimaster replication postoperation plugin",
  738. NULL, identity);
  739. rc = slapi_register_plugin("internalpreoperation", 1 /* Enabled */,
  740. "multimaster_internalpreop_init",
  741. multimaster_internalpreop_init,
  742. "Multimaster replication internal preoperation plugin",
  743. NULL, identity);
  744. rc = slapi_register_plugin("internalpostoperation", 1 /* Enabled */,
  745. "multimaster_internalpostop_init",
  746. multimaster_internalpostop_init,
  747. "Multimaster replication internal postoperation plugin",
  748. NULL, identity);
  749. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_start_extop_init", multimaster_start_extop_init, "Multimaster replication start extended operation plugin", NULL, identity);
  750. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_end_extop_init", multimaster_end_extop_init, "Multimaster replication end extended operation plugin", NULL, identity);
  751. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_total_extop_init", multimaster_total_extop_init, "Multimaster replication total update extended operation plugin", NULL, identity);
  752. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_response_extop_init", multimaster_response_extop_init, "Multimaster replication extended response plugin", NULL, identity);
  753. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_cleanruv_extop_init", multimaster_cleanruv_extop_init, "Multimaster replication cleanruv extended operation plugin", NULL, identity);
  754. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_cleanruv_abort_extop_init", multimaster_cleanruv_abort_extop_init, "Multimaster replication cleanruv abort extended operation plugin", NULL, identity);
  755. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_cleanruv_maxcsn_extop_init", multimaster_cleanruv_maxcsn_extop_init, "Multimaster replication cleanruv maxcsn extended operation plugin", NULL, identity);
  756. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_cleanruv_status_extop_init", multimaster_cleanruv_status_extop_init, "Multimaster replication cleanruv status extended operation plugin", NULL, identity);
  757. if (0 == rc)
  758. {
  759. multimaster_initialised = 1;
  760. }
  761. }
  762. return rc;
  763. }