libstorage-ng
Devicegraph.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) 2016 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 
45 
46  struct DeviceNotFound : public Exception
47  {
48  DeviceNotFound(const std::string& msg);
49  };
50 
51 
53  {
55  };
56 
57 
59  {
60  DeviceNotFoundByName(const std::string& name);
61  };
62 
63 
65  {
66  DeviceNotFoundByUuid(const std::string& uuid);
67  };
68 
69 
70  struct HolderNotFound : public Exception
71  {
72  HolderNotFound(const std::string& msg);
73  };
74 
75 
77  {
78  HolderNotFoundBySid(sid_t source_sid, sid_t target_sid);
79  };
80 
81 
83  {
84  HolderAlreadyExists(sid_t source_sid, sid_t target_sid);
85  };
86 
87 
89  {
90  WrongNumberOfParents(size_t seen, size_t expected);
91  };
92 
93 
95  {
96  WrongNumberOfChildren(size_t seen, size_t expected);
97  };
98 
99 
133  class Devicegraph : private boost::noncopyable
134  {
135 
136  public:
137 
138  Devicegraph(const Storage* storage = nullptr); // TODO
139  ~Devicegraph();
140 
141  bool operator==(const Devicegraph& rhs) const;
142  bool operator!=(const Devicegraph& rhs) const;
143 
144  const Storage* get_storage() const;
145 
146  void load(const std::string& filename);
147  void save(const std::string& filename) const;
148 
149  bool empty() const;
150 
151  size_t num_devices() const;
152  size_t num_holders() const;
153 
154  Device* find_device(sid_t sid);
155  const Device* find_device(sid_t sid) const;
156 
157  bool device_exists(sid_t sid) const;
158 
159  void clear();
160 
161  // convenient functions, equivalent to e.g. Disk::get_all(devicegraph)
162  std::vector<Disk*> get_all_disks();
163  std::vector<const Disk*> get_all_disks() const;
164 
165  std::vector<Md*> get_all_mds();
166  std::vector<const Md*> get_all_mds() const;
167 
168  std::vector<LvmVg*> get_all_lvm_vgs();
169  std::vector<const LvmVg*> get_all_lvm_vgs() const;
170 
171  std::vector<Filesystem*> get_all_filesystems();
172  std::vector<const Filesystem*> get_all_filesystems() const;
173 
181  void remove_device(sid_t sid);
182  void remove_device(Device* a);
183 
184  void remove_devices(std::vector<Device*> devices);
185 
186  Holder* find_holder(sid_t source_sid, sid_t target_sid);
187  const Holder* find_holder(sid_t source_sid, sid_t target_sid) const;
188 
189  void remove_holder(Holder* holder);
190 
191  void check() const;
192 
196  uint64_t used_features() const;
197 
198  // TODO move to Impl
199  void copy(Devicegraph& dest) const;
200 
201  void write_graphviz(const std::string& filename, GraphvizFlags graphviz_flags =
202  GraphvizFlags::NONE) const;
203 
204  friend std::ostream& operator<<(std::ostream& out, const Devicegraph& devicegraph);
205 
206  public:
207 
208  class Impl;
209 
210  Impl& get_impl() { return *impl; }
211  const Impl& get_impl() const { return *impl; }
212 
213  private:
214 
215  const std::unique_ptr<Impl> impl;
216 
217  };
218 
219 }
220 
221 #endif
GraphvizFlags
Bitfield to control graphviz output.
Definition: Graphviz.h:37
Definition: Devicegraph.h:52
Definition: Devicegraph.h:76
Definition: Devicegraph.h:82
const std::string & msg() const
Return the message string provided to the constructor.
Definition: Exception.h:150
Definition: Devicegraph.h:58
The master container of the libstorage.
Definition: Devicegraph.h:133
Definition: Devicegraph.h:70
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:73
Definition: Devicegraph.h:88
Definition: Holder.h:48
The main entry point to libstorage.
Definition: Storage.h:99
Base class for storage exceptions.
Definition: Exception.h:113
The storage namespace.
Definition: Actiongraph.h:36
unsigned int sid_t
An integer storage ID.
Definition: Device.h:64
Definition: Devicegraph.h:64
Definition: Devicegraph.h:94
Definition: Devicegraph.h:46
friend std::ostream & operator<<(std::ostream &str, const Exception &obj)
Exception stream output.