libstorage-ng
Loading...
Searching...
No Matches
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
44namespace storage
45{
79 class Environment;
80 class Arch;
81 class Devicegraph;
82 class Actiongraph;
83 class Pool;
84 enum class PtType;
85 enum class FsType;
86 enum class MountByType;
87
88
98 {
99 public:
100
101 virtual ~ActivateCallbacks() {}
102
108 virtual bool multipath(bool looks_like_real_multipath) const = 0;
109
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_dm_table_name() const;
139 bool is_dm_table_name_generated() const;
140 const std::string& get_uuid() const;
141 const std::string& get_label() const;
142
143 public:
144
145 class Impl;
146
147 Impl& get_impl() { return *impl; }
148 const Impl& get_impl() const { return *impl; }
149
150 private:
151
152 const std::unique_ptr<Impl> impl;
153
154 };
155
156
161 {
162 public:
163
164 virtual ~ActivateCallbacksLuks() {}
165
171 virtual std::pair<bool, std::string> luks(const LuksInfo& luks_info, int attempt) const = 0;
172
173 };
174
175
179 class BitlockerInfo : private boost::noncopyable
180 {
181 public:
182
185
186 const std::string& get_device_name() const;
187 unsigned long long get_size() const;
188 const std::string& get_dm_table_name() const;
189 bool is_dm_table_name_generated() const;
190 const std::string& get_uuid() const;
191
192 public:
193
194 class Impl;
195
196 Impl& get_impl() { return *impl; }
197 const Impl& get_impl() const { return *impl; }
198
199 private:
200
201 const std::unique_ptr<Impl> impl;
202
203 };
204
205
210 {
211 public:
212
213 virtual ~ActivateCallbacksV3() {}
214
218 virtual void begin() const {}
219
223 virtual void end() const {}
224
230 virtual std::pair<bool, std::string> bitlocker(const BitlockerInfo& bitlocker_info, int attempt) const = 0;
231
232 };
233
234
235 struct ST_DEPRECATED DeactivateStatus
236 {
237 bool multipath;
238 bool dm_raid;
239 bool md;
240 bool lvm_lv;
241 bool luks;
242 };
243
244
251 {
252 public:
253
255 DeactivateStatusV2(const DeactivateStatusV2& deactivate_status);
256 virtual ~DeactivateStatusV2();
257
258 DeactivateStatusV2& operator=(const DeactivateStatusV2& deactivate_status);
259
260 bool multipath() const;
261 bool dm_raid() const;
262 bool md() const;
263 bool lvm_lv() const;
264 bool luks() const;
265 bool bitlocker() const;
266
267 public:
268
269 class Impl;
270
271 Impl& get_impl() { return *impl; }
272 const Impl& get_impl() const { return *impl; }
273
274 private:
275
276 const std::unique_ptr<Impl> impl;
277
278 };
279
280
282 {
283 public:
284
285 virtual ~ProbeCallbacks() {}
286
287 };
288
289
291 {
292 public:
293
294 virtual ~ProbeCallbacksV2() {}
295
308 virtual bool missing_command(const std::string& message, const std::string& what,
309 const std::string& command, uint64_t used_features) const = 0;
310
311 };
312
313
315 {
316 public:
317
318 virtual ~ProbeCallbacksV3() {}
319
323 virtual void begin() const {}
324
328 virtual void end() const {}
329
330 };
331
332
334 {
335 public:
336
337 virtual ~ProbeCallbacksV4() {}
338
345 virtual bool ambiguity_partition_table_and_filesystem(const std::string& message, const std::string& what,
346 const std::string& name, PtType pt_type,
347 FsType fs_type) const = 0;
348
355 virtual bool ambiguity_partition_table_and_luks(const std::string& message, const std::string& what,
356 const std::string& name, PtType pt_type) const = 0;
357
364 virtual bool ambiguity_partition_table_and_lvm_pv(const std::string& message, const std::string& what,
365 const std::string& name, PtType pt_type) const = 0;
366
375 virtual bool unsupported_partition_table(const std::string& message, const std::string& what,
376 const std::string& name, PtType pt_type) const = 0;
377
386 virtual bool unsupported_filesystem(const std::string& message, const std::string& what,
387 const std::string& name, FsType fs_type) const = 0;
388
389 };
390
391
393 {
394 public:
395
396 virtual ~CheckCallbacks() {}
397
398 virtual void error(const std::string& message) const = 0;
399
400 };
401
402
404 {
405 public:
406
407 virtual ~CommitCallbacks() {}
408
409 };
410
411
413 {
414 public:
415
419 virtual void begin() const {}
420
424 virtual void end() const {}
425
429 virtual void begin_action(const Action::Base* action) const {}
430
434 virtual void end_action(const Action::Base* action) const {}
435
436 virtual ~CommitCallbacksV2() {}
437
438 };
439
440
442 class Storage : private boost::noncopyable
443 {
444 public:
445
451 Storage(const Environment& environment);
452
453 ~Storage();
454
455 public:
456
457 const Environment& get_environment() const;
458 const Arch& get_arch() const;
459
465 Devicegraph* create_devicegraph(const std::string& name);
466
470 Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
471
477 void remove_devicegraph(const std::string& name);
478
482 void restore_devicegraph(const std::string& name);
483
484 bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
485
489 bool exist_devicegraph(const std::string& name) const;
490
494 std::vector<std::string> get_devicegraph_names() const ST_DEPRECATED;
495
502 std::map<std::string, const Devicegraph*> get_devicegraphs() const;
503
509 Devicegraph* get_devicegraph(const std::string& name);
510
514 const Devicegraph* get_devicegraph(const std::string& name) const;
515
522
528 const Devicegraph* get_staging() const;
529
535 const Devicegraph* get_probed() const;
536
543
549 const Devicegraph* get_system() const;
550
567 void check(const CheckCallbacks* check_callbacks = nullptr) const;
568
573
577 void set_default_mount_by(MountByType default_mount_by);
578
579 const std::string& get_rootprefix() const;
580 void set_rootprefix(const std::string& rootprefix) ST_DEPRECATED;
581
585 std::string prepend_rootprefix(const std::string& mount_point) const;
586
594
611 void activate(const ActivateCallbacks* activate_callbacks) const;
612
616 DeactivateStatus deactivate() const ST_DEPRECATED;
617
632
642 void probe(const ProbeCallbacks* probe_callbacks = nullptr);
643
652 void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
653
662 void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
663
671 void generate_pools(const Devicegraph* devicegraph);
672
678 Pool* create_pool(const std::string& name);
679
685 void remove_pool(const std::string& name);
686
692 void rename_pool(const std::string& old_name, const std::string& new_name);
693
697 bool exists_pool(const std::string& name) const;
698
702 std::vector<std::string> get_pool_names() const ST_DEPRECATED;
703
707 std::map<std::string, Pool*> get_pools();
708
712 std::map<std::string, const Pool*> get_pools() const;
713
719 Pool* get_pool(const std::string& name);
720
724 const Pool* get_pool(const std::string& name) const;
725
726 public:
727
728 class Impl;
729
730 Impl& get_impl() { return *impl; }
731 const Impl& get_impl() const { return *impl; }
732
733 private:
734
735 const std::unique_ptr<Impl> impl;
736
737 };
738
739}
740
741#endif
The actiongraph has all actions including the dependencies among them to get from one devicegraph to ...
Definition: Actiongraph.h:62
Specialized callbacks with a more generic parameter for LUKS activation.
Definition: Storage.h:161
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
virtual std::pair< bool, std::string > bitlocker(const BitlockerInfo &bitlocker_info, int attempt) const =0
Decide whether the BitLocker should be activated.
virtual void begin() const
Called at the begin of activation.
Definition: Storage.h:218
virtual void end() const
Called at the end of activation.
Definition: Storage.h:223
Other storage subsystems are activated automatically, e.g.
Definition: Storage.h:98
virtual bool multipath(bool looks_like_real_multipath) const =0
Decide whether multipath should be activated.
virtual std::pair< bool, std::string > luks(const std::string &uuid, int attempt) const =0
Decide whether the LUKS with uuid should be activated.
Definition: Arch.h:36
Stores information about a Bitlocker device.
Definition: Storage.h:180
Definition: Callbacks.h:34
virtual void message(const std::string &message) const =0
Callback for progress messages.
Definition: Storage.h:393
Definition: Storage.h:413
virtual void end_action(const Action::Base *action) const
Called at the end of commit of a single action.
Definition: Storage.h:434
virtual void begin_action(const Action::Base *action) const
Called at the begin of commit of a single action.
Definition: Storage.h:429
virtual void end() const
Called at the end of commit.
Definition: Storage.h:424
virtual void begin() const
Called at the begin of commit.
Definition: Storage.h:419
Definition: Storage.h:404
Definition: CommitOptions.h:32
Provides information whether deactivate_v2() was able to deactivate subsystems.
Definition: Storage.h:251
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
Definition: Environment.h:64
Stores information about a LUKS device.
Definition: Storage.h:130
A pool represents a collection of devices.
Definition: Pool.h:83
Definition: Storage.h:291
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.
Definition: Storage.h:315
virtual void begin() const
Called at the begin of probing.
Definition: Storage.h:323
virtual void end() const
Called at the end of probing.
Definition: Storage.h:328
Definition: Storage.h:334
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 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.
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.
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.
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....
Definition: Storage.h:282
The main entry point to libstorage.
Definition: Storage.h:443
void remove_pool(const std::string &name)
Remove a pool by name.
std::vector< std::string > get_devicegraph_names() const ST_DEPRECATED
Get the names of all devicegraphs.
MountByType get_default_mount_by() const
Query the default mount-by method.
Devicegraph * get_staging()
Return the staging devicegraph.
Pool * create_pool(const std::string &name)
Create a pool with name.
void generate_pools(const Devicegraph *devicegraph)
Generate pools, e.g.
Pool * get_pool(const std::string &name)
Return a pool by name.
const Actiongraph * calculate_actiongraph()
The actiongraph is only valid until either the probed or staging devicegraph is modified.
void restore_devicegraph(const std::string &name)
bool exists_pool(const std::string &name) const
Check whether a pool exists by name.
std::map< std::string, const Devicegraph * > get_devicegraphs() const
Get all devicegraphs with their names.
bool exist_devicegraph(const std::string &name) const
Check whether a devicegraph exists by name.
void rename_pool(const std::string &old_name, const std::string &new_name)
Rename a pool.
DeactivateStatusV2 deactivate_v2() const
Deactivate devices like multipath, DM and MD RAID, LVM and LUKS.
void set_default_mount_by(MountByType default_mount_by)
Set the default mount-by method.
std::string prepend_rootprefix(const std::string &mount_point) const
Prepends the root prefix to a mount point if necessary.
void check(const CheckCallbacks *check_callbacks=nullptr) const
Checks all devicegraphs.
Storage(const Environment &environment)
Construct Storage object.
void commit(const CommitOptions &commit_options, const CommitCallbacks *commit_callbacks=nullptr)
The actiongraph must be valid.
Devicegraph * get_system()
Return the system devicegraph.
void activate(const ActivateCallbacks *activate_callbacks) const
Activate devices like multipath, DM and MD RAID, LVM and LUKS.
Devicegraph * copy_devicegraph(const std::string &source_name, const std::string &dest_name)
Devicegraph * get_devicegraph(const std::string &name)
Return a devicegraph by name.
const Devicegraph * get_probed() const
Return the probed devicegraph.
Devicegraph * create_devicegraph(const std::string &name)
Create a devicegraph with name.
std::map< std::string, Pool * > get_pools()
Get all pools with their names.
DeactivateStatus deactivate() const ST_DEPRECATED
void probe(const ProbeCallbacks *probe_callbacks=nullptr)
Probe the system and replace the probed, system and staging devicegraphs.
void remove_devicegraph(const std::string &name)
Remove a devicegraph by name.
std::vector< std::string > get_pool_names() const ST_DEPRECATED
Get the names of all pools.
The storage namespace.
Definition: Actiongraph.h:40
PtType
Partition Table Type.
Definition: PartitionTable.h:42
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:60
Definition: Storage.h:236