File libvirt-storage-lvm-lvcreate-fails-with-allocation-0-don-t-do-that.patch of Package libvirt

From ac76180de528670c6aaaeff2b0c36cbffd480c65 Mon Sep 17 00:00:00 2001
Message-Id: <ac76180de528670c6aaaeff2b0c36cbffd480c65.1373271639.git.jdenemar@redhat.com>
From: Cole Robinson <crobinso@redhat.com>
Date: Wed, 6 Mar 2013 21:15:36 +0100
Subject: [PATCH] storage: lvm: lvcreate fails with allocation=0, don't do that

https://bugzilla.redhat.com/show_bug.cgi?id=912179

On F17 at least, this command fails:

$ sudo /usr/sbin/lvcreate --name sparsetest -L 0K --virtualsize 16384K vgvirt
  Unable to create new logical volume with no extents

Which is unfortunate since allocation=0 is what virt-manager tries to use
by default.

Rather than telling the user 'don't do that', let's just give them the
smallest allocation possible if alloc=0 is requested.

https://bugzilla.redhat.com/show_bug.cgi?id=866481
(cherry picked from commit 9f0e9cba27b3e2b8409f2ce1c0ed4d24d677be9b)
---
 src/storage/storage_backend_logical.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 99b403d..c21cb45 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -727,7 +727,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
                                NULL);
     virCommandAddArg(cmd, "-L");
     if (vol->capacity != vol->allocation) {
-        virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->allocation, 1024));
+        virCommandAddArgFormat(cmd, "%lluK",
+                VIR_DIV_UP(vol->allocation ? vol->allocation : 1, 1024));
         virCommandAddArg(cmd, "--virtualsize");
     }
     virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
-- 
1.8.2.1

openSUSE Build Service is sponsored by