summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2018-08-15 18:24:45 +0200
committerJeff Layton <jlayton@redhat.com>2018-08-15 18:24:45 +0200
commitfe0f3e9a389ecbed9225cb3cb5250ff6d67a1047 (patch)
tree47f103f675f6eb098e7149aa88a8a27bafc3c20a /src
parentMerge pull request #23580 from tchaikov/wip-man-page-parse-desc (diff)
downloadceph-fe0f3e9a389ecbed9225cb3cb5250ff6d67a1047.tar.xz
ceph-fe0f3e9a389ecbed9225cb3cb5250ff6d67a1047.zip
librados: add a rados_omap_iter_size function
Sometimes we need to know how many elements are represented by an omap iterator. Add a new rados_omap_iter_size to return the number of elements in the returned iterator. Also add some sanity checks for this to existing tests. Tracker: http://tracker.ceph.com/issues/26948 Signed-off-by: Jeff Layton <jlayton@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/rados/librados.h7
-rw-r--r--src/librados/librados.cc6
-rw-r--r--src/test/librados/c_read_operations.cc4
3 files changed, 17 insertions, 0 deletions
diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h
index e7cacbb2402..fb9989014ed 100644
--- a/src/include/rados/librados.h
+++ b/src/include/rados/librados.h
@@ -1716,6 +1716,13 @@ CEPH_RADOS_API int rados_omap_get_next2(rados_omap_iter_t iter,
size_t *val_len);
/**
+ * Return number of elements in the iterator
+ *
+ * @param iter the iterator of which to return the size
+ */
+CEPH_RADOS_API unsigned int rados_omap_iter_size(rados_omap_iter_t iter);
+
+/**
* Close the omap iterator.
*
* iter should not be used after this is called.
diff --git a/src/librados/librados.cc b/src/librados/librados.cc
index b835f7add95..ee5cec2db50 100644
--- a/src/librados/librados.cc
+++ b/src/librados/librados.cc
@@ -6370,6 +6370,12 @@ extern "C" int rados_omap_get_next2(rados_omap_iter_t iter,
return 0;
}
+extern "C" unsigned int rados_omap_iter_size(rados_omap_iter_t iter)
+{
+ RadosOmapIter *it = static_cast<RadosOmapIter *>(iter);
+ return it->values.size();
+}
+
extern "C" void rados_omap_get_end(rados_omap_iter_t iter)
{
tracepoint(librados, rados_omap_get_end_enter, iter);
diff --git a/src/test/librados/c_read_operations.cc b/src/test/librados/c_read_operations.cc
index 9d424aaaf38..f718cbb1008 100644
--- a/src/test/librados/c_read_operations.cc
+++ b/src/test/librados/c_read_operations.cc
@@ -74,6 +74,7 @@ protected:
char *key = NULL;
char *val = NULL;
size_t val_len = 0;
+ ASSERT_EQ(len, rados_omap_iter_size(iter));
while (i < len) {
ASSERT_EQ(0, rados_omap_get_next(iter, &key, &val, &val_len));
if (val_len == 0 && key == NULL && val == NULL)
@@ -125,6 +126,7 @@ protected:
char *val = NULL;
size_t key_len = 0;
size_t val_len = 0;
+ ASSERT_EQ(len, rados_omap_iter_size(iter));
while (i < len) {
ASSERT_EQ(0, rados_omap_get_next2(iter, &key, &val, &key_len, &val_len));
if (key_len == 0 && val_len == 0 && key == NULL && val == NULL)
@@ -646,6 +648,8 @@ TEST_F(CReadOpsTest, Omap) {
rados_release_read_op(rop);
EXPECT_EQ(0, r_vals);
EXPECT_EQ(0, r_keys);
+ EXPECT_EQ(1, rados_omap_iter_size(iter_vals));
+ EXPECT_EQ(1, rados_omap_iter_size(iter_keys));
compare_omap_vals(&keys[2], &vals[2], &lens[2], 1, iter_vals);
compare_omap_vals(&keys[2], &vals[0], &lens[0], 1, iter_keys);