Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package ibsim for openSUSE:Factory checked 
in at 2021-04-29 01:38:21
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ibsim (Old)
 and      /work/SRC/openSUSE:Factory/.ibsim.new.12324 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ibsim"

Thu Apr 29 01:38:21 2021 rev:14 rq:889001 version:0.10

Changes:
--------
--- /work/SRC/openSUSE:Factory/ibsim/ibsim.changes      2021-04-27 
21:35:36.728077611 +0200
+++ /work/SRC/openSUSE:Factory/.ibsim.new.12324/ibsim.changes   2021-04-29 
01:39:27.630668577 +0200
@@ -1,0 +2,10 @@
+Wed Apr 28 07:49:11 UTC 2021 - Nicolas Morey-Chaisemartin 
<[email protected]>
+
+- Update to version 0.10
+  - Support multiple umad file descriptors
+  - Support latest libibumad
+  - Added ibsim-run, a wrapper to run programs under ibsim
+- Refresh ibsim-PIE.patch against latest sources
+- Add typo-scrips.patch to fix compilation for ibsim-run
+
+-------------------------------------------------------------------

Old:
----
  ibsim-0.9.0.7c2a604ec49a.tar.gz

New:
----
  ibsim-0.10.0.c7e430dc3d9b.tar.gz
  typo-scrips.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ibsim.spec ++++++
--- /var/tmp/diff_new_pack.5VmQjN/_old  2021-04-29 01:39:28.146669307 +0200
+++ /var/tmp/diff_new_pack.5VmQjN/_new  2021-04-29 01:39:28.146669307 +0200
@@ -16,10 +16,10 @@
 #
 
 
-%define git_ver .0.7c2a604ec49a
+%define git_ver .0.c7e430dc3d9b
 
 Name:           ibsim
-Version:        0.9
+Version:        0.10
 Release:        0
 Summary:        InfiniBand fabric simulator for management
 License:        BSD-2-Clause OR GPL-2.0-only
@@ -27,6 +27,8 @@
 Source:         ibsim-%{version}%{git_ver}.tar.gz
 Patch1:         ibsim-fix_type_punning.patch
 Patch2:         ibsim-PIE.patch
+# Backported from upstream
+Patch3:         typo-scrips.patch
 URL:            https://github.com/linux-rdma/ibsim
 BuildRequires:  infiniband-diags-devel
 BuildRequires:  libibumad-devel
@@ -39,7 +41,8 @@
 %prep
 %setup -q -n  %{name}-%{version}%{git_ver}
 %patch1
-%patch2 -p1
+%patch2
+%patch3
 
 %build
 export CFLAGS="%{optflags}"
@@ -55,6 +58,7 @@
 %dir %{_libdir}/umad2sim
 %{_libdir}/umad2sim/libumad2sim*.so*
 %{_bindir}/ibsim
+%{_bindir}/ibsim-run
 %doc README TODO net-examples scripts
 %license COPYING
 

++++++ _service ++++++
--- /var/tmp/diff_new_pack.5VmQjN/_old  2021-04-29 01:39:28.174669347 +0200
+++ /var/tmp/diff_new_pack.5VmQjN/_new  2021-04-29 01:39:28.178669352 +0200
@@ -6,9 +6,9 @@
     <param name="exclude">.git</param>
     <param name="filename">ibsim</param>
     <param name="versionformat">@PARENT_TAG@.@TAG_OFFSET@.%h</param>
-    <param name="versionrewrite-pattern">ibsim(.*)</param>
+    <param name="versionrewrite-pattern">ibsim-(.*)</param>
     <param name="versionrewrite-replacement">\1</param>
-    <param name="revision">7c2a604ec49a772edbff5381f056c8ab8245a19d</param>
+    <param name="revision">c7e430dc3d9bb677e53a8cd9ca87c5d27d406aa1</param>
   </service>
   <service name="recompress" mode="disabled">
     <param name="file">*ibsim*.tar</param>

