initial import

This commit is contained in:
Dan Horák 2013-05-29 17:11:48 +02:00
parent 26afb6dc1e
commit fedf8ec67e
8 changed files with 457 additions and 0 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
/lib-zfcp-hbaapi-2.1.tar.gz

View File

@ -0,0 +1,69 @@
Description: zfcp-hbaapi: Fix crash on HBA_FreeLibrary call.
Symptom: zfcp_ping segmentation fault without any online adapters.
Problem: Segmentation fault happens on libzfcphbaapi if it build as vendor
library at this time when SNIA HBAAPI performs dlclose of
zfcp-hbaapi after clean-up function HBA_FreeLibrary.
zfcp-hbaapi has missing the event thread clean-up.
Solution: zfcp-hbaapi event thread cleanup has been coded using
pthread_cancel and pthread_join in HBA_FreeLibrary function.
Problem-ID: 72524
---
lib-zfcp-hbaapi-2.1/vlib.c | 16 ++++++++++++++++
lib-zfcp-hbaapi-2.1/vlib.h | 2 ++
lib-zfcp-hbaapi-2.1/vlib_events.c | 4 +---
3 files changed, 19 insertions(+), 3 deletions(-)
--- a/lib-zfcp-hbaapi-2.1/vlib.c
+++ b/lib-zfcp-hbaapi-2.1/vlib.c
@@ -169,6 +169,7 @@ HBA_STATUS HBA_LoadLibrary(void)
*/
HBA_STATUS HBA_FreeLibrary(void)
{
+ void *res;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
if (!vlib_data.isLoaded) {
@@ -183,6 +184,21 @@ HBA_STATUS HBA_FreeLibrary(void)
}
vlib_data.unloading = 1;
+ if (pthread_cancel(vlib_data.id) != 0) {
+ VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
+ return HBA_STATUS_ERROR;
+ }
+
+ if (pthread_join(vlib_data.id, &res) != 0) {
+ VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
+ return HBA_STATUS_ERROR;
+ }
+
+ if (res != PTHREAD_CANCELED) {
+ VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
+ return HBA_STATUS_ERROR;
+ }
+
closeAllAdapters();
vlib_data.isLoaded = 0;
--- a/lib-zfcp-hbaapi-2.1/vlib.h
+++ b/lib-zfcp-hbaapi-2.1/vlib.h
@@ -494,6 +494,8 @@ struct vlib_data {
struct block adapters; /**< @brief List of adapters
In fact this is the anchor of
the library's repository. */
+ pthread_t id; /**< @brief Pthread ID of event
+ handling thread*/
pthread_mutex_t mutex; /**< @brief Protects this structure */
};
--- a/lib-zfcp-hbaapi-2.1/vlib_events.c
+++ b/lib-zfcp-hbaapi-2.1/vlib_events.c
@@ -241,7 +241,5 @@ void cleanup_event_thread()
void start_event_thread()
{
- pthread_t id;
-
- pthread_create(&id, NULL, &establish_listener, NULL);
+ pthread_create(&vlib_data.id, NULL, &establish_listener, NULL);
}

View File

@ -0,0 +1,48 @@
---
lib-zfcp-hbaapi-2.1/vlib_sysfs.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
--- a/lib-zfcp-hbaapi-2.1/vlib_sysfs.c
+++ b/lib-zfcp-hbaapi-2.1/vlib_sysfs.c
@@ -310,14 +310,15 @@ HBA_STATUS sysfs_createAndReadConfigAdap
int sysfs_getUnitsFromPort(struct vlib_port *port)
{
char path[PATH_MAX];
- char unitPath[PATH_MAX];
+ char unitPath[PATH_MAX], unitPath2[PATH_MAX];
char attr[ATTR_MAX];
- char *sg;
+ char *sg, *sg2;
struct vlib_unit unit;
struct vlib_adapter *adapter;
- sfhelper_dir *dir, *sg_dir;
+ sfhelper_dir *dir, *sg_dir, *sg_dir2;
char *dirent;
int ret;
+ uint32_t sgindex;
adapter = getAdapterByHostNo(port->host);
if (!adapter)
@@ -369,6 +370,22 @@ int sysfs_getUnitsFromPort(struct vlib_p
if (ret == 1)
/* successful match */
break;
+ /* search match without CONFIG_SYSFS_DEPRECATED[_V2] */
+ if (strncmp(sg, "scsi_generic", 13 /* full */) != 0)
+ continue;
+ snprintf(unitPath2, PATH_MAX, "%s/%s", unitPath, sg);
+ sg_dir2 = sfhelper_opendir(unitPath2);
+ if (sg_dir2 == NULL)
+ continue;
+ while (sg2 = sfhelper_getNextDirEnt(sg_dir2)) {
+ if (sscanf(sg2, "sg%u", &sgindex) != 1)
+ continue;
+ snprintf(unit.sg_dev, sizeof(unit.sg_dev),
+ "%s", sg2);
+ /* successful match */
+ break;
+ }
+ sfhelper_closedir(sg_dir2);
}
sfhelper_closedir(sg_dir);
addUnitToRepos(port, &unit);

View File

@ -0,0 +1,26 @@
diff -up lib-zfcp-hbaapi-2.1/Makefile.am.module lib-zfcp-hbaapi-2.1/Makefile.am
--- lib-zfcp-hbaapi-2.1/Makefile.am.module 2010-07-21 09:55:20.000000000 +0200
+++ lib-zfcp-hbaapi-2.1/Makefile.am 2011-01-14 10:42:06.000000000 +0100
@@ -69,6 +69,10 @@ libzfcphbaapi_la_LDFLAGS = \
-lpthread -Wl,-init,_initvlib,-fini,_finivlib \
-export-symbols $(SYMFILE)
+if VENDORLIB
+libzfcphbaapi_la_LDFLAGS += -module -avoid-version -release $(VERSION)
+endif
+
bin_PROGRAMS = zfcp_ping zfcp_show
zfcp_ping_SOURCES = fc_tools/zfcp_ping.c
diff -up lib-zfcp-hbaapi-2.1/Makefile.in.module lib-zfcp-hbaapi-2.1/Makefile.in
--- lib-zfcp-hbaapi-2.1/Makefile.in.module 2010-09-17 13:17:17.000000000 +0200
+++ lib-zfcp-hbaapi-2.1/Makefile.in 2011-01-14 10:42:44.000000000 +0100
@@ -279,6 +279,8 @@ libzfcphbaapi_la_LDFLAGS = \
-lpthread -Wl,-init,_initvlib,-fini,_finivlib \
-export-symbols $(SYMFILE)
+@VENDORLIB_TRUE@libzfcphbaapi_la_LDFLAGS += -module -avoid-version -release $(VERSION)
+
zfcp_ping_SOURCES = fc_tools/zfcp_ping.c
zfcp_ping_LDADD = -lzfcphbaapi
zfcp_show_SOURCES = fc_tools/zfcp_show.c

View File

@ -0,0 +1,158 @@
---
lib-zfcp-hbaapi-2.1/vlib_sysfs.c | 52 +++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 26 deletions(-)
--- a/lib-zfcp-hbaapi-2.1/vlib_sysfs.c
+++ b/lib-zfcp-hbaapi-2.1/vlib_sysfs.c
@@ -47,13 +47,13 @@ static HBA_STATUS addPortByName(struct v
ret = sfhelper_getProperty(path, "node_name", attr);
if (!ret)
- port.wwnn = strtol(attr, NULL, 16);
+ port.wwnn = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "port_name", attr);
if (!ret)
- port.wwpn = strtol(attr, NULL, 16);
+ port.wwpn = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "port_id", attr);
if (!ret)
- port.did = strtol(attr, NULL, 16);
+ port.did = strtoul(attr, NULL, 16);
addPortToRepos(adapter, &port);
return HBA_STATUS_OK;
@@ -118,13 +118,13 @@ static HBA_STATUS addAdapterByDevPath(ch
ret = sfhelper_getProperty(classpath, "node_name", attr);
if (!ret)
- a.ident.wwnn = strtol(attr, NULL, 16);
+ a.ident.wwnn = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(classpath, "port_name", attr);
if (!ret)
- a.ident.wwpn = strtol(attr, NULL, 16);
+ a.ident.wwpn = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(classpath, "port_id", attr);
if (!ret)
- a.ident.did = strtol(attr, NULL, 16);
+ a.ident.did = strtoul(attr, NULL, 16);
addAdapterToRepos(&a);
@@ -151,17 +151,17 @@ static HBA_STATUS getPortAttributes(HBA_
/* Worldwide Port and Node Name */
ret = sfhelper_getProperty(classpath, "node_name", attr);
if (!ret)
- vlib_wwn_to_HBA_WWN(strtol(attr, NULL, 16),
+ vlib_wwn_to_HBA_WWN(strtoull(attr, NULL, 16),
&(*pPortattributes)->NodeWWN);
ret = sfhelper_getProperty(classpath, "port_name", attr);
if (!ret)
- vlib_wwn_to_HBA_WWN(strtol(attr, NULL, 16),
+ vlib_wwn_to_HBA_WWN(strtoull(attr, NULL, 16),
&(*pPortattributes)->PortWWN);
/* PortFcId */
ret = sfhelper_getProperty(classpath, "port_id", attr);
if (!ret)
- (*pPortattributes)->PortFcId = strtol(attr, NULL, 16);
+ (*pPortattributes)->PortFcId = strtoul(attr, NULL, 16);
/* Port Type */
ret = sfhelper_getProperty(classpath, "port_type", attr);
@@ -361,7 +361,7 @@ int sysfs_getUnitsFromPort(struct vlib_p
strcat(unitPath, dirent);
ret = sfhelper_getProperty(unitPath, "fcp_lun", attr);
if (!ret)
- unit.fcLun = strtol(attr, NULL, 16);
+ unit.fcLun = strtoull(attr, NULL, 16);
sg_dir = sfhelper_opendir(unitPath);
if (sg_dir == NULL)
continue;
@@ -514,7 +514,7 @@ HBA_STATUS sysfs_getAdapterAttributes(HB
ret = sfhelper_getProperty(adapter->ident.sysfsPath, "card_version",
attr);
if (!ret) {
- a = strtol(attr, NULL, 16);
+ a = strtoul(attr, NULL, 16);
strcpy((*pAttrs)->ModelDescription,
"zSeries/System z Fibre Channel Adapter ");
switch (a) {
@@ -612,63 +612,63 @@ HBA_STATUS sysfs_getPortStatistics(HBA_P
ret = sfhelper_getProperty(path, "seconds_since_last_reset", attr);
if (!ret)
- (*pS)->SecondsSinceLastReset = strtol(attr, NULL, 16);
+ (*pS)->SecondsSinceLastReset = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "tx_frames", attr);
if (!ret)
- (*pS)->TxFrames = strtol(attr, NULL, 16);
+ (*pS)->TxFrames = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "tx_words", attr);
if (!ret)
- (*pS)->TxWords = strtol(attr, NULL, 16);
+ (*pS)->TxWords = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "rx_frames", attr);
if (!ret)
- (*pS)->RxFrames = strtol(attr, NULL, 16);
+ (*pS)->RxFrames = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "rx_words", attr);
if (!ret)
- (*pS)->RxWords = strtol(attr, NULL, 16);
+ (*pS)->RxWords = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "lip_count", attr);
if (!ret)
- (*pS)->LIPCount = strtol(attr, NULL, 16);
+ (*pS)->LIPCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "nos_count", attr);
if (!ret)
- (*pS)->NOSCount = strtol(attr, NULL, 16);
+ (*pS)->NOSCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "error_frames", attr);
if (!ret)
- (*pS)->ErrorFrames = strtol(attr, NULL, 16);
+ (*pS)->ErrorFrames = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "dumped_frames", attr);
if (!ret)
- (*pS)->DumpedFrames = strtol(attr, NULL, 16);
+ (*pS)->DumpedFrames = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "link_failure_count", attr);
if (!ret)
- (*pS)->LinkFailureCount = strtol(attr, NULL, 16);
+ (*pS)->LinkFailureCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "loss_of_sync_count", attr);
if (!ret)
- (*pS)->LossOfSyncCount = strtol(attr, NULL, 16);
+ (*pS)->LossOfSyncCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "loss_of_signal_count", attr);
if (!ret)
- (*pS)->LossOfSignalCount = strtol(attr, NULL, 16);
+ (*pS)->LossOfSignalCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "prim_seq_protocol_err_count", attr);
if (!ret)
- (*pS)->PrimitiveSeqProtocolErrCount = strtol(attr, NULL, 16);
+ (*pS)->PrimitiveSeqProtocolErrCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "invalid_tx_word_count", attr);
if (!ret)
- (*pS)->InvalidTxWordCount = strtol(attr, NULL, 16);
+ (*pS)->InvalidTxWordCount = strtoull(attr, NULL, 16);
ret = sfhelper_getProperty(path, "invalid_crc_count", attr);
if (!ret)
- (*pS)->InvalidCRCCount = strtol(attr, NULL, 16);
+ (*pS)->InvalidCRCCount = strtoull(attr, NULL, 16);
return HBA_STATUS_OK;
}

