lib: Move guestfs_device_index impl from daemon to library.

This function doesn't work reliably with the proposed change to device
name translation.  The reason is that strings returned by
Devsparts.list_devices contained translated names, so their indexes
did not correspond to the untranslated names used outside the
appliance..

We can avoid this and make the function much simpler and faster by
implementing it on the library side instead.
This commit is contained in:
Richard W.M. Jones
2020-02-20 15:04:25 +00:00
parent eb17229c3e
commit 3cea2cfe04
5 changed files with 36 additions and 35 deletions

View File

@@ -111,14 +111,3 @@ let is_whole_device device =
try ignore (stat devpath); true
with Unix_error ((ENOENT|ENOTDIR), _, _) -> false
let device_index device =
(* This is the algorithm which was used by the C version. Why
* can't we use drive_index from C_utils? XXX
*)
let rec loop i = function
| [] -> failwithf "%s: device not found" device
| dev :: devices when dev = device -> i
| _ :: devices -> loop (i+1) devices
in
loop 0 (list_devices ())