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 / server / get-eattr.sm < prev    next >
Text File  |  2011-02-25  |  7KB  |  272 lines

  1. /* 
  2.  * (C) 2001 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. /* pvfs2_get_eattr_sm
  8.  *
  9.  * This state machine handles incoming server geteattr operations.  These
  10.  * are the operations sent by PVFS_sys_geteattr() among others.
  11.  *
  12.  * The pvfs2_prelude_sm is responsible for reading the actual metadata
  13.  * to begin with, because it does this as part of the permission checking
  14.  * process.
  15.  */
  16.  
  17. #include <string.h>
  18. #include <assert.h>
  19.  
  20. #include "server-config.h"
  21. #include "pvfs2-server.h"
  22. #include "pvfs2-attr.h"
  23. #include "pvfs2-types.h"
  24. #include "pvfs2-util.h"
  25. #include "pint-util.h"
  26. #include "pint-eattr.h"
  27.  
  28. %%
  29.  
  30. machine pvfs2_get_eattr_sm
  31. {
  32.     state prelude
  33.     {
  34.         jump pvfs2_prelude_sm;
  35.         success => setup_resp;
  36.         default => final_response;
  37.     }
  38.  
  39.     state setup_resp
  40.     {
  41.         run geteattr_setup_resp;
  42.         success => read_eattrib;
  43.         default => final_response;
  44.     }
  45.  
  46.     state read_eattrib
  47.     {
  48.         run geteattr_read_eattrib;
  49.         default => check_resp;
  50.     }
  51.  
  52.     state check_resp
  53.     {
  54.         run geteattr_check_resp;
  55.         default => final_response;
  56.     }
  57.  
  58.     state final_response
  59.     {
  60.         jump pvfs2_final_response_sm;
  61.         default => cleanup;
  62.     }
  63.  
  64.     state cleanup
  65.     {
  66.         run geteattr_cleanup;
  67.         default => terminate;
  68.     }
  69. }
  70.  
  71. %%
  72.  
  73. /*
  74.  * geteattr_setup_resp()
  75.  * Set up the response - allocate needed resources
  76.  */
  77. static PINT_sm_action geteattr_setup_resp(
  78.         struct PINT_smcb *smcb, job_status_s *js_p)
  79. {
  80.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  81.     int i, tsz;
  82.  
  83.     gossip_debug(GOSSIP_GETEATTR_DEBUG,"geteattr requesting %d keys\n",
  84.             s_op->req->u.geteattr.nkey);
  85.  
  86.     js_p->error_code = 0;
  87.  
  88.     /* ensure not too many keys were requested */
  89.     if( s_op->req->u.geteattr.nkey > PVFS_MAX_XATTR_LISTLEN )
  90.     {
  91.         js_p->error_code = -PVFS_EINVAL;
  92.         return SM_ACTION_COMPLETE;
  93.     }
  94.  
  95.     /* iterate through the keys and see if they fall into valid name spaces */
  96.     for(i=0; i<s_op->req->u.geteattr.nkey; i++)
  97.     {
  98.         gossip_debug(GOSSIP_GETEATTR_DEBUG, "geteattr key %d : %s\n", i, 
  99.                 (char *) s_op->req->u.geteattr.key[i].buffer);
  100.  
  101.         /* ensure no buffer_sz is too larger */
  102.         if( s_op->req->u.geteattr.key[i].buffer_sz > PVFS_MAX_XATTR_NAMELEN )
  103.         {
  104.             js_p->error_code = -PVFS_EINVAL;
  105.             return SM_ACTION_COMPLETE;
  106.         }
  107.  
  108.         js_p->error_code = PINT_eattr_check_access(
  109.             &s_op->req->u.geteattr.key[i],
  110.             NULL);
  111.         if(js_p->error_code != 0)
  112.         {
  113.             /* not prefixed: treat this as if the key does not exist */
  114.             js_p->error_code = -PVFS_ENOENT;
  115.             return SM_ACTION_COMPLETE;
  116.         }
  117.     }
  118.  
  119.     s_op->resp.u.geteattr.val =
  120.         malloc(s_op->req->u.geteattr.nkey*sizeof(PVFS_ds_keyval));
  121.     if (!s_op->resp.u.geteattr.val)
  122.     {
  123.         js_p->error_code = -PVFS_ENOMEM;
  124.         return SM_ACTION_COMPLETE;
  125.     }
  126.     s_op->resp.u.geteattr.err =
  127.         malloc(s_op->req->u.geteattr.nkey*sizeof(PVFS_error));
  128.     if (!s_op->resp.u.geteattr.err)
  129.     {
  130.         free(s_op->resp.u.geteattr.val);
  131.         js_p->error_code = -PVFS_ENOMEM;
  132.         return SM_ACTION_COMPLETE;
  133.     }
  134.     s_op->resp.u.geteattr.nkey = s_op->req->u.geteattr.nkey;
  135.     for (i = 0, tsz = 0; i < s_op->req->u.geteattr.nkey; i++)
  136.     {
  137.         s_op->resp.u.geteattr.val[i].buffer = malloc(
  138.             s_op->req->u.geteattr.valsz[i]);
  139.         if (!s_op->resp.u.geteattr.val[i].buffer)
  140.         {
  141.             for(--i; i >= 0; --i)
  142.             {
  143.                 free(s_op->resp.u.geteattr.val[i].buffer);
  144.             }
  145.             s_op->resp.u.geteattr.nkey = 0;
  146.             free (s_op->resp.u.geteattr.val);
  147.             free (s_op->resp.u.geteattr.err);
  148.             js_p->error_code = -PVFS_ENOMEM;
  149.             return SM_ACTION_COMPLETE;
  150.         }
  151.         s_op->resp.u.geteattr.val[i].buffer_sz = s_op->req->u.geteattr.valsz[i];
  152.     }
  153.  
  154.     return SM_ACTION_COMPLETE;
  155. }
  156.  
  157. /*
  158.  * geteattr_read_eattrib()
  159.  * Here is where the eattrib get read.  Not much to this.
  160.  */
  161. static PINT_sm_action geteattr_read_eattrib(
  162.         struct PINT_smcb *smcb, job_status_s *js_p)
  163. {
  164.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  165.     int ret = -PVFS_EINVAL;
  166.     job_id_t i;
  167.  
  168.     js_p->error_code = 0;
  169.  
  170.     ret = job_trove_keyval_read_list(
  171.         s_op->req->u.geteattr.fs_id,
  172.         s_op->req->u.geteattr.handle,
  173.         s_op->req->u.geteattr.key,
  174.         s_op->resp.u.geteattr.val,
  175.         s_op->resp.u.geteattr.err,
  176.         s_op->req->u.geteattr.nkey,
  177.         0,
  178.         NULL,
  179.         smcb,
  180.         0,
  181.         js_p,
  182.         &i,
  183.         server_job_context, s_op->req->hints);
  184.  
  185.     return ret;
  186. }
  187.  
  188. /*
  189.  * geteattr_check_resp()
  190.  * Check the response - handle any errors
  191.  */
  192. static PINT_sm_action geteattr_check_resp(
  193.         struct PINT_smcb *smcb, job_status_s *js_p)
  194. {
  195.     int ret;
  196.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  197.     int k;
  198.     gossip_debug(GOSSIP_GETEATTR_DEBUG,"geteattr returning %d values\n",
  199.             s_op->resp.u.geteattr.nkey);
  200.     /* put the returned read buffer size in buffer_sz */
  201.     gossip_debug(GOSSIP_GETEATTR_DEBUG,"status %d error_code %d nkeys %d\n",
  202.             s_op->resp.status, js_p->error_code, s_op->resp.u.geteattr.nkey);
  203.     /* it is the only thing returned across the wire */
  204.     for (k = 0; k < s_op->resp.u.geteattr.nkey; k++)
  205.     {
  206.         if (js_p->error_code == 0)
  207.         {
  208.             ret = PINT_eattr_encode(
  209.                 &s_op->req->u.geteattr.key[k],
  210.                 &s_op->resp.u.geteattr.val[k]);
  211.             if(ret != 0)
  212.             {
  213.                 gossip_err("%s: failed encoding extended attribute: %s\n",
  214.                            __func__, (char *)s_op->req->u.geteattr.key[k].buffer);
  215.                 s_op->resp.u.geteattr.err[k] = ret;
  216.             }
  217.  
  218.             s_op->resp.u.geteattr.val[k].buffer_sz =
  219.                 s_op->resp.u.geteattr.val[k].read_sz;
  220.             gossip_debug(GOSSIP_GETEATTR_DEBUG, "key %s, read_sz = %d\n",
  221.                 (char *) s_op->req->u.geteattr.key[k].buffer, 
  222.                 s_op->resp.u.geteattr.val[k].buffer_sz);
  223.         }
  224.         /* in case of any errors, we initialize it to 0 */
  225.         else {
  226.             s_op->resp.u.geteattr.val[k].buffer_sz = 0;
  227.         }
  228.     }
  229.     return SM_ACTION_COMPLETE;
  230. }
  231.  
  232. /* geteattr_cleanup()
  233.  * free resources alloc'd by state machine
  234.  */
  235. static PINT_sm_action geteattr_cleanup(
  236.         struct PINT_smcb *smcb, job_status_s *js_p)
  237. {
  238.     int i = 0;
  239.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  240.     for(; i < s_op->resp.u.geteattr.nkey; ++i)
  241.     {
  242.         free(s_op->resp.u.geteattr.val[i].buffer);
  243.     }
  244.     if (s_op->resp.u.geteattr.val)
  245.         free(s_op->resp.u.geteattr.val);
  246.     if (s_op->resp.u.geteattr.err)
  247.         free(s_op->resp.u.geteattr.err);
  248.     return(server_state_machine_complete(smcb));
  249. }
  250.  
  251. PINT_GET_OBJECT_REF_DEFINE(geteattr);
  252.  
  253. struct PINT_server_req_params pvfs2_get_eattr_params =
  254. {
  255.     .string_name = "get_eattr",
  256.     .perm = PINT_SERVER_CHECK_ATTR,
  257.     .sched_policy = PINT_SERVER_REQ_SCHEDULE,
  258.     .get_object_ref = PINT_get_object_ref_geteattr,
  259.     .state_machine = &pvfs2_get_eattr_sm
  260. };
  261.  
  262. /*
  263.  * Local variables:
  264.  *  mode: c
  265.  *  c-indent-level: 4
  266.  *  c-basic-offset: 4
  267.  * End:
  268.  *
  269.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  270.  */
  271.  
  272.