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"
27 pp = (struct path *)MALLOC(sizeof(struct path));
30 pp->sg_id.host_no = -1;
31 pp->sg_id.channel = -1;
32 pp->sg_id.scsi_id = -1;
35 pp->priority = PRIO_UNDEF;
41 free_path (struct path * pp)
46 if (checker_selected(&pp->checker))
47 checker_put(&pp->checker);
56 free_pathvec (vector vec, int free_paths)
65 vector_foreach_slot(vec, pp, i)
72 alloc_pathgroup (void)
74 struct pathgroup * pgp;
76 pgp = (struct pathgroup *)MALLOC(sizeof(struct pathgroup));
81 pgp->paths = vector_alloc();
90 free_pathgroup (struct pathgroup * pgp, int free_paths)
95 free_pathvec(pgp->paths, free_paths);
100 free_pgvec (vector pgvec, int free_paths)
103 struct pathgroup * pgp;
108 vector_foreach_slot(pgvec, pgp, i)
109 free_pathgroup(pgp, free_paths);
115 alloc_multipath (void)
117 struct multipath * mpp;
119 mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
123 mpp->mpcontext = NULL;
129 free_multipath_attributes (struct multipath * mpp)
135 mpp->selector != conf->selector &&
136 (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) &&
137 (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) {
139 mpp->selector = NULL;
143 mpp->features != conf->features &&
144 (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) {
146 mpp->features = NULL;
149 if (mpp->hwhandler &&
150 mpp->hwhandler != conf->hwhandler &&
151 (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) {
152 FREE(mpp->hwhandler);
153 mpp->hwhandler = NULL;
158 free_multipath (struct multipath * mpp, int free_paths)
163 free_multipath_attributes(mpp);
166 (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) &&
167 (mpp->wwid && mpp->alias != mpp->wwid)) {
177 * better own vecs->lock here
180 ((struct event_thread *)mpp->waiter)->mpp = NULL;
183 free_pathvec(mpp->paths, free_paths);
184 free_pgvec(mpp->pg, free_paths);
185 FREE_PTR(mpp->mpcontext);
190 drop_multipath (vector mpvec, char * wwid, int free_paths)
193 struct multipath * mpp;
198 vector_foreach_slot (mpvec, mpp, i) {
199 if (!strncmp(mpp->wwid, wwid, WWID_SIZE)) {
200 free_multipath(mpp, free_paths);
201 vector_del_slot(mpvec, i);
208 free_multipathvec (vector mpvec, int free_paths)
211 struct multipath * mpp;
216 vector_foreach_slot (mpvec, mpp, i)
217 free_multipath(mpp, free_paths);
223 store_path (vector pathvec, struct path * pp)
225 if (!vector_alloc_slot(pathvec))
228 vector_set_slot(pathvec, pp);
234 store_pathgroup (vector pgvec, struct pathgroup * pgp)
236 if (!vector_alloc_slot(pgvec))
239 vector_set_slot(pgvec, pgp);
245 find_mp_by_minor (vector mpvec, int minor)
248 struct multipath * mpp;
253 vector_foreach_slot (mpvec, mpp, i) {
257 if (mpp->dmi->minor == minor)
264 find_mp_by_wwid (vector mpvec, char * wwid)
267 struct multipath * mpp;
272 vector_foreach_slot (mpvec, mpp, i)
273 if (!strncmp(mpp->wwid, wwid, WWID_SIZE))
280 find_mp_by_alias (vector mpvec, char * alias)
284 struct multipath * mpp;
294 vector_foreach_slot (mpvec, mpp, i) {
295 if (strlen(mpp->alias) == len &&
296 !strncmp(mpp->alias, alias, len))
303 find_mp_by_str (vector mpvec, char * str)
307 if (sscanf(str, "dm-%d", &minor) == 1)
308 return find_mp_by_minor(mpvec, minor);
310 return find_mp_by_alias(mpvec, str);
314 find_path_by_dev (vector pathvec, char * dev)
322 vector_foreach_slot (pathvec, pp, i)
323 if (!strcmp_chomp(pp->dev, dev))
326 condlog(3, "%s: not found in pathvec", dev);
331 find_path_by_devt (vector pathvec, char * dev_t)
339 vector_foreach_slot (pathvec, pp, i)
340 if (!strcmp_chomp(pp->dev_t, dev_t))
343 condlog(3, "%s: not found in pathvec", dev_t);
348 pathcountgr (struct pathgroup * pgp, int state)
354 vector_foreach_slot (pgp->paths, pp, i)
355 if ((pp->state == state) || (state < 0))
362 pathcount (struct multipath * mpp, int state)
364 struct pathgroup *pgp;
368 vector_foreach_slot (mpp->pg, pgp, i)
369 count += pathcountgr(pgp, state);
375 first_path (struct multipath * mpp)
377 struct pathgroup * pgp = VECTOR_SLOT(mpp->pg, 0);
378 return VECTOR_SLOT(pgp->paths, 0);