@@ -253,58 +253,63 @@ module VolumeManager = struct
253253 let toLVM = toLVM name in
254254 let fromLVM = fromLVM name in
255255 let freeLVM = freeLVM name in
256- ( try
257- Lwt. return (Lvm.Vg.LVs. find_by_name freeLVM (Vg_IO. metadata_of vg).Lvm.Vg. lvs).Lvm.Lv. id
258- with _ ->
259- fail Xenvm_interface. HostNotCreated ) >> = fun freeLVMid ->
260- ( match Vg_IO. find vg toLVM with
261- | Some lv -> return lv
262- | None -> assert false ) >> = fun v ->
263- Vg_IO.Volume. connect v
264- >> = function
265- | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" toLVM))
266- | `Ok disk ->
267- ToLVM. attach ~name ~disk ()
268- >> = fun to_LVM ->
269- ToLVM. state to_LVM
270- >> = fun state ->
271- debug " ToLVM queue is currently %s" (match state with `Running -> " Running" | `Suspended -> " Suspended" );
272- ToLVM. resume to_LVM
273- >> = fun () ->
274- ( match Vg_IO. find vg fromLVM with
275- | Some lv -> return lv
276- | None -> assert false ) >> = fun v ->
277- Vg_IO.Volume. connect v
278- >> = function
279- | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" fromLVM))
280- | `Ok disk ->
281- FromLVM. attach ~name ~disk ()
282- >> = fun (initial_state , from_LVM ) ->
283- ( if initial_state = `Suspended then begin
284- debug " The FromLVM queue was already suspended: resending the free blocks" ;
285- ( match Vg_IO. find vg freeLVM with
286- | Some lv -> return lv
287- | None -> assert false ) >> = fun lv ->
288- let allocation = Lvm.Lv. to_allocation (Vg_IO.Volume. metadata_of lv) in
289- FromLVM. push from_LVM allocation
290- >> = fun pos ->
291- FromLVM. advance from_LVM pos
292- >> = fun () ->
293- debug " Free blocks pushed" ;
256+ if List. mem_assoc name ! to_LVMs then begin
257+ info " Host-specific volumes (%s, %s, %s) already connected" toLVM fromLVM freeLVM;
294258 return ()
295259 end else begin
296- debug " The FromLVM queue was running: no need to resend the free blocks" ;
260+ ( try
261+ Lwt. return (Lvm.Vg.LVs. find_by_name freeLVM (Vg_IO. metadata_of vg).Lvm.Vg. lvs).Lvm.Lv. id
262+ with _ ->
263+ fail Xenvm_interface. HostNotCreated ) >> = fun freeLVMid ->
264+ ( match Vg_IO. find vg toLVM with
265+ | Some lv -> return lv
266+ | None -> assert false ) >> = fun v ->
267+ Vg_IO.Volume. connect v
268+ >> = function
269+ | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" toLVM))
270+ | `Ok disk ->
271+ ToLVM. attach ~name ~disk ()
272+ >> = fun to_LVM ->
273+ ToLVM. state to_LVM
274+ >> = fun state ->
275+ debug " ToLVM queue is currently %s" (match state with `Running -> " Running" | `Suspended -> " Suspended" );
276+ ToLVM. resume to_LVM
277+ >> = fun () ->
278+ ( match Vg_IO. find vg fromLVM with
279+ | Some lv -> return lv
280+ | None -> assert false ) >> = fun v ->
281+ Vg_IO.Volume. connect v
282+ >> = function
283+ | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" fromLVM))
284+ | `Ok disk ->
285+ FromLVM. attach ~name ~disk ()
286+ >> = fun (initial_state , from_LVM ) ->
287+ ( if initial_state = `Suspended then begin
288+ debug " The FromLVM queue was already suspended: resending the free blocks" ;
289+ ( match Vg_IO. find vg freeLVM with
290+ | Some lv -> return lv
291+ | None -> assert false ) >> = fun lv ->
292+ let allocation = Lvm.Lv. to_allocation (Vg_IO.Volume. metadata_of lv) in
293+ FromLVM. push from_LVM allocation
294+ >> = fun pos ->
295+ FromLVM. advance from_LVM pos
296+ >> = fun () ->
297+ debug " Free blocks pushed" ;
298+ return ()
299+ end else begin
300+ debug " The FromLVM queue was running: no need to resend the free blocks" ;
301+ return ()
302+ end )
303+ >> = fun () ->
304+ debug " querying state" ;
305+ FromLVM. state from_LVM
306+ >> = fun state ->
307+ debug " FromLVM queue is currently %s" (match state with `Running -> " Running" | `Suspended -> " Suspended" );
308+ to_LVMs := (name, to_LVM) :: ! to_LVMs;
309+ from_LVMs := (name, from_LVM) :: ! from_LVMs;
310+ free_LVs := (name, (freeLVM,freeLVMid)) :: ! free_LVs;
297311 return ()
298- end )
299- >> = fun () ->
300- debug " querying state" ;
301- FromLVM. state from_LVM
302- >> = fun state ->
303- debug " FromLVM queue is currently %s" (match state with `Running -> " Running" | `Suspended -> " Suspended" );
304- to_LVMs := (name, to_LVM) :: ! to_LVMs;
305- from_LVMs := (name, from_LVM) :: ! from_LVMs;
306- free_LVs := (name, (freeLVM,freeLVMid)) :: ! free_LVs;
307- return ()
312+ end
308313
309314 (* Hold this mutex when actively flushing from the ToLVM queues *)
310315 let flush_m = Lwt_mutex. create ()
0 commit comments