libstorage-ng
Topology.h
1 /*
2  * Copyright (c) 2016 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_TOPOLOGY_H
24 #define STORAGE_TOPOLOGY_H
25 
26 
27 #include <libxml/tree.h>
28 #include <memory>
29 #include <ostream>
30 
31 #include "storage/Utils/Region.h"
32 #include "storage/Utils/Exception.h"
33 
34 
35 namespace storage
36 {
37 
38  enum class AlignPolicy
39  {
40  ALIGN_END, KEEP_END, KEEP_SIZE
41  };
42 
43 
44  class AlignError : public Exception
45  {
46  public:
47  AlignError();
48  };
49 
50 
57  class Topology
58  {
59  public:
60 
61  Topology();
62  Topology(long alignment_offset, unsigned long optimal_io_size);
63  Topology(const Topology& topology);
64  ~Topology();
65 
66  Topology& operator=(const Topology& topology);
67 
68  long get_alignment_offset() const;
69  void set_alignment_offset(long alignment_offset);
70 
71  unsigned long get_optimal_io_size() const;
72  void set_optimal_io_size(unsigned long optimal_io_size);
73 
74  unsigned long get_minimal_grain() const;
75  void set_minimal_grain(unsigned long minimal_grain);
76 
80  unsigned long calculate_grain() const;
81 
86  bool can_be_aligned(const Region& region, AlignPolicy align_policy) const;
87 
93  Region align(const Region& region, AlignPolicy align_policy = AlignPolicy::ALIGN_END) const;
94 
95  bool operator==(const Topology& rhs) const;
96  bool operator!=(const Topology& rhs) const;
97 
98  friend std::ostream& operator<<(std::ostream& s, const Topology& topology);
99 
100  public:
101 
102  class Impl;
103 
104  Impl& get_impl();
105  const Impl& get_impl() const;
106 
107  friend bool getChildValue(const xmlNode* node, const char* name, Topology& topology);
108  friend void setChildValue(xmlNode* node, const char* name, const Topology& topology);
109 
110  private:
111 
112  const std::unique_ptr<Impl> impl;
113 
114  };
115 
116 }
117 
118 
119 #endif
A start/length pair with a block size.
Definition: Region.h:71
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
CodeLocation stream output.
Base class for storage exceptions.
Definition: Exception.h:113
A class to calculate partition alignment based on hardware topology.
Definition: Topology.h:57
The storage namespace.
Definition: Actiongraph.h:36
Definition: Topology.h:44