#define __STDC_FORMAT_MACROS
#include "common/Cond.h"
+#include "common/dout.h"
#include "common/errno.h"
#include "include/rbd/librbd.hpp"
};
struct ImageCtx {
+ CephContext *cct;
struct rbd_obj_header_ondisk header;
::SnapContext snapc;
vector<snap_t> snaps;
Mutex refresh_lock;
Mutex lock; // protects access to snapshot and header information
- ImageCtx(std::string imgname, IoCtx& p) : snapid(CEPH_NOSNAP),
+ ImageCtx(std::string imgname, IoCtx& p) : cct(p.cct()), snapid(CEPH_NOSNAP),
name(imgname),
needs_refresh(true),
refresh_lock("librbd::ImageCtx::refresh_lock"),
struct AioCompletion;
struct AioBlockCompletion {
+ CephContext *cct;
struct AioCompletion *completion;
uint64_t ofs;
size_t len;
map<uint64_t,uint64_t> m;
bufferlist data_bl;
- AioBlockCompletion(AioCompletion *aio_completion, uint64_t _ofs, size_t _len, char *_buf) :
- completion(aio_completion), ofs(_ofs), len(_len), buf(_buf) {}
+ AioBlockCompletion(CephContext *cct_, AioCompletion *aio_completion, uint64_t _ofs, size_t _len, char *_buf) :
+ cct(cct_), completion(aio_completion), ofs(_ofs), len(_len), buf(_buf) {}
void complete(ssize_t r);
};
int ref;
bool released;
- AioCompletion() : lock("AioCompletion::lock", true), done(false), rval(0), complete_cb(NULL), complete_arg(NULL),
+ AioCompletion() : lock("AioCompletion::lock", true),
+ done(false), rval(0), complete_cb(NULL), complete_arg(NULL),
rbd_comp(NULL), pending_count(1), ref(1), released(false) {
- dout(20) << "AioCompletion::AioCompletion() this=" << (void *)this << dendl;
}
~AioCompletion() {
- dout(20) << "AioCompletion::~AioCompletion() this=" << (void *)this << dendl;
}
int wait_for_complete() {
- dout(20) << "AioCompletion::wait_for_complete() this=" << (void *)this << dendl;
lock.Lock();
while (!done)
cond.Wait(lock);
}
void add_block_completion(AioBlockCompletion *aio_completion) {
- dout(20) << "AioCompletion::add_block_completion() this=" << (void *)this << dendl;
lock.Lock();
pending_count++;
lock.Unlock();
}
void finish_adding_completions() {
- dout(20) << "AioCompletion::finish_adding_completions() this=" << (void *)this << dendl;
lock.Lock();
assert(pending_count);
int count = --pending_count;
}
void complete() {
- dout(20) << "AioCompletion::complete() this=" << (void *)this << dendl;
assert(lock.is_locked());
if (complete_cb) {
complete_cb(rbd_comp, complete_arg);
void complete_block(AioBlockCompletion *block_completion, ssize_t r);
ssize_t get_return_value() {
- dout(20) << "AioCompletion::get_return_value() this=" << (void *)this << dendl;
lock.Lock();
ssize_t r = rval;
lock.Unlock();
void get() {
lock.Lock();
- dout(20) << " AioCompletion::get() this=" << (void *)this << " " << ref << " -> " << ref + 1 << dendl;
assert(ref > 0);
ref++;
lock.Unlock();
}
void release() {
lock.Lock();
- dout(20) << "AioCompletion::release() this=" << (void *)this << dendl;
assert(!released);
released = true;
put_unlock();
}
void put_unlock() {
assert(ref > 0);
- dout(20) << "AioCompletion::put_unlock() this=" << (void *)this << " " << ref << " -> " << ref - 1 << dendl;
int n = --ref;
lock.Unlock();
if (!n)
char *buf, AioCompletion *c);
AioCompletion *aio_create_completion() {
- AioCompletion *c= new AioCompletion;
+ AioCompletion *c= new AioCompletion();
return c;
}
AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete) {
- AioCompletion *c = new AioCompletion;
+ AioCompletion *c = new AioCompletion();
c->set_complete_cb(cb_arg, cb_complete);
return c;
}
void WatchCtx::notify(uint8_t opcode, uint64_t ver)
{
Mutex::Locker l(lock);
- dout(1) << " got notification opcode=" << (int)opcode << " ver=" << ver << " cookie=" << cookie << dendl;
+ ldout(ictx->cct, 1) << " got notification opcode=" << (int)opcode << " ver=" << ver << " cookie=" << cookie << dendl;
if (valid) {
Mutex::Locker lictx(ictx->refresh_lock);
ictx->needs_refresh = true;
void trim_image(IoCtx& io_ctx, const rbd_obj_header_ondisk &header, uint64_t newsize)
{
+ CephContext *cct = io_ctx.cct();
uint64_t numseg = get_max_block(header);
uint64_t start = get_block_num(header, newsize);
- dout(2) << "trimming image data from " << numseg << " to " << start << " objects..." << dendl;
+ ldout(cct, 2) << "trimming image data from " << numseg << " to " << start << " objects..." << dendl;
for (uint64_t i=start; i<numseg; i++) {
string oid = get_block_oid(header, i);
io_ctx.remove(oid);
if ((i & 127) == 0) {
- dout(2) << "\t" << i << "/" << numseg << dendl;
+ ldout(cct, 2) << "\t" << i << "/" << numseg << dendl;
}
}
}
int r;
string oid = get_block_oid(ictx->header, i);
r = ictx->data_ctx.selfmanaged_snap_rollback(oid, snapid);
- dout(10) << "selfmanaged_snap_rollback on " << oid << " to " << snapid << " returned " << r << dendl;
+ ldout(ictx->cct, 10) << "selfmanaged_snap_rollback on " << oid << " to " << snapid << " returned " << r << dendl;
if (r < 0 && r != -ENOENT)
return r;
}
int list(IoCtx& io_ctx, std::vector<std::string>& names)
{
- dout(20) << "list " << &io_ctx << dendl;
+ CephContext *cct = io_ctx.cct();
+ ldout(cct, 20) << "list " << &io_ctx << dendl;
bufferlist bl;
int r = io_ctx.read(RBD_DIRECTORY, bl, 0, 0);
int snap_create(ImageCtx *ictx, const char *snap_name)
{
- dout(20) << "snap_create " << ictx << " " << snap_name << dendl;
+ ldout(ictx->cct, 20) << "snap_create " << ictx << " " << snap_name << dendl;
int r = ictx_check(ictx);
if (r < 0)
int snap_remove(ImageCtx *ictx, const char *snap_name)
{
- dout(20) << "snap_remove " << ictx << " " << snap_name << dendl;
+ ldout(ictx->cct, 20) << "snap_remove " << ictx << " " << snap_name << dendl;
int r = ictx_check(ictx);
if (r < 0)
int create(IoCtx& io_ctx, const char *imgname, uint64_t size, int *order)
{
- dout(20) << "create " << &io_ctx << " name = " << imgname << " size = " << size << dendl;
+ CephContext *cct = io_ctx.cct();
+ ldout(cct, 20) << "create " << &io_ctx << " name = " << imgname << " size = " << size << dendl;
string md_oid = imgname;
md_oid += RBD_SUFFIX;
bufferlist bl;
bl.append((const char *)&header, sizeof(header));
- dout(2) << "adding rbd image to directory..." << dendl;
+ ldout(cct, 2) << "adding rbd image to directory..." << dendl;
bufferlist cmdbl, emptybl;
__u8 c = CEPH_OSD_TMAP_SET;
::encode(c, cmdbl);
return r;
}
- dout(2) << "creating rbd image..." << dendl;
+ ldout(cct, 2) << "creating rbd image..." << dendl;
r = io_ctx.write(md_oid, bl, bl.length(), 0);
if (r < 0) {
derr << "error writing header: " << strerror(-r) << dendl;
return r;
}
- dout(2) << "done." << dendl;
+ ldout(cct, 2) << "done." << dendl;
return 0;
}
int rename(IoCtx& io_ctx, const char *srcname, const char *dstname)
{
- dout(20) << "rename " << &io_ctx << " " << srcname << " -> " << dstname << dendl;
+ CephContext *cct = io_ctx.cct();
+ ldout(cct, 20) << "rename " << &io_ctx << " " << srcname << " -> " << dstname << dendl;
string md_oid = srcname;
md_oid += RBD_SUFFIX;
int info(ImageCtx *ictx, image_info_t& info, size_t infosize)
{
- dout(20) << "info " << ictx << dendl;
+ ldout(ictx->cct, 20) << "info " << ictx << dendl;
int r = ictx_check(ictx);
if (r < 0)
int resize(ImageCtx *ictx, uint64_t size)
{
- dout(20) << "resize " << ictx << " " << ictx->header.image_size << " -> " << size << dendl;
+ CephContext *cct = ictx->cct;
+ ldout(cct, 20) << "resize " << ictx << " " << ictx->header.image_size << " -> " << size << dendl;
int r = ictx_check(ictx);
if (r < 0)
Mutex::Locker l(ictx->lock);
// trim
if (size == ictx->header.image_size) {
- dout(2) << "no change in size (" << size << " -> " << ictx->header.image_size << ")" << dendl;
+ ldout(cct, 2) << "no change in size (" << size << " -> " << ictx->header.image_size << ")" << dendl;
return 0;
}
if (size > ictx->header.image_size) {
- dout(2) << "expanding image " << size << " -> " << ictx->header.image_size << " objects" << dendl;
+ ldout(cct, 2) << "expanding image " << size << " -> " << ictx->header.image_size << " objects" << dendl;
ictx->header.image_size = size;
} else {
- dout(2) << "shrinking image " << size << " -> " << ictx->header.image_size << " objects" << dendl;
+ ldout(cct, 2) << "shrinking image " << size << " -> " << ictx->header.image_size << " objects" << dendl;
trim_image(ictx->data_ctx, ictx->header, size);
ictx->header.image_size = size;
}
notify_change(ictx->md_ctx, ictx->md_oid(), NULL, ictx);
}
- dout(2) << "done." << dendl;
+ ldout(cct, 2) << "done." << dendl;
return 0;
}
int snap_list(ImageCtx *ictx, std::vector<snap_info_t>& snaps)
{
- dout(20) << "snap_list " << ictx << dendl;
+ ldout(ictx->cct, 20) << "snap_list " << ictx << dendl;
int r = ictx_check(ictx);
if (r < 0)
int ictx_check(ImageCtx *ictx)
{
- dout(20) << "ictx_check " << ictx << dendl;
+ ldout(ictx->cct, 20) << "ictx_check " << ictx << dendl;
ictx->refresh_lock.Lock();
bool needs_refresh = ictx->needs_refresh;
ictx->refresh_lock.Unlock();
bufferlist bl, bl2;
if (snap_name) {
- dout(20) << "ictx_refresh " << ictx << " snap = " << snap_name << dendl;
+ ldout(ictx->cct, 20) << "ictx_refresh " << ictx << " snap = " << snap_name << dendl;
} else {
- dout(20) << "ictx_refresh " << ictx << " no snap" << dendl;
+ ldout(ictx->cct, 20) << "ictx_refresh " << ictx << " no snap" << dendl;
}
int r = read_header(ictx->md_ctx, ictx->md_oid(), &(ictx->header), NULL);
int snap_rollback(ImageCtx *ictx, const char *snap_name)
{
- dout(20) << "snap_rollback " << ictx << " snap = " << snap_name << dendl;
+ ldout(ictx->cct, 20) << "snap_rollback " << ictx << " snap = " << snap_name << dendl;
int r = ictx_check(ictx);
if (r < 0)
// refresh without setting the snapid we read from
ictx_refresh(ictx, NULL);
snap_t new_snapid = ictx->get_snapid(snap_name);
- dout(20) << "snapid is " << ictx->snapid << " new snapid is " << new_snapid << dendl;
+ ldout(ictx->cct, 20) << "snapid is " << ictx->snapid << " new snapid is " << new_snapid << dendl;
notify_change(ictx->md_ctx, ictx->md_oid(), NULL, ictx);
int snap_set(ImageCtx *ictx, const char *snap_name)
{
- dout(20) << "snap_set " << ictx << " snap = " << (snap_name ? snap_name : "NULL") << dendl;
+ ldout(ictx->cct, 20) << "snap_set " << ictx << " snap = " << (snap_name ? snap_name : "NULL") << dendl;
int r = ictx_check(ictx);
if (r < 0)
int open_image(IoCtx& io_ctx, ImageCtx *ictx, const char *name, const char *snap_name)
{
+ CephContext *cct = io_ctx.cct();
string sn = snap_name ? snap_name : "NULL";
- dout(20) << "open_image " << &io_ctx << " ictx = " << ictx
+ ldout(cct, 20) << "open_image " << &io_ctx << " ictx = " << ictx
<< " name = " << name << " snap_name = " << (snap_name ? snap_name : "NULL") << dendl;
ictx->lock.Lock();
void close_image(ImageCtx *ictx)
{
- dout(20) << "close_image " << ictx << dendl;
+ ldout(ictx->cct, 20) << "close_image " << ictx << dendl;
ictx->lock.Lock();
ictx->wctx->invalidate();
ictx->md_ctx.unwatch(ictx->md_oid(), ictx->wctx->cookie);
int (*cb)(uint64_t, size_t, const char *, void *),
void *arg)
{
- dout(20) << "read_iterate " << ictx << " off = " << off << " len = " << len << dendl;
+ ldout(ictx->cct, 20) << "read_iterate " << ictx << " off = " << off << " len = " << len << dendl;
int r = ictx_check(ictx);
if (r < 0)
for (iter = m.begin(); iter != m.end(); ++iter) {
uint64_t extent_ofs = iter->first;
size_t extent_len = iter->second;
- dout(20) << "extent_ofs=" << extent_ofs << " extent_len=" << extent_len << dendl;
- dout(20) << "block_read=" << block_read << " total_read=" << total_read << " block_ofs=" << block_ofs << dendl;
+ ldout(ictx->cct, 20) << "extent_ofs=" << extent_ofs << " extent_len=" << extent_len << dendl;
+ ldout(ictx->cct, 20) << "block_read=" << block_read << " total_read=" << total_read << " block_ofs=" << block_ofs << dendl;
/* a hole? */
if (extent_ofs - block_ofs > 0) {
ssize_t write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf)
{
- dout(20) << "write " << ictx << " off = " << off << " len = " << len << dendl;
+ ldout(ictx->cct, 20) << "write " << ictx << " off = " << off << " len = " << len << dendl;
if (!len)
return 0;
void AioBlockCompletion::complete(ssize_t r)
{
- dout(10) << "AioBlockCompletion::complete()" << dendl;
+ ldout(cct, 10) << "AioBlockCompletion::complete()" << dendl;
if ((r >= 0 || r == -ENOENT) && buf) { // this was a sparse_read operation
map<uint64_t, uint64_t>::iterator iter;
uint64_t bl_ofs = 0, buf_bl_pos = 0;
- dout(10) << "ofs=" << ofs << " len=" << len << dendl;
+ ldout(cct, 10) << "ofs=" << ofs << " len=" << len << dendl;
for (iter = m.begin(); iter != m.end(); ++iter) {
uint64_t extent_ofs = iter->first;
size_t extent_len = iter->second;
- dout(10) << "extent_ofs=" << extent_ofs << " extent_len=" << extent_len << dendl;
+ ldout(cct, 10) << "extent_ofs=" << extent_ofs << " extent_len=" << extent_len << dendl;
/* a hole? */
if (extent_ofs - ofs) {
- dout(10) << "<1>zeroing " << buf_bl_pos << "~" << extent_ofs << dendl;
- dout(10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + extent_ofs - ofs - 1) << dendl;
+ ldout(cct, 10) << "<1>zeroing " << buf_bl_pos << "~" << extent_ofs << dendl;
+ ldout(cct, 10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + extent_ofs - ofs - 1) << dendl;
memset(buf + buf_bl_pos, 0, extent_ofs - ofs);
}
buf_bl_pos += extent_ofs - ofs;
/* data */
- dout(10) << "<2>copying " << buf_bl_pos << "~" << extent_len << " from ofs=" << bl_ofs << dendl;
- dout(10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + buf_bl_pos + extent_len -1) << dendl;
+ ldout(cct, 10) << "<2>copying " << buf_bl_pos << "~" << extent_len << " from ofs=" << bl_ofs << dendl;
+ ldout(cct, 10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + buf_bl_pos + extent_len -1) << dendl;
memcpy(buf + buf_bl_pos, data_bl.c_str() + bl_ofs, extent_len);
bl_ofs += extent_len;
buf_bl_pos += extent_len;
/* last hole */
if (len - buf_bl_pos) {
- dout(10) << "<3>zeroing " << buf_bl_pos << "~" << len - buf_bl_pos << dendl;
- dout(10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + len -1) << dendl;
+ ldout(cct, 10) << "<3>zeroing " << buf_bl_pos << "~" << len - buf_bl_pos << dendl;
+ ldout(cct, 10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + len -1) << dendl;
memset(buf + buf_bl_pos, 0, len - buf_bl_pos);
}
void AioCompletion::complete_block(AioBlockCompletion *block_completion, ssize_t r)
{
- dout(20) << "AioCompletion::complete_block() this=" << (void *)this << " complete_cb=" << (void *)complete_cb << dendl;
+ CephContext *cct = block_completion->cct;
+ ldout(cct, 20) << "AioCompletion::complete_block() this="
+ << (void *)this << " complete_cb=" << (void *)complete_cb << dendl;
lock.Lock();
if (rval >= 0) {
if (r < 0 && r != -EEXIST)
void rados_cb(rados_completion_t c, void *arg)
{
- dout(10) << "rados_cb" << dendl;
AioBlockCompletion *block_completion = (AioBlockCompletion *)arg;
block_completion->complete(rados_aio_get_return_value(c));
delete block_completion;
int aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
AioCompletion *c)
{
- dout(20) << "aio_write " << ictx << " off = " << off << " len = " << len << dendl;
+ CephContext *cct = ictx->cct;
+ ldout(cct, 20) << "aio_write " << ictx << " off = " << off << " len = " << len << dendl;
if (!len)
return 0;
ictx->lock.Unlock();
uint64_t write_len = min(block_size - block_ofs, left);
bl.append(buf + total_write, write_len);
- AioBlockCompletion *block_completion = new AioBlockCompletion(c, off, len, NULL);
+ AioBlockCompletion *block_completion = new AioBlockCompletion(cct, c, off, len, NULL);
c->add_block_completion(block_completion);
librados::AioCompletion *rados_completion =
Rados::aio_create_completion(block_completion, NULL, rados_cb);
void rados_aio_sparse_read_cb(rados_completion_t c, void *arg)
{
- dout(10) << "rados_aio_sparse_read_cb" << dendl;
AioBlockCompletion *block_completion = (AioBlockCompletion *)arg;
block_completion->complete(rados_aio_get_return_value(c));
delete block_completion;
char *buf,
AioCompletion *c)
{
- dout(20) << "aio_read " << ictx << " off = " << off << " len = " << len << dendl;
+ ldout(ictx->cct, 20) << "aio_read " << ictx << " off = " << off << " len = " << len << dendl;
int r = ictx_check(ictx);
if (r < 0)
map<uint64_t,uint64_t> m;
map<uint64_t,uint64_t>::iterator iter;
- AioBlockCompletion *block_completion = new AioBlockCompletion(c, block_ofs, read_len, buf + total_read);
+ AioBlockCompletion *block_completion =
+ new AioBlockCompletion(ictx->cct, c, block_ofs, read_len, buf + total_read);
c->add_block_completion(block_completion);
librados::AioCompletion *rados_completion =
ImageCtx *ictx = (ImageCtx *)ctx;
bufferptr ptr(len);
bl.push_back(ptr);
- dout(10) << "Image::aio_read() buf=" << (void *)bl.c_str() << "~" << (void *)(bl.c_str() + len - 1) << dendl;
+ ldout(ictx->cct, 10) << "Image::aio_read() buf=" << (void *)bl.c_str() << "~" << (void *)(bl.c_str() + len - 1) << dendl;
return librbd::aio_read(ictx, off, len, bl.c_str(), (librbd::AioCompletion *)c->pc);
}