forked from pool/libguestfs
Olaf Hering
518efff326
* proto: Fix stack overflow when there are many progress events (RHBZ#909624). * rescue: Count the mountable filesystems when displaying the 'suggest' message. * lib: Define CLEANUP_CMD_CLOSE macro and use it throughout the library. * lib: Allow guestfs_free_* functions to be safely called with a NULL pointer. * btrfs: Fix btrfs_subvolume_list on F18 (RHBZ#903620). * daemon: Check parameter of base64-out and tar-out before running external command (RHBZ#908322). * daemon: download: Add extra check that download file is not a directory (RHBZ#908321). * daemon: Add more information to certain calls to perror. * daemon: Call wipefs before mkfs to work around pathological behaviour in btrfs. * lib: Add CLEANUP_* macros which automatically free things when leaving scope. * header: Deprecate LIBGUESTFS_HAVE_* in favour of GUESTFS_HAVE_*. * fuse: Use guestfs_rename to implement rename(2) syscall (RHBZ#895910). * New API: rename: Rename file within the same filesystem (RHBZ#895910). * fuse: If guestfs_last_errno returns 0, don't return no error to FUSE layer. * daemon: Change ln, ln-f (hard-link) APIs to use link(2) instead of external ln (RHBZ#895905). * Fix checksums-out command (RHBZ#895904). * launch: appliance: Fix parsing of QEMU_OPTIONS. * launch: appliance: Small refactoring of virtio-scsi detection code. - enable ruby bindings only in 12.2 or later, ruby is too fragile OBS-URL: https://build.opensuse.org/package/show/Virtualization/libguestfs?expand=0&rev=190
241 lines
7.2 KiB
Diff
241 lines
7.2 KiB
Diff
From f010abe024b47057f814e369b7b647e52d001019 Mon Sep 17 00:00:00 2001
|
|
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>
|
|
---
|
|
df/output.c | 13 +++++++++----
|
|
fish/options.c | 8 +++++++-
|
|
src/guestfs-internal.h | 2 ++
|
|
src/handle.c | 16 ++++++++++++++++
|
|
src/inspect-fs-unix.c | 4 ++--
|
|
src/launch-appliance.c | 3 +++
|
|
src/launch-libvirt.c | 7 +++++++
|
|
test-tool/test-tool.c | 16 +++++++++++++---
|
|
8 files changed, 59 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/df/output.c b/df/output.c
|
|
index 5729dd4..fb33ca1 100644
|
|
--- 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)
|
|
}
|
|
}
|
|
|
|
-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");
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
|
+ 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
|
|
index 384ef43..74703ca 100644
|
|
--- 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);
|
|
}
|
|
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
|
+ 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
|
|
index 49341e2..1303a7e 100644
|
|
--- a/src/guestfs-internal.h
|
|
+++ b/src/guestfs-internal.h
|
|
@@ -318,6 +318,8 @@ struct guestfs_h
|
|
virDomainPtr dom; /* libvirt domain */
|
|
} virt;
|
|
#endif
|
|
+
|
|
+ int use_virtio_blk;
|
|
};
|
|
|
|
/* Per-filesystem data stored for inspect_os. */
|
|
diff --git a/src/handle.c b/src/handle.c
|
|
index cb00a2e..b0d75c1 100644
|
|
--- a/src/handle.c
|
|
+++ b/src/handle.c
|
|
@@ -215,6 +215,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 40f797d..45d50ee 100644
|
|
--- a/src/inspect-fs-unix.c
|
|
+++ b/src/inspect-fs-unix.c
|
|
@@ -1370,7 +1370,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;
|
|
@@ -1447,7 +1447,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-appliance.c b/src/launch-appliance.c
|
|
index a86a8cc..1067d17 100644
|
|
--- a/src/launch-appliance.c
|
|
+++ b/src/launch-appliance.c
|
|
@@ -935,6 +935,9 @@ qemu_supports_virtio_scsi (guestfs_h *g)
|
|
}
|
|
}
|
|
|
|
+ if (g->use_virtio_blk)
|
|
+ g->app.virtio_scsi = 2;
|
|
+
|
|
return g->app.virtio_scsi == 1;
|
|
}
|
|
|
|
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
|
|
index 6ad19de..b8efc4f 100644
|
|
--- a/src/launch-libvirt.c
|
|
+++ b/src/launch-libvirt.c
|
|
@@ -177,6 +177,13 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
|
|
return -1;
|
|
}
|
|
|
|
+#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
|
|
+
|
|
guestfs___launch_send_progress (g, 0);
|
|
TRACE0 (launch_libvirt_start);
|
|
|
|
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
|
|
index d71caed..58cc885 100644
|
|
--- a/test-tool/test-tool.c
|
|
+++ b/test-tool/test-tool.c
|
|
@@ -95,6 +95,16 @@ main (int argc, char *argv[])
|
|
guestfs_h *g;
|
|
char *qemu = NULL;
|
|
int qemu_use_wrapper;
|
|
+ char *disk_name, *partition_name;
|
|
+ int use_virtio_blk = 0;
|
|
+
|
|
+#ifdef GUESTFS_QEMU_NO_VIRTIO_BLK
|
|
+ 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);
|
|
|
|
for (;;) {
|
|
c = getopt_long (argc, argv, options, long_options, &option_index);
|
|
@@ -281,19 +291,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_name, "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", partition_name) == -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, partition_name, "/") == -1) {
|
|
fprintf (stderr,
|
|
_("libguestfs-test-tool: failed to mount /dev/sda1 on /\n"));
|
|
exit (EXIT_FAILURE);
|