@@ -432,10 +432,6 @@ let assert_can_host_ha_statefile ~__context ~sr =
432432 Xha_statefile. assert_sr_can_host_statefile ~__context ~sr
433433
434434(* Metadata replication to SRs *)
435- let redo_log_lifecycle_mutex = Mutex. create ()
436- let metadata_replication : ((API.ref_SR, (API.ref_VBD * Redo_log.redo_log)) Hashtbl.t) =
437- Hashtbl. create Xapi_globs. redo_log_max_instances
438-
439435let find_or_create_metadata_vdi ~__context ~sr =
440436 let pool = Helpers. get_pool ~__context in
441437 let vdi_can_be_used vdi =
@@ -468,71 +464,23 @@ let get_master_dom0 ~__context =
468464 let vms = Db.Host. get_resident_VMs ~__context ~self: master in
469465 List. hd (List. filter (fun vm -> Db.VM. get_is_control_domain ~__context ~self: vm) vms)
470466
471- let provision_metadata_vdi_and_start_redo_log ~__context ~sr =
472- let vdi = find_or_create_metadata_vdi ~__context ~sr in
473- let log = Redo_log. create () in
474- let sr_uuid = Db.SR. get_uuid ~__context ~self: sr in
475- let dom0 = get_master_dom0 ~__context in
476- (* Create and plug vbd *)
477- let vbd = Helpers. call_api_functions ~__context (fun rpc session_id ->
478- let vbd = Client.VBD. create ~rpc ~session_id ~v M:dom0 ~empty: false ~v DI:vdi
479- ~userdevice: " autodetect" ~bootable: false ~mode: `RW ~_type:`Disk
480- ~unpluggable: true ~qos_algorithm_type: " " ~qos_algorithm_params: []
481- ~other_config: []
482- in
483- Client.VBD. plug ~rpc ~session_id ~self: vbd;
484- vbd)
485- in
486- (* Enable redo_log and point it at the new device *)
487- let device = Db.VBD. get_device ~__context ~self: vbd in
488- try
489- Redo_log. enable_block log (" /dev/" ^ device);
490- Redo_log. startup log;
491- Hashtbl. add metadata_replication sr (vbd, log);
492- debug " Redo log started on SR %s" sr_uuid
493- with e ->
494- Helpers. call_api_functions ~__context (fun rpc session_id ->
495- Client.VBD. unplug ~rpc ~session_id ~self: vbd);
496- raise (Api_errors. Server_error (Api_errors. cannot_enable_redo_log,
497- [Printexc. to_string e]))
498-
499467let enable_database_replication ~__context ~sr =
500468 if (not (Pool_features. is_enabled ~__context Features. DR )) then
501469 raise (Api_errors. Server_error (Api_errors. license_restriction, [] ));
502- Mutex. execute redo_log_lifecycle_mutex (fun () ->
503- debug " Attempting to enable metadata replication on SR [%s:%s]"
504- (Db.SR. get_name_label ~__context ~self: sr) (Db.SR. get_uuid ~__context ~self: sr);
505- if Hashtbl. mem metadata_replication sr then
506- debug " Metadata is already being replicated to this SR."
507- else begin
508- (* Check that the number of metadata redo_logs isn't already at the limit. *)
509- (* There should never actually be more redo_logs than the limit! *)
510- if Hashtbl. length metadata_replication > = Xapi_globs. redo_log_max_instances then
511- raise (Api_errors. Server_error (Api_errors. no_more_redo_logs_allowed, [] ))
512- else
513- provision_metadata_vdi_and_start_redo_log ~__context ~sr
514- end
515- )
470+ let metadata_vdi = find_or_create_metadata_vdi ~__context ~sr in
471+ Xapi_vdi_helpers. enable_database_replication ~__context ~vdi: metadata_vdi
516472
473+ (* Disable metadata replication to all metadata VDIs in this SR. *)
517474let disable_database_replication ~__context ~sr =
518- Mutex. execute redo_log_lifecycle_mutex (fun () ->
519- debug " Attempting to disable metadata replication on SR [%s:%s]."
520- (Db.SR. get_name_label ~__context ~self: sr) (Db.SR. get_uuid ~__context ~self: sr);
521- if not (Hashtbl. mem metadata_replication sr) then
522- debug " Metadata is not being replicated to this SR."
523- else begin
524- let (vbd, log) = Hashtbl. find metadata_replication sr in
525- Redo_log. shutdown log;
526- Redo_log. disable log;
527- Helpers. call_api_functions ~__context (fun rpc session_id ->
528- Client.VBD. unplug ~rpc ~session_id ~self: vbd);
529- Hashtbl. remove metadata_replication sr;
530- Redo_log. delete log;
531- let vdi = Db.VBD. get_VDI ~__context ~self: vbd in
532- Helpers. call_api_functions ~__context (fun rpc session_id ->
533- Client.VDI. destroy ~rpc ~session_id ~self: vdi)
534- end
535- )
475+ let metadata_vdis = List. filter
476+ (fun vdi ->
477+ Db.VDI. get_type ~__context ~self: vdi = `metadata &&
478+ (Db.VDI. get_metadata_of_pool ~__context ~self: vdi = Helpers. get_pool ~__context))
479+ (Db.SR. get_VDIs ~__context ~self: sr)
480+ in
481+ List. iter
482+ (fun vdi -> Xapi_vdi_helpers. disable_database_replication ~__context ~vdi )
483+ metadata_vdis
536484
537485let create_new_blob ~__context ~sr ~name ~mime_type =
538486 let blob = Xapi_blob. create ~__context ~mime_type in
0 commit comments