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 / mgmt-get-dfile-array.sm < prev    next >
Text File  |  2008-11-19  |  5KB  |  191 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 mgmtint
  9.  *
  10.  *  PVFS2 management interface routines for obtaining datafile handles
  11.  *  for a given file.
  12.  *
  13.  *  This are used primarily for file system check and repair purposes.
  14.  */
  15.  
  16. #include <string.h>
  17. #include <assert.h>
  18.  
  19. #include "client-state-machine.h"
  20. #include "pvfs2-debug.h"
  21. #include "job.h"
  22. #include "gossip.h"
  23. #include "str-utils.h"
  24. #include "pint-cached-config.h"
  25. #include "PINT-reqproto-encode.h"
  26. #include "pint-util.h"
  27.  
  28. extern job_context_id pint_client_sm_context;
  29.  
  30. %%
  31.  
  32. machine pvfs2_client_mgmt_get_dfile_array_sm
  33. {
  34.     state getattr
  35.     {
  36.         jump pvfs2_client_getattr_sm;
  37.         default => cleanup;
  38.     }
  39.  
  40.     state cleanup
  41.     {
  42.         run mgmt_get_dfile_array_cleanup;
  43.         default => terminate;
  44.     }
  45. }
  46.  
  47. %%
  48.  
  49. /** Initiate retrieval of list of handles of datafiles associated with
  50.  *  a given file.
  51.  */
  52. PVFS_error PVFS_imgmt_get_dfile_array(
  53.     PVFS_object_ref ref,
  54.     PVFS_credentials *credentials,
  55.     PVFS_handle *dfile_array,
  56.     int dfile_count,
  57.     PVFS_mgmt_op_id *op_id,
  58.     PVFS_hint hints,
  59.     void *user_ptr)
  60. {
  61.     PVFS_error ret = -PVFS_EINVAL;
  62.     PINT_smcb *smcb = NULL;
  63.     PINT_client_sm *sm_p = NULL;
  64.  
  65.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  66.                  "PVFS_imgmt_get_dfile_array entered\n");
  67.  
  68.     if (!dfile_array)
  69.     {
  70.         return ret;
  71.     }
  72.  
  73.     PINT_smcb_alloc(&smcb, PVFS_MGMT_GET_DFILE_ARRAY,
  74.              sizeof(struct PINT_client_sm),
  75.              client_op_state_get_machine,
  76.              client_state_machine_terminate,
  77.              pint_client_sm_context);
  78.     if (!smcb)
  79.     {
  80.     return -PVFS_ENOMEM;
  81.     }
  82.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  83.  
  84.     PINT_init_msgarray_params(sm_p, ref.fs_id);
  85.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  86.     sm_p->object_ref = ref;
  87.     sm_p->u.get_dfile_array.dfile_array = dfile_array;
  88.     sm_p->u.get_dfile_array.dfile_count = dfile_count;
  89.     PVFS_hint_copy(hints, &sm_p->hints);
  90.  
  91.     PINT_SM_GETATTR_STATE_FILL(
  92.         sm_p->getattr,
  93.         ref,
  94.         PVFS_ATTR_META_ALL|PVFS_ATTR_COMMON_TYPE,
  95.         PVFS_TYPE_METAFILE, 
  96.         0);
  97.  
  98.     return PINT_client_state_machine_post(
  99.         smcb,  op_id, user_ptr);
  100. }
  101.  
  102. /** Obtain the list of handles of datafiles associated with a given file.
  103.  */
  104. PVFS_error PVFS_mgmt_get_dfile_array(
  105.     PVFS_object_ref ref,
  106.     PVFS_credentials *credentials,
  107.     PVFS_handle *dfile_array,
  108.     int dfile_count,
  109.     PVFS_hint hints)
  110. {
  111.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  112.     PVFS_mgmt_op_id op_id;
  113.  
  114.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  115.                  "PVFS_mgmt_get_dfile_array entered\n");
  116.  
  117.     ret = PVFS_imgmt_get_dfile_array(
  118.         ref, credentials, dfile_array, dfile_count, &op_id, hints, NULL);
  119.  
  120.     if (ret)
  121.     {
  122.         PVFS_perror_gossip("PVFS_imgmt_get_dfile_array call", ret);
  123.         error = ret;
  124.     }
  125.     else
  126.     {
  127.         if (op_id >= 0)  /* -1 means completed immediately */
  128.         {
  129.             ret = PVFS_mgmt_wait(op_id, "get_dfile_array", &error);
  130.             if (ret)
  131.             {
  132.                 PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  133.                 error = ret;
  134.             }
  135.         }
  136.     }
  137.  
  138.     if (op_id >= 0)
  139.         PINT_mgmt_release(op_id);
  140.     return error;
  141. }
  142.  
  143.  
  144. /****************************************************************/
  145.  
  146. static PINT_sm_action mgmt_get_dfile_array_cleanup(
  147.         struct PINT_smcb *smcb, job_status_s *js_p)
  148. {
  149.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  150.     PVFS_object_attr *attr = NULL;
  151.  
  152.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  153.         "mgmt_get_dfile_array state: cleanup\n");
  154.  
  155.     sm_p->error_code = js_p->error_code;
  156.  
  157.     if (sm_p->error_code == 0)
  158.     {
  159.         attr = &sm_p->getattr.attr;
  160.         assert(attr);
  161.         assert(attr->mask & PVFS_ATTR_META_DFILES);
  162.         assert(attr->u.meta.dfile_count > 0);
  163.  
  164.         /* copy out going parameters */
  165.         sm_p->u.get_dfile_array.dfile_count =
  166.             attr->u.meta.dfile_count;
  167.         memcpy(sm_p->u.get_dfile_array.dfile_array,
  168.                attr->u.meta.dfile_array,
  169.                (attr->u.meta.dfile_count * sizeof(PVFS_handle)));
  170.     }
  171.     else
  172.     {
  173.         PINT_acache_invalidate(sm_p->object_ref);
  174.     }
  175.  
  176.     PINT_SM_GETATTR_STATE_CLEAR(sm_p->getattr);
  177.  
  178.     PINT_SET_OP_COMPLETE;
  179.     return SM_ACTION_TERMINATE;
  180. }
  181.  
  182. /*
  183.  * Local variables:
  184.  *  mode: c
  185.  *  c-indent-level: 4
  186.  *  c-basic-offset: 4
  187.  * End:
  188.  *
  189.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  190.  */
  191.