libstorage-ng
Storage.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_STORAGE_H
25 #define STORAGE_STORAGE_H
26 
27 
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <utility>
32 #include <memory>
33 #include <boost/noncopyable.hpp>
34 
35 #include "storage/CommitOptions.h"
36 #include "storage/Utils/Callbacks.h"
37 #include "storage/Utils/Swig.h"
38 
39 
43 namespace storage
44 {
78  class Environment;
79  class Arch;
80  class Devicegraph;
81  class Actiongraph;
82  class Pool;
83  enum class PtType;
84  enum class FsType;
85  enum class MountByType;
86 
87 
97  {
98  public:
99 
100  virtual ~ActivateCallbacks() {}
101 
107  virtual bool multipath(bool looks_like_real_multipath) const = 0;
108 
121  virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
122 
123  };
124 
125 
129  class LuksInfo : private boost::noncopyable
130  {
131  public:
132 
133  LuksInfo();
134  ~LuksInfo();
135 
136  const std::string& get_device_name() const;
137  unsigned long long get_size() const;
138  const std::string& get_uuid() const;
139  const std::string& get_label() const;
140 
141  public:
142 
143  class Impl;
144 
145  Impl& get_impl() { return *impl; }
146  const Impl& get_impl() const { return *impl; }
147 
148  private:
149 
150  const std::unique_ptr<Impl> impl;
151 
152  };
153 
154 
159  {
160  public:
161 
162  virtual ~ActivateCallbacksLuks() {}
163 
169  virtual std::pair<bool, std::string> luks(const LuksInfo& info, int attempt) const = 0;
170 
171  };
172 
173 
180  {
181  bool multipath;
182  bool dm_raid;
183  bool md;
184  bool lvm_lv;
185  bool luks;
186  // TODO add bcache?
187  };
188 
189 
190  class ProbeCallbacks : public Callbacks
191  {
192  public:
193 
194  virtual ~ProbeCallbacks() {}
195 
196  };
197 
198 
200  {
201  public:
202 
203  virtual ~ProbeCallbacksV2() {}
204 
217  virtual bool missing_command(const std::string& message, const std::string& what,
218  const std::string& command, uint64_t used_features) const = 0;
219 
220  };
221 
222 
224  {
225  public:
226 
227  virtual ~ProbeCallbacksV3() {}
228 
232  virtual void begin() const {}
233 
237  virtual void end() const {}
238 
239  };
240 
241 
243  {
244  public:
245 
246  virtual ~ProbeCallbacksV4() {}
247 
254  virtual bool ambiguity_partition_table_and_filesystem(const std::string& message, const std::string& what,
255  const std::string& name, PtType pt_type,
256  FsType fs_type) const = 0;
257 
264  virtual bool ambiguity_partition_table_and_luks(const std::string& message, const std::string& what,
265  const std::string& name, PtType pt_type) const = 0;
266 
273  virtual bool ambiguity_partition_table_and_lvm_pv(const std::string& message, const std::string& what,
274  const std::string& name, PtType pt_type) const = 0;
275 
284  virtual bool unsupported_partition_table(const std::string& message, const std::string& what,
285  const std::string& name, PtType pt_type) const = 0;
286 
295  virtual bool unsupported_filesystem(const std::string& message, const std::string& what,
296  const std::string& name, FsType fs_type) const = 0;
297 
298  };
299 
300 
302  {
303  public:
304 
305  virtual ~CheckCallbacks() {}
306 
307  virtual void error(const std::string& message) const = 0;
308 
309  };
310 
311 
312  class CommitCallbacks : public Callbacks
313  {
314  public:
315 
316  virtual ~CommitCallbacks() {}
317 
318  };
319 
320 
322  class Storage : private boost::noncopyable
323  {
324  public:
325 
331  Storage(const Environment& environment);
332 
333  ~Storage();
334 
335  public:
336 
337  const Environment& get_environment() const;
338  const Arch& get_arch() const;
339 
345  Devicegraph* create_devicegraph(const std::string& name);
346 
350  Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
351 
357  void remove_devicegraph(const std::string& name);
358 
362  void restore_devicegraph(const std::string& name);
363 
364  bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
365 
369  bool exist_devicegraph(const std::string& name) const;
370 
374  std::vector<std::string> get_devicegraph_names() const ST_DEPRECATED;
375 
382  std::map<std::string, const Devicegraph*> get_devicegraphs() const;
383 
389  Devicegraph* get_devicegraph(const std::string& name);
390 
394  const Devicegraph* get_devicegraph(const std::string& name) const;
395 
402 
408  const Devicegraph* get_staging() const;
409 
415  const Devicegraph* get_probed() const;
416 
423 
429  const Devicegraph* get_system() const;
430 
447  void check(const CheckCallbacks* check_callbacks = nullptr) const;
448 
453 
457  void set_default_mount_by(MountByType default_mount_by);
458 
459  const std::string& get_rootprefix() const;
460  void set_rootprefix(const std::string& rootprefix);
461 
465  std::string prepend_rootprefix(const std::string& mount_point) const;
466 
474 
491  void activate(const ActivateCallbacks* activate_callbacks) const;
492 
507 
517  void probe(const ProbeCallbacks* probe_callbacks = nullptr);
518 
527  void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
528 
537  void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
538 
546  void generate_pools(const Devicegraph* devicegraph);
547 
553  Pool* create_pool(const std::string& name);
554 
560  void remove_pool(const std::string& name);
561 
567  void rename_pool(const std::string& old_name, const std::string& new_name);
568 
572  bool exists_pool(const std::string& name) const;
573 
577  std::vector<std::string> get_pool_names() const ST_DEPRECATED;
578 
582  std::map<std::string, Pool*> get_pools();
583 
587  std::map<std::string, const Pool*> get_pools() const;
588 
594  Pool* get_pool(const std::string& name);
595 
599  const Pool* get_pool(const std::string& name) const;
600 
601  public:
602 
603  class Impl;
604 
605  Impl& get_impl() { return *impl; }
606  const Impl& get_impl() const { return *impl; }
607 
608  private:
609 
610  const std::unique_ptr<Impl> impl;
611 
612  };
613 
614 }
615 
616 #endif
Provides information whether deactivate() was able to deactivate subsystems.
Definition: Storage.h:179
void remove_pool(const std::string &name)
Remove a pool by name.
Definition: Environment.h:62
std::map< std::string, Pool * > get_pools()
Get all pools with their names.
void probe(const ProbeCallbacks *probe_callbacks=nullptr)
Probe the system and replace the probed, system and staging devicegraphs.
virtual bool ambiguity_partition_table_and_luks(const std::string &message, const std::string &what, const std::string &name, PtType pt_type) const =0
This error callback is called when a partition table and a LUKS are found on a device.
MountByType get_default_mount_by() const
Query the default mount-by method.
Definition: CommitOptions.h:31
Definition: Arch.h:35
Definition: Storage.h:223
virtual bool ambiguity_partition_table_and_filesystem(const std::string &message, const std::string &what, const std::string &name, PtType pt_type, FsType fs_type) const =0
This error callback is called when a partition table and a filesystem are found on a device...
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.
Definition: Storage.h:242
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:232
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.
PtType
Partition Table Type.
Definition: PartitionTable.h:42
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:312
void rename_pool(const std::string &old_name, const std::string &new_name)
Rename a pool.
The actiongraph has all actions including the dependencies among them to get from one devicegraph to ...
Definition: Actiongraph.h:60
virtual bool unsupported_filesystem(const std::string &message, const std::string &what, const std::string &name, FsType fs_type) const =0
This error callback is called when a known but unsupported filesystem type, e.g.
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:237
Stores information about a LUKS device.
Definition: Storage.h:129
Definition: Storage.h:199
Devicegraph * get_system()
Return the system devicegraph.
std::vector< std::string > get_devicegraph_names() const ST_DEPRECATED
Get the names of all devicegraphs.
virtual std::pair< bool, std::string > luks(const LuksInfo &info, int attempt) const =0
Decide whether the LUKS should be activated.
Definition: Callbacks.h:33
std::vector< std::string > get_pool_names() const ST_DEPRECATED
Get the names of all pools.
virtual bool unsupported_partition_table(const std::string &message, const std::string &what, const std::string &name, PtType pt_type) const =0
This error callback is called when a known but unsupported partition table type, e.g.
virtual void message(const std::string &message) const =0
Callback for progress messages.
Specialized callbacks with a more generic parameter for LUKS activation.
Definition: Storage.h:158
The main entry point to libstorage.
Definition: Storage.h:322
void generate_pools(const Devicegraph *devicegraph)
Generate pools, e.g.
virtual bool ambiguity_partition_table_and_lvm_pv(const std::string &message, const std::string &what, const std::string &name, PtType pt_type) const =0
This error callback is called when a partition table and a LVM PV are found on a device.
Devicegraph * create_devicegraph(const std::string &name)
Create a devicegraph with name.
Definition: Storage.h:190
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:82
Definition: Storage.h:301
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:96
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:60