Add calls to write to sysfs files for create/delete/reset action in
fcm_fcoe_action function.
Remove create, destroy and reset functionality from fcoeplumb.
Remove the code in service script which destroys non-DCB FCoE interfaces on
service stop script.
Fcoemon now destroys all FCoE interfaces on termination.

Signed-off-by: Lucy Liu <[email protected]>

---

 etc/initd/initd.fedora |   16 --------
 etc/initd/initd.suse   |   16 --------
 fcoemon.c              |   96 +++++++++++++++++++++++++++++++++++++-----------
 fcoeplumb.in           |   89 +++++----------------------------------------
 4 files changed, 84 insertions(+), 133 deletions(-)

diff --git a/etc/initd/initd.fedora b/etc/initd/initd.fedora
index 412b2de..67c3e5f 100755
--- a/etc/initd/initd.fedora
+++ b/etc/initd/initd.fedora
@@ -141,22 +141,6 @@ service_stop()
        pidof $FCOEMON
        [ $? -eq 0 ] && kill -TERM `pidof $FCOEMON`
 
-       for ifcfg_file in `ls $CONFIG_DIR/cfg-eth*`
-       do
-               ifname=`basename $ifcfg_file | cut -d"-" -f2`
-               . $ifcfg_file
-               [ "$FCOE_ENABLE" != "yes" ] &&
-               [ "$FCOE_ENABLE" != "YES" ] && continue
-               if [ "$DCB_REQUIRED" != "yes" ] &&
-                  [ "$DCB_REQUIRED" != "YES" ]; then
-                       STATUS=`$FCOEADM -i $ifname 2>&1 | \
-                               awk '/Symbolic Name:/{print $6}'`
-                       if [ "$STATUS" = "$ifname" ]; then
-                               $FCOEADM -d $ifname
-                       fi
-               fi
-       done
-
        retry_count=5
        while true
        do
diff --git a/etc/initd/initd.suse b/etc/initd/initd.suse
index 6efb88c..b4b1b76 100755
--- a/etc/initd/initd.suse
+++ b/etc/initd/initd.suse
@@ -200,22 +200,6 @@ service_stop()
        checkproc $FCOEMON
        [ $? -eq 0 ] && killproc -TERM $FCOEMON
 
-       for ifcfg_file in `ls $CONFIG_DIR/cfg-eth*`
-       do
-               ifname=`basename $ifcfg_file | cut -d"-" -f2`
-               . $ifcfg_file
-               [ "$FCOE_ENABLE" != "yes" ] &&
-               [ "$FCOE_ENABLE" != "YES" ] && continue
-               if [ "$DCB_REQUIRED" != "yes" ] &&
-                  [ "$DCB_REQUIRED" != "YES" ]; then
-                       STATUS=`$FCOEADM -i $ifname 2>&1 | \
-                               awk '/Symbolic Name:/{print $6}'`
-                       if [ "$STATUS" = "$ifname" ]; then
-                               $FCOEADM -d $ifname
-                       fi
-               fi
-       done
-
        retry_count=5
        while true
        do
diff --git a/fcoemon.c b/fcoemon.c
index a3a09b1..aff2e5e 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -58,6 +58,7 @@
 
 #include "fcoemon_utils.h"
 #include "fcoemon.h"
+#include "fcoe_clif.h"
 
 #ifndef SYSCONFDIR
 #define SYSCONFDIR                  "/etc"
@@ -83,9 +84,18 @@
 #define FCM_PING_REQ_LEN       1 /* byte-length of dcbd PING request */
 #define FCM_PING_RSP_LEN       8 /* byte-length of dcbd PING response */
 
+#define FCOE_CREATE    SYSFS_FCOE "/create"
+#define FCOE_DESTROY   SYSFS_FCOE "/destroy"
+
 static char *fcoemon_version =                                         \
        "fcoemon v1.0.8\n Copyright (c) 2009, Intel Corporation.\n";
 
+enum fcm_srv_status {
+       fcm_success = 0,
+       fcm_fail,
+       fcm_no_action
+};
+
 /*
  * fcoe service configuration data
  * Note: These information are read in from the fcoe service
@@ -128,6 +138,7 @@ static void fcm_dcbd_event(char *, size_t);
 static void fcm_dcbd_cmd_resp(char *, cmd_status);
 static void fcm_netif_advance(struct fcm_netif *);
 static void fcm_fcoe_action(struct fcm_netif *, struct fcoe_port *);
+static int fcm_fcoe_if_action(char *, char *);
 
 struct fcm_clif {
        int cl_fd;
@@ -973,6 +984,8 @@ static void fcm_cleanup(void)
        struct fcm_netif *ff, *head;
 
        for (curr = fcoe_config.port; curr; curr = next) {
+               FCM_LOG_DBG("OP: DESTROY %s\n", curr->ifname);
+               fcm_fcoe_if_action(FCOE_DESTROY,  curr->ifname);
                next = curr->next;
                free(curr);
        }
@@ -1597,11 +1610,11 @@ static void fcm_dcbd_event(char *msg, size_t len)
 
        p = fcm_find_fcoe_port(ff->ifname, FCP_REAL_IFNAME);
        while (p) {
-               if (p->dcb_required && p->last_msg_type != RTM_DELLINK)
+               if (p->dcb_required && p->last_msg_type != RTM_DELLINK &&
+                       p->fcoe_enable)
                        break;
                p = fcm_find_next_fcoe_port(p, ff->ifname);
        }
-
        /*
         * dcb is not required or link was removed, ignore dcbd event
        */
