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-repair-file.sm < prev    next >
Text File  |  2008-05-06  |  8KB  |  308 lines

  1. /* 
  2.  * (C) 2007 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 repairing files.
  11.  */
  12.  
  13. #include <string.h>
  14. #include <assert.h>
  15.  
  16. #include "client-state-machine.h"
  17. #include "pvfs2-debug.h"
  18. #include "pvfs2-dist-simple-stripe.h"
  19. #include "job.h"
  20. #include "gossip.h"
  21. #include "str-utils.h"
  22. #include "pint-cached-config.h"
  23. #include "pint-distribution.h"
  24. #include "PINT-reqproto-encode.h"
  25. #include "pint-util.h"
  26. #include "pint-dist-utils.h"
  27. #include "ncache.h"
  28. #include "pvfs2-internal.h"
  29. #include "sys-create.h"
  30.  
  31. extern job_context_id pint_client_sm_context;
  32.  
  33. %%
  34.  
  35. machine pvfs2_client_mgmt_repair_file_sm
  36. {
  37.     state init
  38.     {
  39.         rung create_init;
  40.         default => parent_getattr;
  41.     }
  42.  
  43.     state parent_getattr
  44.     {
  45.         jump pvfs2_client_getattr_sm;
  46.         success => parent_getattr_inspect;
  47.         default => cleanup;
  48.     }
  49.  
  50.     state parent_getattr_inspect
  51.     {
  52.         rung create_parent_getattr_inspect;
  53.         success => dspace_create_setup_msgpair;
  54.         default => cleanup;
  55.     }
  56.  
  57.     state dspace_create_setup_msgpair
  58.     {
  59.         rung create_dspace_create_setup_msgpair;
  60.         success => dspace_create_xfer_msgpair;
  61.         default => dspace_create_failure;
  62.     }
  63.  
  64.     state dspace_create_xfer_msgpair
  65.     {
  66.         jump pvfs2_msgpairarray_sm;
  67.         success => create_setattr_setup_msgpair;
  68.         default => dspace_create_failure;
  69.     }
  70.  
  71.     state dspace_create_failure
  72.     {
  73.         run create_dspace_create_failure;
  74.         default => cleanup;
  75.     }
  76.  
  77.     state create_setattr_setup_msgpair
  78.     {
  79.         rung create_setattr_setup_msgpair;
  80.         success => create_setattr_xfer_msgpair;
  81.         default => cleanup;
  82.     }
  83.  
  84.     state create_setattr_xfer_msgpair
  85.     {
  86.         jump pvfs2_msgpairarray_sm;
  87.         success => crdirent_setup_msgpair;
  88.         default => create_setattr_failure;
  89.     }
  90.  
  91.     state create_setattr_failure
  92.     {
  93.         rung create_setattr_failure;
  94.         default => delete_handles_setup_msgpair_array;
  95.     }
  96.  
  97.     state crdirent_setup_msgpair
  98.     {
  99.         rung create_crdirent_setup_msgpair;
  100.         success => crdirent_xfer_msgpair;
  101.         default => crdirent_failure;
  102.     }
  103.  
  104.     state crdirent_xfer_msgpair
  105.     {
  106.         jump pvfs2_msgpairarray_sm;
  107.         success => cleanup;
  108.         default => crdirent_failure;
  109.     }
  110.  
  111.     state crdirent_failure
  112.     {
  113.         rung create_crdirent_failure;
  114.         default => delete_handles_setup_msgpair_array;
  115.     }
  116.  
  117.     state delete_handles_setup_msgpair_array
  118.     {
  119.         rung create_delete_handles_setup_msgpair_array;
  120.         success => delete_handles_xfer_msgpair_array;
  121.         default => cleanup;
  122.     }
  123.  
  124.     state delete_handles_xfer_msgpair_array
  125.     {
  126.         jump pvfs2_msgpairarray_sm;
  127.         default => cleanup;
  128.     }
  129.  
  130.     state cleanup
  131.     {
  132.         rung create_cleanup;
  133.         CREATE_RETRY => init;
  134.         default => terminate;
  135.     }
  136. }
  137.  
  138. %%
  139.  
  140. /** Initiate creation of a file with a specified distribution.
  141.  */
  142. PVFS_error PVFS_imgmt_repair_file(
  143.     char *object_name,
  144.     PVFS_object_ref parent_ref,
  145.     PVFS_sys_attr attr,
  146.     PVFS_credentials *credentials,
  147.     PVFS_handle handle,  /*Pull in handle of dfile to create*/
  148.     PVFS_sysresp_create *resp,
  149.     PVFS_sys_op_id *op_id,
  150.     void *user_ptr)
  151. {
  152.     int num_dfiles_req = 0;
  153.     PVFS_error ret = -PVFS_EINVAL;
  154.     PINT_client_sm *sm_p = NULL;
  155.     PINT_smcb *smcb = NULL;
  156.  
  157.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_imgmt_repair_file entered\n");
  158.  
  159.     if ((parent_ref.handle == PVFS_HANDLE_NULL) ||
  160.         (parent_ref.fs_id == PVFS_FS_ID_NULL) ||
  161.         (object_name == NULL) || (resp == NULL))
  162.     {
  163.         gossip_err("invalid (NULL) required argument\n");
  164.         return ret;
  165.     }
  166.  
  167.     if ((attr.mask & PVFS_ATTR_SYS_ALL_SETABLE) !=
  168.         PVFS_ATTR_SYS_ALL_SETABLE)
  169.     {
  170.         gossip_lerr("PVFS_imgmt_repair_file() failure: invalid attributes "
  171.                     "specified\n");
  172.         return ret;
  173.     }
  174.  
  175.     if ((attr.mask & PVFS_ATTR_SYS_DFILE_COUNT) &&
  176.         ((attr.dfile_count < 1) ||
  177.          (attr.dfile_count > PVFS_REQ_LIMIT_DFILE_COUNT)))
  178.     {
  179.     gossip_err("Error: invalid number of datafiles (%d) specified "
  180.                    "in PVFS_mgmt_repair_file().\n", (int)attr.dfile_count);
  181.     return ret;
  182.     }
  183.  
  184.     if ((strlen(object_name) + 1) > PVFS_REQ_LIMIT_SEGMENT_BYTES)
  185.     {
  186.         return -PVFS_ENAMETOOLONG;
  187.     }
  188.  
  189.     PINT_smcb_alloc(&smcb, PVFS_MGMT_REPAIR_FILE,
  190.                     sizeof(struct PINT_client_sm),
  191.                     client_op_state_get_machine,
  192.                     client_state_machine_terminate,
  193.                     pint_client_sm_context);
  194.     if(smcb == NULL)
  195.     {
  196.         return -PVFS_ENOMEM;
  197.     }
  198.     sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  199.  
  200.     sm_p->u.create.datafile_handles = (PVFS_handle *)malloc(
  201.         sizeof(PVFS_handle));
  202.     if (sm_p->u.create.datafile_handles == NULL)
  203.     {
  204.         gossip_err("create: Failed to allocate data handle array\n");
  205.         return -PVFS_ENOMEM;
  206.     }
  207.     memset(sm_p->u.create.datafile_handles, 0,sizeof(PVFS_handle));
  208.  
  209.     PINT_init_msgarray_params(sm_p, parent_ref.fs_id);
  210.     PINT_init_sysint_credentials(sm_p->cred_p, credentials);
  211.     sm_p->u.create.object_name = object_name;
  212.     sm_p->u.create.create_resp = resp;
  213.     sm_p->u.create.datafile_handles[0] = handle; /*Assign handle pulled in here*/
  214.     PVFS_util_copy_sys_attr(&sm_p->u.create.sys_attr, &attr);
  215.     sm_p->u.create.stored_error_code = 0;
  216.     sm_p->u.create.retry_count = 0;
  217.  
  218.     sm_p->object_ref = parent_ref;
  219.  
  220.     /* use the basic_dist distribution to keep all on one server */
  221.     sm_p->u.create.dist = PINT_dist_create("basic_dist");
  222.     if (!sm_p->u.create.dist)
  223.     {
  224.         free(sm_p);
  225.         return -PVFS_ENOMEM;
  226.     }
  227.  
  228.     /*Set requested number of dfiles to 1*/
  229.     num_dfiles_req = 1;
  230.  
  231.     /* Determine the number of dfiles, passing in desired value of 1 */
  232.     ret = PINT_cached_config_get_num_dfiles(sm_p->object_ref.fs_id,
  233.                                             sm_p->u.create.dist,
  234.                                             num_dfiles_req,
  235.                                             &sm_p->u.create.num_data_files);
  236.     if (ret < 0)
  237.     {
  238.         gossip_err("Failed to get number of data servers\n");
  239.         free(sm_p);
  240.         return ret;
  241.     }
  242.  
  243.     gossip_debug(
  244.         GOSSIP_CLIENT_DEBUG, "Creating file %s under %llu, %d\n",
  245.         object_name, llu(parent_ref.handle), parent_ref.fs_id);
  246.           
  247.     return PINT_client_state_machine_post(
  248.         smcb, op_id, user_ptr);
  249. }
  250.  
  251. /** Create a file with a specified distribution.
  252.  */
  253. PVFS_error PVFS_mgmt_repair_file(
  254.     char *object_name,
  255.     PVFS_object_ref parent_ref,
  256.     PVFS_sys_attr attr,
  257.     PVFS_credentials *credentials,
  258.     PVFS_handle handle, 
  259.     PVFS_sysresp_create *resp)
  260. {
  261.     PVFS_error ret = -PVFS_EINVAL, error = 0;
  262.     PVFS_sys_op_id op_id;
  263.  
  264.     gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_mgmt_repair_file entered\n");
  265.  
  266.     ret = PVFS_imgmt_repair_file(object_name, parent_ref, attr, credentials,
  267.                                  handle, resp, &op_id, NULL);
  268.     if (ret)
  269.     {
  270.         PVFS_perror_gossip("PVFS_imgmt_repair_file call", ret);
  271.         error = ret;
  272.     }
  273.     else
  274.     {
  275.         ret = PVFS_sys_wait(op_id, "create", &error);
  276.         if (ret)
  277.         {
  278.             PVFS_perror_gossip("PVFS_sys_wait call", ret);
  279.             error = ret;
  280.         }
  281.     }
  282.  
  283.     PINT_sys_release(op_id);
  284.     return error;
  285. }
  286.  
  287. static PINT_sm_action create_dspace_create_failure(
  288.     struct PINT_smcb *smcb, job_status_s *js_p)
  289. {
  290.     PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
  291.     sm_p->u.create.stored_error_code = js_p->error_code;
  292.  
  293.     gossip_debug(GOSSIP_CLIENT_DEBUG,
  294.                  "create state: dspace_create_failure\n");
  295.     return 1;
  296. }
  297.  
  298.  
  299. /*
  300.  * Local variables:
  301.  *  mode: c
  302.  *  c-indent-level: 4
  303.  *  c-basic-offset: 4
  304.  * End:
  305.  *
  306.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  307.  */
  308.