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 routines, fcm_write_str_to_sysfs_file and fcm_write_str_to_ctlr_attr are 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 <robert.w.l...@intel.com> --- fcoemon.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++---- include/fcoe_utils.h | 24 +++++++++------ lib/fcoe_utils.c | 19 ++++++++++++ 3 files changed, 110 insertions(+), 15 deletions(-) diff --git a/fcoemon.c b/fcoemon.c index 1d00e73..26f8cfa 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -156,6 +156,16 @@ static void fcm_fcoe_action(struct fcm_netif *, struct fcoe_port *); static void fcp_set_next_action(struct fcoe_port *, enum fcp_action); static enum fcoe_status fcm_fcoe_if_action(char *, char *); +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", SYSFS_FCOE_BUS_DEVICES, ctlr, attr); + return fcm_write_str_to_sysfs_file(path, str); +} + /* * Used for backwards compatibility amongst libfcoe * "control" interfaces. @@ -167,10 +177,12 @@ struct libfcoe_interface_template { int (*disable)(struct fcm_netif *, struct fcoe_port *); }; -const struct libfcoe_interface_template *libfcoe_control; +static const struct libfcoe_interface_template *libfcoe_control; static int fcm_module_create(struct fcm_netif *ff, struct fcoe_port *p) { + int rc; + return fcm_fcoe_if_action(FCOE_CREATE, p->ifname); } @@ -196,6 +208,52 @@ static struct libfcoe_interface_template libfcoe_module_tmpl = { .disable = fcm_module_disable, }; +static int 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 int fcm_bus_create(struct fcm_netif *ff, struct fcoe_port *p) +{ + int rc; + + rc = fcm_write_str_to_sysfs_file(FCOE_BUS_CREATE, p->ifname); + if (rc) + return rc; + + /* + * 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); + rc = -ENOSYSFS; + } + + if (!rc) + rc = fcm_bus_enable(ff, p); + + return rc; +} + +static int fcm_bus_destroy(struct fcm_netif *ff, struct fcoe_port *p) +{ + return fcm_write_str_to_sysfs_file(FCOE_BUS_DESTROY, p->ifname); +} + +static int 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 */ @@ -1656,7 +1714,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; + } } /* @@ -2630,6 +2694,12 @@ 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 (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 @@ -2637,11 +2707,10 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p) */ 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)) - FCM_LOG_DBG("Failed to get ctlr for %s\n", 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); @@ -3492,7 +3561,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", SYSFS_FCOE_BUS_DEVICES, dname); status = n = scandir(path, &namelist, fchost_filter, alphasort); for (n-- ; n >= 0 ; n--) { if (rc) { @@ -3520,7 +3589,8 @@ 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(SYSFS_FCOE_BUS_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..6c81a2c 100644 --- a/include/fcoe_utils.h +++ b/include/fcoe_utils.h @@ -35,16 +35,21 @@ #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" -#define SYSFS_DEVICES SYSFS_MOUNT "/bus/fcoe/devices" -#define SYSFS_FCOE SYSFS_MOUNT "/module/libfcoe/parameters" +#define SYSFS_MOUNT "/sys" +#define SYSFS_NET SYSFS_MOUNT "/class/net" +#define SYSFS_FCHOST SYSFS_MOUNT "/class/fc_host" +#define SYSFS_FCOE_BUS SYSFS_MOUNT "/bus/fcoe" +#define SYSFS_FCOE_BUS_DEVICES SYSFS_FCOE_BUS "/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 SYSFS_FCOE SYSFS_MOUNT "/module/libfcoe/parameters" /* legacy */ +#define FCOE_CREATE SYSFS_FCOE "/create" /* legacy */ +#define FCOE_DESTROY SYSFS_FCOE "/destroy" /* legacy */ +#define FCOE_ENABLE SYSFS_FCOE "/enable" /* legacy */ +#define FCOE_DISABLE SYSFS_FCOE "/disable" /* legacy */ + +#define FCOE_BUS_CREATE SYSFS_FCOE_BUS "/ctlr_create" +#define FCOE_BUS_DESTROY SYSFS_FCOE_BUS "/ctlr_destroy" +#define FCOE_CTLR_ATTR_ENABLED "/enabled" #define FCHOSTBUFLEN 64 @@ -84,4 +89,5 @@ 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