Some comments for myself of changes queued for v2 of the patch set. Johannes Thumshirn <[email protected]> writes:
> Add sysfs_hba to to fcoemon_utils. This is the 1st part of obsoleting > libHBAAPI2 and libhbalinux2 for fcoe-utils. > > Signed-off-by: Johannes Thumshirn <[email protected]> > --- > Makefile.am | 7 +- > configure.ac | 3 + > fcoe-utils.spec.in | 2 +- > include/sysfs_hba.h | 64 +++++++++ > lib/sysfs_hba.c | 388 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 460 insertions(+), 4 deletions(-) > create mode 100644 include/sysfs_hba.h > create mode 100644 lib/sysfs_hba.c [..] > + ret = readlink(path, buf, sizeof(buf) - 1); > + free(path); > + if (ret == -1) { > + char realdev[256]; > + char *subif; > + size_t len; > + > + subif = strchr(netdev, '.'); if (subif == NULL) return NULL; or it will segfault here. > + len = strlen(netdev) - strlen(subif); > + strncpy(realdev, netdev, len); > + if (realdev[len] != '\0') > + realdev[len] = '\0'; > + > + ret = asprintf(&path, "%s/%s/lower_%s", SYSFS_NET_DIR, > + netdev, realdev); > + if (ret == -1) > + return NULL; > + > + ret = readlink(path, buf, sizeof(buf) -1 ); > + free(path); > + > + if (ret == -1) > + return NULL; > + } > + > + do { > + cp = strrchr(buf, '/'); > + if (!cp) > + break; > + > + ret = sscanf(cp + 1, "%x:%x:%x.%x", &dom, &bus, &dev, &func); > + if (ret == 4) > + break; > + > + *cp = '\0'; > + } while(cp && cp > buf); > + > + ret = asprintf(&pcidev, "%04x:%02x:%02x.%x\n", dom, bus, dev, func); - \n or it can't determine the driver name and version. > + if (ret == -1) > + return NULL; > + > + return pcidev; > +} > + > +char *get_host_from_netdev(const char *netdev) > +{ > + struct dirent *dp; > + char *host = NULL; > + char *path = NULL; > + DIR *dir; > + int ret; > + > + ret = asprintf(&path, "%s/%s/ctlr_0/", SYSFS_NET_DIR, netdev); > + if(ret == -1) > + return NULL; > + > + dir = opendir(path); > + free(path); > + path = NULL; > + > + if (!dir) > + return NULL; > + > + 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; > + > + host = strstr(dp->d_name, "host"); > + if (host) { > + struct stat sb; > + > + ret = asprintf(&path, "%s/%s/ctlr_0/%s/fc_host/%s", > + SYSFS_NET_DIR, netdev, host, host); > + if (ret == -1) > + goto out_closedir; > + > + ret = stat(path, &sb); > + free(path); > + path = NULL; > + > + if (ret == -1) > + host = NULL; > + break; > + > + } > + } > + > +out_closedir: > + closedir(dir); > + > + return host ? strdup(host) : NULL; > +} > + > +int get_number_of_adapters(void) > +{ > + struct dirent *dp; > + int num = 0; > + DIR *dir; > + > + dir = opendir(SYSFS_HOST_DIR); > + if (!dir) > + return errno; > + > + 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; > + > + if (strstr(dp->d_name, "host")) > + num++; > + > + } > + > + closedir(dir); > + > + return num; > +} -- Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850 _______________________________________________ fcoe-devel mailing list [email protected] http://lists.open-fcoe.org/mailman/listinfo/fcoe-devel
