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 / statfs.sm < prev    next >
Text File  |  2008-02-11  |  4KB  |  174 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 <assert.h>
  13.  
  14. #include "pvfs2-server.h"
  15. #include "trove-handle-mgmt.h"
  16. #include "pint-cached-config.h"
  17.  
  18. #ifdef HAVE_SYSINFO
  19. #include <sys/sysinfo.h>
  20. #endif
  21.  
  22. %%
  23.  
  24. machine pvfs2_statfs_sm
  25. {
  26.     state prelude
  27.     {
  28.         jump pvfs2_prelude_sm;
  29.         default => do_statfs;
  30.     }
  31.  
  32.     state do_statfs
  33.     {
  34.         run statfs_do_statfs;
  35.         default => final_response;
  36.     }
  37.  
  38.     state final_response
  39.     {
  40.         jump pvfs2_final_response_sm;
  41.         default => cleanup;
  42.     }
  43.  
  44.     state cleanup
  45.     {
  46.         run statfs_cleanup;
  47.         default => terminate;
  48.     }
  49. }
  50.  
  51. %%
  52.  
  53. /* statfs_do_statfs()
  54.  *
  55.  * issue the trove call to retrieve fs statistics
  56.  */
  57. static PINT_sm_action statfs_do_statfs(
  58.         struct PINT_smcb *smcb, job_status_s *js_p)
  59. {
  60.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  61.     int ret = -1;
  62.     TROVE_context_id tmp_context;
  63.     struct server_configuration_s *user_opts = get_server_config_struct();
  64.  
  65.     /* first try to gather handle statistics */
  66.     ret = trove_handle_get_statistics(
  67.         s_op->req->u.statfs.fs_id,
  68.         &s_op->resp.u.statfs.stat.handles_available_count);
  69.  
  70.     if (ret < 0)
  71.     {
  72.         js_p->error_code = ret;
  73.         return SM_ACTION_COMPLETE;
  74.     }
  75.  
  76.     /* find out how many total handles this server controls */
  77.     ret = PINT_cached_config_get_server_handle_count(
  78.         user_opts->host_id, s_op->req->u.statfs.fs_id,
  79.         &s_op->resp.u.statfs.stat.handles_total_count);
  80.     if(ret < 0)
  81.     {   
  82.         js_p->error_code = ret;
  83.         return SM_ACTION_COMPLETE;
  84.     }
  85.  
  86.     /* we need a context to be able to make the getinfo call */
  87.     ret = trove_open_context(s_op->req->u.statfs.fs_id, &tmp_context);
  88.     if (ret < 0)
  89.     {
  90.         js_p->error_code = ret;
  91.         return SM_ACTION_COMPLETE;
  92.     }
  93.  
  94.     ret = trove_collection_getinfo(
  95.         s_op->req->u.statfs.fs_id, tmp_context,
  96.         PVFS_COLLECTION_STATFS, &(s_op->resp.u.statfs.stat));
  97.  
  98.     /* close context regardless of whether getinfo was successful */
  99.     trove_close_context(s_op->req->u.statfs.fs_id, tmp_context);
  100.     
  101.     /* getinfo should always return immediately, no testing needed */
  102.     assert(ret != 0);
  103.  
  104. #ifdef HAVE_SYSINFO
  105.     {
  106.         struct sysinfo system_metrics;
  107.         memset(&system_metrics, 0, sizeof(struct sysinfo));
  108.         if (sysinfo(&system_metrics) == 0)
  109.         {
  110.             s_op->resp.u.statfs.stat.ram_total_bytes = (uint64_t)
  111.                 (system_metrics.totalram * system_metrics.mem_unit);
  112.             s_op->resp.u.statfs.stat.ram_free_bytes = (uint64_t)
  113.                 (system_metrics.freeram * system_metrics.mem_unit);
  114.             s_op->resp.u.statfs.stat.uptime_seconds = (uint64_t)
  115.                 system_metrics.uptime;
  116.             s_op->resp.u.statfs.stat.load_1 = (uint64_t)
  117.                 system_metrics.loads[0];
  118.             s_op->resp.u.statfs.stat.load_5 = (uint64_t)
  119.                 system_metrics.loads[1];
  120.             s_op->resp.u.statfs.stat.load_15 = (uint64_t)
  121.                 system_metrics.loads[2];
  122.         }
  123.     }
  124. #else
  125.     s_op->resp.u.statfs.stat.ram_total_bytes = 0;
  126.     s_op->resp.u.statfs.stat.ram_free_bytes = 0;
  127.     s_op->resp.u.statfs.stat.uptime_seconds = 0;
  128.     s_op->resp.u.statfs.stat.load_1 = 0;
  129.     s_op->resp.u.statfs.stat.load_5 = 0;
  130.     s_op->resp.u.statfs.stat.load_15 = 0;
  131. #endif
  132.  
  133.     js_p->error_code = ((ret != 1) ? ret : 0);
  134.     return SM_ACTION_COMPLETE;
  135. }
  136.  
  137.  
  138. /* statfs_cleanup()
  139.  *
  140.  * cleans up any resources consumed by this state machine and ends
  141.  * execution of the machine
  142.  */
  143. static PINT_sm_action statfs_cleanup(
  144.         struct PINT_smcb *smcb, job_status_s *js_p)
  145. {
  146.     return(server_state_machine_complete(smcb));
  147. }
  148.  
  149. static inline int PINT_get_object_ref_statfs(
  150.     struct PVFS_server_req *req, PVFS_fs_id *fs_id, PVFS_handle *handle)
  151. {
  152.     *fs_id = req->u.statfs.fs_id;
  153.     *handle = PVFS_HANDLE_NULL;
  154.     return 0;
  155. }
  156.  
  157. struct PINT_server_req_params pvfs2_statfs_params =
  158. {
  159.     .string_name = "statfs",
  160.     .get_object_ref = PINT_get_object_ref_statfs,
  161.     .state_machine = &pvfs2_statfs_sm
  162. };
  163.  
  164.  
  165. /*
  166.  * Local variables:
  167.  *  mode: c
  168.  *  c-indent-level: 4
  169.  *  c-basic-offset: 4
  170.  * End:
  171.  *
  172.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  173.  */
  174.