Create a new routine that generically writes a string to
a sysfs file. Use that routine to interface with the kernel's
new (v3.?) ctlr_create/delete interfaces.
---
 fcoemon.c            |   76 ++++++++++++++++++++++++++------------------------
 include/fcoe_utils.h |   16 +++++++----
 lib/fcoe_utils.c     |   19 +++++++++++++
 3 files changed, 68 insertions(+), 43 deletions(-)

diff --git a/fcoemon.c b/fcoemon.c
index d3e1a34..d647e7d 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -2514,31 +2514,6 @@ static void fcm_cli_reply(struct sock_info *r, int 
status)
               r->fromlen);
 }
 
-static enum fcoe_status fcm_fcoe_if_action(char *path, char *ifname)
-{
-       FILE *fp = NULL;
-       enum fcoe_status ret = EFAIL;
-
-       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 = SUCCESS;
-out:
-       fclose(fp);
-err_out:
-       return ret;
-}
-
 void fcm_vlan_disc_timeout(void *arg)
 {
        struct fcoe_port *p = arg;
@@ -2564,6 +2539,16 @@ int fcm_start_vlan_disc(struct fcoe_port *p)
        return 0;
 }
 
+static enum fcoe_status fcm_write_str_to_ctlr_attr(const char *ctlr,
+                                                  const char *attr,
+                                                  const char *str)
+{
+       char path[MAX_PATH_LEN];
+
+       sprintf(path, "%s/%s/%s", FCOE_DEVICES, ctlr, attr);
+       return fcm_write_str_to_sysfs_file(path, str);
+}
+
 /*
  *
  * Input:  action = 1      Destroy the FCoE interface
@@ -2580,19 +2565,36 @@ static void fcm_fcoe_action(struct fcm_netif *ff, 
struct fcoe_port *p)
        switch (p->action) {
        case FCP_CREATE_IF:
                FCM_LOG_DBG("OP: CREATE %s\n", p->ifname);
-               rc = fcm_fcoe_if_action(FCOE_CREATE, ifname);
+               rc = fcm_write_str_to_sysfs_file(FCOE_CREATE, ifname);
+               if (rc) {
+                       FCM_LOG_DBG("Failed to create FCoE interface "
+                                   "for %s, rc is %d\n", p->ifname, rc);
+                       break;
+               }
+
                /*
                 * This call validates that the interface name
                 * has an active fcoe session by checking for
                 * the fc_host in sysfs.
                 */
-               if (fcoe_find_fchost(ifname, p->fchost, FCHOSTBUFLEN))
+               if (fcoe_find_fchost(ifname, p->fchost, FCHOSTBUFLEN)) {
                        FCM_LOG_DBG("Failed to find fc_host for %s\n", 
p->ifname);
-               if (fcoe_find_ctlr(p->fchost, p->ctlr, FCHOSTBUFLEN))
+                       break;
+               }
+               if (fcoe_find_ctlr(p->fchost, p->ctlr, FCHOSTBUFLEN)) {
                        FCM_LOG_DBG("Failed to get ctlr for %s\n", p->ifname);
+                       break;
+               }
+
+               if (!rc)
+                       rc = fcm_write_str_to_ctlr_attr(p->ctlr, FCOE_START, 
"1");
+               
+               else
+                       fcm_write_str_to_sysfs_file(FCOE_DESTROY, ifname);
+
+                       FCM_LOG_DBG("OP: create %s for fchost:%s on ctlr:%s for 
%s\n",
+                                   (rc) ? "failed" : "succeeded", p->fchost, 
p->ctlr, p->ifname);
 
-               FCM_LOG_DBG("OP: created fchost:%s on ctlr:%s for %s\n",
-                           p->fchost, p->ctlr, p->ifname);
                break;
        case FCP_DESTROY_IF:
                FCM_LOG_DBG("OP: DESTROY %s\n", p->ifname);
@@ -2609,12 +2611,12 @@ static void fcm_fcoe_action(struct fcm_netif *ff, 
struct fcoe_port *p)
                        rc = SUCCESS;
                        break;
                }
-               rc = fcm_fcoe_if_action(FCOE_DESTROY, ifname);
+               rc = fcm_write_str_to_sysfs_file(FCOE_DESTROY, ifname);
                p->fchost[0] = '\0';
                break;
        case FCP_ENABLE_IF:
                FCM_LOG_DBG("OP: ENABLE %s\n", p->ifname);
-               rc = fcm_fcoe_if_action(FCOE_ENABLE, ifname);
+               rc = fcm_write_str_to_ctlr_attr(p->ctlr, FCOE_ENABLE, "1");
                break;
        case FCP_DISABLE_IF:
                FCM_LOG_DBG("OP: DISABLE %s\n", p->ifname);
@@ -2630,7 +2632,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct 
fcoe_port *p)
                        }
                        break;
                }
-               rc = fcm_fcoe_if_action(FCOE_DISABLE, ifname);
+               rc = fcm_write_str_to_ctlr_attr(p->ctlr, FCOE_DISABLE, "1");
                break;
        case FCP_RESET_IF:
                FCM_LOG_DBG("OP: RESET %s\n", p->ifname);
