libstorage-ng
BlkDevice.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2019] SUSE LLC
4  *
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may
20  * find current contact information at www.novell.com.
21  */
22 
23 
24 #ifndef STORAGE_BLK_DEVICE_H
25 #define STORAGE_BLK_DEVICE_H
26 
27 
28 #include "storage/Utils/Swig.h"
29 #include "storage/Devices/Device.h"
30 #include "storage/Filesystems/BlkFilesystem.h"
31 
32 
33 namespace storage
34 {
35 
36  class Region;
37  class Topology;
38  class Encryption;
39  class Bcache;
40  class BcacheCset;
41 
42 
44  class BlkDevice : public Device
45  {
46  public:
47 
48  const std::string& get_name() const;
49  void set_name(const std::string& name);
50 
51  const Region& get_region() const;
52 
56  void set_region(const Region& region);
57 
58  unsigned long long get_size() const;
59 
63  void set_size(unsigned long long size);
64 
70  std::string get_size_string() const;
71 
75  const Topology& get_topology() const;
76 
80  void set_topology(const Topology& topology);
81 
82  bool is_active() const;
83 
84  const std::string& get_sysfs_name() const;
85  const std::string& get_sysfs_path() const;
86 
87  const std::vector<std::string>& get_udev_paths() const;
88  const std::vector<std::string>& get_udev_ids() const;
89 
98  bool is_usable_as_blk_device() const;
99 
104  const std::string& get_dm_table_name() const;
105 
106  void set_dm_table_name(const std::string& dm_table_name);
107 
111  static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
112 
116  static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
117 
124  static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
125 
129  static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
130 
138  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name);
139 
143  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name);
144 
150  BlkFilesystem* create_blk_filesystem(FsType fs_type);
151 
152  bool has_blk_filesystem() const;
153 
158 
162  const BlkFilesystem* get_blk_filesystem() const;
163 
167  BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
168 
169  bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
170 
174  BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
175 
179  const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
180 
191  Encryption* create_encryption(const std::string& dm_name);
192 
199  void remove_encryption();
200 
201  bool has_encryption() const;
202 
207 
211  const Encryption* get_encryption() const;
212 
217  Bcache* create_bcache(const std::string& name);
218 
219  bool has_bcache() const;
220 
224  Bcache* get_bcache();
225 
229  const Bcache* get_bcache() const;
230 
237 
238  bool has_bcache_cset() const;
239 
244 
248  const BcacheCset* get_bcache_cset() const;
249 
253  static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
254 
255  public:
256 
257  class Impl;
258 
259  Impl& get_impl();
260  const Impl& get_impl() const;
261 
262  protected:
263 
264  BlkDevice(Impl* impl);
265 
266  };
267 
268 
269  bool is_blk_device(const Device* device);
270 
277  BlkDevice* to_blk_device(Device* device);
278 
282  const BlkDevice* to_blk_device(const Device* device);
283 
284 }
285 
286 #endif
Bcache * create_bcache(const std::string &name)
Creates a Bcache on the blk device.
BcacheCset * get_bcache_cset()
static std::vector< BlkDevice * > get_all(Devicegraph *devicegraph)
Get all BlkDevices.
void set_size(unsigned long long size)
bool is_usable_as_blk_device() const
Checks whether the blk device is in general usable as a blk device.
Encryption * get_encryption()
Encryption * create_encryption(const std::string &dm_name)
Creates an encryption device on the blk device.
static BlkDevice * find_by_any_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by any name including any symbolic links in /dev.
A bcache device.
Definition: Bcache.h:61
BlkFilesystem * create_filesystem(FsType fs_type) ST_DEPRECATED
Creates a block filesystem on the block device.
Definition: BlkDevice.h:167
A start/length pair with a block size.
Definition: Region.h:73
BlkFilesystem * create_blk_filesystem(FsType fs_type)
Creates a block filesystem on the block device.
BlkDevice * to_blk_device(Device *device)
Converts pointer to Device to pointer to BlkDevice.
An encryption layer on a blk device.
Definition: Encryption.h:45
const std::string & get_dm_table_name() const
Return device-mapper table name (dm-table-name for short).
The master container of the libstorage.
Definition: Devicegraph.h:153
const Topology & get_topology() const
Get the topology.
BlkFilesystem * get_blk_filesystem()
Definition: BlkFilesystem.h:42
An abstract Block Device.
Definition: BlkDevice.h:44
void set_topology(const Topology &topology)
Set the topology.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
A bcache cache set.
Definition: BcacheCset.h:41
const BlkFilesystem * get_filesystem() const ST_DEPRECATED
Definition: BlkDevice.h:179
static bool compare_by_dm_table_name(const BlkDevice *lhs, const BlkDevice *rhs)
Compare (less than) two BlkDevices by DM table name.
void set_region(const Region &region)
A class to represent hardware alignment information.
Definition: Topology.h:38
The storage namespace.
Definition: Actiongraph.h:37
BcacheCset * create_bcache_cset()
Creates an BcacheCset on the blk device.
std::string get_size_string() const
Returns the size of the block device as a localised string.
Bcache * get_bcache()
BlkFilesystem * get_filesystem() ST_DEPRECATED
Definition: BlkDevice.h:174
void remove_encryption()
Removes an encryption device on the blk device.
static BlkDevice * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.