K 10 svn:author V 6 marcel K 8 svn:date V 27 2014-09-28T00:43:04.307074Z K 7 svn:log V 1826 Start performance optimizations: Output formats typically need to know whether a sequence of blocks has data or not. They use this to determine whether to allocate disk space for them or not. The image_data() function provides that functionality, but is implemented by reading the amount of blocks from the temporary file and comparing that with zeroes. The QCOW format needs to go over the image 3 times and every time we read from the temporary file. We can speed this up by building a "chunk" list in memory while we read the partition data. Each chunk is a sequence of blocks that is either defined as a gap (i.e. all zeroes) or defined as containing data. For each chunk we keep track of the file and the offset in that file where the chunk's data comes from. This allows us handle regular files and in particular sparse files more optimally. For sparse files we can trivially build a chunk for each of the holes in the parse file by using SEEK_HOLE and SEEK_DATA. The data regions still need to be read to handle zeroe blocks for block sizes smaller that the underlying file system's block size. However, we don't have to copy the data into a temporary file anymore. For anything but regular files, we still use the temporary file. We call it a swap file now. With that all data can be mapped and unmapped as we need to access it. This commit implements the creation of the chunk list and the swap file usage for non-regular files (i.e. streams). Mappable files are now handled like streams, so that needs some work. The big part that is missing is the use of the chunk list for determining whether a sequence of blocks has data and all the handling of writing the image data to the output file. As such: this commit breaks mkimg and makes it useless. It's a good WIP to safe thogh -- hence doing it on my branch. END