@@ -1646,48 +1659,86 @@ static void fcm_dcbd_event(char *msg, size_t len)
        return;
 }
 
+static int fcm_fcoe_if_action(char *path, char *ifname)
+{
+       FILE *fp = NULL;
+       int ret = fcm_fail;
+
+       fp = fopen(path, "w");
+       if (!fp) {
+               FCM_LOG_ERR(errno, "%s: Failed to open path %s\n",
+                                       progname, path);
+               goto err_out;
+       }
+
+       if (EOF == fputs(ifname, fp)) {
+               FCM_LOG_ERR(errno, "%s: Failed to write %s to path %s.\n",
+                               progname, ifname, path);
+               goto out;
+       }
+
+       ret = fcm_success;
+out:
+       fclose(fp);
+err_out:
+       return ret;
+}
+
 /*
- * Run script to enable or disable the interface or print a message.
  *
- * Input:  enable = 0      Destroy the FCoE interface
- *         enable = 1      Create the FCoE interface
- *         enable = 2      Reset the interface
+ * Input:  action = 1      Destroy the FCoE interface
+ *         action = 2      Create the FCoE interface
+ *         action = 3      Reset the interface
  */
 static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p)
 {
-       char *op, *debug, *syslog = NULL;
+       char *debug, *syslog = NULL;
        char *qos_arg;
        char qos[64];
+       char *ifname = p->ifname;
+       char fchost[FCHOSTBUFLEN];
+       char path[256];
        u_int32_t mask;
        int rc;
        int fd;
 
+       rc = fcm_success;
        qos_arg = "--qos-enable";
        switch (p->action) {
        case FCP_CREATE_IF:
                if (p->last_action == FCP_CREATE_IF)
-                       return;
-               op = "--create";
+                       break;
+               FCM_LOG_DBG("OP: CREATE\n");
+               rc = fcm_fcoe_if_action(FCOE_CREATE, ifname);
                break;
        case FCP_DESTROY_IF:
                if (p->last_action == FCP_DESTROY_IF)
-                       return;
-               op = "--destroy";
+                       break;
                qos_arg = "--qos-disable";
+               FCM_LOG_DBG("OP: DESTROY\n");
+               rc = fcm_fcoe_if_action(FCOE_DESTROY, ifname);
                break;
        case FCP_RESET_IF:
-               op = "--reset";
+               FCM_LOG_DBG("OP: RESET\n");
+               if (fcoeclif_validate_interface(ifname, fchost, FCHOSTBUFLEN))
+                       return;
+               sprintf(path, "%s/%s/issue_lip", SYSFS_FCHOST, fchost);
+               rc = fcm_fcoe_if_action(path, "1");
                break;
        default:
                return;
                break;
        }
+
+       if ((p->action != FCP_RESET_IF) && (p->last_action == p->action))
+               return;
+
        p->last_action = p->action;
 
        if (p->action && !ff->ff_qos_mask)
                return;
        if (fcm_dcbd_cmd == NULL) {
-               FCM_LOG_DEV_DBG(ff, "Should %s per op state", op);
+               FCM_LOG_DEV_DBG(ff, "Should call fcoeplumb per op state");
                return;
        }
 
@@ -1725,12 +1776,8 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct 
fcoe_port *p)
                if (fcoe_config.debug) {
                        debug = "--debug";
 
-                       if (!p->action)
-                               FCM_LOG_DEV_DBG(ff, "%s %s %s\n", fcm_dcbd_cmd,
-                                               op, syslog);
-                       else
-                               FCM_LOG_DEV_DBG(ff, "%s %s %s %s %s\n",
-                                               fcm_dcbd_cmd, op, qos_arg, qos,
+                       FCM_LOG_DEV_DBG(ff, "%s %s %s %s\n",
+                                               fcm_dcbd_cmd, qos_arg, qos,
                                                syslog);
                }
 
@@ -1738,8 +1785,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct 
fcoe_port *p)
                if (rc < 0)
                        FCM_LOG_ERR(errno, "fork error");
                else if (rc == 0) {     /* child process */
-                       execlp(fcm_dcbd_cmd, fcm_dcbd_cmd, "--fcoeif",
-                              p->ifname, op, "--netif", p->real_ifname,
+                       execlp(fcm_dcbd_cmd, fcm_dcbd_cmd, p->real_ifname,
                               qos_arg, qos, debug, syslog, (char *)NULL);
                }
 
@@ -1921,7 +1967,6 @@ static void fcm_usage(void)
 
 static void fcm_sig(int sig)
 {
-       fcm_dcbd_shutdown();
        sa_select_exit();
 }
 
@@ -2037,6 +2082,13 @@ int main(int argc, char **argv)
                exit(1);
        }
        fcm_pidfile_create();
