libstorage-ng
Btrfs.h
1 /*
2  * Copyright (c) 2015 Novell, Inc.
3  * Copyright (c) [2017-2020] SUSE LLC
4  *
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may
20  * find current contact information at www.novell.com.
21  */
22 
23 
24 #ifndef STORAGE_BTRFS_H
25 #define STORAGE_BTRFS_H
26 
27 
28 #include "storage/Devicegraph.h"
29 #include "storage/Filesystems/BlkFilesystem.h"
30 #include "storage/Filesystems/BtrfsQgroup.h"
31 
32 
33 namespace storage
34 {
35 
36  class BtrfsSubvolume;
37  class FilesystemUser;
38 
39 
45  enum class BtrfsRaidLevel
46  {
47  UNKNOWN, DEFAULT, SINGLE, DUP, RAID0, RAID1, RAID5, RAID6, RAID10, RAID1C3, RAID1C4
48  };
49 
50 
56  std::string get_btrfs_raid_level_name(BtrfsRaidLevel btrfs_raid_level);
57 
58 
60  {
61  public:
62 
63  BtrfsSubvolumeNotFoundByPath(const std::string& path);
64  };
65 
66 
68  {
69  public:
70 
72  };
73 
74 
79  class Btrfs : public BlkFilesystem
80  {
81  public:
82 
89  static Btrfs* create(Devicegraph* devicegraph);
90 
91  static Btrfs* load(Devicegraph* devicegraph, const xmlNode* node);
92 
99 
107  void set_metadata_raid_level(BtrfsRaidLevel metadata_raid_level);
108 
115 
123  void set_data_raid_level(BtrfsRaidLevel data_raid_level);
124 
134  std::vector<BtrfsRaidLevel> get_allowed_metadata_raid_levels() const;
135 
145  std::vector<BtrfsRaidLevel> get_allowed_data_raid_levels() const;
146 
150  bool has_quota() const;
151 
164  void set_quota(bool quota);
165 
172 
180  void remove_device(BlkDevice* blk_device);
181 
186 
191 
196 
201 
207  void set_default_btrfs_subvolume(BtrfsSubvolume* btrfs_subvolume) const;
208 
212  std::vector<BtrfsSubvolume*> get_btrfs_subvolumes();
213 
217  std::vector<const BtrfsSubvolume*> get_btrfs_subvolumes() const;
218 
224  BtrfsSubvolume* find_btrfs_subvolume_by_path(const std::string& path);
225 
229  const BtrfsSubvolume* find_btrfs_subvolume_by_path(const std::string& path) const;
230 
238 
242  std::vector<BtrfsQgroup*> get_btrfs_qgroups();
243 
247  std::vector<const BtrfsQgroup*> get_btrfs_qgroups() const;
248 
255 
260 
264  static std::vector<Btrfs*> get_all(Devicegraph* devicegraph);
265 
269  static std::vector<const Btrfs*> get_all(const Devicegraph* devicegraph);
270 
271  bool get_configure_snapper() const;
272  void set_configure_snapper(bool configure);
273 
274  public:
275 
276  class Impl;
277 
278  Impl& get_impl();
279  const Impl& get_impl() const;
280 
281  virtual Btrfs* clone() const override;
282 
283  protected:
284 
285  Btrfs(Impl* impl);
286 
287  };
288 
289 
295  bool is_btrfs(const Device* device);
296 
303  Btrfs* to_btrfs(Device* device);
304 
308  const Btrfs* to_btrfs(const Device* device);
309 
310 }
311 
312 #endif
An abstract Block Device.
Definition: BlkDevice.h:47
Definition: BlkFilesystem.h:43
Definition: Btrfs.h:68
Class to represent a qgroup of a btrfs filesystem.
Definition: BtrfsQgroup.h:45
std::pair< unsigned int, unsigned long long > id_t
Type for a btrfs qgroup id.
Definition: BtrfsQgroup.h:54
Class to represent a btrfs subvolume in the devicegraph.
Definition: BtrfsSubvolume.h:44
Class to represent a btrfs filesystem https://en.wikipedia.org/wiki/Btrfs in the devicegraph.
Definition: Btrfs.h:80
BtrfsSubvolume * get_default_btrfs_subvolume()
Get the default subvolume.
BtrfsRaidLevel get_metadata_raid_level() const
Get the metadata RAID level.
void set_metadata_raid_level(BtrfsRaidLevel metadata_raid_level)
Set the metadata RAID level.
void remove_device(BlkDevice *blk_device)
Remove a block device from the btrfs.
const BtrfsQgroup * find_btrfs_qgroup_by_id(const BtrfsQgroup::id_t &id) const
Find a btrfs qgroup of the btrfs by its id.
void set_quota(bool quota)
Enable or disable quota for the btrfs.
FilesystemUser * add_device(BlkDevice *blk_device)
Add a block device to the btrfs.
BtrfsQgroup * create_btrfs_qgroup(const BtrfsQgroup::id_t &id)
Create a new btrfs qgroup on the btrfs.
bool has_quota() const
Return whether quota is enabled for the btrfs.
static Btrfs * create(Devicegraph *devicegraph)
Create a device of type Btrfs.
BtrfsRaidLevel get_data_raid_level() const
Get the data RAID level.
std::vector< const BtrfsQgroup * > get_btrfs_qgroups() const
Get all btrfs qgroups of the btrfs.
void set_default_btrfs_subvolume(BtrfsSubvolume *btrfs_subvolume) const
Set the default subvolume.
const BtrfsSubvolume * get_default_btrfs_subvolume() const
Get the default subvolume.
static std::vector< const Btrfs * > get_all(const Devicegraph *devicegraph)
Get all Btrfses.
BtrfsSubvolume * get_top_level_btrfs_subvolume()
Get the top-level subvolume.
std::vector< BtrfsRaidLevel > get_allowed_data_raid_levels() const
Get the allowed data RAID levels for the btrfs.
std::vector< const BtrfsSubvolume * > get_btrfs_subvolumes() const
Get all subvolumes of the btrfs.
std::vector< BtrfsSubvolume * > get_btrfs_subvolumes()
Get all subvolumes of the btrfs.
void set_data_raid_level(BtrfsRaidLevel data_raid_level)
Set the data RAID level.
const BtrfsSubvolume * get_top_level_btrfs_subvolume() const
Get the top-level subvolume.
const BtrfsSubvolume * find_btrfs_subvolume_by_path(const std::string &path) const
Find a btrfs subvolume of the btrfs by its path.
static std::vector< Btrfs * > get_all(Devicegraph *devicegraph)
Get all Btrfses.
BtrfsQgroup * find_btrfs_qgroup_by_id(const BtrfsQgroup::id_t &id)
Find a btrfs qgroup of the btrfs by its id.
BtrfsSubvolume * find_btrfs_subvolume_by_path(const std::string &path)
Find a btrfs subvolume of the btrfs by its path.
std::vector< BtrfsQgroup * > get_btrfs_qgroups()
Get all btrfs qgroups of the btrfs.
std::vector< BtrfsRaidLevel > get_allowed_metadata_raid_levels() const
Get the allowed metadata RAID levels for the btrfs.
Definition: Devicegraph.h:50
An abstract base class for storage devices.
Definition: Device.h:82
The master container of the libstorage-ng.
Definition: Devicegraph.h:170
Holder from BlkDevice to a BlkFilesystem.
Definition: FilesystemUser.h:39
The storage namespace.
Definition: Actiongraph.h:39
BtrfsRaidLevel
Btrfs RAID levels (aka profiles) used for metadata and data.
Definition: Btrfs.h:46
bool is_btrfs(const Device *device)
Checks whether device points to a Btrfs.
Btrfs * to_btrfs(Device *device)
Converts pointer to Device to pointer to Btrfs.
std::string get_btrfs_raid_level_name(BtrfsRaidLevel btrfs_raid_level)
Convert the btrfs RAID level btrfs_raid_level to a string.