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 / initialize.c < prev    next >
C/C++ Source or Header  |  2010-04-30  |  8KB  |  326 lines

  1. /*
  2.  * (C) 2001 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #ifdef HAVE_MALLOC_H
  9. #include <malloc.h>
  10. #endif
  11. #include <errno.h>
  12. #include <assert.h>
  13. #include <string.h>
  14. #include <unistd.h>
  15.  
  16. #include "acache.h"
  17. #include "ncache.h"
  18. #include "pint-cached-config.h"
  19. #include "pvfs2-sysint.h"
  20. #include "pvfs2-util.h"
  21. #include "pint-dist-utils.h"
  22. #include "pint-sysint-utils.h"
  23. #include "gen-locks.h"
  24. #include "PINT-reqproto-encode.h"
  25. #include "trove.h"
  26. #include "server-config-mgr.h"
  27. #include "client-state-machine.h"
  28. #include "src/server/request-scheduler/request-scheduler.h"
  29. #include "job-time-mgr.h"
  30. #include "pint-util.h"
  31. #include "pint-event.h"
  32.  
  33. PINT_smcb *g_smcb = NULL; 
  34.  
  35. extern job_context_id pint_client_sm_context;
  36.  
  37. PINT_event_id PINT_client_sys_event_id;
  38.  
  39. int pint_client_pid;
  40.  
  41. typedef enum
  42. {
  43.     CLIENT_NO_INIT         =      0,
  44.     CLIENT_ENCODER_INIT    = (1 << 0),
  45.     CLIENT_BMI_INIT        = (1 << 1),
  46.     CLIENT_FLOW_INIT       = (1 << 2),
  47.     CLIENT_JOB_INIT        = (1 << 3),
  48.     CLIENT_JOB_CTX_INIT    = (1 << 4),
  49.     CLIENT_ACACHE_INIT     = (1 << 5),
  50.     CLIENT_NCACHE_INIT     = (1 << 6),
  51.     CLIENT_CONFIG_MGR_INIT = (1 << 7),
  52.     CLIENT_REQ_SCHED_INIT  = (1 << 8),
  53.     CLIENT_JOB_TIME_MGR_INIT = (1 << 9),
  54.     CLIENT_DIST_INIT       = (1 << 10)
  55. } PINT_client_status_flag;
  56.  
  57. /* PVFS_sys_initialize()
  58.  *
  59.  * Initializes the PVFS system interface and any necessary internal
  60.  * data structures.  Must be called before any other system interface
  61.  * function.
  62.  *
  63.  * the default_debug_mask is used if not overridden by the
  64.  * PVFS2_DEBUGMASK environment variable at run-time.  allowable string
  65.  * formats of the env variable are the same as the EventLogging line
  66.  * in the server configuration file.
  67.  *
  68.  * returns 0 on success, -PVFS_error on failure
  69.  */
  70. int PVFS_sys_initialize(uint64_t default_debug_mask)
  71. {
  72.     int ret = -PVFS_EINVAL;
  73.     const char *debug_mask_str = NULL, *debug_file = NULL;
  74.     PINT_client_status_flag client_status_flag = CLIENT_NO_INIT;
  75.     PINT_smcb *smcb = NULL;
  76.     uint64_t debug_mask = 0;
  77.     char *event_mask = NULL;
  78.  
  79.     pint_client_pid = getpid();
  80.  
  81.     gossip_enable_stderr();
  82.  
  83.     debug_mask_str = getenv("PVFS2_DEBUGMASK");
  84.     debug_mask = (debug_mask_str ?
  85.                   PVFS_debug_eventlog_to_mask(debug_mask_str) :
  86.                   default_debug_mask);
  87.     gossip_set_debug_mask(1,debug_mask);
  88.  
  89.     debug_file = getenv("PVFS2_DEBUGFILE");
  90.     if (debug_file)
  91.     {
  92.         gossip_enable_file(debug_file, "w");
  93.     }
  94.  
  95.     ret = PINT_event_init(PINT_EVENT_TRACE_TAU);
  96.  
  97. /*  ignore error *
  98.  *  if (ret < 0)
  99.     {
  100.         gossip_err("Error initializing event interface.\n");
  101.         return (ret);
  102.     } */
  103.  
  104.  
  105.     /**
  106.      * (ClientID, Rank, RequestID, Handle, Sys)
  107.      */
  108.     PINT_event_define_event(NULL, "sys", "%d%d%d%llu%d", "", &PINT_client_sys_event_id);
  109.  
  110.     event_mask = getenv("PVFS2_EVENTMASK");
  111.     if (event_mask)
  112.     {
  113.         PINT_event_enable(event_mask);
  114.     }
  115.  
  116.     ret = id_gen_safe_initialize();
  117.     if(ret < 0)
  118.     {
  119.         gossip_lerr("Error initializing id_gen_safe\n");
  120.         goto error_exit;
  121.     }
  122.  
  123.     /* Initialize the distribution subsystem */
  124.     ret = PINT_dist_initialize(NULL);
  125.     if (ret < 0)
  126.     {
  127.         gossip_lerr("Error initializing distributions.\n");
  128.         goto error_exit;
  129.     }
  130.     client_status_flag |= CLIENT_DIST_INIT;
  131.     
  132.     /* initlialize the protocol encoder */
  133.     ret = PINT_encode_initialize();
  134.     if (ret < 0)
  135.     {
  136.         gossip_lerr("Protocol encoder initialize failure\n");
  137.         goto error_exit;
  138.     }
  139.     client_status_flag |= CLIENT_ENCODER_INIT;
  140.     
  141.     /* initialize bmi and the bmi session identifier */
  142.     ret = BMI_initialize(NULL,NULL,0);
  143.     if (ret < 0)
  144.     {
  145.         gossip_lerr("BMI initialize failure\n");
  146.         goto error_exit;
  147.     }
  148.     client_status_flag |= CLIENT_BMI_INIT;
  149.  
  150.     /* initialize the flow interface */
  151.     ret = PINT_flow_initialize(NULL, 0);
  152.     if (ret < 0)
  153.     {
  154.         gossip_lerr("Flow initialize failure.\n");
  155.         goto error_exit;
  156.     }
  157.     client_status_flag |= CLIENT_FLOW_INIT;
  158.  
  159.     /* initialize the request scheduler (used mainly for timers) */
  160.     ret = PINT_req_sched_initialize();
  161.     if (ret < 0)
  162.     {
  163.         gossip_lerr("Req sched initialize failure.\n");
  164.         goto error_exit;
  165.     }
  166.     client_status_flag |= CLIENT_REQ_SCHED_INIT;
  167.  
  168.     /* initialize the job timeout mgr */
  169.     ret = job_time_mgr_init();
  170.     if (ret < 0)
  171.     {
  172.         gossip_lerr("Job time mgr initialize failure.\n");
  173.         goto error_exit;
  174.     }
  175.     client_status_flag |= CLIENT_JOB_TIME_MGR_INIT;
  176.  
  177.     /* initialize the job interface and the job context */
  178.     ret = job_initialize(0);
  179.     if (ret < 0)
  180.     {
  181.         gossip_lerr("Error initializing job interface: %s\n",
  182.                     strerror(-ret));
  183.         goto error_exit;
  184.     }
  185.     client_status_flag |= CLIENT_JOB_INIT;
  186.  
  187.     ret = PINT_client_state_machine_initialize();
  188.     if (ret < 0)
  189.     {
  190.         gossip_lerr("job_open_context() failure.\n");
  191.         goto error_exit;
  192.     }
  193.     client_status_flag |= CLIENT_JOB_CTX_INIT;
  194.         
  195.     /* initialize the attribute cache and set the default timeout */
  196.     ret = PINT_acache_initialize();
  197.     if (ret < 0)
  198.     {
  199.         gossip_lerr("Error initializing attribute cache\n");
  200.         goto error_exit;        
  201.     }
  202.     client_status_flag |= CLIENT_ACACHE_INIT;
  203.  
  204.     /* initialize the name lookup cache and set the default timeout */
  205.     ret = PINT_ncache_initialize();
  206.     if (ret < 0)
  207.     {
  208.         gossip_lerr("Error initializing name lookup cache\n");
  209.         goto error_exit;        
  210.     }        
  211.     client_status_flag |= CLIENT_NCACHE_INIT;
  212.  
  213.     /* initialize the server configuration manager */
  214.     ret = PINT_server_config_mgr_initialize();
  215.     if (ret < 0)
  216.     {
  217.         gossip_lerr("Error initializing server configuration manager\n");
  218.         goto error_exit;        
  219.     }        
  220.     client_status_flag |= CLIENT_CONFIG_MGR_INIT;
  221.  
  222.     /* initialize the handle mapping interface */
  223.     ret = PINT_cached_config_initialize();
  224.     if (ret < 0)
  225.     {
  226.         gossip_lerr("Error initializing handle mapping interface\n");
  227.         goto error_exit;
  228.     }
  229.  
  230.     /* start job timer */
  231.     PINT_smcb_alloc(&smcb, PVFS_CLIENT_JOB_TIMER,
  232.             sizeof(struct PINT_client_sm),
  233.             client_op_state_get_machine,
  234.             NULL,
  235.             pint_client_sm_context);
  236.     if(!smcb)
  237.     {
  238.     return(-PVFS_ENOMEM);
  239.     }
  240.  
  241.     ret = PINT_client_state_machine_post(smcb, NULL, NULL);
  242.     if (ret < 0)
  243.     {
  244.     gossip_lerr("Error posting job timer.\n");
  245.     goto error_exit;
  246.     }
  247.     /* keep track of this pointer for freeing on finalize */
  248.     g_smcb = smcb;
  249.  
  250.     PINT_util_digest_init();
  251.  
  252.    return 0;
  253.  
  254.   error_exit:
  255.  
  256.     id_gen_safe_finalize();
  257.  
  258.     if (client_status_flag & CLIENT_CONFIG_MGR_INIT)
  259.     {
  260.         PINT_server_config_mgr_finalize();
  261.     }
  262.  
  263.     if (client_status_flag & CLIENT_NCACHE_INIT)
  264.     {
  265.         PINT_ncache_finalize();
  266.     }
  267.  
  268.     if (client_status_flag & CLIENT_ACACHE_INIT)
  269.     {
  270.         PINT_acache_finalize();
  271.     }
  272.  
  273.     if (client_status_flag & CLIENT_JOB_TIME_MGR_INIT)
  274.     {
  275.         job_time_mgr_finalize();
  276.     }
  277.  
  278.     if (client_status_flag & CLIENT_JOB_CTX_INIT)
  279.     {
  280.         PINT_client_state_machine_finalize();
  281.     }
  282.  
  283.     if (client_status_flag & CLIENT_JOB_INIT)
  284.     {
  285.         job_finalize();
  286.     }
  287.  
  288.     if (client_status_flag & CLIENT_FLOW_INIT)
  289.     {
  290.         PINT_flow_finalize();
  291.     }
  292.  
  293.     if (client_status_flag & CLIENT_REQ_SCHED_INIT)
  294.     {
  295.         PINT_req_sched_finalize();
  296.     }
  297.  
  298.     if (client_status_flag & CLIENT_BMI_INIT)
  299.     {
  300.         BMI_finalize();
  301.     }
  302.  
  303.     if (client_status_flag & CLIENT_ENCODER_INIT)
  304.     {
  305.         PINT_encode_finalize();
  306.     }
  307.  
  308.     if (client_status_flag & CLIENT_DIST_INIT)
  309.     {
  310.         PINT_dist_finalize();
  311.     }
  312.  
  313.     PINT_smcb_free(smcb);
  314.  
  315.     return ret;
  316. }
  317.  
  318. /*
  319.  * Local variables:
  320.  *  c-indent-level: 4
  321.  *  c-basic-offset: 4
  322.  * End:
  323.  *
  324.  * vim: ts=8 sts=4 sw=4 expandtab
  325.  */
  326.