2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2004 Stefan Bader, IBM
7 #include <libdevmapper.h>
15 #include "structs_vec.h"
16 #include "blacklist.h"
23 pp = (struct path *)MALLOC(sizeof(struct path));
26 pp->sg_id.host_no = -1;
27 pp->sg_id.channel = -1;
28 pp->sg_id.scsi_id = -1;
36 free_path (struct path * pp)
41 if (pp->checker_context)
42 free(pp->checker_context);
51 free_pathvec (vector vec, int free_paths)
60 vector_foreach_slot(vec, pp, i)
67 alloc_pathgroup (void)
69 struct pathgroup * pgp;
71 pgp = (struct pathgroup *)MALLOC(sizeof(struct pathgroup));
76 pgp->paths = vector_alloc();
85 free_pathgroup (struct pathgroup * pgp, int free_paths)
90 free_pathvec(pgp->paths, free_paths);
95 free_pgvec (vector pgvec, int free_paths)
98 struct pathgroup * pgp;
103 vector_foreach_slot(pgvec, pgp, i)
104 free_pathgroup(pgp, free_paths);
110 alloc_multipath (void)
112 struct multipath * mpp;
114 mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
123 free_multipath_attributes (struct multipath * mpp)
129 mpp->selector != conf->selector &&
130 (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) &&
131 (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) {
133 mpp->selector = NULL;
137 mpp->features != conf->features &&
138 (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) {
140 mpp->features = NULL;
143 if (mpp->hwhandler &&
144 mpp->hwhandler != conf->default_hwhandler &&
145 (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) {
146 FREE(mpp->hwhandler);
147 mpp->hwhandler = NULL;
152 free_multipath (struct multipath * mpp, int free_paths)
157 free_multipath_attributes(mpp);
160 (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) &&
161 (mpp->wwid && mpp->alias != mpp->wwid)) {
171 * better own vecs->lock here
174 ((struct event_thread *)mpp->waiter)->mpp = NULL;
177 free_pathvec(mpp->paths, free_paths);
178 free_pgvec(mpp->pg, free_paths);
183 drop_multipath (vector mpvec, char * wwid, int free_paths)
186 struct multipath * mpp;
191 vector_foreach_slot (mpvec, mpp, i) {
192 if (!strncmp(mpp->wwid, wwid, WWID_SIZE)) {
193 free_multipath(mpp, free_paths);
194 vector_del_slot(mpvec, i);
201 free_multipathvec (vector mpvec, int free_paths)
204 struct multipath * mpp;
209 vector_foreach_slot (mpvec, mpp, i)
210 free_multipath(mpp, free_paths);
216 store_path (vector pathvec, struct path * pp)
218 if (!vector_alloc_slot(pathvec))
221 vector_set_slot(pathvec, pp);
227 store_pathgroup (vector pgvec, struct pathgroup * pgp)
229 if (!vector_alloc_slot(pgvec))
232 vector_set_slot(pgvec, pgp);
238 find_mp_by_minor (vector mpvec, int minor)
241 struct multipath * mpp;
246 vector_foreach_slot (mpvec, mpp, i) {
250 if (mpp->dmi->minor == minor)
257 find_mp_by_wwid (vector mpvec, char * wwid)
260 struct multipath * mpp;
265 vector_foreach_slot (mpvec, mpp, i)
266 if (!strncmp(mpp->wwid, wwid, WWID_SIZE))
273 find_mp_by_alias (vector mpvec, char * alias)
277 struct multipath * mpp;
287 vector_foreach_slot (mpvec, mpp, i) {
288 if (strlen(mpp->alias) == len &&
289 !strncmp(mpp->alias, alias, len))
296 find_mp_by_str (vector mpvec, char * str)
300 if (sscanf(str, "dm-%d", &minor) == 1)
301 return find_mp_by_minor(mpvec, minor);
303 return find_mp_by_alias(mpvec, str);
307 find_path_by_dev (vector pathvec, char * dev)
315 vector_foreach_slot (pathvec, pp, i)
316 if (!strcmp_chomp(pp->dev, dev))
319 condlog(3, "%s: not found in pathvec", dev);
324 find_path_by_devt (vector pathvec, char * dev_t)
332 vector_foreach_slot (pathvec, pp, i)
333 if (!strcmp_chomp(pp->dev_t, dev_t))
336 condlog(3, "%s: not found in pathvec", dev_t);
341 pathcount (struct multipath * mpp, int state)
343 struct pathgroup *pgp;
348 vector_foreach_slot (mpp->pg, pgp, i)
349 vector_foreach_slot (pgp->paths, pp, j)
350 if ((pp->state == state) || (state < 0))