libstorage-ng
Md.h
1 /*
2  * Copyright (c) [2016-2018] 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 
77  MdUser* add_device(BlkDevice* blk_device);
78 
82  void remove_device(BlkDevice* blk_device);
83 
84  std::vector<BlkDevice*> get_devices();
85  std::vector<const BlkDevice*> get_devices() const;
86 
90  bool is_numeric() const;
91 
97  unsigned int get_number() const;
98 
99  MdLevel get_md_level() const;
100  void set_md_level(MdLevel md_level);
101 
106  MdParity get_md_parity() const;
107 
112  void set_md_parity(MdParity md_parity);
113 
121  std::vector<MdParity> get_allowed_md_parities() const;
122 
123  unsigned long get_chunk_size() const;
124  void set_chunk_size(unsigned long chunk_size);
125 
126  const std::string& get_uuid() const;
127 
132  const std::string& get_metadata() const;
133 
137  void set_metadata(const std::string& metadata);
138 
144  unsigned int minimal_number_of_devices() const;
145 
150  bool is_in_etc_mdadm() const;
151 
155  void set_in_etc_mdadm(bool in_etc_mdadm);
156 
160  static std::vector<Md*> get_all(Devicegraph* devicegraph);
161 
165  static std::vector<const Md*> get_all(const Devicegraph* devicegraph);
166 
170  static std::vector<Md*> get_all_if(Devicegraph* devicegraph,
171  std::function<bool(const Md*)> pred);
172 
176  static std::vector<const Md*> get_all_if(const Devicegraph* devicegraph,
177  std::function<bool(const Md*)> pred);
178 
185  static Md* find_by_name(Devicegraph* devicegraph, const std::string& name);
186 
190  static const Md* find_by_name(const Devicegraph* devicegraph, const std::string& name);
191 
195  static std::string find_free_numeric_name(const Devicegraph* devicegraph);
196 
202  static bool compare_by_number(const Md* lhs, const Md* rhs);
203 
204  public:
205 
206  class Impl;
207 
208  Impl& get_impl();
209  const Impl& get_impl() const;
210 
211  virtual Md* clone() const override;
212 
213  protected:
214 
215  Md(Impl* impl);
216 
217  };
218 
219 
220  bool is_md(const Device* device);
221 
228  Md* to_md(Device* device);
229 
233  const Md* to_md(const Device* device);
234 
235 }
236 
237 #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.
static std::vector< Md * > get_all(Devicegraph *devicegraph)
Get all Mds.
MdUser * add_device(BlkDevice *blk_device)
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:41
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:40
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.
static Md * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Md by its name.