++++++ ibsim-0.9.0.7c2a604ec49a.tar.gz -> ibsim-0.10.0.c7e430dc3d9b.tar.gz 
++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/changelog 
new/ibsim-0.10.0.c7e430dc3d9b/debian/changelog
--- old/ibsim-0.9.0.7c2a604ec49a/debian/changelog       1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/changelog      2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1,11 @@
+ibsim (0.9) unstable; urgency=low
+
+  * Switch to Github.
+
+ --  Tzafrir Cohen <[email protected]>  Sun, 12 Apr 2020 11:14:12 +0300
+
+ibsim (0.6) unstable; urgency=low
+
+  * Initial release
+
+ --  Ilya Nelkenbaum <[email protected]>  Mon, 11 Mar 2013 11:03:54 +0200
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/compat 
new/ibsim-0.10.0.c7e430dc3d9b/debian/compat
--- old/ibsim-0.9.0.7c2a604ec49a/debian/compat  1970-01-01 01:00:00.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/compat 2020-10-08 07:31:29.000000000 
+0200
@@ -0,0 +1 @@
+9
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/control 
new/ibsim-0.10.0.c7e430dc3d9b/debian/control
--- old/ibsim-0.9.0.7c2a604ec49a/debian/control 1970-01-01 01:00:00.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/control        2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1,19 @@
+Source: ibsim
+Section: net
+Priority: extra
+Maintainer: Tzafrir Cohen <[email protected]>
+Build-Depends: debhelper (>= 9), libibumad-dev, libibmad-dev
+Standards-Version: 4.13
+Homepage: https://github.com/linux-rdma/ibsim
+
+Package: ibsim
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: InfiniBand fabric simulator for management
+ ibsim provides simulation of infiniband fabric for using with OFA OpenSM,
+ diagnostic and management tools.
+
+Package: ibsim-doc
+Architecture: all
+Description: documentation for ibsim
+ Documentation for ibsim
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/copyright 
new/ibsim-0.10.0.c7e430dc3d9b/debian/copyright
--- old/ibsim-0.9.0.7c2a604ec49a/debian/copyright       1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/copyright      2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1,62 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: ibsim
+Source: https://github.com/linux-rdma/ibsim/
+
+Files: *
+Copyright:
+  2004-2008, Voltaire, Inc.
+  2010-2017, Mellanox Technologies LTD.
+License: BSD-2+GPL-2
+
+Files: ibsim/sim_mad.c
+Copyright: 2004-2008, Voltaire, Inc.
+  2009, HNR Consulting.
+  2011, Mellanox Technologies LTD.
+License: BSD-2+GPL-2
+
+Files: tests/mcast_storm.c
+ tests/query_many.c
+ tests/subnet_discover.c
+Copyright: 2006-2008, Voltaire, Inc.
+  2009, Voltaire, Inc.
+License: GPL-2+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+ .
+ on Debian system in the file /usr/share/common-licenses/GPL-2.
+Comment:
+ Those are tests that are included in the source and built, but are not
+ currently included in any binary package.
+
+License: BSD-2+GPL-2
+ ibsim 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.
+ .
+ on Debian system in the file /usr/share/common-licenses/GPL-2.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/docs 
new/ibsim-0.10.0.c7e430dc3d9b/debian/docs
--- old/ibsim-0.9.0.7c2a604ec49a/debian/docs    1970-01-01 01:00:00.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/docs   2020-10-08 07:31:29.000000000 
+0200
@@ -0,0 +1,4 @@
+README
+TODO
+net-examples
+scripts
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/ibsim-doc.docs 
new/ibsim-0.10.0.c7e430dc3d9b/debian/ibsim-doc.docs
--- old/ibsim-0.9.0.7c2a604ec49a/debian/ibsim-doc.docs  1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/ibsim-doc.docs 2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1 @@
+#DOCS#
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/ibsim-doc.install 
new/ibsim-0.10.0.c7e430dc3d9b/debian/ibsim-doc.install
--- old/ibsim-0.9.0.7c2a604ec49a/debian/ibsim-doc.install       1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/ibsim-doc.install      2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1 @@
+#DOCS#
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/ibsim.install 
new/ibsim-0.10.0.c7e430dc3d9b/debian/ibsim.install
--- old/ibsim-0.9.0.7c2a604ec49a/debian/ibsim.install   1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/ibsim.install  2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1,2 @@
+usr/lib
+usr/bin
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/rules 
new/ibsim-0.10.0.c7e430dc3d9b/debian/rules
--- old/ibsim-0.9.0.7c2a604ec49a/debian/rules   1970-01-01 01:00:00.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/rules  2020-10-08 07:31:29.000000000 
+0200
@@ -0,0 +1,21 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+#
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+#
+# Modified to make a template file for a multi-binary package with separated
+# build-arch and build-indep targets  by Bill Allombert 2001
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+# This has to be exported to make some magic below work.
+export DH_OPTIONS
+
+
+%:
+       dh $@
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/debian/source/format 
new/ibsim-0.10.0.c7e430dc3d9b/debian/source/format
--- old/ibsim-0.9.0.7c2a604ec49a/debian/source/format   1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/debian/source/format  2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1 @@
+3.0 (native)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/defs.mk 
new/ibsim-0.10.0.c7e430dc3d9b/defs.mk
--- old/ibsim-0.9.0.7c2a604ec49a/defs.mk        2020-02-13 15:56:54.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/defs.mk       2020-10-08 07:31:29.000000000 
+0200
@@ -13,6 +13,8 @@
                $(prefix)/lib64,$(prefix)/lib)))
 binpath:= $(if $(binpath),$(binpath),$(prefix)/bin)
 
+libdir:=$(libpath)/umad2sim
+
 #IB_DEV_DIR:=$(HOME)/src/m
 ifdef IB_DEV_DIR
  INCS:= $(foreach l, mad umad, -I$(IB_DEV_DIR)/libib$(l)/include) \
@@ -21,7 +23,7 @@
   $(foreach l, mad umad, $(IB_DEV_DIR)/libib$(l)/.libs/libib$(l).so)
 else
  INCS:= -I$(dir $(libpath))include
- LIBS:= -L$(libpath) -libmad -libumad
+ LIBS:= -L$(libpath) -libmad -libumad -lpthread
 endif
 
 CFLAGS += -Wall -g -fpic -I. -I../include $(INCS)
@@ -35,12 +37,12 @@
 all:
 
 %.o: %.c
-       $(CC) $(CFLAGS) -c -o $@ $<
+       $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
 
 %.so:
        $(CC) -shared $(LDFLAGS) -o $@ $^ $(LIBS)
 
-$(progs):
+$(bins): %:
        $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 dep:
@@ -54,9 +56,9 @@
 
 install: all
        install -d $(DESTDIR)$(binpath)
-       install -d $(DESTDIR)$(libpath)/umad2sim
-       $(foreach p, $(progs), install $(p) $(DESTDIR)$(binpath))
-       $(foreach l, $(libs), install $(l) $(DESTDIR)$(libpath)/umad2sim)
+       install -d $(DESTDIR)$(libdir)
+       $(foreach p, $(progs), install $(p) $(DESTDIR)$(binpath);)
+       $(foreach l, $(libs), install $(l) $(DESTDIR)$(libdir);)
 
 $(objs): .build_profile
 .build_profile::
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/dist.sh 
new/ibsim-0.10.0.c7e430dc3d9b/dist.sh
--- old/ibsim-0.9.0.7c2a604ec49a/dist.sh        2020-02-13 15:56:54.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/dist.sh       2020-10-08 07:31:29.000000000 
+0200
@@ -12,7 +12,7 @@
 mkdir $distdir
 
 files=`find . -name '*.[ch]' -o -name Makefile`
-cp -a --parents $files \
+cp -a --parents $files debian \
        defs.mk README COPYING TODO net-examples scripts tests $distdir
 
 cat ibsim.spec.in \
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/ibsim/Makefile 
new/ibsim-0.10.0.c7e430dc3d9b/ibsim/Makefile
--- old/ibsim-0.9.0.7c2a604ec49a/ibsim/Makefile 2020-02-13 15:56:54.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/ibsim/Makefile        2020-10-08 
07:31:29.000000000 +0200
@@ -1,6 +1,13 @@
-progs:=ibsim
+bins:=ibsim
+scripts:=ibsim-run
+progs:=$(bins) $(scrips)
 
 -include ../defs.mk
 
