From: Zhiqiang Wang Date: Wed, 11 Mar 2015 01:15:53 +0000 (+0800) Subject: rados: add the support of pin/unpin object in cache tier X-Git-Tag: v10.0.0~62^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=28b7205216246108aa602e107a99ff9ddbcb0ca5;p=ceph.git rados: add the support of pin/unpin object in cache tier Adding two new APIs in librados: cache_pin_object and cache_unpin_object Signed-off-by: Zhiqiang Wang --- diff --git a/src/include/rados.h b/src/include/rados.h index 59d3225a7872..dde4d9e81814 100644 --- a/src/include/rados.h +++ b/src/include/rados.h @@ -250,6 +250,10 @@ extern const char *ceph_osd_state_name(int s); \ /* hints */ \ f(SETALLOCHINT, __CEPH_OSD_OP(WR, DATA, 35), "set-alloc-hint") \ + \ + /* cache pin/unpin */ \ + f(CACHE_PIN, __CEPH_OSD_OP(WR, DATA, 36), "cache-pin") \ + f(CACHE_UNPIN, __CEPH_OSD_OP(WR, DATA, 37), "cache-unpin") \ \ /** multi **/ \ f(CLONERANGE, __CEPH_OSD_OP(WR, MULTI, 1), "clonerange") \ diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index b92a94f17345..52ce642934c8 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -442,6 +442,14 @@ namespace librados void set_alloc_hint(uint64_t expected_object_size, uint64_t expected_write_size); + /** + * Pin/unpin an object in cache tier + * + * @returns 0 on success, negative error code on failure + */ + void cache_pin(); + void cache_unpin(); + friend class IoCtx; }; @@ -1034,6 +1042,15 @@ namespace librados void set_assert_version(uint64_t ver); void set_assert_src_version(const std::string& o, uint64_t ver); + /** + * Pin/unpin an object in cache tier + * + * @param o the name of the object + * @returns 0 on success, negative error code on failure + */ + int cache_pin(const std::string& o); + int cache_unpin(const std::string& o); + const std::string& get_pool_name() const; void locator_set_key(const std::string& key); diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index 945dbec2126d..517eeb8200b4 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -1294,6 +1294,22 @@ void librados::IoCtxImpl::set_notify_timeout(uint32_t timeout) notify_timeout = timeout; } +int librados::IoCtxImpl::cache_pin(const object_t& oid) +{ + ::ObjectOperation wr; + prepare_assert_ops(&wr); + wr.cache_pin(); + return operate(oid, &wr, NULL); +} + +int librados::IoCtxImpl::cache_unpin(const object_t& oid) +{ + ::ObjectOperation wr; + prepare_assert_ops(&wr); + wr.cache_unpin(); + return operate(oid, &wr, NULL); +} + ///////////////////////////// C_aio_Ack //////////////////////////////// diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index df73b0326965..45bfdfdbee7b 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -216,6 +216,9 @@ struct librados::IoCtxImpl { void set_assert_src_version(const object_t& oid, uint64_t ver); void set_notify_timeout(uint32_t timeout); + int cache_pin(const object_t& oid); + int cache_unpin(const object_t& oid); + }; #endif diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 7a193a30b8b9..09775e2ec588 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -513,6 +513,18 @@ void librados::ObjectWriteOperation::set_alloc_hint( o->set_alloc_hint(expected_object_size, expected_write_size); } +void librados::ObjectWriteOperation::cache_pin() +{ + ::ObjectOperation *o = (::ObjectOperation *)impl; + o->cache_pin(); +} + +void librados::ObjectWriteOperation::cache_unpin() +{ + ::ObjectOperation *o = (::ObjectOperation *)impl; + o->cache_unpin(); +} + librados::WatchCtx:: ~WatchCtx() { @@ -1861,6 +1873,18 @@ void librados::IoCtx::set_assert_src_version(const std::string& oid, uint64_t ve io_ctx_impl->set_assert_src_version(obj, ver); } +int librados::IoCtx::cache_pin(const string& oid) +{ + object_t obj(oid); + return io_ctx_impl->cache_pin(obj); +} + +int librados::IoCtx::cache_unpin(const string& oid) +{ + object_t obj(oid); + return io_ctx_impl->cache_unpin(obj); +} + void librados::IoCtx::locator_set_key(const string& key) { io_ctx_impl->oloc.key = key; diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 379c0ae02734..be251b921b47 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1052,6 +1052,17 @@ struct ObjectOperation { out_rval[i] = &sops[i].rval; } } + + /** + * Pin/unpin an object in cache tier + */ + void cache_pin() { + add_op(CEPH_OSD_OP_CACHE_PIN); + } + + void cache_unpin() { + add_op(CEPH_OSD_OP_CACHE_UNPIN); + } };