From 3fe9235b90ec128cd59407100a1b49c7d4a581de Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 29 Jun 2012 19:03:37 +0100 Subject: 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) --- daemon/devsparts.c | 17 +++++++++++++++++ generator/generator_actions.ml | 12 ++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 8020fbe1..bd955da5 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -264,3 +264,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 4cad3323..47d52a64 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -7253,6 +7253,18 @@ for example as a string returned from C. See also C, C."); + ("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. + +To find out the maximum number of devices that could be added, +call C."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 6f96da66..e64f24d5 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -332 +336 -- cgit