home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / src / io / description / pint-distribution.h < prev    next >
C/C++ Source or Header  |  2010-12-21  |  6KB  |  167 lines

  1. /*
  2.  * (C) 2002 Clemson University and The University of Chicago.
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #ifndef __PINT_DISTRIBUTION_H
  8. #define __PINT_DISTRIBUTION_H
  9.  
  10. #include "pint-request.h"
  11. #include "pvfs2-types.h"
  12.  
  13. /* Distribution table size limits */
  14. #define PINT_DIST_NAME_SZ 32
  15.  
  16. /* Distribution functions that must be supplied by each dist implmentation */
  17. typedef struct PINT_dist_methods_s
  18. {
  19.     /* Returns the physical storage offset for a logical file offset */
  20.     PVFS_offset (*logical_to_physical_offset)(void* params,
  21.                                               PINT_request_file_data* rf_data,
  22.                                               PVFS_offset logical_offset);
  23.     
  24.     /* Returns the logical file offset for a given physical storage offset */
  25.     PVFS_offset (*physical_to_logical_offset)(void* params,
  26.                                               PINT_request_file_data* rf_data,
  27.                                               PVFS_offset physical_offset);
  28.  
  29.     /* Returns the next physical offset for the file on server_nr given an
  30.      * arbitraty logical offset (i.e. an offset anywhere in the file) */
  31.     PVFS_offset (*next_mapped_offset)(void* params,
  32.                                       PINT_request_file_data* rf_data,
  33.                                       PVFS_offset logical_offset);
  34.  
  35.     /* Returns the contiguous length of file data starting at physical_offset*/
  36.     PVFS_size (*contiguous_length)(void* params,
  37.                                    PINT_request_file_data* rf_data,
  38.                                    PVFS_offset physical_offset);
  39.  
  40.     /* Returns the logical file size */
  41.     PVFS_size (*logical_file_size)(void* params,
  42.                                    uint32_t num_handles,
  43.                                    PVFS_size *psizes);
  44.  
  45.     /* Returns the number of data file objects to use for a file */
  46.     int (*get_num_dfiles)(void* params,
  47.                           uint32_t num_servers_available,
  48.                           uint32_t num_dfiles_requested);
  49.  
  50.     /* Sets the parameter designated by name to the given value */
  51.     int (*set_param)(const char* dist_name, void* params,
  52.                      const char* param_name, void* value);
  53.  
  54.     /* Retrieves a blocksize value suitable to report in stat() */
  55.     PVFS_size (*get_blksize)(void* params);
  56.  
  57.     /* Stores parameters in lebf memory at pptr */
  58.     void (*encode_lebf)(char **pptr, void* params);
  59.     
  60.     /* Restores parameters in lebf memory at pptr */
  61.     void (*decode_lebf)(char **pptr, void* params);
  62.  
  63.     /* Called when the distribution is registered */
  64.     void (*registration_init)(void* params);
  65.  
  66.     /* Called when the distribution is unregisterd */
  67.     void (*unregister)(void);
  68.     
  69.     char *(*params_string)(void *params);
  70. } PINT_dist_methods;
  71.  
  72. /* Internal representation of a PVFS2 Distribution */
  73. typedef struct PINT_dist_s {
  74.     char * dist_name;
  75.     int32_t name_size;
  76.     int32_t param_size; 
  77.         void * params;
  78.     PINT_dist_methods * methods;
  79. } PINT_dist;
  80.  
  81.  
  82. /* Macros to encode/decode distributions for sending requests */
  83. #define PINT_DIST_PACK_SIZE(d) \
  84.  (roundup8(sizeof(*(d))) + roundup8((d)->name_size) + roundup8((d)->param_size))
  85.  
  86. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  87. #define encode_PINT_dist(pptr,x) do { PINT_dist *px = *(x); \
  88.     encode_string(pptr, &px->dist_name); \
  89.     if (!px->methods) { \
  90.     gossip_err("%s: encode_PINT_dist: methods is null\n", __func__); \
  91.     exit(1); \
  92.     } \
  93.     (px->methods->encode_lebf) (pptr, px->params); \
  94.     align8(pptr); \
  95. } while (0)
  96. #define decode_PINT_dist(pptr,x) do { PINT_dist tmp_dist; PINT_dist *px; \
  97.     decode_string(pptr, &tmp_dist.dist_name); \
  98.     tmp_dist.params = 0; \
  99.     tmp_dist.methods = 0; \
  100.     /* bizzare lookup function fills in most fields */ \
  101.     PINT_dist_lookup(&tmp_dist); \
  102.     if (!tmp_dist.methods) { \
  103.     gossip_err("%s: decode_PINT_dist: methods is null\n", __func__); \
  104.     exit(1); \
  105.     } \
  106.     /* later routines assume dist is a big contiguous thing, do so */ \
  107.     *(x) = px = decode_malloc(PINT_DIST_PACK_SIZE(&tmp_dist)); \
  108.     memcpy(px, &tmp_dist, sizeof(*px)); \
  109.     px->dist_name = (char *) px + roundup8(sizeof(*px)); \
  110.     memcpy(px->dist_name, tmp_dist.dist_name, tmp_dist.name_size); \
  111.     px->params = (void *)(px->dist_name + roundup8(px->name_size)); \
  112.     (px->methods->decode_lebf) (pptr, px->params); \
  113.     align8(pptr); \
  114. } while (0)
  115. #endif
  116.  
  117. /* Return a cloned copy of the distribution registered for name*/
  118. PINT_dist* PINT_dist_create(const char *name);
  119.  
  120. /* Deallocate resources in a PINT_dist */
  121. int PINT_dist_free(PINT_dist *dist);
  122.  
  123. /* Return a cloned copy of dist */
  124. PINT_dist* PINT_dist_copy(const PINT_dist *dist);
  125.  
  126. /* Makes a memcpy of the distribution parameters in buf.
  127.  * buf must be allocated to the correct size */
  128. int PINT_dist_getparams(void *buf, const PINT_dist *dist);
  129.  
  130. /* Memcpys the the distribution params from buf into dist */
  131. int PINT_dist_setparams(PINT_dist *dist, const void *buf);
  132.  
  133. /* Given a distribution with only the dist_name filled in, the remaining
  134.  * distribution parameters are copied from the registered distribution for
  135.  * that name */
  136. int PINT_dist_lookup(PINT_dist *dist);
  137.  
  138. /* pack dist struct for storage */
  139. void PINT_dist_encode(void *buffer, PINT_dist *dist);
  140.  
  141. /* unpack dist struct after receiving from storage */
  142. void PINT_dist_decode(PINT_dist **dist, void *buffer);
  143.  
  144. /* Print dist state to debug system */
  145. void PINT_dist_dump(PINT_dist *dist);
  146.  
  147. /* Registers the distribution d_p
  148.  *
  149.  * the registration key d_p->dist_name
  150.  */
  151. int PINT_register_distribution(PINT_dist *d_p);
  152.  
  153. /* Removes the distribution registered for the name dist_name */
  154. int PINT_unregister_distribution(char *dist_name);
  155.  
  156. #endif /* __PINT_DISTRIBUTION_H */
  157.  
  158. /*
  159.  * Local variables:
  160.  *  mode: c
  161.  *  c-indent-level: 4
  162.  *  c-basic-offset: 4
  163.  * End:
  164.  *
  165.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  166.  */
  167.