libstorage-ng
Loading...
Searching...
No Matches
Devicegraph.h
1/*
2 * Copyright (c) [2014-2015] Novell, Inc.
3 * Copyright (c) [2016-2021] 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_DEVICEGRAPH_H
25#define STORAGE_DEVICEGRAPH_H
26
27
28#include <boost/noncopyable.hpp>
29
30#include "storage/Devices/Device.h"
31#include "storage/Graphviz.h"
32#include "storage/Utils/Swig.h"
33#include "storage/UsedFeatures.h"
34
35
36namespace storage
37{
38 class Storage;
39 class Device;
40 class Holder;
41 class Disk;
42 class Md;
43 class LvmVg;
44 class Filesystem;
45 class BlkFilesystem;
46 class CheckCallbacks;
47
48
50 {
51 public:
52
53 DeviceNotFound(const std::string& msg);
54 };
55
56
58 {
59 public:
60
62 };
63
64
66 {
67 public:
68
69 DeviceNotFoundByName(const std::string& name);
70 };
71
72
74 {
75 public:
76
77 DeviceNotFoundByUuid(const std::string& uuid);
78 };
79
80
81 class ST_DEPRECATED HolderNotFound: public Exception
82 {
83 public:
84
85 HolderNotFound(const std::string& msg);
86 };
87
88
89 class ST_DEPRECATED HolderNotFoundBySids : public HolderNotFound
90 {
91 public:
92
93 HolderNotFoundBySids(sid_t source_sid, sid_t target_sid);
94 };
95
96
98 {
99 public:
100
101 HolderAlreadyExists(sid_t source_sid, sid_t target_sid);
102 };
103
104
106 {
107 public:
108
109 WrongNumberOfParents(size_t seen, size_t expected);
110 };
111
112
114 {
115 public:
116
117 WrongNumberOfChildren(size_t seen, size_t expected);
118 };
119
120
122 {
123 public:
124
125 WrongNumberOfHolders(size_t seen, size_t expected);
126 };
127
128
169 class Devicegraph : private boost::noncopyable
170 {
171
172 public:
173
175 ~Devicegraph();
176
177 bool operator==(const Devicegraph& rhs) const;
178 bool operator!=(const Devicegraph& rhs) const;
179
184
188 const Storage* get_storage() const;
189
198 void load(const std::string& filename);
199
205 void load(const std::string& filename, bool keep_sids);
206
212 void save(const std::string& filename) const;
213
217 bool empty() const;
218
222 size_t num_devices() const;
223
227 size_t num_holders() const;
228
233
237 const Device* find_device(sid_t sid) const;
238
242 bool device_exists(sid_t sid) const;
243
247 bool holder_exists(sid_t source_sid, sid_t target_sid) const;
248
254 void clear();
255
263 std::vector<Disk*> get_all_disks();
264
268 std::vector<const Disk*> get_all_disks() const;
269
277 std::vector<Md*> get_all_mds();
278
282 std::vector<const Md*> get_all_mds() const;
283
291 std::vector<LvmVg*> get_all_lvm_vgs();
292
296 std::vector<const LvmVg*> get_all_lvm_vgs() const;
297
305 std::vector<Filesystem*> get_all_filesystems();
306
310 std::vector<const Filesystem*> get_all_filesystems() const;
311
319 std::vector<BlkFilesystem*> get_all_blk_filesystems();
320
324 std::vector<const BlkFilesystem*> get_all_blk_filesystems() const;
325
338
345
351 void remove_devices(std::vector<Device*> devices);
352
359 Holder* find_holder(sid_t source_sid, sid_t target_sid);
360
364 const Holder* find_holder(sid_t source_sid, sid_t target_sid) const;
365
369 std::vector<Holder*> find_holders(sid_t source_sid, sid_t target_sid);
370
374 std::vector<const Holder*> find_holders(sid_t source_sid, sid_t target_sid) const;
375
381 void remove_holder(Holder* holder);
382
390 void check(const CheckCallbacks* check_callbacks = nullptr) const;
391
392 uint64_t used_features() const ST_DEPRECATED;
393
397 uf_t used_features(UsedFeaturesDependencyType used_features_dependency_type) const;
398
399 // TODO move to Impl
400 void copy(Devicegraph& dest) const;
401
410 void write_graphviz(const std::string& filename, DevicegraphStyleCallbacks* style_callbacks, View view) const;
411
415 void write_graphviz(const std::string& filename, DevicegraphStyleCallbacks* style_callbacks) const ST_DEPRECATED;
416
425 void write_graphviz(const std::string& filename, GraphvizFlags flags = GraphvizFlags::NAME,
426 GraphvizFlags tooltip_flags = GraphvizFlags::NONE) const ST_DEPRECATED;
427
428 friend std::ostream& operator<<(std::ostream& out, const Devicegraph& devicegraph);
429
430 public:
431
432 class Impl;
433
434 Impl& get_impl() { return *impl; }
435 const Impl& get_impl() const { return *impl; }
436
437 private:
438
439 const std::unique_ptr<Impl> impl;
440
441 };
442
443}
444
445#endif
Definition Storage.h:395
Definition Devicegraph.h:66
Definition Devicegraph.h:58
Definition Devicegraph.h:74
Definition Devicegraph.h:50
An abstract base class for storage devices.
Definition Device.h:82
Style callbacks used by Devicegraph::write_graphviz().
Definition Graphviz.h:105
The main container of the libstorage-ng.
Definition Devicegraph.h:170
void remove_device(sid_t sid)
Removes the device with sid from the devicegraph.
void remove_device(Device *a)
Removes the device from the devicegraph.
const Storage * get_storage() const
Get the storage object the devicegraph belongs to.
std::vector< BlkFilesystem * > get_all_blk_filesystems()
Get all BlkFilesystems.
bool device_exists(sid_t sid) const
Check whether the device with sid exists.
std::vector< const Disk * > get_all_disks() const
Get all Disks.
const Device * find_device(sid_t sid) const
bool empty() const
Query whether the devicegraph is empty.
Device * find_device(sid_t sid)
std::vector< Disk * > get_all_disks()
Get all Disks.
void clear()
Clear the devicegraph.
std::vector< Md * > get_all_mds()
Get all Mds.
void load(const std::string &filename)
Load the devicegraph from a file.
std::vector< const Md * > get_all_mds() const
Get all Mds.
void save(const std::string &filename) const
Save the devicegraph to a file.
std::vector< LvmVg * > get_all_lvm_vgs()
Get all LvmVgs.
std::vector< const Filesystem * > get_all_filesystems() const
Get all Filesystems.
std::vector< const BlkFilesystem * > get_all_blk_filesystems() const
Get all BlkFilesystems.
void load(const std::string &filename, bool keep_sids)
Load the devicegraph from a file.
Storage * get_storage()
Get the storage object the devicegraph belongs to.
void remove_devices(std::vector< Device * > devices)
Removes the devices from the devicegraph.
std::vector< const LvmVg * > get_all_lvm_vgs() const
Get all LvmVgs.
void write_graphviz(const std::string &filename, DevicegraphStyleCallbacks *style_callbacks, View view) const
Writes the devicegraph in graphviz format.
bool holder_exists(sid_t source_sid, sid_t target_sid) const
Check whether a holder with source_sid and target_sid exists.
size_t num_devices() const
Return the number of devices.
size_t num_holders() const
Return the number of holders.
std::vector< Filesystem * > get_all_filesystems()
Get all Filesystems.
std::vector< Holder * > find_holders(sid_t source_sid, sid_t target_sid)
Find all holders with source_sid and sid_t target_sid.
Holder * find_holder(sid_t source_sid, sid_t target_sid)
Find the holder with source_sid and target_sid.
const Holder * find_holder(sid_t source_sid, sid_t target_sid) const
Find the holder with source_sid and target_sid.
void check(const CheckCallbacks *check_callbacks=nullptr) const
Checks the devicegraph.
void remove_holder(Holder *holder)
Removes the holder from the devicegraph.
std::vector< const Holder * > find_holders(sid_t source_sid, sid_t target_sid) const
Find all holders with source_sid and sid_t target_sid.
Base class for storage exceptions.
Definition Exception.h:114
const std::string & msg() const
Return the message string provided to the constructor.
Definition Exception.h:150
Definition Devicegraph.h:98
Definition Devicegraph.h:90
Definition Devicegraph.h:82
An abstract base class for storage holders.
Definition Holder.h:57
The main entry point to libstorage.
Definition Storage.h:445
Definition Devicegraph.h:114
Definition Devicegraph.h:122
Definition Devicegraph.h:106
The storage namespace.
Definition Actiongraph.h:40
View
Enum with possible views on the devicegraph.
Definition View.h:34
unsigned int sid_t
An integer storage ID.
Definition Device.h:67
UsedFeaturesDependencyType
Enum specifying the dependency type of used features.
Definition UsedFeatures.h:38
uint64_t uf_t
Type for used features.
Definition UsedFeatures.h:63
GraphvizFlags
Bitfield to control graphviz output.
Definition Graphviz.h:45