Skip to content

Commit

Permalink
xapi-guard: separate base types to its own module
Browse files Browse the repository at this point in the history
use xapi-guard for name in logs

Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont committed Feb 9, 2024
1 parent 3ebe9c1 commit 3199708
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ocaml/xapi-guard/lib/dorpc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*)
open Idl

module D = Debug.Make (struct let name = "varstored-guard rpc" end)
module D = Debug.Make (struct let name = "xapi-guard rpc" end)

let wrap_rpc error f =
let on_error e =
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi-guard/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
(library
(name xapi_guard)
(modules dorpc)
(modules dorpc types)
(libraries
rpclib.core
lwt
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi-guard/lib/server_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
open Rpc
open Lwt.Syntax

module D = Debug.Make (struct let name = "varstored_interface" end)
module D = Debug.Make (struct let name = __MODULE__ end)

open D

Expand All @@ -25,7 +25,7 @@ let err = Xenops_interface.err

type nvram = (string * string) list [@@deriving rpcty]

let originator = "varstored-guard"
let originator = "xapi-guard"

type session = [`session] Ref.t

Expand Down
5 changes: 5 additions & 0 deletions ocaml/xapi-guard/lib/types.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Service = struct
type t = Varstored | Swtpm [@@deriving rpcty]

let to_string = function Varstored -> "Varstored" | Swtpm -> "Swtpm"
end
7 changes: 7 additions & 0 deletions ocaml/xapi-guard/lib/types.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Service : sig
type t = Varstored | Swtpm

val typ_of : t Rpc.Types.typ

val to_string : t -> string
end
22 changes: 11 additions & 11 deletions ocaml/xapi-guard/src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
* GNU Lesser General Public License for more details.
*)

open Xapi_guard
open Lwt.Syntax
open Xapi_guard_server
module Types = Xapi_guard.Types
module SessionCache = Xen_api_lwt_unix.SessionCache

module D = Debug.Make (struct let name = "varstored-guard" end)
let daemon_name = "xapi-guard"

let ret v = Lwt.bind v Lwt.return_ok |> Rpc_lwt.T.put

type ty = Varstored | Swtpm [@@deriving rpcty]
module D = Debug.Make (struct let name = daemon_name end)

let ty_to_string = function Varstored -> "Varstored" | Swtpm -> "Swtpm"
let ret v = Lwt.bind v Lwt.return_ok |> Rpc_lwt.T.put

let log_fds () =
let count stream = Lwt_stream.fold (fun _ n -> n + 1) stream 0 in
Expand All @@ -41,7 +39,7 @@ module Persistent = struct
vm_uuid: Xapi_idl_guard_privileged.Interface.Uuidm.t
; path: string
; gid: int
; typ: ty
; typ: Types.Service.t
}
[@@deriving rpcty]

Expand Down Expand Up @@ -109,7 +107,8 @@ let listen_for_vm {Persistent.vm_uuid; path; gid; typ} =
in
let vm_uuid_str = Uuidm.to_string vm_uuid in
D.debug "%s: listening for %s on socket %s for VM %s" __FUNCTION__
(ty_to_string typ) path vm_uuid_str ;
(Types.Service.to_string typ)
path vm_uuid_str ;
let* () = safe_unlink path in
let* stop_server = make_server ~cache path vm_uuid_str in
let* () = log_fds () in
Expand Down Expand Up @@ -230,7 +229,8 @@ let rpc_fn =

let process body =
let+ response =
Dorpc.wrap_rpc Xapi_idl_guard_privileged.Interface.E.error (fun () ->
Xapi_guard.Dorpc.wrap_rpc Xapi_idl_guard_privileged.Interface.E.error
(fun () ->
let call = Jsonrpc.call_of_string body in
D.debug "Received request from message-switch, method %s" call.Rpc.name ;
rpc_fn call
Expand Down Expand Up @@ -278,12 +278,12 @@ let main log_level =
old_hook exn
) ;
let () = Lwt_main.run @@ make_message_switch_server () in
D.debug "Exiting varstored-guard"
D.debug "Exiting %s" daemon_name

open! Cmdliner

let cmd =
let info = Cmd.info "varstored-guard" in
let info = Cmd.info daemon_name in
let log_level =
let doc = "Syslog level. E.g. debug, info etc." in
let level_conv =
Expand Down

0 comments on commit 3199708

Please sign in to comment.