#include <map>
class Context;
+class ObjectExtent;
namespace librbd {
struct AioCompletion;
template <typename> class CopyupRequest;
-struct ObjectRequestHandle {
- virtual ~ObjectRequestHandle() {
- }
-
- virtual void fail(int r) = 0;
- virtual void send() = 0;
-};
-
/**
* This class represents an I/O operation to a single RBD data object.
* Its subclasses encapsulate logic for dealing with special cases
* for I/O due to layering.
*/
template <typename ImageCtxT = ImageCtx>
-class ObjectRequest : public ObjectRequestHandle {
+class ObjectRequest {
public:
- static ObjectRequest* create_write(ImageCtxT *ictx, const std::string &oid,
- uint64_t object_no,
- uint64_t object_off,
- const ceph::bufferlist &data,
- const ::SnapContext &snapc, int op_flags,
- const ZTracer::Trace &parent_trace,
- Context *completion);
- static ObjectRequest* create_discard(ImageCtxT *ictx, const std::string &oid,
- uint64_t object_no, uint64_t object_off,
- uint64_t object_len,
- const ::SnapContext &snapc,
- bool disable_clone_remove,
- bool update_object_map,
- const ZTracer::Trace &parent_trace,
- Context *completion);
- static ObjectRequest* create_writesame(ImageCtxT *ictx,
- const std::string &oid,
- uint64_t object_no,
- uint64_t object_off,
- uint64_t object_len,
- const ceph::bufferlist &data,
- const ::SnapContext &snapc,
- int op_flags,
- const ZTracer::Trace &parent_trace,
- Context *completion);
- static ObjectRequest* create_compare_and_write(ImageCtxT *ictx,
- const std::string &oid,
- uint64_t object_no,
- uint64_t object_off,
- const ceph::bufferlist &cmp_data,
- const ceph::bufferlist &write_data,
- const ::SnapContext &snapc,
- uint64_t *mismatch_offset, int op_flags,
- const ZTracer::Trace &parent_trace,
- Context *completion);
+ static ObjectRequest* create_write(
+ ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+ uint64_t object_off, ceph::bufferlist&& data, const ::SnapContext &snapc,
+ int op_flags, const ZTracer::Trace &parent_trace, Context *completion);
+ static ObjectRequest* create_discard(
+ ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+ uint64_t object_off, uint64_t object_len, const ::SnapContext &snapc,
+ int discard_flags, const ZTracer::Trace &parent_trace,
+ Context *completion);
+ static ObjectRequest* create_write_same(
+ ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+ uint64_t object_off, uint64_t object_len, ceph::bufferlist&& data,
+ const ::SnapContext &snapc, int op_flags,
+ const ZTracer::Trace &parent_trace, Context *completion);
+ static ObjectRequest* create_compare_and_write(
+ ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+ uint64_t object_off, ceph::bufferlist&& cmp_data,
+ ceph::bufferlist&& write_data, const ::SnapContext &snapc,
+ uint64_t *mismatch_offset, int op_flags,
+ const ZTracer::Trace &parent_trace, Context *completion);
ObjectRequest(ImageCtxT *ictx, const std::string &oid,
uint64_t objectno, uint64_t off, uint64_t len,
librados::snap_t snap_id, const char *trace_name,
const ZTracer::Trace &parent_trace, Context *completion);
- ~ObjectRequest() override {
+ virtual ~ObjectRequest() {
m_trace.event("finish");
}
static void add_write_hint(ImageCtxT& image_ctx,
librados::ObjectWriteOperation *wr);
- void fail(int r) {
- finish(r);
- }
-
- void send() override = 0;
+ virtual void send() = 0;
bool has_parent() const {
return m_has_parent;
virtual const char *get_op_type() const = 0;
protected:
- bool compute_parent_extents(Extents *parent_extents);
+ bool compute_parent_extents(Extents *parent_extents, bool read_request);
ImageCtxT *m_ictx;
std::string m_oid;
static ObjectReadRequest* create(ImageCtxT *ictx, const std::string &oid,
uint64_t objectno, uint64_t offset,
uint64_t len, librados::snap_t snap_id,
- int op_flags, bool cache_initiated,
+ int op_flags,
const ZTracer::Trace &parent_trace,
- Context *completion) {
+ ceph::bufferlist* read_data,
+ ExtentMap* extent_map, Context *completion) {
return new ObjectReadRequest(ictx, oid, objectno, offset, len,
- snap_id, op_flags, cache_initiated,
- parent_trace, completion);
+ snap_id, op_flags, parent_trace, read_data,
+ extent_map, completion);
}
ObjectReadRequest(ImageCtxT *ictx, const std::string &oid,
uint64_t objectno, uint64_t offset, uint64_t len,
librados::snap_t snap_id, int op_flags,
- bool cache_initiated, const ZTracer::Trace &parent_trace,
+ const ZTracer::Trace &parent_trace,
+ ceph::bufferlist* read_data, ExtentMap* extent_map,
Context *completion);
void send() override;
- inline uint64_t get_offset() const {
- return this->m_object_off;
- }
- inline uint64_t get_length() const {
- return this->m_object_len;
- }
- ceph::bufferlist &data() {
- return m_read_data;
- }
- ExtentMap &get_extent_map() {
- return m_ext_map;
- }
-
const char *get_op_type() const override {
return "read";
}
/**
* @verbatim
*
- * <start>
- * |
- * |
- * /--------/ \--------\
- * | |
- * | (cache | (cache
- * v disabled) v enabled)
- * READ_OBJECT READ_CACHE
- * | |
- * |/------------------/
+ * <start>
+ * |
+ * |
+ * v
+ * READ_OBJECT
* |
* v (skip if not needed)
* READ_PARENT
*/
int m_op_flags;
- bool m_cache_initiated;
-
- ceph::bufferlist m_read_data;
- ExtentMap m_ext_map;
- void read_cache();
- void handle_read_cache(int r);
+ ceph::bufferlist* m_read_data;
+ ExtentMap* m_extent_map;
void read_object();
void handle_read_object(int r);
protected:
bool m_full_object = false;
+ bool m_copyup_enabled = true;
virtual bool is_no_op_for_nonexistent_object() const {
return false;
Extents m_parent_extents;
bool m_object_may_exist = false;
- bool m_copyup_enabled = true;
bool m_copyup_in_progress = false;
+ bool m_guarding_migration_write = false;
+
+ void compute_parent_info();
void pre_write_object_map_update();
void handle_pre_write_object_map_update(int r);
public:
ObjectWriteRequest(ImageCtxT *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
- const ceph::bufferlist &data, const ::SnapContext &snapc,
+ ceph::bufferlist&& data, const ::SnapContext &snapc,
int op_flags, const ZTracer::Trace &parent_trace,
Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, oid, object_no, object_off,
data.length(), snapc, "write",
parent_trace, completion),
- m_write_data(data), m_op_flags(op_flags) {
+ m_write_data(std::move(data)), m_op_flags(op_flags) {
}
bool is_empty_write_op() const override {
ObjectDiscardRequest(ImageCtxT *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
uint64_t object_len, const ::SnapContext &snapc,
- bool disable_clone_remove, bool update_object_map,
- const ZTracer::Trace &parent_trace, Context *completion)
+ int discard_flags, const ZTracer::Trace &parent_trace,
+ Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, oid, object_no, object_off,
object_len, snapc, "discard",
parent_trace, completion),
- m_update_object_map(update_object_map) {
+ m_discard_flags(discard_flags) {
if (this->m_full_object) {
- if (disable_clone_remove && this->has_parent()) {
- // need to hide the parent object instead of child object
- m_discard_action = DISCARD_ACTION_REMOVE_TRUNCATE;
+ if ((m_discard_flags & OBJECT_DISCARD_FLAG_DISABLE_CLONE_REMOVE) != 0 &&
+ this->has_parent()) {
+ if (!this->m_copyup_enabled) {
+ // need to hide the parent object instead of child object
+ m_discard_action = DISCARD_ACTION_REMOVE_TRUNCATE;
+ } else {
+ m_discard_action = DISCARD_ACTION_TRUNCATE;
+ }
this->m_object_len = 0;
} else {
m_discard_action = DISCARD_ACTION_REMOVE;
case DISCARD_ACTION_ZERO:
return "zero";
}
- assert(false);
+ ceph_abort();
return nullptr;
}
return (!this->has_parent());
}
bool is_object_map_update_enabled() const override {
- return m_update_object_map;
+ return (
+ (m_discard_flags & OBJECT_DISCARD_FLAG_DISABLE_OBJECT_MAP_UPDATE) == 0);
}
bool is_non_existent_post_write_object_map_state() const override {
return (m_discard_action == DISCARD_ACTION_REMOVE);
wr->zero(this->m_object_off, this->m_object_len);
break;
default:
- assert(false);
+ ceph_abort();
break;
}
}
};
DiscardAction m_discard_action;
- bool m_update_object_map;
+ int m_discard_flags;
};
public:
ObjectWriteSameRequest(ImageCtxT *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
- uint64_t object_len, const ceph::bufferlist &data,
+ uint64_t object_len, ceph::bufferlist&& data,
const ::SnapContext &snapc, int op_flags,
const ZTracer::Trace &parent_trace,
Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, oid, object_no, object_off,
object_len, snapc, "writesame",
parent_trace, completion),
- m_write_data(data), m_op_flags(op_flags) {
+ m_write_data(std::move(data)), m_op_flags(op_flags) {
}
const char *get_op_type() const override {
public:
ObjectCompareAndWriteRequest(ImageCtxT *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
- const ceph::bufferlist &cmp_bl,
- const ceph::bufferlist &write_bl,
+ ceph::bufferlist&& cmp_bl,
+ ceph::bufferlist&& write_bl,
const ::SnapContext &snapc,
uint64_t *mismatch_offset, int op_flags,
const ZTracer::Trace &parent_trace,
cmp_bl.length(), snapc,
"compare_and_write", parent_trace,
completion),
- m_cmp_bl(cmp_bl), m_write_bl(write_bl),
+ m_cmp_bl(std::move(cmp_bl)), m_write_bl(std::move(write_bl)),
m_mismatch_offset(mismatch_offset), m_op_flags(op_flags) {
}