libstorage-ng
Storage.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2023] 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/Actions/Base.h"
37 #include "storage/Utils/Callbacks.h"
38 #include "storage/Utils/Swig.h"
39 
40 
44 namespace storage
45 {
79  class Environment;
80  class Arch;
81  class Devicegraph;
82  class Actiongraph;
83  class Pool;
84  class SystemInfo;
85  enum class PtType;
86  enum class FsType;
87  enum class MountByType;
88 
89 
99  {
100  public:
101 
102  virtual ~ActivateCallbacks() {}
103 
109  virtual bool multipath(bool looks_like_real_multipath) const = 0;
110 
122  virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
123 
124  };
125 
126 
130  class LuksInfo : private boost::noncopyable
131  {
132  public:
133 
134  LuksInfo();
135  ~LuksInfo();
136 
137  const std::string& get_device_name() const;
138  unsigned long long get_size() const;
139  const std::string& get_dm_table_name() const;
140  bool is_dm_table_name_generated() const;
141  const std::string& get_uuid() const;
142  const std::string& get_label() const;
143 
144  public:
145 
146  class Impl;
147 
148  Impl& get_impl() { return *impl; }
149  const Impl& get_impl() const { return *impl; }
150 
151  private:
152 
153  const std::unique_ptr<Impl> impl;
154 
155  };
156 
157 
162  {
163  public:
164 
165  virtual ~ActivateCallbacksLuks() {}
166 
172  virtual std::pair<bool, std::string> luks(const LuksInfo& luks_info, int attempt) const = 0;
173 
174  };
175 
176 
180  class BitlockerInfo : private boost::noncopyable
181  {
182  public:
183 
184  BitlockerInfo();
185  ~BitlockerInfo();
186 
187  const std::string& get_device_name() const;
188  unsigned long long get_size() const;
189  const std::string& get_dm_table_name() const;
190  bool is_dm_table_name_generated() const;
191  const std::string& get_uuid() const;
192 
193  public:
194 
195  class Impl;
196 
197  Impl& get_impl() { return *impl; }
198  const Impl& get_impl() const { return *impl; }
199 
200  private:
201 
202  const std::unique_ptr<Impl> impl;
203 
204  };
205 
206 
211  {
212  public:
213 
214  virtual ~ActivateCallbacksV3() {}
215 
219  virtual void begin() const {}
220 
224  virtual void end() const {}
225 
231  virtual std::pair<bool, std::string> bitlocker(const BitlockerInfo& bitlocker_info, int attempt) const = 0;
232 
233  };
234 
235 
236  struct ST_DEPRECATED DeactivateStatus
237  {
238  bool multipath;
239  bool dm_raid;
240  bool md;
241  bool lvm_lv;
242  bool luks;
243  };
244 
245 
252  {
253  public:
254 
256  DeactivateStatusV2(const DeactivateStatusV2& deactivate_status);
257  virtual ~DeactivateStatusV2();
258 
259  DeactivateStatusV2& operator=(const DeactivateStatusV2& deactivate_status);
260 
261  bool multipath() const;
262  bool dm_raid() const;
263  bool md() const;
264  bool lvm_lv() const;
265  bool luks() const;
266  bool bitlocker() const;
267 
268  public:
269 
270  class Impl;
271 
272  Impl& get_impl() { return *impl; }
273  const Impl& get_impl() const { return *impl; }
274 
275  private:
276 
277  const std::unique_ptr<Impl> impl;
278 
279  };
280 
281 
282  class ProbeCallbacks : public Callbacks
283  {
284  public:
285 
286  virtual ~ProbeCallbacks() {}
287 
288  };
289 
290 
292  {
293  public:
294 
295  virtual ~ProbeCallbacksV2() {}
296 
309  virtual bool missing_command(const std::string& message, const std::string& what,
310  const std::string& command, uint64_t used_features) const = 0;
311 
312  };
313 
314 
316  {
317  public:
318 
319  virtual ~ProbeCallbacksV3() {}
320 
324  virtual void begin() const {}
325 
329  virtual void end() const {}
330 
331  };
332 
333 
335  {
336  public:
337 
338  virtual ~ProbeCallbacksV4() {}
339 
346  virtual bool ambiguity_partition_table_and_filesystem(const std::string& message, const std::string& what,
347  const std::string& name, PtType pt_type,
348  FsType fs_type) const = 0;
349 
356  virtual bool ambiguity_partition_table_and_luks(const std::string& message, const std::string& what,
357  const std::string& name, PtType pt_type) const = 0;
358 
365  virtual bool ambiguity_partition_table_and_lvm_pv(const std::string& message, const std::string& what,
366  const std::string& name, PtType pt_type) const = 0;
367 
376  virtual bool unsupported_partition_table(const std::string& message, const std::string& what,
377  const std::string& name, PtType pt_type) const = 0;
378 
387  virtual bool unsupported_filesystem(const std::string& message, const std::string& what,
388  const std::string& name, FsType fs_type) const = 0;
389 
390  };
391 
392 
394  {
395  public:
396 
397  virtual ~CheckCallbacks() {}
398 
399  virtual void error(const std::string& message) const = 0;
400 
401  };
402 
403 
404  class CommitCallbacks : public Callbacks
405  {
406  public:
407 
408  virtual ~CommitCallbacks() {}
409 
410  };
411 
412 
414  {
415  public:
416 
420  virtual void begin() const {}
421 
425  virtual void end() const {}
426 
430  virtual void begin_action(const Action::Base* action) const {}
431 
435  virtual void end_action(const Action::Base* action) const {}
436 
437  virtual ~CommitCallbacksV2() {}
438 
439  };
440 
441 
443  class Storage : private boost::noncopyable
444  {
445  public:
446 
452  Storage(const Environment& environment);
453 
454  ~Storage();
455 
456  public:
457 
458  const Environment& get_environment() const;
459 
463  const Arch& get_arch() const;
464 
470  Devicegraph* create_devicegraph(const std::string& name);
471 
475  Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
476 
482  void remove_devicegraph(const std::string& name);
483 
487  void restore_devicegraph(const std::string& name);
488 
489  bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
490 
494  bool exist_devicegraph(const std::string& name) const;
495 
499  std::vector<std::string> get_devicegraph_names() const ST_DEPRECATED;
500 
507  std::map<std::string, const Devicegraph*> get_devicegraphs() const;
508 
514  Devicegraph* get_devicegraph(const std::string& name);
515 
519  const Devicegraph* get_devicegraph(const std::string& name) const;
520 
527 
533  const Devicegraph* get_staging() const;
534 
540  const Devicegraph* get_probed() const;
541 
548 
554  const Devicegraph* get_system() const;
555 
572  void check(const CheckCallbacks* check_callbacks = nullptr) const;
573 
578 
582  void set_default_mount_by(MountByType default_mount_by);
583 
584  const std::string& get_rootprefix() const;
585  void set_rootprefix(const std::string& rootprefix) ST_DEPRECATED;
586 
590  std::string prepend_rootprefix(const std::string& mount_point) const;
591 
599 
616  void activate(const ActivateCallbacks* activate_callbacks) const;
617 
621  DeactivateStatus deactivate() const ST_DEPRECATED;
622 
637 
649  void probe(const ProbeCallbacks* probe_callbacks = nullptr);
650 
660  void probe(SystemInfo& system_info, const ProbeCallbacksV3* probe_callbacks = nullptr);
661 
670  void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
671 
680  void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
681 
689  void generate_pools(const Devicegraph* devicegraph);
690 
696  Pool* create_pool(const std::string& name);
697 
703  void remove_pool(const std::string& name);
704 
710  void rename_pool(const std::string& old_name, const std::string& new_name);
711 
715  bool exists_pool(const std::string& name) const;
716 
720  std::vector<std::string> get_pool_names() const ST_DEPRECATED;
721 
725  std::map<std::string, Pool*> get_pools();
726 
730  std::map<std::string, const Pool*> get_pools() const;
731 
737  Pool* get_pool(const std::string& name);
738 
742  const Pool* get_pool(const std::string& name) const;
743 
744  public:
745 
746  class Impl;
747 
748  Impl& get_impl() { return *impl; }
749  const Impl& get_impl() const { return *impl; }
750 
751  private:
752 
753  const std::unique_ptr<Impl> impl;
754 
755  };
756 
757 }
758 
759 #endif
Provides information whether deactivate_v2() was able to deactivate subsystems.
Definition: Storage.h:251
Definition: Storage.h:236
void remove_pool(const std::string &name)
Remove a pool by name.
Definition: Environment.h:63
std::map< std::string, Pool * > get_pools()
Get all pools with their names.
const Arch & get_arch() const
So far only valid after probing.
void probe(const ProbeCallbacks *probe_callbacks=nullptr)
Probe the system and replace the probed, system and staging devicegraphs.
virtual void end() const
Called at the end of activation.
Definition: Storage.h:224
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: Storage.h:413
Definition: Arch.h:35
Definition: Storage.h:315
virtual void begin() const
Called at the begin of activation.
Definition: Storage.h:219
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.
virtual void begin_action(const Action::Base *action) const
Called at the begin of commit of a single action.
Definition: Storage.h:430
virtual void begin() const
Called at the begin of commit.
Definition: Storage.h:420
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:334
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:324
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.
Stores information about a Bitlocker device.
Definition: Storage.h:180
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.
virtual std::pair< bool, std::string > bitlocker(const BitlockerInfo &bitlocker_info, int attempt) const =0
Decide whether the BitLocker should be activated.
Definition: Storage.h:404
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:61
virtual void end_action(const Action::Base *action) const
Called at the end of commit of a single action.
Definition: Storage.h:435
DeactivateStatus deactivate() const ST_DEPRECATED
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:329
Stores information about a LUKS device.
Definition: Storage.h:130
Definition: Storage.h:291
Devicegraph * get_system()
Return the system devicegraph.
std::vector< std::string > get_devicegraph_names() const ST_DEPRECATED
Get the names of all devicegraphs.
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:161
The main entry point to libstorage.
Definition: Storage.h:443
The SystemInfo class keeps various system information.
Definition: SystemInfo.h:48
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:282
The storage namespace.
Definition: Actiongraph.h:39
virtual void end() const
Called at the end of commit.
Definition: Storage.h:425
DeactivateStatusV2 deactivate_v2() const
Deactivate devices like multipath, DM and MD RAID, LVM and LUKS.
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:393
virtual std::pair< bool, std::string > luks(const LuksInfo &luks_info, int attempt) const =0
Decide whether the LUKS should be activated.
Specialized callbacks with a more generic parameter for Bitlocker activation.
Definition: Storage.h:210
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:98
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:60