libstorage-ng
Storage.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2018] 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 
106  virtual std::pair<bool, std::string> luks(const std::string& uuid, int attempt) const = 0;
107 
108  };
109 
110 
117  {
118  bool multipath;
119  bool dm_raid;
120  bool md;
121  bool lvm_lv;
122  bool luks;
123  };
124 
125 
126  class ProbeCallbacks : public Callbacks
127  {
128  public:
129 
130  virtual ~ProbeCallbacks() {}
131 
132  };
133 
134 
136  {
137  public:
138 
139  virtual ~CheckCallbacks() {}
140 
141  virtual void error(const std::string& message) const = 0;
142 
143  };
144 
145 
146  class CommitCallbacks : public Callbacks
147  {
148  public:
149 
150  virtual ~CommitCallbacks() {}
151 
152  };
153 
154 
156  class Storage : private boost::noncopyable
157  {
158  public:
159 
165  Storage(const Environment& environment);
166 
167  ~Storage();
168 
169  public:
170 
171  const Environment& get_environment() const;
172  const Arch& get_arch() const;
173 
177  Devicegraph* create_devicegraph(const std::string& name);
178 
182  Devicegraph* copy_devicegraph(const std::string& source_name, const std::string& dest_name);
183 
187  void remove_devicegraph(const std::string& name);
188 
192  void restore_devicegraph(const std::string& name);
193 
194  bool equal_devicegraph(const std::string& lhs, const std::string& rhs) const;
195 
196  bool exist_devicegraph(const std::string& name) const;
197  std::vector<std::string> get_devicegraph_names() const;
198 
204  Devicegraph* get_devicegraph(const std::string& name);
205 
211  const Devicegraph* get_devicegraph(const std::string& name) const;
212 
219 
225  const Devicegraph* get_staging() const;
226 
232  const Devicegraph* get_probed() const;
233 
240 
246  const Devicegraph* get_system() const;
247 
264  void check(const CheckCallbacks* check_callbacks = nullptr) const;
265 
270 
274  void set_default_mount_by(MountByType default_mount_by);
275 
276  const std::string& get_rootprefix() const;
277  void set_rootprefix(const std::string& rootprefix);
278 
282  std::string prepend_rootprefix(const std::string& mount_point) const;
283 
291 
308  void activate(const ActivateCallbacks* activate_callbacks) const;
309 
324 
334  void probe(const ProbeCallbacks* probe_callbacks = nullptr);
335 
344  void commit(const CommitOptions& commit_options, const CommitCallbacks* commit_callbacks = nullptr);
345 
354  void commit(const CommitCallbacks* commit_callbacks = nullptr) ST_DEPRECATED;
355 
356  public:
357 
358  class Impl;
359 
360  Impl& get_impl() { return *impl; }
361  const Impl& get_impl() const { return *impl; }
362 
363  private:
364 
365  const std::unique_ptr<Impl> impl;
366 
367  };
368 
369 }
370 
371 #endif
Provides information whether deactivate() was able to deactivate subsystems.
Definition: Storage.h:116
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.
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 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:146
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.
void activate(const ActivateCallbacks *activate_callbacks) const
Activate devices like multipath, DM and MD RAID, LVM and LUKS.
Devicegraph * get_system()
Return the system devicegraph.
The main entry point to libstorage.
Definition: Storage.h:156
Devicegraph * create_devicegraph(const std::string &name)
Definition: Storage.h:126
The storage namespace.
Definition: Actiongraph.h:37
void remove_devicegraph(const std::string &name)
Definition: Storage.h:135
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:54