Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:12.2:PowerPC
open-fcoe
fcoe-utils-rc1-update
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fcoe-utils-rc1-update of Package open-fcoe
fixes for RC1 From: Vasu Dev <vasu.dev@intel.com> This brings up SP1 to this open-fcoe commit:- commit 9403c2aaac0b79d0d236ef9413cc88b7d6f7f04e Author: Robert Love <robert.w.love@intel.com> Date: Fri Mar 12 16:41:32 2010 -0800 fcoe-utils: Increment fcoe-utils version from 1.0.11 to 1.0.12 Signed-off-by: Vasu Dev <vasu.dev@intel.com> --- INSTALL | 2 QUICKSTART | 26 ++ configure.ac | 2 fcoe_utils.c | 3 fcoe_utils.h | 3 fcoeadm.c | 160 +++++---------- fcoeadm.h | 71 ------- fcoeadm_display.c | 555 +++++++++++++++++++++++++++-------------------------- fcoeadm_display.h | 36 +++ fcoemon.c | 24 +- fcoemon_utils.c | 62 ------ fcoemon_utils.h | 15 - 13 files changed, 504 insertions(+), 690 deletions(-) delete mode 100644 fcoeadm.h create mode 100644 fcoeadm_display.h diff --git a/INSTALL b/INSTALL index c974282..9cd35f6 100644 --- a/INSTALL +++ b/INSTALL @@ -9,7 +9,7 @@ their corresponding manual pages. DEPENDENCIES * libhbalinux -* dcbd (optional configure flag to build without) +* dcbd v0.9.24 or greater (optional configure flag to build without) * autoconf * autotools diff --git a/QUICKSTART b/QUICKSTART index a1789af..766c068 100644 --- a/QUICKSTART +++ b/QUICKSTART @@ -88,8 +88,8 @@ DEPENDENCIES PROCESS -1) Obtain the source tarball from sourceforge - http://sourceforge.net/projects/e1000/files/DCB%20Tools/0.9.19/dcbd-0.9.19.tar.gz/download +1) Obtain the latest source tarball from sourceforge + http://sourceforge.net/projects/e1000/files/DCB%20Tools/ 2) Untar the tarball and change into it's directory # tar -xvzf dcbd-x.y.z.tar.gz @@ -169,7 +169,7 @@ PROCESS DEPENDENCIES * libhbalinux -* dcbd (optional configure flag to build without) +* dcbd v0.9.24 or greater (optional configure flag to build without) * autoconf * autotools @@ -207,20 +207,28 @@ PROCESS This example sets up a VLAN (101) for interface eth3 and configures the system to automatically connect to storage over this interface. -1) Create a VLAN +1) Discover VLANs + # fipvlan -a + Fibre Channel Forwarders Discovered + interface | VLAN | FCF MAC + ------------------------------------ + eth3 | 101 | 00:0d:ec:a3:3a:80 + +2) Create a VLAN # cd /etc/sysconfig/network-scripts/ # cp ifcfg-eth3 ifcfg-eth3.101 + Edit ifcfg-eth3.101 so the file has the following settings, DEVICE=eth3.101 VLAN=yes ONBOOT=yes -2) Congigure fcoe for the VLAN +3) Configure fcoe for the VLAN # cd /etc/fcoe/ # cp cfg-ethx cfg-eth3.101 -3) Start dcbd and configure the VLAN interface +4) Start dcbd and configure the VLAN interface # /etc/init.d/dcbd start # dcbtool sc eth3 dcb on # dcbtool sc eth3 pfc e:1 @@ -235,12 +243,12 @@ system to automatically connect to storage over this interface. Follow the suggestions and repeatedly run the script until it states that DCB is configured correctly. -4) Start fcoe +5) Start fcoe # /etc/init.d/fcoe start - After a few moments your storage should apear (assuming everything is + After a few moments your storage should appear (assuming everything is configured correctly on the fabric) -5) Setup dcbd and fcoe to start when booting +6) Setup dcbd and fcoe to start when booting # chkconfig dcbd on # chkconfig fcoe on diff --git a/configure.ac b/configure.ac index 60817e6..517b9c2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([fcoe-utils], [1.0.11], [devel@open-fcoe.org]) +AC_INIT([fcoe-utils], [1.0.12], [devel@open-fcoe.org]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC diff --git a/fcoe_utils.c b/fcoe_utils.c index 016dc0f..506356d 100644 --- a/fcoe_utils.c +++ b/fcoe_utils.c @@ -171,6 +171,9 @@ int check_symbolic_name_for_interface(const char *symbolic_name, int rc = -EINVAL; char *symb; + if (!ifname) + return rc; + symb = get_ifname_from_symbolic_name(symbolic_name); /* diff --git a/fcoe_utils.h b/fcoe_utils.h index 3215804..3c43304 100644 --- a/fcoe_utils.h +++ b/fcoe_utils.h @@ -61,6 +61,7 @@ enum fcoe_err { NOERR = 0, /* No error */ + EFCOECONN, /* FCoE connection already exists */ ENOFCOECONN, /* No FCoE connection on interface */ EINTERR, /* Internal error */ EINVALARG, /* Invalid argument */ @@ -74,11 +75,11 @@ enum fcoe_err { }; enum fcoe_err fcoe_validate_interface(char *ifname); +enum fcoe_err fcoe_validate_fcoe_conn(char *ifname); enum fcoe_err fcoe_find_fchost(char *ifname, char *fchost, int len); int fcoe_checkdir(char *dir); int check_symbolic_name_for_interface(const char *symbolic_name, const char *ifname); char *get_ifname_from_symbolic_name(const char *symbolic_name); -int valid_ifname(const char *ifname); #endif /* _FCOE_UTILS_H_ */ diff --git a/fcoeadm.c b/fcoeadm.c index 97cd1bd..0498e27 100644 --- a/fcoeadm.c +++ b/fcoeadm.c @@ -21,10 +21,17 @@ #include <paths.h> #include <net/if.h> #include <sys/un.h> - +#include <getopt.h> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "fcoe_utils.h" #include "fcoe_utils_version.h" -#include "fcoeadm.h" #include "fcoe_clif.h" +#include "fcoeadm_display.h" static const char *optstring = "c:d:r:S:itlshv"; static struct option fcoeadm_opts[] = { @@ -40,7 +47,6 @@ static struct option fcoeadm_opts[] = { {0, 0, 0, 0} }; -struct opt_info _opt_info, *opt_info = &_opt_info; char progname[20]; static void fcoeadm_help(void) @@ -141,7 +147,6 @@ static void fcoeadm_close_cli(struct clif_sock_info *clif_info) */ static enum fcoe_err fcoeadm_open_cli(struct clif_sock_info *clif_info) { - int counter; enum fcoe_err rc = NOERR; clif_info->socket_fd = socket(PF_UNIX, SOCK_DGRAM, 0); @@ -152,7 +157,7 @@ static enum fcoe_err fcoeadm_open_cli(struct clif_sock_info *clif_info) clif_info->local.sun_family = AF_UNIX; snprintf(clif_info->local.sun_path, sizeof(clif_info->local.sun_path), - "/tmp/fcadm_clif_%d-%d", getpid(), counter++); + "/tmp/fcadm_clif_%d", getpid()); if (bind(clif_info->socket_fd, (struct sockaddr *)&clif_info->local, sizeof(clif_info->local)) < 0) { @@ -200,62 +205,6 @@ static enum fcoe_err fcoeadm_action(enum clif_action cmd, char *ifname) return rc; } -static enum fcoe_err fcoeadm_loadhba() -{ - if (HBA_STATUS_OK != HBA_LoadLibrary()) - return EHBAAPIERR; - - return NOERR; -} - -/* - * Display adapter information - */ -static enum fcoe_err fcoeadm_display_adapter_info(struct opt_info *opt_info) -{ - if (fcoeadm_loadhba()) - return EHBAAPIERR; - - display_adapter_info(opt_info); - - HBA_FreeLibrary(); - return NOERR; -} - -/* - * Display target information - */ -static enum fcoe_err fcoeadm_display_target_info(struct opt_info *opt_info) -{ - if (fcoeadm_loadhba()) - return EHBAAPIERR; - - display_target_info(opt_info); - - HBA_FreeLibrary(); - return NOERR; -} - -/* - * Display port statistics - */ -static int fcoeadm_display_port_stats(struct opt_info *opt_info) -{ - if (!opt_info->s_flag) - return -EINVAL; - - if (!opt_info->n_flag) - opt_info->n_interval = DEFAULT_STATS_INTERVAL; - - if (fcoeadm_loadhba()) - return -EINVAL; - - display_port_stats(opt_info); - - HBA_FreeLibrary(); - return 0; -} - #define MAX_ARG_LEN 32 /* @@ -271,9 +220,10 @@ static int fcoeadm_display_port_stats(struct opt_info *opt_info) */ int main(int argc, char *argv[]) { - int opt; enum clif_action cmd = CLIF_NONE; enum fcoe_err rc = NOERR; + int opt, stat_interval; + char *ifname = NULL; /* * This has to be first because the error print macro @@ -292,8 +242,6 @@ int main(int argc, char *argv[]) if (rc) goto err; - memset(opt_info, 0, sizeof(*opt_info)); - opt = getopt_long(argc, argv, optstring, fcoeadm_opts, NULL); if (opt != -1) { switch (opt) { @@ -314,16 +262,18 @@ int main(int argc, char *argv[]) break; } - strncpy(opt_info->ifname, optarg, - sizeof(opt_info->ifname)); + ifname = optarg; - if (opt == 'c') - rc = fcoe_validate_interface(opt_info->ifname); - else - rc = fcoe_validate_fcoe_conn(opt_info->ifname); + if (opt == 'c') { + rc = fcoe_validate_interface(ifname); + if (!rc && + !fcoe_validate_fcoe_conn(ifname)) + rc = EFCOECONN; + } else + rc = fcoe_validate_fcoe_conn(ifname); if (!rc) - rc = fcoeadm_action(cmd, opt_info->ifname); + rc = fcoeadm_action(cmd, ifname); break; case 'i': @@ -337,14 +287,12 @@ int main(int argc, char *argv[]) * treat it as the interface name. */ if (optind != argc) { - strncpy(opt_info->ifname, argv[optind], - sizeof(opt_info->ifname)); - - rc = fcoe_validate_fcoe_conn(opt_info->ifname); + ifname = argv[optind]; + rc = fcoe_validate_fcoe_conn(ifname); } if (!rc) - rc = fcoeadm_display_adapter_info(opt_info); + rc = display_adapter_info(ifname); break; @@ -359,16 +307,12 @@ int main(int argc, char *argv[]) * treat it as the interface name. */ if (optind != argc) { - strncpy(opt_info->ifname, argv[optind], - sizeof(opt_info->ifname)); - - rc = fcoe_validate_fcoe_conn(opt_info->ifname); + ifname = argv[optind]; + rc = fcoe_validate_fcoe_conn(ifname); } - if (!rc) { - opt_info->t_flag = 1; - rc = fcoeadm_display_target_info(opt_info); - } + if (!rc) + rc = display_target_info(ifname, DISP_TARG); break; @@ -383,16 +327,12 @@ int main(int argc, char *argv[]) * treat it as the interface name. */ if (optind != argc) { - strncpy(opt_info->ifname, argv[optind], - sizeof(opt_info->ifname)); - - rc = fcoe_validate_fcoe_conn(opt_info->ifname); + ifname = argv[optind]; + rc = fcoe_validate_fcoe_conn(ifname); } - if (!rc) { - opt_info->l_flag = 1; - rc = fcoeadm_display_target_info(opt_info); - } + if (!rc) + rc = display_target_info(ifname, DISP_LUN); break; @@ -403,25 +343,19 @@ int main(int argc, char *argv[]) } if (optind != argc) { - strncpy(opt_info->ifname, argv[optind], - sizeof(opt_info->ifname)); - - rc = fcoe_validate_fcoe_conn(opt_info->ifname); + ifname = argv[optind]; + rc = fcoe_validate_fcoe_conn(ifname); } if (!rc && ++optind != argc) { - opt_info->n_interval = atoi(argv[optind]); - if (opt_info->n_interval <= 0) + stat_interval = atoi(argv[optind]); + if (stat_interval <= 0) rc = EINVALARG; - else - opt_info->n_flag = 1; - } - - if (!rc) { - opt_info->s_flag = 1; - rc = fcoeadm_display_port_stats(opt_info); - } + } else if (!rc && optind == argc) + stat_interval = DEFAULT_STATS_INTERVAL; + if (!rc) + rc = display_port_stats(ifname, stat_interval); break; case 'v': @@ -451,9 +385,14 @@ int main(int argc, char *argv[]) err: if (rc) { switch (rc) { + case EFCOECONN: + FCOE_LOG_ERR("Connection already created on " + "interface %s\n", ifname); + break; + case ENOFCOECONN: FCOE_LOG_ERR("No connection created on " - "interface %s\n", opt_info->ifname); + "interface %s\n", ifname); break; case EINVALARG: @@ -476,8 +415,7 @@ err: break; case ENOETHDEV: - FCOE_LOG_ERR("Invalid interface name %s\n", - opt_info->ifname); + FCOE_LOG_ERR("Invalid interface name %s\n", ifname); break; case ENOSYSFS: @@ -492,6 +430,10 @@ err: FCOE_LOG_ERR("Connection to fcoemon timed out\n"); break; + case EHBAAPIERR: + FCOE_LOG_ERR("libHBAAPI or libhbalinux error\n"); + break; + case EINTERR: FCOE_LOG_ERR("Internal error\n"); break; diff --git a/fcoeadm.h b/fcoeadm.h deleted file mode 100644 index 8536fb7..0000000 --- a/fcoeadm.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright(c) 2009 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - * Maintained at www.Open-FCoE.org - */ - -#ifndef _FCOEADM_H_ -#define _FCOEADM_H_ - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/ioctl.h> -#include <linux/types.h> -#include <ctype.h> - -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <unistd.h> -#include <dirent.h> -#include <time.h> -#include <fcntl.h> -#include <malloc.h> -#include <pthread.h> -#include <limits.h> -#include <scsi/sg.h> -#include <getopt.h> -#include <byteswap.h> -#include <net/if.h> -#include "hbaapi.h" -#include "net_types.h" -#include "fc_types.h" -#include "fc_scsi.h" - -#include "fcoe_utils.h" - -struct opt_info { - char ifname[IFNAMSIZ]; - char a_flag; - char t_flag; - char l_flag; - char l_fcid_present; - HBA_UINT32 l_fcid; - char l_lun_id_present; - u_int32_t l_lun_id; - char s_flag; - char n_flag; - #define DEFAULT_STATS_INTERVAL 1 - int n_interval; /* seconds */ -}; - -void display_adapter_info(struct opt_info *opt_info); -void display_target_info(struct opt_info *opt_info); -void display_port_stats(struct opt_info *opt_info); - -#endif /* _FCOEADM_H_ */ diff --git a/fcoeadm_display.c b/fcoeadm_display.c index 8687bb3..9d5690d 100644 --- a/fcoeadm_display.c +++ b/fcoeadm_display.c @@ -17,7 +17,29 @@ * Maintained at www.Open-FCoE.org */ -#include "fcoeadm.h" +#include <sys/param.h> +#include <sys/ioctl.h> +#include <linux/types.h> +#include <ctype.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <time.h> +#include <malloc.h> +#include <pthread.h> +#include <limits.h> +#include <scsi/sg.h> +#include <byteswap.h> +#include <net/if.h> +#include <unistd.h> + +#include "net_types.h" +#include "fc_types.h" +#include "fc_scsi.h" +#include "hbaapi.h" +#include "fcoeadm_display.h" +#include "fcoe_utils.h" /* #define TEST_HBAAPI_V1 */ #ifdef TEST_HBAAPI_V1 @@ -50,6 +72,18 @@ struct sa_nameval { u_int32_t nv_val; }; +/* + * HBA and port objects are one-to-one since there + * is one host created per Ethernet port (vlan). + */ +struct hba_name_table { + HBA_HANDLE hba_handle; + HBA_ADAPTERATTRIBUTES hba_attrs; + HBA_PORTATTRIBUTES port_attrs; + int failed; + int displayed; +}; + struct sa_nameval port_states[] = { { "Not Present", HBA_PORTSTATE_UNKNOWN }, { "Online", HBA_PORTSTATE_ONLINE }, @@ -215,10 +249,8 @@ static void show_wwn(unsigned char *pWwn) sa_dump_wwn(pWwn, 8, 0); } -static void -show_hba_info(int hba_index, HBA_ADAPTERATTRIBUTES *hba_info, int flags) +static void show_hba_info(HBA_ADAPTERATTRIBUTES *hba_info) { - printf("Adapter #%d\n", hba_index); printf(" Description: %s\n", hba_info->ModelDescription); printf(" Revision: %s\n", hba_info->HardwareVersion); printf(" Manufacturer: %s\n", hba_info->Manufacturer); @@ -229,16 +261,12 @@ show_hba_info(int hba_index, HBA_ADAPTERATTRIBUTES *hba_info, int flags) printf("\n"); } -static void -show_port_info(int hba_index, int lp_index, - HBA_ADAPTERATTRIBUTES *hba_info, - HBA_PORTATTRIBUTES *lp_info) +static void show_port_info(HBA_ADAPTERATTRIBUTES *hba_info, + HBA_PORTATTRIBUTES *lp_info) { char buf[256]; int len = sizeof(buf); - printf(" Port #%d\n", lp_index); - printf(" Symbolic Name: %s\n", lp_info->PortSymbolicName); @@ -275,8 +303,7 @@ show_port_info(int hba_index, int lp_index, /* TODO: Display PortSupportedFc4Types and PortActiveFc4Types */ } -static void show_target_info(const char *symbolic_name, int hba_index, - int lp_index, int rp_index, +static void show_target_info(const char *symbolic_name, HBA_ADAPTERATTRIBUTES *hba_info, HBA_PORTATTRIBUTES *rp_info) { @@ -287,9 +314,8 @@ static void show_target_info(const char *symbolic_name, int hba_index, ifname = get_ifname_from_symbolic_name(symbolic_name); - printf("Target #%d @ %s\n", rp_index, ifname); - rc = sa_sys_read_line(rp_info->OSDeviceName, "roles", buf, sizeof(buf)); + printf(" Interface: %s\n", ifname); printf(" Roles: %s\n", buf); printf(" Node Name: 0x"); @@ -893,7 +919,8 @@ scan_device_map(HBA_HANDLE hba_handle, HBA_ADAPTERATTRIBUTES *hba_info, HBA_PORTATTRIBUTES *lp_info, HBA_PORTATTRIBUTES *rp_info, - struct opt_info *opt_info) + const char *ifname, + enum disp_style style) { HBA_STATUS status; HBA_FCP_TARGET_MAPPING *map = NULL; @@ -917,11 +944,6 @@ scan_device_map(HBA_HANDLE hba_handle, if (ep->FcpId.FcId != rp_info->PortFcId) continue; - if (opt_info->l_flag && - opt_info->l_fcid_present && - opt_info->l_lun_id_present && - ep->ScsiId.ScsiOSLun != opt_info->l_lun_id) - continue; dev = ep->ScsiId.OSDeviceName; if (strstr(dev, "/dev/") == dev) dev += 5; @@ -949,15 +971,19 @@ scan_device_map(HBA_HANDLE hba_handle, #endif if (status != HBA_STATUS_OK) continue; - if (opt_info->t_flag) { + switch (style) { + case DISP_TARG: if (!print_header) { show_short_lun_info_header(); print_header = 1; } show_short_lun_info(ep, inqbuf, &rcap_resp); - } else if (opt_info->l_flag) + break; + case DISP_LUN: show_full_lun_info(hba_handle, hba_info, lp_info, - rp_info, ep, inqbuf, &rcap_resp); + rp_info, ep, inqbuf, &rcap_resp); + break; + } #ifdef TEST_REPORT_LUNS if (i == 0) { /* only issue report luns to the first LUN */ @@ -971,25 +997,24 @@ scan_device_map(HBA_HANDLE hba_handle, } /* Newline at the end of the short lun report */ - if (opt_info->t_flag) + if (style == DISP_TARG) printf("\n"); free(map); } -static void -show_port_stats_header(struct opt_info *opt_info) +static void show_port_stats_header(const char *ifname, int interval) { printf("\n"); printf("%-7s interval: %-2d Err Inv " - "IvTx Link Cntl Input Input Output Output\n", - opt_info->ifname, opt_info->n_interval); + "IvTx Link Cntl Input Input Output Output\n", + ifname, interval); printf("Seconds TxFrames TxBytes RxFrames RxBytes " - "Frms CRC Byte Fail Reqs Requests MBytes " - "Requests MBytes\n"); + "Frms CRC Byte Fail Reqs Requests MBytes " + "Requests MBytes\n"); printf("------- --------- ------------ --------- -------------- " - "---- ---- ---- ---- ---- --------- --------- " - "--------- ---------\n"); + "---- ---- ---- ---- ---- --------- --------- " + "--------- ---------\n"); } static void @@ -1014,44 +1039,74 @@ show_port_stats_in_row(HBA_INT64 start_time, printf("\n"); } +static void hba_table_destroy(struct hba_name_table *hba_table) +{ + int i; + + /* + * This is inefficiant as is closes adapter handles + * (presumedly 0) that weren't open. However, it allows + * us to avoid maintaining a count. + */ + for (i = 0 ; i < MAX_HBA_COUNT ; i++) + HBA_CloseAdapter(hba_table[i].hba_handle); +} -void -display_port_stats(struct opt_info *opt_info) +static enum fcoe_err fcoeadm_loadhba() +{ + if (HBA_STATUS_OK != HBA_LoadLibrary()) + return EHBAAPIERR; + + return NOERR; +} + +/* + * This routine leaves all adapters fd's open. + */ +static int hba_table_init(struct hba_name_table *hba_table) { HBA_STATUS retval; - HBA_UINT32 hba_cnt; - HBA_HANDLE hba_handle; - HBA_ADAPTERATTRIBUTES hba_attrs; - HBA_PORTATTRIBUTES port_attrs; - HBA_PORTSTATISTICS port_stats; - HBA_FC4STATISTICS port_fc4stats; - HBA_INT64 start_time = 0; - char namebuf[1028]; - int i = 0, found = 0; + char namebuf[1024]; + int i, j, num_hbas = 0; + + /* + * Initialize the table. + */ + for (i = 0 ; i < MAX_HBA_COUNT ; i++) { + memset(&hba_table[i], 0, + sizeof(struct hba_name_table)); + } - hba_cnt = HBA_GetNumberOfAdapters(); - if (!hba_cnt) { + num_hbas = HBA_GetNumberOfAdapters(); + if (!num_hbas) { fprintf(stderr, "No FCoE interfaces created.\n"); - return; + return num_hbas; } - for (i = 0; i < hba_cnt; i++) { + /* + * Fill out the HBA table. + */ + for (i = 0; i < num_hbas ; i++) { retval = HBA_GetAdapterName(i, namebuf); if (retval != HBA_STATUS_OK) { - fprintf(stderr, "Failure of HBA_GetAdapterName: %d\n", - retval); + fprintf(stderr, + "Failure of HBA_GetAdapterName: %d\n", retval); continue; } - hba_handle = HBA_OpenAdapter(namebuf); - if (!hba_handle) { + hba_table[i].hba_handle = HBA_OpenAdapter(namebuf); + if (!hba_table[i].hba_handle) { + hba_table[i].failed = 1; fprintf(stderr, "HBA_OpenAdapter failed\n"); perror("HBA_OpenAdapter"); continue; } - retval = HBA_GetAdapterAttributes(hba_handle, &hba_attrs); + retval = HBA_GetAdapterAttributes(hba_table[i].hba_handle, + &hba_table[i].hba_attrs); if (retval != HBA_STATUS_OK) { + HBA_CloseAdapter(hba_table[i].hba_handle); + hba_table[i].failed = 1; fprintf(stderr, "HBA_GetAdapterAttributes failed, retval=%d\n", retval); @@ -1059,34 +1114,77 @@ display_port_stats(struct opt_info *opt_info) continue; } - retval = HBA_GetAdapterPortAttributes( - hba_handle, 0, &port_attrs); + retval = HBA_GetAdapterPortAttributes(hba_table[i].hba_handle, + 0, + &hba_table[i].port_attrs); if (retval != HBA_STATUS_OK) { + HBA_CloseAdapter(hba_table[i].hba_handle); + hba_table[i].failed = 1; fprintf(stderr, "HBA_GetAdapterPortAttributes failed, " - "status=%d\n", retval); + "j=%d, status=%d\n", j, retval); continue; } + } + + return num_hbas; +} + +/* + * This routine expects a valid interface name. + */ +static int get_index_for_ifname(struct hba_name_table *hba_table, + int num_hbas, const char *ifname) +{ + int i; + for (i = 0 ; i < num_hbas ; i++) { if (!check_symbolic_name_for_interface( - port_attrs.PortSymbolicName, - opt_info->ifname)) { - found = 1; - break; - } + hba_table[i].port_attrs.PortSymbolicName, + ifname)) + return i; } - if (!found) { - fprintf(stderr, "Cannot find attributes for %s\n", - opt_info->ifname); - return; + return -EINVAL; +} + +enum fcoe_err display_port_stats(const char *ifname, int interval) +{ + HBA_STATUS retval; + HBA_HANDLE hba_handle; + HBA_PORTATTRIBUTES *port_attrs; + HBA_PORTSTATISTICS port_stats; + HBA_FC4STATISTICS port_fc4stats; + HBA_INT64 start_time = 0; + struct hba_name_table hba_table[MAX_HBA_COUNT]; + enum fcoe_err rc = NOERR; + int i, num_hbas; + + if (fcoeadm_loadhba()) + return EHBAAPIERR; + + num_hbas = hba_table_init(hba_table); + + i = get_index_for_ifname(hba_table, num_hbas, ifname); + + /* + * Return error code if a valid index wasn't returned. + */ + if (i < 0) { + hba_table_destroy(hba_table); + HBA_FreeLibrary(); + return EHBAAPIERR; } + hba_handle = hba_table[i].hba_handle; + port_attrs = &hba_table[i].port_attrs; + i = 0; while (1) { unsigned int secs_left; - retval = HBA_GetPortStatistics(hba_handle, 0, &port_stats); + retval = HBA_GetPortStatistics(hba_handle, + 0, &port_stats); if (retval != HBA_STATUS_OK && retval != HBA_STATUS_ERROR_NOT_SUPPORTED) { fprintf(stderr, @@ -1097,7 +1195,7 @@ display_port_stats(struct opt_info *opt_info) if (retval == HBA_STATUS_ERROR_NOT_SUPPORTED) { fprintf(stderr, "Port Statistics not supported by %s\n", - opt_info->ifname); + ifname); break; } @@ -1105,7 +1203,7 @@ display_port_stats(struct opt_info *opt_info) start_time = port_stats.SecondsSinceLastReset; retval = HBA_GetFC4Statistics(hba_handle, - port_attrs.PortWWN, + port_attrs->PortWWN, FC_TYPE_FCP, &port_fc4stats); if (retval != HBA_STATUS_OK && @@ -1117,263 +1215,172 @@ display_port_stats(struct opt_info *opt_info) if (retval == HBA_STATUS_ERROR_NOT_SUPPORTED) { fprintf(stderr, "Port FC4 Statistics not supported by %s\n", - opt_info->ifname); + ifname); break; } if (!(i % 52)) - show_port_stats_header(opt_info); + show_port_stats_header(ifname, interval); show_port_stats_in_row(start_time, &port_stats, &port_fc4stats); i++; /* wait for the requested time interval in seconds */ - secs_left = opt_info->n_interval; + secs_left = interval; do { secs_left = sleep(secs_left); } while (secs_left); } - HBA_CloseAdapter(hba_handle); - return; -} - -static struct hba_name_table { - char SerialNumber[64]; - int index; -} hba_name_table[MAX_HBA_COUNT]; - -static int -find_hba_index(char *serial_number, int *hba_index) -{ - int i, j; - - j = sizeof(hba_name_table[0].SerialNumber) - 1; - for (i = 0; i < MAX_HBA_COUNT; i++) { - if (hba_name_table[i].index == -1) { - /* not found */ - hba_name_table[i].index = i; - /* TODO: change to sa_strncpy_safe */ - strncpy(hba_name_table[i].SerialNumber, - serial_number, j); - *hba_index = i; - return 1; /* print hba info */ - } - if (!strncmp(serial_number, - hba_name_table[i].SerialNumber, j)) { - *hba_index = hba_name_table[i].index; - return 0; /* do not print hba info */ - } - } - /* table full */ - return -1; + hba_table_destroy(hba_table); + HBA_FreeLibrary(); + return rc; } -void -display_adapter_info(struct opt_info *opt_info) +enum fcoe_err display_adapter_info(const char *ifname) { - HBA_STATUS retval; - HBA_UINT32 hba_cnt; - HBA_UINT32 lport_cnt_per_hba = 1; /* always one port per hba */ - HBA_HANDLE hba_handle; - HBA_ADAPTERATTRIBUTES hba_attrs; - HBA_PORTATTRIBUTES port_attrs; - char namebuf[1028]; - int i, j, rc; - int hba_index = -1; - int lp_index = -1; - - for (i = 0; i < MAX_HBA_COUNT; i++) { - hba_name_table[i].index = -1; - memset(hba_name_table[i].SerialNumber, 0, - sizeof(hba_name_table[i].SerialNumber)); - } + struct hba_name_table hba_table[MAX_HBA_COUNT]; + enum fcoe_err rc = NOERR; + int i, j, num_hbas = 0; - hba_cnt = HBA_GetNumberOfAdapters(); - if (!hba_cnt) { - fprintf(stderr, "No FCoE interfaces created.\n"); - return; - } + if (fcoeadm_loadhba()) + return EHBAAPIERR; - for (i = 0; i < hba_cnt; i++) { - retval = HBA_GetAdapterName(i, namebuf); - if (retval != HBA_STATUS_OK) { - fprintf(stderr, - "Failure of HBA_GetAdapterName: %d\n", retval); - continue; - } + num_hbas = hba_table_init(hba_table); - hba_handle = HBA_OpenAdapter(namebuf); - if (!hba_handle) { - fprintf(stderr, "HBA_OpenAdapter failed\n"); - perror("HBA_OpenAdapter"); + /* + * Loop through each HBA entry and for each serial number + * not already printed print the header and each sub-port + * on that adapter. + */ + for (i = 0 ; i < num_hbas ; i++) { + if (hba_table[i].failed || + hba_table[i].displayed) continue; - } - retval = HBA_GetAdapterAttributes(hba_handle, &hba_attrs); - if (retval != HBA_STATUS_OK) { - fprintf(stderr, - "HBA_GetAdapterAttributes failed, retval=%d\n", - retval); - perror("HBA_GetAdapterAttributes"); + if (ifname && check_symbolic_name_for_interface( + hba_table[i].port_attrs.PortSymbolicName, + ifname)) { + /* + * Overloading 'displayed' to indicate + * that the HBA/Port should be skipped. + */ + hba_table[i].displayed = 1; continue; } - rc = find_hba_index(hba_attrs.SerialNumber, &hba_index); - if (rc == -1) { - fprintf(stderr, - "Too many adapters. Maximum %d\n", - MAX_HBA_COUNT); - return; - } else if (rc == 1) - show_hba_info(hba_index, &hba_attrs, 0); - - for (j = 0; j < lport_cnt_per_hba; j++) { - retval = HBA_GetAdapterPortAttributes( - hba_handle, j, &port_attrs); - if (retval != HBA_STATUS_OK) { - fprintf(stderr, - "HBA_GetAdapterPortAttributes failed, " - "j=%d, status=%d\n", j, retval); + /* + * Display the adapter header. + */ + show_hba_info(&hba_table[i].hba_attrs); + + /* + * Loop through HBAs again to print sub-ports. + */ + for (j = 0; j < num_hbas ; j++) { + if (ifname && check_symbolic_name_for_interface( + hba_table[j].port_attrs.PortSymbolicName, + ifname)) { + /* + * Overloading 'displayed' to indicate + * that the HBA/Port should be skipped. + */ + hba_table[i].displayed = 1; continue; } - lp_index++; - - if (strlen(opt_info->ifname)) { - if (check_symbolic_name_for_interface( - port_attrs.PortSymbolicName, - opt_info->ifname)) - continue; + if (!strncmp(hba_table[i].hba_attrs.SerialNumber, + hba_table[j].hba_attrs.SerialNumber, + strlen(hba_table[i].hba_attrs.SerialNumber))) { + show_port_info(&hba_table[j].hba_attrs, + &hba_table[j].port_attrs); + hba_table[j].displayed = 1; } - - show_port_info(hba_index, lp_index, - &hba_attrs, &port_attrs); } - HBA_CloseAdapter(hba_handle); } + + hba_table_destroy(hba_table); + HBA_FreeLibrary(); + + return rc; } -void -display_target_info(struct opt_info *opt_info) +enum fcoe_err display_target_info(const char *ifname, + enum disp_style style) { HBA_STATUS retval; - HBA_UINT32 hba_cnt; - HBA_UINT32 lport_cnt_per_hba = 1; /* always one port per hba */ - HBA_HANDLE hba_handle; - HBA_ADAPTERATTRIBUTES hba_attrs; - HBA_PORTATTRIBUTES port_attrs; HBA_PORTATTRIBUTES rport_attrs; - char namebuf[1028]; - int i, j, rc; - int hba_index = -1; - int lp_index = -1; - int rp_index = -1; - - for (i = 0; i < MAX_HBA_COUNT; i++) { - hba_name_table[i].index = -1; - memset(hba_name_table[i].SerialNumber, 0, - sizeof(hba_name_table[i].SerialNumber)); - } + struct hba_name_table hba_table[MAX_HBA_COUNT]; + int i, target_index, num_hbas = 0; + enum fcoe_err rc = NOERR; - hba_cnt = HBA_GetNumberOfAdapters(); - if (!hba_cnt) { - fprintf(stderr, "No FCoE interfaces created.\n"); - return; - } + if (fcoeadm_loadhba()) + return EHBAAPIERR; - for (i = 0; i < hba_cnt; i++) { - retval = HBA_GetAdapterName(i, namebuf); - if (retval != HBA_STATUS_OK) { - fprintf(stderr, - "Failure of HBA_GetAdapterName: %d\n", retval); - continue; - } + num_hbas = hba_table_init(hba_table); - hba_handle = HBA_OpenAdapter(namebuf); - if (!hba_handle) { - fprintf(stderr, "HBA_OpenAdapter failed\n"); - perror("HBA_OpenAdapter"); + /* + * Loop through each HBA entry and for each serial number + * not already printed print the header and each sub-port + * on that adapter. + */ + for (i = 0 ; i < num_hbas ; i++) { + if (hba_table[i].failed || + hba_table[i].displayed) continue; - } - retval = HBA_GetAdapterAttributes(hba_handle, &hba_attrs); - if (retval != HBA_STATUS_OK) { - fprintf(stderr, - "HBA_GetAdapterAttributes failed, retval=%d\n", - retval); - perror("HBA_GetAdapterAttributes"); + if (ifname && check_symbolic_name_for_interface( + hba_table[i].port_attrs.PortSymbolicName, + ifname)) { + /* + * Overloading 'displayed' to indicate + * that the HBA/Port should be skipped. + */ + hba_table[i].displayed = 1; continue; } - rc = find_hba_index(hba_attrs.SerialNumber, &hba_index); - if (rc == -1) { - fprintf(stderr, - "Too many adapters. Maximum %d\n", - MAX_HBA_COUNT); - return; - } + for (target_index = 0; + target_index < hba_table[i].port_attrs.NumberofDiscoveredPorts; + target_index++) { + + /* TODO: Second arg might be incorrect */ + retval = HBA_GetDiscoveredPortAttributes( + hba_table[i].hba_handle, + 0, target_index, + &rport_attrs); - for (j = 0; j < lport_cnt_per_hba; j++) { - retval = HBA_GetAdapterPortAttributes( - hba_handle, j, &port_attrs); if (retval != HBA_STATUS_OK) { fprintf(stderr, - "HBA_GetAdapterPortAttributes failed, " - "j=%d, status=%d\n", j, retval); + "HBA_GetDiscoveredPortAttributes " + "failed for target_index=%d, " + "status=%d\n", target_index, retval); + hba_table[i].failed = 1; continue; } - lp_index++; - - if (strlen(opt_info->ifname)) { - if (check_symbolic_name_for_interface( - port_attrs.PortSymbolicName, - opt_info->ifname)) - continue; - } - - for (rp_index = 0; - rp_index < port_attrs.NumberofDiscoveredPorts; - rp_index++) { - retval = HBA_GetDiscoveredPortAttributes( - hba_handle, j, rp_index, - &rport_attrs); - if (retval != HBA_STATUS_OK) { - fprintf(stderr, - "HBA_GetDiscoveredPortAttributes " - "failed, j=%d, for rp_index=%d, " - "status=%d\n", j, rp_index, retval); - continue; - } - - /* - * If -l option and fcid are specified in the - * command, filter out the targets do not have - * port ID equals to fcid. - */ - if (opt_info->l_flag && - opt_info->l_fcid_present && - rport_attrs.PortFcId != opt_info->l_fcid) - continue; - - /* - * Skip any targets that are not FCP targets - */ - if (is_fcp_target(&rport_attrs)) - continue; + /* + * Skip any targets that are not FCP targets + */ + if (is_fcp_target(&rport_attrs)) + continue; - show_target_info(port_attrs.PortSymbolicName, - hba_index, lp_index, rp_index, - &hba_attrs, &rport_attrs); + show_target_info( + hba_table[i].port_attrs.PortSymbolicName, + &hba_table[i].hba_attrs, + &rport_attrs); - /* - * This will print the LUN table - * under the target. - */ - scan_device_map(hba_handle, &hba_attrs, - &port_attrs, &rport_attrs, - opt_info); - } + /* + * This will print the LUN table + * under the target. + */ + scan_device_map(hba_table[i].hba_handle, + &hba_table[i].hba_attrs, + &hba_table[i].port_attrs, + &rport_attrs, ifname, style); } - HBA_CloseAdapter(hba_handle); } + + hba_table_destroy(hba_table); + HBA_FreeLibrary(); + + return rc; } diff --git a/fcoeadm_display.h b/fcoeadm_display.h new file mode 100644 index 0000000..662cfa7 --- /dev/null +++ b/fcoeadm_display.h @@ -0,0 +1,36 @@ +/* + * Copyright(c) 2010 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + * Maintained at www.Open-FCoE.org + */ + +#ifndef _FCOEADM_DISPLAY_H_ +#define _FCOEADM_DISPLAY_H_ + +#define DEFAULT_STATS_INTERVAL 1 + +enum disp_style { + DISP_LUN = 0, + DISP_TARG, +}; + +enum fcoe_err display_adapter_info(const char *ifname); +enum fcoe_err display_target_info(const char *ifname, + enum disp_style style); +enum fcoe_err display_port_stats(const char *ifname, + int stat_interval); + +#endif /* _FCOEADM_DISPLAY_H_ */ diff --git a/fcoemon.c b/fcoemon.c index ea246c2..8cb31ea 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -65,10 +65,11 @@ #define DCB_APP_0_DEFAULT_ENABLE 1 #define DCB_APP_0_DEFAULT_WILLING 1 #define FILE_NAME_LEN (NAME_MAX + 1) +#define CFG_FILE_PREFIX "cfg-" +#define DEF_CFG_FILE CFG_FILE_PREFIX "ethx" #define VLAN_DIR "/proc/net/vlan" -#define CLIF_NAME_PATH _PATH_VARRUN "dcbd/clif" #define CLIF_LOCAL_SUN_PATH _PATH_TMP "fcoemon.dcbd.%d" #define DCBD_CONNECT_TIMEOUT (10 * 1000 * 1000) /* 10 seconds */ #define DCBD_CONNECT_RETRY_TIMEOUT (1 * 1000 * 1000) /* 1 seconds */ @@ -301,9 +302,15 @@ static int fcm_read_config_files(void) (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) continue; - rc = strncmp(dp->d_name, "cfg-", strlen("cfg-")); + rc = strncmp(dp->d_name, CFG_FILE_PREFIX, + strlen(CFG_FILE_PREFIX)); if (rc) continue; + + if (!strncmp(dp->d_name, DEF_CFG_FILE, + strlen(DEF_CFG_FILE))) + continue; + next = alloc_fcoe_port(dp->d_name + 4); if (!next) { @@ -320,8 +327,6 @@ static int fcm_read_config_files(void) continue; } - next->action = FCP_WAIT; - /* FCOE_ENABLE */ rc = fcm_read_config_variable(file, val, sizeof(val), fp, "FCOE_ENABLE"); @@ -724,7 +729,6 @@ void fcm_process_link_msg(struct ifinfomsg *ip, int len, unsigned type) u_int8_t operstate; u_int64_t mac; int is_vlan; - int dcb_required_cnt; mac = is_vlan = 0; operstate = IF_OPER_UNKNOWN; @@ -908,7 +912,6 @@ static int fcm_link_buf_check(size_t read_len) return 0; } - static void fcm_fcoe_init(void) { if (fcm_read_config_files()) @@ -1014,7 +1017,7 @@ static int fcm_dcbd_connect(void) memset(&dest, 0, sizeof(dest)); dest.sun_family = PF_UNIX; snprintf(dest.sun_path, sizeof(dest.sun_path), - CLIF_NAME_PATH); + LLDP_CLIF_SOCK); rc = connect(fd, (struct sockaddr *)&dest, sizeof(dest)); if (rc < 0) { FCM_LOG_ERR(errno, "clif connect failed"); @@ -1875,7 +1878,6 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p) static void fcm_netif_advance(struct fcm_netif *ff) { char buf[80], params[30]; - int old_qos_mask; ASSERT(ff); ASSERT(fcm_clif); @@ -2018,7 +2020,7 @@ static void fcm_handle_changes() fcm_fcoe_action(ff, p); - p->action = FCP_WAIT; + fcp_set_next_action(p, FCP_WAIT); next_port: p = p->next; } @@ -2037,7 +2039,6 @@ static void fcm_usage(void) static void fcm_sig(int sig) { - fcm_dcbd_shutdown(); sa_select_exit(); } @@ -2341,11 +2342,12 @@ int main(int argc, char **argv) sa_log_flags = 0; openlog(sa_log_prefix, LOG_CONS, LOG_DAEMON); - while ((c = getopt_long(argc, argv, "fd:hv", + while ((c = getopt_long(argc, argv, "fdhv", fcm_options, NULL)) != -1) { switch (c) { case 'f': fcm_fg = 1; + break; case 'd': fcoe_config.debug = 1; break; diff --git a/fcoemon_utils.c b/fcoemon_utils.c index 74353e0..5f1cd10 100644 --- a/fcoemon_utils.c +++ b/fcoemon_utils.c @@ -469,23 +469,6 @@ static struct sa_sel_state { TAILQ_HEAD(, sa_defer_ent) ts_defer_list; } sa_sel_state; -static void -sa_select_call_deferred_funcs(void) -{ - struct sa_sel_state *ss = &sa_sel_state; - struct sa_defer_ent *de, *de_next; - - de = ss->ts_defer_list.tqh_first; - TAILQ_INIT(&ss->ts_defer_list); - - for (; de != NULL; de = de_next) { - de_next = de->de_next.tqe_next; - if (de->de_func != NULL) - (*de->de_func)(de->de_arg); - free(de); - } -} - int sa_select_loop(void) { struct sa_sel_state *ss = &sa_sel_state; @@ -502,14 +485,7 @@ int sa_select_loop(void) sa_timer_check(&tval); if (ss->ts_exit) break; - if (ss->ts_defer_list.tqh_first != NULL) { - /* - * If a timer or deferred function added a new deferred - * function, just poll through select (zero-timeout). - */ - tval.tv_sec = tval.tv_usec = 0; - tvp = &tval; - } else if (tval.tv_sec == 0 && tval.tv_usec == 0) + if (tval.tv_sec == 0 && tval.tv_usec == 0) tvp = NULL; else tvp = &tval; @@ -552,8 +528,6 @@ int sa_select_loop(void) } if (ss->ts_callback != NULL) (*ss->ts_callback)(); - if (ss->ts_defer_list.tqh_first != NULL) - sa_select_call_deferred_funcs(); } return 0; } @@ -654,40 +628,6 @@ sa_select_set_callback(void (*cb)(void)) } /* - * Add a deferred function call. - */ -void * -sa_select_add_deferred_callback(void (*func)(void *), void *arg) -{ - struct sa_sel_state *ss = &sa_sel_state; - struct sa_defer_ent *de; - - ASSERT(func != NULL); - - de = malloc(sizeof(*de)); - if (de != NULL) { - de->de_func = func; - de->de_arg = arg; - if (ss->ts_defer_list.tqh_first == NULL) - TAILQ_INIT(&ss->ts_defer_list); - TAILQ_INSERT_TAIL(&ss->ts_defer_list, de, de_next); - } - - return de; -} - -/* - * Delete (cancel) a deferred function call. - */ -void -sa_select_del_deferred_callback(void *handle) -{ - struct sa_defer_ent *de = handle; - - de->de_func = NULL; -} - -/* * Cause select loop to exit. * This is invoked from a handler which wants the select loop to return * after the handler is finished. For example, during receipt of a network diff --git a/fcoemon_utils.h b/fcoemon_utils.h index 4a4546f..35ab19e 100644 --- a/fcoemon_utils.h +++ b/fcoemon_utils.h @@ -230,21 +230,6 @@ int sa_select_loop(void); void sa_select_set_callback(void (*)(void)); /* - * Add a deferred function call. The function is called at the start - * of the next select loop cycle. - * Returns a handle to the deferred call object on success, or NULL on memory - * allocation failure. - */ -void *sa_select_add_deferred_callback(void (*func)(void *), void *arg); - -/* - * Delete a deferred function call. - * Takes the handle returned by sa_select_add_deferred_callback as an argument. - */ -void sa_select_del_deferred_callback(void *handle); - - -/* * Add a callback to handle files which are ready for receive, transmit, * or to handle exceptions. */
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor