[typo] s/controler/controller/g
[platform/upstream/multipath-tools.git] / libmultipath / propsel.c
1 /*
2  * Copyright (c) 2004, 2005 Christophe Varoqui
3  * Copyright (c) 2005 Benjamin Marzinski, Redhat
4  * Copyright (c) 2005 Kiyoshi Ueda, NEC
5  */
6 #include <stdio.h>
7
8 #include <checkers.h>
9
10 #include "memory.h"
11 #include "vector.h"
12 #include "structs.h"
13 #include "config.h"
14 #include "debug.h"
15 #include "pgpolicies.h"
16 #include "alias.h"
17 #include "defaults.h"
18 #include "devmapper.h"
19
20 pgpolicyfn *pgpolicies[] = {
21         NULL,
22         one_path_per_group,
23         one_group,
24         group_by_serial,
25         group_by_prio,
26         group_by_node_name
27 };
28
29 /*
30  * selectors :
31  * traverse the configuration layers from most specific to most generic
32  * stop at first explicit setting found
33  */
34 extern int
35 select_rr_weight (struct multipath * mp)
36 {
37         if (mp->mpe && mp->mpe->rr_weight) {
38                 mp->rr_weight = mp->mpe->rr_weight;
39                 condlog(3, "%s: rr_weight = %i (LUN setting)",
40                         mp->alias, mp->rr_weight);
41                 return 0;
42         }
43         if (mp->hwe && mp->hwe->rr_weight) {
44                 mp->rr_weight = mp->hwe->rr_weight;
45                 condlog(3, "%s: rr_weight = %i (controller setting)",
46                         mp->alias, mp->rr_weight);
47                 return 0;
48         }
49         if (conf->rr_weight) {
50                 mp->rr_weight = conf->rr_weight;
51                 condlog(3, "%s: rr_weight = %i (config file default)",
52                         mp->alias, mp->rr_weight);
53                 return 0;
54         }
55         mp->rr_weight = RR_WEIGHT_NONE;
56         condlog(3, "%s: rr_weight = %i (internal default)",
57                 mp->alias, mp->rr_weight);
58         return 0;
59 }
60
61 extern int
62 select_pgfailback (struct multipath * mp)
63 {
64         if (mp->mpe && mp->mpe->pgfailback != FAILBACK_UNDEF) {
65                 mp->pgfailback = mp->mpe->pgfailback;
66                 condlog(3, "%s: pgfailback = %i (LUN setting)",
67                         mp->alias, mp->pgfailback);
68                 return 0;
69         }
70         if (mp->hwe && mp->hwe->pgfailback != FAILBACK_UNDEF) {
71                 mp->pgfailback = mp->hwe->pgfailback;
72                 condlog(3, "%s: pgfailback = %i (controller setting)",
73                         mp->alias, mp->pgfailback);
74                 return 0;
75         }
76         if (conf->pgfailback != FAILBACK_UNDEF) {
77                 mp->pgfailback = conf->pgfailback;
78                 condlog(3, "%s: pgfailback = %i (config file default)",
79                         mp->alias, mp->pgfailback);
80                 return 0;
81         }
82         mp->pgfailback = DEFAULT_FAILBACK;
83         condlog(3, "%s: pgfailover = %i (internal default)",
84                 mp->alias, mp->pgfailback);
85         return 0;
86 }
87
88 extern int
89 select_pgpolicy (struct multipath * mp)
90 {
91         char pgpolicy_name[POLICY_NAME_SIZE];
92
93         if (conf->pgpolicy_flag > 0) {
94                 mp->pgpolicy = conf->pgpolicy_flag;
95                 mp->pgpolicyfn = pgpolicies[mp->pgpolicy];
96                 get_pgpolicy_name(pgpolicy_name, POLICY_NAME_SIZE,
97                                   mp->pgpolicy);
98                 condlog(3, "%s: pgpolicy = %s (cmd line flag)",
99                         mp->alias, pgpolicy_name);
100                 return 0;
101         }
102         if (mp->mpe && mp->mpe->pgpolicy > 0) {
103                 mp->pgpolicy = mp->mpe->pgpolicy;
104                 mp->pgpolicyfn = pgpolicies[mp->pgpolicy];
105                 get_pgpolicy_name(pgpolicy_name, POLICY_NAME_SIZE,
106                                   mp->pgpolicy);
107                 condlog(3, "%s: pgpolicy = %s (LUN setting)",
108                         mp->alias, pgpolicy_name);
109                 return 0;
110         }
111         if (mp->hwe && mp->hwe->pgpolicy > 0) {
112                 mp->pgpolicy = mp->hwe->pgpolicy;
113                 mp->pgpolicyfn = pgpolicies[mp->pgpolicy];
114                 get_pgpolicy_name(pgpolicy_name, POLICY_NAME_SIZE,
115                                   mp->pgpolicy);
116                 condlog(3, "%s: pgpolicy = %s (controller setting)",
117                         mp->alias, pgpolicy_name);
118                 return 0;
119         }
120         if (conf->pgpolicy > 0) {
121                 mp->pgpolicy = conf->pgpolicy;
122                 mp->pgpolicyfn = pgpolicies[mp->pgpolicy];
123                 get_pgpolicy_name(pgpolicy_name, POLICY_NAME_SIZE,
124                                   mp->pgpolicy);
125                 condlog(3, "%s: pgpolicy = %s (config file default)",
126                         mp->alias, pgpolicy_name);
127                 return 0;
128         }
129         mp->pgpolicy = DEFAULT_PGPOLICY;
130         mp->pgpolicyfn = pgpolicies[mp->pgpolicy];
131         get_pgpolicy_name(pgpolicy_name, POLICY_NAME_SIZE, mp->pgpolicy);
132         condlog(3, "%s: pgpolicy = %s (internal default)",
133                 mp->alias, pgpolicy_name);
134         return 0;
135 }
136
137 extern int
138 select_selector (struct multipath * mp)
139 {
140         if (mp->mpe && mp->mpe->selector) {
141                 mp->selector = mp->mpe->selector;
142                 condlog(3, "%s: selector = %s (LUN setting)",
143                         mp->alias, mp->selector);
144                 return 0;
145         }
146         if (mp->hwe && mp->hwe->selector) {
147                 mp->selector = mp->hwe->selector;
148                 condlog(3, "%s: selector = %s (controller setting)",
149                         mp->alias, mp->selector);
150                 return 0;
151         }
152         mp->selector = conf->selector;
153         condlog(3, "%s: selector = %s (internal default)",
154                 mp->alias, mp->selector);
155         return 0;
156 }
157
158 extern int
159 select_alias (struct multipath * mp)
160 {
161         if (mp->mpe && mp->mpe->alias)
162                 mp->alias = mp->mpe->alias;
163         else {
164                 mp->alias = NULL;
165                 if (conf->user_friendly_names)
166                         mp->alias = get_user_friendly_alias(mp->wwid,
167                                         conf->bindings_file);
168                 if (mp->alias == NULL){
169                         char *alias;
170                         if ((alias = MALLOC(WWID_SIZE)) != NULL){
171                                 if (dm_get_name(mp->wwid, DEFAULT_TARGET,
172                                                 alias) == 1)
173                                         mp->alias = alias;
174                                 else
175                                         FREE(alias);
176                         }
177                 }
178                 if (mp->alias == NULL)
179                         mp->alias = mp->wwid;
180         }
181
182         return 0;
183 }
184
185 extern int
186 select_features (struct multipath * mp)
187 {
188         if (mp->hwe && mp->hwe->features) {
189                 mp->features = mp->hwe->features;
190                 condlog(3, "%s: features = %s (controller setting)",
191                         mp->alias, mp->features);
192                 return 0;
193         }
194         mp->features = conf->features;
195         condlog(3, "%s: features = %s (internal default)",
196                 mp->alias, mp->features);
197         return 0;
198 }
199
200 extern int
201 select_hwhandler (struct multipath * mp)
202 {
203         if (mp->hwe && mp->hwe->hwhandler) {
204                 mp->hwhandler = mp->hwe->hwhandler;
205                 condlog(3, "%s: hwhandler = %s (controller setting)",
206                         mp->alias, mp->hwhandler);
207                 return 0;
208         }
209         mp->hwhandler = conf->hwhandler;
210         condlog(3, "%s: hwhandler = %s (internal default)",
211                 mp->alias, mp->hwhandler);
212         return 0;
213 }
214
215 extern int
216 select_checker(struct path *pp)
217 {
218         struct checker * c = &pp->checker;
219
220         if (pp->hwe && pp->hwe->checker) {
221                 checker_get(c, pp->hwe->checker);
222                 condlog(3, "%s: path checker = %s (controller setting)",
223                         pp->dev, checker_name(c));
224                 return 0;
225         }
226         if (conf->checker) {
227                 checker_get(c, conf->checker);
228                 condlog(3, "%s: path checker = %s (config file default)",
229                         pp->dev, checker_name(c));
230                 return 0;
231         }
232         checker_get(c, checker_default());
233         condlog(3, "%s: path checker = %s (internal default)",
234                 pp->dev, checker_name(c));
235         return 0;
236 }
237
238 extern int
239 select_getuid (struct path * pp)
240 {
241         if (pp->hwe && pp->hwe->getuid) {
242                 pp->getuid = pp->hwe->getuid;
243                 condlog(3, "%s: getuid = %s (controller setting)",
244                         pp->dev, pp->getuid);
245                 return 0;
246         }
247         if (conf->getuid) {
248                 pp->getuid = conf->getuid;
249                 condlog(3, "%s: getuid = %s (config file default)",
250                         pp->dev, pp->getuid);
251                 return 0;
252         }
253         pp->getuid = STRDUP(DEFAULT_GETUID);
254         condlog(3, "%s: getuid = %s (internal default)",
255                 pp->dev, pp->getuid);
256         return 0;
257 }
258
259 extern int
260 select_getprio (struct path * pp)
261 {
262         if (pp->hwe && pp->hwe->getprio) {
263                 pp->getprio = pp->hwe->getprio;
264                 condlog(3, "%s: getprio = %s (controller setting)",
265                         pp->dev, pp->getprio);
266                 return 0;
267         }
268         if (conf->getprio) {
269                 pp->getprio = conf->getprio;
270                 condlog(3, "%s: getprio = %s (config file default)",
271                         pp->dev, pp->getprio);
272                 return 0;
273         }
274         pp->getprio = DEFAULT_GETPRIO;
275         condlog(3, "%s: getprio = NULL (internal default)", pp->dev);
276         return 0;
277 }
278
279 extern int
280 select_no_path_retry(struct multipath *mp)
281 {
282         if (mp->mpe && mp->mpe->no_path_retry != NO_PATH_RETRY_UNDEF) {
283                 mp->no_path_retry = mp->mpe->no_path_retry;
284                 condlog(3, "%s: no_path_retry = %i (multipath setting)",
285                         mp->alias, mp->no_path_retry);
286                 return 0;
287         }
288         if (mp->hwe && mp->hwe->no_path_retry != NO_PATH_RETRY_UNDEF) {
289                 mp->no_path_retry = mp->hwe->no_path_retry;
290                 condlog(3, "%s: no_path_retry = %i (controller setting)",
291                         mp->alias, mp->no_path_retry);
292                 return 0;
293         }
294         if (conf->no_path_retry != NO_PATH_RETRY_UNDEF) {
295                 mp->no_path_retry = conf->no_path_retry;
296                 condlog(3, "%s: no_path_retry = %i (config file default)",
297                         mp->alias, mp->no_path_retry);
298                 return 0;
299         }
300         mp->no_path_retry = NO_PATH_RETRY_UNDEF;
301         condlog(3, "%s: no_path_retry = NONE (internal default)",
302                 mp->alias);
303         return 0;
304 }
305
306 extern int
307 select_minio (struct multipath * mp)
308 {
309         if (mp->mpe && mp->mpe->minio) {
310                 mp->minio = mp->mpe->minio;
311                 condlog(3, "%s: minio = %i (LUN setting)",
312                         mp->alias, mp->minio);
313                 return 0;
314         }
315         if (mp->hwe && mp->hwe->minio) {
316                 mp->minio = mp->hwe->minio;
317                 condlog(3, "%s: minio = %i (controller setting)",
318                         mp->alias, mp->minio);
319                 return 0;
320         }
321         if (conf->minio) {
322                 mp->minio = conf->minio;
323                 condlog(3, "%s: minio = %i (config file default)",
324                         mp->alias, mp->minio);
325                 return 0;
326         }
327         mp->minio = DEFAULT_MINIO;
328         condlog(3, "%s: minio = %i (internal default)",
329                 mp->alias, mp->minio);
330         return 0;
331 }
332