+ibsim-run: ibsim-run.in
+       sed -e 's|@sim_so@|$(libdir)/libumad2sim.so|' \
+               <$< >$@
+       chmod +x $@
+
 all: $(progs)
 ibsim: $(objs)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/ibsim/ibsim-run.1 
new/ibsim-0.10.0.c7e430dc3d9b/ibsim/ibsim-run.1
--- old/ibsim-0.9.0.7c2a604ec49a/ibsim/ibsim-run.1      1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/ibsim/ibsim-run.1     2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1,42 @@
+.\"                                      Hey, EMACS: -*- nroff -*-
+.\" (C) Copyright 2020 Tzafrir Cohen <[email protected]>
+.\"
+.TH ibsim\-run 1 "2020-04-05"
+
+.SH NAME
+ibsim\-run \- run programs in an ibsim-simulated envronment
+.SH SYNOPSIS
+.B ibsim\-run
+.RI [ <command> ]
+.SH DESCRIPTION
+The package ibsim simulates calls to the umad library (of the Infiniband
+user-space stack).
+
+In order to use it, you should run ibsim(1), that gets a network diagram.
+Programs that have libumad2sim.so loaded, override the calls to libumad
+with calls to the ibsim simulator.
+
+This is a script that runs commands with libumad2sim.so already
+LD_PRELOAD-ed.
+
+.SH OPTIONS
+The script will manipulate the environment and then run the rest of the
+command line in that environment. If no command was given, it will run
+bash.
+
+However the following options are supported:
+
+.TP
+.B \-h, \-\-help
+Show summary of options and exit.
+
+.SH EXAMPLES
+
+  ibsim -s path/to/net-examples/net.2sw2path4hca
+
+And in a separate shell:
+
+  ibsim-run ibdiscover
+
+.SH SEE ALSO
+.BR ibsim(1)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/ibsim/ibsim-run.in 
new/ibsim-0.10.0.c7e430dc3d9b/ibsim/ibsim-run.in
--- old/ibsim-0.9.0.7c2a604ec49a/ibsim/ibsim-run.in     1970-01-01 
01:00:00.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/ibsim/ibsim-run.in    2020-10-08 
07:31:29.000000000 +0200
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+sim_so=@sim_so@
+shell="bash"
+
+usage() {
+       me=${0##*/}
+       cat <<EOF
+$me: run commands with an ibsim-smulated stack
+
+Will run a command or start a shell with $sim_so
+LD_PRELOAD-ed.
+
+Usage:
+
+  $me <command>    # Run <command> under ibsim
+  $me              # Start a shell similarely
+  $me -h | --help  # Print this message
+
+Note: You still need to run ibsim separately.
+EOF
+}
+
+case "$1" in
+-h | --help) usage; exit 1;;
+esac
+
+if [ "$LD_PRELOAD" = '' ]; then
+       LD_PRELOAD="$sim_so"
+else
+       LD_PRELOAD="$LD_PRELOAD:sim_so"
+fi
+export LD_PRELOAD
+
+if [ "$*" = '' ]; then
+       exec $shell
+else
+       exec "$@"
+fi
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/ibsim/ibsim.c 
new/ibsim-0.10.0.c7e430dc3d9b/ibsim/ibsim.c
--- old/ibsim-0.9.0.7c2a604ec49a/ibsim/ibsim.c  2020-02-13 15:56:54.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/ibsim/ibsim.c 2020-10-08 07:31:29.000000000 
+0200
@@ -55,7 +55,7 @@
 #include <ibsim.h>
 #include "sim.h"
 
-#define IBSIM_VERSION "0.9"
+#define IBSIM_VERSION "0.10"
 
 #undef DEBUG
 #define PDEBUG if (parsedebug) IBWARN
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/scripts/run_opensm.sh 
new/ibsim-0.10.0.c7e430dc3d9b/scripts/run_opensm.sh
--- old/ibsim-0.9.0.7c2a604ec49a/scripts/run_opensm.sh  2020-02-13 
15:56:54.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/scripts/run_opensm.sh 2020-10-08 
07:31:29.000000000 +0200
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 if [ "$1" = "-g" ] ; then
        debug=1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/tests/Makefile 
new/ibsim-0.10.0.c7e430dc3d9b/tests/Makefile
--- old/ibsim-0.9.0.7c2a604ec49a/tests/Makefile 2020-02-13 15:56:54.000000000 
+0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/tests/Makefile        2020-10-08 
07:31:29.000000000 +0200
@@ -1,7 +1,7 @@
-progs:= subnet_discover query_many mcast_storm
+bins:= subnet_discover query_many mcast_storm
 
 -include ../defs.mk
 
-all: $(progs)
+all: $(bins)
 
-$(progs): %: %.o
+$(bins): %: %.o
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/tests/mcast_storm.c 
new/ibsim-0.10.0.c7e430dc3d9b/tests/mcast_storm.c
--- old/ibsim-0.9.0.7c2a604ec49a/tests/mcast_storm.c    2020-02-13 
15:56:54.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/tests/mcast_storm.c   2020-10-08 
07:31:29.000000000 +0200
@@ -512,8 +512,6 @@
        ret = t->func(&addr, td);
 
        umad_unregister(addr.port, addr.agent);
-       umad_close_port(addr.port);
-       umad_done();
 
        info("\'%s\' %s.\n", t->name, ret ? "failed" : "is done");
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ibsim-0.9.0.7c2a604ec49a/umad2sim/umad2sim.c 
new/ibsim-0.10.0.c7e430dc3d9b/umad2sim/umad2sim.c
--- old/ibsim-0.9.0.7c2a604ec49a/umad2sim/umad2sim.c    2020-02-13 
15:56:54.000000000 +0100
+++ new/ibsim-0.10.0.c7e430dc3d9b/umad2sim/umad2sim.c   2020-10-08 
07:31:29.000000000 +0200
@@ -40,6 +40,8 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/time.h>
+#include <sys/errno.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -48,7 +50,7 @@
 #include <string.h>
 #include <dirent.h>
 #include <dlfcn.h>
-
+#include <pthread.h>
 #include <infiniband/umad.h>
 #include <infiniband/mad.h>
 
