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 / iterate-handles.sm < prev    next >
Text File  |  2008-11-19  |  5KB  |  188 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.  
  13. #include "pvfs2-server.h"
  14. #include "server-config.h"
  15.  
  16. %%
  17.  
  18. machine pvfs2_iterate_handles_sm
  19. {
  20.     state prelude
  21.     {
  22.         jump pvfs2_prelude_sm;
  23.         default => do_work;
  24.     }
  25.  
  26.     state do_work
  27.     {
  28.         run iterate_handles_do_work;
  29.         default => fill_resp;
  30.     }
  31.  
  32.     state fill_resp
  33.     {
  34.         run iterate_handles_fill_resp;
  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 iterate_handles_cleanup;
  47.         default => terminate;
  48.     }
  49. }
  50.  
  51. %%
  52.  
  53. /* iterate_handles_cleanup()
  54.  *
  55.  * cleans up any resources consumed by this state machine and ends
  56.  * execution of the machine
  57.  */
  58. static PINT_sm_action iterate_handles_cleanup(
  59.         struct PINT_smcb *smcb, job_status_s *js_p)
  60. {
  61.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  62.     if(s_op->resp.u.mgmt_iterate_handles.handle_array)
  63.     free(s_op->resp.u.mgmt_iterate_handles.handle_array);
  64.  
  65.     return(server_state_machine_complete(smcb));
  66. }
  67.  
  68.  
  69. /* iterate_handles_do_work()
  70.  *
  71.  * actually performs work necessary to retrieve handles
  72.  */
  73. static PINT_sm_action iterate_handles_do_work(
  74.         struct PINT_smcb *smcb, job_status_s *js_p)
  75. {
  76.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  77.     job_id_t tmp_id;
  78.     int ret;
  79.  
  80.     /* allocate memory to hold handles */
  81.     s_op->resp.u.mgmt_iterate_handles.handle_array
  82.     = (PVFS_handle*)malloc(s_op->req->u.mgmt_iterate_handles.handle_count *
  83.     sizeof(PVFS_handle));
  84.     if(!s_op->resp.u.mgmt_iterate_handles.handle_array)
  85.     {
  86.     js_p->error_code = -PVFS_ENOMEM;
  87.     return SM_ACTION_COMPLETE;
  88.     }
  89.     
  90.     s_op->resp.u.mgmt_iterate_handles.position
  91.     = s_op->req->u.mgmt_iterate_handles.position;
  92.  
  93.     if(s_op->req->u.mgmt_iterate_handles.flags == PVFS_MGMT_RESERVED)
  94.     {
  95.         /* for now the only special case reserved handles are those that are
  96.          * allocated by precreate
  97.          */
  98.         ret = job_precreate_pool_iterate_handles(
  99.             s_op->req->u.mgmt_iterate_handles.fs_id,
  100.             s_op->resp.u.mgmt_iterate_handles.position,
  101.             s_op->resp.u.mgmt_iterate_handles.handle_array,
  102.             s_op->req->u.mgmt_iterate_handles.handle_count,
  103.             0,
  104.             NULL,
  105.             smcb,
  106.             0,
  107.             js_p,
  108.             &tmp_id,
  109.             server_job_context,
  110.             s_op->req->hints);
  111.     }
  112.     else if(s_op->req->u.mgmt_iterate_handles.flags == 0)
  113.     {
  114.         ret = job_trove_dspace_iterate_handles(
  115.             s_op->req->u.mgmt_iterate_handles.fs_id,
  116.             s_op->resp.u.mgmt_iterate_handles.position,
  117.             s_op->resp.u.mgmt_iterate_handles.handle_array,
  118.             s_op->req->u.mgmt_iterate_handles.handle_count,
  119.             0,
  120.             NULL,
  121.             smcb,
  122.             0,
  123.             js_p,
  124.             &tmp_id,
  125.             server_job_context);
  126.     }
  127.     else
  128.     {
  129.         gossip_err("Error: unsupported mgmt_iterate_handles flags: %d\n",
  130.             s_op->req->u.mgmt_iterate_handles.flags);
  131.         js_p->error_code = -PVFS_EINVAL;
  132.         return SM_ACTION_COMPLETE;
  133.     }
  134.  
  135.     if (ret < 0)
  136.         return ret;  /* error */
  137.     if (ret == 1)
  138.         return SM_ACTION_COMPLETE;  /* immediate */
  139.     return SM_ACTION_DEFERRED;
  140. }
  141.  
  142. /* iterate_handles_fill_resp()
  143.  *
  144.  * gathers results from job status for response
  145.  */
  146. static PINT_sm_action iterate_handles_fill_resp(
  147.         struct PINT_smcb *smcb, job_status_s *js_p)
  148. {
  149.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  150.     if(js_p->error_code != 0)
  151.     {
  152.     /* propigate error and let final_response handle it */
  153.     return SM_ACTION_COMPLETE;
  154.     }
  155.  
  156.     s_op->resp.u.mgmt_iterate_handles.handle_count = js_p->count;
  157.     s_op->resp.u.mgmt_iterate_handles.position = js_p->position;
  158.  
  159.     return SM_ACTION_COMPLETE;
  160. }
  161.  
  162. static inline int PINT_get_object_ref_iterate_handles(
  163.     struct PVFS_server_req *req, PVFS_fs_id *fs_id, PVFS_handle *handle)
  164. {
  165.     *fs_id = req->u.mgmt_iterate_handles.fs_id;
  166.     *handle = PVFS_HANDLE_NULL;
  167.     return 0;
  168. }
  169.  
  170. struct PINT_server_req_params pvfs2_iterate_handles_params =
  171. {
  172.     .string_name = "mgmt_iterate_handles",
  173.     .perm = PINT_SERVER_CHECK_NONE,
  174.     .get_object_ref = PINT_get_object_ref_iterate_handles,
  175.     .state_machine = &pvfs2_iterate_handles_sm
  176. };
  177.  
  178. /*
  179.  * Local variables:
  180.  *  mode: c
  181.  *  c-indent-level: 4
  182.  *  c-basic-offset: 4
  183.  * End:
  184.  *
  185.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  186.  */
  187.  
  188.