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

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