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 / batch-remove.sm < prev    next >
Text File  |  2008-09-08  |  5KB  |  227 lines

  1. /* 
  2.  * (C) 2001 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #include <string.h>
  8. #include <assert.h>
  9.  
  10. #include "server-config.h"
  11. #include "pvfs2-server.h"
  12. #include "pvfs2-attr.h"
  13. #include "gossip.h"
  14. #include "pvfs2-internal.h"
  15.  
  16. enum
  17. {
  18.     REMOVE_NEXT = 1
  19. };
  20.  
  21. %%
  22.  
  23. machine pvfs2_batch_remove_sm
  24. {
  25.     state setup_prelude
  26.     {
  27.         run setup_prelude;
  28.         default => prelude;
  29.     }
  30.  
  31.     state prelude
  32.     {
  33.         jump pvfs2_prelude_work_sm;
  34.         success => setup_remove;
  35.         default => release;
  36.     }
  37.  
  38.     state setup_remove
  39.     {
  40.         run setup_remove;
  41.         success => remove;
  42.         default => remove_complete;
  43.     }
  44.  
  45.     state remove
  46.     {
  47.         jump pvfs2_remove_work_sm;
  48.         default => remove_complete;
  49.     }
  50.  
  51.     state remove_complete
  52.     {
  53.         run remove_complete;
  54.         default => release;
  55.     }
  56.  
  57.     state release
  58.     {
  59.         run release;
  60.         default => remove_next;
  61.     }
  62.  
  63.     state remove_next
  64.     {
  65.         run remove_next;
  66.         REMOVE_NEXT => setup_prelude;
  67.         default => response;
  68.     }
  69.  
  70.     state response
  71.     {
  72.         jump pvfs2_final_response_sm;
  73.         default => cleanup;
  74.     }
  75.  
  76.     state cleanup
  77.     {
  78.         run cleanup;
  79.         default => terminate;
  80.     }
  81. }
  82.  
  83. %%
  84.  
  85. static PINT_sm_action setup_prelude(
  86.     struct PINT_smcb *smcb, job_status_s *js_p)
  87. {
  88.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  89.     assert(s_op);
  90.  
  91.     /* get the object to remove, the access and scheduling policies */
  92.     s_op->target_fs_id = s_op->req->u.batch_remove.fs_id;
  93.     s_op->target_handle =
  94.         s_op->req->u.batch_remove.handles[s_op->u.batch_remove.handle_index];
  95.  
  96.     s_op->access_type = PINT_server_req_get_access_type(s_op->req);
  97.     s_op->sched_policy = PINT_server_req_get_sched_policy(s_op->req);
  98.  
  99.     js_p->error_code = 0;
  100.     return SM_ACTION_COMPLETE;
  101. }
  102.  
  103. static PINT_sm_action setup_remove(
  104.     struct PINT_smcb *smcb, job_status_s *js_p)
  105. {
  106.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  107.     struct PINT_server_op *remove_op;
  108.     int ret;
  109.  
  110.     remove_op = malloc(sizeof(*remove_op));
  111.     if(!remove_op)
  112.     {
  113.         js_p->error_code = -PVFS_ENOMEM;
  114.         return SM_ACTION_COMPLETE;
  115.     }
  116.     memset(remove_op, 0, sizeof(*remove_op));
  117.  
  118.     remove_op->u.remove.fs_id = s_op->target_fs_id;
  119.     remove_op->u.remove.handle = s_op->target_handle;
  120.  
  121.     ret = PINT_sm_push_frame(smcb, 0, remove_op);
  122.     if(ret < 0)
  123.     {
  124.         js_p->error_code = ret;
  125.     }
  126.     return SM_ACTION_COMPLETE;
  127. }
  128.  
  129. static PINT_sm_action remove_complete(
  130.     struct PINT_smcb *smcb, job_status_s *js_p)
  131. {
  132.     struct PINT_server_op *remove_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  133.     struct PINT_server_op *s_op;
  134.     int error_code;
  135.     int task_id;
  136.     int remaining;
  137.  
  138.     s_op = PINT_sm_pop_frame(smcb, &task_id, &error_code, &remaining);
  139.  
  140.     free(remove_op);
  141.  
  142.     if(error_code != 0)
  143.     {
  144.         s_op->u.batch_remove.error_code = error_code;
  145.         return SM_ACTION_COMPLETE;
  146.     }
  147.  
  148.     return SM_ACTION_COMPLETE;
  149. }
  150.  
  151. static PINT_sm_action release(
  152.     struct PINT_smcb *smcb, job_status_s *js_p)
  153. {
  154.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  155.     job_id_t tmp_id;
  156.     int ret;
  157.  
  158.     /* we need to release the scheduled remove request on the target
  159.      * handle.  The schedule call occurred in the prelude_work sm */
  160.  
  161.     if(!s_op->scheduled_id)
  162.     {
  163.         return SM_ACTION_COMPLETE;
  164.     }
  165.  
  166.     if(js_p->error_code)
  167.     {
  168.         s_op->u.batch_remove.error_code = js_p->error_code;
  169.     }
  170.  
  171.     ret = job_req_sched_release(s_op->scheduled_id, smcb, 0, js_p, &tmp_id,
  172.                                 server_job_context);
  173.     s_op->scheduled_id = 0;
  174.     return ret;
  175. }
  176.  
  177. static PINT_sm_action remove_next(
  178.     struct PINT_smcb *smcb, job_status_s *js_p)
  179. {
  180.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  181.  
  182.     if(s_op->u.batch_remove.error_code != 0)
  183.     {
  184.         js_p->error_code = s_op->u.batch_remove.error_code;
  185.         return SM_ACTION_COMPLETE;
  186.     }
  187.  
  188.     if(js_p->error_code != 0)
  189.     {
  190.         return SM_ACTION_COMPLETE;
  191.     }
  192.  
  193.     s_op->u.batch_remove.handle_index++;
  194.     if(s_op->u.batch_remove.handle_index < s_op->req->u.batch_remove.handle_count)
  195.     {
  196.         js_p->error_code = REMOVE_NEXT;
  197.     }
  198.  
  199.     return SM_ACTION_COMPLETE;
  200. }
  201.  
  202.  
  203. static int cleanup(
  204.         struct PINT_smcb *smcb, job_status_s *js_p)
  205. {
  206.     return(server_state_machine_complete(smcb));
  207. }
  208.  
  209. struct PINT_server_req_params pvfs2_batch_remove_params =
  210. {
  211.     .string_name = "batch_remove",
  212.     .perm = PINT_SERVER_CHECK_NONE,
  213.     .access_type = PINT_server_req_modify,
  214.     .state_machine = &pvfs2_batch_remove_sm
  215. };
  216.  
  217.  
  218. /*
  219.  * Local variables:
  220.  *  mode: c
  221.  *  c-indent-level: 4
  222.  *  c-basic-offset: 4
  223.  * End:
  224.  *
  225.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  226.  */
  227.