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-event-mon-list.sm < prev    next >
Text File  |  2008-11-19  |  7KB  |  274 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 event monitoring.
  11.  */
  12.  
  13. #include <string.h>
  14. #include <assert.h>
  15.  
  16. #include "client-state-machine.h"
  17. #include "pvfs2-debug.h"
  18. #include "job.h"
  19. #include "gossip.h"
  20. #include "str-utils.h"
  21. #include "pvfs2-mgmt.h"
  22. #include "pint-cached-config.h"
  23. #include "PINT-reqproto-encode.h"
  24.  
  25. extern job_context_id pint_client_sm_context;
  26.  
  27. /* completion function prototypes */
  28. static int event_mon_list_comp_fn(
  29.     void* v_p, struct PVFS_server_resp* resp_p, int i);
  30.  
  31. %%
  32.  
  33. machine pvfs2_client_mgmt_event_mon_list_sm
  34. {
  35.     state setup_msgpair
  36.     {
  37.         run mgmt_event_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_event_mon_list_cleanup;
  51.         default => terminate;
  52.     }
  53. }
  54.  
  55. %%
  56.  
  57. PVFS_error PVFS_imgmt_event_mon_list(
  58.     PVFS_fs_id fs_id,
  59.     PVFS_credentials *credentials,
  60.     struct PVFS_mgmt_event** event_matrix,
  61.     PVFS_BMI_addr_t *addr_array,
  62.     int server_count,
  63.     int event_count,
  64.     PVFS_error_details *details,
  65.     PVFS_mgmt_op_id *op_id,
  66.     PVFS_hint hints,
  67.     void *user_ptr)
  68. {
  69.     PINT_smcb *smcb = NULL;
  70.     PINT_client_sm *sm_p = NULL;
  71.     int ret;
  72.  
  73.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  74.                  "PVFS_imgmt_event_mon_list entered\n");
  75.  
  76.     if ((server_count < 1) || (event_count < 1) ||
  77.         !event_matrix || !addr_array)
  78.     {
  79.         return -PVFS_EINVAL;
  80.     }
  81.  
  82.     PINT_smcb_alloc(&smcb, PVFS_MGMT_EVENT_MON_LIST,
  83.              sizeof(struct PINT_client_sm),
  84.              client_op_state_get_machine,
  85.              client_state_machine_terminate,
  86.              pint_client_sm_context);
  87.     if (!smcb)
  88.     {
  89.         return -PVFS_ENOMEM;
  90.     }
  91.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  92.  
  93.     PINT_init_msgarray_params(sm_p, fs_id);
  94.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  95.     sm_p->u.event_mon_list.fs_id = fs_id;
  96.     sm_p->u.event_mon_list.event_matrix = event_matrix;
  97.     sm_p->u.event_mon_list.server_count = server_count;
  98.     sm_p->u.event_mon_list.event_count = event_count;
  99.     sm_p->u.event_mon_list.addr_array = addr_array;
  100.     sm_p->u.event_mon_list.details = details;
  101.     PVFS_hint_copy(hints, &sm_p->hints);
  102.  
  103.     ret = PINT_msgpairarray_init(&sm_p->msgarray_op, server_count);
  104.     if(ret != 0)
  105.     {
  106.         PINT_smcb_free(smcb);
  107.         return ret;
  108.     }
  109.  
  110.     return PINT_client_state_machine_post(
  111.         smcb,  op_id, user_ptr);
  112. }
  113.  
  114. PVFS_error PVFS_mgmt_event_mon_list(
  115.     PVFS_fs_id fs_id,
  116.     PVFS_credentials *credentials,
  117.     struct PVFS_mgmt_event** event_matrix,
  118.     PVFS_BMI_addr_t *addr_array,
  119.     int server_count,
  120.     int event_count,
  121.     PVFS_error_details *details,
  122.     PVFS_hint hints)
  123. {
  124.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  125.     PVFS_mgmt_op_id op_id;
  126.  
  127.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  128.                  "PVFS_mgmt_event_mon_list entered\n");
  129.  
  130.     ret = PVFS_imgmt_event_mon_list(
  131.         fs_id, credentials, event_matrix, addr_array, server_count,
  132.         event_count, details, &op_id, hints, NULL);
  133.  
  134.     if (ret)
  135.     {
  136.         PVFS_perror_gossip("PVFS_imgmt_event_mon_list call", ret);
  137.         error = ret;
  138.     }
  139.     else
  140.     {
  141.         ret = PVFS_mgmt_wait(op_id, "event_mon_list", &error);
  142.         if (ret)
  143.         {
  144.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  145.             error = ret;
  146.         }
  147.     }
  148.  
  149.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  150.                  "PVFS_mgmt_event_mon_list completed\n");
  151.  
  152.     PINT_mgmt_release(op_id);
  153.     return error;
  154. }
  155.  
  156. static PINT_sm_action mgmt_event_mon_list_setup_msgpair(
  157.         struct PINT_smcb *smcb, job_status_s *js_p)
  158. {
  159.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  160.     int i = 0;
  161.     PINT_sm_msgpair_state *msg_p = NULL;
  162.  
  163.     gossip_debug(GOSSIP_CLIENT_DEBUG, "event_mon_list state: "
  164.                  "mgmt_event_mon_list_setup_msgpair\n");
  165.  
  166.     js_p->error_code = 0;
  167.  
  168.     foreach_msgpair(&sm_p->msgarray_op, msg_p, i)
  169.     {
  170.         PINT_SERVREQ_MGMT_EVENT_MON_FILL(
  171.             msg_p->req,
  172.             *sm_p->cred_p,
  173.             sm_p->u.event_mon_list.event_count,
  174.             sm_p->hints);
  175.  
  176.         msg_p->fs_id = sm_p->u.event_mon_list.fs_id;
  177.         msg_p->handle = PVFS_HANDLE_NULL;
  178.         msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  179.         msg_p->comp_fn = event_mon_list_comp_fn;
  180.         msg_p->svr_addr = sm_p->u.event_mon_list.addr_array[i];
  181.     }
  182.  
  183.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  184.     return SM_ACTION_COMPLETE;
  185. }
  186.  
  187. static PINT_sm_action mgmt_event_mon_list_cleanup(
  188.         struct PINT_smcb *smcb, job_status_s *js_p)
  189. {
  190.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  191.     int i = 0, errct = 0;
  192.     PVFS_error error = js_p->error_code;
  193.  
  194.     /* store server-specific errors if requested and present */
  195.     if ((error != 0) && (sm_p->u.event_mon_list.details != NULL))
  196.     {
  197.     sm_p->u.event_mon_list.details->count_exceeded = 0;
  198.  
  199.     for(i = 0; i < sm_p->u.event_mon_list.server_count; i++)
  200.         {
  201.         if (sm_p->msgarray_op.msgarray[i].op_status != 0)
  202.         {
  203.         if (errct <
  204.                     sm_p->u.event_mon_list.details->count_allocated)
  205.         {
  206.             sm_p->u.event_mon_list.details->error[errct].error =
  207.                         sm_p->msgarray_op.msgarray[i].op_status;
  208.             sm_p->u.event_mon_list.details->error[errct].addr =
  209.                         sm_p->msgarray_op.msgarray[i].svr_addr;
  210.             errct++;
  211.         }
  212.         else
  213.         {
  214.             sm_p->u.event_mon_list.details->count_exceeded = 1;
  215.         }
  216.         }
  217.     }
  218.     sm_p->u.event_mon_list.details->count_used = errct;
  219.     error = -PVFS_EDETAIL;
  220.     }
  221.  
  222.     PINT_msgpairarray_destroy(&sm_p->msgarray_op);
  223.  
  224.     sm_p->error_code  = error;
  225.  
  226.     PINT_SET_OP_COMPLETE;
  227.     return SM_ACTION_TERMINATE;
  228. }
  229.  
  230. static int event_mon_list_comp_fn(void* v_p,
  231.                                   struct PVFS_server_resp* resp_p,
  232.                                   int i)
  233. {
  234.     int j = 0;
  235.     PINT_smcb *smcb = v_p;
  236.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  237.  
  238.     /* if this particular request was successful, then store the 
  239.      * performance information in an array to be returned to caller
  240.      */
  241.     if (sm_p->msgarray_op.msgarray[i].op_status == 0)
  242.     {
  243.         memcpy(sm_p->u.event_mon_list.event_matrix[i],
  244.                resp_p->u.mgmt_event_mon.event_array,
  245.                resp_p->u.mgmt_event_mon.event_count
  246.                * sizeof(struct PVFS_mgmt_event));
  247.     }
  248.  
  249.     /* if this is the last response, check all of the status values and 
  250.      * return error code if any requests failed 
  251.      */
  252.     if (i == (sm_p->msgarray_op.count -1))
  253.     {
  254.         for(j = 0; j < sm_p->msgarray_op.count; j++)
  255.         {
  256.             if (sm_p->msgarray_op.msgarray[j].op_status != 0)
  257.             {
  258.                 return sm_p->msgarray_op.msgarray[j].op_status;
  259.             }
  260.         }
  261.     }
  262.     return 0;
  263. }
  264.  
  265. /*
  266.  * Local variables:
  267.  *  mode: c
  268.  *  c-indent-level: 4
  269.  *  c-basic-offset: 4
  270.  * End:
  271.  *
  272.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  273.  */
  274.