libstorage-ng
Md.h
1 /*
2  * Copyright (c) [2016-2019] 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 
62  std::string get_md_level_name(MdLevel md_level);
63 
64 
68  std::string get_md_parity_name(MdParity md_parity);
69 
70 
74  class Md : public Partitionable
75  {
76  public:
77 
85  static Md* create(Devicegraph* devicegraph, const std::string& name);
86 
87  static Md* load(Devicegraph* devicegraph, const xmlNode* node);
88 
97  MdUser* add_device(BlkDevice* blk_device);
98 
102  void remove_device(BlkDevice* blk_device);
103 
108  std::vector<BlkDevice*> get_devices();
109 
113  std::vector<const BlkDevice*> get_devices() const;
114 
118  bool is_numeric() const;
119 
125  unsigned int get_number() const;
126 
130  MdLevel get_md_level() const;
131 
135  void set_md_level(MdLevel md_level);
136 
141  MdParity get_md_parity() const;
142 
147  void set_md_parity(MdParity md_parity);
148 
156  std::vector<MdParity> get_allowed_md_parities() const;
157 
158  unsigned long get_chunk_size() const;
159  void set_chunk_size(unsigned long chunk_size);
160 
161  const std::string& get_uuid() const;
162 
167  void set_uuid(const std::string& uuid);
168 
173  const std::string& get_metadata() const;
174 
178  void set_metadata(const std::string& metadata);
179 
185  unsigned int minimal_number_of_devices() const;
186 
191  bool is_in_etc_mdadm() const;
192 
196  void set_in_etc_mdadm(bool in_etc_mdadm);
197 
201  static std::vector<Md*> get_all(Devicegraph* devicegraph);
202 
206  static std::vector<const Md*> get_all(const Devicegraph* devicegraph);
207 
211  static std::vector<Md*> get_all_if(Devicegraph* devicegraph,
212  std::function<bool(const Md*)> pred);
213 
217  static std::vector<const Md*> get_all_if(const Devicegraph* devicegraph,
218  std::function<bool(const Md*)> pred);
219 
226  static Md* find_by_name(Devicegraph* devicegraph, const std::string& name);
227 
231  static const Md* find_by_name(const Devicegraph* devicegraph, const std::string& name);
232 
236  static std::string find_free_numeric_name(const Devicegraph* devicegraph);
237 
243  static bool compare_by_number(const Md* lhs, const Md* rhs);
244 
245  public:
246 
247  class Impl;
248 
249  Impl& get_impl();
250  const Impl& get_impl() const;
251 
252  virtual Md* clone() const override;
253 
254  protected:
255 
256  Md(Impl* impl);
257 
258  };
259 
260 
266  bool is_md(const Device* device);
267 
274  Md* to_md(Device* device);
275 
279  const Md* to_md(const Device* device);
280 
281 }
282 
283 #endif
bool is_in_etc_mdadm() const
Query whether the MD RAID is present (probed devicegraph) or will be present (staging devicegraph) in...
void set_md_parity(MdParity md_parity)
Set the parity of the MD RAID.
bool is_numeric() const
Returns true if the name of the MD is numeric.
void set_in_etc_mdadm(bool in_etc_mdadm)
Set whether the MD RAID will be present in /etc/mdadm.conf.
std::vector< MdParity > get_allowed_md_parities() const
Get the allowed parities for the MD RAID.
void set_md_level(MdLevel md_level)
Set the MD RAID level.
static Md * create(Devicegraph *devicegraph, const std::string &name)
Create a MD in devicegraph with name.
void set_uuid(const std::string &uuid)
Set uuid for testing purposes.
static std::vector< Md * > get_all(Devicegraph *devicegraph)
Get all Mds.
MdLevel get_md_level() const
Get the MD RAID level.
MdUser * add_device(BlkDevice *blk_device)
Add another device to a RAID.
void remove_device(BlkDevice *blk_device)
MdParity get_md_parity() const
Get the parity of the MD RAID.
const std::string & get_metadata() const
A string like "1.0" for Linux RAID, "imsm" or "ddf" for BIOS RAID containers and empty for BIOS RAID ...
A MD device.
Definition: Md.h:74
The master container of the libstorage.
Definition: Devicegraph.h:153
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.
std::string get_md_level_name(MdLevel md_level)
Convert the MD RAID level md_level to a string.
unsigned int get_number() const
Returns the number of the MD.
An abstract Block Device.
Definition: BlkDevice.h:46
unsigned int minimal_number_of_devices() const
Return the minimal number of devices required by the RAID.
Definition: MdUser.h:33
void set_metadata(const std::string &metadata)
Currently create always uses metadata 1.0.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
std::string get_md_parity_name(MdParity md_parity)
Convert the MD parity algorithm md_parity to a string.
Definition: Partitionable.h:39
static std::string find_free_numeric_name(const Devicegraph *devicegraph)
Find a free numeric name for a MD.
static bool compare_by_number(const Md *lhs, const Md *rhs)
Compare (less than) two Mds by number.
bool is_md(const Device *device)
Checks whether device points to a Md.
MdParity
MD parity algorithms.
Definition: Md.h:50
The storage namespace.
Definition: Actiongraph.h:37
Md * to_md(Device *device)
Converts pointer to Device to pointer to Md.
std::vector< BlkDevice * > get_devices()
Return devices used for the MD RAID.
MdLevel
MD RAID levels.
Definition: Md.h:41
static Md * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Md by its name.