[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH] minor bug in patch support



# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1269428813 0
# Node ID 72cd96315c86de4311cbaefbae5967e0b7b55f7a
# Parent  8b359da7c685ed5deac3390d59ba5947e338cdc7
CA-36934: in the API call patch "precheck", if the patch has been downloaded 
from the master then delete the patch afterwards. This makes leaks of patch 
files less likely (although they're going to be rare since there aren't going 
to be many patches)

Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx>

diff -r 8b359da7c685 -r 72cd96315c86 ocaml/xapi/xapi_pool_patch.ml
--- a/ocaml/xapi/xapi_pool_patch.ml     Wed Mar 17 17:57:21 2010 +0000
+++ b/ocaml/xapi/xapi_pool_patch.ml     Wed Mar 24 11:06:53 2010 +0000
@@ -639,14 +639,7 @@
   | Bad_precheck_xml error ->
       raise (Api_errors.Server_error (Api_errors.invalid_patch_with_log, 
[error]))
 
-let precheck ~__context ~self ~host =
-  (* check we're not on oem *)
-  if on_oem ~__context
-    then raise (Api_errors.Server_error 
(Api_errors.not_allowed_on_oem_edition, ["patch-precheck"]));
-
-  (* get the patch from the master (no-op if we're the master) *)
-  get_patch_to_local ~__context ~self;
-
+let run_precheck ~__context ~self ~host =
   let path = Db.Pool_patch.get_filename ~__context ~self in
     match execute_patch path [ "precheck" ] with
       | Success(output, _) -> output
@@ -658,6 +651,25 @@
         let msg = Printf.sprintf "Error running prechecks on patch %s: %s" 
(Ref.string_of self) log in
           debug "%s" msg;
           raise 
(Api_errors.Server_error(Api_errors.patch_precheck_failed_unknown_error, 
[Ref.string_of self; msg]))
+
+(* precheck API call entrypoint *)
+let precheck ~__context ~self ~host =
+  (* check we're not on oem *)
+  if on_oem ~__context
+    then raise (Api_errors.Server_error 
(Api_errors.not_allowed_on_oem_edition, ["patch-precheck"]));
+
+  (* get the patch from the master (no-op if we're the master) *)
+  get_patch_to_local ~__context ~self;
+
+  finally 
+         (fun () -> run_precheck ~__context ~self ~host)
+         (fun () ->
+                  (* This prevents leaking space on the slave if the patch is 
repeatedly uploaded, prechecked and then destroyed *)
+                  if not (Pool_role.is_master ()) then begin              
+                        let path = Db.Pool_patch.get_filename ~__context ~self 
in
+                        Unixext.unlink_safe path;                 
+                  end
+         )
 
 let apply ~__context ~self ~host = 
   (* 0th, check we're not on oem *)
@@ -673,7 +685,7 @@
   
   let path = Db.Pool_patch.get_filename ~__context ~self in
     (* 3rd, run prechecks *)
-    precheck ~__context ~self ~host;
+    run_precheck ~__context ~self ~host;
  
     (* 4th, apply the patch *)
     begin
1 file changed, 21 insertions(+), 9 deletions(-)
ocaml/xapi/xapi_pool_patch.ml |   30 +++++++++++++++++++++---------


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

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.