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-setparam-list.sm < prev    next >
Text File  |  2008-11-19  |  10KB  |  361 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 setting run-time parameters
  11.  *  on a list of servers.  These are currently used primarily for file
  12.  *  system repair purposes, specifically to put the servers in a special
  13.  *  administrative mode to avoid file system changes while repairs are
  14.  *  underway.
  15.  */
  16.  
  17. #include <string.h>
  18. #include <assert.h>
  19.  
  20. #include "client-state-machine.h"
  21. #include "pvfs2-debug.h"
  22. #include "job.h"
  23. #include "gossip.h"
  24. #include "str-utils.h"
  25. #include "pint-cached-config.h"
  26. #include "PINT-reqproto-encode.h"
  27.  
  28. extern job_context_id pint_client_sm_context;
  29.  
  30. static int root_check_comp_fn(
  31.     void *v_p, struct PVFS_server_resp *resp_p, int i);
  32. static int collect_old_values_comp_fn(
  33.     void *v_p, struct PVFS_server_resp *resp_p, int i);
  34.  
  35. %%
  36.  
  37. machine pvfs2_client_mgmt_setparam_list_sm
  38. {
  39.     state setup_msgpair
  40.     {
  41.         run mgmt_setparam_list_setup_msgpair;
  42.         success => xfer_msgpair;
  43.         default => cleanup;
  44.     }
  45.  
  46.     state xfer_msgpair
  47.     {
  48.         jump pvfs2_msgpairarray_sm;
  49.         default => cleanup;
  50.     }
  51.  
  52.     state cleanup
  53.     {
  54.         run mgmt_setparam_list_cleanup;
  55.         default => terminate;
  56.     }
  57. }
  58.  
  59. %%
  60.  
  61. /** Initiate setting of a run-time server parameter on a list of servers.
  62.  */
  63. PVFS_error PVFS_imgmt_setparam_list(
  64.     PVFS_fs_id fs_id,
  65.     PVFS_credentials *credentials,
  66.     enum PVFS_server_param param,
  67.     struct PVFS_mgmt_setparam_value *value,
  68.     PVFS_BMI_addr_t *addr_array,
  69.     int count,
  70.     PVFS_error_details *details,
  71.     PVFS_hint hints,
  72.     PVFS_mgmt_op_id *op_id,
  73.     void *user_ptr)
  74. {
  75.     PVFS_error ret = -PVFS_EINVAL;
  76.     PINT_smcb *smcb = NULL;
  77.     PINT_client_sm *sm_p = NULL;
  78.  
  79.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  80.                  "PVFS_imgmt_setparam_list entered\n");
  81.  
  82.     if (param == PVFS_SERV_PARAM_INVALID)
  83.     {
  84.         return ret;
  85.     }
  86.  
  87.     PINT_smcb_alloc(&smcb, PVFS_MGMT_SETPARAM_LIST,
  88.              sizeof(struct PINT_client_sm),
  89.              client_op_state_get_machine,
  90.              client_state_machine_terminate,
  91.              pint_client_sm_context);
  92.     if (smcb == NULL)
  93.     {
  94.         return -PVFS_ENOMEM;
  95.     }
  96.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  97.  
  98.     PINT_init_msgarray_params(sm_p, fs_id);
  99.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  100.     sm_p->u.setparam_list.fs_id = fs_id;
  101.     sm_p->u.setparam_list.param = param;
  102.     sm_p->u.setparam_list.value = value;
  103.     sm_p->u.setparam_list.addr_array = addr_array;
  104.     sm_p->u.setparam_list.count = count;
  105.     sm_p->u.setparam_list.details = details;
  106.  
  107.     ret = PINT_msgpairarray_init(&sm_p->msgarray_op, count);
  108.     if(ret != 0)
  109.     {
  110.         PINT_smcb_free(smcb);
  111.         return ret;
  112.     }
  113.  
  114.     if (sm_p->u.setparam_list.root_check_status_array)
  115.     {
  116.         free(sm_p->u.setparam_list.root_check_status_array);
  117.         sm_p->u.setparam_list.root_check_status_array = NULL;
  118.     }
  119.  
  120.     return PINT_client_state_machine_post(
  121.         smcb,  op_id, user_ptr);
  122. }
  123.  
  124. /** Set a run-time parameter on a list of servers.
  125.  */
  126. PVFS_error PVFS_mgmt_setparam_list(
  127.     PVFS_fs_id fs_id,
  128.     PVFS_credentials *credentials,
  129.     enum PVFS_server_param param,
  130.     struct PVFS_mgmt_setparam_value *value,
  131.     PVFS_BMI_addr_t *addr_array,
  132.     int count,
  133.     PVFS_error_details *details,
  134.     PVFS_hint hints)
  135. {
  136.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  137.     PVFS_sys_op_id op_id;
  138.  
  139.     gossip_debug(GOSSIP_CLIENT_DEBUG, "%s entered\n", __func__);
  140.  
  141.     ret = PVFS_imgmt_setparam_list(
  142.         fs_id, credentials, param, value, addr_array,
  143.         count, details, hints, &op_id, NULL);
  144.  
  145.     if (ret)
  146.     {
  147.         PVFS_perror_gossip("PVFS_imgmt_setparam_list call", ret);
  148.         error = ret;
  149.     }
  150.     else
  151.     {
  152.         ret = PVFS_mgmt_wait(op_id, "setparam_list", &error);
  153.         if (ret)
  154.         {
  155.             PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
  156.             error = ret;
  157.         }
  158.     }
  159.  
  160.     gossip_debug(GOSSIP_CLIENT_DEBUG, "%s completed\n", __func__);
  161.  
  162.     PINT_mgmt_release(op_id);
  163.     return error;
  164. }
  165.  
  166. static PINT_sm_action mgmt_setparam_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;
  171.     PINT_sm_msgpair_state *msg_p = NULL;
  172.  
  173.     gossip_debug(GOSSIP_CLIENT_DEBUG, "setparam_list state: "
  174.                  "mgmt_setparam_list_setup_msgpair\n");
  175.  
  176.     /* setup msgpair array */
  177.     foreach_msgpair(&sm_p->msgarray_op, msg_p, i)
  178.     {
  179.         PINT_SERVREQ_MGMT_SETPARAM_FILL(
  180.             msg_p->req,
  181.             *sm_p->cred_p,
  182.             sm_p->u.setparam_list.fs_id,
  183.             sm_p->u.setparam_list.param,
  184.             sm_p->u.setparam_list.value,
  185.             sm_p->hints);
  186.  
  187.         msg_p->fs_id = sm_p->u.setparam_list.fs_id;
  188.         msg_p->handle = PVFS_HANDLE_NULL;
  189.         msg_p->retry_flag = PVFS_MSGPAIR_RETRY;
  190.  
  191.         switch(sm_p->u.setparam_list.param)
  192.         {
  193.             case PVFS_SERV_PARAM_ROOT_CHECK:
  194.                 msg_p->comp_fn = root_check_comp_fn;
  195.                 sm_p->u.setparam_list.root_check_status_array = (int *)
  196.                     malloc(sm_p->u.setparam_list.count * sizeof(int));
  197.                 memset(sm_p->u.setparam_list.root_check_status_array, -1,
  198.                        (sm_p->u.setparam_list.count * sizeof(int)));
  199.                 break;
  200.  
  201.             default:
  202.                 msg_p->comp_fn = collect_old_values_comp_fn;
  203.                 break;
  204.         }
  205.         msg_p->svr_addr = sm_p->u.setparam_list.addr_array[i];
  206.     }
  207.  
  208.     /* immediate return: next state jumps to msgpairarray machine */
  209.     js_p->error_code = 0;
  210.  
  211.     PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op);
  212.     return SM_ACTION_COMPLETE;
  213. }
  214.  
  215. static PINT_sm_action mgmt_setparam_list_cleanup(
  216.         struct PINT_smcb *smcb, job_status_s *js_p)
  217. {
  218.     struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  219.     int i = 0, errct = 0;
  220.     PVFS_error error = js_p->error_code;
  221.  
  222.     /* store server-specific errors if requested and present */
  223.     if ((error != 0) && (sm_p->u.setparam_list.details != NULL))
  224.     {
  225.         sm_p->u.setparam_list.details->count_exceeded = 0;
  226.  
  227.         for(i = 0; i < sm_p->u.setparam_list.count; i++)
  228.         {
  229.             int status;
  230.             if (sm_p->u.setparam_list.param == PVFS_SERV_PARAM_ROOT_CHECK)
  231.             {
  232.                 status = sm_p->u.setparam_list.root_check_status_array[i];
  233.             }
  234.             else
  235.             {
  236.                 status = sm_p->msgarray_op.msgarray[i].op_status;
  237.             }
  238.  
  239.             if (errct < sm_p->u.setparam_list.details->count_allocated)
  240.             {
  241.                 sm_p->u.setparam_list.details->error[errct].error = status;
  242.                 sm_p->u.setparam_list.details->error[errct].addr =
  243.                     sm_p->msgarray_op.msgarray[i].svr_addr;
  244.                 errct++;
  245.             }
  246.             else
  247.             {
  248.                 sm_p->u.setparam_list.details->count_exceeded = 1;
  249.                 break;
  250.             }
  251.         }
  252.         sm_p->u.setparam_list.details->count_used = errct;
  253.  
  254.         error = -PVFS_EDETAIL;
  255.     }
  256.  
  257.     if(sm_p->u.setparam_list.param == PVFS_SERV_PARAM_ROOT_CHECK)
  258.     {
  259.         free(sm_p->u.setparam_list.root_check_status_array);
  260.         sm_p->u.setparam_list.root_check_status_array = NULL;
  261.     }
  262.  
  263.     PINT_msgpairarray_destroy(&sm_p->msgarray_op);
  264.  
  265.     sm_p->error_code  = error;
  266.  
  267.     PINT_SET_OP_COMPLETE;
  268.     return SM_ACTION_TERMINATE;
  269. }
  270.  
  271. /* collect_old_values_comp_fn()
  272.  *
  273.  * completion function that assembles old values for parameters
  274.  * when appropriate
  275.  *
  276.  * returns 0 on success, -PVFS_error on failure
  277.  */
  278. static int collect_old_values_comp_fn(
  279.     void *v_p, struct PVFS_server_resp *resp_p, int i)
  280. {
  281.     PINT_smcb *smcb = v_p;
  282.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  283.     int j;
  284.  
  285.     /* if this is the last response, check all of the status values
  286.      * and return error code if any requests failed
  287.      */
  288.     if (i == (sm_p->msgarray_op.count -1))
  289.     {
  290.         for (j = 0; j < sm_p->msgarray_op.count; j++)
  291.         {
  292.             if (sm_p->msgarray_op.msgarray[j].op_status != 0)
  293.             {
  294.                 return sm_p->msgarray_op.msgarray[j].op_status;
  295.             }
  296.         }
  297.     }
  298.     return 0;
  299. }
  300.  
  301. /* root_check_comp_fn()
  302.  *
  303.  * completion function for PVFS_SERV_PARAM_ROOT_CHECK parameter; it
  304.  * handles this special case operation in which we want just one
  305.  * server to return success and all others to return -PVFS_ENOENT.
  306.  *
  307.  * returns 0 if exactly one server claims ownership of root handle,
  308.  * -PVFS_error on failure
  309.  */
  310. static int root_check_comp_fn(
  311.     void *v_p, struct PVFS_server_resp *resp_p, int i)
  312. {
  313.     int j = 0;
  314.     int owners = 0;
  315.     PINT_smcb *smcb = v_p;
  316.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM);
  317.  
  318.     /*
  319.       store the op_status before it's overwritten with the return
  320.       value of this comp_fn by the msgpairarray code
  321.     */
  322.     sm_p->u.setparam_list.root_check_status_array[i] =
  323.         sm_p->msgarray_op.msgarray[i].op_status;
  324.  
  325.     /* need to return non-zero status at the end if any of the statuses
  326.      * are nonzero
  327.      */
  328.     if(i == (sm_p->u.setparam_list.count - 1))
  329.     {
  330.         for(; j < sm_p->u.setparam_list.count; ++j)
  331.         {
  332.             if(sm_p->u.setparam_list.root_check_status_array[j] == 0)
  333.             {
  334.                 owners++;
  335.             }
  336.             else if(sm_p->u.setparam_list.root_check_status_array[j] != 
  337.                     -PVFS_ENOENT)
  338.             {
  339.                 return -PVFS_EDETAIL;
  340.             }
  341.         }
  342.  
  343.         if(owners != 1)
  344.         {
  345.             return -PVFS_EDETAIL;
  346.         }
  347.     }
  348.  
  349.     return 0;
  350. }
  351.  
  352. /*
  353.  * Local variables:
  354.  *  mode: c
  355.  *  c-indent-level: 4
  356.  *  c-basic-offset: 4
  357.  * End:
  358.  *
  359.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  360.  */
  361.