Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

fcmgmt_cmd.c 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdio.h>
  25. #include <errno.h>
  26. #include <getopt.h>
  27. #include <strings.h>
  28. #include <ipxe/fc.h>
  29. #include <ipxe/fcels.h>
  30. #include <ipxe/command.h>
  31. #include <ipxe/parseopt.h>
  32. #include <ipxe/tables.h>
  33. #include <usr/fcmgmt.h>
  34. /** @file
  35. *
  36. * Fibre Channel management commands
  37. *
  38. */
  39. /**
  40. * Parse Fibre Channel port name
  41. *
  42. * @v text Text
  43. * @ret port Fibre Channel port
  44. * @ret rc Return status code
  45. */
  46. static int parse_fc_port ( char *text, struct fc_port **port ) {
  47. /* Sanity check */
  48. assert ( text != NULL );
  49. /* Find Fibre Channel port */
  50. *port = fc_port_find ( text );
  51. if ( ! *port ) {
  52. printf ( "\"%s\": no such port\n", text );
  53. return -ENODEV;
  54. }
  55. return 0;
  56. }
  57. /**
  58. * Parse Fibre Channel port ID
  59. *
  60. * @v text Text
  61. * @ret port_id Fibre Channel port ID
  62. * @ret rc Return status code
  63. */
  64. static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
  65. int rc;
  66. /* Sanity check */
  67. assert ( text != NULL );
  68. /* Parse port ID */
  69. if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
  70. printf ( "\"%s\": invalid port ID\n", text );
  71. return -EINVAL;
  72. }
  73. return 0;
  74. }
  75. /**
  76. * Parse Fibre Channel ELS handler name
  77. *
  78. * @v text Text
  79. * @ret handler Fibre Channel ELS handler
  80. * @ret rc Return status code
  81. */
  82. static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
  83. for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
  84. if ( strcasecmp ( (*handler)->name, text ) == 0 )
  85. return 0;
  86. }
  87. printf ( "\"%s\": unrecognised ELS\n", text );
  88. return -ENOENT;
  89. }
  90. /** "fcstat" options */
  91. struct fcstat_options {};
  92. /** "fcstat" option list */
  93. static struct option_descriptor fcstat_opts[] = {};
  94. /** "fcstat" command descriptor */
  95. static struct command_descriptor fcstat_cmd =
  96. COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
  97. /**
  98. * The "fcstat" command
  99. *
  100. * @v argc Argument count
  101. * @v argv Argument list
  102. * @ret rc Return status code
  103. */
  104. static int fcstat_exec ( int argc, char **argv ) {
  105. struct fcstat_options opts;
  106. struct fc_port *port;
  107. struct fc_peer *peer;
  108. int rc;
  109. /* Parse options */
  110. if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
  111. return rc;
  112. list_for_each_entry ( port, &fc_ports, list )
  113. fcportstat ( port );
  114. list_for_each_entry ( peer, &fc_peers, list )
  115. fcpeerstat ( peer );
  116. return 0;
  117. }
  118. /** "fcels" options */
  119. struct fcels_options {
  120. /** Fibre Channel port */
  121. struct fc_port *port;
  122. /** Fibre Channel peer port ID */
  123. struct fc_port_id peer_port_id;
  124. };
  125. /** "fcels" option list */
  126. static struct option_descriptor fcels_opts[] = {
  127. OPTION_DESC ( "port", 'p', required_argument,
  128. struct fcels_options, port, parse_fc_port ),
  129. OPTION_DESC ( "id", 'i', required_argument,
  130. struct fcels_options, peer_port_id, parse_fc_port_id ),
  131. };
  132. /** "fcels" command descriptor */
  133. static struct command_descriptor fcels_cmd =
  134. COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
  135. /**
  136. * The "fcels" command
  137. *
  138. * @v argc Argument count
  139. * @v argv Argument list
  140. * @ret rc Return status code
  141. */
  142. static int fcels_exec ( int argc, char **argv ) {
  143. struct fcels_options opts;
  144. struct fc_els_handler *handler;
  145. struct fc_port_id *id;
  146. int rc;
  147. /* Parse options */
  148. if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
  149. return rc;
  150. /* Parse ELS handler */
  151. if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
  152. return rc;
  153. /* Use first port if no port specified */
  154. if ( ! opts.port ) {
  155. opts.port = list_first_entry ( &fc_ports, struct fc_port,
  156. list );
  157. if ( ! opts.port ) {
  158. printf ( "No ports\n" );
  159. return -ENODEV;
  160. }
  161. }
  162. /* Use link peer port ID if no peer port ID specified */
  163. id = &opts.peer_port_id;
  164. if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
  165. if ( fc_link_ok ( &opts.port->link ) &&
  166. ! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
  167. id = &opts.port->ptp_link_port_id;
  168. } else {
  169. id = &fc_f_port_id;
  170. }
  171. }
  172. /** Issue ELS */
  173. if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
  174. return rc;
  175. return 0;
  176. }
  177. /** Fibre Channel management commands */
  178. struct command fcmgmt_commands[] __command = {
  179. {
  180. .name = "fcstat",
  181. .exec = fcstat_exec,
  182. },
  183. {
  184. .name = "fcels",
  185. .exec = fcels_exec,
  186. },
  187. };