[Open-FCoE] [PATCH] User space management tool files layout change

Steve Ma steve.ma at intel.com
Mon Sep 22 18:11:22 UTC 2008


From: Yi Zou <yi.zou at intel.com>

This patch is to re-organize the open-fcoe directory layout so
we can apply the hbaapi vendor library code to it at present,
and apply other code in the future. The following is the proposed
layout for the future.

<open-fcoe>/README
             /kernel/ (future)
             /usr/ (current)
                   /README (current)
                   /INSTALL (future)
                   /Makefile (current)
                   /doc/ (current)
                   /etc/ (current)
                   /tools/ (current)
                         /Makefile (current)
                   /include/ (future)
                   /lib/ (future)
                         /Makefile (future)
                         /Makefile.hbaapi (future)
                         /hbaapi_src_2.2/ (added by user)
                         /libhbalinux/ (future)
                                 Makefile (future)
                         /patches/ (future)

where (current) means the item will be present after this patch is applied.
      (future) means the item will be added in the future.

Signed-off-by: Yi Zou <yi.zou at intel.com>
---

 Makefile                 |   52 -------
 README                   |   40 -----
 doc/fcoeadm.8            |   60 --------
 etc/fcoe.conf            |    3 
 etc/initd/initd.fcoe     |  118 ----------------
 usr/Makefile             |   55 ++++++--
 usr/README               |   40 +++++
 usr/doc/fcoeadm.8        |   60 ++++++++
 usr/etc/fcoe.conf        |    3 
 usr/etc/initd/initd.fcoe |  118 ++++++++++++++++
 usr/fcoeadm.c            |  336 ----------------------------------------------
 usr/tools/Makefile       |   13 ++
 usr/tools/fcoeadm.c      |  336 ++++++++++++++++++++++++++++++++++++++++++++++
 13 files changed, 617 insertions(+), 617 deletions(-)
 delete mode 100644 Makefile
 delete mode 100644 README
 delete mode 100644 doc/fcoeadm.8
 delete mode 100644 etc/fcoe.conf
 delete mode 100644 etc/initd/initd.fcoe
 create mode 100644 usr/README
 create mode 100644 usr/doc/fcoeadm.8
 create mode 100644 usr/etc/fcoe.conf
 create mode 100644 usr/etc/initd/initd.fcoe
 delete mode 100644 usr/fcoeadm.c
 create mode 100644 usr/tools/Makefile
 create mode 100644 usr/tools/fcoeadm.c

