libguestfs/1000-force-virtio_blk-in-old-guest-kernel.patch
Olaf Hering 0c246c48e1 - Update to version 1.26.2
* sparsify: Add a note about qcow2 internal snapshots not being copied (RHBZ#1094746).
  * customize: random-seed file has moved again.
  * lib: xmlParse{File,Memory} -> xmlRead{File,Memory}
  * launch: direct: Supply -M option when testing qemu for devices.
  * tar-in: Fix places where we didn't cancel the receive (FileIn) correctly along error paths (RHBZ#1091803).
  * configure: Make sure grep matches qemu 2.x version string.
  * daemon: parted: part-get-name: switch from sgdisk to parted (RHBZ#1088424).
  * sparsify: If using -v (verbose), ensure #disk_create runs verbose too.
  * disk-create: Fix this API so it works correctly with block devices (RHBZ#1088262).
  * listfs: If LDM not available, don't inhibit partition detection (RHBZ#1079182).
  * mllib: utils: Add mapi function.
  * src/launch: improve the addition of the no-hpet option
  * handle: Free g->backend_settings.
  * python: Remove unnecessary library dependencies.
  * utils: Move guestfs___validate_guid out of utils.c.
  * utils: Remove for-loop variable decl.
  * rescue: Don't leak various variables when using --suggest option with multi-boot guests.
  * make-fs: Close FILE* along error path.
  * make-fs: Check for error return from guestfs_statvfs.
  * daemon: parted: part-get-name: Don't leak partition type string.

OBS-URL: https://build.opensuse.org/package/show/Virtualization/libguestfs?expand=0&rev=283
2014-05-13 13:41:42 +00:00

127 lines
4.2 KiB
Diff

From ec0d8e661b5cb97ea3e2ed5ffb86bdfb538fca00 Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de>
Date: Mon, 3 Sep 2012 19:50:44 +0200
Subject: force virtio_blk in old guest kernel
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
fish/options.c | 7 +++++--
src/guestfs-internal.h | 1 +
src/handle.c | 16 ++++++++++++++++
src/inspect-fs-unix.c | 4 ++--
src/launch-direct.c | 2 ++
test-tool/test-tool.c | 1 +
6 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/fish/options.c b/fish/options.c
index 80b71ec..2cef1bc 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -100,7 +100,10 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive)
{
int r;
struct guestfs_add_drive_opts_argv ad_optargs;
-
+ int use_virtio_blk = 0;
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
+ use_virtio_blk = 1;
+#endif
if (next_drive > 'z') {
fprintf (stderr,
_("%s: too many drives added on the command line\n"),
@@ -114,7 +117,7 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive)
free (drv->device);
drv->device = NULL;
- if (asprintf (&drv->device, "/dev/sd%c", next_drive) == -1) {
+ if (asprintf (&drv->device, "/dev/%s%c", use_virtio_blk ? "vd" : "sd", next_drive) == -1) {
perror ("asprintf");
exit (EXIT_FAILURE);
}
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 648f005..fd99253 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -501,6 +501,7 @@ struct guestfs_h
unsigned int nr_requested_credentials;
virConnectCredentialPtr requested_credentials;
#endif
+ int use_virtio_blk;
};
/* Per-filesystem data stored for inspect_os. */
diff --git a/src/handle.c b/src/handle.c
index 393ac1e..1806570 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -259,6 +259,22 @@ parse_environment (guestfs_h *g,
return -1;
}
+/*
+ * Currently virtio_scsi is forced if qemu in the host supports this
+ * feature. This test does however not take the capabilities of the started
+ * guest into account. As a result no disks will be found if the guest
+ * kernel is older than 3.4.
+ */
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
+ static const char env_string[] = "GUESTFS_QEMU_NO_VIRTIO_BLK";
+ str = getenv(env_string);
+ g->use_virtio_blk = str == NULL;
+ if (str)
+ debug (g, "SuSE: %s in environment, preserving virtio-scsi setting.", env_string);
+ else
+ debug (g, "SuSE: %s not in environment, preventing virtio-scsi usage in old guest kernel.", env_string);
+#endif
+
return 0;
}
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 17b0b5f..20af3f7 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1438,7 +1438,7 @@ resolve_fstab_device_diskbyid (guestfs_h *g, const char *part,
return 0;
/* Make the partition name and check it exists. */
- device = safe_asprintf (g, "/dev/sda%s", part);
+ device = safe_asprintf (g, "/dev/%sa%s", g->use_virtio_blk ? "vd" : "sd", part);
if (!is_partition (g, device)) {
free (device);
return 0;
@@ -1531,7 +1531,7 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
if (disk_i != -1 && disk_i <= 26 &&
slice_i > 0 && slice_i <= 1 /* > 4 .. see comment above */ &&
part_i >= 0 && part_i < 26) {
- device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+ device = safe_asprintf (g, "/dev/%s%c%d", g->use_virtio_blk ? "vd" : "sd", disk_i + 'a', part_i + 5);
}
}
else if ((part = match1 (g, spec, re_diskbyid)) != NULL) {
diff --git a/src/launch-direct.c b/src/launch-direct.c
index 2332368..67b9fd4 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -1183,6 +1183,8 @@ qemu_supports_virtio_scsi (guestfs_h *g, struct backend_direct_data *data)
data->virtio_scsi = 3;
}
}
+ if (g->use_virtio_blk)
+ data->virtio_scsi = 2;
return data->virtio_scsi == 1;
}
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
index 7e8d88e..8d5ae34 100644
--- a/test-tool/test-tool.c
+++ b/test-tool/test-tool.c
@@ -187,6 +187,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
guestfs_set_verbose (g, 1);
+ guestfs_set_trace (g, 1);
if (qemu)
set_qemu (g, qemu, qemu_use_wrapper);