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 / client / sysint / mgmt-remove-object.sm < prev    next >
Text File  |  2008-11-19  |  6KB  |  240 lines

  1. /* 
  2.  * (C) 2003 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. /** \file
  8.  *  \ingroup mgmtint
  9.  *
  10.  *  PVFS2 management interface routines for removing specific objects.
  11.  *  These are used primarily for file system repair purposes (to remove
  12.  *  orphaned objects), although they can also be used to create specific
  13.  *  inconsistency cases for testing of failure tolerance.
  14.  */
  15.  
  16. #include <string.h>
  17. #include <assert.h>
  18.  
  19. #include "client-state-machine.h"
  20. #include "pvfs2-debug.h"
  21. #include "job.h"
  22. #include "gossip.h"
  23. #include "str-utils.h"
  24. #include "pint-cached-config.h"
  25. #include "PINT-reqproto-encode.h"
  26. #include "pvfs2-internal.h"
  27.  
  28. extern job_context_id pint_client_sm_context;
  29.  
  30. static int mgmt_remove_object_comp_fn(
  31.     void *v_p, struct PVFS_server_resp *resp_p, int i);
  32.  
  33. %%
  34.  
  35. machine pvfs2_client_mgmt_remove_object_sm
  36. {
  37.     state init
  38.     {
  39.         run mgmt_remove_init;
  40.         default => remove_object_setup_msgpair;
  41.     }
  42.  
  43.     state remove_object_setup_msgpair
  44.     {
  45.         run mgmt_remove_object_setup_msgpair;
  46.         success => remove_object_xfer_msgpair;
  47.         default => cleanup;
  48.     }
  49.  
  50.     state remove_object_xfer_msgpair
  51.     {
  52.         jump pvfs2_msgpairarray_sm;
  53.         default => cleanup;
  54.     }
  55.  
  56.     state cleanup
  57.     {
  58.         run mgmt_remove_cleanup;
  59.         default => terminate;
  60.     }
  61. }
  62.  
  63. %%
  64.  
  65. /** Initiate removal of a specific file system object.
  66.  */
  67. PVFS_error PVFS_imgmt_remove_object(
  68.     PVFS_object_ref object_ref, 
  69.     PVFS_credentials *credentials,
  70.     PVFS_sys_op_id *op_id,
  71.     PVFS_hint hints,
  72.     void *user_ptr)
  73. {
  74.     PVFS_error ret = -PVFS_EINVAL;
  75.     PINT_smcb *smcb = NULL;
  76.     PINT_client_sm *sm_p = NULL;
  77.  
  78.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  79.                  "PVFS_imgmt_remove_object entered\n");
  80.  
  81.     if ((object_ref.handle == PVFS_HANDLE_NULL) ||
  82.         (object_ref.fs_id == PVFS_FS_ID_NULL))
  83.     {
  84.         return ret;
  85.     }
  86.  
  87.     PINT_smcb_alloc(&smcb, PVFS_MGMT_REMOVE_OBJECT,
  88.              sizeof(struct PINT_client_sm),
  89.              client_op_state_get_machine,
  90.              client_state_machine_terminate,
  91.              pint_client_sm_context);
  92.     if (smcb == NULL)
  93.     {
  94.         return -PVFS_ENOMEM;
  95.     }
  96.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  97.  
  98.     PINT_init_msgarray_params(sm_p, object_ref.fs_id);
  99.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  100.     sm_p->object_ref = object_ref;
  101.     PVFS_hint_copy(hints, &sm_p->hints);
  102.  
  103.     gossip_debug(
  104.         GOSSIP_CLIENT_DEBUG, "Trying to remove handle %llu,%d\n",
  105.         llu(object_ref.handle), object_ref.fs_id);
  106.  
  107.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_imgmt_remove_object calling "
  108.                  "PINT_client_state_machine_post()\n");
  109.  
  110.     return PINT_client_state_machine_post(
  111.         smcb,  op_id, user_ptr);
  112. }
  113.  
  114. /** Remove a specific file system object.
  115.  */
  116. PVFS_error PVFS_mgmt_remove_object(
  117.     PVFS_object_ref object_ref, 
  118.     PVFS_credentials *credentials,
  119.     PVFS_hint hints)
  120. {
  121.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  122.     PVFS_sys_op_id op_id;
  123.  
  124.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  125.                  "PVFS_mgmt_remove_object entered\n");
  126.  
  127.     ret = PVFS_imgmt_remove_object(object_ref, credentials, &op_id, NULL, hints);
  128.     if (ret)
  129.     {
  130.         PVFS_perror_gossip("PVFS_imgmt_remove_object call", ret);
  131.         error = ret;
  132.     }
  133.     else
  134.     {
  135.         ret = PVFS_mgmt_wait(op_id, "remove_object", &error);
  136.         if (ret)
  137.         {
  138.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  139.             error = ret;
  140.         }
  141.     }
  142.  
  143.     PINT_mgmt_release(op_id);
  144.     return error;
  145. }
  146.  
  147. /****************************************************************/
  148.  
  149. static PINT_sm_action mgmt_remove_init(
  150.     struct PINT_smcb *smcb, job_status_s *js_p)
  151. {
  152.     gossip_debug(GOSSIP_CLIENT_DEBUG, "mgmt_remove_init called\n");
  153.  
  154.     assert(js_p->error_code == 0);
  155.     return SM_ACTION_COMPLETE;
  156. }
  157.  
  158. static PINT_sm_action mgmt_remove_object_setup_msgpair(
  159.     struct PINT_smcb *smcb, job_status_s *js_p)
  160. {
  161.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  162.     int ret = -PVFS_EINVAL;
  163.     PINT_sm_msgpair_state *msg_p = NULL;
  164.  
  165.     js_p->error_code = 0;
  166.  
  167.     PINT_msgpair_init(&sm_p->msgarray_op);
  168.     msg_p = &sm_p->msgarray_op.msgpair;
  169.  
  170.     PINT_SERVREQ_MGMT_REMOVE_OBJECT_FILL(
  171.         msg_p->req,
  172.         *sm_p->cred_p,
  173.         sm_p->object_ref.fs_id,
  174.         sm_p->object_ref.handle,
  175.         sm_p->hints);
  176.  
  177.     gossip_debug(GOSSIP_REMOVE_DEBUG, "- doing MGMT_REMOVE_OBJECT on "
  178.                  "%llu,%d\n", llu(sm_p->object_ref.handle),
  179.                  sm_p->object_ref.fs_id);
  180.  
  181.     msg_p->fs_id = sm_p->object_ref.fs_id;
  182.     msg_p->handle = sm_p->object_ref.handle;
  183.     msg_p->retry_flag = PVFS_MSGPAIR_NO_RETRY;
  184.     msg_p->comp_fn = mgmt_remove_object_comp_fn;
  185.  
  186.     ret = PINT_cached_config_map_to_server(
  187.         &msg_p->svr_addr, msg_p->handle, msg_p->fs_id);
  188.  
  189.     if (ret)
  190.     {
  191.         gossip_err("Failed to map server address\n");
  192.         js_p->error_code = ret;
  193.     }
  194.  
  195.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  196.     return SM_ACTION_COMPLETE;
  197. }
  198.  
  199. static int mgmt_remove_object_comp_fn(
  200.     void *v_p, struct PVFS_server_resp *resp_p, int index)
  201. {
  202.     PINT_smcb *smcb = v_p;
  203.     PINT_client_sm *sm_p __attribute__((unused)) =
  204.         PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  205.  
  206.     assert(resp_p->op == PVFS_SERV_MGMT_REMOVE_OBJECT);
  207.  
  208.     if (resp_p->status == 0)
  209.     {
  210.         gossip_debug(
  211.             GOSSIP_CLIENT_DEBUG,
  212.             "  mgmt_remove_object_comp_fn: object %llu,%d removed\n",
  213.             llu(sm_p->object_ref.handle), 
  214.             sm_p->object_ref.fs_id);
  215.     }
  216.     return resp_p->status;
  217. }
  218.  
  219. static PINT_sm_action mgmt_remove_cleanup(
  220.     struct PINT_smcb *smcb, job_status_s *js_p)
  221. {
  222.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  223.     gossip_debug(GOSSIP_CLIENT_DEBUG, "mgmt_remove_cleanup called\n");
  224.  
  225.     sm_p->error_code = js_p->error_code;
  226.  
  227.     PINT_SET_OP_COMPLETE;
  228.     return SM_ACTION_TERMINATE;
  229. }
  230.  
  231. /*
  232.  * Local variables:
  233.  *  mode: c
  234.  *  c-indent-level: 4
  235.  *  c-basic-offset: 4
  236.  * End:
  237.  *
  238.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  239.  */
  240.