[sheepdog-users] [PATCH stable-0.7 3/4] sheep: check EAGAIN for all the sd_lock helpers

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Dec 17 09:52:39 CET 2013


From: Liu Yuan <namei.unix at gmail.com>

Some users report that:

[root at pangkvm01 sheepdog]# cat sheep.log.bak |grep "Dec 16 23"
Dec 16 23:34:22  ERROR [main] modify_event(156) event info for fd 106 not
found
Dec 16 23:40:24  EMERG [io 5574] crash_handler(250) sheep exits unexpectedly
(Segmentation fault).
Dec 16 23:40:24  EMERG [io 7281] sd_write_lock(307) PANIC: failed to lock
for writing, Resource temporarily unavailable
Dec 16 23:40:24  EMERG [io 7281] crash_handler(250) sheep exits unexpectedly
(Aborted).

It means some posix lock funcitions can return what is not documented in manual.
So it's better for us to defensively check it rather than panic out.

Reviewed-by:Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 include/util.h |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/include/util.h b/include/util.h
index ff1f0c7..a9b228e 100644
--- a/include/util.h
+++ b/include/util.h
@@ -281,7 +281,11 @@ static inline void sd_init_lock(struct sd_lock *lock)
 
 static inline void sd_destroy_lock(struct sd_lock *lock)
 {
-	int ret = pthread_rwlock_destroy(&lock->rwlock);
+	int ret;
+
+	do {
+		ret = pthread_rwlock_destroy(&lock->rwlock);
+	} while (ret == EAGAIN);
 
 	if (unlikely(ret != 0))
 		panic("failed to destroy a lock, %s", strerror(ret));
@@ -299,9 +303,17 @@ static inline void sd_read_lock(struct sd_lock *lock)
 		panic("failed to lock for reading, %s", strerror(ret));
 }
 
+/*
+ * Even though POSIX manual it doesn't return EAGAIN, we indeed have met the
+ * case that it returned EAGAIN
+ */
 static inline void sd_write_lock(struct sd_lock *lock)
 {
-	int ret = pthread_rwlock_wrlock(&lock->rwlock);
+	int ret;
+
+	do {
+		ret = pthread_rwlock_wrlock(&lock->rwlock);
+	} while (ret == EAGAIN);
 
 	if (unlikely(ret != 0))
 		panic("failed to lock for writing, %s", strerror(ret));
@@ -309,7 +321,11 @@ static inline void sd_write_lock(struct sd_lock *lock)
 
 static inline void sd_unlock(struct sd_lock *lock)
 {
-	int ret = pthread_rwlock_unlock(&lock->rwlock);
+	int ret;
+
+	do {
+		ret = pthread_rwlock_unlock(&lock->rwlock);
+	} while (ret == EAGAIN);
 
 	if (unlikely(ret != 0))
 		panic("failed to unlock, %s", strerror(ret));
-- 
1.7.10.4




More information about the sheepdog-users mailing list