2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2004 Stefan Bader, IBM
7 #include <libdevmapper.h>
15 #include "structs_vec.h"
22 pp = (struct path *)MALLOC(sizeof(struct path));
25 pp->sg_id.host_no = -1;
26 pp->sg_id.channel = -1;
27 pp->sg_id.scsi_id = -1;
35 free_path (struct path * pp)
40 if (pp->checker_context)
41 free(pp->checker_context);
50 free_pathvec (vector vec, int free_paths)
59 vector_foreach_slot(vec, pp, i)
66 alloc_pathgroup (void)
68 struct pathgroup * pgp;
70 pgp = (struct pathgroup *)MALLOC(sizeof(struct pathgroup));
75 pgp->paths = vector_alloc();
84 free_pathgroup (struct pathgroup * pgp, int free_paths)
89 free_pathvec(pgp->paths, free_paths);
94 free_pgvec (vector pgvec, int free_paths)
97 struct pathgroup * pgp;
102 vector_foreach_slot(pgvec, pgp, i)
103 free_pathgroup(pgp, free_paths);
109 alloc_multipath (void)
111 struct multipath * mpp;
113 mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
122 free_multipath_attributes (struct multipath * mpp)
128 mpp->selector != conf->selector &&
129 (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) &&
130 (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) {
132 mpp->selector = NULL;
136 mpp->features != conf->features &&
137 (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) {
139 mpp->features = NULL;
142 if (mpp->hwhandler &&
143 mpp->hwhandler != conf->default_hwhandler &&
144 (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) {
145 FREE(mpp->hwhandler);
146 mpp->hwhandler = NULL;
151 free_multipath (struct multipath * mpp, int free_paths)
156 free_multipath_attributes(mpp);
159 (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) &&
160 (mpp->wwid && mpp->alias != mpp->wwid)) {
170 * better own vecs->lock here
173 ((struct event_thread *)mpp->waiter)->mpp = NULL;
176 free_pathvec(mpp->paths, free_paths);
177 free_pgvec(mpp->pg, free_paths);
182 drop_multipath (vector mpvec, char * wwid, int free_paths)
185 struct multipath * mpp;
190 vector_foreach_slot (mpvec, mpp, i) {
191 if (!strncmp(mpp->wwid, wwid, WWID_SIZE)) {
192 free_multipath(mpp, free_paths);
193 vector_del_slot(mpvec, i);
200 free_multipathvec (vector mpvec, int free_paths)
203 struct multipath * mpp;
208 vector_foreach_slot (mpvec, mpp, i)
209 free_multipath(mpp, free_paths);
215 store_path (vector pathvec, struct path * pp)
217 if (!vector_alloc_slot(pathvec))
220 vector_set_slot(pathvec, pp);
226 store_pathgroup (vector pgvec, struct pathgroup * pgp)
228 if (!vector_alloc_slot(pgvec))
231 vector_set_slot(pgvec, pgp);
237 find_mp_by_minor (vector mpvec, int minor)
240 struct multipath * mpp;
245 vector_foreach_slot (mpvec, mpp, i) {
249 if (mpp->dmi->minor == minor)
256 find_mp_by_wwid (vector mpvec, char * wwid)
259 struct multipath * mpp;
264 vector_foreach_slot (mpvec, mpp, i)
265 if (!strncmp(mpp->wwid, wwid, WWID_SIZE))
272 find_mp_by_alias (vector mpvec, char * alias)
276 struct multipath * mpp;
286 vector_foreach_slot (mpvec, mpp, i) {
287 if (strlen(mpp->alias) == len &&
288 !strncmp(mpp->alias, alias, len))
295 find_path_by_dev (vector pathvec, char * dev)
303 vector_foreach_slot (pathvec, pp, i)
304 if (!strcmp_chomp(pp->dev, dev))
307 condlog(3, "%s: not found in pathvec", dev);
312 find_path_by_devt (vector pathvec, char * dev_t)
320 vector_foreach_slot (pathvec, pp, i)
321 if (!strcmp_chomp(pp->dev_t, dev_t))
324 condlog(3, "%s: not found in pathvec", dev_t);
329 pathcount (struct multipath * mpp, int state)
331 struct pathgroup *pgp;
336 vector_foreach_slot (mpp->pg, pgp, i)
337 vector_foreach_slot (pgp->paths, pp, j)
338 if ((pp->state == state) || (state < 0))