From e8ec2592202387cca8e45cf15bd55ed5a952f3e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Mon, 18 Mar 2019 11:11:38 +0000
Subject: [PATCH 2/5] storage: add support for new rbd_list2 method
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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.
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 3aa190f2a43a632b542a6ba751a6c3ab4d51f1dd)
---
m4/virt-storage-rbd.m4 | 1 +
src/storage/storage_backend_rbd.c | 43 +++++++++++++++++++++++++++++++
2 files changed, 44 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 0865163756..bfc3419f9c 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -566,6 +566,48 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
}
+#ifdef HAVE_RBD_LIST2
+static char **
+virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
+{
+ char **names = NULL;
+ size_t nnames = 0;
+ int rc;
+ rbd_image_spec_t *images = NULL;
+ size_t nimages = 16;
+ size_t i;
+
+ while (true) {
+ if (VIR_ALLOC_N(images, nimages) < 0)
+ goto error;
+
+ rc = rbd_list2(ptr->ioctx, images, &nimages);
+ if (rc >= 0)
+ break;
+ if (rc != -ERANGE) {
+ virReportSystemError(-rc, "%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++)
+ VIR_STEAL_PTR(names[i], images->name);
+
+ return names;
+
+ error:
+ virStringListFreeCount(names, nnames);
+ rbd_image_spec_list_cleanup(images, nimages);
+ VIR_FREE(images);
+ return NULL;
+}
+
+#else /* ! HAVE_RBD_LIST2 */
+
static char **
virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
{
@@ -614,6 +656,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
virStringListFreeCount(names, nnames);
return NULL;
}
+#endif /* ! HAVE_RBD_LIST2 */
static int
--
2.20.1