libstorage-ng
Md.h
1 /*
2  * Copyright (c) [2016-2020] SUSE LLC
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 
23 #ifndef STORAGE_MD_H
24 #define STORAGE_MD_H
25 
26 
27 #include <functional>
28 
29 #include "storage/Devices/Partitionable.h"
30 
31 
32 namespace storage
33 {
34 
35  class MdUser;
36 
37 
41  enum class MdLevel
42  {
43  UNKNOWN, RAID0, RAID1, RAID4, RAID5, RAID6, RAID10, CONTAINER
44  };
45 
46 
50  enum class MdParity
51  {
52  DEFAULT, LEFT_ASYMMETRIC, LEFT_SYMMETRIC, RIGHT_ASYMMETRIC,
53  RIGHT_SYMMETRIC, FIRST, LAST, LEFT_ASYMMETRIC_6, LEFT_SYMMETRIC_6,
54  RIGHT_ASYMMETRIC_6, RIGHT_SYMMETRIC_6, FIRST_6, NEAR_2, OFFSET_2,
55  FAR_2, NEAR_3, OFFSET_3, FAR_3
56  };
57 
58 
64  std::string get_md_level_name(MdLevel md_level);
65 
66 
72  std::string get_md_parity_name(MdParity md_parity);
73 
74 
78  class Md : public Partitionable
79  {
80  public:
81 
91  static Md* create(Devicegraph* devicegraph, const std::string& name);
92 
93  static Md* load(Devicegraph* devicegraph, const xmlNode* node);
94 
103  MdUser* add_device(BlkDevice* blk_device);
104 
108  void remove_device(BlkDevice* blk_device);
109 
114  std::vector<BlkDevice*> get_devices();
115 
119  std::vector<const BlkDevice*> get_devices() const;
120 
124  bool is_numeric() const;
125 
131  unsigned int get_number() const;
132 
139 
145  void set_md_level(MdLevel md_level);
146 
154 
161  void set_md_parity(MdParity md_parity);
162 
170  std::vector<MdParity> get_allowed_md_parities() const;
171 
172  unsigned long get_chunk_size() const;
173  void set_chunk_size(unsigned long chunk_size);
174 
178  const std::string& get_uuid() const;
179 
184  void set_uuid(const std::string& uuid);
185 
190  const std::string& get_metadata() const;
191 
195  void set_metadata(const std::string& metadata);
196 
202  unsigned int minimal_number_of_devices() const;
203 
209 
215 
220  bool is_in_etc_mdadm() const;
221 
225  void set_in_etc_mdadm(bool in_etc_mdadm);
226 
230  static std::vector<Md*> get_all(Devicegraph* devicegraph);
231 
235  static std::vector<const Md*> get_all(const Devicegraph* devicegraph);
236 
240  static std::vector<Md*> get_all_if(Devicegraph* devicegraph,
241  std::function<bool(const Md*)> pred);
242 
246  static std::vector<const Md*> get_all_if(const Devicegraph* devicegraph,
247  std::function<bool(const Md*)> pred);
248 
255  static Md* find_by_name(Devicegraph* devicegraph, const std::string& name);
256 
260  static const Md* find_by_name(const Devicegraph* devicegraph, const std::string& name);
261 
268  static std::string find_free_numeric_name(const Devicegraph* devicegraph);
269 
277  static bool compare_by_number(const Md* lhs, const Md* rhs);
278 
279  public:
280 
281  class Impl;
282 
283  Impl& get_impl();
284  const Impl& get_impl() const;
285 
286  virtual Md* clone() const override;
287 
288  protected:
289 
290  Md(Impl* impl);
291 
292  };
293 
294 
300  bool is_md(const Device* device);
301 
308  Md* to_md(Device* device);
309 
313  const Md* to_md(const Device* device);
314 
315 }
316 
317 #endif
storage::Md::compare_by_number
static bool compare_by_number(const Md *lhs, const Md *rhs)
Compare (less than) two Mds by number.
storage::Md::is_numeric
bool is_numeric() const
Returns true if the name of the MD is numeric.
storage::Md::supports_spare_devices
bool supports_spare_devices() const
Return whether the RAID supports spare devices.
storage::Partitionable
Definition: Partitionable.h:40
storage::Md::get_number
unsigned int get_number() const
Returns the number of the MD.
storage::Md
A MD device.
Definition: Md.h:79
storage::Md::supports_journal_device
bool supports_journal_device() const
Return whether the RAID supports a journal device.
storage::Md::find_by_name
static const Md * find_by_name(const Devicegraph *devicegraph, const std::string &name)
Find a Md by its name.
storage::Md::minimal_number_of_devices
unsigned int minimal_number_of_devices() const
Return the minimal number of devices required by the RAID (without spare and journal devices).
storage::Md::get_md_level
MdLevel get_md_level() const
Get the MD RAID level.
storage::Md::add_device
MdUser * add_device(BlkDevice *blk_device)
Add another device to a RAID.
storage::MdUser
Holder from a BlkDevice to an Md.
Definition: MdUser.h:39
storage::Md::get_uuid
const std::string & get_uuid() const
Get the UUID.
storage::Md::set_in_etc_mdadm
void set_in_etc_mdadm(bool in_etc_mdadm)
Set whether the MD RAID will be present in /etc/mdadm.conf.
storage::Md::get_allowed_md_parities
std::vector< MdParity > get_allowed_md_parities() const
Get the allowed parities for the MD RAID.
storage::get_md_level_name
std::string get_md_level_name(MdLevel md_level)
Convert the MD RAID level md_level to a string.
storage
The storage namespace.
Definition: Actiongraph.h:39
storage::Md::set_md_level
void set_md_level(MdLevel md_level)
Set the MD RAID level.
storage::Md::get_all
static std::vector< const Md * > get_all(const Devicegraph *devicegraph)
Get all Mds.
storage::Md::get_all
static std::vector< Md * > get_all(Devicegraph *devicegraph)
Get all Mds.
storage::Md::is_in_etc_mdadm
bool is_in_etc_mdadm() const
Query whether the MD RAID is present (probed devicegraph) or will be present (staging devicegraph) in...
storage::get_md_parity_name
std::string get_md_parity_name(MdParity md_parity)
Convert the MD parity algorithm md_parity to a string.
storage::Md::get_all_if
static std::vector< Md * > get_all_if(Devicegraph *devicegraph, std::function< bool(const Md *)> pred)
Get all Mds for which the predicate pred returns true.
storage::BlkDevice
An abstract Block Device.
Definition: BlkDevice.h:47
storage::Md::find_by_name
static Md * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Md by its name.
storage::Devicegraph
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
storage::Md::get_all_if
static std::vector< const Md * > get_all_if(const Devicegraph *devicegraph, std::function< bool(const Md *)> pred)
Get all Mds for which the predicate pred returns true.
storage::Md::create
static Md * create(Devicegraph *devicegraph, const std::string &name)
Create a MD in devicegraph with name.
storage::Md::set_uuid
void set_uuid(const std::string &uuid)
Set UUID for testing purposes.
storage::Md::get_devices
std::vector< BlkDevice * > get_devices()
Return devices used for the MD RAID.
storage::Md::set_md_parity
void set_md_parity(MdParity md_parity)
Set the parity of the MD RAID.
storage::Md::find_free_numeric_name
static std::string find_free_numeric_name(const Devicegraph *devicegraph)
Find a free numeric name for a MD, e.g.
storage::Md::remove_device
void remove_device(BlkDevice *blk_device)
storage::MdLevel
MdLevel
MD RAID levels.
Definition: Md.h:42
storage::Device
An abstract base class for storage devices.
Definition: Device.h:82
storage::Md::get_md_parity
MdParity get_md_parity() const
Get the parity of the MD RAID.
storage::Md::get_metadata
const std::string & get_metadata() const
A string like "1.0" or "1.2" for Linux RAID, "imsm" or "ddf" for BIOS RAID containers and empty for B...
storage::to_md
Md * to_md(Device *device)
Converts pointer to Device to pointer to Md.
storage::MdParity
MdParity
MD parity algorithms for RAID5, RAID6 and RAID10.
Definition: Md.h:51
storage::is_md
bool is_md(const Device *device)
Checks whether device points to a Md.
storage::Md::set_metadata
void set_metadata(const std::string &metadata)
Currently only creating metadata 1.0 is supported.
storage::Md::get_devices
std::vector< const BlkDevice * > get_devices() const
Return devices used for the MD RAID.