@@ -64,9 +66,38 @@
 
 #define arrsize(a) (sizeof(a)/sizeof(a[0]))
 
+#define EVENT_NO_TIMEOUT       0xFFFFFFFF
+#define FD_TIMEOUT     12
 
 #define IB_PORT_EXT_SPEED_SUPPORTED_MASK (1<<14)
 
+struct umad_buf_t {
+       ssize_t size;
+       char *umad;
+};
+
+struct list_elem_t {
+       struct umad_buf_t *data;
+       struct list_elem_t *next;
+};
+
+struct msg_queue_t {
+       struct list_elem_t *tail;
+       struct  list_elem_t *head;
+       ssize_t queue_size;
+};
+
+struct fd_event_t {
+       pthread_cond_t condvar;
+       pthread_mutex_t mutex;
+};
+
+struct fd_data_t {
+       struct fd_event_t fd_event;
+       struct msg_queue_t *mqueue;
+} fd_data_t;
+
+
 struct ib_user_mad_reg_req {
        uint32_t id;
        uint32_t method_mask[4];
@@ -77,16 +108,20 @@
        uint8_t rmpp_version;
 };
 
+#define FD_PER_DEVICE 8
+
 struct umad2sim_dev {
-       int fd;
+       pthread_t thread_id;
        unsigned num;
        char name[32];
        uint8_t port;
        struct sim_client sim_client;
-       unsigned agent_idx[256];
+       unsigned int agent_idx[256];
+       unsigned int agent_fds[256];
        struct ib_user_mad_reg_req agents[32];
        char umad_path[256];
        char issm_path[256];
+       struct fd_data_t *fds[FD_PER_DEVICE];
 };
 
 static int (*real_open) (const char *path, int flags, ...);
@@ -116,6 +151,366 @@
 static unsigned umad2sim_initialized;
 static struct umad2sim_dev *devices[32];
 
