File 0018-support-multiple-connections.patch of Package fcoe-utils
lib/sysfs_hba.c: Allow support for multiple FCoE connections
sysfs_hba.c had the 1st controller number hardcoded, so it was impossible to
have more than one FCoE connection on a system.
This patch also reads the controller number for a given net device from sysfs.
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
lib/sysfs_hba.c | 42 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)
--- a/lib/sysfs_hba.c
+++ b/lib/sysfs_hba.c
@@ -531,6 +531,37 @@ char *get_rport_by_fcid(uint32_t fcid)
return rport;
}
+static int get_ctlr_num(const char *netdev)
+{
+ struct dirent *dp;
+ int ctlr_num = -1;
+ char path[1024];
+ char *ctlr;
+ DIR *dir;
+
+ sprintf(path, "%s/%s", SYSFS_NET_DIR, netdev);
+
+ dir = opendir(path);
+ if (!dir)
+ return -1;
+
+ for (dp = readdir(dir); dp != NULL; dp = readdir(dir)) {
+ if (dp->d_name[0] == '.' && dp->d_name[1] == '\0') continue;
+ if (dp->d_name[1] == '.' && dp->d_name[2] == '\0') continue;
+
+ ctlr = strstr(dp->d_name, "ctlr_");
+ if (!ctlr)
+ continue;
+
+ ctlr_num = atoi(&ctlr[strlen(ctlr) - 1]);
+ break;
+ }
+
+ closedir(dir);
+
+ return ctlr_num;
+}
+
char *get_host_from_netdev(const char *netdev)
{
struct dirent *dp;
@@ -538,8 +569,13 @@ char *get_host_from_netdev(const char *n
char *path = NULL;
DIR *dir;
int ret;
+ int ctlr_num;
+
+ ctlr_num = get_ctlr_num(netdev);
+ if (ctlr_num == -1)
+ return NULL;
- ret = asprintf(&path, "%s/%s/ctlr_0/", SYSFS_NET_DIR, netdev);
+ ret = asprintf(&path, "%s/%s/ctlr_%d/", SYSFS_NET_DIR, netdev, ctlr_num);
if(ret == -1)
return NULL;
@@ -558,8 +594,8 @@ char *get_host_from_netdev(const char *n
if (host) {
struct stat sb;
- ret = asprintf(&path, "%s/%s/ctlr_0/%s/fc_host/%s",
- SYSFS_NET_DIR, netdev, host, host);
+ ret = asprintf(&path, "%s/%s/ctlr_%d/%s/fc_host/%s",
+ SYSFS_NET_DIR, netdev, ctlr_num, host, host);
if (ret == -1)
goto out_closedir;