2729bd
From f13297315495144775f6249e9e24dc5f18f6f902 Mon Sep 17 00:00:00 2001
2729bd
From: Laszlo Ersek <lersek@redhat.com>
2729bd
Date: Wed, 4 May 2022 15:41:53 +0200
2729bd
Subject: [PATCH] lib: drive_create_data, drive: remove field "iface"
2729bd
2729bd
Representing "iface" in the "drive_create_data" and "drive" structures is
2729bd
now useless; the direct backend ignores "iface", while the libvirt one
2729bd
rejects it unless it is empty. Unify both backends -- make them both
2729bd
ignore "iface". (Which only relaxes the libvirt backend, so it cannot
2729bd
cause compatibility problems.) This lets us remove the fields. Update the
2729bd
documentation as well.
2729bd
2729bd
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1844341
2729bd
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
2729bd
Message-Id: <20220504134155.11832-3-lersek@redhat.com>
2729bd
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2729bd
(cherry picked from commit f68eaee1d6c41f91e7dfd2aa9e7d238cca7b8a4c)
2729bd
---
2729bd
 generator/actions_core_deprecated.ml |  6 ++----
2729bd
 lib/drives.c                         | 31 +++++-----------------------
2729bd
 lib/guestfs-internal.h               |  1 -
2729bd
 lib/launch-libvirt.c                 |  6 ------
2729bd
 lib/libvirt-domain.c                 | 15 --------------
2729bd
 5 files changed, 7 insertions(+), 52 deletions(-)
2729bd
2729bd
diff --git a/generator/actions_core_deprecated.ml b/generator/actions_core_deprecated.ml
2729bd
index f1040a0e9..c23f4a330 100644
2729bd
--- a/generator/actions_core_deprecated.ml
2729bd
+++ b/generator/actions_core_deprecated.ml
2729bd
@@ -74,8 +74,7 @@ of C<guestfs_add_drive_ro>." };
2729bd
     longdesc = "\
2729bd
 This is the same as C<guestfs_add_drive> but it allows you
2729bd
 to specify the QEMU interface emulation to use at run time.
2729bd
-The libvirt backend rejects a non-empty C<iface> argument.
2729bd
-The direct backend ignores C<iface>." };
2729bd
+Both the direct and the libvirt backends ignore C<iface>." };
2729bd
 
