Skip to content

Commit 536db8c

Browse files
authored
Minimize xenstore accesses during domid-to-uuid lookups (#6129)
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)
2 parents fce648f + 21d6773 commit 536db8c

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,16 @@ let generate_netdev_dss () =
138138
let uuid_of_domid domid =
139139
try
140140
Xenstore.with_xs (fun xs ->
141-
let vm = xs.Xenstore.Xs.getdomainpath domid ^ "/vm" in
142-
let vm_dir = xs.Xenstore.Xs.read vm in
143-
xs.Xenstore.Xs.read (vm_dir ^ "/uuid")
141+
let vm_uuid_path =
142+
Printf.sprintf "/local/domain/%d/vm" domid
143+
|> xs.Xenstore.Xs.read
144+
|> String.split_on_char '/'
145+
in
146+
match vm_uuid_path with
147+
| [_; _; uuid] ->
148+
uuid
149+
| _ ->
150+
raise (Invalid_argument "Incorrect xenstore node")
144151
)
145152
with e ->
146153
fail "Failed to find uuid corresponding to domid: %d (%s)" domid

ocaml/xenopsd/xc/xenops_helpers.ml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ exception Domain_not_found
2828

2929
let uuid_of_domid ~xs domid =
3030
try
31-
let vm = xs.Xs.getdomainpath domid ^ "/vm" in
32-
let vm_dir = xs.Xs.read vm in
33-
match Uuidx.of_string (xs.Xs.read (vm_dir ^ "/uuid")) with
34-
| Some uuid ->
35-
uuid
36-
| None ->
31+
let vm_uuid_path =
32+
Printf.sprintf "/local/domain/%d/vm" domid
33+
|> xs.Xs.read
34+
|> String.split_on_char '/'
35+
in
36+
match vm_uuid_path with
37+
| [_; _; uuid] -> (
38+
match Uuidx.of_string uuid with
39+
| Some uuid ->
40+
uuid
41+
| None ->
42+
raise Domain_not_found
43+
)
44+
| _ ->
3745
raise Domain_not_found
3846
with _ -> raise Domain_not_found
3947

0 commit comments

Comments
 (0)