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 / server / precreate-pool-refiller.sm < prev    next >
Text File  |  2010-08-27  |  9KB  |  318 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 <string.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include <sys/time.h>
  13. #include <assert.h>
  14.  
  15. #include "pvfs2-server.h"
  16. #include "pint-perf-counter.h"
  17. #include "server-config.h"
  18. #include "pint-util.h"
  19.  
  20. static int batch_create_comp_fn(
  21.     void *v_p, struct PVFS_server_resp *resp_p, int index);
  22.  
  23. %%
  24.  
  25. machine pvfs2_precreate_pool_refiller_sm
  26. {
  27.         state setup
  28.         {
  29.                 run setup_fn;
  30.                 success => wait_for_threshold;
  31.                 default => error_retry;
  32.         }
  33.  
  34.     state wait_for_threshold 
  35.     {
  36.         run wait_for_threshold_fn;
  37.         success => setup_batch_create;
  38.         default => error_retry;
  39.     }
  40.  
  41.     state setup_batch_create 
  42.     {
  43.         run setup_batch_create_fn;
  44.         success => msgpair_xfer_batch_create;
  45.         default => error_retry;
  46.     }
  47.  
  48.         state msgpair_xfer_batch_create
  49.         {
  50.                 jump pvfs2_msgpairarray_sm;
  51.                 success => store_handles;
  52.                 default => msgpair_retry;
  53.         }
  54.  
  55.         state msgpair_retry
  56.         {
  57.                 run msgpair_retry_fn;
  58.                 default => setup_batch_create;
  59.         }
  60.  
  61.         state store_handles
  62.         {
  63.                 run store_handles_fn;
  64.                 success => wait_for_threshold;
  65.                 default => error_retry;
  66.         }
  67.  
  68.         state error_retry
  69.         {
  70.                 run error_fn;
  71.                 success => setup;
  72.                 default => terminate;
  73.         }
  74. }
  75.  
  76. %%
  77.  
  78. /* msgpair_retry_fn()
  79.  *
  80.  * handles anything that needs to happen between sets of msgpair retries
  81.  */
  82. static PINT_sm_action msgpair_retry_fn(
  83.         struct PINT_smcb *smcb, job_status_s *js_p)
  84. {
  85.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  86.     job_id_t tmp_id;
  87.  
  88.     /* signal anyone waiting on get_handles() that we are having trouble */
  89.     return(job_precreate_pool_fill_signal_error(
  90.         s_op->u.precreate_pool_refiller.pool_handle,
  91.         s_op->u.precreate_pool_refiller.fsid,
  92.         js_p->error_code,
  93.     smcb,
  94.     0,
  95.     js_p,
  96.     &tmp_id,
  97.     server_job_context));
  98. }
  99.  
  100. /* wait_for_threshold_fn()
  101.  *
  102.  * waits until the pool count has dropped below a low threshold before
  103.  * proceeding
  104.  */
  105. static PINT_sm_action wait_for_threshold_fn(
  106.         struct PINT_smcb *smcb, job_status_s *js_p)
  107. {
  108.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  109.     job_id_t tmp_id;
  110.     struct server_configuration_s *user_opts = get_server_config_struct();
  111.     int index = 0;
  112.  
  113.     PVFS_ds_type_to_int(s_op->u.precreate_pool_refiller.type, &index);
  114.  
  115.     return(job_precreate_pool_check_level(
  116.         s_op->u.precreate_pool_refiller.pool_handle,
  117.         s_op->u.precreate_pool_refiller.fsid,
  118.         user_opts->precreate_low_threshold[index],
  119.     smcb,
  120.     0,
  121.     js_p,
  122.     &tmp_id,
  123.     server_job_context));
  124. }
  125.  
  126.  /* store_handles_fn()
  127.   *
  128.   * stores a set of precreated handles persistently within precreate pools
  129.   */
  130. static PINT_sm_action store_handles_fn(
  131.         struct PINT_smcb *smcb, job_status_s *js_p)
  132. {
  133.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  134.     job_id_t tmp_id;
  135.     struct server_configuration_s *user_opts = get_server_config_struct();
  136.     int index = 0;
  137.     PVFS_ds_type_to_int( s_op->u.precreate_pool_refiller.type, &index );
  138.  
  139.     return(job_precreate_pool_fill(
  140.         s_op->u.precreate_pool_refiller.pool_handle,
  141.         s_op->u.precreate_pool_refiller.fsid,
  142.         s_op->u.precreate_pool_refiller.precreate_handle_array,
  143.         user_opts->precreate_batch_size[index],
  144.     smcb,
  145.     0,
  146.     js_p,
  147.     &tmp_id,
  148.     server_job_context,
  149.         NULL));
  150. }
  151.  
  152.  
  153. /* setup_batch_create_fn()
  154.  *
  155.  * prepares a req/resp pair to another server to precreate a batch of
  156.  * handles
  157.  */
  158. static PINT_sm_action setup_batch_create_fn(
  159.         struct PINT_smcb *smcb, job_status_s *js_p)
  160. {
  161.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  162.     PINT_sm_msgpair_state *msg_p = NULL;
  163.     PVFS_credentials creds;
  164.     struct server_configuration_s *user_opts = get_server_config_struct();
  165.     int index = 0;
  166.  
  167.     gossip_debug(GOSSIP_SERVER_DEBUG, "setting up msgpair to get precreated "
  168.                  "handles from %s, of type %u, and put store them in %llu.\n",
  169.                 s_op->u.precreate_pool_refiller.host,
  170.                 s_op->u.precreate_pool_refiller.type,
  171.                 llu(s_op->u.precreate_pool_refiller.pool_handle));
  172.  
  173.     PINT_msgpair_init(&s_op->msgarray_op);
  174.     msg_p = &s_op->msgarray_op.msgpair;
  175.  
  176.     /* note: we are acting like a client in this case, so use client timeout
  177.      * and delay values
  178.      */
  179.     s_op->msgarray_op.params.job_timeout = user_opts->client_job_bmi_timeout;
  180.     s_op->msgarray_op.params.retry_delay = user_opts->client_retry_delay_ms;
  181.     s_op->msgarray_op.params.retry_limit = user_opts->client_retry_limit;
  182.     s_op->msgarray_op.params.quiet_flag = 1;
  183.  
  184.     msg_p->svr_addr = s_op->u.precreate_pool_refiller.host_addr;
  185.     PINT_util_gen_credentials(&creds);
  186.  
  187.     PVFS_ds_type_to_int( s_op->u.precreate_pool_refiller.type, &index );
  188.  
  189.     PINT_SERVREQ_BATCH_CREATE_FILL(
  190.         msg_p->req,
  191.         creds,
  192.         s_op->u.precreate_pool_refiller.fsid,
  193.         s_op->u.precreate_pool_refiller.type,
  194.         user_opts->precreate_batch_size[index],
  195.         s_op->u.precreate_pool_refiller.handle_extent_array,
  196.         NULL);
  197.  
  198.     msg_p->fs_id = s_op->u.precreate_pool_refiller.fsid;
  199.     msg_p->handle = s_op->u.precreate_pool_refiller.handle_extent_array.extent_array[0].first;
  200.     msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  201.     msg_p->comp_fn = batch_create_comp_fn;
  202.  
  203.     PINT_sm_push_frame(smcb, 0, &s_op->msgarray_op);
  204.     js_p->error_code = 0;
  205.     return(SM_ACTION_COMPLETE);
  206. }
  207.  
  208.  
  209. /* setup_fn()
  210.  *
  211.  * initial state to allocate memory for use through the remainder of the
  212.  * state machine's life
  213.  */
  214. static PINT_sm_action setup_fn(
  215.         struct PINT_smcb *smcb, job_status_s *js_p)
  216. {
  217.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  218.     struct server_configuration_s *user_opts = get_server_config_struct();
  219.     int index = 0;
  220.     PVFS_ds_type_to_int( s_op->u.precreate_pool_refiller.type, &index);
  221.  
  222.     s_op->u.precreate_pool_refiller.precreate_handle_array = 
  223.         malloc(user_opts->precreate_batch_size[index] * sizeof(PVFS_handle));
  224.     if(!s_op->u.precreate_pool_refiller.precreate_handle_array)
  225.     {
  226.         js_p->error_code = -PVFS_ENOMEM;
  227.         return(SM_ACTION_COMPLETE);
  228.     }
  229.  
  230.     js_p->error_code = 0;
  231.     return(SM_ACTION_COMPLETE);
  232. }
  233.  
  234.  
  235. /* error_fn()
  236.  *
  237.  * handles error transitions
  238.  */
  239. static PINT_sm_action error_fn(
  240.         struct PINT_smcb *smcb, job_status_s *js_p)
  241. {
  242.     job_id_t tmp_id;
  243.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  244.  
  245.     gossip_err("Error: precreate_pool_refiller for %s encountered error.\n",
  246.         s_op->u.precreate_pool_refiller.host);
  247.     gossip_err("Error: sleeping for 30 seconds before retrying.\n");
  248.         
  249.     if(s_op->u.precreate_pool_refiller.precreate_handle_array)
  250.     {
  251.         free(s_op->u.precreate_pool_refiller.precreate_handle_array);
  252.     }
  253.  
  254.     return(job_req_sched_post_timer(
  255.         (30*1000),
  256.     smcb,
  257.     0,
  258.     js_p,
  259.     &tmp_id,
  260.     server_job_context));
  261. }
  262.  
  263.  
  264. /* batch_create_comp_fn()
  265.  *
  266.  * msgpair completion function to handle processing batch create response i
  267.  * from another server
  268.  */
  269. static int batch_create_comp_fn(void *v_p,
  270.                                  struct PVFS_server_resp *resp_p,
  271.                                  int index)
  272. {
  273.     PINT_smcb *smcb = v_p;
  274.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  275.     int i;
  276.     
  277.     gossip_debug(GOSSIP_SERVER_DEBUG, "batch_create_comp_fn\n");
  278.  
  279.     assert(resp_p->op == PVFS_SERV_BATCH_CREATE);
  280.  
  281.     if (resp_p->status != 0)
  282.     {
  283.         PVFS_perror_gossip("batch_create request got", resp_p->status);
  284.     return resp_p->status;
  285.     }
  286.  
  287.     for(i = 0; i<resp_p->u.batch_create.handle_count; i++)
  288.     {
  289.         s_op->u.precreate_pool_refiller.precreate_handle_array[i] = 
  290.             resp_p->u.batch_create.handle_array[i];
  291.  
  292.         gossip_debug(GOSSIP_SERVER_DEBUG,
  293.             "Got batch created handle: %llu from: %s\n",
  294.             llu(resp_p->u.batch_create.handle_array[i]),
  295.             s_op->u.precreate_pool_refiller.host);
  296.     }
  297.  
  298.     return 0;
  299. }
  300.  
  301. struct PINT_server_req_params pvfs2_precreate_pool_refiller_params =
  302. {
  303.     .string_name = "precreate_pool_refiller",
  304.     .perm = PINT_SERVER_CHECK_INVALID,
  305.     .state_machine = &pvfs2_precreate_pool_refiller_sm
  306. };
  307.  
  308. /*
  309.  * Local variables:
  310.  *  mode: c
  311.  *  c-indent-level: 4
  312.  *  c-basic-offset: 4
  313.  * End:
  314.  *
  315.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  316.  */
  317.  
  318.