+#define OBD_FAIL_ONCE_BIT 31
+/* OBD_FAIL_ONCE is 0x80000000 */
+#define OBD_FAIL_ONCE (1 << OBD_FAIL_ONCE_BIT)
+
+/* The following flags aren't made to be combined */
+#define OBD_FAIL_SKIP 0x20000000 /* skip N times then fail */
+#define OBD_FAIL_SOME 0x10000000 /* only fail N times */
+#define OBD_FAIL_RAND 0x08000000 /* fail 1/N of the times */
+#define OBD_FAIL_USR1 0x04000000 /* user flag */
+
+#define OBD_FAIL_PRECHECK(id) (obd_fail_loc && \
+ (obd_fail_loc & OBD_FAIL_MASK_LOC) == \
+ ((id) & OBD_FAIL_MASK_LOC))
+
+static inline int obd_fail_check_set(__u32 id, __u32 value, int set)
+{
+ int ret = 0;
+ if (unlikely(OBD_FAIL_PRECHECK(id) &&
+ (ret = __obd_fail_check_set(id, value, set)))) {
+ CERROR("*** obd_fail_loc=%x ***\n", id);
+ }
+ return ret;
+}
+
+/* If id hit obd_fail_loc, return 1, otherwise return 0 */
+#define OBD_FAIL_CHECK(id) \
+ obd_fail_check_set(id, 0, OBD_FAIL_LOC_NOSET)
+
+/* If id hit obd_fail_loc, obd_fail_loc |= value and return 1,
+ * otherwise return 0 */
+#define OBD_FAIL_CHECK_ORSET(id, value) \
+ obd_fail_check_set(id, value, OBD_FAIL_LOC_ORSET)
+
+/* If id hit obd_fail_loc, obd_fail_loc = value and return 1,
+ * otherwise return 0 */
+#define OBD_FAIL_CHECK_RESET(id, value) \
+ obd_fail_check_set(id, value, OBD_FAIL_LOC_RESET)
+
+
+static inline int obd_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
+{
+ if (unlikely(OBD_FAIL_PRECHECK(id)))
+ return __obd_fail_timeout_set(id, value, ms, set);
+ else
+ return 0;
+}
+
+/* If id hit obd_fail_loc, sleep for seconds or milliseconds */
+#define OBD_FAIL_TIMEOUT(id, secs) \
+ obd_fail_timeout_set(id, 0, secs * 1000, OBD_FAIL_LOC_NOSET)
+
+#define OBD_FAIL_TIMEOUT_MS(id, ms) \
+ obd_fail_timeout_set(id, 0, ms, OBD_FAIL_LOC_NOSET)
+
+/* If id hit obd_fail_loc, obd_fail_loc |= value and
+ * sleep seconds or milliseconds */
+#define OBD_FAIL_TIMEOUT_ORSET(id, value, secs) \
+ obd_fail_timeout_set(id, value, secs * 1000, OBD_FAIL_LOC_ORSET)
+
+#define OBD_FAIL_TIMEOUT_MS_ORSET(id, value, ms) \
+ obd_fail_timeout_set(id, value, ms, OBD_FAIL_LOC_ORSET)