libstorage-ng
Loading...
Searching...
No Matches
LvmLv.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_LV_H
24#define STORAGE_LVM_LV_H
25
26
27#include "storage/Devices/BlkDevice.h"
28#include "storage/Devicegraph.h"
29
30
31namespace storage
32{
33
34 class LvmVg;
35
36
40 enum class LvType
41 {
47 UNKNOWN,
48
53
60
65
72
79
86
93
100
108 };
109
110
116 std::string get_lv_type_name(LvType lv_type);
117
118
119 class LvmLvNotFoundByLvName : public DeviceNotFound
120 {
121 public:
122
123 LvmLvNotFoundByLvName(const std::string& lv_name);
124 };
125
126
127 class InvalidStripeSize : public Exception
128 {
129 public:
130
131 InvalidStripeSize(const std::string& msg);
132 };
133
134
135 class InvalidChunkSize : public Exception
136 {
137 public:
138
139 InvalidChunkSize(const std::string& msg);
140 };
141
142
146 class LvmLv : public BlkDevice
147 {
148
149 public:
150
157 static LvmLv* create(Devicegraph* devicegraph, const std::string& vg_name,
158 const std::string& lv_name, LvType lv_type);
159
160 static LvmLv* load(Devicegraph* devicegraph, const xmlNode* node);
161
165 static std::vector<LvmLv*> get_all(Devicegraph* devicegraph);
166
170 static std::vector<const LvmLv*> get_all(const Devicegraph* devicegraph);
171
180 const std::string& get_lv_name() const;
181
188 void set_lv_name(const std::string& lv_name);
189
194 static bool is_valid_lv_name(const std::string& lv_name);
195
202
206 unsigned int get_stripes() const;
207
215 void set_stripes(unsigned int stripes);
216
220 unsigned long long get_stripe_size() const;
221
229 void set_stripe_size(unsigned long long stripe_size);
230
234 unsigned long long get_chunk_size() const;
235
241 void set_chunk_size(unsigned long long chunk_size);
242
248 const LvmVg* get_lvm_vg() const;
249
255 const LvmLv* get_thin_pool() const;
256
261 bool has_snapshots() const;
262
268 std::vector<LvmLv*> get_snapshots();
269
273 std::vector<const LvmLv*> get_snapshots() const;
274
282 bool has_origin() const;
283
291 LvmLv* get_origin();
292
296 const LvmLv* get_origin() const;
297
306 unsigned long long max_size_for_lvm_lv(LvType lv_type) const;
307
316 LvmLv* create_lvm_lv(const std::string& lv_name, LvType lv_type, unsigned long long size);
317
321 LvmLv* get_lvm_lv(const std::string& lv_name);
322
323 std::vector<LvmLv*> get_lvm_lvs();
324 std::vector<const LvmLv*> get_lvm_lvs() const;
325
333 static bool compare_by_lv_name(const LvmLv* lhs, const LvmLv* rhs);
334
335 public:
336
337 class Impl;
338
339 Impl& get_impl();
340 const Impl& get_impl() const;
341
342 virtual LvmLv* clone() const override;
343 virtual std::unique_ptr<Device> clone_v2() const override;
344
345 LvmLv(Impl* impl);
346 ST_NO_SWIG LvmLv(std::unique_ptr<Device::Impl>&& impl);
347
348 };
349
350
356 bool is_lvm_lv(const Device* device);
357
365
369 const LvmLv* to_lvm_lv(const Device* device);
370
371}
372
373#endif
An abstract base class for storage devices.
Definition Device.h:82
The main container of the libstorage-ng.
Definition Devicegraph.h:170
Exception(LogLevel log_level=LogLevel::ERROR)
Default constructor.
const std::string & msg() const
Return the message string provided to the constructor.
Definition Exception.h:150
A Logical Volume of the Logical Volume Manager (LVM).
Definition LvmLv.h:147
const LvmLv * get_origin() const
Get the origin of the logical volume if it has one.
void set_stripes(unsigned int stripes)
Set the number of stripes.
const LvmVg * get_lvm_vg() const
Return volume group this logical volume belongs to.
unsigned long long get_stripe_size() const
Get the stripe size.
LvmLv * get_lvm_lv(const std::string &lv_name)
LvType get_lv_type() const
Return the logical volume type.
void set_stripe_size(unsigned long long stripe_size)
Set the stripe size.
LvmLv * get_origin()
Get the origin of the logical volume if it has one.
void set_lv_name(const std::string &lv_name)
Set the logical volume name.
static bool compare_by_lv_name(const LvmLv *lhs, const LvmLv *rhs)
Compare (less than) two LvmLvs by lv-name.
bool has_snapshots() const
Check whether the logical volume has snapshots.
static bool is_valid_lv_name(const std::string &lv_name)
Check whether a (new and public) logical volume name is valid.
unsigned int get_stripes() const
Get the number of stripes.
static LvmLv * create(Devicegraph *devicegraph, const std::string &vg_name, const std::string &lv_name, LvType lv_type)
Create a device of type LvmLv.
static std::vector< const LvmLv * > get_all(const Devicegraph *devicegraph)
Get all LvmLvs.
std::vector< const LvmLv * > get_snapshots() const
Get snapshots of the logical volume.
static std::vector< LvmLv * > get_all(Devicegraph *devicegraph)
Get all LvmLvs.
bool has_origin() const
Check whether the logical volume has an origin.
std::vector< LvmLv * > get_snapshots()
Get snapshots of the logical volume.
void set_chunk_size(unsigned long long chunk_size)
Set the chunk size.
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.
const LvmLv * get_thin_pool() const
Return the thin pool for a thin logical volume.
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 std::string & get_lv_name() const
Get the logical volume name.
unsigned long long get_chunk_size() const
Get the chunk size.
A Volume Group of the Logical Volume Manager (LVM).
Definition LvmVg.h:61
The storage namespace.
Definition Actiongraph.h:40
bool is_lvm_lv(const Device *device)
Checks whether device points to a LvmLv.
LvmLv * to_lvm_lv(Device *device)
Converts pointer to Device to pointer to LvmLv.
std::string get_lv_type_name(LvType lv_type)
Convert LvType to string.
LvType
LVM logical volume types, see lvs(8).
Definition LvmLv.h:41
@ CACHE
A cache logical volume.
Definition LvmLv.h:85
@ NORMAL
A linear or striped logical volume.
Definition LvmLv.h:52
@ WRITECACHE
A writecache logical volume.
Definition LvmLv.h:92
@ CACHE_POOL
A cache-pool logical volume.
Definition LvmLv.h:78
@ SNAPSHOT
A thick snapshot.
Definition LvmLv.h:99
@ MIRROR
A mirror volume.
Definition LvmLv.h:107
@ RAID
A raid logical volume.
Definition LvmLv.h:71
@ THIN
A thin logical volume.
Definition LvmLv.h:64
@ THIN_POOL
A thin-pool logical volume.
Definition LvmLv.h:59