Skip to content

Commit a259705

Browse files
author
Jon Ludlam
committed
Merge pull request #135 from simonjbeaumont/force-disconnect
Add uncooperative disconnect
2 parents fded046 + 92056e3 commit a259705

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

cleanup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ if [ "$USE_MOCK" -eq "0" ]; then
2222
losetup -d $LOOP
2323
fi
2424

25-
rm -f localJournal bigdisk *.out* djstest-* dm-mock
25+
rm -f localJournal bigdisk *.out* djstest-* dm-mock xenvmd.log*

idl/xenvm_interface.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module Host = struct
6969
(** [connect host] connects to existing metadata volumes and
7070
process them. *)
7171

72-
external disconnect: name:string -> unit = ""
72+
external disconnect: cooperative:bool -> name:string -> unit = ""
7373
(** [disconnect host] disconnects from metadata volumes and
7474
stops processing them. *)
7575

setup.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,21 @@ kill `cat /tmp/xenvmd.lock`
7676
sleep 10
7777
./xenvm.native host-list /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG | sort > host-list.out2
7878
diff -u host-list.out host-list.out2
79-
79+
80+
# simulate a host failure and uncooperative disconnect
81+
kill `cat /tmp/host2-socket.lock`
82+
./xenvm.native host-disconnect --uncooperative /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
83+
# check we've lost a host in the host-list
84+
./xenvm.native host-list /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG | sort > host-list.out3
85+
grep -v host2 host-list.out2 | diff -u - host-list.out3
86+
# check it doesn't reconnect after a restart
87+
kill `cat /tmp/xenvmd.lock`
88+
./xenvmd.native --config ./test.xenvmd.conf > xenvmd.log.3 &
89+
sleep 10
90+
./xenvm.native host-list /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG | sort > host-list.out4
91+
diff -u host-list.out3 host-list.out4
92+
8093
# destroy hosts
81-
./xenvm.native host-disconnect /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
8294
./xenvm.native host-destroy /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
8395
./xenvm.native host-disconnect /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
8496
./xenvm.native host-destroy /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG

xenvm/xenvm.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ let host_connect copts (vg_name,_) host =
9191
set_uri copts info;
9292
Client.Host.connect host in
9393
Lwt_main.run t
94-
let host_disconnect copts (vg_name,_) host =
94+
let host_disconnect copts (vg_name,_) uncooperative host =
9595
let t =
9696
get_vg_info_t copts vg_name >>= fun info ->
9797
set_uri copts info;
98-
Client.Host.disconnect host in
98+
Client.Host.disconnect ~cooperative:(not uncooperative) ~name:host in
9999
Lwt_main.run t
100100
let host_destroy copts (vg_name,_) host =
101101
let t =
@@ -232,12 +232,15 @@ let host_connect_cmd =
232232
Term.info "host-connect" ~sdocs:copts_sect ~doc ~man
233233

234234
let host_disconnect_cmd =
235-
let doc = "Disconnect to a host" in
235+
let uncooperative_flag =
236+
let doc = "Perform an uncooperative disconnect (if the host is dead)" in
237+
Arg.(value & flag & info ["uncooperative"] ~doc) in
238+
let doc = "Disconnect from a host" in
236239
let man = [
237240
`S "DESCRIPTION";
238-
`P "Dergister a host with the daemon. The daemon will suspend the block queues and stop listening to requests.";
241+
`P "Dergister a host with the daemon. The daemon will suspend the block queues (unless the --uncooperative flag is used) and stop listening to requests.";
239242
] in
240-
Term.(pure host_disconnect $ copts_t $ name_arg $ hostname),
243+
Term.(pure host_disconnect $ copts_t $ name_arg $ uncooperative_flag $ hostname),
241244
Term.info "host-disconnect" ~sdocs:copts_sect ~doc ~man
242245

243246
let host_create_cmd =

xenvm/xenvm_common.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ let physical_device_arg_required =
249249
let parse_name name_arg =
250250
let comps = Stringext.split name_arg '/' in
251251
match comps with
252-
| ["";"dev";vg;lv] -> (vg,Some lv)
252+
| ["";"dev";vg;""]
253253
| ["";"dev";vg] -> (vg,None)
254+
| ["";"dev";vg;lv] -> (vg,Some lv)
254255
| [vg;lv] -> (vg,Some lv)
255256
| [vg] -> (vg,None)
256257
| _ -> failwith "failed to parse vg name"

xenvmd/xenvmd.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,20 @@ module VolumeManager = struct
393393
ToLVM.advance to_lvm pos
394394
end
395395

396-
let disconnect name =
396+
let disconnect ~cooperative name =
397397
if Hashtbl.mem host_connections name then begin
398398
match Hashtbl.find host_connections name with
399399
| Xenvm_interface.Connected ->
400400
let to_lvm = List.assoc name !to_LVMs in
401-
debug "Suspending ToLVM queue for %s" name;
402-
ToLVM.suspend to_lvm
403-
>>= fun () ->
401+
( if cooperative then begin
402+
debug "Cooperative disconnect: suspending ToLVM queue for %s" name;
403+
ToLVM.suspend to_lvm
404+
end else return ()
405+
) >>= fun () ->
404406
(* There may still be updates in the ToLVM queue *)
407+
debug "Flushing ToLVM queue for %s" name;
405408
Lwt_mutex.with_lock flush_m (fun () -> flush_already_locked name)
406409
>>= fun () ->
407-
debug "ToLVM queue for %s has been suspended and flushed" name;
408410
to_LVMs := List.filter (fun (n, _) -> n <> name) !to_LVMs;
409411
from_LVMs := List.filter (fun (n, _) -> n <> name) !from_LVMs;
410412
free_LVs := List.filter (fun (n, _) -> n <> name) !free_LVs;
@@ -419,7 +421,7 @@ module VolumeManager = struct
419421
end else return ()
420422

421423
let destroy name =
422-
disconnect name
424+
disconnect ~cooperative:false name
423425
>>= fun () ->
424426
let toLVM = toLVM name in
425427
let fromLVM = fromLVM name in
@@ -487,7 +489,7 @@ module VolumeManager = struct
487489
vg.Lvm.Vg.lvs [] |> Lwt.return
488490
) >>= fun host_states ->
489491
Lwt_list.iter_s (fun (host, was_connected) ->
490-
if was_connected then connect host else disconnect host) host_states
492+
if was_connected then connect host else disconnect ~cooperative:false host) host_states
491493

492494
end
493495

@@ -503,7 +505,7 @@ module VolumeManager = struct
503505
let shutdown () =
504506
Lwt_list.iter_s
505507
(fun (host, _) ->
506-
Host.disconnect host
508+
Host.disconnect ~cooperative:true host
507509
) !from_LVMs
508510
>>= fun () ->
509511
sync ()
@@ -740,7 +742,7 @@ module Impl = struct
740742
module Host = struct
741743
let create context ~name = VolumeManager.Host.create name
742744
let connect context ~name = VolumeManager.Host.connect name
743-
let disconnect context ~name = VolumeManager.Host.disconnect name
745+
let disconnect context ~cooperative ~name = VolumeManager.Host.disconnect ~cooperative name
744746
let destroy context ~name = VolumeManager.Host.destroy name
745747
let all context () = VolumeManager.Host.all ()
746748
end

0 commit comments

Comments
 (0)