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 / io / trove / trove-mgmt.c < prev    next >
C/C++ Source or Header  |  2009-09-02  |  8KB  |  306 lines

  1. /*
  2.  * (C) 2002 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #include <assert.h>
  8.  
  9. #include "gossip.h"
  10. #include "trove.h"
  11. #include "trove-internal.h"
  12. #include "gen-locks.h"
  13. #include "trove-handle-mgmt/trove-handle-mgmt.h"
  14.  
  15. TROVE_method_callback global_trove_method_callback;
  16.  
  17. static TROVE_method_id TROVE_default_method(TROVE_coll_id id);
  18.  
  19. extern struct TROVE_mgmt_ops dbpf_mgmt_ops;
  20. extern struct TROVE_mgmt_ops dbpf_mgmt_direct_ops;
  21. extern struct TROVE_dspace_ops dbpf_dspace_ops;
  22. extern struct TROVE_keyval_ops dbpf_keyval_ops;
  23. extern struct TROVE_bstream_ops dbpf_bstream_ops;
  24. extern struct TROVE_context_ops dbpf_context_ops;
  25.  
  26. extern struct TROVE_bstream_ops alt_aio_bstream_ops;
  27. extern struct TROVE_bstream_ops null_aio_bstream_ops;
  28. extern struct TROVE_bstream_ops dbpf_bstream_direct_ops;
  29.  
  30. /* currently we only have one method for these tables to refer to */
  31. struct TROVE_mgmt_ops *mgmt_method_table[] =
  32. {
  33.     &dbpf_mgmt_ops,
  34.     &dbpf_mgmt_ops, /* alt-aio */
  35.     &dbpf_mgmt_ops, /* null-aio */
  36.     &dbpf_mgmt_direct_ops  /* direct-io */
  37.  
  38. };
  39.  
  40. struct TROVE_dspace_ops *dspace_method_table[] =
  41. {
  42.     &dbpf_dspace_ops,
  43.     &dbpf_dspace_ops, /* alt-aio */
  44.     &dbpf_dspace_ops, /* null-aio */
  45.     &dbpf_dspace_ops  /* direct-io */
  46. };
  47.  
  48. struct TROVE_keyval_ops *keyval_method_table[] =
  49. {
  50.     &dbpf_keyval_ops,
  51.     &dbpf_keyval_ops, /* alt-aio */
  52.     &dbpf_keyval_ops, /* null-aio */
  53.     &dbpf_keyval_ops  /* direct-io */
  54. };
  55.  
  56. struct TROVE_bstream_ops *bstream_method_table[] =
  57. {
  58.     &dbpf_bstream_ops,
  59.     &alt_aio_bstream_ops,
  60.     &null_aio_bstream_ops,
  61.     &dbpf_bstream_direct_ops
  62. };
  63.  
  64. struct TROVE_context_ops *context_method_table[] =
  65. {
  66.     &dbpf_context_ops,
  67.     &dbpf_context_ops, /* alt-aio */
  68.     &dbpf_context_ops, /* null-aio */
  69.     &dbpf_context_ops  /* direct-io */
  70. };
  71.  
  72. /* trove_init_mutex, trove_init_status
  73.  *
  74.  * These two are used to ensure that trove is only initialized once.
  75.  *
  76.  * A program is erroneous if it performs trove operations before calling
  77.  * trove_initialize(), and we don't try to help in that case.  We do,
  78.  * however, make sure that we don't destroy anything if initialize is called
  79.  * more than once.
  80.  */
  81. static gen_mutex_t trove_init_mutex = GEN_MUTEX_INITIALIZER;
  82. static int trove_init_status = 0;
  83.  
  84. /* Returns -TROVE_EALREADY on failure (already initialized), 1 on
  85.  * success.  This is in keeping with the "1 is immediate succcess"
  86.  * semantic for return values used throughout trove.
  87.  */
  88. int trove_initialize(TROVE_method_id method_id,
  89.                      TROVE_method_callback method_callback,
  90.                      char *data_path,
  91.                       char *meta_path,
  92.                      TROVE_ds_flags flags)
  93. {
  94.     int ret = -TROVE_EALREADY;
  95.  
  96.     gen_mutex_lock(&trove_init_mutex);
  97.     if (trove_init_status)
  98.     {
  99.         return ret;
  100.     }
  101.  
  102.     ret = trove_handle_mgmt_initialize();
  103.     if (ret == -1)
  104.     {
  105.         return ret;
  106.     }
  107.  
  108.     if(!method_callback)
  109.     {
  110.         global_trove_method_callback = TROVE_default_method;
  111.     }
  112.     else
  113.     {
  114.         global_trove_method_callback = method_callback;
  115.     }
  116.  
  117.     /*
  118.       for each underlying method, call its initialize function.
  119.       initialize can fail if storage name isn't valid, but we want
  120.       those op pointers to be right either way.
  121.     */
  122.     ret = mgmt_method_table[method_id]->initialize(
  123.         data_path, meta_path, flags);
  124.     if (ret > -1)
  125.     {
  126.         ret = 1;
  127.         trove_init_status = 1;
  128.     }
  129.     gen_mutex_unlock(&trove_init_mutex);
  130.     return ret;
  131. }
  132.  
  133. int trove_finalize(TROVE_method_id method_id)
  134. {
  135.     int ret = -TROVE_EALREADY;
  136.  
  137.     gen_mutex_lock(&trove_init_mutex);
  138.     if (!trove_init_status)
  139.     {
  140.         gen_mutex_unlock(&trove_init_mutex);
  141.         return ret;
  142.     }
  143.     else
  144.     {
  145.         trove_init_status = 0;
  146.     }
  147.  
  148.     ret = mgmt_method_table[method_id]->finalize();
  149.  
  150.     ret = trove_handle_mgmt_finalize();
  151.  
  152.     gen_mutex_unlock(&trove_init_mutex);
  153.  
  154.     return ((ret < 0) ? ret : 1);
  155. }
  156.  
  157. int trove_storage_create(TROVE_method_id method_id,
  158.                          char *data_path,
  159.                           char *meta_path,
  160.                          void *user_ptr,
  161.                          TROVE_op_id *out_op_id_p)
  162. {
  163.     int ret = mgmt_method_table[method_id]->storage_create(
  164.               data_path, meta_path, user_ptr, out_op_id_p);
  165.  
  166.     return ((ret < 0) ? ret : 1);
  167. }
  168.  
  169.  
  170. int trove_storage_remove(TROVE_method_id method_id,
  171.                          char *data_path,
  172.                           char *meta_path,
  173.                          void *user_ptr,
  174.                          TROVE_op_id *out_op_id_p)
  175. {
  176.     int ret = mgmt_method_table[method_id]->storage_remove(
  177.                   data_path, meta_path, user_ptr, out_op_id_p);
  178.  
  179.     return ((ret < 0) ? ret : 1);
  180. }
  181.  
  182. int trove_collection_create(char *collname,
  183.                             TROVE_coll_id new_coll_id,
  184.                             void *user_ptr,
  185.                             TROVE_op_id *out_op_id_p)
  186. {
  187.     TROVE_method_id method_id;
  188.     int ret = -TROVE_EINVAL;
  189.  
  190.     if (new_coll_id == TROVE_COLL_ID_NULL)
  191.     {
  192.         gossip_err("Error: invalid collection ID requested.\n");
  193.         return ret;
  194.     }
  195.  
  196.     method_id = global_trove_method_callback(new_coll_id);
  197.     ret = mgmt_method_table[method_id]->collection_create(
  198.         collname, new_coll_id, user_ptr, out_op_id_p);
  199.  
  200.     return ((ret < 0) ? ret : 1);
  201. }
  202.  
  203. int trove_collection_remove(TROVE_method_id method_id,
  204.                             char *collname,
  205.                             void *user_ptr,
  206.                             TROVE_op_id *out_op_id_p)
  207. {
  208.     int ret = mgmt_method_table[method_id]->collection_remove(
  209.         collname, user_ptr, out_op_id_p);
  210.  
  211.     return ((ret < 0) ? ret : 1);
  212. }
  213.  
  214. int trove_collection_lookup(TROVE_method_id method_id,
  215.                             char *collname,
  216.                             TROVE_coll_id *coll_id_p,
  217.                             void *user_ptr,
  218.                             TROVE_op_id *out_op_id_p)
  219. {
  220.     int ret = mgmt_method_table[method_id]->collection_lookup(
  221.         collname, coll_id_p, user_ptr, out_op_id_p);
  222.  
  223.     return (ret < 0) ? ret : 1;
  224. }
  225.  
  226. int trove_collection_iterate(TROVE_method_id method_id,
  227.                              TROVE_ds_position *inout_position_p,
  228.                              TROVE_keyval_s *name_array,
  229.                              TROVE_coll_id *coll_id_array,
  230.                              int *inout_count_p,
  231.                              TROVE_ds_flags flags,
  232.                              TROVE_vtag_s *vtag,
  233.                              void *user_ptr,
  234.                              TROVE_op_id *out_op_id_p)
  235. {
  236.     int ret = mgmt_method_table[method_id]->collection_iterate(
  237.         inout_position_p, name_array, coll_id_array, inout_count_p,
  238.         flags, vtag, user_ptr, out_op_id_p);
  239.  
  240.     return ((ret < 0) ? ret : 1);
  241. }
  242.  
  243. int trove_open_context(
  244.     TROVE_coll_id coll_id,
  245.     TROVE_context_id *context_id)
  246. {
  247.     TROVE_method_id method_id;
  248.     int ret = 0;
  249.  
  250.     method_id = global_trove_method_callback(coll_id);
  251.     if(method_id < 0)
  252.     {
  253.         return -TROVE_EINVAL;
  254.     }
  255.  
  256.     if (trove_init_status != 0)
  257.     {
  258.         ret = context_method_table[method_id]->open_context(
  259.             coll_id, context_id);
  260.     }
  261.     return ret;
  262. }
  263.  
  264. int trove_close_context(
  265.     TROVE_coll_id coll_id,
  266.     TROVE_context_id context_id)
  267. {
  268.     TROVE_method_id method_id;
  269.     int ret = 0;
  270.  
  271.     method_id = global_trove_method_callback(coll_id);
  272.     if(method_id < 0)
  273.     {
  274.         return -TROVE_EINVAL;
  275.     }
  276.  
  277.     if (trove_init_status != 0)
  278.     {
  279.         ret = context_method_table[method_id]->close_context(
  280.             coll_id, context_id);
  281.     }
  282.     return ret;
  283. }
  284.  
  285. int trove_collection_clear(
  286.     TROVE_method_id method_id,
  287.     TROVE_coll_id coll_id)
  288. {
  289.     return mgmt_method_table[method_id]->collection_clear(coll_id);
  290. }
  291.  
  292.  
  293. static TROVE_method_id TROVE_default_method(TROVE_coll_id id)
  294. {
  295.     return TROVE_METHOD_DBPF;
  296. }
  297.  
  298. /*
  299.  * Local variables:
  300.  *  c-indent-level: 4
  301.  *  c-basic-offset: 4
  302.  * End:
  303.  *
  304.  * vim: ts=8 sts=4 sw=4 expandtab
  305.  */
  306.