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 
88  bool is_default_btrfs_subvolume() const;
89 
96 
100  Btrfs* get_btrfs();
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 
149  bool has_origin() const;
150 
159 
163  const BtrfsSubvolume* get_origin() const;
164 
168  bool has_btrfs_qgroup() const;
169 
176 
180  const BtrfsQgroup* get_btrfs_qgroup() const;
181 
190 
199  BtrfsSubvolume* create_btrfs_subvolume(const std::string& path);
200 
206  static bool compare_by_id(const BtrfsSubvolume* lhs, const BtrfsSubvolume* rhs);
207 
208  public:
209 
210  class Impl;
211 
212  Impl& get_impl();
213  const Impl& get_impl() const;
214 
215  virtual BtrfsSubvolume* clone() const override;
216 
217  BtrfsSubvolume(Impl* impl);
218 
219  };
220 
221 
227  bool is_btrfs_subvolume(const Device* device);
228 
236 
240  const BtrfsSubvolume* to_btrfs_subvolume(const Device* device);
241 
242 }
243 
244 #endif
Class to represent a btrfs filesystem https://en.wikipedia.org/wiki/Btrfs in the devicegraph.
Definition: Btrfs.h:79
void set_nocow(bool nocow)
Set the copy-on-write (COW) flag of the btrfs subvolume.
BtrfsSubvolume * create_btrfs_subvolume(const std::string &path)
Create a btrfs subvolume for the btrfs subvolume.
const std::string & get_path() const
Get the path of the btrfs subvolume.
bool has_origin() const
Check whether the btrfs subvolume has an origin.
bool has_btrfs_qgroup() const
Return whether the subvolume as a corresponding level 0 qgroup.
bool is_default_btrfs_subvolume() const
Check whether the subvolume is the default subvolume.
BtrfsSubvolume * to_btrfs_subvolume(Device *device)
Converts pointer to Device to pointer to BtrfsSubvolume.
bool is_nocow() const
Get the copy-on-write (COW) flag of the btrfs subvolume.
Class to represent a btrfs subvolume in the devicegraph.
Definition: BtrfsSubvolume.h:43
long get_id() const
Get the id of the btrfs subvolume.
BtrfsQgroup * create_btrfs_qgroup()
Create the corresponding level 0 qgroup for the subvolume.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
Definition: Mountable.h:111
std::vector< BtrfsSubvolume * > get_snapshots()
Get snapshots of the btrfs subvolume.
BtrfsSubvolume * get_origin()
Get the origin of the btrfs subvolume if it has one.
Btrfs * get_btrfs()
Return the btrfs filesystem of the btrfs subvolume.
bool is_btrfs_subvolume(const Device *device)
Checks whether device points to a BtrfsSubvolume.
bool has_snapshots() const
Check whether the btrfs subvolume has snapshots.
An abstract base class for storage devices.
Definition: Device.h:81
static bool compare_by_id(const BtrfsSubvolume *lhs, const BtrfsSubvolume *rhs)
Compare (less than) two BtrfsSubvolumes by id.
static BtrfsSubvolume * create(Devicegraph *devicegraph, const std::string &path)
Create a device of type BtrfsSubvolume.
bool is_top_level() const
Check whether the subvolume is the top-level subvolume.
BtrfsSubvolume * get_top_level_btrfs_subvolume()
Return the top-level subvolume.
Class to represent a qgroup of a btrfs filesystem.
Definition: BtrfsQgroup.h:44
BtrfsQgroup * get_btrfs_qgroup()
Return the corresponding level 0 qgroup of the subvolume.
void set_default_btrfs_subvolume()
Set the subvolume to be the default subvolume.
The storage namespace.
Definition: Actiongraph.h:39