Add a function template implementation for the new fcoe_sysfs kernel interfaces. When the /sys/bus/fcoe/ctlr_create file exists and is writable by fcoemon the new template will be used.
To write to the new sysfs locations the new helper routine fcm_write_str_to_ctlr_attr is added. Also, some reshuffling of the sysfs path defines was required. Also note that that the fcoe_ctlr lookup only needs to happen if fcoemon is to use the new fcoe_sysfs interfaces. Signed-off-by: Robert Love <[email protected]> Tested-by: Marcus Dennis <[email protected]> --- fcoemon.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- include/fcoe_utils.h | 5 ++- lib/fcoe_utils.c | 10 ++++++ 3 files changed, 84 insertions(+), 9 deletions(-) diff --git a/fcoemon.c b/fcoemon.c index c0d9882..a7e3ae5 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -171,7 +171,7 @@ struct libfcoe_interface_template { enum fcoe_status (*disable)(struct fcm_netif *, struct fcoe_port *); }; -const struct libfcoe_interface_template *libfcoe_control; +static const struct libfcoe_interface_template *libfcoe_control; static enum fcoe_status fcm_module_create(struct fcm_netif *ff, struct fcoe_port *p) { @@ -214,6 +214,63 @@ static struct libfcoe_interface_template libfcoe_module_tmpl = { .disable = fcm_module_disable, }; +static enum fcoe_status fcm_bus_enable(struct fcm_netif *ff, + struct fcoe_port *p) +{ + return fcm_write_str_to_ctlr_attr(p->ctlr, FCOE_CTLR_ATTR_ENABLED, "1"); +} + +static enum fcoe_status fcm_bus_create(struct fcm_netif *ff, + struct fcoe_port *p) +{ + enum fcoe_status rc; + + rc = fcm_write_str_to_sysfs_file(FCOE_BUS_CREATE, p->ifname); + if (rc) + return rc; + + /* + * This call validates that the interface name + * has an active fcoe session by checking for + * the fc_host in sysfs. + */ + if (fcoe_find_fchost(p->ifname, p->fchost, FCHOSTBUFLEN)) { + FCM_LOG_DBG("Failed to find fc_host for %s\n", p->ifname); + return ENOSYSFS; + } + + /* + * The fcoe_ctlr_device lookup only happens when the fcoe_sysfs + * kernel interfaces are used. It is a defect if p->ctlr is used + * outside of these abstracted routines. + */ + if (fcoe_find_ctlr(p->fchost, p->ctlr, FCHOSTBUFLEN)) { + FCM_LOG_DBG("Failed to get ctlr for %s\n", p->ifname); + return ENOSYSFS; + } + + return fcm_bus_enable(ff, p); +} + +static enum fcoe_status fcm_bus_destroy(struct fcm_netif *ff, + struct fcoe_port *p) +{ + return fcm_write_str_to_sysfs_file(FCOE_BUS_DESTROY, p->ifname); +} + +static enum fcoe_status fcm_bus_disable(struct fcm_netif *ff, + struct fcoe_port *p) +{ + return fcm_write_str_to_ctlr_attr(p->ctlr, FCOE_CTLR_ATTR_ENABLED, "0"); +} + +static struct libfcoe_interface_template libfcoe_bus_tmpl = { + .create = fcm_bus_create, + .destroy = fcm_bus_destroy, + .enable = fcm_bus_enable, + .disable = fcm_bus_disable, +}; + struct fcm_clif { int cl_fd; int cl_busy; /* non-zero if command pending */ @@ -1672,7 +1729,13 @@ static void fcm_fcoe_init(void) if (fcm_read_config_files()) exit(1); - libfcoe_control = &libfcoe_module_tmpl; + if (!access(FCOE_BUS_CREATE, F_OK)) { + FCM_LOG_DBG("Using /sys/bus/fcoe interfaces\n"); + libfcoe_control = &libfcoe_bus_tmpl; + } else { + FCM_LOG_DBG("Using libfcoe module parameter interfaces\n"); + libfcoe_control = &libfcoe_module_tmpl; + } } /* @@ -2636,14 +2699,15 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p) case FCP_CREATE_IF: FCM_LOG_DBG("OP: CREATE %s\n", p->ifname); rc = libfcoe_control->create(ff, p); - - if (fcoe_find_ctlr(p->fchost, p->ctlr, FCHOSTBUFLEN)) { - FCM_LOG_DBG("Failed to get ctlr for %s\n", p->ifname); + if (rc) { + FCM_LOG_DBG("Failed to create FCoE interface " + "for %s, rc is %d\n", p->ifname, rc); break; } - FCM_LOG_DBG("OP: created fchost:%s on ctlr:%s for %s\n", - p->fchost, p->ctlr, p->ifname); + FCM_LOG_DBG("OP: created fchost:%s for %s\n", + p->fchost, p->ifname); + break; case FCP_DESTROY_IF: FCM_LOG_DBG("OP: DESTROY %s\n", p->ifname); diff --git a/include/fcoe_utils.h b/include/fcoe_utils.h index 34f6a45..037feab 100644 --- a/include/fcoe_utils.h +++ b/include/fcoe_utils.h @@ -35,7 +35,6 @@ #define MAX_STR_LEN 512 #define MAX_PATH_LEN MAX_STR_LEN - #define SYSFS_MOUNT "/sys" #define SYSFS_NET SYSFS_MOUNT "/class/net" #define SYSFS_FCHOST SYSFS_MOUNT "/class/fc_host" @@ -91,5 +90,7 @@ int check_symbolic_name_for_interface(const char *symbolic_name, 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); - +enum fcoe_status fcm_write_str_to_ctlr_attr(const char *ctlr, + const char *attr, + const char *str); #endif /* _FCOE_UTILS_H_ */ diff --git a/lib/fcoe_utils.c b/lib/fcoe_utils.c index 097a130..792ca49 100644 --- a/lib/fcoe_utils.c +++ b/lib/fcoe_utils.c @@ -285,3 +285,13 @@ enum fcoe_status fcoe_find_ctlr(const char *fchost, char *ctlr, int len) return rc; } + +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", SYSFS_FCOE_BUS_DEVICES, ctlr, attr); + return fcm_write_str_to_sysfs_file(path, str); +} _______________________________________________ fcoe-devel mailing list [email protected] http://lists.open-fcoe.org/mailman/listinfo/fcoe-devel
