libstorage-ng
Md.h
1 /*
2  * Copyright (c) [2016-2017] 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 
102  MdParity get_md_parity() const;
103  void set_md_parity(MdParity md_parity);
104 
105  unsigned long get_chunk_size() const;
106  void set_chunk_size(unsigned long chunk_size);
107 
108  const std::string& get_uuid() const;
109 
114  const std::string& get_metadata() const;
115 
119  void set_metadata(const std::string& metadata);
120 
126  unsigned int minimal_number_of_devices() const;
127 
132  bool is_in_etc_mdadm() const;
133 
137  void set_in_etc_mdadm(bool in_etc_mdadm);
138 
142  static std::vector<Md*> get_all(Devicegraph* devicegraph);
143 
147  static std::vector<const Md*> get_all(const Devicegraph* devicegraph);
148 
152  static std::vector<Md*> get_all_if(Devicegraph* devicegraph,
153  std::function<bool(const Md*)> pred);
154 
158  static std::vector<const Md*> get_all_if(const Devicegraph* devicegraph,
159  std::function<bool(const Md*)> pred);
160 
167  static Md* find_by_name(Devicegraph* devicegraph, const std::string& name);
168 
172  static const Md* find_by_name(const Devicegraph* devicegraph, const std::string& name);
173 
177  static std::string find_free_numeric_name(const Devicegraph* devicegraph);
178 
184  static bool compare_by_number(const Md* lhs, const Md* rhs);
185 
186  public:
187 
188  class Impl;
189 
190  Impl& get_impl();
191  const Impl& get_impl() const;
192 
193  virtual Md* clone() const override;
194 
195  protected:
196 
197  Md(Impl* impl);
198 
199  };
200 
201 
202  bool is_md(const Device* device);
203 
210  Md* to_md(Device* device);
211 
215  const Md* to_md(const Device* device);
216 
217 }
218 
219 #endif
bool is_in_etc_mdadm() const
Query whether the MD RAID is present (probed devicegraph) or will be present (staging devicegraph) in...
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.
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)
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.