#include "common/errno.h"
#include "common/ceph_argparse.h"
#include "common/common_init.h"
+#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "include/byteorder.h"
#include "include/fiemap.h"
+static librados::Rados rados;
static librbd::RBD rbd;
static string dir_oid = RBD_DIRECTORY;
static string dir_info_oid = RBD_INFO;
<< std::endl;
}
-static int do_list(librbd::pool_t pool)
+static int do_list(librados::pool_t pool)
{
std::vector<string> names;
int r = rbd.list(pool, names);
return 0;
}
-static int do_create(librbd::pool_t pool, const char *imgname, size_t size, int *order)
+static int do_create(librados::pool_t pool, const char *imgname, size_t size, int *order)
{
int r = rbd.create(pool, imgname, size, order);
if (r < 0)
return 0;
}
-static int do_rename(librbd::pool_t pool, const char *imgname, const char *destname)
+static int do_rename(librados::pool_t pool, const char *imgname, const char *destname)
{
int r = rbd.rename(pool, imgname, destname);
if (r < 0)
static int do_show_info(const char *imgname, librbd::image_t image)
{
librbd::image_info_t info;
- int r = rbd.stat(image, info);
+ int r = rbd.stat(image, info, sizeof(info));
if (r < 0)
return r;
return 0;
}
- static int do_delete(librbd::pool_t pool, const char *imgname)
+ static int do_delete(librados::pool_t pool, const char *imgname)
{
int r = rbd.remove(pool, imgname);
if (r < 0)
static int do_list_snaps(librbd::image_t image)
{
std::vector<librbd::snap_info_t> snaps;
- int r = rbd.list_snaps(image, snaps);
+ int r = rbd.snap_list(image, snaps);
if (r < 0)
return r;
static int do_add_snap(librbd::image_t image, const char *snapname)
{
- int r = rbd.create_snap(image, snapname);
+ int r = rbd.snap_create(image, snapname);
if (r < 0)
return r;
static int do_remove_snap(librbd::image_t image, const char *snapname)
{
- int r = rbd.remove_snap(image, snapname);
+ int r = rbd.snap_remove(image, snapname);
if (r < 0)
return r;
static int do_rollback_snap(librbd::image_t image, const char *snapname)
{
- int r = rbd.rollback_snap(image, snapname);
+ int r = rbd.snap_rollback(image, snapname);
if (r < 0)
return r;
if (fd < 0)
return -errno;
- r = rbd.stat(image, info);
+ r = rbd.stat(image, info, sizeof(info));
if (r < 0)
return r;
return r;
}
librbd::image_t image;
- r = rbd.open_image(pool, imgname, &image, NULL);
+ r = rbd.open(pool, imgname, &image, NULL);
if (r < 0) {
cerr << "failed to open image" << std::endl;
return r;
return r;
}
-static int do_copy(librbd::pool_t& pp, const char *imgname, librbd::pool_t& dest_pp, const char *destname)
+static int do_copy(librados::pool_t& pp, const char *imgname, librados::pool_t& dest_pp, const char *destname)
{
int r = rbd.copy(pp, imgname, dest_pp, destname);
if (r < 0)
}
};
-static int do_watch(librbd::pool_t& pp, const char *imgname)
+static int do_watch(librados::pool_t& pp, const char *imgname)
{
string md_oid, dest_md_oid;
uint64_t cookie;
RbdWatchCtx ctx(imgname);
- librados::pool_t md_pool;
-
- rbd.get_rados_pools(pp, &md_pool, NULL);
md_oid = imgname;
md_oid += RBD_SUFFIX;
- librados::Rados& rados = rbd.get_rados();
- int r = rados.watch(md_pool, md_oid, 0, &cookie, &ctx);
+ int r = rados.watch(pp, md_oid, 0, &cookie, &ctx);
if (r < 0) {
cerr << "watch failed" << std::endl;
- rados.shutdown();
return r;
}
return 0;
}
-static void err_exit(librbd::pool_t pool, librbd::image_t image = NULL)
+static void err_exit(librados::pool_t pool, librbd::image_t image = NULL)
{
if (image)
- rbd.close_image(image);
- rbd.close_pool(pool);
- rbd.shutdown();
+ rbd.close(image);
+ rados.pool_close(pool);
+ rados.release();
exit(1);
}
{
vector<const char*> args;
DEFINE_CONF_VARS(usage_exit);
+ // TODO: use rados conf api
argv_to_vec(argc, argv, args);
env_to_vec(args);
if (!dest_poolname)
dest_poolname = poolname;
- librbd::pool_t pool, dest_pool;
+ librados::pool_t pool, dest_pool;
librbd::image_t image = NULL;
if (opt_cmd == OPT_EXPORT && !path)
usage_exit();
}
- if (rbd.initialize(argc, argv) < 0) {
- cerr << "error: couldn't initialize rbd!" << std::endl;
+ if (rados.init() < 0) {
+ cerr << "error: couldn't initialize rados!" << std::endl;
exit(1);
}
- int r = rbd.open_pool(poolname, &pool);
+ // TODO: add argc/argv conf
+
+ int r = rados.pool_open(poolname, &pool);
if (r < 0) {
cerr << "error opening pool " << poolname << " (err=" << r << ")" << std::endl;
err_exit(pool);
(opt_cmd == OPT_RESIZE || opt_cmd == OPT_INFO || opt_cmd == OPT_SNAP_LIST ||
opt_cmd == OPT_SNAP_CREATE || opt_cmd == OPT_SNAP_ROLLBACK ||
opt_cmd == OPT_SNAP_REMOVE || opt_cmd == OPT_EXPORT || opt_cmd == OPT_WATCH)) {
- r = rbd.open_image(pool, imgname, &image, NULL);
+ r = rbd.open(pool, imgname, &image, NULL);
if (r < 0) {
cerr << "error opening image " << imgname << " (err=" << r << ")" << std::endl;
err_exit(pool);
}
if (snapname) {
- r = rbd.set_snap(image, snapname);
+ r = rbd.snap_set(image, snapname);
if (r < 0 && !(r == -ENOENT && opt_cmd == OPT_SNAP_CREATE)) {
cerr << "error setting snapshot context: " << strerror(-r) << std::endl;
err_exit(pool, image);
}
if (opt_cmd == OPT_COPY || opt_cmd == OPT_IMPORT) {
- r = rbd.open_pool(dest_poolname, &dest_pool);
+ r = rados.pool_open(dest_poolname, &dest_pool);
if (r < 0) {
cerr << "error opening pool " << dest_poolname << " (err=" << r << ")" << std::endl;
err_exit(pool);
}
if (image)
- rbd.close_image(image);
+ rbd.close(image);
- rbd.close_pool(pool);
- rbd.shutdown();
+ rados.pool_close(pool);
+ rados.release();
return 0;
}