2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2004 Stefan Bader, IBM
7 #include <libdevmapper.h>
17 #include "structs_vec.h"
18 #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));
127 free_multipath_attributes (struct multipath * mpp)
133 mpp->selector != conf->selector &&
134 (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) &&
135 (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) {
137 mpp->selector = NULL;
141 mpp->features != conf->features &&
142 (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) {
144 mpp->features = NULL;
147 if (mpp->hwhandler &&
148 mpp->hwhandler != conf->hwhandler &&
149 (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) {
150 FREE(mpp->hwhandler);
151 mpp->hwhandler = NULL;
156 free_multipath (struct multipath * mpp, int free_paths)
161 free_multipath_attributes(mpp);
164 (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) &&
165 (mpp->wwid && mpp->alias != mpp->wwid)) {
175 * better own vecs->lock here
178 ((struct event_thread *)mpp->waiter)->mpp = NULL;
181 free_pathvec(mpp->paths, free_paths);
182 free_pgvec(mpp->pg, free_paths);
187 drop_multipath (vector mpvec, char * wwid, int free_paths)
190 struct multipath * mpp;
195 vector_foreach_slot (mpvec, mpp, i) {
196 if (!strncmp(mpp->wwid, wwid, WWID_SIZE)) {
197 free_multipath(mpp, free_paths);
198 vector_del_slot(mpvec, i);
205 free_multipathvec (vector mpvec, int free_paths)
208 struct multipath * mpp;
213 vector_foreach_slot (mpvec, mpp, i)
214 free_multipath(mpp, free_paths);
220 store_path (vector pathvec, struct path * pp)
222 if (!vector_alloc_slot(pathvec))
225 vector_set_slot(pathvec, pp);
231 store_pathgroup (vector pgvec, struct pathgroup * pgp)
233 if (!vector_alloc_slot(pgvec))
236 vector_set_slot(pgvec, pgp);
242 find_mp_by_minor (vector mpvec, int minor)
245 struct multipath * mpp;
250 vector_foreach_slot (mpvec, mpp, i) {
254 if (mpp->dmi->minor == minor)
261 find_mp_by_wwid (vector mpvec, char * wwid)
264 struct multipath * mpp;
269 vector_foreach_slot (mpvec, mpp, i)
270 if (!strncmp(mpp->wwid, wwid, WWID_SIZE))
277 find_mp_by_alias (vector mpvec, char * alias)
281 struct multipath * mpp;
291 vector_foreach_slot (mpvec, mpp, i) {
292 if (strlen(mpp->alias) == len &&
293 !strncmp(mpp->alias, alias, len))
300 find_mp_by_str (vector mpvec, char * str)
304 if (sscanf(str, "dm-%d", &minor) == 1)
305 return find_mp_by_minor(mpvec, minor);
307 return find_mp_by_alias(mpvec, str);
311 find_path_by_dev (vector pathvec, char * dev)
319 vector_foreach_slot (pathvec, pp, i)
320 if (!strcmp_chomp(pp->dev, dev))
323 condlog(3, "%s: not found in pathvec", dev);
328 find_path_by_devt (vector pathvec, char * dev_t)
336 vector_foreach_slot (pathvec, pp, i)
337 if (!strcmp_chomp(pp->dev_t, dev_t))
340 condlog(3, "%s: not found in pathvec", dev_t);
345 pathcountgr (struct pathgroup * pgp, int state)
351 vector_foreach_slot (pgp->paths, pp, i)
352 if ((pp->state == state) || (state < 0))
359 pathcount (struct multipath * mpp, int state)
361 struct pathgroup *pgp;
365 vector_foreach_slot (mpp->pg, pgp, i)
366 count += pathcountgr(pgp, state);
372 first_path (struct multipath * mpp)
374 struct pathgroup * pgp = VECTOR_SLOT(mpp->pg, 0);
375 return VECTOR_SLOT(pgp->paths, 0);