-#define OBD_FAIL_CHECK_ONCE(id) \
-({ int _ret_ = 0; \
- if (unlikely(OBD_FAIL_CHECK(id))) { \
- CERROR("*** obd_fail_loc=0x%x ***\n", id); \
- obd_fail_loc |= OBD_FAILED; \
- if ((id) & OBD_FAIL_ONCE) \
- obd_fail_loc |= OBD_FAIL_ONCE; \
- _ret_ = 1; \
+static inline int obd_fail_check(__u32 id)
+{
+ static int count = 0;
+ if (likely((obd_fail_loc & OBD_FAIL_MASK_LOC) !=
+ (id & OBD_FAIL_MASK_LOC)))
+ return 0;
+
+ if ((obd_fail_loc & (OBD_FAILED | OBD_FAIL_ONCE)) ==
+ (OBD_FAILED | OBD_FAIL_ONCE)) {
+ count = 0; /* paranoia */
+ return 0;
+ }
+
+ if (obd_fail_loc & OBD_FAIL_RAND) {
+ unsigned int ll_rand(void);
+ if (obd_fail_val < 2)
+ return 0;
+ if (ll_rand() % obd_fail_val > 0)
+ return 0;
+ }
+
+ if (obd_fail_loc & OBD_FAIL_SKIP) {
+ count++;
+ if (count < obd_fail_val)
+ return 0;
+ count = 0;
+ }
+
+ /* Overridden by FAIL_ONCE */
+ if (obd_fail_loc & OBD_FAIL_SOME) {
+ count++;
+ if (count >= obd_fail_val) {
+ count = 0;
+ /* Don't fail anymore */
+ obd_fail_loc |= OBD_FAIL_ONCE;
+ }
+ }
+
+ obd_fail_loc |= OBD_FAILED;
+ /* Handle old checks that OR in this */
+ if (id & OBD_FAIL_ONCE)
+ obd_fail_loc |= OBD_FAIL_ONCE;
+
+ return 1;
+}
+
+#define OBD_FAIL_CHECK(id) \
+({ \
+ int _ret_ = 0; \
+ if (unlikely(obd_fail_loc && (_ret_ = obd_fail_check(id)))) { \
+ CERROR("*** obd_fail_loc=%x ***\n", id); \