components/open-fabrics/libibmad/patches/002-libibmad-diskmon_trid.patch
author boris.chiu@oracle.com
Mon, 19 Sep 2016 15:30:46 -0700
branchs11u3-sru
changeset 6927 af9bb41e858d
permissions -rw-r--r--
22086045 libibmad used [s]random(3c) functions unsafely
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6927
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     1
#This patch was developed both in-house and from outside. We plan to submit it
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     2
#upstream, but do not yet have a target date for doing so
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     3
#
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     4
# HG changeset patch
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     5
# Parent  b0c54b9f271e37d7b605138bcdd0c26844892c3d
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     6
22086045 libibmad used [s]random(3c) functions unsafely
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     7
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     8
diff -r b0c54b9f271e src/mad.c
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
     9
--- a/src/mad.c	Mon Aug 15 14:55:29 2016 -0700
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    10
+++ b/src/mad.c	Mon Aug 15 15:01:53 2016 -0700
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    11
@@ -41,6 +41,9 @@
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    12
 #include <stdlib.h>
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    13
 #include <string.h>
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    14
 #include <time.h>
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    15
+#if defined(__SVR4) && defined(__sun)
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    16
+#include <pthread.h>
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    17
+#endif
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    18
 #include <errno.h>
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    19
 
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    20
 #include <infiniband/umad.h>
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    21
@@ -48,6 +51,10 @@
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    22
 
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    23
 #include "mad_internal.h"
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    24
 
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    25
+#if defined(__SVR4) && defined(__sun)
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    26
+static pthread_mutex_t trid_mutex = PTHREAD_MUTEX_INITIALIZER;
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    27
+#endif
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    28
+
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    29
 #undef DEBUG
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    30
 #define DEBUG	if (ibdebug)	IBWARN
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    31
 
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    32
@@ -63,11 +70,17 @@
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    33
 	static uint64_t trid;
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    34
 	uint64_t next;
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    35
 
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    36
+#if defined(__SVR4) && defined(__sun)
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    37
+	(void) pthread_mutex_lock(&trid_mutex);
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    38
+#endif
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    39
 	if (!trid) {
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    40
 		srandom((int)time(0) * getpid());
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    41
 		trid = random();
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    42
 	}
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    43
 	next = ++trid;
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    44
+#if defined(__SVR4) && defined(__sun)
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    45
+	(void) pthread_mutex_unlock(&trid_mutex);
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    46
+#endif
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    47
 	next = GET_IB_USERLAND_TID(next);
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    48
 	return next;
af9bb41e858d 22086045 libibmad used [s]random(3c) functions unsafely
boris.chiu@oracle.com
parents:
diff changeset
    49
 }