[Libguestfs] [PATCH 1/3] launch: libvirt: Move the is_kvm flag (derived from libvirt capabilities) to backend data struct.

Richard W.M. Jones
Mon, 10 Mar 2014 17:28:52 -0000

This is just rearranging the data between structs.  There should be no
functional change.
---
 src/launch-libvirt.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index fd6e6d2..d86e2d2 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -106,6 +106,7 @@ struct backend_libvirt_data {
   char *selinux_imagelabel;
   bool selinux_norelabel_disks;
   char name[DOMAIN_NAME_LEN];   /* random name */
+  bool is_kvm;                  /* false = qemu, true = kvm (from
capabilities)*/
 };

 /* Parameters passed to construct_libvirt_xml and subfunctions.  We
@@ -122,12 +123,11 @@ struct libvirt_xml_params {
   char guestfsd_path[UNIX_PATH_MAX]; /* paths to sockets */
   char console_path[UNIX_PATH_MAX];
   bool enable_svirt;            /* false if we decided to disable sVirt */
-  bool is_kvm;                  /* false = qemu, true = kvm */
   bool current_proc_is_root;    /* true = euid is root */
 };

-static int parse_capabilities (guestfs_h *g, const char *capabilities_xml,
struct libvirt_xml_params *params);
-static xmlChar *construct_libvirt_xml (guestfs_h *g, const struct
libvirt_xml_params *params);
+static int parse_capabilities (guestfs_h *g, const char *capabilities_xml,
struct backend_libvirt_data *data);
+static xmlChar *construct_libvirt_xml (guestfs_h *g, const struct
backend_libvirt_data *data, const struct libvirt_xml_params *params);
 static void debug_appliance_permissions (guestfs_h *g);
 static void debug_socket_permissions (guestfs_h *g);
 static void libvirt_error (guestfs_h *g, const char *fs, ...)
__attribute__((format (printf,2,3)));
@@ -299,7 +299,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char
*libvirt_uri)
   if (g->verbose)
     guestfs___print_timestamped_message (g, "parsing capabilities
XML");

-  if (parse_capabilities (g, capabilities_xml, &params) == -1)
+  if (parse_capabilities (g, capabilities_xml, data) == -1)
     goto cleanup;

   /* Locate and/or build the appliance. */
@@ -434,7 +434,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char
*libvirt_uri)
   guestfs___drive_name (params.appliance_index, &params.appliance_dev[7]);
   params.enable_svirt = ! is_custom_hv (g);

-  xml = construct_libvirt_xml (g, &params);
+  xml = construct_libvirt_xml (g, data, &params);
   if (!xml)
     goto cleanup;

@@ -575,7 +575,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char
*libvirt_uri)

 static int
 parse_capabilities (guestfs_h *g, const char *capabilities_xml,
-                    struct libvirt_xml_params *params)
+                    struct backend_libvirt_data *data)
 {
   CLEANUP_XMLFREEDOC xmlDocPtr doc = NULL;
   CLEANUP_XMLXPATHFREECONTEXT xmlXPathContextPtr xpathCtx = NULL;
@@ -654,9 +654,9 @@ parse_capabilities (guestfs_h *g, const char
*capabilities_xml,
   force_tcg = guestfs___get_backend_setting_bool (g, "force_tcg");

   if (!force_tcg)
-    params->is_kvm = seen_kvm;
+    data->is_kvm = seen_kvm;
   else
-    params->is_kvm = 0;
+    data->is_kvm = 0;

   return 0;
 }
@@ -779,10 +779,10 @@ debug_socket_permissions (guestfs_h *g)
   }
 }

