I have the need to modify suspend() in domain.ml to add the
ability to abort a migration thread that may be waiting on output from
xenguest. I’ve accomplished this by writing the following code in
lines 720-723
717 |
let cnx = XenguestHelper.connect xenguestargs [ fd ] in
718 |
719
| (* Spawn a thread to monitor an
abort request *)
720 |
if monitor then (
721
| let tid =
start_migration_watcher_thread ~xs domid cnx in
722
|
monitor_thread_started := true;
723
| );
And modified the finally clause of 781-784
781 |
) (fun () -> XenguestHelper.disconnect cnx;
782
|
if monitor && !monitor_thread_started then (
783
|
Thread.kill tid
784
|
);
The main routine will look something like this.
658 |let start_migration_watcher_thread ~xs domid cnx
=
659 |
660 | let timeout = 300. in
661 |
662 | let migration_path =
xs.Xs.getdomainpath domid ^ "/migration" in
663 |
664 | (* Thread stays in a while
loop monitoring the migration abort key.
665 | *)
666 | let migration_watcher_thread
() =
667 | name_thread
"migration monitor";
668 |
669 | let
abort_path = migration_path ^ "/abort" in
670 | debug
"Migration monitoring enabled on path: %s" abort_path;
671 |
672 | let quit =
ref false in
673 | while not
!quit do
674
| begin
675
| try
676
|
Watch.wait_for ~xs ~timeout:timeout ( Watch.value_to_become abort_path
"1" );
677
|
let value = try xs.Xs.read abort_path with _ -> "" in
678
|
debug "Value of %s is now: %s" abort_path value;
679
|
XenguestHelper.disconnect cnx;
680
|
quit := true
681
| with
Watch.Timeout _ ->
682
|
debug "Time out has occurred" ;
683
| end
684 | done;
685 |
686 | debug
"migration watcher thread for domid: %d dying" domid;
687 | in
688 |
689 | let monthread = Thread.create
migration_watcher_thread () in
690 | monthread
The problem I have is with the OCAML compiler. It
finds that the variable “tid” to have an unbound value because of
the IF statement of line 720 that surrounds the code that creates the
thread. It will compile find if I take out the IF, but I don’t want
to do that because I only want to enable monitoring on a per-VM
basis. How do I go about accomplishing the simple task of spawning
a thread SOMETIMES and have tell the compiler that I know what I’m doing
that variable will never be unbound??
221730 |+ ocamlfind ocamlopt -package
"threads,bigarray,stdext,log,threads,uuid,mmap,xc,xb,xs" -g -dtypes
-thread -warn-error F -thread -ccopt -fPIC -I . -I +ocamldoc -I
../../ocaml/util -I ../netdev -I ../idl -c domain.ml
221731 |File "domain.ml", line 721, characters
8-11:
221732 |Warning Y: unused variable tid.
221733 |File "domain.ml", line 783, characters
37-40:
221734 |Error: Unbound value tid
221735 |*** omake: 375/2710 targets are up to date
221736 |*** omake: failed (4.7 sec, 33/45 scans, 31/97 rules,
505/1419 digests)
221737 |*** omake: targets were not rebuilt because of
errors:
221738 | ocaml/xenops/domain.o
221739 | depends on:
ocaml/xenops/domain.ml