libstorage-ng
Bcache.h
1 /*
2  * Copyright (c) [2016-2023] SUSE LLC
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 
23 #ifndef STORAGE_BCACHE_H
24 #define STORAGE_BCACHE_H
25 
26 
27 #include "storage/Devices/Partitionable.h"
28 #include "storage/Devices/Device.h"
29 #include "storage/Devicegraph.h"
30 #include "storage/Utils/Swig.h"
31 
32 
33 namespace storage
34 {
35 
36  class BcacheCset;
37 
38 
42  enum class BcacheType {
43  BACKED, FLASH_ONLY
44  };
45 
46 
52  std::string get_bcache_type_name(BcacheType bcache_type);
53 
54 
58  enum class CacheMode {
59  WRITETHROUGH, WRITEBACK, WRITEAROUND, NONE
60  };
61 
62 
68  std::string get_cache_mode_name(CacheMode cache_mode);
69 
70 
78  class Bcache : public Partitionable
79  {
80  public:
81 
86  static Bcache* create(Devicegraph* devicegraph, const std::string& name);
87 
91  static Bcache* create(Devicegraph* devicegraph, const std::string& name, BcacheType type);
92 
93  static Bcache* load(Devicegraph* devicegraph, const xmlNode* node);
94 
100  BcacheType get_type() const;
101 
105  unsigned int get_number() const;
106 
114  const BlkDevice* get_backing_device() const;
115 
119  const BlkDevice* get_blk_device() const ST_DEPRECATED;
120 
127  bool has_bcache_cset() const;
128 
135  const BcacheCset* get_bcache_cset() const;
136 
144  void attach_bcache_cset(BcacheCset* bcache_cset);
145 
149  void add_bcache_cset(BcacheCset* bcache_cset) ST_DEPRECATED;
150 
158  void detach_bcache_cset();
159 
163  void remove_bcache_cset() ST_DEPRECATED;
164 
170  CacheMode get_cache_mode() const;
171 
179  void set_cache_mode(CacheMode mode);
180 
186  unsigned long long get_sequential_cutoff() const;
187 
193  unsigned get_writeback_percent() const;
194 
198  static std::vector<Bcache*> get_all(Devicegraph* devicegraph);
199 
203  static std::vector<const Bcache*> get_all(const Devicegraph* devicegraph);
204 
215  static void reassign_numbers(Devicegraph* devicegraph);
216 
222  static Bcache* find_by_name(Devicegraph* devicegraph, const std::string& name);
223 
227  static const Bcache* find_by_name(const Devicegraph* devicegraph, const std::string& name);
228 
235  static std::string find_free_name(const Devicegraph* devicegraph);
236 
242  static bool compare_by_number(const Bcache* lhs, const Bcache* rhs);
243 
244  public:
245 
246  class Impl;
247 
248  Impl& get_impl();
249  const Impl& get_impl() const;
250 
251  virtual Bcache* clone() const override;
252 
253  Bcache(Impl* impl);
254 
255  };
256 
257 
263  bool is_bcache(const Device* device);
264 
271  Bcache* to_bcache(Device* device);
272 
276  const Bcache* to_bcache(const Device* device);
277 
278 }
279 
280 #endif
std::string get_bcache_type_name(BcacheType bcache_type)
Convert the BcacheType bcache_type to a string.
static std::vector< Bcache * > get_all(Devicegraph *devicegraph)
Get all bcaches.
static std::string find_free_name(const Devicegraph *devicegraph)
Find a free name for a bcache, e.g.
const BlkDevice * get_backing_device() const
Get the BlkDevice used as backing device.
bool is_bcache(const Device *device)
Checks whether device points to a Bcache.
static bool compare_by_number(const Bcache *lhs, const Bcache *rhs)
Compare (less than) two bcaches by number.
const BlkDevice * get_blk_device() const ST_DEPRECATED
Get the BlkDevice used as backing device.
BcacheType
Bcache types.
Definition: Bcache.h:42
A bcache device.
Definition: Bcache.h:78
static Bcache * create(Devicegraph *devicegraph, const std::string &name)
Create a device of type Bcache.
bool has_bcache_cset() const
Returns true if a caching set is attached.
std::string get_cache_mode_name(CacheMode cache_mode)
Convert the CacheMode cache_mode to a string.
static void reassign_numbers(Devicegraph *devicegraph)
Fix the numeric ids of bcache devices so that there are no holes in the id sequence for in-memory bca...
void attach_bcache_cset(BcacheCset *bcache_cset)
Associates a caching set to the bcache.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
void detach_bcache_cset()
Removes association with a caching set.
void add_bcache_cset(BcacheCset *bcache_cset) ST_DEPRECATED
Associates a caching set to the bcache.
An abstract Block Device.
Definition: BlkDevice.h:48
unsigned get_writeback_percent() const
Returns percent of writeback dirty pages.
void remove_bcache_cset() ST_DEPRECATED
Removes association with a caching set.
const BcacheCset * get_bcache_cset() const
Get the caching set associated with this bcache device.
An abstract base class for storage devices.
Definition: Device.h:81
A bcache cache set.
Definition: BcacheCset.h:41
Bcache * to_bcache(Device *device)
Converts pointer to Device to pointer to Bcache.
unsigned long long get_sequential_cutoff() const
Returns size of sequential_cutoff attribute.
Definition: Partitionable.h:39
The storage namespace.
Definition: Actiongraph.h:39
BcacheType get_type() const
Get the bcache type.
static Bcache * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a bcache by its name.
unsigned int get_number() const
Get the number of the bcache.
void set_cache_mode(CacheMode mode)
Sets cache mode attribute.
CacheMode
The Cache mode attribute.
Definition: Bcache.h:58
CacheMode get_cache_mode() const
Returns cache mode attribute.