Skip to content

CP-53314: Read and watch <domain>/data/service in xenstore to DB #6317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion ocaml/xapi/xapi_guest_agent.ml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ let dead_domains : IntSet.t ref = ref IntSet.empty

let mutex = Mutex.create ()

(* Parse data/service which has the following structure:
data/service/<service_name>/<key> = <value>
data/service/<service_name>/<key> = <value>
...
data/service/<service_name>/<key> = <value>
Read and convert to [(<service_name>/<key>, <value>)] pair list.
The list is intended to store in VM_guest_metrics.services at last *)
let get_guest_services (lookup : string -> string option)
(list : string -> string list) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the list function doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list is defined in xapi_xenops.ml update_vm. It lists all subdirs and keys in one depth under the given dir. In its definition, the data source is a big string string map like [("a", ""); ("a/b", ""); ("a/b/k1", "v1"); ("a/b/k2", "v2"); ("a/c/k1", "v1"); ("a/c/k2", "v2")]. Then function list "a" will give all subdirs ["b", "c"]. It needs to be noticed that the data source is not exposed to the caller in xapi_guest_agent.ml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utop # list_subkeys ["aaa/bbb/c", "x"] "aaa/bb";;
- : string list = ["b"]

Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incorrect. I believe the real implementation of list in xapi_xenops.ml update_vm has this problem, too. Normally, it's a internal function and the caller only pass the parameter as a intact dir, so the problem is not exposed. It deserves to rasie a ticket to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  let ls assoc path =
    let split = String.split_on_char '/' in
    let prefix = split path in
    let paths = List.map (fun (path, _) -> split path) assoc in
    let rec entry prefix path =
      match prefix, path with
      | [], x::_ -> Some x
      | x::xs, y::ys when x = y -> entry xs ys
      | _ -> None
    in
      List.filter_map (entry prefix) paths

let base_path = "data/service" in
let services = list base_path in
List.fold_left
(fun acc service ->
let sub_path = base_path // service in
List.fold_left
(fun acc key ->
let full_path_key = sub_path // key in
let db_key = service // key in
let value = lookup full_path_key in
(db_key, Option.value ~default:"" value) :: acc
)
acc (list sub_path)
)
[] services

(* In the following functions, 'lookup' reads a key from xenstore and 'list' reads
a directory from xenstore. Both are relative to the guest's domainpath. *)
let get_initial_guest_metrics (lookup : string -> string option)
Expand Down Expand Up @@ -290,7 +315,7 @@ let get_initial_guest_metrics (lookup : string -> string option)
; networks "xenserver/attr" "net-sriov-vf" list
]
)
and services = []
and services = get_guest_services lookup list
and other = List.append (to_map (other all_control)) ts
and memory = to_map memory
and last_updated = Unix.gettimeofday () in
Expand Down
2 changes: 2 additions & 0 deletions ocaml/xenopsd/xc/xenops_server_xen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,7 @@ module VM = struct
; ("drivers", None, 0)
; ("data", None, 0)
(* in particular avoid data/volumes which contains many entries for each disk *)
; ("data/service", None, 1) (* data/service/<service-name>/<key>*)
]
|> List.fold_left
(fun acc (dir, excludes, depth) ->
Expand Down Expand Up @@ -4825,6 +4826,7 @@ module Actions = struct
sprintf "/local/domain/%d/attr" domid
; sprintf "/local/domain/%d/data/updated" domid
; sprintf "/local/domain/%d/data/ts" domid
; sprintf "/local/domain/%d/data/service" domid
; sprintf "/local/domain/%d/memory/target" domid
; sprintf "/local/domain/%d/memory/uncooperative" domid
; sprintf "/local/domain/%d/console/vnc-port" domid
Expand Down