int rados_pool_list(rados_t cluster, char *buf, int len);
int rados_ioctx_open(rados_t cluster, const char *pool_name, rados_ioctx_t *ioctx);
-int rados_ioctx_close(rados_ioctx_t io);
+void rados_ioctx_close(rados_ioctx_t io);
int rados_ioctx_lookup(rados_t cluster, const char *pool_name);
int rados_ioctx_stat(rados_ioctx_t io, struct rados_ioctx_stat_t *stats);
int rados_pool_create_with_all(rados_t cluster, const char *pool_name, uint64_t auid,
__u8 crush_rule);
int rados_pool_delete(rados_t cluster, const char *pool_name);
-int rados_ioctx_pool_delete(rados_ioctx_t io);
int rados_ioctx_pool_set_auid(rados_ioctx_t io, uint64_t auid);
/* objects */
int rbd_list(rados_ioctx_t io, char *names, size_t *size);
int rbd_create(rados_ioctx_t io, const char *name, size_t size, int *order);
int rbd_remove(rados_ioctx_t io, const char *name);
-int rbd_copy(rados_ioctx_t src_pool, const char *srcname, rados_ioctx_t dest_pool, const char *destname);
-int rbd_rename(rados_ioctx_t src_pool, const char *srcname, const char *destname);
+int rbd_copy(rados_ioctx_t src_io_ctx, const char *srcname, rados_ioctx_t dest_io_ctx, const char *destname);
+int rbd_rename(rados_ioctx_t src_io_ctx, const char *srcname, const char *destname);
int rbd_open(rados_ioctx_t io, const char *name, rbd_image_t *image, const char *snap_name);
int rbd_close(rbd_image_t image);
void version(int *major, int *minor, int *extra);
- int open(IoCtx& pool, Image *image, const char *name);
- int open(IoCtx& pool, Image *image, const char *name, const char *snapname);
- int list(IoCtx& pool, std::vector<std::string>& names);
- int create(IoCtx& pool, const char *name, size_t size, int *order);
- int remove(IoCtx& pool, const char *name);
- int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *destname);
- int rename(IoCtx& src_pool, const char *srcname, const char *destname);
+ int open(IoCtx& io_ctx, Image *image, const char *name);
+ int open(IoCtx& io_ctx, Image *image, const char *name, const char *snapname);
+ int list(IoCtx& io_ctx, std::vector<std::string>& names);
+ int create(IoCtx& io_ctx, const char *name, size_t size, int *order);
+ int remove(IoCtx& io_ctx, const char *name);
+ int copy(IoCtx& src_io_ctx, const char *srcname, IoCtx& dest_io_ctx, const char *destname);
+ int rename(IoCtx& src_io_ctx, const char *srcname, const char *destname);
private:
/* We don't allow assignment or copying */
return radosp->lookup_pool(name);
}
-extern "C" int rados_ioctx_list(rados_t cluster, char *buf, int len)
+extern "C" int rados_pool_list(rados_t cluster, char *buf, int len)
{
RadosClient *client = (RadosClient *)cluster;
std::list<std::string> pools;
return poolid;
}
-extern "C" int rados_ioctx_close(rados_ioctx_t io)
+extern "C" void rados_ioctx_close(rados_ioctx_t io)
{
IoCtxImpl *ctx = (IoCtxImpl *)io;
delete ctx;
- return 0;
}
extern "C" int rados_ioctx_stat(rados_ioctx_t io, struct rados_ioctx_stat_t *stats)
return ver.version;
}
-extern "C" int rados_ioctx_create(rados_t cluster, const char *name)
+extern "C" int rados_pool_create(rados_t cluster, const char *name)
{
RadosClient *radosp = (RadosClient *)cluster;
string sname(name);
return radosp->pool_create(sname);
}
-extern "C" int rados_ioctx_create_with_auid(rados_t cluster, const char *name,
+extern "C" int rados_pool_create_with_auid(rados_t cluster, const char *name,
uint64_t auid)
{
RadosClient *radosp = (RadosClient *)cluster;
return radosp->pool_create(sname, auid);
}
-extern "C" int rados_ioctx_create_with_crush_rule(rados_t cluster, const char *name,
+extern "C" int rados_pool_create_with_crush_rule(rados_t cluster, const char *name,
__u8 crush_rule)
{
RadosClient *radosp = (RadosClient *)cluster;
return radosp->pool_create(sname, 0, crush_rule);
}
-extern "C" int rados_ioctx_create_with_all(rados_t cluster, const char *name,
+extern "C" int rados_pool_create_with_all(rados_t cluster, const char *name,
uint64_t auid, __u8 crush_rule)
{
RadosClient *radosp = (RadosClient *)cluster;
return client->pool_delete(pool_name);
}
-extern "C" int rados_ioctx_change_auid(rados_ioctx_t io, uint64_t auid)
+extern "C" int rados_ioctx_pool_set_auid(rados_ioctx_t io, uint64_t auid)
{
IoCtxImpl *ctx = (IoCtxImpl *)io;
return ctx->client->pool_change_auid(ctx, auid);
std::map<std::string, struct SnapInfo> snaps_by_name;
uint64_t snapid;
std::string name;
- IoCtx &pool;
+ IoCtx &io_ctx;
WatchCtx *wctx;
bool needs_refresh;
Mutex lock;
ImageCtx(std::string imgname, IoCtx& p) : snapid(0),
name(imgname),
- pool(p),
+ io_ctx(p),
needs_refresh(true),
lock("librbd::ImageCtx::lock") {}
int snap_set(std::string snap_name)
void rados_aio_sparse_read_cb(rados_completion_t cb, void *arg);
int snap_set(ImageCtx *ictx, const char *snap_name);
- int list(IoCtx& pool, std::vector<string>& names);
- int create(IoCtx& pool, string& md_oid, const char *imgname, uint64_t size, int *order);
- int rename(IoCtx& pool, const char *srcname, const char *dstname);
+ int list(IoCtx& io_ctx, std::vector<string>& names);
+ int create(IoCtx& io_ctx, string& md_oid, const char *imgname, uint64_t size, int *order);
+ int rename(IoCtx& io_ctx, const char *srcname, const char *dstname);
int info(ImageCtx *ictx, image_info_t& info, size_t image_size);
- int remove(IoCtx& pool, const char *imgname);
+ int remove(IoCtx& io_ctx, const char *imgname);
int resize(ImageCtx *ictx, uint64_t size);
int snap_create(ImageCtx *ictx, const char *snap_name);
int snap_list(ImageCtx *ictx, std::vector<snap_info_t>& snaps);
int snap_rollback(ImageCtx *ictx, const char *snap_name);
int snap_remove(ImageCtx *ictx, const char *snap_name);
int add_snap(ImageCtx *ictx, const char *snap_name);
- int rm_snap(IoCtx& pool, string& md_oid, const char *snap_name);
+ int rm_snap(IoCtx& io_ctx, string& md_oid, const char *snap_name);
int ictx_check(ImageCtx *ictx);
int ictx_refresh(ImageCtx *ictx, const char *snap_name);
- int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *destname);
+ int copy(IoCtx& src_io_ctx, const char *srcname, IoCtx& dest_io_ctx, const char *destname);
- int open_image(IoCtx& pool, ImageCtx *ictx, const char *name, const char *snap_name);
+ int open_image(IoCtx& io_ctx, ImageCtx *ictx, const char *name, const char *snap_name);
void close_image(ImageCtx *ictx);
- void trim_image(IoCtx& pool, rbd_obj_header_ondisk *header, uint64_t newsize);
- int read_rbd_info(IoCtx& pool, string& info_oid, struct rbd_info *info);
-
- int touch_rbd_info(IoCtx& pool, string& info_oid);
- int rbd_assign_bid(IoCtx& pool, string& info_oid, uint64_t *id);
- int read_header_bl(IoCtx& pool, string& md_oid, bufferlist& header, uint64_t *ver);
- int notify_change(IoCtx& pool, string& oid, uint64_t *pver, ImageCtx *ictx);
- int read_header(IoCtx& pool, string& md_oid, struct rbd_obj_header_ondisk *header, uint64_t *ver);
- int write_header(IoCtx& pool, string& md_oid, bufferlist& header);
- int tmap_set(IoCtx& pool, string& imgname);
- int tmap_rm(IoCtx& pool, string& imgname);
+ void trim_image(IoCtx& io_ctx, rbd_obj_header_ondisk *header, uint64_t newsize);
+ int read_rbd_info(IoCtx& io_ctx, string& info_oid, struct rbd_info *info);
+
+ int touch_rbd_info(IoCtx& io_ctx, string& info_oid);
+ int rbd_assign_bid(IoCtx& io_ctx, string& info_oid, uint64_t *id);
+ int read_header_bl(IoCtx& io_ctx, string& md_oid, bufferlist& header, uint64_t *ver);
+ int notify_change(IoCtx& io_ctx, string& oid, uint64_t *pver, ImageCtx *ictx);
+ int read_header(IoCtx& io_ctx, string& md_oid, struct rbd_obj_header_ondisk *header, uint64_t *ver);
+ int write_header(IoCtx& io_ctx, string& md_oid, bufferlist& header);
+ int tmap_set(IoCtx& io_ctx, string& imgname);
+ int tmap_rm(IoCtx& io_ctx, string& imgname);
int rollback_image(ImageCtx *ictx, const char *snap_name);
void image_info(rbd_obj_header_ondisk& header, image_info_t& info, size_t info_size);
string get_block_oid(rbd_obj_header_ondisk *header, uint64_t num);
return 0;
}
-void trim_image(IoCtx& pool, rbd_obj_header_ondisk *header, uint64_t newsize)
+void trim_image(IoCtx& io_ctx, rbd_obj_header_ondisk *header, uint64_t newsize)
{
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;
for (uint64_t i=start; i<numseg; i++) {
string oid = get_block_oid(header, i);
- pool.remove(oid);
+ io_ctx.remove(oid);
if ((i & 127) == 0) {
dout(2) << "\r\t" << i << "/" << numseg << dendl;
}
}
}
-int read_rbd_info(IoCtx& pool, string& info_oid, struct rbd_info *info)
+int read_rbd_info(IoCtx& io_ctx, string& info_oid, struct rbd_info *info)
{
int r;
bufferlist bl;
- r = pool.read(info_oid, bl, sizeof(*info), 0);
+ r = io_ctx.read(info_oid, bl, sizeof(*info), 0);
if (r < 0)
return r;
if (r == 0) {
return 0;
}
-int touch_rbd_info(IoCtx& pool, string& info_oid)
+int touch_rbd_info(IoCtx& io_ctx, string& info_oid)
{
bufferlist bl;
- int r = pool.write(info_oid, bl, 0, 0);
+ int r = io_ctx.write(info_oid, bl, 0, 0);
if (r < 0)
return r;
return 0;
}
-int rbd_assign_bid(IoCtx& pool, string& info_oid, uint64_t *id)
+int rbd_assign_bid(IoCtx& io_ctx, string& info_oid, uint64_t *id)
{
bufferlist bl, out;
*id = 0;
- int r = touch_rbd_info(pool, info_oid);
+ int r = touch_rbd_info(io_ctx, info_oid);
if (r < 0)
return r;
- r = pool.exec(info_oid, "rbd", "assign_bid", bl, out);
+ r = io_ctx.exec(info_oid, "rbd", "assign_bid", bl, out);
if (r < 0)
return r;
}
-int read_header_bl(IoCtx& pool, string& md_oid, bufferlist& header, uint64_t *ver)
+int read_header_bl(IoCtx& io_ctx, string& md_oid, bufferlist& header, uint64_t *ver)
{
int r;
#define READ_SIZE 4096
do {
bufferlist bl;
- r = pool.read(md_oid, bl, READ_SIZE, 0);
+ r = io_ctx.read(md_oid, bl, READ_SIZE, 0);
if (r < 0)
return r;
header.claim_append(bl);
} while (r == READ_SIZE);
if (ver)
- *ver = pool.get_last_version();
+ *ver = io_ctx.get_last_version();
return 0;
}
-int notify_change(IoCtx& pool, string& oid, uint64_t *pver, ImageCtx *ictx)
+int notify_change(IoCtx& io_ctx, string& oid, uint64_t *pver, ImageCtx *ictx)
{
uint64_t ver;
if (pver)
ver = *pver;
else
- ver = pool.get_last_version();
- pool.notify(oid, ver);
+ ver = io_ctx.get_last_version();
+ io_ctx.notify(oid, ver);
return 0;
}
-int read_header(IoCtx& pool, string& md_oid, struct rbd_obj_header_ondisk *header, uint64_t *ver)
+int read_header(IoCtx& io_ctx, string& md_oid, struct rbd_obj_header_ondisk *header, uint64_t *ver)
{
bufferlist header_bl;
- int r = read_header_bl(pool, md_oid, header_bl, ver);
+ int r = read_header_bl(io_ctx, md_oid, header_bl, ver);
if (r < 0)
return r;
if (header_bl.length() < (int)sizeof(*header))
return 0;
}
-int write_header(IoCtx& pool, string& md_oid, bufferlist& header)
+int write_header(IoCtx& io_ctx, string& md_oid, bufferlist& header)
{
bufferlist bl;
- int r = pool.write(md_oid, header, header.length(), 0);
+ int r = io_ctx.write(md_oid, header, header.length(), 0);
- notify_change(pool, md_oid, NULL, NULL);
+ notify_change(io_ctx, md_oid, NULL, NULL);
return r;
}
-int tmap_set(IoCtx& pool, string& imgname)
+int tmap_set(IoCtx& io_ctx, string& imgname)
{
bufferlist cmdbl, emptybl;
__u8 c = CEPH_OSD_TMAP_SET;
::encode(c, cmdbl);
::encode(imgname, cmdbl);
::encode(emptybl, cmdbl);
- return pool.tmap_update(RBD_DIRECTORY, cmdbl);
+ return io_ctx.tmap_update(RBD_DIRECTORY, cmdbl);
}
-int tmap_rm(IoCtx& pool, string& imgname)
+int tmap_rm(IoCtx& io_ctx, string& imgname)
{
bufferlist cmdbl;
__u8 c = CEPH_OSD_TMAP_RM;
::encode(c, cmdbl);
::encode(imgname, cmdbl);
- return pool.tmap_update(RBD_DIRECTORY, cmdbl);
+ return io_ctx.tmap_update(RBD_DIRECTORY, cmdbl);
}
int rollback_image(ImageCtx *ictx, const char *snap_name)
for (uint64_t i = 0; i < numseg; i++) {
int r;
string oid = get_block_oid(&(ictx->header), i);
- r = ictx->pool.rollback(oid, snap_name);
+ r = ictx->io_ctx.rollback(oid, snap_name);
if (r < 0 && r != -ENOENT)
return r;
}
return 0;
}
-int list(IoCtx& pool, std::vector<std::string>& names)
+int list(IoCtx& io_ctx, std::vector<std::string>& names)
{
bufferlist bl;
- int r = pool.read(RBD_DIRECTORY, bl, 0, 0);
+ int r = io_ctx.read(RBD_DIRECTORY, bl, 0, 0);
if (r < 0)
return r;
string md_oid = ictx->name;
md_oid += RBD_SUFFIX;
- r = ictx->pool.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
+ r = ictx->io_ctx.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
if (r < 0)
return r;
// probably a bug: what's so special about snap 0? (as opposed to CEPH_NOSNAP, etc?)
- ictx->pool.snap_set_read(0);
+ ictx->io_ctx.snap_set_read(0);
r = add_snap(ictx, snap_name);
- notify_change(ictx->pool, md_oid, NULL, ictx);
+ notify_change(ictx->io_ctx, md_oid, NULL, ictx);
return r;
}
if (r < 0)
return r;
- r = ictx->pool.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
+ r = ictx->io_ctx.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
if (r < 0)
return r;
- ictx->pool.snap_set_read(ictx->snapid);
+ ictx->io_ctx.snap_set_read(ictx->snapid);
- r = rm_snap(ictx->pool, md_oid, snap_name);
- r = ictx->pool.selfmanaged_snap_remove(ictx->snapid);
- notify_change(ictx->pool, md_oid, NULL, ictx);
+ r = rm_snap(ictx->io_ctx, md_oid, snap_name);
+ r = ictx->io_ctx.selfmanaged_snap_remove(ictx->snapid);
+ notify_change(ictx->io_ctx, md_oid, NULL, ictx);
return r;
}
-int create(IoCtx& pool, string& md_oid, const char *imgname,
+int create(IoCtx& io_ctx, string& md_oid, const char *imgname,
uint64_t size, int *order)
{
// make sure it doesn't already exist
- int r = pool.stat(md_oid, NULL, NULL);
+ int r = io_ctx.stat(md_oid, NULL, NULL);
if (r == 0) {
derr << "rbd image header " << md_oid << " already exists" << dendl;
return -EEXIST;
uint64_t bid;
string dir_info = RBD_INFO;
- r = rbd_assign_bid(pool, dir_info, &bid);
+ r = rbd_assign_bid(io_ctx, dir_info, &bid);
if (r < 0) {
derr << "failed to assign a block name for image" << dendl;
return r;
::encode(c, cmdbl);
::encode(imgname, cmdbl);
::encode(emptybl, cmdbl);
- r = pool.tmap_update(RBD_DIRECTORY, cmdbl);
+ r = io_ctx.tmap_update(RBD_DIRECTORY, cmdbl);
if (r < 0) {
derr << "error adding img to directory: " << strerror(-r)<< dendl;
return r;
}
dout(2) << "creating rbd image..." << dendl;
- r = pool.write(md_oid, bl, bl.length(), 0);
+ r = io_ctx.write(md_oid, bl, bl.length(), 0);
if (r < 0) {
derr << "error writing header: " << strerror(-r) << dendl;
return r;
return 0;
}
-int rename(IoCtx& pool, const char *srcname, const char *dstname)
+int rename(IoCtx& io_ctx, const char *srcname, const char *dstname)
{
string md_oid = srcname;
md_oid += RBD_SUFFIX;
string imgname_str = srcname;
uint64_t ver;
bufferlist header;
- int r = read_header_bl(pool, md_oid, header, &ver);
+ int r = read_header_bl(io_ctx, md_oid, header, &ver);
if (r < 0) {
derr << "error reading header: " << md_oid << ": " << strerror(-r) << dendl;
return r;
}
- r = pool.stat(dst_md_oid, NULL, NULL);
+ r = io_ctx.stat(dst_md_oid, NULL, NULL);
if (r == 0) {
derr << "rbd image header " << dst_md_oid << " already exists" << dendl;
return -EEXIST;
}
- r = write_header(pool, dst_md_oid, header);
+ r = write_header(io_ctx, dst_md_oid, header);
if (r < 0) {
derr << "error writing header: " << dst_md_oid << ": " << strerror(-r) << dendl;
return r;
}
- r = tmap_set(pool, dstname_str);
+ r = tmap_set(io_ctx, dstname_str);
if (r < 0) {
- pool.remove(dst_md_oid);
+ io_ctx.remove(dst_md_oid);
derr << "can't add " << dst_md_oid << " to directory" << dendl;
return r;
}
- r = tmap_rm(pool, imgname_str);
+ r = tmap_rm(io_ctx, imgname_str);
if (r < 0)
derr << "warning: couldn't remove old entry from directory (" << imgname_str << ")" << dendl;
- r = pool.remove(md_oid);
+ r = io_ctx.remove(md_oid);
if (r < 0)
derr << "warning: couldn't remove old metadata" << dendl;
- notify_change(pool, md_oid, NULL, NULL);
+ notify_change(io_ctx, md_oid, NULL, NULL);
return 0;
}
return 0;
}
-int remove(IoCtx& pool, const char *imgname)
+int remove(IoCtx& io_ctx, const char *imgname)
{
string md_oid = imgname;
md_oid += RBD_SUFFIX;
struct rbd_obj_header_ondisk header;
- int r = read_header(pool, md_oid, &header, NULL);
+ int r = read_header(io_ctx, md_oid, &header, NULL);
if (r >= 0) {
- trim_image(pool, &header, 0);
+ trim_image(io_ctx, &header, 0);
dout(2) << "\rremoving header..." << dendl;
- pool.remove(md_oid);
+ io_ctx.remove(md_oid);
}
dout(2) << "removing rbd image to directory..." << dendl;
__u8 c = CEPH_OSD_TMAP_RM;
::encode(c, cmdbl);
::encode(imgname, cmdbl);
- r = pool.tmap_update(RBD_DIRECTORY, cmdbl);
+ r = io_ctx.tmap_update(RBD_DIRECTORY, cmdbl);
if (r < 0) {
derr << "error removing img from directory: " << strerror(-r)<< dendl;
return r;
ictx->header.image_size = size;
} else {
dout(2) << "shrinking image " << size << " -> " << ictx->header.image_size << " objects" << dendl;
- trim_image(ictx->pool, &(ictx->header), size);
+ trim_image(ictx->io_ctx, &(ictx->header), size);
ictx->header.image_size = size;
}
// rewrite header
bufferlist bl;
bl.append((const char *)&(ictx->header), sizeof(ictx->header));
- r = ictx->pool.write(md_oid, bl, bl.length(), 0);
+ r = ictx->io_ctx.write(md_oid, bl, bl.length(), 0);
if (r == -ERANGE)
derr << "operation might have conflicted with another client!" << dendl;
if (r < 0) {
derr << "error writing header: " << strerror(-r) << dendl;
return r;
} else {
- notify_change(ictx->pool, md_oid, NULL, ictx);
+ notify_change(ictx->io_ctx, md_oid, NULL, ictx);
}
dout(2) << "done." << dendl;
string md_oid = ictx->name;
md_oid += RBD_SUFFIX;
- int r = ictx->pool.selfmanaged_snap_create(&snap_id);
+ int r = ictx->io_ctx.selfmanaged_snap_create(&snap_id);
if (r < 0) {
derr << "failed to create snap id: " << strerror(-r) << dendl;
return r;
::encode(snap_name, bl);
::encode(snap_id, bl);
- r = ictx->pool.exec(md_oid, "rbd", "snap_add", bl, bl2);
+ r = ictx->io_ctx.exec(md_oid, "rbd", "snap_add", bl, bl2);
if (r < 0) {
derr << "rbd.snap_add execution failed failed: " << strerror(-r) << dendl;
return r;
}
- notify_change(ictx->pool, md_oid, NULL, ictx);
+ notify_change(ictx->io_ctx, md_oid, NULL, ictx);
return 0;
}
-int rm_snap(IoCtx& pool, string& md_oid, const char *snap_name)
+int rm_snap(IoCtx& io_ctx, string& md_oid, const char *snap_name)
{
bufferlist bl, bl2;
::encode(snap_name, bl);
- int r = pool.exec(md_oid, "rbd", "snap_remove", bl, bl2);
+ int r = io_ctx.exec(md_oid, "rbd", "snap_remove", bl, bl2);
if (r < 0) {
derr << "rbd.snap_remove execution failed failed: " << strerror(-r) << dendl;
return r;
string md_oid = ictx->name;
md_oid += RBD_SUFFIX;
- int r = read_header(ictx->pool, md_oid, &(ictx->header), NULL);
+ int r = read_header(ictx->io_ctx, md_oid, &(ictx->header), NULL);
if (r < 0)
return r;
- r = ictx->pool.exec(md_oid, "rbd", "snap_list", bl, bl2);
+ r = ictx->io_ctx.exec(md_oid, "rbd", "snap_list", bl, bl2);
if (r < 0)
return r;
if (r < 0)
return r;
- r = ictx->pool.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
+ r = ictx->io_ctx.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
if (r < 0)
return r;
- ictx->pool.snap_set_read(ictx->snapid);
+ ictx->io_ctx.snap_set_read(ictx->snapid);
r = rollback_image(ictx, snap_name);
if (r < 0)
return r;
return 0;
}
-int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *destname)
+int copy(IoCtx& src_io_ctx, const char *srcname, IoCtx& dest_io_ctx, const char *destname)
{
struct rbd_obj_header_ondisk header, dest_header;
int64_t ret;
dest_md_oid = destname;
dest_md_oid += RBD_SUFFIX;
- ret = read_header(src_pool, md_oid, &header, NULL);
+ ret = read_header(src_io_ctx, md_oid, &header, NULL);
if (ret < 0)
return ret;
uint64_t block_size = get_block_size(&header);
int order = header.options.order;
- r = create(dest_pool, dest_md_oid, destname, header.image_size, &order);
+ r = create(dest_io_ctx, dest_md_oid, destname, header.image_size, &order);
if (r < 0) {
derr << "header creation failed" << dendl;
return r;
}
- ret = read_header(dest_pool, dest_md_oid, &dest_header, NULL);
+ ret = read_header(dest_io_ctx, dest_md_oid, &dest_header, NULL);
if (ret < 0) {
derr << "failed to read newly created header" << dendl;
return ret;
string dest_oid = get_block_oid(&dest_header, i);
map<off_t, size_t> m;
map<off_t, size_t>::iterator iter;
- r = src_pool.sparse_read(oid, m, bl, block_size, 0);
+ r = src_io_ctx.sparse_read(oid, m, bl, block_size, 0);
if (r < 0 && r == -ENOENT)
r = 0;
if (r < 0)
return -EIO;
}
bl.copy(extent_ofs, extent_len, wrbl);
- r = dest_pool.write(dest_oid, wrbl, extent_len, extent_ofs);
+ r = dest_io_ctx.write(dest_oid, wrbl, extent_len, extent_ofs);
if (r < 0)
goto done;
}
if (r < 0)
return r;
- r = ictx->pool.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
+ r = ictx->io_ctx.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
if (r < 0)
return r;
- ictx->pool.snap_set_read(ictx->snapid);
+ ictx->io_ctx.snap_set_read(ictx->snapid);
return 0;
}
-int open_image(IoCtx& pool, ImageCtx *ictx, const char *name, const char *snap_name)
+int open_image(IoCtx& io_ctx, ImageCtx *ictx, const char *name, const char *snap_name)
{
int r = ictx_refresh(ictx, snap_name);
if (r < 0)
string md_oid = name;
md_oid += RBD_SUFFIX;
- r = ictx->pool.watch(md_oid, 0, &(wctx->cookie), wctx);
+ r = ictx->io_ctx.watch(md_oid, 0, &(wctx->cookie), wctx);
return r;
}
md_oid += RBD_SUFFIX;
ictx->wctx->invalidate();
- ictx->pool.unwatch(md_oid, ictx->wctx->cookie);
+ ictx->io_ctx.unwatch(md_oid, ictx->wctx->cookie);
delete ictx->wctx;
delete ictx;
ictx = NULL;
map<off_t, size_t> m;
map<off_t, size_t>::iterator iter;
off_t bl_ofs = 0, buf_bl_pos = 0;
- r = ictx->pool.sparse_read(oid, m, bl, read_len, block_ofs);
+ r = ictx->io_ctx.sparse_read(oid, m, bl, read_len, block_ofs);
if (r < 0 && r == -ENOENT)
r = 0;
if (r < 0) {
uint64_t block_ofs = get_block_ofs(&ictx->header, off + total_write);
uint64_t write_len = min(block_size - block_ofs, left);
bl.append(buf + total_write, write_len);
- r = ictx->pool.write(oid, bl, write_len, block_ofs);
+ r = ictx->io_ctx.write(oid, bl, write_len, block_ofs);
if (r < 0)
return r;
if ((uint64_t)r != write_len)
c->add_block_completion(block_completion);
librados::AioCompletion *rados_completion =
Rados::aio_create_completion(block_completion, NULL, rados_cb);
- r = ictx->pool.aio_write(oid, rados_completion, bl, write_len, block_ofs);
+ r = ictx->io_ctx.aio_write(oid, rados_completion, bl, write_len, block_ofs);
if (r < 0)
goto done;
total_write += write_len;
librados::AioCompletion *rados_completion =
Rados::aio_create_completion(block_completion, rados_aio_sparse_read_cb, rados_cb);
- r = ictx->pool.aio_sparse_read(oid, rados_completion,
+ r = ictx->io_ctx.aio_sparse_read(oid, rados_completion,
&block_completion->m, &block_completion->data_bl,
read_len, block_ofs);
if (r < 0 && r == -ENOENT)
rbd_version(major, minor, extra);
}
-int RBD::open(IoCtx& pool, Image *image, const char *name)
+int RBD::open(IoCtx& io_ctx, Image *image, const char *name)
{
- return open(pool, image, name, NULL);
+ return open(io_ctx, image, name, NULL);
}
-int RBD::open(IoCtx& pool, Image *image, const char *name, const char *snapname)
+int RBD::open(IoCtx& io_ctx, Image *image, const char *name, const char *snapname)
{
- ImageCtx *ictx = new ImageCtx(name, pool);
+ ImageCtx *ictx = new ImageCtx(name, io_ctx);
if (!ictx)
return -ENOMEM;
- int r = librbd::open_image(pool, ictx, name, snapname);
+ int r = librbd::open_image(io_ctx, ictx, name, snapname);
if (r < 0)
return r;
return 0;
}
-int RBD::create(IoCtx& pool, const char *name, size_t size, int *order)
+int RBD::create(IoCtx& io_ctx, const char *name, size_t size, int *order)
{
string md_oid = name;
md_oid += RBD_SUFFIX;
- int r = librbd::create(pool, md_oid, name, size, order);
+ int r = librbd::create(io_ctx, md_oid, name, size, order);
return r;
}
-int RBD::remove(IoCtx& pool, const char *name)
+int RBD::remove(IoCtx& io_ctx, const char *name)
{
- int r = librbd::remove(pool, name);
+ int r = librbd::remove(io_ctx, name);
return r;
}
-int RBD::list(IoCtx& pool, std::vector<std::string>& names)
+int RBD::list(IoCtx& io_ctx, std::vector<std::string>& names)
{
- int r = librbd::list(pool, names);
+ int r = librbd::list(io_ctx, names);
return r;
}
-int RBD::copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *destname)
+int RBD::copy(IoCtx& src_io_ctx, const char *srcname, IoCtx& dest_io_ctx, const char *destname)
{
- int r = librbd::copy(src_pool, srcname, dest_pool, destname);
+ int r = librbd::copy(src_io_ctx, srcname, dest_io_ctx, destname);
return r;
}
-int RBD::rename(IoCtx& src_pool, const char *srcname, const char *destname)
+int RBD::rename(IoCtx& src_io_ctx, const char *srcname, const char *destname)
{
- int r = librbd::rename(src_pool, srcname, destname);
+ int r = librbd::rename(src_io_ctx, srcname, destname);
return r;
}
/* images */
extern "C" int rbd_list(rados_ioctx_t p, char *names, size_t *size)
{
- librados::IoCtx pool;
- librados::IoCtx::from_rados_ioctx_t(p, pool);
+ librados::IoCtx io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
std::vector<std::string> cpp_names;
- int r = librbd::list(pool, cpp_names);
+ int r = librbd::list(io_ctx, cpp_names);
if (r == -ENOENT)
return 0;
extern "C" int rbd_create(rados_ioctx_t p, const char *name, size_t size, int *order)
{
- librados::IoCtx pool;
- librados::IoCtx::from_rados_ioctx_t(p, pool);
+ librados::IoCtx io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
string md_oid = name;
md_oid += RBD_SUFFIX;
- return librbd::create(pool, md_oid, name, size, order);
+ return librbd::create(io_ctx, md_oid, name, size, order);
}
extern "C" int rbd_remove(rados_ioctx_t p, const char *name)
{
- librados::IoCtx pool;
- librados::IoCtx::from_rados_ioctx_t(p, pool);
- return librbd::remove(pool, name);
+ librados::IoCtx io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
+ return librbd::remove(io_ctx, name);
}
extern "C" int rbd_copy(rados_ioctx_t src_p, const char *srcname, rados_ioctx_t dest_p, const char *destname)
{
- librados::IoCtx src_pool, dest_pool;
- librados::IoCtx::from_rados_ioctx_t(src_p, src_pool);
- librados::IoCtx::from_rados_ioctx_t(dest_p, dest_pool);
- return librbd::copy(src_pool, srcname, dest_pool, destname);
+ librados::IoCtx src_io_ctx, dest_io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(src_p, src_io_ctx);
+ librados::IoCtx::from_rados_ioctx_t(dest_p, dest_io_ctx);
+ return librbd::copy(src_io_ctx, srcname, dest_io_ctx, destname);
}
extern "C" int rbd_rename(rados_ioctx_t src_p, const char *srcname, const char *destname)
{
- librados::IoCtx src_pool;
- librados::IoCtx::from_rados_ioctx_t(src_p, src_pool);
- return librbd::rename(src_pool, srcname, destname);
+ librados::IoCtx src_io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(src_p, src_io_ctx);
+ return librbd::rename(src_io_ctx, srcname, destname);
}
extern "C" int rbd_open(rados_ioctx_t p, const char *name, rbd_image_t *image, const char *snap_name)
{
- librados::IoCtx pool;
- librados::IoCtx::from_rados_ioctx_t(p, pool);
- librbd::ImageCtx *ictx = new librbd::ImageCtx(name, pool);
+ librados::IoCtx io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
+ librbd::ImageCtx *ictx = new librbd::ImageCtx(name, io_ctx);
if (!ictx)
return -ENOMEM;
- int r = librbd::open_image(pool, ictx, name, snap_name);
+ int r = librbd::open_image(io_ctx, ictx, name, snap_name);
*image = (rbd_image_t)ictx;
return r;
}
}
}
-int write_bench(librados::Rados& rados, librados::IoCtx& pool,
+int write_bench(librados::Rados& rados, librados::IoCtx& io_ctx,
int secondsToRun, int concurrentios, bench_data *data);
-int seq_read_bench(librados::Rados& rados, librados::IoCtx& pool,
+int seq_read_bench(librados::Rados& rados, librados::IoCtx& io_ctx,
int secondsToRun, int concurrentios, bench_data *data,
int writePid);
void *status_printer(void * data_store);
void sanitize_object_contents(bench_data *data, int length);
-int aio_bench(librados::Rados& rados, librados::IoCtx &pool, int operation,
+int aio_bench(librados::Rados& rados, librados::IoCtx &io_ctx, int operation,
int secondsToRun, int concurrentios, int op_size) {
int object_size = op_size;
int num_objects = 0;
//get data from previous write run, if available
if (operation != OP_WRITE) {
bufferlist object_data;
- r = pool.read(BENCH_DATA, object_data, sizeof(int)*3, 0);
+ r = io_ctx.read(BENCH_DATA, object_data, sizeof(int)*3, 0);
if (r <= 0) {
delete[] contentsChars;
if (r == -2)
sanitize_object_contents(data, data->object_size);
if (OP_WRITE == operation) {
- r = write_bench(rados, pool, secondsToRun, concurrentios, data);
+ r = write_bench(rados, io_ctx, secondsToRun, concurrentios, data);
if (r != 0) goto out;
}
else if (OP_SEQ_READ == operation) {
- r = seq_read_bench(rados, pool, secondsToRun, concurrentios, data, prevPid);
+ r = seq_read_bench(rados, io_ctx, secondsToRun, concurrentios, data, prevPid);
if (r != 0) goto out;
}
else if (OP_RAND_READ == operation) {
dataLock.Unlock();
}
-int write_bench(librados::Rados& rados, librados::IoCtx& pool,
+int write_bench(librados::Rados& rados, librados::IoCtx& io_ctx,
int secondsToRun, int concurrentios, bench_data *data) {
cout << "Maintaining " << concurrentios << " concurrent writes of "
<< data->object_size << " bytes for at least "
start_times[i] = g_clock.now();
completions[i] = rados.aio_create_completion((void *) &cond, 0,
&_aio_cb);
- r = pool.aio_write(name[i], completions[i], *contents[i], data->object_size, 0);
+ r = io_ctx.aio_write(name[i], completions[i], *contents[i], data->object_size, 0);
if (r < 0) { //naughty, doesn't clean up heap
goto ERR;
}
//and save locations of new stuff for later deletion
start_times[slot] = g_clock.now();
completions[slot] = rados.aio_create_completion((void *) &cond, 0, &_aio_cb);
- r = pool.aio_write(newName, completions[slot], *newContents, data->object_size, 0);
+ r = io_ctx.aio_write(newName, completions[slot], *newContents, data->object_size, 0);
if (r < 0) {//naughty; doesn't clean up heap space.
goto ERR;
}
::encode(data->object_size, b_write);
::encode(data->finished, b_write);
::encode(getpid(), b_write);
- pool.write(BENCH_DATA, b_write, sizeof(int)*3, 0);
+ io_ctx.write(BENCH_DATA, b_write, sizeof(int)*3, 0);
return 0;
ERR:
return -5;
}
-int seq_read_bench(librados::Rados& rados, librados::IoCtx& pool, int seconds_to_run,
+int seq_read_bench(librados::Rados& rados, librados::IoCtx& io_ctx, int seconds_to_run,
int concurrentios, bench_data *write_data, int pid) {
bench_data *data = new bench_data();
data->done = false;
index[i] = i;
start_times[i] = g_clock.now();
completions[i] = rados.aio_create_completion((void *) &cond, &_aio_cb, 0);
- r = pool.aio_read(name[i], completions[i], contents[i], data->object_size, 0);
+ r = io_ctx.aio_read(name[i], completions[i], contents[i], data->object_size, 0);
if (r < 0) { //naughty, doesn't clean up heap -- oh, or handle the print thread!
cerr << "r = " << r << std::endl;
goto ERR;
start_times[slot] = g_clock.now();
contents[slot] = new bufferlist();
completions[slot] = rados.aio_create_completion((void *) &cond, &_aio_cb, 0);
- r = pool.aio_read(newName, completions[slot], contents[slot], data->object_size, 0);
+ r = io_ctx.aio_read(newName, completions[slot], contents[slot], data->object_size, 0);
if (r < 0) {
goto ERR;
}
int ret = 0;
char buf[80];
- // open pool?
- IoCtx pool;
+ // open io context.
+ IoCtx io_ctx;
if (pool_name) {
- ret = rados.ioctx_open(pool_name, pool);
+ ret = rados.ioctx_open(pool_name, io_ctx);
if (ret < 0) {
cerr << "error opening pool " << pool_name << ": "
<< strerror_r(-ret, buf, sizeof(buf)) << std::endl;
// snapname?
if (snapname) {
- ret = pool.snap_lookup(snapname, &snapid);
+ ret = io_ctx.snap_lookup(snapname, &snapid);
if (ret < 0) {
cerr << "error looking up snap '" << snapname << "': " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
}
if (snapid != CEPH_NOSNAP) {
string name;
- ret = pool.snap_get_name(snapid, &name);
+ ret = io_ctx.snap_get_name(snapid, &name);
if (ret < 0) {
cerr << "snapid " << snapid << " doesn't exist in pool "
- << pool.get_pool_name() << std::endl;
+ << io_ctx.get_pool_name() << std::endl;
return 1;
}
- pool.snap_set_read(snapid);
+ io_ctx.snap_set_read(snapid);
cout << "selected snap " << snapid << " '" << snapname << "'" << std::endl;
}
outstream = new ofstream(nargs[1]);
{
- librados::ObjectIterator i = pool.objects_begin();
- librados::ObjectIterator i_end = pool.objects_end();
+ librados::ObjectIterator i = io_ctx.objects_begin();
+ librados::ObjectIterator i_end = io_ctx.objects_end();
for (; i != i_end; ++i) {
*outstream << *i << std::endl;
}
usage();
uint64_t new_auid = strtol(nargs[1], 0, 10);
- ret = pool.set_auid(new_auid);
+ ret = io_ctx.set_auid(new_auid);
if (ret < 0) {
- cerr << "error changing auid on pool " << pool.get_pool_name() << ':'
+ cerr << "error changing auid on pool " << io_ctx.get_pool_name() << ':'
<< strerror_r(-ret, buf, sizeof(buf)) << std::endl;
- } else cerr << "changed auid on pool " << pool.get_pool_name()
+ } else cerr << "changed auid on pool " << io_ctx.get_pool_name()
<< " to " << new_auid << std::endl;
}
else if (strcmp(nargs[0], "mapext") == 0) {
usage();
string oid(nargs[1]);
std::map<off_t, size_t> m;
- ret = pool.mapext(oid, 0, -1, m);
+ ret = io_ctx.mapext(oid, 0, -1, m);
if (ret < 0) {
cerr << "mapext error on " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
if (!pool_name || nargs.size() < 3)
usage();
string oid(nargs[1]);
- ret = pool.read(oid, outdata, 0, 0);
+ ret = io_ctx.read(oid, outdata, 0, 0);
if (ret < 0) {
cerr << "error reading " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
if (count == 0)
continue;
indata.append(buf, count);
- ret = pool.write(oid, indata, count, offset);
+ ret = io_ctx.write(oid, indata, count, offset);
indata.clear();
if (ret < 0) {
bufferlist bl;
bl.append(attr_val.c_str(), attr_val.length());
- ret = pool.setxattr(oid, attr_name.c_str(), bl);
+ ret = io_ctx.setxattr(oid, attr_name.c_str(), bl);
if (ret < 0) {
cerr << "error setting xattr " << pool_name << "/" << oid << "/" << attr_name << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
string attr_name(nargs[2]);
bufferlist bl;
- ret = pool.getxattr(oid, attr_name.c_str(), bl);
+ ret = io_ctx.getxattr(oid, attr_name.c_str(), bl);
if (ret < 0) {
cerr << "error getting xattr " << pool_name << "/" << oid << "/" << attr_name << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
string oid(nargs[1]);
string attr_name(nargs[2]);
- ret = pool.rmxattr(oid, attr_name.c_str());
+ ret = io_ctx.rmxattr(oid, attr_name.c_str());
if (ret < 0) {
cerr << "error removing xattr " << pool_name << "/" << oid << "/" << attr_name << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
string oid(nargs[1]);
map<std::string, bufferlist> attrset;
bufferlist bl;
- ret = pool.getxattrs(oid, attrset);
+ ret = io_ctx.getxattrs(oid, attrset);
if (ret < 0) {
cerr << "error getting xattr set " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
if (!pool_name || nargs.size() < 2)
usage();
string oid(nargs[1]);
- ret = pool.remove(oid);
+ ret = io_ctx.remove(oid);
if (ret < 0) {
cerr << "error removing " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
if (!pool_name || nargs.size() < 2)
usage();
string oid(nargs[1]);
- ret = pool.create(oid, true);
+ ret = io_ctx.create(oid, true);
if (ret < 0) {
cerr << "error creating " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
usage();
if (strcmp(nargs[1], "dump") == 0) {
string oid(nargs[2]);
- ret = pool.read(oid, outdata, 0, 0);
+ ret = io_ctx.read(oid, outdata, 0, 0);
if (ret < 0) {
cerr << "error reading " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
return 1;
usage();
vector<snap_t> snaps;
- pool.snap_list(&snaps);
+ io_ctx.snap_list(&snaps);
for (vector<snap_t>::iterator i = snaps.begin();
i != snaps.end();
i++) {
string s;
time_t t;
- if (pool.snap_get_name(*i, &s) < 0)
+ if (io_ctx.snap_get_name(*i, &s) < 0)
continue;
- if (pool.snap_get_stamp(*i, &t) < 0)
+ if (io_ctx.snap_get_stamp(*i, &t) < 0)
continue;
struct tm bdt;
localtime_r(&t, &bdt);
if (!pool_name || nargs.size() < 2)
usage();
- ret = pool.snap_create(nargs[1]);
+ ret = io_ctx.snap_create(nargs[1]);
if (ret < 0) {
cerr << "error creating pool " << pool_name << " snapshot " << nargs[1]
<< ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
if (!pool_name || nargs.size() < 2)
usage();
- ret = pool.snap_remove(nargs[1]);
+ ret = io_ctx.snap_remove(nargs[1]);
if (ret < 0) {
cerr << "error removing pool " << pool_name << " snapshot " << nargs[1]
<< ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
if (!pool_name || nargs.size() < 3)
usage();
- ret = pool.rollback(nargs[1], nargs[2]);
+ ret = io_ctx.rollback(nargs[1], nargs[2]);
if (ret < 0) {
cerr << "error rolling back pool " << pool_name << " to snapshot " << nargs[1]
<< strerror_r(-ret, buf, sizeof(buf)) << std::endl;
operation = OP_RAND_READ;
else
usage();
- ret = aio_bench(rados, pool, operation, seconds, concurrent_ios, op_size);
+ ret = aio_bench(rados, io_ctx, operation, seconds, concurrent_ios, op_size);
if (ret != 0)
cerr << "error during benchmark: " << ret << std::endl;
}
const char *oid = "bar";
- IoCtx pool;
- int r = rados.ioctx_open("data", pool);
- cout << "open pool result = " << r << " pool = " << pool.get_name() << std::endl;
+ IoCtx io_ctx;
+ int r = rados.ioctx_open("data", io_ctx);
+ cout << "open io_ctx result = " << r << " pool = " << io_ctx.get_pool_name() << std::endl;
ACLID id;
snprintf(id.id, ID_SIZE + 1, "%.16x", 0x1234);
cout << "id=" << id.id << std::endl;
- r = pool.exec(oid, "acl", "get", bl, bl2);
+ r = io_ctx.exec(oid, "acl", "get", bl, bl2);
cout << "exec returned " << r << " len=" << bl2.length() << std::endl;
ObjectACLs oa;
if (r >= 0) {
oa.set_acl(id, ACL_RD);
bl.clear();
oa.encode(bl);
- r = pool.exec(oid, "acl", "set", bl, bl2);
+ r = io_ctx.exec(oid, "acl", "set", bl, bl2);
const unsigned char *md5 = (const unsigned char *)bl2.c_str();
char md5_str[bl2.length()*2 + 1];
buf_to_hex(md5, bl2.length(), md5_str);
cout << "md5 result=" << md5_str << std::endl;
- int size = pool.read(oid, bl2, 128, 0);
+ int size = io_ctx.read(oid, bl2, 128, 0);
cout << "read result=" << bl2.c_str() << std::endl;
cout << "size=" << size << std::endl;
int entries;
do {
list<object_t> vec;
- r = rados.list(pool, 2, vec, ctx);
+ r = rados.list(io_ctx, 2, vec, ctx);
entries = vec.size();
cout << "list result=" << r << " entries=" << entries << std::endl;
list<object_t>::iterator iter;
} while (entries);
#endif
#if 0
- r = rados.remove(pool, oid);
+ r = rados.remove(io_ctx, oid);
cout << "remove result=" << r << std::endl;
- rados.close_pool(pool);
+ rados.close_io_ctx(io_ctx);
#endif
return 0;
<< std::endl;
}
-static int do_list(librbd::RBD &rbd, librados::IoCtx& pool)
+static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx)
{
std::vector<string> names;
- int r = rbd.list(pool, names);
+ int r = rbd.list(io_ctx, names);
if (r < 0)
return r;
return 0;
}
-static int do_create(librbd::RBD &rbd, librados::IoCtx& pool,
+static int do_create(librbd::RBD &rbd, librados::IoCtx& io_ctx,
const char *imgname, size_t size, int *order)
{
- int r = rbd.create(pool, imgname, size, order);
+ int r = rbd.create(io_ctx, imgname, size, order);
if (r < 0)
return r;
return 0;
}
-static int do_rename(librbd::RBD &rbd, librados::IoCtx& pool,
+static int do_rename(librbd::RBD &rbd, librados::IoCtx& io_ctx,
const char *imgname, const char *destname)
{
- int r = rbd.rename(pool, imgname, destname);
+ int r = rbd.rename(io_ctx, imgname, destname);
if (r < 0)
return r;
return 0;
return 0;
}
- static int do_delete(librbd::RBD &rbd, librados::IoCtx& pool, const char *imgname)
+ static int do_delete(librbd::RBD &rbd, librados::IoCtx& io_ctx, const char *imgname)
{
- int r = rbd.remove(pool, imgname);
+ int r = rbd.remove(io_ctx, imgname);
if (r < 0)
return r;
update_snap_name(*new_img, snap);
}
-static int do_import(librbd::RBD &rbd, librados::IoCtx& pool,
+static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
const char *imgname, int *order, const char *path)
{
int fd = open(path, O_RDONLY);
md_oid = imgname;
md_oid += RBD_SUFFIX;
- r = do_create(rbd, pool, imgname, size, order);
+ r = do_create(rbd, io_ctx, imgname, size, order);
if (r < 0) {
cerr << "image creation failed" << std::endl;
return r;
}
librbd::Image *image = NULL;
- r = rbd.open(pool, image, imgname);
+ r = rbd.open(io_ctx, image, imgname);
if (r < 0) {
cerr << "failed to open image" << std::endl;
return r;
{
librados::Rados rados;
librbd::RBD rbd;
- librados::IoCtx pool, dest_pool;
+ librados::IoCtx io_ctx, dest_io_ctx;
std::auto_ptr < librbd::Image > image;
vector<const char*> args;
}
// TODO: add conf
- int r = rados.ioctx_open(poolname, pool);
+ int r = rados.ioctx_open(poolname, io_ctx);
if (r < 0) {
cerr << "error opening pool " << poolname << " (err=" << r << ")" << std::endl;
exit(1);
opt_cmd == OPT_SNAP_CREATE || opt_cmd == OPT_SNAP_ROLLBACK ||
opt_cmd == OPT_SNAP_REMOVE || opt_cmd == OPT_EXPORT || opt_cmd == OPT_WATCH)) {
librbd::Image *image_ptr = NULL;
- r = rbd.open(pool, image_ptr, imgname);
+ r = rbd.open(io_ctx, image_ptr, imgname);
if (r < 0) {
cerr << "error opening image " << imgname << ": " << strerror(r) << std::endl;
exit(1);
}
if (opt_cmd == OPT_COPY || opt_cmd == OPT_IMPORT) {
- r = rados.ioctx_open(dest_poolname, dest_pool);
+ r = rados.ioctx_open(dest_poolname, dest_io_ctx);
if (r < 0) {
cerr << "error opening pool " << dest_poolname << " (err=" << r << ")" << std::endl;
exit(1);
switch (opt_cmd) {
case OPT_LIST:
- r = do_list(rbd, pool);
+ r = do_list(rbd, io_ctx);
if (r < 0) {
switch (r) {
case -ENOENT:
usage();
exit(1);
}
- r = do_create(rbd, pool, imgname, size, &order);
+ r = do_create(rbd, io_ctx, imgname, size, &order);
if (r < 0) {
cerr << "create error: " << strerror(-r) << std::endl;
exit(1);
break;
case OPT_RENAME:
- r = do_rename(rbd, pool, imgname, destname);
+ r = do_rename(rbd, io_ctx, imgname, destname);
if (r < 0) {
cerr << "rename error: " << strerror(-r) << std::endl;
exit(1);
break;
case OPT_RM:
- r = do_delete(rbd, pool, imgname);
+ r = do_delete(rbd, io_ctx, imgname);
if (r < 0) {
cerr << "delete error: " << strerror(-r) << std::endl;
exit(1);
cerr << "pathname should be specified" << std::endl;
exit(1);
}
- r = do_import(rbd, dest_pool, destname, &order, path);
+ r = do_import(rbd, dest_io_ctx, destname, &order, path);
if (r < 0) {
cerr << "import failed: " << strerror(-r) << std::endl;
exit(1);
break;
case OPT_COPY:
- r = do_copy(rbd, pool, imgname, dest_pool, destname);
+ r = do_copy(rbd, io_ctx, imgname, dest_io_ctx, destname);
if (r < 0) {
cerr << "copy failed: " << strerror(-r) << std::endl;
exit(1);
break;
case OPT_WATCH:
- r = do_watch(pool, imgname);
+ r = do_watch(io_ctx, imgname);
if (r < 0) {
cerr << "watch failed: " << strerror(-r) << std::endl;
exit(1);
#define ROOT_BUCKET ".rgw" //keep this synced to rgw_user.cc::root_bucket!
static string root_bucket(ROOT_BUCKET);
-static librados::IoCtx root_pool;
+static librados::IoCtx root_pool_ctx;
/**
* Initialize the RADOS instance and prepare to do other ops
if (ret < 0)
return ret;
- ret = open_root_pool();
+ ret = open_root_pool_ctx();
return ret;
}
* Open the pool used as root for this gateway
* Returns: 0 on success, -ERR# otherwise.
*/
-int RGWRados::open_root_pool()
+int RGWRados::open_root_pool_ctx()
{
- int r = rados->ioctx_open(root_bucket.c_str(), root_pool);
+ int r = rados->ioctx_open(root_bucket.c_str(), root_pool_ctx);
if (r == -ENOENT) {
r = rados->pool_create(root_bucket.c_str());
if (r < 0)
return r;
- r = rados->ioctx_open(root_bucket.c_str(), root_pool);
+ r = rados->ioctx_open(root_bucket.c_str(), root_pool_ctx);
}
return r;
int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix, string& delim,
string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes)
{
- librados::IoCtx pool;
- int r = rados->ioctx_open(bucket.c_str(), pool);
+ librados::IoCtx io_ctx;
+ int r = rados->ioctx_open(bucket.c_str(), io_ctx);
if (r < 0)
return r;
set<string> dir_set;
{
- librados::ObjectIterator i_end = pool.objects_end();
- for (librados::ObjectIterator i = pool.objects_begin(); i != i_end; ++i) {
+ librados::ObjectIterator i_end = io_ctx.objects_end();
+ for (librados::ObjectIterator i = io_ctx.objects_begin(); i != i_end; ++i) {
if (prefix.empty() ||
((*i).compare(0, prefix.size(), prefix) == 0)) {
dir_set.insert(*i);
}
uint64_t s;
- if (pool.stat(*p, &s, &obj.mtime) < 0)
+ if (io_ctx.stat(*p, &s, &obj.mtime) < 0)
continue;
obj.size = s;
bufferlist bl;
obj.etag[0] = '\0';
- if (pool.getxattr(*p, RGW_ATTR_ETAG, bl) >= 0) {
+ if (io_ctx.getxattr(*p, RGW_ATTR_ETAG, bl) >= 0) {
strncpy(obj.etag, bl.c_str(), sizeof(obj.etag));
obj.etag[sizeof(obj.etag)-1] = '\0';
}
/**
* create a bucket with name bucket and the given list of attrs
- * if auid is set, it sets the auid of the underlying rados pool
+ * if auid is set, it sets the auid of the underlying rados io_ctx
* returns 0 on success, -ERR# otherwise.
*/
int RGWRados::create_bucket(std::string& id, std::string& bucket, map<std::string, bufferlist>& attrs, uint64_t auid)
{
- int ret = root_pool.create(bucket, true);
+ int ret = root_pool_ctx.create(bucket, true);
if (ret < 0)
return ret;
bufferlist& bl = iter->second;
if (bl.length()) {
- ret = root_pool.setxattr(bucket, name.c_str(), bl);
+ ret = root_pool_ctx.setxattr(bucket, name.c_str(), bl);
if (ret < 0) {
delete_bucket(id, bucket);
return ret;
int RGWRados::put_obj_meta(std::string& id, std::string& bucket, std::string& oid,
time_t *mtime, map<string, bufferlist>& attrs)
{
- librados::IoCtx pool;
+ librados::IoCtx io_ctx;
- int r = rados->ioctx_open(bucket.c_str(), pool);
+ int r = rados->ioctx_open(bucket.c_str(), io_ctx);
if (r < 0)
return r;
bufferlist& bl = iter->second;
if (bl.length()) {
- r = pool.setxattr(oid, name.c_str(), bl);
+ r = io_ctx.setxattr(oid, name.c_str(), bl);
if (r < 0)
return r;
}
}
if (mtime) {
- r = pool.stat(oid, NULL, mtime);
+ r = io_ctx.stat(oid, NULL, mtime);
if (r < 0)
return r;
}
int RGWRados::put_obj_data(std::string& id, std::string& bucket, std::string& oid, const char *data, off_t ofs, size_t len,
time_t *mtime)
{
- librados::IoCtx pool;
+ librados::IoCtx io_ctx;
- int r = rados->ioctx_open(bucket.c_str(), pool);
+ int r = rados->ioctx_open(bucket.c_str(), io_ctx);
if (r < 0)
return r;
bufferlist bl;
bl.append(data, len);
- r = pool.write(oid, bl, len, ofs);
+ r = io_ctx.write(oid, bl, len, ofs);
if (r < 0)
return r;
if (mtime) {
- r = pool.stat(oid, NULL, mtime);
+ r = io_ctx.stat(oid, NULL, mtime);
if (r < 0)
return r;
}
*/
int RGWRados::delete_obj(std::string& id, std::string& bucket, std::string& oid)
{
- librados::IoCtx pool;
- int r = rados->ioctx_open(bucket.c_str(), pool);
+ librados::IoCtx io_ctx;
+ int r = rados->ioctx_open(bucket.c_str(), io_ctx);
if (r < 0)
return r;
- r = pool.remove(oid);
+ r = io_ctx.remove(oid);
if (r < 0)
return r;
int RGWRados::get_attr(std::string& bucket, std::string& obj,
const char *name, bufferlist& dest)
{
- librados::IoCtx pool;
+ librados::IoCtx io_ctx;
string actual_bucket = bucket;
string actual_obj = obj;
actual_bucket = root_bucket;
}
- int r = rados->ioctx_open(actual_bucket.c_str(), pool);
+ int r = rados->ioctx_open(actual_bucket.c_str(), io_ctx);
if (r < 0)
return r;
- r = pool.getxattr(actual_obj, name, dest);
+ r = io_ctx.getxattr(actual_obj, name, dest);
if (r < 0)
return r;
int RGWRados::set_attr(std::string& bucket, std::string& oid,
const char *name, bufferlist& bl)
{
- librados::IoCtx pool;
+ librados::IoCtx io_ctx;
string actual_bucket = bucket;
string actual_obj = oid;
actual_bucket = root_bucket;
}
- int r = rados->ioctx_open(actual_bucket.c_str(), pool);
+ int r = rados->ioctx_open(actual_bucket.c_str(), io_ctx);
if (r < 0)
return r;
- r = pool.setxattr(actual_obj, name, bl);
+ r = io_ctx.setxattr(actual_obj, name, bl);
if (r < 0)
return r;
*handle = state;
- r = rados->ioctx_open(bucket.c_str(), state->pool);
+ r = rados->ioctx_open(bucket.c_str(), state->io_ctx);
if (r < 0)
goto done_err;
- r = state->pool.stat(oid, &size, &mtime);
+ r = state->io_ctx.stat(oid, &size, &mtime);
if (r < 0)
goto done_err;
if (attrs) {
- r = state->pool.getxattrs(oid, *attrs);
+ r = state->io_ctx.getxattrs(oid, *attrs);
if (rgw_log_level >= 20) {
for (iter = attrs->begin(); iter != attrs->end(); ++iter) {
RGW_LOG(20) << "Read xattr: " << iter->first << endl;
len = RGW_MAX_CHUNK_SIZE;
RGW_LOG(20) << "rados->read ofs=" << ofs << " len=" << len << endl;
- int r = state->pool.read(oid, bl, len, ofs);
+ int r = state->io_ctx.read(oid, bl, len, ofs);
RGW_LOG(20) << "rados->read r=" << r << endl;
if (r > 0) {
class RGWRados : public RGWAccess
{
/** Open the pool used as root for this gateway */
- int open_root_pool();
+ int open_root_pool_ctx();
struct GetObjState {
- librados::IoCtx pool;
+ librados::IoCtx io_ctx;
bool sent_data;
GetObjState() : sent_data(false) {}
set<string> oid_not_in_use;
int current_snap;
string pool_name;
- librados::pool_t pool;
+ librados::IoCtx io_ctx;
librados::Rados rados;
int next_oid;
string prefix;
errors(0),
max_in_flight(max_in_flight)
{
- rados.initialize(0, 0);
- rados.open_pool(pool_name.c_str(), &pool);
+ rados.init(NULL);
+ rados.connect();
+ rados.ioctx_open(pool_name.c_str(), io_ctx);
char hostname_cstr[100];
gethostname(hostname_cstr, 100);
stringstream hostpid;
write_buffer.append(to_write.str());
context.state_lock.Unlock();
- context.rados.aio_write(context.pool,
- context.prefix+oid,
- 0,
- write_buffer,
- to_write.str().length(),
- completion);
+ context.io_ctx.aio_write(context.prefix+oid, completion,
+ write_buffer, to_write.str().length(), 0);
}
void finalize()
context.find_object(oid, old_value);
context.state_lock.Unlock();
- context.rados.aio_read(context.pool,
- context.prefix+oid,
- 0,
- &result,
- old_value.length(),
- completion);
+ context.io_ctx.aio_read(context.prefix+oid, completion,
+ &result, old_value.length(), 0);
}
void finalize()
stringstream snap_name;
snap_name << context.prefix << context.current_snap - 1;
- context.rados.snap_create(context.pool,
- snap_name.str().c_str());
+ context.io_ctx.snap_create(snap_name.str().c_str());
}
};
stringstream snap_name;
snap_name << context.prefix << to_remove;
- context.rados.snap_remove(context.pool,
- snap_name.str().c_str());
+ context.io_ctx.snap_remove(snap_name.str().c_str());
}
};
stringstream snap_name;
snap_name << context.prefix << roll_back_to;
- context.rados.snap_rollback_object(context.pool,
- context.prefix+oid,
- snap_name.str().c_str());
+ context.io_ctx.rollback(context.prefix+oid, snap_name.str().c_str());
}
};
#define TEST_IO_SIZE 513
#define MB_BYTES(mb) (mb << 20)
-void test_create_and_stat(rados_ioctx_t io, const char *name, size_t size)
+void test_create_and_stat(rados_ioctx_t io_ctx, const char *name, size_t size)
{
rbd_image_info_t info;
rbd_image_t image;
int order = 0;
- assert(rbd_create(pool, name, size, &order) == 0);
- assert(rbd_open(pool, name, &image, NULL) == 0);
+ assert(rbd_create(io_ctx, name, size, &order) == 0);
+ assert(rbd_open(io_ctx, name, &image, NULL) == 0);
assert(rbd_stat(image, &info, sizeof(info)) == 0);
printf("image has size %llu and order %d\n", (unsigned long long) info.size, info.order);
assert(info.size == size);
assert(info.size == size);
}
-void test_ls(rados_ioctx_t io, size_t num_expected, ...)
+void test_ls(rados_ioctx_t io_ctx, size_t num_expected, ...)
{
int num_images, i, j;
char *expected, *names, *cur_name;
size_t max_size = 1024;
names = (char *) malloc(sizeof(char *) * 1024);
printf("names is %p\n", names);
- num_images = rbd_list(pool, names, &max_size);
+ num_images = rbd_list(io_ctx, names, &max_size);
printf("names is %p\n", names);
printf("num images is: %d\nexpected: %d\n", num_images, (int)num_expected);
assert(num_images >= 0);
free(names);
}
-void test_delete(rados_ioctx_t io, const char *name)
+void test_delete(rados_ioctx_t io_ctx, const char *name)
{
- assert(rbd_remove(pool, name) == 0);
+ assert(rbd_remove(io_ctx, name) == 0);
}
void test_create_snap(rbd_image_t image, const char *name)
int main(int argc, const char **argv)
{
rados_t cluster;
- rados_ioctx_t io;
+ rados_ioctx_t io_ctx;
rbd_image_t image;
assert(rados_create(&cluster, NULL) == 0);
assert(rados_conf_read_file(cluster, "/etc/ceph/ceph.conf") == 0);
rados_reopen_log(cluster);
- assert(rados_ioctx_open(cluster, TEST_POOL, &pool) == 0);
+ assert(rados_ioctx_open(cluster, TEST_POOL, &io_ctx) == 0);
assert(rados_connect(cluster) == 0);
- test_ls(pool, 0);
- test_create_and_stat(pool, TEST_IMAGE, MB_BYTES(1));
- assert(rbd_open(pool, TEST_IMAGE, &image, NULL) == 0);
- test_ls(pool, 1, TEST_IMAGE);
+ test_ls(io_ctx, 0);
+ test_create_and_stat(io_ctx, TEST_IMAGE, MB_BYTES(1));
+ assert(rbd_open(io_ctx, TEST_IMAGE, &image, NULL) == 0);
+ test_ls(io_ctx, 1, TEST_IMAGE);
test_ls_snaps(image, 0);
test_create_snap(image, TEST_SNAP);
test_ls_snaps(image, 1, TEST_SNAP, MB_BYTES(1));
test_resize_and_stat(image, MB_BYTES(2));
- test_io(pool, image);
+ test_io(io_ctx, image);
test_create_snap(image, TEST_SNAP "1");
test_ls_snaps(image, 2, TEST_SNAP, MB_BYTES(1), TEST_SNAP "1", MB_BYTES(2));
test_delete_snap(image, TEST_SNAP);
test_delete_snap(image, TEST_SNAP "1");
test_ls_snaps(image, 0);
assert(rbd_close(image) == 0);
- test_create_and_stat(pool, TEST_IMAGE "1", MB_BYTES(2));
- test_ls(pool, 2, TEST_IMAGE, TEST_IMAGE "1");
- test_delete(pool, TEST_IMAGE);
- test_ls(pool, 1, TEST_IMAGE "1");
- test_delete(pool, TEST_IMAGE "1");
- test_ls(pool, 0);
- rados_ioctx_close(pool);
+ test_create_and_stat(io_ctx, TEST_IMAGE "1", MB_BYTES(2));
+ test_ls(io_ctx, 2, TEST_IMAGE, TEST_IMAGE "1");
+ test_delete(io_ctx, TEST_IMAGE);
+ test_ls(io_ctx, 1, TEST_IMAGE "1");
+ test_delete(io_ctx, TEST_IMAGE "1");
+ test_ls(io_ctx, 0);
+ rados_ioctx_close(io_ctx);
rados_shutdown(cluster);
return 0;
}
librbd::RBD *rbd;
-void test_create_and_stat(librados::PoolHandle& pool, const char *name, size_t size)
+void test_create_and_stat(librados::IoCtx& io_ctx, const char *name, size_t size)
{
librbd::image_info_t info;
librbd::Image *image = NULL;
int order = 0;
- assert(rbd->create(pool, name, size, &order) == 0);
- assert(rbd->open(pool, image, name, NULL) == 0);
+ assert(rbd->create(io_ctx, name, size, &order) == 0);
+ assert(rbd->open(io_ctx, image, name, NULL) == 0);
assert(image->stat(info, sizeof(info)) == 0);
cout << "image has size " << info.size << " and order " << info.order << endl;
assert(info.size == size);
assert(info.size == size);
}
-void test_ls(librados::PoolHandle& pool, size_t num_expected, ...)
+void test_ls(librados::IoCtx& io_ctx, size_t num_expected, ...)
{
int r;
size_t i;
char *expected;
va_list ap;
vector<string> names;
- r = rbd->list(pool, names);
+ r = rbd->list(io_ctx, names);
if (r == -ENOENT)
r = 0;
assert(r >= 0);
assert(names.empty());
}
-void test_delete(librados::PoolHandle& pool, const char *name)
+void test_delete(librados::IoCtx& io_ctx, const char *name)
{
- assert(rbd->remove(pool, name) == 0);
+ assert(rbd->remove(io_ctx, name) == 0);
}
void test_create_snap(librbd::Image *image, const char *name)
assert(strncmp(bl.c_str(), expected, expected_len) == 0);
}
-void test_io(librados::PoolHandle& pool, librbd::Image *image)
+void test_io(librados::IoCtx& io_ctx, librbd::Image *image)
{
char test_data[TEST_IO_SIZE];
int i;
int main(int argc, const char **argv)
{
librados::Rados rados;
- librados::PoolHandle pool;
+ librados::IoCtx io_ctx;
std::auto_ptr< librbd::Image > image;
rbd = new librbd::RBD();
assert(rados.init(NULL) == 0);
assert(rados.connect() == 0);
- assert(rados.pool_open(TEST_POOL, pool) == 0);
- test_ls(pool, 0);
- test_create_and_stat(pool, TEST_IMAGE, MB_BYTES(1));
- assert(rbd->open(pool, image.get(), TEST_IMAGE, NULL) == 0);
- test_ls(pool, 1, TEST_IMAGE);
+ assert(rados.ioctx_open(TEST_POOL, io_ctx) == 0);
+ test_ls(io_ctx, 0);
+ test_create_and_stat(io_ctx, TEST_IMAGE, MB_BYTES(1));
+ assert(rbd->open(io_ctx, image.get(), TEST_IMAGE, NULL) == 0);
+ test_ls(io_ctx, 1, TEST_IMAGE);
test_ls_snaps(image.get(), 0);
test_create_snap(image.get(), TEST_SNAP);
test_ls_snaps(image.get(), 1, TEST_SNAP, MB_BYTES(1));
test_resize_and_stat(image.get(), MB_BYTES(2));
- test_io(pool, image.get());
+ test_io(io_ctx, image.get());
test_create_snap(image.get(), TEST_SNAP "1");
test_ls_snaps(image.get(), 2, TEST_SNAP, MB_BYTES(1), TEST_SNAP "1", MB_BYTES(2));
test_delete_snap(image.get(), TEST_SNAP);
test_ls_snaps(image.get(), 1, TEST_SNAP "1", MB_BYTES(2));
test_delete_snap(image.get(), TEST_SNAP "1");
test_ls_snaps(image.get(), 0);
- test_create_and_stat(pool, TEST_IMAGE "1", MB_BYTES(2));
- test_ls(pool, 2, TEST_IMAGE, TEST_IMAGE "1");
- test_delete(pool, TEST_IMAGE);
- test_ls(pool, 1, TEST_IMAGE "1");
- test_delete(pool, TEST_IMAGE "1");
- test_ls(pool, 0);
+ test_create_and_stat(io_ctx, TEST_IMAGE "1", MB_BYTES(2));
+ test_ls(io_ctx, 2, TEST_IMAGE, TEST_IMAGE "1");
+ test_delete(io_ctx, TEST_IMAGE);
+ test_ls(io_ctx, 1, TEST_IMAGE "1");
+ test_delete(io_ctx, TEST_IMAGE "1");
+ test_ls(io_ctx, 0);
delete rbd;
rados.shutdown();
return 0;
exit(1);
}
- /* create a pool */
- r = rados_ioctx_create(cl, "foo");
+ /* create an io_ctx */
+ r = rados_pool_create(cl, "foo");
printf("rados_ioctx_create = %d\n", r);
- rados_ioctx_t io;
- r = rados_ioctx_open(cl, "foo", &pool);
- printf("rados_ioctx_open = %d, pool = %p\n", r, pool);
+ rados_ioctx_t io_ctx;
+ r = rados_ioctx_open(cl, "foo", &io_ctx);
+ printf("rados_ioctx_open = %d, io_ctx = %p\n", r, io_ctx);
/* list all pools */
{
- int buf_sz = rados_ioctx_list(cl, NULL, 0);
+ int buf_sz = rados_pool_list(cl, NULL, 0);
printf("need buffer size of %d\n", buf_sz);
char buf[buf_sz];
- int r = rados_ioctx_list(cl, buf, buf_sz);
+ int r = rados_pool_list(cl, buf, buf_sz);
if (r != buf_sz) {
printf("buffer size mismatch: got %d the first time, but %d "
"the second.\n", buf_sz, r);
/* stat */
struct rados_ioctx_stat_t st;
- r = rados_ioctx_stat(pool, &st);
+ r = rados_ioctx_stat(io_ctx, &st);
printf("rados_ioctx_stat = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects);
/* snapshots */
- r = rados_ioctx_snap_create(pool, "snap1");
+ r = rados_ioctx_snap_create(io_ctx, "snap1");
printf("rados_ioctx_snap_create snap1 = %d\n", r);
rados_snap_t snaps[10];
- r = rados_ioctx_snap_list(pool, snaps, 10);
+ r = rados_ioctx_snap_list(io_ctx, snaps, 10);
for (i=0; i<r; i++) {
char name[100];
- rados_ioctx_snap_get_name(pool, snaps[i], name, sizeof(name));
+ rados_ioctx_snap_get_name(io_ctx, snaps[i], name, sizeof(name));
printf("rados_ioctx_snap_list got snap %lld %s\n", (long long)snaps[i], name);
}
rados_snap_t snapid;
- r = rados_ioctx_snap_lookup(pool, "snap1", &snapid);
+ r = rados_ioctx_snap_lookup(io_ctx, "snap1", &snapid);
printf("rados_ioctx_snap_lookup snap1 got %lld, result %d\n", (long long)snapid, r);
- r = rados_ioctx_snap_remove(pool, "snap1");
+ r = rados_ioctx_snap_remove(io_ctx, "snap1");
printf("rados_ioctx_snap_remove snap1 = %d\n", r);
/* sync io */
time(&tm);
snprintf(buf, 128, "%s", ctime(&tm));
const char *oid = "foo_object";
- r = rados_write(pool, oid, buf, strlen(buf) + 1, 0);
+ r = rados_write(io_ctx, oid, buf, strlen(buf) + 1, 0);
printf("rados_write = %d\n", r);
- r = rados_read(pool, oid, buf2, sizeof(buf2), 0);
+ r = rados_read(io_ctx, oid, buf2, sizeof(buf2), 0);
printf("rados_read = %d\n", r);
if (memcmp(buf, buf2, r))
printf("*** content mismatch ***\n");
/* attrs */
- r = rados_setxattr(pool, oid, "attr1", "bar", 3);
+ r = rados_setxattr(io_ctx, oid, "attr1", "bar", 3);
printf("rados_setxattr attr1=bar = %d\n", r);
char val[10];
- r = rados_getxattr(pool, oid, "attr1", val, sizeof(val));
+ r = rados_getxattr(io_ctx, oid, "attr1", val, sizeof(val));
printf("rados_getxattr attr1 = %d\n", r);
if (memcmp(val, "bar", 3))
printf("*** attr value mismatch ***\n");
uint64_t size;
time_t mtime;
- r = rados_stat(pool, oid, &size, &mtime);
+ r = rados_stat(io_ctx, oid, &size, &mtime);
printf("rados_stat size = %lld mtime = %d = %d\n", (long long)size, (int)mtime, r);
/* tmap */
/* exec */
- rados_exec(pool, oid, "crypto", "md5", buf, strlen(buf) + 1, buf, 128);
+ rados_exec(io_ctx, oid, "crypto", "md5", buf, strlen(buf) + 1, buf, 128);
printf("exec result=%s\n", buf);
- r = rados_read(pool, oid, buf2, 128, 0);
+ r = rados_read(io_ctx, oid, buf2, 128, 0);
printf("read result=%s\n", buf2);
printf("size=%d\n", r);
rados_completion_t a, b;
rados_aio_create_completion(0, 0, 0, &a);
rados_aio_create_completion(0, 0, 0, &b);
- rados_aio_write(pool, "a", a, buf, 100, 0);
- rados_aio_write(pool, "../b/bb_bb_bb\\foo\\bar", b, buf, 100, 0);
+ rados_aio_write(io_ctx, "a", a, buf, 100, 0);
+ rados_aio_write(io_ctx, "../b/bb_bb_bb\\foo\\bar", b, buf, 100, 0);
rados_aio_wait_for_safe(a);
printf("a safe\n");
rados_aio_wait_for_safe(b);
rados_aio_release(a);
rados_aio_release(b);
- rados_read(pool, "../b/bb_bb_bb\\foo\\bar", buf2, 128, 0);
+ rados_read(io_ctx, "../b/bb_bb_bb\\foo\\bar", buf2, 128, 0);
/* list objects */
rados_list_ctx_t h;
- r = rados_objects_list_open(pool, &h);
+ r = rados_objects_list_open(io_ctx, &h);
printf("rados_list_objects_open = %d, h = %p\n", r, h);
const char *poolname;
while (rados_objects_list_next(h, &poolname) == 0)
rados_objects_list_close(h);
/* stat */
- r = rados_ioctx_stat(pool, &st);
+ r = rados_ioctx_stat(io_ctx, &st);
printf("rados_stat_pool = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects);
/* delete a pool */
- r = rados_ioctx_pool_delete(pool);
printf("rados_delete_pool = %d\n", r);
- r = rados_ioctx_close(pool);
+ rados_ioctx_close(io_ctx);
+
+ r = rados_pool_delete(cl, "foo");
+ printf("rados_ioctx_pool_delete = %d\n", r);
rados_shutdown(cl);
const char *oid = "bar";
- IoCtx pool;
- int r = rados.ioctx_open("data", pool);
- cout << "pool_open result = " << r << std::endl;
+ IoCtx io_ctx;
+ int r = rados.ioctx_open("data", io_ctx);
+ cout << "ioctx_open result = " << r << std::endl;
- r = pool.write(oid, bl, bl.length(), 0);
- uint64_t objver = pool.get_last_version();
- cout << "pool.write returned " << r << " last_ver=" << objver << std::endl;
+ r = io_ctx.write(oid, bl, bl.length(), 0);
+ uint64_t objver = io_ctx.get_last_version();
+ cout << "io_ctx.write returned " << r << " last_ver=" << objver << std::endl;
uint64_t handle;
C_Watch wc;
- r = pool.watch(oid, objver, &handle, &wc);
- cout << "pool.watch returned " << r << std::endl;
+ r = io_ctx.watch(oid, objver, &handle, &wc);
+ cout << "io_ctx.watch returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
getchar();
- pool.set_notify_timeout(7);
- r = pool.notify(oid, objver);
- cout << "pool.notify returned " << r << std::endl;
+ io_ctx.set_notify_timeout(7);
+ r = io_ctx.notify(oid, objver);
+ cout << "io_ctx.notify returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
getchar();
- r = pool.notify(oid, objver);
- cout << "pool.notify returned " << r << std::endl;
+ r = io_ctx.notify(oid, objver);
+ cout << "io_ctx.notify returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
getchar();
- r = pool.unwatch(oid, handle);
- cout << "pool.unwatch returned " << r << std::endl;
+ r = io_ctx.unwatch(oid, handle);
+ cout << "io_ctx.unwatch returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
getchar();
- r = pool.notify(oid, objver);
- cout << "pool.notify returned " << r << std::endl;
+ r = io_ctx.notify(oid, objver);
+ cout << "io_ctx.notify returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
getchar();
- pool.set_assert_version(objver);
+ io_ctx.set_assert_version(objver);
- r = pool.write(oid, bl, bl.length() - 1, 0);
- cout << "pool.write returned " << r << std::endl;
+ r = io_ctx.write(oid, bl, bl.length() - 1, 0);
+ cout << "io_ctx.write returned " << r << std::endl;
exit(0);
- r = pool.write(oid, bl, bl.length() - 2, 0);
- cout << "pool.write returned " << r << std::endl;
- r = pool.write(oid, bl, bl.length() - 3, 0);
+ r = io_ctx.write(oid, bl, bl.length() - 2, 0);
+ cout << "io_ctx.write returned " << r << std::endl;
+ r = io_ctx.write(oid, bl, bl.length() - 3, 0);
cout << "rados.write returned " << r << std::endl;
- r = pool.write_full(oid, blf);
+ r = io_ctx.write_full(oid, blf);
cout << "rados.write_full returned " << r << std::endl;
- r = pool.read(oid, bl, bl.length(), 0);
+ r = io_ctx.read(oid, bl, bl.length(), 0);
cout << "rados.read returned " << r << std::endl;
- r = pool.trunc(oid, 8);
+ r = io_ctx.trunc(oid, 8);
cout << "rados.trunc returned " << r << std::endl;
- r = pool.read(oid, bl, bl.length(), 0);
+ r = io_ctx.read(oid, bl, bl.length(), 0);
cout << "rados.read returned " << r << std::endl;
- r = pool.exec(oid, "crypto", "md5", bl, bl2);
+ r = io_ctx.exec(oid, "crypto", "md5", bl, bl2);
cout << "exec returned " << r << " buf size=" << bl2.length() << std::endl;
const unsigned char *md5 = (const unsigned char *)bl2.c_str();
char md5_str[bl2.length()*2 + 1];
buf_to_hex(md5, bl2.length(), md5_str);
cout << "md5 result=" << md5_str << std::endl;
- r = pool.exec(oid, "crypto", "sha1", bl, bl2);
+ r = io_ctx.exec(oid, "crypto", "sha1", bl, bl2);
cout << "exec returned " << r << std::endl;
const unsigned char *sha1 = (const unsigned char *)bl2.c_str();
char sha1_str[bl2.length()*2 + 1];
buf_to_hex(sha1, bl2.length(), sha1_str);
cout << "sha1 result=" << sha1_str << std::endl;
- r = pool.exec(oid, "acl", "set", bl, bl2);
- r = pool.exec(oid, "acl", "get", bl, bl2);
+ r = io_ctx.exec(oid, "acl", "set", bl, bl2);
+ r = io_ctx.exec(oid, "acl", "get", bl, bl2);
cout << "exec returned " << r << std::endl;
if (bl2.length() > 0) {
cout << "attr=" << bl2.c_str() << std::endl;
}
- int size = pool.read(oid, bl2, 128, 0);
+ int size = io_ctx.read(oid, bl2, 128, 0);
cout << "read result=" << bl2.c_str() << std::endl;
cout << "size=" << size << std::endl;
const char *oid2 = "jjj10.rbd";
- r = pool.exec(oid2, "rbd", "snap_list", bl, bl2);
+ r = io_ctx.exec(oid2, "rbd", "snap_list", bl, bl2);
cout << "snap_list result=" << r << std::endl;
- r = pool.exec(oid2, "rbd", "snap_add", bl, bl2);
+ r = io_ctx.exec(oid2, "rbd", "snap_add", bl, bl2);
cout << "snap_add result=" << r << std::endl;
if (r > 0) {
cout << s << std::endl;
}
- for (ObjectIterator iter = pool.objects_begin();
- iter != pool.objects_end(); iter++) {
+ for (ObjectIterator iter = io_ctx.objects_begin();
+ iter != io_ctx.objects_end(); iter++) {
cout << *iter << std::endl;
}
map<string, bufferlist> attrset;
- pool.getxattrs(oid, attrset);
+ io_ctx.getxattrs(oid, attrset);
map<string, bufferlist>::iterator it;
for (it = attrset.begin(); it != attrset.end(); ++it) {
}
#if 0
- r = pool.remove(oid);
+ r = io_ctx.remove(oid);
cout << "remove result=" << r << std::endl;
#endif
rados.shutdown();