[checkers] multipath-wide shared context for checkers
authorChristophe Varoqui <cvaroqui@zezette.localdomain>
Thu, 23 Nov 2006 21:52:35 +0000 (22:52 +0100)
committerChristophe Varoqui <cvaroqui@zezette.localdomain>
Thu, 23 Nov 2006 21:52:35 +0000 (22:52 +0100)
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().

libcheckers/checkers.c
libcheckers/checkers.h
libmultipath/discovery.c
libmultipath/structs.c
libmultipath/structs.h

index 53770a6..4f6928f 100644 (file)
@@ -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);
 }
 
index 219dfaf..050644a 100644 (file)
@@ -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);
index 6f2059a..a4a7997 100644 (file)
@@ -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);
index db3f824..d36eaef 100644 (file)
@@ -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);
 }
 
index 7db7faa..77dd4af 100644 (file)
@@ -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 {