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

[Xen-API] [PATCH 4 of 8] [CA-39589] Refactoring: extracts out the "handl

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH 4 of 8] [CA-39589] Refactoring: extracts out the "handle_death" function from a deeply nested block
From: Jonathan Knowles <jonathan.knowles@xxxxxxxxxxxxx>
Date: Mon, 29 Mar 2010 11:53:43 +0100
Delivery-date: Mon, 29 Mar 2010 03:55:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1269860019@radon>
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>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Jonathan Knowles <jonathan.knowles@xxxxxxxxxxxxx>
# Date 1269859682 -3600
# Node ID af259cf5d310d9f44cc7380de6ed5117ab7c38fa
# Parent  72d353d9ebe73fe82bcec06ea283a0fefdcba512
[CA-39589] Refactoring: extracts out the "handle_death" function from a deeply 
nested block.

Signed-off-by: Jonathan Knowles <jonathan.knowles@xxxxxxxxxxxxx>
Acked-by: Marcus Granado <Marcus.Granado@xxxxxxxxxxxxx>

diff -r 72d353d9ebe7 -r af259cf5d310 ocaml/xapi/vmops.ml
--- a/ocaml/xapi/vmops.ml       Mon Mar 29 11:48:01 2010 +0100
+++ b/ocaml/xapi/vmops.ml       Mon Mar 29 11:48:02 2010 +0100
@@ -900,6 +900,18 @@
        let max = Int64.to_int (Int64.div max 1024L) in
        let suspend_SR = Helpers.choose_suspend_sr ~__context ~vm in
        let required_space = get_suspend_space __context vm in
+       let handle_death = function
+               | Xal.Suspended ->
+                       () (* good *)
+               | Xal.Crashed ->
+                       raise (Api_errors.Server_error(Api_errors.vm_crashed, [ 
Ref.string_of vm ]))
+               | Xal.Rebooted ->
+                       raise (Api_errors.Server_error(Api_errors.vm_rebooted, 
[ Ref.string_of vm ]))
+               | Xal.Halted | Xal.Vanished ->
+                       raise (Api_errors.Server_error(Api_errors.vm_halted, [ 
Ref.string_of vm ]))
+               | Xal.Shutdown x ->
+                       failwith (Printf.sprintf "Expected domain shutdown 
reason: %d" x)
+       in
        Xapi_xenops_errors.handle_xenops_error
                (fun () ->
                        with_xc_and_xs
@@ -933,19 +945,9 @@
                                                                                
                Domain.suspend ~xc ~xs ~hvm domid fd []
                                                                                
                        ~progress_callback:progress_cb
                                                                                
                        (fun () ->
-                                                                               
                                match clean_shutdown_with_reason ~xal
+                                                                               
                                handle_death (clean_shutdown_with_reason ~xal
                                                                                
                                        ~__context ~self:vm domid
-                                                                               
                                        Domain.Suspend with
-                                                                               
                                        | Xal.Suspended -> () (* good *)
-                                                                               
                                        | Xal.Crashed ->
-                                                                               
                                                raise 
(Api_errors.Server_error(Api_errors.vm_crashed, [ Ref.string_of vm ]))
-                                                                               
                                        | Xal.Rebooted ->
-                                                                               
                                                raise 
(Api_errors.Server_error(Api_errors.vm_rebooted, [ Ref.string_of vm ]))
-                                                                               
                                        | Xal.Halted
-                                                                               
                                        | Xal.Vanished ->
-                                                                               
                                                raise 
(Api_errors.Server_error(Api_errors.vm_halted, [ Ref.string_of vm ]))
-                                                                               
                                        | Xal.Shutdown x ->
-                                                                               
                                                failwith (Printf.sprintf 
"Expected domain shutdown reason: %d" x)));
+                                                                               
                                        Domain.Suspend)));
                                                                                
(* If the suspend succeeds, set the suspend_VDI *)
                                                                                
Db.VM.set_suspend_VDI ~__context ~self:vm ~value:vdi_ref;)
                                                                        (fun () 
-> Unix.close fd);
1 file changed, 14 insertions(+), 12 deletions(-)
ocaml/xapi/vmops.ml |   26 ++++++++++++++------------


Attachment: xen-api.hg-8.patch
Description: Text Data

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