/src/pdsh/mod.h

https://code.google.com/ · C++ Header · 219 lines · 59 code · 30 blank · 130 comment · 0 complexity · 683a9894ea2dc74bf77c8cf148294b93 MD5 · raw file

  1. /*****************************************************************************\
  2. * $Id$
  3. *****************************************************************************
  4. * Copyright (C) 2001-2006 The Regents of the University of California.
  5. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  6. * Written by Mark Grondona <mgrondona@llnl.gov>.
  7. * UCRL-CODE-2003-005.
  8. *
  9. * This file is part of Pdsh, a parallel remote shell program.
  10. * For details, see <http://www.llnl.gov/linux/pdsh/>.
  11. *
  12. * Pdsh is free software; you can redistribute it and/or modify it under
  13. * the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. *
  17. * Pdsh is distributed in the hope that it will be useful, but WITHOUT ANY
  18. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  19. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with Pdsh; if not, write to the Free Software Foundation, Inc.,
  24. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  25. \*****************************************************************************/
  26. #ifndef _MOD_H
  27. #define _MOD_H
  28. #if HAVE_CONFIG_H
  29. # include <config.h>
  30. #endif
  31. #include "src/pdsh/opt.h"
  32. #define DEFAULT_MODULE_PRIORITY 100
  33. typedef struct module_components * mod_t;
  34. /*
  35. * Initialize the module loader interface
  36. * Returns 0 for Success and -1 for Failure.
  37. */
  38. int mod_init(void);
  39. /*
  40. * Finalize and close the module loader interface.
  41. * Cycles through list of loaded modules and runs each modules
  42. * "exit" routine if one was exported. Then frees memory associated
  43. * with the module and unloads it.
  44. *
  45. * Returns 0 for Success and -1 for Failure.
  46. */
  47. int mod_exit(void);
  48. /*
  49. * Load all modules from specified directory.
  50. * Directory must be owned by the current user and not writable
  51. * by any other user. After successfully loading each module,
  52. * the module's "init" routine is called and module command line
  53. * options are registered. The module is not loaded if init
  54. * returns < 0 or any module option cannot be registered.
  55. *
  56. * If modules are being compiled statically, the directory argument
  57. * is ignored.
  58. *
  59. * Returns 0 for Success and -1 for Failure.
  60. */
  61. int mod_load_modules(const char *dir, opt_t *opt);
  62. /*
  63. * List information about all loaded modules to stdout.
  64. */
  65. void mod_list_module_info(void);
  66. /*
  67. * Traverse through loaded modules and attempt to process
  68. * option `opt' with argument `arg.'
  69. *
  70. * Note: Only one module exporting a given option can be loaded
  71. * at a time. This is enforced on a first-come-first-served basis.
  72. */
  73. int mod_process_opt(opt_t *pdsh_opts, int opt, char *arg);
  74. /*
  75. * Traverses list of loaded modules, calling any exported "read_wcoll"
  76. * routines. Appends any returned results onto opt->wcoll.
  77. *
  78. * This routine should only be called from within pdsh/opt.c after
  79. * option processing is complete, but before mod_postop().
  80. *
  81. * Returns -1 for failure, 0 for success.
  82. *
  83. */
  84. int mod_read_wcoll(opt_t *pdsh_opts);
  85. /*
  86. * Traverse list of loaded modules and call any exported "postop" routines.
  87. * "Postop" routines in modules are typically used to filter the
  88. * working collective, as in the -v option with nodeupdown, or -i
  89. * with genders.
  90. *
  91. * Returns the total number of errors.
  92. *
  93. */
  94. int mod_postop(opt_t *pdsh_opts);
  95. /*
  96. * Search list of loaded modules for a module with given type and name.
  97. * Returns the module if found, NULL if no match.
  98. */
  99. mod_t mod_get_module(const char *type, const char *name);
  100. /*
  101. * Return the number of loaded modules of type `"type." Returns the
  102. * total number of modules if type is NULL.
  103. */
  104. int mod_count(char *type);
  105. /*
  106. * Build list of module names of type "type"
  107. * List contains all module names if type is NULL.
  108. */
  109. List mod_get_module_names(char *type);
  110. /*
  111. * Build list of module names that are loaded but not initialized
  112. */
  113. List mod_get_uninitialized_module_names (char *type);
  114. /*
  115. * Print all options provided by modules
  116. * Justify option description starting on given column.
  117. */
  118. void mod_print_all_options(int column);
  119. /*
  120. * Print options for module "mod"
  121. */
  122. void mod_print_options(mod_t mod, int descr_column);
  123. /*
  124. * Functions that may be exported by any pdsh module
  125. * via a pdsh_module_operations structure.
  126. */
  127. typedef int (*ModInitF) (void);
  128. typedef int (*ModExitF) (void);
  129. typedef hostlist_t (*ModReadWcollF) (opt_t *);
  130. typedef int (*ModPostOpF) (opt_t *);
  131. /*
  132. * Functions that may be exported by any rcmd module
  133. * via a pdsh_rcmd_operations structure.
  134. */
  135. typedef int (*RcmdInitF) (opt_t *);
  136. typedef int (*RcmdSigF) (int, void *, int);
  137. typedef int (*RcmdF) (char *, char *, char *, char *, char *,
  138. int, int *, void **);
  139. typedef int (*RcmdDestroyF) (void *);
  140. /*
  141. * Module accessor functions. Return module name, type, and
  142. * look up additional exported symbols in given module.
  143. *
  144. * All return a pointer to the desired value if successful, or NULL
  145. * on failure.
  146. */
  147. char * mod_get_name(mod_t mod);
  148. char * mod_get_type(mod_t mod);
  149. RcmdInitF mod_get_rcmd_init(mod_t mod);
  150. RcmdSigF mod_get_rcmd_signal(mod_t mod);
  151. RcmdF mod_get_rcmd(mod_t mod);
  152. RcmdDestroyF mod_get_rcmd_destroy(mod_t mod);
  153. /*
  154. * Store all module operations of a module
  155. */
  156. struct pdsh_module_operations {
  157. ModInitF init; /* Called just after module is loaded */
  158. ModExitF exit; /* Called just before module unloaded */
  159. ModReadWcollF read_wcoll; /* Called if wcoll is not initialized at
  160. end of option processing. First wcoll
  161. returned by a module will be used. */
  162. ModPostOpF postop; /* Called after argv option processing */
  163. };
  164. /*
  165. * Stores all rcmd operations of a module
  166. */
  167. struct pdsh_rcmd_operations {
  168. RcmdInitF rcmd_init;
  169. RcmdSigF rcmd_signal;
  170. RcmdF rcmd;
  171. RcmdDestroyF rcmd_destroy;
  172. };
  173. /*
  174. * Stores all information about a module
  175. */
  176. struct pdsh_module {
  177. char *type; /* module type, e.g. Jedi */
  178. char *name; /* module name, e.g. Yoda */
  179. char *author; /* module author, e.g. George Lucas */
  180. char *descr; /* module description, e.g. "Run pdsh with the force */
  181. int personality; /* personality mask for module (DSH, PCP, or DSH|PCP */
  182. struct pdsh_module_operations *mod_ops;
  183. struct pdsh_rcmd_operations *rcmd_ops;
  184. struct pdsh_module_option *opt_table;
  185. };
  186. #endif /* !_MOD_H */
  187. /*
  188. * vi: tabstop=4 shiftwidth=4 expandtab
  189. */