+static pthread_mutex_t global_devices_mutex;
+
+static ssize_t umad2sim_read(struct umad2sim_dev *dev, void *buf, size_t count,
+                            unsigned int *mgmt_class);
+
+static ssize_t fd_data_mqueue_size(struct fd_data_t *fd_data);
+
+static int fd_event_init(struct fd_event_t * const p_event)
+{
+       if (pthread_cond_init(&p_event->condvar, NULL))
+               return -1;
+       if (pthread_mutex_init(&p_event->mutex, NULL)) {
+               pthread_cond_destroy(&p_event->condvar);
+               return -1;
+       }
+       return 0;
+}
+
+static void fd_event_destroy(struct fd_event_t * const p_event)
+{
+       pthread_cond_broadcast(&p_event->condvar);
+       pthread_cond_destroy(&p_event->condvar);
+       pthread_mutex_destroy(&p_event->mutex);
+}
+
+static void fd_event_signal(struct fd_event_t * const p_event)
+{
+
+       pthread_cond_signal(&p_event->condvar);
+}
+
+static int fd_event_wait_on(struct fd_data_t * const fd_data,
+                           const uint32_t wait_us)
+{
+       int status = -1;
+       int wait_ret;
+       struct timespec timeout;
+       struct timeval curtime;
+       struct fd_event_t *p_event = &fd_data->fd_event;
+       ssize_t size;
+
+       pthread_mutex_lock(&p_event->mutex);
+       size = fd_data_mqueue_size(fd_data);
+
+       if (size) {
+               pthread_mutex_unlock(&p_event->mutex);
+               return 0;
+       }
+
+       if (wait_us == 0) {
+               pthread_mutex_unlock(&p_event->mutex);
+               return FD_TIMEOUT;
+       }
+
+       if (wait_us == EVENT_NO_TIMEOUT) {
+               /* Wait for condition variable to be signaled */
+               if (!pthread_cond_wait(&p_event->condvar, &p_event->mutex))
+                       status = 0;
+               pthread_mutex_unlock(&p_event->mutex);
+               return status;
+       }
+
+       if (gettimeofday(&curtime, NULL) == 0) {
+               unsigned long long n_sec =
+                       curtime.tv_usec*1000 + ((wait_us % 1000000)) * 1000;
+                       timeout.tv_sec = curtime.tv_sec + (wait_us / 1000000)
+                           + (n_sec / 1000000000);
+                       timeout.tv_nsec = n_sec % 1000000000;
+
+                       wait_ret = pthread_cond_timedwait(&p_event->condvar,
+                                                         &p_event->mutex,
+                                                         &timeout);
+                       if (wait_ret == 0) {
+                               size = fd_data_mqueue_size(fd_data);
+                               status = size ? 0 : -1;
+                       } else if (wait_ret == ETIMEDOUT)
+                               status = FD_TIMEOUT;
+
+                       pthread_mutex_unlock(&p_event->mutex);
+       }
+       return status;
+}
+
+static struct umad_buf_t *alloc_umad_buf(ssize_t size)
+{
+       struct umad_buf_t *buf;
+
+       buf = (struct umad_buf_t *) malloc(sizeof(struct umad_buf_t));
+       if (!buf)
+               return NULL;
+
+       buf->umad = malloc(size);
+       if (!buf->umad) {
+               free(buf);
+               return NULL;
+       }
+
+       buf->size = size;
+
+       return buf;
+}
+
+static void free_umad_buf(struct umad_buf_t *buf)
+{
+       free(buf->umad);
+       buf->size = 0;
+       free(buf);
+}
+
+static struct msg_queue_t *mqueue_create(void)
+{
+       struct msg_queue_t *ptr;
+
+       ptr = (struct msg_queue_t *) malloc(sizeof(struct msg_queue_t));
+       if (!ptr)
+               return NULL;
+
+       ptr->head = NULL;
+       ptr->tail = NULL;
+       ptr->queue_size = 0;
+
+       return ptr;
+}
+
+static struct list_elem_t *mqueue_add_tail(struct msg_queue_t *mqueue,
+                                          void *data)
+{
+       struct list_elem_t *ptr;
+
+       ptr = (struct list_elem_t *) malloc(sizeof(struct list_elem_t));
+       if (!ptr)
+               return NULL;
+
+       ptr->data = data;
+       ptr->next = NULL;
+
+       if (mqueue->head == NULL) {
+               mqueue->tail = ptr;
+               mqueue->head = mqueue->tail;
+       } else {
+               mqueue->tail->next = ptr;
+               mqueue->tail = ptr;
+       }
+       mqueue->queue_size++;
+       return ptr;
+}
+
+static ssize_t mqueue_get_size(struct msg_queue_t *mqueue)
+{
+       return mqueue->queue_size;
+}
+
+static struct list_elem_t *mqueue_remove_head(struct msg_queue_t *mqueue)
+{
+       struct list_elem_t *ptr;
+
+       if (mqueue->head == NULL)
+               return NULL;
+
+       ptr = mqueue->head;
+       if (mqueue->head == mqueue->tail) {
+               mqueue->head = NULL;
+               mqueue->tail = NULL;
+       } else {
+               mqueue->head = ptr->next;
+       }
+
+       mqueue->queue_size--;
+       ptr->next = NULL;
+       return ptr;
+}
+
+static void mqueue_destroy(struct msg_queue_t *mqueue)
+{
+       free(mqueue);
+}
+
+static struct fd_data_t *fd_data_create(void)
+{
+       struct fd_data_t *ptr;
+
+       ptr = (struct fd_data_t *) malloc(sizeof(struct fd_data_t));
+       if (!ptr)
+               return NULL;
+
+       ptr->mqueue = mqueue_create();
+       if (!ptr->mqueue) {
+               free(ptr);
+               return NULL;
+       }
+
+       if (fd_event_init(&ptr->fd_event)) {
+               mqueue_destroy(ptr->mqueue);
+               free(ptr);
+               return NULL;
+       }
+
+       return ptr;
+}
+
+/* should be called under fd_data->fd_event.mutex */
+static struct umad_buf_t *fd_data_dequeue(struct fd_data_t *fd_data)
+{
+       struct list_elem_t *ptr;
+       struct umad_buf_t *data_ptr = NULL;
+
+       ptr = mqueue_remove_head(fd_data->mqueue);
+       if (ptr) {
+               data_ptr = ptr->data;
+               free(ptr);
+       }
+       return data_ptr;
+}
+/* should be called under global lock */
+static void fd_data_release(struct fd_data_t *fd_data)
+{
+       struct umad_buf_t *ptr;
+
+       while ((ptr = fd_data_dequeue(fd_data)) != NULL)
+               free_umad_buf(ptr);
+
+       mqueue_destroy(fd_data->mqueue);
+       fd_event_destroy(&fd_data->fd_event);
+       free(fd_data);
+}
+
+/* should be called under fd_data->fd_event.mutex */
+static int fd_data_enqueue(struct fd_data_t *fd_data, void *data)
+{
+       struct list_elem_t *ptr;
+       int result = 0;
+
+       ptr = mqueue_add_tail(fd_data->mqueue, data);
+       if (!ptr)
+               result = -1;
+       return result;
+}
+
+/* should be called under global lock */
+static struct fd_data_t *get_fd_data(struct umad2sim_dev *dev, unsigned int fd)
+{
+       if (fd < 1024 && fd >= 2048)
+               return NULL;
+
+       if (!dev)
+               return NULL;
+
+       return dev->fds[(fd - 1024) % FD_PER_DEVICE];
+}
+
+/* should be called under fd_data->fd_event.mutex */
+static ssize_t fd_data_mqueue_size(struct fd_data_t *fd_data)
+{
+       return mqueue_get_size(fd_data->mqueue);
+}
+
+/* Returns index into dev->fds where new fd_data_t pointer was stored */
+static int get_new_fd(struct umad2sim_dev *dev)
+{
+       int i;
+
+       for (i = 0; i < FD_PER_DEVICE; i++) {
+               if (dev->fds[i] != NULL)
+                       continue;
+               dev->fds[i] = fd_data_create();
+               return (dev->fds[i] == NULL) ? -1 : i;
+       }
+       /* all FDs allocated */
+       return -1;
+}
+
+static struct umad2sim_dev *fd_to_dev(unsigned int fd)
+{
+       if (fd >= 2048)
+               return devices[fd - 2048];
+       if (fd >= 1024)
+               return devices[(fd - 1024) / FD_PER_DEVICE];
+
+       return NULL;
+}
+
+static int close_fd(unsigned int fd)
+{
+       struct umad2sim_dev *dev;
+       int i, idx;
+       struct fd_data_t *fd_data;
+
+       if (fd < 1024)
+               return 0;
+       dev = fd_to_dev(fd);
+       if (!dev)
+               return 0;
+
+       if (fd >= 2048) {
+               sim_client_set_sm(&dev->sim_client, 0);
+               return 0;
+       }
+
+       fd_data = get_fd_data(dev, fd);
+       if (fd_data)
+               fd_data_release(fd_data);
+
+       for (i = 0; i < 256; i++) {
+               if (dev->agent_fds[i] == fd) {
+                       dev->agent_fds[i] = -1;
+                       idx = dev->agent_idx[i];
+                       dev->agents[idx].id = (uint32_t)(-1);
+                       dev->agent_idx[i] = -1;
+                       break;
+               }
+       }
+       dev->fds[(fd - 1024) % FD_PER_DEVICE] = NULL;
+       return 0;
+}
+
+static void *__receiver(void *arg)
+{
+       struct umad2sim_dev *dev = (struct umad2sim_dev *) arg;
+       struct pollfd pfds;
+       struct umad_buf_t *buf;
+       unsigned int mgmt_class;
+       unsigned int fd;
+       struct fd_data_t *fd_data;
+
+       pfds.fd = dev->sim_client.fd_pktin;
+       pfds.events = POLLIN;
+       pfds.revents = 0;
+
+
+       while (1) {
+               if (real_poll(&pfds, 1, -1) < 0) {
+                       ERROR("real_poll failure\n");
+                       continue;
+               }
+               /* Do real read and post the message to the queue */
+               buf = alloc_umad_buf(sizeof(struct sim_request));
+
+               if (!buf)
+                       continue;
+
+               buf->size = umad2sim_read(dev, buf->umad, buf->size, 
&mgmt_class);
+               pthread_mutex_lock(&global_devices_mutex);
+               fd = dev->agent_fds[mgmt_class];
+               fd_data = get_fd_data(dev, fd);
+               pthread_mutex_unlock(&global_devices_mutex);
+               pthread_mutex_lock(&fd_data->fd_event.mutex);
+               /* find appropriate mqueue and push to it */
+               if ((fd_data == NULL) || fd_data_enqueue(fd_data, buf) < 0) {
+                       ERROR("Empty fd_data or fd_data_enqueue failed for FD 
%d\n",
+                             fd);
+                       free_umad_buf(buf);
+               } else {
+                       /* signal reader */
+                       fd_event_signal(&fd_data->fd_event);
+               }
+               pthread_mutex_unlock(&fd_data->fd_event.mutex);
+       }
+       return NULL;
+}
+
 /*
  *  sysfs stuff
  *
@@ -399,11 +794,11 @@
  *
  */
 
