diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-06-29 19:03:37 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-07-07 11:22:52 +0100 |
commit | 6aa281b7e8ca4f63dd5d5750184352ecd6e68fda (patch) | |
tree | e13bc7bf3ef7c315fe0e83e2affa2c7536023b6e | |
parent | 8deae6d2cc27f84d8b1c7112de2b41a2346670b8 (diff) | |
download | libguestfs-6aa281b7e8ca4f63dd5d5750184352ecd6e68fda.tar.gz libguestfs-6aa281b7e8ca4f63dd5d5750184352ecd6e68fda.tar.xz libguestfs-6aa281b7e8ca4f63dd5d5750184352ecd6e68fda.zip |
New API: guestfs_nr_devices
This returns the number of whole block devices added. It is usually
simpler to call this than to list the devices and count them, which
is what we do in some places in the current codebase.
(cherry picked from commit 152b179a19e43fcb0baec65ea65d394ee1dba891)
-rw-r--r-- | daemon/devsparts.c | 17 | ||||
-rw-r--r-- | generator/generator_actions.ml | 12 | ||||
-rw-r--r-- | src/MAX_PROC_NR | 2 |
3 files changed, 30 insertions, 1 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 8f85624f..b5300c50 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -268,3 +268,20 @@ do_device_index (const char *device) reply_with_error ("device not found"); return ret; } + +int +do_nr_devices (void) +{ + char **devices; + size_t i; + + devices = do_list_devices (); + if (devices == NULL) + return -1; + + for (i = 0; devices[i] != NULL; ++i) + free (devices[i]); + free (devices); + + return (int) i; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 14618c29..5cdd0764 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -6664,6 +6664,18 @@ for example as a string returned from C<guestfs_list_devices>. See also C<guestfs_list_devices>, C<guestfs_part_to_dev>."); + ("nr_devices", (RInt "nrdisks", [], []), 336, [], + [InitEmpty, Always, TestOutputInt ( + [["nr_devices"]], 4)], + "return number of whole block devices (disks) added", + "\ +This returns the number of whole block devices that were +added. This is the same as the number of devices that would +be returned if you called C<guestfs_list_devices>. + +To find out the maximum number of devices that could be added, +call C<guestfs_max_disks>."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 3d9988ad..e64f24d5 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -335 +336 |