iPXE
fcmgmt_cmd.c File Reference

Fibre Channel management commands. More...

#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <strings.h>
#include <ipxe/fc.h>
#include <ipxe/fcels.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/tables.h>
#include <usr/fcmgmt.h>

Go to the source code of this file.

Data Structures

struct  fcstat_options
 "fcstat" options More...
struct  fcels_options
 "fcels" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int parse_fc_port (char *text, struct fc_port **port)
 Parse Fibre Channel port name.
static int parse_fc_port_id (char *text, struct fc_port_id *port_id)
 Parse Fibre Channel port ID.
static int parse_fc_els_handler (char *text, struct fc_els_handler **handler)
 Parse Fibre Channel ELS handler name.
static int fcstat_exec (int argc, char **argv)
 The "fcstat" command.
static int fcels_exec (int argc, char **argv)
 The "fcels" command.
 COMMAND (fcstat, fcstat_exec)
 Fibre Channel management commands.
 COMMAND (fcels, fcels_exec)

Variables

static struct option_descriptor fcstat_opts [] = {}
 "fcstat" option list
static struct command_descriptor fcstat_cmd
 "fcstat" command descriptor
static struct option_descriptor fcels_opts []
 "fcels" option list
static struct command_descriptor fcels_cmd
 "fcels" command descriptor

Detailed Description

Fibre Channel management commands.

Definition in file fcmgmt_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ parse_fc_port()

int parse_fc_port ( char * text,
struct fc_port ** port )
static

Parse Fibre Channel port name.

Parameters
textText
Return values
portFibre Channel port
rcReturn status code

Definition at line 50 of file fcmgmt_cmd.c.

50 {
51
52 /* Sanity check */
53 assert ( text != NULL );
54
55 /* Find Fibre Channel port */
56 *port = fc_port_find ( text );
57 if ( ! *port ) {
58 printf ( "\"%s\": no such port\n", text );
59 return -ENODEV;
60 }
61
62 return 0;
63}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 port
Port number.
Definition CIB_PRM.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
struct fc_port * fc_port_find(const char *name)
Find Fibre Channel port by name.
Definition fc.c:1224
#define ENODEV
No such device.
Definition errno.h:510
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References assert, ENODEV, fc_port_find(), NULL, port, and printf().

◆ parse_fc_port_id()

int parse_fc_port_id ( char * text,
struct fc_port_id * port_id )
static

Parse Fibre Channel port ID.

Parameters
textText
Return values
port_idFibre Channel port ID
rcReturn status code

Definition at line 72 of file fcmgmt_cmd.c.

72 {
73 int rc;
74
75 /* Sanity check */
76 assert ( text != NULL );
77
78 /* Parse port ID */
79 if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
80 printf ( "\"%s\": invalid port ID\n", text );
81 return -EINVAL;
82 }
83
84 return 0;
85}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int fc_id_aton(const char *id_text, struct fc_port_id *id)
Parse Fibre Channel port ID.
Definition fc.c:107
#define EINVAL
Invalid argument.
Definition errno.h:429

References assert, EINVAL, fc_id_aton(), NULL, printf(), and rc.

◆ parse_fc_els_handler()

int parse_fc_els_handler ( char * text,
struct fc_els_handler ** handler )
static

Parse Fibre Channel ELS handler name.

Parameters
textText
Return values
handlerFibre Channel ELS handler
rcReturn status code

Definition at line 94 of file fcmgmt_cmd.c.

94 {
95
97 if ( strcasecmp ( (*handler)->name, text ) == 0 )
98 return 0;
99 }
100
101 printf ( "\"%s\": unrecognised ELS\n", text );
102 return -ENOENT;
103}
#define FC_ELS_HANDLERS
Fibre Channel ELS handler table.
Definition fcels.h:381
#define ENOENT
No such file or directory.
Definition errno.h:515
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition string.c:209
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References ENOENT, FC_ELS_HANDLERS, for_each_table_entry, printf(), and strcasecmp().

Referenced by fcels_exec().

◆ fcstat_exec()

int fcstat_exec ( int argc,
char ** argv )
static

The "fcstat" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 122 of file fcmgmt_cmd.c.

122 {
123 struct fcstat_options opts;
124 struct fc_port *port;
125 struct fc_peer *peer;
126 int rc;
127
128 /* Parse options */
129 if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
130 return rc;
131
133 fcportstat ( port );
135 fcpeerstat ( peer );
136
137 return 0;
138}
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
struct list_head fc_peers
struct list_head fc_ports
void fcportstat(struct fc_port *port)
Print status of Fibre Channel port.
Definition fcmgmt.c:45
void fcpeerstat(struct fc_peer *peer)
Print status of Fibre Channel peer.
Definition fcmgmt.c:68
static struct command_descriptor fcstat_cmd
"fcstat" command descriptor
Definition fcmgmt_cmd.c:112
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
A Fibre Channel peer.
Definition fc.h:341
struct list_head list
List of all peers.
Definition fc.h:345
A Fibre Channel port.
Definition fc.h:253
"fcstat" options
Definition fcmgmt_cmd.c:106

