]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-immutable-object-cache: don't return empty path for older clients
authorMykola Golub <mgolub@suse.com>
Mon, 20 Jul 2020 12:14:47 +0000 (13:14 +0100)
committerJason Dillaman <dillaman@redhat.com>
Thu, 27 Aug 2020 17:56:05 +0000 (13:56 -0400)
They would crash. Now they will try to read a non-existing file.

Signed-off-by: Mykola Golub <mgolub@suse.com>
(cherry picked from commit 955a185f410152c87c52377153c397e845edbf1d)

src/test/immutable_object_cache/test_object_store.cc
src/tools/immutable_object_cache/CacheClient.cc
src/tools/immutable_object_cache/CacheController.cc
src/tools/immutable_object_cache/CacheSession.cc
src/tools/immutable_object_cache/CacheSession.h
src/tools/immutable_object_cache/ObjectCacheStore.cc
src/tools/immutable_object_cache/ObjectCacheStore.h
src/tools/immutable_object_cache/Types.cc
src/tools/immutable_object_cache/Types.h

index 5e044322ee012ba590088cf3a110575fe242a73b..736928fe0e7dca794df70a4de7425564d0e15202 100644 (file)
@@ -68,7 +68,8 @@ public:
 
   void lookup_object_cache_store(std::string pool_name, std::string vol_name, std::string obj_name, int& ret) {
     std::string cache_path;
-    ret = m_object_cache_store->lookup_object(pool_name, 1, 2, obj_name, cache_path);
+    ret = m_object_cache_store->lookup_object(pool_name, 1, 2, obj_name, true,
+                                              cache_path);
   }
 
   void TearDown() override {
index 60ba9f52fc1251927a000f2cd9c4435b84aeb26f..eeec92202ad72b338ce2c382d7989508ea2bf787 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "CacheClient.h"
 #include "common/Cond.h"
+#include "common/version.h"
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_immutable_obj_cache
@@ -376,7 +377,8 @@ namespace immutable_obj_cache {
   // TODO : re-implement this method
   int CacheClient::register_client(Context* on_finish) {
     ObjectCacheRequest* reg_req = new ObjectCacheRegData(RBDSC_REGISTER,
-                                                         m_sequence_id++);
+                                                         m_sequence_id++,
+                                                         ceph_version_to_str());
     reg_req->encode();
 
     bufferlist bl;
index c033ca49b61158e7949b57f5fe8fb5221afc7d6e..1fade8f84b4b718b4fb5023e19e5290cbf33d006 100644 (file)
@@ -102,6 +102,9 @@ void CacheController::handle_request(CacheSession* session,
     case RBDSC_REGISTER: {
       // TODO(dehao): skip register and allow clients to lookup directly
 
+      auto req_reg_data = reinterpret_cast <ObjectCacheRegData*> (req);
+      session->set_client_version(req_reg_data->version);
+
       ObjectCacheRequest* reply = new ObjectCacheRegReplyData(
         RBDSC_REGISTER_REPLY, req->seq);
       session->send(reply);
@@ -112,9 +115,11 @@ void CacheController::handle_request(CacheSession* session,
       std::string cache_path;
       ObjectCacheReadData* req_read_data =
         reinterpret_cast <ObjectCacheReadData*> (req);
+      bool return_dne_path = session->client_version().empty();
       int ret = m_object_cache_store->lookup_object(
         req_read_data->pool_namespace, req_read_data->pool_id,
-        req_read_data->snap_id, req_read_data->oid, cache_path);
+        req_read_data->snap_id, req_read_data->oid, return_dne_path,
+        cache_path);
       ObjectCacheRequest* reply = nullptr;
       if (ret != OBJ_CACHE_PROMOTED && ret != OBJ_CACHE_DNE) {
         reply = new ObjectCacheReadRadosData(RBDSC_READ_RADOS, req->seq);
index 5bf730354ab3e6390667210611aedc41ee6efc31..d00eac4f4865f8c97bab4d53ad109dab3b2b15d0 100644 (file)
@@ -31,6 +31,14 @@ stream_protocol::socket& CacheSession::socket() {
   return m_dm_socket;
 }
 
+void CacheSession::set_client_version(const std::string &version) {
+  m_client_version = version;
+}
+
+const std::string &CacheSession::client_version() const {
+  return m_client_version;
+}
+
 void CacheSession::close() {
   if (m_dm_socket.is_open()) {
     boost::system::error_code close_ec;
index d530b529c8c22008d5aa746a05833bb55d6406f9..b2890992f1a0a25117d72c778c5be62ab67cf6be 100644 (file)
@@ -36,11 +36,16 @@ class CacheSession : public std::enable_shared_from_this<CacheSession> {
   void fault(const boost::system::error_code& ec);
   void send(ObjectCacheRequest* msg);
 
+  void set_client_version(const std::string &version);
+  const std::string &client_version() const;
+
  private:
   stream_protocol::socket m_dm_socket;
   ProcessMsg m_server_process_msg;
   CephContext* m_cct;
 
+  std::string m_client_version;
+
   bufferptr m_bp_header;
 };
 
index aec72f3aa50a78faaf06dfdfc6ecdf9cfd83f005..a0b2b27ce1629af4f2ce5852a106b8b870a2b4ba 100644 (file)
@@ -181,6 +181,7 @@ int ObjectCacheStore::handle_promote_callback(int ret, bufferlist* read_buf,
 int ObjectCacheStore::lookup_object(std::string pool_nspace,
                                     uint64_t pool_id, uint64_t snap_id,
                                     std::string object_name,
+                                    bool return_dne_path,
                                     std::string& target_cache_file_path) {
   ldout(m_cct, 20) << "object name = " << object_name
                    << " in pool ID : " << pool_id << dendl;
@@ -202,6 +203,10 @@ int ObjectCacheStore::lookup_object(std::string pool_nspace,
       target_cache_file_path = get_cache_file_path(cache_file_name);
       return ret;
     case OBJ_CACHE_DNE:
+      if (return_dne_path) {
+        target_cache_file_path = get_cache_file_path(cache_file_name);
+      }
+      return ret;
     case OBJ_CACHE_SKIP:
       return ret;
     default:
index eba003412e0cd3c99f61abd7fa3c86ce63ddfae3..270a93be452203d919b9b78e9387d3724d18078c 100644 (file)
@@ -31,6 +31,7 @@ class ObjectCacheStore {
   int lookup_object(std::string pool_nspace,
                     uint64_t pool_id, uint64_t snap_id,
                     std::string object_name,
+                    bool return_dne_path,
                     std::string& target_cache_file_path);
 
  private:
index a0a4c6352aa5382cf729f34d46948cbd7aad0419..e65e94bee1ed321c3493b1ef0d7a7525b233f345 100644 (file)
@@ -40,12 +40,24 @@ void ObjectCacheRequest::decode(bufferlist& bl) {
 ObjectCacheRegData::ObjectCacheRegData() {}
 ObjectCacheRegData::ObjectCacheRegData(uint16_t t, uint64_t s)
   : ObjectCacheRequest(t, s) {}
+ObjectCacheRegData::ObjectCacheRegData(uint16_t t, uint64_t s,
+                                       const std::string &version)
+  : ObjectCacheRequest(t, s),
+    version(version) {
+}
 
 ObjectCacheRegData::~ObjectCacheRegData() {}
 
-void ObjectCacheRegData::encode_payload() {}
+void ObjectCacheRegData::encode_payload() {
+  ceph::encode(version, payload);
+}
 
-void ObjectCacheRegData::decode_payload(bufferlist::const_iterator i) {}
+void ObjectCacheRegData::decode_payload(bufferlist::const_iterator i) {
+  if (i.end()) {
+    return;
+  }
+  ceph::decode(version, i);
+}
 
 ObjectCacheRegReplyData::ObjectCacheRegReplyData() {}
 ObjectCacheRegReplyData::ObjectCacheRegReplyData(uint16_t t, uint64_t s)
index 7967d16564f056738010f6b16c0fa8fdc5ab8505..5fab1ec4897ba9aeed34c8aa48f116b7f23c11a9 100644 (file)
@@ -57,13 +57,15 @@ class ObjectCacheRequest {
 
 class ObjectCacheRegData : public ObjectCacheRequest {
  public:
+  std::string version;
   ObjectCacheRegData();
+  ObjectCacheRegData(uint16_t t, uint64_t s, const std::string &version);
   ObjectCacheRegData(uint16_t t, uint64_t s);
   ~ObjectCacheRegData() override;
   void encode_payload() override;
   void decode_payload(bufferlist::const_iterator bl) override;
   uint16_t get_request_type() override { return RBDSC_REGISTER; }
-  bool payload_empty() override { return true; }
+  bool payload_empty() override { return false; }
 };
 
 class ObjectCacheRegReplyData : public ObjectCacheRequest {