summaryrefslogtreecommitdiff
path: root/src/librbd.cc
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2012-05-05 16:39:21 -0700
committerSage Weil <sage@inktank.com>2012-05-05 20:32:31 -0700
commit9af4d7c6f4610eb1cb8930d1ce277d5c5c99f9ac (patch)
treec781a0d133c43a2bdeee3aceb5f59e2b6fabdb98 /src/librbd.cc
parent714af66f2af33047bfb2893ae631ee22828394bb (diff)
downloadceph-historic/rbd-multi-cache.tar.gz
librbd: add explicit management of cacheshistoric/rbd-multi-cache
Allow librbd users to create in-memory cache pools, and open images using those caches. This lets you control the total amount of memory consumed for some number of open images. It also lets you individually control the writeback behavior for individual images (e.g., have some write-thru, some write-back). This doesn't let you specify max_dirty limits on a per-image basis, tho, unless you give that image its own cache. Note that doing rbd_open on an image when 'rbd cache' is true is equivalent to creating a separate cache for that image using the 'rbd cache *' tunables. This API is meant to be used in leiu of the 'rbd cache*' options. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'src/librbd.cc')
-rw-r--r--src/librbd.cc32
1 files changed, 32 insertions, 0 deletions
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)
{