Based on pr: https://github.com/ceph/ceph/pull/10019.
Signed-off-by: Gui Hecheng <guihecheng@cmss.chinamobile.com>
Signed-off-by: Mingxin Liu <mingxin@xsky.com>
ctx->get_snap_context()));
}
+int IoCtx::writesame(const std::string& oid, bufferlist& bl, size_t len,
+ uint64_t off) {
+ TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
+ return ctx->execute_operation(
+ oid, boost::bind(&TestIoCtxImpl::writesame, _1, _2, bl, len, off,
+ ctx->get_snap_context()));
+}
+
static int save_operation_result(int result, int *pval) {
if (pval != NULL) {
*pval = result;
o->ops.push_back(boost::bind(&TestIoCtxImpl::write_full, _1, _2, bl, _4));
}
+void ObjectWriteOperation::writesame(uint64_t off, uint64_t len, const bufferlist& bl) {
+ TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
+ o->ops.push_back(boost::bind(&TestIoCtxImpl::writesame, _1, _2, bl, len,
+ off, _4));
+}
+
void ObjectWriteOperation::zero(uint64_t off, uint64_t len) {
TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
o->ops.push_back(boost::bind(&TestIoCtxImpl::zero, _1, _2, off, len));
uint64_t off, const SnapContext &snapc) = 0;
virtual int write_full(const std::string& oid, bufferlist& bl,
const SnapContext &snapc) = 0;
+ virtual int writesame(const std::string& oid, bufferlist& bl, size_t len,
+ uint64_t off, const SnapContext &snapc) = 0;
virtual int xattr_get(const std::string& oid,
std::map<std::string, bufferlist>* attrset) = 0;
virtual int xattr_set(const std::string& oid, const std::string &name,
return 0;
}
+int TestMemIoCtxImpl::writesame(const std::string& oid, bufferlist& bl, size_t len,
+ uint64_t off, const SnapContext &snapc) {
+ if (get_snap_read() != CEPH_NOSNAP) {
+ return -EROFS;
+ }
+
+ if (len == 0 || (len % bl.length())) {
+ return -EINVAL;
+ }
+
+ TestMemRadosClient::SharedFile file;
+ {
+ RWLock::WLocker l(m_pool->file_lock);
+ file = get_file(oid, true, snapc);
+ }
+
+ RWLock::WLocker l(file->lock);
+ if (len > 0) {
+ interval_set<uint64_t> is;
+ is.insert(off, len);
+ is.intersection_of(file->snap_overlap);
+ file->snap_overlap.subtract(is);
+ }
+
+ ensure_minimum_length(off + len, &file->data);
+ while (len > 0) {
+ file->data.copy_in(off, bl.length(), bl);
+ off += bl.length();
+ len -= bl.length();
+ }
+ return 0;
+}
+
int TestMemIoCtxImpl::xattr_get(const std::string& oid,
std::map<std::string, bufferlist>* attrset) {
TestMemRadosClient::SharedFile file;
uint64_t off, const SnapContext &snapc);
virtual int write_full(const std::string& oid, bufferlist& bl,
const SnapContext &snapc);
+ virtual int writesame(const std::string& oid, bufferlist& bl, size_t len,
+ uint64_t off, const SnapContext &snapc);
virtual int xattr_get(const std::string& oid,
std::map<std::string, bufferlist>* attrset);
virtual int xattr_set(const std::string& oid, const std::string &name,