RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 853763 - virt-sparsify should use a more robust method to detect the input format
Summary: virt-sparsify should use a more robust method to detect the input format
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libguestfs
Version: 6.4
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Richard W.M. Jones
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On: 853762
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-09-02 18:34 UTC by Richard W.M. Jones
Modified: 2013-02-21 08:38 UTC (History)
6 users (show)

Fixed In Version: libguestfs-1.16.31-2.el6
Doc Type: Bug Fix
Doc Text:
Clone Of: 853762
Environment:
Last Closed: 2013-02-21 08:38:42 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2013:0324 0 normal SHIPPED_LIVE libguestfs bug fix and enhancement update 2013-02-20 20:54:42 UTC

Description Richard W.M. Jones 2012-09-02 18:34:36 UTC
+++ This bug was initially created as a clone of Bug #853762 +++

Description of problem:

Currently virt-sparsify runs the 'file -bsL' command on the
input disk image to try to detect the format.  This is not
robust as 'file' is often broken or might not know about the
disk format.  'file' has also been known to print different
things for different versions of the command, which is why
virt-sparsify breaks in RHEL 6.3:

rhel$ file -bsL /tmp/disk.qcow2 
Qemu Image, Format: Qcow , Version: 2
fedora$ file -bsL /tmp/disk.qcow2 
QEMU QCOW Image (v2), 10485760 bytes

Version-Release number of selected component (if applicable):

libguestfs 1.16.19

How reproducible:

100%

Steps to Reproduce:
1. Use virt-sparsify on a file.
2. Don't specify the --convert argument.

Actual results:

Results will depend on the input format and the version of
'file' installed.  For example on RHEL 6.3 it will detect the
input format as raw, and so produce a raw output file.

Comment 2 Mohua Li 2012-11-07 06:40:21 UTC
hi Rich,

i could found this commit in master branch, but didn't find in 1.16 branch, if we forget to backport this commit?



index 379ccf4..fa729f3 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -351,25 +351,10 @@ let output_format =
     | Some fmt -> fmt           (* user specified input format, use that *)
     | None ->
       (* Don't know, so we must autodetect. *)
-      let cmd = sprintf "file -bsL %s" (Filename.quote indisk) in
-      let chan = open_process_in cmd in
-      let line = input_line chan in
-      let stat = close_process_in chan in
-      (match stat with
-      | WEXITED 0 -> ()
-      | WEXITED _ ->
-        error (f_"external command failed: %s") cmd
-      | WSIGNALED i ->
-        error (f_"external command '%s' killed by signal %d") cmd i
-      | WSTOPPED i ->
-        error (f_"external command '%s' stopped by signal %d") cmd i
-      );
-      if string_prefix line "QEMU QCOW Image (v2)" then
-        "qcow2"
-      else if string_find line "VirtualBox" >= 0 then
-        "vdi"
-      else
-        "raw" (* XXX guess *)
+      match g#disk_format indisk  with
+      | "unknown" ->
+        error (f_"cannot detect input disk format; use the --format parameter")
+      | fmt -> fmt
 
 (* Now run qemu-img convert which copies the overlay to the
  * destination and automatically does sparsification.


but in 1.16, still get this, 


 *)
let output_format =
  match convert with
  | Some fmt -> fmt             (* user specified output conversion *)
  | None ->
    match format with
    | Some fmt -> fmt           (* user specified input format, use that *)
    | None ->
      (* Don't know, so we must autodetect. *)
      let cmd = sprintf "file -bsL %s" (Filename.quote indisk) in
      let chan = open_process_in cmd in
      let line = input_line chan in
      let stat = close_process_in chan in
      (match stat with
      | WEXITED 0 -> ()
      | WEXITED _ ->
        error "external command failed: %s" cmd
      | WSIGNALED i ->
        error "external command '%s' killed by signal %d" cmd i
      | WSTOPPED i ->
        error "external command '%s' stopped by signal %d" cmd i
      );
      if string_prefix line "QEMU QCOW Image (v2)" then
        "qcow2"
      else if string_find line "VirtualBox" >= 0 then
        "vdi"
      else
        "raw" (* XXX guess *)

Comment 3 Richard W.M. Jones 2012-11-07 07:14:09 UTC
This is the patch that I added to RHEL 6.  Note it fixes
the problem (different 'file' command output), but it does
not use the guestfs_disk_format method.  The reason for not
using the guestfs_disk_format method is that it doesn't exist
in RHEL 6 / libguestfs 1.16.  Backporting that method would
be possible, but I opted for the simple (safer?) one-line
fix instead.


commit 9a772e90efef6b0313367600f3ff71916fee0ecc
Author: Richard W.M. Jones <rjones>
Date:   Thu Sep 27 16:36:56 2012 +0100

    RHEL 6: Change virt-sparsify to work with old 'file' command (RHBZ#853763).
    
    The old 'file' command in RHEL produces different output from
    upstream / Fedora:
    
      rhel$ file -bsL /tmp/disk.qcow2
      Qemu Image, Format: Qcow , Version: 2
      fedora$ file -bsL /tmp/disk.qcow2
      QEMU QCOW Image (v2), 10485760 bytes
    
    Upstream solves this in a more robust way, but that would involve
    difficult backporting of a new API.

diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index 544c8ab..bf0d3d0 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -299,7 +299,7 @@ let output_format =
       | WSTOPPED i ->
         error "external command '%s' stopped by signal %d" cmd i
       );
-      if string_prefix line "QEMU QCOW Image (v2)" then
+      if string_prefix line "Qemu Image, Format: Qcow , Version: 2" then
         "qcow2"
       else if string_find line "VirtualBox" >= 0 then
         "vdi"

Comment 6 errata-xmlrpc 2013-02-21 08:38:42 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2013-0324.html


Note You need to log in before you can comment on or make changes to this bug.