Skip to content

Commit

Permalink
On solo5 manifest mismatch print the manifest (#196)
Browse files Browse the repository at this point in the history
* On solo5 manifest mismatch print the manifest

This makes it easier for users of the client to figure out what devices
are expected without them having to know to query the solo5 manifest
using solo5-elftool themselves.

* Print devices only instead of the whole manifest

* Code review: Tweak error message

Co-authored-by: Hannes Mehnert <hannes@mehnert.org>

---------

Co-authored-by: Hannes Mehnert <hannes@mehnert.org>
  • Loading branch information
reynir and hannesm authored Nov 20, 2024
1 parent f5a9ce7 commit 80d24b5
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/vmm_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,34 +252,40 @@ let check_solo5_tender target version =
Error (`Msg (Fmt.str "unexpected solo5 tender --version output, expected one line with 'ABI version %u', got %s"
version (String.concat "\n" out)))

let solo5_image_devices image =
let* mft = Solo5_elftool.query_manifest (owee_buf_of_str image) in
Ok (List.fold_left
(fun (block_devices, networks) -> function
| Solo5_elftool.Dev_block_basic name -> name :: block_devices, networks
| Solo5_elftool.Dev_net_basic name -> block_devices, name :: networks)
([], []) mft.entries)
let solo5_image_devices mft =
List.fold_left
(fun (block_devices, networks) -> function
| Solo5_elftool.Dev_block_basic name -> name :: block_devices, networks
| Solo5_elftool.Dev_net_basic name -> block_devices, name :: networks)
([], []) mft.Solo5_elftool.entries

let equal_string_lists b1 b2 err =
if String_set.(equal (of_list b1) (of_list b2)) then
Ok ()
else
Error (`Msg err)

let devices_match ~bridges ~block_devices (manifest_block, manifest_net) =
let devices_match ~bridges ~block_devices mft =
let (manifest_block, manifest_net) = solo5_image_devices mft in
let pp_entry ppf = function
| Solo5_elftool.Dev_block_basic name -> Fmt.pf ppf "block %S" name
| Solo5_elftool.Dev_net_basic name -> Fmt.pf ppf "net %S" name
in
let* () =
equal_string_lists manifest_block block_devices
"specified block device(s) does not match with manifest"
(Fmt.str "specified block device(s) does not match with manifest. Devices present in manifest: %a"
Fmt.(list ~sep:(any ", ") pp_entry) mft.entries)
in
equal_string_lists manifest_net bridges
"specified bridge(s) does not match with the manifest"
(Fmt.str "specified bridge(s) does not match with the manifest. Devices present in manifest: %a"
Fmt.(list ~sep:(any ", ") pp_entry) mft.entries)

let manifest_devices_match ~bridges ~block_devices image =
let* things = solo5_image_devices image in
let* mft = Solo5_elftool.query_manifest (owee_buf_of_str image) in
let bridges = List.map (fun (b, _, _) -> b) bridges
and block_devices = List.map (fun (b, _, _) -> b) block_devices
in
devices_match ~bridges ~block_devices things
devices_match ~bridges ~block_devices mft

let bridge_name (service, b, _mac) = match b with None -> service | Some b -> b

Expand Down

0 comments on commit 80d24b5

Please sign in to comment.