-static ssize_t umad2sim_read(struct umad2sim_dev *dev, void *buf, size_t count)
+static ssize_t umad2sim_read(struct umad2sim_dev *dev, void *buf, size_t count,
+                            unsigned int *mgmt_class)
 {
        struct sim_request req;
        ib_user_mad_t *umad = (ib_user_mad_t *) buf;
-       unsigned mgmt_class;
        int cnt;
 
        DEBUG("umad2sim_read: %zu...\n", count);
@@ -413,29 +808,30 @@
        if (cnt < sizeof(req)) {
                ERROR("umad2sim_read: partial request - skip.\n");
                umad->status = EAGAIN;
+               *mgmt_class = 0;
                return umad_size();
        }
 
-       mgmt_class = mad_get_field(req.mad, 0, IB_MAD_MGMTCLASS_F);
+       *mgmt_class = mad_get_field(req.mad, 0, IB_MAD_MGMTCLASS_F);
 
        DEBUG("umad2sim_read: mad: method=%x, response=%x, mgmtclass=%x, "
              "attrid=%x, attrmod=%x\n",
              mad_get_field(req.mad, 0, IB_MAD_METHOD_F),
              mad_get_field(req.mad, 0, IB_MAD_RESPONSE_F),
-             mgmt_class,
+             *mgmt_class,
              mad_get_field(req.mad, 0, IB_MAD_ATTRID_F),
              mad_get_field(req.mad, 0, IB_MAD_ATTRMOD_F));
 
-       if (mgmt_class >= arrsize(dev->agent_idx)) {
-               ERROR("bad mgmt_class 0x%x\n", mgmt_class);
-               mgmt_class = 0;
+       if (*mgmt_class >= arrsize(dev->agent_idx)) {
+               ERROR("bad mgmt_class 0x%x\n", *mgmt_class);
+               *mgmt_class = 0;
        }
 
        if (mad_get_field(req.mad, 0, IB_MAD_RESPONSE_F)) {
                uint64_t trid = mad_get_field64(req.mad, 0, IB_MAD_TRID_F);
                umad->agent_id = (trid >> 32) & 0xffff;
        } else
-               umad->agent_id = dev->agent_idx[mgmt_class];
+               umad->agent_id = dev->agent_idx[*mgmt_class];
 
        umad->status = ntohl(req.status);
        umad->timeout_ms = 0;
@@ -523,48 +919,72 @@
        return count;
 }
 
-static int register_agent(struct umad2sim_dev *dev,
+static int register_agent(unsigned int fd,
                          struct ib_user_mad_reg_req *req)
 {
-       unsigned i;
-       DEBUG("register_agent: id = %u, qpn = %u, mgmt_class = %u,"
+       unsigned int i;
+       struct umad2sim_dev *dev;
+
+       pthread_mutex_lock(&global_devices_mutex);
+       dev = fd_to_dev(fd);
+
+       if (!dev) {
+               pthread_mutex_unlock(&global_devices_mutex);
+               return -1;
+       }
+       DEBUG("%s: fd = %u, qpn = %u, mgmt_class = %u,"
              " mgmt_class_version = %u, rmpp_version = %u\n",
-             req->id, req->qpn, req->mgmt_class, req->mgmt_class_version,
+             __func__,
+             fd, req->qpn, req->mgmt_class, req->mgmt_class_version,
              req->rmpp_version);
        for (i = 0; i < arrsize(dev->agents); i++)
                if (dev->agents[i].id == (uint32_t)(-1)) {
                        req->id = i;
                        dev->agents[i] = *req;
                        dev->agent_idx[req->mgmt_class] = i;
+                       dev->agent_fds[req->mgmt_class] = fd;
                        DEBUG("agent registered: %d\n", i);
+                       pthread_mutex_unlock(&global_devices_mutex);
                        return 0;
                }
+       pthread_mutex_unlock(&global_devices_mutex);
        errno = ENOMEM;
        return -1;
 }
 
-static int unregister_agent(struct umad2sim_dev *dev, unsigned id)
+static int unregister_agent(unsigned int fd, unsigned int id)
 {
-       unsigned mgmt_class;
+       unsigned int mgmt_class;
+       struct umad2sim_dev *dev;
+
+       pthread_mutex_lock(&global_devices_mutex);
+       dev = fd_to_dev(fd);
+       if (!dev) {
+               pthread_mutex_unlock(&global_devices_mutex);
+               return -1;
+       }
        if (id >= arrsize(dev->agents)) {
+               pthread_mutex_unlock(&global_devices_mutex);
                errno = EINVAL;
                return -1;
        }
        mgmt_class = dev->agents[id].mgmt_class;
        dev->agents[id].id = (uint32_t)(-1);
        dev->agent_idx[mgmt_class] = -1;
+       dev->agent_fds[mgmt_class] = -1;
+       pthread_mutex_unlock(&global_devices_mutex);
        return 0;
 }
 
-static int umad2sim_ioctl(struct umad2sim_dev *dev, unsigned long request,
+static int umad2sim_ioctl(unsigned int fd, unsigned long request,
                          void *arg)
 {
        DEBUG("umad2sim_ioctl: %lu, %p...\n", request, arg);
        switch (request) {
        case IB_USER_MAD_REGISTER_AGENT:
-               return register_agent(dev, arg);
+               return register_agent(fd, arg);
        case IB_USER_MAD_UNREGISTER_AGENT:
-               return unregister_agent(dev, *((unsigned *)arg));
+               return unregister_agent(fd, *((unsigned int *)arg));
        case IB_USER_MAD_ENABLE_PKEY:
                return 0;
        default:
@@ -573,10 +993,10 @@
        return -1;
 }
 
-static struct umad2sim_dev *umad2sim_dev_create(unsigned num, const char *name)
+static struct umad2sim_dev *umad2sim_dev_create(unsigned int num, const char 
*name)
 {
        struct umad2sim_dev *dev;
-       unsigned i;
+       int i;
 
        DEBUG("umad2sim_dev_create: %s...\n", name);
 
@@ -591,12 +1011,22 @@
        if (sim_client_init(&dev->sim_client) < 0)
                goto _error;
 
+       if (pthread_create(&dev->thread_id, NULL,
+                          __receiver, dev) < 0) {
+               sim_client_exit(&dev->sim_client);
+               goto _error;
+       }
+
        dev->port = mad_get_field(&dev->sim_client.portinfo, 0,
                                  IB_PORT_LOCAL_PORT_F);
        for (i = 0; i < arrsize(dev->agents); i++)
                dev->agents[i].id = (uint32_t)(-1);
-       for (i = 0; i < arrsize(dev->agent_idx); i++)
-               dev->agent_idx[i] = (unsigned)(-1);
+       for (i = 0; i < arrsize(dev->agent_idx); i++) {
+               dev->agent_idx[i] = (unsigned int)(-1);
+               dev->agent_fds[i] = (unsigned int)(-1);
+       }
+       for (i = 0; i < FD_PER_DEVICE; i++)
+               dev->fds[i] = NULL;
 
        dev_sysfs_create(dev);
 
@@ -614,7 +1044,17 @@
 
 static void umad2sim_dev_delete(struct umad2sim_dev *dev)
 {
+       int i;
+
        sim_client_exit(&dev->sim_client);
+       pthread_cancel(dev->thread_id);
+       pthread_join(dev->thread_id, NULL);
+       for (i = 0; i < FD_PER_DEVICE; i++) {
+               if (dev->fds[i] != NULL) {
+                       fd_data_release(dev->fds[i]);
+                       dev->fds[i] = NULL;
+               }
+       }
        free(dev);
 }
 
@@ -655,15 +1095,19 @@
 static void umad2sim_cleanup(void)
 {
        char path[1024];
-       unsigned i;
+       int i;
+
        DEBUG("umad2sim_cleanup...\n");
+       pthread_mutex_lock(&global_devices_mutex);
        for (i = 0; i < arrsize(devices); i++)
                if (devices[i]) {
                        umad2sim_dev_delete(devices[i]);
                        devices[i] = NULL;
                }
+       pthread_mutex_unlock(&global_devices_mutex);
        strncpy(path, umad2sim_sysfs_prefix, sizeof(path) - 1);
        unlink_dir(path, sizeof(path));
+       pthread_mutex_destroy(&global_devices_mutex);
 }
 
 static void umad2sim_init(void)
@@ -678,6 +1122,7 @@
                ERROR("cannot init umad2sim. Exit.\n");
                exit(-1);
        }
+       pthread_mutex_init(&global_devices_mutex, NULL);
        atexit(umad2sim_cleanup);
        umad2sim_initialized = 1;
 }
@@ -711,6 +1156,12 @@
        char new_path[1024];
 
        CHECK_INIT();
+
+       if (!umad2sim_initialized && (is_sysfs_file(path) ||
+                                     !strncmp(path, umad_dev_dir,
+                                              strlen(umad_dev_dir))))
+               umad2sim_init();
+
        DEBUG("libs_wrap: opendir: %s...\n", path);
 
        if (is_sysfs_file(path)) {
@@ -755,7 +1206,7 @@
        struct umad2sim_dev *dev;
        va_list args;
        mode_t mode = 0;
-       unsigned i;
+       int i;
 
        CHECK_INIT();
 
@@ -778,59 +1229,103 @@
                return real_open(new_path, flags, mode);
        }
 
+       pthread_mutex_lock(&global_devices_mutex);
        for (i = 0; i < arrsize(devices); i++) {
                if (!(dev = devices[i]))
                        continue;
                if (!strncmp(path, dev->umad_path, sizeof(dev->umad_path))) {
-                       return 1024 + i;
+                       int fd_index;
+
+                       fd_index = get_new_fd(dev);
+                       pthread_mutex_unlock(&global_devices_mutex);
+                       return (fd_index < 0) ? -1
+                                             :  1024 + i * FD_PER_DEVICE +
+                                                fd_index;
                }
                if (!strncmp(path, dev->issm_path, sizeof(dev->issm_path))) {
                        sim_client_set_sm(&dev->sim_client, 1);
+                       pthread_mutex_unlock(&global_devices_mutex);
                        return 2048 + i;
                }
        }
-
+       pthread_mutex_unlock(&global_devices_mutex);
        return real_open(path, flags, mode);
 }
 
 int close(int fd)
 {
-       struct umad2sim_dev *dev;
-
        DEBUG("libs_wrap: close %d...\n", fd);
        CHECK_INIT();
 
-       if (fd >= 2048) {
-               dev = devices[fd - 2048];
-               sim_client_set_sm(&dev->sim_client, 0);
-               return 0;
-       } else if (fd >= 1024) {
-               return 0;
-       } else
-               return real_close(fd);
+       if (fd >= 1024)
+               return close_fd(fd);
+
+       return real_close(fd);
 }
 
 ssize_t read(int fd, void *buf, size_t count)
 {
+       struct umad2sim_dev *dev;
+       struct fd_data_t *fd_data;
+       struct umad_buf_t *umad_buf;
+       int ret;
+
        CHECK_INIT();
 
        if (fd >= 2048)
                return -1;
-       else if (fd >= 1024)
-               return umad2sim_read(devices[fd - 1024], buf, count);
-       else
+       else if (fd >= 1024) {
+
+               pthread_mutex_lock(&global_devices_mutex);
+               dev = fd_to_dev(fd);
+               fd_data = get_fd_data(dev, fd);
+               if (!fd_data) {
+                       pthread_mutex_unlock(&global_devices_mutex);
+                       return -1;
+               }
+               pthread_mutex_unlock(&global_devices_mutex);
+               pthread_mutex_lock(&fd_data->fd_event.mutex);
+               umad_buf = fd_data_dequeue(fd_data);
+               pthread_mutex_unlock(&fd_data->fd_event.mutex);
+               if (!umad_buf) {
+                       DEBUG("No data in queue\n");
+                       return -EWOULDBLOCK;
+               }
+               if (umad_buf->size > count) {
+                       ERROR("received data size %u larger than requested buf 
size %u\n",
+                            (unsigned int) umad_buf->size, (unsigned int) 
count);
+                       umad_buf->size = count;
+               }
+
+               memcpy(buf, umad_buf->umad, umad_buf->size);
+
+               ret = umad_buf->size;
+               free_umad_buf(umad_buf);
+
+               return ret;
+       } else
                return real_read(fd, buf, count);
 }
 
 ssize_t write(int fd, const void *buf, size_t count)
 {
+       struct umad2sim_dev *dev;
+       ssize_t res;
+
        CHECK_INIT();
 
        if (fd >= 2048)
                return -1;
-       else if (fd >= 1024)
-               return umad2sim_write(devices[fd - 1024], buf, count);
-       else
+       else if (fd >= 1024) {
+               pthread_mutex_lock(&global_devices_mutex);
+               dev = fd_to_dev(fd);
+               if (!dev)
+                       res = -1;
+               else
+                       res = umad2sim_write(dev, buf, count);
+               pthread_mutex_unlock(&global_devices_mutex);
+               return res;
+       } else
                return real_write(fd, buf, count);
 }
 
@@ -847,33 +1342,46 @@
        if (fd >= 2048)
                return -1;
        else if (fd >= 1024)
-               return umad2sim_ioctl(devices[fd - 1024], request, arg);
+               return umad2sim_ioctl(fd, request, arg);
        else
                return real_ioctl(fd, request, arg);
 }
-
+/* Only single FD per devives is support */
+/* This fits current libibumad implementation */
 int poll(struct pollfd *pfds, nfds_t nfds, int timeout)
 {
-       int saved_fds[nfds];
-       unsigned i;
+       struct umad2sim_dev *dev = NULL;
+       struct fd_data_t *fd_data = NULL;
+       unsigned int i, index;
        int ret;
 
        CHECK_INIT();
-
+       pthread_mutex_lock(&global_devices_mutex);
        for (i = 0; i < nfds; i++) {
                if (pfds[i].fd >= 1024 && pfds[i].fd < 2048) {
-                       struct umad2sim_dev *dev = devices[pfds[i].fd - 1024];
-                       saved_fds[i] = pfds[i].fd;
-                       pfds[i].fd = dev->sim_client.fd_pktin;
-               } else
-                       saved_fds[i] = 0;
+                       dev = fd_to_dev(pfds[i].fd);
+                       fd_data = get_fd_data(dev, pfds[i].fd);
+                       index = i;
+                       break;
+               }
        }
+       pthread_mutex_unlock(&global_devices_mutex);
+       if (fd_data != NULL) {
+               /* timeout in microsec*/
+               ret = fd_event_wait_on(fd_data,
+                                      (timeout < 0) ? EVENT_NO_TIMEOUT :
+                                      timeout * 1000);
+               pfds[index].revents = 0;
+               if (ret == 0) {
+                       pfds[index].revents = POLLIN;
+                       ret = 1;
+               } else if (ret == FD_TIMEOUT)
+                       ret = 0;
+               else
+                       ret = -1;
 
-       ret = real_poll(pfds, nfds, timeout);
-
-       for (i = 0; i < nfds; i++)
-               if (saved_fds[i])
-                       pfds[i].fd = saved_fds[i];
-
+       } else {
+               ret = real_poll(pfds, nfds, timeout);
+       }
        return ret;
 }

++++++ ibsim-PIE.patch ++++++
--- /var/tmp/diff_new_pack.5VmQjN/_old  2021-04-29 01:39:28.246669449 +0200
+++ /var/tmp/diff_new_pack.5VmQjN/_new  2021-04-29 01:39:28.246669449 +0200
@@ -1,12 +1,23 @@
-Index: ibsim-0.9.0.7c2a604ec49a/ibsim/Makefile
-===================================================================
---- ibsim-0.9.0.7c2a604ec49a.orig/ibsim/Makefile
-+++ ibsim-0.9.0.7c2a604ec49a/ibsim/Makefile
-@@ -2,5 +2,7 @@ progs:=ibsim
+commit 913edb20ad95d3e369f275db8e718e604ce94169
+Author: Wolfgang Frisch <[email protected]>
+Date:   Wed Apr 28 09:52:43 2021 +0200
+
+    ibsim: PIE
+    
+    Link as position idnependant executable
+    
+    Signed-off-by: Nicolas Morey-Chaisemartin <[email protected]>
+
+diff --git ibsim/Makefile ibsim/Makefile
+index 73f92e963b26..d83d8247df9c 100644
+--- ibsim/Makefile
++++ ibsim/Makefile
+@@ -4,6 +4,8 @@ progs:=$(bins) $(scrips)
  
  -include ../defs.mk
  
 +LDFLAGS += -pie
 +
- all: $(progs)
- ibsim: $(objs)
+ ibsim-run: ibsim-run.in
+       sed -e 's|@sim_so@|$(libdir)/libumad2sim.so|' \
+               <$< >$@

++++++ typo-scrips.patch ++++++
commit a1ade731654548b233306f82081c3c12bdf2838d
Author: Tzafrir Cohen <[email protected]>
Date:   Thu Oct 8 17:17:22 2020 +0300

    typo: scrips
    
    Signed-off-by: Tzafrir Cohen <[email protected]>

diff --git ibsim/Makefile ibsim/Makefile
index d83d8247df9c..a45dbc1c8465 100644
--- ibsim/Makefile
+++ ibsim/Makefile
@@ -1,6 +1,6 @@
 bins:=ibsim
 scripts:=ibsim-run
-progs:=$(bins) $(scrips)
+progs:=$(bins) $(scripts)
 
 -include ../defs.mk
 

Reply via email to