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();
89 free_pathgroup (struct pathgroup * pgp, int free_paths)
94 free_pathvec(pgp->paths, free_paths);
99 free_pgvec (vector pgvec, int free_paths)
102 struct pathgroup * pgp;
107 vector_foreach_slot(pgvec, pgp, i)
108 free_pathgroup(pgp, free_paths);
114 alloc_multipath (void)
116 struct multipath * mpp;
118 mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
122 mpp->mpcontext = NULL;
128 free_multipath_attributes (struct multipath * mpp)
134 mpp->selector != conf->selector &&
135 (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) &&
136 (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) {
138 mpp->selector = NULL;
142 mpp->features != conf->features &&
143 (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) {
145 mpp->features = NULL;
148 if (mpp->hwhandler &&
149 mpp->hwhandler != conf->hwhandler &&
150 (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) {
151 FREE(mpp->hwhandler);
152 mpp->hwhandler = NULL;
157 free_multipath (struct multipath * mpp, int free_paths)
162 free_multipath_attributes(mpp);
165 (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) &&
166 (mpp->wwid && mpp->alias != mpp->wwid)) {
176 * better own vecs->lock here
179 ((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 < 0))
361 pathcount (struct multipath * mpp, int state)
363 struct pathgroup *pgp;
367 vector_foreach_slot (mpp->pg, pgp, i)
368 count += pathcountgr(pgp, state);
374 first_path (struct multipath * mpp)
376 struct pathgroup * pgp = VECTOR_SLOT(mpp->pg, 0);
377 return VECTOR_SLOT(pgp->paths, 0);