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-create-dirent.sm < prev    next >
Text File  |  2008-11-19  |  7KB  |  252 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 creating directory entries
  11.  *  that point to specific existing objects.  These are used primarily
  12.  *  for file system repair purposes.
  13.  */
  14.  
  15. #include <string.h>
  16. #include <assert.h>
  17.  
  18. #include "client-state-machine.h"
  19. #include "pvfs2-debug.h"
  20. #include "job.h"
  21. #include "gossip.h"
  22. #include "str-utils.h"
  23. #include "pint-cached-config.h"
  24. #include "PINT-reqproto-encode.h"
  25. #include "pvfs2-internal.h"
  26.  
  27. extern job_context_id pint_client_sm_context;
  28.  
  29. static int mgmt_create_dirent_comp_fn(
  30.     void *v_p, struct PVFS_server_resp *resp_p, int i);
  31.  
  32. %%
  33.  
  34. machine pvfs2_client_mgmt_create_dirent_sm
  35. {
  36.     state init
  37.     {
  38.         run mgmt_create_dirent_init;
  39.         default => create_dirent_setup_msgpair;
  40.     }
  41.  
  42.     state create_dirent_setup_msgpair
  43.     {
  44.         run mgmt_create_dirent_setup_msgpair;
  45.         success => create_dirent_xfer_msgpair;
  46.         default => cleanup;
  47.     }
  48.  
  49.     state create_dirent_xfer_msgpair
  50.     {
  51.         jump pvfs2_msgpairarray_sm;
  52.         default => cleanup;
  53.     }
  54.  
  55.     state cleanup
  56.     {
  57.         run mgmt_create_dirent_cleanup;
  58.         default => terminate;
  59.     }
  60. }
  61.  
  62. %%
  63.  
  64. /** Initiate creation of a directory entry pointing to a specific object.
  65.  */
  66. PVFS_error PVFS_imgmt_create_dirent(
  67.     PVFS_object_ref parent_ref,
  68.     char *entry,
  69.     PVFS_handle entry_handle,
  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_create_dirent entered\n");
  81.  
  82.     if ((parent_ref.handle == PVFS_HANDLE_NULL) ||
  83.         (parent_ref.fs_id == PVFS_FS_ID_NULL) ||
  84.         (entry_handle == PVFS_HANDLE_NULL) || !entry)
  85.     {
  86.         gossip_err("invalid (NULL) required argument\n");
  87.         return ret;
  88.     }
  89.  
  90.     PINT_smcb_alloc(&smcb, PVFS_MGMT_CREATE_DIRENT,
  91.              sizeof(struct PINT_client_sm),
  92.              client_op_state_get_machine,
  93.              client_state_machine_terminate,
  94.              pint_client_sm_context);
  95.     if (smcb == NULL)
  96.     {
  97.         return -PVFS_ENOMEM;
  98.     }
  99.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  100.  
  101.     PINT_init_msgarray_params(sm_p, parent_ref.fs_id);
  102.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  103.     sm_p->parent_ref = parent_ref;
  104.     sm_p->u.mgmt_create_dirent.entry = entry;
  105.     sm_p->u.mgmt_create_dirent.entry_handle = entry_handle;
  106.     PVFS_hint_copy(hints, &sm_p->hints);
  107.  
  108.     gossip_debug(
  109.         GOSSIP_CLIENT_DEBUG, "Trying to create dirent %s under %llu,%d\n",
  110.         sm_p->u.mgmt_create_dirent.entry, llu(parent_ref.handle),
  111.         parent_ref.fs_id);
  112.  
  113.     return PINT_client_state_machine_post(
  114.         smcb,  op_id, user_ptr);
  115. }
  116.  
  117. /** Create a directory entry pointing to a specific object.
  118.  */
  119. PVFS_error PVFS_mgmt_create_dirent(
  120.     PVFS_object_ref parent_ref,
  121.     char *entry,
  122.     PVFS_handle entry_handle,
  123.     PVFS_credentials *credentials,
  124.     PVFS_hint hints)
  125. {
  126.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  127.     PVFS_mgmt_op_id op_id;
  128.  
  129.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  130.                  "PVFS_mgmt_create_dirent entered\n");
  131.  
  132.     ret = PVFS_imgmt_create_dirent(
  133.         parent_ref, entry, entry_handle, credentials, &op_id, hints, NULL);
  134.     if (ret)
  135.     {
  136.         PVFS_perror_gossip("PVFS_imgmt_create_dirent call", ret);
  137.         error = ret;
  138.     }
  139.     else
  140.     {
  141.         ret = PVFS_mgmt_wait(op_id, "create_dirent", &error);
  142.         if (ret)
  143.         {
  144.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  145.             error = ret;
  146.         }
  147.     }
  148.  
  149.     PINT_mgmt_release(op_id);
  150.     return error;
  151. }
  152.  
  153. /****************************************************************/
  154.  
  155. static int mgmt_create_dirent_init(
  156.     struct PINT_smcb *smcb, job_status_s *js_p)
  157. {
  158.     gossip_debug(GOSSIP_CLIENT_DEBUG, "mgmt_create_dirent_init called\n");
  159.  
  160.     assert(js_p->error_code == 0);
  161.     return SM_ACTION_COMPLETE;
  162. }
  163.  
  164. static int mgmt_create_dirent_setup_msgpair(
  165.     struct PINT_smcb *smcb, job_status_s *js_p)
  166. {
  167.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  168.     int ret = -PVFS_EINVAL;
  169.     PINT_sm_msgpair_state *msg_p = NULL;
  170.  
  171.     js_p->error_code = 0;
  172.  
  173.     PINT_msgpair_init(&sm_p->msgarray_op);
  174.     msg_p = &sm_p->msgarray_op.msgpair;
  175.  
  176.     gossip_debug(
  177.         GOSSIP_CLIENT_DEBUG, " creating dirent entry %s with "
  178.         "handle %llu under parent %llu,%d\n",
  179.         sm_p->u.mgmt_create_dirent.entry,
  180.         llu(sm_p->u.mgmt_create_dirent.entry_handle),
  181.         llu(sm_p->parent_ref.handle), sm_p->parent_ref.fs_id);
  182.  
  183.     PINT_SERVREQ_CRDIRENT_FILL(
  184.         msg_p->req,
  185.         *sm_p->cred_p,
  186.         sm_p->u.mgmt_create_dirent.entry,
  187.         sm_p->u.mgmt_create_dirent.entry_handle,
  188.         sm_p->parent_ref.handle,
  189.         sm_p->parent_ref.fs_id,
  190.         sm_p->hints);
  191.  
  192.     msg_p->fs_id = sm_p->parent_ref.fs_id;
  193.     msg_p->handle = sm_p->parent_ref.handle;
  194.     msg_p->retry_flag = PVFS_MSGPAIR_NO_RETRY;
  195.     msg_p->comp_fn = mgmt_create_dirent_comp_fn;
  196.  
  197.     ret = PINT_cached_config_map_to_server(
  198.         &msg_p->svr_addr, msg_p->handle, msg_p->fs_id);
  199.  
  200.     if (ret)
  201.     {
  202.         gossip_err("Failed to map server address\n");
  203.     js_p->error_code = ret;
  204.     }
  205.  
  206.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  207.     return SM_ACTION_COMPLETE;
  208. }
  209.  
  210. static int mgmt_create_dirent_comp_fn(
  211.     void *v_p, struct PVFS_server_resp *resp_p, int index)
  212. {
  213.     PINT_smcb *smcb = v_p;
  214.     PINT_client_sm *sm_p __attribute__((unused)) =
  215.         PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  216.  
  217.     assert(resp_p->op == PVFS_SERV_CRDIRENT);
  218.  
  219.     if (resp_p->status == 0)
  220.     {
  221.         gossip_debug(
  222.             GOSSIP_CLIENT_DEBUG,
  223.             "  mgmt_create_dirent_comp_fn: dirent %s under %llu,%d "
  224.             "created\n", sm_p->u.mgmt_create_dirent.entry,
  225.             llu(sm_p->parent_ref.handle), sm_p->parent_ref.fs_id);
  226.     }
  227.     return resp_p->status;
  228. }
  229.  
  230. static PINT_sm_action mgmt_create_dirent_cleanup(
  231.     struct PINT_smcb *smcb, job_status_s *js_p)
  232. {
  233.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  234.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  235.                  "mgmt_create_dirent_cleanup called\n");
  236.  
  237.     sm_p->error_code = js_p->error_code;
  238.  
  239.     PINT_SET_OP_COMPLETE;
  240.     return SM_ACTION_TERMINATE;
  241. }
  242.  
  243. /*
  244.  * Local variables:
  245.  *  mode: c
  246.  *  c-indent-level: 4
  247.  *  c-basic-offset: 4
  248.  * End:
  249.  *
  250.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  251.  */
  252.