Imported Upstream version 0.8.7
[platform/upstream/multipath-tools.git] / libmultipath / generic.h
1 /*
2   Copyright (c) 2018 Martin Wilck, SUSE Linux GmbH
3
4   This program is free software; you can redistribute it and/or
5   modify it under the terms of the GNU General Public License
6   as published by the Free Software Foundation; either version 2
7   of the License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 #ifndef _GENERIC_H
18 #define _GENERIC_H
19 #include "vector.h"
20
21 struct strbuf;
22 struct gen_multipath;
23 struct gen_pathgroup;
24 struct gen_path;
25
26 /**
27  * Methods implemented for gen_multipath "objects"
28  */
29 struct gen_multipath_ops {
30         /**
31          * method: get_pathgroups(gmp)
32          * caller is responsible to returned data using rel_pathgroups()
33          * caller is also responsible to lock the gmp (directly or indirectly)
34          * while working with the return value.
35          * @param gmp: generic multipath object to act on
36          * @returns a vector of const struct gen_pathgroup*
37          */
38         const struct _vector* (*get_pathgroups)(const struct gen_multipath*);
39         /**
40          * method: rel_pathgroups(gmp, v)
41          * free data allocated by get_pathgroups(), if any
42          * @param gmp: generic multipath object to act on
43          * @param v the value returned by get_pathgroups()
44          */
45         void (*rel_pathgroups)(const struct gen_multipath*,
46                                const struct _vector*);
47         /**
48          * method: snprint(gmp, buf, len, wildcard)
49          * prints the property of the multipath map matching
50          * the passed-in wildcard character into "buf",
51          * 0-terminated, no more than "len" characters including trailing '\0'.
52          *
53          * @param gmp: generic multipath object to act on
54          * @param buf: output struct strbuf
55          * @param wildcard: the multipath wildcard (see print.c)
56          * @returns the number of characters printed (without trailing '\0').
57          */
58         int (*snprint)(const struct gen_multipath*,
59                        struct strbuf *buf, char wildcard);
60         /**
61          * method: style(gmp, buf, len, verbosity)
62          * returns the format string to be used for the multipath object,
63          * defined with the wildcards as defined in print.c
64          * generic_style() should work well in most cases.
65          * @param gmp: generic multipath object to act on
66          * @param buf: output strbuf
67          * @param verbosity: verbosity level
68          * @returns number of format chars printed
69          */
70         int (*style)(const struct gen_multipath*,
71                      struct strbuf *buf, int verbosity);
72 };
73
74 /**
75  * Methods implemented for gen_pathgroup "objects"
76  */
77 struct gen_pathgroup_ops {
78         /**
79          * method: get_paths(gpg)
80          * caller is responsible to returned data using rel_paths()
81          * @param gpg: generic pathgroup object to act on
82          * @returns a vector of const struct gen_path*
83          */
84         const struct _vector* (*get_paths)(const struct gen_pathgroup*);
85         /**
86          * method: rel_paths(gpg, v)
87          * free data allocated by get_paths(), if any
88          * @param gmp: generic pathgroup object to act on
89          * @param v the value returned by get_paths()
90          */
91         void (*rel_paths)(const struct gen_pathgroup*, const struct _vector*);
92         /**
93          * Method snprint()
94          * see gen_multipath_ops->snprint() above
95          */
96         int (*snprint)(const struct gen_pathgroup*,
97                        struct strbuf *buf, char wildcard);
98 };
99
100 struct gen_path_ops {
101         /**
102          * Method snprint()
103          * see gen_multipath_ops->snprint() above
104          */
105         int (*snprint)(const struct gen_path*,
106                        struct strbuf *buf, char wildcard);
107 };
108
109 struct gen_multipath {
110         const struct gen_multipath_ops *ops;
111 };
112
113 struct gen_pathgroup {
114         const struct gen_pathgroup_ops *ops;
115 };
116
117 struct gen_path {
118         const struct gen_path_ops *ops;
119 };
120
121 /**
122  * Helper functions for setting up the various generic_X_ops
123  */
124
125 /**
126  * generic_style()
127  * A simple style() method (see above) that should fit most
128  * foreign libraries.
129  */
130 int generic_style(const struct gen_multipath*,
131                   struct strbuf *buf, int verbosity);
132
133 #endif /* _GENERIC_H */