diff --git a/Makefile b/Makefile
deleted file mode 100644
index a3eadbe..0000000
--- a/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Makefile for the Open-FCoE Initiator
-#
-
-# set the following corresepondingly to your preferred locations
-DESTDIR ?= 
-
-prefix = /usr
-exec_prefix = /
-sbindir = $(exec_prefix)/sbin
-bindir = $(exec_prefix)/bin
-mandir = $(prefix)/share/man
-etcdir = /etc
-initddir = $(etcdir)/init.d
-
-MANPAGES = doc/fcoeadm.8
-PROGRAMS = usr/fcoeadm
-INSTALL = install
-
-default: all
-
-all:
-	$(MAKE) -C usr
-	
-clean:
-	$(MAKE) -C usr clean
-
-install: all install_usr
-	@echo 
-	@echo -------------------------------------------------
-	@echo Please check README file for detailed information.
-	@echo Remember to setup the FCoE config file located at: 
-	@echo -e "\t$(DESTDIR)$(etcdir)/fcoe/open-fcoe.conf"
-	@echo
-
-install_usr: install_programs install_doc install_initd
-
-install_programs:  $(PROGRAMS)
-	$(INSTALL) -d $(DESTDIR)$(sbindir)
-	$(INSTALL) -m 755 $^ $(DESTDIR)$(sbindir)
-
-install_initd:
-	$(INSTALL) -d $(DESTDIR)$(initddir)
-	$(INSTALL) -m 755 etc/initd/initd.fcoe \
-		$(DESTDIR)$(initddir)/open-fcoe
-	$(INSTALL) -d $(DESTDIR)$(etcdir)/fcoe
-	$(INSTALL) -m 644 etc/fcoe.conf \
-		$(DESTDIR)$(etcdir)/fcoe/open-fcoe.conf
-
-install_doc: $(MANPAGES)
-	$(INSTALL) -d $(DESTDIR)$(mandir)/man8
-	$(INSTALL) -m 644 $^ $(DESTDIR)$(mandir)/man8
diff --git a/README b/README
deleted file mode 100644
index e3cb26e..0000000
--- a/README
+++ /dev/null
@@ -1,40 +0,0 @@
-FCoE user-space tool
-====================
-1. fcoe init script
-This system service script will reside in /etc/init.d/open-fcoe and will be
-used to start fcoe on demand or durring boot-up. The open-fcoe init script
-will check the fcoe config file /etc/fcoe/open-fcoe.conf for the interface that
-will be used to create the FCoE instance. The open-fcoe.conf currently contains
-just one line as:
-
-HBA=<ifname>
-
-e.g., put "HBA=eth1" in open-fcoe.conf will let you use interface "eth1" for
-FCoE. By default, the installation will create a sample config file containing
-the interface "eth0", please make sure to change it accordingly after install.
-
-2. fcoeadm application
-This is the user space fcoe administration tool. It creates and destroys
-FCoE instances on a given interface name. It can also query some basic information
-about the created fc_host. Currently it has limited functionality, but we expect 
-to add more features in the near future. 
-
-Install
-=======
-To build the management tool, 
-	make 
-
-To install fcoeadm,
-	make install [DESTDIR=/sbin]
-
-DESTDIR by default is set to /sbin, you can modify Makefile to point to your
-preferreed destination directory for installation or pass to DESTDIR on the
-command line. Below are the default installation destinations:
-
-Local			Default Install Destination
-====================================================
-etc/initd/inid.fcoe	/etc/init.d/open-fcoe
-etc/fcoe.conf		/etc/fcoe/open-fcoe.conf
-usr/fcoeadm		/sbin/fcoeadm
-doc/fcoeadm.8		/usr/share/man/man8/fcoeadm.8
-doc/fcoeadm.8.gz	/usr/share/man/man8/fcoeadm.8.gz
diff --git a/doc/fcoeadm.8 b/doc/fcoeadm.8
deleted file mode 100644
index 20cde83..0000000
--- a/doc/fcoeadm.8
+++ /dev/null
@@ -1,60 +0,0 @@
-.TH FCOEADM 8 "August 21, 2008" "Open-FCoE Applications" "Open-FCoE Tools"
-.SH "NAME"
-fcoeadm \- The Fibre Channel over Ethernet (FCoE) administration tool
-.SH "SYNOPSIS"
-fcoeadm [[\fB\-c\fR|\fB\-\-create\fR] | [\fB\-d\fR|\fB\-\-destroy\fR] | [\fB\-r\fR|\fB\-\-reset\fR] | [\fB\-q\fR|\fB\-\-query\fR]] \fI<ifname>\fR]
-.P
-fcoeadm [\fB\-h\fR|\fB\-\-help\fR]
-.SH "DESCRIPTION"
-Creates, destroys, resets, or queries an FCoE instance on a given network interface.
-.SH "OPTIONS"
-.TP
-\fB\-c\fR, \fB\-\-create\fR \fI<ifname>\fR
-Creates an FCoE instance based on the given \fI<ifname>\fR. It first checks the 
-existence of /sys/module/fcoe/ to verify that the fcoe module is loaded. Then 
-the \fI<ifname>\fR is written to /sys/module/fcoe/create.
-.TP
-\fB\-d\fR, \fB\-\-destroy\fR \fI<ifname>\fR
-Destroys an FCoE instance based on the given \fI<ifname>\fR. It first checks the
-existence of /sys/module/fcoe/ to verify that fcoe module is loaded. Then
-the \fI<ifname>\fR is written to /sys/module/fcoe/destroy. 
-.TP
-\fB\-r\fR, \fB\-\-reset\fR \fI<ifname>\fR
-Resets the fc_host associated with the FCoE interface given by \fI<ifname>\fR.
-.TP
-\fB\-q\fR, \fB\-\-query\fR \fI<ifname>\fR
-Queries basic FCoE information for the given \fI<ifname>\fR. It looks for the
-corresponding fc_host under /sys/class/fc_host/. If a fc_host is found
-for the \fI<ifname>\fR, basic information such as port ID, worldwide port name,
-worldwide node name, and fabric name will be displayed.
-.TP
-\fB\-h\fR, \fB\-\-help\fR \fI<ifname>\fR
-Displays this help information.
-.TP 
-\fI<ifname>\fR
-The network interface name, such as eth0, eth1, etc.
-.SH "EXAMPLES"
-Creates an FCoE instance on eth2
-.IP 
-$ fcoeadm --create eth2
-.P
-Destroys the FCoE instance on eth2
-.IP 
-$ fcoeadm --destroy eth2
-.P
-Resets the FCoE instance on eth2
-.IP 
-$ fcoeadm --reset eth2
-.P
-Queries FCoE information on eth2
-.IP 
-$ fcoeadm --query eth2
-.SH "REPORTING BUGS"
-If you have identified a
-defect please either file a bug or engage the development mailing list at
-<http://www.Open-FCoE.org>.
-.SH "SUPPORT"
-Open-FCoE is maintained at <http://www.Open-FCoE.org>. There are resources
-available for both developers and users at that site.
-
-
diff --git a/etc/fcoe.conf b/etc/fcoe.conf
deleted file mode 100644
index b6a2b39..0000000
--- a/etc/fcoe.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-# Put the interface name that you want to use for FCoE as below, for example,
-# HBA=eth2
-HBA=eth0
diff --git a/etc/initd/initd.fcoe b/etc/initd/initd.fcoe
deleted file mode 100644
index 2d32f51..0000000
--- a/etc/initd/initd.fcoe
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/sh
-#
-# Copyright(c) 2007 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
-#
-#
-# chkconfig: 2345 92 19
-# description: OpenFC and FCoE: Fibre Channel over Ethernet SAN setup
-
-PATH=/sbin:/bin:/usr/sbin:/usr/bin
-
-HBA=
-FCOEADM=fcoeadm
-FCOE_CONF=/etc/fcoe/fcoe.conf
-
-# validates the ifname
-fcoe_gethba() {
-	HBA=
-	if [ ! -e $FCOE_CONF ]
-	then
-		echo "Open-fcoe config file $FCOE_CONF not found!"
-		return
-	fi
-	# get HBA=
-	HBA=`grep -v "#" $FCOE_CONF | grep "HBA=" | cut -f2 -d=`
-	if ifconfig $HBA &> /dev/null
-	then
-		echo "Found HBA $HBA!"
-	else
-		echo "HBA not found in $FCOE_CONF!"
-		HBA=
-	fi
-}
-# check fcoeadm
-which $FCOEADM
-if [ "$?" -eq "1" ]
-then
-	echo "$0: $FCOEADM command not installed" >&2
-	exit 1
-fi
-
-# Switch on start / stop argument
-case "$1" in
-start)
-	
-	# start fcmon
-	lsmod | grep fcoe &> dev/null
-	if [ "$?" -eq "1" ]
-	then
-		modprobe -q fcoe 2> /dev/null
-		if [ "$?" -eq "1" ]
-		then
-			echo "Failed to load FCoE driver module!"
-			exit 1
-		fi
-	fi
-	# get HBA from conf
-	fcoe_gethba
-	if [ -z "$HBA" ]
-	then
-		echo "Please setup the config file $FCOE_CONF first!"
-		$FCOEADM --create $HBA >&2
-		exit 1
-	fi
-	;;
-
-stop)
-	lsmod | grep fcoe &> dev/null
-	if [ "$?" -eq "1" ]
-	then
-		echo "Open-FCoE driver module not loaded!"
-		exit 1
-	fi
-	fcoe_gethba
-	if [ -n "$HBA" ]
-	then
-		$FCOEADM --destroy $HBA >&2
-	fi
-	;;
-
-status)
-	lsmod | grep fcoe &> dev/null
-	if [ "$?" -eq "1" ]
-	then
-		echo "Open-FCoE driver module not loaded!"
-		exit 1
-	fi
-	fcoe_gethba
-	$FCOEADM --query $HBA >&2
-	;;
-
-restart | reload)
-	$0 stop
-	$0 start
-	;;
-
-save)
-	;;
-
-*)
-	echo "Usage: $0 {start|stop|reload|restart|status}" >&2
-	exit 1
-	;;
-esac
diff --git a/usr/Makefile b/usr/Makefile
index d9b2310..554ad4b 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -1,13 +1,52 @@
-# This Makefile will work only with GNU make.
-OSNAME=$(shell uname -s)
-CFLAGS += -O2 -g -Wall -Wstrict-prototypes -I../include -D$(OSNAME)
-PROGRAMS=fcoeadm
+#
+# Makefile for the Open-FCoE Initiator
+#
 
