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 / flush.sm < prev    next >
Text File  |  2008-11-19  |  4KB  |  219 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 <assert.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <unistd.h>
  12. #include <fcntl.h>
  13.  
  14. #include "server-config.h"
  15. #include "pvfs2-server.h"
  16. #include "pvfs2-internal.h"
  17.  
  18. /*
  19.  * if given a metafile, do a keyval flush
  20.  * if given a datafile, do a bstream flush
  21.  */
  22. enum
  23. {
  24.     FLUSH_KEYVAL  = 4,
  25.     FLUSH_BSTREAM = 5
  26. };
  27.  
  28. void flush_init_state_machine(void);
  29.  
  30. %%
  31.  
  32. machine pvfs2_flush_sm
  33. {
  34.     state prelude
  35.     {
  36.     jump pvfs2_prelude_sm;
  37.     success => flush_check_type;
  38.     default => final_response;
  39.     }
  40.  
  41.     state flush_check_type
  42.     {
  43.     run flush_check_type;
  44.         FLUSH_KEYVAL => kflush;
  45.         FLUSH_BSTREAM => bflush;
  46.     default => cleanup;
  47.     }
  48.  
  49.     state kflush
  50.     {
  51.     run flush_keyval_flush;
  52.     default => kflush_check_error;
  53.     }
  54.  
  55.     state kflush_check_error
  56.     {
  57.     run flush_check_error;
  58.     default => final_response;
  59.     }
  60.  
  61.     state bflush
  62.     {
  63.     run flush_bstream_flush;
  64.     default => bflush_check_error;
  65.     }
  66.  
  67.     state bflush_check_error
  68.     {
  69.     run flush_check_error;
  70.     default => final_response;
  71.     }
  72.  
  73.     state final_response
  74.     {
  75.     jump pvfs2_final_response_sm;
  76.     default => cleanup;
  77.     }
  78.  
  79.     state cleanup
  80.     {
  81.     run flush_cleanup;
  82.     default => terminate;
  83.     }
  84. }
  85.  
  86. %%
  87.  
  88. static PINT_sm_action flush_check_type(
  89.         struct PINT_smcb *smcb, job_status_s *js_p)
  90. {
  91.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  92.     js_p->error_code = 0;
  93.  
  94.     if (s_op->attr.objtype == PVFS_TYPE_METAFILE)
  95.     {
  96.         js_p->error_code = FLUSH_KEYVAL;
  97.     }
  98.     else if (s_op->attr.objtype == PVFS_TYPE_DATAFILE)
  99.     {
  100.         js_p->error_code = FLUSH_BSTREAM;
  101.     }
  102.     return SM_ACTION_COMPLETE;
  103. }
  104.  
  105. /*
  106.  * Function: flush_keyval_flush
  107.  *
  108.  * Params:  server_op *s_op,
  109.  *        job_status_s *js_p
  110.  *
  111.  * Pre: None
  112.  * Post: None
  113.  * Returns: int
  114.  *
  115.  * Synopsys: send a keyval flush request to storage
  116.  *
  117.  */
  118. static PINT_sm_action flush_keyval_flush(
  119.         struct PINT_smcb *smcb, job_status_s *js_p)
  120. {
  121.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  122.     int ret = -1;
  123.     job_id_t tmp_id;
  124.  
  125.     gossip_debug(GOSSIP_SERVER_DEBUG, " doing keyval flush on %llu,%d\n",
  126.                  llu(s_op->req->u.flush.handle), s_op->req->u.flush.fs_id);
  127.  
  128.     ret = job_trove_keyval_flush(
  129.         s_op->req->u.flush.fs_id,
  130.         s_op->req->u.flush.handle,
  131.         s_op->req->u.flush.flags,
  132.         smcb,
  133.         0,
  134.         js_p,
  135.         &tmp_id,
  136.         server_job_context, s_op->req->hints);
  137.  
  138.     return ret;
  139. }
  140.  
  141. static PINT_sm_action flush_check_error(
  142.         struct PINT_smcb *smcb, job_status_s *js_p)
  143. {
  144.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  145.     char buf[64] = {0};
  146.     if (js_p->error_code != 0)
  147.     {
  148.         PVFS_strerror_r(js_p->error_code, buf, 64);
  149.  
  150.         gossip_err("failed to flush handle %llu: %s\n",
  151.                    llu(s_op->req->u.flush.handle), buf);
  152.     }
  153.     return SM_ACTION_COMPLETE;
  154. }
  155.  
  156. /*
  157.  * Function: flush_bstream_flush
  158.  *
  159.  * Params:  server_op *s_op,
  160.  *        job_status_s *js_p
  161.  *
  162.  * Pre: None
  163.  * Post: None
  164.  * Returns: int
  165.  *
  166.  * Synopsys: send a bstream flush request to storage
  167.  *
  168.  */
  169. static PINT_sm_action flush_bstream_flush(
  170.         struct PINT_smcb *smcb, job_status_s *js_p)
  171. {
  172.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  173.     int ret = -1;
  174.     job_id_t i;
  175.  
  176.     gossip_debug(GOSSIP_SERVER_DEBUG, " doing bstream flush on %llu,%d\n",
  177.                  llu(s_op->req->u.flush.handle), s_op->req->u.flush.fs_id);
  178.  
  179.     ret = job_trove_bstream_flush(
  180.         s_op->req->u.flush.fs_id,
  181.         s_op->req->u.flush.handle,
  182.         s_op->req->u.flush.flags,
  183.         smcb,
  184.         0,
  185.         js_p,
  186.         &i,
  187.         server_job_context, s_op->req->hints);
  188.  
  189.     return ret;
  190. }
  191.         
  192. static PINT_sm_action flush_cleanup(
  193.         struct PINT_smcb *smcb, job_status_s *js_p)
  194. {
  195.     return(server_state_machine_complete(smcb));
  196. }
  197.  
  198. PINT_GET_OBJECT_REF_DEFINE(flush);
  199.  
  200. struct PINT_server_req_params pvfs2_flush_params =
  201. {
  202.     .string_name = "flush",
  203.     .perm = PINT_SERVER_CHECK_NONE,
  204.     .access_type = PINT_server_req_modify,
  205.     .sched_policy = PINT_SERVER_REQ_SCHEDULE,
  206.     .get_object_ref = PINT_get_object_ref_flush,
  207.     .state_machine = &pvfs2_flush_sm
  208. };
  209.  
  210. /*
  211.  * Local variables:
  212.  *  mode: c
  213.  *  c-indent-level: 4
  214.  *  c-basic-offset: 4
  215.  * End:
  216.  *
  217.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  218.  */
  219.