]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/cache/pwl/ImageCacheState.h
import ceph quincy 17.2.1
[ceph.git] / ceph / src / librbd / cache / pwl / ImageCacheState.h
CommitLineData
f67539c2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_LIBRBD_CACHE_RWL_IMAGE_CACHE_STATE_H
5#define CEPH_LIBRBD_CACHE_RWL_IMAGE_CACHE_STATE_H
6
33c7a0ef 7#include "json_spirit/json_spirit.h"
f67539c2
TL
8#include "librbd/ImageCtx.h"
9#include "librbd/cache/Types.h"
10#include <string>
11
f67539c2
TL
12namespace ceph {
13 class Formatter;
14}
15
16namespace librbd {
17
18namespace plugin { template <typename> struct Api; }
19
20namespace cache {
21namespace pwl {
22
23template <typename ImageCtxT = ImageCtx>
24class ImageCacheState {
25private:
26 ImageCtxT* m_image_ctx;
27 plugin::Api<ImageCtxT>& m_plugin_api;
28public:
29 bool present = false;
30 bool empty = true;
31 bool clean = true;
32 std::string host;
33 std::string path;
33c7a0ef 34 std::string mode;
f67539c2 35 uint64_t size = 0;
33c7a0ef
TL
36 /* After reloading, the following data does not need to be read,
37 * but recalculated. */
38 utime_t stats_timestamp;
39 uint64_t allocated_bytes = 0;
40 uint64_t cached_bytes = 0;
41 uint64_t dirty_bytes = 0;
42 uint64_t free_bytes = 0;
43 uint64_t hits_full = 0;
44 uint64_t hits_partial = 0;
45 uint64_t misses = 0;
46 uint64_t hit_bytes = 0;
47 uint64_t miss_bytes = 0;
48
49 ImageCacheState(ImageCtxT* image_ctx, plugin::Api<ImageCtxT>& plugin_api)
50 : m_image_ctx(image_ctx), m_plugin_api(plugin_api) {}
f67539c2
TL
51
52 ~ImageCacheState() {}
53
33c7a0ef
TL
54 ImageCacheType get_image_cache_mode() const {
55 if (mode == "rwl") {
f67539c2 56 return IMAGE_CACHE_TYPE_RWL;
33c7a0ef 57 } else if (mode == "ssd") {
f67539c2
TL
58 return IMAGE_CACHE_TYPE_SSD;
59 }
60 return IMAGE_CACHE_TYPE_UNKNOWN;
61 }
62
33c7a0ef
TL
63 void init_from_config();
64 bool init_from_metadata(json_spirit::mValue& json_root);
f67539c2
TL
65
66 void write_image_cache_state(Context *on_finish);
67
68 void clear_image_cache_state(Context *on_finish);
69
f67539c2
TL
70 static ImageCacheState<ImageCtxT>* create_image_cache_state(
71 ImageCtxT* image_ctx, plugin::Api<ImageCtxT>& plugin_api, int &r);
72
73 static ImageCacheState<ImageCtxT>* get_image_cache_state(
74 ImageCtxT* image_ctx, plugin::Api<ImageCtxT>& plugin_api);
75
76 bool is_valid();
77};
78
79} // namespace pwl
80} // namespace cache
81} // namespace librbd
82
83extern template class librbd::cache::pwl::ImageCacheState<librbd::ImageCtx>;
84
85#endif // CEPH_LIBRBD_CACHE_RWL_IMAGE_CACHE_STATE_H