Imported Upstream version 0.7.8
[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 gen_multipath;
22 struct gen_pathgroup;
23 struct gen_path;
24
25 /**
26  * Methods implemented for gen_multipath "objects"
27  */
28 struct gen_multipath_ops {
29         /**
30          * method: get_pathgroups(gmp)
31          * caller is responsible to returned data using rel_pathgroups()
32          * caller is also responsible to lock the gmp (directly or indirectly)
33          * while working with the return value.
34          * @param gmp: generic multipath object to act on
35          * @returns a vector of const struct gen_pathgroup*
36          */
37         const struct _vector* (*get_pathgroups)(const struct gen_multipath*);
38         /**
39          * method: rel_pathgroups(gmp, v)
40          * free data allocated by get_pathgroups(), if any
41          * @param gmp: generic multipath object to act on
42          * @param v the value returned by get_pathgroups()
43          */
44         void (*rel_pathgroups)(const struct gen_multipath*,
45                                const struct _vector*);
46         /**
47          * method: snprint(gmp, buf, len, wildcard)
48          * prints the property of the multipath map matching
49          * the passed-in wildcard character into "buf",
50          * 0-terminated, no more than "len" characters including trailing '\0'.
51          *
52          * @param gmp: generic multipath object to act on
53          * @param buf: output buffer
54          * @param buflen: buffer size
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                        char *buf, int len, 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 buffer
67          * @param buflen: buffer size
68          * @param verbosity: verbosity level
69          * @returns number of format chars printed
70          */
71         int (*style)(const struct gen_multipath*,
72                      char *buf, int len, int verbosity);
73 };
74
75 /**
76  * Methods implemented for gen_pathgroup "objects"
77  */
78 struct gen_pathgroup_ops {
79         /**
80          * method: get_paths(gpg)
81          * caller is responsible to returned data using rel_paths()
82          * @param gpg: generic pathgroup object to act on
83          * @returns a vector of const struct gen_path*
84          */
85         const struct _vector* (*get_paths)(const struct gen_pathgroup*);
86         /**
87          * method: rel_paths(gpg, v)
88          * free data allocated by get_paths(), if any
89          * @param gmp: generic pathgroup object to act on
90          * @param v the value returned by get_paths()
91          */
92         void (*rel_paths)(const struct gen_pathgroup*, const struct _vector*);
93         /**
94          * Method snprint()
95          * see gen_multipath_ops->snprint() above
96          */
97         int (*snprint)(const struct gen_pathgroup*,
98                        char *buf, int len, char wildcard);
99 };
100
101 struct gen_path_ops {
102         /**
103          * Method snprint()
104          * see gen_multipath_ops->snprint() above
105          */
106         int (*snprint)(const struct gen_path*,
107                        char *buf, int len, char wildcard);
108 };
109
110 struct gen_multipath {
111         const struct gen_multipath_ops *ops;
112 };
113
114 struct gen_pathgroup {
115         const struct gen_pathgroup_ops *ops;
116 };
117
118 struct gen_path {
119         const struct gen_path_ops *ops;
120 };
121
122 /**
123  * Helper functions for setting up the various generic_X_ops
124  */
125
126 /**
127  * generic_style()
128  * A simple style() method (see above) that should fit most
129  * foreign libraries.
130  */
131 int generic_style(const struct gen_multipath*,
132                   char *buf, int len, int verbosity);
133
134 #endif /* _GENERIC_H */