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-set-eattr.sm < prev    next >
Text File  |  2009-06-25  |  7KB  |  267 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 set_eattr_comp_fn(
  23.     void *v_p,
  24.     struct PVFS_server_resp *resp_p,
  25.     int i);
  26.  
  27. %%
  28.  
  29. machine pvfs2_client_set_eattr_sm
  30. {
  31.     state setup_msgpair
  32.     {
  33.         run set_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 set_eattr_cleanup;
  47.         default => terminate;
  48.     }
  49. }
  50.  
  51. %%
  52.  
  53. PVFS_error PVFS_isys_seteattr_list(
  54.         PVFS_object_ref ref,
  55.         const PVFS_credentials *credentials,
  56.         int32_t nkey,
  57.         PVFS_ds_keyval *key_array,
  58.         PVFS_ds_keyval *val_array,
  59.         int32_t flags,
  60.         PVFS_sys_op_id *op_id,
  61.         PVFS_hint hints,
  62.         void *user_ptr)
  63. {
  64.     int ret = -PVFS_EINVAL;
  65.     PINT_smcb *smcb = NULL;
  66.     PINT_client_sm *sm_p = NULL;
  67.  
  68.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  69.                  "PINT_isys_set_eattr entered\n");
  70.  
  71.     if(gossip_debug_enabled(GOSSIP_SETEATTR_DEBUG))
  72.     {
  73.         int i = 0;
  74.         int j; char *valBuf = (char *)val_array[i].buffer;
  75.         gossip_debug(GOSSIP_SETEATTR_DEBUG,"Setting extended attributes:\n");
  76.         for(; i < nkey; ++i)
  77.         {
  78.             gossip_debug(GOSSIP_SETEATTR_DEBUG,"eattr[%d]: key=%s\n"
  79.                                               , i
  80.                                               ,(char *)key_array[i].buffer);
  81.             for (j=0; j<val_array[i].buffer_sz; j++)
  82.                 gossip_debug(GOSSIP_SETEATTR_DEBUG,"          val[%d]=%#x\n"
  83.                                                   ,j
  84.                                                   ,(unsigned int)valBuf[j]);
  85.         }/*end for*/
  86.     } /*end if*/
  87.  
  88.     if ((ref.handle == PVFS_HANDLE_NULL) ||
  89.        (ref.fs_id == PVFS_FS_ID_NULL))
  90.     {
  91.         gossip_err("invalid (NULL) required argument\n");
  92.     return ret;
  93.     }
  94.  
  95.     PINT_smcb_alloc(&smcb, PVFS_SYS_SETEATTR,
  96.              sizeof(struct PINT_client_sm),
  97.              client_op_state_get_machine,
  98.              client_state_machine_terminate,
  99.              pint_client_sm_context);
  100.     if (smcb == NULL)
  101.     {
  102.         return -PVFS_ENOMEM;
  103.     }
  104.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  105.  
  106.     PINT_init_msgarray_params(sm_p, ref.fs_id);
  107.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  108.     sm_p->u.seteattr.nkey = nkey;
  109.     sm_p->u.seteattr.key_array = key_array;
  110.     sm_p->u.seteattr.val_array = val_array;
  111.     sm_p->u.seteattr.flags = flags;
  112.     sm_p->error_code = 0;
  113.     sm_p->object_ref = ref;
  114.     PVFS_hint_copy(hints, &sm_p->hints);
  115.  
  116.     return PINT_client_state_machine_post(
  117.             smcb,  op_id, user_ptr);
  118. }
  119.  
  120. PVFS_error PVFS_sys_seteattr_list(
  121.         PVFS_object_ref ref,
  122.         const PVFS_credentials *credentials,
  123.         int32_t nkey,
  124.         PVFS_ds_keyval *key_array,
  125.         PVFS_ds_keyval *val_array,
  126.         int32_t flags,
  127.         PVFS_hint hints)
  128. {
  129.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  130.     PVFS_sys_op_id op_id;
  131.  
  132.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_sys_seteattr entered\n");
  133.  
  134.     ret = PVFS_isys_seteattr_list(ref, credentials,
  135.             nkey, key_array, val_array, flags, &op_id, hints, NULL);
  136.  
  137.     if (ret)
  138.     {
  139.         PVFS_perror_gossip("PVFS_isys_seteattr call", ret);
  140.         error = ret;
  141.     }
  142.     else
  143.     {
  144.         ret = PVFS_sys_wait(op_id, "seteattr", &error);
  145.         if (ret)
  146.         {
  147.              PVFS_perror_gossip("PVFS_sys_wait call", ret);
  148.              error = ret;
  149.         }
  150.     }
  151.  
  152.     PINT_sys_release(op_id);
  153.     return error;
  154. }
  155.  
  156. PVFS_error PVFS_sys_seteattr(
  157.         PVFS_object_ref ref,
  158.         const PVFS_credentials *credentials,
  159.         PVFS_ds_keyval *key_p,
  160.         PVFS_ds_keyval *val_p,
  161.         int32_t flags,
  162.         PVFS_hint hints)
  163. {
  164.     return PVFS_sys_seteattr_list(ref, credentials, 1, key_p, val_p, flags, hints);
  165. }
  166.  
  167.  
  168. static PINT_sm_action set_eattr_setup_msgpair(
  169.         struct PINT_smcb *smcb, job_status_s *js_p)
  170. {
  171.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  172.     int ret = -PVFS_EINVAL;
  173.     PINT_sm_msgpair_state *msg_p;
  174.  
  175.     PINT_msgpair_init(&sm_p->msgarray_op);
  176.     msg_p = &sm_p->msgarray_op.msgpair;
  177.  
  178.     PINT_SERVREQ_SETEATTR_FILL(
  179.             msg_p->req,
  180.             (*sm_p->cred_p),
  181.             sm_p->object_ref.fs_id,
  182.             sm_p->object_ref.handle,
  183.             sm_p->u.seteattr.flags,
  184.             sm_p->u.seteattr.nkey,
  185.             sm_p->u.seteattr.key_array,
  186.             sm_p->u.seteattr.val_array,
  187.             sm_p->hints
  188.             );
  189.  
  190.     msg_p->fs_id = sm_p->object_ref.fs_id;
  191.     msg_p->handle = sm_p->object_ref.handle;
  192.     msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  193.     msg_p->comp_fn = set_eattr_comp_fn;
  194.  
  195.     ret = PINT_cached_config_map_to_server(
  196.             &msg_p->svr_addr, msg_p->handle, msg_p->fs_id);
  197.  
  198.     if (ret)
  199.     {
  200.         gossip_err("Failed to map meta server address\n");
  201.         js_p->error_code = 0;
  202.     }
  203.  
  204.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  205.     return SM_ACTION_COMPLETE;
  206. }
  207.  
  208. static PINT_sm_action set_eattr_cleanup(
  209.         struct PINT_smcb *smcb, job_status_s *js_p)
  210. {
  211.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  212.     sm_p->error_code  = js_p->error_code;
  213.  
  214.     PINT_SET_OP_COMPLETE;
  215.     return SM_ACTION_TERMINATE;
  216. }
  217.  
  218. static int set_eattr_comp_fn(
  219.     void *v_p,
  220.     struct PVFS_server_resp *resp_p,
  221.     int i)
  222. {
  223.     int j = 0;
  224.     int ret = 0;
  225.     PINT_smcb *smcb = v_p;
  226.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  227.     PINT_sm_msgpair_state *msg_p;
  228.  
  229.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  230.         "get_eattr completion fn: set_eattr_comp_fn\n");
  231.  
  232.     /* only posted one msgpair */
  233.     assert(i==0);
  234.  
  235.     /* no return value from set eattrib so just check status */
  236.  
  237.     if (sm_p->msgarray_op.msgarray[i].op_status != 0)
  238.     {
  239.         ret = sm_p->msgarray_op.msgarray[i].op_status;
  240.     }
  241.  
  242.     /* if this is the last response, check all of the status values
  243.      * and return error code if any requests failed
  244.      */
  245.     if (i == (sm_p->msgarray_op.count -1))
  246.     {
  247.         foreach_msgpair(&sm_p->msgarray_op, msg_p, j)
  248.         {
  249.             if (msg_p->op_status != 0)
  250.             {
  251.                 return(msg_p->op_status);
  252.             }
  253.         }
  254.     }
  255.     return ret;
  256. }
  257.  
  258. /*
  259.  * Local variables:
  260.  *  mode: c
  261.  *  c-indent-level: 4
  262.  *  c-basic-offset: 4
  263.  * End:
  264.  *
  265.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  266.  */
  267.