From 20b37c422017e56a3cd441b43193dbd30fbb63da Mon Sep 17 00:00:00 2001 From: Marcus Granado Date: Tue, 12 Oct 2010 10:41:58 +0100 Subject: [PATCH] CP-1833: fix check for lsu vmpr during snapshot in slaves Signed-off-by: Marcus Granado --- ocaml/xapi/xapi_session.ml | 22 ++++++++++++++++++++++ ocaml/xapi/xapi_session.mli | 1 + ocaml/xapi/xapi_vm_clone.ml | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ocaml/xapi/xapi_session.ml b/ocaml/xapi/xapi_session.ml index f1479e5f..b69f2dc9 100644 --- a/ocaml/xapi/xapi_session.ml +++ b/ocaml/xapi/xapi_session.ml @@ -691,3 +691,25 @@ let logout_subject_identifier ~__context ~subject_identifier= (* kill all filtered sessions *) List.iter (fun s -> destroy_db_session ~__context ~self:s) sessions + +(* returns the ancestry chain of session s, starting with s *) +let rec get_ancestry ~__context ~self = + if (self=Ref.null) then [] (* top of session tree *) + else ( + let parent = + try Db.Session.get_parent ~__context ~self + with e-> + debug "error %s getting ancestry for session %s" + (ExnHelper.string_of_exn e) (trackid self) + ; + Ref.null + in + self::(get_ancestry ~__context ~self:parent) + ) + +(* returns the original session up the ancestry chain that created s *) +let get_top ~__context ~self = + let ancestry = get_ancestry ~__context ~self in + match ancestry with + | [] -> Ref.null + | ancestry -> List.nth ancestry ((List.length ancestry)-1) diff --git a/ocaml/xapi/xapi_session.mli b/ocaml/xapi/xapi_session.mli index 32f2cfb6..70f598c2 100644 --- a/ocaml/xapi/xapi_session.mli +++ b/ocaml/xapi/xapi_session.mli @@ -34,3 +34,4 @@ val local_logout: __context:Context.t -> unit val get_group_subject_identifier_from_session: __context:Context.t -> session:[ `session ] Ref.t -> string val get_all_subject_identifiers: __context:Context.t -> string list val logout_subject_identifier: __context:Context.t -> subject_identifier:string -> unit +val get_top: __context:Context.t -> self:API.ref_session -> API.ref_session diff --git a/ocaml/xapi/xapi_vm_clone.ml b/ocaml/xapi/xapi_vm_clone.ml index 04577366..c2a287fa 100644 --- a/ocaml/xapi/xapi_vm_clone.ml +++ b/ocaml/xapi/xapi_vm_clone.ml @@ -251,7 +251,7 @@ let copy_vm_record ~__context ~vm ~disk_op ~new_name ~new_power_state = let is_snapshot_from_vmpp = (try is_a_snapshot && - (let session = Context.get_session_id __context in + (let session = Xapi_session.get_top ~__context ~self:(Context.get_session_id __context) in let uname = Db.Session.get_auth_user_name ~__context ~self:session in let is_lsu = Db.Session.get_is_local_superuser ~__context ~self:session in is_lsu && (uname = Xapi_vmpp.vmpr_username) -- 2.39.5