WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

RE: [Xen-API] Question on how to accomplish a task in OCAML...

To: "Jonathan Ludlam" <Jonathan.Ludlam@xxxxxxxxxxxxx>
Subject: RE: [Xen-API] Question on how to accomplish a task in OCAML...
From: "Roger Cruz" <rcruz@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 5 Feb 2010 16:57:02 -0500
Cc: Xen-api@xxxxxxxxxxxxxxxxxxx
Delivery-date: Fri, 05 Feb 2010 13:57:01 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <693539EC-D8E3-47D6-93ED-AD8560FE2633@xxxxxxxxxxxxx>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
References: <40B551BEDC7945419A5897958AB3947C01D24D5D@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> <693539EC-D8E3-47D6-93ED-AD8560FE2633@xxxxxxxxxxxxx>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcqmraPequIWD74vQUWLpVsNggowHAAAFAug
Thread-topic: [Xen-API] Question on how to accomplish a task in OCAML...

Hi Johnathan,

 

Thanks for your answers.  They were extremely useful.   I’ve just come to learn that the kill piece is not implemented L

 

[20100205 16:53:14.093|debug|p20xen2|418 inet-RPC|Async.VM.pool_migrate R:ef3b7ad472b7|xapi] Sender Caught exception: VM_MIGRATE_FAILED: [ OpaqueRef:decde55c-0224-336a-e26e-b9e5a5bff8a6; OpaqueRef:572a7ac0-cc0c-6dd1-5197-00e9c7efaa1c; OpaqueRef:85613520-3

92e-75fa-da5c-60cb8f4c3691; INTERNAL_ERROR: [ Invalid argument: Thread.kill: not implemented ] ]

 


From: Jonathan Ludlam [mailto:Jonathan.Ludlam@xxxxxxxxxxxxx]
Sent: Friday, February 05, 2010 4:53 PM
To: Roger Cruz
Cc: Xen-api@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Xen-API] Question on how to accomplish a task in OCAML...

 

Hi Roger,

 

To make it parse correctly, you probably want something more like:

 

let tid =

  if monitor then Some (start_migration_watcher_thread ~xs domid cnx) else None

in

 

This wraps up the thread id in an option type - so if the thread isn't required tid will be 'None' otherwise it will be 'Some <id>'

 

Then, later, you'll do something with the value

 

(match tid with

  | Some id ->  ... kill the thread somehow...

  | None -> ())

 

However, you might have to think of another way to kill the thread - Thread.kill is not implemented. A pattern we've used elsewhere is to make a pipe, give the read end to the thread and send a message down it to tell the thread to die.

 

Hope this helps,

 

Jon

 

 

 

On 5 Feb 2010, at 19:11, Roger Cruz wrote:



 

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

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
<Prev in Thread] Current Thread [Next in Thread>