On Tue, Dec 06, 2011 at 04:20:56PM +0000, Alex Bligh wrote: > qemu-img convert appears to support block devices as input, but not > as output. That is irritating, as when using qemu-img convert to > convert qcow to raw on a block partition, an intermediate file has > to be used, which slows things down and pointlessly uses disk space. > > The problem is that ftruncate() is being called on the output file > in order ensure it is sufficiently large, and this fails on > block devices. > > I appreciate there may be other calls that fail depending on the > input file format, but these will presumably be error checked > at the time. > > Is it therefore worth skipping the ftruncate() if the block device > is large enough, and at least attempting to proceed further? Something > like the following (not-even compile tested) patch?
It probably should share the code with raw_truncate. That is factor a new raw_truncate_common that is equivalent to raw_truncate but takes a file descriptor instead of a block driver state and then use it for both raw_truncate and raw_create.