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-iterate-handles-list.sm < prev    next >
Text File  |  2009-08-14  |  9KB  |  316 lines

  1. /*
  2.  * (C) 2001 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 routines for iterating through handles of objects
  11.  *  stored on servers. These routines are used primarily for file system
  12.  *  check and repair purposes.
  13.  */
  14.  
  15. #include <string.h>
  16.  
  17. #include "client-state-machine.h"
  18. #include "pvfs2-types.h"
  19. #include "pvfs2-mgmt.h"
  20. #include "server-config.h"
  21.  
  22. extern job_context_id pint_client_sm_context;
  23.  
  24. static int iterate_handles_list_comp_fn(
  25.     void *v_p, struct PVFS_server_resp *resp_p, int i);
  26.  
  27. %%
  28.  
  29. machine pvfs2_client_mgmt_iterate_handles_list_sm
  30. {
  31.  
  32.     state setup_msgpair
  33.     {
  34.     run mgmt_iterate_handles_list_setup_msgpair;
  35.     success => xfer_msgpair;
  36.     default => cleanup;
  37.     }
  38.  
  39.     state xfer_msgpair
  40.     {
  41.     jump pvfs2_msgpairarray_sm;
  42.     default => cleanup;
  43.     }
  44.  
  45.     state cleanup
  46.     {
  47.     run mgmt_iterate_handles_list_cleanup;
  48.     default => terminate;
  49.     }
  50. }
  51.  
  52. %%
  53.  
  54. /** Initiate retrieval of a list of handles in use on a collection of
  55.  *  servers.
  56.  *
  57.  * \return 0 on success, -PVFS_error on failure.
  58.  */
  59. PVFS_error PVFS_imgmt_iterate_handles_list(
  60.     PVFS_fs_id fs_id,
  61.     PVFS_credentials *credentials,
  62.     PVFS_handle **handle_matrix,
  63.     int *handle_count_array,
  64.     PVFS_ds_position *position_array,
  65.     PVFS_BMI_addr_t *addr_array,
  66.     int server_count,
  67.     int flags,
  68.     PVFS_error_details *details,
  69.     PVFS_hint hints,
  70.     PVFS_mgmt_op_id *op_id,
  71.     void *user_ptr)
  72. {
  73.     PINT_smcb *smcb = NULL;
  74.     PINT_client_sm *sm_p = NULL;
  75.     int ret;
  76.  
  77.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  78.                  "PVFS_imgmt_iterate_handles_list() entered.\n");
  79.  
  80.     if (server_count < 1 || !handle_matrix || !position_array 
  81.     || !handle_count_array || !addr_array)
  82.     {
  83.     return -PVFS_EINVAL;
  84.     }
  85.  
  86.     PINT_smcb_alloc(&smcb, PVFS_MGMT_ITERATE_HANDLES_LIST,
  87.              sizeof(struct PINT_client_sm),
  88.              client_op_state_get_machine,
  89.              client_state_machine_terminate,
  90.              pint_client_sm_context);
  91.     if (smcb == NULL)
  92.     {
  93.         return -PVFS_ENOMEM;
  94.     }
  95.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  96.  
  97.     PINT_init_msgarray_params(sm_p, fs_id);
  98.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  99.     sm_p->u.iterate_handles_list.fs_id = fs_id;
  100.     sm_p->u.iterate_handles_list.server_count = server_count;
  101.     sm_p->u.iterate_handles_list.addr_array = addr_array;
  102.     sm_p->u.iterate_handles_list.handle_matrix = handle_matrix;
  103.     sm_p->u.iterate_handles_list.handle_count_array = handle_count_array;
  104.     sm_p->u.iterate_handles_list.position_array = position_array;
  105.     sm_p->u.iterate_handles_list.details = details;
  106.     PVFS_hint_copy(hints, &sm_p->hints);
  107.     sm_p->u.iterate_handles_list.flags = flags;
  108.  
  109.     ret = PINT_msgpairarray_init(&sm_p->msgarray_op, server_count);
  110.     if(ret != 0)
  111.     {
  112.         PINT_smcb_free(smcb);
  113.         return ret;
  114.     }
  115.  
  116.     return PINT_client_state_machine_post(
  117.         smcb,  op_id, user_ptr);
  118. }
  119.  
  120. /** Obtain a list of handles in use on a collection of servers.
  121.  */
  122. PVFS_error PVFS_mgmt_iterate_handles_list(
  123.     PVFS_fs_id fs_id,
  124.     PVFS_credentials *credentials,
  125.     PVFS_handle **handle_matrix,
  126.     int *handle_count_array,
  127.     PVFS_ds_position *position_array,
  128.     PVFS_BMI_addr_t *addr_array,
  129.     int server_count,
  130.     int flags,
  131.     PVFS_error_details *details,
  132.     PVFS_hint hints)
  133. {
  134.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  135.     PVFS_mgmt_op_id op_id;
  136.  
  137.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  138.                  "PVFS_mgmt_iterate_handles_list entered\n");
  139.  
  140.     ret = PVFS_imgmt_iterate_handles_list(
  141.         fs_id, credentials, handle_matrix, handle_count_array,
  142.         position_array, addr_array, server_count, flags, details, hints, &op_id, NULL);
  143.  
  144.     if (ret)
  145.     {
  146.         PVFS_perror_gossip("PVFS_imgmt_iterate_handles_list call", ret);
  147.         error = ret;
  148.     }
  149.     else
  150.     {
  151.         ret = PVFS_mgmt_wait(op_id, "iterate_handles_list", &error);
  152.         if (ret)
  153.         {
  154.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  155.             error = ret;
  156.         }
  157.     }
  158.  
  159.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  160.                  "PVFS_mgmt_iterate_handles_list completed\n");
  161.  
  162.     PINT_mgmt_release(op_id);
  163.     return error;
  164. }
  165.  
  166. static PINT_sm_action mgmt_iterate_handles_list_setup_msgpair(
  167.         struct PINT_smcb *smcb, job_status_s *js_p)
  168. {
  169.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  170.     int i = 0, j = 0;
  171.     PINT_sm_msgpair_state *msg_p;
  172.  
  173.     gossip_debug(GOSSIP_CLIENT_DEBUG, "iterate_handles_list state: "
  174.                  "mgmt_iterate_handles_list_setup_msgpair\n");
  175.  
  176.     /* setup msgpair array */
  177.     j=0;
  178.     foreach_msgpair(&sm_p->msgarray_op, msg_p, i)
  179.     {
  180. skipped:
  181.     /* skip servers that have already reached end */
  182.     /* TODO: use a better #define or something for ITERATE_END */
  183.     if(sm_p->u.iterate_handles_list.position_array[j]
  184.         == PVFS_ITERATE_END)
  185.     {
  186.         sm_p->msgarray_op.count--;
  187.         sm_p->u.iterate_handles_list.handle_count_array[j] = 0;
  188.             j++;
  189.             goto skipped;
  190.     }
  191.     else
  192.     {
  193.         PINT_SERVREQ_MGMT_ITERATE_HANDLES_FILL(
  194.                 msg_p->req,
  195.         *sm_p->cred_p,
  196.         sm_p->u.iterate_handles_list.fs_id,
  197.         sm_p->u.iterate_handles_list.handle_count_array[j],
  198.         sm_p->u.iterate_handles_list.position_array[j],
  199.                 sm_p->u.iterate_handles_list.flags,
  200.         sm_p->hints);
  201.         msg_p->fs_id = sm_p->u.iterate_handles_list.fs_id;
  202.         msg_p->handle = PVFS_HANDLE_NULL;
  203.         msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  204.         msg_p->comp_fn = iterate_handles_list_comp_fn;
  205.         msg_p->svr_addr = sm_p->u.iterate_handles_list.addr_array[j];
  206.         j++;
  207.     }
  208.     }
  209.  
  210.     /* TODO: be nicer about this, user called function too many times */
  211.     assert(sm_p->msgarray_op.count > 0);
  212.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  213.  
  214.     /* immediate return: next state jumps to msgpairarray machine */
  215.     js_p->error_code = 0;
  216.     return SM_ACTION_COMPLETE;
  217. }
  218.  
  219. static PINT_sm_action mgmt_iterate_handles_list_cleanup(
  220.         struct PINT_smcb *smcb, job_status_s *js_p)
  221. {
  222.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  223.     int i = 0, errct = 0;
  224.     PVFS_error error = js_p->error_code;
  225.  
  226.     /* store server-specific errors if requested and present */
  227.     if ((error != 0) && (sm_p->u.iterate_handles_list.details != NULL))
  228.     {
  229.     sm_p->u.iterate_handles_list.details->count_exceeded = 0;
  230.  
  231.     for(i = 0; i < sm_p->u.iterate_handles_list.server_count; i++)
  232.         {
  233.         if (sm_p->msgarray_op.msgarray[i].op_status != 0)
  234.         {
  235.         if (errct <
  236.                     sm_p->u.iterate_handles_list.details->count_allocated)
  237.         {
  238.             sm_p->u.iterate_handles_list.details->error[
  239.                         errct].error = sm_p->msgarray_op.msgarray[i].op_status;
  240.             sm_p->u.iterate_handles_list.details->error[
  241.                         errct].addr = sm_p->msgarray_op.msgarray[i].svr_addr;
  242.             errct++;
  243.         }
  244.         else
  245.         {
  246.             sm_p->u.iterate_handles_list.details->count_exceeded = 1;
  247.         }
  248.         }
  249.     }
  250.     sm_p->u.iterate_handles_list.details->count_used = errct;
  251.     error = -PVFS_EDETAIL;
  252.     }
  253.  
  254.     PINT_msgpairarray_destroy(&sm_p->msgarray_op);
  255.  
  256.     sm_p->error_code  = error;
  257.  
  258.     PINT_SET_OP_COMPLETE;
  259.     return SM_ACTION_TERMINATE;
  260. }
  261.  
  262. static int iterate_handles_list_comp_fn(void *v_p,
  263.                     struct PVFS_server_resp *resp_p,
  264.                     int i)
  265. {
  266.     int j = 0;
  267.     PINT_smcb *smcb = v_p;
  268.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  269.  
  270.     /* if this particular request was successful, then collect info from 
  271.      * response
  272.      */
  273.     if (sm_p->msgarray_op.msgarray[i].op_status == 0)
  274.     {
  275.     /* first, we have to match this up with the correct array entry */
  276.     for (j=0; j<sm_p->u.iterate_handles_list.server_count; j++)
  277.     {
  278.         if (sm_p->msgarray_op.msgarray[i].svr_addr 
  279.         == sm_p->u.iterate_handles_list.addr_array[j])
  280.         {
  281.         break;
  282.         }
  283.     }
  284.     assert(j != sm_p->u.iterate_handles_list.server_count);
  285.  
  286.     sm_p->u.iterate_handles_list.handle_count_array[j] =
  287.         resp_p->u.mgmt_iterate_handles.handle_count;
  288.     sm_p->u.iterate_handles_list.position_array[j] =
  289.         resp_p->u.mgmt_iterate_handles.position;
  290.     memcpy(sm_p->u.iterate_handles_list.handle_matrix[j],
  291.            resp_p->u.mgmt_iterate_handles.handle_array,
  292.            resp_p->u.mgmt_iterate_handles.handle_count
  293.            * sizeof(PVFS_handle));
  294.     }
  295.  
  296.     /* if this is the last response, check all of the status values and 
  297.      * return error code if any requests failed 
  298.      */
  299.     if (i == (sm_p->msgarray_op.count -1))
  300.     {
  301.         return PINT_msgarray_status(&sm_p->msgarray_op);
  302.     }
  303.    
  304.     return 0;
  305. }
  306.  
  307. /*
  308.  * Local variables:
  309.  *  mode: c
  310.  *  c-indent-level: 4
  311.  *  c-basic-offset: 4
  312.  * End:
  313.  *
  314.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  315.  */
  316.