Skip to contentSkip to conversation

libvirt: Using rbd_create3 to create format 2 images

PATCH Wido den Hollander 2 participants 5 messages Aug 30, 2013 – Sep 3, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

I created the attached patch to have libvirt create images with format 2 by default, this would simplify the CloudStack code and could also help other projects.

The problem with libvirt is that there is no mechanism to supply information like order, features, stripe unit and count to the rbd_create3 method, so it's now hardcoded in libvirt.

Any comments on this patch before I fire it of to the libvirt guys?

Signature · 5 lines
Wido den Hollander
42on B.V.

Phone: +31 (0)20 700 9902
Skype: contact42on

From 2731f7c131d938ed5029bf8343877fcc4d950a0f Mon Sep 17 00:00:00 2001
From: Wido den Hollander <[email protected]>
Date: Fri, 30 Aug 2013 10:50:25 +0200
Subject: [PATCH] rbd: Use rbd_create3 to create RBD format 2 images by
default

This new RBD format supports snapshotting and cloning. By having libvirt create images in format 2 end-users of the created images can benefit of the new RBD format.

---
 src/storage/storage_backend_rbd.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/storage/storage_backend_rbd.c +5 -1
index d9e1789..e5d720e 100644
@@ -443,6 +443,9 @@ static int virStorageBackendRBDCreateVol(virConnectPtr conn,
     ptr.cluster = NULL;
     ptr.ioctx = NULL;
     int order = 0;
+    uint64_t features = 3;
+    uint64_t stripe_count = 1;
+    uint64_t stripe_unit = 4194304;
     int ret = -1;
 
     VIR_DEBUG("Creating RBD image %s/%s with size %llu",
@@ -467,7 +470,8 @@ static int virStorageBackendRBDCreateVol(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (rbd_create(ptr.ioctx, vol->name, vol->capacity, &order) < 0) {
+    if (rbd_create3(ptr.ioctx, vol->name, vol->capacity, features, &order,
+                    stripe_count, stripe_unit) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create volume '%s/%s'"),
                        pool->def->source.name,
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 11 lines · Wido den Hollander

Hi,

I created the attached patch to have libvirt create images with format 2 by default, this would simplify the CloudStack code and could also help other projects.

The problem with libvirt is that there is no mechanism to supply information like order, features, stripe unit and count to the rbd_create3 method, so it's now hardcoded in libvirt.

Any comments on this patch before I fire it of to the libvirt guys?

Seems ok to me. They might want you to detect whether the function is there and compile without it if librbd doesn't support it (rbd_create3 first appeared in bobtail).

#2 lore raw
Quoted 11 lines · Josh Durgin
Quoted 10 lines · Wido den Hollander

Hi,

I created the attached patch to have libvirt create images with format 2 by default, this would simplify the CloudStack code and could also help other projects.

The problem with libvirt is that there is no mechanism to supply information like order, features, stripe unit and count to the rbd_create3 method, so it's now hardcoded in libvirt.

Quoted 6 lines
Quoted 1 line

Any comments on this patch before I fire it of to the libvirt guys?

Seems ok to me. They might want you to detect whether the function is there and compile without it if librbd doesn't support it (rbd_create3 first appeared in bobtail).

Good one. Although I don't think anybody is still running Argonaut I'll do a version check of librbd and switch to rbd_create if needed.

Signature · 5 lines
Wido den Hollander
42on B.V.

Phone: +31 (0)20 700 9902
Skype: contact42on
#3 lore raw
Quoted 14 lines · Wido den Hollander
Quoted 13 lines · Josh Durgin
Quoted 11 lines · Wido den Hollander

Hi,

I created the attached patch to have libvirt create images with format 2 by default, this would simplify the CloudStack code and could also help other projects.

The problem with libvirt is that there is no mechanism to supply information like order, features, stripe unit and count to the rbd_create3 method, so it's now hardcoded in libvirt.

Any comments on this patch before I fire it of to the libvirt guys?

Quoted 9 lines
Quoted 4 lines

Seems ok to me. They might want you to detect whether the function is there and compile without it if librbd doesn't support it (rbd_create3 first appeared in bobtail).

Good one. Although I don't think anybody is still running Argonaut I'll do a version check of librbd and switch to rbd_create if needed.

What do you think of the attached patch Josh?

Signature · 5 lines
Wido den Hollander
42on B.V.

Phone: +31 (0)20 700 9902
Skype: contact42on

From 68e212483a43196626413f2e487e2d6bb9c69726 Mon Sep 17 00:00:00 2001
From: Wido den Hollander <[email protected]>
Date: Fri, 30 Aug 2013 10:50:25 +0200
Subject: [PATCH] rbd: Use rbd_create3 to create RBD format 2 images by
default

This new RBD format supports snapshotting and cloning. By having libvirt create images in format 2 end-users of the created images can benefit of the new RBD format.

---
 src/storage/storage_backend_rbd.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
src/storage/storage_backend_rbd.c +10 -0
index d9e1789..2d4edc2 100644
@@ -443,6 +443,11 @@ static int virStorageBackendRBDCreateVol(virConnectPtr conn,
     ptr.cluster = NULL;
     ptr.ioctx = NULL;
     int order = 0;
+    #if LIBRBD_VERSION_CODE > 259
+    uint64_t features = 3;
+    uint64_t stripe_count = 1;
+    uint64_t stripe_unit = 4194304;
+    #endif
     int ret = -1;
 
     VIR_DEBUG("Creating RBD image %s/%s with size %llu",
@@ -467,7 +472,12 @@ static int virStorageBackendRBDCreateVol(virConnectPtr conn,
         goto cleanup;
     }
 
+    #if LIBRBD_VERSION_CODE > 259
+    if (rbd_create3(ptr.ioctx, vol->name, vol->capacity, features, &order,
+                    stripe_count, stripe_unit) < 0) {
+    #else
     if (rbd_create(ptr.ioctx, vol->name, vol->capacity, &order) < 0) {
+    #endif
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create volume '%s/%s'"),
                        pool->def->source.name,
Signature · 1 line
1.7.9.5
#4 lore raw
Quoted 21 lines · Wido den Hollander
Quoted 20 lines · Wido den Hollander
Quoted 18 lines · Josh Durgin
Quoted 7 lines · Wido den Hollander

Hi,

I created the attached patch to have libvirt create images with format 2
by default, this would simplify the CloudStack code and could also help other projects.

Quoted 5 lines

The problem with libvirt is that there is no mechanism to supply information like order, features, stripe unit and count to the rbd_create3 method, so it's now hardcoded in libvirt.

Any comments on this patch before I fire it of to the libvirt guys?

Seems ok to me. They might want you to detect whether the function is there and compile without it if librbd doesn't support it (rbd_create3 first appeared in bobtail).

Quoted 5 lines
Quoted 4 lines

Good one. Although I don't think anybody is still running Argonaut I'll do a version check of librbd and switch to rbd_create if needed.

What do you think of the attached patch Josh?

It be a bit cleaner to make a helper to call the rbd_create() or rbd_create3() so you only need one check of LIBRBD_VERSION_CODE.

It looks like v0.55 was the first release which contained rbd_create3(), and the version code for that is 261, so the version code check is off by one.

Josh