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 #include <vector>
28 
29 #include "storage/Utils/Swig.h"
30 #include "storage/Devices/Device.h"
31 #include "storage/Filesystems/BlkFilesystem.h"
32 
33 
34 namespace storage
35 {
36 
37  class Region;
38  class Topology;
39  class Encryption;
40  enum class EncryptionType;
41  class Bcache;
42  class BcacheCset;
43 
44 
46  class BlkDevice : public Device
47  {
48  public:
49 
50  const std::string& get_name() const;
51  void set_name(const std::string& name);
52 
53  const Region& get_region() const;
54 
58  void set_region(const Region& region);
59 
60  unsigned long long get_size() const;
61 
65  void set_size(unsigned long long size);
66 
72  std::string get_size_string() const;
73 
77  const Topology& get_topology() const;
78 
82  void set_topology(const Topology& topology);
83 
84  bool is_active() const;
85 
86  const std::string& get_sysfs_name() const;
87  const std::string& get_sysfs_path() const;
88 
89  const std::vector<std::string>& get_udev_paths() const;
90  const std::vector<std::string>& get_udev_ids() const;
91 
100  bool is_usable_as_blk_device() const;
101 
106  const std::string& get_dm_table_name() const;
107 
108  void set_dm_table_name(const std::string& dm_table_name);
109 
113  static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
114 
118  static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
119 
126  static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
127 
131  static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
132 
140  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name);
141 
145  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name);
146 
152  BlkFilesystem* create_blk_filesystem(FsType fs_type);
153 
154  bool has_blk_filesystem() const;
155 
160 
164  const BlkFilesystem* get_blk_filesystem() const;
165 
169  BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
170 
171  bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
172 
176  BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
177 
181  const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
182 
191  Encryption* create_encryption(const std::string& dm_name) ST_DEPRECATED;
192 
203  Encryption* create_encryption(const std::string& dm_name, EncryptionType type);
204 
211  void remove_encryption();
212 
213  bool has_encryption() const;
214 
219 
223  const Encryption* get_encryption() const;
224 
229  Bcache* create_bcache(const std::string& name);
230 
231  bool has_bcache() const;
232 
236  Bcache* get_bcache();
237 
241  const Bcache* get_bcache() const;
242 
249 
250  bool has_bcache_cset() const;
251 
256 
260  const BcacheCset* get_bcache_cset() const;
261 
267  static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
268 
272  std::vector<MountByType> possible_mount_bys() const;
273 
274  public:
275 
276  class Impl;
277 
278  Impl& get_impl();
279  const Impl& get_impl() const;
280 
281  protected:
282 
283  BlkDevice(Impl* impl);
284 
285  };
286 
287 
293  bool is_blk_device(const Device* device);
294 
301  BlkDevice* to_blk_device(Device* device);
302 
306  const BlkDevice* to_blk_device(const Device* device);
307 
308 }
309 
310 #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()
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:62
BlkFilesystem * create_filesystem(FsType fs_type) ST_DEPRECATED
Creates a block filesystem on the block device.
Definition: BlkDevice.h:169
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:46
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:181
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
Encryption * create_encryption(const std::string &dm_name) ST_DEPRECATED
Creates an encryption device on the blk device.
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:176
bool is_blk_device(const Device *device)
Checks whether device points to an BlkDevice.
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.
std::vector< MountByType > possible_mount_bys() const
Returns the possible mount-by methods to reference the block device.