libstorage-ng
Alignment.h
1 /*
2  * Copyright (c) [2016-2018] 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_ALIGNMENT_H
24 #define STORAGE_ALIGNMENT_H
25 
26 
27 #include "storage/Utils/Topology.h"
28 #include "storage/Utils/Region.h"
29 #include "storage/Utils/Exception.h"
30 #include "storage/Utils/Swig.h"
31 
32 
33 namespace storage
34 {
35 
36  enum class AlignType
37  {
41  REQUIRED,
42 
46  OPTIMAL
47  };
48 
49 
50  enum class AlignPolicy
51  {
56  ALIGN_END ST_DEPRECATED = 0,
57 
62  KEEP_END ST_DEPRECATED = 1,
63 
68  KEEP_SIZE ST_DEPRECATED = 2,
69 
74  };
75 
76 
77  class AlignError : public Exception
78  {
79  public:
80  AlignError();
81  };
82 
83 
91  class Alignment
92  {
93 
94  public:
95 
96  Alignment(const Topology& topology, AlignType align_type = AlignType::OPTIMAL);
97  Alignment(const Alignment& alignment);
98  Alignment(Alignment&& alignment) = default;
99  ~Alignment();
100 
101  Alignment& operator=(const Alignment& alignment);
102  Alignment& operator=(Alignment&& alignment) = default;
103 
108  bool can_be_aligned(const Region& region, AlignPolicy align_policy) const;
109 
115  Region align(const Region& region, AlignPolicy align_policy = AlignPolicy::ALIGN_START_AND_END) const;
116 
117  long offset() const;
118 
119  unsigned long grain() const;
120 
121  public:
122 
123  class Impl;
124 
125  Impl& get_impl();
126  const Impl& get_impl() const;
127 
128  private:
129 
130  const std::unique_ptr<Impl> impl;
131 
132  };
133 
134 }
135 
136 
137 #endif
A start/length pair with a block size.
Definition: Region.h:73
AlignPolicy
Definition: Alignment.h:50
A class to calculate partition alignment based on hardware topology.
Definition: Alignment.h:91
Region align(const Region &region, AlignPolicy align_policy=AlignPolicy::ALIGN_START_AND_END) const
Aligns a region.
Only align to hard requirements.
AlignType
Definition: Alignment.h:36
Align to topology information.
Base class for storage exceptions.
Definition: Exception.h:113
A class to represent hardware alignment information.
Definition: Topology.h:38
The storage namespace.
Definition: Actiongraph.h:37
Definition: Alignment.h:77
bool can_be_aligned(const Region &region, AlignPolicy align_policy) const
Checks whether a region can be aligned.