libguestfs/1000-force-virtio_blk-in-old-guest-kernel.patch

165 lines
5.3 KiB
Diff
Raw Normal View History

From 6ad9fa64944b23817e8fa642c81fc3ecc93a3464 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 | 15 ++++++++++++---
6 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/fish/options.c b/fish/options.c
index 770576b..6f143e1 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -100,7 +100,10 @@ add_drives (struct drv *drv, char next_drive)
- Update to version 1.22.6 * Initialize CLEANUP_* stack variables with NULL in various places. * daemon: sh: Fix missing initializer which caused segfault (RHBZ#1000121). * fish: Document that guestfish --remote --add won't work as expected (RHBZ#998513). * launch: direct: Don't try to wait for qemu if parent process forked (RHBZ#998482). * list-filesystems: Don't fail if there are no filesystems found (RHBZ#995711). * virt-list-filesystems: Fix to use $g->canonical_device_name instead of homebrew function. * daemon: If /proc/modules doesn't exist, linuxmodules optgroup is disabled. * launch: direct: Print \n after printing qemu command line. * conn: Make sure we display all log messages when qemu goes away. * lib: Turn 'random_chars' function used by libvirt backend into utility function. * daemon: ldm: Don't return an error if /dev/mapper doesn't exist. * daemon: Move all RESOLVE macros to daemon/stubs.c. * proto: Fix --enable-packet-dump mode. * daemon: Close augeas, hivex handles in unmount_all. * Fix parsing of boot flag in do_part_get_bootable() * Update gnulib to latest version. * augeas: Improve error reporting. * launch: direct: Add drives after machine parameters. * fish: Fix guestfish so it can recognize sheepdog://... as a valid URI. * resize: Move isatty_stdout function to separate module (TTY.isatty_stdout). * daemon: cap-get-file: Return empty string if no capability on file (RHBZ#989356). * src/file.c: Be sure to call guestfs___lazy_make_tmpdir before using g->tmpdir. * generator: Fix the case where a daemon function has one FileIn/FileOut parameter and no other parameters. OBS-URL: https://build.opensuse.org/package/show/Virtualization/libguestfs?expand=0&rev=237
2013-09-19 20:30:37 +02:00
{
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 (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 8888603..d4f6e90 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -472,6 +472,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 fffe825..4633df6 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -237,6 +237,22 @@ parse_environment (guestfs_h *g,
}
}
+/*
+ * 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 93e035f..6d38bf8 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1419,7 +1419,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;
@@ -1512,7 +1512,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 f44cc20..d212b87 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -1066,6 +1066,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 3a35226..03565ac 100644
--- a/test-tool/test-tool.c
+++ b/test-tool/test-tool.c
@@ -44,6 +44,14 @@
#define DEFAULT_TIMEOUT 600
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
+static const char disk[] = "/dev/vda";
+static const char part[] = "/dev/vda1";
+#else
+static const char disk[] = "/dev/sda";
+static const char part[] = "/dev/sda1";
+#endif
+
static int timeout = DEFAULT_TIMEOUT;
static void set_qemu (guestfs_h *g, const char *path, int use_wrapper);
@@ -186,6 +194,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);
@@ -272,19 +281,19 @@ main (int argc, char *argv[])
fflush (stdout);
/* Create the filesystem and mount everything. */
- if (guestfs_part_disk (g, "/dev/sda", "mbr") == -1) {
+ if (guestfs_part_disk (g, disk, "mbr") == -1) {
fprintf (stderr,
_("libguestfs-test-tool: failed to run part-disk\n"));
exit (EXIT_FAILURE);
}
- if (guestfs_mkfs (g, "ext2", "/dev/sda1") == -1) {
+ if (guestfs_mkfs (g, "ext2", part) == -1) {
fprintf (stderr,
_("libguestfs-test-tool: failed to mkfs.ext2\n"));
exit (EXIT_FAILURE);
}
- if (guestfs_mount (g, "/dev/sda1", "/") == -1) {
+ if (guestfs_mount (g, part, "/") == -1) {
fprintf (stderr,
_("libguestfs-test-tool: failed to mount /dev/sda1 on /\n"));
exit (EXIT_FAILURE);