+
+       /* check fcoe module */
+       if (fcoeclif_checkdir(SYSFS_FCOE)) {
+               FCM_LOG_ERR(errno, "make sure FCoE driver module is loaded!");
+               exit(1);
+       }
+
        fcm_fcoe_init();
        fcm_link_init();        /* NETLINK_ROUTE protocol */
        fcm_dcbd_init();
diff --git a/fcoeplumb.in b/fcoeplumb.in
index c916f35..658bd9d 100755
--- a/fcoeplumb.in
+++ b/fcoeplumb.in
@@ -22,10 +22,8 @@ cmdname=`basename $0`
 usage()
 {
        echo usage: $cmdname \
-               '[--fcoeif <ethX> --reset | --create | --destroy]' \
                '[--debug] [--syslog]' \
-               '[--netif <ethX> --qos-disable |' \
-               '--qos-enable  <pri>[,<pri>]...]' >&2
+               '[<ethX> --qos-disable | --qos-enable  <pri>[,<pri>]...]' >&2
        exit 1
 }
 
@@ -51,8 +49,6 @@ sbind...@sbindir@
 sysconfd...@sysconfdir@
 # make sure there's a sane path to find basic commands and system tools (tc)
 PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
-FCOEADM=${sbindir}/fcoeadm     # command to create/destroy FCoE instances
-CONFIG_DIR=${sysconfdir}/fcoe
 LOGGER=
 DEBUG_LOGGING=
 
@@ -194,36 +190,6 @@ replace_skbedit_filter()
                action skbedit queue_mapping $queue
 }
 
-remove_fcoe_interface()
-{
-       ifname=$1
-
-       STATUS=`$FCOEADM -i $ifname 2>&1 | \
-               awk '/Symbolic Name:/ && /'$ifname'$/{print $6}'`
-       if [ "$STATUS" == "$ifname" ]; then
-               [ ${DEBUG_LOGGING} ] && $LOGGER "$FCOEADM -d $ifname"
-               $FCOEADM -d $ifname
-       else
-               [ ${DEBUG_LOGGING} ] && $LOGGER \
-                       "FCoE interface $ifname doesn't exist"
-       fi
-}
-
-create_fcoe_interface()
-{
-       ifname=$1
-
-       STATUS=`$FCOEADM -i $ifname 2>&1 | \
-               awk '/Symbolic Name:/ && /'$ifname'$/{print $6}'`
-       if [ -z "$STATUS" ]; then
-               [ ${DEBUG_LOGGING} ] && $LOGGER "$FCOEADM -c $ifname"
-               $FCOEADM -c $ifname
-       else
-               [ ${DEBUG_LOGGING} ] && $LOGGER \
-                       "FCoE interface $ifname already created"
-       fi
-}
-
 config_logging()
 {
     if [ $DEBUG_LOGGING ] ; then
@@ -241,48 +207,20 @@ config_logging()
 
 [ ${DEBUG_LOGGING} ] && $LOGGER "fcoeplumb arguments: ($*)"
 
+net_ifname=$1
+shift
+
 while [ "$#" -ge 1 ]
 do
        case "$1" in
-           --fcoeif)
-               shift
-               fcoe_ifname=$1
+           --qos-enable)
+               [ "$#" -lt 2 ] && usage
+               qos_list=$2
                shift
-               case "$1" in
-                   --reset | -r)
-                       cmd=reset
-                       ;;
-                   --create | -c)
-                       cmd=create
-                       ;;
-                   --destroy | -d)
-                       cmd=destroy
-                       ;;
-                   *)
-                       echo "$cmdname: unknown fcoe parameter '$1'" >&2
-                       usage
-                       ;;
-               esac
                ;;
-           --netif)
-               shift
-               net_ifname=$1
-               shift
-               case "$1" in
-                   --qos-enable)
-                       [ "$#" -lt 2 ] && usage
-                       qos_list=$2
-                       shift
-                       ;;
-                   --qos-disable)
-                       [[ "$2" =~ ^[0-9]+$ ]] && shift
-                       qos_list="disable"
-                       ;;
-                   *)
-                       echo "$cmdname: unknown qos parameter '$1'" >&2
-                       usage
-                       ;;
-               esac
+           --qos-disable)
+               [[ "$2" =~ ^[0-9]+$ ]] && shift
+               qos_list="disable"
                ;;
            --debug)
                DEBUG_LOGGING=1
@@ -306,13 +244,6 @@ done
 fcoe_filter_id=`get_filter_id $net_ifname $FCOE_FILTER_KEY`
 fip_filter_id=`get_filter_id $net_ifname $FIP_FILTER_KEY`
 
-if [ "$cmd" == "destroy" ]; then
-       remove_fcoe_interface $fcoe_ifname
-
-elif [ "$cmd" == "create" ]; then
-       create_fcoe_interface $fcoe_ifname
-fi
-
 if [ "$qos_list" == "disable" ]; then
        # Remove the FCoE filters
        find_skbedit_filter $net_ifname $FCOE_ETHERTYPE $fcoe_filter_id

-- 
Signature: Lucy Liu <[email protected]>
_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to