Import version 1.8.3
[s390-tools.git] / ziomon / ziorep_collapser.hpp
blobac91b999f73fd9263ad3f5ea3529962de35e141b
1 /*
2 * FCP report generators
4 * Utility classes to get indices for collapsing data by
5 * variable criteria
7 * Copyright IBM Corp. 2008
8 * Author(s): Stefan Raspl <raspl@linux.vnet.ibm.com>
9 */
11 #ifndef ZIOMON_COLLAPSER
12 #define ZIOMON_COLLAPSER
14 #include <list>
16 #include <linux/types.h>
18 #include "ziorep_cfgreader.hpp"
19 #include "ziorep_filters.hpp"
21 using std::list;
24 enum Aggregator {
25 none,
26 chpid,
27 devno,
28 wwpn,
29 multipath_device,
30 all
34 /**
35 * A collapser is basically a mapper that maps a given device to an index.
36 * The interesting part is the AggregationCollapser, which maps devices that
37 * share a certain property to the same index.
38 * NOTE: There is no guarantee that all indices will be used! E.g. the first
39 * index received might be 0, but the next one could be 5. In that case, it is
40 * the caller's responsibility to make sure that indices 1 to 4 are handled
41 * appropriately.
43 class Collapser {
44 public:
45 Collapser(Aggregator criterion);
46 virtual ~Collapser();
48 /// get index by device identifier
49 virtual unsigned int get_index(struct hctl_ident *identifier) const = 0;
51 /// get index by major/minor
52 virtual unsigned int get_index(__u32 device) const = 0;
54 /// get index by host_id
55 virtual unsigned int get_index_by_host_id(__u32 h) const = 0;
57 Aggregator get_criterion() const;
59 protected:
60 struct host_id_mapping {
61 __u32 h;
62 int idx;
64 struct device_mapping {
65 __u32 device;
66 int idx;
68 struct ident_mapping {
69 struct hctl_ident ident;
70 int idx;
72 /// Lookup list for matching a host id to an index, sorted ascending
73 mutable list<struct host_id_mapping> m_host_ids;
75 /// Lookup list for matching a device to an index, sorted ascending
76 mutable list<struct device_mapping> m_devices;
78 /// Lookup list for matching an identifier to an index, sorted ascending
79 mutable list<struct ident_mapping> m_idents;
81 /// add entry, skips duplicates.
82 void add_to_index(struct ident_mapping *new_mapping) const;
84 /// add entry, skips duplicates.
85 void add_to_index(struct device_mapping *new_mapping) const;
87 /// add entry, skips duplicates.
88 void add_to_index(struct host_id_mapping *new_mapping) const;
90 /// search for device, returns <0 if not found
91 int lookup_index(struct hctl_ident *identifier) const;
93 /// search for device, returns <0 if not found
94 int lookup_index(__u32 device) const;
96 /// search for device, returns <0 if not found
97 int lookup_index_by_host_id(__u32 h) const;
99 Aggregator m_criterion;
103 * Collapser that doesn't do any collapsing (ooops) - it merely assigns
104 * an individual index to each device.
106 class NoopCollapser : public Collapser {
107 public:
108 NoopCollapser();
110 virtual unsigned int get_index(struct hctl_ident *identifier) const;
112 virtual unsigned int get_index(__u32 device) const;
114 virtual unsigned int get_index_by_host_id(__u32 h) const;
119 * Collapser that collapses everything into a single element. That is,
120 * all devices will be mapped to the same index of 0.
122 class TotalCollapser : public Collapser {
123 public:
124 TotalCollapser();
126 virtual unsigned int get_index(struct hctl_ident *identifier) const;
128 virtual unsigned int get_index(__u32 device) const;
130 virtual unsigned int get_index_by_host_id(__u32 h) const;
135 * Collapser that collapses by a given criterion. For instance, if the
136 * criterion used is wwpn, then all devices that have the same wwpn will
137 * be matched to the same index.
139 class AggregationCollapser : public Collapser {
140 public:
142 * 'filt' must hold all available devices */
143 AggregationCollapser(ConfigReader &cfg,
144 Aggregator &criterion,
145 DeviceFilter &dev_filt,
146 int *rc);
148 virtual unsigned int get_index(struct hctl_ident *identifier) const;
149 virtual unsigned int get_index(__u32 device) const;
150 virtual unsigned int get_index_by_host_id(__u32 h) const;
152 /// Reference chpids as used for collapsing.
153 const list<__u32>& get_reference_chpids() const;
155 /// Reference wwpns as used for collapsing.
156 const list<__u64>& get_reference_wwpns() const;
158 /// Reference devnos as used for collapsing.
159 const list<__u32>& get_reference_devnos() const;
161 /// Reference multipathes as used for collapsing.
162 const list<__u32>& get_reference_mp_mms() const;
164 private:
165 /** list of all unique __u32 values of the criterion we were
166 * collapsing by. */
167 list<__u32> m_reference_values_u32;
168 list<__u64> m_reference_values_u64;
170 int get_index_u32(list<__u32> &lst, __u32 chpid);
171 int get_index_u64(list<__u64> &lst, __u64 chpid);
173 void setup_by_chpid(ConfigReader &cfg, DeviceFilter &dev_filt);
174 void setup_by_devno(ConfigReader &cfg, DeviceFilter &dev_filt);
175 void setup_by_wwpn(ConfigReader &cfg, DeviceFilter &dev_filt);
176 int setup_by_multipath(ConfigReader &cfg, DeviceFilter &dev_filt);
181 #endif