mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
oxenstored: refactor request processing
Encapsulate the request in a record that is passed from do_input to process_packet and input_handle_error. This will be helpful when keeping track of the requests made as part of a transaction. Signed-off-by: Jonathan Davies <jonathan.davies@citrix.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Reviewed-by: Jon Ludlam <jonathan.ludlam@citrix.com> Reviewed-by: Euan Harris <euan.harris@citrix.com> Acked-by: David Scott <dave@recoil.org>
This commit is contained in:
1 parent
f8ec0bc652
commit
363ae55c8a
2 files changed
+17
-5
No files matched your search
@@ -1,3 +1,10 @@
|
||||
type request = {
|
||||
tid: int;
|
||||
rid: int;
|
||||
ty: Xenbus.Xb.Op.operation;
|
||||
data: string;
|
||||
}
|
||||
|
||||
type response =
|
||||
| Ack of (unit -> unit) (* function is the action to execute after sending the ack *)
|
||||
| Reply of string
|
||||
|
||||
@@ -344,11 +344,11 @@ let function_of_type ty =
|
||||
| Xenbus.Xb.Op.Invalid -> reply_ack do_error
|
||||
| _ -> reply_ack do_error
|
||||
|
||||
let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data =
|
||||
let input_handle_error ~cons ~doms ~fct ~con ~t ~req =
|
||||
let reply_error e =
|
||||
Packet.Error e in
|
||||
try
|
||||
fct con t doms cons data
|
||||
fct con t doms cons req.Packet.data
|
||||
with
|
||||
| Define.Invalid_path -> reply_error "EINVAL"
|
||||
| Define.Already_exist -> reply_error "EEXIST"
|
||||
@@ -370,7 +370,10 @@ let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data =
|
||||
(**
|
||||
* Nothrow guarantee.
|
||||
*)
|
||||
let process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data =
|
||||
let process_packet ~store ~cons ~doms ~con ~req =
|
||||
let ty = req.Packet.ty in
|
||||
let tid = req.Packet.tid in
|
||||
let rid = req.Packet.rid in
|
||||
try
|
||||
let fct = function_of_type ty in
|
||||
let t =
|
||||
@@ -379,7 +382,7 @@ let process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data =
|
||||
else
|
||||
Connection.get_transaction con tid
|
||||
in
|
||||
let response = input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data in
|
||||
let response = input_handle_error ~cons ~doms ~fct ~con ~t ~req in
|
||||
|
||||
(* Put the response on the wire *)
|
||||
send_response ty con t rid response
|
||||
@@ -412,11 +415,13 @@ let do_input store cons doms con =
|
||||
if newpacket then (
|
||||
let packet = Connection.pop_in con in
|
||||
let tid, rid, ty, data = Xenbus.Xb.Packet.unpack packet in
|
||||
let req = {Packet.tid; Packet.rid; Packet.ty; Packet.data} in
|
||||
|
||||
(* As we don't log IO, do not call an unnecessary sanitize_data
|
||||
info "[%s] -> [%d] %s \"%s\""
|
||||
(Connection.get_domstr con) tid
|
||||
(Xenbus.Xb.Op.to_string ty) (sanitize_data data); *)
|
||||
process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data;
|
||||
process_packet ~store ~cons ~doms ~con ~req;
|
||||
write_access_log ~ty ~tid ~con ~data;
|
||||
Connection.incr_ops con;
|
||||
)
|
||||
|
||||