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

@@ -739,6 +739,23 @@ Converted to F</dev/VG/LV> form using C<guestfs_lvm_canonical_lv_name>.
Other strings are returned unmodified." };
{ defaults with
name = "device_index"; added = (1, 19, 7);
style = RInt "index", [String (Device, "device")], [];
tests = [
InitEmpty, Always, TestResult (
[["device_index"; "/dev/sda"]], "ret == 0"), []
];
shortdesc = "convert device to index";
longdesc = "\
This function takes a device name (eg. \"/dev/sdb\") and
returns the index of the device in the list of devices.
Index numbers start from 0. The named device must exist,
for example as a string returned from C<guestfs_list_devices>.
See also C<guestfs_list_devices>, C<guestfs_part_to_dev>." };
{ defaults with
name = "shutdown"; added = (1, 19, 16);
style = RErr, [], [];
@@ -7423,24 +7440,6 @@ different operation that turns free space in the filesystem
into zeroes. It is valid to call C<guestfs_fstrim> either
instead of, or after calling C<guestfs_zero_free_space>." };
{ defaults with
name = "device_index"; added = (1, 19, 7);
style = RInt "index", [String (Device, "device")], [];
impl = OCaml "Devsparts.device_index";
tests = [
InitEmpty, Always, TestResult (
[["device_index"; "/dev/sda"]], "ret == 0"), []
];
shortdesc = "convert device to index";
longdesc = "\
This function takes a device name (eg. \"/dev/sdb\") and
returns the index of the device in the list of devices.
Index numbers start from 0. The named device must exist,
for example as a string returned from C<guestfs_list_devices>.
See also C<guestfs_list_devices>, C<guestfs_part_to_dev>." };
{ defaults with
name = "nr_devices"; added = (1, 19, 15);
impl = OCaml "Devsparts.nr_devices";

View File

@@ -345,7 +345,6 @@ let proc_nr = [
332, "btrfs_fsck";
333, "filesystem_available";
334, "fstrim";
335, "device_index";
336, "nr_devices";
337, "xfs_info";
338, "pvchange_uuid";