-static int construct_libvirt_xml_domain (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
+static int construct_libvirt_xml_domain (guestfs_h *g, const struct
backend_libvirt_data *data, const struct libvirt_xml_params *params,
xmlTextWriterPtr xo);
 static int construct_libvirt_xml_name (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_cpu (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_boot (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
+static int construct_libvirt_xml_cpu (guestfs_h *g, const struct
backend_libvirt_data *data, const struct libvirt_xml_params *params,
xmlTextWriterPtr xo);
+static int construct_libvirt_xml_boot (guestfs_h *g, const struct
backend_libvirt_data *data, const struct libvirt_xml_params *params,
xmlTextWriterPtr xo);
 static int construct_libvirt_xml_seclabel (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
 static int construct_libvirt_xml_lifecycle (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
 static int construct_libvirt_xml_devices (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
@@ -872,7 +872,9 @@ static int construct_libvirt_xml_appliance (guestfs_h *g,
const struct libvirt_x
              __FILE__, __LINE__, (fn));

 static xmlChar *
-construct_libvirt_xml (guestfs_h *g, const struct libvirt_xml_params *params)
+construct_libvirt_xml (guestfs_h *g,
+                       const struct backend_libvirt_data *data,
+                       const struct libvirt_xml_params *params)
 {
   xmlChar *ret = NULL;
   CLEANUP_XMLBUFFERFREE xmlBufferPtr xb = NULL;
@@ -905,7 +907,7 @@ construct_libvirt_xml (guestfs_h *g, const struct
libvirt_xml_params *params)
     return NULL;
   }

-  if (construct_libvirt_xml_domain (g, params, xo) == -1)
+  if (construct_libvirt_xml_domain (g, data, params, xo) == -1)
     return NULL;

   if (xmlTextWriterEndDocument (xo) == -1) {
@@ -925,19 +927,20 @@ construct_libvirt_xml (guestfs_h *g, const struct
libvirt_xml_params *params)

 static int
 construct_libvirt_xml_domain (guestfs_h *g,
+                              const struct backend_libvirt_data *data,
                               const struct libvirt_xml_params *params,
                               xmlTextWriterPtr xo)
 {
   start_element ("domain") {
-    attribute ("type", params->is_kvm ? "kvm" :
"qemu");
+    attribute ("type", data->is_kvm ? "kvm" :
"qemu");
     attribute_ns ("xmlns", "qemu", NULL,
                   "http://libvirt.org/schemas/domain/qemu/1.0");

     if (construct_libvirt_xml_name (g, params, xo) == -1)
       return -1;
-    if (construct_libvirt_xml_cpu (g, params, xo) == -1)
+    if (construct_libvirt_xml_cpu (g, data, params, xo) == -1)
       return -1;
-    if (construct_libvirt_xml_boot (g, params, xo) == -1)
+    if (construct_libvirt_xml_boot (g, data, params, xo) == -1)
       return -1;
     if (construct_libvirt_xml_seclabel (g, params, xo) == -1)
       return -1;
@@ -968,6 +971,7 @@ construct_libvirt_xml_name (guestfs_h *g,
 /* CPU and memory features. */
 static int
 construct_libvirt_xml_cpu (guestfs_h *g,
+                           const struct backend_libvirt_data *data,
                            const struct libvirt_xml_params *params,
                            xmlTextWriterPtr xo)
 {
@@ -987,7 +991,7 @@ construct_libvirt_xml_cpu (guestfs_h *g,
    * Only do this with KVM.  It is broken in subtle ways on TCG, and
    * fairly pointless anyway.
    */
-  if (params->is_kvm) {
+  if (data->is_kvm) {
     start_element ("cpu") {
       attribute ("mode", "host-passthrough");
       start_element ("model") {
@@ -1031,6 +1035,7 @@ construct_libvirt_xml_cpu (guestfs_h *g,
 /* Boot parameters. */
 static int
 construct_libvirt_xml_boot (guestfs_h *g,
+                            const struct backend_libvirt_data *data,
                             const struct libvirt_xml_params *params,
                             xmlTextWriterPtr xo)
 {
@@ -1039,7 +1044,7 @@ construct_libvirt_xml_boot (guestfs_h *g,

   /* Linux kernel command line. */
   flags = 0;
-  if (!params->is_kvm)
+  if (!data->is_kvm)
     flags |= APPLIANCE_COMMAND_LINE_IS_TCG;
   cmdline = guestfs___appliance_command_line (g, params->appliance_dev,
flags);

--
1.8.5.3