libstorage-ng
Storage.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2025] 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 <cstdint>
29 #include <string>
30 #include <vector>
31 #include <map>
32 #include <utility>
33 #include <memory>
34 #include <boost/noncopyable.hpp>
35 
36 #include "storage/CommitOptions.h"
37 #include "storage/Actions/Base.h"
38 #include "storage/Utils/Callbacks.h"
39 #include "storage/Utils/Swig.h"
40 
41 
45 namespace storage
46 {
80  class Environment;
81  class Arch;
82  class Devicegraph;
83  class Actiongraph;
84  class Pool;
85  class SystemInfo;
86  enum class PtType;
87  enum class FsType;
88  enum class MountByType;
89 
90 
100  {
101  public:
102 
103  virtual ~ActivateCallbacks() {}
104 
110  virtual bool multipath(bool looks_like_real_multipath) const = 0;
111 
123  virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
124 
125  };
126 
127 
131  class LuksInfo : private boost::noncopyable
132  {
133  public:
134 
135  LuksInfo();
136  ~LuksInfo();
137 
138  const std::string& get_device_name() const;
139  unsigned long long get_size() const;
140  const std::string& get_dm_table_name() const;
141  bool is_dm_table_name_generated() const;
142  const std::string& get_uuid() const;
143  const std::string& get_label() const;
144 
145  public:
146 
147  class Impl;
148 
149  Impl& get_impl() { return *impl; }
150  const Impl& get_impl() const { return *impl; }
151 
152  private:
153 
154  const std::unique_ptr<Impl> impl;
155 
156  };
157 
158 
163  {
164  public:
165 
166  virtual ~ActivateCallbacksLuks() {}
167 
173  virtual std::pair<bool, std::string> luks(const LuksInfo& luks_info, int attempt) const = 0;
174 
175  };
176 
177 
181  class BitlockerInfo : private boost::noncopyable
182  {
183  public:
184 
185  BitlockerInfo();
186  ~BitlockerInfo();
187 
188  const std::string& get_device_name() const;
189  unsigned long long get_size() const;
190  const std::string& get_dm_table_name() const;
191  bool is_dm_table_name_generated() const;
192  const std::string& get_uuid() const;
193 
194  public:
195 
196  class Impl;
197 
198  Impl& get_impl() { return *impl; }
199  const Impl& get_impl() const { return *impl; }
200 
201  private:
202 
203  const std::unique_ptr<Impl> impl;
204 
205  };
206 
207 
212  {
213  public:
214 
215  virtual ~ActivateCallbacksV3() {}
216 
220  virtual void begin() const {}
221 
225  virtual void end() const {}
226 
232  virtual std::pair<bool, std::string> bitlocker(const BitlockerInfo& bitlocker_info, int attempt) const = 0;
233 
234  };
235 
236 
237  struct ST_DEPRECATED DeactivateStatus
238  {
239  bool multipath;
240  bool dm_raid;
241  bool md;
242  bool lvm_lv;
243  bool luks;
244  };
245 
246 
253  {
254  public:
255 
257  DeactivateStatusV2(const DeactivateStatusV2& deactivate_status);
258  virtual ~DeactivateStatusV2();
259 
260  DeactivateStatusV2& operator=(const DeactivateStatusV2& deactivate_status);
261 
262  bool multipath() const;
263  bool dm_raid() const;
264  bool md() const;
265  bool lvm_lv() const;
266  bool luks() const;
267  bool bitlocker() const;
268 
269  public:
270 
271  class Impl;
272 
273  Impl& get_impl() { return *impl; }
274  const Impl& get_impl() const { return *impl; }
275 
276  private:
277 
278  const std::unique_ptr<Impl> impl;
279 
280  };
281 
282 
283  class ProbeCallbacks : public Callbacks
284  {
285  public:
286 
287  virtual ~ProbeCallbacks() {}
288 
289  };
290 
291 
293  {
294  public:
295 
296  virtual ~ProbeCallbacksV2() {}
297 
310  virtual bool missing_command(const std::string& message, const std::string& what,
311  const std::string& command, uint64_t used_features) const = 0;
312 
313  };
314 
315 
317  {
318  public:
319 
320  virtual ~ProbeCallbacksV3() {}
321 
325  virtual void begin() const {}
326 
330  virtual void end() const {}
331 
332  };
333 
334 
336  {
337  public:
338 
339  virtual ~ProbeCallbacksV4() {}
340 
347  virtual bool ambiguity_partition_table_and_filesystem(const std::string& message, const std::string& what,
348  const std::string& name, PtType pt_type,
349  FsType fs_type) const = 0;
350 
357  virtual bool ambiguity_partition_table_and_luks(const std::string& message, const std::string& what,
358  const std::string& name, PtType pt_type) const = 0;
359 
366  virtual bool ambiguity_partition_table_and_lvm_pv(const std::string& message, const std::string& what,
367  const std::string& name, PtType pt_type) const = 0;
368 
377  virtual bool unsupported_partition_table(const std::string& message, const std::string& what,
378  const std::string& name, PtType pt_type) const = 0;
379 
388  virtual bool unsupported_filesystem(const std::string& message, const std::string& what,
389  const std::string& name, FsType fs_type) const = 0;
390 
391  };
392 
393 
395  {
396  public:
397 
398  virtual ~CheckCallbacks() {}
399 
400  virtual void error(const std::string& message) const = 0;
401 
402  };
403 
404 
405  class CommitCallbacks : public Callbacks
406  {
407  public:
408 
409  virtual ~CommitCallbacks() {}
410 
411  };
412 
413 
415  {
416  public:
417 
421  virtual void begin() const {}
422 
426  virtual void end() const {}
427 
431  virtual void begin_action(const Action::Base* action) const {}
432 
436  virtual void end_action(const Action::Base* action) const {}
437 
438  virtual ~CommitCallbacksV2() {}
439 
440  };
441 
442 
444  class Storage : private boost::noncopyable
445  {
446  public:
447 
453  Storage(const Environment& environment);
454 
455  ~Storage();
456 
457  public:
458 
459  const Environment& get_environment() const;
460 
464  const Arch& get_arch() const;
465 
471  Devicegraph* create_devicegraph(const std::string& name);
472 
476  Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
477 
483  void remove_devicegraph(const std::string& name);
484 
488  void restore_devicegraph(const std::string& name);
489 
490  bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
491 
495  bool exist_devicegraph(const std::string& name) const;
496 
500  std::vector<std::string> get_devicegraph_names() const ST_DEPRECATED;
501 
508  std::map<std::string, const Devicegraph*> get_devicegraphs() const;
509 
515  Devicegraph* get_devicegraph(const std::string& name);
516 
520  const Devicegraph* get_devicegraph(const std::string& name) const;
521 
528 
534  const Devicegraph* get_staging() const;
535 
541  const Devicegraph* get_probed() const;
542 
549 
555  const Devicegraph* get_system() const;
556 
573  void check(const CheckCallbacks* check_callbacks = nullptr) const;
574 
579 
583  void set_default_mount_by(MountByType default_mount_by);
584 
585  const std::string& get_rootprefix() const;
586  void set_rootprefix(const std::string& rootprefix) ST_DEPRECATED;
587 
591  std::string prepend_rootprefix(const std::string& mount_point) const;
592 
602 
619  void activate(const ActivateCallbacks* activate_callbacks) const;
620 
624  DeactivateStatus deactivate() const ST_DEPRECATED;
625 
640 
652  void probe(const ProbeCallbacks* probe_callbacks = nullptr);
653 
663  void probe(SystemInfo& system_info, const ProbeCallbacksV3* probe_callbacks = nullptr);
664 
673  void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
674 
683  void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
684 
692  void generate_pools(const Devicegraph* devicegraph);
693 
699  Pool* create_pool(const std::string& name);
700 
706  void remove_pool(const std::string& name);
707 
713  void rename_pool(const std::string& old_name, const std::string& new_name);
714 
718  bool exists_pool(const std::string& name) const;
719 
723  std::vector<std::string> get_pool_names() const ST_DEPRECATED;
724 
728  std::map<std::string, Pool*> get_pools();
729 
733  std::map<std::string, const Pool*> get_pools() const;
734 
740  Pool* get_pool(const std::string& name);
741 
745  const Pool* get_pool(const std::string& name) const;
746 
747  public:
748 
749  class Impl;
750 
751  Impl& get_impl() { return *impl; }
752  const Impl& get_impl() const { return *impl; }
753 
754  private:
755 
756  const std::unique_ptr<Impl> impl;
757 
758  };
759 
760 }
761 
762 #endif
Provides information whether deactivate_v2() was able to deactivate subsystems.
Definition: Storage.h:252
Definition: Storage.h:237
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:225
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:414
Definition: Arch.h:35
Definition: Storage.h:316
virtual void begin() const
Called at the begin of activation.
Definition: Storage.h:220
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:431
virtual void begin() const
Called at the begin of commit.
Definition: Storage.h:421
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:335
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:325
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:181
PtType
Partition Table Type.
Definition: PartitionTable.h:42
const Actiongraph * calculate_actiongraph()
Calculates the actiongraph including the compound actions.
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:405
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:436
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:330
Stores information about a LUKS device.
Definition: Storage.h:131
Definition: Storage.h:292
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:162
The main entry point to libstorage.
Definition: Storage.h:444
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:283
The storage namespace.
Definition: Actiongraph.h:39
virtual void end() const
Called at the end of commit.
Definition: Storage.h:426
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:394
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:211
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:99
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:60