Skip to content

Commit

Permalink
Minimize xenstore accesses during domid-to-uuid lookups (#6129)
Browse files Browse the repository at this point in the history
Bake in assumptions that have been constant ever since xenstore was
created: getdomainpath always returns "/local/domain/domid",
/local/domain/domid/vm returns "/vm/uuid", so there's no need to look up
that path to get the uuid again

This reduces the number of xenstore accesses from 3 to 1 with no
functional change.

As suggested in:
#6068 (review)
  • Loading branch information
last-genius authored Nov 26, 2024
2 parents fce648f + 21d6773 commit 536db8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 10 additions & 3 deletions ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,16 @@ let generate_netdev_dss () =
let uuid_of_domid domid =
try
Xenstore.with_xs (fun xs ->
let vm = xs.Xenstore.Xs.getdomainpath domid ^ "/vm" in
let vm_dir = xs.Xenstore.Xs.read vm in
xs.Xenstore.Xs.read (vm_dir ^ "/uuid")
let vm_uuid_path =
Printf.sprintf "/local/domain/%d/vm" domid
|> xs.Xenstore.Xs.read
|> String.split_on_char '/'
in
match vm_uuid_path with
| [_; _; uuid] ->
uuid
| _ ->
raise (Invalid_argument "Incorrect xenstore node")
)
with e ->
fail "Failed to find uuid corresponding to domid: %d (%s)" domid
Expand Down
20 changes: 14 additions & 6 deletions ocaml/xenopsd/xc/xenops_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ exception Domain_not_found

let uuid_of_domid ~xs domid =
try
let vm = xs.Xs.getdomainpath domid ^ "/vm" in
let vm_dir = xs.Xs.read vm in
match Uuidx.of_string (xs.Xs.read (vm_dir ^ "/uuid")) with
| Some uuid ->
uuid
| None ->
let vm_uuid_path =
Printf.sprintf "/local/domain/%d/vm" domid
|> xs.Xs.read
|> String.split_on_char '/'
in
match vm_uuid_path with
| [_; _; uuid] -> (
match Uuidx.of_string uuid with
| Some uuid ->
uuid
| None ->
raise Domain_not_found
)
| _ ->
raise Domain_not_found
with _ -> raise Domain_not_found

Expand Down

0 comments on commit 536db8c

Please sign in to comment.