]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
refresh
authorSean Hefty <sean.hefty@intel.com>
Mon, 6 Aug 2012 20:48:47 +0000 (13:48 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 6 Aug 2012 20:48:47 +0000 (13:48 -0700)
meta
patches/dup2
patches/refresh-temp [deleted file]

diff --git a/meta b/meta
index c99a4b5500af7c68a20314550830cdafffe15f88..118cb2bd7405bd9c70b80d1cb245dc874fcdc65a 100644 (file)
--- a/meta
+++ b/meta
@@ -1,10 +1,9 @@
 Version: 1
-Previous: 944e5c1bbd1f7561658b083e94646ac12076c4ed
-Head: fb6f86147c8edabd88ebec12ee516942ecb5dc6c
+Previous: c5e5b79678874f58dd99ce97571f7e13ce70eb79
+Head: 02f124a4ba5b3530bbce5cfbe28a343cd1b54260
 Applied:
   real-close: 3409f8d6af187d25c63a5d1f8ee8bff5f14555e2
-  dup2: 810924b05f1448e9da2916d16c71a44996ade3dc
-  refresh-temp: fb6f86147c8edabd88ebec12ee516942ecb5dc6c
+  dup2: 02f124a4ba5b3530bbce5cfbe28a343cd1b54260
 Unapplied:
   dbg: 0c269855776d3001e37da8c8afe283c20e1d6cd6
   waitall-buggy: c49c6b56c55385774065f5aa2704078e6ae0ceb8
index 14dfc41475e6fbd72bda9a3f59cb33a114043de0..f7d04c0a9dad1181d52a049b5a46fe16a4765cba 100644 (file)
@@ -1,5 +1,5 @@
 Bottom: c4f9e56fde30641b69e81060e3981b0df33f49c2
-Top:    6c3a4d4cc0146d11acbd41ec30ac983f004e11c7
+Top:    1ba59f6f7d9886c4ce5b8aa5fa06f770d53b8bf2
 Author: Sean Hefty <sean.hefty@intel.com>
 Date:   2012-07-30 16:06:32 -0700
 
@@ -13,18 +13,138 @@ Signed-off-by: Sean Hefty <sean.hefty@intel.com>
 
 ---
 
+diff --git a/src/cma.h b/src/cma.h
+index cedc0c3..6c3df27 100644
+--- a/src/cma.h
++++ b/src/cma.h
+@@ -79,6 +79,31 @@ static inline uint64_t ntohll(uint64_t x) { return x; }
+ #define fastlock_destroy(lock) pthread_mutex_destroy(lock)
+ #define fastlock_acquire(lock) pthread_mutex_lock(lock)
+ #define fastlock_release(lock) pthread_mutex_unlock(lock)
++
++typedef struct { pthread_mutex_t mut; int val; } atomic_t;
++static inline int atomic_inc(atomic_t *atomic)
++{
++      int v;
++
++      pthread_mutex_lock(&atomic->mut);
++      v = ++(atomic->val);
++      pthread_mutex_unlock(&atomic->mut);
++      return v;
++}
++static inline int atomic_dec(atomic_t *atomic)
++{
++      int v;
++
++      pthread_mutex_lock(&atomic->mut);
++      v = --(atomic->val);
++      pthread_mutex_unlock(&atomic->mut);
++      return v;
++}
++static inline void atomic_init(atomic_t *atomic)
++{
++      pthread_mutex_init(&atomic->mut, NULL);
++      atomic->val = 0;
++}
+ #else
+ typedef struct {
+       sem_t sem;
+@@ -103,7 +128,14 @@ static inline void fastlock_release(fastlock_t *lock)
+       if (__sync_sub_and_fetch(&lock->cnt, 1) > 0)
+               sem_post(&lock->sem);
+ }
++
++typedef struct { volatile int val; } atomic_t;
++#define atomic_inc(v) (__sync_add_and_fetch(&(v)->val, 1))
++#define atomic_dec(v) (__sync_sub_and_fetch(&(v)->val, 1))
++#define atomic_init(v) ((v)->val = 0)
+ #endif /* DEFINE_ATOMICS */
++#define atomic_get(v) ((v)->val)
++#define atomic_set(v, s) ((v)->val = s)
+ int ucma_max_qpsize(struct rdma_cm_id *id);
+ int ucma_complete(struct rdma_cm_id *id);
 diff --git a/src/preload.c b/src/preload.c
-index a680143..4b891a1 100644
+index a680143..b716e66 100644
 --- a/src/preload.c
 +++ b/src/preload.c
-@@ -886,3 +886,10 @@ int fcntl(int socket, int cmd, ... /* arg */)
+@@ -83,6 +83,7 @@ struct socket_calls {
+       int (*getsockopt)(int socket, int level, int optname,
+                         void *optval, socklen_t *optlen);
+       int (*fcntl)(int socket, int cmd, ... /* arg */);
++      int (*dup2)(int oldfd, int newfd);
+ };
+ static struct socket_calls real;
+@@ -105,6 +106,8 @@ enum fd_type {
+ struct fd_info {
+       enum fd_type type;
+       int fd;
++      struct fd_info *dupfdi;
++      atomic_t refcnt;
+ };
+ static int fd_open(void)
+@@ -122,6 +125,8 @@ static int fd_open(void)
+               goto err1;
+       }
++      atomic_init(&fdi->refcnt);
++      atomic_set(&fdi->refcnt, 1);
+       pthread_mutex_lock(&mut);
+       ret = idm_set(&idm, index, fdi);
+       pthread_mutex_unlock(&mut);
+@@ -252,6 +257,7 @@ static void init_preload(void)
+       real.setsockopt = dlsym(RTLD_NEXT, "setsockopt");
+       real.getsockopt = dlsym(RTLD_NEXT, "getsockopt");
+       real.fcntl = dlsym(RTLD_NEXT, "fcntl");
++      real.dup2 = dlsym(RTLD_NEXT, "dup2");
+       rs.socket = dlsym(RTLD_DEFAULT, "rsocket");
+       rs.bind = dlsym(RTLD_DEFAULT, "rbind");
+@@ -886,3 +892,45 @@ int fcntl(int socket, int cmd, ... /* arg */)
        va_end(args);
        return ret;
  }
 +
