[PVFS2-CVS] commit by bradles in pvfs2/src/io/description: dist-basic.c dist-simple-stripe.c pint-dist-utils.c pint-dist-utils.h pint-distribution.c pint-distribution.h

CVS commit program cvs at parl.clemson.edu
Mon May 17 16:48:27 EDT 2004


Update of /projects/cvsroot/pvfs2/src/io/description
In directory styx.parl.clemson.edu:/tmp/cvs-serv15693/io/description

Modified Files:
	dist-basic.c dist-simple-stripe.c pint-dist-utils.c 
	pint-dist-utils.h pint-distribution.c pint-distribution.h 
Log Message:
Changing distributions to require initialization before use.  Giving
distributions an additional hook/callback to be called once at registration
time for the distribution to allow it to register its parameters and set
parameter defaults as neccesary.


Index: dist-basic.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/description/dist-basic.c,v
diff -p -u -r1.4 -r1.5
--- dist-basic.c	17 May 2004 15:57:02 -0000	1.4
+++ dist-basic.c	17 May 2004 19:48:27 -0000	1.5
@@ -65,6 +65,11 @@ static void decode_lebf(char **pptr, voi
 {
 }
 
+static void registration_init(void* params)
+{
+}
+
+
 static PVFS_basic_params basic_params;
 
 static PINT_dist_methods basic_methods = {
@@ -77,6 +82,7 @@ static PINT_dist_methods basic_methods =
     PINT_dist_default_set_param,
     encode_lebf,
     decode_lebf,
+    registration_init
 };
 
 PINT_dist basic_dist = {

Index: dist-simple-stripe.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/description/dist-simple-stripe.c,v
diff -p -u -r1.4 -r1.5
--- dist-simple-stripe.c	17 May 2004 15:57:03 -0000	1.4
+++ dist-simple-stripe.c	17 May 2004 19:48:27 -0000	1.5
@@ -132,6 +132,14 @@ static void decode_lebf(char **pptr, voi
     decode_PVFS_size(pptr, &dparam->strip_size);
 }
 
+static void registration_init(void* params)
+{
+    PINT_dist_register_param("simple_stripe", "strip_size",
+                             PVFS_simple_stripe_params, strip_size);
+
+}
+    
+
 static PVFS_simple_stripe_params simple_stripe_params = {
 	65536 /* stripe size */
 };
@@ -146,6 +154,7 @@ static PINT_dist_methods simple_stripe_m
     PINT_dist_default_set_param,
     encode_lebf,
     decode_lebf,
+    registration_init
 };
 
 PINT_dist simple_stripe_dist = {

Index: pint-dist-utils.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/description/pint-dist-utils.c,v
diff -p -u -r1.1 -r1.2
--- pint-dist-utils.c	17 May 2004 15:57:03 -0000	1.1
+++ pint-dist-utils.c	17 May 2004 19:48:27 -0000	1.2
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include "pvfs2-dist-simple-stripe.h"
 #include "pint-dist-utils.h"
 
 /* Default distributions */
@@ -52,15 +53,21 @@ static PINT_dist_param_offset* PINT_get_
 /* PINT_dist_initialize implementation */
 int PINT_dist_initialize(void)
 {
-    /* Register the basic distribution 
+    /* Register the basic distribution */
     PINT_register_distribution(&basic_dist);    
-    */
-    /* Register the simple stripe distribution
+    
+    /* Register the simple stripe distribution */
     PINT_register_distribution(&simple_stripe_dist);    
-    */
+    
     return 0;
 }
 
+/* PINT_dist_finalize implementation */
+void PINT_dist_finalize(void)
+{
+    /* Nothing yet */
+}
+
 /*  PINT_dist_default_get_num_dfiles implementation */
 int PINT_dist_default_get_num_dfiles(void* params,
                                      uint32_t num_servers_requested,
@@ -94,6 +101,17 @@ int PINT_dist_default_set_param(const ch
         rc = -1;
     }
     return rc;
+}
+
+int PINT_dist_register_param_offset(const char* dist_name,
+                                    const char* param_name,
+                                    size_t offset,
+                                    size_t field_size)
+{
+    /*fprintf(stderr, "Attempting to reg: %s %s %u %u\n",
+            dist_name, param_name, offset, field_size);
+    */
+    return 0;
 }
 
 /*

Index: pint-dist-utils.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/description/pint-dist-utils.h,v
diff -p -u -r1.1 -r1.2
--- pint-dist-utils.h	17 May 2004 15:57:03 -0000	1.1
+++ pint-dist-utils.h	17 May 2004 19:48:27 -0000	1.2
@@ -11,9 +11,14 @@
 
 /**
  * Perform initialization tasks for distributions
- *   register the default distributions
+ *   - register the default distributions
  */
-int PINT_dist_intialize(void);
+int PINT_dist_initialize(void);
+
+/**
+ * Perform cleanup actions before exiting
+ */
+void PINT_dist_finalize(void);
 
 /**
  * Utility default implmentation for PINT_dist_methods get_num_dfiles
@@ -28,15 +33,37 @@ int PINT_dist_default_get_num_dfiles(voi
 /**
  * Utility default implmentation for PINT_dist_methods set_param
  *
- * Returns the number of dfiles suggested by hint parameter
+ * Sets the specified parameter.  The parameter must have been registered
+ * with PINT_dist_register_param or PINT_dist_register_param_offset, so
+ * implementation may not work correctly with complex structs or pointer
+ * values.
  */
 int PINT_dist_default_set_param(const char* dist_name, void* params,
                                 const char* param_name, void* value);
 
 /**
+ * Register the parameter offset.
+ *
+ * Use PINT_dist_register_param to avoid having to determine the offset
+ * and field size.
+ */
+int PINT_dist_register_param_offset(const char* dist_name,
+                             const char* param_name,
+                             size_t offset,
+                             size_t field_size);
+
+/**
+ * Wrapper macro to make adding parameter fields easy.
  *
+ * Uses the offsetof trick to locate the offset for the struct field
+ * and the sizeof operator to determine the size.  This is only reliable
+ * with POD data, complex structs and pointers may not work as expected.
  */
-#define PINT_dist_register_parameter(dname, pname, params, field) NULL
+#define PINT_dist_register_param(dname, pname, param_type, param_member) \
+    PINT_dist_register_param_offset(dname, pname, \
+                                    (size_t)&((param_type*)0)->param_member, \
+                                    sizeof(((param_type*)0)->param_member))
+
 
 #endif
 

Index: pint-distribution.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/description/pint-distribution.c,v
diff -p -u -r1.14 -r1.15
--- pint-distribution.c	17 May 2004 15:57:03 -0000	1.14
+++ pint-distribution.c	17 May 2004 19:48:27 -0000	1.15
@@ -15,27 +15,29 @@
 
 /* global size of dist table */
 #define PINT_DIST_TABLE_SZ 8
-static int PINT_Dist_count = 2; 
+static int PINT_Dist_count = 0; 
 
 /* compiled-in distributions */
 extern PINT_dist basic_dist;
 extern PINT_dist simple_stripe_dist;
 
 /* initial dist table - default dists */
-PINT_dist* PINT_Dist_table[PINT_DIST_TABLE_SZ] = {
-    &basic_dist,
-    &simple_stripe_dist,
-    NULL
-};
+PINT_dist* PINT_Dist_table[PINT_DIST_TABLE_SZ] = {0};
 
 /*
  * add a dist to dist table
  */
 int PINT_register_distribution(PINT_dist *d_p)
 {
-    if (PINT_Dist_count < PINT_DIST_TABLE_SZ)
+    if (0 != d_p &&
+        PINT_Dist_count < PINT_DIST_TABLE_SZ)
     {
+        /* Register dist */
         PINT_Dist_table[PINT_Dist_count++] = d_p;
+
+        /* Perform dist specific registration code */
+        d_p->methods->registration_init(d_p->params);
+        
         return (0);
     }
     return (-1);

Index: pint-distribution.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/description/pint-distribution.h,v
diff -p -u -r1.7 -r1.8
--- pint-distribution.h	17 May 2004 15:57:03 -0000	1.7
+++ pint-distribution.h	17 May 2004 19:48:27 -0000	1.8
@@ -60,6 +60,9 @@ typedef struct PINT_dist_methods_s {
     /* Restores parameters in lebf memory at pptr */
     void (*decode_lebf)(char **pptr, void* params);
 
+    /* Called when the distribution is registered */
+    void (*registration_init)(void* params);
+    
 } PINT_dist_methods;
 
 /* Internal representation of a PVFS2 Distribution */



More information about the PVFS2-CVS mailing list