Move sysfs() stuff to libibumad tree. Now libibumad doesn't depend from libibcommon anymore - remove this dependency.
Signed-off-by: Sasha Khapyorsky <[email protected]> --- On 13:28 Fri 19 Dec , Hal Rosenstock wrote: > On Fri, Dec 19, 2008 at 1:24 PM, Sean Hefty <[email protected]> wrote: > >>Sasha has written some comments on the general list indicating that > >>libibcommon may disappear in the future. It could be combined with > >>libibumad (as libibmad (and diags) both use it. > > > > I'd much rather see it integrated with libibmad than libibumad. libibumad > > is > > fairly self-contained as the interface into the kernel. > > That's fine as long as things that use libibumad don't now require > libibmad as an additional dependency for something that was in > libibcommon. I don't know if there's anything like that. xdump > wouldn't cause that. I haven't looked at the rest of libibcommon and > the implications. After this patch libibumad doesn't depend from libibcommon anymore. I think we can just merge libibmad and libibcommon and eventually to remove libibcommon at all. infiniband-diags/configure.in | 4 +- infiniband-diags/src/mcm_rereg_test.c | 1 + libibcommon/Makefile.am | 2 +- libibcommon/include/infiniband/common.h | 7 -- libibcommon/libibcommon.ver | 2 +- libibcommon/src/libibcommon.map | 5 - libibcommon/src/sysfs.c | 167 ------------------------------- libibmad/configure.in | 4 +- libibmad/src/gs.c | 1 + libibmad/src/register.c | 1 + libibmad/src/rpc.c | 1 + libibumad/Makefile.am | 2 +- libibumad/configure.in | 13 --- libibumad/include/infiniband/umad.h | 1 - libibumad/libibumad.spec.in | 4 +- libibumad/src/sysfs.c | 158 +++++++++++++++++++++++++++++ libibumad/src/umad.c | 9 ++ 17 files changed, 180 insertions(+), 202 deletions(-) delete mode 100644 libibcommon/src/sysfs.c create mode 100644 libibumad/src/sysfs.c diff --git a/infiniband-diags/configure.in b/infiniband-diags/configure.in index d8524f4..17204a4 100644 --- a/infiniband-diags/configure.in +++ b/infiniband-diags/configure.in @@ -32,8 +32,8 @@ AC_PROG_LIBTOOL if test "$disable_libcheck" != "yes" then dnl Checks for libraries -AC_CHECK_LIB(ibcommon, sys_read_string, [], - AC_MSG_ERROR([sys_read_string() not found. diags require libibcommon.])) +AC_CHECK_LIB(ibcommon, ibpanic, [], + AC_MSG_ERROR([ibpanic() not found. diags require libibcommon.])) AC_CHECK_LIB(ibumad, umad_init, [], AC_MSG_ERROR([umad_init() not found. diags require libibumad.])) AC_CHECK_LIB(ibmad, mad_dump_int, [], diff --git a/infiniband-diags/src/mcm_rereg_test.c b/infiniband-diags/src/mcm_rereg_test.c index 9285b95..0ba9901 100644 --- a/infiniband-diags/src/mcm_rereg_test.c +++ b/infiniband-diags/src/mcm_rereg_test.c @@ -36,6 +36,7 @@ #include <errno.h> #include <inttypes.h> +#include <infiniband/common.h> #include <infiniband/umad.h> #include <infiniband/mad.h> diff --git a/libibcommon/Makefile.am b/libibcommon/Makefile.am index 75889f4..00e5bc8 100644 --- a/libibcommon/Makefile.am +++ b/libibcommon/Makefile.am @@ -13,7 +13,7 @@ else libibcommon_version_script = endif -libibcommon_la_SOURCES = src/stack.c src/sysfs.c src/util.c src/time.c src/hash.c +libibcommon_la_SOURCES = src/stack.c src/util.c src/time.c src/hash.c libibcommon_la_LDFLAGS = -version-info $(ibcommon_api_version) \ -export-dynamic $(libibcommon_version_script) libibcommon_la_DEPENDENCIES = $(srcdir)/src/libibcommon.map diff --git a/libibcommon/include/infiniband/common.h b/libibcommon/include/infiniband/common.h index 01fc796..287703f 100644 --- a/libibcommon/include/infiniband/common.h +++ b/libibcommon/include/infiniband/common.h @@ -121,13 +121,6 @@ void logmsg(const char *const fn, char *msg, ...) IBCOMMON_STRICT_FORMAT; void xdump(FILE *file, char *msg, void *p, int size); -/* sysfs.c: /sys utilities */ -int sys_read_string(char *dir_name, char *file_name, char *str, int max_len); -int sys_read_guid(char *dir_name, char *file_name, uint64_t *net_guid); -int sys_read_gid(char *dir_name, char *file_name, uint8_t *gid); -int sys_read_uint64(char *dir_name, char *file_name, uint64_t *u); -int sys_read_uint(char *dir_name, char *file_name, unsigned *u); - /* stack.c */ void stack_dump(void); void enable_stack_dump(int loop); diff --git a/libibcommon/libibcommon.ver b/libibcommon/libibcommon.ver index 7b88f1b..22b16d9 100644 --- a/libibcommon/libibcommon.ver +++ b/libibcommon/libibcommon.ver @@ -6,4 +6,4 @@ # API_REV - advance on any added API # RUNNING_REV - advance any change to the vendor files # AGE - number of backward versions the API still supports -LIBVERSION=1:0:0 +LIBVERSION=2:1:1 diff --git a/libibcommon/src/libibcommon.map b/libibcommon/src/libibcommon.map index 96ce2d8..f1f693a 100644 --- a/libibcommon/src/libibcommon.map +++ b/libibcommon/src/libibcommon.map @@ -2,11 +2,6 @@ IBCOMMON_1.0 { global: enable_stack_dump; stack_dump; - sys_read_gid; - sys_read_guid; - sys_read_string; - sys_read_uint; - sys_read_uint64; getcurrenttime; fhash; logmsg; diff --git a/libibcommon/src/sysfs.c b/libibcommon/src/sysfs.c deleted file mode 100644 index 3c23010..0000000 --- a/libibcommon/src/sysfs.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -#define _GNU_SOURCE - -#if HAVE_CONFIG_H -# include <config.h> -#endif /* HAVE_CONFIG_H */ - -#include <inttypes.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <stdarg.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <unistd.h> -#include <string.h> -#include <endian.h> -#include <byteswap.h> -#include <sys/poll.h> -#include <syslog.h> -#include <netinet/in.h> -#include <errno.h> - -#include "common.h" - -static int -ret_code(void) -{ - int e = errno; - - if (e > 0) - return -e; - return e; -} - -int -sys_read_string(char *dir_name, char *file_name, char *str, int max_len) -{ - char path[256], *s; - int fd, r; - - snprintf(path, sizeof(path), "%s/%s", dir_name, file_name); - - if ((fd = open(path, O_RDONLY)) < 0) - return ret_code(); - - if ((r = read(fd, str, max_len)) < 0) { - int e = errno; - close(fd); - errno = e; - return ret_code(); - } - - str[(r < max_len) ? r : max_len - 1] = 0; - - if ((s = strrchr(str, '\n'))) - *s = 0; - - close(fd); - return 0; -} - -int -sys_read_guid(char *dir_name, char *file_name, uint64_t *net_guid) -{ - char buf[32], *str, *s; - uint64_t guid; - int r, i; - - if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) - return r; - - guid = 0; - - for (s = buf, i = 0 ; i < 4; i++) { - if (!(str = strsep(&s, ": \t\n"))) - return -EINVAL; - guid = (guid << 16) | (strtoul(str, 0, 16) & 0xffff); - } - - *net_guid = htonll(guid); - - return 0; -} - -int -sys_read_gid(char *dir_name, char *file_name, uint8_t *gid) -{ - char buf[64], *str, *s; - uint16_t *ugid = (uint16_t *)gid; - int r, i; - - if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) - return r; - - for (s = buf, i = 0 ; i < 8; i++) { - if (!(str = strsep(&s, ": \t\n"))) - return -EINVAL; - ugid[i] = htons(strtoul(str, 0, 16) & 0xffff); - } - - return 0; -} - -int -sys_read_uint64(char *dir_name, char *file_name, uint64_t *u) -{ - char buf[32]; - int r; - - if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) - return r; - - *u = strtoull(buf, 0, 0); - - return 0; -} - -int -sys_read_uint(char *dir_name, char *file_name, unsigned *u) -{ - char buf[32]; - int r; - - if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) - return r; - - *u = strtoul(buf, 0, 0); - - return 0; -} diff --git a/libibmad/configure.in b/libibmad/configure.in index 3d8e73d..22ea5ef 100644 --- a/libibmad/configure.in +++ b/libibmad/configure.in @@ -31,8 +31,8 @@ AC_PROG_CC dnl Checks for libraries if test "$disable_libcheck" != "yes" then -AC_CHECK_LIB(ibcommon, sys_read_string, [], - AC_MSG_ERROR([sys_read_string() not found. libibmad requires libibcommon.])) +AC_CHECK_LIB(ibcommon, ibpanic, [], + AC_MSG_ERROR([ibpanic() not found. libibmad requires libibcommon.])) AC_CHECK_LIB(ibumad, umad_init, [], AC_MSG_ERROR([umad_init() not found. libibmad requires libibumad.])) fi diff --git a/libibmad/src/gs.c b/libibmad/src/gs.c index 89c927e..cade54b 100644 --- a/libibmad/src/gs.c +++ b/libibmad/src/gs.c @@ -42,6 +42,7 @@ #include <pthread.h> #include <sys/time.h> +#include <infiniband/common.h> #include <infiniband/umad.h> #include "mad.h" diff --git a/libibmad/src/register.c b/libibmad/src/register.c index a33acd8..8e59e6e 100644 --- a/libibmad/src/register.c +++ b/libibmad/src/register.c @@ -43,6 +43,7 @@ #include <string.h> #include <errno.h> +#include <infiniband/common.h> #include <infiniband/umad.h> #include "mad.h" diff --git a/libibmad/src/rpc.c b/libibmad/src/rpc.c index df28f65..34a6b9a 100644 --- a/libibmad/src/rpc.c +++ b/libibmad/src/rpc.c @@ -43,6 +43,7 @@ #include <string.h> #include <errno.h> +#include <infiniband/common.h> #include <infiniband/umad.h> #include "mad.h" diff --git a/libibumad/Makefile.am b/libibumad/Makefile.am index 1e3e6fd..50222df 100644 --- a/libibumad/Makefile.am +++ b/libibumad/Makefile.am @@ -27,7 +27,7 @@ else libibumad_version_script = endif -libibumad_la_SOURCES = src/umad.c +libibumad_la_SOURCES = src/umad.c src/sysfs.c libibumad_la_LDFLAGS = -version-info $(ibumad_api_version) \ -export-dynamic $(libibumad_version_script) libibumad_la_DEPENDENCIES = $(srcdir)/src/libibumad.map diff --git a/libibumad/configure.in b/libibumad/configure.in index ad3afcd..3a08771 100644 --- a/libibumad/configure.in +++ b/libibumad/configure.in @@ -44,23 +44,10 @@ AC_PROG_LN_S AC_PROG_MAKE_SET AM_PROG_LIBTOOL -if test "$disable_libcheck" != "yes" -then -dnl Checks for libraries -AC_CHECK_LIB(ibcommon, sys_read_string, [], - AC_MSG_ERROR([sys_read_string() not found. libibumad requires libibcommon.])) -fi - dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC AC_CHECK_HEADERS([fcntl.h netinet/in.h stdlib.h string.h sys/ioctl.h unistd.h]) -if test "$disable_libcheck" != "yes" -then -AC_CHECK_HEADER(infiniband/common.h, [], - AC_MSG_ERROR([<infiniband/common.h> not found. libibumad requires libibcommon.]) -) -fi dnl Checks for library functions AC_PROG_GCC_TRADITIONAL diff --git a/libibumad/include/infiniband/umad.h b/libibumad/include/infiniband/umad.h index 7d97c25..91ccf1d 100644 --- a/libibumad/include/infiniband/umad.h +++ b/libibumad/include/infiniband/umad.h @@ -34,7 +34,6 @@ #define _UMAD_H #include <stdint.h> -#include <infiniband/common.h> #ifdef __cplusplus # define BEGIN_C_DECLS extern "C" { diff --git a/libibumad/libibumad.spec.in b/libibumad/libibumad.spec.in index 1b11d18..7732edd 100644 --- a/libibumad/libibumad.spec.in +++ b/libibumad/libibumad.spec.in @@ -13,7 +13,7 @@ Source: http://www.openfabrics.org/downloads/management/@TARBALL@ Url: http://openfabrics.org Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig -BuildRequires: libibcommon-devel, libtool +BuildRequires: libtool %description libibumad provides the user MAD library functions which sit on top of @@ -23,7 +23,7 @@ and management tools, including OpenSM. %package devel Summary: Development files for the libibumad library Group: System Environment/Libraries -Requires: %{name} = %{version}-%{release} libibcommon-devel +Requires: %{name} = %{version}-%{release} Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/libibumad/src/sysfs.c b/libibumad/src/sysfs.c new file mode 100644 index 0000000..af5545e --- /dev/null +++ b/libibumad/src/sysfs.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#define _GNU_SOURCE + +#if HAVE_CONFIG_H +# include <config.h> +#endif /* HAVE_CONFIG_H */ + +#include <inttypes.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <endian.h> +#include <byteswap.h> +#include <netinet/in.h> + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonll(x) bswap_64(x) +#else +#define htonll(x) (x) +#endif + +static int ret_code(void) +{ + int e = errno; + + if (e > 0) + return -e; + return e; +} + +int sys_read_string(char *dir_name, char *file_name, char *str, int max_len) +{ + char path[256], *s; + int fd, r; + + snprintf(path, sizeof(path), "%s/%s", dir_name, file_name); + + if ((fd = open(path, O_RDONLY)) < 0) + return ret_code(); + + if ((r = read(fd, str, max_len)) < 0) { + int e = errno; + close(fd); + errno = e; + return ret_code(); + } + + str[(r < max_len) ? r : max_len - 1] = 0; + + if ((s = strrchr(str, '\n'))) + *s = 0; + + close(fd); + return 0; +} + +int sys_read_guid(char *dir_name, char *file_name, uint64_t *net_guid) +{ + char buf[32], *str, *s; + uint64_t guid; + int r, i; + + if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) + return r; + + guid = 0; + + for (s = buf, i = 0 ; i < 4; i++) { + if (!(str = strsep(&s, ": \t\n"))) + return -EINVAL; + guid = (guid << 16) | (strtoul(str, 0, 16) & 0xffff); + } + + *net_guid = htonll(guid); + + return 0; +} + +int sys_read_gid(char *dir_name, char *file_name, uint8_t *gid) +{ + char buf[64], *str, *s; + uint16_t *ugid = (uint16_t *)gid; + int r, i; + + if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) + return r; + + for (s = buf, i = 0 ; i < 8; i++) { + if (!(str = strsep(&s, ": \t\n"))) + return -EINVAL; + ugid[i] = htons(strtoul(str, 0, 16) & 0xffff); + } + + return 0; +} + +int sys_read_uint64(char *dir_name, char *file_name, uint64_t *u) +{ + char buf[32]; + int r; + + if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) + return r; + + *u = strtoull(buf, 0, 0); + + return 0; +} + +int sys_read_uint(char *dir_name, char *file_name, unsigned *u) +{ + char buf[32]; + int r; + + if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0) + return r; + + *u = strtoul(buf, 0, 0); + + return 0; +} diff --git a/libibumad/src/umad.c b/libibumad/src/umad.c index 3713ffe..c233de9 100644 --- a/libibumad/src/umad.c +++ b/libibumad/src/umad.c @@ -38,6 +38,7 @@ #include <sys/poll.h> #include <unistd.h> #include <string.h> +#include <stdio.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> @@ -76,6 +77,14 @@ typedef struct ib_user_mad_reg_req { uint8_t rmpp_version; } ib_user_mad_reg_req_t; +extern int sys_read_string(char *dir_name, char *file_name, char *str, int len); +extern int sys_read_guid(char *dir_name, char *file_name, uint64_t *net_guid); +extern int sys_read_gid(char *dir_name, char *file_name, uint8_t *gid); +extern int sys_read_uint64(char *dir_name, char *file_name, uint64_t *u); +extern int sys_read_uint(char *dir_name, char *file_name, unsigned *u); + +#define IBWARN(fmt, args...) fprintf(stdout, "ibwarn: [%d] %s: " fmt, getpid(), __func__, ## args) + #define TRACE if (umaddebug) IBWARN #define DEBUG if (umaddebug) IBWARN -- 1.6.0.4.766.g6fc4a _______________________________________________ general mailing list [email protected] http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
