[libvirt] [PATCH 2/2] storage: add support for new rbd_list2 method
Ján Tomko
jtomko at redhat.com
Mon Mar 18 12:56:47 UTC 2019
On Mon, Mar 18, 2019 at 12:20:18PM +0000, Daniel P. Berrangé wrote:
>The rbd_list method has been deprecated in Ceph >= 14.0.0
>in favour of the new rbd_list2 method which populates an
>array of structs.
>
>Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
>---
> m4/virt-storage-rbd.m4 | 1 +
> src/storage/storage_backend_rbd.c | 32 +++++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+)
>
>diff --git a/m4/virt-storage-rbd.m4 b/m4/virt-storage-rbd.m4
>index 17e2115309..f3d9d04908 100644
>--- a/m4/virt-storage-rbd.m4
>+++ b/m4/virt-storage-rbd.m4
>@@ -33,6 +33,7 @@ AC_DEFUN([LIBVIRT_STORAGE_CHECK_RBD], [
> old_LIBS="$LIBS"
> LIBS="$LIBS $LIBRBD_LIBS"
> AC_CHECK_FUNCS([rbd_get_features],[],[LIBRBD_FOUND=no])
>+ AC_CHECK_FUNCS([rbd_list2])
> LIBS="$old_LIBS"
> fi
>
>diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
>index 24ddbc8f69..b6f2785390 100644
>--- a/src/storage/storage_backend_rbd.c
>+++ b/src/storage/storage_backend_rbd.c
>@@ -572,6 +572,33 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
> char **names = NULL;
> size_t nnames = 0;
> int ret;
>+#ifdef HAVE_RBD_LIST2
Please, create two separate implementations:
#ifdef HAVE_RBD_LIST2
static char **
virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
{
...
}
#else /* ! HAVE_RBD_LIST2 */
virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
{
...
}
#endif
A bit more verbose, but easier to read.
>+ rbd_image_spec_t *images = NULL;
>+ size_t nimages = 16;
>+ size_t i;
>+
>+ while (true) {
>+ if (VIR_ALLOC_N(images, nimages) < 0)
>+ goto error;
>+
>+ ret = rbd_list2(ptr->ioctx, images, &nimages);
>+ if (ret >= 0)
>+ break;
>+ if (ret != -ERANGE) {
>+ virReportSystemError(-ret, "%s", _("Unable to list RBD images"));
>+ goto error;
>+ }
>+ }
>+
>+ if (VIR_ALLOC_N(names, nimages + 1) < 0)
>+ goto error;
>+ nnames = nimages;
>+
>+ for (i = 0; i < nimages; i++) {
>+ names[i] = images->name;
>+ images->name = NULL;
This can also use VIR_STEAL_PTR
>+ }
>+#else /* ! HAVE_RBD_LIST2 */
> size_t max_size = 1024;
> VIR_AUTOFREE(char *) namebuf = NULL;
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190318/69f2f2c0/attachment-0001.sig>
More information about the libvir-list
mailing list