Bug 735270 - qemu-img: can't parse negative value of qemu-img resize command.
Summary: qemu-img: can't parse negative value of qemu-img resize command.
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: qemu-kvm
Version: 6.1
Hardware: x86_64
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Kevin Wolf
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-09-02 04:55 UTC by Hajime Taira
Modified: 2013-04-10 07:59 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-04-05 09:42:15 UTC


Attachments (Terms of Use)

Description Hajime Taira 2011-09-02 04:55:26 UTC
Description of problem:
qemu-img can't parse negative value of qemu-img resize command.

I tested same issue in Fedora 16. It fixed.
But in RHEL6.1, It occured.

How reproducible:
# qemu-img create -f raw test.img 10G
Formatting 'test.img', fmt=raw size=10737418240 
# qemu-img resize test.img 9G <- It success.
Image resized.
# qemu-img resize test.img -1G <- It failed.
resize: invalid option -- '1'
  
Actual results:
# qemu-img resize test.img -1G
resize: invalid option -- '1'

Expected results:
# qemu-img resize test.img -1G
Image resized.
# ls -l test.img
-rw-r--r--. 1 root root 9663676416 Sep  2 13:53 test.img

Additional info:
This issue fixed by following patch in upstream.
http://lists.gnu.org/archive/html/qemu-devel/2011-04/msg02551.html

Comment 3 Kevin Wolf 2011-09-05 10:50:54 UTC
Fixed in upstream commit e80fec7f. Will backport to RHEL.

Comment 5 Hajime Taira 2011-09-06 00:13:13 UTC
Additional information. please see manpage of qemu-img in Fedora 15 or Upstream.

QEMU-IMG(1)                                                           QEMU-IMG(1)

NAME
       qemu-img - QEMU disk image utility

SYNOPSIS
       usage: qemu-img command [command options]

OPTIONS
       The following commands are supported:

(snip)

       resize filename [+ | -]size
           Change the disk image as if it had been created with size.

           Before using this command to shrink a disk image, you MUST use file
           system and partitioning tools inside the VM to reduce allocated file
           systems and partition sizes accordingly.  Failure to do so will result
           in data loss!

           After using this command to grow a disk image, you must use file
           system and partitioning tools inside the VM to actually begin using
           the new space on the device.

Comment 7 Chao Yang 2011-11-22 06:13:13 UTC
Reproduced this issue with qemu-kvm-0.12.1.2-2.209.el6.x86_64. 
Got following output by:
# qemu-img --help
qemu-img version 0.12.1, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility

(snip)

  resize filename [+ | -]size

Steps:  
1. create a raw format image file:
# qemu-img create -f raw test.raw 10G
Formatting 'test.raw', fmt=raw size=10737418240 
# qemu-img info test.raw 
image: test.raw
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 0

2. resize this image file to 6G:
# qemu-img resize test.raw 6G
Image resized.
# qemu-img info test.raw 
image: test.raw
file format: raw
virtual size: 6.0G (6442450944 bytes)
disk size: 0

3. resize to 20G
# qemu-img resize test.raw 20G
Image resized.
# qemu-img info test.raw 
image: test.raw
file format: raw
virtual size: 20G (21474836480 bytes)
disk size: 0

4. increase it by +2G
# qemu-img resize test.raw +2G
Image resized.
# qemu-img info test.raw 
image: test.raw
file format: raw
virtual size: 22G (23622320128 bytes)
disk size: 0

5. decrease it by 2G
# qemu-img resize test.raw -2G
resize: invalid option -- '2'


Marking qa_ack+ according to above info.

Comment 9 Jamie Bainbridge 2012-05-23 00:37:10 UTC
Interestingly, you can work around this by specifying the negative value as an addition

eg: to remove 2gb from image
# qemu-img resize image.img "+-2G"

Comment 11 Ademar Reis 2012-07-27 15:06:08 UTC
Deferring to RHEL 6.5 because this is low priority and we're over capacity. This kind of behavior is quite common in getopt(3) applications. The workaround is to use -- before the option (or +-2G, as suggested by Jamie).

Comment 12 Hajime Taira 2012-07-29 09:35:44 UTC
Why discuss this about 1 year?
I propose new sub-commands "qemu-img extend" and "qemu-img reduce"

eg. To extend 2GB from image
# qemu-img extend 2GB image.img

eg. Do not give negative size parameter for "qemu-img resize",
    To reduce 2GB from image
# qemu-img reduce 2GB image.img

Comment 13 Werner Gold 2013-01-24 10:51:43 UTC
Still broken in RHEL 6.3

Comment 16 nigil 2013-04-10 07:59:45 UTC
Still broken in RHEL 6.4


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