View File

@ -0,0 +1,37 @@
diff -up lib-zfcp-hbaapi-2.1/Makefile.am.vendorlib lib-zfcp-hbaapi-2.1/Makefile.am
--- lib-zfcp-hbaapi-2.1/Makefile.am.vendorlib 2011-01-14 12:10:56.000000000 +0100
+++ lib-zfcp-hbaapi-2.1/Makefile.am 2011-01-14 12:12:02.000000000 +0100
@@ -76,9 +76,15 @@ endif
bin_PROGRAMS = zfcp_ping zfcp_show
zfcp_ping_SOURCES = fc_tools/zfcp_ping.c
-zfcp_ping_LDADD = -lzfcphbaapi
zfcp_show_SOURCES = fc_tools/zfcp_show.c
+
+if VENDORLIB
+zfcp_ping_LDADD = -lHBAAPI
+zfcp_show_LDADD = -lHBAAPI
+else
+zfcp_ping_LDADD = -lzfcphbaapi
zfcp_show_LDADD = -lzfcphbaapi
+endif
if DOCS
diff -up lib-zfcp-hbaapi-2.1/Makefile.in.vendorlib lib-zfcp-hbaapi-2.1/Makefile.in
--- lib-zfcp-hbaapi-2.1/Makefile.in.vendorlib 2011-01-14 12:11:01.000000000 +0100
+++ lib-zfcp-hbaapi-2.1/Makefile.in 2011-01-14 12:13:05.000000000 +0100
@@ -282,9 +282,11 @@ libzfcphbaapi_la_LDFLAGS = \
@VENDORLIB_TRUE@libzfcphbaapi_la_LDFLAGS += -module -avoid-version -release $(VERSION)
zfcp_ping_SOURCES = fc_tools/zfcp_ping.c
-zfcp_ping_LDADD = -lzfcphbaapi
zfcp_show_SOURCES = fc_tools/zfcp_show.c
-zfcp_show_LDADD = -lzfcphbaapi
+@VENDORLIB_TRUE@zfcp_ping_LDADD = -lHBAAPI
+@VENDORLIB_TRUE@zfcp_show_LDADD = -lHBAAPI
+@VENDORLIB_FALSE@zfcp_ping_LDADD = -lzfcphbaapi
+@VENDORLIB_FALSE@zfcp_show_LDADD = -lzfcphbaapi
@DOCS_FALSE@man_MANS = zfcp_show.8 zfcp_ping.8 libzfcphbaapi.3
@DOCS_TRUE@man_MANS = libzfcphbaapi.3 dox/man/man3/SupportedHBAAPIs.3 \
@DOCS_TRUE@ dox/man/man3/UnSupportedHBAAPIs.3 dox/man/man3/hbaapi.h.3 \