++/*
++ * dup2 is not thread safe
++ */
 +int dup2(int oldfd, int newfd)
 +{
-+      int fd;
-+      return (fd_get(oldfd, &fd) == fd_rsocket) ?
-+              : dup2(oldfd, newfd);
++      struct fd_info *oldfdi, *newfdi;
++      int ret;
++
++      oldfdi = idm_lookup(&idm, oldfd);
++      newfdi = idm_lookup(&idm, newfd);
++      if (newfdi) {
++               /* newfd cannot have been dup'ed directly */
++              if (atomic_get(&newfdi->refcnt) > 1)
++                      return ERR(EBUSY);
++              close(newfd);
++      }
++
++      ret = real.dup2(oldfd, newfd);
++      if (!oldfdi || ret != newfd)
++              return ret;
++
++      newfdi = calloc(1, sizeof *fdi);
++      if (!newfdi) {
++              close(newfd);
++              return ERR(ENOMEM);
++      }
++
++      pthread_mutex_lock(&mut);
++      idm_set(&idm, newfd, newfdi);
++      pthread_mutex_unlock(&mut);
++
++      if (oldfdi->dupfdi)
++              oldfdi = oldfdi->dupfdi;
++      newfdi->fd = oldfdi->fd;
++      newfdi->type = oldfdi->type;
++      newfdi->dupfdi = oldfdi;
++      atomic_init(&newfdi->refcnt);
++      atomic_set(&newfdi->refcnt, 1);
++      atomic_inc(&oldfdi->refcnt);
++      return newfd;
 +}
