Skip to contentSkip to conversation

block/rbd: implement .bdrv_get_allocated_file_size callback

PATCH Superseded Stefano Garzarella 3 participants 10 messages May 10, 2019 – Jul 3, 2019 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 block/rbd: implement .bdrv_get_allocated_file_size callback

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +54 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+
+    /*
+     * rbd_diff_iterate2(), if the source snapshot name is NULL, invokes
+     * the callback on all allocated regions of the image.
+     */
+    r = rbd_diff_iterate2(s->image, NULL, 0,
+                          bs->total_sectors * BDRV_SECTOR_SIZE, 0, 1,
+                          &rbd_allocated_size_cb, &alloc_size);
+    if (r < 0) {
+        return r;
+    }
+
+    return alloc_size;
+}
+
 static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs,
                                              int64_t offset,
                                              PreallocMode prealloc,
@@ -1254,6 +1307,7 @@ static BlockDriver bdrv_rbd = {
     .bdrv_get_info          = qemu_rbd_getinfo,
     .create_opts            = &qemu_rbd_create_opts,
     .bdrv_getlength         = qemu_rbd_getlength,
+    .bdrv_get_allocated_file_size = qemu_rbd_get_allocated_file_size,
     .bdrv_co_truncate       = qemu_rbd_co_truncate,
     .protocol_name          = "rbd",
 
Signature · 1 line
2.20.1
#1 lore raw

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Quoted 37 lines · Stefano Garzarella

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Quoted 5 lines
block/rbd.c +5 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 10 lines
block/rbd.c +10 -0
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1098

Quoted 11 lines
block/rbd.c +11 -0
+    /*
+     * rbd_diff_iterate2(), if the source snapshot name is NULL, invokes
+     * the callback on all allocated regions of the image.
+     */
+    r = rbd_diff_iterate2(s->image, NULL, 0,
+                          bs->total_sectors * BDRV_SECTOR_SIZE, 0, 1,
+                          &rbd_allocated_size_cb, &alloc_size);
+    if (r < 0) {
+        return r;
+    }
+

I guess I'll take your word for it. ¯\_(ツ)_/¯

Quoted 15 lines
block/rbd.c +4 -0
+    return alloc_size;
+}
+
 static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs,
                                              int64_t offset,
                                              PreallocMode prealloc,
