libstorage-ng
Devicegraph.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2018] 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 <stdexcept>
29 #include <boost/noncopyable.hpp>
30 
31 #include "storage/Devices/Device.h"
32 #include "storage/Graphviz.h"
33 
34 
35 namespace storage
36 {
37  class Storage;
38  class Device;
39  class Holder;
40  class Disk;
41  class Md;
42  class LvmVg;
43  class Filesystem;
44  class BlkFilesystem;
45  class CheckCallbacks;
46 
47 
48  class DeviceNotFound : public Exception
49  {
50  public:
51 
52  DeviceNotFound(const std::string& msg);
53  };
54 
55 
57  {
58  public:
59 
61  };
62 
63 
65  {
66  public:
67 
68  DeviceNotFoundByName(const std::string& name);
69  };
70 
71 
73  {
74  public:
75 
76  DeviceNotFoundByUuid(const std::string& uuid);
77  };
78 
79 
80  class HolderNotFound : public Exception
81  {
82  public:
83 
84  HolderNotFound(const std::string& msg);
85  };
86 
87 
89  {
90  public:
91 
92  HolderNotFoundBySids(sid_t source_sid, sid_t target_sid);
93  };
94 
95 
97  {
98  public:
99 
100  HolderAlreadyExists(sid_t source_sid, sid_t target_sid);
101  };
102 
103 
105  {
106  public:
107 
108  WrongNumberOfParents(size_t seen, size_t expected);
109  };
110 
111 
113  {
114  public:
115 
116  WrongNumberOfChildren(size_t seen, size_t expected);
117  };
118 
119 
153  class Devicegraph : private boost::noncopyable
154  {
155 
156  public:
157 
159  ~Devicegraph();
160 
161  bool operator==(const Devicegraph& rhs) const;
162  bool operator!=(const Devicegraph& rhs) const;
163 
164  Storage* get_storage();
165  const Storage* get_storage() const;
166 
170  void load(const std::string& filename);
171 
175  void save(const std::string& filename) const;
176 
177  bool empty() const;
178 
179  size_t num_devices() const;
180  size_t num_holders() const;
181 
185  Device* find_device(sid_t sid);
186 
190  const Device* find_device(sid_t sid) const;
191 
195  bool device_exists(sid_t sid) const;
196 
200  bool holder_exists(sid_t source_sid, sid_t target_sid) const;
201 
202  void clear();
203 
204  // convenient functions, equivalent to e.g. Disk::get_all(devicegraph)
205  std::vector<Disk*> get_all_disks();
206  std::vector<const Disk*> get_all_disks() const;
207 
208  std::vector<Md*> get_all_mds();
209  std::vector<const Md*> get_all_mds() const;
210 
211  std::vector<LvmVg*> get_all_lvm_vgs();
212  std::vector<const LvmVg*> get_all_lvm_vgs() const;
213 
214  std::vector<Filesystem*> get_all_filesystems();
215  std::vector<const Filesystem*> get_all_filesystems() const;
216 
217  std::vector<BlkFilesystem*> get_all_blk_filesystems();
218  std::vector<const BlkFilesystem*> get_all_blk_filesystems() const;
219 
229  void remove_device(sid_t sid);
230 
231  void remove_device(Device* a);
232 
233  void remove_devices(std::vector<Device*> devices);
234 
238  Holder* find_holder(sid_t source_sid, sid_t target_sid);
239 
243  const Holder* find_holder(sid_t source_sid, sid_t target_sid) const;
244 
245  void remove_holder(Holder* holder);
246 
254  void check(const CheckCallbacks* check_callbacks = nullptr) const;
255 
259  uint64_t used_features() const;
260 
261  // TODO move to Impl
262  void copy(Devicegraph& dest) const;
263 
270  void write_graphviz(const std::string& filename, GraphvizFlags flags = GraphvizFlags::NAME,
271  GraphvizFlags tooltip_flags = GraphvizFlags::NONE) const;
272 
273  friend std::ostream& operator<<(std::ostream& out, const Devicegraph& devicegraph);
274 
275  public:
276 
277  class Impl;
278 
279  Impl& get_impl() { return *impl; }
280  const Impl& get_impl() const { return *impl; }
281 
282  private:
283 
284  const std::unique_ptr<Impl> impl;
285 
286  };
287 
288 }
289 
290 #endif
GraphvizFlags
Bitfield to control graphviz output.
Definition: Graphviz.h:36
Definition: Devicegraph.h:72
Definition: Devicegraph.h:96
Holder * find_holder(sid_t source_sid, sid_t target_sid)
const std::string & msg() const
Return the message string provided to the constructor.
Definition: Exception.h:150
bool device_exists(sid_t sid) const
Check whether the device with sid exists.
void check(const CheckCallbacks *check_callbacks=nullptr) const
Checks the devicegraph.
uint64_t used_features() const
Calculates a bit-field with the used features of the devicegraph.
The master container of the libstorage.
Definition: Devicegraph.h:153
Definition: Devicegraph.h:104
Definition: Devicegraph.h:80
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
Definition: Devicegraph.h:56
bool holder_exists(sid_t source_sid, sid_t target_sid) const
Check whether the holder with source sid and target sid exists.
Definition: Devicegraph.h:88
Definition: Devicegraph.h:48
Definition: Devicegraph.h:64
void save(const std::string &filename) const
Definition: Holder.h:51
Definition: Devicegraph.h:112
void remove_device(sid_t sid)
Removes the device with sid from the devicegraph.
The main entry point to libstorage.
Definition: Storage.h:156
Device * find_device(sid_t sid)
void write_graphviz(const std::string &filename, GraphvizFlags flags=GraphvizFlags::NAME, GraphvizFlags tooltip_flags=GraphvizFlags::NONE) const
Writes the devicegraph in graphviz format.
Base class for storage exceptions.
Definition: Exception.h:113
The storage namespace.
Definition: Actiongraph.h:37
unsigned int sid_t
An integer storage ID.
Definition: Device.h:66
void load(const std::string &filename)
Definition: Storage.h:135