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 / sys-del-eattr.sm < prev    next >
Text File  |  2008-11-19  |  5KB  |  232 lines

  1. /* 
  2.  * (C) 2003 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. #include <unistd.h>
  10.  
  11. #include "client-state-machine.h"
  12. #include "pvfs2-debug.h"
  13. #include "pvfs2-util.h"
  14. #include "job.h"
  15. #include "gossip.h"
  16. #include "str-utils.h"
  17. #include "pint-cached-config.h"
  18. #include "PINT-reqproto-encode.h"
  19.  
  20. extern job_context_id pint_client_sm_context;
  21.  
  22. static int del_eattr_comp_fn(
  23.     void *v_p,
  24.     struct PVFS_server_resp *resp_p,
  25.     int i);
  26.  
  27. %%
  28.  
  29. machine pvfs2_client_del_eattr_sm
  30. {
  31.     state setup_msgpair
  32.     {
  33.         run del_eattr_setup_msgpair;
  34.         success => xfer_msgpair;
  35.         default => cleanup;
  36.     }
  37.  
  38.     state xfer_msgpair
  39.     {
  40.         jump pvfs2_msgpairarray_sm;
  41.         default => cleanup;
  42.     }
  43.  
  44.     state cleanup
  45.     {
  46.         run del_eattr_cleanup;
  47.         default => terminate;
  48.     }
  49. }
  50.  
  51. %%
  52.  
  53. PVFS_error PVFS_isys_deleattr(
  54.         PVFS_object_ref ref,
  55.         const PVFS_credentials *credentials,
  56.         PVFS_ds_keyval *key_p,
  57.         PVFS_sys_op_id *op_id,
  58.         PVFS_hint hints,
  59.         void *user_ptr)
  60. {
  61.     int ret = -PVFS_EINVAL;
  62.     PINT_smcb *smcb = NULL;
  63.     PINT_client_sm *sm_p = NULL;
  64.  
  65.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PINT_isys_del_eattr entered\n");
  66.  
  67.     if ((ref.handle == PVFS_HANDLE_NULL) ||
  68.        (ref.fs_id == PVFS_FS_ID_NULL))
  69.     {
  70.         gossip_err("invalid (NULL) required argument\n");
  71.     return ret;
  72.     }
  73.  
  74.     PINT_smcb_alloc(&smcb, PVFS_SYS_DELEATTR,
  75.              sizeof(struct PINT_client_sm),
  76.              client_op_state_get_machine,
  77.              client_state_machine_terminate,
  78.              pint_client_sm_context);
  79.     if (smcb == NULL)
  80.     {
  81.         return -PVFS_ENOMEM;
  82.     }
  83.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  84.  
  85.     PINT_init_msgarray_params(sm_p, ref.fs_id);
  86.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  87.     sm_p->u.deleattr.key_p = key_p;
  88.     sm_p->error_code = 0;
  89.     sm_p->object_ref = ref;
  90.     PVFS_hint_copy(hints, &sm_p->hints);
  91.     
  92.     return PINT_client_state_machine_post(
  93.             smcb,  op_id, user_ptr);
  94. }
  95.  
  96. PVFS_error PVFS_sys_deleattr(
  97.         PVFS_object_ref ref,
  98.         const PVFS_credentials *credentials,
  99.         PVFS_ds_keyval *key_p, 
  100.         PVFS_hint hints)
  101. {
  102.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  103.     PVFS_sys_op_id op_id;
  104.  
  105.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_sys_deleattr entered\n");
  106.  
  107.     ret = PVFS_isys_deleattr(ref, credentials,
  108.             key_p, &op_id, hints, NULL);
  109.  
  110.     if (ret)
  111.     {
  112.         PVFS_perror_gossip("PVFS_isys_deleattr call", ret);
  113.         error = ret;
  114.     }
  115.     else
  116.     {
  117.         ret = PVFS_sys_wait(op_id, "deleattr", &error);
  118.         if (ret)
  119.         {
  120.              PVFS_perror_gossip("PVFS_sys_wait call", ret);
  121.              error = ret;
  122.         }
  123.     }
  124.  
  125.     PINT_sys_release(op_id);
  126.     return error;
  127. }
  128.  
  129. static PINT_sm_action del_eattr_setup_msgpair(
  130.         struct PINT_smcb *smcb, job_status_s *js_p)
  131. {
  132.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  133.     int ret = -PVFS_EINVAL;
  134.     PINT_sm_msgpair_state *msg_p;
  135.  
  136.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  137.         "del_eattr state: del_eattr_setup_msgpair\n");
  138.  
  139.     PINT_msgpair_init(&sm_p->msgarray_op);
  140.     msg_p = &sm_p->msgarray_op.msgpair;
  141.  
  142.     PINT_SERVREQ_DELEATTR_FILL(
  143.             msg_p->req,
  144.             (*sm_p->cred_p),
  145.             sm_p->object_ref.fs_id,
  146.             sm_p->object_ref.handle,
  147.             (*sm_p->u.deleattr.key_p),
  148.             sm_p->hints
  149.             );
  150.  
  151.     msg_p->fs_id = sm_p->object_ref.fs_id;
  152.     msg_p->handle = sm_p->object_ref.handle;
  153.     msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  154.     msg_p->comp_fn = del_eattr_comp_fn;
  155.  
  156.     ret = PINT_cached_config_map_to_server(
  157.             &msg_p->svr_addr,
  158.             msg_p->handle,
  159.             msg_p->fs_id);
  160.  
  161.     if (ret)
  162.     {
  163.         gossip_err("Failed to map meta server address\n");
  164.         js_p->error_code = 0;
  165.     }
  166.  
  167.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  168.     return SM_ACTION_COMPLETE;
  169. }
  170.  
  171. static PINT_sm_action del_eattr_cleanup(
  172.         struct PINT_smcb *smcb, job_status_s *js_p)
  173. {
  174.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  175.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  176.         "del_eattr state: del_eattr_cleanup\n");
  177.     sm_p->error_code  = js_p->error_code;
  178.  
  179.     PINT_SET_OP_COMPLETE;
  180.     return SM_ACTION_TERMINATE;
  181. }
  182.  
  183. static int del_eattr_comp_fn(
  184.     void *v_p,
  185.     struct PVFS_server_resp *resp_p,
  186.     int i)
  187. {
  188.     int j = 0;
  189.     int ret = 0;
  190.     PINT_smcb *smcb = v_p;
  191.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  192.     PINT_sm_msgpair_state *msg_p;
  193.  
  194.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  195.         "del_eattr completion fn: del_eattr_comp_fn\n");
  196.  
  197.     /* only posted one msgpair */
  198.     assert(i==0);
  199.  
  200.     /* no return value from del eattrib so just check status */
  201.  
  202.     if (sm_p->msgarray_op.msgarray[i].op_status != 0)
  203.     {
  204.         ret = sm_p->msgarray_op.msgarray[i].op_status;
  205.     }
  206.  
  207.     /* if this is the last response, check all of the status values
  208.      * and return error code if any requests failed
  209.      */
  210.     if (i == (sm_p->msgarray_op.count -1))
  211.     {
  212.         foreach_msgpair(&sm_p->msgarray_op, msg_p, j)
  213.         {
  214.             if (msg_p->op_status != 0)
  215.             {
  216.                 return(msg_p->op_status);
  217.             }
  218.         }
  219.     }
  220.     return ret;
  221. }
  222.  
  223. /*
  224.  * Local variables:
  225.  *  mode: c
  226.  *  c-indent-level: 4
  227.  *  c-basic-offset: 4
  228.  * End:
  229.  *
  230.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  231.  */
  232.