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-dirent.sm < prev    next >
Text File  |  2008-11-19  |  6KB  |  245 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 directory
  11.  *  entries.  These are used primarily for file system repair purposes,
  12.  *  although they can also be used to create specific inconsistency cases
  13.  *  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_dirent_comp_fn(
  31.     void *v_p, struct PVFS_server_resp *resp_p, int i);
  32.  
  33. %%
  34.  
  35. machine pvfs2_client_mgmt_remove_dirent_sm
  36. {
  37.     state init
  38.     {
  39.         run mgmt_remove_dirent_init;
  40.         default => remove_dirent_setup_msgpair;
  41.     }
  42.  
  43.     state remove_dirent_setup_msgpair
  44.     {
  45.         run mgmt_remove_dirent_setup_msgpair;
  46.         success => remove_dirent_xfer_msgpair;
  47.         default => cleanup;
  48.     }
  49.  
  50.     state remove_dirent_xfer_msgpair
  51.     {
  52.         jump pvfs2_msgpairarray_sm;
  53.         default => cleanup;
  54.     }
  55.  
  56.     state cleanup
  57.     {
  58.         run mgmt_remove_dirent_cleanup;
  59.         default => terminate;
  60.     }
  61. }
  62.  
  63. %%
  64.  
  65. /** Initiate removal of a specific directory entry.
  66.  */
  67. PVFS_error PVFS_imgmt_remove_dirent(
  68.     PVFS_object_ref parent_ref,
  69.     char *entry,
  70.     PVFS_credentials *credentials,
  71.     PVFS_mgmt_op_id *op_id,
  72.     PVFS_hint hints,
  73.     void *user_ptr)
  74. {
  75.     PVFS_error ret = -PVFS_EINVAL;
  76.     PINT_smcb *smcb = NULL;
  77.     PINT_client_sm *sm_p = NULL;
  78.  
  79.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  80.                  "PVFS_imgmt_remove_dirent entered\n");
  81.  
  82.     if ((parent_ref.handle == PVFS_HANDLE_NULL) ||
  83.         (parent_ref.fs_id == PVFS_FS_ID_NULL))
  84.     {
  85.         gossip_err("invalid (NULL) required argument\n");
  86.         return ret;
  87.     }
  88.  
  89.     PINT_smcb_alloc(&smcb, PVFS_MGMT_REMOVE_DIRENT,
  90.              sizeof(struct PINT_client_sm),
  91.              client_op_state_get_machine,
  92.              client_state_machine_terminate,
  93.              pint_client_sm_context);
  94.     if (smcb == NULL)
  95.     {
  96.         return -PVFS_ENOMEM;
  97.     }
  98.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  99.  
  100.     PINT_init_msgarray_params(sm_p, parent_ref.fs_id);
  101.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  102.     sm_p->parent_ref = parent_ref;
  103.     sm_p->u.mgmt_remove_dirent.entry = entry;
  104.     PVFS_hint_copy(hints, &sm_p->hints);
  105.  
  106.     gossip_debug(
  107.         GOSSIP_CLIENT_DEBUG, "Trying to remove dirent %s under %llu,%d\n",
  108.         sm_p->u.mgmt_remove_dirent.entry, llu(parent_ref.handle),
  109.         parent_ref.fs_id);
  110.  
  111.     return PINT_client_state_machine_post(
  112.         smcb,  op_id, user_ptr);
  113. }
  114.  
  115. /** Remove a specific directory entry.
  116.  */
  117. PVFS_error PVFS_mgmt_remove_dirent(
  118.     PVFS_object_ref parent_ref,
  119.     char *entry,
  120.     PVFS_credentials *credentials,
  121.     PVFS_hint hints)
  122. {
  123.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  124.     PVFS_mgmt_op_id op_id;
  125.  
  126.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  127.                  "PVFS_mgmt_remove_dirent entered\n");
  128.  
  129.     ret = PVFS_imgmt_remove_dirent(
  130.         parent_ref, entry, credentials, &op_id, hints, NULL);
  131.     if (ret)
  132.     {
  133.         PVFS_perror_gossip("PVFS_imgmt_remove_dirent call", ret);
  134.         error = ret;
  135.     }
  136.     else
  137.     {
  138.         ret = PVFS_mgmt_wait(op_id, "remove_dirent", &error);
  139.         if (ret)
  140.         {
  141.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  142.             error = ret;
  143.         }
  144.     }
  145.  
  146.     PINT_mgmt_release(op_id);
  147.     return error;
  148. }
  149.  
  150. /****************************************************************/
  151.  
  152. static PINT_sm_action mgmt_remove_dirent_init(
  153.     struct PINT_smcb *smcb, job_status_s *js_p)
  154. {
  155.     gossip_debug(GOSSIP_CLIENT_DEBUG, "mgmt_remove_dirent_init called\n");
  156.  
  157.     assert(js_p->error_code == 0);
  158.     return SM_ACTION_COMPLETE;
  159. }
  160.  
  161. static PINT_sm_action mgmt_remove_dirent_setup_msgpair(
  162.     struct PINT_smcb *smcb, job_status_s *js_p)
  163. {
  164.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  165.     int ret = -PVFS_EINVAL;
  166.     PINT_sm_msgpair_state *msg_p = NULL;
  167.  
  168.     js_p->error_code = 0;
  169.  
  170.     PINT_msgpair_init(&sm_p->msgarray_op);
  171.     msg_p = &sm_p->msgarray_op.msgpair;
  172.  
  173.     PINT_SERVREQ_MGMT_REMOVE_DIRENT_FILL(
  174.         msg_p->req,
  175.         *sm_p->cred_p,
  176.         sm_p->parent_ref.fs_id,
  177.         sm_p->parent_ref.handle,
  178.         sm_p->u.mgmt_remove_dirent.entry,
  179.         sm_p->hints);
  180.  
  181.     gossip_debug(GOSSIP_REMOVE_DEBUG, "- doing MGMT_REMOVE_DIRENT %s "
  182.                  "under %llu,%d\n", sm_p->u.mgmt_remove_dirent.entry,
  183.                  llu(sm_p->parent_ref.handle), sm_p->parent_ref.fs_id);
  184.  
  185.     msg_p->fs_id = sm_p->parent_ref.fs_id;
  186.     msg_p->handle = sm_p->parent_ref.handle;
  187.     msg_p->retry_flag = PVFS_MSGPAIR_NO_RETRY;
  188.     msg_p->comp_fn = mgmt_remove_dirent_comp_fn;
  189.  
  190.     ret = PINT_cached_config_map_to_server(
  191.         &msg_p->svr_addr, msg_p->handle, msg_p->fs_id);
  192.  
  193.     if (ret)
  194.     {
  195.         gossip_err("Failed to map server address\n");
  196.         js_p->error_code = ret;
  197.     }
  198.  
  199.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  200.     return SM_ACTION_COMPLETE;
  201. }
  202.  
  203. static int mgmt_remove_dirent_comp_fn(
  204.     void *v_p, struct PVFS_server_resp *resp_p, int index)
  205. {
  206.     PINT_smcb *smcb = v_p;
  207.     PINT_client_sm *sm_p __attribute__((unused)) =
  208.         PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  209.  
  210.     assert(resp_p->op == PVFS_SERV_MGMT_REMOVE_DIRENT);
  211.  
  212.     if (resp_p->status == 0)
  213.     {
  214.         gossip_debug(
  215.             GOSSIP_CLIENT_DEBUG,
  216.             "  mgmt_remove_dirent_comp_fn: dirent %s under %llu,%d "
  217.             "removed\n", sm_p->u.mgmt_remove_dirent.entry,
  218.             llu(sm_p->parent_ref.handle), sm_p->parent_ref.fs_id);
  219.     }
  220.     return resp_p->status;
  221. }
  222.  
  223. static PINT_sm_action mgmt_remove_dirent_cleanup(
  224.     struct PINT_smcb *smcb, job_status_s *js_p)
  225. {
  226.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  227.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  228.                  "mgmt_remove_dirent_cleanup called\n");
  229.  
  230.     sm_p->error_code = js_p->error_code;
  231.  
  232.     PINT_SET_OP_COMPLETE;
  233.     return SM_ACTION_TERMINATE;
  234. }
  235.  
  236. /*
  237.  * Local variables:
  238.  *  mode: c
  239.  *  c-indent-level: 4
  240.  *  c-basic-offset: 4
  241.  * End:
  242.  *
  243.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  244.  */
  245.