[Libguestfs] [PATCH 2/2] daemon: Return MD partitions in guestfs_list_partitions (RHBZ#1414510).

Richard W.M. Jones rjones at redhat.com
Thu Jan 19 11:24:37 UTC 2017


From: Pino Toscano <ptoscano at redhat.com>

---
 daemon/devsparts.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index b764f63..852ee99 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -36,7 +37,7 @@ typedef int (*block_dev_func_t) (const char *dev, struct stringsbuf *r);
 
 /* Execute a given function for each discovered block device */
 static char **
-foreach_block_device (block_dev_func_t func)
+foreach_block_device (block_dev_func_t func, bool return_md)
 {
   CLEANUP_FREE_STRINGSBUF DECLARE_STRINGSBUF (r);
   DIR *dir;
@@ -60,7 +61,9 @@ foreach_block_device (block_dev_func_t func)
         STREQLEN (d->d_name, "hd", 2) ||
         STREQLEN (d->d_name, "ubd", 3) ||
         STREQLEN (d->d_name, "vd", 2) ||
-        STREQLEN (d->d_name, "sr", 2)) {
+        STREQLEN (d->d_name, "sr", 2) ||
+        (return_md &&
+         STREQLEN (d->d_name, "md", 2) && c_isdigit (d->d_name[2]))) {
       snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
 
       /* Ignore the root device. */
@@ -131,7 +134,12 @@ add_device (const char *device, struct stringsbuf *r)
 char **
 do_list_devices (void)
 {
-  return foreach_block_device (add_device);
+  /* For backwards compatibility, don't return MD devices in the
+   * list returned by guestfs_list_devices.  This is because most
+   * API users expect that this list is effectively the same as
+   * the list of devices added by guestfs_add_drive.
+   */
+  return foreach_block_device (add_device, false);
 }
 
 static int
@@ -184,7 +192,7 @@ add_partitions (const char *device, struct stringsbuf *r)
 char **
 do_list_partitions (void)
 {
-  return foreach_block_device (add_partitions);
+  return foreach_block_device (add_partitions, true);
 }
 
 char *
-- 
2.9.3




More information about the Libguestfs mailing list