@@ -1254,6 +1307,7 @@ static BlockDriver bdrv_rbd = {
     .bdrv_get_info          = qemu_rbd_getinfo,
     .create_opts            = &qemu_rbd_create_opts,
     .bdrv_getlength         = qemu_rbd_getlength,
+    .bdrv_get_allocated_file_size = qemu_rbd_get_allocated_file_size,
     .bdrv_co_truncate       = qemu_rbd_co_truncate,
     .protocol_name          = "rbd",
 
#2 lore raw
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Quoted 54 lines · Stefano Garzarella
Quoted 37 lines

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

Quoted 5 lines

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Good question!
I didn't find any docs, but looking in the ceph tests test/librbd/fsx.cc, they print an error message if the return value is less than 0.

A 'get_flags' implemented in cls/rbd/cls_rbd.cc for example returns 0 at the end and -EINVAL in a try/catch. It also uses 'read_key()' that in some cases returns -EIO, so I hope that the error returned by rbd_get_flags() is one of the errors defined in errno.h

Quoted 10 lines
Quoted 10 lines
block/rbd.c +10 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
Quoted 8 lines

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 5 lines
block/rbd.c +5 -0
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

Unfortunately no :(
As Jason suggested, I followed what libvirt did in the volStorageBackendRBDUseFastDiff() [src/storage/storage_backend_rbd.c]

Quoted 4 lines

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

Sure, -ENOTSUP is absolutely better!

Quoted 3 lines

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

I hope they return an errno.h errors, but I'm not sure if the meaning make sense for us.

Do you think is better to return -ENOTSUP or -EIO when librbd calls fail?

Thanks for your comments,
Stefano

#3 lore raw
Quoted 8 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

Quoted 100 lines
Quoted 54 lines · Stefano Garzarella
Quoted 37 lines

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

Quoted 5 lines

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Good question!
I didn't find any docs, but looking in the ceph tests test/librbd/fsx.cc, they print an error message if the return value is less than 0.

A 'get_flags' implemented in cls/rbd/cls_rbd.cc for example returns 0 at the end and -EINVAL in a try/catch. It also uses 'read_key()' that in some cases returns -EIO, so I hope that the error returned by rbd_get_flags() is one of the errors defined in errno.h

Quoted 10 lines
Quoted 10 lines
block/rbd.c +10 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
Quoted 8 lines

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 5 lines
block/rbd.c +5 -0
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

Unfortunately no :(
As Jason suggested, I followed what libvirt did in the volStorageBackendRBDUseFastDiff() [src/storage/storage_backend_rbd.c]

Quoted 4 lines

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

Sure, -ENOTSUP is absolutely better!

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

I hope they return an errno.h errors, but I'm not sure if the meaning make sense for us.

Do you think is better to return -ENOTSUP or -EIO when librbd calls fail?

I'll be honest, I have no idea because I don't know what failure of these calls means _at all_, so I don't know if it should be something severe like EIO or something more mundane.

I guess just leave them alone in absence of better information, honestly.

Quoted 4 lines

Thanks for your comments,
Stefano

Thank you for trying to patch rbd :)

#4 lore raw
Quoted 8 lines · John Snow
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Quoted 7 lines
Quoted 4 lines

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

I'm the new (for the past several years) upstream PTL for RBD, so feel free to tag me.

Quoted 88 lines
Quoted 88 lines
Quoted 54 lines · Stefano Garzarella
Quoted 37 lines

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

Quoted 5 lines

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Good question!
I didn't find any docs, but looking in the ceph tests test/librbd/fsx.cc, they print an error message if the return value is less than 0.

A 'get_flags' implemented in cls/rbd/cls_rbd.cc for example returns 0 at the end and -EINVAL in a try/catch. It also uses 'read_key()' that in some cases returns -EIO, so I hope that the error returned by rbd_get_flags() is one of the errors defined in errno.h

Quoted 18 lines
Quoted 5 lines
block/rbd.c +5 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 10 lines
block/rbd.c +10 -0
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

Quoted 3 lines
Quoted 3 lines

Unfortunately no :(
As Jason suggested, I followed what libvirt did in the volStorageBackendRBDUseFastDiff() [src/storage/storage_backend_rbd.c]

These are the only ones.

Quoted 18 lines
Quoted 8 lines
Quoted 4 lines

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

Sure, -ENOTSUP is absolutely better!

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

I hope they return an errno.h errors, but I'm not sure if the meaning make sense for us.

Do you think is better to return -ENOTSUP or -EIO when librbd calls fail?

Quoted 5 lines

I'll be honest, I have no idea because I don't know what failure of these calls means _at all_, so I don't know if it should be something severe like EIO or something more mundane.

I guess just leave them alone in absence of better information, honestly.

It looks like QEMU treats any negative error code like the actual size isn't available. However, for clarity I would vote for -ENOTSUPP since that's what would be returned if the driver doesn't support it.

Quoted 6 lines
Quoted 4 lines

Thanks for your comments,
Stefano

Thank you for trying to patch rbd :)

Signature · 1 line
Jason
#5 lore raw
Quoted 11 lines · Jason Dillaman
Quoted 10 lines · John Snow
Quoted 6 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Yes, I think we still want :)

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Is it okay if I send a v3 following your comments?

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

I'm the new (for the past several years) upstream PTL for RBD, so feel free to tag me.

I got Josh's name out of MAINTAINERS, does it need an update?

Quoted 5 lines

RBD
M: Josh Durgin <[email protected]>
L: [email protected]
S: Supported
F: block/rbd.c

#6 lore raw
Quoted 18 lines · John Snow
Quoted 14 lines · Jason Dillaman
Quoted 13 lines · John Snow
Quoted 8 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Quoted 14 lines
Quoted 6 lines
Quoted 2 lines

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

I'm the new (for the past several years) upstream PTL for RBD, so feel free to tag me.

I got Josh's name out of MAINTAINERS, does it need an update?

Quoted 5 lines

RBD
M: Josh Durgin <[email protected]>
L: [email protected]
S: Supported
F: block/rbd.c

Yes, I'll submit a patch to update that tomorrow.

Signature · 1 line
Jason
#7 lore raw
In reply to Jason Dillaman
Quoted 105 lines · Jason Dillaman
Quoted 5 lines · John Snow
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Quoted 7 lines
Quoted 4 lines

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

I'm the new (for the past several years) upstream PTL for RBD, so feel free to tag me.

Quoted 88 lines
Quoted 88 lines
Quoted 54 lines · Stefano Garzarella
Quoted 37 lines

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

Quoted 5 lines

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Good question!
I didn't find any docs, but looking in the ceph tests test/librbd/fsx.cc, they print an error message if the return value is less than 0.

A 'get_flags' implemented in cls/rbd/cls_rbd.cc for example returns 0 at the end and -EINVAL in a try/catch. It also uses 'read_key()' that in some cases returns -EIO, so I hope that the error returned by rbd_get_flags() is one of the errors defined in errno.h

Quoted 18 lines
Quoted 5 lines
block/rbd.c +5 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 10 lines
block/rbd.c +10 -0
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

Unfortunately no :(
As Jason suggested, I followed what libvirt did in the volStorageBackendRBDUseFastDiff() [src/storage/storage_backend_rbd.c]

These are the only ones.

Thanks for the clarification!

Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
Quoted 5 lines

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

Sure, -ENOTSUP is absolutely better!

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

I hope they return an errno.h errors, but I'm not sure if the meaning make sense for us.

Do you think is better to return -ENOTSUP or -EIO when librbd calls fail?

I'll be honest, I have no idea because I don't know what failure of these calls means _at all_, so I don't know if it should be something severe like EIO or something more mundane.

Quoted 6 lines
Quoted 1 line

I guess just leave them alone in absence of better information, honestly.

It looks like QEMU treats any negative error code like the actual size isn't available. However, for clarity I would vote for -ENOTSUPP since that's what would be returned if the driver doesn't support it.

Do you mean to return -ENOTSUP even when there's a runtime error in rbd_get_features() or rbd_get_flags() or rbd_diff_iterate2?

Thanks,
Stefano

#8 lore raw
Quoted 140 lines · Stefano Garzarella
Quoted 105 lines · Jason Dillaman
Quoted 5 lines · John Snow
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Quoted 7 lines
Quoted 4 lines

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

I'm the new (for the past several years) upstream PTL for RBD, so feel free to tag me.

Quoted 88 lines
Quoted 88 lines
Quoted 54 lines · Stefano Garzarella
Quoted 37 lines

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

Quoted 5 lines

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Good question!
I didn't find any docs, but looking in the ceph tests test/librbd/fsx.cc, they print an error message if the return value is less than 0.

A 'get_flags' implemented in cls/rbd/cls_rbd.cc for example returns 0 at the end and -EINVAL in a try/catch. It also uses 'read_key()' that in some cases returns -EIO, so I hope that the error returned by rbd_get_flags() is one of the errors defined in errno.h

Quoted 18 lines
Quoted 5 lines
block/rbd.c +5 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 10 lines
block/rbd.c +10 -0
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

Unfortunately no :(
As Jason suggested, I followed what libvirt did in the volStorageBackendRBDUseFastDiff() [src/storage/storage_backend_rbd.c]

These are the only ones.

Thanks for the clarification!

Quoted 25 lines
Quoted 24 lines
Quoted 9 lines
Quoted 5 lines

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

Sure, -ENOTSUP is absolutely better!

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

I hope they return an errno.h errors, but I'm not sure if the meaning make sense for us.

Do you think is better to return -ENOTSUP or -EIO when librbd calls fail?

I'll be honest, I have no idea because I don't know what failure of these calls means _at all_, so I don't know if it should be something severe like EIO or something more mundane.

I guess just leave them alone in absence of better information, honestly.

Quoted 7 lines
Quoted 4 lines

It looks like QEMU treats any negative error code like the actual size isn't available. However, for clarity I would vote for -ENOTSUPP since that's what would be returned if the driver doesn't support it.

Do you mean to return -ENOTSUP even when there's a runtime error in rbd_get_features() or rbd_get_flags() or rbd_diff_iterate2?

I was advocating for only returning -ENOTSUP in the case where fast-diff isn't enabled or is flagged as invalid (instead of the hard-coded -1). If one of the librbd APIs returns an error for some reason, it seems like you can just pass it along like the current patch does since any negative result is handled.

Quoted 2 lines

Thanks,
Stefano

--
Jason

#9 lore raw
Quoted 146 lines · Jason Dillaman
Quoted 145 lines · Stefano Garzarella
Quoted 105 lines · Jason Dillaman
Quoted 5 lines · John Snow
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · John Snow

It looks like this has hit a 30 day expiration without any reviews or being merged; do we still want this? If so, can you please resend?

Quoted 7 lines
Quoted 4 lines

Yes, I think we still want :)

Is it okay if I send a v3 following your comments?

Yes, but I don't know who is responsible for final approval; I guess that's Josh Durgin?

I'm the new (for the past several years) upstream PTL for RBD, so feel free to tag me.

Quoted 88 lines
Quoted 88 lines
Quoted 54 lines · Stefano Garzarella
Quoted 37 lines

This patch allows 'qemu-img info' to show the 'disk size' for the RBD images that have the fast-diff feature enabled.

If this feature is enabled, we use the rbd_diff_iterate2() API to calculate the allocated size for the image.

---
v2:
- calculate the actual usage only if the fast-diff feature is enabled [Jason]

---
 block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
block/rbd.c +14 -0
index 0c549c9935..f1bc76ab80 100644
@@ -1046,6 +1046,59 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int rbd_allocated_size_cb(uint64_t offset, size_t len, int exists,
+                                 void *arg)
+{
+    int64_t *alloc_size = (int64_t *) arg;
+
+    if (exists) {
+        (*alloc_size) += len;
+    }
+
+    return 0;
+}
+
+static int64_t qemu_rbd_get_allocated_file_size(BlockDriverState *bs)
+{

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1072

Quoted 10 lines
block/rbd.c +10 -0
+    BDRVRBDState *s = bs->opaque;
+    uint64_t flags, features;
+    int64_t alloc_size = 0;
+    int r;
+
+    r = rbd_get_flags(s->image, &flags);
+    if (r < 0) {
+        return r;
+    }
+

Do you know where rbd_get_flags is documented? I can't seem to quickly find a reference that tells me what to expect from calling it. It returns an int, I guess an error code, but how can I confirm this?

Quoted 5 lines

*clones the ceph repository*

src/librbd/internal.cc get_flags convinces me it probably works like I think, but is there not a reference here?

Good question!
I didn't find any docs, but looking in the ceph tests test/librbd/fsx.cc, they print an error message if the return value is less than 0.

A 'get_flags' implemented in cls/rbd/cls_rbd.cc for example returns 0 at the end and -EINVAL in a try/catch. It also uses 'read_key()' that in some cases returns -EIO, so I hope that the error returned by rbd_get_flags() is one of the errors defined in errno.h

Quoted 18 lines
Quoted 5 lines
block/rbd.c +5 -0
+    r = rbd_get_features(s->image, &features);
+    if (r < 0) {
+        return r;
+    }
+

block/rbd.c static int64_t qemu_rbd_getlength(BlockDriverState *bs) · line 1087

Quoted 10 lines
block/rbd.c +10 -0
+    /*
+     * We use rbd_diff_iterate2() only if the RBD image have fast-diff
+     * feature enabled. If it is disabled, rbd_diff_iterate2() could be
+     * very slow on a big image.
+     */
+    if (!(features & RBD_FEATURE_FAST_DIFF) ||
+        (flags & RBD_FLAG_FAST_DIFF_INVALID)) {
+        return -1;
+    }
+

(Is there a reference for the list of flags to make sure there aren't other cases we might want to skip this?)

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

Unfortunately no :(
As Jason suggested, I followed what libvirt did in the volStorageBackendRBDUseFastDiff() [src/storage/storage_backend_rbd.c]

These are the only ones.

Thanks for the clarification!

Quoted 29 lines
Quoted 19 lines
Quoted 9 lines
Quoted 5 lines

It looks reasonable at a glance, but maybe let's return -ENOTSUP instead of -1, based on the idea that bdrv_get_allocated_file_size returns -ENOMEDIUM in a prominent error case -- let's match that error convention.

Sure, -ENOTSUP is absolutely better!

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

(Well, I wonder what the librbd calls are returning and if THOSE mean anything.)

I hope they return an errno.h errors, but I'm not sure if the meaning make sense for us.

Do you think is better to return -ENOTSUP or -EIO when librbd calls fail?

Quoted 5 lines

I'll be honest, I have no idea because I don't know what failure of these calls means _at all_, so I don't know if it should be something severe like EIO or something more mundane.

I guess just leave them alone in absence of better information, honestly.

It looks like QEMU treats any negative error code like the actual size isn't available. However, for clarity I would vote for -ENOTSUPP since that's what would be returned if the driver doesn't support it.

Quoted 8 lines
Quoted 2 lines

Do you mean to return -ENOTSUP even when there's a runtime error in rbd_get_features() or rbd_get_flags() or rbd_diff_iterate2?

I was advocating for only returning -ENOTSUP in the case where fast-diff isn't enabled or is flagged as invalid (instead of the hard-coded -1). If one of the librbd APIs returns an error for some reason, it seems like you can just pass it along like the current patch does since any negative result is handled.

Sure, that's what I wanted to do in v3, but I had a doubt.

Thanks for the clarification, I'll send a v3 following your and John reviews.

Stefano