This commits adds a proper handling of the assert_version API in RADOS.
Signed-off-by: Or Ozeri <oro@il.ibm.com>
o->ops.push_back(std::bind(&TestIoCtxImpl::assert_exists, _1, _2, _4));
}
+void ObjectOperation::assert_version(uint64_t ver) {
+ TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
+ o->ops.push_back(std::bind(&TestIoCtxImpl::assert_version, _1, _2, ver));
+}
+
void ObjectOperation::exec(const char *cls, const char *method,
bufferlist& inbl) {
TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
return TestMemIoCtxImpl::assert_exists(oid, snap_id);
}
+ MOCK_METHOD2(assert_version, int(const std::string &, uint64_t));
+ int do_assert_version(const std::string &oid, uint64_t ver) {
+ return TestMemIoCtxImpl::assert_version(oid, ver);
+ }
+
MOCK_METHOD3(create, int(const std::string&, bool, const SnapContext &));
int do_create(const std::string& oid, bool exclusive,
const SnapContext &snapc) {
ON_CALL(*this, aio_watch(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_watch));
ON_CALL(*this, aio_unwatch(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_unwatch));
ON_CALL(*this, assert_exists(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_exists));
+ ON_CALL(*this, assert_version(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_version));
ON_CALL(*this, create(_, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_create));
ON_CALL(*this, cmpext(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_cmpext));
ON_CALL(*this, exec(_, _, _, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec));
&librados::TestIoCtxImpl::assert_exists, _1, _2, _4));
}
+void Op::assert_version(uint64_t ver) {
+ auto o = *reinterpret_cast<librados::TestObjectOperationImpl**>(&impl);
+ o->ops.push_back(std::bind(
+ &librados::TestIoCtxImpl::assert_version, _1, _2, ver));
+}
+
void Op::cmpext(uint64_t off, ceph::buffer::list&& cmp_bl, std::size_t* s) {
auto o = *reinterpret_cast<librados::TestObjectOperationImpl**>(&impl);
librados::ObjectOperationTestImpl op = std::bind(
virtual int append(const std::string& oid, const bufferlist &bl,
const SnapContext &snapc) = 0;
virtual int assert_exists(const std::string &oid, uint64_t snap_id) = 0;
+ virtual int assert_version(const std::string &oid, uint64_t ver) = 0;
virtual int create(const std::string& oid, bool exclusive,
const SnapContext &snapc) = 0;
return 0;
}
+int TestMemIoCtxImpl::assert_version(const std::string &oid, uint64_t ver) {
+ if (m_client->is_blacklisted()) {
+ return -EBLACKLISTED;
+ }
+
+ std::shared_lock l{m_pool->file_lock};
+ TestMemCluster::SharedFile file = get_file(oid, false, CEPH_NOSNAP, {});
+ if (file == NULL || !file->exists) {
+ return -ENOENT;
+ }
+ if (ver < file->objver) {
+ return -ERANGE;
+ }
+ if (ver > file->objver) {
+ return -EOVERFLOW;
+ }
+
+ return 0;
+}
+
int TestMemIoCtxImpl::create(const std::string& oid, bool exclusive,
const SnapContext &snapc) {
if (get_snap_read() != CEPH_NOSNAP) {
const SnapContext &snapc) override;
int assert_exists(const std::string &oid, uint64_t snap_id) override;
+ int assert_version(const std::string &oid, uint64_t ver) override;
int create(const std::string& oid, bool exclusive,
const SnapContext &snapc) override;