diff --git a/patches/refresh-temp b/patches/refresh-temp
deleted file mode 100644 (file)
index 37b6c3d..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-Bottom: 6c3a4d4cc0146d11acbd41ec30ac983f004e11c7
-Top:    1ba59f6f7d9886c4ce5b8aa5fa06f770d53b8bf2
-Author: Sean Hefty <sean.hefty@intel.com>
-Date:   2012-08-06 13:48:46 -0700
-
-Refresh of dup2
-
----
-
-diff --git a/src/cma.h b/src/cma.h
-index cedc0c3..6c3df27 100644
---- a/src/cma.h
-+++ b/src/cma.h
-@@ -79,6 +79,31 @@ static inline uint64_t ntohll(uint64_t x) { return x; }
- #define fastlock_destroy(lock) pthread_mutex_destroy(lock)
- #define fastlock_acquire(lock) pthread_mutex_lock(lock)
- #define fastlock_release(lock) pthread_mutex_unlock(lock)
-+
-+typedef struct { pthread_mutex_t mut; int val; } atomic_t;
-+static inline int atomic_inc(atomic_t *atomic)
-+{
-+      int v;
-+
-+      pthread_mutex_lock(&atomic->mut);
-+      v = ++(atomic->val);
-+      pthread_mutex_unlock(&atomic->mut);
-+      return v;
-+}
-+static inline int atomic_dec(atomic_t *atomic)
-+{
-+      int v;
-+
-+      pthread_mutex_lock(&atomic->mut);
-+      v = --(atomic->val);
-+      pthread_mutex_unlock(&atomic->mut);
-+      return v;
-+}
-+static inline void atomic_init(atomic_t *atomic)
-+{
-+      pthread_mutex_init(&atomic->mut, NULL);
-+      atomic->val = 0;
-+}
- #else
- typedef struct {
-       sem_t sem;
-@@ -103,7 +128,14 @@ static inline void fastlock_release(fastlock_t *lock)
-       if (__sync_sub_and_fetch(&lock->cnt, 1) > 0)
-               sem_post(&lock->sem);
- }
-+
-+typedef struct { volatile int val; } atomic_t;
-+#define atomic_inc(v) (__sync_add_and_fetch(&(v)->val, 1))
-+#define atomic_dec(v) (__sync_sub_and_fetch(&(v)->val, 1))
-+#define atomic_init(v) ((v)->val = 0)
- #endif /* DEFINE_ATOMICS */
-+#define atomic_get(v) ((v)->val)
-+#define atomic_set(v, s) ((v)->val = s)
- int ucma_max_qpsize(struct rdma_cm_id *id);
- int ucma_complete(struct rdma_cm_id *id);
-diff --git a/src/preload.c b/src/preload.c
-index 4b891a1..b716e66 100644
---- a/src/preload.c
-+++ b/src/preload.c
-@@ -83,6 +83,7 @@ struct socket_calls {
-       int (*getsockopt)(int socket, int level, int optname,
-                         void *optval, socklen_t *optlen);
-       int (*fcntl)(int socket, int cmd, ... /* arg */);
-+      int (*dup2)(int oldfd, int newfd);
- };
- static struct socket_calls real;
-@@ -105,6 +106,8 @@ enum fd_type {
- struct fd_info {
-       enum fd_type type;
-       int fd;
-+      struct fd_info *dupfdi;
-+      atomic_t refcnt;
- };
- static int fd_open(void)
-@@ -122,6 +125,8 @@ static int fd_open(void)
-               goto err1;
-       }
-+      atomic_init(&fdi->refcnt);
-+      atomic_set(&fdi->refcnt, 1);
-       pthread_mutex_lock(&mut);
-       ret = idm_set(&idm, index, fdi);
-       pthread_mutex_unlock(&mut);
-@@ -252,6 +257,7 @@ static void init_preload(void)
-       real.setsockopt = dlsym(RTLD_NEXT, "setsockopt");
-       real.getsockopt = dlsym(RTLD_NEXT, "getsockopt");
-       real.fcntl = dlsym(RTLD_NEXT, "fcntl");
-+      real.dup2 = dlsym(RTLD_NEXT, "dup2");
-       rs.socket = dlsym(RTLD_DEFAULT, "rsocket");
-       rs.bind = dlsym(RTLD_DEFAULT, "rbind");
-@@ -887,9 +893,44 @@ int fcntl(int socket, int cmd, ... /* arg */)
-       return ret;
- }
-+/*
-+ * dup2 is not thread safe
-+ */
- int dup2(int oldfd, int newfd)
- {
--      int fd;
--      return (fd_get(oldfd, &fd) == fd_rsocket) ?
--              : dup2(oldfd, newfd);
-+      struct fd_info *oldfdi, *newfdi;
-+      int ret;
-+
-+      oldfdi = idm_lookup(&idm, oldfd);
-+      newfdi = idm_lookup(&idm, newfd);
-+      if (newfdi) {
-+               /* newfd cannot have been dup'ed directly */
-+              if (atomic_get(&newfdi->refcnt) > 1)
-+                      return ERR(EBUSY);
-+              close(newfd);
-+      }
-+
-+      ret = real.dup2(oldfd, newfd);
-+      if (!oldfdi || ret != newfd)
-+              return ret;
-+
-+      newfdi = calloc(1, sizeof *fdi);
-+      if (!newfdi) {
-+              close(newfd);
-+              return ERR(ENOMEM);
-+      }
-+
-+      pthread_mutex_lock(&mut);
-+      idm_set(&idm, newfd, newfdi);
-+      pthread_mutex_unlock(&mut);
-+
-+      if (oldfdi->dupfdi)
-+              oldfdi = oldfdi->dupfdi;
-+      newfdi->fd = oldfdi->fd;
-+      newfdi->type = oldfdi->type;
-+      newfdi->dupfdi = oldfdi;
-+      atomic_init(&newfdi->refcnt);
-+      atomic_set(&newfdi->refcnt, 1);
-+      atomic_inc(&oldfdi->refcnt);
-+      return newfd;
- }