libstorage-ng
 All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
LvmVg.h
1 /*
2  * Copyright (c) 2016 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/Devicegraph.h"
29 
30 
31 namespace storage
32 {
33  class BlkDevice;
34  class LvmPv;
35  class LvmLv;
36 
37 
39  {
40  LvmVgNotFoundByVgName(const std::string& vg_name);
41  };
42 
43 
44  struct InvalidExtentSize : public Exception
45  {
46  InvalidExtentSize(unsigned long long extent_size);
47  };
48 
49 
53  class LvmVg : public Device
54  {
55  public:
56 
57  static LvmVg* create(Devicegraph* devicegraph, const std::string& vg_name);
58  static LvmVg* load(Devicegraph* devicegraph, const xmlNode* node);
59 
63  const std::string& get_vg_name() const;
64  void set_vg_name(const std::string& vg_name);
65 
66  const Region& get_region() const;
67 
68  unsigned long long get_size() const;
69 
70  std::string get_size_string() const;
71 
77  unsigned long long get_extent_size() const;
78 
85  void set_extent_size(unsigned long long extent_size);
86 
90  unsigned long long number_of_extents() const;
91 
96  unsigned long long number_of_used_extents() const;
97 
101  unsigned long long number_of_free_extents() const;
102 
108  LvmPv* add_lvm_pv(BlkDevice* blk_device);
109 
114  void remove_lvm_pv(BlkDevice* blk_device);
115 
119  LvmLv* create_lvm_lv(const std::string& lv_name, unsigned long long size);
120 
125  void delete_lvm_lv(LvmLv* lvm_lv);
126 
130  static std::vector<LvmVg*> get_all(Devicegraph* devicegraph);
131 
135  static std::vector<const LvmVg*> get_all(const Devicegraph* devicegraph);
136 
140  static LvmVg* find_by_vg_name(Devicegraph* devicegraph, const std::string& vg_name);
141 
145  static const LvmVg* find_by_vg_name(const Devicegraph* devicegraph, const std::string& vg_name);
146 
147  std::vector<LvmPv*> get_lvm_pvs();
148  std::vector<const LvmPv*> get_lvm_pvs() const;
149 
150  LvmLv* get_lvm_lv(const std::string& lv_name);
151 
152  std::vector<LvmLv*> get_lvm_lvs();
153  std::vector<const LvmLv*> get_lvm_lvs() const;
154 
155  public:
156 
157  class Impl;
158 
159  Impl& get_impl();
160  const Impl& get_impl() const;
161 
162  virtual LvmVg* clone() const override;
163 
164  protected:
165 
166  LvmVg(Impl* impl);
167 
168  };
169 
170 
171  bool is_lvm_vg(const Device* device);
172 
173  LvmVg* to_lvm_vg(Device* device);
174  const LvmVg* to_lvm_vg(const Device* device);
175 
176 }
177 
178 #endif
unsigned long long number_of_free_extents() const
Calculates the number of free extents in the volume group.
unsigned long long get_extent_size() const
Returns the extent size of the volume group.
LvmLv * create_lvm_lv(const std::string &lv_name, unsigned long long size)
Create a logical volume with name lv_name in the volume group.
A Logical Volume of the Logical Volume Manager (LVM).
Definition: LvmLv.h:38
A Volume Group of the Logical Volume Manager (LVM).
Definition: LvmVg.h:53
Definition: LvmPv.h:36
A start/length pair with a block size.
Definition: Region.h:71
unsigned long long number_of_used_extents() const
Calculates the number of used extents in the volume group.
void set_extent_size(unsigned long long extent_size)
Set the extent size of the volume group.
const std::string & get_vg_name() const
Get volume group name.
The master container of the libstorage.
Definition: Devicegraph.h:133
An abstract Block Device.
Definition: BlkDevice.h:40
LvmPv * add_lvm_pv(BlkDevice *blk_device)
Adds a block device as a physical volume to the volume group.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:73
Definition: LvmVg.h:38
static std::vector< LvmVg * > get_all(Devicegraph *devicegraph)
Sorted by vg_name.
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.
Definition: LvmVg.h:44
Base class for storage exceptions.
Definition: Exception.h:113
static LvmVg * find_by_vg_name(Devicegraph *devicegraph, const std::string &vg_name)
Find a volume group by vg-name.
unsigned long long number_of_extents() const
Calculates the number of extents in the volume group.
The storage namespace.
Definition: Actiongraph.h:36
Definition: Devicegraph.h:46