libstorage-ng
LvmLv.h
1 /*
2  * Copyright (c) [2016-2020] 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_LV_H
24 #define STORAGE_LVM_LV_H
25 
26 
27 #include "storage/Devices/BlkDevice.h"
28 #include "storage/Devicegraph.h"
29 
30 
31 namespace storage
32 {
33 
34  class LvmVg;
35 
36 
40  enum class LvType
41  {
47  UNKNOWN,
48 
52  NORMAL,
53 
59  THIN_POOL,
60 
64  THIN,
65 
71  RAID,
72 
78  CACHE_POOL,
79 
85  CACHE,
86 
92  WRITECACHE,
93 
99  SNAPSHOT,
100 
107  MIRROR
108  };
109 
110 
116  std::string get_lv_type_name(LvType lv_type);
117 
118 
120  {
121  public:
122 
123  LvmLvNotFoundByLvName(const std::string& lv_name);
124  };
125 
126 
130  class LvmLv : public BlkDevice
131  {
132 
133  public:
134 
141  static LvmLv* create(Devicegraph* devicegraph, const std::string& vg_name,
142  const std::string& lv_name, LvType lv_type);
143 
144  static LvmLv* load(Devicegraph* devicegraph, const xmlNode* node);
145 
149  static std::vector<LvmLv*> get_all(Devicegraph* devicegraph);
150 
154  static std::vector<const LvmLv*> get_all(const Devicegraph* devicegraph);
155 
164  const std::string& get_lv_name() const;
165 
171  void set_lv_name(const std::string& lv_name);
172 
178  LvType get_lv_type() const;
179 
180  unsigned int get_stripes() const;
181 
189  void set_stripes(unsigned int stripes);
190 
191  unsigned long long get_stripe_size() const;
192 
196  void set_stripe_size(unsigned long long stripe_size);
197 
198  unsigned long long get_chunk_size() const;
199 
205  void set_chunk_size(unsigned long long chunk_size);
206 
212  const LvmVg* get_lvm_vg() const;
213 
219  const LvmLv* get_thin_pool() const;
220 
225  bool has_snapshots() const;
226 
232  std::vector<LvmLv*> get_snapshots();
233 
237  std::vector<const LvmLv*> get_snapshots() const;
238 
246  bool has_origin() const;
247 
255  LvmLv* get_origin();
256 
260  const LvmLv* get_origin() const;
261 
270  unsigned long long max_size_for_lvm_lv(LvType lv_type) const;
271 
280  LvmLv* create_lvm_lv(const std::string& lv_name, LvType lv_type, unsigned long long size);
281 
285  LvmLv* get_lvm_lv(const std::string& lv_name);
286 
287  std::vector<LvmLv*> get_lvm_lvs();
288  std::vector<const LvmLv*> get_lvm_lvs() const;
289 
297  static bool compare_by_lv_name(const LvmLv* lhs, const LvmLv* rhs);
298 
299  public:
300 
301  class Impl;
302 
303  Impl& get_impl();
304  const Impl& get_impl() const;
305 
306  virtual LvmLv* clone() const override;
307 
308  protected:
309 
310  LvmLv(Impl* impl);
311 
312  };
313 
314 
320  bool is_lvm_lv(const Device* device);
321 
328  LvmLv* to_lvm_lv(Device* device);
329 
333  const LvmLv* to_lvm_lv(const Device* device);
334 
335 }
336 
337 #endif
A cache-pool logical volume.
std::string get_lv_type_name(LvType lv_type)
Convert LvType to string.
bool has_origin() const
Check whether the logical volume has an origin.
A thick snapshot.
A mirror volume.
A Logical Volume of the Logical Volume Manager (LVM).
Definition: LvmLv.h:130
static bool compare_by_lv_name(const LvmLv *lhs, const LvmLv *rhs)
Compare (less than) two LvmLvs by lv-name.
std::vector< LvmLv * > get_snapshots()
Get snapshots of the logical volume.
const LvmVg * get_lvm_vg() const
Return volume group this logical volume belongs to.
LvType get_lv_type() const
Return the logical volume type.
LvmLv * get_lvm_lv(const std::string &lv_name)
A linear or striped logical volume.
const std::string & get_lv_name() const
Get the logical volume name.
A cache logical volume.
A Volume Group of the Logical Volume Manager (LVM).
Definition: LvmVg.h:59
Definition: LvmLv.h:119
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 thin pool.
const LvmLv * get_thin_pool() const
Return the thin pool for a thin logical volume.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
void set_lv_name(const std::string &lv_name)
Set the logical volume name.
An abstract Block Device.
Definition: BlkDevice.h:46
static LvmLv * create(Devicegraph *devicegraph, const std::string &vg_name, const std::string &lv_name, LvType lv_type)
Create a device of type LvmLv.
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.
An abstract base class for storage devices.
Definition: Device.h:81
A thin logical volume.
Definition: Devicegraph.h:49
bool has_snapshots() const
Check whether the logical volume has snapshots.
void set_chunk_size(unsigned long long chunk_size)
Set the chunk size.
A thin-pool logical volume.
A raid logical volume.
bool is_lvm_lv(const Device *device)
Checks whether device points to a LvmLv.
The storage namespace.
Definition: Actiongraph.h:38
A writecache logical volume.
LvmLv * get_origin()
Get the origin of the logical volume if it has one.
LvType
LVM logical volume types, see lvs(8).
Definition: LvmLv.h:40
static std::vector< LvmLv * > get_all(Devicegraph *devicegraph)
Get all LvmLvs.
void set_stripes(unsigned int stripes)
Set the number of stripes.
LvmLv * to_lvm_lv(Device *device)
Converts pointer to Device to pointer to LvmLv.
void set_stripe_size(unsigned long long stripe_size)