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