7fb78e3b216bea703cd45c7aa3ec3303c4dc8acd
[stor4nfv.git] / src / ceph / 0002-librbd-cleanup-rbd-shared-RO-cache.patch
1 From 26f4a0804c035895fd77e9a70f47ede3f4512bde Mon Sep 17 00:00:00 2001
2 From: Yuan Zhou <yuan.zhou@intel.com>
3 Date: Wed, 20 Jun 2018 11:34:17 +0800
4 Subject: [PATCH 02/10] librbd: cleanup rbd shared RO cache
5
6 - adding namespace for rbd cache controller
7 - move SyncFile code under librbd/cache/
8
9 Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
10 ---
11  src/librbd/CMakeLists.txt                          |   2 +-
12  src/librbd/cache/SharedPersistentObjectCacher.cc   |   4 +-
13  src/librbd/cache/SharedPersistentObjectCacher.h    |   6 +-
14  .../cache/SharedPersistentObjectCacherFile.cc      | 114 +++++++++++++++++++++
15  .../cache/SharedPersistentObjectCacherFile.h       |  74 +++++++++++++
16  .../SharedPersistentObjectCacherObjectDispatch.cc  |   4 +-
17  .../SharedPersistentObjectCacherObjectDispatch.h   |   2 +-
18  src/os/CacheStore/SyncFile.cc                      | 110 --------------------
19  src/os/CacheStore/SyncFile.h                       |  74 -------------
20  src/tools/rbd_cache/CMakeLists.txt                 |   2 +-
21  src/tools/rbd_cache/CacheController.cc             |   9 +-
22  src/tools/rbd_cache/CacheController.h              |  55 ++++++++++
23  src/tools/rbd_cache/CacheController.hpp            |  49 ---------
24  src/tools/rbd_cache/CacheControllerSocket.hpp      |   6 ++
25  .../rbd_cache/CacheControllerSocketClient.hpp      |   5 +
26  src/tools/rbd_cache/CacheControllerSocketCommon.h  |   5 +
27  src/tools/rbd_cache/ObjectCacheStore.cc            |   7 +-
28  src/tools/rbd_cache/ObjectCacheStore.h             |   9 +-
29  src/tools/rbd_cache/main.cc                        |   6 +-
30  19 files changed, 293 insertions(+), 250 deletions(-)
31  create mode 100644 src/librbd/cache/SharedPersistentObjectCacherFile.cc
32  create mode 100644 src/librbd/cache/SharedPersistentObjectCacherFile.h
33  delete mode 100644 src/os/CacheStore/SyncFile.cc
34  delete mode 100644 src/os/CacheStore/SyncFile.h
35  create mode 100644 src/tools/rbd_cache/CacheController.h
36  delete mode 100644 src/tools/rbd_cache/CacheController.hpp
37
38 diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt
39 index 92539a8..540ee78 100644
40 --- a/src/librbd/CMakeLists.txt
41 +++ b/src/librbd/CMakeLists.txt
42 @@ -34,6 +34,7 @@ set(librbd_internal_srcs
43    cache/ObjectCacherObjectDispatch.cc
44    cache/SharedPersistentObjectCacherObjectDispatch.cc
45    cache/SharedPersistentObjectCacher.cc
46 +  cache/SharedPersistentObjectCacherFile.cc
47    deep_copy/ImageCopyRequest.cc
48    deep_copy/MetadataCopyRequest.cc
49    deep_copy/ObjectCopyRequest.cc
50 @@ -124,7 +125,6 @@ set(librbd_internal_srcs
51    trash/MoveRequest.cc
52    watcher/Notifier.cc
53    watcher/RewatchRequest.cc
54 -  ${CMAKE_SOURCE_DIR}/src/os/CacheStore/SyncFile.cc
55    ${CMAKE_SOURCE_DIR}/src/common/ContextCompletion.cc)
56  
57  add_library(rbd_api STATIC librbd.cc)
58 diff --git a/src/librbd/cache/SharedPersistentObjectCacher.cc b/src/librbd/cache/SharedPersistentObjectCacher.cc
59 index a849260..260567c 100644
60 --- a/src/librbd/cache/SharedPersistentObjectCacher.cc
61 +++ b/src/librbd/cache/SharedPersistentObjectCacher.cc
62 @@ -19,7 +19,7 @@ SharedPersistentObjectCacher<I>::SharedPersistentObjectCacher(I *image_ctx, std:
63    : m_image_ctx(image_ctx), m_cache_path(cache_path),
64      m_file_map_lock("librbd::cache::SharedObjectCacher::filemaplock") {
65    auto *cct = m_image_ctx->cct;
66 -
67 +  ldout(cct, 20) << dendl;
68  }
69  
70  template <typename I>
71 @@ -40,7 +40,7 @@ int SharedPersistentObjectCacher<I>::read_object(std::string oid, ceph::bufferli
72    std::string cache_file_name = m_image_ctx->data_ctx.get_pool_name() + oid;
73  
74    //TODO(): make a cache for cachefile fd
75 -  os::CacheStore::SyncFile* target_cache_file = new os::CacheStore::SyncFile(cct, cache_file_name);
76 +  SyncFile* target_cache_file = new SyncFile(cct, cache_file_name);
77    target_cache_file->open();
78  
79    int ret = target_cache_file->read_object_from_file(read_data, offset, length);
80 diff --git a/src/librbd/cache/SharedPersistentObjectCacher.h b/src/librbd/cache/SharedPersistentObjectCacher.h
81 index d108a05..af04e63 100644
82 --- a/src/librbd/cache/SharedPersistentObjectCacher.h
83 +++ b/src/librbd/cache/SharedPersistentObjectCacher.h
84 @@ -6,7 +6,7 @@
85  
86  #include "include/buffer_fwd.h"
87  #include "include/int_types.h"
88 -#include "os/CacheStore/SyncFile.h"
89 +#include "SharedPersistentObjectCacherFile.h"
90  #include "common/Mutex.h"
91  #include <vector>
92  #include <map>
93 @@ -31,9 +31,9 @@ public:
94  
95  private:
96    ImageCtxT *m_image_ctx;
97 -  std::map<std::string,  os::CacheStore::SyncFile*> file_map;
98 -  Mutex m_file_map_lock;
99    std::string m_cache_path;
100 +  Mutex m_file_map_lock;
101 +  std::map<std::string,  SyncFile*> file_map;
102  
103  };
104  
105 diff --git a/src/librbd/cache/SharedPersistentObjectCacherFile.cc b/src/librbd/cache/SharedPersistentObjectCacherFile.cc
106 new file mode 100644
107 index 0000000..75a3053
108 --- /dev/null
109 +++ b/src/librbd/cache/SharedPersistentObjectCacherFile.cc
110 @@ -0,0 +1,114 @@
111 +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
112 +// vim: ts=8 sw=2 smarttab
113 +
114 +#include "SharedPersistentObjectCacherFile.h"
115 +#include "include/Context.h"
116 +#include "common/dout.h"
117 +#include "common/WorkQueue.h"
118 +#include "librbd/ImageCtx.h"
119 +#include <sys/types.h>
120 +#include <sys/stat.h>
121 +#include <aio.h>
122 +#include <errno.h>
123 +#include <fcntl.h>
124 +#include <utility>
125 +
126 +#define dout_subsys ceph_subsys_rbd
127 +#undef dout_prefix
128 +#define dout_prefix *_dout << "librbd::cache::SyncFile: " << this << " " \
129 +                           <<  __func__ << ": "
130 +
131 +namespace librbd {
132 +namespace cache {
133 +
134 +SyncFile::SyncFile(CephContext *cct, const std::string &name)
135 +  : cct(cct) {
136 +  m_name = cct->_conf->get_val<std::string>("rbd_shared_cache_path") + "/rbd_cache." + name;
137 +  ldout(cct, 20) << "file path=" << m_name << dendl;
138 +}
139 +
140 +SyncFile::~SyncFile() {
141 +  // TODO force proper cleanup
142 +  if (m_fd != -1) {
143 +    ::close(m_fd);
144 +  }
145 +}
146 +
147 +void SyncFile::open(Context *on_finish) {
148 +  while (true) {
149 +    m_fd = ::open(m_name.c_str(), O_CREAT | O_DIRECT | O_NOATIME | O_RDWR | O_SYNC,
150 +                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
151 +    if (m_fd == -1) {
152 +      int r = -errno;
153 +      if (r == -EINTR) {
154 +        continue;
155 +      }
156 +      on_finish->complete(r);
157 +      return;
158 +    }
159 +    break;
160 +  }
161 +
162 +  on_finish->complete(0);
163 +}
164 +
165 +void SyncFile::open() {
166 +  while (true) 
167 +  {
168 +    m_fd = ::open(m_name.c_str(), O_CREAT | O_NOATIME | O_RDWR | O_SYNC,
169 +                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
170 +    if (m_fd == -1) 
171 +    {
172 +      int r = -errno;
173 +      if (r == -EINTR) {
174 +        continue;
175 +      }
176 +      return;
177 +    }
178 +    break;
179 +  }
180 +}
181 +
182 +void SyncFile::read(uint64_t offset, uint64_t length, ceph::bufferlist *bl, Context *on_finish) {
183 +  on_finish->complete(read_object_from_file(bl, offset, length));
184 +}
185 +
186 +void SyncFile::write(uint64_t offset, ceph::bufferlist &&bl, bool fdatasync, Context *on_finish) {
187 +  on_finish->complete(write_object_to_file(bl, bl.length()));
188 +}
189 +
190 +int SyncFile::write_object_to_file(ceph::bufferlist read_buf, uint64_t object_len) {
191 +
192 +  ldout(cct, 20) << "cache file name:" << m_name
193 +                 << ", length:" << object_len <<  dendl;
194 +
195 +  // TODO(): aio
196 +  int ret = pwrite(m_fd, read_buf.c_str(), object_len, 0); 
197 +  if(ret < 0) {
198 +    lderr(cct)<<"write file fail:" << std::strerror(errno) << dendl;
199 +    return ret;
200 +  }
201 +
202 +  return ret;
203 +}
204 +
205 +int SyncFile::read_object_from_file(ceph::bufferlist* read_buf, uint64_t object_off, uint64_t object_len) {
206 +
207 +  ldout(cct, 20) << "offset:" << object_off
208 +                 << ", length:" << object_len <<  dendl;
209 +
210 +  bufferptr buf(object_len);
211 +
212 +  // TODO(): aio
213 +  int ret = pread(m_fd, buf.c_str(), object_len, object_off); 
214 +  if(ret < 0) {
215 +    lderr(cct)<<"read file fail:" << std::strerror(errno) << dendl;
216 +    return ret;
217 +  }
218 +  read_buf->append(std::move(buf));
219 +
220 +  return ret;
221 +}
222 +
223 +} // namespace cache
224 +} // namespace librbd
225 diff --git a/src/librbd/cache/SharedPersistentObjectCacherFile.h b/src/librbd/cache/SharedPersistentObjectCacherFile.h
226 new file mode 100644
227 index 0000000..ccbe730
228 --- /dev/null
229 +++ b/src/librbd/cache/SharedPersistentObjectCacherFile.h
230 @@ -0,0 +1,74 @@
231 +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
232 +// vim: ts=8 sw=2 smarttab
233 +
234 +#ifndef CEPH_LIBRBD_CACHE_STORE_SYNC_FILE
235 +#define CEPH_LIBRBD_CACHE_STORE_SYNC_FILE
236 +
237 +#include "include/buffer_fwd.h"
238 +#include <sys/mman.h>
239 +#include <string>
240 +
241 +struct Context;
242 +struct ContextWQ;
243 +class CephContext;
244 +
245 +namespace librbd {
246 +
247 +namespace cache {
248 +
249 +class SyncFile {
250 +public:
251 +  SyncFile(CephContext *cct, const std::string &name);
252 +  ~SyncFile();
253 +
254 +  // TODO use IO queue instead of individual commands so operations can be
255 +  // submitted in batch
256 +
257 +  // TODO use scatter/gather API
258 +
259 +  void open(Context *on_finish);
260 +
261 +  // ##
262 +  void open();
263 +  bool try_open();
264 +  void close(Context *on_finish);
265 +  void remove(Context *on_finish);
266 +
267 +  void read(uint64_t offset, uint64_t length, ceph::bufferlist *bl, Context *on_finish);
268 +
269 +  void write(uint64_t offset, ceph::bufferlist &&bl, bool fdatasync, Context *on_finish);
270 +
271 +  void discard(uint64_t offset, uint64_t length, bool fdatasync, Context *on_finish);
272 +
273 +  void truncate(uint64_t length, bool fdatasync, Context *on_finish);
274 +
275 +  void fsync(Context *on_finish);
276 +
277 +  void fdatasync(Context *on_finish);
278 +
279 +  uint64_t filesize();
280 +
281 +  int load(void** dest, uint64_t filesize);
282 +
283 +  int remove();
284 +
285 +  // ##
286 +  int write_object_to_file(ceph::bufferlist read_buf, uint64_t object_len);
287 +  int read_object_from_file(ceph::bufferlist* read_buf, uint64_t object_off, uint64_t object_len);
288 +
289 +private:
290 +  CephContext *cct;
291 +  std::string m_name;
292 +  int m_fd = -1;
293 +
294 +  int write(uint64_t offset, const ceph::bufferlist &bl, bool fdatasync);
295 +  int read(uint64_t offset, uint64_t length, ceph::bufferlist *bl);
296 +  int discard(uint64_t offset, uint64_t length, bool fdatasync);
297 +  int truncate(uint64_t length, bool fdatasync);
298 +  int fdatasync();
299 +};
300 +
301 +} // namespace cache
302 +} // namespace librbd
303 +
304 +#endif // CEPH_LIBRBD_CACHE_STORE_SYNC_FILE
305 diff --git a/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.cc b/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.cc
306 index 90d886c..2aa5cad 100644
307 --- a/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.cc
308 +++ b/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.cc
309 @@ -52,7 +52,7 @@ void SharedPersistentObjectCacherObjectDispatch<I>::init() {
310    ldout(cct, 20) << "parent image: setup SRO cache client = " << dendl;
311  
312    std::string controller_path = "/tmp/rbd_shared_readonly_cache_demo";
313 -  m_cache_client = new CacheClient(io_service, controller_path.c_str(),
314 +  m_cache_client = new rbd::cache::CacheClient(io_service, controller_path.c_str(),
315      ([&](std::string s){client_handle_request(s);}));
316  
317    int ret = m_cache_client->connect();
318 @@ -120,7 +120,7 @@ void SharedPersistentObjectCacherObjectDispatch<I>::client_handle_request(std::s
319    auto cct = m_image_ctx->cct;
320    ldout(cct, 20) << dendl;
321  
322 -  rbdsc_req_type_t *io_ctx = (rbdsc_req_type_t*)(msg.c_str());
323 +  rbd::cache::rbdsc_req_type_t *io_ctx = (rbd::cache::rbdsc_req_type_t*)(msg.c_str());
324  
325    switch (io_ctx->type) {
326      case RBDSC_REGISTER_REPLY: {
327 diff --git a/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.h b/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.h
328 index 1ede804..200688f 100644
329 --- a/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.h
330 +++ b/src/librbd/cache/SharedPersistentObjectCacherObjectDispatch.h
331 @@ -115,7 +115,7 @@ private:
332    ImageCtxT* m_image_ctx;
333  
334    void client_handle_request(std::string msg);
335 -  CacheClient *m_cache_client = nullptr;
336 +  rbd::cache::CacheClient *m_cache_client = nullptr;
337    boost::asio::io_service io_service;
338  };
339  
340 diff --git a/src/os/CacheStore/SyncFile.cc b/src/os/CacheStore/SyncFile.cc
341 deleted file mode 100644
342 index 5352bde..0000000
343 --- a/src/os/CacheStore/SyncFile.cc
344 +++ /dev/null
345 @@ -1,110 +0,0 @@
346 -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
347 -// vim: ts=8 sw=2 smarttab
348 -
349 -#include "os/CacheStore/SyncFile.h"
350 -#include "include/Context.h"
351 -#include "common/dout.h"
352 -#include "common/WorkQueue.h"
353 -#include "librbd/ImageCtx.h"
354 -#include <sys/types.h>
355 -#include <sys/stat.h>
356 -#include <aio.h>
357 -#include <errno.h>
358 -#include <fcntl.h>
359 -#include <utility>
360 -
361 -#define dout_subsys ceph_subsys_rbd
362 -#undef dout_prefix
363 -#define dout_prefix *_dout << "librbd::file::SyncFile: " << this << " " \
364 -                           <<  __func__ << ": "
365 -
366 -namespace os {
367 -namespace CacheStore {
368 -
369 -SyncFile::SyncFile(CephContext *cct, const std::string &name)
370 -  : cct(cct)
371 -{
372 -  m_name = cct->_conf->get_val<std::string>("rbd_shared_cache_path") + "/rbd_cache." + name;
373 -  ldout(cct, 20) << "file path=" << m_name << dendl;
374 -}
375 -
376 -SyncFile::~SyncFile() 
377 -{
378 -  // TODO force proper cleanup
379 -  if (m_fd != -1) {
380 -    ::close(m_fd);
381 -  }
382 -}
383 -
384 -void SyncFile::open(Context *on_finish) 
385 -{
386 -  while (true) {
387 -    m_fd = ::open(m_name.c_str(), O_CREAT | O_DIRECT | O_NOATIME | O_RDWR | O_SYNC,
388 -                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
389 -    if (m_fd == -1) {
390 -      int r = -errno;
391 -      if (r == -EINTR) {
392 -        continue;
393 -      }
394 -      on_finish->complete(r);
395 -      return;
396 -    }
397 -    break;
398 -  }
399 -
400 -  on_finish->complete(0);
401 -}
402 -
403 -void SyncFile::open() 
404 -{
405 -  while (true) 
406 -  {
407 -    m_fd = ::open(m_name.c_str(), O_CREAT | O_NOATIME | O_RDWR | O_SYNC,
408 -                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
409 -    if (m_fd == -1) 
410 -    {
411 -      int r = -errno;
412 -      if (r == -EINTR) {
413 -        continue;
414 -      }
415 -      return;
416 -    }
417 -    break;
418 -  }
419 -}
420 -
421 -int SyncFile::write_object_to_file(ceph::bufferlist read_buf, uint64_t object_len) {
422 -
423 -  ldout(cct, 20) << "cache file name:" << m_name
424 -                 << ", length:" << object_len <<  dendl;
425 -
426 -  // TODO(): aio
427 -  int ret = pwrite(m_fd, read_buf.c_str(), object_len, 0); 
428 -  if(ret < 0) {
429 -    lderr(cct)<<"write file fail:" << std::strerror(errno) << dendl;
430 -    return ret;
431 -  }
432 -
433 -  return ret;
434 -}
435 -
436 -int SyncFile::read_object_from_file(ceph::bufferlist* read_buf, uint64_t object_off, uint64_t object_len) {
437 -
438 -  ldout(cct, 20) << "offset:" << object_off
439 -                 << ", length:" << object_len <<  dendl;
440 -
441 -  bufferptr buf(object_len);
442 -
443 -  // TODO(): aio
444 -  int ret = pread(m_fd, buf.c_str(), object_len, object_off); 
445 -  if(ret < 0) {
446 -    lderr(cct)<<"read file fail:" << std::strerror(errno) << dendl;
447 -    return ret;
448 -  }
449 -  read_buf->append(std::move(buf));
450 -
451 -  return ret;
452 -}
453 -
454 -} // namespace CacheStore
455 -} // namespace os
456 diff --git a/src/os/CacheStore/SyncFile.h b/src/os/CacheStore/SyncFile.h
457 deleted file mode 100644
458 index 81602ce..0000000
459 --- a/src/os/CacheStore/SyncFile.h
460 +++ /dev/null
461 @@ -1,74 +0,0 @@
462 -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
463 -// vim: ts=8 sw=2 smarttab
464 -
465 -#ifndef CEPH_LIBOS_CACHE_STORE_SYNC_FILE
466 -#define CEPH_LIBOS_CACHE_STORE_SYNC_FILE
467 -
468 -#include "include/buffer_fwd.h"
469 -#include <sys/mman.h>
470 -#include <string>
471 -
472 -struct Context;
473 -struct ContextWQ;
474 -class CephContext;
475 -
476 -namespace os {
477 -
478 -namespace CacheStore {
479 -
480 -class SyncFile {
481 -public:
482 -  SyncFile(CephContext *cct, const std::string &name);
483 -  ~SyncFile();
484 -
485 -  // TODO use IO queue instead of individual commands so operations can be
486 -  // submitted in batch
487 -
488 -  // TODO use scatter/gather API
489 -
490 -  void open(Context *on_finish);
491 -
492 -  // ##
493 -  void open();
494 -  bool try_open();
495 -  void close(Context *on_finish);
496 -  void remove(Context *on_finish);
497 -
498 -  void read(uint64_t offset, uint64_t length, ceph::bufferlist *bl, Context *on_finish);
499 -
500 -  void write(uint64_t offset, ceph::bufferlist &&bl, bool fdatasync, Context *on_finish);
501 -
502 -  void discard(uint64_t offset, uint64_t length, bool fdatasync, Context *on_finish);
503 -
504 -  void truncate(uint64_t length, bool fdatasync, Context *on_finish);
505 -
506 -  void fsync(Context *on_finish);
507 -
508 -  void fdatasync(Context *on_finish);
509 -
510 -  uint64_t filesize();
511 -
512 -  int load(void** dest, uint64_t filesize);
513 -
514 -  int remove();
515 -
516 -  // ##
517 -  int write_object_to_file(ceph::bufferlist read_buf, uint64_t object_len);
518 -  int read_object_from_file(ceph::bufferlist* read_buf, uint64_t object_off, uint64_t object_len);
519 -
520 -private:
521 -  CephContext *cct;
522 -  std::string m_name;
523 -  int m_fd = -1;
524 -
525 -  int write(uint64_t offset, const ceph::bufferlist &bl, bool fdatasync);
526 -  int read(uint64_t offset, uint64_t length, ceph::bufferlist *bl);
527 -  int discard(uint64_t offset, uint64_t length, bool fdatasync);
528 -  int truncate(uint64_t length, bool fdatasync);
529 -  int fdatasync();
530 -};
531 -
532 -} // namespace CacheStore
533 -} // namespace os
534 -
535 -#endif // CEPH_LIBOS_CACHE_STORE_SYNC_FILE
536 diff --git a/src/tools/rbd_cache/CMakeLists.txt b/src/tools/rbd_cache/CMakeLists.txt
537 index 08eae60..597d802 100644
538 --- a/src/tools/rbd_cache/CMakeLists.txt
539 +++ b/src/tools/rbd_cache/CMakeLists.txt
540 @@ -1,5 +1,5 @@
541  add_executable(rbd-cache
542 -  ${CMAKE_SOURCE_DIR}/src/os/CacheStore/SyncFile.cc
543 +  ${CMAKE_SOURCE_DIR}/src/librbd/cache/SharedPersistentObjectCacherFile.cc
544    ObjectCacheStore.cc
545    CacheController.cc
546    main.cc)
547 diff --git a/src/tools/rbd_cache/CacheController.cc b/src/tools/rbd_cache/CacheController.cc
548 index c914358..e73ba25 100644
549 --- a/src/tools/rbd_cache/CacheController.cc
550 +++ b/src/tools/rbd_cache/CacheController.cc
551 @@ -1,7 +1,7 @@
552  // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
553  // vim: ts=8 sw=2 smarttab
554  
555 -#include "CacheController.hpp"
556 +#include "CacheController.h"
557  
558  #define dout_context g_ceph_context
559  #define dout_subsys ceph_subsys_rbd_cache
560 @@ -9,6 +9,8 @@
561  #define dout_prefix *_dout << "rbd::cache::CacheController: " << this << " " \
562                             << __func__ << ": "
563  
564 +namespace rbd {
565 +namespace cache {
566  
567  class ThreadPoolSingleton : public ThreadPool {
568  public:
569 @@ -103,3 +105,8 @@ void CacheController::handle_request(uint64_t sesstion_id, std::string msg){
570      
571    }
572  }
573 +
574 +} // namespace rbd
575 +} // namespace cache
576 +
577 +
578 diff --git a/src/tools/rbd_cache/CacheController.h b/src/tools/rbd_cache/CacheController.h
579 new file mode 100644
580 index 0000000..0e3abc1
581 --- /dev/null
582 +++ b/src/tools/rbd_cache/CacheController.h
583 @@ -0,0 +1,55 @@
584 +#ifndef CACHE_CONTROLLER_H
585 +#define CACHE_CONTROLLER_H
586 +
587 +#include <thread>
588 +
589 +#include "common/Formatter.h"
590 +#include "common/admin_socket.h"
591 +#include "common/debug.h"
592 +#include "common/errno.h"
593 +#include "common/ceph_context.h"
594 +#include "common/Mutex.h"
595 +#include "common/WorkQueue.h"
596 +#include "include/rados/librados.hpp"
597 +#include "include/rbd/librbd.h"
598 +#include "include/assert.h"
599 +#include "librbd/ImageCtx.h"
600 +#include "librbd/ImageState.h"
601 +
602 +#include "CacheControllerSocket.hpp"
603 +#include "ObjectCacheStore.h"
604 +
605 +
606 +using boost::asio::local::stream_protocol;
607 +
608 +namespace rbd {
609 +namespace cache {
610 +
611 +class CacheController {
612 + public:
613 +  CacheController(CephContext *cct, const std::vector<const char*> &args);
614 +  ~CacheController();
615 +
616 +  int init();
617 +
618 +  int shutdown();
619 +
620 +  void handle_signal(int sinnum);
621 +
622 +  void run();
623 +
624 +  void handle_request(uint64_t sesstion_id, std::string msg);
625 +
626 + private:
627 +  boost::asio::io_service io_service;
628 +  CacheServer *m_cache_server;
629 +  std::vector<const char*> m_args;
630 +  CephContext *m_cct;
631 +  ObjectCacheStore *m_object_cache_store;
632 +  ContextWQ* pcache_op_work_queue;
633 +};
634 +
635 +} // namespace rbd
636 +} // namespace cache
637 +
638 +#endif
639 diff --git a/src/tools/rbd_cache/CacheController.hpp b/src/tools/rbd_cache/CacheController.hpp
640 deleted file mode 100644
641 index 97113e4..0000000
642 --- a/src/tools/rbd_cache/CacheController.hpp
643 +++ /dev/null
644 @@ -1,49 +0,0 @@
645 -#ifndef CACHE_CONTROLLER_H
646 -#define CACHE_CONTROLLER_H
647 -
648 -#include <thread>
649 -
650 -#include "common/Formatter.h"
651 -#include "common/admin_socket.h"
652 -#include "common/debug.h"
653 -#include "common/errno.h"
654 -#include "common/ceph_context.h"
655 -#include "common/Mutex.h"
656 -#include "common/WorkQueue.h"
657 -#include "include/rados/librados.hpp"
658 -#include "include/rbd/librbd.h"
659 -#include "include/assert.h"
660 -#include "librbd/ImageCtx.h"
661 -#include "librbd/ImageState.h"
662 -
663 -#include "CacheControllerSocket.hpp"
664 -#include "ObjectCacheStore.h"
665 -
666 -
667 -using boost::asio::local::stream_protocol;
668 -
669 -class CacheController {
670 - public:
671 -  CacheController(CephContext *cct, const std::vector<const char*> &args);
672 -  ~CacheController();
673 -
674 -  int init();
675 -
676 -  int shutdown();
677 -
678 -  void handle_signal(int sinnum);
679 -
680 -  void run();
681 -
682 -  void handle_request(uint64_t sesstion_id, std::string msg);
683 -
684 - private:
685 -  boost::asio::io_service io_service;
686 -  CacheServer *m_cache_server;
687 -  std::vector<const char*> m_args;
688 -  CephContext *m_cct;
689 -  ObjectCacheStore *m_object_cache_store;
690 -  ContextWQ* pcache_op_work_queue;
691 -};
692 -
693 -#endif
694 diff --git a/src/tools/rbd_cache/CacheControllerSocket.hpp b/src/tools/rbd_cache/CacheControllerSocket.hpp
695 index 6e1a743..967af1d 100644
696 --- a/src/tools/rbd_cache/CacheControllerSocket.hpp
697 +++ b/src/tools/rbd_cache/CacheControllerSocket.hpp
698 @@ -17,6 +17,9 @@
699  
700  using boost::asio::local::stream_protocol;
701  
702 +namespace rbd {
703 +namespace cache {
704 +
705  class session : public std::enable_shared_from_this<session> {
706  public:
707    session(uint64_t session_id, boost::asio::io_service& io_service, ProcessMsg processmsg)
708 @@ -122,4 +125,7 @@ private:
709    std::map<uint64_t, session_ptr> session_map;
710  };
711  
712 +} // namespace cache
713 +} // namespace rbd
714 +
715  #endif
716 diff --git a/src/tools/rbd_cache/CacheControllerSocketClient.hpp b/src/tools/rbd_cache/CacheControllerSocketClient.hpp
717 index 8e61aa9..57be78e 100644
718 --- a/src/tools/rbd_cache/CacheControllerSocketClient.hpp
719 +++ b/src/tools/rbd_cache/CacheControllerSocketClient.hpp
720 @@ -13,6 +13,9 @@
721  
722  using boost::asio::local::stream_protocol;
723  
724 +namespace rbd {
725 +namespace cache {
726 +
727  class CacheClient {
728  public:
729    CacheClient(boost::asio::io_service& io_service,
730 @@ -128,4 +131,6 @@ public:
731    bool connected = false;
732  };
733  
734 +} // namespace cache
735 +} // namespace rbd
736  #endif
737 diff --git a/src/tools/rbd_cache/CacheControllerSocketCommon.h b/src/tools/rbd_cache/CacheControllerSocketCommon.h
738 index e253bb1..ab89155 100644
739 --- a/src/tools/rbd_cache/CacheControllerSocketCommon.h
740 +++ b/src/tools/rbd_cache/CacheControllerSocketCommon.h
741 @@ -12,6 +12,9 @@
742  #define RBDSC_LOOKUP_REPLY     0X16
743  #define RBDSC_READ_RADOS       0X16
744  
745 +namespace rbd {
746 +namespace cache {
747 +
748  typedef std::function<void(uint64_t, std::string)> ProcessMsg;
749  typedef std::function<void(std::string)> ClientProcessMsg;
750  typedef uint8_t rbdsc_req_type;
751 @@ -40,4 +43,6 @@ struct rbdsc_req_type_t {
752    }
753  };
754  
755 +} // namespace cache
756 +} // namespace rbd
757  #endif
758 diff --git a/src/tools/rbd_cache/ObjectCacheStore.cc b/src/tools/rbd_cache/ObjectCacheStore.cc
759 index 90b407c..9572a1a 100644
760 --- a/src/tools/rbd_cache/ObjectCacheStore.cc
761 +++ b/src/tools/rbd_cache/ObjectCacheStore.cc
762 @@ -9,6 +9,8 @@
763  #define dout_prefix *_dout << "rbd::cache::ObjectCacheStore: " << this << " " \
764                             << __func__ << ": "
765  
766 +namespace rbd {
767 +namespace cache {
768  
769  ObjectCacheStore::ObjectCacheStore(CephContext *cct, ContextWQ* work_queue)
770        : m_cct(cct), m_work_queue(work_queue),
771 @@ -77,7 +79,7 @@ int ObjectCacheStore::do_promote(std::string pool_name, std::string object_name)
772    }
773  
774    // persistent to cache
775 -  os::CacheStore::SyncFile cache_file(m_cct, cache_file_name);
776 +  librbd::cache::SyncFile cache_file(m_cct, cache_file_name);
777    cache_file.open();
778    ret = cache_file.write_object_to_file(read_buf, object_size);
779    
780 @@ -145,3 +147,6 @@ int ObjectCacheStore::promote_object(librados::IoCtx* ioctx, std::string object_
781    return ret;
782    
783  }
784 +
785 +} // namespace cache
786 +} // namespace rbd
787 diff --git a/src/tools/rbd_cache/ObjectCacheStore.h b/src/tools/rbd_cache/ObjectCacheStore.h
788 index 12f8399..a81beea 100644
789 --- a/src/tools/rbd_cache/ObjectCacheStore.h
790 +++ b/src/tools/rbd_cache/ObjectCacheStore.h
791 @@ -12,11 +12,14 @@
792  #include "include/rbd/librbd.h"
793  #include "librbd/ImageCtx.h"
794  #include "librbd/ImageState.h"
795 -#include "os/CacheStore/SyncFile.h"
796 +#include "librbd/cache/SharedPersistentObjectCacherFile.h"
797  
798  using librados::Rados;
799  using librados::IoCtx;
800  
801 +namespace rbd {
802 +namespace cache {
803 +
804  typedef shared_ptr<librados::Rados> RadosRef;
805  typedef shared_ptr<librados::IoCtx> IoCtxRef;
806  
807 @@ -59,7 +62,9 @@ class ObjectCacheStore
808  
809      std::map<std::string, librados::IoCtx*> m_ioctxs;
810  
811 -    os::CacheStore::SyncFile *m_cache_file;
812 +    librbd::cache::SyncFile *m_cache_file;
813  };
814  
815 +} // namespace rbd
816 +} // namespace cache
817  #endif
818 diff --git a/src/tools/rbd_cache/main.cc b/src/tools/rbd_cache/main.cc
819 index 336a581..a7c5b64 100644
820 --- a/src/tools/rbd_cache/main.cc
821 +++ b/src/tools/rbd_cache/main.cc
822 @@ -7,11 +7,11 @@
823  #include "common/errno.h"
824  #include "global/global_init.h"
825  #include "global/signal_handler.h"
826 -#include "CacheController.hpp"
827 +#include "CacheController.h"
828  
829  #include <vector>
830  
831 -CacheController *cachectl = nullptr;
832 +rbd::cache::CacheController *cachectl = nullptr;
833  
834  void usage() {
835    std::cout << "usage: cache controller [options...]" << std::endl;
836 @@ -64,7 +64,7 @@ int main(int argc, const char **argv)
837    // disable unnecessary librbd cache
838    g_ceph_context->_conf->set_val_or_die("rbd_cache", "false");
839  
840 -  cachectl = new CacheController(g_ceph_context, cmd_args);
841 +  cachectl = new rbd::cache::CacheController(g_ceph_context, cmd_args);
842    int r = cachectl->init();
843    if (r < 0) {
844      std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl;
845 -- 
846 2.7.4
847