libstorage-ng
LvmVg.h
1 /*
2  * Copyright (c) [2016-2021] 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_LVM_VG_H
24 #define STORAGE_LVM_VG_H
25 
26 
27 #include "storage/Devices/Device.h"
28 #include "storage/Devices/LvmLv.h"
29 #include "storage/Devicegraph.h"
30 
31 
32 namespace storage
33 {
34  class Region;
35  class BlkDevice;
36  class LvmPv;
37  class LvmLv;
38 
39 
41  {
42  public:
43 
44  LvmVgNotFoundByVgName(const std::string& vg_name);
45  };
46 
47 
49  {
50  public:
51 
52  InvalidExtentSize(unsigned long long extent_size) ST_DEPRECATED;
53  InvalidExtentSize(const std::string& msg);
54  };
55 
56 
60  class LvmVg : public Device
61  {
62  public:
63 
69  static LvmVg* create(Devicegraph* devicegraph, const std::string& vg_name);
70 
71  static LvmVg* load(Devicegraph* devicegraph, const xmlNode* node);
72 
76  const std::string& get_vg_name() const;
77 
84  void set_vg_name(const std::string& vg_name);
85 
90  static bool is_valid_vg_name(const std::string& vg_name);
91 
96  const Region& get_region() const;
97 
101  unsigned long long get_size() const;
102 
109  std::string get_size_string() const;
110 
116  unsigned long long get_extent_size() const;
117 
129  void set_extent_size(unsigned long long extent_size);
130 
134  unsigned long long number_of_extents() const;
135 
140  unsigned long long number_of_used_extents() const;
141 
145  unsigned long long number_of_free_extents() const;
146 
151  bool is_overcommitted() const;
152 
160  LvmPv* add_lvm_pv(BlkDevice* blk_device);
161 
168  void remove_lvm_pv(BlkDevice* blk_device);
169 
176  unsigned long long max_size_for_lvm_lv(LvType lv_type) const;
177 
184  LvmLv* create_lvm_lv(const std::string& lv_name, LvType lv_type,
185  unsigned long long size);
186 
187  LvmLv* create_lvm_lv(const std::string& lv_name, unsigned long long size) ST_DEPRECATED;
188 
193  void delete_lvm_lv(LvmLv* lvm_lv);
194 
198  static std::vector<LvmVg*> get_all(Devicegraph* devicegraph);
199 
203  static std::vector<const LvmVg*> get_all(const Devicegraph* devicegraph);
204 
210  static LvmVg* find_by_vg_name(Devicegraph* devicegraph, const std::string& vg_name);
211 
215  static const LvmVg* find_by_vg_name(const Devicegraph* devicegraph, const std::string& vg_name);
216 
220  std::vector<LvmPv*> get_lvm_pvs();
221 
225  std::vector<const LvmPv*> get_lvm_pvs() const;
226 
230  LvmLv* get_lvm_lv(const std::string& lv_name);
231 
238  std::vector<LvmLv*> get_lvm_lvs();
239 
243  std::vector<const LvmLv*> get_lvm_lvs() const;
244 
252  static bool compare_by_vg_name(const LvmVg* lhs, const LvmVg* rhs);
253 
254  public:
255 
256  class Impl;
257 
258  Impl& get_impl();
259  const Impl& get_impl() const;
260 
261  virtual LvmVg* clone() const override;
262 
263  protected:
264 
265  LvmVg(Impl* impl);
266 
267  };
268 
269 
275  bool is_lvm_vg(const Device* device);
276 
283  LvmVg* to_lvm_vg(Device* device);
284 
288  const LvmVg* to_lvm_vg(const Device* device);
289 
290 }
291 
292 #endif
unsigned long long max_size_for_lvm_lv(LvType lv_type) const
Return the max size in bytes for a new logical volume of type lv_type.
std::string get_size_string() const
Returns the size of the volume group as a localised string.
const Region & get_region() const
Get the region of the volume group.
A Logical Volume of the Logical Volume Manager (LVM).
Definition: LvmLv.h:146
std::vector< LvmLv * > get_lvm_lvs()
Get all logical volumes of the volume group that are direct children of the volume group...
static bool is_valid_vg_name(const std::string &vg_name)
Check whether a volume group name is valid.
unsigned long long number_of_used_extents() const
Calculates the number of used extents in the volume group.
const std::string & msg() const
Return the message string provided to the constructor.
Definition: Exception.h:150
A Volume Group of the Logical Volume Manager (LVM).
Definition: LvmVg.h:60
static bool compare_by_vg_name(const LvmVg *lhs, const LvmVg *rhs)
Compare (less than) two LvmVgs by vg-name.
Definition: LvmPv.h:36
A start/length pair with a block size.
Definition: Region.h:84
const std::string & get_vg_name() const
Get volume group name.
void set_extent_size(unsigned long long extent_size)
Set the extent size of the volume group.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
An abstract Block Device.
Definition: BlkDevice.h:48
Definition: LvmVg.h:40
void set_vg_name(const std::string &vg_name)
Set the volume group name.
Definition: LvmVg.h:48
unsigned long long get_extent_size() const
Returns the extent size of the volume group.
LvmPv * add_lvm_pv(BlkDevice *blk_device)
Adds a block device as a physical volume to the volume group.
An abstract base class for storage devices.
Definition: Device.h:81
unsigned long long number_of_extents() const
Returns the number of extents in the volume group.
Definition: Devicegraph.h:49
bool is_overcommitted() const
Check whether the volume group is overcommitted.
static std::vector< LvmVg * > get_all(Devicegraph *devicegraph)
Get all LvmVgs.
LvmLv * create_lvm_lv(const std::string &lv_name, LvType lv_type, unsigned long long size)
Create a logical volume with name lv_name and type lv_type in the volume group.
void delete_lvm_lv(LvmLv *lvm_lv)
Delete a logical volume in the volume group.
void remove_lvm_pv(BlkDevice *blk_device)
Removes a block device from the volume group.
static LvmVg * create(Devicegraph *devicegraph, const std::string &vg_name)
Create a device of type LvmVg.
std::vector< LvmPv * > get_lvm_pvs()
Get all physical volumes of the volume group.
unsigned long long number_of_free_extents() const
Calculates the number of free extents in the volume group.
unsigned long long get_size() const
Returns the size of the volume group in bytes.
Base class for storage exceptions.
Definition: Exception.h:113
LvmLv * get_lvm_lv(const std::string &lv_name)
static LvmVg * find_by_vg_name(Devicegraph *devicegraph, const std::string &vg_name)
Find a volume group by vg-name.
The storage namespace.
Definition: Actiongraph.h:39
bool is_lvm_vg(const Device *device)
Checks whether device points to a LvmVg.
LvmVg * to_lvm_vg(Device *device)
Converts pointer to Device to pointer to LvmVg.
LvType
LVM logical volume types, see lvs(8).
Definition: LvmLv.h:40