References fc_peers, fc_ports, fcpeerstat(), fcportstat(), fcstat_cmd, fc_peer::list, list_for_each_entry, opts, parse_options(), peer, port, and rc.

Referenced by COMMAND().

◆ fcels_exec()

int fcels_exec ( int argc,
char ** argv )
static

The "fcels" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Issue ELS

Definition at line 167 of file fcmgmt_cmd.c.

167 {
168 struct fcels_options opts;
169 struct fc_els_handler *handler;
170 struct fc_port_id *id;
171 int rc;
172
173 /* Parse options */
174 if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
175 return rc;
176
177 /* Parse ELS handler */
178 if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
179 return rc;
180
181 /* Use first port if no port specified */
182 if ( ! opts.port ) {
183 opts.port = list_first_entry ( &fc_ports, struct fc_port,
184 list );
185 if ( ! opts.port ) {
186 printf ( "No ports\n" );
187 return -ENODEV;
188 }
189 }
190
191 /* Use link peer port ID if no peer port ID specified */
192 id = &opts.peer_port_id;
193 if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
194 if ( fc_link_ok ( &opts.port->link ) &&
195 ! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
196 id = &opts.port->ptp_link_port_id;
197 } else {
198 id = &fc_f_port_id;
199 }
200 }
201
202 /** Issue ELS */
203 if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
204 return rc;
205
206 return 0;
207}
uint8_t id
Request identifier.
Definition ena.h:1
struct fc_port_id fc_f_port_id
F_Port contoller port ID.
Definition fc.c:68
struct fc_port_id fc_empty_port_id
Unassigned port ID.
Definition fc.c:65
@ FC_PORT_HAS_FABRIC
Port is attached to a fabric.
Definition fc.h:293
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition fc.h:109
int fcels(struct fc_port *port, struct fc_port_id *peer_port_id, struct fc_els_handler *handler)
Issue Fibre Channel ELS.
Definition fcmgmt.c:105
static struct command_descriptor fcels_cmd
"fcels" command descriptor
Definition fcmgmt_cmd.c:157
static int parse_fc_els_handler(char *text, struct fc_els_handler **handler)
Parse Fibre Channel ELS handler name.
Definition fcmgmt_cmd.c:94
int optind
Current option index.
Definition getopt.c:52
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition list.h:334
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
A Fibre Channel extended link services handler.
Definition fcels.h:353
A Fibre Channel port identifier.
Definition fc.h:38
"fcels" options
Definition fcmgmt_cmd.c:141

References ENODEV, fc_empty_port_id, fc_f_port_id, fc_link_ok(), FC_PORT_HAS_FABRIC, fc_ports, fcels(), fcels_cmd, id, list_first_entry, memcmp(), optind, opts, parse_fc_els_handler(), parse_options(), printf(), and rc.

Referenced by COMMAND().

◆ COMMAND() [1/2]

COMMAND ( fcstat ,
fcstat_exec  )

Fibre Channel management commands.

References fcstat_exec().

◆ COMMAND() [2/2]

COMMAND ( fcels ,
fcels_exec  )

References fcels(), and fcels_exec().

Variable Documentation

◆ fcstat_opts

struct option_descriptor fcstat_opts[] = {}
static

"fcstat" option list

Definition at line 109 of file fcmgmt_cmd.c.

109{};

◆ fcstat_cmd

struct command_descriptor fcstat_cmd
static
Initial value:
=
static struct option_descriptor fcstat_opts[]
"fcstat" option list
Definition fcmgmt_cmd.c:109
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"fcstat" command descriptor

Definition at line 112 of file fcmgmt_cmd.c.

Referenced by fcstat_exec().

◆ fcels_opts

struct option_descriptor fcels_opts[]
static
Initial value:
= {
struct fcels_options, peer_port_id, parse_fc_port_id ),
}
static int parse_fc_port(char *text, struct fc_port **port)
Parse Fibre Channel port name.
Definition fcmgmt_cmd.c:50
static int parse_fc_port_id(char *text, struct fc_port_id *port_id)
Parse Fibre Channel port ID.
Definition fcmgmt_cmd.c:72
@ required_argument
Option requires an argument.
Definition getopt.h:19
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"fcels" option list

Definition at line 149 of file fcmgmt_cmd.c.

149 {
150 OPTION_DESC ( "port", 'p', required_argument,
152 OPTION_DESC ( "id", 'i', required_argument,
153 struct fcels_options, peer_port_id, parse_fc_port_id ),
154};

◆ fcels_cmd

struct command_descriptor fcels_cmd
static
Initial value:
=
COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" )
static struct option_descriptor fcels_opts[]
"fcels" option list
Definition fcmgmt_cmd.c:149

"fcels" command descriptor

Definition at line 157 of file fcmgmt_cmd.c.

Referenced by fcels_exec().