summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/rbd/librbd.h8
-rw-r--r--src/librbd.cc32
2 files changed, 40 insertions, 0 deletions
diff --git a/src/include/rbd/librbd.h b/src/include/rbd/librbd.h
index c2ed7bfb0b2..bebe21d8fc4 100644
--- a/src/include/rbd/librbd.h
+++ b/src/include/rbd/librbd.h
@@ -40,6 +40,7 @@ extern "C" {
typedef void *rbd_snap_t;
typedef void *rbd_image_t;
+typedef void *rbd_cache_t;
typedef int (*librbd_progress_fn_t)(uint64_t offset, uint64_t total, void *ptr);
@@ -73,6 +74,8 @@ int rbd_remove_with_progress(rados_ioctx_t io, const char *name,
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_open_cached(rados_ioctx_t io, const char *name, rbd_image_t *image, const char *snap_name,
+ rbd_cache_t cache);
int rbd_close(rbd_image_t image);
int rbd_resize(rbd_image_t image, uint64_t size);
int rbd_resize_with_progress(rbd_image_t image, uint64_t size,
@@ -82,6 +85,11 @@ int rbd_copy(rbd_image_t image, rados_ioctx_t dest_io_ctx, const char *destname)
int rbd_copy_with_progress(rbd_image_t image, rados_ioctx_t dest_p, const char *destname,
librbd_progress_fn_t cb, void *cbdata);
+/* cache */
+int rbd_cache_create(rados_t cluster, rbd_cache_t *cache, uint64_t max_size,
+ uint64_t max_dirty, uint64_t target_dirty);
+int rbd_cache_destroy(rbd_cache_t cache);
+
/* snapshots */
int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps, int *max_snaps);
void rbd_snap_list_end(rbd_snap_info_t *snaps);
diff --git a/src/librbd.cc b/src/librbd.cc
index 36b93cf7df5..f89ff6ff584 100644
--- a/src/librbd.cc
+++ b/src/librbd.cc
@@ -2420,6 +2420,19 @@ extern "C" int rbd_open(rados_ioctx_t p, const char *name, rbd_image_t *image, c
return r;
}
+extern "C" int rbd_open_cached(rados_ioctx_t p, const char *name, rbd_image_t *image, const char *snap_name,
+ rbd_cache_t cache)
+{
+ librados::IoCtx io_ctx;
+ librados::IoCtx::from_rados_ioctx_t(p, io_ctx);
+ librbd::ImageCtx *ictx = new librbd::ImageCtx(name, snap_name, io_ctx, (librbd::CacheCtx *)cache);
+ if (!ictx)
+ return -ENOMEM;
+ int r = librbd::open_image(ictx);
+ *image = (rbd_image_t)ictx;
+ return r;
+}
+
extern "C" int rbd_close(rbd_image_t image)
{
librbd::ImageCtx *ctx = (librbd::ImageCtx *)image;
@@ -2448,6 +2461,25 @@ extern "C" int rbd_stat(rbd_image_t image, rbd_image_info_t *info, size_t infosi
return librbd::info(ictx, *info, infosize);
}
+/* cache */
+
+extern "C" int rbd_cache_create(rados_t cluster, rbd_cache_t *pcache,
+ uint64_t max_size, uint64_t max_dirty, uint64_t target_dirty)
+{
+ librbd::CacheCtx *cache = new librbd::CacheCtx((CephContext *)rados_cct(cluster), "rbd_cache");
+ cache->object_cacher->set_max_size(max_size);
+ cache->object_cacher->set_max_dirty(max_dirty);
+ cache->object_cacher->set_target_dirty(target_dirty);
+ *pcache = cache;
+ return 0;
+}
+
+extern "C" int rbd_cache_destroy(rbd_cache_t cache)
+{
+ delete (librbd::CacheCtx *)cache;
+ return 0;
+}
+
/* snapshots */
extern "C" int rbd_snap_create(rbd_image_t image, const char *snap_name)
{