2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2004 Stefan Bader, IBM
7 #include <libdevmapper.h>
16 #include "structs_vec.h"
17 #include "blacklist.h"
26 pp = (struct path *)MALLOC(sizeof(struct path));
29 pp->sg_id.host_no = -1;
30 pp->sg_id.channel = -1;
31 pp->sg_id.scsi_id = -1;
34 pp->priority = PRIO_UNDEF;
40 free_path (struct path * pp)
45 if (checker_selected(&pp->checker))
46 checker_put(&pp->checker);
55 free_pathvec (vector vec, int free_paths)
64 vector_foreach_slot(vec, pp, i)
71 alloc_pathgroup (void)
73 struct pathgroup * pgp;
75 pgp = (struct pathgroup *)MALLOC(sizeof(struct pathgroup));
80 pgp->paths = vector_alloc();
91 free_pathgroup (struct pathgroup * pgp, int free_paths)
96 free_pathvec(pgp->paths, free_paths);
101 free_pgvec (vector pgvec, int free_paths)
104 struct pathgroup * pgp;
109 vector_foreach_slot(pgvec, pgp, i)
110 free_pathgroup(pgp, free_paths);
116 alloc_multipath (void)
118 struct multipath * mpp;
120 mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
124 mpp->mpcontext = NULL;
130 free_multipath_attributes (struct multipath * mpp)
136 mpp->selector != conf->selector &&
137 (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) &&
138 (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) {
140 mpp->selector = NULL;
144 mpp->features != conf->features &&
145 (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) {
147 mpp->features = NULL;
150 if (mpp->hwhandler &&
151 mpp->hwhandler != conf->hwhandler &&
152 (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) {
153 FREE(mpp->hwhandler);
154 mpp->hwhandler = NULL;
159 free_multipath (struct multipath * mpp, int free_paths)
164 free_multipath_attributes(mpp);
177 * better own vecs->lock here
180 ((struct event_thread *)mpp->waiter)->mpp = NULL;
182 free_pathvec(mpp->paths, free_paths);
183 free_pgvec(mpp->pg, free_paths);
184 FREE_PTR(mpp->mpcontext);
189 drop_multipath (vector mpvec, char * wwid, int free_paths)
192 struct multipath * mpp;
197 vector_foreach_slot (mpvec, mpp, i) {
198 if (!strncmp(mpp->wwid, wwid, WWID_SIZE)) {
199 free_multipath(mpp, free_paths);
200 vector_del_slot(mpvec, i);
207 free_multipathvec (vector mpvec, int free_paths)
210 struct multipath * mpp;
215 vector_foreach_slot (mpvec, mpp, i)
216 free_multipath(mpp, free_paths);
222 store_path (vector pathvec, struct path * pp)
224 if (!vector_alloc_slot(pathvec))
227 vector_set_slot(pathvec, pp);
233 store_pathgroup (vector pgvec, struct pathgroup * pgp)
235 if (!vector_alloc_slot(pgvec))
238 vector_set_slot(pgvec, pgp);
244 find_mp_by_minor (vector mpvec, int minor)
247 struct multipath * mpp;
252 vector_foreach_slot (mpvec, mpp, i) {
256 if (mpp->dmi->minor == minor)
263 find_mp_by_wwid (vector mpvec, char * wwid)
266 struct multipath * mpp;
271 vector_foreach_slot (mpvec, mpp, i)
272 if (!strncmp(mpp->wwid, wwid, WWID_SIZE))
279 find_mp_by_alias (vector mpvec, char * alias)
283 struct multipath * mpp;
293 vector_foreach_slot (mpvec, mpp, i) {
294 if (strlen(mpp->alias) == len &&
295 !strncmp(mpp->alias, alias, len))
302 find_mp_by_str (vector mpvec, char * str)
306 if (sscanf(str, "dm-%d", &minor) == 1)
307 return find_mp_by_minor(mpvec, minor);
309 return find_mp_by_alias(mpvec, str);
313 find_path_by_dev (vector pathvec, char * dev)
321 vector_foreach_slot (pathvec, pp, i)
322 if (!strcmp_chomp(pp->dev, dev))
325 condlog(3, "%s: not found in pathvec", dev);
330 find_path_by_devt (vector pathvec, char * dev_t)
338 vector_foreach_slot (pathvec, pp, i)
339 if (!strcmp_chomp(pp->dev_t, dev_t))
342 condlog(3, "%s: not found in pathvec", dev_t);
347 pathcountgr (struct pathgroup * pgp, int state)
353 vector_foreach_slot (pgp->paths, pp, i)
354 if ((pp->state == state) || (state == PATH_WILD))
361 pathcount (struct multipath * mpp, int state)
363 struct pathgroup *pgp;
368 vector_foreach_slot (mpp->pg, pgp, i)
369 count += pathcountgr(pgp, state);
375 pathcmp (struct pathgroup *pgp, struct pathgroup *cpgp)
378 struct path *pp, *cpp;
379 int pnum = 0, found = 0;
381 vector_foreach_slot(pgp->paths, pp, i) {
383 vector_foreach_slot(cpgp->paths, cpp, j) {
384 if ((long)pp == (long)cpp) {
395 first_path (struct multipath * mpp)
397 struct pathgroup * pgp;
400 pgp = VECTOR_SLOT(mpp->pg, 0);
402 return pgp?VECTOR_SLOT(pgp->paths, 0):NULL;
406 setup_feature(struct multipath * mpp, char *feature)
408 if (!strncmp(feature, "queue_if_no_path", 16))
409 mpp->no_path_retry = NO_PATH_RETRY_QUEUE;