diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h index 073e665d3..290d1f948 100644 --- a/lib/guestfs-internal.h +++ b/lib/guestfs-internal.h @@ -797,7 +797,7 @@ extern struct version guestfs_int_qemu_version (guestfs_h *g, struct qemu_data * extern int guestfs_int_qemu_supports_device (guestfs_h *g, const struct qemu_data *, const char *device_name); extern bool guestfs_int_platform_has_kvm (guestfs_h *g, const struct qemu_data *data); extern char *guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source *src); -extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, const struct version *qemu_version); +extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv); extern char *guestfs_int_qemu_escape_param (guestfs_h *g, const char *param); extern void guestfs_int_free_qemu_data (struct qemu_data *); diff --git a/lib/launch-direct.c b/lib/launch-direct.c index 6b495dfa1..65541dbe7 100644 --- a/lib/launch-direct.c +++ b/lib/launch-direct.c @@ -221,21 +221,15 @@ add_drive_standard_params (guestfs_h *g, struct backend_direct_data *data, switch (drv->discard) { case discard_disable: /* Since the default is always discard=ignore, don't specify it - * on the command line. This also avoids unnecessary breakage - * with qemu < 1.5 which didn't have the option at all. + * on the command line. */ break; case discard_enable: - if (!guestfs_int_discard_possible (g, drv, &data->qemu_version)) + if (!guestfs_int_discard_possible (g, drv)) return -1; /*FALLTHROUGH*/ case discard_besteffort: - /* I believe from reading the code that this is always safe as - * long as qemu >= 1.5. - */ - if (guestfs_int_version_ge (&data->qemu_version, 1, 5, 0)) - append_list ("discard=unmap"); - break; + append_list ("discard=unmap"); } } else { diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c index c690a444a..e02a86f89 100644 --- a/lib/launch-libvirt.c +++ b/lib/launch-libvirt.c @@ -1651,16 +1651,11 @@ construct_libvirt_xml_disk_driver_qemu (guestfs_h *g, */ break; case discard_enable: - if (!guestfs_int_discard_possible (g, drv, &data->qemu_version)) + if (!guestfs_int_discard_possible (g, drv)) return -1; /*FALLTHROUGH*/ case discard_besteffort: - /* I believe from reading the code that this is always safe as - * long as qemu >= 1.5. - */ - if (guestfs_int_version_ge (&data->qemu_version, 1, 5, 0)) - discard_unmap = true; - break; + discard_unmap = true; } start_element ("driver") { diff --git a/lib/qemu.c b/lib/qemu.c index ac8bf678b..c96d66bda 100644 --- a/lib/qemu.c +++ b/lib/qemu.c @@ -820,31 +820,15 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, } /** - * Test if discard is both supported by qemu AND possible with the - * underlying file or device. This returns C<1> if discard is - * possible. It returns C<0> if not possible and sets the error to - * the reason why. + * Test if discard is possible with the underlying file or device. + * This returns C<1> if discard is possible. It returns C<0> if not + * possible and sets the error to the reason why. * * This function is called when the user set C. */ bool -guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, - const struct version *qemu_version) +guestfs_int_discard_possible (guestfs_h *g, struct drive *drv) { - /* qemu >= 1.5. This was the first version that supported the - * discard option on -drive at all. - */ - bool qemu15 = guestfs_int_version_ge (qemu_version, 1, 5, 0); - /* qemu >= 1.6. This was the first version that supported unmap on - * qcow2 backing files. - */ - bool qemu16 = guestfs_int_version_ge (qemu_version, 1, 6, 0); - - if (!qemu15) - NOT_SUPPORTED (g, false, - _("discard cannot be enabled on this drive: " - "qemu < 1.5")); - /* If it's an overlay, discard is not possible (on the underlying * file). This has probably been caught earlier since we already * checked that the drive is !readonly. Nevertheless ... @@ -861,17 +845,11 @@ guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, _("discard cannot be enabled on this drive: " "you have to specify the format of the file")); } - else if (STREQ (drv->src.format, "raw")) + else if (STREQ (drv->src.format, "raw") || STREQ (drv->src.format, "qcow2")) /* OK */ ; - else if (STREQ (drv->src.format, "qcow2")) { - if (!qemu16) - NOT_SUPPORTED (g, false, - _("discard cannot be enabled on this drive: " - "qemu < 1.6 cannot do discard on qcow2 files")); - } else { - /* It's possible in future other formats will support discard, but - * currently (qemu 1.7) none of them do. + /* It's possible other formats support discard, but we can enable + * them on a case-by-case basis. */ NOT_SUPPORTED (g, false, _("discard cannot be enabled on this drive: "