opr: Assert opr_cv_timedwait return codes 79/14079/6
authorAndrew Deason <adeason@sinenomine.net>
Fri, 21 Feb 2020 15:49:09 +0000 (10:49 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 1 Jul 2021 16:54:36 +0000 (12:54 -0400)
Almost all of our opr locking primitives assert that they did not
receive an error from pthreads. opr_cv_timedwait is the exception to
this, since it needs to return two possible codes that aren't
internal failures: 0 and ETIMEDOUT. As a result, most callers assert
that our returned code is one of these two values.

To make opr_cv_timedwait act more like our other locking primitives,
removing the need to add opr_Assert()s everywhere, change
opr_cv_timedwait to check that the returned code is 0 or ETIMEDOUT,
and remove the relevant asserts from its callers.

Change-Id: Ie9a62f2edb23969d66e4ed821af37077bc6400c4
Reviewed-on: https://gerrit.openafs.org/14079
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>

src/fsprobe/fsprobe.c
src/opr/opr_lock.h
src/viced/viced.c
src/xstat/xstat_cm.c
src/xstat/xstat_fs.c

index e19600e..7690992 100644 (file)
@@ -361,7 +361,6 @@ fsprobe_LWP(void *unused)
        wait.tv_nsec = tv.tv_usec * 1000;
        opr_mutex_enter(&fsprobe_force_lock);
        code = opr_cv_timedwait(&fsprobe_force_cv, &fsprobe_force_lock, &wait);
-       opr_Assert(code == 0 || code == ETIMEDOUT);
        opr_mutex_exit(&fsprobe_force_lock);
     }                          /*Service loop */
     AFS_UNREACHED(free(stats64.ViceStatistics64_val));
index 6051c5d..b8b61ac 100644 (file)
@@ -25,6 +25,7 @@
 #define OPENAFS_OPR_LOCK_H 1
 
 #include <pthread.h>
+#include <errno.h>
 
 /* Mutexes */
 
@@ -78,8 +79,14 @@ typedef pthread_cond_t opr_cv_t;
 # define opr_cv_wait(condvar, mutex) \
     opr_Verify(pthread_cond_wait(condvar, mutex) == 0)
 
-# define opr_cv_timedwait(condvar, mutex, timeout) \
-    pthread_cond_timedwait(condvar, mutex, timeout)
+static_inline int
+opr_cv_timedwait(opr_cv_t *condvar, opr_mutex_t *mutex,
+                const struct timespec *abstime)
+{
+    int code = pthread_cond_timedwait(condvar, mutex, abstime);
+    opr_Assert(code == 0 || code == ETIMEDOUT);
+    return code;
+}
 
 # define opr_cv_signal(condvar) \
     opr_Verify(pthread_cond_signal(condvar) == 0)
index 17cf1f8..2119408 100644 (file)
@@ -525,8 +525,6 @@ FsyncCheckLWP(void *unused)
 
        code = opr_cv_timedwait(&fsync_cond, &fsync_glock_mutex,
                            &fsync_next);
-       if (code != 0 && code != ETIMEDOUT)
-           ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
        FSYNC_UNLOCK;
 
 #ifdef AFS_DEMAND_ATTACH_FS
index 9850d43..4de979e 100644 (file)
@@ -326,7 +326,6 @@ xstat_cm_LWP(void *unused)
            wait.tv_nsec = tv.tv_usec * 1000;
            opr_mutex_enter(&xstat_cm_force_lock);
            code = opr_cv_timedwait(&xstat_cm_force_cv, &xstat_cm_force_lock, &wait);
-           opr_Assert(code == 0 || code == ETIMEDOUT);
            opr_mutex_exit(&xstat_cm_force_lock);
        }                       /*Continuous execution */
     }                          /*Service loop */
index 3145a00..006bcce 100644 (file)
@@ -341,7 +341,6 @@ xstat_fs_LWP(void *unused)
            wait.tv_nsec = tv.tv_usec * 1000;
            opr_mutex_enter(&xstat_fs_force_lock);
            code = opr_cv_timedwait(&xstat_fs_force_cv, &xstat_fs_force_lock, &wait);
-           opr_Verify(code == 0 || code == ETIMEDOUT);
            opr_mutex_exit(&xstat_fs_force_lock);
        }                       /*Continuous execution */
     }                          /*Service loop */