117
libzfcphbaapi.spec Normal file
View File

@ -0,0 +1,117 @@
%global srcname lib-zfcp-hbaapi
Name: libzfcphbaapi
Summary: HBA API for the zFCP device driver
Group: System Environment/Libraries
Version: 2.1
Release: 2%{?dist}
License: CPL
URL: http://www.ibm.com/developerworks/linux/linux390/zfcp-hbaapi.html
# http://www.ibm.com/developerworks/linux/linux390/zfcp-hbaapi-%%{hbaapiver}.html
Source0: http://download.boulder.ibm.com/ibmdl/pub/software/dw/linux390/ht_src/%{srcname}-%{version}.tar.gz
ExclusiveArch: s390 s390x
BuildRequires: automake
BuildRequires: doxygen
BuildRequires: libsysfs-devel
BuildRequires: sg3_utils-devel
BuildRequires: libhbaapi-devel
Requires: libhbaapi
Requires(post): grep
Requires(postun): grep sed
Provides: s390utils-libzfcphbaapi = 2:1.20.0-4
Obsoletes: s390utils-libzfcphbaapi <= 2:1.20.0-3
# exclude plugin soname from Provides
%global __provides_exclude ^(libzfcphbaapi-%{version}[.]so.*)$
# build the library as a module
Patch1: %{srcname}-2.1-module.patch
# fix linking of the tools when using vendor library mode
Patch2: %{srcname}-2.1-vendorlib.patch
# fix crash on HBA_FreeLibrary call (#713817)
Patch3: %{srcname}-2.1-HBA_FreeLibrary.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=951586
Patch4: %{srcname}-2.1-parse-u64-as-ull.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=949099
Patch5: %{srcname}-2.1-find-sg-without-sysfs-deprecated.patch
%description
zFCP HBA API Library is an implementation of FC-HBA (see www.t11.org) for
the zFCP device driver.
%package docs
License: CPL
Summary: zFCP HBA API Library -- Documentation
Group: Development/Libraries
URL: http://www.ibm.com/developerworks/linux/linux390/zfcp-hbaapi.html
Requires: %{name} = %{version}-%{release}
Provides: s390utils-libzfcphbaapi-docs = 2:1.20.0-4
Obsoletes: s390utils-libzfcphbaapi-docs <= 2:1.20.0-3
%description docs
Documentation for the zFCP HBA API Library.
%prep
%setup -q -n %{srcname}-%{version}
%patch1 -p1 -b .module
%patch2 -p1 -b .vendorlib
%patch3 -p2 -b .HBA_FreeLibrary
%patch4 -p2 -b .parse-as-ull
%patch5 -p2 -b .find-sg
# lib-zfcp-hbaapi: fix perms
chmod a-x *.h AUTHORS README ChangeLog LICENSE
%build
%configure --disable-static --enable-vendor-lib
make EXTRA_CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing"
%install
%makeinstall docdir=$RPM_BUILD_ROOT%{_docdir}/%{name}-%{version}
# keep only html docs
rm -rf $RPM_BUILD_ROOT%{_docdir}/%{srcname}-%{version}/latex
# remove unwanted files
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}.*
%post
grep -q -e "^libzfcphbaapi" /etc/hba.conf ||
echo "libzfcphbaapi %{_libdir}/libzfcphbaapi-%{version}.so" >> /etc/hba.conf
:
%preun
grep -q -e "^libzfcphbaapi" /etc/hba.conf &&
sed -i.orig -e "/^libzfcphbaapi/d" /etc/hba.conf
:
%files
%doc README COPYING ChangeLog AUTHORS LICENSE
%{_bindir}/zfcp_ping
%{_bindir}/zfcp_show
%{_libdir}/%{name}-%{version}.so
%{_mandir}/man3/libzfcphbaapi.3*
%{_mandir}/man3/SupportedHBAAPIs.3*
%{_mandir}/man3/UnSupportedHBAAPIs.3*
%{_mandir}/man8/zfcp_ping.8*
%{_mandir}/man8/zfcp_show.8*
%exclude %{_mandir}/man3/hbaapi.h.3*
%files docs
%docdir %{_docdir}/%{name}-%{version}
%{_docdir}/%{name}-%{version}/
%changelog
* Wed May 29 2013 Dan Horák <dan[at]danny.cz> - 2.1-2
- add missing compatibility Provides
- exclude plugin soname from Provides
* Thu May 16 2013 Dan Horák <dan[at]danny.cz> - 2.1-1
- move libzfcphbaapi to own package from s390utils

View File

@ -0,0 +1 @@
ecf3ff0ac4469db7297ebd6f7607fb48 lib-zfcp-hbaapi-2.1.tar.gz