iPXE
Data Structures | Functions | Variables
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.

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
struct command fcmgmt_commands[] __command
 Fibre Channel management commands.

Detailed Description

Fibre Channel management commands.

Definition in file fcmgmt_cmd.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static 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.

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

                                                               {

        /* Sanity check */
        assert ( text != NULL );

        /* Find Fibre Channel port */
        *port = fc_port_find ( text );
        if ( ! *port ) {
                printf ( "\"%s\": no such port\n", text );
                return -ENODEV;
        }

        return 0;
}
static 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.

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

                                                                       {
        int rc;

        /* Sanity check */
        assert ( text != NULL );

        /* Parse port ID */
        if ( ( rc = fc_id_aton ( text, port_id ) ) != 0 ) {
                printf ( "\"%s\": invalid port ID\n", text );
                return -EINVAL;
        }

        return 0;
}
static 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.

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

Referenced by fcels_exec().

                                                                               {

        for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
                if ( strcasecmp ( (*handler)->name, text ) == 0 )
                        return 0;
        }

        printf ( "\"%s\": unrecognised ELS\n", text );
        return -ENOENT;
}
static 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.

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

                                                 {
        struct fcstat_options opts;
        struct fc_port *port;
        struct fc_peer *peer;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &fcstat_cmd, &opts ) ) != 0 )
                return rc;

        list_for_each_entry ( port, &fc_ports, list )
                fcportstat ( port );
        list_for_each_entry ( peer, &fc_peers, list )
                fcpeerstat ( peer );

        return 0;
}
static 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.

References ENODEV, fc_empty_port_id, fc_f_port_id, fc_link_ok(), FC_PORT_HAS_FABRIC, fc_ports, fcels(), fc_port::flags, id, fc_port::link, list_first_entry, memcmp(), optind, parse_fc_els_handler(), parse_options(), fcels_options::peer_port_id, fcels_options::port, printf(), fc_port::ptp_link_port_id, and rc.

                                                {
        struct fcels_options opts;
        struct fc_els_handler *handler;
        struct fc_port_id *id;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &fcels_cmd, &opts ) ) != 0 )
                return rc;

        /* Parse ELS handler */
        if ( ( rc = parse_fc_els_handler ( argv[optind], &handler ) ) != 0 )
                return rc;

        /* Use first port if no port specified */
        if ( ! opts.port ) {
                opts.port = list_first_entry ( &fc_ports, struct fc_port,
                                               list );
                if ( ! opts.port ) {
                        printf ( "No ports\n" );
                        return -ENODEV;
                }
        }

        /* Use link peer port ID if no peer port ID specified */
        id = &opts.peer_port_id;
        if ( memcmp ( id, &fc_empty_port_id, sizeof ( *id ) ) == 0 ) {
                if ( fc_link_ok ( &opts.port->link ) &&
                     ! ( opts.port->flags & FC_PORT_HAS_FABRIC ) ) {
                        id = &opts.port->ptp_link_port_id;
                } else {
                        id = &fc_f_port_id;
                }
        }

        /** Issue ELS */
        if ( ( rc = fcels ( opts.port, id, handler ) ) != 0 )
                return rc;

        return 0;
}

Variable Documentation

struct option_descriptor fcstat_opts[] = {} [static]

"fcstat" option list

Definition at line 109 of file fcmgmt_cmd.c.

struct command_descriptor fcstat_cmd [static]
Initial value:

"fcstat" command descriptor

Definition at line 112 of file fcmgmt_cmd.c.

struct option_descriptor fcels_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "port", 'p', required_argument,
                      struct fcels_options, port, parse_fc_port ),
        OPTION_DESC ( "id", 'i', required_argument,
                      struct fcels_options, peer_port_id, parse_fc_port_id ),
}

"fcels" option list

Definition at line 149 of file fcmgmt_cmd.c.

struct command_descriptor fcels_cmd [static]
Initial value:
        COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" )

"fcels" command descriptor

Definition at line 157 of file fcmgmt_cmd.c.

struct command fcmgmt_commands [] __command
Initial value:
 {
        {
                .name = "fcstat",
                .exec = fcstat_exec,
        },
        {
                .name = "fcels",
                .exec = fcels_exec,
        },
}

Fibre Channel management commands.

Definition at line 210 of file fcmgmt_cmd.c.