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 / del-eattr.sm < prev    next >
Text File  |  2011-02-25  |  6KB  |  227 lines

  1. /* 
  2.  * (C) 2001 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.  
  10. #include "server-config.h"
  11. #include "pvfs2-server.h"
  12. #include "pvfs2-attr.h"
  13. #include "pvfs2-internal.h"
  14. #include "pvfs2-util.h"
  15. #include "pint-util.h"
  16.  
  17. %%
  18.  
  19. machine pvfs2_del_eattr_sm
  20. {
  21.     state prelude
  22.     {
  23.         jump pvfs2_prelude_sm;
  24.         success => verify_eattribs;
  25.         default => final_response;
  26.     }
  27.  
  28.     state verify_eattribs
  29.     {
  30.         run deleattr_verify_eattribs;
  31.         success => delobj_eattrib;
  32.         default => final_response;
  33.     }
  34.  
  35.     state delobj_eattrib
  36.     {
  37.         run deleattr_delobj_eattribs;
  38.         default => final_response;
  39.     }
  40.  
  41.     state final_response
  42.     {
  43.         jump pvfs2_final_response_sm;
  44.         default => cleanup;
  45.     }
  46.  
  47.     state cleanup
  48.     {
  49.         run deleattr_cleanup;
  50.         default => terminate;
  51.     }
  52. }
  53.  
  54. %%
  55.  
  56. /*
  57.  * This routine really just does debugging - can print out info about
  58.  * the target of the operation.  There are few things to verify here
  59.  * be we'll try to verify what we can.  We can also disallow setting
  60.  * extended attributes on certain object types if we want.  We might
  61.  * want to prevent access to standard metadata keys.
  62.  */
  63. static PINT_sm_action deleattr_verify_eattribs(
  64.         struct PINT_smcb *smcb, job_status_s *js_p)
  65. {
  66.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  67.     PVFS_object_attr *a_p = NULL;
  68.  
  69.     a_p = &s_op->attr;
  70.  
  71.     js_p->error_code = 0;
  72.  
  73.     gossip_debug(GOSSIP_DELEATTR_DEBUG,
  74.                  "  ext attr delete from handle %llu refers to a %s\n\t"
  75.                  "[owner = %d, group = %d, perms = %o, type = %d]\n",
  76.                  llu(s_op->req->u.deleattr.handle),
  77.                  PINT_util_get_object_type(a_p->objtype),
  78.                  a_p->owner, a_p->group, a_p->perms, a_p->objtype);
  79.  
  80.  
  81.     if( s_op->req->u.deleattr.key.buffer_sz > PVFS_MAX_XATTR_NAMELEN )
  82.     {
  83.         js_p->error_code = -PVFS_EINVAL;
  84.         return SM_ACTION_COMPLETE;
  85.     }
  86.  
  87.     switch (a_p->objtype)
  88.     {
  89.     case PVFS_TYPE_METAFILE :
  90.         if (!strncmp(s_op->req->u.deleattr.key.buffer,
  91.                     Trove_Common_Keys[METAFILE_HANDLES_KEY].key,
  92.                     s_op->req->u.deleattr.key.buffer_sz) ||
  93.             !strncmp(s_op->req->u.deleattr.key.buffer,
  94.                     Trove_Common_Keys[METAFILE_DIST_KEY].key,
  95.                     s_op->req->u.deleattr.key.buffer_sz))
  96.         {
  97.             /* can't set these keys with this request */
  98.             js_p->error_code = -PVFS_EINVAL;
  99.             return -PVFS_EINVAL;
  100.         }
  101.     case PVFS_TYPE_SYMLINK :
  102.         if (!strncmp(s_op->req->u.deleattr.key.buffer,
  103.                     Trove_Common_Keys[SYMLINK_TARGET_KEY].key,
  104.                     s_op->req->u.deleattr.key.buffer_sz))
  105.         {
  106.             /* can't set these keys with this request */
  107.             js_p->error_code = -PVFS_EINVAL;
  108.             return -PVFS_EINVAL;
  109.         }
  110.     case PVFS_TYPE_DIRECTORY :
  111.         if (!strncmp(s_op->req->u.deleattr.key.buffer,
  112.                     Trove_Common_Keys[DIR_ENT_KEY].key,
  113.                     s_op->req->u.deleattr.key.buffer_sz))
  114.         {
  115.             /* can't set these keys with this request */
  116.             js_p->error_code = -PVFS_EINVAL;
  117.             return -PVFS_EINVAL;
  118.         }
  119.     default :
  120.         /* no holds barred for other types */
  121.         ;
  122.     }
  123.  
  124.     /* no one is allowed to set standard attribs with this op */
  125.     if (!strncmp((void *)s_op->req->u.deleattr.key.buffer,
  126.                 (void *)&s_op->req->u.deleattr.handle,
  127.                 sizeof(s_op->req->u.deleattr.handle)))
  128.     {
  129.         /* can't set these keys with this request */
  130.         js_p->error_code = -PVFS_EINVAL;
  131.         return -PVFS_EINVAL;
  132.     }
  133.  
  134.     return SM_ACTION_COMPLETE;
  135. }
  136.  
  137. /*
  138.  * This is where the actual extended attrib gets written.
  139.  * Not much to this, its pretty straight-forward.
  140.  */
  141. static PINT_sm_action deleattr_delobj_eattribs(
  142.         struct PINT_smcb *smcb, job_status_s *js_p)
  143. {
  144.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  145.     int ret = 0;
  146.     job_id_t j_id;
  147.  
  148.     /* set up key and value structure for keyval write */
  149.     s_op->key.buffer = s_op->req->u.deleattr.key.buffer;
  150.     s_op->key.buffer_sz = s_op->req->u.deleattr.key.buffer_sz;
  151.  
  152.     gossip_debug(
  153.         GOSSIP_DELEATTR_DEBUG,
  154.         "  writing %s [%llu,%d,len %d]\n",
  155.         (char *)s_op->key.buffer,
  156.         llu(s_op->req->u.deleattr.handle),
  157.         s_op->req->u.deleattr.fs_id,
  158.         s_op->val.buffer_sz);
  159.  
  160.     gossip_debug(
  161.         GOSSIP_DELEATTR_DEBUG,
  162.         "keybuf %p keylen %d\n",
  163.         s_op->req->u.deleattr.key.buffer, s_op->req->u.deleattr.key.buffer_sz);
  164.  
  165.     ret = job_trove_keyval_remove(
  166.         s_op->req->u.deleattr.fs_id,
  167.         s_op->req->u.deleattr.handle,
  168.         &(s_op->key),
  169.         NULL,
  170.         TROVE_SYNC ,
  171.         NULL,
  172.         smcb,
  173.         0,
  174.         js_p,
  175.         &j_id,
  176.         server_job_context, s_op->req->hints);
  177.  
  178.     return ret;
  179. }
  180.  
  181. /*
  182.  * Function: delattr_cleanup
  183.  *
  184.  * Params:   server_op *b, 
  185.  *           job_status_s *js_p
  186.  *
  187.  * Returns:  int
  188.  *
  189.  * Synopsis: free memory and return
  190.  *           
  191.  */
  192. static PINT_sm_action deleattr_cleanup(
  193.         struct PINT_smcb *smcb, job_status_s *js_p)
  194. {
  195.     struct PINT_server_op *s_op __attribute__((unused)) =
  196.         PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  197.     gossip_debug(
  198.         GOSSIP_DELEATTR_DEBUG,
  199.         "keybuf %p keylen %d\n",
  200.         s_op->req->u.deleattr.key.buffer, s_op->req->u.deleattr.key.buffer_sz);
  201.  
  202.     return(server_state_machine_complete(smcb));
  203. }
  204.  
  205. PINT_GET_OBJECT_REF_DEFINE(deleattr);
  206.  
  207. struct PINT_server_req_params pvfs2_del_eattr_params =
  208. {
  209.     .string_name = "del_eattr",
  210.     .perm = PINT_SERVER_CHECK_ATTR,
  211.     .access_type = PINT_server_req_modify,
  212.     .sched_policy = PINT_SERVER_REQ_SCHEDULE,
  213.     .get_object_ref = PINT_get_object_ref_deleattr,
  214.     .state_machine = &pvfs2_del_eattr_sm
  215. };
  216.  
  217. /*
  218.  * Local variables:
  219.  *  mode: c
  220.  *  c-indent-level: 4
  221.  *  c-basic-offset: 4
  222.  * End:
  223.  *
  224.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  225.  */
  226.  
  227.