[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen stable-4.4] oxenstored: move functions that process simple operations
commit 5c1d22f7d759af6b76aabf485c4df6b816e2823a Author: Jonathan Davies <jonathan.davies@xxxxxxxxxx> AuthorDate: Thu Mar 23 17:53:03 2017 +0000 Commit: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> CommitDate: Wed Apr 5 15:26:37 2017 +0100 oxenstored: move functions that process simple operations Separate the functions which process operations that can be done as part of a transaction. Specifically, these operations are: read, write, rm, getperms, setperms, getdomainpath, directory, mkdir. Also split function_of_type into two functions: one for processing the simple operations and one for processing the rest. This will help allow replay of transactions, allowing us to invoke the functions that process the simple operations as part of the processing of transaction_end. Signed-off-by: Jonathan Davies <jonathan.davies@xxxxxxxxxx> Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Reviewed-by: Jon Ludlam <jonathan.ludlam@xxxxxxxxxx> Reviewed-by: Euan Harris <euan.harris@xxxxxxxxxx> Acked-by: David Scott <dave@xxxxxxxxxx> Backporting to 4.5: - Removed references to Reset_watches, which was introduced in 4.6. Reported-by: Juergen Gross <jgross@xxxxxxxx> Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx> --- tools/ocaml/xenstored/process.ml | 220 +++++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 101 deletions(-) diff --git a/tools/ocaml/xenstored/process.ml b/tools/ocaml/xenstored/process.ml index 34fb66c..77660bd 100644 --- a/tools/ocaml/xenstored/process.ml +++ b/tools/ocaml/xenstored/process.ml @@ -119,94 +119,6 @@ let do_getperms con t domains cons data = let perms = Transaction.getperms t (Connection.get_perm con) path in Perms.Node.to_string perms ^ "\000" -let do_watch con t domains cons data = - let (node, token) = - match (split None '\000' data) with - | [node; token; ""] -> node, token - | _ -> raise Invalid_Cmd_Args - in - let watch = Connections.add_watch cons con node token in - Packet.Ack (fun () -> Connection.fire_single_watch watch) - -let do_unwatch con t domains cons data = - let (node, token) = - match (split None '\000' data) with - | [node; token; ""] -> node, token - | _ -> raise Invalid_Cmd_Args - in - Connections.del_watch cons con node token - -let do_transaction_start con t domains cons data = - if Transaction.get_id t <> Transaction.none then - raise Transaction_nested; - let store = Transaction.get_store t in - string_of_int (Connection.start_transaction con store) ^ "\000" - -let do_transaction_end con t domains cons data = - let commit = - match (split None '\000' data) with - | "T" :: _ -> true - | "F" :: _ -> false - | x :: _ -> raise (Invalid_argument x) - | _ -> raise Invalid_Cmd_Args - in - let success = - Connection.end_transaction con (Transaction.get_id t) commit in - if not success then - raise Transaction_again; - if commit then - process_watch (List.rev (Transaction.get_paths t)) cons - -let do_introduce con t domains cons data = - if not (Connection.is_dom0 con) - then raise Define.Permission_denied; - let (domid, mfn, port) = - match (split None '\000' data) with - | domid :: mfn :: port :: _ -> - int_of_string domid, Nativeint.of_string mfn, int_of_string port - | _ -> raise Invalid_Cmd_Args; - in - let dom = - if Domains.exist domains domid then - Domains.find domains domid - else try - let ndom = Xenctrl.with_intf (fun xc -> - Domains.create xc domains domid mfn port) in - Connections.add_domain cons ndom; - Connections.fire_spec_watches cons "@introduceDomain"; - ndom - with _ -> raise Invalid_Cmd_Args - in - if (Domain.get_remote_port dom) <> port || (Domain.get_mfn dom) <> mfn then - raise Domain_not_match - -let do_release con t domains cons data = - if not (Connection.is_dom0 con) - then raise Define.Permission_denied; - let domid = - match (split None '\000' data) with - | [domid;""] -> int_of_string domid - | _ -> raise Invalid_Cmd_Args - in - let fire_spec_watches = Domains.exist domains domid in - Domains.del domains domid; - Connections.del_domain cons domid; - if fire_spec_watches - then Connections.fire_spec_watches cons "@releaseDomain" - else raise Invalid_Cmd_Args - -let do_resume con t domains cons data = - if not (Connection.is_dom0 con) - then raise Define.Permission_denied; - let domid = - match (split None '\000' data) with - | domid :: _ -> int_of_string domid - | _ -> raise Invalid_Cmd_Args - in - if Domains.exist domains domid - then Domains.resume domains domid - else raise Invalid_Cmd_Args - let do_getdomainpath con t domains cons data = let domid = match (split None '\000' data) with @@ -314,28 +226,30 @@ let reply_none fct con t doms cons data = (* let the function reply *) fct con t doms cons data -let function_of_type ty = +(* Functions for 'simple' operations that cannot be part of a transaction *) +let function_of_type_simple_op ty = match ty with - | Xenbus.Xb.Op.Debug -> reply_data_or_ack do_debug + | Xenbus.Xb.Op.Debug + | Xenbus.Xb.Op.Watch + | Xenbus.Xb.Op.Unwatch + | Xenbus.Xb.Op.Transaction_start + | Xenbus.Xb.Op.Transaction_end + | Xenbus.Xb.Op.Introduce + | Xenbus.Xb.Op.Release + | Xenbus.Xb.Op.Isintroduced + | Xenbus.Xb.Op.Resume + | Xenbus.Xb.Op.Set_target + | Xenbus.Xb.Op.Restrict + | Xenbus.Xb.Op.Invalid -> error "called function_of_type_simple_op on operation %s" (Xenbus.Xb.Op.to_string ty); + raise (Invalid_argument (Xenbus.Xb.Op.to_string ty)) | Xenbus.Xb.Op.Directory -> reply_data do_directory | Xenbus.Xb.Op.Read -> reply_data do_read | Xenbus.Xb.Op.Getperms -> reply_data do_getperms - | Xenbus.Xb.Op.Watch -> reply_none do_watch - | Xenbus.Xb.Op.Unwatch -> reply_ack do_unwatch - | Xenbus.Xb.Op.Transaction_start -> reply_data do_transaction_start - | Xenbus.Xb.Op.Transaction_end -> reply_ack do_transaction_end - | Xenbus.Xb.Op.Introduce -> reply_ack do_introduce - | Xenbus.Xb.Op.Release -> reply_ack do_release | Xenbus.Xb.Op.Getdomainpath -> reply_data do_getdomainpath | Xenbus.Xb.Op.Write -> reply_ack do_write | Xenbus.Xb.Op.Mkdir -> reply_ack do_mkdir | Xenbus.Xb.Op.Rm -> reply_ack do_rm | Xenbus.Xb.Op.Setperms -> reply_ack do_setperms - | Xenbus.Xb.Op.Isintroduced -> reply_data do_isintroduced - | Xenbus.Xb.Op.Resume -> reply_ack do_resume - | Xenbus.Xb.Op.Set_target -> reply_ack do_set_target - | Xenbus.Xb.Op.Restrict -> reply_ack do_restrict - | Xenbus.Xb.Op.Invalid -> reply_ack do_error | _ -> reply_ack do_error let input_handle_error ~cons ~doms ~fct ~con ~t ~req = @@ -361,6 +275,110 @@ let input_handle_error ~cons ~doms ~fct ~con ~t ~req = | (Failure "int_of_string") -> reply_error "EINVAL" | Define.Unknown_operation -> reply_error "ENOSYS" +let do_watch con t domains cons data = + let (node, token) = + match (split None '\000' data) with + | [node; token; ""] -> node, token + | _ -> raise Invalid_Cmd_Args + in + let watch = Connections.add_watch cons con node token in + Packet.Ack (fun () -> Connection.fire_single_watch watch) + +let do_unwatch con t domains cons data = + let (node, token) = + match (split None '\000' data) with + | [node; token; ""] -> node, token + | _ -> raise Invalid_Cmd_Args + in + Connections.del_watch cons con node token + +let do_transaction_start con t domains cons data = + if Transaction.get_id t <> Transaction.none then + raise Transaction_nested; + let store = Transaction.get_store t in + string_of_int (Connection.start_transaction con store) ^ "\000" + +let do_transaction_end con t domains cons data = + let commit = + match (split None '\000' data) with + | "T" :: _ -> true + | "F" :: _ -> false + | x :: _ -> raise (Invalid_argument x) + | _ -> raise Invalid_Cmd_Args + in + let success = + Connection.end_transaction con (Transaction.get_id t) commit in + if not success then + raise Transaction_again; + if commit then + process_watch (List.rev (Transaction.get_paths t)) cons + +let do_introduce con t domains cons data = + if not (Connection.is_dom0 con) + then raise Define.Permission_denied; + let (domid, mfn, port) = + match (split None '\000' data) with + | domid :: mfn :: port :: _ -> + int_of_string domid, Nativeint.of_string mfn, int_of_string port + | _ -> raise Invalid_Cmd_Args; + in + let dom = + if Domains.exist domains domid then + Domains.find domains domid + else try + let ndom = Xenctrl.with_intf (fun xc -> + Domains.create xc domains domid mfn port) in + Connections.add_domain cons ndom; + Connections.fire_spec_watches cons "@introduceDomain"; + ndom + with _ -> raise Invalid_Cmd_Args + in + if (Domain.get_remote_port dom) <> port || (Domain.get_mfn dom) <> mfn then + raise Domain_not_match + +let do_release con t domains cons data = + if not (Connection.is_dom0 con) + then raise Define.Permission_denied; + let domid = + match (split None '\000' data) with + | [domid;""] -> int_of_string domid + | _ -> raise Invalid_Cmd_Args + in + let fire_spec_watches = Domains.exist domains domid in + Domains.del domains domid; + Connections.del_domain cons domid; + if fire_spec_watches + then Connections.fire_spec_watches cons "@releaseDomain" + else raise Invalid_Cmd_Args + +let do_resume con t domains cons data = + if not (Connection.is_dom0 con) + then raise Define.Permission_denied; + let domid = + match (split None '\000' data) with + | domid :: _ -> int_of_string domid + | _ -> raise Invalid_Cmd_Args + in + if Domains.exist domains domid + then Domains.resume domains domid + else raise Invalid_Cmd_Args + +let function_of_type ty = + match ty with + | Xenbus.Xb.Op.Debug -> reply_data_or_ack do_debug + | Xenbus.Xb.Op.Watch -> reply_none do_watch + | Xenbus.Xb.Op.Unwatch -> reply_ack do_unwatch + | Xenbus.Xb.Op.Transaction_start -> reply_data do_transaction_start + | Xenbus.Xb.Op.Transaction_end -> reply_ack do_transaction_end + | Xenbus.Xb.Op.Introduce -> reply_ack do_introduce + | Xenbus.Xb.Op.Release -> reply_ack do_release + | Xenbus.Xb.Op.Isintroduced -> reply_data do_isintroduced + | Xenbus.Xb.Op.Resume -> reply_ack do_resume + | Xenbus.Xb.Op.Set_target -> reply_ack do_set_target + | Xenbus.Xb.Op.Restrict -> reply_ack do_restrict + | Xenbus.Xb.Op.Invalid -> reply_ack do_error + | _ -> function_of_type_simple_op ty + (** * Nothrow guarantee. *) -- generated by git-patchbot for /home/xen/git/xen.git#stable-4.4 _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |