[libvirt] [PATCH] storage: Ensure 'qemu-img resize' size arg is a 512 multiple

qemu-img resize will fail with "The new size must be a multiple of 512" if libvirt doesn't round it first. This fixes rhbz#951495 Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- src/storage/storage_backend_fs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 9b83e57..99973b0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1219,6 +1219,10 @@ virStorageBackendFilesystemResizeQemuImg(const char *path, return -1; } + /* Round capacity up to the closest 512 multiple as qemu-img errors out + * on sizes which are not a multiple of 512 */ + capacity = (capacity + 511) / 512 * 512; + cmd = virCommandNew(img_tool); virCommandAddArgList(cmd, "resize", path, NULL); virCommandAddArgFormat(cmd, "%llu", capacity); -- 1.8.2.1

On 14/05/13 21:50, Christophe Fergeau wrote:
qemu-img resize will fail with "The new size must be a multiple of 512" if libvirt doesn't round it first. This fixes rhbz#951495
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- src/storage/storage_backend_fs.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 9b83e57..99973b0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1219,6 +1219,10 @@ virStorageBackendFilesystemResizeQemuImg(const char *path, return -1; }
+ /* Round capacity up to the closest 512 multiple as qemu-img errors out + * on sizes which are not a multiple of 512 */ + capacity = (capacity + 511) / 512 * 512;
There is macro VIR_DIV_UP for the purpose. And should we document it somewhere? I guess one will file bug like "specify 1 for vol-resize, but the result is 512". Osier

On Tue, May 14, 2013 at 09:56:44PM +0800, Osier Yang wrote:
On 14/05/13 21:50, Christophe Fergeau wrote:
qemu-img resize will fail with "The new size must be a multiple of 512" if libvirt doesn't round it first. This fixes rhbz#951495
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- src/storage/storage_backend_fs.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 9b83e57..99973b0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1219,6 +1219,10 @@ virStorageBackendFilesystemResizeQemuImg(const char *path, return -1; } + /* Round capacity up to the closest 512 multiple as qemu-img errors out + * on sizes which are not a multiple of 512 */ + capacity = (capacity + 511) / 512 * 512;
There is macro VIR_DIV_UP for the purpose. And should we document it somewhere? I guess one will file bug like "specify 1 for vol-resize, but the result is 512".
Actually VIR_DIV_UP isn't what we're wanting todo here. We're just rounding-up, not scaling. We could add a VIR_ROUND_UP macro though which just encapsulates this logic Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Tue, May 14, 2013 at 09:56:44PM +0800, Osier Yang wrote:
On 14/05/13 21:50, Christophe Fergeau wrote:
qemu-img resize will fail with "The new size must be a multiple of 512" if libvirt doesn't round it first. This fixes rhbz#951495
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- src/storage/storage_backend_fs.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 9b83e57..99973b0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1219,6 +1219,10 @@ virStorageBackendFilesystemResizeQemuImg(const char *path, return -1; } + /* Round capacity up to the closest 512 multiple as qemu-img errors out + * on sizes which are not a multiple of 512 */ + capacity = (capacity + 511) / 512 * 512;
There is macro VIR_DIV_UP for the purpose.
Ah thanks, I knew there had to be such a macro, but could not find it ;)
And should we document it somewhere?
In v2 I've added a short blob about the rounding in virStorageVolResize API doc, hopefully that's a good place for that. Christophe

On 05/14/13 15:50, Christophe Fergeau wrote:
qemu-img resize will fail with "The new size must be a multiple of 512" if libvirt doesn't round it first. This fixes rhbz#951495
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> --- src/storage/storage_backend_fs.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 9b83e57..99973b0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1219,6 +1219,10 @@ virStorageBackendFilesystemResizeQemuImg(const char *path, return -1; }
+ /* Round capacity up to the closest 512 multiple as qemu-img errors out + * on sizes which are not a multiple of 512 */ + capacity = (capacity + 511) / 512 * 512;
Please use the macro introduced specifically for this purpose for the first part. /* divide value by size, rounding up */ # define VIR_DIV_UP(value, size) (((value) + (size) - 1) / (size)) defined in internal.h
+ cmd = virCommandNew(img_tool); virCommandAddArgList(cmd, "resize", path, NULL); virCommandAddArgFormat(cmd, "%llu", capacity);
Peter
participants (4)
-
Christophe Fergeau
-
Daniel P. Berrange
-
Osier Yang
-
Peter Krempa