libstorage-ng
BtrfsSubvolume.h
1 /*
2  * Copyright (c) [2017-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_BTRFS_SUBVOLUME_H
24 #define STORAGE_BTRFS_SUBVOLUME_H
25 
26 
27 #include "storage/Filesystems/Mountable.h"
28 #include "storage/Devicegraph.h"
29 
30 
31 namespace storage
32 {
33 
34  class Btrfs;
35  class BtrfsQgroup;
36 
37 
43  class BtrfsSubvolume : public Mountable
44  {
45  public:
46 
53  static BtrfsSubvolume* create(Devicegraph* devicegraph, const std::string& path);
54 
55  static BtrfsSubvolume* load(Devicegraph* devicegraph, const xmlNode* node);
56 
61  long get_id() const;
62 
66  bool is_top_level() const;
67 
71  const std::string& get_path() const;
72 
76  bool is_nocow() const;
77 
83  void set_nocow(bool nocow);
84 
89 
96 
101 
105  const Btrfs* get_btrfs() const;
106 
113 
118 
122  bool has_snapshots() const;
123 
129  std::vector<BtrfsSubvolume*> get_snapshots();
130 
134  std::vector<const BtrfsSubvolume*> get_snapshots() const;
135 
148  bool has_origin() const;
149 
158 
162  const BtrfsSubvolume* get_origin() const;
163 
167  bool has_btrfs_qgroup() const;
168 
175 
180 
189 
198  BtrfsSubvolume* create_btrfs_subvolume(const std::string& path);
199 
205  static bool compare_by_id(const BtrfsSubvolume* lhs, const BtrfsSubvolume* rhs);
206 
207  public:
208 
209  class Impl;
210 
211  Impl& get_impl();
212  const Impl& get_impl() const;
213 
214  virtual BtrfsSubvolume* clone() const override;
215 
216  protected:
217 
218  BtrfsSubvolume(Impl* impl);
219 
220  };
221 
222 
228  bool is_btrfs_subvolume(const Device* device);
229 
237 
241  const BtrfsSubvolume* to_btrfs_subvolume(const Device* device);
242 
243 }
244 
245 #endif
storage::BtrfsQgroup
Class to represent a qgroup of a btrfs filesystem.
Definition: BtrfsQgroup.h:45
storage::BtrfsSubvolume::get_snapshots
std::vector< const BtrfsSubvolume * > get_snapshots() const
Get snapshots of the btrfs subvolume.
storage::BtrfsSubvolume::create_btrfs_qgroup
BtrfsQgroup * create_btrfs_qgroup()
Create the corresponding level 0 qgroup for the subvolume.
storage::BtrfsSubvolume::get_btrfs_qgroup
BtrfsQgroup * get_btrfs_qgroup()
Return the corresponding level 0 qgroup of the subvolume.
storage::BtrfsSubvolume::get_top_level_btrfs_subvolume
const BtrfsSubvolume * get_top_level_btrfs_subvolume() const
Return the top-level subvolume.
storage::BtrfsSubvolume::create_btrfs_subvolume
BtrfsSubvolume * create_btrfs_subvolume(const std::string &path)
Create a btrfs subvolume for the btrfs subvolume.
storage::to_btrfs_subvolume
BtrfsSubvolume * to_btrfs_subvolume(Device *device)
Converts pointer to Device to pointer to BtrfsSubvolume.
storage::BtrfsSubvolume::has_snapshots
bool has_snapshots() const
Check whether the btrfs subvolume has snapshots.
storage::BtrfsSubvolume
Class to represent a btrfs subvolume in the devicegraph.
Definition: BtrfsSubvolume.h:44
storage::BtrfsSubvolume::compare_by_id
static bool compare_by_id(const BtrfsSubvolume *lhs, const BtrfsSubvolume *rhs)
Compare (less than) two BtrfsSubvolumes by id.
storage::BtrfsSubvolume::set_nocow
void set_nocow(bool nocow)
Set the copy-on-write (COW) flag of the btrfs subvolume.
storage::BtrfsSubvolume::is_default_btrfs_subvolume
bool is_default_btrfs_subvolume() const
Check whether the subvolume is the default subvolume.
storage
The storage namespace.
Definition: Actiongraph.h:39
storage::BtrfsSubvolume::get_btrfs
const Btrfs * get_btrfs() const
Return the btrfs filesystem of the btrfs subvolume.
storage::BtrfsSubvolume::get_path
const std::string & get_path() const
Get the path of the btrfs subvolume.
storage::Mountable
Definition: Mountable.h:101
storage::BtrfsSubvolume::get_origin
BtrfsSubvolume * get_origin()
Get the origin of the btrfs subvolume if it has one.
storage::BtrfsSubvolume::has_btrfs_qgroup
bool has_btrfs_qgroup() const
Return whether the subvolume as a corresponding level 0 qgroup.
storage::BtrfsSubvolume::get_origin
const BtrfsSubvolume * get_origin() const
Get the origin of the btrfs subvolume if it has one.
storage::BtrfsSubvolume::is_nocow
bool is_nocow() const
Get the copy-on-write (COW) flag of the btrfs subvolume.
storage::Devicegraph
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
storage::is_btrfs_subvolume
bool is_btrfs_subvolume(const Device *device)
Checks whether device points to a BtrfsSubvolume.
storage::BtrfsSubvolume::set_default_btrfs_subvolume
void set_default_btrfs_subvolume()
Set the subvolume to be the default subvolume.
storage::BtrfsSubvolume::get_btrfs
Btrfs * get_btrfs()
Return the btrfs filesystem of the btrfs subvolume.
storage::Btrfs
Class to represent a btrfs filesystem https://en.wikipedia.org/wiki/Btrfs in the devicegraph.
Definition: Btrfs.h:80
storage::BtrfsSubvolume::get_btrfs_qgroup
const BtrfsQgroup * get_btrfs_qgroup() const
Return the corresponding level 0 qgroup of the subvolume.
storage::BtrfsSubvolume::get_snapshots
std::vector< BtrfsSubvolume * > get_snapshots()
Get snapshots of the btrfs subvolume.
storage::BtrfsSubvolume::get_id
long get_id() const
Get the id of the btrfs subvolume.
storage::BtrfsSubvolume::create
static BtrfsSubvolume * create(Devicegraph *devicegraph, const std::string &path)
Create a device of type BtrfsSubvolume.
storage::Device
An abstract base class for storage devices.
Definition: Device.h:82
storage::BtrfsSubvolume::is_top_level
bool is_top_level() const
Check whether the subvolume is the top-level subvolume.
storage::BtrfsSubvolume::get_top_level_btrfs_subvolume
BtrfsSubvolume * get_top_level_btrfs_subvolume()
Return the top-level subvolume.
storage::BtrfsSubvolume::has_origin
bool has_origin() const
Check whether the btrfs subvolume has an origin.