From: Christophe Varoqui Date: Thu, 23 Nov 2006 21:52:35 +0000 (+0100) Subject: [checkers] multipath-wide shared context for checkers X-Git-Tag: 0.4.8~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0685846d00f41e7d2ec537beb9f783e41efa3f9c;p=platform%2Fupstream%2Fmultipath-tools.git [checkers] multipath-wide shared context for checkers At least one checker need to shared data between checkers attached to all paths of a multipath. This patch addresses this need by adding a "void * mpcontext" to struct multipath, and its "void **" sibling in struct checker. checker_init() ensures the multipath->mpcontext is attached to *checker->mpcontext. Checkers are in charge of allocating the memory block and attaching it to *checker->mpcontext. the .init checker function is a natural place for that. Freeing the mpcontext in done in free_multipath(). --- diff --git a/libcheckers/checkers.c b/libcheckers/checkers.c index 53770a6..4f6928f 100644 --- a/libcheckers/checkers.c +++ b/libcheckers/checkers.c @@ -75,8 +75,9 @@ struct checker * checker_lookup (char * name) return NULL; } -int checker_init (struct checker * c) +int checker_init (struct checker * c, void ** mpctxt_addr) { + c->mpcontext = mpctxt_addr; return c->init(c); } diff --git a/libcheckers/checkers.h b/libcheckers/checkers.h index 219dfaf..050644a 100644 --- a/libcheckers/checkers.h +++ b/libcheckers/checkers.h @@ -83,6 +83,8 @@ struct checker { char name[CHECKER_NAME_LEN]; char message[CHECKER_MSG_LEN]; /* comm with callers */ void * context; /* store for persistent data */ + void ** mpcontext; /* store for persistent data + shared multipath-wide */ int (*check)(struct checker *); int (*init)(struct checker *); /* to allocate the context */ void (*free)(struct checker *); /* to free the context */ @@ -90,7 +92,7 @@ struct checker { #define MSG(c, a) snprintf((c)->message, CHECKER_MSG_LEN, a); -int checker_init (struct checker *); +int checker_init (struct checker *, void **); void checker_put (struct checker *); void checker_reset (struct checker * c); void checker_set_fd (struct checker *, int); diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 6f2059a..a4a7997 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -611,12 +611,15 @@ get_state (struct path * pp) { struct checker * c = &pp->checker; + if (!pp->mpp) + return 0; + if (!checker_selected(c)) { select_checker(pp); if (!checker_selected(c)) return 1; checker_set_fd(c, pp->fd); - if (checker_init(c)) + if (checker_init(c, &pp->mpp->mpcontext)) return 1; } pp->state = checker_check(c); diff --git a/libmultipath/structs.c b/libmultipath/structs.c index db3f824..d36eaef 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -117,9 +117,10 @@ alloc_multipath (void) mpp = (struct multipath *)MALLOC(sizeof(struct multipath)); - if (mpp) + if (mpp) { mpp->bestpg = 1; - + mpp->mpcontext = NULL; + } return mpp; } @@ -180,6 +181,7 @@ free_multipath (struct multipath * mpp, int free_paths) free_pathvec(mpp->paths, free_paths); free_pgvec(mpp->pg, free_paths); + FREE_PTR(mpp->mpcontext); FREE(mpp); } diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 7db7faa..77dd4af 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -154,6 +154,9 @@ struct multipath { unsigned int stat_map_loads; unsigned int stat_total_queueing_time; unsigned int stat_queueing_timeouts; + + /* checkers shared data */ + void * mpcontext; }; struct pathgroup {