From 66493b7e839d2cc6f422ca4253c011fcaf0adad1 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 20 Apr 2015 12:40:33 -0400 Subject: [PATCH] cls_rbd: get_features needs to support legacy negative tests During Ceph upgrade testing, older Ceph test suites assume that get_features will return -ENOENT if provided a missing snapshot. Support these negative tests until the older releases are no longer supported. Fixes: #11380 Signed-off-by: Jason Dillaman --- src/cls/rbd/cls_rbd.cc | 18 ++++++++++++++++-- src/test/cls_rbd/test_cls_rbd.cc | 9 +++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/cls/rbd/cls_rbd.cc b/src/cls/rbd/cls_rbd.cc index 42207da86abf0..cbd14061b081a 100644 --- a/src/cls/rbd/cls_rbd.cc +++ b/src/cls/rbd/cls_rbd.cc @@ -296,11 +296,11 @@ int create(cls_method_context_t hctx, bufferlist *in, bufferlist *out) */ int get_features(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { + uint64_t snap_id; bool read_only = false; bufferlist::iterator iter = in->begin(); try { - uint64_t snap_id; ::decode(snap_id, iter); if (!iter.end()) { ::decode(read_only, iter); @@ -309,7 +309,21 @@ int get_features(cls_method_context_t hctx, bufferlist *in, bufferlist *out) return -EINVAL; } - CLS_LOG(20, "get_features read_only=%d", read_only); + CLS_LOG(20, "get_features snap_id=%" PRIu64 ", read_only=%d", + snap_id, read_only); + + // NOTE: keep this deprecated snapshot logic to support negative + // test cases in older (pre-Infernalis) releases. Remove once older + // releases are no longer supported. + if (snap_id != CEPH_NOSNAP) { + cls_rbd_snap snap; + string snapshot_key; + key_from_snap_id(snap_id, &snapshot_key); + int r = read_key(hctx, snapshot_key, &snap); + if (r < 0) { + return r; + } + } uint64_t features; int r = read_key(hctx, "features", &features); diff --git a/src/test/cls_rbd/test_cls_rbd.cc b/src/test/cls_rbd/test_cls_rbd.cc index bf971aea57f0c..12e330a23d780 100644 --- a/src/test/cls_rbd/test_cls_rbd.cc +++ b/src/test/cls_rbd/test_cls_rbd.cc @@ -368,8 +368,13 @@ TEST_F(TestClsRbd, get_features) ASSERT_EQ(0, get_features(&ioctx, oid, CEPH_NOSNAP, &features)); ASSERT_EQ(0u, features); - ASSERT_EQ(0, get_features(&ioctx, oid, 1, &features)); - ASSERT_EQ(0u, features); + int r = get_features(&ioctx, oid, 1, &features); + if (r == 0) { + ASSERT_EQ(0u, features); + } else { + // deprecated snapshot handling + ASSERT_EQ(-ENOENT, r); + } ioctx.close(); } -- 2.39.5