Skip to content

Commit

Permalink
librbd: utilize factory methods to create AioObjectRequest objects
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Aug 2, 2016
1 parent 840a473 commit 2e5076e
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 52 deletions.
50 changes: 21 additions & 29 deletions src/librbd/AioImageRequest.cc
Expand Up @@ -269,14 +269,10 @@ void AioImageRead<I>::send_request() {
<< dendl;

C_AioRead<I> *req_comp = new C_AioRead<I>(aio_comp);
AioObjectRead<I> *req = new AioObjectRead<I>(get_image_ctx(&image_ctx),
extent.oid.name,
extent.objectno,
extent.offset,
extent.length,
extent.buffer_extents,
snap_id, true, req_comp,
m_op_flags);
AioObjectRead<I> *req = AioObjectRead<I>::create(
&image_ctx, extent.oid.name, extent.objectno, extent.offset,
extent.length, extent.buffer_extents, snap_id, true, req_comp,
m_op_flags);
req_comp->set_req(req);

if (image_ctx.object_cacher) {
Expand Down Expand Up @@ -379,7 +375,8 @@ void AbstractAioImageWrite<I>::send_object_requests(
ldout(cct, 20) << " oid " << p->oid << " " << p->offset << "~" << p->length
<< " from " << p->buffer_extents << dendl;
C_AioRequest *req_comp = new C_AioRequest(aio_comp);
AioObjectRequest<> *request = create_object_request(*p, snapc, req_comp);
AioObjectRequestHandle *request = create_object_request(*p, snapc,
req_comp);

// if journaling, stash the request for later; otherwise send
if (request != NULL) {
Expand Down Expand Up @@ -450,20 +447,17 @@ void AioImageWrite<I>::send_object_requests(
}

template <typename I>
AioObjectRequest<> *AioImageWrite<I>::create_object_request(
AioObjectRequestHandle *AioImageWrite<I>::create_object_request(
const ObjectExtent &object_extent, const ::SnapContext &snapc,
Context *on_finish) {
I &image_ctx = this->m_image_ctx;
assert(image_ctx.object_cacher == NULL);

bufferlist bl;
assemble_extent(object_extent, &bl);
AioObjectWrite *req = new AioObjectWrite(get_image_ctx(&image_ctx),
object_extent.oid.name,
object_extent.objectno,
object_extent.offset, bl,
snapc, on_finish);
req->set_op_flags(m_op_flags);
AioObjectRequest<I> *req = AioObjectRequest<I>::create_write(
&image_ctx, object_extent.oid.name, object_extent.objectno,
object_extent.offset, bl, snapc, on_finish, m_op_flags);
return req;
}

Expand Down Expand Up @@ -536,27 +530,25 @@ void AioImageDiscard<I>::send_cache_requests(const ObjectExtents &object_extents
}

template <typename I>
AioObjectRequest<> *AioImageDiscard<I>::create_object_request(
AioObjectRequestHandle *AioImageDiscard<I>::create_object_request(
const ObjectExtent &object_extent, const ::SnapContext &snapc,
Context *on_finish) {
I &image_ctx = this->m_image_ctx;

AioObjectRequest<> *req;
AioObjectRequest<I> *req;
if (object_extent.length == image_ctx.layout.object_size) {
req = new AioObjectRemove(get_image_ctx(&image_ctx),
object_extent.oid.name,
object_extent.objectno, snapc, on_finish);
req = AioObjectRequest<I>::create_remove(
&image_ctx, object_extent.oid.name, object_extent.objectno, snapc,
on_finish);
} else if (object_extent.offset + object_extent.length ==
image_ctx.layout.object_size) {
req = new AioObjectTruncate(get_image_ctx(&image_ctx),
object_extent.oid.name,
object_extent.objectno, object_extent.offset,
snapc, on_finish);
req = AioObjectRequest<I>::create_truncate(
&image_ctx, object_extent.oid.name, object_extent.objectno,
object_extent.offset, snapc, on_finish);
} else {
req = new AioObjectZero(get_image_ctx(&image_ctx),
object_extent.oid.name,
object_extent.objectno, object_extent.offset,
object_extent.length, snapc, on_finish);
req = AioObjectRequest<I>::create_zero(
&image_ctx, object_extent.oid.name, object_extent.objectno,
object_extent.offset, object_extent.length, snapc, on_finish);
}
return req;
}
Expand Down
10 changes: 5 additions & 5 deletions src/librbd/AioImageRequest.h
Expand Up @@ -16,7 +16,7 @@
namespace librbd {

class AioCompletion;
template <typename I> class AioObjectRequest;
class AioObjectRequestHandle;
class ImageCtx;

template <typename ImageCtxT = ImageCtx>
Expand Down Expand Up @@ -49,7 +49,7 @@ class AioImageRequest {
void fail(int r);

protected:
typedef std::list<AioObjectRequest<ImageCtx> *> AioObjectRequests;
typedef std::list<AioObjectRequestHandle *> AioObjectRequests;

ImageCtxT &m_image_ctx;
AioCompletion *m_aio_comp;
Expand Down Expand Up @@ -135,7 +135,7 @@ class AbstractAioImageWrite : public AioImageRequest<ImageCtxT> {
virtual void send_object_requests(const ObjectExtents &object_extents,
const ::SnapContext &snapc,
AioObjectRequests *aio_object_requests);
virtual AioObjectRequest<ImageCtx> *create_object_request(
virtual AioObjectRequestHandle *create_object_request(
const ObjectExtent &object_extent, const ::SnapContext &snapc,
Context *on_finish) = 0;

Expand Down Expand Up @@ -175,7 +175,7 @@ class AioImageWrite : public AbstractAioImageWrite<ImageCtxT> {
virtual void send_object_requests(const ObjectExtents &object_extents,
const ::SnapContext &snapc,
AioObjectRequests *aio_object_requests);
virtual AioObjectRequest<ImageCtx> *create_object_request(
virtual AioObjectRequestHandle *create_object_request(
const ObjectExtent &object_extent, const ::SnapContext &snapc,
Context *on_finish);

Expand Down Expand Up @@ -211,7 +211,7 @@ class AioImageDiscard : public AbstractAioImageWrite<ImageCtxT> {
virtual void send_cache_requests(const ObjectExtents &object_extents,
uint64_t journal_tid);

virtual AioObjectRequest<ImageCtx> *create_object_request(
virtual AioObjectRequestHandle *create_object_request(
const ObjectExtent &object_extent, const ::SnapContext &snapc,
Context *on_finish);

Expand Down
48 changes: 45 additions & 3 deletions src/librbd/AioObjectRequest.cc
Expand Up @@ -27,6 +27,48 @@

namespace librbd {

template <typename I>
AioObjectRequest<I>*
AioObjectRequest<I>::create_remove(I *ictx, const std::string &oid,
uint64_t object_no,
const ::SnapContext &snapc,
Context *completion) {
return new AioObjectRemove(util::get_image_ctx(ictx), oid, object_no, snapc,
completion);
}

template <typename I>
AioObjectRequest<I>*
AioObjectRequest<I>::create_truncate(I *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
const ::SnapContext &snapc,
Context *completion) {
return new AioObjectTruncate(util::get_image_ctx(ictx), oid, object_no,
object_off, snapc, completion);
}

template <typename I>
AioObjectRequest<I>*
AioObjectRequest<I>::create_write(I *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
const ceph::bufferlist &data,
const ::SnapContext &snapc,
Context *completion, int op_flags) {
return new AioObjectWrite(util::get_image_ctx(ictx), oid, object_no,
object_off, data, snapc, completion, op_flags);
}

template <typename I>
AioObjectRequest<I>*
AioObjectRequest<I>::create_zero(I *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
uint64_t object_len,
const ::SnapContext &snapc,
Context *completion) {
return new AioObjectZero(util::get_image_ctx(ictx), oid, object_no,
object_off, object_len, snapc, completion);
}

template <typename I>
AioObjectRequest<I>::AioObjectRequest(ImageCtx *ictx, const std::string &oid,
uint64_t objectno, uint64_t off,
Expand Down Expand Up @@ -97,14 +139,14 @@ static inline bool is_copy_on_read(ImageCtx *ictx, librados::snap_t snap_id) {
/** read **/

template <typename I>
AioObjectRead<I>::AioObjectRead(ImageCtx *ictx, const std::string &oid,
AioObjectRead<I>::AioObjectRead(I *ictx, const std::string &oid,
uint64_t objectno, uint64_t offset,
uint64_t len,
vector<pair<uint64_t,uint64_t> >& be,
librados::snap_t snap_id, bool sparse,
Context *completion, int op_flags)
: AioObjectRequest<I>(ictx, oid, objectno, offset, len, snap_id, completion,
false),
: AioObjectRequest<I>(util::get_image_ctx(ictx), oid, objectno, offset, len,
snap_id, completion, false),
m_buffer_extents(be), m_tried_parent(false), m_sparse(sparse),
m_op_flags(op_flags), m_parent_completion(NULL),
m_state(LIBRBD_AIO_READ_FLAT) {
Expand Down
60 changes: 52 additions & 8 deletions src/librbd/AioObjectRequest.h
Expand Up @@ -18,17 +18,54 @@ class Context;
namespace librbd {

struct AioCompletion;
class AioObjectRemove;
class AioObjectTruncate;
class AioObjectWrite;
class AioObjectZero;
struct ImageCtx;
class CopyupRequest;

struct AioObjectRequestHandle {
virtual ~AioObjectRequestHandle() {
}

virtual void complete(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 AioObjectRequest {
class AioObjectRequest : public AioObjectRequestHandle {
public:
typedef std::vector<std::pair<uint64_t, uint64_t> > Extents;

static AioObjectRequest* create_remove(ImageCtxT *ictx,
const std::string &oid,
uint64_t object_no,
const ::SnapContext &snapc,
Context *completion);
static AioObjectRequest* create_truncate(ImageCtxT *ictx,
const std::string &oid,
uint64_t object_no,
uint64_t object_off,
const ::SnapContext &snapc,
Context *completion);
static AioObjectRequest* create_write(ImageCtxT *ictx, const std::string &oid,
uint64_t object_no,
uint64_t object_off,
const ceph::bufferlist &data,
const ::SnapContext &snapc,
Context *completion, int op_flags);
static AioObjectRequest* create_zero(ImageCtxT *ictx, const std::string &oid,
uint64_t object_no, uint64_t object_off,
uint64_t object_len,
const ::SnapContext &snapc,
Context *completion);

AioObjectRequest(ImageCtx *ictx, const std::string &oid,
uint64_t objectno, uint64_t off, uint64_t len,
librados::snap_t snap_id,
Expand All @@ -54,7 +91,7 @@ class AioObjectRequest {
uint64_t m_object_no, m_object_off, m_object_len;
librados::snap_t m_snap_id;
Context *m_completion;
std::vector<std::pair<uint64_t,uint64_t> > m_parent_extents;
Extents m_parent_extents;
bool m_hide_enoent;
};

Expand All @@ -64,7 +101,16 @@ class AioObjectRead : public AioObjectRequest<ImageCtxT> {
typedef std::vector<std::pair<uint64_t, uint64_t> > Extents;
typedef std::map<uint64_t, uint64_t> ExtentMap;

AioObjectRead(ImageCtx *ictx, const std::string &oid,
static AioObjectRead* create(ImageCtxT *ictx, const std::string &oid,
uint64_t objectno, uint64_t offset,
uint64_t len, Extents &buffer_extents,
librados::snap_t snap_id, bool sparse,
Context *completion, int op_flags) {
return new AioObjectRead(ictx, oid, objectno, offset, len, buffer_extents,
snap_id, sparse, completion, op_flags);
}

AioObjectRead(ImageCtxT *ictx, const std::string &oid,
uint64_t objectno, uint64_t offset, uint64_t len,
Extents& buffer_extents, librados::snap_t snap_id, bool sparse,
Context *completion, int op_flags);
Expand Down Expand Up @@ -212,15 +258,13 @@ class AioObjectWrite : public AbstractAioObjectWrite {
public:
AioObjectWrite(ImageCtx *ictx, const std::string &oid, uint64_t object_no,
uint64_t object_off, const ceph::bufferlist &data,
const ::SnapContext &snapc, Context *completion)
const ::SnapContext &snapc, Context *completion,
int op_flags)
: AbstractAioObjectWrite(ictx, oid, object_no, object_off, data.length(),
snapc, completion, false),
m_write_data(data), m_op_flags(0) {
m_write_data(data), m_op_flags(op_flags) {
}

void set_op_flags(int op_flags) {
m_op_flags = op_flags;
}
protected:
virtual void add_write_ops(librados::ObjectWriteOperation *wr);

Expand Down
4 changes: 2 additions & 2 deletions src/librbd/Journal.h
Expand Up @@ -31,7 +31,7 @@ namespace librados {

namespace librbd {

template <typename I> class AioObjectRequest;
struct AioObjectRequestHandle;
class ImageCtx;

namespace journal { template <typename> class Replay; }
Expand Down Expand Up @@ -87,7 +87,7 @@ class Journal {
static const std::string LOCAL_MIRROR_UUID;
static const std::string ORPHAN_MIRROR_UUID;

typedef std::list<AioObjectRequest<ImageCtx> *> AioObjectRequests;
typedef std::list<AioObjectRequestHandle *> AioObjectRequests;

Journal(ImageCtxT &image_ctx);
~Journal();
Expand Down
4 changes: 2 additions & 2 deletions src/librbd/LibrbdWriteback.cc
Expand Up @@ -162,7 +162,7 @@ namespace librbd {

request_sent = true;
AioObjectWrite *req = new AioObjectWrite(image_ctx, oid, object_no, off,
bl, snapc, this);
bl, snapc, this, 0);
req->send();
}
};
Expand Down Expand Up @@ -274,7 +274,7 @@ namespace librbd {
journal_tid));
} else {
AioObjectWrite *req = new AioObjectWrite(m_ictx, oid.name, object_no,
off, bl, snapc, req_comp);
off, bl, snapc, req_comp, 0);
req->send();
}
return ++m_tid;
Expand Down
2 changes: 1 addition & 1 deletion src/librbd/operation/FlattenRequest.cc
Expand Up @@ -42,7 +42,7 @@ class C_FlattenObject : public C_AsyncObjectThrottle<I> {
bufferlist bl;
string oid = image_ctx.get_object_name(m_object_no);
AioObjectWrite *req = new AioObjectWrite(&image_ctx, oid, m_object_no, 0,
bl, m_snapc, this);
bl, m_snapc, this, 0);
if (!req->has_parent()) {
// stop early if the parent went away - it just means
// another flatten finished first or the image was resized
Expand Down
4 changes: 2 additions & 2 deletions src/test/librbd/mock/MockJournal.h
Expand Up @@ -11,11 +11,11 @@

namespace librbd {

template <typename I> struct AioObjectRequest;
struct AioObjectRequestHandle;
struct ImageCtx;

struct MockJournal {
typedef std::list<AioObjectRequest<ImageCtx> *> AioObjectRequests;
typedef std::list<AioObjectRequestHandle *> AioObjectRequests;

static MockJournal *s_instance;
static MockJournal *get_instance() {
Expand Down

0 comments on commit 2e5076e

Please sign in to comment.