2012-12-13 17:10:28 +01:00
|
|
|
From 1b0c7cedf7020a0ac20c60c25f9ca1822768be40 Mon Sep 17 00:00:00 2001
|
2012-09-03 20:00:34 +02:00
|
|
|
From: Olaf Hering <olaf@aepfle.de>
|
|
|
|
Date: Mon, 3 Sep 2012 19:50:44 +0200
|
|
|
|
Subject: [PATCH] force virtio_blk in old guest kernel
|
|
|
|
|
|
|
|
Signed-off-by: Olaf Hering <olaf@aepfle.de>
|
|
|
|
---
|
2012-10-10 16:55:01 +02:00
|
|
|
df/output.c | 13 +++++++++----
|
|
|
|
fish/options.c | 8 +++++++-
|
|
|
|
src/guestfs-internal.h | 2 ++
|
2012-11-14 00:31:27 +01:00
|
|
|
src/handle.c | 16 ++++++++++++++++
|
2012-10-10 16:55:01 +02:00
|
|
|
src/inspect-fs-unix.c | 4 ++--
|
|
|
|
src/launch-appliance.c | 3 +++
|
2012-10-10 17:23:26 +02:00
|
|
|
src/launch-libvirt.c | 7 +++++++
|
2012-10-10 16:55:01 +02:00
|
|
|
test-tool/test-tool.c | 16 +++++++++++++---
|
2012-10-10 17:23:26 +02:00
|
|
|
8 files changed, 59 insertions(+), 10 deletions(-)
|
2012-09-03 20:00:34 +02:00
|
|
|
|
2012-10-10 16:55:01 +02:00
|
|
|
diff --git a/df/output.c b/df/output.c
|
2012-10-10 17:23:26 +02:00
|
|
|
index 5729dd4..fb33ca1 100644
|
2012-10-10 16:55:01 +02:00
|
|
|
--- a/df/output.c
|
|
|
|
+++ b/df/output.c
|
|
|
|
@@ -42,6 +42,7 @@
|
|
|
|
#include "virt-df.h"
|
|
|
|
|
|
|
|
static void write_csv_field (const char *field);
|
|
|
|
+static int use_virtio_blk;
|
|
|
|
|
|
|
|
void
|
|
|
|
print_title (void)
|
|
|
|
@@ -82,7 +83,7 @@ print_title (void)
|
|
|
|
}
|
2012-09-03 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 16:55:01 +02:00
|
|
|
-static char *adjust_device_offset (const char *device, int offset);
|
|
|
|
+static char *adjust_device_offset (guestfs_h *g, const char *device, int offset);
|
|
|
|
|
|
|
|
void
|
|
|
|
print_stat (const char *name, const char *uuid_param,
|
|
|
|
@@ -110,7 +111,7 @@ print_stat (const char *name, const char *uuid_param,
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
if (offset >= 0) {
|
|
|
|
char *p = dev;
|
|
|
|
- dev = adjust_device_offset (p, offset);
|
|
|
|
+ dev = adjust_device_offset (g, p, offset);
|
|
|
|
free (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -237,8 +238,9 @@ write_csv_field (const char *field)
|
|
|
|
static char *drive_name (int index, char *ret);
|
|
|
|
|
|
|
|
static char *
|
|
|
|
-adjust_device_offset (const char *device, int offset)
|
|
|
|
+adjust_device_offset (guestfs_h *g, const char *device, int offset)
|
|
|
|
{
|
|
|
|
+ ;
|
|
|
|
int index;
|
|
|
|
int part_num;
|
|
|
|
char *whole_device;
|
|
|
|
@@ -282,7 +284,10 @@ adjust_device_offset (const char *device, int offset)
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
- strcpy (ret, "/dev/sd");
|
2012-10-10 17:23:26 +02:00
|
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
2012-10-10 16:55:01 +02:00
|
|
|
+ use_virtio_blk = 1;
|
|
|
|
+#endif
|
|
|
|
+ strcpy (ret, use_virtio_blk ? "/dev/vd" : "/dev/sd");
|
|
|
|
drive_name (index, &ret[7]);
|
|
|
|
len = strlen (ret);
|
|
|
|
if (part_num > 0)
|
|
|
|
diff --git a/fish/options.c b/fish/options.c
|
2012-12-13 17:10:28 +01:00
|
|
|
index 40671b5..8a7b8cf 100644
|
2012-10-10 16:55:01 +02:00
|
|
|
--- a/fish/options.c
|
|
|
|
+++ b/fish/options.c
|
|
|
|
@@ -27,6 +27,8 @@
|
|
|
|
|
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
+static int use_virtio_blk;
|
|
|
|
+
|
|
|
|
char
|
|
|
|
add_drives (struct drv *drv, char next_drive)
|
|
|
|
{
|
|
|
|
@@ -40,13 +42,17 @@ add_drives (struct drv *drv, char next_drive)
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-10-10 17:23:26 +02:00
|
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
2012-10-10 16:55:01 +02:00
|
|
|
+ use_virtio_blk = 1;
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
if (drv) {
|
|
|
|
next_drive = add_drives (drv->next, 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
|
2012-12-13 17:10:28 +01:00
|
|
|
index df52f74..471a467 100644
|
2012-10-10 16:55:01 +02:00
|
|
|
--- a/src/guestfs-internal.h
|
|
|
|
+++ b/src/guestfs-internal.h
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -354,6 +354,8 @@ struct guestfs_h
|
2012-10-15 08:24:45 +02:00
|
|
|
virDomainPtr dom; /* libvirt domain */
|
2012-10-10 16:55:01 +02:00
|
|
|
} virt;
|
2012-10-15 08:24:45 +02:00
|
|
|
#endif
|
2012-10-10 16:55:01 +02:00
|
|
|
+
|
|
|
|
+ int use_virtio_blk;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Per-filesystem data stored for inspect_os. */
|
2012-11-14 00:31:27 +01:00
|
|
|
diff --git a/src/handle.c b/src/handle.c
|
2012-12-13 17:10:28 +01:00
|
|
|
index 685571a..efcbcf4 100644
|
2012-11-14 00:31:27 +01:00
|
|
|
--- a/src/handle.c
|
|
|
|
+++ b/src/handle.c
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -215,6 +215,22 @@ parse_environment (guestfs_h *g,
|
2012-10-19 14:33:23 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-10 16:55:01 +02:00
|
|
|
|
2012-09-03 20:00:34 +02:00
|
|
|
+/*
|
|
|
|
+ * 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
|
2012-10-10 16:55:01 +02:00
|
|
|
+ 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);
|
2012-09-03 20:00:34 +02:00
|
|
|
+#endif
|
|
|
|
+
|
2012-10-19 14:33:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:55:01 +02:00
|
|
|
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
|
2012-12-13 17:10:28 +01:00
|
|
|
index 8d3e6b0..97b355b 100644
|
2012-10-10 16:55:01 +02:00
|
|
|
--- a/src/inspect-fs-unix.c
|
|
|
|
+++ b/src/inspect-fs-unix.c
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -1412,7 +1412,7 @@ resolve_fstab_device_diskbyid (guestfs_h *g, const char *part,
|
2012-10-10 16:55:01 +02:00
|
|
|
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;
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -1489,7 +1489,7 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
|
2012-10-10 16:55:01 +02:00
|
|
|
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-appliance.c b/src/launch-appliance.c
|
2012-12-13 17:10:28 +01:00
|
|
|
index 4f21db7..e8e91d5 100644
|
2012-10-10 16:55:01 +02:00
|
|
|
--- a/src/launch-appliance.c
|
|
|
|
+++ b/src/launch-appliance.c
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -940,6 +940,9 @@ qemu_supports_virtio_scsi (guestfs_h *g)
|
|
|
|
}
|
2012-09-03 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 16:55:01 +02:00
|
|
|
+ if (g->use_virtio_blk)
|
|
|
|
+ g->app.virtio_scsi = 2;
|
2012-09-03 20:00:34 +02:00
|
|
|
+
|
|
|
|
return g->app.virtio_scsi == 1;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:55:01 +02:00
|
|
|
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
|
2012-12-13 17:10:28 +01:00
|
|
|
index 2a3bc7f..d23edf5 100644
|
2012-10-10 16:55:01 +02:00
|
|
|
--- a/src/launch-libvirt.c
|
|
|
|
+++ b/src/launch-libvirt.c
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -175,6 +175,13 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
|
2012-10-10 17:23:26 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-10 16:55:01 +02:00
|
|
|
|
|
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
|
|
|
+ if (g->use_virtio_blk) {
|
|
|
|
+ error (g, "Using libvirt is not possible with this binary package due to forced virtio-blk usage.");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
2012-10-10 17:23:26 +02:00
|
|
|
guestfs___launch_send_progress (g, 0);
|
|
|
|
TRACE0 (launch_libvirt_start);
|
2012-10-10 16:55:01 +02:00
|
|
|
|
2012-09-24 14:57:04 +02:00
|
|
|
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
|
2012-12-13 17:10:28 +01:00
|
|
|
index 9db086b..d44b9fa 100644
|
2012-09-24 14:57:04 +02:00
|
|
|
--- a/test-tool/test-tool.c
|
|
|
|
+++ b/test-tool/test-tool.c
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -103,6 +103,16 @@ main (int argc, char *argv[])
|
2012-10-10 16:55:01 +02:00
|
|
|
int i;
|
|
|
|
struct guestfs_version *vers;
|
|
|
|
char *p;
|
|
|
|
+ char *disk_name, *partition_name;
|
2012-12-13 17:10:28 +01:00
|
|
|
+ int use_virtio_blk = 0;
|
|
|
|
+
|
2012-10-10 17:23:26 +02:00
|
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
2012-10-10 16:55:01 +02:00
|
|
|
+ use_virtio_blk = 1;
|
|
|
|
+#endif
|
|
|
|
+ if (asprintf(&disk_name, "/dev/%s", use_virtio_blk ? "vda" : "sda") < 0)
|
|
|
|
+ exit (EXIT_FAILURE);
|
|
|
|
+ if (asprintf(&partition_name, "%s1", disk_name) < 0)
|
|
|
|
+ exit (EXIT_FAILURE);
|
2012-12-13 17:10:28 +01:00
|
|
|
|
2012-10-10 16:55:01 +02:00
|
|
|
for (;;) {
|
|
|
|
c = getopt_long (argc, argv, options, long_options, &option_index);
|
2012-12-13 17:10:28 +01:00
|
|
|
@@ -275,19 +285,19 @@ main (int argc, char *argv[])
|
2012-09-24 14:57:04 +02:00
|
|
|
fflush (stdout);
|
|
|
|
|
|
|
|
/* Create the filesystem and mount everything. */
|
|
|
|
- if (guestfs_part_disk (g, "/dev/sda", "mbr") == -1) {
|
2012-10-10 16:55:01 +02:00
|
|
|
+ if (guestfs_part_disk (g, disk_name, "mbr") == -1) {
|
2012-09-24 14:57:04 +02:00
|
|
|
fprintf (stderr,
|
|
|
|
_("libguestfs-test-tool: failed to run part-disk\n"));
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (guestfs_mkfs (g, "ext2", "/dev/sda1") == -1) {
|
2012-10-10 16:55:01 +02:00
|
|
|
+ if (guestfs_mkfs (g, "ext2", partition_name) == -1) {
|
2012-09-24 14:57:04 +02:00
|
|
|
fprintf (stderr,
|
|
|
|
_("libguestfs-test-tool: failed to mkfs.ext2\n"));
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (guestfs_mount (g, "/dev/sda1", "/") == -1) {
|
2012-10-10 16:55:01 +02:00
|
|
|
+ if (guestfs_mount (g, partition_name, "/") == -1) {
|
2012-09-24 14:57:04 +02:00
|
|
|
fprintf (stderr,
|
2012-10-10 16:55:01 +02:00
|
|
|
_("libguestfs-test-tool: failed to mount /dev/sda1 on /\n"));
|
2012-09-24 14:57:04 +02:00
|
|
|
exit (EXIT_FAILURE);
|
2012-09-03 20:00:34 +02:00
|
|
|
--
|
2012-12-13 17:10:28 +01:00
|
|
|
1.8.0.1
|
2012-09-03 20:00:34 +02:00
|
|
|
|