2729bd
   { defaults with
2729bd
     name = "add_drive_ro_with_if"; added = (1, 0, 84);
2729bd
@@ -86,8 +85,7 @@ The direct backend ignores C<iface>." };
2729bd
     longdesc = "\
2729bd
 This is the same as C<guestfs_add_drive_ro> but it allows you
2729bd
 to specify the QEMU interface emulation to use at run time.
2729bd
-The libvirt backend rejects a non-empty C<iface> argument.
2729bd
-The direct backend ignores C<iface>." };
2729bd
+Both the direct and the libvirt backends ignore C<iface>." };
2729bd
 
2729bd
   { defaults with
2729bd
     name = "lstatlist"; added = (1, 0, 77);
2729bd
diff --git a/lib/drives.c b/lib/drives.c
2729bd
index a6179fc36..8fe46a41c 100644
2729bd
--- a/lib/drives.c
2729bd
+++ b/lib/drives.c
2729bd
@@ -53,7 +53,6 @@ struct drive_create_data {
2729bd
   const char *secret;
2729bd
   bool readonly;
2729bd
   const char *format;
2729bd
-  const char *iface;
2729bd
   const char *name;
2729bd
   const char *disk_label;
2729bd
   const char *cachemode;
2729bd
@@ -110,7 +109,6 @@ create_drive_file (guestfs_h *g,
2729bd
   drv->src.format = data->format ? safe_strdup (g, data->format) : NULL;
2729bd
 
2729bd
   drv->readonly = data->readonly;
2729bd
-  drv->iface = data->iface ? safe_strdup (g, data->iface) : NULL;
2729bd
   drv->name = data->name ? safe_strdup (g, data->name) : NULL;
2729bd
   drv->disk_label = data->disk_label ? safe_strdup (g, data->disk_label) : NULL;
2729bd
   drv->cachemode = data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
2729bd
@@ -147,7 +145,6 @@ create_drive_non_file (guestfs_h *g,
2729bd
   drv->src.format = data->format ? safe_strdup (g, data->format) : NULL;
2729bd
 
2729bd
   drv->readonly = data->readonly;
2729bd
-  drv->iface = data->iface ? safe_strdup (g, data->iface) : NULL;
2729bd
   drv->name = data->name ? safe_strdup (g, data->name) : NULL;
2729bd
   drv->disk_label = data->disk_label ? safe_strdup (g, data->disk_label) : NULL;
2729bd
   drv->cachemode = data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
2729bd
@@ -470,7 +467,6 @@ free_drive_struct (struct drive *drv)
2729bd
 {
2729bd
   free_drive_source (&drv->src);
2729bd
   free (drv->overlay);
2729bd
-  free (drv->iface);
2729bd
   free (drv->name);
2729bd
   free (drv->disk_label);
2729bd
   free (drv->cachemode);
2729bd
@@ -511,14 +507,12 @@ drive_to_string (guestfs_h *g, const struct drive *drv)
2729bd
     s_blocksize = safe_asprintf (g, "%d", drv->blocksize);
2729bd
 
2729bd
   return safe_asprintf
2729bd
-    (g, "%s%s%s%s protocol=%s%s%s%s%s%s%s%s%s%s%s%s%s",
2729bd
+    (g, "%s%s%s%s protocol=%s%s%s%s%s%s%s%s%s%s%s",
2729bd
      drv->src.u.path,
2729bd
      drv->readonly ? " readonly" : "",
2729bd
      drv->src.format ? " format=" : "",
2729bd
      drv->src.format ? : "",
2729bd
      guestfs_int_drive_protocol_to_string (drv->src.protocol),
2729bd
-     drv->iface ? " iface=" : "",
2729bd
-     drv->iface ? : "",
2729bd
      drv->name ? " name=" : "",
2729bd
      drv->name ? : "",
2729bd
      drv->disk_label ? " label=" : "",
2729bd
@@ -747,8 +741,6 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
2729bd
     ? optargs->readonly : false;
2729bd
   data.format = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK
2729bd
     ? optargs->format : NULL;
2729bd
-  data.iface = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK
2729bd
-    ? optargs->iface : NULL;
2729bd
   data.name = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_NAME_BITMASK
2729bd
     ? optargs->name : NULL;
2729bd
   data.disk_label = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_LABEL_BITMASK
2729bd
@@ -804,12 +796,6 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
2729bd
     free_drive_servers (data.servers, data.nr_servers);
2729bd
     return -1;
2729bd
   }
2729bd
-  if (data.iface && !VALID_FORMAT_IFACE (data.iface)) {
2729bd
-    error (g, _("%s parameter is empty or contains disallowed characters"),
2729bd
-           "iface");
2729bd
-    free_drive_servers (data.servers, data.nr_servers);
2729bd
-    return -1;
2729bd
-  }
2729bd
   if (data.disk_label && !VALID_DISK_LABEL (data.disk_label)) {
2729bd
     error (g, _("label parameter is empty, too long, or contains disallowed characters"));
2729bd
     free_drive_servers (data.servers, data.nr_servers);
2729bd
@@ -935,24 +921,17 @@ guestfs_impl_add_drive_ro (guestfs_h *g, const char *filename)
2729bd
 
2729bd
 int
2729bd
 guestfs_impl_add_drive_with_if (guestfs_h *g, const char *filename,
2729bd
-				const char *iface)
2729bd
+				const char *iface ATTRIBUTE_UNUSED)
2729bd
 {
2729bd
-  const struct guestfs_add_drive_opts_argv optargs = {
2729bd
-    .bitmask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK,
2729bd
-    .iface = iface,
2729bd
-  };
2729bd
-
2729bd
-  return guestfs_add_drive_opts_argv (g, filename, &optargs);
2729bd
+  return guestfs_add_drive_opts_argv (g, filename, NULL);
2729bd
 }
2729bd
 
2729bd
 int
2729bd
 guestfs_impl_add_drive_ro_with_if (guestfs_h *g, const char *filename,
2729bd
-                               const char *iface)
2729bd
+                               const char *iface ATTRIBUTE_UNUSED)
2729bd
 {
2729bd
   const struct guestfs_add_drive_opts_argv optargs = {
2729bd
-    .bitmask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK
2729bd
-             | GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
2729bd
-    .iface = iface,
2729bd
+    .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
2729bd
     .readonly = true,
2729bd
   };
2729bd
 
2729bd
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
2729bd
index 5bb00bc10..16755cfb3 100644
2729bd
--- a/lib/guestfs-internal.h
2729bd
+++ b/lib/guestfs-internal.h
2729bd
@@ -298,7 +298,6 @@ struct drive {
2729bd
 
2729bd
   /* Various per-drive flags. */
2729bd
   bool readonly;
2729bd
-  char *iface;
2729bd
   char *name;
2729bd
   char *disk_label;
2729bd
   char *cachemode;
2729bd
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
2729bd
index de342b425..03d69e027 100644
2729bd
--- a/lib/launch-libvirt.c
2729bd
+++ b/lib/launch-libvirt.c
2729bd
@@ -1472,12 +1472,6 @@ construct_libvirt_xml_disk (guestfs_h *g,
2729bd
   const char *type, *uuid;
2729bd
   int r;
2729bd
 
2729bd
-  /* XXX We probably could support this if we thought about it some more. */
2729bd
-  if (drv->iface) {
2729bd
-    error (g, _("‘iface’ parameter is not supported by the libvirt backend"));
2729bd
-    return -1;
2729bd
-  }
2729bd
-
2729bd
   start_element ("disk") {
2729bd
     attribute ("device", "disk");
2729bd
 
2729bd
diff --git a/lib/libvirt-domain.c b/lib/libvirt-domain.c
2729bd
index 3050680fa..fafbf50ea 100644
2729bd
--- a/lib/libvirt-domain.c
2729bd
+++ b/lib/libvirt-domain.c
2729bd
@@ -68,7 +68,6 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
2729bd
   int live;
2729bd
   int allowuuid;
2729bd
   const char *readonlydisk;
2729bd
-  const char *iface;
2729bd
   const char *cachemode;
2729bd
   const char *discard;
2729bd
   bool copyonread;
2729bd
@@ -78,8 +77,6 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
2729bd
     ? optargs->libvirturi : NULL;
2729bd
   readonly = optargs->bitmask & GUESTFS_ADD_DOMAIN_READONLY_BITMASK
2729bd
     ? optargs->readonly : 0;
2729bd
-  iface = optargs->bitmask & GUESTFS_ADD_DOMAIN_IFACE_BITMASK
2729bd
-    ? optargs->iface : NULL;
2729bd
   live = optargs->bitmask & GUESTFS_ADD_DOMAIN_LIVE_BITMASK
2729bd
     ? optargs->live : 0;
2729bd
   allowuuid = optargs->bitmask & GUESTFS_ADD_DOMAIN_ALLOWUUID_BITMASK
2729bd
@@ -136,10 +133,6 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
2729bd
     optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK;
2729bd
     optargs2.readonly = readonly;
2729bd
   }
2729bd
-  if (iface) {
2729bd
-    optargs2.bitmask |= GUESTFS_ADD_LIBVIRT_DOM_IFACE_BITMASK;
2729bd
-    optargs2.iface = iface;
2729bd
-  }
2729bd
   if (live) {
2729bd
     error (g, _("libguestfs live support was removed in libguestfs 1.48"));
2729bd
     goto cleanup;
2729bd
@@ -193,7 +186,6 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
2729bd
   virDomainPtr dom = domvp;
2729bd
   ssize_t r;
2729bd
   int readonly;
2729bd
-  const char *iface;
2729bd
   const char *cachemode;
2729bd
   const char *discard;
2729bd
   bool copyonread;
2729bd
@@ -208,9 +200,6 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
2729bd
   readonly =
2729bd
     optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK
2729bd
     ? optargs->readonly : 0;
2729bd
-  iface =
2729bd
-    optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_IFACE_BITMASK
2729bd
-    ? optargs->iface : NULL;
2729bd
   live =
2729bd
     optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_LIVE_BITMASK
2729bd
     ? optargs->live : 0;
2729bd
@@ -289,10 +278,6 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
2729bd
   data.optargs.bitmask = 0;
2729bd
   data.readonly = readonly;
2729bd
   data.readonlydisk = readonlydisk;
2729bd
-  if (iface) {
2729bd
-    data.optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK;
2729bd
-    data.optargs.iface = iface;
2729bd
-  }
2729bd
   if (cachemode) {
2729bd
     data.optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_CACHEMODE_BITMASK;
2729bd
     data.optargs.cachemode = cachemode;
2729bd
-- 
2729bd
2.31.1
2729bd