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 / small-io.sm < prev    next >
Text File  |  2010-03-08  |  8KB  |  282 lines

  1. /* 
  2.  * (C) 2001 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. /*
  8.  *  PVFS2 server state machine for driving I/O operations (read and write).
  9.  */
  10.  
  11. #include <string.h>
  12. #include <assert.h>
  13.  
  14. #include "server-config.h"
  15. #include "pvfs2-server.h"
  16. #include "pvfs2-attr.h"
  17. #include "pvfs2-request.h"
  18. #include "pint-distribution.h"
  19. #include "pint-request.h"
  20.  
  21. %%
  22.  
  23. machine pvfs2_small_io_sm
  24. {
  25.     state prelude
  26.     {
  27.     jump pvfs2_prelude_sm;
  28.     success => start_job;
  29.     default => send_response;
  30.     }
  31.  
  32.     state start_job 
  33.     {
  34.         run small_io_start_job;
  35.         default => check_size;
  36.     }
  37.  
  38.     state check_size
  39.     {
  40.         run small_io_check_size;
  41.         default => send_response;
  42.     }
  43.  
  44.     state send_response
  45.     {
  46.         jump pvfs2_final_response_sm;
  47.         default => cleanup;
  48.     }
  49.  
  50.     state cleanup
  51.     {
  52.     run small_io_cleanup;
  53.     default => terminate;
  54.     }
  55. }
  56.  
  57. %%
  58.  
  59. static PINT_sm_action small_io_start_job(
  60.         struct PINT_smcb *smcb, job_status_s *js_p)
  61. {
  62.     gossip_debug(GOSSIP_IO_DEBUG,"Executing small_io_start_job...\n");
  63.  
  64.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  65.     int ret;
  66.     job_id_t tmp_id;
  67.     PINT_Request_state * file_req_state;
  68.     PINT_request_file_data fdata;
  69.     PINT_Request_result result;
  70.     struct filesystem_configuration_s * fs_config;
  71.     struct server_configuration_s * server_config;
  72.  
  73.     memset(&s_op->resp.u.small_io, 0, sizeof(struct PVFS_servresp_small_io));
  74.  
  75.     /* set io type in response to io type in request.  This is
  76.      * needed by the client so it konws how to decode the response
  77.      * appropriately.
  78.      */
  79.     s_op->resp.u.small_io.io_type = s_op->req->u.small_io.io_type;
  80.  
  81.     if(s_op->req->u.small_io.io_type == PVFS_IO_READ &&
  82.        s_op->ds_attr.u.datafile.b_size == 0)
  83.     {
  84.         /* nothing to read.  return SM_ACTION_DEFERRED */
  85.         js_p->error_code = 0;
  86.         return SM_ACTION_COMPLETE;
  87.     }
  88.  
  89.     file_req_state = PINT_new_request_state(
  90.         s_op->req->u.small_io.file_req);
  91.     fdata.server_nr = s_op->req->u.small_io.server_nr;
  92.     fdata.server_ct = s_op->req->u.small_io.server_ct;
  93.     fdata.dist = s_op->req->u.small_io.dist;
  94.     result.offset_array = s_op->u.small_io.offsets;
  95.     result.size_array = s_op->u.small_io.sizes;
  96.     result.segmax = IO_MAX_REGIONS;
  97.     result.bytemax = s_op->req->u.small_io.aggregate_size;
  98.     result.bytes = 0;
  99.     result.segs = 0;
  100.  
  101.     PINT_REQUEST_STATE_SET_TARGET(file_req_state, 
  102.                                   s_op->req->u.small_io.file_req_offset);
  103.     PINT_REQUEST_STATE_SET_FINAL(file_req_state,
  104.                                  s_op->req->u.small_io.file_req_offset +
  105.                                  s_op->req->u.small_io.aggregate_size);
  106.  
  107.     s_op->resp.u.small_io.bstream_size = s_op->ds_attr.u.datafile.b_size;
  108.     fdata.fsize = s_op->ds_attr.u.datafile.b_size;
  109.     fdata.extend_flag = 
  110.         (s_op->req->u.small_io.io_type == PVFS_IO_READ) ? 0 : 1;
  111.  
  112.     /* calculate the offsets and sizes in the datafile for the read or write */
  113.     ret = PINT_process_request(
  114.         file_req_state,
  115.         NULL,
  116.         &fdata,
  117.         &result,
  118.         PINT_SERVER);
  119.     if(ret < 0)
  120.     {
  121.         gossip_err("small_io: Failed to process file request\n");
  122.         js_p->error_code = ret;
  123.         return SM_ACTION_COMPLETE;
  124.     }
  125.  
  126.     /* figure out if the fs config has trove data sync turned on or off
  127.      */
  128.     server_config = get_server_config_struct();
  129.     if(!server_config)
  130.     {
  131.         gossip_err("small_io: server config is NULL!\n");
  132.         js_p->error_code = -PVFS_EINVAL;
  133.         return SM_ACTION_COMPLETE;
  134.     }
  135.     
  136.     fs_config = PINT_config_find_fs_id(
  137.         server_config, s_op->req->u.small_io.fs_id);
  138.     if(!fs_config)
  139.     {
  140.         gossip_err("small_io: Failed to get filesystem "
  141.                    "config from fs_id of: %d\n",
  142.                    s_op->req->u.small_io.fs_id);
  143.         js_p->error_code = -PVFS_EINVAL;
  144.         return SM_ACTION_COMPLETE;
  145.     }
  146.  
  147.     if(s_op->req->u.small_io.io_type == PVFS_IO_WRITE)
  148.     {
  149.         ret = job_trove_bstream_write_list(
  150.            s_op->req->u.small_io.fs_id,
  151.            s_op->req->u.small_io.handle,
  152.            (char **)&s_op->req->u.small_io.buffer,
  153.            (TROVE_size *)&s_op->req->u.small_io.total_bytes,
  154.            1,
  155.            s_op->u.small_io.offsets,
  156.            s_op->u.small_io.sizes,
  157.            result.segs,
  158.            &s_op->resp.u.small_io.result_size,
  159.            (fs_config->trove_sync_data ? TROVE_SYNC : 0),
  160.            NULL,
  161.            smcb,
  162.            0,
  163.            js_p,
  164.            &tmp_id,
  165.            server_job_context,
  166.            s_op->req->hints);
  167.         if(ret < 0)
  168.         {
  169.             gossip_err("small_io: Failed to post trove bstream write\n");
  170.         }
  171.     }
  172.     else
  173.     {
  174.         /* allocate space for the read in the response buffer */
  175.         s_op->resp.u.small_io.buffer = BMI_memalloc(
  176.             s_op->addr, result.bytes, BMI_SEND);
  177.         if(!s_op->resp.u.small_io.buffer)
  178.         {
  179.             js_p->error_code = -PVFS_ENOMEM;
  180.             return SM_ACTION_COMPLETE;
  181.         }
  182.         
  183.         s_op->u.small_io.result_bytes = result.bytes;
  184.  
  185.         gossip_debug(GOSSIP_IO_DEBUG,"\tsubmitting job_trove_bstream_read_list for handle %llu\n"
  186.                                     ,llu(s_op->req->u.small_io.handle));
  187.         ret = job_trove_bstream_read_list(
  188.             s_op->req->u.small_io.fs_id,
  189.             s_op->req->u.small_io.handle,
  190.             (char **)&s_op->resp.u.small_io.buffer,
  191.             &s_op->u.small_io.result_bytes,
  192.             1,
  193.             s_op->u.small_io.offsets,
  194.             s_op->u.small_io.sizes,
  195.             result.segs,
  196.             &s_op->resp.u.small_io.result_size,
  197.             (fs_config->trove_sync_data ? TROVE_SYNC : 0),
  198.             NULL,
  199.             smcb,
  200.             0,
  201.             js_p,
  202.             &tmp_id,
  203.             server_job_context,
  204.             s_op->req->hints);
  205.         if(ret < 0)
  206.         {
  207.             gossip_err("small-io: Failed to post trove bstream read\n");
  208.             js_p->error_code = ret;
  209.             return SM_ACTION_COMPLETE;
  210.         }
  211.     }
  212.  
  213.     PINT_free_request_state(file_req_state);
  214.  
  215.     return ret;
  216. }
  217.  
  218. static PINT_sm_action small_io_check_size(
  219.         struct PINT_smcb *smcb, job_status_s *js_p)
  220. {
  221.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  222.     if(s_op->req->u.small_io.io_type == PVFS_IO_READ)
  223.     {
  224.         if(s_op->resp.u.small_io.result_size !=
  225.            s_op->u.small_io.result_bytes)
  226.         {
  227.             /* If we get here assume aio threaded isn't supported and 
  228.              * so result_size won't have been set correctly.  
  229.              * Just set to expected value from process_request for now */
  230.             s_op->resp.u.small_io.result_size = s_op->u.small_io.result_bytes;
  231.         }
  232.     }
  233.  
  234.     return SM_ACTION_COMPLETE;
  235. }
  236.  
  237. static PINT_sm_action small_io_cleanup(
  238.         struct PINT_smcb *smcb, job_status_s *js_p)
  239. {
  240.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  241.     if(s_op->req->u.small_io.io_type == PVFS_IO_READ &&
  242.        s_op->resp.u.small_io.buffer)
  243.     {
  244.         BMI_memfree(s_op->addr, s_op->resp.u.small_io.buffer, 
  245.                     s_op->req->u.small_io.total_bytes, BMI_SEND);
  246.     }
  247.  
  248.     return server_state_machine_complete(smcb);
  249. }
  250.  
  251. static inline enum PINT_server_req_access_type PINT_server_req_access_small_io(
  252.     struct PVFS_server_req *req)
  253. {
  254.     if(req->u.io.io_type == PVFS_IO_READ)
  255.     {
  256.         return PINT_SERVER_REQ_READONLY;
  257.     }
  258.     return PINT_SERVER_REQ_MODIFY;
  259. }
  260.  
  261. PINT_GET_OBJECT_REF_DEFINE(small_io);
  262.  
  263. struct PINT_server_req_params pvfs2_small_io_params =
  264. {
  265.     .string_name = "small_io",
  266.     .perm = PINT_SERVER_CHECK_NONE,
  267.     .access_type = PINT_server_req_access_small_io,
  268.     .sched_policy = PINT_SERVER_REQ_SCHEDULE,
  269.     .get_object_ref = PINT_get_object_ref_small_io,
  270.     .state_machine = &pvfs2_small_io_sm
  271. };
  272.  
  273. /*
  274.  * Local variables:
  275.  *  mode: c
  276.  *  c-indent-level: 4
  277.  *  c-basic-offset: 4
  278.  * End:
  279.  *
  280.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  281.  */
  282.