 b87ac96651
			
		
	
	
		b87ac96651
		
	
	
	
	
		
			
			Rather than open-coding two different ways to check for an unwanted negative sign, reuse the same code in both functions. That way, if we decide down the road to accept "-0" instead of rejecting it, we have fewer places to change. Also, it means we now get ERANGE instead of EINVAL for negative values in qemu_strtosz, which is reasonable for what it represents. This in turn changes the expected output of a couple of iotests. The change is not quite complete: negative fractional scaled values can trip us up. This will be fixed in a later patch addressing other issues with fractional scaled values. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Hanna Czenczek <hreitz@redhat.com> Message-Id: <20230522190441.64278-18-eblake@redhat.com>
		
			
				
	
	
		
			221 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			221 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| QA output created by 049
 | |
| === Check correct interpretation of suffixes for image size ===
 | |
| 
 | |
| == 1. Traditional size parameter ==
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024b
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1k
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1K
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1048576 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1G
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1T
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1099511627776 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0b
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5k
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1536 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5K
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1536 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1572864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5G
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1610612736 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5T
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1649267441664 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| == 2. Specifying size via -o ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1024 TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1024b TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1k TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1K TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1M TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1048576 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1G TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1T TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1099511627776 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1024.0 TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1024.0b TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1024 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1.5k TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1536 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1.5K TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1536 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1.5M TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1572864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1.5G TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1610612736 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1.5T TEST_DIR/t.qcow2
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1649267441664 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| == 3. Invalid sizes ==
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1024
 | |
| qemu-img: Invalid image size specified. Must be between 0 and 9223372036854775807.
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=-1024 TEST_DIR/t.qcow2
 | |
| qemu-img: TEST_DIR/t.qcow2: Value '-1024' is out of range for parameter 'size'
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1k
 | |
| qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suffixes for
 | |
| qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=-1k TEST_DIR/t.qcow2
 | |
| qemu-img: TEST_DIR/t.qcow2: Parameter 'size' expects a non-negative number below 2^64
 | |
| Optional suffix k, M, G, T, P or E means kilo-, mega-, giga-, tera-, peta-
 | |
| and exabytes, respectively.
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- 1kilobyte
 | |
| qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suffixes for
 | |
| qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=1kilobyte TEST_DIR/t.qcow2
 | |
| qemu-img: TEST_DIR/t.qcow2: Parameter 'size' expects a non-negative number below 2^64
 | |
| Optional suffix k, M, G, T, P or E means kilo-, mega-, giga-, tera-, peta-
 | |
| and exabytes, respectively.
 | |
| 
 | |
| qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- foobar
 | |
| qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suffixes for
 | |
| qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=foobar TEST_DIR/t.qcow2
 | |
| qemu-img: TEST_DIR/t.qcow2: Parameter 'size' expects a non-negative number below 2^64
 | |
| Optional suffix k, M, G, T, P or E means kilo-, mega-, giga-, tera-, peta-
 | |
| and exabytes, respectively.
 | |
| 
 | |
| == 4. Specify size twice (-o and traditional parameter) ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o size=10M TEST_DIR/t.qcow2 20M
 | |
| qemu-img: TEST_DIR/t.qcow2: The image size must be specified only once
 | |
| 
 | |
| == Check correct interpretation of suffixes for cluster size ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1024 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1024 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1024b TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1024 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1k TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1024 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1K TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1024 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1M TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1048576 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1024.0 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1024 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=1024.0b TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=1024 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=0.5k TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=512 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=0.5K TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=512 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o cluster_size=0.5M TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=524288 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| == Check compat level option ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=0.10 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=0.10 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=1.1 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=1.1 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=0.42 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=0.42 lazy_refcounts=off refcount_bits=16
 | |
| qemu-img: TEST_DIR/t.qcow2: Parameter 'version' does not accept value '0.42'
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=foobar TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=foobar lazy_refcounts=off refcount_bits=16
 | |
| qemu-img: TEST_DIR/t.qcow2: Parameter 'version' does not accept value 'foobar'
 | |
| 
 | |
| == Check preallocation option ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o preallocation=off TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o preallocation=metadata TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=metadata compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o preallocation=1234 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=1234 compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| qemu-img: TEST_DIR/t.qcow2: Parameter 'preallocation' does not accept value '1234'
 | |
| 
 | |
| == Check encryption option ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o encryption=off TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 encryption=off cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 encryption=on encrypt.key-secret=sec0 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| == Check lazy_refcounts option (only with v3) ==
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=1.1,lazy_refcounts=off TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=1.1 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=1.1,lazy_refcounts=on TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=1.1 lazy_refcounts=on refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=0.10,lazy_refcounts=off TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=0.10 lazy_refcounts=off refcount_bits=16
 | |
| 
 | |
| qemu-img create -f qcow2 -o compat=0.10,lazy_refcounts=on TEST_DIR/t.qcow2 64M
 | |
| Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 compat=0.10 lazy_refcounts=on refcount_bits=16
 | |
| qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibility level 1.1 and above (use version=v3 or greater)
 | |
| 
 | |
| == Expect error when backing file name is empty string ==
 | |
| 
 | |
| qemu-img create -f qcow2 -b  TEST_DIR/t.qcow2 1M
 | |
| qemu-img: TEST_DIR/t.qcow2: Expected backing file name, got empty string
 | |
| 
 | |
| *** done
 |