libstorage-ng
Pool.h
1 /*
2  * Copyright (c) 2020 Arvin Schnell
3  * Copyright (c) 2021 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_POOL_H
25 #define STORAGE_POOL_H
26 
27 
28 #include <vector>
29 #include <map>
30 #include <memory>
31 #include <boost/noncopyable.hpp>
32 
33 #include "storage/Utils/Exception.h"
34 
35 
36 namespace storage
37 {
38 
39  class Devicegraph;
40  class Device;
41  class Partition;
42 
43 
47  class PoolOutOfSpace : public Exception
48  {
49  public:
50 
52 
53  };
54 
55 
82  class Pool : private boost::noncopyable
83  {
84  public:
85 
86  Pool();
87  ~Pool();
88 
92  const std::map<std::string, std::string>& get_userdata() const;
93 
97  void set_userdata(const std::map<std::string, std::string>& userdata);
98 
102  bool exists_device(const Device* device) const;
103 
111  void add_device(const Device* device);
112 
120  void remove_device(const Device* device);
121 
126  size_t size(const Devicegraph* devicegraph) const;
127 
132  std::vector<const Device*> get_devices(const Devicegraph* devicegraph) const;
133 
140  unsigned long long max_partition_size(Devicegraph* devicegraph, unsigned int number) const;
141 
154  std::vector<Partition*> create_partitions(Devicegraph* devicegraph, unsigned int number,
155  unsigned long long size) const;
156 
157  public:
158 
159  class Impl;
160 
161  Impl& get_impl() { return *impl; }
162  const Impl& get_impl() const { return *impl; }
163 
164  private:
165 
166  const std::unique_ptr<Impl> impl;
167 
168  };
169 
170 }
171 
172 
173 #endif
unsigned long long max_partition_size(Devicegraph *devicegraph, unsigned int number) const
Find the maximum partition size the pool can provide for the given number of partitions.
const std::map< std::string, std::string > & get_userdata() const
Return the userdata of the pool.
void remove_device(const Device *device)
Remove a device from the pool.
size_t size(const Devicegraph *devicegraph) const
Get the number of devices of the pool available in the devicegraph.
void set_userdata(const std::map< std::string, std::string > &userdata)
Set the userdata of the pool.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
void add_device(const Device *device)
Add a device to the pool.
An abstract base class for storage devices.
Definition: Device.h:81
bool exists_device(const Device *device) const
Check whether the device exists in the pool.
Base class for storage exceptions.
Definition: Exception.h:113
std::vector< Partition * > create_partitions(Devicegraph *devicegraph, unsigned int number, unsigned long long size) const
Create a number of partitions of size in the pool.
std::vector< const Device * > get_devices(const Devicegraph *devicegraph) const
Get the devices of the pool available in the devicegraph.
The storage namespace.
Definition: Actiongraph.h:38
Exception to report that the pool is out of space to fulfill the request.
Definition: Pool.h:47
A pool represents a collection of devices.
Definition: Pool.h:82