Whamcloud - gitweb
LU-793 ptlrpc: fix ptlrpc_request_change_export()
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_fail.h
index b9dcd6b..f8490cc 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -27,6 +25,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -39,7 +39,7 @@
 extern unsigned long cfs_fail_loc;
 extern unsigned int cfs_fail_val;
 
-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);
@@ -48,7 +48,8 @@ int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set);
 enum {
         CFS_FAIL_LOC_NOSET      = 0,
         CFS_FAIL_LOC_ORSET      = 1,
-        CFS_FAIL_LOC_RESET      = 2
+        CFS_FAIL_LOC_RESET      = 2,
+        CFS_FAIL_LOC_VALUE      = 3
 };
 
 /* Failure injection control */
@@ -73,29 +74,51 @@ enum {
                               (cfs_fail_loc & CFS_FAIL_MASK_LOC) ==           \
                               ((id) & CFS_FAIL_MASK_LOC))
 
-static inline int cfs_fail_check_set(__u32 id, __u32 value, int set)
+static inline int cfs_fail_check_set(__u32 id, __u32 value,
+                                    int set, int quiet)
 {
-        int ret = 0;
-        if (unlikely(CFS_FAIL_PRECHECK(id) &&
-            (ret = __cfs_fail_check_set(id, value, set)))) {
-                CERROR("*** cfs_fail_loc=%x ***\n", id);
-        }
-        return ret;
+       int ret = 0;
+
+       if (unlikely(CFS_FAIL_PRECHECK(id) &&
+                    (ret = __cfs_fail_check_set(id, value, set)))) {
+               if (quiet) {
+                       CDEBUG(D_INFO, "*** cfs_fail_loc=%x, val=%u***\n",
+                              id, value);
+               } else {
+                       LCONSOLE_INFO("*** cfs_fail_loc=%x, val=%u***\n",
+                                     id, value);
+               }
+       }
+
+       return ret;
 }
 
 /* If id hit cfs_fail_loc, return 1, otherwise return 0 */
 #define CFS_FAIL_CHECK(id) \
-        cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET)
+       cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET, 0)
+#define CFS_FAIL_CHECK_QUIET(id) \
+       cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET, 1)
+
+/* If id hit cfs_fail_loc and cfs_fail_val == (-1 or value) return 1,
+ * otherwise return 0 */
+#define CFS_FAIL_CHECK_VALUE(id, value) \
+       cfs_fail_check_set(id, value, CFS_FAIL_LOC_VALUE, 0)
+#define CFS_FAIL_CHECK_VALUE_QUIET(id, value) \
+       cfs_fail_check_set(id, value, CFS_FAIL_LOC_VALUE, 1)
 
 /* If id hit cfs_fail_loc, cfs_fail_loc |= value and return 1,
  * otherwise return 0 */
 #define CFS_FAIL_CHECK_ORSET(id, value) \
-        cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET)
+       cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET, 0)
+#define CFS_FAIL_CHECK_ORSET_QUIET(id, value) \
+       cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET, 1)
 
 /* If id hit cfs_fail_loc, cfs_fail_loc = value and return 1,
  * otherwise return 0 */
 #define CFS_FAIL_CHECK_RESET(id, value) \
-        cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET)
+       cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET, 0)
+#define CFS_FAIL_CHECK_RESET_QUIET(id, value) \
+       cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET, 1)
 
 static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
 {
@@ -107,7 +130,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)
@@ -115,7 +138,7 @@ 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_MS_ORSET(id, value, ms) \
         cfs_fail_timeout_set(id, value, ms, CFS_FAIL_LOC_ORSET)
@@ -127,20 +150,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)
 {
-        int rc;
-
-        if (CFS_FAIL_PRECHECK(id)) {
-                if (unlikely(__cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET))) {
-                        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\n", id);
-                } 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