]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
allow some operations (help, get-*) to be done without any xc and xs interfaces avail...
authorVincent Hanquez <vincent.hanquez@eu.citrix.com>
Mon, 20 Jul 2009 10:59:28 +0000 (11:59 +0100)
committerVincent Hanquez <vincent.hanquez@eu.citrix.com>
Mon, 20 Jul 2009 10:59:28 +0000 (11:59 +0100)
also fix leak of xc and xs interfaces at every commands.

xenvm/xenvm.ml

index 27033b3990a58d37615bf24fb0a2712e9eb33148..200b4dfe83f2f7e4eb731eaf902de788982d13ae 100644 (file)
@@ -393,9 +393,6 @@ let reread_config state path =
        state.vm_next_cfg <- Some cfg
 
 let do_task quit state (task, args) =
-       let xs = Xs.daemon_open () in
-       let xc = Xc.interface_open () in
-
        let task_desc = List.assoc task Tasks.actions_table in
        (*maybe assert_vmstate task_vmstate_required;*)
        match task with
@@ -403,38 +400,45 @@ let do_task quit state (task, args) =
                quit := true; Xenvmlib.Ok
        | Tasks.Help ->
                do_help ();
-       | Tasks.Destroy -> Vmact.stop_vm xc xs state; Xenvmlib.Ok
+       | Tasks.Destroy -> with_xcs (fun xc xs -> Vmact.stop_vm xc xs state); Xenvmlib.Ok
        | Tasks.Halt ->
                let force = Tasks.args_get_bool args "forced" in
-               Misc.with_xal (fun xal -> Vmact.shutdown_vm xc xs xal state force Domain.Halt);
-               Vmact.stop_vm xc xs state;
+               with_xcs (fun xc xs ->
+                       Misc.with_xal (fun xal -> Vmact.shutdown_vm xc xs xal state force Domain.Halt);
+                       Vmact.stop_vm xc xs state;
+               );
                Xenvmlib.Ok
        | Tasks.Reboot ->
                let force = Tasks.args_get_bool args "forced" in
-               Misc.with_xal (fun xal -> Vmact.shutdown_vm xc xs xal state force Domain.Reboot);
-               Vmact.stop_vm xc xs state;
-               Vmact.start_vm xc xs state;
+               with_xcs (fun xc xs ->
+                       Misc.with_xal (fun xal -> Vmact.shutdown_vm xc xs xal state force Domain.Reboot);
+                       Vmact.stop_vm xc xs state;
+                       Vmact.start_vm xc xs state;
+               );
                Xenvmlib.Ok
-       | Tasks.Start -> Vmact.start_vm xc xs state; Xenvmlib.Ok
-       | Tasks.Pause -> Vmact.pause_vm xc state; Xenvmlib.Ok
-       | Tasks.Unpause -> Vmact.unpause_vm xc state; Xenvmlib.Ok
+       | Tasks.Start -> with_xcs (fun xc xs -> Vmact.start_vm xc xs state); Xenvmlib.Ok
+       | Tasks.Pause -> with_xc (fun xc -> Vmact.pause_vm xc state); Xenvmlib.Ok
+       | Tasks.Unpause -> with_xc (fun xc -> Vmact.unpause_vm xc state); Xenvmlib.Ok
        | Tasks.Suspend ->
                let file = Tasks.args_get_string args "file" in
                let live = Tasks.args_get_bool args "live" in
                state.vm_on_suspend_action <- ActionSuspend;
-               Vmact.suspend xc xs state (if live then [ Domain.Live ] else []) (with_datadir state.vm_cfg file);
-               Vmact.stop_vm xc xs state;
+               with_xcs (fun xc xs ->
+                       Vmact.suspend xc xs state (if live then [ Domain.Live ] else [])
+                                                 (with_datadir state.vm_cfg file);
+                       Vmact.stop_vm xc xs state;
+               );
                Xenvmlib.Ok
        | Tasks.Restore ->
                let file = Tasks.args_get_string args "file" in
                let delete = Tasks.args_get_bool args "delete" in
                Vmact.change_vmstate state VmRestoring;
-               Vmact.restore xc xs state delete (with_datadir state.vm_cfg file);
+               with_xcs (fun xc xs -> Vmact.restore xc xs state delete (with_datadir state.vm_cfg file));
                Xenvmlib.Ok
        | Tasks.Checkpoint ->
                let file = Tasks.args_get_string args "file" in
                state.vm_on_suspend_action <- ActionResume;
-               Vmact.suspend xc xs state [] (with_datadir state.vm_cfg file);
+               with_xcs (fun xc xs -> Vmact.suspend xc xs state [] (with_datadir state.vm_cfg file));
                Xenvmlib.Ok
        | Tasks.GetDomid -> Xenvmlib.Msg (string_of_int state.vm_domid)
        | Tasks.GetStatus -> Xenvmlib.Msg (string_of_vmlifestate state.vm_lifestate)
@@ -448,12 +452,12 @@ let do_task quit state (task, args) =
                Vmact.set state field value
        | Tasks.Trigger ->
                let params = Tasks.args_get_liststring args "params" in
-               Vmact.do_trigger xc state params
+               with_xc (fun xc -> Vmact.do_trigger xc state params)
        | Tasks.Device ->
                let ty = Tasks.args_get_string args "type" in
                let cmd = Tasks.args_get_string args "cmd" in
                let extra = Tasks.args_get_liststring args "extra" in
-               Vmact.device_cmd xc xs state ty cmd extra
+               with_xcs (fun xc xs -> Vmact.device_cmd xc xs state ty cmd extra)
        | Tasks.ReadConfig ->
                let path =
                        try Some (Tasks.args_get_string args "path")