Skip to content

Commit a06203b

Browse files
committed
CP-52708: make file descriptor argument optional in Server.dispatch_call
This will enable short-circuiting internal API calls. When the FD is missing mark the call as Internal. Signed-off-by: Edwin Török <[email protected]>
1 parent 9be7780 commit a06203b

File tree

7 files changed

+12
-13
lines changed

7 files changed

+12
-13
lines changed

ocaml/idl/ocaml_backend/gen_server.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ let gen_module api : O.Module.t =
470470
~params:
471471
[
472472
O.Anon (Some "http_req", "Http.Request.t")
473-
; O.Anon (Some "fd", "Unix.file_descr")
473+
; O.Anon (Some "fd", "Unix.file_descr option")
474474
; O.Anon (Some "call", "Rpc.call")
475475
]
476476
~ty:"response"

ocaml/tests/test_client.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
work in unit tests. *)
1111
let make_client_params ~__context =
1212
let req = Xmlrpc_client.xmlrpc ~version:"1.1" "/" in
13-
let rpc = Api_server.Server.dispatch_call req Unix.stdout in
13+
let rpc = Api_server.Server.dispatch_call req None in
1414
let session_id =
1515
let session_id = Ref.make_secret () in
1616
let now = Xapi_stdext_date.Date.now () in

ocaml/xapi/api_server.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let callback1 ?(json_rpc_version = Jsonrpc.V1) is_json req fd call =
3333
else
3434
let response =
3535
let@ req = Helper.with_tracing ~name:"Server.dispatch_call" req in
36-
Server.dispatch_call req fd call
36+
Server.dispatch_call req (Some fd) call
3737
in
3838
let translated =
3939
if

ocaml/xapi/context.ml

+6-7
Original file line numberDiff line numberDiff line change
@@ -460,29 +460,28 @@ let get_http_other_config http_req =
460460
let of_http_req ?session_id ?(internal_async_subtask = false) ~generate_task_for
461461
~supports_async ~label ~http_req ~fd () =
462462
let http_other_config = get_http_other_config http_req in
463+
let origin =
464+
match fd with None -> Internal | Some fd -> Http (http_req, fd)
465+
in
463466
let new_task_context () =
464467
let subtask_of =
465468
Option.map Ref.of_string http_req.Http.Request.subtask_of
466469
in
467470
make ?session_id ?subtask_of ~http_other_config ~task_in_database:true
468-
~origin:(Http (http_req, fd))
469-
label
471+
~origin label
470472
in
471473
if internal_async_subtask then
472474
new_task_context ()
473475
else
474476
match http_req.Http.Request.task with
475477
| Some task_id ->
476-
from_forwarded_task ?session_id ~http_other_config
477-
~origin:(Http (http_req, fd))
478+
from_forwarded_task ?session_id ~http_other_config ~origin
478479
(Ref.of_string task_id)
479480
| None ->
480481
if generate_task_for && supports_async then
481482
new_task_context ()
482483
else
483-
make ?session_id ~http_other_config
484-
~origin:(Http (http_req, fd))
485-
label
484+
make ?session_id ~http_other_config ~origin label
486485

487486
let set_test_rpc context rpc = context.test_rpc <- Some rpc
488487

ocaml/xapi/context.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ val of_http_req :
4949
-> supports_async:bool
5050
-> label:string
5151
-> http_req:Http.Request.t
52-
-> fd:Unix.file_descr
52+
-> fd:Unix.file_descr option
5353
-> unit
5454
-> t
5555

ocaml/xapi/server.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module Make : functor
33
(_ : Custom_actions.CUSTOM_ACTIONS)
44
-> sig
55
val dispatch_call :
6-
Http.Request.t -> Unix.file_descr -> Rpc.call -> Rpc.response
6+
Http.Request.t -> Unix.file_descr option -> Rpc.call -> Rpc.response
77
end

ocaml/xapi/server_helpers.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ val do_dispatch :
6161
-> string
6262
-> (__context:Context.t -> 'a)
6363
-> ('a -> Rpc.t)
64-
-> Unix.file_descr
64+
-> Unix.file_descr option
6565
-> Http.Request.t
6666
-> string
6767
-> [< `Async | `InternalAsync | `Sync > `Sync `InternalAsync]

0 commit comments

Comments
 (0)