From nobody Wed Apr 24 23:33:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552911643761540.5886346435141; Mon, 18 Mar 2019 05:20:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 962693082A27; Mon, 18 Mar 2019 12:20:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6EB795D70D; Mon, 18 Mar 2019 12:20:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 27860181A12B; Mon, 18 Mar 2019 12:20:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ICKNaK014283 for ; Mon, 18 Mar 2019 08:20:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id B300E600C5; Mon, 18 Mar 2019 12:20:23 +0000 (UTC) Received: from dhcp-16-102.lcy.redhat.com (unknown [10.42.16.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AB24600C2; Mon, 18 Mar 2019 12:20:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 18 Mar 2019 12:20:17 +0000 Message-Id: <20190318122018.9715-2-berrange@redhat.com> In-Reply-To: <20190318122018.9715-1-berrange@redhat.com> References: <20190318122018.9715-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] storage: split off code for calling rbd_list X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 18 Mar 2019 12:20:42 +0000 (UTC) The rbd_list method has a quite unpleasant signature returning an array of strings in a single buffer instead of an array. It is being deprecated in favour of rbd_list2. To maintain clarity of code when supporting both APIs in parallel, split the rbd_list code out into a separate method. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_rbd.c | 84 ++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index 3eae780c44..24ddbc8f69 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -565,19 +565,68 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPt= r vol, return ret; } =20 + +static char ** +virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr) +{ + char **names =3D NULL; + size_t nnames =3D 0; + int ret; + size_t max_size =3D 1024; + VIR_AUTOFREE(char *) namebuf =3D NULL; + const char *name; + + while (true) { + if (VIR_ALLOC_N(namebuf, max_size) < 0) + goto error; + + ret =3D rbd_list(ptr->ioctx, namebuf, &max_size); + if (ret >=3D 0) + break; + if (ret !=3D -ERANGE) { + virReportSystemError(-ret, "%s", _("Unable to list RBD images"= )); + goto error; + } + VIR_FREE(namebuf); + } + + for (name =3D namebuf; name < namebuf + max_size;) { + VIR_AUTOFREE(char *) namedup =3D NULL; + + if (STREQ(name, "")) + break; + + if (VIR_STRDUP(namedup, name) < 0) + goto error; + + if (VIR_APPEND_ELEMENT(names, nnames, namedup) < 0) + goto error; + + name +=3D strlen(name) + 1; + } + + if (VIR_EXPAND_N(names, nnames, 1) < 0) + goto error; + + return names; + + error: + virStringListFreeCount(names, nnames); + return NULL; +} + + static int virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool) { - size_t max_size =3D 1024; int ret =3D -1; - int len =3D -1; int r =3D 0; - char *name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virStorageBackendRBDStatePtr ptr =3D NULL; struct rados_cluster_stat_t clusterstat; struct rados_pool_stat_t poolstat; - VIR_AUTOFREE(char *) names =3D NULL; + char **names =3D NULL; + size_t i; =20 if (!(ptr =3D virStorageBackendRBDNewState(pool))) goto cleanup; @@ -602,33 +651,17 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr = pool) def->source.name, clusterstat.kb, clusterstat.kb_avail, poolstat.num_bytes); =20 - while (true) { - if (VIR_ALLOC_N(names, max_size) < 0) - goto cleanup; - - len =3D rbd_list(ptr->ioctx, names, &max_size); - if (len >=3D 0) - break; - if (len !=3D -ERANGE) { - VIR_WARN("%s", "A problem occurred while listing RBD images"); - goto cleanup; - } - VIR_FREE(names); - } + if (!(names =3D virStorageBackendRBDGetVolNames(ptr))) + goto cleanup; =20 - for (name =3D names; name < names + max_size;) { + for (i =3D 0; names[i] !=3D NULL; i++) { VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 - if (STREQ(name, "")) - break; - if (VIR_ALLOC(vol) < 0) goto cleanup; =20 - if (VIR_STRDUP(vol->name, name) < 0) - goto cleanup; - - name +=3D strlen(name) + 1; + vol->name =3D names[i]; + names[i] =3D NULL; =20 r =3D volStorageBackendRBDRefreshVolInfo(vol, pool, ptr); =20 @@ -659,6 +692,7 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr po= ol) ret =3D 0; =20 cleanup: + virStringListFree(names); virStorageBackendRBDFreeState(&ptr); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Apr 24 23:33:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15529116312281022.3457020232116; Mon, 18 Mar 2019 05:20:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE2EF308428C; Mon, 18 Mar 2019 12:20:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 744645D75C; Mon, 18 Mar 2019 12:20:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F34E3D388; Mon, 18 Mar 2019 12:20:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2ICKOXU014291 for ; Mon, 18 Mar 2019 08:20:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 85579600C5; Mon, 18 Mar 2019 12:20:24 +0000 (UTC) Received: from dhcp-16-102.lcy.redhat.com (unknown [10.42.16.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id F32CE600C2; Mon, 18 Mar 2019 12:20:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 18 Mar 2019 12:20:18 +0000 Message-Id: <20190318122018.9715-3-berrange@redhat.com> In-Reply-To: <20190318122018.9715-1-berrange@redhat.com> References: <20190318122018.9715-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] storage: add support for new rbd_list2 method X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 18 Mar 2019 12:20:29 +0000 (UTC) The rbd_list method has been deprecated in Ceph >=3D 14.0.0 in favour of the new rbd_list2 method which populates an array of structs. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- 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=3D"$LIBS" LIBS=3D"$LIBS $LIBRBD_LIBS" AC_CHECK_FUNCS([rbd_get_features],[],[LIBRBD_FOUND=3Dno]) + AC_CHECK_FUNCS([rbd_list2]) LIBS=3D"$old_LIBS" fi =20 diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_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(virStorageBackendRBDSt= atePtr ptr) char **names =3D NULL; size_t nnames =3D 0; int ret; +#ifdef HAVE_RBD_LIST2 + rbd_image_spec_t *images =3D NULL; + size_t nimages =3D 16; + size_t i; + + while (true) { + if (VIR_ALLOC_N(images, nimages) < 0) + goto error; + + ret =3D rbd_list2(ptr->ioctx, images, &nimages); + if (ret >=3D 0) + break; + if (ret !=3D -ERANGE) { + virReportSystemError(-ret, "%s", _("Unable to list RBD images"= )); + goto error; + } + } + + if (VIR_ALLOC_N(names, nimages + 1) < 0) + goto error; + nnames =3D nimages; + + for (i =3D 0; i < nimages; i++) { + names[i] =3D images->name; + images->name =3D NULL; + } +#else /* ! HAVE_RBD_LIST2 */ size_t max_size =3D 1024; VIR_AUTOFREE(char *) namebuf =3D NULL; const char *name; @@ -607,11 +634,16 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDS= tatePtr ptr) =20 if (VIR_EXPAND_N(names, nnames, 1) < 0) goto error; +#endif /* ! HAVE_RBD_LIST2 */ =20 return names; =20 error: virStringListFreeCount(names, nnames); +#ifdef HAVE_RBD_LIST2 + rbd_image_spec_list_cleanup(images, nimages); + VIR_FREE(images); +#endif /* ! HAVE_RBD_LIST2 */ return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list