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 
38  enum class MdLevel {
39  UNKNOWN, RAID0, RAID1, RAID4, RAID5, RAID6, RAID10, CONTAINER
40  };
41 
42 
43  enum class MdParity {
44  DEFAULT, LEFT_ASYMMETRIC, LEFT_SYMMETRIC, RIGHT_ASYMMETRIC,
45  RIGHT_SYMMETRIC, FIRST, LAST, LEFT_ASYMMETRIC_6, LEFT_SYMMETRIC_6,
46  RIGHT_ASYMMETRIC_6, RIGHT_SYMMETRIC_6, FIRST_6, NEAR_2, OFFSET_2,
47  FAR_2, NEAR_3, OFFSET_3, FAR_3
48  };
49 
50 
51  std::string get_md_level_name(MdLevel md_level);
52 
53  std::string get_md_parity_name(MdParity md_parity);
54 
55 
59  class Md : public Partitionable
60  {
61  public:
62 
70  static Md* create(Devicegraph* devicegraph, const std::string& name);
71 
72  static Md* load(Devicegraph* devicegraph, const xmlNode* node);
73 
82  MdUser* add_device(BlkDevice* blk_device);
83 
87  void remove_device(BlkDevice* blk_device);
88 
93  std::vector<BlkDevice*> get_devices();
94 
98  std::vector<const BlkDevice*> get_devices() const;
99 
103  bool is_numeric() const;
104 
110  unsigned int get_number() const;
111 
112  MdLevel get_md_level() const;
113  void set_md_level(MdLevel md_level);
114 
119  MdParity get_md_parity() const;
120 
125  void set_md_parity(MdParity md_parity);
126 
134  std::vector<MdParity> get_allowed_md_parities() const;
135 
136  unsigned long get_chunk_size() const;
137  void set_chunk_size(unsigned long chunk_size);
138 
139  const std::string& get_uuid() const;
140 
145  void set_uuid(const std::string& uuid);
146 
151  const std::string& get_metadata() const;
152 
156  void set_metadata(const std::string& metadata);
157 
163  unsigned int minimal_number_of_devices() const;
164 
169  bool is_in_etc_mdadm() const;
170 
174  void set_in_etc_mdadm(bool in_etc_mdadm);
175 
179  static std::vector<Md*> get_all(Devicegraph* devicegraph);
180 
184  static std::vector<const Md*> get_all(const Devicegraph* devicegraph);
185 
189  static std::vector<Md*> get_all_if(Devicegraph* devicegraph,
190  std::function<bool(const Md*)> pred);
191 
195  static std::vector<const Md*> get_all_if(const Devicegraph* devicegraph,
196  std::function<bool(const Md*)> pred);
197 
204  static Md* find_by_name(Devicegraph* devicegraph, const std::string& name);
205 
209  static const Md* find_by_name(const Devicegraph* devicegraph, const std::string& name);
210 
214  static std::string find_free_numeric_name(const Devicegraph* devicegraph);
215 
221  static bool compare_by_number(const Md* lhs, const Md* rhs);
222 
223  public:
224 
225  class Impl;
226 
227  Impl& get_impl();
228  const Impl& get_impl() const;
229 
230  virtual Md* clone() const override;
231 
232  protected:
233 
234  Md(Impl* impl);
235 
236  };
237 
238 
239  bool is_md(const Device* device);
240 
247  Md* to_md(Device* device);
248 
252  const Md* to_md(const Device* device);
253 
254 }
255 
256 #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.
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.
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:59
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.
unsigned int get_number() const
Returns the number of the MD.
An abstract Block Device.
Definition: BlkDevice.h:44
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
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.
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.
static Md * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Md by its name.