-default: all
+# set the following corresepondingly to your preferred locations
+DESTDIR ?= 
+
+prefix = /usr
+exec_prefix = /
+sbindir = $(exec_prefix)/sbin
+bindir = $(exec_prefix)/bin
+mandir = $(prefix)/share/man
+etcdir = /etc
+initddir = $(etcdir)/init.d
 
-all: $(PROGRAMS)
+MANPAGES = doc/fcoeadm.8
+PROGRAMS = usr/fcoeadm
+INSTALL = install
 
-fcoeadm: fcoeadm.o
+default: all
 
+all:
+	$(MAKE) -C tools
+	
 clean:
-	rm -f *.o $(PROGRAMS)
+	$(MAKE) -C tools clean
+
+install: all install_tools
+	@echo 
+	@echo -------------------------------------------------
+	@echo Please check README file for detailed information.
+	@echo Remember to setup the FCoE config file located at: 
+	@echo -e "\t$(DESTDIR)$(etcdir)/fcoe/open-fcoe.conf"
+	@echo
+
+install_tools: install_programs install_doc install_initd
+
+install_programs:  $(PROGRAMS)
+	$(INSTALL) -d $(DESTDIR)$(sbindir)
+	$(INSTALL) -m 755 $^ $(DESTDIR)$(sbindir)
+
+install_initd:
+	$(INSTALL) -d $(DESTDIR)$(initddir)
+	$(INSTALL) -m 755 etc/initd/initd.fcoe \
+		$(DESTDIR)$(initddir)/open-fcoe
+	$(INSTALL) -d $(DESTDIR)$(etcdir)/fcoe
+	$(INSTALL) -m 644 etc/fcoe.conf \
+		$(DESTDIR)$(etcdir)/fcoe/open-fcoe.conf
+
+install_doc: $(MANPAGES)
+	$(INSTALL) -d $(DESTDIR)$(mandir)/man8
+	$(INSTALL) -m 644 $^ $(DESTDIR)$(mandir)/man8
diff --git a/usr/README b/usr/README
new file mode 100644
index 0000000..e3cb26e
--- /dev/null
+++ b/usr/README
@@ -0,0 +1,40 @@
+FCoE user-space tool
+====================
+1. fcoe init script
+This system service script will reside in /etc/init.d/open-fcoe and will be
+used to start fcoe on demand or durring boot-up. The open-fcoe init script
+will check the fcoe config file /etc/fcoe/open-fcoe.conf for the interface that
+will be used to create the FCoE instance. The open-fcoe.conf currently contains
+just one line as:
+
+HBA=<ifname>
+
+e.g., put "HBA=eth1" in open-fcoe.conf will let you use interface "eth1" for
+FCoE. By default, the installation will create a sample config file containing
+the interface "eth0", please make sure to change it accordingly after install.
+
+2. fcoeadm application
+This is the user space fcoe administration tool. It creates and destroys
+FCoE instances on a given interface name. It can also query some basic information
+about the created fc_host. Currently it has limited functionality, but we expect 
+to add more features in the near future. 
+
+Install
+=======
+To build the management tool, 
+	make 
+
+To install fcoeadm,
+	make install [DESTDIR=/sbin]
+
+DESTDIR by default is set to /sbin, you can modify Makefile to point to your
+preferreed destination directory for installation or pass to DESTDIR on the
+command line. Below are the default installation destinations:
+
+Local			Default Install Destination
+====================================================
+etc/initd/inid.fcoe	/etc/init.d/open-fcoe
+etc/fcoe.conf		/etc/fcoe/open-fcoe.conf
+usr/fcoeadm		/sbin/fcoeadm
+doc/fcoeadm.8		/usr/share/man/man8/fcoeadm.8
+doc/fcoeadm.8.gz	/usr/share/man/man8/fcoeadm.8.gz
diff --git a/usr/doc/fcoeadm.8 b/usr/doc/fcoeadm.8
new file mode 100644
index 0000000..20cde83
--- /dev/null
+++ b/usr/doc/fcoeadm.8
@@ -0,0 +1,60 @@
+.TH FCOEADM 8 "August 21, 2008" "Open-FCoE Applications" "Open-FCoE Tools"
+.SH "NAME"
+fcoeadm \- The Fibre Channel over Ethernet (FCoE) administration tool
+.SH "SYNOPSIS"
+fcoeadm [[\fB\-c\fR|\fB\-\-create\fR] | [\fB\-d\fR|\fB\-\-destroy\fR] | [\fB\-r\fR|\fB\-\-reset\fR] | [\fB\-q\fR|\fB\-\-query\fR]] \fI<ifname>\fR]
+.P
+fcoeadm [\fB\-h\fR|\fB\-\-help\fR]
+.SH "DESCRIPTION"
+Creates, destroys, resets, or queries an FCoE instance on a given network interface.
+.SH "OPTIONS"
+.TP
+\fB\-c\fR, \fB\-\-create\fR \fI<ifname>\fR
+Creates an FCoE instance based on the given \fI<ifname>\fR. It first checks the 
+existence of /sys/module/fcoe/ to verify that the fcoe module is loaded. Then 
+the \fI<ifname>\fR is written to /sys/module/fcoe/create.
+.TP
+\fB\-d\fR, \fB\-\-destroy\fR \fI<ifname>\fR
+Destroys an FCoE instance based on the given \fI<ifname>\fR. It first checks the
+existence of /sys/module/fcoe/ to verify that fcoe module is loaded. Then
+the \fI<ifname>\fR is written to /sys/module/fcoe/destroy. 
+.TP
+\fB\-r\fR, \fB\-\-reset\fR \fI<ifname>\fR
+Resets the fc_host associated with the FCoE interface given by \fI<ifname>\fR.
+.TP
+\fB\-q\fR, \fB\-\-query\fR \fI<ifname>\fR
+Queries basic FCoE information for the given \fI<ifname>\fR. It looks for the
+corresponding fc_host under /sys/class/fc_host/. If a fc_host is found
+for the \fI<ifname>\fR, basic information such as port ID, worldwide port name,
+worldwide node name, and fabric name will be displayed.
+.TP
+\fB\-h\fR, \fB\-\-help\fR \fI<ifname>\fR
+Displays this help information.
+.TP 
+\fI<ifname>\fR
+The network interface name, such as eth0, eth1, etc.
+.SH "EXAMPLES"
+Creates an FCoE instance on eth2
+.IP 
+$ fcoeadm --create eth2
+.P
+Destroys the FCoE instance on eth2
+.IP 
+$ fcoeadm --destroy eth2
+.P
+Resets the FCoE instance on eth2
+.IP 
+$ fcoeadm --reset eth2
+.P
+Queries FCoE information on eth2
+.IP 
+$ fcoeadm --query eth2
+.SH "REPORTING BUGS"
+If you have identified a
+defect please either file a bug or engage the development mailing list at
+<http://www.Open-FCoE.org>.
+.SH "SUPPORT"
+Open-FCoE is maintained at <http://www.Open-FCoE.org>. There are resources
+available for both developers and users at that site.
+
+
diff --git a/usr/etc/fcoe.conf b/usr/etc/fcoe.conf
new file mode 100644
index 0000000..b6a2b39
--- /dev/null
+++ b/usr/etc/fcoe.conf
@@ -0,0 +1,3 @@
+# Put the interface name that you want to use for FCoE as below, for example,
+# HBA=eth2
+HBA=eth0
diff --git a/usr/etc/initd/initd.fcoe b/usr/etc/initd/initd.fcoe
new file mode 100644
index 0000000..2d32f51
--- /dev/null
+++ b/usr/etc/initd/initd.fcoe
@@ -0,0 +1,118 @@
+#!/bin/sh
+#
+# Copyright(c) 2007 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
+#
+#
+# chkconfig: 2345 92 19
+# description: OpenFC and FCoE: Fibre Channel over Ethernet SAN setup
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+HBA=
+FCOEADM=fcoeadm
+FCOE_CONF=/etc/fcoe/fcoe.conf
+
+# validates the ifname
+fcoe_gethba() {
+	HBA=
+	if [ ! -e $FCOE_CONF ]
+	then
+		echo "Open-fcoe config file $FCOE_CONF not found!"
+		return
+	fi
+	# get HBA=
+	HBA=`grep -v "#" $FCOE_CONF | grep "HBA=" | cut -f2 -d=`
+	if ifconfig $HBA &> /dev/null
+	then
+		echo "Found HBA $HBA!"
+	else
+		echo "HBA not found in $FCOE_CONF!"
+		HBA=
+	fi
+}
+# check fcoeadm
+which $FCOEADM
+if [ "$?" -eq "1" ]
+then
+	echo "$0: $FCOEADM command not installed" >&2
+	exit 1
+fi
+
+# Switch on start / stop argument
+case "$1" in
+start)
+	
+	# start fcmon
+	lsmod | grep fcoe &> dev/null
+	if [ "$?" -eq "1" ]
+	then
+		modprobe -q fcoe 2> /dev/null
+		if [ "$?" -eq "1" ]
+		then
+			echo "Failed to load FCoE driver module!"
+			exit 1
+		fi
+	fi
+	# get HBA from conf
+	fcoe_gethba
+	if [ -z "$HBA" ]
+	then
+		echo "Please setup the config file $FCOE_CONF first!"
+		$FCOEADM --create $HBA >&2
+		exit 1
+	fi
+	;;
+
+stop)
+	lsmod | grep fcoe &> dev/null
+	if [ "$?" -eq "1" ]
+	then
+		echo "Open-FCoE driver module not loaded!"
+		exit 1
+	fi
+	fcoe_gethba
+	if [ -n "$HBA" ]
+	then
+		$FCOEADM --destroy $HBA >&2
+	fi
+	;;
+
+status)
+	lsmod | grep fcoe &> dev/null
+	if [ "$?" -eq "1" ]
+	then
+		echo "Open-FCoE driver module not loaded!"
+		exit 1
+	fi
+	fcoe_gethba
+	$FCOEADM --query $HBA >&2
+	;;
+
+restart | reload)
+	$0 stop
+	$0 start
+	;;
+
+save)
+	;;
+
+*)
+	echo "Usage: $0 {start|stop|reload|restart|status}" >&2
+	exit 1
+	;;
+esac
diff --git a/usr/fcoeadm.c b/usr/fcoeadm.c
deleted file mode 100644
index 55dd554..0000000
--- a/usr/fcoeadm.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- -- LICENSE
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <getopt.h>
-#include <dirent.h>
-#include <string.h>
-
-#define SYSFS_MOUNT	"/sys"
-#define SYSFS_NET	SYSFS_MOUNT "/class/net"
-#define SYSFS_FCHOST	SYSFS_MOUNT "/class/fc_host"
-#define SYSFS_FCOE	SYSFS_MOUNT "/module/fcoe"
-#define FCOE_CREATE	SYSFS_FCOE "/create"
-#define FCOE_DESTROY	SYSFS_FCOE "/destroy"
-
-static struct option fcoeadm_opts[] = {
-    {"create", 1, 0, 'c'},
-    {"destroy", 1, 0, 'd'},
-    {"query", 1, 0, 'q'},
-    {"reset", 1, 0, 'r'},
-    {"help", 0, 0, 'h'},
-    {0, 0, 0, 0}
-};
-
-
-void fcoeadm_help(char *name)
-{
-	fprintf(stderr, "Usage: %s\n"
-		"\t [-c|--create] ifname\n"
-		"\t [-d|--destroy] ifname\n"
-		"\t [-q|--query] ifname\n"
-		"\t [-r|--reset] ifname\n"
-		"\t [-h|--help]\n",
-		name);
-}
-
-/*
- * open and close to check if dir exists
- */
-int fcoeadm_checkdir(char *dir)
-{
-	DIR *d = NULL;
-
-	if (!dir)
-		return -EINVAL;
-	/* check if we have sysfs */
-	d = opendir(dir);
-	if (!d)
-		return -EINVAL;
-	closedir(d);
-	return 0;
-}
-/*
- * TODO - check this ifname before performing any action
- */
-int fcoeadm_check(char *ifname)
-{
-	char path[256];
-	/* check if we have sysfs */
-	if (fcoeadm_checkdir(SYSFS_MOUNT)) {
-		fprintf(stderr, "Sysfs mount point %s not found!\n",
-			SYSFS_MOUNT);
-		return -EINVAL;
-	}
-	/* check fcoe module */
-	if (fcoeadm_checkdir(SYSFS_FCOE)) {
-		fprintf(stderr, "Please make sure FCoE driver module "
-			"is loaded!\n");
-		return -EINVAL;
-	}
-	/* check target interface */
-	if (!ifname) {
-		fprintf(stderr, "Invalid interface name!\n");
-		return -EINVAL;
-	}
-	sprintf(path, "%s/%s", SYSFS_NET, ifname);
-	if (fcoeadm_checkdir(path)) {
-		fprintf(stderr, "Interface %s not found!\n", ifname);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-/*
- * TODO - for now, this just writes to path
- */
-int fcoeadm_action(char *path, char *s)
-{
-	FILE *fp = NULL;
-
-	if (!path)
-		return -EINVAL;
-
-	if (!s)
-		return -EINVAL;
-
-	fp = fopen(path, "w");
-	if (!fp) {
-		fprintf(stderr, "Failed to open %s\n", path);
-		return -ENOENT;
-	}
-	if (EOF == fputs(s, fp))
-		fprintf(stderr, "Failed to write %s to %s\n", s, path);
-
-	fclose(fp);
-
-	return 0;
-}
-
-char *fcoeadm_read(const char *path)
-{
-	FILE *fp;
-	char *buf;
-	int size = 512;
-
-	if (!path)
-		return NULL;
-
-	buf = malloc(size);
-	if (!buf)
-		return NULL;
-	memset(buf, 0, size);
-
-	fp = fopen(path, "r");
-	if (fp) {
-		if (fgets(buf, size, fp)) {
-			fclose(fp);
-			return buf;
-		}
-	}
-	fclose(fp);
-	free(buf);
-	return NULL;
-}
-
-/*
- *
- */
-int fcoeadm_query_attr(const char *fchost, const char *attr)
-{
-	char *buf;
-	char path[512];
-
-	sprintf(path, "%s/%s/%s", SYSFS_FCHOST, fchost, attr);
-	buf = fcoeadm_read(path);
-	if (buf) {
-		fprintf(stderr, "%s:\t%s", attr, buf);
-		free(buf);
-	}
-	return 0;
-}
-
-/*
- * TODO - query sysfs for this fcoe instance
- */
-int fcoeadm_query_fchost(const char *ifname, const char *fchost)
-{
-	if (!fchost)
-		return -EINVAL;
-	/* TODO - use filterfunc later */
-	fprintf(stderr, "Query attributes for %s on %s:\n", ifname, fchost);
-	fcoeadm_query_attr(fchost, "fabric_name");
-	fcoeadm_query_attr(fchost, "node_name");
-	fcoeadm_query_attr(fchost, "port_id");
-	fcoeadm_query_attr(fchost, "port_name");
-	fcoeadm_query_attr(fchost, "port_type");
-	fcoeadm_query_attr(fchost, "symbolic_name");
-	fcoeadm_query_attr(fchost, "active_fc4s");
-/*
-  -= Quick list of available fc_host attributes =-
-  active_fc4s fabric_name node_name port_name power
-  statistics supported_classes symbolic_name uevent
-  device issue_lip port_id port_type speed subsystem
-  supported_fc4s tgtid_bind_type
-*/
-	return 0;
-}
-
-int fcoeadm_check_fchost(const char *ifname, const char *dname)
-{
-	char *buf;
-	char path[512];
-	if (!ifname)
-		return -EINVAL;
-
-	if (!dname)
-		return -EINVAL;
-
-	if (dname[0] == '.')
-		return -EINVAL;
-
-	sprintf(path, "%s/%s/symbolic_name", SYSFS_FCHOST, dname);
-	buf = fcoeadm_read(path);
-	if (!buf)
-		return -EINVAL;
-
-	if (!strstr(buf, ifname)) {
-		free(buf);
-		return -EINVAL;
-	}
-	free(buf);
-	return 0;
-}
-
-int fcoeadm_find_fchost(char *ifname, char *fchost, int len)
-{
-	int n;
-	int found = 0;
-	struct dirent **namelist;
-
-	if (!ifname)
-		return -EINVAL;
-
-	if ((!fchost) || (len <= 0))
-		return -EINVAL;
-
-	memset(fchost, 0, len);
-	n = scandir(SYSFS_FCHOST, &namelist, 0, alphasort);
-	if (n > 0) {
-		while (n--) {
-			/* check symboli name */
-			if (!fcoeadm_check_fchost(ifname,
-						  namelist[n]->d_name)) {
-				strncpy(fchost, namelist[n]->d_name, len - 1);
-				found = 1;
-			}
-			free(namelist[n]);
-		}
-	}
-	free(namelist);
-
-	/* check */
-	return found;
-}
-/*
- * TODO -  FCoE dump the instance
- */
-int fcoeadm_query(char *ifname)
-{
-	char fchost[64];
-
-	if (!ifname)
-		return -EINVAL;
-
-	if (!fcoeadm_find_fchost(ifname, fchost, sizeof(fchost))) {
-		fprintf(stderr, "FCoE instance not found for %s\n", ifname);
-		return -EINVAL;
-	}
-	return fcoeadm_query_fchost(ifname, fchost);
-}
-/*
- * create FCoE instance for this ifname
- */
-int fcoeadm_create(char *ifname)
-{
-	if (fcoeadm_check(ifname)) {
-		fprintf(stderr, "Failed to create FCoE instance on %s!\n",
-			ifname);
-		return -EINVAL;
-	}
-	fprintf(stderr, "Creating FCoE instance for %s\n", ifname);
-	return fcoeadm_action(FCOE_CREATE, ifname);
-}
-
-/*
- * remove FCoE instance for this ifname
- */
-int fcoeadm_destroy(char *ifname)
-{
-	if (fcoeadm_check(ifname)) {
-		fprintf(stderr, "Failed to destroy FCoE instance on %s!\n",
-			ifname);
-		return -EINVAL;
-	}
-	fprintf(stderr, "Destroying FCoE instance for %s\n", ifname);
-	return fcoeadm_action(FCOE_DESTROY, ifname);
-}
-
-/*
- * reset the fc_host that is associated w/ this ifname
- */
-int fcoeadm_reset(char *ifname)
-{
-	char fchost[64];
-	char path[256];
-	if (fcoeadm_check(ifname)) {
-		fprintf(stderr, "Failed to create FCoE instance on %s!\n",
-			ifname);
-		return -EINVAL;
-	}
-	if (!fcoeadm_find_fchost(ifname, fchost, sizeof(fchost))) {
-		fprintf(stderr, "No fc_host found for %s\n", ifname);
-		return -EINVAL;
-	}
-	fprintf(stderr, "Resetting fc_host %s for %s\n", fchost, ifname);
-	sprintf(path, "%s/%s/issue_lip", SYSFS_FCHOST, fchost);
-	return fcoeadm_action(path, "1");
-}
-
-int main(int argc, char *argv[])
-{
-	int opt;
-	int rc = -1;
-
-	if (argc <= 1) {
-		fcoeadm_help(argv[0]);
-		exit(-EINVAL);
-	}
-
-	while ((opt = getopt_long(argc, argv, "c:d:q:r:h",
-				  fcoeadm_opts, NULL)) != -1) {
-		switch (opt) {
-		case 'c':
-			rc = fcoeadm_create(optarg);
-			goto done;
-		case 'd':
-			rc = fcoeadm_destroy(optarg);
-			goto done;
-		case 'q':
-			rc = fcoeadm_query(optarg);
-			goto done;
-		case 'r':
-			rc = fcoeadm_reset(optarg);
-			goto done;
-		case 'h':
-		default:
-			fcoeadm_help(argv[0]);
-			exit(-EINVAL);
-		}
-	}
-done:
-	return 0;
-}
diff --git a/usr/tools/Makefile b/usr/tools/Makefile
new file mode 100644
index 0000000..d9b2310
--- /dev/null
+++ b/usr/tools/Makefile
@@ -0,0 +1,13 @@
+# This Makefile will work only with GNU make.
+OSNAME=$(shell uname -s)
+CFLAGS += -O2 -g -Wall -Wstrict-prototypes -I../include -D$(OSNAME)
+PROGRAMS=fcoeadm
+
+default: all
+
+all: $(PROGRAMS)
+
+fcoeadm: fcoeadm.o
+
+clean:
+	rm -f *.o $(PROGRAMS)
diff --git a/usr/tools/fcoeadm.c b/usr/tools/fcoeadm.c
new file mode 100644
index 0000000..55dd554
--- /dev/null
+++ b/usr/tools/fcoeadm.c
@@ -0,0 +1,336 @@
+/*
+ -- LICENSE
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <getopt.h>
+#include <dirent.h>
+#include <string.h>
+
+#define SYSFS_MOUNT	"/sys"
+#define SYSFS_NET	SYSFS_MOUNT "/class/net"
+#define SYSFS_FCHOST	SYSFS_MOUNT "/class/fc_host"
+#define SYSFS_FCOE	SYSFS_MOUNT "/module/fcoe"
+#define FCOE_CREATE	SYSFS_FCOE "/create"
+#define FCOE_DESTROY	SYSFS_FCOE "/destroy"
+
+static struct option fcoeadm_opts[] = {
+    {"create", 1, 0, 'c'},
+    {"destroy", 1, 0, 'd'},
+    {"query", 1, 0, 'q'},
+    {"reset", 1, 0, 'r'},
+    {"help", 0, 0, 'h'},
+    {0, 0, 0, 0}
+};
+
+
+void fcoeadm_help(char *name)
+{
+	fprintf(stderr, "Usage: %s\n"
+		"\t [-c|--create] ifname\n"
+		"\t [-d|--destroy] ifname\n"
+		"\t [-q|--query] ifname\n"
+		"\t [-r|--reset] ifname\n"
+		"\t [-h|--help]\n",
+		name);
+}
+
+/*
+ * open and close to check if dir exists
+ */
+int fcoeadm_checkdir(char *dir)
+{
+	DIR *d = NULL;
+
+	if (!dir)
+		return -EINVAL;
+	/* check if we have sysfs */
+	d = opendir(dir);
+	if (!d)
+		return -EINVAL;
+	closedir(d);
+	return 0;
+}
+/*
+ * TODO - check this ifname before performing any action
+ */
+int fcoeadm_check(char *ifname)
+{
+	char path[256];
+	/* check if we have sysfs */
+	if (fcoeadm_checkdir(SYSFS_MOUNT)) {
+		fprintf(stderr, "Sysfs mount point %s not found!\n",
+			SYSFS_MOUNT);
+		return -EINVAL;
+	}
+	/* check fcoe module */
+	if (fcoeadm_checkdir(SYSFS_FCOE)) {
+		fprintf(stderr, "Please make sure FCoE driver module "
+			"is loaded!\n");
+		return -EINVAL;
+	}
+	/* check target interface */
+	if (!ifname) {
+		fprintf(stderr, "Invalid interface name!\n");
+		return -EINVAL;
+	}
+	sprintf(path, "%s/%s", SYSFS_NET, ifname);
+	if (fcoeadm_checkdir(path)) {
+		fprintf(stderr, "Interface %s not found!\n", ifname);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/*
+ * TODO - for now, this just writes to path
+ */
+int fcoeadm_action(char *path, char *s)
+{
+	FILE *fp = NULL;
+
+	if (!path)
+		return -EINVAL;
+
+	if (!s)
+		return -EINVAL;
+
+	fp = fopen(path, "w");
+	if (!fp) {
+		fprintf(stderr, "Failed to open %s\n", path);
+		return -ENOENT;
+	}
+	if (EOF == fputs(s, fp))
+		fprintf(stderr, "Failed to write %s to %s\n", s, path);
+
+	fclose(fp);
+
+	return 0;
+}
+
+char *fcoeadm_read(const char *path)
+{
+	FILE *fp;
+	char *buf;
+	int size = 512;
+
+	if (!path)
+		return NULL;
+
+	buf = malloc(size);
+	if (!buf)
+		return NULL;
+	memset(buf, 0, size);
+
+	fp = fopen(path, "r");
+	if (fp) {
+		if (fgets(buf, size, fp)) {
+			fclose(fp);
+			return buf;
+		}
+	}
+	fclose(fp);
+	free(buf);
+	return NULL;
+}
+
+/*
+ *
+ */
+int fcoeadm_query_attr(const char *fchost, const char *attr)
+{
+	char *buf;
+	char path[512];
+
+	sprintf(path, "%s/%s/%s", SYSFS_FCHOST, fchost, attr);
+	buf = fcoeadm_read(path);
+	if (buf) {
+		fprintf(stderr, "%s:\t%s", attr, buf);
+		free(buf);
+	}
+	return 0;
+}
+
+/*
+ * TODO - query sysfs for this fcoe instance
+ */
+int fcoeadm_query_fchost(const char *ifname, const char *fchost)
+{
+	if (!fchost)
+		return -EINVAL;
+	/* TODO - use filterfunc later */
+	fprintf(stderr, "Query attributes for %s on %s:\n", ifname, fchost);
+	fcoeadm_query_attr(fchost, "fabric_name");
+	fcoeadm_query_attr(fchost, "node_name");
+	fcoeadm_query_attr(fchost, "port_id");
+	fcoeadm_query_attr(fchost, "port_name");
+	fcoeadm_query_attr(fchost, "port_type");
+	fcoeadm_query_attr(fchost, "symbolic_name");
+	fcoeadm_query_attr(fchost, "active_fc4s");
+/*
+  -= Quick list of available fc_host attributes =-
+  active_fc4s fabric_name node_name port_name power
+  statistics supported_classes symbolic_name uevent
+  device issue_lip port_id port_type speed subsystem
+  supported_fc4s tgtid_bind_type
+*/
+	return 0;
+}
+
+int fcoeadm_check_fchost(const char *ifname, const char *dname)
+{
+	char *buf;
+	char path[512];
+	if (!ifname)
+		return -EINVAL;
+
+	if (!dname)
+		return -EINVAL;
+
+	if (dname[0] == '.')
+		return -EINVAL;
+
+	sprintf(path, "%s/%s/symbolic_name", SYSFS_FCHOST, dname);
+	buf = fcoeadm_read(path);
+	if (!buf)
+		return -EINVAL;
+
+	if (!strstr(buf, ifname)) {
+		free(buf);
+		return -EINVAL;
+	}
+	free(buf);
+	return 0;
+}
+
+int fcoeadm_find_fchost(char *ifname, char *fchost, int len)
+{
+	int n;
+	int found = 0;
+	struct dirent **namelist;
+
+	if (!ifname)
+		return -EINVAL;
+
+	if ((!fchost) || (len <= 0))
+		return -EINVAL;
+
+	memset(fchost, 0, len);
+	n = scandir(SYSFS_FCHOST, &namelist, 0, alphasort);
+	if (n > 0) {
+		while (n--) {
+			/* check symboli name */
+			if (!fcoeadm_check_fchost(ifname,
+						  namelist[n]->d_name)) {
+				strncpy(fchost, namelist[n]->d_name, len - 1);
+				found = 1;
+			}
+			free(namelist[n]);
+		}
+	}
+	free(namelist);
+
+	/* check */
+	return found;
+}
+/*
+ * TODO -  FCoE dump the instance
+ */
+int fcoeadm_query(char *ifname)
+{
+	char fchost[64];
+
+	if (!ifname)
+		return -EINVAL;
+
+	if (!fcoeadm_find_fchost(ifname, fchost, sizeof(fchost))) {
+		fprintf(stderr, "FCoE instance not found for %s\n", ifname);
+		return -EINVAL;
+	}
+	return fcoeadm_query_fchost(ifname, fchost);
+}
+/*
+ * create FCoE instance for this ifname
+ */
+int fcoeadm_create(char *ifname)
+{
+	if (fcoeadm_check(ifname)) {
+		fprintf(stderr, "Failed to create FCoE instance on %s!\n",
+			ifname);
+		return -EINVAL;
+	}
+	fprintf(stderr, "Creating FCoE instance for %s\n", ifname);
+	return fcoeadm_action(FCOE_CREATE, ifname);
+}
+
+/*
+ * remove FCoE instance for this ifname
+ */
+int fcoeadm_destroy(char *ifname)
+{
+	if (fcoeadm_check(ifname)) {
+		fprintf(stderr, "Failed to destroy FCoE instance on %s!\n",
+			ifname);
+		return -EINVAL;
+	}
+	fprintf(stderr, "Destroying FCoE instance for %s\n", ifname);
+	return fcoeadm_action(FCOE_DESTROY, ifname);
+}
+
+/*
+ * reset the fc_host that is associated w/ this ifname
+ */
+int fcoeadm_reset(char *ifname)
+{
+	char fchost[64];
+	char path[256];
+	if (fcoeadm_check(ifname)) {
+		fprintf(stderr, "Failed to create FCoE instance on %s!\n",
+			ifname);
+		return -EINVAL;
+	}
+	if (!fcoeadm_find_fchost(ifname, fchost, sizeof(fchost))) {
+		fprintf(stderr, "No fc_host found for %s\n", ifname);
+		return -EINVAL;
+	}
+	fprintf(stderr, "Resetting fc_host %s for %s\n", fchost, ifname);
+	sprintf(path, "%s/%s/issue_lip", SYSFS_FCHOST, fchost);
+	return fcoeadm_action(path, "1");
+}
+
+int main(int argc, char *argv[])
+{
+	int opt;
+	int rc = -1;
+
+	if (argc <= 1) {
+		fcoeadm_help(argv[0]);
+		exit(-EINVAL);
+	}
+
+	while ((opt = getopt_long(argc, argv, "c:d:q:r:h",
+				  fcoeadm_opts, NULL)) != -1) {
+		switch (opt) {
+		case 'c':
+			rc = fcoeadm_create(optarg);
+			goto done;
+		case 'd':
+			rc = fcoeadm_destroy(optarg);
+			goto done;
+		case 'q':
+			rc = fcoeadm_query(optarg);
+			goto done;
+		case 'r':
+			rc = fcoeadm_reset(optarg);
+			goto done;
+		case 'h':
+		default:
+			fcoeadm_help(argv[0]);
+			exit(-EINVAL);
+		}
+	}
+done:
+	return 0;
+}




More information about the devel mailing list