[libvirt] [PATCH] fix vol-create when target allocation=0

Chunyan Liu cyliu at suse.com
Mon Aug 24 05:50:41 UTC 2015


Regression is introduced by commit e30297b0. After that, it will
report "Cannot fill file" error with following xml file:
<volume>
  <name>virtinst-vmlinuz-xen.tP1NHh</name>
  <capacity>4343792</capacity>
  <allocation>0</allocation>
  <target>
    <format type="raw"/>
    <nocow/>
  </target>
</volume>
Because of this, installing xen pv guest with virt-manager fails.

Reason is: posix_fallocate(int fd, off_t offset, off_t len) will
return EINVAL when len is equal to 0. So, this patch adds a check
before calling safezero().

Signed-off-by: Chunyan Liu <cyliu at suse.com>
---
 src/storage/storage_backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index db49739..2a265af 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -455,7 +455,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
         pos = inputvol->target.capacity - remain;
     }
 
-    if (need_alloc) {
+    if (need_alloc && (vol->target.allocation > pos)) {
         if (safezero(fd, pos, vol->target.allocation - pos) < 0) {
             ret = -errno;
             virReportSystemError(errno, _("cannot fill file '%s'"),
-- 
2.1.4




More information about the libvir-list mailing list