@@ -2642,7 +2644,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct 
fcoe_port *p)
 
                sprintf(path, "%s/%s/issue_lip", SYSFS_FCHOST, p->fchost);
                FCM_LOG_DBG("OP: RESET %s\n", path);
-               rc = fcm_fcoe_if_action(path, "1");
+               rc = fcm_write_str_to_sysfs_file(path, "1");
                break;
        case FCP_SCAN_IF:
                FCM_LOG_DBG("OP: SCAN %s\n", p->ifname);
@@ -2654,7 +2656,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct 
fcoe_port *p)
                sprintf(path, "%s/%s/device/scsi_host/%s/scan",
                        SYSFS_FCHOST, p->fchost, p->fchost);
                FCM_LOG_DBG("OP: SCAN %s\n", path);
-               rc = fcm_fcoe_if_action(path, "- - -");
+               rc = fcm_write_str_to_sysfs_file(path, "- - -");
                break;
        case FCP_VLAN_DISC:
                FCM_LOG_DBG("OP: VLAN DISC %s\n", p->ifname);
@@ -3443,7 +3445,7 @@ static int fcoe_check_ctlr(char *fchost, const char 
*dname, int len)
        char path[MAX_PATH_LEN];
        int rc = -EINVAL;
 
-       sprintf(path, "%s/%s", SYSFS_DEVICES, dname);
+       sprintf(path, "%s/%s", FCOE_DEVICES, dname);
        status = n = scandir(path, &namelist, fchost_filter, alphasort);
        for (n-- ; n >= 0 ; n--) {
                if (rc) {
@@ -3471,7 +3473,7 @@ enum fcoe_status fcoe_find_ctlr(char *fchost, char *ctlr, 
int len)
        struct dirent **namelist;
        int rc = ENOFCOECONN;
 
-       status = n = scandir(SYSFS_DEVICES, &namelist, ctlr_filter, alphasort);
+       status = n = scandir(FCOE_DEVICES, &namelist, ctlr_filter, alphasort);
        for (n-- ; n >= 0 ; n--) {
                if (rc) {
                        /* check ctlr against known host */
diff --git a/include/fcoe_utils.h b/include/fcoe_utils.h
index 5f99073..da86724 100644
--- a/include/fcoe_utils.h
+++ b/include/fcoe_utils.h
@@ -38,13 +38,15 @@
 #define SYSFS_MOUNT    "/sys"
 #define SYSFS_NET      SYSFS_MOUNT "/class/net"
 #define SYSFS_FCHOST   SYSFS_MOUNT "/class/fc_host"
-#define SYSFS_DEVICES   SYSFS_MOUNT "/bus/fcoe/devices"
-#define SYSFS_FCOE     SYSFS_MOUNT "/module/libfcoe/parameters"
+#define SYSFS_FCOE     SYSFS_MOUNT "/bus/fcoe"
+#define FCOE_DEVICES    SYSFS_FCOE "/devices"
 
-#define FCOE_CREATE    SYSFS_FCOE "/create"
-#define FCOE_DESTROY   SYSFS_FCOE "/destroy"
-#define FCOE_ENABLE    SYSFS_FCOE "/enable"
-#define FCOE_DISABLE   SYSFS_FCOE "/disable"
+#define FCOE_CREATE    SYSFS_FCOE "/ctlr_create"
+#define FCOE_DESTROY   SYSFS_FCOE "/ctlr_destroy"
+
+#define FCOE_START      "/start"
+#define FCOE_ENABLE    "/enable"
+#define FCOE_DISABLE   "/disable"
 
 #define FCHOSTBUFLEN 64
 
@@ -84,4 +86,6 @@ int check_symbolic_name_for_interface(const char 
*symbolic_name,
                                      const char *ifname);
 char *get_ifname_from_symbolic_name(const char *symbolic_name);
 int fcoe_sysfs_read(char *buf, int size, const char *path);
+enum fcoe_status fcm_write_str_to_sysfs_file(const char *path, const char 
*str);
+
 #endif /* _FCOE_UTILS_H_ */
diff --git a/lib/fcoe_utils.c b/lib/fcoe_utils.c
index 0ebc854..27828a8 100644
--- a/lib/fcoe_utils.c
+++ b/lib/fcoe_utils.c
@@ -193,3 +193,22 @@ int check_symbolic_name_for_interface(const char 
*symbolic_name,
 
        return rc;
 }
+
+enum fcoe_status fcm_write_str_to_sysfs_file(const char *path, const char *str)
+{
+       FILE *fp = NULL;
+       enum fcoe_status ret = EFAIL;
+
+       fp = fopen(path, "w");
+       if (!fp)
+               goto err_out;
+
+       if (EOF == fputs(str, fp))
+               goto out;
+
+       ret = SUCCESS;
+out:
+       fclose(fp);
+err_out:
+       return ret;
+}

_______________________________________________
devel mailing list
devel@open-fcoe.org
https://lists.open-fcoe.org/mailman/listinfo/devel

Reply via email to