From: Colin Patrick McCabe Date: Sat, 26 Feb 2011 00:38:33 +0000 (-0800) Subject: Rename PoolHandle to IoContext: part 2 X-Git-Tag: v0.25~45^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=141509c059acfb6a07faeb9192c72ff6ddf80213;p=ceph.git Rename PoolHandle to IoContext: part 2 The previous change changed all PoolHandle uses to IoContext. This change also renames the variable names. Also fix a few API functions whose names weren't quite right after the previous change. rados_pool_list really does just list pools-- it has nothing to do with ioctxes. rados_ioctx_change_auid should be rados_ioctx_pool_set_auid. Although it takes an ioctx as an argument, it operates on the pool. rados_ioctx_close should just return void. APIs where the close operation can fail are broken. What is the user supposed to do if closing doesn't work? Also, fix a few test programs that got overlooked earlier. Signed-off-by: Colin McCabe --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index aa8072ebe41a..297cf36ef0a5 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -98,7 +98,7 @@ int rados_conf_get(rados_t cluster, const char *option, char *buf, int len); 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); @@ -110,7 +110,6 @@ int rados_pool_create_with_crush_rule(rados_t cluster, const char *pool_name, 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 */ diff --git a/src/include/rbd/librbd.h b/src/include/rbd/librbd.h index f0b73139b5fb..220664819740 100644 --- a/src/include/rbd/librbd.h +++ b/src/include/rbd/librbd.h @@ -62,8 +62,8 @@ void rbd_version(int *major, int *minor, int *extra); 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); diff --git a/src/include/rbd/librbd.hpp b/src/include/rbd/librbd.hpp index a575f6a6e4f7..ce73a4dc9e2a 100644 --- a/src/include/rbd/librbd.hpp +++ b/src/include/rbd/librbd.hpp @@ -57,13 +57,13 @@ public: 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& 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& 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 */ diff --git a/src/librados.cc b/src/librados.cc index 04e50437c458..8a9bcdfb2439 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -2548,7 +2548,7 @@ extern "C" int rados_ioctx_lookup(rados_t cluster, const char *name) 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 pools; @@ -2590,11 +2590,10 @@ extern "C" int rados_ioctx_open(rados_t cluster, const char *name, rados_ioctx_t 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) @@ -2703,14 +2702,14 @@ extern "C" uint64_t rados_get_last_version(rados_ioctx_t io) 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; @@ -2718,7 +2717,7 @@ extern "C" int rados_ioctx_create_with_auid(rados_t cluster, const char *name, 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; @@ -2726,7 +2725,7 @@ extern "C" int rados_ioctx_create_with_crush_rule(rados_t cluster, const char *n 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; @@ -2740,7 +2739,7 @@ extern "C" int rados_pool_delete(rados_t cluster, const char *pool_name) 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); diff --git a/src/librbd.cc b/src/librbd.cc index 4adaee068e60..58be33081d05 100644 --- a/src/librbd.cc +++ b/src/librbd.cc @@ -64,14 +64,14 @@ namespace librbd { std::map 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) @@ -201,36 +201,36 @@ namespace librbd { 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& 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& 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& 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); @@ -360,25 +360,25 @@ int init_rbd_info(struct rbd_info *info) 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; iheader), 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& names) +int list(IoCtx& io_ctx, std::vector& 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; @@ -539,14 +539,14 @@ int snap_create(ImageCtx *ictx, const char *snap_name) 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; } @@ -563,24 +563,24 @@ int snap_remove(ImageCtx *ictx, const char *snap_name) 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; @@ -588,7 +588,7 @@ int create(IoCtx& pool, string& md_oid, const char *imgname, 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; @@ -606,14 +606,14 @@ int create(IoCtx& pool, string& md_oid, const char *imgname, ::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; @@ -623,7 +623,7 @@ int create(IoCtx& pool, string& md_oid, const char *imgname, 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; @@ -633,35 +633,35 @@ int rename(IoCtx& pool, const char *srcname, const char *dstname) 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; } @@ -676,17 +676,17 @@ int info(ImageCtx *ictx, image_info_t& info, size_t infosize) 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; @@ -694,7 +694,7 @@ int remove(IoCtx& pool, const char *imgname) __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; @@ -724,21 +724,21 @@ int resize(ImageCtx *ictx, uint64_t size) 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; @@ -773,7 +773,7 @@ int add_snap(ImageCtx *ictx, const char *snap_name) 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; @@ -782,22 +782,22 @@ int add_snap(ImageCtx *ictx, const char *snap_name) ::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; @@ -824,10 +824,10 @@ int ictx_refresh(ImageCtx *ictx, const char *snap_name) 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; @@ -880,11 +880,11 @@ int snap_rollback(ImageCtx *ictx, const char *snap_name) 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; @@ -892,7 +892,7 @@ int snap_rollback(ImageCtx *ictx, const char *snap_name) 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; @@ -904,7 +904,7 @@ int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *des 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; @@ -912,13 +912,13 @@ int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *des 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; @@ -930,7 +930,7 @@ int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *des string dest_oid = get_block_oid(&dest_header, i); map m; map::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) @@ -946,7 +946,7 @@ int copy(IoCtx& src_pool, const char *srcname, IoCtx& dest_pool, const char *des 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; } @@ -969,16 +969,16 @@ int snap_set(ImageCtx *ictx, const char *snap_name) 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) @@ -991,7 +991,7 @@ int open_image(IoCtx& pool, ImageCtx *ictx, const char *name, const char *snap_n 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; } @@ -1001,7 +1001,7 @@ void close_image(ImageCtx *ictx) 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; @@ -1031,7 +1031,7 @@ int read_iterate(ImageCtx *ictx, off_t off, size_t len, map m; map::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) { @@ -1113,7 +1113,7 @@ int write(ImageCtx *ictx, off_t off, size_t len, const char *buf) 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) @@ -1227,7 +1227,7 @@ int aio_write(ImageCtx *ictx, off_t off, size_t len, const char *buf, 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; @@ -1275,7 +1275,7 @@ int aio_read(ImageCtx *ictx, off_t off, size_t 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) @@ -1308,18 +1308,18 @@ void RBD::version(int *major, int *minor, int *extra) 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; @@ -1327,35 +1327,35 @@ int RBD::open(IoCtx& pool, Image *image, const char *name, const char *snapname) 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& names) +int RBD::list(IoCtx& io_ctx, std::vector& 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; } @@ -1501,10 +1501,10 @@ extern "C" void rbd_version(int *major, int *minor, int *extra) /* 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 cpp_names; - int r = librbd::list(pool, cpp_names); + int r = librbd::list(io_ctx, cpp_names); if (r == -ENOENT) return 0; @@ -1530,43 +1530,43 @@ extern "C" int rbd_list(rados_ioctx_t p, char *names, size_t *size) 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; } diff --git a/src/osdc/rados_bencher.h b/src/osdc/rados_bencher.h index 0ad51d3766f7..1faa0121f707 100644 --- a/src/osdc/rados_bencher.h +++ b/src/osdc/rados_bencher.h @@ -59,15 +59,15 @@ void generate_object_name(char *s, int objnum, int pid = 0) } } -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; @@ -78,7 +78,7 @@ int aio_bench(librados::Rados& rados, librados::IoCtx &pool, int operation, //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) @@ -111,11 +111,11 @@ int aio_bench(librados::Rados& rados, librados::IoCtx &pool, int operation, 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) { @@ -136,7 +136,7 @@ void _aio_cb(void *cb, void *arg) { 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 " @@ -173,7 +173,7 @@ int write_bench(librados::Rados& rados, librados::IoCtx& pool, 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; } @@ -235,7 +235,7 @@ int write_bench(librados::Rados& rados, librados::IoCtx& pool, //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; } @@ -300,7 +300,7 @@ int write_bench(librados::Rados& rados, librados::IoCtx& pool, ::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: @@ -311,7 +311,7 @@ int write_bench(librados::Rados& rados, librados::IoCtx& pool, 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; @@ -360,7 +360,7 @@ int seq_read_bench(librados::Rados& rados, librados::IoCtx& pool, int seconds_to 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; @@ -418,7 +418,7 @@ int seq_read_bench(librados::Rados& rados, librados::IoCtx& pool, int seconds_to 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; } diff --git a/src/rados.cc b/src/rados.cc index 49f4f5981f91..3b7f9f62c704 100644 --- a/src/rados.cc +++ b/src/rados.cc @@ -149,10 +149,10 @@ int main(int argc, const char **argv) 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; @@ -162,7 +162,7 @@ int main(int argc, const char **argv) // 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; @@ -170,13 +170,13 @@ int main(int argc, const char **argv) } 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; } @@ -238,8 +238,8 @@ int main(int argc, const char **argv) 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; } @@ -252,11 +252,11 @@ int main(int argc, const char **argv) 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) { @@ -264,7 +264,7 @@ int main(int argc, const char **argv) usage(); string oid(nargs[1]); std::map 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; @@ -278,7 +278,7 @@ int main(int argc, const char **argv) 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; @@ -321,7 +321,7 @@ int main(int argc, const char **argv) 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) { @@ -343,7 +343,7 @@ int main(int argc, const char **argv) 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; @@ -357,7 +357,7 @@ int main(int argc, const char **argv) 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; @@ -371,7 +371,7 @@ int main(int argc, const char **argv) 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; @@ -383,7 +383,7 @@ int main(int argc, const char **argv) string oid(nargs[1]); map 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; @@ -398,7 +398,7 @@ int main(int argc, const char **argv) 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; @@ -408,7 +408,7 @@ int main(int argc, const char **argv) 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; @@ -420,7 +420,7 @@ int main(int argc, const char **argv) 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; @@ -478,15 +478,15 @@ int main(int argc, const char **argv) usage(); vector snaps; - pool.snap_list(&snaps); + io_ctx.snap_list(&snaps); for (vector::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); @@ -511,7 +511,7 @@ int main(int argc, const char **argv) 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; @@ -524,7 +524,7 @@ int main(int argc, const char **argv) 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; @@ -537,7 +537,7 @@ int main(int argc, const char **argv) 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; @@ -560,7 +560,7 @@ int main(int argc, const char **argv) 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; } diff --git a/src/radosacl.cc b/src/radosacl.cc index 2199af8bcfdc..be607778ddb2 100644 --- a/src/radosacl.cc +++ b/src/radosacl.cc @@ -143,16 +143,16 @@ int main(int argc, const char **argv) 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) { @@ -163,14 +163,14 @@ int main(int argc, const char **argv) 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; @@ -179,7 +179,7 @@ int main(int argc, const char **argv) int entries; do { list 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::iterator iter; @@ -189,9 +189,9 @@ int main(int argc, const char **argv) } 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; diff --git a/src/rbd.cc b/src/rbd.cc index 16734bd3fac7..839313d91310 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -99,10 +99,10 @@ static void print_info(const char *imgname, librbd::image_info_t& info) << 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 names; - int r = rbd.list(pool, names); + int r = rbd.list(io_ctx, names); if (r < 0) return r; @@ -111,19 +111,19 @@ static int do_list(librbd::RBD &rbd, librados::IoCtx& pool) 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; @@ -140,9 +140,9 @@ static int do_show_info(const char *imgname, librbd::Image *image) 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; @@ -309,7 +309,7 @@ done_img: 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); @@ -338,13 +338,13 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& pool, 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; @@ -572,7 +572,7 @@ int main(int argc, const char **argv) { 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 args; @@ -698,7 +698,7 @@ int main(int argc, const char **argv) } // 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); @@ -709,7 +709,7 @@ int main(int argc, const char **argv) 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); @@ -726,7 +726,7 @@ int main(int argc, const char **argv) } 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); @@ -735,7 +735,7 @@ int main(int argc, const char **argv) switch (opt_cmd) { case OPT_LIST: - r = do_list(rbd, pool); + r = do_list(rbd, io_ctx); if (r < 0) { switch (r) { case -ENOENT: @@ -759,7 +759,7 @@ int main(int argc, const char **argv) 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); @@ -767,7 +767,7 @@ int main(int argc, const char **argv) 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); @@ -783,7 +783,7 @@ int main(int argc, const char **argv) 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); @@ -863,7 +863,7 @@ int main(int argc, const char **argv) 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); @@ -871,7 +871,7 @@ int main(int argc, const char **argv) 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); @@ -879,7 +879,7 @@ int main(int argc, const char **argv) 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); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 4039f6b97fdc..dfa4eae25f86 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -20,7 +20,7 @@ Rados *rados = NULL; #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 @@ -41,7 +41,7 @@ int RGWRados::initialize(int argc, char *argv[]) if (ret < 0) return ret; - ret = open_root_pool(); + ret = open_root_pool_ctx(); return ret; } @@ -50,15 +50,15 @@ int RGWRados::initialize(int argc, char *argv[]) * 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; @@ -135,15 +135,15 @@ int RGWRados::list_buckets_next(std::string& id, RGWObjEnt& obj, RGWAccessHandle int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix, string& delim, string& marker, vector& result, map& 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 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); @@ -177,13 +177,13 @@ int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix, } 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'; } @@ -195,12 +195,12 @@ int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix, /** * 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& attrs, uint64_t auid) { - int ret = root_pool.create(bucket, true); + int ret = root_pool_ctx.create(bucket, true); if (ret < 0) return ret; @@ -210,7 +210,7 @@ int RGWRados::create_bucket(std::string& id, std::string& bucket, mapsecond; 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; @@ -237,9 +237,9 @@ int RGWRados::create_bucket(std::string& id, std::string& bucket, map& 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; @@ -249,14 +249,14 @@ int RGWRados::put_obj_meta(std::string& id, std::string& bucket, std::string& oi 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; } @@ -278,20 +278,20 @@ int RGWRados::put_obj_meta(std::string& id, std::string& bucket, std::string& oi 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; } @@ -387,12 +387,12 @@ int RGWRados::delete_bucket(std::string& id, std::string& bucket) */ 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; @@ -410,7 +410,7 @@ int RGWRados::delete_obj(std::string& id, std::string& bucket, std::string& oid) 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; @@ -419,11 +419,11 @@ int RGWRados::get_attr(std::string& bucket, std::string& 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; @@ -441,7 +441,7 @@ int RGWRados::get_attr(std::string& bucket, std::string& obj, 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; @@ -450,11 +450,11 @@ int RGWRados::set_attr(std::string& bucket, std::string& 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; @@ -512,16 +512,16 @@ int RGWRados::prepare_get_obj(std::string& bucket, std::string& oid, *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; @@ -609,7 +609,7 @@ int RGWRados::get_obj(void **handle, 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) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 544709b0f370..3d5ad41b0c0e 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -8,10 +8,10 @@ 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) {} diff --git a/src/test/osd/RadosModel.h b/src/test/osd/RadosModel.h index ef8e40d573b8..5381ef83186e 100644 --- a/src/test/osd/RadosModel.h +++ b/src/test/osd/RadosModel.h @@ -64,7 +64,7 @@ struct RadosTestContext set 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; @@ -79,8 +79,9 @@ struct RadosTestContext 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; @@ -224,12 +225,8 @@ struct WriteOp : public TestOp 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() @@ -270,12 +267,8 @@ struct ReadOp : public TestOp 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() @@ -317,8 +310,7 @@ struct SnapCreateOp : public TestOp 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()); } }; @@ -339,8 +331,7 @@ struct SnapRemoveOp : public TestOp 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()); } }; @@ -365,8 +356,6 @@ struct RollbackOp : public TestOp 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()); } }; diff --git a/src/testlibrbd.c b/src/testlibrbd.c index f6fd1b91203a..e37e21e5c9ba 100644 --- a/src/testlibrbd.c +++ b/src/testlibrbd.c @@ -32,13 +32,13 @@ #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); @@ -55,7 +55,7 @@ void test_resize_and_stat(rbd_image_t image, size_t 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; @@ -63,7 +63,7 @@ void test_ls(rados_ioctx_t io, size_t num_expected, ...) 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); @@ -101,9 +101,9 @@ void test_ls(rados_ioctx_t io, size_t num_expected, ...) 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) @@ -259,22 +259,22 @@ void test_io(rados_ioctx_t io, rbd_image_t image) 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); @@ -282,13 +282,13 @@ int main(int argc, const char **argv) 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; } diff --git a/src/testlibrbdpp.cc b/src/testlibrbdpp.cc index 008c477268ef..9bf7af8f4fcd 100644 --- a/src/testlibrbdpp.cc +++ b/src/testlibrbdpp.cc @@ -38,13 +38,13 @@ using namespace std; 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); @@ -61,14 +61,14 @@ void test_resize_and_stat(librbd::Image *image, size_t 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 names; - r = rbd->list(pool, names); + r = rbd->list(io_ctx, names); if (r == -ENOENT) r = 0; assert(r >= 0); @@ -91,9 +91,9 @@ void test_ls(librados::PoolHandle& pool, size_t num_expected, ...) 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) @@ -215,7 +215,7 @@ void read_test_data(librbd::Image *image, const char *expected, off_t off) 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; @@ -243,33 +243,33 @@ void test_io(librados::PoolHandle& pool, librbd::Image *image) 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; diff --git a/src/testrados.c b/src/testrados.c index 8ce637ff3eb4..ac2f18eb5444 100644 --- a/src/testrados.c +++ b/src/testrados.c @@ -67,20 +67,20 @@ int main(int argc, const char **argv) 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); @@ -100,23 +100,23 @@ int main(int argc, const char **argv) /* 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 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) { @@ -181,12 +181,12 @@ int main(int argc, const char **argv) 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 attrset; - pool.getxattrs(oid, attrset); + io_ctx.getxattrs(oid, attrset); map::iterator it; for (it = attrset.begin(); it != attrset.end(); ++it) { @@ -194,7 +194,7 @@ int main(int argc, const char **argv) } #if 0 - r = pool.remove(oid); + r = io_ctx.remove(oid); cout << "remove result=" << r << std::endl; #endif rados.shutdown();