Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

fcmgmt_cmd.c 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <getopt.h>
  23. #include <strings.h>
  24. #include <ipxe/fc.h>
  25. #include <ipxe/fcels.h>
  26. #include <ipxe/command.h>
  27. #include <ipxe/parseopt.h>
  28. #include <ipxe/tables.h>
  29. #include <usr/fcmgmt.h>
  30. /** @file
  31. *
  32. * Fibre Channel management commands
  33. *
  34. */
  35. /**
  36. * Parse Fibre Channel port name
  37. *
  38. * @v text Text
  39. * @ret port Fibre Channel port
  40. * @ret rc Return status code
  41. */
  42. static int parse_fc_port ( char *text, struct fc_port **port ) {
  43. /* Sanity check */
  44. assert ( text != NULL );
  45. /* Find Fibre Channel port */
  46. *port = fc_port_find ( text );
  47. if ( ! *port ) {
  48. printf ( "\"%s\": no such port\n", text );
  49. return -ENODEV;
  50. }
  51. return 0;
  52. }
  53. /**
  54. * Parse Fibre Channel port ID
  55. *
  56. * @v text Text
  57. * @ret port_id Fibre Channel port ID
  58. * @ret rc Return status code
  59. */
  60. static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
  61. int rc;
  62. /* Sanity check */
  63. assert ( text != NULL );
  64. /* Parse port ID */
  65. if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
  66. printf ( "\"%s\": invalid port ID\n", text );
  67. return -EINVAL;
  68. }
  69. return 0;
  70. }
  71. /**
  72. * Parse Fibre Channel ELS handler name
  73. *
  74. * @v text Text
  75. * @ret handler Fibre Channel ELS handler
  76. * @ret rc Return status code
  77. */
  78. static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
  79. for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
  80. if ( strcasecmp ( (*handler)->name, text ) == 0 )
  81. return 0;
  82. }
  83. printf ( "\"%s\": unrecognised ELS\n", text );
  84. return -ENOENT;
  85. }
  86. /** "fcstat" options */
  87. struct fcstat_options {};
  88. /** "fcstat" option list */
  89. static struct option_descriptor fcstat_opts[] = {};
  90. /** "fcstat" command descriptor */
  91. static struct command_descriptor fcstat_cmd =
  92. COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
  93. /**
  94. * The "fcstat" command
  95. *
  96. * @v argc Argument count
  97. * @v argv Argument list
  98. * @ret rc Return status code
  99. */
  100. static int fcstat_exec ( int argc, char **argv ) {
  101. struct fcstat_options opts;
  102. struct fc_port *port;
  103. struct fc_peer *peer;
  104. int rc;
  105. /* Parse options */
  106. if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
  107. return rc;
  108. list_for_each_entry ( port, &fc_ports, list )
  109. fcportstat ( port );
  110. list_for_each_entry ( peer, &fc_peers, list )
  111. fcpeerstat ( peer );
  112. return 0;
  113. }
  114. /** "fcels" options */
  115. struct fcels_options {
  116. /** Fibre Channel port */
  117. struct fc_port *port;
  118. /** Fibre Channel peer port ID */
  119. struct fc_port_id peer_port_id;
  120. };
  121. /** "fcels" option list */
  122. static struct option_descriptor fcels_opts[] = {
  123. OPTION_DESC ( "port", 'p', required_argument,
  124. struct fcels_options, port, parse_fc_port ),
  125. OPTION_DESC ( "id", 'i', required_argument,
  126. struct fcels_options, peer_port_id, parse_fc_port_id ),
  127. };
  128. /** "fcels" command descriptor */
  129. static struct command_descriptor fcels_cmd =
  130. COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
  131. /**
  132. * The "fcels" command
  133. *
  134. * @v argc Argument count
  135. * @v argv Argument list
  136. * @ret rc Return status code
  137. */
  138. static int fcels_exec ( int argc, char **argv ) {
  139. struct fcels_options opts;
  140. struct fc_els_handler *handler;
  141. struct fc_port_id *id;
  142. int rc;
  143. /* Parse options */
  144. if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
  145. return rc;
  146. /* Parse ELS handler */
  147. if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
  148. return rc;
  149. /* Use first port if no port specified */
  150. if ( ! opts.port ) {
  151. opts.port = list_first_entry ( &fc_ports, struct fc_port,
  152. list );
  153. if ( ! opts.port ) {
  154. printf ( "No ports\n" );
  155. return -ENODEV;
  156. }
  157. }
  158. /* Use link peer port ID if no peer port ID specified */
  159. id = &opts.peer_port_id;
  160. if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
  161. if ( fc_link_ok ( &opts.port->link ) &&
  162. ! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
  163. id = &opts.port->ptp_link_port_id;
  164. } else {
  165. id = &fc_f_port_id;
  166. }
  167. }
  168. /** Issue ELS */
  169. if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
  170. return rc;
  171. return 0;
  172. }
  173. /** Fibre Channel management commands */
  174. struct command fcmgmt_commands[] __command = {
  175. {
  176. .name = "fcstat",
  177. .exec = fcstat_exec,
  178. },
  179. {
  180. .name = "fcels",
  181. .exec = fcels_exec,
  182. },
  183. };