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 
31 
32 namespace storage
33 {
34 
35  class BtrfsSubvolume;
36  class FilesystemUser;
37 
38 
42  enum class BtrfsRaidLevel
43  {
44  UNKNOWN, DEFAULT, SINGLE, DUP, RAID0, RAID1, RAID5, RAID6, RAID10, RAID1C3, RAID1C4
45  };
46 
47 
51  std::string get_btrfs_raid_level_name(BtrfsRaidLevel btrfs_raid_level);
52 
53 
55  {
56  public:
57 
58  BtrfsSubvolumeNotFoundByPath(const std::string& path);
59  };
60 
61 
66  class Btrfs : public BlkFilesystem
67  {
68  public:
69 
70  static Btrfs* create(Devicegraph* devicegraph);
71  static Btrfs* load(Devicegraph* devicegraph, const xmlNode* node);
72 
77 
83  void set_metadata_raid_level(BtrfsRaidLevel metadata_raid_level);
84 
89 
95  void set_data_raid_level(BtrfsRaidLevel data_raid_level);
96 
104  std::vector<BtrfsRaidLevel> get_allowed_metadata_raid_levels() const;
105 
113  std::vector<BtrfsRaidLevel> get_allowed_data_raid_levels() const;
114 
120  FilesystemUser* add_device(BlkDevice* blk_device);
121 
129  void remove_device(BlkDevice* blk_device);
130 
131  BtrfsSubvolume* get_top_level_btrfs_subvolume();
132  const BtrfsSubvolume* get_top_level_btrfs_subvolume() const;
133 
134  BtrfsSubvolume* get_default_btrfs_subvolume();
135  const BtrfsSubvolume* get_default_btrfs_subvolume() const;
136 
137  void set_default_btrfs_subvolume(BtrfsSubvolume* btrfs_subvolume) const;
138 
139  std::vector<BtrfsSubvolume*> get_btrfs_subvolumes();
140  std::vector<const BtrfsSubvolume*> get_btrfs_subvolumes() const;
141 
147  BtrfsSubvolume* find_btrfs_subvolume_by_path(const std::string& path);
148 
152  const BtrfsSubvolume* find_btrfs_subvolume_by_path(const std::string& path) const;
153 
154  bool get_configure_snapper() const;
155  void set_configure_snapper(bool configure);
156 
157  public:
158 
159  class Impl;
160 
161  Impl& get_impl();
162  const Impl& get_impl() const;
163 
164  virtual Btrfs* clone() const override;
165 
166  protected:
167 
168  Btrfs(Impl* impl);
169 
170  };
171 
172 
178  bool is_btrfs(const Device* device);
179 
186  Btrfs* to_btrfs(Device* device);
187 
191  const Btrfs* to_btrfs(const Device* device);
192 
193 }
194 
195 #endif
Class to represent a btrfs filesystem https://en.wikipedia.org/wiki/Btrfs in the devicegraph.
Definition: Btrfs.h:66
Btrfs * to_btrfs(Device *device)
Converts pointer to Device to pointer to Btrfs.
void set_metadata_raid_level(BtrfsRaidLevel metadata_raid_level)
Set the metadata RAID level.
std::vector< BtrfsRaidLevel > get_allowed_metadata_raid_levels() const
Get the allowed metadata RAID levels for the btrfs.
Class to represent a btrfs subvolume in the devicegraph.
Definition: BtrfsSubvolume.h:40
std::vector< BtrfsRaidLevel > get_allowed_data_raid_levels() const
Get the allowed data RAID levels for the btrfs.
The master container of the libstorage.
Definition: Devicegraph.h:153
bool is_btrfs(const Device *device)
Checks whether device points to a Btrfs.
Definition: BlkFilesystem.h:42
An abstract Block Device.
Definition: BlkDevice.h:46
void remove_device(BlkDevice *blk_device)
Remove a block device from the btrfs.
void set_data_raid_level(BtrfsRaidLevel data_raid_level)
Set the data RAID level.
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
Definition: Devicegraph.h:48
std::string get_btrfs_raid_level_name(BtrfsRaidLevel btrfs_raid_level)
Convert the btrfs RAID level btrfs_raid_level to a string.
FilesystemUser * add_device(BlkDevice *blk_device)
Add a block device to the btrfs.
BtrfsRaidLevel get_metadata_raid_level() const
Get the metadata RAID level.
BtrfsRaidLevel get_data_raid_level() const
Get the data RAID level.
The storage namespace.
Definition: Actiongraph.h:37
BtrfsSubvolume * find_btrfs_subvolume_by_path(const std::string &path)
Find a btrfs subvolume of the btrfs by its path.
BtrfsRaidLevel
Btrfs RAID levels (aka profiles) used for metadata and data.
Definition: Btrfs.h:42
Definition: FilesystemUser.h:33