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-perf-mon-list.sm < prev    next >
Text File  |  2008-11-19  |  8KB  |  293 lines

  1. /* 
  2.  * (C) 2003 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. /** \file
  8.  *  \ingroup mgmtint
  9.  *
  10.  *  PVFS2 management interface routines for obtaining server performance
  11.  *  statistics.  This is used primarily for monitoring purposes.
  12.  */
  13.  
  14. #include <string.h>
  15. #include <assert.h>
  16.  
  17. #include "client-state-machine.h"
  18. #include "pvfs2-debug.h"
  19. #include "job.h"
  20. #include "gossip.h"
  21. #include "str-utils.h"
  22. #include "pvfs2-mgmt.h"
  23. #include "pint-cached-config.h"
  24. #include "PINT-reqproto-encode.h"
  25.  
  26. extern job_context_id pint_client_sm_context;
  27.  
  28. static int perf_mon_list_comp_fn(
  29.     void* v_p, struct PVFS_server_resp *resp_p, int i);
  30.  
  31. %%
  32.  
  33. machine pvfs2_client_mgmt_perf_mon_list_sm
  34. {
  35.     state setup_msgpair
  36.     {
  37.         run mgmt_perf_mon_list_setup_msgpair;
  38.         success => xfer_msgpair;
  39.         default => cleanup;
  40.     }
  41.  
  42.     state xfer_msgpair
  43.     {
  44.         jump pvfs2_msgpairarray_sm;
  45.         default => cleanup;
  46.     }
  47.  
  48.     state cleanup
  49.     {
  50.         run mgmt_perf_mon_list_cleanup;
  51.         default => terminate;
  52.     }
  53. }
  54.  
  55. %%
  56.  
  57. /** Initiate retrieval of performance statistics from a list of servers.
  58.  */
  59. PVFS_error PVFS_imgmt_perf_mon_list(
  60.     PVFS_fs_id fs_id,
  61.     PVFS_credentials *credentials,
  62.     struct PVFS_mgmt_perf_stat **perf_matrix,
  63.     uint64_t *end_time_ms_array,
  64.     PVFS_BMI_addr_t *addr_array,
  65.     uint32_t* next_id_array,
  66.     int server_count,
  67.     int history_count,
  68.     PVFS_error_details *details,
  69.     PVFS_mgmt_op_id *op_id,
  70.     PVFS_hint hints,
  71.     void *user_ptr)
  72. {
  73.     PINT_smcb *smcb;
  74.     PINT_client_sm *sm_p;
  75.     int ret;
  76.  
  77.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  78.                  "PVFS_imgmt_perf_mon_list entered\n");
  79.  
  80.     if ((server_count < 1) || (history_count < 1) || !perf_matrix ||
  81.         !addr_array || !end_time_ms_array)
  82.     {
  83.     return -PVFS_EINVAL;
  84.     }
  85.  
  86.     PINT_smcb_alloc(&smcb, PVFS_MGMT_PERF_MON_LIST,
  87.              sizeof(struct PINT_client_sm),
  88.              client_op_state_get_machine,
  89.              client_state_machine_terminate,
  90.              pint_client_sm_context);
  91.     if (!smcb)
  92.     {
  93.         return -PVFS_ENOMEM;
  94.     }
  95.  
  96.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  97.  
  98.     PINT_init_msgarray_params(sm_p, fs_id);
  99.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  100.     sm_p->u.perf_mon_list.fs_id = fs_id;
  101.     sm_p->u.perf_mon_list.perf_matrix = perf_matrix;
  102.     sm_p->u.perf_mon_list.server_count = server_count;
  103.     sm_p->u.perf_mon_list.history_count = history_count;
  104.     sm_p->u.perf_mon_list.addr_array = addr_array;
  105.     sm_p->u.perf_mon_list.next_id_array = next_id_array;
  106.     sm_p->u.perf_mon_list.end_time_ms_array = end_time_ms_array;
  107.     sm_p->u.perf_mon_list.details = details;
  108.     PVFS_hint_copy(hints, &sm_p->hints);
  109.  
  110.     ret = PINT_msgpairarray_init(&sm_p->msgarray_op, server_count);
  111.     if(ret != 0)
  112.     {
  113.         PINT_smcb_free(smcb);
  114.         return ret;
  115.     }
  116.  
  117.     return PINT_client_state_machine_post(
  118.         smcb,  op_id, user_ptr);
  119. }
  120.  
  121. /** Obtain performance statistics from a list of servers.
  122.  */
  123. PVFS_error PVFS_mgmt_perf_mon_list(
  124.     PVFS_fs_id fs_id,
  125.     PVFS_credentials *credentials,
  126.     struct PVFS_mgmt_perf_stat **perf_matrix,
  127.     uint64_t *end_time_ms_array,
  128.     PVFS_BMI_addr_t *addr_array,
  129.     uint32_t* next_id_array,
  130.     int server_count,
  131.     int history_count,
  132.     PVFS_error_details *details,
  133.     PVFS_hint hints)
  134. {
  135.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  136.     PVFS_mgmt_op_id op_id;
  137.  
  138.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  139.                  "PVFS_mgmt_perf_mon_list entered\n");
  140.  
  141.     ret = PVFS_imgmt_perf_mon_list(
  142.         fs_id, credentials, perf_matrix, end_time_ms_array,
  143.         addr_array, next_id_array, server_count, history_count,
  144.         details, &op_id, hints, NULL);
  145.  
  146.     if (ret)
  147.     {
  148.         PVFS_perror_gossip("PVFS_imgmt_perf_mon_list call", ret);
  149.         error = ret;
  150.     }
  151.     else
  152.     {
  153.         ret = PVFS_mgmt_wait(op_id, "perf_mon_list", &error);
  154.         if (ret)
  155.         {
  156.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  157.             error = ret;
  158.         }
  159.     }
  160.  
  161.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  162.                  "PVFS_mgmt_perf_mon_list completed\n");
  163.  
  164.     PINT_mgmt_release(op_id);
  165.     return error;
  166. }
  167.  
  168. static PINT_sm_action mgmt_perf_mon_list_setup_msgpair(
  169.         struct PINT_smcb *smcb, job_status_s *js_p)
  170. {
  171.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  172.     int i = 0;
  173.     PINT_sm_msgpair_state *msg_p = NULL;
  174.  
  175.     gossip_debug(GOSSIP_CLIENT_DEBUG, "perf_mon_list state: "
  176.                  "mgmt_perf_mon_list_setup_msgpair\n");
  177.  
  178.     /* setup msgpair array */
  179.     foreach_msgpair(&sm_p->msgarray_op, msg_p, i)
  180.     {
  181.     PINT_SERVREQ_MGMT_PERF_MON_FILL(
  182.             msg_p->req,
  183.             *sm_p->cred_p,
  184.             sm_p->u.perf_mon_list.next_id_array[i],
  185.             sm_p->u.perf_mon_list.history_count,
  186.             sm_p->hints);
  187.  
  188.     msg_p->fs_id = sm_p->u.perf_mon_list.fs_id;
  189.     msg_p->handle = PVFS_HANDLE_NULL;
  190.     msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  191.     msg_p->comp_fn = perf_mon_list_comp_fn;
  192.     msg_p->svr_addr = sm_p->u.perf_mon_list.addr_array[i];
  193.     }
  194.  
  195.     /* immediate return: next state jumps to msgpairarray machine */
  196.     js_p->error_code = 0;
  197.  
  198.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  199.     return SM_ACTION_COMPLETE;
  200. }
  201.  
  202. static PINT_sm_action mgmt_perf_mon_list_cleanup(
  203.         struct PINT_smcb *smcb, job_status_s *js_p)
  204. {
  205.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  206.     int i = 0, errct = 0;
  207.     PVFS_error error = js_p->error_code;
  208.  
  209.     /* store server-specific errors if requested and present */
  210.     if ((error != 0) && (sm_p->u.perf_mon_list.details != NULL))
  211.     {
  212.     sm_p->u.perf_mon_list.details->count_exceeded = 0;
  213.  
  214.     for(i = 0; i < sm_p->u.perf_mon_list.server_count; i++)
  215.         {
  216.         if (sm_p->msgarray_op.msgarray[i].op_status != 0)
  217.         {
  218.         if (errct <
  219.                     sm_p->u.perf_mon_list.details->count_allocated)
  220.         {
  221.             sm_p->u.perf_mon_list.details->error[errct].error =
  222.                         sm_p->msgarray_op.msgarray[i].op_status;
  223.             sm_p->u.perf_mon_list.details->error[errct].addr =
  224.                         sm_p->msgarray_op.msgarray[i].svr_addr;
  225.             errct++;
  226.         }
  227.         else
  228.         {
  229.             sm_p->u.perf_mon_list.details->count_exceeded = 1;
  230.         }
  231.         }
  232.     }
  233.     sm_p->u.perf_mon_list.details->count_used = errct;
  234.     error = -PVFS_EDETAIL;
  235.     }
  236.  
  237.     PINT_msgpairarray_destroy(&sm_p->msgarray_op);
  238.  
  239.     sm_p->error_code  = error;
  240.  
  241.     PINT_SET_OP_COMPLETE;
  242.     return SM_ACTION_TERMINATE;
  243. }
  244.  
  245. static int perf_mon_list_comp_fn(void* v_p,
  246.                  struct PVFS_server_resp *resp_p,
  247.                  int i)
  248. {
  249.     int j = 0;
  250.     PINT_smcb *smcb = v_p;
  251.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  252.  
  253.     /* if this particular request was successful, then store the 
  254.      * performance information in an array to be returned to caller
  255.      */
  256.     if (sm_p->msgarray_op.msgarray[i].op_status == 0)
  257.     {
  258.     sm_p->u.perf_mon_list.next_id_array[i] = 
  259.         resp_p->u.mgmt_perf_mon.suggested_next_id;
  260.     sm_p->u.perf_mon_list.end_time_ms_array[i] =
  261.         resp_p->u.mgmt_perf_mon.end_time_ms;
  262.     memcpy(sm_p->u.perf_mon_list.perf_matrix[i],
  263.            resp_p->u.mgmt_perf_mon.perf_array,
  264.            resp_p->u.mgmt_perf_mon.perf_array_count
  265.            * sizeof(struct PVFS_mgmt_perf_stat));
  266.     }
  267.  
  268.     /* if this is the last response, check all of the status values and 
  269.      * return error code if any requests failed 
  270.      */
  271.     if (i == (sm_p->msgarray_op.count -1))
  272.     {
  273.     for (j=0; j < sm_p->msgarray_op.count; j++)
  274.     {
  275.         if (sm_p->msgarray_op.msgarray[j].op_status != 0)
  276.         {
  277.         return(sm_p->msgarray_op.msgarray[j].op_status);
  278.         }
  279.     }
  280.     }
  281.     return 0;
  282. }
  283.  
  284. /*
  285.  * Local variables:
  286.  *  mode: c
  287.  *  c-indent-level: 4
  288.  *  c-basic-offset: 4
  289.  * End:
  290.  *
  291.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  292.  */
  293.