summaryrefslogtreecommitdiff
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
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>
-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)
{