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 / mgmt-get-config.c < prev    next >
C/C++ Source or Header  |  2008-05-06  |  4KB  |  144 lines

  1. /* 
  2.  * (C) 2003 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <unistd.h>
  10.  
  11. #include "client-state-machine.h"
  12. #include "pvfs2-debug.h"
  13. #include "pvfs2-util.h"
  14. #include "job.h"
  15. #include "gossip.h"
  16. #include "str-utils.h"
  17. #include "pint-cached-config.h"
  18. #include "PINT-reqproto-encode.h"
  19.  
  20. extern job_context_id pint_client_sm_context;
  21.  
  22. /*
  23.   given mount information, retrieve the server's configuration by
  24.   issuing a getconfig operation.  on successful response, we parse the
  25.   configuration and fill in the config object specified.
  26.  
  27.   returns 0 on success, -errno on error
  28. */
  29. int PVFS_mgmt_get_config(
  30.     const PVFS_fs_id * fsid,
  31.     PVFS_BMI_addr_t * addr,
  32.     char *fs_buf,
  33.     int fs_buf_size)
  34. {
  35.     int ret = -PVFS_EINVAL;
  36.     PINT_smcb *smcb = NULL;
  37.     PINT_client_sm *sm_p = NULL;
  38.     PVFS_error error = 0;
  39.     PVFS_credentials creds;
  40.     struct filesystem_configuration_s *cur_fs = NULL;
  41.     PVFS_sys_op_id op_id;
  42.     struct server_configuration_s *config = NULL;
  43.     struct PVFS_sys_mntent mntent;
  44.     int server_type = 0;
  45.  
  46.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_mgmt_get_config entered\n");
  47.  
  48.     PVFS_util_gen_credentials(&creds);
  49.  
  50.     PINT_smcb_alloc(&smcb, PVFS_SERVER_GET_CONFIG,
  51.                     sizeof(struct PINT_client_sm),
  52.                     client_op_state_get_machine,
  53.                     client_state_machine_terminate,
  54.                     pint_client_sm_context);
  55.     if(smcb == NULL)
  56.     {
  57.         return -PVFS_ENOMEM;
  58.     }
  59.  
  60.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  61.  
  62.     sm_p->u.get_config.persist_config_buffers = 1;
  63.  
  64.     PINT_init_msgarray_params(sm_p, *fsid);
  65.  
  66.     PINT_init_sysint_credentials(sm_p->cred_p, &creds);
  67.  
  68.     config = PINT_get_server_config_struct(*fsid);
  69.  
  70.     mntent.the_pvfs_config_server =
  71.         (char*)PINT_cached_config_map_addr(*fsid, *addr, &server_type);
  72.  
  73.     PINT_put_server_config_struct(config);
  74.  
  75.     cur_fs = PINT_config_find_fs_id(config, *fsid);
  76.  
  77.     mntent.encoding = cur_fs->encoding;
  78.     mntent.flowproto = cur_fs->flowproto;
  79.  
  80.     mntent.fs_id = *fsid;
  81.  
  82.     mntent.pvfs_fs_name = cur_fs->file_system_name;
  83.     sm_p->u.get_config.config = config;
  84.  
  85.     sm_p->msgarray_op.msgpair.enc_type = cur_fs->encoding;
  86.  
  87.     sm_p->u.get_config.mntent = &mntent;
  88.  
  89.     PINT_msgpair_init(&sm_p->msgarray_op);
  90.  
  91.     ret = PINT_client_state_machine_post(
  92.         smcb, &op_id, NULL);
  93.  
  94.     if (ret)
  95.     {
  96.         PVFS_perror_gossip("PINT_client_state_machine_post call", ret);
  97.         error = ret;
  98.     }
  99.     else
  100.     {
  101.         ret = PVFS_mgmt_wait(op_id, "X-get_config", &error);
  102.         if (ret)
  103.         {
  104.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  105.             error = ret;
  106.         }
  107.     }
  108.  
  109.     if (error)
  110.     {
  111.         goto exit_path;
  112.     }
  113.  
  114.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_mgmt_get_config completed\n");
  115.  
  116.     /* make sure strings will be null terminated after strncpy */
  117.     fs_buf[fs_buf_size-1] = '\0';
  118.  
  119.     /* The following copies the retrieved configuration buffers
  120.        into the return buffers */
  121.     strncpy(fs_buf, sm_p->u.get_config.fs_config_buf, (fs_buf_size - 1));
  122.  
  123.   exit_path:
  124.  
  125.     if (sm_p && sm_p->u.get_config.persist_config_buffers)
  126.     {
  127.         free(sm_p->u.get_config.fs_config_buf);
  128.         sm_p->u.get_config.fs_config_buf = NULL;
  129.     }
  130.  
  131.     PINT_mgmt_release(op_id);
  132.     return error;
  133. }
  134.  
  135. /*
  136.  * Local variables:
  137.  *  mode: c
  138.  *  c-indent-level: 4
  139.  *  c-basic-offset: 4
  140.  * End:
  141.  *
  142.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  143.  */
  144.