libstorage-ng
Storage.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2020] 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_STORAGE_H
25 #define STORAGE_STORAGE_H
26 
27 
28 #include <string>
29 #include <vector>
30 #include <utility>
31 #include <memory>
32 #include <boost/noncopyable.hpp>
33 
34 #include "storage/Filesystems/Mountable.h"
35 #include "storage/CommitOptions.h"
36 #include "storage/Utils/Callbacks.h"
37 
38 
42 namespace storage
43 {
77  class Environment;
78  class Arch;
79  class Devicegraph;
80  class Actiongraph;
81  class Pool;
82 
83 
92  class ActivateCallbacks : public Callbacks
93  {
94  public:
95 
96  virtual ~ActivateCallbacks() {}
97 
103  virtual bool multipath(bool looks_like_real_multipath) const = 0;
104 
117  virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
118 
119  };
120 
121 
125  class LuksInfo : private boost::noncopyable
126  {
127  public:
128 
129  LuksInfo();
130 
131  ~LuksInfo();
132 
133  const std::string& get_device_name() const;
134 
135  const std::string& get_uuid() const;
136 
137  const std::string& get_label() const;
138 
139  public:
140 
141  class Impl;
142 
143  Impl& get_impl() { return *impl; }
144  const Impl& get_impl() const { return *impl; }
145 
146  private:
147 
148  const std::unique_ptr<Impl> impl;
149 
150  };
151 
152 
157  {
158  public:
159 
160  virtual ~ActivateCallbacksLuks() {}
161 
167  virtual std::pair<bool, std::string> luks(const LuksInfo& info, int attempt) const = 0;
168 
169  };
170 
171 
178  {
179  bool multipath;
180  bool dm_raid;
181  bool md;
182  bool lvm_lv;
183  bool luks;
184  // TODO add bcache?
185  };
186 
187 
188  class ProbeCallbacks : public Callbacks
189  {
190  public:
191 
192  virtual ~ProbeCallbacks() {}
193 
194  };
195 
196 
198  {
199  public:
200 
201  virtual ~ProbeCallbacksV2() {}
202 
215  virtual bool missing_command(const std::string& message, const std::string& what,
216  const std::string& command, uint64_t used_features) const = 0;
217 
218  };
219 
220 
222  {
223  public:
224 
225  virtual ~ProbeCallbacksV3() {}
226 
230  virtual void begin() const {}
231 
235  virtual void end() const {}
236 
237  };
238 
239 
241  {
242  public:
243 
244  virtual ~CheckCallbacks() {}
245 
246  virtual void error(const std::string& message) const = 0;
247 
248  };
249 
250 
251  class CommitCallbacks : public Callbacks
252  {
253  public:
254 
255  virtual ~CommitCallbacks() {}
256 
257  };
258 
259 
261  class Storage : private boost::noncopyable
262  {
263  public:
264 
270  Storage(const Environment& environment);
271 
272  ~Storage();
273 
274  public:
275 
276  const Environment& get_environment() const;
277  const Arch& get_arch() const;
278 
284  Devicegraph* create_devicegraph(const std::string& name);
285 
289  Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
290 
296  void remove_devicegraph(const std::string& name);
297 
301  void restore_devicegraph(const std::string& name);
302 
303  bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
304 
308  bool exist_devicegraph(const std::string& name) const;
309 
313  std::vector<std::string> get_devicegraph_names() const ST_DEPRECATED;
314 
321  std::map<std::string, const Devicegraph*> get_devicegraphs() const;
322 
328  Devicegraph* get_devicegraph(const std::string& name);
329 
333  const Devicegraph* get_devicegraph(const std::string& name) const;
334 
341 
347  const Devicegraph* get_staging() const;
348 
354  const Devicegraph* get_probed() const;
355 
362 
368  const Devicegraph* get_system() const;
369 
386  void check(const CheckCallbacks* check_callbacks = nullptr) const;
387 
392 
396  void set_default_mount_by(MountByType default_mount_by);
397 
398  const std::string& get_rootprefix() const;
399  void set_rootprefix(const std::string& rootprefix);
400 
404  std::string prepend_rootprefix(const std::string& mount_point) const;
405 
413 
430  void activate(const ActivateCallbacks* activate_callbacks) const;
431 
446 
456  void probe(const ProbeCallbacks* probe_callbacks = nullptr);
457 
466  void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
467 
476  void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
477 
482  void generate_pools(const Devicegraph* devicegraph);
483 
489  Pool* create_pool(const std::string& name);
490 
496  void remove_pool(const std::string& name);
497 
501  bool exists_pool(const std::string& name) const;
502 
506  std::vector<std::string> get_pool_names() const ST_DEPRECATED;
507 
511  std::map<std::string, const Pool*> get_pools() const;
512 
518  Pool* get_pool(const std::string& name);
519 
523  const Pool* get_pool(const std::string& name) const;
524 
525  public:
526 
527  class Impl;
528 
529  Impl& get_impl() { return *impl; }
530  const Impl& get_impl() const { return *impl; }
531 
532  private:
533 
534  const std::unique_ptr<Impl> impl;
535 
536  };
537 
538 }
539 
540 #endif
Provides information whether deactivate() was able to deactivate subsystems.
Definition: Storage.h:177
void remove_pool(const std::string &name)
Remove a pool by name.
Definition: Environment.h:52
void probe(const ProbeCallbacks *probe_callbacks=nullptr)
Probe the system and replace the probed, system and staging devicegraphs.
MountByType get_default_mount_by() const
Query the default mount-by method.
Definition: Storage.h:221
Devicegraph * copy_devicegraph(const std::string &source_name, const std::string &dest_name)
void restore_devicegraph(const std::string &name)
const Devicegraph * get_probed() const
Return the probed devicegraph.
bool exist_devicegraph(const std::string &name) const
Check whether a devicegraph exists by name.
Storage(const Environment &environment)
Construct Storage object.
void check(const CheckCallbacks *check_callbacks=nullptr) const
Checks all devicegraphs.
void commit(const CommitOptions &commit_options, const CommitCallbacks *commit_callbacks=nullptr)
The actiongraph must be valid.
virtual void begin() const
Called at the begin of probing.
Definition: Storage.h:230
virtual std::pair< bool, std::string > luks(const std::string &uuid, int attempt) const =0
Decide whether the LUKS with uuid should be activated.
std::string prepend_rootprefix(const std::string &mount_point) const
Prepends the root prefix to a mount point if necessary.
bool exists_pool(const std::string &name) const
Check whether a pool exists by name.
DeactivateStatus deactivate() const
Deactivate devices like multipath, DM and MD RAID, LVM and LUKS.
const Actiongraph * calculate_actiongraph()
The actiongraph is only valid until either the probed or staging devicegraph is modified.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
Devicegraph * get_devicegraph(const std::string &name)
Return a devicegraph by name.
Definition: Storage.h:251
The actiongraph has all actions including the dependencies among them to get from one devicegraph to ...
Definition: Actiongraph.h:60
virtual bool multipath(bool looks_like_real_multipath) const =0
Decide whether multipath should be activated.
Pool * create_pool(const std::string &name)
Create a pool with name.
void set_default_mount_by(MountByType default_mount_by)
Set the default mount-by method.
Devicegraph * get_staging()
Return the staging devicegraph.
virtual bool missing_command(const std::string &message, const std::string &what, const std::string &command, uint64_t used_features) const =0
Callback for missing commands.
void activate(const ActivateCallbacks *activate_callbacks) const
Activate devices like multipath, DM and MD RAID, LVM and LUKS.
virtual void end() const
Called at the end of probing.
Definition: Storage.h:235
Stores information about a LUKS device.
Definition: Storage.h:125
Definition: Storage.h:197
Devicegraph * get_system()
Return the system devicegraph.
std::vector< std::string > get_devicegraph_names() const ST_DEPRECATED
Get the names of all devicegraphs.
std::map< std::string, const Pool * > get_pools() const
Get all pools with their names.
virtual std::pair< bool, std::string > luks(const LuksInfo &info, int attempt) const =0
Decide whether the LUKS should be activated.
std::vector< std::string > get_pool_names() const ST_DEPRECATED
Get the names of all pools.
Specialized callbacks with a more generic parameter for LUKS activation.
Definition: Storage.h:156
The main entry point to libstorage.
Definition: Storage.h:261
void generate_pools(const Devicegraph *devicegraph)
Generate pools, e.g.
Devicegraph * create_devicegraph(const std::string &name)
Create a devicegraph with name.
Definition: Storage.h:188
The storage namespace.
Definition: Actiongraph.h:38
void remove_devicegraph(const std::string &name)
Remove a devicegraph by name.
A pool represents a collection of devices.
Definition: Pool.h:80
Definition: Storage.h:240
std::map< std::string, const Devicegraph * > get_devicegraphs() const
Get all devicegraphs with their names.
Pool * get_pool(const std::string &name)
Return a pool by name.
Other storage subsystems are activated automatically, e.g.
Definition: Storage.h:92
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:60