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 / client / sysint / sys-dist.c < prev    next >
C/C++ Source or Header  |  2004-12-21  |  3KB  |  109 lines

  1. /* 
  2.  * (C) 2003 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "gossip.h"
  9. #include "pint-distribution.h"
  10. #include "pvfs2-sysint.h"
  11.  
  12. /** Return the distribution associated with the given identifier, or null
  13.  *  if none exists.
  14.  */
  15. PVFS_sys_dist* PVFS_sys_dist_lookup(const char* dist_name)
  16. {
  17.     PVFS_sys_dist* sys_dist = 0;
  18.  
  19.     if (0 != dist_name)
  20.     {
  21.         /* Construct a dummy dist to lookup the registered dist */
  22.         PINT_dist template_dist;
  23.         template_dist.dist_name = (char*)dist_name;
  24.         template_dist.params = 0;
  25.         template_dist.methods = 0;
  26.  
  27.         if (0 == PINT_dist_lookup(&template_dist))
  28.         {
  29.             /* Copy the data from the registered dist */
  30.             sys_dist = malloc(sizeof(PVFS_sys_dist));
  31.             if (0 != sys_dist)
  32.             {
  33.                 sys_dist->name = malloc(template_dist.name_size);
  34.                 sys_dist->params = malloc(template_dist.param_size);
  35.                 if (0 != sys_dist->name && 0 != sys_dist->params)
  36.                 {
  37.                     memcpy(sys_dist->name, template_dist.dist_name,
  38.                            template_dist.name_size);
  39.                     memcpy(sys_dist->params, template_dist.params,
  40.                            template_dist.param_size);
  41.                 }
  42.                 else
  43.                 {
  44.                     free(sys_dist->name);
  45.                     free(sys_dist->params);
  46.                     free(sys_dist);
  47.                     sys_dist = 0;
  48.                 }
  49.             }
  50.         }
  51.     }
  52.     return sys_dist;
  53. }
  54.  
  55. /** Free resources associated with this distribution.
  56.  */
  57. PVFS_error PVFS_sys_dist_free(PVFS_sys_dist* dist)
  58. {
  59.     if (0 != dist)
  60.     {
  61.         free(dist->name);
  62.         free(dist->params);
  63.         free(dist);
  64.     }
  65.     return 0;
  66. }
  67.  
  68. /** Set the named distribution parameter with the given value.
  69.  */
  70. PVFS_error PVFS_sys_dist_setparam(
  71.     PVFS_sys_dist* dist,
  72.     const char* param,
  73.     void* value)
  74. {
  75.     PVFS_error rc = -PVFS_EINVAL;
  76.     if (0 != dist)
  77.     {
  78.         /* Construct a dummy dist to lookup the registered dist */
  79.         PINT_dist template_dist;
  80.         template_dist.dist_name = dist->name;
  81.         template_dist.params = 0;
  82.         template_dist.methods = 0;
  83.  
  84.         if (0 == PINT_dist_lookup(&template_dist))
  85.         {
  86.             rc = template_dist.methods->set_param(dist->name,
  87.                                                   dist->params,
  88.                                                   param, value);
  89.             if (0 != rc)
  90.             {
  91.                 rc = -PVFS_EINVAL;
  92.                 gossip_err("Error: Distribution does not have parameter: %s\n",
  93.                            param);
  94.             }
  95.         }
  96.     }
  97.     return rc;
  98. }
  99.  
  100. /*
  101.  * Local variables:
  102.  *  mode: c
  103.  *  c-indent-level: 4
  104.  *  c-basic-offset: 4
  105.  * End:
  106.  *
  107.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  108.  */
  109.