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 / setparam.sm < prev    next >
Text File  |  2008-11-19  |  9KB  |  304 lines

  1. /* 
  2.  * (C) 2001 Clemson University and The University of Chicago 
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include <assert.h>
  13.  
  14. #include "server-config.h"
  15. #include "pvfs2-server.h"
  16. #include "pint-event.h"
  17. #include "pvfs2-internal.h"
  18. #include "gossip.h"
  19. #include "request-scheduler/request-scheduler.h"
  20.  
  21. static int check_fs_id(PVFS_fs_id fs_id);
  22. static int drop_caches(void);
  23.  
  24. %%
  25.  
  26. machine pvfs2_setparam_sm
  27. {
  28.     state prelude
  29.     {
  30.         jump pvfs2_prelude_sm;
  31.         success => work;
  32.         default => final_response;
  33.     }
  34.  
  35.     state work
  36.     {
  37.         run setparam_work;
  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 setparam_cleanup;
  50.         default => terminate;
  51.     }
  52. }
  53.  
  54. %%
  55.  
  56. /* setparam_work()
  57.  *
  58.  * actually does the "work" involved in setting a runtime server parameter
  59.  */
  60. static PINT_sm_action setparam_work(
  61.         struct PINT_smcb *smcb, job_status_s *js_p)
  62. {
  63.     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  64.     int ret = -1, tmp_on = 0;
  65.     job_id_t tmp_id;
  66.     uint64_t tmp_mask = 0;
  67.     PVFS_handle tmp_handle = PVFS_HANDLE_NULL;
  68.     struct server_configuration_s *user_opts;
  69.     struct filesystem_configuration_s *fs_conf;
  70.     char buf[16] = {0};
  71.  
  72.     switch(s_op->req->u.mgmt_setparam.param)
  73.     {
  74.         case PVFS_SERV_PARAM_GOSSIP_MASK:
  75.             gossip_get_debug_mask(&tmp_on, &tmp_mask);
  76.             gossip_set_debug_mask(
  77.                 1, s_op->req->u.mgmt_setparam.value.u.value);
  78.             js_p->error_code = 0;
  79.             return SM_ACTION_COMPLETE;
  80.         case PVFS_SERV_PARAM_INVALID:
  81.             gossip_lerr("Error: mgmt_setparam for unknown parameter %d.\n",
  82.                 (int)s_op->req->u.mgmt_setparam.param);
  83.             js_p->error_code = -PVFS_ENOSYS;
  84.             return SM_ACTION_COMPLETE;
  85.         case PVFS_SERV_PARAM_FSID_CHECK:
  86.             js_p->error_code = check_fs_id(
  87.                 (PVFS_fs_id)s_op->req->u.mgmt_setparam.value.u.value);
  88.             return SM_ACTION_COMPLETE;
  89.         case PVFS_SERV_PARAM_ROOT_CHECK:
  90.             tmp_handle = (PVFS_handle)s_op->req->u.mgmt_setparam.value.u.value;
  91.             gossip_debug(GOSSIP_SERVER_DEBUG, " - ROOT_CHECK looking for"
  92.                          " handle %llu, on fs_id %d\n", llu(tmp_handle),
  93.                          s_op->req->u.mgmt_setparam.fs_id);
  94.             ret = job_trove_dspace_verify(
  95.                 s_op->req->u.mgmt_setparam.fs_id, tmp_handle,
  96.                 0, 
  97.                 smcb, 0, js_p, &tmp_id, server_job_context, s_op->req->hints);
  98.             return(ret);
  99.         case PVFS_SERV_PARAM_EVENT_ENABLE:
  100.             ret = 0;
  101.             PINT_event_enable(s_op->req->u.mgmt_setparam.value.u.string_value);
  102.             js_p->error_code = ret;
  103.             return SM_ACTION_COMPLETE;
  104.         case PVFS_SERV_PARAM_EVENT_DISABLE:
  105.             PINT_event_disable(s_op->req->u.mgmt_setparam.value.u.string_value);
  106.             js_p->error_code = 0;
  107.             return SM_ACTION_COMPLETE;
  108.         case PVFS_SERV_PARAM_SYNC_META:
  109.             user_opts = get_server_config_struct();
  110.             fs_conf = PINT_config_find_fs_id(user_opts, 
  111.                 s_op->req->u.mgmt_setparam.fs_id);
  112.             if(fs_conf)
  113.             {
  114.                 if(s_op->req->u.mgmt_setparam.value.u.value)
  115.                     fs_conf->trove_sync_meta = TROVE_SYNC;
  116.                 else
  117.                     fs_conf->trove_sync_meta = 0;
  118.             }
  119.             js_p->error_code = 0;
  120.             return SM_ACTION_COMPLETE;
  121.         case PVFS_SERV_PARAM_SYNC_DATA:
  122.             user_opts = get_server_config_struct();
  123.             fs_conf = PINT_config_find_fs_id(user_opts, 
  124.                 s_op->req->u.mgmt_setparam.fs_id);
  125.             if(fs_conf)
  126.             {
  127.                 if(s_op->req->u.mgmt_setparam.value.u.value)
  128.                 {
  129.                     snprintf(buf, 16, "%d,%d", s_op->req->u.mgmt_setparam.fs_id,
  130.                              TROVE_SYNC);
  131.                     PINT_flow_setinfo(NULL, FLOWPROTO_DATA_SYNC_MODE, buf);
  132.                     fs_conf->trove_sync_data = TROVE_SYNC;
  133.                 }
  134.                 else
  135.                 {
  136.                     snprintf(buf, 16, "%d,%d", s_op->req->u.mgmt_setparam.fs_id,
  137.                              0);
  138.                     PINT_flow_setinfo(NULL, FLOWPROTO_DATA_SYNC_MODE, buf);
  139.                     fs_conf->trove_sync_data = 0;
  140.                 }
  141.             }
  142.             js_p->error_code = 0;
  143.             return SM_ACTION_COMPLETE;
  144.         case PVFS_SERV_PARAM_MODE:
  145.  
  146.             ret = job_req_sched_change_mode(
  147.                 s_op->req->u.mgmt_setparam.value.u.value,
  148.                 NULL, 0, js_p, &s_op->scheduled_id,
  149.                 server_job_context);
  150.  
  151.             js_p->error_code = 0;
  152.             return ret;
  153.         case PVFS_SERV_PARAM_DROP_CACHES:
  154.             js_p->error_code = drop_caches();
  155.             return SM_ACTION_COMPLETE;
  156.     }
  157.  
  158.     gossip_lerr("Error: mgmt_setparam for unknown parameter %d.\n",
  159.                 (int)s_op->req->u.mgmt_setparam.param);
  160.  
  161.     js_p->error_code = -PVFS_ENOSYS;
  162.     return SM_ACTION_COMPLETE;
  163. }
  164.  
  165. /* setparam_cleanup()
  166.  *
  167.  * cleans up any resources consumed by this state machine and ends
  168.  * execution of the machine
  169.  */
  170. static PINT_sm_action setparam_cleanup(
  171.         struct PINT_smcb *smcb, job_status_s *js_p)
  172. {
  173.     gossip_debug(GOSSIP_SERVER_DEBUG, " - setparam returning %d\n",
  174.                  js_p->error_code);
  175.     return(server_state_machine_complete(smcb));
  176. }
  177.  
  178. /* check_fs_id()
  179.  *
  180.  * checks to see if a given fs id is valid
  181.  *
  182.  * returns 0 on success, -PVFS_error on failure
  183.  */
  184. static int check_fs_id(PVFS_fs_id fs_id)
  185. {
  186.     int ret = -PVFS_ENOENT, count = 1;
  187.     TROVE_ds_position pos = TROVE_ITERATE_START;
  188.     TROVE_keyval_s name;
  189.     TROVE_coll_id tmp_coll;
  190.     TROVE_op_id tmp_id;
  191.     struct server_configuration_s * server_config;
  192.  
  193.     name.buffer = malloc(PVFS_NAME_MAX);
  194.     if (!name.buffer)
  195.     {
  196.         ret = -PVFS_ENOMEM;
  197.         goto check_failed;
  198.     }
  199.     name.buffer_sz = PVFS_NAME_MAX;
  200.  
  201.     server_config = get_server_config_struct();
  202.  
  203.     while(count == 1)
  204.     {
  205.         ret = trove_collection_iterate(
  206.             server_config->trove_method,
  207.             &pos, &name, &tmp_coll, &count, 0, 0, NULL, &tmp_id);
  208.  
  209.         if (ret == 0)
  210.         {
  211.             gossip_lerr("Error: unexpected trove behavior.\n");
  212.             ret = -PVFS_EINVAL;
  213.             goto free_name_buffer;
  214.         }
  215.         
  216.         if (ret < 0)
  217.         {
  218.             goto free_name_buffer;
  219.         }
  220.  
  221.         gossip_debug(GOSSIP_SERVER_DEBUG, "looking for fs_id: %d, "
  222.                      "found %d.\n", (int)fs_id, (int)tmp_coll);
  223.  
  224.         if ((count > 0) && (tmp_coll == fs_id))
  225.         {
  226.             /* we found a matching collection */
  227.             ret = 0;
  228.             break;
  229.         }
  230.     }
  231.  
  232. free_name_buffer:
  233.     free(name.buffer);
  234. check_failed:
  235.  
  236.     return ret;
  237. }
  238.  
  239. static inline int PINT_get_object_ref_setparam(
  240.     struct PVFS_server_req *req, PVFS_fs_id *fs_id, PVFS_handle *handle)
  241. {
  242.     *fs_id = req->u.mgmt_setparam.fs_id;
  243.     *handle = PVFS_HANDLE_NULL;
  244.     return 0;
  245. };
  246.  
  247. struct PINT_server_req_params pvfs2_setparam_params =
  248. {
  249.     .string_name = "mgmt_setparam",
  250.     .perm = PINT_SERVER_CHECK_NONE,
  251.     .access_type = PINT_server_req_modify,
  252.     .get_object_ref = PINT_get_object_ref_setparam,
  253.     .state_machine = &pvfs2_setparam_sm
  254. };
  255.  
  256. /* drop_caches()
  257.  *
  258.  * Linux specific, but should fail cleanly on other platforms. 
  259.  *
  260.  * This function asks the operating system to sync and drop any in memory
  261.  * caches that it may have.  Applies globally to all file systems on the
  262.  * server, not just the PVFS storage space.
  263.  */
  264. static int drop_caches(void)
  265. {
  266.     int fd;
  267.     int ret;
  268.  
  269.     /* try to commit buffer cache first */
  270.     sync();
  271.  
  272.     /* open Linux specific control file if present */
  273.     fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
  274.     if(fd < 0)
  275.     {
  276.         gossip_debug(GOSSIP_SERVER_DEBUG, 
  277.             "Warning: drop_caches not supported.\n");
  278.         return(-PVFS_EOPNOTSUPP);
  279.     }
  280.  
  281.     /* free page cache, dentries, and inodes */
  282.     ret = write(fd, "3", 2);
  283.     if(ret < 0)
  284.     {
  285.         gossip_debug(GOSSIP_SERVER_DEBUG, 
  286.             "Warning: found drop_caches file but failed to write to it.\n");
  287.         close(fd);
  288.         return(-PVFS_EOPNOTSUPP);
  289.     }
  290.    
  291.     close(fd);
  292.     return(0);
  293. }
  294.  
  295. /*
  296.  * Local variables:
  297.  *  mode: c
  298.  *  c-indent-level: 4
  299.  *  c-basic-offset: 4
  300.  * End:
  301.  *
  302.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  303.  */
  304.