libstorage-ng
Loading...
Searching...
No Matches
Storage.h
1/*
2 * Copyright (c) [2014-2015] Novell, Inc.
3 * Copyright (c) [2016-2022] 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
43namespace 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
120 virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
121
122 };
123
124
128 class LuksInfo : private boost::noncopyable
129 {
130 public:
131
132 LuksInfo();
133 ~LuksInfo();
134
135 const std::string& get_device_name() const;
136 unsigned long long get_size() const;
137 const std::string& get_dm_table_name() const;
138 bool is_dm_table_name_generated() const;
139 const std::string& get_uuid() const;
140 const std::string& get_label() const;
141
142 public:
143
144 class Impl;
145
146 Impl& get_impl() { return *impl; }
147 const Impl& get_impl() const { return *impl; }
148
149 private:
150
151 const std::unique_ptr<Impl> impl;
152
153 };
154
155
160 {
161 public:
162
163 virtual ~ActivateCallbacksLuks() {}
164
170 virtual std::pair<bool, std::string> luks(const LuksInfo& luks_info, int attempt) const = 0;
171
172 };
173
174
178 class BitlockerInfo : private boost::noncopyable
179 {
180 public:
181
184
185 const std::string& get_device_name() const;
186 unsigned long long get_size() const;
187 const std::string& get_dm_table_name() const;
188 bool is_dm_table_name_generated() const;
189 const std::string& get_uuid() const;
190
191 public:
192
193 class Impl;
194
195 Impl& get_impl() { return *impl; }
196 const Impl& get_impl() const { return *impl; }
197
198 private:
199
200 const std::unique_ptr<Impl> impl;
201
202 };
203
204
209 {
210 public:
211
212 virtual ~ActivateCallbacksV3() {}
213
217 virtual void begin() const {}
218
222 virtual void end() const {}
223
229 virtual std::pair<bool, std::string> bitlocker(const BitlockerInfo& bitlocker_info, int attempt) const = 0;
230
231 };
232
233
234 struct ST_DEPRECATED DeactivateStatus
235 {
236 bool multipath;
237 bool dm_raid;
238 bool md;
239 bool lvm_lv;
240 bool luks;
241 };
242
243
250 {
251 public:
252
254 DeactivateStatusV2(const DeactivateStatusV2& deactivate_status);
255 virtual ~DeactivateStatusV2();
256
257 DeactivateStatusV2& operator=(const DeactivateStatusV2& deactivate_status);
258
259 bool multipath() const;
260 bool dm_raid() const;
261 bool md() const;
262 bool lvm_lv() const;
263 bool luks() const;
264 bool bitlocker() const;
265
266 public:
267
268 class Impl;
269
270 Impl& get_impl() { return *impl; }
271 const Impl& get_impl() const { return *impl; }
272
273 private:
274
275 const std::unique_ptr<Impl> impl;
276
277 };
278
279
281 {
282 public:
283
284 virtual ~ProbeCallbacks() {}
285
286 };
287
288
290 {
291 public:
292
293 virtual ~ProbeCallbacksV2() {}
294
307 virtual bool missing_command(const std::string& message, const std::string& what,
308 const std::string& command, uint64_t used_features) const = 0;
309
310 };
311
312
314 {
315 public:
316
317 virtual ~ProbeCallbacksV3() {}
318
322 virtual void begin() const {}
323
327 virtual void end() const {}
328
329 };
330
331
333 {
334 public:
335
336 virtual ~ProbeCallbacksV4() {}
337
344 virtual bool ambiguity_partition_table_and_filesystem(const std::string& message, const std::string& what,
345 const std::string& name, PtType pt_type,
346 FsType fs_type) const = 0;
347
354 virtual bool ambiguity_partition_table_and_luks(const std::string& message, const std::string& what,
355 const std::string& name, PtType pt_type) const = 0;
356
363 virtual bool ambiguity_partition_table_and_lvm_pv(const std::string& message, const std::string& what,
364 const std::string& name, PtType pt_type) const = 0;
365
374 virtual bool unsupported_partition_table(const std::string& message, const std::string& what,
375 const std::string& name, PtType pt_type) const = 0;
376
385 virtual bool unsupported_filesystem(const std::string& message, const std::string& what,
386 const std::string& name, FsType fs_type) const = 0;
387
388 };
389
390
392 {
393 public:
394
395 virtual ~CheckCallbacks() {}
396
397 virtual void error(const std::string& message) const = 0;
398
399 };
400
401
403 {
404 public:
405
406 virtual ~CommitCallbacks() {}
407
408 };
409
410
412 class Storage : private boost::noncopyable
413 {
414 public:
415
421 Storage(const Environment& environment);
422
423 ~Storage();
424
425 public:
426
427 const Environment& get_environment() const;
428 const Arch& get_arch() const;
429
435 Devicegraph* create_devicegraph(const std::string& name);
436
440 Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
441
447 void remove_devicegraph(const std::string& name);
448
452 void restore_devicegraph(const std::string& name);
453
454 bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
455
459 bool exist_devicegraph(const std::string& name) const;
460
464 std::vector<std::string> get_devicegraph_names() const ST_DEPRECATED;
465
472 std::map<std::string, const Devicegraph*> get_devicegraphs() const;
473
479 Devicegraph* get_devicegraph(const std::string& name);
480
484 const Devicegraph* get_devicegraph(const std::string& name) const;
485
492
498 const Devicegraph* get_staging() const;
499
505 const Devicegraph* get_probed() const;
506
513
519 const Devicegraph* get_system() const;
520
537 void check(const CheckCallbacks* check_callbacks = nullptr) const;
538
543
547 void set_default_mount_by(MountByType default_mount_by);
548
549 const std::string& get_rootprefix() const;
550 void set_rootprefix(const std::string& rootprefix) ST_DEPRECATED;
551
555 std::string prepend_rootprefix(const std::string& mount_point) const;
556
564
581 void activate(const ActivateCallbacks* activate_callbacks) const;
582
586 DeactivateStatus deactivate() const ST_DEPRECATED;
587
602
612 void probe(const ProbeCallbacks* probe_callbacks = nullptr);
613
622 void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
623
632 void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
633
641 void generate_pools(const Devicegraph* devicegraph);
642
648 Pool* create_pool(const std::string& name);
649
655 void remove_pool(const std::string& name);
656
662 void rename_pool(const std::string& old_name, const std::string& new_name);
663
667 bool exists_pool(const std::string& name) const;
668
672 std::vector<std::string> get_pool_names() const ST_DEPRECATED;
673
677 std::map<std::string, Pool*> get_pools();
678
682 std::map<std::string, const Pool*> get_pools() const;
683
689 Pool* get_pool(const std::string& name);
690
694 const Pool* get_pool(const std::string& name) const;
695
696 public:
697
698 class Impl;
699
700 Impl& get_impl() { return *impl; }
701 const Impl& get_impl() const { return *impl; }
702
703 private:
704
705 const std::unique_ptr<Impl> impl;
706
707 };
708
709}
710
711#endif
The actiongraph has all actions including the dependencies among them to get from one devicegraph to ...
Definition: Actiongraph.h:61
Specialized callbacks with a more generic parameter for LUKS activation.
Definition: Storage.h:160
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:209
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:217
virtual void end() const
Called at the end of activation.
Definition: Storage.h:222
Other storage subsystems are activated automatically, e.g.
Definition: Storage.h:97
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:179
Definition: Callbacks.h:34
virtual void message(const std::string &message) const =0
Callback for progress messages.
Definition: Storage.h:392
Definition: Storage.h:403
Definition: CommitOptions.h:32
Provides information whether deactivate_v2() was able to deactivate subsystems.
Definition: Storage.h:250
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
Definition: Environment.h:64
Stores information about a LUKS device.
Definition: Storage.h:129
A pool represents a collection of devices.
Definition: Pool.h:83
Definition: Storage.h:290
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:314
virtual void begin() const
Called at the begin of probing.
Definition: Storage.h:322
virtual void end() const
Called at the end of probing.
Definition: Storage.h:327
Definition: Storage.h:333
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:281
The main entry point to libstorage.
Definition: Storage.h:413
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:39
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:235