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-setattr.sm < prev    next >
Text File  |  2010-12-19  |  8KB  |  294 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 sysint
  9.  *
  10.  *  PVFS2 system interface routines for setting the attributes of an object
  11.  *  (file or directory).
  12.  */
  13.  
  14. #include <string.h>
  15. #include <assert.h>
  16.  
  17. #include "client-state-machine.h"
  18. #include "pvfs2-debug.h"
  19. #include "job.h"
  20. #include "gossip.h"
  21. #include "str-utils.h"
  22. #include "pint-cached-config.h"
  23. #include "PINT-reqproto-encode.h"
  24. #include "pint-util.h"
  25. #include "pvfs2-internal.h"
  26.  
  27. extern job_context_id pint_client_sm_context;
  28.  
  29. static int setattr_msg_comp_fn(
  30.     void *v_p, struct PVFS_server_resp *resp_p, int index);
  31.  
  32. %%
  33.  
  34. machine pvfs2_client_setattr_sm
  35. {
  36.     state init
  37.     {
  38.         run setattr_init;
  39.         default => setattr_msg_setup_msgpair;
  40.     }
  41.  
  42.     state setattr_msg_setup_msgpair
  43.     {
  44.         run setattr_msg_setup_msgpair;
  45.         success => setattr_msg_xfer_msgpair;
  46.         default => cleanup;
  47.     }
  48.  
  49.     state setattr_msg_xfer_msgpair
  50.     {
  51.         jump pvfs2_msgpairarray_sm;
  52.         success => cleanup;
  53.         default => setattr_msg_failure;
  54.     }
  55.  
  56.     state setattr_msg_failure
  57.     {
  58.         run setattr_msg_failure;
  59.         default => cleanup;
  60.     }
  61.  
  62.     state cleanup
  63.     {
  64.         run setattr_cleanup;
  65.         default => terminate;
  66.     }
  67. }
  68.  
  69. %%
  70.  
  71. /** Initiate modification of attributes of a single object.
  72.  */
  73. PVFS_error PVFS_isys_setattr(
  74.     PVFS_object_ref ref,
  75.     PVFS_sys_attr attr,
  76.     const PVFS_credentials *credentials,
  77.     PVFS_sys_op_id *op_id,
  78.     PVFS_hint hints,
  79.     void *user_ptr)
  80. {
  81.     PVFS_error ret = -PVFS_EINVAL;
  82.     PINT_smcb *smcb = NULL;
  83.     PINT_client_sm *sm_p = NULL;
  84.  
  85.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_isys_setattr entered\n");
  86.  
  87.     if ((ref.handle == PVFS_HANDLE_NULL) ||
  88.         (ref.fs_id == PVFS_FS_ID_NULL))
  89.     {
  90.         gossip_err("invalid (NULL) required argument\n");
  91.         return ret;
  92.     }
  93.  
  94.     /*
  95.      * make sure the caller didn't set invalid mask bits.
  96.      * only common attributes can be set.
  97.      */
  98.     if ((attr.mask & ~PVFS_ATTR_SYS_ALL_TIMES) != 0)
  99.     {
  100.         gossip_lerr("PVFS_isys_setattr() failure: invalid attributes "
  101.                     "specified\n");
  102.         return ret;
  103.     }
  104.  
  105.     /* make sure that the permission bits are acceptable */
  106.     if ((attr.mask & PVFS_ATTR_SYS_PERM) && (attr.perms & ~PVFS_PERM_VALID) != 0)
  107.     {
  108.         gossip_lerr("PVFS_isys_setattr() failure: invalid or unsupported " 
  109.                     "permission bits\n");
  110.         return(-PVFS_EINVAL);
  111.     }
  112.  
  113.     PINT_smcb_alloc(&smcb, PVFS_SYS_SETATTR,
  114.              sizeof(struct PINT_client_sm),
  115.              client_op_state_get_machine,
  116.              client_state_machine_terminate,
  117.              pint_client_sm_context);
  118.     if (smcb == NULL)
  119.     {
  120.         return -PVFS_ENOMEM;
  121.     }
  122.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  123.  
  124.     PINT_init_msgarray_params(sm_p, ref.fs_id);
  125.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  126.     sm_p->object_ref = ref;
  127.     PVFS_hint_copy(hints, &sm_p->hints);
  128.     PVFS_hint_add(&sm_p->hints, PVFS_HINT_HANDLE_NAME, sizeof(PVFS_handle), &ref.handle);
  129.  
  130.     ret = PVFS_util_copy_sys_attr(&sm_p->u.setattr.sys_attr, &attr);
  131.     if(ret < 0)
  132.     {
  133.         gossip_lerr("PVFS_isys_setattr() failure: %s\n",
  134.                     strerror(PVFS_get_errno_mapping(-ret)));
  135.         return ret;
  136.     } 
  137.  
  138.     gossip_debug(GOSSIP_CLIENT_DEBUG, "Doing setattr on handle %llu "
  139.                  "on fs %d\n", llu(ref.handle),
  140.                  ref.fs_id);
  141.  
  142.     return PINT_client_state_machine_post(
  143.         smcb,  op_id, user_ptr);
  144. }
  145.  
  146. /**  Modify the attributes of a single object.
  147.  */
  148. PVFS_error PVFS_sys_setattr(
  149.     PVFS_object_ref ref,
  150.     PVFS_sys_attr attr,
  151.     const PVFS_credentials *credentials,
  152.     PVFS_hint hints)
  153. {
  154.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  155.     PVFS_sys_op_id op_id;
  156.  
  157.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_sys_setattr entered\n");
  158.  
  159.     ret = PVFS_isys_setattr(ref, attr, credentials, &op_id, hints, NULL);
  160.     if (ret)
  161.     {
  162.         PVFS_perror_gossip("PVFS_isys_setattr call", ret);
  163.         error = ret;
  164.     }
  165.     else
  166.     {
  167.         ret = PVFS_sys_wait(op_id, "setattr", &error);
  168.         if (ret)
  169.         {
  170.             PVFS_perror_gossip("PVFS_sys_wait call", ret);
  171.             error = ret;
  172.         }
  173.     }
  174.  
  175.     PINT_sys_release(op_id);
  176.     return error;
  177. }
  178.  
  179. /****************************************************************/
  180.  
  181. static PINT_sm_action setattr_init(
  182.         struct PINT_smcb *smcb, job_status_s *js_p)
  183. {
  184.     assert(js_p->error_code == 0);
  185.     return SM_ACTION_COMPLETE;
  186. }
  187.  
  188. static int setattr_msg_comp_fn(void *v_p,
  189.                                struct PVFS_server_resp *resp_p,
  190.                                int index)
  191. {
  192.     gossip_debug(GOSSIP_CLIENT_DEBUG, "setattr_msg_comp_fn\n");
  193.  
  194.     assert(resp_p->op == PVFS_SERV_SETATTR);
  195.     return resp_p->status;
  196. }
  197.  
  198. static PINT_sm_action setattr_msg_setup_msgpair(
  199.         struct PINT_smcb *smcb, job_status_s *js_p)
  200. {
  201.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  202.     int ret = -PVFS_EINVAL;
  203.     PINT_sm_msgpair_state *msg_p = NULL;
  204.     PVFS_ds_type objtype;
  205.  
  206.     js_p->error_code = 0;
  207.  
  208.     gossip_debug(GOSSIP_CLIENT_DEBUG," setattr: posting setattr req\n");
  209.  
  210.     PINT_msgpair_init(&sm_p->msgarray_op);
  211.     msg_p = &sm_p->msgarray_op.msgpair;
  212.  
  213.     objtype = ((sm_p->u.setattr.sys_attr.mask & PVFS_ATTR_SYS_TYPE) ? 
  214.          sm_p->u.setattr.sys_attr.objtype : PVFS_TYPE_NONE);
  215.  
  216.     PINT_SERVREQ_SETATTR_FILL(
  217.         msg_p->req,
  218.         *sm_p->cred_p,
  219.         sm_p->object_ref.fs_id,
  220.         sm_p->object_ref.handle,
  221.         objtype,
  222.         sm_p->u.setattr.sys_attr,
  223.         0,
  224.         sm_p->hints);
  225.  
  226.     /* clients should not be able to mess with dfile and distribution
  227.      * information here.  Those parameters should only be set at create time.
  228.      * Maybe at some point we'll have a utility to adjust those attributes.  At
  229.      * this time if they somehow get changed we'll have garbage on disk */
  230.  
  231.     msg_p->fs_id = sm_p->object_ref.fs_id;
  232.     msg_p->handle = sm_p->object_ref.handle;
  233.     msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  234.     msg_p->comp_fn = setattr_msg_comp_fn;
  235.  
  236.     gossip_debug(
  237.             GOSSIP_CLIENT_DEBUG, "setattr attr mask sent to server: 0x%x\n",
  238.             (int)sm_p->u.setattr.sys_attr.mask);
  239.  
  240.     ret = PINT_cached_config_map_to_server(
  241.         &msg_p->svr_addr, msg_p->handle, msg_p->fs_id);
  242.  
  243.     if (ret)
  244.     {
  245.         gossip_err("Failed to map meta server address\n");
  246.         js_p->error_code = ret;
  247.     }
  248.  
  249.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  250.     return SM_ACTION_COMPLETE;
  251. }
  252.  
  253. static PINT_sm_action setattr_msg_failure(
  254.         struct PINT_smcb *smcb, job_status_s *js_p)
  255. {
  256.     assert(js_p->error_code != 0);
  257.     return SM_ACTION_COMPLETE;
  258. }
  259.  
  260. static PINT_sm_action setattr_cleanup(
  261.         struct PINT_smcb *smcb, job_status_s *js_p)
  262. {
  263.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  264.     PVFS_object_attr attr;
  265.  
  266.     sm_p->error_code = js_p->error_code;
  267.  
  268.     /* either update acache or invalidate depending on if we were successful
  269.      * or not 
  270.      */
  271.     if(sm_p->error_code == 0)
  272.     {
  273.         PINT_CONVERT_ATTR(&attr, &sm_p->u.setattr.sys_attr, 0);
  274.         PINT_acache_update(sm_p->object_ref, &attr, NULL);
  275.     }
  276.     else
  277.     {
  278.         PINT_acache_invalidate(sm_p->object_ref);
  279.     }
  280.  
  281.     PINT_SET_OP_COMPLETE;
  282.     return SM_ACTION_TERMINATE;
  283. }
  284.  
  285. /*
  286.  * Local variables:
  287.  *  mode: c
  288.  *  c-indent-level: 4
  289.  *  c-basic-offset: 4
  290.  * End:
  291.  *
  292.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  293.  */
  294.