Whamcloud - gitweb
LU-5409 obd: add CFS_FAULT_CHECK()
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_fail.h
index 6dda76b..79c6795 100644 (file)
@@ -26,7 +26,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -38,8 +38,9 @@
 
 extern unsigned long cfs_fail_loc;
 extern unsigned int cfs_fail_val;
+extern int cfs_fail_err;
 
-extern cfs_waitq_t cfs_race_waitq;
+extern wait_queue_head_t cfs_race_waitq;
 extern int cfs_race_state;
 
 int __cfs_fail_check_set(__u32 id, __u32 value, int set);
@@ -70,9 +71,15 @@ enum {
 #define CFS_FAIL_RAND        0x08000000 /* fail 1/N of the times */
 #define CFS_FAIL_USR1        0x04000000 /* user flag */
 
-#define CFS_FAIL_PRECHECK(id) (cfs_fail_loc &&                                \
-                              (cfs_fail_loc & CFS_FAIL_MASK_LOC) ==           \
-                              ((id) & CFS_FAIL_MASK_LOC))
+/* CFS_FAULT may be combined with any one of the above flags. */
+#define CFS_FAULT           0x02000000 /* match any CFS_FAULT_CHECK */
+
+static inline bool CFS_FAIL_PRECHECK(__u32 id)
+{
+       return cfs_fail_loc != 0 &&
+             ((cfs_fail_loc & CFS_FAIL_MASK_LOC) == (id & CFS_FAIL_MASK_LOC) ||
+              (cfs_fail_loc & id & CFS_FAULT));
+}
 
 static inline int cfs_fail_check_set(__u32 id, __u32 value,
                                     int set, int quiet)
@@ -130,7 +137,7 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
 
 /* If id hit cfs_fail_loc, sleep for seconds or milliseconds */
 #define CFS_FAIL_TIMEOUT(id, secs) \
-        cfs_fail_timeout_set(id, 0, secs * 1000, CFS_FAIL_LOC_NOSET)
+        cfs_fail_timeout_set(id, 0, (secs) * 1000, CFS_FAIL_LOC_NOSET)
 
 #define CFS_FAIL_TIMEOUT_MS(id, ms) \
         cfs_fail_timeout_set(id, 0, ms, CFS_FAIL_LOC_NOSET)
@@ -138,11 +145,17 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
 /* If id hit cfs_fail_loc, cfs_fail_loc |= value and
  * sleep seconds or milliseconds */
 #define CFS_FAIL_TIMEOUT_ORSET(id, value, secs) \
-        cfs_fail_timeout_set(id, value, secs * 1000, CFS_FAIL_LOC_ORSET)
+        cfs_fail_timeout_set(id, value, (secs) * 1000, CFS_FAIL_LOC_ORSET)
+
+#define CFS_FAIL_TIMEOUT_RESET(id, value, secs) \
+       cfs_fail_timeout_set(id, value, secs * 1000, CFS_FAIL_LOC_RESET)
 
 #define CFS_FAIL_TIMEOUT_MS_ORSET(id, value, ms) \
         cfs_fail_timeout_set(id, value, ms, CFS_FAIL_LOC_ORSET)
 
+#define CFS_FAULT_CHECK(id)                    \
+       CFS_FAIL_CHECK(CFS_FAULT | (id))
+
 #ifdef __KERNEL__
 /* The idea here is to synchronise two threads to force a race. The
  * first thread that calls this with a matching fail_loc is put to
@@ -150,21 +163,20 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
  * the first and continues. */
 static inline void cfs_race(__u32 id)
 {
-
-        if (CFS_FAIL_PRECHECK(id)) {
-                if (unlikely(__cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET))) {
-                        int rc;
-                        cfs_race_state = 0;
-                        CERROR("cfs_race id %x sleeping\n", id);
-                        cfs_wait_event_interruptible(cfs_race_waitq,
-                                                     cfs_race_state != 0, rc);
-                        CERROR("cfs_fail_race id %x awake, rc=%d\n", id, rc);
-                } else {
-                        CERROR("cfs_fail_race id %x waking\n", id);
-                        cfs_race_state = 1;
-                        cfs_waitq_signal(&cfs_race_waitq);
-                }
-        }
+       if (CFS_FAIL_PRECHECK(id)) {
+               if (unlikely(__cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET))) {
+                       int rc;
+                       cfs_race_state = 0;
+                       CERROR("cfs_race id %x sleeping\n", id);
+                       rc = wait_event_interruptible(cfs_race_waitq,
+                                                     cfs_race_state != 0);
+                       CERROR("cfs_fail_race id %x awake, rc=%d\n", id, rc);
+               } else {
+                       CERROR("cfs_fail_race id %x waking\n", id);
+                       cfs_race_state = 1;
+                       wake_up(&cfs_race_waitq);
+               }
+       }
 }
 #define CFS_RACE(id) cfs_race(id)
 #else