libstorage-ng
Storage.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2020] 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 <utility>
31 #include <memory>
32 #include <boost/noncopyable.hpp>
33 
34 #include "storage/Filesystems/Mountable.h"
35 #include "storage/CommitOptions.h"
36 #include "storage/Utils/Callbacks.h"
37 
38 
39 namespace storage
40 {
74  class Environment;
75  class Arch;
76  class Devicegraph;
77  class Actiongraph;
78 
79 
88  class ActivateCallbacks : public Callbacks
89  {
90  public:
91 
92  virtual ~ActivateCallbacks() {}
93 
99  virtual bool multipath(bool looks_like_real_multipath) const = 0;
100 
113  virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
114 
115  };
116 
117 
118  class LuksInfo;
119 
120 
125  {
126  public:
127 
128  virtual ~ActivateCallbacksLuks() {}
129 
135  virtual std::pair<bool, std::string> luks(const LuksInfo& info, int attempt) const = 0;
136 
137  };
138 
139 
143  class LuksInfo : private boost::noncopyable
144  {
145  public:
146 
147  LuksInfo();
148 
149  ~LuksInfo();
150 
151  const std::string& get_device_name() const;
152 
153  const std::string& get_uuid() const;
154 
155  const std::string& get_label() const;
156 
157  public:
158 
159  class Impl;
160 
161  Impl& get_impl() { return *impl; }
162  const Impl& get_impl() const { return *impl; }
163 
164  private:
165 
166  const std::unique_ptr<Impl> impl;
167  };
168 
169 
176  {
177  bool multipath;
178  bool dm_raid;
179  bool md;
180  bool lvm_lv;
181  bool luks;
182  // TODO add bcache?
183  };
184 
185 
186  class ProbeCallbacks : public Callbacks
187  {
188  public:
189 
190  virtual ~ProbeCallbacks() {}
191 
192  };
193 
194 
196  {
197  public:
198 
199  virtual ~ProbeCallbacksV2() {}
200 
213  virtual bool missing_command(const std::string& message, const std::string& what,
214  const std::string& command, uint64_t used_features) const = 0;
215 
216  };
217 
218 
220  {
221  public:
222 
223  virtual ~ProbeCallbacksV3() {}
224 
228  virtual void begin() const {}
229 
233  virtual void end() const {}
234 
235  };
236 
237 
239  {
240  public:
241 
242  virtual ~CheckCallbacks() {}
243 
244  virtual void error(const std::string& message) const = 0;
245 
246  };
247 
248 
249  class CommitCallbacks : public Callbacks
250  {
251  public:
252 
253  virtual ~CommitCallbacks() {}
254 
255  };
256 
257 
259  class Storage : private boost::noncopyable
260  {
261  public:
262 
268  Storage(const Environment& environment);
269 
270  ~Storage();
271 
272  public:
273 
274  const Environment& get_environment() const;
275  const Arch& get_arch() const;
276 
280  Devicegraph* create_devicegraph(const std::string& name);
281 
285  Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
286 
290  void remove_devicegraph(const std::string& name);
291 
295  void restore_devicegraph(const std::string& name);
296 
297  bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
298 
299  bool exist_devicegraph(const std::string& name) const;
300  std::vector<std::string> get_devicegraph_names() const;
301 
307  Devicegraph* get_devicegraph(const std::string& name);
308 
314  const Devicegraph* get_devicegraph(const std::string& name) const;
315 
322 
328  const Devicegraph* get_staging() const;
329 
335  const Devicegraph* get_probed() const;
336 
343 
349  const Devicegraph* get_system() const;
350 
367  void check(const CheckCallbacks* check_callbacks = nullptr) const;
368 
373 
377  void set_default_mount_by(MountByType default_mount_by);
378 
379  const std::string& get_rootprefix() const;
380  void set_rootprefix(const std::string& rootprefix);
381 
385  std::string prepend_rootprefix(const std::string& mount_point) const;
386 
394 
411  void activate(const ActivateCallbacks* activate_callbacks) const;
412 
427 
437  void probe(const ProbeCallbacks* probe_callbacks = nullptr);
438 
447  void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
448 
457  void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
458 
459  public:
460 
461  class Impl;
462 
463  Impl& get_impl() { return *impl; }
464  const Impl& get_impl() const { return *impl; }
465 
466  private:
467 
468  const std::unique_ptr<Impl> impl;
469 
470  };
471 
472 }
473 
474 #endif
Provides information whether deactivate() was able to deactivate subsystems.
Definition: Storage.h:175
Definition: Environment.h:52
void probe(const ProbeCallbacks *probe_callbacks=nullptr)
Probe the system and replace the probed, system and staging devicegraphs.
MountByType get_default_mount_by() const
Query the default mount-by method.
Definition: Storage.h:219
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.
Storage(const Environment &environment)
Construct Storage object.
void check(const CheckCallbacks *check_callbacks=nullptr) const
Checks all devicegraphs.
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:228
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.
DeactivateStatus deactivate() const
Deactivate devices like multipath, DM and MD RAID, LVM and LUKS.
const Actiongraph * calculate_actiongraph()
The actiongraph is only valid until either the probed or staging devicegraph is modified.
The master container of the libstorage.
Definition: Devicegraph.h:153
Devicegraph * get_devicegraph(const std::string &name)
Return a devicegraph by name.
Definition: Storage.h:249
Definition: Actiongraph.h:55
virtual bool multipath(bool looks_like_real_multipath) const =0
Decide whether multipath should be activated.
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:233
Stores information about a LUKS device.
Definition: Storage.h:143
Definition: Storage.h:195
Devicegraph * get_system()
Return the system devicegraph.
virtual std::pair< bool, std::string > luks(const LuksInfo &info, int attempt) const =0
Decide whether the LUKS should be activated.
Specialized callbacks with a more generic parameter for LUKS activation.
Definition: Storage.h:124
The main entry point to libstorage.
Definition: Storage.h:259
Devicegraph * create_devicegraph(const std::string &name)
Definition: Storage.h:186
The storage namespace.
Definition: Actiongraph.h:37
void remove_devicegraph(const std::string &name)
Definition: Storage.h:238
Other storage subsystems are activated automatically, e.g.
Definition: Storage.h:88
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:55