]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: add the support of pin/unpin object in cache tier
authorZhiqiang Wang <zhiqiang.wang@intel.com>
Wed, 11 Mar 2015 01:15:53 +0000 (09:15 +0800)
committerSage Weil <sage@redhat.com>
Tue, 20 Oct 2015 14:34:49 +0000 (10:34 -0400)
Adding two new APIs in librados: cache_pin_object and cache_unpin_object

Signed-off-by: Zhiqiang Wang <zhiqiang.wang@intel.com>
src/include/rados.h
src/include/rados/librados.hpp
src/librados/IoCtxImpl.cc
src/librados/IoCtxImpl.h
src/librados/librados.cc
src/osdc/Objecter.h

index 59d3225a787247fbf36fc24082238f9858f543af..dde4d9e81814af0fe1a4a55cf7b1c3b9e36b0645 100644 (file)
@@ -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")       \
index b92a94f173457c4ef3535ea6f291272f36746567..52ce642934c88ca851c21f7305a9f5890838721a 100644 (file)
@@ -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);
index 945dbec2126d75f0903fce8c740eef965f916112..517eeb8200b422f55e24b435cabb36557fa922d5 100644 (file)
@@ -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 ////////////////////////////////
 
index df73b0326965ce0cc5c5eb76eef04f18875edf25..45bfdfdbee7b04377b64ae9018c41b75296cf676 100644 (file)
@@ -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
index 7a193a30b8b9e0f4f003db6ca5cfcda20f3ee526..09775e2ec588a41ec3502c022a82d9f6fbca2a65 100644 (file)
@@ -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;
index 379c0ae027347be0ab621fcebf7da7b4e247bdf4..be251b921b47a4ac5bff0e6795ec58e6cf1032fc 100644 (file)
@@ -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);
+  }
 };